Example #1
0
  private int getStatusIconResource(
      LinphoneCore.RegistrationState state, boolean isDefaultAccount) {
    try {
      LinphoneCore lc = RedfoxManager.getLcIfManagerNotDestroyedOrNull();
      boolean defaultAccountConnected =
          (isDefaultAccount
                  && lc != null
                  && lc.getDefaultProxyConfig() != null
                  && lc.getDefaultProxyConfig().isRegistered())
              || !isDefaultAccount;
      if (state == RegistrationState.RegistrationOk && defaultAccountConnected) {
        return R.drawable.led_connected;
      } else if (state == RegistrationState.RegistrationProgress) {
        return R.drawable.led_inprogress;
      } else if (state == RegistrationState.RegistrationFailed) {
        return R.drawable.led_error;
      } else {
        return R.drawable.led_disconnected;
      }
    } catch (Exception e) {
      e.printStackTrace();
    }

    return R.drawable.led_disconnected;
  }
Example #2
0
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.status, container, false);

    statusText = (TextView) view.findViewById(R.id.status_text);
    statusLed = (ImageView) view.findViewById(R.id.status_led);

    mListener =
        new LinphoneCoreListenerBase() {
          @Override
          public void registrationState(
              final LinphoneCore lc,
              final LinphoneProxyConfig proxy,
              final LinphoneCore.RegistrationState state,
              String smessage) {
            if (!isAttached || !RedfoxService.isReady()) {
              return;
            }

            if (lc.getProxyConfigList() == null) {
              statusLed.setImageResource(R.drawable.led_disconnected);
              statusText.setText(getString(R.string.no_account));
            } else {
              statusLed.setVisibility(View.VISIBLE);
            }

            if (lc.getDefaultProxyConfig() != null && lc.getDefaultProxyConfig().equals(proxy)) {
              statusLed.setImageResource(getStatusIconResource(state, true));
              statusText.setText(getStatusIconText(state));
            } else if (lc.getDefaultProxyConfig() == null) {
              statusLed.setImageResource(getStatusIconResource(state, true));
              statusText.setText(getStatusIconText(state));
            }

            try {
              statusText.setOnClickListener(
                  new OnClickListener() {
                    @Override
                    public void onClick(View v) {
                      lc.refreshRegisters();
                    }
                  });
            } catch (IllegalStateException ise) {
            }
          }
        };

    LinphoneCore lc = RedfoxManager.getLcIfManagerNotDestroyedOrNull();
    if (lc != null) {
      lc.addListener(mListener);
      LinphoneProxyConfig lpc = lc.getDefaultProxyConfig();
      if (lpc != null) {
        mListener.registrationState(lc, lpc, lpc.getState(), null);
      }
    }

    return view;
  }
Example #3
0
  @Override
  public void onResume() {
    super.onResume();

    LinphoneCore lc = RedfoxManager.getLcIfManagerNotDestroyedOrNull();
    if (lc != null) {
      LinphoneCall call = lc.getCurrentCall();
      if (isInCall && (call != null || lc.getConferenceSize() > 1 || lc.getCallsNb() > 0)) {
        // We are obviously connected
        if (lc.getDefaultProxyConfig() == null) {
          statusLed.setImageResource(R.drawable.led_disconnected);
          statusText.setText(getString(R.string.no_account));
        } else {
          statusLed.setImageResource(
              getStatusIconResource(lc.getDefaultProxyConfig().getState(), true));
          statusText.setText(getStatusIconText(lc.getDefaultProxyConfig().getState()));
        }
      }
    } else {
      statusText.setVisibility(View.VISIBLE);
    }
  }
  // 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());*/
  }