Skip to content

Commit 7ad3d1c

Browse files
committed
add some icons
1 parent 270e22c commit 7ad3d1c

26 files changed

+61
-16
lines changed

app/src/main/AndroidManifest.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@
4040
android:screenOrientation="portrait"/>
4141

4242
<receiver
43-
android:name=".MyWidgetProvider">
43+
android:name=".MyWidgetProvider"
44+
android:icon="@mipmap/flashlight_small">
4445
<intent-filter>
4546
<action android:name="android.appwidget.action.APPWIDGET_UPDATE"/>
4647
</intent-filter>

app/src/main/java/com/simplemobiletools/flashlight/MainActivity.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
package com.simplemobiletools.flashlight;
22

33
import android.content.Intent;
4+
import android.graphics.PorterDuff;
45
import android.os.Bundle;
56
import android.support.v7.app.AppCompatActivity;
67
import android.view.Menu;
78
import android.view.MenuInflater;
89
import android.view.MenuItem;
910
import android.view.WindowManager;
1011
import android.widget.ImageView;
11-
import android.widget.Toast;
1212

1313
import butterknife.BindView;
1414
import butterknife.ButterKnife;
@@ -82,20 +82,21 @@ protected void onStop() {
8282

8383
@Override
8484
public void enableFlashlight() {
85-
toggleBtn.setImageResource(R.mipmap.flashlight_big_on);
85+
final int appColor = getResources().getColor(R.color.colorPrimary);
86+
toggleBtn.setImageResource(R.mipmap.flashlight_big);
87+
toggleBtn.getDrawable().mutate().setColorFilter(appColor, PorterDuff.Mode.SRC_IN);
8688
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
8789
}
8890

8991
@Override
9092
public void disableFlashlight() {
91-
toggleBtn.setImageResource(R.mipmap.flashlight_big_off);
93+
toggleBtn.setImageResource(R.mipmap.flashlight_big);
9294
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
9395
}
9496

9597
@Override
9698
public void cameraUnavailable() {
97-
final String errorMsg = getResources().getString(R.string.camera_error);
98-
Toast.makeText(this, errorMsg, Toast.LENGTH_SHORT).show();
99+
Utils.showToast(this, R.string.camera_error);
99100
disableFlashlight();
100101
}
101102
}

app/src/main/java/com/simplemobiletools/flashlight/MyWidgetProvider.java

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,18 @@
66
import android.content.ComponentName;
77
import android.content.Context;
88
import android.content.Intent;
9+
import android.content.res.Resources;
10+
import android.graphics.Bitmap;
911
import android.widget.RemoteViews;
1012

1113
public class MyWidgetProvider extends AppWidgetProvider implements MyCamera {
1214
private static MyCameraImpl cameraImpl;
1315
private static RemoteViews remoteViews;
16+
private static Context cxt;
1417
private static int[] widgetIds;
1518
private static AppWidgetManager widgetManager;
1619
private static final String TOGGLE = "toggle";
20+
private static Bitmap coloredBmp;
1721

1822
@Override
1923
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
@@ -22,17 +26,22 @@ public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] a
2226
}
2327

2428
private void initVariables(Context context) {
25-
final ComponentName component = new ComponentName(context, MyWidgetProvider.class);
29+
cxt = context;
30+
final ComponentName component = new ComponentName(cxt, MyWidgetProvider.class);
2631
widgetManager = AppWidgetManager.getInstance(context);
2732
widgetIds = widgetManager.getAppWidgetIds(component);
2833

29-
final Intent intent = new Intent(context, MyWidgetProvider.class);
34+
final Intent intent = new Intent(cxt, MyWidgetProvider.class);
3035
intent.setAction(TOGGLE);
3136

32-
final PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, intent, 0);
33-
remoteViews = new RemoteViews(context.getPackageName(), R.layout.widget);
37+
final PendingIntent pendingIntent = PendingIntent.getBroadcast(cxt, 0, intent, 0);
38+
remoteViews = new RemoteViews(cxt.getPackageName(), R.layout.widget);
3439
remoteViews.setOnClickPendingIntent(R.id.toggle_btn, pendingIntent);
3540
cameraImpl = new MyCameraImpl(this);
41+
42+
final Resources res = cxt.getResources();
43+
final int appColor = res.getColor(R.color.colorPrimary);
44+
coloredBmp = Utils.getColoredIcon(cxt.getResources(), appColor, R.mipmap.flashlight_small);
3645
}
3746

