Fixed contact picture edition
This commit is contained in:
parent
165e9a8f76
commit
c7aecaa1d7
3 changed files with 45 additions and 54 deletions
|
@ -58,6 +58,7 @@ import org.linphone.core.tools.Log;
|
||||||
import org.linphone.mediastream.Version;
|
import org.linphone.mediastream.Version;
|
||||||
import org.linphone.settings.LinphonePreferences;
|
import org.linphone.settings.LinphonePreferences;
|
||||||
import org.linphone.utils.FileUtils;
|
import org.linphone.utils.FileUtils;
|
||||||
|
import org.linphone.utils.ImageUtils;
|
||||||
import org.linphone.utils.LinphoneUtils;
|
import org.linphone.utils.LinphoneUtils;
|
||||||
|
|
||||||
public class ContactEditorFragment extends Fragment {
|
public class ContactEditorFragment extends Fragment {
|
||||||
|
@ -426,10 +427,12 @@ public class ContactEditorFragment extends Fragment {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mContact != null) {
|
if (mPhotoToAdd == null) {
|
||||||
ContactAvatar.displayAvatar(mContact, mView.findViewById(R.id.avatar_layout));
|
if (mContact != null) {
|
||||||
} else {
|
ContactAvatar.displayAvatar(mContact, mView.findViewById(R.id.avatar_layout));
|
||||||
ContactAvatar.displayAvatar("", mView.findViewById(R.id.avatar_layout));
|
} else {
|
||||||
|
ContactAvatar.displayAvatar("", mView.findViewById(R.id.avatar_layout));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
mSipAddresses = initSipAddressFields(mContact);
|
mSipAddresses = initSipAddressFields(mContact);
|
||||||
|
@ -438,27 +441,24 @@ public class ContactEditorFragment extends Fragment {
|
||||||
|
|
||||||
private void pickImage() {
|
private void pickImage() {
|
||||||
mPickedPhotoForContactUri = null;
|
mPickedPhotoForContactUri = null;
|
||||||
final List<Intent> cameraIntents = new ArrayList<>();
|
List<Intent> cameraIntents = new ArrayList<>();
|
||||||
final Intent captureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
|
|
||||||
|
// Handles image & video picking
|
||||||
|
Intent galleryIntent = new Intent(Intent.ACTION_PICK);
|
||||||
|
galleryIntent.setType("image/*");
|
||||||
|
|
||||||
|
// Allows to capture directly from the camera
|
||||||
|
Intent captureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
|
||||||
File file =
|
File file =
|
||||||
new File(
|
new File(
|
||||||
FileUtils.getStorageDirectory(getActivity()),
|
FileUtils.getStorageDirectory(getActivity()),
|
||||||
getString(R.string.temp_photo_name));
|
getString(R.string.temp_photo_name_with_date)
|
||||||
|
.replace("%s", System.currentTimeMillis() + ".jpeg"));
|
||||||
mPickedPhotoForContactUri = Uri.fromFile(file);
|
mPickedPhotoForContactUri = Uri.fromFile(file);
|
||||||
captureIntent.putExtra("outputX", PHOTO_SIZE);
|
|
||||||
captureIntent.putExtra("outputY", PHOTO_SIZE);
|
|
||||||
captureIntent.putExtra("aspectX", 0);
|
|
||||||
captureIntent.putExtra("aspectY", 0);
|
|
||||||
captureIntent.putExtra("scale", true);
|
|
||||||
captureIntent.putExtra("return-data", false);
|
|
||||||
captureIntent.putExtra(MediaStore.EXTRA_OUTPUT, mPickedPhotoForContactUri);
|
captureIntent.putExtra(MediaStore.EXTRA_OUTPUT, mPickedPhotoForContactUri);
|
||||||
cameraIntents.add(captureIntent);
|
cameraIntents.add(captureIntent);
|
||||||
|
|
||||||
final Intent galleryIntent = new Intent();
|
Intent chooserIntent =
|
||||||
galleryIntent.setType("image/*");
|
|
||||||
galleryIntent.setAction(Intent.ACTION_GET_CONTENT);
|
|
||||||
|
|
||||||
final Intent chooserIntent =
|
|
||||||
Intent.createChooser(galleryIntent, getString(R.string.image_picker_title));
|
Intent.createChooser(galleryIntent, getString(R.string.image_picker_title));
|
||||||
chooserIntent.putExtra(
|
chooserIntent.putExtra(
|
||||||
Intent.EXTRA_INITIAL_INTENTS, cameraIntents.toArray(new Parcelable[] {}));
|
Intent.EXTRA_INITIAL_INTENTS, cameraIntents.toArray(new Parcelable[] {}));
|
||||||
|
@ -471,40 +471,13 @@ public class ContactEditorFragment extends Fragment {
|
||||||
image = BitmapFactory.decodeFile(filePath);
|
image = BitmapFactory.decodeFile(filePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
Bitmap scaledPhoto;
|
|
||||||
int size = getThumbnailSize();
|
|
||||||
if (size > 0) {
|
|
||||||
scaledPhoto = Bitmap.createScaledBitmap(image, size, size, false);
|
|
||||||
} else {
|
|
||||||
scaledPhoto = Bitmap.createBitmap(image);
|
|
||||||
}
|
|
||||||
image.recycle();
|
|
||||||
|
|
||||||
ByteArrayOutputStream stream = new ByteArrayOutputStream();
|
ByteArrayOutputStream stream = new ByteArrayOutputStream();
|
||||||
scaledPhoto.compress(Bitmap.CompressFormat.PNG, 0, stream);
|
image.compress(Bitmap.CompressFormat.JPEG, 100, stream);
|
||||||
mContactPicture.setImageBitmap(scaledPhoto);
|
|
||||||
mPhotoToAdd = stream.toByteArray();
|
mPhotoToAdd = stream.toByteArray();
|
||||||
}
|
|
||||||
|
|
||||||
private int getThumbnailSize() {
|
Bitmap roundPicture = ImageUtils.getRoundBitmap(image);
|
||||||
int value = -1;
|
ContactAvatar.displayAvatar(roundPicture, mView.findViewById(R.id.avatar_layout));
|
||||||
Cursor c =
|
image.recycle();
|
||||||
getActivity()
|
|
||||||
.getContentResolver()
|
|
||||||
.query(
|
|
||||||
DisplayPhoto.CONTENT_MAX_DIMENSIONS_URI,
|
|
||||||
new String[] {DisplayPhoto.THUMBNAIL_MAX_DIM},
|
|
||||||
null,
|
|
||||||
null,
|
|
||||||
null);
|
|
||||||
try {
|
|
||||||
c.moveToFirst();
|
|
||||||
value = c.getInt(0);
|
|
||||||
} catch (Exception e) {
|
|
||||||
Log.e(e);
|
|
||||||
}
|
|
||||||
c.close();
|
|
||||||
return value;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private LinearLayout initNumbersFields(final LinphoneContact contact) {
|
private LinearLayout initNumbersFields(final LinphoneContact contact) {
|
||||||
|
|
|
@ -137,10 +137,7 @@ public class ContactAvatar {
|
||||||
|
|
||||||
Bitmap bm = ImageUtils.getRoundBitmapFromUri(v.getContext(), contact.getThumbnailUri());
|
Bitmap bm = ImageUtils.getRoundBitmapFromUri(v.getContext(), contact.getThumbnailUri());
|
||||||
if (bm != null) {
|
if (bm != null) {
|
||||||
holder.contactPicture.setImageBitmap(bm);
|
displayAvatar(bm, holder);
|
||||||
holder.contactPicture.setVisibility(View.VISIBLE);
|
|
||||||
holder.generatedAvatar.setVisibility(View.GONE);
|
|
||||||
holder.generatedAvatarBackground.setVisibility(View.GONE);
|
|
||||||
} else if (generated_avatars) {
|
} else if (generated_avatars) {
|
||||||
holder.generatedAvatar.setVisibility(View.VISIBLE);
|
holder.generatedAvatar.setVisibility(View.VISIBLE);
|
||||||
holder.generatedAvatarBackground.setVisibility(View.VISIBLE);
|
holder.generatedAvatarBackground.setVisibility(View.VISIBLE);
|
||||||
|
@ -151,6 +148,27 @@ public class ContactAvatar {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void displayAvatar(Bitmap bm, ContactAvatarHolder holder) {
|
||||||
|
holder.contactPicture.setImageBitmap(bm);
|
||||||
|
holder.contactPicture.setVisibility(View.VISIBLE);
|
||||||
|
holder.generatedAvatar.setVisibility(View.GONE);
|
||||||
|
holder.generatedAvatarBackground.setVisibility(View.GONE);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void displayAvatar(Bitmap bm, View v) {
|
||||||
|
if (bm == null || v == null) return;
|
||||||
|
|
||||||
|
ContactAvatarHolder holder = new ContactAvatarHolder(v);
|
||||||
|
holder.init();
|
||||||
|
|
||||||
|
holder.generatedAvatar.setVisibility(View.GONE);
|
||||||
|
holder.generatedAvatarBackground.setVisibility(View.GONE);
|
||||||
|
holder.contactPicture.setVisibility(View.VISIBLE);
|
||||||
|
holder.securityLevel.setVisibility(View.GONE);
|
||||||
|
|
||||||
|
displayAvatar(bm, holder);
|
||||||
|
}
|
||||||
|
|
||||||
public static void displayAvatar(LinphoneContact contact, View v) {
|
public static void displayAvatar(LinphoneContact contact, View v) {
|
||||||
displayAvatar(contact, v, false);
|
displayAvatar(contact, v, false);
|
||||||
}
|
}
|
||||||
|
|
|
@ -55,7 +55,7 @@ public class ImageUtils {
|
||||||
return bm;
|
return bm;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Bitmap getRoundBitmap(Bitmap bitmap) {
|
public static Bitmap getRoundBitmap(Bitmap bitmap) {
|
||||||
Bitmap output =
|
Bitmap output =
|
||||||
Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888);
|
Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888);
|
||||||
Canvas canvas = new Canvas(output);
|
Canvas canvas = new Canvas(output);
|
||||||
|
|
Loading…
Reference in a new issue