Advertisement
Guest User

Untitled

a guest
Nov 4th, 2016
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.20 KB | None | 0 0
  1. package hack.autoinstalls.autoinstallhack;
  2.  
  3. import android.app.Activity;
  4. import android.content.Intent;
  5. import android.content.SharedPreferences;
  6. import android.content.pm.PackageInfo;
  7. import android.content.pm.PackageManager;
  8. import android.os.Bundle;
  9. import android.view.View;
  10. import android.view.View.OnClickListener;
  11. import android.widget.Button;
  12. import android.widget.CheckBox;
  13. import android.widget.EditText;
  14.  
  15. public class Main extends Activity {
  16.  
  17. SharedPreferences prefs;
  18. String pack;
  19.  
  20. @Override
  21. protected void onCreate(Bundle savedInstanceState) {
  22. super.onCreate(savedInstanceState);
  23. setContentView(R.layout.activity_main);
  24. prefs = getSharedPreferences(getPackageName(), 0);
  25.  
  26. // Sample code:
  27. final EditText p = (EditText) findViewById(R.id.editText1);
  28. final EditText p2 = (EditText) findViewById(R.id.editText2);
  29. final EditText p3 = (EditText) findViewById(R.id.editText3);
  30. p.setText("com.elvison.batterywidget"); //com.darek.beerw"); //com.nadroj"); //com.sum.mp3converter");
  31. Button b = (Button) findViewById(R.id.button1);
  32. Button b2 = (Button) findViewById(R.id.button2);
  33. Button b3 = (Button) findViewById(R.id.button3);
  34. final CheckBox c = (CheckBox) findViewById(R.id.checkBox1);
  35. b.setOnClickListener(new OnClickListener() {
  36. @Override
  37. public void onClick(View arg0) {
  38. prefs.edit().putBoolean("hide", c.isChecked()).commit();
  39. installPackageAndRate(p.getText().toString(), Integer
  40. .parseInt(p2.getText().toString()), p3.getText()
  41. .toString(), true); // 1 parameter - package name , 2
  42. // parameter - number of stars , 3
  43. // parameter - optional comment , 4
  44. // parameter - rate immediatelly
  45. // after install
  46. }
  47. });
  48. b2.setOnClickListener(new OnClickListener() {
  49. @Override
  50. public void onClick(View arg0) {
  51. prefs.edit().putBoolean("hide", c.isChecked()).commit();
  52. installPackageAndRate(p.getText().toString(), Integer
  53. .parseInt(p2.getText().toString()), p3.getText()
  54. .toString(), false);
  55. }
  56. });
  57. b3.setOnClickListener(new OnClickListener() {
  58. @Override
  59. public void onClick(View arg0) {
  60. prefs.edit().putBoolean("hide", c.isChecked()).commit();
  61. onlyRate(p.getText().toString(), Integer.parseInt(p2.getText()
  62. .toString()), p3.getText().toString(), true);
  63. }
  64. });
  65.  
  66. }
  67.  
  68. private boolean isPackageExisted(String targetPackage) {
  69. PackageManager pm = getPackageManager();
  70. try {
  71. PackageInfo info = pm.getPackageInfo(targetPackage,
  72. PackageManager.GET_META_DATA);
  73. } catch (PackageManager.NameNotFoundException e) {
  74. return false;
  75. }
  76. return true;
  77. }
  78.  
  79. private void installPackageAndRate(String packageName, int rating,
  80. String comment, boolean autoRating) {
  81. pack = packageName;
  82. try {
  83. String rate = "";
  84. if (rating == 0) // do not rate if second parameter is 0
  85. prefs.edit().putBoolean(pack + "rate", true).commit();
  86. else if (rating == 5)
  87. rate = "fifth-star";
  88. else if (rating == 4)
  89. rate = "fourth-star";
  90. else if (rating == 3)
  91. rate = "third-star";
  92. else if (rating == 2)
  93. rate = "second-star";
  94. else if (rating == 1)
  95. rate = "first-star";
  96. prefs.edit().putString(pack + "stars", rate).commit();
  97. prefs.edit().putBoolean(pack + "auto", autoRating).commit();
  98. prefs.edit().putString(pack + "review", comment).commit();
  99. } catch (Exception e) {
  100. }
  101. prefs.edit().putString("pack", pack).commit();
  102. if (!isPackageExisted(pack)) { // if package is not installed -
  103. // install it first
  104. Intent a = new Intent(this, InstallActivity.class);
  105. a.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK
  106. | Intent.FLAG_ACTIVITY_SINGLE_TOP
  107. | Intent.FLAG_ACTIVITY_NEW_TASK);
  108. startActivity(a);
  109. } else if (!prefs.getBoolean(pack + "rate", false)) { // if package
  110. // is
  111. // installed
  112. // - rate
  113. // it if it was
  114. // nor rated
  115. // before
  116. Intent a = new Intent(this, RateActivity.class);
  117. a.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK
  118. | Intent.FLAG_ACTIVITY_SINGLE_TOP
  119. | Intent.FLAG_ACTIVITY_NEW_TASK);
  120. startActivity(a);
  121.  
  122. }
  123. }
  124.  
  125. private void onlyRate(String packageName, int rating, String comment,
  126. boolean autoRating) {
  127. prefs = getSharedPreferences(getPackageName(), 0);
  128. pack = packageName;
  129. String rate = "";
  130. if (rating == 0) // do not rate if second parameter is 0
  131. prefs.edit().putBoolean(pack + "rate", true).commit();
  132. else if (rating == 5)
  133. rate = "fifth-star";
  134. else if (rating == 4)
  135. rate = "fourth-star";
  136. else if (rating == 3)
  137. rate = "third-star";
  138. else if (rating == 2)
  139. rate = "second-star";
  140. else if (rating == 1)
  141. rate = "first-star";
  142. prefs.edit().putString(pack + "stars", rate).commit();
  143. prefs.edit().putBoolean(pack + "auto", autoRating).commit();
  144. prefs.edit().putString(pack + "review", comment).commit();
  145. prefs.edit().putString("pack", pack).commit();
  146. if (isPackageExisted(pack)) {
  147. Intent a = new Intent(this, RateActivity.class);
  148. a.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK
  149. | Intent.FLAG_ACTIVITY_SINGLE_TOP
  150. | Intent.FLAG_ACTIVITY_NEW_TASK);
  151. startActivity(a);
  152.  
  153. }
  154. }
  155. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement