use of android.content.DialogInterface in project Rashr by DsLNeXuS.
the class SettingsFragment method onCreateView.
@Override
public View onCreateView(final LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
final View root = inflater.inflate(R.layout.fragment_settings, container, false);
final AppCompatButton bSetDevName = (AppCompatButton) root.findViewById(R.id.bSetDevName);
final AppCompatCheckBox cbShowAds = (AppCompatCheckBox) root.findViewById(R.id.cbShowAds);
final AppCompatCheckBox cbLog = (AppCompatCheckBox) root.findViewById(R.id.cbLog);
// final AppCompatCheckBox cbDarkUI = (AppCompatCheckBox) root.findViewById(R.id.cbDarkUI);
final AppCompatCheckBox cbCheckUpdates = (AppCompatCheckBox) root.findViewById(R.id.cbCheckUpdates);
final AppCompatCheckBox cbHideUpToDateHint = (AppCompatCheckBox) root.findViewById(R.id.cbShowUpToDateHints);
final AppCompatCheckBox cbSkipSizeCheck = (AppCompatCheckBox) root.findViewById(R.id.cbSkipSizeChecking);
final AppCompatCheckBox cbSkipValidate = (AppCompatCheckBox) root.findViewById(R.id.cbSkipValidateImages);
final AppCompatButton bShowLogs = (AppCompatButton) root.findViewById(R.id.bShowLogs);
final AppCompatButton bReport = (AppCompatButton) root.findViewById(R.id.bReport);
final AppCompatButton bShowChangelog = (AppCompatButton) root.findViewById(R.id.bShowChangelog);
final AppCompatButton bReset = (AppCompatButton) root.findViewById(R.id.bReset);
final AppCompatButton bClearCache = (AppCompatButton) root.findViewById(R.id.bClearCache);
final AppCompatButton bShowLicences = (AppCompatButton) root.findViewById(R.id.bShowLicenses);
// cbDarkUI.setChecked(Common.getBooleanPref(root.getContext(), Const.PREF_NAME,
// Const.PREF_KEY_DARK_UI));
cbShowAds.setChecked(Common.getBooleanPref(root.getContext(), Const.PREF_NAME, Const.PREF_KEY_ADS));
cbLog.setChecked(Common.getBooleanPref(root.getContext(), Const.PREF_NAME, Const.PREF_KEY_LOG));
cbCheckUpdates.setChecked(Common.getBooleanPref(root.getContext(), Const.PREF_NAME, Const.PREF_KEY_CHECK_UPDATES));
cbShowAds.setChecked(Common.getBooleanPref(root.getContext(), Const.PREF_NAME, Const.PREF_KEY_ADS));
cbHideUpToDateHint.setChecked(Common.getBooleanPref(root.getContext(), Const.PREF_NAME, Const.PREF_KEY_HIDE_UPDATE_HINTS));
cbSkipSizeCheck.setChecked(Common.getBooleanPref(root.getContext(), Const.PREF_NAME, Const.PREF_KEY_SKIP_SIZE_CHECK));
cbSkipValidate.setChecked(Common.getBooleanPref(root.getContext(), Const.PREF_NAME, Const.PREF_KEY_SKIP_IMAGE_CHECK));
// cbDarkUI.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
// @Override
// public void onCheckedChanged(CompoundButton view, boolean isChecked) {
// Common.setBooleanPref(view.getContext(), Const.PREF_NAME,
// Const.PREF_KEY_DARK_UI, isChecked);
// RashrActivity.isDark = isChecked;
// }
// });
cbLog.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton view, boolean isChecked) {
Common.setBooleanPref(view.getContext(), Const.PREF_NAME, Const.PREF_KEY_LOG, isChecked);
root.findViewById(R.id.bShowLogs).setVisibility(isChecked ? View.VISIBLE : View.INVISIBLE);
}
});
cbCheckUpdates.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton view, boolean isChecked) {
Common.setBooleanPref(view.getContext(), Const.PREF_NAME, Const.PREF_KEY_CHECK_UPDATES, isChecked);
}
});
cbShowAds.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton view, boolean isChecked) {
Common.setBooleanPref(view.getContext(), Const.PREF_NAME, Const.PREF_KEY_ADS, isChecked);
}
});
cbHideUpToDateHint.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton view, boolean isChecked) {
Common.setBooleanPref(view.getContext(), Const.PREF_NAME, Const.PREF_KEY_HIDE_UPDATE_HINTS, isChecked);
}
});
cbSkipSizeCheck.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
Common.setBooleanPref(buttonView.getContext(), Const.PREF_NAME, Const.PREF_KEY_SKIP_SIZE_CHECK, isChecked);
}
});
cbSkipValidate.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
Common.setBooleanPref(buttonView.getContext(), Const.PREF_NAME, Const.PREF_KEY_SKIP_IMAGE_CHECK, isChecked);
}
});
final RashrActivity activity = (RashrActivity) getActivity();
bReport.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
ReportDialog dialog = new ReportDialog(activity, "");
dialog.show();
}
});
bShowLogs.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
showLogs();
}
});
bShowLogs.setVisibility(cbLog.isChecked() ? View.VISIBLE : View.INVISIBLE);
bReset.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
AppCompatActivity activity = (AppCompatActivity) getActivity();
SharedPreferences.Editor editor = activity.getSharedPreferences(Const.PREF_NAME, Context.MODE_PRIVATE).edit();
editor.clear().apply();
editor = activity.getSharedPreferences(Const.PREF_NAME, Context.MODE_PRIVATE).edit();
editor.clear().apply();
RashrActivity.firstSetup(v.getContext());
}
});
bClearCache.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final AlertDialog.Builder ConfirmationDialog = new AlertDialog.Builder(v.getContext());
ConfirmationDialog.setTitle(R.string.warning);
ConfirmationDialog.setMessage(R.string.delete_confirmation);
ConfirmationDialog.setPositiveButton(R.string.positive, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
if (!Common.deleteFolder(Const.PathToCWM, false) || !Common.deleteFolder(Const.PathToTWRP, false) || !Common.deleteFolder(Const.PathToPhilz, false) || !Common.deleteFolder(Const.PathToStockRecovery, false) || !Common.deleteFolder(Const.PathToStockKernel, false)) {
Toast.makeText(getActivity(), R.string.delete_failed, Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(getActivity(), R.string.files_deleted, Toast.LENGTH_SHORT).show();
}
}
});
ConfirmationDialog.setNegativeButton(R.string.negative, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
});
ConfirmationDialog.show();
}
});
bShowChangelog.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
SettingsFragment.showChangelog(v.getContext());
}
});
bShowLicences.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
new LicensesDialog.Builder(v.getContext()).setNotices(R.raw.licenses_notice).setIncludeOwnLicense(true).build().show();
}
});
bSetDevName.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final AppCompatEditText et = new AppCompatEditText(v.getContext());
AlertDialog.Builder inputDialog = new AlertDialog.Builder(v.getContext());
String dev_name = Common.getStringPref(v.getContext(), Const.PREF_NAME, Const.PREF_KEY_DEVICE_NAME);
if (dev_name.equals(""))
dev_name = RashrApp.DEVICE.getName();
et.setText(dev_name);
inputDialog.setTitle(R.string.device_name);
inputDialog.setView(et);
inputDialog.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
String name = et.getText().toString();
if (!name.equals("")) {
Common.setStringPref(getContext(), Const.PREF_NAME, Const.PREF_KEY_DEVICE_NAME, et.getText().toString());
Snackbar.make(bSetDevName, R.string.please_restart, Snackbar.LENGTH_SHORT).show();
}
}
});
inputDialog.setNeutralButton(R.string.reset, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Common.setStringPref(getContext(), Const.PREF_NAME, Const.PREF_KEY_DEVICE_NAME, Build.DEVICE.toLowerCase());
}
});
inputDialog.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
});
inputDialog.show();
}
});
return root;
}
use of android.content.DialogInterface in project android_frameworks_base by DirtyUnicorns.
the class VersionDialog method onCreateDialog.
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
final Activity activity = getActivity();
// Need to use our library's resources for showing the dialog.
final Context context;
try {
context = activity.createPackageContext(SharedLibraryMain.LIBRARY_PACKAGE, 0);
} catch (PackageManager.NameNotFoundException e) {
throw new IllegalStateException("Can't find my package!", e);
}
final Resources res = context.getResources();
AlertDialog.Builder builder = new AlertDialog.Builder(activity);
builder.setTitle(res.getText(R.string.upgrade_title));
builder.setMessage(res.getString(R.string.upgrade_body, activity.getApplicationInfo().loadLabel(activity.getPackageManager()), context.getApplicationInfo().loadLabel(context.getPackageManager())));
builder.setPositiveButton(res.getText(R.string.upgrade_button), new Dialog.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// Launch play store into the details of our app.
try {
activity.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + SharedLibraryMain.LIBRARY_PACKAGE)));
} catch (android.content.ActivityNotFoundException anfe) {
activity.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://play.google.com/store/apps/details?id=" + SharedLibraryMain.LIBRARY_PACKAGE)));
}
}
});
return builder.create();
}
use of android.content.DialogInterface in project android_frameworks_base by DirtyUnicorns.
the class InputMethodManagerService method showInputMethodMenu.
private void showInputMethodMenu(boolean showAuxSubtypes) {
if (DEBUG)
Slog.v(TAG, "Show switching menu. showAuxSubtypes=" + showAuxSubtypes);
final Context context = mContext;
final boolean isScreenLocked = isScreenLocked();
final String lastInputMethodId = mSettings.getSelectedInputMethod();
int lastInputMethodSubtypeId = mSettings.getSelectedInputMethodSubtypeId(lastInputMethodId);
if (DEBUG)
Slog.v(TAG, "Current IME: " + lastInputMethodId);
synchronized (mMethodMap) {
final HashMap<InputMethodInfo, List<InputMethodSubtype>> immis = mSettings.getExplicitlyOrImplicitlyEnabledInputMethodsAndSubtypeListLocked(mContext);
if (immis == null || immis.size() == 0) {
return;
}
hideInputMethodMenuLocked();
final List<ImeSubtypeListItem> imList = mSwitchingController.getSortedInputMethodAndSubtypeListLocked(showAuxSubtypes, isScreenLocked);
if (lastInputMethodSubtypeId == NOT_A_SUBTYPE_ID) {
final InputMethodSubtype currentSubtype = getCurrentInputMethodSubtypeLocked();
if (currentSubtype != null) {
final InputMethodInfo currentImi = mMethodMap.get(mCurMethodId);
lastInputMethodSubtypeId = InputMethodUtils.getSubtypeIdFromHashCode(currentImi, currentSubtype.hashCode());
}
}
final int N = imList.size();
mIms = new InputMethodInfo[N];
mSubtypeIds = new int[N];
int checkedItem = 0;
for (int i = 0; i < N; ++i) {
final ImeSubtypeListItem item = imList.get(i);
mIms[i] = item.mImi;
mSubtypeIds[i] = item.mSubtypeId;
if (mIms[i].getId().equals(lastInputMethodId)) {
int subtypeId = mSubtypeIds[i];
if ((subtypeId == NOT_A_SUBTYPE_ID) || (lastInputMethodSubtypeId == NOT_A_SUBTYPE_ID && subtypeId == 0) || (subtypeId == lastInputMethodSubtypeId)) {
checkedItem = i;
}
}
}
final Context settingsContext = new ContextThemeWrapper(context, com.android.internal.R.style.Theme_DeviceDefault_Settings);
mDialogBuilder = new AlertDialog.Builder(settingsContext);
mDialogBuilder.setOnCancelListener(new OnCancelListener() {
@Override
public void onCancel(DialogInterface dialog) {
hideInputMethodMenu();
}
});
final Context dialogContext = mDialogBuilder.getContext();
final TypedArray a = dialogContext.obtainStyledAttributes(null, com.android.internal.R.styleable.DialogPreference, com.android.internal.R.attr.alertDialogStyle, 0);
final Drawable dialogIcon = a.getDrawable(com.android.internal.R.styleable.DialogPreference_dialogIcon);
a.recycle();
mDialogBuilder.setIcon(dialogIcon);
final LayoutInflater inflater = dialogContext.getSystemService(LayoutInflater.class);
final View tv = inflater.inflate(com.android.internal.R.layout.input_method_switch_dialog_title, null);
mDialogBuilder.setCustomTitle(tv);
// Setup layout for a toggle switch of the hardware keyboard
mSwitchingDialogTitleView = tv;
mSwitchingDialogTitleView.findViewById(com.android.internal.R.id.hard_keyboard_section).setVisibility(mWindowManagerInternal.isHardKeyboardAvailable() ? View.VISIBLE : View.GONE);
final Switch hardKeySwitch = (Switch) mSwitchingDialogTitleView.findViewById(com.android.internal.R.id.hard_keyboard_switch);
hardKeySwitch.setChecked(mShowImeWithHardKeyboard);
hardKeySwitch.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
mSettings.setShowImeWithHardKeyboard(isChecked);
// Ensure that the input method dialog is dismissed when changing
// the hardware keyboard state.
hideInputMethodMenu();
}
});
final ImeSubtypeListAdapter adapter = new ImeSubtypeListAdapter(dialogContext, com.android.internal.R.layout.input_method_switch_item, imList, checkedItem);
final OnClickListener choiceListener = new OnClickListener() {
@Override
public void onClick(final DialogInterface dialog, final int which) {
synchronized (mMethodMap) {
if (mIms == null || mIms.length <= which || mSubtypeIds == null || mSubtypeIds.length <= which) {
return;
}
final InputMethodInfo im = mIms[which];
int subtypeId = mSubtypeIds[which];
adapter.mCheckedItem = which;
adapter.notifyDataSetChanged();
hideInputMethodMenu();
if (im != null) {
if (subtypeId < 0 || subtypeId >= im.getSubtypeCount()) {
subtypeId = NOT_A_SUBTYPE_ID;
}
setInputMethodLocked(im.getId(), subtypeId);
}
}
}
};
mDialogBuilder.setSingleChoiceItems(adapter, checkedItem, choiceListener);
mSwitchingDialog = mDialogBuilder.create();
mSwitchingDialog.setCanceledOnTouchOutside(true);
mSwitchingDialog.getWindow().setType(WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG);
mSwitchingDialog.getWindow().getAttributes().privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS;
mSwitchingDialog.getWindow().getAttributes().setTitle("Select input method");
updateSystemUi(mCurToken, mImeWindowVis, mBackDisposition);
mSwitchingDialog.show();
}
}
use of android.content.DialogInterface in project XobotOS by xamarin.
the class CallbackProxy method handleMessage.
@Override
public void handleMessage(Message msg) {
// 32-bit reads and writes.
switch(msg.what) {
case PAGE_STARTED:
String startedUrl = msg.getData().getString("url");
mWebView.onPageStarted(startedUrl);
if (mWebViewClient != null) {
mWebViewClient.onPageStarted(mWebView, startedUrl, (Bitmap) msg.obj);
}
break;
case PAGE_FINISHED:
String finishedUrl = (String) msg.obj;
mWebView.onPageFinished(finishedUrl);
if (mWebViewClient != null) {
mWebViewClient.onPageFinished(mWebView, finishedUrl);
}
break;
case RECEIVED_ICON:
if (mWebChromeClient != null) {
mWebChromeClient.onReceivedIcon(mWebView, (Bitmap) msg.obj);
}
break;
case RECEIVED_TOUCH_ICON_URL:
if (mWebChromeClient != null) {
mWebChromeClient.onReceivedTouchIconUrl(mWebView, (String) msg.obj, msg.arg1 == 1);
}
break;
case RECEIVED_TITLE:
if (mWebChromeClient != null) {
mWebChromeClient.onReceivedTitle(mWebView, (String) msg.obj);
}
break;
case REPORT_ERROR:
if (mWebViewClient != null) {
int reasonCode = msg.arg1;
final String description = msg.getData().getString("description");
final String failUrl = msg.getData().getString("failingUrl");
mWebViewClient.onReceivedError(mWebView, reasonCode, description, failUrl);
}
break;
case RESEND_POST_DATA:
Message resend = (Message) msg.getData().getParcelable("resend");
Message dontResend = (Message) msg.getData().getParcelable("dontResend");
if (mWebViewClient != null) {
mWebViewClient.onFormResubmission(mWebView, dontResend, resend);
} else {
dontResend.sendToTarget();
}
break;
case OVERRIDE_URL:
String overrideUrl = msg.getData().getString("url");
boolean override = uiOverrideUrlLoading(overrideUrl);
ResultTransport<Boolean> result = (ResultTransport<Boolean>) msg.obj;
synchronized (this) {
result.setResult(override);
notify();
}
break;
case AUTH_REQUEST:
if (mWebViewClient != null) {
HttpAuthHandler handler = (HttpAuthHandler) msg.obj;
String host = msg.getData().getString("host");
String realm = msg.getData().getString("realm");
mWebViewClient.onReceivedHttpAuthRequest(mWebView, handler, host, realm);
}
break;
case SSL_ERROR:
if (mWebViewClient != null) {
HashMap<String, Object> map = (HashMap<String, Object>) msg.obj;
mWebViewClient.onReceivedSslError(mWebView, (SslErrorHandler) map.get("handler"), (SslError) map.get("error"));
}
break;
case PROCEEDED_AFTER_SSL_ERROR:
if (mWebViewClient != null) {
mWebViewClient.onProceededAfterSslError(mWebView, (SslError) msg.obj);
}
break;
case CLIENT_CERT_REQUEST:
if (mWebViewClient != null) {
HashMap<String, Object> map = (HashMap<String, Object>) msg.obj;
mWebViewClient.onReceivedClientCertRequest(mWebView, (ClientCertRequestHandler) map.get("handler"), (String) map.get("host_and_port"));
}
break;
case PROGRESS:
// changed.
synchronized (this) {
if (mWebChromeClient != null) {
mWebChromeClient.onProgressChanged(mWebView, mLatestProgress);
}
mProgressUpdatePending = false;
}
break;
case UPDATE_VISITED:
if (mWebViewClient != null) {
mWebViewClient.doUpdateVisitedHistory(mWebView, (String) msg.obj, msg.arg1 != 0);
}
break;
case LOAD_RESOURCE:
if (mWebViewClient != null) {
mWebViewClient.onLoadResource(mWebView, (String) msg.obj);
}
break;
case DOWNLOAD_FILE:
if (mDownloadListener != null) {
String url = msg.getData().getString("url");
String userAgent = msg.getData().getString("userAgent");
String contentDisposition = msg.getData().getString("contentDisposition");
String mimetype = msg.getData().getString("mimetype");
Long contentLength = msg.getData().getLong("contentLength");
mDownloadListener.onDownloadStart(url, userAgent, contentDisposition, mimetype, contentLength);
}
break;
case CREATE_WINDOW:
if (mWebChromeClient != null) {
if (!mWebChromeClient.onCreateWindow(mWebView, msg.arg1 == 1, msg.arg2 == 1, (Message) msg.obj)) {
synchronized (this) {
notify();
}
}
mWebView.dismissZoomControl();
}
break;
case REQUEST_FOCUS:
if (mWebChromeClient != null) {
mWebChromeClient.onRequestFocus(mWebView);
}
break;
case CLOSE_WINDOW:
if (mWebChromeClient != null) {
mWebChromeClient.onCloseWindow((WebView) msg.obj);
}
break;
case SAVE_PASSWORD:
Bundle bundle = msg.getData();
String schemePlusHost = bundle.getString("host");
String username = bundle.getString("username");
String password = bundle.getString("password");
// will not be sent and we should notify WebCore ourselves.
if (!mWebView.onSavePassword(schemePlusHost, username, password, (Message) msg.obj)) {
synchronized (this) {
notify();
}
}
break;
case ASYNC_KEYEVENTS:
if (mWebViewClient != null) {
mWebViewClient.onUnhandledKeyEvent(mWebView, (KeyEvent) msg.obj);
}
break;
case EXCEEDED_DATABASE_QUOTA:
if (mWebChromeClient != null) {
HashMap<String, Object> map = (HashMap<String, Object>) msg.obj;
String databaseIdentifier = (String) map.get("databaseIdentifier");
String url = (String) map.get("url");
long currentQuota = ((Long) map.get("currentQuota")).longValue();
long totalUsedQuota = ((Long) map.get("totalUsedQuota")).longValue();
long estimatedSize = ((Long) map.get("estimatedSize")).longValue();
WebStorage.QuotaUpdater quotaUpdater = (WebStorage.QuotaUpdater) map.get("quotaUpdater");
mWebChromeClient.onExceededDatabaseQuota(url, databaseIdentifier, currentQuota, estimatedSize, totalUsedQuota, quotaUpdater);
}
break;
case REACHED_APPCACHE_MAXSIZE:
if (mWebChromeClient != null) {
HashMap<String, Object> map = (HashMap<String, Object>) msg.obj;
long spaceNeeded = ((Long) map.get("spaceNeeded")).longValue();
long totalUsedQuota = ((Long) map.get("totalUsedQuota")).longValue();
WebStorage.QuotaUpdater quotaUpdater = (WebStorage.QuotaUpdater) map.get("quotaUpdater");
mWebChromeClient.onReachedMaxAppCacheSize(spaceNeeded, totalUsedQuota, quotaUpdater);
}
break;
case GEOLOCATION_PERMISSIONS_SHOW_PROMPT:
if (mWebChromeClient != null) {
HashMap<String, Object> map = (HashMap<String, Object>) msg.obj;
String origin = (String) map.get("origin");
GeolocationPermissions.Callback callback = (GeolocationPermissions.Callback) map.get("callback");
mWebChromeClient.onGeolocationPermissionsShowPrompt(origin, callback);
}
break;
case GEOLOCATION_PERMISSIONS_HIDE_PROMPT:
if (mWebChromeClient != null) {
mWebChromeClient.onGeolocationPermissionsHidePrompt();
}
break;
case JS_ALERT:
if (mWebChromeClient != null) {
final JsResult res = (JsResult) msg.obj;
String message = msg.getData().getString("message");
String url = msg.getData().getString("url");
if (!mWebChromeClient.onJsAlert(mWebView, url, message, res)) {
if (!canShowAlertDialog()) {
res.cancel();
res.setReady();
break;
}
new AlertDialog.Builder(mContext).setTitle(getJsDialogTitle(url)).setMessage(message).setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
res.confirm();
}
}).setOnCancelListener(new DialogInterface.OnCancelListener() {
public void onCancel(DialogInterface dialog) {
res.cancel();
}
}).show();
}
res.setReady();
}
break;
case JS_CONFIRM:
if (mWebChromeClient != null) {
final JsResult res = (JsResult) msg.obj;
String message = msg.getData().getString("message");
String url = msg.getData().getString("url");
if (!mWebChromeClient.onJsConfirm(mWebView, url, message, res)) {
if (!canShowAlertDialog()) {
res.cancel();
res.setReady();
break;
}
new AlertDialog.Builder(mContext).setTitle(getJsDialogTitle(url)).setMessage(message).setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
res.confirm();
}
}).setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
res.cancel();
}
}).setOnCancelListener(new DialogInterface.OnCancelListener() {
public void onCancel(DialogInterface dialog) {
res.cancel();
}
}).show();
}
// Tell the JsResult that it is ready for client
// interaction.
res.setReady();
}
break;
case JS_PROMPT:
if (mWebChromeClient != null) {
final JsPromptResult res = (JsPromptResult) msg.obj;
String message = msg.getData().getString("message");
String defaultVal = msg.getData().getString("default");
String url = msg.getData().getString("url");
if (!mWebChromeClient.onJsPrompt(mWebView, url, message, defaultVal, res)) {
if (!canShowAlertDialog()) {
res.cancel();
res.setReady();
break;
}
final LayoutInflater factory = LayoutInflater.from(mContext);
final View view = factory.inflate(R.layout.js_prompt, null);
final EditText v = (EditText) view.findViewById(R.id.value);
v.setText(defaultVal);
((TextView) view.findViewById(R.id.message)).setText(message);
new AlertDialog.Builder(mContext).setTitle(getJsDialogTitle(url)).setView(view).setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
res.confirm(v.getText().toString());
}
}).setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
res.cancel();
}
}).setOnCancelListener(new DialogInterface.OnCancelListener() {
public void onCancel(DialogInterface dialog) {
res.cancel();
}
}).show();
}
// Tell the JsResult that it is ready for client
// interaction.
res.setReady();
}
break;
case JS_UNLOAD:
if (mWebChromeClient != null) {
final JsResult res = (JsResult) msg.obj;
String message = msg.getData().getString("message");
String url = msg.getData().getString("url");
if (!mWebChromeClient.onJsBeforeUnload(mWebView, url, message, res)) {
if (!canShowAlertDialog()) {
res.cancel();
res.setReady();
break;
}
final String m = mContext.getString(R.string.js_dialog_before_unload, message);
new AlertDialog.Builder(mContext).setMessage(m).setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
res.confirm();
}
}).setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
res.cancel();
}
}).show();
}
res.setReady();
}
break;
case JS_TIMEOUT:
if (mWebChromeClient != null) {
final JsResult res = (JsResult) msg.obj;
if (mWebChromeClient.onJsTimeout()) {
res.confirm();
} else {
res.cancel();
}
res.setReady();
}
break;
case RECEIVED_CERTIFICATE:
mWebView.setCertificate((SslCertificate) msg.obj);
break;
case NOTIFY:
synchronized (this) {
notify();
}
break;
case SCALE_CHANGED:
if (mWebViewClient != null) {
mWebViewClient.onScaleChanged(mWebView, msg.getData().getFloat("old"), msg.getData().getFloat("new"));
}
break;
case SWITCH_OUT_HISTORY:
mWebView.switchOutDrawHistory();
break;
case ADD_MESSAGE_TO_CONSOLE:
if (mWebChromeClient == null) {
break;
}
String message = msg.getData().getString("message");
String sourceID = msg.getData().getString("sourceID");
int lineNumber = msg.getData().getInt("lineNumber");
int msgLevel = msg.getData().getInt("msgLevel");
int numberOfMessageLevels = ConsoleMessage.MessageLevel.values().length;
// Sanity bounds check as we'll index an array with msgLevel
if (msgLevel < 0 || msgLevel >= numberOfMessageLevels) {
msgLevel = 0;
}
ConsoleMessage.MessageLevel messageLevel = ConsoleMessage.MessageLevel.values()[msgLevel];
if (!mWebChromeClient.onConsoleMessage(new ConsoleMessage(message, sourceID, lineNumber, messageLevel))) {
// If false was returned the user did not provide their own console function so
// we should output some default messages to the system log.
String logTag = "Web Console";
String logMessage = message + " at " + sourceID + ":" + lineNumber;
switch(messageLevel) {
case TIP:
Log.v(logTag, logMessage);
break;
case LOG:
Log.i(logTag, logMessage);
break;
case WARNING:
Log.w(logTag, logMessage);
break;
case ERROR:
Log.e(logTag, logMessage);
break;
case DEBUG:
Log.d(logTag, logMessage);
break;
}
}
break;
case GET_VISITED_HISTORY:
if (mWebChromeClient != null) {
mWebChromeClient.getVisitedHistory((ValueCallback<String[]>) msg.obj);
}
break;
case OPEN_FILE_CHOOSER:
if (mWebChromeClient != null) {
UploadFileMessageData data = (UploadFileMessageData) msg.obj;
mWebChromeClient.openFileChooser(data.getUploadFile(), data.getAcceptType());
}
break;
case ADD_HISTORY_ITEM:
if (mWebBackForwardListClient != null) {
mWebBackForwardListClient.onNewHistoryItem((WebHistoryItem) msg.obj);
}
break;
case HISTORY_INDEX_CHANGED:
if (mWebBackForwardListClient != null) {
mWebBackForwardListClient.onIndexChanged((WebHistoryItem) msg.obj, msg.arg1);
}
break;
case AUTH_CREDENTIALS:
{
String host = msg.getData().getString("host");
String realm = msg.getData().getString("realm");
username = msg.getData().getString("username");
password = msg.getData().getString("password");
mWebView.setHttpAuthUsernamePassword(host, realm, username, password);
break;
}
case SET_INSTALLABLE_WEBAPP:
if (mWebChromeClient != null) {
mWebChromeClient.setInstallableWebApp();
}
break;
case NOTIFY_SEARCHBOX_LISTENERS:
{
SearchBoxImpl searchBox = (SearchBoxImpl) mWebView.getSearchBox();
@SuppressWarnings("unchecked") List<String> suggestions = (List<String>) msg.obj;
searchBox.handleSuggestions(msg.getData().getString("query"), suggestions);
break;
}
case AUTO_LOGIN:
{
if (mWebViewClient != null) {
String realm = msg.getData().getString("realm");
String account = msg.getData().getString("account");
String args = msg.getData().getString("args");
mWebViewClient.onReceivedLoginRequest(mWebView, realm, account, args);
}
break;
}
case SEARCHBOX_IS_SUPPORTED_CALLBACK:
{
SearchBoxImpl searchBox = (SearchBoxImpl) mWebView.getSearchBox();
Boolean supported = (Boolean) msg.obj;
searchBox.handleIsSupportedCallback(supported);
break;
}
case SEARCHBOX_DISPATCH_COMPLETE_CALLBACK:
{
SearchBoxImpl searchBox = (SearchBoxImpl) mWebView.getSearchBox();
Boolean success = (Boolean) msg.obj;
searchBox.handleDispatchCompleteCallback(msg.getData().getString("function"), msg.getData().getInt("id"), success);
break;
}
}
}
use of android.content.DialogInterface in project kdeconnect-android by KDE.
the class MaterialActivity method renameDevice.
public void renameDevice() {
final TextView nameView = (TextView) mNavigationView.findViewById(R.id.device_name);
final EditText deviceNameEdit = new EditText(MaterialActivity.this);
String deviceName = DeviceHelper.getDeviceName(MaterialActivity.this);
deviceNameEdit.setText(deviceName);
deviceNameEdit.setPadding(((int) (18 * getResources().getDisplayMetrics().density)), ((int) (16 * getResources().getDisplayMetrics().density)), ((int) (18 * getResources().getDisplayMetrics().density)), ((int) (12 * getResources().getDisplayMetrics().density)));
new AlertDialog.Builder(MaterialActivity.this).setView(deviceNameEdit).setPositiveButton(R.string.device_rename_confirm, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
String deviceName = deviceNameEdit.getText().toString();
DeviceHelper.setDeviceName(MaterialActivity.this, deviceName);
nameView.setText(deviceName);
}
}).setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
}).setTitle(R.string.device_rename_title).show();
}
Aggregations