Code Monkey home page Code Monkey logo

bensonx / android-speedyviewselector Goto Github PK

View Code? Open in Web Editor NEW

This project forked from mapleqin/android-speedyviewselector

0.0 2.0 0.0 648 KB

This is a change Background Or TextColor Selector support library, with which you can directly specify the Background to be displayed in different states or TextColor Layout xml, such as clicking the button effect, the conventional practice is to create Selector xml file in drawable directory but when the project becomes larger when the file back to the directory Selector cause more and more difficult to maintain and achieve the Library can easily solve these problems, and can also achieve a lot Shape effects can be achieved, if you are using process have any questions or suggestions, please send an email to my email below, thank you!

License: Apache License 2.0

Java 100.00%

android-speedyviewselector's Introduction

Android-SpeedyViewSelector

This is a change Background Or TextColor Selector support library, with which you can directly specify the Background to be displayed in different states or TextColor Layout xml, such as clicking the button effect, the conventional practice is to create Selector xml file in drawable directory but when the project becomes larger when the file back to the directory Selector cause more and more difficult to maintain and achieve the Library can easily solve these problems, and can also achieve a lot Shape effects can be achieved, if you are using process have any questions or suggestions, please send an email to my email below, thank you!

For more information please see the website

Screenshots

Sample1

