예제 #1
0
  public short getEngineContactIdViaNumber(String number) {
    String formatNumber = null;

    if (TextUtils.isEmpty(number)) {
      NmsLog.error(TAG, "number2engineId. number is empty!");
      return -1;
    }
    if (number.contains(",")) { // for broadcast
      formatNumber = number;
    } else {
      if (number.length() > NmsCustomUIConfig.PHONENUM_MAX_LENGTH
          && !NmsGroupChatContact.isGroupChatContactNumber(number)) {
        NmsLog.error(TAG, "number2engineId. number is too long!");
        return -1;
      }

      if (!NmsCommonUtils.isPhoneNumberValid(number)) {
        NmsLog.error(TAG, "number2engineId. number(" + number + ") is invalid!");
        return -1;
      }

      formatNumber = NmsCommonUtils.nmsGetStandardPhoneNum(number);
      if (TextUtils.isEmpty(formatNumber)) {
        NmsLog.error(TAG, "number2engineId. formatNumber is invalid!");
      }
    }

    return (short) engineadapter.get().nmsUIGetContactId(formatNumber);
  }
예제 #2
0
  public String getSystemNameViaSystemContactId(long systemContactId) {
    if (systemContactId <= 0) {
      NmsLog.error(TAG, "getSystemNameViaSystemContactId: sysContactId is invalid!");
      return null;
    }

    String result = "";

    Cursor cursor = null;
    try {
      cursor =
          NmsContentResolver.query(
              mContext.getContentResolver(),
              Contacts.CONTENT_URI,
              new String[] {Contacts.DISPLAY_NAME},
              Contacts._ID + "=?",
              new String[] {String.valueOf(systemContactId)},
              null);
      if (cursor != null && cursor.moveToFirst()) {
        result = cursor.getString(cursor.getColumnIndex(Contacts.DISPLAY_NAME));
      }
    } catch (Exception e) {
      NmsLog.nmsPrintStackTrace(e);
    } finally {
      if (cursor != null) {
        cursor.close();
        cursor = null;
      }
    }

    return result == null ? "" : result;
  }
예제 #3
0
  public long getSystemContactIdViaContactUri(Uri uri) {
    if (uri == null) {
      NmsLog.error(TAG, "getSystemContactIdViaContactUri is invalid!");
      return -1;
    }

    long result = -1;
    Cursor cursor = null;
    try {
      cursor =
          NmsContentResolver.query(
              mContext.getContentResolver(), uri, new String[] {Contacts._ID}, null, null, null);
      if (cursor != null && cursor.moveToFirst()) {
        result = cursor.getLong(cursor.getColumnIndex(Contacts._ID));
      }
    } catch (Exception e) {
      NmsLog.nmsPrintStackTrace(e);
    } finally {
      if (cursor != null) {
        cursor.close();
        cursor = null;
      }
    }
    return result;
  }
  public void selectGroupMembers(String[] contactId) {
    List<String> members = new ArrayList<String>();
    NmsGroupChatContact groupContact = (NmsGroupChatContact) contact;
    short groupId = groupContact.getId();
    if (contactId != null) {
      NmsLog.trace(Tag, "Add group members to group chat, the groupId:" + groupId);
      if (groupId > 0) {
        for (String id : contactId) {
          short engineContactId = Short.valueOf(id);
          NmsContact contact = NmsIpMessageApiNative.nmsGetContactInfoViaEngineId(engineContactId);
          if (contact != null) {
            members.add(contact.getNumber());
          } else {
            NmsLog.error(Tag, "can't get contact info. engineContactId:" + id);
          }
        }

        boolean ret = NmsIpMessageApiNative.nmsAddMembersToGroup(groupId, members);
        if (ret) {
          for (String id : contactId) {
            short engineContactId = Short.valueOf(id);
            NmsContact contact =
                NmsIpMessageApiNative.nmsGetContactInfoViaEngineId(engineContactId);
            if (contact != null) {
              memberList.add(contact);
            } else {
              NmsLog.error(Tag, "can't get contact info. engineContactId:" + id);
            }
          }
          Toast.makeText(mContext, R.string.STR_NMS_ADD_GROUP_MEMBER_SUCCESS, Toast.LENGTH_SHORT)
              .show();
        } else {
          Toast.makeText(mContext, R.string.STR_NMS_ADD_GROUP_MEMBER_FAILED, Toast.LENGTH_SHORT)
              .show();
        }
      } else {
        for (String id : contactId) {
          short engineContactId = Short.valueOf(id);
          NmsContact contact = NmsIpMessageApiNative.nmsGetContactInfoViaEngineId(engineContactId);
          if (contact != null) {
            memberList.add(contact);
          } else {
            NmsLog.error(Tag, "can't get contact info. engineContactId:" + id);
          }
        }
      }
    }

    // if (GroupChatMode.VIEW == groupChatMode) {
    // buildViewGroupMembers();
    // }
  }
