Browse Source

Added swipe listview to the profile manager

Alexander Brakowski 10 years ago
parent
commit
47b667cb27

+ 2 - 1
.gitignore

@@ -24,5 +24,6 @@ proguard/
 *.iws
 .idea/
 
-#Ignore target folder
+#Ignore some folders
 target/
+gen-external-apklibs/

+ 12 - 1
pom.xml

@@ -54,7 +54,18 @@
 			<artifactId>roboguice</artifactId>
 			<version>2.0</version>
 		</dependency>
-	</dependencies>
+        <dependency>
+            <groupId>com.nineoldandroids</groupId>
+            <artifactId>library</artifactId>
+            <version>2.4.0</version>
+        </dependency>
+        <dependency>
+            <groupId>com.fortysevendeg.android</groupId>
+            <artifactId>swipelistview</artifactId>
+            <version>1.0-SNAPSHOT</version>
+            <type>apklib</type>
+        </dependency>
+    </dependencies>
 	<build>
 		<finalName>${project.artifactId}</finalName>
 		<sourceDirectory>src</sourceDirectory>

+ 6 - 3
res/layout/fragment_profile_manager.xml

@@ -7,10 +7,10 @@
     android:layout_height="fill_parent"
     android:id="@+id/profile_manager_root_view">
 
-    <ListView
+    <com.fortysevendeg.android.swipelistview.SwipeListView
         android:layout_width="match_parent"
         android:layout_height="match_parent"
-        xmlns:android="http://schemas.android.com/apk/res/android"
+        xmlns:swipe="http://schemas.android.com/apk/res-auto"
         android:id="@+id/profile_manager_listview"
         android:choiceMode="singleChoice"
         android:background="#F2F2F2"
@@ -21,6 +21,9 @@
         android:layout_marginLeft="0dp"
         android:layout_alignParentTop="true"
         android:layout_marginTop="0dp"
-        android:descendantFocusability="blocksDescendants"/>
+        android:descendantFocusability="blocksDescendants"
+        swipe:swipeFrontView="@+id/profile_manager_item_front"
+        swipe:swipeBackView="@+id/profile_manager_item_back"
+        swipe:swipeMode="both"/>
 
 </RelativeLayout>

+ 65 - 69
res/layout/profile_manager_list_item.xml

@@ -1,74 +1,8 @@
 <?xml version="1.0" encoding="utf-8"?>
 
-<ViewSwitcher xmlns:android="http://schemas.android.com/apk/res/android"
+<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
               android:layout_width="wrap_content"
-              android:layout_height="wrap_content"
-              android:id="@+id/profile_manager_viewswitcher"
-              android:measureAllChildren="true"
-              android:focusable="false">
-
-    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
-        android:id="@+id/profile_manager_item_front"
-        android:layout_width="match_parent"
-        android:layout_height="wrap_content"
-        android:padding="5dp"
-        android:baselineAligned="false"
-        android:background="@drawable/panel_bg"
-        android:focusable="false">
-
-        <TextView
-            android:id="@+id/profile_manager_item_label"
-            android:layout_width="match_parent"
-            android:layout_height="wrap_content"
-            android:textAppearance="?android:attr/textAppearanceListItemSmall"
-            android:gravity="center_vertical"
-            android:paddingLeft="16dp"
-            android:paddingRight="16dp"
-            android:textColor="?android:attr/colorForeground"
-            android:minHeight="?android:attr/listPreferredItemHeightSmall"
-            android:text="Sample title"
-            android:layout_alignParentTop="true"
-            android:layout_toRightOf="@+id/profile_manager_item_image" />
-
-        <TextView
-            android:layout_width="match_parent"
-            android:layout_height="wrap_content"
-            android:text="Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet."
-            android:id="@+id/profile_manager_item_text"
-            android:paddingLeft="16dp"
-            android:paddingRight="16dp"
-            android:paddingBottom="16dp"
-            android:textColor="#808080"
-            android:visibility="visible"
-            android:singleLine="false"
-            android:layout_alignParentLeft="true"
-            android:layout_alignParentStart="true"
-            android:layout_below="@+id/profile_manager_item_label"
-            android:paddingTop="10dp"
-            android:layout_toLeftOf="@+id/profile_manager_item_activated"/>
-
-        <ImageView
-            android:layout_width="wrap_content"
-            android:layout_height="wrap_content"
-            android:id="@+id/profile_manager_item_activated"
-            android:src="@drawable/ic_action_accept"
-            android:layout_centerVertical="true"
-            android:layout_alignParentRight="true"
-            android:layout_alignParentEnd="true"
-            android:layout_marginRight="20dp"
-            android:visibility="visible"
-            android:layout_marginLeft="20dp"/>
-
-        <ImageView
-            android:layout_width="wrap_content"
-            android:layout_height="wrap_content"
-            android:id="@+id/profile_manager_item_image"
-            android:src="@drawable/ic_launcher"
-            android:layout_above="@+id/profile_manager_item_text"
-            android:layout_alignParentLeft="true"
-            android:layout_alignParentStart="true" />
-
-    </RelativeLayout>
+              android:layout_height="wrap_content">
 
     <RelativeLayout
         android:id="@+id/profile_manager_item_back"
