2012-07-24 04:43:55 +00:00
|
|
|
/**
|
2011-12-20 18:20:44 +00:00
|
|
|
* Copyright (C) 2011 Whisper Systems
|
2012-07-24 04:43:55 +00:00
|
|
|
*
|
2011-12-20 18:20:44 +00:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
2012-07-24 04:43:55 +00:00
|
|
|
*
|
2011-12-20 18:20:44 +00:00
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
package org.thoughtcrime.securesms;
|
|
|
|
|
|
|
|
import android.content.Context;
|
2013-05-24 00:47:42 +00:00
|
|
|
import android.os.Build;
|
2013-05-23 23:36:24 +00:00
|
|
|
import android.os.Handler;
|
2011-12-20 18:20:44 +00:00
|
|
|
import android.util.AttributeSet;
|
2013-05-24 00:47:42 +00:00
|
|
|
import android.view.View;
|
|
|
|
import android.widget.ImageView;
|
|
|
|
import android.widget.QuickContactBadge;
|
2011-12-20 18:20:44 +00:00
|
|
|
import android.widget.RelativeLayout;
|
|
|
|
import android.widget.TextView;
|
|
|
|
|
2013-05-23 23:36:24 +00:00
|
|
|
import org.thoughtcrime.securesms.crypto.IdentityKey;
|
|
|
|
import org.thoughtcrime.securesms.database.IdentityDatabase;
|
|
|
|
import org.thoughtcrime.securesms.recipients.Recipient;
|
|
|
|
import org.thoughtcrime.securesms.recipients.Recipients;
|
|
|
|
|
2011-12-20 18:20:44 +00:00
|
|
|
/**
|
2012-07-24 04:43:55 +00:00
|
|
|
* List item view for displaying user identity keys.
|
|
|
|
*
|
2011-12-20 18:20:44 +00:00
|
|
|
* @author Moxie Marlinspike
|
|
|
|
*/
|
2013-05-23 23:36:24 +00:00
|
|
|
public class IdentityKeyView extends RelativeLayout
|
|
|
|
implements Recipient.RecipientModifiedListener
|
|
|
|
{
|
2012-07-24 04:43:55 +00:00
|
|
|
|
2013-05-24 00:47:42 +00:00
|
|
|
private TextView identityName;
|
|
|
|
private TextView fingerprint;
|
|
|
|
private QuickContactBadge contactBadge;
|
|
|
|
private ImageView contactImage;
|
2013-05-23 23:36:24 +00:00
|
|
|
|
|
|
|
private Recipients recipients;
|
|
|
|
private IdentityKey identityKey;
|
|
|
|
|
|
|
|
private final Handler handler = new Handler();
|
2012-07-24 04:43:55 +00:00
|
|
|
|
2011-12-20 18:20:44 +00:00
|
|
|
public IdentityKeyView(Context context) {
|
|
|
|
super(context);
|
|
|
|
}
|
2012-07-24 04:43:55 +00:00
|
|
|
|
2011-12-20 18:20:44 +00:00
|
|
|
public IdentityKeyView(Context context, AttributeSet attributeSet) {
|
|
|
|
super(context, attributeSet);
|
|
|
|
}
|
2012-07-24 04:43:55 +00:00
|
|
|
|
2013-05-24 00:47:42 +00:00
|
|
|
@Override
|
|
|
|
public void onFinishInflate() {
|
|
|
|
this.identityName = (TextView)findViewById(R.id.identity_name);
|
|
|
|
this.fingerprint = (TextView)findViewById(R.id.fingerprint);
|
|
|
|
this.contactBadge = (QuickContactBadge)findViewById(R.id.contact_photo_badge);
|
|
|
|
this.contactImage = (ImageView)findViewById(R.id.contact_photo_image);
|
|
|
|
|
|
|
|
if (isBadgeEnabled()) {
|
|
|
|
this.contactBadge.setVisibility(View.VISIBLE);
|
|
|
|
this.contactImage.setVisibility(View.GONE);
|
|
|
|
} else {
|
|
|
|
this.contactBadge.setVisibility(View.GONE);
|
|
|
|
this.contactImage.setVisibility(View.VISIBLE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-23 23:36:24 +00:00
|
|
|
public void set(IdentityDatabase.Identity identity) {
|
|
|
|
this.recipients = identity.getRecipients();
|
|
|
|
this.identityKey = identity.getIdentityKey();
|
|
|
|
|
|
|
|
this.recipients.addListener(this);
|
|
|
|
|
|
|
|
identityName.setText(recipients.toShortString());
|
2013-05-24 00:47:42 +00:00
|
|
|
fingerprint.setText(identity.getIdentityKey().getFingerprint());
|
|
|
|
|
|
|
|
contactBadge.setImageBitmap(recipients.getPrimaryRecipient().getContactPhoto());
|
|
|
|
contactBadge.assignContactFromPhone(recipients.getPrimaryRecipient().getNumber(), true);
|
|
|
|
contactImage.setImageBitmap(recipients.getPrimaryRecipient().getContactPhoto());
|
2011-12-20 18:20:44 +00:00
|
|
|
}
|
2012-07-24 04:43:55 +00:00
|
|
|
|
2013-05-23 23:36:24 +00:00
|
|
|
public IdentityKey getIdentityKey() {
|
|
|
|
return this.identityKey;
|
2012-07-24 04:43:55 +00:00
|
|
|
}
|
|
|
|
|
2013-05-24 00:47:42 +00:00
|
|
|
private boolean isBadgeEnabled() {
|
|
|
|
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB;
|
2011-12-20 18:20:44 +00:00
|
|
|
}
|
|
|
|
|
2013-05-23 23:36:24 +00:00
|
|
|
@Override
|
|
|
|
public void onModified(Recipient recipient) {
|
|
|
|
handler.post(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
IdentityKeyView.this.identityName.setText(recipients.toShortString());
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2011-12-20 18:20:44 +00:00
|
|
|
}
|