Browse Source

有点错误。

liuyuqi-dellpc 5 years ago
parent
commit
48d877c623

+ 2 - 2
AndroidManifest.xml

@@ -1,8 +1,8 @@
 <?xml version="1.0" encoding="utf-8"?>
 <?xml version="1.0" encoding="utf-8"?>
 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
     package="me.yoqi.screenfilter"
     package="me.yoqi.screenfilter"
-    android:versionCode="1"
-    android:versionName="1.0" >
+    android:versionCode="2"
+    android:versionName="1.0.1" >
 
 
     <uses-sdk
     <uses-sdk
         android:minSdkVersion="8"
         android:minSdkVersion="8"

BIN
ic_launcher-web.png


+ 6 - 5
res/drawable/widget_icon.xml

@@ -1,7 +1,8 @@
 <?xml version="1.0" encoding="utf-8"?>
 <?xml version="1.0" encoding="utf-8"?>
-<selector
-  xmlns:android="http://schemas.android.com/apk/res/android">
-    <item android:state_pressed="true" android:drawable="@drawable/icon_pressed" />
-    <item android:state_focused="true" android:state_pressed="false" android:drawable="@drawable/icon" />
-    <item android:drawable="@drawable/icon" />
+<selector xmlns:android="http://schemas.android.com/apk/res/android">
+
+    <item android:drawable="@drawable/icon_pressed" android:state_pressed="true"/>
+    <item android:drawable="@drawable/icon" android:state_focused="true" android:state_pressed="false"/>
+    <item android:drawable="@drawable/icon"/>
+
 </selector>
 </selector>

+ 1 - 2
res/layout/activity_screen_filter.xml

@@ -3,6 +3,5 @@
     android:layout_width="match_parent"
     android:layout_width="match_parent"
     android:layout_height="match_parent"
     android:layout_height="match_parent"
     android:orientation="vertical" >
     android:orientation="vertical" >
-    
 
 
-</LinearLayout>
+</LinearLayout>

+ 0 - 16
res/layout/activity_settings.xml

@@ -1,16 +0,0 @@
-<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:tools="http://schemas.android.com/tools"
-    android:layout_width="match_parent"
-    android:layout_height="match_parent"
-    android:paddingBottom="@dimen/activity_vertical_margin"
-    android:paddingLeft="@dimen/activity_horizontal_margin"
-    android:paddingRight="@dimen/activity_horizontal_margin"
-    android:paddingTop="@dimen/activity_vertical_margin"
-    tools:context="me.yoqi.screenfilter.ui.SettingsActivity" >
-
-    <TextView
-        android:layout_width="wrap_content"
-        android:layout_height="wrap_content"
-        android:text="@string/app_name" />
-
-</RelativeLayout>

+ 1 - 1
res/layout/configure_widget.xml

@@ -4,7 +4,7 @@
     android:layout_height="fill_parent"
     android:layout_height="fill_parent"
     android:orientation="vertical" >
     android:orientation="vertical" >
 
 
-    <com.haxor.BrightnessSelector
+    <me.yoqi.screenfilter.BrightnessSelector
         android:id="@+id/PreferencesBrightnessSelector"
         android:id="@+id/PreferencesBrightnessSelector"
         android:layout_width="fill_parent"
         android:layout_width="fill_parent"
         android:layout_height="wrap_content"
         android:layout_height="wrap_content"

+ 1 - 3
res/layout/locale_edit.xml

@@ -4,7 +4,7 @@
     android:layout_height="fill_parent"
     android:layout_height="fill_parent"
     android:orientation="vertical" >
     android:orientation="vertical" >
 
 
-    <com.haxor.BrightnessSelector
+    <me.yoqi.screenfilter.BrightnessSelector
         android:id="@+id/PreferencesBrightnessSelector"
         android:id="@+id/PreferencesBrightnessSelector"
         android:layout_width="fill_parent"
         android:layout_width="fill_parent"
         android:layout_height="wrap_content"
         android:layout_height="wrap_content"
@@ -15,9 +15,7 @@
         android:layout_height="wrap_content"
         android:layout_height="wrap_content"
         android:layout_weight="0.0"
         android:layout_weight="0.0"
         android:stretchColumns="*" >
         android:stretchColumns="*" >
