diff --git a/res/layout/item_dir_grid.xml b/res/layout/item_dir_grid.xml index 06948f60afccf2910ba12bf506a86c4301548c38..20bb07e1a093cbc9669bc17315317d8396482db3 100644 --- a/res/layout/item_dir_grid.xml +++ b/res/layout/item_dir_grid.xml @@ -43,6 +43,7 @@ #ff4688f2 #ff3367d6 #fff5f5f5 + + #fff1f1f1 + #4d3367d6 + #ff333333 + diff --git a/src/com/android/documentsui/BaseActivity.java b/src/com/android/documentsui/BaseActivity.java index 9954e9d0ee831d429856d0ca6b8ab0a465884285..9d5126d790bec039ecb943177be05fc1a1f496f8 100644 --- a/src/com/android/documentsui/BaseActivity.java +++ b/src/com/android/documentsui/BaseActivity.java @@ -24,6 +24,7 @@ import android.content.Intent; import android.content.pm.PackageInfo; import android.content.pm.PackageManager; import android.content.pm.ProviderInfo; +import android.content.res.TypedArray; import android.graphics.Color; import android.net.Uri; import android.os.Build; @@ -33,11 +34,15 @@ import android.preference.PreferenceManager; 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; import android.view.View; import android.view.ViewGroup; +import android.view.Window; +import android.view.WindowManager; import android.widget.Checkable; import android.widget.TextView; @@ -116,6 +121,10 @@ public abstract class BaseActivity private PreferencesMonitor mPreferencesMonitor; + private Toolbar toolbar; + public static int accentColor; + + public BaseActivity(@LayoutRes int layoutId, String tag) { mLayoutId = layoutId; mTag = tag; @@ -157,7 +166,7 @@ public abstract class BaseActivity mProviders = DocumentsApplication.getProvidersCache(this); mDocs = DocumentsAccess.create(this); - Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); + toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); Breadcrumb breadcrumb = @@ -275,6 +284,7 @@ public abstract class BaseActivity // Base classes must update result in their onCreate. setResult(AppCompatActivity.RESULT_CANCELED); + accentColor=fetchAccentColor(); } public void onPreferenceChanged(String pref) { @@ -886,4 +896,38 @@ public abstract class BaseActivity */ void onDirectoryLoaded(@Nullable Uri uri); } + + /* + * 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 + toolbar.setBackgroundColor(color); + //change status bar color + if (Build.VERSION.SDK_INT >= 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 e5996558b5f4ba7c0ec0b6861d3405e4b3474cf0..feda5e60c23417e3543ed21b40d76c0b0d36578b 100644 --- a/src/com/android/documentsui/DrawerController.java +++ b/src/com/android/documentsui/DrawerController.java @@ -19,7 +19,10 @@ 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.ContextThemeWrapper; import android.view.View; import androidx.annotation.ColorRes; @@ -43,12 +46,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 +61,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 +139,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 +258,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/GridDirectoryHolder.java b/src/com/android/documentsui/dirlist/GridDirectoryHolder.java index e32a48b342b61b59844c448b1fa666f88782611b..7575354f510cb81aa3ba1f10f74a2b48402be14f 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 55b4ec050a6f95e0a644afd52d45873f22124391..3fc1f8e6ec2acc996d1431484f0de2ee7374258a 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 8cd7dcbb8073abe1e86e5c4084bb3b65f4a0a7bd..c55f9f657f99b1d13a364e0a45bd295aa09ecdb3 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 androidx.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(); @@ -169,4 +174,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; + } + }