private static String getTextMessageDetails(Context context, Cursor cursor) {
    Log.d(TAG, "getTextMessageDetails");

    StringBuilder details = new StringBuilder();
    Resources res = context.getResources();

    // Message Type: Text message.
    details.append(res.getString(R.string.message_type_label));
    details.append(res.getString(R.string.text_message));

    // Address: ***
    details.append('\n');
    int smsType = cursor.getInt(MessageListAdapter.COLUMN_SMS_TYPE);
    if (Sms.isOutgoingFolder(smsType)) {
      details.append(res.getString(R.string.to_address_label));
    } else {
      details.append(res.getString(R.string.from_label));
    }
    details.append(cursor.getString(MessageListAdapter.COLUMN_SMS_ADDRESS));

    // Sent: ***
    if (smsType == Sms.MESSAGE_TYPE_INBOX) {
      long date_sent = cursor.getLong(MessageListAdapter.COLUMN_SMS_DATE_SENT);
      if (date_sent > 0) {
        details.append('\n');
        details.append(res.getString(R.string.sent_label));
        details.append(MessageUtils.formatTimeStampString(context, date_sent, true));
      }
    }

    // Received: ***
    details.append('\n');
    if (smsType == Sms.MESSAGE_TYPE_DRAFT) {
      details.append(res.getString(R.string.saved_label));
    } else if (smsType == Sms.MESSAGE_TYPE_INBOX) {
      details.append(res.getString(R.string.received_label));
    } else {
      details.append(res.getString(R.string.sent_label));
    }

    long date = cursor.getLong(MessageListAdapter.COLUMN_SMS_DATE);
    details.append(MessageUtils.formatTimeStampString(context, date, true));

    // Error code: ***
    int errorCode = cursor.getInt(MessageListAdapter.COLUMN_SMS_ERROR_CODE);
    if (errorCode != 0) {
      details.append('\n').append(res.getString(R.string.error_code_label)).append(errorCode);
    }

    return details.toString();
  }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
    setContentView(R.layout.sim_list);

    Intent intent = getIntent();
    mManageMode = intent.getIntExtra(ComposeMessageActivity.MANAGE_MODE, MessageUtils.INVALID_MODE);
    if (mManageMode == MessageUtils.FORWARD_MODE || mManageMode == MessageUtils.BATCH_DELETE_MODE) {
      mThreadId = intent.getLongExtra(ComposeMessageActivity.THREAD_ID, INVALID_THREAD);
    } else if (mManageMode == MessageUtils.SIM_MESSAGE_MODE) {
      mSubscription = intent.getIntExtra(MessageUtils.SUB_KEY, SUB_INVALID);
      mIccUri = MessageUtils.getIccUriBySubscription(mSubscription);
    }

    mMsgListView = (ListView) findViewById(R.id.messages);
    mMessage = (TextView) findViewById(R.id.empty_message);

    mContentResolver = getContentResolver();
    mBackgroundQueryHandler = new BackgroundQueryHandler(mContentResolver);

    ActionBar actionBar = getActionBar();
    actionBar.setDisplayHomeAsUpEnabled(true);

    startMsgListQuery();
  }
 private static void viewMmsMessageAttachment(
     Context context, Uri msgUri, SlideshowModel slideshow, int requestCode) {
   boolean isSimple = (slideshow == null) ? false : slideshow.isSimple();
   if (isSimple) {
     // In attachment-editor mode, we only ever have one slide.
     MessageUtils.viewSimpleSlideshow(context, slideshow);
   } else {
     // If a slideshow was provided, save it to disk first.
     if (slideshow != null) {
       PduPersister persister = PduPersister.getPduPersister(context);
       try {
         PduBody pb = slideshow.toPduBody();
         persister.updateParts(msgUri, pb);
         slideshow.sync(pb);
       } catch (MmsException e) {
         Log.e(TAG, "Unable to save message for preview");
         return;
       }
     }
     // Launch the slideshow activity to play/view.
     Intent intent = new Intent(context, SlideshowActivity.class);
     intent.setData(msgUri);
     if (requestCode > 0 && context instanceof Activity) {
       ((Activity) context).startActivityForResult(intent, requestCode);
     } else {
       context.startActivity(intent);
     }
   }
 }
        public void onResizeResult(PduPart part, boolean append) {
          Context context = SlideEditorActivity.this;
          if (part == null) {
            Toast.makeText(
                    SlideEditorActivity.this,
                    getResourcesString(R.string.failed_to_add_media, getPictureString()),
                    Toast.LENGTH_SHORT)
                .show();
            return;
          }

          try {
            long messageId = ContentUris.parseId(mUri);
            PduPersister persister = PduPersister.getPduPersister(context);
            Uri newUri = persister.persistPart(part, messageId);
            mSlideshowEditor.changeImage(mPosition, newUri);

            setReplaceButtonText(R.string.replace_image);
          } catch (MmsException e) {
            notifyUser("add picture failed");
            Toast.makeText(
                    SlideEditorActivity.this,
                    getResourcesString(R.string.failed_to_add_media, getPictureString()),
                    Toast.LENGTH_SHORT)
                .show();
          } catch (UnsupportContentTypeException e) {
            MessageUtils.showErrorDialog(
                SlideEditorActivity.this,
                getResourcesString(R.string.unsupported_media_format, getPictureString()),
                getResourcesString(R.string.select_different_media, getPictureString()));
          } catch (ResolutionException e) {
            MessageUtils.showErrorDialog(
                SlideEditorActivity.this,
                getResourcesString(R.string.failed_to_resize_image),
                getResourcesString(R.string.resize_image_error_information));
          } catch (ExceedMessageSizeException e) {
            MessageUtils.showErrorDialog(
                SlideEditorActivity.this,
                getResourcesString(R.string.exceed_message_size_limitation),
                getResourcesString(R.string.failed_to_add_media, getPictureString()));
          }
        }
  private static String getNotificationIndDetails(Context context, Cursor cursor) {
    StringBuilder details = new StringBuilder();
    Resources res = context.getResources();

    long id = cursor.getLong(MessageListAdapter.COLUMN_ID);
    Uri uri = ContentUris.withAppendedId(Mms.CONTENT_URI, id);
    NotificationInd nInd;

    try {
      nInd = (NotificationInd) PduPersister.getPduPersister(context).load(uri);
    } catch (MmsException e) {
      Log.e(TAG, "Failed to load the message: " + uri, e);
      return context.getResources().getString(R.string.cannot_get_details);
    }

    // Message Type: Mms Notification.
    details.append(res.getString(R.string.message_type_label));
    details.append(res.getString(R.string.multimedia_notification));

    // From: ***
    String from = extractEncStr(context, nInd.getFrom());
    details.append('\n');
    details.append(res.getString(R.string.from_label));
    details.append(!TextUtils.isEmpty(from) ? from : res.getString(R.string.hidden_sender_address));

    // Date: ***
    details.append('\n');
    details.append(
        res.getString(
            R.string.expire_on,
            MessageUtils.formatTimeStampString(context, nInd.getExpiry() * 1000L, true)));

    // Subject: ***
    details.append('\n');
    details.append(res.getString(R.string.subject_label));

    EncodedStringValue subject = nInd.getSubject();
    if (subject != null) {
      details.append(subject.getString());
    }

    // Message class: Personal/Advertisement/Infomational/Auto
    details.append('\n');
    details.append(res.getString(R.string.message_class_label));
    details.append(new String(nInd.getMessageClass()));

    // Message size: *** KB
    details.append('\n');
    details.append(res.getString(R.string.message_size_label));
    details.append(String.valueOf((nInd.getMessageSize() + 1023) / 1024));
    details.append(context.getString(R.string.kilobyte));

    return details.toString();
  }
