mirror of
https://github.com/SimpleMobileTools/Simple-Flashlight.git
synced 2025-02-11 01:10:35 +01:00
update the flashlight widget behaviour
This commit is contained in:
parent
b01b499bf2
commit
167c26dff4
@ -9,6 +9,7 @@ import android.content.Intent;
|
|||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
|
import android.graphics.Color;
|
||||||
import android.graphics.PorterDuff;
|
import android.graphics.PorterDuff;
|
||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
import android.widget.RemoteViews;
|
import android.widget.RemoteViews;
|
||||||
@ -22,6 +23,7 @@ public class MyWidgetProvider extends AppWidgetProvider {
|
|||||||
private static RemoteViews mRemoteViews;
|
private static RemoteViews mRemoteViews;
|
||||||
private static AppWidgetManager mWidgetManager;
|
private static AppWidgetManager mWidgetManager;
|
||||||
private static Bitmap mColoredBmp;
|
private static Bitmap mColoredBmp;
|
||||||
|
private static Bitmap mWhiteBmp;
|
||||||
private static Bus mBus;
|
private static Bus mBus;
|
||||||
private static Context mContext;
|
private static Context mContext;
|
||||||
|
|
||||||
@ -50,11 +52,12 @@ public class MyWidgetProvider extends AppWidgetProvider {
|
|||||||
final SharedPreferences prefs = initPrefs(context);
|
final SharedPreferences prefs = initPrefs(context);
|
||||||
final Resources res = context.getResources();
|
final Resources res = context.getResources();
|
||||||
final int defaultColor = res.getColor(R.color.colorPrimary);
|
final int defaultColor = res.getColor(R.color.colorPrimary);
|
||||||
final int appColor = prefs.getInt(Constants.WIDGET_COLOR, defaultColor);
|
final int selectedColor = prefs.getInt(Constants.WIDGET_COLOR, defaultColor);
|
||||||
|
final int alpha = Color.alpha(selectedColor);
|
||||||
|
|
||||||
final Drawable drawable = context.getResources().getDrawable(R.drawable.circles_small);
|
mColoredBmp = getColoredCircles(selectedColor, alpha);
|
||||||
drawable.mutate().setColorFilter(appColor, PorterDuff.Mode.SRC_ATOP);
|
mWhiteBmp = getColoredCircles(Color.WHITE, alpha);
|
||||||
mColoredBmp = Utils.drawableToBitmap(drawable);
|
mRemoteViews.setImageViewBitmap(R.id.toggle_btn, mWhiteBmp);
|
||||||
|
|
||||||
if (mBus == null) {
|
if (mBus == null) {
|
||||||
mBus = BusProvider.getInstance();
|
mBus = BusProvider.getInstance();
|
||||||
@ -75,6 +78,13 @@ public class MyWidgetProvider extends AppWidgetProvider {
|
|||||||
super.onReceive(context, intent);
|
super.onReceive(context, intent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Bitmap getColoredCircles(int color, int alpha) {
|
||||||
|
final Drawable drawable = mContext.getResources().getDrawable(R.drawable.circles_small);
|
||||||
|
drawable.mutate().setColorFilter(color, PorterDuff.Mode.SRC_ATOP);
|
||||||
|
drawable.mutate().setAlpha(alpha);
|
||||||
|
return Utils.drawableToBitmap(drawable);
|
||||||
|
}
|
||||||
|
|
||||||
public void enableFlashlight() {
|
public void enableFlashlight() {
|
||||||
mRemoteViews.setImageViewBitmap(R.id.toggle_btn, mColoredBmp);
|
mRemoteViews.setImageViewBitmap(R.id.toggle_btn, mColoredBmp);
|
||||||
for (int widgetId : mWidgetIds) {
|
for (int widgetId : mWidgetIds) {
|
||||||
@ -83,7 +93,7 @@ public class MyWidgetProvider extends AppWidgetProvider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void disableFlashlight() {
|
public void disableFlashlight() {
|
||||||
mRemoteViews.setImageViewResource(R.id.toggle_btn, R.drawable.circles_small);
|
mRemoteViews.setImageViewBitmap(R.id.toggle_btn, mWhiteBmp);
|
||||||
for (int widgetId : mWidgetIds) {
|
for (int widgetId : mWidgetIds) {
|
||||||
mWidgetManager.updateAppWidget(widgetId, mRemoteViews);
|
mWidgetManager.updateAppWidget(widgetId, mRemoteViews);
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
|
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
<item
|
<item
|
||||||
android:width="24dp"
|
android:bottom="24dp"
|
||||||
android:height="24dp"
|
|
||||||
android:left="24dp"
|
android:left="24dp"
|
||||||
|
android:right="24dp"
|
||||||
android:top="24dp">
|
android:top="24dp">
|
||||||
<shape
|
<shape
|
||||||
android:shape="oval">
|
android:shape="oval">
|
||||||
@ -15,9 +15,9 @@
|
|||||||
</item>
|
</item>
|
||||||
|
|
||||||
<item
|
<item
|
||||||
android:width="48dp"
|
android:bottom="12dp"
|
||||||
android:height="48dp"
|
|
||||||
android:left="12dp"
|
android:left="12dp"
|
||||||
|
android:right="12dp"
|
||||||
android:top="12dp">
|
android:top="12dp">
|
||||||
<shape
|
<shape
|
||||||
android:shape="oval">
|
android:shape="oval">
|
||||||
@ -28,9 +28,7 @@
|
|||||||
</shape>
|
</shape>
|
||||||
</item>
|
</item>
|
||||||
|
|
||||||
<item
|
<item>
|
||||||
android:width="72dp"
|
|
||||||
android:height="72dp">
|
|
||||||
<shape
|
<shape
|
||||||
android:shape="oval">
|
android:shape="oval">
|
||||||
<stroke
|
<stroke
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<ImageView
|
<ImageView
|
||||||
android:id="@+id/toggle_btn"
|
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:layout_width="match_parent"
|
android:id="@+id/toggle_btn"
|
||||||
android:layout_height="match_parent"
|
android:layout_width="60dp"
|
||||||
android:padding="10dp"
|
android:layout_height="60dp"/>
|
||||||
android:src="@drawable/circles_small"/>
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user