├── .idea
├── .name
├── vcs.xml
└── gradle.xml
├── app
├── .gitignore
├── src
│ ├── main
│ │ ├── res
│ │ │ ├── drawable-xhdpi
│ │ │ │ ├── icon_add.png
│ │ │ │ ├── ic_launcher.png
│ │ │ │ ├── icon_arrow_right.png
│ │ │ │ ├── icon_header_back.png
│ │ │ │ ├── icon_header_pause.png
│ │ │ │ ├── icon_header_play.png
│ │ │ │ └── divider_headerbar_bottom.9.png
│ │ │ ├── drawable-hdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── drawable-ldpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── drawable-mdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── drawable-xxhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── drawable-xxxhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── values
│ │ │ │ ├── colorsl.xml
│ │ │ │ ├── colors.xml
│ │ │ │ ├── dimens.xml
│ │ │ │ ├── arrays.xml
│ │ │ │ ├── styles.xml
│ │ │ │ └── strings.xml
│ │ │ ├── values-w820dp
│ │ │ │ └── dimens.xml
│ │ │ └── layout
│ │ │ │ ├── activity_ltab.xml
│ │ │ │ ├── activity_lpreference.xml
│ │ │ │ ├── activity_ldialog.xml
│ │ │ │ ├── activity_limagebutton.xml
│ │ │ │ ├── activity_lbutton.xml
│ │ │ │ ├── activity_lframelayout.xml
│ │ │ │ └── activity_main.xml
│ │ ├── java
│ │ │ └── com
│ │ │ │ └── lion
│ │ │ │ └── demo
│ │ │ │ └── material
│ │ │ │ ├── activity
│ │ │ │ ├── BaseActivity.java
│ │ │ │ ├── LTabActivity.java
│ │ │ │ ├── LPreferenceActivity.java
│ │ │ │ ├── LImageButtonActivity.java
│ │ │ │ ├── LButtonActivity.java
│ │ │ │ ├── LFrameLayoutActivity.java
│ │ │ │ ├── LDialogActivity.java
│ │ │ │ └── MainActivity.java
│ │ │ │ └── tab
│ │ │ │ ├── TabPagerAdapter.java
│ │ │ │ └── TabFragment.java
│ │ └── AndroidManifest.xml
│ ├── test
│ │ └── java
│ │ │ └── com
│ │ │ └── lion
│ │ │ └── material
│ │ │ └── demo
│ │ │ └── ExampleUnitTest.java
│ └── androidTest
│ │ └── java
│ │ └── com
│ │ └── lion
│ │ └── material
│ │ └── demo
│ │ └── ApplicationTest.java
├── proguard-rules.pro
└── build.gradle
├── material
├── .gitignore
├── src
│ ├── main
│ │ ├── res
│ │ │ ├── values
│ │ │ │ ├── strings.xml
│ │ │ │ ├── dimens_material.xml
│ │ │ │ ├── colors_material.xml
│ │ │ │ └── attrs_material.xml
│ │ │ ├── drawable-hdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── drawable-mdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── drawable-xhdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ ├── icon_dialog_close.png
│ │ │ │ ├── icon_dialog_list_checked.png
│ │ │ │ └── headerbar_bottom_divider.9.png
│ │ │ ├── drawable-xxhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── drawable
│ │ │ │ ├── material_dialog_bg.9.png
│ │ │ │ └── material_selector_dialog_list_checkbox.xml
│ │ │ ├── color
│ │ │ │ ├── selecter_preference_summary.xml
│ │ │ │ └── selecter_settings_item_text.xml
│ │ │ └── layout
│ │ │ │ ├── material_dialog_listview.xml
│ │ │ │ ├── material_dialog_listview_adapter.xml
│ │ │ │ ├── preference_normal.xml
│ │ │ │ ├── preference_checkbox.xml
│ │ │ │ └── material_alert_dialog.xml
│ │ ├── java
│ │ │ └── com
│ │ │ │ └── lion
│ │ │ │ └── material
│ │ │ │ ├── extra
│ │ │ │ ├── LItemClickListener.java
│ │ │ │ ├── IMaterial.java
│ │ │ │ └── MaterialStyle.java
│ │ │ │ ├── dialog
│ │ │ │ ├── LDialogLayout.java
│ │ │ │ ├── LDialogListBuilder.java
│ │ │ │ ├── LAlertDialog.java
│ │ │ │ └── LDialogController.java
│ │ │ │ └── widget
│ │ │ │ ├── PreferenceNormal.java
│ │ │ │ ├── LDrawerButton.java
│ │ │ │ ├── PreferenceCheckBox.java
│ │ │ │ ├── LButton.java
│ │ │ │ ├── LImageButton.java
│ │ │ │ ├── LFrameLayout.java
│ │ │ │ ├── LLinearLayout.java
│ │ │ │ ├── LTabIndicator.java
│ │ │ │ └── LSwitch.java
│ │ └── AndroidManifest.xml
│ ├── test
│ │ └── java
│ │ │ └── com
│ │ │ └── lion
│ │ │ └── material
│ │ │ └── ExampleUnitTest.java
│ └── androidTest
│ │ └── java
│ │ └── com
│ │ └── lion
│ │ └── material
│ │ └── ApplicationTest.java
├── build.gradle
└── proguard-rules.pro
├── settings.gradle
├── Preview Gif
├── main.gif
├── button.gif
└── checkbox.gif
├── Photo_locker_release_1.5.2.apk
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── .gitignore
├── .gitattributes
├── gradle.properties
├── gradlew.bat
├── README.md
└── gradlew
/.idea/.name:
--------------------------------------------------------------------------------
1 | MaterialWidget
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/material/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app', ':material'
2 |
--------------------------------------------------------------------------------
/Preview Gif/main.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cshxql/MaterialWidget/HEAD/Preview Gif/main.gif
--------------------------------------------------------------------------------
/Preview Gif/button.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cshxql/MaterialWidget/HEAD/Preview Gif/button.gif
--------------------------------------------------------------------------------
/Preview Gif/checkbox.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cshxql/MaterialWidget/HEAD/Preview Gif/checkbox.gif
--------------------------------------------------------------------------------
/Photo_locker_release_1.5.2.apk:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cshxql/MaterialWidget/HEAD/Photo_locker_release_1.5.2.apk
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cshxql/MaterialWidget/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/material/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | MaterialLib
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/workspace.xml
5 | /.idea/libraries
6 | .DS_Store
7 | /build
8 | /captures
9 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/icon_add.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cshxql/MaterialWidget/HEAD/app/src/main/res/drawable-xhdpi/icon_add.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cshxql/MaterialWidget/HEAD/app/src/main/res/drawable-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-ldpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cshxql/MaterialWidget/HEAD/app/src/main/res/drawable-ldpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cshxql/MaterialWidget/HEAD/app/src/main/res/drawable-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cshxql/MaterialWidget/HEAD/app/src/main/res/drawable-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cshxql/MaterialWidget/HEAD/app/src/main/res/drawable-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cshxql/MaterialWidget/HEAD/app/src/main/res/drawable-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/icon_arrow_right.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cshxql/MaterialWidget/HEAD/app/src/main/res/drawable-xhdpi/icon_arrow_right.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/icon_header_back.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cshxql/MaterialWidget/HEAD/app/src/main/res/drawable-xhdpi/icon_header_back.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/icon_header_pause.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cshxql/MaterialWidget/HEAD/app/src/main/res/drawable-xhdpi/icon_header_pause.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/icon_header_play.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cshxql/MaterialWidget/HEAD/app/src/main/res/drawable-xhdpi/icon_header_play.png
--------------------------------------------------------------------------------
/material/src/main/res/drawable-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cshxql/MaterialWidget/HEAD/material/src/main/res/drawable-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/material/src/main/res/drawable-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cshxql/MaterialWidget/HEAD/material/src/main/res/drawable-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/material/src/main/res/drawable-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cshxql/MaterialWidget/HEAD/material/src/main/res/drawable-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/material/src/main/res/drawable-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cshxql/MaterialWidget/HEAD/material/src/main/res/drawable-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/material/src/main/res/drawable/material_dialog_bg.9.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cshxql/MaterialWidget/HEAD/material/src/main/res/drawable/material_dialog_bg.9.png
--------------------------------------------------------------------------------
/material/src/main/res/drawable-xhdpi/icon_dialog_close.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cshxql/MaterialWidget/HEAD/material/src/main/res/drawable-xhdpi/icon_dialog_close.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/divider_headerbar_bottom.9.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cshxql/MaterialWidget/HEAD/app/src/main/res/drawable-xhdpi/divider_headerbar_bottom.9.png
--------------------------------------------------------------------------------
/material/src/main/res/drawable-xhdpi/icon_dialog_list_checked.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cshxql/MaterialWidget/HEAD/material/src/main/res/drawable-xhdpi/icon_dialog_list_checked.png
--------------------------------------------------------------------------------
/material/src/main/res/drawable-xhdpi/headerbar_bottom_divider.9.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cshxql/MaterialWidget/HEAD/material/src/main/res/drawable-xhdpi/headerbar_bottom_divider.9.png
--------------------------------------------------------------------------------
/app/src/main/res/values/colorsl.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #de000000
4 | #8a000000
5 | #607d8b
6 |
7 |
8 |
--------------------------------------------------------------------------------
/material/src/main/java/com/lion/material/extra/LItemClickListener.java:
--------------------------------------------------------------------------------
1 | package com.lion.material.extra;
2 |
3 | /**
4 | * Created by Lion on 2015/11/10.
5 | */
6 | public interface LItemClickListener {
7 | void onItemClickListener(Object object);
8 | }
9 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 |
6 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/arrays.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | - One
6 | - Two
7 | - Three
8 |
9 |
10 |
--------------------------------------------------------------------------------
/material/src/main/java/com/lion/material/extra/IMaterial.java:
--------------------------------------------------------------------------------
1 | package com.lion.material.extra;
2 |
3 | public interface IMaterial {
4 | public void perfirmSuperClick();
5 |
6 | public void setColor(int fullColor);
7 |
8 | public void setType(int widgetType);
9 |
10 | }
11 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Mon Dec 28 10:00:20 PST 2015
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip
7 |
--------------------------------------------------------------------------------
/material/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/material/src/main/res/color/selecter_preference_summary.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/material/src/main/res/color/selecter_settings_item_text.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/material/src/main/res/drawable/material_selector_dialog_list_checkbox.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/material/src/main/res/values/dimens_material.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 56dp
4 | 56dp
5 | 15sp
6 |
7 | 70dp
8 | 42dp
9 |
10 |
11 |
--------------------------------------------------------------------------------
/app/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/material/src/test/java/com/lion/material/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.lion.material;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * To work on unit tests, switch the Test Artifact in the Build Variants view.
9 | */
10 | public class ExampleUnitTest {
11 | @Test
12 | public void addition_isCorrect() throws Exception {
13 | assertEquals(4, 2 + 2);
14 | }
15 | }
--------------------------------------------------------------------------------
/app/src/test/java/com/lion/material/demo/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.lion.material.demo;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * To work on unit tests, switch the Test Artifact in the Build Variants view.
9 | */
10 | public class ExampleUnitTest {
11 | @Test
12 | public void addition_isCorrect() throws Exception {
13 | assertEquals(4, 2 + 2);
14 | }
15 | }
--------------------------------------------------------------------------------
/material/src/androidTest/java/com/lion/material/ApplicationTest.java:
--------------------------------------------------------------------------------
1 | package com.lion.material;
2 |
3 | import android.app.Application;
4 | import android.test.ApplicationTestCase;
5 |
6 | /**
7 | * Testing Fundamentals
8 | */
9 | public class ApplicationTest extends ApplicationTestCase {
10 | public ApplicationTest() {
11 | super(Application.class);
12 | }
13 | }
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/lion/material/demo/ApplicationTest.java:
--------------------------------------------------------------------------------
1 | package com.lion.material.demo;
2 |
3 | import android.app.Application;
4 | import android.test.ApplicationTestCase;
5 |
6 | /**
7 | * Testing Fundamentals
8 | */
9 | public class ApplicationTest extends ApplicationTestCase {
10 | public ApplicationTest() {
11 | super(Application.class);
12 | }
13 | }
--------------------------------------------------------------------------------
/.gitattributes:
--------------------------------------------------------------------------------
1 | # Auto detect text files and perform LF normalization
2 | * text=auto
3 |
4 | # Custom for Visual Studio
5 | *.cs diff=csharp
6 | *.sln merge=union
7 | *.csproj merge=union
8 | *.vbproj merge=union
9 | *.fsproj merge=union
10 | *.dbproj merge=union
11 |
12 | # Standard to msysgit
13 | *.doc diff=astextplain
14 | *.DOC diff=astextplain
15 | *.docx diff=astextplain
16 | *.DOCX diff=astextplain
17 | *.dot diff=astextplain
18 | *.DOT diff=astextplain
19 | *.pdf diff=astextplain
20 | *.PDF diff=astextplain
21 | *.rtf diff=astextplain
22 | *.RTF diff=astextplain
23 |
--------------------------------------------------------------------------------
/material/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 |
3 | android {
4 | compileSdkVersion 23
5 | buildToolsVersion "23.0.3"
6 |
7 | defaultConfig {
8 | minSdkVersion 14
9 | targetSdkVersion 23
10 | versionCode 1
11 | versionName "1.0"
12 | }
13 | buildTypes {
14 | release {
15 | minifyEnabled false
16 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
17 | }
18 | }
19 | }
20 |
21 | dependencies {
22 | compile fileTree(dir: 'libs', include: ['*.jar'])
23 | testCompile 'junit:junit:4.12'
24 | compile 'com.android.support:appcompat-v7:23.4.0'
25 | }
26 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in E:\development\sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/material/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in E:\development\sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 23
5 | buildToolsVersion "23.0.3"
6 |
7 | defaultConfig {
8 | applicationId "com.lion.demo.material"
9 | minSdkVersion 14
10 | targetSdkVersion 23
11 | versionCode 1
12 | versionName "1.0"
13 | }
14 | buildTypes {
15 | release {
16 | minifyEnabled false
17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
18 | }
19 | }
20 | }
21 |
22 | dependencies {
23 | compile fileTree(dir: 'libs', include: ['*.jar'])
24 | testCompile 'junit:junit:4.12'
25 | compile 'com.android.support:appcompat-v7:23.4.0'
26 | compile project(path: ':material')
27 | }
28 |
--------------------------------------------------------------------------------
/material/src/main/res/layout/material_dialog_listview.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
13 |
14 |
22 |
23 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m
13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
14 |
15 | # When configured, Gradle will run in incubating parallel mode.
16 | # This option should only be used with decoupled projects. More details, visit
17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
18 | # org.gradle.parallel=true
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
14 |
15 |
16 |
19 |
20 |
24 |
25 |
--------------------------------------------------------------------------------
/app/src/main/java/com/lion/demo/material/activity/BaseActivity.java:
--------------------------------------------------------------------------------
1 | package com.lion.demo.material.activity;
2 |
3 | import android.content.Context;
4 | import android.content.pm.ActivityInfo;
5 | import android.os.Bundle;
6 | import android.support.v4.app.FragmentActivity;
7 | import android.view.Window;
8 |
9 | public class BaseActivity extends FragmentActivity {
10 | protected Context mContext;
11 |
12 | @Override
13 | protected void onCreate(Bundle savedInstanceState) {
14 | final int orientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
15 | if (getRequestedOrientation() != orientation) {
16 | setRequestedOrientation(orientation);
17 | }
18 | requestWindowFeature(Window.FEATURE_NO_TITLE);
19 | super.onCreate(savedInstanceState);
20 | mContext = this;
21 | }
22 |
23 | private boolean mCalled = false;
24 |
25 | @Override
26 | public void setRequestedOrientation(int requestedOrientation) {
27 | if (!mCalled) {
28 | super.setRequestedOrientation(requestedOrientation);
29 | mCalled = true;
30 | }
31 | }
32 |
33 |
34 | }
35 |
--------------------------------------------------------------------------------
/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
26 |
27 |
--------------------------------------------------------------------------------
/app/src/main/java/com/lion/demo/material/tab/TabPagerAdapter.java:
--------------------------------------------------------------------------------
1 | package com.lion.demo.material.tab;
2 |
3 | import android.content.Context;
4 | import android.support.v4.app.Fragment;
5 | import android.support.v4.app.FragmentManager;
6 | import android.support.v4.app.FragmentPagerAdapter;
7 |
8 | import com.lion.demo.material.R;
9 |
10 |
11 | public class TabPagerAdapter extends FragmentPagerAdapter {
12 | private String[] mTitles;
13 | private final String[] mContent = new String[] { "One", "Two", "Three" };
14 |
15 | private Context mContext;
16 |
17 | public TabPagerAdapter(Context context, FragmentManager fm) {
18 | super(fm);
19 | this.mContext = context;
20 | mTitles = mContext.getResources().getStringArray(R.array.title);
21 | }
22 |
23 | @Override
24 | public Fragment getItem(int position) {
25 | return TabFragment.newInstance(mContent[position % mContent.length]);
26 | }
27 |
28 | @Override
29 | public CharSequence getPageTitle(int position) {
30 | return mTitles[position];
31 | }
32 |
33 | @Override
34 | public int getCount() {
35 | return mTitles.length;
36 | }
37 | }
--------------------------------------------------------------------------------
/material/src/main/res/values/colors_material.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #00000000
4 |
5 | #FF9800
6 | #09314B
7 | #5A7384
8 |
9 |
10 |
12 | #1d311b92
13 | #de000000
14 | #8a000000
15 | #30000000
16 | #30ffffff
17 | #dcdcdc
18 | #3d000000
19 | #de000000
20 | #8a000000
21 | #de000000
22 |
23 |
--------------------------------------------------------------------------------
/app/src/main/java/com/lion/demo/material/activity/LTabActivity.java:
--------------------------------------------------------------------------------
1 | package com.lion.demo.material.activity;
2 |
3 | import android.os.Bundle;
4 | import android.support.v4.view.ViewPager;
5 | import android.view.View;
6 | import android.view.View.OnClickListener;
7 |
8 | import com.lion.demo.material.R;
9 | import com.lion.demo.material.tab.TabPagerAdapter;
10 | import com.lion.material.widget.LTabIndicator;
11 |
12 |
13 | public class LTabActivity extends BaseActivity {
14 | private LTabIndicator lineTabIndicator;
15 | private ViewPager viewPager;
16 |
17 | @Override
18 | protected void onCreate(Bundle bundle) {
19 | super.onCreate(bundle);
20 | setContentView(R.layout.activity_ltab);
21 | findViews();
22 | }
23 |
24 | private void findViews() {
25 | findViewById(R.id.header_left).setOnClickListener(
26 | new OnClickListener() {
27 |
28 | @Override
29 | public void onClick(View v) {
30 | finish();
31 | }
32 | });
33 | lineTabIndicator = (LTabIndicator) findViewById(R.id.tab_indicator);
34 | viewPager = (ViewPager) findViewById(R.id.view_pager);
35 | viewPager.setAdapter(new TabPagerAdapter(this,
36 | getSupportFragmentManager()));
37 | lineTabIndicator.setViewPager(viewPager);
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/material/src/main/res/layout/material_dialog_listview_adapter.xml:
--------------------------------------------------------------------------------
1 |
2 |
12 |
13 |
21 |
22 |
30 |
31 |
--------------------------------------------------------------------------------
/material/src/main/java/com/lion/material/dialog/LDialogLayout.java:
--------------------------------------------------------------------------------
1 | package com.lion.material.dialog;
2 |
3 | import android.content.Context;
4 | import android.util.AttributeSet;
5 | import android.util.DisplayMetrics;
6 | import android.widget.LinearLayout;
7 |
8 | import static android.view.View.MeasureSpec.EXACTLY;
9 |
10 | public class LDialogLayout extends LinearLayout {
11 | private float mMaxWidthWeight = 0.9f;
12 | private float mMinWidthWeight = 0.55f;
13 | // private float mMaxHeightWeight = 0.8f;
14 | private DisplayMetrics metrics;
15 |
16 | public LDialogLayout(Context context) {
17 | super(context);
18 | }
19 |
20 | public LDialogLayout(Context context, AttributeSet attrs) {
21 | super(context, attrs);
22 | metrics = getContext().getResources().getDisplayMetrics();
23 | }
24 |
25 | @Override
26 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
27 |
28 | float widthWeight = metrics.widthPixels < metrics.heightPixels ? mMaxWidthWeight
29 | : mMinWidthWeight;
30 | widthMeasureSpec = MeasureSpec.makeMeasureSpec(
31 | (int) (metrics.widthPixels * widthWeight), EXACTLY);
32 |
33 | super.onMeasure(widthMeasureSpec, heightMeasureSpec);
34 | // if (getMeasuredHeight() > metrics.heightPixels * mMaxHeightWeight) {
35 | // super.onMeasure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(
36 | // (int) (metrics.heightPixels * mMaxHeightWeight), EXACTLY));
37 | // }
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/material/src/main/res/values/attrs_material.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
31 |
32 |
--------------------------------------------------------------------------------
/app/src/main/java/com/lion/demo/material/tab/TabFragment.java:
--------------------------------------------------------------------------------
1 | package com.lion.demo.material.tab;
2 |
3 | import android.os.Bundle;
4 | import android.support.v4.app.Fragment;
5 | import android.view.Gravity;
6 | import android.view.LayoutInflater;
7 | import android.view.View;
8 | import android.view.ViewGroup;
9 | import android.widget.LinearLayout;
10 | import android.widget.LinearLayout.LayoutParams;
11 | import android.widget.TextView;
12 |
13 | public class TabFragment extends Fragment {
14 | private static final String KEY_CONTENT = "MyContent";
15 |
16 | public static TabFragment newInstance(String content) {
17 | TabFragment fragment = new TabFragment();
18 | fragment.mContent = content;
19 | return fragment;
20 | }
21 |
22 | private String mContent = "One";
23 |
24 | @Override
25 | public void onCreate(Bundle savedInstanceState) {
26 | super.onCreate(savedInstanceState);
27 |
28 | if ((savedInstanceState != null)
29 | && savedInstanceState.containsKey(KEY_CONTENT)) {
30 | mContent = savedInstanceState.getString(KEY_CONTENT);
31 | }
32 | }
33 |
34 | @Override
35 | public View onCreateView(LayoutInflater inflater, ViewGroup container,
36 | Bundle savedInstanceState) {
37 | TextView text = new TextView(getActivity());
38 | text.setGravity(Gravity.CENTER);
39 | text.setText(mContent);
40 | text.setTextSize(20 * getResources().getDisplayMetrics().density);
41 | text.setPadding(20, 20, 20, 20);
42 |
43 | LinearLayout layout = new LinearLayout(getActivity());
44 | layout.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT,
45 | LayoutParams.MATCH_PARENT));
46 | layout.setGravity(Gravity.CENTER);
47 | layout.addView(text);
48 |
49 | return layout;
50 | }
51 |
52 | @Override
53 | public void onSaveInstanceState(Bundle outState) {
54 | super.onSaveInstanceState(outState);
55 | outState.putString(KEY_CONTENT, mContent);
56 | }
57 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/lion/demo/material/activity/LPreferenceActivity.java:
--------------------------------------------------------------------------------
1 | package com.lion.demo.material.activity;
2 |
3 | import android.os.Bundle;
4 | import android.view.View;
5 | import android.view.View.OnClickListener;
6 | import android.widget.Toast;
7 |
8 | import com.lion.demo.material.R;
9 | import com.lion.material.widget.PreferenceCheckBox;
10 | import com.lion.material.widget.PreferenceNormal;
11 |
12 |
13 | public class LPreferenceActivity extends BaseActivity implements
14 | OnClickListener {
15 | private PreferenceCheckBox mPreferenceCheckBox;
16 | private PreferenceNormal mPreferenceNormal;
17 |
18 | @Override
19 | protected void onCreate(Bundle savedInstanceState) {
20 | super.onCreate(savedInstanceState);
21 | setContentView(R.layout.activity_lpreference);
22 | initView();
23 | }
24 |
25 | private void initView() {
26 | findViewById(R.id.header_left).setOnClickListener(this);
27 | mPreferenceCheckBox = (PreferenceCheckBox) findViewById(R.id.lpreference_checkbox);
28 | mPreferenceCheckBox
29 | .setOnCheckedChangeListener(new PreferenceCheckBox.OnLPreferenceSwitchListener() {
30 |
31 | @Override
32 | public void onLCheckedChanged(View v, boolean isChecked) {
33 | // Toast.makeText(mContext, "checked-->" + isChecked,
34 | // Toast.LENGTH_SHORT).show();
35 | mPreferenceCheckBox.setSummary("status:" + isChecked);
36 | }
37 | });
38 | mPreferenceNormal = (PreferenceNormal) findViewById(R.id.lpreference_normal);
39 | mPreferenceNormal.setOnClickListener(this);
40 | }
41 |
42 | @Override
43 | public void onClick(View v) {
44 | switch (v.getId()) {
45 | case R.id.header_left:
46 | finish();
47 | break;
48 | case R.id.lpreference_normal:
49 | Toast.makeText(mContext, R.string.lpreference_toast_normal_click,
50 | Toast.LENGTH_SHORT).show();
51 | break;
52 | default:
53 | break;
54 | }
55 | }
56 |
57 | }
58 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_ltab.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
14 |
15 |
23 |
24 |
30 |
31 |
32 |
37 |
38 |
41 |
42 |
46 |
47 |
51 |
52 |
53 |
--------------------------------------------------------------------------------
/app/src/main/java/com/lion/demo/material/activity/LImageButtonActivity.java:
--------------------------------------------------------------------------------
1 | package com.lion.demo.material.activity;
2 |
3 | import android.os.Bundle;
4 | import android.view.View;
5 | import android.view.View.OnClickListener;
6 | import android.widget.ImageButton;
7 | import android.widget.Toast;
8 |
9 | import com.lion.demo.material.R;
10 | import com.lion.material.widget.LImageButton;
11 |
12 | public class LImageButtonActivity extends BaseActivity implements
13 | OnClickListener {
14 | private ImageButton imageButton1;
15 | private LImageButton imageButton2;
16 | private LImageButton imageButton3;
17 | private LImageButton imageButton4;
18 |
19 | // private Random mRandom = new Random();
20 | // private int[] randomColor = new int[] { 0x1d000000, 0x1d00ff00,
21 | // 0xff00ffff,
22 | // 0xffffff00, 0x1dff0000 };
23 |
24 | @Override
25 | protected void onCreate(Bundle savedInstanceState) {
26 | super.onCreate(savedInstanceState);
27 | setContentView(R.layout.activity_limagebutton);
28 | initView();
29 | }
30 |
31 | private void initView() {
32 | findViewById(R.id.header_left).setOnClickListener(this);
33 | imageButton1 = (ImageButton) findViewById(R.id.imagebutton1);
34 | imageButton2 = (LImageButton) findViewById(R.id.imagebutton2);
35 | imageButton3 = (LImageButton) findViewById(R.id.imagebutton3);
36 | imageButton4 = (LImageButton) findViewById(R.id.imagebutton4);
37 | imageButton1.setOnClickListener(this);
38 | imageButton2.setOnClickListener(this);
39 | imageButton3.setOnClickListener(this);
40 | imageButton4.setOnClickListener(this);
41 | }
42 |
43 | @Override
44 | public void onClick(View v) {
45 | switch (v.getId()) {
46 | case R.id.header_left:
47 | finish();
48 | break;
49 | case R.id.imagebutton1:
50 | Toast.makeText(mContext, R.string.limagebutton_toast_system_button,
51 | Toast.LENGTH_SHORT).show();
52 | break;
53 | case R.id.imagebutton2:
54 | case R.id.imagebutton3:
55 | case R.id.imagebutton4:
56 | // if (v instanceof LImageButton) {
57 | // ((LImageButton) v).setColor(randomColor[mRandom
58 | // .nextInt(randomColor.length)]);
59 | // }
60 | break;
61 | default:
62 | break;
63 | }
64 | }
65 |
66 | }
67 |
--------------------------------------------------------------------------------
/app/src/main/java/com/lion/demo/material/activity/LButtonActivity.java:
--------------------------------------------------------------------------------
1 | package com.lion.demo.material.activity;
2 |
3 | import android.os.Bundle;
4 | import android.view.View;
5 | import android.view.View.OnClickListener;
6 | import android.widget.Button;
7 | import android.widget.Toast;
8 |
9 | import com.lion.demo.material.R;
10 | import com.lion.material.widget.LButton;
11 |
12 | import java.util.Random;
13 |
14 |
15 | public class LButtonActivity extends BaseActivity implements OnClickListener {
16 | private Button button1;
17 | private LButton button2;
18 | private LButton button3;
19 | private LButton button4;
20 |
21 | private Random mRandom = new Random();
22 | private int[] randomColor = new int[] { 0x1d000000, 0x1d00ff00, 0xff00ffff,
23 | 0xffffff00, 0x1dff0000 };
24 |
25 | @Override
26 | protected void onCreate(Bundle savedInstanceState) {
27 | super.onCreate(savedInstanceState);
28 | setContentView(R.layout.activity_lbutton);
29 |
30 | initView();
31 | }
32 |
33 | private void initView() {
34 | findViewById(R.id.header_left).setOnClickListener(this);
35 | button1 = (Button) findViewById(R.id.button1);
36 | button2 = (LButton) findViewById(R.id.button2);
37 | button3 = (LButton) findViewById(R.id.button3);
38 | button4 = (LButton) findViewById(R.id.button4);
39 | button1.setOnClickListener(this);
40 | button2.setOnClickListener(this);
41 | button3.setOnClickListener(this);
42 | button4.setOnClickListener(this);
43 | }
44 |
45 | @Override
46 | public void onClick(View v) {
47 | switch (v.getId()) {
48 | case R.id.header_left:
49 | finish();
50 | break;
51 | case R.id.button1:
52 | Toast.makeText(mContext, R.string.lbutton_toast_system_button,
53 | Toast.LENGTH_SHORT).show();
54 | break;
55 | case R.id.button2:
56 | case R.id.button3:
57 | button2.setEnabled(!button2.isEnabled());
58 | button2.setText(button2.isEnabled() ? R.string.lbutton_enabled
59 | : R.string.lbutton_disabled);
60 | break;
61 | case R.id.button4:
62 | if (v instanceof LButton) {
63 | int fullColor = randomColor[mRandom.nextInt(randomColor.length)];
64 | ((LButton) v).setColor(fullColor);
65 | }
66 | break;
67 | default:
68 | break;
69 | }
70 | }
71 |
72 | }
73 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | MaterialWidget
2 | ==============
3 |
4 | Materical style widget use before Android 5.0
5 |
6 | MaterialWidget is a library to provide Android5.0 Material style widget, you can use this library in sdk>=10.(actually, it should be support sdk<10, if you need,you can change the minSdkVersion to try!)
7 |
8 | This library provide some android widget but not all of them.Don't worry, you can wirte other you need widget like LButton, it's so easy!
9 |
10 | Developed By
11 | ==============
12 | Lion - cshxql@gmail.com
13 |
14 | Preview
15 | ==============
16 | 
17 | 
18 | 
19 |
20 |
21 | Usage
22 | ==============
23 | * 1.Include library
24 |
25 | * 2.Add namespace into your xml which use MaterialWidget.
xmlns:material="http://schemas.android.com/apk/res-auto"
26 |
27 | * 3.Add widget in xml:
28 | ```
29 |
40 |
41 | material:widget_type---some type ,you can see use in demo. default is normal.
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 | material:widget_background---no explain(default is null)
50 | material:widget_animColor---the animation color, you can try it!
51 | ```
52 |
53 | * 4.add code in Java:
`same as system widget because every Material widget is extends system widget!`
54 | ```java
55 | findViewById(R.id.header_left).setOnClickListener(this);
56 |
57 | @Override
58 | public void onClick(View v) {
59 | switch (v.getId()) {
60 | case R.id.header_left:
61 | finish();
62 | break;
63 | default:
64 | break;
65 | }
66 | }
67 | ```
68 |
69 | Known bug
70 | ==============
71 | * 1.Singleline has some bug but i don't know why, if you find this bug reason please tell me,TKS!
72 | * please use maxLine="1" instead of singleLine="true"
73 |
74 |
75 |
--------------------------------------------------------------------------------
/material/src/main/java/com/lion/material/widget/PreferenceNormal.java:
--------------------------------------------------------------------------------
1 | package com.lion.material.widget;
2 |
3 | import android.content.Context;
4 | import android.content.res.TypedArray;
5 | import android.graphics.drawable.Drawable;
6 | import android.text.TextUtils;
7 | import android.util.AttributeSet;
8 | import android.view.View;
9 | import android.widget.TextView;
10 |
11 | import com.lion.material.R;
12 |
13 | public class PreferenceNormal extends LFrameLayout {
14 | private final String TAG = "PreferenceNormal";
15 | private Context mContext;
16 | private TextView mTitleTextView;
17 | private TextView mSummaryTextView;
18 | private View mDividerView;
19 |
20 | public PreferenceNormal(Context context, AttributeSet attrs) {
21 | super(context, attrs);
22 | mContext = context;
23 | initView();
24 | TypedArray a = context.obtainStyledAttributes(attrs,
25 | R.styleable.PreferenceStyle);
26 | mTitleTextView.setText(a
27 | .getString(R.styleable.PreferenceStyle_preference_title));
28 | String summary = a
29 | .getString(R.styleable.PreferenceStyle_preference_summary);
30 | mSummaryTextView.setVisibility(TextUtils.isEmpty(summary) ? View.GONE
31 | : View.VISIBLE);
32 | mSummaryTextView.setText(summary);
33 | mDividerView
34 | .setVisibility(a.getBoolean(
35 | R.styleable.PreferenceStyle_preference_show_divider,
36 | true) ? View.VISIBLE : View.GONE);
37 | a.recycle();
38 | }
39 |
40 | private void initView() {
41 | View.inflate(mContext, R.layout.preference_normal, this);
42 | mTitleTextView = (TextView) findViewById(R.id.preference_title);
43 | mSummaryTextView = (TextView) findViewById(R.id.preference_summary);
44 | mDividerView = findViewById(R.id.preference_divider);
45 | }
46 |
47 | @Override
48 | public void setEnabled(boolean enabled) {
49 | super.setEnabled(enabled);
50 | mTitleTextView.setEnabled(enabled);
51 | mSummaryTextView.setEnabled(enabled);
52 | }
53 |
54 | public void setSummary(int resId) {
55 | setSummary(mContext.getString(resId));
56 | }
57 |
58 | public void setSummary(String summary) {
59 | mSummaryTextView.setVisibility(TextUtils.isEmpty(summary) ? View.GONE
60 | : View.VISIBLE);
61 | mSummaryTextView.setText(summary);
62 | }
63 |
64 | /**
65 | * 设置title右边的图片
66 | *
67 | * @param drawable
68 | */
69 | public void setTitleRightDrawable(Drawable drawable) {
70 | mTitleTextView.setCompoundDrawablesWithIntrinsicBounds(null, null, drawable, null);
71 | }
72 |
73 | public void setTitleDrawablePadding(int padding) {
74 | mTitleTextView.setCompoundDrawablePadding(padding);
75 | }
76 |
77 | }
78 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | MaterialDemo
5 | Hello world!
6 | Settings
7 |
8 |
9 | Material Style
10 | Setting
11 |
12 |
13 | Back
14 | Material Button
15 | This is a long menu
16 | System style
17 | Enabled
18 | Disabled
19 | With background color
20 | Change color dynamically
21 | This is a tall button!
22 | This is system style Button!
23 |
24 |
25 | Material ImageButton
26 | This is system style ImageButton!
27 |
28 |
29 | Material FrameLayout
30 | This is system style FrameLayout!
31 |
32 |
33 | Material Preference
34 | Checkbox
35 | status:true
36 | Normal
37 | this is normal!
38 | Click preference item!
39 |
40 |
41 | Material Drawer
42 | MenuItem One
43 | MenuItem Two
44 | MenuItem Three
45 | MenuItem Four
46 | This is right DrawerLayout
47 |
48 | Material Dialog
49 | System Dialog
50 | Normal Dialog
51 | Normal Dialog width long message
52 | List Dialog
53 | Single choice Dialog
54 |
55 | Material TabIndicator
56 |
57 |
58 |
--------------------------------------------------------------------------------
/material/src/main/res/layout/preference_normal.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
14 |
15 |
20 |
21 |
27 |
28 |
36 |
37 |
42 |
43 |
53 |
54 |
55 |
56 |
66 |
67 |
68 |
69 |
--------------------------------------------------------------------------------
/app/src/main/java/com/lion/demo/material/activity/LFrameLayoutActivity.java:
--------------------------------------------------------------------------------
1 | package com.lion.demo.material.activity;
2 |
3 | import android.os.Bundle;
4 | import android.view.View;
5 | import android.view.View.OnClickListener;
6 | import android.widget.FrameLayout;
7 | import android.widget.ImageView;
8 | import android.widget.Toast;
9 |
10 | import com.lion.demo.material.R;
11 | import com.lion.material.widget.LFrameLayout;
12 |
13 | import java.util.Random;
14 |
15 |
16 | public class LFrameLayoutActivity extends BaseActivity implements
17 | OnClickListener {
18 | private FrameLayout mFrameLayout1;
19 | private LFrameLayout mFrameLayout2;
20 | private LFrameLayout mFrameLayout3;
21 | private LFrameLayout mFrameLayout4;
22 | private LFrameLayout mHeaderFrameLayout;
23 |
24 | private ImageView mPauseImageView;
25 | private ImageView mPlayImageView;
26 |
27 | private Random mRandom = new Random();
28 | private int[] randomColor = new int[] { 0x1d000000, 0x1d00ff00, 0xff00ffff,
29 | 0xffffff00, 0x1dff0000 };
30 |
31 | private boolean isPlaying = false;
32 |
33 | @Override
34 | protected void onCreate(Bundle savedInstanceState) {
35 | super.onCreate(savedInstanceState);
36 | setContentView(R.layout.activity_lframelayout);
37 | initView();
38 | }
39 |
40 | private void initView() {
41 | findViewById(R.id.header_left).setOnClickListener(this);
42 | mHeaderFrameLayout = (LFrameLayout) findViewById(R.id.header_framelayout);
43 | mFrameLayout1 = (FrameLayout) findViewById(R.id.framelayout1);
44 | mFrameLayout2 = (LFrameLayout) findViewById(R.id.framelayout2);
45 | mFrameLayout3 = (LFrameLayout) findViewById(R.id.framelayout3);
46 | mFrameLayout4 = (LFrameLayout) findViewById(R.id.framelayout4);
47 | mHeaderFrameLayout.setOnClickListener(this);
48 | mFrameLayout1.setOnClickListener(this);
49 | mFrameLayout2.setOnClickListener(this);
50 | mFrameLayout3.setOnClickListener(this);
51 | mFrameLayout4.setOnClickListener(this);
52 |
53 | mPauseImageView = (ImageView) findViewById(R.id.header_pause);
54 | mPlayImageView = (ImageView) findViewById(R.id.header_play);
55 |
56 | }
57 |
58 | @Override
59 | public void onClick(View v) {
60 | switch (v.getId()) {
61 | case R.id.header_left:
62 | finish();
63 | break;
64 | case R.id.framelayout1:
65 | Toast.makeText(mContext, R.string.lframelayout_toast_system_button,
66 | Toast.LENGTH_SHORT).show();
67 | break;
68 | case R.id.framelayout2:
69 | break;
70 | case R.id.framelayout3:
71 | break;
72 | case R.id.framelayout4:
73 | if (v instanceof LFrameLayout) {
74 | ((LFrameLayout) v).setColor(randomColor[mRandom
75 | .nextInt(randomColor.length)]);
76 | }
77 | break;
78 | case R.id.header_framelayout:
79 | isPlaying = !isPlaying;
80 | mPauseImageView.setVisibility(isPlaying ? View.VISIBLE : View.GONE);
81 | mPlayImageView.setVisibility(isPlaying ? View.GONE : View.VISIBLE);
82 | break;
83 | default:
84 | break;
85 | }
86 | }
87 |
88 | }
89 |
--------------------------------------------------------------------------------
/material/src/main/res/layout/preference_checkbox.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
14 |
15 |
20 |
21 |
27 |
28 |
36 |
37 |
43 |
44 |
53 |
54 |
55 |
56 |
66 |
67 |
68 |
77 |
78 |
79 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_lpreference.xml:
--------------------------------------------------------------------------------
1 |
7 |
8 |
14 |
15 |
25 |
26 |
32 |
33 |
37 |
38 |
39 |
42 |
43 |
48 |
49 |
57 |
58 |
65 |
66 |
70 |
71 |
75 |
76 |
77 |
78 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_ldialog.xml:
--------------------------------------------------------------------------------
1 |
7 |
8 |
14 |
15 |
24 |
25 |
31 |
32 |
33 |
36 |
37 |
41 |
42 |
48 |
54 |
60 |
61 |
67 |
68 |
74 |
75 |
76 |
77 |
78 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_limagebutton.xml:
--------------------------------------------------------------------------------
1 |
7 |
8 |
14 |
15 |
24 |
25 |
31 |
32 |
40 |
41 |
42 |
45 |
46 |
51 |
52 |
58 |
59 |
65 |
66 |
74 |
75 |
81 |
82 |
83 |
84 |
--------------------------------------------------------------------------------
/material/src/main/java/com/lion/material/widget/LDrawerButton.java:
--------------------------------------------------------------------------------
1 | package com.lion.material.widget;
2 |
3 | import android.content.Context;
4 | import android.content.res.TypedArray;
5 | import android.graphics.Canvas;
6 | import android.graphics.Paint;
7 | import android.util.AttributeSet;
8 |
9 | import com.lion.material.R;
10 | import com.lion.material.extra.MaterialStyle;
11 |
12 | public class LDrawerButton extends LButton {
13 | private final String TAG = "LDrawerButton";
14 |
15 | private Paint mLinePaint = new Paint();
16 | private int mCenterX;
17 | private int mCenterY;
18 | private int mStrokeWidth;
19 | private int mLineSplit;// split between line
20 | private int mLineHalfWidth;// Half width of line
21 | private int mSplitHalfHeight;// Half height of line
22 | private int mLineLeftBase;// Left base pointX of line
23 | private int mLineRightBase;// Right base pointX of line
24 | private int mLine1TopBase;// line1 base pointY
25 | private int mLine2TopBase;// line2 base pointY
26 | private int mLine3TopBase;// line3 base pointY
27 | private float mLineLeftOffset;
28 |
29 | private float mLeftOffsetY;
30 | private float mRightOffsetY;
31 | private int mCurrentDegrees = 0;
32 | private boolean mIsLeftGravity = true;
33 | private int mBaseDegrees = 0;
34 |
35 | public LDrawerButton(Context context, AttributeSet attrs) {
36 | super(context, attrs);
37 | mLinePaint.setColor(0xffffffff);
38 | if (attrs != null) {
39 | TypedArray a = context.obtainStyledAttributes(attrs,
40 | R.styleable.LButtonStyle);
41 | mIsLeftGravity = a.getInt(R.styleable.LButtonStyle_widget_type,
42 | MaterialStyle.TYPE_HEADBAR_BACK_BTN) != MaterialStyle.TYPE_HEADBAR_RIGHT_BTN;
43 | setDelayClick(a.getBoolean(
44 | R.styleable.LButtonStyle_widget_delayclick, false));
45 | mBaseDegrees = mIsLeftGravity ? 0 : 180;
46 | a.recycle();
47 |
48 | }
49 | }
50 |
51 | private void initDrawer() {
52 | if (getWidth() == 0 || getHeight() == 0)
53 | return;
54 | mCenterX = getWidth() / 2;
55 | mCenterY = getHeight() / 2;
56 | mStrokeWidth = getHeight() / 35;
57 | mLinePaint.setStrokeWidth(mStrokeWidth);
58 | mLineSplit = mStrokeWidth * 3;// getHeight() / 15
59 | mLineHalfWidth = (int) (getHeight() / 4.5f);
60 | mLineLeftBase = mCenterX - mLineHalfWidth;
61 | mLineRightBase = mCenterX + mLineHalfWidth;
62 |
63 | mLine1TopBase = mCenterY - mLineSplit - mStrokeWidth;
64 | mLine2TopBase = mCenterY;
65 | mLine3TopBase = mCenterY + mLineSplit + mStrokeWidth;
66 | mSplitHalfHeight = mLine3TopBase - mLine2TopBase;
67 | }
68 |
69 | @Override
70 | protected void onDraw(Canvas canvas) {
71 | super.onDraw(canvas);
72 | if (mCenterX == 0 || mCenterY == 0) {
73 | initDrawer();
74 | }
75 | canvas.rotate(mCurrentDegrees, mCenterX, mCenterY);
76 |
77 | canvas.drawLine(mLineLeftBase + mLineLeftOffset, mLine1TopBase
78 | - mLeftOffsetY, mLineRightBase, mLine1TopBase + mRightOffsetY,
79 | mLinePaint);
80 | canvas.drawLine(mLineLeftBase + mLineLeftOffset / 3, mLine2TopBase,
81 | mLineRightBase, mLine2TopBase, mLinePaint);
82 | canvas.drawLine(mLineLeftBase + mLineLeftOffset, mLine3TopBase
83 | + mLeftOffsetY, mLineRightBase, mLine3TopBase - mRightOffsetY,
84 | mLinePaint);
85 | }
86 |
87 | public void onDrag(boolean isOpened, float progress) {
88 | if (progress < 0) {
89 | progress = 0;
90 | } else if (progress > 1) {
91 | progress = 1;
92 | }
93 | mLineLeftOffset = (mLineHalfWidth * progress);
94 | mLeftOffsetY = (mSplitHalfHeight / 1.5f * progress);
95 | mRightOffsetY = (mSplitHalfHeight * progress);
96 | float degreesProgress = isOpened ? (1 - progress) : progress;
97 | mCurrentDegrees = (int) (180 * degreesProgress) + (isOpened ? 180 : 0)
98 | + mBaseDegrees;
99 | invalidate();
100 | }
101 |
102 | }
103 |
--------------------------------------------------------------------------------
/material/src/main/java/com/lion/material/widget/PreferenceCheckBox.java:
--------------------------------------------------------------------------------
1 | package com.lion.material.widget;
2 |
3 |
4 | import android.content.Context;
5 | import android.content.res.TypedArray;
6 | import android.text.TextUtils;
7 | import android.util.AttributeSet;
8 | import android.view.View;
9 | import android.widget.CompoundButton;
10 | import android.widget.CompoundButton.OnCheckedChangeListener;
11 | import android.widget.TextView;
12 |
13 | import com.lion.material.R;
14 |
15 | public class PreferenceCheckBox extends LFrameLayout {
16 | private Context mContext;
17 | private LSwitch mCustomSwitch;
18 | private TextView mTitleTextView;
19 | private TextView mSummaryTextView;
20 | private View mDividerView;
21 |
22 | private OnLPreferenceSwitchListener mListener;
23 |
24 |
25 | public PreferenceCheckBox(Context context, AttributeSet attrs) {
26 | super(context, attrs);
27 | mContext = context;
28 | initView();
29 | TypedArray a = context.obtainStyledAttributes(attrs,
30 | R.styleable.PreferenceStyle);
31 | mTitleTextView.setText(a
32 | .getString(R.styleable.PreferenceStyle_preference_title));
33 | String summary = a
34 | .getString(R.styleable.PreferenceStyle_preference_summary);
35 | mSummaryTextView.setVisibility(TextUtils.isEmpty(summary) ? View.GONE
36 | : View.VISIBLE);
37 | mSummaryTextView.setText(summary);
38 | mCustomSwitch.setChecked(a.getBoolean(
39 | R.styleable.PreferenceStyle_preference_checked, false));
40 | mDividerView
41 | .setVisibility(a.getBoolean(
42 | R.styleable.PreferenceStyle_preference_show_divider,
43 | true) ? View.VISIBLE : View.GONE);
44 | a.recycle();
45 | mCustomSwitch.setOnCheckedChangeListener(new OnCheckedChangeListener() {
46 |
47 | @Override
48 | public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
49 | if (mListener != null) {
50 | mListener.onLCheckedChanged(PreferenceCheckBox.this, isChecked);
51 | }
52 | }
53 | });
54 | }
55 |
56 | private void initView() {
57 | View.inflate(mContext, R.layout.preference_checkbox, this);
58 | mTitleTextView = (TextView) findViewById(R.id.preference_title);
59 | mSummaryTextView = (TextView) findViewById(R.id.preference_summary);
60 | mCustomSwitch = (LSwitch) findViewById(R.id.preference_checkbox);
61 | mDividerView = findViewById(R.id.preference_divider);
62 | }
63 |
64 | @Override
65 | public boolean performClick() {
66 | mCustomSwitch.performClick();
67 | return super.performClick();
68 | }
69 |
70 | public void setOnCheckedChangeListener(OnLPreferenceSwitchListener listener) {
71 | mListener = listener;
72 |
73 | }
74 |
75 | public void setChecked(boolean checked) {
76 | mCustomSwitch.setChecked(checked);
77 | }
78 |
79 | @Override
80 | public void setEnabled(boolean enabled) {
81 | super.setEnabled(enabled);
82 | mCustomSwitch.setEnabled(enabled);
83 | mTitleTextView.setEnabled(enabled);
84 | mSummaryTextView.setEnabled(enabled);
85 | }
86 |
87 | public void setSummary(int resId) {
88 | setSummary(mContext.getString(resId));
89 | }
90 |
91 | public void setSummary(String summary) {
92 | mSummaryTextView.setVisibility(TextUtils.isEmpty(summary) ? View.GONE
93 | : View.VISIBLE);
94 | mSummaryTextView.setText(summary);
95 | }
96 |
97 | /**
98 | * check值改变的回调
99 | */
100 | public interface OnLPreferenceSwitchListener {
101 | void onLCheckedChanged(View v, boolean isChecked);
102 | }
103 |
104 | }
105 |
--------------------------------------------------------------------------------
/material/src/main/java/com/lion/material/widget/LButton.java:
--------------------------------------------------------------------------------
1 | package com.lion.material.widget;
2 |
3 | import android.annotation.SuppressLint;
4 | import android.content.Context;
5 | import android.graphics.Canvas;
6 | import android.graphics.drawable.Drawable;
7 | import android.util.AttributeSet;
8 | import android.view.MotionEvent;
9 | import android.view.View;
10 | import android.widget.Button;
11 |
12 | import com.lion.material.extra.IMaterial;
13 | import com.lion.material.extra.MaterialStyle;
14 |
15 | public class LButton extends Button implements IMaterial {
16 | private MaterialStyle mMaterialStyle;
17 |
18 | public LButton(Context context) {
19 | this(context, null);
20 | }
21 |
22 | public LButton(Context context, AttributeSet attrs) {
23 | super(context, attrs);
24 | mMaterialStyle = new MaterialStyle(this, attrs);
25 | }
26 |
27 | public void perfirmSuperClick() {
28 | super.performClick();
29 | }
30 |
31 | public void setColor(int fullColor) {
32 | mMaterialStyle.setColor(fullColor);
33 | }
34 |
35 | public void setType(int widgetType) {
36 | mMaterialStyle.setType(widgetType);
37 | }
38 |
39 | @Override
40 | protected void onDraw(Canvas canvas) {
41 | if (!isEnabled()) {
42 | canvas.drawColor(0xffCFCFCF);
43 | super.onDraw(canvas);
44 | return;
45 | }
46 | mMaterialStyle.doDraw(canvas);
47 | super.onDraw(canvas);
48 | }
49 |
50 | @SuppressLint("ClickableViewAccessibility")
51 | @Override
52 | public boolean performClick() {
53 | if (mMaterialStyle != null) {
54 | mMaterialStyle.performClick();
55 | } else {
56 | return super.performClick();
57 | }
58 | return true;
59 | }
60 |
61 | @SuppressLint("ClickableViewAccessibility")
62 | @Override
63 | public boolean onTouchEvent(MotionEvent event) {
64 | if (mMaterialStyle != null)
65 | mMaterialStyle.onTouchEvent(event);
66 | return super.onTouchEvent(event);
67 | }
68 |
69 | @Override
70 | public void onWindowFocusChanged(boolean hasWindowFocus) {
71 | super.onWindowFocusChanged(hasWindowFocus);
72 | if (mMaterialStyle != null)
73 | mMaterialStyle.onWindowFocusChanged(hasWindowFocus);
74 | }
75 |
76 | @Override
77 | protected void onVisibilityChanged(View changedView, int visibility) {
78 | super.onVisibilityChanged(changedView, visibility);
79 | if (mMaterialStyle != null)
80 | mMaterialStyle.onVisibilityChanged(changedView, visibility);
81 | }
82 |
83 | /**
84 | * set click event delay to animation end
85 | *
86 | * @param delayClick
87 | */
88 | public void setDelayClick(boolean delayClick) {
89 | mMaterialStyle.setDelayClick(delayClick);
90 | }
91 |
92 | @Override
93 | public void setBackgroundResource(int resId) {
94 | setBackground(this.getResources().getDrawable(resId));
95 | }
96 |
97 | @Override
98 | public void setBackground(Drawable background) {
99 | if (mMaterialStyle != null)
100 | mMaterialStyle.setBackground(background);
101 | }
102 |
103 | @Override
104 | public void setBackgroundColor(int color) {
105 | if (mMaterialStyle != null)
106 | mMaterialStyle.setBackgroundColor(color);
107 | }
108 |
109 | @Override
110 | @Deprecated
111 | public void setBackgroundDrawable(Drawable background) {
112 | // super.setBackgroundDrawable(background);
113 | this.setBackground(background);
114 | }
115 |
116 | @Override
117 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
118 | if (mMaterialStyle != null) {
119 | if (mMaterialStyle.needBackgroundMeasure()) {
120 | int[] size = mMaterialStyle.getMeasureSize(widthMeasureSpec,
121 | heightMeasureSpec);
122 | setMeasuredDimension(size[0], size[1]);
123 | } else {
124 | super.onMeasure(widthMeasureSpec, heightMeasureSpec);
125 | }
126 | } else {
127 | super.onMeasure(widthMeasureSpec, heightMeasureSpec);
128 | }
129 |
130 | }
131 |
132 | @Override
133 | public boolean dispatchTouchEvent(MotionEvent event) {
134 | if (!isEnabled())
135 | return false;
136 | return super.dispatchTouchEvent(event);
137 | }
138 |
139 | }
140 |
--------------------------------------------------------------------------------
/app/src/main/java/com/lion/demo/material/activity/LDialogActivity.java:
--------------------------------------------------------------------------------
1 | package com.lion.demo.material.activity;
2 |
3 | import android.app.AlertDialog;
4 | import android.content.Context;
5 | import android.content.DialogInterface;
6 | import android.os.Bundle;
7 | import android.view.View;
8 | import android.view.View.OnClickListener;
9 | import android.widget.Toast;
10 |
11 | import com.lion.demo.material.R;
12 | import com.lion.material.dialog.LAlertDialog;
13 | import com.lion.material.dialog.LDialogListBuilder;
14 |
15 |
16 | public class LDialogActivity extends BaseActivity implements OnClickListener {
17 | private Context mContext;
18 | private int mSelectedIndex = 0;
19 |
20 | @Override
21 | protected void onCreate(Bundle savedInstanceState) {
22 | super.onCreate(savedInstanceState);
23 | mContext = this;
24 | setContentView(R.layout.activity_ldialog);
25 | initView();
26 | }
27 |
28 | private void initView() {
29 | findViewById(R.id.header_left).setOnClickListener(this);
30 | findViewById(R.id.ldialog_system).setOnClickListener(this);
31 | findViewById(R.id.ldialog_normal).setOnClickListener(this);
32 | findViewById(R.id.ldialog_normal_longmsg).setOnClickListener(this);
33 | findViewById(R.id.ldialog_list).setOnClickListener(this);
34 | findViewById(R.id.ldialog_single_choice).setOnClickListener(this);
35 |
36 | }
37 |
38 | @Override
39 | public void onClick(View v) {
40 | switch (v.getId()) {
41 | case R.id.header_left:
42 | finish();
43 | break;
44 | case R.id.ldialog_system:
45 | showSystemDialog();
46 | break;
47 | case R.id.ldialog_normal:
48 | showNormal(false);
49 | break;
50 | case R.id.ldialog_normal_longmsg:
51 | showNormal(true);
52 | break;
53 | case R.id.ldialog_list:
54 | showSingleList(false);
55 | break;
56 | case R.id.ldialog_single_choice:
57 | showSingleList(true);
58 | break;
59 | default:
60 | break;
61 | }
62 | }
63 |
64 | private void showSystemDialog() {
65 | new AlertDialog.Builder(this).setTitle("This is title")
66 | .setMessage("This is message.").setPositiveButton("OK", null)
67 | .setNegativeButton("Cancel", null).show();
68 | }
69 |
70 | private void showNormal(boolean longMsg) {
71 | String longContent = "1.If you don't make the time to work on creating the life you want, you're eventually going to be forced to spend a lot of time dealing with a life you don't want.\n"
72 | + "2.One needs 3 things to be truly happy living in the world: some thing to do, some one to love, some thing to hope for.\n"
73 | + "3.Slow the pace of your life and give yourself some time for meditating .It's not death that aman should fear ,but he should fear never live truly. \n";
74 | String message = longMsg ? longContent : "This is message.";
75 | new LAlertDialog.Builder(this)
76 | .setTitle("This is title")
77 | .setMessage(message)
78 | .setPositiveButton("OK", new DialogInterface.OnClickListener() {
79 |
80 | @Override
81 | public void onClick(DialogInterface dialog, int which) {
82 | Toast.makeText(mContext, "OK Clicked",
83 | Toast.LENGTH_SHORT).show();
84 | }
85 | })
86 | .setNegativeButton("Cancel",
87 | new DialogInterface.OnClickListener() {
88 |
89 | @Override
90 | public void onClick(DialogInterface dialog,
91 | int which) {
92 | Toast.makeText(mContext, "Cancel Clicked",
93 | Toast.LENGTH_SHORT).show();
94 | }
95 | }).show();
96 | }
97 |
98 | private void showSingleList(boolean chooseMode) {
99 | final String[] items = new String[] { "Item 1", "Item 2", "Item 3" };
100 | new LDialogListBuilder(this, mSelectedIndex, chooseMode)
101 | .setItems(items, new DialogInterface.OnClickListener() {
102 |
103 | @Override
104 | public void onClick(DialogInterface arg0, int position) {
105 | Toast.makeText(mContext, items[position],
106 | Toast.LENGTH_SHORT).show();
107 | mSelectedIndex = position;
108 |
109 | }
110 | }).showCloseButton(true).setTitle("Title").show();
111 | // .show();
112 | }
113 |
114 | }
115 |
--------------------------------------------------------------------------------
/material/src/main/java/com/lion/material/widget/LImageButton.java:
--------------------------------------------------------------------------------
1 | package com.lion.material.widget;
2 |
3 | import android.annotation.SuppressLint;
4 | import android.content.Context;
5 | import android.graphics.Canvas;
6 | import android.graphics.drawable.Drawable;
7 | import android.util.AttributeSet;
8 | import android.view.MotionEvent;
9 | import android.view.View;
10 | import android.widget.ImageView;
11 |
12 | import com.lion.material.extra.IMaterial;
13 | import com.lion.material.extra.MaterialStyle;
14 |
15 | public class LImageButton extends ImageView implements IMaterial {
16 | private MaterialStyle mMaterialStyle;
17 |
18 | public LImageButton(Context context) {
19 | this(context, null);
20 | }
21 |
22 | @SuppressLint("NewApi")
23 | public LImageButton(Context context, AttributeSet attrs) {
24 | super(context, attrs);
25 | mMaterialStyle = new MaterialStyle(this, attrs);
26 | }
27 |
28 | public void perfirmSuperClick() {
29 | super.performClick();
30 | }
31 |
32 | public void setColor(int fullColor) {
33 | mMaterialStyle.setColor(fullColor);
34 | }
35 |
36 | public void setType(int widgetType) {
37 | mMaterialStyle.setType(widgetType);
38 | }
39 |
40 | @Override
41 | protected void onDraw(Canvas canvas) {
42 | if (!isEnabled()) {
43 | super.onDraw(canvas);
44 | return;
45 | }
46 | mMaterialStyle.doDraw(canvas);
47 | super.onDraw(canvas);
48 | }
49 |
50 | @SuppressLint("ClickableViewAccessibility")
51 | @Override
52 | public boolean performClick() {
53 | if (mMaterialStyle != null) {
54 | mMaterialStyle.performClick();
55 | } else {
56 | return super.performClick();
57 | }
58 | return true;
59 | }
60 |
61 | @SuppressLint("ClickableViewAccessibility")
62 | @Override
63 | public boolean onTouchEvent(MotionEvent event) {
64 | if (mMaterialStyle != null)
65 | mMaterialStyle.onTouchEvent(event);
66 | return super.onTouchEvent(event);
67 | }
68 |
69 | @Override
70 | public void onWindowFocusChanged(boolean hasWindowFocus) {
71 | super.onWindowFocusChanged(hasWindowFocus);
72 | if (mMaterialStyle != null)
73 | mMaterialStyle.onWindowFocusChanged(hasWindowFocus);
74 | }
75 |
76 | @Override
77 | protected void onVisibilityChanged(View changedView, int visibility) {
78 | super.onVisibilityChanged(changedView, visibility);
79 | if (mMaterialStyle != null)
80 | mMaterialStyle.onVisibilityChanged(changedView, visibility);
81 | }
82 |
83 | /**
84 | * set click event delay to animation end
85 | *
86 | * @param delayClick
87 | */
88 | public void setDelayClick(boolean delayClick) {
89 | mMaterialStyle.setDelayClick(delayClick);
90 | }
91 |
92 | @Override
93 | public void setBackgroundResource(int resId) {
94 | setBackground(this.getResources().getDrawable(resId));
95 | }
96 |
97 | @Override
98 | public void setBackground(Drawable background) {
99 | if (mMaterialStyle != null)
100 | mMaterialStyle.setBackground(background);
101 | }
102 |
103 | @Override
104 | public void setBackgroundColor(int color) {
105 | if (mMaterialStyle != null)
106 | mMaterialStyle.setBackgroundColor(color);
107 | }
108 |
109 | @Override
110 | @Deprecated
111 | public void setBackgroundDrawable(Drawable background) {
112 | // super.setBackgroundDrawable(background);
113 | this.setBackground(background);
114 | }
115 |
116 | @Override
117 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
118 | if (mMaterialStyle != null) {
119 | if (mMaterialStyle.needBackgroundMeasure()) {
120 | int[] size = mMaterialStyle.getMeasureSize(widthMeasureSpec,
121 | heightMeasureSpec);
122 | setMeasuredDimension(size[0], size[1]);
123 | } else {
124 | super.onMeasure(widthMeasureSpec, heightMeasureSpec);
125 | }
126 | } else {
127 | super.onMeasure(widthMeasureSpec, heightMeasureSpec);
128 | }
129 |
130 | }
131 |
132 | public int mImageResId;
133 |
134 | @Override
135 | public void setImageResource(int resId) {
136 | super.setImageResource(resId);
137 | mImageResId = resId;
138 | }
139 |
140 | @Override
141 | public boolean dispatchTouchEvent(MotionEvent event) {
142 | if (!isEnabled())
143 | return false;
144 | return super.dispatchTouchEvent(event);
145 | }
146 |
147 | }
148 |
--------------------------------------------------------------------------------
/material/src/main/java/com/lion/material/widget/LFrameLayout.java:
--------------------------------------------------------------------------------
1 | package com.lion.material.widget;
2 |
3 | import android.annotation.SuppressLint;
4 | import android.content.Context;
5 | import android.graphics.Canvas;
6 | import android.graphics.drawable.Drawable;
7 | import android.util.AttributeSet;
8 | import android.view.MotionEvent;
9 | import android.view.View;
10 | import android.widget.FrameLayout;
11 |
12 | import com.lion.material.extra.IMaterial;
13 | import com.lion.material.extra.MaterialStyle;
14 |
15 | public class LFrameLayout extends FrameLayout implements IMaterial {
16 | private MaterialStyle mMaterialStyle;
17 |
18 | public LFrameLayout(Context context) {
19 | this(context, null);
20 | }
21 |
22 | @SuppressLint("NewApi")
23 | public LFrameLayout(Context context, AttributeSet attrs) {
24 | super(context, attrs);
25 | mMaterialStyle = new MaterialStyle(this, attrs);
26 | }
27 |
28 | public void perfirmSuperClick() {
29 | super.performClick();
30 | }
31 |
32 | public void setColor(int fullColor) {
33 | mMaterialStyle.setColor(fullColor);
34 | }
35 |
36 | public void setType(int widgetType) {
37 | mMaterialStyle.setType(widgetType);
38 | }
39 |
40 | @Override
41 | protected void onDraw(Canvas canvas) {
42 | if (!isEnabled()) {
43 | super.onDraw(canvas);
44 | return;
45 | }
46 | mMaterialStyle.doDraw(canvas);
47 | super.onDraw(canvas);
48 | }
49 |
50 | @SuppressLint("ClickableViewAccessibility")
51 | @Override
52 | public boolean performClick() {
53 | if (mMaterialStyle != null) {
54 | mMaterialStyle.performClick();
55 | } else {
56 | return super.performClick();
57 | }
58 | return true;
59 | }
60 |
61 | // @Override
62 | // public void setOnClickListener(OnClickListener l) {
63 | // super.setOnClickListener(l);
64 | // if (mMaterialStyle != null) {
65 | // mMaterialStyle.setOnclickListener(l);
66 | // }
67 | // }
68 |
69 | @SuppressLint("ClickableViewAccessibility")
70 | @Override
71 | public boolean onTouchEvent(MotionEvent event) {
72 | //if (mMaterialStyle != null) {
73 | // return mMaterialStyle.onTouchEvent(event) ? super
74 | // .onTouchEvent(event) : false;
75 | //}
76 | if (mMaterialStyle != null)
77 | mMaterialStyle.onTouchEvent(event);
78 | return super.onTouchEvent(event);
79 | }
80 |
81 | @Override
82 | public void onWindowFocusChanged(boolean hasWindowFocus) {
83 | super.onWindowFocusChanged(hasWindowFocus);
84 | if (mMaterialStyle != null)
85 | mMaterialStyle.onWindowFocusChanged(hasWindowFocus);
86 | }
87 |
88 | @Override
89 | protected void onVisibilityChanged(View changedView, int visibility) {
90 | super.onVisibilityChanged(changedView, visibility);
91 | if (mMaterialStyle != null)
92 | mMaterialStyle.onVisibilityChanged(changedView, visibility);
93 | }
94 |
95 | /**
96 | * set click event delay to animation end
97 | *
98 | * @param need
99 | */
100 | public void setDelayClick(boolean delayClick) {
101 | mMaterialStyle.setDelayClick(delayClick);
102 | }
103 |
104 | @Override
105 | public void setBackgroundResource(int resId) {
106 | setBackground(this.getResources().getDrawable(resId));
107 | }
108 |
109 | @Override
110 | public void setBackground(Drawable background) {
111 | if (mMaterialStyle != null)
112 | mMaterialStyle.setBackground(background);
113 | }
114 |
115 | @Override
116 | public void setBackgroundColor(int color) {
117 | if (mMaterialStyle != null)
118 | mMaterialStyle.setBackgroundColor(color);
119 | }
120 |
121 | @Override
122 | @Deprecated
123 | public void setBackgroundDrawable(Drawable background) {
124 | // super.setBackgroundDrawable(background);
125 | this.setBackground(background);
126 | }
127 |
128 | @Override
129 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
130 | if (mMaterialStyle != null) {
131 | if (mMaterialStyle.needBackgroundMeasure()) {
132 | int[] size = mMaterialStyle.getMeasureSize(widthMeasureSpec,
133 | heightMeasureSpec);
134 | setMeasuredDimension(size[0], size[1]);
135 | } else {
136 | super.onMeasure(widthMeasureSpec, heightMeasureSpec);
137 | }
138 | } else {
139 | super.onMeasure(widthMeasureSpec, heightMeasureSpec);
140 | }
141 |
142 | }
143 |
144 | @Override
145 | public boolean dispatchTouchEvent(MotionEvent event) {
146 | if (!isEnabled())
147 | return false;
148 | return super.dispatchTouchEvent(event);
149 | }
150 |
151 | }
152 |
--------------------------------------------------------------------------------
/material/src/main/java/com/lion/material/dialog/LDialogListBuilder.java:
--------------------------------------------------------------------------------
1 | package com.lion.material.dialog;
2 |
3 | import android.content.Context;
4 | import android.content.DialogInterface;
5 | import android.content.DialogInterface.OnClickListener;
6 | import android.view.View;
7 | import android.view.ViewGroup;
8 | import android.widget.BaseAdapter;
9 | import android.widget.ImageView;
10 | import android.widget.ListView;
11 | import android.widget.TextView;
12 |
13 | import com.lion.material.R;
14 | import com.lion.material.dialog.LAlertDialog.Builder;
15 |
16 | public class LDialogListBuilder extends Builder {
17 | private Context mContext;
18 | private ListView mListView;
19 | private OnClickListener mListener;
20 | private LDialogController mController;
21 | private int mSelectedIndex = -1;
22 | private boolean mIsChooseMode;
23 | private ListItemAdapter mAdapter;
24 |
25 | public LDialogListBuilder(Context context, int selectedIndex,
26 | boolean isChooseMode) {
27 | super(context);
28 | this.mContext = context;
29 | View v = View.inflate(mContext, R.layout.material_dialog_listview, null);
30 | mListView = (ListView) v.findViewById(R.id.dialog_listview);
31 | this.setView(v);
32 | this.mSelectedIndex = selectedIndex;
33 | this.mIsChooseMode = isChooseMode;
34 | }
35 |
36 | public Builder setItems(String[] items, OnClickListener listener) {
37 | this.mListener = listener;
38 | mAdapter = new ListItemAdapter(mContext, items, mSelectedIndex,
39 | mIsChooseMode);
40 | mListView.setAdapter(mAdapter);
41 | return this;
42 | }
43 |
44 | public void setSelectedIndex(int index) {
45 | this.mSelectedIndex = index;
46 | if (mAdapter != null) {
47 | mAdapter.setSelectedIndex(index);
48 | }
49 |
50 | }
51 |
52 | /**
53 | * 创建dialog
54 | *
55 | * @return
56 | */
57 | public LAlertDialog create() {
58 | LAlertDialog dialog = super.create();
59 | mController = dialog.getController();
60 | return dialog;
61 | }
62 |
63 | /**
64 | * 创建并显示dialog
65 | *
66 | * @return
67 | */
68 | public LAlertDialog show() {
69 | LAlertDialog dialog = create();
70 | dialog.show();
71 | return dialog;
72 | }
73 |
74 | public class ListItemAdapter extends BaseAdapter {
75 | private Context mContext;
76 | private String[] items;
77 | private int selectedIndex = -1;
78 | private boolean isChooseMode;
79 |
80 | public ListItemAdapter(Context context, String[] items,
81 | int selectedIndex, boolean isChooseMode) {
82 | this.mContext = context;
83 | this.items = items;
84 | this.selectedIndex = selectedIndex;
85 | this.isChooseMode = isChooseMode;
86 | }
87 |
88 | @Override
89 | public int getCount() {
90 | return items.length;
91 | }
92 |
93 | @Override
94 | public Object getItem(int arg0) {
95 | return null;
96 | }
97 |
98 | @Override
99 | public long getItemId(int arg0) {
100 | return 0;
101 | }
102 |
103 | @Override
104 | public View getView(final int position, View convertView, ViewGroup arg2) {
105 |
106 | ViewHolder viewHolder = null;
107 | if (convertView == null) {
108 | viewHolder = new ViewHolder();
109 | convertView = View.inflate(mContext,
110 | R.layout.material_dialog_listview_adapter, null);
111 | viewHolder.mTextView = (TextView) convertView
112 | .findViewById(R.id.dialog_listview_adapter_content);
113 | viewHolder.mIconImageView = (ImageView) convertView
114 | .findViewById(R.id.dialog_listview_adapter_checkbox);
115 | if (isChooseMode) {
116 | viewHolder.mIconImageView.setVisibility(View.VISIBLE);
117 | }
118 | convertView.setTag(viewHolder);
119 | } else {
120 | viewHolder = (ViewHolder) convertView.getTag();
121 | }
122 | viewHolder.mIconImageView.setSelected(selectedIndex == position);
123 | viewHolder.mTextView.setText(items[position]);
124 | convertView.setOnClickListener(new View.OnClickListener() {
125 |
126 | @Override
127 | public void onClick(View arg0) {
128 | if (mListener != null) {
129 | DialogInterface dialogInterface = mController == null ? null
130 | : mController.getDialogInterface();
131 | mListener.onClick(dialogInterface, position);
132 | if (dialogInterface != null) {
133 | dialogInterface.dismiss();
134 | }
135 | }
136 | }
137 | });
138 |
139 | return convertView;
140 | }
141 |
142 | private class ViewHolder {
143 | TextView mTextView;
144 | ImageView mIconImageView;
145 | }
146 |
147 | public void setSelectedIndex(int index) {
148 | this.selectedIndex = index;
149 | notifyDataSetChanged();
150 | }
151 | }
152 |
153 | }
154 |
--------------------------------------------------------------------------------
/material/src/main/java/com/lion/material/widget/LLinearLayout.java:
--------------------------------------------------------------------------------
1 | package com.lion.material.widget;
2 |
3 | import android.annotation.SuppressLint;
4 | import android.content.Context;
5 | import android.graphics.Canvas;
6 | import android.graphics.drawable.Drawable;
7 | import android.util.AttributeSet;
8 | import android.view.MotionEvent;
9 | import android.view.View;
10 | import android.widget.LinearLayout;
11 |
12 | import com.lion.material.extra.IMaterial;
13 | import com.lion.material.extra.MaterialStyle;
14 |
15 | public class LLinearLayout extends LinearLayout implements IMaterial {
16 | private MaterialStyle mMaterialStyle;
17 |
18 | public LLinearLayout(Context context) {
19 | this(context, null);
20 | }
21 |
22 | public LLinearLayout(Context context, AttributeSet attrs) {
23 | super(context, attrs);
24 | mMaterialStyle = new MaterialStyle(this, attrs);
25 | }
26 |
27 | public void perfirmSuperClick() {
28 | super.performClick();
29 | }
30 |
31 | public void setColor(int fullColor) {
32 | mMaterialStyle.setColor(fullColor);
33 | }
34 |
35 | public void setType(int widgetType) {
36 | mMaterialStyle.setType(widgetType);
37 | }
38 |
39 | @Override
40 | protected void onDraw(Canvas canvas) {
41 | if (!isEnabled()) {
42 | super.onDraw(canvas);
43 | return;
44 | }
45 | mMaterialStyle.doDraw(canvas);
46 | super.onDraw(canvas);
47 | }
48 |
49 | @SuppressLint("ClickableViewAccessibility")
50 | @Override
51 | public boolean performClick() {
52 | if (mMaterialStyle != null) {
53 | mMaterialStyle.performClick();
54 | } else {
55 | return super.performClick();
56 | }
57 | return true;
58 | }
59 |
60 | // @Override
61 | //public void setOnClickListener(OnClickListener l) {
62 | // super.setOnClickListener(l);
63 | // if (mMaterialStyle != null) {
64 | // mMaterialStyle.setOnclickListener(l);
65 | // }
66 | // }
67 |
68 | @SuppressLint("ClickableViewAccessibility")
69 | @Override
70 | public boolean onTouchEvent(MotionEvent event) {
71 | // if (mMaterialStyle != null) {
72 | // return mMaterialStyle.onTouchEvent(event) ? super
73 | // .onTouchEvent(event) : false;
74 | // }
75 | if (mMaterialStyle != null)
76 | mMaterialStyle.onTouchEvent(event);
77 | return super.onTouchEvent(event);
78 | }
79 |
80 | @Override
81 | public void onWindowFocusChanged(boolean hasWindowFocus) {
82 | super.onWindowFocusChanged(hasWindowFocus);
83 | if (mMaterialStyle != null)
84 | mMaterialStyle.onWindowFocusChanged(hasWindowFocus);
85 | }
86 |
87 | @Override
88 | protected void onVisibilityChanged(View changedView, int visibility) {
89 | super.onVisibilityChanged(changedView, visibility);
90 | if (mMaterialStyle != null)
91 | mMaterialStyle.onVisibilityChanged(changedView, visibility);
92 | }
93 |
94 | /**
95 | * set click event delay to animation end
96 | *
97 | * @param delayClick
98 | */
99 | public void setDelayClick(boolean delayClick) {
100 | mMaterialStyle.setDelayClick(delayClick);
101 | }
102 |
103 | @Override
104 | public void setBackgroundResource(int resId) {
105 | setBackground(this.getResources().getDrawable(resId));
106 | }
107 |
108 | @Override
109 | public void setBackground(Drawable background) {
110 | if (mMaterialStyle != null)
111 | mMaterialStyle.setBackground(background);
112 | }
113 |
114 | @Override
115 | public void setBackgroundColor(int color) {
116 | if (mMaterialStyle != null)
117 | mMaterialStyle.setBackgroundColor(color);
118 | }
119 |
120 | @Override
121 | @Deprecated
122 | public void setBackgroundDrawable(Drawable background) {
123 | // super.setBackgroundDrawable(background);
124 | this.setBackground(background);
125 | }
126 |
127 | @Override
128 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
129 | if (mMaterialStyle != null) {
130 | if (mMaterialStyle.needBackgroundMeasure()) {
131 | int[] size = mMaterialStyle.getMeasureSize(widthMeasureSpec,
132 | heightMeasureSpec);
133 | setMeasuredDimension(size[0], size[1]);
134 | } else {
135 | super.onMeasure(widthMeasureSpec, heightMeasureSpec);
136 | }
137 | } else {
138 | super.onMeasure(widthMeasureSpec, heightMeasureSpec);
139 | }
140 |
141 | }
142 |
143 | @Override
144 | public boolean dispatchTouchEvent(MotionEvent event) {
145 | if (!isEnabled())
146 | return false;
147 | return super.dispatchTouchEvent(event);
148 | }
149 |
150 | }
151 |
--------------------------------------------------------------------------------
/app/src/main/java/com/lion/demo/material/activity/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.lion.demo.material.activity;
2 |
3 | import android.content.Intent;
4 | import android.net.Uri;
5 | import android.os.Bundle;
6 | import android.support.v4.widget.DrawerLayout;
7 | import android.support.v4.widget.DrawerLayout.DrawerListener;
8 | import android.view.Gravity;
9 | import android.view.View;
10 | import android.view.View.OnClickListener;
11 |
12 | import com.lion.demo.material.R;
13 | import com.lion.material.widget.LDrawerButton;
14 |
15 | public class MainActivity extends BaseActivity implements OnClickListener {
16 | private String TAG = "MainActivity";
17 | private DrawerLayout mDrawerLayout;
18 | private View mLeftGravityView;
19 | private LDrawerButton drawerButtonLeft;
20 | private LDrawerButton drawerButtonRight;
21 |
22 | @Override
23 | protected void onCreate(Bundle savedInstanceState) {
24 | super.onCreate(savedInstanceState);
25 | setContentView(R.layout.activity_main);
26 | initView();
27 | }
28 |
29 | private void initView() {
30 | mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
31 | // init left headerButton
32 | drawerButtonLeft = (LDrawerButton) findViewById(R.id.header_left);
33 | drawerButtonLeft.setOnClickListener(this);
34 | // init right headerButton
35 | drawerButtonRight = (LDrawerButton) findViewById(R.id.header_right);
36 | drawerButtonRight.setOnClickListener(this);
37 | mLeftGravityView = findViewById(R.id.main_menu_left);
38 | findViewById(R.id.main_add).setOnClickListener(this);
39 | findViewById(R.id.main_item_lbutton).setOnClickListener(this);
40 | findViewById(R.id.main_item_limagebutton).setOnClickListener(this);
41 | findViewById(R.id.main_item_lframelayout).setOnClickListener(this);
42 | findViewById(R.id.main_item_lpreference).setOnClickListener(this);
43 | findViewById(R.id.main_item_ldialog).setOnClickListener(this);
44 | findViewById(R.id.main_item_ltab).setOnClickListener(this);
45 |
46 | mDrawerLayout.setDrawerListener(new DrawerListener() {
47 |
48 | @Override
49 | public void onDrawerStateChanged(int drawerStatus) {
50 | }
51 |
52 | @Override
53 | public void onDrawerSlide(View v, float progress) {
54 | if (v == mLeftGravityView) {
55 | drawerButtonLeft.onDrag(
56 | mDrawerLayout.isDrawerOpen(Gravity.LEFT), progress);
57 | } else {
58 | drawerButtonRight.onDrag(
59 | mDrawerLayout.isDrawerOpen(Gravity.RIGHT), progress);
60 | }
61 |
62 | }
63 |
64 | @Override
65 | public void onDrawerOpened(View v) {
66 | }
67 |
68 | @Override
69 | public void onDrawerClosed(View v) {
70 | }
71 | });
72 | }
73 |
74 | @Override
75 | public void onClick(View v) {
76 | switch (v.getId()) {
77 | case R.id.main_add:
78 | case R.id.header_left:
79 | if (mDrawerLayout.isDrawerOpen(Gravity.RIGHT)) {
80 | mDrawerLayout.closeDrawer(Gravity.RIGHT);
81 | }
82 | if (mDrawerLayout.isDrawerOpen(Gravity.LEFT)) {
83 | mDrawerLayout.closeDrawer(Gravity.LEFT);
84 | } else {
85 | mDrawerLayout.openDrawer(Gravity.LEFT);
86 | }
87 | break;
88 | case R.id.header_right:
89 | if (mDrawerLayout.isDrawerOpen(Gravity.LEFT)) {
90 | mDrawerLayout.closeDrawer(Gravity.LEFT);
91 | }
92 | if (mDrawerLayout.isDrawerOpen(Gravity.RIGHT)) {
93 | mDrawerLayout.closeDrawer(Gravity.RIGHT);
94 | } else {
95 | mDrawerLayout.openDrawer(Gravity.RIGHT);
96 | }
97 | break;
98 | case R.id.main_item_lbutton:
99 | startActivity(new Intent(mContext, LButtonActivity.class));
100 | break;
101 | case R.id.main_item_limagebutton:
102 | startActivity(new Intent(mContext, LImageButtonActivity.class));
103 | break;
104 | case R.id.main_item_lframelayout:
105 | startActivity(new Intent(mContext, LFrameLayoutActivity.class));
106 | break;
107 | case R.id.main_item_lpreference:
108 | startActivity(new Intent(mContext, LPreferenceActivity.class));
109 | break;
110 | case R.id.main_item_ldialog:
111 | startActivity(new Intent(mContext, LDialogActivity.class));
112 | break;
113 | case R.id.main_item_ltab:
114 | startActivity(new Intent(mContext, LTabActivity.class));
115 | break;
116 | default:
117 | break;
118 | }
119 | }
120 | }
121 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_lbutton.xml:
--------------------------------------------------------------------------------
1 |
7 |
8 |
14 |
15 |
24 |
25 |
31 |
32 |
44 |
45 |
46 |
49 |
50 |
55 |
56 |
65 |
66 |
78 |
79 |
86 |
87 |
96 |
97 |
107 |
108 |
116 |
117 |
118 |
119 |
--------------------------------------------------------------------------------
/material/src/main/res/layout/material_alert_dialog.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
14 |
15 |
23 |
24 |
30 |
31 |
41 |
42 |
51 |
52 |
53 |
54 |
59 |
60 |
65 |
66 |
73 |
74 |
81 |
82 |
83 |
87 |
88 |
89 |
99 |
100 |
112 |
113 |
117 |
118 |
130 |
131 |
132 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_lframelayout.xml:
--------------------------------------------------------------------------------
1 |
7 |
8 |
14 |
15 |
24 |
25 |
31 |
32 |
40 |
41 |
48 |
49 |
55 |
56 |
57 |
58 |
61 |
62 |
66 |
67 |
72 |
73 |
80 |
81 |
86 |
87 |
88 |
92 |
93 |
99 |
100 |
107 |
108 |
113 |
114 |
115 |
119 |
120 |
127 |
128 |
136 |
137 |
142 |
143 |
144 |
148 |
149 |
155 |
156 |
163 |
164 |
169 |
170 |
171 |
172 |
173 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
7 |
8 |
14 |
15 |
25 |
26 |
32 |
33 |
43 |
44 |
45 |
49 |
50 |
53 |
54 |
57 |
58 |
62 |
63 |
69 |
70 |
76 |
77 |
83 |
84 |
90 |
91 |
97 |
98 |
104 |
105 |
106 |
107 |
116 |
117 |
118 |
125 |
126 |
131 |
132 |
137 |
138 |
143 |
144 |
149 |
150 |
151 |
158 |
159 |
165 |
166 |
167 |
168 |
--------------------------------------------------------------------------------
/material/src/main/java/com/lion/material/dialog/LAlertDialog.java:
--------------------------------------------------------------------------------
1 | package com.lion.material.dialog;
2 |
3 | import android.app.Dialog;
4 | import android.content.Context;
5 | import android.content.DialogInterface;
6 | import android.graphics.drawable.Drawable;
7 | import android.os.Bundle;
8 | import android.view.View;
9 |
10 | import com.lion.material.R;
11 |
12 | public class LAlertDialog extends Dialog implements DialogInterface {
13 |
14 | public interface VisibleCallback {
15 | public void onclick();
16 | }
17 |
18 | private LDialogController control;
19 | private static final int default_theme = 0;
20 |
21 | // private static final int default_theme = R.style.customDialogStyle;
22 |
23 | protected LAlertDialog(Context context) {
24 | this(context, default_theme);
25 | this.getWindow().setBackgroundDrawableResource(
26 | R.drawable.material_dialog_bg);
27 | }
28 |
29 | protected LAlertDialog(Context context, int theme) {
30 | super(context, theme);
31 | control = new LDialogController(context, this, getWindow());
32 | }
33 |
34 | protected LAlertDialog(Context context, boolean cancelable,
35 | OnCancelListener cancelListener) {
36 | super(context, default_theme);
37 | setCancelable(cancelable);
38 | setOnCancelListener(cancelListener);
39 | control = new LDialogController(context, this, getWindow());
40 | }
41 |
42 | public void setPositiveButtonEnable(boolean enable) {
43 | control.setPositiveButtonEnable(enable);
44 | }
45 |
46 | public LDialogController getController() {
47 | return control;
48 | }
49 |
50 | @Override
51 | protected void onCreate(Bundle savedInstanceState) {
52 | super.onCreate(savedInstanceState);
53 | control.installContent();
54 | }
55 |
56 | public static class Builder {
57 | private final LDialogController.DialogParams P;
58 |
59 | public Builder(Context context) {
60 | P = new LDialogController.DialogParams(context);
61 | }
62 |
63 | /**
64 | * 根据resource id来设置title
65 | *
66 | * @param titleId
67 | * @return
68 | */
69 | public Builder setTitle(int titleId) {
70 | P.mTitle = P.mContext.getText(titleId);
71 | return this;
72 | }
73 |
74 | /**
75 | * 给定字符串来设置dialog的title
76 | *
77 | * @param title
78 | * @return
79 | */
80 | public Builder setTitle(CharSequence title) {
81 | P.mTitle = title;
82 | return this;
83 | }
84 |
85 | /**
86 | * 根据resource id来设置message
87 | *
88 | * @param messageId
89 | * @return
90 | */
91 | public Builder setMessage(int messageId) {
92 | P.mMessage = P.mContext.getText(messageId);
93 | return this;
94 | }
95 |
96 | /**
97 | * 给定字符串来设置dialog的message
98 | *
99 | * @param message
100 | * @return
101 | */
102 | public Builder setMessage(CharSequence message) {
103 | P.mMessage = message;
104 | return this;
105 | }
106 |
107 | public Builder showCloseButton(boolean show) {
108 | P.visibleCallback = show;
109 | return this;
110 | }
111 |
112 | /**
113 | * 根据resource id来设置title左边图标
114 | *
115 | * @param iconId
116 | * @return
117 | */
118 | public Builder setIcon(int iconId) {
119 | P.mIconId = iconId;
120 | return this;
121 | }
122 |
123 | /**
124 | * 给定drawable来设置dialog的title左边图标
125 | *
126 | * @param icon
127 | * @return
128 | */
129 | public Builder setIcon(Drawable icon) {
130 | P.mIcon = icon;
131 | return this;
132 | }
133 |
134 | /**
135 | * 设置message信息是否居中,默认居左
136 | *
137 | * @param value
138 | * @return
139 | */
140 | public Builder setCenterMsg(boolean value) {
141 | P.centerMsg = value;
142 | return this;
143 | }
144 |
145 | /**
146 | * 设置dialog弹出的是否为警告信息, 是则改变title文字的颜色为红色。默认为蓝色
147 | *
148 | * @param value
149 | * @return
150 | */
151 | // public Builder setWarnTitle(boolean value){
152 | // P.warnTitle = value;
153 | // return this;
154 | // }
155 |
156 | /**
157 | * 为左边的按钮设置一个事件监听,当按钮被按下时可以执行某些动作
158 | *
159 | * @param textId 按钮中显示的文字的resource id
160 | * @param listener 事件监听器
161 | * @return
162 | */
163 | public Builder setPositiveButton(int textId,
164 | final OnClickListener listener) {
165 | P.mPositiveButtonText = P.mContext.getText(textId);
166 | P.mPositiveButtonListener = listener;
167 | return this;
168 | }
169 |
170 | /**
171 | * 为确定的按钮设置一个事件监听,当按钮被按下时可以执行某些动作
172 | *
173 | * @param text 按钮中显示的文字字符串
174 | * @param listener 事件监听器
175 | * @return
176 | */
177 | public Builder setPositiveButton(CharSequence text,
178 | final OnClickListener listener) {
179 | P.mPositiveButtonText = text;
180 | P.mPositiveButtonListener = listener;
181 | return this;
182 | }
183 |
184 | /**
185 | * @param value false点击确定不dismiss,默认为true
186 | * @return
187 | */
188 | public Builder setClickPositiveBtnDismiss(boolean value) {
189 | P.clickPositiveBtnDismiss = value;
190 | return this;
191 | }
192 |
193 | /**
194 | * 为右边的按钮设置一个事件监听,当按钮被按下时可以执行某些动作
195 | *
196 | * @param textId 按钮中显示的文字的resource id
197 | * @param listener 事件监听器
198 | * @return
199 | */
200 | public Builder setNegativeButton(int textId,
201 | final OnClickListener listener) {
202 | P.mNegativeButtonText = P.mContext.getText(textId);
203 | P.mNegativeButtonListener = listener;
204 | return this;
205 | }
206 |
207 | /**
208 | * 为右边的按钮设置一个事件监听,当按钮被按下时可以执行某些动作
209 | *
210 | * @param text 按钮中显示的文字字符串
211 | * @param listener 事件监听器
212 | * @return
213 | */
214 | public Builder setNegativeButton(CharSequence text,
215 | final OnClickListener listener) {
216 | P.mNegativeButtonText = text;
217 | P.mNegativeButtonListener = listener;
218 | return this;
219 | }
220 |
221 | public Builder setCancelable(boolean cancelable) {
222 | P.mCancelable = cancelable;
223 | return this;
224 | }
225 |
226 | public Builder setOnCancelListener(OnCancelListener onCancelListener) {
227 | P.mOnCancelListener = onCancelListener;
228 | return this;
229 | }
230 |
231 | /**
232 | * 为内容区域设置自定义的视图
233 | *
234 | * @param view
235 | * @return
236 | */
237 | public Builder setView(View view) {
238 | P.mView = view;
239 | return this;
240 | }
241 |
242 | /**
243 | * 创建dialog
244 | *
245 | * @return
246 | */
247 | public LAlertDialog create() {
248 | final LAlertDialog dialog = new LAlertDialog(P.mContext);
249 | P.apply(dialog.control);
250 | dialog.setCancelable(P.mCancelable);
251 | if (P.mCancelable) {
252 | dialog.setCanceledOnTouchOutside(true);
253 | }
254 | dialog.setOnCancelListener(P.mOnCancelListener);
255 | return dialog;
256 | }
257 |
258 | /**
259 | * 创建并显示dialog
260 | *
261 | * @return
262 | */
263 | public LAlertDialog show() {
264 | LAlertDialog dialog = create();
265 | dialog.show();
266 | return dialog;
267 | }
268 | }
269 |
270 | }
271 |
--------------------------------------------------------------------------------
/material/src/main/java/com/lion/material/widget/LTabIndicator.java:
--------------------------------------------------------------------------------
1 | package com.lion.material.widget;
2 |
3 | import android.content.Context;
4 | import android.graphics.Canvas;
5 | import android.graphics.Color;
6 | import android.graphics.Paint;
7 | import android.graphics.Paint.Style;
8 | import android.support.v4.view.ViewPager;
9 | import android.support.v4.view.ViewPager.OnPageChangeListener;
10 | import android.util.AttributeSet;
11 | import android.util.DisplayMetrics;
12 | import android.util.TypedValue;
13 | import android.view.Gravity;
14 | import android.view.View;
15 | import android.widget.HorizontalScrollView;
16 | import android.widget.LinearLayout;
17 | import android.widget.TextView;
18 |
19 | public class LTabIndicator extends HorizontalScrollView {
20 |
21 | public interface OnTabSelectedListener {
22 |
23 | void onTabSelected(int position);
24 | }
25 |
26 | public OnPageChangeListener mOnPageChangeListener;
27 | private OnTabSelectedListener mTabSelectedListener;
28 |
29 | private LinearLayout mTabsContainer;
30 | private ViewPager mPager;
31 |
32 | private int tabCount;
33 | private int currentPosition = 0;
34 | private float currentPositionOffset = 0f;
35 |
36 | private Paint mCurrentPaint = new Paint();;
37 | private Paint mBaseLinePaint = new Paint();;
38 | private Paint diviPaint;
39 |
40 | private int indicatorColor = 0xdeffffff;
41 | private int underlineColor = 0x8AFFFFFF;// 0x42ffffff;
42 | private int dividerColor = 0x1A000000;
43 | private int textSelectedColor = 0xDEFFFFFF;
44 | private int textUnselectColor = 0x8AFFFFFF;
45 | private int mAnimColor = 0x8affffff;
46 |
47 | private boolean enableExpand = true;
48 | private boolean enableDivider = false;
49 | private boolean indicatorOnTop = false;
50 | private boolean viewPagerScrollWithAnimation = true;
51 |
52 | private int tabTextSize = 16;
53 | private int scrollOffset = 52;
54 | private float indicatorHeight = 3f;
55 | private float underlineHeight = 1.0f;
56 | private int dividerPadding = 12;
57 | private int tabPadding = 24;
58 | private int dividerWidth = 1;
59 | private int lastScrollX = 0;
60 |
61 | public LTabIndicator(Context context) {
62 | this(context, null);
63 | }
64 |
65 | public LTabIndicator(Context context, AttributeSet attrs) {
66 | this(context, attrs, 0);
67 | }
68 |
69 | public LTabIndicator(Context context, AttributeSet attrs, int defStyle) {
70 | super(context, attrs, defStyle);
71 |
72 | setFillViewport(true);
73 | setWillNotDraw(false);
74 |
75 | DisplayMetrics dm = getResources().getDisplayMetrics();
76 |
77 | mTabsContainer = new LinearLayout(context);
78 | mTabsContainer.setOrientation(LinearLayout.HORIZONTAL);
79 | LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT,
80 | LayoutParams.MATCH_PARENT);
81 | params.height = (int) TypedValue.applyDimension(
82 | TypedValue.COMPLEX_UNIT_DIP, 50, dm);
83 | mTabsContainer.setLayoutParams(params);
84 | addView(mTabsContainer);
85 |
86 | scrollOffset = (int) TypedValue.applyDimension(
87 | TypedValue.COMPLEX_UNIT_DIP, scrollOffset, dm);
88 | dividerPadding = (int) TypedValue.applyDimension(
89 | TypedValue.COMPLEX_UNIT_DIP, dividerPadding, dm);
90 | tabPadding = (int) TypedValue.applyDimension(
91 | TypedValue.COMPLEX_UNIT_DIP, tabPadding, dm);
92 | dividerWidth = (int) TypedValue.applyDimension(
93 | TypedValue.COMPLEX_UNIT_DIP, dividerWidth, dm);
94 | indicatorHeight = TypedValue.applyDimension(
95 | TypedValue.COMPLEX_UNIT_DIP, indicatorHeight, dm);
96 | underlineHeight = TypedValue.applyDimension(
97 | TypedValue.COMPLEX_UNIT_DIP, underlineHeight, dm);
98 |
99 | mCurrentPaint.setAntiAlias(true);
100 | mCurrentPaint.setStyle(Style.FILL);
101 | mCurrentPaint.setColor(indicatorColor);
102 | mBaseLinePaint.setAntiAlias(true);
103 | mBaseLinePaint.setStyle(Style.FILL);
104 | mBaseLinePaint.setColor(underlineColor);
105 | diviPaint = new Paint();
106 | diviPaint.setAntiAlias(true);
107 | diviPaint.setStrokeWidth(dividerWidth);
108 | }
109 |
110 | @Override
111 | protected void onDraw(Canvas canvas) {
112 | super.onDraw(canvas);
113 |
114 | if (isInEditMode() || tabCount == 0) {
115 | return;
116 | }
117 |
118 | final int height = getHeight();
119 |
120 | if (indicatorOnTop) {
121 | canvas.drawRect(0, 0, mTabsContainer.getWidth(), underlineHeight,
122 | mBaseLinePaint);
123 | } else {
124 | canvas.drawRect(0, height - underlineHeight,
125 | mTabsContainer.getWidth(), height, mBaseLinePaint);
126 | }
127 |
128 | View currentTab = mTabsContainer.getChildAt(currentPosition);
129 | float lineLeft = currentTab.getLeft();
130 | float lineRight = currentTab.getRight();
131 |
132 | if (currentPositionOffset > 0f && currentPosition < tabCount - 1) {
133 | View nextTab = mTabsContainer.getChildAt(currentPosition + 1);
134 | final float nextTabLeft = nextTab.getLeft();
135 | final float nextTabRight = nextTab.getRight();
136 |
137 | lineLeft = (currentPositionOffset * nextTabLeft + (1f - currentPositionOffset)
138 | * lineLeft);
139 | lineRight = (currentPositionOffset * nextTabRight + (1f - currentPositionOffset)
140 | * lineRight);
141 | }
142 |
143 | if (indicatorOnTop) {
144 | canvas.drawRect(lineLeft, 0, lineRight, indicatorHeight,
145 | mCurrentPaint);
146 | } else {
147 | canvas.drawRect(lineLeft, height - indicatorHeight, lineRight,
148 | height, mCurrentPaint);
149 | }
150 |
151 | if (enableDivider) {
152 | diviPaint.setColor(dividerColor);
153 | for (int i = 0; i < tabCount - 1; i++) {
154 | View tab = mTabsContainer.getChildAt(i);
155 | canvas.drawLine(tab.getRight(), dividerPadding, tab.getRight(),
156 | height - dividerPadding, diviPaint);
157 | }
158 | }
159 | }
160 |
161 | public void setViewPager(ViewPager pager) {
162 | this.mPager = pager;
163 |
164 | if (pager.getAdapter() == null) {
165 | throw new IllegalStateException(
166 | "ViewPager does not have adapter instance.");
167 | }
168 |
169 | pager.setOnPageChangeListener(new PageListener());
170 |
171 | notifyDataSetChanged();
172 | }
173 |
174 | public void setOnPageChangeListener(OnPageChangeListener listener) {
175 | this.mOnPageChangeListener = listener;
176 | }
177 |
178 | public void setOnTabReselectedListener(OnTabSelectedListener listener) {
179 | mTabSelectedListener = listener;
180 | }
181 |
182 | public void notifyDataSetChanged() {
183 |
184 | mTabsContainer.removeAllViews();
185 |
186 | tabCount = mPager.getAdapter().getCount();
187 |
188 | for (int i = 0; i < tabCount; i++) {
189 | addTab(i, mPager.getAdapter().getPageTitle(i).toString());
190 | }
191 |
192 | updateTabStyles();
193 | }
194 |
195 | private class TabView extends LFrameLayout {
196 | private TextView mTabText;
197 |
198 | public TabView(Context context) {
199 | this(context, null);
200 | }
201 |
202 | public TabView(Context context, AttributeSet attrs) {
203 | super(context, attrs);
204 | init();
205 | this.setDelayClick(false);
206 | this.setColor(mAnimColor);
207 | }
208 |
209 | private void init() {
210 | mTabText = new TextView(getContext());
211 | // mTabText.setTextAppearance(getContext(),
212 | // android.R.attr.textAppearanceMedium);
213 | mTabText.setTextSize(tabTextSize
214 | / getResources().getConfiguration().fontScale);
215 | mTabText.setSingleLine(true);
216 | mTabText.setGravity(Gravity.CENTER);
217 | LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT,
218 | LayoutParams.MATCH_PARENT);
219 | this.addView(mTabText, params);
220 |
221 | }
222 |
223 | public TextView getTextView() {
224 | return mTabText;
225 | }
226 | }
227 |
228 | private void addTab(final int position, String title) {
229 | TabView tab = new TabView(getContext());
230 | tab.getTextView().setText(title);
231 | tab.setFocusable(true);
232 | tab.setOnClickListener(new OnClickListener() {
233 | @Override
234 | public void onClick(View v) {
235 | final int oldSelected = mPager.getCurrentItem();
236 | if (oldSelected != position && mTabSelectedListener != null) {
237 | mTabSelectedListener.onTabSelected(position);
238 | }
239 |
240 | mPager.setCurrentItem(position, viewPagerScrollWithAnimation);
241 | }
242 | });
243 |
244 | if (!enableExpand) {
245 | tab.setPadding(tabPadding, 0, tabPadding, 0);
246 | }
247 | mTabsContainer.addView(tab, position,
248 | enableExpand ? new LinearLayout.LayoutParams(0,
249 | LayoutParams.MATCH_PARENT, 1.0f)
250 | : new LinearLayout.LayoutParams(
251 | LayoutParams.WRAP_CONTENT,
252 | LayoutParams.MATCH_PARENT));
253 | }
254 |
255 | public void setTabText(int position, String text) {
256 | if (position < 0 || position > (mTabsContainer.getChildCount() - 1))
257 | throw new RuntimeException("tabs does not have this position.");
258 |
259 | View tab = mTabsContainer.getChildAt(position);
260 | if (tab instanceof TextView) {
261 | ((TextView) tab).setText(text);
262 | }
263 | }
264 |
265 | public boolean isIndicatorOnTop() {
266 | return indicatorOnTop;
267 | }
268 |
269 | public void setIndicatorOnTop(boolean indicatorOnTop) {
270 | this.indicatorOnTop = indicatorOnTop;
271 | }
272 |
273 | public boolean isEnableExpand() {
274 | return enableExpand;
275 | }
276 |
277 | public void setEnableExpand(boolean enableExpand) {
278 | this.enableExpand = enableExpand;
279 | }
280 |
281 | public boolean isEnableDivider() {
282 | return enableDivider;
283 | }
284 |
285 | public void setEnableDivider(boolean enableDivider) {
286 | this.enableDivider = enableDivider;
287 | }
288 |
289 | public void setViewPagerScrollWithAnimation(boolean enable) {
290 | this.viewPagerScrollWithAnimation = enable;
291 | }
292 |
293 | public boolean getViewPagerScrollWithAnimation() {
294 | return this.viewPagerScrollWithAnimation;
295 | }
296 |
297 | public void setCurrentItem(int item) {
298 | mPager.setCurrentItem(item, viewPagerScrollWithAnimation);
299 | }
300 |
301 | private void tabSelect(int index) {
302 | final int tabCount = mTabsContainer.getChildCount();
303 | for (int i = 0; i < tabCount; i++) {
304 | final View child = mTabsContainer.getChildAt(i);
305 | final boolean isSelected = (i == index);
306 | child.setSelected(isSelected);
307 | if (isSelected) {
308 | ((TabView) child).getTextView().setTextColor(textSelectedColor);
309 | } else {
310 | ((TabView) child).getTextView().setTextColor(textUnselectColor);
311 | }
312 | }
313 | }
314 |
315 | private void updateTabStyles() {
316 | for (int i = 0; i < tabCount; i++) {
317 | View v = mTabsContainer.getChildAt(i);
318 | v.setBackgroundColor(Color.TRANSPARENT);
319 | }
320 | tabSelect(mPager.getCurrentItem());
321 | }
322 |
323 | private void scrollToChild(int position, int offset) {
324 | if (tabCount == 0) {
325 | return;
326 | }
327 |
328 | int newScrollX = mTabsContainer.getChildAt(position).getLeft() + offset;
329 |
330 | if (position > 0 || offset > 0) {
331 | newScrollX -= scrollOffset;
332 | }
333 |
334 | if (newScrollX != lastScrollX) {
335 | lastScrollX = newScrollX;
336 | scrollTo(newScrollX, 0);
337 | }
338 | }
339 |
340 | private class PageListener implements OnPageChangeListener {
341 |
342 | @Override
343 | public void onPageScrolled(int position, float positionOffset,
344 | int positionOffsetPixels) {
345 | currentPosition = position;
346 | currentPositionOffset = positionOffset;
347 |
348 | scrollToChild(position, (int) (positionOffset * mTabsContainer
349 | .getChildAt(position).getWidth()));
350 |
351 | invalidate();
352 |
353 | if (mOnPageChangeListener != null) {
354 | mOnPageChangeListener.onPageScrolled(position, positionOffset,
355 | positionOffsetPixels);
356 | }
357 | }
358 |
359 | @Override
360 | public void onPageScrollStateChanged(int state) {
361 | if (state == ViewPager.SCROLL_STATE_IDLE) {
362 | scrollToChild(mPager.getCurrentItem(), 0);
363 | }
364 |
365 | if (mOnPageChangeListener != null) {
366 | mOnPageChangeListener.onPageScrollStateChanged(state);
367 | }
368 | }
369 |
370 | @Override
371 | public void onPageSelected(int position) {
372 | tabSelect(position);
373 |
374 | if (mOnPageChangeListener != null) {
375 | mOnPageChangeListener.onPageSelected(position);
376 | }
377 | }
378 | }
379 | }
--------------------------------------------------------------------------------
/material/src/main/java/com/lion/material/dialog/LDialogController.java:
--------------------------------------------------------------------------------
1 | package com.lion.material.dialog;
2 |
3 | import android.content.Context;
4 | import android.content.DialogInterface;
5 | import android.content.DialogInterface.OnCancelListener;
6 | import android.graphics.drawable.Drawable;
7 | import android.os.Handler;
8 | import android.os.Message;
9 | import android.text.TextUtils;
10 | import android.view.Gravity;
11 | import android.view.LayoutInflater;
12 | import android.view.View;
13 | import android.view.View.OnClickListener;
14 | import android.view.ViewGroup.LayoutParams;
15 | import android.view.Window;
16 | import android.widget.FrameLayout;
17 | import android.widget.ImageView;
18 | import android.widget.ScrollView;
19 | import android.widget.TextView;
20 |
21 | import com.lion.material.R;
22 | import com.lion.material.widget.LButton;
23 | import com.lion.material.widget.LImageButton;
24 |
25 | import java.lang.ref.WeakReference;
26 |
27 | import static android.view.ViewGroup.LayoutParams.MATCH_PARENT;
28 |
29 | public class LDialogController {
30 | private final DialogInterface mDialogInterface;
31 | private final Window mWindow;
32 |
33 | private View mView; // Custom view
34 |
35 | private LButton mButtonPositive; // right Button
36 | private CharSequence mButtonPositiveText;
37 | private Message mButtonPositiveMessage;
38 |
39 | private LButton mButtonNegative; // left Button
40 | private CharSequence mButtonNegativeText;
41 | private Message mButtonNegativeMessage;
42 |
43 | private ScrollView mScrollView;
44 |
45 | private int mIconId = -1;
46 | private Drawable mIcon;
47 | private ImageView mIconView;
48 | public LImageButton mCloseImageView;
49 |
50 | private TextView mTitleView;
51 | private CharSequence mTitle;
52 |
53 | private TextView mMessageView;
54 | private CharSequence mMessage;
55 |
56 | public boolean clickPositiveBtnDismiss;
57 | public boolean centerMsg;
58 |
59 | private Handler mHandler;
60 |
61 | private boolean mShowCloseBtn = false;
62 |
63 | public DialogInterface getDialogInterface() {
64 | return mDialogInterface;
65 | }
66 |
67 | OnClickListener mButtonHandler = new OnClickListener() {
68 | @Override
69 | public void onClick(View v) {
70 | Message m = null;
71 | if (v == mButtonPositive && mButtonPositiveMessage != null) {
72 | m = Message.obtain(mButtonPositiveMessage);
73 | } else if (v == mButtonNegative && mButtonNegativeMessage != null) {
74 | m = Message.obtain(mButtonNegativeMessage);
75 | }
76 | if (m != null) {
77 | m.sendToTarget();
78 | }
79 |
80 | if (!clickPositiveBtnDismiss && v == mButtonPositive) {
81 | return;
82 | }
83 | // Post a message so we dismiss after the above handlers are
84 | // executed
85 | mHandler.obtainMessage(ButtonHandler.MSG_DISMISS_DIALOG,
86 | mDialogInterface).sendToTarget();
87 | }
88 | };
89 |
90 | private static final class ButtonHandler extends Handler {
91 | // Button clicks have Message.what as the BUTTON{1,2,3} constant
92 | private static final int MSG_DISMISS_DIALOG = 1;
93 |
94 | private WeakReference mDialog;
95 |
96 | public ButtonHandler(DialogInterface dialog) {
97 | mDialog = new WeakReference(dialog);
98 | }
99 |
100 | @Override
101 | public void handleMessage(Message msg) {
102 | switch (msg.what) {
103 |
104 | case DialogInterface.BUTTON_POSITIVE:
105 | case DialogInterface.BUTTON_NEGATIVE:
106 | case DialogInterface.BUTTON_NEUTRAL:
107 | ((DialogInterface.OnClickListener) msg.obj).onClick(
108 | mDialog.get(), msg.what);
109 | break;
110 |
111 | case MSG_DISMISS_DIALOG:
112 | ((DialogInterface) msg.obj).dismiss();
113 | }
114 | }
115 | }
116 |
117 | public LDialogController(Context context, DialogInterface di, Window window) {
118 | mDialogInterface = di;
119 | mWindow = window;
120 | mHandler = new ButtonHandler(di);
121 | }
122 |
123 | public void setPositiveButtonEnable(boolean enable) {
124 | mButtonPositive.setEnabled(enable);
125 | }
126 |
127 |
128 | public void installContent() {
129 | /* We use a custom title so never request a window title */
130 | mWindow.requestFeature(Window.FEATURE_NO_TITLE);
131 | mWindow.setContentView(R.layout.material_alert_dialog);
132 | setupView();
133 | }
134 |
135 | private void setupView() {
136 | setupContent();
137 | boolean hasButtons = setupButtons(); // bottom button
138 | mWindow.findViewById(R.id.buttonPanel).setVisibility(
139 | hasButtons ? View.VISIBLE : View.GONE);
140 | setupTitle(); // title
141 | FrameLayout custom = (FrameLayout) mWindow.findViewById(R.id.custom);
142 | if (mView != null) { // custom view
143 | custom.addView(mView, new LayoutParams(MATCH_PARENT, MATCH_PARENT));
144 | } else {
145 | custom.setVisibility(View.GONE);
146 | }
147 |
148 | }
149 |
150 | private boolean setupTitle() {
151 | boolean hasTitle = true;
152 |
153 | final boolean hasTextTitle = !TextUtils.isEmpty(mTitle);
154 | mIconView = (ImageView) mWindow.findViewById(R.id.icon);
155 | mCloseImageView = (LImageButton) mWindow.findViewById(R.id.close);
156 | mCloseImageView.setOnClickListener(new OnClickListener() {
157 |
158 | @Override
159 | public void onClick(View v) {
160 | mDialogInterface.dismiss();
161 | }
162 | });
163 | if (hasTextTitle) {
164 | mTitleView = (TextView) mWindow.findViewById(R.id.alertTitle);
165 | mTitleView.setText(mTitle);
166 | if (mIconId > 0) {
167 | mIconView.setImageResource(mIconId);
168 | } else if (mIcon != null) {
169 | mIconView.setImageDrawable(mIcon);
170 | } else if (mIconId == 0) {
171 | mTitleView.setPadding(mIconView.getPaddingLeft(),
172 | mIconView.getPaddingTop(), mIconView.getPaddingRight(),
173 | mIconView.getPaddingBottom());
174 | mIconView.setVisibility(View.GONE);
175 | }
176 | mCloseImageView.setVisibility(mShowCloseBtn ? View.VISIBLE
177 | : View.INVISIBLE);
178 | } else {
179 | // Hide the title template
180 | View titleTemplate = mWindow.findViewById(R.id.title_template);
181 | titleTemplate.setVisibility(View.GONE);
182 | mIconView.setVisibility(View.GONE);
183 | mWindow.findViewById(R.id.topPanel).setVisibility(View.GONE);
184 | hasTitle = false;
185 |
186 | }
187 | mWindow.findViewById(R.id.notitle_space).setVisibility(
188 | hasTitle ? View.GONE : View.VISIBLE);
189 | return hasTitle;
190 | }
191 |
192 |
193 | private void setupContent() {
194 | mScrollView = (ScrollView) mWindow.findViewById(R.id.scrollView);
195 | mScrollView.setFocusable(false);
196 |
197 | mMessageView = (TextView) mWindow.findViewById(R.id.message);
198 | if (mMessage != null) {
199 | if (centerMsg) {
200 | mMessageView.setGravity(Gravity.CENTER);
201 | }
202 | mMessageView.setText(mMessage);
203 | } else {
204 | mMessageView.setVisibility(View.GONE);
205 | mScrollView.setVisibility(View.GONE);
206 | }
207 | }
208 |
209 | public int getMaxListLineNum() {
210 | return 6;
211 | }
212 |
213 |
214 | private boolean setupButtons() {
215 | int BIT_BUTTON_POSITIVE = 1;
216 | int BIT_BUTTON_NEGATIVE = 2;
217 | int whichButtons = 0;
218 | mButtonPositive = (LButton) mWindow.findViewById(R.id.button1);
219 | mButtonPositive.setOnClickListener(mButtonHandler);
220 |
221 | if (TextUtils.isEmpty(mButtonPositiveText)) {
222 | mButtonPositive.setVisibility(View.GONE);
223 | } else {
224 | mButtonPositive.setText(mButtonPositiveText);
225 | mButtonPositive.setVisibility(View.VISIBLE);
226 | whichButtons = whichButtons | BIT_BUTTON_POSITIVE;
227 | }
228 |
229 | mButtonNegative = (LButton) mWindow.findViewById(R.id.button2);
230 | mButtonNegative.setOnClickListener(mButtonHandler);
231 |
232 | if (TextUtils.isEmpty(mButtonNegativeText)) {
233 | mButtonNegative.setVisibility(View.GONE);
234 | } else {
235 | mButtonNegative.setText(mButtonNegativeText);
236 | mButtonNegative.setVisibility(View.VISIBLE);
237 | whichButtons = whichButtons | BIT_BUTTON_NEGATIVE;
238 | }
239 |
240 | return whichButtons != 0;
241 |
242 | }
243 |
244 | public void setTitle(CharSequence title) {
245 | mTitle = title;
246 | if (mTitleView != null) {
247 | mTitleView.setText(title);
248 | }
249 | }
250 |
251 | public void setClickPositiveBtnDismiss(boolean value) {
252 | clickPositiveBtnDismiss = value;
253 | }
254 |
255 | public void setCenterMsg(boolean value) {
256 | centerMsg = value;
257 | }
258 |
259 | public void setMessage(CharSequence message) {
260 | mMessage = message;
261 | if (mMessageView != null) {
262 | mMessageView.setText(message);
263 | }
264 | }
265 |
266 | public void setButton(int whichButton, CharSequence text,
267 | DialogInterface.OnClickListener listener, Message msg) {
268 |
269 | if (msg == null && listener != null) {
270 | msg = mHandler.obtainMessage(whichButton, listener);
271 | }
272 |
273 | switch (whichButton) {
274 |
275 | case DialogInterface.BUTTON_POSITIVE:
276 | mButtonPositiveText = text;
277 | mButtonPositiveMessage = msg;
278 | break;
279 |
280 | case DialogInterface.BUTTON_NEGATIVE:
281 | mButtonNegativeText = text;
282 | mButtonNegativeMessage = msg;
283 | break;
284 |
285 | default:
286 | // throw new IllegalArgumentException("Button does not exist");
287 | break;
288 | }
289 | }
290 |
291 | public void setCloseButton(boolean showCloseBtn) {
292 | this.mShowCloseBtn = showCloseBtn;
293 | }
294 |
295 | public void setIcon(int resId) {
296 | mIconId = resId;
297 | if (mIconView != null) {
298 | if (resId > 0) {
299 | mIconView.setImageResource(mIconId);
300 | } else if (resId == 0) {
301 | mIconView.setVisibility(View.GONE);
302 | }
303 | }
304 | }
305 |
306 | public void setIcon(Drawable icon) {
307 | mIcon = icon;
308 | if ((mIconView != null) && (mIcon != null)) {
309 | mIconView.setImageDrawable(icon);
310 | }
311 | }
312 |
313 | public void setView(View view) {
314 | mView = view;
315 | }
316 |
317 | public static class DialogParams {
318 | public final Context mContext;
319 | public final LayoutInflater mInflater;
320 |
321 | public boolean visibleCallback;
322 | public int mIconId = 0;
323 | public Drawable mIcon;
324 | public CharSequence mTitle;
325 | public CharSequence mMessage;
326 | public CharSequence mPositiveButtonText;
327 | public DialogInterface.OnClickListener mPositiveButtonListener;
328 | public DialogInterface.OnClickListener mCloseListener;
329 | public CharSequence mNegativeButtonText;
330 | public DialogInterface.OnClickListener mNegativeButtonListener;
331 | public boolean mCancelable;
332 | public boolean clickPositiveBtnDismiss;
333 | public boolean centerMsg;
334 | public OnCancelListener mOnCancelListener;
335 |
336 | public DialogInterface.OnClickListener mOnClickListener;
337 |
338 | public View mView;
339 |
340 | public DialogParams(Context context) {
341 | mContext = context;
342 | mCancelable = true;
343 | clickPositiveBtnDismiss = true;
344 | mInflater = (LayoutInflater) context
345 | .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
346 | }
347 |
348 | public void apply(LDialogController control) {
349 | control.setClickPositiveBtnDismiss(clickPositiveBtnDismiss);
350 | control.setCenterMsg(centerMsg);
351 | if (mTitle != null) {
352 | control.setTitle(mTitle);
353 | }
354 | if (mIcon != null) {
355 | control.setIcon(mIcon);
356 | }
357 | control.setCloseButton(visibleCallback);
358 |
359 | if (mIconId >= 0) {
360 | control.setIcon(mIconId);
361 | }
362 | if (mMessage != null) {
363 | control.setMessage(mMessage);
364 | }
365 |
366 | if (mPositiveButtonText != null) {
367 | control.setButton(DialogInterface.BUTTON_POSITIVE,
368 | mPositiveButtonText, mPositiveButtonListener, null);
369 | }
370 | if (mNegativeButtonText != null) {
371 | control.setButton(DialogInterface.BUTTON_NEGATIVE,
372 | mNegativeButtonText, mNegativeButtonListener, null);
373 | }
374 | if (mView != null) {
375 | control.setView(mView);
376 | }
377 | }
378 |
379 | }
380 | }
381 |
--------------------------------------------------------------------------------
/material/src/main/java/com/lion/material/widget/LSwitch.java:
--------------------------------------------------------------------------------
1 | package com.lion.material.widget;
2 |
3 | import android.content.Context;
4 | import android.graphics.Canvas;
5 | import android.graphics.Paint;
6 | import android.graphics.Paint.Style;
7 | import android.graphics.PaintFlagsDrawFilter;
8 | import android.graphics.PorterDuff;
9 | import android.graphics.PorterDuffXfermode;
10 | import android.graphics.RectF;
11 | import android.util.AttributeSet;
12 | import android.view.MotionEvent;
13 | import android.view.WindowManager;
14 | import android.widget.ToggleButton;
15 |
16 | //public class LSwitch extends CheckBox {
17 | // public class LSwitch extends Switch {
18 | public class LSwitch extends ToggleButton {
19 | public static int screenHeight;
20 |
21 | private Paint mPaintChecked = new Paint();
22 | private Paint mPaintNotChecked = new Paint();
23 | private Paint mPaintAnim = new Paint();
24 | private Paint mPaintLine = new Paint();
25 | private Paint mPaintTemp = new Paint();
26 |
27 | private PaintFlagsDrawFilter drawFilter = new PaintFlagsDrawFilter(0,
28 | Paint.ANTI_ALIAS_FLAG | Paint.FILTER_BITMAP_FLAG);
29 | private RectF mRectFOff;
30 | private RectF mRectFOn;
31 |
32 | private float mPostionX;
33 | private float offsetSpeed = 5;
34 | private float scaleSpeed = 0.01f;
35 |
36 | private final int STATUS_NORMAL = 0;
37 | private final int STATUS_ANIM_TO_OFF = 1;
38 | private final int STATUS_ANIM_TO_ON = 2;
39 | private final int STATUS_MOVE_BY_TOUCH = 3;
40 |
41 | private int status = STATUS_NORMAL;
42 | private final int ANIM_TIME = 100;
43 |
44 | private final int mCheckedColor = 0xaa09314B;
45 | private final int mNotCheckedColor = 0xff868384;
46 | private final int mAnimCheckedColor = 0x6609314B;
47 | private final int mAnimNotCheckedColor = 0x66868384;
48 | // private final int mCheckedColor = 0xff03a9f4;
49 | // private final int mNotCheckedColor = 0xff868384;
50 | // private final int mAnimCheckedColor = 0x6603a9f4;
51 | // private final int mAnimNotCheckedColor = 0x66868384;
52 |
53 | private int mWarpWidth;
54 | private int mWarpHeight;
55 |
56 | public LSwitch(Context context, AttributeSet attrs) {
57 | super(context, attrs);
58 | this.setBackgroundColor(0x00000000);
59 | // this.setBackgroundDrawable(null);
60 | // this.setButtonDrawable(null);
61 | if (LSwitch.screenHeight <= 0) {
62 | WindowManager wm = (WindowManager) context
63 | .getSystemService(Context.WINDOW_SERVICE);
64 | LSwitch.screenHeight = wm.getDefaultDisplay().getHeight();
65 | }
66 | mWarpHeight = (int) (60 * LSwitch.screenHeight / 1280f);
67 | mWarpWidth = mWarpHeight * 2;
68 | }
69 |
70 | private void init() {
71 | if (getHeight() == 0 || getWidth() == 0) {
72 | return;
73 | }
74 | int reallyHeight = getHeight();
75 | int reallyWidth = getWidth();
76 | int contentWidth = getWidth();
77 | int contentHeight = getWidth();
78 | int leftRightEmpty = 0;
79 | int topBottomEmpty = 0;
80 | float padding = mWarpHeight * 0.1f;
81 | float circleRadius;
82 | float offsetMax;
83 | if (reallyWidth >= 2 * reallyHeight) {// 填满高度
84 | contentWidth = 2 * reallyHeight;
85 | circleRadius = reallyHeight - 2 * padding;
86 | leftRightEmpty = (reallyWidth - contentWidth) / 2;
87 | offsetMax = contentWidth - circleRadius - padding * 2;
88 | offsetSpeed = (contentWidth - offsetMax - mPostionX)
89 | / (ANIM_TIME / 15f);
90 | } else {// 填满宽度
91 | contentHeight = reallyWidth / 2;
92 | circleRadius = contentHeight - 2 * padding;
93 | topBottomEmpty = (reallyHeight - contentHeight) / 2;
94 | offsetMax = reallyWidth - circleRadius - padding * 2;
95 | offsetSpeed = (reallyWidth - offsetMax - mPostionX)
96 | / (ANIM_TIME / 15f);
97 | }
98 | mRectFOff = new RectF();
99 | mRectFOff.left = padding + leftRightEmpty;
100 | mRectFOff.top = padding + topBottomEmpty;
101 | mRectFOff.right = mRectFOff.left + circleRadius;
102 | mRectFOff.bottom = mRectFOff.top + circleRadius;
103 | mPostionX = mRectFOff.left;
104 |
105 | mRectFOn = new RectF();
106 | mRectFOn.left = mRectFOff.left + offsetMax;
107 | mRectFOn.top = mRectFOff.top;
108 | mRectFOn.right = mRectFOff.right + offsetMax;
109 | mRectFOn.bottom = mRectFOff.bottom;
110 |
111 | mPaintChecked.setColor(mCheckedColor);
112 | mPaintChecked.setStyle(Style.FILL);
113 | mPaintNotChecked.setColor(mNotCheckedColor);
114 | mPaintNotChecked.setStyle(Style.STROKE);
115 | mPaintNotChecked.setStrokeWidth(mRectFOff.width() * 0.1f);
116 | mPaintTemp.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
117 | mPaintAnim.setStyle(Style.STROKE);
118 | mPaintLine.setStyle(Style.STROKE);
119 | mPaintLine.setStrokeWidth(mRectFOff.width() * 0.1f);
120 |
121 | scaleSpeed = (mScaleMax - mScaleMin) / (ANIM_TIME / 15f);
122 | }
123 |
124 | long lastTime;
125 |
126 | @Override
127 | protected void onDraw(Canvas canvas) {
128 | // super.onDraw(canvas);
129 | if (mRectFOff == null) {
130 | init();
131 | lastTime = System.currentTimeMillis();
132 | }
133 | // Log.e(TAG, "onDraw-time-->" + (System.currentTimeMillis() -
134 | // lastTime));
135 | lastTime = System.currentTimeMillis();
136 | canvas.setDrawFilter(drawFilter);
137 | mPaintLine.setColor(isChecked() ? mAnimCheckedColor
138 | : mAnimNotCheckedColor);
139 | if (status == STATUS_NORMAL) {
140 | if (isChecked()) {
141 | canvas.drawCircle(mRectFOn.centerX(), mRectFOn.centerY(),
142 | mRectFOn.width() / 2, mPaintChecked);
143 | canvas.drawLine(mRectFOff.left, mRectFOff.centerY(),
144 | mRectFOn.left, mRectFOff.centerY(), mPaintLine);
145 | mPostionX = mRectFOn.left;
146 | } else {
147 | canvas.drawCircle(mRectFOff.centerX(), mRectFOff.centerY(),
148 | mRectFOff.width() / 2 * (1 - 0.1f), mPaintNotChecked);
149 | canvas.drawLine(mRectFOff.right, mRectFOff.centerY(),
150 | mRectFOn.right, mRectFOff.centerY(), mPaintLine);
151 | mPostionX = mRectFOff.left;
152 | }
153 | } else {
154 | mPaintAnim.setColor(isChecked() ? mCheckedColor : mNotCheckedColor);
155 |
156 | canvas.drawCircle(mPostionX + mRectFOff.width() / 2,
157 | mRectFOff.centerY(), mRectFOff.width() / 2
158 | * (1 - mStrokeWidthScale), mPaintAnim);
159 | canvas.drawLine(mRectFOff.left, mRectFOff.centerY(), mPostionX,
160 | mRectFOff.centerY(), mPaintLine);
161 | canvas.drawLine(mPostionX + mRectFOff.width(), mRectFOff.centerY(),
162 | mRectFOn.right, mRectFOff.centerY(), mPaintLine);
163 | }
164 |
165 | move();
166 | }
167 |
168 | private float mScaleMax = 0.5f;
169 | private float mScaleMin = 0.1f;
170 | private float mStrokeWidthScale = 0;
171 |
172 | private void move() {
173 | if (status == STATUS_NORMAL || status == STATUS_MOVE_BY_TOUCH) {
174 | return;
175 | }
176 | switch (status) {
177 | case STATUS_ANIM_TO_OFF:
178 | mPostionX -= offsetSpeed;
179 | if (mPostionX <= mRectFOff.left) {
180 | mPostionX = mRectFOff.left;
181 | }
182 | mStrokeWidthScale -= scaleSpeed;
183 | if (mStrokeWidthScale <= mScaleMin) {
184 | mStrokeWidthScale = mScaleMin;
185 | }
186 | if (mPostionX <= mRectFOff.left && mStrokeWidthScale <= mScaleMin) {
187 | status = STATUS_NORMAL;
188 | }
189 | // mPaintAnim.setColor(mCheckedColor);
190 | break;
191 | case STATUS_ANIM_TO_ON:
192 | mPostionX += offsetSpeed;
193 | if (mPostionX >= mRectFOn.left) {
194 | mPostionX = mRectFOn.left;
195 | }
196 | mStrokeWidthScale += scaleSpeed;
197 | if (mStrokeWidthScale >= mScaleMax) {
198 | mStrokeWidthScale = mScaleMax;
199 | }
200 | if (mPostionX >= mRectFOn.left && mStrokeWidthScale >= mScaleMax) {
201 | status = STATUS_NORMAL;
202 | }
203 | // mPaintAnim.setColor(mNotCheckedColor);
204 | break;
205 |
206 | default:
207 | break;
208 | }
209 | mPaintAnim.setStrokeWidth(mRectFOff.width() * mStrokeWidthScale);
210 | if (mPostionX <= mRectFOff.left) {
211 | mPostionX = mRectFOff.left;
212 | } else if (mPostionX >= mRectFOn.left) {
213 | mPostionX = mRectFOn.left;
214 | }
215 | invalidate();
216 | }
217 |
218 | private void moveByTouch(float offset) {
219 | mPostionX += offset;
220 | if (mPostionX <= mRectFOff.left) {
221 | mPostionX = mRectFOff.left;
222 | } else if (mPostionX >= mRectFOn.left) {
223 | mPostionX = mRectFOn.left;
224 | }
225 | }
226 |
227 | @Override
228 | public boolean performClick() {
229 | status = isChecked() ? STATUS_ANIM_TO_OFF : STATUS_ANIM_TO_ON;
230 | return super.performClick();
231 | }
232 |
233 | private boolean canMove = false;
234 | private float mLastX;
235 | private boolean needSuperClick = true;
236 |
237 | @Override
238 | public boolean dispatchTouchEvent(MotionEvent event) {
239 | if (!isEnabled())
240 | return true;
241 | return super.dispatchTouchEvent(event);
242 | }
243 |
244 | @Override
245 | public boolean onTouchEvent(MotionEvent ev) {
246 | switch (ev.getAction()) {
247 | case MotionEvent.ACTION_DOWN:
248 | canMove = false;
249 | if (isChecked() && (ev.getX() > getWidth() / 2)
250 | || (!isChecked() && (ev.getX() < getWidth() / 2))) {
251 | mStrokeWidthScale = isChecked() ? mScaleMax : mScaleMin;
252 | mPaintAnim
253 | .setStrokeWidth(mRectFOff.width() * mStrokeWidthScale);
254 | canMove = true;
255 | status = STATUS_MOVE_BY_TOUCH;
256 | mLastX = ev.getX();
257 | invalidate();
258 | // return true;
259 | }
260 | break;
261 | case MotionEvent.ACTION_MOVE:
262 | if (canMove) {
263 | moveByTouch(ev.getX() - mLastX);
264 | mLastX = ev.getX();
265 | invalidate();
266 | if (needSuperClick) {
267 | if ((isChecked() && mPostionX <= ((getWidth() - mRectFOff
268 | .width()) / 2))
269 | || (!isChecked() && mPostionX >= ((getWidth() - mRectFOff
270 | .width()) / 2))) {
271 | needSuperClick = false;
272 | }
273 | }
274 | return true;
275 | }
276 | break;
277 |
278 | case MotionEvent.ACTION_UP:
279 | if (canMove) {
280 | moveByTouch(ev.getX() - mLastX);
281 | }
282 | case MotionEvent.ACTION_CANCEL:
283 | case MotionEvent.ACTION_OUTSIDE:
284 | if (canMove) {
285 | if (isChecked()) {
286 | if (mPostionX <= (getWidth() - mRectFOff.width()) / 2) {
287 | setChecked(false);
288 | status = STATUS_ANIM_TO_OFF;
289 | } else {
290 | status = STATUS_ANIM_TO_ON;
291 | }
292 | } else {
293 | if ((mPostionX >= (getWidth() - mRectFOff.width()) / 2)) {
294 | setChecked(true);
295 | status = STATUS_ANIM_TO_ON;
296 |
297 | } else {
298 | status = STATUS_ANIM_TO_OFF;
299 | }
300 | }
301 | // status = isChecked() ? STATUS_ANIM_TO_OFF :
302 | // STATUS_ANIM_TO_ON;
303 | invalidate();
304 | if (!needSuperClick) {
305 | needSuperClick = true;
306 | return true;
307 | }
308 | }
309 | break;
310 | default:
311 | break;
312 | }
313 | // return true;
314 | return super.onTouchEvent(ev);
315 | }
316 |
317 | @Override
318 | public void setChecked(boolean checked) {
319 | status = checked ? STATUS_ANIM_TO_ON : STATUS_ANIM_TO_OFF;
320 | super.setChecked(checked);
321 | invalidate();
322 | }
323 |
324 | @Override
325 | protected void onSizeChanged(int w, int h, int oldw, int oldh) {
326 | super.onSizeChanged(w, h, oldw, oldh);
327 | if (mRectFOff == null) {
328 | init();
329 | }
330 | }
331 |
332 | @Override
333 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
334 | int widthMode = MeasureSpec.getMode(widthMeasureSpec);
335 | int widthSize = MeasureSpec.getSize(widthMeasureSpec);
336 | int heightMode = MeasureSpec.getMode(heightMeasureSpec);
337 | int heightSize = MeasureSpec.getSize(heightMeasureSpec);
338 | int width = widthSize;
339 | int height = heightSize;
340 | switch (widthMode) {
341 | case MeasureSpec.EXACTLY:
342 | width = widthSize;
343 | switch (heightMode) {
344 | case MeasureSpec.EXACTLY:
345 | height = heightSize;
346 | break;
347 | case MeasureSpec.AT_MOST:
348 | height = Math.max(Math.min(mWarpHeight, heightSize),
349 | widthSize / 2);
350 | break;
351 | case MeasureSpec.UNSPECIFIED:
352 | height = Math.min(mWarpHeight, widthSize / 2);
353 | break;
354 |
355 | default:
356 | break;
357 | }
358 | break;
359 | case MeasureSpec.AT_MOST:
360 | switch (heightMode) {
361 | case MeasureSpec.EXACTLY:
362 | width = Math.max(Math.min(mWarpWidth, widthSize),
363 | heightSize * 2);
364 | height = heightSize;
365 | break;
366 | case MeasureSpec.AT_MOST:
367 | width = Math.min(mWarpWidth, widthSize);
368 | height = Math.min(mWarpHeight, heightSize);
369 | break;
370 | case MeasureSpec.UNSPECIFIED:
371 | width = Math.min(mWarpWidth, widthSize);
372 | height = mWarpHeight;
373 | if (width > height * 2) {
374 | width = height * 2;
375 | } else {
376 | height = width / 2;
377 | }
378 | break;
379 |
380 | default:
381 | break;
382 | }
383 | break;
384 | case MeasureSpec.UNSPECIFIED:
385 | switch (heightMode) {
386 | case MeasureSpec.EXACTLY:
387 | width = Math.min(mWarpWidth, heightSize * 2);
388 | height = heightSize;
389 | break;
390 | case MeasureSpec.AT_MOST:
391 | width = mWarpWidth;
392 | height = Math.min(mWarpHeight, heightSize);
393 | if (width > height * 2) {
394 | width = height * 2;
395 | } else {
396 | height = width / 2;
397 | }
398 | break;
399 | case MeasureSpec.UNSPECIFIED:
400 | width = mWarpWidth;
401 | height = mWarpHeight;
402 | if (width > height * 2) {
403 | width = height * 2;
404 | } else {
405 | height = width / 2;
406 | }
407 | break;
408 |
409 | default:
410 | break;
411 | }
412 | break;
413 |
414 | default:
415 | break;
416 | }
417 | setMeasuredDimension(width, height);
418 | }
419 | }
420 |
--------------------------------------------------------------------------------
/material/src/main/java/com/lion/material/extra/MaterialStyle.java:
--------------------------------------------------------------------------------
1 | package com.lion.material.extra;
2 |
3 | import android.annotation.SuppressLint;
4 | import android.content.res.TypedArray;
5 | import android.graphics.Canvas;
6 | import android.graphics.Color;
7 | import android.graphics.Paint;
8 | import android.graphics.PaintFlagsDrawFilter;
9 | import android.graphics.Path;
10 | import android.graphics.Path.Direction;
11 | import android.graphics.Region.Op;
12 | import android.graphics.drawable.Drawable;
13 | import android.os.Build.VERSION;
14 | import android.os.Build.VERSION_CODES;
15 | import android.util.AttributeSet;
16 | import android.view.MotionEvent;
17 | import android.view.View;
18 | import android.view.View.MeasureSpec;
19 |
20 | import com.lion.material.R;
21 |
22 | public class MaterialStyle {
23 | private final int STATUS_NORMAL = 0;
24 | // hand up will change to fast status
25 | private final int STATUS_ANIM_FAST = 1;
26 | // hand down and go on pressed is slowly status
27 | private final int STATUS_ANIM_SLOWLY = 2;
28 | // when time out,changed to pressed status
29 | private final int STATUS_PRESSED = 3;
30 | // when animation over will change to normal status
31 | private final int STATUS_TO_NORMAL = 4;
32 | private int status = STATUS_NORMAL;
33 |
34 | private final int SHAPE_MODE_EQUAL = 0;
35 | private final int SHAPE_MODE_WIDTH = 1;
36 | private final int SHAPE_MODE_HEIGHT = 2;
37 | private int mAnimMode = SHAPE_MODE_EQUAL;
38 |
39 | private int ANIM_FAST_TIME = 125;
40 | private final int ANIM_SLOW_TIME = 200;
41 | private final int ANIM_SLEEP_TIME = 10;
42 |
43 | // normal status (no touch, no pressed) paint
44 | // private Paint mBackgroundPaint = new Paint();
45 | private Drawable mBackgroundDrawable;
46 | private int mBackgroundColor = 0;
47 | private int mAnimColorAlpha = 0;// current alpha
48 | private int mAnimColorAlphaMax = (int) (255 * 0.06f);// max alpha
49 | private int mAnimColorAlphaSlowSpeed;// long press alpha animation speed
50 | private int mAnimColorAlphaFastSpeed;// click alpha animation speed
51 | private int mAnimColorAlphaToNormalSpeed;// change to normal alpha animation
52 | // speed
53 | private Path mPath = new Path();
54 | // paint for bottom (alpha will change)
55 | private Paint mAnimBottomPaint = new Paint();
56 | // paint for top circle(color and alpha will not change)
57 | private Paint mCirclePaint = new Paint();
58 |
59 | private float mCirRSpeedSlow;// long press circle radius speed
60 | private float mCirRSpeedFast;// click circle radius speed
61 | private float mCircleRadius; // current circle radius speed
62 | private float mCircleRadiusMax;// max circle radius speed
63 |
64 | private int animSlowTimes;
65 | private int animFastTimes;
66 |
67 | private float actionDownX;// touch down x position
68 | private float actionDownY;// touch down y position
69 | private int mBackgroundWidth;
70 | private int mBackgroundHeight;
71 |
72 | //private OnClickListener mClickListener;
73 |
74 | /**
75 | * there have 3 type: TYPE_HEADBAR_CENTER_BTN is normal button shape,could
76 | * be circle TYPE_HEADBAR_BACK_BTN like back button in header bar
77 | * TYPE_HEADBAR_RIGHT_BTN like setting button in header bar
78 | */
79 | public static final int TYPE_NORMAL_BTN = 0;
80 | public static final int TYPE_HEADBAR_BACK_BTN = 1;
81 | public static final int TYPE_HEADBAR_RIGHT_BTN = 2;
82 | public static final int TYPE_HEADER_CENTER_BTN = 3;
83 |
84 | private int mAnimFullColor = -1;
85 |
86 | private PaintFlagsDrawFilter drawFilter = new PaintFlagsDrawFilter(0,
87 | Paint.ANTI_ALIAS_FLAG | Paint.FILTER_BITMAP_FLAG);
88 |
89 | private int type = TYPE_NORMAL_BTN;
90 | private boolean mNeedDelayClick = true;
91 | private View mDependView;
92 | private IMaterial mCallBack;
93 |
94 | @SuppressLint("NewApi")
95 | public MaterialStyle(View view, AttributeSet attrs) {
96 | this.mCallBack = (IMaterial) view;
97 | mDependView = view;
98 | view.setClickable(true);
99 | setBackgroundColor(0x00000000);
100 | animSlowTimes = ANIM_SLOW_TIME / ANIM_SLEEP_TIME;
101 | animFastTimes = ANIM_FAST_TIME / ANIM_SLEEP_TIME;
102 | if (VERSION.SDK_INT >= VERSION_CODES.HONEYCOMB) {
103 | view.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
104 | }
105 | view.setWillNotDraw(false);
106 | if (attrs != null) {
107 | TypedArray a = view.getContext().obtainStyledAttributes(attrs,
108 | R.styleable.LButtonStyle);
109 | mNeedDelayClick = a.getBoolean(
110 | R.styleable.LButtonStyle_widget_delayclick, true);
111 | mAnimFullColor = a.getInt(
112 | R.styleable.LButtonStyle_widget_animColor, -1);
113 | mBackgroundDrawable = a
114 | .getDrawable(R.styleable.LButtonStyle_widget_background);
115 | if (mBackgroundDrawable != null) {
116 | mBackgroundWidth = mBackgroundDrawable.getIntrinsicWidth();
117 | mBackgroundHeight = mBackgroundDrawable.getIntrinsicHeight();
118 | }
119 | // mBackgroundPaint.setColor(a.getInt(
120 | // R.styleable.LButtonStyle_widget_background, 0x00000000));
121 | type = a.getInt(R.styleable.LButtonStyle_widget_type, 0);
122 | a.recycle();
123 | }
124 | }
125 |
126 | public void setColor(int fullColor) {
127 | this.mAnimFullColor = fullColor;
128 | initColorInfo();
129 | }
130 |
131 | public void setType(int widgetType) {
132 | this.type = widgetType;
133 | init();
134 | }
135 |
136 | private void init() {
137 |
138 | float width = mDependView.getWidth();
139 | float heigh = mDependView.getHeight();
140 | if (width <= 0 || heigh <= 0)
141 | return;
142 | // if width is close to height, regard as equale
143 | boolean inNormalSize = Math.min(width, heigh) / Math.max(width, heigh) > 0.8f;
144 | if (inNormalSize) {
145 | mAnimMode = SHAPE_MODE_EQUAL;
146 | } else if (width > heigh) {
147 | mAnimMode = SHAPE_MODE_WIDTH;
148 | } else {
149 | mAnimMode = SHAPE_MODE_HEIGHT;
150 | }
151 | switch (type) {
152 | case TYPE_HEADBAR_BACK_BTN:
153 | case TYPE_HEADBAR_RIGHT_BTN:
154 | mCircleRadius = heigh / 2f;
155 | mCircleRadiusMax = width;// / 2.5f;
156 | if (mAnimFullColor == -1) {
157 | mAnimFullColor = 0x60ffffff;
158 | }
159 | break;
160 | case TYPE_NORMAL_BTN:
161 | mCircleRadius = Math.min(width, heigh) / 4f;
162 | if (mAnimMode == SHAPE_MODE_EQUAL) {
163 | // this is for case:width is close to height
164 | mCircleRadiusMax = Math.min(width, heigh) / 2;
165 | } else {
166 | mCircleRadiusMax = Math.max(width, heigh) / 2;
167 | }
168 | if (mAnimFullColor == -1) {
169 | mAnimFullColor = 0x30000000;
170 | }
171 | break;
172 | case TYPE_HEADER_CENTER_BTN:
173 | mCircleRadius = Math.min(width, heigh) / 4f;
174 | mCircleRadiusMax = Math.max(width, heigh) / 2;
175 | if (mAnimFullColor == -1) {
176 | mAnimFullColor = 0x60ffffff;
177 | }
178 | break;
179 | }
180 | mCirRSpeedSlow = (mCircleRadiusMax - mCircleRadius) / animSlowTimes;
181 | mCirRSpeedFast = (mCircleRadiusMax - mCircleRadius) / animFastTimes;
182 | initColorInfo();
183 | }
184 |
185 | private void initColorInfo() {
186 | // if (mBackGroundPaint.getColor() == 0) {
187 | mAnimBottomPaint.setColor(Color.rgb(Color.red(mAnimFullColor),
188 | Color.green(mAnimFullColor), Color.blue(mAnimFullColor)));
189 | mAnimColorAlphaMax = Color.alpha(mAnimFullColor);
190 | mCirclePaint.setColor(Color.rgb(Color.red(mAnimFullColor),
191 | Color.green(mAnimFullColor), Color.blue(mAnimFullColor)));
192 | mCirclePaint.setAlpha(mAnimColorAlphaMax);
193 | // } else {
194 | // mAnimBottomPaint.setColor(Color.rgb(
195 | // Color.red(255 - mBackGroundPaint.getColor()),
196 | // Color.green(255 - mBackGroundPaint.getColor()),
197 | // Color.blue(255 - mBackGroundPaint.getColor())));
198 | // mAnimColorAlphaMax = Color.alpha(mBackGroundPaint.getColor());
199 | // }
200 | mAnimBottomPaint.setAlpha(0);
201 | mAnimColorAlphaSlowSpeed = (int) (mAnimColorAlphaMax / animSlowTimes);
202 | mAnimColorAlphaFastSpeed = (int) (mAnimColorAlphaMax / animFastTimes);
203 | if (mAnimColorAlphaSlowSpeed < 1) {
204 | mAnimColorAlphaSlowSpeed = 1;
205 | }
206 | if (mAnimColorAlphaFastSpeed < 1) {
207 | mAnimColorAlphaFastSpeed = 1;
208 | }
209 | mAnimColorAlphaToNormalSpeed = mAnimColorAlphaFastSpeed;
210 | }
211 |
212 | private int getWidth() {
213 | if (mDependView == null)
214 | return 0;
215 | return mDependView.getWidth();
216 | }
217 |
218 | private int getHeight() {
219 | if (mDependView == null)
220 | return 0;
221 | return mDependView.getHeight();
222 | }
223 |
224 | public void doDraw(Canvas canvas) {
225 | if (mCircleRadius == 0 || mCircleRadiusMax == 0) {
226 | init();
227 | }
228 | canvas.setDrawFilter(drawFilter);
229 | canvas.save();
230 | // Log.e("LButton", "status-->" + status + " Circle.Alpha-->"
231 | // + mCirclePaint.getAlpha() + " Bottom.Alpha-->"
232 | // + mAnimBottomPaint.getAlpha() + " Circle.Color-->"
233 | // + mCirclePaint.getColor() + " bottomColor-->"
234 | // + mAnimBottomPaint.getColor() + " mCirR-->" + mCircleRadius);
235 | if (mBackgroundDrawable != null) {
236 | mBackgroundDrawable.setBounds(0, 0, getWidth(), getHeight());
237 | mBackgroundDrawable.draw(canvas);
238 | } else if (mBackgroundColor != 0) {
239 | canvas.drawColor(mBackgroundColor);
240 | }
241 | switch (status) {
242 | case STATUS_NORMAL:
243 | break;
244 | case STATUS_PRESSED:
245 | switch (type) {
246 | case TYPE_HEADBAR_BACK_BTN:
247 | canvas.drawCircle(0, getHeight() / 2, getWidth(),
248 | mAnimBottomPaint);
249 | break;
250 | case TYPE_HEADBAR_RIGHT_BTN:
251 | canvas.drawCircle(getWidth(), getHeight() / 2, getWidth(),
252 | mAnimBottomPaint);
253 | break;
254 | case TYPE_NORMAL_BTN:
255 | if (mAnimMode == SHAPE_MODE_EQUAL) {
256 | canvas.drawCircle(getWidth() / 2, getHeight() / 2,
257 | Math.min(getWidth(), getHeight()) / 2,
258 | mAnimBottomPaint);
259 | } else {
260 | canvas.drawPaint(mAnimBottomPaint);
261 | }
262 | break;
263 | case TYPE_HEADER_CENTER_BTN:
264 | canvas.drawCircle(getWidth() / 2, getHeight() / 2,
265 | Math.max(getWidth(), getHeight()) / 2, mAnimBottomPaint);
266 | break;
267 | }
268 | break;
269 | case STATUS_ANIM_SLOWLY:
270 | case STATUS_ANIM_FAST:
271 | switch (type) {
272 | case TYPE_HEADBAR_BACK_BTN:
273 | // if (mBackgroundDrawable == null && mBackgroundColor == 0) {
274 | mPath.reset();
275 | mPath.addCircle(0, getHeight() / 2, mCircleRadius,
276 | Direction.CCW);
277 | canvas.drawPath(mPath, mCirclePaint);
278 | canvas.clipPath(mPath, Op.XOR);
279 | canvas.drawCircle(0, getHeight() / 2, mCircleRadiusMax,
280 | mAnimBottomPaint);
281 | // } else {
282 | // canvas.drawCircle(0, getHeight() / 2, mCircleRadius,
283 | // mAnimBottomPaint);
284 | // }
285 | break;
286 | case TYPE_HEADBAR_RIGHT_BTN:
287 | // if (mBackgroundDrawable == null && mBackgroundColor == 0) {
288 | mPath.reset();
289 | mPath.addCircle(getWidth(), getHeight() / 2, mCircleRadius,
290 | Direction.CCW);
291 | canvas.drawPath(mPath, mCirclePaint);
292 | canvas.clipPath(mPath, Op.XOR);
293 | canvas.drawCircle(getWidth(), getHeight() / 2,
294 | mCircleRadiusMax, mAnimBottomPaint);
295 | // } else {
296 | // canvas.drawCircle(getWidth(), getHeight() / 2,
297 | // mCircleRadius, mAnimBottomPaint);
298 | // }
299 | break;
300 | case TYPE_NORMAL_BTN:
301 | // if (mBackgroundDrawable == null && mBackgroundColor == 0) {
302 | mPath.reset();
303 | mPath.addCircle(actionDownX, actionDownY, mCircleRadius,
304 | Direction.CCW);
305 | canvas.drawPath(mPath, mCirclePaint);
306 | canvas.clipPath(mPath, Op.XOR);
307 | if (mAnimMode == SHAPE_MODE_EQUAL) {
308 | canvas.drawCircle(getWidth() / 2, getHeight() / 2,
309 | mCircleRadiusMax, mAnimBottomPaint);
310 | } else {
311 | canvas.drawPaint(mAnimBottomPaint);
312 | }
313 | // } else {
314 | // canvas.drawCircle(actionDownX, actionDownY, mCircleRadius,
315 | // mAnimBottomPaint);
316 | // }
317 | break;
318 | case TYPE_HEADER_CENTER_BTN:
319 | // if (mBackgroundDrawable == null && mBackgroundColor == 0) {
320 | mPath.reset();
321 | mPath.addCircle(getWidth() / 2, getHeight() / 2, mCircleRadius,
322 | Direction.CCW);
323 | canvas.drawPath(mPath, mCirclePaint);
324 | canvas.clipPath(mPath, Op.XOR);
325 | canvas.drawCircle(getWidth() / 2, getHeight() / 2,
326 | mCircleRadiusMax, mAnimBottomPaint);
327 | // } else {
328 | // canvas.drawCircle(getWidth() / 2, getHeight() / 2,
329 | // mCircleRadius, mAnimBottomPaint);
330 | // }
331 | break;
332 | }
333 | break;
334 | case STATUS_TO_NORMAL:
335 | switch (type) {
336 | case TYPE_HEADBAR_BACK_BTN:
337 | canvas.drawCircle(0, getHeight() / 2, mCircleRadius,
338 | mAnimBottomPaint);
339 | break;
340 | case TYPE_HEADBAR_RIGHT_BTN:
341 | canvas.drawCircle(getWidth(), getHeight() / 2, mCircleRadius,
342 | mAnimBottomPaint);
343 | break;
344 | case TYPE_NORMAL_BTN:
345 | if (mAnimMode == SHAPE_MODE_EQUAL) {
346 | canvas.drawCircle(getWidth() / 2, getHeight() / 2,
347 | mCircleRadius, mAnimBottomPaint);
348 | } else {
349 | canvas.drawPaint(mAnimBottomPaint);
350 | }
351 | break;
352 | case TYPE_HEADER_CENTER_BTN:
353 | canvas.drawCircle(getWidth() / 2, getHeight() / 2,
354 | mCircleRadius, mAnimBottomPaint);
355 | break;
356 | }
357 | break;
358 | default:
359 | break;
360 | }
361 | canvas.restore();
362 | move();
363 | }
364 |
365 | private void move() {
366 | if (status == STATUS_NORMAL || status == STATUS_PRESSED)
367 | return;
368 | if (status == STATUS_ANIM_SLOWLY) {
369 | mAnimColorAlpha += mAnimColorAlphaSlowSpeed;
370 | mCircleRadius += mCirRSpeedSlow;
371 | } else if (status == STATUS_ANIM_FAST) {
372 | mAnimColorAlpha += mAnimColorAlphaFastSpeed;
373 | mCircleRadius += mCirRSpeedFast;
374 | } else if (status == STATUS_TO_NORMAL) {
375 | mAnimColorAlpha -= mAnimColorAlphaToNormalSpeed;
376 | mCircleRadius = mCircleRadiusMax;
377 | }
378 | if (mAnimColorAlpha >= mAnimColorAlphaMax) {
379 | mAnimColorAlpha = mAnimColorAlphaMax;
380 | }
381 | if (mAnimColorAlpha < 0) {
382 | mAnimColorAlpha = 0;
383 | }
384 | mAnimBottomPaint.setAlpha(mAnimColorAlpha);
385 | // Log.e(TAG, "mAnimColorAlpha-->" + mAnimColorAlpha);
386 | // mBottomColor = Color.argb(mAnimColorAlpha, 0, 0, 0);
387 | if (mCircleRadius > mCircleRadiusMax) {
388 | mCircleRadius = mCircleRadiusMax;
389 | }
390 | if (mAnimColorAlpha <= 0 || mAnimColorAlpha >= mAnimColorAlphaMax) {
391 | reset();
392 | }
393 | mDependView.invalidate();
394 | }
395 |
396 | private void reset() {
397 | switch (status) {
398 | case STATUS_ANIM_FAST:
399 | case STATUS_PRESSED:
400 | mCircleRadius = mCircleRadiusMax;
401 | status = STATUS_TO_NORMAL;
402 | break;
403 | case STATUS_ANIM_SLOWLY:
404 | status = STATUS_PRESSED;
405 | if (type == TYPE_HEADBAR_BACK_BTN || type == TYPE_HEADBAR_RIGHT_BTN) {
406 | mCircleRadius = getWidth();
407 | }
408 | break;
409 | case STATUS_TO_NORMAL:
410 | if (mNeedDelayClick && hasClick) {
411 | if (mCallBack != null)
412 | mCallBack.perfirmSuperClick();
413 | hasClick = false;
414 | }
415 | resetStatus();
416 | break;
417 | default:
418 | break;
419 | }
420 | mDependView.invalidate();
421 | }
422 |
423 | private boolean hasClick = false;
424 |
425 | public void resetStatus() {
426 | status = STATUS_NORMAL;
427 | hasClick = false;
428 | mCircleRadius = getHeight() / 4;
429 | mAnimColorAlpha = 0;
430 | }
431 |
432 | public void performClick() {
433 | if (status != STATUS_TO_NORMAL)
434 | status = STATUS_ANIM_FAST;
435 | if (!mNeedDelayClick) {
436 | if (mCallBack != null)
437 | mCallBack.perfirmSuperClick();
438 | } else {
439 | if (status == STATUS_PRESSED) {
440 | if (mCallBack != null)
441 | mCallBack.perfirmSuperClick();
442 | } else {
443 | hasClick = true;
444 | }
445 | }
446 | }
447 |
448 | public void dispatchKeyEvent() {
449 |
450 | }
451 |
452 | public void onTouchEvent(MotionEvent event) {
453 | switch (event.getAction()) {
454 | case MotionEvent.ACTION_DOWN:
455 | // Log.e(TAG, "onTouchEvent ACTION_DOWN");
456 | if (status != STATUS_NORMAL) {
457 | resetStatus();
458 | }
459 | actionDownX = event.getX();
460 | actionDownY = event.getY();
461 | switch (mAnimMode) {
462 | case SHAPE_MODE_EQUAL:
463 | actionDownX = getWidth() / 2;
464 | actionDownY = getHeight() / 2;
465 | break;
466 | case SHAPE_MODE_WIDTH:
467 | actionDownY = getHeight() / 2;
468 | break;
469 | case SHAPE_MODE_HEIGHT:
470 | actionDownX = getWidth() / 2;
471 | break;
472 | default:
473 | break;
474 | }
475 |
476 | status = STATUS_ANIM_SLOWLY;
477 | break;
478 | case MotionEvent.ACTION_MOVE:
479 | break;
480 | case MotionEvent.ACTION_CANCEL:
481 | case MotionEvent.ACTION_OUTSIDE:
482 | if (status == STATUS_ANIM_SLOWLY) {
483 | status = STATUS_ANIM_FAST;
484 | }
485 | case MotionEvent.ACTION_UP:
486 | if (status == STATUS_PRESSED) {
487 | reset();
488 | } else if (status == STATUS_ANIM_SLOWLY) {
489 | status = STATUS_ANIM_FAST;
490 | // resetSpeed();
491 | }
492 | break;
493 | default:
494 | break;
495 | }
496 | mDependView.invalidate();
497 | //return mClickListener == null ? false : true;
498 | }
499 |
500 | public boolean needBackgroundMeasure() {
501 | if (mBackgroundWidth <= 0 || mBackgroundHeight <= 0) {
502 | return false;
503 | }
504 | return true;
505 | }
506 |
507 | public int[] getMeasureSize(int widthMeasureSpec, int heightMeasureSpec) {
508 | int widthMode = MeasureSpec.getMode(widthMeasureSpec);
509 | int widthSize = MeasureSpec.getSize(widthMeasureSpec);
510 | int heightMode = MeasureSpec.getMode(heightMeasureSpec);
511 | int heightSize = MeasureSpec.getSize(heightMeasureSpec);
512 |
513 | int width;
514 | int height;
515 |
516 | if (widthMode == MeasureSpec.EXACTLY) {
517 | width = widthSize;
518 | } else if (widthMode == MeasureSpec.AT_MOST) {
519 | width = Math.min(mBackgroundWidth, widthSize);
520 | } else {
521 | width = mBackgroundWidth;
522 | }
523 |
524 | if (heightMode == MeasureSpec.EXACTLY) {
525 | height = heightSize;
526 | } else if (heightMode == MeasureSpec.AT_MOST) {
527 | height = Math.min(mBackgroundHeight, heightSize);
528 | } else {
529 | height = mBackgroundHeight;
530 | }
531 | return new int[] { width, height };
532 | // mDependView.setMeasuredDimension(width, height);
533 | }
534 |
535 | public void setDelayClick(boolean delayClick) {
536 | this.mNeedDelayClick = delayClick;
537 | }
538 |
539 | public void setBackground(Drawable background) {
540 | mBackgroundDrawable = background;
541 | mBackgroundColor = 0;
542 | if (mBackgroundDrawable != null) {
543 | mBackgroundWidth = mBackgroundDrawable.getIntrinsicWidth();
544 | mBackgroundHeight = mBackgroundDrawable.getIntrinsicHeight();
545 | }
546 | mDependView.requestLayout();
547 | mDependView.invalidate();
548 | }
549 |
550 | public void setBackgroundColor(int color) {
551 | // super.setBackgroundColor(color);
552 | mBackgroundDrawable = null;
553 | mBackgroundColor = color;
554 | }
555 |
556 | public void onWindowFocusChanged(boolean hasWindowFocus) {
557 | if (!hasWindowFocus) {
558 | resetStatus();
559 | }
560 | }
561 |
562 | public void onVisibilityChanged(View changedView, int visibility) {
563 | if (visibility != View.VISIBLE) {
564 | resetStatus();
565 | }
566 | }
567 |
568 | //public void setOnclickListener(OnClickListener listener) {
569 | // this.mClickListener = listener;
570 | //}
571 |
572 | }
573 |
--------------------------------------------------------------------------------