From c59685a34e6387c53d2d04160bcd789cc4060f3d Mon Sep 17 00:00:00 2001
From: Alexandre Lision <alexandre.lision@savoirfairelinux.com>
Date: Fri, 4 Oct 2013 16:36:36 -0400
Subject: [PATCH] * #31230: link to contact app

---
 res/layout/item_contact.xml                   | 17 +++++------
 res/values/strings_content_description.xml    |  3 ++
 .../sflphone/adapters/ContactPictureTask.java | 14 +++++----
 .../sflphone/adapters/ContactsAdapter.java    | 29 +++++++++++++++++++
 .../sflphone/client/SFLPhoneHomeActivity.java | 12 ++++++++
 .../fragments/ContactListFragment.java        | 17 ++++++-----
 .../views/SwipeListViewTouchListener.java     | 17 +++++++----
 7 files changed, 81 insertions(+), 28 deletions(-)

diff --git a/res/layout/item_contact.xml b/res/layout/item_contact.xml
index f7a5db161..e4984121e 100644
--- a/res/layout/item_contact.xml
+++ b/res/layout/item_contact.xml
@@ -33,45 +33,44 @@ as that of the covered work.
 
 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
     android:layout_width="match_parent"
-    android:layout_height="match_parent" >
+    android:layout_height="match_parent"
+    android:background="@color/sfl_another_blue" >
 
     <LinearLayout
         android:id="@+id/contact_underview"
         android:layout_width="match_parent"
-        android:layout_height="wrap_content"
+        android:layout_height="match_parent"
+        android:layout_alignParentBottom="true"
+        android:layout_alignParentTop="true"
         android:layout_centerVertical="true"
         android:orientation="horizontal"
-        android:background="@color/sfl_another_blue"
         android:weightSum="6" >
 
         <ImageButton
             android:id="@+id/quick_starred"
             android:layout_width="0dp"
             android:layout_height="match_parent"
-            android:layout_margin="5dp"
             android:layout_weight="1"
             android:background="@null"
-            android:contentDescription="@string/contact_quick_call_description"
+            android:contentDescription="@string/contact_quick_starred_description"
             android:src="@drawable/ic_action_not_important" />
 
         <ImageButton
             android:id="@+id/quick_edit"
             android:layout_width="0dp"
             android:layout_height="match_parent"
-            android:layout_margin="5dp"
             android:layout_weight="1"
             android:background="@null"
-            android:contentDescription="@string/contact_quick_msg_description"
+            android:contentDescription="@string/contact_quick_edit_description"
             android:src="@drawable/ic_action_edit" />
 
         <ImageButton
             android:id="@+id/quick_discard"
             android:layout_width="0dp"
             android:layout_height="match_parent"
-            android:layout_margin="5dp"
             android:layout_weight="1"
             android:background="@null"
-            android:contentDescription="@string/contact_quick_msg_description"
+            android:contentDescription="@string/contact_quick_discard_description"
             android:src="@drawable/ic_action_discard" />
 
         <Space
diff --git a/res/values/strings_content_description.xml b/res/values/strings_content_description.xml
index dc672741a..0469016de 100644
--- a/res/values/strings_content_description.xml
+++ b/res/values/strings_content_description.xml
@@ -3,6 +3,9 @@
     <!-- Strings for xml content description of images -->
     <string name="contact_quick_call_description">Quick Call</string>
     <string name="contact_quick_msg_description">Quick Message</string>
+    <string name="contact_quick_starred_description">Quick Starred</string>
+    <string name="contact_quick_edit_description">Quick Edit</string>
+    <string name="contact_quick_discard_description">Quick Discard</string>
     <string name="contact_picture_description">Contact Picture</string>
     <string name="dial_numeric_pad">Numeric dialpad</string>
     <string name="dial_alphabetic_pad">Alphabetic dialpad</string>
