27a4fda1 |
1 | /* \r |
2 | * Copyright (C) 2008-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 |
17 | package org.openintents.filemanager;\r |
18 | \r |
19 | import org.openintents.util.VersionUtils;\r |
20 | \r |
21 | import android.content.Context;\r |
22 | import android.content.DialogInterface;\r |
23 | import android.content.Intent;\r |
24 | import android.content.pm.PackageInfo;\r |
25 | import android.content.pm.PackageManager.NameNotFoundException;\r |
26 | import android.net.Uri;\r |
27 | \r |
28 | /**\r |
29 | * @version 2009-10-23: support Market and aTrackDog\r |
30 | * @version 2009-02-04\r |
31 | * @author Peli\r |
32 | *\r |
33 | */\r |
34 | public class UpdateDialog extends DownloadAppDialog {\r |
35 | \r |
36 | private static final String TAG = "UpdateMenu";\r |
37 | private static final boolean DEBUG_NO_MARKET = false;\r |
38 | \r |
39 | /**\r |
40 | * If any of the following applications is installed,\r |
41 | * there is no need for a manual "Update" menu entry.\r |
42 | */\r |
43 | public static final String[] UPDATE_CHECKER = new String[]\r |
44 | {\r |
45 | "org.openintents.updatechecker", // OI Update\r |
46 | "com.android.vending", // Google's Android Market\r |
47 | "com.a0soft.gphone.aTrackDog" // aTrackDog\r |
48 | };\r |
49 | \r |
50 | public UpdateDialog(Context context) {\r |
51 | super(context, \r |
52 | R.string.oi_distribution_update_box_text, \r |
53 | R.string.oi_distribution_update_app, \r |
54 | R.string.oi_distribution_update_checker_package, \r |
55 | R.string.oi_distribution_update_checker_website);\r |
56 | mContext = context;\r |
57 | \r |
58 | String version = VersionUtils.getVersionNumber(mContext);\r |
59 | String appname = VersionUtils.getApplicationName(mContext);\r |
60 | String appnameversion = mContext.getString(R.string.oi_distribution_name_and_version, appname, version);\r |
61 | \r |
62 | StringBuilder sb = new StringBuilder();\r |
63 | sb.append(appnameversion);\r |
64 | sb.append("\n\n");\r |
65 | sb.append(mMessageText);\r |
66 | setMessage(sb.toString());\r |
67 | \r |
68 | setButton(mContext.getText(R.string.oi_distribution_update_check_now), this);\r |
69 | }\r |
70 | \r |
71 | public void onClick(DialogInterface dialog, int which) {\r |
72 | final Intent intent = new Intent(Intent.ACTION_VIEW);\r |
73 | \r |
74 | if (which == BUTTON1) {\r |
75 | \r |
76 | // TODO: Obtain this resId properly from\r |
77 | // Manifest or about.xml\r |
78 | int resId = R.string.about_website_url;\r |
79 | \r |
80 | intent.setData(Uri.parse(mContext.getString(resId)));\r |
81 | startSaveActivity(intent);\r |
82 | } else {\r |
83 | // BUTTON2 is handled by parent.\r |
84 | super.onClick(dialog, which);\r |
85 | }\r |
86 | \r |
87 | }\r |
88 | \r |
89 | /**\r |
90 | * Check if no updater application is installed.\r |
91 | * \r |
92 | * @param context\r |
93 | * @return\r |
94 | */\r |
95 | public static boolean isUpdateMenuNecessary(Context context) {\r |
96 | PackageInfo pi = null;\r |
97 | \r |
98 | // Test for existence of all known update checker applications.\r |
99 | for (int i = 0; i < UPDATE_CHECKER.length; i++) {\r |
100 | try {\r |
101 | pi = context.getPackageManager().getPackageInfo(\r |
102 | UPDATE_CHECKER[i], 0);\r |
103 | } catch (NameNotFoundException e) {\r |
104 | // ignore\r |
105 | }\r |
106 | if (pi != null && !DEBUG_NO_MARKET) {\r |
107 | // At least one kind of update checker exists,\r |
108 | // so there is no need to add a menu item.\r |
109 | return false;\r |
110 | }\r |
111 | }\r |
112 | \r |
113 | // If we reach this point, we add a menu item for manual update.\r |
114 | return true; \r |
115 | }\r |
116 | \r |
117 | }\r |