blob: 619dc945f675cb73231835fb57d43258f9f2b3ae [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);
61 mWebView.loadUrl(userSafetylegalUrl);
62 mWebView.setWebViewClient(new WebViewClient() {
Wink Savillea40fb232009-09-26 16:47:18 -070063 @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 Yamasanibe023c82009-09-30 12:18:51 -070068
69 @Override
70 public void onReceivedError(WebView view, int errorCode,
71 String description, String failingUrl) {
72 showErrorAndFinish(failingUrl);
73 }
Wink Savillea40fb232009-09-26 16:47:18 -070074 });
75
76 final AlertController.AlertParams p = mAlertParams;
77 p.mTitle = getString(R.string.settings_safetylegal_activity_loading);
Amith Yamasanibe023c82009-09-30 12:18:51 -070078 p.mView = mWebView;
Wink Savillea40fb232009-09-26 16:47:18 -070079 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 Yamasanibe023c82009-09-30 12:18:51 -070088 .setPositiveButton(android.R.string.ok, this)
89 .setOnCancelListener(this)
Wink Savillea40fb232009-09-26 16:47:18 -070090 .setCancelable(true)
91 .show();
92 }
93
Amith Yamasanibe023c82009-09-30 12:18:51 -070094 @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 Savillea40fb232009-09-26 16:47:18 -0700102 }
Amith Yamasanibe023c82009-09-30 12:18:51 -0700103 return super.dispatchKeyEvent(event);
Wink Savillea40fb232009-09-26 16:47:18 -0700104 }
105
Amith Yamasanibe023c82009-09-30 12:18:51 -0700106 public void onClick(DialogInterface dialog, int whichButton) {
107 finish();
108 }
109
110 public void onCancel(DialogInterface dialog) {
111 finish();
112 }
Wink Savillea40fb232009-09-26 16:47:18 -0700113}