3847
@Override
@@ -50,15 +59,15 @@ public void onReceive(Context context, Intent intent) {
5059

5160
@Override
5261
public void enableFlashlight() {
53-
remoteViews.setImageViewResource(R.id.toggle_btn, R.mipmap.flashlight_big_on);
62+
remoteViews.setImageViewBitmap(R.id.toggle_btn, coloredBmp);
5463
for (int widgetId : widgetIds) {
5564
widgetManager.updateAppWidget(widgetId, remoteViews);
5665
}
5766
}
5867

5968
@Override
6069
public void disableFlashlight() {
61-
remoteViews.setImageViewResource(R.id.toggle_btn, R.mipmap.flashlight_big_off);
70+
remoteViews.setImageViewResource(R.id.toggle_btn, R.mipmap.flashlight_small);
6271
for (int widgetId : widgetIds) {
6372
widgetManager.updateAppWidget(widgetId, remoteViews);
6473
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package com.simplemobiletools.flashlight;
2+
3+
import android.content.Context;
4+
import android.content.res.Resources;
5+
import android.graphics.Bitmap;
6+
import android.graphics.BitmapFactory;
7+
import android.graphics.Canvas;
8+
import android.graphics.ColorFilter;
9+
import android.graphics.Paint;
10+
import android.graphics.PorterDuff;
11+
import android.graphics.PorterDuffColorFilter;
12+
import android.widget.Toast;
13+
14+
public class Utils {
15+
public static Bitmap getColoredIcon(Resources res, int newTextColor, int id) {
16+
final BitmapFactory.Options options = new BitmapFactory.Options();
17+
options.inMutable = true;
18+
final Bitmap bmp = BitmapFactory.decodeResource(res, id, options);
19+
final Paint paint = new Paint();
20+
final ColorFilter filter = new PorterDuffColorFilter(newTextColor, PorterDuff.Mode.SRC_IN);
21+
paint.setColorFilter(filter);
22+
final Canvas canvas = new Canvas(bmp);
23+
canvas.drawBitmap(bmp, 0, 0, paint);
24+
return bmp;
25+
}
26+
27+
public static void showToast(Context context, int resId) {
28+
Toast.makeText(context, context.getResources().getString(resId), Toast.LENGTH_SHORT).show();
29+
}
30+
}

app/src/main/res/layout/activity_main.xml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,13 @@
33
xmlns:android="http://schemas.android.com/apk/res/android"
44
android:layout_width="match_parent"
55
android:layout_height="match_parent"
6-
android:paddingBottom="@dimen/activity_margin">
6+
android:background="@android:color/black"
7+
android:gravity="center"
8+
android:padding="@dimen/activity_margin">
79

810
<ImageView
911
android:id="@+id/toggle_btn"
10-
android:layout_width="match_parent"
11-
android:layout_height="match_parent"/>
12+
android:layout_width="wrap_content"
13+
android:layout_height="wrap_content"
14+
android:src="@mipmap/flashlight_big"/>
1215
</RelativeLayout>

app/src/main/res/layout/widget.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@
44
xmlns:android="http://schemas.android.com/apk/res/android"
55
android:layout_width="match_parent"
66
android:layout_height="match_parent"
7-
android:src="@mipmap/flashlight_big_off"/>
7+
android:padding="10dp"
8+
android:src="@mipmap/flashlight_small"/>
13.6 KB
Loading
-1.37 KB
Binary file not shown.
-1.3 KB
Binary file not shown.
4.52 KB
Loading

0 commit comments

Comments
 (0)