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; |
Amith Yamasani | be023c8 | 2009-09-30 12:18:51 -0700 | [diff] [blame^] | 27 | import android.view.KeyEvent; |
Wink Saville | a40fb23 | 2009-09-26 16:47:18 -0700 | [diff] [blame] | 28 | import android.webkit.WebView; |
| 29 | import android.webkit.WebViewClient; |
| 30 | import com.android.internal.app.AlertActivity; |
| 31 | import com.android.internal.app.AlertController; |
| 32 | import android.content.DialogInterface; |
Wink Saville | a40fb23 | 2009-09-26 16:47:18 -0700 | [diff] [blame] | 33 | |
| 34 | /** |
| 35 | * The "dialog" that shows from "Safety information" in the Settings app. |
| 36 | */ |
Amith Yamasani | be023c8 | 2009-09-30 12:18:51 -0700 | [diff] [blame^] | 37 | public class SettingsSafetyLegalActivity extends AlertActivity |
| 38 | implements DialogInterface.OnCancelListener, DialogInterface.OnClickListener { |
Wink Saville | a40fb23 | 2009-09-26 16:47:18 -0700 | [diff] [blame] | 39 | private static final String PROPERTY_LSAFETYLEGAL_URL = "ro.url.safetylegal"; |
| 40 | |
Amith Yamasani | be023c8 | 2009-09-30 12:18:51 -0700 | [diff] [blame^] | 41 | private WebView mWebView; |
| 42 | |
Wink Saville | a40fb23 | 2009-09-26 16:47:18 -0700 | [diff] [blame] | 43 | @Override |
| 44 | protected void onCreate(Bundle savedInstanceState) { |
| 45 | super.onCreate(savedInstanceState); |
| 46 | |
| 47 | String userSafetylegalUrl = SystemProperties.get(PROPERTY_LSAFETYLEGAL_URL); |
| 48 | |
| 49 | final Configuration configuration = getResources().getConfiguration(); |
| 50 | final String language = configuration.locale.getLanguage(); |
| 51 | final String country = configuration.locale.getCountry(); |
| 52 | |
| 53 | String loc = String.format("locale=%s-%s", language, country); |
| 54 | |
| 55 | userSafetylegalUrl = String.format("%s&%s", userSafetylegalUrl, loc); |
| 56 | |
Amith Yamasani | be023c8 | 2009-09-30 12:18:51 -0700 | [diff] [blame^] | 57 | mWebView = new WebView(this); |
Wink Saville | a40fb23 | 2009-09-26 16:47:18 -0700 | [diff] [blame] | 58 | |
| 59 | // Begin accessing |
Amith Yamasani | be023c8 | 2009-09-30 12:18:51 -0700 | [diff] [blame^] | 60 | mWebView.getSettings().setJavaScriptEnabled(true); |
| 61 | mWebView.loadUrl(userSafetylegalUrl); |
| 62 | mWebView.setWebViewClient(new WebViewClient() { |
Wink Saville | a40fb23 | 2009-09-26 16:47:18 -0700 | [diff] [blame] | 63 | @Override |
| 64 | public void onPageFinished(WebView view, String url) { |
| 65 | // Change from 'Loading...' to the real title |
| 66 | mAlert.setTitle(getString(R.string.settings_safetylegal_activity_title)); |
| 67 | } |
Amith Yamasani | be023c8 | 2009-09-30 12:18:51 -0700 | [diff] [blame^] | 68 | |
| 69 | @Override |
| 70 | public void onReceivedError(WebView view, int errorCode, |
| 71 | String description, String failingUrl) { |
| 72 | showErrorAndFinish(failingUrl); |
| 73 | } |
Wink Saville | a40fb23 | 2009-09-26 16:47:18 -0700 | [diff] [blame] | 74 | }); |
| 75 | |
| 76 | final AlertController.AlertParams p = mAlertParams; |
| 77 | p.mTitle = getString(R.string.settings_safetylegal_activity_loading); |
Amith Yamasani | be023c8 | 2009-09-30 12:18:51 -0700 | [diff] [blame^] | 78 | p.mView = mWebView; |
Wink Saville | a40fb23 | 2009-09-26 16:47:18 -0700 | [diff] [blame] | 79 | p.mForceInverseBackground = true; |
| 80 | setupAlert(); |
| 81 | } |
| 82 | |
| 83 | private void showErrorAndFinish(String url) { |
| 84 | new AlertDialog.Builder(this) |
| 85 | .setMessage(getResources() |
| 86 | .getString(R.string.settings_safetylegal_activity_unreachable, url)) |
| 87 | .setTitle(R.string.settings_safetylegal_activity_title) |
Amith Yamasani | be023c8 | 2009-09-30 12:18:51 -0700 | [diff] [blame^] | 88 | .setPositiveButton(android.R.string.ok, this) |
| 89 | .setOnCancelListener(this) |
Wink Saville | a40fb23 | 2009-09-26 16:47:18 -0700 | [diff] [blame] | 90 | .setCancelable(true) |
| 91 | .show(); |
| 92 | } |
| 93 | |
Amith Yamasani | be023c8 | 2009-09-30 12:18:51 -0700 | [diff] [blame^] | 94 | @Override |
| 95 | public boolean dispatchKeyEvent(KeyEvent event) { |
| 96 | if (event.getKeyCode() == KeyEvent.KEYCODE_BACK |
| 97 | && event.getAction() == KeyEvent.ACTION_DOWN) { |
| 98 | if (mWebView.canGoBack()) { |
| 99 | mWebView.goBack(); |
| 100 | return true; |
| 101 | } |
Wink Saville | a40fb23 | 2009-09-26 16:47:18 -0700 | [diff] [blame] | 102 | } |
Amith Yamasani | be023c8 | 2009-09-30 12:18:51 -0700 | [diff] [blame^] | 103 | return super.dispatchKeyEvent(event); |
Wink Saville | a40fb23 | 2009-09-26 16:47:18 -0700 | [diff] [blame] | 104 | } |
| 105 | |
Amith Yamasani | be023c8 | 2009-09-30 12:18:51 -0700 | [diff] [blame^] | 106 | public void onClick(DialogInterface dialog, int whichButton) { |
| 107 | finish(); |
| 108 | } |
| 109 | |
| 110 | public void onCancel(DialogInterface dialog) { |
| 111 | finish(); |
| 112 | } |
Wink Saville | a40fb23 | 2009-09-26 16:47:18 -0700 | [diff] [blame] | 113 | } |