@Override
 protected void onPause() {
   super.onPause();
   preferences.setIsDarkLayoutEnabled(force_dark.isChecked());
   preferences.setIsForceLandscape(force_landscape.isChecked());
   preferences.setIsToolbarsHidden(hide_toolbars.isChecked());
   preferences.setIsHighQualityOn(enable_hq.isChecked());
   preferences.setIsDarkWidgetLayoutEnabled(force_dark_widget.isChecked());
   preferences.setIsSharingImage(share_image.isChecked());
   preferences.setIsSlowNetwork(mobile_network.isChecked());
   preferences.setIsReversedLandscape(reverse_landscape.isChecked());
   preferences.setShouldOpenAtLatestStrip(open_at_latest_strip.isChecked());
   preferences.setWidgetAlwaysShowLatest(widget_always_show_latest.isChecked());
   updateWidgets();
 }
 @Override
 public void onClick(View v) {
   Intent downloadPathSelector =
       new Intent(DilbertPreferencesActivity.this, FolderPickerActivity.class);
   downloadPathSelector.setData(Uri.fromFile(new File(preferences.getDownloadTarget())));
   startActivityForResult(downloadPathSelector, REQUEST_DOWNLOAD_TARGET);
 }
 protected void onActivityResult(int requestCode, int resultCode, Intent data) {
   if (requestCode != REQUEST_DOWNLOAD_TARGET) {
     super.onActivityResult(requestCode, resultCode, data);
     return;
   }
   if (resultCode != RESULT_OK) return;
   if (data != null) {
     Uri path = data.getData();
     if (path != null) {
       preferences.setDownloadTarget(new File(path.getPath()).getAbsolutePath());
     }
   }
 }
 @Override
 protected void onCreate(Bundle savedInstanceState) {
   preferences = new DilbertPreferences(this);
   if (preferences.isForceLandscape())
     setRequestedOrientation(preferences.getLandscapeOrientation());
   setTheme(preferences.isDarkLayoutEnabled() ? R.style.AppThemeDark : R.style.AppThemeLight);
   super.onCreate(savedInstanceState);
   getSupportActionBar().setDisplayHomeAsUpEnabled(true);
   setContentView(R.layout.preferences);
   setTitle(R.string.title_preferences);
   force_landscape = (CheckBox) findViewById(R.id.pref_force_landscape);
   enable_hq = (CheckBox) findViewById(R.id.pref_enable_high_quality);
   force_dark = (CheckBox) findViewById(R.id.pref_force_dark_background);
   force_dark_widget = (CheckBox) findViewById(R.id.pref_force_dark_background_widget);
   hide_toolbars = (CheckBox) findViewById(R.id.pref_hide_toolbars);
   share_image = (CheckBox) findViewById(R.id.pref_share_image);
   mobile_network = (CheckBox) findViewById(R.id.pref_mobile_network);
   download_path = (TextView) findViewById(R.id.pref_download_path);
   reverse_landscape = (CheckBox) findViewById(R.id.pref_reverse_landscape);
   open_at_latest_strip = (CheckBox) findViewById(R.id.pref_open_at_latest_strip);
   widget_always_show_latest = (CheckBox) findViewById(R.id.pref_widget_always_latest);
   TextView author = (TextView) findViewById(R.id.app_author);
   LinearLayout download_path_layout = (LinearLayout) findViewById(R.id.pref_download_path_layout);
   TextView license = (TextView) findViewById(R.id.pref_show_license);
   TextView rating = (TextView) findViewById(R.id.pref_rating);
   download_path_layout.setOnClickListener(downloadPathClickListener);
   license.setOnClickListener(licenseOnClickListener);
   rating.setOnClickListener(ratingOnClickListener);
   author.setOnClickListener(authorOnClickListener);
   force_landscape.setOnCheckedChangeListener(
       new CompoundButton.OnCheckedChangeListener() {
         @Override
         public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
           reverse_landscape.setEnabled(isChecked);
           reverse_landscape.setChecked(reverse_landscape.isChecked() && isChecked);
         }
       });
 }
 @Override
 protected void onResume() {
   super.onResume();
   force_landscape.setChecked(preferences.isForceLandscape());
   enable_hq.setChecked(preferences.isHighQualityOn());
   force_dark.setChecked(preferences.isDarkLayoutEnabled());
   force_dark_widget.setChecked(preferences.isDarkWidgetLayoutEnabled());
   hide_toolbars.setChecked(preferences.isToolbarsHidden());
   download_path.setText(preferences.getDownloadTarget());
   share_image.setChecked(preferences.isSharingImage());
   mobile_network.setChecked(preferences.isSlowNetwork());
   reverse_landscape.setVisibility(Build.VERSION.SDK_INT >= 9 ? View.VISIBLE : View.GONE);
   reverse_landscape.setEnabled(preferences.isForceLandscape());
   reverse_landscape.setChecked(
       preferences.isReversedLandscape() && preferences.isForceLandscape());
   open_at_latest_strip.setChecked(preferences.isShouldOpenAtLatestStrip());
   widget_always_show_latest.setChecked(preferences.isWidgetAlwaysShowLatest());
 }