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.content.res.Resources; 21 import android.os.Build; 22 import android.os.Parcel; 23 24 import com.android.wallpaper.R; 25 import com.android.wallpaper.asset.Asset; 26 import com.android.wallpaper.asset.BuiltInWallpaperAsset; 27 import com.android.wallpaper.asset.ResourceAsset; 28 29 import java.util.Arrays; 30 import java.util.List; 31 32 /** 33 * Represents the default built-in wallpaper on the device. 34 */ 35 public class DefaultWallpaperInfo extends WallpaperInfo { 36 public static final Creator<DefaultWallpaperInfo> CREATOR = 37 new Creator<DefaultWallpaperInfo>() { 38 @Override 39 public DefaultWallpaperInfo createFromParcel(Parcel in) { 40 return new DefaultWallpaperInfo(); 41 } 42 43 @Override 44 public DefaultWallpaperInfo[] newArray(int size) { 45 return new DefaultWallpaperInfo[size]; 46 } 47 }; 48 private Asset mAsset; 49 50 @Override getAttributions(Context context)51 public List<String> getAttributions(Context context) { 52 return Arrays.asList(context.getResources().getString(R.string.fallback_wallpaper_title)); 53 } 54 55 @Override getAsset(Context context)56 public Asset getAsset(Context context) { 57 if (mAsset == null) { 58 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { 59 mAsset = new BuiltInWallpaperAsset(context); 60 } else { 61 Resources sysRes = Resources.getSystem(); 62 mAsset = new ResourceAsset( 63 sysRes, 64 sysRes.getIdentifier( 65 "default_wallpaper" /* name */, 66 "drawable" /* defType */, 67 "android" /* defPackage */)); 68 } 69 } 70 return mAsset; 71 } 72 73 @Override getThumbAsset(Context context)74 public Asset getThumbAsset(Context context) { 75 // Same asset as full size. 76 return getAsset(context); 77 } 78 79 @Override getCollectionId(Context context)80 public String getCollectionId(Context context) { 81 return context.getString(R.string.on_device_wallpaper_collection_id); 82 } 83 84 @Override getWallpaperId()85 public String getWallpaperId() { 86 return "built-in-wallpaper"; 87 } 88 89 @Override showPreview(Activity srcActivity, InlinePreviewIntentFactory factory, int requestCode)90 public void showPreview(Activity srcActivity, InlinePreviewIntentFactory factory, 91 int requestCode) { 92 srcActivity.startActivityForResult(factory.newIntent(srcActivity, this), requestCode); 93 } 94 95 @Override 96 @BackupPermission getBackupPermission()97 public int getBackupPermission() { 98 return BACKUP_NOT_ALLOWED; 99 } 100 101 @Override writeToParcel(Parcel parcel, int i)102 public void writeToParcel(Parcel parcel, int i) { 103 } 104 } 105