switch to alsa.omap3 module
[android_pandora.git] / apps / oi-filemanager / FileManager / src / org / openintents / filemanager / EulaOrNewVersion.java
CommitLineData
27a4fda1 1/* \r
2 * Copyright (C) 2007-2011 OpenIntents.org\r
3 *\r
4 * Licensed under the Apache License, Version 2.0 (the "License");\r
5 * you may not use this file except in compliance with the License.\r
6 * You may obtain a copy of the License at\r
7 *\r
8 * http://www.apache.org/licenses/LICENSE-2.0\r
9 *\r
10 * Unless required by applicable law or agreed to in writing, software\r
11 * distributed under the License is distributed on an "AS IS" BASIS,\r
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
13 * See the License for the specific language governing permissions and\r
14 * limitations under the License.\r
15 */\r
16\r
17package org.openintents.filemanager;\r
18\r
19import org.openintents.util.VersionUtils;\r
20\r
21import android.app.Activity;\r
22import android.content.ComponentName;\r
23import android.content.Context;\r
24import android.content.Intent;\r
25import android.content.SharedPreferences;\r
26import android.preference.PreferenceManager;\r
27import android.util.Log;\r
28\r
29\r
30\r
31/**\r
32 * Displays the Eula for the first time, reading it from a raw resource.\r
33 * \r
34 * @author Peli\r
35 *\r
36 */\r
37public class EulaOrNewVersion {\r
38 /** TAG for log messages. */\r
39 private static final String TAG = "EulaOrNewVersion";\r
40 private static final boolean debug = false;\r
41 \r
42 public static final String PREFERENCES_EULA_ACCEPTED = "eula_accepted";\r
43\r
44 public static final String PREFERENCES_VERSION_NUMBER = "org.openintents.distribution.version_number_check";\r
45 \r
46 /**\r
47 * Extra for main intent.\r
48 * Specifies activity that should be launched after Eula has been accepted.\r
49 */\r
50 static final String EXTRA_LAUNCH_ACTIVITY_PACKAGE = "org.openintents.extra.launch_activity_package";\r
51 static final String EXTRA_LAUNCH_ACTIVITY_CLASS = "org.openintents.extra.launch_activity_class";\r
52 static final String EXTRA_LAUNCH_ACTIVITY_INTENT = "org.openintents.extra.launch_activity_intent";\r
53 \r
54 /**\r
55 * Test whether EULA has been accepted. Otherwise display EULA.\r
56 * \r
57 * @return True if Eula needs to be shown.\r
58 */\r
59 static boolean showEula(Activity activity) {\r
60 SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(activity);\r
61 boolean accepted = sp.getBoolean(PREFERENCES_EULA_ACCEPTED, false);\r
62 \r
63 if (accepted) {\r
64 if (debug) Log.d(TAG, "Eula has been accepted.");\r
65 return false;\r
66 } else {\r
67 if (debug) Log.d(TAG, "Eula has not been accepted yet.");\r
68 \r
69 startForwardActivity(activity, EulaActivity.class);\r
70 return true;\r
71 }\r
72 }\r
73 \r
74 static void storeEulaAccepted(Context context) {\r
75 SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);\r
76 SharedPreferences.Editor e = sp.edit();\r
77 e.putBoolean(PREFERENCES_EULA_ACCEPTED, true);\r
78 e.commit();\r
79 }\r
80 \r
81 /**\r
82 * Test whether version code changed.\r
83 * \r
84 * @return True if version code changed and recent changes are being shown.\r
85 */\r
86 static boolean showNewVersion(Activity activity) {\r
87 SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(activity);\r
88 int lastVersion = sp.getInt(PREFERENCES_VERSION_NUMBER, 0);\r
89 int thisVersion = VersionUtils.getVersionCode(activity);\r
90 \r
91 if (lastVersion == thisVersion) {\r
92 if (debug) Log.i(TAG, "Same version " + lastVersion + " as last launch.");\r
93 return false;\r
94 } else {\r
95 if (debug) Log.i(TAG, "Newer version " + thisVersion + " since last launch " + lastVersion + ". Show recent changes.");\r
96 \r
97 startForwardActivity(activity, NewVersionActivity.class);\r
98 return true;\r
99 }\r
100 }\r
101 \r
102 static void storeCurrentVersionCode(Context context) {\r
103 SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);\r
104 int thisVersion = VersionUtils.getVersionCode(context);\r
105 SharedPreferences.Editor e = sp.edit();\r
106 e.putInt(PREFERENCES_VERSION_NUMBER, thisVersion);\r
107 e.commit();\r
108 }\r
109\r
110 private static void startForwardActivity(Activity activity, Class launchClass) {\r
111 // Launch Eula activity\r
112 Intent forwardIntent = activity.getIntent();\r
113 \r
114 Intent i = new Intent(activity, launchClass);\r
115 ComponentName ci = activity.getComponentName();\r
116 \r
117 // Specify in intent extras which activity should be called\r
118 // after Eula has been accepted.\r
119 if (debug) Log.d(TAG, "Local package name: " + ci.getPackageName());\r
120 if (debug) Log.d(TAG, "Local class name: " + ci.getClassName());\r
121 i.putExtra(EXTRA_LAUNCH_ACTIVITY_PACKAGE, ci.getPackageName());\r
122 i.putExtra(EXTRA_LAUNCH_ACTIVITY_CLASS, ci.getClassName());\r
123 if (forwardIntent != null) {\r
124 i.putExtra(EXTRA_LAUNCH_ACTIVITY_INTENT, forwardIntent);\r
125 }\r
126 i.addFlags(Intent.FLAG_ACTIVITY_FORWARD_RESULT);\r
127 activity.startActivity(i);\r
128 activity.finish();\r
129 }\r
130 \r
131}\r