Skip to content

Commit

Permalink
Custom HTML
Browse files Browse the repository at this point in the history
Change-Id: Ied06a086e26ba8794da32322969de3847d6f482d
  • Loading branch information
samtstern committed Dec 9, 2015
1 parent faf21ad commit 94c0482
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 4 deletions.
3 changes: 2 additions & 1 deletion android/appinvites/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ dependencies {
compile 'com.android.support:appcompat-v7:23.0.1'
compile 'com.android.support:design:23.0.1'

compile 'com.google.android.gms:play-services-appinvite:8.3.0'
// TODO: Change for release
compile 'com.google.android.gms:play-services-appinvite:8.4.89'

// UiAutomatorTesting
androidTestCompile 'com.android.support.test:runner:0.3'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
import com.google.android.gms.common.api.ResultCallback;

/**
* Main Activity for sending App Invites and launching the DeepLinkActivity when an
* Main Activity for sending App Invites and launchings the DeepLinkActivity when an
* App Invite is received.
*/
public class MainActivity extends AppCompatActivity implements
Expand All @@ -54,6 +54,7 @@ protected void onCreate(Bundle savedInstanceState) {

// Invite button click listener
findViewById(R.id.invite_button).setOnClickListener(this);
findViewById(R.id.custom_invite_button).setOnClickListener(this);
// [END_EXCLUDE]

// Create an auto-managed GoogleApiClient with acccess to App Invites.
Expand Down Expand Up @@ -102,6 +103,31 @@ private void onInviteClicked() {
}
// [END on_invite_clicked]

/**
* User has clicked the 'Custom Invite' button, launch the invitation UI but pass in
* a custom HTML body and subject for email invites.
*/
// [START on_custom_invite_clicked]
private void onCustomInviteClicked() {
// When using the setEmailHtmlContent method, you must also set a subject using the
// setEmailSubject message and you may not use either setCustomImage or setCallToActionText
// in conjunction with the setEmailHtmlContent method.
//
// The "%%APPINVITE_LINK_PLACEHOLDER%%" token is replaced by the invitation server
// with the custom invitation deep link based on the other parameters you provide.
Intent intent = new AppInviteInvitation.IntentBuilder(getString(R.string.invitation_title))
.setMessage(getString(R.string.invitation_message))
.setDeepLink(Uri.parse(getString(R.string.invitation_deep_link)))
.setEmailHtmlContent("<html><body>" +
"<h1>App Invites</h1>" +
"<a href=\"%%APPINVITE_LINK_PLACEHOLDER%%\">Install Now!</a>" +
"<body></html>")
.setEmailSubject(getString(R.string.invitation_subject))
.build();
startActivityForResult(intent, REQUEST_INVITE);
}
// [END on_custom_invite_clicked]

// [START on_activity_result]
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
Expand Down Expand Up @@ -135,6 +161,9 @@ public void onClick(View view) {
case R.id.invite_button:
onInviteClicked();
break;
case R.id.custom_invite_button:
onCustomInviteClicked();
break;
}
}
}
Expand Down
13 changes: 11 additions & 2 deletions android/appinvites/app/src/main/res/layout/main_activity.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,20 @@
android:id="@+id/invite_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/custom_invite_button"
android:layout_centerHorizontal="true"
android:text="@string/invite_friends"
android:theme="@style/ThemeOverlay.MyBlueButton"/>

<Button
android:id="@+id/custom_invite_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="75dp"
android:theme="@style/ThemeOverlay.MyBlueButton"
android:text="@string/invite_friends"/>
android:text="@string/custom_invite"
android:theme="@style/ThemeOverlay.MyBlueButton"/>

<FrameLayout
android:id="@+id/snackbar_layout"
Expand Down
2 changes: 2 additions & 0 deletions android/appinvites/app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
<string name="invitation_deep_link">http://example.com/offer/five_dollar_offer</string>
<string name="invitation_custom_image">https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png</string>
<string name="invitation_cta">Install!</string>
<string name="invitation_subject">Try this great app!</string>

<string name="deep_link_fmt" formatted="false">Deep Link: %s</string>
<string name="invitation_id_fmt" formatted="false">Invitation ID: %s</string>
Expand All @@ -26,4 +27,5 @@
<string name="invite_dialog_title">You got an invitation!</string>

<string name="google_play_services_error">Google Play Services Error</string>
<string name="custom_invite">Custom Invite</string>
</resources>

0 comments on commit 94c0482

Please sign in to comment.