diff options
author | Danesh M <daneshm90@gmail.com> | 2013-08-09 14:40:23 -0700 |
---|---|---|
committer | Danesh M <daneshm90@gmail.com> | 2013-08-16 10:49:52 -0700 |
commit | 3effba041c8019be2cdd5da19409c45f7529bade (patch) | |
tree | 948f27cb0fd0d485f28e68c720d8fc12b9dfb554 | |
parent | 8834e86030ab48890308b3aaa005c11cf968424f (diff) | |
download | android_packages_providers_DownloadProvider-3effba041c8019be2cdd5da19409c45f7529bade.tar.gz android_packages_providers_DownloadProvider-3effba041c8019be2cdd5da19409c45f7529bade.tar.bz2 android_packages_providers_DownloadProvider-3effba041c8019be2cdd5da19409c45f7529bade.zip |
DownloadManager : Add live folder
Add support for live folders, which mirrors downloaded content
Change-Id: I145a8e044d0ac9b9bd62ebd7db4c0d6a265391f7
-rw-r--r-- | Android.mk | 1 | ||||
-rw-r--r-- | AndroidManifest.xml | 17 | ||||
-rw-r--r-- | res/drawable-hdpi/ic_download_misc_file_type.png | bin | 0 -> 2405 bytes | |||
-rw-r--r-- | res/drawable-mdpi/ic_download_misc_file_type.png | bin | 0 -> 1624 bytes | |||
-rw-r--r-- | res/mipmap-hdpi/ic_launcher_download.png | bin | 0 -> 10593 bytes | |||
-rw-r--r-- | res/mipmap-mdpi/ic_launcher_download.png | bin | 0 -> 23509 bytes | |||
-rw-r--r-- | res/mipmap-xhdpi/ic_launcher_download.png | bin | 0 -> 32416 bytes | |||
-rw-r--r-- | res/mipmap-xxhdpi/ic_launcher_download.png | bin | 0 -> 21228 bytes | |||
-rw-r--r-- | res/values/cm_strings.xml | 19 | ||||
-rw-r--r-- | src/com/android/providers/downloads/DownloadService.java | 5 | ||||
-rw-r--r-- | src/com/android/providers/downloads/LiveFolderConfigActivity.java | 40 | ||||
-rw-r--r-- | src/com/android/providers/downloads/LiveFolderReceiver.java | 145 |
12 files changed, 227 insertions, 0 deletions
@@ -9,6 +9,7 @@ LOCAL_SRC_FILES := $(call all-java-files-under, src) LOCAL_PACKAGE_NAME := DownloadProvider LOCAL_CERTIFICATE := media LOCAL_STATIC_JAVA_LIBRARIES := guava +LOCAL_STATIC_JAVA_LIBRARIES += org.cyanogenmod.support include $(BUILD_PACKAGE) diff --git a/AndroidManifest.xml b/AndroidManifest.xml index 3024a17a..eb7eed4a 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -56,6 +56,7 @@ <uses-permission android:name="android.permission.MODIFY_NETWORK_ACCOUNTING" /> <application android:process="android.process.media" + android:icon="@mipmap/ic_launcher_download" android:label="@string/app_label"> <provider android:name=".DownloadProvider" @@ -90,6 +91,22 @@ </intent-filter> </receiver> + <activity android:name=".LiveFolderConfigActivity" android:label="@string/live_folder_drawer_label" + android:permission="com.cyanogenmod.trebuchet.permission.MANAGE_LIVE_FOLDERS" + android:theme="@android:style/Theme.NoDisplay"> + <intent-filter> + <action android:name="cyanogenmod.intent.action.CREATE_LIVE_FOLDER" /> + </intent-filter> + </activity> + + <receiver android:name=".LiveFolderReceiver" + android:permission="com.cyanogenmod.trebuchet.permission.MANAGE_LIVE_FOLDERS" + android:exported="true"> + <intent-filter> + <action android:name="cyanogenmod.intent.action.LIVE_FOLDER_UPDATES" /> + </intent-filter> + </receiver> + <activity android:name=".SizeLimitActivity" android:launchMode="singleTask" android:theme="@style/Theme.Translucent"/> diff --git a/res/drawable-hdpi/ic_download_misc_file_type.png b/res/drawable-hdpi/ic_download_misc_file_type.png Binary files differnew file mode 100644 index 00000000..dab3b6e1 --- /dev/null +++ b/res/drawable-hdpi/ic_download_misc_file_type.png diff --git a/res/drawable-mdpi/ic_download_misc_file_type.png b/res/drawable-mdpi/ic_download_misc_file_type.png Binary files differnew file mode 100644 index 00000000..ceed70cf --- /dev/null +++ b/res/drawable-mdpi/ic_download_misc_file_type.png diff --git a/res/mipmap-hdpi/ic_launcher_download.png b/res/mipmap-hdpi/ic_launcher_download.png Binary files differnew file mode 100644 index 00000000..3f092d39 --- /dev/null +++ b/res/mipmap-hdpi/ic_launcher_download.png diff --git a/res/mipmap-mdpi/ic_launcher_download.png b/res/mipmap-mdpi/ic_launcher_download.png Binary files differnew file mode 100644 index 00000000..76652fb9 --- /dev/null +++ b/res/mipmap-mdpi/ic_launcher_download.png diff --git a/res/mipmap-xhdpi/ic_launcher_download.png b/res/mipmap-xhdpi/ic_launcher_download.png Binary files differnew file mode 100644 index 00000000..7d7b1b11 --- /dev/null +++ b/res/mipmap-xhdpi/ic_launcher_download.png diff --git a/res/mipmap-xxhdpi/ic_launcher_download.png b/res/mipmap-xxhdpi/ic_launcher_download.png Binary files differnew file mode 100644 index 00000000..0921c124 --- /dev/null +++ b/res/mipmap-xxhdpi/ic_launcher_download.png diff --git a/res/values/cm_strings.xml b/res/values/cm_strings.xml new file mode 100644 index 00000000..30e80386 --- /dev/null +++ b/res/values/cm_strings.xml @@ -0,0 +1,19 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- Copyright (C) 2012-2013 The CyanogenMod 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. +--> +<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2"> + <string name="live_folder_drawer_label">Downloads folder</string> + <string name="live_folder_label">Downloads</string> +</resources> diff --git a/src/com/android/providers/downloads/DownloadService.java b/src/com/android/providers/downloads/DownloadService.java index 7d746cca..0d4266fb 100644 --- a/src/com/android/providers/downloads/DownloadService.java +++ b/src/com/android/providers/downloads/DownloadService.java @@ -368,6 +368,10 @@ public class DownloadService extends Service { PendingIntent.getBroadcast(this, 0, intent, PendingIntent.FLAG_ONE_SHOT)); } + if (!isActive) { + LiveFolderReceiver.updateFolders(this, 0); + } + return isActive; } @@ -413,6 +417,7 @@ public class DownloadService extends Service { deleteFileIfExists(info.mFileName); } mDownloads.remove(info.mId); + LiveFolderReceiver.updateFolders(this, 0); } private void deleteFileIfExists(String path) { diff --git a/src/com/android/providers/downloads/LiveFolderConfigActivity.java b/src/com/android/providers/downloads/LiveFolderConfigActivity.java new file mode 100644 index 00000000..cf8183e2 --- /dev/null +++ b/src/com/android/providers/downloads/LiveFolderConfigActivity.java @@ -0,0 +1,40 @@ +/* + * Copyright (C) 2013 The CyanogenMod 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.providers.downloads; + +import android.app.Activity; +import android.content.ComponentName; +import android.content.Intent; +import android.os.Bundle; + +import org.cyanogenmod.support.ui.LiveFolder; + +public class LiveFolderConfigActivity extends Activity { + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + Intent i = new Intent(); + // Set the receiver responsible for folder updates + ComponentName receiver = new ComponentName(this, LiveFolderReceiver.class); + i.putExtra(LiveFolder.Constants.FOLDER_RECEIVER_EXTRA, receiver); + i.putExtra(LiveFolder.Constants.FOLDER_TITLE_EXTRA, getString(R.string.live_folder_label)); + setResult(RESULT_OK, i); + finish(); + } + +} diff --git a/src/com/android/providers/downloads/LiveFolderReceiver.java b/src/com/android/providers/downloads/LiveFolderReceiver.java new file mode 100644 index 00000000..58378343 --- /dev/null +++ b/src/com/android/providers/downloads/LiveFolderReceiver.java @@ -0,0 +1,145 @@ +/* + * Copyright (C) 2013 The CyanogenMod 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.providers.downloads; + +import android.app.DownloadManager; +import android.content.BroadcastReceiver; +import android.content.Context; +import android.content.Intent; +import android.content.pm.PackageManager; +import android.content.pm.ResolveInfo; +import android.database.Cursor; +import android.graphics.Bitmap; +import android.graphics.BitmapFactory; +import android.graphics.drawable.BitmapDrawable; +import android.graphics.drawable.Drawable; +import android.net.Uri; +import android.provider.BaseColumns; +import android.text.TextUtils; + +import com.android.providers.downloads.OpenHelper; + +import org.cyanogenmod.support.ui.LiveFolder; + +import java.util.ArrayList; +import java.util.List; + +public class LiveFolderReceiver extends BroadcastReceiver { + + private static int sNumLiveFolders = 0; + + private static Bitmap retrieveAndSetIcon(Context context, String mediaType) { + if (mediaType == null) { + return null; + } + + Intent intent = new Intent(Intent.ACTION_VIEW); + intent.setDataAndType(Uri.fromParts("file", "", null), mediaType); + + PackageManager pm = context.getPackageManager(); + List<ResolveInfo> list = pm.queryIntentActivities(intent, + PackageManager.MATCH_DEFAULT_ONLY); + + if (list.isEmpty()) { + return BitmapFactory.decodeResource(context.getResources(), + R.drawable.ic_download_misc_file_type); + } else { + Drawable d = list.get(0).activityInfo.loadIcon(pm); + return ((BitmapDrawable) d).getBitmap(); + } + } + + public static void updateFolders(Context context, long folderId) { + if (sNumLiveFolders == 0) { + return; + } + + DownloadManager dm = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE); + dm.setAccessAllDownloads(true); + + DownloadManager.Query baseQuery = + new DownloadManager.Query().setOnlyIncludeVisibleInDownloadsUi(true); + Cursor cursor = dm.query(baseQuery); + if (cursor == null) { + return; + } + ArrayList<LiveFolder.Item> folderItems = new ArrayList<LiveFolder.Item>(); + + while (cursor.moveToNext() && folderItems.size() < LiveFolder.Constants.MAX_ITEMS) { + long id = cursor.getLong(cursor.getColumnIndexOrThrow(BaseColumns._ID)); + String title = cursor.getString(cursor.getColumnIndex(DownloadManager.COLUMN_TITLE)); + String mediaType = + cursor.getString(cursor.getColumnIndex(DownloadManager.COLUMN_MEDIA_TYPE)); + + LiveFolder.Item folderItem = new LiveFolder.Item(); + folderItem.setLabel(title); + folderItem.setIcon(retrieveAndSetIcon(context, mediaType)); + folderItem.setId((int) id); + folderItems.add(folderItem); + } + + if (folderItems.isEmpty()) { + return; + } + + if (folderId == 0) { + LiveFolder.updateAllFolders(context, folderItems); + } else { + LiveFolder.updateSingleFolder(context, folderId, folderItems); + } + } + + @Override + public void onReceive(Context context, Intent intent) { + String type = intent.getStringExtra(LiveFolder.Constants.FOLDER_UPDATE_TYPE_EXTRA); + + if (TextUtils.isEmpty(type)) { + return; + } + + long folderId = intent.getLongExtra(LiveFolder.Constants.FOLDER_ID_EXTRA, 0); + if (folderId <= 0 && !type.equals(LiveFolder.Constants.EXISTING_FOLDERS_CREATED)) { + return; + } + + if (type.equals(LiveFolder.Constants.NEW_FOLDER_CREATED)) { + sNumLiveFolders++; + updateFolders(context, folderId); + } else if (type.equals(LiveFolder.Constants.EXISTING_FOLDERS_CREATED)) { + long[] existingFolders = intent.getLongArrayExtra( + LiveFolder.Constants.EXISTING_FOLDER_IDS_EXTRA); + sNumLiveFolders = existingFolders.length; + updateFolders(context, 0); + } else if (type.equals(LiveFolder.Constants.FOLDER_ITEM_SELECTED)) { + int itemId = intent.getIntExtra(LiveFolder.Constants.FOLDER_ITEM_ID_EXTRA, 0); + final Intent viewIntent = OpenHelper.buildViewIntent(context, itemId); + viewIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + context.startActivity(viewIntent); + } else if (type.equals(LiveFolder.Constants.FOLDER_ITEM_REMOVED)) { + // Get selected item id + int itemId = intent.getIntExtra(LiveFolder.Constants.FOLDER_ITEM_ID_EXTRA, 0); + DownloadManager dm = + (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE); + + dm.setAccessAllDownloads(true); + dm.markRowDeleted(itemId); + } else if (type.equals(LiveFolder.Constants.FOLDER_DELETED)) { + sNumLiveFolders--; + } + } + +} |