Update download/upload images outside the chatfragment
This commit is contained in:
parent
d3b2d6c2aa
commit
b5d499799a
3 changed files with 181 additions and 82 deletions
|
@ -21,7 +21,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
|
||||||
import android.graphics.Matrix;
|
import android.graphics.Matrix;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -31,7 +31,6 @@ import org.linphone.compatibility.Compatibility;
|
||||||
import org.linphone.core.LinphoneAddress;
|
import org.linphone.core.LinphoneAddress;
|
||||||
import org.linphone.core.LinphoneBuffer;
|
import org.linphone.core.LinphoneBuffer;
|
||||||
import org.linphone.core.LinphoneChatMessage;
|
import org.linphone.core.LinphoneChatMessage;
|
||||||
import org.linphone.core.LinphoneChatMessage.LinphoneChatMessageListener;
|
|
||||||
import org.linphone.core.LinphoneChatRoom;
|
import org.linphone.core.LinphoneChatRoom;
|
||||||
import org.linphone.core.LinphoneContent;
|
import org.linphone.core.LinphoneContent;
|
||||||
import org.linphone.core.LinphoneCore;
|
import org.linphone.core.LinphoneCore;
|
||||||
|
@ -85,7 +84,7 @@ import android.widget.RelativeLayout;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
public class ChatFragment extends Fragment implements OnClickListener, LinphoneChatMessageListener {
|
public class ChatFragment extends Fragment implements OnClickListener, LinphoneChatMessage.LinphoneChatMessageListener {
|
||||||
private static ChatFragment instance;
|
private static ChatFragment instance;
|
||||||
|
|
||||||
private static final int ADD_PHOTO = 1337;
|
private static final int ADD_PHOTO = 1337;
|
||||||
|
@ -113,9 +112,7 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC
|
||||||
private ChatMessageAdapter adapter;
|
private ChatMessageAdapter adapter;
|
||||||
|
|
||||||
private LinphoneCoreListenerBase mListener;
|
private LinphoneCoreListenerBase mListener;
|
||||||
private ByteArrayOutputStream mDownloadedImageStream;
|
|
||||||
private ByteArrayInputStream mUploadingImageStream;
|
private ByteArrayInputStream mUploadingImageStream;
|
||||||
private int mDownloadedImageStreamSize;
|
|
||||||
private LinphoneChatMessage currentMessageInFileTransferUploadState;
|
private LinphoneChatMessage currentMessageInFileTransferUploadState;
|
||||||
|
|
||||||
public static boolean isInstanciated() {
|
public static boolean isInstanciated() {
|
||||||
|
@ -127,7 +124,8 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
instance = this;
|
instance = this;
|
||||||
View view = inflater.inflate(R.layout.chat, container, false);
|
View view = inflater.inflate(R.layout.chat, container, false);
|
||||||
|
|
||||||
|
LinphoneManager.addListener(this);
|
||||||
// Retain the fragment across configuration changes
|
// Retain the fragment across configuration changes
|
||||||
setRetainInstance(true);
|
setRetainInstance(true);
|
||||||
|
|
||||||
|
@ -194,6 +192,7 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC
|
||||||
progressBar.setProgress(0);
|
progressBar.setProgress(0);
|
||||||
currentMessageInFileTransferUploadState.cancelFileTransfer();
|
currentMessageInFileTransferUploadState.cancelFileTransfer();
|
||||||
currentMessageInFileTransferUploadState = null;
|
currentMessageInFileTransferUploadState = null;
|
||||||
|
LinphoneManager.getInstance().setUploadPendingFileMessage(null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -283,7 +282,6 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC
|
||||||
topBar.setVisibility(View.GONE);
|
topBar.setVisibility(View.GONE);
|
||||||
}
|
}
|
||||||
contactPicture.setVisibility(View.GONE);
|
contactPicture.setVisibility(View.GONE);
|
||||||
//scrollToEnd();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void hideKeyboardVisibleMode() {
|
public void hideKeyboardVisibleMode() {
|
||||||
|
@ -292,7 +290,6 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC
|
||||||
if (isOrientationLandscape && topBar != null) {
|
if (isOrientationLandscape && topBar != null) {
|
||||||
topBar.setVisibility(View.VISIBLE);
|
topBar.setVisibility(View.VISIBLE);
|
||||||
}
|
}
|
||||||
//scrollToEnd();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class ChatMessageAdapter extends BaseAdapter {
|
class ChatMessageAdapter extends BaseAdapter {
|
||||||
|
@ -327,7 +324,7 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC
|
||||||
public View getView(int position, View convertView, ViewGroup parent) {
|
public View getView(int position, View convertView, ViewGroup parent) {
|
||||||
LinphoneChatMessage message = history[position];
|
LinphoneChatMessage message = history[position];
|
||||||
|
|
||||||
BubbleChat bubble = new BubbleChat(context, message, ChatFragment.this);
|
BubbleChat bubble = new BubbleChat(context, message);
|
||||||
View v = bubble.getView();
|
View v = bubble.getView();
|
||||||
|
|
||||||
registerForContextMenu(v);
|
registerForContextMenu(v);
|
||||||
|
@ -453,6 +450,8 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC
|
||||||
lc.removeListener(mListener);
|
lc.removeListener(mListener);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LinphoneManager.removeListener(this);
|
||||||
|
|
||||||
onSaveInstanceState(getArguments());
|
onSaveInstanceState(getArguments());
|
||||||
|
|
||||||
//Hide keybord
|
//Hide keybord
|
||||||
|
@ -479,6 +478,29 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC
|
||||||
LinphoneActivity.instance().updateChatFragment(this);
|
LinphoneActivity.instance().updateChatFragment(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LinphoneManager.addListener(this);
|
||||||
|
|
||||||
|
final LinphoneChatMessage msg = LinphoneManager.getInstance().getMessageUploadPending();
|
||||||
|
if(msg != null){
|
||||||
|
uploadLayout.setVisibility(View.VISIBLE);
|
||||||
|
textLayout.setVisibility(View.GONE);
|
||||||
|
if(msg.getFileTransferInformation() != null){
|
||||||
|
progressBar.setProgress(msg.getFileTransferInformation().getRealSize());
|
||||||
|
}
|
||||||
|
|
||||||
|
cancelUpload.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
uploadLayout.setVisibility(View.GONE);
|
||||||
|
textLayout.setVisibility(View.VISIBLE);
|
||||||
|
progressBar.setProgress(0);
|
||||||
|
msg.cancelFileTransfer();
|
||||||
|
LinphoneManager.getInstance().setUploadPendingFileMessage(null);
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
String draft = getArguments().getString("messageDraft");
|
String draft = getArguments().getString("messageDraft");
|
||||||
message.setText(draft);
|
message.setText(draft);
|
||||||
|
|
||||||
|
@ -504,13 +526,14 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC
|
||||||
|
|
||||||
if (chatRoom != null && messageToSend != null && messageToSend.length() > 0 && isNetworkReachable) {
|
if (chatRoom != null && messageToSend != null && messageToSend.length() > 0 && isNetworkReachable) {
|
||||||
LinphoneChatMessage message = chatRoom.createLinphoneChatMessage(messageToSend);
|
LinphoneChatMessage message = chatRoom.createLinphoneChatMessage(messageToSend);
|
||||||
message.setListener(this);
|
|
||||||
chatRoom.sendChatMessage(message);
|
chatRoom.sendChatMessage(message);
|
||||||
|
|
||||||
if (LinphoneActivity.isInstanciated()) {
|
if (LinphoneActivity.isInstanciated()) {
|
||||||
LinphoneActivity.instance().onMessageSent(sipUri, messageToSend);
|
LinphoneActivity.instance().onMessageSent(sipUri, messageToSend);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
message.setListener(LinphoneManager.getInstance());
|
||||||
|
|
||||||
invalidate();
|
invalidate();
|
||||||
Log.i("Sent message current status: " + message.getStatus());
|
Log.i("Sent message current status: " + message.getStatus());
|
||||||
} else if (!isNetworkReachable && LinphoneActivity.isInstanciated()) {
|
} else if (!isNetworkReachable && LinphoneActivity.isInstanciated()) {
|
||||||
|
@ -600,9 +623,12 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC
|
||||||
content.setName(fileName);
|
content.setName(fileName);
|
||||||
|
|
||||||
LinphoneChatMessage message = chatRoom.createFileTransferMessage(content);
|
LinphoneChatMessage message = chatRoom.createFileTransferMessage(content);
|
||||||
message.setListener(ChatFragment.this);
|
message.setListener(LinphoneManager.getInstance());
|
||||||
message.setAppData(path);
|
message.setAppData(path);
|
||||||
|
|
||||||
|
LinphoneManager.getInstance().setUploadPendingFileMessage(message);
|
||||||
|
LinphoneManager.getInstance().setUploadingImageStream(mUploadingImageStream);
|
||||||
|
|
||||||
chatRoom.sendChatMessage(message);
|
chatRoom.sendChatMessage(message);
|
||||||
currentMessageInFileTransferUploadState = message;
|
currentMessageInFileTransferUploadState = message;
|
||||||
}
|
}
|
||||||
|
@ -703,32 +729,6 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onLinphoneChatMessageStateChanged(LinphoneChatMessage msg, State state) {
|
public void onLinphoneChatMessageStateChanged(LinphoneChatMessage msg, State state) {
|
||||||
if (LinphoneActivity.isInstanciated() && state != LinphoneChatMessage.State.InProgress) {
|
|
||||||
if (msg != null) {
|
|
||||||
LinphoneActivity.instance().onMessageStateChanged(sipUri, msg.getText(), state.toInt());
|
|
||||||
}
|
|
||||||
invalidate();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (state == State.FileTransferDone) {
|
|
||||||
if (mDownloadedImageStream != null) {
|
|
||||||
byte[] bytes = mDownloadedImageStream.toByteArray();
|
|
||||||
Bitmap bm = BitmapFactory.decodeByteArray(bytes, 0, mDownloadedImageStreamSize);
|
|
||||||
|
|
||||||
String path = msg.getExternalBodyUrl();
|
|
||||||
String fileName = path.substring(path.lastIndexOf("/") + 1);
|
|
||||||
String url = MediaStore.Images.Media.insertImage(getActivity().getContentResolver(), bm, fileName, null);
|
|
||||||
if (url != null) {
|
|
||||||
msg.setAppData(url);
|
|
||||||
}
|
|
||||||
|
|
||||||
mDownloadedImageStream = null;
|
|
||||||
mDownloadedImageStreamSize = 0;
|
|
||||||
} else if (mUploadingImageStream != null) {
|
|
||||||
mUploadingImageStream = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (state == State.FileTransferDone || state == State.FileTransferError) {
|
if (state == State.FileTransferDone || state == State.FileTransferError) {
|
||||||
uploadLayout.setVisibility(View.GONE);
|
uploadLayout.setVisibility(View.GONE);
|
||||||
textLayout.setVisibility(View.VISIBLE);
|
textLayout.setVisibility(View.VISIBLE);
|
||||||
|
@ -740,33 +740,10 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onLinphoneChatMessageFileTransferReceived(LinphoneChatMessage msg, LinphoneContent content, LinphoneBuffer buffer) {
|
public void onLinphoneChatMessageFileTransferReceived(LinphoneChatMessage msg, LinphoneContent content, LinphoneBuffer buffer) {
|
||||||
if (mDownloadedImageStream == null) {
|
|
||||||
mDownloadedImageStream = new ByteArrayOutputStream();
|
|
||||||
mDownloadedImageStreamSize = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (buffer != null && buffer.getSize() > 0) {
|
|
||||||
try {
|
|
||||||
mDownloadedImageStream.write(buffer.getContent());
|
|
||||||
mDownloadedImageStreamSize += buffer.getSize();
|
|
||||||
} catch (IOException e) {
|
|
||||||
Log.e(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onLinphoneChatMessageFileTransferSent(LinphoneChatMessage msg, LinphoneContent content, int offset, int size, LinphoneBuffer bufferToFill) {
|
public void onLinphoneChatMessageFileTransferSent(LinphoneChatMessage msg, LinphoneContent content, int offset, int size, LinphoneBuffer bufferToFill) {
|
||||||
if (mUploadingImageStream != null && size > 0) {
|
|
||||||
byte[] data = new byte[size];
|
|
||||||
int read = mUploadingImageStream.read(data, 0, size);
|
|
||||||
if (read > 0) {
|
|
||||||
bufferToFill.setContent(data);
|
|
||||||
bufferToFill.setSize(read);
|
|
||||||
} else {
|
|
||||||
Log.e("Error, upload task asking for more bytes(" + size + ") than available (" + mUploadingImageStream.available() + ")");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -22,13 +22,17 @@ import static android.media.AudioManager.MODE_RINGTONE;
|
||||||
import static android.media.AudioManager.STREAM_RING;
|
import static android.media.AudioManager.STREAM_RING;
|
||||||
import static android.media.AudioManager.STREAM_VOICE_CALL;
|
import static android.media.AudioManager.STREAM_VOICE_CALL;
|
||||||
|
|
||||||
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
|
import java.io.FileNotFoundException;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.Timer;
|
import java.util.Timer;
|
||||||
import java.util.TimerTask;
|
import java.util.TimerTask;
|
||||||
|
@ -36,6 +40,7 @@ import java.util.TimerTask;
|
||||||
import org.linphone.compatibility.Compatibility;
|
import org.linphone.compatibility.Compatibility;
|
||||||
import org.linphone.core.CallDirection;
|
import org.linphone.core.CallDirection;
|
||||||
import org.linphone.core.LinphoneAddress;
|
import org.linphone.core.LinphoneAddress;
|
||||||
|
import org.linphone.core.LinphoneBuffer;
|
||||||
import org.linphone.core.LinphoneCall;
|
import org.linphone.core.LinphoneCall;
|
||||||
import org.linphone.core.LinphoneCall.State;
|
import org.linphone.core.LinphoneCall.State;
|
||||||
import org.linphone.core.LinphoneCallParams;
|
import org.linphone.core.LinphoneCallParams;
|
||||||
|
@ -88,10 +93,12 @@ import android.net.ConnectivityManager;
|
||||||
import android.net.NetworkInfo;
|
import android.net.NetworkInfo;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
|
import android.os.Environment;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.PowerManager;
|
import android.os.PowerManager;
|
||||||
import android.os.PowerManager.WakeLock;
|
import android.os.PowerManager.WakeLock;
|
||||||
import android.os.Vibrator;
|
import android.os.Vibrator;
|
||||||
|
import android.provider.MediaStore;
|
||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
import android.provider.Settings.SettingNotFoundException;
|
import android.provider.Settings.SettingNotFoundException;
|
||||||
import android.telephony.TelephonyManager;
|
import android.telephony.TelephonyManager;
|
||||||
|
@ -116,7 +123,7 @@ import android.widget.Toast;
|
||||||
* @author Guillaume Beraudo
|
* @author Guillaume Beraudo
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class LinphoneManager implements LinphoneCoreListener {
|
public class LinphoneManager implements LinphoneCoreListener, LinphoneChatMessage.LinphoneChatMessageListener {
|
||||||
|
|
||||||
private static LinphoneManager instance;
|
private static LinphoneManager instance;
|
||||||
private Context mServiceContext;
|
private Context mServiceContext;
|
||||||
|
@ -133,9 +140,21 @@ public class LinphoneManager implements LinphoneCoreListener {
|
||||||
private ConnectivityManager mConnectivityManager;
|
private ConnectivityManager mConnectivityManager;
|
||||||
private Handler mHandler = new Handler();
|
private Handler mHandler = new Handler();
|
||||||
private WakeLock mIncallWakeLock;
|
private WakeLock mIncallWakeLock;
|
||||||
|
private static List<LinphoneChatMessage> mPendingChatFileMessage;
|
||||||
|
private static LinphoneChatMessage mUploadPendingFileMessage;
|
||||||
|
|
||||||
public String wizardLoginViewDomain = null;
|
public String wizardLoginViewDomain = null;
|
||||||
|
|
||||||
|
private static List<LinphoneChatMessage.LinphoneChatMessageListener> simpleListeners = new ArrayList<LinphoneChatMessage.LinphoneChatMessageListener>();
|
||||||
|
public static void addListener(LinphoneChatMessage.LinphoneChatMessageListener listener) {
|
||||||
|
if (!simpleListeners.contains(listener)) {
|
||||||
|
simpleListeners.add(listener);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public static void removeListener(LinphoneChatMessage.LinphoneChatMessageListener listener) {
|
||||||
|
simpleListeners.remove(listener);
|
||||||
|
}
|
||||||
|
|
||||||
protected LinphoneManager(final Context c) {
|
protected LinphoneManager(final Context c) {
|
||||||
sExited = false;
|
sExited = false;
|
||||||
mServiceContext = c;
|
mServiceContext = c;
|
||||||
|
@ -156,6 +175,7 @@ public class LinphoneManager implements LinphoneCoreListener {
|
||||||
mPowerManager = (PowerManager) c.getSystemService(Context.POWER_SERVICE);
|
mPowerManager = (PowerManager) c.getSystemService(Context.POWER_SERVICE);
|
||||||
mConnectivityManager = (ConnectivityManager) c.getSystemService(Context.CONNECTIVITY_SERVICE);
|
mConnectivityManager = (ConnectivityManager) c.getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||||
mR = c.getResources();
|
mR = c.getResources();
|
||||||
|
mPendingChatFileMessage = new ArrayList<LinphoneChatMessage>();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final int LINPHONE_VOLUME_STREAM = STREAM_VOICE_CALL;
|
private static final int LINPHONE_VOLUME_STREAM = STREAM_VOICE_CALL;
|
||||||
|
@ -170,6 +190,7 @@ public class LinphoneManager implements LinphoneCoreListener {
|
||||||
private final String mPauseSoundFile;
|
private final String mPauseSoundFile;
|
||||||
private final String mChatDatabaseFile;
|
private final String mChatDatabaseFile;
|
||||||
private final String mErrorToneFile;
|
private final String mErrorToneFile;
|
||||||
|
private ByteArrayInputStream mUploadingImageStream;
|
||||||
|
|
||||||
private Timer mTimer;
|
private Timer mTimer;
|
||||||
|
|
||||||
|
@ -213,6 +234,98 @@ public class LinphoneManager implements LinphoneCoreListener {
|
||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void addDownloadMessagePending(LinphoneChatMessage message){
|
||||||
|
synchronized (mPendingChatFileMessage) {
|
||||||
|
mPendingChatFileMessage.add(message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isMessagePending(LinphoneChatMessage message){
|
||||||
|
boolean messagePending = false;
|
||||||
|
synchronized (mPendingChatFileMessage) {
|
||||||
|
for (LinphoneChatMessage chat : mPendingChatFileMessage) {
|
||||||
|
if (chat.getStorageId() == message.getStorageId()) {
|
||||||
|
messagePending = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return messagePending;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void removePendingMessage(LinphoneChatMessage message){
|
||||||
|
synchronized (mPendingChatFileMessage) {
|
||||||
|
for (LinphoneChatMessage chat : mPendingChatFileMessage) {
|
||||||
|
if (chat.getStorageId() == message.getStorageId()) {
|
||||||
|
mPendingChatFileMessage.remove(chat);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUploadPendingFileMessage(LinphoneChatMessage message){
|
||||||
|
mUploadPendingFileMessage = message;
|
||||||
|
}
|
||||||
|
|
||||||
|
public LinphoneChatMessage getMessageUploadPending(){
|
||||||
|
return mUploadPendingFileMessage;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUploadingImageStream(ByteArrayInputStream array){
|
||||||
|
this.mUploadingImageStream = array;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onLinphoneChatMessageStateChanged(LinphoneChatMessage msg, LinphoneChatMessage.State state) {
|
||||||
|
if (state == LinphoneChatMessage.State.FileTransferDone) {
|
||||||
|
if(msg.isOutgoing() && mUploadingImageStream != null){
|
||||||
|
mUploadPendingFileMessage = null;
|
||||||
|
mUploadingImageStream = null;
|
||||||
|
} else {
|
||||||
|
File file = new File(Environment.getExternalStorageDirectory(), msg.getFileTransferInformation().getName());
|
||||||
|
try {
|
||||||
|
String url = MediaStore.Images.Media.insertImage(getContext().getContentResolver(), file.getPath(), msg.getFileTransferInformation().getName(), null);
|
||||||
|
msg.setAppData(url);
|
||||||
|
file.delete();
|
||||||
|
} catch (FileNotFoundException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
removePendingMessage(msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (LinphoneChatMessage.LinphoneChatMessageListener l: simpleListeners) {
|
||||||
|
l.onLinphoneChatMessageStateChanged(msg, state);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onLinphoneChatMessageFileTransferReceived(LinphoneChatMessage msg, LinphoneContent content, LinphoneBuffer buffer) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onLinphoneChatMessageFileTransferSent(LinphoneChatMessage msg, LinphoneContent content, int offset, int size, LinphoneBuffer bufferToFill) {
|
||||||
|
if (mUploadingImageStream != null && size > 0) {
|
||||||
|
byte[] data = new byte[size];
|
||||||
|
int read = mUploadingImageStream.read(data, 0, size);
|
||||||
|
if (read > 0) {
|
||||||
|
bufferToFill.setContent(data);
|
||||||
|
bufferToFill.setSize(read);
|
||||||
|
} else {
|
||||||
|
Log.e("Error, upload task asking for more bytes(" + size + ") than available (" + mUploadingImageStream.available() + ")");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onLinphoneChatMessageFileTransferProgressChanged(LinphoneChatMessage msg, LinphoneContent content, int offset, int total) {
|
||||||
|
for (LinphoneChatMessage.LinphoneChatMessageListener l: simpleListeners) {
|
||||||
|
l.onLinphoneChatMessageFileTransferProgressChanged(msg, content, offset, total);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private boolean isPresenceModelActivitySet() {
|
private boolean isPresenceModelActivitySet() {
|
||||||
LinphoneCore lc = getLcIfManagerNotDestroyedOrNull();
|
LinphoneCore lc = getLcIfManagerNotDestroyedOrNull();
|
||||||
if (isInstanciated() && lc != null) {
|
if (isInstanciated() && lc != null) {
|
||||||
|
@ -331,7 +444,6 @@ public class LinphoneManager implements LinphoneCoreListener {
|
||||||
LinphoneManager.getLc().setVideoDevice(camId);
|
LinphoneManager.getLc().setVideoDevice(camId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static interface AddressType {
|
public static interface AddressType {
|
||||||
void setText(CharSequence s);
|
void setText(CharSequence s);
|
||||||
CharSequence getText();
|
CharSequence getText();
|
||||||
|
@ -1097,7 +1209,6 @@ public class LinphoneManager implements LinphoneCoreListener {
|
||||||
return distanceInCm < threshold;
|
return distanceInCm < threshold;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private static boolean sLastProximitySensorValueNearby;
|
private static boolean sLastProximitySensorValueNearby;
|
||||||
private static Set<Activity> sProximityDependentActivities = new HashSet<Activity>();
|
private static Set<Activity> sProximityDependentActivities = new HashSet<Activity>();
|
||||||
private static SensorEventListener sProximitySensorListener = new SensorEventListener() {
|
private static SensorEventListener sProximitySensorListener = new SensorEventListener() {
|
||||||
|
|
|
@ -17,6 +17,7 @@ You should have received a copy of the GNU General Public License
|
||||||
along with this program; if not, write to the Free Software
|
along with this program; if not, write to the Free Software
|
||||||
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
*/
|
*/
|
||||||
|
import java.io.File;
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.lang.ref.WeakReference;
|
import java.lang.ref.WeakReference;
|
||||||
|
@ -25,6 +26,7 @@ import java.util.Calendar;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
|
import org.linphone.LinphoneManager;
|
||||||
import org.linphone.R;
|
import org.linphone.R;
|
||||||
import org.linphone.core.LinphoneChatMessage;
|
import org.linphone.core.LinphoneChatMessage;
|
||||||
import org.linphone.core.LinphoneChatMessage.State;
|
import org.linphone.core.LinphoneChatMessage.State;
|
||||||
|
@ -42,6 +44,7 @@ import android.graphics.drawable.Drawable;
|
||||||
import android.media.ThumbnailUtils;
|
import android.media.ThumbnailUtils;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.AsyncTask;
|
import android.os.AsyncTask;
|
||||||
|
import android.os.Environment;
|
||||||
import android.provider.MediaStore;
|
import android.provider.MediaStore;
|
||||||
import android.text.Html;
|
import android.text.Html;
|
||||||
import android.text.Spannable;
|
import android.text.Spannable;
|
||||||
|
@ -100,17 +103,15 @@ public class BubbleChat {
|
||||||
private RelativeLayout view;
|
private RelativeLayout view;
|
||||||
private ImageView statusView;
|
private ImageView statusView;
|
||||||
private LinphoneChatMessage nativeMessage;
|
private LinphoneChatMessage nativeMessage;
|
||||||
private LinphoneChatMessage.LinphoneChatMessageListener fileTransferListener;
|
|
||||||
private Context mContext;
|
private Context mContext;
|
||||||
private static final int SIZE_MAX = 512;
|
private static final int SIZE_MAX = 512;
|
||||||
|
|
||||||
@SuppressLint("InflateParams")
|
@SuppressLint("InflateParams")
|
||||||
public BubbleChat(final Context context, LinphoneChatMessage message, LinphoneChatMessage.LinphoneChatMessageListener listener) {
|
public BubbleChat(final Context context, LinphoneChatMessage message) {
|
||||||
if (message == null) {
|
if (message == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
nativeMessage = message;
|
nativeMessage = message;
|
||||||
fileTransferListener = listener;
|
|
||||||
mContext = context;
|
mContext = context;
|
||||||
|
|
||||||
view = new RelativeLayout(context);
|
view = new RelativeLayout(context);
|
||||||
|
@ -153,22 +154,32 @@ public class BubbleChat {
|
||||||
|
|
||||||
String appData = message.getAppData();
|
String appData = message.getAppData();
|
||||||
if (appData == null) {
|
if (appData == null) {
|
||||||
download.setVisibility(View.VISIBLE);
|
if(LinphoneManager.getInstance().isMessagePending(nativeMessage)){
|
||||||
download.setOnClickListener(new OnClickListener() {
|
download.setEnabled(false);
|
||||||
@Override
|
ProgressBar spinner = (ProgressBar) layout.findViewById(R.id.spinner);
|
||||||
public void onClick(View v) {
|
spinner.setVisibility(View.VISIBLE);
|
||||||
v.setEnabled(false);
|
download.setVisibility(View.GONE);
|
||||||
ProgressBar spinner = (ProgressBar) view.findViewById(R.id.spinner);
|
} else {
|
||||||
spinner.setVisibility(View.VISIBLE);
|
download.setVisibility(View.VISIBLE);
|
||||||
v.setVisibility(View.GONE);
|
download.setOnClickListener(new OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
v.setEnabled(false);
|
||||||
|
ProgressBar spinner = (ProgressBar) view.findViewById(R.id.spinner);
|
||||||
|
spinner.setVisibility(View.VISIBLE);
|
||||||
|
v.setVisibility(View.GONE);
|
||||||
|
|
||||||
nativeMessage.setListener(fileTransferListener);
|
File file = new File(Environment.getExternalStorageDirectory(), nativeMessage.getFileTransferInformation().getName());
|
||||||
nativeMessage.downloadFile();
|
nativeMessage.setListener(LinphoneManager.getInstance());
|
||||||
}
|
nativeMessage.setFileTransferFilepath(file.getPath());
|
||||||
});
|
nativeMessage.downloadFile();
|
||||||
|
LinphoneManager.getInstance().addDownloadMessagePending(nativeMessage);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
imageView.setVisibility(View.VISIBLE);
|
imageView.setVisibility(View.VISIBLE);
|
||||||
loadBitmap(appData, imageView);
|
loadBitmap(appData, imageView);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
TextView msgView = (TextView) layout.findViewById(R.id.message);
|
TextView msgView = (TextView) layout.findViewById(R.id.message);
|
||||||
|
@ -325,7 +336,7 @@ public class BubbleChat {
|
||||||
task.execute(path);
|
task.execute(path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private class BitmapWorkerTask extends AsyncTask<String, Void, Bitmap> {
|
private class BitmapWorkerTask extends AsyncTask<String, Void, Bitmap> {
|
||||||
private final WeakReference<ImageView> imageViewReference;
|
private final WeakReference<ImageView> imageViewReference;
|
||||||
public String path;
|
public String path;
|
||||||
|
|
Loading…
Reference in a new issue