예제 #5
0
  public short getMyselfEngineContactIdViaSimId(int simId) {
    if (simId < 0) {
      NmsLog.error(TAG, "simId < 0.");
      return -1;
    }

    SNmsSimInfo simInfo = NmsIpMessageApiNative.nmsGetSimInfoViaSimId(simId);
    if (simInfo == null) {
      NmsLog.error(TAG, "simInfo is null.");
      return -1;
    }

    return getEngineContactIdViaNumber(simInfo.number);
  }
예제 #6
0
  public Bitmap getSystemAvatarViaNumber(String number) {
    if (TextUtils.isEmpty(number)) {
      NmsLog.error(TAG, "getSystemAvatarViaNumber. number is empty!");
      return null;
    }

    long systemContactId = getSystemContactIdViaNumber(number);
    if (systemContactId <= 0) {
      NmsLog.trace(TAG, "this number is not in System Contact. number:" + number);
      return null;
    }

    return getSystemAvatarViaSystemContactId(systemContactId);
  }
예제 #7
0
  public short getEngineContactIdViaSystemMsgId(long msgId) {
    if (msgId <= 0) {
      NmsLog.error(TAG, "msgId2engineId. msgId is invalid!");
      return -1;
    }

    long threadId = NmsSMSMMSManager.getInstance(mContext).getThreadViaSysMsgId(msgId);
    if (threadId <= 0) {
      NmsLog.error(TAG, "msgId2engineId. threadId is invalid!");
      return -1;
    }

    return getEngineContactIdViaSystemThreadId(threadId);
  }
  public void buildGroupMembers(short[] contactId, boolean isAlive) {
    memberList.clear();

    if (isAlive) {
      NmsContact selfPerson = new NmsContact();
      selfPerson.setName(
          this.getResources().getText(R.string.STR_NMS_GROUP_MEMEBER_YOU).toString());
      selfPerson.setId(
          NmsContactApi.getInstance(mContext)
              .getMyselfEngineContactIdViaSimId(
                  (int) NmsPlatformAdapter.getInstance(mContext).getCurrentSimId()));

      memberList.add(selfPerson);
    }

    if (contactId != null) {
      for (short id : contactId) {
        NmsContact contact = NmsIpMessageApiNative.nmsGetContactInfoViaEngineId(id);
        if (contact != null) {
          memberList.add(contact);
        } else {
          NmsLog.error(Tag, "can't get contact info. engineContactId:" + id);
        }
      }
    }
  }
예제 #9
0
  public boolean isHissageNumber(String number) {
    if (TextUtils.isEmpty(number)) {
      NmsLog.error(TAG, "isHissageNumber. number is empty!");
      return false;
    }
    if (number.contains("@")) {
      return false;
    }

    String cutNumber = NmsCommonUtils.nmsGetStandardPhoneNum(number);
    if (TextUtils.isEmpty(cutNumber)) {
      NmsLog.warn(TAG, "isHisssageNumber. cutNumber is empty!");
    }

    return engineadapter.get().nmsUIGetIsHesineAccount(cutNumber) == 0 ? true : false;
  }
