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();
            }
          }
        });
  }
  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);
    }
  }
  public void sendLogs(Context context, String info) {
    final String appName = context.getString(R.string.app_name);

    Intent i = new Intent(Intent.ACTION_SEND);
    i.putExtra(
        Intent.EXTRA_EMAIL, new String[] {context.getString(R.string.about_bugreport_email)});
    i.putExtra(Intent.EXTRA_SUBJECT, appName + " Logs");
    i.putExtra(Intent.EXTRA_TEXT, info);
    i.setType("application/zip");

    try {
      startActivity(Intent.createChooser(i, "Send mail..."));
    } catch (android.content.ActivityNotFoundException ex) {
      Log.e(ex);
    }
  }
 public void setUpnpEnabled(boolean enabled) {
   if (enabled) {
     if (isIceEnabled()) {
       Log.e("Cannot have both ice and upnp enabled, disabling upnp");
     } else {
       getLc().setFirewallPolicy(FirewallPolicy.UseUpnp);
     }
   } else {
     String stun = getStunServer();
     if (stun != null && stun.length() > 0) {
       getLc().setFirewallPolicy(FirewallPolicy.UseStun);
     } else {
       getLc().setFirewallPolicy(FirewallPolicy.NoFirewall);
     }
   }
 }
  public void switchCamera() {
    try {
      int videoDeviceId = LinphoneManager.getLc().getVideoDevice();
      videoDeviceId = (videoDeviceId + 1) % AndroidCameraConfiguration.retrieveCameras().length;
      LinphoneManager.getLc().setVideoDevice(videoDeviceId);
      CallManager.getInstance().updateCall();

      // previous call will cause graph reconstruction -> regive preview
      // window
      if (mCaptureView != null) {
        LinphoneManager.getLc().setPreviewWindow(mCaptureView);
      }
    } catch (ArithmeticException ae) {
      Log.e("Cannot swtich camera : no camera");
    }
  }
Exemple #6
0
  @Override
  public void onLinphoneChatMessageFileTransferReceived(
      LinphoneChatMessage msg, LinphoneContent content, LinphoneBuffer buffer) {
    if (mDownloadedImageStream == null) {
      mDownloadedImageStream = new ByteArrayOutputStream();
      mDownloadedImageStreamSize = 0;
    }

    if (buffer != null && buffer.getSize() > 0) {
      try {
        mDownloadedImageStream.write(buffer.getContent());
        mDownloadedImageStreamSize += buffer.getSize();
      } catch (IOException e) {
        Log.e(e);
      }
    }
  }
