add some icons

This commit is contained in:
tibbi 2016-06-04 13:39:00 +02:00
parent 270e22c9e6
commit 7ad3d1c327
26 changed files with 61 additions and 16 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 836 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 821 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 25 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 39 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 68 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB