瀏覽代碼

Merge pull request #575 from owncloud/images_gallery_zoom

Pinch-to-zoom in preview of images
David A. Velasco 10 年之前
父節點
當前提交
5756dd8ac4

+ 8 - 0
THIRD_PARTY.txt

@@ -60,4 +60,12 @@ The third party software included and used by this project is:
    A binary JAR file must be generated from this linked project
    and included in the ownCloud client APK.
    See http://http://actionbarsherlock.com/
+   
+ * TouchImageView, commit 6dbeac4f11936185ba374c73144ac431c23c9aab
+   Copyright (c) 2012 Michael Ortiz
+   Licensed under MIT License
+   JAR file libs/touch-image-view.jar has been generated by ownCloud Inc., including without 
+   modifications com.ortiz.touch.ExtendedViewPager and com.ortiz.touch.TouchImageView classes. 
+   See https://github.com/MikeOrtiz/TouchImageView
+ 
  

二進制
libs/touch-image-view.jar


+ 1 - 1
res/layout/preview_image_activity.xml

@@ -21,7 +21,7 @@
     android:layout_height="match_parent"
     android:orientation="vertical" >
 
-    <android.support.v4.view.ViewPager 
+    <com.ortiz.touch.ExtendedViewPager
         android:id="@+id/fragmentPager"
 		android:layout_width="match_parent"
 		android:layout_height="match_parent" 

+ 3 - 3
res/layout/preview_image_fragment.xml

@@ -43,10 +43,10 @@
         android:layout_centerInParent="true"
         />
     
-    <ImageView
+    <com.ortiz.touch.TouchImageView
         android:id="@+id/image"
-        android:layout_width="wrap_content"
-        android:layout_height="wrap_content"
+        android:layout_width="match_parent"
+        android:layout_height="match_parent"
         android:layout_margin="0dp"
         android:layout_centerInParent="true"
         android:contentDescription="@string/preview_image_description"

+ 10 - 18
src/com/owncloud/android/ui/preview/PreviewImageActivity.java

@@ -27,20 +27,18 @@ import android.os.Bundle;
 import android.os.IBinder;
 import android.preference.PreferenceManager;
 import android.support.v4.view.ViewPager;
-import android.view.MotionEvent;
-import android.view.View;
-import android.view.View.OnTouchListener;
 
 import com.actionbarsherlock.app.ActionBar;
 import com.actionbarsherlock.view.MenuItem;
 import com.actionbarsherlock.view.Window;
+import com.ortiz.touch.ExtendedViewPager;
 import com.owncloud.android.R;
 import com.owncloud.android.authentication.AccountUtils;
 import com.owncloud.android.datamodel.FileDataStorageManager;
 import com.owncloud.android.datamodel.OCFile;
 import com.owncloud.android.files.services.FileDownloader;
-import com.owncloud.android.files.services.FileUploader;
 import com.owncloud.android.files.services.FileDownloader.FileDownloaderBinder;
+import com.owncloud.android.files.services.FileUploader;
 import com.owncloud.android.files.services.FileUploader.FileUploaderBinder;
 import com.owncloud.android.lib.common.operations.OnRemoteOperationListener;
 import com.owncloud.android.lib.common.operations.RemoteOperation;
@@ -63,7 +61,7 @@ import com.owncloud.android.utils.Log_OC;
  *  @author David A. Velasco
  */
 public class PreviewImageActivity extends FileActivity implements 
-FileFragment.ContainerActivity, OnTouchListener,  
+ FileFragment.ContainerActivity,
 ViewPager.OnPageChangeListener, OnRemoteOperationListener {
     
     public static final int DIALOG_SHORT_WAIT = 0;
@@ -73,7 +71,7 @@ ViewPager.OnPageChangeListener, OnRemoteOperationListener {
     public static final String KEY_WAITING_TO_PREVIEW = "WAITING_TO_PREVIEW";
     private static final String KEY_WAITING_FOR_BINDER = "WAITING_FOR_BINDER";
     
-    private ViewPager mViewPager; 
+    private ExtendedViewPager mViewPager;
     private PreviewImagePagerAdapter mPreviewImagePagerAdapter;    
     
     private boolean mRequestWaitingForBinder;
@@ -118,7 +116,7 @@ ViewPager.OnPageChangeListener, OnRemoteOperationListener {
             parentFolder = getStorageManager().getFileByPath(OCFile.ROOT_PATH);
         }
         mPreviewImagePagerAdapter = new PreviewImagePagerAdapter(getSupportFragmentManager(), parentFolder, getAccount(), getStorageManager());
-        mViewPager = (ViewPager) findViewById(R.id.fragmentPager);
+        mViewPager = (ExtendedViewPager) findViewById(R.id.fragmentPager);
         int position = mPreviewImagePagerAdapter.getFilePosition(getFile());
         position = (position >= 0) ? position : 0;
         mViewPager.setAdapter(mPreviewImagePagerAdapter); 
@@ -322,7 +320,11 @@ ViewPager.OnPageChangeListener, OnRemoteOperationListener {
                     requestForDownload(currentFile);
                 }
             }
+
+            // Call to reset image zoom to initial state
+            ((PreviewImagePagerAdapter) mViewPager.getAdapter()).resetZoom();
         }