Exemple #7
0
  private void sendImageMessage(String path) {
    LinphoneCore lc = LinphoneManager.getLcIfManagerNotDestroyedOrNull();
    boolean isNetworkReachable = lc == null ? false : lc.isNetworkReachable();

    if (chatRoom != null && path != null && path.length() > 0 && isNetworkReachable) {
      Bitmap bm = BitmapFactory.decodeFile(path);
      if (bm != null) {
        FileUploadPrepareTask task = new FileUploadPrepareTask(getActivity(), path);
        task.execute(bm);
      } else {
        Log.e("Error, bitmap factory can't read " + path);
      }
    } else if (!isNetworkReachable && LinphoneActivity.isInstanciated()) {
      LinphoneActivity.instance()
          .displayCustomToast(getString(R.string.error_network_unreachable), Toast.LENGTH_LONG);
    }
  }
  private void refreshInCallActions() {
    try {
      if (isSpeakerEnabled) {
        speaker.setBackgroundResource(R.drawable.speaker_on);
        routeSpeaker.setBackgroundResource(R.drawable.route_speaker_on);
        routeReceiver.setBackgroundResource(R.drawable.route_receiver_off);
        routeBluetooth.setBackgroundResource(R.drawable.route_bluetooth_off);
      } else {
        speaker.setBackgroundResource(R.drawable.speaker_off);
        routeSpeaker.setBackgroundResource(R.drawable.route_speaker_off);
        if (BluetoothManager.getInstance().isUsingBluetoothAudioRoute()) {
          routeReceiver.setBackgroundResource(R.drawable.route_receiver_off);
          routeBluetooth.setBackgroundResource(R.drawable.route_bluetooth_on);
        } else {
          routeReceiver.setBackgroundResource(R.drawable.route_receiver_on);
          routeBluetooth.setBackgroundResource(R.drawable.route_bluetooth_off);
        }
      }
    } catch (NullPointerException npe) {
      Log.e("Bluetooth: Audio routes menu disabled on tablets for now (4)");
    }

    if (isMicMuted) {
      micro.setBackgroundResource(R.drawable.micro_off);
    } else {
      micro.setBackgroundResource(R.drawable.micro_on);
    }

    if (LinphoneManager.getLc().getCallsNb() > 1) {
      conference.setVisibility(View.VISIBLE);
      pause.setVisibility(View.GONE);
    } else {
      conference.setVisibility(View.GONE);
      pause.setVisibility(View.VISIBLE);

      List<LinphoneCall> pausedCalls =
          LinphoneUtils.getCallsInState(LinphoneManager.getLc(), Arrays.asList(State.Paused));
      if (pausedCalls.size() == 1) {
        pause.setBackgroundResource(R.drawable.pause_on);
      } else {
        pause.setBackgroundResource(R.drawable.pause_off);
      }
    }
  }
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    if (getArguments() != null && getArguments().getSerializable("About") != null) {
      about = (FragmentsAvailable) getArguments().getSerializable("About");
    }

    View view = inflater.inflate(R.layout.about, container, false);

    TextView aboutText = (TextView) view.findViewById(R.id.AboutText);
    try {
      aboutText.setText(
          String.format(
              getString(R.string.about_text),
              getActivity()
                  .getPackageManager()
                  .getPackageInfo(getActivity().getPackageName(), 0)
                  .versionName));
    } catch (NameNotFoundException e) {
      Log.e(e, "cannot get version name");
    }

    sendLogButton = view.findViewById(R.id.send_log);
    sendLogButton.setOnClickListener(this);
    sendLogButton.setVisibility(
        LinphonePreferences.instance().isDebugEnabled() ? View.VISIBLE : View.GONE);

    resetLogButton = view.findViewById(R.id.reset_log);
    resetLogButton.setOnClickListener(this);
    resetLogButton.setVisibility(
        LinphonePreferences.instance().isDebugEnabled() ? View.VISIBLE : View.GONE);

    exitButton = view.findViewById(R.id.exit);
    exitButton.setOnClickListener(this);
    exitButton.setVisibility(View.VISIBLE);

    return view;
  }
