Search in sources :

Example 1 with QrShareAsyncTask

use of org.awesomeapp.messenger.ui.qr.QrShareAsyncTask in project Zom-Android by zom.

the class GroupDisplayActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    getSupportActionBar().setTitle("");
    getSupportActionBar().setDisplayShowHomeEnabled(true);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    setContentView(R.layout.awesome_activity_group);
    mName = getIntent().getStringExtra("nickname");
    mAddress = getIntent().getStringExtra("address");
    mProviderId = getIntent().getLongExtra("provider", -1);
    mAccountId = getIntent().getLongExtra("account", -1);
    mLastChatId = getIntent().getLongExtra("chat", -1);
    Cursor cursor = getContentResolver().query(Imps.ProviderSettings.CONTENT_URI, new String[] { Imps.ProviderSettings.NAME, Imps.ProviderSettings.VALUE }, Imps.ProviderSettings.PROVIDER + "=?", new String[] { Long.toString(mProviderId) }, null);
    if (cursor == null)
        // not going to work
        return;
    Imps.ProviderSettings.QueryMap providerSettings = new Imps.ProviderSettings.QueryMap(cursor, getContentResolver(), mProviderId, false, null);
    mMembers = new ArrayList<>();
    mConn = ((ImApp) getApplication()).getConnection(mProviderId, mAccountId);
    mLocalAddress = Imps.Account.getUserName(getContentResolver(), mAccountId) + '@' + providerSettings.getDomain();
    providerSettings.close();
    try {
        mSession = mConn.getChatSessionManager().getChatSession(mAddress);
        if (mSession != null) {
            mGroupOwner = mSession.getGroupChatOwner();
            if (mGroupOwner != null)
                mIsOwner = mGroupOwner.getAddress().getBareAddress().equals(mLocalAddress);
        }
    } catch (RemoteException e) {
    }
    mRecyclerView = (RecyclerView) findViewById(R.id.rvRoot);
    mRecyclerView.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false));
    mRecyclerView.setAdapter(new RecyclerView.Adapter() {

        private static final int VIEW_TYPE_MEMBER = 0;

        private static final int VIEW_TYPE_HEADER = 1;

        private static final int VIEW_TYPE_FOOTER = 2;

        private int colorTextPrimary = 0xff000000;

        public RecyclerView.Adapter init() {
            TypedValue out = new TypedValue();
            getTheme().resolveAttribute(R.attr.contactTextPrimary, out, true);
            colorTextPrimary = out.data;
            return this;
        }

        @Override
        public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
            switch(viewType) {
                case VIEW_TYPE_HEADER:
                    return new HeaderViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.awesome_activity_group_header, parent, false));
                case VIEW_TYPE_FOOTER:
                    return new FooterViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.awesome_activity_group_footer, parent, false));
            }
            return new MemberViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.group_member_view, parent, false));
        }

        @Override
        public void onBindViewHolder(final RecyclerView.ViewHolder holder, int position) {
            if (holder instanceof HeaderViewHolder) {
                final HeaderViewHolder h = (HeaderViewHolder) holder;
                GroupAvatar avatar = new GroupAvatar(mAddress.split("@")[0]);
                avatar.setRounded(false);
                h.avatar.setImageDrawable(avatar);
                h.qr.setOnClickListener(new View.OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        String inviteString;
                        try {
                            inviteString = OnboardingManager.generateInviteLink(GroupDisplayActivity.this, mAddress, "", mName);
                            OnboardingManager.inviteScan(GroupDisplayActivity.this, inviteString);
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    }
                });
                h.groupName.setText(mName);
                h.groupAddress.setText(mAddress);
                h.actionShare.setOnClickListener(new View.OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        try {
                            String inviteLink = OnboardingManager.generateInviteLink(GroupDisplayActivity.this, mAddress, "", mName);
                            new QrShareAsyncTask(GroupDisplayActivity.this).execute(inviteLink, mName);
                        } catch (Exception e) {
                            Log.e(ImApp.LOG_TAG, "couldn't generate QR code", e);
                        }
                    }
                });
                mActionAddFriends = h.actionAddFriends;
                showAddFriends();
                /**
                 *                    h.actionNotifications.setOnClickListener(new View.OnClickListener() {
                 *                        @Override
                 *                        public void onClick(View v) {
                 *                            setNotificationsEnabled(areNotificationsEnabled());
                 *                            h.checkNotifications.setChecked(areNotificationsEnabled());
                 *                        }
                 *                    });
                 */
                h.checkNotifications.setChecked(areNotificationsEnabled());
                h.checkNotifications.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

                    @Override
                    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                        setNotificationsEnabled(isChecked);
                    }
                });
                if (Preferences.doGroupEncryption()) {
                    h.checkGroupEncryption.setChecked(isGroupEncryptionEnabled());
                    h.checkGroupEncryption.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

                        @Override
                        public void onCheckedChanged(CompoundButton compoundButton, boolean isChecked) {
                            setGroupEncryptionEnabled(isChecked);
                        }
                    });
                } else {
                    h.actionGroupEncryption.setVisibility(View.GONE);
                }
                if (!mIsOwner)
                    h.editGroupName.setVisibility(View.GONE);
                else {
                    h.editGroupName.setOnClickListener(new View.OnClickListener() {

                        @Override
                        public void onClick(View v) {
                            editGroupSubject();
                        }
                    });
                }
            } else if (holder instanceof FooterViewHolder) {
                FooterViewHolder h = (FooterViewHolder) holder;
                // Tint the "leave" text and drawable(s)
                int colorAccent = ResourcesCompat.getColor(getResources(), R.color.holo_orange_light, getTheme());
                for (Drawable d : h.actionLeave.getCompoundDrawables()) {
                    if (d != null) {
                        DrawableCompat.setTint(d, colorAccent);
                    }
                }
                h.actionLeave.setTextColor(colorAccent);
                h.actionLeave.setOnClickListener(new View.OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        confirmLeaveGroup();
                    }
                });
            } else if (holder instanceof MemberViewHolder) {
                MemberViewHolder h = (MemberViewHolder) holder;
                // Reset the padding to match other views in this hierarchy
                // 
                int padding = getResources().getDimensionPixelOffset(R.dimen.detail_view_padding);
                h.itemView.setPadding(padding, h.itemView.getPaddingTop(), padding, h.itemView.getPaddingBottom());
                int idxMember = position - 1;
                final GroupMemberDisplay member = mMembers.get(idxMember);
                String nickname = member.nickname;
                if (TextUtils.isEmpty(nickname)) {
                    nickname = member.username.split("@")[0].split("\\.")[0];
                } else {
                    nickname = nickname.split("@")[0].split("\\.")[0];
                }
                h.line1.setText(nickname);
                boolean hasRoleNone = TextUtils.isEmpty(member.role) || "none".equalsIgnoreCase(member.role);
                h.line1.setTextColor(hasRoleNone ? Color.GRAY : colorTextPrimary);
                h.line2.setText(member.username);
                if (member.affiliation != null && (member.affiliation.contentEquals("owner") || member.affiliation.contentEquals("admin"))) {
                    h.avatarCrown.setVisibility(View.VISIBLE);
                } else {
                    h.avatarCrown.setVisibility(View.GONE);
                }
                // h.line2.setText(member.username);
                if (member.avatar == null) {
                    padding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 12, getResources().getDisplayMetrics());
                    member.avatar = new LetterAvatar(holder.itemView.getContext(), nickname, padding);
                }
                h.avatar.setImageDrawable(member.avatar);
                h.avatar.setVisibility(View.VISIBLE);
                h.itemView.setOnClickListener(new View.OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        showMemberInfo(member);
                    }
                });
            }
        }

        @Override
        public int getItemCount() {
            return 2 + mMembers.size();
        }

        @Override
        public int getItemViewType(int position) {
            if (position == 0)
                return VIEW_TYPE_HEADER;
            else if (position == getItemCount() - 1)
                return VIEW_TYPE_FOOTER;
            return VIEW_TYPE_MEMBER;
        }
    }.init());
}
Also used : ChatListenerAdapter(org.awesomeapp.messenger.ui.legacy.adapter.ChatListenerAdapter) LetterAvatar(org.awesomeapp.messenger.ui.widgets.LetterAvatar) Cursor(android.database.Cursor) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) GroupAvatar(org.awesomeapp.messenger.ui.widgets.GroupAvatar) TypedValue(android.util.TypedValue) Imps(org.awesomeapp.messenger.provider.Imps) ViewGroup(android.view.ViewGroup) Drawable(android.graphics.drawable.Drawable) QrShareAsyncTask(org.awesomeapp.messenger.ui.qr.QrShareAsyncTask) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) RecyclerView(android.support.v7.widget.RecyclerView) DecoderException(org.apache.commons.codec.DecoderException) RemoteException(android.os.RemoteException) RecyclerView(android.support.v7.widget.RecyclerView) RemoteException(android.os.RemoteException) CompoundButton(android.widget.CompoundButton)

