下载管理界面学习

1、清单中的界面声明:

<activity android:name="com.android.providers.downloads.ui.DownloadList"
android:theme="@style/theme_for_activity"
android:launchMode="singleInstance"
android:label="@string/app_label"
android:icon="@drawable/ic_launcher_download"
android:configChanges="orientation|keyboardHidden|screenSize"
android:windowSoftInputMode="adjustPan">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
</intent-filter>

<intent-filter>
<action android:name="android.intent.action.VIEW_DOWNLOADS" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>

<meta-data android:name="oldComponentName"
android:resource="@array/downLoadListOldComponentName"/>
<meta-data android:name="oldComponentNameVersion"
android:value="1"/>

</activity>



2、有时候这个应用不会在桌面中显示图标,其他地方没有直接进入的改界面的入口,可以使用am命令来直接打开:

      $ adb shell
      $ am start -n {包(package)名}/{包名}.{活动(activity)名称}
 
启动下载管理界面:
adb shell am start -n com.android.providers.downloads/com.android.providers.downloads.ui.DownloadList
 
 
3、界面中对于文件的排序有两种方式:date 和 size。
即从数据库分别按照两种方式排序后,返回cursor:
DownloadManager.Query baseQuery = new DownloadManager.Query()
.setOnlyIncludeVisibleInDownloadsUi(true);
mDateSortedCursor = mDownloadManager.query(baseQuery);
mSizeSortedCursor = mDownloadManager.query(baseQuery
.orderBy(DownloadManager.COLUMN_TOTAL_SIZE_BYTES,
DownloadManager.Query.ORDER_DESCENDING));


这两种列表的排布布局也不同:
按照时间排序     ExpandableListView mDateOrderedListView;
按照文件大小排序 ListView mSizeOrderedListView;


注册监听数据库变化,更新界面:
mDateSortedCursor.registerContentObserver(mContentObserver);
mSizeSortedCursor.registerContentObserver(mContentObserver);
mDateSortedCursor.registerDataSetObserver(mDataSetObserver);


在更新界面时,由于有更具时间来排序,在下载的过程中各个文件可能会随时更改last_modification属性,造成排序跳动的结果,
此时可以在更新处增加条件显示,让其等到下载完成之后,在更新该属性。


4、各种点击和长按事件的处理
onContextItemSelected
handleItemClick


其实存粹看代码熟悉的程度是比较慢的, 因为在看的过程中精力会比较分散,面面俱到反而一事无成。也许给几个实际的问题来分析会更加有效果,寻找蛛丝马迹的过程会给大脑留下更深刻的映像。
原文地址:https://www.cnblogs.com/yangwubo/p/4992115.html