From 69413c91c5839fd061f2422ea603faf11a5dd629 Mon Sep 17 00:00:00 2001 From: Michael Jurka Date: Wed, 11 Dec 2013 17:09:53 +0100 Subject: Move additional wallpaper picker files to special dir Change-Id: I3dd6f0ce4db72f9f30ed02e8c27039f68ab9a728 --- src/com/android/launcher3/DrawableTileSource.java | 102 --------- .../launcher3/LiveWallpaperListAdapter.java | 205 ------------------ .../android/launcher3/SavedWallpaperImages.java | 241 --------------------- .../ThirdPartyWallpaperPickerListAdapter.java | 139 ------------ src/com/android/launcher3/WallpaperRootView.java | 39 ---- update_system_wallpaper_cropper.py | 71 +++--- .../com/android/launcher3/DrawableTileSource.java | 102 +++++++++ .../launcher3/LiveWallpaperListAdapter.java | 205 ++++++++++++++++++ .../android/launcher3/SavedWallpaperImages.java | 241 +++++++++++++++++++++ .../ThirdPartyWallpaperPickerListAdapter.java | 139 ++++++++++++ .../com/android/launcher3/WallpaperRootView.java | 39 ++++ 11 files changed, 763 insertions(+), 760 deletions(-) delete mode 100644 src/com/android/launcher3/DrawableTileSource.java delete mode 100644 src/com/android/launcher3/LiveWallpaperListAdapter.java delete mode 100644 src/com/android/launcher3/SavedWallpaperImages.java delete mode 100644 src/com/android/launcher3/ThirdPartyWallpaperPickerListAdapter.java delete mode 100644 src/com/android/launcher3/WallpaperRootView.java create mode 100644 wallpaper_picker_src/com/android/launcher3/DrawableTileSource.java create mode 100644 wallpaper_picker_src/com/android/launcher3/LiveWallpaperListAdapter.java create mode 100644 wallpaper_picker_src/com/android/launcher3/SavedWallpaperImages.java create mode 100644 wallpaper_picker_src/com/android/launcher3/ThirdPartyWallpaperPickerListAdapter.java create mode 100644 wallpaper_picker_src/com/android/launcher3/WallpaperRootView.java diff --git a/src/com/android/launcher3/DrawableTileSource.java b/src/com/android/launcher3/DrawableTileSource.java deleted file mode 100644 index c1f2eff0f..000000000 --- a/src/com/android/launcher3/DrawableTileSource.java +++ /dev/null @@ -1,102 +0,0 @@ -/* - * Copyright (C) 2013 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.launcher3; - -import android.content.Context; -import android.graphics.Bitmap; -import android.graphics.Canvas; -import android.graphics.Rect; -import android.graphics.drawable.Drawable; - -import com.android.gallery3d.glrenderer.BasicTexture; -import com.android.gallery3d.glrenderer.BitmapTexture; -import com.android.photos.views.TiledImageRenderer; - -public class DrawableTileSource implements TiledImageRenderer.TileSource { - private static final int GL_SIZE_LIMIT = 2048; - // This must be no larger than half the size of the GL_SIZE_LIMIT - // due to decodePreview being allowed to be up to 2x the size of the target - public static final int MAX_PREVIEW_SIZE = GL_SIZE_LIMIT / 2; - - private int mTileSize; - private int mPreviewSize; - private Drawable mDrawable; - private BitmapTexture mPreview; - - public DrawableTileSource(Context context, Drawable d, int previewSize) { - mTileSize = TiledImageRenderer.suggestedTileSize(context); - mDrawable = d; - mPreviewSize = Math.min(previewSize, MAX_PREVIEW_SIZE); - } - - @Override - public int getTileSize() { - return mTileSize; - } - - @Override - public int getImageWidth() { - return mDrawable.getIntrinsicWidth(); - } - - @Override - public int getImageHeight() { - return mDrawable.getIntrinsicHeight(); - } - - @Override - public int getRotation() { - return 0; - } - - @Override - public BasicTexture getPreview() { - if (mPreviewSize == 0) { - return null; - } - if (mPreview == null){ - float width = getImageWidth(); - float height = getImageHeight(); - while (width > MAX_PREVIEW_SIZE || height > MAX_PREVIEW_SIZE) { - width /= 2; - height /= 2; - } - Bitmap b = Bitmap.createBitmap((int) width, (int) height, Bitmap.Config.ARGB_8888); - Canvas c = new Canvas(b); - mDrawable.setBounds(new Rect(0, 0, (int) width, (int) height)); - mDrawable.draw(c); - c.setBitmap(null); - mPreview = new BitmapTexture(b); - } - return mPreview; - } - - @Override - public Bitmap getTile(int level, int x, int y, Bitmap bitmap) { - int tileSize = getTileSize(); - if (bitmap == null) { - bitmap = Bitmap.createBitmap(tileSize, tileSize, Bitmap.Config.ARGB_8888); - } - Canvas c = new Canvas(bitmap); - Rect bounds = new Rect(0, 0, getImageWidth(), getImageHeight()); - bounds.offset(-x, -y); - mDrawable.setBounds(bounds); - mDrawable.draw(c); - c.setBitmap(null); - return bitmap; - } -} diff --git a/src/com/android/launcher3/LiveWallpaperListAdapter.java b/src/com/android/launcher3/LiveWallpaperListAdapter.java deleted file mode 100644 index 152a75ded..000000000 --- a/src/com/android/launcher3/LiveWallpaperListAdapter.java +++ /dev/null @@ -1,205 +0,0 @@ -/* - * Copyright (C) 2010 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.launcher3; - -import android.app.WallpaperInfo; -import android.app.WallpaperManager; -import android.content.Context; -import android.content.Intent; -import android.content.pm.PackageManager; -import android.content.pm.ResolveInfo; -import android.graphics.drawable.Drawable; -import android.os.AsyncTask; -import android.service.wallpaper.WallpaperService; -import android.util.Log; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.BaseAdapter; -import android.widget.FrameLayout; -import android.widget.ImageView; -import android.widget.ListAdapter; -import android.widget.TextView; - -import org.xmlpull.v1.XmlPullParserException; - -import java.io.IOException; -import java.text.Collator; -import java.util.ArrayList; -import java.util.Collections; -import java.util.Comparator; -import java.util.List; - -public class LiveWallpaperListAdapter extends BaseAdapter implements ListAdapter { - private static final String LOG_TAG = "LiveWallpaperListAdapter"; - - private final LayoutInflater mInflater; - private final PackageManager mPackageManager; - - private List mWallpapers; - - @SuppressWarnings("unchecked") - public LiveWallpaperListAdapter(Context context) { - mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); - mPackageManager = context.getPackageManager(); - - List list = mPackageManager.queryIntentServices( - new Intent(WallpaperService.SERVICE_INTERFACE), - PackageManager.GET_META_DATA); - - mWallpapers = new ArrayList(); - - new LiveWallpaperEnumerator(context).execute(list); - } - - public int getCount() { - if (mWallpapers == null) { - return 0; - } - return mWallpapers.size(); - } - - public LiveWallpaperTile getItem(int position) { - return mWallpapers.get(position); - } - - public long getItemId(int position) { - return position; - } - - public View getView(int position, View convertView, ViewGroup parent) { - View view; - - if (convertView == null) { - view = mInflater.inflate(R.layout.wallpaper_picker_live_wallpaper_item, parent, false); - } else { - view = convertView; - } - - WallpaperPickerActivity.setWallpaperItemPaddingToZero((FrameLayout) view); - - LiveWallpaperTile wallpaperInfo = mWallpapers.get(position); - wallpaperInfo.setView(view); - ImageView image = (ImageView) view.findViewById(R.id.wallpaper_image); - ImageView icon = (ImageView) view.findViewById(R.id.wallpaper_icon); - if (wallpaperInfo.mThumbnail != null) { - image.setImageDrawable(wallpaperInfo.mThumbnail); - icon.setVisibility(View.GONE); - } else { - icon.setImageDrawable(wallpaperInfo.mInfo.loadIcon(mPackageManager)); - icon.setVisibility(View.VISIBLE); - } - - TextView label = (TextView) view.findViewById(R.id.wallpaper_item_label); - label.setText(wallpaperInfo.mInfo.loadLabel(mPackageManager)); - - return view; - } - - public static class LiveWallpaperTile extends WallpaperPickerActivity.WallpaperTileInfo { - private Drawable mThumbnail; - private WallpaperInfo mInfo; - public LiveWallpaperTile(Drawable thumbnail, WallpaperInfo info, Intent intent) { - mThumbnail = thumbnail; - mInfo = info; - } - @Override - public void onClick(WallpaperPickerActivity a) { - Intent preview = new Intent(WallpaperManager.ACTION_CHANGE_LIVE_WALLPAPER); - preview.putExtra(WallpaperManager.EXTRA_LIVE_WALLPAPER_COMPONENT, - mInfo.getComponent()); - a.onLiveWallpaperPickerLaunch(); - Utilities.startActivityForResultSafely( - a, preview, WallpaperPickerActivity.PICK_LIVE_WALLPAPER); - } - } - - private class LiveWallpaperEnumerator extends - AsyncTask, LiveWallpaperTile, Void> { - private Context mContext; - private int mWallpaperPosition; - - public LiveWallpaperEnumerator(Context context) { - super(); - mContext = context; - mWallpaperPosition = 0; - } - - @Override - protected Void doInBackground(List... params) { - final PackageManager packageManager = mContext.getPackageManager(); - - List list = params[0]; - - Collections.sort(list, new Comparator() { - final Collator mCollator; - - { - mCollator = Collator.getInstance(); - } - - public int compare(ResolveInfo info1, ResolveInfo info2) { - return mCollator.compare(info1.loadLabel(packageManager), - info2.loadLabel(packageManager)); - } - }); - - for (ResolveInfo resolveInfo : list) { - WallpaperInfo info = null; - try { - info = new WallpaperInfo(mContext, resolveInfo); - } catch (XmlPullParserException e) { - Log.w(LOG_TAG, "Skipping wallpaper " + resolveInfo.serviceInfo, e); - continue; - } catch (IOException e) { - Log.w(LOG_TAG, "Skipping wallpaper " + resolveInfo.serviceInfo, e); - continue; - } - - - Drawable thumb = info.loadThumbnail(packageManager); - Intent launchIntent = new Intent(WallpaperService.SERVICE_INTERFACE); - launchIntent.setClassName(info.getPackageName(), info.getServiceName()); - LiveWallpaperTile wallpaper = new LiveWallpaperTile(thumb, info, launchIntent); - publishProgress(wallpaper); - } - // Send a null object to show loading is finished - publishProgress((LiveWallpaperTile) null); - - return null; - } - - @Override - protected void onProgressUpdate(LiveWallpaperTile...infos) { - for (LiveWallpaperTile info : infos) { - if (info == null) { - LiveWallpaperListAdapter.this.notifyDataSetChanged(); - break; - } - if (info.mThumbnail != null) { - info.mThumbnail.setDither(true); - } - if (mWallpaperPosition < mWallpapers.size()) { - mWallpapers.set(mWallpaperPosition, info); - } else { - mWallpapers.add(info); - } - mWallpaperPosition++; - } - } - } -} diff --git a/src/com/android/launcher3/SavedWallpaperImages.java b/src/com/android/launcher3/SavedWallpaperImages.java deleted file mode 100644 index 58add7022..000000000 --- a/src/com/android/launcher3/SavedWallpaperImages.java +++ /dev/null @@ -1,241 +0,0 @@ -/* - * Copyright (C) 2013 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.launcher3; - -import android.app.Activity; -import android.content.ContentValues; -import android.content.Context; -import android.database.Cursor; -import android.database.sqlite.SQLiteDatabase; -import android.database.sqlite.SQLiteOpenHelper; -import android.graphics.Bitmap; -import android.graphics.BitmapFactory; -import android.graphics.drawable.BitmapDrawable; -import android.graphics.drawable.Drawable; -import android.util.Log; -import android.util.Pair; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.BaseAdapter; -import android.widget.ListAdapter; - -import com.android.photos.BitmapRegionTileSource; - -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; -import java.util.ArrayList; - - -public class SavedWallpaperImages extends BaseAdapter implements ListAdapter { - private static String TAG = "Launcher3.SavedWallpaperImages"; - private ImageDb mDb; - ArrayList mImages; - Context mContext; - LayoutInflater mLayoutInflater; - - public static class SavedWallpaperTile extends WallpaperPickerActivity.WallpaperTileInfo { - private int mDbId; - private Drawable mThumb; - public SavedWallpaperTile(int dbId, Drawable thumb) { - mDbId = dbId; - mThumb = thumb; - } - @Override - public void onClick(WallpaperPickerActivity a) { - String imageFilename = a.getSavedImages().getImageFilename(mDbId); - File file = new File(a.getFilesDir(), imageFilename); - BitmapRegionTileSource.FilePathBitmapSource bitmapSource = - new BitmapRegionTileSource.FilePathBitmapSource(file.getAbsolutePath(), 1024); - a.setCropViewTileSource(bitmapSource, false, true, null); - } - @Override - public void onSave(WallpaperPickerActivity a) { - boolean finishActivityWhenDone = true; - String imageFilename = a.getSavedImages().getImageFilename(mDbId); - a.setWallpaper(imageFilename, finishActivityWhenDone); - } - @Override - public void onDelete(WallpaperPickerActivity a) { - a.getSavedImages().deleteImage(mDbId); - } - @Override - public boolean isSelectable() { - return true; - } - @Override - public boolean isNamelessWallpaper() { - return true; - } - } - - public SavedWallpaperImages(Activity context) { - mDb = new ImageDb(context); - mContext = context; - mLayoutInflater = context.getLayoutInflater(); - } - - public void loadThumbnailsAndImageIdList() { - mImages = new ArrayList(); - SQLiteDatabase db = mDb.getReadableDatabase(); - Cursor result = db.query(ImageDb.TABLE_NAME, - new String[] { ImageDb.COLUMN_ID, - ImageDb.COLUMN_IMAGE_THUMBNAIL_FILENAME }, // cols to return - null, // select query - null, // args to select query - null, - null, - ImageDb.COLUMN_ID + " DESC", - null); - - while (result.moveToNext()) { - String filename = result.getString(1); - File file = new File(mContext.getFilesDir(), filename); - - Bitmap thumb = BitmapFactory.decodeFile(file.getAbsolutePath()); - if (thumb != null) { - mImages.add(new SavedWallpaperTile(result.getInt(0), new BitmapDrawable(thumb))); - } - } - result.close(); - } - - public int getCount() { - return mImages.size(); - } - - public SavedWallpaperTile getItem(int position) { - return mImages.get(position); - } - - public long getItemId(int position) { - return position; - } - - public View getView(int position, View convertView, ViewGroup parent) { - Drawable thumbDrawable = mImages.get(position).mThumb; - if (thumbDrawable == null) { - Log.e(TAG, "Error decoding thumbnail for wallpaper #" + position); - } - return WallpaperPickerActivity.createImageTileView( - mLayoutInflater, position, convertView, parent, thumbDrawable); - } - - public String getImageFilename(int id) { - Pair filenames = getImageFilenames(id); - if (filenames != null) { - return filenames.second; - } - return null; - } - - private Pair getImageFilenames(int id) { - SQLiteDatabase db = mDb.getReadableDatabase(); - Cursor result = db.query(ImageDb.TABLE_NAME, - new String[] { ImageDb.COLUMN_IMAGE_THUMBNAIL_FILENAME, - ImageDb.COLUMN_IMAGE_FILENAME }, // cols to return - ImageDb.COLUMN_ID + " = ?", // select query - new String[] { Integer.toString(id) }, // args to select query - null, - null, - null, - null); - if (result.getCount() > 0) { - result.moveToFirst(); - String thumbFilename = result.getString(0); - String imageFilename = result.getString(1); - result.close(); - return new Pair(thumbFilename, imageFilename); - } else { - return null; - } - } - - public void deleteImage(int id) { - Pair filenames = getImageFilenames(id); - File imageFile = new File(mContext.getFilesDir(), filenames.first); - imageFile.delete(); - File thumbFile = new File(mContext.getFilesDir(), filenames.second); - thumbFile.delete(); - SQLiteDatabase db = mDb.getWritableDatabase(); - db.delete(ImageDb.TABLE_NAME, - ImageDb.COLUMN_ID + " = ?", // SELECT query - new String[] { - Integer.toString(id) // args to SELECT query - }); - } - - public void writeImage(Bitmap thumbnail, byte[] imageBytes) { - try { - File imageFile = File.createTempFile("wallpaper", "", mContext.getFilesDir()); - FileOutputStream imageFileStream = - mContext.openFileOutput(imageFile.getName(), Context.MODE_PRIVATE); - imageFileStream.write(imageBytes); - imageFileStream.close(); - - File thumbFile = File.createTempFile("wallpaperthumb", "", mContext.getFilesDir()); - FileOutputStream thumbFileStream = - mContext.openFileOutput(thumbFile.getName(), Context.MODE_PRIVATE); - thumbnail.compress(Bitmap.CompressFormat.JPEG, 95, thumbFileStream); - thumbFileStream.close(); - - SQLiteDatabase db = mDb.getWritableDatabase(); - ContentValues values = new ContentValues(); - values.put(ImageDb.COLUMN_IMAGE_THUMBNAIL_FILENAME, thumbFile.getName()); - values.put(ImageDb.COLUMN_IMAGE_FILENAME, imageFile.getName()); - db.insert(ImageDb.TABLE_NAME, null, values); - } catch (IOException e) { - Log.e(TAG, "Failed writing images to storage " + e); - } - } - - static class ImageDb extends SQLiteOpenHelper { - final static int DB_VERSION = 1; - final static String DB_NAME = "saved_wallpaper_images.db"; - final static String TABLE_NAME = "saved_wallpaper_images"; - final static String COLUMN_ID = "id"; - final static String COLUMN_IMAGE_THUMBNAIL_FILENAME = "image_thumbnail"; - final static String COLUMN_IMAGE_FILENAME = "image"; - - Context mContext; - - public ImageDb(Context context) { - super(context, new File(context.getCacheDir(), DB_NAME).getPath(), null, DB_VERSION); - // Store the context for later use - mContext = context; - } - - @Override - public void onCreate(SQLiteDatabase database) { - database.execSQL("CREATE TABLE IF NOT EXISTS " + TABLE_NAME + " (" + - COLUMN_ID + " INTEGER NOT NULL, " + - COLUMN_IMAGE_THUMBNAIL_FILENAME + " TEXT NOT NULL, " + - COLUMN_IMAGE_FILENAME + " TEXT NOT NULL, " + - "PRIMARY KEY (" + COLUMN_ID + " ASC) " + - ");"); - } - - @Override - public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { - if (oldVersion != newVersion) { - // Delete all the records; they'll be repopulated as this is a cache - db.execSQL("DELETE FROM " + TABLE_NAME); - } - } - } -} diff --git a/src/com/android/launcher3/ThirdPartyWallpaperPickerListAdapter.java b/src/com/android/launcher3/ThirdPartyWallpaperPickerListAdapter.java deleted file mode 100644 index 494694cbd..000000000 --- a/src/com/android/launcher3/ThirdPartyWallpaperPickerListAdapter.java +++ /dev/null @@ -1,139 +0,0 @@ -/* - * Copyright (C) 2010 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.launcher3; - -import android.content.ComponentName; -import android.content.Context; -import android.content.Intent; -import android.content.pm.ActivityInfo; -import android.content.pm.PackageManager; -import android.content.pm.ResolveInfo; -import android.graphics.Rect; -import android.graphics.drawable.Drawable; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.BaseAdapter; -import android.widget.FrameLayout; -import android.widget.ListAdapter; -import android.widget.TextView; - -import java.util.ArrayList; -import java.util.List; - -public class ThirdPartyWallpaperPickerListAdapter extends BaseAdapter implements ListAdapter { - private static final String LOG_TAG = "LiveWallpaperListAdapter"; - - private final LayoutInflater mInflater; - private final PackageManager mPackageManager; - private final int mIconSize; - - private List mThirdPartyWallpaperPickers = - new ArrayList(); - - public static class ThirdPartyWallpaperTile extends WallpaperPickerActivity.WallpaperTileInfo { - private ResolveInfo mResolveInfo; - public ThirdPartyWallpaperTile(ResolveInfo resolveInfo) { - mResolveInfo = resolveInfo; - } - @Override - public void onClick(WallpaperPickerActivity a) { - final ComponentName itemComponentName = new ComponentName( - mResolveInfo.activityInfo.packageName, mResolveInfo.activityInfo.name); - Intent launchIntent = new Intent(Intent.ACTION_SET_WALLPAPER); - launchIntent.setComponent(itemComponentName); - Utilities.startActivityForResultSafely( - a, launchIntent, WallpaperPickerActivity.PICK_WALLPAPER_THIRD_PARTY_ACTIVITY); - } - } - - public ThirdPartyWallpaperPickerListAdapter(Context context) { - mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); - mPackageManager = context.getPackageManager(); - mIconSize = context.getResources().getDimensionPixelSize(R.dimen.wallpaperItemIconSize); - final PackageManager pm = mPackageManager; - - final Intent pickWallpaperIntent = new Intent(Intent.ACTION_SET_WALLPAPER); - final List apps = - pm.queryIntentActivities(pickWallpaperIntent, 0); - - // Get list of image picker intents - Intent pickImageIntent = new Intent(Intent.ACTION_GET_CONTENT); - pickImageIntent.setType("image/*"); - final List imagePickerActivities = - pm.queryIntentActivities(pickImageIntent, 0); - final ComponentName[] imageActivities = new ComponentName[imagePickerActivities.size()]; - for (int i = 0; i < imagePickerActivities.size(); i++) { - ActivityInfo activityInfo = imagePickerActivities.get(i).activityInfo; - imageActivities[i] = new ComponentName(activityInfo.packageName, activityInfo.name); - } - - outerLoop: - for (ResolveInfo info : apps) { - final ComponentName itemComponentName = - new ComponentName(info.activityInfo.packageName, info.activityInfo.name); - final String itemPackageName = itemComponentName.getPackageName(); - // Exclude anything from our own package, and the old Launcher, - // and live wallpaper picker - if (itemPackageName.equals(context.getPackageName()) || - itemPackageName.equals("com.android.launcher") || - itemPackageName.equals("com.android.wallpaper.livepicker")) { - continue; - } - // Exclude any package that already responds to the image picker intent - for (ResolveInfo imagePickerActivityInfo : imagePickerActivities) { - if (itemPackageName.equals( - imagePickerActivityInfo.activityInfo.packageName)) { - continue outerLoop; - } - } - mThirdPartyWallpaperPickers.add(new ThirdPartyWallpaperTile(info)); - } - } - - public int getCount() { - return mThirdPartyWallpaperPickers.size(); - } - - public ThirdPartyWallpaperTile getItem(int position) { - return mThirdPartyWallpaperPickers.get(position); - } - - public long getItemId(int position) { - return position; - } - - public View getView(int position, View convertView, ViewGroup parent) { - View view; - - if (convertView == null) { - view = mInflater.inflate(R.layout.wallpaper_picker_third_party_item, parent, false); - } else { - view = convertView; - } - - WallpaperPickerActivity.setWallpaperItemPaddingToZero((FrameLayout) view); - - ResolveInfo info = mThirdPartyWallpaperPickers.get(position).mResolveInfo; - TextView label = (TextView) view.findViewById(R.id.wallpaper_item_label); - label.setText(info.loadLabel(mPackageManager)); - Drawable icon = info.loadIcon(mPackageManager); - icon.setBounds(new Rect(0, 0, mIconSize, mIconSize)); - label.setCompoundDrawables(null, icon, null, null); - return view; - } -} diff --git a/src/com/android/launcher3/WallpaperRootView.java b/src/com/android/launcher3/WallpaperRootView.java deleted file mode 100644 index ceaa043a7..000000000 --- a/src/com/android/launcher3/WallpaperRootView.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (C) 2013 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.launcher3; - -import android.content.Context; -import android.graphics.Rect; -import android.util.AttributeSet; -import android.widget.RelativeLayout; - -public class WallpaperRootView extends RelativeLayout { - private final WallpaperPickerActivity a; - public WallpaperRootView(Context context, AttributeSet attrs) { - super(context, attrs); - a = (WallpaperPickerActivity) context; - } - public WallpaperRootView(Context context, AttributeSet attrs, int defStyle) { - super(context, attrs, defStyle); - a = (WallpaperPickerActivity) context; - } - - protected boolean fitSystemWindows(Rect insets) { - a.setWallpaperStripYOffset(insets.bottom); - return true; - } -} diff --git a/update_system_wallpaper_cropper.py b/update_system_wallpaper_cropper.py index 5d24f6ffe..36904f215 100644 --- a/update_system_wallpaper_cropper.py +++ b/update_system_wallpaper_cropper.py @@ -5,42 +5,43 @@ # necessary so do this with care import os import sys +src_dir = "wallpaper_picker_src/" files = """ src/android/util/Pools.java -src/com/android/gallery3d/util/IntArray.java -src/com/android/gallery3d/common/Utils.java -src/com/android/gallery3d/exif/ByteBufferInputStream.java -src/com/android/gallery3d/exif/CountedDataInputStream.java -src/com/android/gallery3d/exif/ExifData.java -src/com/android/gallery3d/exif/ExifInterface.java -src/com/android/gallery3d/exif/ExifInvalidFormatException.java -src/com/android/gallery3d/exif/ExifModifier.java -src/com/android/gallery3d/exif/ExifOutputStream.java -src/com/android/gallery3d/exif/ExifParser.java -src/com/android/gallery3d/exif/ExifReader.java -src/com/android/gallery3d/exif/ExifTag.java -src/com/android/gallery3d/exif/IfdData.java -src/com/android/gallery3d/exif/IfdId.java -src/com/android/gallery3d/exif/JpegHeader.java -src/com/android/gallery3d/exif/OrderedDataOutputStream.java -src/com/android/gallery3d/exif/Rational.java -src/com/android/gallery3d/glrenderer/BasicTexture.java -src/com/android/gallery3d/glrenderer/BitmapTexture.java -src/com/android/gallery3d/glrenderer/GLCanvas.java -src/com/android/gallery3d/glrenderer/GLES20Canvas.java -src/com/android/gallery3d/glrenderer/GLES20IdImpl.java -src/com/android/gallery3d/glrenderer/GLId.java -src/com/android/gallery3d/glrenderer/GLPaint.java -src/com/android/gallery3d/glrenderer/RawTexture.java -src/com/android/gallery3d/glrenderer/Texture.java -src/com/android/gallery3d/glrenderer/UploadedTexture.java -src/com/android/photos/BitmapRegionTileSource.java -src/com/android/photos/views/BlockingGLTextureView.java -src/com/android/photos/views/TiledImageRenderer.java -src/com/android/photos/views/TiledImageView.java -src/com/android/gallery3d/common/BitmapUtils.java -src/com/android/launcher3/CropView.java -src/com/android/launcher3/WallpaperCropActivity.java +com/android/gallery3d/util/IntArray.java +com/android/gallery3d/common/Utils.java +com/android/gallery3d/exif/ByteBufferInputStream.java +com/android/gallery3d/exif/CountedDataInputStream.java +com/android/gallery3d/exif/ExifData.java +com/android/gallery3d/exif/ExifInterface.java +com/android/gallery3d/exif/ExifInvalidFormatException.java +com/android/gallery3d/exif/ExifModifier.java +com/android/gallery3d/exif/ExifOutputStream.java +com/android/gallery3d/exif/ExifParser.java +com/android/gallery3d/exif/ExifReader.java +com/android/gallery3d/exif/ExifTag.java +com/android/gallery3d/exif/IfdData.java +com/android/gallery3d/exif/IfdId.java +com/android/gallery3d/exif/JpegHeader.java +com/android/gallery3d/exif/OrderedDataOutputStream.java +com/android/gallery3d/exif/Rational.java +com/android/gallery3d/glrenderer/BasicTexture.java +com/android/gallery3d/glrenderer/BitmapTexture.java +com/android/gallery3d/glrenderer/GLCanvas.java +com/android/gallery3d/glrenderer/GLES20Canvas.java +com/android/gallery3d/glrenderer/GLES20IdImpl.java +com/android/gallery3d/glrenderer/GLId.java +com/android/gallery3d/glrenderer/GLPaint.java +com/android/gallery3d/glrenderer/RawTexture.java +com/android/gallery3d/glrenderer/Texture.java +com/android/gallery3d/glrenderer/UploadedTexture.java +com/android/photos/BitmapRegionTileSource.java +com/android/photos/views/BlockingGLTextureView.java +com/android/photos/views/TiledImageRenderer.java +com/android/photos/views/TiledImageView.java +com/android/gallery3d/common/BitmapUtils.java +com/android/launcher3/CropView.java +com/android/launcher3/WallpaperCropActivity.java """ if len(sys.argv) != 2: @@ -48,8 +49,10 @@ if len(sys.argv) != 2: exit() framework_dir = sys.argv[1] + "/packages/WallpaperCropper" for file_path in files.split(): + file_path = src_dir + file_path dir = os.path.dirname(file_path) dir = dir.replace("launcher3", "wallpapercropper") + dir = dir.replace(src_dir, "src/") cmd = 'cp %s %s/%s' % (file_path, framework_dir, dir) print cmd os.system(cmd) diff --git a/wallpaper_picker_src/com/android/launcher3/DrawableTileSource.java b/wallpaper_picker_src/com/android/launcher3/DrawableTileSource.java new file mode 100644 index 000000000..c1f2eff0f --- /dev/null +++ b/wallpaper_picker_src/com/android/launcher3/DrawableTileSource.java @@ -0,0 +1,102 @@ +/* + * Copyright (C) 2013 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.launcher3; + +import android.content.Context; +import android.graphics.Bitmap; +import android.graphics.Canvas; +import android.graphics.Rect; +import android.graphics.drawable.Drawable; + +import com.android.gallery3d.glrenderer.BasicTexture; +import com.android.gallery3d.glrenderer.BitmapTexture; +import com.android.photos.views.TiledImageRenderer; + +public class DrawableTileSource implements TiledImageRenderer.TileSource { + private static final int GL_SIZE_LIMIT = 2048; + // This must be no larger than half the size of the GL_SIZE_LIMIT + // due to decodePreview being allowed to be up to 2x the size of the target + public static final int MAX_PREVIEW_SIZE = GL_SIZE_LIMIT / 2; + + private int mTileSize; + private int mPreviewSize; + private Drawable mDrawable; + private BitmapTexture mPreview; + + public DrawableTileSource(Context context, Drawable d, int previewSize) { + mTileSize = TiledImageRenderer.suggestedTileSize(context); + mDrawable = d; + mPreviewSize = Math.min(previewSize, MAX_PREVIEW_SIZE); + } + + @Override + public int getTileSize() { + return mTileSize; + } + + @Override + public int getImageWidth() { + return mDrawable.getIntrinsicWidth(); + } + + @Override + public int getImageHeight() { + return mDrawable.getIntrinsicHeight(); + } + + @Override + public int getRotation() { + return 0; + } + + @Override + public BasicTexture getPreview() { + if (mPreviewSize == 0) { + return null; + } + if (mPreview == null){ + float width = getImageWidth(); + float height = getImageHeight(); + while (width > MAX_PREVIEW_SIZE || height > MAX_PREVIEW_SIZE) { + width /= 2; + height /= 2; + } + Bitmap b = Bitmap.createBitmap((int) width, (int) height, Bitmap.Config.ARGB_8888); + Canvas c = new Canvas(b); + mDrawable.setBounds(new Rect(0, 0, (int) width, (int) height)); + mDrawable.draw(c); + c.setBitmap(null); + mPreview = new BitmapTexture(b); + } + return mPreview; + } + + @Override + public Bitmap getTile(int level, int x, int y, Bitmap bitmap) { + int tileSize = getTileSize(); + if (bitmap == null) { + bitmap = Bitmap.createBitmap(tileSize, tileSize, Bitmap.Config.ARGB_8888); + } + Canvas c = new Canvas(bitmap); + Rect bounds = new Rect(0, 0, getImageWidth(), getImageHeight()); + bounds.offset(-x, -y); + mDrawable.setBounds(bounds); + mDrawable.draw(c); + c.setBitmap(null); + return bitmap; + } +} diff --git a/wallpaper_picker_src/com/android/launcher3/LiveWallpaperListAdapter.java b/wallpaper_picker_src/com/android/launcher3/LiveWallpaperListAdapter.java new file mode 100644 index 000000000..152a75ded --- /dev/null +++ b/wallpaper_picker_src/com/android/launcher3/LiveWallpaperListAdapter.java @@ -0,0 +1,205 @@ +/* + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.launcher3; + +import android.app.WallpaperInfo; +import android.app.WallpaperManager; +import android.content.Context; +import android.content.Intent; +import android.content.pm.PackageManager; +import android.content.pm.ResolveInfo; +import android.graphics.drawable.Drawable; +import android.os.AsyncTask; +import android.service.wallpaper.WallpaperService; +import android.util.Log; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.BaseAdapter; +import android.widget.FrameLayout; +import android.widget.ImageView; +import android.widget.ListAdapter; +import android.widget.TextView; + +import org.xmlpull.v1.XmlPullParserException; + +import java.io.IOException; +import java.text.Collator; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; +import java.util.List; + +public class LiveWallpaperListAdapter extends BaseAdapter implements ListAdapter { + private static final String LOG_TAG = "LiveWallpaperListAdapter"; + + private final LayoutInflater mInflater; + private final PackageManager mPackageManager; + + private List mWallpapers; + + @SuppressWarnings("unchecked") + public LiveWallpaperListAdapter(Context context) { + mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); + mPackageManager = context.getPackageManager(); + + List list = mPackageManager.queryIntentServices( + new Intent(WallpaperService.SERVICE_INTERFACE), + PackageManager.GET_META_DATA); + + mWallpapers = new ArrayList(); + + new LiveWallpaperEnumerator(context).execute(list); + } + + public int getCount() { + if (mWallpapers == null) { + return 0; + } + return mWallpapers.size(); + } + + public LiveWallpaperTile getItem(int position) { + return mWallpapers.get(position); + } + + public long getItemId(int position) { + return position; + } + + public View getView(int position, View convertView, ViewGroup parent) { + View view; + + if (convertView == null) { + view = mInflater.inflate(R.layout.wallpaper_picker_live_wallpaper_item, parent, false); + } else { + view = convertView; + } + + WallpaperPickerActivity.setWallpaperItemPaddingToZero((FrameLayout) view); + + LiveWallpaperTile wallpaperInfo = mWallpapers.get(position); + wallpaperInfo.setView(view); + ImageView image = (ImageView) view.findViewById(R.id.wallpaper_image); + ImageView icon = (ImageView) view.findViewById(R.id.wallpaper_icon); + if (wallpaperInfo.mThumbnail != null) { + image.setImageDrawable(wallpaperInfo.mThumbnail); + icon.setVisibility(View.GONE); + } else { + icon.setImageDrawable(wallpaperInfo.mInfo.loadIcon(mPackageManager)); + icon.setVisibility(View.VISIBLE); + } + + TextView label = (TextView) view.findViewById(R.id.wallpaper_item_label); + label.setText(wallpaperInfo.mInfo.loadLabel(mPackageManager)); + + return view; + } + + public static class LiveWallpaperTile extends WallpaperPickerActivity.WallpaperTileInfo { + private Drawable mThumbnail; + private WallpaperInfo mInfo; + public LiveWallpaperTile(Drawable thumbnail, WallpaperInfo info, Intent intent) { + mThumbnail = thumbnail; + mInfo = info; + } + @Override + public void onClick(WallpaperPickerActivity a) { + Intent preview = new Intent(WallpaperManager.ACTION_CHANGE_LIVE_WALLPAPER); + preview.putExtra(WallpaperManager.EXTRA_LIVE_WALLPAPER_COMPONENT, + mInfo.getComponent()); + a.onLiveWallpaperPickerLaunch(); + Utilities.startActivityForResultSafely( + a, preview, WallpaperPickerActivity.PICK_LIVE_WALLPAPER); + } + } + + private class LiveWallpaperEnumerator extends + AsyncTask, LiveWallpaperTile, Void> { + private Context mContext; + private int mWallpaperPosition; + + public LiveWallpaperEnumerator(Context context) { + super(); + mContext = context; + mWallpaperPosition = 0; + } + + @Override + protected Void doInBackground(List... params) { + final PackageManager packageManager = mContext.getPackageManager(); + + List list = params[0]; + + Collections.sort(list, new Comparator() { + final Collator mCollator; + + { + mCollator = Collator.getInstance(); + } + + public int compare(ResolveInfo info1, ResolveInfo info2) { + return mCollator.compare(info1.loadLabel(packageManager), + info2.loadLabel(packageManager)); + } + }); + + for (ResolveInfo resolveInfo : list) { + WallpaperInfo info = null; + try { + info = new WallpaperInfo(mContext, resolveInfo); + } catch (XmlPullParserException e) { + Log.w(LOG_TAG, "Skipping wallpaper " + resolveInfo.serviceInfo, e); + continue; + } catch (IOException e) { + Log.w(LOG_TAG, "Skipping wallpaper " + resolveInfo.serviceInfo, e); + continue; + } + + + Drawable thumb = info.loadThumbnail(packageManager); + Intent launchIntent = new Intent(WallpaperService.SERVICE_INTERFACE); + launchIntent.setClassName(info.getPackageName(), info.getServiceName()); + LiveWallpaperTile wallpaper = new LiveWallpaperTile(thumb, info, launchIntent); + publishProgress(wallpaper); + } + // Send a null object to show loading is finished + publishProgress((LiveWallpaperTile) null); + + return null; + } + + @Override + protected void onProgressUpdate(LiveWallpaperTile...infos) { + for (LiveWallpaperTile info : infos) { + if (info == null) { + LiveWallpaperListAdapter.this.notifyDataSetChanged(); + break; + } + if (info.mThumbnail != null) { + info.mThumbnail.setDither(true); + } + if (mWallpaperPosition < mWallpapers.size()) { + mWallpapers.set(mWallpaperPosition, info); + } else { + mWallpapers.add(info); + } + mWallpaperPosition++; + } + } + } +} diff --git a/wallpaper_picker_src/com/android/launcher3/SavedWallpaperImages.java b/wallpaper_picker_src/com/android/launcher3/SavedWallpaperImages.java new file mode 100644 index 000000000..58add7022 --- /dev/null +++ b/wallpaper_picker_src/com/android/launcher3/SavedWallpaperImages.java @@ -0,0 +1,241 @@ +/* + * Copyright (C) 2013 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.launcher3; + +import android.app.Activity; +import android.content.ContentValues; +import android.content.Context; +import android.database.Cursor; +import android.database.sqlite.SQLiteDatabase; +import android.database.sqlite.SQLiteOpenHelper; +import android.graphics.Bitmap; +import android.graphics.BitmapFactory; +import android.graphics.drawable.BitmapDrawable; +import android.graphics.drawable.Drawable; +import android.util.Log; +import android.util.Pair; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.BaseAdapter; +import android.widget.ListAdapter; + +import com.android.photos.BitmapRegionTileSource; + +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.util.ArrayList; + + +public class SavedWallpaperImages extends BaseAdapter implements ListAdapter { + private static String TAG = "Launcher3.SavedWallpaperImages"; + private ImageDb mDb; + ArrayList mImages; + Context mContext; + LayoutInflater mLayoutInflater; + + public static class SavedWallpaperTile extends WallpaperPickerActivity.WallpaperTileInfo { + private int mDbId; + private Drawable mThumb; + public SavedWallpaperTile(int dbId, Drawable thumb) { + mDbId = dbId; + mThumb = thumb; + } + @Override + public void onClick(WallpaperPickerActivity a) { + String imageFilename = a.getSavedImages().getImageFilename(mDbId); + File file = new File(a.getFilesDir(), imageFilename); + BitmapRegionTileSource.FilePathBitmapSource bitmapSource = + new BitmapRegionTileSource.FilePathBitmapSource(file.getAbsolutePath(), 1024); + a.setCropViewTileSource(bitmapSource, false, true, null); + } + @Override + public void onSave(WallpaperPickerActivity a) { + boolean finishActivityWhenDone = true; + String imageFilename = a.getSavedImages().getImageFilename(mDbId); + a.setWallpaper(imageFilename, finishActivityWhenDone); + } + @Override + public void onDelete(WallpaperPickerActivity a) { + a.getSavedImages().deleteImage(mDbId); + } + @Override + public boolean isSelectable() { + return true; + } + @Override + public boolean isNamelessWallpaper() { + return true; + } + } + + public SavedWallpaperImages(Activity context) { + mDb = new ImageDb(context); + mContext = context; + mLayoutInflater = context.getLayoutInflater(); + } + + public void loadThumbnailsAndImageIdList() { + mImages = new ArrayList(); + SQLiteDatabase db = mDb.getReadableDatabase(); + Cursor result = db.query(ImageDb.TABLE_NAME, + new String[] { ImageDb.COLUMN_ID, + ImageDb.COLUMN_IMAGE_THUMBNAIL_FILENAME }, // cols to return + null, // select query + null, // args to select query + null, + null, + ImageDb.COLUMN_ID + " DESC", + null); + + while (result.moveToNext()) { + String filename = result.getString(1); + File file = new File(mContext.getFilesDir(), filename); + + Bitmap thumb = BitmapFactory.decodeFile(file.getAbsolutePath()); + if (thumb != null) { + mImages.add(new SavedWallpaperTile(result.getInt(0), new BitmapDrawable(thumb))); + } + } + result.close(); + } + + public int getCount() { + return mImages.size(); + } + + public SavedWallpaperTile getItem(int position) { + return mImages.get(position); + } + + public long getItemId(int position) { + return position; + } + + public View getView(int position, View convertView, ViewGroup parent) { + Drawable thumbDrawable = mImages.get(position).mThumb; + if (thumbDrawable == null) { + Log.e(TAG, "Error decoding thumbnail for wallpaper #" + position); + } + return WallpaperPickerActivity.createImageTileView( + mLayoutInflater, position, convertView, parent, thumbDrawable); + } + + public String getImageFilename(int id) { + Pair filenames = getImageFilenames(id); + if (filenames != null) { + return filenames.second; + } + return null; + } + + private Pair getImageFilenames(int id) { + SQLiteDatabase db = mDb.getReadableDatabase(); + Cursor result = db.query(ImageDb.TABLE_NAME, + new String[] { ImageDb.COLUMN_IMAGE_THUMBNAIL_FILENAME, + ImageDb.COLUMN_IMAGE_FILENAME }, // cols to return + ImageDb.COLUMN_ID + " = ?", // select query + new String[] { Integer.toString(id) }, // args to select query + null, + null, + null, + null); + if (result.getCount() > 0) { + result.moveToFirst(); + String thumbFilename = result.getString(0); + String imageFilename = result.getString(1); + result.close(); + return new Pair(thumbFilename, imageFilename); + } else { + return null; + } + } + + public void deleteImage(int id) { + Pair filenames = getImageFilenames(id); + File imageFile = new File(mContext.getFilesDir(), filenames.first); + imageFile.delete(); + File thumbFile = new File(mContext.getFilesDir(), filenames.second); + thumbFile.delete(); + SQLiteDatabase db = mDb.getWritableDatabase(); + db.delete(ImageDb.TABLE_NAME, + ImageDb.COLUMN_ID + " = ?", // SELECT query + new String[] { + Integer.toString(id) // args to SELECT query + }); + } + + public void writeImage(Bitmap thumbnail, byte[] imageBytes) { + try { + File imageFile = File.createTempFile("wallpaper", "", mContext.getFilesDir()); + FileOutputStream imageFileStream = + mContext.openFileOutput(imageFile.getName(), Context.MODE_PRIVATE); + imageFileStream.write(imageBytes); + imageFileStream.close(); + + File thumbFile = File.createTempFile("wallpaperthumb", "", mContext.getFilesDir()); + FileOutputStream thumbFileStream = + mContext.openFileOutput(thumbFile.getName(), Context.MODE_PRIVATE); + thumbnail.compress(Bitmap.CompressFormat.JPEG, 95, thumbFileStream); + thumbFileStream.close(); + + SQLiteDatabase db = mDb.getWritableDatabase(); + ContentValues values = new ContentValues(); + values.put(ImageDb.COLUMN_IMAGE_THUMBNAIL_FILENAME, thumbFile.getName()); + values.put(ImageDb.COLUMN_IMAGE_FILENAME, imageFile.getName()); + db.insert(ImageDb.TABLE_NAME, null, values); + } catch (IOException e) { + Log.e(TAG, "Failed writing images to storage " + e); + } + } + + static class ImageDb extends SQLiteOpenHelper { + final static int DB_VERSION = 1; + final static String DB_NAME = "saved_wallpaper_images.db"; + final static String TABLE_NAME = "saved_wallpaper_images"; + final static String COLUMN_ID = "id"; + final static String COLUMN_IMAGE_THUMBNAIL_FILENAME = "image_thumbnail"; + final static String COLUMN_IMAGE_FILENAME = "image"; + + Context mContext; + + public ImageDb(Context context) { + super(context, new File(context.getCacheDir(), DB_NAME).getPath(), null, DB_VERSION); + // Store the context for later use + mContext = context; + } + + @Override + public void onCreate(SQLiteDatabase database) { + database.execSQL("CREATE TABLE IF NOT EXISTS " + TABLE_NAME + " (" + + COLUMN_ID + " INTEGER NOT NULL, " + + COLUMN_IMAGE_THUMBNAIL_FILENAME + " TEXT NOT NULL, " + + COLUMN_IMAGE_FILENAME + " TEXT NOT NULL, " + + "PRIMARY KEY (" + COLUMN_ID + " ASC) " + + ");"); + } + + @Override + public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { + if (oldVersion != newVersion) { + // Delete all the records; they'll be repopulated as this is a cache + db.execSQL("DELETE FROM " + TABLE_NAME); + } + } + } +} diff --git a/wallpaper_picker_src/com/android/launcher3/ThirdPartyWallpaperPickerListAdapter.java b/wallpaper_picker_src/com/android/launcher3/ThirdPartyWallpaperPickerListAdapter.java new file mode 100644 index 000000000..494694cbd --- /dev/null +++ b/wallpaper_picker_src/com/android/launcher3/ThirdPartyWallpaperPickerListAdapter.java @@ -0,0 +1,139 @@ +/* + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.launcher3; + +import android.content.ComponentName; +import android.content.Context; +import android.content.Intent; +import android.content.pm.ActivityInfo; +import android.content.pm.PackageManager; +import android.content.pm.ResolveInfo; +import android.graphics.Rect; +import android.graphics.drawable.Drawable; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.BaseAdapter; +import android.widget.FrameLayout; +import android.widget.ListAdapter; +import android.widget.TextView; + +import java.util.ArrayList; +import java.util.List; + +public class ThirdPartyWallpaperPickerListAdapter extends BaseAdapter implements ListAdapter { + private static final String LOG_TAG = "LiveWallpaperListAdapter"; + + private final LayoutInflater mInflater; + private final PackageManager mPackageManager; + private final int mIconSize; + + private List mThirdPartyWallpaperPickers = + new ArrayList(); + + public static class ThirdPartyWallpaperTile extends WallpaperPickerActivity.WallpaperTileInfo { + private ResolveInfo mResolveInfo; + public ThirdPartyWallpaperTile(ResolveInfo resolveInfo) { + mResolveInfo = resolveInfo; + } + @Override + public void onClick(WallpaperPickerActivity a) { + final ComponentName itemComponentName = new ComponentName( + mResolveInfo.activityInfo.packageName, mResolveInfo.activityInfo.name); + Intent launchIntent = new Intent(Intent.ACTION_SET_WALLPAPER); + launchIntent.setComponent(itemComponentName); + Utilities.startActivityForResultSafely( + a, launchIntent, WallpaperPickerActivity.PICK_WALLPAPER_THIRD_PARTY_ACTIVITY); + } + } + + public ThirdPartyWallpaperPickerListAdapter(Context context) { + mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); + mPackageManager = context.getPackageManager(); + mIconSize = context.getResources().getDimensionPixelSize(R.dimen.wallpaperItemIconSize); + final PackageManager pm = mPackageManager; + + final Intent pickWallpaperIntent = new Intent(Intent.ACTION_SET_WALLPAPER); + final List apps = + pm.queryIntentActivities(pickWallpaperIntent, 0); + + // Get list of image picker intents + Intent pickImageIntent = new Intent(Intent.ACTION_GET_CONTENT); + pickImageIntent.setType("image/*"); + final List imagePickerActivities = + pm.queryIntentActivities(pickImageIntent, 0); + final ComponentName[] imageActivities = new ComponentName[imagePickerActivities.size()]; + for (int i = 0; i < imagePickerActivities.size(); i++) { + ActivityInfo activityInfo = imagePickerActivities.get(i).activityInfo; + imageActivities[i] = new ComponentName(activityInfo.packageName, activityInfo.name); + } + + outerLoop: + for (ResolveInfo info : apps) { + final ComponentName itemComponentName = + new ComponentName(info.activityInfo.packageName, info.activityInfo.name); + final String itemPackageName = itemComponentName.getPackageName(); + // Exclude anything from our own package, and the old Launcher, + // and live wallpaper picker + if (itemPackageName.equals(context.getPackageName()) || + itemPackageName.equals("com.android.launcher") || + itemPackageName.equals("com.android.wallpaper.livepicker")) { + continue; + } + // Exclude any package that already responds to the image picker intent + for (ResolveInfo imagePickerActivityInfo : imagePickerActivities) { + if (itemPackageName.equals( + imagePickerActivityInfo.activityInfo.packageName)) { + continue outerLoop; + } + } + mThirdPartyWallpaperPickers.add(new ThirdPartyWallpaperTile(info)); + } + } + + public int getCount() { + return mThirdPartyWallpaperPickers.size(); + } + + public ThirdPartyWallpaperTile getItem(int position) { + return mThirdPartyWallpaperPickers.get(position); + } + + public long getItemId(int position) { + return position; + } + + public View getView(int position, View convertView, ViewGroup parent) { + View view; + + if (convertView == null) { + view = mInflater.inflate(R.layout.wallpaper_picker_third_party_item, parent, false); + } else { + view = convertView; + } + + WallpaperPickerActivity.setWallpaperItemPaddingToZero((FrameLayout) view); + + ResolveInfo info = mThirdPartyWallpaperPickers.get(position).mResolveInfo; + TextView label = (TextView) view.findViewById(R.id.wallpaper_item_label); + label.setText(info.loadLabel(mPackageManager)); + Drawable icon = info.loadIcon(mPackageManager); + icon.setBounds(new Rect(0, 0, mIconSize, mIconSize)); + label.setCompoundDrawables(null, icon, null, null); + return view; + } +} diff --git a/wallpaper_picker_src/com/android/launcher3/WallpaperRootView.java b/wallpaper_picker_src/com/android/launcher3/WallpaperRootView.java new file mode 100644 index 000000000..ceaa043a7 --- /dev/null +++ b/wallpaper_picker_src/com/android/launcher3/WallpaperRootView.java @@ -0,0 +1,39 @@ +/* + * Copyright (C) 2013 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.launcher3; + +import android.content.Context; +import android.graphics.Rect; +import android.util.AttributeSet; +import android.widget.RelativeLayout; + +public class WallpaperRootView extends RelativeLayout { + private final WallpaperPickerActivity a; + public WallpaperRootView(Context context, AttributeSet attrs) { + super(context, attrs); + a = (WallpaperPickerActivity) context; + } + public WallpaperRootView(Context context, AttributeSet attrs, int defStyle) { + super(context, attrs, defStyle); + a = (WallpaperPickerActivity) context; + } + + protected boolean fitSystemWindows(Rect insets) { + a.setWallpaperStripYOffset(insets.bottom); + return true; + } +} -- cgit v1.2.3