3row Grid
authortobiasKaminsky <tobias@kaminsky.me>
Wed, 17 Sep 2014 15:21:26 +0000 (17:21 +0200)
committertobiasKaminsky <tobias@kaminsky.me>
Wed, 17 Sep 2014 15:21:26 +0000 (17:21 +0200)
res/layout/grid_image.xml
res/layout/grid_item.xml
res/layout/list_fragment.xml
src/com/owncloud/android/ui/ExtendedListView.java
src/com/owncloud/android/ui/SquareImageView.java [new file with mode: 0644]
src/com/owncloud/android/ui/adapter/FileListListAdapter.java
src/com/owncloud/android/ui/fragment/ExtendedListFragment.java

index a9fe863..ffeafcb 100644 (file)
   GNU General Public License for more details.\r
 \r
   You should have received a copy of the GNU General Public License\r
-  along with this program.  If not, see <http://www.gnu.org/licenses/>.\r
+  along with this program.  If not, see <http://www.gnu.org/licenses/>.
   \r
 -->\r
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"\r
     android:id="@+id/ListItemLayout"\r
-    android:layout_width="fill_parent"\r
-    android:layout_height="160dp"\r
+    android:layout_width="match_parent"\r
+    android:layout_height="match_parent"\r
+    android:layout_gravity="center_horizontal"\r
     android:background="@drawable/list_selector"\r
-    android:orientation="horizontal" >\r
+    android:gravity="center_horizontal"\r
+    android:orientation="vertical" >\r
 \r
-    <ImageView\r
+    <com.owncloud.android.ui.SquareImageView\r
         android:id="@+id/imageView1"\r
-        android:layout_width="150dp"\r
-        android:layout_height="150dp"\r
-        android:layout_marginBottom="5dp"\r
-        android:layout_marginLeft="9dp"\r
-        android:layout_marginTop="5dp"\r
+        android:layout_width="match_parent"\r
+        android:layout_height="match_parent"\r
+        android:layout_gravity="fill"\r
+        android:paddingLeft="10dp"\r
+        android:paddingRight="10dp"\r
+        android:scaleType="centerCrop"\r
         android:src="@drawable/ic_menu_archive" />\r
 \r
-    <ImageView\r
-        android:id="@+id/imageView2"\r
-        android:layout_width="40dp"\r
-        android:layout_height="22dp"\r
-        android:layout_marginLeft="22dp"\r
-        android:src="@drawable/local_file_indicator" />\r
-\r
     <FrameLayout\r
         android:id="@+id/imageItemFrame"\r
-        android:layout_width="56dp"\r
-        android:layout_height="56dp"\r
+        android:layout_width="wrap_content"\r
+        android:layout_height="match_parent"\r
         android:focusable="false"\r
         android:focusableInTouchMode="false" >\r
 \r
             android:textSize="12dip" />\r
     </FrameLayout>\r
 \r
+    <ImageView\r
+        android:id="@+id/imageView2"\r
+        android:layout_width="40dp"\r
+        android:layout_height="22dp"\r
+        android:layout_marginLeft="22dp"\r
+        android:src="@drawable/local_file_indicator" />\r
+\r
 </LinearLayout>
\ No newline at end of file
index 5c35c62..9d7d719 100644 (file)
 -->\r
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"\r
     android:id="@+id/ListItemLayout"\r
-    android:layout_width="fill_parent"\r
-    android:layout_height="160dp"\r
+    android:layout_width="match_parent"\r
+    android:layout_height="match_parent"\r
+    android:layout_gravity="center_horizontal"\r
     android:background="@drawable/list_selector"\r
+    android:gravity="center"\r
     android:orientation="vertical" >\r
 \r
     <ImageView\r
         android:id="@+id/imageView1"\r
         android:layout_width="90dp"\r
-        android:layout_height="93dp"\r
-        android:layout_marginBottom="5dp"\r
-        android:layout_marginLeft="9dp"\r
-        android:layout_marginTop="5dp"\r
+        android:layout_height="90dp"\r
+        android:layout_marginLeft="10dp"\r
+        android:layout_marginRight="10dp"\r
         android:src="@drawable/ic_menu_archive" />\r
 \r
     <TextView\r
         android:id="@+id/Filename"\r
-        android:layout_width="95dp"\r
+        android:layout_width="100dp"\r
         android:layout_height="wrap_content"\r
+        android:layout_gravity="center_horizontal"\r
         android:layout_marginLeft="4dp"\r
         android:layout_marginRight="4dp"\r
         android:ellipsize="middle"\r
+        android:gravity="center_horizontal"\r
         android:singleLine="true"\r
         android:text="TextView"\r
         android:textColor="#303030"\r
index 1f51f41..564404a 100644 (file)
             android:id="@+id/list_root"
             android:layout_width="match_parent"
             android:layout_height="match_parent"
-            android:columnWidth="160dp"
+            android:columnWidth="100dp"
             android:gravity="center"
