A backport of the SwitchPreference component that was introduced on Android 4 (ICS / level 14). This port works on Android 2.1+ (Eclair MR1 / level 7).

Overview

Android Switch Preference Backport

A backport of the SwitchPreference component that was introduced on Android 4 (ICS / level 14).

This port works on Android 2.1+ (Eclair MR1 / level 7).

The current version of this library is 2.0.1.

IMPORTANT: THIS LIBRARY IS NOW DEPRECATED

Since the AppCompat library now includes a Switch widget backport (SwitchCompat), and a SwitchPreference widget backport (SwitchPreferenceCompat), this library is no longer useful.

I was glad to work on this library and to see that it has been used in many projects.

How to use

Adding the library to your project

Option 1: Gradle

The aar artifact is available at the jcenter repository. Declare the repository and the dependency in your build.gradle file:

repositories {
    jcenter()
}

 (...)

dependencies {
    compile 'org.jraf:android-switch-backport:2.0.1'
}

Option 2: Android library project (ant / Eclipse)

This is an Android library project, you have to add it as a dependency to your project (please see this page to know how to do that.)

Using the SwitchPreference

Once you have done that, have a theme for your application (or Activity), that declares the asb_switchPreferenceStyle item to be the value @style/asb_Preference.SwitchPreference.

The simplest way to do that is to create a themes.xml file in your project's res/values folder with this contents:

<?xml version="1.0" encoding="utf-8"?>
<resources>

    <style name="Theme.App" parent="Theme.AppCompat">
        <item name="asb_switchPreferenceStyle">@style/asb_Preference.SwitchPreference</item>
    </style>

</resources>

And use it in your Application or Activity by updating your AndroidManifest.xml file:

(...)
<application
    android:theme="@style/Theme.App"
(...)

or

(...)
<activity
    android:theme="@style/Theme.App"
(...)

Then in your preferences xml file:

<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto" >

    <org.jraf.android.backport.switchwidget.SwitchPreference
        android:key="testKey"
        android:title="SwitchPreference Test"
        app:asb_summaryOff="@string/summary_off"
        app:asb_summaryOn="@string/summary_on" />

</PreferenceScreen>

Sample app

A sample app is available in the sample folder, and also on the Play Store: Get it on Google Play

Credits

The code was copied directly from the Android 5.0 (Lollipop / level 21) source code, then slightly tweaked by myself ([email protected]) to make it run on 2.1+ (Eclair MR1 / level 7). The v1 SwitchPreference was added by Intrications (intrications.com / github.com/intrications), also by taking code from Android and tweaking it a bit. Other people also have contributed tweaks and fixes, please see this page for a detailed list: https://github.com/BoD/android-switch-backport/graphs/contributors.

Contributing

Pull requests are welcome, as long as they are consistent to the original SwitchPreference of the Android sdk.

Please do not contribute improvements that are not present in the original sdk classes! I believe it would be confusing for this backport to have a feature set different than the original sdk classes. It would also lead to difficult situations if/when stopping using this backport and using the sdk classes instead (which should happen when dropping support for old platforms). Thank you very much.

Licence

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.

