Aidan Follestad 7 anos atrás
pai
commit
333c856a68

+ 8 - 3
core/src/main/java/com/afollestad/materialdialogs/DefaultRvAdapter.java

@@ -5,6 +5,7 @@ import android.annotation.TargetApi;
 import android.content.res.Configuration;
 import android.os.Build;
 import android.support.annotation.LayoutRes;
+import android.support.annotation.Nullable;
 import android.support.v7.widget.RecyclerView;
 import android.view.Gravity;
 import android.view.LayoutInflater;
@@ -171,7 +172,11 @@ class DefaultRvAdapter extends RecyclerView.Adapter<DefaultRvAdapter.DefaultVH>
   interface InternalListCallback {
 
     boolean onItemSelected(
-        MaterialDialog dialog, View itemView, int position, CharSequence text, boolean longPress);
+        MaterialDialog dialog,
+        View itemView,
+        int position,
+        @Nullable CharSequence text,
+        boolean longPress);
   }
 
   static class DefaultVH extends RecyclerView.ViewHolder
@@ -183,8 +188,8 @@ class DefaultRvAdapter extends RecyclerView.Adapter<DefaultRvAdapter.DefaultVH>
 
     DefaultVH(View itemView, DefaultRvAdapter adapter) {
       super(itemView);
-      control = (CompoundButton) itemView.findViewById(R.id.md_control);
-      title = (TextView) itemView.findViewById(R.id.md_title);
+      control = itemView.findViewById(R.id.md_control);
+      title = itemView.findViewById(R.id.md_title);
       this.adapter = adapter;
       itemView.setOnClickListener(this);
       if (adapter.dialog.builder.listLongCallback != null) {

+ 47 - 145
core/src/main/java/com/afollestad/materialdialogs/MaterialDialog.java

@@ -57,6 +57,7 @@ import java.util.List;
 import java.util.Locale;
 
 /** @author Aidan Follestad (afollestad) */
+@SuppressWarnings({"WeakerAccess", "SameParameterValue", "unused"})
 public class MaterialDialog extends DialogBase
     implements View.OnClickListener, DefaultRvAdapter.InternalListCallback {
 
@@ -95,7 +96,7 @@ public class MaterialDialog extends DialogBase
     return builder;
   }
 
-  public final void setTypeface(TextView target, Typeface t) {
+  public final void setTypeface(TextView target, @Nullable Typeface t) {
     if (t == null) {
       return;
     }
@@ -104,7 +105,6 @@ public class MaterialDialog extends DialogBase
     target.setTypeface(t);
   }
 
-  @SuppressWarnings("unused")
   @Nullable
   public Object getTag() {
     return builder.tag;
@@ -204,10 +204,12 @@ public class MaterialDialog extends DialogBase
         }
         final boolean shouldBeChecked = !selectedIndicesList.contains(position);
         if (shouldBeChecked) {
-          // Add the selection to the states first so the callback includes it (when alwaysCallMultiChoiceCallback)
+          // Add the selection to the states first so the callback includes it (when
+          // alwaysCallMultiChoiceCallback)
           selectedIndicesList.add(position);
           if (builder.alwaysCallMultiChoiceCallback) {
-            // If the checkbox wasn't previously selected, and the callback returns true, add it to the states and check it
+            // If the checkbox wasn't previously selected, and the callback returns true, add it to
+            // the states and check it
             if (sendMultiChoiceCallback()) {
               cb.setChecked(true);
             } else {
@@ -219,10 +221,12 @@ public class MaterialDialog extends DialogBase
             cb.setChecked(true);
           }
         } else {
-          // Remove the selection from the states first so the callback does not include it (when alwaysCallMultiChoiceCallback)
+          // Remove the selection from the states first so the callback does not include it (when
+          // alwaysCallMultiChoiceCallback)
           selectedIndicesList.remove(Integer.valueOf(position));
           if (builder.alwaysCallMultiChoiceCallback) {
-            // If the checkbox was previously selected, and the callback returns true, remove it from the states and uncheck it
+            // If the checkbox was previously selected, and the callback returns true, remove it
+            // from the states and uncheck it
             if (sendMultiChoiceCallback()) {
               cb.setChecked(false);
             } else {
@@ -243,7 +247,8 @@ public class MaterialDialog extends DialogBase
         final int oldSelected = builder.selectedIndex;
 
         if (builder.autoDismiss && builder.positiveText == null) {
-          // If auto dismiss is enabled, and no action button is visible to approve the selection, dismiss the dialog
+          // If auto dismiss is enabled, and no action button is visible to approve the selection,
+          // dismiss the dialog
           dismiss();
           // Don't allow the selection to be updated since the dialog is being dismissed anyways
           allowSelection = false;
@@ -290,7 +295,6 @@ public class MaterialDialog extends DialogBase
     return checkBoxPrompt != null && checkBoxPrompt.isChecked();
   }
 
-  @SuppressWarnings("unused")
   public void setPromptCheckBoxChecked(boolean checked) {
     if (checkBoxPrompt != null) {
       checkBoxPrompt.setChecked(checked);
@@ -400,56 +404,38 @@ public class MaterialDialog extends DialogBase
     DialogAction tag = (DialogAction) v.getTag();
     switch (tag) {
       case POSITIVE:
-        {
-          if (builder.callback != null) {
-            builder.callback.onAny(this);
-            builder.callback.onPositive(this);
-          }
-          if (builder.onPositiveCallback != null) {
-            builder.onPositiveCallback.onClick(this, tag);
-          }
-          if (!builder.alwaysCallSingleChoiceCallback) {
-            sendSingleChoiceCallback(v);
-          }
-          if (!builder.alwaysCallMultiChoiceCallback) {
-            sendMultiChoiceCallback();
-          }
-          if (builder.inputCallback != null && input != null && !builder.alwaysCallInputCallback) {
-            builder.inputCallback.onInput(this, input.getText());
-          }
-          if (builder.autoDismiss) {
-            dismiss();
-          }
-          break;
+        if (builder.onPositiveCallback != null) {
+          builder.onPositiveCallback.onClick(this, tag);
+        }
+        if (!builder.alwaysCallSingleChoiceCallback) {
+          sendSingleChoiceCallback(v);
         }
+        if (!builder.alwaysCallMultiChoiceCallback) {
+          sendMultiChoiceCallback();
+        }
+        if (builder.inputCallback != null && input != null && !builder.alwaysCallInputCallback) {
+          builder.inputCallback.onInput(this, input.getText());
+        }
+        if (builder.autoDismiss) {
+          dismiss();
+        }
+        break;
       case NEGATIVE:
-        {
-          if (builder.callback != null) {
-            builder.callback.onAny(this);
-            builder.callback.onNegative(this);
-          }
-          if (builder.onNegativeCallback != null) {
-            builder.onNegativeCallback.onClick(this, tag);
-          }
-          if (builder.autoDismiss) {
-            cancel();
-          }
-          break;
+        if (builder.onNegativeCallback != null) {
+          builder.onNegativeCallback.onClick(this, tag);
         }
+        if (builder.autoDismiss) {
+          cancel();
+        }
+        break;
       case NEUTRAL:
-        {
-          if (builder.callback != null) {
-            builder.callback.onAny(this);
-            builder.callback.onNeutral(this);
-          }
-          if (builder.onNeutralCallback != null) {
-            builder.onNeutralCallback.onClick(this, tag);
-          }
-          if (builder.autoDismiss) {
-            dismiss();
-          }
-          break;
+        if (builder.onNeutralCallback != null) {
+          builder.onNeutralCallback.onClick(this, tag);
         }
+        if (builder.autoDismiss) {
+          dismiss();
+        }
+        break;
     }
     if (builder.onAnyCallback != null) {
       builder.onAnyCallback.onClick(this, tag);
@@ -501,13 +487,11 @@ public class MaterialDialog extends DialogBase
    * Retrieves the TextView that contains the dialog title. If you want to update the title, use
    * #{@link #setTitle(CharSequence)} instead.
    */
-  @SuppressWarnings("unused")
   public final TextView getTitleView() {
     return title;
   }
 
   /** Retrieves the ImageView that contains the dialog icon. */
-  @SuppressWarnings("unused")
   public ImageView getIconView() {
     return icon;
   }
@@ -517,7 +501,6 @@ public class MaterialDialog extends DialogBase
    * (message), use #{@link #setContent(CharSequence)} instead.
    */
   @Nullable
-  @SuppressWarnings("unused")
   public final TextView getContentView() {
     return content;
   }
@@ -539,9 +522,8 @@ public class MaterialDialog extends DialogBase
    * @param which The action button to update.
    * @param title The new title of the action button.
    */
-  @SuppressWarnings("WeakerAccess")
   @UiThread
-  public final void setActionButton(final DialogAction which, final CharSequence title) {
+  public final void setActionButton(final DialogAction which, @Nullable final CharSequence title) {
     switch (which) {
       default:
         builder.positiveText = title;
@@ -613,7 +595,6 @@ public class MaterialDialog extends DialogBase
     setTitle(builder.context.getString(newTitleRes));
   }
 
-  @SuppressWarnings("unused")
   @UiThread
   public final void setTitle(@StringRes int newTitleRes, @Nullable Object... formatArgs) {
     setTitle(builder.context.getString(newTitleRes, formatArgs));
@@ -626,12 +607,11 @@ public class MaterialDialog extends DialogBase
   }
 
   @UiThread
-  public void setIcon(final Drawable d) {
+  public void setIcon(@Nullable final Drawable d) {
     icon.setImageDrawable(d);
     icon.setVisibility(d != null ? View.VISIBLE : View.GONE);
   }
 
-  @SuppressWarnings("unused")
   @UiThread
   public void setIconAttribute(@AttrRes int attrId) {
     Drawable d = DialogUtils.resolveDrawable(builder.context, attrId);
@@ -649,7 +629,6 @@ public class MaterialDialog extends DialogBase
     setContent(builder.context.getString(newContentRes));
   }
 
-  @SuppressWarnings("unused")
   @UiThread
   public final void setContent(@StringRes int newContentRes, @Nullable Object... formatArgs) {
     setContent(builder.context.getString(newContentRes, formatArgs));
@@ -661,7 +640,7 @@ public class MaterialDialog extends DialogBase
   }
 
   @UiThread
-  public final void setItems(CharSequence... items) {
+  public final void setItems(@Nullable CharSequence... items) {
     if (builder.adapter == null) {
       throw new IllegalStateException(
           "This MaterialDialog instance does not "
@@ -686,7 +665,6 @@ public class MaterialDialog extends DialogBase
     builder.adapter.notifyItemInserted(index);
   }
 
-  @SuppressWarnings("unused")
   @UiThread
   public final void notifyItemChanged(@IntRange(from = 0, to = Integer.MAX_VALUE) int index) {
     builder.adapter.notifyItemChanged(index);
@@ -704,7 +682,6 @@ public class MaterialDialog extends DialogBase
     return progressBar.getProgress();
   }
 
-  @SuppressWarnings("unused")
   public ProgressBar getProgressBar() {
     return progressBar;
   }
@@ -740,7 +717,6 @@ public class MaterialDialog extends DialogBase
         });
   }
 
-  @SuppressWarnings("unused")
   public final boolean isIndeterminateProgress() {
     return builder.indeterminateProgress;
   }
@@ -752,7 +728,6 @@ public class MaterialDialog extends DialogBase
     return progressBar.getMax();
   }
 
-  @SuppressWarnings("unused")
   public final void setMaxProgress(final int max) {
     if (builder.progress <= -2) {
       throw new IllegalStateException("Cannot use setMaxProgress() on this dialog.");
@@ -764,7 +739,6 @@ public class MaterialDialog extends DialogBase
    * Change the format of the small text showing the percentage of progress. The default is
    * NumberFormat.getPercentageInstance().
    */
-  @SuppressWarnings("unused")
   public final void setProgressPercentFormat(NumberFormat format) {
     builder.progressPercentFormat = format;
     setProgress(getCurrentProgress()); // invalidates display
@@ -774,7 +748,6 @@ public class MaterialDialog extends DialogBase
    * Change the format of the small text showing current and maximum units of progress. The default
    * is "%1d/%2d".
    */
-  @SuppressWarnings("unused")
   public final void setProgressNumberFormat(String format) {
     builder.progressNumberFormat = format;
     setProgress(getCurrentProgress()); // invalidates display
@@ -790,7 +763,6 @@ public class MaterialDialog extends DialogBase
    * @return Currently selected index of a single choice list, or -1 if not showing a single choice
    *     list
    */
-  @SuppressWarnings("unused")
   public int getSelectedIndex() {
     if (builder.listCallbackSingleChoice != null) {
       return builder.selectedIndex;
@@ -808,7 +780,6 @@ public class MaterialDialog extends DialogBase
    * @param index The index of the list item to check.
    */
   @UiThread
-  @SuppressWarnings("unused")
   public void setSelectedIndex(int index) {
     builder.selectedIndex = index;
     if (builder.adapter != null && builder.adapter instanceof DefaultRvAdapter) {
@@ -826,7 +797,6 @@ public class MaterialDialog extends DialogBase
    *     list
    */
   @Nullable
-  @SuppressWarnings("unused")
   public Integer[] getSelectedIndices() {
     if (builder.listCallbackMultiChoice != null) {
       return selectedIndicesList.toArray(new Integer[selectedIndicesList.size()]);
@@ -844,7 +814,6 @@ public class MaterialDialog extends DialogBase
    * @param indices The indices of the list items to check.
    */
   @UiThread
-  @SuppressWarnings("unused")
   public void setSelectedIndices(Integer[] indices) {
     selectedIndicesList = new ArrayList<>(Arrays.asList(indices));
     if (builder.adapter != null && builder.adapter instanceof DefaultRvAdapter) {
@@ -865,7 +834,6 @@ public class MaterialDialog extends DialogBase
    *
    * @param sendCallback Defaults to true. True will notify the multi-choice callback, if any.
    */
-  @SuppressWarnings("WeakerAccess")
   public void clearSelectedIndices(boolean sendCallback) {
     if (listType == null || listType != ListType.MULTI) {
       throw new IllegalStateException(
@@ -886,7 +854,6 @@ public class MaterialDialog extends DialogBase
   }
 
   /** Selects all checkboxes in multi choice list dialogs. */
-  @SuppressWarnings("unused")
   public void selectAllIndices() {
     selectAllIndices(true);
   }
@@ -896,7 +863,6 @@ public class MaterialDialog extends DialogBase
    *
    * @param sendCallback Defaults to true. True will notify the multi-choice callback, if any.
    */
-  @SuppressWarnings("WeakerAccess")
   public void selectAllIndices(boolean sendCallback) {
     if (listType == null || listType != ListType.MULTI) {
       throw new IllegalStateException(
@@ -1014,13 +980,11 @@ public class MaterialDialog extends DialogBase
 
   /** A callback used for regular list dialogs. */
   public interface ListCallback {
-
     void onSelection(MaterialDialog dialog, View itemView, int position, CharSequence text);
   }
 
   /** A callback used for regular list dialogs. */
   public interface ListLongCallback {
-
     boolean onLongSelection(MaterialDialog dialog, View itemView, int position, CharSequence text);
   }
 
@@ -1036,7 +1000,8 @@ public class MaterialDialog extends DialogBase
      * @param text The text of the item that was selected.
      * @return True to allow the radio button to be selected.
      */
-    boolean onSelection(MaterialDialog dialog, View itemView, int which, CharSequence text);
+    boolean onSelection(
+        MaterialDialog dialog, View itemView, int which, @Nullable CharSequence text);
   }
 
   /** A callback used for multi choice (check box) list dialogs. */
@@ -1056,24 +1021,21 @@ public class MaterialDialog extends DialogBase
 
   /** An alternate way to define a single callback. */
   public interface SingleButtonCallback {
-
     void onClick(MaterialDialog dialog, DialogAction which);
   }
 
   public interface InputCallback {
-
     void onInput(MaterialDialog dialog, CharSequence input);
   }
 
   private static class DialogException extends WindowManager.BadTokenException {
-
     DialogException(@SuppressWarnings("SameParameterValue") String message) {
       super(message);
     }
   }
 
   /** The class used to construct a MaterialDialog. */
-  @SuppressWarnings({"WeakerAccess", "unused"})
+  @SuppressWarnings({"WeakerAccess", "unused", "SameParameterValue", "ConstantConditions"})
   public static class Builder {
 
     protected final Context context;
@@ -1101,7 +1063,6 @@ public class MaterialDialog extends DialogBase
     protected ColorStateList negativeColor;
     protected ColorStateList neutralColor;
     protected ColorStateList linkColor;
-    protected ButtonCallback callback;
     protected SingleButtonCallback onPositiveCallback;
     protected SingleButtonCallback onNegativeCallback;
     protected SingleButtonCallback onNeutralCallback;
@@ -1206,7 +1167,8 @@ public class MaterialDialog extends DialogBase
       this.progressPercentFormat = NumberFormat.getPercentInstance();
       this.progressNumberFormat = "%1d/%2d";
 
-      // Set the default theme based on the Activity theme's primary color darkness (more white or more black)
+      // Set the default theme based on the Activity theme's primary color darkness (more white or
+      // more black)
       final int primaryTextColor =
           DialogUtils.resolveColor(context, android.R.attr.textColorPrimary);
       this.theme = DialogUtils.isColorDark(primaryTextColor) ? Theme.LIGHT : Theme.DARK;
@@ -1955,11 +1917,6 @@ public class MaterialDialog extends DialogBase
       return backgroundColor(DialogUtils.resolveColor(this.context, colorAttr));
     }
 
-    public Builder callback(ButtonCallback callback) {
-      this.callback = callback;
-      return this;
-    }
-
     public Builder onPositive(SingleButtonCallback callback) {
       this.onPositiveCallback = callback;
       return this;
@@ -2017,7 +1974,6 @@ public class MaterialDialog extends DialogBase
      *     default linear manager.
      * @return This Builder object to allow for chaining of calls to set methods
      */
-    @SuppressWarnings("ConstantConditions")
     public Builder adapter(
         RecyclerView.Adapter<?> adapter, @Nullable RecyclerView.LayoutManager layoutManager) {
       if (this.customView != null) {
@@ -2185,58 +2141,4 @@ public class MaterialDialog extends DialogBase
       return dialog;
     }
   }
-
-  /**
-   * Override these as needed, so no needing to sub empty methods from an interface
-   *
-   * @deprecated Use the individual onPositive, onNegative, onNeutral, or onAny Builder methods
-   *     instead.
-   */
-  @SuppressWarnings({"WeakerAccess", "UnusedParameters"})
-  @Deprecated
-  public abstract static class ButtonCallback {
-
-    public ButtonCallback() {
-      super();
-    }
-
-    @Deprecated
-    public void onAny(MaterialDialog dialog) {}
-
-    @Deprecated
-    public void onPositive(MaterialDialog dialog) {}
-
-    @Deprecated
-    public void onNegative(MaterialDialog dialog) {}
-
-    // The overidden methods below prevent Android Studio from suggesting that they are overidden by developers
-
-    @Deprecated
-    public void onNeutral(MaterialDialog dialog) {}
-
-    @Override
-    protected final Object clone() throws CloneNotSupportedException {
-      return super.clone();
-    }
-
-    @Override
-    public final boolean equals(Object o) {
-      return super.equals(o);
-    }
-
-    @Override
-    protected final void finalize() throws Throwable {
-      super.finalize();
-    }
-
-    @Override
-    public final int hashCode() {
-      return super.hashCode();
-    }
-
-    @Override
-    public final String toString() {
-      return super.toString();
-    }
-  }
 }

+ 0 - 1
core/src/main/java/com/afollestad/materialdialogs/internal/AllCapsTransformationMethod.java

@@ -7,7 +7,6 @@ import android.view.View;
 import java.util.Locale;
 
 class AllCapsTransformationMethod implements TransformationMethod {
-
   private Locale mLocale;
 
   AllCapsTransformationMethod(Context context) {

+ 0 - 1
core/src/main/java/com/afollestad/materialdialogs/internal/MDAdapter.java

@@ -4,6 +4,5 @@ import com.afollestad.materialdialogs.MaterialDialog;
 
 /** @author Aidan Follestad (afollestad) */
 public interface MDAdapter {
-
   void setDialog(MaterialDialog dialog);
 }

+ 2 - 2
core/src/main/java/com/afollestad/materialdialogs/internal/MDRootLayout.java

@@ -139,7 +139,7 @@ public class MDRootLayout extends ViewGroup {
    * @return View touching the bottom of this ViewGroup or null
    */
   @Nullable
-  private static View getBottomView(ViewGroup viewGroup) {
+  private static View getBottomView(@Nullable ViewGroup viewGroup) {
     if (viewGroup == null || viewGroup.getChildCount() == 0) {
       return null;
     }
@@ -156,7 +156,7 @@ public class MDRootLayout extends ViewGroup {
   }
 
   @Nullable
-  private static View getTopView(ViewGroup viewGroup) {
+  private static View getTopView(@Nullable ViewGroup viewGroup) {
     if (viewGroup == null || viewGroup.getChildCount() == 0) {
       return null;
     }

+ 1 - 6
core/src/main/java/com/afollestad/materialdialogs/internal/MDTintHelper.java

@@ -103,9 +103,6 @@ public class MDTintHelper {
       }
     } else {
       PorterDuff.Mode mode = PorterDuff.Mode.SRC_IN;
-      if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.GINGERBREAD_MR1) {
-        mode = PorterDuff.Mode.MULTIPLY;
-      }
       if (seekBar.getIndeterminateDrawable() != null) {
         seekBar.getIndeterminateDrawable().setColorFilter(color, mode);
       }
@@ -130,9 +127,6 @@ public class MDTintHelper {
       }
     } else {
       PorterDuff.Mode mode = PorterDuff.Mode.SRC_IN;
-      if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.GINGERBREAD_MR1) {
-        mode = PorterDuff.Mode.MULTIPLY;
-      }
       if (!skipIndeterminate && progressBar.getIndeterminateDrawable() != null) {
         progressBar.getIndeterminateDrawable().setColorFilter(color, mode);
       }
@@ -157,6 +151,7 @@ public class MDTintHelper {
     return new ColorStateList(states, colors);
   }
 
+  @SuppressLint("RestrictedApi")
   public static void setTint(EditText editText, @ColorInt int color) {
     ColorStateList editTextColorStateList =
         createEditTextColorStateList(editText.getContext(), color);