예제 #6
0
 public CBMessageItem(Context context, CBMessage message) {
   mMessage = message;
   mId = message.getMessageId();
   mPresenceResId = 0;
   mSubject = message.getBody();
   mFrom = message.getDisplayName();
   mDate =
       String.format(
           context.getString(R.string.received_on),
           MessageUtils.formatTimeStampString(context, message.getDate()));
   mChannelId = message.getChannelId();
   mSimId = message.getSimId();
 }
 public static void viewMmsMessageAttachment(
     Context context, WorkingMessage msg, int requestCode) {
   SlideshowModel slideshow = msg.getSlideshow();
   if (slideshow == null) {
     throw new IllegalStateException("msg.getSlideshow() == null");
   }
   if (slideshow.isSimple()) {
     MessageUtils.viewSimpleSlideshow(context, slideshow);
   } else {
     Uri uri = msg.saveAsMms(false);
     if (uri != null) {
       // Pass null for the slideshow paramater, otherwise viewMmsMessageAttachment
       // will persist the slideshow to disk again (we just did that above in saveAsMms)
       viewMmsMessageAttachment(context, uri, null, requestCode);
     }
   }
 }
예제 #8
0
 protected void onEditTextChanged(Editable s) {
   Dialog dlg = getDialog();
   if (dlg instanceof AlertDialog) {
     AlertDialog alertDlg = (AlertDialog) dlg;
     Button btn = alertDlg.getButton(AlertDialog.BUTTON_POSITIVE);
     if (s.length() == 0) {
       btn.setEnabled(false);
     } else {
       btn.setEnabled(true);
     }
   }
   if (s.length() > mMaxSize) {
     String title =
         SimListActivity.this.getResources().getString(R.string.exceed_text_length_limitation);
     String message =
         SimListActivity.this
             .getResources()
             .getString(R.string.exceed_text_length_limitation_info);
     MessageUtils.showErrorDialog(SimListActivity.this, title, message);
     getEditText().setText("");
   }
 }
  public String[] getNumbers(boolean scrubForMmsAddress) {
    List<String> numbers = new ArrayList<String>();
    String number;
    for (Contact c : this) {
      number = c.getNumber();

      if (scrubForMmsAddress) {
        // parse/scrub the address for valid MMS address. The returned number
        // could be null if it's not a valid MMS address. We don't want to send
        // a message to an invalid number, as the network may do its own stripping,
        // and end up sending the message to a different number!
        number = MessageUtils.parseMmsAddress(number);
      }

      // Don't add duplicate numbers. This can happen if a contact name has a comma.
      // Since we use a comma as a delimiter between contacts, the code will consider
      // the same recipient has been added twice. The recipients UI still works correctly.
      // It's easiest to just make sure we only send to the same recipient once.
      if (!TextUtils.isEmpty(number) && !numbers.contains(number)) {
        numbers.add(number);
      }
    }
    return numbers.toArray(new String[numbers.size()]);
  }
