Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(411)

Side by Side Diff: blimp/client/app/android/java/src/org/chromium/blimp/settings/AboutBlimpPreferences.java

Issue 2493333002: Move Java Blimp shell code to app subpackage (Closed)
Patch Set: Merge branch 'refs/heads/master' into blimp-shell-integration Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 package org.chromium.blimp.settings;
6
7 import android.app.Activity;
8 import android.app.AlertDialog;
9 import android.content.Context;
10 import android.content.DialogInterface;
11 import android.content.Intent;
12 import android.content.pm.ApplicationInfo;
13 import android.content.pm.PackageInfo;
14 import android.content.pm.PackageManager;
15 import android.os.Build;
16 import android.os.Bundle;
17 import android.preference.ListPreference;
18 import android.preference.Preference;
19 import android.preference.PreferenceFragment;
20 import android.text.TextUtils;
21
22 import org.chromium.base.Log;
23 import org.chromium.blimp.BrowserRestartActivity;
24 import org.chromium.blimp.R;
25 import org.chromium.blimp.preferences.PreferencesUtil;
26
27 /**
28 * Fragment to display blimp client and engine version related info.
29 */
30 public class AboutBlimpPreferences extends PreferenceFragment {
31 private static final String TAG = "AboutBlimp";
32 public static final String EXTRA_ENGINE_IP = "engine_ip";
33 public static final String EXTRA_ENGINE_VERSION = "engine_version";
34
35 private static final String PREF_APPLICATION_VERSION = "application_version" ;
36 private static final String PREF_OS_VERSION = "os_version";
37 private static final String PREF_ENGINE_IP = "blimp_engine_ip";
38 private static final String PREF_ENGINE_VERSION = "blimp_engine_version";
39 private static final String PREF_ASSIGNER_URL = "blimp_assigner_url";
40
41 @Override
42 public void onCreate(Bundle savedInstanceState) {
43 super.onCreate(savedInstanceState);
44 getActivity().setTitle(R.string.about_blimp_preferences);
45 addPreferencesFromResource(R.xml.about_blimp_preferences);
46
47 setAppVersion(getActivity());
48 setOSVersion();
49 setEngineIPandVersion(getActivity().getIntent());
50 setupAssignerPreferences();
51 }
52
53 private void setAppVersion(Activity activity) {
54 PackageManager pm = activity.getPackageManager();
55 try {
56 ApplicationInfo applicationInfo = pm.getApplicationInfo(activity.get PackageName(), 0);
57 PackageInfo packageInfo = pm.getPackageInfo(activity.getPackageName( ), 0);
58
59 String versionString;
60 if (!TextUtils.isEmpty(packageInfo.versionName)
61 && Character.isDigit(packageInfo.versionName.charAt(0))) {
62 versionString = activity.getString(
63 R.string.subtitle_for_version_number, packageInfo.versio nName);
64 } else {
65 versionString = packageInfo.versionName;
66 }
67
68 Preference p = findPreference(PREF_APPLICATION_VERSION);
69 p.setSummary(versionString);
70 } catch (PackageManager.NameNotFoundException e) {
71 Log.d(TAG, "Fetching ApplicationInfo failed.", e);
72 }
73 }
74
75 private void setOSVersion() {
76 Preference p = findPreference(PREF_OS_VERSION);
77 p.setSummary("Android " + Build.VERSION.RELEASE);
78 }
79
80 private void setEngineIPandVersion(Intent intent) {
81 String engineIP = intent.getStringExtra(EXTRA_ENGINE_IP);
82 Preference p = findPreference(PREF_ENGINE_IP);
83 p.setSummary(engineIP == null ? "" : engineIP);
84
85 String engineVersion = intent.getStringExtra(EXTRA_ENGINE_VERSION);
86 p = findPreference(PREF_ENGINE_VERSION);
87 p.setSummary(engineVersion == null ? "" : engineVersion);
88 }
89
90 /**
91 * When the user taps on the current assigner, a list of available assigners pops up.
92 * User is allowed to change the assigner which is saved to shared preferenc es.
93 * A dialog is displayed which prompts the user to restart the application.
94 */
95 private void setupAssignerPreferences() {
96 final Activity activity = getActivity();
97 String assigner = PreferencesUtil.getLastUsedAssigner(activity);
98
99 final ListPreference lp = (ListPreference) findPreference(PREF_ASSIGNER_ URL);
100 lp.setSummary(assigner == null ? "" : assigner);
101
102 lp.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListen er() {
103 @Override
104 public boolean onPreferenceChange(Preference preference, Object newV alue) {
105 String newAssignmentUrl = (String) newValue;
106 lp.setSummary(newAssignmentUrl);
107 lp.setValue(newAssignmentUrl);
108
109 PreferencesUtil.setLastUsedAssigner(activity, newAssignmentUrl);
110 showRestartDialog(activity);
111
112 return true;
113 }
114 });
115 }
116
117 private void showRestartDialog(final Context context) {
118 // TODO(shaktisahu): Change this to use android.support.v7.app.AlertDial og later.
119 new AlertDialog.Builder(context)
120 .setTitle(R.string.restart_blimp)
121 .setMessage(R.string.blimp_assigner_changed_please_restart)
122 .setPositiveButton(R.string.restart_now,
123 new DialogInterface.OnClickListener() {
124 @Override
125 public void onClick(DialogInterface dialog, int whic h) {
126 restartBrowser(context);
127 }
128 })
129 .create()
130 .show();
131 }
132
133 private void restartBrowser(Context context) {
134 Intent intent = BrowserRestartActivity.createRestartIntent(context);
135 context.startActivity(intent);
136 }
137 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698