diff options
author | Bobby Georgescu <georgescu@google.com> | 2013-03-04 11:44:49 -0800 |
---|---|---|
committer | Bobby Georgescu <georgescu@google.com> | 2013-03-05 17:37:31 -0800 |
commit | a73acc17eea200014edba9c9c6a40f1c632fa57d (patch) | |
tree | fa41c07495474614b29629d0a7b8f32cd000bd12 | |
parent | 63b33e8c7ebeeec2b520fb419d89ada712ad6604 (diff) | |
download | android_packages_apps_Gallery2-a73acc17eea200014edba9c9c6a40f1c632fa57d.tar.gz android_packages_apps_Gallery2-a73acc17eea200014edba9c9c6a40f1c632fa57d.tar.bz2 android_packages_apps_Gallery2-a73acc17eea200014edba9c9c6a40f1c632fa57d.zip |
Preliminary AlbumSet UI
Change-Id: Ie99bd2939bfcb47c80605cbb22b84b1064098e91
-rw-r--r-- | res/layout/album_set.xml | 26 | ||||
-rw-r--r-- | res/layout/album_set_item.xml | 40 | ||||
-rw-r--r-- | res/values/dimensions.xml | 6 | ||||
-rw-r--r-- | src/com/android/photos/AlbumSetFragment.java | 91 | ||||
-rw-r--r-- | src/com/android/photos/data/AlbumSetLoader.java | 51 | ||||
-rw-r--r-- | src/com/android/photos/drawables/AutoThumbnailDrawable.java | 4 |
6 files changed, 215 insertions, 3 deletions
diff --git a/res/layout/album_set.xml b/res/layout/album_set.xml new file mode 100644 index 000000000..5ff1d23ff --- /dev/null +++ b/res/layout/album_set.xml @@ -0,0 +1,26 @@ +<?xml version="1.0" encoding="utf-8"?> +<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" + android:layout_width="match_parent" + android:layout_height="match_parent" > + + <GridView + android:id="@id/android:list" + android:layout_width="match_parent" + android:layout_height="match_parent" + android:layout_weight="1" + android:numColumns="auto_fit" + android:columnWidth="@dimen/album_set_item_width" + android:stretchMode="columnWidth" + android:drawSelectorOnTop="true" + android:padding="10dp" + android:horizontalSpacing="10dp" + android:verticalSpacing="10dp" /> + + <TextView + android:id="@id/android:empty" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_gravity="center" + android:text="@string/empty_album" /> + +</FrameLayout>
\ No newline at end of file diff --git a/res/layout/album_set_item.xml b/res/layout/album_set_item.xml new file mode 100644 index 000000000..46084e938 --- /dev/null +++ b/res/layout/album_set_item.xml @@ -0,0 +1,40 @@ +<?xml version="1.0" encoding="utf-8"?> +<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" + android:layout_height="wrap_content" + android:layout_width="match_parent" + android:background="#FFF" > + + <TextView + android:id="@+id/album_set_item_title" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_alignParentLeft="true" + android:layout_alignParentTop="true" + android:layout_marginLeft="10dp" + android:layout_marginTop="10dp" + android:textAppearance="?android:attr/textAppearanceMedium" /> + + <TextView + android:id="@+id/album_set_item_date" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_alignLeft="@+id/album_set_item_title" + android:layout_below="@+id/album_set_item_title" + android:layout_marginBottom="10dp" + android:textAppearance="?android:attr/textAppearanceSmall" /> + + <ImageView + android:id="@+id/album_set_item_image" + android:layout_width="match_parent" + android:layout_height="@dimen/album_set_item_image_height" + android:layout_below="@+id/album_set_item_date" + android:scaleType="centerCrop" /> + + <ProgressBar + android:id="@+id/album_set_item_upload_progress" + style="?android:attr/progressBarStyleHorizontal" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:visibility="invisible" + android:layout_alignParentBottom="true" /> +</RelativeLayout>
\ No newline at end of file diff --git a/res/values/dimensions.xml b/res/values/dimensions.xml index dc9e8c300..ae506807a 100644 --- a/res/values/dimensions.xml +++ b/res/values/dimensions.xml @@ -19,7 +19,7 @@ <dimen name="stack_photo_width">160dp</dimen> <dimen name="stack_photo_height">120dp</dimen> - <!-- configuration for album set page --> + <!-- configuration for legacy album set page --> <integer name="albumset_rows_land">2</integer> <integer name="albumset_rows_port">3</integer> <dimen name="albumset_padding_top">7dp</dimen> @@ -50,4 +50,8 @@ <!-- configuration for filtershow UI --> <dimen name="thumbnail_size">96dip</dimen> <dimen name="thumbnail_margin">3dip</dimen> + + <!-- configuration for album set page --> + <dimen name="album_set_item_image_height">100dp</dimen> + <dimen name="album_set_item_width">160dp</dimen> </resources> diff --git a/src/com/android/photos/AlbumSetFragment.java b/src/com/android/photos/AlbumSetFragment.java index 2d348c248..6a9520a5e 100644 --- a/src/com/android/photos/AlbumSetFragment.java +++ b/src/com/android/photos/AlbumSetFragment.java @@ -17,8 +17,97 @@ package com.android.photos; import android.app.Fragment; +import android.content.Context; +import android.database.Cursor; +import android.graphics.drawable.Drawable; +import android.os.Bundle; +import android.text.format.DateFormat; +import android.view.LayoutInflater; +import android.view.View; +import android.view.View.OnClickListener; +import android.view.ViewGroup; +import android.widget.AdapterView; +import android.widget.AdapterView.OnItemClickListener; +import android.widget.CursorAdapter; +import android.widget.GridView; +import android.widget.ImageView; +import android.widget.ProgressBar; +import android.widget.TextView; +import android.widget.Toast; +import com.android.gallery3d.R; +import com.android.photos.data.AlbumSetLoader; +import com.android.photos.drawables.DataUriThumbnailDrawable; -public class AlbumSetFragment extends Fragment { +import java.util.Date; + +public class AlbumSetFragment extends Fragment implements OnItemClickListener { + private GridView mAlbumSetView; + private View mEmptyView; + private CursorAdapter mAdapter; + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) { + View root = inflater.inflate(R.layout.album_set, container, false); + mAlbumSetView = (GridView) root.findViewById(android.R.id.list); + mEmptyView = root.findViewById(android.R.id.empty); + mEmptyView.setVisibility(View.GONE); + mAdapter = new AlbumSetCursorAdapter(getActivity()); + mAlbumSetView.setAdapter(mAdapter); + mAlbumSetView.setOnItemClickListener(this); + mAdapter.swapCursor(AlbumSetLoader.MOCK); + return root; + } + + @Override + public void onItemClick(AdapterView<?> av, View v, int pos, long id) { + Cursor c = (Cursor) av.getItemAtPosition(pos); + int albumId = c.getInt(AlbumSetLoader.INDEX_ID); + // TODO launch an activity showing the photos in the album + Toast.makeText(v.getContext(), "Clicked " + albumId, Toast.LENGTH_SHORT).show(); + } + + private static class AlbumSetCursorAdapter extends CursorAdapter { + + private Date mDate = new Date(); // Used for converting timestamps for display + + public AlbumSetCursorAdapter(Context context) { + super(context, null, false); + } + + @Override + public void bindView(View v, Context context, Cursor cursor) { + TextView titleTextView = (TextView) v.findViewById( + R.id.album_set_item_title); + titleTextView.setText(cursor.getString(AlbumSetLoader.INDEX_TITLE)); + + TextView dateTextView = (TextView) v.findViewById( + R.id.album_set_item_date); + mDate.setTime(cursor.getLong(AlbumSetLoader.INDEX_TIMESTAMP)); + dateTextView.setText(DateFormat.getMediumDateFormat(context).format(mDate)); + + ProgressBar uploadProgressBar = (ProgressBar) v.findViewById( + R.id.album_set_item_upload_progress); + if (cursor.getInt(AlbumSetLoader.INDEX_COUNT_PENDING_UPLOAD) > 0) { + uploadProgressBar.setVisibility(View.VISIBLE); + uploadProgressBar.setProgress(50); + } else { + uploadProgressBar.setVisibility(View.INVISIBLE); + } + + // TODO show the thumbnail + } + + @Override + public View newView(Context context, Cursor cursor, ViewGroup parent) { + View v = LayoutInflater.from(context).inflate( + R.layout.album_set_item, parent, false); + ImageView thumbImageView = (ImageView) v.findViewById( + R.id.album_set_item_image); + thumbImageView.setImageResource(android.R.color.darker_gray); + return v; + } + } } diff --git a/src/com/android/photos/data/AlbumSetLoader.java b/src/com/android/photos/data/AlbumSetLoader.java new file mode 100644 index 000000000..f5fc3b732 --- /dev/null +++ b/src/com/android/photos/data/AlbumSetLoader.java @@ -0,0 +1,51 @@ +package com.android.photos.data; + +import android.database.MatrixCursor; + + +public class AlbumSetLoader { + public static final int INDEX_ID = 0; + public static final int INDEX_TITLE = 1; + public static final int INDEX_TIMESTAMP = 2; + public static final int INDEX_THUMBNAIL_URI = 3; + public static final int INDEX_THUMBNAIL_WIDTH = 4; + public static final int INDEX_THUMBNAIL_HEIGHT = 5; + public static final int INDEX_COUNT_PENDING_UPLOAD = 6; + public static final int INDEX_COUNT = 7; + + public static final MatrixCursor MOCK = createRandomCursor(30); + + private static MatrixCursor createRandomCursor(int count) { + String[] rows = { + "_id", + "title", + "timestamp", + "thumb_uri", + "thumb_width", + "thumb_height", + "count_pending_upload", + "_count" + }; + MatrixCursor c = new MatrixCursor(rows, count); + for (int i = 0; i < count; i++) { + c.addRow(createRandomRow()); + } + return c; + } + + private static Object[] createRandomRow() { + double random = Math.random(); + int id = (int) (500 * random); + Object[] row = { + id, + "Fun times " + id, + (long) (System.currentTimeMillis() * random), + null, + 0, + 0, + (random < .3 ? 1 : 0), + 1 + }; + return row; + } +}
\ No newline at end of file diff --git a/src/com/android/photos/drawables/AutoThumbnailDrawable.java b/src/com/android/photos/drawables/AutoThumbnailDrawable.java index 09b344147..b51b6709f 100644 --- a/src/com/android/photos/drawables/AutoThumbnailDrawable.java +++ b/src/com/android/photos/drawables/AutoThumbnailDrawable.java @@ -167,7 +167,9 @@ public abstract class AutoThumbnailDrawable<T> extends Drawable { } private void refreshSampleSizeLocked() { - if (mBounds.isEmpty()) return; + if (mBounds.isEmpty() || mImageWidth == 0 || mImageHeight == 0) { + return; + } int sampleSize = calculateSampleSizeLocked(mImageWidth, mImageHeight); if (sampleSize != mSampleSize || mBitmap == null) { |