/** * Displays a message box to the user with an OK button. * * @param title * @param message * @param className The calling class, such as GpsMainActivity.this or mainActivity. * @param msgCallback An object which implements IHasACallBack so that the click event can call * the callback method. */ private static void MsgBox( String title, String message, Context className, final IMessageBoxCallback msgCallback) { MaterialDialog alertDialog = new MaterialDialog.Builder(className) .title(title) .content(message) .positiveText(R.string.ok) .callback( new MaterialDialog.ButtonCallback() { @Override public void onPositive(MaterialDialog dialog) { if (msgCallback != null) { msgCallback.MessageBoxResult(0); } } @Override public void onNegative(MaterialDialog dialog) { super.onNegative(dialog); } }) .build(); if (className instanceof Activity && !((Activity) className).isFinishing()) { alertDialog.show(); } else { alertDialog.show(); } }
/** * Displays a message box to the user with an OK button. * * @param title * @param message * @param context The calling class, such as GpsMainActivity.this or mainActivity. * @param msgCallback An object which implements IHasACallBack so that the click event can call * the callback method. */ public static void alert( String title, String message, Context context, final MessageBoxCallback msgCallback) { MaterialDialog alertDialog = new MaterialDialog.Builder(context) .title(title) .content(Html.fromHtml(message)) .positiveText(R.string.ok) .onPositive( new MaterialDialog.SingleButtonCallback() { @Override public void onClick( @NonNull MaterialDialog materialDialog, @NonNull DialogAction dialogAction) { if (msgCallback != null) { msgCallback.messageBoxResult(MessageBoxCallback.OK); } } }) .onNegative( new MaterialDialog.SingleButtonCallback() { @Override public void onClick( @NonNull MaterialDialog materialDialog, @NonNull DialogAction dialogAction) { if (msgCallback != null) { msgCallback.messageBoxResult(MessageBoxCallback.CANCEL); } } }) .build(); if (context instanceof Activity && !((Activity) context).isFinishing()) { alertDialog.show(); } else { alertDialog.show(); } }
@Override public void showLoadDialog(String title, String message) { MaterialDialog.Builder builder = new MaterialDialog.Builder(this) .title(title) .content(message) .positiveText("确定") .onPositive( new MaterialDialog.SingleButtonCallback() { @Override public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) { presenter.updateOrderCargo(unRemoveEt.getText().toString()); } }) .negativeText("取消") .onNegative( new MaterialDialog.SingleButtonCallback() { @Override public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) { dialog.dismiss(); } }); MaterialDialog dialog = builder.build(); dialog.show(); }
private void executequery() { materialDialog.show(); Client.INSTANCE.getServiceReport( MkShop.AUTH, sFromDate, sToDate, new Callback<List<ServiceCenterEntity>>() { @Override public void success(final List<ServiceCenterEntity> serviceList, Response response) { Myenum.INSTANCE.setServiceList(serviceList); if (materialDialog != null && materialDialog.isShowing()) materialDialog.dismiss(); tabLayout.setTabsFromPagerAdapter(adapter); viewPager.setAdapter(adapter); } @Override public void failure(RetrofitError error) { if (materialDialog != null && materialDialog.isShowing()) materialDialog.dismiss(); MkShop.toast(getActivity(), error.getMessage()); } }); }
public static void showInputDialog( Activity context, int title, int hint, String prefillInput, final InputCallback callback) { @SuppressLint("InflateParams") final View view = context.getLayoutInflater().inflate(R.layout.dialog_input, null); MaterialDialog.Builder dialog = new MaterialDialog.Builder(context) .title(title) .positiveText(android.R.string.ok) .negativeText(android.R.string.cancel) .callback( new MaterialDialog.ButtonCallback() { @Override public void onPositive(MaterialDialog dialog) { if (callback != null) { EditText input = (EditText) view.findViewById(R.id.input); callback.onInput(input.getText().toString().trim()); } } }) .customView(view, true); final EditText input = (EditText) view.findViewById(R.id.input); if (hint != 0) input.setHint(hint); if (prefillInput != null) input.append(prefillInput); MaterialDialog alert = dialog.build(); alert.setOnDismissListener( new DialogInterface.OnDismissListener() { @Override public void onDismiss(DialogInterface dialog) { if (callback instanceof InputCancelCallback) ((InputCancelCallback) callback).onCancel(); } }); alert.show(); }
@OnClick(R.id.customView) public void showCustomView() { MaterialDialog dialog = new MaterialDialog.Builder(this) .title(R.string.googleWifi) .customView(R.layout.dialog_customview, true) .positiveText(R.string.connect) .negativeText(android.R.string.cancel) .onPositive( new MaterialDialog.SingleButtonCallback() { @Override public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) { showToast("Password: " + passwordInput.getText().toString()); } }) .build(); positiveAction = dialog.getActionButton(DialogAction.POSITIVE); //noinspection ConstantConditions passwordInput = (EditText) dialog.getCustomView().findViewById(R.id.password); passwordInput.addTextChangedListener( new TextWatcher() { @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) {} @Override public void onTextChanged(CharSequence s, int start, int before, int count) { positiveAction.setEnabled(s.toString().trim().length() > 0); } @Override public void afterTextChanged(Editable s) {} }); // Toggling the show password CheckBox will mask or unmask the password input EditText CheckBox checkbox = (CheckBox) dialog.getCustomView().findViewById(R.id.showPassword); checkbox.setOnCheckedChangeListener( new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { passwordInput.setInputType( !isChecked ? InputType.TYPE_TEXT_VARIATION_PASSWORD : InputType.TYPE_CLASS_TEXT); passwordInput.setTransformationMethod( !isChecked ? PasswordTransformationMethod.getInstance() : null); } }); int widgetColor = ThemeSingleton.get().widgetColor; MDTintHelper.setTint( checkbox, widgetColor == 0 ? ContextCompat.getColor(this, R.color.material_teal_500) : widgetColor); MDTintHelper.setTint( passwordInput, widgetColor == 0 ? ContextCompat.getColor(this, R.color.material_teal_500) : widgetColor); dialog.show(); positiveAction.setEnabled(false); // disabled by default }
private void showCustomView() { MaterialDialog dialog = new MaterialDialog.Builder(this) .title(R.string.googleWifi) .positiveText(R.string.agree) .customView(R.layout.dialog_customview) .positiveText(R.string.connect) .negativeText(android.R.string.cancel) .callback( new MaterialDialog.Callback() { @Override public void onPositive(MaterialDialog dialog) { Toast.makeText( getApplicationContext(), "Password: " + passwordInput.getText().toString(), Toast.LENGTH_SHORT) .show(); } @Override public void onNegative(MaterialDialog dialog) {} }) .build(); positiveAction = dialog.getActionButton(DialogAction.POSITIVE); passwordInput = (EditText) dialog.getCustomView().findViewById(R.id.password); passwordInput.addTextChangedListener( new TextWatcher() { @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) {} @Override public void onTextChanged(CharSequence s, int start, int before, int count) { positiveAction.setEnabled(s.toString().trim().length() > 0); } @Override public void afterTextChanged(Editable s) {} }); // Toggling the show password CheckBox will mask or unmask the password input EditText ((CheckBox) dialog.getCustomView().findViewById(R.id.showPassword)) .setOnCheckedChangeListener( new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { passwordInput.setInputType( !isChecked ? InputType.TYPE_TEXT_VARIATION_PASSWORD : InputType.TYPE_CLASS_TEXT); passwordInput.setTransformationMethod( !isChecked ? PasswordTransformationMethod.getInstance() : null); } }); dialog.show(); positiveAction.setEnabled(false); // disabled by default }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); tracer = LoggerFactory.getLogger(NotificationAnnotationActivity.class.getSimpleName()); MaterialDialog alertDialog = new MaterialDialog.Builder(this) .title(R.string.add_description) .customView(R.layout.alertview, false) .positiveText(R.string.ok) .negativeText(R.string.cancel) .callback( new MaterialDialog.ButtonCallback() { @Override public void onNeutral(MaterialDialog dialog) { super.onNeutral(dialog); } @Override public void onNegative(MaterialDialog dialog) { finish(); } @Override public void onPositive(MaterialDialog dialog) { EditText userInput = (EditText) dialog.getCustomView().findViewById(R.id.alert_user_input); tracer.info("Annotation from notification: " + userInput.getText().toString()); EventBus.getDefault() .postSticky(new CommandEvents.Annotate(userInput.getText().toString())); Intent serviceIntent = new Intent(getApplicationContext(), GpsLoggingService.class); getApplicationContext().startService(serviceIntent); finish(); } }) .cancelListener( new DialogInterface.OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { dialog.dismiss(); finish(); } }) .build(); TextView tvMessage = (TextView) alertDialog.getCustomView().findViewById(R.id.alert_user_message); tvMessage.setText(R.string.letters_numbers); alertDialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE); alertDialog.show(); }
@Override public void onDownloadFinished(boolean success, File file) { if (downloadDialog.isShowing()) downloadDialog.cancel(); if (success) { downloadDialog = new BaseDialog(this).getDownloadFinishedDialog(true, file.getAbsolutePath()); } else { downloadDialog = new BaseDialog(this).getDownloadFinishedDialog(false, null); } downloadDialog.show(); }
@Override protected void onPreExecute() { super.onPreExecute(); dialog = new MaterialDialog.Builder(getActivity()) .content("please wait") .progress(true, 0) .build(); dialog.show(); }
public void showAwesomePopup() { MaterialDialog awesomeDialog = new MaterialDialog.Builder(hostActivity) .title(R.string.how_is_the_app) .items(R.array.greatOrNot) .itemsCallbackSingleChoice( 0, new MaterialDialog.ListCallbackSingleChoice() { @Override public boolean onSelection( MaterialDialog dialog, View view, int which, CharSequence text) { switch (which) { case 0: showRatingPopup(); break; case 1: isClickedNotGreate = true; mEditor.putBoolean(PREF_CLICKED_NOT_GREAT, true).commit(); showFeedbackPopup(); break; } return true; // allow selection } }) // .positiveText(R.string.great) .negativeText(R.string.cancel) // .neutralText(R.string.cancel) .onAny( new MaterialDialog.SingleButtonCallback() { @Override public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) { switch (which) { case POSITIVE: // great showRatingPopup(); break; case NEGATIVE: // not great isClickedNotGreate = true; mEditor.putBoolean(PREF_CLICKED_NOT_GREAT, true).commit(); showFeedbackPopup(); break; case NEUTRAL: // later isClickedLater = true; startUsingAppTime = System.currentTimeMillis(); mEditor.putBoolean(PREF_CLICKED_LATER, true).commit(); break; } } }) .build(); awesomeDialog.show(); }
private void requestGplusPermission() { final String[] PERMISSIONS = {Manifest.permission.GET_ACCOUNTS, Manifest.permission.INTERNET}; if (ActivityCompat.shouldShowRequestPermissionRationale( getActivity(), Manifest.permission.GET_ACCOUNTS) || ActivityCompat.shouldShowRequestPermissionRationale( getActivity(), Manifest.permission.INTERNET)) { // Provide an additional rationale to the user if the permission was not granted // and the user would benefit from additional context for the use of the permission. // For example, if the request has been denied previously. String fab_skin = (BaseActivity.accentSkin); final MaterialDialog materialDialog = Futils.showBasicDialog( getActivity(), fab_skin, theme, new String[] { getResources().getString(R.string.grantgplus), getResources().getString(R.string.grantper), getResources().getString(R.string.grant), getResources().getString(R.string.cancel), null }); materialDialog .getActionButton(DialogAction.POSITIVE) .setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { ActivityCompat.requestPermissions(getActivity(), PERMISSIONS, 66); materialDialog.dismiss(); } }); materialDialog .getActionButton(DialogAction.NEGATIVE) .setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { getActivity().finish(); } }); materialDialog.setCancelable(false); materialDialog.show(); } else { // Contact permissions have not been granted yet. Request them directly. ActivityCompat.requestPermissions(getActivity(), PERMISSIONS, 66); } }
@Override public void showProgress() { if (progressDialog == null || !progressDialog.isShowing()) { progressDialog = new MaterialDialog.Builder(this) .title(R.string.app_name) .content(R.string.creating_keys) .progress(true, 0) .build(); progressDialog.setCanceledOnTouchOutside(false); } if (!isFinishing()) { progressDialog.show(); } }
private void displayDiscoveryDialog() { dialog = new MaterialDialog.Builder(this.context) .title(R.string.dialog_search_blueetooth_title) .content(R.string.dialog_search_blueetooth_message) .progress(true, 0) .cancelListener( new DialogInterface.OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { currentBluetoothAdapter.cancelDiscovery(); } }) .build(); dialog.show(); }
public void removeArticle(FeedItem feedItem) { final FeedItem feedItemFinal = feedItem; MaterialDialog removeArticleDialog = new MaterialDialog.Builder(mContext) .title(R.string.remove_archive) .content(R.string.remove_archive_content) .positiveText(R.string.remove) .negativeText(R.string.cancel) .onPositive( new MaterialDialog.SingleButtonCallback() { @Override public void onClick(MaterialDialog materialDialog, DialogAction dialogAction) { // remove this archive from db mArticleInteractor.deleteArticleInDb( ArticlePresenter.this, mContext, feedItemFinal); } }) .build(); removeArticleDialog.show(); }
private void consultaTabelaPreco(final Produtos produto) { final Integer divisao = 100; final MaterialDialog dialog = new MaterialDialog.Builder(this) .title("Tabela Preço") .customView(R.layout.layout_dialogs_tabelapreco, true) .negativeText("Sair") .autoDismiss(true) .build(); listviewtabelaPreco = (ListView) dialog.findViewById(R.id.listviewtabelaPreco); lista = produtodao.listPrecoidprodutoComTabelaItem(produto.getIdproduto()); arrayAdapter = new AdapterTabelaprecoSpinner(this, lista); listviewtabelaPreco.setAdapter(arrayAdapter); dialog.show(); }
public void showFeedbackPopup() { MaterialDialog feedbackDialog = new MaterialDialog.Builder(hostActivity) .content(R.string.ask_to_leave_feedback) .positiveText(R.string.ok) .negativeText(R.string.cancel) .onAny( new MaterialDialog.SingleButtonCallback() { @Override public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) { switch (which) { case POSITIVE: // ok sendFeedbackEmail(); break; case NEGATIVE: // do not show break; } } }) .build(); feedbackDialog.show(); }
private void showRatingPopup() { if (dialog == null) { dialog = new MaterialDialog.Builder(hostActivity) // .title(R.string.rate_inmapz) .content(R.string.will_rate_inmapz) .positiveText(R.string.ok) .negativeText(R.string.later) // .neutralText(R.string.later) .onAny( new MaterialDialog.SingleButtonCallback() { @Override public void onClick( @NonNull MaterialDialog dialog, @NonNull DialogAction which) { switch (which) { case POSITIVE: // ok isClickedRate = true; mEditor.putBoolean(PREF_CLICKED_RATE, true).commit(); gotoStore(); break; // case NEGATIVE://do not show // isClickedNotGreate = true; // // mEditor.putBoolean(PREF_CLICKED_NOT_GREAT, true).commit(); // break; case NEGATIVE: // later isClickedLater = true; startUsingAppTime = System.currentTimeMillis(); mEditor.putBoolean(PREF_CLICKED_LATER, true).commit(); break; } } }) .build(); } dialog.show(); }
@Override public boolean onOptionsItemSelected(MenuItem item) { int id = item.getItemId(); if (id == R.id.send) { if (!mImagesPanel.isUploadFinished()) { Toast.makeText(getActivity(), "Wait or check for errors!", Toast.LENGTH_SHORT).show(); return true; } final String text = mPostText.getText().toString(); final String[] tags = mPostTags.getText().toString().split("\\s*,\\s*"); StringBuilder sb = new StringBuilder(text); for (String l : mImagesPanel.getLinks()) { sb.append("\n").append(l); } mProgressDialog.show(); if (TextUtils.isEmpty(mPostId)) { if (mIsPrivate.isChecked()) PointConnectionManager.getInstance() .pointIm .createPrivatePost( sb.toString().trim(), tags, mIsPrivate.isChecked(), mNewPostCallback); else PointConnectionManager.getInstance() .pointIm .createPost(sb.toString().trim(), tags, mNewPostCallback); } else { PointConnectionManager.getInstance() .pointIm .editPost(mPostId, sb.toString().trim(), tags, mNewPostCallback); } return true; } else if (id == R.id.attach) { Intent i = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI); startActivityForResult(i, RESULT_LOAD_IMAGE); } return super.onOptionsItemSelected(item); }
@Override public boolean onItemLongClick( AdapterView<?> adapterView, final View view, final int i, long l) { MaterialDialog deleteDialog = new MaterialDialog.Builder(getActivity()) .title(R.string.options) .titleColor(getResources().getColor(R.color.lightest)) .backgroundColor(getResources().getColor(R.color.primary)) .items(R.array.message_options) .itemColor(getResources().getColor(R.color.lightest)) .itemsCallback( new MaterialDialog.ListCallback() { @Override public void onSelection( MaterialDialog materialDialog, View _view, int which, CharSequence charSequence) { switch (which) { // Copy case 0: TextView msgText = (TextView) view.findViewById(R.id.message_text); ClipboardManager cbManager = (ClipboardManager) getActivity().getSystemService(Context.CLIPBOARD_SERVICE); ClipData clipData = ClipData.newPlainText("message", msgText.getText().toString()); cbManager.setPrimaryClip(clipData); Toast.makeText( getActivity(), R.string.clipboard_text_copied, Toast.LENGTH_LONG) .show(); break; // Delete case 1: new MaterialDialog.Builder(getActivity()) .title(R.string.delete_message) .backgroundColor(getResources().getColor(R.color.primary)) .titleColor(getResources().getColor(R.color.lightest)) .positiveText(R.string.yes) .positiveColor(getResources().getColor(R.color.lightest)) .negativeText(R.string.no) .negativeColor(getResources().getColor(R.color.lightest)) .callback( new MaterialDialog.ButtonCallback() { @Override public void onPositive(MaterialDialog dialog) { super.onPositive(dialog); dbManager.deleteMessage(messages.get(i).dbid); Animation anim = AnimationUtils.loadAnimation( getActivity(), android.R.anim.slide_out_right); anim.setDuration(250); anim.setAnimationListener( new Animation.AnimationListener() { @Override public void onAnimationStart(Animation animation) {} @Override public void onAnimationEnd(Animation animation) { messages.remove(i); adapter.notifyDataSetChanged(); } @Override public void onAnimationRepeat( Animation animation) {} }); view.startAnimation(anim); } @Override public void onNegative(MaterialDialog dialog) { super.onNegative(dialog); } }) .build() .show(); break; } } }) .build(); deleteDialog.show(); return true; }
private void showChooseDataFolderDialog() { Context context = ui.getActivity(); File dataFolder = UserPreferences.getDataFolder(null); if (dataFolder == null) { new MaterialDialog.Builder(ui.getActivity()) .title(R.string.error_label) .content(R.string.external_storage_error_msg) .neutralText(android.R.string.ok) .show(); return; } String dataFolderPath = dataFolder.getAbsolutePath(); int selectedIndex = -1; File[] mediaDirs = ContextCompat.getExternalFilesDirs(context, null); List<String> folders = new ArrayList<>(mediaDirs.length); List<CharSequence> choices = new ArrayList<>(mediaDirs.length); for (int i = 0; i < mediaDirs.length; i++) { File dir = mediaDirs[i]; if (dir == null || !dir.exists() || !dir.canRead() || !dir.canWrite()) { continue; } String path = mediaDirs[i].getAbsolutePath(); folders.add(path); if (dataFolderPath.equals(path)) { selectedIndex = i; } int index = path.indexOf("Android"); String choice; if (index >= 0) { choice = path.substring(0, index); } else { choice = path; } long bytes = StorageUtils.getFreeSpaceAvailable(path); String freeSpace = String.format( context.getString(R.string.free_space_label), Converter.byteToString(bytes)); choices.add( Html.fromHtml("<html><small>" + choice + " [" + freeSpace + "]" + "</small></html>")); } if (choices.size() == 0) { new MaterialDialog.Builder(ui.getActivity()) .title(R.string.error_label) .content(R.string.external_storage_error_msg) .neutralText(android.R.string.ok) .show(); return; } MaterialDialog dialog = new MaterialDialog.Builder(ui.getActivity()) .title(R.string.choose_data_directory) .content(R.string.choose_data_directory_message) .items(choices.toArray(new CharSequence[choices.size()])) .itemsCallbackSingleChoice( selectedIndex, (dialog1, itemView, which, text) -> { String folder = folders.get(which); Log.d(TAG, "data folder: " + folder); UserPreferences.setDataFolder(folder); setDataFolderText(); return true; }) .negativeText(R.string.cancel_label) .cancelable(true) .build(); dialog.show(); }
public void addTask(final View view) { boolean wrapInScrollView = true; final MaterialDialog dialog = new MaterialDialog.Builder(this) .title("Create task") .customView(R.layout.layout, wrapInScrollView) .positiveText("Add") .negativeText("Cancel") .build(); // Create the SPINNER to select the LIST Spinner spinner = (Spinner) dialog.findViewById(R.id.spinner); CharSequence[] charSequences = new CharSequence[groups.size() - 3]; int j = 0; for (int i = 0; i < groups.size(); i++) { if (i == 1 || i == 2 || i == (groups.size() - 1)) { } else { charSequences[j] = groups.get(i).getName(); j++; } } // Create an ArrayAdapter using the string array and a default spinner layout ArrayAdapter<CharSequence> adapter = new ArrayAdapter<CharSequence>( this, android.R.layout.simple_spinner_dropdown_item, charSequences); // Specify the layout to use when the list of choices appears adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); // Apply the adapter to the spinner spinner.setAdapter(adapter); final EditText taskName = (EditText) dialog.findViewById(R.id.editText); final Spinner listId = (Spinner) dialog.findViewById(R.id.spinner); dialog.getActionButton(DialogAction.POSITIVE).setEnabled(false); taskName.addTextChangedListener( new TextWatcher() { @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) {} @Override public void onTextChanged(CharSequence s, int start, int before, int count) {} @Override public void afterTextChanged(Editable s) { if (s.length() > 0) dialog.getActionButton(DialogAction.POSITIVE).setEnabled(true); else dialog.getActionButton(DialogAction.POSITIVE).setEnabled(false); } }); dialog .getBuilder() .onPositive( new MaterialDialog.SingleButtonCallback() { @Override public void onClick(MaterialDialog materialDialog, DialogAction dialogAction) { if (taskName.getText().toString().isEmpty()) return; Task task = new Task(); task.setAuthor(ParseUser.getCurrentUser()); task.setUuidString(); task.setName(taskName.getText().toString()); task.setDraft(true); task.setImportant(false); task.setDone(false); saveTask(task, (int) listId.getSelectedItemId()); } }); dialog.show(); }
public static void error( String title, final String friendlyMessage, final String errorMessage, final Throwable throwable, final Context context) { final String messageFormatted = getFormattedErrorMessageForDisplay(errorMessage, throwable); MaterialDialog alertDialog = new MaterialDialog.Builder(context) .title(title) .customView(R.layout.error_alertview, true) .autoDismiss(false) .negativeText("Copy") .positiveText(R.string.ok) .neutralText("Details") .onNeutral( new MaterialDialog.SingleButtonCallback() { @Override public void onClick( @NonNull MaterialDialog materialDialog, @NonNull DialogAction dialogAction) { final ExpandableTextView expTv1 = (ExpandableTextView) materialDialog .getCustomView() .findViewById(R.id.error_expand_text_view); expTv1.findViewById(R.id.expand_collapse).performClick(); } }) .onNegative( new MaterialDialog.SingleButtonCallback() { @Override public void onClick( @NonNull MaterialDialog materialDialog, @NonNull DialogAction dialogAction) { android.content.ClipboardManager clipboard = (android.content.ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE); android.content.ClipData clip = android.content.ClipData.newPlainText( "Gpslogger error message", getFormattedErrorMessageForPlainText(errorMessage, throwable)); clipboard.setPrimaryClip(clip); materialDialog.dismiss(); } }) .onPositive( new MaterialDialog.SingleButtonCallback() { @Override public void onClick( @NonNull MaterialDialog materialDialog, @NonNull DialogAction dialogAction) { materialDialog.dismiss(); } }) .build(); final ExpandableTextView expTv1 = (ExpandableTextView) alertDialog.getCustomView().findViewById(R.id.error_expand_text_view); expTv1.setText(Html.fromHtml(messageFormatted)); TextView tv = (TextView) expTv1.findViewById(R.id.expandable_text); tv.setMovementMethod(LinkMovementMethod.getInstance()); TextView tvFriendly = (TextView) alertDialog.getCustomView().findViewById(R.id.error_friendly_message); tvFriendly.setText(friendlyMessage); if (context instanceof Activity && !((Activity) context).isFinishing()) { alertDialog.show(); } else { alertDialog.show(); } }
@Override public void onDownloadStarted() { downloadDialog.show(); }
/** * 显示剂量编辑框的dialog * * @param view1 显示剂量编辑框 * @param viewheshu1 显示剂量单位编辑框 * @param view2 显示盒数的编辑框 * @param viewheshu2 显示规格的编辑框 * @param nextView 下一个要弹出的spinner */ public void showEditDialog( final View view1, final View viewheshu1, final View view2, final View viewheshu2, final View nextView) { if (!(view1 instanceof TextView) || !(viewheshu1 instanceof TextView)) { return; } if (!(view2 instanceof TextView) || !(viewheshu2 instanceof TextView)) { return; } View rootView = getActivity().getLayoutInflater().inflate(R.layout.dialog_number_complex, null); final NumberPicker np1 = (NumberPicker) rootView.findViewById(R.id.np_dialog_complex1); final NumberPicker np2 = (NumberPicker) rootView.findViewById(R.id.np_dialog_complex2); final NumberPicker np3 = (NumberPicker) rootView.findViewById(R.id.np_dialog_complex3); final NumberPicker np4 = (NumberPicker) rootView.findViewById(R.id.np_dialog_complex4); final TextView tvDian = (TextView) rootView.findViewById(R.id.tv_dialog_complex_dian); final NumberPicker little = (NumberPicker) rootView.findViewById(R.id.np_dialog_complex_little); final EditText et = (EditText) rootView.findViewById(R.id.et_dialog_complex); IllnessInfo illnessInfo = (IllnessInfo) spinnerTellMedical3.getSelectedItem(); // 诺和力剂量需要小数点 if (illnessInfo.getId().equals("1022")) { tvDian.setVisibility(View.VISIBLE); little.setVisibility(View.VISIBLE); } final TextView tv = (TextView) rootView.findViewById(R.id.tv_dialog_dost); final NumberPicker np5 = (NumberPicker) rootView.findViewById(R.id.np_dialog_complex5); final NumberPicker np6 = (NumberPicker) rootView.findViewById(R.id.np_dialog_complex6); final NumberPicker np7 = (NumberPicker) rootView.findViewById(R.id.np_dialog_complex7); np1.setMaxValue(5); np1.setMinValue(0); np2.setMaxValue(9); np2.setMinValue(0); np3.setMaxValue(9); np3.setMinValue(0); little.setMinValue(0); little.setMaxValue(9); np5.setMaxValue(5); np5.setMinValue(0); np6.setMaxValue(9); np6.setMinValue(0); np7.setMaxValue(9); np7.setMinValue(0); // 设置规格的数据 if (!TextUtils.isEmpty(((TextView) viewheshu2).getText())) { tv.setText(((TextView) viewheshu2).getText()); } // 如果剂量数值是double类型 if (CommonUtil.isStr2Num(((TextView) view1).getText().toString())) { final double defaultValues1 = TextUtils.isEmpty(((TextView) view1).getText()) ? 000.00 : Double.parseDouble(((TextView) view1).getText().toString()); np1.setValue((int) (defaultValues1 / 100)); np2.setValue((int) (defaultValues1 * 100 % 10000 / 1000)); np3.setValue((int) (defaultValues1 * 100 % 1000 / 100)); little.setValue((int) (defaultValues1 * 100 % 100 / 10)); } else { et.setText(((TextView) view1).getText()); } // 如果固定单位数组中没有新的,则添加 if (!defaultDost.contains(((TextView) viewheshu1).getText())) { defaultDost.add(((TextView) viewheshu1).getText().toString()); } // 默认的索引 int index = defaultDost.indexOf(((TextView) viewheshu1).getText().toString()); np4.setDisplayedValues(defaultDost.toArray(new String[defaultDost.size()])); np4.setMinValue(0); np4.setMaxValue(defaultDost.size() - 1); np4.setValue(index); final double defaultValues2 = TextUtils.isEmpty(((TextView) view2).getText()) ? 000.00 : Double.parseDouble(((TextView) view2).getText().toString()); np5.setValue((int) (defaultValues2 / 100)); np6.setValue((int) (defaultValues2 * 100 % 10000 / 1000)); np7.setValue((int) (defaultValues2 * 100 % 1000 / 100)); MaterialDialog dialog = new MaterialDialog.Builder(getActivity()) .customView(rootView, false) .autoDismiss(false) .cancelable(false) .positiveText("确定") .negativeText("取消") .neutralText("重置") .onPositive( new MaterialDialog.SingleButtonCallback() { @Override public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) { String aValue1, aValue1_dian = "", aValue2; if (view1 instanceof TextView && view2 instanceof TextView) { // 格式化小数点之前的数 if (np1.getValue() == 0) { if (np2.getValue() == 0) { aValue1 = String.valueOf(np3.getValue()); } else { aValue1 = String.valueOf(np2.getValue()) + String.valueOf(np3.getValue()); } } else { aValue1 = String.valueOf(np1.getValue()) + String.valueOf(np2.getValue()) + String.valueOf(np3.getValue()); } // 格式化小数点之后的数 if (little.getValue() != 0) { aValue1_dian = "." + little.getValue(); } // 格式化小数点之前的数 if (np5.getValue() == 0) { if (np6.getValue() == 0) { aValue2 = String.valueOf(np7.getValue()); } else { aValue2 = String.valueOf(np6.getValue()) + String.valueOf(np7.getValue()); } } else { aValue2 = String.valueOf(np5.getValue()) + String.valueOf(np6.getValue()) + String.valueOf(np7.getValue()); } ((TextView) view1).setText(aValue1 + aValue1_dian); ((TextView) view2).setText(aValue2); CommonUtil.hideSoftInputView(getActivity(), np1); CommonUtil.hideSoftInputView(getActivity(), np2); CommonUtil.hideSoftInputView(getActivity(), np3); CommonUtil.hideSoftInputView(getActivity(), np4); CommonUtil.hideSoftInputView(getActivity(), np5); CommonUtil.hideSoftInputView(getActivity(), np6); CommonUtil.hideSoftInputView(getActivity(), np7); dialog.dismiss(); if (!TextUtils.isEmpty(et.getText())) { ((TextView) view1).setText(et.getText()); } else { spinnerTellMedical6.setAdapter( new ArrayAdapter<>( getActivity(), R.layout.spinner_list_item, getResources().getStringArray(R.array.medic_blfy))); nextView.performClick(); } } } }) .onNeutral( new MaterialDialog.SingleButtonCallback() { @Override public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) { np1.setValue(0); np2.setValue(0); np3.setValue(0); np5.setValue(0); np6.setValue(0); np7.setValue(0); et.setText(""); } }) .onNegative( new MaterialDialog.SingleButtonCallback() { @Override public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) { CommonUtil.hideSoftInputView(getActivity(), np1); CommonUtil.hideSoftInputView(getActivity(), np2); CommonUtil.hideSoftInputView(getActivity(), np3); CommonUtil.hideSoftInputView(getActivity(), np4); CommonUtil.hideSoftInputView(getActivity(), np5); CommonUtil.hideSoftInputView(getActivity(), np6); CommonUtil.hideSoftInputView(getActivity(), np7); CommonUtil.hideSoftInputView(getActivity(), et); dialog.dismiss(); } }) .build(); dialog.show(); // 关闭自动弹出输入法 CommonUtil.resetDialogParam(getActivity(), dialog); }
/** * A dialog fragment that allows picking a label or entering a new label to set this new label to * the torrent. * * @param context The activity context that opens (and owns) this dialog * @param onLabelPickedListener The callback when a new label has been entered or picked by the * user * @param currentLabels The list of labels as currently exist on the server, to present as list * for easy selection */ public static void show( final Context context, final OnLabelPickedListener onLabelPickedListener, List<Label> currentLabels) { // Discard the empty label in this list before storing it locally for (Iterator<Label> iter = currentLabels.iterator(); iter.hasNext(); ) { if (iter.next().isEmptyLabel()) { iter.remove(); } } final View setLabelLayout = LayoutInflater.from(context).inflate(R.layout.dialog_setlabel, null); final ListView labelsList = (ListView) setLabelLayout.findViewById(R.id.labels_list); final EditText newLabelEdit = (EditText) setLabelLayout.findViewById(R.id.newlabel_edit); final MaterialDialog dialog = new MaterialDialog.Builder(context) .customView(setLabelLayout, false) .positiveText(R.string.status_update) .neutralText(R.string.status_label_remove) .negativeText(android.R.string.cancel) .callback( new MaterialDialog.ButtonCallback() { @Override public void onPositive(MaterialDialog dialog) { // User should have provided a new label if (TextUtils.isEmpty(newLabelEdit.getText())) { SnackbarManager.show( Snackbar.with(context) .text(R.string.error_notalabel) .colorResource(R.color.red)); return; } onLabelPickedListener.onLabelPicked(newLabelEdit.getText().toString()); } @Override public void onNeutral(MaterialDialog dialog) { onLabelPickedListener.onLabelPicked(null); } }) .theme(SystemSettings_.getInstance_(context).getMaterialDialogtheme()) .build(); if (currentLabels.size() == 0) { // Hide the list (and its label) if there are no labels yet setLabelLayout.findViewById(R.id.pick_label).setVisibility(View.GONE); labelsList.setVisibility(View.GONE); } else { labelsList.setAdapter(new FilterListItemAdapter(context, currentLabels)); labelsList.setOnItemClickListener( new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { onLabelPickedListener.onLabelPicked( ((Label) labelsList.getItemAtPosition(position)).getName()); dialog.dismiss(); } }); } dialog.show(); }
@Override public boolean onOptionsItemSelected(MenuItem item) { int id = item.getItemId(); // override default back button present on the toolbar if (id == android.R.id.home) { onBackPressed(); return true; } if (id == R.id.action_refresh) { if (NetworkConnectionUtil.isNetworkAvailable(ArticleActivity.this)) { mArticlePresenter.attemptArticleLoading(getFeedItem().getItemLink()); } else { NetworkConnectionUtil.showNoNetworkDialog(ArticleActivity.this); } return true; } if (id == R.id.action_share) { Intent intent = new Intent(Intent.ACTION_SEND); intent.putExtra(Intent.EXTRA_SUBJECT, getFeedItem().getItemTitle()); intent.putExtra( Intent.EXTRA_TEXT, getFeedItem().getItemLink() + "\n\n" + txtContent.getText().toString()); intent.setType("text/plain"); startActivity(intent); return true; } if (id == R.id.action_open_in_browser) { // Use chrome custom tabs if user wants in-app browser, otherwise use user's own selected // browser for opening links if (SettingsPreferences.IN_APP_BROWSER) { new WebsiteIntentUtil(ArticleActivity.this) .loadCustomChromeTabs(getFeedItem().getItemLink()); } else { new WebsiteIntentUtil(ArticleActivity.this).loadNormalBrowser(getFeedItem().getItemLink()); } return true; } if (id == R.id.action_delete) { MaterialDialog confirmDeleteDialog = new MaterialDialog.Builder(this) .title(R.string.delete_this_feed) .content(R.string.delete_this_feed_desc) .iconRes(R.drawable.ic_delete_24dp) .positiveText(R.string.delete) .negativeText(R.string.cancel) .onPositive( new MaterialDialog.SingleButtonCallback() { @Override public void onClick(MaterialDialog materialDialog, DialogAction dialogAction) { mFeedsPresenter.deleteSelectedFeed(getFeedItem()); Intent intent = new Intent(ArticleActivity.this, HomeActivity.class); startActivity(intent); finish(); } }) .build(); confirmDeleteDialog.show(); return true; } return super.onOptionsItemSelected(item); }
@Override protected void showDialog(Bundle state) { List<Integer> indices = new ArrayList<>(); for (String s : getValues()) { int index = findIndexOfValue(s); if (index >= 0) indices.add(findIndexOfValue(s)); } MaterialDialog.Builder builder = new MaterialDialog.Builder(context) .title(getDialogTitle()) .icon(getDialogIcon()) .negativeText(getNegativeButtonText()) .positiveText(getPositiveButtonText()) .onAny( new MaterialDialog.SingleButtonCallback() { @Override public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) { switch (which) { default: MaterialMultiSelectListPreference.this.onClick( dialog, DialogInterface.BUTTON_POSITIVE); break; case NEUTRAL: MaterialMultiSelectListPreference.this.onClick( dialog, DialogInterface.BUTTON_NEUTRAL); break; case NEGATIVE: MaterialMultiSelectListPreference.this.onClick( dialog, DialogInterface.BUTTON_NEGATIVE); break; } } }) .items(getEntries()) .itemsCallbackMultiChoice( indices.toArray(new Integer[indices.size()]), new MaterialDialog.ListCallbackMultiChoice() { @Override public boolean onSelection( MaterialDialog dialog, Integer[] which, CharSequence[] text) { onClick(null, DialogInterface.BUTTON_POSITIVE); dialog.dismiss(); final Set<String> values = new HashSet<>(); for (int i : which) { values.add(getEntryValues()[i].toString()); } if (callChangeListener(values)) setValues(values); return true; } }) .dismissListener(this); final View contentView = onCreateDialogView(); if (contentView != null) { onBindDialogView(contentView); builder.customView(contentView, false); } else { builder.content(getDialogMessage()); } PrefUtil.registerOnActivityDestroyListener(this, this); mDialog = builder.build(); if (state != null) mDialog.onRestoreInstanceState(state); mDialog.show(); }
@Override public boolean onLongClick(View v) { final Point pointToAdd = new Point(new LatLng(-31.90, 115.86), "Point " + route.getPointsNumber(), false); final MaterialDialog dialog = new MaterialDialog.Builder(this) .title(R.string.new_point) .titleColor(getResources().getColor(R.color.colorAccent)) .customView(R.layout.dialog_new_point_define, true) .positiveText(R.string.add) .backgroundColorRes(R.color.background) .negativeText(android.R.string.cancel) .onPositive( new MaterialDialog.SingleButtonCallback() { @Override public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) { if (pointToAdd.getPosition().latitude != -31.90 && pointToAdd.getPosition().longitude != 115.86) { route.addPoint(pointToAdd); MapUtilities.drawPathOnMap(mMap, route, getResources()); robotMarker = MapUtilities.placeRobotMarkerOnMap( robotMarker, mMap, Utilities.convertLocationToLatLng(robotLocation), true, getResources(), getApplicationContext()); dialog.dismiss(); } else { Toast.makeText( getApplicationContext(), "Please define coordinates for the new Point", Toast.LENGTH_SHORT) .show(); } } }) .build(); final EditText etLatitude = (EditText) dialog.getCustomView().findViewById(R.id.etLatitude); final EditText etLongitude = (EditText) dialog.getCustomView().findViewById(R.id.etLongitude); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { etLatitude.setTextColor(getColor(R.color.green)); etLongitude.setTextColor(getColor(R.color.colorPrimaryDark)); } etLatitude.addTextChangedListener( new TextWatcher() { @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) {} @Override public void onTextChanged(CharSequence s, int start, int before, int count) {} @Override public void afterTextChanged(Editable s) { pointToAdd.setPosition( new LatLng(Double.parseDouble(s.toString()), pointToAdd.getPosition().longitude)); } }); etLongitude.addTextChangedListener( new TextWatcher() { @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) {} @Override public void onTextChanged(CharSequence s, int start, int before, int count) {} @Override public void afterTextChanged(Editable s) { pointToAdd.setPosition( new LatLng(pointToAdd.getPosition().latitude, Double.parseDouble(s.toString()))); } }); dialog.show(); return false; }