Exemple #10
0
 @Override
 public void onLinphoneChatMessageFileTransferSent(
     LinphoneChatMessage msg,
     LinphoneContent content,
     int offset,
     int size,
     LinphoneBuffer bufferToFill) {
   if (mUploadingImageStream != null && size > 0) {
     byte[] data = new byte[size];
     int read = mUploadingImageStream.read(data, 0, size);
     if (read > 0) {
       bufferToFill.setContent(data);
       bufferToFill.setSize(read);
     } else {
       Log.e(
           "Error, upload task asking for more bytes("
               + size
               + ") than available ("
               + mUploadingImageStream.available()
               + ")");
     }
   }
 }
  // Added by me
  public void createGroupChat(String groupName, String[] groupMembers, int groupSize) {
    // Intent intent = new Intent(this, ChatActivity.class);
    // intent.putExtra("GroupName", groupName);
    // intent.putExtra("GroupMembers", groupMembers);
    // intent.putExtra("GroupSize", groupSize);
    // intent.putExtra("ChatType", 1);

    LinphoneCore lc = LinphoneManager.getLcIfManagerNotDestroyedOrNull();
    if (lc != null) {
      LinphoneChatRoom chatRoom = null;
      chatRoom = lc.getOrCreateGroupChatRoom(groupName, groupMembers, groupSize, 0, 0);

      if (chatRoom != null) {
        LinphoneAddress la = chatRoom.getPeerAddress();

        String sipUri = la.asStringUriOnly();
        String displayName = la.getDisplayName();
        String addrStr = la.asString();

        // intent.putExtra("SipUri", sipUri);
        // intent.putExtra("DisplayName", displayName);

        LinphoneProxyConfig pc = lc.getDefaultProxyConfig();
        String identity = pc.getIdentity();

        String id = "";
        try {
          la = LinphoneCoreFactory.instance().createLinphoneAddress(identity);
          id = la.getUserName();
        } catch (LinphoneCoreException e) {
          Log.e("Cannot display chat", e);
          // return;
        }

        String message = id + " created group " + groupName;
        LinphoneChatMessage msg = chatRoom.createLinphoneGroupChatMessage(message);
        chatRoom.sendGroupChatMessage(msg);
        // chatRoom.sendGroupMessage(message);

        onMessageSent(sipUri, message);

        goToChatList();

        /*String toDisplay = "Display Name: " + displayName;
        toDisplay += "\nSIP URI: " + sipUri;
        toDisplay += "\nGroup Name: " + chatRoom.getGroupName();
        toDisplay += "\nGroup Address: " + addrStr;
        displayCustomToast(toDisplay, Toast.LENGTH_SHORT);*/
      }

      // LinphoneProxyConfig pc = lc.getDefaultProxyConfig();
      // String identity = pc.getIdentity();
      // displayCustomToast("I am: " + identity, Toast.LENGTH_SHORT);
    }

    /*startOrientationSensor();
    startActivityForResult(intent, CHAT_ACTIVITY);

    LinphoneService.instance().resetMessageNotifCount();
    LinphoneService.instance().removeMessageNotification();
    displayMissedChats(getChatStorage().getUnreadMessageCount());*/
  }
  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());
  }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    if (isTablet() && getRequestedOrientation() != ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE) {
      setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
    } else if (!isTablet()
        && getRequestedOrientation() != ActivityInfo.SCREEN_ORIENTATION_PORTRAIT) {
      setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
    }

    if (!LinphoneManager.isInstanciated()) {
      Log.e("No service running: avoid crash by starting the launcher", this.getClass().getName());
      // super.onCreate called earlier
      finish();
      startActivity(getIntent().setClass(this, LinphoneLauncherActivity.class));
      return;
    }

    boolean useFirstLoginActivity =
        getResources().getBoolean(R.bool.display_account_wizard_at_first_start);
    if (LinphonePreferences.instance().isProvisioningLoginViewEnabled()) {
      Intent wizard = new Intent();
      wizard.setClass(this, RemoteProvisioningLoginActivity.class);
      wizard.putExtra("Domain", LinphoneManager.getInstance().wizardLoginViewDomain);
      startActivityForResult(wizard, REMOTE_PROVISIONING_LOGIN_ACTIVITY);
    } else if (useFirstLoginActivity && LinphonePreferences.instance().isFirstLaunch()) {
      if (LinphonePreferences.instance().getAccountCount() > 0) {
        LinphonePreferences.instance().firstLaunchSuccessful();
      } else {
        startActivityForResult(
            new Intent().setClass(this, SetupActivity.class), FIRST_LOGIN_ACTIVITY);
      }
    }

    if (getResources().getBoolean(R.bool.use_linphone_tag)) {
      ContactsManager.getInstance()
          .initializeSyncAccount(getApplicationContext(), getContentResolver());
    } else {
      ContactsManager.getInstance()
          .initializeContactManager(getApplicationContext(), getContentResolver());
    }

    if (!LinphonePreferences.instance().isContactsMigrationDone()) {
      ContactsManager.getInstance().migrateContacts();
      LinphonePreferences.instance().contactsMigrationDone();
    }

    setContentView(R.layout.main);
    instance = this;
    fragmentsHistory = new ArrayList<FragmentsAvailable>();
    initButtons();

    currentFragment = nextFragment = FragmentsAvailable.DIALER;
    fragmentsHistory.add(currentFragment);
    if (savedInstanceState == null) {
      if (findViewById(R.id.fragmentContainer) != null) {
        dialerFragment = new DialerFragment();
        dialerFragment.setArguments(getIntent().getExtras());
        getSupportFragmentManager()
            .beginTransaction()
            .add(R.id.fragmentContainer, dialerFragment, currentFragment.toString())
            .commit();
        selectMenu(FragmentsAvailable.DIALER);
      }
    }

    mListener =
        new LinphoneCoreListenerBase() {
          @Override
          public void messageReceived(
              LinphoneCore lc, LinphoneChatRoom cr, LinphoneChatMessage message) {
            if (!displayChatMessageNotification(message.getFrom().asStringUriOnly())) {
              cr.markAsRead();
            }
            displayMissedChats(getChatStorage().getUnreadMessageCount());
            if (messageListFragment != null && messageListFragment.isVisible()) {
              ((ChatListFragment) messageListFragment).refresh();
            }
          }

          @Override
          public void registrationState(
              LinphoneCore lc,
              LinphoneProxyConfig proxy,
              LinphoneCore.RegistrationState state,
              String smessage) {
            if (state.equals(RegistrationState.RegistrationCleared)) {
              if (lc != null) {
                LinphoneAuthInfo authInfo =
                    lc.findAuthInfo(proxy.getIdentity(), proxy.getRealm(), proxy.getDomain());
                if (authInfo != null) lc.removeAuthInfo(authInfo);
              }
            }
          }

          @Override
          public void callState(
              LinphoneCore lc, LinphoneCall call, LinphoneCall.State state, String message) {
            if (state == State.IncomingReceived) {
              startActivity(new Intent(LinphoneActivity.instance(), IncomingCallActivity.class));
            } else if (state == State.OutgoingInit) {
              if (call.getCurrentParamsCopy().getVideoEnabled()) {
                startVideoActivity(call);
              } else {
                startIncallActivity(call);
              }
            } else if (state == State.CallEnd
                || state == State.Error
                || state == State.CallReleased) {
              // Convert LinphoneCore message for internalization
              if (message != null && message.equals("Call declined.")) {
                displayCustomToast(getString(R.string.error_call_declined), Toast.LENGTH_LONG);
              } else if (message != null && message.equals("Not Found")) {
                displayCustomToast(getString(R.string.error_user_not_found), Toast.LENGTH_LONG);
              } else if (message != null && message.equals("Unsupported media type")) {
                displayCustomToast(getString(R.string.error_incompatible_media), Toast.LENGTH_LONG);
              } else if (message != null && state == State.Error) {
                displayCustomToast(
                    getString(R.string.error_unknown) + " - " + message, Toast.LENGTH_LONG);
              }
              resetClassicMenuLayoutAndGoBackToCallIfStillRunning();
            }

            int missedCalls = LinphoneManager.getLc().getMissedCallsCount();
            displayMissedCalls(missedCalls);
          }
        };

    LinphoneCore lc = LinphoneManager.getLcIfManagerNotDestroyedOrNull();
    if (lc != null) {
      lc.addListener(mListener);
    }

    int missedCalls = LinphoneManager.getLc().getMissedCallsCount();
    displayMissedCalls(missedCalls);

    int rotation = getWindowManager().getDefaultDisplay().getRotation();
    switch (rotation) {
      case Surface.ROTATION_0:
        rotation = 0;
        break;
      case Surface.ROTATION_90:
        rotation = 90;
        break;
      case Surface.ROTATION_180:
        rotation = 180;
        break;
      case Surface.ROTATION_270:
        rotation = 270;
        break;
    }

    LinphoneManager.getLc().setDeviceRotation(rotation);
    mAlwaysChangingPhoneAngle = rotation;

    updateAnimationsState();
  }
  private void initUI() {
    inflater = LayoutInflater.from(this);
    container = (ViewGroup) findViewById(R.id.topLayout);
    callsList = (TableLayout) findViewById(R.id.calls);

    micro = (TextView) findViewById(R.id.micro);
    micro.setOnClickListener(this);
    //		micro.setEnabled(false);
    speaker = (TextView) findViewById(R.id.speaker);
    speaker.setOnClickListener(this);
    if (isTablet()) {
      speaker.setEnabled(false);
    }
    //		speaker.setEnabled(false);
    addCall = (TextView) findViewById(R.id.addCall);
    addCall.setOnClickListener(this);
    addCall.setEnabled(false);
    transfer = (TextView) findViewById(R.id.transfer);
    transfer.setOnClickListener(this);
    transfer.setEnabled(false);
    options = (TextView) findViewById(R.id.options);
    options.setOnClickListener(this);
    options.setEnabled(false);
    pause = (TextView) findViewById(R.id.pause);
    pause.setOnClickListener(this);
    pause.setEnabled(false);
    hangUp = (TextView) findViewById(R.id.hangUp);
    hangUp.setOnClickListener(this);
    conference = (TextView) findViewById(R.id.conference);
    conference.setOnClickListener(this);
    dialer = (TextView) findViewById(R.id.dialer);
    dialer.setOnClickListener(this);
    dialer.setEnabled(false);
    numpad = (Numpad) findViewById(R.id.numpad);

    try {
      routeLayout = (LinearLayout) findViewById(R.id.routesLayout);
      audioRoute = (TextView) findViewById(R.id.audioRoute);
      audioRoute.setOnClickListener(this);
      routeSpeaker = (TextView) findViewById(R.id.routeSpeaker);
      routeSpeaker.setOnClickListener(this);
      routeReceiver = (TextView) findViewById(R.id.routeReceiver);
      routeReceiver.setOnClickListener(this);
      routeBluetooth = (TextView) findViewById(R.id.routeBluetooth);
      routeBluetooth.setOnClickListener(this);
    } catch (NullPointerException npe) {
      Log.e("Bluetooth: Audio routes menu disabled on tablets for now (1)");
    }

    mControlsLayout = (ViewGroup) findViewById(R.id.menu);

    if (!isTransferAllowed) {
      addCall.setBackgroundResource(R.drawable.options_add_call);
    }

    if (!isAnimationDisabled) {
      slideInRightToLeft = AnimationUtils.loadAnimation(this, R.anim.slide_in_right_to_left);
      slideOutLeftToRight = AnimationUtils.loadAnimation(this, R.anim.slide_out_left_to_right);
      slideInBottomToTop = AnimationUtils.loadAnimation(this, R.anim.slide_in_bottom_to_top);
      slideInTopToBottom = AnimationUtils.loadAnimation(this, R.anim.slide_in_top_to_bottom);
      slideOutBottomToTop = AnimationUtils.loadAnimation(this, R.anim.slide_out_bottom_to_top);
      slideOutTopToBottom = AnimationUtils.loadAnimation(this, R.anim.slide_out_top_to_bottom);
    }

    if (BluetoothManager.getInstance().isBluetoothHeadsetAvailable()) {
      try {
        if (routeLayout != null) routeLayout.setVisibility(View.VISIBLE);
        audioRoute.setVisibility(View.VISIBLE);
        speaker.setVisibility(View.GONE);
      } catch (NullPointerException npe) {
        Log.e("Bluetooth: Audio routes menu disabled on tablets for now (2)");
      }
    } else {
      try {
        if (routeLayout != null) routeLayout.setVisibility(View.GONE);
        audioRoute.setVisibility(View.GONE);
        speaker.setVisibility(View.VISIBLE);
      } catch (NullPointerException npe) {
        Log.e("Bluetooth: Audio routes menu disabled on tablets for now (3)");
      }
    }

    LinphoneManager.getInstance().changeStatusToOnThePhone();
  }
