Back to project page GuildViewerApp2.
The source code is released under:
Apache License
If you think the Android project GuildViewerApp2 listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.skywomantechnology.app.guildviewer; /*ww w .jav a2s. c o m*/ /* * Guild Viewer is an Android app that allows users to view news feeds and news feed details * on a mobile device and while not logged into the game servers. * * Copyright 2014 Sky Woman Technology LLC * * 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. */ import android.content.SharedPreferences; import android.os.Bundle; import android.preference.ListPreference; import android.preference.Preference; import android.preference.Preference.OnPreferenceChangeListener; import android.preference.PreferenceFragment; import android.preference.PreferenceManager; //import android.util.Log; import android.widget.Toast; import com.skywomantechnology.app.guildviewer.data.GuildViewerContract.GuildEntry; import com.skywomantechnology.app.guildviewer.data.GuildViewerContract.MemberEntry; import com.skywomantechnology.app.guildviewer.data.GuildViewerContract.NewsEntry; import com.skywomantechnology.app.guildviewer.sync.GuildViewerSyncAdapter; public class SettingsFragment extends PreferenceFragment implements OnPreferenceChangeListener { //public final String LOG_TAG = SettingsFragment.class.getSimpleName(); boolean mBindingPreference = false; /** * set up the display and putting the preferences in the summary * * @param savedInstanceState bundle of saved information */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.preferences); bindPreferenceSummaryToValue(findPreference(getString(R.string.pref_region_key))); bindPreferenceSummaryToValue(findPreference(getString(R.string.pref_realm_key))); bindPreferenceSummaryToValue(findPreference(getString(R.string.pref_guild_key))); bindPreferenceSummaryToValue(findPreference(getString(R.string.pref_character_key))); bindPreferenceSummaryToValue(findPreference(getString(R.string.pref_days_to_keep_key))); } /** * Put the preference in the summary * * @param preference map of preferences */ private void bindPreferenceSummaryToValue(Preference preference) { mBindingPreference = true; preference.setOnPreferenceChangeListener(this); onPreferenceChange(preference, PreferenceManager .getDefaultSharedPreferences(preference.getContext()) .getString(preference.getKey(), "")); mBindingPreference = false; } /** * process any preference changes * * @param preference preference map * @param value summary text * @return true */ @Override public boolean onPreferenceChange(Preference preference, Object value) { String stringValue = value.toString(); // don't do this if we are binding the preference if (!mBindingPreference) { if ( preference.getKey().equals(getString(R.string.pref_region_key)) || preference.getKey().equals(getString(R.string.pref_realm_key)) || preference.getKey().equals(getString(R.string.pref_guild_key))) { // reset the last notification timestamp if we are changing the guild // because the stored one is for the current guild and not the new guild // since its a new guild we have to reset the date for the last sync SharedPreferences.Editor editor = PreferenceManager.getDefaultSharedPreferences(preference.getContext()).edit(); editor.putLong(getActivity().getString(R.string.pref_last_notification),0L); editor.apply(); // clear out the last sync time for the guild member updates Utility.setPreferenceForLastGuildMemberUpdate(preference.getContext(), 0L); // since we change the guild we need to delete all of the old news from the // previous guild and start over getActivity().getContentResolver().delete(NewsEntry.CONTENT_URI, null, null); getActivity().getContentResolver().delete(GuildEntry.CONTENT_URI, null, null); getActivity().getContentResolver().delete(MemberEntry.CONTENT_URI, null, null); // If the guild is very active this can take a long long time!! // so I put up a warning? Is there a better way to design this. Toast.makeText(getActivity(), getString(R.string.toast_retrieving_data_message), Toast.LENGTH_LONG).show(); // only sync a minimum number of records for initial list // then load the rest of the list right after ... puts something in the list // to keep it from looking empty when there is a lot of news items GuildViewerSyncAdapter.syncImmediately(getActivity()); } else if (preference.getKey().equals(getString(R.string.pref_days_to_keep_key))) { GuildViewerSyncAdapter.syncImmediately(getActivity()); } else { getActivity().getContentResolver().notifyChange(NewsEntry.CONTENT_URI, null); } } if (preference instanceof ListPreference) { ListPreference listPreference = (ListPreference) preference; int prefIndex = listPreference.findIndexOfValue(stringValue); if (prefIndex >= 0) { preference.setSummary(listPreference.getEntries()[prefIndex]); } } else { preference.setSummary(stringValue); } return true; } }