experimental option that puts invite url text into clipboard so user

can invite using app of her choice.
This commit is contained in:
Eric House 2015-08-07 07:55:26 -07:00
parent 134ef851f6
commit c99decaf32
7 changed files with 92 additions and 3 deletions

View file

@ -113,6 +113,7 @@
<string name="key_na_values">key_na_values</string>
<string name="key_na_studycopy">key_na_studycopy</string>
<string name="key_na_fmt_expl">key_na_fmt_expl</string>
<string name="key_na_clip_expl">key_na_clip_expl</string>
<string name="key_na_dicts">key_na_dicts</string>
<string name="key_enable_debug">key_enable_debug</string>
<string name="key_enable_dup_invite">key_enable_dup_invite</string>

View file

@ -2558,4 +2558,18 @@
<string name="enable_relay_toself_title">Enable relay invites to self</string>
<string name="enable_relay_toself_summary">(To aid testing and debugging)</string>
<!-- EXPERIMENATL: A choice of how to invite, along with SMS,
Bluetooth, email etc -->
<string name="invite_choice_clip">I\'ll choose</string>
<!-- EXPERIMENATL: Shown as toast when user chooses "My choice" for
invitation -->
<string name="invite_copied">Invitation ready to paste</string>
<!-- EXPERIMENATL: "label" for invite on clipboard. If it's shown
it's by some Android utility -->
<string name="clip_label">Invitation URL</string>
<!-- EXPERIMENATL: Newbie hint next when invite_choice_clip shown
when chosen -->
<string name="not_again_clip_expl_fmt">The \"%1$s\" option copies an
invitation URL to the clipboard. Paste it into the app of your
choice and send it to your friend.</string>
</resources>

View file

@ -2203,4 +2203,18 @@
em wonk fi I\'m gnorw dna I\'ll yrt redrah ot ekam ti krow.</string>
<string name="enable_relay_toself_title">Elbane yaler setivni ot fles</string>
<string name="enable_relay_toself_summary">oT( dia gnitset dna )gniggubed</string>
<!-- EXPERIMENATL: A choice of how to invite, along with SMS,
Bluetooth, email etc -->
<string name="invite_choice_clip">I\'ll esoohc</string>
<!-- EXPERIMENATL: Shown as toast when user chooses "My choice" for
invitation -->
<string name="invite_copied">Noitativni ydaer ot etsap</string>
<!-- EXPERIMENATL: "label" for invite on clipboard. If it's shown
it's by some Android utility -->
<string name="clip_label">Noitativni LRU</string>
<!-- EXPERIMENATL: Newbie hint next when invite_choice_clip shown
when chosen -->
<string name="not_again_clip_expl_fmt">Eht \"%1$s\" noitpo seipoc na
noitativni LRU ot eht draobpilc. Etsap ti otni eht ppa fo ruoy
eciohc dna dnes ti ot ruoy dneirf.</string>
</resources>

View file

@ -2203,4 +2203,18 @@
ME KNOW IF I\'M WRONG AND I\'LL TRY HARDER TO MAKE IT WORK.</string>
<string name="enable_relay_toself_title">ENABLE RELAY INVITES TO SELF</string>
<string name="enable_relay_toself_summary">(TO AID TESTING AND DEBUGGING)</string>
<!-- EXPERIMENATL: A choice of how to invite, along with SMS,
Bluetooth, email etc -->
<string name="invite_choice_clip">I\'LL CHOOSE</string>
<!-- EXPERIMENATL: Shown as toast when user chooses "My choice" for
invitation -->
<string name="invite_copied">INVITATION READY TO PASTE</string>
<!-- EXPERIMENATL: "label" for invite on clipboard. If it's shown
it's by some Android utility -->
<string name="clip_label">INVITATION URL</string>
<!-- EXPERIMENATL: Newbie hint next when invite_choice_clip shown
when chosen -->
<string name="not_again_clip_expl_fmt">THE \"%1$s\" OPTION COPIES AN
INVITATION URL TO THE CLIPBOARD. PASTE IT INTO THE APP OF YOUR
CHOICE AND SEND IT TO YOUR FRIEND.</string>
</resources>

View file