-
         <TableRow>
         <TableRow>
-
             <Button
             <Button
                 android:id="@+id/DontSaveSettingButton"
                 android:id="@+id/DontSaveSettingButton"
                 android:text="@string/dont_save_setting"
                 android:text="@string/dont_save_setting"

+ 1 - 1
res/layout/preferences.xml

@@ -14,7 +14,7 @@
         android:text="@string/reenable_button"
         android:text="@string/reenable_button"
         android:textSize="18.0dip" />
         android:textSize="18.0dip" />
 
 
-    <com.haxor.BrightnessSelector
+    <me.yoqi.screenfilter.BrightnessSelector
         android:id="@+id/PreferencesBrightnessSelector"
         android:id="@+id/PreferencesBrightnessSelector"
         android:layout_width="fill_parent"
         android:layout_width="fill_parent"
         android:layout_height="wrap_content" />
         android:layout_height="wrap_content" />

+ 128 - 0
src/me/yoqi/screenfilter/BrightnessSelector.java

@@ -0,0 +1,128 @@
+package me.yoqi.screenfilter;
+
+import android.app.AlertDialog;
+import android.app.AlertDialog.Builder;
+import android.content.Context;
+import android.content.DialogInterface;
+import android.content.DialogInterface.OnClickListener;
+import android.graphics.Color;
+import android.text.Editable;
+import android.util.AttributeSet;
+import android.util.Log;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.widget.Button;
+import android.widget.CheckBox;
+import android.widget.EditText;
+import android.widget.RelativeLayout;
+import android.widget.SeekBar;
+import android.widget.SeekBar.OnSeekBarChangeListener;
+import android.widget.TextView;
+import java.util.Locale;
+
+/**
+ * 
+ * @author liuyuqi
+ *
+ */
+public class BrightnessSelector extends RelativeLayout {
+	private SeekBar brightnessAdjust;
+	private CheckBox softKeysEnabled;
+
+	public BrightnessSelector(Context context, AttributeSet attrs2) {
+		super(context, attrs2);
+		View attrs = ((LayoutInflater) context.getSystemService("layout_inflater"))
+				.inflate(R.layout.brightness_selector, null);
+		this.brightnessAdjust = ((SeekBar) attrs.findViewById(R.id.BrightnessSeekBar));
+		this.brightnessAdjust.setOnSeekBarChangeListener(new ProgressChangedHandler());
+		this.softKeysEnabled = ((CheckBox) attrs.findViewById(R.id.SoftKeysEnabled));
+		((Button) attrs.findViewById(R.id.BrightnessEdit)).setOnClickListener(new View.OnClickListener() {
+			public void onClick(View paramAnonymousView) {
+				paramAnonymousView = new EditText(context);
+				paramAnonymousView.setInputType(3);
+				new AlertDialog.Builder(context).setTitle(context.getString(2131165211))
+						.setMessage(context.getString(2131165212)).setView(paramAnonymousView)
+						.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
+							public void onClick(DialogInterface paramAnonymous2DialogInterface,
+									int paramAnonymous2Int) {
+								str = paramAnonymousView.getText().toString();
+								paramAnonymous2Int = -1;
+								try {
+									int i = Integer.parseInt(str);
+									paramAnonymous2Int = i;
+								} catch (NumberFormatException localNumberFormatException) {
+									for (;;) {
+										Log.e("BrightnessSelector", "Bad user input: " + str);
+										continue;
+										Log.e("BrightnessSelector", "User input out of range: " + str);
+									}
+								}
+								if ((paramAnonymous2Int >= 0) && (paramAnonymous2Int <= 100)) {
+									BrightnessSelector.this.setProgress(ScreenFilterActivity
+											.invertAlpha((int) Math.round(paramAnonymous2Int * 255.0D / 100.0D)));
+									paramAnonymous2DialogInterface.dismiss();
+									return;
+								}
+							}
+						}).setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
+							public void onClick(DialogInterface paramAnonymous2DialogInterface,
+									int paramAnonymous2Int) {
+								paramAnonymous2DialogInterface.dismiss();
+							}
+						}).create().show();
+			}
+		});
+		addView(attrs);
+		setProgress(82);
+	}
+
+	private void setExampleBrightness(int paramInt) {
+		((TextView) findViewById(2131034121)).setTextColor(
+				Color.argb((int) Math.round(ScreenFilterActivity.computeAlpha(paramInt) * 255.0D), 255, 255, 255));
+		TextView localTextView = (TextView) findViewById(2131034120);
+		String str = String.format(Locale.US, "%.1f%%",
+				new Object[] { Double.valueOf(ScreenFilterActivity.computePercentage(paramInt)) }).toString();
+		if (paramInt == 100) {
+			str = "100%";
+		}
+		localTextView.setText(str);
+	}
+
+	public int getProgress() {
+		return this.brightnessAdjust.getProgress();
+	}
+
+	public boolean isSoftKeysEnabled() {
+		return this.softKeysEnabled.isChecked();
+	}
+
+	public void setProgress(int paramInt) {
+		this.brightnessAdjust.setProgress(paramInt);
+		setExampleBrightness(paramInt);
+	}
+
+	public void setSoftKeysEnabled(boolean flag) {
+		this.softKeysEnabled.setChecked(flag);
+	}
+
+	/**
+	 * 进度条监听事件
+	 * 
+	 * @author liuyuqi
+	 *
+	 */
+	private class ProgressChangedHandler implements SeekBar.OnSeekBarChangeListener {
+		private ProgressChangedHandler() {
+		}
+
+		public void onProgressChanged(SeekBar paramSeekBar, int paramInt, boolean paramBoolean) {
+			BrightnessSelector.this.setExampleBrightness(paramInt);
+		}
+
+		public void onStartTrackingTouch(SeekBar paramSeekBar) {
+		}
+
+		public void onStopTrackingTouch(SeekBar paramSeekBar) {
+		}
+	}
+}

