Guest User

Untitled

a guest
Apr 26th, 2018
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.98 KB | None | 0 0
  1. public class ActivityBuy extends AppCompatActivity {
  2. IabHelper mHelper;
  3. public static final int BUY_CODE = 13;
  4. IInAppBillingService mService;
  5.  
  6. @Override
  7. protected void onCreate(Bundle savedInstanceState) {
  8. super.onCreate(savedInstanceState); // <== строка 31
  9. setContentView(R.layout.dialog_buy);
  10.  
  11. findViewById(R.id.dialogExit).setOnClickListener(new View.OnClickListener() {
  12. @Override
  13. public void onClick(View v) {
  14. finish();
  15. }
  16. });
  17. findViewById(R.id.dialogBuy).setOnClickListener(new View.OnClickListener() {
  18. @Override
  19. public void onClick(View v) {
  20. try {
  21. buyFullResolve();
  22. } catch (RemoteException e) {
  23. e.printStackTrace();
  24. }
  25. finish();
  26. }
  27. });
  28.  
  29. Intent serviceIntent = new Intent("com.android.vending.billing.InAppBillingService.BIND");
  30. serviceIntent.setPackage("com.android.vending");
  31. bindService(serviceIntent, mServiceConn, Context.BIND_AUTO_CREATE);
  32.  
  33. String base64EncodedPublicKey = getString(R.string.licence);
  34.  
  35. mHelper = new IabHelper(this, base64EncodedPublicKey);
  36.  
  37. mHelper.startSetup(new IabHelper.OnIabSetupFinishedListener() {
  38. public void onIabSetupFinished(IabResult result) {
  39. if (!result.isSuccess()) {
  40. Log.d("ttt", "Problem setting up In-app Billing: " + result);
  41. } else {
  42. Log.d("ttt", "Success: " + result);
  43. mHelper.queryInventoryAsync(mGotInventoryListener);
  44. }
  45. }
  46. });
  47. }
  48.  
  49. IabHelper.QueryInventoryFinishedListener mGotInventoryListener
  50. = new IabHelper.QueryInventoryFinishedListener() {
  51. public void onQueryInventoryFinished(IabResult result, Inventory inventory) {
  52. if (result.isFailure()) {
  53. StaticToaster.makeToaster(getLayoutInflater(), ActivityBuy.this, getString(R.string.noconnection), true, true);
  54. } else {
  55. //
  56. }
  57. }
  58. };
  59.  
  60.  
  61. public void buyFullResolve() throws RemoteException {
  62. ArrayList<String> skuList = new ArrayList<String>();
  63. skuList.add(getString(R.string.buyFullID));
  64. Bundle querySkus = new Bundle();
  65. querySkus.putStringArrayList("ITEM_ID_LIST", skuList);
  66.  
  67. try {
  68. if (mHelper != null) mHelper.flagEndAsync();
  69. mHelper.launchPurchaseFlow(this, getString(R.string.buyFullID), BUY_CODE, mPurchaseFinishedListener, getString(R.string.randomKey));
  70. } catch (IllegalStateException e) {
  71. StaticToaster.makeToaster(getLayoutInflater(), this, "Покупка не удалась. Попробуйте через несколько секунд.", false, false);
  72. }
  73. }
  74.  
  75. IabHelper.OnIabPurchaseFinishedListener mPurchaseFinishedListener
  76. = new IabHelper.OnIabPurchaseFinishedListener() {
  77. public void onIabPurchaseFinished(IabResult result, Purchase purchase) {
  78. if (result.isFailure()) {
  79. Log.d("ttt", "Error purchasing: " + result);
  80. setResult(RESULT_CANCELED);
  81. } else if (purchase.getSku().equals(getString(R.string.buyFullID))) {
  82. MyLab.get(ActivityBuy.this).setFullVersion(true);
  83. StaticToaster.makeToaster(getLayoutInflater(), ActivityBuy.this, getString(R.string.fullSuccess), false, false);
  84.  
  85. setResult(RESULT_OK);
  86. finish();
  87. }
  88. }
  89. };
  90.  
  91. ServiceConnection mServiceConn = new ServiceConnection() {
  92. @Override
  93. public void onServiceDisconnected(ComponentName name) {
  94. mService = null;
  95. }
  96.  
  97. @Override
  98. public void onServiceConnected(ComponentName name,
  99. IBinder service) {
  100. mService = IInAppBillingService.Stub.asInterface(service);
  101. }
  102. };
  103.  
  104. private void queryPurchasedItems() {
  105. if (mHelper.isSetupDone() && !mHelper.isAsyncInProgress()) {
  106. mHelper.queryInventoryAsync(mGotInventoryListener);
  107. }
  108. }
  109.  
  110. <style name="myDialogStyle" parent="Theme.AppCompat.Dialog.Alert">
  111. <item name="windowActionBar">false</item>
  112. <item name="windowNoTitle">true</item>
  113. </style>
  114.  
  115. <?xml version="1.0" encoding="utf-8"?>
  116. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  117. android:layout_width="match_parent"
  118. android:layout_height="wrap_content"
  119. android:orientation="vertical">
  120.  
  121. <TextView
  122. style="@style/textStyle"
  123. android:text="@string/buyFullHeader"
  124. android:id="@+id/header"/>
  125.  
  126. <TextView
  127. android:id="@+id/dialogHeaderText"
  128. style="@style/textStyle"
  129. android:text="@string/buyFullVersion" />
  130.  
  131. <LinearLayout
  132. android:layout_width="match_parent"
  133. android:layout_height="wrap_content"
  134. android:orientation="horizontal">
  135.  
  136. <Button
  137. android:id="@+id/dialogExit"
  138. android:text="@string/back"
  139. style="@style/dialogButton"/>
  140.  
  141. <Button
  142. android:id="@+id/dialogBuy"
  143. android:text="@string/buy"
  144. style="@style/dialogButton"/>
  145.  
  146. </LinearLayout>
  147.  
  148. compileSdkVersion 27
  149. buildToolsVersion "27.0.3"
  150.  
  151. defaultConfig {
  152. applicationId "id"
  153. minSdkVersion 14
  154. targetSdkVersion 27
  155. versionCode 1
  156. versionName "1.1"
  157. }
Add Comment
Please, Sign In to add comment