/* * Aegis Bitcoin Wallet - The secure Bitcoin wallet for Android * Copyright 2014 Bojan Simic and specularX.co, designed by Reuven Yamrom * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ package com.aegiswallet.tasks; import android.content.Context; import android.database.Cursor; import android.provider.ContactsContract; import com.aegiswallet.PayBitsApplication; import com.aegiswallet.R; import com.aegiswallet.listeners.WalletDecryptedListener; import com.aegiswallet.widgets.AegisProgressDialog; import com.google.bitcoin.core.Wallet; import java.util.ArrayList; import java.util.HashMap; import java.util.Map; /** * Created by bsimic on 3/19/14. */ public class PopulateContactsTask extends BaseTask { private String TAG = this.getClass().getName(); private Context context; private ArrayList<Map<String, String>> peopleList; public PopulateContactsTask(Context context, ArrayList<Map<String, String>> peopleList) { this.context = context; this.peopleList = peopleList; populateContactsList(); } @Override protected void onPreExecute() { } @Override protected Object doInBackground(Object[] objects) { populateContactsList(); return null; } @Override protected void onPostExecute(Object o) { } public void populateContactsList() { peopleList.clear(); Cursor people = context.getContentResolver().query( ContactsContract.Contacts.CONTENT_URI, null, null, null, null); while (people.moveToNext()) { String contactName = people.getString(people .getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME)); String contactId = people.getString(people .getColumnIndex(ContactsContract.Contacts._ID)); String hasPhone = people .getString(people .getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER)); if ((Integer.parseInt(hasPhone) > 0)) { Cursor phones = context.getContentResolver().query( ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, ContactsContract.CommonDataKinds.Phone.CONTACT_ID + " = " + contactId, null, null); while (phones.moveToNext()) { //store numbers and display a dialog letting the user select which. String phoneNumber = phones.getString( phones.getColumnIndex( ContactsContract.CommonDataKinds.Phone.NUMBER)); String numberType = phones.getString(phones.getColumnIndex( ContactsContract.CommonDataKinds.Phone.TYPE)); Map<String, String> NamePhoneType = new HashMap<String, String>(); NamePhoneType.put("Name", contactName); NamePhoneType.put("Phone", phoneNumber); if(numberType != null) { if (numberType.equals("0")) NamePhoneType.put("Type", "Work"); else if (numberType.equals("1")) NamePhoneType.put("Type", "Home"); else if (numberType.equals("2")) NamePhoneType.put("Type", "Mobile"); else NamePhoneType.put("Type", "Other"); } peopleList.add(NamePhoneType); } phones.close(); } } people.close(); } }