forked from organicmaps/organicmaps
[android] Made sharing of edits nicer, added pictures to fb-twitter etc.
This commit is contained in:
parent
6eec1a8b3c
commit
136fffe835
11 changed files with 123 additions and 81 deletions
BIN
android/res/drawable/img_sharing_editor.png
Normal file
BIN
android/res/drawable/img_sharing_editor.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 392 KiB |
|
@ -1,11 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item android:id="@+id/share_message"
|
||||
android:title="@string/share_by_message"
|
||||
android:icon="@drawable/ic_share_message"/>
|
||||
|
||||
<item android:id="@+id/share"
|
||||
android:title="@string/share"
|
||||
android:icon="@drawable/ic_share"/>
|
||||
|
||||
</menu>
|
|
@ -96,6 +96,9 @@ public enum BookmarkManager
|
|||
|
||||
public native void nativeShowBookmarkOnMap(int catId, int bmkId);
|
||||
|
||||
/**
|
||||
* @return null, if wrong category is passed.
|
||||
*/
|
||||
public native @Nullable String nativeSaveToKmzFile(int catId, String tmpPath);
|
||||
|
||||
public native Bookmark nativeAddBookmarkToLastEditedCategory(String name, double lat, double lon);
|
||||
|
|
|
@ -2,12 +2,10 @@ package com.mapswithme.maps.editor;
|
|||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.Dialog;
|
||||
import android.content.DialogInterface;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.widget.TextView;
|
||||
|
||||
|
@ -16,9 +14,8 @@ import java.util.Random;
|
|||
import com.mapswithme.maps.MwmApplication;
|
||||
import com.mapswithme.maps.R;
|
||||
import com.mapswithme.maps.base.BaseMwmDialogFragment;
|
||||
import com.mapswithme.util.BottomSheetHelper;
|
||||
import com.mapswithme.util.ConnectionState;
|
||||
import com.mapswithme.util.sharing.ShareOption;
|
||||
import com.mapswithme.util.sharing.SharingHelper;
|
||||
import com.mapswithme.util.statistics.Statistics;
|
||||
|
||||
public class ViralFragment extends BaseMwmDialogFragment
|
||||
|
@ -55,6 +52,7 @@ public class ViralFragment extends BaseMwmDialogFragment
|
|||
public void onClick(View v)
|
||||
{
|
||||
share();
|
||||
dismiss();
|
||||
Statistics.INSTANCE.trackEvent(Statistics.EventName.EDITOR_SHARE_CLICK);
|
||||
}
|
||||
});
|
||||
|
@ -64,7 +62,6 @@ public class ViralFragment extends BaseMwmDialogFragment
|
|||
public void onClick(View v)
|
||||
{
|
||||
dismiss();
|
||||
// TODO send statistics
|
||||
}
|
||||
});
|
||||
return builder.setView(root).create();
|
||||
|
@ -72,41 +69,7 @@ public class ViralFragment extends BaseMwmDialogFragment
|
|||
|
||||
private void share()
|
||||
{
|
||||
// TODO add custom sharing in twitter and url to facebook sharing
|
||||
BottomSheetHelper.Builder sheet = BottomSheetHelper.create(getActivity())
|
||||
.sheet(R.menu.menu_viral_editor)
|
||||
.listener(new MenuItem.OnMenuItemClickListener() {
|
||||
@Override
|
||||
public boolean onMenuItemClick(MenuItem item)
|
||||
{
|
||||
if (item.getItemId() == R.id.share_message)
|
||||
{
|
||||
ShareOption.SMS.share(getActivity(),
|
||||
getString(R.string.whatsnew_editor_message_1));
|
||||
}
|
||||
else
|
||||
{
|
||||
ShareOption.ANY.share(getActivity(),
|
||||
getString(R.string.whatsnew_editor_message_1),
|
||||
R.string.editor_sharing_title);
|
||||
}
|
||||
|
||||
dismiss();
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
if (!ShareOption.SMS.isSupported(getActivity()))
|
||||
sheet.getMenu().removeItem(R.id.share_message);
|
||||
|
||||
sheet.tint().show();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDismiss(DialogInterface dialog)
|
||||
{
|
||||
super.onDismiss(dialog);
|
||||
// TODO remove before merge
|
||||
SharingHelper.shareViralEditor(getActivity(), R.drawable.img_sharing_editor, R.string.editor_sharing_title, R.string.whatsnew_editor_message_1);
|
||||
}
|
||||
|
||||
private void initViralText()
|
||||
|
|
|
@ -2,9 +2,14 @@ package com.mapswithme.util;
|
|||
|
||||
import android.animation.Animator;
|
||||
import android.app.Activity;
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.res.Configuration;
|
||||
import android.content.res.Resources;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.support.annotation.AnyRes;
|
||||
import android.support.annotation.DimenRes;
|
||||
import android.support.annotation.IdRes;
|
||||
import android.support.annotation.NonNull;
|
||||
|
@ -286,6 +291,15 @@ public final class UiUtils
|
|||
: R.attr.accentButtonTextColorDisabled));
|
||||
}
|
||||
|
||||
public static Uri getUriToResId(@NonNull Context context, @AnyRes int resId)
|
||||
{
|
||||
final Resources resources = context.getResources();
|
||||
return Uri.parse(ContentResolver.SCHEME_ANDROID_RESOURCE + "://"
|
||||
+ resources.getResourcePackageName(resId) + '/'
|
||||
+ resources.getResourceTypeName(resId) + '/'
|
||||
+ resources.getResourceEntryName(resId));
|
||||
}
|
||||
|
||||
// utility class
|
||||
private UiUtils() {}
|
||||
}
|
||||
|
|
|
@ -12,9 +12,9 @@ import com.mapswithme.util.statistics.AlohaHelper;
|
|||
public abstract class BaseShareable
|
||||
{
|
||||
private final Activity mActivity;
|
||||
private Intent mBaseIntent;
|
||||
private String mText;
|
||||
private String mSubject;
|
||||
protected Intent mBaseIntent;
|
||||
protected String mText;
|
||||
protected String mSubject;
|
||||
|
||||
public BaseShareable(Activity activity)
|
||||
{
|
||||
|
|
|
@ -5,6 +5,8 @@ import android.content.Intent;
|
|||
import android.net.Uri;
|
||||
import android.support.annotation.Nullable;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public class LocalFileShareable extends BaseShareable
|
||||
{
|
||||
private final String mFileName;
|
||||
|
@ -21,7 +23,7 @@ public class LocalFileShareable extends BaseShareable
|
|||
protected void modifyIntent(Intent intent, @Nullable SharingTarget target)
|
||||
{
|
||||
super.modifyIntent(intent, target);
|
||||
intent.putExtra(android.content.Intent.EXTRA_STREAM, Uri.parse("file://" + mFileName));
|
||||
intent.putExtra(android.content.Intent.EXTRA_STREAM, Uri.fromFile(new File(mFileName)));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -48,7 +48,7 @@ public abstract class ShareOption
|
|||
public void share(Activity activity, String body)
|
||||
{
|
||||
Intent smsIntent = new Intent();
|
||||
TargetUtils.fillSmsIntent(activity, smsIntent, body);
|
||||
TargetUtils.fillSmsIntent(smsIntent, body);
|
||||
activity.startActivity(smsIntent);
|
||||
Statistics.INSTANCE.trackPlaceShared("SMS");
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@ import android.content.SharedPreferences;
|
|||
import android.content.pm.ActivityInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.pm.ResolveInfo;
|
||||
import android.support.annotation.DrawableRes;
|
||||
import android.support.annotation.StringRes;
|
||||
import android.text.TextUtils;
|
||||
|
||||
|
@ -86,7 +87,6 @@ public final class SharingHelper
|
|||
mPrefs.edit().putString(PREFS_KEY_ITEMS, json).apply();
|
||||
}
|
||||
|
||||
|
||||
private static String guessAppName(PackageManager pm, ResolveInfo ri)
|
||||
{
|
||||
CharSequence name = ri.activityInfo.loadLabel(pm);
|
||||
|
@ -110,7 +110,6 @@ public final class SharingHelper
|
|||
PackageManager pm = MwmApplication.get().getPackageManager();
|
||||
List<ResolveInfo> rlist = pm.queryIntentActivities(it, 0);
|
||||
|
||||
|
||||
final List<SharingTarget> res = new ArrayList<>(rlist.size());
|
||||
for (ResolveInfo ri : rlist)
|
||||
{
|
||||
|
@ -216,17 +215,20 @@ public final class SharingHelper
|
|||
|
||||
public static void shareBookmarksCategory(Activity context, int id)
|
||||
{
|
||||
String path = MwmApplication.get().getTempPath();
|
||||
String name = BookmarkManager.INSTANCE.nativeSaveToKmzFile(id, path);
|
||||
String name = BookmarkManager.INSTANCE.nativeSaveToKmzFile(id, MwmApplication.get().getTempPath());
|
||||
if (name == null)
|
||||
// some error occurred
|
||||
return;
|
||||
|
||||
path += name + ".kmz";
|
||||
|
||||
// FIXME bug with "%s.kmz"
|
||||
shareOutside(new LocalFileShareable(context, path, "application/vnd.google-earth.kmz")
|
||||
.setText(R.string.share_bookmarks_email_body)
|
||||
.setSubject(R.string.share_bookmarks_email_subject));
|
||||
shareOutside(new LocalFileShareable(context, name + ".kmz", "application/vnd.google-earth.kmz")
|
||||
.setText(R.string.share_bookmarks_email_body)
|
||||
.setSubject(R.string.share_bookmarks_email_subject));
|
||||
}
|
||||
|
||||
public static void shareViralEditor(Activity context, @DrawableRes int imageId, @StringRes int subject, @StringRes int text)
|
||||
{
|
||||
shareOutside(new ViralEditorShareable(context, imageId)
|
||||
.setText(text)
|
||||
.setSubject(subject));
|
||||
}
|
||||
|
||||
}
|
|
@ -1,10 +1,7 @@
|
|||
package com.mapswithme.util.sharing;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.provider.Telephony;
|
||||
|
||||
final class TargetUtils
|
||||
{
|
||||
|
@ -16,18 +13,9 @@ final class TargetUtils
|
|||
|
||||
private TargetUtils() {}
|
||||
|
||||
public static void fillSmsIntent(Activity activity, Intent smsIntent, String body)
|
||||
public static void fillSmsIntent(Intent smsIntent, String body)
|
||||
{
|
||||
smsIntent.setData(Uri.parse(URI_STRING_SMS));
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT)
|
||||
{
|
||||
final String defaultSms = Telephony.Sms.getDefaultSmsPackage(activity);
|
||||
smsIntent.setType(TYPE_TEXT_PLAIN);
|
||||
smsIntent.putExtra(EXTRA_SMS_TEXT, body);
|
||||
if (defaultSms != null)
|
||||
smsIntent.setPackage(defaultSms);
|
||||
}
|
||||
else
|
||||
smsIntent.putExtra(EXTRA_SMS_BODY, body);
|
||||
smsIntent.putExtra(EXTRA_SMS_BODY, body);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,81 @@
|
|||
package com.mapswithme.util.sharing;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.support.annotation.DrawableRes;
|
||||
import android.support.annotation.Nullable;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
import com.facebook.FacebookSdk;
|
||||
import com.facebook.share.model.ShareLinkContent;
|
||||
import com.facebook.share.widget.ShareDialog;
|
||||
import com.mapswithme.util.UiUtils;
|
||||
|
||||
public class ViralEditorShareable extends BaseShareable
|
||||
{
|
||||
private static final String FACEBOOK_SHARE_URL = "http://maps.me/fb-editor-v1?lang=" + Locale.getDefault().getLanguage();
|
||||
|
||||
private final Uri mUri;
|
||||
|
||||
public ViralEditorShareable(Activity context, @DrawableRes int resId)
|
||||
{
|
||||
super(context);
|
||||
mUri = UiUtils.getUriToResId(context, resId);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void modifyIntent(Intent intent, @Nullable SharingTarget target)
|
||||
{
|
||||
super.modifyIntent(intent, target);
|
||||
intent.putExtra(Intent.EXTRA_STREAM, mUri);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMimeType()
|
||||
{
|
||||
return TargetUtils.TYPE_TEXT_PLAIN;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void share(SharingTarget target)
|
||||
{
|
||||
Intent intent = getTargetIntent(target);
|
||||
String lowerCaseName = target.activityName.toLowerCase();
|
||||
|
||||
if (lowerCaseName.contains("facebook"))
|
||||
{
|
||||
shareFacebook();
|
||||
return;
|
||||
}
|
||||
|
||||
if (lowerCaseName.contains("sms") || lowerCaseName.contains("mms"))
|
||||
TargetUtils.fillSmsIntent(intent, mText);
|
||||
else if (lowerCaseName.contains("twitter"))
|
||||
setSubject("");
|
||||
else if (!lowerCaseName.contains("mail"))
|
||||
{
|
||||
setText(mSubject + "\n" + mText);
|
||||
setSubject("");
|
||||
}
|
||||
|
||||
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
|
||||
|
||||
super.share(target);
|
||||
}
|
||||
|
||||
private void shareFacebook()
|
||||
{
|
||||
FacebookSdk.sdkInitialize(getActivity());
|
||||
ShareDialog shareDialog = new ShareDialog(getActivity());
|
||||
if (ShareDialog.canShow(ShareLinkContent.class))
|
||||
{
|
||||
ShareLinkContent linkContent = new ShareLinkContent.Builder()
|
||||
.setContentUrl(Uri.parse(FACEBOOK_SHARE_URL))
|
||||
.build();
|
||||
|
||||
shareDialog.show(linkContent);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue