|
@@ -1,16 +1,30 @@
|
|
|
package me.yoqi.screenfilter;
|
|
|
|
|
|
+import java.util.Locale;
|
|
|
+import java.util.prefs.Preferences;
|
|
|
+
|
|
|
import android.app.Activity;
|
|
|
+import android.app.AlertDialog;
|
|
|
+import android.app.Notification;
|
|
|
+import android.app.NotificationManager;
|
|
|
+import android.content.Context;
|
|
|
+import android.content.Intent;
|
|
|
+import android.content.SharedPreferences;
|
|
|
+import android.graphics.Color;
|
|
|
+import android.graphics.drawable.ColorDrawable;
|
|
|
+import android.graphics.drawable.Drawable;
|
|
|
import android.os.Bundle;
|
|
|
+import android.util.Log;
|
|
|
+import android.view.LayoutInflater;
|
|
|
import android.view.View;
|
|
|
import android.view.WindowManager;
|
|
|
-import me.yoqi.screenfilter.R;
|
|
|
-import me.yoqi.screenfilter.R.layout;
|
|
|
+import android.widget.Toast;
|
|
|
+import me.yoqi.screenfilter.service.FilterService;
|
|
|
|
|
|
public class ScreenFilterActivity extends Activity {
|
|
|
|
|
|
- public static final String ACTION_FILTER_TOGGLED = "com.haxor.ScreenFilter.ACTION_FILTER_TOGGLED";
|
|
|
- public static final String ACTION_FILTER_TOGGLED_EXTRA = "com.haxor.ScreenFilter.ACTION_FILTER_TOGGLED_EXTRA";
|
|
|
+ public static final String ACTION_FILTER_TOGGLED = "me.yoqi.ScreenFilterActivity.ACTION_FILTER_TOGGLED";
|
|
|
+ public static final String ACTION_FILTER_TOGGLED_EXTRA = "me.yoqi.ScreenFilterActivity.ACTION_FILTER_TOGGLED_EXTRA";
|
|
|
public static final int BRIGHTNESS_DEFAULT = 82;
|
|
|
public static final String NEW_BRIGHTNESS = "NEW_BRIGHTNESS";
|
|
|
public static final int NOTIFICATION_ID = 1;
|
|
@@ -24,11 +38,152 @@ public class ScreenFilterActivity extends Activity {
|
|
|
private static View toastView;
|
|
|
private static WindowManager windowManager = null;
|
|
|
|
|
|
- @Override
|
|
|
- protected void onCreate(Bundle savedInstanceState) {
|
|
|
- // TODO Auto-generated method stub
|
|
|
- super.onCreate(savedInstanceState);
|
|
|
- setContentView(R.layout.activity_screen_filter);
|
|
|
+ static {
|
|
|
+ toastView = null;
|
|
|
+ }
|
|
|
+
|
|
|
+ public static double computeAlpha(int paramInt) {
|
|
|
+ return Math.exp(4.0D * (paramInt / 100.0D) - 4.0D);
|
|
|
+ }
|
|
|
+
|
|
|
+ public static double computePercentage(int paramInt) {
|
|
|
+ return 100.0D * computeAlpha(paramInt);
|
|
|
}
|
|
|
|
|
|
+ private Drawable getBackgroundDrawable(int paramInt) {
|
|
|
+ return new ColorDrawable(Color.argb(0, 0, 0, 0));
|
|
|
+ }
|
|
|
+
|
|
|
+ public static int getBrightness(Context paramContext) {
|
|
|
+ int j = paramContext.getSharedPreferences("preferences", 0).getInt("NEW_BRIGHTNESS", -1);
|
|
|
+ int i = j;
|
|
|
+ if (j == -1) {
|
|
|
+ i = 82;
|
|
|
+ }
|
|
|
+ return i;
|
|
|
+ }
|
|
|
+
|
|
|
+ public static Notification getNotification(Context paramContext) {
|
|
|
+ double d = computePercentage(currentProgress);
|
|
|
+ Object localObject1 = String
|
|
|
+ .format(Locale.US, paramContext.getString(2131165190), new Object[] { Double.valueOf(d) }).toString();
|
|
|
+ Object localObject2 = Locale.US;
|
|
|
+ int i;
|
|
|
+ Notification localNotification = null;
|
|
|
+ if (directlyInitiated) {
|
|
|
+ i = 2131165197;
|
|
|
+ localObject2 = String
|
|
|
+ .format((Locale) localObject2, paramContext.getString(i), new Object[] { Double.valueOf(d) })
|
|
|
+ .toString();
|
|
|
+ Log.d("ScreenFilter", "Notification message: " + (String) localObject2);
|
|
|
+ localNotification = new Notification(2130837506, (CharSequence) localObject1, System.currentTimeMillis());
|
|
|
+ localNotification.flags |= 0x22;
|
|
|
+ if (directlyInitiated) {
|
|
|
+
|
|
|
+ }
|
|
|
+ localObject1 = new Intent(paramContext, Preferences.class);
|
|
|
+ }
|
|
|
+ return localNotification;
|
|
|
+ }
|
|
|
+
|
|
|
+ public static void hideFilter(Context paramContext, boolean paramBoolean) {
|
|
|
+ hideNotification(paramContext);
|
|
|
+ if (toastView != null) {
|
|
|
+ windowManager.removeView(toastView);
|
|
|
+ toastView = null;
|
|
|
+ if (!paramBoolean) {
|
|
|
+ paramContext.stopService(new Intent(paramContext, FilterService.class));
|
|
|
+ Toast.makeText(paramContext, paramContext.getString(2131165191), 0).show();
|
|
|
+ }
|
|
|
+ Intent localIntent = new Intent("com.haxor.ScreenFilter.ACTION_FILTER_TOGGLED");
|
|
|
+ localIntent.putExtra("com.haxor.ScreenFilter.ACTION_FILTER_TOGGLED_EXTRA", false);
|
|
|
+ paramContext.sendBroadcast(localIntent);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public static void hideNotification(Context paramContext) {
|
|
|
+ ((NotificationManager) paramContext.getSystemService("notification")).cancel(1);
|
|
|
+ }
|
|
|
+
|
|
|
+ public static int invertAlpha(int paramInt) {
|
|
|
+ long l = Math.max(0L, Math.min(100L, Math.round(100.0D * (Math.log(paramInt / 255.0D) / 4.0D + 1.0D))));
|
|
|
+ Log.d("Screen Filter", "Inverted alpha=" + paramInt + " to progress=" + l);
|
|
|
+ return (int) l;
|
|
|
+ }
|
|
|
+
|
|
|
+ public static boolean isEnabled() {
|
|
|
+ return toastView != null;
|
|
|
+ }
|
|
|
+
|
|
|
+ private boolean shouldShowWarning(int paramInt) {
|
|
|
+ boolean bool2 = false;
|
|
|
+ SharedPreferences localSharedPreferences = getSharedPreferences("preferences", 0);
|
|
|
+ boolean bool1 = bool2;
|
|
|
+ if (computePercentage(paramInt) < 20.0D) {
|
|
|
+ bool1 = bool2;
|
|
|
+ if (!localSharedPreferences.getBoolean("TOO_LOW_CONFIRMED", false)) {
|
|
|
+ bool1 = true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return bool1;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void showFilter(int paramInt, boolean paramBoolean) {
|
|
|
+ showToast(paramInt, paramBoolean);
|
|
|
+ Intent localIntent = new Intent("com.haxor.ScreenFilter.ACTION_FILTER_TOGGLED");
|
|
|
+ localIntent.putExtra("com.haxor.ScreenFilter.ACTION_FILTER_TOGGLED_EXTRA", true);
|
|
|
+ sendBroadcast(localIntent);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void showToast(int paramInt, boolean paramBoolean) {
|
|
|
+ toastView = ((LayoutInflater) getSystemService("layout_inflater")).inflate(2130903045, null);
|
|
|
+ toastView.setFocusable(false);
|
|
|
+ toastView.setClickable(false);
|
|
|
+ toastView.setKeepScreenOn(false);
|
|
|
+ toastView.setLongClickable(false);
|
|
|
+ toastView.setFocusableInTouchMode(false);
|
|
|
+ toastView.setBackgroundDrawable(getBackgroundDrawable(paramInt));
|
|
|
+ }
|
|
|
+
|
|
|
+ private void showWarning(int paramInt) {
|
|
|
+ Log.d("ScreenFilter", "Displaying warning dialog");
|
|
|
+ Object localObject = new Intent(this, ScreenFilterActivity.class);
|
|
|
+ ((Intent) localObject).putExtra("NEW_BRIGHTNESS", paramInt);
|
|
|
+ final Intent localIntent = new Intent(this, Preferences.class);
|
|
|
+ double d = computePercentage(paramInt);
|
|
|
+ String str = String.format(Locale.US, getString(2131165205), new Object[] { Double.valueOf(d) }).toString();
|
|
|
+
|
|
|
+ ((AlertDialog) localObject).show();
|
|
|
+ }
|
|
|
+
|
|
|
+ public void onCreate(Bundle paramBundle) {
|
|
|
+ super.onCreate(paramBundle);
|
|
|
+ Log.d("ScreenFilter", "onCreate");
|
|
|
+ onNewIntent(getIntent());
|
|
|
+ }
|
|
|
+
|
|
|
+ protected void onDestroy() {
|
|
|
+ super.onDestroy();
|
|
|
+ Log.d("ScreenFilter", "onDestroy; isFinishing=" + isFinishing());
|
|
|
+ }
|
|
|
+
|
|
|
+ public void onNewIntent(Intent paramIntent) {
|
|
|
+ Log.d("ScreenFilter", "onNewIntent: action=" + paramIntent.getAction());
|
|
|
+ int i = paramIntent.getIntExtra("NEW_BRIGHTNESS", -1);
|
|
|
+ boolean bool2 = false;
|
|
|
+ boolean bool1;
|
|
|
+ if (i == -1) {
|
|
|
+ i = getBrightness(this);
|
|
|
+ Log.d("ScreenFilter", "User-initiated filter; progress=" + i);
|
|
|
+ if (toastView == null) {
|
|
|
+ bool1 = true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ protected void onPause() {
|
|
|
+ super.onPause();
|
|
|
+ Log.d("ScreenFilter", "onPause");
|
|
|
+ }
|
|
|
}
|