├── settings.gradle ├── samples ├── demo │ ├── board.gif │ ├── local.gif │ ├── global.gif │ ├── remote.gif │ └── badge_example.png ├── res │ ├── drawable-mdpi │ │ ├── android_gray.png │ │ └── ic_launcher.png │ ├── values │ │ └── strings.xml │ └── layout │ │ └── main.xml ├── build.gradle ├── src │ └── zemin │ │ └── notification │ │ └── samples │ │ ├── MainApplication.java │ │ └── MainActivity.java └── AndroidManifest.xml ├── core ├── res │ ├── raw │ │ └── fallbackring.ogg │ ├── drawable-mdpi │ │ ├── clear_button.png │ │ └── divider_horizontal_dark.9.png │ ├── values │ │ ├── strings.xml │ │ └── styles.xml │ └── layout │ │ ├── notification_text_only.xml │ │ ├── notification_board_footer.xml │ │ ├── notification_simple_2.xml │ │ ├── notification_simple.xml │ │ ├── notification_large_icon.xml │ │ ├── notification_full.xml │ │ └── notification_board_row.xml ├── AndroidManifest.xml ├── src │ └── zemin │ │ └── notification │ │ ├── CallbackNotFoundException.java │ │ ├── Utils.java │ │ ├── NotificationListener.java │ │ ├── AnimationListener.java │ │ ├── AnimatorListener.java │ │ ├── AnimationFactory.java │ │ ├── ViewWrapper.java │ │ ├── GestureListener.java │ │ ├── ChildViewManager.java │ │ ├── NotificationLocal.java │ │ ├── NotificationRemoteCallback.java │ │ ├── NotificationViewCallback.java │ │ ├── NotificationBoardCallback.java │ │ ├── ViewSwitcherWrapper.java │ │ ├── NotificationEffect.java │ │ ├── NotificationRemote.java │ │ ├── NotificationDelegater.java │ │ ├── NotificationGlobal.java │ │ ├── NotificationHandler.java │ │ └── NotificationRootView.java └── build.gradle ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradle.properties ├── .gitignore ├── gradlew.bat ├── gradlew ├── README.md └── LICENSE /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':core' 2 | include ':samples' 3 | -------------------------------------------------------------------------------- /samples/demo/board.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lamydev/Android-Notification/HEAD/samples/demo/board.gif -------------------------------------------------------------------------------- /samples/demo/local.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lamydev/Android-Notification/HEAD/samples/demo/local.gif -------------------------------------------------------------------------------- /samples/demo/global.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lamydev/Android-Notification/HEAD/samples/demo/global.gif -------------------------------------------------------------------------------- /samples/demo/remote.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lamydev/Android-Notification/HEAD/samples/demo/remote.gif -------------------------------------------------------------------------------- /core/res/raw/fallbackring.ogg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lamydev/Android-Notification/HEAD/core/res/raw/fallbackring.ogg -------------------------------------------------------------------------------- /samples/demo/badge_example.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lamydev/Android-Notification/HEAD/samples/demo/badge_example.png -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lamydev/Android-Notification/HEAD/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /core/res/drawable-mdpi/clear_button.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lamydev/Android-Notification/HEAD/core/res/drawable-mdpi/clear_button.png -------------------------------------------------------------------------------- /samples/res/drawable-mdpi/android_gray.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lamydev/Android-Notification/HEAD/samples/res/drawable-mdpi/android_gray.png -------------------------------------------------------------------------------- /samples/res/drawable-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lamydev/Android-Notification/HEAD/samples/res/drawable-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /core/res/drawable-mdpi/divider_horizontal_dark.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lamydev/Android-Notification/HEAD/core/res/drawable-mdpi/divider_horizontal_dark.9.png -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | COMPILE_SDK_VERSION=22 2 | BUILD_TOOLS_VERSION=22.0.0 3 | MIN_SDK_VERSION=11 4 | TARGET_SDK_VERSION=22 5 | 6 | PROJECT_VERSION_CODE=3 7 | PROJECT_VERSION_NAME=3.0 8 | -------------------------------------------------------------------------------- /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=http\://services.gradle.org/distributions/gradle-2.2.1-all.zip 7 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Built application files 2 | *.apk 3 | *.ap_ 4 | 5 | # Files for the Dalvik VM 6 | *.dex 7 | 8 | # Java class files 9 | *.class 10 | 11 | # Generated files 12 | bin/ 13 | gen/ 14 | 15 | # Gradle files 16 | .gradle/ 17 | build/ 18 | /*/build/ 19 | 20 | # Local configuration file (sdk path, etc) 21 | local.properties 22 | 23 | # Proguard folder generated by Eclipse 24 | proguard/ 25 | 26 | # Log Files 27 | *.log 28 | -------------------------------------------------------------------------------- /samples/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | dependencies { 4 | compile project(':core') 5 | compile 'com.android.support:appcompat-v7:22.0.0' 6 | } 7 | 8 | android { 9 | compileSdkVersion 22 10 | buildToolsVersion "22.0.0" 11 | 12 | defaultConfig { 13 | minSdkVersion 11 14 | targetSdkVersion 22 15 | versionCode 1 16 | versionName "1.0.0" 17 | } 18 | 19 | sourceSets { 20 | main { 21 | manifest.srcFile 'AndroidManifest.xml' 22 | java.srcDir 'src' 23 | res.srcDir 'res' 24 | assets.srcDir 'assets' 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /core/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /core/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 19 | 20 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /core/src/zemin/notification/CallbackNotFoundException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 Zemin Liu 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package zemin.notification; 18 | 19 | /** 20 | * RuntimeException to be thrown when callback not set. 21 | */ 22 | public class CallbackNotFoundException extends RuntimeException { 23 | 24 | public CallbackNotFoundException(String msg) { super(msg); } 25 | } 26 | -------------------------------------------------------------------------------- /core/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'android-library' 2 | 3 | repositories { 4 | mavenCentral() 5 | } 6 | 7 | dependencies { 8 | compile 'com.android.support:appcompat-v7:22.0.0' 9 | } 10 | 11 | project.group = 'com.github.lamydev' 12 | 13 | android { 14 | 15 | compileSdkVersion Integer.parseInt(project.COMPILE_SDK_VERSION) 16 | buildToolsVersion project.BUILD_TOOLS_VERSION 17 | 18 | defaultConfig { 19 | minSdkVersion Integer.parseInt(project.MIN_SDK_VERSION) 20 | targetSdkVersion Integer.parseInt(project.TARGET_SDK_VERSION) 21 | versionCode Integer.parseInt(project.PROJECT_VERSION_CODE) 22 | versionName project.PROJECT_VERSION_NAME 23 | } 24 | 25 | sourceSets { 26 | main { 27 | manifest.srcFile 'AndroidManifest.xml' 28 | java.srcDir 'src' 29 | res.srcDir 'res' 30 | assets.srcDir 'assets' 31 | } 32 | } 33 | 34 | lintOptions { 35 | abortOnError false 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /samples/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 19 | 20 | 21 | zemin-noti-samples 22 | 23 | remote 24 | local 25 | global 26 | board 27 | arrival 28 | total 29 | 30 | cancelAll 31 | dismiss 32 | 33 | 0 34 | 35 | -------------------------------------------------------------------------------- /core/res/layout/notification_text_only.xml: -------------------------------------------------------------------------------- 1 | 2 | 19 | 20 | 23 | 24 | 32 | 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /core/src/zemin/notification/Utils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 Zemin Liu 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package zemin.notification; 18 | 19 | /** 20 | * Utils 21 | */ 22 | public class Utils { 23 | 24 | /** 25 | * Calculate the alpha value for a position offset. 26 | * 27 | * @param alphaStart 28 | * @param alphaEnd 29 | * @param posStart 30 | * @param posEnd 31 | * @param posOffset 32 | */ 33 | public static float getAlphaForOffset(float alphaStart, float alphaEnd, 34 | float posStart, float posEnd, float posOffset) { 35 | return alphaStart + posOffset * (alphaEnd - alphaStart) / (posEnd - posStart); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /core/res/layout/notification_board_footer.xml: -------------------------------------------------------------------------------- 1 | 2 | 19 | 20 | 24 | 25 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /samples/src/zemin/notification/samples/MainApplication.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 Zemin Liu 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package zemin.notification.samples; 18 | 19 | import android.app.Application; 20 | 21 | import zemin.notification.NotificationDelegater; 22 | 23 | // 24 | public class MainApplication extends Application { 25 | 26 | @Override 27 | public void onCreate() { 28 | super.onCreate(); 29 | 30 | initNotification(); 31 | } 32 | 33 | private void initNotification() { 34 | 35 | NotificationDelegater.initialize( 36 | this, 37 | NotificationDelegater.LOCAL | 38 | NotificationDelegater.GLOBAL | 39 | NotificationDelegater.REMOTE); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /samples/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 19 | 20 | 22 | 23 | 28 | 29 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /core/src/zemin/notification/NotificationListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 Zemin Liu 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package zemin.notification; 18 | 19 | /** 20 | * Listener used to propagate events indicating when notifications 21 | * are delivered and/or canceled. 22 | * 23 | * @see NotificationDelegater#addListener 24 | * @see NotificationDelegater#removeListener 25 | */ 26 | public interface NotificationListener { 27 | 28 | /** 29 | * Called when a notification arrives. 30 | * 31 | * @param entry 32 | */ 33 | void onArrival(NotificationEntry entry); 34 | 35 | /** 36 | * Called when a notification is canceled. 37 | * 38 | * @param entry 39 | */ 40 | void onCancel(NotificationEntry entry); 41 | 42 | /** 43 | * Called when a notification is updated. 44 | * 45 | * @param entry 46 | */ 47 | void onUpdate(NotificationEntry entry); 48 | } 49 | -------------------------------------------------------------------------------- /core/src/zemin/notification/AnimationListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 Zemin Liu 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package zemin.notification; 18 | 19 | import android.view.View; 20 | import android.view.animation.Animation; 21 | 22 | /** 23 | * A convenience class to extend when you only want to listen for a subset 24 | * of all animation states. This implements all methods in the 25 | * {@link android.view.animation.Animation#AnimationListener}. 26 | */ 27 | public class AnimationListener implements Animation.AnimationListener { 28 | 29 | /** 30 | * {@inheritDoc} 31 | */ 32 | @Override 33 | public void onAnimationStart(Animation animation) { 34 | } 35 | 36 | /** 37 | * {@inheritDoc} 38 | */ 39 | @Override 40 | public void onAnimationEnd(Animation animation) { 41 | } 42 | 43 | /** 44 | * {@inheritDoc} 45 | */ 46 | @Override 47 | public void onAnimationRepeat(Animation animation) { 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /core/src/zemin/notification/AnimatorListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 Zemin Liu 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package zemin.notification; 18 | 19 | import android.animation.Animator; 20 | import android.view.View; 21 | 22 | /** 23 | * A convenience class to extend when you only want to listen for a subset 24 | * of all animator states. This implements all methods in the 25 | * {@link android.animation.Animator#AnimatorListener}. 26 | */ 27 | public class AnimatorListener implements Animator.AnimatorListener { 28 | 29 | /** 30 | * {@inheritDoc} 31 | */ 32 | @Override 33 | public void onAnimationStart(Animator animation) { 34 | } 35 | 36 | /** 37 | * {@inheritDoc} 38 | */ 39 | @Override 40 | public void onAnimationEnd(Animator animation) { 41 | } 42 | 43 | /** 44 | * {@inheritDoc} 45 | */ 46 | @Override 47 | public void onAnimationRepeat(Animator animation) { 48 | } 49 | 50 | /** 51 | * {@inheritDoc} 52 | */ 53 | @Override 54 | public void onAnimationCancel(Animator animator) { 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /core/res/layout/notification_simple_2.xml: -------------------------------------------------------------------------------- 1 | 2 | 19 | 20 | 30 | 31 | 37 | 38 | 45 | 46 | 53 | 54 | 62 | 63 | 64 | -------------------------------------------------------------------------------- /core/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 19 | 20 | 21 | 22 | 30 | 31 | 37 | 38 | 42 | 43 | 51 | 52 | 59 | 60 | 63 | 64 | 65 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /core/src/zemin/notification/AnimationFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 Zemin Liu 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package zemin.notification; 18 | 19 | import android.view.animation.AlphaAnimation; 20 | import android.view.animation.Animation; 21 | import android.view.animation.AnimationSet; 22 | import android.view.animation.TranslateAnimation; 23 | 24 | /** 25 | * Animation Factory 26 | */ 27 | public class AnimationFactory { 28 | 29 | /** 30 | * Create push down animation for entering. 31 | * 32 | * @return Animation 33 | */ 34 | public static Animation pushDownIn() { 35 | AnimationSet animationSet = new AnimationSet(true); 36 | animationSet.setFillAfter(true); 37 | animationSet.addAnimation(new TranslateAnimation(0, 0, -100, 0)); 38 | animationSet.addAnimation(new AlphaAnimation(0.0f, 1.0f)); 39 | return animationSet; 40 | } 41 | 42 | /** 43 | * Create push down animation for leaving. 44 | * 45 | * @return Animation 46 | */ 47 | public static Animation pushDownOut() { 48 | AnimationSet animationSet = new AnimationSet(true); 49 | animationSet.setFillAfter(true); 50 | animationSet.addAnimation(new TranslateAnimation(0, 0, 0, 100)); 51 | animationSet.addAnimation(new AlphaAnimation(1.0f, 0.0f)); 52 | return animationSet; 53 | } 54 | 55 | /** 56 | * Create push up animation for entering. 57 | * 58 | * @return Animation 59 | */ 60 | public static Animation pushUpIn() { 61 | AnimationSet animationSet = new AnimationSet(true); 62 | animationSet.setFillAfter(true); 63 | animationSet.addAnimation(new TranslateAnimation(0, 0, 100, 0)); 64 | animationSet.addAnimation(new AlphaAnimation(0.0f, 1.0f)); 65 | return animationSet; 66 | } 67 | 68 | /** 69 | * Create push up animation for leaving. 70 | * 71 | * @return Animation 72 | */ 73 | public static Animation pushUpOut() { 74 | AnimationSet animationSet = new AnimationSet(true); 75 | animationSet.setFillAfter(true); 76 | animationSet.addAnimation(new TranslateAnimation(0, 0, 0, -100)); 77 | animationSet.addAnimation(new AlphaAnimation(1.0f, 0.0f)); 78 | return animationSet; 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /core/src/zemin/notification/ViewWrapper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 Zemin Liu 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package zemin.notification; 18 | 19 | import android.graphics.drawable.Drawable; 20 | import android.view.View; 21 | import android.widget.ImageView; 22 | import android.widget.TextView; 23 | 24 | /** 25 | * 26 | */ 27 | public class ViewWrapper { 28 | 29 | private static final String TAG = "zemin.ViewWrapper"; 30 | public static boolean DBG; 31 | 32 | public final String name; 33 | public View view; 34 | 35 | public ViewWrapper(String name) { 36 | this.name = name; 37 | } 38 | 39 | public void clear() { 40 | view = null; 41 | } 42 | 43 | public void reset() { 44 | } 45 | 46 | public boolean hasView() { 47 | return view != null; 48 | } 49 | 50 | public void setView(View view) { 51 | this.view = view; 52 | } 53 | 54 | public View getView() { 55 | return view; 56 | } 57 | 58 | public void show() { 59 | if (view != null) { 60 | view.setVisibility(View.VISIBLE); 61 | } 62 | } 63 | 64 | public void hide() { 65 | if (view != null) { 66 | view.setVisibility(View.INVISIBLE); 67 | } 68 | } 69 | 70 | public void setImageDrawable(Drawable drawable) { 71 | setImageDrawable(drawable, true); 72 | } 73 | 74 | // throws ClassCastException 75 | public void setImageDrawable(Drawable drawable, boolean animate) { 76 | if (view != null) { 77 | ((ImageView) view).setImageDrawable(drawable); 78 | } 79 | } 80 | 81 | public void setText(CharSequence text) { 82 | setText(text, true); 83 | } 84 | 85 | // throws ClassCastException 86 | public void setText(CharSequence text, boolean animate) { 87 | if (view != null) { 88 | ((TextView) view).setText(text); 89 | } 90 | } 91 | 92 | public void setTextSize(int size) { 93 | if (view != null) { 94 | ((TextView) view).setTextSize(size); 95 | } 96 | } 97 | 98 | public void setTextColor(int color) { 99 | if (view != null) { 100 | ((TextView) view).setTextColor(color); 101 | } 102 | } 103 | } 104 | -------------------------------------------------------------------------------- /core/src/zemin/notification/GestureListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 Zemin Liu 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package zemin.notification; 18 | 19 | import android.view.GestureDetector; 20 | import android.view.MotionEvent; 21 | 22 | /** 23 | * A convenience class to extend when you only want to listen for a subset 24 | * of all gesture states. This implements all methods in the 25 | * {@link android.view.GestureDetector#OnGestureListener} and 26 | * {@link android.view.GestureDetector#OnDoubleTapListener}. 27 | * 28 | * Moreover, new APIs are also introduced: 29 | * 30 | * 1) void onUpOrCancel(MotionEvent event, boolean handled); 31 | */ 32 | public class GestureListener implements GestureDetector.OnGestureListener, 33 | GestureDetector.OnDoubleTapListener { 34 | 35 | /** 36 | * Called when {@link MotionEvent#ACTION_UP} or {@link MotionEvent#ACTION_CANCEL} event occurs. 37 | * 38 | * @param event 39 | * @param handled 40 | */ 41 | public void onUpOrCancel(MotionEvent event, boolean handled) { 42 | } 43 | 44 | /** 45 | * {@inheritDoc} 46 | */ 47 | @Override 48 | public boolean onDown(MotionEvent event) { 49 | return false; 50 | } 51 | 52 | /** 53 | * {@inheritDoc} 54 | */ 55 | @Override 56 | public void onShowPress(MotionEvent event) { 57 | } 58 | 59 | /** 60 | * {@inheritDoc} 61 | */ 62 | @Override 63 | public boolean onSingleTapUp(MotionEvent event) { 64 | return false; 65 | } 66 | 67 | /** 68 | * {@inheritDoc} 69 | */ 70 | @Override 71 | public boolean onSingleTapConfirmed(MotionEvent event) { 72 | return false; 73 | } 74 | 75 | /** 76 | * {@inheritDoc} 77 | */ 78 | @Override 79 | public boolean onDoubleTap(MotionEvent event) { 80 | return false; 81 | } 82 | 83 | /** 84 | * {@inheritDoc} 85 | */ 86 | @Override 87 | public boolean onDoubleTapEvent(MotionEvent event) { 88 | return false; 89 | } 90 | 91 | /** 92 | * {@inheritDoc} 93 | */ 94 | @Override 95 | public void onLongPress(MotionEvent event) { 96 | } 97 | 98 | /** 99 | * {@inheritDoc} 100 | */ 101 | @Override 102 | public boolean onScroll(MotionEvent event1, MotionEvent event2, float distanceX, float distanceY) { 103 | return false; 104 | } 105 | 106 | /** 107 | * {@inheritDoc} 108 | */ 109 | @Override 110 | public boolean onFling(MotionEvent event1, MotionEvent event2, float velocityX, float velocityY) { 111 | return false; 112 | } 113 | } 114 | -------------------------------------------------------------------------------- /core/res/layout/notification_simple.xml: -------------------------------------------------------------------------------- 1 | 2 | 19 | 20 | 30 | 31 | 37 | 41 | 45 | 46 | 47 | 53 | 57 | 61 | 62 | 63 | 69 | 73 | 77 | 78 | 79 | 86 | 90 | 94 | 95 | 96 | -------------------------------------------------------------------------------- /core/res/layout/notification_large_icon.xml: -------------------------------------------------------------------------------- 1 | 2 | 19 | 20 | 28 | 29 | 39 | 45 | 50 | 54 | 58 | 59 | 60 | 65 | 69 | 73 | 74 | 75 | 76 | 80 | 84 | 88 | 89 | 90 | 91 | 99 | 103 | 107 | 108 | 109 | -------------------------------------------------------------------------------- /core/res/layout/notification_full.xml: -------------------------------------------------------------------------------- 1 | 2 | 19 | 20 | 29 | 30 | 38 | 43 | 47 | 51 | 52 | 53 | 59 | 63 | 67 | 68 | 69 | 75 | 79 | 83 | 84 | 85 | 86 | 96 | 100 | 105 | 110 | 111 | 112 | 113 | -------------------------------------------------------------------------------- /core/src/zemin/notification/ChildViewManager.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 Zemin Liu 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package zemin.notification; 18 | 19 | import android.graphics.drawable.Drawable; 20 | import android.view.View; 21 | import android.widget.ViewSwitcher; 22 | 23 | import android.support.v4.util.ArrayMap; 24 | 25 | import java.util.Collection; 26 | 27 | /** 28 | * 29 | */ 30 | public class ChildViewManager { 31 | 32 | private static final String TAG = "zemin.ChildViewManager"; 33 | public static boolean DBG; 34 | 35 | public void setView(String name, View view) { 36 | Holder holder = mHolders.get(name); 37 | if (holder == null && name != null) { 38 | holder = new Holder(name); 39 | mHolders.put(name, holder); 40 | } 41 | holder.set(view); 42 | } 43 | 44 | public ViewWrapper getViewWrapper(String name) { 45 | Holder holder = mHolders.get(name); 46 | return holder != null ? holder.curr() : null; 47 | } 48 | 49 | public void show(String name) { 50 | getViewWrapper(name).show(); 51 | } 52 | 53 | public void hide(String name) { 54 | getViewWrapper(name).hide(); 55 | } 56 | 57 | public void setImageDrawable(String name, Drawable drawable) { 58 | setImageDrawable(name, drawable, true); 59 | } 60 | 61 | public void setImageDrawable(String name, Drawable drawable, boolean animate) { 62 | ViewWrapper v = getViewWrapper(name); 63 | if (drawable != null) { 64 | v.show(); 65 | v.setImageDrawable(drawable, animate); 66 | } else { 67 | v.hide(); 68 | } 69 | } 70 | 71 | public void setText(String name, CharSequence text) { 72 | setText(name, text, true); 73 | } 74 | 75 | public void setText(String name, CharSequence text, boolean animate) { 76 | ViewWrapper v = getViewWrapper(name); 77 | if (text != null) { 78 | v.show(); 79 | v.setText(text, animate); 80 | } else { 81 | v.hide(); 82 | } 83 | } 84 | 85 | public void setTextSize(String name, int size) { 86 | getViewWrapper(name).setTextSize(size); 87 | } 88 | 89 | public void setTextColor(String name, int color) { 90 | getViewWrapper(name).setTextColor(color); 91 | } 92 | 93 | public void clear() { 94 | Collection holders = mHolders.values(); 95 | for (Holder h : holders) { 96 | h.clear(); 97 | } 98 | } 99 | 100 | public void reset() { 101 | Collection holders = mHolders.values(); 102 | for (Holder h : holders) { 103 | h.reset(); 104 | } 105 | } 106 | 107 | private final ArrayMap mHolders = 108 | new ArrayMap(); 109 | 110 | private class Holder { 111 | final String name; 112 | ViewWrapper view; 113 | ViewSwitcherWrapper switcher; 114 | Holder(String name) { this.name = name; } 115 | 116 | ViewWrapper curr() { 117 | if (switcher != null && switcher.hasView()) { 118 | return switcher; 119 | } else if (view != null && view.hasView()) { 120 | return view; 121 | } 122 | return null; 123 | } 124 | 125 | void set(View v) { 126 | if (v instanceof ViewSwitcher) { 127 | if (switcher == null) { 128 | switcher = new ViewSwitcherWrapper(name); 129 | } 130 | switcher.setView(v); 131 | } else { 132 | if (view == null) { 133 | view = new ViewWrapper(name); 134 | } 135 | view.setView(v); 136 | } 137 | } 138 | 139 | void clear() { 140 | ViewWrapper curr = curr(); 141 | if (curr != null) curr.clear(); 142 | } 143 | 144 | void reset() { 145 | ViewWrapper curr = curr(); 146 | if (curr != null) curr.reset(); 147 | } 148 | } 149 | } 150 | -------------------------------------------------------------------------------- /core/src/zemin/notification/NotificationLocal.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 Zemin Liu 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package zemin.notification; 18 | 19 | import android.content.Context; 20 | import android.os.Looper; 21 | import android.util.Log; 22 | import android.view.View; 23 | 24 | import java.util.ArrayList; 25 | 26 | /** 27 | * In-layout notification view. 28 | */ 29 | public class NotificationLocal extends NotificationHandler { 30 | 31 | public static final String SIMPLE_NAME = "Local"; 32 | public static boolean DBG; 33 | 34 | /** 35 | * Implementaiton of {@link NotificationViewCallback} for in-layout {@link NotificationView}. 36 | */ 37 | public static class ViewCallback extends NotificationViewCallback { 38 | 39 | @Override 40 | public int getContentViewDefaultLayoutId(NotificationView view) { 41 | return R.layout.notification_simple_2; 42 | } 43 | 44 | @Override 45 | public void onViewSetup(NotificationView view) { 46 | // nothing. 47 | } 48 | } 49 | 50 | private NotificationView mView; 51 | 52 | /* package */ NotificationLocal(Context context, Looper looper) { 53 | super(context, NotificationDelegater.LOCAL, looper); 54 | } 55 | 56 | /** 57 | * Set notification view. 58 | * 59 | * @param view 60 | */ 61 | public void setView(NotificationView view) { 62 | view.initialize(this); 63 | mView = view; 64 | } 65 | 66 | /** 67 | * Set callback for notification view. 68 | * 69 | * @param cb 70 | */ 71 | public void setViewCallback(NotificationViewCallback cb) { 72 | if (mView != null) { 73 | mView.setCallback(cb); 74 | } 75 | } 76 | 77 | /** 78 | * Enable/disable notification view. 79 | * 80 | * @param enable 81 | */ 82 | public void setViewEnabled(boolean enable) { 83 | if (mView != null) { 84 | mView.setViewEnabled(enable); 85 | } 86 | } 87 | 88 | /** 89 | * Get notification view. 90 | * 91 | * @param NotificationView 92 | */ 93 | public NotificationView getView() { 94 | return mView; 95 | } 96 | 97 | /** 98 | * Dismiss notification view. 99 | */ 100 | public void dismissView() { 101 | if (mView != null) { 102 | mView.dismiss(); 103 | } 104 | } 105 | 106 | @Override 107 | protected void onCancel(NotificationEntry entry) { 108 | if (mView != null) { 109 | mView.onCancel(entry); 110 | } else { 111 | onCancelFinished(entry); 112 | } 113 | } 114 | 115 | @Override 116 | protected void onCancelAll() { 117 | if (mView != null) { 118 | mView.onCancelAll(); 119 | } else { 120 | onCancelAllFinished(); 121 | } 122 | } 123 | 124 | @Override 125 | protected void onArrival(NotificationEntry entry) { 126 | if (mView == null) { 127 | Log.w(TAG, "NotificationView not found."); 128 | onSendIgnored(entry); 129 | return; 130 | } 131 | 132 | if (!mView.hasCallback()) { 133 | if (DBG) Log.v(TAG, "set default NotificationViewCallback."); 134 | mView.setCallback(new ViewCallback()); 135 | } 136 | 137 | if (!mView.isViewEnabled()) { 138 | if (DBG) Log.v(TAG, "NotificationView is currently disabled."); 139 | onSendIgnored(entry); 140 | return; 141 | } 142 | 143 | mView.onArrival(entry); 144 | } 145 | 146 | 147 | @Override 148 | protected void onUpdate(NotificationEntry entry) { 149 | if (mView == null) { 150 | Log.w(TAG, "NotificationView not found."); 151 | onUpdateIgnored(entry); 152 | return; 153 | } 154 | 155 | if (!mView.isViewEnabled()) { 156 | if (DBG) Log.v(TAG, "NotificationView is currently disabled."); 157 | onUpdateIgnored(entry); 158 | return; 159 | } 160 | 161 | mView.onUpdate(entry); 162 | } 163 | 164 | @Override public String toSimpleString() { return SIMPLE_NAME; } 165 | @Override public String toString() { return SIMPLE_NAME; } 166 | } 167 | -------------------------------------------------------------------------------- /core/res/layout/notification_board_row.xml: -------------------------------------------------------------------------------- 1 | 2 | 19 | 20 | 25 | 26 | 36 | 42 | 50 | 58 | 59 | 60 | 67 | 68 | 78 | 79 | 85 | 86 | 90 | 91 |