예제 #1
0
  private void setAvatar(Bitmap bmp) {

    BitmapDrawable avatar = new BitmapDrawable(bmp);
    mIvAvatar.setImageDrawable(avatar);

    final ImApp app = ((ImApp) getActivity().getApplication());

    try {

      ByteArrayOutputStream stream = new ByteArrayOutputStream();
      bmp.compress(Bitmap.CompressFormat.JPEG, 90, stream);

      byte[] avatarBytesCompressed = stream.toByteArray();
      String avatarHash = "nohash";
      DatabaseUtils.insertAvatarBlob(
          getActivity().getContentResolver(),
          Imps.Avatars.CONTENT_URI,
          mProviderId,
          mAccountId,
          avatarBytesCompressed,
          avatarHash,
          mUserAddress);
    } catch (Exception e) {
      Log.w(ImApp.LOG_TAG, "error loading image bytes", e);
    }
  }
예제 #2
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;
  }