Fix issue in received image display + manually give picture bytes to liblinphone (instead of using setFileTransferFilePath) + added migration code to update the sharing server url

This commit is contained in:
Sylvain Berfini 2015-03-17 15:02:32 +01:00
parent f90327e58c
commit 48a8ea1a70
9 changed files with 70 additions and 53 deletions

View file

@ -7,6 +7,7 @@
<TextView
android:id="@+id/message"
android:visibility="gone"
android:textColor="@android:color/black"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
@ -14,6 +15,7 @@
<ImageView
android:id="@+id/image"
android:visibility="gone"
android:adjustViewBounds="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"

View file

@ -8,6 +8,7 @@
<ImageView
android:contentDescription="@string/content_description_message_status"
android:id="@+id/status"
android:visibility="gone"
android:layout_gravity="bottom"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
@ -25,6 +26,7 @@
<TextView
android:id="@+id/message"
android:visibility="gone"
android:linksClickable="true"
android:autoLink="web"
android:textColor="@android:color/black"

View file

@ -9,12 +9,14 @@
<TextView
android:id="@+id/message"
android:layout_gravity="left"
android:visibility="gone"
android:textColor="@android:color/black"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<ImageView
android:id="@+id/image"
android:visibility="gone"
android:adjustViewBounds="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"

View file

@ -9,6 +9,7 @@
<TextView
android:id="@+id/message"
android:layout_gravity="right"
android:visibility="gone"
android:textColor="@android:color/black"
android:linksClickable="true"
android:autoLink="web"
@ -17,6 +18,7 @@
<ImageView
android:id="@+id/image"
android:visibility="gone"
android:adjustViewBounds="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"

View file

@ -12,7 +12,7 @@ keepalive_period=30000
size=vga
[app]
sharing_server=https://www.linphone.org:444/upload.php
sharing_server=https://www.linphone.org:444/lft.php
tunnel=disabled
[tunnel]

View file

@ -18,6 +18,7 @@ along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.ArrayList;
@ -104,6 +105,7 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC
private LinphoneCoreListenerBase mListener;
private ByteArrayOutputStream mDownloadedImageStream;
private ByteArrayInputStream mUploadingImageStream;
private int mDownloadedImageStreamSize;
private LinphoneChatMessage currentMessageInFileTransferUploadState;
@ -498,13 +500,13 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bm.compress(Bitmap.CompressFormat.PNG, 100, stream);
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.setFileTransferFilepath(path);
message.setListener(this);
message.setAppData(path);
@ -630,20 +632,26 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC
invalidate();
}
if (state == State.FileTransferDone && 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);
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;
}
mDownloadedImageStream = null;
mDownloadedImageStreamSize = 0;
} else if (state == State.FileTransferDone || state == State.FileTransferError) {
}
if (state == State.FileTransferDone || state == State.FileTransferError) {
uploadLayout.setVisibility(View.GONE);
textLayout.setVisibility(View.VISIBLE);
progressBar.setProgress(0);
@ -671,7 +679,12 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC
@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);
bufferToFill.setContent(data);
bufferToFill.setSize(read);
}
}
@Override

View file

@ -484,7 +484,8 @@ public class LinphoneManager implements LinphoneCoreListener {
PreferencesMigrator prefMigrator = new PreferencesMigrator(mServiceContext);
prefMigrator.migrateRemoteProvisioningUriIfNeeded();
prefMigrator.migrateSharingServerUrlIfNeeded();
if (prefMigrator.isMigrationNeeded()) {
prefMigrator.doMigration();
}

View file

@ -102,6 +102,14 @@ public class PreferencesMigrator {
mNewPrefs.getConfig().sync();
}
}
public void migrateSharingServerUrlIfNeeded() {
String currentUrl = mNewPrefs.getConfig().getString("app", "sharing_server", null);
if (currentUrl == null || currentUrl.equals("https://www.linphone.org:444/upload.php")) {
mNewPrefs.setSharingPictureServerUrl("https://www.linphone.org:444/lft.php");
mNewPrefs.getConfig().sync();
}
}
private void doAccountsMigration() {
LinphoneCore lc = LinphoneManager.getLcIfManagerNotDestroyedOrNull();

View file

@ -27,6 +27,7 @@ import java.util.Map.Entry;
import org.linphone.R;
import org.linphone.core.LinphoneChatMessage;
import org.linphone.core.LinphoneChatMessage.State;
import org.linphone.core.LinphoneContent;
import org.linphone.mediastream.Log;
import android.annotation.SuppressLint;
@ -134,45 +135,16 @@ public class BubbleChat {
layout = (LinearLayout) LayoutInflater.from(context).inflate(R.layout.chat_bubble_incoming, null);
}
}
TextView msgView = (TextView) layout.findViewById(R.id.message);
if (msgView != null) {
Spanned text = null;
String msg = message.getText();
if (msg != null) {
if (context.getResources().getBoolean(R.bool.emoticons_in_messages)) {
text = getSmiledText(context, getTextWithHttpLinks(msg));
} else {
text = getTextWithHttpLinks(msg);
}
msgView.setText(text);
msgView.setMovementMethod(LinkMovementMethod.getInstance());
msgView.setVisibility(View.VISIBLE);
} else {
msgView.setVisibility(View.GONE);
}
}
if (message.getExternalBodyUrl() != null || message.getFileTransferInformation() != null) {
if (message.getAppData() == null) {
String appData = null;
if (message.getExternalBodyUrl() != null) {
appData = message.getExternalBodyUrl();
} else if (message.getFileTransferInformation() != null) {
appData = message.getFileTransferInformation().getDataAsString();
}
message.setAppData(appData);
}
}
String appData = message.getAppData();
if (appData != null) {
String externalBodyUrl = message.getExternalBodyUrl();
LinphoneContent fileTransferContent = message.getFileTransferInformation();
if (externalBodyUrl != null || fileTransferContent != null) {
Button download = (Button) layout.findViewById(R.id.download);
ImageView imageView = (ImageView) layout.findViewById(R.id.image);
if (appData.startsWith("http")) {
String appData = message.getAppData();
if (appData == null) {
download.setVisibility(View.VISIBLE);
imageView.setVisibility(View.GONE);
download.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
@ -186,7 +158,6 @@ public class BubbleChat {
}
});
} else {
download.setVisibility(View.GONE);
imageView.setVisibility(View.VISIBLE);
Bitmap bm = null;
@ -216,6 +187,22 @@ public class BubbleChat {
});
}
}
} else {
TextView msgView = (TextView) layout.findViewById(R.id.message);
if (msgView != null) {
Spanned text = null;
String msg = message.getText();
if (msg != null) {
if (context.getResources().getBoolean(R.bool.emoticons_in_messages)) {
text = getSmiledText(context, getTextWithHttpLinks(msg));
} else {
text = getTextWithHttpLinks(msg);
}
msgView.setText(text);
msgView.setMovementMethod(LinkMovementMethod.getInstance());
msgView.setVisibility(View.VISIBLE);
}
}
}
TextView timeView = (TextView) layout.findViewById(R.id.time);