示例#1
0
  void signOut(long providerId, long accountId) {

    try {

      IImConnection conn = mApp.getConnection(mProviderId, mAccountId);
      if (conn != null) {
        conn.logout();
      } else {
        // Normally, we can always get the connection when user chose to
        // sign out. However, if the application crash unexpectedly, the
        // status will never be updated. Clear the status in this case
        // to make it recoverable from the crash.
        ContentValues values = new ContentValues(2);
        values.put(Imps.AccountStatusColumns.PRESENCE_STATUS, Imps.CommonPresenceColumns.OFFLINE);
        values.put(Imps.AccountStatusColumns.CONNECTION_STATUS, Imps.ConnectionStatus.OFFLINE);
        String where = Imps.AccountStatusColumns.ACCOUNT + "=?";
        getActivity()
            .getContentResolver()
            .update(
                Imps.AccountStatus.CONTENT_URI,
                values,
                where,
                new String[] {Long.toString(accountId)});
      }
    } catch (RemoteException ex) {
      Log.e(ImApp.LOG_TAG, "signout: caught ", ex);
    } finally {

    }
  }
示例#2
0
  private boolean checkConnection() {
    try {
      IImConnection conn = mApp.getConnection(mProviderId, mAccountId);

      if (conn.getState() == ImConnection.DISCONNECTED) return false;

      return true;
    } catch (Exception e) {
      return false;
    }
  }
示例#3
0
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    // Inflate the layout for this fragment

    mApp = ((ImApp) getActivity().getApplication());
    mProviderId = mApp.getDefaultProviderId();
    mAccountId = mApp.getDefaultAccountId();
    mUserAddress = mApp.getDefaultUsername();
    mUserKey = mApp.getDefaultOtrKey();
    mNickname = Imps.Account.getNickname(getContext().getContentResolver(), mAccountId);

    mView = inflater.inflate(R.layout.awesome_fragment_account, container, false);

    if (!TextUtils.isEmpty(mUserAddress)) {

      XmppAddress xAddress = new XmppAddress(mUserAddress);

      TextView tvNickname = (TextView) mView.findViewById(R.id.tvNickname);

      TextView tvUsername = (TextView) mView.findViewById(R.id.edtName);
      mTvPassword = (TextView) mView.findViewById(R.id.edtPass);
      View btnShowPassword = mView.findViewById(R.id.btnShowPass);
      btnShowPassword.setOnClickListener(
          new View.OnClickListener() {
            @Override
            public void onClick(View view) {

              mTvPassword.setText(getAccountPassword(mProviderId));
            }
          });

      TextView tvFingerprint = (TextView) mView.findViewById(R.id.tvFingerprint);

      ivScan = (ImageView) mView.findViewById(R.id.qrcode);

      ivScan.setOnClickListener(
          new View.OnClickListener() {

            @Override
            public void onClick(View v) {

              String inviteString;
              try {
                inviteString =
                    OnboardingManager.generateInviteLink(
                        getActivity(), mUserAddress, mUserKey, mNickname);

                Intent intent = new Intent(getActivity(), QrDisplayActivity.class);
                intent.putExtra(Intent.EXTRA_TEXT, inviteString);
                intent.setType("text/plain");
                startActivity(intent);

                //   OnboardingManager.inviteScan(getActivity(), inviteString);
              } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
              }
            }
          });

      mIvAvatar = (ImageView) mView.findViewById(R.id.imageAvatar);
      mIvAvatar.setOnClickListener(
          new View.OnClickListener() {

            @Override
            public void onClick(View view) {

              startAvatarTaker();
            }
          });

      ImageView btnQrShare = (ImageView) mView.findViewById(R.id.qrshare);
      btnQrShare.setOnClickListener(
          new View.OnClickListener() {
            @Override
            public void onClick(View v) {

              try {
                String inviteLink =
                    OnboardingManager.generateInviteLink(
                        getActivity(), mUserAddress, mUserKey, mNickname);
                new QrShareAsyncTask(getActivity()).execute(inviteLink);
              } catch (IOException ioe) {
                Log.e(ImApp.LOG_TAG, "couldn't generate QR code", ioe);
              }
            }
          });

      Switch switchOnline = (Switch) mView.findViewById(R.id.switchOnline);
      switchOnline.setChecked(checkConnection());

      switchOnline.setOnCheckedChangeListener(
          new CompoundButton.OnCheckedChangeListener() {
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
              if (isChecked) {
                signIn();
              } else {
                // The toggle is disabled
                signOut();
              }
            }
          });

      try {

        Drawable avatar =
            DatabaseUtils.getAvatarFromAddress(
                mApp.getContentResolver(),
                mUserAddress,
                ImApp.DEFAULT_AVATAR_WIDTH,
                ImApp.DEFAULT_AVATAR_HEIGHT,
                false);

        if (avatar != null) mIvAvatar.setImageDrawable(avatar);
      } catch (Exception e) {
        Log.w(ImApp.LOG_TAG, "error getting avatar", e);
      }

      tvUsername.setText(mUserAddress);
      tvNickname.setText(mNickname);

      if (mUserKey != null) {
        tvFingerprint.setText(prettyPrintFingerprint(mUserKey));

        /**
         * try { String inviteLink = OnboardingManager.generateInviteLink(getActivity(),
         * fullUserName, mApp.getDefaultOtrKey()); new QrGenAsyncTask(getActivity(),
         * ivScan,ImApp.DEFAULT_AVATAR_WIDTH).execute(inviteLink); } catch (IOException ioe) {
         * Log.e(ImApp.LOG_TAG, "couldn't generate QR code", ioe); }
         */
      }

      /**
       * Button btnLock = (Button) mView.findViewById(R.id.btnLock); btnLock.setOnClickListener(new
       * View.OnClickListener() { @Override public void onClick(View v) { ((MainActivity)
       * getActivity()).handleLock(); } });
       */
    }

    return mView;
  }