List of usage examples for android.app AlertDialog.Builder setIcon
public void setIcon(Drawable icon)
From source file:com.android.launcher3.Utilities.java
public static void answerToChangeDefaultLauncher(final Context context) { AlertDialog.Builder alert = new AlertDialog.Builder( new ContextThemeWrapper(context, R.style.AlertDialogCustom)); alert.setTitle(context.getResources().getString(R.string.app_name)); alert.setMessage(context.getResources().getString(R.string.ask_default)); alert.setPositiveButton(context.getResources().getString(R.string.ok), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { changeDefaultLauncher(context); }// w ww . ja va2 s . c o m }); alert.setNegativeButton(context.getResources().getString(R.string.cancel), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { dialog.dismiss(); } }); alert.setIcon(R.mipmap.ic_launcher_home); alert.show(); }
From source file:com.android.launcher3.Utilities.java
public static void answerToRestartLauncher(final Context contextRestart, Context context, final int delay) { AlertDialog.Builder alert = new AlertDialog.Builder( new ContextThemeWrapper(context, R.style.AlertDialogCustom)); alert.setTitle(context.getResources().getString(R.string.app_name)); alert.setMessage(context.getResources().getString(R.string.ask_restart)); alert.setPositiveButton(context.getResources().getString(R.string.ok), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { restart(contextRestart, delay); }//from w w w . ja va 2 s. co m }); alert.setNegativeButton(context.getResources().getString(R.string.cancel), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { dialog.dismiss(); } }); alert.setIcon(R.mipmap.ic_launcher_home); alert.show(); }
From source file:com.dattasmoon.pebble.plugin.EditNotificationActivity.java
@Override public boolean onOptionsItemSelected(MenuItem item) { if (Constants.IS_LOGGABLE) { Log.i(Constants.LOG_TAG, "Selected menu item id: " + String.valueOf(item.getItemId())); }/* w ww .j a v a 2s .c o m*/ final AlertDialog.Builder builder = new AlertDialog.Builder(this); View v; ListViewHolder viewHolder; AdapterView.AdapterContextMenuInfo contextInfo; String app_name; final String package_name; switch (item.getItemId()) { case R.id.btnUncheckAll: builder.setTitle(R.string.dialog_confirm_title); builder.setMessage(getString(R.string.dialog_uncheck_message)); builder.setCancelable(false); builder.setPositiveButton(R.string.confirm, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int buttonId) { if (lvPackages == null || lvPackages.getAdapter() == null || ((packageAdapter) lvPackages.getAdapter()).selected == null) { //something went wrong return; } ((packageAdapter) lvPackages.getAdapter()).selected.clear(); lvPackages.invalidateViews(); } }); builder.setNegativeButton(R.string.decline, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int buttonId) { //do nothing! } }); builder.setIcon(android.R.drawable.ic_dialog_alert); builder.show(); return true; case R.id.btnSave: finish(); return true; case R.id.btnDonate: Intent i = new Intent(Intent.ACTION_VIEW); i.setData(Uri.parse(Constants.DONATION_URL)); startActivity(i); return true; case R.id.btnSettings: Intent settings = new Intent(this, SettingsActivity.class); startActivity(settings); return true; case R.id.btnRename: contextInfo = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo(); int position = contextInfo.position; long id = contextInfo.id; // the child view who's info we're viewing (should be equal to v) v = contextInfo.targetView; app_name = ((TextView) v.findViewById(R.id.tvPackage)).getText().toString(); viewHolder = (ListViewHolder) v.getTag(); if (viewHolder == null || viewHolder.chkEnabled == null) { //failure return true; } package_name = (String) viewHolder.chkEnabled.getTag(); builder.setTitle(R.string.dialog_title_rename_notification); final EditText input = new EditText(this); input.setHint(app_name); builder.setView(input); builder.setPositiveButton(R.string.confirm, null); builder.setNegativeButton(R.string.decline, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { //do nothing } }); final AlertDialog d = builder.create(); d.setOnShowListener(new DialogInterface.OnShowListener() { @Override public void onShow(DialogInterface dialog) { Button b = d.getButton(AlertDialog.BUTTON_POSITIVE); if (b != null) { b.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { //can't be nothing if (input.getText().length() > 0) { if (Constants.IS_LOGGABLE) { Log.i(Constants.LOG_TAG, "Adding rename for " + package_name + " to " + input.getText()); } JSONObject rename = new JSONObject(); try { rename.put("pkg", package_name); rename.put("to", input.getText()); arrayRenames.put(rename); } catch (JSONException e) { e.printStackTrace(); } ((packageAdapter) lvPackages.getAdapter()).notifyDataSetChanged(); d.dismiss(); } else { input.setText(R.string.error_cant_be_blank); } } }); } } }); d.show(); return true; case R.id.btnRemoveRename: contextInfo = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo(); // the child view who's info we're viewing (should be equal to v) v = contextInfo.targetView; app_name = ((TextView) v.findViewById(R.id.tvPackage)).getText().toString(); viewHolder = (ListViewHolder) v.getTag(); if (viewHolder == null || viewHolder.chkEnabled == null) { if (Constants.IS_LOGGABLE) { Log.i(Constants.LOG_TAG, "Viewholder is null or chkEnabled is null"); } //failure return true; } package_name = (String) viewHolder.chkEnabled.getTag(); builder.setTitle( getString(R.string.dialog_title_remove_rename) + app_name + " (" + package_name + ")?"); builder.setPositiveButton(R.string.confirm, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { if (Constants.IS_LOGGABLE) { Log.i(Constants.LOG_TAG, "Before remove is: " + String.valueOf(arrayRenames.length())); } JSONArray tmp = new JSONArray(); try { for (int i = 0; i < arrayRenames.length(); i++) { if (!arrayRenames.getJSONObject(i).getString("pkg").equalsIgnoreCase(package_name)) { tmp.put(arrayRenames.getJSONObject(i)); } } } catch (JSONException e) { e.printStackTrace(); } arrayRenames = tmp; if (Constants.IS_LOGGABLE) { Log.i(Constants.LOG_TAG, "After remove is: " + String.valueOf(arrayRenames.length())); } ((packageAdapter) lvPackages.getAdapter()).notifyDataSetChanged(); } }); builder.setNegativeButton(R.string.decline, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { //do nothing } }); builder.show(); return true; } return super.onOptionsItemSelected(item); }
From source file:org.kiwix.kiwixmobile.KiwixMobileActivity.java
private void manageExternalLaunchAndRestoringViewState() { if (getIntent().getData() != null) { String filePath = FileUtils.getLocalFilePathByUri(getApplicationContext(), getIntent().getData()); if (filePath == null || !new File(filePath).exists()) { Toast.makeText(KiwixMobileActivity.this, getString(R.string.error_filenotfound), Toast.LENGTH_LONG) .show();/* w ww. j a v a2s .c o m*/ return; } Log.d(TAG_KIWIX, " Kiwix started from a filemanager. Intent filePath: " + filePath + " -> open this zimfile and load menu_main page"); openZimFile(new File(filePath), false); } else { SharedPreferences settings = getSharedPreferences(PREF_KIWIX_MOBILE, 0); String zimFile = settings.getString(TAG_CURRENT_FILE, null); if (zimFile != null && new File(zimFile).exists()) { Log.d(TAG_KIWIX, " Kiwix normal start, zimFile loaded last time -> Open last used zimFile " + zimFile); restoreTabStates(); // Alternative would be to restore webView state. But more effort to implement, and actually // fits better normal android behavior if after closing app ("back" button) state is not maintained. } else { if (BuildConfig.IS_CUSTOM_APP) { Log.d(TAG_KIWIX, "Kiwix Custom App starting for the first time. Check Companion ZIM."); String currentLocaleCode = Locale.getDefault().toString(); // Custom App recommends to start off a specific language if (BuildConfig.ENFORCED_LANG.length() > 0 && !BuildConfig.ENFORCED_LANG.equals(currentLocaleCode)) { // change the locale machinery LanguageUtils.handleLocaleChange(this, BuildConfig.ENFORCED_LANG); // save new locale into preferences for next startup SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this); SharedPreferences.Editor editor = sharedPreferences.edit(); editor.putString("pref_language_chooser", BuildConfig.ENFORCED_LANG); editor.apply(); // restart activity for new locale to take effect this.setResult(1236); this.finish(); this.startActivity(new Intent(this, this.getClass())); } String filePath = ""; if (BuildConfig.HAS_EMBEDDED_ZIM) { String appPath = getPackageResourcePath(); File libDir = new File(appPath.substring(0, appPath.lastIndexOf("/")) + "/lib/"); if (libDir.exists() && libDir.listFiles().length > 0) { filePath = libDir.listFiles()[0].getPath() + "/" + BuildConfig.ZIM_FILE_NAME; } if (filePath.isEmpty() || !new File(filePath).exists()) { filePath = String.format("/data/data/%s/lib/%s", BuildConfig.APPLICATION_ID, BuildConfig.ZIM_FILE_NAME); } } else { String fileName = FileUtils.getExpansionAPKFileName(true); filePath = FileUtils.generateSaveFileName(fileName); } if (!FileUtils.doesFileExist(filePath, BuildConfig.ZIM_FILE_SIZE, false)) { AlertDialog.Builder zimFileMissingBuilder = new AlertDialog.Builder(this, dialogStyle()); zimFileMissingBuilder.setTitle(R.string.app_name); zimFileMissingBuilder.setMessage(R.string.customapp_missing_content); zimFileMissingBuilder.setIcon(R.mipmap.kiwix_icon); final Activity activity = this; zimFileMissingBuilder.setPositiveButton(getString(R.string.go_to_play_store), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { String market_uri = "market://details?id=" + BuildConfig.APPLICATION_ID; Intent intent = new Intent(Intent.ACTION_VIEW); intent.setData(Uri.parse(market_uri)); startActivity(intent); activity.finish(); } }); zimFileMissingBuilder.setCancelable(false); AlertDialog zimFileMissingDialog = zimFileMissingBuilder.create(); zimFileMissingDialog.show(); } else { openZimFile(new File(filePath), true); } } else { Log.d(TAG_KIWIX, " Kiwix normal start, no zimFile loaded last time -> display help page"); showHelpPage(); } } } }
From source file:ac.robinson.mediaphone.MediaPhoneActivity.java
private void onBackgroundTaskProgressUpdate(int taskId) { // dismiss dialogs first so we don't leak if onBackgroundTaskCompleted finishes the activity if (mBackgroundRunnerDialogShown) { safeDismissDialog(R.id.dialog_background_runner_in_progress); mBackgroundRunnerDialogShown = false; }/*www . j a v a 2 s . c o m*/ // report any task results onBackgroundTaskCompleted(taskId); // alert when template creation is complete - here as template creation can happen in several places // don't do this from template browser as in that case we're copying the other way (i.e. creating narrative) if (taskId == R.id.make_load_template_task_complete && !(MediaPhoneActivity.this instanceof TemplateBrowserActivity) && !MediaPhoneActivity.this.isFinishing()) { AlertDialog.Builder builder = new AlertDialog.Builder(MediaPhoneActivity.this); builder.setTitle(R.string.make_template_confirmation); builder.setMessage(R.string.make_template_hint); builder.setIcon(android.R.drawable.ic_dialog_info); builder.setPositiveButton(android.R.string.ok, null); AlertDialog alert = builder.create(); alert.show(); } }
From source file:ac.robinson.mediaphone.MediaPhoneActivity.java
protected void deleteNarrativeDialog(final String frameInternalId) { AlertDialog.Builder builder = new AlertDialog.Builder(MediaPhoneActivity.this); builder.setTitle(R.string.delete_narrative_confirmation); builder.setMessage(R.string.delete_narrative_hint); builder.setIcon(android.R.drawable.ic_dialog_alert); builder.setNegativeButton(android.R.string.cancel, null); builder.setPositiveButton(R.string.button_delete, new DialogInterface.OnClickListener() { @Override/*from ww w .j a va 2 s .com*/ public void onClick(DialogInterface dialog, int whichButton) { ContentResolver contentResolver = getContentResolver(); FrameItem currentFrame = FramesManager.findFrameByInternalId(contentResolver, frameInternalId); final String narrativeId = currentFrame.getParentId(); int numFramesDeleted = FramesManager.countFramesByParentId(contentResolver, narrativeId); AlertDialog.Builder builder = new AlertDialog.Builder(MediaPhoneActivity.this); builder.setTitle(R.string.delete_narrative_second_confirmation); builder.setMessage(getResources().getQuantityString(R.plurals.delete_narrative_second_hint, numFramesDeleted, numFramesDeleted)); builder.setIcon(android.R.drawable.ic_dialog_alert); builder.setNegativeButton(android.R.string.cancel, null); builder.setPositiveButton(R.string.button_delete, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int whichButton) { ContentResolver contentResolver = getContentResolver(); NarrativeItem narrativeToDelete = NarrativesManager .findNarrativeByInternalId(contentResolver, narrativeId); narrativeToDelete.setDeleted(true); NarrativesManager.updateNarrative(contentResolver, narrativeToDelete); UIUtilities.showToast(MediaPhoneActivity.this, R.string.delete_narrative_succeeded); onBackPressed(); } }); AlertDialog alert = builder.create(); alert.show(); } }); AlertDialog alert = builder.create(); alert.show(); }
From source file:org.thoughtland.xlocation.ActivityApp.java
public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); final int userId = Util.getUserId(Process.myUid()); // Check privacy service client if (!PrivacyService.checkClient()) return;/*from w w w . ja v a2s. c o m*/ // Set layout setContentView(R.layout.restrictionlist); // Get arguments Bundle extras = getIntent().getExtras(); if (extras == null) { finish(); return; } int uid = extras.getInt(cUid); String restrictionName = (extras.containsKey(cRestrictionName) ? extras.getString(cRestrictionName) : null); String methodName = (extras.containsKey(cMethodName) ? extras.getString(cMethodName) : null); // Get app info mAppInfo = new ApplicationInfoEx(this, uid); if (mAppInfo.getPackageName().size() == 0) { finish(); return; } // Set sub title getActionBar().setSubtitle(TextUtils.join(", ", mAppInfo.getApplicationName())); // Handle info click ImageView imgInfo = (ImageView) findViewById(R.id.imgInfo); imgInfo.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { // Packages can be selected on the web site Util.viewUri(ActivityApp.this, Uri.parse(String.format(ActivityShare.getBaseURL() + "?package_name=%s", mAppInfo.getPackageName().get(0)))); } }); // Display app name TextView tvAppName = (TextView) findViewById(R.id.tvApp); tvAppName.setText(mAppInfo.toString()); // Background color if (mAppInfo.isSystem()) { LinearLayout llInfo = (LinearLayout) findViewById(R.id.llInfo); llInfo.setBackgroundColor(getResources().getColor(getThemed(R.attr.color_dangerous))); } // Display app icon final ImageView imgIcon = (ImageView) findViewById(R.id.imgIcon); imgIcon.setImageDrawable(mAppInfo.getIcon(this)); // Handle icon click imgIcon.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { openContextMenu(imgIcon); } }); // Display on-demand state final ImageView imgCbOnDemand = (ImageView) findViewById(R.id.imgCbOnDemand); boolean isApp = PrivacyManager.isApplication(mAppInfo.getUid()); boolean odSystem = PrivacyManager.getSettingBool(userId, PrivacyManager.cSettingOnDemandSystem, false); boolean gondemand = PrivacyManager.getSettingBool(userId, PrivacyManager.cSettingOnDemand, true); if ((isApp || odSystem) && gondemand) { boolean ondemand = PrivacyManager.getSettingBool(-mAppInfo.getUid(), PrivacyManager.cSettingOnDemand, false); imgCbOnDemand.setImageBitmap(ondemand ? getOnDemandCheckBox() : getOffCheckBox()); imgCbOnDemand.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { boolean ondemand = !PrivacyManager.getSettingBool(-mAppInfo.getUid(), PrivacyManager.cSettingOnDemand, false); PrivacyManager.setSetting(mAppInfo.getUid(), PrivacyManager.cSettingOnDemand, Boolean.toString(ondemand)); imgCbOnDemand.setImageBitmap(ondemand ? getOnDemandCheckBox() : getOffCheckBox()); if (mPrivacyListAdapter != null) mPrivacyListAdapter.notifyDataSetChanged(); } }); } else imgCbOnDemand.setVisibility(View.GONE); // Display restriction state swEnabled = (Switch) findViewById(R.id.swEnable); swEnabled.setChecked( PrivacyManager.getSettingBool(mAppInfo.getUid(), PrivacyManager.cSettingRestricted, true)); swEnabled.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { PrivacyManager.setSetting(mAppInfo.getUid(), PrivacyManager.cSettingRestricted, Boolean.toString(isChecked)); if (mPrivacyListAdapter != null) mPrivacyListAdapter.notifyDataSetChanged(); imgCbOnDemand.setEnabled(isChecked); } }); imgCbOnDemand.setEnabled(swEnabled.isChecked()); // Add context menu to icon registerForContextMenu(imgIcon); // Check if internet access if (!mAppInfo.hasInternet(this)) { ImageView imgInternet = (ImageView) findViewById(R.id.imgInternet); imgInternet.setVisibility(View.INVISIBLE); } // Check if frozen if (!mAppInfo.isFrozen(this)) { ImageView imgFrozen = (ImageView) findViewById(R.id.imgFrozen); imgFrozen.setVisibility(View.INVISIBLE); } // Display version TextView tvVersion = (TextView) findViewById(R.id.tvVersion); tvVersion.setText(TextUtils.join(", ", mAppInfo.getPackageVersionName(this))); // Display package name TextView tvPackageName = (TextView) findViewById(R.id.tvPackageName); tvPackageName.setText(TextUtils.join(", ", mAppInfo.getPackageName())); // Fill privacy expandable list view adapter final ExpandableListView elvRestriction = (ExpandableListView) findViewById(R.id.elvRestriction); elvRestriction.setGroupIndicator(null); mPrivacyListAdapter = new RestrictionAdapter(this, R.layout.restrictionentry, mAppInfo, restrictionName, methodName); elvRestriction.setAdapter(mPrivacyListAdapter); // Listen for group expand elvRestriction.setOnGroupExpandListener(new OnGroupExpandListener() { @Override public void onGroupExpand(final int groupPosition) { if (!PrivacyManager.getSettingBool(userId, PrivacyManager.cSettingMethodExpert, false)) { AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(ActivityApp.this); alertDialogBuilder.setTitle(R.string.app_name); alertDialogBuilder.setIcon(getThemed(R.attr.icon_launcher)); alertDialogBuilder.setMessage(R.string.msg_method_expert); alertDialogBuilder.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { PrivacyManager.setSetting(userId, PrivacyManager.cSettingMethodExpert, Boolean.toString(true)); } }); alertDialogBuilder.setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { elvRestriction.collapseGroup(groupPosition); } }); alertDialogBuilder.setCancelable(false); AlertDialog alertDialog = alertDialogBuilder.create(); alertDialog.show(); } } }); // Go to method if (restrictionName != null) { int groupPosition = new ArrayList<String>(PrivacyManager.getRestrictions(this).values()) .indexOf(restrictionName); elvRestriction.setSelectedGroup(groupPosition); elvRestriction.expandGroup(groupPosition); if (methodName != null) { Version version = new Version(Util.getSelfVersionName(this)); int childPosition = PrivacyManager.getHooks(restrictionName, version) .indexOf(new Hook(restrictionName, methodName)); elvRestriction.setSelectedChild(groupPosition, childPosition, true); } } // Listen for package add/remove IntentFilter iff = new IntentFilter(); iff.addAction(Intent.ACTION_PACKAGE_REMOVED); iff.addDataScheme("package"); registerReceiver(mPackageChangeReceiver, iff); mPackageChangeReceiverRegistered = true; // Up navigation getActionBar().setDisplayHomeAsUpEnabled(true); // Tutorial if (!PrivacyManager.getSettingBool(userId, PrivacyManager.cSettingTutorialDetails, false)) { ((ScrollView) findViewById(R.id.svTutorialHeader)).setVisibility(View.VISIBLE); ((ScrollView) findViewById(R.id.svTutorialDetails)).setVisibility(View.VISIBLE); } View.OnClickListener listener = new View.OnClickListener() { @Override public void onClick(View view) { ViewParent parent = view.getParent(); while (!parent.getClass().equals(ScrollView.class)) parent = parent.getParent(); ((View) parent).setVisibility(View.GONE); PrivacyManager.setSetting(userId, PrivacyManager.cSettingTutorialDetails, Boolean.TRUE.toString()); } }; ((Button) findViewById(R.id.btnTutorialHeader)).setOnClickListener(listener); ((Button) findViewById(R.id.btnTutorialDetails)).setOnClickListener(listener); // Process actions if (extras.containsKey(cAction)) { NotificationManager notificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); notificationManager.cancel(mAppInfo.getUid()); if (extras.getInt(cAction) == cActionClear) optionClear(); else if (extras.getInt(cAction) == cActionSettings) optionSettings(); } }
From source file:com.android.launcher3.Utilities.java
public static void answerToRestoreIconPack(final Activity context, String packName) { AlertDialog.Builder alert = new AlertDialog.Builder( new ContextThemeWrapper(context, R.style.AlertDialogCustom)); alert.setTitle(context.getResources().getString(R.string.app_name)); alert.setMessage(context.getResources().getString(R.string.ask_icon) + " " + packName + "?"); alert.setPositiveButton(context.getResources().getString(R.string.ok), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { applyChange(context); }/*w w w . j a v a2 s . c o m*/ }); alert.setNegativeButton(context.getResources().getString(R.string.cancel), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { Utilities.setAppIconPackageNamePrefEnabled(context.getApplicationContext(), "NULL"); dialog.dismiss(); } }); alert.setIcon(R.mipmap.ic_launcher_home); alert.show(); }
From source file:org.nla.tarotdroid.lib.ui.GameSetHistoryActivity.java
@Override public boolean onCreateOptionsMenu(com.actionbarsherlock.view.Menu menu) { SubMenu subMenuBlueTooth = menu.addSubMenu(this.getString(R.string.lblBluetoothItem)); com.actionbarsherlock.view.MenuItem miBluetooth = subMenuBlueTooth.getItem(); miBluetooth.setIcon(R.drawable.stat_sys_data_bluetooth); miBluetooth.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER); com.actionbarsherlock.view.MenuItem miBlueToothDiscover = subMenuBlueTooth .add(R.string.lblBluetoothDiscover).setIcon(R.drawable.ic_menu_allfriends); com.actionbarsherlock.view.MenuItem miBlueToothGetDiscoverable = subMenuBlueTooth .add(R.string.lblBluetoothGetDiscoverable).setIcon(android.R.drawable.ic_menu_myplaces); com.actionbarsherlock.view.MenuItem miBlueToothReceive = subMenuBlueTooth.add(R.string.lblBluetoothReceive) .setIcon(R.drawable.ic_menu_download); com.actionbarsherlock.view.MenuItem miBlueToothHelp = subMenuBlueTooth.add(R.string.lblBluetoothHelp) .setIcon(android.R.drawable.ic_menu_info_details); miBlueToothDiscover.setOnMenuItemClickListener(new OnMenuItemClickListener() { @Override//from www . jav a 2s .c om public boolean onMenuItemClick(com.actionbarsherlock.view.MenuItem item) { if (isBluetoothActivated()) { GameSetHistoryActivity.this.bluetoothHelper.startDiscovery(); AuditHelper.auditEvent(AuditHelper.EventTypes.actionBluetoothDiscoverDevices); } return true; } }); miBlueToothGetDiscoverable.setOnMenuItemClickListener(new OnMenuItemClickListener() { @Override public boolean onMenuItemClick(com.actionbarsherlock.view.MenuItem item) { if (isBluetoothActivated()) { GameSetHistoryActivity.this.bluetoothHelper.setBluetoothDeviceDiscoverable(); AuditHelper.auditEvent(AuditHelper.EventTypes.actionBluetoothSetDiscoverable); } return true; } }); miBlueToothReceive.setOnMenuItemClickListener(new OnMenuItemClickListener() { @Override public boolean onMenuItemClick(com.actionbarsherlock.view.MenuItem item) { if (isBluetoothActivated()) { // retrieve game count int gameSetCount; try { gameSetCount = AppContext.getApplication().getDalService().getGameSetCount(); } catch (DalException de) { gameSetCount = 0; } // prevent user from downloading if game set count > 5 and // limited version if (AppContext.getApplication().isAppLimited() && gameSetCount >= 5) { Toast.makeText(GameSetHistoryActivity.this, AppContext.getApplication().getResources() .getString(R.string.msgLimitedVersionInformation), Toast.LENGTH_SHORT).show(); } // ok for download else { try { GameSetHistoryActivity.this.receiveGameSetTask = new ReceiveGameSetTask( GameSetHistoryActivity.this, GameSetHistoryActivity.this.progressDialog, GameSetHistoryActivity.this.bluetoothHelper.getBluetoothAdapter()); GameSetHistoryActivity.this.receiveGameSetTask.setCallback(refreshCallback); GameSetHistoryActivity.this.receiveGameSetTask.execute(); AuditHelper.auditEvent(AuditHelper.EventTypes.actionBluetoothReceiveGameSet); } catch (IOException ioe) { Log.v(AppContext.getApplication().getAppLogTag(), "TarotDroid Exception in " + this.getClass().toString(), ioe); Toast.makeText(GameSetHistoryActivity.this, AppContext.getApplication().getResources() .getString(R.string.msgBluetoothError, ioe), Toast.LENGTH_SHORT).show(); } } } return true; } }); miBlueToothHelp.setOnMenuItemClickListener(new OnMenuItemClickListener() { @Override public boolean onMenuItemClick(com.actionbarsherlock.view.MenuItem item) { UIHelper.showSimpleRichTextDialog(GameSetHistoryActivity.this, AppContext.getApplication().getResources().getText(R.string.msgHelpBluetooth).toString(), AppContext.getApplication().getResources().getString(R.string.titleHelpBluetooth)); return true; } }); // TODO Improve Massive excel export // if (!AppContext.getApplication().isAppLimited()) { // com.actionbarsherlock.view.MenuItem miGlobalExport = // menu.add(this.getString(R.string.lblExcelExport)).setIcon(R.drawable.ic_excel); // miGlobalExport.setShowAsAction(com.actionbarsherlock.view.MenuItem.SHOW_AS_ACTION_NEVER); // //miGlobalExport.setIcon(R.drawable.ic_excel); // // miGlobalExport.setOnMenuItemClickListener(new // OnMenuItemClickListener() { // @Override // public boolean onMenuItemClick(com.actionbarsherlock.view.MenuItem // item) { // ExportToExcelTask task = new // ExportToExcelTask(GameSetHistoryActivity.this, progressDialog); // task.execute(); // return true; // } // }); // } com.actionbarsherlock.view.MenuItem miBin = menu.add(this.getString(R.string.lblInitDalItem)); miBin.setShowAsAction(com.actionbarsherlock.view.MenuItem.SHOW_AS_ACTION_NEVER); miBin.setIcon(R.drawable.gd_action_bar_trashcan); miBin.setOnMenuItemClickListener(new OnMenuItemClickListener() { @Override public boolean onMenuItemClick(com.actionbarsherlock.view.MenuItem item) { AlertDialog.Builder builder = new AlertDialog.Builder(GameSetHistoryActivity.this); builder.setTitle(GameSetHistoryActivity.this.getString(R.string.titleReinitDalYesNo)); builder.setMessage( Html.fromHtml(GameSetHistoryActivity.this.getText(R.string.msgReinitDalYesNo).toString())); builder.setPositiveButton(GameSetHistoryActivity.this.getString(R.string.btnOk), GameSetHistoryActivity.this.removeAllGameSetsDialogClickListener); builder.setNegativeButton(GameSetHistoryActivity.this.getString(R.string.btnCancel), GameSetHistoryActivity.this.removeAllGameSetsDialogClickListener).show(); builder.setIcon(android.R.drawable.ic_dialog_alert); return true; } }); return true; }
From source file:jmri.enginedriver.threaded_application.java
public void checkExit(final Activity activity) { final AlertDialog.Builder b = new AlertDialog.Builder(activity); b.setIcon(android.R.drawable.ic_dialog_alert); b.setTitle(R.string.exit_title);//from w w w . j a v a 2 s . co m b.setMessage(R.string.exit_text); b.setCancelable(true); b.setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { firstCreate = true; sendMsg(comm_msg_handler, message_type.DISCONNECT, ""); //trigger disconnect / shutdown sequence } }); b.setNegativeButton(R.string.no, null); AlertDialog alert = b.create(); alert.show(); }