diff --git a/src/org/sflphone/adapters/ContactPictureTask.java b/src/org/sflphone/adapters/ContactPictureTask.java
index 70c33e93d..42b7cd592 100644
--- a/src/org/sflphone/adapters/ContactPictureTask.java
+++ b/src/org/sflphone/adapters/ContactPictureTask.java
@@ -50,6 +50,9 @@ import android.graphics.RectF;
 import android.graphics.Shader;
 import android.net.Uri;
 import android.provider.ContactsContract;
+import android.view.MotionEvent;
+import android.view.View;
+import android.view.View.OnTouchListener;
 import android.widget.ImageView;
 
 public class ContactPictureTask implements Runnable {
@@ -82,7 +85,7 @@ public class ContactPictureTask implements Runnable {
         } catch (IllegalArgumentException e) {
             photo_bmp = null;
         }
-        
+
         if (photo_bmp == null) {
             photo_bmp = decodeSampledBitmapFromResource(view.getResources(), R.drawable.ic_contact_picture, view.getWidth(), view.getHeight());
         }
@@ -95,10 +98,10 @@ public class ContactPictureTask implements Runnable {
         }
 
         final Bitmap externalBMP = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
-        
+
         BitmapShader shader;
         shader = new BitmapShader(photo_bmp, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);
-        
+
         Paint paint = new Paint();
         paint.setAntiAlias(true);
         paint.setShader(shader);
@@ -113,9 +116,8 @@ public class ContactPictureTask implements Runnable {
             }
         });
     }
