Beispiel #1
0
  private void displayChatHeader(String displayName, String pictureUri) {
    LinphoneAddress lAddress;
    try {
      lAddress = LinphoneCoreFactory.instance().createLinphoneAddress(sipUri);
      Contact contact =
          ContactsManager.getInstance()
              .findContactWithAddress(getActivity().getContentResolver(), lAddress);
      if (contact != null) {
        LinphoneUtils.setImagePictureFromUri(
            getActivity(),
            contactPicture.getView(),
            contact.getPhotoUri(),
            contact.getThumbnailUri(),
            R.drawable.unknown_small);

      } else {
        contactPicture.setImageResource(R.drawable.unknown_small);
      }
    } catch (LinphoneCoreException e) {
      e.printStackTrace();
    }

    contactName.setTextSize(15);
    if (displayName == null
        && getResources().getBoolean(R.bool.only_display_username_if_unknown)
        && LinphoneUtils.isSipAddress(sipUri)) {
      contactName.setText(LinphoneUtils.getUsernameFromAddress(sipUri));
    } else if (displayName == null) {
      contactName.setText(sipUri);
    } else {
      contactName.setText(displayName);
    }
  }
 @Override
 public void onClick(View v) {
   if (LinphoneActivity.isInstanciated()) {
     LinphoneActivity.instance()
         .setAddresGoToDialerAndCall(
             v.getTag().toString(), contact.getName(), contact.getPhotoUri());
   }
 }
  public void displayHistoryDetail(String sipUri, LinphoneCallLog log) {
    LinphoneAddress lAddress;
    try {
      lAddress = LinphoneCoreFactory.instance().createLinphoneAddress(sipUri);
    } catch (LinphoneCoreException e) {
      Log.e("Cannot display history details", e);
      return;
    }
    Contact c =
        ContactsManager.getInstance().findContactWithAddress(getContentResolver(), lAddress);

    String displayName = c != null ? c.getName() : null;
    String pictureUri = c != null && c.getPhotoUri() != null ? c.getPhotoUri().toString() : null;

    String status;
    if (log.getDirection() == CallDirection.Outgoing) {
      status = "Outgoing";
    } else {
      if (log.getStatus() == CallStatus.Missed) {
        status = "Missed";
      } else {
        status = "Incoming";
      }
    }

    String callTime = secondsToDisplayableString(log.getCallDuration());
    String callDate = String.valueOf(log.getTimestamp());

    Fragment fragment2 = getSupportFragmentManager().findFragmentById(R.id.fragmentContainer2);
    if (fragment2 != null
        && fragment2.isVisible()
        && currentFragment == FragmentsAvailable.HISTORY_DETAIL) {
      HistoryDetailFragment historyDetailFragment = (HistoryDetailFragment) fragment2;
      historyDetailFragment.changeDisplayedHistory(
          sipUri, displayName, pictureUri, status, callTime, callDate);
    } else {
      Bundle extras = new Bundle();
      extras.putString("SipUri", sipUri);
      if (displayName != null) {
        extras.putString("DisplayName", displayName);
        extras.putString("PictureUri", pictureUri);
      }
      extras.putString("CallStatus", status);
      extras.putString("CallTime", callTime);
      extras.putString("CallDate", callDate);

      changeCurrentFragment(FragmentsAvailable.HISTORY_DETAIL, extras);
    }
  }
  private void displayCall(Resources resources, LinphoneCall call, int index) {
    String sipUri = call.getRemoteAddress().asStringUriOnly();
    LinphoneAddress lAddress;
    try {
      lAddress = LinphoneCoreFactory.instance().createLinphoneAddress(sipUri);
    } catch (LinphoneCoreException e) {
      Log.e("Incall activity cannot parse remote address", e);
      lAddress =
          LinphoneCoreFactory.instance().createLinphoneAddress("uknown", "unknown", "unkonown");
    }

    // Control Row
    LinearLayout callView =
        (LinearLayout) inflater.inflate(R.layout.active_call_control_row, container, false);
    callView.setId(index + 1);
    setContactName(callView, lAddress, sipUri, resources);
    displayCallStatusIconAndReturnCallPaused(callView, call);
    setRowBackground(callView, index);
    registerCallDurationTimer(callView, call);
    callsList.addView(callView);

    // Image Row
    LinearLayout imageView =
        (LinearLayout) inflater.inflate(R.layout.active_call_image_row, container, false);
    Contact contact =
        ContactsManager.getInstance()
            .findContactWithAddress(imageView.getContext().getContentResolver(), lAddress);
    if (contact != null) {
      displayOrHideContactPicture(
          imageView, contact.getPhotoUri(), contact.getThumbnailUri(), false);
    } else {
      displayOrHideContactPicture(imageView, null, null, false);
    }
    callsList.addView(imageView);

    callView.setTag(imageView);
    callView.setOnClickListener(
        new OnClickListener() {
          @Override
          public void onClick(View v) {
            if (v.getTag() != null) {
              View imageView = (View) v.getTag();
              if (imageView.getVisibility() == View.VISIBLE) imageView.setVisibility(View.GONE);
              else imageView.setVisibility(View.VISIBLE);
              callsList.invalidate();
            }
          }
        });
  }
  private void setContactName(
      LinearLayout callView, LinphoneAddress lAddress, String sipUri, Resources resources) {
    TextView contact = (TextView) callView.findViewById(R.id.contactNameOrNumber);

    Contact lContact =
        ContactsManager.getInstance()
            .findContactWithAddress(callView.getContext().getContentResolver(), lAddress);
    if (lContact == null) {
      if (resources.getBoolean(R.bool.only_display_username_if_unknown)
          && LinphoneUtils.isSipAddress(sipUri)) {
        contact.setText(lAddress.getUserName());
      } else {
        contact.setText(sipUri);
      }
    } else {
      contact.setText(lContact.getName());
    }
  }
 public void editContact(Contact contact) {
   if (getResources().getBoolean(R.bool.use_android_native_contact_edit_interface)) {
     Intent intent = Compatibility.prepareEditContactIntent(Integer.parseInt(contact.getID()));
     startActivity(intent);
   } else {
     Bundle extras = new Bundle();
     extras.putSerializable("Contact", contact);
     changeCurrentFragment(FragmentsAvailable.EDIT_CONTACT, extras);
   }
 }
  @Override
  public void onResume() {
    super.onResume();

    if (LinphoneActivity.isInstanciated()) {
      LinphoneActivity.instance().selectMenu(FragmentsAvailable.CONTACT);

      if (getResources().getBoolean(R.bool.show_statusbar_only_on_dialer)) {
        LinphoneActivity.instance().hideStatusBar();
      }
    }

    contact.refresh(getActivity().getContentResolver());
    if (contact.getName() == null || contact.getName().equals("")) {
      // Contact has been deleted, return
      LinphoneActivity.instance().displayContacts(false);
    }
    displayContact(inflater, view);
  }
  public void displayChat(String sipUri) {
    if (getResources().getBoolean(R.bool.disable_chat)) {
      return;
    }

    LinphoneAddress lAddress;
    try {
      lAddress = LinphoneCoreFactory.instance().createLinphoneAddress(sipUri);
    } catch (LinphoneCoreException e) {
      Log.e("Cannot display chat", e);
      return;
    }
    Contact contact =
        ContactsManager.getInstance().findContactWithAddress(getContentResolver(), lAddress);
    String displayName = contact != null ? contact.getName() : null;

    String pictureUri = null;
    String thumbnailUri = null;
    if (contact != null && contact.getPhotoUri() != null) {
      pictureUri = contact.getPhotoUri().toString();
      thumbnailUri = contact.getThumbnailUri().toString();
    }

    if (isTablet()) {
      if (currentFragment == FragmentsAvailable.CHATLIST
          || currentFragment == FragmentsAvailable.CHAT) {
        Fragment fragment2 = getSupportFragmentManager().findFragmentById(R.id.fragmentContainer2);
        if (fragment2 != null
            && fragment2.isVisible()
            && currentFragment == FragmentsAvailable.CHAT) {
          ChatFragment chatFragment = (ChatFragment) fragment2;
          chatFragment.changeDisplayedChat(sipUri, displayName, pictureUri);
        } else {
          Bundle extras = new Bundle();
          extras.putString("SipUri", sipUri);
          if (contact != null) {
            extras.putString("DisplayName", displayName);
            extras.putString("PictureUri", pictureUri);
            extras.putString("ThumbnailUri", thumbnailUri);
          }
          changeCurrentFragment(FragmentsAvailable.CHAT, extras);
        }
      } else {
        changeCurrentFragment(FragmentsAvailable.CHATLIST, null);
        displayChat(sipUri);
      }
      if (messageListFragment != null && messageListFragment.isVisible()) {
        ((ChatListFragment) messageListFragment).refresh();
      }
    } else {
      Intent intent = new Intent(this, ChatActivity.class);
      intent.putExtra("SipUri", sipUri);
      if (contact != null) {
        intent.putExtra("DisplayName", contact.getName());
        intent.putExtra("PictureUri", pictureUri);
        intent.putExtra("ThumbnailUri", thumbnailUri);
      }
      startOrientationSensor();
      startActivityForResult(intent, CHAT_ACTIVITY);
    }

    LinphoneService.instance().resetMessageNotifCount();
    LinphoneService.instance().removeMessageNotification();
    displayMissedChats(getChatStorage().getUnreadMessageCount());
  }
  private void displayContact(LayoutInflater inflater, View view) {
    AvatarWithShadow contactPicture = (AvatarWithShadow) view.findViewById(R.id.contactPicture);
    if (contact.getPhotoUri() != null) {
      InputStream input =
          Compatibility.getContactPictureInputStream(
              LinphoneActivity.instance().getContentResolver(), contact.getID());
      contactPicture.setImageBitmap(BitmapFactory.decodeStream(input));
    } else {
      contactPicture.setImageResource(R.drawable.unknown_small);
    }

    TextView contactName = (TextView) view.findViewById(R.id.contactName);
    contactName.setText(contact.getName());

    TableLayout controls = (TableLayout) view.findViewById(R.id.controls);
    controls.removeAllViews();
    for (String numberOrAddress : contact.getNumerosOrAddresses()) {
      View v = inflater.inflate(R.layout.contact_control_row, null);

      String displayednumberOrAddress = numberOrAddress;
      if (numberOrAddress.startsWith("sip:")) {
        displayednumberOrAddress = displayednumberOrAddress.replace("sip:", "");
      }

      TextView tv = (TextView) v.findViewById(R.id.numeroOrAddress);
      tv.setText(displayednumberOrAddress);
      tv.setSelected(true);

      if (!displayChatAddressOnly) {
        v.findViewById(R.id.dial).setOnClickListener(dialListener);
        v.findViewById(R.id.dial).setTag(displayednumberOrAddress);
      } else {
        v.findViewById(R.id.dial).setVisibility(View.GONE);
      }

      v.findViewById(R.id.start_chat).setOnClickListener(chatListener);
      LinphoneProxyConfig lpc = LinphoneManager.getLc().getDefaultProxyConfig();
      if (lpc != null) {
        if (!displayednumberOrAddress.startsWith("sip:")) {
          numberOrAddress = "sip:" + displayednumberOrAddress;
        }

        String tag = numberOrAddress;
        if (!numberOrAddress.contains("@")) {
          tag = numberOrAddress + "@" + lpc.getDomain();
        }
        v.findViewById(R.id.start_chat).setTag(tag);
      } else {
        v.findViewById(R.id.start_chat).setTag(numberOrAddress);
      }

      final String finalNumberOrAddress = numberOrAddress;
      ImageView friend = (ImageView) v.findViewById(R.id.addFriend);
      if (getResources().getBoolean(R.bool.enable_linphone_friends) && !displayChatAddressOnly) {
        friend.setVisibility(View.VISIBLE);

        boolean isAlreadyAFriend =
            LinphoneManager.getLc().findFriendByAddress(finalNumberOrAddress) != null;
        if (!isAlreadyAFriend) {
          friend.setImageResource(R.drawable.friend_add);
          friend.setOnClickListener(
              new OnClickListener() {
                @Override
                public void onClick(View v) {
                  if (LinphoneActivity.instance().newFriend(contact, finalNumberOrAddress)) {
                    displayContact(ContactFragment.this.inflater, ContactFragment.this.view);
                  }
                }
              });
        } else {
          friend.setImageResource(R.drawable.friend_remove);
          friend.setOnClickListener(
              new OnClickListener() {
                @Override
                public void onClick(View v) {
                  if (LinphoneActivity.instance().removeFriend(contact, finalNumberOrAddress)) {
                    displayContact(ContactFragment.this.inflater, ContactFragment.this.view);
                  }
                }
              });
        }
      }

      if (getResources().getBoolean(R.bool.disable_chat)) {
        v.findViewById(R.id.start_chat).setVisibility(View.GONE);
      }

      controls.addView(v);
    }
  }
 public void changeDisplayedContact(Contact newContact) {
   contact = newContact;
   contact.refresh(getActivity().getContentResolver());
   displayContact(inflater, view);
 }