| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package org.chromium.chrome.browser.physicalweb; | 5 package org.chromium.chrome.browser.physicalweb; |
| 6 | 6 |
| 7 import android.content.Context; | 7 import android.app.Activity; |
| 8 import android.content.Intent; | 8 import android.content.Intent; |
| 9 import android.content.res.Resources; | 9 import android.content.res.Resources; |
| 10 import android.os.Build; | 10 import android.os.Build; |
| 11 import android.text.Html; | 11 import android.text.Html; |
| 12 import android.text.util.Linkify; | 12 import android.text.util.Linkify; |
| 13 import android.view.LayoutInflater; | 13 import android.view.LayoutInflater; |
| 14 import android.view.View; | 14 import android.view.View; |
| 15 import android.widget.Button; | 15 import android.widget.Button; |
| 16 import android.widget.TextView; | 16 import android.widget.TextView; |
| 17 | 17 |
| 18 import org.chromium.base.ApiCompatibilityUtils; | 18 import org.chromium.base.ApiCompatibilityUtils; |
| 19 import org.chromium.base.ContextUtils; |
| 19 import org.chromium.chrome.R; | 20 import org.chromium.chrome.R; |
| 20 import org.chromium.chrome.browser.NativePage; | 21 import org.chromium.chrome.browser.BasicNativePage; |
| 21 import org.chromium.chrome.browser.UrlConstants; | 22 import org.chromium.chrome.browser.UrlConstants; |
| 23 import org.chromium.chrome.browser.tab.Tab; |
| 22 import org.chromium.components.location.LocationUtils; | 24 import org.chromium.components.location.LocationUtils; |
| 23 | 25 |
| 24 import java.util.HashSet; | 26 import java.util.HashSet; |
| 25 import java.util.Set; | 27 import java.util.Set; |
| 26 | 28 |
| 27 /** | 29 /** |
| 28 * Provides diagnostic information about the Physical Web feature. | 30 * Provides diagnostic information about the Physical Web feature. |
| 29 */ | 31 */ |
| 30 public class PhysicalWebDiagnosticsPage implements NativePage { | 32 public class PhysicalWebDiagnosticsPage extends BasicNativePage { |
| 31 private final Context mContext; | 33 private String mSuccessColor; |
| 32 private final int mBackgroundColor; | 34 private String mFailureColor; |
| 33 private final int mThemeColor; | 35 private String mIndeterminateColor; |
| 34 private final String mSuccessColor; | 36 private View mPageView; |
| 35 private final String mFailureColor; | 37 private Button mLaunchButton; |
| 36 private final String mIndeterminateColor; | 38 private TextView mDiagnosticsText; |
| 37 private final View mPageView; | |
| 38 private final Button mLaunchButton; | |
| 39 private final TextView mDiagnosticsText; | |
| 40 | 39 |
| 41 public PhysicalWebDiagnosticsPage(Context context) { | 40 /** |
| 42 mContext = context; | 41 * Create a new instance of the Physical Web diagnostics page. |
| 42 * @param activity The activity to get context and manage fragments. |
| 43 * @param tab The tab to load urls. |
| 44 */ |
| 45 public PhysicalWebDiagnosticsPage(Activity activity, Tab tab) { |
| 46 super(activity, tab); |
| 47 } |
| 43 | 48 |
| 44 Resources resources = mContext.getResources(); | 49 @Override |
| 45 mBackgroundColor = ApiCompatibilityUtils.getColor(resources, R.color.ntp
_bg); | 50 protected void initialize(Activity activity, Tab tab) { |
| 46 mThemeColor = ApiCompatibilityUtils.getColor(resources, R.color.default_
primary_color); | 51 Resources resources = activity.getResources(); |
| 47 mSuccessColor = colorToHexValue(ApiCompatibilityUtils.getColor(resources
, | 52 mSuccessColor = colorToHexValue(ApiCompatibilityUtils.getColor(resources
, |
| 48 R.color.physical_web_diags_success_color)); | 53 R.color.physical_web_diags_success_color)); |
| 49 mFailureColor = colorToHexValue(ApiCompatibilityUtils.getColor(resources
, | 54 mFailureColor = colorToHexValue(ApiCompatibilityUtils.getColor(resources
, |
| 50 R.color.physical_web_diags_failure_color)); | 55 R.color.physical_web_diags_failure_color)); |
| 51 mIndeterminateColor = colorToHexValue(ApiCompatibilityUtils.getColor(res
ources, | 56 mIndeterminateColor = colorToHexValue(ApiCompatibilityUtils.getColor(res
ources, |
| 52 R.color.physical_web_diags_indeterminate_color)); | 57 R.color.physical_web_diags_indeterminate_color)); |
| 53 | 58 |
| 54 LayoutInflater inflater = LayoutInflater.from(mContext); | 59 LayoutInflater inflater = LayoutInflater.from(activity); |
| 55 mPageView = inflater.inflate(R.layout.physical_web_diagnostics, null); | 60 mPageView = inflater.inflate(R.layout.physical_web_diagnostics, null); |
| 56 | 61 |
| 57 mLaunchButton = (Button) mPageView.findViewById(R.id.physical_web_launch
); | 62 mLaunchButton = (Button) mPageView.findViewById(R.id.physical_web_launch
); |
| 58 mLaunchButton.setOnClickListener(new View.OnClickListener() { | 63 mLaunchButton.setOnClickListener(new View.OnClickListener() { |
| 59 @Override | 64 @Override |
| 60 public void onClick(View v) { | 65 public void onClick(View v) { |
| 61 mContext.startActivity(createListUrlsIntent(mContext)); | 66 ContextUtils.getApplicationContext().startActivity(createListUrl
sIntent()); |
| 62 } | 67 } |
| 63 }); | 68 }); |
| 64 | 69 |
| 65 mDiagnosticsText = (TextView) mPageView.findViewById(R.id.physical_web_d
iagnostics_text); | 70 mDiagnosticsText = (TextView) mPageView.findViewById(R.id.physical_web_d
iagnostics_text); |
| 66 mDiagnosticsText.setAutoLinkMask(Linkify.WEB_URLS); | 71 mDiagnosticsText.setAutoLinkMask(Linkify.WEB_URLS); |
| 67 mDiagnosticsText.setText(Html.fromHtml(createDiagnosticsReportHtml())); | 72 mDiagnosticsText.setText(Html.fromHtml(createDiagnosticsReportHtml())); |
| 68 } | 73 } |
| 69 | 74 |
| 75 @Override |
| 76 public String getTitle() { |
| 77 return "Physical Web Diagnostics"; |
| 78 } |
| 79 |
| 80 @Override |
| 81 public String getHost() { |
| 82 return UrlConstants.PHYSICAL_WEB_HOST; |
| 83 } |
| 84 |
| 85 @Override |
| 86 public View getView() { |
| 87 return mPageView; |
| 88 } |
| 89 |
| 70 private void appendResult(StringBuilder sb, boolean success, String successM
essage, | 90 private void appendResult(StringBuilder sb, boolean success, String successM
essage, |
| 71 String failureMessage) { | 91 String failureMessage) { |
| 72 int successValue = (success ? Utils.RESULT_SUCCESS : Utils.RESULT_FAILUR
E); | 92 int successValue = (success ? Utils.RESULT_SUCCESS : Utils.RESULT_FAILUR
E); |
| 73 appendResult(sb, successValue, successMessage, failureMessage, null); | 93 appendResult(sb, successValue, successMessage, failureMessage, null); |
| 74 } | 94 } |
| 75 | 95 |
| 76 private void appendResult(StringBuilder sb, int successValue, String success
Message, | 96 private void appendResult(StringBuilder sb, int successValue, String success
Message, |
| 77 String failureMessage, String indeterminateMessage) { | 97 String failureMessage, String indeterminateMessage) { |
| 78 String color; | 98 String color; |
| 79 String message; | 99 String message; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 92 break; | 112 break; |
| 93 default: | 113 default: |
| 94 return; | 114 return; |
| 95 } | 115 } |
| 96 | 116 |
| 97 sb.append(String.format("<font color=\"%s\">%s</font><br/>", color, mess
age)); | 117 sb.append(String.format("<font color=\"%s\">%s</font><br/>", color, mess
age)); |
| 98 } | 118 } |
| 99 | 119 |
| 100 private void appendPrerequisitesReport(StringBuilder sb) { | 120 private void appendPrerequisitesReport(StringBuilder sb) { |
| 101 boolean isSdkVersionCorrect = isSdkVersionCorrect(); | 121 boolean isSdkVersionCorrect = isSdkVersionCorrect(); |
| 102 boolean isDataConnectionActive = Utils.isDataConnectionActive(mContext); | 122 boolean isDataConnectionActive = Utils.isDataConnectionActive(); |
| 103 int bluetoothStatus = Utils.getBluetoothEnabledStatus(mContext); | 123 int bluetoothStatus = Utils.getBluetoothEnabledStatus(); |
| 104 LocationUtils locationUtils = LocationUtils.getInstance(); | 124 LocationUtils locationUtils = LocationUtils.getInstance(); |
| 105 boolean isLocationServicesEnabled = locationUtils.isSystemLocationSettin
gEnabled(); | 125 boolean isLocationServicesEnabled = locationUtils.isSystemLocationSettin
gEnabled(); |
| 106 boolean isLocationPermissionGranted = locationUtils.hasAndroidLocationPe
rmission(); | 126 boolean isLocationPermissionGranted = locationUtils.hasAndroidLocationPe
rmission(); |
| 107 boolean isPreferenceEnabled = PhysicalWeb.isPhysicalWebPreferenceEnabled
(); | 127 boolean isPreferenceEnabled = PhysicalWeb.isPhysicalWebPreferenceEnabled
(); |
| 108 boolean isOnboarding = PhysicalWeb.isOnboarding(); | 128 boolean isOnboarding = PhysicalWeb.isOnboarding(); |
| 109 | 129 |
| 110 int prerequisitesResult = Utils.RESULT_SUCCESS; | 130 int prerequisitesResult = Utils.RESULT_SUCCESS; |
| 111 if (!isSdkVersionCorrect | 131 if (!isSdkVersionCorrect |
| 112 || !isDataConnectionActive | 132 || !isDataConnectionActive |
| 113 || bluetoothStatus == Utils.RESULT_FAILURE | 133 || bluetoothStatus == Utils.RESULT_FAILURE |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 188 appendPrerequisitesReport(sb); | 208 appendPrerequisitesReport(sb); |
| 189 sb.append("<br/>"); | 209 sb.append("<br/>"); |
| 190 appendUrlManagerReport(sb); | 210 appendUrlManagerReport(sb); |
| 191 return sb.toString(); | 211 return sb.toString(); |
| 192 } | 212 } |
| 193 | 213 |
| 194 private boolean isSdkVersionCorrect() { | 214 private boolean isSdkVersionCorrect() { |
| 195 return (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT); | 215 return (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT); |
| 196 } | 216 } |
| 197 | 217 |
| 198 private static Intent createListUrlsIntent(Context context) { | 218 private static Intent createListUrlsIntent() { |
| 199 Intent intent = new Intent(context, ListUrlsActivity.class); | 219 return new Intent(ContextUtils.getApplicationContext(), ListUrlsActivity
.class) |
| 200 intent.putExtra(ListUrlsActivity.REFERER_KEY, ListUrlsActivity.DIAGNOSTI
CS_REFERER); | 220 .putExtra(ListUrlsActivity.REFERER_KEY, ListUrlsActivity.DIAGNOS
TICS_REFERER); |
| 201 return intent; | |
| 202 } | 221 } |
| 203 | 222 |
| 204 private static String colorToHexValue(int color) { | 223 private static String colorToHexValue(int color) { |
| 205 return "#" + Integer.toHexString(color & 0x00ffffff); | 224 return "#" + Integer.toHexString(color & 0x00ffffff); |
| 206 } | 225 } |
| 207 | |
| 208 // NativePage overrides | |
| 209 | |
| 210 @Override | |
| 211 public void destroy() { | |
| 212 // nothing to do | |
| 213 } | |
| 214 | |
| 215 @Override | |
| 216 public String getUrl() { | |
| 217 return UrlConstants.PHYSICAL_WEB_URL; | |
| 218 } | |
| 219 | |
| 220 @Override | |
| 221 public String getTitle() { | |
| 222 return "Physical Web Diagnostics"; | |
| 223 } | |
| 224 | |
| 225 @Override | |
| 226 public int getBackgroundColor() { | |
| 227 return mBackgroundColor; | |
| 228 } | |
| 229 | |
| 230 @Override | |
| 231 public int getThemeColor() { | |
| 232 return mThemeColor; | |
| 233 } | |
| 234 | |
| 235 @Override | |
| 236 public boolean needsToolbarShadow() { | |
| 237 return true; | |
| 238 } | |
| 239 | |
| 240 @Override | |
| 241 public View getView() { | |
| 242 return mPageView; | |
| 243 } | |
| 244 | |
| 245 @Override | |
| 246 public String getHost() { | |
| 247 return UrlConstants.PHYSICAL_WEB_HOST; | |
| 248 } | |
| 249 | |
| 250 @Override | |
| 251 public void updateForUrl(String url) { | |
| 252 // nothing to do | |
| 253 } | |
| 254 } | 226 } |
| OLD | NEW |