| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
package android.service.quicksettings; |
| 17 |
|
| 18 |
import android.annotation.Nullable; |
| 19 |
import android.app.PendingIntent; |
| 20 |
import android.graphics.drawable.Icon; |
| 21 |
import android.os.IBinder; |
| 22 |
import android.os.Parcel; |
| 23 |
import android.os.Parcelable; |
| 24 |
import android.os.RemoteException; |
| 25 |
import android.text.TextUtils; |
| 26 |
import android.util.Log; |
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
public final class Tile implements Parcelable { |
| 38 |
|
| 39 |
private static final String TAG = "Tile"; |
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
public static final int STATE_UNAVAILABLE = 0; |
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
public static final int STATE_INACTIVE = 1; |
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
public static final int STATE_ACTIVE = 2; |
| 63 |
|
| 64 |
private IBinder mToken; |
| 65 |
private Icon mIcon; |
| 66 |
private CharSequence mLabel; |
| 67 |
private CharSequence mSubtitle; |
| 68 |
private CharSequence mContentDescription; |
| 69 |
private CharSequence mStateDescription; |
| 70 |
private PendingIntent mPendingIntent; |
| 71 |
|
| 72 |
private int mState = STATE_INACTIVE; |
| 73 |
|
| 74 |
private IQSService mService; |
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
public Tile(Parcel source) { |
| 80 |
readFromParcel(source); |
| 81 |
} |
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
public Tile() { |
| 87 |
} |
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
public void setService(IQSService service, IBinder stub) { |
| 93 |
mService = service; |
| 94 |
mToken = stub; |
| 95 |
} |
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
public int getState() { |
| 105 |
return mState; |
| 106 |
} |
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
public void setState(int state) { |
| 117 |
mState = state; |
| 118 |
} |
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
public Icon getIcon() { |
| 124 |
return mIcon; |
| 125 |
} |
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
public void setIcon(Icon icon) { |
| 138 |
this.mIcon = icon; |
| 139 |
} |
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
public CharSequence getLabel() { |
| 145 |
return mLabel; |
| 146 |
} |
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
public void setLabel(CharSequence label) { |
| 156 |
this.mLabel = label; |
| 157 |
} |
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
@Nullable |
| 163 |
public CharSequence getSubtitle() { |
| 164 |
return mSubtitle; |
| 165 |
} |
| 166 |
|
| 167 |
|
| 168 |
|
| 169 |
|
| 170 |
|
| 171 |
public void setSubtitle(@Nullable CharSequence subtitle) { |
| 172 |
this.mSubtitle = subtitle; |
| 173 |
} |
| 174 |
|
| 175 |
|
| 176 |
|
| 177 |
|
| 178 |
public CharSequence getContentDescription() { |
| 179 |
return mContentDescription; |
| 180 |
} |
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
|
| 185 |
@Nullable |
| 186 |
public CharSequence getStateDescription() { |
| 187 |
return mStateDescription; |
| 188 |
} |
| 189 |
|
| 190 |
|
| 191 |
|
| 192 |
|
| 193 |
|
| 194 |
|
| 195 |
|
| 196 |
|
| 197 |
public void setContentDescription(CharSequence contentDescription) { |
| 198 |
this.mContentDescription = contentDescription; |
| 199 |
} |
| 200 |
|
| 201 |
|
| 202 |
|
| 203 |
|
| 204 |
|
| 205 |
|
| 206 |
|
| 207 |
|
| 208 |
public void setStateDescription(@Nullable CharSequence stateDescription) { |
| 209 |
this.mStateDescription = stateDescription; |
| 210 |
} |
| 211 |
|
| 212 |
@Override |
| 213 |
public int describeContents() { |
| 214 |
return 0; |
| 215 |
} |
| 216 |
|
| 217 |
|
| 218 |
|
| 219 |
|
| 220 |
public void updateTile() { |
| 221 |
try { |
| 222 |
mService.updateQsTile(this, mToken); |
| 223 |
} catch (RemoteException e) { |
| 224 |
Log.e(TAG, "Couldn't update tile"); |
| 225 |
} |
| 226 |
} |
| 227 |
|
| 228 |
|
| 229 |
|
| 230 |
|
| 231 |
|
| 232 |
@Nullable |
| 233 |
public PendingIntent getActivityLaunchForClick() { |
| 234 |
return mPendingIntent; |
| 235 |
} |
| 236 |
|
| 237 |
|
| 238 |
|
| 239 |
|
| 240 |
|
| 241 |
|
| 242 |
|
| 243 |
|
| 244 |
|
| 245 |
|
| 246 |
|
| 247 |
|
| 248 |
public void setActivityLaunchForClick(@Nullable PendingIntent pendingIntent) { |
| 249 |
if (pendingIntent != null && !pendingIntent.isActivity()) { |
| 250 |
throw new IllegalArgumentException(); |
| 251 |
} else { |
| 252 |
mPendingIntent = pendingIntent; |
| 253 |
} |
| 254 |
} |
| 255 |
|
| 256 |
@Override |
| 257 |
public void writeToParcel(Parcel dest, int flags) { |
| 258 |
if (mIcon != null) { |
| 259 |
dest.writeByte((byte) 1); |
| 260 |
mIcon.writeToParcel(dest, flags); |
| 261 |
} else { |
| 262 |
dest.writeByte((byte) 0); |
| 263 |
} |
| 264 |
if (mPendingIntent != null) { |
| 265 |
dest.writeByte((byte) 1); |
| 266 |
mPendingIntent.writeToParcel(dest, flags); |
| 267 |
} else { |
| 268 |
dest.writeByte((byte) 0); |
| 269 |
} |
| 270 |
dest.writeInt(mState); |
| 271 |
TextUtils.writeToParcel(mLabel, dest, flags); |
| 272 |
TextUtils.writeToParcel(mSubtitle, dest, flags); |
| 273 |
TextUtils.writeToParcel(mContentDescription, dest, flags); |
| 274 |
TextUtils.writeToParcel(mStateDescription, dest, flags); |
| 275 |
} |
| 276 |
|
| 277 |
private void readFromParcel(Parcel source) { |
| 278 |
if (source.readByte() != 0) { |
| 279 |
mIcon = Icon.CREATOR.createFromParcel(source); |
| 280 |
} else { |
| 281 |
mIcon = null; |
| 282 |
} |
| 283 |
if (source.readByte() != 0) { |
| 284 |
mPendingIntent = PendingIntent.CREATOR.createFromParcel(source); |
| 285 |
} else { |
| 286 |
mPendingIntent = null; |
| 287 |
} |
| 288 |
mState = source.readInt(); |
| 289 |
mLabel = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(source); |
| 290 |
mSubtitle = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(source); |
| 291 |
mContentDescription = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(source); |
| 292 |
mStateDescription = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(source); |
| 293 |
} |
| 294 |
|
| 295 |
public static final @android.annotation.NonNull Creator<Tile> CREATOR = new Creator<Tile>() { |
| 296 |
@Override |
| 297 |
public Tile createFromParcel(Parcel source) { |
| 298 |
return new Tile(source); |
| 299 |
} |
| 300 |
|
| 301 |
@Override |
| 302 |
public Tile[] newArray(int size) { |
| 303 |
return new Tile[size]; |
| 304 |
} |
| 305 |
}; |
| 306 |
} |