+ 0 - 5
src/me/yoqi/screenfilter/FilterWidget.java

@@ -1,5 +0,0 @@
-package me.yoqi.screenfilter;
-
-public class FilterWidget {
-
-}

+ 164 - 9
src/me/yoqi/screenfilter/ScreenFilterActivity.java

@@ -1,16 +1,30 @@
 package me.yoqi.screenfilter;
 package me.yoqi.screenfilter;
 
 
+import java.util.Locale;
+import java.util.prefs.Preferences;
+
 import android.app.Activity;
 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.os.Bundle;
+import android.util.Log;
+import android.view.LayoutInflater;
 import android.view.View;
 import android.view.View;
 import android.view.WindowManager;
 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 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 int BRIGHTNESS_DEFAULT = 82;
 	public static final String NEW_BRIGHTNESS = "NEW_BRIGHTNESS";
 	public static final String NEW_BRIGHTNESS = "NEW_BRIGHTNESS";
 	public static final int NOTIFICATION_ID = 1;
 	public static final int NOTIFICATION_ID = 1;
@@ -24,11 +38,152 @@ public class ScreenFilterActivity extends Activity {
 	private static View toastView;
 	private static View toastView;
 	private static WindowManager windowManager = null;
 	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");
+	}
 }
 }

+ 98 - 1
src/me/yoqi/screenfilter/receiver/ScreenFilterWidget.java

@@ -1,5 +1,102 @@
 package me.yoqi.screenfilter.receiver;
 package me.yoqi.screenfilter.receiver;
 
 
-public class ScreenFilterWidget {
+import android.app.PendingIntent;
+import android.appwidget.AppWidgetManager;
+import android.appwidget.AppWidgetProvider;
+import android.content.ComponentName;
+import android.content.Context;
+import android.content.Intent;
+import android.content.SharedPreferences;
+import android.content.SharedPreferences.Editor;
+import android.util.Log;
+import android.widget.RemoteViews;
+import me.yoqi.screenfilter.ScreenFilterActivity;
 
 
+import java.util.Locale;
+
+public class ScreenFilterWidget extends AppWidgetProvider {
+	public static void updateWidget(Context paramContext, AppWidgetManager paramAppWidgetManager, int paramInt) {
+		Object localObject1 = paramContext.getSharedPreferences("preferences", 0);
+		Object localObject2 = "NEW_BRIGHTNESS:" + paramInt;
+		String str = "SOFT_KEYS_ENABLED:" + paramInt;
+		int i = ((SharedPreferences) localObject1).getInt((String) localObject2, -1);
+		boolean bool = ((SharedPreferences) localObject1).getBoolean(str, true);
+		if (i == -1) {
+			Log.e("ScreenFilterWidget", "Could not find preferences for widgetId=" + paramInt);
+			return;
+		}
+		localObject1 = new Intent(paramContext, ScreenFilterActivity.class);
+		if (!ScreenFilterActivity.isEnabled()) {
+			Log.d("ScreenFilterWidget",
+					"Updating display for widgetId=" + paramInt + ", progress=" + i + ", softKeys=" + bool);
+			((Intent) localObject1).setAction("Activate:" + paramInt);
+			((Intent) localObject1).putExtra("NEW_BRIGHTNESS", i);
+			((Intent) localObject1).putExtra("SOFT_KEYS_ENABLED", bool);
+		}
+		for (;;) {
+			localObject1 = PendingIntent.getActivity(paramContext, 0, (Intent) localObject1, 134217728);
+			double d = ScreenFilter.computePercentage(i);
+			localObject2 = new RemoteViews(paramContext.getPackageName(), 2130903044);
+			((RemoteViews) localObject2).setTextViewText(2131034128,
+					String.format(Locale.US, paramContext.getString(2131165209), new Object[] { Double.valueOf(d) })
+							.toString());
+			((RemoteViews) localObject2).setOnClickPendingIntent(2131034127, (PendingIntent) localObject1);
+			paramAppWidgetManager.updateAppWidget(paramInt, (RemoteViews) localObject2);
+			return;
+			Log.d("ScreenFilterWidget", "Toggling widget to disable mode widgetId=" + paramInt);
+			((Intent) localObject1).setAction("Deactivate:" + paramInt);
+			((Intent) localObject1).putExtra("NEW_BRIGHTNESS", 100);
+			((Intent) localObject1).putExtra("SOFT_KEYS_ENABLED", true);
+		}
+	}
+
+	public void onDeleted(Context paramContext, int[] paramArrayOfInt) {
+		int i = 0;
+		super.onDeleted(paramContext, paramArrayOfInt);
+		paramContext = paramContext.getSharedPreferences("preferences", 0);
+		int j = paramArrayOfInt.length;
+		for (;;) {
+			if (i >= j) {
+				return;
+			}
+			int k = paramArrayOfInt[i];
+			String str1 = "NEW_BRIGHTNESS:" + k;
+			String str2 = "SOFT_KEYS_ENABLED:" + k;
+			Log.d("ScreenFilterWidget", "Removing preferences for widgetId=" + k);
+			paramContext.edit().remove(str1).remove(str2).commit();
+			i += 1;
+		}
+	}
+
+	public void onReceive(Context paramContext, Intent paramIntent) {
+		int i = 0;
+		if (paramIntent.getAction().equals("com.haxor.ScreenFilter.ACTION_FILTER_TOGGLED")) {
+			boolean bool = paramIntent.getBooleanExtra("com.haxor.ScreenFilter.ACTION_FILTER_TOGGLED_EXTRA", false);
+			Log.d("ScreenFilterWidget", "Filter toggle received, enabling=" + bool);
+			paramIntent = AppWidgetManager.getInstance(paramContext);
+			int[] arrayOfInt = paramIntent.getAppWidgetIds(new ComponentName(paramContext, ScreenFilterWidget.class));
+			int j = arrayOfInt.length;
+			for (;;) {
+				if (i >= j) {
+					return;
+				}
+				updateWidget(paramContext, paramIntent, arrayOfInt[i]);
+				i += 1;
+			}
+		}
+		super.onReceive(paramContext, paramIntent);
+	}
+
+	public void onUpdate(Context paramContext, AppWidgetManager paramAppWidgetManager, int[] paramArrayOfInt) {
+		super.onUpdate(paramContext, paramAppWidgetManager, paramArrayOfInt);
+		int j = paramArrayOfInt.length;
+		int i = 0;
+		for (;;) {
+			if (i >= j) {
+				return;
+			}
+			updateWidget(paramContext, paramAppWidgetManager, paramArrayOfInt[i]);
+			i += 1;
+		}
+	}
 }
 }

