1/** 2 * Copyright (C) 2015 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17package com.android.settingslib.drawer; 18 19import android.content.Intent; 20import android.graphics.drawable.Icon; 21import android.os.Bundle; 22import android.os.Parcel; 23import android.os.Parcelable; 24import android.os.UserHandle; 25import android.text.TextUtils; 26 27import java.util.ArrayList; 28 29/** 30 * Description of a single dashboard tile that the user can select. 31 */ 32public class Tile implements Parcelable { 33 34 /** 35 * Title of the tile that is shown to the user. 36 * @attr ref android.R.styleable#PreferenceHeader_title 37 */ 38 public CharSequence title; 39 40 /** 41 * Optional summary describing what this tile controls. 42 * @attr ref android.R.styleable#PreferenceHeader_summary 43 */ 44 public CharSequence summary; 45 46 /** 47 * Optional icon to show for this tile. 48 * @attr ref android.R.styleable#PreferenceHeader_icon 49 */ 50 public Icon icon; 51 52 /** 53 * Intent to launch when the preference is selected. 54 */ 55 public Intent intent; 56 57 /** 58 * Optional list of user handles which the intent should be launched on. 59 */ 60 public ArrayList<UserHandle> userHandle = new ArrayList<>(); 61 62 /** 63 * Optional additional data for use by subclasses of the activity 64 */ 65 public Bundle extras; 66 67 /** 68 * Category in which the tile should be placed. 69 */ 70 public String category; 71 72 /** 73 * Priority of the intent filter that created this tile, used for display ordering. 74 */ 75 public int priority; 76 77 /** 78 * The metaData from the activity that defines this tile. 79 */ 80 public Bundle metaData; 81 82 public Tile() { 83 // Empty 84 } 85 86 @Override 87 public int describeContents() { 88 return 0; 89 } 90 91 @Override 92 public void writeToParcel(Parcel dest, int flags) { 93 TextUtils.writeToParcel(title, dest, flags); 94 TextUtils.writeToParcel(summary, dest, flags); 95 if (icon != null) { 96 dest.writeByte((byte) 1); 97 icon.writeToParcel(dest, flags); 98 } else { 99 dest.writeByte((byte) 0); 100 } 101 if (intent != null) { 102 dest.writeByte((byte) 1); 103 intent.writeToParcel(dest, flags); 104 } else { 105 dest.writeByte((byte) 0); 106 } 107 final int N = userHandle.size(); 108 dest.writeInt(N); 109 for (int i = 0; i < N; i++) { 110 userHandle.get(i).writeToParcel(dest, flags); 111 } 112 dest.writeBundle(extras); 113 dest.writeString(category); 114 dest.writeInt(priority); 115 dest.writeBundle(metaData); 116 } 117 118 public void readFromParcel(Parcel in) { 119 title = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(in); 120 summary = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(in); 121 if (in.readByte() != 0) { 122 icon = Icon.CREATOR.createFromParcel(in); 123 } 124 if (in.readByte() != 0) { 125 intent = Intent.CREATOR.createFromParcel(in); 126 } 127 final int N = in.readInt(); 128 for (int i = 0; i < N; i++) { 129 userHandle.add(UserHandle.CREATOR.createFromParcel(in)); 130 } 131 extras = in.readBundle(); 132 category = in.readString(); 133 priority = in.readInt(); 134 metaData = in.readBundle(); 135 } 136 137 Tile(Parcel in) { 138 readFromParcel(in); 139 } 140 141 public static final Creator<Tile> CREATOR = new Creator<Tile>() { 142 public Tile createFromParcel(Parcel source) { 143 return new Tile(source); 144 } 145 public Tile[] newArray(int size) { 146 return new Tile[size]; 147 } 148 }; 149} 150