Browse Source

Merge branch 'master' of https://git.tk.informatik.tu-darmstadt.de/scm-ssi-student-hostagev2

Fabio Arnold 10 years ago
parent
commit
8f2f234757

BIN
res/drawable-hdpi/ic_discard.png


BIN
res/drawable-hdpi/ic_edit.png


BIN
res/drawable-mdpi/ic_discard.png


BIN
res/drawable-mdpi/ic_edit.png


BIN
res/drawable-xhdpi/ic_discard.png


BIN
res/drawable-xhdpi/ic_edit.png


+ 14 - 0
res/drawable/panel_white_bg.xml

@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="utf-8"?>
+<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
+
+    <!-- Bottom 3dp Shadow -->
+    <item>
+        <shape android:shape="rectangle">
+
+            <solid android:color="#FFFFFF" />
+            <corners android:radius="4dp" />
+
+        </shape>
+    </item>
+
+</layer-list>

+ 2 - 1
res/layout/fragment_profile_manager.xml

@@ -20,6 +20,7 @@
         android:layout_alignParentLeft="true"
         android:layout_marginLeft="0dp"
         android:layout_alignParentTop="true"
-        android:layout_marginTop="0dp" />
+        android:layout_marginTop="0dp"
+        android:descendantFocusability="blocksDescendants"/>
 
 </RelativeLayout>

+ 149 - 56
res/layout/profile_manager_list_item.xml

@@ -1,62 +1,155 @@
 <?xml version="1.0" encoding="utf-8"?>
 
-<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
-    android:layout_width="match_parent"
-    android:layout_height="wrap_content"
-    android:padding="5dp"
-    android:baselineAligned="false"
-    android:background="@drawable/panel_bg">
-
-    <TextView
-        android:id="@+id/profile_manager_item_label"
+<ViewSwitcher 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: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: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>
+
+    <RelativeLayout
+        android:id="@+id/profile_manager_item_back"
+        android:orientation="horizontal"
         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:phoneNumber="true"
-        android:layout_toLeftOf="@+id/profile_manager_item_activated"
-        android:layout_alignParentLeft="true"
-        android:layout_alignParentStart="true"
-        android:layout_below="@+id/profile_manager_item_label"
-        android:paddingTop="10dp" />
-
-    <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" />
-
-    <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" />
+        android:layout_height="match_parent"
+        android:background="@drawable/panel_white_bg"
+        android:focusable="false">
+
+        <LinearLayout
+            android:orientation="horizontal"
+            android:layout_width="fill_parent"
+            android:layout_height="fill_parent"
+            android:focusable="false"
+            android:layout_below="@+id/profile_manager_item_image_back">
+
+            <ImageButton
+                android:layout_width="0dp"
+                android:layout_height="match_parent"
+                android:text="Edit"
+                android:id="@+id/profile_manager_item_button_edit"
+                android:layout_weight="1"
+                style="@android:style/DeviceDefault.Light.ButtonBar"
+                android:focusable="false"
+                android:layout_alignParentTop="true"
+                android:layout_alignParentLeft="true"
+                android:layout_alignParentStart="true"
+                android:src="@drawable/ic_edit"/>
+            <View
+                android:layout_width="1dp"
+                android:layout_height="match_parent"
+                android:background="@color/light_grey"
+                android:layout_marginTop="10dp"
+                android:layout_marginBottom="10dp"/>
+
+            <ImageButton
+                android:layout_width="0dp"
+                android:layout_height="match_parent"
+                android:text="Delete"
+                android:id="@+id/profile_manager_item_button_delete"
+                android:layout_alignParentTop="true"
+                android:layout_alignParentRight="true"
+                android:layout_alignParentEnd="true"
+                android:layout_weight="1"
+                style="@android:style/DeviceDefault.Light.ButtonBar"
+                android:focusable="false"
+                android:layout_marginTop="0dp"
+                android:src="@drawable/ic_discard"/>
+        </LinearLayout>
+
+        <ImageView
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:id="@+id/profile_manager_item_image_back"
+            android:src="@drawable/ic_launcher"
+            android:layout_toLeftOf="@+id/profile_manager_item_label_back"
+            android:layout_alignBottom="@+id/profile_manager_item_label_back"
+            android:layout_alignParentTop="true"
+            android:paddingLeft="15dp"
+            android:paddingTop="15dp"
+            android:paddingBottom="15dp"
+            android:paddingRight="-10dp"/>
+
+        <TextView
+            android:id="@+id/profile_manager_item_label_back"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:gravity="center_vertical"
+            android:paddingLeft="0dp"
+            android:paddingRight="0dp"
+            android:textColor="?android:attr/colorForeground"
+            android:minHeight="?android:attr/listPreferredItemHeightSmall"
+            android:text="Sample title"
+            android:background="@android:color/transparent"
+            android:singleLine="true"
+            android:layout_alignParentLeft="false"
+            android:textAlignment="center"
+            android:layout_centerHorizontal="true"
+            android:textSize="8sp"
+            android:layout_alignParentTop="true"/>
+
+    </RelativeLayout>
 