-    
-    public static Bitmap decodeSampledBitmapFromResource(Resources res, int resId,
-            int reqWidth, int reqHeight) {
+
+    public static Bitmap decodeSampledBitmapFromResource(Resources res, int resId, int reqWidth, int reqHeight) {
 
         // First decode with inJustDecodeBounds=true to check dimensions
         final BitmapFactory.Options options = new BitmapFactory.Options();
diff --git a/src/org/sflphone/adapters/ContactsAdapter.java b/src/org/sflphone/adapters/ContactsAdapter.java
index 4491f6958..7a68361b2 100644
--- a/src/org/sflphone/adapters/ContactsAdapter.java
+++ b/src/org/sflphone/adapters/ContactsAdapter.java
@@ -25,6 +25,7 @@ import android.widget.BaseAdapter;
 import android.widget.ImageView;
 import android.widget.SectionIndexer;
 import android.widget.TextView;
+import android.widget.Toast;
 
 public class ContactsAdapter extends BaseAdapter implements SectionIndexer {
 
@@ -95,6 +96,34 @@ public class ContactsAdapter extends BaseAdapter implements SectionIndexer {
 
             }
         });
+        
+        convertView.findViewById(R.id.quick_starred).setOnClickListener(new OnClickListener() {
+
+            @Override
+            public void onClick(View v) {
+                Toast.makeText(mContext, "Coming soon", Toast.LENGTH_SHORT).show();
+            }
+        });
+        
+        convertView.findViewById(R.id.quick_edit).setOnClickListener(new OnClickListener() {
+
+            @Override
+            public void onClick(View v) {
+                parent.get().mCallbacks.onEditContact(item);
+
+            }
+        });
+        
+        convertView.findViewById(R.id.quick_discard).setOnClickListener(new OnClickListener() {
+
+            @Override
+            public void onClick(View v) {
+                Toast.makeText(mContext, "Coming soon", Toast.LENGTH_SHORT).show();
+
+            }
+        });
+        
+        
 
         convertView.findViewById(R.id.quick_message).setOnClickListener(new OnClickListener() {
 
diff --git a/src/org/sflphone/client/SFLPhoneHomeActivity.java b/src/org/sflphone/client/SFLPhoneHomeActivity.java
index 9e5c75495..17bddf565 100644
--- a/src/org/sflphone/client/SFLPhoneHomeActivity.java
+++ b/src/org/sflphone/client/SFLPhoneHomeActivity.java
@@ -63,9 +63,11 @@ import android.content.IntentFilter;
 import android.content.ServiceConnection;
 import android.content.res.Configuration;
 import android.database.Cursor;
+import android.net.Uri;
 import android.os.Bundle;
 import android.os.IBinder;
 import android.os.RemoteException;
+import android.provider.ContactsContract;
 import android.provider.ContactsContract.CommonDataKinds.Phone;
 import android.provider.ContactsContract.CommonDataKinds.SipAddress;
 import android.support.v4.app.ActionBarDrawerToggle;
@@ -340,6 +342,7 @@ public class SFLPhoneHomeActivity extends Activity implements DialingFragment.Ca
     }
 
     public void launchCallActivity(SipCall infos) {
+
         Log.i(TAG, "Launch Call Activity");
         Bundle bundle = new Bundle();
         Conference tmp = new Conference("-1");
@@ -465,10 +468,19 @@ public class SFLPhoneHomeActivity extends Activity implements DialingFragment.Ca
     public void onTextContact(final CallContact c) {
         // TODO
     }
+    
+    @Override
+    public void onEditContact(final CallContact c) {
+        Intent intent = new Intent(Intent.ACTION_VIEW);
+        Uri uri = Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_URI, String.valueOf(c.getId()));
+        intent.setData(uri);
+        startActivity(intent);
+    }
 
     @Override
     public void onCallContact(final CallContact c) {
 
+        getActionBar().show(); // in case the contact drawer is open
         if (fMenu.getSelectedAccount() == null) {
             // Toast.makeText(this, "No Account Selected", Toast.LENGTH_SHORT).show();
             createAccountDialog().show();
diff --git a/src/org/sflphone/fragments/ContactListFragment.java b/src/org/sflphone/fragments/ContactListFragment.java
index 0bdfede13..1e9216c01 100644
--- a/src/org/sflphone/fragments/ContactListFragment.java
+++ b/src/org/sflphone/fragments/ContactListFragment.java
@@ -39,7 +39,6 @@ import org.sflphone.adapters.StarredContactsAdapter;
 import org.sflphone.loaders.ContactsLoader;
 import org.sflphone.loaders.LoaderConstants;
 import org.sflphone.model.CallContact;
-import org.sflphone.model.Conference;
 import org.sflphone.service.ISipService;
 import org.sflphone.views.SwipeListViewTouchListener;
 import org.sflphone.views.TACGridView;
@@ -48,10 +47,11 @@ import android.animation.LayoutTransition;
 import android.app.Activity;
 import android.app.Fragment;
 import android.app.LoaderManager;
+import android.content.Intent;
 import android.content.Loader;
 import android.net.Uri;
 import android.os.Bundle;
-import android.os.RemoteException;
+import android.provider.ContactsContract;
 import android.provider.ContactsContract.Contacts;
 import android.util.Log;
 import android.view.DragEvent;
@@ -71,7 +71,6 @@ import android.widget.LinearLayout;
 import android.widget.ListView;
 import android.widget.RelativeLayout;
 import android.widget.SearchView;
-import android.widget.Toast;
 import android.widget.SearchView.OnQueryTextListener;
 
 public class ContactListFragment extends Fragment implements OnQueryTextListener, LoaderManager.LoaderCallbacks<Bundle> {
@@ -100,6 +99,10 @@ public class ContactListFragment extends Fragment implements OnQueryTextListener
         @Override
         public void onTextContact(CallContact c) {
         }
+        
+        @Override
+        public void onEditContact(CallContact c) {
+        }
 
         @Override
         public ISipService getService() {
@@ -127,6 +130,8 @@ public class ContactListFragment extends Fragment implements OnQueryTextListener
 
         void openDrawer();
 
+        void onEditContact(CallContact item);
+
     }
 
     @Override
@@ -182,12 +187,10 @@ public class ContactListFragment extends Fragment implements OnQueryTextListener
             }
 
             @Override
-            public void onSwipeRight(ListView listView, int[] reverseSortedPositions) {
+            public void onSwipeRight(ListView listView, final int[] reverseSortedPositions) {
                 // Log.i(ProfileMenuActivity.class.getClass().getName(), "swipe right : pos="+reverseSortedPositions[0]);
                 // TODO : YOUR CODE HERE FOR RIGHT ACTION
-
-                CallContact tmp = mListAdapter.getItem(reverseSortedPositions[0]);
-
+                
             }
         }, true, false));
         list.setOnItemLongClickListener(mItemLongClickListener);
diff --git a/src/org/sflphone/views/SwipeListViewTouchListener.java b/src/org/sflphone/views/SwipeListViewTouchListener.java
index 489543029..38125b913 100644
--- a/src/org/sflphone/views/SwipeListViewTouchListener.java
+++ b/src/org/sflphone/views/SwipeListViewTouchListener.java
@@ -10,6 +10,7 @@ import android.animation.Animator;
 import android.animation.AnimatorListenerAdapter;
 import android.animation.ValueAnimator;
 import android.graphics.Rect;
+import android.util.Log;
 import android.view.MotionEvent;
 import android.view.VelocityTracker;
 import android.view.View;
@@ -24,6 +25,8 @@ public class SwipeListViewTouchListener implements View.OnTouchListener {
     private int mMinFlingVelocity;
     private int mMaxFlingVelocity;
     private long mAnimationTime;
+    
+    private static final String TAG = SwipeListViewTouchListener.class.getSimpleName();
 
     // Fixed properties
     private ListView mListView;
@@ -130,10 +133,12 @@ public class SwipeListViewTouchListener implements View.OnTouchListener {
     }
 
     @Override
-    public boolean onTouch(View view, MotionEvent motionEvent) {
+    public boolean onTouch(View item, MotionEvent motionEvent) {
         if (mViewWidth < 2) {
             mViewWidth = mListView.getWidth();
         }
+        
+        Log.i(TAG,"->onTouch");
 
         switch (motionEvent.getActionMasked()) {
         case MotionEvent.ACTION_DOWN: {
@@ -169,7 +174,7 @@ public class SwipeListViewTouchListener implements View.OnTouchListener {
                 mVelocityTracker.addMovement(motionEvent);
                 mVelocityTracker.recycle();
             }
-            view.onTouchEvent(motionEvent);
+            item.onTouchEvent(motionEvent);
             return true;
         }
 
@@ -206,7 +211,8 @@ public class SwipeListViewTouchListener implements View.OnTouchListener {
                         @Override
                         public void onAnimationEnd(Animator animation) {
                             mListView.requestDisallowInterceptTouchEvent(false);
-                            // performSwipeAction(downView, downPosition, toTheRight,dismissRight);
+//                            mCallback.onSwipeRight(mListView, swipePositions);
+//                             performSwipeAction(downView, downPosition, toTheRight,dismissRight);
                         }
                     });
                 } else {
@@ -234,7 +240,7 @@ public class SwipeListViewTouchListener implements View.OnTouchListener {
             float deltaX = motionEvent.getRawX() - mDownX;
             float deltaY = motionEvent.getRawY() - mDownY;
 
-            if ((deltaX > 0 && deltaY - deltaX > mSlop) || (deltaX < 0 &&  deltaY - deltaX > mSlop)) {
+            if ((deltaX > 0 && deltaY - deltaX > mSlop) || (deltaX < 0 && deltaY - deltaX > mSlop)) {
                 mListView.requestDisallowInterceptTouchEvent(false);
                 return false;
             }
@@ -249,8 +255,7 @@ public class SwipeListViewTouchListener implements View.OnTouchListener {
                 mListView.onTouchEvent(cancelEvent);
                 cancelEvent.recycle();
             }
-
-            if (deltaX < 0 || view.getX() > view.getWidth() / 2)
+            if (deltaX < 0)
                 return true;
 
             if (mSwiping) {
-- 
GitLab