Android Open Source - UTHPortal-Android-Gradle Settings Manager






From Project

Back to project page UTHPortal-Android-Gradle.

License

The source code is released under:

MIT License

If you think the Android project UTHPortal-Android-Gradle listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.uth.uthportal.buffers;
/*  w  w w  . j a  v  a  2  s  . co  m*/
import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.content.SharedPreferences;

import com.uth.uthportal.collections.Settings;
/**
 * Manages built-in settings future.
 * It includes save/load functions.
 * Loading settings for the very first time
 * will return default values.
 * @author GeorgeT
 *
 */
public class SettingsManager {
  public static Settings loadSettings(Context context){
    Settings settings = new Settings();
     SharedPreferences sp = context.getSharedPreferences("GlobalSettings",0);
     settings.courses = stringToList(sp.getString("courses", ""));
     settings.autoRefresh = sp.getBoolean("autoRefresh", true);
     settings.refreshInterval = sp.getInt("refreshInterval",30);
     settings.notify = sp.getBoolean("notify",true);
    return settings;
  }
  public static void saveSettings(Settings settings, Context context){
     SharedPreferences sp = context.getSharedPreferences("GlobalSettings",0);
     SharedPreferences.Editor editor = sp.edit();

     editor.putString("courses", listToString(settings.courses));
     editor.putBoolean("autoRefresh", settings.autoRefresh);
     editor.putInt("refreshInterval",settings.refreshInterval);
     editor.putBoolean("notify",settings.notify);
     editor.commit();
  }
  private static String listToString(List<String> list){
    String result = "";
    for(String item : list){
      result += item + ",";
    }
    return result;
  }
  private static List<String> stringToList(String string){
    if (string == null) return null;
    List<String> result = new ArrayList<String>();
        if (string.equals("")) return result;
    String[] parts  = string.split(","); 
    for(String part : parts){
      result.add(part);
    }
    return result;
  }
}




Java Source Code List

com.uth.uthportal.AboutScreen.java
com.uth.uthportal.CoursesFragment.java
com.uth.uthportal.DepartmentFragment.java
com.uth.uthportal.FoodFragment.java
com.uth.uthportal.MainScreen.java
com.uth.uthportal.SettingsScreen.java
com.uth.uthportal.adapter.AdapterManager.java
com.uth.uthportal.adapter.AdapterProvider.java
com.uth.uthportal.adapter.ExpandableListAdapter.java
com.uth.uthportal.adapter.SettingsAdapter.java
com.uth.uthportal.adapter.TabsPagerAdapter.java
com.uth.uthportal.buffers.AvailableCoursesParser.java
com.uth.uthportal.buffers.CoursesParser.java
com.uth.uthportal.buffers.FileOperation.java
com.uth.uthportal.buffers.FoodParser.java
com.uth.uthportal.buffers.GeneralAnnParser.java
com.uth.uthportal.buffers.SettingsManager.java
com.uth.uthportal.collections.AnnItem.java
com.uth.uthportal.collections.Announcements.java
com.uth.uthportal.collections.AvailableCourse.java
com.uth.uthportal.collections.CourseInfo.java
com.uth.uthportal.collections.Course.java
com.uth.uthportal.collections.DayMenu.java
com.uth.uthportal.collections.DefaultIntervals.java
com.uth.uthportal.collections.Dish.java
com.uth.uthportal.collections.Food.java
com.uth.uthportal.collections.GeneralAnnouncement.java
com.uth.uthportal.collections.Settings.java
com.uth.uthportal.network.ApiLinks.java
com.uth.uthportal.network.AppRater.java
com.uth.uthportal.network.AsyncJSONDownloader.java
com.uth.uthportal.network.JSONDownloader.java
com.uth.uthportal.service.DataSyncService.java
com.uth.uthportal.util.SystemUiHiderBase.java
com.uth.uthportal.util.SystemUiHiderHoneycomb.java
com.uth.uthportal.util.SystemUiHider.java