Projects >> Android-Application >>b72c33e0fe47f9c5c08c6fc5bc6b11844763bca9

Chunk
Conflicting content
		launchAddMoneyView();
	}

<<<<<<< HEAD
	@Override
	public void onResume() {
		super.onResume();
		tracker.trackPageView("AddMoneyActivity");

	}

	@Override
	public void onPause() {
		super.onPause();
	}

=======
>>>>>>> 31a4072af63868cb5dc09a90683f893d7dca6010

	protected void launchAddMoneyView() {
		setContentView(R.layout.money_amount_controller);
Solution content
		launchAddMoneyView();
	}

	@Override
	public void onResume() {
		super.onResume();
		tracker.trackPageView("Amount");

	}

	protected void launchAddMoneyView() {
		setContentView(R.layout.money_amount_controller);
File
AddMoneyActivity.java
Developer's decision
Manual
Kind of conflict
Annotation
Method declaration
Chunk
Conflicting content
package me.pdthx;

<<<<<<< HEAD

=======
import android.content.pm.ActivityInfo;
>>>>>>> 31a4072af63868cb5dc09a90683f893d7dca6010
import java.io.FileNotFoundException;
import java.io.IOException;
import java.net.MalformedURLException;
Solution content
package me.pdthx;

import android.content.pm.ActivityInfo;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.net.MalformedURLException;
File
BaseActivity.java
Developer's decision
Version 2
Kind of conflict
Import
Chunk
Conflicting content
import android.view.MenuItem;

public class BaseActivity extends Activity {
<<<<<<< HEAD
	
	public static final String TAG = "BaseActivity";
	protected SharedPreferences prefs;
	protected AlertDialog alertDialog;
	protected ProgressDialog progressDialog;

	protected Facebook facebook = new Facebook("332189543469634");
	protected AsyncFacebookRunner mAsyncRunner = new AsyncFacebookRunner(
			facebook);
	protected static boolean signedInViaFacebook = false;
	protected static ArrayList friendsList = new ArrayList();
	private static boolean contactListAdded = false;
	protected static boolean facebookFriendsAdded = false;
	private ContactList contactList;

	protected int RETURNFROM_PROFILESETUP = 10;
	
	GoogleAnalyticsTracker tracker;
	private ZubhiumSDK sdk;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		
		tracker = GoogleAnalyticsTracker.getInstance();
		tracker.startNewSession("UA-30208011-10", 5, this);
		setContentView(R.layout.main);
		
		prefs = PreferenceManager.getDefaultSharedPreferences(this);

		signedInViaFacebook = prefs.getBoolean("signedInViaFacebook", false);

		alertDialog = new AlertDialog.Builder(BaseActivity.this).create();
		progressDialog = new ProgressDialog(BaseActivity.this);
		
		Editor editor = prefs.edit();
		editor.putString("deviceToken", Secure.getString(getBaseContext().getContentResolver(),
				Secure.ANDROID_ID));
		editor.commit();

		sdk = ZubhiumSDK.getZubhiumSDKInstance(this, getString(R.string.secret_key));

		if(sdk != null){
			sdk.setCrashReportingMode(CrashReportingMode.SILENT);
		}

		if (!contactListAdded && friendsList.size() == 0) {
			contactList = new ContactList(getBaseContext());
			friendsList.addAll(contactList.getContacts());
			contactListAdded = true;
		}

		validateFBLogin();

		if (signedInViaFacebook && !facebookFriendsAdded) {
			requestFacebookFriends();
		}

	}
	
	public void registerPushNotifications() {
		Intent registrationIntent = new Intent("com.google.android.c2dm.intent.REGISTER");
		registrationIntent.putExtra("app", PendingIntent.getBroadcast(this, 1, new Intent(), 0));
		registrationIntent.putExtra("sender", "android.paidthx@gmail.com");
		startService(registrationIntent);
	}
	

	private void validateFBLogin() {
		String access_token = prefs.getString("access_token", null);
		long expires = prefs.getLong("access_expires", 0);
		if (access_token != null) {
			facebook.setAccessToken(access_token);
		}
		if (expires != 0) {
			facebook.setAccessExpires(expires);
		}
	}
	
	public void signInWithFacebook(String[] permissions) {
		facebook.authorize(this, permissions, 2,
				new DialogListener() {
					public void onComplete(Bundle values) {
						Editor editor = prefs.edit();
						editor.putString("access_token",
								facebook.getAccessToken());
						editor.putLong("access_expires",
								facebook.getAccessExpires());
						editor.commit();
					}

					public void onFacebookError(FacebookError error) {
						Log.d(error.toString(), error.toString());
						
					}

					public void onError(DialogError e) {
						Log.d(e.toString(), e.toString());
					}

					public void onCancel() {
						Log.d("Canceled", "Canceled");
					}
				});
	}

	private void requestFacebookFriends() {

		if (signedInViaFacebook && !facebookFriendsAdded) {
			mAsyncRunner.request("me/friends", new RequestListener(){

				@Override
				public void onComplete(String response, Object state) {

					try {
						JSONObject json = new JSONObject(response);
						JSONArray d = json.getJSONArray("data");
						int l = (d != null ? d.length() : 0);
						Log.d("Requesting Friends, BaseActivity", "d.length(): " + l);
						for (int i=0; i friendsList = new ArrayList();
    private static boolean contactListAdded = false;
    protected static boolean facebookFriendsAdded = false;
    private ContactList contactList;
    protected static Thread contactThread;

    protected int RETURNFROM_PROFILESETUP = 10;

    private ZubhiumSDK sdk;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
        prefs = PreferenceManager.getDefaultSharedPreferences(this);

        signedInViaFacebook = prefs.getBoolean("signedInViaFacebook", false);

        alertDialog = new AlertDialog.Builder(BaseActivity.this).create();
        progressDialog = new ProgressDialog(BaseActivity.this);

        Editor editor = prefs.edit();
        editor.putString("deviceToken", Secure.getString(getBaseContext().getContentResolver(),
            Secure.ANDROID_ID));
        editor.commit();

        sdk = ZubhiumSDK.getZubhiumSDKInstance(this, getString(R.string.secret_key));

        if(sdk != null){
            sdk.setCrashReportingMode(CrashReportingMode.SILENT);
        }

        validateFBLogin();

        if (signedInViaFacebook && !facebookFriendsAdded)
        {
            if (friendsList.size() == 0)
            {
                requestFacebookFriends();
            }
            else
            {
                facebookFriendsAdded = true;
            }
        }

        if (contactList == null || contactList.getContacts().size() == 0)
        {
            Runnable run = new Runnable() {
                public void run() {
                    contactList = new ContactList(getBaseContext());
                    friendsList.addAll(contactList.getContacts());
                }
            };

            if (!contactListAdded)
            {
                contactListAdded = true;
                contactThread = new Thread(run);
                contactThread.start();
            }
        }
        else
        {
            friendsList.addAll(contactList.getContacts());
            contactListAdded = true;
        }

    }

    public void registerPushNotifications() {
        Intent registrationIntent = new Intent("com.google.android.c2dm.intent.REGISTER");
        registrationIntent.putExtra("app", PendingIntent.getBroadcast(this, 1, new Intent(), 0));
        registrationIntent.putExtra("sender", "android.paidthx@gmail.com");
        startService(registrationIntent);
    }


    private void validateFBLogin() {
        String access_token = prefs.getString("access_token", null);
        long expires = prefs.getLong("access_expires", 0);
        if (access_token != null) {
            facebook.setAccessToken(access_token);
        }
        if (expires != 0) {
            facebook.setAccessExpires(expires);
        }
    }

    public void signInWithFacebook(String[] permissions) {
        if (!facebook.isSessionValid())
        {

            facebook.authorize(this, permissions, 2,
                new DialogListener() {
                public void onComplete(Bundle values) {
                    Editor editor = prefs.edit();
                    editor.putString("access_token",
                        facebook.getAccessToken());
                    editor.putLong("access_expires",
                        facebook.getAccessExpires());
                    editor.commit();
                }

                public void onFacebookError(FacebookError error) {
                    Log.d(error.toString(), error.toString());

                }

                public void onError(DialogError e) {
                    Log.d(e.toString(), e.toString());
                }

                public void onCancel() {
                    Log.d("Canceled", "Canceled");
                }
            });
        }
    }

    private void requestFacebookFriends() {

        if (signedInViaFacebook && !facebookFriendsAdded) {
            facebookFriendsAdded = true;
            mAsyncRunner.request("me/friends", new RequestListener(){

                @Override
                public void onComplete(String response, Object state) {

                    try {
                        JSONObject json = new JSONObject(response);
                        JSONArray d = json.getJSONArray("data");
                        int l = (d != null ? d.length() : 0);
                        Log.d("Requesting Friends, BaseActivity", "d.length(): " + l);
                        for (int i=0; i>>>>>> 31a4072af63868cb5dc09a90683f893d7dca6010

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
Solution content
import android.view.MenuItem;

public class BaseActivity extends Activity {

	public static final String TAG = "BaseActivity";
	protected SharedPreferences prefs;
	protected AlertDialog alertDialog;
	protected ProgressDialog progressDialog;

	protected Facebook facebook = new Facebook("332189543469634");
							facebook.getAccessToken());
	protected AsyncFacebookRunner mAsyncRunner = new AsyncFacebookRunner(
			facebook);
	protected static boolean signedInViaFacebook = false;
	protected static ArrayList friendsList = new ArrayList();
	private static boolean contactListAdded = false;
	protected static boolean facebookFriendsAdded = false;
	private ContactList contactList;
	protected static Thread contactThread;

	protected int RETURNFROM_PROFILESETUP = 10;

	protected GoogleAnalyticsTracker tracker;
	private ZubhiumSDK sdk;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		tracker = GoogleAnalyticsTracker.getInstance();
		tracker.startNewSession("UA-30208011-10", 5, this);
		setContentView(R.layout.main);

		setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
		prefs = PreferenceManager.getDefaultSharedPreferences(this);

		signedInViaFacebook = prefs.getBoolean("signedInViaFacebook", false);

		alertDialog = new AlertDialog.Builder(BaseActivity.this).create();
		progressDialog = new ProgressDialog(BaseActivity.this);

		Editor editor = prefs.edit();
		editor.putString("deviceToken", Secure.getString(getBaseContext().getContentResolver(),
				Secure.ANDROID_ID));
		editor.commit();

		sdk = ZubhiumSDK.getZubhiumSDKInstance(this, getString(R.string.secret_key));

		if(sdk != null){
			sdk.setCrashReportingMode(CrashReportingMode.SILENT);
		}

		validateFBLogin();

		if (signedInViaFacebook && !facebookFriendsAdded)
		{
			if (friendsList.size() == 0)
			{
				requestFacebookFriends();
			}
			else
			{
				facebookFriendsAdded = true;
			}
		}

		if (contactList == null || contactList.getContacts().size() == 0)
		{
			Runnable run = new Runnable() {
				public void run() {
					contactList = new ContactList(getBaseContext());
					friendsList.addAll(contactList.getContacts());
				}
			};

			if (!contactListAdded)
			{
				contactListAdded = true;
				contactThread = new Thread(run);
				contactThread.start();
			}
		}
		else
		{
			friendsList.addAll(contactList.getContacts());
			contactListAdded = true;
		}

	}

	public void registerPushNotifications() {
		Intent registrationIntent = new Intent("com.google.android.c2dm.intent.REGISTER");
		registrationIntent.putExtra("app", PendingIntent.getBroadcast(this, 1, new Intent(), 0));
		registrationIntent.putExtra("sender", "android.paidthx@gmail.com");
		startService(registrationIntent);
	}


	private void validateFBLogin() {
		String access_token = prefs.getString("access_token", null);
		long expires = prefs.getLong("access_expires", 0);
		if (access_token != null) {
			facebook.setAccessToken(access_token);
		}
		if (expires != 0) {
			facebook.setAccessExpires(expires);
		}
	}

	public void signInWithFacebook(String[] permissions) {
		if (!facebook.isSessionValid())
		{
			facebook.authorize(this, permissions, 2,
					new DialogListener() {
				public void onComplete(Bundle values) {
					Editor editor = prefs.edit();
					editor.putString("access_token",
					editor.putLong("access_expires",
							facebook.getAccessExpires());
					editor.commit();
				}

				public void onFacebookError(FacebookError error) {
					Log.d(error.toString(), error.toString());

				}

				public void onError(DialogError e) {
					Log.d(e.toString(), e.toString());
				}

				public void onCancel() {
					Log.d("Canceled", "Canceled");
				}
			});
		}
	}

	private void requestFacebookFriends() {

		if (signedInViaFacebook && !facebookFriendsAdded) {
			mAsyncRunner.request("me/friends", new RequestListener(){

				@Override
				public void onComplete(String response, Object state) {

					try {
						JSONObject json = new JSONObject(response);
						JSONArray d = json.getJSONArray("data");
						int l = (d != null ? d.length() : 0);
						Log.d("Requesting Friends, BaseActivity", "d.length(): " + l);
						for (int i=0; i
File
BaseActivity.java
Developer's decision
Manual
Kind of conflict
Annotation
Attribute
If statement
Method declaration
Method invocation
Method signature
Variable
Chunk
Conflicting content
public class ContactList {

<<<<<<< HEAD
	private ArrayList contactsList = new ArrayList();
	private Random random = new Random();
	
	public ContactList(Context context) {


		Cursor cursor = context.getContentResolver().query(ContactsContract.Contacts.CONTENT_URI,null, null, null, null); 
		while (cursor.moveToNext()) { 
			String hasPhone = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER)); 
			if (hasPhone.equals("1")) { 
				// You know it has a number so now query it like this
				String contactId = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts._ID));
				Cursor phones = context.getContentResolver().query( ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, ContactsContract.CommonDataKinds.Phone.CONTACT_ID +" = "+ contactId, null, null); 
				while (phones.moveToNext()) {
					Friend friend = new Friend();
					String name = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
					String phoneNumber = phones.getString(phones.getColumnIndex( ContactsContract.CommonDataKinds.Phone.NUMBER));
					friend.setId(new UUID(random.nextLong(), random.nextLong()).toString());
					friend.setName(name);
					friend.setPhoneNumber(phoneNumber);
					friend.setPicture(BitmapFactory.decodeResource(context.getResources(), R.drawable.person_icon_small));
					contactsList.add(friend);
				} 
				phones.close(); 
			}

//			Cursor emails = context.getContentResolver().query(ContactsContract.CommonDataKinds.Email.CONTENT_URI, null, ContactsContract.CommonDataKinds.Email.CONTACT_ID + " = " + contactId, null, null); 
//			while (emails.moveToNext()) { 
//				// This would allow you get several email addresses 
//				String emailAddress = emails.getString( 
//						emails.getColumnIndex(ContactsContract.CommonDataKinds.Email.ADDRESS));
//				
//			} 
//			emails.close(); 
		}
		
		cursor.close();

	}

	public ArrayList getContacts() {
		return contactsList;
	}
=======
    private ArrayList contactsList = new ArrayList();
>>>>>>> 31a4072af63868cb5dc09a90683f893d7dca6010

    public ContactList(Context context) {
Solution content
public class ContactList {

    private ArrayList contactsList = new ArrayList();

    public ContactList(Context context) {
File
ContactList.java
Developer's decision
Version 2
Kind of conflict
Attribute
Method declaration
Method invocation
Chunk
Conflicting content
package me.pdthx;

<<<<<<< HEAD

=======
import me.pdthx.helpers.PhoneNumberFormatter;
import android.app.ProgressDialog;
import android.provider.ContactsContract;
import android.net.Uri;
import java.io.InputStream;
>>>>>>> 31a4072af63868cb5dc09a90683f893d7dca6010
import java.io.IOException;
import java.net.URL;
import java.util.ArrayList;
Solution content
package me.pdthx;

import me.pdthx.helpers.PhoneNumberFormatter;
import android.app.ProgressDialog;
import android.provider.ContactsContract;
import android.net.Uri;
import java.io.InputStream;
import java.io.IOException;
import java.net.URL;
import java.util.ArrayList;
File
FriendsListActivity.java
Developer's decision
Version 2
Kind of conflict
Import
Chunk
Conflicting content

public final class FriendsListActivity extends BaseActivity  {

<<<<<<< HEAD
	private ProgressDialog m_ProgressDialog = null; 
	private FriendAdapter m_adapter;
	public static final String TAG = "FriendListActivity";
	private ListView mListView = null;
	private TextView mEmptyTextView = null;
	private final static int SETFRIENDIMAGE = 1;
	private static HashMap pictureMap;
	private EditText searchBar = null;
	private ArrayList contacts = new ArrayList();

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		tracker.trackPageView("Contact List");
		pictureMap = new HashMap();

		showFriendsController();

	}

	private void showFriendsController() {
		setContentView(R.layout.friend_controller);
		m_ProgressDialog = ProgressDialog.show(FriendsListActivity.this,    
				"Please wait...", "Retrieving your friends...", true);

		mListView = (ListView) findViewById(R.id.lvFriends);
		mListView.setOnScrollListener(mOnScrollListener);

		mEmptyTextView = (TextView)findViewById(R.id.txtEmptyFriendList);

		if(friendsList != null && friendsList.size() > 0) {
			for(int x = 0; x < friendsList.size(); x++)
			{
				contacts.add(friendsList.get(x));
			}
			Collections.sort(friendsList);
			mEmptyTextView.setVisibility(View.GONE);
			m_adapter = new FriendAdapter(this, R.layout.friend_item, friendsList);
			mListView.setAdapter(m_adapter);
			mListView.setFastScrollEnabled(true);
			m_adapter.notifyDataSetChanged();

		}
		else {
			Log.e("Friend list problem", "Friend List not populated");
			mEmptyTextView.setVisibility(View.VISIBLE);
		}

		m_ProgressDialog.dismiss();
		loadViewableImages(mListView.getFirstVisiblePosition(), mListView.getChildCount());


		mListView.setOnItemClickListener(new OnItemClickListener() {
			@Override
			public void onItemClick(AdapterView arg0, View arg1, int arg2,
					long arg3) {

				Intent data = new Intent();
				data.putExtra("contact_id", contacts.get(arg2).getId());

				
				setResult(RESULT_OK, data);
				finish();
			}
		});

		searchBar = (EditText) findViewById(R.id.searchBar);
		searchBar.addTextChangedListener(new TextWatcher() {

			String current = "";

			@Override
			public void afterTextChanged(Editable s) {

				ArrayListsearched = new ArrayList();
				current = s.toString();
				int currentLength = current.length();

				for (int x = 0; x < friendsList.size(); x++) {
					String name = friendsList.get(x).getName().toLowerCase();
					if (name.length() > currentLength) {
						int counter = 0;
						for (int y = 0; y < currentLength; y++) {
							char currentChar = current.charAt(y);
							char recipientChar = name.charAt(y);
=======
    private FriendAdapter m_adapter;
    public static final String TAG = "FriendListActivity";
    private ListView mListView = null;
    private TextView mEmptyTextView = null;
    private final static int SETFRIENDIMAGE = 1;
    private static HashMap pictureMap;
    private EditText searchBar = null;
>>>>>>> 31a4072af63868cb5dc09a90683f893d7dca6010

    @Override
    public void onCreate(Bundle savedInstanceState) {
Solution content
public final class FriendsListActivity extends BaseActivity  {

    private FriendAdapter m_adapter;
    public static final String TAG = "FriendListActivity";
    private ListView mListView = null;
    private TextView mEmptyTextView = null;
    private final static int SETFRIENDIMAGE = 1;
    private static HashMap pictureMap;
    private EditText searchBar = null;

    @Override
    public void onCreate(Bundle savedInstanceState) {
File
FriendsListActivity.java
Developer's decision
Version 2
Kind of conflict
Annotation
Attribute
Cast expression
If statement
Method declaration
Method invocation
Method signature
Chunk
Conflicting content
                for (int x = 0; x < friendsList.size(); x++) {

<<<<<<< HEAD
						}
					}
				}
				
				ArrayList tempList = new ArrayList();
				tempList.addAll(friendsList);
				contacts.clear();
				for(int i = 0; i < searched.size(); i++)
				{
					for (int j = 0; j < friendsList.size(); j++)
					{
						if(tempList.get(j).getName().toLowerCase().equals(searched.get(i)))
						{															
							contacts.add(tempList.get(j));					
							break;
						}
					}
				}		
				if(contacts.size() == 0)
				{
					Friend newContact = new Friend();
					newContact.setName(searchBar.getText().toString());
					contacts.add(newContact);
				}
				if(searchBar.getText().toString().length() == 0)
				{
					m_adapter = new FriendAdapter(FriendsListActivity.this, R.layout.friend_item,
							friendsList);
					contacts.clear();
				}
				else
				{
					m_adapter = new FriendAdapter(FriendsListActivity.this, R.layout.friend_item,
							contacts);
				}
				mListView.setAdapter(m_adapter);
				
			}

			@Override
			public void beforeTextChanged(CharSequence s, int start, int count,
					int after) {

			}

			@Override
			public void onTextChanged(CharSequence s, int start, int before,
					int count) 
			{


			}

		});
	}

	private OnScrollListener mOnScrollListener = new OnScrollListener() {

		@Override
		public void onScroll(AbsListView view, int firstVisibleItem,
				int visibleItemCount, int totalItemCount) {
			// TODO Auto-generated method stub
		}

		@Override
		public void onScrollStateChanged(AbsListView view, int scrollState) {
			// TODO Auto-generated method stub
			switch (scrollState) {

			case SCROLL_STATE_IDLE :

				loadViewableImages(view.getFirstVisiblePosition(), view.getChildCount());




				break;

			case SCROLL_STATE_TOUCH_SCROLL:

				break;

			case SCROLL_STATE_FLING :
				break;

			}

		}
	};

	private void loadViewableImages(int first, int count) {
		for (int i = 0; i < count; i++) {

			Friend friend = (Friend) mListView.getAdapter().getItem(i + first);
			ImageView imageView = (ImageView) mListView.getChildAt(i).findViewById(R.id.imgFriend);
			if (friend.getPicture() == null && friend.getType().equals("Facebook")) {
				if (!pictureMap.containsKey(friend.getId())) {
					Log.d("Retrieving Image for:", friend.getName());
					fetchDrawableOnThread(friend, imageView);
				}
				else {
					imageView.setImageBitmap(pictureMap.get(friend.getId()));
				}
			}

		}
	}

	private void fetchDrawableOnThread(final Friend friend, final ImageView imageView) {
		final Handler handler = new Handler() {
			@Override
			public void handleMessage(Message message) {
				Bitmap image = (Bitmap) message.obj;

				friend.setPicture(image);
				pictureMap.put(friend.getId(), image);
				imageView.setImageBitmap(image);
				m_adapter.notifyDataSetChanged();
			}
		};

		Thread thread = new Thread() {
			public void run() {
				try {
					URL url = new URL("http://graph.facebook.com/" + friend.getId() + "/picture");
					Bitmap mIcon = BitmapFactory.decodeStream(url.openConnection().getInputStream());
					Message message = handler.obtainMessage(SETFRIENDIMAGE, mIcon);
					handler.sendMessage(message);
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
=======
                    Friend friend = friendsList.get(x);
                    if (friend.masterSearch(current.toLowerCase())) {
                        searched.add(friend);
                    }
                }
>>>>>>> 31a4072af63868cb5dc09a90683f893d7dca6010

                if(searchBar.getText().toString().length() == 0)
                {
Solution content
                for (int x = 0; x < friendsList.size(); x++) {

                    Friend friend = friendsList.get(x);
                    if (friend.masterSearch(current.toLowerCase())) {
                        searched.add(friend);
                    }
                }

                if(searchBar.getText().toString().length() == 0)
                {
File
FriendsListActivity.java
Developer's decision
Version 2
Kind of conflict
Annotation
Attribute
For statement
If statement
Method declaration
Method invocation
Method signature
Variable
Chunk
Conflicting content
import java.text.NumberFormat;

<<<<<<< HEAD
import com.google.android.apps.analytics.GoogleAnalyticsTracker;

import me.pdthx.Login.TabUIActivity;
=======
>>>>>>> 31a4072af63868cb5dc09a90683f893d7dca6010
import me.pdthx.Requests.UserRequest;
import me.pdthx.Responses.UserResponse;
import me.pdthx.Services.UserService;
Solution content
import java.text.NumberFormat;

import me.pdthx.Requests.UserRequest;
import me.pdthx.Responses.UserResponse;
import me.pdthx.Services.UserService;
File
HomeActivity.java
Developer's decision
Version 2
Kind of conflict
Import
Chunk
Conflicting content
	@Override
	public void onCreate(Bundle savedInstanceState) {
<<<<<<< HEAD
		super.onCreate(savedInstanceState);  

		tracker.trackPageView("HomeActivity");
=======
		super.onCreate(savedInstanceState);

>>>>>>> 31a4072af63868cb5dc09a90683f893d7dca6010

		if(prefs.getString("userId", "").length() == 0) {
			startActivityForResult(new Intent(this, SignInActivity.class), 1);
Solution content
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);  

		tracker.trackPageView("Home");

		if(prefs.getString("userId", "").length() == 0) {
			startActivityForResult(new Intent(this, SignInActivity.class), 1);
File
HomeActivity.java
Developer's decision
Manual
Kind of conflict
Method invocation
Chunk
Conflicting content
import me.pdthx.helpers.PhoneNumberFormatter;

public class Friend implements Comparable {
<<<<<<< HEAD
	private String name = "";
	private String id = "";
	private String type = "";
	private String phoneNumber = "";
	private String emailAddress = "";
	private Bitmap picture = null;

	public String getId()
	{
		return id;
	}
	public void setId(String id)
	{
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}

	public String getPhoneNumber() {
		return phoneNumber;
	}

	public void setPhoneNumber(String phoneNumber) {
		String fixedNumber = "";
		String number = "";
		String extras = "";

		fixedNumber = phoneNumber.replaceAll("[^0-9]", "");
		int fixedNumberLength = fixedNumber.length();

		if (fixedNumberLength >= 10) {

			if (fixedNumberLength == 10) {
				number = fixedNumber;
			}
			else if (fixedNumberLength > 10) {
				extras = fixedNumber.substring(0, fixedNumberLength - 10) + " ";
				number = fixedNumber.substring(fixedNumberLength - 11);
			}

			number = "(" + number.substring(0, 3) + ") " + 
					number.substring(3, 6) + "-" + number.substring(6);

			fixedNumber = extras + number;

			this.phoneNumber = fixedNumber;
		}
		else {
			this.phoneNumber = "";
		}
	}

	public String getEmailAddress() {
		return emailAddress;
	}

	public void setEmailAddress(String emailAddress) {
		this.emailAddress = emailAddress;
	}

	public Bitmap getPicture() {
		return picture;
	}
	public void setPicture(Bitmap picture) {
		this.picture = picture;
	}
	@Override
	public int compareTo(Friend friend) {
		return this.name.compareTo(friend.name);
	}
	
	public boolean equals(Object other) {
		return other instanceof Friend && id.equals(((Friend) other).getId());
	}

=======
    private String name = "";
    private String id = "";
    private boolean fbContact = false;
    private String paypoint = "";
    private Bitmap picture;
    private Uri pictureUri;

    public String getId()
    {
        return id;
    }
    public void setId(String id)
    {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public boolean isFBContact() {
        return fbContact;
    }

    public void setFBContact(boolean fbContact) {
        this.fbContact = fbContact;
    }

    public String getPaypoint()
    {
        return paypoint;
    }
    public void setPaypoint(String paypoint)
    {
        this.paypoint = paypoint;
    }
    public Bitmap getPicture() {
        return picture;
    }
    public void setPicture(Bitmap picture) {
        this.picture = picture;
    }

    public Uri getPictureUri()
    {
        return pictureUri;
    }
    public void setPictureUri(Uri pictureUri)
    {
        this.pictureUri = pictureUri;
    }
    public boolean equals(Object other) {
        return other instanceof Friend && ((Friend)other).getId().equals(id);
    }

    @Override
    public int compareTo(Friend friend) {
        return this.name.compareToIgnoreCase(friend.name);
    }

    public boolean masterSearch(String s) {
        String search = s.trim().toLowerCase();
        String[] names = NameSeparator.separateName(name);
        String firstName = names[0].toLowerCase();
        String lastName = names[1].toLowerCase();

        if (search.contains(" "))
        {
            String[] searchNames = NameSeparator.separateName(search);
            String searchFirst = searchNames[0].toLowerCase();
            String searchLast = searchNames[1].toLowerCase();

            return firstName.startsWith(searchFirst) && lastName.startsWith(searchLast)
                || firstName.startsWith(searchLast) && lastName.startsWith(searchFirst);
        }

        if (name.startsWith(search))
        {
            return true;
        }

        if (firstName.startsWith(search)) {
            return true;
        }

        if (lastName.startsWith(search)) {
            return true;
        }

        if (paypoint.toLowerCase().startsWith(search))
        {
            return true;
        }

        return false;
    }

    public String toString() {
        if (!paypoint.equals("")) {
            return name + ": " + paypoint;
        }

        return name;
    }
>>>>>>> 31a4072af63868cb5dc09a90683f893d7dca6010

}
Solution content
public class Friend implements Comparable {
    private String name = "";
    private String id = "";
    private boolean fbContact = false;
    private String paypoint = "";
    private Bitmap picture;
    private Uri pictureUri;

    public String getId()
    {
        return id;
    }
    public void setId(String id)
    {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public boolean isFBContact() {
        return fbContact;
    }

    public void setFBContact(boolean fbContact) {
        this.fbContact = fbContact;
    }

    public String getPaypoint()
    {
        return paypoint;
    }
    public void setPaypoint(String paypoint)
    {
        this.paypoint = paypoint;
    }
    public Bitmap getPicture() {
        return picture;
    }
    public void setPicture(Bitmap picture) {
        this.picture = picture;
    }

    public Uri getPictureUri()
    {
        return pictureUri;
    }
    public void setPictureUri(Uri pictureUri)
    {
        this.pictureUri = pictureUri;
    }
    public boolean equals(Object other) {
        return other instanceof Friend && ((Friend)other).getId().equals(id);
    }

    @Override
    public int compareTo(Friend friend) {
        return this.name.compareToIgnoreCase(friend.name);
    }

    public boolean masterSearch(String s) {
        String search = s.trim().toLowerCase();
        String[] names = NameSeparator.separateName(name);
        String firstName = names[0].toLowerCase();
        String lastName = names[1].toLowerCase();

        if (search.contains(" "))
        {
            String[] searchNames = NameSeparator.separateName(search);
            String searchFirst = searchNames[0].toLowerCase();
            String searchLast = searchNames[1].toLowerCase();

            return firstName.startsWith(searchFirst) && lastName.startsWith(searchLast)
                || firstName.startsWith(searchLast) && lastName.startsWith(searchFirst);
        }

        if (name.startsWith(search))
        {
            return true;
        }

        if (firstName.startsWith(search)) {
            return true;
        }

        if (lastName.startsWith(search)) {
            return true;
        }

        if (paypoint.toLowerCase().startsWith(search))
        {
            return true;
        }

        return false;
    }

    public String toString() {
        if (!paypoint.equals("")) {
            return name + ": " + paypoint;
        }

        return name;
    }

}
File
Friend.java
Developer's decision
Version 2
Kind of conflict
Annotation
Attribute
Method declaration
Chunk
Conflicting content
			@Override
			public void afterTextChanged(Editable s) {

<<<<<<< HEAD
				ArrayList searched = new ArrayList();
				current = s.toString().toLowerCase();
				int checked = group.getCheckedRadioButtonId();

				if (checked == 2131165310) {
					searched.clear();
					for (int x = 0; x < m_transactions.size(); x++)
					{

						if(m_transactions.get(x).search(current))
						{
							searched.add(m_transactions.get(x));
						}
					}
					if (searched.size() == 0) {
						m_adapter = new PaystreamAdapter(PaystreamActivity.this,R.layout.transaction_item, m_transactions);
					} 
					else {
						m_adapter = new PaystreamAdapter(PaystreamActivity.this, R.layout.transaction_item, searched);
					}
				} 
				else if (checked == 2131165311) {
					searched.clear();
					for (int x = 0; x < send_transactions.size(); x++)
					{

						if(m_transactions.get(x).search(current))
						{
							searched.add(send_transactions.get(x));
=======
				ArrayList searched = new ArrayList();
				current = s.toString();
				int currentLength = current.length();

				for (int x = 0; x < transactionsList.size(); x++) {
					String recipient = transactionsList.get(x).getRecipientUri()
							.toString();

					if (recipient.length() > currentLength) {
						int counter = 0;
						for (int y = 0; y < currentLength; y++) {
							char currentChar = current.charAt(y);
							char recipientChar = recipient.charAt(y);
							if (currentChar == recipientChar) {
								counter++;
							}
							if (counter == currentLength) {
								searched.add(recipient);
							}
>>>>>>> 31a4072af63868cb5dc09a90683f893d7dca6010
						}
					}
Solution content
			@Override
			public void afterTextChanged(Editable s) {
				ArrayList searched = new ArrayList();
				current = s.toString().toLowerCase();
				int checked = group.getCheckedRadioButtonId();

				if (checked == 2131165310) {
					searched.clear();
					for (int x = 0; x < m_transactions.size(); x++)
					{

						if(m_transactions.get(x).search(current))
						{
							searched.add(m_transactions.get(x));
						}
					}
					if (searched.size() == 0) {
						m_adapter = new PaystreamAdapter(PaystreamActivity.this,R.layout.transaction_item, m_transactions);
					} 
					else {
						m_adapter = new PaystreamAdapter(PaystreamActivity.this, R.layout.transaction_item, searched);
					}
				} 
				else if (checked == 2131165311) {
					searched.clear();
					for (int x = 0; x < send_transactions.size(); x++)
					{

						if(m_transactions.get(x).search(current))
						{
							searched.add(send_transactions.get(x));
						}
					}
File
PaystreamActivity.java
Developer's decision
Version 1
Kind of conflict
Attribute
For statement
If statement
Method invocation
Variable
Chunk
Conflicting content
					searched.clear();
					for (int x = 0; x < recieve_transactions.size(); x++)
					{
<<<<<<< HEAD

						if(m_transactions.get(x).search(current))
						{
							searched.add(recieve_transactions.get(x));
						}
					}

					
					if (searchBar.getText().toString().length() == 0) {
						m_adapter = new PaystreamAdapter(PaystreamActivity.this,R.layout.transaction_item, recieve_transactions);
					} 
					else {
						m_adapter = new PaystreamAdapter(PaystreamActivity.this, R.layout.transaction_item, searched);
					}
				} else if (checked == 2131165313) {
					searched.clear();
					for (int x = 0; x < other_transactions.size(); x++)
					{

						if(other_transactions.get(x).search(current))
						{
							searched.add(other_transactions.get(x));
						}
					}

					
					if (searchBar.getText().toString().length() == 0) {
						m_adapter = new PaystreamAdapter(PaystreamActivity.this,R.layout.transaction_item, other_transactions);
					} 
					else {
						m_adapter = new PaystreamAdapter(PaystreamActivity.this, R.layout.transaction_item, searched);
					}
=======
						if(tempList.get(j).getRecipientUri().equals(searched.get(i)))
						{
							m_transactions.add(tempList.get(j));
							break;
						}
					}
				}
				if(searchBar.getText().toString().length() == 0)
				{
					m_adapter = new PaystreamAdapter(PaystreamActivity.this, R.layout.transaction_item,
							transactionsList);
					m_transactions.clear();
				}
				else
				{
					m_adapter = new PaystreamAdapter(PaystreamActivity.this, R.layout.transaction_item,
							m_transactions);
>>>>>>> 31a4072af63868cb5dc09a90683f893d7dca6010
				}

Solution content
					searched.clear();
					for (int x = 0; x < recieve_transactions.size(); x++)
					{

						if(m_transactions.get(x).search(current))
						{
							searched.add(recieve_transactions.get(x));
						}
					}

					
					if (searchBar.getText().toString().length() == 0) {
						m_adapter = new PaystreamAdapter(PaystreamActivity.this,R.layout.transaction_item, recieve_transactions);
					} 
					else {
						m_adapter = new PaystreamAdapter(PaystreamActivity.this, R.layout.transaction_item, searched);
					}
				} else if (checked == 2131165313) {
					searched.clear();
					for (int x = 0; x < other_transactions.size(); x++)
					{

						if(other_transactions.get(x).search(current))
						{
							searched.add(other_transactions.get(x));
						}
					}

					
					if (searchBar.getText().toString().length() == 0) {
						m_adapter = new PaystreamAdapter(PaystreamActivity.this,R.layout.transaction_item, other_transactions);
					} 
					else {
						m_adapter = new PaystreamAdapter(PaystreamActivity.this, R.layout.transaction_item, searched);
					}
				}

File
PaystreamActivity.java
Developer's decision
Version 1
Kind of conflict
Attribute
For statement
If statement
Method invocation
Chunk
Conflicting content
			@Override
			public void onTextChanged(CharSequence s, int start, int before,
<<<<<<< HEAD
					int count) {
=======
					int count)
			{

>>>>>>> 31a4072af63868cb5dc09a90683f893d7dca6010

			}
Solution content
			@Override
			public void onTextChanged(CharSequence s, int start, int before,
					int count) {

			}
File
PaystreamActivity.java
Developer's decision
Version 1
Kind of conflict
Variable
Chunk
Conflicting content
<<<<<<< HEAD
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		tracker.trackPageView("ProfileSetupActivity");
		this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN); 
=======

		this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
>>>>>>> 31a4072af63868cb5dc09a90683f893d7dca6010
		showProfileSetup();

	}
Solution content
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		tracker.trackPageView("ProfileSetupActivity");
		this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN); 
		showProfileSetup();

	}
File
ProfileSetupActivity.java
Developer's decision
Version 1
Kind of conflict
Method invocation
Chunk
Conflicting content
				startActivityForResult(new Intent(RequestPaymentActivity.this, AddMoneyActivity.class), ADD_MONEY);
			}
		});
<<<<<<< HEAD
		
		btnCamera = (Button) findViewById(R.id.camera);
		btnCamera.setOnClickListener(new OnClickListener()
		{
			@Override
			public void onClick(View v) {
				
				startActivityForResult(new Intent(RequestPaymentActivity.this, CameraActivity.class), CAMERA);
			}	
		});

=======
//		txtAmount.addTextChangedListener(new TextWatcher() {
//			String current = "";
//
//			@Override
//			public void onTextChanged(CharSequence s, int start, int before,
//					int count) {
//				if (!s.toString().equals(current)) {
//					EditText txtAmount = (EditText) findViewById(R.id.txtRequestMoneyAmount);
//					txtAmount.removeTextChangedListener(this);
//
//					String cleanString = s.toString().replaceAll("[$,.]", "");
//
//					double parsed = Double.parseDouble(cleanString);
//					String formatted = NumberFormat.getCurrencyInstance()
//							.format((parsed / 100));
//
//					current = formatted;
//					txtAmount.setText(formatted);
//					txtAmount.setSelection(formatted.length());
//
//					txtAmount.addTextChangedListener(this);
//				}
//			}
//
//			@Override
//			public void afterTextChanged(Editable arg0) {
//				if (arg0.length() == 14) {
//					arg0.replace(13, 14, "");
//				}
//			}
//
//			@Override
//			public void beforeTextChanged(CharSequence arg0, int arg1,
//					int arg2, int arg3) {
//
//			}
//		});
//
>>>>>>> 31a4072af63868cb5dc09a90683f893d7dca6010
		btnAddContacts = (Button) findViewById(R.id.addRecipient);
		btnAddContacts.setOnClickListener(new OnClickListener(){
Solution content
				startActivityForResult(new Intent(RequestPaymentActivity.this, AddMoneyActivity.class), ADD_MONEY);
			}
		});
		
		btnCamera = (Button) findViewById(R.id.camera);
		btnCamera.setOnClickListener(new OnClickListener()
		{
			@Override
			public void onClick(View v) {
				
				startActivityForResult(new Intent(RequestPaymentActivity.this, CameraActivity.class), CAMERA);
			}	
		});

		btnAddContacts = (Button) findViewById(R.id.addRecipient);
		btnAddContacts.setOnClickListener(new OnClickListener(){
File
RequestPaymentActivity.java
Developer's decision
Version 1
Kind of conflict
Attribute
Cast expression
Comment
Method invocation
Chunk
Conflicting content
                }
		if (resultCode == RESULT_OK) {
			if (requestCode == ADDING_FRIEND) {
				Bundle bundle = data.getExtras();
<<<<<<< HEAD
				Friend pickedFriend = new Friend();
				pickedFriend.setId(bundle.getString("contact_id"));
				if (!pickedFriend.getId().equals("")) {
					friend = friendsList.get(friendsList.indexOf(pickedFriend));

					if (friend.getType().equals("Facebook")) {
						recipientUri = "fb_" + friend.getId();
						btnAddContacts.setText(friend.getName() + ": " + friend.getId());
					}
					else {
						recipientUri = "" + friend.getPhoneNumber();
						btnAddContacts.setText(friend.getName() + ": " + friend.getPhoneNumber());
					}
				}
				
=======
				if (bundle.getString("id") != null)
                {
                    Friend chosenContact = new Friend();
                    chosenContact.setId(bundle.getString("id"));
                    friend = friendsList.get(friendsList.indexOf(chosenContact));

                    if (friend.isFBContact()) {
                        recipientUri = "fb_" + friend.getId();
                        btnAddContacts.setText(friend.getName() + ": " + friend.getId());
                    }
                    else {
                        recipientUri = "" + friend.getPaypoint();
                        btnAddContacts.setText(friend.toString());
                    }
                else
                {
                    recipientUri = "" + friend.getPaypoint();
                    btnAddContacts.setText(friend.toString());
                }


>>>>>>> 31a4072af63868cb5dc09a90683f893d7dca6010
			}
			else if(requestCode == ADD_MONEY){
				Bundle bundle = data.getExtras();
Solution content
		if (resultCode == RESULT_OK) {
			if (requestCode == ADDING_FRIEND) {
				Bundle bundle = data.getExtras();
				if (bundle.getString("id") != null)
                {
                    Friend chosenContact = new Friend();
                    chosenContact.setId(bundle.getString("id"));
                    friend = friendsList.get(friendsList.indexOf(chosenContact));

                    if (friend.isFBContact()) {
                        recipientUri = "fb_" + friend.getId();
                        btnAddContacts.setText(friend.getName() + ": " + friend.getId());
                    }
                    else {
                        recipientUri = "" + friend.getPaypoint();
                        btnAddContacts.setText(friend.toString());
                    }
                }
                else
                {
                    recipientUri = "" + friend.getPaypoint();
                    btnAddContacts.setText(friend.toString());
                }

			}
			else if(requestCode == ADD_MONEY){
				Bundle bundle = data.getExtras();
File
RequestPaymentActivity.java
Developer's decision
Version 2
Kind of conflict
If statement
Method invocation
Variable
Chunk
Conflicting content
    private String comments = "";
    private String errorMessage = "";

<<<<<<< HEAD
	private Location location;
	private LocationManager locationManager;
	private LocationListener locationListener;

	private Friend friend;
=======
    private Location location;
    private LocationManager locationManager;
    private LocationListener locationListener;
>>>>>>> 31a4072af63868cb5dc09a90683f893d7dca6010

    private Friend friend;
Solution content
    private String comments = "";
    private String errorMessage = "";

	private Location location;
	private LocationManager locationManager;
	private LocationListener locationListener;


    private Friend friend;
File
SendPaymentActivity.java
Developer's decision
Version 2
Kind of conflict
Attribute
Chunk
Conflicting content
            }

<<<<<<< HEAD
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		tracker.trackPageView("/SendPaymentActivity");
		setTitle("Send Money");
=======
        }
    };
>>>>>>> 31a4072af63868cb5dc09a90683f893d7dca6010

    @Override
    public void onCreate(Bundle savedInstanceState) {
Solution content
            }

        }
    };

    @Override
    public void onCreate(Bundle savedInstanceState) {
File
SendPaymentActivity.java
Developer's decision
Version 2
Kind of conflict
Annotation
Method invocation
Method signature
Chunk
Conflicting content
        launchSendMoneyView();

<<<<<<< HEAD
	@Override
	public void onResume() {
		super.onResume();
		tracker.trackPageView("/SendPaymentActivity");
		locationManager.requestLocationUpdates(
				LocationManager.GPS_PROVIDER, 0, 0, locationListener);
		//		locationManager.requestLocationUpdates(
		//				LocationManager.NETWORK_PROVIDER, 0, 0, locationListener);


	}

	@Override
	public void onPause() {
		super.onPause();

		locationManager.removeUpdates(locationListener);
	}

	protected android.app.Dialog onCreateDialog(int id) {
		AlertDialog alertDialog = null;
		ProgressDialog progressDialog = null;
		Thread thread = null;
		switch (id) {
		case SUBMITPAYMENT_DIALOG:
			progressDialog = new ProgressDialog(this);

			progressDialog.setMessage("Submitting Request...");
			progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);

			thread = new Thread(new Runnable() {

				@Override
				public void run() {
					// TODO Auto-generated method stub
					try {
						SubmitPaymentRequest();

					} catch (Exception e) {
						e.printStackTrace();
					}
					dialogHandler.sendEmptyMessage(SUBMITPAYMENT_ACTION);
				}

			});
			dialog = progressDialog;
			thread.start();

			return dialog;
		case SUBMITPAYMENTFAILED_DIALOG:
			alertDialog = new AlertDialog.Builder(this).create();
			alertDialog.setTitle("Failed");

			alertDialog.setMessage(errorMessage);
			alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
				public void onClick(DialogInterface dialog, int which) {
					dialog.dismiss();

				}
			});

			return alertDialog;
		case SUBMITPAYMENTSUCCESS_DIALOG:

				return true;
					friend = friendsList.get(friendsList.indexOf(pickedFriend));

			alertDialog = new AlertDialog.Builder(this).create();
			alertDialog.setTitle("Payment Sumitted");
			NumberFormat nf = NumberFormat.getCurrencyInstance();

			alertDialog.setMessage(String.format(
					"Your payment for %s was sent to %s.", nf.format(amount),
					recipientUri));

			alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
				public void onClick(DialogInterface dialog, int which) {
					removeDialog(4);
					dialog.dismiss();

					friend = null;
					btnAddContacts.setText("Add recipient");
					txtAmount.setText("$0.00");
					txtComments.setText("");
				}
			});

			return alertDialog;
		case NORECIPIENTSPECIFIED_DIALOG:
			alertDialog = new AlertDialog.Builder(SendPaymentActivity.this)
			.create();
			alertDialog.setTitle("Please Specify a Recipient");
			alertDialog
			.setMessage("You must specify the recipient's mobile number.");

			alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
				public void onClick(DialogInterface dialog, int which) {
					dialog.dismiss();
				}
			});

			return alertDialog;
		case NOAMOUNTSPECIFIED_DIALOG:
			alertDialog = new AlertDialog.Builder(SendPaymentActivity.this)
			.create();
			alertDialog.setTitle("Please Specify an Amount");
			alertDialog.setMessage("You must specify the amount to send.");

			alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
				public void onClick(DialogInterface dialog, int which) {
					dialog.dismiss();
				}
			});

			return alertDialog;

		case INVALIDPASSCODELENGTH_DIALOG:
			alertDialog = new AlertDialog.Builder(SendPaymentActivity.this)
			.create();
			alertDialog.setTitle("Invalid Passcode");
			alertDialog
			.setMessage("Your passcode is atleast 4 buttons. Please try again.");

			alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
				public void onClick(DialogInterface dialog, int which) {
					dialog.dismiss();
				}
			});

			return alertDialog;


		case PAYMENTEXCEEDSLIMIT_DIALOG:
			alertDialog = new AlertDialog.Builder(SendPaymentActivity.this)
			.create();
			alertDialog.setTitle("Exceeds Limit");
			alertDialog
			.setMessage("The payment exceeds your upper limit. Please try again.");

			alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
				public void onClick(DialogInterface dialog, int which) {
					dialog.dismiss();
				}
			});

			return alertDialog;

		}

		return null;
	}

	protected void launchSendMoneyView() {
		sendMoneyView = View.inflate(this, R.layout.contactmanager, null);
		setContentView(sendMoneyView);


		btnAddContacts = (Button) findViewById(R.id.addRecipient);

		txtAmount = (Button) findViewById(R.id.btnAmount);
		txtComments = (EditText) findViewById(R.id.txtComments);
		btnSendMoney = (Button) findViewById(R.id.btnSubmitPaymentRequest);
		Typeface type = Typeface.createFromAsset(getAssets(),"HelveticaWorld-Bold.ttf");
		btnSendMoney.setTypeface(type);
		btnSendMoney.setTextColor(Color.WHITE);

		txtAmount.setOnClickListener(new OnClickListener(){

			@Override
			public void onClick(View v) {
					if (friend.getType().equals("Facebook")) {
				startActivityForResult(new Intent(SendPaymentActivity.this, AddMoneyActivity.class), ADD_MONEY);			
			}		
		});

		btnAddContacts.setOnClickListener(new OnClickListener(){	
			@Override
			public void onClick(View v) {
				startActivityForResult(new Intent(SendPaymentActivity.this, FriendsListActivity.class), ADDING_FRIEND);			
			}

		});

		//		txtAmount.addTextChangedListener(new TextWatcher() {
		//			String current = "";
		//
		//			@Override
		//			public void onTextChanged(CharSequence s, int start, int before,
		//					int count) {
		//				if (!s.toString().equals(current)) {
		//					txtAmount.removeTextChangedListener(this);
		//
		//					String cleanString = s.toString().replaceAll("[$,.]", "");
		//
		//					double parsed = Double.parseDouble(cleanString);
		//					String formatted = NumberFormat.getCurrencyInstance()
		//							.format((parsed / 100));
		//
		//					current = formatted;
		//					txtAmount.setText(formatted);
		//					txtAmount.setSelection(formatted.length());
		//					
		//					txtAmount.addTextChangedListener(this);
		//				}
		//			}
		//
		//			@Override
		//			public void afterTextChanged(Editable arg0) {
		//				// TODO Auto-generated method stub
		//				if (arg0.length() == 14) {
		//					arg0.replace(13, 14, "");
		//				}
		//			}
		//
		//			@Override
		//			public void beforeTextChanged(CharSequence arg0, int arg1,
		//					int arg2, int arg3) {
		//				// TODO Auto-generated method stub
		//
		//			}
		//		});



		btnSendMoney.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				boolean isValid = true;

				amount = Double.parseDouble(txtAmount.getText().toString().trim()
						.replaceAll("[$,]*", ""));
				comments = txtComments.getText().toString();

				if (isValid && recipientUri.length() == 0) {
					showDialog(NORECIPIENTSPECIFIED_DIALOG);
					isValid = false;
				}
				if (isValid && amount == 0) {
					showDialog(NOAMOUNTSPECIFIED_DIALOG);
					isValid = false;
				}
				if (isValid && amount > prefs.getInt("upperLimit", 0)) {
					showDialog(PAYMENTEXCEEDSLIMIT_DIALOG);
					isValid = false;
				}
				if (isValid) {

					Location lastKnownLocation = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);

					if (isBetterLocation(lastKnownLocation, location)) {
						location = lastKnownLocation;
					}


					if(prefs.getString("userId", "").length() == 0)		{
						startActivityForResult(new Intent(SendPaymentActivity.this, SignInActivity.class), 1);
					} else {
						showSecurityPinDialog();
					}
				}
			}
		});

		btnSendMoney.setVisibility(View.VISIBLE);

	}

	@Override
	public void onActivityResult(int requestCode, int resultCode, Intent data) {
		if (resultCode == RESULT_OK) {
			if (requestCode == ADDING_FRIEND) {
				Bundle bundle = data.getExtras();
				Friend pickedFriend = new Friend();
				pickedFriend.setId(bundle.getString("contact_id"));
				if (!pickedFriend.getId().equals("")) {
					
						recipientUri = "fb_" + friend.getId();
						btnAddContacts.setText(friend.getName() + ": " + friend.getId());
					}
					else {
						recipientUri = "" + friend.getPhoneNumber();
						btnAddContacts.setText(friend.getName() + ": " + friend.getPhoneNumber());
					}
				}


			}
			else if(requestCode == ADD_MONEY){
				Bundle bundle = data.getExtras();
				String amount = bundle.getString("index");
				txtAmount.setText(amount);
			}
			else {
				launchSendMoneyView();
			}
		}
		else {
			if (requestCode != ADDING_FRIEND && requestCode != ADD_MONEY) {
				finish();
			}
		}
	}

	protected void showSecurityPinDialog() {
		final Dialog d = new Dialog(SendPaymentActivity.this, R.style.CustomDialogTheme);
		d.setContentView(R.layout.security_dialog);

		d.getWindow().setLayout(400, 600);
		d.show();

		TextView txtConfirmHeader = (TextView)d.findViewById(R.id.txtConfirmHeader);
		TextView txtConfirmBody = (TextView)d.findViewById(R.id.txtConfirmBody);

		txtConfirmHeader.setText("Confirm Your Payment");
		txtConfirmBody.setText(String.format("To confirm your payment of %s to %s, swipe you pin below.", 
				txtAmount.getText(), friend.getName()));

		Button btnCancel = (Button) d.findViewById(R.id.btnCancelSendMoney);
		btnCancel.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				d.dismiss();
			}
		});

		final CustomLockView ctrlSecurityPin = (CustomLockView) d.findViewById(R.id.ctrlSecurityPin);
		ctrlSecurityPin.invalidate();
		ctrlSecurityPin.setOnTouchListener(new OnTouchListener() {
			@Override
			public boolean onTouch(View v, MotionEvent event) {
				passcode = ctrlSecurityPin.getPasscode();

				if (passcode.length() > 3) {
					amount = Double.parseDouble(txtAmount.getText().toString()
							.replace("$", ""));
					comments = txtComments.getText().toString();
					passcode = ctrlSecurityPin.getPasscode();

					d.dismiss();

					showDialog(SUBMITPAYMENT_DIALOG);
				} else
					showDialog(INVALIDPASSCODELENGTH_DIALOG);

				return false;
			}
		});
	}

	protected void SubmitPaymentRequest() {

		PaymentRequest paymentRequest = new PaymentRequest();
		paymentRequest.UserId = prefs.getString("userId", "");
		paymentRequest.SecurityPin = passcode;
		paymentRequest.SenderUri = prefs.getString("login", "");
		paymentRequest.RecipientUri = recipientUri;
		paymentRequest.Amount = amount;
		paymentRequest.Comments = comments;
		paymentRequest.SenderAccountId = prefs.getString("paymentAccountId", "0");

		if (location != null) {
			paymentRequest.Latitude = location.getLatitude();
			paymentRequest.Longitude = location.getLongitude();
		}

		paymentResponse = PaymentServices.sendMoney(paymentRequest);

	}

	/** Determines whether one Location reading is better than the current Location fix
	 * @param location  The new Location that you want to evaluate
	 * @param currentBestLocation  The current Location fix, to which you want to compare the new one
	 */
	private boolean isBetterLocation(Location location, Location currentBestLocation) {
		final int TWO_MINUTES = 1000 * 60 * 2;

		if (location != null) {

			if (currentBestLocation == null) {
				// A new location is always better than no location
			}

			// Check whether the new location fix is newer or older
			long timeDelta = location.getTime() - currentBestLocation.getTime();
			boolean isSignificantlyNewer = timeDelta > TWO_MINUTES;
			boolean isSignificantlyOlder = timeDelta < -TWO_MINUTES;
			boolean isNewer = timeDelta > 0;

			// If it's been more than two minutes since the current location, use the new location
			// because the user has likely moved
			if (isSignificantlyNewer) {
				return true;
				// If the new location is more than two minutes older, it must be worse
			} else if (isSignificantlyOlder) {
				return false;
			}

			// Check whether the new location fix is more or less accurate
			int accuracyDelta = (int) (location.getAccuracy() - currentBestLocation.getAccuracy());
			boolean isLessAccurate = accuracyDelta > 0;
			boolean isMoreAccurate = accuracyDelta < 0;
			boolean isSignificantlyLessAccurate = accuracyDelta > 200;

			// Check if the old and new location are from the same provider
			boolean isFromSameProvider = isSameProvider(location.getProvider(),
					currentBestLocation.getProvider());

			// Determine location quality using a combination of timeliness and accuracy
			if (isMoreAccurate) {
				return true;
			} else if (isNewer && !isLessAccurate) {
				return true;
			} else if (isNewer && !isSignificantlyLessAccurate && isFromSameProvider) {
				return true;
			}
		}
		return false;
	}

	/** Checks whether two providers are the same */
	private boolean isSameProvider(String provider1, String provider2) {
		if (provider1 == null) {
			return provider2 == null;
		}
		return provider1.equals(provider2);
	}
=======
    }

    @Override
    public void onResume() {
        super.onResume();

        locationManager.requestLocationUpdates(
            LocationManager.GPS_PROVIDER, 0, 0, locationListener);
//		locationManager.requestLocationUpdates(
//				LocationManager.NETWORK_PROVIDER, 0, 0, locationListener);


    }

    @Override
    public void onPause() {
        super.onPause();

        locationManager.removeUpdates(locationListener);
    }

    protected android.app.Dialog onCreateDialog(int id) {
        AlertDialog alertDialog = null;
        ProgressDialog progressDialog = null;
        Thread thread = null;
        switch (id) {
            case SUBMITPAYMENT_DIALOG:
                progressDialog = new ProgressDialog(this);

                progressDialog.setMessage("Submitting Request...");
                progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);

                thread = new Thread(new Runnable() {

                    @Override
                    public void run() {
                        // TODO Auto-generated method stub
                        try {
                            SubmitPaymentRequest();

                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                        dialogHandler.sendEmptyMessage(SUBMITPAYMENT_ACTION);
                    }

                });
                dialog = progressDialog;
                thread.start();

                return dialog;
            case SUBMITPAYMENTFAILED_DIALOG:
                alertDialog = new AlertDialog.Builder(this).create();
                alertDialog.setTitle("Failed");

                alertDialog.setMessage(errorMessage);
                alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.dismiss();

                    }
                });

                return alertDialog;
            case SUBMITPAYMENTSUCCESS_DIALOG:
                alertDialog = new AlertDialog.Builder(this).create();
                alertDialog.setTitle("Payment Sumitted");
                NumberFormat nf = NumberFormat.getCurrencyInstance();

                alertDialog.setMessage(String.format(
                    "Your payment for %s was sent to %s.", nf.format(amount),
                    recipientUri));

                alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                        removeDialog(4);
                        dialog.dismiss();

                        friend = null;
                        btnAddContacts.setText("Add recipient");
                        txtAmount.setText("$0.00");
                        txtComments.setText("");
                    }
                });

                return alertDialog;
            case NORECIPIENTSPECIFIED_DIALOG:
                alertDialog = new AlertDialog.Builder(SendPaymentActivity.this)
                .create();
                alertDialog.setTitle("Please Specify a Recipient");
                alertDialog
                .setMessage("You must specify the recipient's mobile number.");

                alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.dismiss();
                    }
                });

                return alertDialog;
            case NOAMOUNTSPECIFIED_DIALOG:
                alertDialog = new AlertDialog.Builder(SendPaymentActivity.this)
                .create();
                alertDialog.setTitle("Please Specify an Amount");
                alertDialog.setMessage("You must specify the amount to send.");

                alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.dismiss();
                    }
                });

                return alertDialog;

            case INVALIDPASSCODELENGTH_DIALOG:
                alertDialog = new AlertDialog.Builder(SendPaymentActivity.this)
                .create();
                alertDialog.setTitle("Invalid Passcode");
                alertDialog
                .setMessage("Your passcode is atleast 4 buttons. Please try again.");

                alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.dismiss();
                    }
                });

                return alertDialog;


            case PAYMENTEXCEEDSLIMIT_DIALOG:
                alertDialog = new AlertDialog.Builder(SendPaymentActivity.this)
                .create();
                alertDialog.setTitle("Exceeds Limit");
                alertDialog
                .setMessage("The payment exceeds your upper limit. Please try again.");

                alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.dismiss();
                    }
                });

                return alertDialog;

        }

        return null;
    }

    protected void launchSendMoneyView() {
        sendMoneyView = View.inflate(this, R.layout.contactmanager, null);
        setContentView(sendMoneyView);


        btnAddContacts = (Button) findViewById(R.id.addRecipient);

        txtAmount = (Button) findViewById(R.id.btnAmount);
        txtComments = (EditText) findViewById(R.id.txtComments);
        btnSendMoney = (Button) findViewById(R.id.btnSubmitPaymentRequest);
        Typeface type = Typeface.createFromAsset(getAssets(),"HelveticaWorld-Bold.ttf");
        btnSendMoney.setTypeface(type);
        btnSendMoney.setTextColor(Color.WHITE);

        txtAmount.setOnClickListener(new OnClickListener(){

            @Override
            public void onClick(View v) {
                startActivityForResult(new Intent(SendPaymentActivity.this, AddMoneyActivity.class), ADD_MONEY);
            }
        });

        btnAddContacts.setOnClickListener(new OnClickListener(){
            @Override
            public void onClick(View v) {
                startActivityForResult(new Intent(SendPaymentActivity.this, FriendsListActivity.class), ADDING_FRIEND);
            }

        });

//		txtAmount.addTextChangedListener(new TextWatcher() {
//			String current = "";
//
//			@Override
//			public void onTextChanged(CharSequence s, int start, int before,
//					int count) {
//				if (!s.toString().equals(current)) {
//					txtAmount.removeTextChangedListener(this);
//
//					String cleanString = s.toString().replaceAll("[$,.]", "");
//
//					double parsed = Double.parseDouble(cleanString);
//					String formatted = NumberFormat.getCurrencyInstance()
//							.format((parsed / 100));
//
//					current = formatted;
//					txtAmount.setText(formatted);
//					txtAmount.setSelection(formatted.length());
//
//					txtAmount.addTextChangedListener(this);
//				}
//			}
//
//			@Override
//			public void afterTextChanged(Editable arg0) {
//				// TODO Auto-generated method stub
//				if (arg0.length() == 14) {
//					arg0.replace(13, 14, "");
//				}
//			}
//
//			@Override
//			public void beforeTextChanged(CharSequence arg0, int arg1,
//					int arg2, int arg3) {
//				// TODO Auto-generated method stub
//
//			}
//		});



        btnSendMoney.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                boolean isValid = true;

                amount = Double.parseDouble(txtAmount.getText().toString().trim()
                    .replaceAll("[$,]*", ""));
                comments = txtComments.getText().toString();

                if (isValid && recipientUri.length() == 0) {
                    showDialog(NORECIPIENTSPECIFIED_DIALOG);
                    isValid = false;
                }
                if (isValid && amount == 0) {
                    showDialog(NOAMOUNTSPECIFIED_DIALOG);
                    isValid = false;
                }
                if (isValid && amount > prefs.getInt("upperLimit", 0)) {
                    showDialog(PAYMENTEXCEEDSLIMIT_DIALOG);
                    isValid = false;
                }
                if (isValid) {
                    Location lastKnownLocation = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);

                    if (isBetterLocation(lastKnownLocation, location)) {
                        location = lastKnownLocation;
                    }


                    if(prefs.getString("userId", "").length() == 0)		{
                        startActivityForResult(new Intent(SendPaymentActivity.this, SignInActivity.class), 1);
                    } else {
                        showSecurityPinDialog();
                    }
                }
            }
        });

        btnSendMoney.setVisibility(View.VISIBLE);

    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (resultCode == RESULT_OK) {
            if (requestCode == ADDING_FRIEND) {
                Bundle bundle = data.getExtras();
                Friend chosenContact = new Friend();
                if (bundle.getString("id") != null)
                {
                    chosenContact.setId(bundle.getString("id"));
                    friend = friendsList.get(friendsList.indexOf(chosenContact));

                    if (friend.isFBContact()) {
                        recipientUri = "fb_" + friend.getId();
                        btnAddContacts.setText(friend.getName() + ": " + friend.getId());
                    }
                    else {
                        recipientUri = "" + friend.getPaypoint();
                        btnAddContacts.setText(friend.toString());
                    }
                }
                else
                {
                    String paypoint = bundle.getString("paypoint");
                    chosenContact.setName("New Contact");
                    chosenContact.setPaypoint(paypoint);
                    friend = chosenContact;
                    recipientUri = "" + paypoint;
                    btnAddContacts.setText("New contact: " + paypoint);
                }


            }
            else if(requestCode == ADD_MONEY){
                Bundle bundle = data.getExtras();
                String amount = bundle.getString("index");
                txtAmount.setText("$"+ amount);
            }
            else {
                launchSendMoneyView();
            }
        }
        else {
            if (requestCode != ADDING_FRIEND && requestCode != ADD_MONEY) {
                finish();
            }
        }
    }

    protected void showSecurityPinDialog() {
        final Dialog d = new Dialog(SendPaymentActivity.this, R.style.CustomDialogTheme);
        d.setContentView(R.layout.security_dialog);

        d.getWindow().setLayout(400, 600);
        d.show();

        TextView txtConfirmHeader = (TextView)d.findViewById(R.id.txtConfirmHeader);
        TextView txtConfirmBody = (TextView)d.findViewById(R.id.txtConfirmBody);

        txtConfirmHeader.setText("Confirm Your Payment");
        txtConfirmBody.setText(String.format("To confirm your payment of %s to %s, swipe you pin below.",
            txtAmount.getText(), friend.getName()));

        Button btnCancel = (Button) d.findViewById(R.id.btnCancelSendMoney);
        btnCancel.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                d.dismiss();
            }
        });

        final CustomLockView ctrlSecurityPin = (CustomLockView) d.findViewById(R.id.ctrlSecurityPin);
        ctrlSecurityPin.invalidate();
        ctrlSecurityPin.setOnTouchListener(new OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                passcode = ctrlSecurityPin.getPasscode();

                if (passcode.length() > 3) {
                    amount = Double.parseDouble(txtAmount.getText().toString()
                        .replace("$", ""));
                    comments = txtComments.getText().toString();
                    passcode = ctrlSecurityPin.getPasscode();

                    d.dismiss();

                    showDialog(SUBMITPAYMENT_DIALOG);
                } else
                    showDialog(INVALIDPASSCODELENGTH_DIALOG);

                return false;
            }
        });
    }

    protected void SubmitPaymentRequest() {

        PaymentRequest paymentRequest = new PaymentRequest();
        paymentRequest.UserId = prefs.getString("userId", "");
        paymentRequest.SecurityPin = passcode;
        paymentRequest.SenderUri = prefs.getString("login", "");
        paymentRequest.RecipientUri = recipientUri;
        paymentRequest.Amount = amount;
        paymentRequest.Comments = comments;
        paymentRequest.SenderAccountId = prefs.getString("paymentAccountId", "0");

        if (location != null) {
            paymentRequest.Latitude = location.getLatitude();
            paymentRequest.Longitude = location.getLongitude();
        }

        paymentResponse = PaymentServices.sendMoney(paymentRequest);

    }

    /** Determines whether one Location reading is better than the current Location fix
     * @param location  The new Location that you want to evaluate
     * @param currentBestLocation  The current Location fix, to which you want to compare the new one
     */
    private boolean isBetterLocation(Location location, Location currentBestLocation) {
        final int TWO_MINUTES = 1000 * 60 * 2;

        if (location != null) {

            if (currentBestLocation == null) {
                // A new location is always better than no location
                return true;
            }

            // Check whether the new location fix is newer or older
            long timeDelta = location.getTime() - currentBestLocation.getTime();
            boolean isSignificantlyNewer = timeDelta > TWO_MINUTES;
            boolean isSignificantlyOlder = timeDelta < -TWO_MINUTES;
            boolean isNewer = timeDelta > 0;

            // If it's been more than two minutes since the current location, use the new location
            // because the user has likely moved
            if (isSignificantlyNewer) {
                return true;
                // If the new location is more than two minutes older, it must be worse
            } else if (isSignificantlyOlder) {
                return false;
            }

            // Check whether the new location fix is more or less accurate
            int accuracyDelta = (int) (location.getAccuracy() - currentBestLocation.getAccuracy());
            boolean isLessAccurate = accuracyDelta > 0;
            boolean isMoreAccurate = accuracyDelta < 0;
            boolean isSignificantlyLessAccurate = accuracyDelta > 200;

            // Check if the old and new location are from the same provider
            boolean isFromSameProvider = isSameProvider(location.getProvider(),
                currentBestLocation.getProvider());

            // Determine location quality using a combination of timeliness and accuracy
            if (isMoreAccurate) {
                return true;
            } else if (isNewer && !isLessAccurate) {
                return true;
            } else if (isNewer && !isSignificantlyLessAccurate && isFromSameProvider) {
                return true;
            }
        }
        return false;
    }

    /** Checks whether two providers are the same */
    private boolean isSameProvider(String provider1, String provider2) {
        if (provider1 == null) {
            return provider2 == null;
        }
        return provider1.equals(provider2);
    }