@@ -152,4 +86,66 @@
 
     </RelativeLayout>
 
-</ViewSwitcher>
+    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
+                    android:id="@+id/profile_manager_item_front"
+                    android:layout_width="match_parent"
+                    android:layout_height="wrap_content"
+                    android:padding="5dp"
+                    android:baselineAligned="false"
+                    android:background="@drawable/panel_bg"
+                    android:focusable="false">
+
+        <TextView
+            android:id="@+id/profile_manager_item_label"
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content"
+            android:textAppearance="?android:attr/textAppearanceListItemSmall"
+            android:gravity="center_vertical"
+            android:paddingLeft="16dp"
+            android:paddingRight="16dp"
+            android:textColor="?android:attr/colorForeground"
+            android:minHeight="?android:attr/listPreferredItemHeightSmall"
+            android:text="Sample title"
+            android:layout_alignParentTop="true"
+            android:layout_toRightOf="@+id/profile_manager_item_image" />
+
+        <TextView
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content"
+            android:text="Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet."
+            android:id="@+id/profile_manager_item_text"
+            android:paddingLeft="16dp"
+            android:paddingRight="16dp"
+            android:paddingBottom="16dp"
+            android:textColor="#808080"
+            android:visibility="visible"
+            android:singleLine="false"
+            android:layout_alignParentLeft="true"
+            android:layout_alignParentStart="true"
+            android:layout_below="@+id/profile_manager_item_label"
+            android:paddingTop="10dp"
+            android:layout_toLeftOf="@+id/profile_manager_item_activated"/>
+
+        <ImageView
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:id="@+id/profile_manager_item_activated"
+            android:src="@drawable/ic_action_accept"
+            android:layout_centerVertical="true"
+            android:layout_alignParentRight="true"
+            android:layout_alignParentEnd="true"
+            android:layout_marginRight="20dp"
+            android:visibility="visible"
+            android:layout_marginLeft="20dp"/>
+
+        <ImageView
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:id="@+id/profile_manager_item_image"
+            android:src="@drawable/ic_launcher"
+            android:layout_above="@+id/profile_manager_item_text"
+            android:layout_alignParentLeft="true"
+            android:layout_alignParentStart="true" />
+
+    </RelativeLayout>
+</FrameLayout>

+ 10 - 5
src/de/tudarmstadt/informatik/hostage/ui2/adapter/ProfileManagerListAdapter.java

@@ -14,6 +14,8 @@ import android.widget.RelativeLayout;
 import android.widget.TextView;
 import android.widget.ViewSwitcher;
 
