1744b63632a0d41eabf60e95a7b61e235e43f6d07Jason Monk/** 2744b63632a0d41eabf60e95a7b61e235e43f6d07Jason Monk * Copyright (C) 2015 The Android Open Source Project 3744b63632a0d41eabf60e95a7b61e235e43f6d07Jason Monk * 4744b63632a0d41eabf60e95a7b61e235e43f6d07Jason Monk * Licensed under the Apache License, Version 2.0 (the "License"); 5744b63632a0d41eabf60e95a7b61e235e43f6d07Jason Monk * you may not use this file except in compliance with the License. 6744b63632a0d41eabf60e95a7b61e235e43f6d07Jason Monk * You may obtain a copy of the License at 7744b63632a0d41eabf60e95a7b61e235e43f6d07Jason Monk * 8744b63632a0d41eabf60e95a7b61e235e43f6d07Jason Monk * http://www.apache.org/licenses/LICENSE-2.0 9744b63632a0d41eabf60e95a7b61e235e43f6d07Jason Monk * 10744b63632a0d41eabf60e95a7b61e235e43f6d07Jason Monk * Unless required by applicable law or agreed to in writing, software 11744b63632a0d41eabf60e95a7b61e235e43f6d07Jason Monk * distributed under the License is distributed on an "AS IS" BASIS, 12744b63632a0d41eabf60e95a7b61e235e43f6d07Jason Monk * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13744b63632a0d41eabf60e95a7b61e235e43f6d07Jason Monk * See the License for the specific language governing permissions and 14744b63632a0d41eabf60e95a7b61e235e43f6d07Jason Monk * limitations under the License. 15744b63632a0d41eabf60e95a7b61e235e43f6d07Jason Monk */ 16744b63632a0d41eabf60e95a7b61e235e43f6d07Jason Monk 17744b63632a0d41eabf60e95a7b61e235e43f6d07Jason Monkpackage com.android.settingslib.drawer; 18744b63632a0d41eabf60e95a7b61e235e43f6d07Jason Monk 19744b63632a0d41eabf60e95a7b61e235e43f6d07Jason Monkimport android.content.Intent; 20744b63632a0d41eabf60e95a7b61e235e43f6d07Jason Monkimport android.graphics.drawable.Icon; 21744b63632a0d41eabf60e95a7b61e235e43f6d07Jason Monkimport android.os.Bundle; 22744b63632a0d41eabf60e95a7b61e235e43f6d07Jason Monkimport android.os.Parcel; 23744b63632a0d41eabf60e95a7b61e235e43f6d07Jason Monkimport android.os.Parcelable; 24744b63632a0d41eabf60e95a7b61e235e43f6d07Jason Monkimport android.os.UserHandle; 25744b63632a0d41eabf60e95a7b61e235e43f6d07Jason Monkimport android.text.TextUtils; 26d8ae77b7f593528896b33bdd2755fa9562735472Maurice Lamimport android.widget.RemoteViews; 27744b63632a0d41eabf60e95a7b61e235e43f6d07Jason Monk 28744b63632a0d41eabf60e95a7b61e235e43f6d07Jason Monkimport java.util.ArrayList; 29744b63632a0d41eabf60e95a7b61e235e43f6d07Jason Monk 30744b63632a0d41eabf60e95a7b61e235e43f6d07Jason Monk/** 31744b63632a0d41eabf60e95a7b61e235e43f6d07Jason Monk * Description of a single dashboard tile that the user can select. 32744b63632a0d41eabf60e95a7b61e235e43f6d07Jason Monk */ 33f509d7e65a062957be86619b3cb894e99268c4aeJason Monkpublic class Tile implements Parcelable { 34744b63632a0d41eabf60e95a7b61e235e43f6d07Jason Monk 35744b63632a0d41eabf60e95a7b61e235e43f6d07Jason Monk /** 36744b63632a0d41eabf60e95a7b61e235e43f6d07Jason Monk * Title of the tile that is shown to the user. 37744b63632a0d41eabf60e95a7b61e235e43f6d07Jason Monk * @attr ref android.R.styleable#PreferenceHeader_title 38744b63632a0d41eabf60e95a7b61e235e43f6d07Jason Monk */ 39744b63632a0d41eabf60e95a7b61e235e43f6d07Jason Monk public CharSequence title; 40744b63632a0d41eabf60e95a7b61e235e43f6d07Jason Monk 41744b63632a0d41eabf60e95a7b61e235e43f6d07Jason Monk /** 42744b63632a0d41eabf60e95a7b61e235e43f6d07Jason Monk * Optional summary describing what this tile controls. 43744b63632a0d41eabf60e95a7b61e235e43f6d07Jason Monk * @attr ref android.R.styleable#PreferenceHeader_summary 44744b63632a0d41eabf60e95a7b61e235e43f6d07Jason Monk */ 45744b63632a0d41eabf60e95a7b61e235e43f6d07Jason Monk public CharSequence summary; 46744b63632a0d41eabf60e95a7b61e235e43f6d07Jason Monk 47744b63632a0d41eabf60e95a7b61e235e43f6d07Jason Monk /** 48744b63632a0d41eabf60e95a7b61e235e43f6d07Jason Monk * Optional icon to show for this tile. 49744b63632a0d41eabf60e95a7b61e235e43f6d07Jason Monk * @attr ref android.R.styleable#PreferenceHeader_icon 50744b63632a0d41eabf60e95a7b61e235e43f6d07Jason Monk */ 51744b63632a0d41eabf60e95a7b61e235e43f6d07Jason Monk public Icon icon; 52744b63632a0d41eabf60e95a7b61e235e43f6d07Jason Monk 53744b63632a0d41eabf60e95a7b61e235e43f6d07Jason Monk /** 54b10c6ffbaa2aa0c6f158415d028ce691385a7a83Maurice Lam * Whether the icon can be tinted. This should be set to true for monochrome (single-color) 55b10c6ffbaa2aa0c6f158415d028ce691385a7a83Maurice Lam * icons that can be tinted to match the design. 56b10c6ffbaa2aa0c6f158415d028ce691385a7a83Maurice Lam */ 57b10c6ffbaa2aa0c6f158415d028ce691385a7a83Maurice Lam public boolean isIconTintable; 58b10c6ffbaa2aa0c6f158415d028ce691385a7a83Maurice Lam 59b10c6ffbaa2aa0c6f158415d028ce691385a7a83Maurice Lam /** 60744b63632a0d41eabf60e95a7b61e235e43f6d07Jason Monk * Intent to launch when the preference is selected. 61744b63632a0d41eabf60e95a7b61e235e43f6d07Jason Monk */ 62744b63632a0d41eabf60e95a7b61e235e43f6d07Jason Monk public Intent intent; 63744b63632a0d41eabf60e95a7b61e235e43f6d07Jason Monk 64744b63632a0d41eabf60e95a7b61e235e43f6d07Jason Monk /** 65744b63632a0d41eabf60e95a7b61e235e43f6d07Jason Monk * Optional list of user handles which the intent should be launched on. 66744b63632a0d41eabf60e95a7b61e235e43f6d07Jason Monk */ 67744b63632a0d41eabf60e95a7b61e235e43f6d07Jason Monk public ArrayList<UserHandle> userHandle = new ArrayList<>(); 68744b63632a0d41eabf60e95a7b61e235e43f6d07Jason Monk 69744b63632a0d41eabf60e95a7b61e235e43f6d07Jason Monk /** 70744b63632a0d41eabf60e95a7b61e235e43f6d07Jason Monk * Optional additional data for use by subclasses of the activity 71744b63632a0d41eabf60e95a7b61e235e43f6d07Jason Monk */ 72744b63632a0d41eabf60e95a7b61e235e43f6d07Jason Monk public Bundle extras; 73744b63632a0d41eabf60e95a7b61e235e43f6d07Jason Monk 74744b63632a0d41eabf60e95a7b61e235e43f6d07Jason Monk /** 75744b63632a0d41eabf60e95a7b61e235e43f6d07Jason Monk * Category in which the tile should be placed. 76744b63632a0d41eabf60e95a7b61e235e43f6d07Jason Monk */ 77744b63632a0d41eabf60e95a7b61e235e43f6d07Jason Monk public String category; 78744b63632a0d41eabf60e95a7b61e235e43f6d07Jason Monk 79744b63632a0d41eabf60e95a7b61e235e43f6d07Jason Monk /** 80744b63632a0d41eabf60e95a7b61e235e43f6d07Jason Monk * Priority of the intent filter that created this tile, used for display ordering. 81744b63632a0d41eabf60e95a7b61e235e43f6d07Jason Monk */ 82744b63632a0d41eabf60e95a7b61e235e43f6d07Jason Monk public int priority; 83744b63632a0d41eabf60e95a7b61e235e43f6d07Jason Monk 84e79790b26803ee338b2fdc3404344094d7f94476Jason Monk /** 85e79790b26803ee338b2fdc3404344094d7f94476Jason Monk * The metaData from the activity that defines this tile. 86e79790b26803ee338b2fdc3404344094d7f94476Jason Monk */ 87e79790b26803ee338b2fdc3404344094d7f94476Jason Monk public Bundle metaData; 88e79790b26803ee338b2fdc3404344094d7f94476Jason Monk 896b32ae37461a30d5c7c1124c805a77075e543badShahriyar Amini /** 906b32ae37461a30d5c7c1124c805a77075e543badShahriyar Amini * Optional key to use for this tile. 916b32ae37461a30d5c7c1124c805a77075e543badShahriyar Amini */ 926b32ae37461a30d5c7c1124c805a77075e543badShahriyar Amini public String key; 936b32ae37461a30d5c7c1124c805a77075e543badShahriyar Amini 94d8ae77b7f593528896b33bdd2755fa9562735472Maurice Lam /** 95d8ae77b7f593528896b33bdd2755fa9562735472Maurice Lam * Optional remote view which will be displayed instead of the regular title-summary item. 96d8ae77b7f593528896b33bdd2755fa9562735472Maurice Lam */ 97d8ae77b7f593528896b33bdd2755fa9562735472Maurice Lam public RemoteViews remoteViews; 98d8ae77b7f593528896b33bdd2755fa9562735472Maurice Lam 99f509d7e65a062957be86619b3cb894e99268c4aeJason Monk public Tile() { 100744b63632a0d41eabf60e95a7b61e235e43f6d07Jason Monk // Empty 101744b63632a0d41eabf60e95a7b61e235e43f6d07Jason Monk } 102744b63632a0d41eabf60e95a7b61e235e43f6d07Jason Monk 103744b63632a0d41eabf60e95a7b61e235e43f6d07Jason Monk @Override 104744b63632a0d41eabf60e95a7b61e235e43f6d07Jason Monk public int describeContents() { 105744b63632a0d41eabf60e95a7b61e235e43f6d07Jason Monk return 0; 106744b63632a0d41eabf60e95a7b61e235e43f6d07Jason Monk } 107744b63632a0d41eabf60e95a7b61e235e43f6d07Jason Monk 108744b63632a0d41eabf60e95a7b61e235e43f6d07Jason Monk @Override 109744b63632a0d41eabf60e95a7b61e235e43f6d07Jason Monk public void writeToParcel(Parcel dest, int flags) { 110744b63632a0d41eabf60e95a7b61e235e43f6d07Jason Monk TextUtils.writeToParcel(title, dest, flags); 111744b63632a0d41eabf60e95a7b61e235e43f6d07Jason Monk TextUtils.writeToParcel(summary, dest, flags); 112744b63632a0d41eabf60e95a7b61e235e43f6d07Jason Monk if (icon != null) { 113744b63632a0d41eabf60e95a7b61e235e43f6d07Jason Monk dest.writeByte((byte) 1); 114744b63632a0d41eabf60e95a7b61e235e43f6d07Jason Monk icon.writeToParcel(dest, flags); 115744b63632a0d41eabf60e95a7b61e235e43f6d07Jason Monk } else { 116744b63632a0d41eabf60e95a7b61e235e43f6d07Jason Monk dest.writeByte((byte) 0); 117744b63632a0d41eabf60e95a7b61e235e43f6d07Jason Monk } 118744b63632a0d41eabf60e95a7b61e235e43f6d07Jason Monk if (intent != null) { 119744b63632a0d41eabf60e95a7b61e235e43f6d07Jason Monk dest.writeByte((byte) 1); 120744b63632a0d41eabf60e95a7b61e235e43f6d07Jason Monk intent.writeToParcel(dest, flags); 121744b63632a0d41eabf60e95a7b61e235e43f6d07Jason Monk } else { 122744b63632a0d41eabf60e95a7b61e235e43f6d07Jason Monk dest.writeByte((byte) 0); 123744b63632a0d41eabf60e95a7b61e235e43f6d07Jason Monk } 124744b63632a0d41eabf60e95a7b61e235e43f6d07Jason Monk final int N = userHandle.size(); 125744b63632a0d41eabf60e95a7b61e235e43f6d07Jason Monk dest.writeInt(N); 126744b63632a0d41eabf60e95a7b61e235e43f6d07Jason Monk for (int i = 0; i < N; i++) { 127744b63632a0d41eabf60e95a7b61e235e43f6d07Jason Monk userHandle.get(i).writeToParcel(dest, flags); 128744b63632a0d41eabf60e95a7b61e235e43f6d07Jason Monk } 129744b63632a0d41eabf60e95a7b61e235e43f6d07Jason Monk dest.writeBundle(extras); 130744b63632a0d41eabf60e95a7b61e235e43f6d07Jason Monk dest.writeString(category); 131744b63632a0d41eabf60e95a7b61e235e43f6d07Jason Monk dest.writeInt(priority); 132e79790b26803ee338b2fdc3404344094d7f94476Jason Monk dest.writeBundle(metaData); 1336b32ae37461a30d5c7c1124c805a77075e543badShahriyar Amini dest.writeString(key); 134d8ae77b7f593528896b33bdd2755fa9562735472Maurice Lam dest.writeParcelable(remoteViews, flags); 135b10c6ffbaa2aa0c6f158415d028ce691385a7a83Maurice Lam dest.writeBoolean(isIconTintable); 136744b63632a0d41eabf60e95a7b61e235e43f6d07Jason Monk } 137744b63632a0d41eabf60e95a7b61e235e43f6d07Jason Monk 138744b63632a0d41eabf60e95a7b61e235e43f6d07Jason Monk public void readFromParcel(Parcel in) { 139744b63632a0d41eabf60e95a7b61e235e43f6d07Jason Monk title = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(in); 140744b63632a0d41eabf60e95a7b61e235e43f6d07Jason Monk summary = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(in); 141744b63632a0d41eabf60e95a7b61e235e43f6d07Jason Monk if (in.readByte() != 0) { 142744b63632a0d41eabf60e95a7b61e235e43f6d07Jason Monk icon = Icon.CREATOR.createFromParcel(in); 143744b63632a0d41eabf60e95a7b61e235e43f6d07Jason Monk } 144744b63632a0d41eabf60e95a7b61e235e43f6d07Jason Monk if (in.readByte() != 0) { 145744b63632a0d41eabf60e95a7b61e235e43f6d07Jason Monk intent = Intent.CREATOR.createFromParcel(in); 146744b63632a0d41eabf60e95a7b61e235e43f6d07Jason Monk } 147744b63632a0d41eabf60e95a7b61e235e43f6d07Jason Monk final int N = in.readInt(); 148744b63632a0d41eabf60e95a7b61e235e43f6d07Jason Monk for (int i = 0; i < N; i++) { 149744b63632a0d41eabf60e95a7b61e235e43f6d07Jason Monk userHandle.add(UserHandle.CREATOR.createFromParcel(in)); 150744b63632a0d41eabf60e95a7b61e235e43f6d07Jason Monk } 151744b63632a0d41eabf60e95a7b61e235e43f6d07Jason Monk extras = in.readBundle(); 152744b63632a0d41eabf60e95a7b61e235e43f6d07Jason Monk category = in.readString(); 153744b63632a0d41eabf60e95a7b61e235e43f6d07Jason Monk priority = in.readInt(); 154e79790b26803ee338b2fdc3404344094d7f94476Jason Monk metaData = in.readBundle(); 1556b32ae37461a30d5c7c1124c805a77075e543badShahriyar Amini key = in.readString(); 156d8ae77b7f593528896b33bdd2755fa9562735472Maurice Lam remoteViews = in.readParcelable(RemoteViews.class.getClassLoader()); 157b10c6ffbaa2aa0c6f158415d028ce691385a7a83Maurice Lam isIconTintable = in.readBoolean(); 158744b63632a0d41eabf60e95a7b61e235e43f6d07Jason Monk } 159744b63632a0d41eabf60e95a7b61e235e43f6d07Jason Monk 160f509d7e65a062957be86619b3cb894e99268c4aeJason Monk Tile(Parcel in) { 161744b63632a0d41eabf60e95a7b61e235e43f6d07Jason Monk readFromParcel(in); 162744b63632a0d41eabf60e95a7b61e235e43f6d07Jason Monk } 163744b63632a0d41eabf60e95a7b61e235e43f6d07Jason Monk 164f509d7e65a062957be86619b3cb894e99268c4aeJason Monk public static final Creator<Tile> CREATOR = new Creator<Tile>() { 165f509d7e65a062957be86619b3cb894e99268c4aeJason Monk public Tile createFromParcel(Parcel source) { 166f509d7e65a062957be86619b3cb894e99268c4aeJason Monk return new Tile(source); 167744b63632a0d41eabf60e95a7b61e235e43f6d07Jason Monk } 168f509d7e65a062957be86619b3cb894e99268c4aeJason Monk public Tile[] newArray(int size) { 169f509d7e65a062957be86619b3cb894e99268c4aeJason Monk return new Tile[size]; 170744b63632a0d41eabf60e95a7b61e235e43f6d07Jason Monk } 171744b63632a0d41eabf60e95a7b61e235e43f6d07Jason Monk }; 172744b63632a0d41eabf60e95a7b61e235e43f6d07Jason Monk} 173