Skip to content
This repository has been archived by the owner on Mar 19, 2020. It is now read-only.

Commit

Permalink
Closed #29
Browse files Browse the repository at this point in the history
  • Loading branch information
rock3r committed Jul 11, 2013
1 parent cdcebd0 commit ea63713
Show file tree
Hide file tree
Showing 8 changed files with 246 additions and 117 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
Changelog
=========

### Version 1.1.4 ###
Released on 11th July 2013

- FIX: crash on the Settings Activity on xlarge screens (multicolumn layout)

### Version 1.1.3 ###
Released on 11th July 2013

Expand Down
14 changes: 8 additions & 6 deletions res/xml/pref_headers.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,19 @@

<!-- These settings headers are only used on tablets. -->
<header
android:fragment="net.frakbot.FWeather.activity.SettingsActivity$CustomizationPreferenceFragment"
android:fragment="net.frakbot.FWeather.fragments.CustomizationPreferencesFragment"
android:title="@string/pref_header_customization"/>

<header
android:fragment="net.frakbot.FWeather.activity.SettingsActivity$DataSyncPreferenceFragment"
android:fragment="net.frakbot.FWeather.fragments.DataSyncPreferencesFragment"
android:title="@string/pref_header_data_sync"/>

<header
android:fragment="net.frakbot.FWeather.activity.SettingsActivity$InformationPreferenceFragment"
android:title="@string/pref_header_info"/>
<header
android:fragment="net.frakbot.FWeather.activity.SettingsActivity$AdvancedPreferenceFragment"
android:fragment="net.frakbot.FWeather.fragments.AdvancedPreferencesFragment"
android:title="@string/pref_header_advanced"/>

<header
android:fragment="net.frakbot.FWeather.fragments.InformationPreferencesFragment"
android:title="@string/pref_header_info"/>

</preference-headers>
123 changes: 12 additions & 111 deletions src/net/frakbot/FWeather/activity/SettingsActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

package net.frakbot.FWeather.activity;

import android.annotation.SuppressLint;
import android.annotation.TargetApi;
import android.app.AlertDialog;
import android.app.ApplicationErrorReport;
Expand All @@ -39,9 +38,9 @@
import com.actionbarsherlock.app.SherlockPreferenceActivity;
import net.frakbot.FWeather.R;
import net.frakbot.FWeather.global.Const;
import net.frakbot.FWeather.util.WidgetHelper;
import net.frakbot.FWeather.util.FLog;
import net.frakbot.FWeather.util.TrackerHelper;
import net.frakbot.FWeather.util.WidgetHelper;
import org.jraf.android.backport.switchwidget.SwitchPreference;

import java.util.List;
Expand Down Expand Up @@ -137,8 +136,8 @@ protected void onPause() {
super.onPause();

// Unregister the SharedPreferences listener (me, duh)
getPreferenceManager().getSharedPreferences()
.unregisterOnSharedPreferenceChangeListener(this);
PreferenceManager.getDefaultSharedPreferences(this)
.unregisterOnSharedPreferenceChangeListener(this);
}

@Override
Expand All @@ -157,9 +156,8 @@ protected void onResume() {
super.onResume();

// Register a SharedPreferences listener (me, duh)
getPreferenceManager()
.getSharedPreferences()
.registerOnSharedPreferenceChangeListener(this);
PreferenceManager.getDefaultSharedPreferences(this)
.registerOnSharedPreferenceChangeListener(this);
}