+import com.fortysevendeg.android.swipelistview.SwipeListView;
+
 import java.util.List;
 
 import de.tudarmstadt.informatik.hostage.R;
@@ -81,7 +83,7 @@ public class ProfileManagerListAdapter extends ArrayAdapter<ProfileListItem> {
 		    holder.itemIcon = (ImageView) rowView.findViewById(R.id.profile_manager_item_image);
 		    holder.buttonEdit = (ImageButton) rowView.findViewById(R.id.profile_manager_item_button_edit);
 		    holder.buttonDelete = (ImageButton) rowView.findViewById(R.id.profile_manager_item_button_delete);
-			holder.switcher = (ViewSwitcher) rowView.findViewById(R.id.profile_manager_viewswitcher);
+			//holder.switcher = (ViewSwitcher) rowView.findViewById(R.id.profile_manager_viewswitcher);
 			holder.itemIconBack = (ImageView) rowView.findViewById(R.id.profile_manager_item_image_back);
 		    holder.labelViewBack = (TextView) rowView.findViewById(R.id.profile_manager_item_label_back);
 
@@ -90,7 +92,9 @@ public class ProfileManagerListAdapter extends ArrayAdapter<ProfileListItem> {
 		    holder = (ViewHolder) rowView.getTag();
 	    }
 
-	    final ViewSwitcher switcher = holder.switcher;
+	    ((SwipeListView)parent).recycle(rowView, position);
+
+	    /*final ViewSwitcher switcher = holder.switcher;
 
 	    holder.switcher.setOnTouchListener(new OnSwipeTouchListener(){
 		    public void onSwipeRight() {
@@ -116,7 +120,7 @@ public class ProfileManagerListAdapter extends ArrayAdapter<ProfileListItem> {
 	    holder.buttonDelete.setFocusable(false);
 	    holder.buttonEdit.setFocusableInTouchMode(false);
 	    holder.buttonDelete.setFocusableInTouchMode(false);
-
+*/
 
 	    holder.textView.setText(item.label);
 	    holder.labelView.setText(item.text);
@@ -124,7 +128,7 @@ public class ProfileManagerListAdapter extends ArrayAdapter<ProfileListItem> {
 	    holder.itemIconBack.setImageBitmap(item.icon);
 	    holder.itemIcon.setImageBitmap(item.icon);
 
-		holder.switcher.setInAnimation(null);
+		/*holder.switcher.setInAnimation(null);
 	    holder.switcher.setOutAnimation(null);
 	    if(item.isBackVisible){
 		    holder.switcher.setDisplayedChild(1);
@@ -133,7 +137,8 @@ public class ProfileManagerListAdapter extends ArrayAdapter<ProfileListItem> {
 	    }
 
 	    holder.switcher.setInAnimation(inAnimationRL);
-		holder.switcher.setOutAnimation(outAnimationRL);
+		holder.switcher.setOutAnimation(outAnimationRL);*/
+
         if(!item.activated){
             RelativeLayout.LayoutParams lp = (RelativeLayout.LayoutParams )holder.textView.getLayoutParams();
             lp.setMargins(0,0,0,0);

+ 3 - 1
src/de/tudarmstadt/informatik/hostage/ui2/fragment/ProfileManagerFragment.java

@@ -7,6 +7,8 @@ import android.view.View;
 import android.view.ViewGroup;
 import android.widget.ListView;
 
+import com.fortysevendeg.android.swipelistview.SwipeListView;
+
 import java.util.ArrayList;
 
 import de.tudarmstadt.informatik.hostage.R;
@@ -29,7 +31,7 @@ public class ProfileManagerFragment extends Fragment {
 
         View rootView = inflater.inflate(R.layout.fragment_profile_manager, container, false);
 
-        ListView list = (ListView) rootView.findViewById(R.id.profile_manager_listview);
+	    SwipeListView list = (SwipeListView) rootView.findViewById(R.id.profile_manager_listview);
 
 	    list.setItemsCanFocus(false);