예제 #10
0
 public void nmsCheckDefaultSmsAppChanged() {
   try {
     mApiProviders.call(API_CONTENT_URI, FUNC_ID_nmsCheckDefaultSmsApp, null, null);
   } catch (Exception e) {
     NmsLog.nmsPrintStackTrace(e);
   }
 }
예제 #11
0
  public boolean nmsDeleteMsgFromImportantList(long[] msgIds) {
    if (msgIds == null || msgIds.length <= 0) {
      NmsLog.error(HissageTag.api, "nmsDeleteMsgFromImportantList param error.");
      return false;
    }
    Bundle param = new Bundle();
    param.putLongArray(FUNC_ID_nmsDeleteMsgFromImportantList + 1, msgIds);

    Bundle back =
        mApiProviders.call(API_CONTENT_URI, FUNC_ID_nmsDeleteMsgFromImportantList, null, param);
    if (back != null) {
      return back.getBoolean(FUNC_ID_nmsDeleteMsgFromImportantList);
    } else {
      NmsLog.error(HissageTag.api, "failed to delete msg from important list, return false");
      return false;
    }
  }
예제 #12
0
  private SystemContactSummary getSystemContactSummaryViaNumber(String number) {
    if (TextUtils.isEmpty(number)) {
      NmsLog.error(TAG, "getSystemContactSummaryViaNumber. number is empty!");
      return null;
    }

    String encodeNumber = Uri.encode(number);
    if (TextUtils.isEmpty(encodeNumber)) {
      NmsLog.error(TAG, "getSystemContactSummaryViaNumber. encodeNumber is empty!");
      return null;
    }

    SystemContactSummary result = null;
    Cursor cursor = null;
    try {
      Uri lookupUri = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI, encodeNumber);
      cursor =
          NmsContentResolver.query(
              mContext.getContentResolver(),
              lookupUri,
              new String[] {PhoneLookup._ID, PhoneLookup.DISPLAY_NAME, PhoneLookup.NUMBER},
              null,
              null,
              null);
      if (cursor != null && cursor.moveToFirst()) {
        result = new SystemContactSummary();
        result.contactId = cursor.getLong(cursor.getColumnIndex(PhoneLookup._ID));
        result.name = cursor.getString(cursor.getColumnIndex(PhoneLookup.DISPLAY_NAME));
        result.number =
            NmsCommonUtils.nmsGetStandardPhoneNum(
                cursor.getString(cursor.getColumnIndex(PhoneLookup.NUMBER)));
      }

    } catch (Exception e) {
      NmsLog.error(TAG, "number: " + number + ". encodeNumber: " + encodeNumber);
      NmsLog.nmsPrintStackTrace(e);
    } finally {
      if (cursor != null) {
        cursor.close();
        cursor = null;
      }
    }

    return result;
  }
예제 #13
0
 public void addPrivateContactsStatistics(int contacts) {
   try {
     Bundle param = new Bundle();
     param.putInt(FUNC_ID_addPrivateContactsStatistics + 1, contacts);
     mApiProviders.call(API_CONTENT_URI, FUNC_ID_addPrivateContactsStatistics, null, param);
   } catch (Exception e) {
     NmsLog.nmsPrintStackTrace(e);
   }
 }
예제 #14
0
 // M: Activation Statistics
 public void nmsAddActivatePromptStatistics(int type) {
   try {
     Bundle param = new Bundle();
     param.putInt(FUNC_ID_nmsAddActivatePromptStatistics + 1, type);
     mApiProviders.call(API_CONTENT_URI, FUNC_ID_nmsAddActivatePromptStatistics, null, param);
   } catch (Exception e) {
     NmsLog.nmsPrintStackTrace(e);
   }
 }