@ -1069,12 +1069,17 @@ public class BoardDelegate extends DelegateBase
RELAY_INVITE_RESULT );
break;
case EMAIL:
case CLIPBOARD:
NetLaunchInfo nli = new NetLaunchInfo( m_summary, m_gi, 1,
1 + m_nGuestDevs );
if ( !m_relayConnected ) {
nli.removeAddress( CommsConnType.COMMS_CONN_RELAY );
}
if ( InviteMeans.EMAIL == means ) {
GameUtils.launchEmailInviteActivity( m_activity, nli );
} else if ( InviteMeans.CLIPBOARD == means ) {
GameUtils.inviteURLToClip( m_activity, nli );
}
break;
default:
Assert.fail();

View file

@ -138,7 +138,7 @@ public class DlgDelegate {
public interface DlgClickNotify {
public static enum InviteMeans {
SMS, EMAIL, NFC, BLUETOOTH, RELAY,
SMS, EMAIL, NFC, BLUETOOTH, RELAY, CLIPBOARD,
};
void dlgButtonClicked( Action action, int button, Object[] params );
void inviteChoiceMade( Action action, InviteMeans means, Object[] params );
@ -335,6 +335,11 @@ public class DlgDelegate {
showNotAgainDlgThen( msgID, prefsKey, Action.SKIP_CALLBACK );
}
private void showNotAgainDlgThen( String msg, int prefsKey )
{
showNotAgainDlgThen( msg, prefsKey, Action.SKIP_CALLBACK, null, null );
}
public void showConfirmThen( String msg, Action action )
{
showConfirmThen( null, msg, android.R.string.ok, action, null );
@ -630,6 +635,9 @@ public class DlgDelegate {
items.add( getString( R.string.invite_choice_relay ) );
means.add( DlgClickNotify.InviteMeans.RELAY );
}
final int clipPos = means.size();
items.add( getString( R.string.invite_choice_clip ) );
means.add( DlgClickNotify.InviteMeans.CLIPBOARD );
final int[] sel = { -1 };
OnClickListener selChanged = new OnClickListener() {
@ -641,6 +649,13 @@ public class DlgDelegate {
.setEnabled( true );
}
sel[0] = view;
if ( view == clipPos ) {
String msg =
getString( R.string.not_again_clip_expl_fmt,
getString(R.string.invite_choice_clip) );
showNotAgainDlgThen( msg, R.string.key_na_clip_expl );
}
}
};
OnClickListener okClicked = new OnClickListener() {

View file

@ -49,7 +49,6 @@ import org.eehouse.android.xw4.jni.CommsAddrRec.CommsConnType;
import org.eehouse.android.xw4.jni.CommsAddrRec.CommsConnTypeSet;
import org.eehouse.android.xw4.jni.CurGameInfo.DeviceRole;
import org.eehouse.android.xw4.jni.LastMoveInfo;
import org.eehouse.android.xw4.DlgDelegate.DlgClickNotify.InviteMeans;
public class GameUtils {
@ -608,6 +607,33 @@ public class GameUtils {
isHost );
}
// @SuppressLint({ "NewApi", "NewApi", "NewApi", "NewApi" })
// @SuppressWarnings("deprecation")
// @TargetApi(11)
public static void inviteURLToClip( Context context, NetLaunchInfo nli )
{
Uri gameUri = nli.makeLaunchUri( context );
String asStr = gameUri.toString();
int sdk = android.os.Build.VERSION.SDK_INT;
if ( sdk < android.os.Build.VERSION_CODES.HONEYCOMB ) {
android.text.ClipboardManager clipboard =
(android.text.ClipboardManager)
context.getSystemService(Context.CLIPBOARD_SERVICE);
clipboard.setText( asStr );
} else {
android.content.ClipboardManager clipboard =
(android.content.ClipboardManager)
context.getSystemService(Context.CLIPBOARD_SERVICE);
String label = LocUtils.getString( context, R.string.clip_label );
android.content.ClipData clip = android.content.ClipData
.newPlainText( label, asStr );
clipboard.setPrimaryClip( clip );
}
Utils.showToast( context, R.string.invite_copied );
}
public static void launchEmailInviteActivity( Activity activity, NetLaunchInfo nli )
{
// DbgUtils.logf( "launchEmailInviteActivity: nli=%s", nli.makeLaunchJSON() );