query user before sending invite whether to use html or text and

format differently depending on the answer.  With html only I couldn't
invite using SMS, which bites.
This commit is contained in:
Andy2 2011-08-06 13:01:40 -07:00
parent 560208f516
commit d7dfb89f65
5 changed files with 102 additions and 8 deletions

View file

@ -64,6 +64,8 @@
<string name="button_save">Save</string>
<string name="button_discard">Discard</string>
<string name="button_retry">Retry</string>
<string name="button_text">Text</string>
<string name="button_html">Html</string>
<string name="player_label">Name:</string>
@ -558,13 +560,19 @@
that many people.)</string>
<string name="invite_subject">Let\'s play Crosswords</string>
<string name="invite_bodyf">\u003ca href=\"%1$s\"\u003ETap here to
<string name="invite_htmf">\u003ca href=\"%1$s\"\u003ETap here to
accept\u003c/a\u003E my invitation and join this
game.\u003cbr\u003E \u003ca
href=\"http://eehouse.org/market.php\"\u003E
Tap here to install Crosswords\u003c/a\u003E if you haven\'t
already.</string>
<string name="invite_txtf">Accept my invitation and join this
game: %1$s . (But install Crosswords first:
http://eehouse.org/market.php ).</string>
<string name="text_or_html">Send invitation using plain text or
html? Text links are harder to open but can be sent via SMS.
Most devices let you send html only via email.</string>
<string name="invite_chooser">Send invitation via</string>
<string name="no_download_warning">Unable to download. Do you have

View file

@ -39,6 +39,7 @@ public class DlgDelegate {
public static final int DIALOG_OKONLY = 2;
public static final int DIALOG_NOTAGAIN = 3;
public static final int CONFIRM_THEN = 4;
public static final int TEXT_OR_HTML_THEN = 5;
public static final int DIALOG_LAST = CONFIRM_THEN;
private int m_msgID;
@ -49,6 +50,11 @@ public class DlgDelegate {
private String m_dictName = null;
DialogInterface.OnClickListener m_then;
public interface TextOrHtmlClicked {
public void clicked( boolean choseText );
};
private TextOrHtmlClicked m_txt_or_html;
public DlgDelegate( Activity activity ) {
m_activity = activity;
}
@ -69,6 +75,9 @@ public class DlgDelegate {
case CONFIRM_THEN:
dialog = createConfirmThenDialog();
break;
case TEXT_OR_HTML_THEN:
dialog = createHtmlThenDialog();
break;
}
return dialog;
}
@ -87,6 +96,8 @@ public class DlgDelegate {
public void onPrepareDialog( int id, Dialog dialog )
{
AlertDialog ad = (AlertDialog)dialog;
DialogInterface.OnClickListener lstnr;
switch( id ) {
case DIALOG_ABOUT:
break;
@ -105,6 +116,22 @@ public class DlgDelegate {
ad.setButton( AlertDialog.BUTTON_POSITIVE,
m_activity.getString( R.string.button_ok ), m_then );
break;
case TEXT_OR_HTML_THEN:
lstnr = new DialogInterface.OnClickListener() {
public void onClick( DialogInterface dlg, int button ) {
if ( null != m_txt_or_html ) {
m_txt_or_html.
clicked( button == AlertDialog.BUTTON_POSITIVE );
}
}
};
ad.setButton( AlertDialog.BUTTON_POSITIVE,
m_activity.getString( R.string.button_text ),
lstnr );
ad.setButton( AlertDialog.BUTTON_NEGATIVE,
m_activity.getString( R.string.button_html ),
lstnr );
break;
}
}
@ -142,6 +169,12 @@ public class DlgDelegate {
m_activity.showDialog( CONFIRM_THEN );
}
public void showTextOrHtmlThen( TextOrHtmlClicked txtOrHtml )
{
m_txt_or_html = txtOrHtml;
m_activity.showDialog( TEXT_OR_HTML_THEN );
}
public void doSyncMenuitem()
{
if ( null == DBUtils.getRelayIDs( m_activity, false ) ) {
@ -239,4 +272,15 @@ public class DlgDelegate {
.create();
return dialog;
}
private Dialog createHtmlThenDialog()
{
return new AlertDialog.Builder( m_activity )
.setTitle( R.string.query_title )
.setMessage( R.string.text_or_html )
.setPositiveButton( R.string.button_text, null ) // will change
.setNegativeButton( R.string.button_html, null )
.create();
}
}

View file

@ -404,7 +404,9 @@ public class GameUtils {
info.nPlayers );
}
public static void launchInviteActivity( Context context, String room,
public static void launchInviteActivity( Context context,
boolean choseText,
String room,
int lang, int nPlayers )
{
Random random = new Random();
@ -413,19 +415,36 @@ public class GameUtils {
if ( null != gameUri ) {
Intent intent = new Intent( Intent.ACTION_SEND );
intent.setType("text/html");
intent.setType( choseText? "text/plain" : "text/html");
intent.putExtra( Intent.EXTRA_SUBJECT,
context.getString( R.string.invite_subject ) );
String format = context.getString( R.string.invite_bodyf );
int fmtId = choseText? R.string.invite_txtf : R.string.invite_htmf;
String format = context.getString( fmtId );
String message = String.format( format, gameUri.toString() );
intent.putExtra( Intent.EXTRA_TEXT, Html.fromHtml(message) );
intent.putExtra( Intent.EXTRA_TEXT,
choseText ? message : Html.fromHtml(message) );
String chooserMsg = context.getString( R.string.invite_chooser );
context.startActivity( Intent.createChooser( intent, chooserMsg ) );
}
}
public static void launchInviteActivity( final XWActivity activity,
final String room,
final int lang,
final int nPlayers )
{
DlgDelegate.TextOrHtmlClicked cb =
new DlgDelegate.TextOrHtmlClicked() {
public void clicked( boolean choseText ) {
launchInviteActivity( activity, choseText, room,
lang, nPlayers );
}
};
activity.showTextOrHtmlThen( cb );
}
public static boolean gameDictsHere( Context context, long rowid )
{
return gameDictsHere( context, rowid, null, null );

View file

@ -88,6 +88,7 @@ public class NewGameActivity extends XWActivity {
private void makeNewGame( boolean networked, boolean launch )
{
boolean finished = true;
String room = null;
long rowid;
int[] lang = {0};
@ -102,15 +103,32 @@ public class NewGameActivity extends XWActivity {
}
if ( launch ) {
GameUtils.launchGame( this, rowid, networked );
if ( networked ) {
GameUtils.launchInviteActivity( this, room, lang[0], nPlayers );
finished = false;
final String froom = room;
final long frowid = rowid;
final int flang = lang[0];
showTextOrHtmlThen( new DlgDelegate.TextOrHtmlClicked() {
public void clicked( boolean choseText ) {
GameUtils.launchGame( NewGameActivity.this,
frowid, true );
GameUtils.
launchInviteActivity( NewGameActivity.this,
choseText, froom, flang,
nPlayers );
finish();
}
} );
} else {
GameUtils.launchGame( this, rowid, false );
}
} else {
GameUtils.doConfig( this, rowid, GameConfig.class );
}
finish();
if ( finished ) {
finish();
}
}
}

View file

@ -127,6 +127,11 @@ public class XWActivity extends Activity {
m_delegate.showConfirmThen( getString(msgID), action );
}
public void showTextOrHtmlThen( DlgDelegate.TextOrHtmlClicked txtOrHtml )
{
m_delegate.showTextOrHtmlThen( txtOrHtml );
}
protected void doSyncMenuitem()
{
m_delegate.doSyncMenuitem();