diff options
author | Daniel Sandler <dsandler@android.com> | 2010-08-26 16:52:11 -0400 |
---|---|---|
committer | Daniel Sandler <dsandler@android.com> | 2010-08-27 13:50:34 -0400 |
commit | f82202d691f7988584252d87e670de7a6e125fe5 (patch) | |
tree | e86de64e0e4a27fa2fb7baceb737809086d23437 /src | |
parent | fea396610f4cf0742a8b026740d0ca5bf63d1b32 (diff) | |
download | Protips-f82202d691f7988584252d87e670de7a6e125fe5.tar.gz |
Update tip widget text.
Bug: 2600981
Change-Id: Ic27de75c0aab691f125c8de5dc1c3cdea5d32d7a
Diffstat (limited to 'src')
-rw-r--r-- | src/com/android/protips/ProtipWidget.java | 28 |
1 files changed, 26 insertions, 2 deletions
diff --git a/src/com/android/protips/ProtipWidget.java b/src/com/android/protips/ProtipWidget.java index c41c90e..ddc0b42 100644 --- a/src/com/android/protips/ProtipWidget.java +++ b/src/com/android/protips/ProtipWidget.java @@ -56,6 +56,7 @@ public class ProtipWidget extends AppWidgetProvider { public static final String PREFS_NAME = "Protips"; public static final String PREFS_TIP_NUMBER = "widget_tip"; + public static final String PREFS_TIP_SET = "widget_tip_set"; private static Random sRNG = new Random(); @@ -65,6 +66,7 @@ public class ProtipWidget extends AppWidgetProvider { // initial appearance: eyes closed, no bubble private int mIconRes = R.drawable.droidman_open; private int mMessage = 0; + private int mTipSet = 0; private AppWidgetManager mWidgetManager = null; private int[] mWidgetIds; @@ -79,15 +81,15 @@ public class ProtipWidget extends AppWidgetProvider { SharedPreferences pref = context.getSharedPreferences(PREFS_NAME, 0); mMessage = pref.getInt(PREFS_TIP_NUMBER, 0); + mTipSet = pref.getInt(PREFS_TIP_SET, 0); - mTips = context.getResources().getTextArray(R.array.tips); + mTips = context.getResources().getTextArray(mTipSet == 1 ? R.array.tips2 : R.array.tips); if (mTips != null) { if (mMessage >= mTips.length) mMessage = 0; } else { mMessage = -1; } - } public void goodmorning() { @@ -112,6 +114,9 @@ public class ProtipWidget extends AppWidgetProvider { public void onReceive(Context context, Intent intent) { setup(context); + Resources res = mContext.getResources(); + mTips = res.getTextArray(mTipSet == 1 ? R.array.tips2 : R.array.tips); + if (intent.getAction().equals(ACTION_NEXT_TIP)) { mMessage = getNextMessageIndex(); SharedPreferences.Editor pref = context.getSharedPreferences(PREFS_NAME, 0).edit(); @@ -122,6 +127,25 @@ public class ProtipWidget extends AppWidgetProvider { blink(intent.getIntExtra(EXTRA_TIMES, 1)); } else if (intent.getAction().equals(AppWidgetManager.ACTION_APPWIDGET_ENABLED)) { goodmorning(); + } else if (intent.getAction().equals("android.provider.Telephony.SECRET_CODE")) { + Log.d("Protips", "ACHIEVEMENT UNLOCKED"); + mTipSet = 1 - mTipSet; + mMessage = 0; + + SharedPreferences.Editor pref = context.getSharedPreferences(PREFS_NAME, 0).edit(); + pref.putInt(PREFS_TIP_NUMBER, mMessage); + pref.putInt(PREFS_TIP_SET, mTipSet); + pref.commit(); + + mContext.startActivity( + new Intent(Intent.ACTION_MAIN) + .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK|Intent.FLAG_ACTIVITY_CLEAR_TOP) + .addCategory(Intent.CATEGORY_HOME)); + + final Intent bcast = new Intent(context, ProtipWidget.class); + bcast.setAction(ACTION_POKE); + bcast.putExtra(EXTRA_TIMES, 3); + mContext.sendBroadcast(bcast); } else { mIconRes = R.drawable.droidman_open; refresh(); |