Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pinch zoom #1466

Closed
wants to merge 9 commits into from
61 changes: 57 additions & 4 deletions src/com/owncloud/android/ui/fragment/ExtendedListFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,16 @@

package com.owncloud.android.ui.fragment;

import java.util.ArrayList;

import android.content.SharedPreferences;
import android.os.Build;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.v4.app.Fragment;
import android.support.v4.widget.SwipeRefreshLayout;
import android.view.GestureDetector;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.ScaleGestureDetector;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AbsListView;
Expand All @@ -37,6 +40,7 @@
import android.widget.ListView;
import android.widget.TextView;

import com.owncloud.android.MainApp;
import com.getbase.floatingactionbutton.FloatingActionButton;
import com.getbase.floatingactionbutton.FloatingActionsMenu;
import com.owncloud.android.R;
Expand All @@ -45,6 +49,8 @@
import com.owncloud.android.ui.activity.OnEnforceableRefreshListener;
import com.owncloud.android.ui.adapter.FileListListAdapter;

import java.util.ArrayList;

import third_parties.in.srain.cube.GridViewWithHeaderAndFooter;

/**
Expand All @@ -61,7 +67,9 @@ public class ExtendedListFragment extends Fragment
private static final String KEY_TOPS = "TOPS";
private static final String KEY_HEIGHT_CELL = "HEIGHT_CELL";
private static final String KEY_EMPTY_LIST_MESSAGE = "EMPTY_LIST_MESSAGE";
private static final String GRID_COLUMNS = "gridColumns";

private ScaleGestureDetector mScaleGestureDetector = null;
private SwipeRefreshLayout mRefreshListLayout;
private SwipeRefreshLayout mRefreshGridLayout;
private SwipeRefreshLayout mRefreshEmptyLayout;
Expand All @@ -71,7 +79,7 @@ public class ExtendedListFragment extends Fragment
private FloatingActionButton mFabUpload;
private FloatingActionButton mFabMkdir;
private FloatingActionButton mFabUploadFromApp;

// Save the state of the scroll in browsing
private ArrayList<Integer> mIndexes;
private ArrayList<Integer> mFirstPositions;
Expand All @@ -88,6 +96,8 @@ public class ExtendedListFragment extends Fragment

private ListAdapter mAdapter;

private float mScale = -1f;

protected void setListAdapter(ListAdapter listAdapter) {
mAdapter = listAdapter;
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
Expand Down Expand Up @@ -174,6 +184,17 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
mGridView.setOnItemClickListener(this);
mGridFooterView = inflater.inflate(R.layout.list_footer, null, false);

mScaleGestureDetector = new ScaleGestureDetector(MainApp.getAppContext(),new ScaleListener());
// gestureDetector = new GestureDetector(MainApp.getAppContext(), new SingleTapConfirm());

mGridView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
mScaleGestureDetector.onTouchEvent(motionEvent);
return false;
}
});

if (savedInstanceState != null) {
int referencePosition = savedInstanceState.getInt(KEY_SAVED_LIST_POSITION);
if (mCurrentListView == mListView) {
Expand Down Expand Up @@ -208,6 +229,30 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
return v;
}

private class SingleTapConfirm extends GestureDetector.SimpleOnGestureListener {
@Override
public boolean onSingleTapUp(MotionEvent e) {
return true;
}
}

private class ScaleListener extends ScaleGestureDetector.SimpleOnScaleGestureListener {
@Override
public boolean onScale(ScaleGestureDetector detector) {
if (mScale == -1f) {
mGridView.setNumColumns(GridView.AUTO_FIT);
mScale = mGridView.getNumColumns();
}
mScale *= 1.f - (detector.getScaleFactor() - 1.f);
mScale = Math.max(2.0f, Math.min(mScale, 10.0f));
Integer scaleInt = Math.round(mScale);
mGridView.setNumColumns(scaleInt);
mGridView.invalidateViews();

return true;
}
}

/**
* {@inheritDoc}
*/
Expand All @@ -228,7 +273,11 @@ public void onActivityCreated(Bundle savedInstanceState) {
mTops = new ArrayList<Integer>();
mHeightCell = 0;
}
}

SharedPreferences appPreferences = PreferenceManager
.getDefaultSharedPreferences(getContext());
mScale = appPreferences.getFloat(GRID_COLUMNS, -1.0f);
}


@Override
Expand All @@ -241,6 +290,10 @@ public void onSaveInstanceState(Bundle savedInstanceState) {
savedInstanceState.putIntegerArrayList(KEY_TOPS, mTops);
savedInstanceState.putInt(KEY_HEIGHT_CELL, mHeightCell);
savedInstanceState.putString(KEY_EMPTY_LIST_MESSAGE, getEmptyViewText());

SharedPreferences.Editor editor = PreferenceManager
.getDefaultSharedPreferences(getContext()).edit();
editor.putFloat(GRID_COLUMNS, mScale).apply();
}

/**
Expand Down