|
@@ -1,16 +1,19 @@
|
|
|
package com.afollestad.materialdialogs;
|
|
|
|
|
|
import android.content.Context;
|
|
|
+import android.content.DialogInterface;
|
|
|
import android.content.res.ColorStateList;
|
|
|
import android.content.res.Resources;
|
|
|
import android.content.res.TypedArray;
|
|
|
import android.graphics.Color;
|
|
|
+import android.graphics.PorterDuff;
|
|
|
import android.graphics.drawable.Drawable;
|
|
|
import android.os.Build;
|
|
|
import android.text.method.LinkMovementMethod;
|
|
|
import android.view.ContextThemeWrapper;
|
|
|
import android.view.View;
|
|
|
import android.view.ViewGroup;
|
|
|
+import android.view.inputmethod.InputMethodManager;
|
|
|
import android.widget.EditText;
|
|
|
import android.widget.FrameLayout;
|
|
|
import android.widget.ImageView;
|
|
@@ -53,10 +56,12 @@ class DialogInit {
|
|
|
return R.layout.md_dialog_custom;
|
|
|
} else if (builder.items != null && builder.items.length > 0 || builder.adapter != null) {
|
|
|
return R.layout.md_dialog_list;
|
|
|
- } else if (builder.mProgress > -2) {
|
|
|
+ } else if (builder.progress > -2) {
|
|
|
return R.layout.md_dialog_progress;
|
|
|
- } else if (builder.mIndeterminateProgress) {
|
|
|
+ } else if (builder.indeterminateProgress) {
|
|
|
return R.layout.md_dialog_progress_indeterminate;
|
|
|
+ } else if (builder.inputCallback != null) {
|
|
|
+ return R.layout.md_dialog_input;
|
|
|
} else {
|
|
|
return R.layout.md_dialog_basic;
|
|
|
}
|
|
@@ -120,6 +125,9 @@ class DialogInit {
|
|
|
dialog.neutralButton = (MDButton) dialog.view.findViewById(R.id.buttonDefaultNeutral);
|
|
|
dialog.negativeButton = (MDButton) dialog.view.findViewById(R.id.buttonDefaultNegative);
|
|
|
|
|
|
+ if (builder.inputCallback != null && builder.positiveText == null)
|
|
|
+ builder.positiveText = builder.context.getString(android.R.string.ok);
|
|
|
+
|
|
|
// Set up the initial visibility of action buttons based on whether or not text was set
|
|
|
dialog.positiveButton.setVisibility(builder.positiveText != null ? View.VISIBLE : View.GONE);
|
|
|
dialog.neutralButton.setVisibility(builder.neutralText != null ? View.VISIBLE : View.GONE);
|
|
@@ -204,6 +212,7 @@ class DialogInit {
|
|
|
} else {
|
|
|
textAllCaps = DialogUtils.resolveBoolean(builder.context, R.attr.textAllCaps, true);
|
|
|
}
|
|
|
+
|
|
|
if (dialog.positiveButton != null && builder.positiveText != null) {
|
|
|
MDButton positiveTextView = dialog.positiveButton;
|
|
|
dialog.setTypeface(positiveTextView, builder.mediumFont);
|
|
@@ -280,6 +289,10 @@ class DialogInit {
|
|
|
// Setup progress dialog stuff if needed
|
|
|
setupProgressDialog(dialog);
|
|
|
|
|
|
+ // Setup inputu dialog stuff if needed
|
|
|
+ setupInputDialog(dialog);
|
|
|
+
|
|
|
+ // Setup custom views
|
|
|
if (builder.customView != null) {
|
|
|
FrameLayout frame = (FrameLayout) dialog.view.findViewById(R.id.customViewFrame);
|
|
|
dialog.customViewFrame = frame;
|
|
@@ -329,18 +342,19 @@ class DialogInit {
|
|
|
|
|
|
private static void setupProgressDialog(final MaterialDialog dialog) {
|
|
|
final MaterialDialog.Builder builder = dialog.mBuilder;
|
|
|
- if (builder.mIndeterminateProgress || builder.mProgress > -2) {
|
|
|
+ if (builder.indeterminateProgress || builder.progress > -2) {
|
|
|
dialog.mProgress = (MDProgressBar) dialog.view.findViewById(android.R.id.progress);
|
|
|
+ if (dialog.mProgress == null) return;
|
|
|
dialog.mProgress.setColorFilter(builder.widgetColor);
|
|
|
|
|
|
- if (!builder.mIndeterminateProgress) {
|
|
|
+ if (!builder.indeterminateProgress) {
|
|
|
dialog.mProgress.setProgress(0);
|
|
|
- dialog.mProgress.setMax(builder.mProgressMax);
|
|
|
+ dialog.mProgress.setMax(builder.progressMax);
|
|
|
dialog.mProgressLabel = (TextView) dialog.view.findViewById(R.id.label);
|
|
|
dialog.mProgressMinMax = (TextView) dialog.view.findViewById(R.id.minMax);
|
|
|
- if (builder.mShowMinMax) {
|
|
|
+ if (builder.showMinMax) {
|
|
|
dialog.mProgressMinMax.setVisibility(View.VISIBLE);
|
|
|
- dialog.mProgressMinMax.setText("0/" + builder.mProgressMax);
|
|
|
+ dialog.mProgressMinMax.setText("0/" + builder.progressMax);
|
|
|
ViewGroup.MarginLayoutParams lp = (ViewGroup.MarginLayoutParams) dialog.mProgress.getLayoutParams();
|
|
|
lp.leftMargin = 0;
|
|
|
lp.rightMargin = 0;
|
|
@@ -349,10 +363,72 @@ class DialogInit {
|
|
|
}
|
|
|
dialog.mProgressLabel.setText("0%");
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ private static void setupInputDialog(final MaterialDialog dialog) {
|
|
|
+ final MaterialDialog.Builder builder = dialog.mBuilder;
|
|
|
+ dialog.input = (EditText) dialog.view.findViewById(android.R.id.input);
|
|
|
+ if (dialog.input == null) return;
|
|
|
+ if (builder.inputPrefill != null)
|
|
|
+ dialog.input.append(builder.inputPrefill);
|
|
|
+ dialog.input.setHint(builder.inputHint);
|
|
|
+ dialog.input.setSingleLine();
|
|
|
+
|
|
|
+ dialog.setOnShowListener(new DialogInterface.OnShowListener() {
|
|
|
+ @Override
|
|
|
+ public void onShow(DialogInterface di) {
|
|
|
+ final MaterialDialog dialog = (MaterialDialog) di;
|
|
|
+ if (dialog.getInputEditText() == null) return;
|
|
|
+ dialog.getInputEditText().post(new Runnable() {
|
|
|
+ @Override
|
|
|
+ public void run() {
|
|
|
+ dialog.getInputEditText().requestFocus();
|
|
|
+ InputMethodManager imm = (InputMethodManager) builder.context.getSystemService(Context.INPUT_METHOD_SERVICE);
|
|
|
+ if (imm != null)
|
|
|
+ imm.showSoftInput(dialog.getInputEditText(), InputMethodManager.SHOW_IMPLICIT);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ });
|
|
|
+ dialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
|
|
|
+ @Override
|
|
|
+ public void onCancel(DialogInterface di) {
|
|
|
+ final MaterialDialog dialog = (MaterialDialog) di;
|
|
|
+ if (dialog.getInputEditText() == null) return;
|
|
|
+ dialog.getInputEditText().post(new Runnable() {
|
|
|
+ @Override
|
|
|
+ public void run() {
|
|
|
+ dialog.getInputEditText().requestFocus();
|
|
|
+ InputMethodManager imm = (InputMethodManager) builder.context.getSystemService(Context.INPUT_METHOD_SERVICE);
|
|
|
+ imm.hideSoftInputFromWindow(dialog.getInputEditText().getWindowToken(), 0);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ });
|
|
|
+ dialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
|
|
|
+ @Override
|
|
|
+ public void onDismiss(DialogInterface di) {
|
|
|
+ final MaterialDialog dialog = (MaterialDialog) di;
|
|
|
+ if (dialog.getInputEditText() == null) return;
|
|
|
+ dialog.getInputEditText().post(new Runnable() {
|
|
|
+ @Override
|
|
|
+ public void run() {
|
|
|
+ dialog.getInputEditText().requestFocus();
|
|
|
+ InputMethodManager imm = (InputMethodManager) builder.context.getSystemService(Context.INPUT_METHOD_SERVICE);
|
|
|
+ if (imm != null)
|
|
|
+ imm.hideSoftInputFromWindow(dialog.getInputEditText().getWindowToken(), 0);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
|
|
|
+ dialog.input.setBackgroundTintList(ColorStateList.valueOf(builder.widgetColor));
|
|
|
+ else if (dialog.input.getBackground() != null)
|
|
|
+ dialog.input.getBackground().setColorFilter(builder.widgetColor, PorterDuff.Mode.SRC_IN);
|
|
|
+ }
|
|
|
+
|
|
|
private static ColorStateList getActionTextStateList(Context context, int newPrimaryColor) {
|
|
|
final int fallBackButtonColor = DialogUtils.resolveColor(context, android.R.attr.textColorPrimary);
|
|
|
if (newPrimaryColor == 0) newPrimaryColor = fallBackButtonColor;
|