From 17ea344e85867184f3ab64ceac66a467222d9a12 Mon Sep 17 00:00:00 2001 From: Narinder Rana Date: Thu, 17 Sep 2020 09:09:33 +0530 Subject: [PATCH 1/3] get accent color from OS and implement on all screens for Q --- res/layout/item_dir_grid.xml | 1 + res/layout/item_doc_list.xml | 1 + src/com/android/documentsui/BaseActivity.java | 41 ++++++++++++++++++- .../android/documentsui/DrawerController.java | 37 +++++++++++++++-- .../dirlist/GridDirectoryHolder.java | 22 +++++++++- .../dirlist/ListDocumentHolder.java | 18 +++++++- .../documentsui/files/LauncherActivity.java | 22 +++++++++- 7 files changed, 134 insertions(+), 8 deletions(-) diff --git a/res/layout/item_dir_grid.xml b/res/layout/item_dir_grid.xml index 06948f60a..20bb07e1a 100644 --- a/res/layout/item_dir_grid.xml +++ b/res/layout/item_dir_grid.xml @@ -43,6 +43,7 @@ = 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 e5996558b..6ff04e01b 100644 --- a/src/com/android/documentsui/DrawerController.java +++ b/src/com/android/documentsui/DrawerController.java @@ -19,7 +19,9 @@ package com.android.documentsui; import static com.android.documentsui.base.SharedMinimal.DEBUG; import android.app.Activity; +import android.content.res.TypedArray; import android.util.Log; +import android.util.TypedValue; import android.view.View; import androidx.annotation.ColorRes; @@ -43,12 +45,13 @@ public abstract class DrawerController implements DrawerListener { public abstract boolean isPresent(); public abstract boolean isOpen(); abstract void setTitle(String title); + private static int accentColor; /** * Returns a controller suitable for {@code Layout}. */ public static DrawerController create(Activity activity, ActivityConfig activityConfig) { - + accentColor=fetchAccentColor(activity); DrawerLayout layout = (DrawerLayout) activity.findViewById(R.id.drawer_layout); if (layout == null) { @@ -57,6 +60,11 @@ 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( @@ -130,9 +138,15 @@ 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.secondary : - android.R.color.transparent; - v.setBackgroundColor(id); + 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 @@ -243,4 +257,19 @@ 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(); + TypedArray a = activity.obtainStyledAttributes(typedValue.data, new int[] { R.attr.colorAccent }); + int color = a.getColor(0, 0); + a.recycle(); + Log.e("TAG", "accent Colour #"+Integer.toHexString(color)); + //toolbar change color to accent color + return color; + } + } diff --git a/src/com/android/documentsui/dirlist/GridDirectoryHolder.java b/src/com/android/documentsui/dirlist/GridDirectoryHolder.java index e32a48b34..7575354f5 100644 --- a/src/com/android/documentsui/dirlist/GridDirectoryHolder.java +++ b/src/com/android/documentsui/dirlist/GridDirectoryHolder.java @@ -26,8 +26,10 @@ import android.view.MotionEvent; import android.view.View; 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.IconUtils; import com.android.documentsui.R; import com.android.documentsui.base.State; @@ -40,14 +42,18 @@ final class GridDirectoryHolder extends DocumentHolder { private final ImageView mIconCheck; private final ImageView mIconMime; private final View mIconLayout; + 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; mIconLayout = itemView.findViewById(R.id.icon); 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); mIconMime.setImageDrawable( IconUtils.loadMimeIcon(context, DocumentsContract.Document.MIME_TYPE_DIR)); } @@ -64,6 +70,20 @@ 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 55b4ec050..3fc1f8e6e 100644 --- a/src/com/android/documentsui/dirlist/ListDocumentHolder.java +++ b/src/com/android/documentsui/dirlist/ListDocumentHolder.java @@ -30,6 +30,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.Lookup; @@ -58,10 +59,13 @@ final class ListDocumentHolder extends DocumentHolder { // 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); @@ -73,6 +77,7 @@ final class ListDocumentHolder extends DocumentHolder { // Warning: mDetails view doesn't exists in layout-sw720dp-land layout mDetails = (LinearLayout) itemView.findViewById(R.id.line2); mPreviewIcon = itemView.findViewById(R.id.preview_icon); + layout_list_item = (LinearLayout) itemView.findViewById(R.id.layout_list_item); mIconHelper = iconHelper; mFileTypeLookup = fileTypeLookup; @@ -105,6 +110,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 8cd7dcbb8..e030a6760 100644 --- a/src/com/android/documentsui/files/LauncherActivity.java +++ b/src/com/android/documentsui/files/LauncherActivity.java @@ -23,11 +23,13 @@ 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 androidx.annotation.Nullable; import android.util.Log; +import android.util.TypedValue; import com.android.documentsui.R; @@ -49,7 +51,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 +62,8 @@ public class LauncherActivity extends Activity { protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); + ACCENT_COLOR=fetchAccentColor(); + launch(); finish(); @@ -169,4 +173,20 @@ 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(); + TypedArray a = this.obtainStyledAttributes(typedValue.data, new int[] { R.attr.colorAccent }); + int color = a.getColor(0, 0); + a.recycle(); + Log.e("TAG", "accent Colour #"+Integer.toHexString(color)); + //toolbar change color to accent color + + return color; + } + } -- GitLab From 31c4191b626889444591b37b523095b93a1c7c3d Mon Sep 17 00:00:00 2001 From: Narinder Rana Date: Fri, 18 Sep 2020 08:46:06 +0530 Subject: [PATCH 2/3] Add some of color value --- res/values/colors.xml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/res/values/colors.xml b/res/values/colors.xml index a34f09d2b..519632ed7 100644 --- a/res/values/colors.xml +++ b/res/values/colors.xml @@ -41,4 +41,9 @@ #ff4688f2 #ff3367d6 #fff5f5f5 + + #fff1f1f1 + #4d3367d6 + #ff333333 + -- GitLab From 27b5317b5f26e0f10167886391d4e0e3522d7e58 Mon Sep 17 00:00:00 2001 From: Narinder Rana Date: Fri, 18 Sep 2020 10:29:14 +0530 Subject: [PATCH 3/3] update Theme_DeviceDefault_Light --- src/com/android/documentsui/BaseActivity.java | 11 ++++++++--- src/com/android/documentsui/DrawerController.java | 9 ++++++--- .../android/documentsui/files/LauncherActivity.java | 9 ++++++--- 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/src/com/android/documentsui/BaseActivity.java b/src/com/android/documentsui/BaseActivity.java index 240178f94..9d5126d79 100644 --- a/src/com/android/documentsui/BaseActivity.java +++ b/src/com/android/documentsui/BaseActivity.java @@ -35,6 +35,7 @@ import android.provider.DocumentsContract; import android.text.TextUtils; import android.util.Log; import android.util.TypedValue; +import android.view.ContextThemeWrapper; import android.view.KeyEvent; import android.view.Menu; import android.view.MenuItem; @@ -902,9 +903,13 @@ public abstract class BaseActivity private int fetchAccentColor() { TypedValue typedValue = new TypedValue(); - TypedArray a = this.obtainStyledAttributes(typedValue.data, new int[] { R.attr.colorAccent }); - int color = a.getColor(0, 0); - a.recycle(); + + 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 toolbar.setBackgroundColor(color); diff --git a/src/com/android/documentsui/DrawerController.java b/src/com/android/documentsui/DrawerController.java index 6ff04e01b..feda5e60c 100644 --- a/src/com/android/documentsui/DrawerController.java +++ b/src/com/android/documentsui/DrawerController.java @@ -22,6 +22,7 @@ import android.app.Activity; import android.content.res.TypedArray; import android.util.Log; import android.util.TypedValue; +import android.view.ContextThemeWrapper; import android.view.View; import androidx.annotation.ColorRes; @@ -264,9 +265,11 @@ public abstract class DrawerController implements DrawerListener { private static int fetchAccentColor(Activity activity) { TypedValue typedValue = new TypedValue(); - TypedArray a = activity.obtainStyledAttributes(typedValue.data, new int[] { R.attr.colorAccent }); - int color = a.getColor(0, 0); - a.recycle(); + 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/files/LauncherActivity.java b/src/com/android/documentsui/files/LauncherActivity.java index e030a6760..c55f9f657 100644 --- a/src/com/android/documentsui/files/LauncherActivity.java +++ b/src/com/android/documentsui/files/LauncherActivity.java @@ -30,6 +30,7 @@ import android.provider.DocumentsContract; import androidx.annotation.Nullable; import android.util.Log; import android.util.TypedValue; +import android.view.ContextThemeWrapper; import com.android.documentsui.R; @@ -180,9 +181,11 @@ public class LauncherActivity extends Activity { private int fetchAccentColor() { TypedValue typedValue = new TypedValue(); - TypedArray a = this.obtainStyledAttributes(typedValue.data, new int[] { R.attr.colorAccent }); - int color = a.getColor(0, 0); - a.recycle(); + 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 -- GitLab