-            android:horizontalSpacing="10dp"
+            android:horizontalSpacing="2dp"
             android:numColumns="auto_fit"
             android:stretchMode="columnWidth"
-            android:verticalSpacing="10dp"
+            android:verticalSpacing="2dp"
             android:visibility="visible" />
+
     </android.support.v4.widget.SwipeRefreshLayout>
 
     <android.support.v4.widget.SwipeRefreshLayout
index 9b347be..c28ff1c 100644 (file)
@@ -22,10 +22,9 @@ import android.content.Context;
 import android.graphics.Canvas;
 import android.util.AttributeSet;
 import android.widget.GridView;
-import android.widget.ListView;
 
 /**
- * ListView allowing to specify the position of an item that should be centered in the visible area, if possible.
+ * GridView allowing to specify the position of an item that should be top left in the visible area, if possible.
  * 
  * The cleanest way I found to overcome the problem due to getHeight() returns 0 until the view is really drawn. 
  *  
@@ -33,7 +32,7 @@ import android.widget.ListView;
  */
 public class ExtendedListView extends GridView {
 
-    private int mPositionToSetAndCenter;
+    private int mPositionToSetTopLeft;
 
     public ExtendedListView(Context context) {
         super(context);
@@ -46,7 +45,7 @@ public class ExtendedListView extends GridView {
     public ExtendedListView(Context context, AttributeSet attrs, int defStyle) {
         super(context, attrs, defStyle);
     }
-
+    
     /**
      * {@inheritDoc}
      * 
@@ -55,21 +54,20 @@ public class ExtendedListView extends GridView {
     @Override
     protected void onDraw (Canvas canvas) {
         super.onDraw(canvas);
-        if (mPositionToSetAndCenter > 0) {
-            this.setSelection(mPositionToSetAndCenter);
-            //this.setSelectionFromTop(mPositionToSetAndCenter, getHeight() / 2);
-            mPositionToSetAndCenter = 0;
+        if (mPositionToSetTopLeft > 0) {
+            this.smoothScrollToPosition(mPositionToSetTopLeft);
+            mPositionToSetTopLeft = 0;
         }
     }
     
     /**
-     * Public method to set the position of the item that should be centered in the visible area of the view.
+     * Public method to set the position of the item that should be top left in the visible area of the view.
      * 
      * The position is saved here and checked in onDraw().
      *  
-     * @param position         Position (in the list of items) of the item to center in the visible area.     
+     * @param position         Position (in the list of items) of the item to be top left in the visible area.     
      */
-    public void setAndCenterSelection(int position) {
-        mPositionToSetAndCenter = position;
+    public void setSelectionAsTopLeft(int position) {
+        mPositionToSetTopLeft = position;
     }
 }
diff --git a/src/com/owncloud/android/ui/SquareImageView.java b/src/com/owncloud/android/ui/SquareImageView.java
new file mode 100644 (file)
index 0000000..3c90999
--- /dev/null
@@ -0,0 +1,25 @@
+package com.owncloud.android.ui;
+
+import android.content.Context;
+import android.util.AttributeSet;
+import android.widget.ImageView;
+
+public class SquareImageView extends ImageView {
+
+    public SquareImageView(Context context) {
+        super(context);
+    }
+
+    public SquareImageView(Context context, AttributeSet attrs) {
+        super(context, attrs);
+    }
+
+    public SquareImageView(Context context, AttributeSet attrs, int defStyle) {
+        super(context, attrs, defStyle);
+    }
+
+    @Override
+    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
+        super.onMeasure(widthMeasureSpec, widthMeasureSpec);
+    }
+}
index 202854f..5997020 100644 (file)
@@ -180,6 +180,10 @@ public class FileListListAdapter extends BaseAdapter implements ListAdapter {
                 localStateView.setVisibility(View.INVISIBLE);\r
             }\r
             \r
+            if (!fileView){\r
+                localStateView.setVisibility(View.GONE);\r
+            }\r
+            \r
             TextView fileSizeV = (TextView) view.findViewById(R.id.file_size);\r
             TextView lastModV = (TextView) view.findViewById(R.id.last_mod);\r
             ImageView checkBoxV = (ImageView) view.findViewById(R.id.custom_checkbox);\r
index 547a3c0..17c3d01 100644 (file)
@@ -201,22 +201,14 @@ implements OnItemClickListener, SwipeRefreshLayout.OnRefreshListener {
             
             int top = mTops.remove(mTops.size() - 1);
             
-            imageView.setSelection(firstPosition);
+            imageView.smoothScrollToPosition(firstPosition);
             
             // Move the scroll if the selection is not visible
             int indexPosition = mHeightCell*index;
             int height = imageView.getHeight();
             
             if (indexPosition > height) {
-                if (android.os.Build.VERSION.SDK_INT >= 11)
-                {
-                    imageView.smoothScrollToPosition(index); 
-                }
-                else if (android.os.Build.VERSION.SDK_INT >= 8)
-                {
-                    imageView.setSelection(index);
-                }
-                
+                imageView.smoothScrollToPosition(index);
             }
         }
     }