/**
Expand Down Expand Up @@ -270,7 +268,7 @@ private void requestWidgetsUpdate(boolean forced, boolean silent) {
*
* @param preference The feedback preference
*/
private void setupFeedbackOnClickListener(Preference preference) {
public void setupFeedbackOnClickListener(Preference preference) {
preference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {

@Override
Expand Down Expand Up @@ -355,12 +353,12 @@ private boolean isInstalledFromPlayStore() {
* @param newValue The new value
*/
private void handlePreferenceChange(Preference preference, Object newValue) {
Long value = Long.valueOf(0);
Long value = (long) 0;
if (preference.getKey().equals(Const.Preferences.ANALYTICS)) {
if (newValue == Boolean.FALSE)
value = Long.valueOf(0);
value = (long) 0;
else
value = Long.valueOf(1);
value = (long) 1;
} else if (preference.getKey().equals(Const.Preferences.SYNC_FREQUENCY)) {
value = Long.valueOf((String)newValue);
}
Expand Down Expand Up @@ -412,7 +410,7 @@ public boolean onPreferenceChange(Preference preference, Object value) {
*
* @param preference The Changelog preference.
*/
private void setupChangelogOnClickListener(Preference preference) {
public void setupChangelogOnClickListener(Preference preference) {
preference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
Expand All @@ -439,7 +437,7 @@ public void onClick(DialogInterface dialog, int which) {
*
* @param preference The Analytics preference.
*/
private void setupAnalyticsOnChangeListener(SwitchPreference preference) {
public void setupAnalyticsOnChangeListener(SwitchPreference preference) {
preference.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(final Preference preference, Object newValue) {
Expand Down Expand Up @@ -527,7 +525,7 @@ public void onBuildHeaders(List<PreferenceActivity.Header> target) {
*
* @see #sBindPreferenceSummaryToValueListener
*/
private void bindPreferenceSummaryToValue(Preference preference) {
public void bindPreferenceSummaryToValue(Preference preference) {
// Set the listener to watch for value changes.
preference
.setOnPreferenceChangeListener(sBindPreferenceSummaryToValueListener);
Expand All @@ -540,72 +538,6 @@ private void bindPreferenceSummaryToValue(Preference preference) {
preference.getContext()).getString(preference.getKey(), ""));
}

/**
* This fragment shows data and sync preferences only. It is used when the
* activity is showing a two-pane settings UI.
*/
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public static class DataSyncPreferenceFragment extends BackupPreferenceFragment {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.pref_data_sync);

// Bind the summaries of EditText/List/Dialog/Ringtone preferences
// to their values. When their values change, their summaries are
// updated to reflect the new value, per the Android Design
// guidelines.
((SettingsActivity) getActivity()).bindPreferenceSummaryToValue(
findPreference(getString(R.string.pref_key_sync_frequency)));
}
}

/**
* This fragment shows customization preferences only. It is used when the
* activity is showing a two-pane settings UI.
*/
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public class CustomizationPreferenceFragment extends BackupPreferenceFragment {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.pref_customization);
}
}

/**
* This fragment shows advanced settings only. It is used when the activity
* is showing a two-pane settings UI.
*/
@SuppressLint("ValidFragment")
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public class AdvancedPreferenceFragment extends BackupPreferenceFragment {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.pref_advanced);

setupAnalyticsOnChangeListener((SwitchPreference) findPreference(getString(R.string.pref_key_analytics)));
}
}

/**
* This fragment shows information only. It is used when the
* activity is showing a two-pane settings UI.
*/
@SuppressLint("ValidFragment")
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public class InformationPreferenceFragment extends BackupPreferenceFragment {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.pref_info);

setupFeedbackOnClickListener(findPreference(getString(R.string.pref_key_feedback)));
setupChangelogOnClickListener(findPreference(getString(R.string.pref_key_changelog)));
}
}

/**
* Broadcasts an action that causes the update of the updater alarm.
* If the preference changes, the update rate of the application data
Expand All @@ -616,35 +548,4 @@ private void sendSyncPreferenceChangedBroadcast() {
sendBroadcast(i);
}

/**
* PreferenceFragment extension that takes care of registering/unregistering against
* SharedPreferences changes and notifying any changes to the underlying BackupManager.
*
* @author Francesco Pontillo
*/
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public static class BackupPreferenceFragment extends PreferenceFragment implements
OnSharedPreferenceChangeListener {

@Override
public void onResume() {
super.onResume();
getPreferenceManager().getSharedPreferences()
.registerOnSharedPreferenceChangeListener(this);
}

@Override
public void onPause() {
super.onPause();
getPreferenceManager().getSharedPreferences()
.unregisterOnSharedPreferenceChangeListener(this);
}

@Override
public void onSharedPreferenceChanged(
SharedPreferences sharedPreferences, String s) {
new BackupManager(getActivity()).dataChanged();
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Copyright 2013 Sebastiano Poggi and Francesco Pontillo
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package net.frakbot.FWeather.fragments;

import android.annotation.SuppressLint;
import android.annotation.TargetApi;
import android.os.Build;
import android.os.Bundle;
import net.frakbot.FWeather.R;
import net.frakbot.FWeather.activity.SettingsActivity;
import org.jraf.android.backport.switchwidget.SwitchPreference;

/**
* This fragment shows advanced settings only. It is used when the activity
* is showing a two-pane settings UI.
*/
@SuppressLint("ValidFragment")
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public class AdvancedPreferencesFragment extends BackupPreferenceFragment {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.pref_advanced);

if (getActivity() instanceof SettingsActivity) {
((SettingsActivity)getActivity()).setupAnalyticsOnChangeListener(
(SwitchPreference) findPreference(getString(R.string.pref_key_analytics)));
}
}
}
54 changes: 54 additions & 0 deletions src/net/frakbot/FWeather/fragments/BackupPreferenceFragment.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* Copyright 2013 Sebastiano Poggi and Francesco Pontillo
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package net.frakbot.FWeather.fragments;

import android.annotation.TargetApi;
import android.app.backup.BackupManager;
import android.content.SharedPreferences;
import android.os.Build;
import android.preference.PreferenceFragment;

/**
* PreferenceFragment extension that takes care of registering/unregistering against
* SharedPreferences changes and notifying any changes to the underlying BackupManager.
*
* @author Francesco Pontillo
*/
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public class BackupPreferenceFragment extends PreferenceFragment implements
SharedPreferences.OnSharedPreferenceChangeListener {

@Override
public void onResume() {
super.onResume();
getPreferenceManager().getSharedPreferences()
.registerOnSharedPreferenceChangeListener(this);
}

@Override
public void onPause() {
super.onPause();
getPreferenceManager().getSharedPreferences()
.unregisterOnSharedPreferenceChangeListener(this);
}

@Override
public void onSharedPreferenceChanged(
SharedPreferences sharedPreferences, String s) {
new BackupManager(getActivity()).dataChanged();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Copyright 2013 Sebastiano Poggi and Francesco Pontillo
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package net.frakbot.FWeather.fragments;

import android.annotation.TargetApi;
import android.os.Build;
import android.os.Bundle;
import net.frakbot.FWeather.R;

/**
* This fragment shows customization preferences only. It is used when the
* activity is showing a two-pane settings UI.
*/
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public class CustomizationPreferencesFragment extends BackupPreferenceFragment {

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.pref_customization);
}
}
Loading

0 comments on commit ea63713

Please sign in to comment.