編輯:關於Android編程
時光飛逝,從事Android系統開發已經兩年了,總想寫點什麼來安慰自己。思考了很久總是無法下筆,覺得沒什麼好寫的。現在終於決定寫一些符合大多數人需求的東西,想必使用過Android手機的人們一定對“圖庫”(以下簡稱Gallery)這個應用非常熟悉。在Android市場裡面有各種關於圖庫的應用,他們的最初原型其實就是Android系統原生“圖庫”,只是做了不同的差異化而已(UI差異化)。在研究Gallery源碼之前,我們需要對設計模式有一定的了解,根據自己對Gallery的了解,Gallery的設計就好比是一座設計精良的並且高效運轉的機器(32個攢)。毫不誇張地說,在Android市場裡,沒有一款“圖庫”應用的設計設計能夠和Gallery媲美。接下來的一段時間,就讓我們共同來揭開Gallery的神秘面紗。
在研究Gallery之前,我們還是來欣賞一下Gallery的整體效果,具體見圖1-1所示:
<喎?/kf/ware/vc/" target="_blank" class="keylink">vcD4KPHA+ICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIM28MS0xPC9wPgo8cD7K18/IztLDx8/IwLS/tNK7z8JHYWxsZXJ5tcS3otW5wPrKt6Os1NpBbmRyb2lkMi4z1q7HsEFuZHJvaWTPtc2ztcShsM28v+KhscP7zqpHYWxsZXJ5M0SjrNTaQW5kcm9pZDIuM9auuvPPtc2zvavWrsewtcRHYWxsZXJ5M0S4/LjEzqpHYWxsZXJ5MqOs0rvWsdHY08O1vcS/x7DX7tDCsOaxvqOoNC40o6mjrEdhbGxlcnky1NpVSbrNuabE3MnPw+bX9sHL1sq1xLfJ1L6jrMrHxL/HsEFuZHJvaWTUtMLr1tC3x7Oj08XQ47XExKO/6aOsttTT2kFuZHJvaWTTptPDv6q3otXfwLTLtcrHt8ezo7rDtcS/qtS0z+7Ev6OsxuTW0LXEyei8xtDCy7zP67rNyei8xsSjyr22vCYjMjA1NDA7tcPO0sPHvei8+KGjPC9wPgo8cD7P1tTau9i1vc7Sw8fR0L6/tcTW98ziLcr9vt2809TYo6zO0sPHz8jAtL+00rvPwkdhbGxlcnky1NrUtMLr1tC1xMK3vrYocGFja2FnZS9hcHAvR2FsbGVyeTIvKSzU2rjDwre+ts/CsPy6rMHLobDNvL/iobHKudPDtcTXytS0us3UtMLroaPO0sPH1NrJ6LzG0ru/7sjtvP61xMqxuvLK18/Iv7zCx7XEysfK/b7dtcS05rSius23w87Ko6zS8rTLztLDx9KysLTV1dXi0fm1xMnovMbLvMK3wLTMvb6/R2FsbGVyeTK1xMr9vt2809TYuf2zzKGjy7W1vdXitvnJ1M6izOHSu8/CztK31s721LTC67XEt73KvaOsv8nE3LTzvNK21EFuZHJvaWTUtMLrydTOotPQ0ru148HLveK1xM2s0afTprjD1qq1wKOsQW5kcm9pZNS0wuvKx7fHs6PF07TztcSjrNLytMvRodTxt9bO9rPM0PK1xMfQyOu147Tz1sK/ydLUt9bOqsG9wOCjurXa0rvW1srHsLTV1bLZs8zQ8rLZ1/eyvdbot9bO9tS0wuuhqqGqysrTw9PavefD5sz416rH5c76tcSzzNDyo7u12rb+1tbKx7j5vt208tOhtcRMb2fQxc+it9bO9rPM0PK1xNTL0NDC37ytoaqhqsrK08PT2ri01NO1xLLZ1/fC37ytoaM8L3A+CjxwPsrXz8jO0sPHz8jAtL+00rvPwkJ1Y2tldEhlbHBlci5qYXZhwOCjqC9zcmMvY29tL2FuZHJvaWQvZ2FsbGVyeTNkL2RhdGEvQnVja2V0SGVscGVyLmphdmGjqaOsuMPA4Nb30qrKx7i61PC2wcihTWVkaWFQcm92aWRlcsr9vt2/4tbQSW1hZ2W6zVZpZGVvyv2+3aOsvt/M5bT6wuvI58/Cy/nKvqO6PC9wPgo8cD48L3A+CjxwcmUgY2xhc3M9"brush:java;">package com.android.gallery3d.data;
import android.annotation.TargetApi;
import android.content.ContentResolver;
import android.database.Cursor;
import android.net.Uri;
import android.provider.MediaStore.Files;
import android.provider.MediaStore.Files.FileColumns;
import android.provider.MediaStore.Images;
import android.provider.MediaStore.Images.ImageColumns;
import android.provider.MediaStore.Video;
import android.util.Log;
import com.android.gallery3d.common.ApiHelper;
import com.android.gallery3d.common.Utils;
import com.android.gallery3d.util.ThreadPool.JobContext;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.HashMap;
class BucketHelper {
private static final String TAG = "BucketHelper";
private static final String EXTERNAL_MEDIA = "external";
// BUCKET_DISPLAY_NAME is a string like "Camera" which is the directory
// name of where an image or video is in. BUCKET_ID is a hash of the path
// name of that directory (see computeBucketValues() in MediaProvider for
// details). MEDIA_TYPE is video, image, audio, etc.
// BUCKET_DISPLAY_NAME字段為文件目錄名稱 BUCKET_ID字段為目錄路徑(path)的HASH值
// The "albums" are not explicitly recorded in the database, but each image
// or video has the two columns (BUCKET_ID, MEDIA_TYPE). We define an
// "album" to be the collection of images/videos which have the same value
// for the two columns.
// "專輯"的劃分方式為:當文件具有相同的目錄(BUCKET_ID)和多媒體類型(MEDIA_TYPE)即屬於同一專輯
// The goal of the query (used in loadSubMediaSetsFromFilesTable()) is to
// find all albums, that is, all unique values for (BUCKET_ID, MEDIA_TYPE).
// In the meantime sort them by the timestamp of the latest image/video in
// each of the album.
//
// The order of columns below is important: it must match to the index in
// MediaStore.
private static final String[] PROJECTION_BUCKET = {
ImageColumns.BUCKET_ID,
FileColumns.MEDIA_TYPE,
ImageColumns.BUCKET_DISPLAY_NAME};
// The indices should match the above projections.
private static final int INDEX_BUCKET_ID = 0;
private static final int INDEX_MEDIA_TYPE = 1;
private static final int INDEX_BUCKET_NAME = 2;
// We want to order the albums by reverse chronological order. We abuse the
// "WHERE" parameter to insert a "GROUP BY" clause into the SQL statement.
// The template for "WHERE" parameter is like:
// SELECT ... FROM ... WHERE (%s)
// and we make it look like:
// SELECT ... FROM ... WHERE (1) GROUP BY 1,(2)
// The "(1)" means true. The "1,(2)" means the first two columns specified
// after SELECT. Note that because there is a ")" in the template, we use
// "(2" to match it.
private static final String BUCKET_GROUP_BY = "1) GROUP BY 1,(2";
private static final String BUCKET_ORDER_BY = "MAX(datetaken) DESC";
// Before HoneyComb there is no Files table. Thus, we need to query the
// bucket info from the Images and Video tables and then merge them
// together.
//
// A bucket can exist in both tables. In this case, we need to find the
// latest timestamp from the two tables and sort ourselves. So we add the
// MAX(date_taken) to the projection and remove the media_type since we
// already know the media type from the table we query from.
private static final String[] PROJECTION_BUCKET_IN_ONE_TABLE = {
ImageColumns.BUCKET_ID,
"MAX(datetaken)",
ImageColumns.BUCKET_DISPLAY_NAME};
// We keep the INDEX_BUCKET_ID and INDEX_BUCKET_NAME the same as
// PROJECTION_BUCKET so we can reuse the values defined before.
private static final int INDEX_DATE_TAKEN = 1;
// When query from the Images or Video tables, we only need to group by BUCKET_ID.
private static final String BUCKET_GROUP_BY_IN_ONE_TABLE = "1) GROUP BY (1";
public static BucketEntry[] loadBucketEntries(
JobContext jc, ContentResolver resolver, int type) {
if (ApiHelper.HAS_MEDIA_PROVIDER_FILES_TABLE) {//當API1>= 11(即Android3.0版本之後)
return loadBucketEntriesFromFilesTable(jc, resolver, type);//獲取MediaScanner數據庫中多媒體文件(圖片和視頻)的目錄路徑和目錄名稱
} else {//Android3.0之前版本
return loadBucketEntriesFromImagesAndVideoTable(jc, resolver, type);
}
}
private static void updateBucketEntriesFromTable(JobContext jc,
ContentResolver resolver, Uri tableUri, HashMap 接下來我們再來看看BucketHelper類的調用關系的時序圖,具體如1-2所示: 到目前為止我們大致了解了Gallery數據加載的一個大體流程,接下來的文章將分析Album數據的讀取以及數據封裝。
1.我們之前已經用scrollView實現了輪播圖效果因為需要定時器,所以我們要cd到當前項目根目錄下安裝這個類庫:npm i react-timer-mixin --s
來這實習已經10多天了,今天整理整理學習時的Android筆記。正所謂好記性不如爛筆頭,今天來說說service組件。 service可以在和多
最近接了個項目其中有需要要實現此功能:seekbar需要顯示最左和最右值,進度要跟隨進度塊移動。下面通過此圖給大家展示下效果,可能比文字描述要更清晰。其實實現起來很簡單,
1.什麼是分支使用分支意味著你可以從開發主線上分離開來(即脫離主分支),然後在不影響主線的同時繼續工作。這種機制在多人開發過程中非常有用,每個人只需要創建一個屬於自己的分