@Override
 public void onPostResume() {
   super.onPostResume();
   setTheme();
   securityObj.updateSecuritySetting();
 }
  @Override
  protected void onPostCreate(Bundle savedInstanceState) {
    super.onPostCreate(savedInstanceState);
    setContentView(R.layout.activity_settings);
    toolbar = (Toolbar) findViewById(R.id.toolbar);
    SP = PreferenceManager.getDefaultSharedPreferences(this);

    // region TESTING
    fabMoreThemeOptions = (FloatingActionButton) findViewById(R.id.fab_more_theme_options);
    fabMoreGeneralOptions = (FloatingActionButton) findViewById(R.id.fab_more_general_options);

    fabMoreGeneralOptions.setBackgroundTintList(ColorStateList.valueOf(getSubTextColor()));
    fabMoreGeneralOptions.setImageDrawable(
        new IconicsDrawable(this)
            .icon(GoogleMaterial.Icon.gmd_keyboard_arrow_up)
            .sizeDp(16)
            .color(getCardBackgroundColor()));

    fabMoreGeneralOptions.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            LinearLayout llMoreOptions = (LinearLayout) findViewById(R.id.ll_more_options_general);
            boolean visible = llMoreOptions.getVisibility() == View.VISIBLE;
            llMoreOptions.setVisibility(visible ? View.GONE : View.VISIBLE);
            fabMoreGeneralOptions.setImageDrawable(
                new IconicsDrawable(SettingsActivity.this)
                    .icon(
                        visible
                            ? GoogleMaterial.Icon.gmd_keyboard_arrow_up
                            : GoogleMaterial.Icon.gmd_keyboard_arrow_down)
                    .sizeDp(16)
                    .color(getCardBackgroundColor()));
          }
        });

    fabMoreThemeOptions.setBackgroundTintList(ColorStateList.valueOf(getSubTextColor()));
    fabMoreThemeOptions.setImageDrawable(
        new IconicsDrawable(this)
            .icon(GoogleMaterial.Icon.gmd_keyboard_arrow_up)
            .sizeDp(16)
            .color(getCardBackgroundColor()));
    fabMoreThemeOptions.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            LinearLayout llMoreOptions = (LinearLayout) findViewById(R.id.ll_more_options_theme);
            boolean visible = llMoreOptions.getVisibility() == View.VISIBLE;
            llMoreOptions.setVisibility(visible ? View.GONE : View.VISIBLE);
            fabMoreThemeOptions.setImageDrawable(
                new IconicsDrawable(SettingsActivity.this)
                    .icon(
                        visible
                            ? GoogleMaterial.Icon.gmd_keyboard_arrow_up
                            : GoogleMaterial.Icon.gmd_keyboard_arrow_down)
                    .sizeDp(16)
                    .color(getCardBackgroundColor()));
          }
        });
    // endregion

    securityObj = new SecurityHelper(SettingsActivity.this);

    txtTT = (TextView) findViewById(R.id.theme_setting_title);
    txtGT = (TextView) findViewById(R.id.general_setting_title);
    txtPT = (TextView) findViewById(R.id.picture_setting_title);
    txtVT = (TextView) findViewById(R.id.video_setting_title);

    scr = (ScrollView) findViewById(R.id.settingAct_scrollView);

    /** * EXCLUDED ALBUMS ** */
    findViewById(R.id.ll_basic_theme)
        .setOnClickListener(
            new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                baseThemeDialog();
              }
            });

    /** * SECURITY ** */
    findViewById(R.id.ll_security)
        .setOnClickListener(
            new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                if (!securityObj.isActiveSecurity())
                  startActivity(new Intent(getApplicationContext(), SecurityActivity.class));
                else askPasswordDialog();
              }
            });

    /** * PRIMARY COLOR PIKER ** */
    findViewById(R.id.ll_primaryColor)
        .setOnClickListener(
            new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                primaryColorPiker();
              }
            });

    /** * ACCENT COLOR PIKER ** */
    findViewById(R.id.ll_accentColor)
        .setOnClickListener(
            new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                accentColorPiker();
              }
            });

    /** * EXCLUDED ALBUMS INTENT ** */
    findViewById(R.id.ll_excluded_album)
        .setOnClickListener(
            new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                startActivity(new Intent(SettingsActivity.this, ExcludedAlbumsActivity.class));
              }
            });

    /** * CUSTOMIZE PICTURE VIEWER DIALOG ** */
    findViewById(R.id.ll_custom_thirdAct)
        .setOnClickListener(
            new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                customizePictureViewer();
              }
            });

    /** * MAP PROVIDER DIALOG ** */
    findViewById(R.id.ll_map_provider)
        .setOnClickListener(
            new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                mapProviderDialog();
              }
            });

    /** * SW Internal Player ** */
    swInternalBrowser = (SwitchCompat) findViewById(R.id.set_internal_player);
    swInternalBrowser.setChecked(
        SP.getBoolean(getString(R.string.preference_internal_player), false));
    swInternalBrowser.setOnCheckedChangeListener(
        new CompoundButton.OnCheckedChangeListener() {
          @Override
          public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            SharedPreferences.Editor editor = SP.edit();
            editor.putBoolean(getString(R.string.preference_internal_player), isChecked);
            editor.apply();

            new Thread(
                    new Runnable() {
                      @Override
                      public void run() {
                        ((MyApplication) getApplicationContext()).updateAlbums();
                      }
                    })
                .start();

            updateSwitchColor(swInternalBrowser, getAccentColor());
          }
        });
    updateSwitchColor(swInternalBrowser, getAccentColor());

    /** * SW INCLUDE VIDEO ** */
    swIncludeVideo = (SwitchCompat) findViewById(R.id.set_include_video);
    swIncludeVideo.setChecked(SP.getBoolean(getString(R.string.preference_include_video), true));
    swIncludeVideo.setOnCheckedChangeListener(
        new CompoundButton.OnCheckedChangeListener() {
          @Override
          public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            SharedPreferences.Editor editor = SP.edit();
            editor.putBoolean(getString(R.string.preference_include_video), isChecked);
            editor.apply();
            updateSwitchColor(swIncludeVideo, getAccentColor());
          }
        });
    updateSwitchColor(swIncludeVideo, getAccentColor());

    /** * SW SWIPE DIRECTION ** */
    swSwipeDirection = (SwitchCompat) findViewById(R.id.Set_media_viewer_swipe_direction);
    swSwipeDirection.setChecked(
        SP.getBoolean(getString(R.string.preference_swipe_direction_inverted), false));
    swSwipeDirection.setOnCheckedChangeListener(
        new CompoundButton.OnCheckedChangeListener() {
          @Override
          public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            SharedPreferences.Editor editor = SP.edit();
            editor.putBoolean(getString(R.string.preference_swipe_direction_inverted), isChecked);
            editor.apply();
            updateSwitchColor(swSwipeDirection, getAccentColor());
          }
        });
    updateSwitchColor(swSwipeDirection, getAccentColor());

    /** * SW AUTO UPDATE MEDIA ** */
    swAutoUpdate = (SwitchCompat) findViewById(R.id.SetAutoUpdateMedia);
    swAutoUpdate.setChecked(SP.getBoolean(getString(R.string.preference_auto_update_media), false));
    swAutoUpdate.setOnCheckedChangeListener(
        new CompoundButton.OnCheckedChangeListener() {
          @Override
          public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            SharedPreferences.Editor editor = SP.edit();
            editor.putBoolean(getString(R.string.preference_auto_update_media), isChecked);
            editor.apply();
            updateSwitchColor(swAutoUpdate, getAccentColor());
          }
        });
    updateSwitchColor(swAutoUpdate, getAccentColor());

    /** * SW DELAY FULL-SIZE IMAGE ** */
    swDelayFullImage = (SwitchCompat) findViewById(R.id.set_full_resolution);
    swDelayFullImage.setChecked(
        SP.getBoolean(getString(R.string.preference_delay_full_image), true));
    swDelayFullImage.setOnCheckedChangeListener(
        new CompoundButton.OnCheckedChangeListener() {
          @Override
          public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            SharedPreferences.Editor editor = SP.edit();
            editor.putBoolean(getString(R.string.preference_delay_full_image), isChecked);
            editor.apply();
            updateSwitchColor(swDelayFullImage, getAccentColor());
          }
        });
    updateSwitchColor(swDelayFullImage, getAccentColor());

    /** * SW PICTURE ORIENTATION ** */
    swPictureOrientation = (SwitchCompat) findViewById(R.id.set_picture_orientation);
    swPictureOrientation.setChecked(
        SP.getBoolean(getString(R.string.preference_auto_rotate), false));
    swPictureOrientation.setOnCheckedChangeListener(
        new CompoundButton.OnCheckedChangeListener() {
          @Override
          public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            SharedPreferences.Editor editor = SP.edit();
            editor.putBoolean(getString(R.string.preference_auto_rotate), isChecked);
            editor.apply();
            updateSwitchColor(swPictureOrientation, getAccentColor());
          }
        });
    updateSwitchColor(swPictureOrientation, getAccentColor());

    /** * SW MAX LUMINOSITA ** */
    swMaxLuminosita = (SwitchCompat) findViewById(R.id.set_max_luminosita);
    swMaxLuminosita.setChecked(SP.getBoolean(getString(R.string.preference_max_brightness), false));
    swMaxLuminosita.setOnCheckedChangeListener(
        new CompoundButton.OnCheckedChangeListener() {
          @Override
          public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            SharedPreferences.Editor editor = SP.edit();
            editor.putBoolean(getString(R.string.preference_max_brightness), isChecked);
            editor.apply();
            updateSwitchColor(swMaxLuminosita, getAccentColor());
          }
        });
    updateSwitchColor(swMaxLuminosita, getAccentColor());

    /** * SW TRANSLUCENT STATUS BAR ** */
    swStatusBar = (SwitchCompat) findViewById(R.id.SetTraslucentStatusBar);
    swStatusBar.setChecked(isTranslucentStatusBar());
    swStatusBar.setOnCheckedChangeListener(
        new CompoundButton.OnCheckedChangeListener() {
          @Override
          public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            SharedPreferences.Editor editor = SP.edit();
            editor.putBoolean(getString(R.string.preference_translucent_status_bar), isChecked);
            editor.apply();
            updateTheme();
            setStatusBarColor();
            updateSwitchColor(swStatusBar, getAccentColor());
          }
        });
    updateSwitchColor(swStatusBar, getAccentColor());

    /** * SW COLORED NAV BAR ** */
    swNavBar = (SwitchCompat) findViewById(R.id.SetColoredNavBar);
    swNavBar.setChecked(isNavigationBarColored());
    swNavBar.setOnCheckedChangeListener(
        new CompoundButton.OnCheckedChangeListener() {
          @Override
          public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            SharedPreferences.Editor editor = SP.edit();
            editor.putBoolean(getString(R.string.preference_colored_nav_bar), isChecked);
            editor.apply();
            updateTheme();
            updateSwitchColor(swNavBar, getAccentColor());
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
              getWindow()
                  .setNavigationBarColor(
                      isNavigationBarColored()
                          ? getPrimaryColor()
                          : ContextCompat.getColor(getApplicationContext(), R.color.md_black_1000));
          }
        });
    updateSwitchColor(swNavBar, getAccentColor());
  }