Fix for black screen when trying to upload a large file
This commit is contained in:
parent
48a8ea1a70
commit
159e9ccfe5
2 changed files with 51 additions and 28 deletions
|
@ -405,4 +405,5 @@
|
||||||
<string name="retry">Retry</string>
|
<string name="retry">Retry</string>
|
||||||
<string name="remote_provisioning_failure">Failed to download or apply remote provisioning profile...</string>
|
<string name="remote_provisioning_failure">Failed to download or apply remote provisioning profile...</string>
|
||||||
<string name="remote_provisioning_again_title">Remote provisioning</string>
|
<string name="remote_provisioning_again_title">Remote provisioning</string>
|
||||||
<string name="remote_provisioning_again_message">Do you want to change the provisioning URI ?</string></resources>
|
<string name="remote_provisioning_again_message">Do you want to change the provisioning URI ?</string>
|
||||||
|
<string name="processing_image">Processing image, can take up to a few seconds depending on the size of the file</string></resources>
|
||||||
|
|
|
@ -41,6 +41,7 @@ import org.linphone.ui.BubbleChat;
|
||||||
|
|
||||||
import android.annotation.SuppressLint;
|
import android.annotation.SuppressLint;
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
|
import android.app.ProgressDialog;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.res.Configuration;
|
import android.content.res.Configuration;
|
||||||
|
@ -49,8 +50,8 @@ import android.graphics.Bitmap;
|
||||||
import android.graphics.BitmapFactory;
|
import android.graphics.BitmapFactory;
|
||||||
import android.graphics.Rect;
|
import android.graphics.Rect;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
|
import android.os.AsyncTask;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
|
||||||
import android.os.Parcelable;
|
import android.os.Parcelable;
|
||||||
import android.provider.MediaStore;
|
import android.provider.MediaStore;
|
||||||
import android.support.v4.app.Fragment;
|
import android.support.v4.app.Fragment;
|
||||||
|
@ -101,7 +102,6 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC
|
||||||
private TextWatcher textWatcher;
|
private TextWatcher textWatcher;
|
||||||
private ViewTreeObserver.OnGlobalLayoutListener keyboardListener;
|
private ViewTreeObserver.OnGlobalLayoutListener keyboardListener;
|
||||||
private ChatMessageAdapter adapter;
|
private ChatMessageAdapter adapter;
|
||||||
private Handler mHandler = new Handler();
|
|
||||||
|
|
||||||
private LinphoneCoreListenerBase mListener;
|
private LinphoneCoreListenerBase mListener;
|
||||||
private ByteArrayOutputStream mDownloadedImageStream;
|
private ByteArrayOutputStream mDownloadedImageStream;
|
||||||
|
@ -497,24 +497,8 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC
|
||||||
if (chatRoom != null && path != null && path.length() > 0 && isNetworkReachable) {
|
if (chatRoom != null && path != null && path.length() > 0 && isNetworkReachable) {
|
||||||
Bitmap bm = BitmapFactory.decodeFile(path);
|
Bitmap bm = BitmapFactory.decodeFile(path);
|
||||||
if (bm != null) {
|
if (bm != null) {
|
||||||
ByteArrayOutputStream stream = new ByteArrayOutputStream();
|
FileUploadPrepareTask task = new FileUploadPrepareTask(getActivity(), path);
|
||||||
bm.compress(Bitmap.CompressFormat.PNG, 100, stream);
|
task.execute(bm);
|
||||||
byte[] byteArray = stream.toByteArray();
|
|
||||||
mUploadingImageStream = new ByteArrayInputStream(byteArray);
|
|
||||||
|
|
||||||
LinphoneContent content = LinphoneCoreFactory.instance().createLinphoneContent("image", "jpeg", byteArray, null);
|
|
||||||
String fileName = path.substring(path.lastIndexOf("/") + 1);
|
|
||||||
content.setName(fileName);
|
|
||||||
|
|
||||||
LinphoneChatMessage message = chatRoom.createFileTransferMessage(content);
|
|
||||||
message.setListener(this);
|
|
||||||
message.setAppData(path);
|
|
||||||
|
|
||||||
uploadLayout.setVisibility(View.VISIBLE);
|
|
||||||
textLayout.setVisibility(View.GONE);
|
|
||||||
|
|
||||||
chatRoom.sendChatMessage(message);
|
|
||||||
currentMessageInFileTransferUploadState = message;
|
|
||||||
} else {
|
} else {
|
||||||
Log.e("Error, bitmap factory can't read " + path);
|
Log.e("Error, bitmap factory can't read " + path);
|
||||||
}
|
}
|
||||||
|
@ -523,6 +507,50 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class FileUploadPrepareTask extends AsyncTask<Bitmap, Void, byte[]> {
|
||||||
|
private String path;
|
||||||
|
private ProgressDialog progressDialog;
|
||||||
|
|
||||||
|
public FileUploadPrepareTask(Context context, String fileToUploadPath) {
|
||||||
|
path = fileToUploadPath;
|
||||||
|
|
||||||
|
uploadLayout.setVisibility(View.VISIBLE);
|
||||||
|
textLayout.setVisibility(View.GONE);
|
||||||
|
|
||||||
|
progressDialog = new ProgressDialog(context);
|
||||||
|
progressDialog.setIndeterminate(true);
|
||||||
|
progressDialog.setMessage(getString(R.string.processing_image));
|
||||||
|
progressDialog.show();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected byte[] doInBackground(Bitmap... params) {
|
||||||
|
Bitmap bm = params[0];
|
||||||
|
ByteArrayOutputStream stream = new ByteArrayOutputStream();
|
||||||
|
bm.compress(Bitmap.CompressFormat.PNG, 100, stream);
|
||||||
|
byte[] byteArray = stream.toByteArray();
|
||||||
|
return byteArray;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onPostExecute(byte[] result) {
|
||||||
|
progressDialog.dismiss();
|
||||||
|
|
||||||
|
mUploadingImageStream = new ByteArrayInputStream(result);
|
||||||
|
|
||||||
|
LinphoneContent content = LinphoneCoreFactory.instance().createLinphoneContent("image", "jpeg", result, null);
|
||||||
|
String fileName = path.substring(path.lastIndexOf("/") + 1);
|
||||||
|
content.setName(fileName);
|
||||||
|
|
||||||
|
LinphoneChatMessage message = chatRoom.createFileTransferMessage(content);
|
||||||
|
message.setListener(ChatFragment.this);
|
||||||
|
message.setAppData(path);
|
||||||
|
|
||||||
|
chatRoom.sendChatMessage(message);
|
||||||
|
currentMessageInFileTransferUploadState = message;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private LinphoneChatMessage getMessageForId(int id) {
|
private LinphoneChatMessage getMessageForId(int id) {
|
||||||
for (LinphoneChatMessage message : chatRoom.getHistory()) {
|
for (LinphoneChatMessage message : chatRoom.getHistory()) {
|
||||||
if (message.getStorageId() == id) {
|
if (message.getStorageId() == id) {
|
||||||
|
@ -610,13 +638,7 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fileToUploadPath != null) {
|
if (fileToUploadPath != null) {
|
||||||
final String filePath = fileToUploadPath;
|
sendImageMessage(fileToUploadPath);
|
||||||
mHandler.post(new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
sendImageMessage(filePath);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
super.onActivityResult(requestCode, resultCode, data);
|
super.onActivityResult(requestCode, resultCode, data);
|
||||||
|
|
Loading…
Reference in a new issue