2 * Copyright (C) 2008-2011 OpenIntents.org
\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
8 * http://www.apache.org/licenses/LICENSE-2.0
\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
17 package org.openintents.filemanager;
\r
19 import org.openintents.util.VersionUtils;
\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
29 * @version 2009-10-23: support Market and aTrackDog
\r
30 * @version 2009-02-04
\r
34 public class UpdateDialog extends DownloadAppDialog {
\r
36 private static final String TAG = "UpdateMenu";
\r
37 private static final boolean DEBUG_NO_MARKET = false;
\r
40 * If any of the following applications is installed,
\r
41 * there is no need for a manual "Update" menu entry.
\r
43 public static final String[] UPDATE_CHECKER = new String[]
\r
45 "org.openintents.updatechecker", // OI Update
\r
46 "com.android.vending", // Google's Android Market
\r
47 "com.a0soft.gphone.aTrackDog" // aTrackDog
\r
50 public UpdateDialog(Context 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
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
62 StringBuilder sb = new StringBuilder();
\r
63 sb.append(appnameversion);
\r
65 sb.append(mMessageText);
\r
66 setMessage(sb.toString());
\r
68 setButton(mContext.getText(R.string.oi_distribution_update_check_now), this);
\r
71 public void onClick(DialogInterface dialog, int which) {
\r
72 final Intent intent = new Intent(Intent.ACTION_VIEW);
\r
74 if (which == BUTTON1) {
\r
76 // TODO: Obtain this resId properly from
\r
77 // Manifest or about.xml
\r
78 int resId = R.string.about_website_url;
\r
80 intent.setData(Uri.parse(mContext.getString(resId)));
\r
81 startSaveActivity(intent);
\r
83 // BUTTON2 is handled by parent.
\r
84 super.onClick(dialog, which);
\r
90 * Check if no updater application is installed.
\r
95 public static boolean isUpdateMenuNecessary(Context context) {
\r
96 PackageInfo pi = null;
\r
98 // Test for existence of all known update checker applications.
\r
99 for (int i = 0; i < UPDATE_CHECKER.length; i++) {
\r
101 pi = context.getPackageManager().getPackageInfo(
\r
102 UPDATE_CHECKER[i], 0);
\r
103 } catch (NameNotFoundException e) {
\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
113 // If we reach this point, we add a menu item for manual update.
\r