mirror of
https://github.com/nextcloud/android.git
synced 2024-11-27 09:39:25 +03:00
- GridLayout
This commit is contained in:
parent
4f1b50795c
commit
ca59c75371
8 changed files with 193 additions and 61 deletions
|
@ -34,6 +34,13 @@
|
|||
android:layout_marginTop="5dp"
|
||||
android:src="@drawable/ic_menu_archive" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/imageView2"
|
||||
android:layout_width="40dp"
|
||||
android:layout_height="22dp"
|
||||
android:layout_marginLeft="22dp"
|
||||
android:src="@drawable/local_file_indicator" />
|
||||
|
||||
<FrameLayout
|
||||
android:id="@+id/imageItemFrame"
|
||||
android:layout_width="56dp"
|
||||
|
@ -67,14 +74,6 @@
|
|||
android:layout_marginRight="4dp"
|
||||
android:src="@android:drawable/checkbox_off_background" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/imageView2"
|
||||
android:layout_width="32dp"
|
||||
android:layout_height="32dp"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:layout_marginLeft="22dp"
|
||||
android:src="@drawable/local_file_indicator" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/Filename"
|
||||
android:layout_width="wrap_content"
|
118
res/layout/grid_item.xml
Normal file
118
res/layout/grid_item.xml
Normal file
|
@ -0,0 +1,118 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
ownCloud Android client application
|
||||
|
||||
Copyright (C) 2012 Bartek Przybylski
|
||||
Copyright (C) 2012-2013 ownCloud Inc.
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License version 2,
|
||||
as published by the Free Software Foundation.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
-->
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/ListItemLayout"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="160dp"
|
||||
android:background="@drawable/list_selector"
|
||||
android:orientation="vertical" >
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/imageView1"
|
||||
android:layout_width="90dp"
|
||||
android:layout_height="93dp"
|
||||
android:layout_marginBottom="5dp"
|
||||
android:layout_marginLeft="9dp"
|
||||
android:layout_marginTop="5dp"
|
||||
android:src="@drawable/ic_menu_archive" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/Filename"
|
||||
android:layout_width="95dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="4dp"
|
||||
android:layout_marginRight="4dp"
|
||||
android:ellipsize="middle"
|
||||
android:singleLine="true"
|
||||
android:text="TextView"
|
||||
android:textColor="#303030"
|
||||
android:textSize="16dip" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/imageView2"
|
||||
android:layout_width="40dp"
|
||||
android:layout_height="22dp"
|
||||
android:layout_marginLeft="22dp"
|
||||
android:src="@drawable/local_file_indicator" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/file_size"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight=".5"
|
||||
android:gravity="right"
|
||||
android:text="TextView"
|
||||
android:textColor="@color/list_item_lastmod_and_filesize_text"
|
||||
android:textSize="12dip" />
|
||||
|
||||
<FrameLayout
|
||||
android:id="@+id/imageItemFrame"
|
||||
android:layout_width="56dp"
|
||||
android:layout_height="56dp"
|
||||
android:focusable="false"
|
||||
android:focusableInTouchMode="false" >
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/sharedIcon"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="4dp"
|
||||
android:layout_marginLeft="4dp"
|
||||
android:layout_marginRight="4dp"
|
||||
android:src="@drawable/sharedlink" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/sharedWithMeIcon"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="4dp"
|
||||
android:layout_marginRight="4dp"
|
||||
android:layout_marginTop="4dp"
|
||||
android:src="@drawable/shared_with_me" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/custom_checkbox"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="4dp"
|
||||
android:layout_marginRight="4dp"
|
||||
android:src="@android:drawable/checkbox_off_background" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/imageView3"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="bottom|right"
|
||||
android:layout_marginBottom="10dp"
|
||||
android:layout_marginRight="2dp"
|
||||
android:src="@drawable/ic_favorite" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/last_mod"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight=".5"
|
||||
android:text="TextView"
|
||||
android:textColor="@color/list_item_lastmod_and_filesize_text"
|
||||
android:textSize="12dip" />
|
||||
</FrameLayout>
|
||||
|
||||
</LinearLayout>
|
|
@ -19,7 +19,7 @@
|
|||
-->
|
||||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="0dp"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1" >
|
||||
|
||||
|
@ -31,7 +31,14 @@
|
|||
<com.owncloud.android.ui.ExtendedListView
|
||||
android:id="@+id/list_root"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent" />
|
||||
android:layout_height="match_parent"
|
||||
android:columnWidth="160dp"
|
||||
android:gravity="center"
|
||||
android:horizontalSpacing="10dp"
|
||||
android:numColumns="auto_fit"
|
||||
android:stretchMode="columnWidth"
|
||||
android:verticalSpacing="10dp"
|
||||
android:visibility="visible" />
|
||||
</android.support.v4.widget.SwipeRefreshLayout>
|
||||
|
||||
<android.support.v4.widget.SwipeRefreshLayout
|
||||
|
@ -40,13 +47,14 @@
|
|||
android:layout_height="match_parent"
|
||||
android:visibility="gone" >
|
||||
|
||||
<GridView
|
||||
android:id="@+id/grid_list_view"
|
||||
android:layout_width="fill_parent"
|
||||
<TextView
|
||||
android:id="@+id/empty_list_view"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:numColumns="1"
|
||||
android:layout_gravity="center"
|
||||
android:gravity="center_vertical|center_horizontal"
|
||||
android:text="@string/empty"
|
||||
android:visibility="visible" />
|
||||
|
||||
</android.support.v4.widget.SwipeRefreshLayout>
|
||||
|
||||
</FrameLayout>
|
|
@ -21,6 +21,7 @@ package com.owncloud.android.ui;
|
|||
import android.content.Context;
|
||||
import android.graphics.Canvas;
|
||||
import android.util.AttributeSet;
|
||||
import android.widget.GridView;
|
||||
import android.widget.ListView;
|
||||
|
||||
/**
|
||||
|
@ -30,7 +31,7 @@ import android.widget.ListView;
|
|||
*
|
||||
* @author David A. Velasco
|
||||
*/
|
||||
public class ExtendedListView extends ListView {
|
||||
public class ExtendedListView extends GridView {
|
||||
|
||||
private int mPositionToSetAndCenter;
|
||||
|
||||
|
@ -55,7 +56,8 @@ public class ExtendedListView extends ListView {
|
|||
protected void onDraw (Canvas canvas) {
|
||||
super.onDraw(canvas);
|
||||
if (mPositionToSetAndCenter > 0) {
|
||||
this.setSelectionFromTop(mPositionToSetAndCenter, getHeight() / 2);
|
||||
this.setSelection(mPositionToSetAndCenter);
|
||||
//this.setSelectionFromTop(mPositionToSetAndCenter, getHeight() / 2);
|
||||
mPositionToSetAndCenter = 0;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -130,22 +130,31 @@ public class FileListListAdapter extends BaseAdapter implements ListAdapter {
|
|||
}
|
||||
|
||||
View view = convertView;
|
||||
OCFile file = null;
|
||||
LayoutInflater inflator = (LayoutInflater) mContext
|
||||
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||
|
||||
if (mFiles != null && mFiles.size() > position) {
|
||||
file = mFiles.get(position);
|
||||
}
|
||||
|
||||
if (fileView){
|
||||
view = inflator.inflate(R.layout.list_item, null);
|
||||
} else {
|
||||
view = inflator.inflate(R.layout.image_item, null);
|
||||
if (file.isImage()){
|
||||
view = inflator.inflate(R.layout.grid_image, null);
|
||||
} else {
|
||||
view = inflator.inflate(R.layout.grid_item, null);
|
||||
}
|
||||
|
||||
View frame = view.findViewById(R.id.imageItemFrame);
|
||||
frame.setVisibility(View.GONE);
|
||||
}
|
||||
// }
|
||||
view.invalidate();
|
||||
|
||||
if (mFiles != null && mFiles.size() > position) {
|
||||
OCFile file = mFiles.get(position);
|
||||
if (file != null){
|
||||
TextView fileName = (TextView) view.findViewById(R.id.Filename);
|
||||
if (!fileView){fileName.setVisibility(View.GONE);}
|
||||
// if (!fileView){fileName.setVisibility(View.GONE);}
|
||||
String name = file.getFileName();
|
||||
|
||||
fileName.setText(name);
|
||||
|
@ -189,7 +198,7 @@ public class FileListListAdapter extends BaseAdapter implements ListAdapter {
|
|||
}
|
||||
|
||||
GridView parentList = (GridView)parent;
|
||||
if (parentList.getChoiceMode() == ListView.CHOICE_MODE_NONE) {
|
||||
if (parentList.getChoiceMode() == GridView.CHOICE_MODE_NONE) {
|
||||
checkBoxV.setVisibility(View.GONE);
|
||||
} else {
|
||||
if (parentList.isItemChecked(position)) {
|
||||
|
|
|
@ -52,7 +52,7 @@ implements OnItemClickListener, SwipeRefreshLayout.OnRefreshListener {
|
|||
private static final String KEY_HEIGHT_CELL = "HEIGHT_CELL";
|
||||
private static final String KEY_EMPTY_LIST_MESSAGE = "EMPTY_LIST_MESSAGE";
|
||||
|
||||
protected ExtendedListView mList;
|
||||
// protected ExtendedListView mList;
|
||||
|
||||
private SwipeRefreshLayout mRefreshLayout;
|
||||
private SwipeRefreshLayout mRefreshEmptyLayout;
|
||||
|
@ -66,29 +66,24 @@ implements OnItemClickListener, SwipeRefreshLayout.OnRefreshListener {
|
|||
|
||||
private SwipeRefreshLayout.OnRefreshListener mOnRefreshListener = null;
|
||||
|
||||
private GridView imageView;
|
||||
private View fileView;
|
||||
|
||||
|
||||
protected GridView imageView;
|
||||
|
||||
public void setListAdapter(ListAdapter listAdapter) {
|
||||
imageView.setAdapter(listAdapter);
|
||||
imageView.invalidate();
|
||||
}
|
||||
|
||||
public ListView getListView() {
|
||||
return mList;
|
||||
public GridView getGridView() {
|
||||
return imageView;
|
||||
}
|
||||
|
||||
protected void switchImageView(){
|
||||
// TODO berechnen, wieviele Spalten
|
||||
imageView.setNumColumns(3);
|
||||
mList.invalidate();
|
||||
imageView.setNumColumns(GridView.AUTO_FIT);
|
||||
imageView.invalidate();
|
||||
}
|
||||
|
||||
protected void switchFileView(){
|
||||
imageView.setNumColumns(1);
|
||||
mList.invalidate();
|
||||
imageView.setNumColumns(1);
|
||||
imageView.invalidate();
|
||||
}
|
||||
|
||||
|
@ -99,15 +94,16 @@ implements OnItemClickListener, SwipeRefreshLayout.OnRefreshListener {
|
|||
|
||||
View v = inflater.inflate(R.layout.list_fragment, null);
|
||||
|
||||
imageView = (GridView) v.findViewById(R.id.grid_list_view);
|
||||
imageView.setOnItemClickListener(this);
|
||||
// imageView = (GridView) v.findViewById(R.id.grid_list_view);
|
||||
// imageView.setOnItemClickListener(this);
|
||||
|
||||
// mEmptyListMessage = (TextView) v.findViewById(R.id.empty_list_view);
|
||||
mList = (ExtendedListView)(v.findViewById(R.id.list_root));
|
||||
// mList.setOnItemClickListener(this);
|
||||
imageView = (ExtendedListView)(v.findViewById(R.id.list_root));
|
||||
imageView.setOnItemClickListener(this);
|
||||
|
||||
mList.setDivider(getResources().getDrawable(R.drawable.uploader_list_separator));
|
||||
mList.setDividerHeight(1);
|
||||
//mList.set
|
||||
//mList.setDivider(getResources().getDrawable(R.drawable.uploader_list_separator));
|
||||
//mList.setDividerHeight(1);
|
||||
|
||||
if (savedInstanceState != null) {
|
||||
int referencePosition = savedInstanceState.getInt(KEY_SAVED_LIST_POSITION);
|
||||
|
@ -121,7 +117,7 @@ implements OnItemClickListener, SwipeRefreshLayout.OnRefreshListener {
|
|||
onCreateSwipeToRefresh(mRefreshLayout);
|
||||
onCreateSwipeToRefresh(mRefreshEmptyLayout);
|
||||
|
||||
mList.setEmptyView(mRefreshEmptyLayout);
|
||||
// mList.setEmptyView(mRefreshEmptyLayout);
|
||||
|
||||
return v;
|
||||
}
|
||||
|
@ -172,8 +168,8 @@ implements OnItemClickListener, SwipeRefreshLayout.OnRefreshListener {
|
|||
* @return The position in the list of the visible item in the center of the screen.
|
||||
*/
|
||||
protected int getReferencePosition() {
|
||||
if (mList != null) {
|
||||
return (mList.getFirstVisiblePosition() + mList.getLastVisiblePosition()) / 2;
|
||||
if (imageView != null) {
|
||||
return (imageView.getFirstVisiblePosition() + imageView.getLastVisiblePosition()) / 2;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
|
@ -186,8 +182,8 @@ implements OnItemClickListener, SwipeRefreshLayout.OnRefreshListener {
|
|||
* @param position Reference position previously returned by {@link LocalFileListFragment#getReferencePosition()}
|
||||
*/
|
||||
protected void setReferencePosition(int position) {
|
||||
if (mList != null) {
|
||||
mList.setAndCenterSelection(position);
|
||||
if (imageView != null) {
|
||||
imageView.setSelection(position);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -205,20 +201,20 @@ implements OnItemClickListener, SwipeRefreshLayout.OnRefreshListener {
|
|||
|
||||
int top = mTops.remove(mTops.size() - 1);
|
||||
|
||||
mList.setSelectionFromTop(firstPosition, top);
|
||||
imageView.setSelection(firstPosition);
|
||||
|
||||
// Move the scroll if the selection is not visible
|
||||
int indexPosition = mHeightCell*index;
|
||||
int height = mList.getHeight();
|
||||
int height = imageView.getHeight();
|
||||
|
||||
if (indexPosition > height) {
|
||||
if (android.os.Build.VERSION.SDK_INT >= 11)
|
||||
{
|
||||
mList.smoothScrollToPosition(index);
|
||||
imageView.smoothScrollToPosition(index);
|
||||
}
|
||||
else if (android.os.Build.VERSION.SDK_INT >= 8)
|
||||
{
|
||||
mList.setSelectionFromTop(index, 0);
|
||||
imageView.setSelection(index);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -232,10 +228,10 @@ implements OnItemClickListener, SwipeRefreshLayout.OnRefreshListener {
|
|||
|
||||
mIndexes.add(index);
|
||||
|
||||
int firstPosition = mList.getFirstVisiblePosition();
|
||||
int firstPosition = imageView.getFirstVisiblePosition();
|
||||
mFirstPositions.add(firstPosition);
|
||||
|
||||
View view = mList.getChildAt(0);
|
||||
View view = imageView.getChildAt(0);
|
||||
int top = (view == null) ? 0 : view.getTop() ;
|
||||
|
||||
mTops.add(top);
|
||||
|
|
|
@ -75,7 +75,7 @@ public class LocalFileListFragment extends ExtendedListFragment {
|
|||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
Log_OC.i(TAG, "onCreateView() start");
|
||||
View v = super.onCreateView(inflater, container, savedInstanceState);
|
||||
getListView().setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
|
||||
getGridView().setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
|
||||
disableSwipe(); // Disable pull refresh
|
||||
setMessageForEmptyList(getString(R.string.local_file_list_empty));
|
||||
Log_OC.i(TAG, "onCreateView() end");
|
||||
|
@ -117,7 +117,7 @@ public class LocalFileListFragment extends ExtendedListFragment {
|
|||
} else { /// Click on a file
|
||||
ImageView checkBoxV = (ImageView) v.findViewById(R.id.custom_checkbox);
|
||||
if (checkBoxV != null) {
|
||||
if (getListView().isItemChecked(position)) {
|
||||
if (getGridView().isItemChecked(position)) {
|
||||
checkBoxV.setImageResource(android.R.drawable.checkbox_on_background);
|
||||
} else {
|
||||
checkBoxV.setImageResource(android.R.drawable.checkbox_off_background);
|
||||
|
@ -194,10 +194,10 @@ public class LocalFileListFragment extends ExtendedListFragment {
|
|||
directory = directory.getParentFile();
|
||||
}
|
||||
|
||||
mList.clearChoices(); // by now, only files in the same directory will be kept as selected
|
||||
imageView.clearChoices(); // by now, only files in the same directory will be kept as selected
|
||||
mAdapter.swapDirectory(directory);
|
||||
if (mDirectory == null || !mDirectory.equals(directory)) {
|
||||
mList.setSelectionFromTop(0, 0);
|
||||
imageView.setSelection(0);
|
||||
}
|
||||
mDirectory = directory;
|
||||
}
|
||||
|
@ -210,12 +210,12 @@ public class LocalFileListFragment extends ExtendedListFragment {
|
|||
*/
|
||||
public String[] getCheckedFilePaths() {
|
||||
String [] result = null;
|
||||
SparseBooleanArray positions = mList.getCheckedItemPositions();
|
||||
SparseBooleanArray positions = imageView.getCheckedItemPositions();
|
||||
if (positions.size() > 0) {
|
||||
Log_OC.d(TAG, "Returning " + positions.size() + " selected files");
|
||||
result = new String[positions.size()];
|
||||
for (int i=0; i<positions.size(); i++) {
|
||||
result[i] = ((File) mList.getItemAtPosition(positions.keyAt(i))).getAbsolutePath();
|
||||
result[i] = ((File) imageView.getItemAtPosition(positions.keyAt(i))).getAbsolutePath();
|
||||
}
|
||||
}
|
||||
return result;
|
||||
|
|
|
@ -126,8 +126,8 @@ public class OCFileListFragment extends ExtendedListFragment {
|
|||
);
|
||||
setListAdapter(mAdapter);
|
||||
|
||||
registerForContextMenu(getListView());
|
||||
getListView().setOnCreateContextMenuListener(this);
|
||||
registerForContextMenu(getGridView());
|
||||
getGridView().setOnCreateContextMenuListener(this);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -381,7 +381,7 @@ public class OCFileListFragment extends ExtendedListFragment {
|
|||
|
||||
mAdapter.swapDirectory(directory, storageManager);
|
||||
if (mFile == null || !mFile.equals(directory)) {
|
||||
mList.setSelectionFromTop(0, 0);
|
||||
imageView.setSelection(0);
|
||||
}
|
||||
mFile = directory;
|
||||
|
||||
|
|
Loading…
Reference in a new issue