/***************************************************************************** * Preferences.java ***************************************************************************** * Copyright © 2011-2014 VLC authors and VideoLAN * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. *****************************************************************************/ package org.videolan.vlc.util; import android.content.SharedPreferences; import android.content.SharedPreferences.Editor; import org.json.JSONArray; import org.json.JSONException; public class Preferences { public final static String TAG = "VLC/Util/Preferences"; public static float[] getFloatArray(SharedPreferences pref, String key) { float[] array = null; String s = pref.getString(key, null); if (s != null) { try { JSONArray json = new JSONArray(s); array = new float[json.length()]; for (int i = 0; i < array.length; i++) array[i] = (float) json.getDouble(i); } catch (JSONException e) { e.printStackTrace(); } } return array; } public static void putFloatArray(Editor editor, String key, float[] array) { try { JSONArray json = new JSONArray(); for (float f : array) json.put(f); editor.putString(key, json.toString()); } catch (JSONException e) { e.printStackTrace(); } } }