+ 38 - 38
src/me/yoqi/screenfilter/service/FilterService.java

@@ -7,6 +7,7 @@ import android.content.Intent;
 import android.os.Binder;
 import android.os.Binder;
 import android.os.IBinder;
 import android.os.IBinder;
 import android.util.Log;
 import android.util.Log;
+import me.yoqi.screenfilter.ScreenFilterActivity;
 
 
 public class FilterService extends Service {
 public class FilterService extends Service {
 
 
@@ -16,46 +17,45 @@ public class FilterService extends Service {
 		return this.binder;
 		return this.binder;
 	}
 	}
 
 
-//	public void onCreate() {
-//		super.onCreate();
-//		Log.d("FilterService", "onCreate");
-//		Notification localNotification = ScreenFilterActivity.getNotification(getBaseContext());
-//		try {
-//			getClass().getMethod("startForeground", new Class[] { Integer.TYPE, Notification.class }).invoke(this,
-//					new Object[] { Integer.valueOf(1), localNotification });
-//			return;
-//		} catch (Exception localException) {
-//			Log.w("ScreenFilter", "Error calling startForeground", localException);
-//			setForegroundBackwardsCompat(true);
-//			((NotificationManager) getSystemService("notification")).notify(1, localNotification);
-//		}
-//	}
-//
-//	public void onDestroy() {
-//		super.onDestroy();
-//		Log.d("FilterService", "onDestroy");
-//		setForegroundBackwardsCompat(false);
-//		ScreenFilterActivity.hideNotification(getBaseContext());
-//	}
-//
-//	public void onStart(Intent paramIntent, int paramInt) {
-//		super.onStart(paramIntent, paramInt);
-//		Log.d("FilterService", "onStart");
-//	}
-//
-//	void setForegroundBackwardsCompat(boolean paramBoolean) {
-//		try {
-//			getClass().getMethod("setForeground", new Class[] { Boolean.class }).invoke(this,
-//					new Object[] { Boolean.valueOf(paramBoolean) });
-//			return;
-//		} catch (Exception localException) {
-//			Log.w("ScreenFilter", "Error calling setForeground", localException);
-//		}
-//	}
-//
+	public void onCreate() {
+		super.onCreate();
+		Log.d("FilterService", "onCreate");
+		Notification localNotification = ScreenFilterActivity.getNotification(getBaseContext());
+		try {
+			getClass().getMethod("startForeground", new Class[] { Integer.TYPE, Notification.class }).invoke(this,
+					new Object[] { Integer.valueOf(1), localNotification });
+			return;
+		} catch (Exception localException) {
+			Log.w("ScreenFilter", "Error calling startForeground", localException);
+			setForegroundBackwardsCompat(true);
+			((NotificationManager) getSystemService("notification")).notify(1, localNotification);
+		}
+	}
+
+	public void onDestroy() {
+		super.onDestroy();
+		Log.d("FilterService", "onDestroy");
+		setForegroundBackwardsCompat(false);
+		ScreenFilterActivity.hideNotification(getBaseContext());
+	}
+
+	public void onStart(Intent paramIntent, int paramInt) {
+		super.onStart(paramIntent, paramInt);
+		Log.d("FilterService", "onStart");
+	}
+
+	void setForegroundBackwardsCompat(boolean paramBoolean) {
+		try {
+			getClass().getMethod("setForeground", new Class[] { Boolean.class }).invoke(this,
+					new Object[] { Boolean.valueOf(paramBoolean) });
+			return;
+		} catch (Exception localException) {
+			Log.w("ScreenFilter", "Error calling setForeground", localException);
+		}
+	}
+
 	public class LocalBinder extends Binder {
 	public class LocalBinder extends Binder {
 		public LocalBinder() {
 		public LocalBinder() {
-		
 		}
 		}
 
 
 		FilterService getService() {
 		FilterService getService() {

+ 36 - 0
src/me/yoqi/screenfilter/service/LocaleReceiver.java

@@ -0,0 +1,36 @@
+package me.yoqi.screenfilter.service;
+
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.util.Log;
+
+public class LocaleReceiver extends BroadcastReceiver {
+	
+	public void onReceive(Context paramContext, Intent paramIntent) {
+		if (!"com.twofortyfouram.locale.intent.action.FIRE_SETTING".equals(paramIntent.getAction())) {
+			return;
+		}
+		if (paramIntent.getBundleExtra("com.twofortyfouram.locale.intent.extra.BUNDLE") == null) {
+			Log.e("LocaleReceiver", "Bundle extra was null");
+			return;
+		}
+		paramIntent = paramIntent.getBundleExtra("com.twofortyfouram.locale.intent.extra.BUNDLE");
+		int i = -1;
+		boolean bool = true;
+		if (paramIntent != null) {
+			i = paramIntent.getInt("com.haxor.LocaleEdit.LOCALE_BRIGHTNESS", -1);
+			if (i == -1) {
+				Log.e("LocaleReceiver", "Locale forwarded bundle missing key com.haxor.LocaleEdit.LOCALE_BRIGHTNESS");
+				return;
+			}
+			bool = paramIntent.getBoolean("com.haxor.LocaleEdit.LOCALE_SOFT_KEYS_ENABLED", true);
+		}
+		Log.i("LocaleReceiver", "Applying progress=" + i);
+		paramIntent = new Intent(paramContext, ScreenFilterActivity.class);
+		paramIntent.addFlags(268435456);
+		paramIntent.putExtra("NEW_BRIGHTNESS", i);
+		paramIntent.putExtra("SOFT_KEYS_ENABLED", bool);
+		paramContext.startActivity(paramIntent);
+	}
+}

+ 69 - 4
src/me/yoqi/screenfilter/ui/LocaleEditActivity.java

@@ -2,11 +2,76 @@ package me.yoqi.screenfilter.ui;
 
 
 import android.app.Activity;
 import android.app.Activity;
 import android.os.Bundle;
 import android.os.Bundle;
+import android.content.Intent;
+import android.util.Log;
+import android.view.View;
+import android.view.View.OnClickListener;
+import android.widget.Button;
+import me.yoqi.screenfilter.R;
+
+import java.util.Formatter;
 
 
 public class LocaleEditActivity extends Activity {
 public class LocaleEditActivity extends Activity {
-	@Override
-	protected void onCreate(Bundle savedInstanceState) {
-		// TODO Auto-generated method stub
-		super.onCreate(savedInstanceState);
+	public static final String LOCALE_BRIGHTNESS = "com.haxor.LocaleEdit.LOCALE_BRIGHTNESS";
+	public static final String LOCALE_SOFT_KEYS_ENABLED = "com.haxor.LocaleEdit.LOCALE_SOFT_KEYS_ENABLED";
+	private boolean saved;
+
+	protected void onCreate(Bundle paramBundle) {
+		super.onCreate(paramBundle);
+		this.saved = false;
+		setTitle(getIntent().getStringExtra("com.twofortyfouram.locale.intent.extra.BREADCRUMB") + " > Screen Filter");
+		setContentView(R.layout.locale_edit);
+		paramBundle = (BrightnessSelector) findViewById(R.id.PreferencesBrightnessSelector);
+		Bundle localBundle = getIntent().getBundleExtra("com.twofortyfouram.locale.intent.extra.BUNDLE");
+		if (localBundle != null) {
+			int i = localBundle.getInt("com.haxor.LocaleEdit.LOCALE_BRIGHTNESS", -1);
+			if (i != -1) {
+				paramBundle.setProgress(i);
+			}
+			if (localBundle.containsKey("com.haxor.LocaleEdit.LOCALE_SOFT_KEYS_ENABLED")) {
+				paramBundle.setSoftKeysEnabled(
+						localBundle.getBoolean("com.haxor.LocaleEdit.LOCALE_SOFT_KEYS_ENABLED", true));
+			}
+		}
+		((Button) findViewById(R.id.SaveSettingButton)).setOnClickListener(new View.OnClickListener() {
+			public void onClick(View paramAnonymousView) {
+				int i = paramBundle.getProgress();
+				double d = ScreenFilterActivity.computePercentage(i);
+				paramAnonymousView = new Formatter()
+						.format(LocaleEditActivity.this.getString(2131165203), new Object[] { Double.valueOf(d) })
+						.toString();
+				if (paramBundle.isSoftKeysEnabled()) {
+				}
+				for (paramAnonymousView = paramAnonymousView + " "
+						+ LocaleEditActivity.this.getString(2131165206);; paramAnonymousView = paramAnonymousView + " "
+								+ LocaleEditActivity.this.getString(2131165207)) {
+					Intent localIntent = new Intent();
+					Bundle localBundle = new Bundle();
+					localBundle.putInt("com.haxor.LocaleEdit.LOCALE_BRIGHTNESS", i);
+					localBundle.putBoolean("com.haxor.LocaleEdit.LOCALE_SOFT_KEYS_ENABLED",
+							paramBundle.isSoftKeysEnabled());
+					localIntent.putExtra("com.twofortyfouram.locale.intent.extra.BUNDLE", localBundle);
+					localIntent.putExtra("com.twofortyfouram.locale.intent.extra.BLURB", paramAnonymousView);
+					Log.i("LocaleEdit", "Progress=" + i + ", blurb=" + paramAnonymousView);
+					LocaleEditActivity.this.setResult(-1, localIntent);
+					LocaleEditActivity.this.saved = true;
+					LocaleEditActivity.this.finish();
+					return;
+				}
+			}
+		});
+		((Button) findViewById(R.id.DontSaveSettingButton)).setOnClickListener(new View.OnClickListener() {
+			public void onClick(View paramAnonymousView) {
+				Log.i("LocaleEdit", "Edit canceled");
+				LocaleEditActivity.this.finish();
+			}
+		});
+	}
+
+	protected void onPause() {
+		super.onPause();
+		if (!this.saved) {
+			setResult(0);
+		}
 	}
 	}
 }
 }

+ 66 - 2
src/me/yoqi/screenfilter/ui/ScreenFilterWidgetConfigure.java

@@ -1,7 +1,71 @@
 package me.yoqi.screenfilter.ui;
 package me.yoqi.screenfilter.ui;
 
 
 import android.app.Activity;
 import android.app.Activity;
+import android.appwidget.AppWidgetManager;
+import android.content.Intent;
+import android.content.SharedPreferences;
+import android.content.SharedPreferences.Editor;
+import android.os.Bundle;
+import android.util.Log;
+import android.view.View;
+import android.view.View.OnClickListener;
+import android.widget.Button;
+import me.yoqi.screenfilter.BrightnessSelector;
+import me.yoqi.screenfilter.receiver.ScreenFilterWidget;
 
 
-public class ScreenFilterWidgetConfigure extends Activity {
-
+public class ScreenFilterWidgetConfigure
+  extends Activity
+{
+  protected void onCreate(final Bundle paramBundle)
+  {
+    super.onCreate(paramBundle);
+    setResult(0);
+    paramBundle = getIntent().getExtras();
+    if (paramBundle == null)
+    {
+      Log.d("ScreenFilterWidgetConfigure", "Missing intent extras bundle");
+      finish();
+      return;
+    }
+    final int i = paramBundle.getInt("appWidgetId", 0);
+    if (i == 0)
+    {
+      Log.d("ScreenFilterWidgetConfigure", "Bad widget Id: " + i);
+      finish();
+      return;
+    }
+    setContentView(2130903041);
+    paramBundle = getSharedPreferences("preferences", 0);
+    String str1 = "NEW_BRIGHTNESS:" + i;
+    String str2 = "SOFT_KEYS_ENABLED:" + i;
+    final BrightnessSelector localBrightnessSelector = (BrightnessSelector)findViewById(2131034123);
+    int j = paramBundle.getInt(str1, -1);
+    if (j != -1) {
+      localBrightnessSelector.setProgress(j);
+    }
+    localBrightnessSelector.setSoftKeysEnabled(paramBundle.getBoolean(str2, true));
+    ((Button)findViewById(2131034125)).setOnClickListener(new View.OnClickListener()
+    {
+      public void onClick(View paramAnonymousView)
+      {
+				paramAnonymousView = new Intent();
+        paramAnonymousView.putExtra("appWidgetId", i);
+        ScreenFilterWidgetConfigure.this.setResult(-1, paramAnonymousView);
+        int i = localBrightnessSelector.getProgress();
+        boolean bool = localBrightnessSelector.isSoftKeysEnabled();
+        Log.d("ScreenFilterWidgetConfigure", "Widget config saved. WidgetId=" + i + ", progress=" + i + ", softKeys=" + bool);
+        paramBundle.edit().putInt("NEW_BRIGHTNESS:" + i, i).putBoolean("SOFT_KEYS_ENABLED:" + i, bool).commit();
+        ScreenFilterWidget.updateWidget(ScreenFilterWidgetConfigure.this, AppWidgetManager.getInstance(ScreenFilterWidgetConfigure.this), i);
+        ScreenFilterWidgetConfigure.this.finish();
+      }
+    });
+    ((Button)findViewById(2131034124)).setOnClickListener(new View.OnClickListener()
+    {
+      public void onClick(View paramAnonymousView)
+      {
+        Log.d("ScreenFilterWidgetConfigure", "Widet config canceled. WidgetId=" + i);
+        ScreenFilterWidgetConfigure.this.finish();
+      }
+    });
+  }
 }
 }

+ 48 - 4
src/me/yoqi/screenfilter/ui/SettingsActivity.java

@@ -2,14 +2,58 @@ package me.yoqi.screenfilter.ui;
 
 
 import android.app.Activity;
 import android.app.Activity;
 import android.os.Bundle;
 import android.os.Bundle;
+import me.yoqi.screenfilter.BrightnessSelector;
 import me.yoqi.screenfilter.R;
 import me.yoqi.screenfilter.R;
 import me.yoqi.screenfilter.R.layout;
 import me.yoqi.screenfilter.R.layout;
+import me.yoqi.screenfilter.ScreenFilterActivity;
+import android.app.Activity;
+import android.content.Intent;
+import android.content.SharedPreferences;
+import android.content.SharedPreferences.Editor;
+import android.os.Bundle;
+import android.util.Log;
+import android.view.View;
+import android.view.View.OnClickListener;
+import android.widget.Button;
 
 
 public class SettingsActivity extends Activity {
 public class SettingsActivity extends Activity {
+	private SharedPreferences prefs;
+	private BrightnessSelector selector;
+
+	protected void onCreate(Bundle paramBundle) {
+		super.onCreate(paramBundle);
+		Log.d("Preferences", "onCreate");
+		onNewIntent(getIntent());
+	}
+
+	public void onNewIntent(Intent paramIntent) {
+		Log.d("Preferences", "onNewIntent");
+		this.prefs = getSharedPreferences("preferences", 0);
+		ScreenFilterActivity.hideFilter(this, false);
+		setContentView(2130903043);
+		((Button) findViewById(2131034126)).setOnClickListener(new ReenableListener(null));
+		int i = ScreenFilterActivity.getBrightness(this);
+		this.selector = ((BrightnessSelector) findViewById(2131034123));
+		this.selector.setProgress(i);
+		this.selector.setSoftKeysEnabled(this.prefs.getBoolean("SOFT_KEYS_ENABLED", true));
+	}
+
+	protected void onPause() {
+		super.onPause();
+		Log.d("Preferences", "onPause");
+		this.prefs.edit().putInt("NEW_BRIGHTNESS", this.selector.getProgress())
+				.putBoolean("SOFT_KEYS_ENABLED", this.selector.isSoftKeysEnabled()).remove("TOO_LOW_CONFIRMED")
+				.commit();
+		finish();
+	}
+
+	private class ReenableListener implements View.OnClickListener {
+		private ReenableListener() {
+		}
 
 
-	@Override
-	protected void onCreate(Bundle savedInstanceState) {
-		super.onCreate(savedInstanceState);
-		setContentView(R.layout.activity_settings);
+		public void onClick(View paramView) {
+			SettingsActivity.this.startActivity(new Intent(SettingsActivity.this, ScreenFilterActivity.class));
+			SettingsActivity.this.finish();
+		}
 	}
 	}
 }
 }