Guest User

Untitled

a guest
Oct 16th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.73 KB | None | 0 0
  1. import java.io.ByteArrayInputStream;
  2. import java.util.HashMap;
  3. import java.util.List;
  4. import java.util.Map;
  5. import com.sabretch.mobility.colorEyeD3.R;
  6. import com.sabretch.mobility.colorEyeD3.Constants.Constants;
  7. import com.sabretch.mobility.colorEyeD3.custom.CustomScreen;
  8. import
  9. com.sabretch.mobility.colorEyeD3.database.TableDetails.MetaData;
  10. import com.sabretch.mobility.colorEyeD3.text.compose.Compose;
  11. import android.app.ListActivity;
  12. import android.app.ProgressDialog;
  13. import android.app.SearchManager;
  14. import android.content.ContentUris;
  15. import android.content.Context;
  16. import android.content.Intent;
  17. import android.database.Cursor;
  18. import android.graphics.Bitmap;
  19. import android.graphics.drawable.BitmapDrawable;
  20. import android.net.Uri;
  21. import android.os.Bundle;
  22. import android.provider.Contacts.Phones;
  23. import android.provider.Contacts.Photos;
  24. import android.util.Log;
  25. import android.view.LayoutInflater;
  26. import android.view.View;
  27. import android.view.ViewGroup;
  28. import android.widget.Filterable;
  29. import android.widget.ImageView;
  30. import android.widget.ListView;
  31. import android.widget.SimpleCursorAdapter;
  32. import android.widget.TextView;
  33.  
  34. public class Contacts extends ListActivity {
  35. static final String[] cat = Constants.DEFAULT_CATEGORIES;
  36. static int[] id;
  37. static List<Long> contactId;
  38. DisplayContacts dispCont;
  39. List<String> number;
  40. Map<String, String> combination = new HashMap<String, String>();
  41. String isDisplayDetails;
  42. ProgressDialog dialog;
  43.  
  44. private class DisplayContacts extends SimpleCursorAdapter {
  45. private LayoutInflater mInflater;
  46. Context mCtx;
  47.  
  48. public DisplayContacts(Context context, int layout, Cursor c,
  49. String[] from, int[] to) {
  50. super(context, layout, c, from, to);
  51. // TODO Auto-generated constructor stub
  52. mInflater = LayoutInflater.from(context);
  53. this.mCtx = context;
  54. }
  55.  
  56. @Override
  57. public View newView(Context context, Cursor cursor, ViewGroup
  58. parent) {
  59. // TODO Auto-generated method stub
  60. Cursor c = getCursor();
  61. // int idCol = c.getColumnIndex(Phones._ID);
  62. int nameCol = c.getColumnIndex(Phones.NAME);
  63. int numCol = c.getColumnIndex(Phones.NUMBER);
  64. int foreign = c.getColumnIndex(Phones.PERSON_ID);
  65. String name = c.getString(nameCol);
  66. String number = c.getString(numCol);
  67. // long id = c.getLong(idCol);
  68. long phoneForeign = c.getLong(foreign);
  69. View v = mInflater.inflate(R.layout.contacts, parent, false);
  70. TextView name_text = (TextView) v.findViewById(R.id.contactName);
  71.  
  72. if (name_text != null) {
  73. name_text.setText(name);
  74. }
  75.  
  76. TextView num_text = (TextView) v.findViewById(R.id.number);
  77. if (num_text != null) {
  78. num_text.setText(number);
  79. }
  80. // set the profile picture
  81. ImageView profile = (ImageView) v.findViewById(R.id.imgContact);
  82. if (profile != null) {
  83. // retrieve the contact photo as a Bitmap
  84. // Uri uri = ContentUris.withAppendedId(People.CONTENT_URI, id);
  85. Cursor cur = getContentResolver().query(Photos.CONTENT_URI,
  86. null, Photos.PERSON_ID + "='" + phoneForeign + "'",
  87. null, null);
  88. byte[] b = null;
  89. if (cur != null) {
  90. if (cur.moveToNext()) {
  91. int imgColumn = cur.getColumnIndex(Photos.DATA);
  92. b = cur.getBlob(imgColumn);
  93. }
  94. }
  95. Bitmap bm = null;
  96. if (b != null) {
  97. ByteArrayInputStream bytes = new ByteArrayInputStream(b);
  98. BitmapDrawable bmd = new BitmapDrawable(bytes);
  99. bm = bmd.getBitmap();
  100. profile.setImageBitmap(bm);
  101. } else {
  102. profile.setImageResource(R.drawable.defaultcontact);
  103. }
  104. }
  105. ImageView indicator = (ImageView) v.findViewById(R.id.is);
  106. boolean b = isAssign(number);
  107. if (b) {
  108. // set the profile picture
  109. indicator.setImageResource(R.drawable.ok);
  110. } else {
  111. indicator.setImageResource(R.drawable.delete);
  112. }
  113. dialog.dismiss();
  114. return v;
  115. }
  116.  
  117. protected boolean isAssign(String number) {
  118. boolean b = false;
  119. Uri books = MetaData.CONTENT_URI;
  120. // Log.d("Authority", books.getAuthority());
  121. Cursor cur = managedQuery(books, null, MetaData.MOBILE_NUMBER
  122. + "='" + number + "'", null, MetaData.CAT_NAME + " DESC");
  123. startManagingCursor(cur);
  124. if (cur != null) {
  125. if (cur.moveToNext()) {
  126. combination.put(number.trim(), cur.getString(cur
  127. .getColumnIndex(MetaData.COMBINATION)));
  128. isDisplayDetails = cur.getString(cur
  129. .getColumnIndex(MetaData.IS_HIDE));
  130. b = true;
  131. return b;
  132. } else {
  133. return b;
  134. }
  135. }
  136. return b;
  137. }
  138.  
  139. @Override
  140. public void bindView(View view, Context context, Cursor c) {
  141. // TODO Auto-generated method stub
  142. // int idCol = c.getColumnIndex(Phones._ID);
  143. int nameCol = c.getColumnIndex(Phones.NAME);
  144. int numCol = c.getColumnIndex(Phones.NUMBER);
  145. int foreign = c.getColumnIndex(Phones.PERSON_ID);
  146. String name = c.getString(nameCol);
  147. String number = c.getString(numCol);
  148. // long id = c.getLong(idCol);
  149. long phoneForeign = c.getLong(foreign);
  150. // View v = mInflater.inflate(R.layout.contacts, parent, false);
  151. TextView name_text = (TextView)
  152. view.findViewById(R.id.contactName);
  153. if (name_text != null) {
  154. name_text.setText(name);
  155. }
  156.  
  157. TextView num_text = (TextView) view.findViewById(R.id.number);
  158. if (num_text != null) {
  159. num_text.setText(number);
  160. }
  161.  
  162. // set the profile picture
  163. ImageView profile = (ImageView) view.findViewById(R.id.imgContact);
  164. if (profile != null) {
  165. // Uri uri = ContentUris.withAppendedId(People.CONTENT_URI, id);
  166. Cursor cur = getContentResolver().query(Photos.CONTENT_URI,
  167. null, Photos.PERSON_ID + "='" + phoneForeign + "'",
  168. null, null);
  169. byte[] b = null;
  170. if (cur != null) {
  171. if (cur.moveToNext()) {
  172. int imgColumn = cur.getColumnIndex(Photos.DATA);
  173. b = cur.getBlob(imgColumn);
  174. }
  175. }
  176. Bitmap bm = null;
  177. if (b != null) {
  178. ByteArrayInputStream bytes = new ByteArrayInputStream(b);
  179. BitmapDrawable bmd = new BitmapDrawable(bytes);
  180. bm = bmd.getBitmap();
  181. profile.setImageBitmap(bm);
  182. } else {
  183. profile.setImageResource(R.drawable.defaultcontact);
  184. }
  185. ImageView indicator = (ImageView) view.findViewById(R.id.is);
  186. boolean assign = isAssign(number);
  187. if (assign) {
  188. // set the profile picture
  189. indicator.setImageResource(R.drawable.ok);
  190. } else {
  191. indicator.setImageResource(R.drawable.delete);
  192. }
  193. }
  194. }
  195.  
  196. @Override
  197. public Object getItem(int position) {
  198. // TODO Auto-generated method stub
  199. return super.getItem(position);
  200. }
  201.  
  202. }
  203.  
  204. @Override
  205. protected void onCreate(Bundle savedInstanceState) {
  206. // TODO Auto-generated method stub
  207. super.onCreate(savedInstanceState);
  208. setTitle("Color Eye D - Contacts");
  209. dialog = ProgressDialog.show(Contacts.this, "",
  210. "Loading. Please wait...", true);
  211.  
  212. Cursor cursor = getContentResolver().query(Phones.CONTENT_URI, null,
  213. null, null, Phones.NAME + " ASC");
  214. startManagingCursor(cursor);
  215.  
  216. String[] columns = new String[] { Phones.NAME, Phones.NUMBER };
  217. int[] names = new int[] { R.id.contactName, R.id.number };
  218. dispCont = new DisplayContacts(this, R.layout.contacts, cursor,
  219. columns, names);
  220. setDefaultKeyMode(DEFAULT_KEYS_SEARCH_LOCAL);
  221. onNewIntent(getIntent());
  222. setListAdapter(dispCont);
  223. // setListAdapter(new DisplayContacts(this));
  224. registerForContextMenu(getListView());
  225.  
  226. }
  227.  
  228. @Override
  229. protected void onListItemClick(ListView l, View v, int position, long
  230. id) {
  231. // TODO Auto-generated method stub
  232. Cursor c = (Cursor) dispCont.getItem(position);
  233. long phoneId = c.getLong(c.getColumnIndex(Phones._ID));
  234. String composeName = null;
  235. Uri uri = ContentUris.withAppendedId(Phones.CONTENT_URI, phoneId);
  236. Cursor cur = managedQuery(uri, null, null, null, null);
  237. String phoneNumber = null;
  238. if (cur.moveToFirst()) {
  239. Constants.selectedName = cur.getString(cur
  240. .getColumnIndex(Phones.NAME));
  241. composeName = Constants.selectedName;
  242. int phoneColumn = cur.getColumnIndex(Phones.NUMBER);
  243. do {
  244. // Get the field values
  245. phoneNumber = cur.getString(phoneColumn);
  246. } while (cur.moveToNext());
  247. }
  248.  
  249. if (Constants.isCompose) {
  250. String combina = null;
  251. if (phoneNumber != null) {
  252. Constants.selectedName = null;
  253. combina = combination.get(phoneNumber.trim());
  254. }
  255. String[] data = new String[] { combina, composeName, phoneNumber,
  256. isDisplayDetails };
  257. Intent comp = new Intent(Contacts.this, Compose.class);
  258. comp.putExtra("Combination", data);
  259. startActivity(comp);
  260. finish();
  261. } else {
  262. Intent i = new Intent(Contacts.this, CustomScreen.class);
  263. Bundle b = new Bundle();
  264. Constants.mobile = phoneNumber;
  265. b.putString("Number", phoneNumber);
  266. i.putExtras(b);
  267. startActivity(i);
  268. finish();
  269. }
  270. }
  271. }
Add Comment
Please, Sign In to add comment