-</RelativeLayout>
+</ViewSwitcher>

+ 124 - 17
src/de/tudarmstadt/informatik/hostage/ui2/adapter/ProfileManagerListAdapter.java

@@ -2,17 +2,21 @@ package de.tudarmstadt.informatik.hostage.ui2.adapter;
 
 import android.content.Context;
 import android.view.LayoutInflater;
+import android.view.MotionEvent;
 import android.view.View;
 import android.view.ViewGroup;
+import android.view.animation.Animation;
+import android.view.animation.AnimationUtils;
 import android.widget.ArrayAdapter;
+import android.widget.ImageButton;
 import android.widget.ImageView;
 import android.widget.RelativeLayout;
 import android.widget.TextView;
+import android.widget.ViewSwitcher;
 
 import java.util.List;
 
 import de.tudarmstadt.informatik.hostage.R;
-import de.tudarmstadt.informatik.hostage.ui2.model.DrawerListItem;
 import de.tudarmstadt.informatik.hostage.ui2.model.ProfileListItem;
 
 /**
@@ -20,40 +24,143 @@ import de.tudarmstadt.informatik.hostage.ui2.model.ProfileListItem;
  * @created 14.01.14 18:00
  */
 public class ProfileManagerListAdapter extends ArrayAdapter<ProfileListItem> {
+	private class ViewHolder {
+		public TextView labelView;
+		public TextView textView;
+		public ImageView imageSelected;
+		public ImageView itemIcon;
+		public ImageButton buttonEdit;
+		public ImageButton buttonDelete;
+		public ViewSwitcher switcher;
+
+		public ImageView itemIconBack;
+		public TextView labelViewBack;
+	}
+
     private final Context context;
     private final List<ProfileListItem> values;
+	private float mLastX, upX;
+	private static final int MIN_DISTANCE = 50;
+	private Animation inAnimation;
 
     public ProfileManagerListAdapter(Context context, List<ProfileListItem> objects) {
-        super(context, R.layout.drawer_list_item, objects);
+        super(context, R.layout.profile_manager_list_item, objects);
         this.context = context;
         this.values  = objects;
+
+	    inAnimation = AnimationUtils.loadAnimation(getContext(), R.anim.in_right_to_left);
     }
 
+
     @Override
-    public View getView(int position, View convertView, ViewGroup parent) {
-        LayoutInflater inflater = (LayoutInflater) context
-                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
+    public View getView(final int position, View convertView, ViewGroup parent) {
+	    LayoutInflater inflater = (LayoutInflater) context
+			    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
+
+        View rowView = convertView;
+	    ViewHolder holder = null;
+
+	    final ProfileListItem item = values.get(position);
+
+	    if(rowView == null){
+		    rowView = inflater.inflate(R.layout.profile_manager_list_item, parent, false);
+
+		    holder = new ViewHolder();
+		    holder.labelView = (TextView) rowView.findViewById(R.id.profile_manager_item_label);
+		    holder.textView = (TextView) rowView.findViewById(R.id.profile_manager_item_text);
+		    holder.imageSelected = (ImageView) rowView.findViewById(R.id.profile_manager_item_activated);
+		    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.itemIconBack = (ImageView) rowView.findViewById(R.id.profile_manager_item_image_back);
+		    holder.labelViewBack = (TextView) rowView.findViewById(R.id.profile_manager_item_label_back);
+
+		    rowView.setTag(holder);
+	    } else {
+		    holder = (ViewHolder) rowView.getTag();
+	    }
+
+	    holder.switcher.setOnTouchListener(new View.OnTouchListener(){
+		    @Override
+		    public boolean onTouch(View v, MotionEvent event) {
+			    float currentX = event.getX();
+
+			    ViewHolder holder = (ViewHolder) v.getTag();
+
+			    System.out.println("_______________ MOTION! " + event.toString());
+			    switch(event.getAction()) {
+				    case  MotionEvent.ACTION_DOWN:
+					    mLastX = currentX;
+					    return true;
+				    case MotionEvent.ACTION_MOVE:
+					    return true;
+				    case MotionEvent.ACTION_UP:
+					    upX = event.getX();
 
-        View rowView = inflater.inflate(R.layout.profile_manager_list_item, parent, false);
-        TextView labelView = (TextView) rowView.findViewById(R.id.profile_manager_item_label);
-        TextView textView = (TextView) rowView.findViewById(R.id.profile_manager_item_text);
-        ImageView imageSelected = (ImageView) rowView.findViewById(R.id.profile_manager_item_activated);
-		ImageView itemIcon = (ImageView) rowView.findViewById(R.id.profile_manager_item_image);
+					    float deltaX = mLastX - upX;
 
-        ProfileListItem item = values.get(position);
-        textView.setText(item.label);
-        labelView.setText(item.text);
-		itemIcon.setImageBitmap(item.icon);
+					    // horizontal swipe detection
+					    if (Math.abs(deltaX) > MIN_DISTANCE) {
+						    if (deltaX < 0) {
+							    // swipe left to right
+							    if(item.isBackVisible){
+								    holder.switcher.setDisplayedChild(0);
+								    item.isBackVisible = false;
+							    }
+
+							    return true;
+						    }
+						    if (deltaX > 0) {
+							    // swipe right to left
+							    if(!item.isBackVisible){
+								    holder.switcher.setDisplayedChild(1);
+								    item.isBackVisible = true;
+							    }
+
+							    return true;
+						    }
+					    }
+
+					    break;
+			    }
+			    return false;
+		    }
+	    });
+
+	    holder.buttonEdit.setFocusable(false);
+	    holder.buttonDelete.setFocusable(false);
+	    holder.buttonEdit.setFocusableInTouchMode(false);
+	    holder.buttonDelete.setFocusableInTouchMode(false);
+
+
+	    holder.textView.setText(item.label);
+	    holder.labelView.setText(item.text);
+	    holder.labelViewBack.setText(item.text);
+	    holder.itemIconBack.setImageBitmap(item.icon);
+	    holder.itemIcon.setImageBitmap(item.icon);
+
+		holder.switcher.setInAnimation(null);
+	    if(item.isBackVisible){
+		    holder.switcher.setDisplayedChild(1);
+	    } else {
+		    holder.switcher.setDisplayedChild(0);
+	    }
+
+	    holder.switcher.setInAnimation(inAnimation);
 
         if(!item.activated){
-            RelativeLayout.LayoutParams lp = (RelativeLayout.LayoutParams )textView.getLayoutParams();
+            RelativeLayout.LayoutParams lp = (RelativeLayout.LayoutParams )holder.textView.getLayoutParams();
             lp.setMargins(0,0,0,0);
 
-            textView.setLayoutParams(lp);
+	        holder.textView.setLayoutParams(lp);
 
-            imageSelected.setVisibility(View.GONE);
+	        holder.imageSelected.setVisibility(View.GONE);
         }
 
+
         return rowView;
     }
+
+
 }

+ 2 - 0
src/de/tudarmstadt/informatik/hostage/ui2/fragment/HomeFragment.java

@@ -136,6 +136,8 @@ public class HomeFragment extends Fragment {
     public View onCreateView(LayoutInflater inflater, ViewGroup container,
                              Bundle savedInstanceState) {
 
+	    super.onCreateView(inflater, container, savedInstanceState);
+
         rootView = inflater.inflate(R.layout.fragment_home, container, false);
 	    assignViews();
 

+ 12 - 7
src/de/tudarmstadt/informatik/hostage/ui2/fragment/ProfileManagerFragment.java

@@ -25,32 +25,37 @@ public class ProfileManagerFragment extends Fragment {
     public View onCreateView(LayoutInflater inflater, ViewGroup container,
                              Bundle savedInstanceState) {
 
+	    super.onCreateView(inflater, container, savedInstanceState);
+
         View rootView = inflater.inflate(R.layout.fragment_profile_manager, container, false);
 
         ListView list = (ListView) rootView.findViewById(R.id.profile_manager_listview);
 
-        ArrayList<ProfileListItem> strList = new ArrayList<ProfileListItem>();
+	    list.setItemsCanFocus(false);
 
-        ProfileListItem nitem = new ProfileListItem(
-                "Windows 7",
-                "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat.",
-                R.drawable.ic_profile_w7);
+        ArrayList<ProfileListItem> strList = new ArrayList<ProfileListItem>();
 
-        nitem.activated = true;
 
-        strList.add(nitem);
         strList.add(new ProfileListItem(
                 "Windows Vista",
 		        "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat.",
 		        R.drawable.ic_profile_vista));
+
+	    strList.add(new ProfileListItem(
+			    "Windows 7",
+			    "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat.",
+			    R.drawable.ic_profile_w7));
+
         strList.add(new ProfileListItem(
                 "Unix Distro",
 		        "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat.",
 		        R.drawable.ic_profile_unix));
+
         strList.add(new ProfileListItem(
                 "Random",
 		        "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat.",
 		        R.drawable.ic_service_green));
+
 	    strList.add(new ProfileListItem(
 			    "Mix",
 			    "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat.",

+ 2 - 0
src/de/tudarmstadt/informatik/hostage/ui2/model/ProfileListItem.java

@@ -16,6 +16,8 @@ public class ProfileListItem {
     public boolean activated;
     public Bitmap icon;
 
+	public boolean isBackVisible = false;
+
     public ProfileListItem(String text, String label, Bitmap icon){
         this.text = text;
         this.label = label;