Back to project page Calma.
The source code is released under:
Apache License
If you think the Android project Calma listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
/* * Copyright (C) 2013 Thomas Schmid//w w w.j a v a 2 s . co m * * 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 com.scto.android.calma.utils; import com.scto.android.calma.R; import android.content.SharedPreferences; import android.content.SharedPreferences.Editor; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; /** * Reflection utils to call {@link SharedPreferences.Editor} apply() when * possible, falling back to commit when apply isn't available. */ public final class SharedPreferencesCompat { private final static Method mApplyMethod = findApplyMethod(); /** * @return The apply() method from {@link SharedPreferences.Editor}. */ private final static Method findApplyMethod() { try { final Class<Editor> class1 = SharedPreferences.Editor.class; return class1.getMethod("apply"); } catch (final NoSuchMethodException ignored) { } return null; } /** * @param editor The {@link SharedPreferences.Editor} to use. */ public static void apply(final SharedPreferences.Editor editor) { if (mApplyMethod != null) { try { mApplyMethod.invoke(editor); return; } catch (final InvocationTargetException ignored) { } catch (final IllegalAccessException ignored) { } } editor.commit(); } }