Advertisement
ChocoMan

Untitled

Jun 18th, 2012
268
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.56 KB | None | 0 0
  1. public class CallLog extends Activity{
  2.  
  3.     public static final String TAG = "CallLog";
  4.  
  5.     LayoutInflater inflater;
  6.     private ListView lv;
  7.     private LinearLayout ll_btn_newMsg;
  8.  
  9.     String address = null;
  10.     ArrayList<String> newlist = null;
  11.  
  12.     @Override
  13.     protected void onCreate(Bundle savedInstanceState) {
  14.  
  15.         super.onCreate(savedInstanceState);
  16.         requestWindowFeature(Window.FEATURE_NO_TITLE);
  17.         setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
  18.         setContentView(R.layout.call_log); // call_log
  19.  
  20.         // removes all duplicate instances of the same number
  21.         Set<String> set = new HashSet<String>(fetchInboxNumbers());
  22.         // then puts them in a new arraylist
  23.         newlist = new ArrayList<String>(set);
  24.  
  25.         // CUSTOMADAPTER CONSTRUCTOR
  26.         CustomAdapter cAdapt = new CustomAdapter(this,
  27.                 R.id.lv_contactList, newlist);
  28.  
  29.         // Find the ListView resource
  30.         lv = (ListView) findViewById(R.id.lv_contactList);
  31.         lv.setAdapter(cAdapt);
  32.         lv.setTextFilterEnabled(true);
  33.         lv.setClickable(true);
  34.  
  35.         Log.d(TAG, "list count " + lv.getCount());
  36.     }
  37.  
  38.     /** END ONCREATE **/
  39.  
  40.     // Menu inflater
  41.     @Override
  42.     public boolean onCreateOptionsMenu(Menu menu) {
  43.         MenuInflater inflater = getMenuInflater();
  44.         inflater.inflate(R.menu.menu_calllog, menu);
  45.         // Calling a method to set the background color of the options menu
  46.         return true;
  47.     } // END MENU INFLATER
  48.    
  49.  
  50.         // GET ALL CONTACTS FROM INBOX
  51.     public ArrayList<String> fetchInboxNumbers() {
  52.  
  53.         newMsgNumbers = new ArrayList<String>();
  54.         ArrayList<String> sms = new ArrayList<String>();
  55.         Uri uriSms = Uri.parse("content://sms/inbox");
  56.         Cursor cursorM = getContentResolver().query(uriSms,
  57.                 new String[] { "_id", "address", "date", "body" }, null, null, null);
  58.  
  59.         cursorM.moveToFirst();
  60.         while (cursorM.moveToNext()) {
  61.  
  62.             String nMN = cursorM.getString(1);
  63.             address = cursorM.getString(1); // Displays phone number
  64.             address = getDisplayName(address); // convert numbers to names
  65.             Log.d("ADDRESS", address);
  66.             newMsgNumbers.add(nMN);
  67.             sms.add(address); // + " " + body
  68.         }
  69.         return sms;
  70.     } // END FETCHINBOX
  71.    
  72.     public String getDisplayName(String address) {
  73.        
  74.         Uri uri = Uri.withAppendedPath(ContactsContract.PhoneLookup.CONTENT_FILTER_URI,  Uri.encode(address));
  75.        
  76.         Cursor cursorN = getContentResolver().query(uri, new String[] { Phone._ID, Phone.DISPLAY_NAME, Phone.PHOTO_ID}, null, null, null);
  77.        
  78.         if (cursorN.moveToFirst()) {
  79.  
  80.            address =  cursorN.getString(cursorN.getColumnIndex(ContactsContract.PhoneLookup.DISPLAY_NAME));
  81.         }
  82.         return address;
  83.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement