Jelajahi Sumber

Used ResourcesCompat and suppressions to satisfy various Lint issues.

Aidan Follestad 10 tahun lalu
induk
melakukan
922635f977

+ 25 - 14
library/src/main/java/com/afollestad/materialdialogs/MaterialDialog.java

@@ -22,6 +22,7 @@ import android.support.annotation.LayoutRes;
 import android.support.annotation.NonNull;
 import android.support.annotation.Nullable;
 import android.support.annotation.StringRes;
+import android.support.v4.content.res.ResourcesCompat;
 import android.support.v7.widget.RecyclerView;
 import android.util.Log;
 import android.view.Gravity;
@@ -72,9 +73,9 @@ public class MaterialDialog extends DialogBase implements
     protected TextView mProgressMinMax;
     protected TextView content;
 
-    protected View positiveButton;
-    protected View neutralButton;
-    protected View negativeButton;
+    private View positiveButton;
+    private View neutralButton;
+    private View negativeButton;
     protected boolean isStacked;
     protected int defaultItemColor;
     protected ListType listType;
@@ -125,10 +126,12 @@ public class MaterialDialog extends DialogBase implements
         listView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
             @Override
             public void onGlobalLayout() {
-                if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN)
+                if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
+                    //noinspection deprecation
                     listView.getViewTreeObserver().removeGlobalOnLayoutListener(this);
-                else
+                } else {
                     listView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
+                }
 
                 if (listType == ListType.SINGLE || listType == ListType.MULTI) {
                     int selectedIndex;
@@ -476,13 +479,13 @@ public class MaterialDialog extends DialogBase implements
     }
 
     public static class NotImplementedException extends Error {
-        public NotImplementedException(String message) {
+        public NotImplementedException(@SuppressWarnings("SameParameterValue") String message) {
             super(message);
         }
     }
 
     public static class DialogException extends WindowManager.BadTokenException {
-        public DialogException(String message) {
+        public DialogException(@SuppressWarnings("SameParameterValue") String message) {
             super(message);
         }
     }
@@ -526,7 +529,7 @@ public class MaterialDialog extends DialogBase implements
 
     protected final Drawable getListSelector() {
         if (mBuilder.listSelector != 0)
-            return mBuilder.context.getResources().getDrawable(mBuilder.listSelector);
+            return ResourcesCompat.getDrawable(mBuilder.context.getResources(), mBuilder.listSelector, null);
         final Drawable d = DialogUtils.resolveDrawable(mBuilder.context, R.attr.md_list_selector);
         if (d != null) return d;
         return DialogUtils.resolveDrawable(getContext(), R.attr.md_list_selector);
@@ -535,7 +538,7 @@ public class MaterialDialog extends DialogBase implements
     private Drawable getButtonSelector(DialogAction which) {
         if (isStacked) {
             if (mBuilder.btnSelectorStacked != 0)
-                return mBuilder.context.getResources().getDrawable(mBuilder.btnSelectorStacked);
+                return ResourcesCompat.getDrawable(mBuilder.context.getResources(), mBuilder.btnSelectorStacked, null);
             final Drawable d = DialogUtils.resolveDrawable(mBuilder.context, R.attr.md_btn_stacked_selector);
             if (d != null) return d;
             return DialogUtils.resolveDrawable(getContext(), R.attr.md_btn_stacked_selector);
@@ -543,21 +546,21 @@ public class MaterialDialog extends DialogBase implements
             switch (which) {
                 default: {
                     if (mBuilder.btnSelectorPositive != 0)
-                        return mBuilder.context.getResources().getDrawable(mBuilder.btnSelectorPositive);
+                        ResourcesCompat.getDrawable(mBuilder.context.getResources(), mBuilder.btnSelectorPositive, null);
                     final Drawable d = DialogUtils.resolveDrawable(mBuilder.context, R.attr.md_btn_positive_selector);
                     if (d != null) return d;
                     return DialogUtils.resolveDrawable(getContext(), R.attr.md_btn_positive_selector);
                 }
                 case NEUTRAL: {
                     if (mBuilder.btnSelectorNeutral != 0)
-                        return mBuilder.context.getResources().getDrawable(mBuilder.btnSelectorNeutral);
+                        ResourcesCompat.getDrawable(mBuilder.context.getResources(), mBuilder.btnSelectorNeutral, null);
                     final Drawable d = DialogUtils.resolveDrawable(mBuilder.context, R.attr.md_btn_neutral_selector);
                     if (d != null) return d;
                     return DialogUtils.resolveDrawable(getContext(), R.attr.md_btn_neutral_selector);
                 }
                 case NEGATIVE: {
                     if (mBuilder.btnSelectorNegative != 0)
-                        return mBuilder.context.getResources().getDrawable(mBuilder.btnSelectorNegative);
+                        return ResourcesCompat.getDrawable(mBuilder.context.getResources(), mBuilder.btnSelectorNegative, null);
                     final Drawable d = DialogUtils.resolveDrawable(mBuilder.context, R.attr.md_btn_negative_selector);
                     if (d != null) return d;
                     return DialogUtils.resolveDrawable(getContext(), R.attr.md_btn_negative_selector);
@@ -938,7 +941,7 @@ public class MaterialDialog extends DialogBase implements
         }
 
         public Builder iconRes(@DrawableRes int icon) {
-            this.icon = context.getResources().getDrawable(icon);
+            this.icon = ResourcesCompat.getDrawable(context.getResources(), icon, null);
             return this;
         }
 
@@ -1466,6 +1469,13 @@ public class MaterialDialog extends DialogBase implements
         return titleFrame;
     }
 
+    /**
+     * Retrieves the view representing the dialog as a whole. Be careful with this.
+     */
+    public final View getView() {
+        return view;
+    }
+
     /**
      * Retrieves the custom view that was inflated or set to the MaterialDialog during building.
      *
@@ -1628,7 +1638,8 @@ public class MaterialDialog extends DialogBase implements
      * @return The ListView instance used by this dialog, or null if not using a list.
      */
     @Nullable
-    public ListView getListView() {
+    @Override
+    public final ListView getListView() {
         return listView;
     }
 

+ 2 - 2
library/src/main/java/com/afollestad/materialdialogs/MaterialDialogAdapter.java

@@ -12,8 +12,8 @@ import com.afollestad.materialdialogs.util.DialogUtils;
 
 class MaterialDialogAdapter extends ArrayAdapter<CharSequence> {
 
-    final int itemColor;
-    final MaterialDialog dialog;
+    private final int itemColor;
+    private final MaterialDialog dialog;
 
     public MaterialDialogAdapter(MaterialDialog dialog, int resource, int textViewResourceId, CharSequence[] objects) {
         super(dialog.mBuilder.context, resource, textViewResourceId, objects);

+ 1 - 1
library/src/main/java/com/afollestad/materialdialogs/prefs/MaterialEditTextPreference.java

@@ -70,6 +70,7 @@ public class MaterialEditTextPreference extends EditTextPreference {
                 .positiveText(getPositiveButtonText())
                 .negativeText(getNegativeButtonText())
                 .callback(callback)
+                .dismissListener(this)
                 .content(getDialogMessage());
 
         View layout = LayoutInflater.from(getContext()).inflate(R.layout.md_stub_input, null);
@@ -92,7 +93,6 @@ public class MaterialEditTextPreference extends EditTextPreference {
             mDialog.onRestoreInstanceState(state);
         requestInputMethod(mDialog);
 
-        mDialog.setOnDismissListener(this);
         mDialog.show();
     }
 

+ 3 - 3
library/src/main/java/com/afollestad/materialdialogs/util/DialogUtils.java

@@ -11,7 +11,7 @@ import android.support.annotation.AttrRes;
  */
 public class DialogUtils {
 
-    public static int adjustAlpha(int color, float factor) {
+    public static int adjustAlpha(int color, @SuppressWarnings("SameParameterValue") float factor) {
         int alpha = Math.round(Color.alpha(color) * factor);
         int red = Color.red(color);
         int green = Color.green(color);
@@ -36,7 +36,7 @@ public class DialogUtils {
         return resolveDrawable(context, attr, null);
     }
 
-    private static Drawable resolveDrawable(Context context, @AttrRes int attr, Drawable fallback) {
+    private static Drawable resolveDrawable(Context context, @AttrRes int attr, @SuppressWarnings("SameParameterValue") Drawable fallback) {
         TypedArray a = context.getTheme().obtainStyledAttributes(new int[]{attr});
         try {
             Drawable d = a.getDrawable(0);
@@ -52,7 +52,7 @@ public class DialogUtils {
         return resolveDimension(context, attr, -1);
     }
 
-    public static int resolveDimension(Context context, @AttrRes int attr, int fallback) {
+    private static int resolveDimension(Context context, @AttrRes int attr, int fallback) {
         TypedArray a = context.getTheme().obtainStyledAttributes(new int[]{attr});
         try {
             return a.getDimensionPixelSize(0, fallback);

+ 7 - 6
library/src/main/java/com/afollestad/materialdialogs/util/RecyclerUtil.java

@@ -20,12 +20,13 @@ public class RecyclerUtil {
         if (lm instanceof LinearLayoutManager) {
             LinearLayoutManager llm = (LinearLayoutManager) lm;
             lastVisible = llm.findLastVisibleItemPosition();
-        } else if (lm instanceof GridLayoutManager) {
-            GridLayoutManager glm = (GridLayoutManager) lm;
-            lastVisible = glm.findLastVisibleItemPosition();
-        } else {
-            throw new MaterialDialog.NotImplementedException("Material Dialogs currently only supports LinearLayoutManager and GridLayoutManager. Please report any new layout managers.");
-        }
+        } else //noinspection ConstantConditions
+            if (lm instanceof GridLayoutManager) {
+                GridLayoutManager glm = (GridLayoutManager) lm;
+                lastVisible = glm.findLastVisibleItemPosition();
+            } else {
+                throw new MaterialDialog.NotImplementedException("Material Dialogs currently only supports LinearLayoutManager and GridLayoutManager. Please report any new layout managers.");
+            }
 
         if (lastVisible == -1)
             return false;

+ 0 - 1
library/src/main/res/values/colors.xml

@@ -15,6 +15,5 @@
     <color name="md_divider_white">#10FFFFFF</color>
 
     <color name="md_material_blue_600">#1E88E5</color>
-    <color name="md_material_blue_800">#1565C0</color>
 
 </resources>

+ 0 - 2
library/src/main/res/values/dimens.xml

@@ -37,6 +37,4 @@
     <dimen name="md_listitem_margin_left">24dp</dimen>
     <dimen name="md_action_corner_radius">2dp</dimen>
 
-    <dimen name="md_progressdialog_paddingwithtitle">4dp</dimen>
-
 </resources>