-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add basic formatting for movie details activity. Complete sort settings.
- Loading branch information
Showing
14 changed files
with
363 additions
and
79 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
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
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
77 changes: 77 additions & 0 deletions
77
app/src/main/java/com/example/android/popularmovies/SettingsActivity.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,77 @@ | ||
package com.example.android.popularmovies; | ||
|
||
/** | ||
* Created by boykoco on 09/22/2015. | ||
*/ | ||
|
||
import android.os.Bundle; | ||
import android.preference.ListPreference; | ||
import android.preference.Preference; | ||
import android.preference.PreferenceActivity; | ||
import android.preference.PreferenceManager; | ||
|
||
/** | ||
* Created by boykoco on 09/08/2015. | ||
*/ | ||
|
||
/** | ||
* A {@link PreferenceActivity} that presents a set of application settings. | ||
* <p> | ||
* See <a href="http://developer.android.com/design/patterns/settings.html"> | ||
* Android Design: Settings</a> for design guidelines and the <a | ||
* href="http://developer.android.com/guide/topics/ui/settings.html">Settings | ||
* API Guide</a> for more information on developing a Settings UI. | ||
*/ | ||
public class SettingsActivity extends PreferenceActivity | ||
implements Preference.OnPreferenceChangeListener { | ||
|
||
@Override | ||
public void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
// Add 'general' preferences, defined in the XML file | ||
// Yes, this function is deprecated, but it is actually the current best practice given | ||
// that we're targeting Gingerbread! | ||
addPreferencesFromResource(R.xml.pref_general); | ||
|
||
// For all preferences, attach an OnPreferenceChangeListener so the UI summary can be | ||
// updated when the preference changes. | ||
bindPreferenceSummaryToValue(findPreference(getString(R.string.pref_sort_order_key))); | ||
} | ||
|
||
/** | ||
* Attaches a listener so the summary is always updated with the preference value. | ||
* Also fires the listener once, to initialize the summary (so it shows up before the value | ||
* is changed.) | ||
*/ | ||
private void bindPreferenceSummaryToValue(Preference preference) { | ||
// Set the listener to watch for value changes. | ||
preference.setOnPreferenceChangeListener(this); | ||
|
||
// Trigger the listener immediately with the preference's | ||
// current value. | ||
onPreferenceChange(preference, | ||
PreferenceManager | ||
.getDefaultSharedPreferences(preference.getContext()) | ||
.getString(preference.getKey(), "")); | ||
} | ||
|
||
@Override | ||
public boolean onPreferenceChange(Preference preference, Object value) { | ||
String stringValue = value.toString(); | ||
|
||
if (preference instanceof ListPreference) { | ||
// For list preferences, look up the correct display value in | ||
// the preference's 'entries' list (since they have separate labels/values). | ||
ListPreference listPreference = (ListPreference) preference; | ||
int prefIndex = listPreference.findIndexOfValue(stringValue); | ||
if (prefIndex >= 0) { | ||
preference.setSummary(listPreference.getEntries()[prefIndex]); | ||
} | ||
} else { | ||
// For other preferences, set the summary to the value's simple string representation. | ||
preference.setSummary(stringValue); | ||
} | ||
return true; | ||
} | ||
|
||
} |
Oops, something went wrong.