add some icons
@ -40,7 +40,8 @@
|
||||
android:screenOrientation="portrait"/>
|
||||
|
||||
<receiver
|
||||
android:name=".MyWidgetProvider">
|
||||
android:name=".MyWidgetProvider"
|
||||
android:icon="@mipmap/flashlight_small">
|
||||
<intent-filter>
|
||||
<action android:name="android.appwidget.action.APPWIDGET_UPDATE"/>
|
||||
</intent-filter>
|
||||
|
@ -1,6 +1,7 @@
|
||||
package com.simplemobiletools.flashlight;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.graphics.PorterDuff;
|
||||
import android.os.Bundle;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.view.Menu;
|
||||
@ -8,7 +9,6 @@ import android.view.MenuInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
@ -82,20 +82,21 @@ public class MainActivity extends AppCompatActivity implements MyCamera {
|
||||
|
||||
@Override
|
||||
public void enableFlashlight() {
|
||||
toggleBtn.setImageResource(R.mipmap.flashlight_big_on);
|
||||
final int appColor = getResources().getColor(R.color.colorPrimary);
|
||||
toggleBtn.setImageResource(R.mipmap.flashlight_big);
|
||||
toggleBtn.getDrawable().mutate().setColorFilter(appColor, PorterDuff.Mode.SRC_IN);
|
||||
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disableFlashlight() {
|
||||
toggleBtn.setImageResource(R.mipmap.flashlight_big_off);
|
||||
toggleBtn.setImageResource(R.mipmap.flashlight_big);
|
||||
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cameraUnavailable() {
|
||||
final String errorMsg = getResources().getString(R.string.camera_error);
|
||||
Toast.makeText(this, errorMsg, Toast.LENGTH_SHORT).show();
|
||||
Utils.showToast(this, R.string.camera_error);
|
||||
disableFlashlight();
|
||||
}
|
||||
}
|
||||
|
@ -6,14 +6,18 @@ import android.appwidget.AppWidgetProvider;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.res.Resources;
|
||||
import android.graphics.Bitmap;
|
||||
import android.widget.RemoteViews;
|
||||
|
||||
public class MyWidgetProvider extends AppWidgetProvider implements MyCamera {
|
||||
private static MyCameraImpl cameraImpl;
|
||||
private static RemoteViews remoteViews;
|
||||
private static Context cxt;
|
||||
private static int[] widgetIds;
|
||||
private static AppWidgetManager widgetManager;
|
||||
private static final String TOGGLE = "toggle";
|
||||
private static Bitmap coloredBmp;
|
||||
|
||||
@Override
|
||||
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
|
||||
@ -22,17 +26,22 @@ public class MyWidgetProvider extends AppWidgetProvider implements MyCamera {
|
||||
}
|
||||
|
||||
private void initVariables(Context context) {
|
||||
final ComponentName component = new ComponentName(context, MyWidgetProvider.class);
|
||||
cxt = context;
|
||||
final ComponentName component = new ComponentName(cxt, MyWidgetProvider.class);
|
||||
widgetManager = AppWidgetManager.getInstance(context);
|
||||
widgetIds = widgetManager.getAppWidgetIds(component);
|
||||
|
||||
final Intent intent = new Intent(context, MyWidgetProvider.class);
|
||||
final Intent intent = new Intent(cxt, MyWidgetProvider.class);
|
||||
intent.setAction(TOGGLE);
|
||||
|
||||
final PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, intent, 0);
|
||||
remoteViews = new RemoteViews(context.getPackageName(), R.layout.widget);
|
||||
final PendingIntent pendingIntent = PendingIntent.getBroadcast(cxt, 0, intent, 0);
|
||||
remoteViews = new RemoteViews(cxt.getPackageName(), R.layout.widget);
|
||||
remoteViews.setOnClickPendingIntent(R.id.toggle_btn, pendingIntent);
|
||||
cameraImpl = new MyCameraImpl(this);
|
||||
|
||||
final Resources res = cxt.getResources();
|
||||
final int appColor = res.getColor(R.color.colorPrimary);
|
||||
coloredBmp = Utils.getColoredIcon(cxt.getResources(), appColor, R.mipmap.flashlight_small);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -50,7 +59,7 @@ public class MyWidgetProvider extends AppWidgetProvider implements MyCamera {
|
||||
|
||||
@Override
|
||||
public void enableFlashlight() {
|
||||
remoteViews.setImageViewResource(R.id.toggle_btn, R.mipmap.flashlight_big_on);
|
||||
remoteViews.setImageViewBitmap(R.id.toggle_btn, coloredBmp);
|
||||
for (int widgetId : widgetIds) {
|
||||
widgetManager.updateAppWidget(widgetId, remoteViews);
|
||||
}
|
||||
@ -58,7 +67,7 @@ public class MyWidgetProvider extends AppWidgetProvider implements MyCamera {
|
||||
|
||||
@Override
|
||||
public void disableFlashlight() {
|
||||
remoteViews.setImageViewResource(R.id.toggle_btn, R.mipmap.flashlight_big_off);
|
||||
remoteViews.setImageViewResource(R.id.toggle_btn, R.mipmap.flashlight_small);
|
||||
for (int widgetId : widgetIds) {
|
||||
widgetManager.updateAppWidget(widgetId, remoteViews);
|
||||
}
|
||||
|
@ -0,0 +1,30 @@
|
||||
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.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 void showToast(Context context, int resId) {
|
||||
Toast.makeText(context, context.getResources().getString(resId), Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
@ -3,10 +3,13 @@
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:paddingBottom="@dimen/activity_margin">
|
||||
android:background="@android:color/black"
|
||||
android:gravity="center"
|
||||
android:padding="@dimen/activity_margin">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/toggle_btn"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"/>
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:src="@mipmap/flashlight_big"/>
|
||||
</RelativeLayout>
|
||||
|
@ -4,4 +4,5 @@
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:src="@mipmap/flashlight_big_off"/>
|
||||
android:padding="10dp"
|
||||
android:src="@mipmap/flashlight_small"/>
|
||||
|
BIN
app/src/main/res/mipmap-hdpi/flashlight_big.png
Normal file
After Width: | Height: | Size: 14 KiB |
Before Width: | Height: | Size: 1.4 KiB |
Before Width: | Height: | Size: 1.3 KiB |
BIN
app/src/main/res/mipmap-hdpi/flashlight_small.png
Normal file
After Width: | Height: | Size: 4.5 KiB |
BIN
app/src/main/res/mipmap-mdpi/flashlight_big.png
Normal file
After Width: | Height: | Size: 10 KiB |
Before Width: | Height: | Size: 836 B |
Before Width: | Height: | Size: 821 B |
BIN
app/src/main/res/mipmap-mdpi/flashlight_small.png
Normal file
After Width: | Height: | Size: 3.0 KiB |
BIN
app/src/main/res/mipmap-xhdpi/flashlight_big.png
Normal file
After Width: | Height: | Size: 25 KiB |
Before Width: | Height: | Size: 1.6 KiB |
Before Width: | Height: | Size: 1.6 KiB |
BIN
app/src/main/res/mipmap-xhdpi/flashlight_small.png
Normal file
After Width: | Height: | Size: 6.3 KiB |
BIN
app/src/main/res/mipmap-xxhdpi/flashlight_big.png
Normal file
After Width: | Height: | Size: 39 KiB |
Before Width: | Height: | Size: 3.1 KiB |
Before Width: | Height: | Size: 3.0 KiB |
BIN
app/src/main/res/mipmap-xxhdpi/flashlight_small.png
Normal file
After Width: | Height: | Size: 10 KiB |
BIN
app/src/main/res/mipmap-xxxhdpi/flashlight_big.png
Normal file
After Width: | Height: | Size: 68 KiB |
Before Width: | Height: | Size: 3.0 KiB |
Before Width: | Height: | Size: 3.3 KiB |
BIN
app/src/main/res/mipmap-xxxhdpi/flashlight_small.png
Normal file
After Width: | Height: | Size: 14 KiB |