Exemplo n.º 1
0
  void updatePresence(int status, String statusText) {
    if (mPresence == null) {
      // No connection yet. Don't allow to update presence yet.
      return;
    }

    Presence newPresence = new Presence(mPresence);

    if (status != -1) {
      newPresence.setStatus(status);
    }

    if (statusText != null) newPresence.setStatusText(statusText);

    try {
      int res = mConn.updateUserPresence(newPresence);
      if (res != ImErrorInfo.NO_ERROR) {
        mHandler.showAlert(R.string.error, ErrorResUtils.getErrorRes(getResources(), res));
      } else {
        mPresence = newPresence;
        updateView();
      }
    } catch (RemoteException e) {
      mHandler.showServiceErrorAlert();
    }
  }
Exemplo n.º 2
0
  private void updateView() {
    ImApp app = ImApp.getApplication((Activity) mContext);
    BrandingResources brandingRes = app.getBrandingResource(mProviderId);
    int status = PresenceUtils.convertStatus(mPresence.getStatus());
    mStatusDialogButton.setImageDrawable(
        brandingRes.getDrawable(PresenceUtils.getStatusIconId(status)));

    String statusText = mPresence.getStatusText();
    if (TextUtils.isEmpty(statusText)) {
      statusText = brandingRes.getString(PresenceUtils.getStatusStringRes(status));
    }
    mLastStatusText = statusText;

    if (mStatusBar == null) {
      mStatusBar = initStatusBar(mProviderId, false);
    }
    mStatusBar.setText(statusText);

    // Disable the user to edit the custom status text because
    // the AIM and MSN server don't support it now.
    ProviderDef provider = app.getProvider(mProviderId);
    String providerName = provider == null ? null : provider.mName;
    if (Imps.ProviderNames.AIM.equals(providerName)
        || Imps.ProviderNames.MSN.equals(providerName)) {
      mStatusBar.setFocusable(false);
    }
  }
Exemplo n.º 3
0
  private TextView initStatusBar(long providerId, boolean showEdit) {

    EditText statusEdit = (EditText) findViewById(R.id.statusEdit);
    statusEdit.setVisibility(View.GONE);
    TextView statusView = (TextView) findViewById(R.id.statusView);
    statusView.setVisibility(View.GONE);

    if (showEdit) {

      statusEdit.setVisibility(View.VISIBLE);
      statusEdit.setOnKeyListener(
          new OnKeyListener() {
            public boolean onKey(View v, int keyCode, KeyEvent event) {
              if (KeyEvent.ACTION_DOWN == event.getAction()) {
                switch (keyCode) {
                  case KeyEvent.KEYCODE_DPAD_CENTER:
                  case KeyEvent.KEYCODE_ENTER:
                    updateStatusText();
                    return true;
                }
              }
              return false;
            }
          });

      statusEdit.setOnFocusChangeListener(
          new View.OnFocusChangeListener() {
            public void onFocusChange(View v, boolean hasFocus) {
              if (!hasFocus) {
                updateStatusText();
              }
            }
          });

      return statusEdit;
    } else {
      if (mPresence != null) {
        statusView.setText(mPresence.getStatusText());
      }

      statusView.setVisibility(View.VISIBLE);

      statusView.setOnClickListener(
          new OnClickListener() {

            @Override
            public void onClick(View v) {
              mStatusBar = initStatusBar(mProviderId, true);
            }
          });

      return statusView;
    }
  }