├── .idea
├── .name
├── copyright
│ └── profiles_settings.xml
├── scopes
│ └── scope_settings.xml
├── encodings.xml
├── vcs.xml
├── misc.xml
├── modules.xml
├── gradle.xml
└── compiler.xml
├── app
├── .gitignore
├── src
│ ├── main
│ │ ├── res
│ │ │ ├── drawable-hdpi
│ │ │ │ ├── icon.png
│ │ │ │ ├── ic_launcher.png
│ │ │ │ ├── ic_cloud_queue_black_24dp.png
│ │ │ │ └── butto.xml
│ │ │ ├── drawable-mdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── drawable-xhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── drawable-xxhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── values
│ │ │ │ ├── styles.xml
│ │ │ │ ├── dimens.xml
│ │ │ │ └── strings.xml
│ │ │ ├── menu
│ │ │ │ └── menu_main.xml
│ │ │ ├── values-w820dp
│ │ │ │ └── dimens.xml
│ │ │ └── layout
│ │ │ │ ├── activity_main.xml
│ │ │ │ └── custom_notification.xml
│ │ ├── AndroidManifest.xml
│ │ └── java
│ │ │ └── com
│ │ │ └── mingle
│ │ │ └── headsupdemo
│ │ │ └── MainActivity.java
│ └── androidTest
│ │ └── java
│ │ └── com
│ │ └── mingle
│ │ └── headsupdemo
│ │ └── ApplicationTest.java
├── build.gradle
├── proguard-rules.pro
└── app.iml
├── library
├── .gitignore
├── src
│ ├── main
│ │ ├── res
│ │ │ ├── drawable-hdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ ├── notification_bg2.9.png
│ │ │ │ ├── notification_bg3.9.png
│ │ │ │ ├── bg_transparency_to_grey.xml
│ │ │ │ └── notification_bg.xml
│ │ │ ├── drawable-mdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── drawable-xhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── drawable-xxhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── values
│ │ │ │ ├── dimens.xml
│ │ │ │ ├── strings.xml
│ │ │ │ ├── defualt.xml
│ │ │ │ └── circle_imageview_attrs.xml
│ │ │ ├── values-w820dp
│ │ │ │ └── dimens.xml
│ │ │ ├── menu
│ │ │ │ └── my.xml
│ │ │ └── layout
│ │ │ │ ├── notification_bg.xml
│ │ │ │ └── notification.xml
│ │ ├── AndroidManifest.xml
│ │ └── java
│ │ │ └── com
│ │ │ └── mingle
│ │ │ └── headsUp
│ │ │ ├── Distance.java
│ │ │ ├── HeadsUpManager.java
│ │ │ ├── widget
│ │ │ └── CircleImageView.java
│ │ │ ├── HeadsUp.java
│ │ │ └── FloatView.java
│ └── androidTest
│ │ └── java
│ │ └── com
│ │ └── example
│ │ └── administrator
│ │ └── ll
│ │ └── ApplicationTest.java
├── build.gradle
├── proguard-rules.pro
└── library.iml
├── settings.gradle
├── Demo.apk
├── .gitignore
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradle.properties
├── HeadsUp.iml
├── HeadsUpDemo.iml
├── gradlew.bat
├── README.markdown
└── gradlew
/.idea/.name:
--------------------------------------------------------------------------------
1 | HeadsUp
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/library/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app', ':library'
2 |
--------------------------------------------------------------------------------
/Demo.apk:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zzz40500/HeadsUp/HEAD/Demo.apk
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | .gradle
2 | /local.properties
3 | /.idea/workspace.xml
4 | /.idea/libraries
5 | .DS_Store
6 | /build
7 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zzz40500/HeadsUp/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/.idea/copyright/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable-hdpi/icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zzz40500/HeadsUp/HEAD/app/src/main/res/drawable-hdpi/icon.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zzz40500/HeadsUp/HEAD/app/src/main/res/drawable-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zzz40500/HeadsUp/HEAD/app/src/main/res/drawable-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zzz40500/HeadsUp/HEAD/app/src/main/res/drawable-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zzz40500/HeadsUp/HEAD/app/src/main/res/drawable-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/library/src/main/res/drawable-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zzz40500/HeadsUp/HEAD/library/src/main/res/drawable-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/library/src/main/res/drawable-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zzz40500/HeadsUp/HEAD/library/src/main/res/drawable-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/library/src/main/res/drawable-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zzz40500/HeadsUp/HEAD/library/src/main/res/drawable-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/library/src/main/res/drawable-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zzz40500/HeadsUp/HEAD/library/src/main/res/drawable-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/library/src/main/res/drawable-hdpi/notification_bg2.9.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zzz40500/HeadsUp/HEAD/library/src/main/res/drawable-hdpi/notification_bg2.9.png
--------------------------------------------------------------------------------
/library/src/main/res/drawable-hdpi/notification_bg3.9.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zzz40500/HeadsUp/HEAD/library/src/main/res/drawable-hdpi/notification_bg3.9.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-hdpi/ic_cloud_queue_black_24dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zzz40500/HeadsUp/HEAD/app/src/main/res/drawable-hdpi/ic_cloud_queue_black_24dp.png
--------------------------------------------------------------------------------
/.idea/scopes/scope_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/.idea/encodings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 |
6 |
--------------------------------------------------------------------------------
/library/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | HeadsUpDemo
5 | Hello world!
6 | Settings
7 |
8 |
9 |
--------------------------------------------------------------------------------
/library/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Ll
5 | Hello world!
6 | Settings
7 |
8 |
9 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Wed Apr 10 15:27:10 PDT 2013
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.2.1-all.zip
7 |
--------------------------------------------------------------------------------
/library/src/main/res/values/defualt.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #808080
4 | #e0e0e0
5 | #00000000
6 | #ffffff
7 |
--------------------------------------------------------------------------------
/library/src/main/res/values/circle_imageview_attrs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable-hdpi/butto.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/library/src/main/res/drawable-hdpi/bg_transparency_to_grey.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/menu/menu_main.xml:
--------------------------------------------------------------------------------
1 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/library/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/library/src/main/res/menu/my.xml:
--------------------------------------------------------------------------------
1 |
10 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/mingle/headsupdemo/ApplicationTest.java:
--------------------------------------------------------------------------------
1 | package com.mingle.headsupdemo;
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 | }
--------------------------------------------------------------------------------
/library/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/library/src/main/res/layout/notification_bg.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
11 |
12 |
--------------------------------------------------------------------------------
/library/src/androidTest/java/com/example/administrator/ll/ApplicationTest.java:
--------------------------------------------------------------------------------
1 | package com.example.administrator.ll;
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 | }
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/library/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 |
3 | android {
4 | compileSdkVersion 21
5 | buildToolsVersion "21.1.2"
6 | defaultConfig {
7 | minSdkVersion 9
8 | targetSdkVersion 21
9 | versionCode 1
10 | versionName "1.1.0"
11 | }
12 | buildTypes {
13 | release {
14 |
15 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
16 | }
17 | }
18 | }
19 |
20 | dependencies {
21 |
22 | compile 'com.nineoldandroids:library:2.4.0'
23 | compile 'com.android.support:support-v4:21.0.3'
24 | }
25 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 21
5 | buildToolsVersion "21.1.2"
6 |
7 | defaultConfig {
8 | applicationId "com.mingle.headupdemo"
9 | minSdkVersion 9
10 | targetSdkVersion 21
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 'com.android.support:appcompat-v7:21.0.3'
24 | compile project(':library')
25 | }
26 |
--------------------------------------------------------------------------------
/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/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/zzz40500/Documents/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 |
--------------------------------------------------------------------------------
/library/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 D:/Program Files (x86)/Android/android-studio/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 |
--------------------------------------------------------------------------------
/.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 |
23 |
24 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
10 |
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 | # 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
--------------------------------------------------------------------------------
/library/src/main/res/drawable-hdpi/notification_bg.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | -
5 |
7 |
8 |
13 |
14 |
18 |
19 |
20 |
21 |
22 | -
23 |
24 |
25 |
26 |
27 |
28 |
29 |
32 |
33 |
34 |
35 |
--------------------------------------------------------------------------------
/HeadsUp.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/HeadsUpDemo.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
8 |
9 |
14 |
19 |
20 |
25 |
30 |
31 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/custom_notification.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
11 |
12 |
19 |
20 |
26 |
27 |
33 |
39 |
40 |
41 |
42 |
43 |
--------------------------------------------------------------------------------
/library/src/main/java/com/mingle/headsUp/Distance.java:
--------------------------------------------------------------------------------
1 | package com.mingle.headsUp;
2 |
3 | import android.content.Context;
4 | import android.hardware.SensorManager;
5 | import android.view.ViewConfiguration;
6 |
7 | /**
8 | * Created by zzz40500 on 15/1/29.
9 | */
10 | public class Distance {
11 | private float mFlingFriction = ViewConfiguration.getScrollFriction();
12 |
13 | private static float DECELERATION_RATE = (float) (Math.log(0.78) / Math.log(0.9));
14 | private static final float INFLEXION = 0.35f;
15 | private float mPhysicalCoeff;
16 |
17 |
18 | public Distance(Context context){
19 |
20 | final float ppi = context.getResources().getDisplayMetrics().density * 160.0f;
21 | mPhysicalCoeff = SensorManager.GRAVITY_EARTH // g (m/s^2)
22 | * 39.37f // inch/meter
23 | * ppi
24 | * 0.84f; // look and feel tuning
25 | }
26 | public double getSplineFlingDistance(int velocity) {
27 | final double l = getSplineDeceleration(velocity);
28 | final double decelMinusOne = DECELERATION_RATE - 1.0;
29 | return mFlingFriction * mPhysicalCoeff * Math.exp(DECELERATION_RATE / decelMinusOne * l);
30 | }
31 |
32 | private double getSplineDeceleration(int velocity) {
33 | return Math.log(INFLEXION * Math.abs(velocity) / (mFlingFriction * mPhysicalCoeff));
34 | }
35 |
36 | /* Returns the duration, expressed in milliseconds */
37 | public int getSplineFlingDuration(int velocity) {
38 | final double l = getSplineDeceleration(velocity);
39 | final double decelMinusOne = DECELERATION_RATE - 1.0;
40 | return (int) (1000.0 * Math.exp(l / decelMinusOne));
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/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.markdown:
--------------------------------------------------------------------------------
1 | #2.0 使用库实现类似的方法(向下兼容2.3)#
2 | 下面介绍一个自己写的,类似 Heads-up 组件的库.
3 | [github 源码地址](https://github.com/zzz40500/HeadsUp)
4 | simple heads-up (no expand)
5 | 使用方法:
6 | ~~~
7 | HeadsUpManager manage = HeadsUpManager.getInstant(getApplication());
8 | HeadsUp.Builder builder = new HeadsUp.Builder(MainActivity.this);
9 | builder.setContentTitle("提醒").setDefaults(Notification.DEFAULT_SOUND | Notification.DEFAULT_LIGHTS)
10 | //要显示通知栏通知,这个一定要设置
11 | .setSmallIcon(R.drawable.icon)
12 | //2.3 一定要设置这个参数,否则会报错
13 | .setContentIntent(pendingIntent)
14 | .setContentText("你有新的消息");
15 |
16 | HeadsUp headsUp = builder.buildHeadUp();
17 | manage.notify(code++, headsUp);
18 | ~~~
19 | simple heads-up
20 | 使用方法:
21 | ~~~
22 | HeadsUpManager manage = HeadsUpManager.getInstant(getApplication());
23 | HeadsUp.Builder builder = new HeadsUp.Builder(MainActivity.this);
24 | builder.setContentTitle("提醒").setDefaults(Notification.DEFAULT_SOUND | Notification.DEFAULT_LIGHTS)
25 | //要显示通知栏通知,这个一定要设置
26 | .setSmallIcon(R.drawable.icon)
27 | .setContentText("你有新的消息")
28 | //2.3 一定要设置这个参数,否则会报错
29 | .setContentIntent(pendingIntent)
30 | //设置是否显示 action 按键
31 | .setUsesChronometer(true)
32 | .addAction(R.drawable.ic_cloud_queue_black_24dp, "查看", pendingIntent);
33 |
34 | HeadsUp headsUp = builder.buildHeadUp();
35 | manage.notify(code++, headsUp);
36 | ~~~
37 |
38 | 使用自定义布局,支持 button 的点击事件.
39 | 使用方法:
40 | ~~~
41 | final HeadsUpManager manage1 = HeadsUpManager.getInstant(getApplication());
42 |
43 | View view=getLayoutInflater().inflate(R.layout.custom_notification, null);
44 |
45 | view.findViewById(R.id.openSource).setOnClickListener(new View.OnClickListener() {
46 | @Override
47 | public void onClick(View v) {
48 | Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://github.com/zzz40500/HeadsUp"));
49 | intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
50 | MainActivity.this.startActivity(intent);
51 | manage1.cancel();
52 | }
53 | });
54 |
55 | HeadsUp headsUp1 = new HeadsUp.Builder(MainActivity.this)
56 | .setContentTitle("标题")
57 | //要显示通知栏通知,这个一定要设置
58 | .setSmallIcon(R.drawable.icon)
59 | //2.3 一定要设置这个参数,否则会报错
60 | .setContentIntent(pendingIntent)
61 | .setContentText("这个是自定义通知")
62 | .buildHeadUp();
63 | headsUp1.setCustomView(view);
64 | manage1.notify(code++, headsUp1);
65 | ~~~
66 |
67 | 
68 |
69 | 局限性:
70 | >1. ~~heads-up 没有加入阴影效果:~~
71 | * 没有对消息进行优先级排序,现在的排序算法是先进先出.
72 | * miui 系统开启悬浮窗才可以正常使用. (**miui 真讨厌!!!!**)
73 |
74 | 1.0.1更新内容;
75 | >增加了背景阴影部分.
76 | 1. 增加了消息横向滑动时候的 alpha 值的改变
77 | * 增加了常驻消息:调用 HeadsUp.setSticky(true),用 HeadsUpManager.cancel(code)取消.
78 | * 修改了滑动动画.
79 | * 向下兼容2.3
80 |
81 | 1.1.0更新内容;
82 | >* 增加了圆形头像,基于[CircleImageView](https://github.com/hdodenhof/CircleImageView)上做的修改
83 | * 增加在 android 5.0 上使用原生的 headsUp.
84 | 增加了方法 `setActivateStatusBar(boolean )` 默认 true ,设置 false 表示只显示 heads-up ,而不会发送到通知栏上.
85 |
86 | #####1.1.0注意:#####
87 | >*使用原生的 headsUp 逻辑是:
88 | 系统是大于21,且headsUp 没有使用`setCustomView(View )`也没有设置`setIsActivateStatusBar(true)`则使用原生的 heads-up
89 | 如果要调用了原生的 heads-up,所以你得设置`setFullScreenIntent(pendding,false)`pendding不能为空,否则没有效果
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
--------------------------------------------------------------------------------
/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 | # For Cygwin, ensure paths are in UNIX format before anything is touched.
46 | if $cygwin ; then
47 | [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
48 | fi
49 |
50 | # Attempt to set APP_HOME
51 | # Resolve links: $0 may be a link
52 | PRG="$0"
53 | # Need this for relative symlinks.
54 | while [ -h "$PRG" ] ; do
55 | ls=`ls -ld "$PRG"`
56 | link=`expr "$ls" : '.*-> \(.*\)$'`
57 | if expr "$link" : '/.*' > /dev/null; then
58 | PRG="$link"
59 | else
60 | PRG=`dirname "$PRG"`"/$link"
61 | fi
62 | done
63 | SAVED="`pwd`"
64 | cd "`dirname \"$PRG\"`/" >&-
65 | APP_HOME="`pwd -P`"
66 | cd "$SAVED" >&-
67 |
68 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
69 |
70 | # Determine the Java command to use to start the JVM.
71 | if [ -n "$JAVA_HOME" ] ; then
72 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
73 | # IBM's JDK on AIX uses strange locations for the executables
74 | JAVACMD="$JAVA_HOME/jre/sh/java"
75 | else
76 | JAVACMD="$JAVA_HOME/bin/java"
77 | fi
78 | if [ ! -x "$JAVACMD" ] ; then
79 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
80 |
81 | Please set the JAVA_HOME variable in your environment to match the
82 | location of your Java installation."
83 | fi
84 | else
85 | JAVACMD="java"
86 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
87 |
88 | Please set the JAVA_HOME variable in your environment to match the
89 | location of your Java installation."
90 | fi
91 |
92 | # Increase the maximum file descriptors if we can.
93 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
94 | MAX_FD_LIMIT=`ulimit -H -n`
95 | if [ $? -eq 0 ] ; then
96 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
97 | MAX_FD="$MAX_FD_LIMIT"
98 | fi
99 | ulimit -n $MAX_FD
100 | if [ $? -ne 0 ] ; then
101 | warn "Could not set maximum file descriptor limit: $MAX_FD"
102 | fi
103 | else
104 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
105 | fi
106 | fi
107 |
108 | # For Darwin, add options to specify how the application appears in the dock
109 | if $darwin; then
110 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
111 | fi
112 |
113 | # For Cygwin, switch paths to Windows format before running java
114 | if $cygwin ; then
115 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
116 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
158 | function splitJvmOpts() {
159 | JVM_OPTS=("$@")
160 | }
161 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
162 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
163 |
164 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
165 |
--------------------------------------------------------------------------------
/app/src/main/java/com/mingle/headsupdemo/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.mingle.headsupdemo;
2 |
3 | import android.app.Notification;
4 | import android.app.NotificationManager;
5 | import android.app.PendingIntent;
6 | import android.content.Context;
7 | import android.content.Intent;
8 | import android.net.Uri;
9 | import android.os.Bundle;
10 | import android.support.v4.app.NotificationCompat;
11 | import android.support.v7.app.ActionBarActivity;
12 | import android.view.Menu;
13 | import android.view.MenuItem;
14 | import android.view.View;
15 | import android.view.Window;
16 | import android.view.WindowManager;
17 | import android.widget.RemoteViews;
18 | import android.widget.ScrollView;
19 |
20 | import com.mingle.headsUp.HeadsUp;
21 | import com.mingle.headsUp.HeadsUpManager;
22 |
23 |
24 | public class MainActivity extends ActionBarActivity {
25 |
26 |
27 | private int code=1;
28 |
29 |
30 | private Context context;
31 |
32 |
33 |
34 | @Override
35 | protected void onCreate(Bundle savedInstanceState) {
36 | super.onCreate(savedInstanceState);
37 | setContentView(R.layout.activity_main);
38 | context=this;
39 |
40 | findViewById(R.id.l0).setOnClickListener(new View.OnClickListener() {
41 | @Override
42 | public void onClick(View v) {
43 |
44 |
45 |
46 | PendingIntent pendingIntent=PendingIntent.getActivity(MainActivity.this,11,new Intent(MainActivity.this,MainActivity.class),PendingIntent.FLAG_UPDATE_CURRENT);
47 | HeadsUpManager manage = HeadsUpManager.getInstant(getApplication());
48 | HeadsUp.Builder builder = new HeadsUp.Builder(MainActivity.this);
49 | builder.setContentTitle("提醒").setDefaults(Notification.DEFAULT_SOUND | Notification.DEFAULT_LIGHTS)
50 | //要显示通知栏通知,这个一定要设置
51 | .setSmallIcon(R.drawable.icon)
52 | //2.3 一定要设置这个参数,负责会报错
53 | .setContentIntent(pendingIntent)
54 | .setFullScreenIntent(pendingIntent,false)
55 | .setContentText("你有新的消息");
56 |
57 | HeadsUp headsUp = builder.buildHeadUp();
58 | headsUp.setSticky(true);
59 | manage.notify(code++, headsUp);
60 |
61 |
62 | }
63 | });
64 |
65 | findViewById(R.id.l1).setOnClickListener(new View.OnClickListener() {
66 | @Override
67 | public void onClick(View v) {
68 |
69 | PendingIntent pendingIntent=PendingIntent.getActivity(MainActivity.this,11,new Intent(MainActivity.this,MainActivity.class),PendingIntent.FLAG_UPDATE_CURRENT);
70 | HeadsUpManager manage = HeadsUpManager.getInstant(getApplication());
71 | HeadsUp.Builder builder = new HeadsUp.Builder(MainActivity.this);
72 | builder.setContentTitle("提醒").setDefaults(Notification.DEFAULT_SOUND | Notification.DEFAULT_LIGHTS)
73 | //要显示通知栏通知,这个一定要设置
74 | .setSmallIcon(R.drawable.icon)
75 | .setContentText("你有新的消息")
76 | //2.3 一定要设置这个参数,负责会报错
77 | .setContentIntent(pendingIntent)
78 | .setFullScreenIntent(pendingIntent, false)
79 | //设置是否显示 action 按键
80 | .setUsesChronometer(true)
81 | .addAction(R.drawable.ic_cloud_queue_black_24dp, "查看", pendingIntent);
82 |
83 | HeadsUp headsUp = builder.buildHeadUp();
84 | manage.notify(1, headsUp);
85 |
86 |
87 | }
88 | });
89 |
90 | findViewById(R.id.l2).setOnClickListener(new View.OnClickListener() {
91 | @Override
92 | public void onClick(View v) {
93 |
94 | PendingIntent pendingIntent=PendingIntent.getActivity(MainActivity.this,11,new Intent(MainActivity.this,MainActivity.class),PendingIntent.FLAG_UPDATE_CURRENT);
95 |
96 | final HeadsUpManager manage1 = HeadsUpManager.getInstant(getApplication());
97 |
98 | View view=getLayoutInflater().inflate(R.layout.custom_notification, null);
99 |
100 | view.findViewById(R.id.openSource).setOnClickListener(new View.OnClickListener() {
101 | @Override
102 | public void onClick(View v) {
103 | Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://github.com/zzz40500/HeadsUp"));
104 | intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
105 | MainActivity.this.startActivity(intent);
106 | manage1.cancel();
107 | }
108 | });
109 |
110 | HeadsUp headsUp1 = new HeadsUp.Builder(MainActivity.this)
111 | .setContentTitle("标题")
112 | //要显示通知栏通知,这个一定要设置
113 | .setSmallIcon(R.drawable.icon)
114 | //2.3 一定要设置这个参数,负责会报错
115 | .setContentIntent(pendingIntent)
116 | .setContentText("这个是自定义通知")
117 | .buildHeadUp();
118 | headsUp1.setCustomView(view);
119 | manage1.notify(code++, headsUp1);
120 |
121 | }
122 | });
123 |
124 | findViewById(R.id.l3).setOnClickListener(new View.OnClickListener() {
125 | @Override
126 | public void onClick(View v) {
127 |
128 | HeadsUpManager.getInstant(MainActivity.this).cancelAll();
129 |
130 |
131 |
132 |
133 |
134 | }
135 | });
136 |
137 | }
138 |
139 |
140 | @Override
141 | public boolean onCreateOptionsMenu(Menu menu) {
142 | // Inflate the menu; this adds items to the action bar if it is present.
143 | getMenuInflater().inflate(R.menu.menu_main, menu);
144 | return true;
145 | }
146 |
147 | @Override
148 | public boolean onOptionsItemSelected(MenuItem item) {
149 | // Handle action bar item clicks here. The action bar will
150 | // automatically handle clicks on the Home/Up button, so long
151 | // as you specify a parent activity in AndroidManifest.xml.
152 | int id = item.getItemId();
153 |
154 | //noinspection SimplifiableIfStatement
155 | if (id == R.id.action_settings) {
156 | return true;
157 | }
158 |
159 | return super.onOptionsItemSelected(item);
160 | }
161 | }
162 |
--------------------------------------------------------------------------------
/library/library.iml:
--------------------------------------------------------------------------------
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 |
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 |
--------------------------------------------------------------------------------
/app/app.iml:
--------------------------------------------------------------------------------
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 |
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 |
--------------------------------------------------------------------------------
/library/src/main/java/com/mingle/headsUp/HeadsUpManager.java:
--------------------------------------------------------------------------------
1 | package com.mingle.headsUp;
2 |
3 | import android.app.NotificationManager;
4 | import android.content.Context;
5 | import android.os.Build;
6 | import android.view.Gravity;
7 | import android.view.WindowManager;
8 |
9 |
10 | import com.nineoldandroids.animation.Animator;
11 | import com.nineoldandroids.animation.ObjectAnimator;
12 |
13 | import java.util.HashMap;
14 | import java.util.LinkedList;
15 | import java.util.Map;
16 | import java.util.Queue;
17 |
18 | /**
19 | * Created by zzz40500 on 2014/10/9.
20 | */
21 | public class HeadsUpManager {
22 |
23 | private WindowManager wmOne;
24 | private FloatView floatView;
25 | private Queue msgQueue;
26 | private static HeadsUpManager manager;
27 | private Context context;
28 |
29 | /**
30 | *
31 | */
32 | private boolean isPolling = false;
33 |
34 | private Map map;
35 | private NotificationManager notificationManager=null;
36 |
37 | public static HeadsUpManager getInstant(Context c) {
38 |
39 | if (manager == null) {
40 | manager = new HeadsUpManager(c);
41 |
42 | }
43 | return manager;
44 |
45 | }
46 |
47 | private HeadsUpManager(Context context) {
48 | this.context = context;
49 | map = new HashMap();
50 | msgQueue = new LinkedList();
51 | wmOne = (WindowManager) context
52 | .getSystemService(Context.WINDOW_SERVICE);
53 |
54 | notificationManager= (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
55 | }
56 |
57 | public synchronized void notify(HeadsUp headsUp) {
58 |
59 |
60 | if (map.containsKey(headsUp.getCode())) {
61 | msgQueue.remove(map.get(headsUp.getCode()));
62 | }
63 | map.put(headsUp.getCode(), headsUp);
64 | msgQueue.add(headsUp);
65 |
66 | if (!isPolling) {
67 | poll();
68 | }
69 | }
70 | public synchronized void notify(int code,HeadsUp headsUp) {
71 | headsUp.setCode(code);
72 | notify(headsUp);
73 |
74 | }
75 |
76 |
77 | public synchronized void cancel(HeadsUp headsUp) {
78 |
79 | cancel(headsUp.getCode());
80 | }
81 |
82 |
83 | private synchronized void poll() {
84 | if (!msgQueue.isEmpty()) {
85 | HeadsUp headsUp = msgQueue.poll();
86 | map.remove(headsUp.getCode());
87 |
88 |
89 | if ( Build.VERSION.SDK_INT < 21 || headsUp.getCustomView() != null || !headsUp.isActivateStatusBar()){
90 | isPolling = true;
91 | show(headsUp);
92 | }else {
93 | //当 系统是 lollipop 以上,并且没有自定义布局以后,调用系统自己的 notification
94 | isPolling = false;
95 | notificationManager.notify(headsUp.getCode(),headsUp.getBuilder().setIcon(headsUp.getIcon()).build());
96 |
97 | }
98 | } else {
99 | isPolling = false;
100 | }
101 | }
102 |
103 |
104 | private void show(HeadsUp headsUp) {
105 |
106 | floatView = new FloatView(context, 20);
107 | WindowManager.LayoutParams params = FloatView.winParams;
108 | params.flags = WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL
109 | | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|WindowManager.LayoutParams.FLAG_FULLSCREEN
110 | | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN;
111 | params.type = WindowManager.LayoutParams.TYPE_SYSTEM_ERROR;
112 | params.width = WindowManager.LayoutParams.MATCH_PARENT;
113 | params.height = WindowManager.LayoutParams.WRAP_CONTENT;
114 | params.format = -3;
115 | params.gravity = Gravity.CENTER | Gravity.TOP;
116 | params.x = floatView.originalLeft;
117 | params.y = 0;
118 | params.alpha = 1f;
119 | wmOne.addView(floatView, params);
120 | ObjectAnimator a = ObjectAnimator.ofFloat(floatView.rootView, "translationY", -700, 0);
121 | a.setDuration(600);
122 | a.start();
123 | floatView.setNotification(headsUp);
124 | if(headsUp.getNotification()!=null ){
125 | notificationManager.notify(headsUp.getCode(), headsUp.getNotification());
126 | }
127 |
128 |
129 | }
130 |
131 |
132 |
133 | public void cancel(){
134 |
135 | if(floatView !=null && floatView.getParent()!=null) {
136 |
137 | floatView.cancel();
138 | }
139 |
140 |
141 | }
142 |
143 | protected void dismiss() {
144 |
145 | if (floatView.getParent()!=null) {
146 | wmOne.removeView(floatView);
147 | floatView.postDelayed(new Runnable() {
148 | @Override
149 | public void run() {
150 | poll();
151 | }
152 | }, 1000);
153 | }
154 |
155 | }
156 |
157 | protected void animDismiss(){
158 |
159 | if(floatView !=null && floatView.getParent()!=null){
160 |
161 | ObjectAnimator a = ObjectAnimator.ofFloat(floatView.rootView, "translationY", 0, -700);
162 | a.setDuration(700);
163 | a.start();
164 |
165 |
166 | a.addListener(new Animator.AnimatorListener() {
167 | @Override
168 | public void onAnimationStart(Animator animator) {
169 |
170 | }
171 |
172 | @Override
173 | public void onAnimationEnd(Animator animator) {
174 |
175 |
176 | dismiss();
177 | }
178 |
179 | @Override
180 | public void onAnimationCancel(Animator animator) {
181 | }
182 |
183 | @Override
184 | public void onAnimationRepeat(Animator animator) {
185 |
186 |
187 | }
188 | });
189 | }
190 |
191 |
192 |
193 | }
194 |
195 | protected void animDismiss(HeadsUp headsUp){
196 |
197 |
198 | if(floatView.getHeadsUp().getCode()==headsUp.getCode()){
199 | animDismiss();
200 | }
201 |
202 | }
203 |
204 |
205 | protected void silencerNotify(HeadsUp headsUp){
206 | if(headsUp.getSilencerNotification()!=null){
207 | notificationManager.notify(headsUp.getCode(), headsUp.getSilencerNotification());
208 | }
209 | }
210 |
211 | public void cancel(int code) {
212 | if (map.containsKey(code)) {
213 | msgQueue.remove(map.get(code));
214 | }
215 | if(floatView!=null && floatView.getHeadsUp().getCode()==code){
216 | animDismiss();
217 | }
218 |
219 | }
220 |
221 |
222 |
223 | public void close() {
224 | cancelAll();
225 | manager = null;
226 | }
227 |
228 |
229 | public void cancelAll() {
230 | msgQueue.clear();
231 | if (floatView!=null && floatView.getParent()!=null) {
232 | animDismiss();
233 | }
234 | }
235 | }
236 |
--------------------------------------------------------------------------------
/library/src/main/res/layout/notification.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
7 |
16 |
27 |
28 |
37 |
38 |
39 |
50 |
51 |
60 |
61 |
69 |
70 |
77 |
78 |
86 |
87 |
95 |
96 |
97 |
104 |
105 |
113 |
114 |
123 |
124 |
125 |
132 |
133 |
141 |
142 |
150 |
151 |
152 |
153 |
154 |
155 |
--------------------------------------------------------------------------------
/library/src/main/java/com/mingle/headsUp/widget/CircleImageView.java:
--------------------------------------------------------------------------------
1 | package com.mingle.headsUp.widget;
2 |
3 | import android.content.Context;
4 | import android.content.res.ColorStateList;
5 | import android.content.res.TypedArray;
6 | import android.graphics.Bitmap;
7 | import android.graphics.BitmapShader;
8 | import android.graphics.Canvas;
9 | import android.graphics.Color;
10 | import android.graphics.ColorFilter;
11 | import android.graphics.Matrix;
12 | import android.graphics.Paint;
13 | import android.graphics.RectF;
14 | import android.graphics.Shader;
15 | import android.graphics.drawable.BitmapDrawable;
16 | import android.graphics.drawable.ColorDrawable;
17 | import android.graphics.drawable.Drawable;
18 | import android.net.Uri;
19 | import android.util.AttributeSet;
20 | import android.util.Log;
21 | import android.view.MotionEvent;
22 | import android.widget.ImageView;
23 |
24 | import com.mingle.headsUp.R;
25 |
26 |
27 | public class CircleImageView extends ImageView {
28 |
29 | private static final ScaleType SCALE_TYPE = ScaleType.CENTER_CROP;
30 |
31 | private static final Bitmap.Config BITMAP_CONFIG = Bitmap.Config.ARGB_8888;
32 | private static final int COLORDRAWABLE_DIMENSION = 2;
33 |
34 | private static final int DEFAULT_BORDER_WIDTH = 2;
35 | private static final int DEFAULT_BORDER_COLOR = Color.BLACK;
36 |
37 | private final RectF mDrawableRect = new RectF();
38 | private final RectF mBorderRect = new RectF();
39 |
40 | private final Matrix mShaderMatrix = new Matrix();
41 | private final Paint mBitmapPaint = new Paint();
42 | private final Paint mBorderPaint = new Paint();
43 |
44 | private ColorStateList mBorderColorStateList;
45 | private int mBorderColor;
46 | private int mBorderWidth = DEFAULT_BORDER_WIDTH;
47 |
48 | private Bitmap mBitmap;
49 | private BitmapShader mBitmapShader;
50 | private int mBitmapWidth;
51 | private int mBitmapHeight;
52 |
53 | private float mDrawableRadius;
54 | private float mBorderRadius;
55 |
56 | private ColorFilter mColorFilter;
57 |
58 | private boolean mReady;
59 | private boolean mSetupPending;
60 |
61 | public CircleImageView(Context context) {
62 | super(context);
63 |
64 | init();
65 | }
66 |
67 | public CircleImageView(Context context, AttributeSet attrs) {
68 | this(context, attrs, 0);
69 | }
70 |
71 | private int paddingTop,paddingLeft,paddingRight,paddingBottom;
72 |
73 | public CircleImageView(Context context, AttributeSet attrs, int defStyle) {
74 | super(context, attrs, defStyle);
75 |
76 | TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.CircleImageView, defStyle, 0);
77 |
78 | mBorderWidth = a.getDimensionPixelSize(R.styleable.CircleImageView_border_width, DEFAULT_BORDER_WIDTH);
79 | mBorderColorStateList = a.getColorStateList(R.styleable.CircleImageView_border_color);
80 | if(mBorderColorStateList!=null) {
81 | mBorderColor = mBorderColorStateList.getColorForState(getDrawableState(), Color.WHITE);
82 | }else{
83 | mBorderColor=Color.WHITE;
84 | }
85 | a.recycle();
86 |
87 | paddingTop=getPaddingTop();
88 | paddingLeft=getPaddingLeft();
89 | paddingRight=getPaddingRight();
90 | paddingBottom=getPaddingBottom();
91 |
92 |
93 | init();
94 | }
95 |
96 | private void init() {
97 | super.setScaleType(SCALE_TYPE);
98 | mReady = true;
99 |
100 | if (mSetupPending) {
101 | setup();
102 | mSetupPending = false;
103 | }
104 | }
105 |
106 | @Override
107 | public ScaleType getScaleType() {
108 | return SCALE_TYPE;
109 | }
110 |
111 | @Override
112 | public void setScaleType(ScaleType scaleType) {
113 | if (scaleType != SCALE_TYPE) {
114 | throw new IllegalArgumentException(String.format("ScaleType %s not supported.", scaleType));
115 | }
116 | }
117 |
118 | @Override
119 | public void setAdjustViewBounds(boolean adjustViewBounds) {
120 | if (adjustViewBounds) {
121 | throw new IllegalArgumentException("adjustViewBounds not supported.");
122 | }
123 | }
124 |
125 | @Override
126 | protected void onDraw(Canvas canvas) {
127 | if (getDrawable() == null) {
128 | return;
129 | }
130 | canvas.drawCircle(paddingLeft+(getWidth()-paddingRight-paddingLeft) / 2, paddingTop+(getHeight()-paddingTop-paddingBottom )/ 2, mDrawableRadius, mBitmapPaint);
131 | if (mBorderWidth != 0) {
132 |
133 | mBorderPaint.setColor(mBorderColor);
134 | canvas.drawCircle(
135 | paddingLeft+(getWidth()-paddingRight-paddingLeft) / 2, paddingTop+(getHeight()-paddingTop-paddingBottom )/ 2
136 | , mBorderRadius, mBorderPaint);
137 | }
138 | }
139 |
140 | @Override
141 | public boolean onTouchEvent(MotionEvent event) {
142 |
143 |
144 | if(mBorderColorStateList ==null || !isClickable()){
145 | return super.onTouchEvent(event);
146 | }
147 |
148 | switch (event.getAction()){
149 | case MotionEvent.ACTION_UP:
150 | case MotionEvent.ACTION_CANCEL:
151 | mBorderColor=mBorderColorStateList.getDefaultColor();
152 | break;
153 |
154 | default:
155 | mBorderColor = mBorderColorStateList.getColorForState(getDrawableState(), Color.WHITE);
156 |
157 | break;
158 | }
159 | invalidate();
160 | return super.onTouchEvent(event);
161 | }
162 |
163 | @Override
164 | protected void onSizeChanged(int w, int h, int oldw, int oldh) {
165 | super.onSizeChanged(w, h, oldw, oldh);
166 | setup();
167 | }
168 |
169 | public int getBorderColor() {
170 | return mBorderColor;
171 | }
172 |
173 | public void setBorderColor(int borderColor) {
174 | if (borderColor == mBorderColor) {
175 | return;
176 | }
177 |
178 | mBorderColor = borderColor;
179 | mBorderPaint.setColor(mBorderColor);
180 | invalidate();
181 | }
182 |
183 | public int getBorderWidth() {
184 | return mBorderWidth;
185 | }
186 |
187 | public void setBorderWidth(int borderWidth) {
188 | if (borderWidth == mBorderWidth) {
189 | return;
190 | }
191 |
192 | mBorderWidth = borderWidth;
193 | setup();
194 | }
195 |
196 | @Override
197 | public void setImageBitmap(Bitmap bm) {
198 | super.setImageBitmap(bm);
199 | mBitmap = bm;
200 | setup();
201 | }
202 |
203 | @Override
204 | public void setImageDrawable(Drawable drawable) {
205 | super.setImageDrawable(drawable);
206 | mBitmap = getBitmapFromDrawable(drawable);
207 | setup();
208 | }
209 |
210 | @Override
211 | public void setImageResource(int resId) {
212 | super.setImageResource(resId);
213 | mBitmap = getBitmapFromDrawable(getDrawable());
214 | setup();
215 | }
216 |
217 | @Override
218 | public void setImageURI(Uri uri) {
219 | super.setImageURI(uri);
220 | mBitmap = getBitmapFromDrawable(getDrawable());
221 | setup();
222 | }
223 |
224 | @Override
225 | public void setColorFilter(ColorFilter cf) {
226 | if (cf == mColorFilter) {
227 | return;
228 | }
229 |
230 | mColorFilter = cf;
231 | mBitmapPaint.setColorFilter(mColorFilter);
232 | invalidate();
233 | }
234 |
235 | private Bitmap getBitmapFromDrawable(Drawable drawable) {
236 | if (drawable == null) {
237 | return null;
238 | }
239 |
240 | if (drawable instanceof BitmapDrawable) {
241 | return ((BitmapDrawable) drawable).getBitmap();
242 | }
243 |
244 | try {
245 | Bitmap bitmap;
246 |
247 | if (drawable instanceof ColorDrawable) {
248 | bitmap = Bitmap.createBitmap(COLORDRAWABLE_DIMENSION, COLORDRAWABLE_DIMENSION, BITMAP_CONFIG);
249 | } else {
250 | bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), BITMAP_CONFIG);
251 | }
252 |
253 | Canvas canvas = new Canvas(bitmap);
254 | drawable.setBounds(paddingLeft, paddingTop, canvas.getWidth()-paddingRight, canvas.getHeight()-paddingBottom);
255 | drawable.draw(canvas);
256 | return bitmap;
257 | } catch (OutOfMemoryError e) {
258 | return null;
259 | }
260 | }
261 |
262 | private void setup() {
263 | if (!mReady) {
264 | mSetupPending = true;
265 | return;
266 | }
267 |
268 | if (mBitmap == null) {
269 | return;
270 | }
271 |
272 | mBitmapShader = new BitmapShader(mBitmap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);
273 |
274 | mBitmapPaint.setAntiAlias(true);
275 | mBitmapPaint.setShader(mBitmapShader);
276 |
277 | mBorderPaint.setStyle(Paint.Style.STROKE);
278 | mBorderPaint.setAntiAlias(true);
279 |
280 | mBorderPaint.setStrokeWidth(mBorderWidth);
281 |
282 | mBitmapHeight = mBitmap.getHeight();
283 | mBitmapWidth = mBitmap.getWidth();
284 |
285 | mBorderRect.set(paddingLeft, paddingTop, getWidth()-paddingRight, getHeight()-paddingBottom);
286 | mBorderRadius = Math.min((mBorderRect.height()-mBorderWidth) / 2,( mBorderRect.width()-mBorderWidth) / 2);
287 |
288 |
289 | mDrawableRect.set(mBorderWidth+paddingLeft, mBorderWidth+paddingTop, getWidth()-paddingRight - mBorderWidth, getHeight()-paddingBottom - mBorderWidth);
290 | mDrawableRadius = Math.min(mDrawableRect.height() / 2, mDrawableRect.width() / 2);
291 |
292 | Log.e("mDrawableRadius", mDrawableRadius + "");
293 | updateShaderMatrix();
294 | invalidate();
295 | }
296 |
297 | private void updateShaderMatrix() {
298 | float scale;
299 | float dx = 0;
300 | float dy = 0;
301 |
302 | mShaderMatrix.set(null);
303 |
304 | if (mBitmapWidth * mDrawableRect.height() > mDrawableRect.width() * mBitmapHeight) {
305 | scale = mDrawableRect.height() / (float) mBitmapHeight;
306 | dx = (mDrawableRect.width() - mBitmapWidth * scale) * 0.5f;
307 | } else {
308 | scale = mDrawableRect.width() / (float) mBitmapWidth;
309 | dy = (mDrawableRect.height() - mBitmapHeight * scale) * 0.5f;
310 | }
311 |
312 | mShaderMatrix.setScale(scale, scale);
313 | mShaderMatrix.postTranslate((int) (dx + 0.5f) +paddingLeft+ mBorderWidth, (int) (dy + 0.5f) + paddingTop+mBorderWidth);
314 |
315 | mBitmapShader.setLocalMatrix(mShaderMatrix);
316 | }
317 |
318 | }
--------------------------------------------------------------------------------
/library/src/main/java/com/mingle/headsUp/HeadsUp.java:
--------------------------------------------------------------------------------
1 | package com.mingle.headsUp;
2 |
3 | import android.app.Notification;
4 | import android.app.PendingIntent;
5 | import android.content.Context;
6 | import android.graphics.Bitmap;
7 | import android.net.Uri;
8 | import android.os.Bundle;
9 | import android.support.v4.app.NotificationCompat;
10 | import android.view.View;
11 | import android.widget.RemoteViews;
12 | import java.util.ArrayList;
13 | import java.util.List;
14 |
15 |
16 | /**
17 | * Created by zzz40500 on 2014/10/9.
18 | */
19 | public class HeadsUp {
20 |
21 | private Context context;
22 | /**
23 | * 出现时间 单位是 second
24 | */
25 | private long duration= 9;
26 | /**
27 | *
28 | */
29 | private Notification notification;
30 |
31 | private Builder builder;
32 |
33 | private boolean isSticky=false;
34 |
35 |
36 | private boolean activateStatusBar=true;
37 |
38 |
39 | /**
40 | *
41 | */
42 |
43 | private Notification silencerNotification;
44 | /**
45 | * 间隔时间
46 | */
47 | private long interval=600 ;
48 | private int code;
49 | private List actions;
50 | private CharSequence titleStr;
51 | private CharSequence msgStr;
52 | private int icon;
53 | private View customView;
54 | private boolean isExpand;
55 | private HeadsUp(Context context) {
56 | this.context=context;
57 | }
58 |
59 |
60 |
61 |
62 |
63 | public static class Builder extends NotificationCompat.Builder {
64 |
65 | private List actions=new ArrayList();
66 | private HeadsUp headsUp;
67 |
68 | public Builder(Context context) {
69 | super(context);
70 | headsUp=new HeadsUp(context);
71 | }
72 | /**
73 | * 显示全部界面
74 | * @param isExpand
75 | */
76 | public Builder setUsesChronometer(boolean isExpand){
77 | headsUp.setExpand(isExpand);
78 | return this;
79 | }
80 | /**
81 | * Set the first line of text in the platform notification template.
82 | */
83 | public Builder setContentTitle(CharSequence title) {
84 | headsUp.setTitle(title);
85 | super.setContentTitle(title);
86 | return this;
87 | }
88 |
89 | /**
90 | * Set the second line of text in the platform notification template.
91 | */
92 | public Builder setContentText(CharSequence text) {
93 | headsUp.setMessage(text);
94 | super.setContentText(text);
95 | return this;
96 | }
97 | public Builder setSmallIcon(int icon) {
98 | headsUp.setIcon(icon);
99 | // super.setSmallIcon(icon);
100 | return this;
101 | }
102 | protected Builder setIcon(int icon){
103 | super.setSmallIcon(icon);
104 | return this;
105 | }
106 |
107 |
108 |
109 | public Builder setSticky(boolean isSticky){
110 | headsUp.setSticky(isSticky);
111 | return this;
112 | }
113 |
114 |
115 |
116 |
117 | @Override
118 | public Builder addAction(int icon, CharSequence title, PendingIntent intent) {
119 | NotificationCompat.Action action=new NotificationCompat.Action(icon, title, intent);
120 | actions.add(action);
121 | super.addAction(icon, title, intent);
122 | return this;
123 | }
124 |
125 |
126 |
127 |
128 | public HeadsUp buildHeadUp(){
129 | headsUp.setNotification(this.build());
130 | headsUp.setActions(actions);
131 | headsUp.setBuilder(this);
132 | return headsUp;
133 | }
134 |
135 | private Notification silencerNotification(){
136 | super.setSmallIcon(headsUp.getIcon());
137 | setDefaults(0);
138 | return this.build();
139 | }
140 |
141 | @Override
142 | public Builder setSmallIcon(int icon, int level) {
143 | setSmallIcon(icon);
144 |
145 | return this;
146 | }
147 |
148 | @Override
149 | public Builder setAutoCancel(boolean autoCancel) {
150 | super.setAutoCancel(autoCancel);
151 | return this;
152 |
153 | }
154 |
155 | @Override
156 | public Builder setColor(int argb) {
157 | super.setColor(argb);
158 | return this;
159 | }
160 |
161 | @Override
162 | public Builder setDefaults(int defaults) {
163 | super.setDefaults(defaults);
164 | return this;
165 | }
166 |
167 | @Override
168 | public Builder setFullScreenIntent(PendingIntent intent, boolean highPriority) {
169 | super.setFullScreenIntent(intent, highPriority);
170 | return this;
171 | }
172 |
173 | @Override
174 | public Builder setOngoing(boolean ongoing) {
175 | super.setOngoing(ongoing);
176 | return this;
177 | }
178 |
179 |
180 | @Override
181 | public Builder setVibrate(long[] pattern) {
182 | super.setVibrate(pattern);
183 | return this;
184 | }
185 |
186 |
187 | @Override
188 | public Builder setLargeIcon(Bitmap icon) {
189 | super.setLargeIcon(icon);
190 | return this;
191 | }
192 |
193 | @Override
194 | public Builder setLights(int argb, int onMs, int offMs) {
195 | super.setLights(argb, onMs, offMs);
196 | return this;
197 | }
198 |
199 | @Override
200 | public Builder setWhen(long when) {
201 | super.setWhen(when);
202 | return this;
203 | }
204 |
205 | @Override
206 | public Builder setShowWhen(boolean show) {
207 | super.setShowWhen(show);
208 | return this;
209 | }
210 |
211 |
212 |
213 | @Override
214 | public Builder setSubText(CharSequence text) {
215 | super.setSubText(text);
216 | return this;
217 | }
218 |
219 | @Override
220 | public Builder setNumber(int number) {
221 | super.setNumber(number);
222 | return this;
223 | }
224 |
225 | @Override
226 | public Builder setContentInfo(CharSequence info) {
227 | super.setContentInfo(info);
228 | return this;
229 | }
230 |
231 | @Override
232 | public Builder setProgress(int max, int progress, boolean indeterminate) {
233 | super.setProgress(max, progress, indeterminate);
234 | return this;
235 | }
236 |
237 | @Override
238 | public Builder setContent(RemoteViews views) {
239 | super.setContent(views);
240 | return this;
241 | }
242 |
243 | @Override
244 | public Builder setContentIntent(PendingIntent intent) {
245 | super.setContentIntent(intent);
246 | return this;
247 | }
248 |
249 | @Override
250 | public Builder setDeleteIntent(PendingIntent intent) {
251 | super.setDeleteIntent(intent);
252 | return this;
253 | }
254 |
255 | @Override
256 | public Builder setTicker(CharSequence tickerText) {
257 | super.setTicker(tickerText);
258 | return this;
259 | }
260 |
261 | @Override
262 | public Builder setTicker(CharSequence tickerText, RemoteViews views) {
263 | super.setTicker(tickerText, views);
264 | return this;
265 | }
266 |
267 | @Override
268 | public Builder setSound(Uri sound) {
269 | super.setSound(sound);
270 | return this;
271 | }
272 |
273 | @Override
274 | public Builder setSound(Uri sound, int streamType) {
275 | super.setSound(sound, streamType);
276 | return this;
277 | }
278 |
279 | @Override
280 | public Builder setOnlyAlertOnce(boolean onlyAlertOnce) {
281 | super.setOnlyAlertOnce(onlyAlertOnce);
282 | return this;
283 | }
284 |
285 | @Override
286 | public Builder setLocalOnly(boolean b) {
287 | super.setLocalOnly(b);
288 | return this;
289 | }
290 |
291 | @Override
292 | public Builder setCategory(String category) {
293 | super.setCategory(category);
294 | return this;
295 | }
296 |
297 | @Override
298 | public Builder setPriority(int pri) {
299 | super.setPriority(pri);
300 | return this;
301 | }
302 |
303 | @Override
304 | public Builder addPerson(String uri) {
305 | super.addPerson(uri);
306 | return this;
307 | }
308 |
309 | @Override
310 | public Builder setGroup(String groupKey) {
311 | super.setGroup(groupKey);
312 | return this;
313 | }
314 |
315 | @Override
316 | public Builder setGroupSummary(boolean isGroupSummary) {
317 | super.setGroupSummary(isGroupSummary);
318 | return this;
319 | }
320 |
321 | @Override
322 | public Builder setSortKey(String sortKey) {
323 | super.setSortKey(sortKey);
324 | return this;
325 | }
326 |
327 | @Override
328 | public Builder addExtras(Bundle extras) {
329 | super.addExtras(extras);
330 | return this;
331 | }
332 |
333 | @Override
334 | public Builder setExtras(Bundle extras) {
335 | super.setExtras(extras);
336 | return this;
337 | }
338 |
339 | @Override
340 | public Builder addAction(NotificationCompat.Action action) {
341 | actions.add(action);
342 | super.addAction(action);
343 | return this;
344 | }
345 |
346 | @Override
347 | public Builder setStyle(NotificationCompat.Style style) {
348 | super.setStyle(style);
349 | return this;
350 | }
351 |
352 | @Override
353 | public Builder setVisibility(int visibility) {
354 | super.setVisibility(visibility);
355 | return this;
356 | }
357 |
358 | @Override
359 | public Builder setPublicVersion(Notification n) {
360 | super.setPublicVersion(n);
361 | return this;
362 | }
363 |
364 |
365 | }
366 |
367 |
368 |
369 | protected void setIcon(int dRes) {
370 | icon = dRes;
371 | }
372 |
373 |
374 | /**
375 | * 设置消息标题
376 | *
377 | * @param titleStr
378 | */
379 | protected void setTitle(CharSequence titleStr) {
380 | this.titleStr = titleStr;
381 | }
382 |
383 | /**
384 | * 设置消息内容
385 | *
386 | * @param msgStr
387 | */
388 | protected void setMessage(CharSequence msgStr) {
389 | this.msgStr = msgStr;
390 | }
391 |
392 |
393 |
394 | public Context getContext() {
395 | return context;
396 | }
397 |
398 | public long getDuration() {
399 | return duration;
400 | }
401 |
402 |
403 | public long getInterval() {
404 | return interval;
405 | }
406 |
407 |
408 |
409 |
410 | public CharSequence getTitleStr() {
411 | return titleStr;
412 | }
413 |
414 | public CharSequence getMsgStr() {
415 | return msgStr;
416 | }
417 |
418 | public int getIcon() {
419 | return icon;
420 | }
421 |
422 | public void setInterval(long interval) {
423 | this.interval = interval;
424 | }
425 |
426 |
427 |
428 |
429 | public Notification getNotification() {
430 | return notification;
431 | }
432 |
433 | protected void setNotification(Notification notification) {
434 | this.notification = notification;
435 | }
436 |
437 |
438 | public View getCustomView() {
439 | return customView;
440 | }
441 |
442 | public void setCustomView(View customView) {
443 | this.customView = customView;
444 | }
445 |
446 | public int getCode() {
447 | return code;
448 | }
449 |
450 | protected void setCode(int code) {
451 | this.code = code;
452 | }
453 |
454 | protected List getActions() {
455 | return actions;
456 | }
457 |
458 | protected void setActions(List actions) {
459 | this.actions = actions;
460 | }
461 |
462 | protected boolean isExpand() {
463 | return isExpand;
464 | }
465 |
466 | protected void setExpand(boolean isExpand) {
467 | this.isExpand = isExpand;
468 | }
469 |
470 | protected Notification getSilencerNotification() {
471 | return getBuilder().silencerNotification();
472 | }
473 |
474 |
475 |
476 | protected Builder getBuilder() {
477 | return builder;
478 | }
479 |
480 | private void setBuilder(Builder builder) {
481 | this.builder = builder;
482 | }
483 |
484 |
485 | public boolean isSticky() {
486 | return isSticky;
487 | }
488 |
489 | public void setSticky(boolean isSticky) {
490 | this.isSticky = isSticky;
491 | }
492 |
493 |
494 | protected boolean isActivateStatusBar() {
495 | return activateStatusBar;
496 | }
497 |
498 | public void setActivateStatusBar(boolean activateStatusBar) {
499 | this.activateStatusBar = activateStatusBar;
500 | }
501 | }
502 |
--------------------------------------------------------------------------------
/library/src/main/java/com/mingle/headsUp/FloatView.java:
--------------------------------------------------------------------------------
1 | package com.mingle.headsUp;
2 |
3 |
4 | import android.annotation.SuppressLint;
5 | import android.app.PendingIntent;
6 | import android.content.Context;
7 | import android.os.Handler;
8 | import android.os.Message;
9 | import android.view.LayoutInflater;
10 | import android.view.MotionEvent;
11 | import android.view.VelocityTracker;
12 | import android.view.View;
13 | import android.view.ViewConfiguration;
14 | import android.view.WindowManager;
15 | import android.widget.ImageView;
16 | import android.widget.LinearLayout;
17 | import android.widget.TextView;
18 | import com.nineoldandroids.animation.Animator;
19 | import com.nineoldandroids.animation.AnimatorSet;
20 | import com.nineoldandroids.animation.ObjectAnimator;
21 | import java.text.SimpleDateFormat;
22 | import java.util.Date;
23 |
24 | /**
25 | *
26 | */
27 | @SuppressLint("ViewConstructor")
28 | public class FloatView extends LinearLayout {
29 |
30 |
31 |
32 | private float rawX = 0;
33 | private float rawY=0;
34 | private float touchX = 0;
35 | private float startY = 0;
36 | public LinearLayout rootView;
37 | public int originalLeft;
38 | public int viewWidth;
39 | private float validWidth;
40 | private VelocityTracker velocityTracker;
41 | private int maxVelocity;
42 | private Distance distance;
43 |
44 | private ScrollOrientationEnum scrollOrientationEnum=ScrollOrientationEnum.NONE;
45 |
46 | public static WindowManager.LayoutParams winParams = new WindowManager.LayoutParams();
47 |
48 | public FloatView(final Context context, int i) {
49 | super(context);
50 | LinearLayout view = (LinearLayout) LayoutInflater.from(getContext()).inflate(R.layout.notification_bg, null);
51 | maxVelocity= ViewConfiguration.get(context).getScaledMaximumFlingVelocity();
52 | rootView = (LinearLayout) view.findViewById(R.id.rootView);
53 | addView(view);
54 | viewWidth = context.getResources().getDisplayMetrics().widthPixels;
55 | validWidth=viewWidth/2.0f;
56 | originalLeft = 0;
57 | distance=new Distance(context);
58 | }
59 |
60 | public void setCustomView(View view) {
61 | rootView.addView(view);
62 | }
63 |
64 |
65 | @Override
66 | protected void onFinishInflate() {
67 | super.onFinishInflate();
68 | }
69 |
70 |
71 | private HeadsUp headsUp;
72 | private long cutDown;
73 | private Handler mHandle=null;
74 | private CutDownTime cutDownTime;
75 | private class CutDownTime extends Thread{
76 |
77 | @Override
78 | public void run() {
79 | super.run();
80 |
81 |
82 | while (cutDown>0){
83 | try {
84 | Thread.sleep(1000);
85 | cutDown--;
86 | } catch (InterruptedException e) {
87 | e.printStackTrace();
88 | }
89 | }
90 |
91 | if(cutDown==0) {
92 | mHandle.sendEmptyMessage(0);
93 | }
94 |
95 |
96 | }
97 | };
98 |
99 |
100 |
101 | public HeadsUp getHeadsUp() {
102 | return headsUp;
103 | }
104 |
105 | private int pointerId;
106 | public boolean onTouchEvent(MotionEvent event) {
107 | rawX = event.getRawX();
108 | rawY=event.getRawY();
109 | acquireVelocityTracker(event);
110 | cutDown= headsUp.getDuration();
111 | switch (event.getAction()) {
112 | case MotionEvent.ACTION_DOWN:
113 | touchX = event.getX();
114 | startY = event.getRawY();
115 | pointerId=event.getPointerId(0);
116 | break;
117 | case MotionEvent.ACTION_MOVE:
118 | switch (scrollOrientationEnum){
119 | case NONE:
120 | if(Math.abs((rawX - touchX))>20) {
121 | scrollOrientationEnum=ScrollOrientationEnum.HORIZONTAL;
122 |
123 | }else if(startY-rawY>20){
124 | scrollOrientationEnum=ScrollOrientationEnum.VERTICAL;
125 |
126 | }
127 |
128 | break;
129 | case HORIZONTAL:
130 | updatePosition((int) (rawX - touchX));
131 | break;
132 | case VERTICAL:
133 | if(startY-rawY>20) {
134 | cancel();
135 | }
136 | break;
137 | }
138 |
139 | break;
140 | case MotionEvent.ACTION_UP:
141 | velocityTracker.computeCurrentVelocity(1000,maxVelocity);
142 | int dis= (int) velocityTracker.getYVelocity(pointerId);
143 | if(scrollOrientationEnum==ScrollOrientationEnum.NONE){
144 | if(headsUp.getNotification().contentIntent!=null){
145 |
146 | try {
147 | headsUp.getNotification().contentIntent.send();
148 | cancel();
149 | } catch (PendingIntent.CanceledException e) {
150 | e.printStackTrace();
151 | }
152 | }
153 | break;
154 | }
155 |
156 |
157 | int toX;
158 | if(preLeft>0){
159 | toX= (int) (preLeft+Math.abs(dis));
160 | }else{
161 | toX= (int) (preLeft-Math.abs(dis));
162 | }
163 | if (toX <= -validWidth) {
164 | float preAlpha=1-Math.abs(preLeft)/validWidth;
165 | preAlpha=preAlpha>=0?preAlpha:0;
166 | translationX(preLeft,-(validWidth+10),preAlpha,0);
167 | } else if (toX <= validWidth) {
168 | float preAlpha=1-Math.abs(preLeft)/validWidth;
169 | preAlpha=preAlpha>=0?preAlpha:0;
170 | translationX(preLeft,0,preAlpha,1);
171 |
172 | }else{
173 | float preAlpha=1-Math.abs(preLeft)/validWidth;
174 | preAlpha=preAlpha>=0?preAlpha:0;
175 | translationX(preLeft, validWidth + 10, preAlpha, 0);
176 | }
177 | preLeft = 0;
178 | scrollOrientationEnum=ScrollOrientationEnum.NONE;
179 | break;
180 | }
181 |
182 | return super.onTouchEvent(event);
183 |
184 | }
185 | /**
186 | *
187 | * @param event 向VelocityTracker添加MotionEvent
188 | *
189 | * @see android.view.VelocityTracker#obtain()
190 | * @see android.view.VelocityTracker#addMovement(MotionEvent)
191 | */
192 | private void acquireVelocityTracker( MotionEvent event) {
193 | if(null == velocityTracker) {
194 | velocityTracker = VelocityTracker.obtain();
195 | }
196 | velocityTracker.addMovement(event);
197 | }
198 |
199 |
200 | private int preLeft;
201 |
202 | public void updatePosition(int left) {
203 |
204 | float preAlpha=1-Math.abs(preLeft)/validWidth;
205 | float leftAlpha=1-Math.abs(left)/validWidth;
206 | preAlpha = preAlpha>=0 ? preAlpha : 0;
207 | leftAlpha = leftAlpha>=0 ? leftAlpha : 0;
208 | translationX(preLeft,left,preAlpha,leftAlpha);
209 |
210 | preLeft = left;
211 | }
212 |
213 |
214 |
215 | public void translationX(float fromX,float toX,float formAlpha, final float toAlpha ){
216 | ObjectAnimator a1=ObjectAnimator.ofFloat(rootView,"alpha",formAlpha,toAlpha);
217 | ObjectAnimator a2 = ObjectAnimator.ofFloat(rootView, "translationX", fromX, toX);
218 | AnimatorSet animatorSet=new AnimatorSet();
219 | animatorSet.playTogether(a1,a2);
220 | animatorSet.addListener(new Animator.AnimatorListener() {
221 | @Override
222 | public void onAnimationStart(Animator animation) {
223 | }
224 |
225 | @Override
226 | public void onAnimationEnd(Animator animation) {
227 | if(toAlpha==0){
228 | HeadsUpManager.getInstant(getContext()).dismiss();
229 |
230 | cutDown=-1;
231 | if(velocityTracker!=null) {
232 | velocityTracker.clear();
233 | try {
234 | velocityTracker.recycle();
235 | } catch (IllegalStateException e) {
236 |
237 | }
238 | }
239 |
240 | }
241 | }
242 |
243 | @Override
244 | public void onAnimationCancel(Animator animation) {
245 | }
246 |
247 | @Override
248 | public void onAnimationRepeat(Animator animation) {
249 | }
250 | });
251 | animatorSet.start();
252 | }
253 |
254 | public void setNotification(final HeadsUp headsUp) {
255 |
256 | this.headsUp = headsUp;
257 |
258 | mHandle= new Handler(){
259 | @Override
260 | public void handleMessage(Message msg) {
261 | super.handleMessage(msg);
262 | if(headsUp.isActivateStatusBar()) {
263 | HeadsUpManager.getInstant(getContext()).silencerNotify(headsUp);
264 | }
265 | HeadsUpManager.getInstant(getContext()).animDismiss(headsUp);
266 | }
267 | };
268 |
269 |
270 |
271 | cutDownTime= new CutDownTime();
272 |
273 | if(!headsUp.isSticky()){
274 | cutDownTime.start();
275 | }
276 |
277 |
278 | cutDown= headsUp.getDuration();
279 |
280 | if (headsUp.getCustomView() == null) {
281 |
282 | View defaultView = LayoutInflater.from(getContext()).inflate(R.layout.notification, rootView, false);
283 | rootView.addView(defaultView);
284 | ImageView imageView = (ImageView) defaultView.findViewById(R.id.iconIM);
285 | TextView titleTV = (TextView) defaultView.findViewById(R.id.titleTV);
286 | TextView timeTV = (TextView) defaultView.findViewById(R.id.timeTV);
287 | TextView messageTV = (TextView) defaultView.findViewById(R.id.messageTV);
288 | imageView.setImageResource(headsUp.getIcon());
289 | titleTV.setText(headsUp.getTitleStr());
290 | messageTV.setText(headsUp.getMsgStr());
291 | SimpleDateFormat simpleDateFormat=new SimpleDateFormat("HH:mm");
292 | timeTV.setText( simpleDateFormat.format(new Date()));
293 |
294 | if(headsUp.isExpand() && headsUp.getActions().size()>0){
295 |
296 | defaultView.findViewById(R.id.menuL).setVisibility(VISIBLE);
297 | defaultView.findViewById(R.id.line).setVisibility(VISIBLE);
298 |
299 | defaultView.findViewById(R.id.menu1).setVisibility(VISIBLE);
300 | ImageView imageView1= (ImageView) defaultView.findViewById(R.id.menuIM1);
301 | ImageView imageView2= (ImageView) defaultView.findViewById(R.id.menuIM2);
302 | ImageView imageView3= (ImageView) defaultView.findViewById(R.id.menuIM3);
303 | TextView text1= (TextView) defaultView.findViewById(R.id.menuText1);
304 | TextView text2= (TextView) defaultView.findViewById(R.id.menuText2);
305 | TextView text3= (TextView) defaultView.findViewById(R.id.menuText3);
306 | imageView1.setImageResource(headsUp.getActions().get(0).icon);
307 | text1.setText(headsUp.getActions().get(0).title);
308 |
309 | defaultView.findViewById(R.id.menu1).setOnClickListener(new OnClickListener() {
310 | @Override
311 | public void onClick(View v) {
312 | try {
313 | headsUp.getActions().get(0).actionIntent.send();
314 | cancel();
315 | } catch (PendingIntent.CanceledException e) {
316 | e.printStackTrace();
317 | }
318 | }
319 | });
320 |
321 | if(headsUp.getActions().size()>1){
322 |
323 | defaultView.findViewById(R.id.menu2).setVisibility(VISIBLE);
324 |
325 | imageView2.setImageResource(headsUp.getActions().get(1).icon);
326 | text2.setText(headsUp.getActions().get(1).title);
327 | defaultView.findViewById(R.id.menu2).setOnClickListener(new OnClickListener() {
328 | @Override
329 | public void onClick(View v) {
330 | try {
331 | headsUp.getActions().get(1).actionIntent.send();
332 | cancel();
333 | } catch (PendingIntent.CanceledException e) {
334 | e.printStackTrace();
335 | }
336 | }
337 | });
338 | }
339 |
340 | if(headsUp.getActions().size()>2){
341 |
342 | defaultView.findViewById(R.id.menu3).setVisibility(VISIBLE);
343 | imageView3.setImageResource(headsUp.getActions().get(2).icon);
344 | text3.setText(headsUp.getActions().get(2).title);
345 | defaultView.findViewById(R.id.menu3).setOnClickListener(new OnClickListener() {
346 | @Override
347 | public void onClick(View v) {
348 | try {
349 | headsUp.getActions().get(2).actionIntent.send();
350 | cancel();
351 | } catch (PendingIntent.CanceledException e) {
352 | e.printStackTrace();
353 | }
354 | }
355 | });
356 |
357 | }
358 | }
359 |
360 | } else {
361 | setCustomView(headsUp.getCustomView());
362 | }
363 |
364 | }
365 |
366 |
367 | protected void cancel(){
368 | HeadsUpManager.getInstant(getContext()).animDismiss();
369 | cutDown = -1;
370 | cutDownTime.interrupt();
371 |
372 |
373 | if(velocityTracker!=null) {
374 | try {
375 | velocityTracker.clear();
376 | velocityTracker.recycle();
377 | } catch (IllegalStateException e) {
378 |
379 | }
380 | }
381 | }
382 |
383 |
384 |
385 |
386 | enum ScrollOrientationEnum {
387 | VERTICAL,HORIZONTAL,NONE
388 | }
389 | }
390 |
--------------------------------------------------------------------------------