diff --git a/res/layout/item_dir_grid.xml b/res/layout/item_dir_grid.xml index da923e94d21ab80eb18a2286b9c5a583a22ca2a6..4a5c4622c38dd786a6a5a851ae89a70df99ee1b4 100644 --- a/res/layout/item_dir_grid.xml +++ b/res/layout/item_dir_grid.xml @@ -22,7 +22,8 @@ when touch mode is not enable. So, if you, heroic engineer of the future, decide to rip these out, please be sure to check out focus and keyboards. --> = Build.VERSION_CODES.LOLLIPOP) { + Window window = getWindow(); + window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); + window.setStatusBarColor(darkenColor(color)); + } + + return color; + } + + int darkenColor(int color) { + float[] hsv = new float[3]; + android.graphics.Color.colorToHSV(color, hsv); + hsv[2] *= 0.8f; + return android.graphics.Color.HSVToColor(hsv); + } + + } diff --git a/src/com/android/documentsui/DrawerController.java b/src/com/android/documentsui/DrawerController.java index d8c679aa78412880131226e6f70024a767cd6e7b..169cda8cf485c0f2fa4881205b874f0c764ee8ba 100644 --- a/src/com/android/documentsui/DrawerController.java +++ b/src/com/android/documentsui/DrawerController.java @@ -16,15 +16,19 @@ package com.android.documentsui; + import static com.android.documentsui.base.Shared.DEBUG; import android.annotation.IntDef; import android.app.Activity; +import android.content.res.TypedArray; import android.support.annotation.ColorRes; import android.support.v4.app.ActionBarDrawerToggle; import android.support.v4.widget.DrawerLayout; import android.support.v4.widget.DrawerLayout.DrawerListener; import android.util.Log; +import android.util.TypedValue; +import android.view.ContextThemeWrapper; import android.view.View; import android.widget.Toolbar; @@ -40,7 +44,7 @@ import java.lang.annotation.RetentionPolicy; */ public abstract class DrawerController implements DrawerListener { public static final String TAG = "DrawerController"; - + private static int accentColor; public abstract void update(); public abstract void setOpen(boolean open); public abstract boolean isPresent(); @@ -52,6 +56,7 @@ public abstract class DrawerController implements DrawerListener { */ public static DrawerController create(Activity activity, ActivityConfig activityConfig) { + accentColor=fetchAccentColor(activity); DrawerLayout layout = (DrawerLayout) activity.findViewById(R.id.drawer_layout); if (layout == null) { @@ -61,6 +66,10 @@ public abstract class DrawerController implements DrawerListener { View drawer = activity.findViewById(R.id.drawer_roots); Toolbar toolbar = (Toolbar) activity.findViewById(R.id.roots_toolbar); + if(accentColor!=0){ + toolbar.setBackgroundColor(accentColor); + } + drawer.getLayoutParams().width = calculateDrawerWidth(activity); ActionBarDrawerToggle toggle = new ActionBarDrawerToggle( @@ -134,9 +143,19 @@ public abstract class DrawerController implements DrawerListener { public void setDropTargetHighlight(View v, boolean highlight) { assert (v.getId() == R.id.drawer_edge); - @ColorRes int id = highlight ? R.color.item_doc_background_selected : - android.R.color.transparent; - v.setBackgroundColor(id); +// @ColorRes int id = highlight ? R.color.item_doc_background_selected : +// android.R.color.transparent; + + if(accentColor!=0){ + @ColorRes int id = highlight ? accentColor : android.R.color.transparent; + v.setBackgroundColor(id); + } + else { + @ColorRes int id = highlight ? R.color.item_doc_background_selected : android.R.color.transparent; + v.setBackgroundColor(id); + } + + } @Override @@ -247,4 +266,21 @@ public abstract class DrawerController implements DrawerListener { @Override public void onDrawerStateChanged(int newState) {} } + + /* + * get Accent color from OS + * */ + + private static int fetchAccentColor(Activity activity) { + TypedValue typedValue = new TypedValue(); + + ContextThemeWrapper contextThemeWrapper = new ContextThemeWrapper(activity, android.R.style.Theme_DeviceDefault_Light); + contextThemeWrapper.getTheme().resolveAttribute(android.R.attr.colorAccent, + typedValue, true); + int color = typedValue.data; + Log.e("TAG", "accent Colour #"+Integer.toHexString(color)); + //toolbar change color to accent color + return color; + } + } diff --git a/src/com/android/documentsui/dirlist/DirectoryItemAnimator.java b/src/com/android/documentsui/dirlist/DirectoryItemAnimator.java index d769f7fda75eec4cc11d88c6cbac04c682922fa1..cb60a1ac0331a4cf6b77569039054b5d78e496d2 100644 --- a/src/com/android/documentsui/dirlist/DirectoryItemAnimator.java +++ b/src/com/android/documentsui/dirlist/DirectoryItemAnimator.java @@ -30,6 +30,7 @@ import com.android.documentsui.R; import java.util.ArrayList; import java.util.List; import java.util.Map; +import static com.android.documentsui.files.LauncherActivity.ACCENT_COLOR; /** * Performs change animations on Items in DirectoryFragment's RecyclerView. This class overrides @@ -43,10 +44,10 @@ class DirectoryItemAnimator extends DefaultItemAnimator { new ArrayMap<>(); private final Integer mDefaultColor; private final Integer mSelectedColor; - public DirectoryItemAnimator(Context context) { mDefaultColor = context.getResources().getColor(R.color.item_doc_background); - mSelectedColor = context.getResources().getColor(R.color.item_doc_background_selected); + //mSelectedColor = context.getResources().getColor(R.color.item_doc_background_selected); + mSelectedColor = Integer.valueOf(ACCENT_COLOR); } @Override diff --git a/src/com/android/documentsui/dirlist/GridDirectoryHolder.java b/src/com/android/documentsui/dirlist/GridDirectoryHolder.java index cf793db38ac2ea0ff4f7bd9443b1160d22305a3d..1a272c25faf260a859955d9516290d5c33fc48bf 100644 --- a/src/com/android/documentsui/dirlist/GridDirectoryHolder.java +++ b/src/com/android/documentsui/dirlist/GridDirectoryHolder.java @@ -24,8 +24,10 @@ import android.graphics.Rect; import android.provider.DocumentsContract.Document; import android.view.ViewGroup; import android.widget.ImageView; +import android.widget.LinearLayout; import android.widget.TextView; +import com.android.documentsui.BaseActivity; import com.android.documentsui.R; import com.android.documentsui.base.DebugFlags; import com.android.documentsui.base.DocumentInfo; @@ -38,13 +40,16 @@ final class GridDirectoryHolder extends DocumentHolder { private final ImageView mIconCheck; private final ImageView mIconMime; + private final LinearLayout mlayout_grid_item; + private final Context context; public GridDirectoryHolder(Context context, ViewGroup parent) { super(context, parent, R.layout.item_dir_grid); - + this.context=context; mTitle = (TextView) itemView.findViewById(android.R.id.title); mIconMime = (ImageView) itemView.findViewById(R.id.icon_mime_sm); mIconCheck = (ImageView) itemView.findViewById(R.id.icon_check); + mlayout_grid_item=(LinearLayout)itemView.findViewById(R.id.layout_grid_item); } @Override @@ -59,6 +64,18 @@ final class GridDirectoryHolder extends DocumentHolder { mIconCheck.setAlpha(checkAlpha); mIconMime.setAlpha(1f - checkAlpha); } + + if(selected){ + mlayout_grid_item.setBackgroundColor(BaseActivity.accentColor); + mTitle.setTextColor(context.getResources().getColor(R.color.window_background)); + mIconCheck.setColorFilter(context.getResources().getColor(R.color.window_background), android.graphics.PorterDuff.Mode.SRC_IN); + } + else { + mlayout_grid_item.setBackgroundColor(context.getResources().getColor(R.color.menu_search_background)); + mTitle.setTextColor(context.getResources().getColor(R.color.item_title)); + + } + } @Override diff --git a/src/com/android/documentsui/dirlist/ListDocumentHolder.java b/src/com/android/documentsui/dirlist/ListDocumentHolder.java index 42be8f9c47397d05359d5a9bffb47812dac17b08..6d59469e63d4e3c5a5b00fb45986b2eba057da46 100644 --- a/src/com/android/documentsui/dirlist/ListDocumentHolder.java +++ b/src/com/android/documentsui/dirlist/ListDocumentHolder.java @@ -29,6 +29,7 @@ import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.TextView; +import com.android.documentsui.BaseActivity; import com.android.documentsui.R; import com.android.documentsui.base.DocumentInfo; import com.android.documentsui.base.Events.InputEvent; @@ -53,11 +54,13 @@ final class ListDocumentHolder extends DocumentHolder { private final Lookup mFileTypeLookup; // This is used in as a convenience in our bind method. private final DocumentInfo mDoc; - + private final LinearLayout layout_list_item; + private final Context context; public ListDocumentHolder(Context context, ViewGroup parent, IconHelper iconHelper, Lookup fileTypeLookup) { super(context, parent, R.layout.item_doc_list); + this.context=context; mIconLayout = itemView.findViewById(android.R.id.icon); mIconMime = (ImageView) itemView.findViewById(R.id.icon_mime); mIconThumb = (ImageView) itemView.findViewById(R.id.icon_thumb); @@ -69,6 +72,7 @@ final class ListDocumentHolder extends DocumentHolder { mType = (TextView) itemView.findViewById(R.id.file_type); // Warning: mDetails view doesn't exists in layout-sw720dp-land layout mDetails = (LinearLayout) itemView.findViewById(R.id.line2); + layout_list_item = (LinearLayout) itemView.findViewById(R.id.layout_list_item); mIconHelper = iconHelper; mFileTypeLookup = fileTypeLookup; @@ -101,6 +105,17 @@ final class ListDocumentHolder extends DocumentHolder { mIconMime.setAlpha(1f - checkAlpha); mIconThumb.setAlpha(1f - checkAlpha); } + + if(selected){ + layout_list_item.setBackgroundColor(BaseActivity.accentColor); + mTitle.setTextColor(context.getResources().getColor(R.color.window_background)); + mIconCheck.setColorFilter(context.getResources().getColor(R.color.window_background), android.graphics.PorterDuff.Mode.SRC_IN); + } + else { + layout_list_item.setBackgroundColor(context.getResources().getColor(R.color.menu_search_background)); + mTitle.setTextColor(context.getResources().getColor(R.color.item_title)); + } + } @Override diff --git a/src/com/android/documentsui/files/LauncherActivity.java b/src/com/android/documentsui/files/LauncherActivity.java index 705d9681efd20158a7092d5142ffec2eb02dc209..ff205e5b75ccd64756a2b56a5deb6480e3a22c11 100644 --- a/src/com/android/documentsui/files/LauncherActivity.java +++ b/src/com/android/documentsui/files/LauncherActivity.java @@ -23,11 +23,14 @@ import android.app.ActivityManager; import android.app.ActivityManager.AppTask; import android.content.Context; import android.content.Intent; +import android.content.res.TypedArray; import android.net.Uri; import android.os.Bundle; import android.provider.DocumentsContract; import android.support.annotation.Nullable; import android.util.Log; +import android.util.TypedValue; +import android.view.ContextThemeWrapper; import com.android.documentsui.R; @@ -49,7 +52,7 @@ public class LauncherActivity extends Activity { private static final String LAUNCH_CONTROL_AUTHORITY = "com.android.documentsui.launchControl"; private static final String TAG = "LauncherActivity"; - + public static int ACCENT_COLOR; // Array of boolean extras that should be copied when creating new launch intents. // Missing intents will be ignored. private static final String[] PERSISTENT_BOOLEAN_EXTRAS = { @@ -60,6 +63,8 @@ public class LauncherActivity extends Activity { protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); + ACCENT_COLOR=fetchAccentColor(); + launch(); finish(); @@ -165,4 +170,22 @@ public class LauncherActivity extends Activity { boolean result = uri != null && LAUNCH_CONTROL_AUTHORITY.equals(uri.getAuthority()); return result; } + + /* + * get Accent color from OS + * */ + + private int fetchAccentColor() { + TypedValue typedValue = new TypedValue(); + + ContextThemeWrapper contextThemeWrapper = new ContextThemeWrapper(this, android.R.style.Theme_DeviceDefault_Light); + contextThemeWrapper.getTheme().resolveAttribute(android.R.attr.colorAccent, + typedValue, true); + int color = typedValue.data; + Log.e("TAG", "accent Colour #"+Integer.toHexString(color)); + //toolbar change color to accent color + + return color; + } + }