--- /dev/null
+/* \r
+ * Copyright (C) 2008-2011 OpenIntents.org\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+\r
+package org.openintents.filemanager;\r
+\r
+import org.openintents.util.VersionUtils;\r
+\r
+import android.content.Context;\r
+import android.content.DialogInterface;\r
+import android.content.Intent;\r
+import android.content.pm.PackageInfo;\r
+import android.content.pm.PackageManager.NameNotFoundException;\r
+import android.net.Uri;\r
+\r
+/**\r
+ * @version 2009-10-23: support Market and aTrackDog\r
+ * @version 2009-02-04\r
+ * @author Peli\r
+ *\r
+ */\r
+public class UpdateDialog extends DownloadAppDialog {\r
+ \r
+ private static final String TAG = "UpdateMenu";\r
+ private static final boolean DEBUG_NO_MARKET = false;\r
+ \r
+ /**\r
+ * If any of the following applications is installed,\r
+ * there is no need for a manual "Update" menu entry.\r
+ */\r
+ public static final String[] UPDATE_CHECKER = new String[]\r
+ {\r
+ "org.openintents.updatechecker", // OI Update\r
+ "com.android.vending", // Google's Android Market\r
+ "com.a0soft.gphone.aTrackDog" // aTrackDog\r
+ };\r
+ \r
+ public UpdateDialog(Context context) {\r
+ super(context, \r
+ R.string.oi_distribution_update_box_text, \r
+ R.string.oi_distribution_update_app, \r
+ R.string.oi_distribution_update_checker_package, \r
+ R.string.oi_distribution_update_checker_website);\r
+ mContext = context;\r
+\r
+ String version = VersionUtils.getVersionNumber(mContext);\r
+ String appname = VersionUtils.getApplicationName(mContext);\r
+ String appnameversion = mContext.getString(R.string.oi_distribution_name_and_version, appname, version);\r
+ \r
+ StringBuilder sb = new StringBuilder();\r
+ sb.append(appnameversion);\r
+ sb.append("\n\n");\r
+ sb.append(mMessageText);\r
+ setMessage(sb.toString());\r
+ \r
+ setButton(mContext.getText(R.string.oi_distribution_update_check_now), this);\r
+ }\r
+\r
+ public void onClick(DialogInterface dialog, int which) {\r
+ final Intent intent = new Intent(Intent.ACTION_VIEW);\r
+ \r
+ if (which == BUTTON1) {\r
+ \r
+ // TODO: Obtain this resId properly from\r
+ // Manifest or about.xml\r
+ int resId = R.string.about_website_url;\r
+ \r
+ intent.setData(Uri.parse(mContext.getString(resId)));\r
+ startSaveActivity(intent);\r
+ } else {\r
+ // BUTTON2 is handled by parent.\r
+ super.onClick(dialog, which);\r
+ }\r
+ \r
+ }\r
+ \r
+ /**\r
+ * Check if no updater application is installed.\r
+ * \r
+ * @param context\r
+ * @return\r
+ */\r
+ public static boolean isUpdateMenuNecessary(Context context) {\r
+ PackageInfo pi = null;\r
+ \r
+ // Test for existence of all known update checker applications.\r
+ for (int i = 0; i < UPDATE_CHECKER.length; i++) {\r
+ try {\r
+ pi = context.getPackageManager().getPackageInfo(\r
+ UPDATE_CHECKER[i], 0);\r
+ } catch (NameNotFoundException e) {\r
+ // ignore\r
+ }\r
+ if (pi != null && !DEBUG_NO_MARKET) {\r
+ // At least one kind of update checker exists,\r
+ // so there is no need to add a menu item.\r
+ return false;\r
+ }\r
+ }\r
+ \r
+ // If we reach this point, we add a menu item for manual update.\r
+ return true; \r
+ }\r
+\r
+}\r