Ejemplo n.º 1
0
  /**
   * Default Constructor.
   *
   * @param c {@link ConversationListActivity}
   */
  public ConversationAdapter(final Activity c) {
    super(c, R.layout.conversationlist_item, null, true);
    activity = c;

    SharedPreferences p = PreferenceManager.getDefaultSharedPreferences(activity);
    useGridLayout = PreferencesActivity.getGridlayoutEnabled(activity);
    if (useGridLayout) {
      super.setViewResource(R.layout.conversation_square);
    }
    final ContentResolver cr = c.getContentResolver();
    queryHandler = new BackgroundQueryHandler(cr);
    SpamDB spam = new SpamDB(c);
    spam.open();
    blacklist = spam.getAllEntries();
    spam.close();

    defaultContactAvatar = c.getResources().getDrawable(R.drawable.ic_contact_picture);

    convertNCR = PreferencesActivity.decodeDecimalNCR(c);
    showEmoticons = PreferencesActivity.showEmoticons(c);
    textSize = PreferencesActivity.getTextsize(c);
    textColor = PreferencesActivity.getTextcolor(c);

    Cursor cursor = null;
    try {
      cursor = cr.query(Conversation.URI_SIMPLE, Conversation.PROJECTION_SIMPLE, null, null, null);
    } catch (SQLiteException e) {
      Log.e(TAG, "error getting conversations", e);
    }
    /* {@link Cursor} to the original Content to listen for changes. */
    Cursor origCursor = cursor;

    if (origCursor != null) {
      origCursor.registerContentObserver(
          new ContentObserver(new Handler()) {
            @Override
            public void onChange(final boolean selfChange) {
              super.onChange(selfChange);
              if (!selfChange) {
                Log.d(TAG, "call startMsgListQuery();");
                ConversationAdapter.this.startMsgListQuery();
                Log.d(TAG, "invalidate cache");
                Conversation.invalidate();
              }
            }
          });
    }
    // startMsgListQuery();
  }
 /**
  * Add or remove an entry to/from blacklist.
  *
  * @param context {@link Context}
  * @param addr address
  */
 private static void addToOrRemoveFromSpamlist(final Context context, final String addr) {
   final SpamDB db = new SpamDB(context);
   db.open();
   if (!db.isInDB(addr)) {
     db.insertNr(addr);
     Log.d(TAG, "Added " + addr + " to spam list");
   } else {
     db.removeNr(addr);
     Log.d(TAG, "Removed " + addr + " from spam list");
   }
   db.close();
 }
 /** {@inheritDoc} */
 public boolean onItemLongClick(
     final AdapterView<?> parent, final View view, final int position, final long id) {
   final Conversation c =
       Conversation.getConversation(this, (Cursor) parent.getItemAtPosition(position), true);
   final Uri target = c.getUri();
   Builder builder = new Builder(this);
   String[] items = this.longItemClickDialog;
   final Contact contact = c.getContact();
   final String a = contact.getNumber();
   Log.d(TAG, "p: " + a);
   final String n = contact.getName();
   if (TextUtils.isEmpty(n)) {
     builder.setTitle(a);
     items = items.clone();
     items[WHICH_VIEW_CONTACT] = this.getString(R.string.add_contact_);
   } else {
     builder.setTitle(n);
   }
   final SpamDB db = new SpamDB(this.getApplicationContext());
   db.open();
   if (db.isInDB(a)) {
     items = items.clone();
     items[WHICH_MARK_SPAM] = this.getString(R.string.dont_filter_spam_);
   }
   db.close();
   builder.setItems(
       items,
       new DialogInterface.OnClickListener() {
         @Override
         public void onClick(final DialogInterface dialog, final int which) {
           Intent i = null;
           switch (which) {
             case WHICH_ANSWER:
               ConversationListActivity.this.startActivity(
                   getComposeIntent(ConversationListActivity.this, a));
               break;
             case WHICH_CALL:
               i = new Intent(Intent.ACTION_VIEW, Uri.parse("tel:" + a));
               ConversationListActivity.this.startActivity(i);
               break;
             case WHICH_VIEW_CONTACT:
               if (n == null) {
                 i = ContactsWrapper.getInstance().getInsertPickIntent(a);
                 Conversation.flushCache();
               } else {
                 final Uri uri = c.getContact().getUri();
                 i = new Intent(Intent.ACTION_VIEW, uri);
               }
               ConversationListActivity.this.startActivity(i);
               break;
             case WHICH_VIEW:
               i =
                   new Intent(
                       ConversationListActivity.this, // .
                       MessageListActivity.class);
               i.setData(target);
               ConversationListActivity.this.startActivity(i);
               break;
             case WHICH_DELETE:
               ConversationListActivity.deleteMessages(
                   ConversationListActivity.this,
                   target,
                   R.string.delete_thread_,
                   R.string.delete_thread_question,
                   null);
               break;
             case WHICH_MARK_SPAM:
               ConversationListActivity.addToOrRemoveFromSpamlist(
                   ConversationListActivity.this, c.getContact().getNumber());
               break;
             default:
               break;
           }
         }
       });
   builder.create().show();
   return true;
 }