Example 2 with QrShareAsyncTask

use of org.awesomeapp.messenger.ui.qr.QrShareAsyncTask in project Zom-Android by zom.

the class AccountFragment method setFingerprints.

private void setFingerprints() {
    new AsyncTask<String, Void, Boolean>() {

        @Override
        protected Boolean doInBackground(String... strings) {
            try {
                mRemoteOmemoFingeprints = mConn.getFingerprints(mUserAddress);
                return true;
            } catch (RemoteException e) {
                e.printStackTrace();
                return false;
            }
        }

        @Override
        protected void onPostExecute(Boolean success) {
            super.onPostExecute(success);
            if (success) {
                if (mRemoteOmemoFingeprints != null && mRemoteOmemoFingeprints.size() > 0) {
                    ImageView btnQrDisplay = (ImageView) mView.findViewById(R.id.omemoqrcode);
                    btnQrDisplay.setOnClickListener(new View.OnClickListener() {

                        @Override
                        public void onClick(View view) {
                            try {
                                String xmppLink = OnboardingManager.generateXmppLink(mUserAddress, mRemoteOmemoFingeprints.get(0));
                                Intent intent = new Intent(getActivity(), QrDisplayActivity.class);
                                intent.putExtra(Intent.EXTRA_TEXT, xmppLink);
                                getActivity().startActivity(intent);
                            } catch (IOException ioe) {
                                Log.e(ImApp.LOG_TAG, "couldn't generate QR code", ioe);
                            }
                        }
                    });
                    TextView tvFingerprint = (TextView) mView.findViewById(R.id.omemoFingerprint);
                    tvFingerprint.setText(prettyPrintFingerprint(mRemoteOmemoFingeprints.get(0)));
                    ImageView btnQrShare = (ImageView) mView.findViewById(R.id.omemoqrshare);
                    btnQrShare.setOnClickListener(new View.OnClickListener() {

                        @Override
                        public void onClick(View v) {
                            try {
                                String inviteLink = OnboardingManager.generateInviteLink(getActivity(), mUserAddress, mRemoteOmemoFingeprints.get(0), mNickname);
                                new QrShareAsyncTask(getActivity()).execute(inviteLink, mNickname);
                            } catch (IOException ioe) {
                                Log.e(ImApp.LOG_TAG, "couldn't generate QR code", ioe);
                            }
                        }
                    });
                } else {
                    mView.findViewById(R.id.omemodisplay).setVisibility(View.GONE);
                }
            }
        }
    }.execute();
}
Also used : Intent(android.content.Intent) QrShareAsyncTask(org.awesomeapp.messenger.ui.qr.QrShareAsyncTask) IOException(java.io.IOException) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) CropImageView(com.theartofdev.edmodo.cropper.CropImageView) TextView(android.widget.TextView) ImageView(android.widget.ImageView) CropImageView(com.theartofdev.edmodo.cropper.CropImageView) RemoteException(android.os.RemoteException)