Android-SpeedyViewSelector with xml code

	   <net.soulwolf.widget.speedyselector.widget.SelectorTextView
            xmlns:soulwolf="http://schemas.android.com/apk/res-auto"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:padding="8dp"
            android:textSize="16sp"
            android:clickable="true"
            android:background="@color/sample_primary"
            android:textColor="@color/sample_primary"
            soulwolf:spStatePressedTextColor="@color/sample_accent"
            soulwolf:spStatePressedBackground="@color/sample_accent"
            soulwolf:spRadius="8dp"
            soulwolf:spJustBorder="true"
            soulwolf:spBorderWidth="1dp"
            android:text="SelectorTextView"/>

        <net.soulwolf.widget.speedyselector.widget.SelectorTextView
            xmlns:soulwolf="http://schemas.android.com/apk/res-auto"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:padding="8dp"
            android:textSize="16sp"
            android:layout_marginTop="8dp"
            android:clickable="true"
            android:background="@color/sample_primary"
            android:textColor="@color/sample_primary"
            soulwolf:spStatePressedTextColor="@color/sample_accent"
            soulwolf:spStatePressedBackground="@color/sample_accent"
            soulwolf:spRadius="0dp"
            soulwolf:spJustBorder="true"
            soulwolf:spBorderWidth="1dp"
            android:text="SelectorTextView"/>


        <net.soulwolf.widget.speedyselector.widget.SelectorTextView
            xmlns:soulwolf="http://schemas.android.com/apk/res-auto"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:padding="8dp"
            android:textSize="16sp"
            android:layout_marginTop="8dp"
            android:clickable="true"
            android:background="@color/sample_primary"
            android:textColor="@color/sample_primary"
            soulwolf:spStatePressedTextColor="@color/sample_accent"
            soulwolf:spStatePressedBackground="@color/sample_accent"
            soulwolf:spRadius="360dp"
            soulwolf:spJustBorder="true"
            soulwolf:spBorderWidth="1dp"
            android:text="SelectorTextView"/>

        <net.soulwolf.widget.speedyselector.widget.SelectorFrameLayout
            xmlns:soulwolf="http://schemas.android.com/apk/res-auto"
            android:layout_width="match_parent"
            android:layout_marginTop="8dp"
            android:padding="20dp"
            soulwolf:spStateDefaultBackground="@color/sample_primary"
            soulwolf:spStatePressedBackground="@color/sample_accent"
            soulwolf:spRadius="8dp"
            android:clickable="true"
            android:layout_height="wrap_content"/>

        <net.soulwolf.widget.speedyselector.widget.SelectorFrameLayout
            xmlns:soulwolf="http://schemas.android.com/apk/res-auto"
            android:layout_width="match_parent"
            android:layout_marginTop="8dp"
            android:padding="20dp"
            soulwolf:spStateDefaultBackground="@color/sample_primary"
            soulwolf:spStatePressedBackground="@color/sample_accent"
            soulwolf:spRadius="0dp"
            android:clickable="true"
            android:layout_height="wrap_content"/>

        <net.soulwolf.widget.speedyselector.widget.SelectorFrameLayout
            android:layout_width="match_parent"
            android:layout_marginTop="8dp"
            android:padding="20dp"
            soulwolf:spStateDefaultBackground="@color/sample_primary"
            soulwolf:spStatePressedBackground="@color/sample_accent"
            soulwolf:spRadius="360dp"
            android:clickable="true"
            android:layout_height="wrap_content"/>

        <net.soulwolf.widget.speedyselector.widget.SelectorRelativeLayout
            xmlns:soulwolf="http://schemas.android.com/apk/res-auto"
            android:layout_width="match_parent"
            android:layout_marginTop="8dp"
            android:padding="8dp"
            soulwolf:spStateDefaultBackground="@color/sample_primary"
            soulwolf:spStatePressedBackground="@color/sample_accent"
            soulwolf:spRadius="8dp"
            soulwolf:spJustBorder="true"
            soulwolf:spBorderWidth="1dp"
            android:clickable="true"
            android:layout_height="wrap_content">

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="SelectorRelativeLayout"
                android:gravity="center"/>

        </net.soulwolf.widget.speedyselector.widget.SelectorRelativeLayout>

        <net.soulwolf.widget.speedyselector.widget.SelectorRelativeLayout
            xmlns:soulwolf="http://schemas.android.com/apk/res-auto"
            android:layout_width="match_parent"
            android:layout_marginTop="8dp"
            android:padding="8dp"
            soulwolf:spStateDefaultBackground="@color/sample_primary"
            soulwolf:spStatePressedBackground="@color/sample_accent"
            soulwolf:spRadius="0dp"
            soulwolf:spJustBorder="true"
            soulwolf:spBorderWidth="1dp"
            android:clickable="true"
            android:layout_height="wrap_content">

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="SelectorRelativeLayout"
                android:gravity="center"/>

        </net.soulwolf.widget.speedyselector.widget.SelectorRelativeLayout>

        <net.soulwolf.widget.speedyselector.widget.SelectorRelativeLayout
            xmlns:soulwolf="http://schemas.android.com/apk/res-auto"
            android:layout_width="match_parent"
            android:layout_marginTop="8dp"
            android:padding="8dp"
            soulwolf:spStateDefaultBackground="@color/sample_primary"
            soulwolf:spStatePressedBackground="@color/sample_accent"
            soulwolf:spRadius="360dp"
            soulwolf:spJustBorder="true"
            soulwolf:spBorderWidth="1dp"
            android:clickable="true"
            android:layout_height="wrap_content">

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="SelectorRelativeLayout"
                android:gravity="center"/>

        </net.soulwolf.widget.speedyselector.widget.SelectorRelativeLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="8dp"
            android:gravity="center_horizontal"
            android:orientation="horizontal">

            <net.soulwolf.widget.speedyselector.widget.SelectorLinearLayout
                xmlns:soulwolf="http://schemas.android.com/apk/res-auto"
                android:layout_width="150dp"
                android:layout_height="150dp"
                soulwolf:spStateDefaultBackground="@color/sample_primary"
                soulwolf:spStatePressedBackground="@color/sample_accent"
                soulwolf:spRadius="360dp"
                android:clickable="true"
                android:gravity="center"
                android:padding="8dp"
                soulwolf:spJustBorder="true"
                soulwolf:spBorderWidth="1dp"
                android:orientation="horizontal">

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="SelectorLinearLayout"/>

            </net.soulwolf.widget.speedyselector.widget.SelectorLinearLayout>

            <net.soulwolf.widget.speedyselector.widget.SelectorLinearLayout
                xmlns:soulwolf="http://schemas.android.com/apk/res-auto"
                android:layout_width="150dp"
                android:layout_height="150dp"
                soulwolf:spStateDefaultBackground="@color/sample_primary"
                soulwolf:spStatePressedBackground="@color/sample_accent"
                soulwolf:spRadius="360dp"
                android:padding="8dp"
                android:clickable="true"
                android:layout_marginLeft="20dp"
                android:gravity="center"
                soulwolf:spJustBorder="false"
                soulwolf:spBorderWidth="1dp"
                android:orientation="horizontal">

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="SelectorLinearLayout"/>

            </net.soulwolf.widget.speedyselector.widget.SelectorLinearLayout>

        </LinearLayout>

Android-SpeedyViewSelector with java code

	// BackgroundSelector
	public void addStateBackground(StateType state,Drawable drawable);

    public void addStateBackgroundResource(StateType state,@DrawableRes int draRes);

    public void addStateBackground(StateType state,float radius,@ColorInt int  color);

    public void addStateBackground(StateType state,float radius,boolean justBorder,@ColorInt int color);

    public void addStateBackground(StateType state,float radius,boolean justBorder,float borderWidth,@ColorInt int color);

    public void addStateBackgroundResource(StateType state,float radius,@ColorRes int colorRes);

    public void addStateBackgroundResource(StateType state,float radius,boolean justBorder,@ColorRes int colorRes);

    public void addStateBackgroundResource(StateType state,float radius,boolean justBorder,float borderWidth,@ColorRes int colorRes);

    public void requestSelector();

	// TextColorSelector
	public void setTextColorResource(@ColorRes int resId);

    public void addTextStateColor(StateType state,@ColorInt int color);

    public void addTextStateColorResource(StateType state, @ColorRes int colorRes);

    public void requestSelector();

Attr params info

attrName Explanation
spRadius This parameter is used to set the radius of each corner Background!
spJustBorder This parameter indicates whether to draw only border
spBorderWidth This parameter indicates the width of the border
spStateDefaultBackground
spStateDefaultTextColor
Background Or TextColor this parameter default to be displayed
spStateFocusedBackground
spStateFocusedTextColor
Background Or TextColor this parameter StateFocused to be displayed
spStateWindowFocusedBackground
spStateWindowFocusedTextColor
Background Or TextColor this parameter StateWindowFocused to be displayed
spStateEnabledBackground
spStateEnabledTextColor
Background Or TextColor this parameter StateEnabled to be displayed
spStateCheckedBackground
spStateCheckedTextColor
Background Or TextColor this parameter StateChecked to be displayed
spStateSelectedBackground
spStateSelectedTextColor
Background Or TextColor this parameter StateSelected to be displayed
spStateActivatedBackground
spStateActivatedTextColor
Background Or TextColor this parameter StateActivated to be displayed
spStatePressedBackground
spStatePressedTextColor
Background Or TextColor this parameter StatePressed to be displayed
spStateActiveBackground
spStateActiveTextColor
Background Or TextColor this parameter StateActive to be displayed

Implementing View!

  • SelectorAbsoluteLayout
  • SelectorButton
  • SelectorCheckBox
  • SelectorEditText
  • SelectorFrameLayout
  • SelectorGridLayout
  • SelectorImageButton
  • SelectorLinearLayout
  • SelectorRadioButton
  • SelectorRadioGroup
  • SelectorRelativeLayout
  • SelectorTableLayout
  • SelectorTextView
  • SelectorView

