├── app
├── .gitignore
├── src
│ ├── main
│ │ ├── res
│ │ │ ├── values
│ │ │ │ ├── strings.xml
│ │ │ │ ├── colors.xml
│ │ │ │ ├── dimens.xml
│ │ │ │ └── styles.xml
│ │ │ ├── mipmap-hdpi
│ │ │ │ ├── gift.png
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-mdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xxhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xxxhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── values-w820dp
│ │ │ │ └── dimens.xml
│ │ │ └── layout
│ │ │ │ └── activity_main.xml
│ │ ├── AndroidManifest.xml
│ │ └── java
│ │ │ └── com
│ │ │ └── ldoublem
│ │ │ └── giftCard
│ │ │ └── MainActivity.java
│ ├── test
│ │ └── java
│ │ │ └── com
│ │ │ └── ldoublem
│ │ │ └── giftCard
│ │ │ └── ExampleUnitTest.java
│ └── androidTest
│ │ └── java
│ │ └── com
│ │ └── ldoublem
│ │ └── giftCard
│ │ └── ExampleInstrumentedTest.java
├── proguard-rules.pro
└── build.gradle
├── giftcardlib
├── .gitignore
├── src
│ ├── main
│ │ ├── res
│ │ │ ├── drawable
│ │ │ │ └── apple.png
│ │ │ └── values
│ │ │ │ ├── strings.xml
│ │ │ │ └── card_style.xml
│ │ ├── AndroidManifest.xml
│ │ └── java
│ │ │ └── com
│ │ │ └── ldoblem
│ │ │ └── giftcardlib
│ │ │ ├── models
│ │ │ └── Buyer.java
│ │ │ └── GiftCardView.java
│ ├── test
│ │ └── java
│ │ │ └── com
│ │ │ └── ldoblem
│ │ │ └── giftcardlib
│ │ │ └── ExampleUnitTest.java
│ └── androidTest
│ │ └── java
│ │ └── com
│ │ └── ldoblem
│ │ └── giftcardlib
│ │ └── ExampleInstrumentedTest.java
├── proguard-rules.pro
└── build.gradle
├── settings.gradle
├── screenshot
├── shot.gif
├── shot1.png
└── shot2.png
├── .idea
├── copyright
│ └── profiles_settings.xml
├── encodings.xml
├── vcs.xml
├── modules.xml
├── runConfigurations.xml
├── gradle.xml
├── compiler.xml
└── misc.xml
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── .gitignore
├── config
├── findbugs
│ └── findbugs-excludes.xml
├── check.gradle
├── checkstyle
│ └── checkstyle.xml
└── pmd
│ └── pmd-ruleset.xml
├── gradle.properties
├── gradlew.bat
├── README.md
└── gradlew
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/giftcardlib/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app', ':giftcardlib'
2 |
--------------------------------------------------------------------------------
/screenshot/shot.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ldoublem/GiftCard/HEAD/screenshot/shot.gif
--------------------------------------------------------------------------------
/screenshot/shot1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ldoublem/GiftCard/HEAD/screenshot/shot1.png
--------------------------------------------------------------------------------
/screenshot/shot2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ldoublem/GiftCard/HEAD/screenshot/shot2.png
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | GiftCard
3 |
4 |
--------------------------------------------------------------------------------
/.idea/copyright/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ldoublem/GiftCard/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/gift.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ldoublem/GiftCard/HEAD/app/src/main/res/mipmap-hdpi/gift.png
--------------------------------------------------------------------------------
/.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/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ldoublem/GiftCard/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ldoublem/GiftCard/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ldoublem/GiftCard/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/giftcardlib/src/main/res/drawable/apple.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ldoublem/GiftCard/HEAD/giftcardlib/src/main/res/drawable/apple.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ldoublem/GiftCard/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ldoublem/GiftCard/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/.idea/encodings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/giftcardlib/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | GiftCardLib
3 |
4 | Gift Card
5 | YOU ORDER WILL BE SHIPPED TO:
6 |
7 | Buy
8 | ok
9 |
10 |
11 |
--------------------------------------------------------------------------------
/giftcardlib/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/config/findbugs/findbugs-excludes.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/app/src/test/java/com/ldoublem/giftCard/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.ldoublem.giftcard;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() throws Exception {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/giftcardlib/src/test/java/com/ldoblem/giftcardlib/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.ldoblem.giftcardlib;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() throws Exception {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
11 |
12 |
--------------------------------------------------------------------------------
/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 /Users/lumingmin/Documents/android-sdk-macosx-3/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 |
--------------------------------------------------------------------------------
/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/giftcardlib/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 /Users/lumingmin/Documents/android-sdk-macosx-3/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 |
--------------------------------------------------------------------------------
/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/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 | org.gradle.jvmargs=-Xmx1536m
13 |
14 | # When configured, Gradle will run in incubating parallel mode.
15 | # This option should only be used with decoupled projects. More details, visit
16 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
17 | # org.gradle.parallel=true
18 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
11 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/giftcardlib/src/main/java/com/ldoblem/giftcardlib/models/Buyer.java:
--------------------------------------------------------------------------------
1 | package com.ldoblem.giftcardlib.models;
2 |
3 | public class Buyer {
4 |
5 | private final String name;
6 | private final String region;
7 |
8 | private final String address;
9 | private final String availableDay;
10 |
11 | public Buyer(String name, String region, String address, String availableDay) {
12 | this.name = name;
13 | this.region = region;
14 | this.address = address;
15 | this.availableDay = availableDay;
16 | }
17 |
18 | public String getName() {
19 | return name;
20 | }
21 |
22 | public String getRegion() {
23 | return region;
24 | }
25 |
26 | public String getAddress() {
27 | return address;
28 | }
29 |
30 | public String getAvailableDay() {
31 | return availableDay;
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/ldoublem/giftCard/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.ldoublem.giftcard;
2 |
3 | import android.content.Context;
4 | import android.support.test.InstrumentationRegistry;
5 | import android.support.test.runner.AndroidJUnit4;
6 |
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 |
10 | import static org.junit.Assert.*;
11 |
12 | /**
13 | * Instrumentation test, which will execute on an Android device.
14 | *
15 | * @see Testing documentation
16 | */
17 | @RunWith(AndroidJUnit4.class)
18 | public class ExampleInstrumentedTest {
19 | @Test
20 | public void useAppContext() throws Exception {
21 | // Context of the app under test.
22 | Context appContext = InstrumentationRegistry.getTargetContext();
23 |
24 | assertEquals("com.ldoublem.giftCard", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/giftcardlib/src/androidTest/java/com/ldoblem/giftcardlib/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.ldoblem.giftcardlib;
2 |
3 | import android.content.Context;
4 | import android.support.test.InstrumentationRegistry;
5 | import android.support.test.runner.AndroidJUnit4;
6 |
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 |
10 | import static org.junit.Assert.*;
11 |
12 | /**
13 | * Instrumentation test, which will execute on an Android device.
14 | *
15 | * @see Testing documentation
16 | */
17 | @RunWith(AndroidJUnit4.class)
18 | public class ExampleInstrumentedTest {
19 | @Test
20 | public void useAppContext() throws Exception {
21 | // Context of the app under test.
22 | Context appContext = InstrumentationRegistry.getTargetContext();
23 |
24 | assertEquals("com.ldoblem.giftcardlib.test", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/giftcardlib/src/main/res/values/card_style.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 | apply from: '../config/check.gradle'
3 |
4 | android {
5 | compileSdkVersion 23
6 | buildToolsVersion "23.0.3"
7 | defaultConfig {
8 | applicationId "com.ldoublem.giftCard"
9 | minSdkVersion 15
10 | targetSdkVersion 23
11 | versionCode 1
12 | versionName "1.0"
13 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
14 | }
15 | buildTypes {
16 | release {
17 | minifyEnabled false
18 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
19 | }
20 | }
21 | }
22 |
23 | dependencies {
24 | compile fileTree(include: ['*.jar'], dir: 'libs')
25 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
26 | exclude group: 'com.android.support', module: 'support-annotations'
27 | })
28 | compile 'com.android.support:appcompat-v7:23.4.0'
29 | compile 'com.android.support:design:23.4.0'
30 | compile 'com.android.support.constraint:constraint-layout:1.0.0-alpha3'
31 | testCompile 'junit:junit:4.12'
32 | // compile 'com.ldoublem.GiftCard:giftcardlib:0.2'
33 |
34 | compile project(':giftcardlib')
35 | }
36 |
--------------------------------------------------------------------------------
/config/check.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'checkstyle'
2 | apply plugin: 'pmd'
3 | apply plugin: 'findbugs'
4 |
5 | check.dependsOn 'checkstyle', 'findbugs', 'pmd', 'lint'
6 |
7 | task checkstyle(type: Checkstyle) {
8 | configFile file('../config/checkstyle/checkstyle.xml')
9 | source 'src/main/java'
10 | include '**/*.java'
11 | exclude '**/gen/**'
12 |
13 | classpath = files()
14 | }
15 |
16 | task pmd(type: Pmd) {
17 | ignoreFailures = false
18 | ruleSetFiles = files("${project.rootDir}/config/pmd/pmd-ruleset.xml")
19 | ruleSets = []
20 |
21 | source 'src'
22 | include '**/*.java'
23 | exclude '**/gen/**'
24 |
25 | reports {
26 | xml.enabled = false
27 | html.enabled = true
28 | xml {
29 | destination "$project.buildDir/reports/pmd/pmd.xml"
30 | }
31 | html {
32 | destination "$project.buildDir/reports/pmd/pmd.html"
33 | }
34 | }
35 | }
36 |
37 | task findbugs(type: FindBugs) {
38 | ignoreFailures = false
39 | effort = "max"
40 | excludeFilter = new File("${project.rootDir}/config/findbugs/findbugs-excludes.xml")
41 | classes = files("${project.rootDir}/app/build/intermediates/classes")
42 |
43 | source 'src'
44 | include '**/*.java'
45 | exclude '**/gen/**'
46 |
47 | reports {
48 | xml.enabled = false
49 | html.enabled = true
50 | xml {
51 | destination "$project.buildDir/reports/findbugs/findbugs.xml"
52 | }
53 | html {
54 | destination "$project.buildDir/reports/findbugs/findbugs.html"
55 | }
56 | }
57 |
58 | classpath = files()
59 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/ldoublem/giftCard/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.ldoublem.giftcard;
2 |
3 | import android.support.design.widget.Snackbar;
4 | import android.support.v7.app.AppCompatActivity;
5 | import android.os.Bundle;
6 | import android.view.WindowManager;
7 | import android.widget.Toast;
8 |
9 | import com.ldoblem.giftcardlib.GiftCardView;
10 | import com.ldoblem.giftcardlib.models.Buyer;
11 |
12 | public class MainActivity extends AppCompatActivity implements GiftCardView.OnCheckOut {
13 | GiftCardView mGiftCardView;
14 |
15 | @Override
16 | protected void onCreate(Bundle savedInstanceState) {
17 | super.onCreate(savedInstanceState);
18 | this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
19 | WindowManager.LayoutParams.FLAG_FULLSCREEN); //去掉信息栏
20 | setContentView(R.layout.activity_main);
21 | mGiftCardView = (GiftCardView) findViewById(R.id.gc_shop);
22 | // mGiftCardView.setMTitle("苹果礼券");
23 | // mGiftCardView.setMPrice(188);
24 | // mGiftCardView.setButtonBuyText("买");
25 | // mGiftCardView.setButtonCheckText("确定");
26 | // mGiftCardView.setCardTip("请检查你的购物单");
27 | // mGiftCardView.setCardBgColor(Color.BLACK);
28 | // mGiftCardView.setGiftLogo(R.mipmap.ic_launcher);
29 | // mGiftCardView.setBgStartColor(Color.BLACK);
30 | // mGiftCardView.setBgEndColor(Color.BLACK);
31 | // mGiftCardView.setBuyButtonColor(Color.BLACK);
32 | // mGiftCardView.setCheckButtonColor(Color.BLACK);
33 | // mGiftCardView.setPriceTextColor(Color.BLACK);
34 | // mGiftCardView.setBgPackBgColor(Color.BLACK);
35 | mGiftCardView.setOnCheckOut(new Buyer("陆先生", "中国浙江省",
36 | "杭州市,西湖区,南山路100号", "有效期:3天"),
37 | this);
38 |
39 | }
40 |
41 | @Override
42 | public void ok(int vid) {
43 | if (vid == R.id.gc_shop) {
44 | Snackbar.make(findViewById(R.id.snackbarPosition), "Thank you", Snackbar.LENGTH_SHORT)
45 | .show();
46 | mGiftCardView.restore();
47 | }
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 | 1.8
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
11 |
12 |
20 |
21 |
25 |
26 |
31 |
32 |
45 |
46 |
58 |
59 |
60 |
66 |
67 |
68 |
69 |
70 |
71 |
--------------------------------------------------------------------------------
/giftcardlib/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 | apply from: '../config/check.gradle'
3 |
4 | android {
5 | compileSdkVersion 23
6 | buildToolsVersion "23.0.3"
7 |
8 | defaultConfig {
9 | minSdkVersion 15
10 | targetSdkVersion 23
11 | versionCode 1
12 | versionName "1.0"
13 |
14 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
15 |
16 | }
17 | buildTypes {
18 | release {
19 | minifyEnabled false
20 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
21 | }
22 | }
23 | }
24 |
25 | dependencies {
26 | compile fileTree(dir: 'libs', include: ['*.jar'])
27 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
28 | exclude group: 'com.android.support', module: 'support-annotations'
29 | })
30 | compile 'com.android.support:appcompat-v7:23.4.0'
31 | testCompile 'junit:junit:4.12'
32 | }
33 | apply plugin: 'com.github.dcendents.android-maven'
34 | apply plugin: 'com.jfrog.bintray'
35 |
36 | version = "0.3"
37 | def siteUrl = 'https://github.com/ldoublem/GiftCard' // project homepage
38 | def gitUrl = 'https://github.com/ldoublem/GiftCard.git' // project git
39 | group = "com.ldoublem.GiftCard"
40 |
41 |
42 | install {
43 | repositories.mavenInstaller {
44 | // This generates POM.xml with proper parameters
45 | pom {
46 | project {
47 | packaging 'aar'
48 | name 'GiftCard For Android'//一些描述
49 | url siteUrl
50 | licenses {
51 | license {
52 | name 'The Apache software License, Version 2.0'
53 | url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
54 | }
55 | }
56 | developers {
57 | developer {//开发者信息
58 | id ''
59 | name 'ldoublem'
60 | email '122710260@qq.com'
61 | }
62 | }
63 | scm {
64 | connection gitUrl
65 | developerConnection gitUrl
66 | url siteUrl
67 | }
68 | }
69 | }
70 | }
71 | }
72 | task sourcesJar(type: Jar) {
73 | from android.sourceSets.main.java.srcDirs
74 | classifier = 'sources'
75 | }
76 |
77 | task javadoc(type: Javadoc) {
78 | source = android.sourceSets.main.java.srcDirs
79 | classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
80 | }
81 |
82 | task javadocJar(type: Jar, dependsOn: javadoc) {
83 | classifier = 'javadoc'
84 | from javadoc.destinationDir
85 | }
86 |
87 | javadoc {
88 | options{
89 | encoding 'UTF-8'
90 | charSet 'UTF-8'
91 | author true
92 | }
93 | }
94 |
95 | artifacts {
96 | archives javadocJar
97 | archives sourcesJar
98 | }
99 |
100 |
101 | Properties properties = new Properties()
102 | properties.load(project.rootProject.file('local.properties').newDataInputStream())
103 | bintray {
104 | user = properties.getProperty("bintray.user")
105 | key = properties.getProperty("bintray.apikey")
106 | configurations = ['archives']
107 | pkg {
108 | repo = "maven"
109 | name = "GiftCard" // project name in maven
110 | websiteUrl = siteUrl
111 | vcsUrl = gitUrl
112 | licenses = ["Apache-2.0"]
113 | publish = true
114 | }
115 | }
116 |
117 |
118 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # GiftCard
2 | A beautiful gift Cards for android
3 |
4 | Inspiration comes from [dribbble](https://dribbble.com/shots/2045026-Gift-Card)
5 |
6 | #Preview
7 | ---
8 | 
9 | 
10 | 
11 |
12 | #Requirements
13 | Use [Android Studio 2.2 Preview 5](http://tools.android.com/download/studio/canary/latest) or higher, as the following are not available in earlier versions:
14 |
15 | * `com.android.tools.build:gradle:2.2.0-alpha5`
16 | * `com.android.support.constraint:constraint-layout:1.0.0-alpha3`
17 |
18 | #Gradle
19 | compile 'com.ldoublem.GiftCard:giftcardlib:0.3'
20 |
21 | ---
22 | Usage with xml
23 | ```
24 |
37 | ```
38 | Usage with java
39 | ```
40 | mGiftCardView = (GiftCardView) findViewById(R.id.gc_shop);
41 | mGiftCardView.setMTitle("苹果礼券");
42 | mGiftCardView.setMPrice(188);
43 | mGiftCardView.setButtonBuyText("买");
44 | mGiftCardView.setButtonCheckText("确定");
45 | mGiftCardView.setCardTip("请检查你的购物单");
46 | mGiftCardView.setCardBgColor(Color.BLACK);
47 | mGiftCardView.setGiftLogo(R.mipmap.ic_launcher);
48 | mGiftCardView.setBgStartColor(Color.BLACK);
49 | mGiftCardView.setBgEndColor(Color.BLACK);
50 | mGiftCardView.setBuyButtonColor(Color.BLACK);
51 | mGiftCardView.setCheckButtonColor(Color.BLACK);
52 | mGiftCardView.setPriceTextColor(Color.BLACK);
53 | mGiftCardView.setBgPackBgColor(Color.BLACK);
54 | mGiftCardView.setOnCheckOut(new GiftCardView.Buyer("陆先生", "中国浙江省",
55 | "杭州市,西湖区,南山路100号", "有效期:3天"),
56 | new GiftCardView.OnCheckOut() {
57 | @Override
58 | public void Ok(int vid) {
59 |
60 | }
61 | });
62 | ```
63 |
64 | ## About me
65 |
66 | An android developer in Hangzhou.
67 |
68 | If you want to make friends with me, You can email to me.
69 | my [email](mailto:1227102260@qq.com) :smiley:
70 |
71 |
72 | License
73 | =======
74 |
75 | The MIT License (MIT)
76 |
77 | Copyright (c) 2016 ldoublem
78 |
79 | Permission is hereby granted, free of charge, to any person obtaining a copy
80 | of this software and associated documentation files (the "Software"), to deal
81 | in the Software without restriction, including without limitation the rights
82 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
83 | copies of the Software, and to permit persons to whom the Software is
84 | furnished to do so, subject to the following conditions:
85 |
86 | The above copyright notice and this permission notice shall be included in all
87 | copies or substantial portions of the Software.
88 |
89 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
90 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
91 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
92 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
93 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
94 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
95 | SOFTWARE.
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
--------------------------------------------------------------------------------
/config/checkstyle/checkstyle.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
7 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
117 |
118 |
119 |
120 |
121 |
122 |
123 |
124 |
125 |
126 |
127 |
128 |
129 |
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 |
--------------------------------------------------------------------------------
/config/pmd/pmd-ruleset.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 | 3
8 |
9 |
10 | 3
11 |
12 |
13 | 3
14 |
15 |
16 | 3
17 |
18 |
19 | 3
20 |
21 |
22 | 3
23 |
24 |
25 | 3
26 |
27 |
28 | 3
29 |
30 |
31 | 3
32 |
33 |
34 | 2
35 |
36 |
37 | 4
38 |
39 |
40 | 3
41 |
42 |
43 | 3
44 |
45 |
46 | 3
47 |
48 |
49 | 4
50 |
51 |
52 | 3
53 |
54 |
55 | 2
56 |
57 |
58 | 3
59 |
60 |
61 | 3
62 |
63 |
64 | 3
65 |
66 |
67 | 3
68 |
69 |
70 | 4
71 |
72 |
73 | 2
74 |
75 |
76 | 4
77 |
78 |
79 | 3
80 |
81 |
82 | 3
83 |
84 |
85 | 3
86 |
87 |
88 | 2
89 |
90 |
91 | 4
92 |
93 |
94 | 2
95 |
96 |
97 | 3
98 |
99 |
100 | 5
101 |
102 |
103 | 3
104 |
105 |
106 | 3
107 |
108 |
109 | 2
110 |
111 |
112 | 3
113 |
114 |
115 | 1
116 |
117 |
118 | 1
119 |
120 |
121 | 3
122 |
123 |
124 | 3
125 |
126 |
127 | 2
128 |
129 |
130 | 3
131 |
132 |
133 | 3
134 |
135 |
136 | 4
137 |
138 |
139 | 4
140 |
141 |
142 | 3
143 |
144 |
145 | 3
146 |
147 |
148 | 3
149 |
150 |
151 | 3
152 |
153 |
154 | 3
155 |
156 |
157 | 3
158 |
159 |
160 | 3
161 |
162 |
163 | 3
164 |
165 |
166 |
167 |
168 |
169 | 3
170 |
171 |
172 | 3
173 |
174 |
175 | 3
176 |
177 |
178 | 3
179 |
180 |
181 |
182 |
183 |
184 | 4
185 |
186 |
187 | 3
188 |
189 |
190 | 3
191 |
192 |
193 | 4
194 |
195 |
196 | 3
197 |
198 |
199 | 3
200 |
201 |
202 | 3
203 |
204 |
205 | 3
206 |
207 |
208 | 3
209 |
210 |
211 | 3
212 |
213 |
214 | 3
215 |
216 |
217 | 3
218 |
219 |
220 | 3
221 |
222 |
223 | 3
224 |
225 |
226 | 3
227 |
228 |
229 |
230 |
231 |
232 | 3
233 |
234 |
235 | 3
236 |
237 |
238 | 3
239 |
240 |
241 | 3
242 |
243 |
244 | 3
245 |
246 |
247 | 4
248 |
249 |
250 | 3
251 |
252 |
253 | 3
254 |
255 |
256 | 3
257 |
258 |
259 | 4
260 |
261 |
262 | 3
263 |
264 |
265 | 3
266 |
267 |
268 | 3
269 |
270 |
271 | 3
272 |
273 |
274 | 3
275 |
276 |
277 |
278 |
279 |
280 | 3
281 |
282 |
283 |
284 |
--------------------------------------------------------------------------------
/giftcardlib/src/main/java/com/ldoblem/giftcardlib/GiftCardView.java:
--------------------------------------------------------------------------------
1 | package com.ldoblem.giftcardlib;
2 |
3 | import android.animation.Animator;
4 | import android.animation.AnimatorListenerAdapter;
5 | import android.animation.ValueAnimator;
6 | import android.content.Context;
7 | import android.content.res.TypedArray;
8 | import android.graphics.Bitmap;
9 | import android.graphics.BitmapFactory;
10 | import android.graphics.Canvas;
11 | import android.graphics.Color;
12 | import android.graphics.LinearGradient;
13 | import android.graphics.Paint;
14 | import android.graphics.Path;
15 | import android.graphics.Rect;
16 | import android.graphics.RectF;
17 | import android.graphics.Shader;
18 | import android.util.AttributeSet;
19 | import android.view.MotionEvent;
20 | import android.view.View;
21 | import android.view.animation.LinearInterpolator;
22 | import android.widget.Toast;
23 | import com.ldoblem.giftcardlib.models.Buyer;
24 |
25 | /**
26 | * Created by lumingmin on 16/7/14.
27 | */
28 |
29 | public class GiftCardView extends View {
30 | private Paint mPaintBg;
31 | private Paint mPaintText;
32 | private Paint mPaintBuyButton;
33 |
34 | private Path mPathBg;
35 | private RectF rectFBg;
36 | private RectF rectFBgMove;
37 |
38 | private Path mPathPackLeft;
39 | private Path mPathPackTop;
40 | private Path mPathPackBottom;
41 |
42 | private Path mPathPackRight;
43 |
44 | private Path mPathsilkTop;
45 | private Path mPathsilkBottom;
46 | private Path mPathsilkLeft;
47 | private Path mPathsilkRight;
48 |
49 | private RectF rectFBuyButton;
50 | private RectF rectFCheckButton;
51 |
52 | private float mPadding = 0f;
53 |
54 | private float mCircular = 0f;
55 | private Shader mShader;
56 |
57 | private String mTitle;
58 | private float mPrice = 25.00f;
59 |
60 | private String mButtonBuyText;
61 | private String mButtonCheckText;
62 | private String cardTip;
63 |
64 | private float mBuyButtonH = 0f;
65 | private float mBuyButtonW = 0f;
66 |
67 | private int bgStartColor = Color.rgb(231, 0, 148);
68 | private int bgEndColor = Color.rgb(164, 13, 158);
69 | private int buyButtonColor = Color.rgb(243, 152, 0);
70 |
71 | private int checkButtonColor = Color.rgb(8, 156, 239);
72 |
73 | private int cardBgColor = Color.WHITE;
74 | private int giftLogo = R.drawable.apple;
75 | private int bgPackBgColor = Color.rgb(252, 44, 44);
76 |
77 | private int mPriceTextColor = Color.rgb(150, 150, 150);
78 |
79 | private Buyer mBuyer;
80 |
81 | private OnCheckOut mOnCheckOut;
82 |
83 | private boolean pressBuyButton = false;
84 | private boolean pressCheckButton = false;
85 |
86 | private ValueAnimator valueAnimator;
87 | private float mAnimatedBgValue = 0f;
88 | private float mAmAnimatedPackValue = 0f;
89 |
90 |
91 | public GiftCardView(Context context) {
92 | this(context, null);
93 | }
94 |
95 | public GiftCardView(Context context, AttributeSet attrs) {
96 | this(context, attrs, 0);
97 | }
98 |
99 | public GiftCardView(Context context, AttributeSet attrs, int defStyleAttr) {
100 | super(context, attrs, defStyleAttr);
101 | init(attrs);
102 | }
103 |
104 | public void setMTitle(String text) {
105 | this.mTitle = text;
106 | }
107 |
108 | public void setMPrice(float price) {
109 | this.mPrice = price;
110 | }
111 |
112 | public void setCardTip(String text) {
113 | this.cardTip = text;
114 | }
115 |
116 | public void setButtonBuyText(String text) {
117 | this.mButtonBuyText = text;
118 | }
119 |
120 | public void setButtonCheckText(String text) {
121 | this.mButtonCheckText = text;
122 | }
123 |
124 | public void setCardBgColor(int color) {
125 | this.cardBgColor = color;
126 | }
127 |
128 | public void setGiftLogo(int id) {
129 | this.giftLogo = id;
130 | }
131 |
132 | public void setBgStartColor(int bgStartColor) {
133 | this.bgStartColor = bgStartColor;
134 | }
135 |
136 | public void setBgEndColor(int bgEndColor) {
137 | this.bgEndColor = bgEndColor;
138 | }
139 |
140 | public void setBuyButtonColor(int buyButtonColor) {
141 | this.buyButtonColor = buyButtonColor;
142 | }
143 |
144 | public void setCheckButtonColor(int checkButtonColor) {
145 | this.checkButtonColor = checkButtonColor;
146 | }
147 |
148 | public void setBgPackBgColor(int bgPackBgColor) {
149 | this.bgPackBgColor = bgPackBgColor;
150 | }
151 |
152 | public void setPriceTextColor(int mPriceTextColor) {
153 | this.mPriceTextColor = mPriceTextColor;
154 | }
155 |
156 |
157 | public void setOnCheckOut(Buyer buyer, OnCheckOut onCheckOut) {
158 | this.mBuyer = buyer;
159 | this.mOnCheckOut = onCheckOut;
160 | invalidate();
161 | }
162 |
163 | private void init(AttributeSet attrs) {
164 | TypedArray typedArray = getContext().obtainStyledAttributes(attrs, R.styleable.CardView);
165 | if (typedArray != null) {
166 | // isCanvasLine = typedArray.getBoolean(R.styleable.SelectView_isCanvasLine, true);
167 | // mTextSize = typedArray.getDimension(R.styleable.SelectView_textSize, dip2px(12));
168 | bgStartColor = typedArray.getColor(R.styleable.CardView_bgStartColor, bgStartColor);
169 | bgEndColor = typedArray.getColor(R.styleable.CardView_bgEndColor, bgEndColor);
170 | buyButtonColor = typedArray.getColor(R.styleable.CardView_buyButtonColor, buyButtonColor);
171 | checkButtonColor = typedArray.getColor(R.styleable.CardView_checkButtonColor, checkButtonColor);
172 | cardBgColor = typedArray.getColor(R.styleable.CardView_cardBgColor, cardBgColor);
173 | bgPackBgColor = typedArray.getColor(R.styleable.CardView_bgPackColor, bgPackBgColor);
174 |
175 | mPriceTextColor = typedArray.getColor(R.styleable.CardView_priceTextColor, mPriceTextColor);
176 |
177 |
178 | giftLogo = typedArray.getResourceId(R.styleable.CardView_cardGiftLogo, R.drawable.apple);
179 | mTitle = typedArray.getString(R.styleable.CardView_cardGiftTitle);
180 | if (mTitle == null) {
181 | mTitle = getContext().getString(R.string.card_title);
182 | }
183 |
184 | cardTip = getContext().getString(R.string.card_tip);
185 |
186 | mButtonCheckText = typedArray.getString(R.styleable.CardView_buttonCheckText);
187 | if (mButtonCheckText == null) {
188 | mButtonCheckText = getContext().getString(R.string.button_check_test);
189 | }
190 | mButtonBuyText = typedArray.getString(R.styleable.CardView_buttonByText);
191 | if (mButtonBuyText == null) {
192 | mButtonBuyText = getContext().getString(R.string.button_buy);
193 | }
194 |
195 |
196 | mPrice = typedArray.getFloat(R.styleable.CardView_cardGiftPrice, 0);
197 |
198 | // mUnit = typedArray.getDimension(R.styleable.SelectView_unitSize, 50.f);
199 | // mUnitLongLine = typedArray.getInteger(R.styleable.SelectView_unitLongLine, 5);
200 | // textSelectColor = typedArray.getColor(R.styleable.SelectView_textSelectColor, Color.rgb(151, 151, 151));
201 |
202 | typedArray.recycle();
203 | }
204 | initPaint();
205 | }
206 |
207 |
208 | public void setBuyer(Buyer buyer) {
209 | this.mBuyer = buyer;
210 | }
211 |
212 | private void initPaint() {
213 |
214 | mBuyer = new Buyer("ldoublem", "Zhejiang Province",
215 | "Hangzhou , Xihu , Nanshan Road", "Available to ship: 1 business day");
216 |
217 | mPaintBg = new Paint();
218 | mPaintBg.setAntiAlias(true);
219 | mPaintBg.setColor(Color.WHITE);
220 | mPaintBg.setStyle(Paint.Style.FILL);
221 |
222 | mPaintText = new Paint();
223 | mPaintText.setAntiAlias(true);
224 | mPaintText.setColor(Color.WHITE);
225 | mPaintText.setStyle(Paint.Style.FILL);
226 |
227 |
228 | mPaintBuyButton = new Paint();
229 | mPaintBuyButton.setAntiAlias(true);
230 | mPaintBuyButton.setColor(buyButtonColor);
231 | mPaintBuyButton.setStyle(Paint.Style.FILL);
232 |
233 |
234 | mPathBg = new Path();
235 | mPathBg.reset();
236 | mPathPackLeft = new Path();
237 | mPathPackBottom = new Path();
238 | mPathPackTop = new Path();
239 | mPathPackRight = new Path();
240 | mPathPackLeft.reset();
241 | mPathPackRight.reset();
242 | mPathPackTop.reset();
243 | mPathPackBottom.reset();
244 |
245 |
246 | mPathsilkTop = new Path();
247 | mPathsilkBottom = new Path();
248 | mPathsilkRight = new Path();
249 | mPathsilkLeft = new Path();
250 | mPathsilkTop.reset();
251 | mPathsilkBottom.reset();
252 | mPathsilkLeft.reset();
253 | mPathsilkRight.reset();
254 | rectFBg = new RectF();
255 | rectFBgMove = new RectF();
256 | rectFBuyButton = new RectF();
257 | rectFCheckButton = new RectF();
258 | mPadding = dip2px(1);
259 | mShader = new Shader();
260 |
261 | }
262 |
263 | @Override
264 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
265 | super.onMeasure(widthMeasureSpec, heightMeasureSpec);
266 | int widthSpecMode = MeasureSpec.getMode(widthMeasureSpec);
267 | int widthSpecSize = MeasureSpec.getSize(widthMeasureSpec);
268 | int heightSpecMode = MeasureSpec.getMode(heightMeasureSpec);
269 | int heightSpecSize = MeasureSpec.getSize(heightMeasureSpec);
270 | if (widthSpecMode == MeasureSpec.AT_MOST
271 | && heightSpecMode == MeasureSpec.AT_MOST) {
272 | // 指定wrap_content模式(MeasureSpec.AT_MOST)的默认宽高,比如200px
273 | setMeasuredDimension(dip2px(200), dip2px(150));
274 | } else if (widthSpecMode == MeasureSpec.AT_MOST) {
275 | setMeasuredDimension(dip2px(200), heightSpecSize);
276 | } else if (heightSpecMode == MeasureSpec.AT_MOST) {
277 | setMeasuredDimension(widthSpecSize, dip2px(150));
278 | }
279 | }
280 |
281 |
282 | private void drawBg(Canvas canvas) {
283 | mPathBg.reset();
284 | mPathBg.moveTo(rectFBg.left, rectFBg.top + rectFBg.height() / 3f * 2f);
285 | mPathBg.lineTo(rectFBg.left, rectFBg.top + mCircular);
286 | mPathBg.quadTo(rectFBg.left, rectFBg.top, rectFBg.left + mCircular, rectFBg.top);
287 | mPathBg.lineTo(rectFBg.right - mCircular, rectFBg.top);
288 | mPathBg.quadTo(rectFBg.right, rectFBg.top, rectFBg.right, rectFBg.top + mCircular);
289 | mPathBg.lineTo(rectFBg.right, rectFBg.top + rectFBg.height() / 3f * 2f);
290 | mPathBg.close();
291 |
292 | mPaintBg.setColor(cardBgColor);
293 | canvas.drawPath(mPathBg, mPaintBg);
294 |
295 | mPaintText.setTextSize(mCircular - 1);
296 |
297 | mBuyButtonW = (getFontHeight(mPaintText, mButtonBuyText)) * 4.5f;
298 |
299 | mBuyButtonH = mBuyButtonW / 3f;
300 |
301 | rectFBgMove.top = rectFBg.top;
302 | rectFBgMove.bottom = rectFBg.bottom;
303 | rectFBgMove.left = rectFBg.left
304 | - mAnimatedBgValue * (rectFBg.width() - mCircular * 2 - mBuyButtonW);
305 | rectFBgMove.right = rectFBg.right
306 | - mAnimatedBgValue * (rectFBg.width() - mCircular * 2 - mBuyButtonW);
307 | }
308 |
309 | private void drawCardTopBg(Canvas canvas) {
310 | mPathBg.reset();
311 |
312 | float mRightLeft = mCircular * mAnimatedBgValue;
313 | float mTop = mAnimatedBgValue * rectFBg.height() / 3f * 2f;
314 |
315 | if (rectFBg.height() / 3f * 2f - mTop < mCircular / 2) {
316 | if (mAnimatedBgValue <= 1.0f) {
317 | mPathBg.moveTo(rectFBg.left + mRightLeft,
318 | rectFBg.top + rectFBg.height() / 3f * 2f);
319 | mPathBg.lineTo(rectFBg.left + mRightLeft,
320 | rectFBg.top + rectFBg.height() / 3f * 2f - 2);
321 | mPathBg.lineTo(rectFBg.right - mRightLeft,
322 | rectFBg.top + rectFBg.height() / 3f * 2f - 2);
323 | mPathBg.lineTo(rectFBg.right - mRightLeft,
324 | rectFBg.top + rectFBg.height() / 3f * 2f);
325 | } else {
326 | mRightLeft = mCircular;
327 | mPathBg.moveTo(rectFBg.left + mRightLeft,
328 | rectFBg.top + rectFBg.height() / 3f * 2f);
329 | mPathBg.lineTo(rectFBg.left + mRightLeft,
330 | rectFBg.top + rectFBg.height() / 3f * 2f - 2);
331 | mPathBg.lineTo(rectFBg.right - mRightLeft,
332 | rectFBg.top + rectFBg.height() / 3f * 2f - 2);
333 | mPathBg.lineTo(rectFBg.right - mRightLeft,
334 | rectFBg.top + rectFBg.height() / 3f * 2f);
335 | }
336 |
337 | } else {
338 | mPathBg.moveTo(rectFBg.left + mRightLeft, rectFBg.top + rectFBg.height() / 3f * 2f);
339 | mPathBg.lineTo(rectFBg.left + mRightLeft, rectFBg.top + mCircular + mTop);
340 | mPathBg.quadTo(rectFBg.left + mRightLeft, rectFBg.top + mTop,
341 | rectFBg.left + mCircular + mRightLeft, rectFBg.top + mTop);
342 | mPathBg.lineTo(rectFBg.right - mCircular - mRightLeft, rectFBg.top + mTop);
343 | mPathBg.quadTo(rectFBg.right - mRightLeft, rectFBg.top + mTop,
344 | rectFBg.right - mRightLeft, rectFBg.top + mCircular + mTop);
345 | mPathBg.lineTo(rectFBg.right - mRightLeft, rectFBg.top + rectFBg.height() / 3f * 2f);
346 | mPathBg.close();
347 |
348 | }
349 | setShader(mPaintBg, bgStartColor, bgEndColor);
350 | canvas.drawPath(mPathBg, mPaintBg);
351 | mPaintBg.setShader(null);
352 | }
353 |
354 | private void drawCardTopBgShadow(Canvas canvas) {
355 | if (mAnimatedBgValue > 0.1f) {
356 | return;
357 | }
358 | mPathBg.reset();
359 |
360 | mPathBg.moveTo(rectFBg.left, rectFBg.top + rectFBg.height() / 3f * 2f);
361 | mPathBg.lineTo(rectFBg.left, rectFBg.top + rectFBg.height() / 3f * 2f
362 | - (rectFBg.height() / 3f * 2f) / 4f);
363 | mPathBg.quadTo(rectFBg.left,
364 | rectFBg.top + rectFBg.height() / 3f * 2f,
365 | rectFBg.right,
366 | rectFBg.top + rectFBg.height() / 3f
367 | );
368 | mPathBg.lineTo(rectFBg.right, rectFBg.top + rectFBg.height() / 3f * 2f);
369 | mPathBg.close();
370 |
371 | mPaintBg.setColor(Color.argb(30, 255, 255, 255));
372 | canvas.drawPath(mPathBg, mPaintBg);
373 | mPaintBg.setShader(null);
374 | }
375 |
376 | private void drawLogo(Canvas canvas) {
377 | if (mAnimatedBgValue < 1f) {
378 | mPaintBg.setColor(Color.WHITE);
379 | Bitmap ios = setBitmapSize(giftLogo, (int) (rectFBg.height() / 4f ));
380 | canvas.drawBitmap(ios, rectFBg.centerX() - ios.getWidth() / 2,
381 | rectFBg.top + rectFBg.height() / 3f - ios.getHeight() / 2
382 | + rectFBg.height() / 4.5f * (mAnimatedBgValue), mPaintBg);
383 | }
384 | }
385 |
386 | private void drawCardBottomBg(Canvas canvas) {
387 | mPathBg.reset();
388 | mPathBg.moveTo(rectFBg.left, rectFBg.top + rectFBg.height() / 3f * 2f);
389 | mPathBg.lineTo(rectFBg.left, rectFBg.bottom - mCircular);
390 | mPathBg.quadTo(rectFBg.left, rectFBg.bottom,
391 | rectFBg.left + mCircular, rectFBg.bottom);
392 | mPathBg.lineTo(rectFBg.right - mCircular, rectFBg.bottom);
393 | mPathBg.quadTo(rectFBg.right, rectFBg.bottom,
394 | rectFBg.right, rectFBg.bottom - mCircular);
395 | mPathBg.lineTo(rectFBg.right, rectFBg.top + rectFBg.height() / 3f * 2f);
396 | mPathBg.close();
397 |
398 | mPaintBg.setColor(cardBgColor);
399 | canvas.drawPath(mPathBg, mPaintBg);
400 | }
401 |
402 | private void drawTitleAndPrice(Canvas canvas) {
403 | setShader(mPaintText, bgStartColor, bgEndColor);
404 | mPaintText.setTextSize(mCircular + 1);
405 | canvas.drawText(mTitle, rectFBgMove.left + mCircular,
406 | rectFBgMove.top + rectFBgMove.height() / 3f * 2f + rectFBgMove.height() / 6f
407 | - getFontHeight(mPaintText, mTitle) / 2f,
408 | mPaintText);
409 | mPaintText.setShader(null);
410 |
411 | mPaintText.setColor(mPriceTextColor);
412 | mPaintText.setTextSize(mCircular - 1);
413 |
414 | String price = "$" + new java.text.DecimalFormat("#.00").format(mPrice);
415 |
416 | canvas.drawText(price, rectFBgMove.left + mCircular,
417 | rectFBgMove.top + rectFBgMove.height() / 3f * 2f
418 | + rectFBgMove.height() / 6f + getFontHeight(mPaintText, price),
419 | mPaintText);
420 | }
421 |
422 | private void drawBuyButton(Canvas canvas) {
423 | mPaintBuyButton.setColor(buyButtonColor);
424 | mPaintText.setTextSize(mCircular - 1);
425 | rectFBuyButton.top = rectFBgMove.top + rectFBgMove.height() / 3f * 2f
426 | + rectFBgMove.height() / 6f - mBuyButtonH;
427 | rectFBuyButton.bottom = rectFBgMove.top + rectFBgMove.height() / 3f * 2f
428 | + rectFBgMove.height() / 6f + mBuyButtonH;
429 | rectFBuyButton.right = rectFBgMove.right - mCircular;
430 | rectFBuyButton.left = rectFBgMove.right - mCircular - mBuyButtonW;
431 |
432 | if (pressBuyButton) {
433 | rectFBuyButton.top += 4;
434 | rectFBuyButton.left += 4;
435 | rectFBuyButton.bottom -= 4;
436 | rectFBuyButton.right -= 4;
437 | }
438 |
439 | canvas.drawRoundRect(rectFBuyButton, mCircular / 2f, mCircular / 2f, mPaintBuyButton);
440 | mPaintText.setColor(Color.WHITE);
441 | canvas.drawText(mButtonBuyText,
442 | rectFBuyButton.centerX() - getFontlength(mPaintText, mButtonBuyText) / 2f,
443 | rectFBuyButton.centerY() + getFontHeight(mPaintText, mButtonBuyText) / 3f,
444 | mPaintText);
445 |
446 | if (mAmAnimatedPackValue > 0f && mAmAnimatedPackValue <= 0.4f) {
447 | drawBuyButtonFrom0to4(canvas);
448 | } else if (mAmAnimatedPackValue > 0.4f && mAmAnimatedPackValue <= 0.5f) {
449 | drawBuyButtonFrom4to5(canvas);
450 | } else if (mAmAnimatedPackValue > 0.5f && mAmAnimatedPackValue <= 1f) {
451 | drawBuyButtonFrom5to10(canvas);
452 | }
453 | }
454 |
455 | private void drawBuyButtonFrom0to4(Canvas canvas) {
456 | float packValueFirst = mAmAnimatedPackValue / 0.4f;
457 | float maxHigh = rectFBuyButton.height() / 2f * 0.8f;
458 |
459 | mPaintBuyButton.setColor(bgPackBgColor);
460 | mPathPackTop.reset();
461 | mPathPackTop.moveTo(rectFBuyButton.left + mCircular / 2f, rectFBuyButton.top);
462 | mPathPackTop.lineTo(rectFBuyButton.right - mCircular / 2f, rectFBuyButton.top);
463 |
464 | mPathPackTop.lineTo(rectFBuyButton.right - mCircular / 2f
465 | - maxHigh * (1 - packValueFirst), rectFBuyButton.top
466 | - maxHigh * (1 - packValueFirst));
467 |
468 | mPathPackTop.lineTo(rectFBuyButton.left + mCircular / 2f
469 | + maxHigh * (1 - packValueFirst),
470 | rectFBuyButton.top - maxHigh * (1 - packValueFirst));
471 |
472 | mPathPackTop.close();
473 | mPaintBuyButton.setAlpha(200);
474 | canvas.drawPath(mPathPackTop, mPaintBuyButton);
475 |
476 | mPathPackTop.reset();
477 | mPathPackTop.moveTo(rectFBuyButton.right - mCircular / 2f
478 | - maxHigh * (1 - packValueFirst),
479 | rectFBuyButton.top - maxHigh * (1 - packValueFirst));
480 |
481 | mPathPackTop.lineTo(rectFBuyButton.left + mCircular / 2f
482 | + maxHigh * (1 - packValueFirst),
483 | rectFBuyButton.top - maxHigh * (1 - packValueFirst));
484 |
485 | mPathPackTop.lineTo(rectFBuyButton.centerX(),
486 | rectFBuyButton.top - maxHigh * (1 - packValueFirst) + maxHigh * packValueFirst);
487 | mPathPackTop.close();
488 | mPaintBuyButton.setAlpha(255);
489 |
490 | canvas.drawPath(mPathPackTop, mPaintBuyButton);
491 |
492 | mPathPackBottom.reset();
493 | mPathPackBottom.moveTo(rectFBuyButton.left + mCircular / 2f, rectFBuyButton.bottom);
494 | mPathPackBottom.lineTo(rectFBuyButton.right - mCircular / 2f, rectFBuyButton.bottom);
495 |
496 | mPathPackBottom.lineTo(rectFBuyButton.right - mCircular / 2f
497 | - maxHigh * (1 - packValueFirst),
498 | rectFBuyButton.bottom + maxHigh * (1 - packValueFirst));
499 |
500 | mPathPackBottom.lineTo(rectFBuyButton.left + mCircular / 2f
501 | + maxHigh * (1 - packValueFirst),
502 | rectFBuyButton.bottom + maxHigh * (1 - packValueFirst));
503 |
504 | mPathPackBottom.close();
505 | mPaintBuyButton.setAlpha(200);
506 | canvas.drawPath(mPathPackBottom, mPaintBuyButton);
507 |
508 | mPathPackBottom.reset();
509 | mPathPackBottom.moveTo(rectFBuyButton.right - mCircular / 2f
510 | - maxHigh * (1 - packValueFirst),
511 | rectFBuyButton.bottom + maxHigh * (1 - packValueFirst));
512 |
513 | mPathPackBottom.lineTo(rectFBuyButton.left + mCircular / 2f
514 | + maxHigh * (1 - packValueFirst),
515 | rectFBuyButton.bottom + maxHigh * (1 - packValueFirst));
516 | mPathPackBottom.lineTo(rectFBuyButton.centerX(),
517 | rectFBuyButton.bottom + maxHigh * (1 - packValueFirst)
518 | - maxHigh * packValueFirst
519 |
520 | );
521 | mPathPackBottom.close();
522 | mPaintBuyButton.setAlpha(255);
523 |
524 | canvas.drawPath(mPathPackBottom, mPaintBuyButton);
525 |
526 | float maxWidth = rectFBuyButton.height() / 2f * 0.5f;
527 |
528 | mPathPackLeft.reset();
529 | mPathPackLeft.moveTo(rectFBuyButton.left, rectFBuyButton.top + mCircular / 2f);
530 | mPathPackLeft.lineTo(rectFBuyButton.left, rectFBuyButton.bottom - mCircular / 2f);
531 | mPathPackLeft.lineTo(rectFBuyButton.left - maxWidth * (1 - packValueFirst),
532 | rectFBuyButton.bottom - mCircular / 2f - maxWidth * (1 - packValueFirst)
533 | );
534 | mPathPackLeft.lineTo(rectFBuyButton.left - maxWidth * (1 - packValueFirst),
535 | rectFBuyButton.top + mCircular / 2f + maxWidth * (1 - packValueFirst));
536 |
537 | mPathPackLeft.close();
538 | mPaintBuyButton.setAlpha(200);
539 | canvas.drawPath(mPathPackLeft, mPaintBuyButton);
540 |
541 | mPathPackLeft.reset();
542 | mPathPackLeft.moveTo(rectFBuyButton.left - maxWidth * (1 - packValueFirst),
543 | rectFBuyButton.bottom - mCircular / 2f - maxWidth * (1 - packValueFirst));
544 | mPathPackLeft.lineTo(rectFBuyButton.left - maxWidth * (1 - packValueFirst),
545 | rectFBuyButton.top + mCircular / 2f + maxWidth * (1 - packValueFirst));
546 |
547 | mPathPackLeft.lineTo(rectFBuyButton.left - maxWidth * (1 - packValueFirst)
548 | + maxWidth * packValueFirst, rectFBuyButton.centerY());
549 |
550 | mPathPackLeft.close();
551 | mPaintBuyButton.setAlpha(255);
552 | canvas.drawPath(mPathPackLeft, mPaintBuyButton);
553 |
554 | mPathPackRight.reset();
555 | mPathPackRight.moveTo(rectFBuyButton.right, rectFBuyButton.top + mCircular / 2f);
556 | mPathPackRight.lineTo(rectFBuyButton.right, rectFBuyButton.bottom - mCircular / 2f);
557 | mPathPackRight.lineTo(rectFBuyButton.right + maxWidth * (1 - packValueFirst),
558 | rectFBuyButton.bottom - mCircular / 2f - maxWidth * (1 - packValueFirst)
559 | );
560 | mPathPackRight.lineTo(rectFBuyButton.right + maxWidth * (1 - packValueFirst),
561 | rectFBuyButton.top + mCircular / 2f + maxWidth * (1 - packValueFirst));
562 |
563 | mPathPackRight.close();
564 | mPaintBuyButton.setAlpha(200);
565 | canvas.drawPath(mPathPackRight, mPaintBuyButton);
566 |
567 | mPathPackRight.reset();
568 | mPathPackRight.moveTo(rectFBuyButton.right + maxWidth * (1 - packValueFirst),
569 | rectFBuyButton.bottom - mCircular / 2f - maxWidth * (1 - packValueFirst));
570 | mPathPackRight.lineTo(rectFBuyButton.right + maxWidth * (1 - packValueFirst),
571 | rectFBuyButton.top + mCircular / 2f + maxWidth * (1 - packValueFirst));
572 |
573 | mPathPackRight.lineTo(rectFBuyButton.right + maxWidth * (1 - packValueFirst)
574 | - maxWidth * packValueFirst,
575 | rectFBuyButton.centerY());
576 |
577 | mPathPackRight.close();
578 | mPaintBuyButton.setAlpha(255);
579 | canvas.drawPath(mPathPackRight, mPaintBuyButton);
580 | }
581 |
582 | private void drawBuyButtonFrom4to5(Canvas canvas) {
583 | mPaintBuyButton.setColor(bgPackBgColor);
584 |
585 | canvas.drawRoundRect(rectFBuyButton, mCircular / 2f, mCircular / 2f, mPaintBuyButton);
586 |
587 | float packValueFirst = (mAmAnimatedPackValue - 0.4f) / 0.1f;
588 |
589 | mPaintBuyButton.setColor(Color.rgb(253, 209, 48));
590 | // mPaintBuyButton.setAlpha(200);
591 | mPathsilkTop.reset();
592 | mPathsilkTop.moveTo(rectFBuyButton.left + mCircular * 1.1f, rectFBuyButton.top);
593 | mPathsilkTop.lineTo(rectFBuyButton.left + mCircular * 1.1f + mCircular / 1.5f,
594 | rectFBuyButton.top);
595 | mPathsilkTop.lineTo(rectFBuyButton.left + mCircular * 1.1f + mCircular / 1.5f,
596 | rectFBuyButton.top - packValueFirst * mCircular / 2f);
597 | mPathsilkTop.lineTo(rectFBuyButton.left + mCircular * 1.1f,
598 | rectFBuyButton.top - packValueFirst * mCircular / 2f
599 | );
600 |
601 | mPathsilkTop.close();
602 | canvas.drawPath(mPathsilkTop, mPaintBuyButton);
603 |
604 | mPathsilkBottom.reset();
605 | mPathsilkBottom.moveTo(rectFBuyButton.left + mCircular * 1.1f, rectFBuyButton.bottom);
606 | mPathsilkBottom.lineTo(rectFBuyButton.left + mCircular * 1.1f + mCircular / 1.5f,
607 | rectFBuyButton.bottom);
608 | mPathsilkBottom.lineTo(rectFBuyButton.left + mCircular * 1.1f + mCircular / 1.5f,
609 | rectFBuyButton.bottom + mCircular / 2f * packValueFirst);
610 | mPathsilkBottom.lineTo(rectFBuyButton.left + mCircular * 1.1f, rectFBuyButton.bottom
611 | + mCircular / 2f * packValueFirst
612 | );
613 |
614 | mPathsilkBottom.close();
615 | canvas.drawPath(mPathsilkBottom, mPaintBuyButton);
616 |
617 | mPathsilkLeft.reset();
618 | mPathsilkLeft.moveTo(rectFBuyButton.left, rectFBuyButton.top + mCircular / 1.4f);
619 | mPathsilkLeft.lineTo(rectFBuyButton.left, rectFBuyButton.top + mCircular / 1.4f
620 | + mCircular / 1.5f);
621 | mPathsilkLeft.lineTo(rectFBuyButton.left - mCircular / 2f * packValueFirst
622 | , rectFBuyButton.top + mCircular / 1.4f + mCircular / 1.5f
623 | );
624 | mPathsilkLeft.lineTo(rectFBuyButton.left - mCircular / 2f * packValueFirst
625 | , rectFBuyButton.top + mCircular / 1.4f
626 | );
627 |
628 | mPathsilkLeft.close();
629 | canvas.drawPath(mPathsilkLeft, mPaintBuyButton);
630 |
631 | mPathsilkRight.reset();
632 | mPathsilkRight.moveTo(rectFBuyButton.right, rectFBuyButton.top + mCircular / 1.4f);
633 | mPathsilkRight.lineTo(rectFBuyButton.right, rectFBuyButton.top + mCircular / 1.4f
634 | + mCircular / 1.5f);
635 | mPathsilkRight.lineTo(rectFBuyButton.right + mCircular / 2f * packValueFirst,
636 | rectFBuyButton.top + mCircular / 1.4f + mCircular / 1.5f
637 | );
638 | mPathsilkRight.lineTo(rectFBuyButton.right + mCircular / 2f * packValueFirst,
639 | rectFBuyButton.top + mCircular / 1.4f
640 | );
641 |
642 | mPathsilkRight.close();
643 | canvas.drawPath(mPathsilkRight, mPaintBuyButton);
644 | }
645 |
646 | private void drawBuyButtonFrom5to10(Canvas canvas) {
647 | mPaintBuyButton.setColor(bgPackBgColor);
648 |
649 | canvas.drawRoundRect(rectFBuyButton, mCircular / 2f, mCircular / 2f, mPaintBuyButton);
650 |
651 | float packValueSecond = (mAmAnimatedPackValue - 0.5f) / 0.5f;
652 | if (packValueSecond >= 1f) {
653 | packValueSecond = 1f;
654 | }
655 |
656 | mPaintBuyButton.setColor(Color.rgb(253, 209, 48));
657 | float maxSilkTopH = rectFBuyButton.height() / 3f + mCircular;
658 | float maxSilkBottpmH = rectFBuyButton.height() / 3f * 2 + mCircular;
659 | mPathsilkTop.reset();
660 | mPathsilkTop.moveTo(rectFBuyButton.left + mCircular * 1.1f, rectFBuyButton.top);
661 | mPathsilkTop.lineTo(rectFBuyButton.left + mCircular * 1.1f + mCircular / 1.5f,
662 | rectFBuyButton.top);
663 | mPathsilkTop.lineTo(rectFBuyButton.left + mCircular * 1.1f + mCircular / 1.5f,
664 | rectFBuyButton.top + maxSilkTopH * packValueSecond - mCircular / 2f
665 | );
666 | mPathsilkTop.lineTo(rectFBuyButton.left + mCircular * 1.1f,
667 | rectFBuyButton.top + maxSilkTopH * packValueSecond - mCircular / 2f
668 | );
669 |
670 | mPathsilkTop.close();
671 | canvas.drawPath(mPathsilkTop, mPaintBuyButton);
672 |
673 | mPathsilkBottom.reset();
674 | mPathsilkBottom.moveTo(rectFBuyButton.left + mCircular * 1.1f, rectFBuyButton.bottom);
675 | mPathsilkBottom.lineTo(rectFBuyButton.left + mCircular * 1.1f + mCircular / 1.5f,
676 | rectFBuyButton.bottom);
677 | mPathsilkBottom.lineTo(rectFBuyButton.left + mCircular * 1.1f + mCircular / 1.5f,
678 | rectFBuyButton.bottom - maxSilkBottpmH * packValueSecond + mCircular / 2f);
679 | mPathsilkBottom.lineTo(rectFBuyButton.left + mCircular * 1.1f,
680 | rectFBuyButton.bottom - maxSilkBottpmH * packValueSecond + mCircular / 2f
681 | );
682 |
683 | mPathsilkBottom.close();
684 | canvas.drawPath(mPathsilkBottom, mPaintBuyButton);
685 |
686 | float maxSilkLeftW = mCircular + mCircular;
687 |
688 | mPathsilkLeft.reset();
689 | mPathsilkLeft.moveTo(rectFBuyButton.left, rectFBuyButton.top + mCircular / 1.4f);
690 | mPathsilkLeft.lineTo(rectFBuyButton.left, rectFBuyButton.top + mCircular / 1.4f
691 | + mCircular / 1.5f);
692 | mPathsilkLeft.lineTo(rectFBuyButton.left + maxSilkLeftW * packValueSecond
693 | - mCircular / 2f,
694 | rectFBuyButton.top + mCircular / 1.4f + mCircular / 1.5f
695 | );
696 | mPathsilkLeft.lineTo(rectFBuyButton.left + maxSilkLeftW * packValueSecond
697 | - mCircular / 2f,
698 | rectFBuyButton.top + mCircular / 1.4f
699 | );
700 |
701 | mPathsilkLeft.close();
702 | canvas.drawPath(mPathsilkLeft, mPaintBuyButton);
703 |
704 | float maxSilkRightW = rectFBuyButton.width() - mCircular + mCircular;
705 |
706 | mPathsilkRight.reset();
707 | mPathsilkRight.moveTo(rectFBuyButton.right, rectFBuyButton.top + mCircular / 1.4f);
708 | mPathsilkRight.lineTo(rectFBuyButton.right, rectFBuyButton.top + mCircular / 1.4f
709 | + mCircular / 1.5f);
710 | mPathsilkRight.lineTo(rectFBuyButton.right - maxSilkRightW * packValueSecond
711 | + mCircular / 2f,
712 | rectFBuyButton.top + mCircular / 1.4f + mCircular / 1.5f
713 | );
714 | mPathsilkRight.lineTo(rectFBuyButton.right - maxSilkRightW * packValueSecond
715 | + mCircular / 2f,
716 | rectFBuyButton.top + mCircular / 1.4f
717 | );
718 |
719 | mPathsilkRight.close();
720 | canvas.drawPath(mPathsilkRight, mPaintBuyButton);
721 |
722 | if (mAmAnimatedPackValue > 0.8f && mAmAnimatedPackValue <= 1f) {
723 | mPaintBuyButton.setColor(Color.rgb(254, 230, 51));
724 | float packValueThird = (mAmAnimatedPackValue - 0.8f) / 0.2f;
725 |
726 | Path bowknotLeftTop = new Path();
727 | bowknotLeftTop.reset();
728 |
729 | float x = (float) ((mCircular / 3f) * Math.cos(90 * Math.PI / 180f));
730 | float y = (float) ((mCircular / 3f) * Math.sin(90 * Math.PI / 180f));
731 |
732 | bowknotLeftTop.moveTo(rectFBuyButton.left + mCircular * 1.1f + mCircular / 3f - x,
733 | rectFBuyButton.top + mCircular / 1.4f + mCircular / 3f - y);
734 |
735 | float x2 = (float) ((mCircular / 3f) * Math.cos(-60 * Math.PI / 180f));
736 | float y2 = (float) ((mCircular / 3f) * Math.sin(-60 * Math.PI / 180f));
737 |
738 | bowknotLeftTop.lineTo(rectFBuyButton.left + mCircular * 1.1f + mCircular / 3f - x2,
739 | rectFBuyButton.top + mCircular / 1.4f + mCircular / 3f - y2);
740 |
741 | bowknotLeftTop.lineTo(rectFBuyButton.left + mCircular * 1.1f
742 | + mCircular / 3f - x2 - mCircular,
743 | rectFBuyButton.top + mCircular / 1.4f - y2);
744 |
745 | bowknotLeftTop.lineTo(rectFBuyButton.left + mCircular * 1.1f
746 | + mCircular / 3f - x - mCircular,
747 | rectFBuyButton.top + mCircular / 1.4f - y);
748 | bowknotLeftTop.close();
749 | canvas.drawPath(bowknotLeftTop, mPaintBuyButton);
750 |
751 | Path bowknotRighrTop = new Path();
752 | bowknotRighrTop.reset();
753 | float x3 = (float) ((mCircular / 3f) * Math.cos(240 * Math.PI / 180f));
754 | float y3 = (float) ((mCircular / 3f) * Math.sin(240 * Math.PI / 180f));
755 |
756 | bowknotRighrTop.moveTo(rectFBuyButton.left + mCircular * 1.1f + mCircular / 3f - x,
757 | rectFBuyButton.top + mCircular / 1.4f + mCircular / 3f - y);
758 |
759 | bowknotRighrTop.lineTo(rectFBuyButton.left + mCircular * 1.1f + mCircular / 3f - x3,
760 | rectFBuyButton.top + mCircular / 1.4f + mCircular / 3f - y3);
761 | bowknotRighrTop.lineTo(rectFBuyButton.left + mCircular * 1.1f
762 | + mCircular / 3f - x3 + mCircular,
763 | rectFBuyButton.top + mCircular / 1.4f - y3);
764 |
765 | bowknotRighrTop.lineTo(rectFBuyButton.left + mCircular * 1.1f
766 | + mCircular / 3f - x + mCircular,
767 | rectFBuyButton.top + mCircular / 1.4f - y);
768 |
769 | bowknotRighrTop.close();
770 | canvas.drawPath(bowknotRighrTop, mPaintBuyButton);
771 |
772 | float space = mCircular / 3 * 2 * 1.2f;
773 | Path bowknotLeftBottom = new Path();
774 | bowknotLeftBottom.reset();
775 | float x4 = (float) ((mCircular / 3f) * Math.cos(270 * Math.PI / 180f));
776 | float y4 = (float) ((mCircular / 3f) * Math.sin(270 * Math.PI / 180f));
777 | bowknotLeftBottom.moveTo(rectFBuyButton.left + mCircular * 1.1f
778 | + mCircular / 3f - x4,
779 | rectFBuyButton.top + mCircular / 1.4f + mCircular / 3f - y4);
780 |
781 | bowknotLeftBottom.lineTo(rectFBuyButton.left + mCircular * 1.1f
782 | + mCircular / 3f - x4 - space,
783 | rectFBuyButton.top + mCircular / 1.4f + mCircular / 3f - y4 + space);
784 |
785 | bowknotLeftBottom.lineTo(rectFBuyButton.left + mCircular * 1.1f
786 | + mCircular / 3f - x4 - space,
787 | rectFBuyButton.top + mCircular / 1.4f + mCircular / 3f - y4
788 | + space - space / 2);
789 |
790 | bowknotLeftBottom.lineTo(rectFBuyButton.left + mCircular * 1.1f
791 | + mCircular / 3f - x4 - space - space / 2,
792 | rectFBuyButton.top + mCircular / 1.4f + mCircular / 3f - y4
793 | + space - space / 2);
794 |
795 | bowknotLeftBottom.lineTo(rectFBuyButton.left + mCircular * 1.1f
796 | + mCircular / 3f - x4,
797 | rectFBuyButton.top + mCircular / 1.4f + mCircular / 3f - y4 - space);
798 | bowknotLeftBottom.close();
799 | canvas.drawPath(bowknotLeftBottom, mPaintBuyButton);
800 |
801 | Path bowknotRightBottom = new Path();
802 | bowknotRightBottom.reset();
803 |
804 | bowknotRightBottom.moveTo(rectFBuyButton.left + mCircular * 1.1f
805 | + mCircular / 3f - x4,
806 | rectFBuyButton.top + mCircular / 1.4f + mCircular / 3f - y4);
807 |
808 | bowknotRightBottom.lineTo(rectFBuyButton.left + mCircular * 1.1f
809 | + mCircular / 3f - x4 + space,
810 | rectFBuyButton.top + mCircular / 1.4f + mCircular / 3f - y4 + space);
811 |
812 | bowknotRightBottom.lineTo(rectFBuyButton.left + mCircular * 1.1f
813 | + mCircular / 3f - x4 + space,
814 | rectFBuyButton.top + mCircular / 1.4f + mCircular / 3f - y4
815 | + space - space / 2);
816 |
817 | bowknotRightBottom.lineTo(rectFBuyButton.left + mCircular * 1.1f
818 | + mCircular / 3f - x4 + space + space / 2,
819 | rectFBuyButton.top + mCircular / 1.4f + mCircular / 3f - y4
820 | + space - space / 2);
821 |
822 | bowknotRightBottom.lineTo(rectFBuyButton.left + mCircular * 1.1f
823 | + mCircular / 3f - x4,
824 | rectFBuyButton.top + mCircular / 1.4f + mCircular / 3f - y4 - space);
825 | bowknotRightBottom.close();
826 | canvas.drawPath(bowknotRightBottom, mPaintBuyButton);
827 |
828 | mPaintBuyButton.setColor(Color.GRAY);
829 |
830 | canvas.drawCircle(rectFBuyButton.left + mCircular * 1.1f + mCircular / 3f,
831 | rectFBuyButton.top + mCircular / 1.4f + mCircular / 3f,
832 | (mCircular / 3f * 1.401f) * packValueThird, mPaintBuyButton);
833 |
834 | mPaintBuyButton.setColor(Color.rgb(254, 230, 51));
835 |
836 | canvas.drawCircle(rectFBuyButton.left + mCircular * 1.1f + mCircular / 3f,
837 | rectFBuyButton.top + mCircular / 1.4f + mCircular / 3f,
838 | (mCircular / 3f * 1.4f) * packValueThird,
839 | mPaintBuyButton
840 | );
841 | }
842 | }
843 |
844 | private void drawCheckOutButton(Canvas canvas) {
845 |
846 | if (mAnimatedBgValue > 0.5f) {
847 | mPaintBuyButton.setColor(checkButtonColor);
848 | rectFCheckButton.top = rectFBgMove.top + rectFBgMove.height() / 3f * 2f
849 | + rectFBgMove.height() / 6f - mBuyButtonH;
850 | rectFCheckButton.bottom = rectFBgMove.top + rectFBgMove.height() / 3f * 2f
851 | + rectFBgMove.height() / 6f + mBuyButtonH;
852 | rectFCheckButton.right = rectFBgMove.right - mCircular
853 | + (rectFBg.width() - mCircular * 2 - mBuyButtonW);
854 | rectFCheckButton.left = rectFBgMove.right - mCircular - mBuyButtonW
855 | + (rectFBg.width() - mCircular * 2 - mBuyButtonW);
856 |
857 |
858 | if (pressCheckButton) {
859 | rectFCheckButton.bottom -= 4;
860 | rectFCheckButton.top += 4;
861 | rectFCheckButton.left += 4;
862 | rectFCheckButton.right -= 4;
863 | }
864 |
865 | canvas.drawRoundRect(rectFCheckButton, mCircular / 2f, mCircular / 2f, mPaintBuyButton);
866 | mPaintText.setColor(Color.WHITE);
867 | mPaintText.setTextSize(mCircular - 1);
868 | canvas.drawText(mButtonCheckText, rectFCheckButton.centerX() - getFontlength(mPaintText,
869 | mButtonCheckText) / 2f,
870 | rectFCheckButton.centerY() + getFontHeight(mPaintText, mButtonCheckText) / 3f,
871 | mPaintText);
872 | }
873 | }
874 |
875 | private void drawCardContent(Canvas canvas) {
876 |
877 | if (mAnimatedBgValue > 0.6f) {
878 | mPaintText.setTextSize(mCircular * 0.8f);
879 | mPaintText.setColor(Color.BLACK);
880 | canvas.drawText(cardTip, rectFBuyButton.left,
881 | rectFBg.top + mCircular + getFontHeight(mPaintText, cardTip),
882 | mPaintText);
883 |
884 |
885 | if (mBuyer != null) {
886 | canvas.drawText(mBuyer.getName(), rectFBuyButton.left,
887 | rectFBg.top + mCircular + getFontHeight(mPaintText, mBuyer.getName()) * 3,
888 | mPaintText);
889 |
890 | mPaintText.setColor(mPriceTextColor);
891 |
892 | canvas.drawText(mBuyer.getRegion(), rectFBuyButton.left,
893 | rectFBg.top + mCircular + getFontHeight(mPaintText, mBuyer.getRegion()) * 4
894 | + getFontHeight(mPaintText, mBuyer.getName()) / 2,
895 | mPaintText);
896 | canvas.drawText(mBuyer.getAddress(), rectFBuyButton.left,
897 | rectFBg.top + mCircular + getFontHeight(mPaintText, mBuyer.getAddress()) * 5f
898 | + getFontHeight(mPaintText, mBuyer.getName()) / 2,
899 | mPaintText);
900 |
901 | canvas.drawText(mBuyer.getAvailableDay(), rectFBuyButton.left,
902 | rectFBg.top + mCircular + getFontHeight(mPaintText,
903 | mBuyer.getAvailableDay()) * 8, mPaintText);
904 | }
905 | }
906 | }
907 |
908 |
909 | @Override
910 | protected void onDraw(Canvas canvas) {
911 | super.onDraw(canvas);
912 | canvas.save();
913 |
914 | mCircular = (getMeasuredWidth() / 20);
915 | rectFBg.top = mPadding;
916 | rectFBg.left = mPadding;
917 | rectFBg.bottom = getMeasuredHeight() - mPadding;
918 | rectFBg.right = getMeasuredWidth() - mPadding;
919 |
920 |
921 | drawBg(canvas);
922 | drawCardTopBg(canvas);
923 | drawCardTopBgShadow(canvas);
924 | drawLogo(canvas);
925 | drawCardBottomBg(canvas);
926 | drawTitleAndPrice(canvas);
927 | drawBuyButton(canvas);
928 | drawCheckOutButton(canvas);
929 | drawCardContent(canvas);
930 | canvas.restore();
931 |
932 | }
933 |
934 | private float getFontlength(Paint paint, String str) {
935 | Rect rect = new Rect();
936 | paint.getTextBounds(str, 0, str.length(), rect);
937 | return rect.width();
938 | }
939 |
940 | private float getFontHeight(Paint paint, String str) {
941 | Rect rect = new Rect();
942 | paint.getTextBounds(str, 0, str.length(), rect);
943 | return rect.height();
944 | }
945 |
946 | private int dip2px(float dpValue) {
947 | final float scale = getContext().getResources().getDisplayMetrics().density;
948 | return (int) (dpValue * scale + 0.5f);
949 | }
950 |
951 | private Bitmap setBitmapSize(int iconId, int w) {
952 | Bitmap bitmap = BitmapFactory.decodeResource(getContext().getResources(), iconId);
953 | float s = w * 1.0f / bitmap.getWidth();
954 | bitmap = Bitmap.createScaledBitmap(bitmap, (int) (bitmap.getWidth() * s),
955 | (int) (bitmap.getHeight() * s), true);
956 | return bitmap;
957 | }
958 |
959 | private void setShader(Paint p, int startColor, int endColor) {
960 | mShader = new LinearGradient(rectFBg.left, rectFBg.top,
961 | rectFBg.right, rectFBg.bottom,
962 | new int[]{startColor, endColor},
963 | new float[]{0f, 1f},
964 | Shader.TileMode.CLAMP);
965 | p.setColor(startColor);
966 | p.setShader(mShader);
967 | }
968 |
969 |
970 | @Override
971 | public boolean onTouchEvent(MotionEvent event) {
972 | int action = event.getAction();
973 |
974 | switch (action) {
975 | case MotionEvent.ACTION_DOWN:
976 | getParent().requestDisallowInterceptTouchEvent(false);
977 |
978 | pressBuyButton = rectFBuyButton.contains(event.getX(), event.getY())
979 | && mAmAnimatedPackValue == 0f;
980 | invalidate();
981 |
982 |
983 | break;
984 | case MotionEvent.ACTION_MOVE:
985 |
986 | if (rectFBuyButton.contains(event.getX(), event.getY())
987 | && mAmAnimatedPackValue == 0f) {
988 | pressBuyButton = true;
989 | invalidate();
990 | } else if (pressBuyButton) {
991 | pressBuyButton = false;
992 | invalidate();
993 | }
994 |
995 | if (rectFCheckButton.contains(event.getX(), event.getY())
996 | && mAnimatedBgValue == 1.0f) {
997 | pressCheckButton = true;
998 | invalidate();
999 | } else if (pressCheckButton) {
1000 | pressCheckButton = false;
1001 | invalidate();
1002 | }
1003 |
1004 |
1005 | break;
1006 | case MotionEvent.ACTION_UP:
1007 | case MotionEvent.ACTION_CANCEL:
1008 | getParent().requestDisallowInterceptTouchEvent(false);
1009 | pressBuyButton = false;
1010 | pressCheckButton = false;
1011 | if (rectFBuyButton.contains(event.getX(), event.getY())
1012 | && mAmAnimatedPackValue == 0f) {
1013 | startAnim(1);
1014 | } else if (rectFCheckButton.contains(event.getX(), event.getY())
1015 | && mAnimatedBgValue == 1.0f) {
1016 | // Toast.makeText(getContext(), "111", Toast.LENGTH_SHORT).show();
1017 | if (mOnCheckOut != null) {
1018 | mOnCheckOut.ok(getId());
1019 | } else {
1020 | Toast.makeText(getContext(), "OnCheckOut is null", Toast.LENGTH_SHORT)
1021 | .show();
1022 | }
1023 | postInvalidate();
1024 |
1025 | }
1026 |
1027 |
1028 | return false;
1029 | default:
1030 | break;
1031 | }
1032 | return true;
1033 | }
1034 |
1035 | private void startAnim(int step) {
1036 | if (step == 1) {
1037 | stopAnim();
1038 | startViewAnim(0f, 1f, 600, step);
1039 | } else if (step == 2) {
1040 | startViewAnim(0f, 1f, 400, step);
1041 |
1042 | }
1043 | }
1044 |
1045 | public void restore() {
1046 | if (valueAnimator != null) {
1047 | clearAnimation();
1048 | valueAnimator.setRepeatCount(0);
1049 | valueAnimator.cancel();
1050 | mAmAnimatedPackValue = 0f;
1051 | mAnimatedBgValue = 0f;
1052 | postInvalidate();
1053 | }
1054 | }
1055 |
1056 | private void stopAnim() {
1057 | if (valueAnimator != null) {
1058 | clearAnimation();
1059 | valueAnimator.setRepeatCount(0);
1060 | valueAnimator.cancel();
1061 | // valueAnimator.end();
1062 | mAmAnimatedPackValue = 0f;
1063 | mAnimatedBgValue = 0f;
1064 | postInvalidate();
1065 | }
1066 | }
1067 |
1068 |
1069 | private ValueAnimator startViewAnim(float startF, final float endF, long time, final int step) {
1070 | valueAnimator = ValueAnimator.ofFloat(startF, endF);
1071 | valueAnimator.setDuration(time);
1072 | valueAnimator.setInterpolator(new LinearInterpolator());
1073 | valueAnimator.setRepeatCount(0);
1074 | valueAnimator.setRepeatMode(ValueAnimator.RESTART);
1075 | valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
1076 | @Override
1077 | public void onAnimationUpdate(ValueAnimator valueAnimator) {
1078 |
1079 | // mAnimatedBgValue = (float) valueAnimator.getAnimatedValue() ;
1080 | if (step == 1) {
1081 | mAmAnimatedPackValue = (float) valueAnimator.getAnimatedValue();
1082 | } else if (step == 2) {
1083 | mAnimatedBgValue = (float) valueAnimator.getAnimatedValue();
1084 |
1085 | }
1086 | invalidate();
1087 | }
1088 | });
1089 | valueAnimator.addListener(new AnimatorListenerAdapter() {
1090 | @Override
1091 | public void onAnimationEnd(Animator animation) {
1092 | super.onAnimationEnd(animation);
1093 | if (step == 1) {
1094 | startAnim(2);
1095 | }
1096 | }
1097 |
1098 | });
1099 | if (!valueAnimator.isRunning()) {
1100 | valueAnimator.start();
1101 |
1102 | }
1103 |
1104 | return valueAnimator;
1105 | }
1106 |
1107 | public interface OnCheckOut {
1108 | void ok(int vid);
1109 | }
1110 |
1111 |
1112 | }
1113 |
--------------------------------------------------------------------------------