소스 검색

move image button icon coloring to DisplayUtils

AndyScherzinger 8 년 전
부모
커밋
c1867c0509
2개의 변경된 파일19개의 추가작업 그리고 16개의 파일을 삭제
  1. 7 16
      src/com/owncloud/android/ui/dialog/SortingOrderDialogFragment.java
  2. 12 0
      src/main/java/com/owncloud/android/utils/DisplayUtils.java

+ 7 - 16
src/com/owncloud/android/ui/dialog/SortingOrderDialogFragment.java

@@ -22,7 +22,6 @@
 package com.owncloud.android.ui.dialog;
 
 import android.app.Dialog;
-import android.graphics.PorterDuff;
 import android.os.Bundle;
 import android.support.annotation.NonNull;
 import android.support.v4.app.DialogFragment;
@@ -33,6 +32,7 @@ import android.widget.ImageButton;
 
 import com.owncloud.android.R;
 import com.owncloud.android.lib.common.utils.Log_OC;
+import com.owncloud.android.utils.DisplayUtils;
 
 /**
  * Dialog to show and choose the sorting order for the file listing.
@@ -130,13 +130,13 @@ public class SortingOrderDialogFragment extends DialogFragment {
         if (mSortAscending) {
             switch (mSortOrder) {
                 case 0:
-                    setActiveState(mSortByNameAscendingButton);
+                    DisplayUtils.colorImageButton(mSortByNameAscendingButton);
                     break;
                 case 1:
-                    setActiveState(mSortByModificationDateAscendingButton);
+                    DisplayUtils.colorImageButton(mSortByModificationDateAscendingButton);
                     break;
                 case 2:
-                    setActiveState(mSortBySizeAscendingButton);
+                    DisplayUtils.colorImageButton(mSortBySizeAscendingButton);
                     break;
                 default: //do nothing
                     Log_OC.w(TAG, "Unknown sort criteria!");
@@ -145,13 +145,13 @@ public class SortingOrderDialogFragment extends DialogFragment {
         } else {
             switch (mSortOrder) {
                 case 0:
-                    setActiveState(mSortByNameDescendingButton);
+                    DisplayUtils.colorImageButton(mSortByNameDescendingButton);
                     break;
                 case 1:
-                    setActiveState(mSortByModificationDateDescendingButton);
+                    DisplayUtils.colorImageButton(mSortByModificationDateDescendingButton);
                     break;
                 case 2:
-                    setActiveState(mSortBySizeDescendingButton);
+                    DisplayUtils.colorImageButton(mSortBySizeDescendingButton);
                     break;
                 default: //do nothing
                     Log_OC.w(TAG, "Unknown sort criteria!");
@@ -160,15 +160,6 @@ public class SortingOrderDialogFragment extends DialogFragment {
         }
     }
 
-    /**
-     * tints a given ImageButton's drawable in the app's primary color.
-     *
-     * @param imageButton the image button to tint
-     */
-    private void setActiveState(ImageButton imageButton) {
-        imageButton.setColorFilter(getResources().getColor(R.color.primary), PorterDuff.Mode.SRC_ATOP);
-    }
-
     /**
      * setup all listeners.
      *

+ 12 - 0
src/main/java/com/owncloud/android/utils/DisplayUtils.java

@@ -43,6 +43,7 @@ import android.text.SpannableStringBuilder;
 import android.text.format.DateUtils;
 import android.text.style.StyleSpan;
 import android.view.View;
+import android.widget.ImageButton;
 import android.widget.ProgressBar;
 import android.widget.SeekBar;
 
@@ -321,6 +322,17 @@ public class DisplayUtils {
         }
     }
 
+    /**
+     * sets the tinting of the given ImageButton's icon to color_accent.
+     *
+     * @param imageButton the image button who's icon should be colored
+     */
+    public static void colorImageButton(ImageButton imageButton) {
+        if (imageButton != null) {
+            imageButton.setColorFilter(imageButton.getResources().getColor(R.color.primary), PorterDuff.Mode.SRC_ATOP);
+        }
+    }
+
     /**
      * sets the coloring of the given progress bar to color_accent.
      *