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; 21 22 import com.android.wallpaper.asset.Asset; 23 import com.android.wallpaper.asset.CurrentWallpaperAssetV16; 24 import com.android.wallpaper.asset.FileAsset; 25 import com.android.wallpaper.module.InjectorProvider; 26 import com.android.wallpaper.module.NoBackupImageWallpaper; 27 28 import java.io.File; 29 import java.util.ArrayList; 30 import java.util.List; 31 32 import androidx.annotation.DrawableRes; 33 import androidx.annotation.StringRes; 34 35 /** 36 * Represents the wallpaper currently set to the device for API 16 through 23. Should not be used 37 * to set a new wallpaper. 38 */ 39 public class CurrentWallpaperInfoV16 extends WallpaperInfo { 40 41 public static final Creator<CurrentWallpaperInfoV16> CREATOR = 42 new Creator<CurrentWallpaperInfoV16>() { 43 @Override 44 public CurrentWallpaperInfoV16 createFromParcel(Parcel source) { 45 return new CurrentWallpaperInfoV16(source); 46 } 47 48 @Override 49 public CurrentWallpaperInfoV16[] newArray(int size) { 50 return new CurrentWallpaperInfoV16[size]; 51 } 52 }; 53 private List<String> mAttributions; 54 private Asset mAsset; 55 private String mActionUrl; 56 @StringRes 57 private int mActionLabelRes; 58 @DrawableRes 59 private int mActionIconRes; 60 private String mCollectionId; 61 CurrentWallpaperInfoV16(List<String> attributions, String actionUrl, @StringRes int actionLabelRes, @DrawableRes int actionIconRes, String collectionId)62 public CurrentWallpaperInfoV16(List<String> attributions, String actionUrl, 63 @StringRes int actionLabelRes, @DrawableRes int actionIconRes, 64 String collectionId) { 65 mAttributions = attributions; 66 mActionUrl = actionUrl; 67 mActionLabelRes = actionLabelRes; 68 mActionIconRes = actionIconRes; 69 mCollectionId = collectionId; 70 } 71 CurrentWallpaperInfoV16(Parcel in)72 private CurrentWallpaperInfoV16(Parcel in) { 73 mAttributions = new ArrayList<>(); 74 in.readStringList(mAttributions); 75 mActionUrl = in.readString(); 76 mCollectionId = in.readString(); 77 mActionLabelRes = in.readInt(); 78 mActionIconRes = in.readInt(); 79 } 80 81 @Override getAttributions(Context context)82 public List<String> getAttributions(Context context) { 83 return mAttributions; 84 } 85 86 @Override getAsset(Context context)87 public Asset getAsset(Context context) { 88 if (mAsset == null) { 89 boolean isNoBackupImageWallpaperSet = InjectorProvider.getInjector() 90 .getLiveWallpaperStatusChecker(context).isNoBackupImageWallpaperSet(); 91 92 mAsset = isNoBackupImageWallpaperSet 93 ? new FileAsset(new File(context.getApplicationContext().getFilesDir(), 94 NoBackupImageWallpaper.ROTATING_WALLPAPER_FILE_PATH)) 95 : new CurrentWallpaperAssetV16(context); 96 } 97 return mAsset; 98 } 99 100 @Override getThumbAsset(Context context)101 public Asset getThumbAsset(Context context) { 102 return getAsset(context); 103 } 104 105 @Override getActionUrl(Context unused)106 public String getActionUrl(Context unused) { 107 return mActionUrl; 108 } 109 110 @Override getActionIconRes(Context unused)111 public int getActionIconRes(Context unused) { 112 return mActionIconRes != 0 ? mActionIconRes : WallpaperInfo.getDefaultActionIcon(); 113 } 114 115 @Override getActionLabelRes(Context unused)116 public int getActionLabelRes(Context unused) { 117 return mActionLabelRes != 0 ? mActionLabelRes : WallpaperInfo.getDefaultActionLabel(); 118 } 119 120 @Override getCollectionId(Context unused)121 public String getCollectionId(Context unused) { 122 return mCollectionId; 123 } 124 125 @Override writeToParcel(Parcel parcel, int flags)126 public void writeToParcel(Parcel parcel, int flags) { 127 parcel.writeStringList(mAttributions); 128 parcel.writeString(mActionUrl); 129 parcel.writeString(mCollectionId); 130 parcel.writeInt(mActionLabelRes); 131 parcel.writeInt(mActionIconRes); 132 } 133 134 @Override showPreview(Activity srcActivity, InlinePreviewIntentFactory factory, int requestCode)135 public void showPreview(Activity srcActivity, InlinePreviewIntentFactory factory, 136 int requestCode) { 137 srcActivity.startActivityForResult(factory.newIntent(srcActivity, this), requestCode); 138 } 139 } 140