android-switch-backport


Source link: https://github.com/BoD/android-switch-backport

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:

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.

Resources

Gradle plugin for Spoon. Allows you to run spoon with almost no effort under new Android build system.

Helium is a DSL for REST API specifications and also a Java API for processing descriptions written in this language. The main goal of this project is to create a single source of truth about some REST API. Taking a spec as an input, Helium generates a lot of useful staff that can be used to rapidly develop REST clients.

Goro performs asynchronous operations in a queue. You may ask Goro to perform some task with schedule method invocation.

Android Lollipop Palette is now easy to use with Glide.

This Gradle plugin adds a new task to print out the dex method count of your Android projects without having to install separate tools.

A Safari extension that adds view source links for the Android SDK.

Topics


2D Engines   3D Engines   9-Patch   Action Bars   Activities   ADB   Advertisements   Analytics   Animations   ANR   AOP   API   APK   APT   Architecture   Audio   Autocomplete   Background Processing   Backward Compatibility   Badges   Bar Codes   Benchmarking   Bitmaps   Bluetooth   Blur Effects   Bread Crumbs   BRMS   Browser Extensions   Build Systems   Bundles   Buttons   Caching   Camera   Canvas   Cards   Carousels   Changelog   Checkboxes   Cloud Storages   Color Analysis   Color Pickers   Colors   Comet/Push   Compass Sensors   Conferences   Content Providers   Continuous Integration   Crash Reports   Credit Cards   Credits   CSV   Curl/Flip   Data Binding   Data Generators   Data Structures   Database   Database Browsers   Date &   Debugging   Decompilers   Deep Links   Dependency Injections   Design   Design Patterns   Dex   Dialogs   Distributed Computing   Distribution Platforms   Download Managers   Drawables   Emoji   Emulators   EPUB   Equalizers &   Event Buses   Exception Handling   Face Recognition   Feedback &   File System   File/Directory   Fingerprint   Floating Action   Fonts   Forms   Fragments   FRP   FSM   Functional Programming   Gamepads   Games   Geocaching   Gestures   GIF   Glow Pad   Gradle Plugins   Graphics   Grid Views   Highlighting   HTML   HTTP Mocking   Icons   IDE   IDE Plugins   Image Croppers   Image Loaders   Image Pickers   Image Processing   Image Views   Instrumentation   Intents   Job Schedulers   JSON   Keyboard   Kotlin   Layouts   Library Demos   List View   List Views   Localization   Location   Lock Patterns   Logcat   Logging   Mails   Maps   Markdown   Mathematics   Maven Plugins   MBaaS   Media   Menus   Messaging   MIME   Mobile Web   Native Image   Navigation   NDK   Networking   NFC   NoSQL   Number Pickers   OAuth   Object Mocking   OCR Engines   OpenGL   ORM   Other Pickers   Parallax List   Parcelables   Particle Systems   Password Inputs   PDF   Permissions   Physics Engines   Platforms   Plugin Frameworks   Preferences   Progress Indicators   ProGuard   Properties   Protocol Buffer   Pull To   Purchases   Push/Pull   QR Codes   Quick Return   Radio Buttons   Range Bars   Ratings   Recycler Views   Resources   REST   Ripple Effects   RSS   Screenshots   Scripting   Scroll Views   SDK   Search Inputs   Security   Sensors   Services   Showcase Views   Signatures   Sliding Panels   Snackbars   SOAP   Social Networks   Spannable   Spinners   Splash Screens   SSH   Static Analysis   Status Bars   Styling   SVG   System   Tags   Task Managers   TDD &   Template Engines   Testing   Testing Tools   Text Formatting   Text Views   Text Watchers   Text-to   Toasts   Toolkits For   Tools   Tooltips   Trainings   TV   Twitter   Updaters   USB   User Stories   Utils   Validation   Video   View Adapters   View Pagers   Views   Watch Face   Wearable Data   Wearables   Weather   Web Tools   Web Views   WebRTC   WebSockets   Wheel Widgets   Wi-Fi   Widgets   Windows   Wizards   XML   XMPP   YAML   ZIP Codes