blob: e5efee6a14188336b7f6cb2cc8e820a26eb7b1a6 [file] [log] [blame]
Jon Miranda16ea1b12017-12-12 14:52:48 -08001/*
2 * Copyright (C) 2017 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 */
16package com.android.wallpaper.model;
17
18import android.app.Activity;
19import android.content.Context;
20import android.os.Parcel;
Santiago Etchebehered1bd5092018-04-18 16:03:30 -070021import android.support.annotation.DrawableRes;
22import android.support.annotation.StringRes;
Jon Miranda16ea1b12017-12-12 14:52:48 -080023
24import com.android.wallpaper.asset.Asset;
25import com.android.wallpaper.asset.CurrentWallpaperAssetV16;
26import com.android.wallpaper.asset.FileAsset;
27import com.android.wallpaper.module.InjectorProvider;
28import com.android.wallpaper.module.NoBackupImageWallpaper;
29
30import java.io.File;
31import java.util.ArrayList;
32import java.util.List;
33
34/**
35 * Represents the wallpaper currently set to the device for API 16 through 23. Should not be used
36 * to set a new wallpaper.
37 */
38public class CurrentWallpaperInfoV16 extends WallpaperInfo {
39
40 public static final Creator<CurrentWallpaperInfoV16> CREATOR =
41 new Creator<CurrentWallpaperInfoV16>() {
42 @Override
43 public CurrentWallpaperInfoV16 createFromParcel(Parcel source) {
44 return new CurrentWallpaperInfoV16(source);
45 }
46
47 @Override
48 public CurrentWallpaperInfoV16[] newArray(int size) {
49 return new CurrentWallpaperInfoV16[size];
50 }
51 };
52 private List<String> mAttributions;
53 private Asset mAsset;
54 private String mActionUrl;
Santiago Etchebehered1bd5092018-04-18 16:03:30 -070055 @StringRes
56 private int mActionLabelRes;
57 @DrawableRes
58 private int mActionIconRes;
Jon Miranda16ea1b12017-12-12 14:52:48 -080059 private String mCollectionId;
60
Santiago Etchebehered1bd5092018-04-18 16:03:30 -070061 public CurrentWallpaperInfoV16(List<String> attributions, String actionUrl,
62 @StringRes int actionLabelRes, @DrawableRes int actionIconRes,
63 String collectionId) {
Jon Miranda16ea1b12017-12-12 14:52:48 -080064 mAttributions = attributions;
65 mActionUrl = actionUrl;
Santiago Etchebehered1bd5092018-04-18 16:03:30 -070066 mActionLabelRes = actionLabelRes;
67 mActionIconRes = actionIconRes;
Jon Miranda16ea1b12017-12-12 14:52:48 -080068 mCollectionId = collectionId;
69 }
70
71 private CurrentWallpaperInfoV16(Parcel in) {
72 mAttributions = new ArrayList<>();
73 in.readStringList(mAttributions);
74 mActionUrl = in.readString();
75 mCollectionId = in.readString();
Santiago Etchebehered1bd5092018-04-18 16:03:30 -070076 mActionLabelRes = in.readInt();
77 mActionIconRes = in.readInt();
Jon Miranda16ea1b12017-12-12 14:52:48 -080078 }
79
80 @Override
81 public List<String> getAttributions(Context context) {
82 return mAttributions;
83 }
84
85 @Override
86 public Asset getAsset(Context context) {
87 if (mAsset == null) {
88 boolean isNoBackupImageWallpaperSet = InjectorProvider.getInjector()
89 .getLiveWallpaperStatusChecker(context).isNoBackupImageWallpaperSet();
90
91 mAsset = isNoBackupImageWallpaperSet
92 ? new FileAsset(new File(context.getApplicationContext().getFilesDir(),
93 NoBackupImageWallpaper.ROTATING_WALLPAPER_FILE_PATH))
94 : new CurrentWallpaperAssetV16(context);
95 }
96 return mAsset;
97 }
98
99 @Override
100 public Asset getThumbAsset(Context context) {
101 return getAsset(context);
102 }
103
104 @Override
105 public String getActionUrl(Context unused) {
106 return mActionUrl;
107 }
108
109 @Override
Santiago Etchebeheree0810d02018-05-10 17:39:40 -0700110 public int getActionIconRes(Context unused) {
Santiago Etchebehered1bd5092018-04-18 16:03:30 -0700111 return mActionIconRes != 0 ? mActionIconRes : WallpaperInfo.getDefaultActionIcon();
112 }
113
114 @Override
Santiago Etchebeheree0810d02018-05-10 17:39:40 -0700115 public int getActionLabelRes(Context unused) {
Santiago Etchebehered1bd5092018-04-18 16:03:30 -0700116 return mActionLabelRes != 0 ? mActionLabelRes : WallpaperInfo.getDefaultActionLabel();
117 }
118
119 @Override
Jon Miranda16ea1b12017-12-12 14:52:48 -0800120 public String getCollectionId(Context unused) {
121 return mCollectionId;
122 }
123
124 @Override
125 public void writeToParcel(Parcel parcel, int flags) {
126 parcel.writeStringList(mAttributions);
127 parcel.writeString(mActionUrl);
128 parcel.writeString(mCollectionId);
Santiago Etchebehered1bd5092018-04-18 16:03:30 -0700129 parcel.writeInt(mActionLabelRes);
130 parcel.writeInt(mActionIconRes);
Jon Miranda16ea1b12017-12-12 14:52:48 -0800131 }
132
133 @Override
134 public void showPreview(Activity srcActivity, InlinePreviewIntentFactory factory,
135 int requestCode) {
136 srcActivity.startActivityForResult(factory.newIntent(srcActivity, this), requestCode);
137 }
138}