diff options
12 files changed, 140 insertions, 40 deletions
diff --git a/packages/DocumentsUI/res/color/item_details.xml b/packages/DocumentsUI/res/color/item_details.xml new file mode 100644 index 000000000000..769b94472a31 --- /dev/null +++ b/packages/DocumentsUI/res/color/item_details.xml @@ -0,0 +1,26 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- Copyright (C) 2016 The Android Open Source Project + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +--> + +<selector xmlns:android="http://schemas.android.com/apk/res/android"> + <item + android:state_enabled="true" + android:color="?android:attr/textColorPrimary" + android:alpha="0.63" /> + <item + android:state_enabled="false" + android:color="?android:attr/textColorPrimary" + android:alpha="0.3" /> +</selector> diff --git a/packages/DocumentsUI/res/color/item_title.xml b/packages/DocumentsUI/res/color/item_title.xml new file mode 100644 index 000000000000..ef6aea33fece --- /dev/null +++ b/packages/DocumentsUI/res/color/item_title.xml @@ -0,0 +1,25 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- Copyright (C) 2016 The Android Open Source Project + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +--> + +<selector xmlns:android="http://schemas.android.com/apk/res/android"> + <item + android:state_enabled="true" + android:color="?android:attr/textColorPrimary" /> + <item + android:state_enabled="false" + android:color="?android:attr/textColorPrimary" + android:alpha="0.3" /> +</selector> diff --git a/packages/DocumentsUI/res/layout/item_dir_grid.xml b/packages/DocumentsUI/res/layout/item_dir_grid.xml index a4f06d1cefe8..429a972c5d94 100644 --- a/packages/DocumentsUI/res/layout/item_dir_grid.xml +++ b/packages/DocumentsUI/res/layout/item_dir_grid.xml @@ -66,7 +66,7 @@ android:singleLine="true" android:textAlignment="viewStart" android:textAppearance="@android:style/TextAppearance.Material.Subhead" - android:textColor="@*android:color/primary_text_default_material_light" /> + android:textColor="@color/item_title" /> </LinearLayout> diff --git a/packages/DocumentsUI/res/layout/item_doc_grid.xml b/packages/DocumentsUI/res/layout/item_doc_grid.xml index af1703fbe423..56a061fb1f31 100644 --- a/packages/DocumentsUI/res/layout/item_doc_grid.xml +++ b/packages/DocumentsUI/res/layout/item_doc_grid.xml @@ -93,7 +93,7 @@ android:ellipsize="end" android:textAlignment="viewStart" android:textAppearance="@android:style/TextAppearance.Material.Subhead" - android:textColor="@*android:color/primary_text_default_material_light" /> + android:textColor="@color/item_title" /> <TextView android:id="@+id/size" @@ -106,7 +106,7 @@ android:ellipsize="end" android:textAlignment="viewStart" android:textAppearance="@android:style/TextAppearance.Material.Caption" - android:textColor="@*android:color/primary_text_default_material_light" /> + android:textColor="@color/item_details" /> <TextView android:id="@+id/date" @@ -118,7 +118,7 @@ android:ellipsize="end" android:textAlignment="viewStart" android:textAppearance="@android:style/TextAppearance.Material.Caption" - android:textColor="@*android:color/primary_text_default_material_light" /> + android:textColor="@color/item_details" /> </RelativeLayout> diff --git a/packages/DocumentsUI/res/layout/item_doc_list.xml b/packages/DocumentsUI/res/layout/item_doc_list.xml index 29f65e09f184..a939fcddccee 100644 --- a/packages/DocumentsUI/res/layout/item_doc_list.xml +++ b/packages/DocumentsUI/res/layout/item_doc_list.xml @@ -85,7 +85,7 @@ android:singleLine="true" android:textAlignment="viewStart" android:textAppearance="@android:style/TextAppearance.Material.Subhead" - android:textColor="?android:attr/textColorPrimary" /> + android:textColor="@color/item_title" /> <LinearLayout android:id="@+id/line2" @@ -102,8 +102,8 @@ android:ellipsize="end" android:singleLine="true" android:textAlignment="viewStart" - android:textAppearance="@android:style/TextAppearance.Material.Body1" - android:textColor="?android:attr/textColorSecondary" /> + android:textAppearance="@android:style/TextAppearance.Material.Caption" + android:textColor="@color/item_details" /> <TextView android:id="@+id/size" @@ -113,8 +113,8 @@ android:ellipsize="end" android:singleLine="true" android:textAlignment="viewStart" - android:textAppearance="@android:style/TextAppearance.Material.Body1" - android:textColor="?android:attr/textColorSecondary" /> + android:textAppearance="@android:style/TextAppearance.Material.Caption" + android:textColor="@color/item_details" /> <TextView android:id="@android:id/summary" @@ -125,8 +125,8 @@ android:ellipsize="end" android:singleLine="true" android:textAlignment="viewStart" - android:textAppearance="@android:style/TextAppearance.Material.Body1" - android:textColor="?android:attr/textColorSecondary" /> + android:textAppearance="@android:style/TextAppearance.Material.Caption" + android:textColor="@color/item_details" /> </LinearLayout> </LinearLayout> </LinearLayout> diff --git a/packages/DocumentsUI/res/values-sw720dp-land/config.xml b/packages/DocumentsUI/res/values-sw720dp-land/config.xml index 8d9526d62dff..6893d7a6735b 100644 --- a/packages/DocumentsUI/res/values-sw720dp-land/config.xml +++ b/packages/DocumentsUI/res/values-sw720dp-land/config.xml @@ -15,5 +15,4 @@ --> <resources> - <bool name="always_show_summary">true</bool> </resources> diff --git a/packages/DocumentsUI/res/values/colors.xml b/packages/DocumentsUI/res/values/colors.xml index 3785adf7f878..04b7feeca827 100644 --- a/packages/DocumentsUI/res/values/colors.xml +++ b/packages/DocumentsUI/res/values/colors.xml @@ -23,8 +23,6 @@ <color name="window_background">#fff1f1f1</color> <color name="drawer_background">#fff1f1f1</color> <color name="directory_background">#fff7f7f7</color> - <color name="item_doc_background">#fffafafa</color> - <color name="item_doc_background_selected">#ffe0f2f1</color> <color name="menu_search_background">#ff676f74</color> <color name="primary_dark">@*android:color/primary_dark_material_dark</color> @@ -35,4 +33,11 @@ <color name="band_select_background">#88ffffff</color> <color name="band_select_border">#44000000</color> + + <color name="item_doc_background_disabled">#fff4f4f4</color> + + <!-- TODO: Would be nice to move this to a color-set, but not sure how to support animation --> + <color name="item_doc_background">#fffafafa</color> + <color name="item_doc_background_selected">#ffe0f2f1</color> + </resources> diff --git a/packages/DocumentsUI/res/values/config.xml b/packages/DocumentsUI/res/values/config.xml index 8a7654071a3e..86087c3ffa50 100644 --- a/packages/DocumentsUI/res/values/config.xml +++ b/packages/DocumentsUI/res/values/config.xml @@ -21,5 +21,4 @@ <!-- Intentionally unset. Vendors should set this in an overlay. --> <string name="trusted_quick_viewer_package" translatable="false"></string> <bool name="list_divider_inset_left">true</bool> - <bool name="always_show_summary">false</bool> </resources> diff --git a/packages/DocumentsUI/src/com/android/documentsui/dirlist/DocumentHolder.java b/packages/DocumentsUI/src/com/android/documentsui/dirlist/DocumentHolder.java index 3b5ce87ebfb0..5edda3866d5c 100644 --- a/packages/DocumentsUI/src/com/android/documentsui/dirlist/DocumentHolder.java +++ b/packages/DocumentsUI/src/com/android/documentsui/dirlist/DocumentHolder.java @@ -16,6 +16,7 @@ package com.android.documentsui.dirlist; +import android.annotation.ColorInt; import android.content.Context; import android.database.Cursor; import android.graphics.Rect; @@ -35,17 +36,19 @@ public abstract class DocumentHolder extends RecyclerView.ViewHolder implements View.OnKeyListener { + static final float DISABLED_ALPHA = 0.3f; + public @Nullable String modelId; - final int mSelectedItemColor; - final int mDefaultItemColor; - final boolean mAlwaysShowSummary; final Context mContext; + final @ColorInt int mDefaultBgColor; + final @ColorInt int mSelectedBgColor; DocumentHolder.EventListener mEventListener; private View.OnKeyListener mKeyListener; private View mSelectionHotspot; + public DocumentHolder(Context context, ViewGroup parent, int layout) { this(context, inflateLayout(context, parent, layout)); } @@ -57,9 +60,8 @@ public abstract class DocumentHolder mContext = context; - mDefaultItemColor = context.getColor(R.color.item_doc_background); - mSelectedItemColor = context.getColor(R.color.item_doc_background_selected); - mAlwaysShowSummary = context.getResources().getBoolean(R.bool.always_show_summary); + mDefaultBgColor = context.getColor(R.color.item_doc_background); + mSelectedBgColor = context.getColor(R.color.item_doc_background_selected); mSelectionHotspot = itemView.findViewById(R.id.icon_check); } @@ -80,7 +82,7 @@ public abstract class DocumentHolder */ public void setSelected(boolean selected) { itemView.setActivated(selected); - itemView.setBackgroundColor(selected ? mSelectedItemColor : mDefaultItemColor); + itemView.setBackgroundColor(selected ? mSelectedBgColor : mDefaultBgColor); } /** @@ -88,7 +90,11 @@ public abstract class DocumentHolder * @param highlighted */ public void setHighlighted(boolean highlighted) { - itemView.setBackgroundColor(highlighted ? mSelectedItemColor : mDefaultItemColor); + itemView.setBackgroundColor(highlighted ? mSelectedBgColor : mDefaultBgColor); + } + + public void setEnabled(boolean enabled) { + setEnabledRecursive(itemView, enabled); } @Override @@ -111,10 +117,6 @@ public abstract class DocumentHolder mKeyListener = listener; } - public void setEnabled(boolean enabled) { - setEnabledRecursive(itemView, enabled); - } - public boolean onSingleTapUp(MotionEvent event) { if (Events.isMouseEvent(event)) { // Mouse clicks select. diff --git a/packages/DocumentsUI/src/com/android/documentsui/dirlist/GridDocumentHolder.java b/packages/DocumentsUI/src/com/android/documentsui/dirlist/GridDocumentHolder.java index a4bce1626fb4..e7fa28b25837 100644 --- a/packages/DocumentsUI/src/com/android/documentsui/dirlist/GridDocumentHolder.java +++ b/packages/DocumentsUI/src/com/android/documentsui/dirlist/GridDocumentHolder.java @@ -20,6 +20,7 @@ import static com.android.documentsui.model.DocumentInfo.getCursorInt; import static com.android.documentsui.model.DocumentInfo.getCursorLong; import static com.android.documentsui.model.DocumentInfo.getCursorString; +import android.annotation.ColorInt; import android.content.Context; import android.database.Cursor; import android.net.Uri; @@ -37,6 +38,7 @@ import com.android.documentsui.Shared; import com.android.documentsui.State; final class GridDocumentHolder extends DocumentHolder { + private static boolean mHideTitles; final TextView mTitle; @@ -48,9 +50,13 @@ final class GridDocumentHolder extends DocumentHolder { final ImageView mIconCheck; final IconHelper mIconHelper; + private final @ColorInt int mDisabledBgColor; + public GridDocumentHolder(Context context, ViewGroup parent, IconHelper iconHelper) { super(context, parent, R.layout.item_doc_grid); + mDisabledBgColor = context.getColor(R.color.item_doc_background_disabled); + mTitle = (TextView) itemView.findViewById(android.R.id.title); mDate = (TextView) itemView.findViewById(R.id.date); mSize = (TextView) itemView.findViewById(R.id.size); @@ -64,13 +70,35 @@ final class GridDocumentHolder extends DocumentHolder { @Override public void setSelected(boolean selected) { - super.setSelected(selected); + // We always want to make sure our check box disappears if we're not selected, + // even if the item is disabled. This is because this object can be reused + // and this method will be called to setup initial state. float checkAlpha = selected ? 1f : 0f; - mIconCheck.animate().alpha(checkAlpha).start(); + + // But it should be an error to be set to selected && be disabled. + if (!itemView.isEnabled()) { + assert(!selected); + return; + } + + super.setSelected(selected); + mIconMimeSm.animate().alpha(1f - checkAlpha).start(); } + public void setEnabled(boolean enabled) { + super.setEnabled(enabled); + + // Text colors enabled/disabled is handle via a color set. + itemView.setBackgroundColor(enabled ? mDefaultBgColor : mDisabledBgColor); + float imgAlpha = enabled ? 1f : DISABLED_ALPHA; + + mIconMimeLg.setAlpha(imgAlpha); + mIconMimeSm.setAlpha(imgAlpha); + mIconThumb.setAlpha(imgAlpha); + } + /** * Bind this view to the given document for display. * @param cursor Pointing to the item to be bound. diff --git a/packages/DocumentsUI/src/com/android/documentsui/dirlist/ListDocumentHolder.java b/packages/DocumentsUI/src/com/android/documentsui/dirlist/ListDocumentHolder.java index 0831dbfc14d2..3a1be119896b 100644 --- a/packages/DocumentsUI/src/com/android/documentsui/dirlist/ListDocumentHolder.java +++ b/packages/DocumentsUI/src/com/android/documentsui/dirlist/ListDocumentHolder.java @@ -66,14 +66,33 @@ final class ListDocumentHolder extends DocumentHolder { @Override public void setSelected(boolean selected) { - super.setSelected(selected); + // We always want to make sure our check box disappears if we're not selected, + // even if the item is disabled. But it should be an error (see assert below) + // to be set to selected && be disabled. float checkAlpha = selected ? 1f : 0f; - mIconCheck.animate().alpha(checkAlpha).start(); + + if (!itemView.isEnabled()) { + assert(!selected); + return; + } + + super.setSelected(selected); + mIconMime.animate().alpha(1f - checkAlpha).start(); mIconThumb.animate().alpha(1f - checkAlpha).start(); } + @Override + public void setEnabled(boolean enabled) { + super.setEnabled(enabled); + + // Text colors enabled/disabled is handle via a color set. + final float imgAlpha = enabled ? 1f : DISABLED_ALPHA; + mIconMime.setAlpha(imgAlpha); + mIconThumb.setAlpha(imgAlpha); + } + /** * Bind this view to the given document for display. * @param cursor Pointing to the item to be bound. @@ -145,12 +164,4 @@ final class ListDocumentHolder extends DocumentHolder { mDetails.setVisibility(hasDetails ? View.VISIBLE : View.GONE); } } - - @Override - public void setEnabled(boolean enabled) { - super.setEnabled(enabled); - final float iconAlpha = enabled ? 1f : 0.5f; - mIconMime.setAlpha(iconAlpha); - mIconThumb.setAlpha(iconAlpha); - } } diff --git a/packages/DocumentsUI/src/com/android/documentsui/dirlist/ModelBackedDocumentsAdapter.java b/packages/DocumentsUI/src/com/android/documentsui/dirlist/ModelBackedDocumentsAdapter.java index 2b073397f292..a8b762b7f54e 100644 --- a/packages/DocumentsUI/src/com/android/documentsui/dirlist/ModelBackedDocumentsAdapter.java +++ b/packages/DocumentsUI/src/com/android/documentsui/dirlist/ModelBackedDocumentsAdapter.java @@ -118,8 +118,13 @@ final class ModelBackedDocumentsAdapter extends DocumentsAdapter { final String docMimeType = getCursorString(cursor, Document.COLUMN_MIME_TYPE); final int docFlags = getCursorInt(cursor, Document.COLUMN_FLAGS); + boolean enabled = mEnv.isDocumentEnabled(docMimeType, docFlags); + boolean selected = mEnv.isSelected(modelId); + if (!enabled) { + assert(!selected); + } + holder.setEnabled(enabled); holder.setSelected(mEnv.isSelected(modelId)); - holder.setEnabled(mEnv.isDocumentEnabled(docMimeType, docFlags)); mEnv.onBindDocumentHolder(holder, cursor); } |