List of usage examples for android.content Intent getDataString
public @Nullable String getDataString()
From source file:com.xperia64.timidityae.TimidityActivity.java
public void handleIntentData(Intent in) { if (in.getData() != null) { String data;// w w w . j a v a 2 s.c o m if ((data = in.getData().getPath()) != null && in.getData().getScheme() != null) { if (in.getData().getScheme().equals("file")) { if (new File(data).exists()) { File f = new File(data.substring(0, data.lastIndexOf('/') + 1)); if (f.exists()) { if (f.isDirectory()) { ArrayList<String> files = new ArrayList<String>(); int position = -1; int goodCounter = 0; for (File ff : f.listFiles()) { if (ff != null && ff.isFile()) { int dotPosition = ff.getName().lastIndexOf('.'); String extension = ""; if (dotPosition != -1) { extension = (ff.getName().substring(dotPosition)) .toLowerCase(Locale.US); if (extension != null) { if ((Globals.showVideos ? Globals.musicVideoFiles : Globals.musicFiles).contains("*" + extension + "*")) { files.add(ff.getPath()); if (ff.getPath().equals(data)) position = goodCounter; goodCounter++; } } } } } if (position == -1) Toast.makeText(this, getResources().getString(R.string.intErr1), Toast.LENGTH_SHORT).show(); else { stop(); selectedSong(files, position, true, false, false); fileFrag.getDir(data.substring(0, data.lastIndexOf('/') + 1)); } } } } else { Toast.makeText(this, getResources().getString(R.string.srv_fnf), Toast.LENGTH_SHORT).show(); } } else if (in.getData().getScheme().equals("http") || in.getData().getScheme().equals("https")) { if (!data.endsWith("/")) { if (!Globals.getExternalCacheDir(this).exists()) { Globals.getExternalCacheDir(this).mkdirs(); } final Globals.DownloadTask downloadTask = new Globals.DownloadTask(this); downloadTask.execute(in.getData().toString(), in.getData().getLastPathSegment()); in.setData(null); } else { Toast.makeText(this, "This is a directory, not a file", Toast.LENGTH_SHORT).show(); } } else if (in.getData().getScheme().equals("content") && (data.contains("downloads"))) { String filename = null; Cursor cursor = null; try { cursor = this.getContentResolver().query(in.getData(), new String[] { OpenableColumns.DISPLAY_NAME, OpenableColumns.SIZE }, null, null, null); if (cursor != null && cursor.moveToFirst()) { filename = cursor.getString(0); } } finally { if (cursor != null) cursor.close(); } try { InputStream input = getContentResolver().openInputStream(in.getData()); if (new File(Globals.getExternalCacheDir(this).getAbsolutePath() + '/' + filename) .exists()) { new File(Globals.getExternalCacheDir(this).getAbsolutePath() + '/' + filename).delete(); } OutputStream output = new FileOutputStream( Globals.getExternalCacheDir(this).getAbsolutePath() + '/' + filename); byte[] buffer = new byte[4096]; int count; while ((count = input.read(buffer)) != -1) { output.write(buffer, 0, count); } output.close(); } catch (IOException e) { e.printStackTrace(); return; } File f = new File(Globals.getExternalCacheDir(this).getAbsolutePath() + '/'); if (f.exists()) { if (f.isDirectory()) { ArrayList<String> files = new ArrayList<String>(); int position = -1; int goodCounter = 0; for (File ff : f.listFiles()) { if (ff != null && ff.isFile()) { int dotPosition = ff.getName().lastIndexOf('.'); String extension = ""; if (dotPosition != -1) { extension = (ff.getName().substring(dotPosition)).toLowerCase(Locale.US); if (extension != null) { if ((Globals.showVideos ? Globals.musicVideoFiles : Globals.musicFiles) .contains("*" + extension + "*")) { files.add(ff.getPath()); if (ff.getPath() .equals(Globals.getExternalCacheDir(this).getAbsolutePath() + '/' + filename)) position = goodCounter; goodCounter++; } } } } } if (position == -1) Toast.makeText(this, getResources().getString(R.string.intErr1), Toast.LENGTH_SHORT) .show(); else { stop(); selectedSong(files, position, true, false, false); fileFrag.getDir(Globals.getExternalCacheDir(this).getAbsolutePath()); } } } } else { System.out.println(in.getDataString()); Toast.makeText(this, getResources().getString(R.string.intErr2) + " (" + in.getData().getScheme() + ")", Toast.LENGTH_SHORT).show(); } } } }
From source file:com.zoffcc.applications.zanavi.Navit.java
protected void onNewIntent(Intent intent) { super.onNewIntent(intent); try {/* w w w .ja va 2s . c o m*/ System.out.println("XXIIXX(2):111"); String mid_str = intent.getExtras().getString("com.zoffcc.applications.zanavi.mid"); System.out.println("XXIIXX(2):111a:mid_str=" + mid_str); if (mid_str != null) { if (mid_str.equals("201:UPDATE-APP")) { // a new ZANavi version is available, show something to the user here ------------------- // a new ZANavi version is available, show something to the user here ------------------- // a new ZANavi version is available, show something to the user here ------------------- // a new ZANavi version is available, show something to the user here ------------------- // a new ZANavi version is available, show something to the user here ------------------- // a new ZANavi version is available, show something to the user here ------------------- } else if (mid_str.startsWith("202:UPDATE-MAP:")) { // System.out.println("need to update1:" + mid_str); // System.out.println("need to update2:" + mid_str.substring(15)); auto_start_update_map(mid_str.substring(15)); } } System.out.println("XXIIXX(2):111b:mid_str=" + mid_str); } catch (Exception e) { e.printStackTrace(); System.out.println("XXIIXX(2):111:EEEE"); } // ---- Intent dump ---- // ---- Intent dump ---- // ---- Intent dump ---- // ---- Intent dump ---- try { System.out.println("XXIIXX(2):" + intent); Bundle bundle77 = intent.getExtras(); System.out.println("XXIIXX(2):" + intent_flags_to_string(intent.getFlags())); if (bundle77 == null) { System.out.println("XXIIXX(2):" + "null"); } else { for (String key : bundle77.keySet()) { Object value = bundle77.get(key); System.out.println("XXIIXX(2):" + String.format("%s %s (%s)", key, value.toString(), value.getClass().getName())); } } } catch (Exception ee22) { String exst = Log.getStackTraceString(ee22); System.out.println("XXIIXX(2):ERR:" + exst); } // ---- Intent dump ---- // ---- Intent dump ---- // ---- Intent dump ---- // ---- Intent dump ---- Log.e("Navit", "3:**1**A " + intent.getAction()); Log.e("Navit", "3:**1**D " + intent.getDataString()); Log.e("Navit", "3:**1**S " + intent.toString()); try { Log.e("Navit", "3:**1**S " + intent.getExtras().describeContents()); } catch (Exception ee3) { } // if (Navit.startup_intent == null) { try { // make a copy of the given intent object // Navit.startup_intent = intent.cloneFilter(); Navit.startup_intent = intent; Log.e("Navit", "3a:**1**001"); Bundle extras2 = intent.getExtras(); Log.e("Navit", "3a:**1**002"); try { Navit.startup_intent.putExtras(extras2); Log.e("Navit", "3a:**1**003"); } catch (Exception e4) { if (startup_intent.getDataString() != null) { // we have a "geo:" thingy intent, use it // or "gpx file" Log.e("Navit", "3c:**1**A " + startup_intent.getAction()); Log.e("Navit", "3c:**1**D " + startup_intent.getDataString()); Log.e("Navit", "3c:**1**S " + startup_intent.toString()); } else { Log.e("Navit", "3X:**1**X "); Navit.startup_intent = null; } // hack! remeber timstamp, and only allow 4 secs. later in onResume to set target! Navit.startup_intent_timestamp = System.currentTimeMillis(); return; } // Intent { act=android.intent.action.VIEW // cat=[android.intent.category.DEFAULT] // dat=file:///mnt/sdcard/zanavi_pos_recording_347834278.gpx // cmp=com.zoffcc.applications.zanavi/.Navit } // hack! remeber timstamp, and only allow 4 secs. later in onResume to set target! Navit.startup_intent_timestamp = System.currentTimeMillis(); Log.e("Navit", "3a:**1**A " + startup_intent.getAction()); Log.e("Navit", "3a:**1**D " + startup_intent.getDataString()); Log.e("Navit", "3a:**1**S " + startup_intent.toString()); if (extras2 != null) { long l = extras2.getLong("com.zoffcc.applications.zanavi.ZANAVI_INTENT_type"); // System.out.println("DH:a007 l=" + l); if (l != 0L) { if (l == Navit.NAVIT_START_INTENT_DRIVE_HOME) { // Log.e("Navit", "2:**1** started via drive home"); // we have been called from "drive home" widget // drive home // check if we have a home location int home_id = find_home_point(); if (home_id != -1) { Message msg7 = progress_handler.obtainMessage(); Bundle b7 = new Bundle(); msg7.what = 2; // long Toast message b7.putString("text", Navit.get_text("driving to Home Location")); //TRANS msg7.setData(b7); progress_handler.sendMessage(msg7); // clear any previous destinations Message msg2 = new Message(); Bundle b2 = new Bundle(); b2.putInt("Callback", 7); msg2.setData(b2); NavitGraphics.callback_handler.sendMessage(msg2); // set position to middle of screen ----------------------- // set position to middle of screen ----------------------- // set position to middle of screen ----------------------- // Message msg67 = new Message(); // Bundle b67 = new Bundle(); // b67.putInt("Callback", 51); // b67.putInt("x", (int) (NavitGraphics.Global_dpi_factor * Navit.NG__map_main.view.getWidth() / 2)); // b67.putInt("y", (int) (NavitGraphics.Global_dpi_factor * Navit.NG__map_main.view.getHeight() / 2)); // msg67.setData(b67); // N_NavitGraphics.callback_handler.sendMessage(msg67); // set position to middle of screen ----------------------- // set position to middle of screen ----------------------- // set position to middle of screen ----------------------- try { Thread.sleep(60); } catch (Exception e) { } route_wrapper(map_points.get(home_id).point_name, 0, 0, false, map_points.get(home_id).lat, map_points.get(home_id).lon, true); // Navit.destination_set(); // // // set destination to home location // String lat = String.valueOf(map_points.get(home_id).lat); // String lon = String.valueOf(map_points.get(home_id).lon); // String q = map_points.get(home_id).point_name; // // // System.out.println("lat=" + lat + " lon=" + lon + " name=" + q); // // Message msg55 = new Message(); // Bundle b55 = new Bundle(); // b55.putInt("Callback", 3); // b55.putString("lat", lat); // b55.putString("lon", lon); // b55.putString("q", q); // msg55.setData(b55); // NavitGraphics.callback_handler.sendMessage(msg55); final Thread zoom_to_route_001 = new Thread() { int wait = 1; int count = 0; int max_count = 60; @Override public void run() { while (wait == 1) { try { if ((NavitGraphics.navit_route_status == 17) || (NavitGraphics.navit_route_status == 33)) { zoom_to_route(); wait = 0; } else { wait = 1; } count++; if (count > max_count) { wait = 0; } else { Thread.sleep(400); } } catch (Exception e) { } } } }; zoom_to_route_001.start(); // try // { // show_geo_on_screen(Float.parseFloat(lat), Float.parseFloat(lon)); // } // catch (Exception e2) // { // e2.printStackTrace(); // } try { Navit.follow_button_on(); } catch (Exception e2) { e2.printStackTrace(); } } else { // no home location set Message msg = progress_handler.obtainMessage(); Bundle b = new Bundle(); msg.what = 2; // long Toast message b.putString("text", Navit.get_text("No Home Location set")); //TRANS msg.setData(b); progress_handler.sendMessage(msg); } } } else { if (startup_intent.getDataString() != null) { // we have a "geo:" thingy intent, use it // or "gpx file" } else { Navit.startup_intent = null; } } } else { if (startup_intent.getDataString() != null) { // we have a "geo:" thingy intent, use it } else { Navit.startup_intent = null; } } } catch (Exception e99) { Navit.startup_intent = null; } } }
From source file:com.android.contacts.quickcontact.QuickContactActivity.java
/** * Converts a {@link DataItem} into an {@link ExpandingEntryCardView.Entry} for display. * If the {@link ExpandingEntryCardView.Entry} has no visual elements, null is returned. * * This runs on a background thread. This is set as static to avoid accidentally adding * additional dependencies on unsafe things (like the Activity). * * @param dataItem The {@link DataItem} to convert. * @param secondDataItem A second {@link DataItem} to help build a full entry for some * mimetypes/*from w ww .j av a 2s . c o m*/ * @return The {@link ExpandingEntryCardView.Entry}, or null if no visual elements are present. */ private static Entry dataItemToEntry(DataItem dataItem, DataItem secondDataItem, Context context, Contact contactData, final MutableString aboutCardName) { Drawable icon = null; String header = null; String subHeader = null; Drawable subHeaderIcon = null; String text = null; Drawable textIcon = null; StringBuilder primaryContentDescription = new StringBuilder(); Spannable phoneContentDescription = null; Spannable smsContentDescription = null; Intent intent = null; boolean shouldApplyColor = true; Drawable alternateIcon = null; Intent alternateIntent = null; StringBuilder alternateContentDescription = new StringBuilder(); final boolean isEditable = false; EntryContextMenuInfo entryContextMenuInfo = null; Drawable thirdIcon = null; Intent thirdIntent = null; int thirdAction = Entry.ACTION_NONE; String thirdContentDescription = null; Bundle thirdExtras = null; int iconResourceId = 0; context = context.getApplicationContext(); final Resources res = context.getResources(); DataKind kind = dataItem.getDataKind(); if (dataItem instanceof ImDataItem) { final ImDataItem im = (ImDataItem) dataItem; intent = ContactsUtils.buildImIntent(context, im).first; final boolean isEmail = im.isCreatedFromEmail(); final int protocol; if (!im.isProtocolValid()) { protocol = Im.PROTOCOL_CUSTOM; } else { protocol = isEmail ? Im.PROTOCOL_GOOGLE_TALK : im.getProtocol(); } if (protocol == Im.PROTOCOL_CUSTOM) { // If the protocol is custom, display the "IM" entry header as well to distinguish // this entry from other ones header = res.getString(R.string.header_im_entry); subHeader = Im.getProtocolLabel(res, protocol, im.getCustomProtocol()).toString(); text = im.getData(); } else { header = Im.getProtocolLabel(res, protocol, im.getCustomProtocol()).toString(); subHeader = im.getData(); } entryContextMenuInfo = new EntryContextMenuInfo(im.getData(), header, dataItem.getMimeType(), dataItem.getId(), dataItem.isSuperPrimary()); } else if (dataItem instanceof OrganizationDataItem) { final OrganizationDataItem organization = (OrganizationDataItem) dataItem; header = res.getString(R.string.header_organization_entry); subHeader = organization.getCompany(); entryContextMenuInfo = new EntryContextMenuInfo(subHeader, header, dataItem.getMimeType(), dataItem.getId(), dataItem.isSuperPrimary()); text = organization.getTitle(); } else if (dataItem instanceof NicknameDataItem) { final NicknameDataItem nickname = (NicknameDataItem) dataItem; // Build nickname entries final boolean isNameRawContact = (contactData.getNameRawContactId() == dataItem.getRawContactId()); final boolean duplicatesTitle = isNameRawContact && contactData.getDisplayNameSource() == DisplayNameSources.NICKNAME; if (!duplicatesTitle) { header = res.getString(R.string.header_nickname_entry); subHeader = nickname.getName(); entryContextMenuInfo = new EntryContextMenuInfo(subHeader, header, dataItem.getMimeType(), dataItem.getId(), dataItem.isSuperPrimary()); } } else if (dataItem instanceof NoteDataItem) { final NoteDataItem note = (NoteDataItem) dataItem; header = res.getString(R.string.header_note_entry); subHeader = note.getNote(); entryContextMenuInfo = new EntryContextMenuInfo(subHeader, header, dataItem.getMimeType(), dataItem.getId(), dataItem.isSuperPrimary()); } else if (dataItem instanceof WebsiteDataItem) { final WebsiteDataItem website = (WebsiteDataItem) dataItem; header = res.getString(R.string.header_website_entry); subHeader = website.getUrl(); entryContextMenuInfo = new EntryContextMenuInfo(subHeader, header, dataItem.getMimeType(), dataItem.getId(), dataItem.isSuperPrimary()); try { final WebAddress webAddress = new WebAddress(website.buildDataStringForDisplay(context, kind)); intent = new Intent(Intent.ACTION_VIEW, Uri.parse(webAddress.toString())); } catch (final ParseException e) { Log.e(TAG, "Couldn't parse website: " + website.buildDataStringForDisplay(context, kind)); } } else if (dataItem instanceof EventDataItem) { final EventDataItem event = (EventDataItem) dataItem; final String dataString = event.buildDataStringForDisplay(context, kind); final Calendar cal = DateUtils.parseDate(dataString, false); if (cal != null) { final Date nextAnniversary = DateUtils.getNextAnnualDate(cal); final Uri.Builder builder = CalendarContract.CONTENT_URI.buildUpon(); builder.appendPath("time"); ContentUris.appendId(builder, nextAnniversary.getTime()); intent = new Intent(Intent.ACTION_VIEW).setData(builder.build()); } header = res.getString(R.string.header_event_entry); if (event.hasKindTypeColumn(kind)) { subHeader = EventCompat.getTypeLabel(res, event.getKindTypeColumn(kind), event.getLabel()) .toString(); } text = DateUtils.formatDate(context, dataString); entryContextMenuInfo = new EntryContextMenuInfo(text, header, dataItem.getMimeType(), dataItem.getId(), dataItem.isSuperPrimary()); } else if (dataItem instanceof RelationDataItem) { final RelationDataItem relation = (RelationDataItem) dataItem; final String dataString = relation.buildDataStringForDisplay(context, kind); if (!TextUtils.isEmpty(dataString)) { intent = new Intent(Intent.ACTION_SEARCH); intent.putExtra(SearchManager.QUERY, dataString); intent.setType(Contacts.CONTENT_TYPE); } header = res.getString(R.string.header_relation_entry); subHeader = relation.getName(); entryContextMenuInfo = new EntryContextMenuInfo(subHeader, header, dataItem.getMimeType(), dataItem.getId(), dataItem.isSuperPrimary()); if (relation.hasKindTypeColumn(kind)) { text = Relation.getTypeLabel(res, relation.getKindTypeColumn(kind), relation.getLabel()).toString(); } } else if (dataItem instanceof PhoneDataItem) { final PhoneDataItem phone = (PhoneDataItem) dataItem; String phoneLabel = null; if (!TextUtils.isEmpty(phone.getNumber())) { primaryContentDescription.append(res.getString(R.string.call_other)).append(" "); header = sBidiFormatter.unicodeWrap(phone.buildDataStringForDisplay(context, kind), TextDirectionHeuristics.LTR); entryContextMenuInfo = new EntryContextMenuInfo(header, res.getString(R.string.phoneLabelsGroup), dataItem.getMimeType(), dataItem.getId(), dataItem.isSuperPrimary()); if (phone.hasKindTypeColumn(kind)) { final int kindTypeColumn = phone.getKindTypeColumn(kind); final String label = phone.getLabel(); phoneLabel = label; if (kindTypeColumn == Phone.TYPE_CUSTOM && TextUtils.isEmpty(label)) { text = ""; } else { text = Phone.getTypeLabel(res, kindTypeColumn, label).toString(); phoneLabel = text; primaryContentDescription.append(text).append(" "); } } primaryContentDescription.append(header); phoneContentDescription = com.android.contacts.common.util.ContactDisplayUtils .getTelephoneTtsSpannable(primaryContentDescription.toString(), header); icon = res.getDrawable(R.drawable.ic_phone_24dp); iconResourceId = R.drawable.ic_phone_24dp; if (PhoneCapabilityTester.isPhone(context)) { intent = CallUtil.getCallIntent(phone.getNumber()); } alternateIntent = new Intent(Intent.ACTION_SENDTO, Uri.fromParts(ContactsUtils.SCHEME_SMSTO, phone.getNumber(), null)); alternateIcon = res.getDrawable(R.drawable.ic_message_24dp); alternateContentDescription.append(res.getString(R.string.sms_custom, header)); smsContentDescription = com.android.contacts.common.util.ContactDisplayUtils .getTelephoneTtsSpannable(alternateContentDescription.toString(), header); int videoCapability = CallUtil.getVideoCallingAvailability(context); boolean isPresenceEnabled = (videoCapability & CallUtil.VIDEO_CALLING_PRESENCE) != 0; boolean isVideoEnabled = (videoCapability & CallUtil.VIDEO_CALLING_ENABLED) != 0; if (CallUtil.isCallWithSubjectSupported(context)) { thirdIcon = res.getDrawable(R.drawable.ic_call_note_white_24dp); thirdAction = Entry.ACTION_CALL_WITH_SUBJECT; thirdContentDescription = res.getString(R.string.call_with_a_note); // Create a bundle containing the data the call subject dialog requires. thirdExtras = new Bundle(); thirdExtras.putLong(CallSubjectDialog.ARG_PHOTO_ID, contactData.getPhotoId()); thirdExtras.putParcelable(CallSubjectDialog.ARG_PHOTO_URI, UriUtils.parseUriOrNull(contactData.getPhotoUri())); thirdExtras.putParcelable(CallSubjectDialog.ARG_CONTACT_URI, contactData.getLookupUri()); thirdExtras.putString(CallSubjectDialog.ARG_NAME_OR_NUMBER, contactData.getDisplayName()); thirdExtras.putBoolean(CallSubjectDialog.ARG_IS_BUSINESS, false); thirdExtras.putString(CallSubjectDialog.ARG_NUMBER, phone.getNumber()); thirdExtras.putString(CallSubjectDialog.ARG_DISPLAY_NUMBER, phone.getFormattedPhoneNumber()); thirdExtras.putString(CallSubjectDialog.ARG_NUMBER_LABEL, phoneLabel); } else if (isVideoEnabled) { // Check to ensure carrier presence indicates the number supports video calling. int carrierPresence = dataItem.getCarrierPresence(); boolean isPresent = (carrierPresence & Phone.CARRIER_PRESENCE_VT_CAPABLE) != 0; if ((isPresenceEnabled && isPresent) || !isPresenceEnabled) { thirdIcon = res.getDrawable(R.drawable.ic_videocam); thirdAction = Entry.ACTION_INTENT; thirdIntent = CallUtil.getVideoCallIntent(phone.getNumber(), CALL_ORIGIN_QUICK_CONTACTS_ACTIVITY); thirdContentDescription = res.getString(R.string.description_video_call); } } } } else if (dataItem instanceof EmailDataItem) { final EmailDataItem email = (EmailDataItem) dataItem; final String address = email.getData(); if (!TextUtils.isEmpty(address)) { primaryContentDescription.append(res.getString(R.string.email_other)).append(" "); final Uri mailUri = Uri.fromParts(ContactsUtils.SCHEME_MAILTO, address, null); intent = new Intent(Intent.ACTION_SENDTO, mailUri); header = email.getAddress(); entryContextMenuInfo = new EntryContextMenuInfo(header, res.getString(R.string.emailLabelsGroup), dataItem.getMimeType(), dataItem.getId(), dataItem.isSuperPrimary()); if (email.hasKindTypeColumn(kind)) { text = Email.getTypeLabel(res, email.getKindTypeColumn(kind), email.getLabel()).toString(); primaryContentDescription.append(text).append(" "); } primaryContentDescription.append(header); icon = res.getDrawable(R.drawable.ic_email_24dp); iconResourceId = R.drawable.ic_email_24dp; } } else if (dataItem instanceof StructuredPostalDataItem) { StructuredPostalDataItem postal = (StructuredPostalDataItem) dataItem; final String postalAddress = postal.getFormattedAddress(); if (!TextUtils.isEmpty(postalAddress)) { primaryContentDescription.append(res.getString(R.string.map_other)).append(" "); intent = StructuredPostalUtils.getViewPostalAddressIntent(postalAddress); header = postal.getFormattedAddress(); entryContextMenuInfo = new EntryContextMenuInfo(header, res.getString(R.string.postalLabelsGroup), dataItem.getMimeType(), dataItem.getId(), dataItem.isSuperPrimary()); if (postal.hasKindTypeColumn(kind)) { text = StructuredPostal.getTypeLabel(res, postal.getKindTypeColumn(kind), postal.getLabel()) .toString(); primaryContentDescription.append(text).append(" "); } primaryContentDescription.append(header); alternateIntent = StructuredPostalUtils.getViewPostalAddressDirectionsIntent(postalAddress); alternateIcon = res.getDrawable(R.drawable.ic_directions_24dp); alternateContentDescription.append(res.getString(R.string.content_description_directions)) .append(" ").append(header); icon = res.getDrawable(R.drawable.ic_place_24dp); iconResourceId = R.drawable.ic_place_24dp; } } else if (dataItem instanceof SipAddressDataItem) { final SipAddressDataItem sip = (SipAddressDataItem) dataItem; final String address = sip.getSipAddress(); if (!TextUtils.isEmpty(address)) { primaryContentDescription.append(res.getString(R.string.call_other)).append(" "); if (PhoneCapabilityTester.isSipPhone(context)) { final Uri callUri = Uri.fromParts(PhoneAccount.SCHEME_SIP, address, null); intent = CallUtil.getCallIntent(callUri); } header = address; entryContextMenuInfo = new EntryContextMenuInfo(header, res.getString(R.string.phoneLabelsGroup), dataItem.getMimeType(), dataItem.getId(), dataItem.isSuperPrimary()); if (sip.hasKindTypeColumn(kind)) { text = SipAddress.getTypeLabel(res, sip.getKindTypeColumn(kind), sip.getLabel()).toString(); primaryContentDescription.append(text).append(" "); } primaryContentDescription.append(header); icon = res.getDrawable(R.drawable.ic_dialer_sip_black_24dp); iconResourceId = R.drawable.ic_dialer_sip_black_24dp; } } else if (dataItem instanceof StructuredNameDataItem) { // If the name is already set and this is not the super primary value then leave the // current value. This way we show the super primary value when we are able to. if (dataItem.isSuperPrimary() || aboutCardName.value == null || aboutCardName.value.isEmpty()) { final String givenName = ((StructuredNameDataItem) dataItem).getGivenName(); if (!TextUtils.isEmpty(givenName)) { aboutCardName.value = res.getString(R.string.about_card_title) + " " + givenName; } else { aboutCardName.value = res.getString(R.string.about_card_title); } } } else { // Custom DataItem header = dataItem.buildDataStringForDisplay(context, kind); text = kind.typeColumn; intent = new Intent(Intent.ACTION_VIEW); final Uri uri = ContentUris.withAppendedId(Data.CONTENT_URI, dataItem.getId()); intent.setDataAndType(uri, dataItem.getMimeType()); if (intent != null) { final String mimetype = intent.getType(); // Build advanced entry for known 3p types. Otherwise default to ResolveCache icon. switch (mimetype) { case MIMETYPE_GPLUS_PROFILE: // If a secondDataItem is available, use it to build an entry with // alternate actions if (secondDataItem != null) { icon = res.getDrawable(R.drawable.ic_google_plus_24dp); alternateIcon = res.getDrawable(R.drawable.ic_add_to_circles_black_24); final GPlusOrHangoutsDataItemModel itemModel = new GPlusOrHangoutsDataItemModel(intent, alternateIntent, dataItem, secondDataItem, alternateContentDescription, header, text, context); populateGPlusOrHangoutsDataItemModel(itemModel); intent = itemModel.intent; alternateIntent = itemModel.alternateIntent; alternateContentDescription = itemModel.alternateContentDescription; header = itemModel.header; text = itemModel.text; } else { if (GPLUS_PROFILE_DATA_5_ADD_TO_CIRCLE.equals(intent.getDataString())) { icon = res.getDrawable(R.drawable.ic_add_to_circles_black_24); } else { icon = res.getDrawable(R.drawable.ic_google_plus_24dp); } } break; case MIMETYPE_HANGOUTS: // If a secondDataItem is available, use it to build an entry with // alternate actions if (secondDataItem != null) { icon = res.getDrawable(R.drawable.ic_hangout_24dp); alternateIcon = res.getDrawable(R.drawable.ic_hangout_video_24dp); final GPlusOrHangoutsDataItemModel itemModel = new GPlusOrHangoutsDataItemModel(intent, alternateIntent, dataItem, secondDataItem, alternateContentDescription, header, text, context); populateGPlusOrHangoutsDataItemModel(itemModel); intent = itemModel.intent; alternateIntent = itemModel.alternateIntent; alternateContentDescription = itemModel.alternateContentDescription; header = itemModel.header; text = itemModel.text; } else { if (HANGOUTS_DATA_5_VIDEO.equals(intent.getDataString())) { icon = res.getDrawable(R.drawable.ic_hangout_video_24dp); } else { icon = res.getDrawable(R.drawable.ic_hangout_24dp); } } break; default: entryContextMenuInfo = new EntryContextMenuInfo(header, mimetype, dataItem.getMimeType(), dataItem.getId(), dataItem.isSuperPrimary()); icon = ResolveCache.getInstance(context).getIcon(dataItem.getMimeType(), intent); // Call mutate to create a new Drawable.ConstantState for color filtering if (icon != null) { icon.mutate(); } shouldApplyColor = false; } } } if (intent != null) { // Do not set the intent is there are no resolves if (!PhoneCapabilityTester.isIntentRegistered(context, intent)) { intent = null; } } if (alternateIntent != null) { // Do not set the alternate intent is there are no resolves if (!PhoneCapabilityTester.isIntentRegistered(context, alternateIntent)) { alternateIntent = null; } else if (TextUtils.isEmpty(alternateContentDescription)) { // Attempt to use package manager to find a suitable content description if needed alternateContentDescription.append(getIntentResolveLabel(alternateIntent, context)); } } // If the Entry has no visual elements, return null if (icon == null && TextUtils.isEmpty(header) && TextUtils.isEmpty(subHeader) && subHeaderIcon == null && TextUtils.isEmpty(text) && textIcon == null) { return null; } // Ignore dataIds from the Me profile. final int dataId = dataItem.getId() > Integer.MAX_VALUE ? -1 : (int) dataItem.getId(); return new Entry(dataId, icon, header, subHeader, subHeaderIcon, text, textIcon, phoneContentDescription == null ? new SpannableString(primaryContentDescription.toString()) : phoneContentDescription, intent, alternateIcon, alternateIntent, smsContentDescription == null ? new SpannableString(alternateContentDescription.toString()) : smsContentDescription, shouldApplyColor, isEditable, entryContextMenuInfo, thirdIcon, thirdIntent, thirdContentDescription, thirdAction, thirdExtras, iconResourceId); }