Back to project page n4lwp.
The source code is released under:
Copyright (c) 2012, Patrick O'Leary All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:...
If you think the Android project n4lwp 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) 2012, Patrick O'Leary/*from w w w . j ava2 s.c o m*/ All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package com.greentaperacing.olearyp.n4lwp; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.List; import android.annotation.TargetApi; import android.content.Context; import android.os.Bundle; import android.preference.Preference; import android.preference.Preference.OnPreferenceChangeListener; import android.preference.PreferenceActivity; import android.preference.PreferenceFragment; public class N4WallpaperSettings extends PreferenceActivity implements OnPreferenceChangeListener { // Following technique from http://www.blackmoonit.com/2012/07/all_api_prefsactivity/ protected Method mLoadHeaders = null; protected Method mHasHeaders = null; /** * Checks to see if using new v11+ way of handling PrefsFragments. * @return Returns false pre-v11, else checks to see if using headers. */ public boolean isNewV11Prefs() { if (mHasHeaders!=null && mLoadHeaders!=null) { try { return (Boolean)mHasHeaders.invoke(this); } catch (IllegalArgumentException e) { } catch (IllegalAccessException e) { } catch (InvocationTargetException e) { } } return false; } @SuppressWarnings("deprecation") @Override public void onCreate(Bundle aSavedState) { //onBuildHeaders() will be called during super.onCreate() try { mLoadHeaders = getClass().getMethod("loadHeadersFromResource", int.class, List.class ); mHasHeaders = getClass().getMethod("hasHeaders"); } catch (NoSuchMethodException e) { } super.onCreate(aSavedState); if (!isNewV11Prefs()) { addPreferencesFromResource(R.xml.prefs); } } /* This method is hidden for now so we only get one screen @Override public void onBuildHeaders(List<Header> aTarget) { try { mLoadHeaders.invoke(this,new Object[]{R.xml.pref_headers, aTarget}); } catch (IllegalArgumentException e) { } catch (IllegalAccessException e) { } catch (InvocationTargetException e) { } } */ @TargetApi(11) static public class PrefsFragment extends PreferenceFragment { @Override public void onCreate(Bundle aSavedState) { super.onCreate(aSavedState); Context anAct = getActivity().getApplicationContext(); int thePrefRes = anAct.getResources().getIdentifier(getArguments().getString("pref-resource"), "xml",anAct.getPackageName()); addPreferencesFromResource(thePrefRes); } } @Override public boolean onPreferenceChange(Preference arg0, Object arg1) { // TODO Auto-generated method stub return true; } }