4
4
import org .solovyev .android .checkout .Billing ;
5
5
import org .solovyev .android .checkout .Checkout ;
6
6
import org .solovyev .android .checkout .EmptyRequestListener ;
7
+ import org .solovyev .android .checkout .Logger ;
7
8
import org .solovyev .android .checkout .ProductTypes ;
8
9
import org .solovyev .android .checkout .Purchase ;
9
10
14
15
import android .view .View ;
15
16
import android .widget .ArrayAdapter ;
16
17
import android .widget .Spinner ;
18
+ import android .widget .TextView ;
19
+
20
+ import javax .annotation .Nonnull ;
17
21
18
22
import butterknife .BindView ;
19
23
import butterknife .ButterKnife ;
@@ -27,6 +31,8 @@ public class StaticActivity extends AppCompatActivity implements View.OnClickLis
27
31
View mBuy ;
28
32
@ BindView (R .id .skus )
29
33
Spinner mSkus ;
34
+ @ BindView (R .id .console )
35
+ TextView mConsole ;
30
36
private ActivityCheckout mCheckout ;
31
37
32
38
@ Override
@@ -39,6 +45,7 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
39
45
mBuy .setOnClickListener (this );
40
46
mSkus .setAdapter (new ArrayAdapter <>(this , R .layout .support_simple_spinner_dropdown_item , new String []{"android.test.purchased" , "android.test.canceled" , "android.test.refunded" , "android.test.item_unavailable" }));
41
47
mSkus .setSelection (0 );
48
+ Billing .setLogger (Billing .newMainThreadLogger (new BillingLogger (mConsole )));
42
49
43
50
final Billing billing = CheckoutApplication .get (this ).getBilling ();
44
51
mCheckout = Checkout .forActivity (this , billing );
@@ -54,6 +61,7 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
54
61
@ Override
55
62
protected void onDestroy () {
56
63
mCheckout .stop ();
64
+ Billing .setLogger (Billing .newLogger ());
57
65
super .onDestroy ();
58
66
}
59
67
@@ -62,8 +70,82 @@ public void onClick(View v) {
62
70
switch (v .getId ()) {
63
71
case R .id .buy :
64
72
final String sku = (String ) mSkus .getSelectedItem ();
73
+ mConsole .setText ("" );
65
74
mCheckout .startPurchaseFlow (ProductTypes .IN_APP , sku , null , new EmptyRequestListener <Purchase >());
66
75
break ;
67
76
}
68
77
}
78
+
79
+ private static class BillingLogger implements Logger {
80
+ private final TextView mView ;
81
+
82
+ public BillingLogger (TextView view ) {
83
+ mView = view ;
84
+ }
85
+
86
+ @ Override
87
+ public void v (@ Nonnull String tag , @ Nonnull String msg ) {
88
+ log ("v" , tag , msg , null );
89
+ }
90
+
91
+ private void log (String level , @ Nonnull String tag , @ Nonnull String msg , @ Nullable Throwable e ) {
92
+ if (!tag .equals ("Checkout" )) {
93
+ return ;
94
+ }
95
+ final boolean empty = mView .getText ().length () == 0 ;
96
+ if (!empty ) {
97
+ mView .append ("\n " );
98
+ }
99
+ mView .append (level + ": " + msg );
100
+ if (e != null ) {
101
+ mView .append ("\n " );
102
+ mView .append (e .getMessage ());
103
+ }
104
+ }
105
+
106
+ @ Override
107
+ public void v (@ Nonnull String tag , @ Nonnull String msg , @ Nonnull Throwable e ) {
108
+ log ("v" , tag , msg , e );
109
+ }
110
+
111
+ @ Override
112
+ public void d (@ Nonnull String tag , @ Nonnull String msg ) {
113
+ log ("d" , tag , msg , null );
114
+ }
115
+
116
+ @ Override
117
+ public void d (@ Nonnull String tag , @ Nonnull String msg , @ Nonnull Throwable e ) {
118
+ log ("d" , tag , msg , e );
119
+ }
120
+
121
+ @ Override
122
+ public void i (@ Nonnull String tag , @ Nonnull String msg ) {
123
+ log ("i" , tag , msg , null );
124
+ }
125
+
126
+ @ Override
127
+ public void i (@ Nonnull String tag , @ Nonnull String msg , @ Nonnull Throwable e ) {
128
+ log ("i" , tag , msg , e );
129
+ }
130
+
131
+ @ Override
132
+ public void w (@ Nonnull String tag , @ Nonnull String msg ) {
133
+ log ("w" , tag , msg , null );
134
+ }
135
+
136
+ @ Override
137
+ public void w (@ Nonnull String tag , @ Nonnull String msg , @ Nonnull Throwable e ) {
138
+ log ("w" , tag , msg , e );
139
+ }
140
+
141
+ @ Override
142
+ public void e (@ Nonnull String tag , @ Nonnull String msg ) {
143
+ log ("e" , tag , msg , null );
144
+ }
145
+
146
+ @ Override
147
+ public void e (@ Nonnull String tag , @ Nonnull String msg , @ Nonnull Throwable e ) {
148
+ log ("e" , tag , msg , e );
149
+ }
150
+ }
69
151
}
0 commit comments