2424import io .branch .referral .BranchError ;
2525import io .branch .referral .BranchViewHandler ;
2626import io .branch .referral .Defines ;
27- import io .branch .referral .validators .DeepLinkRoutingValidator ;
2827import io .branch .referral .SharingHelper ;
2928import io .branch .referral .util .BRANCH_STANDARD_EVENT ;
3029import io .branch .referral .util .BranchContentSchema ;
3433import io .branch .referral .util .LinkProperties ;
3534import io .branch .referral .util .ProductCategory ;
3635import io .branch .referral .util .ShareSheetStyle ;
37- import io .branch .referral .validators .IntegrationValidator ;
3836
3937
4038public class MainActivity extends Activity {
41- Branch branch ;
39+ private EditText txtShortUrl ;
40+ private TextView txtInstallCount ;
41+ private TextView txtRewardBalance ;
4242
43- EditText txtShortUrl ;
44- TextView txtInstallCount ;
45- TextView txtRewardBalance ;
46-
47- BranchUniversalObject branchUniversalObject ;
43+ private BranchUniversalObject branchUniversalObject ;
4844
4945 @ Override
5046 protected void onCreate (Bundle savedInstanceState ) {
5147 super .onCreate (savedInstanceState );
5248 setContentView (R .layout .activity_main );
5349
54- txtShortUrl = ( EditText ) findViewById (R .id .editReferralShortUrl );
55- txtInstallCount = ( TextView ) findViewById (R .id .txtInstallCount );
56- txtRewardBalance = ( TextView ) findViewById (R .id .txtRewardBalance );
50+ txtShortUrl = findViewById (R .id .editReferralShortUrl );
51+ txtInstallCount = findViewById (R .id .txtInstallCount );
52+ txtRewardBalance = findViewById (R .id .txtRewardBalance );
5753 ((ToggleButton ) findViewById (R .id .tracking_cntrl_btn )).setChecked (Branch .getInstance ().isTrackingDisabled ());
5854
5955 // Create a BranchUniversal object for the content referred on this activity instance
@@ -90,7 +86,7 @@ protected void onCreate(Bundle savedInstanceState) {
9086 findViewById (R .id .cmdIdentifyUser ).setOnClickListener (new OnClickListener () {
9187 @ Override
9288 public void onClick (View v ) {
93- branch .setIdentity ("test_user_10" , new BranchReferralInitListener () {
89+ Branch . getInstance () .setIdentity ("test_user_10" , new BranchReferralInitListener () {
9490 @ Override
9591 public void onInitFinished (JSONObject referringParams , BranchError error ) {
9692 if (error != null ) {
@@ -106,22 +102,22 @@ public void onInitFinished(JSONObject referringParams, BranchError error) {
106102 findViewById (R .id .cmdClearUser ).setOnClickListener (new OnClickListener () {
107103 @ Override
108104 public void onClick (View v ) {
109- branch .logout (new Branch .LogoutStatusListener () {
105+ Branch . getInstance () .logout (new Branch .LogoutStatusListener () {
110106 @ Override
111107 public void onLogoutFinished (boolean loggedOut , BranchError error ) {
112108 Log .i ("BranchTestBed" , "onLogoutFinished " + loggedOut + " errorMessage " + error );
113109 }
114110 });
115111
116- txtRewardBalance .setText ("rewards = " );
117- txtInstallCount .setText ("install count =" );
112+ txtRewardBalance .setText (R . string . rewards_empty );
113+ txtInstallCount .setText (R . string . install_count_empty );
118114 }
119115 });
120116
121117 findViewById (R .id .cmdPrintInstallParam ).setOnClickListener (new OnClickListener () {
122118 @ Override
123119 public void onClick (View v ) {
124- JSONObject obj = branch .getFirstReferringParams ();
120+ JSONObject obj = Branch . getInstance () .getFirstReferringParams ();
125121 Log .i ("BranchTestBed" , "install params = " + obj .toString ());
126122 }
127123 });
@@ -139,33 +135,35 @@ public void onClick(View arg0) {
139135 .setDuration (100 );
140136 //.setAlias("myContentName") // in case you need to white label your link
141137
142- // Sync link create example
143- txtShortUrl .setText (branchUniversalObject .getShortUrl (MainActivity .this , linkProperties ));
138+ // Sync link create example. This makes a network call on the UI thread
139+ // txtShortUrl.setText(branchUniversalObject.getShortUrl(MainActivity.this, linkProperties));
144140
145141 // Async Link creation example
146- /* branchUniversalObject.generateShortUrl(MainActivity.this, linkProperties, new Branch.BranchLinkCreateListener() {
142+ branchUniversalObject .generateShortUrl (MainActivity .this , linkProperties , new Branch .BranchLinkCreateListener () {
147143 @ Override
148144 public void onLinkCreate (String url , BranchError error ) {
149- String shortUrl = url;
145+ if (error != null ) {
146+ txtShortUrl .setText (error .getMessage ());
147+ } else {
148+ txtShortUrl .setText (url );
149+ }
150150 }
151- });*/
152-
151+ });
153152 }
154-
155153 });
156154
157155
158156 findViewById (R .id .cmdRefreshReward ).setOnClickListener (new OnClickListener () {
159157 @ Override
160158 public void onClick (View arg0 ) {
161- branch .loadRewards (new BranchReferralStateChangedListener () {
159+ Branch . getInstance () .loadRewards (new BranchReferralStateChangedListener () {
162160 @ Override
163161 public void onStateChanged (boolean changed , BranchError error ) {
164162 if (error != null ) {
165163 Log .i ("BranchTestBed" , "branch load rewards failed. Caused by -" + error .getMessage ());
166164 } else {
167165 Log .i ("BranchTestBed" , "changed = " + changed );
168- txtRewardBalance .setText (" rewards = " + branch . getCredits ());
166+ txtRewardBalance .setText (getString ( R . string . rewards , Branch . getInstance (). getCredits () ));
169167 }
170168 }
171169 });
@@ -175,15 +173,15 @@ public void onStateChanged(boolean changed, BranchError error) {
175173 findViewById (R .id .cmdRedeemFive ).setOnClickListener (new OnClickListener () {
176174 @ Override
177175 public void onClick (View v ) {
178- branch .redeemRewards (5 , new BranchReferralStateChangedListener () {
176+ Branch . getInstance () .redeemRewards (5 , new BranchReferralStateChangedListener () {
179177 @ Override
180178 public void onStateChanged (boolean changed , BranchError error ) {
181179 if (error != null ) {
182180 Log .i ("BranchTestBed" , "branch redeem rewards failed. Caused by -" + error .getMessage ());
183181 } else {
184182 if (changed ) {
185183 Log .i ("BranchTestBed" , "redeemed rewards = " + true );
186- txtRewardBalance .setText (" rewards = " + branch . getCredits ());
184+ txtRewardBalance .setText (getString ( R . string . rewards , Branch . getInstance (). getCredits () ));
187185 } else {
188186 Log .i ("BranchTestBed" , "redeem rewards unknown error " );
189187 }
@@ -196,7 +194,7 @@ public void onStateChanged(boolean changed, BranchError error) {
196194 findViewById (R .id .cmdCommitBuyAction ).setOnClickListener (new OnClickListener () {
197195 @ Override
198196 public void onClick (View v ) {
199- branch .userCompletedAction ("buy" , new BranchViewHandler .IBranchViewEvents () {
197+ Branch . getInstance () .userCompletedAction ("buy" , new BranchViewHandler .IBranchViewEvents () {
200198 @ Override
201199 public void onBranchViewVisible (String action , String branchViewID ) {
202200 Log .i ("BranchTestBed" , "onBranchViewVisible" );
@@ -233,7 +231,7 @@ public void onClick(View arg0) {
233231 } catch (JSONException e ) {
234232 e .printStackTrace ();
235233 }
236- branch .userCompletedAction ("buy" , params );
234+ Branch . getInstance () .userCompletedAction ("buy" , params );
237235 }
238236
239237 });
@@ -263,7 +261,6 @@ public void onClick(View v) {
263261 findViewById (R .id .share_btn ).setOnClickListener (new OnClickListener () {
264262 @ Override
265263 public void onClick (View view ) {
266- JSONObject obj = new JSONObject ();
267264 LinkProperties linkProperties = new LinkProperties ()
268265 .addTag ("myShareTag1" )
269266 .addTag ("myShareTag2" )
@@ -307,7 +304,7 @@ public void onLinkShareResponse(String sharedLink, String sharedChannel, BranchE
307304 public void onChannelSelected (String channelName ) {
308305 }
309306
310- /**
307+ /*
311308 * Use {@link io.branch.referral.Branch.ExtendedBranchLinkShareListener} if the params need to be modified according to the channel selected by the user.
312309 * This allows modification of content or link properties through callback {@link #onChannelSelected(String, BranchUniversalObject, LinkProperties)} }
313310 */
@@ -381,7 +378,7 @@ public void onClick(View v) {
381378 ((ToggleButton ) findViewById (R .id .tracking_cntrl_btn )).setOnCheckedChangeListener (new CompoundButton .OnCheckedChangeListener () {
382379 @ Override
383380 public void onCheckedChanged (CompoundButton buttonView , boolean isChecked ) {
384- branch .getInstance ().disableTracking (isChecked );
381+ Branch .getInstance ().disableTracking (isChecked );
385382 }
386383 });
387384
@@ -391,8 +388,7 @@ public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
391388 @ Override
392389 protected void onStart () {
393390 super .onStart ();
394- branch = Branch .getInstance ();
395- branch .initSession (new Branch .BranchUniversalReferralInitListener () {
391+ Branch .getInstance ().initSession (new Branch .BranchUniversalReferralInitListener () {
396392 @ Override
397393 public void onInitFinished (BranchUniversalObject branchUniversalObject , LinkProperties linkProperties , BranchError error ) {
398394 if (error != null ) {
0 commit comments