-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Dhaval Solanki
committed
Apr 25, 2019
1 parent
56600b0
commit 6b23a10
Showing
9 changed files
with
167 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
app/src/main/java/com/tristate/radarsample/BitmapUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package com.tristate.radarsample; | ||
|
||
import android.graphics.Bitmap; | ||
import android.graphics.Point; | ||
|
||
import java.util.LinkedList; | ||
import java.util.Queue; | ||
|
||
public class BitmapUtil { | ||
public static void floodFill(Bitmap image, Point node, int targetColor, | ||
int replacementColor) { | ||
int width = image.getWidth(); | ||
int height = image.getHeight(); | ||
int target = targetColor; | ||
int replacement = replacementColor; | ||
if (target != replacement) { | ||
Queue<Point> queue = new LinkedList<Point>(); | ||
do { | ||
int x = node.x; | ||
int y = node.y; | ||
while (x > 0 && image.getPixel(x - 1, y) == target) { | ||
x--; | ||
} | ||
boolean spanUp = false; | ||
boolean spanDown = false; | ||
while (x < width && image.getPixel(x, y) == target) { | ||
image.setPixel(x, y, replacement); | ||
if (!spanUp && y > 0 && image.getPixel(x, y - 1) == target) { | ||
queue.add(new Point(x, y - 1)); | ||
spanUp = true; | ||
} else if (spanUp && y > 0 | ||
&& image.getPixel(x, y - 1) != target) { | ||
spanUp = false; | ||
} | ||
if (!spanDown && y < height - 1 | ||
&& image.getPixel(x, y + 1) == target) { | ||
queue.add(new Point(x, y + 1)); | ||
spanDown = true; | ||
} else if (spanDown && y < height - 1 | ||
&& image.getPixel(x, y + 1) != target) { | ||
spanDown = false; | ||
} | ||
x++; | ||
} | ||
} while ((node = queue.poll()) != null); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 84 additions & 0 deletions
84
app/src/main/java/com/tristate/radarsample/PaintActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
package com.tristate.radarsample; | ||
|
||
import android.annotation.SuppressLint; | ||
import android.graphics.Bitmap; | ||
import android.graphics.Color; | ||
import android.graphics.Point; | ||
import android.graphics.drawable.BitmapDrawable; | ||
import android.media.Image; | ||
import android.os.AsyncTask; | ||
import android.support.v7.app.AppCompatActivity; | ||
import android.os.Bundle; | ||
import android.view.MotionEvent; | ||
import android.view.View; | ||
import android.widget.ImageView; | ||
|
||
public class PaintActivity extends AppCompatActivity implements View.OnTouchListener { | ||
|
||
private ImageView mImgSource; | ||
|
||
@SuppressLint("ClickableViewAccessibility") | ||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_paint); | ||
mImgSource = (ImageView) findViewById(R.id.mImgSource); | ||
mImgSource.setOnTouchListener(this); | ||
} | ||
|
||
@Override | ||
public boolean onTouch(View v, MotionEvent event) { | ||
|
||
switch (event.getAction()) { | ||
case MotionEvent.ACTION_DOWN: | ||
case MotionEvent.ACTION_MOVE: | ||
|
||
break; | ||
case MotionEvent.ACTION_UP: | ||
float x = event.getX(); | ||
float y = event.getY(); | ||
|
||
final Point p1 = new Point(); | ||
p1.x = (int) x; //x co-ordinate where the user touches on the screen | ||
p1.y = (int) y; //y co-ordinate where the user touches on the screen | ||
Bitmap bitmap = ((BitmapDrawable) mImgSource.getDrawable()).getBitmap(); | ||
final int sourceColor = bitmap.getPixel((int) x, (int) y); | ||
new ColorFillOpt(bitmap, p1, Color.parseColor("#D81B60"), sourceColor).doInBackground(); | ||
break; | ||
} | ||
return true; | ||
} | ||
|
||
@Override | ||
public void onPointerCaptureChanged(boolean hasCapture) { | ||
|
||
} | ||
|
||
public class ColorFillOpt extends AsyncTask<Void, Void, Void> { | ||
|
||
private final Bitmap bitmap; | ||
private final Point p1; | ||
private final int titleColor; | ||
private final int sourceColor; | ||
|
||
public ColorFillOpt(Bitmap bitmap, Point p1, int titleColor, int sourceColor) { | ||
this.bitmap = bitmap; | ||
this.p1 = p1; | ||
this.titleColor = titleColor; | ||
this.sourceColor = sourceColor; | ||
} | ||
|
||
@Override | ||
protected Void doInBackground(Void... voids) { | ||
BitmapUtil.floodFill(bitmap, p1, getTitleColor(), sourceColor); | ||
return null; | ||
} | ||
|
||
@Override | ||
protected void onPostExecute(Void aVoid) { | ||
mImgSource.setImageBitmap(bitmap); | ||
super.onPostExecute(aVoid); | ||
|
||
} | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:app="http://schemas.android.com/apk/res-auto" | ||
xmlns:tools="http://schemas.android.com/tools" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
tools:context=".PaintActivity"> | ||
|
||
<ImageView | ||
android:id="@+id/mImgSource" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:adjustViewBounds="true" | ||
android:src="@drawable/wall" | ||
app:layout_constraintTop_toTopOf="parent" /> | ||
|
||
</android.support.constraint.ConstraintLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters