Merge "Ignore the first navigation to position One, not zero" into jb-ub-mail
diff --git a/Android.mk b/Android.mk
index e91e7d8..68e3281 100644
--- a/Android.mk
+++ b/Android.mk
@@ -16,7 +16,10 @@
# Include res dir from chips
chips_dir := ../../../frameworks/ex/chips/res
-res_dirs := $(chips_dir) res
+
+#Include res dir from photoviewer
+photo_dir := ../../../frameworks/ex/photoviewer/res
+res_dirs := $(chips_dir) $(photo_dir) res
##################################################
# Build APK
@@ -26,6 +29,7 @@
LOCAL_PACKAGE_NAME := UnifiedEmail
LOCAL_STATIC_JAVA_LIBRARIES := android-common-chips
+LOCAL_STATIC_JAVA_LIBRARIES += android-common-photoviewer
LOCAL_STATIC_JAVA_LIBRARIES += guava
LOCAL_STATIC_JAVA_LIBRARIES += android-common
LOCAL_STATIC_JAVA_LIBRARIES += com.android.emailcommon
@@ -38,7 +42,7 @@
$(call all-logtags-files-under, $(src_dirs))
LOCAL_RESOURCE_DIR := $(addprefix $(LOCAL_PATH)/, $(res_dirs)) $(LOCAL_PATH)/res
LOCAL_AAPT_FLAGS := --auto-add-overlay
-LOCAL_AAPT_FLAGS += --extra-packages com.android.ex.chips
+LOCAL_AAPT_FLAGS += --extra-packages com.android.ex.chips:com.android.ex.photo
LOCAL_PROGUARD_FLAG_FILES := proguard.flags
diff --git a/res/drawable/photo_view_background.xml b/res/drawable/photo_view_background.xml
deleted file mode 100644
index f7ebc17..0000000
--- a/res/drawable/photo_view_background.xml
+++ /dev/null
@@ -1,24 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!--
- Copyright (C) 2011 Google Inc.
- Licensed to 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.
--->
-<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
- <item>
- <shape>
- <solid android:color="@color/photo_background_color"/>
- </shape>
- </item>
-</layer-list>
diff --git a/res/drawable/photo_view_selector.xml b/res/drawable/photo_view_selector.xml
deleted file mode 100644
index 55b118a..0000000
--- a/res/drawable/photo_view_selector.xml
+++ /dev/null
@@ -1,24 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!--
- Copyright (C) 2011 Google Inc.
- Licensed to 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.
--->
-<selector xmlns:android="http://schemas.android.com/apk/res/android">
- <item android:state_pressed="true"
- android:drawable="@drawable/photo_view_selector_pressed" />
-
- <item android:state_focused="true"
- android:drawable="@drawable/photo_view_selector_focused" />
-</selector>
\ No newline at end of file
diff --git a/res/drawable/photo_view_selector_focused.xml b/res/drawable/photo_view_selector_focused.xml
deleted file mode 100644
index 3bda586..0000000
--- a/res/drawable/photo_view_selector_focused.xml
+++ /dev/null
@@ -1,22 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!--
- Copyright (C) 2011 Google Inc.
- Licensed to 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.
--->
-<shape xmlns:android="http://schemas.android.com/apk/res/android"
- android:shape="rectangle">
- <solid android:color="@color/clear"/>
- <stroke android:width="2dp" android:color="@color/photo_selection_color"/>
-</shape>
diff --git a/res/drawable/photo_view_selector_pressed.xml b/res/drawable/photo_view_selector_pressed.xml
deleted file mode 100644
index ced1b02..0000000
--- a/res/drawable/photo_view_selector_pressed.xml
+++ /dev/null
@@ -1,21 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!--
- Copyright (C) 2011 Google Inc.
- Licensed to 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.
--->
-<shape xmlns:android="http://schemas.android.com/apk/res/android"
- android:shape="rectangle">
- <solid android:color="@color/clear"/>
-</shape>
diff --git a/res/drawable/title_button_background.xml b/res/drawable/title_button_background.xml
deleted file mode 100644
index dff0640..0000000
--- a/res/drawable/title_button_background.xml
+++ /dev/null
@@ -1,23 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!--
- Copyright (C) 2011 Google Inc.
- Licensed to 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.
--->
-<selector xmlns:android="http://schemas.android.com/apk/res/android">
- <item android:state_focused="true" android:state_pressed="true" android:drawable="@drawable/btn_bg_pressed"/>
- <item android:state_focused="false" android:state_pressed="true" android:drawable="@drawable/btn_bg_pressed"/>
- <item android:state_focused="true" android:drawable="@drawable/btn_bg_selected"/>
- <item android:state_focused="false" android:state_pressed="false" android:drawable="@color/clear"/>
-</selector>
\ No newline at end of file
diff --git a/res/layout/action_bar_progress_spinner_layout.xml b/res/layout/action_bar_progress_spinner_layout.xml
deleted file mode 100644
index 38df7de..0000000
--- a/res/layout/action_bar_progress_spinner_layout.xml
+++ /dev/null
@@ -1,34 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
- Copyright (C) 2011 Google Inc.
- Licensed to 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.
--->
-
-<!-- ProgressBar must be wrapped into a container view if we want to control its
- visibility programmatically. The visibility of the container is determined by the
- visibility set on the MenuItem, not by the explicit setVisibility() calls. -->
-<FrameLayout
- xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:paddingRight="16dp">
- <ProgressBar
- android:id="@+id/action_bar_progress_spinner_view"
- style="?android:attr/progressBarStyleSmall"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:padding="5dip"
- android:indeterminate="true" />
-</FrameLayout>
diff --git a/res/layout/photo_activity_view.xml b/res/layout/photo_activity_view.xml
deleted file mode 100644
index df2a959..0000000
--- a/res/layout/photo_activity_view.xml
+++ /dev/null
@@ -1,72 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
- Copyright (C) 2011 Google Inc.
- Licensed to 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.
--->
-<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:id="@+id/photo_activity_root_view"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- >
- <LinearLayout
- android:orientation="vertical"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- >
- <!-- <include layout="@layout/title_layout"/> -->
- <com.android.mail.photo.PhotoViewPager
- android:id="@+id/photo_view_pager"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- />
- </LinearLayout>
- <!-- We cannot directly include empty_layout as the IDs defined there
- would clash with IDs defined underneath the PhotoViewPager. -->
- <FrameLayout
- android:id="@+id/photo_activity_empty"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:layout_weight="1">
- <TextView
- android:id="@+id/photo_activity_empty_text"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:gravity="center"
- android:textSize="18sp"/>
-
- <LinearLayout
- android:id="@+id/photo_activity_empty_progress"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_gravity="center"
- android:visibility="gone">
- <ProgressBar
- style="?android:attr/progressBarStyleSmall"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_marginTop="5dip"
- android:indeterminate="true"/>
- <TextView
- android:id="@+id/photo_activity_empty_progress_text"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_marginLeft="5dip"
- android:textSize="18sp"
- android:textColor="@color/title_text_color"
- android:text="@string/loading_photo"/>
- </LinearLayout>
- </FrameLayout>
-</FrameLayout>
-
diff --git a/res/layout/photo_fragment_view.xml b/res/layout/photo_fragment_view.xml
deleted file mode 100644
index 926ca69..0000000
--- a/res/layout/photo_fragment_view.xml
+++ /dev/null
@@ -1,68 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!--
- Copyright (C) 2011 Google Inc.
- Licensed to 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.
--->
-<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:background="@color/solid_black"
- >
- <com.android.mail.photo.views.PhotoView
- android:id="@+id/photo_view"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- />
-
- <FrameLayout
- android:id="@id/android:empty"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:layout_centerInParent="true"
- >
- <TextView
- android:id="@+id/list_empty_text"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:gravity="center"
- android:textSize="18sp"
- android:visibility="gone"
- />
- <LinearLayout
- android:id="@+id/list_empty_progress"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_gravity="center"
- android:visibility="gone"
- >
- <ProgressBar
- style="?android:attr/progressBarStyleSmall"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_marginTop="5dip"
- android:indeterminate="true"
- />
- <TextView
- android:id="@+id/list_empty_progress_text"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_marginLeft="5dip"
- android:textSize="18sp"
- android:textColor="@color/title_text_color"
- android:text="@string/loading_photo"
- />
- </LinearLayout>
- </FrameLayout>
-</RelativeLayout>
diff --git a/res/layout/title_layout.xml b/res/layout/title_layout.xml
deleted file mode 100644
index f904348..0000000
--- a/res/layout/title_layout.xml
+++ /dev/null
@@ -1,103 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
- Copyright (C) 2011 Google Inc.
- Licensed to 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.
--->
-<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:id="@+id/title_layout"
- android:layout_width="match_parent"
- android:layout_height="@dimen/titlebar_height"
- android:background="@color/title_background"
- android:padding="0dp"
- android:visibility="gone">
- <LinearLayout android:id="@+id/titlebar_icon_layout"
- android:layout_width="wrap_content"
- android:layout_height="match_parent"
- android:layout_alignParentLeft="true"
- android:gravity="center_vertical"
- android:orientation="horizontal">
- <ImageView
- android:id="@+id/titlebar_up"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:src="@drawable/ic_ab_back_holo_dark"/>
- <ImageView
- android:id="@+id/titlebar_icon"
- android:layout_width="@dimen/titlebar_icon_size"
- android:layout_height="@dimen/titlebar_icon_size"/>
- </LinearLayout>
- <LinearLayout
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_toLeftOf="@+id/title_button_1"
- android:layout_toRightOf="@+id/titlebar_icon_layout"
- android:layout_centerVertical="true"
- android:orientation="vertical"
- android:layout_marginLeft="4dip"
- android:layout_marginRight="4dip">
- <TextView
- android:id="@+id/titlebar_label"
- android:layout_width="wrap_content"
- android:layout_height="match_parent"
- android:textSize="18sp"
- android:textStyle="bold"
- android:ellipsize="end"
- android:singleLine="true"
- android:textColor="@color/title_text_color"/>
- <TextView
- android:id="@+id/titlebar_label_2"
- android:layout_width="wrap_content"
- android:layout_height="match_parent"
- android:textSize="12sp"
- android:ellipsize="end"
- android:singleLine="true"
- android:textColor="@color/title_text_color"
- android:visibility="gone"/>
- </LinearLayout>
-
- <ProgressBar android:id="@+id/progress_spinner"
- style="?android:attr/progressBarStyleSmallInverse"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_toLeftOf="@+id/title_button_1"
- android:layout_alignWithParentIfMissing="true"
- android:layout_centerVertical="true"
- android:layout_marginRight="16dip"
- android:visibility="gone"
- android:indeterminate="true"/>
- <ImageButton android:id="@+id/title_button_1"
- android:layout_width="@dimen/titlebar_height"
- android:layout_height="match_parent"
- android:layout_toLeftOf="@+id/title_button_2"
- android:layout_alignWithParentIfMissing="true"
- android:layout_alignParentTop="true"
- android:layout_alignParentBottom="true"
- android:visibility="gone"/>
- <ImageButton android:id="@+id/title_button_2"
- android:layout_width="@dimen/titlebar_height"
- android:layout_height="match_parent"
- android:layout_toLeftOf="@+id/title_button_3"
- android:layout_alignWithParentIfMissing="true"
- android:layout_alignParentTop="true"
- android:layout_alignParentBottom="true"
- android:visibility="gone"/>
- <ImageButton android:id="@+id/title_button_3"
- android:layout_width="@dimen/titlebar_height"
- android:layout_height="match_parent"
- android:layout_alignParentRight="true"
- android:layout_alignParentTop="true"
- android:layout_alignParentBottom="true"
- android:visibility="gone"/>
-</RelativeLayout>
diff --git a/res/values/colors.xml b/res/values/colors.xml
index a084da5..0b28fe6 100644
--- a/res/values/colors.xml
+++ b/res/values/colors.xml
@@ -56,20 +56,6 @@
<!-- Folder colors -->
<color name="folder_disabled_drop_target_text_color">#999999</color>
- <!-- Photo Viewer Colors -->
- <color name="solid_black">#ff000000</color>
- <color name="title_background">#ff292929</color>
- <color name="title_text_color">#ffffffff</color>
- <color name="clear">#00000000</color>
- <color name="participants_gallery">#FF3d3d3d</color>
- <color name="stream_content_color">#333</color>
- <color name="stream_comment_bg_color">#aaedf0f4</color>
- <color name="stream_link">#ff33bede</color>
- <color name="photo_selection_color">#ff58d83e</color>
- <color name="photo_background_color">#ff000000</color>
- <color name="photo_crop_dim_color">#cc000000</color>
- <color name="photo_crop_highlight_color">#fff</color>
-
<!-- Color of the semi-transparent shadow box on attachment tiles -->
<color name="attachment_tile_shadow_box_color">#7F000000</color>
<!-- Color of the subtitle message in the attachment tile -->
diff --git a/res/values/ids.xml b/res/values/ids.xml
index ff10d92..1443e92 100644
--- a/res/values/ids.xml
+++ b/res/values/ids.xml
@@ -20,18 +20,4 @@
<item type="id" name="personal_level"/>
<item type="id" name="reply_state" />
<item type="id" name="manage_folders_item"/>
-
- <!-- Loaders for PhotoViewActivity -->
- <item type="id" name="photo_view_photo_list_loader_id"/>
-
- <!-- Loaders for PhotoViewFragment -->
- <item type="id" name="photo_view_photo_loader_id"/>
-
- <!-- Dialogs for PhotoViewActivity -->
- <item type="id" name="photo_view_pending_dialog"/>
- <item type="id" name="photo_view_download_nonfull_failed_dialog"/>
- <item type="id" name="photo_view_download_full_failed_dialog"/>
-
- <!-- Dialogs for Photo View -->
- <item type="id" name="dialog_insert_photo"/>
</resources>
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 29073d4..39366ce 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -636,15 +636,6 @@
<!-- Photo View strings -->
- <!-- Default title for photo view [CHAR LIMIT=40] -->
- <string name="photo_view_default_title">Photos from message</string>
-
- <!-- Toast message if there was a problem loading the photo view. [CHAR LIMIT=80] -->
- <string name="photo_view_load_error">Photo couldn\'t be loaded.</string>
-
- <!-- Message displayed when trying to play a video that isn't ready [CHAR LIMIT=100] -->
- <string name="photo_view_video_not_ready">Video not available at this time. Please refresh.</string>
-
<!-- Message displayed when displaying a place holder image (for photos & videos) [CHAR LIMIT=60] -->
<string name="photo_view_placeholder_image">Item not available at this time. Please refresh.</string>
diff --git a/res/values/themes.xml b/res/values/themes.xml
deleted file mode 100644
index 7cb72b7..0000000
--- a/res/values/themes.xml
+++ /dev/null
@@ -1,26 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!--
- Copyright (C) 2011 Google Inc.
- Licensed to 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>
- <style name="PhotoViewTheme" parent="android:Theme.Holo.Light.DarkActionBar">
- <item name="android:windowNoTitle">false</item>
- <item name="android:windowContentOverlay">@null</item>
- <item name="android:windowActionBarOverlay">true</item>
- <item name="android:windowBackground">@drawable/photo_view_background</item>
- </style>
-</resources>
diff --git a/src/com/android/mail/browse/MessageAttachmentTile.java b/src/com/android/mail/browse/MessageAttachmentTile.java
index cda46bb..1f4af82 100644
--- a/src/com/android/mail/browse/MessageAttachmentTile.java
+++ b/src/com/android/mail/browse/MessageAttachmentTile.java
@@ -27,11 +27,11 @@
import android.view.View.OnClickListener;
import android.view.ViewGroup;
+import com.android.ex.photo.Intents;
+import com.android.ex.photo.Intents.PhotoViewIntentBuilder;
+import com.android.ex.photo.util.ImageUtils;
import com.android.mail.R;
-import com.android.mail.photo.Intents;
-import com.android.mail.photo.Intents.PhotoViewIntentBuilder;
import com.android.mail.photo.MailPhotoViewActivity;
-import com.android.mail.photo.util.ImageUtils;
import com.android.mail.providers.Attachment;
import com.android.mail.providers.UIProvider;
import com.android.mail.providers.UIProvider.AttachmentDestination;
diff --git a/src/com/android/mail/photo/Intents.java b/src/com/android/mail/photo/Intents.java
deleted file mode 100644
index b867ad4..0000000
--- a/src/com/android/mail/photo/Intents.java
+++ /dev/null
@@ -1,152 +0,0 @@
-/*
- * Copyright (C) 2011 Google Inc.
- * Licensed to 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.mail.photo;
-
-import android.content.ContentProvider;
-import android.content.Context;
-import android.content.Intent;
-import android.text.TextUtils;
-
-import com.android.mail.photo.fragments.PhotoViewFragment;
-
-/**
- * Build intents to start app activities
- */
-public class Intents {
- // Intent extras
- public static final String EXTRA_PHOTO_INDEX = "photo_index";
- public static final String EXTRA_PHOTO_ID = "photo_id";
- public static final String EXTRA_PHOTOS_URI = "photos_uri";
- public static final String EXTRA_RESOLVED_PHOTO_URI = "resolved_photo_uri";
- public static final String EXTRA_PHOTO_NAME = "photo_name";
- public static final String EXTRA_PROJECTION = "projection";
-
- /**
- * Gets a photo view intent builder to display the photos from phone activity.
- *
- * @param context The context
- * @return The intent builder
- */
- public static PhotoViewIntentBuilder newPhotoViewActivityIntentBuilder(Context context) {
- return new PhotoViewIntentBuilder(context, PhotoViewActivity.class);
- }
-
- /**
- * Gets a photo view intent builder to display the photo view fragment
- *
- * @param context The context
- * @return The intent builder
- */
- public static PhotoViewIntentBuilder newPhotoViewFragmentIntentBuilder(Context context) {
- return new PhotoViewIntentBuilder(context, PhotoViewFragment.class);
- }
-
- /** Gets a new photo view intent builder */
- public static PhotoViewIntentBuilder newPhotoViewIntentBuilder(
- Context context, Class<? extends PhotoViewActivity> cls) {
- return new PhotoViewIntentBuilder(context, cls);
- }
-
- /** Builder to create a photo view intent */
- public static class PhotoViewIntentBuilder {
- private final Intent mIntent;
-
- /** The name of the photo being displayed */
- private String mPhotoName;
- /** The index of the photo to show */
- private Integer mPhotoIndex;
- /** The URI of the group of photos to display */
- private String mPhotosUri;
- /** The URL of the photo to display */
- private String mResolvedPhotoUri;
- /** The projection for the query to use; optional */
- private String[] mProjection;
-
- private PhotoViewIntentBuilder(Context context, Class<?> cls) {
- mIntent = new Intent(context, cls);
- }
-
- /** Sets the photo name */
- public PhotoViewIntentBuilder setPhotoName(String photoName) {
- mPhotoName = photoName;
- return this;
- }
-
- /** Sets the photo index */
- public PhotoViewIntentBuilder setPhotoIndex(Integer photoIndex) {
- mPhotoIndex = photoIndex;
- return this;
- }
-
- /** Sets the photos URI */
- public PhotoViewIntentBuilder setPhotosUri(String photosUri) {
- mPhotosUri = photosUri;
- return this;
- }
-
- /** Sets the query projection */
- public PhotoViewIntentBuilder setProjection(String[] projection) {
- mProjection = projection;
- return this;
- }
-
- /** Sets the resolved photo URI. This method is for the case
- * where the URI given to {@link PhotoViewActivity} points directly
- * to a single image and does not need to be resolved via a query
- * to the {@link ContentProvider}. If this value is set, it supersedes
- * {@link #setPhotosUri(String)}. */
- public PhotoViewIntentBuilder setResolvedPhotoUri(String resolvedPhotoUri) {
- mResolvedPhotoUri = resolvedPhotoUri;
- return this;
- }
-
- /** Build the intent */
- public Intent build() {
- if (TextUtils.isEmpty(mPhotosUri) && TextUtils.isEmpty(mResolvedPhotoUri)) {
- throw new IllegalArgumentException(
- "Either PhotosUri or ResolvedPhotoUri must be set.");
- }
-
- mIntent.setAction(Intent.ACTION_VIEW);
-
- mIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
-
- if (mPhotoName != null) {
- mIntent.putExtra(EXTRA_PHOTO_NAME, mPhotoName);
- }
-
- if (mPhotoIndex != null) {
- mIntent.putExtra(EXTRA_PHOTO_INDEX, (int) mPhotoIndex);
- }
-
- if (mPhotosUri != null) {
- mIntent.putExtra(EXTRA_PHOTOS_URI, mPhotosUri);
- }
-
- if (mResolvedPhotoUri != null) {
- mIntent.putExtra(EXTRA_RESOLVED_PHOTO_URI, mResolvedPhotoUri);
- }
-
- if (mProjection != null) {
- mIntent.putExtra(EXTRA_PROJECTION, mProjection);
- }
-
- return mIntent;
- }
- }
-}
diff --git a/src/com/android/mail/photo/MailPhotoViewActivity.java b/src/com/android/mail/photo/MailPhotoViewActivity.java
index 588c807..087ef0e 100644
--- a/src/com/android/mail/photo/MailPhotoViewActivity.java
+++ b/src/com/android/mail/photo/MailPhotoViewActivity.java
@@ -8,6 +8,7 @@
import android.view.MenuInflater;
import android.view.MenuItem;
+import com.android.ex.photo.PhotoViewActivity;
import com.android.mail.R;
import com.android.mail.browse.AttachmentActionHandler;
import com.android.mail.providers.Attachment;
diff --git a/src/com/android/mail/photo/PhotoViewActivity.java b/src/com/android/mail/photo/PhotoViewActivity.java
deleted file mode 100644
index e9ba9f9..0000000
--- a/src/com/android/mail/photo/PhotoViewActivity.java
+++ /dev/null
@@ -1,561 +0,0 @@
-/*
- * Copyright (C) 2011 Google Inc.
- * Licensed to 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.mail.photo;
-
-import android.app.ActionBar;
-import android.app.Activity;
-import android.app.ActivityManager;
-import android.app.Fragment;
-import android.app.LoaderManager.LoaderCallbacks;
-import android.content.Intent;
-import android.content.Loader;
-import android.database.Cursor;
-import android.net.Uri;
-import android.os.Bundle;
-import android.os.Handler;
-import android.support.v4.view.ViewPager.OnPageChangeListener;
-import android.view.View;
-import android.widget.ProgressBar;
-import android.widget.TextView;
-
-import com.android.mail.R;
-import com.android.mail.photo.PhotoViewPager.InterceptType;
-import com.android.mail.photo.PhotoViewPager.OnInterceptTouchListener;
-import com.android.mail.photo.adapters.BaseFragmentPagerAdapter.OnFragmentPagerListener;
-import com.android.mail.photo.adapters.PhotoPagerAdapter;
-import com.android.mail.photo.fragments.PhotoViewFragment;
-import com.android.mail.photo.fragments.PhotoViewFragment.PhotoViewCallbacks;
-import com.android.mail.photo.loaders.PhotoPagerLoader;
-import com.android.mail.photo.provider.PhotoContract;
-
-import java.util.HashSet;
-import java.util.Set;
-
-/**
- * Activity to view the contents of an album.
- */
-public class PhotoViewActivity extends Activity implements PhotoViewCallbacks,
- LoaderCallbacks<Cursor>, OnPageChangeListener, OnInterceptTouchListener,
- OnFragmentPagerListener {
-
- /**
- * Listener to be invoked for screen events.
- */
- public static interface OnScreenListener {
-
- /**
- * The full screen state has changed.
- */
- public void onFullScreenChanged(boolean fullScreen, boolean animate);
-
- /**
- * A new view has been activated and the previous view de-activated.
- */
- public void onViewActivated();
-
- /**
- * Updates the view that can be used to show progress.
- *
- * @param progressView a View that can be used to show progress
- */
- public void onUpdateProgressView(ProgressBar progressView);
-
- /**
- * Called when a right-to-left touch move intercept is about to occur.
- *
- * @param origX the raw x coordinate of the initial touch
- * @param origY the raw y coordinate of the initial touch
- * @return {@code true} if the touch should be intercepted.
- */
- public boolean onInterceptMoveLeft(float origX, float origY);
-
- /**
- * Called when a left-to-right touch move intercept is about to occur.
- *
- * @param origX the raw x coordinate of the initial touch
- * @param origY the raw y coordinate of the initial touch
- * @return {@code true} if the touch should be intercepted.
- */
- public boolean onInterceptMoveRight(float origX, float origY);
- }
-
- private final static String STATE_ITEM_KEY =
- "com.google.android.apps.plus.PhotoViewFragment.ITEM";
- private final static String STATE_FULLSCREEN_KEY =
- "com.google.android.apps.plus.PhotoViewFragment.FULLSCREEN";
-
- private static final int LOADER_PHOTO_LIST = R.id.photo_view_photo_list_loader_id;
-
- /** Count used when the real photo count is unknown [but, may be determined] */
- public static final int ALBUM_COUNT_UNKNOWN = -1;
-
- /** Argument key for the dialog message */
- public static final String KEY_MESSAGE = "dialog_message";
-
- public static int sMemoryClass;
-
- /** The URI of the photos we're viewing; may be {@code null} */
- private String mPhotosUri;
- /** The index of the currently viewed photo */
- private int mPhotoIndex;
- /** The query projection to use; may be {@code null} */
- private String[] mProjection;
- /** The name of the particular photo being viewed. */
- private String mPhotoName;
- /** The total number of photos; only valid if {@link #mIsEmpty} is {@code false}. */
- private int mAlbumCount = ALBUM_COUNT_UNKNOWN;
- /** {@code true} if the view is empty. Otherwise, {@code false}. */
- private boolean mIsEmpty;
- /** The root view of the activity */
- private View mRootView;
- /** The main pager; provides left/right swipe between photos */
- private PhotoViewPager mViewPager;
- /** Adapter to create pager views */
- private PhotoPagerAdapter mAdapter;
- /** Whether or not we're in "full screen" mode */
- private boolean mFullScreen;
- /** The set of listeners wanting full screen state */
- private Set<OnScreenListener> mScreenListeners = new HashSet<OnScreenListener>();
- /** When {@code true}, restart the loader when the activity becomes active */
- private boolean mRestartLoader;
- /** Whether or not this activity is paused */
- private boolean mIsPaused = true;
- // TODO Find a better way to do this. We basically want the activity to display the
- // "loading..." progress until the fragment takes over and shows it's own "loading..."
- // progress [located in photo_header_view.xml]. We could potentially have all status displayed
- // by the activity, but, that gets tricky when it comes to screen rotation. For now, we
- // track the loading by this variable which is fragile and may cause phantom "loading..."
- // text.
- /** {@code true} if the fragment is loading. */
- private boolean mFragmentIsLoading;
-
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
-
- final ActivityManager mgr = (ActivityManager) getApplicationContext().
- getSystemService(Activity.ACTIVITY_SERVICE);
- sMemoryClass = mgr.getMemoryClass();
-
- Intent mIntent = getIntent();
-
- int currentItem = -1;
- if (savedInstanceState != null) {
- currentItem = savedInstanceState.getInt(STATE_ITEM_KEY, -1);
- mFullScreen = savedInstanceState.getBoolean(STATE_FULLSCREEN_KEY, false);
- }
-
- // album name; if not set, use a default name
- if (mIntent.hasExtra(Intents.EXTRA_PHOTO_NAME)) {
- mPhotoName = mIntent.getStringExtra(Intents.EXTRA_PHOTO_NAME);
- } else {
- mPhotoName = getResources().getString(R.string.photo_view_default_title);
- }
-
- // uri of the photos to view; optional
- if (mIntent.hasExtra(Intents.EXTRA_PHOTOS_URI)) {
- mPhotosUri = mIntent.getStringExtra(Intents.EXTRA_PHOTOS_URI);
- }
-
- // projection for the query; optional
- // I.f not set, the default projection is used.
- // This projection must include the columns from the default projection.
- if (mIntent.hasExtra(Intents.EXTRA_PROJECTION)) {
- mProjection = mIntent.getStringArrayExtra(Intents.EXTRA_PROJECTION);
- } else {
- mProjection = null;
- }
-
- // Set the current item from the intent if wasn't in the saved instance
- if (mIntent.hasExtra(Intents.EXTRA_PHOTO_INDEX) && currentItem < 0) {
- currentItem = mIntent.getIntExtra(Intents.EXTRA_PHOTO_INDEX, -1);
- }
- mPhotoIndex = currentItem;
-
- setContentView(R.layout.photo_activity_view);
- mRootView = findViewById(R.id.photo_activity_root_view);
-
- // Create the adapter and add the view pager
- mAdapter = new PhotoPagerAdapter(this, getFragmentManager(), null);
- mAdapter.setFragmentPagerListener(this);
-
- mViewPager = (PhotoViewPager) findViewById(R.id.photo_view_pager);
- mViewPager.setAdapter(mAdapter);
- mViewPager.setOnPageChangeListener(this);
- mViewPager.setOnInterceptTouchListener(this);
-
- // Kick off the loader
- getLoaderManager().initLoader(LOADER_PHOTO_LIST, null, this);
-
- final ActionBar actionBar = getActionBar();
- actionBar.setDisplayHomeAsUpEnabled(true);
-
- updateView(mRootView);
- }
-
- @Override
- protected void onResume() {
- super.onResume();
- setFullScreen(mFullScreen, false);
-
- mIsPaused = false;
- if (mRestartLoader) {
- mRestartLoader = false;
- getLoaderManager().restartLoader(LOADER_PHOTO_LIST, null, this);
- }
- }
-
- @Override
- protected void onPause() {
- mIsPaused = true;
-
- super.onPause();
- }
-
- @Override
- public void onBackPressed() {
- // If in full screen mode, toggle mode & eat the 'back'
- if (mFullScreen) {
- toggleFullScreen();
- } else {
- super.onBackPressed();
- }
- }
-
- @Override
- public void onAttachFragment(Fragment fragment) {
- super.onAttachFragment(fragment);
- PhotoViewFragment photoFragment = null;
- if (fragment instanceof PhotoViewFragment) {
- photoFragment = (PhotoViewFragment) fragment;
- }
-
- // Set the progress view as new fragments are attached
- final ProgressBar progressView
- = (ProgressBar) findViewById(R.id.action_bar_progress_spinner_view);
-
- if (photoFragment != null && progressView != null) {
- photoFragment.onUpdateProgressView(progressView);
- }
- }
-
- @Override
- public void onSaveInstanceState(Bundle outState) {
- super.onSaveInstanceState(outState);
-
- outState.putInt(STATE_ITEM_KEY, mViewPager.getCurrentItem());
- outState.putBoolean(STATE_FULLSCREEN_KEY, mFullScreen);
- }
-
- @Override
- public void addScreenListener(OnScreenListener listener) {
- mScreenListeners.add(listener);
- }
-
- @Override
- public void removeScreenListener(OnScreenListener listener) {
- mScreenListeners.remove(listener);
- }
-
- @Override
- public boolean isFragmentFullScreen(Fragment fragment) {
- if (mViewPager == null || mAdapter == null || mAdapter.getCount() == 0) {
- return mFullScreen;
- }
- return mFullScreen || (mViewPager.getCurrentItem() != mAdapter.getItemPosition(fragment));
- }
-
- @Override
- public void toggleFullScreen() {
- setFullScreen(!mFullScreen, true);
- }
-
- @Override
- public void onPhotoRemoved(long photoId) {
- final Cursor data = mAdapter.getCursor();
- if (data == null) {
- // Huh?! How would this happen?
- return;
- }
-
- final int dataCount = data.getCount();
- if (dataCount <= 1) {
- // The last photo was removed ... finish the activity & go to photos-home
-// final Intent intent = Intents.getPhotosHomeIntent(this, mAccount, mAccount.getGaiaId());
-//
-// intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
-// startActivity(intent);
- finish();
- return;
- }
-
- getLoaderManager().restartLoader(LOADER_PHOTO_LIST, null, this);
- }
-
- @Override
- public Loader<Cursor> onCreateLoader(int id, Bundle args) {
- if (id == LOADER_PHOTO_LIST) {
- mFragmentIsLoading = true;
- return new PhotoPagerLoader(this, Uri.parse(mPhotosUri), mProjection);
- }
- return null;
- }
-
- @Override
- public void onLoadFinished(final Loader<Cursor> loader, final Cursor data) {
- final int id = loader.getId();
- if (id == LOADER_PHOTO_LIST) {
- if (data == null || data.getCount() == 0) {
- mIsEmpty = true;
- mFragmentIsLoading = false;
- updateView(mRootView);
- } else {
- mAlbumCount = data.getCount();
-
- // Cannot do this directly; need to be out of the loader
- new Handler().post(new Runnable() {
- @Override
- public void run() {
- // We're paused; don't do anything now, we'll get re-invoked
- // when the activity becomes active again
- if (mIsPaused) {
- mRestartLoader = true;
- return;
- }
- mIsEmpty = false;
-
- // set the selected photo
- int itemIndex = mPhotoIndex;
-
- // Use an index of 0 if the index wasn't specified or couldn't be found
- if (itemIndex < 0) {
- itemIndex = 0;
- }
-
- mAdapter.swapCursor(data);
- updateView(mRootView);
- mViewPager.setCurrentItem(itemIndex, false);
- updateActionBar();
- }
- });
- }
- }
- }
-
- @Override
- public void onLoaderReset(Loader<Cursor> loader) {
- }
-
- @Override
- public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
- }
-
- @Override
- public void onPageSelected(int position) {
- setViewActivated();
- updateActionBar();
- mPhotoIndex = position;
- }
-
- @Override
- public void onPageScrollStateChanged(int state) {
- }
-
- @Override
- public void onPageActivated(Fragment fragment) {
- setViewActivated();
- }
-
- @Override
- public boolean isFragmentActive(Fragment fragment) {
- if (mViewPager == null || mAdapter == null) {
- return false;
- }
- return mViewPager.getCurrentItem() == mAdapter.getItemPosition(fragment);
- }
-
- @Override
- public void onFragmentVisible(Fragment fragment) {
- if (mViewPager == null || mAdapter == null) {
- return;
- }
- if (mViewPager.getCurrentItem() == mAdapter.getItemPosition(fragment)) {
- mFragmentIsLoading = false;
- }
- updateView(mRootView);
- }
-
- @Override
- public InterceptType onTouchIntercept(float origX, float origY) {
- boolean interceptLeft = false;
- boolean interceptRight = false;
-
- for (OnScreenListener listener : mScreenListeners) {
- if (!interceptLeft) {
- interceptLeft = listener.onInterceptMoveLeft(origX, origY);
- }
- if (!interceptRight) {
- interceptRight = listener.onInterceptMoveRight(origX, origY);
- }
- listener.onViewActivated();
- }
-
- if (interceptLeft) {
- if (interceptRight) {
- return InterceptType.BOTH;
- }
- return InterceptType.LEFT;
- } else if (interceptRight) {
- return InterceptType.RIGHT;
- }
- return InterceptType.NONE;
- }
-
- /**
- * Updates the title bar according to the value of {@link #mFullScreen}.
- */
- private void setFullScreen(boolean fullScreen, boolean animate) {
- final boolean fullScreenChanged = (fullScreen != mFullScreen);
- mFullScreen = fullScreen;
-
- ActionBar actionBar = getActionBar();
- if (mFullScreen) {
- actionBar.hide();
- } else {
- actionBar.show();
- }
-
- if (fullScreenChanged) {
- for (OnScreenListener listener : mScreenListeners) {
- listener.onFullScreenChanged(mFullScreen, animate);
- }
- }
- }
-
- /**
- * Updates the title bar according to the value of {@link #mFullScreen}.
- */
- private void setViewActivated() {
- for (OnScreenListener listener : mScreenListeners) {
- listener.onViewActivated();
- }
- }
-
- /**
- * Updates the view to show the correct content. If album data is available, show the album
- * list. Otherwise, show either progress or no album view.
- */
- private void updateView(View view) {
- if (view == null) {
- return;
- }
-
- if (mFragmentIsLoading || (mAdapter.getCursor() == null && !mIsEmpty)) {
- showEmptyViewProgress(view);
- } else {
- if (!mIsEmpty) {
- showContent(view);
- } else {
- showEmptyView(view, getResources().getString(R.string.camera_photo_error));
- }
- }
- }
-
- /**
- * Display loading progress
- *
- * @param view The layout view
- */
- private void showEmptyViewProgress(View view) {
- view.findViewById(R.id.photo_activity_empty_text).setVisibility(View.GONE);
- view.findViewById(R.id.photo_activity_empty_progress).setVisibility(View.VISIBLE);
- view.findViewById(R.id.photo_activity_empty).setVisibility(View.VISIBLE);
- }
-
- /**
- * Show only the empty view
- *
- * @param view The layout view
- */
- private void showEmptyView(View view, CharSequence emptyText) {
- view.findViewById(R.id.photo_activity_empty_progress).setVisibility(View.GONE);
- final TextView etv = (TextView) view.findViewById(R.id.photo_activity_empty_text);
- etv.setText(emptyText);
- etv.setVisibility(View.VISIBLE);
- view.findViewById(R.id.photo_activity_empty).setVisibility(View.VISIBLE);
- }
-
- /**
- * Hide the empty view and show the content
- *
- * @param view The layout view
- */
- private void showContent(View view) {
- view.findViewById(R.id.photo_activity_empty).setVisibility(View.GONE);
- }
-
- /**
- * Adjusts the activity title and subtitle to reflect the photo name and count.
- */
- protected void updateActionBar() {
- final int position = mViewPager.getCurrentItem() + 1;
- final String subtitle;
- final boolean hasAlbumCount = mAlbumCount >= 0;
-
- final Cursor cursor = getCursorAtProperPosition();
-
- if (cursor != null) {
- final int photoNameIndex = cursor.getColumnIndex(PhotoContract.PhotoViewColumns.NAME);
- mPhotoName = cursor.getString(photoNameIndex);
- }
-
- if (mIsEmpty || !hasAlbumCount || position <= 0) {
- subtitle = null;
- } else {
- subtitle = getResources().getString(R.string.photo_view_count, position, mAlbumCount);
- }
-
- final ActionBar actionBar = getActionBar();
-
- actionBar.setTitle(mPhotoName);
- actionBar.setSubtitle(subtitle);
- }
-
- /**
- * Utility method that will return the cursor that contains the data
- * at the current position so that it refers to the current image on screen.
- * @return the cursor at the current position or
- * null if no cursor exists or if the {@link PhotoViewPager} is null.
- */
- public Cursor getCursorAtProperPosition() {
- if (mViewPager == null) {
- return null;
- }
-
- final int position = mViewPager.getCurrentItem();
- final Cursor cursor = mAdapter.getCursor();
-
- if (cursor == null) {
- return null;
- }
-
- cursor.moveToPosition(position);
-
- return cursor;
- }
-}
diff --git a/src/com/android/mail/photo/PhotoViewPager.java b/src/com/android/mail/photo/PhotoViewPager.java
deleted file mode 100644
index 7982ff3..0000000
--- a/src/com/android/mail/photo/PhotoViewPager.java
+++ /dev/null
@@ -1,154 +0,0 @@
-/*
- * Copyright (C) 2011 Google Inc.
- * Licensed to 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.mail.photo;
-
-import android.content.Context;
-import android.support.v4.view.MotionEventCompat;
-import android.support.v4.view.ViewPager;
-import android.util.AttributeSet;
-import android.view.MotionEvent;
-
-/**
- * View pager for photo view fragments. Define our own class so we can specify the
- * view pager in XML.
- */
-public class PhotoViewPager extends ViewPager {
- /**
- * A type of intercept that should be performed
- */
- public static enum InterceptType { NONE, LEFT, RIGHT, BOTH }
-
- /**
- * Provides an ability to intercept touch events.
- * <p>
- * {@link ViewPager} intercepts all touch events and we need to be able to override this
- * behaviour. Instead, we could perform a similar function by declaring a custom
- * {@link ViewGroup} to contain the pager and intercept touch events at a higher level.
- */
- public static interface OnInterceptTouchListener {
- /**
- * Called when a touch intercept is about to occur.
- *
- * @param origX the raw x coordinate of the initial touch
- * @param origY the raw y coordinate of the initial touch
- * @return Which type of touch, if any, should should be intercepted.
- */
- public InterceptType onTouchIntercept(float origX, float origY);
- }
-
- private static final int INVALID_POINTER = -1;
-
- private float mLastMotionX;
- private int mActivePointerId;
- /** The x coordinate where the touch originated */
- private float mActivatedX;
- /** The y coordinate where the touch originated */
- private float mActivatedY;
- private OnInterceptTouchListener mListener;
-
- public PhotoViewPager(Context context) {
- super(context);
- }
-
- public PhotoViewPager(Context context, AttributeSet attrs) {
- super(context, attrs);
- }
-
- /**
- * {@inheritDoc}
- * <p>
- * We intercept touch event intercepts so we can prevent switching views when the
- * current view is internally scrollable.
- */
- @Override
- public boolean onInterceptTouchEvent(MotionEvent ev) {
- final InterceptType intercept = (mListener != null)
- ? mListener.onTouchIntercept(mActivatedX, mActivatedY)
- : InterceptType.NONE;
- final boolean ignoreScrollLeft =
- (intercept == InterceptType.BOTH || intercept == InterceptType.LEFT);
- final boolean ignoreScrollRight =
- (intercept == InterceptType.BOTH || intercept == InterceptType.RIGHT);
-
- // Only check ability to page if we can't scroll in one / both directions
- final int action = ev.getAction() & MotionEventCompat.ACTION_MASK;
-
- if (action == MotionEvent.ACTION_CANCEL || action == MotionEvent.ACTION_UP) {
- mActivePointerId = INVALID_POINTER;
- }
-
- switch (action) {
- case MotionEvent.ACTION_MOVE: {
- if (ignoreScrollLeft || ignoreScrollRight) {
- final int activePointerId = mActivePointerId;
- if (activePointerId == INVALID_POINTER) {
- // If we don't have a valid id, the touch down wasn't on content.
- break;
- }
-
- final int pointerIndex =
- MotionEventCompat.findPointerIndex(ev, activePointerId);
- final float x = MotionEventCompat.getX(ev, pointerIndex);
-
- if (ignoreScrollLeft && ignoreScrollRight) {
- mLastMotionX = x;
- return false;
- } else if (ignoreScrollLeft && (x > mLastMotionX)) {
- mLastMotionX = x;
- return false;
- } else if (ignoreScrollRight && (x < mLastMotionX)) {
- mLastMotionX = x;
- return false;
- }
- }
- break;
- }
-
- case MotionEvent.ACTION_DOWN: {
- mLastMotionX = ev.getX();
- // Use the raw x/y as the children can be located anywhere and there isn't a
- // single offset that would be meaningful
- mActivatedX = ev.getRawX();
- mActivatedY = ev.getRawY();
- mActivePointerId = MotionEventCompat.getPointerId(ev, 0);
- break;
- }
-
- case MotionEventCompat.ACTION_POINTER_UP: {
- final int pointerIndex = MotionEventCompat.getActionIndex(ev);
- final int pointerId = MotionEventCompat.getPointerId(ev, pointerIndex);
- if (pointerId == mActivePointerId) {
- // Our active pointer going up; select a new active pointer
- final int newPointerIndex = pointerIndex == 0 ? 1 : 0;
- mLastMotionX = MotionEventCompat.getX(ev, newPointerIndex);
- mActivePointerId = MotionEventCompat.getPointerId(ev, newPointerIndex);
- }
- break;
- }
- }
-
- return super.onInterceptTouchEvent(ev);
- }
-
- /**
- * sets the intercept touch listener.
- */
- public void setOnInterceptTouchListener(OnInterceptTouchListener l) {
- mListener = l;
- }
-}
diff --git a/src/com/android/mail/photo/adapters/BaseCursorPagerAdapter.java b/src/com/android/mail/photo/adapters/BaseCursorPagerAdapter.java
deleted file mode 100644
index d4d6c99..0000000
--- a/src/com/android/mail/photo/adapters/BaseCursorPagerAdapter.java
+++ /dev/null
@@ -1,261 +0,0 @@
-/*
- * Copyright (C) 2011 Google Inc.
- * Licensed to 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.mail.photo.adapters;
-
-import android.app.Fragment;
-import android.app.FragmentManager;
-import android.content.Context;
-import android.database.Cursor;
-import android.util.Log;
-import android.util.SparseIntArray;
-import android.view.View;
-
-import com.android.mail.photo.provider.PhotoContract;
-
-import java.util.HashMap;
-
-/**
- * Page adapter for use with an BaseCursorLoader. Unlike other cursor adapters, this has no
- * observers for automatic refresh. Instead, it depends upon external mechanisms to provide
- * the update signal.
- */
-public abstract class BaseCursorPagerAdapter extends BaseFragmentPagerAdapter {
- private static final String TAG = "BaseCursorPagerAdapter";
-
- Context mContext;
- private boolean mDataValid;
- private Cursor mCursor;
- private int mRowIDColumn;
- /** Mapping of row ID to cursor position */
- private SparseIntArray mItemPosition;
- /** Mapping of instantiated object to row ID */
- private HashMap<Object, Integer> mObjectRowMap = new HashMap<Object, Integer>();
-
- /**
- * Constructor that always enables auto-requery.
- *
- * @param c The cursor from which to get the data.
- * @param context The context
- */
- public BaseCursorPagerAdapter(Context context, FragmentManager fm, Cursor c) {
- super(fm);
- init(context, c);
- }
-
- /**
- * Makes a fragment for the data pointed to by the cursor
- *
- * @param context Interface to application's global information
- * @param cursor The cursor from which to get the data. The cursor is already
- * moved to the correct position.
- * @return the newly created fragment.
- */
- public abstract Fragment getItem(Context context, Cursor cursor);
-
- @Override
- public Fragment getItem(int position) {
- if (mDataValid && moveCursorTo(position)) {
- return getItem(mContext, mCursor);
- }
- return null;
- }
-
- @Override
- public int getCount() {
- if (mDataValid && mCursor != null) {
- return mCursor.getCount();
- } else {
- return 0;
- }
- }
-
- @Override
- public Object instantiateItem(View container, int position) {
- if (!mDataValid) {
- throw new IllegalStateException("this should only be called when the cursor is valid");
- }
-
- final Integer rowId;
- if (moveCursorTo(position)) {
- rowId = mCursor.getString(mRowIDColumn).hashCode();
- } else {
- rowId = null;
- }
-
- // Create the fragment and bind cursor data
- final Object obj = super.instantiateItem(container, position);
- if (obj != null) {
- mObjectRowMap.put(obj, rowId);
- }
- return obj;
- }
-
- @Override
- public void destroyItem(View container, int position, Object object) {
- mObjectRowMap.remove(object);
-
- super.destroyItem(container, position, object);
- }
-
- @Override
- public int getItemPosition(Object object) {
- final Integer rowId = mObjectRowMap.get(object);
- if (rowId == null || mItemPosition == null) {
- return POSITION_NONE;
- }
-
- final int position = mItemPosition.get(rowId, POSITION_NONE);
- return position;
- }
-
- /**
- * @return true if data is valid
- */
- public boolean isDataValid() {
- return mDataValid;
- }
-
- /**
- * Returns the cursor.
- */
- public Cursor getCursor() {
- return mCursor;
- }
-
- /**
- * Returns the data item associated with the specified position in the data set.
- */
- public Object getDataItem(int position) {
- if (mDataValid && moveCursorTo(position)) {
- return mCursor;
- } else {
- return null;
- }
- }
-
- /**
- * Returns the row id associated with the specified position in the list.
- */
- public long getItemId(int position) {
- if (mDataValid && moveCursorTo(position)) {
- return mCursor.getString(mRowIDColumn).hashCode();
- } else {
- return 0;
- }
- }
-
- /**
- * Swap in a new Cursor, returning the old Cursor.
- *
- * @param newCursor The new cursor to be used.
- * @return Returns the previously set Cursor, or null if there was not one.
- * If the given new Cursor is the same instance is the previously set
- * Cursor, null is also returned.
- */
- public Cursor swapCursor(Cursor newCursor) {
- if (Log.isLoggable(TAG, Log.VERBOSE)) {
- Log.v(TAG, "swapCursor old=" + (mCursor == null ? -1 : mCursor.getCount()) +
- "; new=" + (newCursor == null ? -1 : newCursor.getCount()));
- }
-
- if (newCursor == mCursor) {
- return null;
- }
- Cursor oldCursor = mCursor;
- mCursor = newCursor;
- if (newCursor != null) {
- mRowIDColumn = newCursor.getColumnIndex(PhotoContract.PhotoViewColumns.URI);
- mDataValid = true;
- } else {
- mRowIDColumn = -1;
- mDataValid = false;
- }
-
- setItemPosition();
- notifyDataSetChanged(); // notify the observers about the new cursor
- return oldCursor;
- }
-
- /**
- * Converts the cursor into a CharSequence. Subclasses should override this
- * method to convert their results. The default implementation returns an
- * empty String for null values or the default String representation of
- * the value.
- *
- * @param cursor the cursor to convert to a CharSequence
- * @return a CharSequence representing the value
- */
- public CharSequence convertToString(Cursor cursor) {
- return cursor == null ? "" : cursor.toString();
- }
-
- @Override
- protected String makeFragmentName(int viewId, int index) {
- if (moveCursorTo(index)) {
- return "android:pager:" + viewId + ":" + mCursor.getString(mRowIDColumn).hashCode();
- } else {
- return super.makeFragmentName(viewId, index);
- }
- }
-
- /**
- * Moves the cursor to the given position
- *
- * @return {@code true} if the cursor's position was set. Otherwise, {@code false}.
- */
- private boolean moveCursorTo(int position) {
- if (mCursor != null && !mCursor.isClosed()) {
- return mCursor.moveToPosition(position);
- }
- return false;
- }
-
- /**
- * Initialize the adapter.
- */
- private void init(Context context, Cursor c) {
- boolean cursorPresent = c != null;
- mCursor = c;
- mDataValid = cursorPresent;
- mContext = context;
- mRowIDColumn = cursorPresent
- ? mCursor.getColumnIndex(PhotoContract.PhotoViewColumns.URI) : -1;
- }
-
- /**
- * Sets the {@link #mItemPosition} instance variable with the current mapping of
- * row id to cursor position.
- */
- private void setItemPosition() {
- if (!mDataValid || mCursor == null || mCursor.isClosed()) {
- mItemPosition = null;
- return;
- }
-
- SparseIntArray itemPosition = new SparseIntArray(mCursor.getCount());
-
- mCursor.moveToPosition(-1);
- while (mCursor.moveToNext()) {
- final int rowId = mCursor.getString(mRowIDColumn).hashCode();
- final int position = mCursor.getPosition();
-
- itemPosition.append(rowId, position);
- }
- mItemPosition = itemPosition;
- }
-}
diff --git a/src/com/android/mail/photo/adapters/BaseFragmentPagerAdapter.java b/src/com/android/mail/photo/adapters/BaseFragmentPagerAdapter.java
deleted file mode 100644
index 22a74bf..0000000
--- a/src/com/android/mail/photo/adapters/BaseFragmentPagerAdapter.java
+++ /dev/null
@@ -1,209 +0,0 @@
-/*
- * Copyright (C) 2011 Google Inc.
- * Licensed to 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.mail.photo.adapters;
-
-import android.app.Fragment;
-import android.app.FragmentManager;
-import android.app.FragmentTransaction;
-import android.os.Parcelable;
-import android.support.v4.app.FragmentPagerAdapter;
-import android.support.v4.view.PagerAdapter;
-import android.util.Log;
-import android.util.LruCache;
-import android.view.View;
-
-/**
- * NOTE: This is a direct copy of {@link FragmentPagerAdapter} with four very important
- * modifications.
- * <p>
- * <ol>
- * <li>The method {@link #makeFragmentName(int, int)} is declared "protected"
- * in our class. We need to be able to re-define the fragment's name according to data
- * only available to sub-classes.</li>
- * <li>The method {@link #isViewFromObject(View, Object)} has been reimplemented to search
- * the entire view hierarchy for the given view.</li>
- * <li>In method {@link #destroyItem(View, int, Object)}, the fragment is detached and
- * added to a cache. If the fragment is evicted from the cache, it will be deleted.
- * An album may contain thousands of photos and we want to avoid having thousands of
- * fragments.</li>
- * <li>The interface {@link OnFragmentPagerListener} and supporting plumbing has been
- * added.</li>
- * </ol>
- */
-public abstract class BaseFragmentPagerAdapter extends PagerAdapter {
- /**
- * Listener for fragment pager events
- */
- public interface OnFragmentPagerListener {
- /**
- * The given fragment has been made the activated fragment.
- */
- public void onPageActivated(Fragment fragment);
- }
-
- /** The default size of {@link #mFragmentCache} */
- private static final int DEFAULT_CACHE_SIZE = 5;
- private static final String TAG = "FragmentPagerAdapter";
- private static final boolean DEBUG = false;
-
- private final FragmentManager mFragmentManager;
- private FragmentTransaction mCurTransaction = null;
- private Fragment mCurrentPrimaryItem = null;
- private OnFragmentPagerListener mPagerListener;
- /** A cache to store detached fragments before they are removed */
- private LruCache<String, Fragment> mFragmentCache = new FragmentCache(DEFAULT_CACHE_SIZE);
-
- public BaseFragmentPagerAdapter(FragmentManager fm) {
- mFragmentManager = fm;
- }
-
- /**
- * Return the Fragment associated with a specified position.
- */
- public abstract Fragment getItem(int position);
-
- @Override
- public void startUpdate(View container) {
- }
-
- @Override
- public Object instantiateItem(View container, int position) {
- if (mCurTransaction == null) {
- mCurTransaction = mFragmentManager.beginTransaction();
- }
-
- // Do we already have this fragment?
- String name = makeFragmentName(container.getId(), position);
-
- // Remove item from the cache
- mFragmentCache.remove(name);
-
- Fragment fragment = mFragmentManager.findFragmentByTag(name);
- if (fragment != null) {
- if (DEBUG) Log.v(TAG, "Attaching item #" + position + ": f=" + fragment);
- mCurTransaction.attach(fragment);
- } else {
- fragment = getItem(position);
- if (DEBUG) Log.v(TAG, "Adding item #" + position + ": f=" + fragment);
- mCurTransaction.add(container.getId(), fragment,
- makeFragmentName(container.getId(), position));
- }
- if (fragment != mCurrentPrimaryItem) {
- fragment.setMenuVisibility(false);
- }
-
- return fragment;
- }
-
- @Override
- public void destroyItem(View container, int position, Object object) {
- if (mCurTransaction == null) {
- mCurTransaction = mFragmentManager.beginTransaction();
- }
- if (DEBUG) Log.v(TAG, "Detaching item #" + position + ": f=" + object
- + " v=" + ((Fragment)object).getView());
-
- Fragment fragment = (Fragment) object;
- String name = fragment.getTag();
- if (name == null) {
- // We prefer to get the name directly from the fragment, but, if the fragment is
- // detached before the add transaction is committed, this could be 'null'. In
- // that case, generate a name so we can still cache the fragment.
- name = makeFragmentName(container.getId(), position);
- }
-
- mFragmentCache.put(name, fragment);
- mCurTransaction.detach(fragment);
- }
-
- @Override
- public void setPrimaryItem(View container, int position, Object object) {
- Fragment fragment = (Fragment) object;
- if (fragment != mCurrentPrimaryItem) {
- if (mCurrentPrimaryItem != null) {
- mCurrentPrimaryItem.setMenuVisibility(false);
- }
- if (fragment != null) {
- fragment.setMenuVisibility(true);
- }
- mCurrentPrimaryItem = fragment;
- }
-
- if (mPagerListener != null) {
- mPagerListener.onPageActivated(fragment);
- }
- }
-
- @Override
- public void finishUpdate(View container) {
- if (mCurTransaction != null) {
- mCurTransaction.commitAllowingStateLoss();
- mCurTransaction = null;
- mFragmentManager.executePendingTransactions();
- }
- }
-
- @Override
- public boolean isViewFromObject(View view, Object object) {
- // Ascend the tree to determine if the view is a child of the fragment
- View root = ((Fragment) object).getView();
- for (Object v = view; v instanceof View; v = ((View) v).getParent()) {
- if (v == root) {
- return true;
- }
- }
- return false;
- }
-
- @Override
- public Parcelable saveState() {
- return null;
- }
-
- @Override
- public void restoreState(Parcelable state, ClassLoader loader) {
- }
-
- /** Sets the fragment pager listener */
- public void setFragmentPagerListener(OnFragmentPagerListener pagerListener) {
- mPagerListener = pagerListener;
- }
-
- /** Creates a name for the fragment */
- protected String makeFragmentName(int viewId, int index) {
- return "android:switcher:" + viewId + ":" + index;
- }
-
- /**
- * A cache of detached fragments.
- */
- private class FragmentCache extends LruCache<String, Fragment> {
- public FragmentCache(int size) {
- super(size);
- }
-
- @Override
- protected void entryRemoved(boolean evicted, String key,
- Fragment oldValue, Fragment newValue) {
- // remove the fragment if it's evicted OR it's replaced by a new fragment
- if (evicted || (newValue != null && oldValue != newValue)) {
- mCurTransaction.remove(oldValue);
- }
- }
- }
-}
diff --git a/src/com/android/mail/photo/adapters/PhotoPagerAdapter.java b/src/com/android/mail/photo/adapters/PhotoPagerAdapter.java
deleted file mode 100644
index befac9d..0000000
--- a/src/com/android/mail/photo/adapters/PhotoPagerAdapter.java
+++ /dev/null
@@ -1,65 +0,0 @@
-/*
- * Copyright (C) 2011 Google Inc.
- * Licensed to 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.mail.photo.adapters;
-
-import android.app.Fragment;
-import android.app.FragmentManager;
-import android.content.Context;
-import android.database.Cursor;
-
-import com.android.mail.photo.Intents;
-import com.android.mail.photo.Intents.PhotoViewIntentBuilder;
-import com.android.mail.photo.fragments.PhotoViewFragment;
-import com.android.mail.photo.provider.PhotoContract;
-
-/**
- * Pager adapter for the photo view
- */
-public class PhotoPagerAdapter extends BaseCursorPagerAdapter {
- private int mContentUriIndex;
- private int mPhotoNameIndex;
-
- public PhotoPagerAdapter(Context context, FragmentManager fm, Cursor c) {
- super(context, fm, c);
- }
-
- @Override
- public Fragment getItem(Context context, Cursor cursor) {
- final String photoUri = cursor.getString(mContentUriIndex);
- final String photoName = cursor.getString(mPhotoNameIndex);
-
- // create new PhotoViewFragment
- final PhotoViewIntentBuilder builder =
- Intents.newPhotoViewFragmentIntentBuilder(mContext);
- builder
- .setPhotoName(photoName)
- .setResolvedPhotoUri(photoUri);
-
- return new PhotoViewFragment(builder.build());
- }
-
- @Override
- public Cursor swapCursor(Cursor newCursor) {
- mContentUriIndex =
- newCursor.getColumnIndex(PhotoContract.PhotoViewColumns.CONTENT_URI);
- mPhotoNameIndex =
- newCursor.getColumnIndex(PhotoContract.PhotoViewColumns.NAME);
-
- return super.swapCursor(newCursor);
- }
-}
diff --git a/src/com/android/mail/photo/fragments/PhotoViewFragment.java b/src/com/android/mail/photo/fragments/PhotoViewFragment.java
deleted file mode 100644
index e3f3034..0000000
--- a/src/com/android/mail/photo/fragments/PhotoViewFragment.java
+++ /dev/null
@@ -1,440 +0,0 @@
-/*
- * Copyright (C) 2011 Google Inc.
- * Licensed to 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.mail.photo.fragments;
-
-import android.app.Activity;
-import android.app.Fragment;
-import android.app.LoaderManager.LoaderCallbacks;
-import android.content.Context;
-import android.content.Intent;
-import android.content.Loader;
-import android.graphics.Bitmap;
-import android.os.Bundle;
-import android.util.DisplayMetrics;
-import android.view.LayoutInflater;
-import android.view.View;
-import android.view.View.OnClickListener;
-import android.view.ViewGroup;
-import android.view.WindowManager;
-import android.widget.ProgressBar;
-import android.widget.Toast;
-
-import com.android.mail.R;
-import com.android.mail.photo.Intents;
-import com.android.mail.photo.PhotoViewActivity.OnScreenListener;
-import com.android.mail.photo.loaders.PhotoBitmapLoader;
-import com.android.mail.photo.util.ImageUtils;
-import com.android.mail.photo.views.PhotoView;
-
-/**
- * Displays a photo.
- */
-public class PhotoViewFragment extends Fragment implements
- LoaderCallbacks<Bitmap>, OnClickListener, OnScreenListener {
-
- /**
- * Interface that activities must implement in order to use this fragment.
- */
- public static interface PhotoViewCallbacks {
- /**
- * Returns true of the given fragment is the currently active fragment.
- */
- public boolean isFragmentActive(Fragment fragment);
-
- /**
- * Called when the given fragment becomes visible.
- */
- public void onFragmentVisible(Fragment fragment);
-
- /**
- * Toggles full screen mode.
- */
- public void toggleFullScreen();
-
- /**
- * Returns {@code true} if full screen mode is enabled for the given fragment.
- * Otherwise, {@code false}.
- */
- public boolean isFragmentFullScreen(Fragment fragment);
-
- /**
- * Adds a full screen listener.
- */
- public void addScreenListener(OnScreenListener listener);
-
- /**
- * Removes a full screen listener.
- */
- public void removeScreenListener(OnScreenListener listener);
-
- /**
- * A photo has been deleted.
- */
- public void onPhotoRemoved(long photoId);
- }
-
- /**
- * Interface for components that are internally scrollable left-to-right.
- */
- public static interface HorizontallyScrollable {
- /**
- * Return {@code true} if the component needs to receive right-to-left
- * touch movements.
- *
- * @param origX the raw x coordinate of the initial touch
- * @param origY the raw y coordinate of the initial touch
- */
-
- public boolean interceptMoveLeft(float origX, float origY);
-
- /**
- * Return {@code true} if the component needs to receive left-to-right
- * touch movements.
- *
- * @param origX the raw x coordinate of the initial touch
- * @param origY the raw y coordinate of the initial touch
- */
- public boolean interceptMoveRight(float origX, float origY);
- }
-
- private final static String STATE_INTENT_KEY =
- "com.android.mail.photo.fragments.PhotoViewFragment.INTENT";
-
- // Loader IDs
- private final static int LOADER_ID_PHOTO = R.id.photo_view_photo_loader_id;
-
- /** The size of the photo */
- public static Integer sPhotoSize;
-
- /** The URL of a photo to display */
- private String mResolvedPhotoUri;
- /** The intent we were launched with */
- private Intent mIntent;
- private PhotoViewCallbacks mCallback;
-
- private PhotoView mPhotoView;
-
- /** Whether or not the fragment should make the photo full-screen */
- private boolean mFullScreen;
-
- public PhotoViewFragment() {
- }
-
- public PhotoViewFragment(Intent intent) {
- this();
- mIntent = intent;
- }
-
- @Override
- public void onAttach(Activity activity) {
- super.onAttach(activity);
- if (activity instanceof PhotoViewCallbacks) {
- mCallback = (PhotoViewCallbacks) activity;
- } else {
- throw new IllegalArgumentException("Activity must implement PhotoViewCallbacks");
- }
-
- if (sPhotoSize == null) {
- final DisplayMetrics metrics = new DisplayMetrics();
- final WindowManager wm =
- (WindowManager) getActivity().getSystemService(Context.WINDOW_SERVICE);
- final ImageUtils.ImageSize imageSize = ImageUtils.sUseImageSize;
- wm.getDefaultDisplay().getMetrics(metrics);
- switch (imageSize) {
- case EXTRA_SMALL: {
- // Use a photo that's 80% of the "small" size
- sPhotoSize = (Math.min(metrics.heightPixels, metrics.widthPixels) * 800) / 1000;
- break;
- }
-
- case SMALL:
- case NORMAL:
- default: {
- sPhotoSize = Math.min(metrics.heightPixels, metrics.widthPixels);
- break;
- }
- }
- }
- }
-
- @Override
- public void onDetach() {
- mCallback = null;
- super.onDetach();
- }
-
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
-
- if (savedInstanceState != null) {
- mIntent = new Intent().putExtras(savedInstanceState.getBundle(STATE_INTENT_KEY));
- }
-
- mResolvedPhotoUri = mIntent.getStringExtra(Intents.EXTRA_RESOLVED_PHOTO_URI);
-
- setHasOptionsMenu(true);
- }
-
- @Override
- public View onCreateView(LayoutInflater inflater, ViewGroup container,
- Bundle savedInstanceState) {
- final View view = inflater.inflate(R.layout.photo_fragment_view, container, false);
-
- mPhotoView = (PhotoView) view.findViewById(R.id.photo_view);
-
- mPhotoView.setPhotoLoading(true);
-
- mPhotoView.setOnClickListener(this);
- mPhotoView.setFullScreen(mFullScreen, false);
-
- // Don't call until we've setup the entire view
- setViewVisibility();
-
- return view;
- }
-
- @Override
- public void onResume() {
- mCallback.addScreenListener(this);
-
- getLoaderManager().initLoader(LOADER_ID_PHOTO, null, this);
-
- super.onResume();
- }
-
- @Override
- public void onPause() {
- super.onPause();
- // Remove listener
- mCallback.removeScreenListener(this);
- resetPhotoView();
- }
-
- @Override
- public void onDestroyView() {
- // Clean up views and other components
- if (mPhotoView != null) {
- mPhotoView.clear();
- mPhotoView = null;
- }
-
- super.onDestroyView();
- }
-
- @Override
- public void onSaveInstanceState(Bundle outState) {
- super.onSaveInstanceState(outState);
-
- if (mIntent != null) {
- outState.putParcelable(STATE_INTENT_KEY, mIntent.getExtras());
- }
- }
-
- @Override
- public Loader<Bitmap> onCreateLoader(int id, Bundle args) {
- if (id == LOADER_ID_PHOTO) {
- return new PhotoBitmapLoader(getActivity(), mResolvedPhotoUri);
- } else {
- return null;
- }
- }
-
- @Override
- public void onLoadFinished(Loader<Bitmap> loader, Bitmap data) {
- // If we don't have a view, the fragment has been paused. We'll get the cursor again later.
- if (getView() == null) {
- return;
- }
-
- final int id = loader.getId();
- if (id == LOADER_ID_PHOTO) {
- if (data == null) {
- Toast.makeText(getActivity(), R.string.photo_view_load_error, Toast.LENGTH_SHORT)
- .show();
- return;
- }
- final View view = getView();
- if (view != null) {
- bindPhoto(data);
- }
-
- setViewVisibility();
- }
- }
-
- /**
- * Binds an image to the photo view.
- */
- private void bindPhoto(Bitmap bitmap) {
- if (mPhotoView != null) {
- mPhotoView.setPhotoLoading(false);
- mPhotoView.bindPhoto(bitmap);
- }
- }
-
- /**
- * Resets the photo view to it's default state w/ no bound photo.
- */
- private void resetPhotoView() {
- if (mPhotoView != null) {
- mPhotoView.setPhotoLoading(true);
- mPhotoView.bindPhoto(null);
- }
- }
-
- @Override
- public void onLoaderReset(Loader<Bitmap> loader) {
- // Do nothing
- }
-
- @Override
- public void onClick(View v) {
- switch (v.getId()) {
- default: {
- if (!isPhotoBound()) {
- // If there is no photo, don't allow any actions except to exit
- // full-screen mode. We want to let the user view comments, etc...
- if (mCallback.isFragmentFullScreen(this)) {
- mCallback.toggleFullScreen();
- }
- break;
- }
-
- // TODO: enable video
- if (isVideo() && mCallback.isFragmentFullScreen(this)) {
- if (isVideoReady()) {
-// final Intent startIntent = Intents.getVideoViewActivityIntent(getActivity(),
-// mAccount, mOwnerId, mPhotoId, mAdapter.getVideoData());
-// startActivity(startIntent);
- } else {
- final String toastText = getString(R.string.photo_view_video_not_ready);
- Toast.makeText(getActivity(), toastText, Toast.LENGTH_LONG).show();
- }
- } else {
- mCallback.toggleFullScreen();
- }
- break;
- }
- }
- }
-
- @Override
- public void onFullScreenChanged(boolean fullScreen, boolean animate) {
- setViewVisibility();
- }
-
- @Override
- public void onViewActivated() {
- if (!mCallback.isFragmentActive(this)) {
- // we're not in the foreground; reset our view
- resetViews();
- } else {
- mCallback.onFragmentVisible(this);
- }
- }
-
- /**
- * Reset the views to their default states
- */
- public void resetViews() {
- if (mPhotoView != null) {
- mPhotoView.resetTransformations();
- }
- }
-
- @Override
- public boolean onInterceptMoveLeft(float origX, float origY) {
- if (!mCallback.isFragmentActive(this)) {
- // we're not in the foreground; don't intercept any touches
- return false;
- }
-
- return (mPhotoView != null && mPhotoView.interceptMoveLeft(origX, origY));
- }
-
- @Override
- public boolean onInterceptMoveRight(float origX, float origY) {
- if (!mCallback.isFragmentActive(this)) {
- // we're not in the foreground; don't intercept any touches
- return false;
- }
-
- return (mPhotoView != null && mPhotoView.interceptMoveRight(origX, origY));
- }
-
- /**
- * Returns {@code true} if a photo has been bound. Otherwise, returns {@code false}.
- */
- public boolean isPhotoBound() {
- return (mPhotoView != null && mPhotoView.isPhotoBound());
- }
-
- /**
- * Returns {@code true} if a photo is loading. Otherwise, returns {@code false}.
- */
- public boolean isPhotoLoading() {
- return (mPhotoView != null && mPhotoView.isPhotoLoading());
- }
-
- /**
- * Returns {@code true} if the photo represents a video. Otherwise, returns {@code false}.
- */
- public boolean isVideo() {
- return (mPhotoView != null && mPhotoView.isVideo());
- }
-
- /**
- * Returns {@code true} if the video is ready to play. Otherwise, returns {@code false}.
- */
- public boolean isVideoReady() {
- return (mPhotoView != null && mPhotoView.isVideoReady());
- }
-
- /**
- * Returns video data for the photo. Otherwise, {@code null} if the photo is not a video.
- */
- public byte[] getVideoData() {
- return (mPhotoView == null ? null : mPhotoView.getVideoData());
- }
-
- /**
- * Sets the progress bar.
- */
- @Override
- public void onUpdateProgressView(ProgressBar progressBarView) {
- }
-
- /**
- * Sets view visibility depending upon whether or not we're in "full screen" mode.
- */
- private void setViewVisibility() {
- final boolean fullScreen = mCallback.isFragmentFullScreen(this);
- final boolean hide = fullScreen;
-
- setFullScreen(hide);
- }
-
- /**
- * Sets full-screen mode for the views.
- */
- public void setFullScreen(boolean fullScreen) {
- mFullScreen = fullScreen;
- mPhotoView.enableImageTransforms(true);
- }
-}
diff --git a/src/com/android/mail/photo/loaders/PhotoBitmapLoader.java b/src/com/android/mail/photo/loaders/PhotoBitmapLoader.java
deleted file mode 100644
index 1169df4..0000000
--- a/src/com/android/mail/photo/loaders/PhotoBitmapLoader.java
+++ /dev/null
@@ -1,151 +0,0 @@
-/*
- * Copyright (C) 2011 Google Inc.
- * Licensed to 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.mail.photo.loaders;
-
-import android.content.AsyncTaskLoader;
-import android.content.ContentResolver;
-import android.content.Context;
-import android.graphics.Bitmap;
-import android.net.Uri;
-
-import com.android.mail.photo.fragments.PhotoViewFragment;
-import com.android.mail.photo.util.ImageUtils;
-
-/**
- * Loader for the bitmap of a photo.
- */
-public class PhotoBitmapLoader extends AsyncTaskLoader<Bitmap> {
- private final String mPhotoUri;
-
- private Bitmap mBitmap;
-
- public PhotoBitmapLoader(Context context, String photoUri) {
- super(context);
- mPhotoUri = photoUri;
- }
-
- @Override
- public Bitmap loadInBackground() {
- Context context = getContext();
-
- if (context != null && mPhotoUri != null) {
- final ContentResolver resolver = context.getContentResolver();
- return ImageUtils.createLocalBitmap(resolver, Uri.parse(mPhotoUri),
- PhotoViewFragment.sPhotoSize);
- }
-
- return null;
- }
-
- /**
- * Called when there is new data to deliver to the client. The
- * super class will take care of delivering it; the implementation
- * here just adds a little more logic.
- */
- @Override
- public void deliverResult(Bitmap bitmap) {
- if (isReset()) {
- // An async query came in while the loader is stopped. We
- // don't need the result.
- if (bitmap != null) {
- onReleaseResources(bitmap);
- }
- }
- Bitmap oldBitmap = mBitmap;
- mBitmap = bitmap;
-
- if (isStarted()) {
- // If the Loader is currently started, we can immediately
- // deliver its results.
- super.deliverResult(bitmap);
- }
-
- // At this point we can release the resources associated with
- // 'oldBitmap' if needed; now that the new result is delivered we
- // know that it is no longer in use.
- if (oldBitmap != null && oldBitmap != bitmap && !oldBitmap.isRecycled()) {
- onReleaseResources(oldBitmap);
- }
- }
-
- /**
- * Handles a request to start the Loader.
- */
- @Override
- protected void onStartLoading() {
- if (mBitmap != null) {
- // If we currently have a result available, deliver it
- // immediately.
- deliverResult(mBitmap);
- }
-
- if (takeContentChanged() || mBitmap == null) {
- // If the data has changed since the last time it was loaded
- // or is not currently available, start a load.
- forceLoad();
- }
- }
-
- /**
- * Handles a request to stop the Loader.
- */
- @Override protected void onStopLoading() {
- // Attempt to cancel the current load task if possible.
- cancelLoad();
- }
-
- /**
- * Handles a request to cancel a load.
- */
- @Override
- public void onCanceled(Bitmap bitmap) {
- super.onCanceled(bitmap);
-
- // At this point we can release the resources associated with 'bitmap'
- // if needed.
- onReleaseResources(bitmap);
- }
-
- /**
- * Handles a request to completely reset the Loader.
- */
- @Override
- protected void onReset() {
- super.onReset();
-
- // Ensure the loader is stopped
- onStopLoading();
-
- // At this point we can release the resources associated with 'bitmap'
- // if needed.
- if (mBitmap != null) {
- onReleaseResources(mBitmap);
- mBitmap = null;
- }
- }
-
- /**
- * Helper function to take care of releasing resources associated
- * with an actively loaded data set.
- */
- protected void onReleaseResources(Bitmap bitmap) {
- if (bitmap != null && !bitmap.isRecycled()) {
- bitmap.recycle();
- }
- }
-}
diff --git a/src/com/android/mail/photo/loaders/PhotoPagerLoader.java b/src/com/android/mail/photo/loaders/PhotoPagerLoader.java
deleted file mode 100644
index 70bd204..0000000
--- a/src/com/android/mail/photo/loaders/PhotoPagerLoader.java
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * Copyright (C) 2011 Google Inc.
- * Licensed to 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.mail.photo.loaders;
-
-import android.content.Context;
-import android.content.CursorLoader;
-import android.database.Cursor;
-import android.net.Uri;
-
-import com.android.mail.photo.provider.PhotoContract;
-
-/**
- * Loader for a set of photo IDs.
- */
-public class PhotoPagerLoader extends CursorLoader {
- private final Uri mPhotosUri;
- private final String[] mProjection;
-
- public PhotoPagerLoader(
- Context context, Uri photosUri, String[] projection) {
- super(context);
- mPhotosUri = photosUri;
- mProjection = projection != null ? projection : PhotoContract.PhotoQuery.PROJECTION;
- }
-
- @Override
- public Cursor loadInBackground() {
- Cursor returnCursor = null;
-
- final Uri loaderUri = mPhotosUri.buildUpon().appendQueryParameter(
- PhotoContract.ContentTypeParameters.CONTENT_TYPE, "image/").build();
- setUri(loaderUri);
- setProjection(mProjection);
- returnCursor = super.loadInBackground();
-
- return returnCursor;
- }
-}
diff --git a/src/com/android/mail/photo/provider/PhotoContract.java b/src/com/android/mail/photo/provider/PhotoContract.java
deleted file mode 100644
index 76c62a7..0000000
--- a/src/com/android/mail/photo/provider/PhotoContract.java
+++ /dev/null
@@ -1,72 +0,0 @@
-/*
- * Copyright (C) 2011 Google Inc.
- * Licensed to 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.mail.photo.provider;
-
-import android.net.Uri;
-import android.provider.OpenableColumns;
-
-public final class PhotoContract {
- /** Columns for the view {@link #PHOTO_VIEW} */
- public static interface PhotoViewColumns {
- /**
- * This column is a {@link Uri} that can be queried
- * for this individual image (resulting cursor has one single row for this image).
- */
- public static final String URI = "uri";
- /**
- * This column is a {@link String} that can be queried for this
- * individual image to return a displayable name.
- */
- public static final String NAME = OpenableColumns.DISPLAY_NAME;
- /**
- * This column is a {@link Uri} that points to the downloaded local file
- * This value is undefined in any other state.
- */
- public static final String CONTENT_URI = "contentUri";
- /**
- * This string column is the MIME type.
- */
- public static final String CONTENT_TYPE = "contentType";
-
- }
-
- public static interface PhotoQuery {
- /** Projection of the returned cursor */
- public final static String[] PROJECTION = {
- PhotoViewColumns.URI,
- PhotoViewColumns.NAME,
- PhotoViewColumns.CONTENT_URI,
- PhotoViewColumns.CONTENT_TYPE,
- };
-
- public final static int INDEX_URI = 0;
- public final static int INDEX_NAME = 1;
- public final static int INDEX_CONTENT_URI = 2;
- public final static int INDEX_CONTENT_TYPE = 3;
- }
-
- public static final class ContentTypeParameters {
- /**
- * Parameter used to specify which type of content to return.
- * Allows multiple types to be specified.
- */
- public static final String CONTENT_TYPE = "contentType";
-
- private ContentTypeParameters() {}
- }
-}
diff --git a/src/com/android/mail/photo/util/ImageUtils.java b/src/com/android/mail/photo/util/ImageUtils.java
deleted file mode 100644
index 98edacb..0000000
--- a/src/com/android/mail/photo/util/ImageUtils.java
+++ /dev/null
@@ -1,173 +0,0 @@
-/*
- * Copyright (C) 2011 Google Inc.
- * Licensed to 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.mail.photo.util;
-
-import android.content.ContentResolver;
-import android.graphics.Bitmap;
-import android.graphics.BitmapFactory;
-import android.graphics.Point;
-import android.graphics.Rect;
-import android.net.Uri;
-import android.os.Build;
-import android.util.Log;
-
-import com.android.mail.photo.PhotoViewActivity;
-
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.io.InputStream;
-
-/**
- * Image utilities
- */
-public class ImageUtils {
- // Logging
- private static final String TAG = "ImageUtils";
-
- /** Minimum class memory class to use full-res photos */
- private final static long MIN_NORMAL_CLASS = 32;
- /** Minimum class memory class to use small photos */
- private final static long MIN_SMALL_CLASS = 24;
-
- public static enum ImageSize {
- EXTRA_SMALL,
- SMALL,
- NORMAL,
- }
-
- public static final ImageSize sUseImageSize;
- static {
- // On HC and beyond, assume devices are more capable
- if (Build.VERSION.SDK_INT >= 11) {
- sUseImageSize = ImageSize.NORMAL;
- } else {
- if (PhotoViewActivity.sMemoryClass >= MIN_NORMAL_CLASS) {
- // We have plenty of memory; use full sized photos
- sUseImageSize = ImageSize.NORMAL;
- } else if (PhotoViewActivity.sMemoryClass >= MIN_SMALL_CLASS) {
- // We have slight less memory; use smaller sized photos
- sUseImageSize = ImageSize.SMALL;
- } else {
- // We have little memory; use very small sized photos
- sUseImageSize = ImageSize.EXTRA_SMALL;
- }
- }
- }
-
- /**
- * @return true if the MimeType type is image
- */
- public static boolean isImageMimeType(String mimeType) {
- return mimeType != null && mimeType.startsWith("image/");
- }
-
- /**
- * Create a bitmap from a local URI
- *
- * @param resolver The ContentResolver
- * @param uri The local URI
- * @param maxSize The maximum size (either width or height)
- *
- * @return The new bitmap
- */
- public static Bitmap createLocalBitmap(ContentResolver resolver, Uri uri, int maxSize) {
- InputStream inputStream = null;
- try {
- final BitmapFactory.Options opts = new BitmapFactory.Options();
- final Point bounds = getImageBounds(resolver, uri);
-
- inputStream = resolver.openInputStream(uri);
- opts.inSampleSize = Math.max(bounds.x / maxSize, bounds.y / maxSize);
-
- final Bitmap decodedBitmap = decodeStream(inputStream, null, opts);
-
- // Correct thumbnail orientation as necessary
- // TODO: Fix rotation if it's actually a problem
- //return rotateBitmap(resolver, uri, decodedBitmap);
- return decodedBitmap;
-
- } catch (FileNotFoundException exception) {
- // Do nothing - the photo will appear to be missing
- } catch (IOException exception) {
- // Do nothing - the photo will appear to be missing
- } finally {
- try {
- if (inputStream != null) {
- inputStream.close();
- }
- } catch (IOException ignore) {
- }
- }
- return null;
- }
-
- /**
- * Wrapper around {@link BitmapFactory#decodeStream(InputStream, Rect,
- * BitmapFactory.Options)} that returns {@code null} on {@link
- * OutOfMemoryError}.
- *
- * @param is The input stream that holds the raw data to be decoded into a
- * bitmap.
- * @param outPadding If not null, return the padding rect for the bitmap if
- * it exists, otherwise set padding to [-1,-1,-1,-1]. If
- * no bitmap is returned (null) then padding is
- * unchanged.
- * @param opts null-ok; Options that control downsampling and whether the
- * image should be completely decoded, or just is size returned.
- * @return The decoded bitmap, or null if the image data could not be
- * decoded, or, if opts is non-null, if opts requested only the
- * size be returned (in opts.outWidth and opts.outHeight)
- */
- public static Bitmap decodeStream(InputStream is, Rect outPadding, BitmapFactory.Options opts) {
- try {
- return BitmapFactory.decodeStream(is, outPadding, opts);
- } catch (OutOfMemoryError oome) {
- Log.e(TAG, "ImageUtils#decodeStream(InputStream, Rect, Options) threw an OOME", oome);
- return null;
- }
- }
-
- /**
- * Gets the image bounds
- *
- * @param resolver The ContentResolver
- * @param uri The uri
- *
- * @return The image bounds
- */
- private static Point getImageBounds(ContentResolver resolver, Uri uri)
- throws IOException {
- final BitmapFactory.Options opts = new BitmapFactory.Options();
- InputStream inputStream = null;
-
- try {
- opts.inJustDecodeBounds = true;
- inputStream = resolver.openInputStream(uri);
- decodeStream(inputStream, null, opts);
-
- return new Point(opts.outWidth, opts.outHeight);
- } finally {
- try {
- if (inputStream != null) {
- inputStream.close();
- }
- } catch (IOException ignore) {
- }
- }
- }
-}
diff --git a/src/com/android/mail/photo/views/PhotoView.java b/src/com/android/mail/photo/views/PhotoView.java
deleted file mode 100644
index 8538401..0000000
--- a/src/com/android/mail/photo/views/PhotoView.java
+++ /dev/null
@@ -1,1325 +0,0 @@
-/*
- * Copyright (C) 2011 Google Inc.
- * Licensed to 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.mail.photo.views;
-
-import android.content.Context;
-import android.content.pm.PackageManager;
-import android.content.res.Resources;
-import android.graphics.Bitmap;
-import android.graphics.Canvas;
-import android.graphics.Matrix;
-import android.graphics.Paint;
-import android.graphics.Paint.Style;
-import android.graphics.Rect;
-import android.graphics.RectF;
-import android.graphics.drawable.BitmapDrawable;
-import android.util.AttributeSet;
-import android.view.GestureDetector;
-import android.view.MotionEvent;
-import android.view.ScaleGestureDetector;
-import android.view.View;
-
-import com.android.mail.R;
-import com.android.mail.photo.fragments.PhotoViewFragment.HorizontallyScrollable;
-
-/**
- * Layout for the photo list view header.
- */
-public class PhotoView extends View implements GestureDetector.OnGestureListener,
- GestureDetector.OnDoubleTapListener, ScaleGestureDetector.OnScaleGestureListener,
- HorizontallyScrollable {
- /** Zoom animation duration; in milliseconds */
- private final static long ZOOM_ANIMATION_DURATION = 300L;
- /** Rotate animation duration; in milliseconds */
- private final static long ROTATE_ANIMATION_DURATION = 500L;
- /** Snap animation duration; in milliseconds */
- private static final long SNAP_DURATION = 100L;
- /** Amount of time to wait before starting snap animation; in milliseconds */
- private static final long SNAP_DELAY = 250L;
- /** By how much to scale the image when double click occurs */
- private final static float DOUBLE_TAP_SCALE_FACTOR = 1.5f;
- /** Amount of translation needed before starting a snap animation */
- private final static float SNAP_THRESHOLD = 20.0f;
- /** The width & height of the bitmap returned by {@link #getCroppedPhoto()} */
- private final static float CROPPED_SIZE = 256.0f;
-
- /** If {@code true}, the static values have been initialized */
- private static boolean sInitialized;
-
- // Various dimensions
- /** Width & height of the crop region */
- private static int sCropSize;
-
- // Bitmaps
- /** Video icon */
- private static Bitmap sVideoImage;
- /** Video icon */
- private static Bitmap sVideoNotReadyImage;
-
- // Features
- private static boolean sHasMultitouchDistinct;
-
- // Paints
- /** Paint to partially dim the photo during crop */
- private static Paint sCropDimPaint;
- /** Paint to highlight the cropped portion of the photo */
- private static Paint sCropPaint;
-
- // Colours
- /** The colour of the header background */
- private static int sBackgroundColor;
-
- /** The photo to display */
- private BitmapDrawable mDrawable;
- /** Whether or not the photo is in the process of loading */
- private boolean mLoading;
- /** The matrix used for drawing; this may be {@code null} */
- private Matrix mDrawMatrix;
- /** A matrix to apply the scaling of the photo */
- private Matrix mMatrix = new Matrix();
- /** The original matrix for this image; used to reset any transformations applied by the user */
- private Matrix mOriginalMatrix = new Matrix();
-
- /** The fixed height of this view. If {@code -1}, calculate the height */
- private int mFixedHeight = -1;
- /** When {@code true}, the view has been laid out */
- private boolean mHaveLayout;
- /** Whether or not the photo is full-screen */
- private boolean mFullScreen;
- /** Whether or not this is a still image of a video */
- private byte[] mVideoBlob;
- /** Whether or not this is a still image of a video */
- private boolean mVideoReady;
-
- /** Whether or not crop is allowed */
- private boolean mAllowCrop;
- /** The crop region */
- private Rect mCropRect = new Rect();
- /** Actual crop size; may differ from {@link #sCropSize} if the screen is smaller */
- private int mCropSize;
-
- /** Gesture detector */
- private GestureDetector mGestureDetector;
- /** Gesture detector that detects pinch gestures */
- private ScaleGestureDetector mScaleGetureDetector;
- /** An external click listener */
- private OnClickListener mExternalClickListener;
- /** When {@code true}, allows gestures to scale / pan the image */
- private boolean mTransformsEnabled;
-
- // To support zooming
- /** When {@code true}, a double tap scales the image by {@link #DOUBLE_TAP_SCALE_FACTOR} */
- private boolean mDoubleTapToZoomEnabled = true;
- /** When {@code true}, prevents scale end gesture from falsely triggering a double click. */
- private boolean mDoubleTapDebounce;
- /** When {@code false}, event is a scale gesture. Otherwise, event is a double touch. */
- private boolean mIsDoubleTouch;
- /** Runnable that scales the image */
- private ScaleRunnable mScaleRunnable;
- /** Minimum scale the image can have. */
- private float mMinScale;
- /** Maximum scale to limit scaling to, 0 means no limit. */
- private float mMaxScale;
- /** When {@code true}, prevents scale end gesture from falsely triggering a fling. */
- private boolean mFlingDebounce;
- /** When {@code true}, prevents scale end gesture from falsely triggering a scroll. */
- private boolean mScrollDebounce;
-
- // To support translation [i.e. panning]
- /** Runnable that can move the image */
- private TranslateRunnable mTranslateRunnable;
- private SnapRunnable mSnapRunnable;
-
- // To support rotation
- /** The rotate runnable used to animate rotations of the image */
- private RotateRunnable mRotateRunnable;
- /** The current rotation amount, in degrees */
- private float mRotation;
-
- // Convenience fields
- // These are declared here not because they are important properties of the view. Rather, we
- // declare them here to avoid object allocation during critical graphics operations; such as
- // layout or drawing.
- /** Source (i.e. the photo size) bounds */
- private RectF mTempSrc = new RectF();
- /** Destination (i.e. the display) bounds. The image is scaled to this size. */
- private RectF mTempDst = new RectF();
- /** Rectangle to handle translations */
- private RectF mTranslateRect = new RectF();
- /** Array to store a copy of the matrix values */
- private float[] mValues = new float[9];
-
- public PhotoView(Context context) {
- super(context);
- initialize();
- }
-
- public PhotoView(Context context, AttributeSet attrs) {
- super(context, attrs);
- initialize();
- }
-
- public PhotoView(Context context, AttributeSet attrs, int defStyle) {
- super(context, attrs, defStyle);
- initialize();
- }
-
- @Override
- public boolean onTouchEvent(MotionEvent event) {
- if (mScaleGetureDetector == null || mGestureDetector == null) {
- // We're being destroyed; ignore any touch events
- return true;
- }
-
- mScaleGetureDetector.onTouchEvent(event);
- mGestureDetector.onTouchEvent(event);
- final int action = event.getAction();
-
- switch (action) {
- case MotionEvent.ACTION_UP:
- case MotionEvent.ACTION_CANCEL:
- if (!mTranslateRunnable.mRunning) {
- snap();
- }
- break;
- }
-
- return true;
- }
-
- @Override
- public boolean onDoubleTap(MotionEvent e) {
- if (mDoubleTapToZoomEnabled && mTransformsEnabled) {
- if (!mDoubleTapDebounce) {
- float currentScale = getScale();
- float targetScale = currentScale * DOUBLE_TAP_SCALE_FACTOR;
-
- // Ensure the target scale is within our bounds
- targetScale = Math.max(mMinScale, targetScale);
- targetScale = Math.min(mMaxScale, targetScale);
-
- mScaleRunnable.start(currentScale, targetScale, e.getX(), e.getY());
- }
- mDoubleTapDebounce = false;
- }
- return true;
- }
-
- @Override
- public boolean onDoubleTapEvent(MotionEvent e) {
- return true;
- }
-
- @Override
- public boolean onSingleTapConfirmed(MotionEvent e) {
- if (mExternalClickListener != null && !mIsDoubleTouch) {
- mExternalClickListener.onClick(this);
- }
- mIsDoubleTouch = false;
- return true;
- }
-
- @Override
- public boolean onSingleTapUp(MotionEvent e) {
- return false;
- }
-
- @Override
- public void onLongPress(MotionEvent e) {
- }
-
- @Override
- public void onShowPress(MotionEvent e) {
- }
-
- @Override
- public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
- if (mTransformsEnabled) {
- if (!mScrollDebounce) {
- translate(-distanceX, -distanceY);
- }
- mScrollDebounce = false;
- }
- return true;
- }
-
- @Override
- public boolean onDown(MotionEvent e) {
- if (mTransformsEnabled) {
- mTranslateRunnable.stop();
- mSnapRunnable.stop();
- }
- return true;
- }
-
- @Override
- public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
- if (mTransformsEnabled) {
- if (!mFlingDebounce) {
- mTranslateRunnable.start(velocityX, velocityY);
- }
- mFlingDebounce = false;
- }
- return true;
- }
-
- @Override
- public boolean onScale(ScaleGestureDetector detector) {
- if (mTransformsEnabled) {
- mIsDoubleTouch = false;
- float currentScale = getScale();
- float newScale = currentScale * detector.getScaleFactor();
- scale(newScale, detector.getFocusX(), detector.getFocusY());
- }
- return true;
- }
-
- @Override
- public boolean onScaleBegin(ScaleGestureDetector detector) {
- if (mTransformsEnabled) {
- mScaleRunnable.stop();
- mIsDoubleTouch = true;
- }
- return true;
- }
-
- @Override
- public void onScaleEnd(ScaleGestureDetector detector) {
- if (mTransformsEnabled && mIsDoubleTouch) {
- mDoubleTapDebounce = true;
- resetTransformations();
- }
- mFlingDebounce = true;
- mScrollDebounce = true;
- }
-
- @Override
- public void setOnClickListener(OnClickListener listener) {
- mExternalClickListener = listener;
- }
-
- @Override
- public boolean interceptMoveLeft(float origX, float origY) {
- if (!mTransformsEnabled) {
- // Allow intercept if we're not in transform mode
- return false;
- } else if (mTranslateRunnable.mRunning) {
- // Don't allow touch intercept until we've stopped flinging
- return true;
- } else {
- mMatrix.getValues(mValues);
- mTranslateRect.set(mTempSrc);
- mMatrix.mapRect(mTranslateRect);
-
- final float viewWidth = getWidth();
- final float transX = mValues[Matrix.MTRANS_X];
- final float drawWidth = mTranslateRect.right - mTranslateRect.left;
-
- if (!mTransformsEnabled || drawWidth <= viewWidth) {
- // Allow intercept if not in transform mode or the image is smaller than the view
- return false;
- } else if (transX == 0) {
- // We're at the left-side of the image; allow intercepting movements to the right
- return false;
- } else if (viewWidth >= drawWidth + transX) {
- // We're at the right-side of the image; allow intercepting movements to the left
- return true;
- } else {
- // We're in the middle of the image; don't allow touch intercept
- return true;
- }
- }
- }
-
- @Override
- public boolean interceptMoveRight(float origX, float origY) {
- if (!mTransformsEnabled) {
- // Allow intercept if we're not in transform mode
- return false;
- } else if (mTranslateRunnable.mRunning) {
- // Don't allow touch intercept until we've stopped flinging
- return true;
- } else {
- mMatrix.getValues(mValues);
- mTranslateRect.set(mTempSrc);
- mMatrix.mapRect(mTranslateRect);
-
- final float viewWidth = getWidth();
- final float transX = mValues[Matrix.MTRANS_X];
- final float drawWidth = mTranslateRect.right - mTranslateRect.left;
-
- if (!mTransformsEnabled || drawWidth <= viewWidth) {
- // Allow intercept if not in transform mode or the image is smaller than the view
- return false;
- } else if (transX == 0) {
- // We're at the left-side of the image; allow intercepting movements to the right
- return true;
- } else if (viewWidth >= drawWidth + transX) {
- // We're at the right-side of the image; allow intercepting movements to the left
- return false;
- } else {
- // We're in the middle of the image; don't allow touch intercept
- return true;
- }
- }
- }
-
- /**
- * Free all resources held by this view.
- * The view is on its way to be collected and will not be reused.
- */
- public void clear() {
- mGestureDetector = null;
- mScaleGetureDetector = null;
- mDrawable = null;
- mScaleRunnable.stop();
- mScaleRunnable = null;
- mTranslateRunnable.stop();
- mTranslateRunnable = null;
- mSnapRunnable.stop();
- mSnapRunnable = null;
- mRotateRunnable.stop();
- mRotateRunnable = null;
- setOnClickListener(null);
- mExternalClickListener = null;
- }
-
- /**
- * Binds a bitmap to the view.
- *
- * @param photoBitmap the bitmap to bind.
- */
- public void bindPhoto(Bitmap photoBitmap) {
- boolean changed = false;
- if (mDrawable != null) {
- final Bitmap drawableBitmap = mDrawable.getBitmap();
- if (photoBitmap == drawableBitmap) {
- // setting the same bitmap; do nothing
- return;
- }
-
- changed = photoBitmap != null &&
- (mDrawable.getIntrinsicWidth() != photoBitmap.getWidth() ||
- mDrawable.getIntrinsicHeight() != photoBitmap.getHeight());
-
- // Reset mMinScale to ensure the bounds / matrix are recalculated
- mMinScale = 0f;
- mDrawable = null;
- }
-
- if (mDrawable == null && photoBitmap != null) {
- mDrawable = new BitmapDrawable(getResources(), photoBitmap);
- }
-
- configureBounds(changed);
- invalidate();
- }
-
- /**
- * Returns the bound photo data if set. Otherwise, {@code null}.
- */
- public Bitmap getPhoto() {
- if (mDrawable != null) {
- return mDrawable.getBitmap();
- }
- return null;
- }
-
- /**
- * Gets video data associated with this item. Returns {@code null} if this is not a video.
- */
- public byte[] getVideoData() {
- return mVideoBlob;
- }
-
- /**
- * Returns {@code true} if the photo represents a video. Otherwise, {@code false}.
- */
- public boolean isVideo() {
- return mVideoBlob != null;
- }
-
- /**
- * Returns {@code true} if the video is ready to play. Otherwise, {@code false}.
- */
- public boolean isVideoReady() {
- return mVideoBlob != null && mVideoReady;
- }
-
- /**
- * Returns {@code true} if a photo has been bound. Otherwise, {@code false}.
- */
- public boolean isPhotoBound() {
- return mDrawable != null;
- }
-
- /**
- * Returns {@code true} if a photo has been bound. Otherwise, {@code false}.
- */
- public boolean isPhotoLoading() {
- return mLoading;
- }
-
- /**
- * Sets whether the photo is being loaded.
- */
- public void setPhotoLoading(boolean loading) {
- mLoading = loading;
- }
-
- /**
- * Hides the photo info portion of the header. As a side effect, this automatically enables
- * or disables image transformations [eg zoom, pan, etc...] depending upon the value of
- * fullScreen. If this is not desirable, enable / disable image transformations manually.
- */
- public void setFullScreen(boolean fullScreen, boolean animate) {
- if (fullScreen != mFullScreen) {
- mFullScreen = fullScreen;
- requestLayout();
- invalidate();
- }
- }
-
- /**
- * Enable or disable cropping of the displayed image. Cropping can only be enabled
- * <em>before</em> the view has been laid out. Additionally, once cropping has been
- * enabled, it cannot be disabled.
- */
- public void enableAllowCrop(boolean allowCrop) {
- if (allowCrop && mHaveLayout) {
- throw new IllegalArgumentException("Cannot set crop after view has been laid out");
- }
- if (!allowCrop && mAllowCrop) {
- throw new IllegalArgumentException("Cannot unset crop mode");
- }
- mAllowCrop = allowCrop;
- }
-
- /**
- * Gets a bitmap of the cropped region. If cropping is not enabled, returns {@code null}.
- */
- public Bitmap getCroppedPhoto() {
- if (!mAllowCrop) {
- return null;
- }
-
- final Bitmap croppedBitmap = Bitmap.createBitmap(
- (int) CROPPED_SIZE, (int) CROPPED_SIZE, Bitmap.Config.ARGB_8888);
- final Canvas croppedCanvas = new Canvas(croppedBitmap);
-
- // scale for the final dimensions
- final int cropWidth = mCropRect.right - mCropRect.left;
- final float scaleWidth = CROPPED_SIZE / cropWidth;
- final float scaleHeight = CROPPED_SIZE / cropWidth;
-
- // translate to the origin & scale
- final Matrix matrix = new Matrix(mDrawMatrix);
- matrix.postTranslate(-mCropRect.left, -mCropRect.top);
- matrix.postScale(scaleWidth, scaleHeight);
-
- // Set the background to black
- croppedCanvas.drawColor(sBackgroundColor);
-
- // draw the photo
- if (mDrawable != null) {
- croppedCanvas.concat(matrix);
- mDrawable.draw(croppedCanvas);
- }
- return croppedBitmap;
- }
-
- /**
- * Resets the image transformation to its original value.
- */
- public void resetTransformations() {
- // snap transformations; we don't animate
- mMatrix.set(mOriginalMatrix);
-
- // Invalidate the view because if you move off this PhotoHeaderView
- // to another one and come back, you want it to draw from scratch
- // in case you were zoomed in or translated (since those settings
- // are not preserved and probably shouldn't be).
- invalidate();
- }
-
- /**
- * Rotates the image 90 degrees, clockwise.
- */
- public void rotateClockwise() {
- rotate(90, true);
- }
-
- /**
- * Rotates the image 90 degrees, counter clockwise.
- */
- public void rotateCounterClockwise() {
- rotate(-90, true);
- }
-
- @Override
- protected void onDraw(Canvas canvas) {
- super.onDraw(canvas);
- // Set the background to black
- canvas.drawColor(sBackgroundColor);
-
- // draw the photo
- if (mDrawable != null) {
- int saveCount = canvas.getSaveCount();
- canvas.save();
-
- if (mDrawMatrix != null) {
- canvas.concat(mDrawMatrix);
- }
- mDrawable.draw(canvas);
-
- canvas.restoreToCount(saveCount);
-
- if (mVideoBlob != null) {
- final Bitmap videoImage = (mVideoReady ? sVideoImage : sVideoNotReadyImage);
- final int drawLeft = (getWidth() - videoImage.getWidth()) / 2;
- final int drawTop = (getHeight() - videoImage.getHeight()) / 2;
- canvas.drawBitmap(videoImage, drawLeft, drawTop, null);
- }
-
- // Extract the drawable's bounds (in our own copy, to not alter the image)
- mTranslateRect.set(mDrawable.getBounds());
- if (mDrawMatrix != null) {
- mDrawMatrix.mapRect(mTranslateRect);
- }
-
- if (mAllowCrop) {
- int previousSaveCount = canvas.getSaveCount();
- canvas.drawRect(0, 0, getWidth(), getHeight(), sCropDimPaint);
- canvas.save();
- canvas.clipRect(mCropRect);
-
- if (mDrawMatrix != null) {
- canvas.concat(mDrawMatrix);
- }
-
- mDrawable.draw(canvas);
- canvas.restoreToCount(previousSaveCount);
- canvas.drawRect(mCropRect, sCropPaint);
- }
- }
- }
-
- @Override
- protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
- super.onLayout(changed, left, top, right, bottom);
- mHaveLayout = true;
- final int layoutWidth = getWidth();
- final int layoutHeight = getHeight();
-
- if (mAllowCrop) {
- mCropSize = Math.min(sCropSize, Math.min(layoutWidth, layoutHeight));
- final int cropLeft = (layoutWidth - mCropSize) / 2;
- final int cropTop = (layoutHeight - mCropSize) / 2;
- final int cropRight = cropLeft + mCropSize;
- final int cropBottom = cropTop + mCropSize;
-
- // Create a crop region overlay. We need a separate canvas to be able to "punch
- // a hole" through to the underlying image.
- mCropRect.set(cropLeft, cropTop, cropRight, cropBottom);
- }
- configureBounds(changed);
- }
-
- @Override
- protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
- if (mFixedHeight != -1) {
- super.onMeasure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(mFixedHeight,
- MeasureSpec.AT_MOST));
- setMeasuredDimension(getMeasuredWidth(), mFixedHeight);
- } else {
- super.onMeasure(widthMeasureSpec, heightMeasureSpec);
- }
- }
-
- /**
- * Forces a fixed height for this view.
- *
- * @param fixedHeight The height. If {@code -1}, use the measured height.
- */
- public void setFixedHeight(int fixedHeight) {
- final boolean adjustBounds = (fixedHeight != mFixedHeight);
- mFixedHeight = fixedHeight;
- setMeasuredDimension(getMeasuredWidth(), mFixedHeight);
- if (adjustBounds) {
- configureBounds(true);
- requestLayout();
- }
- }
-
- /**
- * Enable or disable image transformations. When transformations are enabled, this view
- * consumes all touch events.
- */
- public void enableImageTransforms(boolean enable) {
- mTransformsEnabled = enable;
- if (!mTransformsEnabled) {
- resetTransformations();
- }
- }
-
- /**
- * Configures the bounds of the photo. The photo will always be scaled to fit center.
- */
- private void configureBounds(boolean changed) {
- if (mDrawable == null || !mHaveLayout) {
- return;
- }
- final int dwidth = mDrawable.getIntrinsicWidth();
- final int dheight = mDrawable.getIntrinsicHeight();
-
- final int vwidth = getWidth();
- final int vheight = getHeight();
-
- final boolean fits = (dwidth < 0 || vwidth == dwidth) &&
- (dheight < 0 || vheight == dheight);
-
- // We need to do the scaling ourself, so have the drawable use its native size.
- mDrawable.setBounds(0, 0, dwidth, dheight);
-
- // Create a matrix with the proper transforms
- if (changed || (mMinScale == 0 && mDrawable != null && mHaveLayout)) {
- generateMatrix();
- generateScale();
- }
-
- if (fits || mMatrix.isIdentity()) {
- // The bitmap fits exactly, no transform needed.
- mDrawMatrix = null;
- } else {
- mDrawMatrix = mMatrix;
- }
- }
-
- /**
- * Generates the initial transformation matrix for drawing. Additionally, it sets the
- * minimum and maximum scale values.
- */
- private void generateMatrix() {
- final int dwidth = mDrawable.getIntrinsicWidth();
- final int dheight = mDrawable.getIntrinsicHeight();
-
- final int vwidth = mAllowCrop ? sCropSize : getWidth();
- final int vheight = mAllowCrop ? sCropSize : getHeight();
-
- final boolean fits = (dwidth < 0 || vwidth == dwidth) &&
- (dheight < 0 || vheight == dheight);
-
- // Set the matrix to fill the screen
- if (fits && !mAllowCrop) {
- mMatrix.reset();
- } else {
- // Generate the required transforms for the photo
- mTempSrc.set(0, 0, dwidth, dheight);
- if (mAllowCrop) {
- mTempDst.set(mCropRect);
- } else {
- mTempDst.set(0, 0, vwidth, vheight);
- }
- mMatrix.setRectToRect(mTempSrc, mTempDst, Matrix.ScaleToFit.CENTER);
- }
- mOriginalMatrix.set(mMatrix);
- }
-
- private void generateScale() {
- final int dwidth = mDrawable.getIntrinsicWidth();
- final int dheight = mDrawable.getIntrinsicHeight();
-
- final int vwidth = mAllowCrop ? getCropSize() : getWidth();
- final int vheight = mAllowCrop ? getCropSize() : getHeight();
-
- if (dwidth < vwidth && dheight < vheight && !mAllowCrop) {
- mMinScale = 1.0f;
- } else {
- mMinScale = getScale();
- }
- mMaxScale = Math.max(mMinScale * 8, 8);
- }
-
- /**
- * @return the size of the crop regions
- */
- private int getCropSize() {
- return mCropSize > 0 ? mCropSize : sCropSize;
- }
-
- /**
- * Returns the currently applied scale factor for the image.
- * <p>
- * NOTE: This method overwrites any values stored in {@link #mValues}.
- */
- private float getScale() {
- mMatrix.getValues(mValues);
- return mValues[Matrix.MSCALE_X];
- }
-
- /**
- * Scales the image while keeping the aspect ratio.
- *
- * The given scale is capped so that the resulting scale of the image always remains
- * between {@link #mMinScale} and {@link #mMaxScale}.
- *
- * The scaled image is never allowed to be outside of the viewable area. If the image
- * is smaller than the viewable area, it will be centered.
- *
- * @param newScale the new scale
- * @param centerX the center horizontal point around which to scale
- * @param centerY the center vertical point around which to scale
- */
- private void scale(float newScale, float centerX, float centerY) {
- // rotate back to the original orientation
- mMatrix.postRotate(-mRotation, getWidth() / 2, getHeight() / 2);
-
- // ensure that mMixScale <= newScale <= mMaxScale
- newScale = Math.max(newScale, mMinScale);
- newScale = Math.min(newScale, mMaxScale);
-
- float currentScale = getScale();
- float factor = newScale / currentScale;
-
- // apply the scale factor
- mMatrix.postScale(factor, factor, centerX, centerY);
-
- // ensure the image is within the view bounds
- snap();
-
- // re-apply any rotation
- mMatrix.postRotate(mRotation, getWidth() / 2, getHeight() / 2);
-
- invalidate();
- }
-
- /**
- * Translates the image.
- *
- * This method will not allow the image to be translated outside of the visible area.
- *
- * @param tx how many pixels to translate horizontally
- * @param ty how many pixels to translate vertically
- * @return {@code true} if the translation was applied as specified. Otherwise, {@code false}
- * if the translation was modified.
- */
- private boolean translate(float tx, float ty) {
- mTranslateRect.set(mTempSrc);
- mMatrix.mapRect(mTranslateRect);
-
- final float maxLeft = mAllowCrop ? mCropRect.left : 0.0f;
- final float maxRight = mAllowCrop ? mCropRect.right : getWidth();
- float l = mTranslateRect.left;
- float r = mTranslateRect.right;
-
- final float translateX;
- if (mAllowCrop) {
- // If we're cropping, allow the image to scroll off the edge of the screen
- translateX = Math.max(maxLeft - mTranslateRect.right,
- Math.min(maxRight - mTranslateRect.left, tx));
- } else {
- // Otherwise, ensure the image never leaves the screen
- if (r - l < maxRight - maxLeft) {
- translateX = maxLeft + ((maxRight - maxLeft) - (r + l)) / 2;
- } else {
- translateX = Math.max(maxRight - r, Math.min(maxLeft - l, tx));
- }
- }
-
- float maxTop = mAllowCrop ? mCropRect.top: 0.0f;
- float maxBottom = mAllowCrop ? mCropRect.bottom : getHeight();
- float t = mTranslateRect.top;
- float b = mTranslateRect.bottom;
-
- final float translateY;
-
- if (mAllowCrop) {
- // If we're cropping, allow the image to scroll off the edge of the screen
- translateY = Math.max(maxTop - mTranslateRect.bottom,
- Math.min(maxBottom - mTranslateRect.top, ty));
- } else {
- // Otherwise, ensure the image never leaves the screen
- if (b - t < maxBottom - maxTop) {
- translateY = maxTop + ((maxBottom - maxTop) - (b + t)) / 2;
- } else {
- translateY = Math.max(maxBottom - b, Math.min(maxTop - t, ty));
- }
- }
-
- // Do the translation
- mMatrix.postTranslate(translateX, translateY);
- invalidate();
-
- return (translateX == tx) && (translateY == ty);
- }
-
- /**
- * Snaps the image so it touches all edges of the view.
- */
- private void snap() {
- mTranslateRect.set(mTempSrc);
- mMatrix.mapRect(mTranslateRect);
-
- // Determine how much to snap in the horizontal direction [if any]
- float maxLeft = mAllowCrop ? mCropRect.left : 0.0f;
- float maxRight = mAllowCrop ? mCropRect.right : getWidth();
- float l = mTranslateRect.left;
- float r = mTranslateRect.right;
-
- final float translateX;
- if (r - l < maxRight - maxLeft) {
- // Image is narrower than view; translate to the center of the view
- translateX = maxLeft + ((maxRight - maxLeft) - (r + l)) / 2;
- } else if (l > maxLeft) {
- // Image is off right-edge of screen; bring it into view
- translateX = maxLeft - l;
- } else if (r < maxRight) {
- // Image is off left-edge of screen; bring it into view
- translateX = maxRight - r;
- } else {
- translateX = 0.0f;
- }
-
- // Determine how much to snap in the vertical direction [if any]
- float maxTop = mAllowCrop ? mCropRect.top : 0.0f;
- float maxBottom = mAllowCrop ? mCropRect.bottom : getHeight();
- float t = mTranslateRect.top;
- float b = mTranslateRect.bottom;
-
- final float translateY;
- if (b - t < maxBottom - maxTop) {
- // Image is shorter than view; translate to the bottom edge of the view
- translateY = maxTop + ((maxBottom - maxTop) - (b + t)) / 2;
- } else if (t > maxTop) {
- // Image is off bottom-edge of screen; bring it into view
- translateY = maxTop - t;
- } else if (b < maxBottom) {
- // Image is off top-edge of screen; bring it into view
- translateY = maxBottom - b;
- } else {
- translateY = 0.0f;
- }
-
- if (Math.abs(translateX) > SNAP_THRESHOLD || Math.abs(translateY) > SNAP_THRESHOLD) {
- mSnapRunnable.start(translateX, translateY);
- } else {
- mMatrix.postTranslate(translateX, translateY);
- invalidate();
- }
- }
-
- /**
- * Rotates the image, either instantly or gradually
- *
- * @param degrees how many degrees to rotate the image, positive rotates clockwise
- * @param animate if {@code true}, animate during the rotation. Otherwise, snap rotate.
- */
- private void rotate(float degrees, boolean animate) {
- if (animate) {
- mRotateRunnable.start(degrees);
- } else {
- mRotation += degrees;
- mMatrix.postRotate(degrees, getWidth() / 2, getHeight() / 2);
- invalidate();
- }
- }
-
- /**
- * Initializes the header and any static values
- */
- private void initialize() {
- Context context = getContext();
-
- if (!sInitialized) {
- sInitialized = true;
-
- Resources resources = context.getApplicationContext().getResources();
-
- // Initialize colors
- sBackgroundColor = resources.getColor(R.color.photo_background_color);
-
- sCropSize = resources.getDimensionPixelSize(R.dimen.photo_crop_width);
-
- sCropDimPaint = new Paint();
- sCropDimPaint.setAntiAlias(true);
- sCropDimPaint.setColor(resources.getColor(R.color.photo_crop_dim_color));
- sCropDimPaint.setStyle(Style.FILL);
-
- sCropPaint = new Paint();
- sCropPaint.setAntiAlias(true);
- sCropPaint.setColor(resources.getColor(R.color.photo_crop_highlight_color));
- sCropPaint.setStyle(Style.STROKE);
- sCropPaint.setStrokeWidth(resources.getDimension(R.dimen.photo_crop_stroke_width));
-
- sHasMultitouchDistinct = context.getPackageManager().hasSystemFeature(
- PackageManager.FEATURE_TOUCHSCREEN_MULTITOUCH_DISTINCT);
- }
-
- mGestureDetector = new GestureDetector(context, this, null, !sHasMultitouchDistinct);
- mScaleGetureDetector = new ScaleGestureDetector(context, this);
- mScaleRunnable = new ScaleRunnable(this);
- mTranslateRunnable = new TranslateRunnable(this);
- mSnapRunnable = new SnapRunnable(this);
- mRotateRunnable = new RotateRunnable(this);
- }
-
- /**
- * Runnable that animates an image scale operation.
- */
- private static class ScaleRunnable implements Runnable {
-
- private final PhotoView mHeader;
-
- private float mCenterX;
- private float mCenterY;
-
- private boolean mZoomingIn;
-
- private float mTargetScale;
- private float mStartScale;
- private float mVelocity;
- private long mStartTime;
-
- private boolean mRunning;
- private boolean mStop;
-
- public ScaleRunnable(PhotoView header) {
- mHeader = header;
- }
-
- /**
- * Starts the animation. There is no target scale bounds check.
- */
- public boolean start(float startScale, float targetScale, float centerX, float centerY) {
- if (mRunning) {
- return false;
- }
-
- mCenterX = centerX;
- mCenterY = centerY;
-
- // Ensure the target scale is within the min/max bounds
- mTargetScale = targetScale;
- mStartTime = System.currentTimeMillis();
- mStartScale = startScale;
- mZoomingIn = mTargetScale > mStartScale;
- mVelocity = (mTargetScale - mStartScale) / ZOOM_ANIMATION_DURATION;
- mRunning = true;
- mStop = false;
- mHeader.post(this);
- return true;
- }
-
- /**
- * Stops the animation in place. It does not snap the image to its final zoom.
- */
- public void stop() {
- mRunning = false;
- mStop = true;
- }
-
- @Override
- public void run() {
- if (mStop) {
- return;
- }
-
- // Scale
- long now = System.currentTimeMillis();
- long ellapsed = now - mStartTime;
- float newScale = (mStartScale + mVelocity * ellapsed);
- mHeader.scale(newScale, mCenterX, mCenterY);
-
- // Stop when done
- if (newScale == mTargetScale || (mZoomingIn == (newScale > mTargetScale))) {
- mHeader.scale(mTargetScale, mCenterX, mCenterY);
- stop();
- }
-
- if (!mStop) {
- mHeader.post(this);
- }
- }
- }
-
- /**
- * Runnable that animates an image translation operation.
- */
- private static class TranslateRunnable implements Runnable {
-
- private static final float DECELERATION_RATE = 1000f;
- private static final long NEVER = -1L;
-
- private final PhotoView mHeader;
-
- private float mVelocityX;
- private float mVelocityY;
-
- private long mLastRunTime;
- private boolean mRunning;
- private boolean mStop;
-
- public TranslateRunnable(PhotoView header) {
- mLastRunTime = NEVER;
- mHeader = header;
- }
-
- /**
- * Starts the animation.
- */
- public boolean start(float velocityX, float velocityY) {
- if (mRunning) {
- return false;
- }
- mLastRunTime = NEVER;
- mVelocityX = velocityX;
- mVelocityY = velocityY;
- mStop = false;
- mRunning = true;
- mHeader.post(this);
- return true;
- }
-
- /**
- * Stops the animation in place. It does not snap the image to its final translation.
- */
- public void stop() {
- mRunning = false;
- mStop = true;
- }
-
- @Override
- public void run() {
- // See if we were told to stop:
- if (mStop) {
- return;
- }
-
- // Translate according to current velocities and time delta:
- long now = System.currentTimeMillis();
- float delta = (mLastRunTime != NEVER) ? (now - mLastRunTime) / 1000f : 0f;
- final boolean didTranslate = mHeader.translate(mVelocityX * delta, mVelocityY * delta);
- mLastRunTime = now;
- // Slow down:
- float slowDown = DECELERATION_RATE * delta;
- if (mVelocityX > 0f) {
- mVelocityX -= slowDown;
- if (mVelocityX < 0f) {
- mVelocityX = 0f;
- }
- } else {
- mVelocityX += slowDown;
- if (mVelocityX > 0f) {
- mVelocityX = 0f;
- }
- }
- if (mVelocityY > 0f) {
- mVelocityY -= slowDown;
- if (mVelocityY < 0f) {
- mVelocityY = 0f;
- }
- } else {
- mVelocityY += slowDown;
- if (mVelocityY > 0f) {
- mVelocityY = 0f;
- }
- }
-
- // Stop when done
- if ((mVelocityX == 0f && mVelocityY == 0f) || !didTranslate) {
- stop();
- mHeader.snap();
- }
-
- // See if we need to continue flinging:
- if (mStop) {
- return;
- }
- mHeader.post(this);
- }
- }
-
- /**
- * Runnable that animates an image translation operation.
- */
- private static class SnapRunnable implements Runnable {
-
- private static final long NEVER = -1L;
-
- private final PhotoView mHeader;
-
- private float mTranslateX;
- private float mTranslateY;
-
- private long mStartRunTime;
- private boolean mRunning;
- private boolean mStop;
-
- public SnapRunnable(PhotoView header) {
- mStartRunTime = NEVER;
- mHeader = header;
- }
-
- /**
- * Starts the animation.
- */
- public boolean start(float translateX, float translateY) {
- if (mRunning) {
- return false;
- }
- mStartRunTime = NEVER;
- mTranslateX = translateX;
- mTranslateY = translateY;
- mStop = false;
- mRunning = true;
- mHeader.postDelayed(this, SNAP_DELAY);
- return true;
- }
-
- /**
- * Stops the animation in place. It does not snap the image to its final translation.
- */
- public void stop() {
- mRunning = false;
- mStop = true;
- }
-
- @Override
- public void run() {
- // See if we were told to stop:
- if (mStop) {
- return;
- }
-
- // Translate according to current velocities and time delta:
- long now = System.currentTimeMillis();
- float delta = (mStartRunTime != NEVER) ? (now - mStartRunTime) : 0f;
-
- if (mStartRunTime == NEVER) {
- mStartRunTime = now;
- }
-
- float transX;
- float transY;
- if (delta >= SNAP_DURATION) {
- transX = mTranslateX;
- transY = mTranslateY;
- } else {
- transX = (mTranslateX / (SNAP_DURATION - delta)) * 10f;
- transY = (mTranslateY / (SNAP_DURATION - delta)) * 10f;
- if (Math.abs(transX) > Math.abs(mTranslateX) || transX == Float.NaN) {
- transX = mTranslateX;
- }
- if (Math.abs(transY) > Math.abs(mTranslateY) || transY == Float.NaN) {
- transY = mTranslateY;
- }
- }
-
- mHeader.translate(transX, transY);
- mTranslateX -= transX;
- mTranslateY -= transY;
-
- if (mTranslateX == 0 && mTranslateY == 0) {
- stop();
- }
-
- // See if we need to continue flinging:
- if (mStop) {
- return;
- }
- mHeader.post(this);
- }
- }
-
- /**
- * Runnable that animates an image rotation operation.
- */
- private static class RotateRunnable implements Runnable {
-
- private static final long NEVER = -1L;
-
- private final PhotoView mHeader;
-
- private float mTargetRotation;
- private float mAppliedRotation;
- private float mVelocity;
- private long mLastRuntime;
-
- private boolean mRunning;
- private boolean mStop;
-
- public RotateRunnable(PhotoView header) {
- mHeader = header;
- }
-
- /**
- * Starts the animation.
- */
- public void start(float rotation) {
- if (mRunning) {
- return;
- }
-
- mTargetRotation = rotation;
- mVelocity = mTargetRotation / ROTATE_ANIMATION_DURATION;
- mAppliedRotation = 0f;
- mLastRuntime = NEVER;
- mStop = false;
- mRunning = true;
- mHeader.post(this);
- }
-
- /**
- * Stops the animation in place. It does not snap the image to its final rotation.
- */
- public void stop() {
- mRunning = false;
- mStop = true;
- }
-
- @Override
- public void run() {
- if (mStop) {
- return;
- }
-
- if (mAppliedRotation != mTargetRotation) {
- long now = System.currentTimeMillis();
- long delta = mLastRuntime != NEVER ? now - mLastRuntime : 0L;
- float rotationAmount = mVelocity * delta;
- if (mAppliedRotation < mTargetRotation
- && mAppliedRotation + rotationAmount > mTargetRotation
- || mAppliedRotation > mTargetRotation
- && mAppliedRotation + rotationAmount < mTargetRotation) {
- rotationAmount = mTargetRotation - mAppliedRotation;
- }
- mHeader.rotate(rotationAmount, false);
- mAppliedRotation += rotationAmount;
- if (mAppliedRotation == mTargetRotation) {
- stop();
- }
- mLastRuntime = now;
- }
-
- if (mStop) {
- return;
- }
- mHeader.post(this);
- }
- }
-}
diff --git a/src/com/android/mail/ui/AbstractActivityController.java b/src/com/android/mail/ui/AbstractActivityController.java
index e182a44..1559b06 100644
--- a/src/com/android/mail/ui/AbstractActivityController.java
+++ b/src/com/android/mail/ui/AbstractActivityController.java
@@ -117,7 +117,7 @@
protected static final String TAG_FOLDER_LIST = "tag-folder-list";
protected Account mAccount;
- private Folder mFolder;
+ protected Folder mFolder;
protected MailActionBarView mActionBarView;
protected final RestrictedActivity mActivity;
protected final Context mContext;
diff --git a/src/com/android/mail/ui/AttachmentTile.java b/src/com/android/mail/ui/AttachmentTile.java
index 87d19e3..055ee5d 100644
--- a/src/com/android/mail/ui/AttachmentTile.java
+++ b/src/com/android/mail/ui/AttachmentTile.java
@@ -26,8 +26,8 @@
import android.widget.ImageView;
import android.widget.RelativeLayout;
+import com.android.ex.photo.util.ImageUtils;
import com.android.mail.R;
-import com.android.mail.photo.util.ImageUtils;
import com.android.mail.providers.Attachment;
import com.android.mail.utils.LogUtils;
diff --git a/src/com/android/mail/ui/OnePaneController.java b/src/com/android/mail/ui/OnePaneController.java
index e963bff..25ff012 100644
--- a/src/com/android/mail/ui/OnePaneController.java
+++ b/src/com/android/mail/ui/OnePaneController.java
@@ -221,7 +221,7 @@
}
// TODO: improve this transition
- mPagerController.show(mAccount, getFolder(), conversation);
+ mPagerController.show(mAccount, mFolder, conversation);
onConversationVisibilityChanged(true);
resetActionBarIcon();
@@ -297,17 +297,11 @@
public boolean onBackPressed() {
final int mode = mViewMode.getMode();
if (mode == ViewMode.FOLDER_LIST) {
- if (getFolderListFragment().showingHierarchy()) {
+ if (getFolderListFragment().showingHierarchy() && mFolder != null) {
// If we are showing the folder list and the user is exploring
// the children of a single parent folder,
// back should display the parent folder's parent and siblings.
- if (getFolder() != null && getFolder().parent != null) {
- onFolderSelected(getFolder().parent);
- } else {
- // If there was no parent, this must have been a top level
- // folder, so just show the top level folder list.
- showFolderList();
- }
+ goUpFolderHierarchy(mFolder);
} else {
// We are at the topmost list of folders; just go back to
// whatever conv list we were viewing before.
@@ -321,11 +315,11 @@
// If the user got here by navigating via the folder list, back
// should bring them back to the folder list.
mViewMode.enterFolderListMode();
- if (getFolder() != null && getFolder().parent != null) {
+ if (mFolder != null && mFolder.parent != null) {
// If there was a parent folder, show the parent and
// siblings of the current folder for which we are viewing
// the conversation list.
- setFolder(getFolder().parent);
+ setFolder(mFolder.parent);
} else {
// Otherwise, clear the selected folder and go back to whatever the last
// folder list displayed was.
@@ -345,6 +339,25 @@
return true;
}
+ private void goUpFolderHierarchy(Folder current) {
+ Folder top = current.parent;
+ if (top != null) {
+ setFolder(top);
+ // Replace this fragment with a new FolderListFragment
+ // showing this folder's children if we are not already
+ // looking at the child view for this folder.
+ mLastFolderListTransactionId = replaceFragment(FolderListFragment.newInstance(
+ top, top.childFoldersListUri),
+ FragmentTransaction.TRANSIT_FRAGMENT_OPEN, TAG_FOLDER_LIST);
+ // Show the up affordance when digging into child folders.
+ mActionBarView.setBackButton();
+ } else {
+ // Otherwise, clear the selected folder and go back to whatever the
+ // last folder list displayed was.
+ showFolderList();
+ }
+ }
+
private void transitionToInbox() {
mViewMode.enterConversationListMode();
if (mInbox == null) {
@@ -361,7 +374,7 @@
@Override
public void onFolderSelected(Folder folder) {
- if (folder.hasChildren && !getFolderListFragment().showingHierarchy()) {
+ if (folder.hasChildren) {
setFolder(folder);
// Replace this fragment with a new FolderListFragment
// showing this folder's children if we are not already
@@ -369,15 +382,10 @@
mLastFolderListTransactionId = replaceFragment(
FolderListFragment.newInstance(folder, folder.childFoldersListUri),
FragmentTransaction.TRANSIT_FRAGMENT_OPEN, TAG_FOLDER_LIST);
- return;
+ // Show the up affordance when digging into child folders.
+ mActionBarView.setBackButton();
} else {
- // We are looking at the child folders of this folder, so just
- // open the conv list for this folder.
- // We set the folder to null to clear the selected folder and
- // make sure that everything gets updated in case we were previously
- // viewing the child folders or conversation list for the selected folder.
- setFolder(null);
- super.onFolderChanged(folder);
+ super.onFolderSelected(folder);
}
}
diff --git a/src/com/android/mail/ui/TwoPaneController.java b/src/com/android/mail/ui/TwoPaneController.java
index ccd54dd..e75cae6 100644
--- a/src/com/android/mail/ui/TwoPaneController.java
+++ b/src/com/android/mail/ui/TwoPaneController.java
@@ -186,7 +186,7 @@
}
}
- public void goUpFolderHierarchy(Folder current) {
+ private void goUpFolderHierarchy(Folder current) {
Folder parent = current.parent;
if (parent.parent != null) {
super.onFolderSelected(parent);
@@ -277,7 +277,7 @@
} else {
mViewMode.enterConversationMode();
}
- mPagerController.show(mAccount, getFolder(), conversation);
+ mPagerController.show(mAccount, mFolder, conversation);
final ConversationListFragment convList = getConversationListFragment();
if (convList != null) {
LogUtils.d(LOG_TAG, "showConversation: Selecting position %d.", conversation.position);
@@ -373,8 +373,8 @@
if (mode == ViewMode.CONVERSATION_LIST && getFolderListFragment().showingHierarchy()) {
// If the user navigated via the left folders list into a child folder,
// back should take the user up to the parent folder's conversation list.
- if (getFolder().parent != null) {
- goUpFolderHierarchy(getFolder());
+ if (mFolder.parent != null) {
+ goUpFolderHierarchy(mFolder);
} else {
// Show inbox; we are at the top of the hierarchy we were
// showing, and it doesn't have a parent, so we must want to