-
-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4d1f05e
commit 572c1db
Showing
16 changed files
with
1,117 additions
and
638 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
package it.rignanese.leo.slimfacebook.settings; | ||
|
||
import android.content.Context; | ||
import android.content.Intent; | ||
import android.content.SharedPreferences; | ||
import android.content.pm.PackageInfo; | ||
|
@@ -15,95 +16,99 @@ | |
import it.rignanese.leo.slimfacebook.R; | ||
|
||
/** | ||
SlimSocial for Facebook is an Open Source app realized by Leonardo Rignanese <[email protected]> | ||
* SlimSocial for Facebook is an Open Source app realized by Leonardo Rignanese <[email protected]> | ||
* GNU GENERAL PUBLIC LICENSE Version 2, June 1991 | ||
* GITHUB: https://github.com/rignaneseleo/SlimSocial-for-Facebook | ||
*/ | ||
public class SettingsActivity extends PreferenceActivity implements | ||
SharedPreferences.OnSharedPreferenceChangeListener { | ||
|
||
private static String appVersion; | ||
|
||
//using a PreferenceFragment along with the PreferenceActivity (see there | ||
// http://alvinalexander.com/android/android-tutorial-preferencescreen-preferenceactivity-preferencefragment ) | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
|
||
//get the appVersion | ||
try { | ||
appVersion = appVersion(); | ||
} catch (PackageManager.NameNotFoundException e) { | ||
e.printStackTrace(); | ||
} | ||
|
||
//load the fragment | ||
getFragmentManager().beginTransaction().replace(android.R.id.content, new MyPreferenceFragment()).commit(); | ||
} | ||
|
||
@Override | ||
public void onResume() { | ||
super.onResume(); | ||
// register the listener | ||
PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).registerOnSharedPreferenceChangeListener(this); | ||
} | ||
|
||
@Override | ||
public void onPause() { | ||
super.onPause(); | ||
// unregister the listener | ||
PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).unregisterOnSharedPreferenceChangeListener(this); | ||
} | ||
|
||
@Override | ||
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { | ||
switch (key) { | ||
case "pref_recentNewsFirst": | ||
case "pref_centerTextPosts": | ||
case "pref_fixedBar": | ||
case "pref_addSpaceBetweenPosts": { | ||
Toast.makeText(SettingsActivity.this, R.string.refreshToApply, Toast.LENGTH_SHORT).show(); | ||
break; | ||
} | ||
case "pref_doNotDownloadImages": | ||
case "pref_allowGeolocation": | ||
case "pref_theme": | ||
case "pref_textSize": { | ||
restart(); | ||
break; | ||
} | ||
} | ||
} | ||
private void restart() { | ||
// notify user | ||
Toast.makeText(SettingsActivity.this, R.string.applyingChanges, Toast.LENGTH_SHORT).show(); | ||
|
||
// sending intent to onNewIntent() of MainActivity that restarts the app | ||
Intent intent = new Intent(getApplicationContext(), MainActivity.class); | ||
intent.putExtra("settingsChanged", true); | ||
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); | ||
startActivity(intent); | ||
} | ||
|
||
|
||
//preference fragment | ||
public static class MyPreferenceFragment extends PreferenceFragment { | ||
@Override | ||
public void onCreate(final Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
addPreferencesFromResource(R.xml.settings);//load the layout | ||
|
||
//set the appVersion | ||
Preference version = findPreference("pref_key_version"); | ||
version.setSummary(appVersion);// set the current version | ||
} | ||
} | ||
|
||
|
||
//read the appVersion | ||
private String appVersion() throws PackageManager.NameNotFoundException { | ||
PackageInfo pInfo = getPackageManager().getPackageInfo(getPackageName(), 0); | ||
return pInfo.versionName; | ||
} | ||
} | ||
SharedPreferences.OnSharedPreferenceChangeListener { | ||
private static String appVersion; | ||
|
||
//using a PreferenceFragment along with the PreferenceActivity (see there | ||
// http://alvinalexander.com/android/android-tutorial-preferencescreen-preferenceactivity-preferencefragment ) | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
|
||
//get the appVersion | ||
try { | ||
appVersion = appVersion(); | ||
} catch (PackageManager.NameNotFoundException e) { | ||
e.printStackTrace(); | ||
} | ||
|
||
//load the fragment | ||
getFragmentManager().beginTransaction().replace(android.R.id.content, new MyPreferenceFragment()).commit(); | ||
} | ||
|
||
//read the appVersion | ||
private String appVersion() throws PackageManager.NameNotFoundException { | ||
PackageInfo pInfo = getPackageManager().getPackageInfo(getPackageName(), 0); | ||
return pInfo.versionName; | ||
} | ||
|
||
@Override | ||
public void onResume() { | ||
super.onResume(); | ||
// register the listener | ||
PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).registerOnSharedPreferenceChangeListener(this); | ||
} | ||
|
||
@Override | ||
public void onPause() { | ||
super.onPause(); | ||
// unregister the listener | ||
PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).unregisterOnSharedPreferenceChangeListener(this); | ||
} | ||
|
||
@Override | ||
public void onDestroy() { | ||
super.onDestroy(); | ||
} | ||
|
||
@Override | ||
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { | ||
switch (key) { | ||
case "pref_recentNewsFirst": | ||
case "pref_centerTextPosts": | ||
case "pref_fixedBar": | ||
case "pref_addSpaceBetweenPosts": { | ||
Toast.makeText(SettingsActivity.this, R.string.refreshToApply, Toast.LENGTH_SHORT).show(); | ||
break; | ||
} | ||
case "pref_doNotDownloadImages": | ||
case "pref_allowGeolocation": | ||
case "pref_theme": | ||
case "pref_textSize": { | ||
restart(); | ||
break; | ||
} | ||
} | ||
} | ||
|
||
private void restart() { | ||
// notify user | ||
Toast.makeText(SettingsActivity.this, R.string.applyingChanges, Toast.LENGTH_SHORT).show(); | ||
|
||
// sending intent to onNewIntent() of MainActivity that restarts the app | ||
Intent intent = new Intent(getApplicationContext(), MainActivity.class); | ||
intent.putExtra("settingsChanged", true); | ||
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); | ||
startActivity(intent); | ||
} | ||
|
||
//preference fragment | ||
public static class MyPreferenceFragment extends PreferenceFragment { | ||
@Override | ||
public void onCreate(final Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
addPreferencesFromResource(R.xml.settings);//load the layout | ||
|
||
//set the appVersion | ||
Preference version = findPreference("pref_key_version"); | ||
version.setSummary(appVersion);// set the current version | ||
} | ||
} | ||
} | ||
|
24 changes: 24 additions & 0 deletions
24
SlimFacebook/app/src/main/java/it/rignanese/leo/slimfacebook/utils/SwitchWithoutBugs.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package it.rignanese.leo.slimfacebook.utils; | ||
|
||
import android.content.Context; | ||
import android.preference.SwitchPreference; | ||
import android.util.AttributeSet; | ||
|
||
/** | ||
* SlimSocial for Facebook is an Open Source app realized by Leonardo Rignanese <[email protected]> | ||
* GNU GENERAL PUBLIC LICENSE Version 2, June 1991 | ||
* GITHUB: https://github.com/rignaneseleo/SlimSocial-for-Facebook | ||
*/ | ||
public class SwitchWithoutBugs extends SwitchPreference { | ||
public SwitchWithoutBugs(Context context) { | ||
super(context); | ||
} | ||
|
||
public SwitchWithoutBugs(Context context, AttributeSet attrs) { | ||
super(context, attrs); | ||
} | ||
|
||
public SwitchWithoutBugs(Context context, AttributeSet attrs, int defStyle) { | ||
super(context, attrs, defStyle); | ||
} | ||
} |
Oops, something went wrong.