Support for location messages

Start with encoding as a simple image thumbnail for compatibility
with MMS and iOS

// FREEBIE
This commit is contained in:
Moxie Marlinspike 2015-12-18 14:37:11 -08:00
parent 4fa6680f83
commit bcf95e50aa
24 changed files with 338 additions and 19 deletions

View File

@ -97,6 +97,10 @@
android:allowBackup="false" android:allowBackup="false"
android:theme="@style/TextSecure.LightTheme"> android:theme="@style/TextSecure.LightTheme">
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="AIzaSyCSx9xea86GwDKGznCAULE9Y5a8b-TfN9U"/>
<meta-data android:name="com.google.android.gms.version" <meta-data android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" /> android:value="@integer/google_play_services_version" />

View File

@ -36,7 +36,9 @@ repositories {
dependencies { dependencies {
compile 'me.leolin:ShortcutBadger:1.1.0-WS1' compile 'me.leolin:ShortcutBadger:1.1.0-WS1'
compile 'se.emilsjolander:stickylistheaders:2.7.0' compile 'se.emilsjolander:stickylistheaders:2.7.0'
compile 'com.google.android.gms:play-services-base:6.5.87' compile 'com.google.android.gms:play-services-gcm:8.1.0'
compile 'com.google.android.gms:play-services-maps:8.1.0'
compile 'com.google.android.gms:play-services-location:8.1.0'
compile 'com.jpardogo.materialtabstrip:library:1.0.9' compile 'com.jpardogo.materialtabstrip:library:1.0.9'
compile 'org.w3c:smil:1.0.0' compile 'org.w3c:smil:1.0.0'
compile 'org.apache.httpcomponents:httpclient-android:4.3.5' compile 'org.apache.httpcomponents:httpclient-android:4.3.5'
@ -97,7 +99,9 @@ dependencyVerification {
verify = [ verify = [
'me.leolin:ShortcutBadger:3142d017234bfa0cdd69ccded7cc5ea63f13b97574803c8c616c9bbeaad33ad9', 'me.leolin:ShortcutBadger:3142d017234bfa0cdd69ccded7cc5ea63f13b97574803c8c616c9bbeaad33ad9',
'se.emilsjolander:stickylistheaders:a08ca948aa6b220f09d82f16bbbac395f6b78897e9eeac6a9f0b0ba755928eeb', 'se.emilsjolander:stickylistheaders:a08ca948aa6b220f09d82f16bbbac395f6b78897e9eeac6a9f0b0ba755928eeb',
'com.google.android.gms:play-services-base:832cb6b3130e871db6a412c4ab585656dbcc5e7948101f190186757785703f75', 'com.google.android.gms:play-services-gcm:757ecd2c837ac81c98f4cc7dc783e7454c6d0506f6cc66b10417126b675248c9',
'com.google.android.gms:play-services-maps:c58a9d98a98889fb0b27f78100f2d9341ed7722db24ccf832df62b6e8ce1b42e',
'com.google.android.gms:play-services-location:8226f778aa86bd15b9143f62425262cc53d64021990f62eb1aaec108d4e25f35',
'com.jpardogo.materialtabstrip:library:c6ef812fba4f74be7dc4a905faa4c2908cba261a94c13d4f96d5e67e4aad4aaa', 'com.jpardogo.materialtabstrip:library:c6ef812fba4f74be7dc4a905faa4c2908cba261a94c13d4f96d5e67e4aad4aaa',
'org.w3c:smil:085dc40f2bb249651578bfa07499fd08b16ad0886dbe2c4078586a408da62f9b', 'org.w3c:smil:085dc40f2bb249651578bfa07499fd08b16ad0886dbe2c4078586a408da62f9b',
'org.apache.httpcomponents:httpclient-android:6f56466a9bd0d42934b90bfbfe9977a8b654c058bf44a12bdc2877c4e1f033f1', 'org.apache.httpcomponents:httpclient-android:6f56466a9bd0d42934b90bfbfe9977a8b654c058bf44a12bdc2877c4e1f033f1',
@ -125,12 +129,14 @@ dependencyVerification {
'org.whispersystems:textsecure-android:aec5fc59952d9f5482491091091687816f46be1144342a0244f48fd55d6ab393', 'org.whispersystems:textsecure-android:aec5fc59952d9f5482491091091687816f46be1144342a0244f48fd55d6ab393',
'com.h6ah4i.android.compat:mulsellistprefcompat:47167c5cb796de1a854788e9ff318358e36c8fb88123baaa6e38fb78511dfabe', 'com.h6ah4i.android.compat:mulsellistprefcompat:47167c5cb796de1a854788e9ff318358e36c8fb88123baaa6e38fb78511dfabe',
'com.google.zxing:core:b4d82452e7a6bf6ec2698904b332431717ed8f9a850224f295aec89de80f2259', 'com.google.zxing:core:b4d82452e7a6bf6ec2698904b332431717ed8f9a850224f295aec89de80f2259',
'com.google.android.gms:play-services-base:ef36e50fa5c0415ed41f74dd399a889efd2fa327c449036e140c7c3786aa0e1f',
'com.android.support:support-annotations:104f353b53d5dd8d64b2f77eece4b37f6b961de9732eb6b706395e91033ec70a', 'com.android.support:support-annotations:104f353b53d5dd8d64b2f77eece4b37f6b961de9732eb6b706395e91033ec70a',
'com.nineoldandroids:library:68025a14e3e7673d6ad2f95e4b46d78d7d068343aa99256b686fe59de1b3163a', 'com.nineoldandroids:library:68025a14e3e7673d6ad2f95e4b46d78d7d068343aa99256b686fe59de1b3163a',
'javax.inject:javax.inject:91c77044a50c481636c32d916fd89c9118a72195390452c81065080f957de7ff', 'javax.inject:javax.inject:91c77044a50c481636c32d916fd89c9118a72195390452c81065080f957de7ff',
'com.madgag.spongycastle:core:8d6240b974b0aca4d3da9c7dd44d42339d8a374358aca5fc98e50a995764511f', 'com.madgag.spongycastle:core:8d6240b974b0aca4d3da9c7dd44d42339d8a374358aca5fc98e50a995764511f',
'org.whispersystems:textsecure-java:b407ca6d1430204dfabf38e27db22d5177409072a9668238bd1877de7676ad3f', 'org.whispersystems:textsecure-java:b407ca6d1430204dfabf38e27db22d5177409072a9668238bd1877de7676ad3f',
'org.whispersystems:axolotl-android:40d3db5004a84749a73f68d2f0d01b2ae35a73c54df96d8c6c6723b96efb6fc0', 'org.whispersystems:axolotl-android:40d3db5004a84749a73f68d2f0d01b2ae35a73c54df96d8c6c6723b96efb6fc0',
'com.google.android.gms:play-services-basement:e1d29b21e02fd2a63e5a31807415cbb17a59568e27e3254181c01ffae10659bf',
'com.googlecode.libphonenumber:libphonenumber:9625de9d2270e9a280ff4e6d9ef3106573fb4828773fd32c9b7614f4e17d2811', 'com.googlecode.libphonenumber:libphonenumber:9625de9d2270e9a280ff4e6d9ef3106573fb4828773fd32c9b7614f4e17d2811',
'com.google.protobuf:protobuf-java:e0c1c64575c005601725e7c6a02cebf9e1285e888f756b2a1d73ffa8d725cc74', 'com.google.protobuf:protobuf-java:e0c1c64575c005601725e7c6a02cebf9e1285e888f756b2a1d73ffa8d725cc74',
'com.squareup.okhttp:okhttp:89b7f63e2e5b6c410266abc14f50fe52ea8d2d8a57260829e499b1cd9f0e61af', 'com.squareup.okhttp:okhttp:89b7f63e2e5b6c410266abc14f50fe52ea8d2d8a57260829e499b1cd9f0e61af',

Binary file not shown.

After

Width:  |  Height:  |  Size: 521 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 371 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 675 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 970 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

View File

@ -143,6 +143,29 @@
android:gravity="center" android:gravity="center"
android:orientation="vertical"> android:orientation="vertical">
<LinearLayout android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical">
<org.thoughtcrime.securesms.components.CircleColorImageView
android:id="@+id/location_button"
android:layout_width="60dp"
android:layout_height="60dp"
android:src="@drawable/ic_location_on_white_36dp"
android:scaleType="center"
android:elevation="4dp"
app:circleColor="@color/blue_grey_400"/>
<TextView android:layout_marginTop="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="@style/AttachmentTypeLabel"
android:text="@string/attachment_type_selector__location"/>
</LinearLayout>
</LinearLayout> </LinearLayout>

View File

@ -46,6 +46,13 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="center"> android:layout_gravity="center">
<org.thoughtcrime.securesms.components.location.SignalMapView
android:id="@+id/attachment_location"
android:layout_width="210dp"
android:layout_height="210dp"
android:layout_gravity="center_horizontal"
android:visibility="gone"/>
<org.thoughtcrime.securesms.components.ThumbnailView <org.thoughtcrime.securesms.components.ThumbnailView
android:id="@+id/attachment_thumbnail" android:id="@+id/attachment_thumbnail"
android:layout_width="230dp" android:layout_width="230dp"

View File

@ -0,0 +1,33 @@
<?xml version="1.0" encoding="utf-8"?>
<merge xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<FrameLayout android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1">
<com.google.android.gms.maps.MapView
android:id="@+id/map_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone"/>
<ImageView android:id="@+id/image_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone"
tools:src="@drawable/ic_action_warning_red"
tools:visibility="visible"/>
</FrameLayout>
<TextView android:id="@+id/address_view"
android:visibility="visible"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0"
android:ellipsize="end"
android:maxLines="1"
android:singleLine="true"
android:padding="5dp"
tools:text="21 Jump St, Atlanta GA 30311"/>
</merge>

View File

@ -617,6 +617,7 @@
<string name="attachment_type_selector__video">Video</string> <string name="attachment_type_selector__video">Video</string>
<string name="attachment_type_selector__contact">Contact</string> <string name="attachment_type_selector__contact">Contact</string>
<string name="attachment_type_selector__camera">Camera</string> <string name="attachment_type_selector__camera">Camera</string>
<string name="attachment_type_selector__location">Location</string>
<!-- change_passphrase_activity --> <!-- change_passphrase_activity -->
<string name="change_passphrase_activity__old_passphrase">Old passphrase</string> <string name="change_passphrase_activity__old_passphrase">Old passphrase</string>

View File

@ -56,6 +56,8 @@ import android.widget.LinearLayout;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
import com.google.android.gms.location.places.Place;
import com.google.android.gms.location.places.ui.PlacePicker;
import com.google.protobuf.ByteString; import com.google.protobuf.ByteString;
import org.thoughtcrime.redphone.RedPhone; import org.thoughtcrime.redphone.RedPhone;
@ -174,6 +176,7 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
private static final int GROUP_EDIT = 5; private static final int GROUP_EDIT = 5;
private static final int TAKE_PHOTO = 6; private static final int TAKE_PHOTO = 6;
private static final int ADD_CONTACT = 7; private static final int ADD_CONTACT = 7;
private static final int PICK_LOCATION = 8;
private MasterSecret masterSecret; private MasterSecret masterSecret;
protected ComposeText composeText; protected ComposeText composeText;
@ -312,7 +315,7 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
} }
@Override @Override
public void onActivityResult(int reqCode, int resultCode, Intent data) { public void onActivityResult(final int reqCode, int resultCode, Intent data) {
Log.w(TAG, "onActivityResult called: " + reqCode + ", " + resultCode + " , " + data); Log.w(TAG, "onActivityResult called: " + reqCode + ", " + resultCode + " , " + data);
super.onActivityResult(reqCode, resultCode, data); super.onActivityResult(reqCode, resultCode, data);
@ -349,6 +352,9 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
recipients.addListener(this); recipients.addListener(this);
fragment.reloadList(); fragment.reloadList();
break; break;
case PICK_LOCATION:
attachmentManager.setLocation(masterSecret, PlacePicker.getPlace(data, this), getCurrentMediaConstraints());
break;
} }
} }
@ -998,6 +1004,8 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
AttachmentManager.selectAudio(this, PICK_AUDIO); break; AttachmentManager.selectAudio(this, PICK_AUDIO); break;
case AttachmentTypeSelectorAdapter.ADD_CONTACT_INFO: case AttachmentTypeSelectorAdapter.ADD_CONTACT_INFO:
AttachmentManager.selectContactInfo(this, PICK_CONTACT_INFO); break; AttachmentManager.selectContactInfo(this, PICK_CONTACT_INFO); break;
case AttachmentTypeSelector.ADD_LOCATION:
AttachmentManager.selectLocation(this, PICK_LOCATION); break;
case AttachmentTypeSelectorAdapter.TAKE_PHOTO: case AttachmentTypeSelectorAdapter.TAKE_PHOTO:
attachmentManager.capturePhoto(this, TAKE_PHOTO); break; attachmentManager.capturePhoto(this, TAKE_PHOTO); break;
} }

View File

@ -33,6 +33,7 @@ public class AttachmentTypeSelector extends PopupWindow {
public static final int ADD_SOUND = 3; public static final int ADD_SOUND = 3;
public static final int ADD_CONTACT_INFO = 4; public static final int ADD_CONTACT_INFO = 4;
public static final int TAKE_PHOTO = 5; public static final int TAKE_PHOTO = 5;
public static final int ADD_LOCATION = 6;
private static final int ANIMATION_DURATION = 300; private static final int ANIMATION_DURATION = 300;
@ -43,6 +44,7 @@ public class AttachmentTypeSelector extends PopupWindow {
private final @NonNull ImageView videoButton; private final @NonNull ImageView videoButton;
private final @NonNull ImageView contactButton; private final @NonNull ImageView contactButton;
private final @NonNull ImageView cameraButton; private final @NonNull ImageView cameraButton;
private final @NonNull ImageView locationButton;
private final @NonNull ImageView closeButton; private final @NonNull ImageView closeButton;
private @Nullable View currentAnchor; private @Nullable View currentAnchor;
@ -54,21 +56,27 @@ public class AttachmentTypeSelector extends PopupWindow {
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
LinearLayout layout = (LinearLayout) inflater.inflate(R.layout.attachment_type_selector, null, true); LinearLayout layout = (LinearLayout) inflater.inflate(R.layout.attachment_type_selector, null, true);
this.listener = listener; this.listener = listener;
this.imageButton = ViewUtil.findById(layout, R.id.gallery_button); this.imageButton = ViewUtil.findById(layout, R.id.gallery_button);
this.audioButton = ViewUtil.findById(layout, R.id.audio_button); this.audioButton = ViewUtil.findById(layout, R.id.audio_button);
this.videoButton = ViewUtil.findById(layout, R.id.video_button); this.videoButton = ViewUtil.findById(layout, R.id.video_button);
this.contactButton = ViewUtil.findById(layout, R.id.contact_button); this.contactButton = ViewUtil.findById(layout, R.id.contact_button);
this.cameraButton = ViewUtil.findById(layout, R.id.camera_button); this.cameraButton = ViewUtil.findById(layout, R.id.camera_button);
this.closeButton = ViewUtil.findById(layout, R.id.close_button); this.closeButton = ViewUtil.findById(layout, R.id.close_button);
this.locationButton = ViewUtil.findById(layout, R.id.location_button);
this.imageButton.setOnClickListener(new PropagatingClickListener(ADD_IMAGE)); this.imageButton.setOnClickListener(new PropagatingClickListener(ADD_IMAGE));
this.audioButton.setOnClickListener(new PropagatingClickListener(ADD_SOUND)); this.audioButton.setOnClickListener(new PropagatingClickListener(ADD_SOUND));
this.videoButton.setOnClickListener(new PropagatingClickListener(ADD_VIDEO)); this.videoButton.setOnClickListener(new PropagatingClickListener(ADD_VIDEO));
this.contactButton.setOnClickListener(new PropagatingClickListener(ADD_CONTACT_INFO)); this.contactButton.setOnClickListener(new PropagatingClickListener(ADD_CONTACT_INFO));
this.cameraButton.setOnClickListener(new PropagatingClickListener(TAKE_PHOTO)); this.cameraButton.setOnClickListener(new PropagatingClickListener(TAKE_PHOTO));
this.locationButton.setOnClickListener(new PropagatingClickListener(ADD_LOCATION));
this.closeButton.setOnClickListener(new CloseClickListener()); this.closeButton.setOnClickListener(new CloseClickListener());
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
this.locationButton.setVisibility(View.INVISIBLE);
}
setContentView(layout); setContentView(layout);
setWidth(LinearLayout.LayoutParams.MATCH_PARENT); setWidth(LinearLayout.LayoutParams.MATCH_PARENT);
setHeight(LinearLayout.LayoutParams.WRAP_CONTENT); setHeight(LinearLayout.LayoutParams.WRAP_CONTENT);

View File

@ -0,0 +1,98 @@
package org.thoughtcrime.securesms.components.location;
import android.annotation.TargetApi;
import android.content.Context;
import android.graphics.Bitmap;
import android.os.Build;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.google.android.gms.location.places.Place;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapView;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.model.MarkerOptions;
import org.thoughtcrime.securesms.R;
import org.thoughtcrime.securesms.util.ViewUtil;
import org.thoughtcrime.securesms.util.concurrent.ListenableFuture;
import org.thoughtcrime.securesms.util.concurrent.SettableFuture;
public class SignalMapView extends LinearLayout {
private MapView mapView;
private ImageView imageView;
private TextView textView;
public SignalMapView(Context context) {
this(context, null);
}
public SignalMapView(Context context, AttributeSet attrs) {
super(context, attrs);
initialize(context);
}
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public SignalMapView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
initialize(context);
}
private void initialize(Context context) {
setOrientation(LinearLayout.VERTICAL);
LayoutInflater.from(context).inflate(R.layout.signal_map_view, this, true);
this.mapView = ViewUtil.findById(this, R.id.map_view);
this.imageView = ViewUtil.findById(this, R.id.image_view);
this.textView = ViewUtil.findById(this, R.id.address_view);
}
public ListenableFuture<Bitmap> display(final SignalPlace place) {
final SettableFuture<Bitmap> future = new SettableFuture<>();
this.mapView.onCreate(null);
this.mapView.onResume();
this.mapView.setVisibility(View.VISIBLE);
this.imageView.setVisibility(View.GONE);
this.mapView.getMapAsync(new OnMapReadyCallback() {
@Override
public void onMapReady(final GoogleMap googleMap) {
googleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(place.getLatLong(), 13));
googleMap.addMarker(new MarkerOptions().position(place.getLatLong()));
googleMap.setBuildingsEnabled(true);
googleMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
googleMap.getUiSettings().setAllGesturesEnabled(false);
googleMap.setOnMapLoadedCallback(new GoogleMap.OnMapLoadedCallback() {
@Override
public void onMapLoaded() {
googleMap.snapshot(new GoogleMap.SnapshotReadyCallback() {
@Override
public void onSnapshotReady(Bitmap bitmap) {
future.set(bitmap);
imageView.setImageBitmap(bitmap);
imageView.setVisibility(View.VISIBLE);
mapView.setVisibility(View.GONE);
mapView.onPause();
mapView.onDestroy();
}
});
}
});
}
});
this.textView.setText(place.getDescription());
return future;
}
}

View File

@ -0,0 +1,37 @@
package org.thoughtcrime.securesms.components.location;
import android.text.TextUtils;
import com.google.android.gms.location.places.Place;
import com.google.android.gms.maps.model.LatLng;
public class SignalPlace {
private static final String URL = "https://maps.google.com/maps?q=%s,%s";
private final Place place;
public SignalPlace(Place place) {
this.place = place;
}
public LatLng getLatLong() {
return place.getLatLng();
}
public String getDescription() {
String description = "";
if (!TextUtils.isEmpty(place.getName())) {
description += (place.getName() + "\n");
}
if (!TextUtils.isEmpty(place.getAddress())) {
description += (place.getAddress() + "\n");
}
description += String.format(URL, place.getLatLng().latitude, place.getLatLng().longitude);
return description;
}
}

View File

@ -20,6 +20,7 @@ import android.app.Activity;
import android.content.ActivityNotFoundException; import android.content.ActivityNotFoundException;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.graphics.Bitmap;
import android.net.Uri; import android.net.Uri;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.os.Build; import android.os.Build;
@ -32,15 +33,25 @@ import android.util.Log;
import android.view.View; import android.view.View;
import android.widget.Toast; import android.widget.Toast;
import com.google.android.gms.common.GooglePlayServicesNotAvailableException;
import com.google.android.gms.common.GooglePlayServicesRepairableException;
import com.google.android.gms.location.places.Place;
import com.google.android.gms.location.places.ui.PlacePicker;
import org.thoughtcrime.securesms.MediaPreviewActivity; import org.thoughtcrime.securesms.MediaPreviewActivity;
import org.thoughtcrime.securesms.R; import org.thoughtcrime.securesms.R;
import org.thoughtcrime.securesms.components.AudioView; import org.thoughtcrime.securesms.components.AudioView;
import org.thoughtcrime.securesms.components.RemovableMediaView; import org.thoughtcrime.securesms.components.RemovableMediaView;
import org.thoughtcrime.securesms.components.location.SignalMapView;
import org.thoughtcrime.securesms.components.ThumbnailView; import org.thoughtcrime.securesms.components.ThumbnailView;
import org.thoughtcrime.securesms.components.location.SignalPlace;
import org.thoughtcrime.securesms.crypto.MasterSecret; import org.thoughtcrime.securesms.crypto.MasterSecret;
import org.thoughtcrime.securesms.providers.PersistentBlobProvider; import org.thoughtcrime.securesms.providers.PersistentBlobProvider;
import org.thoughtcrime.securesms.util.BitmapUtil;
import org.thoughtcrime.securesms.util.MediaUtil; import org.thoughtcrime.securesms.util.MediaUtil;
import org.thoughtcrime.securesms.util.ViewUtil; import org.thoughtcrime.securesms.util.ViewUtil;
import org.thoughtcrime.securesms.util.concurrent.AssertedSuccessListener;
import org.thoughtcrime.securesms.util.concurrent.ListenableFuture;
import org.thoughtcrime.securesms.util.concurrent.ListenableFuture.Listener; import org.thoughtcrime.securesms.util.concurrent.ListenableFuture.Listener;
import org.whispersystems.libaxolotl.util.guava.Optional; import org.whispersystems.libaxolotl.util.guava.Optional;
@ -61,6 +72,7 @@ public class AttachmentManager {
private final @NonNull RemovableMediaView removableMediaView; private final @NonNull RemovableMediaView removableMediaView;
private final @NonNull ThumbnailView thumbnail; private final @NonNull ThumbnailView thumbnail;
private final @NonNull AudioView audioView; private final @NonNull AudioView audioView;
private final @NonNull SignalMapView mapView;
private final @NonNull AttachmentListener attachmentListener; private final @NonNull AttachmentListener attachmentListener;
private @NonNull List<Uri> garbage = new LinkedList<>(); private @NonNull List<Uri> garbage = new LinkedList<>();
@ -71,6 +83,7 @@ public class AttachmentManager {
this.attachmentView = ViewUtil.findById(activity, R.id.attachment_editor); this.attachmentView = ViewUtil.findById(activity, R.id.attachment_editor);
this.thumbnail = ViewUtil.findById(activity, R.id.attachment_thumbnail); this.thumbnail = ViewUtil.findById(activity, R.id.attachment_thumbnail);
this.audioView = ViewUtil.findById(activity, R.id.attachment_audio); this.audioView = ViewUtil.findById(activity, R.id.attachment_audio);
this.mapView = ViewUtil.findById(activity, R.id.attachment_location);
this.removableMediaView = ViewUtil.findById(activity, R.id.removable_media_view); this.removableMediaView = ViewUtil.findById(activity, R.id.removable_media_view);
this.context = activity; this.context = activity;
this.attachmentListener = listener; this.attachmentListener = listener;
@ -134,6 +147,29 @@ public class AttachmentManager {
this.slide = Optional.of(slide); this.slide = Optional.of(slide);
} }
public void setLocation(@NonNull final MasterSecret masterSecret,
@NonNull final Place place,
@NonNull final MediaConstraints constraints)
{
final SignalPlace signalPlace = new SignalPlace(place);
ListenableFuture<Bitmap> future = mapView.display(signalPlace);
attachmentView.setVisibility(View.VISIBLE);
removableMediaView.display(mapView);
future.addListener(new AssertedSuccessListener<Bitmap>() {
@Override
public void onSuccess(@NonNull Bitmap result) {
byte[] blob = BitmapUtil.toByteArray(result);
Uri uri = PersistentBlobProvider.getInstance(context).create(masterSecret, blob);
LocationSlide locationSlide = new LocationSlide(context, uri, blob.length, signalPlace.getDescription());
setSlide(locationSlide);
attachmentListener.onAttachmentChanged();
}
});
}
public void setMedia(@NonNull final MasterSecret masterSecret, public void setMedia(@NonNull final MasterSecret masterSecret,
@NonNull final Uri uri, @NonNull final Uri uri,
@NonNull final MediaType mediaType, @NonNull final MediaType mediaType,
@ -218,6 +254,14 @@ public class AttachmentManager {
activity.startActivityForResult(intent, requestCode); activity.startActivityForResult(intent, requestCode);
} }
public static void selectLocation(Activity activity, int requestCode) {
try {
activity.startActivityForResult(new PlacePicker.IntentBuilder().build(activity), requestCode);
} catch (GooglePlayServicesRepairableException | GooglePlayServicesNotAvailableException e) {
Log.w(TAG, e);
}
}
private @Nullable Uri getSlideUri() { private @Nullable Uri getSlideUri() {
return slide.isPresent() ? slide.get().getUri() : null; return slide.isPresent() ? slide.get().getUri() : null;
} }
@ -310,7 +354,6 @@ public class AttachmentManager {
public @NonNull Slide createSlide(@NonNull Context context, public @NonNull Slide createSlide(@NonNull Context context,
@NonNull Uri uri, @NonNull Uri uri,
long dataSize) long dataSize)
throws IOException
{ {
switch (this) { switch (this) {
case IMAGE: return new ImageSlide(context, uri, dataSize); case IMAGE: return new ImageSlide(context, uri, dataSize);

View File

@ -36,7 +36,7 @@ import ws.com.google.android.mms.pdu.PduPart;
public class AudioSlide extends Slide { public class AudioSlide extends Slide {
public AudioSlide(Context context, Uri uri, long dataSize) throws IOException { public AudioSlide(Context context, Uri uri, long dataSize) {
super(context, constructAttachmentFromUri(context, uri, ContentType.AUDIO_UNSPECIFIED, dataSize)); super(context, constructAttachmentFromUri(context, uri, ContentType.AUDIO_UNSPECIFIED, dataSize));
} }

View File

@ -19,7 +19,7 @@ public class GifSlide extends ImageSlide {
super(context, attachment); super(context, attachment);
} }
public GifSlide(Context context, Uri uri, long size) throws IOException { public GifSlide(Context context, Uri uri, long size) {
super(context, constructAttachmentFromUri(context, uri, ContentType.IMAGE_GIF, size)); super(context, constructAttachmentFromUri(context, uri, ContentType.IMAGE_GIF, size));
} }

View File

@ -37,7 +37,7 @@ public class ImageSlide extends Slide {
super(context, attachment); super(context, attachment);
} }
public ImageSlide(Context context, Uri uri, long size) throws IOException { public ImageSlide(Context context, Uri uri, long size) {
super(context, constructAttachmentFromUri(context, uri, ContentType.IMAGE_JPEG, size)); super(context, constructAttachmentFromUri(context, uri, ContentType.IMAGE_JPEG, size));
} }

View File

@ -0,0 +1,25 @@
package org.thoughtcrime.securesms.mms;
import android.content.Context;
import android.net.Uri;
import android.support.annotation.NonNull;
import org.whispersystems.libaxolotl.util.guava.Optional;
public class LocationSlide extends ImageSlide {
@NonNull
private final String description;
public LocationSlide(@NonNull Context context, @NonNull Uri uri, long size, @NonNull String description)
{
super(context, uri, size);
this.description = description;
}
@Override
@NonNull
public Optional<String> getBody() {
return Optional.of(description);
}
}

View File

@ -1,5 +1,7 @@
package org.thoughtcrime.securesms.mms; package org.thoughtcrime.securesms.mms;
import android.text.TextUtils;
import org.thoughtcrime.securesms.attachments.Attachment; import org.thoughtcrime.securesms.attachments.Attachment;
import org.thoughtcrime.securesms.recipients.Recipients; import org.thoughtcrime.securesms.recipients.Recipients;
@ -26,7 +28,11 @@ public class OutgoingMediaMessage {
public OutgoingMediaMessage(Recipients recipients, SlideDeck slideDeck, String message, long sentTimeMillis, int distributionType) public OutgoingMediaMessage(Recipients recipients, SlideDeck slideDeck, String message, long sentTimeMillis, int distributionType)
{ {
this(recipients, message, slideDeck.asAttachments(), sentTimeMillis, distributionType); this(recipients,
TextUtils.isEmpty(message) ? slideDeck.getBody() : slideDeck.getBody() + "\n\n" + message,
slideDeck.asAttachments(),
sentTimeMillis,
distributionType);
} }
public OutgoingMediaMessage(OutgoingMediaMessage that) { public OutgoingMediaMessage(OutgoingMediaMessage that) {

View File

@ -30,8 +30,6 @@ import org.thoughtcrime.securesms.util.MediaUtil;
import org.thoughtcrime.securesms.util.Util; import org.thoughtcrime.securesms.util.Util;
import org.whispersystems.libaxolotl.util.guava.Optional; import org.whispersystems.libaxolotl.util.guava.Optional;
import java.io.IOException;
public abstract class Slide { public abstract class Slide {
protected final Attachment attachment; protected final Attachment attachment;
@ -57,6 +55,11 @@ public abstract class Slide {
return attachment.getThumbnailUri(); return attachment.getThumbnailUri();
} }
@NonNull
public Optional<String> getBody() {
return Optional.absent();
}
public boolean hasImage() { public boolean hasImage() {
return false; return false;
} }
@ -100,7 +103,6 @@ public abstract class Slide {
@NonNull Uri uri, @NonNull Uri uri,
@NonNull String defaultMime, @NonNull String defaultMime,
long size) long size)
throws IOException
{ {
Optional<String> resolvedType = Optional.fromNullable(MediaUtil.getMimeType(context, uri)); Optional<String> resolvedType = Optional.fromNullable(MediaUtil.getMimeType(context, uri));
return new UriAttachment(uri, resolvedType.or(defaultMime), AttachmentDatabase.TRANSFER_PROGRESS_STARTED, size); return new UriAttachment(uri, resolvedType.or(defaultMime), AttachmentDatabase.TRANSFER_PROGRESS_STARTED, size);

View File

@ -17,10 +17,12 @@
package org.thoughtcrime.securesms.mms; package org.thoughtcrime.securesms.mms;
import android.content.Context; import android.content.Context;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import org.thoughtcrime.securesms.attachments.Attachment; import org.thoughtcrime.securesms.attachments.Attachment;
import org.thoughtcrime.securesms.util.MediaUtil; import org.thoughtcrime.securesms.util.MediaUtil;
import org.whispersystems.libaxolotl.util.guava.Optional;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
@ -48,6 +50,22 @@ public class SlideDeck {
slides.clear(); slides.clear();
} }
@NonNull
public String getBody() {
String body = "";
for (Slide slide : slides) {
Optional<String> slideBody = slide.getBody();
if (slideBody.isPresent()) {
body = slideBody.get();
}
}
return body;
}
@NonNull
public List<Attachment> asAttachments() { public List<Attachment> asAttachments() {
List<Attachment> attachments = new LinkedList<>(); List<Attachment> attachments = new LinkedList<>();

View File

@ -34,7 +34,7 @@ import ws.com.google.android.mms.pdu.PduPart;
public class VideoSlide extends Slide { public class VideoSlide extends Slide {
public VideoSlide(Context context, Uri uri, long dataSize) throws IOException { public VideoSlide(Context context, Uri uri, long dataSize) {
super(context, constructAttachmentFromUri(context, uri, ContentType.VIDEO_UNSPECIFIED, dataSize)); super(context, constructAttachmentFromUri(context, uri, ContentType.VIDEO_UNSPECIFIED, dataSize));
} }