Jon Miranda | 16ea1b1 | 2017-12-12 14:52:48 -0800 | [diff] [blame] | 1 | /* |
| 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 | */ |
| 16 | package com.android.wallpaper.model; |
| 17 | |
| 18 | import android.app.Activity; |
| 19 | import android.content.Context; |
| 20 | import android.os.Parcel; |
Santiago Etchebehere | d1bd509 | 2018-04-18 16:03:30 -0700 | [diff] [blame] | 21 | import android.support.annotation.DrawableRes; |
| 22 | import android.support.annotation.StringRes; |
Jon Miranda | 16ea1b1 | 2017-12-12 14:52:48 -0800 | [diff] [blame] | 23 | |
| 24 | import com.android.wallpaper.asset.Asset; |
| 25 | import com.android.wallpaper.asset.CurrentWallpaperAssetV16; |
| 26 | import com.android.wallpaper.asset.FileAsset; |
| 27 | import com.android.wallpaper.module.InjectorProvider; |
| 28 | import com.android.wallpaper.module.NoBackupImageWallpaper; |
| 29 | |
| 30 | import java.io.File; |
| 31 | import java.util.ArrayList; |
| 32 | import 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 | */ |
| 38 | public 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 Etchebehere | d1bd509 | 2018-04-18 16:03:30 -0700 | [diff] [blame] | 55 | @StringRes |
| 56 | private int mActionLabelRes; |
| 57 | @DrawableRes |
| 58 | private int mActionIconRes; |
Jon Miranda | 16ea1b1 | 2017-12-12 14:52:48 -0800 | [diff] [blame] | 59 | private String mCollectionId; |
| 60 | |
Santiago Etchebehere | d1bd509 | 2018-04-18 16:03:30 -0700 | [diff] [blame] | 61 | public CurrentWallpaperInfoV16(List<String> attributions, String actionUrl, |
| 62 | @StringRes int actionLabelRes, @DrawableRes int actionIconRes, |
| 63 | String collectionId) { |
Jon Miranda | 16ea1b1 | 2017-12-12 14:52:48 -0800 | [diff] [blame] | 64 | mAttributions = attributions; |
| 65 | mActionUrl = actionUrl; |
Santiago Etchebehere | d1bd509 | 2018-04-18 16:03:30 -0700 | [diff] [blame] | 66 | mActionLabelRes = actionLabelRes; |
| 67 | mActionIconRes = actionIconRes; |
Jon Miranda | 16ea1b1 | 2017-12-12 14:52:48 -0800 | [diff] [blame] | 68 | 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 Etchebehere | d1bd509 | 2018-04-18 16:03:30 -0700 | [diff] [blame] | 76 | mActionLabelRes = in.readInt(); |
| 77 | mActionIconRes = in.readInt(); |
Jon Miranda | 16ea1b1 | 2017-12-12 14:52:48 -0800 | [diff] [blame] | 78 | } |
| 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 Etchebehere | e0810d0 | 2018-05-10 17:39:40 -0700 | [diff] [blame] | 110 | public int getActionIconRes(Context unused) { |
Santiago Etchebehere | d1bd509 | 2018-04-18 16:03:30 -0700 | [diff] [blame] | 111 | return mActionIconRes != 0 ? mActionIconRes : WallpaperInfo.getDefaultActionIcon(); |
| 112 | } |
| 113 | |
| 114 | @Override |
Santiago Etchebehere | e0810d0 | 2018-05-10 17:39:40 -0700 | [diff] [blame] | 115 | public int getActionLabelRes(Context unused) { |
Santiago Etchebehere | d1bd509 | 2018-04-18 16:03:30 -0700 | [diff] [blame] | 116 | return mActionLabelRes != 0 ? mActionLabelRes : WallpaperInfo.getDefaultActionLabel(); |
| 117 | } |
| 118 | |
| 119 | @Override |
Jon Miranda | 16ea1b1 | 2017-12-12 14:52:48 -0800 | [diff] [blame] | 120 | 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 Etchebehere | d1bd509 | 2018-04-18 16:03:30 -0700 | [diff] [blame] | 129 | parcel.writeInt(mActionLabelRes); |
| 130 | parcel.writeInt(mActionIconRes); |
Jon Miranda | 16ea1b1 | 2017-12-12 14:52:48 -0800 | [diff] [blame] | 131 | } |
| 132 | |
| 133 | @Override |
| 134 | public void showPreview(Activity srcActivity, InlinePreviewIntentFactory factory, |
| 135 | int requestCode) { |
| 136 | srcActivity.startActivityForResult(factory.newIntent(srcActivity, this), requestCode); |
| 137 | } |
| 138 | } |