예제 #10
0
  private void initModelFromUri(Uri uri) throws MmsException {
    ContentResolver cr = mContext.getContentResolver();
    Cursor c = SqliteWrapper.query(mContext, cr, uri, null, null, null, null);

    if (c != null) {
      try {
        if (c.moveToFirst()) {
          String path;
          boolean isFromMms = isMmsUri(uri);

          // FIXME We suppose that there should be only two sources
          // of the audio, one is the media store, the other is
          // our MMS database.
          if (isFromMms) {
            path = c.getString(c.getColumnIndexOrThrow(Part._DATA));
            mContentType = c.getString(c.getColumnIndexOrThrow(Part.CONTENT_TYPE));
          } else {
            path = c.getString(c.getColumnIndexOrThrow(Audio.Media.DATA));
            mContentType = c.getString(c.getColumnIndexOrThrow(Audio.Media.MIME_TYPE));
            // Get more extras information which would be useful
            // to the user.
            String album = c.getString(c.getColumnIndexOrThrow("album"));
            if (!TextUtils.isEmpty(album)) {
              mExtras.put("album", album);
            }

            String artist = c.getString(c.getColumnIndexOrThrow("artist"));
            if (!TextUtils.isEmpty(artist)) {
              mExtras.put("artist", artist);
            }
          }
          if (FeatureOption.MTK_DRM_APP) {
            if (MessageUtils.checkUriContainsDrm(mContext, uri)) {
              path += ".dcf";
            }
          }

          mSrc = path.substring(path.lastIndexOf('/') + 1).replace(' ', '_');
          Log.i(TAG, "path: " + path);
          Log.i(TAG, "mSrc: " + mSrc);

          if (TextUtils.isEmpty(mContentType)) {
            throw new MmsException("Type of media is unknown.");
          }

          if (LOCAL_LOGV) {
            Log.v(
                TAG,
                "New AudioModel created:"
                    + " mSrc="
                    + mSrc
                    + " mContentType="
                    + mContentType
                    + " mUri="
                    + uri
                    + " mExtras="
                    + mExtras);
          }
        } else {
          throw new MmsException("Nothing found: " + uri);
        }
      } finally {
        c.close();
      }
    } else {
      throw new MmsException("Bad URI: " + uri);
    }

    initMediaDuration();
  }
  @Override
  protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (resultCode != RESULT_OK) {
      return;
    }

    switch (requestCode) {
      case REQUEST_CODE_EDIT_TEXT:
        // XXX where does this come from?  Action is probably not the
        // right place to have the text...
        mSlideshowEditor.changeText(mPosition, data.getAction());
        break;

      case REQUEST_CODE_TAKE_PICTURE:
        Uri pictureUri = null;
        boolean showError = false;
        try {
          pictureUri = TempFileProvider.renameScrapFile(".jpg", Integer.toString(mPosition), this);

          if (pictureUri == null) {
            showError = true;
          } else {
            mSlideshowEditor.changeImage(mPosition, pictureUri);
            setReplaceButtonText(R.string.replace_image);
          }
        } catch (MmsException e) {
          Log.e(TAG, "add image failed", e);
          showError = true;
        } catch (UnsupportContentTypeException e) {
          MessageUtils.showErrorDialog(
              SlideEditorActivity.this,
              getResourcesString(R.string.unsupported_media_format, getPictureString()),
              getResourcesString(R.string.select_different_media, getPictureString()));
        } catch (ResolutionException e) {
          MessageUtils.resizeImageAsync(
              this, pictureUri, new Handler(), mResizeImageCallback, false);
        } catch (ExceedMessageSizeException e) {
          MessageUtils.resizeImageAsync(
              this, pictureUri, new Handler(), mResizeImageCallback, false);
        }
        if (showError) {
          notifyUser("add picture failed");
          Toast.makeText(
                  SlideEditorActivity.this,
                  getResourcesString(R.string.failed_to_add_media, getPictureString()),
                  Toast.LENGTH_SHORT)
              .show();
        }
        break;

      case REQUEST_CODE_CHANGE_PICTURE:
        try {
          mSlideshowEditor.changeImage(mPosition, data.getData());
          setReplaceButtonText(R.string.replace_image);
        } catch (MmsException e) {
          Log.e(TAG, "add image failed", e);
          notifyUser("add picture failed");
          Toast.makeText(
                  SlideEditorActivity.this,
                  getResourcesString(R.string.failed_to_add_media, getPictureString()),
                  Toast.LENGTH_SHORT)
              .show();
        } catch (UnsupportContentTypeException e) {
          MessageUtils.showErrorDialog(
              SlideEditorActivity.this,
              getResourcesString(R.string.unsupported_media_format, getPictureString()),
              getResourcesString(R.string.select_different_media, getPictureString()));
        } catch (ResolutionException e) {
          MessageUtils.resizeImageAsync(
              this, data.getData(), new Handler(), mResizeImageCallback, false);
        } catch (ExceedMessageSizeException e) {
          MessageUtils.resizeImageAsync(
              this, data.getData(), new Handler(), mResizeImageCallback, false);
        }
        break;

      case REQUEST_CODE_CHANGE_MUSIC:
      case REQUEST_CODE_RECORD_SOUND:
        Uri uri;
        if (requestCode == REQUEST_CODE_CHANGE_MUSIC) {
          uri = (Uri) data.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI);
          if (Settings.System.DEFAULT_RINGTONE_URI.equals(uri)) {
            return;
          }
        } else {
          uri = data.getData();
        }

        try {
          mSlideshowEditor.changeAudio(mPosition, uri);
        } catch (MmsException e) {
          Log.e(TAG, "add audio failed", e);
          notifyUser("add music failed");
          Toast.makeText(
                  SlideEditorActivity.this,
                  getResourcesString(R.string.failed_to_add_media, getAudioString()),
                  Toast.LENGTH_SHORT)
              .show();
        } catch (UnsupportContentTypeException e) {
          MessageUtils.showErrorDialog(
              SlideEditorActivity.this,
              getResourcesString(R.string.unsupported_media_format, getAudioString()),
              getResourcesString(R.string.select_different_media, getAudioString()));
        } catch (ExceedMessageSizeException e) {
          MessageUtils.showErrorDialog(
              SlideEditorActivity.this,
              getResourcesString(R.string.exceed_message_size_limitation),
              getResourcesString(R.string.failed_to_add_media, getAudioString()));
        }
        break;

      case REQUEST_CODE_TAKE_VIDEO:
        try {
          Uri videoUri =
              TempFileProvider.renameScrapFile(".3gp", Integer.toString(mPosition), this);

          mSlideshowEditor.changeVideo(mPosition, videoUri);
        } catch (MmsException e) {
          notifyUser("add video failed");
          Toast.makeText(
                  SlideEditorActivity.this,
                  getResourcesString(R.string.failed_to_add_media, getVideoString()),
                  Toast.LENGTH_SHORT)
              .show();
        } catch (UnsupportContentTypeException e) {
          MessageUtils.showErrorDialog(
              SlideEditorActivity.this,
              getResourcesString(R.string.unsupported_media_format, getVideoString()),
              getResourcesString(R.string.select_different_media, getVideoString()));
        } catch (ExceedMessageSizeException e) {
          MessageUtils.showErrorDialog(
              SlideEditorActivity.this,
              getResourcesString(R.string.exceed_message_size_limitation),
              getResourcesString(R.string.failed_to_add_media, getVideoString()));
        }
        break;

      case REQUEST_CODE_CHANGE_VIDEO:
        try {
          mSlideshowEditor.changeVideo(mPosition, data.getData());
        } catch (MmsException e) {
          Log.e(TAG, "add video failed", e);
          notifyUser("add video failed");
          Toast.makeText(
                  SlideEditorActivity.this,
                  getResourcesString(R.string.failed_to_add_media, getVideoString()),
                  Toast.LENGTH_SHORT)
              .show();
        } catch (UnsupportContentTypeException e) {
          MessageUtils.showErrorDialog(
              SlideEditorActivity.this,
              getResourcesString(R.string.unsupported_media_format, getVideoString()),
              getResourcesString(R.string.select_different_media, getVideoString()));
        } catch (ExceedMessageSizeException e) {
          MessageUtils.showErrorDialog(
              SlideEditorActivity.this,
              getResourcesString(R.string.exceed_message_size_limitation),
              getResourcesString(R.string.failed_to_add_media, getVideoString()));
        }
        break;

      case REQUEST_CODE_CHANGE_DURATION:
        mSlideshowEditor.changeDuration(mPosition, Integer.valueOf(data.getAction()) * 1000);
        break;
    }
  }
  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
      case MENU_PREVIEW_SLIDESHOW:
        previewSlideshow();
        break;

      case MENU_REMOVE_TEXT:
        SlideModel slide = mSlideshowModel.get(mPosition);
        if (slide != null) {
          slide.removeText();
        }
        break;

      case MENU_ADD_PICTURE:
        Intent intent = new Intent(Intent.ACTION_GET_CONTENT, null);
        intent.setType(ContentType.IMAGE_UNSPECIFIED);
        startActivityForResult(intent, REQUEST_CODE_CHANGE_PICTURE);
        break;

      case MENU_TAKE_PICTURE:
        intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        // We have to pass a uri to store the picture data, otherwise the camera will return
        // a very small image bitmap.
        intent.putExtra(MediaStore.EXTRA_OUTPUT, TempFileProvider.SCRAP_CONTENT_URI);
        startActivityForResult(intent, REQUEST_CODE_TAKE_PICTURE);
        break;

      case MENU_DEL_PICTURE:
        mSlideshowEditor.removeImage(mPosition);
        setReplaceButtonText(R.string.add_picture);
        break;

      case MENU_ADD_AUDIO:
        MessageUtils.selectAudio(this, REQUEST_CODE_CHANGE_MUSIC);
        break;

      case MENU_RECORD_SOUND:
        slide = mSlideshowModel.get(mPosition);
        int currentSlideSize = slide.getSlideSize();
        long sizeLimit =
            ComposeMessageActivity.computeAttachmentSizeLimit(mSlideshowModel, currentSlideSize);
        MessageUtils.recordSound(this, REQUEST_CODE_RECORD_SOUND, sizeLimit);
        break;

      case MENU_DEL_AUDIO:
        mSlideshowEditor.removeAudio(mPosition);
        break;

      case MENU_ADD_VIDEO:
        intent = new Intent(Intent.ACTION_GET_CONTENT);
        intent.setType(ContentType.VIDEO_UNSPECIFIED);
        intent.putExtra(Intent.EXTRA_LOCAL_ONLY, true);
        startActivityForResult(intent, REQUEST_CODE_CHANGE_VIDEO);
        break;

      case MENU_TAKE_VIDEO:
        slide = mSlideshowModel.get(mPosition);
        currentSlideSize = slide.getSlideSize();
        sizeLimit =
            ComposeMessageActivity.computeAttachmentSizeLimit(mSlideshowModel, currentSlideSize);
        if (sizeLimit > 0) {
          MessageUtils.recordVideo(this, REQUEST_CODE_TAKE_VIDEO, sizeLimit);
        } else {
          Toast.makeText(this, getString(R.string.message_too_big_for_video), Toast.LENGTH_SHORT)
              .show();
        }
        break;

      case MENU_DEL_VIDEO:
        mSlideshowEditor.removeVideo(mPosition);
        break;

      case MENU_ADD_SLIDE:
        mPosition++;
        if (mSlideshowEditor.addNewSlide(mPosition)) {
          // add successfully
          showCurrentSlide();
        } else {
          // move position back
          mPosition--;
          Toast.makeText(this, R.string.cannot_add_slide_anymore, Toast.LENGTH_SHORT).show();
        }
        break;

      case MENU_LAYOUT:
        showLayoutSelectorDialog();
        break;

      case MENU_DURATION:
        showDurationDialog();
        break;
    }

    return true;
  }
 private void previewSlideshow() {
   MessageUtils.viewMmsMessageAttachment(SlideEditorActivity.this, mUri, mSlideshowModel);
 }
