List of usage examples for android.app AlertDialog setOnShowListener
public void setOnShowListener(@Nullable OnShowListener listener)
From source file:com.otaupdater.SettingsActivity.java
@Override @SuppressWarnings("deprecation") public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) { if (preference == accountPref) { showAccountDialog();/* www .j av a2 s .c om*/ } else if (preference == notifPref) { cfg.setShowNotif(notifPref.isChecked()); } else if (preference == wifidlPref) { cfg.setWifiOnlyDl(wifidlPref.isChecked()); } else if (preference == autodlPref) { if (cfg.hasProKey()) { cfg.setAutoDlState(autodlPref.isChecked()); } else { Utils.showProKeyOnlyFeatureDialog(this, this); cfg.setAutoDlState(false); autodlPref.setChecked(false); } } else if (preference == resetWarnPref) { cfg.clearIgnored(); } else if (preference == prokeyPref) { if (cfg.hasProKey()) { AlertDialog.Builder builder = new AlertDialog.Builder(this); if (cfg.isKeyRedeemCode()) { builder.setMessage(R.string.prokey_redeemed_thanks); } else { builder.setMessage(R.string.prokey_thanks); } builder.setNeutralButton(R.string.close, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); final AlertDialog dlg = builder.create(); dlg.setOnShowListener(new DialogInterface.OnShowListener() { @Override public void onShow(DialogInterface dialog) { onDialogShown(dlg); } }); dlg.setOnDismissListener(new DialogInterface.OnDismissListener() { @Override public void onDismiss(DialogInterface dialog) { onDialogClosed(dlg); } }); dlg.show(); } else { showGetProKeyDialog(); } } else if (preference == donatePref) { startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(Config.SITE_BASE_URL + Config.DONATE_URL))); } else { return super.onPreferenceTreeClick(preferenceScreen, preference); } return true; }
From source file:com.tnc.android.graphite.activities.GraphActivity.java
@Override public boolean onOptionsItemSelected(MenuItem item) { // TODO move to controller switch (item.getItemId()) { case R.id.graph_menu_reload: controller.handleMessage(GraphController.MESSAGE_RELOAD); break;//w w w . j a v a 2 s . c om case R.id.graph_menu_auto_refresh: controller.handleMessage(GraphController.MESSAGE_AUTO_REFRESH_DIALOG); break; case R.id.graph_menu_edit: layout.closeDrawers(); Intent editIntent = new Intent(this, EditActivity.class); startActivityForResult(editIntent, GraphController.ACTIVITY_EDIT_GRAPHS); break; case R.id.graph_menu_save: final EditText input = new EditText(this); final AlertDialog saveDialog = new AlertDialog.Builder(this).setTitle(R.string.save_dialog_title) .setView(input).setPositiveButton(R.string.dialog_positive, null) .setNegativeButton(R.string.dialog_negative, null).create(); saveDialog.setOnShowListener(new DialogInterface.OnShowListener() { @Override public void onShow(DialogInterface dialog) { Button b = saveDialog.getButton(AlertDialog.BUTTON_POSITIVE); b.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { String value = input.getText().toString(); if (!value.equals("")) { controller.handleMessage(GraphController.MESSAGE_SAVE_GRAPH, value); saveDialog.dismiss(); } } }); } }); saveDialog.show(); break; default: return super.onOptionsItemSelected(item); } return true; }
From source file:org.akvo.caddisfly.sensor.colorimetry.liquid.CalibrateListActivity.java
/** * Load the calibrated swatches from the calibration text file * * @param callback callback to be initiated once the loading is complete *//*from ww w . ja va 2s. c o m*/ private void loadCalibration(@NonNull final Context context, @NonNull final Handler.Callback callback) { try { AlertDialog.Builder builder = new AlertDialog.Builder(context); builder.setTitle(R.string.loadCalibration); final ArrayAdapter<String> arrayAdapter = new ArrayAdapter<>(context, R.layout.row_text); final File path = FileHelper.getFilesDir(FileHelper.FileType.CALIBRATION, CaddisflyApp.getApp().getCurrentTestInfo().getId()); File[] listFilesTemp = null; if (path.exists() && path.isDirectory()) { listFilesTemp = path.listFiles(); } final File[] listFiles = listFilesTemp; if (listFiles != null && listFiles.length > 0) { Arrays.sort(listFiles); for (File listFile : listFiles) { arrayAdapter.add(listFile.getName()); } builder.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick(@NonNull DialogInterface dialog, int which) { dialog.dismiss(); } }); builder.setAdapter(arrayAdapter, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { String fileName = listFiles[which].getName(); try { final List<Swatch> swatchList = SwatchHelper.loadCalibrationFromFile(getBaseContext(), fileName); (new AsyncTask<Void, Void, Void>() { @Nullable @Override protected Void doInBackground(Void... params) { SwatchHelper.saveCalibratedSwatches(context, swatchList); return null; } @Override protected void onPostExecute(Void result) { super.onPostExecute(result); callback.handleMessage(null); } }).execute(); } catch (Exception ex) { AlertUtil.showError(context, R.string.error, getString(R.string.errorLoadingFile), null, R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(@NonNull DialogInterface dialog, int which) { dialog.dismiss(); } }, null, null); } } }); final AlertDialog alertDialog = builder.create(); alertDialog.setOnShowListener(new DialogInterface.OnShowListener() { @Override public void onShow(DialogInterface dialogInterface) { final ListView listView = alertDialog.getListView(); listView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() { @Override public boolean onItemLongClick(AdapterView<?> adapterView, View view, int i, long l) { final int position = i; AlertUtil.askQuestion(context, R.string.delete, R.string.deleteConfirm, R.string.delete, R.string.cancel, true, new DialogInterface.OnClickListener() { @SuppressWarnings("unchecked") @Override public void onClick(DialogInterface dialogInterface, int i) { String fileName = listFiles[position].getName(); FileUtil.deleteFile(path, fileName); ArrayAdapter listAdapter = (ArrayAdapter) listView.getAdapter(); listAdapter.remove(listAdapter.getItem(position)); alertDialog.dismiss(); Toast.makeText(context, R.string.deleted, Toast.LENGTH_SHORT) .show(); } }, null); return true; } }); } }); alertDialog.show(); } else { AlertUtil.showMessage(context, R.string.notFound, R.string.loadFilesNotAvailable); } } catch (ActivityNotFoundException ignored) { } callback.handleMessage(null); }
From source file:it.imwatch.nfclottery.dialogs.InsertContactDialog.java
@Override public Dialog onCreateDialog(Bundle savedInstanceState) { // Use the Builder class for convenient dialog construction final Activity activity = getActivity(); if (activity == null) { Log.e(TAG, "Not attached to Activity: cannot build dialog"); return null; }//from www.j a v a 2 s . co m AlertDialog.Builder builder = new AlertDialog.Builder(activity); // Get the layout inflater LayoutInflater inflater = LayoutInflater.from(activity); final View rootView = inflater.inflate(R.layout.dialog_insert, null); if (rootView == null) { Log.e(TAG, "Cannot inflate the dialog layout!"); return null; } mErrorAnimTranslateY = getResources().getDimensionPixelSize(R.dimen.error_anim_translate_y); mEmailErrorTextView = (TextView) rootView.findViewById(R.id.lbl_email_error); mNameErrorTextView = (TextView) rootView.findViewById(R.id.lbl_name_error); // Restore instance state (if any) if (savedInstanceState != null) { mNameErrorState = savedInstanceState.getInt(EXTRA_NAME_ERROR, 0); mEmailErrorState = savedInstanceState.getInt(EXTRA_EMAIL_ERROR, 0); if (mNameErrorState == 1) showNameError(); if (mEmailErrorState == 1) { showEmailError(activity.getString(R.string.error_emailinput_invalid), 1); } else if (mEmailErrorState == 2) { showEmailError(activity.getString(R.string.error_emailinput_duplicate), 2); } } mEmailEditText = (EditText) rootView.findViewById(R.id.txt_edit_email); mNameEditText = (EditText) rootView.findViewById(R.id.txt_edit_name); mOrganizationEditText = (EditText) rootView.findViewById(R.id.txt_edit_organization); mTitleEditText = (EditText) rootView.findViewById(R.id.txt_edit_title); // Add the check for a valid email address and names mEmailEditText.setOnFocusChangeListener(mFocusWatcher); mNameEditText.setOnFocusChangeListener(mFocusWatcher); // Add the check for a valid email during typing mEmailEditText.addTextChangedListener(mEmailTypingWatcher); // Inflate and set the layout for the dialog // Pass null as the parent view because its going in the dialog layout builder.setView(rootView).setPositiveButton(android.R.string.ok, null) .setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { final Dialog thisDialog = InsertContactDialog.this.getDialog(); if (thisDialog != null) { thisDialog.cancel(); } else { Log.w(TAG, "Can't get the Dialog instance."); } } }); // Create the AlertDialog object and return it AlertDialog alertDialog = builder.create(); alertDialog.setOnShowListener(new DialogInterface.OnShowListener() { @Override public void onShow(DialogInterface dialog) { final AlertDialog alertDialog = (AlertDialog) dialog; // Disable the positive button. It will be enabled only when there is a valid email final Button button = alertDialog.getButton(AlertDialog.BUTTON_POSITIVE); if (button != null) { button.setEnabled(false); button.setOnClickListener(new DontAutoCloseDialogListener(alertDialog)); } else { Log.w(TAG, "Can't get the dialog positive button."); } alertDialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE); } }); return alertDialog; }
From source file:org.catrobat.catroid.ui.dialogs.LoginRegisterDialog.java
@Override public Dialog onCreateDialog(Bundle bundle) { View rootView = LayoutInflater.from(getActivity()).inflate(R.layout.dialog_login_register, null); usernameEditText = (EditText) rootView.findViewById(R.id.username); passwordEditText = (EditText) rootView.findViewById(R.id.password); termsOfUseLinkTextView = (TextView) rootView.findViewById(R.id.register_terms_link); String termsOfUseUrl = getString(R.string.about_link_template, Constants.CATROBAT_TERMS_OF_USE_URL, getString(R.string.register_pocketcode_terms_of_use_text)); termsOfUseLinkTextView.setMovementMethod(LinkMovementMethod.getInstance()); termsOfUseLinkTextView.setText(Html.fromHtml(termsOfUseUrl)); usernameEditText.setText(""); passwordEditText.setText(""); final AlertDialog loginRegisterDialog = new AlertDialog.Builder(getActivity()).setView(rootView) .setTitle(R.string.login_register_dialog_title).setPositiveButton(R.string.login_or_register, null) .setNeutralButton(R.string.password_forgotten, null).create(); loginRegisterDialog.setCanceledOnTouchOutside(true); loginRegisterDialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE); loginRegisterDialog.setOnShowListener(new OnShowListener() { @Override/* w w w . jav a 2s.c o m*/ public void onShow(DialogInterface dialog) { InputMethodManager inputManager = (InputMethodManager) getActivity() .getSystemService(Context.INPUT_METHOD_SERVICE); inputManager.showSoftInput(usernameEditText, InputMethodManager.SHOW_IMPLICIT); Button loginRegisterButton = loginRegisterDialog.getButton(AlertDialog.BUTTON_POSITIVE); loginRegisterButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { handleLoginRegisterButtonClick(); } }); Button passwordForgottenButton = loginRegisterDialog.getButton(AlertDialog.BUTTON_NEUTRAL); passwordForgottenButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { handlePasswordForgottenButtonClick(); } }); } }); return loginRegisterDialog; }
From source file:de.spiritcroc.ownlog.ui.fragment.ExportDialog.java
@Override public Dialog onCreateDialog(Bundle savedInstanceState) { View progressView = getActivity().getLayoutInflater().inflate(R.layout.dialog_progess_indeterminate, null); mMessage = progressView.findViewById(R.id.progress_message); mMessage.setText(R.string.export_dialog_message); mProgressBar = progressView.findViewById(R.id.progress_bar); mProgressBar.setVisibility(View.GONE); setCancelable(false);/*from w ww. j a v a 2 s . c o m*/ final AlertDialog alertDialog = new AlertDialog.Builder(getActivity()) .setTitle(R.string.export_dialog_title).setView(progressView) .setPositiveButton(R.string.dialog_ok, null) .setNegativeButton(R.string.dialog_cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // Only close dialog } }).create(); alertDialog.setOnShowListener(new DialogInterface.OnShowListener() { @Override public void onShow(DialogInterface dialog) { alertDialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { PasswdHelper.getWritableDatabase(getActivity(), ExportDialog.this, DB_REQUEST_EXPORT); } }); } }); return alertDialog; }
From source file:com.nks.nksmod.otaupdater.OTAUpdaterActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); final Context context = getApplicationContext(); cfg = Config.getInstance(context);//from ww w. j a v a 2s. co m final int MY_PERMISSIONS_REQUEST_WRITE_EXTERNAL_STORAGE = 0; if (ContextCompat.checkSelfPermission(OTAUpdaterActivity.this, android.Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { if (ActivityCompat.shouldShowRequestPermissionRationale(OTAUpdaterActivity.this, android.Manifest.permission.WRITE_EXTERNAL_STORAGE)) { AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle(R.string.alert_permission_storage); builder.setMessage(R.string.alert_permission_storage_message); builder.setCancelable(false); builder.setNegativeButton(R.string.exit, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); finish(); } }); builder.setNeutralButton(R.string.enable_permission, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); ActivityCompat.requestPermissions(OTAUpdaterActivity.this, new String[] { android.Manifest.permission.WRITE_EXTERNAL_STORAGE }, MY_PERMISSIONS_REQUEST_WRITE_EXTERNAL_STORAGE); } }); final AlertDialog dlg = builder.create(); dlg.setOnShowListener(new DialogInterface.OnShowListener() { @Override public void onShow(DialogInterface dialog) { onDialogShown(dlg); } }); dlg.setOnDismissListener(new DialogInterface.OnDismissListener() { @Override public void onDismiss(DialogInterface dialog) { onDialogClosed(dlg); } }); dlg.show(); } else { ActivityCompat.requestPermissions(OTAUpdaterActivity.this, new String[] { android.Manifest.permission.WRITE_EXTERNAL_STORAGE }, MY_PERMISSIONS_REQUEST_WRITE_EXTERNAL_STORAGE); if (ActivityCompat.shouldShowRequestPermissionRationale(OTAUpdaterActivity.this, android.Manifest.permission.WRITE_EXTERNAL_STORAGE)) { AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle(R.string.alert_permission_storage); builder.setMessage(R.string.alert_permission_storage_message); builder.setCancelable(false); builder.setNegativeButton(R.string.exit, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); finish(); } }); final AlertDialog dlg = builder.create(); dlg.setOnShowListener(new DialogInterface.OnShowListener() { @Override public void onShow(DialogInterface dialog) { onDialogShown(dlg); } }); dlg.setOnDismissListener(new DialogInterface.OnDismissListener() { @Override public void onDismiss(DialogInterface dialog) { onDialogClosed(dlg); } }); dlg.show(); } } } boolean data = Utils.dataAvailable(this); boolean wifi = Utils.wifiConnected(this); if (!data || !wifi) { final boolean nodata = !data && !wifi; if ((nodata && !cfg.getIgnoredDataWarn()) || (!nodata && !cfg.getIgnoredWifiWarn())) { AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle(nodata ? R.string.alert_nodata_title : R.string.alert_nowifi_title); builder.setMessage(nodata ? R.string.alert_nodata_message : R.string.alert_nowifi_message); builder.setCancelable(false); builder.setNegativeButton(R.string.exit, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); finish(); } }); builder.setNeutralButton(R.string.alert_wifi_settings, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); Intent i = new Intent(Settings.ACTION_WIFI_SETTINGS); startActivity(i); } }); builder.setPositiveButton(R.string.ignore, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { if (nodata) { cfg.setIgnoredDataWarn(true); } else { cfg.setIgnoredWifiWarn(true); } dialog.dismiss(); } }); final AlertDialog dlg = builder.create(); dlg.setOnShowListener(new DialogInterface.OnShowListener() { @Override public void onShow(DialogInterface dialog) { onDialogShown(dlg); } }); dlg.setOnDismissListener(new DialogInterface.OnDismissListener() { @Override public void onDismiss(DialogInterface dialog) { onDialogClosed(dlg); } }); dlg.show(); } } Utils.updateDeviceRegistration(this); CheckinReceiver.setDailyAlarm(this); setContentView(R.layout.main); ViewPager mViewPager = (ViewPager) findViewById(R.id.pager); bar = getActionBar(); assert bar != null; bar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); bar.setDisplayOptions(ActionBar.DISPLAY_SHOW_TITLE, ActionBar.DISPLAY_SHOW_TITLE); bar.setTitle(R.string.app_name); TabsAdapter mTabsAdapter = new TabsAdapter(this, mViewPager); mTabsAdapter.addTab(bar.newTab().setText(R.string.main_about), AboutTab.class); ActionBar.Tab romTab = bar.newTab().setText(R.string.main_rom); if (cfg.hasStoredRomUpdate()) romTab.setIcon(R.drawable.ic_action_warning); romTabIdx = mTabsAdapter.addTab(romTab, ROMTab.class); /* ActionBar.Tab kernelTab = bar.newTab().setText(R.string.main_kernel); if (cfg.hasStoredKernelUpdate()) kernelTab.setIcon(R.drawable.ic_action_warning); kernelTabIdx = mTabsAdapter.addTab(kernelTab, KernelTab.class); */ if (!handleNotifAction(getIntent())) { if (cfg.hasStoredRomUpdate() && !cfg.isDownloadingRom()) { cfg.getStoredRomUpdate().showUpdateNotif(this); } /* if (cfg.hasStoredKernelUpdate() && !cfg.isDownloadingKernel()) { cfg.getStoredKernelUpdate().showUpdateNotif(this); } */ if (savedInstanceState != null) { bar.setSelectedNavigationItem(savedInstanceState.getInt(KEY_TAB, 0)); } } }
From source file:com.sdrtouch.tools.DialogManager.java
private Dialog createDialog(final dialogs id) { switch (id) { case DIAG_ABOUT: final AlertDialog addd = new AlertDialog.Builder(getActivity()).setTitle(R.string.help) .setPositiveButton(R.string.btn_ok, new DialogInterface.OnClickListener() { @Override/*from ww w. j ava 2 s .c om*/ public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }).setMessage(Html.fromHtml(getString(R.string.help_info))).create(); try { addd.setOnShowListener(new DialogInterface.OnShowListener() { @Override public void onShow(DialogInterface paramDialogInterface) { try { final TextView tv = (TextView) addd.getWindow().findViewById(android.R.id.message); if (tv != null) tv.setMovementMethod(LinkMovementMethod.getInstance()); } catch (Exception ignored) { } } }); } catch (Exception ignored) { } return addd; case DIAG_LICENSE: return new AlertDialog.Builder(getActivity()).setTitle("License") .setPositiveButton(R.string.btn_ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }).setMessage(readWholeStream(R.raw.license)).create(); } return null; }
From source file:de.spiritcroc.ownlog.ui.fragment.LogFilterEditFragment.java
@Override public Dialog onCreateDialog(Bundle savedInstanceState) { final Activity activity = getActivity(); AlertDialog.Builder builder = new AlertDialog.Builder(activity); final View view = activity.getLayoutInflater().inflate(R.layout.log_filter_edit_item, null); mEditName = (EditText) view.findViewById(R.id.name_edit); mSpinSortOrder = (Spinner) view.findViewById(R.id.sort_order_spin); mCheckStrictFilterTags = (CheckBox) view.findViewById(R.id.tags_strict_check); mStrictFilterTagsInfoNoTags = view.findViewById(R.id.text_view_tags_strict_no_tags); mStrictFilterTagsInfoTags = view.findViewById(R.id.text_view_tags_strict_tags); mEditTagsView = (EditTagsView) view.findViewById(R.id.edit_tags_view); mEditTagsView.setTagsProvider(mTagsProvider); mEditTagsView.setAvailableTagsFilter(mAvailableTagsFilter); mEditExcludedTagsView = (EditTagsView) view.findViewById(R.id.edit_excluded_tags_view); mEditExcludedTagsView.setTagsProvider(mExcludedTagsProvider); mEditExcludedTagsView.setAvailableTagsFilter(mAvailableTagsFilter); View.OnClickListener strictFilterInfoClickListener = new View.OnClickListener() { @Override/* w w w . j a v a2s .co m*/ public void onClick(View view) { mCheckStrictFilterTags.toggle(); } }; mStrictFilterTagsInfoNoTags.setOnClickListener(strictFilterInfoClickListener); mStrictFilterTagsInfoTags.setOnClickListener(strictFilterInfoClickListener); mSortOrderValues = getResources().getStringArray(R.array.edit_log_filter_sort_order_values); mSpinSortOrder.setAdapter(ArrayAdapter.createFromResource(activity, R.array.edit_log_filter_sort_order_entries, R.layout.support_simple_spinner_dropdown_item)); mSpinSortOrder.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) { mSortOrder = i; } @Override public void onNothingSelected(AdapterView<?> adapterView) { } }); mInitName = getString(R.string.log_filter_default_new_name); mInitSortOrder = mSortOrderValues[0]; boolean restoredValues = restoreValues(savedInstanceState); builder.setTitle(mAddItem ? R.string.title_log_filter_add : R.string.title_log_filter_edit).setView(view) .setPositiveButton(R.string.dialog_ok, null) .setNegativeButton(R.string.dialog_cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // Only dismiss } }); if (!mAddItem) { builder.setNeutralButton(R.string.dialog_delete, null); } final AlertDialog alertDialog = builder.create(); alertDialog.setOnShowListener(new DialogInterface.OnShowListener() { @Override public void onShow(DialogInterface dialogInterface) { alertDialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { saveChanges(); } }); if (!mAddItem) { alertDialog.getButton(DialogInterface.BUTTON_NEUTRAL) .setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { promptDelete(); } }); } } }); if (!restoredValues) { loadContent(); if (mAddItem) { initValues(alertDialog); } } return alertDialog; }
From source file:com.otaupdater.OTAUpdaterActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); final Context context = getApplicationContext(); cfg = Config.getInstance(context);/*from w ww . ja va 2 s . c o m*/ if (!cfg.hasProKey()) { bindService(new Intent("com.android.vending.billing.InAppBillingService.BIND"), billingSrvConn = new ServiceConnection() { @Override public void onServiceDisconnected(ComponentName name) { billingSrvConn = null; } @Override public void onServiceConnected(ComponentName name, IBinder binder) { IInAppBillingService service = IInAppBillingService.Stub.asInterface(binder); try { Bundle owned = service.getPurchases(3, getPackageName(), "inapp", null); ArrayList<String> ownedItems = owned.getStringArrayList("INAPP_PURCHASE_ITEM_LIST"); ArrayList<String> ownedItemData = owned .getStringArrayList("INAPP_PURCHASE_DATA_LIST"); if (ownedItems != null && ownedItemData != null) { for (int q = 0; q < ownedItems.size(); q++) { if (ownedItems.get(q).equals(Config.PROKEY_SKU)) { JSONObject itemData = new JSONObject(ownedItemData.get(q)); cfg.setKeyPurchaseToken(itemData.getString("purchaseToken")); break; } } } } catch (RemoteException ignored) { } catch (JSONException e) { e.printStackTrace(); } unbindService(this); billingSrvConn = null; } }, Context.BIND_AUTO_CREATE); } boolean data = Utils.dataAvailable(this); boolean wifi = Utils.wifiConnected(this); if (!data || !wifi) { final boolean nodata = !data && !wifi; if ((nodata && !cfg.getIgnoredDataWarn()) || (!nodata && !cfg.getIgnoredWifiWarn())) { AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle(nodata ? R.string.alert_nodata_title : R.string.alert_nowifi_title); builder.setMessage(nodata ? R.string.alert_nodata_message : R.string.alert_nowifi_message); builder.setCancelable(false); builder.setNegativeButton(R.string.exit, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); finish(); } }); builder.setNeutralButton(R.string.alert_wifi_settings, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); Intent i = new Intent(Settings.ACTION_WIFI_SETTINGS); startActivity(i); } }); builder.setPositiveButton(R.string.ignore, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { if (nodata) { cfg.setIgnoredDataWarn(true); } else { cfg.setIgnoredWifiWarn(true); } dialog.dismiss(); } }); final AlertDialog dlg = builder.create(); dlg.setOnShowListener(new DialogInterface.OnShowListener() { @Override public void onShow(DialogInterface dialog) { onDialogShown(dlg); } }); dlg.setOnDismissListener(new DialogInterface.OnDismissListener() { @Override public void onDismiss(DialogInterface dialog) { onDialogClosed(dlg); } }); dlg.show(); } } Utils.updateDeviceRegistration(this); CheckinReceiver.setDailyAlarm(this); if (!PropUtils.isRomOtaEnabled() && !PropUtils.isKernelOtaEnabled() && !cfg.getIgnoredUnsupportedWarn()) { AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle(R.string.alert_unsupported_title); builder.setMessage(R.string.alert_unsupported_message); builder.setCancelable(false); builder.setNegativeButton(R.string.exit, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); finish(); } }); builder.setPositiveButton(R.string.ignore, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { cfg.setIgnoredUnsupportedWarn(true); dialog.dismiss(); } }); final AlertDialog dlg = builder.create(); dlg.setOnShowListener(new DialogInterface.OnShowListener() { @Override public void onShow(DialogInterface dialog) { onDialogShown(dlg); } }); dlg.setOnDismissListener(new DialogInterface.OnDismissListener() { @Override public void onDismiss(DialogInterface dialog) { onDialogClosed(dlg); } }); dlg.show(); } setContentView(R.layout.main); Fragment adFragment = getFragmentManager().findFragmentById(R.id.ads); if (adFragment != null) getFragmentManager().beginTransaction().hide(adFragment).commit(); ViewPager mViewPager = (ViewPager) findViewById(R.id.pager); bar = getActionBar(); assert bar != null; bar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); bar.setDisplayOptions(ActionBar.DISPLAY_SHOW_TITLE, ActionBar.DISPLAY_SHOW_TITLE); bar.setTitle(R.string.app_name); TabsAdapter mTabsAdapter = new TabsAdapter(this, mViewPager); mTabsAdapter.addTab(bar.newTab().setText(R.string.main_about), AboutTab.class); ActionBar.Tab romTab = bar.newTab().setText(R.string.main_rom); if (cfg.hasStoredRomUpdate()) romTab.setIcon(R.drawable.ic_action_warning); romTabIdx = mTabsAdapter.addTab(romTab, ROMTab.class); ActionBar.Tab kernelTab = bar.newTab().setText(R.string.main_kernel); if (cfg.hasStoredKernelUpdate()) kernelTab.setIcon(R.drawable.ic_action_warning); kernelTabIdx = mTabsAdapter.addTab(kernelTab, KernelTab.class); if (!handleNotifAction(getIntent())) { if (cfg.hasStoredRomUpdate() && !cfg.isDownloadingRom()) { cfg.getStoredRomUpdate().showUpdateNotif(this); } if (cfg.hasStoredKernelUpdate() && !cfg.isDownloadingKernel()) { cfg.getStoredKernelUpdate().showUpdateNotif(this); } if (savedInstanceState != null) { bar.setSelectedNavigationItem(savedInstanceState.getInt(KEY_TAB, 0)); } } }