예제 #1
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    // Setting up spinner
    spinner = (ProgressBar) findViewById(R.id.progressBar1);
    spinner.setVisibility(View.GONE);

    // Set up UI Components
    title_box = (TextView) findViewById(R.id.title);
    status_box = (TextView) findViewById(R.id.status);
    downloadsize_box = (TextView) findViewById(R.id.downloadsize);
    mp3_butt = (Button) findViewById(R.id.downmp3);

    oldColors = status_box.getTextColors(); // Save default color

    Typeface font_title = Typeface.createFromAsset(c.getAssets(), "fonts/JosefinSlab-Bold.ttf");
    title_box.setTypeface(font_title);
    status_box.setTypeface(font_title);
    downloadsize_box.setTypeface(font_title);

    // Set up ProgressDialog
    mProgressDialog = new CustomProgressDialog(MainActivity.this);
    mProgressDialog.setIndeterminate(true);
    mProgressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
    mProgressDialog.setCancelable(true);
    mProgressDialog.setProgressDrawable(
        getResources().getDrawable(R.drawable.apptheme_progress_horizontal_holo_dark));
    mProgressDialog.setIndeterminateDrawable(
        getResources()
            .getDrawable(R.drawable.apptheme_progress_indeterminate_horizontal_holo_dark));

    syncpref();

    /* Check First Time Launch */
    if (sharedPrefs.getBoolean(
        "firststart", true)) { // Check if it's the first time you run the application
      // Show a disclaimer.
      showdialog(
          0,
          getResources().getString(R.string.disclaimer_title),
          getResources().getString(R.string.disclaimer_text));
    } else {
      checkandstart();
    }
  }
  /*
   * Maps the persistent data in shared_prefs to our currently
   * available objects and also sets up the per app dialog
   */
  private void getPersistentData(
      final perAppHelper perApp, final String profileName, final TextView txtViewSummary) {

    if (mPerAppDialogVisible) return;

    mPerAppDialogVisible = true;

    final String savedSelectedProfiles = mPerAppPrefs.getString(profileName, null);
    String systemApps = mPerAppPrefs.getString("systemStatus", null);

    // Probably a "fresh" profile;
    if (systemApps == null) systemApps = "false";

    perApp.setSystemAppStatus(Boolean.valueOf(systemApps));

    if (mPackages != null) {
      // We are good to go, save time!
      perApp.setPackages(mPackages);

      // Map data if present
      if (savedSelectedProfiles != null) {
        String tmp[];
        tmp = savedSelectedProfiles.replace("+", " ").split(" ");

        // Finds the matches;
        perApp.findMatch(tmp);
      }

      showPerAppDialog(perApp, profileName, txtViewSummary);

    } else {
      if (mProgressDialog == null) {
        mProgressDialog = new ProgressDialog(mContext);
        mProgressDialog.setMessage(Util.getRandomLoadingText(mContext));
        mProgressDialog.setIndeterminate(true);
        mProgressDialog.setIndeterminateDrawable(
            getResources().getDrawable(R.drawable.spinner_animation));
      }

      mProgressDialog.show();

      // Worst case;
      Runnable runnable =
          new Runnable() {
            @Override
            public void run() {

              /*
               * While we are getting the relevant data, we show a spinner
               * and continue with our operation afterwards in the UI thread
               */
              perApp.getAllApps(perApp.getSystemAppStatus());
              mPackages = perApp.getPackages();

              // Map data if present
              if (savedSelectedProfiles != null) {
                String tmp[];
                tmp = savedSelectedProfiles.replace("+", " ").split(" ");

                // Finds the matches;
                perApp.findMatch(tmp);
              }

              getActivity()
                  .runOnUiThread(
                      new Runnable() {
                        @Override
                        public void run() {

                          mProgressDialog.dismiss();

                          showPerAppDialog(perApp, profileName, txtViewSummary);
                        }
                      });
            }
          };
      new Thread(runnable).start();
    }
  }