1486b78e42652466f6241eb87d5bed60040db7a25John Spurlock/*
2486b78e42652466f6241eb87d5bed60040db7a25John Spurlock * Copyright (C) 2014 The Android Open Source Project
3486b78e42652466f6241eb87d5bed60040db7a25John Spurlock *
4486b78e42652466f6241eb87d5bed60040db7a25John Spurlock * Licensed under the Apache License, Version 2.0 (the "License");
5486b78e42652466f6241eb87d5bed60040db7a25John Spurlock * you may not use this file except in compliance with the License.
6486b78e42652466f6241eb87d5bed60040db7a25John Spurlock * You may obtain a copy of the License at
7486b78e42652466f6241eb87d5bed60040db7a25John Spurlock *
8486b78e42652466f6241eb87d5bed60040db7a25John Spurlock *      http://www.apache.org/licenses/LICENSE-2.0
9486b78e42652466f6241eb87d5bed60040db7a25John Spurlock *
10486b78e42652466f6241eb87d5bed60040db7a25John Spurlock * Unless required by applicable law or agreed to in writing, software
11486b78e42652466f6241eb87d5bed60040db7a25John Spurlock * distributed under the License is distributed on an "AS IS" BASIS,
12486b78e42652466f6241eb87d5bed60040db7a25John Spurlock * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13486b78e42652466f6241eb87d5bed60040db7a25John Spurlock * See the License for the specific language governing permissions and
14486b78e42652466f6241eb87d5bed60040db7a25John Spurlock * limitations under the License.
15486b78e42652466f6241eb87d5bed60040db7a25John Spurlock */
16486b78e42652466f6241eb87d5bed60040db7a25John Spurlock
17486b78e42652466f6241eb87d5bed60040db7a25John Spurlockpackage com.android.systemui.qs;
18486b78e42652466f6241eb87d5bed60040db7a25John Spurlock
19486b78e42652466f6241eb87d5bed60040db7a25John Spurlockimport android.content.Context;
20e17c4b49a41ec9de5c1d7f229273fc4677ec24b1Jorim Jaggiimport android.content.res.Configuration;
21b27ec6d37d277fe54cb8b85590758a7ad1767ff0Jason Monkimport android.graphics.drawable.Drawable;
22486b78e42652466f6241eb87d5bed60040db7a25John Spurlockimport android.os.Handler;
23486b78e42652466f6241eb87d5bed60040db7a25John Spurlockimport android.os.Looper;
24486b78e42652466f6241eb87d5bed60040db7a25John Spurlockimport android.os.Message;
25486b78e42652466f6241eb87d5bed60040db7a25John Spurlockimport android.text.TextUtils;
26486b78e42652466f6241eb87d5bed60040db7a25John Spurlockimport android.util.AttributeSet;
27486b78e42652466f6241eb87d5bed60040db7a25John Spurlockimport android.util.Log;
28486b78e42652466f6241eb87d5bed60040db7a25John Spurlockimport android.view.LayoutInflater;
29486b78e42652466f6241eb87d5bed60040db7a25John Spurlockimport android.view.View;
30486b78e42652466f6241eb87d5bed60040db7a25John Spurlockimport android.view.ViewGroup;
31486b78e42652466f6241eb87d5bed60040db7a25John Spurlockimport android.widget.FrameLayout;
32486b78e42652466f6241eb87d5bed60040db7a25John Spurlockimport android.widget.ImageView;
33486b78e42652466f6241eb87d5bed60040db7a25John Spurlockimport android.widget.LinearLayout;
34486b78e42652466f6241eb87d5bed60040db7a25John Spurlockimport android.widget.TextView;
35486b78e42652466f6241eb87d5bed60040db7a25John Spurlock
36e17c4b49a41ec9de5c1d7f229273fc4677ec24b1Jorim Jaggiimport com.android.systemui.FontSizeUtils;
37486b78e42652466f6241eb87d5bed60040db7a25John Spurlockimport com.android.systemui.R;
38486b78e42652466f6241eb87d5bed60040db7a25John Spurlock
39486b78e42652466f6241eb87d5bed60040db7a25John Spurlock/**
40486b78e42652466f6241eb87d5bed60040db7a25John Spurlock * Quick settings common detail view with line items.
41486b78e42652466f6241eb87d5bed60040db7a25John Spurlock */
42486b78e42652466f6241eb87d5bed60040db7a25John Spurlockpublic class QSDetailItems extends FrameLayout {
43486b78e42652466f6241eb87d5bed60040db7a25John Spurlock    private static final String TAG = "QSDetailItems";
44486b78e42652466f6241eb87d5bed60040db7a25John Spurlock    private static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG);
45486b78e42652466f6241eb87d5bed60040db7a25John Spurlock
46486b78e42652466f6241eb87d5bed60040db7a25John Spurlock    private final Context mContext;
47486b78e42652466f6241eb87d5bed60040db7a25John Spurlock    private final H mHandler = new H();
48486b78e42652466f6241eb87d5bed60040db7a25John Spurlock
49486b78e42652466f6241eb87d5bed60040db7a25John Spurlock    private String mTag;
50486b78e42652466f6241eb87d5bed60040db7a25John Spurlock    private Callback mCallback;
51486b78e42652466f6241eb87d5bed60040db7a25John Spurlock    private boolean mItemsVisible = true;
52486b78e42652466f6241eb87d5bed60040db7a25John Spurlock    private LinearLayout mItems;
53486b78e42652466f6241eb87d5bed60040db7a25John Spurlock    private View mEmpty;
540ed01deb2fc99603a33f968044703a740673c7b3Jorim Jaggi    private View mMinHeightSpacer;
55486b78e42652466f6241eb87d5bed60040db7a25John Spurlock    private TextView mEmptyText;
56486b78e42652466f6241eb87d5bed60040db7a25John Spurlock    private ImageView mEmptyIcon;
570ed01deb2fc99603a33f968044703a740673c7b3Jorim Jaggi    private int mMaxItems;
58486b78e42652466f6241eb87d5bed60040db7a25John Spurlock
59486b78e42652466f6241eb87d5bed60040db7a25John Spurlock    public QSDetailItems(Context context, AttributeSet attrs) {
60486b78e42652466f6241eb87d5bed60040db7a25John Spurlock        super(context, attrs);
61486b78e42652466f6241eb87d5bed60040db7a25John Spurlock        mContext = context;
62486b78e42652466f6241eb87d5bed60040db7a25John Spurlock        mTag = TAG;
63486b78e42652466f6241eb87d5bed60040db7a25John Spurlock    }
64486b78e42652466f6241eb87d5bed60040db7a25John Spurlock
65486b78e42652466f6241eb87d5bed60040db7a25John Spurlock    public static QSDetailItems convertOrInflate(Context context, View convert, ViewGroup parent) {
66486b78e42652466f6241eb87d5bed60040db7a25John Spurlock        if (convert instanceof QSDetailItems) {
67486b78e42652466f6241eb87d5bed60040db7a25John Spurlock            return (QSDetailItems) convert;
68486b78e42652466f6241eb87d5bed60040db7a25John Spurlock        }
69486b78e42652466f6241eb87d5bed60040db7a25John Spurlock        return (QSDetailItems) LayoutInflater.from(context).inflate(R.layout.qs_detail_items,
70486b78e42652466f6241eb87d5bed60040db7a25John Spurlock                parent, false);
71486b78e42652466f6241eb87d5bed60040db7a25John Spurlock    }
72486b78e42652466f6241eb87d5bed60040db7a25John Spurlock
73486b78e42652466f6241eb87d5bed60040db7a25John Spurlock    @Override
74486b78e42652466f6241eb87d5bed60040db7a25John Spurlock    protected void onFinishInflate() {
75486b78e42652466f6241eb87d5bed60040db7a25John Spurlock        super.onFinishInflate();
76486b78e42652466f6241eb87d5bed60040db7a25John Spurlock        mItems = (LinearLayout) findViewById(android.R.id.list);
77486b78e42652466f6241eb87d5bed60040db7a25John Spurlock        mItems.setVisibility(GONE);
78486b78e42652466f6241eb87d5bed60040db7a25John Spurlock        mEmpty = findViewById(android.R.id.empty);
79486b78e42652466f6241eb87d5bed60040db7a25John Spurlock        mEmpty.setVisibility(GONE);
80486b78e42652466f6241eb87d5bed60040db7a25John Spurlock        mEmptyText = (TextView) mEmpty.findViewById(android.R.id.title);
81486b78e42652466f6241eb87d5bed60040db7a25John Spurlock        mEmptyIcon = (ImageView) mEmpty.findViewById(android.R.id.icon);
820ed01deb2fc99603a33f968044703a740673c7b3Jorim Jaggi        mMinHeightSpacer = findViewById(R.id.min_height_spacer);
830ed01deb2fc99603a33f968044703a740673c7b3Jorim Jaggi
840ed01deb2fc99603a33f968044703a740673c7b3Jorim Jaggi        // By default, a detail item view has fixed size.
850ed01deb2fc99603a33f968044703a740673c7b3Jorim Jaggi        mMaxItems = getResources().getInteger(
860ed01deb2fc99603a33f968044703a740673c7b3Jorim Jaggi                R.integer.quick_settings_detail_max_item_count);
870ed01deb2fc99603a33f968044703a740673c7b3Jorim Jaggi        setMinHeightInItems(mMaxItems);
88486b78e42652466f6241eb87d5bed60040db7a25John Spurlock    }
89486b78e42652466f6241eb87d5bed60040db7a25John Spurlock
90e17c4b49a41ec9de5c1d7f229273fc4677ec24b1Jorim Jaggi    @Override
91e17c4b49a41ec9de5c1d7f229273fc4677ec24b1Jorim Jaggi    protected void onConfigurationChanged(Configuration newConfig) {
92e17c4b49a41ec9de5c1d7f229273fc4677ec24b1Jorim Jaggi        super.onConfigurationChanged(newConfig);
93e17c4b49a41ec9de5c1d7f229273fc4677ec24b1Jorim Jaggi        FontSizeUtils.updateFontSize(mEmptyText, R.dimen.qs_detail_empty_text_size);
94e17c4b49a41ec9de5c1d7f229273fc4677ec24b1Jorim Jaggi        int count = mItems.getChildCount();
95e17c4b49a41ec9de5c1d7f229273fc4677ec24b1Jorim Jaggi        for (int i = 0; i < count; i++) {
96e17c4b49a41ec9de5c1d7f229273fc4677ec24b1Jorim Jaggi            View item = mItems.getChildAt(i);
97e17c4b49a41ec9de5c1d7f229273fc4677ec24b1Jorim Jaggi            FontSizeUtils.updateFontSize(item, android.R.id.title,
98e17c4b49a41ec9de5c1d7f229273fc4677ec24b1Jorim Jaggi                    R.dimen.qs_detail_item_primary_text_size);
99e17c4b49a41ec9de5c1d7f229273fc4677ec24b1Jorim Jaggi            FontSizeUtils.updateFontSize(item, android.R.id.summary,
100e17c4b49a41ec9de5c1d7f229273fc4677ec24b1Jorim Jaggi                    R.dimen.qs_detail_item_secondary_text_size);
101e17c4b49a41ec9de5c1d7f229273fc4677ec24b1Jorim Jaggi        }
102e17c4b49a41ec9de5c1d7f229273fc4677ec24b1Jorim Jaggi    }
103e17c4b49a41ec9de5c1d7f229273fc4677ec24b1Jorim Jaggi
104486b78e42652466f6241eb87d5bed60040db7a25John Spurlock    public void setTagSuffix(String suffix) {
105486b78e42652466f6241eb87d5bed60040db7a25John Spurlock        mTag = TAG + "." + suffix;
106486b78e42652466f6241eb87d5bed60040db7a25John Spurlock    }
107486b78e42652466f6241eb87d5bed60040db7a25John Spurlock
108486b78e42652466f6241eb87d5bed60040db7a25John Spurlock    public void setEmptyState(int icon, int text) {
109486b78e42652466f6241eb87d5bed60040db7a25John Spurlock        mEmptyIcon.setImageResource(icon);
110486b78e42652466f6241eb87d5bed60040db7a25John Spurlock        mEmptyText.setText(text);
111486b78e42652466f6241eb87d5bed60040db7a25John Spurlock    }
112486b78e42652466f6241eb87d5bed60040db7a25John Spurlock
1130ed01deb2fc99603a33f968044703a740673c7b3Jorim Jaggi    /**
1140ed01deb2fc99603a33f968044703a740673c7b3Jorim Jaggi     * Set the minimum height of this detail view, in item count.
1150ed01deb2fc99603a33f968044703a740673c7b3Jorim Jaggi     */
1160ed01deb2fc99603a33f968044703a740673c7b3Jorim Jaggi    public void setMinHeightInItems(int minHeightInItems) {
1170ed01deb2fc99603a33f968044703a740673c7b3Jorim Jaggi        ViewGroup.LayoutParams lp = mMinHeightSpacer.getLayoutParams();
1180ed01deb2fc99603a33f968044703a740673c7b3Jorim Jaggi        lp.height = minHeightInItems * getResources().getDimensionPixelSize(
1190ed01deb2fc99603a33f968044703a740673c7b3Jorim Jaggi                R.dimen.qs_detail_item_height);
1200ed01deb2fc99603a33f968044703a740673c7b3Jorim Jaggi        mMinHeightSpacer.setLayoutParams(lp);
1210ed01deb2fc99603a33f968044703a740673c7b3Jorim Jaggi    }
1220ed01deb2fc99603a33f968044703a740673c7b3Jorim Jaggi
123486b78e42652466f6241eb87d5bed60040db7a25John Spurlock    @Override
124486b78e42652466f6241eb87d5bed60040db7a25John Spurlock    protected void onAttachedToWindow() {
125486b78e42652466f6241eb87d5bed60040db7a25John Spurlock        super.onAttachedToWindow();
126486b78e42652466f6241eb87d5bed60040db7a25John Spurlock        if (DEBUG) Log.d(mTag, "onAttachedToWindow");
127486b78e42652466f6241eb87d5bed60040db7a25John Spurlock    }
128486b78e42652466f6241eb87d5bed60040db7a25John Spurlock
129486b78e42652466f6241eb87d5bed60040db7a25John Spurlock    @Override
130486b78e42652466f6241eb87d5bed60040db7a25John Spurlock    protected void onDetachedFromWindow() {
131486b78e42652466f6241eb87d5bed60040db7a25John Spurlock        super.onDetachedFromWindow();
132486b78e42652466f6241eb87d5bed60040db7a25John Spurlock        if (DEBUG) Log.d(mTag, "onDetachedFromWindow");
133486b78e42652466f6241eb87d5bed60040db7a25John Spurlock        mCallback = null;
134486b78e42652466f6241eb87d5bed60040db7a25John Spurlock    }
135486b78e42652466f6241eb87d5bed60040db7a25John Spurlock
136486b78e42652466f6241eb87d5bed60040db7a25John Spurlock    public void setCallback(Callback callback) {
137486b78e42652466f6241eb87d5bed60040db7a25John Spurlock        mHandler.removeMessages(H.SET_CALLBACK);
138486b78e42652466f6241eb87d5bed60040db7a25John Spurlock        mHandler.obtainMessage(H.SET_CALLBACK, callback).sendToTarget();
139486b78e42652466f6241eb87d5bed60040db7a25John Spurlock    }
140486b78e42652466f6241eb87d5bed60040db7a25John Spurlock
141486b78e42652466f6241eb87d5bed60040db7a25John Spurlock    public void setItems(Item[] items) {
142486b78e42652466f6241eb87d5bed60040db7a25John Spurlock        mHandler.removeMessages(H.SET_ITEMS);
143486b78e42652466f6241eb87d5bed60040db7a25John Spurlock        mHandler.obtainMessage(H.SET_ITEMS, items).sendToTarget();
144486b78e42652466f6241eb87d5bed60040db7a25John Spurlock    }
145486b78e42652466f6241eb87d5bed60040db7a25John Spurlock
146486b78e42652466f6241eb87d5bed60040db7a25John Spurlock    public void setItemsVisible(boolean visible) {
147486b78e42652466f6241eb87d5bed60040db7a25John Spurlock        mHandler.removeMessages(H.SET_ITEMS_VISIBLE);
148486b78e42652466f6241eb87d5bed60040db7a25John Spurlock        mHandler.obtainMessage(H.SET_ITEMS_VISIBLE, visible ? 1 : 0, 0).sendToTarget();
149486b78e42652466f6241eb87d5bed60040db7a25John Spurlock    }
150486b78e42652466f6241eb87d5bed60040db7a25John Spurlock
151486b78e42652466f6241eb87d5bed60040db7a25John Spurlock    private void handleSetCallback(Callback callback) {
152486b78e42652466f6241eb87d5bed60040db7a25John Spurlock        mCallback = callback;
153486b78e42652466f6241eb87d5bed60040db7a25John Spurlock    }
154486b78e42652466f6241eb87d5bed60040db7a25John Spurlock
155486b78e42652466f6241eb87d5bed60040db7a25John Spurlock    private void handleSetItems(Item[] items) {
1560ed01deb2fc99603a33f968044703a740673c7b3Jorim Jaggi        final int itemCount = items != null ? Math.min(items.length, mMaxItems) : 0;
157486b78e42652466f6241eb87d5bed60040db7a25John Spurlock        mEmpty.setVisibility(itemCount == 0 ? VISIBLE : GONE);
158486b78e42652466f6241eb87d5bed60040db7a25John Spurlock        mItems.setVisibility(itemCount == 0 ? GONE : VISIBLE);
159486b78e42652466f6241eb87d5bed60040db7a25John Spurlock        for (int i = mItems.getChildCount() - 1; i >= itemCount; i--) {
160486b78e42652466f6241eb87d5bed60040db7a25John Spurlock            mItems.removeViewAt(i);
161486b78e42652466f6241eb87d5bed60040db7a25John Spurlock        }
162486b78e42652466f6241eb87d5bed60040db7a25John Spurlock        for (int i = 0; i < itemCount; i++) {
163486b78e42652466f6241eb87d5bed60040db7a25John Spurlock            bind(items[i], mItems.getChildAt(i));
164486b78e42652466f6241eb87d5bed60040db7a25John Spurlock        }
165486b78e42652466f6241eb87d5bed60040db7a25John Spurlock    }
166486b78e42652466f6241eb87d5bed60040db7a25John Spurlock
167486b78e42652466f6241eb87d5bed60040db7a25John Spurlock    private void handleSetItemsVisible(boolean visible) {
168486b78e42652466f6241eb87d5bed60040db7a25John Spurlock        if (mItemsVisible == visible) return;
169486b78e42652466f6241eb87d5bed60040db7a25John Spurlock        mItemsVisible = visible;
170486b78e42652466f6241eb87d5bed60040db7a25John Spurlock        for (int i = 0; i < mItems.getChildCount(); i++) {
171486b78e42652466f6241eb87d5bed60040db7a25John Spurlock            mItems.getChildAt(i).setVisibility(mItemsVisible ? VISIBLE : INVISIBLE);
172486b78e42652466f6241eb87d5bed60040db7a25John Spurlock        }
173486b78e42652466f6241eb87d5bed60040db7a25John Spurlock    }
174486b78e42652466f6241eb87d5bed60040db7a25John Spurlock
175486b78e42652466f6241eb87d5bed60040db7a25John Spurlock    private void bind(final Item item, View view) {
176486b78e42652466f6241eb87d5bed60040db7a25John Spurlock        if (view == null) {
177486b78e42652466f6241eb87d5bed60040db7a25John Spurlock            view = LayoutInflater.from(mContext).inflate(R.layout.qs_detail_item, this, false);
178486b78e42652466f6241eb87d5bed60040db7a25John Spurlock            mItems.addView(view);
179486b78e42652466f6241eb87d5bed60040db7a25John Spurlock        }
180486b78e42652466f6241eb87d5bed60040db7a25John Spurlock        view.setVisibility(mItemsVisible ? VISIBLE : INVISIBLE);
181486b78e42652466f6241eb87d5bed60040db7a25John Spurlock        final ImageView iv = (ImageView) view.findViewById(android.R.id.icon);
182486b78e42652466f6241eb87d5bed60040db7a25John Spurlock        iv.setImageResource(item.icon);
183b27ec6d37d277fe54cb8b85590758a7ad1767ff0Jason Monk        iv.getOverlay().clear();
184b27ec6d37d277fe54cb8b85590758a7ad1767ff0Jason Monk        if (item.overlay != null) {
185b27ec6d37d277fe54cb8b85590758a7ad1767ff0Jason Monk            item.overlay.setBounds(0, 0, item.overlay.getIntrinsicWidth(),
186b27ec6d37d277fe54cb8b85590758a7ad1767ff0Jason Monk                    item.overlay.getIntrinsicHeight());
187b27ec6d37d277fe54cb8b85590758a7ad1767ff0Jason Monk            iv.getOverlay().add(item.overlay);
188b27ec6d37d277fe54cb8b85590758a7ad1767ff0Jason Monk        }
189486b78e42652466f6241eb87d5bed60040db7a25John Spurlock        final TextView title = (TextView) view.findViewById(android.R.id.title);
190486b78e42652466f6241eb87d5bed60040db7a25John Spurlock        title.setText(item.line1);
191486b78e42652466f6241eb87d5bed60040db7a25John Spurlock        final TextView summary = (TextView) view.findViewById(android.R.id.summary);
192486b78e42652466f6241eb87d5bed60040db7a25John Spurlock        final boolean twoLines = !TextUtils.isEmpty(item.line2);
193867874b06a5918d727838e6b3d77e8c3f62df300Jason Monk        title.setMaxLines(twoLines ? 1 : 2);
194486b78e42652466f6241eb87d5bed60040db7a25John Spurlock        summary.setVisibility(twoLines ? VISIBLE : GONE);
195486b78e42652466f6241eb87d5bed60040db7a25John Spurlock        summary.setText(twoLines ? item.line2 : null);
196486b78e42652466f6241eb87d5bed60040db7a25John Spurlock        view.setMinimumHeight(mContext.getResources() .getDimensionPixelSize(
197486b78e42652466f6241eb87d5bed60040db7a25John Spurlock                twoLines ? R.dimen.qs_detail_item_height_twoline : R.dimen.qs_detail_item_height));
198486b78e42652466f6241eb87d5bed60040db7a25John Spurlock        view.setOnClickListener(new OnClickListener() {
199486b78e42652466f6241eb87d5bed60040db7a25John Spurlock            @Override
200486b78e42652466f6241eb87d5bed60040db7a25John Spurlock            public void onClick(View v) {
201486b78e42652466f6241eb87d5bed60040db7a25John Spurlock                if (mCallback != null) {
202486b78e42652466f6241eb87d5bed60040db7a25John Spurlock                    mCallback.onDetailItemClick(item);
203486b78e42652466f6241eb87d5bed60040db7a25John Spurlock                }
204486b78e42652466f6241eb87d5bed60040db7a25John Spurlock            }
205486b78e42652466f6241eb87d5bed60040db7a25John Spurlock        });
206486b78e42652466f6241eb87d5bed60040db7a25John Spurlock        final ImageView disconnect = (ImageView) view.findViewById(android.R.id.icon2);
207486b78e42652466f6241eb87d5bed60040db7a25John Spurlock        disconnect.setVisibility(item.canDisconnect ? VISIBLE : GONE);
208486b78e42652466f6241eb87d5bed60040db7a25John Spurlock        disconnect.setOnClickListener(new OnClickListener() {
209486b78e42652466f6241eb87d5bed60040db7a25John Spurlock            @Override
210486b78e42652466f6241eb87d5bed60040db7a25John Spurlock            public void onClick(View v) {
211486b78e42652466f6241eb87d5bed60040db7a25John Spurlock                if (mCallback != null) {
212486b78e42652466f6241eb87d5bed60040db7a25John Spurlock                    mCallback.onDetailItemDisconnect(item);
213486b78e42652466f6241eb87d5bed60040db7a25John Spurlock                }
214486b78e42652466f6241eb87d5bed60040db7a25John Spurlock            }
215486b78e42652466f6241eb87d5bed60040db7a25John Spurlock        });
216486b78e42652466f6241eb87d5bed60040db7a25John Spurlock    }
217486b78e42652466f6241eb87d5bed60040db7a25John Spurlock
218486b78e42652466f6241eb87d5bed60040db7a25John Spurlock    private class H extends Handler {
219486b78e42652466f6241eb87d5bed60040db7a25John Spurlock        private static final int SET_ITEMS = 1;
220486b78e42652466f6241eb87d5bed60040db7a25John Spurlock        private static final int SET_CALLBACK = 2;
221486b78e42652466f6241eb87d5bed60040db7a25John Spurlock        private static final int SET_ITEMS_VISIBLE = 3;
222486b78e42652466f6241eb87d5bed60040db7a25John Spurlock
223486b78e42652466f6241eb87d5bed60040db7a25John Spurlock        public H() {
224486b78e42652466f6241eb87d5bed60040db7a25John Spurlock            super(Looper.getMainLooper());
225486b78e42652466f6241eb87d5bed60040db7a25John Spurlock        }
226486b78e42652466f6241eb87d5bed60040db7a25John Spurlock
227486b78e42652466f6241eb87d5bed60040db7a25John Spurlock        @Override
228486b78e42652466f6241eb87d5bed60040db7a25John Spurlock        public void handleMessage(Message msg) {
229486b78e42652466f6241eb87d5bed60040db7a25John Spurlock            if (msg.what == SET_ITEMS) {
230486b78e42652466f6241eb87d5bed60040db7a25John Spurlock                handleSetItems((Item[]) msg.obj);
231486b78e42652466f6241eb87d5bed60040db7a25John Spurlock            } else if (msg.what == SET_CALLBACK) {
232486b78e42652466f6241eb87d5bed60040db7a25John Spurlock                handleSetCallback((QSDetailItems.Callback) msg.obj);
233486b78e42652466f6241eb87d5bed60040db7a25John Spurlock            } else if (msg.what == SET_ITEMS_VISIBLE) {
234486b78e42652466f6241eb87d5bed60040db7a25John Spurlock                handleSetItemsVisible(msg.arg1 != 0);
235486b78e42652466f6241eb87d5bed60040db7a25John Spurlock            }
236486b78e42652466f6241eb87d5bed60040db7a25John Spurlock        }
237486b78e42652466f6241eb87d5bed60040db7a25John Spurlock    }
238486b78e42652466f6241eb87d5bed60040db7a25John Spurlock
239486b78e42652466f6241eb87d5bed60040db7a25John Spurlock    public static class Item {
240486b78e42652466f6241eb87d5bed60040db7a25John Spurlock        public int icon;
241b27ec6d37d277fe54cb8b85590758a7ad1767ff0Jason Monk        public Drawable overlay;
242486b78e42652466f6241eb87d5bed60040db7a25John Spurlock        public String line1;
243486b78e42652466f6241eb87d5bed60040db7a25John Spurlock        public String line2;
244486b78e42652466f6241eb87d5bed60040db7a25John Spurlock        public Object tag;
245486b78e42652466f6241eb87d5bed60040db7a25John Spurlock        public boolean canDisconnect;
246486b78e42652466f6241eb87d5bed60040db7a25John Spurlock    }
247486b78e42652466f6241eb87d5bed60040db7a25John Spurlock
248486b78e42652466f6241eb87d5bed60040db7a25John Spurlock    public interface Callback {
249486b78e42652466f6241eb87d5bed60040db7a25John Spurlock        void onDetailItemClick(Item item);
250486b78e42652466f6241eb87d5bed60040db7a25John Spurlock        void onDetailItemDisconnect(Item item);
251486b78e42652466f6241eb87d5bed60040db7a25John Spurlock    }
252486b78e42652466f6241eb87d5bed60040db7a25John Spurlock}
253