Merge "Make disabled items look disabled." into nyc-dev

This commit is contained in:
Steve McKay
2016-03-09 18:35:32 +00:00
committed by Android (Google) Code Review
12 changed files with 140 additions and 40 deletions

View File

@@ -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>

View File

@@ -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>

View File

@@ -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>

View File

@@ -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>

View File

@@ -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>

View File

@@ -15,5 +15,4 @@
-->
<resources>
<bool name="always_show_summary">true</bool>
</resources>

View File

@@ -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>

View File

@@ -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>

View File

@@ -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.

View File

@@ -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.

View File

@@ -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);
}
}

View File

@@ -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);
}