Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package hack.autoinstalls.autoinstallhack;
- import android.app.Activity;
- import android.content.Intent;
- import android.content.SharedPreferences;
- import android.content.pm.PackageInfo;
- import android.content.pm.PackageManager;
- import android.os.Bundle;
- import android.view.View;
- import android.view.View.OnClickListener;
- import android.widget.Button;
- import android.widget.CheckBox;
- import android.widget.EditText;
- public class Main extends Activity {
- SharedPreferences prefs;
- String pack;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- prefs = getSharedPreferences(getPackageName(), 0);
- // Sample code:
- final EditText p = (EditText) findViewById(R.id.editText1);
- final EditText p2 = (EditText) findViewById(R.id.editText2);
- final EditText p3 = (EditText) findViewById(R.id.editText3);
- p.setText("com.elvison.batterywidget"); //com.darek.beerw"); //com.nadroj"); //com.sum.mp3converter");
- Button b = (Button) findViewById(R.id.button1);
- Button b2 = (Button) findViewById(R.id.button2);
- Button b3 = (Button) findViewById(R.id.button3);
- final CheckBox c = (CheckBox) findViewById(R.id.checkBox1);
- b.setOnClickListener(new OnClickListener() {
- @Override
- public void onClick(View arg0) {
- prefs.edit().putBoolean("hide", c.isChecked()).commit();
- installPackageAndRate(p.getText().toString(), Integer
- .parseInt(p2.getText().toString()), p3.getText()
- .toString(), true); // 1 parameter - package name , 2
- // parameter - number of stars , 3
- // parameter - optional comment , 4
- // parameter - rate immediatelly
- // after install
- }
- });
- b2.setOnClickListener(new OnClickListener() {
- @Override
- public void onClick(View arg0) {
- prefs.edit().putBoolean("hide", c.isChecked()).commit();
- installPackageAndRate(p.getText().toString(), Integer
- .parseInt(p2.getText().toString()), p3.getText()
- .toString(), false);
- }
- });
- b3.setOnClickListener(new OnClickListener() {
- @Override
- public void onClick(View arg0) {
- prefs.edit().putBoolean("hide", c.isChecked()).commit();
- onlyRate(p.getText().toString(), Integer.parseInt(p2.getText()
- .toString()), p3.getText().toString(), true);
- }
- });
- }
- private boolean isPackageExisted(String targetPackage) {
- PackageManager pm = getPackageManager();
- try {
- PackageInfo info = pm.getPackageInfo(targetPackage,
- PackageManager.GET_META_DATA);
- } catch (PackageManager.NameNotFoundException e) {
- return false;
- }
- return true;
- }
- private void installPackageAndRate(String packageName, int rating,
- String comment, boolean autoRating) {
- pack = packageName;
- try {
- String rate = "";
- if (rating == 0) // do not rate if second parameter is 0
- prefs.edit().putBoolean(pack + "rate", true).commit();
- else if (rating == 5)
- rate = "fifth-star";
- else if (rating == 4)
- rate = "fourth-star";
- else if (rating == 3)
- rate = "third-star";
- else if (rating == 2)
- rate = "second-star";
- else if (rating == 1)
- rate = "first-star";
- prefs.edit().putString(pack + "stars", rate).commit();
- prefs.edit().putBoolean(pack + "auto", autoRating).commit();
- prefs.edit().putString(pack + "review", comment).commit();
- } catch (Exception e) {
- }
- prefs.edit().putString("pack", pack).commit();
- if (!isPackageExisted(pack)) { // if package is not installed -
- // install it first
- Intent a = new Intent(this, InstallActivity.class);
- a.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK
- | Intent.FLAG_ACTIVITY_SINGLE_TOP
- | Intent.FLAG_ACTIVITY_NEW_TASK);
- startActivity(a);
- } else if (!prefs.getBoolean(pack + "rate", false)) { // if package
- // is
- // installed
- // - rate
- // it if it was
- // nor rated
- // before
- Intent a = new Intent(this, RateActivity.class);
- a.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK
- | Intent.FLAG_ACTIVITY_SINGLE_TOP
- | Intent.FLAG_ACTIVITY_NEW_TASK);
- startActivity(a);
- }
- }
- private void onlyRate(String packageName, int rating, String comment,
- boolean autoRating) {
- prefs = getSharedPreferences(getPackageName(), 0);
- pack = packageName;
- String rate = "";
- if (rating == 0) // do not rate if second parameter is 0
- prefs.edit().putBoolean(pack + "rate", true).commit();
- else if (rating == 5)
- rate = "fifth-star";
- else if (rating == 4)
- rate = "fourth-star";
- else if (rating == 3)
- rate = "third-star";
- else if (rating == 2)
- rate = "second-star";
- else if (rating == 1)
- rate = "first-star";
- prefs.edit().putString(pack + "stars", rate).commit();
- prefs.edit().putBoolean(pack + "auto", autoRating).commit();
- prefs.edit().putString(pack + "review", comment).commit();
- prefs.edit().putString("pack", pack).commit();
- if (isPackageExisted(pack)) {
- Intent a = new Intent(this, RateActivity.class);
- a.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK
- | Intent.FLAG_ACTIVITY_SINGLE_TOP
- | Intent.FLAG_ACTIVITY_NEW_TASK);
- startActivity(a);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement