Wink Saville | a40fb23 | 2009-09-26 16:47:18 -0700 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (C) 2009 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package com.android.settings; |
| 18 | |
| 19 | import android.app.AlertDialog; |
| 20 | import android.content.Context; |
| 21 | import android.content.res.Configuration; |
| 22 | import android.os.Build; |
| 23 | import android.os.Bundle; |
| 24 | import android.os.SystemProperties; |
| 25 | import android.telephony.TelephonyManager; |
| 26 | import android.text.TextUtils; |
| 27 | import android.webkit.WebView; |
| 28 | import android.webkit.WebViewClient; |
| 29 | import com.android.internal.app.AlertActivity; |
| 30 | import com.android.internal.app.AlertController; |
| 31 | import android.content.DialogInterface; |
| 32 | import android.content.DialogInterface.OnClickListener; |
| 33 | |
| 34 | /** |
| 35 | * The "dialog" that shows from "Safety information" in the Settings app. |
| 36 | */ |
| 37 | public class SettingsSafetyLegalActivity extends AlertActivity { |
| 38 | private static final String PROPERTY_LSAFETYLEGAL_URL = "ro.url.safetylegal"; |
| 39 | |
| 40 | @Override |
| 41 | protected void onCreate(Bundle savedInstanceState) { |
| 42 | super.onCreate(savedInstanceState); |
| 43 | |
| 44 | String userSafetylegalUrl = SystemProperties.get(PROPERTY_LSAFETYLEGAL_URL); |
| 45 | |
| 46 | final Configuration configuration = getResources().getConfiguration(); |
| 47 | final String language = configuration.locale.getLanguage(); |
| 48 | final String country = configuration.locale.getCountry(); |
| 49 | |
| 50 | String loc = String.format("locale=%s-%s", language, country); |
| 51 | |
| 52 | userSafetylegalUrl = String.format("%s&%s", userSafetylegalUrl, loc); |
| 53 | |
| 54 | if (!isDataNetworkConnected()) { |
| 55 | showErrorAndFinish(userSafetylegalUrl); |
| 56 | return; |
| 57 | } |
| 58 | |
| 59 | WebView webView = new WebView(this); |
| 60 | |
| 61 | // Begin accessing |
| 62 | webView.getSettings().setJavaScriptEnabled(true); |
| 63 | webView.loadUrl(userSafetylegalUrl); |
| 64 | webView.setWebViewClient(new WebViewClient() { |
| 65 | @Override |
| 66 | public void onPageFinished(WebView view, String url) { |
| 67 | // Change from 'Loading...' to the real title |
| 68 | mAlert.setTitle(getString(R.string.settings_safetylegal_activity_title)); |
| 69 | } |
| 70 | }); |
| 71 | |
| 72 | final AlertController.AlertParams p = mAlertParams; |
| 73 | p.mTitle = getString(R.string.settings_safetylegal_activity_loading); |
| 74 | p.mView = webView; |
| 75 | p.mForceInverseBackground = true; |
| 76 | setupAlert(); |
| 77 | } |
| 78 | |
| 79 | private void showErrorAndFinish(String url) { |
| 80 | new AlertDialog.Builder(this) |
| 81 | .setMessage(getResources() |
| 82 | .getString(R.string.settings_safetylegal_activity_unreachable, url)) |
| 83 | .setTitle(R.string.settings_safetylegal_activity_title) |
| 84 | .setPositiveButton(android.R.string.ok, mOkListener) |
| 85 | .setCancelable(true) |
| 86 | .show(); |
| 87 | } |
| 88 | |
| 89 | private boolean isDataNetworkConnected() { |
| 90 | TelephonyManager mTelephonyManager = (TelephonyManager)getSystemService(TELEPHONY_SERVICE); |
| 91 | |
| 92 | if (mTelephonyManager.getDataState() == TelephonyManager.DATA_CONNECTED) { |
| 93 | return true; |
| 94 | } else { |
| 95 | return false; |
| 96 | } |
| 97 | } |
| 98 | |
| 99 | private final OnClickListener mOkListener = new OnClickListener() { |
| 100 | public void onClick(DialogInterface dialog, int whichButton) { |
| 101 | finish(); |
| 102 | } |
| 103 | }; |
| 104 | } |