blob: 62b9be43efc9a114b2557b33f6d8b3a02700b670 [file] [log] [blame]
Sunny Goyalbd822502016-02-18 15:09:21 -08001/*
2 * Copyright (C) 2016 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
17package com.android.launcher3;
18
19import android.content.Intent;
20import android.content.pm.ApplicationInfo;
21import android.content.pm.PackageManager;
22import android.content.res.Resources;
23import android.graphics.Bitmap;
24import android.graphics.BitmapFactory;
25import android.graphics.drawable.BitmapDrawable;
26import android.os.Bundle;
27import android.util.Pair;
28
29import com.android.wallpaperpicker.tileinfo.DefaultWallpaperInfo;
30import com.android.wallpaperpicker.tileinfo.FileWallpaperInfo;
31import com.android.wallpaperpicker.tileinfo.WallpaperTileInfo;
32
33import java.io.File;
34import java.util.ArrayList;
35
36public class WallpaperPickerActivity extends com.android.wallpaperpicker.WallpaperPickerActivity {
37
38 @Override
39 public void startActivityForResultSafely(Intent intent, int requestCode) {
40 Utilities.startActivityForResultSafely(this, intent, requestCode);
41 }
42
43 @Override
44 public boolean enableRotation() {
45 return super.enableRotation() ||
46 getContentResolver().call(LauncherSettings.Settings.CONTENT_URI,
47 LauncherSettings.Settings.METHOD_GET_BOOLEAN,
48 Utilities.ALLOW_ROTATION_PREFERENCE_KEY, new Bundle())
49 .getBoolean(LauncherSettings.Settings.EXTRA_VALUE);
50 }
51
52 @Override
53 public ArrayList<WallpaperTileInfo> findBundledWallpapers() {
54 final PackageManager pm = getPackageManager();
55 final ArrayList<WallpaperTileInfo> bundled = new ArrayList<WallpaperTileInfo>(24);
56
57 Partner partner = Partner.get(pm);
58 if (partner != null) {
59 final Resources partnerRes = partner.getResources();
60 final int resId = partnerRes.getIdentifier(Partner.RES_WALLPAPERS, "array",
61 partner.getPackageName());
62 if (resId != 0) {
63 addWallpapers(bundled, partnerRes, partner.getPackageName(), resId);
64 }
65
66 // Add system wallpapers
67 File systemDir = partner.getWallpaperDirectory();
68 if (systemDir != null && systemDir.isDirectory()) {
69 for (File file : systemDir.listFiles()) {
70 if (!file.isFile()) {
71 continue;
72 }
73 String name = file.getName();
74 int dotPos = name.lastIndexOf('.');
75 String extension = "";
76 if (dotPos >= -1) {
77 extension = name.substring(dotPos);
78 name = name.substring(0, dotPos);
79 }
80
81 if (name.endsWith("_small")) {
82 // it is a thumbnail
83 continue;
84 }
85
86 File thumbnail = new File(systemDir, name + "_small" + extension);
87 Bitmap thumb = BitmapFactory.decodeFile(thumbnail.getAbsolutePath());
88 if (thumb != null) {
89 bundled.add(new FileWallpaperInfo(
90 file, new BitmapDrawable(getResources(), thumb)));
91 }
92 }
93 }
94 }
95
96 Pair<ApplicationInfo, Integer> r = getWallpaperArrayResourceId();
97 if (r != null) {
98 try {
99 Resources wallpaperRes = pm.getResourcesForApplication(r.first);
100 addWallpapers(bundled, wallpaperRes, r.first.packageName, r.second);
101 } catch (PackageManager.NameNotFoundException e) {
102 }
103 }
104
105 if (partner == null || !partner.hideDefaultWallpaper()) {
106 // Add an entry for the default wallpaper (stored in system resources)
107 WallpaperTileInfo defaultWallpaperInfo = DefaultWallpaperInfo.get(this);
108 if (defaultWallpaperInfo != null) {
109 bundled.add(0, defaultWallpaperInfo);
110 }
111 }
112 return bundled;
113 }
114}