Fix Safety Settings screen bugs - 2150942, 2151440, 2151727
Handle the back key. Finish the activity if dialog is cancelled. Show an error and finish the activity if URL couldn't be found due to connectivity problem and not just when Telephony is not available.
This commit is contained in:
@@ -24,19 +24,22 @@ import android.os.Bundle;
|
|||||||
import android.os.SystemProperties;
|
import android.os.SystemProperties;
|
||||||
import android.telephony.TelephonyManager;
|
import android.telephony.TelephonyManager;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
|
import android.view.KeyEvent;
|
||||||
import android.webkit.WebView;
|
import android.webkit.WebView;
|
||||||
import android.webkit.WebViewClient;
|
import android.webkit.WebViewClient;
|
||||||
import com.android.internal.app.AlertActivity;
|
import com.android.internal.app.AlertActivity;
|
||||||
import com.android.internal.app.AlertController;
|
import com.android.internal.app.AlertController;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
import android.content.DialogInterface.OnClickListener;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The "dialog" that shows from "Safety information" in the Settings app.
|
* The "dialog" that shows from "Safety information" in the Settings app.
|
||||||
*/
|
*/
|
||||||
public class SettingsSafetyLegalActivity extends AlertActivity {
|
public class SettingsSafetyLegalActivity extends AlertActivity
|
||||||
|
implements DialogInterface.OnCancelListener, DialogInterface.OnClickListener {
|
||||||
private static final String PROPERTY_LSAFETYLEGAL_URL = "ro.url.safetylegal";
|
private static final String PROPERTY_LSAFETYLEGAL_URL = "ro.url.safetylegal";
|
||||||
|
|
||||||
|
private WebView mWebView;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
@@ -51,27 +54,28 @@ public class SettingsSafetyLegalActivity extends AlertActivity {
|
|||||||
|
|
||||||
userSafetylegalUrl = String.format("%s&%s", userSafetylegalUrl, loc);
|
userSafetylegalUrl = String.format("%s&%s", userSafetylegalUrl, loc);
|
||||||
|
|
||||||
if (!isDataNetworkConnected()) {
|
mWebView = new WebView(this);
|
||||||
showErrorAndFinish(userSafetylegalUrl);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
WebView webView = new WebView(this);
|
|
||||||
|
|
||||||
// Begin accessing
|
// Begin accessing
|
||||||
webView.getSettings().setJavaScriptEnabled(true);
|
mWebView.getSettings().setJavaScriptEnabled(true);
|
||||||
webView.loadUrl(userSafetylegalUrl);
|
mWebView.loadUrl(userSafetylegalUrl);
|
||||||
webView.setWebViewClient(new WebViewClient() {
|
mWebView.setWebViewClient(new WebViewClient() {
|
||||||
@Override
|
@Override
|
||||||
public void onPageFinished(WebView view, String url) {
|
public void onPageFinished(WebView view, String url) {
|
||||||
// Change from 'Loading...' to the real title
|
// Change from 'Loading...' to the real title
|
||||||
mAlert.setTitle(getString(R.string.settings_safetylegal_activity_title));
|
mAlert.setTitle(getString(R.string.settings_safetylegal_activity_title));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onReceivedError(WebView view, int errorCode,
|
||||||
|
String description, String failingUrl) {
|
||||||
|
showErrorAndFinish(failingUrl);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
final AlertController.AlertParams p = mAlertParams;
|
final AlertController.AlertParams p = mAlertParams;
|
||||||
p.mTitle = getString(R.string.settings_safetylegal_activity_loading);
|
p.mTitle = getString(R.string.settings_safetylegal_activity_loading);
|
||||||
p.mView = webView;
|
p.mView = mWebView;
|
||||||
p.mForceInverseBackground = true;
|
p.mForceInverseBackground = true;
|
||||||
setupAlert();
|
setupAlert();
|
||||||
}
|
}
|
||||||
@@ -81,24 +85,29 @@ public class SettingsSafetyLegalActivity extends AlertActivity {
|
|||||||
.setMessage(getResources()
|
.setMessage(getResources()
|
||||||
.getString(R.string.settings_safetylegal_activity_unreachable, url))
|
.getString(R.string.settings_safetylegal_activity_unreachable, url))
|
||||||
.setTitle(R.string.settings_safetylegal_activity_title)
|
.setTitle(R.string.settings_safetylegal_activity_title)
|
||||||
.setPositiveButton(android.R.string.ok, mOkListener)
|
.setPositiveButton(android.R.string.ok, this)
|
||||||
|
.setOnCancelListener(this)
|
||||||
.setCancelable(true)
|
.setCancelable(true)
|
||||||
.show();
|
.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isDataNetworkConnected() {
|
@Override
|
||||||
TelephonyManager mTelephonyManager = (TelephonyManager)getSystemService(TELEPHONY_SERVICE);
|
public boolean dispatchKeyEvent(KeyEvent event) {
|
||||||
|
if (event.getKeyCode() == KeyEvent.KEYCODE_BACK
|
||||||
if (mTelephonyManager.getDataState() == TelephonyManager.DATA_CONNECTED) {
|
&& event.getAction() == KeyEvent.ACTION_DOWN) {
|
||||||
|
if (mWebView.canGoBack()) {
|
||||||
|
mWebView.goBack();
|
||||||
return true;
|
return true;
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return super.dispatchKeyEvent(event);
|
||||||
|
}
|
||||||
|
|
||||||
private final OnClickListener mOkListener = new OnClickListener() {
|
|
||||||
public void onClick(DialogInterface dialog, int whichButton) {
|
public void onClick(DialogInterface dialog, int whichButton) {
|
||||||
finish();
|
finish();
|
||||||
}
|
}
|
||||||
};
|
|
||||||
|
public void onCancel(DialogInterface dialog) {
|
||||||
|
finish();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user