예제 #15
0
  public boolean isExistSystemContactViaEmail(String email) {
    if (TextUtils.isEmpty(email)) {
      NmsLog.error(TAG, "isExistSystemContactViaEmail. email is empty!");
      return false;
    }
    if (!email.contains("@")) {
      NmsLog.error(TAG, "isExistSystemContactViaEmail. email is invalid");
      return false;
    }

    String encodeEmail = Uri.encode(email);
    if (TextUtils.isEmpty(encodeEmail)) {
      NmsLog.error(TAG, "isExistSystemContactViaEmail. encodeEmail is empty!");
      return false;
    }
    Cursor cursor = null;
    boolean result = false;
    try {
      Uri lookupUri = Uri.withAppendedPath(Email.CONTENT_LOOKUP_URI, encodeEmail);
      cursor =
          NmsContentResolver.query(
              mContext.getContentResolver(),
              lookupUri,
              new String[] {Email.CONTACT_ID},
              null,
              null,
              null);
      if (cursor != null && cursor.moveToFirst()) {
        result = true;
      }

    } catch (Exception e) {
      NmsLog.error(TAG, "email: " + email + ". encodeEmail: " + encodeEmail);
      NmsLog.nmsPrintStackTrace(e);
    } finally {
      if (cursor != null) {
        cursor.close();
        cursor = null;
      }
    }

    return result;
  }
예제 #16
0
  public void nmsExitFromChatMode(String number) {
    Bundle param = new Bundle();
    param.putString(FUNC_ID_nmsExitFromChatMode + 1, number);

    try {
      mApiProviders.call(API_CONTENT_URI, FUNC_ID_nmsExitFromChatMode, null, param);
    } catch (Exception e) {
      NmsLog.nmsPrintStackTrace(e);
    }
  }
예제 #17
0
  public void nmsSaveChatHistory(long threadId[]) {
    Bundle param = new Bundle();
    param.putLongArray(FUNC_ID_nmsSaveChatHistory + 1, threadId);

    try {
      mApiProviders.call(API_CONTENT_URI, FUNC_ID_nmsSaveChatHistory, null, param);
    } catch (Exception e) {
      NmsLog.nmsPrintStackTrace(e);
    }
  }
예제 #18
0
  public void nmsReSendFailedMsg(long simId, long msgId) {
    try {
      Bundle param = new Bundle();
      param.putLong(FUNC_ID_nmsReSendFailedMsg + 1, simId);
      param.putLong(FUNC_ID_nmsReSendFailedMsg + 2, msgId);

      mApiProviders.call(API_CONTENT_URI, FUNC_ID_nmsReSendFailedMsg, null, param);
    } catch (Exception e) {
      NmsLog.nmsPrintStackTrace(e);
    }
  }
예제 #19
0
  public boolean isExistSystemContactViaNumber(String number) {
    if (TextUtils.isEmpty(number)) {
      NmsLog.error(TAG, "isExistSystemContact. number is empty!");
      return false;
    }

    if (getSystemContactSummaryViaNumber(number) != null) {
      return true;
    } else {
      return false;
    }
  }
예제 #20
0
  public void nmsDeleteIpMsg(final long[] ids, boolean delImportant, boolean isDelMsgInSmsDb) {
    if (ids == null || ids.length <= 0) {
      NmsLog.error(HissageTag.api, "nmsDeleteIpMsg param error.");
      return;
    }
    Bundle param = new Bundle();
    param.putLongArray(FUNC_ID_nmsDeleteIpMsg + 1, ids);
    param.putBoolean(FUNC_ID_nmsDeleteIpMsg + 2, delImportant);
    param.putBoolean(FUNC_ID_nmsDeleteIpMsg + 3, isDelMsgInSmsDb);

    mApiProviders.call(API_CONTENT_URI, FUNC_ID_nmsDeleteIpMsg, null, param);
  };
  @Override
  protected void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    requestWindowFeature(Window.FEATURE_NO_TITLE);

    mContext = this; // this.getApplicationContext();
    threadId = getIntent().getLongExtra("threadId", (long) -1);
    contactId = getIntent().getShortExtra("contactId", (short) -1);
    phoneNum = getIntent().getStringExtra("PHONE_NUM");

    int simId = (int) NmsPlatformAdapter.getInstance(this).getCurrentSimId();
    SNmsSimInfo info = NmsIpMessageApiNative.nmsGetSimInfoViaSimId(simId);
    if (info != null && info.status != NmsSimActivateStatus.NMS_SIM_STATUS_ACTIVATED) {
      isActive = false;
    }

    if (threadId > 0) {
      contact = NmsIpMessageApiNative.nmsGetContactInfoViaThreadId(threadId);
    } else {
      if (contactId > 0) {
        contact = NmsIpMessageApiNative.nmsGetContactInfoViaEngineId(contactId);
      } else {
        contact = NmsIpMessageApiNative.nmsGetContactInfoViaNumber(phoneNum);
      }
    }

    try {
      if (contact instanceof NmsGroupChatContact) {
        if (simId != ((NmsGroupChatContact) contact).getSimId()) {
          isActive = false;
        }

        initQuickGroupCard();
      } else {
        initQuickContactCard();
      }
    } catch (Exception e) {
      NmsLog.error(Tag, "onCreate got the execption: " + NmsLog.nmsGetStactTrace(e));
    }
  }