+
     }
     
     /**
@@ -388,17 +390,7 @@ ViewPager.OnPageChangeListener, OnRemoteOperationListener {
 
     }
 
-
-    @Override
-    public boolean onTouch(View v, MotionEvent event) {
-        if (event.getAction() == MotionEvent.ACTION_UP) {
-           toggleFullScreen();
-        }
-        return true;
-    }
-
-    
-    private void toggleFullScreen() {
+    public void toggleFullScreen() {
         ActionBar actionBar = getSupportActionBar();
         if (mFullScreen) {
             actionBar.show();

+ 14 - 20
src/com/owncloud/android/ui/preview/PreviewImageFragment.java

@@ -18,7 +18,6 @@ package com.owncloud.android.ui.preview;
 
 import java.lang.ref.WeakReference;
 
-
 import android.accounts.Account;
 import android.annotation.SuppressLint;
 import android.app.Activity;
@@ -32,7 +31,7 @@ import android.support.v4.app.FragmentStatePagerAdapter;
 import android.view.Display;
 import android.view.LayoutInflater;
 import android.view.View;
-import android.view.View.OnTouchListener;
+import android.view.View.OnClickListener;
 import android.view.ViewGroup;
 import android.widget.ImageView;
 import android.widget.ProgressBar;
@@ -41,6 +40,7 @@ import android.widget.TextView;
 import com.actionbarsherlock.view.Menu;
 import com.actionbarsherlock.view.MenuInflater;
 import com.actionbarsherlock.view.MenuItem;
+import com.ortiz.touch.TouchImageView;
 import com.owncloud.android.R;
 import com.owncloud.android.datamodel.OCFile;
 import com.owncloud.android.files.FileMenuFilter;
@@ -65,7 +65,7 @@ public class PreviewImageFragment extends FileFragment {
 
     private View mView;
     private Account mAccount;
-    private ImageView mImageView;
+    private TouchImageView mImageView;
     private TextView mMessageView;
     private ProgressBar mProgressWheel;
 
@@ -124,30 +124,22 @@ public class PreviewImageFragment extends FileFragment {
             Bundle savedInstanceState) {
         super.onCreateView(inflater, container, savedInstanceState);
         mView = inflater.inflate(R.layout.preview_image_fragment, container, false);
-        mImageView = (ImageView)mView.findViewById(R.id.image);
+        mImageView = (TouchImageView) mView.findViewById(R.id.image);
         mImageView.setVisibility(View.GONE);
-        mView.setOnTouchListener((OnTouchListener)getActivity());
+        mImageView.setOnClickListener(new OnClickListener() {
+            @Override
+            public void onClick(View v) {
+                ((PreviewImageActivity) getActivity()).toggleFullScreen();
+            }
+
+        });
         mMessageView = (TextView)mView.findViewById(R.id.message);
         mMessageView.setVisibility(View.GONE);
         mProgressWheel = (ProgressBar)mView.findViewById(R.id.progressWheel);
         mProgressWheel.setVisibility(View.VISIBLE);
         return mView;
     }
-    
 
-    /**
-     * {@inheritDoc}
-     */
-    @Override
-    public void onAttach(Activity activity) {
-        super.onAttach(activity);
-        if (!(activity instanceof OnTouchListener)) {
-            throw new ClassCastException(activity.toString() + 
-                    " must implement " + OnTouchListener.class.getSimpleName());
-        }
-    }
-    
-    
     /**
      * {@inheritDoc}
      */
@@ -303,7 +295,6 @@ public class PreviewImageFragment extends FileFragment {
         super.onPause();
     }
 
-
     @Override
     public void onDestroy() {
         if (mBitmap != null) {
@@ -513,5 +504,8 @@ public class PreviewImageFragment extends FileFragment {
         container.finish();
     }
     
+    public TouchImageView getImageView() {
+        return mImageView;
+    }
     
 }

+ 16 - 3
src/com/owncloud/android/ui/preview/PreviewImagePagerAdapter.java

@@ -18,13 +18,11 @@ package com.owncloud.android.ui.preview;
 
 import java.util.HashMap;
 import java.util.HashSet;
+import java.util.Iterator;
 import java.util.Map;
 import java.util.Set;
 import java.util.Vector;
 
-import com.owncloud.android.datamodel.OCFile;
-import com.owncloud.android.ui.fragment.FileFragment;
-
 import android.accounts.Account;
 import android.support.v4.app.Fragment;
 import android.support.v4.app.FragmentManager;
@@ -32,6 +30,8 @@ import android.support.v4.app.FragmentStatePagerAdapter;
 import android.view.ViewGroup;
 
 import com.owncloud.android.datamodel.FileDataStorageManager;
+import com.owncloud.android.datamodel.OCFile;
+import com.owncloud.android.ui.fragment.FileFragment;
 
 /**
  * Adapter class that provides Fragment instances  
@@ -179,6 +179,19 @@ public class PreviewImagePagerAdapter extends FragmentStatePagerAdapter {
         return mDownloadErrors.contains(Integer.valueOf(position));
     }
 
+    /**
+     * Reset the image zoom to default value for each CachedFragments
+     */
+    public void resetZoom() {
+        Iterator<FileFragment> entries = mCachedFragments.values().iterator();
+        while (entries.hasNext()) {
+        FileFragment fileFragment = (FileFragment) entries.next();
+            if (fileFragment instanceof PreviewImageFragment) {
+                ((PreviewImageFragment) fileFragment).getImageView().resetZoom();
+            }
+        }
+    }
+
     /* -*
      * Called when a change in the shown pages is going to start being made.
      * 

+ 7 - 0
third_party/touch-image-view/LICENSE

@@ -0,0 +1,7 @@
+opyright (c) 2012 Michael Ortiz
+
+Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE