├── whatisnewdialog-sample
├── .gitignore
├── src
│ └── main
│ │ ├── res
│ │ ├── values
│ │ │ ├── strings.xml
│ │ │ ├── colors.xml
│ │ │ └── styles.xml
│ │ ├── drawable
│ │ │ ├── giphy.gif
│ │ │ ├── giphy2.gif
│ │ │ └── androidpicture.png
│ │ ├── mipmap-hdpi
│ │ │ ├── ic_launcher.png
│ │ │ └── ic_launcher_round.png
│ │ ├── mipmap-mdpi
│ │ │ ├── ic_launcher.png
│ │ │ └── ic_launcher_round.png
│ │ ├── mipmap-xhdpi
│ │ │ ├── ic_launcher.png
│ │ │ └── ic_launcher_round.png
│ │ ├── mipmap-xxhdpi
│ │ │ ├── ic_launcher.png
│ │ │ └── ic_launcher_round.png
│ │ ├── mipmap-xxxhdpi
│ │ │ ├── ic_launcher.png
│ │ │ └── ic_launcher_round.png
│ │ └── layout
│ │ │ └── activity_main.xml
│ │ ├── AndroidManifest.xml
│ │ └── java
│ │ └── com
│ │ └── nonzeroapps
│ │ └── whatisnewdialog
│ │ └── sample
│ │ └── MainActivity.java
├── .project
├── build.gradle
└── proguard-rules.pro
├── settings.gradle
├── preview
├── usage.gif
├── nonzeroapps.png
└── darkModeExample.png
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── whatisnewdialog
├── src
│ ├── main
│ │ ├── AndroidManifest.xml
│ │ ├── res
│ │ │ ├── values
│ │ │ │ ├── colors.xml
│ │ │ │ ├── strings.xml
│ │ │ │ └── attrs.xml
│ │ │ ├── values-tr
│ │ │ │ └── strings.xml
│ │ │ └── layout
│ │ │ │ ├── newfeaturedialog.xml
│ │ │ │ └── item_view_pager_image.xml
│ │ └── java
│ │ │ └── com
│ │ │ └── nonzeroapps
│ │ │ └── whatisnewdialog
│ │ │ ├── util
│ │ │ ├── Util.java
│ │ │ └── SharedPrefHelper.java
│ │ │ ├── adapter
│ │ │ ├── ViewPagerAdapter.java
│ │ │ └── ImageViewPagerAdapter.java
│ │ │ ├── object
│ │ │ ├── NewFeatureItem.java
│ │ │ └── DialogSettings.java
│ │ │ ├── NewItemDialog.java
│ │ │ ├── fragment
│ │ │ └── WhatIsNewDialogFragment.java
│ │ │ └── view
│ │ │ └── InkPageIndicator.java
│ └── test
│ │ └── java
│ │ └── com
│ │ └── nonzeroapps
│ │ └── whatisnewdialog
│ │ └── ExampleUnitTest.java
├── gradle.properties
├── .project
├── .gitignore
├── proguard-rules.pro
└── build.gradle
├── .travis.yml
├── .gitignore
├── gradle.properties
├── gradlew.bat
├── gradlew
├── README.md
└── LICENSE
/whatisnewdialog-sample/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':whatisnewdialog-sample', ':whatisnewdialog'
2 |
--------------------------------------------------------------------------------
/preview/usage.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nonzeroapps/whatisnewdialog/HEAD/preview/usage.gif
--------------------------------------------------------------------------------
/preview/nonzeroapps.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nonzeroapps/whatisnewdialog/HEAD/preview/nonzeroapps.png
--------------------------------------------------------------------------------
/preview/darkModeExample.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nonzeroapps/whatisnewdialog/HEAD/preview/darkModeExample.png
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nonzeroapps/whatisnewdialog/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/whatisnewdialog/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/whatisnewdialog-sample/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | WhatIsNew
3 |
4 |
--------------------------------------------------------------------------------
/whatisnewdialog-sample/src/main/res/drawable/giphy.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nonzeroapps/whatisnewdialog/HEAD/whatisnewdialog-sample/src/main/res/drawable/giphy.gif
--------------------------------------------------------------------------------
/whatisnewdialog-sample/src/main/res/drawable/giphy2.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nonzeroapps/whatisnewdialog/HEAD/whatisnewdialog-sample/src/main/res/drawable/giphy2.gif
--------------------------------------------------------------------------------
/whatisnewdialog-sample/src/main/res/drawable/androidpicture.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nonzeroapps/whatisnewdialog/HEAD/whatisnewdialog-sample/src/main/res/drawable/androidpicture.png
--------------------------------------------------------------------------------
/whatisnewdialog-sample/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nonzeroapps/whatisnewdialog/HEAD/whatisnewdialog-sample/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/whatisnewdialog-sample/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nonzeroapps/whatisnewdialog/HEAD/whatisnewdialog-sample/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/whatisnewdialog-sample/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nonzeroapps/whatisnewdialog/HEAD/whatisnewdialog-sample/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/whatisnewdialog-sample/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nonzeroapps/whatisnewdialog/HEAD/whatisnewdialog-sample/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/whatisnewdialog-sample/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nonzeroapps/whatisnewdialog/HEAD/whatisnewdialog-sample/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/whatisnewdialog-sample/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nonzeroapps/whatisnewdialog/HEAD/whatisnewdialog-sample/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/whatisnewdialog-sample/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nonzeroapps/whatisnewdialog/HEAD/whatisnewdialog-sample/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/whatisnewdialog-sample/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nonzeroapps/whatisnewdialog/HEAD/whatisnewdialog-sample/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/whatisnewdialog-sample/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nonzeroapps/whatisnewdialog/HEAD/whatisnewdialog-sample/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/whatisnewdialog-sample/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nonzeroapps/whatisnewdialog/HEAD/whatisnewdialog-sample/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/whatisnewdialog/gradle.properties:
--------------------------------------------------------------------------------
1 | POM_NAME=What Is New Dialog
2 | POM_ARTIFACT_ID=whatisnewdialog
3 | POM_DESCRIPTION=An Android library for displaying a dialog where it presents new features in the app.
4 | POM_PACKAGING=aar
--------------------------------------------------------------------------------
/whatisnewdialog/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
--------------------------------------------------------------------------------
/whatisnewdialog-sample/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Sun Mar 22 14:18:31 EET 2020
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-6.2.2-all.zip
7 |
--------------------------------------------------------------------------------
/whatisnewdialog/src/main/res/values-tr/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | Bu Sürümdeki Yenilikler
4 | Daha Sonra Hatırlat
5 | Tamam
6 | Kapat
7 |
--------------------------------------------------------------------------------
/whatisnewdialog/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | 1.0.0
3 | What Is New In This Version!
4 | OK
5 | Close
6 | Remind Me Later
7 |
--------------------------------------------------------------------------------
/whatisnewdialog-sample/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/whatisnewdialog-sample/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/whatisnewdialog/src/main/res/values/attrs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/whatisnewdialog/src/test/java/com/nonzeroapps/whatisnewdialog/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.nonzeroapps.whatisnewdialog;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() throws Exception {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: android
2 | jdk: oraclejdk8
3 |
4 | android:
5 | components:
6 | - tools
7 | - platform-tools
8 | - build-tools-26.0.2
9 | - android-26
10 | - extra-google-google_play_services
11 | - extra-android-m2repository
12 | - extra-android-support
13 | - extra-google-m2repository
14 | - sys-img-armeabi-v7a-android-25
15 | - sys-img-armeabi-v7a-android-24
16 |
17 | before_install:
18 | - chmod +x gradlew
19 |
20 | script:
21 | - ./gradlew clean connectedCheck
22 |
23 | after_success:
24 | - .buildscript/deploy_snapshot.sh
25 |
26 | notifications:
27 | email: false
28 |
29 |
--------------------------------------------------------------------------------
/whatisnewdialog/src/main/java/com/nonzeroapps/whatisnewdialog/util/Util.java:
--------------------------------------------------------------------------------
1 | package com.nonzeroapps.whatisnewdialog.util;
2 |
3 | import android.graphics.Color;
4 | import androidx.annotation.ColorInt;
5 |
6 | /**
7 | * Created by berkayturanci on 04/08/2017.
8 | */
9 |
10 | public class Util {
11 |
12 | @ColorInt
13 | public static int getContrastColor(@ColorInt int color) {
14 | // Counting the perceptive luminance - human eye favors green color...
15 | double a = 1 - (0.299 * Color.red(color) + 0.587 * Color.green(color) + 0.114 * Color.blue(color)) / 255;
16 | return a < 0.5 ? Color.BLACK : Color.WHITE;
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/whatisnewdialog-sample/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | sample
4 | Project sample created by Buildship.
5 |
6 |
7 |
8 |
9 | org.eclipse.jdt.core.javabuilder
10 |
11 |
12 |
13 |
14 | org.eclipse.buildship.core.gradleprojectbuilder
15 |
16 |
17 |
18 |
19 |
20 | org.eclipse.jdt.core.javanature
21 | org.eclipse.buildship.core.gradleprojectnature
22 |
23 |
24 |
--------------------------------------------------------------------------------
/whatisnewdialog/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | whatisnewdialoglibrary
4 | Project whatisnewdialoglibrary created by Buildship.
5 |
6 |
7 |
8 |
9 | org.eclipse.jdt.core.javabuilder
10 |
11 |
12 |
13 |
14 | org.eclipse.buildship.core.gradleprojectbuilder
15 |
16 |
17 |
18 |
19 |
20 | org.eclipse.jdt.core.javanature
21 | org.eclipse.buildship.core.gradleprojectnature
22 |
23 |
24 |
--------------------------------------------------------------------------------
/whatisnewdialog-sample/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 29
5 | defaultConfig {
6 | applicationId "com.nonzeroapps.whatisnewdialog.sample"
7 | minSdkVersion 16
8 | targetSdkVersion 29
9 | versionCode 1
10 | versionName "1.0"
11 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
12 | }
13 | buildTypes {
14 | release {
15 | minifyEnabled false
16 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
17 | }
18 | }
19 | productFlavors {
20 | }
21 | }
22 |
23 | dependencies {
24 | implementation fileTree(include: ['*.jar'], dir: 'libs')
25 | implementation 'androidx.appcompat:appcompat:1.0.2'
26 | implementation project(':whatisnewdialog')
27 | }
28 |
--------------------------------------------------------------------------------
/whatisnewdialog/src/main/java/com/nonzeroapps/whatisnewdialog/adapter/ViewPagerAdapter.java:
--------------------------------------------------------------------------------
1 | package com.nonzeroapps.whatisnewdialog.adapter;
2 |
3 | import android.view.View;
4 | import android.view.ViewGroup;
5 |
6 | import androidx.viewpager.widget.PagerAdapter;
7 |
8 | /**
9 | * Created by berkayturanci on 01/08/2017.
10 | */
11 |
12 | abstract class ViewPagerAdapter extends PagerAdapter {
13 |
14 | public abstract View getItem(int position);
15 |
16 | @Override
17 | public Object instantiateItem(ViewGroup container, final int position) {
18 |
19 | View mItemView = getItem(position);
20 | container.addView(mItemView);
21 | return mItemView;
22 | }
23 |
24 | @Override
25 | public boolean isViewFromObject(View view, Object object) {
26 | return view == object;
27 | }
28 |
29 | @Override
30 | public void destroyItem(ViewGroup container, int position, Object object) {
31 | container.removeView((View) object);
32 | }
33 | }
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Built application files
2 | *.apk
3 | *.ap_
4 |
5 | # Files for the ART/Dalvik VM
6 | *.dex
7 |
8 | # Java class files
9 | *.class
10 |
11 | # Generated files
12 | bin/
13 | gen/
14 | out/
15 |
16 | # Gradle files
17 | .gradle/
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 |
29 | # Android Studio Navigation editor temp files
30 | .navigation/
31 |
32 | # Android Studio captures folder
33 | captures/
34 |
35 | # Intellij
36 | *.iml
37 | .idea/workspace.xml
38 | .idea/tasks.xml
39 | .idea/gradle.xml
40 | .idea/dictionaries
41 | .idea/libraries
42 |
43 | # Keystore files
44 | *.jks
45 |
46 | # External native build folder generated in Android Studio 2.2 and later
47 | .externalNativeBuild
48 |
49 | # Google Services (e.g. APIs or Firebase)
50 | google-services.json
51 |
52 | # Freeline
53 | freeline.py
54 | freeline/
55 | freeline_project_description.json
56 |
--------------------------------------------------------------------------------
/whatisnewdialog/.gitignore:
--------------------------------------------------------------------------------
1 | # Built application files
2 | *.apk
3 | *.ap_
4 |
5 | # Files for the ART/Dalvik VM
6 | *.dex
7 |
8 | # Java class files
9 | *.class
10 |
11 | # Generated files
12 | bin/
13 | gen/
14 | out/
15 |
16 | # Gradle files
17 | .gradle/
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 |
29 | # Android Studio Navigation editor temp files
30 | .navigation/
31 |
32 | # Android Studio captures folder
33 | captures/
34 |
35 | # Intellij
36 | *.iml
37 | .idea/workspace.xml
38 | .idea/tasks.xml
39 | .idea/gradle.xml
40 | .idea/dictionaries
41 | .idea/libraries
42 |
43 | # Keystore files
44 | *.jks
45 |
46 | # External native build folder generated in Android Studio 2.2 and later
47 | .externalNativeBuild
48 |
49 | # Google Services (e.g. APIs or Firebase)
50 | google-services.json
51 |
52 | # Freeline
53 | freeline.py
54 | freeline/
55 | freeline_project_description.json
--------------------------------------------------------------------------------
/whatisnewdialog-sample/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/whatisnewdialog-sample/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/berkayturanci/Library/Android/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 listener
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.listener.for.webview {
16 | # public *;
17 | #}
18 |
19 | # Uncomment this to preserve the line number information for
20 | # debugging stack traces.
21 | #-keepattributes SourceFile,LineNumberTable
22 |
23 | # If you keep the line number information, uncomment this to
24 | # hide the original source file name.
25 | #-renamesourcefileattribute SourceFile
26 |
--------------------------------------------------------------------------------
/whatisnewdialog/src/main/res/layout/newfeaturedialog.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
19 |
20 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/whatisnewdialog/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/berkayturanci/Library/Android/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 listener
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.listener.for.webview {
16 | # public *;
17 | #}
18 |
19 | # Uncomment this to preserve the line number information for
20 | # debugging stack traces.
21 | #-keepattributes SourceFile,LineNumberTable
22 |
23 | # If you keep the line number information, uncomment this to
24 | # hide the original source file name.
25 | #-renamesourcefileattribute SourceFile
26 |
27 | # Glide Proguard Config
28 | -keep public class * implements com.bumptech.glide.module.GlideModule
29 | -keep public class * extends com.bumptech.glide.AppGlideModule
30 | -keep public enum com.bumptech.glide.load.resource.bitmap.ImageHeaderParser$** {
31 | **[] $VALUES;
32 | public *;
33 | }
34 |
35 | # for DexGuard only
36 | -keepresourcexmlelements manifest/application/meta-data@value=GlideModule
--------------------------------------------------------------------------------
/whatisnewdialog/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 | apply plugin: 'com.github.dcendents.android-maven'
3 |
4 | group='com.nonzeroapps.whatisnewdialog'
5 |
6 | android {
7 | compileSdkVersion 29
8 | defaultConfig {
9 | minSdkVersion 16
10 | targetSdkVersion 29
11 | versionCode 7
12 | versionName "1.0.7"
13 |
14 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
15 |
16 | }
17 | buildTypes {
18 | release {
19 | minifyEnabled false
20 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
21 | }
22 | }
23 | productFlavors {
24 | }
25 | }
26 |
27 | dependencies {
28 | implementation fileTree(include: ['*.jar'], dir: 'libs')
29 | androidTestImplementation('androidx.test.espresso:espresso-core:3.1.0', {
30 | exclude group: 'com.android.support', module: 'support-annotations'
31 | })
32 | testImplementation 'junit:junit:4.12'
33 |
34 | implementation 'androidx.appcompat:appcompat:1.1.0'
35 | implementation 'com.google.android.material:material:1.1.0'
36 | implementation 'com.github.bumptech.glide:glide:4.11.0'
37 | annotationProcessor 'com.github.bumptech.glide:compiler:4.11.0'
38 | implementation 'androidx.palette:palette:1.0.0'
39 | implementation 'com.xgc1986.android:parallaxpagertransformer:1.0.4'
40 | }
41 |
42 | apply from: 'https://raw.github.com/chrisbanes/gradle-mvn-push/master/gradle-mvn-push.gradle'
--------------------------------------------------------------------------------
/whatisnewdialog/src/main/java/com/nonzeroapps/whatisnewdialog/util/SharedPrefHelper.java:
--------------------------------------------------------------------------------
1 | package com.nonzeroapps.whatisnewdialog.util;
2 |
3 | import android.content.Context;
4 | import android.content.SharedPreferences;
5 |
6 | /**
7 | * Created by berkayturanci on 03/08/2017.
8 | */
9 |
10 | final public class SharedPrefHelper {
11 | private static final String SHARED_PREF_FILE_NAME = "what_is_new_dialog_pref_file";
12 |
13 | private static SharedPreferences getPreferences(Context context) {
14 | return context.getSharedPreferences(SHARED_PREF_FILE_NAME, Context.MODE_PRIVATE);
15 | }
16 |
17 | private static SharedPreferences.Editor getPreferencesEditor(Context context) {
18 | return getPreferences(context).edit();
19 | }
20 |
21 | /**
22 | * Clear data in shared preferences.
23 | *
24 | * @param context context
25 | */
26 | public static void clearSharedPreferences(Context context) {
27 | SharedPreferences.Editor editor = getPreferencesEditor(context);
28 | editor.clear();
29 | editor.apply();
30 | }
31 |
32 | public static void setSeenBefore(Context context, String versionName, boolean isSeenBefore) {
33 | SharedPreferences.Editor editor = getPreferencesEditor(context);
34 | editor.putBoolean(versionName, isSeenBefore);
35 | editor.apply();
36 | }
37 |
38 | public static boolean isSeenBefore(Context context, String versionName) {
39 | return getPreferences(context).getBoolean(versionName, false);
40 | }
41 |
42 | }
43 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | org.gradle.jvmargs=-Xmx1536m
13 |
14 | # When configured, Gradle will run in incubating parallel mode.
15 | # This option should only be used with decoupled projects. More details, visit
16 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
17 | # org.gradle.parallel=true
18 |
19 | GROUP=com.nonzeroapps.whatisnewdialog
20 | VERSION_NAME=1.0.3
21 | VERSION_CODE=4
22 |
23 | POM_DESCRIPTION=An Android library for displaying a dialog where it presents new features in the app.
24 |
25 | POM_URL=https://github.com/nonzeroapps/whatisnewdialog
26 | POM_SCM_URL=https://github.com/nonzeroapps/whatisnewdialog
27 | POM_SCM_CONNECTION=scm:git:git://github.com/nonzeroapps/whatisnewdialog.git
28 | POM_SCM_DEV_CONNECTION=scm:git:ssh://git@github.com:nonzeroapps/whatisnewdialog.git
29 | POM_ISSUE_URL=https://github.com/nonzeroapps/whatisnewdialog/issues
30 |
31 | POM_LICENCE_NAME=The Apache Software License, Version 2.0
32 | POM_LICENCE_URL=http://www.apache.org/licenses/LICENSE-2.0.txt
33 | POM_ALL_LICENCES=['Apache-2.0']
34 | POM_LICENCE_DIST=repo
35 |
36 | POM_DEVELOPER_ID=berkayturanci
37 | POM_DEVELOPER_NAME=Berkay Turancı
38 | android.useAndroidX=true
39 | android.enableJetifier=true
--------------------------------------------------------------------------------
/whatisnewdialog/src/main/java/com/nonzeroapps/whatisnewdialog/object/NewFeatureItem.java:
--------------------------------------------------------------------------------
1 | package com.nonzeroapps.whatisnewdialog.object;
2 |
3 | import android.os.Parcel;
4 | import android.os.Parcelable;
5 | import androidx.annotation.DrawableRes;
6 |
7 | /**
8 | * Created by berkayturanci on 01/08/2017.
9 | */
10 |
11 | public class NewFeatureItem implements Parcelable {
12 |
13 | private String featureTitle;
14 | private String featureDesc;
15 | private String imageResource;
16 | private int imageDrawableResource;
17 |
18 | public String getFeatureTitle() {
19 | return featureTitle;
20 | }
21 |
22 | public void setFeatureTitle(String featureTitle) {
23 | this.featureTitle = featureTitle;
24 | }
25 |
26 | public String getFeatureDesc() {
27 | return featureDesc;
28 | }
29 |
30 | public void setFeatureDesc(String featureDesc) {
31 | this.featureDesc = featureDesc;
32 | }
33 |
34 | public String getImageResource() {
35 | return imageResource;
36 | }
37 |
38 | public void setImageResource(String imageResource) {
39 | this.imageResource = imageResource;
40 | }
41 |
42 | public void setImageResource(@DrawableRes int imageResource) {
43 | imageDrawableResource = imageResource;
44 | }
45 |
46 | public int getImageDrawableResource() {
47 | return imageDrawableResource;
48 | }
49 |
50 |
51 | @Override
52 | public int describeContents() {
53 | return 0;
54 | }
55 |
56 | @Override
57 | public void writeToParcel(Parcel dest, int flags) {
58 | dest.writeString(this.featureTitle);
59 | dest.writeString(this.featureDesc);
60 | dest.writeString(this.imageResource);
61 | dest.writeInt(this.imageDrawableResource);
62 | }
63 |
64 | public NewFeatureItem() {
65 | }
66 |
67 | protected NewFeatureItem(Parcel in) {
68 | this.featureTitle = in.readString();
69 | this.featureDesc = in.readString();
70 | this.imageResource = in.readString();
71 | this.imageDrawableResource = in.readInt();
72 | }
73 |
74 | public static final Parcelable.Creator CREATOR = new Parcelable.Creator() {
75 | @Override
76 | public NewFeatureItem createFromParcel(Parcel source) {
77 | return new NewFeatureItem(source);
78 | }
79 |
80 | @Override
81 | public NewFeatureItem[] newArray(int size) {
82 | return new NewFeatureItem[size];
83 | }
84 | };
85 | }
86 |
--------------------------------------------------------------------------------
/whatisnewdialog/src/main/res/layout/item_view_pager_image.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
14 |
15 |
21 |
22 |
27 |
28 |
32 |
33 |
34 |
35 |
36 |
37 |
43 |
44 |
48 |
49 |
58 |
59 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
--------------------------------------------------------------------------------
/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
--------------------------------------------------------------------------------
/whatisnewdialog-sample/src/main/java/com/nonzeroapps/whatisnewdialog/sample/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.nonzeroapps.whatisnewdialog.sample;
2 |
3 | import android.content.DialogInterface;
4 | import android.os.Bundle;
5 | import android.widget.Toast;
6 |
7 | import androidx.appcompat.app.AppCompatActivity;
8 |
9 | import com.nonzeroapps.android.whatisnewdialog.sample.R;
10 | import com.nonzeroapps.whatisnewdialog.NewItemDialog;
11 | import com.nonzeroapps.whatisnewdialog.object.NewFeatureItem;
12 |
13 | import java.util.ArrayList;
14 |
15 | public class MainActivity extends AppCompatActivity {
16 |
17 | @Override
18 | protected void onCreate(Bundle savedInstanceState) {
19 | super.onCreate(savedInstanceState);
20 | setContentView(R.layout.activity_main);
21 |
22 | // Create and show the dialog.
23 |
24 | ArrayList arrayList = new ArrayList<>();
25 |
26 | NewFeatureItem newFeatureItem = new NewFeatureItem();
27 | newFeatureItem.setFeatureDesc("From now on, you can search all things with keys. For searching please go to ");
28 | newFeatureItem.setFeatureTitle("Searching");
29 | newFeatureItem.setImageResource(R.drawable.androidpicture);
30 | arrayList.add(newFeatureItem);
31 |
32 | NewFeatureItem newFeatureItem2 = new NewFeatureItem();
33 | newFeatureItem2.setFeatureTitle("Feature 2");
34 | newFeatureItem2.setFeatureDesc("You waited long for this feature, we know that!!!\n\n From now on, you can follow your friend with our application. This makes our application super and cool. Don't believe my words, try and see it. If you want another features like this please contact with us via e-mail or feedback button.");
35 | newFeatureItem2.setImageResource("https://f1gr.hjfile.cn/pic/20170906/201709060335318628.gif");
36 | arrayList.add(newFeatureItem2);
37 |
38 | NewItemDialog
39 | .init(this)
40 | .setVersionName("1.2.0")
41 | .setDialogTitle("New Features of 1.2.0 Version!")
42 | .setPositiveButtonTitle("Close")
43 | .setNeutralButtonTitle("Show Me Later")
44 | .setUsePaletteForDescBackground(false)
45 | .setUsePaletteForImageBackground(false)
46 | .setCancelable(false)
47 | .setItems(arrayList)
48 | .setCancelButtonListener(new DialogInterface.OnClickListener() {
49 | @Override
50 | public void onClick(DialogInterface dialog, int which) {
51 | Toast.makeText(MainActivity.this, "Close Clicked", Toast.LENGTH_LONG).show();
52 | }
53 | })
54 | .setShowLaterButtonListener(new DialogInterface.OnClickListener() {
55 | @Override
56 | public void onClick(DialogInterface dialog, int which) {
57 | Toast.makeText(MainActivity.this, "Remind Me Later Clicked", Toast.LENGTH_LONG).show();
58 | }
59 | })
60 | .showDialogIfConditionsSuitable(this);
61 |
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/whatisnewdialog/src/main/java/com/nonzeroapps/whatisnewdialog/NewItemDialog.java:
--------------------------------------------------------------------------------
1 | package com.nonzeroapps.whatisnewdialog;
2 |
3 | import android.content.Context;
4 | import android.content.DialogInterface;
5 |
6 | import androidx.annotation.NonNull;
7 | import androidx.fragment.app.FragmentTransaction;
8 | import androidx.appcompat.app.AppCompatActivity;
9 |
10 | import com.nonzeroapps.whatisnewdialog.fragment.WhatIsNewDialogFragment;
11 | import com.nonzeroapps.whatisnewdialog.object.DialogSettings;
12 | import com.nonzeroapps.whatisnewdialog.object.NewFeatureItem;
13 | import com.nonzeroapps.whatisnewdialog.util.SharedPrefHelper;
14 |
15 | import java.util.ArrayList;
16 |
17 | /**
18 | * Created by berkayturanci on 01/08/2017.
19 | */
20 |
21 | public final class NewItemDialog {
22 |
23 | private static final String DIALOG_TAG = "whatIsNewDialogFragment";
24 |
25 | private static volatile NewItemDialog mNewItemDialog;
26 |
27 | private ArrayList mNewFeatureItemArrayList;
28 | private DialogSettings mDialogSettings;
29 | private DialogInterface.OnClickListener mPositiveButtonListener;
30 | private DialogInterface.OnClickListener mNegativeButtonListener;
31 | private Context mContext;
32 |
33 | public static NewItemDialog init(@NonNull Context context) {
34 | if (mNewItemDialog == null) {
35 | synchronized (NewItemDialog.class) {
36 | if (mNewItemDialog == null) {
37 | mNewItemDialog = new NewItemDialog(context);
38 | }
39 | }
40 | }
41 |
42 | return mNewItemDialog;
43 | }
44 |
45 | private NewItemDialog(@NonNull Context context) {
46 | mContext = context;
47 | mDialogSettings = new DialogSettings();
48 | }
49 |
50 | public NewItemDialog setDialogTitle(String dialogTitle) {
51 | mDialogSettings.setTitleText(dialogTitle);
52 | return this;
53 | }
54 |
55 | public NewItemDialog setPositiveButtonTitle(String positiveButtonTitle) {
56 | mDialogSettings.setPositiveText(positiveButtonTitle);
57 | return this;
58 | }
59 |
60 | /**
61 | * It is used for
62 | * @param usePaletteForDescBackground
63 | * @return
64 | */
65 | public NewItemDialog setUsePaletteForDescBackground(boolean usePaletteForDescBackground) {
66 | mDialogSettings.setUsePaletteForDescBackground(usePaletteForDescBackground);
67 | return this;
68 | }
69 |
70 | public NewItemDialog setUsePaletteForImageBackground(boolean usePaletteForImageBackground) {
71 | mDialogSettings.setUsePaletteForImageBackground(usePaletteForImageBackground);
72 | return this;
73 | }
74 |
75 | public NewItemDialog setNeutralButtonTitle(String neutralButtonTitle) {
76 | mDialogSettings.setNeutralText(neutralButtonTitle);
77 | return this;
78 | }
79 |
80 | public NewItemDialog setShowLaterButton(boolean isShowNeutralButton) {
81 | mDialogSettings.setShowNeutralButton(isShowNeutralButton);
82 | return this;
83 | }
84 |
85 | public NewItemDialog setCancelButton(boolean isShowCancelButton) {
86 | mDialogSettings.setShowPositiveButton(isShowCancelButton);
87 | return this;
88 | }
89 |
90 | public NewItemDialog setCancelable(boolean cancelable) {
91 | mDialogSettings.setCancelable(cancelable);
92 | return this;
93 | }
94 |
95 | public NewItemDialog setVersionName(String versionName) {
96 | mDialogSettings.setVersionName(versionName);
97 | return this;
98 | }
99 |
100 | public NewItemDialog setCancelButtonListener(DialogInterface.OnClickListener cancelButtonListener) {
101 | this.mPositiveButtonListener = cancelButtonListener;
102 | return this;
103 | }
104 |
105 | public NewItemDialog setShowLaterButtonListener(DialogInterface.OnClickListener showLaterButtonListener) {
106 | this.mNegativeButtonListener = showLaterButtonListener;
107 | return this;
108 | }
109 |
110 | public NewItemDialog setItems(ArrayList newFeatureItemArraylist) {
111 | mNewFeatureItemArrayList = newFeatureItemArraylist;
112 | return this;
113 | }
114 |
115 | public void clearSharedPref() {
116 | SharedPrefHelper.clearSharedPreferences(mContext);
117 | }
118 |
119 | public boolean isConditionsSuitable() {
120 | return !SharedPrefHelper.isSeenBefore(mContext, mDialogSettings.getVersionName(mContext));
121 | }
122 |
123 | public void showDialogIfConditionsSuitable(@NonNull AppCompatActivity activity) {
124 |
125 | if (activity.isFinishing()) {
126 | return;
127 | }
128 |
129 | if (isConditionsSuitable()) {
130 | showDialog(activity);
131 | }
132 | }
133 |
134 | public void showDialog(@NonNull AppCompatActivity activity) {
135 | try {
136 | if (activity.getSupportFragmentManager().findFragmentByTag(DIALOG_TAG) == null) {
137 | WhatIsNewDialogFragment newFragment = WhatIsNewDialogFragment.newInstance(mNewFeatureItemArrayList, mDialogSettings, mPositiveButtonListener, mNegativeButtonListener);
138 |
139 | FragmentTransaction transaction = activity.getSupportFragmentManager().beginTransaction();
140 | transaction.add(newFragment, DIALOG_TAG);
141 | transaction.commitAllowingStateLoss();
142 | }
143 | } catch (IllegalStateException ex) {
144 |
145 | }
146 | }
147 |
148 | }
149 |
--------------------------------------------------------------------------------
/whatisnewdialog/src/main/java/com/nonzeroapps/whatisnewdialog/fragment/WhatIsNewDialogFragment.java:
--------------------------------------------------------------------------------
1 | package com.nonzeroapps.whatisnewdialog.fragment;
2 |
3 |
4 | import android.app.Dialog;
5 | import android.content.Context;
6 | import android.content.DialogInterface;
7 | import android.os.Bundle;
8 | import android.view.View;
9 |
10 | import androidx.annotation.NonNull;
11 | import androidx.appcompat.app.AlertDialog;
12 | import androidx.fragment.app.DialogFragment;
13 | import androidx.viewpager.widget.ViewPager;
14 |
15 | import com.nonzeroapps.whatisnewdialog.R;
16 | import com.nonzeroapps.whatisnewdialog.adapter.ImageViewPagerAdapter;
17 | import com.nonzeroapps.whatisnewdialog.object.DialogSettings;
18 | import com.nonzeroapps.whatisnewdialog.object.NewFeatureItem;
19 | import com.nonzeroapps.whatisnewdialog.util.SharedPrefHelper;
20 | import com.nonzeroapps.whatisnewdialog.view.InkPageIndicator;
21 | import com.xgc1986.parallaxPagerTransformer.ParallaxPagerTransformer;
22 |
23 | import java.util.ArrayList;
24 |
25 |
26 | /**
27 | * Created by berkayturanci on 01/08/2017.
28 | */
29 |
30 | public class WhatIsNewDialogFragment extends DialogFragment {
31 |
32 | private static final String NEW_FEATURE_ITEM_LIST = "newFeatureItemList";
33 | private static final String DIALOG_SETTINGS = "dialogSettings";
34 |
35 | private ViewPager mImageViewPager;
36 | private InkPageIndicator mInkPageIndicator;
37 | private ArrayList mNewFeatureItemArrayList;
38 | private DialogInterface.OnClickListener mPositiveButtonListener;
39 | private DialogInterface.OnClickListener mNeutralButtonListener;
40 |
41 | public static WhatIsNewDialogFragment newInstance(ArrayList newFeatureItemArrayList, DialogSettings dialogSettings, DialogInterface.OnClickListener positiveButtonListener, DialogInterface.OnClickListener neutralButtonListener) {
42 | WhatIsNewDialogFragment whatIsNewDialogFragment = new WhatIsNewDialogFragment();
43 |
44 | whatIsNewDialogFragment.setPositiveButtonListener(positiveButtonListener);
45 | whatIsNewDialogFragment.setNeutralButtonListener(neutralButtonListener);
46 |
47 | Bundle args = new Bundle();
48 | args.putParcelableArrayList(NEW_FEATURE_ITEM_LIST, newFeatureItemArrayList);
49 | args.putParcelable(DIALOG_SETTINGS, dialogSettings);
50 | whatIsNewDialogFragment.setArguments(args);
51 |
52 | return whatIsNewDialogFragment;
53 | }
54 |
55 | @NonNull
56 | @Override
57 | public Dialog onCreateDialog(Bundle savedInstanceState) {
58 |
59 | final Context context = getContext();
60 |
61 | View view = getActivity().getLayoutInflater().inflate(R.layout.newfeaturedialog, null);
62 |
63 | mNewFeatureItemArrayList = getArguments().getParcelableArrayList(NEW_FEATURE_ITEM_LIST);
64 | final DialogSettings dialogSettings = getArguments().getParcelable(DIALOG_SETTINGS);
65 | mImageViewPager = (ViewPager) view.findViewById(R.id.viewPager);
66 | mInkPageIndicator = (InkPageIndicator) view.findViewById(R.id.indicator);
67 | mImageViewPager.setPageTransformer(false, new ParallaxPagerTransformer(R.id.imageView));
68 |
69 | initPage(dialogSettings);
70 |
71 | AlertDialog.Builder builder = new AlertDialog.Builder(context)
72 | .setView(view);
73 |
74 | if (dialogSettings != null) {
75 | if (dialogSettings.isShowTitle()) {
76 | builder.setTitle(dialogSettings.getTitleText(context));
77 | }
78 |
79 | if (dialogSettings.isShowPositiveButton()) {
80 | builder.setPositiveButton(dialogSettings.getPositiveText(context), new DialogInterface.OnClickListener() {
81 | @Override
82 | public void onClick(DialogInterface dialog, int which) {
83 | SharedPrefHelper.setSeenBefore(context, dialogSettings.getVersionName(context), true);
84 |
85 | if (mPositiveButtonListener != null) {
86 | mPositiveButtonListener.onClick(dialog, which);
87 | }
88 | }
89 | });
90 | }
91 |
92 | if (dialogSettings.isShowNeutralButton()) {
93 | builder.setNeutralButton(dialogSettings.getNeutralText(context), new DialogInterface.OnClickListener() {
94 | @Override
95 | public void onClick(DialogInterface dialog, int which) {
96 |
97 | if (mNeutralButtonListener != null) {
98 | mNeutralButtonListener.onClick(dialog, which);
99 | }
100 | }
101 | });
102 | }
103 |
104 | builder.setCancelable(dialogSettings.isCancelable());
105 | }
106 |
107 | return builder.create();
108 | }
109 |
110 | private void initPage(DialogSettings dialogSettings) {
111 | ImageViewPagerAdapter adapter = new ImageViewPagerAdapter(getContext(), mNewFeatureItemArrayList,
112 | dialogSettings.usePaletteForDescBackground(),
113 | dialogSettings.usePaletteForImageBackground());
114 |
115 | mImageViewPager.setAdapter(adapter);
116 | mInkPageIndicator.setViewPager(mImageViewPager);
117 | }
118 |
119 | public void setPositiveButtonListener(DialogInterface.OnClickListener positiveButtonListener) {
120 | mPositiveButtonListener = positiveButtonListener;
121 | }
122 |
123 | public void setNeutralButtonListener(DialogInterface.OnClickListener neutralButtonListener) {
124 | mNeutralButtonListener = neutralButtonListener;
125 | }
126 | }
127 |
--------------------------------------------------------------------------------
/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 | Please set the JAVA_HOME variable in your environment to match the
81 | location of your Java installation."
82 | fi
83 | else
84 | JAVACMD="java"
85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
86 | Please set the JAVA_HOME variable in your environment to match the
87 | location of your Java installation."
88 | fi
89 |
90 | # Increase the maximum file descriptors if we can.
91 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
92 | MAX_FD_LIMIT=`ulimit -H -n`
93 | if [ $? -eq 0 ] ; then
94 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
95 | MAX_FD="$MAX_FD_LIMIT"
96 | fi
97 | ulimit -n $MAX_FD
98 | if [ $? -ne 0 ] ; then
99 | warn "Could not set maximum file descriptor limit: $MAX_FD"
100 | fi
101 | else
102 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
103 | fi
104 | fi
105 |
106 | # For Darwin, add options to specify how the application appears in the dock
107 | if $darwin; then
108 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
109 | fi
110 |
111 | # For Cygwin, switch paths to Windows format before running java
112 | if $cygwin ; then
113 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
114 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
115 |
116 | # We build the pattern for arguments to be converted via cygpath
117 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
118 | SEP=""
119 | for dir in $ROOTDIRSRAW ; do
120 | ROOTDIRS="$ROOTDIRS$SEP$dir"
121 | SEP="|"
122 | done
123 | OURCYGPATTERN="(^($ROOTDIRS))"
124 | # Add a user-defined pattern to the cygpath arguments
125 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
126 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
127 | fi
128 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
129 | i=0
130 | for arg in "$@" ; do
131 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
132 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
133 |
134 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
135 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
136 | else
137 | eval `echo args$i`="\"$arg\""
138 | fi
139 | i=$((i+1))
140 | done
141 | case $i in
142 | (0) set -- ;;
143 | (1) set -- "$args0" ;;
144 | (2) set -- "$args0" "$args1" ;;
145 | (3) set -- "$args0" "$args1" "$args2" ;;
146 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
147 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
148 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
149 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
150 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
151 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
152 | esac
153 | fi
154 |
155 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
156 | function splitJvmOpts() {
157 | JVM_OPTS=("$@")
158 | }
159 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
160 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
161 |
162 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
163 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # WhatIsNewDialog
2 | [](https://opensource.org/licenses/Apache-2.0) [](https://android-arsenal.com/api?level=16) [](https://jitpack.io/#nonzeroapps/whatisnewdialog)
3 |
4 | What is new dialog for Android is used for presenting new features in the the app. It can be used in the activity starts, from menu or from a button. It is highly customizable and flexible. It has two options (customizable) where user can either select remind me later or close. Close selection will record that dialog for given version name is seen. So next time it won't be shown to the user. It uses Glide for showing gif and images.
5 |
6 | 
7 | 
8 |
9 | ## Installation
10 |
11 | ### Gradle
12 | You can download from jitpack.
13 |
14 | https://jitpack.io/#nonzeroapps/whatisnewdialog
15 |
16 | ## Features
17 | - Add unlimited pages for dialog
18 | - Callbacks for buttons
19 | - It records the dialog seen condition for future openings
20 | - Gif support.
21 | - Parallax effects on view pager
22 | - It can show network images, gifs or local resources (image or gif) from the project
23 | - Extracts the accent color from your app's theme
24 | - Customizable title, positive button and negative button texts
25 | - Customizable button and title colors (It uses the activity style)
26 | - Override dialog redirection to Google Play or Feedback form according to your needs
27 | - Low memory usage
28 | - Can be used For Night Mode too
29 |
30 | If you want the dialog to appear on the start of the app, just add the `showDialogIfConditionsSuitable(activity)` to the `onCreate()` method of your Activity class. The dialog will appear when the app is opened and the condition is satisfied.
31 |
32 | ## How to use
33 |
34 | Use the dialog as it is
35 |
36 | ```java
37 |
38 | NewItemDialog newItemDialog = NewItemDialog
39 | .init(this)
40 | .setVersionName("1.2.0")
41 | .setDialogTitle("New Features of 1.2.0 Version!")
42 | .setItems(arrayList);
43 |
44 |
45 | newItemDialog.showDialog(this);
46 |
47 | ```
48 |
49 | or for the large example
50 |
51 | ```java
52 |
53 | // Create and show the dialog.
54 |
55 | ArrayList arrayList = new ArrayList<>();
56 |
57 | NewFeatureItem newFeatureItem = new NewFeatureItem();
58 | newFeatureItem.setFeatureDesc("From now on, you can search all things with keys. For searching please go to ");
59 | newFeatureItem.setFeatureTitle("Searching");
60 | newFeatureItem.setImageResource(R.drawable.androidpicture);
61 | arrayList.add(newFeatureItem);
62 |
63 | NewFeatureItem newFeatureItem2 = new NewFeatureItem();
64 | newFeatureItem2.setFeatureTitle("Feature 2");
65 | newFeatureItem2.setFeatureDesc("You waited long for this feature, we know that!!!\n\n From now on, you can follow your friend with our application. This makes our application super and cool. Don't believe my words, try and see it. If you want another features like this please contact with us via e-mail or feedback button.");
66 | newFeatureItem2.setImageResource("https://media.giphy.com/media/JltOMwYmi0VrO/giphy.gif");
67 | arrayList.add(newFeatureItem2);
68 |
69 | NewItemDialog
70 | .init(this)
71 | .setVersionName("1.2.0")
72 | .setDialogTitle("New Features of 1.2.0 Version!")
73 | .setPositiveButtonTitle("Close")
74 | .setNeutralButtonTitle("Show Me Later")
75 | .setCancelable(false)
76 | .setItems(arrayList)
77 | .setUsePaletteForDescBackground(false) //This can be used for adjusting not using palette (Can be Used For Night Mode)
78 | .setUsePaletteForImageBackground(false) //This can be used for adjusting not using palette (Can be Used For Night Mode)
79 | .setCancelButtonListener(new DialogInterface.OnClickListener() {
80 | @Override
81 | public void onClick(DialogInterface dialog, int which) {
82 | Toast.makeText(MainActivity.this, "Close Clicked", Toast.LENGTH_LONG).show();
83 | }
84 | })
85 | .setShowLaterButtonListener(new DialogInterface.OnClickListener() {
86 | @Override
87 | public void onClick(DialogInterface dialog, int which) {
88 | Toast.makeText(MainActivity.this, "Remind Me Later Clicked", Toast.LENGTH_LONG).show();
89 | }
90 | })
91 | .showDialog(this);
92 |
93 | ```
94 |
95 | ### Note
96 | * Use `showDialogIfConditionsSuitable()` for showing dialog by checking the condition. Dialog will not shown if condition is not satisfied. In other words, user closes the dialog which has the same version name before.
97 | * Use `showDialog()` for force show of the dialog without checking the condition.
98 | * Use `isConditionsSuitable()` to check if dialog is shown or not.
99 | * Use `clearSharedPref()` to delete condition storages.
100 |
101 | ## Sample
102 | Have a look at the [sample](https://github.com/nonzeroapps/whatisnewdialog/tree/master/whatisnewdialog-sample).
103 |
104 | ## Support
105 | WhatIsNewDialog supports API level 16 and up.
106 |
107 | ## Contribute
108 |
109 | 1. Fork it
110 | 2. Create your own branch (git checkout -b new-feature-branch)
111 | 3. Commit your changes (git commit -am 'Some features added')
112 | 4. Push to the your own branch (git push origin new-feature-branch)
113 | 5. Create new Pull Request
114 |
115 | ## Credits
116 |
117 | This project was initiated by [**NonZeroApps**](https://nonzeroapps.com). You can contribute to this project by submitting issues or/and by forking this repo and sending a pull request.
118 |
119 | 
120 |
121 | Author: [Berkay Turancı](https://github.com/berkayturanci)
122 |
123 | # License
124 | ```
125 | Copyright (C) 2017 NonZeroApps
126 |
127 | Licensed under the Apache License, Version 2.0 (the "License");
128 | you may not use this file except in compliance with the License.
129 | You may obtain a copy of the License at
130 |
131 | http://www.apache.org/licenses/LICENSE-2.0
132 |
133 | Unless required by applicable law or agreed to in writing, software
134 | distributed under the License is distributed on an "AS IS" BASIS,
135 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
136 | See the License for the specific language governing permissions and
137 | limitations under the License.
138 | ```
139 |
--------------------------------------------------------------------------------
/whatisnewdialog/src/main/java/com/nonzeroapps/whatisnewdialog/object/DialogSettings.java:
--------------------------------------------------------------------------------
1 | package com.nonzeroapps.whatisnewdialog.object;
2 |
3 | import android.content.Context;
4 | import android.os.Parcel;
5 | import android.os.Parcelable;
6 |
7 | import androidx.annotation.NonNull;
8 |
9 | import com.nonzeroapps.whatisnewdialog.R;
10 |
11 |
12 | /**
13 | * Created by berkayturanci on 02/08/2017.
14 | */
15 |
16 | final public class DialogSettings implements Parcelable {
17 |
18 | private int versionNameId = R.string.version_name;
19 | private int titleResId = R.string.new_features_dialog_title;
20 | private int textPositiveResId = R.string.close;
21 | private int textNeutralResId = R.string.remind_me_later;
22 |
23 | private boolean usePaletteForDescBackground = true;
24 | private boolean usePaletteForImageBackground = true;
25 | private boolean showNeutralButton = true;
26 | private boolean showPositiveButton = true;
27 | private boolean showTitle = true;
28 | private boolean cancelable = true;
29 |
30 | private String versionName = null;
31 | private String titleText = null;
32 | private String positiveText = null;
33 | private String neutralText = null;
34 |
35 | public int getTitleResId() {
36 | return titleResId;
37 | }
38 |
39 | public void setTitleResId(int titleResId) {
40 | this.titleResId = titleResId;
41 | }
42 |
43 | public int getTextPositiveResId() {
44 | return textPositiveResId;
45 | }
46 |
47 | public void setTextPositiveResId(int textPositiveResId) {
48 | this.textPositiveResId = textPositiveResId;
49 | }
50 |
51 | public int getTextNeutralResId() {
52 | return textNeutralResId;
53 | }
54 |
55 | public void setTextNeutralResId(int textNeutralResId) {
56 | this.textNeutralResId = textNeutralResId;
57 | }
58 |
59 | public boolean usePaletteForDescBackground() {
60 | return usePaletteForDescBackground;
61 | }
62 |
63 | public void setUsePaletteForDescBackground(boolean usePaletteForDescBackground) {
64 | this.usePaletteForDescBackground = usePaletteForDescBackground;
65 | }
66 |
67 | public boolean usePaletteForImageBackground() {
68 | return usePaletteForImageBackground;
69 | }
70 |
71 | public void setUsePaletteForImageBackground(boolean usePaletteForImageBackground) {
72 | this.usePaletteForImageBackground = usePaletteForImageBackground;
73 | }
74 |
75 | public boolean isShowNeutralButton() {
76 | return showNeutralButton;
77 | }
78 |
79 | public void setShowNeutralButton(boolean showNeutralButton) {
80 | this.showNeutralButton = showNeutralButton;
81 | }
82 |
83 | public boolean isShowPositiveButton() {
84 | return showPositiveButton;
85 | }
86 |
87 | public void setShowPositiveButton(boolean showPositiveButton) {
88 | this.showPositiveButton = showPositiveButton;
89 | }
90 |
91 | public boolean isShowTitle() {
92 | return showTitle;
93 | }
94 |
95 | public void setShowTitle(boolean showTitle) {
96 | this.showTitle = showTitle;
97 | }
98 |
99 | public boolean isCancelable() {
100 | return cancelable;
101 | }
102 |
103 | public void setCancelable(boolean cancelable) {
104 | this.cancelable = cancelable;
105 | }
106 |
107 | public String getTitleText(@NonNull Context context) {
108 | if (titleText == null) {
109 | titleText = context.getString(titleResId);
110 | }
111 | return titleText;
112 | }
113 |
114 | public void setTitleText(String titleText) {
115 | this.titleText = titleText;
116 | }
117 |
118 | public String getPositiveText(@NonNull Context context) {
119 | if (positiveText == null) {
120 | positiveText = context.getString(textPositiveResId);
121 | }
122 | return positiveText;
123 | }
124 |
125 | public void setPositiveText(String positiveText) {
126 | this.positiveText = positiveText;
127 | }
128 |
129 | public String getNeutralText(@NonNull Context context) {
130 | if (neutralText == null) {
131 | neutralText = context.getString(textNeutralResId);
132 | }
133 | return neutralText;
134 | }
135 |
136 | public void setNeutralText(String neutralText) {
137 | this.neutralText = neutralText;
138 | }
139 |
140 | public String getVersionName(@NonNull Context context) {
141 | if (versionName == null) {
142 | versionName = context.getString(versionNameId);
143 | }
144 | return versionName;
145 | }
146 |
147 | public void setVersionName(String versionName) {
148 | this.versionName = versionName;
149 | }
150 |
151 | @Override
152 | public int describeContents() {
153 | return 0;
154 | }
155 |
156 | @Override
157 | public void writeToParcel(Parcel dest, int flags) {
158 | dest.writeString(this.versionName);
159 | dest.writeInt(this.titleResId);
160 | dest.writeInt(this.textPositiveResId);
161 | dest.writeInt(this.textNeutralResId);
162 | dest.writeByte(this.usePaletteForDescBackground ? (byte) 1 : (byte) 0);
163 | dest.writeByte(this.usePaletteForImageBackground ? (byte) 1 : (byte) 0);
164 | dest.writeByte(this.showNeutralButton ? (byte) 1 : (byte) 0);
165 | dest.writeByte(this.showPositiveButton ? (byte) 1 : (byte) 0);
166 | dest.writeByte(this.showTitle ? (byte) 1 : (byte) 0);
167 | dest.writeByte(this.cancelable ? (byte) 1 : (byte) 0);
168 | dest.writeString(this.titleText);
169 | dest.writeString(this.positiveText);
170 | dest.writeString(this.neutralText);
171 | }
172 |
173 | public DialogSettings() {
174 | }
175 |
176 | protected DialogSettings(Parcel in) {
177 | this.versionName = in.readString();
178 | this.titleResId = in.readInt();
179 | this.textPositiveResId = in.readInt();
180 | this.textNeutralResId = in.readInt();
181 | this.usePaletteForDescBackground = in.readByte() != 0;
182 | this.usePaletteForImageBackground = in.readByte() != 0;
183 | this.showNeutralButton = in.readByte() != 0;
184 | this.showPositiveButton = in.readByte() != 0;
185 | this.showTitle = in.readByte() != 0;
186 | this.cancelable = in.readByte() != 0;
187 | this.titleText = in.readString();
188 | this.positiveText = in.readString();
189 | this.neutralText = in.readString();
190 | }
191 |
192 | public static final Parcelable.Creator CREATOR = new Parcelable.Creator() {
193 | @Override
194 | public DialogSettings createFromParcel(Parcel source) {
195 | return new DialogSettings(source);
196 | }
197 |
198 | @Override
199 | public DialogSettings[] newArray(int size) {
200 | return new DialogSettings[size];
201 | }
202 | };
203 | }
204 |
--------------------------------------------------------------------------------
/whatisnewdialog/src/main/java/com/nonzeroapps/whatisnewdialog/adapter/ImageViewPagerAdapter.java:
--------------------------------------------------------------------------------
1 | package com.nonzeroapps.whatisnewdialog.adapter;
2 |
3 | import android.animation.ArgbEvaluator;
4 | import android.animation.ObjectAnimator;
5 | import android.content.Context;
6 | import android.graphics.Bitmap;
7 | import android.graphics.drawable.BitmapDrawable;
8 | import android.graphics.drawable.Drawable;
9 | import android.view.LayoutInflater;
10 | import android.view.View;
11 | import android.view.ViewTreeObserver;
12 | import android.widget.ImageView;
13 | import android.widget.LinearLayout;
14 | import android.widget.TextView;
15 |
16 | import androidx.annotation.Nullable;
17 | import androidx.palette.graphics.Palette;
18 |
19 | import com.bumptech.glide.Glide;
20 | import com.bumptech.glide.RequestBuilder;
21 | import com.bumptech.glide.RequestManager;
22 | import com.bumptech.glide.load.DataSource;
23 | import com.bumptech.glide.load.engine.DiskCacheStrategy;
24 | import com.bumptech.glide.load.engine.GlideException;
25 | import com.bumptech.glide.load.resource.gif.GifDrawable;
26 | import com.bumptech.glide.request.RequestListener;
27 | import com.bumptech.glide.request.RequestOptions;
28 | import com.bumptech.glide.request.target.Target;
29 | import com.nonzeroapps.whatisnewdialog.R;
30 | import com.nonzeroapps.whatisnewdialog.object.NewFeatureItem;
31 | import com.nonzeroapps.whatisnewdialog.util.Util;
32 |
33 | import java.util.ArrayList;
34 |
35 | /**
36 | * Created by berkayturanci on 01/08/2017.
37 | */
38 |
39 | public class ImageViewPagerAdapter extends ViewPagerAdapter {
40 |
41 | private Context mContext;
42 | private ArrayList mNewFeatureItems;
43 | private int finalHeight, finalWidth;
44 | private boolean mUsePaletteForDescBackground, mUsePaletteForImageBackground;
45 |
46 | public ImageViewPagerAdapter(Context context, ArrayList newFeatureItems,
47 | boolean usePaletteForDescBackground,
48 | boolean usePaletteForImageBackground) {
49 | mContext = context;
50 | mNewFeatureItems = newFeatureItems;
51 | mUsePaletteForDescBackground = usePaletteForDescBackground;
52 | mUsePaletteForImageBackground = usePaletteForImageBackground;
53 | }
54 |
55 | @Override
56 | public View getItem(final int position) {
57 |
58 | View view = LayoutInflater.from(mContext).inflate(R.layout.item_view_pager_image, null);
59 |
60 | final LinearLayout linearLayout = view.findViewById(R.id.linearLayout);
61 | final ImageView imageView = view.findViewById(R.id.imageView);
62 | final View progress = view.findViewById(R.id.progress);
63 | final TextView textViewDesc = view.findViewById(R.id.textViewDesc);
64 | final TextView textViewTitle = view.findViewById(R.id.textViewTitle);
65 |
66 | final NewFeatureItem newFeatureItem = mNewFeatureItems.get(position);
67 | textViewDesc.setText(newFeatureItem.getFeatureDesc());
68 | textViewTitle.setText(newFeatureItem.getFeatureTitle());
69 | imageView.setContentDescription(newFeatureItem.getFeatureTitle());
70 |
71 | progress.setVisibility(View.VISIBLE);
72 | ViewTreeObserver vto = imageView.getViewTreeObserver();
73 | vto.addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
74 | public boolean onPreDraw() {
75 | imageView.getViewTreeObserver().removeOnPreDrawListener(this);
76 | finalHeight = imageView.getMeasuredHeight();
77 | finalWidth = imageView.getMeasuredWidth();
78 |
79 | boolean isGif = newFeatureItem.getImageResource() != null && newFeatureItem.getImageResource().toLowerCase().endsWith(".gif");
80 |
81 | RequestManager requestManager = Glide.with(mContext);
82 | RequestOptions requestOptions = new RequestOptions()
83 | .fitCenter()
84 | .diskCacheStrategy(DiskCacheStrategy.NONE)
85 | .skipMemoryCache(true);
86 |
87 | if (finalHeight != 0 && finalWidth != 0) {
88 | requestOptions = requestOptions.override(finalWidth, finalHeight);
89 | }
90 |
91 | if (isGif) {
92 | RequestBuilder drawableTypeRequest = requestManager
93 | .setDefaultRequestOptions(requestOptions)
94 | .asGif()
95 | .load(newFeatureItem.getImageResource())
96 | .listener(new RequestListener() {
97 | @Override
98 | public boolean onLoadFailed(@Nullable GlideException e, Object model, Target target, boolean isFirstResource) {
99 | progress.setVisibility(View.GONE);
100 | return false;
101 | }
102 |
103 | @Override
104 | public boolean onResourceReady(GifDrawable resource, Object model, Target target, DataSource dataSource, boolean isFirstResource) {
105 | progress.setVisibility(View.GONE);
106 | Bitmap bitmap = resource.getFirstFrame();
107 | putBackgroundColors(bitmap, imageView, linearLayout, textViewTitle, textViewDesc);
108 | return false;
109 | }
110 | });
111 |
112 | drawableTypeRequest.into(imageView);
113 | } else {
114 | RequestBuilder drawableTypeRequest;
115 |
116 | if (newFeatureItem.getImageResource() == null) {
117 | drawableTypeRequest = requestManager.setDefaultRequestOptions(requestOptions).load(newFeatureItem.getImageDrawableResource());
118 | } else {
119 | drawableTypeRequest = requestManager.setDefaultRequestOptions(requestOptions).load(newFeatureItem.getImageResource());
120 | }
121 | drawableTypeRequest = drawableTypeRequest
122 | .listener(new RequestListener() {
123 | @Override
124 | public boolean onLoadFailed(@Nullable GlideException e, Object model, Target target, boolean isFirstResource) {
125 | progress.setVisibility(View.GONE);
126 | return false;
127 | }
128 |
129 | @Override
130 | public boolean onResourceReady(Drawable resource, Object model, Target target, DataSource dataSource, boolean isFirstResource) {
131 | progress.setVisibility(View.GONE);
132 | Bitmap bitmap = ((BitmapDrawable) resource).getBitmap();
133 | putBackgroundColors(bitmap, imageView, linearLayout, textViewTitle, textViewDesc);
134 | return false;
135 | }
136 | });
137 |
138 | drawableTypeRequest.into(imageView);
139 | }
140 | return true;
141 | }
142 | });
143 |
144 | return view;
145 | }
146 |
147 |
148 | @Override
149 | public int getCount() {
150 | return mNewFeatureItems.size();
151 | }
152 |
153 | private void putBackgroundColors(Bitmap bitmap, final ImageView imageView, final LinearLayout linearLayout, final TextView textViewTitle, final TextView textViewDesc) {
154 |
155 | boolean usePalette = mUsePaletteForDescBackground || mUsePaletteForImageBackground;
156 | if (!usePalette) {
157 | return;
158 | }
159 |
160 | if (bitmap != null && !bitmap.isRecycled()) {
161 |
162 | Palette.from(bitmap).generate(new Palette.PaletteAsyncListener() {
163 | @Override
164 | public void onGenerated(Palette palette) {
165 | int whiteColor = mContext.getResources().getColor(android.R.color.white);
166 | int blackColor = mContext.getResources().getColor(android.R.color.black);
167 | int dominantColor = palette.getDominantColor(whiteColor);
168 | int contrastColor = Util.getContrastColor(palette.getDominantColor(whiteColor));
169 |
170 | if (mUsePaletteForImageBackground) {
171 | ObjectAnimator colorAnim = ObjectAnimator.ofInt(imageView, "backgroundColor", whiteColor, dominantColor);
172 | colorAnim.setEvaluator(new ArgbEvaluator());
173 | colorAnim.setDuration(500)
174 | .start();
175 | }
176 |
177 | if (mUsePaletteForDescBackground) {
178 | ObjectAnimator colorAnim2 = ObjectAnimator.ofInt(linearLayout, "backgroundColor", whiteColor, dominantColor);
179 | colorAnim2.setEvaluator(new ArgbEvaluator());
180 | colorAnim2.setDuration(500)
181 | .start();
182 |
183 | ObjectAnimator colorAnim3 = ObjectAnimator.ofInt(textViewTitle, "textColor", blackColor, contrastColor);
184 | colorAnim3.setEvaluator(new ArgbEvaluator());
185 | colorAnim3.setDuration(500)
186 | .start();
187 |
188 | ObjectAnimator colorAnim4 = ObjectAnimator.ofInt(textViewDesc, "textColor", blackColor, contrastColor);
189 | colorAnim4.setEvaluator(new ArgbEvaluator());
190 | colorAnim4.setDuration(500)
191 | .start();
192 | }
193 | }
194 | });
195 | }
196 | }
197 | }
198 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "{}"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright {yyyy} {name of copyright owner}
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
--------------------------------------------------------------------------------
/whatisnewdialog/src/main/java/com/nonzeroapps/whatisnewdialog/view/InkPageIndicator.java:
--------------------------------------------------------------------------------
1 | package com.nonzeroapps.whatisnewdialog.view;
2 |
3 | /**
4 | * Created by berkayturanci on 04/08/2017.
5 | */
6 |
7 | import android.animation.Animator;
8 | import android.animation.AnimatorListenerAdapter;
9 | import android.animation.ValueAnimator;
10 | import android.annotation.SuppressLint;
11 | import android.content.Context;
12 | import android.content.res.TypedArray;
13 | import android.database.DataSetObserver;
14 | import android.graphics.Canvas;
15 | import android.graphics.Paint;
16 | import android.graphics.Path;
17 | import android.graphics.RectF;
18 | import android.os.Parcel;
19 | import android.os.Parcelable;
20 | import android.util.AttributeSet;
21 | import android.view.View;
22 | import android.view.animation.Interpolator;
23 |
24 | import androidx.core.view.ViewCompat;
25 | import androidx.interpolator.view.animation.FastOutSlowInInterpolator;
26 | import androidx.viewpager.widget.ViewPager;
27 |
28 | import com.nonzeroapps.whatisnewdialog.R;
29 |
30 | import java.util.Arrays;
31 |
32 |
33 | public class InkPageIndicator extends View implements ViewPager.OnPageChangeListener, View.OnAttachStateChangeListener {
34 | private static final int DEFAULT_DOT_SIZE = 8;
35 | private static final int DEFAULT_GAP = 12;
36 | private static final int DEFAULT_ANIM_DURATION = 400;
37 | private static final int DEFAULT_UNSELECTED_COLOUR = 0x80ffffff;
38 | private static final int DEFAULT_SELECTED_COLOUR = 0xffffffff;
39 |
40 | private static final float INVALID_FRACTION = -1f;
41 | private static final float MINIMAL_REVEAL = 0.00001f;
42 | private final Paint selectedPaint;
43 | private final Path unselectedDotPath;
44 | private final Path unselectedDotLeftPath;
45 | private final Path unselectedDotRightPath;
46 | private final RectF rectF;
47 | private final Interpolator interpolator;
48 | float endX1;
49 | float endY1;
50 | float endX2;
51 | float endY2;
52 | float controlX1;
53 | float controlY1;
54 | float controlX2;
55 | float controlY2;
56 | private int dotDiameter;
57 | private int gap;
58 | private long animDuration;
59 | private int unselectedColour;
60 | private float dotRadius;
61 | private float halfDotRadius;
62 | private long animHalfDuration;
63 | private float dotTopY;
64 | private float dotCenterY;
65 | private float dotBottomY;
66 | private ViewPager viewPager;
67 | private int pageCount;
68 | private int currentPage;
69 | private int previousPage;
70 | private float selectedDotX;
71 | private boolean selectedDotInPosition;
72 | private float[] dotCenterX;
73 | private float[] joiningFractions;
74 | private float retreatingJoinX1;
75 | private float retreatingJoinX2;
76 | private float[] dotRevealFractions;
77 | private boolean isAttachedToWindow;
78 | private boolean pageChanging;
79 | private Paint unselectedPaint;
80 | private Path combinedUnselectedPath;
81 | private ValueAnimator moveAnimation;
82 | private PendingRetreatAnimator retreatAnimation;
83 | private PendingRevealAnimator[] revealAnimations;
84 |
85 | public InkPageIndicator(Context context) {
86 | this(context, null, 0);
87 | }
88 |
89 | public InkPageIndicator(Context context, AttributeSet attrs) {
90 | this(context, attrs, 0);
91 | }
92 |
93 | public InkPageIndicator(Context context, AttributeSet attrs, int defStyle) {
94 | super(context, attrs, defStyle);
95 |
96 | final int density = (int) context.getResources().getDisplayMetrics().density;
97 |
98 | final TypedArray typedArray = getContext().obtainStyledAttributes(
99 | attrs, R.styleable.InkPageIndicator, defStyle, 0);
100 |
101 | dotDiameter = typedArray.getDimensionPixelSize(R.styleable.InkPageIndicator_dotDiameter, DEFAULT_DOT_SIZE * density);
102 | dotRadius = dotDiameter / 2;
103 | halfDotRadius = dotRadius / 2;
104 | gap = typedArray.getDimensionPixelSize(R.styleable.InkPageIndicator_dotGap, DEFAULT_GAP * density);
105 | animDuration = (long) typedArray.getInteger(R.styleable.InkPageIndicator_animationDuration, DEFAULT_ANIM_DURATION);
106 | animHalfDuration = animDuration / 2;
107 | unselectedColour = typedArray.getColor(R.styleable.InkPageIndicator_pageIndicatorColor, DEFAULT_UNSELECTED_COLOUR);
108 | int selectedColour = typedArray.getColor(R.styleable.InkPageIndicator_currentPageIndicatorColor, DEFAULT_SELECTED_COLOUR);
109 | typedArray.recycle();
110 |
111 | unselectedPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
112 | unselectedPaint.setColor(unselectedColour);
113 | selectedPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
114 | selectedPaint.setColor(selectedColour);
115 | interpolator = new FastOutSlowInInterpolator();
116 |
117 | combinedUnselectedPath = new Path();
118 | unselectedDotPath = new Path();
119 | unselectedDotLeftPath = new Path();
120 | unselectedDotRightPath = new Path();
121 | rectF = new RectF();
122 |
123 | addOnAttachStateChangeListener(this);
124 | }
125 |
126 | private int getCount() {
127 | return viewPager.getAdapter().getCount();
128 | }
129 |
130 | public void setViewPager(final ViewPager viewPager) {
131 | this.viewPager = viewPager;
132 | viewPager.addOnPageChangeListener(this);
133 | setPageCount(getCount());
134 | viewPager.getAdapter().registerDataSetObserver(new DataSetObserver() {
135 | @Override
136 | public void onChanged() {
137 | setPageCount(getCount());
138 | }
139 | });
140 | setCurrentPageImmediate();
141 | }
142 |
143 | @Override
144 | public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
145 | if (isAttachedToWindow) {
146 | float fraction = positionOffset;
147 | int currentPosition = pageChanging ? previousPage : currentPage;
148 | int leftDotPosition = position;
149 |
150 | if (currentPosition != position) {
151 | fraction = 1f - positionOffset;
152 |
153 | if (fraction == 1f) {
154 | leftDotPosition = Math.min(currentPosition, position);
155 | }
156 | }
157 | setJoiningFraction(leftDotPosition, fraction);
158 | }
159 | }
160 |
161 | @Override
162 | public void onPageSelected(int position) {
163 | if (position < pageCount) {
164 | if (isAttachedToWindow) {
165 | setSelectedPage(position);
166 | } else {
167 | setCurrentPageImmediate();
168 | }
169 | }
170 | }
171 |
172 | @Override
173 | public void onPageScrollStateChanged(int state) {
174 | }
175 |
176 | private void setPageCount(int pages) {
177 | if (pages > 0) {
178 | pageCount = pages;
179 | resetState();
180 | requestLayout();
181 | }
182 | }
183 |
184 | private void calculateDotPositions(int width) {
185 | int left = getPaddingLeft();
186 | int top = getPaddingTop();
187 | int right = width - getPaddingRight();
188 |
189 | int requiredWidth = getRequiredWidth();
190 | float startLeft = left + ((right - left - requiredWidth) / 2) + dotRadius;
191 |
192 | dotCenterX = new float[pageCount];
193 | for (int i = 0; i < pageCount; i++) {
194 | dotCenterX[i] = startLeft + i * (dotDiameter + gap);
195 | }
196 | dotTopY = top;
197 | dotCenterY = top + dotRadius;
198 | dotBottomY = top + dotDiameter;
199 |
200 | setCurrentPageImmediate();
201 | }
202 |
203 | private void setCurrentPageImmediate() {
204 | if (viewPager != null) {
205 | currentPage = viewPager.getCurrentItem();
206 | } else {
207 | currentPage = 0;
208 | }
209 | if (isDotAnimationStarted()) {
210 | selectedDotX = dotCenterX[currentPage];
211 | }
212 | }
213 |
214 | private boolean isDotAnimationStarted() {
215 | return dotCenterX != null && dotCenterX.length > 0 && (moveAnimation == null || !moveAnimation.isStarted());
216 | }
217 |
218 | private void resetState() {
219 | joiningFractions = new float[pageCount - 1];
220 | Arrays.fill(joiningFractions, 0f);
221 | dotRevealFractions = new float[pageCount];
222 | Arrays.fill(dotRevealFractions, 0f);
223 | retreatingJoinX1 = INVALID_FRACTION;
224 | retreatingJoinX2 = INVALID_FRACTION;
225 | selectedDotInPosition = true;
226 | }
227 |
228 | @SuppressLint("SwitchIntDef")
229 | @Override
230 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
231 | int desiredHeight = getDesiredHeight();
232 | int height;
233 | switch (MeasureSpec.getMode(heightMeasureSpec)) {
234 | case MeasureSpec.EXACTLY:
235 | height = MeasureSpec.getSize(heightMeasureSpec);
236 | break;
237 | case MeasureSpec.AT_MOST:
238 | height = Math.min(desiredHeight, MeasureSpec.getSize(heightMeasureSpec));
239 | break;
240 | default:
241 | height = desiredHeight;
242 | break;
243 | }
244 |
245 | int desiredWidth = getDesiredWidth();
246 | int width;
247 | switch (MeasureSpec.getMode(widthMeasureSpec)) {
248 | case MeasureSpec.EXACTLY:
249 | width = MeasureSpec.getSize(widthMeasureSpec);
250 | break;
251 | case MeasureSpec.AT_MOST:
252 | width = Math.min(desiredWidth, MeasureSpec.getSize(widthMeasureSpec));
253 | break;
254 | default:
255 | width = desiredWidth;
256 | break;
257 | }
258 | setMeasuredDimension(width, height);
259 | calculateDotPositions(width);
260 | }
261 |
262 | private int getDesiredHeight() {
263 | return getPaddingTop() + dotDiameter + getPaddingBottom();
264 | }
265 |
266 | private int getRequiredWidth() {
267 | return pageCount * dotDiameter + (pageCount - 1) * gap;
268 | }
269 |
270 | private int getDesiredWidth() {
271 | return getPaddingLeft() + getRequiredWidth() + getPaddingRight();
272 | }
273 |
274 | @Override
275 | public void onViewAttachedToWindow(View view) {
276 | isAttachedToWindow = true;
277 | }
278 |
279 | @Override
280 | public void onViewDetachedFromWindow(View view) {
281 | isAttachedToWindow = false;
282 | }
283 |
284 | @Override
285 | protected void onDraw(Canvas canvas) {
286 | if (viewPager == null || pageCount == 0) return;
287 | drawUnselected(canvas);
288 | drawSelected(canvas);
289 | }
290 |
291 | private void drawUnselected(Canvas canvas) {
292 | combinedUnselectedPath.rewind();
293 |
294 | for (int page = 0; page < pageCount; page++) {
295 | int nextXIndex;
296 |
297 | if (page == pageCount - 1) {
298 | nextXIndex = page;
299 | } else {
300 | nextXIndex = page + 1;
301 | }
302 |
303 | Path unselectedPath = getUnselectedPath(page,
304 | dotCenterX[page],
305 | dotCenterX[nextXIndex],
306 | page == pageCount - 1 ? INVALID_FRACTION : joiningFractions[page],
307 | dotRevealFractions[page]);
308 |
309 | unselectedPath.addPath(combinedUnselectedPath);
310 | combinedUnselectedPath.addPath(unselectedPath);
311 | }
312 |
313 | if (retreatingJoinX1 != INVALID_FRACTION) {
314 | Path retreatingJoinPath = getRetreatingJoinPath();
315 | combinedUnselectedPath.addPath(retreatingJoinPath);
316 | }
317 |
318 | canvas.drawPath(combinedUnselectedPath, unselectedPaint);
319 | }
320 |
321 | private Path getUnselectedPath(int page, float centerX, float nextCenterX, float joiningFraction, float dotRevealFraction) {
322 | unselectedDotPath.rewind();
323 |
324 | if (isDotNotJoining(page, joiningFraction, dotRevealFraction)) {
325 | unselectedDotPath.addCircle(dotCenterX[page], dotCenterY, dotRadius, Path.Direction.CW);
326 | }
327 |
328 | if (isDotJoining(joiningFraction)) {
329 |
330 | unselectedDotLeftPath.rewind();
331 | unselectedDotLeftPath.moveTo(centerX, dotBottomY);
332 | rectF.set(centerX - dotRadius, dotTopY, centerX + dotRadius, dotBottomY);
333 | unselectedDotLeftPath.arcTo(rectF, 90, 180, true);
334 |
335 | endX1 = centerX + dotRadius + (joiningFraction * gap);
336 | endY1 = dotCenterY;
337 | controlX1 = centerX + halfDotRadius;
338 | controlY1 = dotTopY;
339 | controlX2 = endX1;
340 | controlY2 = endY1 - halfDotRadius;
341 | unselectedDotLeftPath.cubicTo(controlX1, controlY1,
342 | controlX2, controlY2,
343 | endX1, endY1);
344 |
345 | endX2 = centerX;
346 | endY2 = dotBottomY;
347 | controlX1 = endX1;
348 | controlY1 = endY1 + halfDotRadius;
349 | controlX2 = centerX + halfDotRadius;
350 | controlY2 = dotBottomY;
351 | unselectedDotLeftPath.cubicTo(controlX1, controlY1,
352 | controlX2, controlY2,
353 | endX2, endY2);
354 |
355 | unselectedDotPath.addPath(unselectedDotLeftPath);
356 |
357 | unselectedDotRightPath.rewind();
358 | unselectedDotRightPath.moveTo(nextCenterX, dotBottomY);
359 |
360 | rectF.set(nextCenterX - dotRadius, dotTopY, nextCenterX + dotRadius, dotBottomY);
361 | unselectedDotRightPath.arcTo(rectF, 90, -180, true);
362 |
363 | endX1 = nextCenterX - dotRadius - (joiningFraction * gap);
364 | endY1 = dotCenterY;
365 | controlX1 = nextCenterX - halfDotRadius;
366 | controlY1 = dotTopY;
367 | controlX2 = endX1;
368 | controlY2 = endY1 - halfDotRadius;
369 | unselectedDotRightPath.cubicTo(controlX1, controlY1,
370 | controlX2, controlY2,
371 | endX1, endY1);
372 |
373 | endX2 = nextCenterX;
374 | endY2 = dotBottomY;
375 | controlX1 = endX1;
376 | controlY1 = endY1 + halfDotRadius;
377 | controlX2 = endX2 - halfDotRadius;
378 | controlY2 = dotBottomY;
379 | unselectedDotRightPath.cubicTo(controlX1, controlY1,
380 | controlX2, controlY2,
381 | endX2, endY2);
382 | unselectedDotPath.addPath(unselectedDotRightPath);
383 | }
384 |
385 | if (joiningFraction > 0.5f && joiningFraction < 1f && retreatingJoinX1 == INVALID_FRACTION) {
386 | float adjustedFraction = (joiningFraction - 0.2f) * 1.25f;
387 |
388 | unselectedDotPath.moveTo(centerX, dotBottomY);
389 | rectF.set(centerX - dotRadius, dotTopY, centerX + dotRadius, dotBottomY);
390 | unselectedDotPath.arcTo(rectF, 90, 180, true);
391 |
392 | endX1 = centerX + dotRadius + (gap / 2);
393 | endY1 = dotCenterY - (adjustedFraction * dotRadius);
394 | controlX1 = endX1 - (adjustedFraction * dotRadius);
395 | controlY1 = dotTopY;
396 | controlX2 = endX1 - ((1 - adjustedFraction) * dotRadius);
397 | controlY2 = endY1;
398 | unselectedDotPath.cubicTo(controlX1, controlY1,
399 | controlX2, controlY2,
400 | endX1, endY1);
401 |
402 | endX2 = nextCenterX;
403 | endY2 = dotTopY;
404 | controlX1 = endX1 + ((1 - adjustedFraction) * dotRadius);
405 | controlY1 = endY1;
406 | controlX2 = endX1 + (adjustedFraction * dotRadius);
407 | controlY2 = dotTopY;
408 | unselectedDotPath.cubicTo(controlX1, controlY1,
409 | controlX2, controlY2,
410 | endX2, endY2);
411 |
412 | rectF.set(nextCenterX - dotRadius, dotTopY, nextCenterX + dotRadius, dotBottomY);
413 | unselectedDotPath.arcTo(rectF, 270, 180, true);
414 |
415 | endY1 = dotCenterY + (adjustedFraction * dotRadius);
416 | controlX1 = endX1 + (adjustedFraction * dotRadius);
417 | controlY1 = dotBottomY;
418 | controlX2 = endX1 + ((1 - adjustedFraction) * dotRadius);
419 | controlY2 = endY1;
420 | unselectedDotPath.cubicTo(controlX1, controlY1,
421 | controlX2, controlY2,
422 | endX1, endY1);
423 |
424 | endX2 = centerX;
425 | endY2 = dotBottomY;
426 | controlX1 = endX1 - ((1 - adjustedFraction) * dotRadius);
427 | controlY1 = endY1;
428 | controlX2 = endX1 - (adjustedFraction * dotRadius);
429 | controlY2 = endY2;
430 | unselectedDotPath.cubicTo(controlX1, controlY1,
431 | controlX2, controlY2,
432 | endX2, endY2);
433 | }
434 | if (joiningFraction == 1 && retreatingJoinX1 == INVALID_FRACTION) {
435 | rectF.set(centerX - dotRadius, dotTopY, nextCenterX + dotRadius, dotBottomY);
436 | unselectedDotPath.addRoundRect(rectF, dotRadius, dotRadius, Path.Direction.CW);
437 | }
438 |
439 | if (dotRevealFraction > MINIMAL_REVEAL) {
440 | unselectedDotPath.addCircle(centerX, dotCenterY, dotRevealFraction * dotRadius,
441 | Path.Direction.CW);
442 | }
443 |
444 | return unselectedDotPath;
445 | }
446 |
447 | private boolean isDotJoining(float joiningFraction) {
448 | return joiningFraction > 0f && joiningFraction <= 0.5f && retreatingJoinX1 == INVALID_FRACTION;
449 | }
450 |
451 | private boolean isDotNotJoining(int page, float joiningFraction, float dotRevealFraction) {
452 | return (joiningFraction == 0f || joiningFraction == INVALID_FRACTION)
453 | && dotRevealFraction == 0f
454 | && !(page == currentPage && selectedDotInPosition);
455 | }
456 |
457 | private Path getRetreatingJoinPath() {
458 | unselectedDotPath.rewind();
459 | rectF.set(retreatingJoinX1, dotTopY, retreatingJoinX2, dotBottomY);
460 | unselectedDotPath.addRoundRect(rectF, dotRadius, dotRadius, Path.Direction.CW);
461 | return unselectedDotPath;
462 | }
463 |
464 | private void drawSelected(Canvas canvas) {
465 | canvas.drawCircle(selectedDotX, dotCenterY, dotRadius, selectedPaint);
466 | }
467 |
468 | private void setSelectedPage(int now) {
469 | if (now == currentPage) {
470 | return;
471 | }
472 |
473 | pageChanging = true;
474 | previousPage = currentPage;
475 | currentPage = now;
476 | final int steps = Math.abs(now - previousPage);
477 |
478 | if (steps > 1) {
479 | if (now > previousPage) {
480 | for (int i = 0; i < steps; i++) {
481 | setJoiningFraction(previousPage + i, 1f);
482 | }
483 | } else {
484 | for (int i = -1; i > -steps; i--) {
485 | setJoiningFraction(previousPage + i, 1f);
486 | }
487 | }
488 | }
489 |
490 | moveAnimation = createMoveSelectedAnimator(dotCenterX[now], previousPage, now, steps);
491 | moveAnimation.start();
492 | }
493 |
494 | private ValueAnimator createMoveSelectedAnimator(
495 | final float moveTo, int was, int now, int steps) {
496 | ValueAnimator moveSelected = ValueAnimator.ofFloat(selectedDotX, moveTo);
497 |
498 | retreatAnimation = new PendingRetreatAnimator(was, now, steps,
499 | now > was ?
500 | new RightwardStartPredicate(moveTo - ((moveTo - selectedDotX) * 0.25f)) :
501 | new LeftwardStartPredicate(moveTo + ((selectedDotX - moveTo) * 0.25f)));
502 | retreatAnimation.addListener(new AnimatorListenerAdapter() {
503 | @Override
504 | public void onAnimationEnd(Animator animation) {
505 | resetState();
506 | pageChanging = false;
507 | }
508 | });
509 | moveSelected.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
510 | @Override
511 | public void onAnimationUpdate(ValueAnimator valueAnimator) {
512 | selectedDotX = (Float) valueAnimator.getAnimatedValue();
513 | retreatAnimation.startIfNecessary(selectedDotX);
514 | ViewCompat.postInvalidateOnAnimation(InkPageIndicator.this);
515 | }
516 | });
517 | moveSelected.addListener(new AnimatorListenerAdapter() {
518 | @Override
519 | public void onAnimationStart(Animator animation) {
520 | selectedDotInPosition = false;
521 | }
522 |
523 | @Override
524 | public void onAnimationEnd(Animator animation) {
525 | selectedDotInPosition = true;
526 | }
527 | });
528 |
529 | moveSelected.setStartDelay(selectedDotInPosition ? animDuration / 4L : 0L);
530 | moveSelected.setDuration(animDuration * 3L / 4L);
531 | moveSelected.setInterpolator(interpolator);
532 | return moveSelected;
533 | }
534 |
535 | private void setJoiningFraction(int leftDot, float fraction) {
536 | if (joiningFractions != null) {
537 | if (leftDot < joiningFractions.length) {
538 | joiningFractions[leftDot] = fraction;
539 | ViewCompat.postInvalidateOnAnimation(this);
540 | }
541 | }
542 | }
543 |
544 | public void clearJoiningFractions() {
545 | Arrays.fill(joiningFractions, 0f);
546 | ViewCompat.postInvalidateOnAnimation(this);
547 | }
548 |
549 | private void setDotRevealFraction(int dot, float fraction) {
550 | if (dot < dotRevealFractions.length) {
551 | dotRevealFractions[dot] = fraction;
552 | }
553 | ViewCompat.postInvalidateOnAnimation(this);
554 | }
555 |
556 | public void setPageIndicatorColor(int secondaryColor) {
557 | unselectedColour = secondaryColor;
558 | unselectedPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
559 | unselectedPaint.setColor(unselectedColour);
560 | }
561 |
562 | @Override
563 | public void onRestoreInstanceState(Parcelable state) {
564 | SavedState savedState = (SavedState) state;
565 | super.onRestoreInstanceState(savedState.getSuperState());
566 | currentPage = savedState.currentPage;
567 | requestLayout();
568 | }
569 |
570 | @Override
571 | public Parcelable onSaveInstanceState() {
572 | Parcelable superState = super.onSaveInstanceState();
573 | SavedState savedState = new SavedState(superState);
574 | savedState.currentPage = currentPage;
575 | return savedState;
576 | }
577 |
578 | static class SavedState extends BaseSavedState {
579 | public static final Creator CREATOR = new Creator() {
580 | @Override
581 | public SavedState createFromParcel(Parcel in) {
582 | return new SavedState(in);
583 | }
584 |
585 | @Override
586 | public SavedState[] newArray(int size) {
587 | return new SavedState[size];
588 | }
589 | };
590 | int currentPage;
591 |
592 | SavedState(Parcelable superState) {
593 | super(superState);
594 | }
595 |
596 | private SavedState(Parcel in) {
597 | super(in);
598 | currentPage = in.readInt();
599 | }
600 |
601 | @Override
602 | public void writeToParcel(Parcel dest, int flags) {
603 | super.writeToParcel(dest, flags);
604 | dest.writeInt(currentPage);
605 | }
606 | }
607 |
608 | public abstract class PendingStartAnimator extends ValueAnimator {
609 | boolean hasStarted;
610 | StartPredicate predicate;
611 |
612 | PendingStartAnimator(StartPredicate predicate) {
613 | super();
614 | this.predicate = predicate;
615 | hasStarted = false;
616 | }
617 |
618 | void startIfNecessary(float currentValue) {
619 | if (!hasStarted && predicate.shouldStart(currentValue)) {
620 | start();
621 | hasStarted = true;
622 | }
623 | }
624 | }
625 |
626 | public class PendingRetreatAnimator extends PendingStartAnimator {
627 | PendingRetreatAnimator(int was, int now, int steps, StartPredicate predicate) {
628 | super(predicate);
629 | setDuration(animHalfDuration);
630 | setInterpolator(interpolator);
631 |
632 | // work out the start/end values of the retreating join from the direction we're
633 | // travelling in. Also look at the current selected dot position, i.e. we're moving on
634 | // before a prior anim has finished.
635 | final float initialX1 = now > was ? Math.min(dotCenterX[was], selectedDotX) - dotRadius
636 | : dotCenterX[now] - dotRadius;
637 | final float finalX1 = now > was ? dotCenterX[now] - dotRadius
638 | : dotCenterX[now] - dotRadius;
639 | final float initialX2 = now > was ? dotCenterX[now] + dotRadius
640 | : Math.max(dotCenterX[was], selectedDotX) + dotRadius;
641 | final float finalX2 = now > was ? dotCenterX[now] + dotRadius
642 | : dotCenterX[now] + dotRadius;
643 |
644 | revealAnimations = new PendingRevealAnimator[steps];
645 | // hold on to the indexes of the dots that will be hidden by the retreat so that
646 | // we can initialize their revealFraction's i.e. make sure they're hidden while the
647 | // reveal animation runs
648 | final int[] dotsToHide = new int[steps];
649 | if (initialX1 != finalX1) {
650 | setFloatValues(initialX1, finalX1);
651 | for (int i = 0; i < steps; i++) {
652 | revealAnimations[i] = new PendingRevealAnimator(was + i,
653 | new RightwardStartPredicate(dotCenterX[was + i]));
654 | dotsToHide[i] = was + i;
655 | }
656 | addUpdateListener(new AnimatorUpdateListener() {
657 | @Override
658 | public void onAnimationUpdate(ValueAnimator valueAnimator) {
659 | retreatingJoinX1 = (Float) valueAnimator.getAnimatedValue();
660 | ViewCompat.postInvalidateOnAnimation(InkPageIndicator.this);
661 |
662 | for (PendingRevealAnimator pendingReveal : revealAnimations) {
663 | pendingReveal.startIfNecessary(retreatingJoinX1);
664 | }
665 | }
666 | });
667 | } else {
668 | setFloatValues(initialX2, finalX2);
669 | for (int i = 0; i < steps; i++) {
670 | revealAnimations[i] = new PendingRevealAnimator(was - i,
671 | new LeftwardStartPredicate(dotCenterX[was - i]));
672 | dotsToHide[i] = was - i;
673 | }
674 | addUpdateListener(new AnimatorUpdateListener() {
675 | @Override
676 | public void onAnimationUpdate(ValueAnimator valueAnimator) {
677 | retreatingJoinX2 = (Float) valueAnimator.getAnimatedValue();
678 | ViewCompat.postInvalidateOnAnimation(InkPageIndicator.this);
679 |
680 | for (PendingRevealAnimator pendingReveal : revealAnimations) {
681 | pendingReveal.startIfNecessary(retreatingJoinX2);
682 | }
683 | }
684 | });
685 | }
686 |
687 | addListener(new AnimatorListenerAdapter() {
688 | @Override
689 | public void onAnimationStart(Animator animation) {
690 | clearJoiningFractions();
691 |
692 | for (int dot : dotsToHide) {
693 | setDotRevealFraction(dot, MINIMAL_REVEAL);
694 | }
695 | retreatingJoinX1 = initialX1;
696 | retreatingJoinX2 = initialX2;
697 | ViewCompat.postInvalidateOnAnimation(InkPageIndicator.this);
698 | }
699 |
700 | @Override
701 | public void onAnimationEnd(Animator animation) {
702 | retreatingJoinX1 = INVALID_FRACTION;
703 | retreatingJoinX2 = INVALID_FRACTION;
704 | ViewCompat.postInvalidateOnAnimation(InkPageIndicator.this);
705 | }
706 | });
707 | }
708 | }
709 |
710 | public class PendingRevealAnimator extends PendingStartAnimator {
711 | private int dot;
712 |
713 | PendingRevealAnimator(int dot, StartPredicate predicate) {
714 | super(predicate);
715 | setFloatValues(MINIMAL_REVEAL, 1f);
716 | this.dot = dot;
717 | setDuration(animHalfDuration);
718 | setInterpolator(interpolator);
719 | addUpdateListener(new AnimatorUpdateListener() {
720 | @Override
721 | public void onAnimationUpdate(ValueAnimator valueAnimator) {
722 | setDotRevealFraction(PendingRevealAnimator.this.dot,
723 | (Float) valueAnimator.getAnimatedValue());
724 | }
725 | });
726 | addListener(new AnimatorListenerAdapter() {
727 | @Override
728 | public void onAnimationEnd(Animator animation) {
729 | setDotRevealFraction(PendingRevealAnimator.this.dot, 0f);
730 | ViewCompat.postInvalidateOnAnimation(InkPageIndicator.this);
731 | }
732 | });
733 | }
734 | }
735 |
736 | public abstract class StartPredicate {
737 | float thresholdValue;
738 |
739 | StartPredicate(float thresholdValue) {
740 | this.thresholdValue = thresholdValue;
741 | }
742 |
743 | abstract boolean shouldStart(float currentValue);
744 | }
745 |
746 | public class RightwardStartPredicate extends StartPredicate {
747 | RightwardStartPredicate(float thresholdValue) {
748 | super(thresholdValue);
749 | }
750 |
751 | boolean shouldStart(float currentValue) {
752 | return currentValue > thresholdValue;
753 | }
754 | }
755 |
756 | public class LeftwardStartPredicate extends StartPredicate {
757 | LeftwardStartPredicate(float thresholdValue) {
758 | super(thresholdValue);
759 | }
760 |
761 | boolean shouldStart(float currentValue) {
762 | return currentValue < thresholdValue;
763 | }
764 | }
765 | }
--------------------------------------------------------------------------------