Example 3 with QrShareAsyncTask

use of org.awesomeapp.messenger.ui.qr.QrShareAsyncTask in project Zom-Android by zom.

the class ContactDisplayActivity method displayFingerprint.

private void displayFingerprint(final String remoteFingerprint) {
    try {
        ImageView btnQrShare = (ImageView) findViewById(R.id.qrshare);
        ImageView iv = (ImageView) findViewById(R.id.qrcode);
        TextView tv = (TextView) findViewById(R.id.tvFingerprint);
        ArrayList<String> fingerprints = OtrChatManager.getInstance().getRemoteKeyFingerprints(mUsername);
        if (!TextUtils.isEmpty(remoteFingerprint)) {
            findViewById(R.id.listEncryptionKey).setVisibility(View.VISIBLE);
            tv.setText(OmemoKeyUtil.prettyFingerprint(remoteFingerprint));
            iv.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    String inviteString;
                    try {
                        inviteString = OnboardingManager.generateInviteLink(ContactDisplayActivity.this, mUsername, remoteFingerprint, mNickname);
                        Intent intent = new Intent(ContactDisplayActivity.this, QrDisplayActivity.class);
                        intent.putExtra(Intent.EXTRA_TEXT, inviteString);
                        intent.setType("text/plain");
                        startActivity(intent);
                    } catch (IOException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                }
            });
            btnQrShare.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    try {
                        String inviteLink = OnboardingManager.generateInviteLink(ContactDisplayActivity.this, mUsername, remoteFingerprint, mNickname);
                        new QrShareAsyncTask(ContactDisplayActivity.this).execute(inviteLink, mNickname);
                    } catch (IOException ioe) {
                        Log.e(ImApp.LOG_TAG, "couldn't generate QR code", ioe);
                    }
                }
            });
        // if (!OtrChatManager.getInstance().isRemoteKeyVerified(mUsername, remoteFingerprint))
        // btnVerify.setVisibility(View.VISIBLE);
        }
    } catch (Exception e) {
        Log.e(ImApp.LOG_TAG, "error displaying contact", e);
    }
}
Also used : QrDisplayActivity(org.awesomeapp.messenger.ui.qr.QrDisplayActivity) TextView(android.widget.TextView) Intent(android.content.Intent) QrShareAsyncTask(org.awesomeapp.messenger.ui.qr.QrShareAsyncTask) ImageView(android.widget.ImageView) IOException(java.io.IOException) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) XmppStringprepException(org.jxmpp.stringprep.XmppStringprepException) RemoteException(android.os.RemoteException) IOException(java.io.IOException)

Aggregations

RemoteException (android.os.RemoteException)3 View (android.view.View)3 ImageView (android.widget.ImageView)3 TextView (android.widget.TextView)3 QrShareAsyncTask (org.awesomeapp.messenger.ui.qr.QrShareAsyncTask)3 Intent (android.content.Intent)2 IOException (java.io.IOException)2 Cursor (android.database.Cursor)1 Drawable (android.graphics.drawable.Drawable)1 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)1 RecyclerView (android.support.v7.widget.RecyclerView)1 TypedValue (android.util.TypedValue)1 ViewGroup (android.view.ViewGroup)1 CompoundButton (android.widget.CompoundButton)1 CropImageView (com.theartofdev.edmodo.cropper.CropImageView)1 DecoderException (org.apache.commons.codec.DecoderException)1 Imps (org.awesomeapp.messenger.provider.Imps)1 ChatListenerAdapter (org.awesomeapp.messenger.ui.legacy.adapter.ChatListenerAdapter)1 QrDisplayActivity (org.awesomeapp.messenger.ui.qr.QrDisplayActivity)1 GroupAvatar (org.awesomeapp.messenger.ui.widgets.GroupAvatar)1