コード例 #1
0
ファイル: Preffrag.java プロジェクト: Nilpo/AmazeFileManager
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    PreferenceUtils.reset();
    // Load the preferences from an XML resource
    addPreferencesFromResource(R.xml.preferences);

    sharedPref = PreferenceManager.getDefaultSharedPreferences(getActivity());

    final int th1 = Integer.parseInt(sharedPref.getString("theme", "0"));
    theme = th1 == 2 ? PreferenceUtils.hourOfDay() : th1;

    findPreference("columns")
        .setOnPreferenceClickListener(
            new Preference.OnPreferenceClickListener() {
              @Override
              public boolean onPreferenceClick(Preference preference) {
                final String[] sort = getResources().getStringArray(R.array.columns);
                MaterialDialog.Builder a = new MaterialDialog.Builder(getActivity());
                if (theme == 1) a.theme(Theme.DARK);
                a.title(R.string.gridcolumnno);
                int current = Integer.parseInt(sharedPref.getString("columns", "-1"));
                current = current == -1 ? 0 : current;
                if (current != 0) current = current - 1;
                a.items(sort)
                    .itemsCallbackSingleChoice(
                        current,
                        new MaterialDialog.ListCallbackSingleChoice() {
                          @Override
                          public boolean onSelection(
                              MaterialDialog dialog, View view, int which, CharSequence text) {
                            sharedPref
                                .edit()
                                .putString("columns", "" + (which != 0 ? sort[which] : "" + -1))
                                .commit();
                            dialog.dismiss();
                            return true;
                          }
                        });
                a.build().show();
                return true;
              }
            });

    findPreference("theme")
        .setOnPreferenceClickListener(
            new Preference.OnPreferenceClickListener() {
              @Override
              public boolean onPreferenceClick(Preference preference) {
                String[] sort = getResources().getStringArray(R.array.theme);
                int current = Integer.parseInt(sharedPref.getString("theme", "0"));
                MaterialDialog.Builder a = new MaterialDialog.Builder(getActivity());
                if (theme == 1) a.theme(Theme.DARK);
                a.items(sort)
                    .itemsCallbackSingleChoice(
                        current,
                        new MaterialDialog.ListCallbackSingleChoice() {
                          @Override
                          public boolean onSelection(
                              MaterialDialog dialog, View view, int which, CharSequence text) {
                            sharedPref.edit().putString("theme", "" + which).commit();
                            dialog.dismiss();
                            restartPC(getActivity());
                            return true;
                          }
                        });
                a.title(R.string.theme);
                a.build().show();
                return true;
              }
            });
    findPreference("colors")
        .setOnPreferenceClickListener(
            new Preference.OnPreferenceClickListener() {
              @Override
              public boolean onPreferenceClick(Preference preference) {
                ((com.amaze.filemanager.activities.Preferences) getActivity()).selectItem(1);
                return true;
              }
            });

    final CheckBx rootmode = (CheckBx) findPreference("rootmode");
    rootmode.setOnPreferenceClickListener(
        new Preference.OnPreferenceClickListener() {
          @Override
          public boolean onPreferenceClick(Preference preference) {
            boolean b = sharedPref.getBoolean("rootmode", false);
            if (b) {
              if (RootTools.isAccessGiven()) {
                rootmode.setChecked(true);

              } else {
                rootmode.setChecked(false);

                Toast.makeText(
                        getActivity(),
                        getResources().getString(R.string.rootfailure),
                        Toast.LENGTH_LONG)
                    .show();
              }
            } else {
              rootmode.setChecked(false);
            }

            return false;
          }
        });

    // Feedback
    Preference preference3 = (Preference) findPreference("feedback");
    preference3.setOnPreferenceClickListener(
        new Preference.OnPreferenceClickListener() {
          @Override
          public boolean onPreferenceClick(Preference preference) {
            Intent emailIntent =
                new Intent(
                    Intent.ACTION_SENDTO, Uri.fromParts("mailto", "*****@*****.**", null));
            emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Feedback : Amaze File Manager");
            startActivity(
                Intent.createChooser(emailIntent, getResources().getString(R.string.feedback)));
            return false;
          }
        });

    // About
    Preference aboutPreference = findPreference(PREFERENCE_KEY_ABOUT);
    aboutPreference.setOnPreferenceClickListener(
        new Preference.OnPreferenceClickListener() {
          @Override
          public boolean onPreferenceClick(Preference preference) {
            startActivity(new Intent(getActivity(), AboutActivity.class));
            return false;
          }
        });

    // G+
    gplus = (CheckBx) findPreference("plus_pic");
    gplus.setOnPreferenceClickListener(
        new Preference.OnPreferenceClickListener() {
          @Override
          public boolean onPreferenceClick(Preference preference) {
            if (gplus.isChecked()) {
              boolean b = checkGplusPermission();
              if (!b) requestGplusPermission();
            }
            return false;
          }
        });
    if (BuildConfig.IS_VERSION_FDROID) gplus.setEnabled(false);

    // Colored navigation bar
  }
コード例 #2
0
ファイル: Preffrag.java プロジェクト: Nilpo/AmazeFileManager
 public void invalidateGplus() {
   boolean a = checkGplusPermission();
   if (!a) gplus.setChecked(false);
 }