예제 #22
0
  public Bitmap getGroupChatContactAvatar(NmsGroupChatContact groupChatContact) {
    if (groupChatContact == null) {
      NmsLog.error(TAG, "groupChatContact is invalid!");
      return null;
    }

    ArrayList<Bitmap> bitmapList = new ArrayList<Bitmap>();

    short[] memberIds = groupChatContact.getMemberIds();

    if (memberIds != null) {
      for (int index = 0; index < memberIds.length && bitmapList.size() < 3; ++index) {
        Bitmap avatar = getAvatarViaEngineContactId(memberIds[index]);
        if (avatar != null) {
          bitmapList.add(avatar);
        }
      }
    } else {
      NmsLog.warn(TAG, "memberIds is null.");
    }

    if (bitmapList.size() < 3 && groupChatContact.isAlive()) {
      // myself bitmap
      Bitmap avatar = getMyselfAvatarViaSimId(groupChatContact.getSimId());
      if (avatar == null) {
        avatar = mDefaultBitmap;
      }
      bitmapList.add(avatar);
    }

    bitmapList =
        fillBitmapList(groupChatContact.getMemberCount(), bitmapList, mDefaultBitmap, mBlankBitmap);

    Bitmap result = null;
    if (bitmapList != null && bitmapList.size() == 3) {
      result = NmsCommonUtils.stitchBitmap(bitmapList.get(0), bitmapList.get(1), bitmapList.get(2));
    }

    return result;
  }
예제 #23
0
  public String getIpMessageSrvNumberName(String number) {
    NmsLog.trace(TAG, "getIpMessageSrvNumberName. number is " + number);
    if (TextUtils.isEmpty(number)) {
      NmsLog.error(TAG, "getIpMessageSrvNumberName. number is empty!");
      return null;
    }
    if (number.contains("@")) {
      NmsLog.error(TAG, "getIpMessageSrvNumberName. number is include contain @");
      return null;
    }

    short[] ids = engineadapter.get().nmsUIGetServiceContactList();
    if (ids != null) {
      for (int i = 0; i < ids.length; ++i) {
        NmsLog.trace(TAG, "hesine customer service id is " + ids[i]);
        NmsUIContact contact = getContactInfoViaEngineContactId(ids[i]);
        if (contact != null && contact.getNumberOrEmail().equals(number)) {
          NmsLog.trace(TAG, "hesine customer service id name " + contact.getName());
          return contact.getName();
        }
      }
    } else {
      NmsLog.trace(TAG, "hesine customer service num is null");
    }
    return null;
  }
예제 #24
0
  public boolean nmsDeleteContactFromSpamList(int[] engineContactIds) {
    Bundle param = new Bundle();
    if (engineContactIds == null || engineContactIds.length <= 0) {
      NmsLog.error(HissageTag.api, "The engineContactIds is null or the length is 0");
      return false;
    }
    short[] s = new short[engineContactIds.length];

    for (int i = 0; i < engineContactIds.length; i++) {
      s[i] = (short) engineContactIds[i];
    }
    param.putShortArray(FUNC_ID_nmsDeleteContactFromSpamList + 1, s);

    Bundle back =
        mApiProviders.call(API_CONTENT_URI, FUNC_ID_nmsDeleteContactFromSpamList, null, param);
    if (back != null) {
      return back.getBoolean(FUNC_ID_nmsDeleteContactFromSpamList);
    } else {
      NmsLog.error(HissageTag.api, "failed to delete contact from spam list, return false");
      return false;
    }
  }
