blob: 0c51928bc1588128cfd18338e9ed498cd005d214 [file] [log] [blame]
Wink Savillea40fb232009-09-26 16:47:18 -07001/*
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
17package com.android.settings;
18
19import android.app.AlertDialog;
20import android.content.Context;
21import android.content.res.Configuration;
22import android.os.Build;
23import android.os.Bundle;
24import android.os.SystemProperties;
25import android.telephony.TelephonyManager;
26import android.text.TextUtils;
Amith Yamasanibe023c82009-09-30 12:18:51 -070027import android.view.KeyEvent;
Wink Savillea40fb232009-09-26 16:47:18 -070028import android.webkit.WebView;
29import android.webkit.WebViewClient;
30import com.android.internal.app.AlertActivity;
31import com.android.internal.app.AlertController;
32import android.content.DialogInterface;
Wink Savillea40fb232009-09-26 16:47:18 -070033
34/**
35 * The "dialog" that shows from "Safety information" in the Settings app.
36 */
Amith Yamasanibe023c82009-09-30 12:18:51 -070037public class SettingsSafetyLegalActivity extends AlertActivity
38 implements DialogInterface.OnCancelListener, DialogInterface.OnClickListener {
Wink Savillea40fb232009-09-26 16:47:18 -070039 private static final String PROPERTY_LSAFETYLEGAL_URL = "ro.url.safetylegal";
40
Amith Yamasanibe023c82009-09-30 12:18:51 -070041 private WebView mWebView;
42
Wink Savillea40fb232009-09-26 16:47:18 -070043 @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 Yamasanibe023c82009-09-30 12:18:51 -070057 mWebView = new WebView(this);
Wink Savillea40fb232009-09-26 16:47:18 -070058
59 // Begin accessing
Amith Yamasanibe023c82009-09-30 12:18:51 -070060 mWebView.getSettings().setJavaScriptEnabled(true);
Amith Yamasani3c9f79b2009-10-06 13:10:14 -070061 if (savedInstanceState == null) {
62 mWebView.loadUrl(userSafetylegalUrl);
63 } else {
64 mWebView.restoreState(savedInstanceState);
65 }
Amith Yamasanibe023c82009-09-30 12:18:51 -070066 mWebView.setWebViewClient(new WebViewClient() {
Wink Savillea40fb232009-09-26 16:47:18 -070067 @Override
68 public void onPageFinished(WebView view, String url) {
69 // Change from 'Loading...' to the real title
70 mAlert.setTitle(getString(R.string.settings_safetylegal_activity_title));
71 }
Amith Yamasanibe023c82009-09-30 12:18:51 -070072
73 @Override
74 public void onReceivedError(WebView view, int errorCode,
75 String description, String failingUrl) {
76 showErrorAndFinish(failingUrl);
77 }
Wink Savillea40fb232009-09-26 16:47:18 -070078 });
79
80 final AlertController.AlertParams p = mAlertParams;
81 p.mTitle = getString(R.string.settings_safetylegal_activity_loading);
Amith Yamasanibe023c82009-09-30 12:18:51 -070082 p.mView = mWebView;
Wink Savillea40fb232009-09-26 16:47:18 -070083 p.mForceInverseBackground = true;
84 setupAlert();
85 }
86
87 private void showErrorAndFinish(String url) {
88 new AlertDialog.Builder(this)
89 .setMessage(getResources()
90 .getString(R.string.settings_safetylegal_activity_unreachable, url))
91 .setTitle(R.string.settings_safetylegal_activity_title)
Amith Yamasanibe023c82009-09-30 12:18:51 -070092 .setPositiveButton(android.R.string.ok, this)
93 .setOnCancelListener(this)
Wink Savillea40fb232009-09-26 16:47:18 -070094 .setCancelable(true)
95 .show();
96 }
97
Amith Yamasanibe023c82009-09-30 12:18:51 -070098 @Override
99 public boolean dispatchKeyEvent(KeyEvent event) {
100 if (event.getKeyCode() == KeyEvent.KEYCODE_BACK
101 && event.getAction() == KeyEvent.ACTION_DOWN) {
102 if (mWebView.canGoBack()) {
103 mWebView.goBack();
104 return true;
105 }
Wink Savillea40fb232009-09-26 16:47:18 -0700106 }
Amith Yamasanibe023c82009-09-30 12:18:51 -0700107 return super.dispatchKeyEvent(event);
Wink Savillea40fb232009-09-26 16:47:18 -0700108 }
109
Amith Yamasanibe023c82009-09-30 12:18:51 -0700110 public void onClick(DialogInterface dialog, int whichButton) {
111 finish();
112 }
113
114 public void onCancel(DialogInterface dialog) {
115 finish();
116 }
Amith Yamasani3c9f79b2009-10-06 13:10:14 -0700117
118 @Override
119 public void onSaveInstanceState(Bundle icicle) {
120 mWebView.saveState(icicle);
121 super.onSaveInstanceState(icicle);
122 }
Wink Savillea40fb232009-09-26 16:47:18 -0700123}