List of usage examples for android.app AlertDialog setTitle
@Override public void setTitle(CharSequence title)
From source file:info.zamojski.soft.towercollector.MainActivity.java
private void displayUploadResultDialog(Bundle extras) { int descriptionId = extras.getInt(UploaderService.INTENT_KEY_RESULT_DESCRIPTION); try {/*w w w .j a v a 2s. c om*/ String descriptionContent = getString(descriptionId); Log.d("displayUploadResultDialog(): Received extras: %s", descriptionId); // display dialog AlertDialog alertDialog = new AlertDialog.Builder(this).create(); alertDialog.setCanceledOnTouchOutside(true); alertDialog.setCancelable(true); alertDialog.setTitle(R.string.uploader_result_dialog_title); alertDialog.setMessage(descriptionContent); alertDialog.setButton(DialogInterface.BUTTON_POSITIVE, getString(R.string.dialog_ok), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { } }); alertDialog.show(); } catch (NotFoundException ex) { Log.w("displayUploadResultDialog(): Invalid string id received with intent extras: %s", descriptionId); MyApplication.getAnalytics().sendException(ex, Boolean.FALSE); ACRA.getErrorReporter().handleSilentException(ex); } }
From source file:org.mixare.MixViewActivity.java
@TargetApi(Build.VERSION_CODES.KITKAT) @Override//from w ww. jav a2 s . c o m public void selectItem(int position) { int menuItemId = getResources().obtainTypedArray(R.array.menu_item_titles).getResourceId(position, -1); switch (menuItemId) { /* Data sources */ case R.string.menu_item_datasources: if (!getMarkerRenderer().getIsLauncherStarted()) { Intent intent = new Intent(MixViewActivity.this, DataSourceList.class); startActivityForResult(intent, Config.INTENT_REQUEST_CODE_DATASOURCES); } else { markerRenderer.getContext().getNotificationManager() .addNotification(getString(R.string.no_website_available)); } break; /* Plugin View */ case R.string.menu_item_plugins: if (!getMarkerRenderer().getIsLauncherStarted()) { Intent intent = new Intent(MixViewActivity.this, PluginListActivity.class); startActivityForResult(intent, Config.INTENT_REQUEST_CODE_PLUGINS); } else { markerRenderer.getContext().getNotificationManager() .addNotification(getString(R.string.no_website_available)); } break; /* List markerRenderer */ case R.string.menu_item_list: /* * if the list of titles to show in alternative list markerRenderer is not * empty */ if (getMarkerRenderer().getDataHandler().getMarkerCount() > 0) { Intent intent1 = new Intent(MixViewActivity.this, MarkerListActivity.class); intent1.setAction(Intent.ACTION_VIEW); startActivityForResult(intent1, Config.INTENT_REQUEST_CODE_MARKERLIST); } /* if the list is empty */ else { markerRenderer.getContext().getNotificationManager() .addNotification(getString(R.string.empty_list)); } break; /* Map View */ case R.string.menu_item_map: Intent intent2 = new Intent(MixViewActivity.this, MixMap.class); startActivityForResult(intent2, Config.INTENT_REQUEST_CODE_MAP); break; /* range level */ case R.string.menu_item_range: hudView.showRangeBar(); drawerLayout.closeDrawer(drawerList); break; /* Search */ case R.string.menu_item_search: onSearchRequested(); break; /* GPS Information */ case R.string.menu_item_info: Location currentGPSInfo = MixContext.getInstance().getLocationFinder().getCurrentLocation(); AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setMessage(getString(R.string.general_info_text) + "\n\n" + getString(R.string.longitude) + currentGPSInfo.getLongitude() + "\n" + getString(R.string.latitude) + currentGPSInfo.getLatitude() + "\n" + getString(R.string.altitude) + currentGPSInfo.getAltitude() + "m\n" + getString(R.string.speed) + currentGPSInfo.getSpeed() + "km/h\n" + getString(R.string.accuracy) + currentGPSInfo.getAccuracy() + "m\n" + getString(R.string.gps_last_fix) + new Date(currentGPSInfo.getTime()).toString() + "\n"); builder.setNegativeButton(getString(R.string.close_button), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.dismiss(); } }); AlertDialog alert = builder.create(); alert.setTitle(getString(R.string.general_info_title)); alert.show(); break; /* license agreement */ case R.string.menu_item_license: AlertDialog.Builder builder1 = new AlertDialog.Builder(this); builder1.setMessage(getString(R.string.license)); /* Retry */ builder1.setNegativeButton(getString(R.string.close_button), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.dismiss(); } }); AlertDialog alert1 = builder1.create(); alert1.setTitle(getString(R.string.license_title)); alert1.show(); break; case R.string.menu_item_test_augmentedview: Location curLocation = MixViewDataHolder.getInstance().getCurLocation(); Log.d(Config.TAG, "info 1: aktuelle Postition: " + curLocation.getLongitude() + ", " + curLocation.getLatitude()); if (!cubeView.isAttachedToWindow()) { cameraView.addView(cubeView, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)); } else { cameraView.removeView(cubeView); } break; /* test destination selection (from marker) */ case R.string.menu_item_route: new MarkerListFragment().show(getFragmentManager(), "TAG"); break; /* some random error (for testing?!)*/ default: doError(null, new Random().nextInt(3)); break; } }
From source file:info.zamojski.soft.towercollector.MainActivity.java
private void displayNewVersionDownloadOptions(Bundle extras) { UpdateInfo updateInfo = (UpdateInfo) extras.getSerializable(UpdateCheckAsyncTask.INTENT_KEY_UPDATE_INFO); // display dialog AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this); LayoutInflater inflater = LayoutInflater.from(this); View dialogLayout = inflater.inflate(R.layout.new_version, null); dialogBuilder.setView(dialogLayout); final AlertDialog alertDialog = dialogBuilder.create(); alertDialog.setCanceledOnTouchOutside(true); alertDialog.setCancelable(true);/*from w w w. j av a 2 s. c om*/ alertDialog.setTitle(R.string.updater_dialog_new_version_available); // load data ArrayAdapter<UpdateInfo.DownloadLink> adapter = new UpdateDialogArrayAdapter(alertDialog.getContext(), inflater, updateInfo.getDownloadLinks()); ListView listView = (ListView) dialogLayout.findViewById(R.id.download_options_list); listView.setAdapter(adapter); // bind events final CheckBox disableAutoUpdateCheckCheckbox = (CheckBox) dialogLayout .findViewById(R.id.download_options_disable_auto_update_check_checkbox); listView.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { DownloadLink downloadLink = (DownloadLink) parent.getItemAtPosition(position); Log.d("displayNewVersionDownloadOptions(): Selected position: %s", downloadLink.getLabel()); boolean disableAutoUpdateCheckCheckboxChecked = disableAutoUpdateCheckCheckbox.isChecked(); Log.d("displayNewVersionDownloadOptions(): Disable update check checkbox checked = %s", disableAutoUpdateCheckCheckboxChecked); if (disableAutoUpdateCheckCheckboxChecked) { MyApplication.getPreferencesProvider().setUpdateCheckEnabled(false); } MyApplication.getAnalytics().sendUpdateAction(downloadLink.getLabel()); String link = downloadLink.getLink(); try { startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(link))); } catch (ActivityNotFoundException ex) { Toast.makeText(getApplication(), R.string.web_browser_missing, Toast.LENGTH_LONG).show(); } alertDialog.dismiss(); } }); alertDialog.setButton(DialogInterface.BUTTON_POSITIVE, getString(R.string.dialog_cancel), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { boolean disableAutoUpdateCheckCheckboxChecked = disableAutoUpdateCheckCheckbox.isChecked(); Log.d("displayNewVersionDownloadOptions(): Disable update check checkbox checked = %s", disableAutoUpdateCheckCheckboxChecked); if (disableAutoUpdateCheckCheckboxChecked) { MyApplication.getPreferencesProvider().setUpdateCheckEnabled(false); } } }); alertDialog.show(); }
From source file:com.awrtechnologies.carbudgetsales.MainActivity.java
/** * Function to display simple Alert Dialog * * @param context - application context/*from ww w . j a v a 2 s . c o m*/ * @param title - alert dialog title * @param message - alert message * @param status - success/failure (used to set icon) */ public void showAlertDialog(Context context, String title, String message, Boolean status) { AlertDialog alertDialog = new AlertDialog.Builder(context).create(); // Setting Dialog Title alertDialog.setTitle(title); // Setting Dialog Message alertDialog.setMessage(message); // Setting alert dialog icon alertDialog.setIcon((status) ? R.drawable.transparentlogo : R.drawable.transparentlogo); // Setting OK Button alertDialog.setButton("OK", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { MainActivity.this.finish(); dialog.dismiss(); } }); // Showing Alert Message alertDialog.show(); }
From source file:foam.littlej.android.app.ui.phone.AddReportActivity.java
/** * Create various dialog/*from ww w .j a v a 2 s. c o m*/ */ @Override protected Dialog onCreateDialog(int id) { switch (id) { case DIALOG_ERROR_NETWORK: { AlertDialog dialog = (new AlertDialog.Builder(this)).create(); dialog.setTitle(getString(R.string.network_error)); dialog.setMessage(getString(R.string.network_error_msg)); dialog.setButton2(getString(R.string.ok), new Dialog.OnClickListener() { public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); dialog.setCancelable(false); return dialog; } case DIALOG_ERROR_SAVING: { AlertDialog dialog = (new AlertDialog.Builder(this)).create(); dialog.setTitle(getString(R.string.network_error)); dialog.setMessage(getString(R.string.file_system_error_msg)); dialog.setButton2(getString(R.string.ok), new Dialog.OnClickListener() { public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); dialog.setCancelable(false); return dialog; } case DIALOG_CHOOSE_IMAGE_METHOD: { AlertDialog dialog = (new AlertDialog.Builder(this)).create(); dialog.setTitle(getString(R.string.choose_method)); dialog.setMessage(getString(R.string.how_to_select_pic)); dialog.setButton(getString(R.string.gallery_option), new Dialog.OnClickListener() { public void onClick(DialogInterface dialog, int which) { Intent intent = new Intent(); intent.setAction(Intent.ACTION_PICK); intent.setData(MediaStore.Images.Media.EXTERNAL_CONTENT_URI); startActivityForResult(intent, REQUEST_CODE_IMAGE); dialog.dismiss(); } }); dialog.setButton2(getString(R.string.cancel), new Dialog.OnClickListener() { public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); dialog.setButton3(getString(R.string.camera_option), new Dialog.OnClickListener() { public void onClick(DialogInterface dialog, int which) { Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); intent.putExtra(MediaStore.EXTRA_OUTPUT, PhotoUtils.getPhotoUri(photoName, AddReportActivity.this)); startActivityForResult(intent, REQUEST_CODE_CAMERA); dialog.dismiss(); } }); dialog.setCancelable(false); return dialog; } case DIALOG_MULTIPLE_CATEGORY: { if (showCategories() != null) { return new AlertDialog.Builder(this).setTitle(R.string.choose_categories) .setMultiChoiceItems(showCategories(), setCheckedCategories(), new DialogInterface.OnMultiChoiceClickListener() { public void onClick(DialogInterface dialog, int whichButton, boolean isChecked) { // see if categories have previously if (isChecked) { mVectorCategories.add(mCategoriesId.get(whichButton)); mError = false; } else { mVectorCategories.remove(mCategoriesId.get(whichButton)); } setSelectedCategories(mVectorCategories); } }) .setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { /* User clicked Yes so do some stuff */ } }).create(); } } case TIME_DIALOG_ID: return new TimePickerDialog(this, mTimeSetListener, mCalendar.get(Calendar.HOUR), mCalendar.get(Calendar.MINUTE), false); case DATE_DIALOG_ID: return new DatePickerDialog(this, mDateSetListener, mCalendar.get(Calendar.YEAR), mCalendar.get(Calendar.MONTH), mCalendar.get(Calendar.DAY_OF_MONTH)); case DIALOG_SHOW_MESSAGE: AlertDialog.Builder messageBuilder = new AlertDialog.Builder(this); messageBuilder.setMessage(mErrorMessage).setPositiveButton(getString(R.string.ok), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.cancel(); } }); AlertDialog showDialog = messageBuilder.create(); showDialog.show(); break; case DIALOG_SHOW_REQUIRED: AlertDialog.Builder requiredBuilder = new AlertDialog.Builder(this); requiredBuilder.setTitle(R.string.required_fields); requiredBuilder.setMessage(mErrorMessage).setPositiveButton(getString(R.string.ok), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.cancel(); } }); AlertDialog showRequiredDialog = requiredBuilder.create(); showRequiredDialog.show(); break; // prompt for unsaved changes case DIALOG_SHOW_PROMPT: { AlertDialog dialog = (new AlertDialog.Builder(this)).create(); dialog.setTitle(getString(R.string.unsaved_changes)); dialog.setMessage(getString(R.string.want_to_cancel)); dialog.setButton(getString(R.string.no), new Dialog.OnClickListener() { public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); dialog.setButton2(getString(R.string.yes), new Dialog.OnClickListener() { public void onClick(DialogInterface dialog, int which) { new DiscardTask(AddReportActivity.this).execute((String) null); finish(); dialog.dismiss(); } }); dialog.setCancelable(false); return dialog; } // prompt for report deletion case DIALOG_SHOW_DELETE_PROMPT: { AlertDialog dialog = (new AlertDialog.Builder(this)).create(); dialog.setTitle(getString(R.string.delete_report)); dialog.setMessage(getString(R.string.want_to_delete)); dialog.setButton(getString(R.string.no), new Dialog.OnClickListener() { public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); dialog.setButton2(getString(R.string.yes), new Dialog.OnClickListener() { public void onClick(DialogInterface dialog, int which) { // delete report deleteReport(); dialog.dismiss(); } }); dialog.setCancelable(false); return dialog; } } return null; }
From source file:info.zamojski.soft.towercollector.MainActivity.java
private void displayNotCompatibleDialog() { // check if displayed in this app run if (showNotCompatibleDialog) { // check if not disabled in preferences boolean showCompatibilityWarningEnabled = MyApplication.getPreferencesProvider() .getShowCompatibilityWarning(); if (showCompatibilityWarningEnabled) { TelephonyManager telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE); // check if device contains telephony hardware (some tablets doesn't report even if have) // NOTE: in the future this may need to be expanded when new specific features appear PackageManager packageManager = getPackageManager(); boolean noRadioDetected = !(packageManager.hasSystemFeature(PackageManager.FEATURE_TELEPHONY) && (packageManager.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_GSM) || packageManager.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_CDMA))); // show dialog if something is not supported if (noRadioDetected) { Log.d("displayNotCompatibleDialog(): Not compatible because of radio: %s, phone type: %s", noRadioDetected, telephonyManager.getPhoneType()); //use custom layout to show "don't show this again" checkbox AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this); LayoutInflater inflater = LayoutInflater.from(this); View dialogLayout = inflater.inflate(R.layout.dont_show_again_dialog, null); final CheckBox dontShowAgainCheckbox = (CheckBox) dialogLayout .findViewById(R.id.dont_show_again_dialog_checkbox); dialogBuilder.setView(dialogLayout); AlertDialog alertDialog = dialogBuilder.create(); alertDialog.setCanceledOnTouchOutside(true); alertDialog.setCancelable(true); alertDialog.setTitle(R.string.main_dialog_not_compatible_title); StringBuilder stringBuilder = new StringBuilder( getString(R.string.main_dialog_not_compatible_begin)); if (noRadioDetected) { stringBuilder.append(getString(R.string.main_dialog_no_compatible_mobile_radio_message)); }/*from w w w .j a va 2s .com*/ // text set this way to prevent checkbox from disappearing when text is too long TextView messageTextView = (TextView) dialogLayout .findViewById(R.id.dont_show_again_dialog_textview); messageTextView.setText(stringBuilder.toString()); alertDialog.setButton(DialogInterface.BUTTON_POSITIVE, getString(R.string.dialog_ok), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { boolean dontShowAgainCheckboxChecked = dontShowAgainCheckbox.isChecked(); Log.d("displayNotCompatibleDialog(): Don't show again checkbox checked = %s", dontShowAgainCheckboxChecked); if (dontShowAgainCheckboxChecked) { MyApplication.getPreferencesProvider().setShowCompatibilityWarning(false); } } }); alertDialog.show(); } } showNotCompatibleDialog = false; } }
From source file:com.xperia64.rompatcher.MainActivity.java
private void patchCheck() { // Just try to interpret the following if statement. I dare you. if (new File(Globals.fileToPatch + ".bak").exists() || (Globals.fileToPatch.toLowerCase(Locale.US).endsWith(".ecm") && new File( Globals.fileToPatch.substring(0, Globals.fileToPatch.lastIndexOf('.'))).exists()) || new File(Globals.fileToPatch + ".new").exists() || (new File(Globals.fileToPatch.substring(0, Globals.fileToPatch.lastIndexOf('/') + 1) + ed.getText().toString() + ((e.isChecked())//from w w w. j a v a2 s .c o m ? ((Globals.fileToPatch.lastIndexOf('.') > -1) ? Globals.fileToPatch.substring( Globals.fileToPatch.lastIndexOf('.'), Globals.fileToPatch.length()) : "") : "")).exists() && d.isChecked() && c.isChecked())) { System.out.println("bad"); AlertDialog dialog2 = new AlertDialog.Builder(staticThis).create(); dialog2.setTitle(getResources().getString(R.string.warning)); dialog2.setMessage(getResources().getString(R.string.warning_desc)); dialog2.setCancelable(false); dialog2.setButton(DialogInterface.BUTTON_POSITIVE, getResources().getString(android.R.string.yes), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int buttonId) { new File(Globals.fileToPatch + ".bak").delete(); new File(Globals.fileToPatch + ".new").delete(); if (Globals.fileToPatch.toLowerCase(Locale.US).endsWith(".ecm")) new File(Globals.fileToPatch.substring(0, Globals.fileToPatch.lastIndexOf('.'))) .delete(); new File(Globals.fileToPatch.substring(0, Globals.fileToPatch.lastIndexOf('/') + 1) + ed.getText().toString() + ((e.isChecked()) ? ((Globals.fileToPatch.lastIndexOf('.') > -1) ? Globals.fileToPatch.substring(Globals.fileToPatch.lastIndexOf('.'), Globals.fileToPatch.length()) : "") : "")).delete(); if (d.isChecked() && c.isChecked() && e.isChecked() && Globals.fileToPatch.lastIndexOf('.') > -1) { ed.setText(ed.getText() + Globals.fileToPatch.substring( Globals.fileToPatch.lastIndexOf('.'), Globals.fileToPatch.length())); } patch(c.isChecked(), d.isChecked(), r.isChecked(), ed.getText().toString()); } }); dialog2.setButton(DialogInterface.BUTTON_NEGATIVE, getResources().getString(android.R.string.cancel), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int buttonId) { Toast t = Toast.makeText(staticThis, getResources().getString(R.string.nopatch), Toast.LENGTH_SHORT); t.show(); } }); dialog2.show(); } else { if (d.isChecked() && c.isChecked() && e.isChecked() && Globals.fileToPatch.lastIndexOf('.') > -1) { ed.setText(ed.getText() + Globals.fileToPatch.substring(Globals.fileToPatch.lastIndexOf('.'), Globals.fileToPatch.length())); } patch(c.isChecked(), d.isChecked(), r.isChecked(), ed.getText().toString()); } }
From source file:info.zamojski.soft.towercollector.MainActivity.java
private void startUploaderServiceWithCheck() { String runningTaskClassName = MyApplication.getBackgroundTaskName(); if (runningTaskClassName != null) { Log.d("startUploaderService(): Another task is running in background: %s", runningTaskClassName); backgroundTaskHelper.showTaskRunningMessage(runningTaskClassName); return;/* ww w .jav a2s.c o m*/ } // check API key String apiKey = MyApplication.getPreferencesProvider().getApiKey(); if (!Validator.isOpenCellIdApiKeyValid(apiKey)) { final String apiKeyLocal = apiKey; AlertDialog alertDialog = new AlertDialog.Builder(this).create(); alertDialog.setCanceledOnTouchOutside(true); alertDialog.setCancelable(true); if (StringUtils.isNullEmptyOrWhitespace(apiKey)) { alertDialog.setTitle(R.string.main_dialog_api_key_empty_title); alertDialog.setMessage(getString(R.string.main_dialog_api_key_empty_message)); alertDialog.setButton(DialogInterface.BUTTON_POSITIVE, getString(R.string.dialog_register), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { try { Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(getString(R.string.preferences_opencellid_org_sign_up_link))); startActivity(browserIntent); } catch (ActivityNotFoundException ex) { Toast.makeText(getApplication(), R.string.web_browser_missing, Toast.LENGTH_LONG).show(); } } }); } else { alertDialog.setTitle(R.string.main_dialog_api_key_invalid_title); alertDialog.setMessage(getString(R.string.main_dialog_api_key_invalid_message)); alertDialog.setButton(DialogInterface.BUTTON_POSITIVE, getString(R.string.dialog_upload), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { startUploaderService(apiKeyLocal); } }); } alertDialog.setButton(DialogInterface.BUTTON_NEUTRAL, getString(R.string.dialog_enter_api_key), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { startPreferencesActivity(); } }); alertDialog.setButton(DialogInterface.BUTTON_NEGATIVE, getString(R.string.dialog_cancel), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { } }); alertDialog.show(); return; } else { startUploaderService(apiKey); } }
From source file:com.xperia64.timidityae.PlayerFragment.java
@SuppressLint("InflateParams") public void showMidiDialog() { AlertDialog.Builder b = new AlertDialog.Builder(getActivity()); View v = getActivity().getLayoutInflater().inflate(R.layout.midi_options, null); Button speedUp = (Button) v.findViewById(R.id.speedUp); Button slowDown = (Button) v.findViewById(R.id.slowDown); Button keyUp = (Button) v.findViewById(R.id.keyUp); Button keyDown = (Button) v.findViewById(R.id.keyDown); Button vplus = (Button) v.findViewById(R.id.vplus); Button vminus = (Button) v.findViewById(R.id.vminus); Button export = (Button) v.findViewById(R.id.exportButton); Button saveCfg = (Button) v.findViewById(R.id.saveCfg); Button loadCfg = (Button) v.findViewById(R.id.loadCfg); Button savedefCfg = (Button) v.findViewById(R.id.savedefCfg); final Button deldefCfg = (Button) v.findViewById(R.id.deldefCfg); deldefCfg.setEnabled(new File(mActivity.currSongName + ".def.tcf").exists() || new File(mActivity.currSongName + ".def.tzf").exists()); tempo = (TextView) v.findViewById(R.id.tempoText); pitch = (TextView) v.findViewById(R.id.pitchText); voices = (TextView) v.findViewById(R.id.voiceText); tempo.setText(String.format(getResources().getString(R.string.mop_tempo), JNIHandler.ttr, (int) (500000 / (double) JNIHandler.tt * 120 * (double) JNIHandler.ttr / 100 + 0.5))); pitch.setText(String.format(getResources().getString(R.string.mop_pitch), ((JNIHandler.koffset > 0) ? "+" : "") + Integer.toString(JNIHandler.koffset))); voices.setText(/*from w ww .java2 s . com*/ String.format(getResources().getString(R.string.mop_voice), JNIHandler.voice, JNIHandler.maxvoice)); speedUp.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { JNIHandler.controlTimidity(17, 1); JNIHandler.waitUntilReady(); JNIHandler.tb++; } }); slowDown.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { JNIHandler.controlTimidity(18, 1); JNIHandler.waitUntilReady(); JNIHandler.tb--; } }); keyUp.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { JNIHandler.controlTimidity(15, 1); JNIHandler.waitUntilReady(); } }); keyDown.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { JNIHandler.controlTimidity(16, -1); JNIHandler.waitUntilReady(); } }); vplus.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { JNIHandler.controlTimidity(19, 5); JNIHandler.waitUntilReady(); } }); vminus.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { JNIHandler.controlTimidity(20, 5); JNIHandler.waitUntilReady(); } }); export.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { mActivity.dynExport(); } }); saveCfg.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { mActivity.saveCfg(); } }); loadCfg.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { mActivity.loadCfg(); } }); savedefCfg.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { String value1; String value2; boolean alreadyExists = (new File(mActivity.currSongName + ".def.tcf").exists() || new File(mActivity.currSongName + ".def.tzf").exists()); boolean aWrite = true; String needRename1 = null; String needRename2 = null; String probablyTheRoot = ""; String probablyTheDirectory = ""; try { if (Globals.compressCfg) new FileOutputStream(mActivity.currSongName + ".def.tzf", true).close(); else new FileOutputStream(mActivity.currSongName + ".def.tcf", true).close(); } catch (FileNotFoundException e) { aWrite = false; } catch (IOException e) { e.printStackTrace(); } final boolean canWrite = aWrite; if (!alreadyExists && canWrite) { new File(mActivity.currSongName + ".def.tcf").delete(); new File(mActivity.currSongName + ".def.tzf").delete(); } if (canWrite && new File(mActivity.currSongName).canWrite()) { value1 = mActivity.currSongName + (Globals.compressCfg ? ".def.tzf" : ".def.tcf"); value2 = mActivity.currSongName + (Globals.compressCfg ? ".def.tcf" : ".def.tzf"); } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && Globals.theFold != null) { //TODO // Write the file to getExternalFilesDir, then move it with the Uri // We need to tell JNIHandler that movement is needed. // This is pretty much done now? String[] tmp = Globals.getDocFilePaths(getActivity(), mActivity.currSongName); probablyTheDirectory = tmp[0]; probablyTheRoot = tmp[1]; if (probablyTheDirectory.length() > 1) { needRename1 = (mActivity.currSongName).substring( mActivity.currSongName.indexOf(probablyTheRoot) + probablyTheRoot.length()) + (Globals.compressCfg ? ".def.tzf" : ".def.tcf"); needRename2 = (mActivity.currSongName).substring( mActivity.currSongName.indexOf(probablyTheRoot) + probablyTheRoot.length()) + (Globals.compressCfg ? ".def.tcf" : ".def.tzf"); value1 = probablyTheDirectory + mActivity.currSongName.substring(mActivity.currSongName.lastIndexOf('/')) + (Globals.compressCfg ? ".def.tzf" : ".def.tcf"); value2 = probablyTheDirectory + mActivity.currSongName.substring(mActivity.currSongName.lastIndexOf('/')) + (Globals.compressCfg ? ".def.tcf" : ".def.tzf"); } else { Toast.makeText(getActivity(), "Could not write config file. Did you give Timidity write access to the root of your external sd card?", Toast.LENGTH_SHORT).show(); return; } } else { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { Toast.makeText(getActivity(), "Could not write config file. Did you give Timidity write access to the root of your external sd card?", Toast.LENGTH_SHORT).show(); } else { Toast.makeText(getActivity(), "Could not write config file. Permission denied.", Toast.LENGTH_SHORT).show(); } return; } final String finalval1 = value1; final String finalval2 = value2; final String needToRename1 = needRename1; final String needToRename2 = needRename2; final String probRoot = probablyTheRoot; if (alreadyExists) { AlertDialog dialog = new AlertDialog.Builder(mActivity).create(); dialog.setTitle("Warning"); dialog.setMessage("Overwrite default config file?"); dialog.setCancelable(false); dialog.setButton(DialogInterface.BUTTON_POSITIVE, getResources().getString(android.R.string.yes), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int buttonId) { if (!canWrite && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { if (needToRename1 != null) { Globals.tryToDeleteFile(getActivity(), probRoot + needToRename1); Globals.tryToDeleteFile(getActivity(), finalval1); Globals.tryToDeleteFile(getActivity(), probRoot + needToRename2); Globals.tryToDeleteFile(getActivity(), finalval2); } else { Globals.tryToDeleteFile(getActivity(), finalval1); Globals.tryToDeleteFile(getActivity(), finalval2); } } else { new File(mActivity.currSongName + ".def.tcf").delete(); new File(mActivity.currSongName + ".def.tzf").delete(); } mActivity.localfinished = false; mActivity.saveCfgPart2(finalval1, needToRename1); deldefCfg.setEnabled(true); /*Intent new_intent = new Intent(); new_intent.setAction(getResources().getString(R.string.msrv_rec)); new_intent.putExtra(getResources().getString(R.string.msrv_cmd), 16); new_intent.putExtra(getResources().getString(R.string.msrv_outfile), mActivity.currSongName+".def.tcf"); getActivity().sendBroadcast(new_intent); deldefCfg.setEnabled(true);*/ } }); dialog.setButton(DialogInterface.BUTTON_NEGATIVE, getResources().getString(android.R.string.no), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int buttonId) { } }); dialog.show(); } else { /*Intent new_intent = new Intent(); new_intent.setAction(getResources().getString(R.string.msrv_rec)); new_intent.putExtra(getResources().getString(R.string.msrv_cmd), 16); new_intent.putExtra(getResources().getString(R.string.msrv_outfile), mActivity.currSongName+".def.tcf"); getActivity().sendBroadcast(new_intent); deldefCfg.setEnabled(true);*/ mActivity.localfinished = false; mActivity.saveCfgPart2(finalval1, needToRename1); deldefCfg.setEnabled(true); } } }); deldefCfg.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { if (new File(mActivity.currSongName + ".def.tcf").exists() || new File(mActivity.currSongName + ".def.tzf").exists()) { boolean aWrite = true; try { if (Globals.compressCfg) new FileOutputStream(mActivity.currSongName + ".def.tzf", true).close(); else new FileOutputStream(mActivity.currSongName + ".def.tcf", true).close(); } catch (FileNotFoundException e) { aWrite = false; } catch (IOException e) { e.printStackTrace(); } final boolean canWrite = aWrite; AlertDialog dialog = new AlertDialog.Builder(mActivity).create(); dialog.setTitle("Warning"); dialog.setMessage("Really delete default config file?"); dialog.setCancelable(false); dialog.setButton(DialogInterface.BUTTON_POSITIVE, getResources().getString(android.R.string.yes), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int buttonId) { if (!canWrite && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { Globals.tryToDeleteFile(getActivity(), mActivity.currSongName + ".def.tzf"); Globals.tryToDeleteFile(getActivity(), mActivity.currSongName + ".def.tcf"); } else { new File(mActivity.currSongName + ".def.tcf").delete(); new File(mActivity.currSongName + ".def.tzf").delete(); } deldefCfg.setEnabled(false); } }); dialog.setButton(DialogInterface.BUTTON_NEGATIVE, getResources().getString(android.R.string.no), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int buttonId) { } }); dialog.show(); } } }); final Spinner x = (Spinner) v.findViewById(R.id.resampSpinner); List<String> arrayAdapter = new ArrayList<String>(); for (String yyy : Globals.sampls) arrayAdapter.add(yyy); ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(getActivity(), android.R.layout.simple_spinner_item, arrayAdapter); dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); x.setAdapter(dataAdapter); firstSelection = true; x.setOnItemSelectedListener(new OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> arg0, View arg1, int pos, long id) { if (firstSelection) firstSelection = false; else { JNIHandler.setResampleTimidity(JNIHandler.currsamp = pos); JNIHandler.seekTo(JNIHandler.currTime); } } @Override public void onNothingSelected(AdapterView<?> arg0) { } }); x.setSelection(JNIHandler.currsamp); if (Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.ICE_CREAM_SANDWICH) v.setBackgroundColor(Globals.theme == 1 ? Color.WHITE : Color.BLACK); b.setView(v); b.setPositiveButton("OK", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { } }); b.setTitle(getActivity().getResources().getString(R.string.mop)); ddd = b.create(); ddd.show(); }
From source file:com.simadanesh.isatis.ScreenSlideActivity.java
private void switchFlash() { boolean hasFlash = getApplicationContext().getPackageManager() .hasSystemFeature(PackageManager.FEATURE_CAMERA_FLASH); if (!hasFlash) { // device doesn't support flash // Show alert message and close the application AlertDialog alert = new AlertDialog.Builder(this).create(); alert.setTitle("Error"); alert.setMessage("Sorry, your device doesn't support flash light!"); alert.setButton(AlertDialog.BUTTON_POSITIVE, "OK", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { }//w ww . java2 s.c o m }); alert.show(); return; } if (isFlashOn) { // turn off flash turnOffFlash(); } else { // turn on flash turnOnFlash(); } }