List of usage examples for android.telephony PhoneNumberUtils formatNumber
@Deprecated public static String formatNumber(String source)
From source file:org.voltdb.MainActivity.java
private void identifyPhoneNumber() { mTelephonyManager = (TelephonyManager) getApplicationContext().getSystemService(Context.TELEPHONY_SERVICE); String phoneStr = null;// w ww . j a v a 2 s .com try { phoneStr = mTelephonyManager.getLine1Number(); } catch (Exception e) { e.printStackTrace(); } if (phoneStr != null) { TextView phonePrompt = (TextView) findViewById(R.id.phone_prompt_id); phonePrompt.setText(getString(R.string.your_phone_number)); phoneStr = mTelephonyManager.getLine1Number(); String normilizedPhone = PhoneNumberUtils.formatNumber(phoneStr.substring(1)); mPhoneEdit.setHint(normilizedPhone); } else { mPhoneEdit.setHint(R.string.hint_phone); } }
From source file:at.flack.activity.NewSMSContactActivity.java
public ArrayList<ContactModel> readSMSContacts(Activity activity) { LinkedHashSet<ContactModel> smsList = new LinkedHashSet<ContactModel>(); Cursor phones = activity.getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, null, null, null);// w w w .j a v a 2 s .c om while (phones.moveToNext()) { String name = phones .getString(phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME)); String phoneNumber = phones.getString(phones .getColumnIndex(PhoneNumberUtils.formatNumber(ContactsContract.CommonDataKinds.Phone.NUMBER))); String photo = phones .getString(phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.PHOTO_THUMBNAIL_URI)); String primary = name; if (name == null) primary = phoneNumber; smsList.add(new ContactModel(fetchThumbnail(activity, photo != null ? Uri.parse(photo) : null), primary, phoneNumber, "", false)); } phones.close(); ArrayList<ContactModel> unsorted = new ArrayList<ContactModel>(smsList); Collections.sort(unsorted, new Comparator<ContactModel>() { @Override public int compare(ContactModel lhs, ContactModel rhs) { return lhs.getTitle().compareTo(rhs.getTitle()); } }); return unsorted; }
From source file:org.pixmob.droidlink.ui.EventDetailsFragment.java
private void initFields() { if (eventUri == null) { return;//w w w.jav a2 s . co m } final Cursor cursor = getActivity().getContentResolver().query(eventUri, EVENT_PROJECTION, null, null, null); if (cursor == null) { throw new IllegalArgumentException("Cannot event: " + eventUri); } if (!cursor.moveToNext()) { cursor.close(); throw new IllegalArgumentException("Cannot find event: " + eventUri); } final long date; final int type; final String name; String message; try { date = cursor.getLong(cursor.getColumnIndexOrThrow(CREATED)); type = cursor.getInt(cursor.getColumnIndexOrThrow(TYPE)); name = cursor.getString(cursor.getColumnIndexOrThrow(NAME)); number = cursor.getString(cursor.getColumnIndexOrThrow(NUMBER)); message = cursor.getString(cursor.getColumnIndexOrThrow(MESSAGE)); } finally { cursor.close(); } if (number != null) { number = PhoneNumberUtils.formatNumber(number); } final String dateStr = DateUtils.formatDateTime(getActivity(), date, DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_TIME); dateView.setText(dateStr); final Integer typeResourceId = EVENT_ICONS.get(type); typeView.setVisibility(typeResourceId == null ? View.GONE : View.VISIBLE); if (typeResourceId != null) { typeView.setImageResource(typeResourceId); } final String eventName; final String eventNumber; if (number == null) { eventName = getActivity().getString(R.string.unknown_number); eventNumber = null; } else if (name == null) { eventName = number; eventNumber = null; } else { eventName = name; eventNumber = number; } nameView.setText(eventName); numberView.setText(eventNumber); if (EventsContract.MISSED_CALL_TYPE == type) { message = getString(R.string.missed_call); } messageView.setText(message); new GetContactPictureTask(this, eventNumber).execute(); }
From source file:in.shick.diode.common.Common.java
/** * Helper function to display a list of URLs. * @param theContext The current application context. * @param settings The settings to use regarding the browser component. * @param theItem The ThingInfo item to get URLs from. */// ww w. j a v a 2s . c om public static void showLinksDialog(final Context theContext, final RedditSettings settings, final ThingInfo theItem) { assert (theContext != null); assert (theItem != null); assert (settings != null); final ArrayList<String> urls = new ArrayList<String>(); final ArrayList<MarkdownURL> vtUrls = theItem.getUrls(); for (MarkdownURL vtUrl : vtUrls) { urls.add(vtUrl.url); } ArrayAdapter<MarkdownURL> adapter = new ArrayAdapter<MarkdownURL>(theContext, android.R.layout.select_dialog_item, vtUrls) { public View getView(int position, View convertView, ViewGroup parent) { TextView tv; if (convertView == null) { tv = (TextView) ((LayoutInflater) theContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE)) .inflate(android.R.layout.select_dialog_item, null); } else { tv = (TextView) convertView; } String url = getItem(position).url; String anchorText = getItem(position).anchorText; // if (Constants.LOGGING) Log.d(TAG, "links url="+url + " anchorText="+anchorText); Drawable d = null; try { d = theContext.getPackageManager() .getActivityIcon(new Intent(Intent.ACTION_VIEW, Uri.parse(url))); } catch (PackageManager.NameNotFoundException ignore) { } if (d != null) { d.setBounds(0, 0, d.getIntrinsicHeight(), d.getIntrinsicHeight()); tv.setCompoundDrawablePadding(10); tv.setCompoundDrawables(d, null, null, null); } final String telPrefix = "tel:"; if (url.startsWith(telPrefix)) { url = PhoneNumberUtils.formatNumber(url.substring(telPrefix.length())); } if (anchorText != null) tv.setText(Html.fromHtml("<span>" + anchorText + "</span><br /><small>" + url + "</small>")); else tv.setText(Html.fromHtml(url)); return tv; } }; AlertDialog.Builder b = new AlertDialog.Builder( new ContextThemeWrapper(theContext, settings.getDialogTheme())); DialogInterface.OnClickListener click = new DialogInterface.OnClickListener() { public final void onClick(DialogInterface dialog, int which) { if (which >= 0) { Common.launchBrowser(settings, theContext, urls.get(which), Util.createThreadUri(theItem).toString(), false, false, settings.isUseExternalBrowser(), settings.isSaveHistory()); } } }; b.setTitle(R.string.select_link_title); b.setCancelable(true); b.setAdapter(adapter, click); b.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() { public final void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); b.show(); }
From source file:com.mattprecious.notisync.service.SecondaryService.java
private void handleTextMessage(TextMessage message) { if (!Preferences.getSecondaryTextMessageEnabled(this)) { return;/*from w ww.j av a2s. c om*/ } if (textMessages.containsKey(message.number)) { List<TextMessage> messages = textMessages.remove(message.number); messages.add(message); textMessages.put(message.number, messages); } else { List<TextMessage> list = Lists.newArrayList(); list.add(message); textMessages.put(message.number, list); } NotificationCompat.Builder builder = new NotificationCompat.Builder(this); builder.setSmallIcon(R.drawable.ic_stat_sms); builder.setSound(getRingtoneUri(Preferences.getSecondaryTextMessageRingtone(this))); builder.setAutoCancel(true); int defaults = 0; if (Preferences.getSecondaryTextMessageVibrate(this)) { defaults |= Notification.DEFAULT_VIBRATE; } if (Preferences.getSecondaryTextMessageLights(this)) { defaults |= Notification.DEFAULT_LIGHTS; } builder.setDefaults(defaults); PendingIntent deleteIntent = PendingIntent.getBroadcast(this, 0, new Intent(ACTION_TEXT_NOTIFICATION_DELETED), 0); builder.setContentIntent(deleteIntent); builder.setDeleteIntent(deleteIntent); List<List<NotificationData>> threadList = Lists.newArrayList(); List<Entry<String, List<TextMessage>>> entryList = Lists .reverse(Lists.newArrayList(textMessages.entrySet())); for (Entry<String, List<TextMessage>> entry : entryList) { List<TextMessage> messages = entry.getValue(); TextMessage last = messages.get(messages.size() - 1); String sender; if (last.name != null) { sender = last.name; } else { sender = PhoneNumberUtils.formatNumber(last.number); } List<NotificationData> data = Lists.newArrayList(); for (TextMessage msg : messages) { data.add(new NotificationData(sender, msg.message)); } threadList.add(data); } Bitmap photo = ContactHelper.getContactPhoto(this, message.number); notificationManager.notify(NOTIFICATION_ID_TEXT, buildRichNotification(builder, threadList, photo)); String sender; if (message.name != null) { sender = message.name; } else { sender = PhoneNumberUtils.formatNumber(message.number); } openNotificationDatabaseWrite(); notificationsDbAdapter.insertNotification("text.message", "smsmms", "SMS/MMS", sender, PhoneNumberUtils.formatNumber(message.number), System.currentTimeMillis() + ""); notificationsDbAdapter.close(); }
From source file:com.mattprecious.notisync.service.SecondaryService.java
private void handlePhoneCallMessage(PhoneCallMessage message) { if (!Preferences.getSecondaryPhoneCallEnabled(this)) { return;/*from w w w.ja va 2 s . c om*/ } NotificationCompat.Builder builder = new NotificationCompat.Builder(this); builder.setSound(getRingtoneUri(Preferences.getSecondaryPhoneCallRingtone(this))); builder.setAutoCancel(true); int defaults = 0; if (Preferences.getSecondaryPhoneCallVibrate(this)) { defaults |= Notification.DEFAULT_VIBRATE; } if (Preferences.getSecondaryPhoneCallLights(this)) { defaults |= Notification.DEFAULT_LIGHTS; } builder.setDefaults(defaults); PendingIntent intent = PendingIntent.getActivity(this, 0, new Intent(), 0); builder.setContentIntent(intent); int notificationId; if (message.type == PhoneCallMessage.Type.INCOMING) { incomingCallMessage = message; notificationId = NOTIFICATION_ID_PHONE_INCOMING; builder.setContentTitle(getString(R.string.noti_title_incoming_call)); builder.setSmallIcon(R.drawable.ic_stat_incoming); } else if (message.type == PhoneCallMessage.Type.MISSED) { notificationId = NOTIFICATION_ID_PHONE_MISSED; builder.setContentTitle(getString(R.string.noti_title_missed_call)); builder.setSmallIcon(R.drawable.ic_stat_missed_call); if (incomingCallMessage != null && message.number != null && message.number.equals(incomingCallMessage.number)) { notificationManager.cancel(NOTIFICATION_ID_PHONE_INCOMING); incomingCallMessage = null; } } else { return; } String text; if (message.name != null) { text = message.name; } else { text = PhoneNumberUtils.formatNumber(message.number); } builder.setContentText(text); Notification notification = builder.build(); notificationManager.notify(notificationId, notification); openNotificationDatabaseWrite(); notificationsDbAdapter.insertNotification("phone.call", "phone", "Phone call", text, PhoneNumberUtils.formatNumber(message.number), System.currentTimeMillis() + ""); notificationsDbAdapter.close(); }
From source file:com.supremainc.biostar2.door.DoorFragment.java
private void sendOpenRequest() { String PhoneNumber = null;/*from ww w . ja v a2 s . c o m*/ try { if (Build.VERSION.SDK_INT >= 23) { if (ActivityCompat.checkSelfPermission(mContext, Manifest.permission.READ_PHONE_STATE) != PackageManager.PERMISSION_GRANTED) { ActivityCompat.requestPermissions(mContext, new String[] { Manifest.permission.READ_PHONE_STATE }, Setting.REQUEST_READ_PHONE_STATE); return; } } TelephonyManager telephony = (TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE); if (telephony != null) { PhoneNumber = telephony.getLine1Number(); } if (PhoneNumber != null) { PhoneNumber = PhoneNumberUtils.formatNumber(PhoneNumber); } } catch (Exception e) { PhoneNumber = null; if (BuildConfig.DEBUG) { Log.e(TAG, " " + e.getMessage()); } } if (PhoneNumber == null) { PhoneNumber = mDoorDataProvider.getLoginUserInfo().phone_number; } mPopup.showWait(true); mDoorDataProvider.openRequestDoor(TAG, mDoor.id, PhoneNumber, mRequestDoorListener, mRequestDoorErrorListener, null); }
From source file:at.flack.MainActivity.java
public void whoEncrypts() { if (listItems == null) return;//from w ww .j a v a 2 s .c o m boolean handshake; for (int i = 0; i < getListItems().size(); i++) { handshake = false; if (getListItems().get(i).getLastMessage() == null) continue; // Pre Shared Exchange if ((getListItems().get(i).getLastMessage().toString().length() == 10 || getListItems().get(i).getLastMessage().toString().length() == 9) && getListItems().get(i).getLastMessage().toString().charAt(0) == '%') { if (Base64.isPureBase64(getListItems().get(i).getLastMessage().toString().substring(1, 9))) { getListItems().get(i).setLastMessage(res.getString(R.string.handshake_message)); handshake = true; } } // DH Exchange if (getListItems().get(i).getLastMessage().toString().length() >= 120 && getListItems().get(i).getLastMessage().toString().length() < 125 && getListItems().get(i).getLastMessage().toString().charAt(0) == '%') { if (Base64.isPureBase64(getListItems().get(i).getLastMessage().toString().substring(1, getListItems().get(i).getLastMessage().toString().lastIndexOf("=")))) { getListItems().get(i).setLastMessage(res.getString(R.string.handshake_message)); handshake = true; } } if (contacts.get(i).mAddress != null && KeySafe.getInstance(this) .contains(PhoneNumberUtils.formatNumber(contacts.get(i).mAddress))) { KeyEntity key = KeySafe.getInstance(this) .get(PhoneNumberUtils.formatNumber(contacts.get(i).mAddress)); if (key.getVersion() != KeyEntity.ECDH_PRIVATE_KEY) { getListItems().get(i).setEncrypted(View.VISIBLE); if (!handshake) { try { getListItems().get(i).setLastMessage( new Message(getListItems().get(i).getLastMessage()).decryptedMessage(key)); } catch (MessageDecrypterException e) { } } } } } SMSMainActivity.getInstance().updateContacts(MainActivity.this); }
From source file:com.hualu.wifistart.vcardsrc.VCardBuilder.java
public VCardBuilder appendPhones(final List<ContentValues> contentValuesList) { boolean phoneLineExists = false; if (contentValuesList != null) { Set<String> phoneSet = new HashSet<String>(); for (ContentValues contentValues : contentValuesList) { final Integer typeAsObject = contentValues.getAsInteger(Phone.TYPE); final String label = contentValues.getAsString(Phone.LABEL); final Integer isPrimaryAsInteger = contentValues.getAsInteger(Phone.IS_PRIMARY); final boolean isPrimary = (isPrimaryAsInteger != null ? (isPrimaryAsInteger > 0) : false); String phoneNumber = contentValues.getAsString(Phone.NUMBER); if (phoneNumber != null) { phoneNumber = phoneNumber.trim(); }//from w ww . j a v a2s .c om if (TextUtils.isEmpty(phoneNumber)) { continue; } int type = (typeAsObject != null ? typeAsObject : DEFAULT_PHONE_TYPE); if (type == Phone.TYPE_PAGER) { phoneLineExists = true; if (!phoneSet.contains(phoneNumber)) { phoneSet.add(phoneNumber); appendTelLine(type, label, phoneNumber, isPrimary); } } else { // The entry "may" have several phone numbers when the contact entry is // corrupted because of its original source. // // e.g. I encountered the entry like the following. // "111-222-3333 (Miami)\n444-555-6666 (Broward; 305-653-6796 (Miami); ..." // This kind of entry is not able to be inserted via Android devices, but // possible if the source of the data is already corrupted. List<String> phoneNumberList = splitIfSeveralPhoneNumbersExist(phoneNumber); if (phoneNumberList.isEmpty()) { continue; } phoneLineExists = true; for (String actualPhoneNumber : phoneNumberList) { if (!phoneSet.contains(actualPhoneNumber)) { // final int format = VCardUtils.getPhoneNumberFormat(mVCardType); //final String formattedPhoneNumber = // PhoneNumberUtils.formatNumber(actualPhoneNumber, format); // final int format = VCardUtils.getPhoneNumberFormat(mVCardType); final String formattedPhoneNumber = PhoneNumberUtils.formatNumber(actualPhoneNumber); phoneSet.add(actualPhoneNumber); appendTelLine(type, label, formattedPhoneNumber, isPrimary); } } } } } if (!phoneLineExists && mIsDoCoMo) { appendTelLine(Phone.TYPE_HOME, "", "", false); } return this; }
From source file:com.android.incallui.CallCardFragment.java
@Override public void setCallbackNumber(String callbackNumber, boolean isEmergencyCall) { if (mInCallMessageLabel == null) { return;/*from w w w . j a v a 2s .c o m*/ } if (TextUtils.isEmpty(callbackNumber)) { mInCallMessageLabel.setVisibility(View.GONE); return; } // TODO: The new Locale-specific methods don't seem to be working. Revisit this. callbackNumber = PhoneNumberUtils.formatNumber(callbackNumber); int stringResourceId = isEmergencyCall ? R.string.card_title_callback_number_emergency : R.string.card_title_callback_number; String text = getString(stringResourceId, callbackNumber); mInCallMessageLabel.setText(text); mInCallMessageLabel.setVisibility(View.VISIBLE); }