1a40fb23734cc5d5ac6e69a060cbb488269ad8af3Wink Saville/* 2a40fb23734cc5d5ac6e69a060cbb488269ad8af3Wink Saville * Copyright (C) 2009 The Android Open Source Project 3a40fb23734cc5d5ac6e69a060cbb488269ad8af3Wink Saville * 4a40fb23734cc5d5ac6e69a060cbb488269ad8af3Wink Saville * Licensed under the Apache License, Version 2.0 (the "License"); 5a40fb23734cc5d5ac6e69a060cbb488269ad8af3Wink Saville * you may not use this file except in compliance with the License. 6a40fb23734cc5d5ac6e69a060cbb488269ad8af3Wink Saville * You may obtain a copy of the License at 7a40fb23734cc5d5ac6e69a060cbb488269ad8af3Wink Saville * 8a40fb23734cc5d5ac6e69a060cbb488269ad8af3Wink Saville * http://www.apache.org/licenses/LICENSE-2.0 9a40fb23734cc5d5ac6e69a060cbb488269ad8af3Wink Saville * 10a40fb23734cc5d5ac6e69a060cbb488269ad8af3Wink Saville * Unless required by applicable law or agreed to in writing, software 11a40fb23734cc5d5ac6e69a060cbb488269ad8af3Wink Saville * distributed under the License is distributed on an "AS IS" BASIS, 12a40fb23734cc5d5ac6e69a060cbb488269ad8af3Wink Saville * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13a40fb23734cc5d5ac6e69a060cbb488269ad8af3Wink Saville * See the License for the specific language governing permissions and 14a40fb23734cc5d5ac6e69a060cbb488269ad8af3Wink Saville * limitations under the License. 15a40fb23734cc5d5ac6e69a060cbb488269ad8af3Wink Saville */ 16a40fb23734cc5d5ac6e69a060cbb488269ad8af3Wink Saville 17a40fb23734cc5d5ac6e69a060cbb488269ad8af3Wink Savillepackage com.android.settings; 18a40fb23734cc5d5ac6e69a060cbb488269ad8af3Wink Saville 19a40fb23734cc5d5ac6e69a060cbb488269ad8af3Wink Savilleimport android.app.AlertDialog; 20a40fb23734cc5d5ac6e69a060cbb488269ad8af3Wink Savilleimport android.content.Context; 21a40fb23734cc5d5ac6e69a060cbb488269ad8af3Wink Savilleimport android.content.res.Configuration; 22a40fb23734cc5d5ac6e69a060cbb488269ad8af3Wink Savilleimport android.os.Build; 23a40fb23734cc5d5ac6e69a060cbb488269ad8af3Wink Savilleimport android.os.Bundle; 24a40fb23734cc5d5ac6e69a060cbb488269ad8af3Wink Savilleimport android.os.SystemProperties; 25a40fb23734cc5d5ac6e69a060cbb488269ad8af3Wink Savilleimport android.telephony.TelephonyManager; 26a40fb23734cc5d5ac6e69a060cbb488269ad8af3Wink Savilleimport android.text.TextUtils; 27be023c8a75567f66b41fb3b11a08b37c68a2e0acAmith Yamasaniimport android.view.KeyEvent; 28a40fb23734cc5d5ac6e69a060cbb488269ad8af3Wink Savilleimport android.webkit.WebView; 29a40fb23734cc5d5ac6e69a060cbb488269ad8af3Wink Savilleimport android.webkit.WebViewClient; 30a40fb23734cc5d5ac6e69a060cbb488269ad8af3Wink Savilleimport com.android.internal.app.AlertActivity; 31a40fb23734cc5d5ac6e69a060cbb488269ad8af3Wink Savilleimport com.android.internal.app.AlertController; 32a40fb23734cc5d5ac6e69a060cbb488269ad8af3Wink Savilleimport android.content.DialogInterface; 33a40fb23734cc5d5ac6e69a060cbb488269ad8af3Wink Saville 34a40fb23734cc5d5ac6e69a060cbb488269ad8af3Wink Saville/** 35a40fb23734cc5d5ac6e69a060cbb488269ad8af3Wink Saville * The "dialog" that shows from "Safety information" in the Settings app. 36a40fb23734cc5d5ac6e69a060cbb488269ad8af3Wink Saville */ 37be023c8a75567f66b41fb3b11a08b37c68a2e0acAmith Yamasanipublic class SettingsSafetyLegalActivity extends AlertActivity 38be023c8a75567f66b41fb3b11a08b37c68a2e0acAmith Yamasani implements DialogInterface.OnCancelListener, DialogInterface.OnClickListener { 39a40fb23734cc5d5ac6e69a060cbb488269ad8af3Wink Saville private static final String PROPERTY_LSAFETYLEGAL_URL = "ro.url.safetylegal"; 40a40fb23734cc5d5ac6e69a060cbb488269ad8af3Wink Saville 41be023c8a75567f66b41fb3b11a08b37c68a2e0acAmith Yamasani private WebView mWebView; 42be023c8a75567f66b41fb3b11a08b37c68a2e0acAmith Yamasani 43a40fb23734cc5d5ac6e69a060cbb488269ad8af3Wink Saville @Override 44a40fb23734cc5d5ac6e69a060cbb488269ad8af3Wink Saville protected void onCreate(Bundle savedInstanceState) { 45a40fb23734cc5d5ac6e69a060cbb488269ad8af3Wink Saville super.onCreate(savedInstanceState); 46a40fb23734cc5d5ac6e69a060cbb488269ad8af3Wink Saville 47a40fb23734cc5d5ac6e69a060cbb488269ad8af3Wink Saville String userSafetylegalUrl = SystemProperties.get(PROPERTY_LSAFETYLEGAL_URL); 48a40fb23734cc5d5ac6e69a060cbb488269ad8af3Wink Saville 49a40fb23734cc5d5ac6e69a060cbb488269ad8af3Wink Saville final Configuration configuration = getResources().getConfiguration(); 50a40fb23734cc5d5ac6e69a060cbb488269ad8af3Wink Saville final String language = configuration.locale.getLanguage(); 51a40fb23734cc5d5ac6e69a060cbb488269ad8af3Wink Saville final String country = configuration.locale.getCountry(); 52a40fb23734cc5d5ac6e69a060cbb488269ad8af3Wink Saville 53a40fb23734cc5d5ac6e69a060cbb488269ad8af3Wink Saville String loc = String.format("locale=%s-%s", language, country); 54a40fb23734cc5d5ac6e69a060cbb488269ad8af3Wink Saville 55a40fb23734cc5d5ac6e69a060cbb488269ad8af3Wink Saville userSafetylegalUrl = String.format("%s&%s", userSafetylegalUrl, loc); 56a40fb23734cc5d5ac6e69a060cbb488269ad8af3Wink Saville 57be023c8a75567f66b41fb3b11a08b37c68a2e0acAmith Yamasani mWebView = new WebView(this); 58a40fb23734cc5d5ac6e69a060cbb488269ad8af3Wink Saville 59a40fb23734cc5d5ac6e69a060cbb488269ad8af3Wink Saville // Begin accessing 60be023c8a75567f66b41fb3b11a08b37c68a2e0acAmith Yamasani mWebView.getSettings().setJavaScriptEnabled(true); 613c9f79ba35c29ee6988f5b0b8a7bb7e59614088aAmith Yamasani if (savedInstanceState == null) { 623c9f79ba35c29ee6988f5b0b8a7bb7e59614088aAmith Yamasani mWebView.loadUrl(userSafetylegalUrl); 633c9f79ba35c29ee6988f5b0b8a7bb7e59614088aAmith Yamasani } else { 643c9f79ba35c29ee6988f5b0b8a7bb7e59614088aAmith Yamasani mWebView.restoreState(savedInstanceState); 653c9f79ba35c29ee6988f5b0b8a7bb7e59614088aAmith Yamasani } 66be023c8a75567f66b41fb3b11a08b37c68a2e0acAmith Yamasani mWebView.setWebViewClient(new WebViewClient() { 67a40fb23734cc5d5ac6e69a060cbb488269ad8af3Wink Saville @Override 68a40fb23734cc5d5ac6e69a060cbb488269ad8af3Wink Saville public void onPageFinished(WebView view, String url) { 69a40fb23734cc5d5ac6e69a060cbb488269ad8af3Wink Saville // Change from 'Loading...' to the real title 70a40fb23734cc5d5ac6e69a060cbb488269ad8af3Wink Saville mAlert.setTitle(getString(R.string.settings_safetylegal_activity_title)); 71a40fb23734cc5d5ac6e69a060cbb488269ad8af3Wink Saville } 72be023c8a75567f66b41fb3b11a08b37c68a2e0acAmith Yamasani 73be023c8a75567f66b41fb3b11a08b37c68a2e0acAmith Yamasani @Override 74be023c8a75567f66b41fb3b11a08b37c68a2e0acAmith Yamasani public void onReceivedError(WebView view, int errorCode, 75be023c8a75567f66b41fb3b11a08b37c68a2e0acAmith Yamasani String description, String failingUrl) { 76be023c8a75567f66b41fb3b11a08b37c68a2e0acAmith Yamasani showErrorAndFinish(failingUrl); 77be023c8a75567f66b41fb3b11a08b37c68a2e0acAmith Yamasani } 78a40fb23734cc5d5ac6e69a060cbb488269ad8af3Wink Saville }); 79a40fb23734cc5d5ac6e69a060cbb488269ad8af3Wink Saville 80a40fb23734cc5d5ac6e69a060cbb488269ad8af3Wink Saville final AlertController.AlertParams p = mAlertParams; 81a40fb23734cc5d5ac6e69a060cbb488269ad8af3Wink Saville p.mTitle = getString(R.string.settings_safetylegal_activity_loading); 82be023c8a75567f66b41fb3b11a08b37c68a2e0acAmith Yamasani p.mView = mWebView; 83a40fb23734cc5d5ac6e69a060cbb488269ad8af3Wink Saville p.mForceInverseBackground = true; 84a40fb23734cc5d5ac6e69a060cbb488269ad8af3Wink Saville setupAlert(); 85a40fb23734cc5d5ac6e69a060cbb488269ad8af3Wink Saville } 86a40fb23734cc5d5ac6e69a060cbb488269ad8af3Wink Saville 87a40fb23734cc5d5ac6e69a060cbb488269ad8af3Wink Saville private void showErrorAndFinish(String url) { 88a40fb23734cc5d5ac6e69a060cbb488269ad8af3Wink Saville new AlertDialog.Builder(this) 89a40fb23734cc5d5ac6e69a060cbb488269ad8af3Wink Saville .setMessage(getResources() 90a40fb23734cc5d5ac6e69a060cbb488269ad8af3Wink Saville .getString(R.string.settings_safetylegal_activity_unreachable, url)) 91a40fb23734cc5d5ac6e69a060cbb488269ad8af3Wink Saville .setTitle(R.string.settings_safetylegal_activity_title) 92be023c8a75567f66b41fb3b11a08b37c68a2e0acAmith Yamasani .setPositiveButton(android.R.string.ok, this) 93be023c8a75567f66b41fb3b11a08b37c68a2e0acAmith Yamasani .setOnCancelListener(this) 94a40fb23734cc5d5ac6e69a060cbb488269ad8af3Wink Saville .setCancelable(true) 95a40fb23734cc5d5ac6e69a060cbb488269ad8af3Wink Saville .show(); 96a40fb23734cc5d5ac6e69a060cbb488269ad8af3Wink Saville } 97a40fb23734cc5d5ac6e69a060cbb488269ad8af3Wink Saville 98be023c8a75567f66b41fb3b11a08b37c68a2e0acAmith Yamasani @Override 99be023c8a75567f66b41fb3b11a08b37c68a2e0acAmith Yamasani public boolean dispatchKeyEvent(KeyEvent event) { 100be023c8a75567f66b41fb3b11a08b37c68a2e0acAmith Yamasani if (event.getKeyCode() == KeyEvent.KEYCODE_BACK 101be023c8a75567f66b41fb3b11a08b37c68a2e0acAmith Yamasani && event.getAction() == KeyEvent.ACTION_DOWN) { 102be023c8a75567f66b41fb3b11a08b37c68a2e0acAmith Yamasani if (mWebView.canGoBack()) { 103be023c8a75567f66b41fb3b11a08b37c68a2e0acAmith Yamasani mWebView.goBack(); 104be023c8a75567f66b41fb3b11a08b37c68a2e0acAmith Yamasani return true; 105be023c8a75567f66b41fb3b11a08b37c68a2e0acAmith Yamasani } 106a40fb23734cc5d5ac6e69a060cbb488269ad8af3Wink Saville } 107be023c8a75567f66b41fb3b11a08b37c68a2e0acAmith Yamasani return super.dispatchKeyEvent(event); 108a40fb23734cc5d5ac6e69a060cbb488269ad8af3Wink Saville } 109a40fb23734cc5d5ac6e69a060cbb488269ad8af3Wink Saville 110be023c8a75567f66b41fb3b11a08b37c68a2e0acAmith Yamasani public void onClick(DialogInterface dialog, int whichButton) { 111be023c8a75567f66b41fb3b11a08b37c68a2e0acAmith Yamasani finish(); 112be023c8a75567f66b41fb3b11a08b37c68a2e0acAmith Yamasani } 113be023c8a75567f66b41fb3b11a08b37c68a2e0acAmith Yamasani 114be023c8a75567f66b41fb3b11a08b37c68a2e0acAmith Yamasani public void onCancel(DialogInterface dialog) { 115be023c8a75567f66b41fb3b11a08b37c68a2e0acAmith Yamasani finish(); 116be023c8a75567f66b41fb3b11a08b37c68a2e0acAmith Yamasani } 1173c9f79ba35c29ee6988f5b0b8a7bb7e59614088aAmith Yamasani 1183c9f79ba35c29ee6988f5b0b8a7bb7e59614088aAmith Yamasani @Override 1193c9f79ba35c29ee6988f5b0b8a7bb7e59614088aAmith Yamasani public void onSaveInstanceState(Bundle icicle) { 1203c9f79ba35c29ee6988f5b0b8a7bb7e59614088aAmith Yamasani mWebView.saveState(icicle); 1213c9f79ba35c29ee6988f5b0b8a7bb7e59614088aAmith Yamasani super.onSaveInstanceState(icicle); 1223c9f79ba35c29ee6988f5b0b8a7bb7e59614088aAmith Yamasani } 123a40fb23734cc5d5ac6e69a060cbb488269ad8af3Wink Saville} 124