Custom

	// Background Selector
	public class SelectorFrameLayout extends FrameLayout implements BackgroundSelector{

	    SpeedySelectorDelegate mSpeedySelectorDelegate;
	
	    public SelectorFrameLayout(Context context) {
	        super(context);
	        mSpeedySelectorDelegate = SpeedySelectorDelegate.obtain(this);
	    }
	
	    public SelectorFrameLayout(Context context, AttributeSet attrs) {
	        super(context, attrs);
	        mSpeedySelectorDelegate = SpeedySelectorDelegate.obtain(this,attrs);
	    }
	
	    public SelectorFrameLayout(Context context, AttributeSet attrs, int defStyleAttr) {
	        super(context, attrs, defStyleAttr);
	        mSpeedySelectorDelegate = SpeedySelectorDelegate.obtain(this,attrs,defStyleAttr);
	    }
	
	    @TargetApi(Build.VERSION_CODES.LOLLIPOP)
	    public SelectorFrameLayout(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
	        super(context, attrs, defStyleAttr, defStyleRes);
	        mSpeedySelectorDelegate = SpeedySelectorDelegate.obtain(this,attrs,defStyleAttr,defStyleRes);
	    }
	
	    @Override
	    public void addStateBackground(StateType state, Drawable drawable) {
	        mSpeedySelectorDelegate.addStateBackground(state,drawable);
	    }
	
	    @Override
	    public void addStateBackgroundResource(StateType state, @DrawableRes int draRes) {
	        mSpeedySelectorDelegate.addStateBackgroundResource(state, draRes);
	    }
	
	    @Override
	    public void addStateBackground(StateType state, float radius, @ColorInt int color) {
	        mSpeedySelectorDelegate.addStateBackground(state,radius,color);
	    }
	
	    @Override
	    public void addStateBackground(StateType state, float radius, boolean justBorder, @ColorInt int color) {
	        mSpeedySelectorDelegate.addStateBackground(state,radius,justBorder,color);
	    }
	
	    @Override
	    public void addStateBackground(StateType state, float radius, boolean justBorder, float borderWidth, @ColorInt int color) {
	        mSpeedySelectorDelegate.addStateBackground(state,radius,justBorder,borderWidth,color);
	    }
	
	    @Override
	    public void addStateBackgroundResource(StateType state, float radius, @ColorRes int colorRes) {
	        mSpeedySelectorDelegate.addStateBackgroundResource(state, radius,colorRes);
	    }
	
	    @Override
	    public void addStateBackgroundResource(StateType state, float radius, boolean justBorder, @ColorRes int colorRes) {
	        mSpeedySelectorDelegate.addStateBackgroundResource(state, radius,justBorder,colorRes);
	    }
	
	    @Override
	    public void addStateBackgroundResource(StateType state, float radius, boolean justBorder, float borderWidth, @ColorRes int colorRes) {
	        mSpeedySelectorDelegate.addStateBackgroundResource(state, radius,justBorder,borderWidth,colorRes);
	    }
	
	    @Override
	    public void requestSelector() {
	        mSpeedySelectorDelegate.requestSelector();
	    }
	}

	// General Selector
	public class SelectorTextView extends TextView implements GeneralSelector{

	    SpeedySelectorDelegate mSpeedySelectorDelegate;
	
	    public SelectorTextView(Context context) {
	        super(context);
	        mSpeedySelectorDelegate = SpeedySelectorDelegate.obtainGeneral(this);
	    }
	
	    public SelectorTextView(Context context, AttributeSet attrs) {
	        super(context, attrs);
	        mSpeedySelectorDelegate = SpeedySelectorDelegate.obtainGeneral(this, attrs);
	    }
	
	    public SelectorTextView(Context context, AttributeSet attrs, int defStyleAttr) {
	        super(context, attrs, defStyleAttr);
	        mSpeedySelectorDelegate = SpeedySelectorDelegate.obtainGeneral(this, attrs, defStyleAttr);
	    }
	
	    @TargetApi(Build.VERSION_CODES.LOLLIPOP)
	    public SelectorTextView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
	        super(context, attrs, defStyleAttr, defStyleRes);
	        mSpeedySelectorDelegate = SpeedySelectorDelegate.obtainGeneral(this, attrs, defStyleAttr, defStyleRes);
	    }
	
	    @Override
	    public void addStateBackground(StateType state, Drawable drawable) {
	        mSpeedySelectorDelegate.addStateBackground(state,drawable);
	    }
	
	    @Override
	    public void addStateBackgroundResource(StateType state, @DrawableRes int draRes) {
	        mSpeedySelectorDelegate.addStateBackgroundResource(state, draRes);
	    }
	
	    @Override
	    public void addStateBackground(StateType state, float radius, @ColorInt int color) {
	        mSpeedySelectorDelegate.addStateBackground(state,radius,color);
	    }
	
	    @Override
	    public void addStateBackground(StateType state, float radius, boolean justBorder, @ColorInt int color) {
	        mSpeedySelectorDelegate.addStateBackground(state,radius,justBorder,color);
	    }
	
	    @Override
	    public void addStateBackground(StateType state, float radius, boolean justBorder, float borderWidth, @ColorInt int color) {
	        mSpeedySelectorDelegate.addStateBackground(state,radius,justBorder,borderWidth,color);
	    }
	
	    @Override
	    public void addStateBackgroundResource(StateType state, float radius, @ColorRes int colorRes) {
	        mSpeedySelectorDelegate.addStateBackgroundResource(state, radius,colorRes);
	    }
	
	    @Override
	    public void addStateBackgroundResource(StateType state, float radius, boolean justBorder, @ColorRes int colorRes) {
	        mSpeedySelectorDelegate.addStateBackgroundResource(state, radius,justBorder,colorRes);
	    }
	
	    @Override
	    public void addStateBackgroundResource(StateType state, float radius, boolean justBorder, float borderWidth, @ColorRes int colorRes) {
	        mSpeedySelectorDelegate.addStateBackgroundResource(state, radius,justBorder,borderWidth,colorRes);
	    }
	
	    @Override
	    public void setTextColorResource(@ColorRes int resId) {
	        mSpeedySelectorDelegate.setTextColorRessource(resId);
	    }
	
	    @Override
	    public void addTextStateColor(StateType state, @ColorInt int color) {
	        mSpeedySelectorDelegate.addTextStateColor(state,color);
	    }
	
	    @Override
	    public void addTextStateColorResource(StateType state, @ColorRes int colorRes) {
	        mSpeedySelectorDelegate.addTextStateColorRessource(state, colorRes);
	    }
	
	    @Override
	    public void requestSelector() {
	        mSpeedySelectorDelegate.requestSelector();
	    }
	}

Maven

<dependency>
    <groupId>net.soulwolf.widget</groupId>
	<url>https://dl.bintray.com/soulwolf/maven</url>
    <artifactId>speedySelector</artifactId>
    <version>1.0.0</version>
</dependency>

Gradle

allprojects {
   repositories {
      jcenter()
   }
}

compile 'net.soulwolf.widget:speedySelector:1.0.0'

Developed by

Ching Soulwolf - [email protected]

License

Copyright 2015 Soulwolf Ching
Copyright 2015 The Android Open Source Project for Android-SpeedyViewSelector

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.

android-speedyviewselector's People

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.