summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeff Sharkey <jsharkey@android.com>2014-08-06 10:09:40 -0700
committerJeff Sharkey <jsharkey@android.com>2014-08-06 10:09:40 -0700
commit35b0a916ca7fd9a3c0cbfec6eab4fe87c0f4ac13 (patch)
tree9abdd23d2d727559dea7428bb11e857aac64bccb
parent2e16979a9133ef83f6e513eaa4b84de40350a2dd (diff)
downloadandroid_packages_providers_DownloadProvider-35b0a916ca7fd9a3c0cbfec6eab4fe87c0f4ac13.tar.gz
android_packages_providers_DownloadProvider-35b0a916ca7fd9a3c0cbfec6eab4fe87c0f4ac13.tar.bz2
android_packages_providers_DownloadProvider-35b0a916ca7fd9a3c0cbfec6eab4fe87c0f4ac13.zip
Remove unused Downloads code/resources.
Change-Id: Ie9be11140fd8f235eae6455bc4ecf8a938488d04
-rw-r--r--ui/res/anim/footer_appear.xml25
-rw-r--r--ui/res/anim/footer_disappear.xml25
-rw-r--r--ui/res/drawable-hdpi/ic_download_misc_file_type.pngbin2405 -> 0 bytes
-rw-r--r--ui/res/drawable-hdpi/ic_launcher_drm_file.pngbin4501 -> 0 bytes
-rw-r--r--ui/res/drawable-hdpi/ic_menu_desk_clock.pngbin2171 -> 0 bytes
-rw-r--r--ui/res/drawable-mdpi/ic_download_misc_file_type.pngbin1624 -> 0 bytes
-rw-r--r--ui/res/drawable-mdpi/ic_launcher_drm_file.pngbin2738 -> 0 bytes
-rw-r--r--ui/res/layout/download_list.xml71
-rw-r--r--ui/res/layout/download_list_item.xml85
-rw-r--r--ui/res/layout/list_group_header.xml23
-rw-r--r--ui/res/menu/download_menu.xml27
-rw-r--r--ui/res/values/dimen.xml19
-rw-r--r--ui/src/com/android/providers/downloads/ui/DateSortedDownloadAdapter.java60
-rw-r--r--ui/src/com/android/providers/downloads/ui/DateSortedExpandableListAdapter.java354
-rw-r--r--ui/src/com/android/providers/downloads/ui/DownloadAdapter.java215
-rw-r--r--ui/src/com/android/providers/downloads/ui/DownloadItem.java156
-rw-r--r--ui/src/com/android/providers/downloads/ui/DownloadList.java765
17 files changed, 0 insertions, 1825 deletions
diff --git a/ui/res/anim/footer_appear.xml b/ui/res/anim/footer_appear.xml
deleted file mode 100644
index aacfd035..00000000
--- a/ui/res/anim/footer_appear.xml
+++ /dev/null
@@ -1,25 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!--
-** Copyright 2010, Google Inc.
-**
-** 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.
-*/
--->
-
-<set xmlns:android="http://schemas.android.com/apk/res/android" >
- <translate
- android:interpolator="@android:anim/decelerate_interpolator"
- android:fromYDelta="+12%p"
- android:toYDelta="0"
- android:duration="300" />
-</set>
diff --git a/ui/res/anim/footer_disappear.xml b/ui/res/anim/footer_disappear.xml
deleted file mode 100644
index d87be6ab..00000000
--- a/ui/res/anim/footer_disappear.xml
+++ /dev/null
@@ -1,25 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!--
-** Copyright 2010, Google Inc.
-**
-** 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.
-*/
--->
-
-<set xmlns:android="http://schemas.android.com/apk/res/android" >
- <translate
- android:interpolator="@android:anim/decelerate_interpolator"
- android:fromYDelta="0"
- android:toYDelta="+12%p"
- android:duration="300" />
-</set>
diff --git a/ui/res/drawable-hdpi/ic_download_misc_file_type.png b/ui/res/drawable-hdpi/ic_download_misc_file_type.png
deleted file mode 100644
index dab3b6e1..00000000
--- a/ui/res/drawable-hdpi/ic_download_misc_file_type.png
+++ /dev/null
Binary files differ
diff --git a/ui/res/drawable-hdpi/ic_launcher_drm_file.png b/ui/res/drawable-hdpi/ic_launcher_drm_file.png
deleted file mode 100644
index 9df1c556..00000000
--- a/ui/res/drawable-hdpi/ic_launcher_drm_file.png
+++ /dev/null
Binary files differ
diff --git a/ui/res/drawable-hdpi/ic_menu_desk_clock.png b/ui/res/drawable-hdpi/ic_menu_desk_clock.png
deleted file mode 100644
index 4101434e..00000000
--- a/ui/res/drawable-hdpi/ic_menu_desk_clock.png
+++ /dev/null
Binary files differ
diff --git a/ui/res/drawable-mdpi/ic_download_misc_file_type.png b/ui/res/drawable-mdpi/ic_download_misc_file_type.png
deleted file mode 100644
index ceed70cf..00000000
--- a/ui/res/drawable-mdpi/ic_download_misc_file_type.png
+++ /dev/null
Binary files differ
diff --git a/ui/res/drawable-mdpi/ic_launcher_drm_file.png b/ui/res/drawable-mdpi/ic_launcher_drm_file.png
deleted file mode 100644
index 57378b23..00000000
--- a/ui/res/drawable-mdpi/ic_launcher_drm_file.png
+++ /dev/null
Binary files differ
diff --git a/ui/res/layout/download_list.xml b/ui/res/layout/download_list.xml
deleted file mode 100644
index a0ff5ff2..00000000
--- a/ui/res/layout/download_list.xml
+++ /dev/null
@@ -1,71 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!--
-/*
-** Copyright 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.
-*/
--->
-<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:orientation="vertical"
- android:divider="?android:attr/dividerHorizontal"
- android:showDividers="middle"
- android:dividerPadding="16dip">
-
- <!-- The main area showing the list of downloads -->
- <FrameLayout android:layout_width="match_parent"
- android:layout_height="0dip"
- android:layout_weight="1">
-
- <ExpandableListView android:id="@+id/date_ordered_list"
- android:paddingStart="16dip"
- android:paddingEnd="16dip"
- android:paddingBottom="16dip"
- android:clipToPadding="false"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:scrollbarStyle="outsideOverlay" />
- <ListView android:id="@+id/size_ordered_list"
- android:paddingStart="16dip"
- android:paddingEnd="16dip"
- android:paddingBottom="16dip"
- android:clipToPadding="false"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:scrollbarStyle="outsideOverlay" />
- <TextView xmlns:android="http://schemas.android.com/apk/res/android"
- android:id="@+id/empty"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:text="@string/no_downloads"
- android:gravity="center"
- android:textStyle="bold"/>
- </FrameLayout>
-
- <!-- The selection menu that pops up from the bottom of the screen -->
- <LinearLayout android:id="@+id/sort_menu"
- android:orientation="horizontal"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_gravity="center"
- style="?android:attr/buttonBarStyle">
-
- <Button android:id="@+id/sort_button"
- style="?android:attr/buttonBarButtonStyle"
- android:layout_width="0dip"
- android:layout_weight="1"
- android:layout_height="match_parent"/>
- </LinearLayout>
-</LinearLayout>
diff --git a/ui/res/layout/download_list_item.xml b/ui/res/layout/download_list_item.xml
deleted file mode 100644
index 2435ba7f..00000000
--- a/ui/res/layout/download_list_item.xml
+++ /dev/null
@@ -1,85 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!--
-/*
-** Copyright 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.
-*/
--->
-
-<com.android.providers.downloads.ui.DownloadItem
- xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:minHeight="?android:attr/listPreferredItemHeight"
- android:paddingStart="?android:attr/listPreferredItemPaddingStart"
- android:paddingEnd="?android:attr/listPreferredItemPaddingEnd"
- android:paddingTop="8dip"
- android:paddingBottom="8dip"
- android:columnCount="4"
- android:descendantFocusability="blocksDescendants">
-
- <!-- Clicks are handled directly by DownloadItem -->
- <CheckBox
- android:id="@+id/download_checkbox"
- android:layout_rowSpan="3"
- android:layout_gravity="center_vertical"
- android:clickable="false" />
-
- <ImageView
- android:id="@+id/download_icon"
- android:layout_width="@android:dimen/app_icon_size"
- android:layout_height="@android:dimen/app_icon_size"
- android:layout_rowSpan="3"
- android:layout_marginEnd="8dip"
- android:layout_gravity="center_vertical"
- android:scaleType="centerInside"
- android:contentDescription="@null" />
-
- <TextView
- android:id="@+id/download_title"
- android:layout_width="0dip"
- android:layout_columnSpan="2"
- android:layout_gravity="fill_horizontal"
- android:singleLine="true"
- android:ellipsize="marquee"
- android:textStyle="bold"
- android:textAppearance="?android:attr/textAppearance"
- android:textAlignment="viewStart" />
-
- <TextView
- android:id="@+id/domain"
- android:layout_width="0dip"
- android:layout_columnSpan="2"
- android:layout_gravity="fill_horizontal"
- android:singleLine="true"
- android:ellipsize="marquee"
- android:textAppearance="?android:attr/textAppearanceSmall"
- android:textAlignment="viewStart" />
-
- <TextView
- android:id="@+id/size_text"
- android:layout_width="0dip"
- android:layout_gravity="fill_horizontal"
- android:singleLine="true"
- android:ellipsize="marquee"
- android:textAppearance="?android:attr/textAppearanceSmall"
- android:textAlignment="viewStart" />
-
- <TextView
- android:id="@+id/status_text"
- android:layout_marginStart="8dip"
- android:textAppearance="?android:attr/textAppearanceSmall"
- android:textAlignment="viewStart" />
-
-</com.android.providers.downloads.ui.DownloadItem>
diff --git a/ui/res/layout/list_group_header.xml b/ui/res/layout/list_group_header.xml
deleted file mode 100644
index 466cd6c6..00000000
--- a/ui/res/layout/list_group_header.xml
+++ /dev/null
@@ -1,23 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!-- 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.
--->
-
-<TextView xmlns:android="http://schemas.android.com/apk/res/android"
- android:id="@android:id/text1"
- android:layout_width="match_parent"
- android:layout_height="?android:attr/listPreferredItemHeight"
- android:paddingStart="?android:attr/expandableListPreferredItemPaddingLeft"
- android:textAppearance="?android:attr/textAppearanceMedium"
- android:gravity="center_vertical" />
diff --git a/ui/res/menu/download_menu.xml b/ui/res/menu/download_menu.xml
deleted file mode 100644
index a33dd52b..00000000
--- a/ui/res/menu/download_menu.xml
+++ /dev/null
@@ -1,27 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!-- Copyright (C) 2008 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.
--->
-
-<menu xmlns:android="http://schemas.android.com/apk/res/android">
- <item android:id="@+id/share_download"
- android:icon="@android:drawable/ic_menu_share"
- android:title="@string/download_share_dialog"
- android:showAsAction="always" />
-
- <item android:id="@+id/delete_download"
- android:icon="@android:drawable/ic_menu_delete"
- android:title="@string/delete_download"
- android:showAsAction="always" />
-</menu>
diff --git a/ui/res/values/dimen.xml b/ui/res/values/dimen.xml
deleted file mode 100644
index 7519b878..00000000
--- a/ui/res/values/dimen.xml
+++ /dev/null
@@ -1,19 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!-- 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.
--->
-
-<resources>
- <dimen name="checkmark_area">48dip</dimen>
-</resources>
diff --git a/ui/src/com/android/providers/downloads/ui/DateSortedDownloadAdapter.java b/ui/src/com/android/providers/downloads/ui/DateSortedDownloadAdapter.java
deleted file mode 100644
index b69fb8b8..00000000
--- a/ui/src/com/android/providers/downloads/ui/DateSortedDownloadAdapter.java
+++ /dev/null
@@ -1,60 +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.providers.downloads.ui;
-
-import android.app.DownloadManager;
-import android.database.Cursor;
-import android.view.View;
-import android.view.ViewGroup;
-import android.widget.ExpandableListView;
-import android.widget.RelativeLayout;
-
-/**
- * Adapter for a date-sorted list of downloads. Delegates all the real work to
- * {@link DownloadAdapter}.
- */
-public class DateSortedDownloadAdapter extends DateSortedExpandableListAdapter {
- private final DownloadAdapter mDelegate;
- private final DownloadList mDownloadList;
-
- public DateSortedDownloadAdapter(DownloadList downloadList, Cursor cursor) {
- super(downloadList, cursor,
- cursor.getColumnIndexOrThrow(DownloadManager.COLUMN_LAST_MODIFIED_TIMESTAMP));
- mDelegate = new DownloadAdapter(downloadList, cursor);
- mDownloadList = downloadList;
- }
-
- @Override
- public View getChildView(int groupPosition, int childPosition,
- boolean isLastChild, View convertView, ViewGroup parent) {
- // The layout file uses a RelativeLayout, whereas the GroupViews use TextView.
- if (null == convertView || !(convertView instanceof RelativeLayout)) {
- convertView = mDelegate.newView();
- }
-
- // Bail early if the Cursor is closed.
- if (!moveCursorToChildPosition(groupPosition, childPosition)) {
- return convertView;
- }
-
- int pos = mDownloadList.getExpandableListView().getFlatListPosition(
- ExpandableListView.getPackedPositionForChild(groupPosition, childPosition));
- mDelegate.bindView(convertView, pos);
- return convertView;
- }
-}
diff --git a/ui/src/com/android/providers/downloads/ui/DateSortedExpandableListAdapter.java b/ui/src/com/android/providers/downloads/ui/DateSortedExpandableListAdapter.java
deleted file mode 100644
index f5d70770..00000000
--- a/ui/src/com/android/providers/downloads/ui/DateSortedExpandableListAdapter.java
+++ /dev/null
@@ -1,354 +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.providers.downloads.ui;
-
-import android.app.DownloadManager;
-import android.content.Context;
-import android.database.ContentObserver;
-import android.database.Cursor;
-import android.database.DataSetObserver;
-import android.os.Handler;
-import android.view.LayoutInflater;
-import android.view.View;
-import android.view.ViewGroup;
-import android.webkit.DateSorter;
-import android.widget.ExpandableListAdapter;
-import android.widget.ExpandableListView;
-import android.widget.TextView;
-
-import java.util.Vector;
-
-/**
- * ExpandableListAdapter which separates data into categories based on date. Copied from
- * packages/apps/Browser.
- */
-public class DateSortedExpandableListAdapter implements ExpandableListAdapter {
- // Array for each of our bins. Each entry represents how many items are
- // in that bin.
- private int mItemMap[];
- // This is our GroupCount. We will have at most DateSorter.DAY_COUNT
- // bins, less if the user has no items in one or more bins.
- private int mNumberOfBins;
- private Vector<DataSetObserver> mObservers;
- private Cursor mCursor;
- private DateSorter mDateSorter;
- private int mDateIndex;
- private int mIdIndex;
- private Context mContext;
-
- private class ChangeObserver extends ContentObserver {
- public ChangeObserver() {
- super(new Handler());
- }
-
- @Override
- public boolean deliverSelfNotifications() {
- return true;
- }
-
- @Override
- public void onChange(boolean selfChange) {
- refreshData();
- }
- }
-
- private class MyDataSetObserver extends DataSetObserver {
- @Override
- public void onChanged() {
- buildMap();
- for (DataSetObserver o : mObservers) {
- o.onChanged();
- }
- }
- }
-
- public DateSortedExpandableListAdapter(Context context, Cursor cursor,
- int dateIndex) {
- mContext = context;
- mDateSorter = new DateSorter(context);
- mObservers = new Vector<DataSetObserver>();
- mCursor = cursor;
- mIdIndex = cursor.getColumnIndexOrThrow(DownloadManager.COLUMN_ID);
- cursor.registerContentObserver(new ChangeObserver());
- cursor.registerDataSetObserver(new MyDataSetObserver());
- mDateIndex = dateIndex;
- buildMap();
- }
-
- /**
- * Set up the bins for determining which items belong to which groups.
- */
- private void buildMap() {
- // The cursor is sorted by date
- // The ItemMap will store the number of items in each bin.
- int array[] = new int[DateSorter.DAY_COUNT];
- // Zero out the array.
- for (int j = 0; j < DateSorter.DAY_COUNT; j++) {
- array[j] = 0;
- }
- mNumberOfBins = 0;
- int dateIndex = -1;
- if (mCursor.moveToFirst() && mCursor.getCount() > 0) {
- while (!mCursor.isAfterLast()) {
- long date = getLong(mDateIndex);
- int index = mDateSorter.getIndex(date);
- if (index > dateIndex) {
- mNumberOfBins++;
- if (index == DateSorter.DAY_COUNT - 1) {
- // We are already in the last bin, so it will
- // include all the remaining items
- array[index] = mCursor.getCount()
- - mCursor.getPosition();
- break;
- }
- dateIndex = index;
- }
- array[dateIndex]++;
- mCursor.moveToNext();
- }
- }
- mItemMap = array;
- }
-
- /**
- * Get the byte array at cursorIndex from the Cursor. Assumes the Cursor
- * has already been moved to the correct position. Along with
- * {@link #getInt} and {@link #getString}, these are provided so the client
- * does not need to access the Cursor directly
- * @param cursorIndex Index to query the Cursor.
- * @return corresponding byte array from the Cursor.
- */
- /* package */ byte[] getBlob(int cursorIndex) {
- return mCursor.getBlob(cursorIndex);
- }
-
- /* package */ Context getContext() {
- return mContext;
- }
-
- /**
- * Get the integer at cursorIndex from the Cursor. Assumes the Cursor has
- * already been moved to the correct position. Along with
- * {@link #getBlob} and {@link #getString}, these are provided so the client
- * does not need to access the Cursor directly
- * @param cursorIndex Index to query the Cursor.
- * @return corresponding integer from the Cursor.
- */
- /* package */ int getInt(int cursorIndex) {
- return mCursor.getInt(cursorIndex);
- }
-
- /**
- * Get the long at cursorIndex from the Cursor. Assumes the Cursor has
- * already been moved to the correct position.
- */
- /* package */ long getLong(int cursorIndex) {
- return mCursor.getLong(cursorIndex);
- }
-
- /**
- * Get the String at cursorIndex from the Cursor. Assumes the Cursor has
- * already been moved to the correct position. Along with
- * {@link #getInt} and {@link #getInt}, these are provided so the client
- * does not need to access the Cursor directly
- * @param cursorIndex Index to query the Cursor.
- * @return corresponding String from the Cursor.
- */
- /* package */ String getString(int cursorIndex) {
- return mCursor.getString(cursorIndex);
- }
-
- /**
- * Determine which group an item belongs to.
- * @param childId ID of the child view in question.
- * @return int Group position of the containing group.
- /* package */ int groupFromChildId(long childId) {
- int group = -1;
- for (mCursor.moveToFirst(); !mCursor.isAfterLast();
- mCursor.moveToNext()) {
- if (getLong(mIdIndex) == childId) {
- int bin = mDateSorter.getIndex(getLong(mDateIndex));
- // bin is the same as the group if the number of bins is the
- // same as DateSorter
- if (DateSorter.DAY_COUNT == mNumberOfBins) return bin;
- // There are some empty bins. Find the corresponding group.
- group = 0;
- for (int i = 0; i < bin; i++) {
- if (mItemMap[i] != 0) group++;
- }
- break;
- }
- }
- return group;
- }
-
- /**
- * Translates from a group position in the ExpandableList to a bin. This is
- * necessary because some groups have no history items, so we do not include
- * those in the ExpandableList.
- * @param groupPosition Position in the ExpandableList's set of groups
- * @return The corresponding bin that holds that group.
- */
- private int groupPositionToBin(int groupPosition) {
- if (groupPosition < 0 || groupPosition >= DateSorter.DAY_COUNT) {
- throw new AssertionError("group position out of range");
- }
- if (DateSorter.DAY_COUNT == mNumberOfBins || 0 == mNumberOfBins) {
- // In the first case, we have exactly the same number of bins
- // as our maximum possible, so there is no need to do a
- // conversion
- // The second statement is in case this method gets called when
- // the array is empty, in which case the provided groupPosition
- // will do fine.
- return groupPosition;
- }
- int arrayPosition = -1;
- while (groupPosition > -1) {
- arrayPosition++;
- if (mItemMap[arrayPosition] != 0) {
- groupPosition--;
- }
- }
- return arrayPosition;
- }
-
- /**
- * Move the cursor to the position indicated.
- * @param packedPosition Position in packed position representation.
- * @return True on success, false otherwise.
- */
- boolean moveCursorToPackedChildPosition(long packedPosition) {
- if (ExpandableListView.getPackedPositionType(packedPosition) !=
- ExpandableListView.PACKED_POSITION_TYPE_CHILD) {
- return false;
- }
- int groupPosition = ExpandableListView.getPackedPositionGroup(
- packedPosition);
- int childPosition = ExpandableListView.getPackedPositionChild(
- packedPosition);
- return moveCursorToChildPosition(groupPosition, childPosition);
- }
-
- /**
- * Move the cursor the the position indicated.
- * @param groupPosition Index of the group containing the desired item.
- * @param childPosition Index of the item within the specified group.
- * @return boolean False if the cursor is closed, so the Cursor was not
- * moved. True on success.
- */
- /* package */ boolean moveCursorToChildPosition(int groupPosition,
- int childPosition) {
- if (mCursor.isClosed()) return false;
- groupPosition = groupPositionToBin(groupPosition);
- int index = childPosition;
- for (int i = 0; i < groupPosition; i++) {
- index += mItemMap[i];
- }
- return mCursor.moveToPosition(index);
- }
-
- /* package */ void refreshData() {
- if (mCursor.isClosed()) {
- return;
- }
- mCursor.requery();
- }
-
- public View getGroupView(int groupPosition, boolean isExpanded,
- View convertView, ViewGroup parent) {
- TextView item;
- if (null == convertView || !(convertView instanceof TextView)) {
- LayoutInflater factory = LayoutInflater.from(mContext);
- item = (TextView) factory.inflate(R.layout.list_group_header, parent, false);
- } else {
- item = (TextView) convertView;
- }
- String label = mDateSorter.getLabel(groupPositionToBin(groupPosition));
- item.setText(label);
- return item;
- }
-
- public View getChildView(int groupPosition, int childPosition,
- boolean isLastChild, View convertView, ViewGroup parent) {
- return null;
- }
-
- public boolean areAllItemsEnabled() {
- return true;
- }
-
- public boolean isChildSelectable(int groupPosition, int childPosition) {
- return true;
- }
-
- public int getGroupCount() {
- return mNumberOfBins;
- }
-
- public int getChildrenCount(int groupPosition) {
- return mItemMap[groupPositionToBin(groupPosition)];
- }
-
- public Object getGroup(int groupPosition) {
- return null;
- }
-
- public Object getChild(int groupPosition, int childPosition) {
- return null;
- }
-
- public long getGroupId(int groupPosition) {
- return groupPosition;
- }
-
- public long getChildId(int groupPosition, int childPosition) {
- if (moveCursorToChildPosition(groupPosition, childPosition)) {
- return getLong(mIdIndex);
- }
- return 0;
- }
-
- public boolean hasStableIds() {
- return true;
- }
-
- public void registerDataSetObserver(DataSetObserver observer) {
- mObservers.add(observer);
- }
-
- public void unregisterDataSetObserver(DataSetObserver observer) {
- mObservers.remove(observer);
- }
-
- public void onGroupExpanded(int groupPosition) {
- }
-
- public void onGroupCollapsed(int groupPosition) {
- }
-
- public long getCombinedChildId(long groupId, long childId) {
- return childId;
- }
-
- public long getCombinedGroupId(long groupId) {
- return groupId;
- }
-
- public boolean isEmpty() {
- return mCursor.isClosed() || mCursor.getCount() == 0;
- }
-}
diff --git a/ui/src/com/android/providers/downloads/ui/DownloadAdapter.java b/ui/src/com/android/providers/downloads/ui/DownloadAdapter.java
deleted file mode 100644
index 9ce2a986..00000000
--- a/ui/src/com/android/providers/downloads/ui/DownloadAdapter.java
+++ /dev/null
@@ -1,215 +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.providers.downloads.ui;
-
-import android.app.DownloadManager;
-import android.content.Context;
-import android.content.Intent;
-import android.content.pm.PackageManager;
-import android.content.pm.ResolveInfo;
-import android.content.res.Resources;
-import android.database.Cursor;
-import android.graphics.drawable.Drawable;
-import android.net.Uri;
-import android.text.format.Formatter;
-import android.view.LayoutInflater;
-import android.view.View;
-import android.view.ViewGroup;
-import android.widget.CursorAdapter;
-import android.widget.ImageView;
-import android.widget.TextView;
-
-import java.text.DateFormat;
-import java.util.Calendar;
-import java.util.Date;
-import java.util.GregorianCalendar;
-import java.util.List;
-
-/**
- * List adapter for Cursors returned by {@link DownloadManager}.
- */
-public class DownloadAdapter extends CursorAdapter {
- private final DownloadList mDownloadList;
- private Cursor mCursor;
- private Resources mResources;
- private DateFormat mDateFormat;
- private DateFormat mTimeFormat;
-
- private final int mTitleColumnId;
- private final int mDescriptionColumnId;
- private final int mStatusColumnId;
- private final int mReasonColumnId;
- private final int mTotalBytesColumnId;
- private final int mMediaTypeColumnId;
- private final int mDateColumnId;
- private final int mIdColumnId;
- private final int mFileNameColumnId;
-
- public DownloadAdapter(DownloadList downloadList, Cursor cursor) {
- super(downloadList, cursor);
- mDownloadList = downloadList;
- mCursor = cursor;
- mResources = mDownloadList.getResources();
- mDateFormat = DateFormat.getDateInstance(DateFormat.SHORT);
- mTimeFormat = DateFormat.getTimeInstance(DateFormat.SHORT);
-
- mIdColumnId = cursor.getColumnIndexOrThrow(DownloadManager.COLUMN_ID);
- mTitleColumnId = cursor.getColumnIndexOrThrow(DownloadManager.COLUMN_TITLE);
- mDescriptionColumnId = cursor.getColumnIndexOrThrow(DownloadManager.COLUMN_DESCRIPTION);
- mStatusColumnId = cursor.getColumnIndexOrThrow(DownloadManager.COLUMN_STATUS);
- mReasonColumnId = cursor.getColumnIndexOrThrow(DownloadManager.COLUMN_REASON);
- mTotalBytesColumnId = cursor.getColumnIndexOrThrow(DownloadManager.COLUMN_TOTAL_SIZE_BYTES);
- mMediaTypeColumnId = cursor.getColumnIndexOrThrow(DownloadManager.COLUMN_MEDIA_TYPE);
- mDateColumnId =
- cursor.getColumnIndexOrThrow(DownloadManager.COLUMN_LAST_MODIFIED_TIMESTAMP);
- mFileNameColumnId =
- cursor.getColumnIndexOrThrow(DownloadManager.COLUMN_LOCAL_FILENAME);
- }
-
- public View newView() {
- final DownloadItem view = (DownloadItem) LayoutInflater.from(mDownloadList)
- .inflate(R.layout.download_list_item, null);
- view.setDownloadListObj(mDownloadList);
- return view;
- }
-
- public void bindView(View convertView, int position) {
- if (!(convertView instanceof DownloadItem)) {
- return;
- }
-
- long downloadId = mCursor.getLong(mIdColumnId);
- ((DownloadItem) convertView).setData(downloadId, position,
- mCursor.getString(mFileNameColumnId),
- mCursor.getString(mMediaTypeColumnId));
-
- // Retrieve the icon for this download
- retrieveAndSetIcon(convertView);
-
- String title = mCursor.getString(mTitleColumnId);
- if (title.isEmpty()) {
- title = mResources.getString(R.string.missing_title);
- }
- setTextForView(convertView, R.id.download_title, title);
- setTextForView(convertView, R.id.domain, mCursor.getString(mDescriptionColumnId));
- setTextForView(convertView, R.id.size_text, getSizeText());
-
- final int status = mCursor.getInt(mStatusColumnId);
- final CharSequence statusText;
- if (status == DownloadManager.STATUS_SUCCESSFUL) {
- statusText = getDateString();
- } else {
- statusText = mResources.getString(getStatusStringId(status));
- }
- setTextForView(convertView, R.id.status_text, statusText);
-
- ((DownloadItem) convertView).getCheckBox()
- .setChecked(mDownloadList.isDownloadSelected(downloadId));
- }
-
- private String getDateString() {
- Date date = new Date(mCursor.getLong(mDateColumnId));
- if (date.before(getStartOfToday())) {
- return mDateFormat.format(date);
- } else {
- return mTimeFormat.format(date);
- }
- }
-
- private Date getStartOfToday() {
- Calendar today = new GregorianCalendar();
- today.set(Calendar.HOUR_OF_DAY, 0);
- today.set(Calendar.MINUTE, 0);
- today.set(Calendar.SECOND, 0);
- today.set(Calendar.MILLISECOND, 0);
- return today.getTime();
- }
-
- private String getSizeText() {
- long totalBytes = mCursor.getLong(mTotalBytesColumnId);
- String sizeText = "";
- if (totalBytes >= 0) {
- sizeText = Formatter.formatFileSize(mContext, totalBytes);
- }
- return sizeText;
- }
-
- private int getStatusStringId(int status) {
- switch (status) {
- case DownloadManager.STATUS_FAILED:
- return R.string.download_error;
-
- case DownloadManager.STATUS_SUCCESSFUL:
- return R.string.download_success;
-
- case DownloadManager.STATUS_PENDING:
- case DownloadManager.STATUS_RUNNING:
- return R.string.download_running;
-
- case DownloadManager.STATUS_PAUSED:
- final int reason = mCursor.getInt(mReasonColumnId);
- switch (reason) {
- case DownloadManager.PAUSED_QUEUED_FOR_WIFI:
- return R.string.download_queued;
- default:
- return R.string.download_running;
- }
- }
- throw new IllegalStateException("Unknown status: " + mCursor.getInt(mStatusColumnId));
- }
-
- private void retrieveAndSetIcon(View convertView) {
- String mediaType = mCursor.getString(mMediaTypeColumnId);
- ImageView iconView = (ImageView) convertView.findViewById(R.id.download_icon);
- iconView.setVisibility(View.INVISIBLE);
-
- if (mediaType == null) {
- return;
- }
-
- Intent intent = new Intent(Intent.ACTION_VIEW);
- intent.setDataAndType(Uri.fromParts("file", "", null), mediaType);
- PackageManager pm = mContext.getPackageManager();
- List<ResolveInfo> list = pm.queryIntentActivities(intent,
- PackageManager.MATCH_DEFAULT_ONLY);
- if (list.size() == 0) {
- // no icon found for this mediatype. use "unknown" icon
- iconView.setImageResource(R.drawable.ic_download_misc_file_type);
- } else {
- Drawable icon = list.get(0).activityInfo.loadIcon(pm);
- iconView.setImageDrawable(icon);
- }
- iconView.setVisibility(View.VISIBLE);
- }
-
- private void setTextForView(View parent, int textViewId, CharSequence text) {
- TextView view = (TextView) parent.findViewById(textViewId);
- view.setText(text);
- }
-
- // CursorAdapter overrides
-
- @Override
- public View newView(Context context, Cursor cursor, ViewGroup parent) {
- return newView();
- }
-
- @Override
- public void bindView(View view, Context context, Cursor cursor) {
- bindView(view, cursor.getPosition());
- }
-}
diff --git a/ui/src/com/android/providers/downloads/ui/DownloadItem.java b/ui/src/com/android/providers/downloads/ui/DownloadItem.java
deleted file mode 100644
index 0562cd05..00000000
--- a/ui/src/com/android/providers/downloads/ui/DownloadItem.java
+++ /dev/null
@@ -1,156 +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.providers.downloads.ui;
-
-import android.content.Context;
-import android.util.AttributeSet;
-import android.view.MotionEvent;
-import android.view.accessibility.AccessibilityEvent;
-import android.widget.CheckBox;
-import android.widget.Checkable;
-import android.widget.GridLayout;
-
-/**
- * This class customizes RelativeLayout to directly handle clicks on the left part of the view and
- * treat them at clicks on the checkbox. This makes rapid selection of many items easier. This class
- * also keeps an ID associated with the currently displayed download and notifies a listener upon
- * selection changes with that ID.
- */
-public class DownloadItem extends GridLayout implements Checkable {
- private static float CHECKMARK_AREA = -1;
-
- private boolean mIsInDownEvent = false;
- private CheckBox mCheckBox;
- private long mDownloadId;
- private String mFileName;
- private String mMimeType;
- private DownloadList mDownloadList;
- private int mPosition;
-
- public DownloadItem(Context context, AttributeSet attrs, int defStyle) {
- super(context, attrs, defStyle);
- initialize();
- }
-
- public DownloadItem(Context context, AttributeSet attrs) {
- super(context, attrs);
- initialize();
- }
-
- public DownloadItem(Context context) {
- super(context);
- initialize();
- }
-
- private void initialize() {
- if (CHECKMARK_AREA == -1) {
- CHECKMARK_AREA = getResources().getDimensionPixelSize(R.dimen.checkmark_area);
- }
- }
-
- @Override
- protected void onFinishInflate() {
- super.onFinishInflate();
- mCheckBox = (CheckBox) findViewById(R.id.download_checkbox);
- }
-
- public void setData(long downloadId, int position, String fileName, String mimeType) {
- mDownloadId = downloadId;
- mPosition = position;
- mFileName = fileName;
- mMimeType = mimeType;
- if (mDownloadList.isDownloadSelected(downloadId)) {
- setChecked(true);
- }
- }
-
- public void setDownloadListObj(DownloadList downloadList) {
- mDownloadList = downloadList;
- }
-
- private boolean inCheckArea(MotionEvent event) {
- if (isLayoutRtl()) {
- return event.getX() > getWidth() - CHECKMARK_AREA;
- } else {
- return event.getX() < CHECKMARK_AREA;
- }
- }
-
- @Override
- public boolean onTouchEvent(MotionEvent event) {
- boolean handled = false;
- switch(event.getAction()) {
- case MotionEvent.ACTION_DOWN:
- if (inCheckArea(event)) {
- mIsInDownEvent = true;
- handled = true;
- }
- break;
-
- case MotionEvent.ACTION_CANCEL:
- mIsInDownEvent = false;
- break;
-
- case MotionEvent.ACTION_UP:
- if (mIsInDownEvent && inCheckArea(event)) {
- toggle();
- sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_CLICKED);
- handled = true;
- }
- mIsInDownEvent = false;
- break;
- }
-
- if (handled) {
- postInvalidate();
- } else {
- handled = super.onTouchEvent(event);
- }
-
- return handled;
- }
-
- @Override
- public boolean isChecked() {
- return mCheckBox.isChecked();
- }
-
- @Override
- public void setChecked(boolean checked) {
- mCheckBox.setChecked(checked);
- mDownloadList.onDownloadSelectionChanged(mDownloadId, mCheckBox.isChecked(),
- mFileName, mMimeType);
- mDownloadList.getCurrentView().setItemChecked(mPosition, mCheckBox.isChecked());
- }
-
- @Override
- public void toggle() {
- setChecked(!isChecked());
- }
-
- public CheckBox getCheckBox() {
- return this.mCheckBox;
- }
-
- public String getFileName() {
- return mFileName;
- }
-
- public String getMimeType() {
- return mMimeType;
- }
-}
diff --git a/ui/src/com/android/providers/downloads/ui/DownloadList.java b/ui/src/com/android/providers/downloads/ui/DownloadList.java
index 107940c0..044bd4eb 100644
--- a/ui/src/com/android/providers/downloads/ui/DownloadList.java
+++ b/ui/src/com/android/providers/downloads/ui/DownloadList.java
@@ -17,134 +17,13 @@
package com.android.providers.downloads.ui;
import android.app.Activity;
-import android.app.AlertDialog;
-import android.app.DownloadManager;
-import android.content.ContentUris;
-import android.content.Context;
-import android.content.DialogInterface;
import android.content.Intent;
-import android.database.ContentObserver;
-import android.database.Cursor;
-import android.database.DataSetObserver;
-import android.net.Uri;
import android.os.Bundle;
-import android.os.Environment;
-import android.os.Handler;
-import android.os.Parcelable;
-import android.provider.BaseColumns;
import android.provider.DocumentsContract;
-import android.provider.Downloads;
-import android.util.Log;
-import android.util.SparseBooleanArray;
-import android.view.ActionMode;
-import android.view.Menu;
-import android.view.MenuInflater;
-import android.view.MenuItem;
-import android.view.View;
-import android.view.View.OnClickListener;
-import android.widget.AbsListView.MultiChoiceModeListener;
-import android.widget.AdapterView;
-import android.widget.AdapterView.OnItemClickListener;
-import android.widget.Button;
-import android.widget.ExpandableListView;
-import android.widget.ExpandableListView.OnChildClickListener;
-import android.widget.ListView;
-import android.widget.Toast;
import com.android.providers.downloads.Constants;
-import com.android.providers.downloads.OpenHelper;
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.Map;
-import java.util.Set;
-
-/**
- * View showing a list of all downloads the Download Manager knows about.
- */
public class DownloadList extends Activity {
- static final String LOG_TAG = "DownloadList";
-
- private ExpandableListView mDateOrderedListView;
- private ListView mSizeOrderedListView;
- private View mEmptyView;
-
- private DownloadManager mDownloadManager;
- private Cursor mDateSortedCursor;
- private DateSortedDownloadAdapter mDateSortedAdapter;
- private Cursor mSizeSortedCursor;
- private DownloadAdapter mSizeSortedAdapter;
- private ActionMode mActionMode;
- private MyContentObserver mContentObserver = new MyContentObserver();
- private MyDataSetObserver mDataSetObserver = new MyDataSetObserver();
-
- private int mStatusColumnId;
- private int mIdColumnId;
- private int mLocalUriColumnId;
- private int mMediaTypeColumnId;
- private int mReasonColumndId;
-
- // TODO this shouldn't be necessary
- private final Map<Long, SelectionObjAttrs> mSelectedIds =
- new HashMap<Long, SelectionObjAttrs>();
- private static class SelectionObjAttrs {
- private String mFileName;
- private String mMimeType;
- SelectionObjAttrs(String fileName, String mimeType) {
- mFileName = fileName;
- mMimeType = mimeType;
- }
- String getFileName() {
- return mFileName;
- }
- String getMimeType() {
- return mMimeType;
- }
- }
- private ListView mCurrentView;
- private Cursor mCurrentCursor;
- private boolean mCurrentViewIsExpandableListView = false;
- private boolean mIsSortedBySize = false;
-
- /**
- * We keep track of when a dialog is being displayed for a pending download, because if that
- * download starts running, we want to immediately hide the dialog.
- */
- private Long mQueuedDownloadId = null;
- private AlertDialog mQueuedDialog;
- String mSelectedCountFormat;
-
- private Button mSortOption;
-
- private class MyContentObserver extends ContentObserver {
- public MyContentObserver() {
- super(new Handler());
- }
-
- @Override
- public void onChange(boolean selfChange) {
- handleDownloadsChanged();
- }
- }
-
- private class MyDataSetObserver extends DataSetObserver {
- @Override
- public void onChanged() {
- // ignore change notification if there are selections
- if (mSelectedIds.size() > 0) {
- return;
- }
- // may need to switch to or from the empty view
- chooseListToShow();
- ensureSomeGroupIsExpanded();
- }
- }
-
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
@@ -156,648 +35,4 @@ public class DownloadList extends Activity {
startActivity(intent);
finish();
}
-
- public void onCreateLegacy(Bundle icicle) {
- super.onCreate(icicle);
- setFinishOnTouchOutside(true);
- setupViews();
-
- mDownloadManager = (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE);
- mDownloadManager.setAccessAllDownloads(true);
- DownloadManager.Query baseQuery = new DownloadManager.Query()
- .setOnlyIncludeVisibleInDownloadsUi(true);
- //TODO don't do both queries - do them as needed
- mDateSortedCursor = mDownloadManager.query(baseQuery);
- mSizeSortedCursor = mDownloadManager.query(baseQuery
- .orderBy(DownloadManager.COLUMN_TOTAL_SIZE_BYTES,
- DownloadManager.Query.ORDER_DESCENDING));
-
- // only attach everything to the listbox if we can access the download database. Otherwise,
- // just show it empty
- if (haveCursors()) {
- startManagingCursor(mDateSortedCursor);
- startManagingCursor(mSizeSortedCursor);
-
- mStatusColumnId =
- mDateSortedCursor.getColumnIndexOrThrow(DownloadManager.COLUMN_STATUS);
- mIdColumnId =
- mDateSortedCursor.getColumnIndexOrThrow(DownloadManager.COLUMN_ID);
- mLocalUriColumnId =
- mDateSortedCursor.getColumnIndexOrThrow(DownloadManager.COLUMN_LOCAL_URI);
- mMediaTypeColumnId =
- mDateSortedCursor.getColumnIndexOrThrow(DownloadManager.COLUMN_MEDIA_TYPE);
- mReasonColumndId =
- mDateSortedCursor.getColumnIndexOrThrow(DownloadManager.COLUMN_REASON);
-
- mDateSortedAdapter = new DateSortedDownloadAdapter(this, mDateSortedCursor);
- mDateOrderedListView.setAdapter(mDateSortedAdapter);
- mSizeSortedAdapter = new DownloadAdapter(this, mSizeSortedCursor);
- mSizeOrderedListView.setAdapter(mSizeSortedAdapter);
-
- ensureSomeGroupIsExpanded();
- }
-
- // did the caller want to display the data sorted by size?
- Bundle extras = getIntent().getExtras();
- if (extras != null &&
- extras.getBoolean(DownloadManager.INTENT_EXTRAS_SORT_BY_SIZE, false)) {
- mIsSortedBySize = true;
- }
- mSortOption = (Button) findViewById(R.id.sort_button);
- mSortOption.setOnClickListener(new OnClickListener() {
- @Override
- public void onClick(View v) {
- // flip the view
- mIsSortedBySize = !mIsSortedBySize;
- // clear all selections
- mSelectedIds.clear();
- chooseListToShow();
- }
- });
-
- chooseListToShow();
- mSelectedCountFormat = getString(R.string.selected_count);
- }
-
- /**
- * If no group is expanded in the date-sorted list, expand the first one.
- */
- private void ensureSomeGroupIsExpanded() {
- mDateOrderedListView.post(new Runnable() {
- public void run() {
- if (mDateSortedAdapter.getGroupCount() == 0) {
- return;
- }
- for (int group = 0; group < mDateSortedAdapter.getGroupCount(); group++) {
- if (mDateOrderedListView.isGroupExpanded(group)) {
- return;
- }
- }
- mDateOrderedListView.expandGroup(0);
- }
- });
- }
-
- private void setupViews() {
- setContentView(R.layout.download_list);
- ModeCallback modeCallback = new ModeCallback(this);
-
- //TODO don't create both views. create only the one needed.
- mDateOrderedListView = (ExpandableListView) findViewById(R.id.date_ordered_list);
- mDateOrderedListView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL);
- mDateOrderedListView.setMultiChoiceModeListener(modeCallback);
- mDateOrderedListView.setOnChildClickListener(new OnChildClickListener() {
- // called when a child is clicked on (this is NOT the checkbox click)
- @Override
- public boolean onChildClick(ExpandableListView parent, View v,
- int groupPosition, int childPosition, long id) {
- if (!(v instanceof DownloadItem)) {
- // can this even happen?
- return false;
- }
- if (mSelectedIds.size() > 0) {
- ((DownloadItem)v).setChecked(true);
- } else {
- mDateSortedAdapter.moveCursorToChildPosition(groupPosition, childPosition);
- handleItemClick(mDateSortedCursor);
- }
- return true;
- }
- });
- mSizeOrderedListView = (ListView) findViewById(R.id.size_ordered_list);
- mSizeOrderedListView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL);
- mSizeOrderedListView.setMultiChoiceModeListener(modeCallback);
- mSizeOrderedListView.setOnItemClickListener(new OnItemClickListener() {
- // handle a click from the size-sorted list. (this is NOT the checkbox click)
- @Override
- public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
- mSizeSortedCursor.moveToPosition(position);
- handleItemClick(mSizeSortedCursor);
- }
- });
- mEmptyView = findViewById(R.id.empty);
- }
-
- private static class ModeCallback implements MultiChoiceModeListener {
- private final DownloadList mDownloadList;
-
- public ModeCallback(DownloadList downloadList) {
- mDownloadList = downloadList;
- }
-
- @Override public void onDestroyActionMode(ActionMode mode) {
- mDownloadList.mSelectedIds.clear();
- mDownloadList.mActionMode = null;
- }
-
- @Override
- public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
- return true;
- }
-
- @Override
- public boolean onCreateActionMode(ActionMode mode, Menu menu) {
- if (mDownloadList.haveCursors()) {
- final MenuInflater inflater = mDownloadList.getMenuInflater();
- inflater.inflate(R.menu.download_menu, menu);
- }
- mDownloadList.mActionMode = mode;
- return true;
- }
-
- @Override
- public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
- if (mDownloadList.mSelectedIds.size() == 0) {
- // nothing selected.
- return true;
- }
- switch (item.getItemId()) {
- case R.id.delete_download:
- for (Long downloadId : mDownloadList.mSelectedIds.keySet()) {
- mDownloadList.deleteDownload(downloadId);
- }
- // uncheck all checked items
- ListView lv = mDownloadList.getCurrentView();
- SparseBooleanArray checkedPositionList = lv.getCheckedItemPositions();
- int checkedPositionListSize = checkedPositionList.size();
- ArrayList<DownloadItem> sharedFiles = null;
- for (int i = 0; i < checkedPositionListSize; i++) {
- int position = checkedPositionList.keyAt(i);
- if (checkedPositionList.get(position, false)) {
- lv.setItemChecked(position, false);
- onItemCheckedStateChanged(mode, position, 0, false);
- }
- }
- mDownloadList.mSelectedIds.clear();
- // update the subtitle
- onItemCheckedStateChanged(mode, 1, 0, false);
- break;
- case R.id.share_download:
- mDownloadList.shareDownloadedFiles();
- break;
- }
- return true;
- }
-
- @Override
- public void onItemCheckedStateChanged(ActionMode mode, int position, long id,
- boolean checked) {
- // ignore long clicks on groups
- if (mDownloadList.isCurrentViewExpandableListView()) {
- ExpandableListView ev = mDownloadList.getExpandableListView();
- long pos = ev.getExpandableListPosition(position);
- if (checked && (ExpandableListView.getPackedPositionType(pos) ==
- ExpandableListView.PACKED_POSITION_TYPE_GROUP)) {
- // ignore this click
- ev.setItemChecked(position, false);
- return;
- }
- }
- mDownloadList.setActionModeTitle(mode);
- }
- }
-
- void setActionModeTitle(ActionMode mode) {
- int numSelected = mSelectedIds.size();
- if (numSelected > 0) {
- mode.setTitle(String.format(mSelectedCountFormat, numSelected,
- mCurrentCursor.getCount()));
- } else {
- mode.setTitle("");
- }
- }
-
- private boolean haveCursors() {
- return mDateSortedCursor != null && mSizeSortedCursor != null;
- }
-
- @Override
- protected void onResume() {
- super.onResume();
- if (haveCursors()) {
- mDateSortedCursor.registerContentObserver(mContentObserver);
- mDateSortedCursor.registerDataSetObserver(mDataSetObserver);
- refresh();
- }
- }
-
- @Override
- protected void onPause() {
- super.onPause();
- if (haveCursors()) {
- mDateSortedCursor.unregisterContentObserver(mContentObserver);
- mDateSortedCursor.unregisterDataSetObserver(mDataSetObserver);
- }
- }
-
- private static final String BUNDLE_SAVED_DOWNLOAD_IDS = "download_ids";
- private static final String BUNDLE_SAVED_FILENAMES = "filenames";
- private static final String BUNDLE_SAVED_MIMETYPES = "mimetypes";
- @Override
- protected void onSaveInstanceState(Bundle outState) {
- super.onSaveInstanceState(outState);
- outState.putBoolean("isSortedBySize", mIsSortedBySize);
- int len = mSelectedIds.size();
- if (len == 0) {
- return;
- }
- long[] selectedIds = new long[len];
- String[] fileNames = new String[len];
- String[] mimeTypes = new String[len];
- int i = 0;
- for (long id : mSelectedIds.keySet()) {
- selectedIds[i] = id;
- SelectionObjAttrs obj = mSelectedIds.get(id);
- fileNames[i] = obj.getFileName();
- mimeTypes[i] = obj.getMimeType();
- i++;
- }
- outState.putLongArray(BUNDLE_SAVED_DOWNLOAD_IDS, selectedIds);
- outState.putStringArray(BUNDLE_SAVED_FILENAMES, fileNames);
- outState.putStringArray(BUNDLE_SAVED_MIMETYPES, mimeTypes);
- }
-
- @Override
- protected void onRestoreInstanceState(Bundle savedInstanceState) {
- super.onRestoreInstanceState(savedInstanceState);
- mIsSortedBySize = savedInstanceState.getBoolean("isSortedBySize");
- mSelectedIds.clear();
- long[] selectedIds = savedInstanceState.getLongArray(BUNDLE_SAVED_DOWNLOAD_IDS);
- String[] fileNames = savedInstanceState.getStringArray(BUNDLE_SAVED_FILENAMES);
- String[] mimeTypes = savedInstanceState.getStringArray(BUNDLE_SAVED_MIMETYPES);
- if (selectedIds != null && selectedIds.length > 0) {
- for (int i = 0; i < selectedIds.length; i++) {
- mSelectedIds.put(selectedIds[i], new SelectionObjAttrs(fileNames[i], mimeTypes[i]));
- }
- }
- chooseListToShow();
- }
-
- /**
- * Show the correct ListView and hide the other, or hide both and show the empty view.
- */
- private void chooseListToShow() {
- mDateOrderedListView.setVisibility(View.GONE);
- mSizeOrderedListView.setVisibility(View.GONE);
-
- if (mDateSortedCursor == null || mDateSortedCursor.getCount() == 0) {
- mEmptyView.setVisibility(View.VISIBLE);
- mSortOption.setVisibility(View.GONE);
- } else {
- mEmptyView.setVisibility(View.GONE);
- mSortOption.setVisibility(View.VISIBLE);
- ListView lv = activeListView();
- lv.setVisibility(View.VISIBLE);
- lv.invalidateViews(); // ensure checkboxes get updated
- }
- // restore the ActionMode title if there are selections
- if (mActionMode != null) {
- setActionModeTitle(mActionMode);
- }
- }
-
- ListView getCurrentView() {
- return mCurrentView;
- }
-
- ExpandableListView getExpandableListView() {
- return mDateOrderedListView;
- }
-
- boolean isCurrentViewExpandableListView() {
- return mCurrentViewIsExpandableListView;
- }
-
- private ListView activeListView() {
- if (mIsSortedBySize) {
- mCurrentCursor = mSizeSortedCursor;
- mCurrentView = mSizeOrderedListView;
- setTitle(R.string.download_title_sorted_by_size);
- mSortOption.setText(R.string.button_sort_by_date);
- mCurrentViewIsExpandableListView = false;
- } else {
- mCurrentCursor = mDateSortedCursor;
- mCurrentView = mDateOrderedListView;
- setTitle(R.string.download_title_sorted_by_date);
- mSortOption.setText(R.string.button_sort_by_size);
- mCurrentViewIsExpandableListView = true;
- }
- if (mActionMode != null) {
- mActionMode.finish();
- }
- return mCurrentView;
- }
-
- /**
- * @return an OnClickListener to delete the given downloadId from the Download Manager
- */
- private DialogInterface.OnClickListener getDeleteClickHandler(final long downloadId) {
- return new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int which) {
- deleteDownload(downloadId);
- }
- };
- }
-
- /**
- * @return an OnClickListener to restart the given downloadId in the Download Manager
- */
- private DialogInterface.OnClickListener getRestartClickHandler(final long downloadId) {
- return new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int which) {
- mDownloadManager.restartDownload(downloadId);
- }
- };
- }
-
- /**
- * Send an Intent to open the download currently pointed to by the given cursor.
- */
- private void openCurrentDownload(Cursor cursor) {
- final Uri localUri = Uri.parse(cursor.getString(mLocalUriColumnId));
- try {
- getContentResolver().openFileDescriptor(localUri, "r").close();
- } catch (FileNotFoundException exc) {
- Log.d(LOG_TAG, "Failed to open download " + cursor.getLong(mIdColumnId), exc);
- showFailedDialog(cursor.getLong(mIdColumnId),
- getString(R.string.dialog_file_missing_body));
- return;
- } catch (IOException exc) {
- // close() failed, not a problem
- }
-
- final long id = cursor.getLong(cursor.getColumnIndexOrThrow(BaseColumns._ID));
- if (!OpenHelper.startViewIntent(this, id, 0)) {
- Toast.makeText(this, R.string.download_no_application_title, Toast.LENGTH_SHORT).show();
- }
- }
-
- private void handleItemClick(Cursor cursor) {
- long id = cursor.getInt(mIdColumnId);
- switch (cursor.getInt(mStatusColumnId)) {
- case DownloadManager.STATUS_PENDING:
- case DownloadManager.STATUS_RUNNING:
- sendRunningDownloadClickedBroadcast(id);
- break;
-
- case DownloadManager.STATUS_PAUSED:
- if (isPausedForWifi(cursor)) {
- mQueuedDownloadId = id;
- mQueuedDialog = new AlertDialog.Builder(this)
- .setTitle(R.string.dialog_title_queued_body)
- .setMessage(R.string.dialog_queued_body)
- .setPositiveButton(R.string.keep_queued_download, null)
- .setNegativeButton(R.string.remove_download, getDeleteClickHandler(id))
- .setOnCancelListener(new DialogInterface.OnCancelListener() {
- /**
- * Called when a dialog for a pending download is canceled.
- */
- @Override
- public void onCancel(DialogInterface dialog) {
- mQueuedDownloadId = null;
- mQueuedDialog = null;
- }
- })
- .show();
- } else {
- sendRunningDownloadClickedBroadcast(id);
- }
- break;
-
- case DownloadManager.STATUS_SUCCESSFUL:
- openCurrentDownload(cursor);
- break;
-
- case DownloadManager.STATUS_FAILED:
- showFailedDialog(id, getErrorMessage(cursor));
- break;
- }
- }
-
- /**
- * @return the appropriate error message for the failed download pointed to by cursor
- */
- private String getErrorMessage(Cursor cursor) {
- switch (cursor.getInt(mReasonColumndId)) {
- case DownloadManager.ERROR_FILE_ALREADY_EXISTS:
- if (isOnExternalStorage(cursor)) {
- return getString(R.string.dialog_file_already_exists);
- } else {
- // the download manager should always find a free filename for cache downloads,
- // so this indicates a strange internal error
- return getUnknownErrorMessage();
- }
-
- case DownloadManager.ERROR_INSUFFICIENT_SPACE:
- if (isOnExternalStorage(cursor)) {
- return getString(R.string.dialog_insufficient_space_on_external);
- } else {
- return getString(R.string.dialog_insufficient_space_on_cache);
- }
-
- case DownloadManager.ERROR_DEVICE_NOT_FOUND:
- return getString(R.string.dialog_media_not_found);
-
- case DownloadManager.ERROR_CANNOT_RESUME:
- return getString(R.string.dialog_cannot_resume);
-
- default:
- return getUnknownErrorMessage();
- }
- }
-
- private boolean isOnExternalStorage(Cursor cursor) {
- String localUriString = cursor.getString(mLocalUriColumnId);
- if (localUriString == null) {
- return false;
- }
- Uri localUri = Uri.parse(localUriString);
- if (!localUri.getScheme().equals("file")) {
- return false;
- }
- String path = localUri.getPath();
- String externalRoot = Environment.getExternalStorageDirectory().getPath();
- return path.startsWith(externalRoot);
- }
-
- private String getUnknownErrorMessage() {
- return getString(R.string.dialog_failed_body);
- }
-
- private void showFailedDialog(long downloadId, String dialogBody) {
- new AlertDialog.Builder(this)
- .setTitle(R.string.dialog_title_not_available)
- .setMessage(dialogBody)
- .setNegativeButton(R.string.delete_download, getDeleteClickHandler(downloadId))
- .setPositiveButton(R.string.retry_download, getRestartClickHandler(downloadId))
- .show();
- }
-
- private void sendRunningDownloadClickedBroadcast(long id) {
- final Intent intent = new Intent(Constants.ACTION_LIST);
- intent.setPackage(Constants.PROVIDER_PACKAGE_NAME);
- intent.putExtra(DownloadManager.EXTRA_NOTIFICATION_CLICK_DOWNLOAD_IDS,
- new long[] { id });
- sendBroadcast(intent);
- }
-
- // handle a click on one of the download item checkboxes
- public void onDownloadSelectionChanged(long downloadId, boolean isSelected,
- String fileName, String mimeType) {
- if (isSelected) {
- mSelectedIds.put(downloadId, new SelectionObjAttrs(fileName, mimeType));
- } else {
- mSelectedIds.remove(downloadId);
- }
- }
-
- /**
- * Requery the database and update the UI.
- */
- private void refresh() {
- mDateSortedCursor.requery();
- mSizeSortedCursor.requery();
- // Adapters get notification of changes and update automatically
- }
-
- /**
- * Delete a download from the Download Manager.
- */
- private void deleteDownload(long downloadId) {
- // let DownloadService do the job of cleaning up the downloads db, mediaprovider db,
- // and removal of file from sdcard
- // TODO do the following in asynctask - not on main thread.
- mDownloadManager.markRowDeleted(downloadId);
- }
-
- public boolean isDownloadSelected(long id) {
- return mSelectedIds.containsKey(id);
- }
-
- /**
- * Called when there's a change to the downloads database.
- */
- void handleDownloadsChanged() {
- checkSelectionForDeletedEntries();
-
- if (mQueuedDownloadId != null && moveToDownload(mQueuedDownloadId)) {
- if (mDateSortedCursor.getInt(mStatusColumnId) != DownloadManager.STATUS_PAUSED
- || !isPausedForWifi(mDateSortedCursor)) {
- mQueuedDialog.cancel();
- }
- }
- }
-
- private boolean isPausedForWifi(Cursor cursor) {
- return cursor.getInt(mReasonColumndId) == DownloadManager.PAUSED_QUEUED_FOR_WIFI;
- }
-
- /**
- * Check if any of the selected downloads have been deleted from the downloads database, and
- * remove such downloads from the selection.
- */
- private void checkSelectionForDeletedEntries() {
- // gather all existing IDs...
- Set<Long> allIds = new HashSet<Long>();
- for (mDateSortedCursor.moveToFirst(); !mDateSortedCursor.isAfterLast();
- mDateSortedCursor.moveToNext()) {
- allIds.add(mDateSortedCursor.getLong(mIdColumnId));
- }
-
- // ...and check if any selected IDs are now missing
- for (Iterator<Long> iterator = mSelectedIds.keySet().iterator(); iterator.hasNext(); ) {
- if (!allIds.contains(iterator.next())) {
- iterator.remove();
- }
- }
- }
-
- /**
- * Move {@link #mDateSortedCursor} to the download with the given ID.
- * @return true if the specified download ID was found; false otherwise
- */
- private boolean moveToDownload(long downloadId) {
- for (mDateSortedCursor.moveToFirst(); !mDateSortedCursor.isAfterLast();
- mDateSortedCursor.moveToNext()) {
- if (mDateSortedCursor.getLong(mIdColumnId) == downloadId) {
- return true;
- }
- }
- return false;
- }
-
- /**
- * handle share menu button click when one more files are selected for sharing
- */
- public boolean shareDownloadedFiles() {
- Intent intent = new Intent();
- if (mSelectedIds.size() > 1) {
- intent.setAction(Intent.ACTION_SEND_MULTIPLE);
- ArrayList<Parcelable> attachments = new ArrayList<Parcelable>();
- ArrayList<String> mimeTypes = new ArrayList<String>();
- for (Map.Entry<Long, SelectionObjAttrs> item : mSelectedIds.entrySet()) {
- final Uri uri = ContentUris.withAppendedId(
- Downloads.Impl.ALL_DOWNLOADS_CONTENT_URI, item.getKey());
- final String mimeType = item.getValue().getMimeType();
- attachments.add(uri);
- if (mimeType != null) {
- mimeTypes.add(mimeType);
- }
- }
- intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, attachments);
- intent.setType(findCommonMimeType(mimeTypes));
- } else {
- // get the entry
- // since there is ONLY one entry in this, we can do the following
- for (Map.Entry<Long, SelectionObjAttrs> item : mSelectedIds.entrySet()) {
- final Uri uri = ContentUris.withAppendedId(
- Downloads.Impl.ALL_DOWNLOADS_CONTENT_URI, item.getKey());
- final String mimeType = item.getValue().getMimeType();
- intent.setAction(Intent.ACTION_SEND);
- intent.putExtra(Intent.EXTRA_STREAM, uri);
- intent.setType(mimeType);
- }
- }
- intent = Intent.createChooser(intent, getText(R.string.download_share_dialog));
- startActivity(intent);
- return true;
- }
-
- private String findCommonMimeType(ArrayList<String> mimeTypes) {
- // are all mimeypes the same?
- String str = findCommonString(mimeTypes);
- if (str != null) {
- return str;
- }
-
- // are all prefixes of the given mimetypes the same?
- ArrayList<String> mimeTypePrefixes = new ArrayList<String>();
- for (String s : mimeTypes) {
- if (s != null) {
- mimeTypePrefixes.add(s.substring(0, s.indexOf('/')));
- }
- }
- str = findCommonString(mimeTypePrefixes);
- if (str != null) {
- return str + "/*";
- }
-
- // return generic mimetype
- return "*/*";
- }
- private String findCommonString(Collection<String> set) {
- String str = null;
- boolean found = true;
- for (String s : set) {
- if (str == null) {
- str = s;
- } else if (!str.equals(s)) {
- found = false;
- break;
- }
- }
- return (found) ? str : null;
- }
}