>>>>>>> 31a4072af63868cb5dc09a90683f893d7dca6010

}
Solution content

        launchSendMoneyView();


    }

    @Override
    public void onResume() {
        super.onResume();

        tracker.trackPageView("Send Money");
        locationManager.requestLocationUpdates(
            LocationManager.GPS_PROVIDER, 0, 0, locationListener);
//		locationManager.requestLocationUpdates(
//				LocationManager.NETWORK_PROVIDER, 0, 0, locationListener);


    }

    @Override
    public void onPause() {
        super.onPause();

        locationManager.removeUpdates(locationListener);
    }

    protected android.app.Dialog onCreateDialog(int id) {
        AlertDialog alertDialog = null;
        ProgressDialog progressDialog = null;
        Thread thread = null;
        switch (id) {
            case SUBMITPAYMENT_DIALOG:
            	tracker.trackPageView("Send Money: Confirm");
                progressDialog = new ProgressDialog(this);

                progressDialog.setMessage("Submitting Request...");
                progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);

                thread = new Thread(new Runnable() {

                    @Override
                    public void run() {
                        // TODO Auto-generated method stub
                        try {
                            SubmitPaymentRequest();

                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                        dialogHandler.sendEmptyMessage(SUBMITPAYMENT_ACTION);
                    }

                });
                dialog = progressDialog;
                thread.start();

                return dialog;
            case SUBMITPAYMENTFAILED_DIALOG:
                alertDialog = new AlertDialog.Builder(this).create();
                alertDialog.setTitle("Failed");

                alertDialog.setMessage(errorMessage);
                alertDialog.setButton("OK", new DialogInterface.OnClickListener() {

                    public void onClick(DialogInterface dialog, int which) {
                        dialog.dismiss();

                    }
                });

                return alertDialog;
            case SUBMITPAYMENTSUCCESS_DIALOG:
            	tracker.trackPageView("Send Money: Completed");
                alertDialog = new AlertDialog.Builder(this).create();
                alertDialog.setTitle("Payment Sumitted");
                NumberFormat nf = NumberFormat.getCurrencyInstance();

                alertDialog.setMessage(String.format(
                    "Your payment for %s was sent to %s.", nf.format(amount),
                    recipientUri));

                alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                        removeDialog(4);
                        dialog.dismiss();

                        friend = null;
                        btnAddContacts.setText("Add recipient");
                        txtAmount.setText("$0.00");
                        txtComments.setText("");
                    }
                });

                return alertDialog;
            case NORECIPIENTSPECIFIED_DIALOG:
                alertDialog = new AlertDialog.Builder(SendPaymentActivity.this)
                .create();
                alertDialog.setTitle("Please Specify a Recipient");
                alertDialog
                .setMessage("You must specify the recipient's mobile number.");

                alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.dismiss();
                    }
                });

                return alertDialog;
            case NOAMOUNTSPECIFIED_DIALOG:
                alertDialog = new AlertDialog.Builder(SendPaymentActivity.this)
                .create();
                alertDialog.setTitle("Please Specify an Amount");
                alertDialog.setMessage("You must specify the amount to send.");

                alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.dismiss();
                    }
                });

                return alertDialog;

            case INVALIDPASSCODELENGTH_DIALOG:
                alertDialog = new AlertDialog.Builder(SendPaymentActivity.this)
                .create();
                alertDialog.setTitle("Invalid Passcode");
                alertDialog
                .setMessage("Your passcode is atleast 4 buttons. Please try again.");

                alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.dismiss();
                    }
                });

                return alertDialog;


            case PAYMENTEXCEEDSLIMIT_DIALOG:
                alertDialog = new AlertDialog.Builder(SendPaymentActivity.this)
                .create();
                alertDialog.setTitle("Exceeds Limit");
                alertDialog
                .setMessage("The payment exceeds your upper limit. Please try again.");

                alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.dismiss();
                    }
                });

                return alertDialog;

        }

        return null;
    }
    protected void launchSendMoneyView() {
        sendMoneyView = View.inflate(this, R.layout.contactmanager, null);
        setContentView(sendMoneyView);


        btnAddContacts = (Button) findViewById(R.id.addRecipient);

        txtAmount = (Button) findViewById(R.id.btnAmount);
        txtComments = (EditText) findViewById(R.id.txtComments);
        btnSendMoney = (Button) findViewById(R.id.btnSubmitPaymentRequest);
        Typeface type = Typeface.createFromAsset(getAssets(),"HelveticaWorld-Bold.ttf");
        btnSendMoney.setTypeface(type);
        btnSendMoney.setTextColor(Color.WHITE);

        txtAmount.setOnClickListener(new OnClickListener(){

            @Override
            public void onClick(View v) {
                startActivityForResult(new Intent(SendPaymentActivity.this, AddMoneyActivity.class), ADD_MONEY);
            }
        });

        btnAddContacts.setOnClickListener(new OnClickListener(){
            @Override
            public void onClick(View v) {
                startActivityForResult(new Intent(SendPaymentActivity.this, FriendsListActivity.class), ADDING_FRIEND);
            }

        });


        btnSendMoney.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                boolean isValid = true;

                amount = Double.parseDouble(txtAmount.getText().toString().trim()
                    .replaceAll("[$,]*", ""));
                comments = txtComments.getText().toString();

                if (isValid && recipientUri.length() == 0) {
                    showDialog(NORECIPIENTSPECIFIED_DIALOG);
                    isValid = false;
                }
                if (isValid && amount == 0) {
                    showDialog(NOAMOUNTSPECIFIED_DIALOG);
                    isValid = false;
                }
                if (isValid && amount > prefs.getInt("upperLimit", 0)) {
                    showDialog(PAYMENTEXCEEDSLIMIT_DIALOG);
                    isValid = false;
                }
                if (isValid) {

                    Location lastKnownLocation = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);

                    if (isBetterLocation(lastKnownLocation, location)) {
                        location = lastKnownLocation;
                    }


                    if(prefs.getString("userId", "").length() == 0)		{
                        startActivityForResult(new Intent(SendPaymentActivity.this, SignInActivity.class), 1);
                    } else {
                        showSecurityPinDialog();
                    }
                }
            }
        });

        btnSendMoney.setVisibility(View.VISIBLE);

    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (resultCode == RESULT_OK) {
            if (requestCode == ADDING_FRIEND) {
                Bundle bundle = data.getExtras();
                Friend chosenContact = new Friend();
                if (bundle.getString("id") != null)
                {
                    chosenContact.setId(bundle.getString("id"));
                    friend = friendsList.get(friendsList.indexOf(chosenContact));

                    if (friend.isFBContact()) {
                        recipientUri = "fb_" + friend.getId();
                        btnAddContacts.setText(friend.getName() + ": " + friend.getId());
                    }
                    else {
                        recipientUri = "" + friend.getPaypoint();
                        btnAddContacts.setText(friend.toString());
                    }
                }
                else
                {
                    String paypoint = bundle.getString("paypoint");
                    chosenContact.setName("New Contact");
                    chosenContact.setPaypoint(paypoint);
                    friend = chosenContact;
                    recipientUri = "" + paypoint;
                    btnAddContacts.setText("New contact: " + paypoint);
                }


            }
            else if(requestCode == ADD_MONEY){
                Bundle bundle = data.getExtras();
                String amount = bundle.getString("index");
                txtAmount.setText("$"+ amount);
            }
            else {
                launchSendMoneyView();
            }
        }
        else {
            if (requestCode != ADDING_FRIEND && requestCode != ADD_MONEY) {
                finish();
            }
        }
    }

    protected void showSecurityPinDialog() {
        final Dialog d = new Dialog(SendPaymentActivity.this, R.style.CustomDialogTheme);
        d.setContentView(R.layout.security_dialog);

        d.getWindow().setLayout(400, 600);
        d.show();

        TextView txtConfirmHeader = (TextView)d.findViewById(R.id.txtConfirmHeader);
        TextView txtConfirmBody = (TextView)d.findViewById(R.id.txtConfirmBody);

        txtConfirmHeader.setText("Confirm Your Payment");
        txtConfirmBody.setText(String.format("To confirm your payment of %s to %s, swipe you pin below.",
            txtAmount.getText(), friend.getName()));
        Button btnCancel = (Button) d.findViewById(R.id.btnCancelSendMoney);
        btnCancel.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                d.dismiss();
            }
        });

        final CustomLockView ctrlSecurityPin = (CustomLockView) d.findViewById(R.id.ctrlSecurityPin);
        ctrlSecurityPin.invalidate();
        ctrlSecurityPin.setOnTouchListener(new OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                passcode = ctrlSecurityPin.getPasscode();

                if (passcode.length() > 3) {
                    amount = Double.parseDouble(txtAmount.getText().toString()
                        .replace("$", ""));
                    comments = txtComments.getText().toString();
                    passcode = ctrlSecurityPin.getPasscode();

                    d.dismiss();

                    showDialog(SUBMITPAYMENT_DIALOG);
                } else
                    showDialog(INVALIDPASSCODELENGTH_DIALOG);

                return false;
            }
        });
    }

    protected void SubmitPaymentRequest() {

        PaymentRequest paymentRequest = new PaymentRequest();
        paymentRequest.UserId = prefs.getString("userId", "");
        paymentRequest.SecurityPin = passcode;
        paymentRequest.SenderUri = prefs.getString("login", "");
        paymentRequest.RecipientUri = recipientUri;
        paymentRequest.Amount = amount;
        paymentRequest.Comments = comments;
        paymentRequest.SenderAccountId = prefs.getString("paymentAccountId", "0");

        if (location != null) {
            paymentRequest.Latitude = location.getLatitude();
            paymentRequest.Longitude = location.getLongitude();
        }

        paymentResponse = PaymentServices.sendMoney(paymentRequest);

    }

    /** Determines whether one Location reading is better than the current Location fix
     * @param location  The new Location that you want to evaluate
     * @param currentBestLocation  The current Location fix, to which you want to compare the new one
     */
    private boolean isBetterLocation(Location location, Location currentBestLocation) {
        final int TWO_MINUTES = 1000 * 60 * 2;

        if (location != null) {

            if (currentBestLocation == null) {
                // A new location is always better than no location
                return true;
            }

            // Check whether the new location fix is newer or older
            long timeDelta = location.getTime() - currentBestLocation.getTime();
            boolean isSignificantlyNewer = timeDelta > TWO_MINUTES;
            boolean isSignificantlyOlder = timeDelta < -TWO_MINUTES;
            boolean isNewer = timeDelta > 0;

            // If it's been more than two minutes since the current location, use the new location
            // because the user has likely moved
            if (isSignificantlyNewer) {
                return true;
                // If the new location is more than two minutes older, it must be worse
            } else if (isSignificantlyOlder) {
                return false;
            }

            // Check whether the new location fix is more or less accurate
            int accuracyDelta = (int) (location.getAccuracy() - currentBestLocation.getAccuracy());
            boolean isLessAccurate = accuracyDelta > 0;
            boolean isMoreAccurate = accuracyDelta < 0;
            boolean isSignificantlyLessAccurate = accuracyDelta > 200;

            // Check if the old and new location are from the same provider
            boolean isFromSameProvider = isSameProvider(location.getProvider(),
                currentBestLocation.getProvider());

            // Determine location quality using a combination of timeliness and accuracy
            if (isMoreAccurate) {
                return true;
            } else if (isNewer && !isLessAccurate) {
                return true;
            } else if (isNewer && !isSignificantlyLessAccurate && isFromSameProvider) {
                return true;
            }
        }
        return false;
    }

    /** Checks whether two providers are the same */
    private boolean isSameProvider(String provider1, String provider2) {
        if (provider1 == null) {
            return provider2 == null;
        }
        return provider1.equals(provider2);
    }

}
File
SendPaymentActivity.java
Developer's decision
Manual
Kind of conflict
Annotation
Comment
Method declaration