@Override
 public void appendSearchableData(IndexBuilder builder) {
   int protocol = builder.getInt(Im.PROTOCOL);
   String customProtocol = builder.getString(Im.CUSTOM_PROTOCOL);
   builder.appendContent(
       Im.getProtocolLabel(mContext.getResources(), protocol, customProtocol).toString());
   builder.appendContentFromColumn(Im.DATA, IndexBuilder.SEPARATOR_SLASH);
 }
 protected EditType buildImType(int type) {
   return new EditType(type, Im.getProtocolLabelResource(type));
 }
Beispiel #3
0
  /** Create an action from common {@link Data} elements. */
  public DataAction(Context context, DataItem item) {
    mContext = context;
    mKind = item.getDataKind();
    mMimeType = item.getMimeType();

    /*
     * New Feature by Mediatek Begin.
     *   Original Android's code:
     *
     *   CR ID: ALPS00308657
     *   Descriptions: RCS
     */
    String exMimeType = null;
    boolean pluginStatus =
        ExtensionManager.getInstance()
            .getContactDetailExtension()
            .checkPluginSupport(ExtensionManager.COMMD_FOR_RCS);
    if (pluginStatus) {
      exMimeType =
          ExtensionManager.getInstance()
              .getContactDetailExtension()
              .getExtentionMimeType(ExtensionManager.COMMD_FOR_RCS);
    }
    /*
     * New Feature by Mediatek End.
     */

    // Determine type for subtitle
    mSubtitle = "";
    if (item.hasKindTypeColumn()) {
      final int typeValue = item.getKindTypeColumn();
      // get type string
      /** M:AAS @ { */
      if (SimUtils.isAasPhoneType(typeValue)) {
        int slotId =
            ExtensionManager.getInstance()
                .getContactAccountExtension()
                .getCurrentSlot(ExtensionManager.COMMD_FOR_AAS);
        mSubtitle =
            (String)
                ExtensionManager.getInstance()
                    .getContactAccountExtension()
                    .getTypeLabel(
                        context.getResources(),
                        typeValue,
                        item.getContentValues().getAsString(Data.DATA3),
                        slotId,
                        ExtensionManager.COMMD_FOR_AAS);
      } else {
        /** M: @ } */
        for (EditType type : item.getDataKind().typeList) {
          if (type.rawValue == typeValue) {
            if (type.customColumn == null) {
              // Non-custom type. Get its description from the
              // resource
              mSubtitle = context.getString(type.labelRes);
            } else {
              // Custom type. Read it from the database
              mSubtitle = item.getContentValues().getAsString(type.customColumn);
            }
            break;
          }
        }
      }
    }

    mIsPrimary = item.isSuperPrimary();
    mBody = item.buildDataStringForDisplay();

    mDataId = item.getId();
    mDataUri = ContentUris.withAppendedId(Data.CONTENT_URI, mDataId);

    final boolean hasPhone = PhoneCapabilityTester.isPhone(mContext);
    final boolean hasSms = PhoneCapabilityTester.isSmsIntentRegistered(mContext);

    // Handle well-known MIME-types with special care
    if (item instanceof PhoneDataItem) {
      if (PhoneCapabilityTester.isPhone(mContext)) {
        PhoneDataItem phone = (PhoneDataItem) item;
        final String number = phone.getNumber();
        if (!TextUtils.isEmpty(number)) {

          /*
           * New Feature by Mediatek Begin.
           *   Original Android's code:
           *
           *   CR ID: ALPS00308657
           *   Descriptions: RCS
           */
          mPhoneAndSubtitle.put(number, mSubtitle.toString());
          /*
           * New Feature by Mediatek End.
           */

          final Intent phoneIntent = hasPhone ? ContactsUtils.getCallIntent(number) : null;
          final Intent smsIntent =
              hasSms
                  ? new Intent(
                      Intent.ACTION_SENDTO, Uri.fromParts(Constants.SCHEME_SMSTO, number, null))
                  : null;

          // Configure Icons and Intents. Notice actionIcon is already set to the phone
          if (hasPhone && hasSms) {
            mIntent = phoneIntent;
            mAlternateIntent = smsIntent;
            mAlternateIconRes = item.getDataKind().iconAltRes;
            mAlternateIconDescriptionRes = item.getDataKind().iconAltDescriptionRes;
          } else if (hasPhone) {
            mIntent = phoneIntent;
          } else if (hasSms) {
            mIntent = smsIntent;
          }
        }
      }
    } else if (item instanceof SipAddressDataItem) {
      if (PhoneCapabilityTester.isSipPhone(mContext)) {
        final SipAddressDataItem sip = (SipAddressDataItem) item;
        final String address = sip.getSipAddress();
        if (!TextUtils.isEmpty(address)) {
          final Uri callUri = Uri.fromParts(Constants.SCHEME_SIP, address, null);
          mIntent = ContactsUtils.getCallIntent(callUri);
          // Note that this item will get a SIP-specific variant
          // of the "call phone" icon, rather than the standard
          // app icon for the Phone app (which we show for
          // regular phone numbers.)  That's because the phone
          // app explicitly specifies an android:icon attribute
          // for the SIP-related intent-filters in its manifest.
        }
      }
    } else if (item instanceof EmailDataItem) {
      final EmailDataItem email = (EmailDataItem) item;
      final String address = email.getData();
      if (!TextUtils.isEmpty(address)) {
        final Uri mailUri = Uri.fromParts(Constants.SCHEME_MAILTO, address, null);
        mIntent = new Intent(Intent.ACTION_SENDTO, mailUri);
      }

    } else if (item instanceof WebsiteDataItem) {
      final WebsiteDataItem website = (WebsiteDataItem) item;
      final String url = website.getUrl();
      if (!TextUtils.isEmpty(url)) {
        WebAddress webAddress = new WebAddress(url);
        mIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(webAddress.toString()));
      }

    } else if (item instanceof ImDataItem) {
      ImDataItem im = (ImDataItem) item;
      final boolean isEmail = im.isCreatedFromEmail();
      if (isEmail || im.isProtocolValid()) {
        final int protocol = isEmail ? Im.PROTOCOL_GOOGLE_TALK : im.getProtocol();

        if (isEmail) {
          // Use Google Talk string when using Email, and clear data
          // Uri so we don't try saving Email as primary.
          mSubtitle = Im.getProtocolLabel(context.getResources(), Im.PROTOCOL_GOOGLE_TALK, null);
          mDataUri = null;
        }

        String host = im.getCustomProtocol();
        String data = im.getData();
        if (protocol != Im.PROTOCOL_CUSTOM) {
          // Try bringing in a well-known host for specific protocols
          host = ContactsUtils.lookupProviderNameFromId(protocol);
        }

        if (!TextUtils.isEmpty(host) && !TextUtils.isEmpty(data)) {
          final String authority = host.toLowerCase();
          final Uri imUri =
              new Uri.Builder()
                  .scheme(Constants.SCHEME_IMTO)
                  .authority(authority)
                  .appendPath(data)
                  .build();
          mIntent = new Intent(Intent.ACTION_SENDTO, imUri);

          // If the address is also available for a video chat, we'll show the capability
          // as a secondary action.
          final int chatCapability = im.getChatCapability();
          final boolean isVideoChatCapable = (chatCapability & Im.CAPABILITY_HAS_CAMERA) != 0;
          final boolean isAudioChatCapable = (chatCapability & Im.CAPABILITY_HAS_VOICE) != 0;
          if (isVideoChatCapable || isAudioChatCapable) {
            mAlternateIntent =
                new Intent(Intent.ACTION_SENDTO, Uri.parse("xmpp:" + data + "?call"));
            if (isVideoChatCapable) {
              mAlternateIconRes = R.drawable.sym_action_videochat_holo_light;
              mAlternateIconDescriptionRes = R.string.video_chat;
            } else {
              mAlternateIconRes = R.drawable.sym_action_audiochat_holo_light;
              mAlternateIconDescriptionRes = R.string.audio_chat;
            }
          }
        }
      }
    } else if (item instanceof StructuredPostalDataItem) {
      StructuredPostalDataItem postal = (StructuredPostalDataItem) item;
      final String postalAddress = postal.getFormattedAddress();
      if (!TextUtils.isEmpty(postalAddress)) {
        mIntent = StructuredPostalUtils.getViewPostalAddressIntent(postalAddress);
      }
    }

    /*
     * New Feature by Mediatek Begin.
     *   Original Android's code:
     *
     *   CR ID: ALPS00308657
     *   Descriptions: RCS
     */

    else if (exMimeType != null && exMimeType.equals(item.getMimeType())) {
      String number = item.getContentValues().getAsString(Data.DATA1);
      mSubtitle = mPhoneAndSubtitle.get(number);
      int im = item.getContentValues().getAsInteger(Data.DATA5);
      int ft = item.getContentValues().getAsInteger(Data.DATA6);
      Log.i(TAG, "mSubtitle : " + mSubtitle + " | number : " + number);
      Intent intent =
          ExtensionManager.getInstance()
              .getContactDetailExtension()
              .getExtentionIntent(im, ft, ExtensionManager.COMMD_FOR_RCS);
      Log.i(TAG, "intent : " + intent + " | exMimeType : " + exMimeType);
      if (intent != null) {
        String name = item.getContentValues().getAsString(Contacts.DISPLAY_NAME);
        Log.i(TAG, "name : " + name + " | number : " + number);
        intent.putExtra(RCS_PHONE_NUMBER, number);
        intent.putExtra(RCS_DISPLAY_NAME, name);
        mIntent = intent;
      }
    }
    /*
     * New Feature by Mediatek End.
     */

    if (mIntent == null) {
      // Otherwise fall back to default VIEW action
      mIntent = new Intent(Intent.ACTION_VIEW);
      mIntent.setDataAndType(mDataUri, item.getMimeType());
    }

    mIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
  }