fix #10, allow changing the widgets active color

This commit is contained in:
tibbi 2016-08-30 21:20:39 +02:00
parent f4ac335799
commit c9accb65f2
14 changed files with 67 additions and 27 deletions

View File

@ -57,7 +57,7 @@
<receiver
android:name=".MyWidgetProvider"
android:icon="@mipmap/flashlight_small">
android:icon="@drawable/circles_small">
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE"/>
</intent-filter>

View File

@ -9,6 +9,8 @@ import android.content.Intent;
import android.content.SharedPreferences;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.PorterDuff;
import android.graphics.drawable.Drawable;
import android.widget.RemoteViews;
import com.squareup.otto.Bus;
@ -49,7 +51,10 @@ public class MyWidgetProvider extends AppWidgetProvider {
final Resources res = context.getResources();
final int defaultColor = res.getColor(R.color.colorPrimary);
final int appColor = prefs.getInt(Constants.WIDGET_COLOR, defaultColor);
mColoredBmp = Utils.getColoredIcon(context.getResources(), appColor, R.mipmap.flashlight_small);
final Drawable drawable = context.getResources().getDrawable(R.drawable.circles_small);
drawable.mutate().setColorFilter(appColor, PorterDuff.Mode.SRC_ATOP);
mColoredBmp = Utils.drawableToBitmap(drawable);
if (mBus == null) {
mBus = BusProvider.getInstance();
@ -78,7 +83,7 @@ public class MyWidgetProvider extends AppWidgetProvider {
}
public void disableFlashlight() {
mRemoteViews.setImageViewResource(R.id.toggle_btn, R.mipmap.flashlight_small);
mRemoteViews.setImageViewResource(R.id.toggle_btn, R.drawable.circles_small);
for (int widgetId : mWidgetIds) {
mWidgetManager.updateAppWidget(widgetId, mRemoteViews);
}

View File

@ -1,28 +1,20 @@
package com.simplemobiletools.flashlight;
import android.content.Context;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.ColorFilter;
import android.graphics.Paint;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffColorFilter;
import android.graphics.drawable.Drawable;
import android.widget.Toast;
public class Utils {
public static Bitmap getColoredIcon(Resources res, int newTextColor, int id) {
final BitmapFactory.Options options = new BitmapFactory.Options();
options.inMutable = true;
final Bitmap bmp = BitmapFactory.decodeResource(res, id, options);
final Paint paint = new Paint();
final ColorFilter filter = new PorterDuffColorFilter(newTextColor, PorterDuff.Mode.SRC_IN);
paint.setColorFilter(filter);
final Canvas canvas = new Canvas(bmp);
canvas.drawBitmap(bmp, 0, 0, paint);
return bmp;
public static Bitmap drawableToBitmap(Drawable drawable) {
final int width = drawable.getIntrinsicWidth();
final int height = drawable.getIntrinsicHeight();
final Bitmap mutableBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
final Canvas canvas = new Canvas(mutableBitmap);
drawable.setBounds(0, 0, width, height);
drawable.draw(canvas);
return mutableBitmap;
}
public static void showToast(Context context, int resId) {

View File

@ -133,7 +133,7 @@ public class MainActivity extends SimpleActivity {
private void changeIconColor(int colorId, ImageView imageView) {
final int appColor = getResources().getColor(colorId);
imageView.getDrawable().mutate().setColorFilter(appColor, PorterDuff.Mode.SRC_ATOP);
imageView.getDrawable().mutate().setColorFilter(appColor, PorterDuff.Mode.SRC_IN);
}
@Subscribe

View File

@ -9,7 +9,7 @@
android:shape="oval">
<stroke
android:width="15dp"
android:color="@android:color/white"/>
android:color="@color/translucent_white"/>
<solid android:color="@android:color/transparent"/>
</shape>
</item>
@ -23,7 +23,7 @@
android:shape="oval">
<stroke
android:width="15dp"
android:color="@android:color/white"/>
android:color="@color/translucent_white"/>
<solid android:color="@android:color/transparent"/>
</shape>
</item>
@ -35,7 +35,7 @@
android:shape="oval">
<stroke
android:width="15dp"
android:color="@android:color/white"/>
android:color="@color/translucent_white"/>
<solid android:color="@android:color/transparent"/>
</shape>
</item>

View File

@ -0,0 +1,43 @@
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:width="12dp"
android:height="12dp"
android:left="12dp"
android:top="12dp">
<shape
android:shape="oval">
<stroke
android:width="3dp"
android:color="@android:color/white"/>
<solid android:color="@android:color/transparent"/>
</shape>
</item>
<item
android:width="24dp"
android:height="24dp"
android:left="6dp"
android:top="6dp">
<shape
android:shape="oval">
<stroke
android:width="3dp"
android:color="@android:color/white"/>
<solid android:color="@android:color/transparent"/>
</shape>
</item>
<item
android:width="36dp"
android:height="36dp">
<shape
android:shape="oval">
<stroke
android:width="3dp"
android:color="@android:color/white"/>
<solid android:color="@android:color/transparent"/>
</shape>
</item>
</layer-list>

View File

@ -5,4 +5,4 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="10dp"
android:src="@mipmap/flashlight_small"/>
android:src="@drawable/circles_small"/>

View File

@ -13,7 +13,7 @@
android:layout_height="match_parent"
android:layout_above="@+id/config_widget_color"
android:scaleType="centerInside"
android:src="@mipmap/flashlight_small"/>
android:src="@drawable/circles_big"/>
<Button
android:id="@+id/config_widget_color"

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 14 KiB

View File

@ -3,6 +3,6 @@
<color name="colorPrimary">#fff68630</color>
<color name="colorPrimaryDark">#ffe27725</color>
<color name="colorAccent">@color/colorPrimary</color>
<color name="translucent_white">#aaffffff</color>
<color name="translucent_white">#ccffffff</color>
<color name="translucent_black">#88000000</color>
</resources>