├── .gitignore
├── README.md
├── app
├── .gitignore
├── 2019_10_16_23_01_06.gif
├── build.gradle
├── proguard-rules.pro
└── src
│ └── main
│ ├── AndroidManifest.xml
│ ├── java
│ └── jp
│ │ └── shts
│ │ └── android
│ │ └── storyprogressbar
│ │ ├── MainActivity.java
│ │ └── StoriesData.java
│ └── res
│ ├── layout
│ └── activity_main.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
├── build.gradle
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── library
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── jp
│ │ └── shts
│ │ └── android
│ │ └── storiesprogressview
│ │ └── ExampleInstrumentedTest.java
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── jp
│ │ │ └── shts
│ │ │ └── android
│ │ │ └── storiesprogressview
│ │ │ ├── PausableProgressBar.java
│ │ │ └── StoriesProgressView.java
│ └── res
│ │ ├── layout
│ │ └── pausable_progress.xml
│ │ └── values
│ │ ├── attrs.xml
│ │ ├── colors.xml
│ │ └── dimens.xml
│ └── test
│ └── java
│ └── jp
│ └── shts
│ └── android
│ └── storiesprogressview
│ └── ExampleUnitTest.java
└── settings.gradle
/.gitignore:
--------------------------------------------------------------------------------
1 | .idea/
2 | *.iml
3 | .gradle
4 | /local.properties
5 | /.idea/workspace.xml
6 | /.idea/libraries
7 | /.idea/dictionaries
8 | .DS_Store
9 | /build
10 | /captures
11 | .externalNativeBuild
12 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # StoriesProgressView
2 | A WhatsApp, Instagram, social media like story progress view with both image and video play functionality.
3 |
4 | This story progress is a modified version of [Yui Kobayashi](https://github.com/shts/StoriesProgressView)
5 |
6 | StoriesProgressView
7 | ====
8 |
9 | Library that shows a horizontal progress like Instagram stories.
10 |
11 | [](https://jitpack.io/#shts/StoriesProgressView)
12 |
13 |
14 |
15 |
16 |
17 | ^Modified by me [Ravi Shankar Singh](https://about.me/itsravishankarsingh)
18 |
19 | How to Use
20 | ----
21 |
22 | To see how a StoriesProgressView can be added to your xml layouts, check the sample project.
23 |
24 | ```xml
25 |
31 | ```
32 | Overview
33 |
34 | ```java
35 | public class MainActivity extends AppCompatActivity implements StoriesProgressView.StoriesListener {
36 |
37 | private static final int PROGRESS_COUNT = 6;
38 | private StoriesProgressView storiesProgressView;
39 | private ProgressBar mProgressBar;
40 | private LinearLayout mVideoViewLayout;
41 | private int counter = 0;
42 | private ArrayList mStoriesList = new ArrayList<>();
43 |
44 | private ArrayList mediaPlayerArrayList = new ArrayList<>();
45 |
46 | long pressTime = 0L;
47 | long limit = 500L;
48 |
49 | private View.OnTouchListener onTouchListener = new View.OnTouchListener() {
50 | @Override
51 | public boolean onTouch(View v, MotionEvent event) {
52 | switch (event.getAction()) {
53 | case MotionEvent.ACTION_DOWN:
54 | pressTime = System.currentTimeMillis();
55 | storiesProgressView.pause();
56 | return false;
57 | case MotionEvent.ACTION_UP:
58 | long now = System.currentTimeMillis();
59 | storiesProgressView.resume();
60 | return limit < now - pressTime;
61 | }
62 | return false;
63 | }
64 | };
65 |
66 | @Override
67 | protected void onCreate(Bundle savedInstanceState) {
68 | super.onCreate(savedInstanceState);
69 | getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
70 | setContentView(R.layout.activity_main);
71 | mProgressBar = findViewById(R.id.progressBar);
72 | mVideoViewLayout = findViewById(R.id.videoView);
73 | storiesProgressView = (StoriesProgressView) findViewById(R.id.stories);
74 | storiesProgressView.setStoriesCount(PROGRESS_COUNT);
75 | prepareStoriesList();
76 | storiesProgressView.setStoriesListener(this);
77 | for (int i = 0; i < mStoriesList.size(); i++) {
78 | if (mStoriesList.get(i).mimeType.contains("video")) {
79 | mediaPlayerArrayList.add(getVideoView(i));
80 | } else if (mStoriesList.get(i).mimeType.contains("image")) {
81 | mediaPlayerArrayList.add(getImageView(i));
82 | }
83 | }
84 |
85 | setStoryView(counter);
86 |
87 | // bind reverse view
88 | View reverse = findViewById(R.id.reverse);
89 | reverse.setOnClickListener(new View.OnClickListener() {
90 | @Override
91 | public void onClick(View v) {
92 | storiesProgressView.reverse();
93 | }
94 | });
95 | reverse.setOnTouchListener(onTouchListener);
96 |
97 | // bind skip view
98 | View skip = findViewById(R.id.skip);
99 | skip.setOnClickListener(new View.OnClickListener() {
100 | @Override
101 | public void onClick(View v) {
102 | storiesProgressView.skip();
103 | }
104 | });
105 | skip.setOnTouchListener(onTouchListener);
106 | }
107 |
108 | ```
109 | I have done some modifications to support videos as well for stories.
110 |
111 | ```java
112 | private void setStoryView(final int counter) {
113 | final View view = (View) mediaPlayerArrayList.get(counter);
114 | mVideoViewLayout.addView(view);
115 | if (view instanceof VideoView) {
116 | final VideoView video = (VideoView) view;
117 | video.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
118 | @Override
119 | public void onPrepared(MediaPlayer mediaPlayer) {
120 | mediaPlayer.setOnInfoListener(new MediaPlayer.OnInfoListener() {
121 | @Override
122 | public boolean onInfo(MediaPlayer mediaPlayer, int i, int i1) {
123 | Log.d("mediaStatus", "onInfo: =============>>>>>>>>>>>>>>>>>>>" + i);
124 | switch (i) {
125 | case MediaPlayer.MEDIA_INFO_VIDEO_RENDERING_START: {
126 | mProgressBar.setVisibility(View.GONE);
127 | storiesProgressView.resume();
128 | return true;
129 | }
130 | case MediaPlayer.MEDIA_INFO_BUFFERING_START: {
131 | mProgressBar.setVisibility(View.VISIBLE);
132 | storiesProgressView.pause();
133 | return true;
134 | }
135 | case MediaPlayer.MEDIA_INFO_BUFFERING_END: {
136 | mProgressBar.setVisibility(View.VISIBLE);
137 | storiesProgressView.pause();
138 | return true;
139 |
140 | }
141 | case MediaPlayer.MEDIA_ERROR_TIMED_OUT: {
142 | mProgressBar.setVisibility(View.VISIBLE);
143 | storiesProgressView.pause();
144 | return true;
145 | }
146 |
147 | case MediaPlayer.MEDIA_INFO_AUDIO_NOT_PLAYING: {
148 | mProgressBar.setVisibility(View.VISIBLE);
149 | storiesProgressView.pause();
150 | return true;
151 | }
152 | }
153 | return false;
154 | }
155 | });
156 | video.start();
157 | mProgressBar.setVisibility(View.GONE);
158 | storiesProgressView.setStoryDuration(mediaPlayer.getDuration());
159 | storiesProgressView.startStories(counter);
160 | }
161 | });
162 | } else if (view instanceof ImageView) {
163 | final ImageView image = (ImageView) view;
164 | mProgressBar.setVisibility(View.GONE);
165 | Glide.with(this).load(mStoriesList.get(counter).mediaUrl).addListener(new RequestListener() {
166 | @Override
167 | public boolean onLoadFailed(@Nullable GlideException e, Object model, Target target, boolean isFirstResource) {
168 | Toast.makeText(MainActivity.this, "Failed to load media...", Toast.LENGTH_SHORT).show();
169 | mProgressBar.setVisibility(View.GONE);
170 | return false;
171 | }
172 |
173 | @Override
174 | public boolean onResourceReady(Drawable resource, Object model, Target target, DataSource dataSource, boolean isFirstResource) {
175 | mProgressBar.setVisibility(View.GONE);
176 | storiesProgressView.setStoryDuration(5000);
177 | storiesProgressView.startStories(counter);
178 | return false;
179 | }
180 | }).into(image);
181 | }
182 | }
183 |
184 | ```
185 |
186 | Skip and Reverse story
187 | ---
188 |
189 | ```java
190 | storiesProgressView.skip();
191 | storiesProgressView.reverse();
192 | ```
193 |
194 | Pause and Resume story
195 | ---
196 |
197 |
198 | ```java
199 | storiesProgressView.pause();
200 | storiesProgressView.resume();
201 | ```
202 |
203 |
204 | Install
205 | ---
206 |
207 | Add it in your root build.gradle at the end of repositories:
208 |
209 | ```groovy
210 | allprojects {
211 | repositories {
212 | ...
213 | maven { url "https://jitpack.io" }
214 | }
215 | }
216 |
217 | ```
218 |
219 | Add the dependency
220 |
221 | ```
222 | dependencies {
223 | implementation 'com.github.shts:StoriesProgressView:3.0.0'
224 | }
225 |
226 | ```
227 |
228 | License
229 | ---
230 |
231 | ```
232 | Copyright (C) 2019 Ravi Shankar Singh
233 |
234 | Licensed under the Apache License, Version 2.0 (the "License");
235 | you may not use this file except in compliance with the License.
236 | You may obtain a copy of the License at
237 |
238 | http://www.apache.org/licenses/LICENSE-2.0
239 |
240 | Unless required by applicable law or agreed to in writing, software
241 | distributed under the License is distributed on an "AS IS" BASIS,
242 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
243 | See the License for the specific language governing permissions and
244 | limitations under the License.
245 | ```
246 |
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/app/2019_10_16_23_01_06.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ravishankarsingh1996/StoriesProgressView/73c9dbec114ca4ef21ccb40499a02956cb53f88c/app/2019_10_16_23_01_06.gif
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 27
5 | buildToolsVersion '27.0.3'
6 | defaultConfig {
7 | applicationId "jp.shts.android.storyprogressbar"
8 | minSdkVersion 21
9 | targetSdkVersion 27
10 | versionCode 1
11 | versionName "1.0"
12 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
13 | }
14 | buildTypes {
15 | release {
16 | minifyEnabled false
17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
18 | }
19 | }
20 | }
21 |
22 | dependencies {
23 | implementation project(':library')
24 | implementation 'com.android.support:appcompat-v7:27.1.1'
25 | implementation 'com.android.support.constraint:constraint-layout:1.1.3'
26 | testImplementation 'junit:junit:4.12'
27 | androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', {
28 | exclude group: 'com.android.support', module: 'support-annotations'
29 | })
30 | implementation 'com.github.bumptech.glide:glide:4.9.0'
31 | annotationProcessor 'com.github.bumptech.glide:compiler:4.9.0'
32 | }
33 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /Users/a/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 interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.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 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/app/src/main/java/jp/shts/android/storyprogressbar/MainActivity.java:
--------------------------------------------------------------------------------
1 | package jp.shts.android.storyprogressbar;
2 |
3 | import android.graphics.drawable.Drawable;
4 | import android.media.MediaPlayer;
5 | import android.net.Uri;
6 | import android.os.Bundle;
7 | import android.support.annotation.Nullable;
8 | import android.support.v7.app.AppCompatActivity;
9 | import android.util.Log;
10 | import android.view.MotionEvent;
11 | import android.view.View;
12 | import android.view.ViewGroup;
13 | import android.view.WindowManager;
14 | import android.widget.FrameLayout;
15 | import android.widget.ImageView;
16 | import android.widget.LinearLayout;
17 | import android.widget.ProgressBar;
18 | import android.widget.Toast;
19 | import android.widget.VideoView;
20 |
21 | import com.bumptech.glide.Glide;
22 | import com.bumptech.glide.load.DataSource;
23 | import com.bumptech.glide.load.engine.GlideException;
24 | import com.bumptech.glide.request.RequestListener;
25 | import com.bumptech.glide.request.target.Target;
26 |
27 | import java.util.ArrayList;
28 |
29 | import jp.shts.android.storiesprogressview.StoriesProgressView;
30 |
31 | public class MainActivity extends AppCompatActivity implements StoriesProgressView.StoriesListener {
32 |
33 | private static final int PROGRESS_COUNT = 6;
34 | private StoriesProgressView storiesProgressView;
35 | private ProgressBar mProgressBar;
36 | private LinearLayout mVideoViewLayout;
37 | private int counter = 0;
38 | private ArrayList mStoriesList = new ArrayList<>();
39 |
40 | private ArrayList mediaPlayerArrayList = new ArrayList<>();
41 |
42 | long pressTime = 0L;
43 | long limit = 500L;
44 |
45 | private View.OnTouchListener onTouchListener = new View.OnTouchListener() {
46 | @Override
47 | public boolean onTouch(View v, MotionEvent event) {
48 | switch (event.getAction()) {
49 | case MotionEvent.ACTION_DOWN:
50 | pressTime = System.currentTimeMillis();
51 | storiesProgressView.pause();
52 | return false;
53 | case MotionEvent.ACTION_UP:
54 | long now = System.currentTimeMillis();
55 | storiesProgressView.resume();
56 | return limit < now - pressTime;
57 | }
58 | return false;
59 | }
60 | };
61 |
62 | @Override
63 | protected void onCreate(Bundle savedInstanceState) {
64 | super.onCreate(savedInstanceState);
65 | getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
66 | setContentView(R.layout.activity_main);
67 | mProgressBar = findViewById(R.id.progressBar);
68 | mVideoViewLayout = findViewById(R.id.videoView);
69 | storiesProgressView = (StoriesProgressView) findViewById(R.id.stories);
70 | storiesProgressView.setStoriesCount(PROGRESS_COUNT);
71 | prepareStoriesList();
72 | storiesProgressView.setStoriesListener(this);
73 | for (int i = 0; i < mStoriesList.size(); i++) {
74 | if (mStoriesList.get(i).mimeType.contains("video")) {
75 | mediaPlayerArrayList.add(getVideoView(i));
76 | } else if (mStoriesList.get(i).mimeType.contains("image")) {
77 | mediaPlayerArrayList.add(getImageView(i));
78 | }
79 | }
80 |
81 | setStoryView(counter);
82 |
83 | // bind reverse view
84 | View reverse = findViewById(R.id.reverse);
85 | reverse.setOnClickListener(new View.OnClickListener() {
86 | @Override
87 | public void onClick(View v) {
88 | storiesProgressView.reverse();
89 | }
90 | });
91 | reverse.setOnTouchListener(onTouchListener);
92 |
93 | // bind skip view
94 | View skip = findViewById(R.id.skip);
95 | skip.setOnClickListener(new View.OnClickListener() {
96 | @Override
97 | public void onClick(View v) {
98 | storiesProgressView.skip();
99 | }
100 | });
101 | skip.setOnTouchListener(onTouchListener);
102 | }
103 |
104 | private void setStoryView(final int counter) {
105 | final View view = (View) mediaPlayerArrayList.get(counter);
106 | mVideoViewLayout.addView(view);
107 | if (view instanceof VideoView) {
108 | final VideoView video = (VideoView) view;
109 | video.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
110 | @Override
111 | public void onPrepared(MediaPlayer mediaPlayer) {
112 | mediaPlayer.setOnInfoListener(new MediaPlayer.OnInfoListener() {
113 | @Override
114 | public boolean onInfo(MediaPlayer mediaPlayer, int i, int i1) {
115 | Log.d("mediaStatus", "onInfo: =============>>>>>>>>>>>>>>>>>>>" + i);
116 | switch (i) {
117 | case MediaPlayer.MEDIA_INFO_VIDEO_RENDERING_START: {
118 | mProgressBar.setVisibility(View.GONE);
119 | storiesProgressView.resume();
120 | return true;
121 | }
122 | case MediaPlayer.MEDIA_INFO_BUFFERING_START: {
123 | mProgressBar.setVisibility(View.VISIBLE);
124 | storiesProgressView.pause();
125 | return true;
126 | }
127 | case MediaPlayer.MEDIA_INFO_BUFFERING_END: {
128 | mProgressBar.setVisibility(View.VISIBLE);
129 | storiesProgressView.pause();
130 | return true;
131 |
132 | }
133 | case MediaPlayer.MEDIA_ERROR_TIMED_OUT: {
134 | mProgressBar.setVisibility(View.VISIBLE);
135 | storiesProgressView.pause();
136 | return true;
137 | }
138 |
139 | case MediaPlayer.MEDIA_INFO_AUDIO_NOT_PLAYING: {
140 | mProgressBar.setVisibility(View.VISIBLE);
141 | storiesProgressView.pause();
142 | return true;
143 | }
144 | }
145 | return false;
146 | }
147 | });
148 | video.start();
149 | mProgressBar.setVisibility(View.GONE);
150 | storiesProgressView.setStoryDuration(mediaPlayer.getDuration());
151 | storiesProgressView.startStories(counter);
152 | }
153 | });
154 | } else if (view instanceof ImageView) {
155 | final ImageView image = (ImageView) view;
156 | mProgressBar.setVisibility(View.GONE);
157 | Glide.with(this).load(mStoriesList.get(counter).mediaUrl).addListener(new RequestListener() {
158 | @Override
159 | public boolean onLoadFailed(@Nullable GlideException e, Object model, Target target, boolean isFirstResource) {
160 | Toast.makeText(MainActivity.this, "Failed to load media...", Toast.LENGTH_SHORT).show();
161 | mProgressBar.setVisibility(View.GONE);
162 | return false;
163 | }
164 |
165 | @Override
166 | public boolean onResourceReady(Drawable resource, Object model, Target target, DataSource dataSource, boolean isFirstResource) {
167 | mProgressBar.setVisibility(View.GONE);
168 | storiesProgressView.setStoryDuration(5000);
169 | storiesProgressView.startStories(counter);
170 | return false;
171 | }
172 | }).into(image);
173 | }
174 | }
175 |
176 | private void prepareStoriesList() {
177 | mStoriesList.add(new StoriesData("https://4.bp.blogspot.com/-IvTudMG6xNs/XPlXQ7Vxl_I/AAAAAAAAVcc/rZQR7Jcvbzoor3vO_lCtMHPZG7sO3VJOgCK4BGAYYCw/s1600/1D6A0131.JPG-01.jpeg.jpg", "image/png"));
178 | mStoriesList.add(new StoriesData("https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/ElephantsDream.mp4", "video/mp4"));
179 | mStoriesList.add(new StoriesData("http://4.bp.blogspot.com/-CmDFsVPzKSk/XadSsWodkxI/AAAAAAAAWjw/BBL2XfSgz0MnNPwp2Utsj1Sd5EM7RlGGgCK4BGAYYCw/s1600/download.png", "image/png"));
180 | mStoriesList.add(new StoriesData("https://1.bp.blogspot.com/-7uvberoubSg/XKh7rdskK0I/AAAAAAAAUaM/1B4CAK5oieUYApo1s9ZifReQRihVTXPvgCLcBGAs/s1600/Screenshot%2B2019-04-06%2Bat%2B3.08.31%2BPM.png", "image/png"));
181 | mStoriesList.add(new StoriesData("https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/ForBiggerFun.mp4", "video/mp4"));
182 | mStoriesList.add(new StoriesData("https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/ForBiggerJoyrides.mp4", "video/mp4"));
183 | }
184 |
185 | private VideoView getVideoView(int position) {
186 | final VideoView video = new VideoView(this);
187 | video.setVideoPath(mStoriesList.get(position).mediaUrl);
188 | video.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
189 | return video;
190 | }
191 |
192 | private ImageView getImageView(int position) {
193 | final ImageView imageView = new ImageView(this);
194 | imageView.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
195 | return imageView;
196 | }
197 |
198 | @Override
199 | public void onNext() {
200 | storiesProgressView.destroy();
201 | mVideoViewLayout.removeAllViews();
202 | mProgressBar.setVisibility(View.VISIBLE);
203 | setStoryView(++counter);
204 | }
205 |
206 | @Override
207 | public void onPrev() {
208 | if ((counter - 1) < 0) return;
209 | storiesProgressView.destroy();
210 | mVideoViewLayout.removeAllViews();
211 | mProgressBar.setVisibility(View.VISIBLE);
212 | setStoryView(--counter);
213 | }
214 |
215 | @Override
216 | public void onComplete() {
217 | finish();
218 | }
219 |
220 | @Override
221 | protected void onDestroy() {
222 | // Very important !
223 | storiesProgressView.destroy();
224 | super.onDestroy();
225 | }
226 | }
227 |
--------------------------------------------------------------------------------
/app/src/main/java/jp/shts/android/storyprogressbar/StoriesData.java:
--------------------------------------------------------------------------------
1 | package jp.shts.android.storyprogressbar;
2 |
3 | public class StoriesData {
4 |
5 | public StoriesData(String mediaUrl, String mimeType) {
6 | this.mediaUrl = mediaUrl;
7 | this.mimeType = mimeType;
8 | }
9 |
10 | public String mediaUrl;
11 | public String mimeType;
12 | }
13 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
7 |
13 |
14 |
15 |
16 |
20 |
21 |
26 |
27 |
28 |
33 |
34 |
39 |
40 |
45 |
46 |
47 |
55 |
56 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ravishankarsingh1996/StoriesProgressView/73c9dbec114ca4ef21ccb40499a02956cb53f88c/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ravishankarsingh1996/StoriesProgressView/73c9dbec114ca4ef21ccb40499a02956cb53f88c/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ravishankarsingh1996/StoriesProgressView/73c9dbec114ca4ef21ccb40499a02956cb53f88c/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ravishankarsingh1996/StoriesProgressView/73c9dbec114ca4ef21ccb40499a02956cb53f88c/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ravishankarsingh1996/StoriesProgressView/73c9dbec114ca4ef21ccb40499a02956cb53f88c/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ravishankarsingh1996/StoriesProgressView/73c9dbec114ca4ef21ccb40499a02956cb53f88c/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ravishankarsingh1996/StoriesProgressView/73c9dbec114ca4ef21ccb40499a02956cb53f88c/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ravishankarsingh1996/StoriesProgressView/73c9dbec114ca4ef21ccb40499a02956cb53f88c/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ravishankarsingh1996/StoriesProgressView/73c9dbec114ca4ef21ccb40499a02956cb53f88c/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ravishankarsingh1996/StoriesProgressView/73c9dbec114ca4ef21ccb40499a02956cb53f88c/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #9E9E9E
4 | #616161
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | StoryProgressBar
3 |
4 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 | repositories {
5 | jcenter()
6 | mavenCentral()
7 | google()
8 | }
9 | dependencies {
10 | classpath 'com.android.tools.build:gradle:3.1.4'
11 | classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5'
12 | // NOTE: Do not place your application dependencies here; they belong
13 | // in the individual module build.gradle files
14 | }
15 | }
16 |
17 | allprojects {
18 | repositories {
19 | jcenter()
20 | google()
21 | }
22 | }
23 |
24 | task clean(type: Delete) {
25 | delete rootProject.buildDir
26 | }
27 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ravishankarsingh1996/StoriesProgressView/73c9dbec114ca4ef21ccb40499a02956cb53f88c/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Mon Sep 10 10:57:05 WEST 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 bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/library/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/library/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 |
3 | android {
4 | compileSdkVersion 27
5 | buildToolsVersion '27.0.3'
6 |
7 | defaultConfig {
8 | minSdkVersion 15
9 | targetSdkVersion 27
10 | versionCode 1
11 | versionName "1.0"
12 |
13 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
14 |
15 | }
16 | buildTypes {
17 | release {
18 | minifyEnabled false
19 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
20 | }
21 | }
22 | }
23 |
24 | dependencies {
25 | implementation 'com.android.support:appcompat-v7:27.1.1'
26 | testImplementation 'junit:junit:4.12'
27 | androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', {
28 | exclude group: 'com.android.support', module: 'support-annotations'
29 | })
30 | }
31 |
--------------------------------------------------------------------------------
/library/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /Users/a/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 interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.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 |
--------------------------------------------------------------------------------
/library/src/androidTest/java/jp/shts/android/storiesprogressview/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package jp.shts.android.storiesprogressview;
2 |
3 | import android.content.Context;
4 | import android.support.test.InstrumentationRegistry;
5 | import android.support.test.runner.AndroidJUnit4;
6 |
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 |
10 | import static org.junit.Assert.*;
11 |
12 | /**
13 | * Instrumentation test, which will execute on an Android device.
14 | *
15 | * @see Testing documentation
16 | */
17 | @RunWith(AndroidJUnit4.class)
18 | public class ExampleInstrumentedTest {
19 | @Test
20 | public void useAppContext() throws Exception {
21 | // Context of the app under test.
22 | Context appContext = InstrumentationRegistry.getTargetContext();
23 |
24 | assertEquals("jp.shts.android.storiesprogressview.test", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/library/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/library/src/main/java/jp/shts/android/storiesprogressview/PausableProgressBar.java:
--------------------------------------------------------------------------------
1 | package jp.shts.android.storiesprogressview;
2 |
3 | import android.content.Context;
4 | import android.support.annotation.AttrRes;
5 | import android.support.annotation.NonNull;
6 | import android.support.annotation.Nullable;
7 | import android.util.AttributeSet;
8 | import android.view.LayoutInflater;
9 | import android.view.View;
10 | import android.view.animation.Animation;
11 | import android.view.animation.LinearInterpolator;
12 | import android.view.animation.ScaleAnimation;
13 | import android.view.animation.Transformation;
14 | import android.widget.FrameLayout;
15 |
16 | final class PausableProgressBar extends FrameLayout {
17 |
18 | /***
19 | * progress
20 | */
21 | private static final int DEFAULT_PROGRESS_DURATION = 200000;
22 |
23 | private View frontProgressView;
24 | private View maxProgressView;
25 |
26 | private PausableScaleAnimation animation;
27 | private long duration = DEFAULT_PROGRESS_DURATION;
28 | private Callback callback;
29 |
30 | interface Callback {
31 | void onStartProgress();
32 | void onFinishProgress();
33 | }
34 |
35 | public PausableProgressBar(Context context) {
36 | this(context, null);
37 | }
38 |
39 | public PausableProgressBar(@NonNull Context context, @Nullable AttributeSet attrs) {
40 | this(context, attrs, 0);
41 | }
42 |
43 | public PausableProgressBar(@NonNull Context context, @Nullable AttributeSet attrs, @AttrRes int defStyleAttr) {
44 | super(context, attrs, defStyleAttr);
45 | LayoutInflater.from(context).inflate(R.layout.pausable_progress, this);
46 | frontProgressView = findViewById(R.id.front_progress);
47 | maxProgressView = findViewById(R.id.max_progress); // work around
48 | }
49 |
50 | public void setDuration(long duration) {
51 | this.duration = duration;
52 | }
53 |
54 | public void setCallback(@NonNull Callback callback) {
55 | this.callback = callback;
56 | }
57 |
58 | void setMax() {
59 | finishProgress(true);
60 | }
61 |
62 | void setMin() {
63 | finishProgress(false);
64 | }
65 |
66 | void setMinWithoutCallback() {
67 | maxProgressView.setBackgroundResource(R.color.progress_secondary);
68 |
69 | maxProgressView.setVisibility(VISIBLE);
70 | if (animation != null) {
71 | animation.setAnimationListener(null);
72 | animation.cancel();
73 | }
74 | }
75 |
76 | void setMaxWithoutCallback() {
77 | maxProgressView.setBackgroundResource(R.color.progress_max_active);
78 |
79 | maxProgressView.setVisibility(VISIBLE);
80 | if (animation != null) {
81 | animation.setAnimationListener(null);
82 | animation.cancel();
83 | }
84 | }
85 |
86 | private void finishProgress(boolean isMax) {
87 | if (isMax) maxProgressView.setBackgroundResource(R.color.progress_max_active);
88 | maxProgressView.setVisibility(isMax ? VISIBLE : GONE);
89 | if (animation != null) {
90 | animation.setAnimationListener(null);
91 | animation.cancel();
92 | if (callback != null) {
93 | callback.onFinishProgress();
94 | }
95 | }
96 | }
97 |
98 | public void startProgress() {
99 | maxProgressView.setVisibility(GONE);
100 |
101 | animation = new PausableScaleAnimation(0, 1, 1, 1, Animation.ABSOLUTE, 0, Animation.RELATIVE_TO_SELF, 0);
102 | animation.setDuration(duration);
103 | animation.setInterpolator(new LinearInterpolator());
104 | animation.setAnimationListener(new Animation.AnimationListener() {
105 | @Override
106 | public void onAnimationStart(Animation animation) {
107 | frontProgressView.setVisibility(View.VISIBLE);
108 | if (callback != null) callback.onStartProgress();
109 | }
110 |
111 | @Override
112 | public void onAnimationRepeat(Animation animation) {
113 | }
114 |
115 | @Override
116 | public void onAnimationEnd(Animation animation) {
117 | if (callback != null) callback.onFinishProgress();
118 | }
119 | });
120 | animation.setFillAfter(true);
121 | frontProgressView.startAnimation(animation);
122 | }
123 |
124 | public void pauseProgress() {
125 | if (animation != null) {
126 | animation.pause();
127 | }
128 | }
129 |
130 | public void resumeProgress() {
131 | if (animation != null) {
132 | animation.resume();
133 | }
134 | }
135 |
136 | void clear() {
137 | if (animation != null) {
138 | animation.setAnimationListener(null);
139 | animation.cancel();
140 | animation = null;
141 | }
142 | }
143 |
144 | private class PausableScaleAnimation extends ScaleAnimation {
145 |
146 | private long mElapsedAtPause = 0;
147 | private boolean mPaused = false;
148 |
149 | PausableScaleAnimation(float fromX, float toX, float fromY,
150 | float toY, int pivotXType, float pivotXValue, int pivotYType,
151 | float pivotYValue) {
152 | super(fromX, toX, fromY, toY, pivotXType, pivotXValue, pivotYType,
153 | pivotYValue);
154 | }
155 |
156 | @Override
157 | public boolean getTransformation(long currentTime, Transformation outTransformation, float scale) {
158 | if (mPaused && mElapsedAtPause == 0) {
159 | mElapsedAtPause = currentTime - getStartTime();
160 | }
161 | if (mPaused) {
162 | setStartTime(currentTime - mElapsedAtPause);
163 | }
164 | return super.getTransformation(currentTime, outTransformation, scale);
165 | }
166 |
167 | /***
168 | * pause animation
169 | */
170 | void pause() {
171 | if (mPaused) return;
172 | mElapsedAtPause = 0;
173 | mPaused = true;
174 | }
175 |
176 | /***
177 | * resume animation
178 | */
179 | void resume() {
180 | mPaused = false;
181 | }
182 | }
183 | }
184 |
--------------------------------------------------------------------------------
/library/src/main/java/jp/shts/android/storiesprogressview/StoriesProgressView.java:
--------------------------------------------------------------------------------
1 | package jp.shts.android.storiesprogressview;
2 |
3 | import android.annotation.TargetApi;
4 | import android.content.Context;
5 | import android.content.res.TypedArray;
6 | import android.os.Build;
7 | import android.support.annotation.NonNull;
8 | import android.support.annotation.Nullable;
9 | import android.util.AttributeSet;
10 | import android.view.View;
11 | import android.widget.LinearLayout;
12 |
13 | import java.util.ArrayList;
14 | import java.util.List;
15 |
16 | public class StoriesProgressView extends LinearLayout {
17 |
18 | private static final String TAG = StoriesProgressView.class.getSimpleName();
19 |
20 | private final LayoutParams PROGRESS_BAR_LAYOUT_PARAM = new LayoutParams(0, LayoutParams.WRAP_CONTENT, 1);
21 | private final LayoutParams SPACE_LAYOUT_PARAM = new LayoutParams(5, LayoutParams.WRAP_CONTENT);
22 |
23 | private final List progressBars = new ArrayList<>();
24 |
25 | private int storiesCount = -1;
26 | /**
27 | * pointer of running animation
28 | */
29 | private int current = -1;
30 | private StoriesListener storiesListener;
31 | boolean isComplete;
32 |
33 | private boolean isSkipStart;
34 | private boolean isReverseStart;
35 |
36 | public interface StoriesListener {
37 | void onNext();
38 |
39 | void onPrev();
40 |
41 | void onComplete();
42 | }
43 |
44 | public StoriesProgressView(Context context) {
45 | this(context, null);
46 | }
47 |
48 | public StoriesProgressView(Context context, @Nullable AttributeSet attrs) {
49 | super(context, attrs);
50 | init(context, attrs);
51 | }
52 |
53 | public StoriesProgressView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
54 | super(context, attrs, defStyleAttr);
55 | init(context, attrs);
56 | }
57 |
58 | @TargetApi(Build.VERSION_CODES.LOLLIPOP)
59 | public StoriesProgressView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
60 | super(context, attrs, defStyleAttr, defStyleRes);
61 | init(context, attrs);
62 | }
63 |
64 | private void init(Context context, @Nullable AttributeSet attrs) {
65 | setOrientation(LinearLayout.HORIZONTAL);
66 | TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.StoriesProgressView);
67 | storiesCount = typedArray.getInt(R.styleable.StoriesProgressView_progressCount, 0);
68 | typedArray.recycle();
69 | bindViews();
70 | }
71 |
72 | private void bindViews() {
73 | progressBars.clear();
74 | removeAllViews();
75 |
76 | for (int i = 0; i < storiesCount; i++) {
77 | final PausableProgressBar p = createProgressBar();
78 | progressBars.add(p);
79 | addView(p);
80 | if ((i + 1) < storiesCount) {
81 | addView(createSpace());
82 | }
83 | }
84 | }
85 |
86 | private PausableProgressBar createProgressBar() {
87 | PausableProgressBar p = new PausableProgressBar(getContext());
88 | p.setLayoutParams(PROGRESS_BAR_LAYOUT_PARAM);
89 | return p;
90 | }
91 |
92 | private View createSpace() {
93 | View v = new View(getContext());
94 | v.setLayoutParams(SPACE_LAYOUT_PARAM);
95 | return v;
96 | }
97 |
98 | /**
99 | * Set story count and create views
100 | *
101 | * @param storiesCount story count
102 | */
103 | public void setStoriesCount(int storiesCount) {
104 | this.storiesCount = storiesCount;
105 | bindViews();
106 | }
107 |
108 | /**
109 | * Set storiesListener
110 | *
111 | * @param storiesListener StoriesListener
112 | */
113 | public void setStoriesListener(StoriesListener storiesListener) {
114 | this.storiesListener = storiesListener;
115 | }
116 |
117 | /**
118 | * Skip current story
119 | */
120 | public void skip() {
121 | if (isSkipStart || isReverseStart) return;
122 | if (isComplete) return;
123 | if (current < 0) return;
124 | PausableProgressBar p = progressBars.get(current);
125 | isSkipStart = true;
126 | p.setMax();
127 | }
128 |
129 | /**
130 | * Reverse current story
131 | */
132 | public void reverse() {
133 | if (isSkipStart || isReverseStart) return;
134 | if (isComplete) return;
135 | if (current < 0) return;
136 | PausableProgressBar p = progressBars.get(current);
137 | isReverseStart = true;
138 | p.setMin();
139 | }
140 |
141 | /**
142 | * Set a story's duration
143 | *
144 | * @param duration millisecond
145 | */
146 | public void setStoryDuration(long duration) {
147 | for (int i = 0; i < progressBars.size(); i++) {
148 | progressBars.get(i).setDuration(duration);
149 | progressBars.get(i).setCallback(callback(i));
150 | }
151 | }
152 |
153 | /**
154 | * Set stories count and each story duration
155 | *
156 | * @param durations milli
157 | */
158 | public void setStoriesCountWithDurations(@NonNull long[] durations) {
159 | storiesCount = durations.length;
160 | bindViews();
161 | for (int i = 0; i < progressBars.size(); i++) {
162 | progressBars.get(i).setDuration(durations[i]);
163 | progressBars.get(i).setCallback(callback(i));
164 | }
165 | }
166 |
167 | private PausableProgressBar.Callback callback(final int index) {
168 | return new PausableProgressBar.Callback() {
169 | @Override
170 | public void onStartProgress() {
171 | current = index;
172 | }
173 |
174 | @Override
175 | public void onFinishProgress() {
176 | if (isReverseStart) {
177 | if (storiesListener != null) storiesListener.onPrev();
178 | if (0 <= (current - 1)) {
179 | PausableProgressBar p = progressBars.get(current - 1);
180 | p.setMinWithoutCallback();
181 | progressBars.get(--current).startProgress();
182 | } else {
183 | progressBars.get(current).startProgress();
184 | }
185 | isReverseStart = false;
186 | return;
187 | }
188 | int next = current + 1;
189 | if (next <= (progressBars.size() - 1)) {
190 | if (storiesListener != null) storiesListener.onNext();
191 | progressBars.get(next).startProgress();
192 | } else {
193 | isComplete = true;
194 | if (storiesListener != null) storiesListener.onComplete();
195 | }
196 | isSkipStart = false;
197 | }
198 | };
199 | }
200 |
201 | /**
202 | * Start progress animation
203 | */
204 | public void startStories() {
205 | progressBars.get(0).startProgress();
206 | }
207 |
208 | /**
209 | * Start progress animation from specific progress
210 | */
211 | public void startStories(int from) {
212 | for (int i = 0; i < from; i++) {
213 | progressBars.get(i).setMaxWithoutCallback();
214 | }
215 | progressBars.get(from).startProgress();
216 | }
217 |
218 | /**
219 | * Need to call when Activity or Fragment destroy
220 | */
221 | public void destroy() {
222 | for (PausableProgressBar p : progressBars) {
223 | p.clear();
224 | }
225 | }
226 |
227 | /**
228 | * Pause story
229 | */
230 | public void pause() {
231 | if (current < 0) return;
232 | progressBars.get(current).pauseProgress();
233 | }
234 |
235 | /**
236 | * Resume story
237 | */
238 | public void resume() {
239 | if (current < 0) return;
240 | progressBars.get(current).resumeProgress();
241 | }
242 | }
243 |
--------------------------------------------------------------------------------
/library/src/main/res/layout/pausable_progress.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
12 |
13 |
20 |
21 |
27 |
28 |
--------------------------------------------------------------------------------
/library/src/main/res/values/attrs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/library/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | @color/white
5 | @color/gray_scale
6 | @color/white
7 |
8 | #8affffff
9 | #fff
10 |
11 |
--------------------------------------------------------------------------------
/library/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 2dp
4 |
--------------------------------------------------------------------------------
/library/src/test/java/jp/shts/android/storiesprogressview/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package jp.shts.android.storiesprogressview;
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 | }
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app', ':library'
2 |
--------------------------------------------------------------------------------