本文整理汇总了Java中android.telephony.SmsMessage.calculateLength方法的典型用法代码示例。如果您正苦于以下问题:Java SmsMessage.calculateLength方法的具体用法?Java SmsMessage.calculateLength怎么用?Java SmsMessage.calculateLength使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.telephony.SmsMessage
的用法示例。
在下文中一共展示了SmsMessage.calculateLength方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: calculateCharacters
import android.telephony.SmsMessage; //导入方法依赖的package包/类
@Override
public CharacterState calculateCharacters(String messageBody) {
int[] length = SmsMessage.calculateLength(messageBody, false);
int messagesSpent = length[0];
int charactersSpent = length[1];
int charactersRemaining = length[2];
int maxMessageSize;
if (messagesSpent > 0) {
maxMessageSize = (charactersSpent + charactersRemaining) / messagesSpent;
} else {
maxMessageSize = (charactersSpent + charactersRemaining);
}
return new CharacterState(messagesSpent, charactersRemaining, maxMessageSize);
}
示例2: addressContainsEmailToMms
import android.telephony.SmsMessage; //导入方法依赖的package包/类
private boolean addressContainsEmailToMms(Conversation conv, String text) {
if (MmsConfig.getEmailGateway() != null) {
String[] dests = conv.getRecipients().getNumbers();
int length = dests.length;
for (int i = 0; i < length; i++) {
if (Mms.isEmailAddress(dests[i])
|| MessageUtils.isAlias(dests[i])) {
String mtext = dests[i] + " " + text;
int[] params = SmsMessage.calculateLength(mtext, false);
if (params[0] > 1) {
updateState(RECIPIENTS_REQUIRE_MMS, true, true);
ensureSlideshow();
syncTextToSlideshow();
return true;
}
}
}
}
return false;
}
示例3: addressContainsEmailToMms
import android.telephony.SmsMessage; //导入方法依赖的package包/类
private boolean addressContainsEmailToMms(Conversation conv, String text) {
if (MmsConfig.getEmailGateway() != null) {
String[] dests = conv.getRecipients().getNumbers();
int length = dests.length;
for (int i = 0; i < length; i++) {
if (Mms.isEmailAddress(dests[i]) || MessageUtils.isAlias(dests[i])) {
String mtext = dests[i] + " " + text;
int[] params = SmsMessage.calculateLength(mtext, false);
if (params[0] > 1) {
updateState(RECIPIENTS_REQUIRE_MMS, true, true);
ensureSlideshow();
syncTextToSlideshow();
return true;
}
}
}
}
return false;
}
示例4: retriveSentSmsFromDefaultApp
import android.telephony.SmsMessage; //导入方法依赖的package包/类
private void retriveSentSmsFromDefaultApp(){
Uri uriSMSURI = Uri.parse("content://sms");
// String[] FROM = { "_id", "type", "date", "thread_id", "address","length(body) as sms_lenth"};
Cursor cur = getContentResolver().query(uriSMSURI, null, null , null, null);
int id = cur.getColumnIndex("_id");
int type = cur.getColumnIndex( "type" );
int date = cur.getColumnIndex( "date");
int threadID = cur.getColumnIndex( "thread_id");
int address = cur.getColumnIndex("address");
int body = cur.getColumnIndex("body");
if(cur!=null && cur.moveToFirst()){
do {
int[] ar = SmsMessage.calculateLength(cur.getString(body),true);
textView1.append("id: "+cur.getInt(id)+ " \t address: "+cur.getString(address)+"\t msg length: "+ar[0] +"\nthread_id: "+cur.getString(threadID)+" \t type: "+cur.getString(type)+"\ndate: "+getStringFromMillis(Constants.SMS_DATE_FORMAT,cur.getLong(date)));
textView1.append("\n====================\n");
}while ( cur.moveToNext());
}
}
示例5: afterTextChanged
import android.telephony.SmsMessage; //导入方法依赖的package包/类
/**
* {@inheritDoc}
*/
public void afterTextChanged(final Editable s) {
final int len = s.length();
if (len == 0) {
if (cbmgr.hasText()
&& !PreferenceManager.getDefaultSharedPreferences(context).getBoolean(
PreferencesActivity.PREFS_HIDE_PASTE, false)) {
tvPaste.setVisibility(View.VISIBLE);
} else {
tvPaste.setVisibility(View.GONE);
}
tvTextLabel.setVisibility(View.GONE);
} else {
tvPaste.setVisibility(View.GONE);
if (len > TEXT_LABLE_MIN_LEN) {
try {
int[] l = SmsMessage.calculateLength(s.toString(), false);
tvTextLabel.setText(l[0] + "/" + l[2]);
tvTextLabel.setVisibility(View.VISIBLE);
} catch (Exception e) {
Log.e(TAG, "error calculating message length", e);
}
} else {
tvTextLabel.setVisibility(View.GONE);
}
}
}
示例6: stripAccents
import android.telephony.SmsMessage; //导入方法依赖的package包/类
public static String stripAccents(String s) {
int[] messageData = SmsMessage.calculateLength(s, false);
if (messageData[0] != 1) {
for (int i = 0; i < characters.length(); i++) {
s = s.replaceAll(characters.substring(i, i + 1), gsm.substring(i, i + 1));
}
}
return s;
}
示例7: getNumPages
import android.telephony.SmsMessage; //导入方法依赖的package包/类
/**
* Gets the number of pages in the SMS based on settings and the length of string
*
* @param settings is the settings object to check against
* @param text is the text from the message object to be sent
* @return the number of pages required to hold message
*/
public static int getNumPages(Settings settings, String text) {
if (settings.getStripUnicode()) {
text = StripAccents.stripAccents(text);
}
int[] data = SmsMessage.calculateLength(text, false);
return data[0];
}
示例8: calculateCharacters
import android.telephony.SmsMessage; //导入方法依赖的package包/类
@Override
public CharacterState calculateCharacters(String messageBody) {
int[] length = SmsMessage.calculateLength(messageBody, false);
int messagesSpent = (length[0] > 0) ? length[0] : 1;
int charactersSpent = length[1];
int charactersRemaining = length[2];
int maxMessageSize = (charactersSpent + charactersRemaining) / messagesSpent;
return new CharacterState(messagesSpent, charactersRemaining, maxMessageSize);
}
示例9: getQuickReplyCounterText
import android.telephony.SmsMessage; //导入方法依赖的package包/类
public static void getQuickReplyCounterText(CharSequence s, TextView mTextView,
Button mSendButton) {
if (mSendButton != null) {
if (s.length() > 0) {
mSendButton.setEnabled(true);
} else {
mSendButton.setEnabled(false);
}
}
if (s.length() < (80 - CHARS_REMAINING_BEFORE_COUNTER_SHOWN)) {
mTextView.setVisibility(View.GONE);
return;
}
/*
* SmsMessage.calculateLength returns an int[4] with: int[0] being the number of SMS's
* required, int[1] the number of code units used, int[2] is the number of code units
* remaining until the next message. int[3] is the encoding type that should be used for the
* message.
*/
int[] params = SmsMessage.calculateLength(s, false);
int msgCount = params[0];
int remainingInCurrentMessage = params[2];
if (msgCount > 1 || remainingInCurrentMessage <= CHARS_REMAINING_BEFORE_COUNTER_SHOWN) {
mTextView.setText(remainingInCurrentMessage + " / " + msgCount);
mTextView.setVisibility(View.VISIBLE);
} else {
mTextView.setVisibility(View.GONE);
}
}
示例10: updateCounter
import android.telephony.SmsMessage; //导入方法依赖的package包/类
private void updateCounter(CharSequence text, int start, int before,
int count) {
WorkingMessage workingMessage = mWorkingMessage;
if (workingMessage.requiresMms()) {
// If we're not removing text (i.e. no chance of converting back to
// SMS
// because of this change) and we're in MMS mode, just bail out
// since we
// then won't have to calculate the length unnecessarily.
final boolean textRemoved = (before > count);
if (!textRemoved) {
showSmsOrMmsSendButton(workingMessage.requiresMms());
// showSmsOrMmsSendButton(workingMessage.requiresMms());
Log.v("showSmsorMmsSendButton",
"workingMessage.requiresMms(): "
+ workingMessage.requiresMms());
return;
}
}
int[] params = SmsMessage.calculateLength(text, false);
/*
* SmsMessage.calculateLength returns an int[4] with: int[0] being the
* number of SMS's required, int[1] the number of code units used,
* int[2] is the number of code units remaining until the next message.
* int[3] is the encoding type that should be used for the message.
*/
int msgCount = params[0];
int remainingInCurrentMessage = params[2];
if (!MmsConfig.getMultipartSmsEnabled()) {
// The provider doesn't support multi-part sms's so as soon as the
// user types
// an sms longer than one segment, we have to turn the message into
// an mms.
mWorkingMessage.setLengthRequiresMms(msgCount > 1, true);
} else {
int threshold = MmsConfig.getSmsToMmsTextThreshold();
mWorkingMessage.setLengthRequiresMms(threshold > 0
&& msgCount > threshold, true);
}
// Show the counter only if:
// - We are not in MMS mode
// - We are going to send more than one message OR we are getting close
boolean showCounter = false;
if (!workingMessage.requiresMms()
&& (msgCount > 1 || remainingInCurrentMessage <= CHARS_REMAINING_BEFORE_COUNTER_SHOWN)) {
showCounter = true;
}
// ˫������-�ؼ���ʾ��λ
showSmsOrMmsSendButton(workingMessage.requiresMms());
// showSmsOrMmsSendButton(true);
Log.v("showSmsorMmsSendButton", "workingMessage.requiresMms(): "
+ workingMessage.requiresMms());
if (showCounter) {
// Update the remaining characters and number of messages required.
String counterText = msgCount > 1 ? remainingInCurrentMessage
+ " / " + msgCount : String
.valueOf(remainingInCurrentMessage);
mTextCounter.setText(counterText);
mTextCounter.setVisibility(View.VISIBLE);
} else {
mTextCounter.setVisibility(View.GONE);
}
}
示例11: setAttachment
import android.telephony.SmsMessage; //导入方法依赖的package包/类
/**
* Adds an attachment to the message, replacing an old one if it existed.
* @param type Type of this attachment, such as {@link IMAGE}
* @param dataUri Uri containing the attachment data (or null for {@link TEXT})
* @param append true if we should add the attachment to a new slide
* @return An error code such as {@link UNKNOWN_ERROR} or {@link OK} if successful
*/
public int setAttachment(int type, Uri dataUri, boolean append) {
if (Log.isLoggable(LogTag.APP, Log.VERBOSE)) {
LogTag.debug("setAttachment type=%d uri %s", type, dataUri);
}
int result = OK;
SlideshowEditor slideShowEditor = new SlideshowEditor(mActivity, mSlideshow);
// Special case for deleting a slideshow. When ComposeMessageActivity gets told to
// remove an attachment (search for AttachmentEditor.MSG_REMOVE_ATTACHMENT), it calls
// this function setAttachment with a type of TEXT and a null uri. Basically, it's turning
// the working message from an MMS back to a simple SMS. The various attachment types
// use slide[0] as a special case. The call to ensureSlideshow below makes sure there's
// a slide zero. In the case of an already attached slideshow, ensureSlideshow will do
// nothing and the slideshow will remain such that if a user adds a slideshow again, they'll
// see their old slideshow they previously deleted. Here we really delete the slideshow.
if (type == TEXT && mAttachmentType == SLIDESHOW && mSlideshow != null && dataUri == null
&& !append) {
slideShowEditor.removeAllSlides();
}
// Make sure mSlideshow is set up and has a slide.
ensureSlideshow(); // mSlideshow can be null before this call, won't be afterwards
slideShowEditor.setSlideshow(mSlideshow);
// Change the attachment
result = append ? appendMedia(type, dataUri, slideShowEditor)
: changeMedia(type, dataUri, slideShowEditor);
// If we were successful, update mAttachmentType and notify
// the listener than there was a change.
if (result == OK) {
mAttachmentType = type;
}
correctAttachmentState(true); // this can remove the slideshow if there are no attachments
if (mSlideshow != null && type == IMAGE) {
// Prime the image's cache; helps A LOT when the image is coming from the network
// (e.g. Picasa album). See b/5445690.
int numSlides = mSlideshow.size();
if (numSlides > 0) {
ImageModel imgModel = mSlideshow.get(numSlides - 1).getImage();
if (imgModel != null) {
cancelThumbnailLoading();
imgModel.loadThumbnailBitmap(null);
}
}
}
mStatusListener.onAttachmentChanged(); // have to call whether succeeded or failed,
// because a replace that fails, removes the slide
if (!append && mAttachmentType == TEXT && type == TEXT) {
int[] params = SmsMessage.calculateLength(getText(), false);
/* SmsMessage.calculateLength returns an int[4] with:
* int[0] being the number of SMS's required,
* int[1] the number of code units used,
* int[2] is the number of code units remaining until the next message.
* int[3] is the encoding type that should be used for the message.
*/
int smsSegmentCount = params[0];
if (!MmsConfig.getMultipartSmsEnabled()) {
// The provider doesn't support multi-part sms's so as soon as the user types
// an sms longer than one segment, we have to turn the message into an mms.
setLengthRequiresMms(smsSegmentCount > 1, false);
} else {
int threshold = MmsConfig.getSmsToMmsTextThreshold();
setLengthRequiresMms(threshold > 0 && smsSegmentCount > threshold, false);
}
}
return result;
}
示例12: updateCounter
import android.telephony.SmsMessage; //导入方法依赖的package包/类
private void updateCounter(CharSequence text, int start, int before, int count) {
WorkingMessage workingMessage = mWorkingMessage;
if (workingMessage.requiresMms()) {
// If we're not removing text (i.e. no chance of converting back to SMS
// because of this change) and we're in MMS mode, just bail out since we
// then won't have to calculate the length unnecessarily.
final boolean textRemoved = (before > count);
if (!textRemoved) {
showSmsOrMmsSendButton(workingMessage.requiresMms());
return;
}
}
int[] params = SmsMessage.calculateLength(text, false);
/* SmsMessage.calculateLength returns an int[4] with:
* int[0] being the number of SMS's required,
* int[1] the number of code units used,
* int[2] is the number of code units remaining until the next message.
* int[3] is the encoding type that should be used for the message.
*/
int msgCount = params[0];
int remainingInCurrentMessage = params[2];
if (!MmsConfig.getMultipartSmsEnabled()) {
// The provider doesn't support multi-part sms's so as soon as the user types
// an sms longer than one segment, we have to turn the message into an mms.
mWorkingMessage.setLengthRequiresMms(msgCount > 1, true);
} else {
int threshold = MmsConfig.getSmsToMmsTextThreshold();
mWorkingMessage.setLengthRequiresMms(threshold > 0 && msgCount > threshold, true);
}
// Show the counter only if:
// - We are not in MMS mode
// - We are going to send more than one message OR we are getting close
boolean showCounter = false;
if (!workingMessage.requiresMms() &&
(msgCount > 1 ||
remainingInCurrentMessage <= CHARS_REMAINING_BEFORE_COUNTER_SHOWN)) {
showCounter = true;
}
showSmsOrMmsSendButton(workingMessage.requiresMms());
if (showCounter) {
// Update the remaining characters and number of messages required.
String counterText = msgCount > 1 ? remainingInCurrentMessage + " / " + msgCount
: String.valueOf(remainingInCurrentMessage);
mTextCounter.setText(counterText);
mTextCounter.setVisibility(View.VISIBLE);
} else {
mTextCounter.setVisibility(View.GONE);
}
}
示例13: getSmsListDetailsFromDeviceApp
import android.telephony.SmsMessage; //导入方法依赖的package包/类
private synchronized ArrayList<SMSMessage> getSmsListDetailsFromDeviceApp() {
ArrayList<SMSMessage> smsList = new ArrayList<SMSMessage>();
Cursor managedCursor = null;
try{
long lastSMSDate = Util.getLongFromSP(mActivity, Constants.SP_LAST_SMS_DATE);
Uri uriSMSURI = Uri.parse("content://sms");
//fetch the messages which are sent and received
managedCursor = mActivity.getContentResolver().query(uriSMSURI, null, " date > "+lastSMSDate +" AND ( type = 1 OR type = 2 )", null, null);
mActivity.stopManagingCursor(managedCursor);
int id = managedCursor.getColumnIndex("_id");
int type = managedCursor.getColumnIndex( "type" );
int date = managedCursor.getColumnIndex( "date");
int threadID = managedCursor.getColumnIndex( "thread_id");
int address = managedCursor.getColumnIndex("address");
int body = managedCursor.getColumnIndex("body");
if(managedCursor!=null && managedCursor.moveToFirst()){
do {
SMSMessage smsMessage = new SMSMessage();
smsMessage.setId(managedCursor.getLong(id));
smsMessage.setNumber(managedCursor.getString(address));
smsMessage.setDate(Long.parseLong(managedCursor.getString(date)));
smsMessage.setThreadID(Long.parseLong(managedCursor.getString(threadID)));
smsMessage.setType(Integer.parseInt(managedCursor.getString(type)));
int parts[] = SmsMessage.calculateLength(managedCursor.getString(body), true);//parts of a message will come this
smsMessage.setSmsParts(parts[0]);
smsList.add(smsMessage);
}while ( managedCursor.moveToNext());
}
return smsList;
}catch(Exception e){
e.printStackTrace();
}finally{
if(managedCursor!=null){
managedCursor.close();
/*Warning: Do not call close() on a cursor obtained using this method, because the activity will do that for you at the appropriate time.
* However, if you call stopManagingCursor(Cursor) on a cursor from a managed query,
* the system will not automatically close the cursor and, in that case, you must call close().*/
}
}
return null;
}
示例14: getMessageCount
import android.telephony.SmsMessage; //导入方法依赖的package包/类
/**
* Calculates the number of messages in a multi part message based on the messageBody
* @param messageBody the message body
* @return message count
*/
public static int getMessageCount(String messageBody){
return SmsMessage.calculateLength(messageBody, false)[0];
}