예제 #14
0
  private static String getMultimediaMessageDetails(Context context, Cursor cursor, int size) {
    int type = cursor.getInt(MessageListAdapter.COLUMN_MMS_MESSAGE_TYPE);
    if (type == PduHeaders.MESSAGE_TYPE_NOTIFICATION_IND) {
      return getNotificationIndDetails(context, cursor);
    }

    StringBuilder details = new StringBuilder();
    Resources res = context.getResources();

    long id = cursor.getLong(MessageListAdapter.COLUMN_ID);
    Uri uri = ContentUris.withAppendedId(Mms.CONTENT_URI, id);
    MultimediaMessagePdu msg;

    try {
      msg = (MultimediaMessagePdu) PduPersister.getPduPersister(context).load(uri);
    } catch (MmsException e) {
      Log.e(TAG, "Failed to load the message: " + uri, e);
      return context.getResources().getString(R.string.cannot_get_details);
    }

    // Message Type: Text message.
    details.append(res.getString(R.string.message_type_label));
    details.append(res.getString(R.string.multimedia_message));

    if (msg instanceof RetrieveConf) {
      // From: ***
      String from = extractEncStr(context, ((RetrieveConf) msg).getFrom());
      details.append('\n');
      details.append(res.getString(R.string.from_label));
      details.append(
          !TextUtils.isEmpty(from) ? from : res.getString(R.string.hidden_sender_address));
    }

    // To: ***
    details.append('\n');
    details.append(res.getString(R.string.to_address_label));
    EncodedStringValue[] to = msg.getTo();
    if (to != null) {
      details.append(EncodedStringValue.concat(to));
    } else {
      Log.w(TAG, "recipient list is empty!");
    }

    // Bcc: ***
    if (msg instanceof SendReq) {
      EncodedStringValue[] values = ((SendReq) msg).getBcc();
      if ((values != null) && (values.length > 0)) {
        details.append('\n');
        details.append(res.getString(R.string.bcc_label));
        details.append(EncodedStringValue.concat(values));
      }
    }

    // Date: ***
    details.append('\n');
    int msgBox = cursor.getInt(MessageListAdapter.COLUMN_MMS_MESSAGE_BOX);
    if (msgBox == Mms.MESSAGE_BOX_DRAFTS) {
      details.append(res.getString(R.string.saved_label));
    } else if (msgBox == Mms.MESSAGE_BOX_INBOX) {
      details.append(res.getString(R.string.received_label));
    } else {
      details.append(res.getString(R.string.sent_label));
    }

    details.append(MessageUtils.formatTimeStampString(context, msg.getDate() * 1000L, true));

    // Subject: ***
    details.append('\n');
    details.append(res.getString(R.string.subject_label));

    EncodedStringValue subject = msg.getSubject();
    if (subject != null) {
      String subStr = subject.getString();
      // Message size should include size of subject.
      size += subStr.length();
      details.append(subStr);
    }

    // Priority: High/Normal/Low
    details.append('\n');
    details.append(res.getString(R.string.priority_label));
    details.append(getPriorityDescription(context, msg.getPriority()));

    // Message size: *** KB
    details.append('\n');
    details.append(res.getString(R.string.message_size_label));
    details.append((size - 1) / 1000 + 1);
    details.append(" KB");

    return details.toString();
  }
  @Override
  public void onReceive(Context context, Intent intent) {
    if (Log.isLoggable(LogTag.TRANSACTION, Log.VERBOSE)) {
      Log.v(TAG, "Intent received: " + intent);
    }
    Xlog.d(MmsApp.LOG_TAG, "onReceive(): intent=" + intent.toString());
    String action = intent.getAction();
    if (action.equals(Mms.Intents.CONTENT_CHANGED_ACTION)) {
      final Intent mIntent = intent;
      new Thread(
              new Runnable() {
                @Override
                public void run() {
                  Uri changed = (Uri) mIntent.getParcelableExtra(Mms.Intents.DELETED_CONTENTS);
                  PduCache.getInstance().purge(changed);
                  Xlog.d(MmsApp.TXN_TAG, "Mms.Intents.CONTENT_CHANGED_ACTION: " + changed);
                }
              })
          .start();
    } else if (action.equals(TelephonyIntents.ACTION_ANY_DATA_CONNECTION_STATE_CHANGED)) {
      String state = intent.getStringExtra(Phone.STATE_KEY);

      if (Log.isLoggable(LogTag.TRANSACTION, Log.VERBOSE)) {
        Log.v(TAG, "ANY_DATA_STATE event received: " + state);
      }

      String apnType = intent.getStringExtra(Phone.DATA_APN_TYPE_KEY);

      // if (state.equals("CONNECTED")) {
      if (Phone.APN_TYPE_MMS.equals(apnType)) {
        Xlog.d(
            MmsApp.TXN_TAG,
            "TelephonyIntents.ACTION_ANY_DATA_CONNECTION_STATE_CHANGED, type is mms.");
        // if the network is not available for mms, keep listening
        ConnectivityManager ConnMgr =
            (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo ni = ConnMgr.getNetworkInfo(ConnectivityManager.TYPE_MOBILE_MMS);
        if (ni != null && !ni.isAvailable()) {
          Xlog.d(MmsApp.TXN_TAG, "network is not available for mms, keep listening.");
          return;
        }

        unRegisterForConnectionStateChanges(context);
        // add for gemini
        if (FeatureOption.MTK_GEMINI_SUPPORT == true) {
          // conver slot id to sim id
          SIMInfo si =
              SIMInfo.getSIMInfoBySlot(
                  context, intent.getIntExtra(Phone.GEMINI_SIM_ID_KEY, Phone.GEMINI_SIM_1));
          if (null == si) {
            Xlog.e(
                MmsApp.TXN_TAG,
                "System event receiver: SIMInfo is null for slot "
                    + intent.getIntExtra(Phone.GEMINI_SIM_ID_KEY, -1));
            return;
          }
          int simId = (int) si.mSimId;
          wakeUpServiceGemini(
              context, simId /*intent.getIntExtra(Phone.GEMINI_SIM_ID_KEY,Phone.GEMINI_SIM_1)*/);
        } else {
          wakeUpService(context);
        }
      }
    } else if (action.equals(Intent.ACTION_BOOT_COMPLETED)) {
      Xlog.d(MmsApp.TXN_TAG, "Intent.ACTION_BOOT_COMPLETED");
      final Context contxt = context;
      new Thread(
              new Runnable() {
                public void run() {
                  setPendingMmsFailed(contxt);
                  setPendingSmsFailed(contxt);
                  setNotificationIndUnstarted(contxt);
                }
              })
          .start();
      // We should check whether there are unread incoming
      // messages in the Inbox and then update the notification icon.
      // Called on the UI thread so don't block.
      MessagingNotification.nonBlockingUpdateNewMessageIndicator(context, false, false);
    } else if (action.equals(Intent.SIM_SETTINGS_INFO_CHANGED)) {
      int simId = (int) intent.getLongExtra("simid", -1);
      MessageUtils.simInfoMap.remove(simId);
      MessageUtils.getSimInfo(context, simId);
    } else if (action.equals(Intent.ACTION_SHUTDOWN)) {
      saveDraft = (OnShutDownListener) ComposeMessageActivity.getComposeContext();
      if (saveDraft != null) {
        saveDraft.onShutDown();
      }
    } else if (action.equals(Intent.ACTION_SMS_DEFAULT_SIM_CHANGED)) {
      Xlog.d(MmsApp.LOG_TAG, "SMS default SIM changed.");
      mSimInforChangedListener =
          (OnSimInforChangedListener) ComposeMessageActivity.getComposeContext();
      if (mSimInforChangedListener != null) {
        mSimInforChangedListener.OnSimInforChanged();
      }
      mSimInforChangedListener = (OnSimInforChangedListener) ConversationList.getContext();
      if (mSimInforChangedListener != null) {
        mSimInforChangedListener.OnSimInforChanged();
      }
    } else if (action.equals(Intent.ACTION_DEVICE_STORAGE_FULL)) {
      MmsConfig.setDeviceStorageFullStatus(true);
    } else if (action.equals(Intent.ACTION_DEVICE_STORAGE_NOT_FULL)) {
      MmsConfig.setDeviceStorageFullStatus(false);
      MessagingNotification.cancelNotification(
          context, SmsRejectedReceiver.SMS_REJECTED_NOTIFICATION_ID);
    }
  }
예제 #16
0
  @Override
  public void onReceive(Context context, Intent intent) {
    if (Log.isLoggable(LogTag.TRANSACTION, Log.VERBOSE)) {
      Log.v(TAG, "Intent received: " + intent);
    }
    /// M:
    MmsLog.d(MmsApp.LOG_TAG, "onReceive(): intent=" + intent.toString());
    String action = intent.getAction();
    if (action.equals(Mms.Intents.CONTENT_CHANGED_ACTION)) {
      /// M:Code analyze 003, put in a new thread @{
      final Intent mIntent = intent;
      new Thread(
              new Runnable() {
                @Override
                public void run() {
                  Uri changed = (Uri) mIntent.getParcelableExtra(Mms.Intents.DELETED_CONTENTS);
                  if (changed != null) {
                    MmsApp.getApplication().getPduLoaderManager().removePdu(changed);
                  }
                  MmsLog.d(MmsApp.TXN_TAG, "Mms.Intents.CONTENT_CHANGED_ACTION: " + changed);
                }
              })
          .start();
      /// @}
    } else if (action.equals(TelephonyIntents.ACTION_ANY_DATA_CONNECTION_STATE_CHANGED)) {
      String state = intent.getStringExtra(EncapsulatedPhone.STATE_KEY);

      if (Log.isLoggable(LogTag.TRANSACTION, Log.VERBOSE)) {
        Log.v(TAG, "ANY_DATA_STATE event received: " + state);
      }
      /// M:Code analyze 004, modify the logic,if data connection change,unRegister the listener of
      /// connection changed and wake up transaction service,and add gemini logic @{
      String apnType = intent.getStringExtra(EncapsulatedPhone.DATA_APN_TYPE_KEY);

      // if (state.equals("CONNECTED")) {
      if (EncapsulatedPhone.APN_TYPE_MMS.equals(apnType)) {
        MmsLog.d(
            MmsApp.TXN_TAG,
            "TelephonyIntents.ACTION_ANY_DATA_CONNECTION_STATE_CHANGED, type is mms.");
        // if the network is not available for mms, keep listening
        ConnectivityManager connMgr =
            (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo ni = connMgr.getNetworkInfo(ConnectivityManager.TYPE_MOBILE_MMS);
        if (ni != null && !ni.isAvailable()) {
          MmsLog.d(MmsApp.TXN_TAG, "network is not available for mms, keep listening.");
          return;
        }

        unRegisterForConnectionStateChanges(context);
        // add for gemini
        if (EncapsulatedFeatureOption.MTK_GEMINI_SUPPORT) {
          // conver slot id to sim id
          SIMInfo si =
              SIMInfo.getSIMInfoBySlot(
                  context,
                  intent.getIntExtra(
                      EncapsulatedPhone.GEMINI_SIM_ID_KEY, EncapsulatedPhone.GEMINI_SIM_1));
          if (null == si) {
            MmsLog.e(
                MmsApp.TXN_TAG,
                "System event receiver: SIMInfo is null for slot "
                    + intent.getIntExtra(EncapsulatedPhone.GEMINI_SIM_ID_KEY, -1));
            return;
          }
          int simId = (int) si.getSimId();
          wakeUpServiceGemini(
              context, simId /*intent.getIntExtra(Phone.GEMINI_SIM_ID_KEY,Phone.GEMINI_SIM_1)*/);
        } else {
          wakeUpService(context);
        }
      }
      /// @}
    } else if (action.equals(Intent.ACTION_BOOT_COMPLETED)) {
      /// M:Code analyze 005, mark pending msg failed after boot complete @{
      MmsLog.d(MmsApp.TXN_TAG, "Intent.ACTION_BOOT_COMPLETED");
      final Context contxt = context;
      new Thread(
              new Runnable() {
                public void run() {
                  IpMessageUtils.getIpMessagePlugin(contxt)
                      .getServiceManager(contxt.getApplicationContext())
                      .startIpService();
                  setPendingMmsFailed(contxt);
                  setNotificationIndUnstarted(contxt);
                }
              })
          .start();
      /// @}
      // We should check whether there are unread incoming
      // messages in the Inbox and then update the notification icon.
      // Called on the UI thread so don't block.
      MessagingNotification.nonBlockingUpdateNewMessageIndicator(
          context, MessagingNotification.THREAD_NONE, false);
      /// M: when power off,save the chat setting. {@
      SharedPreferences sp =
          PreferenceManager.getDefaultSharedPreferences(contxt.getApplicationContext());
      final long unSavedthreadId = sp.getLong(ChatPreferenceActivity.CHAT_THREAD_ID, -1l);
      Log.v(TAG, "unSaved chatThreadSetting: " + unSavedthreadId);
      if (unSavedthreadId > 0) {
        final boolean mNotificationEnable =
            sp.getBoolean(ChatPreferenceActivity.ENABLE_NOTIFICATION, false);
        final String mMute = sp.getString(ChatPreferenceActivity.CHAT_MUTE, "0");
        final String mRingtone =
            sp.getString(
                ChatPreferenceActivity.CHAT_RINGTONE, ChatPreferenceActivity.DEFAULT_RINGTONE);
        final boolean mVibrate = sp.getBoolean(ChatPreferenceActivity.CHAT_VIBRATE, false);
        final long mMuteStart = sp.getLong(ChatPreferenceActivity.CHAT_MUTE_START, 0);
        new Thread() {
          public void run() {
            SharedPreferences spChatThreadId =
                PreferenceManager.getDefaultSharedPreferences(contxt.getApplicationContext());
            Uri uri =
                ContentUris.withAppendedId(
                    Uri.parse(ChatPreferenceActivity.CHAT_SETTINGS_URI), unSavedthreadId);
            ContentValues values = new ContentValues();
            values.put(ThreadSettings.NOTIFICATION_ENABLE, mNotificationEnable ? 1 : 0);
            values.put(ThreadSettings.MUTE, Integer.parseInt(mMute));
            values.put(ThreadSettings.MUTE_START, mMuteStart);
            values.put(ThreadSettings.RINGTONE, mRingtone);
            values.put(ThreadSettings.VIBRATE, mVibrate ? 1 : 0);
            contxt.getContentResolver().update(uri, values, null, null);
            SharedPreferences.Editor editor = spChatThreadId.edit();
            editor.putLong(ChatPreferenceActivity.CHAT_THREAD_ID, -1l);
            editor.commit();
            if (MmsConfig.getFolderModeEnabled()) {
              MuteCache.setMuteCache(
                  unSavedthreadId, Long.parseLong(mMute), mMuteStart, mNotificationEnable);
            }
          }
        }.start();
      }
      /// M: @}
      /// M:Code analyze 006,add for listening sim setting info changed @{
    } else if (action.equals(EncapsulatedAction.SIM_SETTINGS_INFO_CHANGED)) {
      int simId = (int) intent.getLongExtra("simid", -1);
      MessageUtils.simInfoMap.remove(simId);
      MessageUtils.getSimInfo(context, simId);
      /// @}
      /// M:Code analyze 001,add for save draft mms when received event of shutdown @{
    } else if (action.equals(Intent.ACTION_SHUTDOWN)) {
      mSaveDraft = (OnShutDownListener) ComposeMessageActivity.getComposeContext();
      if (mSaveDraft != null) {
        mSaveDraft.onShutDown();
      }
      /// @}
      /// M:Code analyze 002,add for listening the changing of sim info @{
    } else if (action.equals(EncapsulatedAction.ACTION_SMS_DEFAULT_SIM_CHANGED)) {
      MmsLog.d(MmsApp.LOG_TAG, "SMS default SIM changed.");
      mSimInforChangedListener =
          (OnSimInforChangedListener) ComposeMessageActivity.getComposeContext();
      if (mSimInforChangedListener != null) {
        mSimInforChangedListener.onSimInforChanged();
      }
      mSimInforChangedListener = (OnSimInforChangedListener) ConversationList.getContext();
      if (mSimInforChangedListener != null) {
        mSimInforChangedListener.onSimInforChanged();
      }
      /// @}
      /// M:Code analyze 007,add for listening device storage full or not @{
    } else if (action.equals(Intent.ACTION_DEVICE_STORAGE_FULL)) {
      MmsConfig.setDeviceStorageFullStatus(true);
    } else if (action.equals(Intent.ACTION_DEVICE_STORAGE_NOT_FULL)) {
      MmsConfig.setDeviceStorageFullStatus(false);
      MessagingNotification.cancelNotification(
          context, SmsRejectedReceiver.SMS_REJECTED_NOTIFICATION_ID);
      /// @}
      /// M: new feature, add default quick_text @{
    } else if (action.equals(Intent.ACTION_LOCALE_CHANGED)) {
      if (MmsConfig.getInitQuickText()) {
        return;
      }
      final Context runContext = context;
      new Thread(
              new Runnable() {
                public void run() {
                  Cursor cursor =
                      runContext
                          .getContentResolver()
                          .query(
                              EncapsulatedTelephony.MmsSms.CONTENT_URI_QUICKTEXT,
                              null,
                              null,
                              null,
                              null);
                  // get delete and add ID in DB, id quick Text array
                  ArrayList<Integer> delAddID = new ArrayList<Integer>();
                  ArrayList<Integer> quickTextID = new ArrayList<Integer>();
                  if (cursor != null) {
                    try {
                      ArrayList<String> preQuickText = MmsConfig.getPreQuickText();
                      while (cursor.moveToNext()) {
                        int id = cursor.getInt(0);
                        String str = cursor.getString(1);
                        for (int i = 0; i < preQuickText.size(); i++) {
                          if (str.equals(preQuickText.get(i))) {
                            delAddID.add(new Integer(id));
                            quickTextID.add(new Integer(i));
                            break;
                          }
                        }
                      }
                    } finally {
                      cursor.close();
                    }
                  }
                  // delete old language default quick text
                  for (Integer i : delAddID) {
                    runContext
                        .getContentResolver()
                        .delete(
                            EncapsulatedTelephony.MmsSms.CONTENT_URI_QUICKTEXT,
                            _ID + "=" + i,
                            null);
                  }

                  // add new language default quick text
                  String[] default_quick_texts =
                      runContext.getResources().getStringArray(R.array.default_quick_texts);
                  for (int i = 0, j = 0; i < delAddID.size() && j < quickTextID.size(); i++, j++) {
                    ContentValues values = new ContentValues();
                    values.put(_ID, delAddID.get(i));
                    values.put("text", default_quick_texts[quickTextID.get(j)]);
                    runContext
                        .getContentResolver()
                        .insert(EncapsulatedTelephony.MmsSms.CONTENT_URI_QUICKTEXT, values);
                  }
                  MmsConfig.setPreQuickText(default_quick_texts);
                }
              })
          .start();
    }
    /// @}
  }