├── .gitignore ├── .idea ├── caches │ └── build_file_checksums.ser ├── codeStyles │ └── Project.xml ├── copyright │ ├── bxute.xml │ └── profiles_settings.xml ├── gradle.xml ├── misc.xml ├── runConfigurations.xml └── vcs.xml ├── README.md ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── xute │ │ └── storyviewsample │ │ └── ExampleInstrumentedTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── xute │ │ │ └── storyviewsample │ │ │ └── MainActivity.java │ └── res │ │ ├── drawable-v24 │ │ └── ic_launcher_foreground.xml │ │ ├── drawable │ │ └── ic_launcher_background.xml │ │ ├── layout │ │ └── activity_main.xml │ │ ├── mipmap-anydpi-v26 │ │ ├── ic_launcher.xml │ │ └── ic_launcher_round.xml │ │ ├── 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 │ │ └── values │ │ ├── colors.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test │ └── java │ └── xute │ └── storyviewsample │ └── ExampleUnitTest.java ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── settings.gradle ├── storyView.png ├── storyplayer.png └── storyview ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src ├── androidTest └── java │ └── xute │ └── storyview │ └── ExampleInstrumentedTest.java ├── main ├── AndroidManifest.xml ├── java │ └── xute │ │ └── storyview │ │ ├── StoryModel.java │ │ ├── StoryPlayer.java │ │ ├── StoryPlayerProgressView.java │ │ ├── StoryPreference.java │ │ └── StoryView.java └── res │ ├── layout │ └── activity_story_player.xml │ └── values │ ├── attrs.xml │ └── strings.xml └── test └── java └── xute └── storyview └── ExampleUnitTest.java /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/libraries 5 | /.idea/modules.xml 6 | /.idea/workspace.xml 7 | .DS_Store 8 | /build 9 | /captures 10 | .externalNativeBuild 11 | -------------------------------------------------------------------------------- /.idea/caches/build_file_checksums.ser: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bxute/StoryView/3b78146c1bc426327439a552b05ee045992ac0fc/.idea/caches/build_file_checksums.ser -------------------------------------------------------------------------------- /.idea/codeStyles/Project.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 |
7 | 8 | 9 | 10 | xmlns:android 11 | 12 | ^$ 13 | 14 | 15 | 16 |
17 |
18 | 19 | 20 | 21 | xmlns:.* 22 | 23 | ^$ 24 | 25 | 26 | BY_NAME 27 | 28 |
29 |
30 | 31 | 32 | 33 | .*:id 34 | 35 | http://schemas.android.com/apk/res/android 36 | 37 | 38 | 39 |
40 |
41 | 42 | 43 | 44 | .*:name 45 | 46 | http://schemas.android.com/apk/res/android 47 | 48 | 49 | 50 |
51 |
52 | 53 | 54 | 55 | name 56 | 57 | ^$ 58 | 59 | 60 | 61 |
62 |
63 | 64 | 65 | 66 | style 67 | 68 | ^$ 69 | 70 | 71 | 72 |
73 |
74 | 75 | 76 | 77 | .* 78 | 79 | ^$ 80 | 81 | 82 | BY_NAME 83 | 84 |
85 |
86 | 87 | 88 | 89 | .* 90 | 91 | http://schemas.android.com/apk/res/android 92 | 93 | 94 | ANDROID_ATTRIBUTE_ORDER 95 | 96 |
97 |
98 | 99 | 100 | 101 | .* 102 | 103 | .* 104 | 105 | 106 | BY_NAME 107 | 108 |
109 |
110 |
111 |
112 |
113 |
-------------------------------------------------------------------------------- /.idea/copyright/bxute.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | -------------------------------------------------------------------------------- /.idea/copyright/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 19 | 20 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 9 | -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # StoryView [![](https://jitpack.io/v/bxute/StoryView.svg)](https://jitpack.io/#bxute/StoryView) 2 | 3 | A library for social stories. 4 | 5 | How it looks like: 6 | 7 | **Story View** 8 | 9 | 10 | 11 | 12 | **Story Player** 13 | 14 | 15 | 16 | 17 | ### Features: 18 | - It marks the visited stories 19 | 20 | ![visit_show](https://user-images.githubusercontent.com/10809719/41231419-a66d6c32-6da0-11e8-8c49-6f0cc5693cb3.gif) 21 | 22 | - It pauses when we keep our finger on screen and resumes when fingers are released. 23 | 24 | ![pause_show](https://user-images.githubusercontent.com/10809719/41231418-a63aae32-6da0-11e8-852d-365d44ce9dc5.gif) 25 | ### How to use this library 26 | 27 | 1. Add it in your root build.gradle at the end of repositories: 28 | ```java 29 | allprojects { 30 | repositories { 31 | maven { url 'https://jitpack.io' } 32 | } 33 | } 34 | ``` 35 | 36 | 2. Add the dependency 37 | ```java 38 | dependencies { 39 | implementation 'com.github.bxute:StoryView:v1.0' 40 | } 41 | 42 | ``` 43 | 44 | 3. Add xml to your layout 45 | ```xml 46 | 54 | ``` 55 | 56 | 4. Set story info 57 | ```java 58 | StoryView storyView = findViewById(R.id.storyView); 59 | storyView.resetStoryVisits(); 60 | ArrayList uris = new ArrayList<>(); 61 | uris.add(new StoryModel("https://www.planwallpaper.com/static/images/animals-4.jpg","Steve","Yesterday")); 62 | uris.add(new StoryModel("https://static.boredpanda.com/blog/wp-content/uuuploads/albino-animals/albino-animals-3.jpg","Grambon","10:15 PM")); 63 | storyView.setImageUris(uris); 64 | ``` 65 | 66 | That`s it 😀 67 | 68 | ### Customizations 69 | You can customize the experience of `StoryView` using below given set of attributes: 70 | ```xml 71 | 72 | 73 | 74 | 75 | 76 | ``` 77 | 78 | When you need to put a set of new stories use 79 | ```java 80 | storyView.resetStoryVisits(); 81 | ``` 82 | this to reset the visits. 83 | 84 | ### Contributions 85 | 86 | Any contributions are welcome. You can send PR or open issues. 87 | 88 | ### License 89 | MIT License 90 | 91 | Copyright (c) 2018 bxute 92 | 93 | Permission is hereby granted, free of charge, to any person obtaining a copy 94 | of this software and associated documentation files (the "Software"), to deal 95 | in the Software without restriction, including without limitation the rights 96 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 97 | copies of the Software, and to permit persons to whom the Software is 98 | furnished to do so, subject to the following conditions: 99 | 100 | The above copyright notice and this permission notice shall be included in all 101 | copies or substantial portions of the Software. 102 | 103 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 104 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 105 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 106 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 107 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 108 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 109 | SOFTWARE. 110 | 111 | 112 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 27 5 | defaultConfig { 6 | applicationId "xute.storyviewsample" 7 | minSdkVersion 21 8 | targetSdkVersion 27 9 | versionCode 1 10 | versionName "1.0" 11 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 12 | } 13 | buildTypes { 14 | release { 15 | minifyEnabled true 16 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 17 | } 18 | debug { 19 | minifyEnabled true 20 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 21 | } 22 | } 23 | } 24 | 25 | dependencies { 26 | implementation fileTree(include: ['*.jar'], dir: 'libs') 27 | implementation 'com.android.support:appcompat-v7:27.1.1' 28 | implementation 'com.android.support.constraint:constraint-layout:1.1.1' 29 | testImplementation 'junit:junit:4.12' 30 | androidTestImplementation 'com.android.support.test:runner:1.0.2' 31 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' 32 | implementation project(':storyview') 33 | } 34 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile 22 | -------------------------------------------------------------------------------- /app/src/androidTest/java/xute/storyviewsample/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package xute.storyviewsample; 2 | 3 | import android.content.Context; 4 | import android.support.test.InstrumentationRegistry; 5 | import android.support.test.runner.AndroidJUnit4; 6 | 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | 10 | import static org.junit.Assert.*; 11 | 12 | /** 13 | * Instrumented test, which will execute on an Android device. 14 | * 15 | * @see Testing documentation 16 | */ 17 | @RunWith(AndroidJUnit4.class) 18 | public class ExampleInstrumentedTest { 19 | @Test 20 | public void useAppContext() { 21 | // Context of the app under test. 22 | Context appContext = InstrumentationRegistry.getTargetContext(); 23 | 24 | assertEquals("xute.storyviewsample", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /app/src/main/java/xute/storyviewsample/MainActivity.java: -------------------------------------------------------------------------------- 1 | package xute.storyviewsample; 2 | 3 | import android.os.Bundle; 4 | import android.support.v7.app.AppCompatActivity; 5 | 6 | import java.util.ArrayList; 7 | 8 | import xute.storyview.StoryModel; 9 | import xute.storyview.StoryView; 10 | 11 | public class MainActivity extends AppCompatActivity { 12 | 13 | @Override 14 | protected void onCreate(Bundle savedInstanceState) { 15 | super.onCreate(savedInstanceState); 16 | setContentView(R.layout.activity_main); 17 | StoryView storyView = findViewById(R.id.storyView); 18 | storyView.setActivityContext(this); 19 | storyView.resetStoryVisits(); 20 | ArrayList uris = new ArrayList<>(); 21 | uris.add(new StoryModel("https://picsum.photos/200/300", "Ankit Kumar", "12:00 PM")); 22 | uris.add(new StoryModel("https://cdn.pixabay.com/photo/2015/04/19/08/32/marguerite-729510__340.jpg", "Panda Man", "01:00 AM")); 23 | uris.add(new StoryModel("https://encrypted-tbn0.gstatic.com/images?q=tbn%3AANd9GcRCv_Gx6Fde6mja_lLmll0fzrxRvcKLHGrPxnqMrQLWKqXi9IYy&usqp=CAU", "Steve", "Yesterday")); 24 | uris.add(new StoryModel("https://english.mathrubhumi.com/polopoly_fs/1.3885588!/image/image.jpg_gen/derivatives/landscape_607/image.jpg", "Grambon", "10:15 PM")); 25 | storyView.setImageUris(uris); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-v24/ic_launcher_foreground.xml: -------------------------------------------------------------------------------- 1 | 7 | 12 | 13 | 19 | 22 | 25 | 26 | 27 | 28 | 34 | 35 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_launcher_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 10 | 15 | 20 | 25 | 30 | 35 | 40 | 45 | 50 | 55 | 60 | 65 | 70 | 75 | 80 | 85 | 90 | 95 | 100 | 105 | 110 | 115 | 120 | 125 | 130 | 135 | 140 | 145 | 150 | 155 | 160 | 165 | 170 | 171 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 18 | 19 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bxute/StoryView/3b78146c1bc426327439a552b05ee045992ac0fc/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bxute/StoryView/3b78146c1bc426327439a552b05ee045992ac0fc/app/src/main/res/mipmap-hdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bxute/StoryView/3b78146c1bc426327439a552b05ee045992ac0fc/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bxute/StoryView/3b78146c1bc426327439a552b05ee045992ac0fc/app/src/main/res/mipmap-mdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bxute/StoryView/3b78146c1bc426327439a552b05ee045992ac0fc/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bxute/StoryView/3b78146c1bc426327439a552b05ee045992ac0fc/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bxute/StoryView/3b78146c1bc426327439a552b05ee045992ac0fc/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bxute/StoryView/3b78146c1bc426327439a552b05ee045992ac0fc/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bxute/StoryView/3b78146c1bc426327439a552b05ee045992ac0fc/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bxute/StoryView/3b78146c1bc426327439a552b05ee045992ac0fc/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #3F51B5 4 | #303F9F 5 | #FF4081 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | StoryViewSample 3 | 4 | -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /app/src/test/java/xute/storyviewsample/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package xute.storyviewsample; 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() { 15 | assertEquals(4, 2 + 2); 16 | } 17 | } -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 2 | 3 | buildscript { 4 | 5 | repositories { 6 | google() 7 | jcenter() 8 | } 9 | dependencies { 10 | classpath 'com.android.tools.build:gradle:3.1.2' 11 | classpath 'com.github.dcendents:android-maven-gradle-plugin:2.0' 12 | } 13 | } 14 | 15 | allprojects { 16 | repositories { 17 | jcenter() 18 | mavenCentral() 19 | google() 20 | maven { url 'https://jitpack.io' } 21 | } 22 | } 23 | task clean(type: Delete) { 24 | delete rootProject.buildDir 25 | } 26 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | # IDE (e.g. Android Studio) users: 3 | # Gradle settings configured through the IDE *will override* 4 | # any settings specified in this file. 5 | # For more details on how to configure your build environment visit 6 | # http://www.gradle.org/docs/current/userguide/build_environment.html 7 | # Specifies the JVM arguments used for the daemon process. 8 | # The setting is particularly useful for tweaking memory settings. 9 | org.gradle.jvmargs=-Xmx1536m 10 | # When configured, Gradle will run in incubating parallel mode. 11 | # This option should only be used with decoupled projects. More details, visit 12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 13 | # org.gradle.parallel=true 14 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bxute/StoryView/3b78146c1bc426327439a552b05ee045992ac0fc/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Sat Jun 09 14:06:28 IST 2018 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-4.4-all.zip 7 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Attempt to set APP_HOME 10 | # Resolve links: $0 may be a link 11 | PRG="$0" 12 | # Need this for relative symlinks. 13 | while [ -h "$PRG" ] ; do 14 | ls=`ls -ld "$PRG"` 15 | link=`expr "$ls" : '.*-> \(.*\)$'` 16 | if expr "$link" : '/.*' > /dev/null; then 17 | PRG="$link" 18 | else 19 | PRG=`dirname "$PRG"`"/$link" 20 | fi 21 | done 22 | SAVED="`pwd`" 23 | cd "`dirname \"$PRG\"`/" >/dev/null 24 | APP_HOME="`pwd -P`" 25 | cd "$SAVED" >/dev/null 26 | 27 | APP_NAME="Gradle" 28 | APP_BASE_NAME=`basename "$0"` 29 | 30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 31 | DEFAULT_JVM_OPTS="" 32 | 33 | # Use the maximum available, or set MAX_FD != -1 to use that value. 34 | MAX_FD="maximum" 35 | 36 | warn () { 37 | echo "$*" 38 | } 39 | 40 | die () { 41 | echo 42 | echo "$*" 43 | echo 44 | exit 1 45 | } 46 | 47 | # OS specific support (must be 'true' or 'false'). 48 | cygwin=false 49 | msys=false 50 | darwin=false 51 | nonstop=false 52 | case "`uname`" in 53 | CYGWIN* ) 54 | cygwin=true 55 | ;; 56 | Darwin* ) 57 | darwin=true 58 | ;; 59 | MINGW* ) 60 | msys=true 61 | ;; 62 | NONSTOP* ) 63 | nonstop=true 64 | ;; 65 | esac 66 | 67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 68 | 69 | # Determine the Java command to use to start the JVM. 70 | if [ -n "$JAVA_HOME" ] ; then 71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 72 | # IBM's JDK on AIX uses strange locations for the executables 73 | JAVACMD="$JAVA_HOME/jre/sh/java" 74 | else 75 | JAVACMD="$JAVA_HOME/bin/java" 76 | fi 77 | if [ ! -x "$JAVACMD" ] ; then 78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 79 | 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 | 87 | Please set the JAVA_HOME variable in your environment to match the 88 | location of your Java installation." 89 | fi 90 | 91 | # Increase the maximum file descriptors if we can. 92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 93 | MAX_FD_LIMIT=`ulimit -H -n` 94 | if [ $? -eq 0 ] ; then 95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 96 | MAX_FD="$MAX_FD_LIMIT" 97 | fi 98 | ulimit -n $MAX_FD 99 | if [ $? -ne 0 ] ; then 100 | warn "Could not set maximum file descriptor limit: $MAX_FD" 101 | fi 102 | else 103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 104 | fi 105 | fi 106 | 107 | # For Darwin, add options to specify how the application appears in the dock 108 | if $darwin; then 109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 110 | fi 111 | 112 | # For Cygwin, switch paths to Windows format before running java 113 | if $cygwin ; then 114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 116 | JAVACMD=`cygpath --unix "$JAVACMD"` 117 | 118 | # We build the pattern for arguments to be converted via cygpath 119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 120 | SEP="" 121 | for dir in $ROOTDIRSRAW ; do 122 | ROOTDIRS="$ROOTDIRS$SEP$dir" 123 | SEP="|" 124 | done 125 | OURCYGPATTERN="(^($ROOTDIRS))" 126 | # Add a user-defined pattern to the cygpath arguments 127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 129 | fi 130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 131 | i=0 132 | for arg in "$@" ; do 133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 135 | 136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 138 | else 139 | eval `echo args$i`="\"$arg\"" 140 | fi 141 | i=$((i+1)) 142 | done 143 | case $i in 144 | (0) set -- ;; 145 | (1) set -- "$args0" ;; 146 | (2) set -- "$args0" "$args1" ;; 147 | (3) set -- "$args0" "$args1" "$args2" ;; 148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 154 | esac 155 | fi 156 | 157 | # Escape application args 158 | save () { 159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 160 | echo " " 161 | } 162 | APP_ARGS=$(save "$@") 163 | 164 | # Collect all arguments for the java command, following the shell quoting and substitution rules 165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 166 | 167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong 168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then 169 | cd "$(dirname "$0")" 170 | fi 171 | 172 | exec "$JAVACMD" "$@" 173 | -------------------------------------------------------------------------------- /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 | set DIRNAME=%~dp0 12 | if "%DIRNAME%" == "" set DIRNAME=. 13 | set APP_BASE_NAME=%~n0 14 | set APP_HOME=%DIRNAME% 15 | 16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 17 | set DEFAULT_JVM_OPTS= 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 Windows variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | 53 | :win9xME_args 54 | @rem Slurp the command line arguments. 55 | set CMD_LINE_ARGS= 56 | set _SKIP=2 57 | 58 | :win9xME_args_slurp 59 | if "x%~1" == "x" goto execute 60 | 61 | set CMD_LINE_ARGS=%* 62 | 63 | :execute 64 | @rem Setup the command line 65 | 66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 67 | 68 | @rem Execute Gradle 69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 70 | 71 | :end 72 | @rem End local scope for the variables with windows NT shell 73 | if "%ERRORLEVEL%"=="0" goto mainEnd 74 | 75 | :fail 76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 77 | rem the _cmd.exe /c_ return code! 78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 79 | exit /b 1 80 | 81 | :mainEnd 82 | if "%OS%"=="Windows_NT" endlocal 83 | 84 | :omega 85 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app', ':storyview' 2 | -------------------------------------------------------------------------------- /storyView.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bxute/StoryView/3b78146c1bc426327439a552b05ee045992ac0fc/storyView.png -------------------------------------------------------------------------------- /storyplayer.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bxute/StoryView/3b78146c1bc426327439a552b05ee045992ac0fc/storyplayer.png -------------------------------------------------------------------------------- /storyview/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /storyview/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | apply plugin: 'com.github.dcendents.android-maven' 3 | group='com.github.bxute' 4 | android { 5 | compileSdkVersion 27 6 | 7 | 8 | 9 | defaultConfig { 10 | minSdkVersion 19 11 | targetSdkVersion 27 12 | versionCode 2 13 | versionName "1.1" 14 | 15 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 16 | 17 | } 18 | 19 | buildTypes { 20 | release { 21 | minifyEnabled false 22 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 23 | } 24 | } 25 | 26 | } 27 | 28 | dependencies { 29 | implementation fileTree(dir: 'libs', include: ['*.jar']) 30 | implementation 'com.android.support:appcompat-v7:27.1.1' 31 | implementation 'com.github.bumptech.glide:glide:4.9.0' 32 | annotationProcessor 'com.github.bumptech.glide:compiler:4.9.0' 33 | } 34 | -------------------------------------------------------------------------------- /storyview/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile 22 | -------------------------------------------------------------------------------- /storyview/src/androidTest/java/xute/storyview/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package xute.storyview; 2 | 3 | import android.content.Context; 4 | import android.support.test.InstrumentationRegistry; 5 | import android.support.test.runner.AndroidJUnit4; 6 | 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | 10 | import static org.junit.Assert.*; 11 | 12 | /** 13 | * Instrumented test, which will execute on an Android device. 14 | * 15 | * @see Testing documentation 16 | */ 17 | @RunWith(AndroidJUnit4.class) 18 | public class ExampleInstrumentedTest { 19 | @Test 20 | public void useAppContext() { 21 | // Context of the app under test. 22 | Context appContext = InstrumentationRegistry.getTargetContext(); 23 | 24 | assertEquals("xute.storyview.test", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /storyview/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /storyview/src/main/java/xute/storyview/StoryModel.java: -------------------------------------------------------------------------------- 1 | package xute.storyview; 2 | 3 | import android.os.Parcel; 4 | import android.os.Parcelable; 5 | 6 | public class StoryModel implements Parcelable { 7 | public String imageUri; 8 | public String name; 9 | public String time; 10 | 11 | public StoryModel(String imageUri, String name, String time) { 12 | this.imageUri = imageUri; 13 | this.name = name; 14 | this.time = time; 15 | } 16 | 17 | public String getImageUri() { 18 | return imageUri; 19 | } 20 | 21 | public void setImageUri(String imageUri) { 22 | this.imageUri = imageUri; 23 | } 24 | 25 | public String getName() { 26 | return name; 27 | } 28 | 29 | public void setName(String name) { 30 | this.name = name; 31 | } 32 | 33 | public String getTime() { 34 | return time; 35 | } 36 | 37 | public void setTime(String time) { 38 | this.time = time; 39 | } 40 | 41 | public static Creator getCREATOR() { 42 | return CREATOR; 43 | } 44 | 45 | protected StoryModel(Parcel in) { 46 | imageUri = in.readString(); 47 | name = in.readString(); 48 | time = in.readString(); 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(imageUri); 59 | dest.writeString(name); 60 | dest.writeString(time); 61 | } 62 | 63 | @SuppressWarnings("unused") 64 | public static final Parcelable.Creator CREATOR = new Parcelable.Creator() { 65 | @Override 66 | public StoryModel createFromParcel(Parcel in) { 67 | return new StoryModel(in); 68 | } 69 | 70 | @Override 71 | public StoryModel[] newArray(int size) { 72 | return new StoryModel[size]; 73 | } 74 | }; 75 | } 76 | -------------------------------------------------------------------------------- /storyview/src/main/java/xute/storyview/StoryPlayer.java: -------------------------------------------------------------------------------- 1 | package xute.storyview; 2 | 3 | import android.content.Intent; 4 | import android.graphics.Bitmap; 5 | import android.graphics.drawable.Drawable; 6 | import android.os.Bundle; 7 | import android.support.annotation.NonNull; 8 | import android.support.annotation.Nullable; 9 | import android.support.v7.app.AppCompatActivity; 10 | import android.view.MotionEvent; 11 | import android.view.View; 12 | import android.widget.ImageView; 13 | import android.widget.TextView; 14 | 15 | import com.bumptech.glide.Glide; 16 | import com.bumptech.glide.load.DataSource; 17 | import com.bumptech.glide.load.engine.GlideException; 18 | import com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions; 19 | import com.bumptech.glide.request.Request; 20 | import com.bumptech.glide.request.RequestListener; 21 | import com.bumptech.glide.request.target.SizeReadyCallback; 22 | import com.bumptech.glide.request.target.Target; 23 | import com.bumptech.glide.request.transition.Transition; 24 | 25 | import java.util.ArrayList; 26 | 27 | public class StoryPlayer extends AppCompatActivity implements StoryPlayerProgressView.StoryPlayerListener { 28 | public static final String STORY_IMAGE_KEY = "storyImages"; 29 | StoryPlayerProgressView storyPlayerProgressView; 30 | ImageView imageView; 31 | TextView name; 32 | TextView time; 33 | ArrayList stories; 34 | StoryPreference storyPreference; 35 | 36 | @Override 37 | protected void onCreate(Bundle savedInstanceState) { 38 | super.onCreate(savedInstanceState); 39 | setContentView(R.layout.activity_story_player); 40 | storyPlayerProgressView = findViewById(R.id.progressBarView); 41 | name = findViewById(R.id.storyUserName); 42 | time = findViewById(R.id.storyTime); 43 | storyPlayerProgressView.setSingleStoryDisplayTime(2000); 44 | imageView = findViewById(R.id.storyImage); 45 | storyPreference = new StoryPreference(this); 46 | Intent intent = getIntent(); 47 | if (intent != null) { 48 | stories = intent.getParcelableArrayListExtra(STORY_IMAGE_KEY); 49 | initStoryProgressView(); 50 | } 51 | } 52 | 53 | @Override 54 | protected void onPause() { 55 | super.onPause(); 56 | storyPlayerProgressView.cancelAnimation(); 57 | } 58 | 59 | private void initStoryProgressView() { 60 | if (stories != null && stories.size() > 0) { 61 | storyPlayerProgressView.setStoryPlayerListener(this); 62 | storyPlayerProgressView.setProgressBarsCount(stories.size()); 63 | setTouchListener(); 64 | } 65 | } 66 | 67 | private void setTouchListener() { 68 | imageView.setOnTouchListener(new View.OnTouchListener() { 69 | @Override 70 | public boolean onTouch(View view, MotionEvent motionEvent) { 71 | if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) { 72 | //pause 73 | storyPlayerProgressView.pauseProgress(); 74 | return true; 75 | } else if (motionEvent.getAction() == MotionEvent.ACTION_UP) { 76 | //resume 77 | storyPlayerProgressView.resumeProgress(); 78 | return true; 79 | }else { 80 | return false; 81 | } 82 | } 83 | }); 84 | } 85 | 86 | 87 | @Override 88 | public void onStartedPlaying(int index) { 89 | loadImage(index); 90 | name.setText(stories.get(index).name); 91 | time.setText(stories.get(index).time); 92 | storyPreference.setStoryVisited(stories.get(index).imageUri); 93 | } 94 | 95 | @Override 96 | public void onFinishedPlaying() { 97 | finish(); 98 | } 99 | 100 | private void loadImage(int index) { 101 | if(!this.isDestroyed()) { 102 | storyPlayerProgressView.pauseProgress(); 103 | Glide.with(this).clear(imageView); 104 | Glide.with(this) 105 | .load(stories.get(index).imageUri) 106 | .transition(DrawableTransitionOptions.withCrossFade(500)) 107 | .addListener(new RequestListener() { 108 | @Override 109 | public boolean onLoadFailed(@Nullable GlideException e, Object model, Target target, boolean isFirstResource) { 110 | storyPlayerProgressView.resumeProgress(); 111 | return false; 112 | } 113 | 114 | @Override 115 | public boolean onResourceReady(Drawable resource, Object model, Target target, DataSource dataSource, boolean isFirstResource) { 116 | storyPlayerProgressView.resumeProgress(); 117 | return false; 118 | } 119 | }) 120 | .into(imageView); 121 | } 122 | } 123 | } 124 | -------------------------------------------------------------------------------- /storyview/src/main/java/xute/storyview/StoryPlayerProgressView.java: -------------------------------------------------------------------------------- 1 | package xute.storyview; 2 | 3 | import android.animation.Animator; 4 | import android.animation.ValueAnimator; 5 | import android.content.Context; 6 | import android.content.res.Resources; 7 | import android.content.res.TypedArray; 8 | import android.graphics.Canvas; 9 | import android.graphics.Color; 10 | import android.graphics.Paint; 11 | import android.graphics.RectF; 12 | import android.support.annotation.Nullable; 13 | import android.util.AttributeSet; 14 | import android.util.Log; 15 | import android.util.TypedValue; 16 | import android.view.View; 17 | 18 | 19 | public class StoryPlayerProgressView extends View { 20 | public static final int PROGRESS_BAR_HEIGHT = 2; 21 | public static final int GAP_BETWEEN_PROGRESS_BARS = 2; 22 | public static final int SINGLE_STORY_DISPLAY_TIME = 1000; 23 | public static final String PROGRESS_PRIMARY_COLOR = "#009988"; 24 | public static final String PROGRESS_SECONDARY_COLOR = "#EEEEEE"; 25 | private int mScreenWidth; 26 | private int mProgressHeight; 27 | private int mGapBetweenProgressBars; 28 | private Resources resources; 29 | private Paint mProgressPaint; 30 | private int singleProgressBarWidth; 31 | private int progressBarsCount; 32 | private int[] progressBarRightEdge; 33 | private RectF progressBarRectF; 34 | private int top; 35 | private int bottom; 36 | private int progressBarPrimaryColor; 37 | private int progressBarSecondaryColor; 38 | private int currentProgressIndex; 39 | private long singleStoryDisplayTime; 40 | private ValueAnimator progressAnimator; 41 | private boolean isCancelled; 42 | 43 | public StoryPlayerProgressView(Context context) { 44 | super(context); 45 | setDefaults(); 46 | init(context); 47 | prepareValues(); 48 | } 49 | 50 | public StoryPlayerProgressView(Context context, @Nullable AttributeSet attrs) { 51 | super(context, attrs); 52 | init(context); 53 | TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.StoryPlayerProgressView, 0, 0); 54 | try { 55 | mProgressHeight = getPxFromDp((int) ta.getDimension(R.styleable.StoryPlayerProgressView_progressBarHeight, PROGRESS_BAR_HEIGHT)); 56 | mGapBetweenProgressBars = getPxFromDp((int) ta.getDimension(R.styleable.StoryPlayerProgressView_gapBetweenProgressBar, GAP_BETWEEN_PROGRESS_BARS)); 57 | progressBarPrimaryColor = ta.getColor(R.styleable.StoryPlayerProgressView_progressBarPrimaryColor, Color.parseColor(PROGRESS_PRIMARY_COLOR)); 58 | progressBarSecondaryColor = ta.getColor(R.styleable.StoryPlayerProgressView_progressBarSecondaryColor, Color.parseColor(PROGRESS_SECONDARY_COLOR)); 59 | singleStoryDisplayTime = ta.getInt(R.styleable.StoryPlayerProgressView_singleStoryDisplayTime, SINGLE_STORY_DISPLAY_TIME); 60 | } finally { 61 | ta.recycle(); 62 | } 63 | prepareValues(); 64 | } 65 | 66 | private void init(Context context) { 67 | resources = context.getResources(); 68 | mScreenWidth = resources.getDisplayMetrics().widthPixels; 69 | mProgressPaint = new Paint(); 70 | mProgressPaint.setAntiAlias(true); 71 | } 72 | 73 | private void setDefaults() { 74 | mProgressHeight = getPxFromDp(PROGRESS_BAR_HEIGHT); 75 | mGapBetweenProgressBars = getPxFromDp(GAP_BETWEEN_PROGRESS_BARS); 76 | progressBarPrimaryColor = Color.parseColor(PROGRESS_PRIMARY_COLOR); 77 | progressBarSecondaryColor = Color.parseColor(PROGRESS_SECONDARY_COLOR); 78 | singleStoryDisplayTime = SINGLE_STORY_DISPLAY_TIME; 79 | } 80 | 81 | private void prepareValues() { 82 | top = mGapBetweenProgressBars; 83 | bottom = mGapBetweenProgressBars + mProgressHeight; 84 | mProgressPaint.setColor(progressBarSecondaryColor); 85 | mProgressPaint.setStyle(Paint.Style.FILL); 86 | mProgressPaint.setStrokeCap(Paint.Cap.ROUND); 87 | progressBarRectF = new RectF(0, top, 0, bottom); 88 | } 89 | 90 | public void setProgressBarsCount(int count) { 91 | if (count < 1) { 92 | throw new IllegalArgumentException("Count cannot be less than 1"); 93 | } 94 | this.progressBarsCount = count; 95 | progressBarRightEdge = new int[progressBarsCount]; 96 | calculateWidthOfEachProgressBar(progressBarsCount); 97 | invalidate(); 98 | startAnimating(0); 99 | } 100 | 101 | public void setProgressBarHeight(int dpValue) { 102 | mProgressHeight = getPxFromDp(dpValue); 103 | invalidate(); 104 | } 105 | 106 | public void setGapBetweenProgressBars(int dpValue) { 107 | mGapBetweenProgressBars = getPxFromDp(dpValue); 108 | invalidate(); 109 | } 110 | 111 | public void setProgressPrimaryColor(int color) { 112 | progressBarPrimaryColor = color; 113 | invalidate(); 114 | } 115 | 116 | public void setProgressSecondaryColor(int color) { 117 | progressBarSecondaryColor = color; 118 | invalidate(); 119 | } 120 | 121 | public void setSingleStoryDisplayTime(int time) { 122 | singleStoryDisplayTime = time; 123 | invalidate(); 124 | } 125 | 126 | public void pauseProgress() { 127 | if (progressAnimator != null) { 128 | if (progressAnimator.isRunning()) { 129 | progressAnimator.pause(); 130 | } 131 | } 132 | } 133 | 134 | public void resumeProgress() { 135 | if (progressAnimator != null) { 136 | if (progressAnimator.isPaused()) { 137 | progressAnimator.resume(); 138 | } 139 | } 140 | } 141 | 142 | public void cancelAnimation() { 143 | if (progressAnimator != null) { 144 | progressAnimator.cancel(); 145 | isCancelled = true; 146 | } 147 | } 148 | 149 | @Override 150 | protected void onDraw(Canvas canvas) { 151 | super.onDraw(canvas); 152 | for (int i = 0; i < progressBarsCount; i++) { 153 | int left = (mGapBetweenProgressBars + singleProgressBarWidth) * i + mGapBetweenProgressBars; 154 | int right = (i + 1) * (mGapBetweenProgressBars + singleProgressBarWidth); 155 | mProgressPaint.setColor(progressBarSecondaryColor); 156 | progressBarRectF.set(left, top, right, bottom); 157 | canvas.drawRoundRect(progressBarRectF, mProgressHeight, mProgressHeight, mProgressPaint); 158 | right = progressBarRightEdge[i]; 159 | if (right > 0) { 160 | mProgressPaint.setColor(progressBarPrimaryColor); 161 | progressBarRectF.set(left, top, right, bottom); 162 | canvas.drawRoundRect(progressBarRectF, mProgressHeight, mProgressHeight, mProgressPaint); 163 | } 164 | } 165 | } 166 | 167 | @Override 168 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { 169 | int width = mScreenWidth - getPaddingStart() + getPaddingEnd(); 170 | int height = getPaddingTop() + getPaddingBottom() + (2 * mGapBetweenProgressBars) + mProgressHeight; 171 | int w = resolveSizeAndState(width, widthMeasureSpec, 0); 172 | int h = resolveSizeAndState(height, heightMeasureSpec, 0); 173 | setMeasuredDimension(w, h); 174 | } 175 | 176 | private void startAnimating(final int index) { 177 | if (index >= progressBarsCount) { 178 | if (storyPlayerListener != null) { 179 | storyPlayerListener.onFinishedPlaying(); 180 | return; 181 | } 182 | } 183 | progressAnimator = ValueAnimator.ofInt(0, singleProgressBarWidth); 184 | progressAnimator.setDuration(singleStoryDisplayTime); 185 | progressAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { 186 | @Override 187 | public void onAnimationUpdate(ValueAnimator valueAnimator) { 188 | int value = (int) valueAnimator.getAnimatedValue(); 189 | progressBarRightEdge[index] = (index + 1) * mGapBetweenProgressBars + index * singleProgressBarWidth + value; 190 | invalidate(); 191 | } 192 | }); 193 | progressAnimator.addListener(new Animator.AnimatorListener() { 194 | @Override 195 | public void onAnimationStart(Animator animator) { 196 | 197 | } 198 | 199 | @Override 200 | public void onAnimationEnd(Animator animator) { 201 | if (!isCancelled) startAnimating(index + 1); 202 | } 203 | 204 | @Override 205 | public void onAnimationCancel(Animator animator) { 206 | isCancelled = true; 207 | } 208 | 209 | @Override 210 | public void onAnimationRepeat(Animator animator) { 211 | } 212 | }); 213 | progressAnimator.start(); 214 | if (storyPlayerListener != null) { 215 | storyPlayerListener.onStartedPlaying(index); 216 | } 217 | } 218 | 219 | private int getPxFromDp(int dpValue) { 220 | return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dpValue, resources.getDisplayMetrics()); 221 | } 222 | 223 | private void calculateWidthOfEachProgressBar(int progressBarsCount) { 224 | this.singleProgressBarWidth = (mScreenWidth - (progressBarsCount + 1) * mGapBetweenProgressBars) / progressBarsCount; 225 | } 226 | 227 | private StoryPlayerListener storyPlayerListener; 228 | 229 | public void setStoryPlayerListener(StoryPlayerListener storyPlayerListener) { 230 | this.storyPlayerListener = storyPlayerListener; 231 | } 232 | 233 | public interface StoryPlayerListener { 234 | void onStartedPlaying(int index); 235 | 236 | void onFinishedPlaying(); 237 | } 238 | } 239 | -------------------------------------------------------------------------------- /storyview/src/main/java/xute/storyview/StoryPreference.java: -------------------------------------------------------------------------------- 1 | package xute.storyview; 2 | 3 | import android.content.Context; 4 | import android.content.SharedPreferences; 5 | 6 | public class StoryPreference { 7 | private static SharedPreferences preferences; 8 | private static SharedPreferences.Editor editor; 9 | 10 | private static final String PREF_NAME = "storyview_cache_pref"; 11 | private static final int PREF_MODE_PRIVATE = 1; 12 | 13 | public StoryPreference(Context context) { 14 | preferences = context.getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE); 15 | editor = preferences.edit(); 16 | editor.apply(); 17 | } 18 | public void clearStoryPreferences() { 19 | editor.clear(); 20 | editor.apply(); 21 | } 22 | 23 | public void setStoryVisited(String uri){ 24 | editor.putBoolean(uri,true); 25 | editor.apply(); 26 | } 27 | 28 | public boolean isStoryVisited(String uri){ 29 | return preferences.getBoolean(uri,false); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /storyview/src/main/java/xute/storyview/StoryView.java: -------------------------------------------------------------------------------- 1 | package xute.storyview; 2 | 3 | import android.content.Context; 4 | import android.content.Intent; 5 | import android.content.res.Resources; 6 | import android.content.res.TypedArray; 7 | import android.graphics.Bitmap; 8 | import android.graphics.Canvas; 9 | import android.graphics.Color; 10 | import android.graphics.Paint; 11 | import android.graphics.Rect; 12 | import android.support.annotation.Nullable; 13 | import android.support.v7.app.AppCompatActivity; 14 | import android.util.AttributeSet; 15 | import android.util.TypedValue; 16 | import android.view.MotionEvent; 17 | import android.view.View; 18 | 19 | import com.bumptech.glide.Glide; 20 | import com.bumptech.glide.request.RequestOptions; 21 | import com.bumptech.glide.request.target.SimpleTarget; 22 | import com.bumptech.glide.request.transition.Transition; 23 | 24 | import java.util.ArrayList; 25 | 26 | public class StoryView extends View { 27 | public static final int STORY_IMAGE_RADIUS_IN_DP = 36; 28 | public static final int STORY_INDICATOR_WIDTH_IN_DP = 4; 29 | public static final int SPACE_BETWEEN_IMAGE_AND_INDICATOR = 4; 30 | public static final int START_ANGLE = 270; 31 | public static final String PENDING_INDICATOR_COLOR = "#009988"; 32 | public static final String VISITED_INDICATOR_COLOR = "#33009988"; 33 | public static int ANGEL_OF_GAP = 15; 34 | StoryPreference storyPreference; 35 | private int mStoryImageRadiusInPx; 36 | private int mStoryIndicatorWidthInPx; 37 | private int mSpaceBetweenImageAndIndicator; 38 | private int mPendingIndicatorColor; 39 | private int mVisistedIndicatorColor; 40 | private int mViewWidth; 41 | private int mViewHeight; 42 | private int mIndicatoryOffset; 43 | private int mIndicatorImageOffset; 44 | private Resources resources; 45 | private ArrayList storyImageUris; 46 | private Paint mIndicatorPaint; 47 | private int indicatorCount; 48 | private int indicatorSweepAngle; 49 | private Bitmap mIndicatorImageBitmap; 50 | private Rect mIndicatorImageRect; 51 | private AppCompatActivity mContext; 52 | 53 | public StoryView(Context context) { 54 | super(context); 55 | init(context); 56 | setDefaults(); 57 | } 58 | 59 | private void init(Context context) { 60 | storyPreference = new StoryPreference(context); 61 | resources = context.getResources(); 62 | storyImageUris = new ArrayList<>(); 63 | mIndicatorPaint = new Paint(); 64 | mIndicatorPaint.setAntiAlias(true); 65 | mIndicatorPaint.setStyle(Paint.Style.STROKE); 66 | mIndicatorPaint.setStrokeCap(Paint.Cap.ROUND); 67 | } 68 | 69 | private void setDefaults() { 70 | mStoryImageRadiusInPx = getPxFromDp(STORY_IMAGE_RADIUS_IN_DP); 71 | mStoryIndicatorWidthInPx = getPxFromDp(STORY_INDICATOR_WIDTH_IN_DP); 72 | mSpaceBetweenImageAndIndicator = getPxFromDp(SPACE_BETWEEN_IMAGE_AND_INDICATOR); 73 | mPendingIndicatorColor = Color.parseColor(PENDING_INDICATOR_COLOR); 74 | mVisistedIndicatorColor = Color.parseColor(VISITED_INDICATOR_COLOR); 75 | prepareValues(); 76 | } 77 | 78 | private int getPxFromDp(int dpValue) { 79 | return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dpValue, resources.getDisplayMetrics()); 80 | } 81 | 82 | private void prepareValues() { 83 | mViewHeight = 2 * (mStoryIndicatorWidthInPx + mSpaceBetweenImageAndIndicator + mStoryImageRadiusInPx); 84 | mViewWidth = mViewHeight; 85 | mIndicatoryOffset = mStoryIndicatorWidthInPx / 2; 86 | mIndicatorImageOffset = mStoryIndicatorWidthInPx + mSpaceBetweenImageAndIndicator; 87 | mIndicatorImageRect = new Rect(mIndicatorImageOffset, mIndicatorImageOffset, mViewWidth - mIndicatorImageOffset, mViewHeight - mIndicatorImageOffset); 88 | } 89 | 90 | public StoryView(Context context, @Nullable AttributeSet attrs) { 91 | super(context, attrs); 92 | init(context); 93 | TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.StoryView, 0, 0); 94 | try { 95 | mStoryImageRadiusInPx = getPxFromDp((int) ta.getDimension(R.styleable.StoryView_storyImageRadius, STORY_IMAGE_RADIUS_IN_DP)); 96 | mStoryIndicatorWidthInPx = getPxFromDp((int) ta.getDimension(R.styleable.StoryView_storyItemIndicatorWidth, STORY_INDICATOR_WIDTH_IN_DP)); 97 | mSpaceBetweenImageAndIndicator = getPxFromDp((int) ta.getDimension(R.styleable.StoryView_spaceBetweenImageAndIndicator, SPACE_BETWEEN_IMAGE_AND_INDICATOR)); 98 | mPendingIndicatorColor = ta.getColor(R.styleable.StoryView_pendingIndicatorColor, Color.parseColor(PENDING_INDICATOR_COLOR)); 99 | mVisistedIndicatorColor = ta.getColor(R.styleable.StoryView_visitedIndicatorColor, Color.parseColor(VISITED_INDICATOR_COLOR)); 100 | } 101 | finally { 102 | ta.recycle(); 103 | } 104 | prepareValues(); 105 | } 106 | 107 | public void setActivityContext(AppCompatActivity activityContext) { 108 | this.mContext = activityContext; 109 | } 110 | 111 | public void resetStoryVisits() { 112 | storyPreference.clearStoryPreferences(); 113 | } 114 | 115 | public void setImageUris(ArrayList imageUris) { 116 | this.storyImageUris = imageUris; 117 | this.indicatorCount = imageUris.size(); 118 | calculateSweepAngle(indicatorCount); 119 | invalidate(); 120 | loadFirstImageBitamp(); 121 | } 122 | 123 | private void calculateSweepAngle(int itemCounts) { 124 | if (itemCounts == 1) { 125 | ANGEL_OF_GAP = 0; 126 | } 127 | this.indicatorSweepAngle = (360 / itemCounts) - ANGEL_OF_GAP / 2; 128 | } 129 | 130 | private void loadFirstImageBitamp() { 131 | Glide.with(this) 132 | .asBitmap() 133 | .circleCrop() 134 | .load(storyImageUris.get(0).imageUri) 135 | .into(new SimpleTarget() { 136 | @Override 137 | public void onResourceReady(Bitmap resource, Transition transition) { 138 | mIndicatorImageBitmap = resource; 139 | invalidate(); 140 | } 141 | }); 142 | } 143 | 144 | @Override 145 | public boolean onTouchEvent(MotionEvent event) { 146 | if (event.getAction() == MotionEvent.ACTION_UP) { 147 | navigateToStoryPlayerPage(); 148 | return true; 149 | } 150 | return true; 151 | } 152 | 153 | private void navigateToStoryPlayerPage() { 154 | if (mContext == null) { 155 | throw new RuntimeException("Activity Context MUST not be null. You need to call StoryView.setActivityContext(activity)"); 156 | } else { 157 | Intent intent = new Intent(mContext, StoryPlayer.class); 158 | intent.putParcelableArrayListExtra(StoryPlayer.STORY_IMAGE_KEY, storyImageUris); 159 | mContext.startActivity(intent); 160 | } 161 | 162 | } 163 | 164 | @Override 165 | protected void onDraw(Canvas canvas) { 166 | super.onDraw(canvas); 167 | mIndicatorPaint.setColor(mPendingIndicatorColor); 168 | mIndicatorPaint.setStrokeWidth(mStoryIndicatorWidthInPx); 169 | int startAngle = START_ANGLE + ANGEL_OF_GAP / 2; 170 | for (int i = 0; i < indicatorCount; i++) { 171 | mIndicatorPaint.setColor(getIndicatorColor(i)); 172 | canvas.drawArc(mIndicatoryOffset, mIndicatoryOffset, mViewWidth - mIndicatoryOffset, mViewHeight - mIndicatoryOffset, startAngle, indicatorSweepAngle - ANGEL_OF_GAP / 2, false, mIndicatorPaint); 173 | startAngle += indicatorSweepAngle + ANGEL_OF_GAP / 2; 174 | } 175 | if (mIndicatorImageBitmap != null) { 176 | canvas.drawBitmap(mIndicatorImageBitmap, null, mIndicatorImageRect, null); 177 | } 178 | } 179 | 180 | private int getIndicatorColor(int index) { 181 | return storyPreference.isStoryVisited(storyImageUris.get(index).imageUri) ? mVisistedIndicatorColor : mPendingIndicatorColor; 182 | } 183 | 184 | @Override 185 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { 186 | int width = getPaddingStart() + getPaddingEnd() + mViewWidth; 187 | int height = getPaddingTop() + getPaddingBottom() + mViewHeight; 188 | int w = resolveSizeAndState(width, widthMeasureSpec, 0); 189 | int h = resolveSizeAndState(height, heightMeasureSpec, 0); 190 | setMeasuredDimension(w, h); 191 | } 192 | } 193 | -------------------------------------------------------------------------------- /storyview/src/main/res/layout/activity_story_player.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 15 | 16 | 21 | 22 | 30 | 31 | 41 | 42 | 51 | 52 | 53 | 54 | 55 | 56 | -------------------------------------------------------------------------------- /storyview/src/main/res/values/attrs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /storyview/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | StoryView 3 | 4 | -------------------------------------------------------------------------------- /storyview/src/test/java/xute/storyview/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package xute.storyview; 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() { 15 | assertEquals(4, 2 + 2); 16 | } 17 | } --------------------------------------------------------------------------------