Started to handle pictures in liblinphone message storage
This commit is contained in:
parent
b8490bac65
commit
015b83c9ca
3 changed files with 42 additions and 25 deletions
|
@ -117,6 +117,7 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC
|
||||||
private HashMap<Integer, String> latestImageMessages;
|
private HashMap<Integer, String> latestImageMessages;
|
||||||
private int messagesFilterLimit = 0;
|
private int messagesFilterLimit = 0;
|
||||||
private List<ChatMessage> messagesList;
|
private List<ChatMessage> messagesList;
|
||||||
|
private boolean useLinphoneMessageStorage;
|
||||||
|
|
||||||
private ProgressBar progressBar;
|
private ProgressBar progressBar;
|
||||||
private int bytesSent;
|
private int bytesSent;
|
||||||
|
@ -136,6 +137,8 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC
|
||||||
|
|
||||||
view = inflater.inflate(R.layout.chat, container, false);
|
view = inflater.inflate(R.layout.chat, container, false);
|
||||||
|
|
||||||
|
useLinphoneMessageStorage = getResources().getBoolean(R.bool.use_linphone_chat_storage);
|
||||||
|
|
||||||
contactName = (TextView) view.findViewById(R.id.contactName);
|
contactName = (TextView) view.findViewById(R.id.contactName);
|
||||||
contactPicture = (AvatarWithShadow) view.findViewById(R.id.contactPicture);
|
contactPicture = (AvatarWithShadow) view.findViewById(R.id.contactPicture);
|
||||||
|
|
||||||
|
@ -406,7 +409,11 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC
|
||||||
public void run() {
|
public void run() {
|
||||||
final Bitmap bm = ChatFragment.downloadImage(url);
|
final Bitmap bm = ChatFragment.downloadImage(url);
|
||||||
if (bm != null) {
|
if (bm != null) {
|
||||||
LinphoneActivity.instance().getChatStorage().saveImage(finalId, bm);
|
if (useLinphoneMessageStorage) {
|
||||||
|
saveImage(bm, finalId);
|
||||||
|
} else {
|
||||||
|
LinphoneActivity.instance().getChatStorage().saveImage(finalId, bm);
|
||||||
|
}
|
||||||
mHandler.post(new Runnable() {
|
mHandler.post(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
@ -468,7 +475,9 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC
|
||||||
menu.add(v.getId(), MENU_DELETE_MESSAGE, 0, getString(R.string.delete));
|
menu.add(v.getId(), MENU_DELETE_MESSAGE, 0, getString(R.string.delete));
|
||||||
ImageView iv = (ImageView) v.findViewById(R.id.image);
|
ImageView iv = (ImageView) v.findViewById(R.id.image);
|
||||||
if (iv != null && iv.getVisibility() == View.VISIBLE) {
|
if (iv != null && iv.getVisibility() == View.VISIBLE) {
|
||||||
menu.add(v.getId(), MENU_SAVE_PICTURE, 0, getString(R.string.save_picture));
|
if (!useLinphoneMessageStorage) {
|
||||||
|
menu.add(v.getId(), MENU_SAVE_PICTURE, 0, getString(R.string.save_picture));
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
menu.add(v.getId(), MENU_COPY_TEXT, 0, getString(R.string.copy_text));
|
menu.add(v.getId(), MENU_COPY_TEXT, 0, getString(R.string.copy_text));
|
||||||
}
|
}
|
||||||
|
@ -623,23 +632,22 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else if (message.getExternalBodyUrl() != null) {
|
} else if (message.getExternalBodyUrl() != null) {
|
||||||
byte[] rawImage = LinphoneActivity.instance().getChatStorage().getRawImageFromMessage(id);
|
Bitmap bm = null;
|
||||||
if (rawImage == null) {
|
if (useLinphoneMessageStorage) {
|
||||||
mHandler.post(new Runnable() {
|
//TODO: Try to read image from file
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
displayImageMessage(id, null, String.valueOf(message.getTime()), true, null, messagesLayout, message.getExternalBodyUrl());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
} else {
|
} else {
|
||||||
final Bitmap bm = BitmapFactory.decodeByteArray(rawImage, 0, rawImage.length);
|
byte[] rawImage = LinphoneActivity.instance().getChatStorage().getRawImageFromMessage(id);
|
||||||
mHandler.post(new Runnable() {
|
if (rawImage != null) {
|
||||||
@Override
|
bm = BitmapFactory.decodeByteArray(rawImage, 0, rawImage.length);
|
||||||
public void run() {
|
}
|
||||||
displayImageMessage(id, bm, String.valueOf(message.getTime()), true, null, messagesLayout, "");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
final Bitmap fbm = bm;
|
||||||
|
mHandler.post(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
displayImageMessage(id, fbm, String.valueOf(message.getTime()), true, null, messagesLayout, fbm == null ? "" : message.getExternalBodyUrl());
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
scrollToEnd();
|
scrollToEnd();
|
||||||
}
|
}
|
||||||
|
@ -727,10 +735,17 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC
|
||||||
}
|
}
|
||||||
|
|
||||||
private void saveImage(int id) {
|
private void saveImage(int id) {
|
||||||
|
byte[] rawImage = LinphoneActivity.instance().getChatStorage().getRawImageFromMessage(id);
|
||||||
|
Bitmap bm = BitmapFactory.decodeByteArray(rawImage, 0, rawImage.length);
|
||||||
|
if (saveImage(bm, id)) {
|
||||||
|
Toast.makeText(getActivity(), getString(R.string.image_saved), Toast.LENGTH_SHORT).show();
|
||||||
|
} else {
|
||||||
|
Toast.makeText(getActivity(), getString(R.string.image_not_saved), Toast.LENGTH_LONG).show();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean saveImage(Bitmap bm, int id) {
|
||||||
try {
|
try {
|
||||||
byte[] rawImage = LinphoneActivity.instance().getChatStorage().getRawImageFromMessage(id);
|
|
||||||
Bitmap bm = BitmapFactory.decodeByteArray(rawImage, 0, rawImage.length);
|
|
||||||
|
|
||||||
String path = Environment.getExternalStorageDirectory().toString();
|
String path = Environment.getExternalStorageDirectory().toString();
|
||||||
OutputStream fOut = null;
|
OutputStream fOut = null;
|
||||||
File file = new File(path, getString(R.string.picture_name_format).replace("%s", String.valueOf(id)));
|
File file = new File(path, getString(R.string.picture_name_format).replace("%s", String.valueOf(id)));
|
||||||
|
@ -739,13 +754,15 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC
|
||||||
bm.compress(Bitmap.CompressFormat.JPEG, 100, fOut);
|
bm.compress(Bitmap.CompressFormat.JPEG, 100, fOut);
|
||||||
fOut.flush();
|
fOut.flush();
|
||||||
fOut.close();
|
fOut.close();
|
||||||
|
|
||||||
|
//TODO: Update url path in liblinphone database
|
||||||
|
|
||||||
Toast.makeText(getActivity(), getString(R.string.image_saved), Toast.LENGTH_SHORT).show();
|
|
||||||
MediaStore.Images.Media.insertImage(getActivity().getContentResolver(),file.getAbsolutePath(),file.getName(),file.getName());
|
MediaStore.Images.Media.insertImage(getActivity().getContentResolver(),file.getAbsolutePath(),file.getName(),file.getName());
|
||||||
|
return true;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Toast.makeText(getActivity(), getString(R.string.image_not_saved), Toast.LENGTH_LONG).show();
|
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private long hashBitmap(Bitmap bmp){
|
private long hashBitmap(Bitmap bmp){
|
||||||
|
|
|
@ -162,7 +162,7 @@ public class ChatStorage {
|
||||||
|
|
||||||
public void saveImage(int id, Bitmap image) {
|
public void saveImage(int id, Bitmap image) {
|
||||||
if (useNativeAPI) {
|
if (useNativeAPI) {
|
||||||
//TODO
|
//Handled before this point
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -409,7 +409,7 @@ public class ChatStorage {
|
||||||
|
|
||||||
public byte[] getRawImageFromMessage(int id) {
|
public byte[] getRawImageFromMessage(int id) {
|
||||||
if (useNativeAPI) {
|
if (useNativeAPI) {
|
||||||
//TODO
|
//Handled before this point
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
Subproject commit 88a0da21c15c3ac031e55b40e219aebee85e82b0
|
Subproject commit d56d927caf4c22554e333ff3227628da2d370a65
|
Loading…
Reference in a new issue