Changed Undo arrow color based on the selected background

This commit is contained in:
Lonami Exo 2016-12-04 18:00:50 +01:00
parent f8bd541f9a
commit e6a1268207
13 changed files with 25 additions and 1 deletions

View File

@ -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;
}
}

View File

@ -19,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;
@ -98,6 +99,11 @@ public class MainActivity extends SimpleActivity implements MyCanvas.PathsChange
@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);
}
});

View File

@ -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>

View File

Before

Width:  |  Height:  |  Size: 473 B

After

Width:  |  Height:  |  Size: 473 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 477 B

View File

Before

Width:  |  Height:  |  Size: 333 B

After

Width:  |  Height:  |  Size: 333 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 339 B

View File

Before

Width:  |  Height:  |  Size: 601 B

After

Width:  |  Height:  |  Size: 601 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 606 B

View File

Before

Width:  |  Height:  |  Size: 862 B

After

Width:  |  Height:  |  Size: 862 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 894 B

View File

Before

Width:  |  Height:  |  Size: 1.1 KiB

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB