Use the default theme for selected mailbox.

The latest framework change made it very easy to do this.
We no longer need to implement Checkable by ourselves.

Change-Id: I9264b157b6600659597ca8d525a4288d7bb9c470
This commit is contained in:
Makoto Onuki 2010-09-17 15:03:32 -07:00
parent 0435a0775e
commit 0af92c0c39
3 changed files with 43 additions and 185 deletions

View File

@ -14,59 +14,56 @@
limitations under the License.
-->
<com.android.email.activity.MailboxListItem
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="?android:attr/listPreferredItemHeight"
android:orientation="horizontal"
android:gravity="center_vertical"
android:paddingRight="8dip"
android:background="?android:attr/activatedBackgroundIndicator"
>
<LinearLayout
android:layout_width="match_parent"
<View
android:id="@+id/chip"
android:background="@drawable/appointment_indicator_leftside_1"
android:layout_width="4dip"
android:layout_height="match_parent"
android:orientation="horizontal"
android:layout_centerVertical="true" />
<ImageView
android:id="@+id/folder_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_list_folder"
android:paddingLeft="2dip" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:gravity="center_vertical"
android:paddingRight="8dip">
<View
android:id="@+id/chip"
android:background="@drawable/appointment_indicator_leftside_1"
android:layout_width="4dip"
android:layout_height="match_parent"
android:layout_centerVertical="true" />
<ImageView
android:id="@+id/folder_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_list_folder"
android:paddingLeft="2dip" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:gravity="center_vertical"
android:paddingLeft="4dip">
<!--
STOPSHIP android:textColor="?android:attr/textColorPrimary"
which was somehow white in the "move to" dialog.
-->
<TextView
android:id="@+id/mailbox_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#000" />
</LinearLayout>
android:paddingLeft="4dip">
<!--
STOPSHIP android:textColor="?android:attr/textColorPrimary"
which was somehow white in the "move to" dialog.
-->
<TextView
android:id="@+id/new_message_count"
android:id="@+id/mailbox_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="4dip"
android:background="@drawable/ind_unread"
style="@style/unreadCount"/>
<TextView
android:id="@+id/all_message_count"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="4dip"
android:background="@drawable/ind_sum"
style="@style/unreadCount"/>
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#000" />
</LinearLayout>
</com.android.email.activity.MailboxListItem>
<TextView
android:id="@+id/new_message_count"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="4dip"
android:background="@drawable/ind_unread"
style="@style/unreadCount"/>
<TextView
android:id="@+id/all_message_count"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="4dip"
android:background="@drawable/ind_sum"
style="@style/unreadCount"/>
</LinearLayout>

View File

@ -1,89 +0,0 @@
/*
* Copyright (C) 2010 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.
*/
package com.android.email.activity;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.widget.Checkable;
import android.widget.FrameLayout;
/**
* Base layout that changes its background when checked.
*/
public abstract class CheckableFrameLayout extends FrameLayout implements Checkable {
private boolean mChecked = false;
private Drawable mCheckedBackgroundDrawable;
private static final int[] CHECKED_STATE_SET = { android.R.attr.state_checked };
public CheckableFrameLayout(Context context) {
super(context);
}
public CheckableFrameLayout(Context context, AttributeSet attrs) {
super(context, attrs);
}
public CheckableFrameLayout(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
@Override
public int[] onCreateDrawableState(int extraSpace) {
final int[] drawableState = super.onCreateDrawableState(extraSpace + 1);
if (isChecked()) {
mergeDrawableStates(drawableState, CHECKED_STATE_SET);
}
return drawableState;
}
@Override
public void toggle() {
setChecked(!mChecked);
}
@Override
public boolean isChecked() {
return mChecked;
}
@Override
public void setChecked(boolean checked) {
if (mChecked != checked) {
mChecked = checked;
updateBackground();
}
}
private void updateBackground() {
if (mChecked) {
if (mCheckedBackgroundDrawable == null) {
mCheckedBackgroundDrawable = getCheckedBackground();
}
setBackgroundDrawable(mCheckedBackgroundDrawable);
} else {
setBackgroundDrawable(null);
}
}
/**
* Subclass implements this and returns the {@link Drawable} for the background for the checked
* state.
*/
protected abstract Drawable getCheckedBackground();
}

View File

@ -1,50 +0,0 @@
/*
* Copyright (C) 2010 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.
*/
package com.android.email.activity;
import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
/**
* List item in {@link MailboxListFragment}.
*
* Inheriting from {@link CheckableFrameLayout}, change the background when checked.
*/
public class MailboxListItem extends CheckableFrameLayout {
private static final Drawable mCheckedBackground = new ColorDrawable(Color.RED);
public MailboxListItem(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
public MailboxListItem(Context context, AttributeSet attrs) {
super(context, attrs);
}
public MailboxListItem(Context context) {
super(context);
}
@Override
protected Drawable getCheckedBackground() {
return mCheckedBackground;
}
}