List of usage examples for android.app AlertDialog setButton
public void setButton(int whichButton, CharSequence text, OnClickListener listener)
From source file:de.blinkt.openvpn.ActivityDashboard.java
public void handlerMessageBox(int id, Handler handler, String title, String message, String yes, String no, String cancel) {/*from w ww .ja va 2s. co m*/ AlertDialog box = new AlertDialog.Builder(this).create(); HandlerDialogClickListener listener = new HandlerDialogClickListener(handler, id); if (yes != null) box.setButton(AlertDialog.BUTTON_POSITIVE, yes, listener); if (no != null) box.setButton(AlertDialog.BUTTON_NEUTRAL, no, listener); if (cancel != null) box.setButton(AlertDialog.BUTTON_NEGATIVE, cancel, listener); box.setTitle(title); box.setMessage(message); box.show(); }
From source file:net.homelinux.penecoptero.android.citybikes.app.MainActivity.java
private void showAutoNetworkDialog(int method) { AlertDialog alertDialog = new AlertDialog.Builder(this).create(); alertDialog.setIcon(android.R.drawable.ic_dialog_map); final int mth = method; try {//from w w w . j a va2s. c om mNDBAdapter.update(); final JSONObject network = mNDBAdapter.getAutomaticNetwork(hOverlay.getPoint(), method); alertDialog.setTitle(R.string.bike_network_alert_success_title); alertDialog.setMessage(getString(R.string.bike_network_alert_success_text0) + ":\n- (" + network.getString("city") + ") " + network.getString("name") + "\n" + getString(R.string.bike_network_alert_success_text1)); alertDialog.setButton(AlertDialog.BUTTON_POSITIVE, getString(R.string.sure), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { try { mNDBAdapter.setManualNetwork(network.getInt("id")); fillData(view_all); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } }); alertDialog.setButton(AlertDialog.BUTTON_NEUTRAL, getString(R.string.try_again), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { showAutoNetworkDialog(0); } }); alertDialog.setButton(AlertDialog.BUTTON_NEGATIVE, getString(R.string.manual), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { showBikeNetworks(); } }); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); alertDialog.setTitle(R.string.bike_network_alert_error_title); alertDialog.setMessage(getString(R.string.bike_network_alert_error_text)); alertDialog.setButton(AlertDialog.BUTTON_POSITIVE, getString(R.string.try_again), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { if (mth == 0) showAutoNetworkDialog(1); else showAutoNetworkDialog(0); } }); alertDialog.setButton(AlertDialog.BUTTON_NEGATIVE, getString(R.string.manual), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { showBikeNetworks(); } }); } alertDialog.show(); }
From source file:info.zamojski.soft.towercollector.MainActivity.java
private boolean displayInAirplaneModeDialog() { // check if in airplane mode boolean inAirplaneMode = NetworkUtils.isInAirplaneMode(getApplication()); if (inAirplaneMode) { Log.d("displayInAirplaneModeDialog(): Device is in airplane mode"); AlertDialog alertDialog = new AlertDialog.Builder(this).create(); alertDialog.setCanceledOnTouchOutside(true); alertDialog.setCancelable(true); alertDialog.setTitle(R.string.main_dialog_in_airplane_mode_title); alertDialog.setMessage(getString(R.string.main_dialog_in_airplane_mode_message)); alertDialog.setButton(DialogInterface.BUTTON_POSITIVE, getString(R.string.dialog_ok), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { }//from w w w .j a va 2s . c o m }); alertDialog.show(); } return inAirplaneMode; }
From source file:piuk.blockchain.android.ui.SendCoinsFragment.java
@Override public View onCreateView(final LayoutInflater inflater, final ViewGroup container, final Bundle savedInstanceState) { final SendCoinsActivity activity = (SendCoinsActivity) getActivity(); final View view = inflater.inflate(R.layout.send_coins_fragment, container); final MyRemoteWallet wallet = application.getRemoteWallet(); if (wallet == null) return view; BigInteger available = null;//from w w w .j ava 2s .c o m if (application.isInP2PFallbackMode()) { try { available = application.bitcoinjWallet.getBalance(BalanceType.ESTIMATED); } catch (Exception e) { e.printStackTrace(); } } else { available = wallet.getBalance(); } receivingAddressView = (AutoCompleteTextView) view.findViewById(R.id.send_coins_receiving_address); feeContainerView = view.findViewById(R.id.send_coins_fee_container); sendCoinsFromContainer = view.findViewById(R.id.send_coins_from_container); sendCoinsFromSpinner = (Spinner) view.findViewById(R.id.send_coins_from_spinner); feeAmountView = (CurrencyAmountView) view.findViewById(R.id.send_coins_fee); sendTypeDescriptionContainer = view.findViewById(R.id.send_type_description_container); sendTypeDescription = (TextView) view.findViewById(R.id.send_type_description); sendTypeDescriptionIcon = (ImageView) view.findViewById(R.id.send_type_description_icon); { //Construct the from drop down list String[] activeAddresses = wallet.getActiveAddresses(); Map<String, String> labelMap = wallet.getLabelMap(); List<Pair<String, String>> pairs = new ArrayList<Pair<String, String>>(); for (String address : activeAddresses) { String label = labelMap.get(address); if (label == null || label.length() == 0) { label = "No Label"; } BigInteger balance = wallet.getBalance(address); if (balance.compareTo(BigInteger.ZERO) > 0) { label += " (" + WalletUtils.formatValue(balance) + " BTC)"; pairs.add(new Pair<String, String>(address, label)); } } pairs.add(0, new Pair<String, String>("Any Address", "Any Address")); sendCoinsFromSpinner.setAdapter(new SpinAdapter(activity, android.R.layout.simple_list_item_1, pairs)); } feeAmountView.setAmount(wallet.getBaseFee()); StringPairAdapter adapter = new StringPairAdapter(this.getLabelList()); receivingAddressView.setAdapter(adapter); receivingAddressView.addTextChangedListener(textWatcher); receivingAddressView.setOnTouchListener(new RightDrawableOnTouchListener(receivingAddressView) { @Override public boolean onDrawableTouch(final MotionEvent event) { activity.showQRReader(activity.new QrCodeDelagate() { @Override public void didReadQRCode(String data) { activity.handleScanURI(data); } }); return true; } }); receivingAddressErrorView = view.findViewById(R.id.send_coins_receiving_address_error); availableViewContainer = view.findViewById(R.id.send_coins_available_container); availableView = (CurrencyAmountView) view.findViewById(R.id.send_coins_available); availableView.setAmount(available); amountView = (CurrencyAmountView) view.findViewById(R.id.send_coins_amount); amountView.setListener(listener); amountView.setContextButton(R.drawable.ic_input_calculator, new OnClickListener() { public void onClick(final View v) { final FragmentTransaction ft = getFragmentManager().beginTransaction(); final Fragment prev = getFragmentManager().findFragmentByTag(AmountCalculatorFragment.FRAGMENT_TAG); if (prev != null) ft.remove(prev); ft.addToBackStack(null); final DialogFragment newFragment = new AmountCalculatorFragment( new AmountCalculatorFragment.Listener() { public void use(final BigInteger amount) { amountView.setAmount(amount); } }); newFragment.show(ft, AmountCalculatorFragment.FRAGMENT_TAG); } }); viewGo = (Button) view.findViewById(R.id.send_coins_go); viewGo.setOnClickListener(new OnClickListener() { final SendProgress progress = new SendProgress() { public void onSend(final Transaction tx, final String message) { handler.post(new Runnable() { public void run() { state = State.SENT; activity.longToast(message); Intent intent = activity.getIntent(); intent.putExtra("tx", tx.getHash()); activity.setResult(Activity.RESULT_OK, intent); activity.finish(); updateView(); } }); try { Thread.sleep(2000); } catch (InterruptedException e) { e.printStackTrace(); } application.doMultiAddr(true); } public void onError(final String message) { handler.post(new Runnable() { public void run() { System.out.println("On Error"); if (message != null) activity.longToast(message); state = State.INPUT; updateView(); } }); } public void onProgress(final String message) { handler.post(new Runnable() { public void run() { state = State.SENDING; updateView(); } }); } public boolean onReady(Transaction tx, BigInteger fee, FeePolicy feePolicy, long priority) { boolean containsOutputLessThanThreshold = false; for (TransactionOutput output : tx.getOutputs()) { if (output.getValue().compareTo(Constants.FEE_THRESHOLD_MIN) < 0) { containsOutputLessThanThreshold = true; break; } } if (feePolicy != FeePolicy.FeeNever && fee.compareTo(BigInteger.ZERO) == 0) { if (tx.bitcoinSerialize().length > 1024 || containsOutputLessThanThreshold) { makeTransaction(FeePolicy.FeeForce); return false; } else if (priority < 97600000L) { handler.post(new Runnable() { public void run() { AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); builder.setMessage(R.string.ask_for_fee).setCancelable(false); AlertDialog alert = builder.create(); alert.setButton(AlertDialog.BUTTON_NEUTRAL, getString(R.string.continue_without_fee), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { makeTransaction(FeePolicy.FeeNever); dialog.dismiss(); } }); alert.setButton(AlertDialog.BUTTON_POSITIVE, getString(R.string.add_fee), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { makeTransaction(FeePolicy.FeeForce); dialog.dismiss(); } }); alert.setButton(AlertDialog.BUTTON_NEGATIVE, getString(R.string.cancel), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.dismiss(); } }); alert.show(); } }); handler.post(new Runnable() { public void run() { state = State.INPUT; updateView(); } }); return false; } } return true; } public ECKey onPrivateKeyMissing(final String address) { handler.post(new Runnable() { public void run() { AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); builder.setMessage(getString(R.string.ask_for_private_key, address)) .setCancelable(false) .setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { activity.scanPrivateKeyAddress = address; activity.showQRReader(activity.new QrCodeDelagate() { @Override public void didReadQRCode(String data) throws Exception { activity.handleScanPrivateKey(data); } }); } }) .setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { synchronized (activity.temporaryPrivateKeys) { activity.temporaryPrivateKeys.notify(); } dialog.cancel(); } }); AlertDialog alert = builder.create(); alert.show(); } }); try { synchronized (activity.temporaryPrivateKeys) { activity.temporaryPrivateKeys.wait(); } } catch (InterruptedException e) { e.printStackTrace(); } return activity.temporaryPrivateKeys.get(address); } }; public void send(Address receivingAddress, BigInteger fee, FeePolicy feePolicy) { if (application.getRemoteWallet() == null) return; if (sendType != null && !sendType.equals(SendCoinsActivity.SendTypeQuickSend) && application.isInP2PFallbackMode()) { activity.longToast(R.string.only_quick_supported); return; } String[] from; if (sendType != null && sendType.equals(SendCoinsActivity.SendTypeCustomSend)) { Pair<String, String> selected = (Pair<String, String>) sendCoinsFromSpinner.getSelectedItem(); if (selected.first.equals("Any Address")) { from = wallet.getActiveAddresses(); } else { from = new String[] { selected.first.toString() }; } } else { from = wallet.getActiveAddresses(); } final BigInteger amount; if (sendType != null && sendType.equals(SendCoinsActivity.SendTypeSharedSend)) { BigDecimal amountDecimal = BigDecimal.valueOf(amountView.getAmount().doubleValue()); //Add the fee amount = amountDecimal.add(amountDecimal.divide(BigDecimal.valueOf(100)) .multiply(BigDecimal.valueOf(wallet.getSharedFee()))).toBigInteger(); } else { amount = amountView.getAmount(); } final WalletApplication application = (WalletApplication) getActivity().getApplication(); if (application.isInP2PFallbackMode()) { final long blockchainLag = System.currentTimeMillis() - service.blockChain.getChainHead().getHeader().getTime().getTime(); final boolean blockchainUptodate = blockchainLag < Constants.BLOCKCHAIN_UPTODATE_THRESHOLD_MS; if (!blockchainUptodate) { activity.longToast(R.string.blockchain_not_upto_date); return; } // create spend final SendRequest sendRequest = SendRequest.to(receivingAddress, amountView.getAmount()); sendRequest.fee = fee; new Thread(new Runnable() { public void run() { final Transaction transaction = application.bitcoinjWallet .sendCoinsOffline(sendRequest); handler.post(new Runnable() { public void run() { if (transaction != null) { state = State.SENDING; updateView(); service.broadcastTransaction(transaction); state = State.SENT; activity.longToast(R.string.wallet_transactions_fragment_tab_sent); Intent intent = activity.getIntent(); intent.putExtra("tx", transaction.getHash()); activity.setResult(Activity.RESULT_OK, intent); activity.finish(); updateView(); EventListeners.invokeOnTransactionsChanged(); } else { state = State.INPUT; updateView(); activity.longToast(R.string.send_coins_error_msg); } } }); } }).start(); } else { application.getRemoteWallet().sendCoinsAsync(from, receivingAddress.toString(), amount, feePolicy, fee, progress); } } public void makeTransaction(FeePolicy feePolicy) { if (application.getRemoteWallet() == null) return; try { MyRemoteWallet wallet = application.getRemoteWallet(); BigInteger baseFee = wallet.getBaseFee(); BigInteger fee = null; if (feePolicy == FeePolicy.FeeForce) { fee = baseFee; } else if (sendType != null && sendType.equals(SendCoinsActivity.SendTypeCustomSend)) { feePolicy = FeePolicy.FeeOnlyIfNeeded; fee = feeAmountView.getAmount(); } else { fee = (wallet.getFeePolicy() == 1) ? baseFee : BigInteger.ZERO; } final BigInteger finalFee = fee; final FeePolicy finalFeePolicy = feePolicy; if (sendType != null && sendType.equals(SendCoinsActivity.SendTypeSharedSend)) { new Thread(new Runnable() { @Override public void run() { try { final String addressString = MyRemoteWallet .generateSharedAddress(getToAddress()); handler.post(new Runnable() { @Override public void run() { try { send(new Address(Constants.NETWORK_PARAMETERS, addressString), finalFee, finalFeePolicy); } catch (Exception e) { e.printStackTrace(); Toast.makeText(application, e.getLocalizedMessage(), Toast.LENGTH_LONG).show(); } } }); } catch (final Exception e) { handler.post(new Runnable() { @Override public void run() { e.printStackTrace(); Toast.makeText(application, e.getLocalizedMessage(), Toast.LENGTH_LONG) .show(); } }); } } }).start(); } else { String addressString = getToAddress(); Address receivingAddress = new Address(Constants.NETWORK_PARAMETERS, addressString); send(receivingAddress, fee, feePolicy); } } catch (Exception e) { e.printStackTrace(); } } public void onClick(final View v) { if (application.getRemoteWallet() == null) return; MyRemoteWallet remoteWallet = application.getRemoteWallet(); if (remoteWallet.isDoubleEncrypted() == false) { makeTransaction(FeePolicy.FeeOnlyIfNeeded); } else { if (remoteWallet.temporySecondPassword == null) { RequestPasswordDialog.show(getFragmentManager(), new SuccessCallback() { public void onSuccess() { makeTransaction(FeePolicy.FeeOnlyIfNeeded); } public void onFail() { Toast.makeText(application, R.string.send_no_password_error, Toast.LENGTH_LONG) .show(); } }, RequestPasswordDialog.PasswordTypeSecond); } else { makeTransaction(FeePolicy.FeeOnlyIfNeeded); } } } }); viewCancel = (Button) view.findViewById(R.id.send_coins_cancel); viewCancel.setOnClickListener(new OnClickListener() { public void onClick(final View v) { activity.setResult(Activity.RESULT_CANCELED); activity.finish(); } }); activity.setOnChangedSendTypeListener(new OnChangedSendTypeListener() { @Override public void onChangedSendType(String type) { sendType = type; feeContainerView.setVisibility(View.GONE); sendCoinsFromContainer.setVisibility(View.GONE); availableViewContainer.setVisibility(View.VISIBLE); sendTypeDescriptionContainer.setVisibility(View.GONE); if (type.equals(SendCoinsActivity.SendTypeCustomSend)) { feeContainerView.setVisibility(View.VISIBLE); sendCoinsFromContainer.setVisibility(View.VISIBLE); availableViewContainer.setVisibility(View.GONE); } else if (type.equals(SendCoinsActivity.SendTypeSharedSend)) { sendTypeDescriptionContainer.setVisibility(View.VISIBLE); sendTypeDescription .setText(getString(R.string.shared_send_description, wallet.getSharedFee() + "%")); sendTypeDescriptionIcon.setImageResource(R.drawable.ic_icon_shared); } } }); updateView(); return view; }
From source file:in.animeshpathak.nextbus.NextBusMain.java
/** * Creates the Application Info dialog with clickable links. * /*ww w. j ava 2 s.c o m*/ * @throws UnsupportedEncodingException * @throws IOException */ private void showVersionInfoDialog() throws UnsupportedEncodingException, IOException { AlertDialog alertDialog = new AlertDialog.Builder(this).create(); alertDialog.setTitle(getString(R.string.app_name) + " " + getString(R.string.version_name)); AssetManager assetManager = getResources().getAssets(); String versionInfoFile = getString(R.string.versioninfo_asset); InputStreamReader reader = new InputStreamReader(assetManager.open(versionInfoFile), "UTF-8"); BufferedReader br = new BufferedReader(reader); StringBuffer sbuf = new StringBuffer(); String line; while ((line = br.readLine()) != null) { sbuf.append(line); sbuf.append("\r\n"); } final ScrollView scroll = new ScrollView(this); final TextView message = new TextView(this); final SpannableString sWlinks = new SpannableString(sbuf.toString()); Linkify.addLinks(sWlinks, Linkify.WEB_URLS); message.setText(sWlinks); message.setMovementMethod(LinkMovementMethod.getInstance()); message.setPadding(15, 15, 15, 15); scroll.addView(message); alertDialog.setView(scroll); alertDialog.setButton(AlertDialog.BUTTON_POSITIVE, "Ok", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // nothing to do, just dismiss dialog } }); alertDialog.show(); }
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 ww w. ja va 2s .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;//from w w w .j a v a 2 s . 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:fr.cobaltians.cobalt.fragments.CobaltFragment.java
/****************************************************************************************************************** * ALERT DIALOG/*from w w w . j av a 2s . c o m*/ *****************************************************************************************************************/ private void showAlertDialog(JSONObject data, final String callback) { try { String title = data.optString(Cobalt.kJSAlertTitle); String message = data.optString(Cobalt.kJSMessage); boolean cancelable = data.optBoolean(Cobalt.kJSAlertCancelable, false); JSONArray buttons = data.has(Cobalt.kJSAlertButtons) ? data.getJSONArray(Cobalt.kJSAlertButtons) : new JSONArray(); AlertDialog alertDialog = new AlertDialog.Builder(mContext).setTitle(title).setMessage(message) .create(); alertDialog.setCancelable(cancelable); if (buttons.length() == 0) { alertDialog.setButton(DialogInterface.BUTTON_NEGATIVE, "OK", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { if (callback != null) { try { JSONObject data = new JSONObject(); data.put(Cobalt.kJSAlertButtonIndex, 0); sendCallback(callback, data); } catch (JSONException exception) { if (Cobalt.DEBUG) Log.e(Cobalt.TAG, TAG + ".AlertDialog - onClick: JSONException"); exception.printStackTrace(); } } } }); } else { int buttonsLength = Math.min(buttons.length(), 3); for (int i = 0; i < buttonsLength; i++) { int buttonId; switch (i) { case 0: default: buttonId = DialogInterface.BUTTON_NEGATIVE; break; case 1: buttonId = DialogInterface.BUTTON_NEUTRAL; break; case 2: buttonId = DialogInterface.BUTTON_POSITIVE; break; } alertDialog.setButton(buttonId, buttons.getString(i), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { if (callback != null) { int buttonIndex; switch (which) { case DialogInterface.BUTTON_NEGATIVE: default: buttonIndex = 0; break; case DialogInterface.BUTTON_NEUTRAL: buttonIndex = 1; break; case DialogInterface.BUTTON_POSITIVE: buttonIndex = 2; break; } try { JSONObject data = new JSONObject(); data.put(Cobalt.kJSAlertButtonIndex, buttonIndex); sendCallback(callback, data); } catch (JSONException exception) { if (Cobalt.DEBUG) Log.e(Cobalt.TAG, TAG + ".AlertDialog - onClick: JSONException"); exception.printStackTrace(); } } } }); } } alertDialog.show(); } catch (JSONException exception) { if (Cobalt.DEBUG) Log.e(Cobalt.TAG, TAG + " - showAlertDialog: JSONException"); exception.printStackTrace(); } }
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(/*w ww . j ava 2s .co m*/ 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 w w. ja v a 2 s. c om }); alert.show(); return; } if (isFlashOn) { // turn off flash turnOffFlash(); } else { // turn on flash turnOnFlash(); } }