예제 #25
0
  public int nmsDeleteDraftMsgInThread(long threadId) {
    try {
      Bundle param = new Bundle();
      param.putLong(FUNC_ID_nmsDeleteDraftMsgInThread + 1, threadId);
      Bundle back =
          mApiProviders.call(API_CONTENT_URI, FUNC_ID_nmsDeleteDraftMsgInThread, null, param);
      if (back != null) return back.getInt(FUNC_ID_nmsDeleteDraftMsgInThread, -1);
    } catch (Exception e) {
      NmsLog.nmsPrintStackTrace(e);
    }

    return 0;
  }
  @Override
  public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    NmsLog.trace(Tag, "Get activtiy result requestCode:" + requestCode);

    switch (requestCode) {
      case REQ_OUTSIDE_INVITE_MORE:
        {
          if (data != null) {
            String[] contactId = data.getStringArrayExtra(NmsContactSelectionActivity.CONTACTTAG);
            NmsLog.trace(Tag, "Invite more contacts and get contactId count:" + contactId.length);
            selectGroupMembers(contactId);
            chat();
          }
        }
        break;

      default:
        NmsLog.trace(Tag, "The unknown activity result");
        break;
    }
  }
예제 #27
0
 public boolean nmsIsIpMsgSendable(String number) {
   Bundle param = new Bundle();
   param.putString(FUNC_ID_nmsIsIpMsgSendable + 1, number);
   try {
     Bundle back = mApiProviders.call(API_CONTENT_URI, FUNC_ID_nmsIsIpMsgSendable, null, param);
     if (back != null) {
       return back.getBoolean(FUNC_ID_nmsIsIpMsgSendable);
     }
   } catch (Exception e) {
     NmsLog.nmsPrintStackTrace(e);
   }
   return false;
 }
예제 #28
0
  private Bitmap getMyselfAvatarViaSimId(int simId) {
    if (simId < 0) {
      NmsLog.error(TAG, "simId < 0..");
      return null;
    }

    SNmsSimInfo simInfo = NmsIpMessageApiNative.nmsGetSimInfoViaSimId(simId);
    if (simInfo == null) {
      NmsLog.error(TAG, "simInfo is null");
      return null;
    }

    Bitmap result = getSystemAvatarViaNumber(simInfo.number);
    if (result == null) {
      NmsProfileSettings userProfile = engineadapter.get().nmsUIGetUserInfoViaImsi(simInfo.imsi);
      if (userProfile != null) {
        result = userProfile.getProfileSettingsAvatar();
      }
    }

    return result;
  }
예제 #29
0
 public String nmsGetUnifyPhoneNumber(String number) {
   Bundle param = new Bundle();
   param.putString(FUNC_ID_getUnifyPhoneNumber + 1, number);
   try {
     Bundle back = mApiProviders.call(API_CONTENT_URI, FUNC_ID_getUnifyPhoneNumber, null, param);
     if (back != null) {
       return back.getString(FUNC_ID_getUnifyPhoneNumber);
     }
   } catch (Exception e) {
     NmsLog.nmsPrintStackTrace(e);
   }
   return null;
 }
예제 #30
0
 public boolean nmsNeedShowInviteDlg(long threadId) {
   Bundle param = new Bundle();
   param.putLong(FUNC_ID_nmsNeedShowInviteDlg + 1, threadId);
   try {
     Bundle back = mApiProviders.call(API_CONTENT_URI, FUNC_ID_nmsNeedShowInviteDlg, null, param);
     if (back != null) {
       return back.getBoolean(FUNC_ID_nmsNeedShowInviteDlg);
     }
   } catch (Exception e) {
     NmsLog.nmsPrintStackTrace(e);
   }
   return false;
 }