mirror of
https://github.com/oxen-io/session-android.git
synced 2025-10-20 15:10:51 +00:00
repurpose ImageDivet for avatar, minor lint, fix bitmap decoding
// FREEBIE
This commit is contained in:
@@ -25,7 +25,6 @@ import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.content.res.TypedArray;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.graphics.drawable.BitmapDrawable;
|
||||
import android.net.Uri;
|
||||
import android.os.AsyncTask;
|
||||
@@ -61,7 +60,6 @@ import org.thoughtcrime.securesms.components.EmojiToggle;
|
||||
import org.thoughtcrime.securesms.components.RecipientsPanel;
|
||||
import org.thoughtcrime.securesms.contacts.ContactAccessor;
|
||||
import org.thoughtcrime.securesms.contacts.ContactAccessor.ContactData;
|
||||
import org.thoughtcrime.securesms.contacts.ContactPhotoFactory;
|
||||
import org.thoughtcrime.securesms.crypto.KeyExchangeInitiator;
|
||||
import org.thoughtcrime.securesms.crypto.KeyExchangeProcessor;
|
||||
import org.thoughtcrime.securesms.database.DatabaseFactory;
|
||||
@@ -496,7 +494,7 @@ public class ConversationActivity extends PassphraseRequiredSherlockFragmentActi
|
||||
title = (!TextUtils.isEmpty(groupName)) ? groupName : getString(R.string.ConversationActivity_unnamed_group);
|
||||
final Bitmap avatar = getRecipients().getPrimaryRecipient().getContactPhoto();
|
||||
if (avatar != null) {
|
||||
getSupportActionBar().setIcon(new BitmapDrawable(getResources(), BitmapUtil.getCroppedBitmap(avatar)));
|
||||
getSupportActionBar().setIcon(new BitmapDrawable(getResources(), BitmapUtil.getCircleCroppedBitmap(avatar)));
|
||||
}
|
||||
} else {
|
||||
title = getString(R.string.ConversationActivity_group_conversation);
|
||||
|
@@ -34,7 +34,6 @@ import android.provider.ContactsContract.QuickContact;
|
||||
import org.thoughtcrime.securesms.util.DateUtils;
|
||||
import android.util.AttributeSet;
|
||||
import android.util.Log;
|
||||
import android.util.Pair;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.ImageView;
|
||||
@@ -55,7 +54,6 @@ import org.thoughtcrime.securesms.recipients.Recipient;
|
||||
import org.thoughtcrime.securesms.service.SendReceiveService;
|
||||
import org.thoughtcrime.securesms.util.BitmapUtil;
|
||||
import org.thoughtcrime.securesms.util.Emoji;
|
||||
import org.whispersystems.textsecure.util.Base64;
|
||||
import org.whispersystems.textsecure.util.FutureTaskListener;
|
||||
import org.whispersystems.textsecure.util.ListenableFutureTask;
|
||||
import org.whispersystems.textsecure.util.Util;
|
||||
@@ -65,7 +63,6 @@ import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.util.List;
|
||||
|
||||
import static org.whispersystems.textsecure.push.PushMessageProtos.PushMessageContent.GroupContext;
|
||||
|
||||
@@ -178,17 +175,19 @@ public class ConversationItem extends LinearLayout {
|
||||
/// MessageRecord Attribute Parsers
|
||||
|
||||
private void setBodyText(MessageRecord messageRecord) {
|
||||
// TODO jake is going to fill these in
|
||||
switch (messageRecord.getGroupAction()) {
|
||||
case GroupContext.Type.QUIT_VALUE:
|
||||
bodyText.setText(messageRecord.getIndividualRecipient().toShortString() + " has left the group.");
|
||||
bodyText.setText(context.getString(R.string.ConversationItem_group_action_left,
|
||||
messageRecord.getIndividualRecipient().toShortString()));
|
||||
return;
|
||||
case GroupContext.Type.ADD_VALUE:
|
||||
case GroupContext.Type.CREATE_VALUE:
|
||||
bodyText.setText(Util.join(GroupUtil.getSerializedArgumentMembers(messageRecord.getGroupActionArguments()), ", ") + " have joined the group.");
|
||||
bodyText.setText(context.getString(R.string.ConversationItem_group_action_joined,
|
||||
Util.join(GroupUtil.getSerializedArgumentMembers(messageRecord.getGroupActionArguments()), ", ")));
|
||||
return;
|
||||
case GroupContext.Type.MODIFY_VALUE:
|
||||
bodyText.setText(messageRecord.getIndividualRecipient() + " has updated the group.");
|
||||
bodyText.setText(context.getString(R.string.ConversationItem_group_action_modify,
|
||||
messageRecord.getIndividualRecipient()));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -254,11 +253,9 @@ public class ConversationItem extends LinearLayout {
|
||||
}
|
||||
|
||||
private void setNotificationMmsAttributes(NotificationMmsMessageRecord messageRecord) {
|
||||
String messageSize = String.format(getContext()
|
||||
.getString(R.string.ConversationItem_message_size_d_kb),
|
||||
String messageSize = String.format(context.getString(R.string.ConversationItem_message_size_d_kb),
|
||||
messageRecord.getMessageSize());
|
||||
String expires = String.format(getContext()
|
||||
.getString(R.string.ConversationItem_expires_s),
|
||||
String expires = String.format(context.getString(R.string.ConversationItem_expires_s),
|
||||
DateUtils.getRelativeTimeSpanString(getContext(),
|
||||
messageRecord.getExpiration(),
|
||||
false));
|
||||
@@ -341,7 +338,7 @@ public class ConversationItem extends LinearLayout {
|
||||
}
|
||||
|
||||
private void setContactPhotoForRecipient(final Recipient recipient) {
|
||||
contactPhoto.setImageBitmap(BitmapUtil.getCroppedBitmap(recipient.getContactPhoto()));
|
||||
contactPhoto.setImageBitmap(BitmapUtil.getCircleCroppedBitmap(recipient.getContactPhoto()));
|
||||
contactPhoto.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
|
@@ -32,7 +32,6 @@ import android.text.style.StyleSpan;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.View;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.QuickContactBadge;
|
||||
import android.widget.RelativeLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
@@ -130,7 +129,7 @@ public class ConversationListItem extends RelativeLayout
|
||||
private void setContactPhoto(final Recipient recipient) {
|
||||
if (recipient == null) return;
|
||||
|
||||
contactPhotoImage.setImageBitmap(BitmapUtil.getCroppedBitmap(recipient.getContactPhoto()));
|
||||
contactPhotoImage.setImageBitmap(BitmapUtil.getCircleCroppedBitmap(recipient.getContactPhoto()));
|
||||
contactPhotoImage.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
|
@@ -17,7 +17,9 @@ import android.util.Pair;
|
||||
import android.view.View;
|
||||
import android.widget.EditText;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.ListView;
|
||||
import android.widget.RelativeLayout;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
@@ -36,6 +38,7 @@ import org.thoughtcrime.securesms.recipients.RecipientFormattingException;
|
||||
import org.thoughtcrime.securesms.recipients.Recipients;
|
||||
import org.thoughtcrime.securesms.sms.MessageSender;
|
||||
import org.thoughtcrime.securesms.util.ActionBarUtil;
|
||||
import org.thoughtcrime.securesms.util.BitmapUtil;
|
||||
import org.thoughtcrime.securesms.util.DynamicLanguage;
|
||||
import org.thoughtcrime.securesms.util.DynamicTheme;
|
||||
import org.thoughtcrime.securesms.util.GroupUtil;
|
||||
@@ -67,20 +70,23 @@ public class GroupCreateActivity extends PassphraseRequiredSherlockFragmentActiv
|
||||
|
||||
private final static String TAG = GroupCreateActivity.class.getSimpleName();
|
||||
|
||||
|
||||
public static final String MASTER_SECRET_EXTRA = "master_secret";
|
||||
|
||||
private final DynamicTheme dynamicTheme = new DynamicTheme();
|
||||
private final DynamicLanguage dynamicLanguage = new DynamicLanguage();
|
||||
|
||||
private static final String TEMP_PHOTO_FILE = "__tmp_group_create_avatar_photo.png";
|
||||
private static final String TEMP_PHOTO_FILE = "__tmp_group_create_avatar_photo.tmp";
|
||||
|
||||
private static final int PICK_CONTACT = 1;
|
||||
private static final int PICK_AVATAR = 2;
|
||||
public static final int AVATAR_SIZE = 210;
|
||||
|
||||
private EditText groupName;
|
||||
private ListView lv;
|
||||
private PushRecipientsPanel recipientsPanel;
|
||||
private ImageView avatar;
|
||||
private TextView creatingText;
|
||||
|
||||
private MasterSecret masterSecret;
|
||||
private Bitmap avatarBmp;
|
||||
@@ -172,7 +178,13 @@ public class GroupCreateActivity extends PassphraseRequiredSherlockFragmentActiv
|
||||
|
||||
private void initializeResources() {
|
||||
masterSecret = getIntent().getParcelableExtra(MASTER_SECRET_EXTRA);
|
||||
groupName = (EditText) findViewById(R.id.group_name);
|
||||
|
||||
lv = (ListView) findViewById(R.id.selected_contacts_list);
|
||||
avatar = (ImageView) findViewById(R.id.avatar);
|
||||
groupName = (EditText) findViewById(R.id.group_name);
|
||||
creatingText = (TextView) findViewById(R.id.creating_group_text);
|
||||
recipientsPanel = (PushRecipientsPanel) findViewById(R.id.recipients);
|
||||
|
||||
groupName.addTextChangedListener(new TextWatcher() {
|
||||
@Override
|
||||
public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) { }
|
||||
@@ -187,7 +199,6 @@ public class GroupCreateActivity extends PassphraseRequiredSherlockFragmentActiv
|
||||
}
|
||||
});
|
||||
|
||||
lv = (ListView) findViewById(R.id.selected_contacts_list);
|
||||
SelectedRecipientsAdapter adapter = new SelectedRecipientsAdapter(this, android.R.id.text1, new ArrayList<Recipient>());
|
||||
adapter.setOnRecipientDeletedListener(new SelectedRecipientsAdapter.OnRecipientDeletedListener() {
|
||||
@Override
|
||||
@@ -197,7 +208,6 @@ public class GroupCreateActivity extends PassphraseRequiredSherlockFragmentActiv
|
||||
});
|
||||
lv.setAdapter(adapter);
|
||||
|
||||
recipientsPanel = (PushRecipientsPanel) findViewById(R.id.recipients);
|
||||
recipientsPanel.setPanelChangeListener(new PushRecipientsPanel.RecipientsPanelChangedListener() {
|
||||
@Override
|
||||
public void onRecipientsPanelUpdate(Recipients recipients) {
|
||||
@@ -210,7 +220,6 @@ public class GroupCreateActivity extends PassphraseRequiredSherlockFragmentActiv
|
||||
});
|
||||
(findViewById(R.id.contacts_button)).setOnClickListener(new AddRecipientButtonListener());
|
||||
|
||||
avatar = (ImageView) findViewById(R.id.avatar);
|
||||
avatar.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
@@ -219,8 +228,8 @@ public class GroupCreateActivity extends PassphraseRequiredSherlockFragmentActiv
|
||||
photoPickerIntent.putExtra("crop", "true");
|
||||
photoPickerIntent.putExtra("aspectX", 1);
|
||||
photoPickerIntent.putExtra("aspectY", 1);
|
||||
photoPickerIntent.putExtra("outputX", 210);
|
||||
photoPickerIntent.putExtra("outputY", 210);
|
||||
photoPickerIntent.putExtra("outputX", AVATAR_SIZE);
|
||||
photoPickerIntent.putExtra("outputY", AVATAR_SIZE);
|
||||
photoPickerIntent.putExtra(MediaStore.EXTRA_OUTPUT, getTempUri());
|
||||
photoPickerIntent.putExtra("outputFormat", Bitmap.CompressFormat.PNG.toString());
|
||||
startActivityForResult(photoPickerIntent, PICK_AVATAR);
|
||||
@@ -292,7 +301,8 @@ public class GroupCreateActivity extends PassphraseRequiredSherlockFragmentActiv
|
||||
findViewById(R.id.group_details_layout).setVisibility(View.GONE);
|
||||
findViewById(R.id.creating_group_layout).setVisibility(View.VISIBLE);
|
||||
findViewById(R.id.menu_create_group).setVisibility(View.GONE);
|
||||
((TextView)findViewById(R.id.creating_group_text)).setText("Creating " + groupName.getText().toString() + "...");
|
||||
if (groupName.getText() != null)
|
||||
creatingText.setText(getString(R.string.GroupCreateActivity_creating_group, groupName.getText().toString()));
|
||||
}
|
||||
|
||||
private void disableWhisperGroupCreatingUi() {
|
||||
@@ -312,7 +322,6 @@ public class GroupCreateActivity extends PassphraseRequiredSherlockFragmentActiv
|
||||
|
||||
@Override
|
||||
public void onActivityResult(int reqCode, int resultCode, Intent data) {
|
||||
Log.w("ComposeMessageActivity", "onActivityResult called: " + resultCode + " , " + data);
|
||||
super.onActivityResult(reqCode, resultCode, data);
|
||||
|
||||
if (data == null || resultCode != Activity.RESULT_OK)
|
||||
@@ -331,7 +340,7 @@ public class GroupCreateActivity extends PassphraseRequiredSherlockFragmentActiv
|
||||
addSelectedContact(recipient);
|
||||
}
|
||||
} catch (RecipientFormattingException e) {
|
||||
Log.w("GroupCreateActivity", e);
|
||||
Log.w(TAG, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -339,10 +348,9 @@ public class GroupCreateActivity extends PassphraseRequiredSherlockFragmentActiv
|
||||
break;
|
||||
case PICK_AVATAR:
|
||||
if(resultCode == RESULT_OK) {
|
||||
File tempFile = getTempFile();
|
||||
avatarBmp = BitmapFactory.decodeFile(tempFile.getAbsolutePath());
|
||||
if (avatarBmp != null) avatar.setImageBitmap(avatarBmp);
|
||||
tempFile.delete();
|
||||
|
||||
new DecodeCropAndSetAsyncTask().execute();
|
||||
|
||||
break;
|
||||
} else {
|
||||
Log.i(TAG, "Avatar selection result was not RESULT_OK.");
|
||||
@@ -384,7 +392,7 @@ public class GroupCreateActivity extends PassphraseRequiredSherlockFragmentActiv
|
||||
} catch (RecipientFormattingException e) {
|
||||
throw new AssertionError(e);
|
||||
} catch (MmsException e) {
|
||||
Log.w("GroupCreateActivity", e);
|
||||
Log.w(TAG, e);
|
||||
groupDatabase.remove(groupId, TextSecurePreferences.getLocalNumber(this));
|
||||
throw new MmsException(e);
|
||||
}
|
||||
@@ -409,6 +417,22 @@ public class GroupCreateActivity extends PassphraseRequiredSherlockFragmentActiv
|
||||
return results;
|
||||
}
|
||||
|
||||
private class DecodeCropAndSetAsyncTask extends AsyncTask<Void,Void,Bitmap> {
|
||||
|
||||
@Override
|
||||
protected Bitmap doInBackground(Void... voids) {
|
||||
File tempFile = getTempFile();
|
||||
avatarBmp = BitmapUtil.getCircleCroppedBitmap(BitmapFactory.decodeFile(tempFile.getAbsolutePath()));
|
||||
tempFile.delete();
|
||||
return avatarBmp;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(Bitmap result) {
|
||||
if (avatarBmp != null) avatar.setImageBitmap(avatarBmp);
|
||||
}
|
||||
}
|
||||
|
||||
private class CreateMmsGroupAsyncTask extends AsyncTask<Void,Void,Long> {
|
||||
|
||||
@Override
|
||||
@@ -460,10 +484,10 @@ public class GroupCreateActivity extends PassphraseRequiredSherlockFragmentActiv
|
||||
try {
|
||||
return handleCreatePushGroup(name, avatarBytes, selectedContacts);
|
||||
} catch (MmsException e) {
|
||||
Log.w("GroupCreateActivity", e);
|
||||
Log.w(TAG, e);
|
||||
return new Pair<Long,Recipients>(RES_MMS_EXCEPTION, null);
|
||||
} catch (InvalidNumberException e) {
|
||||
Log.w("GroupCreateActivity", e);
|
||||
Log.w(TAG, e);
|
||||
return new Pair<Long,Recipients>(RES_BAD_NUMBER, null);
|
||||
}
|
||||
}
|
||||
|
@@ -339,6 +339,7 @@ public class PushContactSelectionListFragment extends SherlockListFragment
|
||||
public void onLoadFinished(Loader<Cursor> arg0, Cursor cursor) {
|
||||
Cursor pushCursor = ContactAccessor.getInstance().getCursorForContactsWithPush(getActivity());
|
||||
((CursorAdapter) getListAdapter()).changeCursor(new MergeCursor(new Cursor[]{pushCursor,cursor}));
|
||||
((TextView)getView().findViewById(android.R.id.empty)).setText(R.string.contact_selection_group_activity__no_contacts);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -265,6 +265,7 @@ public class SingleContactSelectionListFragment extends SherlockListFragment
|
||||
public void onLoadFinished(Loader<Cursor> arg0, Cursor cursor) {
|
||||
Cursor pushCursor = ContactAccessor.getInstance().getCursorForContactsWithPush(getActivity());
|
||||
((CursorAdapter) getListAdapter()).changeCursor(new MergeCursor(new Cursor[]{pushCursor,cursor}));
|
||||
((TextView)getView().findViewById(android.R.id.empty)).setText(R.string.contact_selection_group_activity__no_contacts);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -12,7 +12,7 @@ import org.thoughtcrime.securesms.R;
|
||||
|
||||
public class ImageDivet extends ImageView {
|
||||
private static final float CORNER_OFFSET = 12F;
|
||||
private static final String[] POSITIONS = new String[] {"left", "right"};
|
||||
private static final String[] POSITIONS = new String[] {"bottom_right"};
|
||||
|
||||
private Drawable drawable;
|
||||
|
||||
@@ -46,16 +46,12 @@ public class ImageDivet extends ImageView {
|
||||
}
|
||||
|
||||
private void setDrawable() {
|
||||
int attributes[] = new int[] {R.attr.conversation_avatar_divet_left,
|
||||
R.attr.conversation_avatar_divet_right};
|
||||
int attributes[] = new int[] {R.attr.lower_right_divet};
|
||||
|
||||
TypedArray drawables = getContext().obtainStyledAttributes(attributes);
|
||||
|
||||
switch (position) {
|
||||
case 0:
|
||||
drawable = drawables.getDrawable(1);
|
||||
break;
|
||||
case 1:
|
||||
drawable = drawables.getDrawable(0);
|
||||
break;
|
||||
}
|
||||
@@ -98,26 +94,16 @@ public class ImageDivet extends ImageView {
|
||||
}
|
||||
|
||||
private void computeBounds(Canvas c) {
|
||||
final int left = 0;
|
||||
final int top = 0;
|
||||
final int right = getWidth();
|
||||
|
||||
final int cornerOffset = (int) getCloseOffset();
|
||||
final int bottom = getHeight();
|
||||
|
||||
switch (position) {
|
||||
case 1:
|
||||
drawable.setBounds(
|
||||
right - drawableIntrinsicWidth,
|
||||
top + cornerOffset,
|
||||
right,
|
||||
top + cornerOffset + drawableIntrinsicHeight);
|
||||
break;
|
||||
case 0:
|
||||
drawable.setBounds(
|
||||
left,
|
||||
top + cornerOffset,
|
||||
left + drawableIntrinsicWidth,
|
||||
top + cornerOffset + drawableIntrinsicHeight);
|
||||
right - drawableIntrinsicWidth,
|
||||
bottom - drawableIntrinsicHeight,
|
||||
right,
|
||||
bottom);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@@ -11,6 +11,7 @@ import android.graphics.Rect;
|
||||
import android.net.Uri;
|
||||
import android.util.Log;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
@@ -66,7 +67,7 @@ public class BitmapUtil {
|
||||
options.inSampleSize = scaler;
|
||||
options.inJustDecodeBounds = false;
|
||||
|
||||
Bitmap roughThumbnail = BitmapFactory.decodeStream(data, null, options);
|
||||
Bitmap roughThumbnail = BitmapFactory.decodeStream(new BufferedInputStream(data), null, options);
|
||||
|
||||
if (roughThumbnail == null) {
|
||||
throw new BitmapDecodingException("Decoded stream was null.");
|
||||
@@ -103,7 +104,7 @@ public class BitmapUtil {
|
||||
return options;
|
||||
}
|
||||
|
||||
public static Bitmap getCroppedBitmap(Bitmap bitmap) {
|
||||
public static Bitmap getCircleCroppedBitmap(Bitmap bitmap) {
|
||||
Bitmap output = Bitmap.createBitmap(bitmap.getWidth(),
|
||||
bitmap.getHeight(), Bitmap.Config.ARGB_8888);
|
||||
Canvas canvas = new Canvas(output);
|
||||
|
Reference in New Issue
Block a user