Comments
  • Attribute has already been defined exception when using lib with compile ('com.doomonafireball.betterpickers:library:1.5.2')

    Attribute has already been defined exception when using lib with compile ('com.doomonafireball.betterpickers:library:1.5.2')

    There is conflict in my project when I try to use this library with compile betterpickers library. Gradle report following error:

    Error:Attribute "switchStyle" has already been defined Error:Attribute "switchPreferenceStyle" has already been defined

    opened by depodefi 14
  • NPE on Android 2.3.3

    NPE on Android 2.3.3

    Device: LG Optimus Android version 2.3.3

    I'm inflating the xml in a customView of my actionbar. It works on 4.0 but not on 2.3.3

    Java code: View mActionBarView = getLayoutInflater().inflate(R.layout.custom_switch, null); mActionBarView.findViewById(R.id.switch_server); getSupportActionBar().setCustomView(mActionBarView); getSupportActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM | ActionBar.DISPLAY_SHOW_HOME|ActionBar.DISPLAY_USE_LOGO|ActionBar.DISPLAY_SHOW_TITLE);

    xml:

    <org.jraf.android.backport.switchwidget.Switch
        android:id="@+id/switch_server"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        />
    
    Stack trace: java.lang.NullPointerException at android.text.Layout.getDesiredWidth(Layout.java:67) at org.jraf.android.backport.switchwidget.Switch.makeLayout(Switch.java:378) at org.jraf.android.backport.switchwidget.Switch.onMeasure(Switch.java:306) at android.view.View.measure(View.java:8313) at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:581) at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:365) at android.view.View.measure(View.java:8313) at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3138) at android.widget.FrameLayout.onMeasure(FrameLayout.java:250) at android.view.View.measure(View.java:8313) at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3138) at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1017) at android.widget.LinearLayout.measureVertical(LinearLayout.java:386) at android.widget.LinearLayout.onMeasure(LinearLayout.java:309) at android.view.View.measure(View.java:8313) at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3138)
    opened by Hemanshu 11
  • NullPointerException

    NullPointerException

    java.lang.NullPointerException at android.text.Layout.getDesiredWidth(Layout.java:67) at org.jraf.android.backport.switchwidget.Switch.makeLayout(Switch.java:350) at org.jraf.android.backport.switchwidget.Switch.onMeasure(Switch.java:302) at android.view.View.measure(View.java:16497) at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:719) at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:455) at android.view.View.measure(View.java:16497) at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:719) at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:455) at android.view.View.measure(View.java:16497) at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125) at android.widget.FrameLayout.onMeasure(FrameLayout.java:310) at android.view.View.measure(View.java:16497) at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125) at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1404) at android.widget.LinearLayout.measureVertical(LinearLayout.java:695) at android.widget.LinearLayout.onMeasure(LinearLayout.java:588) at android.view.View.measure(View.java:16497) at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125) at android.widget.FrameLayout.onMeasure(FrameLayout.java:310) at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2291) at android.view.View.measure(View.java:16497) at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:1912) at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1109) at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1291) at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:996) at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5600) at android.view.Choreographer$CallbackRecord.run(Choreographer.java:761) at android.view.Choreographer.doCallbacks(Choreographer.java:574) at android.view.Choreographer.doFrame(Choreographer.java:544) at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:747) at android.os.Handler.handleCallback(Handler.java:733) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:136) at android.app.ActivityThread.main(ActivityThread.java:5001) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:515) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601) at dalvik.system.NativeStart.main(Native Method)

    opened by ericshao 8
  • Modified gradle build so it pushes an 'aar' file to Maven instead of an ...

    Modified gradle build so it pushes an 'aar' file to Maven instead of an ...

    If you could please push a signed AAR repository to MavenCentral I would be much obliged.

    Added maven_push.gradle, a script from Chris Banes (https://github.com/chrisbanes) for pushing to Sonatype repository. Modified so it pushes to file://localhost/local-repo instead.

    Modified gradle build so it pushes an 'aar' file to Maven instead of an 'apklib'.

    Needed to support to aar because gradle build has problems with duplicate AndroidManifest.xml in apklibs for some reason.

    opened by jclyons 8
  • Android 4.1.2 can not run?

    Android 4.1.2 can not run?

    11-20 14:19:04.128: E/AndroidRuntime(10332): FATAL EXCEPTION: main
    11-20 14:19:04.128: E/AndroidRuntime(10332): java.lang.NullPointerException
    11-20 14:19:04.128: E/AndroidRuntime(10332):    at android.text.Layout.getDesiredWidth(Layout.java:67)
    11-20 14:19:04.128: E/AndroidRuntime(10332):    at org.jraf.android.backport.switchwidget.Switch.makeLayout(Switch.java:378)
    11-20 14:19:04.128: E/AndroidRuntime(10332):    at org.jraf.android.backport.switchwidget.Switch.onMeasure(Switch.java:306)
    11-20 14:19:04.128: E/AndroidRuntime(10332):    at android.view.View.measure(View.java:15172)
    11-20 14:19:04.128: E/AndroidRuntime(10332):    at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:617)
    11-20 14:19:04.128: E/AndroidRuntime(10332):    at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:399)
    11-20 14:19:04.128: E/AndroidRuntime(10332):    at android.view.View.measure(View.java:15172)
    11-20 14:19:04.128: E/AndroidRuntime(10332):    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4816)
    11-20 14:19:04.128: E/AndroidRuntime(10332):    at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
    11-20 14:19:04.128: E/AndroidRuntime(10332):    at android.view.View.measure(View.java:15172)
    11-20 14:19:04.128: E/AndroidRuntime(10332):    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4816)
    11-20 14:19:04.128: E/AndroidRuntime(10332):    at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1390)
    11-20 14:19:04.128: E/AndroidRuntime(10332):    at android.widget.LinearLayout.measureVertical(LinearLayout.java:681)
    11-20 14:19:04.128: E/AndroidRuntime(10332):    at android.widget.LinearLayout.onMeasure(LinearLayout.java:574)
    11-20 14:19:04.128: E/AndroidRuntime(10332):    at android.view.View.measure(View.java:15172)
    11-20 14:19:04.128: E/AndroidRuntime(10332):    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4816)
    11-20 14:19:04.128: E/AndroidRuntime(10332):    at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
    11-20 14:19:04.128: E/AndroidRuntime(10332):    at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2148)
    11-20 14:19:04.128: E/AndroidRuntime(10332):    at android.view.View.measure(View.java:15172)
    11-20 14:19:04.128: E/AndroidRuntime(10332):    at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:1850)
    11-20 14:19:04.128: E/AndroidRuntime(10332):    at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1102)
    11-20 14:19:04.128: E/AndroidRuntime(10332):    at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1275)
    11-20 14:19:04.128: E/AndroidRuntime(10332):    at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1000)
    11-20 14:19:04.128: E/AndroidRuntime(10332):    at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4214)
    11-20 14:19:04.128: E/AndroidRuntime(10332):    at android.view.Choreographer$CallbackRecord.run(Choreographer.java:725)
    11-20 14:19:04.128: E/AndroidRuntime(10332):    at android.view.Choreographer.doCallbacks(Choreographer.java:555)
    11-20 14:19:04.128: E/AndroidRuntime(10332):    at android.view.Choreographer.doFrame(Choreographer.java:525)
    11-20 14:19:04.128: E/AndroidRuntime(10332):    at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:711)
    11-20 14:19:04.128: E/AndroidRuntime(10332):    at android.os.Handler.handleCallback(Handler.java:615)
    11-20 14:19:04.128: E/AndroidRuntime(10332):    at android.os.Handler.dispatchMessage(Handler.java:92)
    11-20 14:19:04.128: E/AndroidRuntime(10332):    at android.os.Looper.loop(Looper.java:137)
    11-20 14:19:04.128: E/AndroidRuntime(10332):    at android.app.ActivityThread.main(ActivityThread.java:4745)
    11-20 14:19:04.128: E/AndroidRuntime(10332):    at java.lang.reflect.Method.invokeNative(Native Method)
    11-20 14:19:04.128: E/AndroidRuntime(10332):    at java.lang.reflect.Method.invoke(Method.java:511)
    11-20 14:19:04.128: E/AndroidRuntime(10332):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
    11-20 14:19:04.128: E/AndroidRuntime(10332):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
    11-20 14:19:04.128: E/AndroidRuntime(10332):    at dalvik.system.NativeStart.main(Native Method)
    11-20 14:22:38.050: E/AndroidRuntime(12344): FATAL EXCEPTION: main
    11-20 14:22:38.050: E/AndroidRuntime(12344): java.lang.NullPointerException
    11-20 14:22:38.050: E/AndroidRuntime(12344):    at android.text.Layout.getDesiredWidth(Layout.java:67)
    11-20 14:22:38.050: E/AndroidRuntime(12344):    at org.jraf.android.backport.switchwidget.Switch.makeLayout(Switch.java:378)
    11-20 14:22:38.050: E/AndroidRuntime(12344):    at org.jraf.android.backport.switchwidget.Switch.onMeasure(Switch.java:306)
    11-20 14:22:38.050: E/AndroidRuntime(12344):    at android.view.View.measure(View.java:15172)
    11-20 14:22:38.050: E/AndroidRuntime(12344):    at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:617)
    11-20 14:22:38.050: E/AndroidRuntime(12344):    at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:399)
    11-20 14:22:38.050: E/AndroidRuntime(12344):    at android.view.View.measure(View.java:15172)
    11-20 14:22:38.050: E/AndroidRuntime(12344):    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4816)
    11-20 14:22:38.050: E/AndroidRuntime(12344):    at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
    11-20 14:22:38.050: E/AndroidRuntime(12344):    at android.view.View.measure(View.java:15172)
    11-20 14:22:38.050: E/AndroidRuntime(12344):    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4816)
    11-20 14:22:38.050: E/AndroidRuntime(12344):    at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1390)
    11-20 14:22:38.050: E/AndroidRuntime(12344):    at android.widget.LinearLayout.measureVertical(LinearLayout.java:681)
    11-20 14:22:38.050: E/AndroidRuntime(12344):    at android.widget.LinearLayout.onMeasure(LinearLayout.java:574)
    11-20 14:22:38.050: E/AndroidRuntime(12344):    at android.view.View.measure(View.java:15172)
    11-20 14:22:38.050: E/AndroidRuntime(12344):    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4816)
    11-20 14:22:38.050: E/AndroidRuntime(12344):    at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
    11-20 14:22:38.050: E/AndroidRuntime(12344):    at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2148)
    11-20 14:22:38.050: E/AndroidRuntime(12344):    at android.view.View.measure(View.java:15172)
    11-20 14:22:38.050: E/AndroidRuntime(12344):    at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:1850)
    11-20 14:22:38.050: E/AndroidRuntime(12344):    at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1102)
    11-20 14:22:38.050: E/AndroidRuntime(12344):    at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1275)
    11-20 14:22:38.050: E/AndroidRuntime(12344):    at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1000)
    11-20 14:22:38.050: E/AndroidRuntime(12344):    at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4214)
    11-20 14:22:38.050: E/AndroidRuntime(12344):    at android.view.Choreographer$CallbackRecord.run(Choreographer.java:725)
    11-20 14:22:38.050: E/AndroidRuntime(12344):    at android.view.Choreographer.doCallbacks(Choreographer.java:555)
    11-20 14:22:38.050: E/AndroidRuntime(12344):    at android.view.Choreographer.doFrame(Choreographer.java:525)
    11-20 14:22:38.050: E/AndroidRuntime(12344):    at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:711)
    11-20 14:22:38.050: E/AndroidRuntime(12344):    at android.os.Handler.handleCallback(Handler.java:615)
    11-20 14:22:38.050: E/AndroidRuntime(12344):    at android.os.Handler.dispatchMessage(Handler.java:92)
    11-20 14:22:38.050: E/AndroidRuntime(12344):    at android.os.Looper.loop(Looper.java:137)
    11-20 14:22:38.050: E/AndroidRuntime(12344):    at android.app.ActivityThread.main(ActivityThread.java:4745)
    11-20 14:22:38.050: E/AndroidRuntime(12344):    at java.lang.reflect.Method.invokeNative(Native Method)
    11-20 14:22:38.050: E/AndroidRuntime(12344):    at java.lang.reflect.Method.invoke(Method.java:511)
    11-20 14:22:38.050: E/AndroidRuntime(12344):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
    11-20 14:22:38.050: E/AndroidRuntime(12344):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
    11-20 14:22:38.050: E/AndroidRuntime(12344):    at dalvik.system.NativeStart.main(Native Method)
    11-20 14:24:08.136: E/AndroidRuntime(12973): FATAL EXCEPTION: main
    11-20 14:24:08.136: E/AndroidRuntime(12973): java.lang.NullPointerException
    11-20 14:24:08.136: E/AndroidRuntime(12973):    at android.text.Layout.getDesiredWidth(Layout.java:67)
    11-20 14:24:08.136: E/AndroidRuntime(12973):    at org.jraf.android.backport.switchwidget.Switch.makeLayout(Switch.java:378)
    11-20 14:24:08.136: E/AndroidRuntime(12973):    at org.jraf.android.backport.switchwidget.Switch.onMeasure(Switch.java:306)
    11-20 14:24:08.136: E/AndroidRuntime(12973):    at android.view.View.measure(View.java:15172)
    11-20 14:24:08.136: E/AndroidRuntime(12973):    at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:617)
    11-20 14:24:08.136: E/AndroidRuntime(12973):    at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:399)
    11-20 14:24:08.136: E/AndroidRuntime(12973):    at android.view.View.measure(View.java:15172)
    11-20 14:24:08.136: E/AndroidRuntime(12973):    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4816)
    11-20 14:24:08.136: E/AndroidRuntime(12973):    at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
    11-20 14:24:08.136: E/AndroidRuntime(12973):    at android.view.View.measure(View.java:15172)
    11-20 14:24:08.136: E/AndroidRuntime(12973):    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4816)
    11-20 14:24:08.136: E/AndroidRuntime(12973):    at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1390)
    11-20 14:24:08.136: E/AndroidRuntime(12973):    at android.widget.LinearLayout.measureVertical(LinearLayout.java:681)
    11-20 14:24:08.136: E/AndroidRuntime(12973):    at android.widget.LinearLayout.onMeasure(LinearLayout.java:574)
    11-20 14:24:08.136: E/AndroidRuntime(12973):    at android.view.View.measure(View.java:15172)
    11-20 14:24:08.136: E/AndroidRuntime(12973):    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4816)
    11-20 14:24:08.136: E/AndroidRuntime(12973):    at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
    11-20 14:24:08.136: E/AndroidRuntime(12973):    at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2148)
    11-20 14:24:08.136: E/AndroidRuntime(12973):    at android.view.View.measure(View.java:15172)
    11-20 14:24:08.136: E/AndroidRuntime(12973):    at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:1850)
    11-20 14:24:08.136: E/AndroidRuntime(12973):    at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1102)
    11-20 14:24:08.136: E/AndroidRuntime(12973):    at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1275)
    11-20 14:24:08.136: E/AndroidRuntime(12973):    at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1000)
    11-20 14:24:08.136: E/AndroidRuntime(12973):    at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4214)
    11-20 14:24:08.136: E/AndroidRuntime(12973):    at android.view.Choreographer$CallbackRecord.run(Choreographer.java:725)
    11-20 14:24:08.136: E/AndroidRuntime(12973):    at android.view.Choreographer.doCallbacks(Choreographer.java:555)
    11-20 14:24:08.136: E/AndroidRuntime(12973):    at android.view.Choreographer.doFrame(Choreographer.java:525)
    11-20 14:24:08.136: E/AndroidRuntime(12973):    at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:711)
    11-20 14:24:08.136: E/AndroidRuntime(12973):    at android.os.Handler.handleCallback(Handler.java:615)
    11-20 14:24:08.136: E/AndroidRuntime(12973):    at android.os.Handler.dispatchMessage(Handler.java:92)
    11-20 14:24:08.136: E/AndroidRuntime(12973):    at android.os.Looper.loop(Looper.java:137)
    11-20 14:24:08.136: E/AndroidRuntime(12973):    at android.app.ActivityThread.main(ActivityThread.java:4745)
    11-20 14:24:08.136: E/AndroidRuntime(12973):    at java.lang.reflect.Method.invokeNative(Native Method)
    11-20 14:24:08.136: E/AndroidRuntime(12973):    at java.lang.reflect.Method.invoke(Method.java:511)
    11-20 14:24:08.136: E/AndroidRuntime(12973):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
    11-20 14:24:08.136: E/AndroidRuntime(12973):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
    11-20 14:24:08.136: E/AndroidRuntime(12973):    at dalvik.system.NativeStart.main(Native Method)
    
    
    opened by crossle 8
  • A couple of fixes, update API target to Android 4.4

    A couple of fixes, update API target to Android 4.4

    This is the full list of changes:

    • Removed the + from the layout files' id fields (they're already defined, you shouldn't have the plus in there)
    • Set target API level to 19 (Android 4.4 KitKat) in the library manifest and in the Gradle build file (for both targetSdkVersion and compileSdkVersion)
    • Tweaks to the Gradle settings: use the newer 0.6.x Android plugin and version 19 build tools; declare the defaultConfig to match what is declared in the Manifest
    • Tweaked a bit the Switch class code: now it uses the original API calls that were substituted in the backporting process if running on a platform version that supports them; removed some code in onMeasure that wasn't actually used for anything

    The Gradle changes should be fine as they're pretty basic but I haven't had the chance to test them as much as I'd like. I am not confident with Maven, so that will need someone else to work on it.

    opened by rock3r 7
  • Add empty <application /> element to avoid a Gradle manifest merging error.

    Add empty element to avoid a Gradle manifest merging error.

    Per Android Team (http://stackoverflow.com/a/17757200/937715), library manifests should include an empty <application /> element. Otherwise, the application cannot use a targetSdkVersion number that is different than the library when using Gradle/Android Studio. If the app uses a different targetSdkVersion, you get a compile error Manifest merging failed. - Main manifest has <uses-sdk android:targetSdkVersion='8'> but library uses targetSdkVersion='19'.

    opened by barbeau 6
  • Custom images are ignored

    Custom images are ignored

    This a really weird bug and it's probably not an issue with the library itself, but more of an issue with how the apk is compiled.

    I've generated styles from http://android-holo-colors.com/ and I'm trying to use them to override the default Switch styles. The images that it generates are using the same names as the images provided by this library.

    When I install my app on my Nexus One running 2.3.6, everything is fine and it's using my custom images. When I install the app on any of my 4.2 devices, it uses the default blue images.

    Do you have any idea how to get this to work without having to rename all of my images? I've tried changing the ordering in the .classpath but to no avail.

    Thanks!

    opened by mattprecious 5
  • Incompatible with Support Library material Switch theme

    Incompatible with Support Library material Switch theme

    In Support Library >= 21 Widget.AppCompat.CompoundButton.Switch provides material theming for SwitchCompat. Unfortunately, it does not work as drop-in replacement for Widget.Holo.CompoundButton.Switch if used as value for asb_switchStyle: application crashes with NullPointerException:

                at org.jraf.android.backport.switchwidget.Switch.onMeasure(Unknown Source)
                at android.view.View.measure(View.java:16772)
                at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5139)
                at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1404)
                at android.widget.LinearLayout.measureVertical(LinearLayout.java:695)
                at android.widget.LinearLayout.onMeasure(LinearLayout.java:588)
                at android.view.View.measure(View.java:16772)
                at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5139)
                at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1404)
                at android.widget.LinearLayout.measureHorizontal(LinearLayout.java:1052)
                at android.widget.LinearLayout.onMeasure(LinearLayout.java:590)
                at android.view.View.measure(View.java:16772)
                at android.widget.ListView.setupChild(ListView.java:1870)
                at android.widget.ListView.makeAndAddView(ListView.java:1793)
                at android.widget.ListView.fillDown(ListView.java:691)
                at android.widget.ListView.fillFromTop(ListView.java:752)
                at android.widget.ListView.layoutChildren(ListView.java:1630)
                at android.widget.AbsListView.onLayout(AbsListView.java:2136)
                at android.view.View.layout(View.java:15092)
                at android.view.ViewGroup.layout(ViewGroup.java:4645)
                at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1671)
                at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1525)
                at android.widget.LinearLayout.onLayout(LinearLayout.java:1434)
                at android.view.View.layout(View.java:15092)
                at android.view.ViewGroup.layout(ViewGroup.java:4645)
                at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1671)
                at android.widget.LinearLayout.layoutHorizontal(LinearLayout.java:1660)
                at android.widget.LinearLayout.onLayout(LinearLayout.java:1436)
                at android.view.View.layout(View.java:15092)
                at android.view.ViewGroup.layout(ViewGroup.java:4645)
                at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1671)
                at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1525)
                at android.widget.LinearLayout.onLayout(LinearLayout.java:1434)
                at android.view.View.layout(View.java:15092)
                at android.view.ViewGroup.layout(ViewGroup.java:4645)
                at android.widget.FrameLayout.layoutChildren(FrameLayout.java:453)
                at android.widget.FrameLayout.onLayout(FrameLayout.java:388)
                at android.view.View.layout(View.java:15092)
                at android.view.ViewGroup.layout(ViewGroup.java:4645)
                at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1671)
                at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1525)
                at android.widget.LinearLayout.onLayout(LinearLayout.java:1434)
                at android.view.View.layout(View.java:15092)
                at android.view.ViewGroup.layout(ViewGroup.java:4645)
                at android.widget.FrameLayout.layoutChildren(FrameLayout.java:453)
                at android.widget.FrameLayout.onLayout(FrameLayout.java:388)
                at android.view.View.layout(View.java:15092)
                at android.view.ViewGroup.layout(ViewGroup.java:4645)
                at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:2014)
                at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1771)
                at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1026)
                at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5776)
                at android.view.Choreographer$CallbackRecord.run(Choreographer.java:771)
                at android.view.Choreographer.doCallbacks(Choreographer.java:574)
                at android.view.Choreographer.doFrame(Choreographer.java:544)
                at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:757)
                at android.os.Handler.handleCallback(Handler.java:733)
                at android.os.Handler.dispatchMessage(Handler.java:95)
                at android.os.Looper.loop(Looper.java:149)
                at android.app.ActivityThread.main(ActivityThread.java:5268)
    
    opened by Alexander-- 4
  • Publish on Maven Central or JCenter

    Publish on Maven Central or JCenter

    Hello,

    Can you please consider publishing your library on Maven Central or JCenter for every release ? JRAF is currently down (http://www.downforeveryoneorjustme.com/jraf.org). Maven Central or JCenter are more reliable repositories than JRAF.

    Thank you.

    opened by pdegand 4
  • Customize text on switch and color

    Customize text on switch and color

    Hi,

    I've managed to switch the background color from blue to green but now I want to change the text color?

              <org.jraf.android.backport.switchwidget.Switch
                            android:id="@+id/th"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            app:thumb="@drawable/apptheme_switch_inner_holo_light"
                            app:track="@drawable/apptheme_switch_track_holo_light"
                            app:textOn="@string/switch_yes"
                            app:textOff="@string/switch_no"
                            android:textColor="#000000"
                            />
    

    But it isn't working.

    opened by donpironet 4
  • Getting Null pointer exception

    Getting Null pointer exception

    Failed to find style 'asb_switchStyle' in current theme java.lang.NullPointerException Exception details are logged in Window > Show View > Error Log

    java.lang.NullPointerException at android.text.Layout.getDesiredWidth(Layout.java:68) at org.jraf.android.backport.switchwidget.Switch.makeLayout(Switch.java:350) at org.jraf.android.backport.switchwidget.Switch.onMeasure(Switch.java:302) at android.view.View.measure(View.java:17430) at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:727) at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:463) at android.view.View.measure(View.java:17430) at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:727) at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:463) at android.view.View.measure(View.java:17430) at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5463) at android.widget.FrameLayout.onMeasure(FrameLayout.java:430) at android.view.View.measure(View.java:17430) at android.widget.LinearLayout.measureVertical(LinearLayout.java:875) at android.widget.LinearLayout.onMeasure(LinearLayout.java:613) at android.view.View.measure(View.java:17430) at android.widget.LinearLayout.measureVertical(LinearLayout.java:875) at android.widget.LinearLayout.onMeasure(LinearLayout.java:613) at android.view.View.measure(View.java:17430)

    I added the style as described as follows :

    stil i ma getting the error . I am assuming i am not describing the style properly can you please help.

    opened by PreetiW 4
  • Problem to change thumb and track drawables

    Problem to change thumb and track drawables

    Hi,

    I generated my custom style of Switch in this site : http://android-holo-colors.com/ I added the drawable folders to my project and I inflated the Custom Switch like this :

    <org.jraf.android.backport.switchwidget.Switch xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" xmlns:app="http://schemas.android.com/apk/res/com.myproject" android:layout_width="wrap_content" android:layout_height="wrap_content" app:thumb="@drawable/switch_inner_holo_light" app:track="@drawable/switch_track_holo_light" />

    My custom style is applied correctly on Android 2.3 BUT NOT on Android 4.2 like Samsung Galaxy S4.

    I also tried to create "drawable-xxx-v16" folders with the drawables but doesn't work too. Where is my problem ?

    Soory for my English, I am French. Thanks you for your help.

    opened by anto2b 1
