Exemplo n.º 1
0
 /**
  * Get a {@link Conversation}.
  *
  * @param context {@link Context}
  * @param threadId threadId
  * @param forceUpdate force an update of that {@link Conversation}
  * @return {@link Conversation}
  */
 public static Conversation getConversation(
     final Context context, final int threadId, final boolean forceUpdate) {
   Log.d(TAG, "getConversation(" + threadId + ")");
   synchronized (CACHE) {
     Conversation ret = CACHE.get(threadId);
     if (ret == null || ret.getContact().getNumber() == null || forceUpdate) {
       Cursor cursor =
           context
               .getContentResolver()
               .query(
                   URI_SIMPLE,
                   PROJECTION_SIMPLE,
                   ID + " = ?",
                   new String[] {String.valueOf(threadId)},
                   null);
       if (cursor.moveToFirst()) {
         ret = getConversation(context, cursor, true);
       } else {
         Log.e(TAG, "did not found conversation: " + threadId);
       }
       cursor.close();
     }
     return ret;
   }
 }
Exemplo n.º 2
0
 /** {@inheritDoc} */
 @Override
 public final void onClick(final View v) {
   switch (v.getId()) {
     case R.id.add:
       Preferences.setDefaultPlan(this, false);
       Intent intent = new Intent(this, RuleEdit.class);
       this.startActivity(intent);
       break;
     case R.id.ok:
       Preferences.setDefaultPlan(this, false);
       this.finish();
       break;
     case R.id.import_default:
       intent = new Intent(Intent.ACTION_VIEW, Uri.parse(this.getString(R.string.url_rulesets)));
       try {
         this.startActivity(intent);
       } catch (ActivityNotFoundException e) {
         Log.e(TAG, "no activity to load url", e);
         Toast.makeText(
                 this, "no activity to load url: " + intent.getDataString(), Toast.LENGTH_LONG)
             .show();
       }
       break;
     default:
       break;
   }
 }
Exemplo n.º 3
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();
  }
Exemplo n.º 4
0
  /** {@inheritDoc} */
  @Override
  public void onCreate() {
    super.onCreate();
    Log.init("SMSdroid");
    Log.i(TAG, "init SMSdroid v" + this.getString(R.string.app_version));

    final SharedPreferences p = PreferenceManager.getDefaultSharedPreferences(this);
    int state = PackageManager.COMPONENT_ENABLED_STATE_DISABLED;
    if (p.getBoolean(PreferencesActivity.PREFS_ACTIVATE_SENDER, true)) {
      try {
        Cursor c =
            this.getContentResolver()
                .query(SenderActivity.URI_SENT, PROJECTION, null, null, "_id LIMIT 1");
        if (c == null) {
          Log.i(TAG, "disable .Sender: curor=null");
        } else if (SmsManager.getDefault() == null) {
          Log.i(TAG, "disable .Sender: SmsManager=null");
        } else {
          state = PackageManager.COMPONENT_ENABLED_STATE_ENABLED;
          Log.d(TAG, "enable .Sender");
        }
        if (c != null && !c.isClosed()) {
          c.close();
        }
      } catch (IllegalArgumentException e) {
        Log.e(TAG, "disable .Sender: " + e.getMessage(), e);
      } catch (SQLiteException e) {
        Log.e(TAG, "disable .Sender: " + e.getMessage(), e);
      }
    } else {
      Log.i(TAG, "disable .Sender");
    }
    this.getPackageManager()
        .setComponentEnabledSetting(
            new ComponentName(this, SenderActivity.class), state, PackageManager.DONT_KILL_APP);
  }
 /** {@inheritDoc} */
 @Override
 public boolean onOptionsItemSelected(final MenuItem item) {
   switch (item.getItemId()) {
     case R.id.item_compose:
       final Intent i = getComposeIntent(this, null);
       try {
         this.startActivity(i);
       } catch (ActivityNotFoundException e) {
         Log.e(TAG, "error launching intent: " + i.getAction() + ", " + i.getData());
         Toast.makeText(
                 this,
                 "error launching messaging app!\n" + "Please contact the developer.",
                 Toast.LENGTH_LONG)
             .show();
       }
       return true;
     case R.id.item_settings: // start settings activity
       if (Utils.isApi(Build.VERSION_CODES.HONEYCOMB)) {
         this.startActivity(
             new Intent(
                 this, // .
                 Preferences11Activity.class));
       } else {
         this.startActivity(new Intent(this, PreferencesActivity.class));
       }
       return true;
     case R.id.item_donate:
       DonationHelper.startDonationActivity(this, true);
       return true;
     case R.id.item_delete_all_threads:
       deleteMessages(
           this,
           Uri.parse("content://sms/"),
           R.string.delete_threads_,
           R.string.delete_threads_question,
           null);
       return true;
     case R.id.item_mark_all_read:
       markRead(this, Uri.parse("content://sms/"), 1);
       markRead(this, Uri.parse("content://mms/"), 1);
       return true;
     default:
       return super.onOptionsItemSelected(item);
   }
 }
 /** {@inheritDoc} */
 public void onItemClick(
     final AdapterView<?> parent, final View view, final int position, final long id) {
   final Conversation c =
       Conversation.getConversation(this, (Cursor) parent.getItemAtPosition(position), false);
   final Uri target = c.getUri();
   final Intent i = new Intent(this, MessageListActivity.class);
   i.setData(target);
   try {
     this.startActivity(i);
   } catch (ActivityNotFoundException e) {
     Log.e(TAG, "error launching intent: " + i.getAction() + ", " + i.getData());
     Toast.makeText(
             this,
             "error launching messaging app!\n" + "Please contact the developer.",
             Toast.LENGTH_LONG)
         .show();
   }
 }
Exemplo n.º 7
0
 /** Start ConversationList query. */
 public final void startMsgListQuery() {
   // Cancel any pending queries
   queryHandler.cancelOperation(MESSAGE_LIST_QUERY_TOKEN);
   try {
     // Kick off the new query
     activity.setProgressBarIndeterminateVisibility(Boolean.TRUE);
     queryHandler.startQuery(
         MESSAGE_LIST_QUERY_TOKEN,
         null,
         Conversation.URI_SIMPLE,
         Conversation.PROJECTION_SIMPLE,
         null,
         null,
         SORT);
   } catch (SQLiteException e) {
     Log.e(TAG, "error starting query", e);
   }
 }
 /**
  * Mark all messages with a given {@link Uri} as read.
  *
  * @param context {@link Context}
  * @param uri {@link Uri}
  * @param read read status
  */
 static void markRead(final Context context, final Uri uri, final int read) {
   Log.d(TAG, "markRead(" + uri + "," + read + ")");
   if (uri == null) {
     return;
   }
   String[] sel = Message.SELECTION_UNREAD;
   if (read == 0) {
     sel = Message.SELECTION_READ;
   }
   final ContentResolver cr = context.getContentResolver();
   final ContentValues cv = new ContentValues();
   cv.put(Message.PROJECTION[Message.INDEX_READ], read);
   try {
     cr.update(uri, cv, Message.SELECTION_READ_UNREAD, sel);
   } catch (IllegalArgumentException e) {
     Log.e(TAG, "failed update", e);
     Toast.makeText(context, e.getMessage(), Toast.LENGTH_LONG).show();
   }
   SmsReceiver.updateNewMessageNotification(context, null);
 }