Merge pull request #27 from LonamiWebs/master
Added clear color (implements and closes #6)
@ -85,7 +85,7 @@ public class MyCanvas extends View {
|
||||
canvas.drawPath(mPath, mPaint);
|
||||
}
|
||||
|
||||
public void clearCanvas(){
|
||||
public void clearCanvas() {
|
||||
mPath.reset();
|
||||
mPaths.clear();
|
||||
pathsUpdated();
|
||||
|
@ -1,10 +1,28 @@
|
||||
package com.simplemobiletools.draw;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Color;
|
||||
import android.widget.Toast;
|
||||
|
||||
public class Utils {
|
||||
private final static double BRIGHTNESS_CUTOFF = 130.0;
|
||||
|
||||
public static void showToast(Context cxt, int msgId) {
|
||||
Toast.makeText(cxt, cxt.getResources().getString(msgId), Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
|
||||
// Used to determine the best foreground color (black or white) given a background color
|
||||
public static boolean shouldUseWhite(int color) {
|
||||
float r, g, b;
|
||||
r = Color.red(color);
|
||||
g = Color.green(color);
|
||||
b = Color.blue(color);
|
||||
|
||||
double brightness = Math.sqrt(
|
||||
r * r * .299 +
|
||||
g * g * .587 +
|
||||
b * b * .114);
|
||||
|
||||
return brightness < BRIGHTNESS_CUTOFF;
|
||||
}
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.drawable.ColorDrawable;
|
||||
import android.media.MediaScannerConnection;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
@ -18,6 +19,7 @@ import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.widget.EditText;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.simplemobiletools.draw.Config;
|
||||
@ -87,6 +89,27 @@ public class MainActivity extends SimpleActivity implements MyCanvas.PathsChange
|
||||
case R.id.clear:
|
||||
mMyCanvas.clearCanvas();
|
||||
return true;
|
||||
case R.id.change_background:
|
||||
int oldColor = ((ColorDrawable)mMyCanvas.getBackground()).getColor();
|
||||
AmbilWarnaDialog dialog = new AmbilWarnaDialog(this, oldColor,
|
||||
new AmbilWarnaDialog.OnAmbilWarnaListener() {
|
||||
@Override
|
||||
public void onCancel(AmbilWarnaDialog dialog) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onOk(AmbilWarnaDialog dialog, int pickedColor) {
|
||||
if (Utils.shouldUseWhite(pickedColor)) {
|
||||
((ImageView)mUndoBtn).setImageResource(R.mipmap.undo_white);
|
||||
} else {
|
||||
((ImageView)mUndoBtn).setImageResource(R.mipmap.undo_black);
|
||||
}
|
||||
mMyCanvas.setBackgroundColor(pickedColor);
|
||||
}
|
||||
});
|
||||
|
||||
dialog.show();
|
||||
return true;
|
||||
case R.id.about:
|
||||
startActivity(new Intent(getApplicationContext(), AboutActivity.class));
|
||||
return true;
|
||||
|
@ -23,7 +23,7 @@
|
||||
android:layout_alignParentRight="true"
|
||||
android:layout_below="@id/color_picker"
|
||||
android:padding="@dimen/icon_padding"
|
||||
android:src="@mipmap/undo"
|
||||
android:src="@mipmap/undo_black"
|
||||
android:visibility="gone"/>
|
||||
|
||||
</RelativeLayout>
|
||||
|
@ -15,6 +15,10 @@
|
||||
android:id="@+id/clear"
|
||||
android:title="@string/clear"
|
||||
app:showAsAction="never"/>
|
||||
<item
|
||||
android:id="@+id/change_background"
|
||||
android:title="@string/change_background"
|
||||
app:showAsAction="never"/>
|
||||
<item
|
||||
android:id="@+id/settings"
|
||||
android:title="@string/settings"
|
||||
|
Before Width: | Height: | Size: 473 B After Width: | Height: | Size: 473 B |
BIN
app/src/main/res/mipmap-hdpi/undo_white.png
Normal file
After Width: | Height: | Size: 477 B |
Before Width: | Height: | Size: 333 B After Width: | Height: | Size: 333 B |
BIN
app/src/main/res/mipmap-mdpi/undo_white.png
Normal file
After Width: | Height: | Size: 339 B |
Before Width: | Height: | Size: 601 B After Width: | Height: | Size: 601 B |
BIN
app/src/main/res/mipmap-xhdpi/undo_white.png
Normal file
After Width: | Height: | Size: 606 B |
Before Width: | Height: | Size: 862 B After Width: | Height: | Size: 862 B |
BIN
app/src/main/res/mipmap-xxhdpi/undo_white.png
Normal file
After Width: | Height: | Size: 894 B |
Before Width: | Height: | Size: 1.1 KiB After Width: | Height: | Size: 1.1 KiB |
BIN
app/src/main/res/mipmap-xxxhdpi/undo_white.png
Normal file
After Width: | Height: | Size: 1.1 KiB |
@ -17,6 +17,7 @@
|
||||
<string name="settings">Ajustes</string>
|
||||
<string name="dark_theme">Tema oscuro</string>
|
||||
<string name="clear">Limpiar</string>
|
||||
<string name="change_background">Cambiar fondo</string>
|
||||
|
||||
<!-- About -->
|
||||
<string name="about">Acerca de</string>
|
||||
|
@ -17,6 +17,7 @@
|
||||
<string name="settings">Settings</string>
|
||||
<string name="dark_theme">Dark theme</string>
|
||||
<string name="clear">Clear</string>
|
||||
<string name="change_background">Change background</string>
|
||||
|
||||
<!-- About -->
|
||||
<string name="about">About</string>
|
||||
|