Releases(v2.0.1)
Owner
Benoit Lubek
I do mostly Android development. See http://JRAF.org for more info about me :)
Benoit Lubek
View that imitates Ripple Effect on click which was introduced in Android L (for Android 2.3+)

RippleView View that imitates Ripple Effect on click which was introduced in Android L. Usage For a working implementation, Have a look at the Sample

Muthuramakrishnan Viswanathan 1.2k Dec 30, 2022
Provides 9-patch based drop shadow for view elements. Works on API level 9 or later.

Material Shadow 9-Patch This library provides 9-patch based drop shadow for view elements. Works on API level 14 or later. Target platforms API level

Haruki Hasegawa 481 Dec 19, 2022
A beautiful Android custom View that works similar to a range or seekbar. With animations.

ValueBar A beautiful Android custom View that works similar to a range or seekbar. Selection by gesture. With animations. Supporting API level 11+. De

Philipp Jahoda 147 Nov 20, 2022
Make your native android Toasts Fancy. A library that takes the standard Android toast to the next level with a variety of styling options. Style your toast from code.

FancyToast-Android Prerequisites Add this in your root build.gradle file (not your module build.gradle file): allprojects { repositories { ... ma

Shashank Singhal 1.2k Dec 26, 2022
Make your native android Dialog Fancy. A library that takes the standard Android Dialog to the next level with a variety of styling options. Style your dialog from code.

FancyAlertDialog-Android Prerequisites Add this in your root build.gradle file (not your module build.gradle file): allprojects { repositories { ..

Shashank Singhal 350 Dec 9, 2022
Android library used to create an awesome Android UI based on a draggable element similar to the last YouTube graphic component.

Draggable Panel DEPRECATED. This project is not maintained anymore. Draggable Panel is an Android library created to build a draggable user interface

Pedro Vicente Gómez Sánchez 3k Dec 6, 2022
[] A fast PDF reader component for Android development

This project is no longer maintained. You can find a good replacement here, which is a fork relying on Pdfium instead of Vudroid/MuPDF for decoding PD

Joan Zapata 2.8k Dec 16, 2022
(Deprecated) A custom view component that mimics the new Material Design Bottom Navigation pattern.

BottomBar (Deprecated) I don't have time to maintain this anymore. I basically wrote the whole library in a rush, without tests, while being a serious

Iiro Krankka 8.4k Dec 29, 2022
Library and example project on how to use the UITableView component

UITableView for Android Usage Installation Android Studio Paste or clone this library into the /libs folder, in the root directory of your project. Cr

Thiago Locatelli 679 Nov 11, 2022
A tinder like swipeable card stack component

AndroidSwipeableCardStack Change log: provide option to infinitly swipe in a loop card rotation setting card gravity setting undo animation Thanks for

wenchao jiang 824 Nov 10, 2022
Component Box - a multiplatform server-driven UI framework

Component Box · Component Box is a multiplatform server-driven UI framework. Learn how to use Component Box in your project. Installation implementati

Dropbox 216 Dec 31, 2022
TourGuide is an Android library that aims to provide an easy way to add pointers with animations over a desired Android View

TourGuide TourGuide is an Android library. It lets you add pointer, overlay and tooltip easily, guiding users on how to use your app. Refer to the exa

Tan Jun Rong 2.6k Jan 5, 2023
Bubbles for Android is an Android library to provide chat heads capabilities on your apps. With a fast way to integrate with your development.

Bubbles for Android Bubbles for Android is an Android library to provide chat heads capabilities on your apps. With a fast way to integrate with your

Txus Ballesteros 1.5k Jan 2, 2023
A new canvas drawing library for Android. Aims to be the Fabric.js for Android. Supports text, images, and hand/stylus drawing input. The library has a website and API docs, check it out

FabricView - A new canvas drawing library for Android. The library was born as part of a project in SD Hacks (www.sdhacks.io) on October 3rd. It is cu

Antwan Gaggi 1k Dec 13, 2022
MarkdownView is an Android webview with the capablity of loading Markdown text or file and display it as HTML, it uses MarkdownJ and extends Android webview.

About MarkdownView (Markdown For Android) is an Android library that helps you display Markdown text or files (local/remote) as formatted HTML, and st

Feras Alnatsheh 1k Dec 20, 2022
SwipeBack for Android Activities to do pretty the same as the android "back-button" will do, but in a really intuitive way by using a swipe gesture

SwipeBack SwipeBack is for Android Activities to do pretty the same as the android "back-button" will do, but in a really intuitive way by using a swi

Hannes Dorfmann 697 Dec 14, 2022
Wizard Pager is a library that provides an example implementation of a Wizard UI on Android, it's based of Roman Nurik's wizard pager (https://github.com/romannurik/android-wizardpager)

Wizard Pager Wizard Pager is a library that provides an example implementation of a Wizard UI on Android, it's based of Roman Nurik's wizard pager (ht

Julián Suárez 520 Nov 11, 2022
Xamarin.Android provides open-source bindings of the Android SDK for use with .NET managed languages such as C#

Xamarin.Android Xamarin.Android provides open-source bindings of the Android SDK for use with .NET managed languages such as C#. Build Status Platform

Xamarin 1.8k Jan 5, 2023