diff options
-rw-r--r-- | res/values/ids.xml | 19 | ||||
-rw-r--r-- | src/com/android/camera/Camera.java | 48 | ||||
-rw-r--r-- | src/com/android/camera/VideoCamera.java | 50 |
3 files changed, 85 insertions, 32 deletions
diff --git a/res/values/ids.xml b/res/values/ids.xml new file mode 100644 index 0000000..81d920f --- /dev/null +++ b/res/values/ids.xml @@ -0,0 +1,19 @@ +<?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> + <item type="id" name="btn_gallery" /> +</resources> diff --git a/src/com/android/camera/Camera.java b/src/com/android/camera/Camera.java index f7545d6..bc0ec88 100644 --- a/src/com/android/camera/Camera.java +++ b/src/com/android/camera/Camera.java @@ -79,10 +79,11 @@ import android.view.Window; import android.view.WindowManager; import android.view.MenuItem.OnMenuItemClickListener; import android.widget.AdapterView; +import android.widget.AdapterView.OnItemClickListener; +import android.widget.Button; import android.widget.CursorAdapter; import android.widget.FrameLayout; import android.widget.ListView; -import android.widget.AdapterView.OnItemClickListener; import java.io.File; import java.io.FileNotFoundException; @@ -177,6 +178,7 @@ public class Camera extends NoSearchActivity implements View.OnClickListener, private ListView mThumbnailList; private OnItemClickListener mThumbnailItemClickListener = new ThumbnailItemClickListener(); + private ThumbnailAdapter mThumbnailAdapter; // mCropValue and mSaveUri are used only if isImageCaptureIntent() is true. private String mCropValue; @@ -425,26 +427,37 @@ public class Camera extends NoSearchActivity implements View.OnClickListener, private void initThumbnailList() { mThumbnailList = (ListView) findViewById(R.id.thumbnail_list); - if (mThumbnailList != null) { - int width = mThumbnailList.getWidth(); - int height = mThumbnailList.getHeight(); - int thumbnailCount = (height + mThumbnailList.getDividerHeight()) - / (width + mThumbnailList.getDividerHeight()); - Cursor cursor = getThumbnailsCursor(thumbnailCount); - ThumbnailAdapter adapter = new ThumbnailAdapter( - getApplicationContext(), R.layout.thumbnail_item, cursor, - true); - mThumbnailList.setAdapter(adapter); - mThumbnailList.setOnItemClickListener(mThumbnailItemClickListener); + if (mThumbnailList == null) return; + + int width = mThumbnailList.getWidth(); + int height = mThumbnailList.getHeight(); + + // Add gallery button to header view. + if (mThumbnailList.getHeaderViewsCount() == 0) { + LayoutInflater inflater = getLayoutInflater(); + Button b = new Button(this); + ListView.LayoutParams params = new ListView.LayoutParams(width, width); + b.setId(R.id.btn_gallery); + b.setLayoutParams(params); + b.setOnClickListener(this); + b.setBackgroundResource(R.drawable.ic_menu_gallery); + mThumbnailList.addHeaderView(b); } + + // Set data adapter. + int thumbnailCount = (height + mThumbnailList.getDividerHeight()) + / (width + mThumbnailList.getDividerHeight()) - 1; + Cursor cursor = getThumbnailsCursor(thumbnailCount); + mThumbnailAdapter = new ThumbnailAdapter( + getApplicationContext(), R.layout.thumbnail_item, cursor, true); + mThumbnailList.setAdapter(mThumbnailAdapter); + mThumbnailList.setOnItemClickListener(mThumbnailItemClickListener); } private void updateThumbnailList() { if (mThumbnailList == null) return; - CursorAdapter adapter = (CursorAdapter) mThumbnailList.getAdapter(); - Cursor cursor = adapter.getCursor(); - cursor.requery(); - adapter.notifyDataSetChanged(); + mThumbnailAdapter.getCursor().requery(); + mThumbnailAdapter.notifyDataSetChanged(); } private Cursor getThumbnailsCursor(int thumbnailCount) { @@ -1234,6 +1247,9 @@ public class Camera extends NoSearchActivity implements View.OnClickListener, case R.id.btn_cancel: doCancel(); break; + case R.id.btn_gallery: + gotoGallery(); + break; } } diff --git a/src/com/android/camera/VideoCamera.java b/src/com/android/camera/VideoCamera.java index 65b4103..b3a9721 100644 --- a/src/com/android/camera/VideoCamera.java +++ b/src/com/android/camera/VideoCamera.java @@ -73,6 +73,7 @@ import android.view.animation.AlphaAnimation; import android.view.animation.Animation; import android.widget.AdapterView; import android.widget.AdapterView.OnItemClickListener; +import android.widget.Button; import android.widget.CursorAdapter; import android.widget.FrameLayout; import android.widget.ImageView; @@ -152,7 +153,9 @@ public class VideoCamera extends NoSearchActivity // last captured pictures. private ListView mThumbnailList; private OnItemClickListener mThumbnailItemClickListener = - new ThumbnailItemClickListener(); + new ThumbnailItemClickListener(); + private ThumbnailAdapter mThumbnailAdapter; + private boolean mStartPreviewFail = false; private int mStorageStatus = STORAGE_STATUS_OK; @@ -490,6 +493,9 @@ public class VideoCamera extends NoSearchActivity case R.id.review_thumbnail: if (!mMediaRecorderRecording) viewVideo(mThumbnailButton); break; + case R.id.btn_gallery: + gotoGallery(); + break; } } @@ -1504,26 +1510,38 @@ public class VideoCamera extends NoSearchActivity private void initThumbnailList() { mThumbnailList = (ListView) findViewById(R.id.thumbnail_list); - if (mThumbnailList != null) { - int width = mThumbnailList.getWidth(); - int height = mThumbnailList.getHeight(); - int thumbnailCount = (height + mThumbnailList.getDividerHeight()) - / (width + mThumbnailList.getDividerHeight()); - Cursor cursor = getThumbnailsCursor(thumbnailCount); - ThumbnailAdapter adapter = new ThumbnailAdapter( - getApplicationContext(), R.layout.thumbnail_item, cursor, - false); - mThumbnailList.setAdapter(adapter); - mThumbnailList.setOnItemClickListener(mThumbnailItemClickListener); + if (mThumbnailList == null) return; + + int width = mThumbnailList.getWidth(); + int height = mThumbnailList.getHeight(); + + // Add gallery button to header view. + if (mThumbnailList.getHeaderViewsCount() == 0) { + LayoutInflater inflater = getLayoutInflater(); + Button b = new Button(this); + ListView.LayoutParams params = new ListView.LayoutParams(width, width); + b.setId(R.id.btn_gallery); + b.setLayoutParams(params); + b.setOnClickListener(this); + b.setBackgroundResource(R.drawable.ic_menu_gallery); + mThumbnailList.addHeaderView(b); } + + // Set cursor adapter. + int thumbnailCount = (height + mThumbnailList.getDividerHeight()) + / (width + mThumbnailList.getDividerHeight()) - 1; + Cursor cursor = getThumbnailsCursor(thumbnailCount); + mThumbnailAdapter = new ThumbnailAdapter( + getApplicationContext(), R.layout.thumbnail_item, cursor, + false); + mThumbnailList.setAdapter(mThumbnailAdapter); + mThumbnailList.setOnItemClickListener(mThumbnailItemClickListener); } private void updateThumbnailList() { if (mThumbnailList == null) return; - CursorAdapter adapter = (CursorAdapter) mThumbnailList.getAdapter(); - Cursor cursor = adapter.getCursor(); - cursor.requery(); - adapter.notifyDataSetChanged(); + mThumbnailAdapter.getCursor().requery(); + mThumbnailAdapter.notifyDataSetChanged(); } private class ThumbnailItemClickListener implements OnItemClickListener { |