Exemple #15
0
 @Override
 protected void onError(Context context, String errorId) {
   Log.e("Error while registering push notification : " + errorId);
 }
    public View getView(int position, View convertView, ViewGroup parent) {
      View view = null;

      if (convertView != null) {
        view = convertView;
      } else {
        view = mInflater.inflate(R.layout.chatlist_cell, parent, false);
      }
      String contact;
      boolean isDraft = false;
      if (position >= mDrafts.size()) {
        contact = mConversations.get(position - mDrafts.size());
      } else {
        contact = mDrafts.get(position);
        isDraft = true;
      }
      view.setTag(contact);
      int unreadMessagesCount =
          LinphoneActivity.instance().getChatStorage().getUnreadMessageCount(contact);

      LinphoneAddress address;
      try {
        address = LinphoneCoreFactory.instance().createLinphoneAddress(contact);
      } catch (LinphoneCoreException e) {
        Log.e("Chat view cannot parse address", e);
        return view;
      }
      LinphoneUtils.findUriPictureOfContactAndSetDisplayName(
          address, view.getContext().getContentResolver());

      String message = "";
      if (useNativeAPI) {
        LinphoneChatRoom chatRoom = LinphoneManager.getLc().getOrCreateChatRoom(contact);
        LinphoneChatMessage[] history = chatRoom.getHistory(20);
        if (history != null && history.length > 0) {
          for (int i = history.length - 1; i >= 0; i--) {
            LinphoneChatMessage msg = history[i];
            if (msg.getText() != null && msg.getText().length() > 0) {
              message = msg.getText();
              break;
            }
          }
        }
      } else {
        List<ChatMessage> messages = LinphoneActivity.instance().getChatMessages(contact);
        if (messages != null && messages.size() > 0) {
          int iterator = messages.size() - 1;
          ChatMessage lastMessage = null;

          while (iterator >= 0) {
            lastMessage = messages.get(iterator);
            if (lastMessage.getMessage() == null) {
              iterator--;
            } else {
              iterator = -1;
            }
          }
          message =
              (lastMessage == null || lastMessage.getMessage() == null)
                  ? ""
                  : lastMessage.getMessage();
        }
      }
      TextView lastMessageView = (TextView) view.findViewById(R.id.lastMessage);
      lastMessageView.setText(message);

      TextView sipUri = (TextView) view.findViewById(R.id.sipUri);
      sipUri.setSelected(true); // For animation

      if (getResources().getBoolean(R.bool.only_display_username_if_unknown)
          && address.getDisplayName() != null
          && LinphoneUtils.isSipAddress(address.getDisplayName())) {
        address.setDisplayName(LinphoneUtils.getUsernameFromAddress(address.getDisplayName()));
      } else if (getResources().getBoolean(R.bool.only_display_username_if_unknown)
          && LinphoneUtils.isSipAddress(contact)) {
        contact = LinphoneUtils.getUsernameFromAddress(contact);
      }

      sipUri.setText(address.getDisplayName() == null ? contact : address.getDisplayName());
      if (isDraft) {
        view.findViewById(R.id.draft).setVisibility(View.VISIBLE);
      }

      ImageView delete = (ImageView) view.findViewById(R.id.delete);
      TextView unreadMessages = (TextView) view.findViewById(R.id.unreadMessages);

      if (unreadMessagesCount > 0) {
        unreadMessages.setVisibility(View.VISIBLE);
        unreadMessages.setText(String.valueOf(unreadMessagesCount));
      } else {
        unreadMessages.setVisibility(View.GONE);
      }

      if (isEditMode) {
        delete.setVisibility(View.VISIBLE);
      } else {
        delete.setVisibility(View.INVISIBLE);
      }

      return view;
    }