├── app
├── .gitignore
├── src
│ ├── main
│ │ ├── res
│ │ │ ├── drawable-hdpi
│ │ │ │ ├── ic_drawer.png
│ │ │ │ └── drawer_shadow.9.png
│ │ │ ├── drawable-mdpi
│ │ │ │ ├── ic_drawer.png
│ │ │ │ └── drawer_shadow.9.png
│ │ │ ├── drawable-xhdpi
│ │ │ │ ├── ic_drawer.png
│ │ │ │ └── drawer_shadow.9.png
│ │ │ ├── drawable-xxhdpi
│ │ │ │ ├── speakers.jpg
│ │ │ │ ├── ic_drawer.png
│ │ │ │ ├── drawer_shadow.9.png
│ │ │ │ ├── avatar_placeholder.png
│ │ │ │ └── icon_active_conversation.png
│ │ │ ├── mipmap-hdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-mdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xxhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── values-v21
│ │ │ │ └── styles.xml
│ │ │ ├── drawable
│ │ │ │ ├── shape_dark_circle.xml
│ │ │ │ ├── branch_minified_grow_source.xml
│ │ │ │ ├── branch_minified_grow_leave1.xml
│ │ │ │ ├── branch_minified_grow_leave2.xml
│ │ │ │ ├── branch_minified_grow_leave3.xml
│ │ │ │ ├── branch_minified_grow_leave4.xml
│ │ │ │ ├── branch_minified_grow_leave5.xml
│ │ │ │ ├── branch_minified_grow_leave6.xml
│ │ │ │ ├── branch_minified_grow_leave7.xml
│ │ │ │ ├── branch_minified_grow_leave8.xml
│ │ │ │ ├── branch_minified_grow_leave9.xml
│ │ │ │ ├── branch_minified_grow_branch1.xml
│ │ │ │ ├── branch_minified_grow_branch2.xml
│ │ │ │ ├── branch_minified_grow_branch3.xml
│ │ │ │ ├── branch_minified_grow_branch4.xml
│ │ │ │ ├── branch_minified_grow_branch5.xml
│ │ │ │ ├── branch_minified_grow_branch6.xml
│ │ │ │ ├── circle_stroke_animated_show.xml
│ │ │ │ ├── circle_stroke_animated_hide.xml
│ │ │ │ ├── branch_minified_swipe_refresh_branch2.xml
│ │ │ │ ├── branch_minified_swipe_refresh_branch6.xml
│ │ │ │ ├── branch_minified_swipe_refresh_branch3.xml
│ │ │ │ ├── branch_minified_swipe_refresh_branch4.xml
│ │ │ │ ├── branch_minified_swipe_refresh_branch5.xml
│ │ │ │ ├── branch_minified_swipe_refresh_branch1.xml
│ │ │ │ ├── circle_stroke.xml
│ │ │ │ ├── branch_minified_swipe_refresh_dot.xml
│ │ │ │ ├── branch_minified_swipe_refresh_leave2.xml
│ │ │ │ ├── branch_minified_swipe_refresh_leave8.xml
│ │ │ │ ├── branch_minified_swipe_refresh_leave9.xml
│ │ │ │ ├── branch_minified_swipe_refresh_leave3.xml
│ │ │ │ ├── branch_minified_swipe_refresh_leave1.xml
│ │ │ │ ├── branch_minified_swipe_refresh_leave4.xml
│ │ │ │ ├── branch_minified_swipe_refresh_leave5.xml
│ │ │ │ ├── branch_minified_swipe_refresh_leave6.xml
│ │ │ │ └── branch_minified_swipe_refresh_leave7.xml
│ │ │ ├── menu
│ │ │ │ ├── global.xml
│ │ │ │ └── main.xml
│ │ │ ├── values
│ │ │ │ ├── styles.xml
│ │ │ │ ├── strings.xml
│ │ │ │ ├── attrs.xml
│ │ │ │ ├── colors.xml
│ │ │ │ └── dimens.xml
│ │ │ ├── values-w820dp
│ │ │ │ └── dimens.xml
│ │ │ ├── layout
│ │ │ │ ├── view_viewpager_header_textview.xml
│ │ │ │ ├── fragment_navigation_drawer.xml
│ │ │ │ ├── item_list.xml
│ │ │ │ ├── fragment_viewpager_container.xml
│ │ │ │ ├── fragment_placeholder.xml
│ │ │ │ ├── activity_main.xml
│ │ │ │ ├── fragment_viewpager.xml
│ │ │ │ ├── fragment_static_header_list.xml
│ │ │ │ ├── view_recyclerview_header.xml
│ │ │ │ ├── fragment_dynamic_header_list.xml
│ │ │ │ └── fragment_slidinglayer.xml
│ │ │ └── animator
│ │ │ │ ├── shape_pop.xml
│ │ │ │ ├── stroke_appear_from_end.xml
│ │ │ │ ├── stroke_appear_from_center.xml
│ │ │ │ └── stroke_disappear_to_center.xml
│ │ ├── java
│ │ │ └── ugia
│ │ │ │ └── io
│ │ │ │ └── androidbeautytreatment
│ │ │ │ ├── viewcontroller
│ │ │ │ ├── fragment
│ │ │ │ │ ├── ClickableViewController.java
│ │ │ │ │ ├── TaggableFragment.java
│ │ │ │ │ ├── ViewPagerTextViewFragment.java
│ │ │ │ │ ├── SlidingLayerFragment.java
│ │ │ │ │ ├── ViewPagerFragment.java
│ │ │ │ │ ├── NavigationDrawerFragment.java
│ │ │ │ │ ├── DynamicHeaderListFragment.java
│ │ │ │ │ └── StaticHeaderListFragment.java
│ │ │ │ ├── adapter
│ │ │ │ │ ├── ViewPagerAdapter.java
│ │ │ │ │ ├── ContactAdapter.java
│ │ │ │ │ ├── HeaderContactListAdapter.java
│ │ │ │ │ ├── ContactListAdapter.java
│ │ │ │ │ └── FragmentPagerAdapter.java
│ │ │ │ └── activity
│ │ │ │ │ └── MainActivity.java
│ │ │ │ ├── util
│ │ │ │ ├── ColorUtils.java
│ │ │ │ ├── Poets.java
│ │ │ │ └── Transitions.java
│ │ │ │ ├── model
│ │ │ │ └── Contact.java
│ │ │ │ └── view
│ │ │ │ ├── ClippedImageView.java
│ │ │ │ └── NoisySwipeRefreshLayout.java
│ │ └── AndroidManifest.xml
│ └── androidTest
│ │ └── java
│ │ └── ugia
│ │ └── io
│ │ └── androidbeautytreatment
│ │ └── ApplicationTest.java
├── proguard-rules.pro
└── build.gradle
├── settings.gradle
├── assets
├── swiperefresh.gif
├── listviewpathexample.gif
├── slidinglayerparty.gif
└── viewpagerslidejoy.gif
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── .gitignore
├── README.md
├── gradle.properties
├── gradlew.bat
├── gradlew
└── LICENSE
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
2 |
--------------------------------------------------------------------------------
/assets/swiperefresh.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JlUgia/beauty-treatment-android-animations/HEAD/assets/swiperefresh.gif
--------------------------------------------------------------------------------
/assets/listviewpathexample.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JlUgia/beauty-treatment-android-animations/HEAD/assets/listviewpathexample.gif
--------------------------------------------------------------------------------
/assets/slidinglayerparty.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JlUgia/beauty-treatment-android-animations/HEAD/assets/slidinglayerparty.gif
--------------------------------------------------------------------------------
/assets/viewpagerslidejoy.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JlUgia/beauty-treatment-android-animations/HEAD/assets/viewpagerslidejoy.gif
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JlUgia/beauty-treatment-android-animations/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/app/src/main/res/drawable-hdpi/ic_drawer.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JlUgia/beauty-treatment-android-animations/HEAD/app/src/main/res/drawable-hdpi/ic_drawer.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-mdpi/ic_drawer.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JlUgia/beauty-treatment-android-animations/HEAD/app/src/main/res/drawable-mdpi/ic_drawer.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/ic_drawer.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JlUgia/beauty-treatment-android-animations/HEAD/app/src/main/res/drawable-xhdpi/ic_drawer.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/speakers.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JlUgia/beauty-treatment-android-animations/HEAD/app/src/main/res/drawable-xxhdpi/speakers.jpg
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JlUgia/beauty-treatment-android-animations/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JlUgia/beauty-treatment-android-animations/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JlUgia/beauty-treatment-android-animations/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/ic_drawer.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JlUgia/beauty-treatment-android-animations/HEAD/app/src/main/res/drawable-xxhdpi/ic_drawer.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JlUgia/beauty-treatment-android-animations/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-hdpi/drawer_shadow.9.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JlUgia/beauty-treatment-android-animations/HEAD/app/src/main/res/drawable-hdpi/drawer_shadow.9.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-mdpi/drawer_shadow.9.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JlUgia/beauty-treatment-android-animations/HEAD/app/src/main/res/drawable-mdpi/drawer_shadow.9.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/drawer_shadow.9.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JlUgia/beauty-treatment-android-animations/HEAD/app/src/main/res/drawable-xhdpi/drawer_shadow.9.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/drawer_shadow.9.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JlUgia/beauty-treatment-android-animations/HEAD/app/src/main/res/drawable-xxhdpi/drawer_shadow.9.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/avatar_placeholder.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JlUgia/beauty-treatment-android-animations/HEAD/app/src/main/res/drawable-xxhdpi/avatar_placeholder.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/icon_active_conversation.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JlUgia/beauty-treatment-android-animations/HEAD/app/src/main/res/drawable-xxhdpi/icon_active_conversation.png
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Wed Sep 16 21:58:55 CEST 2015
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.4-all.zip
7 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Built application files
2 | *.apk
3 | *.ap_
4 |
5 | # Files for the Dalvik VM
6 | *.dex
7 |
8 | # Java class files
9 | *.class
10 |
11 | # Generated files
12 | bin/
13 | gen/
14 |
15 | # Gradle files
16 | .gradle/
17 | build/
18 | /*/build/
19 |
20 | # Local configuration file (sdk path, etc)
21 | local.properties
22 |
23 | # Proguard folder generated by Eclipse
24 | proguard/
25 |
26 | # Log Files
27 | *.log
28 | *.iml
29 | .idea
30 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/ugia/io/androidbeautytreatment/ApplicationTest.java:
--------------------------------------------------------------------------------
1 | package ugia.io.androidbeautytreatment;
2 |
3 | import android.app.Application;
4 | import android.test.ApplicationTestCase;
5 |
6 | /**
7 | * Testing Fundamentals
8 | */
9 | public class ApplicationTest extends ApplicationTestCase {
10 | public ApplicationTest() {
11 | super(Application.class);
12 | }
13 | }
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # beauty-treatment-android-animations
2 | Set of samples of views with slick interaction patterns and animations
3 |
4 | Screenshots
5 | -----------
6 |
7 | ![Demo Screenshot 1][1]
8 | ![Demo Screenshot 2][2]
9 | ![Demo Screenshot 4][3]
10 | ![Demo Screenshot 3][4]
11 |
12 | [1]: ./assets/swiperefresh.gif
13 | [2]: ./assets/slidinglayerparty.gif
14 | [3]: ./assets/listviewpathexample.gif
15 | [4]: ./assets/viewpagerslidejoy.gif
16 |
17 |
18 | Seen on:
19 |
20 | [](https://android-arsenal.com/details/3/2611)
21 |
--------------------------------------------------------------------------------
/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/joseluisugia/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 |
--------------------------------------------------------------------------------
/app/src/main/res/values-v21/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 |
19 |
21 |
22 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m
13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
14 |
15 | # When configured, Gradle will run in incubating parallel mode.
16 | # This option should only be used with decoupled projects. More details, visit
17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
18 | # org.gradle.parallel=true
--------------------------------------------------------------------------------
/app/src/main/res/drawable/shape_dark_circle.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 23
5 | buildToolsVersion "23.0.1"
6 |
7 | defaultConfig {
8 | applicationId "ugia.io.androidbeautytreatment"
9 | minSdkVersion 21
10 | targetSdkVersion 23
11 | versionCode 1
12 | versionName "1.0"
13 | }
14 | buildTypes {
15 | release {
16 | minifyEnabled false
17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
18 | }
19 | }
20 | }
21 |
22 | dependencies {
23 | compile fileTree(dir: 'libs', include: ['*.jar'])
24 |
25 | compile 'com.wunderlist:sliding-layer:1.2.5'
26 |
27 | compile 'com.android.support:recyclerview-v7:23.0.1'
28 | compile 'com.android.support:appcompat-v7:23.0.1'
29 | compile 'com.android.support:design:23.0.1'
30 | compile 'com.android.support:support-v4:23.0.1'
31 | }
32 |
--------------------------------------------------------------------------------
/app/src/main/res/menu/global.xml:
--------------------------------------------------------------------------------
1 |
16 |
17 |
23 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 |
19 |
20 |
21 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/app/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
16 |
17 |
18 |
21 | 64dp
22 |
23 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/branch_minified_grow_source.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 |
21 |
22 |
25 |
26 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/branch_minified_grow_leave1.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 |
21 |
22 |
25 |
26 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/branch_minified_grow_leave2.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 |
21 |
22 |
25 |
26 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/branch_minified_grow_leave3.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 |
21 |
22 |
25 |
26 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/branch_minified_grow_leave4.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 |
21 |
22 |
25 |
26 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/branch_minified_grow_leave5.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 |
21 |
22 |
25 |
26 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/branch_minified_grow_leave6.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 |
21 |
22 |
25 |
26 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/branch_minified_grow_leave7.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 |
21 |
22 |
25 |
26 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/branch_minified_grow_leave8.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 |
21 |
22 |
25 |
26 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/branch_minified_grow_leave9.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 |
21 |
22 |
25 |
26 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/branch_minified_grow_branch1.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 |
21 |
22 |
25 |
26 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/branch_minified_grow_branch2.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 |
21 |
22 |
25 |
26 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/branch_minified_grow_branch3.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 |
21 |
22 |
25 |
26 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/branch_minified_grow_branch4.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 |
21 |
22 |
25 |
26 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/branch_minified_grow_branch5.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 |
21 |
22 |
25 |
26 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/branch_minified_grow_branch6.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 |
21 |
22 |
25 |
26 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/view_viewpager_header_textview.xml:
--------------------------------------------------------------------------------
1 |
16 |
17 |
--------------------------------------------------------------------------------
/app/src/main/java/ugia/io/androidbeautytreatment/viewcontroller/fragment/ClickableViewController.java:
--------------------------------------------------------------------------------
1 | /*
2 | * ClickableViewController.java
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package ugia.io.androidbeautytreatment.viewcontroller.fragment;
18 |
19 | import android.view.View;
20 |
21 | /**
22 | * This interface enforces the fact that classes implementing it can accept click events on sub views contained
23 | * within the view group.
24 | *
25 | * Created by joseluisugia on 01/10/15.
26 | */
27 | public interface ClickableViewController {
28 |
29 | void buttonClicked(View view);
30 | }
31 |
--------------------------------------------------------------------------------
/app/src/main/res/animator/shape_pop.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 |
21 |
22 |
29 |
30 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_navigation_drawer.xml:
--------------------------------------------------------------------------------
1 |
16 |
17 |
26 |
--------------------------------------------------------------------------------
/app/src/main/res/menu/main.xml:
--------------------------------------------------------------------------------
1 |
16 |
17 |
28 |
--------------------------------------------------------------------------------
/app/src/main/res/animator/stroke_appear_from_end.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 |
21 |
22 |
29 |
30 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/circle_stroke_animated_show.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 |
21 |
22 |
25 |
26 |
29 |
30 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/circle_stroke_animated_hide.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 |
21 |
22 |
25 |
26 |
29 |
30 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
16 |
17 |
18 | Android Beauty Treatment
19 |
20 | Active View Pager
21 | Artistic Recycler View
22 | Creative Recycler View
23 | Composed Sliding Layer
24 |
25 | Open navigation drawer
26 | Close navigation drawer
27 |
28 | Example action
29 |
30 | Settings
31 |
32 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/item_list.xml:
--------------------------------------------------------------------------------
1 |
16 |
17 |
20 |
21 |
31 |
32 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_viewpager_container.xml:
--------------------------------------------------------------------------------
1 |
16 |
17 |
21 |
22 |
31 |
32 |
--------------------------------------------------------------------------------
/app/src/main/res/values/attrs.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/branch_minified_swipe_refresh_branch2.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 |
23 |
24 |
25 |
26 |
33 |
34 |
35 |
36 |
37 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/branch_minified_swipe_refresh_branch6.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 |
23 |
24 |
25 |
26 |
33 |
34 |
35 |
36 |
37 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/branch_minified_swipe_refresh_branch3.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 |
23 |
24 |
25 |
26 |
27 |
34 |
35 |
36 |
37 |
38 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/branch_minified_swipe_refresh_branch4.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 |
23 |
24 |
25 |
26 |
27 |
34 |
35 |
36 |
37 |
38 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/branch_minified_swipe_refresh_branch5.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 |
23 |
24 |
25 |
26 |
27 |
34 |
35 |
36 |
37 |
38 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/branch_minified_swipe_refresh_branch1.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 |
23 |
24 |
25 |
26 |
27 |
34 |
35 |
36 |
37 |
38 |
--------------------------------------------------------------------------------
/app/src/main/java/ugia/io/androidbeautytreatment/util/ColorUtils.java:
--------------------------------------------------------------------------------
1 | /*
2 | * ColorUtils.java
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package ugia.io.androidbeautytreatment.util;
18 |
19 | /**
20 | * Utils to play with colors seamlessly
21 | *
22 | * Created by joseluisugia on 11/02/15.
23 | */
24 | public class ColorUtils {
25 |
26 | /**
27 | * This method applies alpha channel to a given color without it. Useful when playing with alpha channels on
28 | * #android.widget.TextView. Applying a color with alpha is significantly more performing that doing the
29 | * same at the view level
30 | *
31 | *
32 | * @param color
33 | * @param alpha
34 | * @return the final result with the desired alpha applied
35 | */
36 | public static int applyAlphaToColor(int color, float alpha) {
37 | return (int) (0xFF * alpha) << 24 | color & 0xFFFFFF;
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/app/src/main/java/ugia/io/androidbeautytreatment/viewcontroller/fragment/TaggableFragment.java:
--------------------------------------------------------------------------------
1 | /*
2 | * TaggableFragment.java
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package ugia.io.androidbeautytreatment.viewcontroller.fragment;
18 |
19 | import android.app.Fragment;
20 | import android.os.Bundle;
21 | import android.view.View;
22 |
23 | /**
24 | * Created by joseluisugia on 25/09/15.
25 | */
26 | public abstract class TaggableFragment extends Fragment {
27 |
28 | private static final int INVALID_TAG = -1;
29 | protected int viewTag = INVALID_TAG;
30 |
31 | @Override
32 | public void onViewCreated(View view, Bundle savedInstanceState) {
33 | super.onViewCreated(view, savedInstanceState);
34 |
35 | if (viewTag != INVALID_TAG && view != null) {
36 | view.setTag(viewTag);
37 | }
38 | }
39 |
40 | public void setViewTag(int viewTag) {
41 | this.viewTag = viewTag;
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/app/src/main/res/animator/stroke_appear_from_center.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 |
21 |
22 |
29 |
30 |
37 |
38 |
--------------------------------------------------------------------------------
/app/src/main/res/animator/stroke_disappear_to_center.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 |
21 |
22 |
29 |
30 |
37 |
38 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_placeholder.xml:
--------------------------------------------------------------------------------
1 |
16 |
17 |
26 |
27 |
31 |
32 |
33 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/circle_stroke.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 |
23 |
24 |
29 |
30 |
35 |
36 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/branch_minified_swipe_refresh_dot.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 |
23 |
24 |
25 |
26 |
30 |
31 |
32 |
33 |
34 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/branch_minified_swipe_refresh_leave2.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 |
23 |
24 |
25 |
26 |
27 |
35 |
36 |
37 |
38 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/branch_minified_swipe_refresh_leave8.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 |
23 |
24 |
25 |
26 |
27 |
35 |
36 |
37 |
38 |
39 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/branch_minified_swipe_refresh_leave9.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 |
23 |
24 |
25 |
26 |
27 |
35 |
36 |
37 |
38 |
39 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/branch_minified_swipe_refresh_leave3.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 |
23 |
24 |
25 |
26 |
27 |
35 |
36 |
37 |
38 |
39 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 |
20 |
21 |
26 |
27 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 |
19 |
20 |
21 | #dadada
22 | #c8c8c8
23 | #808080
24 | #666666
25 | #424242
26 | #242424
27 |
28 | #55000000
29 | #80000000
30 | #bb000000
31 |
32 |
33 | #e3ffffff
34 | #ddffffff
35 | #ccffffff
36 | #aaffffff
37 | #99ffffff
38 | #66ffffff
39 | #33ffffff
40 |
41 |
42 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/branch_minified_swipe_refresh_leave1.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 |
23 |
24 |
25 |
26 |
27 |
36 |
37 |
38 |
39 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/branch_minified_swipe_refresh_leave4.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 |
23 |
24 |
25 |
26 |
27 |
36 |
37 |
38 |
39 |
40 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/branch_minified_swipe_refresh_leave5.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 |
23 |
24 |
25 |
26 |
27 |
36 |
37 |
38 |
39 |
40 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/branch_minified_swipe_refresh_leave6.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 |
23 |
24 |
25 |
26 |
27 |
36 |
37 |
38 |
39 |
40 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/branch_minified_swipe_refresh_leave7.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 |
23 |
24 |
25 |
26 |
27 |
36 |
37 |
38 |
39 |
40 |
--------------------------------------------------------------------------------
/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
16 |
17 |
18 |
19 | 16dp
20 | 16dp
21 |
22 |
24 | 240dp
25 |
26 |
27 | 80dp
28 |
29 |
30 | 100dp
31 | 50dp
32 | 120dp
33 |
34 |
35 | 150dp
36 | 50dp
37 |
38 | 100dp
39 |
40 |
41 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
16 |
17 |
18 |
25 |
26 |
30 |
31 |
37 |
38 |
39 |
--------------------------------------------------------------------------------
/app/src/main/java/ugia/io/androidbeautytreatment/model/Contact.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Contact.java
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package ugia.io.androidbeautytreatment.model;
18 |
19 | /**
20 | * Simple POJO holding the information of a contact or friend
21 | *
22 | * Created by joseluisugia on 26/09/15.
23 | */
24 | public class Contact {
25 |
26 | private final int avatarResource;
27 | private final String name;
28 | private final String phoneNumber;
29 | private final boolean hasRecentConversation;
30 |
31 | public Contact(String name, String phoneNumber, boolean hasRecentConversation) {
32 | this(name, phoneNumber, hasRecentConversation, 0);
33 | }
34 |
35 | public Contact(String name, String phoneNumber, boolean hasRecentConversation, int avatarResource) {
36 |
37 | this.name = name;
38 | this.phoneNumber = phoneNumber;
39 | this.hasRecentConversation = hasRecentConversation;
40 | this.avatarResource = avatarResource;
41 | }
42 |
43 | public String getName() {
44 | return name;
45 | }
46 |
47 | public String getPhoneNumber() {
48 | return phoneNumber;
49 | }
50 |
51 | public boolean hasRecentConversation() {
52 | return hasRecentConversation;
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/app/src/main/java/ugia/io/androidbeautytreatment/util/Poets.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Poets.java
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package ugia.io.androidbeautytreatment.util;
18 |
19 | import ugia.io.androidbeautytreatment.model.Contact;
20 |
21 | /**
22 | * Ghost data provider utils that simulates a source of information.
23 | *
24 | * Created by joseluisugia on 18/11/15.
25 | */
26 | public class Poets {
27 |
28 | public static Contact[] generate() {
29 |
30 | return new Contact[] {
31 |
32 | new Contact("Pio Baroja", "123", true),
33 | new Contact("Miguel Hernandez", "456", false),
34 | new Contact("Miguel de Cervantes", "789", false),
35 | new Contact("Juan Ramón Jimenez", "101", true),
36 | new Contact("Miguel de Unamuno", "112", true),
37 | new Contact("Antonio Machado", "175", false),
38 | new Contact("Federico García Lorca", "623", false),
39 | new Contact("Ramiro de Maeztu", "999", true),
40 | new Contact("Ramón María del Valle-Inclán", "747", false),
41 | new Contact("Ángel Ganivet", "622", false),
42 | new Contact("Enrique de Mesa", "278", true),
43 | new Contact("Azorín", "345", false)
44 | };
45 | }
46 |
47 | }
48 |
--------------------------------------------------------------------------------
/app/src/main/java/ugia/io/androidbeautytreatment/viewcontroller/adapter/ViewPagerAdapter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * ViewPagerAdapter.java
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package ugia.io.androidbeautytreatment.viewcontroller.adapter;
18 |
19 | import android.app.Fragment;
20 | import android.app.FragmentManager;
21 |
22 | import ugia.io.androidbeautytreatment.viewcontroller.fragment.TaggableFragment;
23 | import ugia.io.androidbeautytreatment.viewcontroller.fragment.ViewPagerTextViewFragment;
24 |
25 | /**
26 | * Created by joseluisugia on 18/09/15.
27 | */
28 | public class ViewPagerAdapter extends FragmentPagerAdapter {
29 |
30 | private int[] backgroundColorResources = new int[] {
31 | android.R.color.holo_green_light,
32 | android.R.color.holo_blue_dark,
33 | android.R.color.holo_orange_dark,
34 | android.R.color.holo_red_dark,
35 | android.R.color.holo_purple };
36 |
37 | public ViewPagerAdapter(FragmentManager fm) {
38 | super(fm);
39 | }
40 |
41 | @Override
42 | public Fragment getItem(int position) {
43 |
44 | int color = backgroundColorResources[position];
45 |
46 | TaggableFragment fragment = ViewPagerTextViewFragment.newInstance(position + 1, color);
47 | fragment.setViewTag(position);
48 | return fragment;
49 | }
50 |
51 | @Override
52 | public int getCount() {
53 | return backgroundColorResources.length;
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_viewpager.xml:
--------------------------------------------------------------------------------
1 |
16 |
17 |
21 |
22 |
28 |
29 |
31 |
32 |
34 |
35 |
37 |
38 |
40 |
41 |
43 |
44 |
45 |
46 |
50 |
51 |
55 |
56 |
57 |
--------------------------------------------------------------------------------
/app/src/main/java/ugia/io/androidbeautytreatment/util/Transitions.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Transitions.java
3 | *
4 | * @author Jose L Ugia - @Jl_Ugia
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | package ugia.io.androidbeautytreatment.util;
20 |
21 | /**
22 | * Created by joseluisugia on 17/03/15.
23 | */
24 | public class Transitions {
25 |
26 |
27 | public static float intermediateValueForRange(float position, float[] values) {
28 | return intermediateValueForRange(position, new float[] { 0, 1 }, values);
29 | }
30 |
31 | public static float intermediateValueForCuePoints(float position, float[] range) {
32 | return intermediateValueForRange(position, range, range);
33 | }
34 |
35 | public static float intermediateValueForRange(float position, float[] cuePoints, float[] values) {
36 |
37 | if (cuePoints.length != values.length) {
38 | throw new IllegalArgumentException("Range and values arrays must be of the same size");
39 | }
40 |
41 | int length = cuePoints.length;
42 |
43 | if (position <= cuePoints[0]) {
44 | return values[0];
45 |
46 | } else {
47 |
48 | float cuePoint, previousCuePoint, value, previousValue;
49 | float rangeRatio;
50 |
51 | for (int i = 1; i < length; i++) {
52 |
53 | cuePoint = cuePoints[i];
54 |
55 | if (position <= cuePoint) {
56 | previousCuePoint = cuePoints[i - 1];
57 | value = values[i];
58 | previousValue = values[i - 1];
59 | rangeRatio = (position - previousCuePoint) / (cuePoint - previousCuePoint);
60 | return previousValue + ((value - previousValue) * rangeRatio);
61 | }
62 | }
63 |
64 | return values[length - 1];
65 | }
66 | }
67 | }
68 |
--------------------------------------------------------------------------------
/app/src/main/java/ugia/io/androidbeautytreatment/viewcontroller/adapter/ContactAdapter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * ContactAdapter.java
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package ugia.io.androidbeautytreatment.viewcontroller.adapter;
18 |
19 | import java.util.Arrays;
20 | import java.util.Comparator;
21 |
22 | import android.support.v7.widget.RecyclerView;
23 | import android.view.View;
24 | import android.widget.TextView;
25 |
26 | import ugia.io.androidbeautytreatment.R;
27 | import ugia.io.androidbeautytreatment.model.Contact;
28 |
29 | /**
30 | * This base class holds a basic adapter that takes care of populating a list of contacts. This class may be
31 | * extended to add extra functionality
32 | *
33 | * Created by joseluisugia on 16/07/15.
34 | */
35 | abstract class ContactAdapter extends RecyclerView.Adapter {
36 |
37 | protected final static int VIEW_TYPE_ROW = 0;
38 |
39 | protected final Contact[] contacts;
40 |
41 | public ContactAdapter(Contact[] contacts) {
42 | this.contacts = contacts;
43 | sortContactArray();
44 | }
45 |
46 | private void sortContactArray() {
47 | Arrays.sort(contacts, contactComparator);
48 | }
49 |
50 | @Override
51 | public int getItemCount() {
52 | return contacts.length;
53 | }
54 |
55 | class ContactViewHolder extends RecyclerView.ViewHolder {
56 |
57 | private final TextView contactName;
58 |
59 | public ContactViewHolder(View view) {
60 | super(view);
61 | contactName = (TextView) view.findViewById(R.id.il_textview);
62 | }
63 |
64 | protected void bindContact(Contact contact) {
65 | contactName.setText(contact.getName());
66 | }
67 | }
68 |
69 | private final Comparator contactComparator = new Comparator() {
70 | @Override
71 | public int compare(Contact lhs, Contact rhs) {
72 | return lhs.getName().compareTo(rhs.getName());
73 | }
74 | };
75 | }
76 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/app/src/main/java/ugia/io/androidbeautytreatment/viewcontroller/fragment/ViewPagerTextViewFragment.java:
--------------------------------------------------------------------------------
1 | /*
2 | * ViewPagerTextViewFragment.java
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package ugia.io.androidbeautytreatment.viewcontroller.fragment;
18 |
19 | import android.os.Bundle;
20 | import android.support.annotation.Nullable;
21 | import android.view.LayoutInflater;
22 | import android.view.View;
23 | import android.view.ViewGroup;
24 | import android.widget.TextView;
25 |
26 | import ugia.io.androidbeautytreatment.R;
27 |
28 | /**
29 | * This fragment is used to populate the each of the pages of the view pager. Depending on the index, a different
30 | * text and background color is assigned to it.
31 | *
32 | * Created by joseluisugia on 22/09/15.
33 | */
34 | public class ViewPagerTextViewFragment extends TaggableFragment {
35 |
36 | private static final String PAGE_COLOR_RESOURCE = "pageColorResource";
37 | private static final String PAGE_INDEX_KEY = "pageIndex";
38 |
39 | protected int pageColor;
40 | private int pageIndex;
41 |
42 | public static ViewPagerTextViewFragment newInstance(int pageIndex, int color) {
43 |
44 | ViewPagerTextViewFragment fragment = new ViewPagerTextViewFragment();
45 | Bundle arguments = new Bundle();
46 | arguments.putInt(PAGE_INDEX_KEY, pageIndex);
47 | arguments.putInt(PAGE_COLOR_RESOURCE, color);
48 |
49 | fragment.setArguments(arguments);
50 |
51 | return fragment;
52 | }
53 |
54 | @Override
55 | public void onCreate(Bundle savedInstanceState) {
56 | super.onCreate(savedInstanceState);
57 |
58 | Bundle arguments = getArguments();
59 | pageIndex = arguments != null ? arguments.getInt(PAGE_INDEX_KEY) : 1;
60 | pageColor = arguments != null ? getResources().getColor(arguments.getInt(PAGE_COLOR_RESOURCE)) : 0;
61 | }
62 |
63 | @Nullable
64 | @Override
65 | public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
66 |
67 | View view = inflater.inflate(R.layout.fragment_viewpager_container, container, false);
68 | view.setBackgroundColor(pageColor);
69 |
70 | TextView textView = (TextView) view.findViewById(R.id.fvc_textview);
71 | textView.setText("I am #" + pageIndex);
72 |
73 | return view;
74 | }
75 | }
76 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_static_header_list.xml:
--------------------------------------------------------------------------------
1 |
16 |
17 |
21 |
22 |
27 |
28 |
30 |
31 |
42 |
43 |
44 |
45 |
48 |
49 |
54 |
55 |
56 |
60 |
61 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/view_recyclerview_header.xml:
--------------------------------------------------------------------------------
1 |
16 |
17 |
22 |
23 |
35 |
36 |
43 |
44 |
51 |
52 |
60 |
61 |
62 |
63 |
73 |
74 |
--------------------------------------------------------------------------------
/app/src/main/java/ugia/io/androidbeautytreatment/viewcontroller/fragment/SlidingLayerFragment.java:
--------------------------------------------------------------------------------
1 | /*
2 | * SlidingLayerFragment.java
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package ugia.io.androidbeautytreatment.viewcontroller.fragment;
18 |
19 | import android.app.Fragment;
20 | import android.os.Bundle;
21 | import android.support.annotation.Nullable;
22 | import android.view.LayoutInflater;
23 | import android.view.View;
24 | import android.view.ViewGroup;
25 |
26 | import com.wunderlist.slidinglayer.SlidingLayer;
27 | import com.wunderlist.slidinglayer.transformer.RotationTransformer;
28 | import com.wunderlist.slidinglayer.transformer.SlideJoyTransformer;
29 | import ugia.io.androidbeautytreatment.R;
30 |
31 | /**
32 | * Created by joseluisugia on 18/09/15.
33 | */
34 | public class SlidingLayerFragment extends Fragment implements ClickableViewController {
35 |
36 | private SlidingLayer slidingLayerLeft;
37 | private SlidingLayer slidingLayerTop;
38 | private SlidingLayer slidingLayerRight;
39 | private SlidingLayer slidingLayerBottom;
40 |
41 | public static SlidingLayerFragment newInstance() {
42 | return new SlidingLayerFragment();
43 | }
44 |
45 | @Nullable
46 | @Override
47 | public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
48 |
49 | View view = inflater.inflate(R.layout.fragment_slidinglayer, container, false);
50 |
51 | slidingLayerLeft = (SlidingLayer) view.findViewById(R.id.fs_slidinglayer_left);
52 | slidingLayerTop = (SlidingLayer) view.findViewById(R.id.fs_slidinglayer_top);
53 | slidingLayerRight = (SlidingLayer) view.findViewById(R.id.fs_slidinglayer_right);
54 | slidingLayerBottom = (SlidingLayer) view.findViewById(R.id.fs_slidinglayer_bottom);
55 |
56 | slidingLayerLeft.setLayerTransformer(new RotationTransformer());
57 | slidingLayerRight.setLayerTransformer(new RotationTransformer());
58 | slidingLayerTop.setLayerTransformer(new SlideJoyTransformer());
59 | slidingLayerBottom.setLayerTransformer(new SlideJoyTransformer());
60 |
61 | view.post(new Runnable() {
62 | @Override
63 | public void run() {
64 | slidingLayerLeft.closeLayer(false);
65 | slidingLayerRight.closeLayer(false);
66 | }
67 | });
68 |
69 | return view;
70 | }
71 |
72 | @Override
73 | public void buttonClicked(View view) {
74 | openLayers();
75 | }
76 |
77 | private void openLayers() {
78 | slidingLayerLeft.openLayer(true);
79 | slidingLayerTop.openLayer(true);
80 | slidingLayerRight.openLayer(true);
81 | slidingLayerBottom.openLayer(true);
82 | }
83 | }
84 |
--------------------------------------------------------------------------------
/app/src/main/java/ugia/io/androidbeautytreatment/viewcontroller/adapter/HeaderContactListAdapter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * HeaderContactListAdapter.java
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package ugia.io.androidbeautytreatment.viewcontroller.adapter;
18 |
19 | import android.support.v7.widget.RecyclerView;
20 | import android.view.LayoutInflater;
21 | import android.view.View;
22 | import android.view.ViewGroup;
23 |
24 | import ugia.io.androidbeautytreatment.R;
25 | import ugia.io.androidbeautytreatment.model.Contact;
26 |
27 | /**
28 | * This class adds on top of @{ContactAdapter} and includes a header on top of the list
29 | *
30 | * Created by joseluisugia on 16/07/15.
31 | */
32 | public class HeaderContactListAdapter extends ContactAdapter {
33 |
34 | private final static int VIEW_TYPE_HEADER = 1;
35 |
36 | public HeaderContactListAdapter(Contact[] contacts) {
37 | super(contacts);
38 | }
39 |
40 | @Override
41 | public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
42 |
43 | LayoutInflater layoutInflater = LayoutInflater.from(parent.getContext());
44 |
45 | if (viewType == VIEW_TYPE_ROW) {
46 | View view = layoutInflater.inflate(R.layout.item_list, parent, false);
47 | return new ContactViewHolder(view);
48 |
49 | } else {
50 | return new HeaderViewHolder(createHeader(parent));
51 | }
52 | }
53 |
54 | private View createHeader(ViewGroup parent) {
55 |
56 | View view = new View(parent.getContext());
57 | parent.addView(view);
58 |
59 | ViewGroup.LayoutParams lp = view.getLayoutParams();
60 | lp.height = (int) parent.getContext().getResources()
61 | .getDimension(R.dimen.recyclerview_dynamic_header_big_height);
62 | view.setLayoutParams(lp);
63 |
64 | return view;
65 | }
66 |
67 | @Override
68 | public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
69 |
70 | int viewType = getItemViewType(position);
71 |
72 | if (viewType == VIEW_TYPE_ROW) {
73 | Contact contact = contacts[position - 1];
74 | ((ContactViewHolder) holder).bindContact(contact);
75 | }
76 | }
77 |
78 | @Override
79 | public int getItemCount() {
80 | return super.getItemCount() + 1;
81 | }
82 |
83 | @Override
84 | public int getItemViewType(int position) {
85 | if (position == 0) {
86 | return VIEW_TYPE_HEADER;
87 | } else {
88 | return VIEW_TYPE_ROW;
89 | }
90 | }
91 |
92 | class HeaderViewHolder extends RecyclerView.ViewHolder {
93 |
94 | public HeaderViewHolder(View view) {
95 | super(view);
96 | }
97 | }
98 | }
99 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_dynamic_header_list.xml:
--------------------------------------------------------------------------------
1 |
16 |
17 |
21 |
22 |
26 |
27 |
34 |
35 |
36 |
37 |
44 |
45 |
51 |
52 |
61 |
62 |
66 |
67 |
68 |
69 |
76 |
77 |
78 |
--------------------------------------------------------------------------------
/app/src/main/java/ugia/io/androidbeautytreatment/viewcontroller/adapter/ContactListAdapter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * ContactListAdapter.java
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package ugia.io.androidbeautytreatment.viewcontroller.adapter;
18 |
19 | import android.support.v7.widget.RecyclerView;
20 | import android.view.LayoutInflater;
21 | import android.view.View;
22 | import android.view.ViewGroup;
23 |
24 | import ugia.io.androidbeautytreatment.R;
25 | import ugia.io.androidbeautytreatment.model.Contact;
26 |
27 | /**
28 | * This class adds on top of @{ContactAdapter} and includes a footer in the bottom of the list
29 | *
30 | * Created by joseluisugia on 16/07/15.
31 | */
32 | public class ContactListAdapter extends ContactAdapter {
33 |
34 | private final static int VIEW_TYPE_FOOTER = 1;
35 |
36 | public ContactListAdapter(Contact[] contacts) {
37 | super(contacts);
38 | }
39 |
40 | @Override
41 | public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
42 |
43 | LayoutInflater layoutInflater = LayoutInflater.from(parent.getContext());
44 |
45 | if (viewType == VIEW_TYPE_ROW) {
46 | View view = layoutInflater.inflate(R.layout.item_list, parent, false);
47 | return new ContactViewHolder(view);
48 | } else {
49 | return new FooterViewHolder(createFooterView(parent));
50 | }
51 | }
52 |
53 | private View createFooterView(ViewGroup parent) {
54 |
55 | int screenHeight = parent.getMeasuredHeight();
56 | int itemHeight = (int) parent.getContext().getResources().getDimension(R.dimen.recyclerview_item_height);
57 |
58 | View view = new View(parent.getContext());
59 | parent.addView(view);
60 |
61 | ViewGroup.LayoutParams lp = view.getLayoutParams();
62 | lp.height = screenHeight - itemHeight;
63 | view.setLayoutParams(lp);
64 |
65 | return view;
66 | }
67 |
68 | @Override
69 | public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
70 |
71 | int viewType = getItemViewType(position);
72 |
73 | if (viewType == VIEW_TYPE_ROW) {
74 | Contact contact = contacts[position];
75 | ((ContactViewHolder) holder).bindContact(contact);
76 | }
77 | }
78 |
79 | @Override
80 | public int getItemCount() {
81 | return super.getItemCount() + 1;
82 | }
83 |
84 | @Override
85 | public int getItemViewType(int position) {
86 | if (position == super.getItemCount()) {
87 | return VIEW_TYPE_FOOTER;
88 | } else {
89 | return VIEW_TYPE_ROW;
90 | }
91 | }
92 |
93 | class FooterViewHolder extends RecyclerView.ViewHolder {
94 |
95 | public FooterViewHolder(View view) {
96 | super(view);
97 | }
98 | }
99 | }
100 |
--------------------------------------------------------------------------------
/app/src/main/java/ugia/io/androidbeautytreatment/viewcontroller/activity/MainActivity.java:
--------------------------------------------------------------------------------
1 | /*
2 | * MainActivity.java
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package ugia.io.androidbeautytreatment.viewcontroller.activity;
18 |
19 | import android.app.Activity;
20 | import android.app.Fragment;
21 | import android.os.Bundle;
22 | import android.support.v4.widget.DrawerLayout;
23 | import android.view.Menu;
24 | import android.view.View;
25 |
26 | import ugia.io.androidbeautytreatment.R;
27 | import ugia.io.androidbeautytreatment.viewcontroller.fragment.ClickableViewController;
28 | import ugia.io.androidbeautytreatment.viewcontroller.fragment.DynamicHeaderListFragment;
29 | import ugia.io.androidbeautytreatment.viewcontroller.fragment.NavigationDrawerFragment;
30 | import ugia.io.androidbeautytreatment.viewcontroller.fragment.SlidingLayerFragment;
31 | import ugia.io.androidbeautytreatment.viewcontroller.fragment.StaticHeaderListFragment;
32 | import ugia.io.androidbeautytreatment.viewcontroller.fragment.ViewPagerFragment;
33 |
34 | public class MainActivity extends Activity
35 | implements NavigationDrawerFragment.NavigationDrawerCallbacks, ClickableViewController {
36 |
37 | /**
38 | * Fragment managing the behaviors, interactions and presentation of the navigation drawer.
39 | */
40 | private NavigationDrawerFragment mNavigationDrawerFragment;
41 | private ClickableViewController visibleFragment;
42 |
43 | @Override
44 | protected void onCreate(Bundle savedInstanceState) {
45 | super.onCreate(savedInstanceState);
46 |
47 | setContentView(R.layout.activity_main);
48 | bindViews();
49 | }
50 |
51 | @Override
52 | public void buttonClicked(View view) {
53 | visibleFragment.buttonClicked(view);
54 | }
55 |
56 | private void bindViews() {
57 |
58 | mNavigationDrawerFragment = (NavigationDrawerFragment)
59 | getFragmentManager().findFragmentById(R.id.navigation_drawer);
60 |
61 | mNavigationDrawerFragment.setUp(
62 | R.id.navigation_drawer,
63 | (DrawerLayout) findViewById(R.id.drawer_layout));
64 | }
65 |
66 | @Override
67 | public void onNavigationDrawerItemSelected(int position) {
68 |
69 | switch (position) {
70 | case 0:
71 | visibleFragment = ViewPagerFragment.newInstance();
72 | break;
73 |
74 | case 1:
75 | visibleFragment = StaticHeaderListFragment.newInstance();
76 | break;
77 |
78 | case 2:
79 | visibleFragment = DynamicHeaderListFragment.newInstance();
80 | break;
81 |
82 | case 3:
83 | visibleFragment = SlidingLayerFragment.newInstance();
84 | break;
85 |
86 | default:
87 | throw new IllegalArgumentException("There should be no section with this position index.");
88 | }
89 |
90 | getFragmentManager().beginTransaction()
91 | .replace(R.id.container, (Fragment) visibleFragment)
92 | .commit();
93 | }
94 |
95 | @Override
96 | public boolean onCreateOptionsMenu(Menu menu) {
97 | if (!mNavigationDrawerFragment.isDrawerOpen()) {
98 | getMenuInflater().inflate(R.menu.main, menu);
99 | return true;
100 | }
101 | return super.onCreateOptionsMenu(menu);
102 | }
103 | }
104 |
--------------------------------------------------------------------------------
/app/src/main/java/ugia/io/androidbeautytreatment/view/ClippedImageView.java:
--------------------------------------------------------------------------------
1 | /*
2 | * ClippedImageView.java
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package ugia.io.androidbeautytreatment.view;
18 |
19 | import android.content.Context;
20 | import android.content.res.TypedArray;
21 | import android.graphics.Canvas;
22 | import android.graphics.Paint;
23 | import android.graphics.Path;
24 | import android.graphics.RectF;
25 | import android.os.Build;
26 | import android.util.AttributeSet;
27 | import android.view.View;
28 | import android.widget.ImageView;
29 |
30 | import ugia.io.androidbeautytreatment.R;
31 |
32 | /**
33 | * This class provides a straightforward way to add clipping and stroke to an #ImageView
34 | *
35 | * Created by joseluisugia on 1/28/14.
36 | */
37 | public class ClippedImageView extends ImageView {
38 |
39 | private float cornerRadius;
40 | private Path path;
41 | private RectF rect;
42 |
43 | private Paint strokePaint;
44 |
45 | public ClippedImageView(Context context) {
46 | this(context, null);
47 | }
48 |
49 | public ClippedImageView(Context context, AttributeSet attrs) {
50 | this(context, attrs, 0);
51 | }
52 |
53 | public ClippedImageView(Context context, AttributeSet attrs, int defStyle) {
54 | super(context, attrs, defStyle);
55 |
56 | if (attrs == null) return;
57 |
58 | path = new Path();
59 | rect = new RectF();
60 |
61 | TypedArray attrsArray = context.obtainStyledAttributes(attrs, R.styleable.ClippedImageView, defStyle, 0);
62 | cornerRadius = attrsArray.getDimensionPixelSize(R.styleable.ClippedImageView_cornerRadius, 0);
63 |
64 | TypedArray bgAttrsArray = context.obtainStyledAttributes(attrs, R.styleable.BackgroundShape, defStyle, 0);
65 | int strokeColor = bgAttrsArray.getColor(R.styleable.BackgroundShape_backgroundStrokeColor, 0);
66 | int strokeWidth = bgAttrsArray.getDimensionPixelSize(R.styleable.BackgroundShape_backgroundStrokeSize, 0);
67 |
68 | if (strokeWidth > 0) {
69 | setupStrokePaint(strokeColor, strokeWidth);
70 | }
71 |
72 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH
73 | && Build.VERSION.SDK_INT <= Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1) {
74 |
75 | setLayerType(View.LAYER_TYPE_SOFTWARE, null);
76 | }
77 | }
78 |
79 | private void setupStrokePaint(int color, int borderWidth) {
80 |
81 | strokePaint = new Paint(Paint.ANTI_ALIAS_FLAG | Paint.DITHER_FLAG);
82 | strokePaint.setStrokeJoin(Paint.Join.ROUND);
83 | strokePaint.setStrokeCap(Paint.Cap.ROUND);
84 | strokePaint.setStyle(Paint.Style.STROKE);
85 | strokePaint.setColor(color);
86 | strokePaint.setStrokeWidth(borderWidth);
87 | }
88 |
89 | @Override
90 | protected void onDraw(Canvas canvas) {
91 |
92 | int width = getWidth();
93 | int height = getHeight();
94 |
95 | rect.set(getPaddingLeft(),
96 | getPaddingTop(),
97 | width - getPaddingRight(),
98 | height - getPaddingBottom());
99 |
100 | path.addRoundRect(rect, cornerRadius, cornerRadius, Path.Direction.CW);
101 | canvas.clipPath(path);
102 |
103 | super.onDraw(canvas);
104 |
105 | if (strokePaint != null) {
106 | canvas.drawCircle(width / 2, height / 2,
107 | (cornerRadius - strokePaint.getStrokeWidth() + 1) / 2, strokePaint);
108 | }
109 | }
110 | }
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_slidinglayer.xml:
--------------------------------------------------------------------------------
1 |
16 |
17 |
23 |
24 |
33 |
34 |
41 |
42 |
51 |
52 |
57 |
58 |
59 |
60 |
61 |
69 |
70 |
75 |
76 |
77 |
78 |
79 |
80 |
89 |
90 |
95 |
96 |
97 |
98 |
107 |
108 |
112 |
113 |
114 |
115 |
116 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # For Cygwin, ensure paths are in UNIX format before anything is touched.
46 | if $cygwin ; then
47 | [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
48 | fi
49 |
50 | # Attempt to set APP_HOME
51 | # Resolve links: $0 may be a link
52 | PRG="$0"
53 | # Need this for relative symlinks.
54 | while [ -h "$PRG" ] ; do
55 | ls=`ls -ld "$PRG"`
56 | link=`expr "$ls" : '.*-> \(.*\)$'`
57 | if expr "$link" : '/.*' > /dev/null; then
58 | PRG="$link"
59 | else
60 | PRG=`dirname "$PRG"`"/$link"
61 | fi
62 | done
63 | SAVED="`pwd`"
64 | cd "`dirname \"$PRG\"`/" >&-
65 | APP_HOME="`pwd -P`"
66 | cd "$SAVED" >&-
67 |
68 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
69 |
70 | # Determine the Java command to use to start the JVM.
71 | if [ -n "$JAVA_HOME" ] ; then
72 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
73 | # IBM's JDK on AIX uses strange locations for the executables
74 | JAVACMD="$JAVA_HOME/jre/sh/java"
75 | else
76 | JAVACMD="$JAVA_HOME/bin/java"
77 | fi
78 | if [ ! -x "$JAVACMD" ] ; then
79 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
80 |
81 | Please set the JAVA_HOME variable in your environment to match the
82 | location of your Java installation."
83 | fi
84 | else
85 | JAVACMD="java"
86 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
87 |
88 | Please set the JAVA_HOME variable in your environment to match the
89 | location of your Java installation."
90 | fi
91 |
92 | # Increase the maximum file descriptors if we can.
93 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
94 | MAX_FD_LIMIT=`ulimit -H -n`
95 | if [ $? -eq 0 ] ; then
96 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
97 | MAX_FD="$MAX_FD_LIMIT"
98 | fi
99 | ulimit -n $MAX_FD
100 | if [ $? -ne 0 ] ; then
101 | warn "Could not set maximum file descriptor limit: $MAX_FD"
102 | fi
103 | else
104 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
105 | fi
106 | fi
107 |
108 | # For Darwin, add options to specify how the application appears in the dock
109 | if $darwin; then
110 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
111 | fi
112 |
113 | # For Cygwin, switch paths to Windows format before running java
114 | if $cygwin ; then
115 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
116 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
158 | function splitJvmOpts() {
159 | JVM_OPTS=("$@")
160 | }
161 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
162 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
163 |
164 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
165 |
--------------------------------------------------------------------------------
/app/src/main/java/ugia/io/androidbeautytreatment/viewcontroller/adapter/FragmentPagerAdapter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2011 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package ugia.io.androidbeautytreatment.viewcontroller.adapter;
18 |
19 | import android.app.Fragment;
20 | import android.app.FragmentManager;
21 | import android.app.FragmentTransaction;
22 | import android.os.Parcelable;
23 | import android.support.v4.view.PagerAdapter;
24 | import android.util.Log;
25 | import android.view.View;
26 | import android.view.ViewGroup;
27 |
28 | /**
29 | * Implementation of {@link android.support.v4.view.PagerAdapter} that
30 | * represents each page as a {@link Fragment} that is persistently
31 | * kept in the fragment manager as long as the user can return to the page.
32 | *
33 | *
This version of the pager is best for use when there are a handful of
34 | * typically more static fragments to be paged through, such as a set of tabs.
35 | *
36 | *
When using FragmentPagerAdapter the host ViewPager must have a
37 | * valid ID set.
38 | *
39 | *
Subclasses only need to implement {@link #getItem(int)}
40 | * and {@link #getCount()} to have a working adapter.
41 | *
42 | *
Here is an example implementation of a pager containing fragments of
43 | * lists:
44 | *
The R.layout.fragment_pager_list resource containing each
54 | * individual fragment's layout is:
55 | *
56 | * {@sample development/samples/Support4Demos/res/layout/fragment_pager_list.xml
57 | * complete}
58 | */
59 | public abstract class FragmentPagerAdapter extends PagerAdapter {
60 | private static final String TAG = "FragmentPagerAdapter";
61 | private static final boolean DEBUG = false;
62 |
63 | private final FragmentManager mFragmentManager;
64 | private FragmentTransaction mCurTransaction = null;
65 | private Fragment mCurrentPrimaryItem = null;
66 |
67 | public FragmentPagerAdapter(FragmentManager fm) {
68 | mFragmentManager = fm;
69 | }
70 |
71 | /**
72 | * Return the Fragment associated with a specified position.
73 | */
74 | public abstract Fragment getItem(int position);
75 |
76 | @Override
77 | public void startUpdate(ViewGroup container) {
78 | }
79 |
80 | @Override
81 | public Object instantiateItem(ViewGroup container, int position) {
82 | if (mCurTransaction == null) {
83 | mCurTransaction = mFragmentManager.beginTransaction();
84 | }
85 |
86 | final long itemId = getItemId(position);
87 |
88 | // Do we already have this fragment?
89 | String name = makeFragmentName(container.getId(), itemId);
90 | Fragment fragment = mFragmentManager.findFragmentByTag(name);
91 | if (fragment != null) {
92 | if (DEBUG) Log.v(TAG, "Attaching item #" + itemId + ": f=" + fragment);
93 | mCurTransaction.attach(fragment);
94 | } else {
95 | fragment = getItem(position);
96 | if (DEBUG) Log.v(TAG, "Adding item #" + itemId + ": f=" + fragment);
97 | mCurTransaction.add(container.getId(), fragment,
98 | makeFragmentName(container.getId(), itemId));
99 | }
100 | if (fragment != mCurrentPrimaryItem) {
101 | fragment.setMenuVisibility(false);
102 | fragment.setUserVisibleHint(false);
103 | }
104 |
105 | return fragment;
106 | }
107 |
108 | @Override
109 | public void destroyItem(ViewGroup container, int position, Object object) {
110 | if (mCurTransaction == null) {
111 | mCurTransaction = mFragmentManager.beginTransaction();
112 | }
113 | if (DEBUG) {
114 | Log.v(TAG, "Detaching item #" + getItemId(position) + ": f=" + object
115 | + " v=" + ((Fragment) object).getView());
116 | }
117 | mCurTransaction.detach((Fragment) object);
118 | }
119 |
120 | @Override
121 | public void setPrimaryItem(ViewGroup container, int position, Object object) {
122 | Fragment fragment = (Fragment) object;
123 | if (fragment != mCurrentPrimaryItem) {
124 | if (mCurrentPrimaryItem != null) {
125 | mCurrentPrimaryItem.setMenuVisibility(false);
126 | mCurrentPrimaryItem.setUserVisibleHint(false);
127 | }
128 | if (fragment != null) {
129 | fragment.setMenuVisibility(true);
130 | fragment.setUserVisibleHint(true);
131 | }
132 | mCurrentPrimaryItem = fragment;
133 | }
134 | }
135 |
136 | @Override
137 | public void finishUpdate(ViewGroup container) {
138 | if (mCurTransaction != null) {
139 | mCurTransaction.commitAllowingStateLoss();
140 | mCurTransaction = null;
141 | mFragmentManager.executePendingTransactions();
142 | }
143 | }
144 |
145 | @Override
146 | public boolean isViewFromObject(View view, Object object) {
147 | return ((Fragment) object).getView() == view;
148 | }
149 |
150 | @Override
151 | public Parcelable saveState() {
152 | return null;
153 | }
154 |
155 | @Override
156 | public void restoreState(Parcelable state, ClassLoader loader) {
157 | }
158 |
159 | /**
160 | * Return a unique identifier for the item at the given position.
161 | *
162 | *
The default implementation returns the given position.
163 | * Subclasses should override this method if the positions of items can change.
164 | *
165 | * @param position Position within this adapter
166 | * @return Unique identifier for the item at position
167 | */
168 | public long getItemId(int position) {
169 | return position;
170 | }
171 |
172 | private static String makeFragmentName(int viewId, long id) {
173 | return "android:switcher:" + viewId + ":" + id;
174 | }
175 | }
176 |
--------------------------------------------------------------------------------
/app/src/main/java/ugia/io/androidbeautytreatment/viewcontroller/fragment/ViewPagerFragment.java:
--------------------------------------------------------------------------------
1 | /*
2 | * ViewPagerFragment.java
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package ugia.io.androidbeautytreatment.viewcontroller.fragment;
18 |
19 | import android.app.Fragment;
20 | import android.os.Bundle;
21 | import android.support.annotation.Nullable;
22 | import android.support.v4.view.ViewPager;
23 | import android.view.LayoutInflater;
24 | import android.view.View;
25 | import android.view.ViewGroup;
26 | import android.widget.TextView;
27 |
28 | import com.wunderlist.slidinglayer.utils.Transitions;
29 | import ugia.io.androidbeautytreatment.R;
30 | import ugia.io.androidbeautytreatment.viewcontroller.adapter.ViewPagerAdapter;
31 |
32 | /**
33 | * This fragment contains a @{ViewPager} that can be applied to example transformations:
34 | *
35 | * @{RotationalPageTransformer} or @{SlideJoyPageTransformer}. It also has an informative header with text views
36 | * that are animated based on the current scroll state of the view pager.
37 | *
38 | * Created by joseluisugia on 18/09/15.
39 | */
40 | public class ViewPagerFragment extends Fragment implements ClickableViewController {
41 |
42 | private ViewPager viewPager;
43 | private ViewPagerAdapter pagerAdapter;
44 |
45 | private TextView[] userDetailsTextViews;
46 | private int viewPagerHeaderHeight;
47 |
48 | public static ViewPagerFragment newInstance() {
49 | return new ViewPagerFragment();
50 | }
51 |
52 | @Override
53 | public void onCreate(Bundle savedInstanceState) {
54 | super.onCreate(savedInstanceState);
55 |
56 | viewPagerHeaderHeight = (int) getResources().getDimension(R.dimen.viewpager_header_height);
57 | }
58 |
59 | @Nullable
60 | @Override
61 | public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
62 |
63 | View view = inflater.inflate(R.layout.fragment_viewpager, container, false);
64 |
65 | viewPager = (ViewPager) view.findViewById(R.id.viewpager);
66 | pagerAdapter = new ViewPagerAdapter(getChildFragmentManager());
67 | viewPager.setAdapter(pagerAdapter);
68 | viewPager.setPageTransformer(true, new SlideJoyPageTransformer());
69 |
70 | viewPager.setEnabled(false);
71 |
72 | userDetailsTextViews = new TextView[5];
73 | userDetailsTextViews[0] = (TextView) view.findViewById(R.id.fv_header_text_1);
74 | userDetailsTextViews[1] = (TextView) view.findViewById(R.id.fv_header_text_2);
75 | userDetailsTextViews[2] = (TextView) view.findViewById(R.id.fv_header_text_3);
76 | userDetailsTextViews[3] = (TextView) view.findViewById(R.id.fv_header_text_4);
77 | userDetailsTextViews[4] = (TextView) view.findViewById(R.id.fv_header_text_5);
78 | setupHeaderTextViews();
79 |
80 | return view;
81 | }
82 |
83 | private void setupHeaderTextViews() {
84 |
85 | int length = userDetailsTextViews.length;
86 | for (int i = 0; i < length; i++) {
87 | userDetailsTextViews[i].setText(String.format("Are you #%s?", i + 1));
88 | }
89 | }
90 |
91 | @Override
92 | public void buttonClicked(View view) {
93 | }
94 |
95 |
96 | private class RotationalPageTransformer implements ViewPager.PageTransformer {
97 |
98 | private final float[] alphaValues = new float[] { 0, 1, 1, 0 };
99 | private final float[] alphaCuePoints = new float[] { -.7f, -.5f, .5f, .7f };
100 |
101 | private final float[] scaleValues = new float[] { .5f, 1, .5f };
102 | private final float[] scaleCuePoints = new float[] { -1, 0, 1 };
103 |
104 | public void transformPage(View page, float position) {
105 |
106 | transformHeaderTextViews(position, (int) page.getTag());
107 |
108 | // Alpha
109 | float alpha = Transitions.intermediateValueForRange(position, alphaCuePoints, alphaValues);
110 | page.setAlpha(alpha);
111 |
112 | // Scale
113 | float scaleValue = Transitions.intermediateValueForRange(position, scaleCuePoints, scaleValues);
114 | page.setScaleX(scaleValue);
115 | page.setScaleY(scaleValue);
116 |
117 | // Periodic translation
118 | double pi = position * Math.PI;
119 | float bouncingPosition = (float) Math.sin(pi) / 2;
120 |
121 | int pageWidth = page.getWidth();
122 |
123 | // Calculate basic translation cancelling out natural effect of viewPager
124 | float translationX = pageWidth * (bouncingPosition - position);
125 | page.setTranslationX(translationX);
126 | }
127 | }
128 |
129 | private class SlideJoyPageTransformer implements ViewPager.PageTransformer {
130 |
131 | private final float[] rotationYValues = new float[] { 0, -2.8f, 0, 2.8f, 0 };
132 | private final float[] rotationYCuePoints = new float[] { -.3f, -.1f, 0, .1f, .3f };
133 |
134 | private final float[] scaleValues = new float[] { .9f, 1, .9f };
135 | private final float[] scaleCuePoints = new float[] { -.1f, 0, .1f };
136 |
137 | @Override
138 | public void transformPage(View page, float position) {
139 |
140 | transformHeaderTextViews(position, (int) page.getTag());
141 |
142 | // Scale
143 | float scaleValue = Transitions.intermediateValueForRange(position, scaleCuePoints, scaleValues);
144 | page.setScaleX(scaleValue);
145 | page.setScaleY(scaleValue);
146 |
147 | // Prepare pivots for rotation
148 | page.setPivotY(page.getMeasuredHeight() / 2);
149 | if (position >= 0) {
150 | page.setPivotX(page.getMeasuredWidth());
151 | } else {
152 | page.setPivotX(0);
153 | }
154 |
155 | // Perform actual rotation
156 | float rotationY = Transitions.intermediateValueForRange(position, rotationYCuePoints, rotationYValues);
157 | page.setRotationY(rotationY);
158 | }
159 | }
160 |
161 | private void transformHeaderTextViews(float progress, int currentPage) {
162 |
163 | TextView textView = userDetailsTextViews[currentPage];
164 | float translationY;
165 |
166 | if (progress < -1) { // [-Infinity,-1)
167 | translationY = viewPagerHeaderHeight * 2;
168 |
169 | } else if (progress <= 1) { // (0,1]
170 | translationY = progress * -viewPagerHeaderHeight * 2;
171 |
172 | } else { // (1,+Infinity]
173 | translationY = -viewPagerHeaderHeight * 2;
174 | }
175 |
176 | textView.setTranslationY(translationY);
177 | }
178 | }
179 |
--------------------------------------------------------------------------------
/app/src/main/java/ugia/io/androidbeautytreatment/viewcontroller/fragment/NavigationDrawerFragment.java:
--------------------------------------------------------------------------------
1 | /*
2 | * NavigationDrawerFragment.java
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package ugia.io.androidbeautytreatment.viewcontroller.fragment;
18 |
19 |
20 | import android.app.Activity;
21 | import android.app.Fragment;
22 | import android.os.Bundle;
23 | import android.support.v4.view.GravityCompat;
24 | import android.support.v4.widget.DrawerLayout;
25 | import android.view.LayoutInflater;
26 | import android.view.Menu;
27 | import android.view.MenuInflater;
28 | import android.view.MenuItem;
29 | import android.view.View;
30 | import android.view.ViewGroup;
31 | import android.widget.AdapterView;
32 | import android.widget.ArrayAdapter;
33 | import android.widget.ListView;
34 | import android.widget.Toast;
35 |
36 | import ugia.io.androidbeautytreatment.R;
37 |
38 | /**
39 | * Fragment used for managing interactions for and presentation of a navigation drawer.
40 | * See the
41 | * design guidelines for a complete explanation of the behaviors implemented here.
42 | */
43 | public class NavigationDrawerFragment extends Fragment {
44 |
45 | /**
46 | * Remember the position of the selected item.
47 | */
48 | private static final String STATE_SELECTED_POSITION = "selected_navigation_drawer_position";
49 |
50 | /**
51 | * Per the design guidelines, you should show the drawer on launch until the user manually
52 | * expands it. This shared preference tracks this.
53 | */
54 | private static final String PREF_USER_LEARNED_DRAWER = "navigation_drawer_learned";
55 |
56 | /**
57 | * A pointer to the current callbacks instance (the Activity).
58 | */
59 | private NavigationDrawerCallbacks mCallbacks;
60 |
61 | private DrawerLayout mDrawerLayout;
62 | private ListView mDrawerListView;
63 | private View mFragmentContainerView;
64 |
65 | private int mCurrentSelectedPosition = 0;
66 |
67 | public NavigationDrawerFragment() {
68 | }
69 |
70 | @Override
71 | public void onCreate(Bundle savedInstanceState) {
72 | super.onCreate(savedInstanceState);
73 |
74 | if (savedInstanceState != null) {
75 | mCurrentSelectedPosition = savedInstanceState.getInt(STATE_SELECTED_POSITION);
76 | }
77 |
78 | // Select either the default item (0) or the last selected item.
79 | selectItem(mCurrentSelectedPosition);
80 | }
81 |
82 | @Override
83 | public void onActivityCreated(Bundle savedInstanceState) {
84 | super.onActivityCreated(savedInstanceState);
85 | }
86 |
87 | @Override
88 | public View onCreateView(LayoutInflater inflater, ViewGroup container,
89 | Bundle savedInstanceState) {
90 |
91 | mDrawerListView = (ListView) inflater.inflate(
92 | R.layout.fragment_navigation_drawer, container, false);
93 | mDrawerListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
94 | @Override
95 | public void onItemClick(AdapterView> parent, View view, int position, long id) {
96 | selectItem(position);
97 | }
98 | });
99 | mDrawerListView.setAdapter(new ArrayAdapter(
100 | getActivity(),
101 | android.R.layout.simple_list_item_activated_1,
102 | android.R.id.text1,
103 | new String[] {
104 | getString(R.string.title_section1),
105 | getString(R.string.title_section2),
106 | getString(R.string.title_section3),
107 | getString(R.string.title_section4),
108 | }));
109 | mDrawerListView.setItemChecked(mCurrentSelectedPosition, true);
110 | return mDrawerListView;
111 | }
112 |
113 | public boolean isDrawerOpen() {
114 | return mDrawerLayout != null && mDrawerLayout.isDrawerOpen(mFragmentContainerView);
115 | }
116 |
117 | /**
118 | * Users of this fragment must call this method to set up the navigation drawer interactions.
119 | *
120 | * @param fragmentId The android:id of this fragment in its activity's layout.
121 | * @param drawerLayout The DrawerLayout containing this fragment's UI.
122 | */
123 | public void setUp(int fragmentId, DrawerLayout drawerLayout) {
124 | mFragmentContainerView = getActivity().findViewById(fragmentId);
125 | mDrawerLayout = drawerLayout;
126 |
127 | // set a custom shadow that overlays the main content when the drawer opens
128 | mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START);
129 | }
130 |
131 | private void selectItem(int position) {
132 | mCurrentSelectedPosition = position;
133 | if (mDrawerListView != null) {
134 | mDrawerListView.setItemChecked(position, true);
135 | }
136 | if (mDrawerLayout != null) {
137 | mDrawerLayout.closeDrawer(mFragmentContainerView);
138 | }
139 | if (mCallbacks != null) {
140 | mCallbacks.onNavigationDrawerItemSelected(position);
141 | }
142 | }
143 |
144 | @Override
145 | public void onAttach(Activity activity) {
146 | super.onAttach(activity);
147 | try {
148 | mCallbacks = (NavigationDrawerCallbacks) activity;
149 | } catch (ClassCastException e) {
150 | throw new ClassCastException("Activity must implement NavigationDrawerCallbacks.");
151 | }
152 | }
153 |
154 | @Override
155 | public void onDetach() {
156 | super.onDetach();
157 | mCallbacks = null;
158 | }
159 |
160 | @Override
161 | public void onSaveInstanceState(Bundle outState) {
162 | super.onSaveInstanceState(outState);
163 | outState.putInt(STATE_SELECTED_POSITION, mCurrentSelectedPosition);
164 | }
165 |
166 | @Override
167 | public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
168 | if (mDrawerLayout != null && isDrawerOpen()) {
169 | inflater.inflate(R.menu.global, menu);
170 | }
171 | super.onCreateOptionsMenu(menu, inflater);
172 | }
173 |
174 | @Override
175 | public boolean onOptionsItemSelected(MenuItem item) {
176 | if (item.getItemId() == R.id.action_example) {
177 | Toast.makeText(getActivity(), "Example action.", Toast.LENGTH_SHORT).show();
178 | return true;
179 | }
180 |
181 | return super.onOptionsItemSelected(item);
182 | }
183 |
184 | /**
185 | * Callbacks interface that all activities using this fragment must implement.
186 | */
187 | public static interface NavigationDrawerCallbacks {
188 | /**
189 | * Called when an item in the navigation drawer is selected.
190 | */
191 | void onNavigationDrawerItemSelected(int position);
192 | }
193 | }
194 |
--------------------------------------------------------------------------------
/app/src/main/java/ugia/io/androidbeautytreatment/viewcontroller/fragment/DynamicHeaderListFragment.java:
--------------------------------------------------------------------------------
1 | /*
2 | * DynamicHeaderListFragment.java
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package ugia.io.androidbeautytreatment.viewcontroller.fragment;
18 |
19 | import android.app.Fragment;
20 | import android.graphics.drawable.AnimatedVectorDrawable;
21 | import android.os.Bundle;
22 | import android.support.annotation.Nullable;
23 | import android.support.v7.widget.LinearLayoutManager;
24 | import android.support.v7.widget.RecyclerView;
25 | import android.view.LayoutInflater;
26 | import android.view.View;
27 | import android.view.ViewGroup;
28 | import android.widget.ImageView;
29 |
30 | import ugia.io.androidbeautytreatment.R;
31 | import ugia.io.androidbeautytreatment.model.Contact;
32 | import ugia.io.androidbeautytreatment.util.Poets;
33 | import ugia.io.androidbeautytreatment.viewcontroller.adapter.HeaderContactListAdapter;
34 |
35 | /**
36 | * This fragment holds a list of elements using a @{RecyclerView}. At the top of the list there is a header that
37 | * reacts based on scrolling events in two different ways:
38 | *
39 | * 1. The avatar repositions itself within the Y axis and it is scaled according to the scrolling boundaries
40 | * defined.
41 | *
42 | * 2. An animation is triggered, causing the perceived effect of the diluting the stroke of the avatar into a
43 | * line that is then used as a boundary to separate the header from the content. This is made out of three
44 | * different animations. The first is a vector animation that acts on the animatable properties #trimPathStart
45 | * and #trimPathEnd to collapse the stroke of the avatar image. This is followed by a scaling animation to a view
46 | * containing a thin line. This view is initially invisible and drawn behind the user avatar. Finally, a reveal
47 | * effect is triggered to fill the top bar.
48 | *
49 | * Created by joseluisugia on 26/09/15.
50 | */
51 | public class DynamicHeaderListFragment extends Fragment implements ClickableViewController {
52 |
53 | private Contact[] contacts;
54 |
55 | private float userAvatarResizeRatio = 0.5f;
56 | private View userAvatarContainer;
57 | private ImageView userAvatar;
58 | private ImageView imageStrokeVectorDrawable;
59 | private AnimatedVectorDrawable appearingImageStroke;
60 | private AnimatedVectorDrawable disappearingImageStroke;
61 |
62 | private View topHeader;
63 | private View topHeaderBackground;
64 | private View topHeaderDividerLine;
65 |
66 | private RecyclerView recyclerView;
67 | private LinearLayoutManager layoutManager;
68 | private HeaderContactListAdapter contactListAdapter;
69 |
70 | private int listHeaderHeight;
71 | private int userAvatarInitialDimension;
72 |
73 | private boolean userAvatarStrokeVisible;
74 | private boolean topHeaderBackgroundVisible;
75 |
76 | @Override
77 | public void onCreate(Bundle savedInstanceState) {
78 | super.onCreate(savedInstanceState);
79 |
80 | contacts = Poets.generate();
81 | contactListAdapter = new HeaderContactListAdapter(contacts);
82 |
83 | initVectorDrawables();
84 | initDimensions();
85 | }
86 |
87 | private void initDimensions() {
88 | listHeaderHeight = (int) getResources().getDimension(R.dimen.recyclerview_dynamic_header_big_height);
89 | userAvatarInitialDimension = (int) getResources().getDimension(R.dimen
90 | .dynamic_header_list_user_avatar_size_big);
91 | }
92 |
93 | private void initVectorDrawables() {
94 |
95 | userAvatarStrokeVisible = true;
96 | topHeaderBackgroundVisible = false;
97 |
98 | appearingImageStroke = (AnimatedVectorDrawable) getResources().getDrawable(R.drawable
99 | .circle_stroke_animated_show);
100 | disappearingImageStroke = (AnimatedVectorDrawable) getResources().getDrawable(R.drawable
101 | .circle_stroke_animated_hide);
102 | }
103 |
104 | public static DynamicHeaderListFragment newInstance() {
105 | return new DynamicHeaderListFragment();
106 | }
107 |
108 | @Nullable
109 | @Override
110 | public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
111 |
112 | View rootView = inflater.inflate(R.layout.fragment_dynamic_header_list, container, false);
113 | bindViews(rootView);
114 |
115 | return rootView;
116 | }
117 |
118 | private void bindViews(View view) {
119 |
120 | recyclerView = (RecyclerView) view.findViewById(R.id.fdh_recyclerview);
121 | initializeRecyclerView();
122 |
123 | userAvatarContainer = view.findViewById(R.id.fdh_avatar_stroke_group);
124 | userAvatar = (ImageView) view.findViewById(R.id.fdh_avatar_imageview);
125 | imageStrokeVectorDrawable = (ImageView) view.findViewById(R.id.fdh_avatar_stroke_imageview);
126 | imageStrokeVectorDrawable.setImageDrawable(disappearingImageStroke);
127 |
128 | topHeader = view.findViewById(R.id.fdh_top_header);
129 | topHeaderBackground = view.findViewById(R.id.fdh_top_header_background);
130 | topHeaderDividerLine = view.findViewById(R.id.fdh_top_header_divider_line);
131 | }
132 |
133 | private void initializeRecyclerView() {
134 |
135 | recyclerView.setHasFixedSize(true);
136 | recyclerView.addOnScrollListener(scrollListener);
137 |
138 | layoutManager = new LinearLayoutManager(getActivity());
139 | recyclerView.setLayoutManager(layoutManager);
140 | recyclerView.setAdapter(contactListAdapter);
141 | }
142 |
143 | /**
144 | * This method is responsible for updating the views according to the new progress value extracted from
145 | * scrolling events coming from our @{RecyclerView}
146 | *
147 | * @param progress
148 | */
149 | private void updateViewsForHeaderSizeChanged(float progress) {
150 |
151 | // Scale avatar group
152 | float scale = 1 - (progress * userAvatarResizeRatio);
153 | userAvatarContainer.setScaleY(scale);
154 | userAvatarContainer.setScaleX(scale);
155 |
156 | // Translate views along Y axis
157 | float translationY = (float) (-listHeaderHeight * 0.5 * progress);
158 | userAvatarContainer.setTranslationY(translationY);
159 | topHeader.setTranslationY(translationY);
160 | topHeaderDividerLine.setTranslationY(translationY);
161 |
162 | // Recalculate stroke transformation
163 | if (userAvatarStrokeVisible) {
164 | if (progress > 0.1) {
165 | triggerAvatarStrokeTransformation(false);
166 | }
167 | } else {
168 | if (progress < 0.1) {
169 | triggerAvatarStrokeTransformation(true);
170 | }
171 | }
172 |
173 | // Final reveal effect
174 | if (topHeaderBackgroundVisible) {
175 | if (progress < 0.4) {
176 | topHeaderBackground.animate().scaleX(1).scaleY(1).setDuration(200);
177 | topHeaderBackgroundVisible = false;
178 | }
179 | } else {
180 | if (progress > 0.4) {
181 | topHeaderBackground.animate().scaleX(10).scaleY(10).setDuration(320);
182 | topHeaderBackgroundVisible = true;
183 | }
184 | }
185 | }
186 |
187 | private void triggerAvatarStrokeTransformation(boolean appear) {
188 |
189 | // Scale thin line behind avatar
190 | int lineScaleX = appear ? 1 : 10;
191 | topHeaderDividerLine.animate().scaleX(lineScaleX).setDuration(200);
192 |
193 | // Animate avatar stroke vector path
194 | AnimatedVectorDrawable drawable = appear ? appearingImageStroke : disappearingImageStroke;
195 | imageStrokeVectorDrawable.setImageDrawable(drawable);
196 | drawable.start();
197 |
198 | userAvatarStrokeVisible = appear;
199 | }
200 |
201 | private RecyclerView.OnScrollListener scrollListener = new RecyclerView.OnScrollListener() {
202 |
203 | @Override
204 | public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
205 | super.onScrolled(recyclerView, dx, dy);
206 |
207 | View header = layoutManager.findViewByPosition(0);
208 |
209 | float currentTopOffset;
210 | if (header == null) {
211 | currentTopOffset = listHeaderHeight;
212 | } else {
213 | currentTopOffset = -header.getTop();
214 | }
215 |
216 | updateViewsForHeaderSizeChanged(currentTopOffset / listHeaderHeight);
217 | }
218 | };
219 |
220 | @Override
221 | public void buttonClicked(View view) {
222 |
223 | }
224 | }
225 |
--------------------------------------------------------------------------------
/app/src/main/java/ugia/io/androidbeautytreatment/viewcontroller/fragment/StaticHeaderListFragment.java:
--------------------------------------------------------------------------------
1 | /*
2 | * StaticHeaderListFragment.java
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package ugia.io.androidbeautytreatment.viewcontroller.fragment;
18 |
19 | import android.app.Fragment;
20 | import android.graphics.drawable.AnimatedVectorDrawable;
21 | import android.os.Bundle;
22 | import android.support.annotation.Nullable;
23 | import android.support.v7.widget.LinearLayoutManager;
24 | import android.support.v7.widget.RecyclerView;
25 | import android.view.LayoutInflater;
26 | import android.view.View;
27 | import android.view.ViewGroup;
28 | import android.widget.ImageView;
29 | import android.widget.TextView;
30 |
31 | import ugia.io.androidbeautytreatment.R;
32 | import ugia.io.androidbeautytreatment.model.Contact;
33 | import ugia.io.androidbeautytreatment.util.Poets;
34 | import ugia.io.androidbeautytreatment.view.NoisySwipeRefreshLayout;
35 | import ugia.io.androidbeautytreatment.viewcontroller.adapter.ContactListAdapter;
36 |
37 | /**
38 | * This fragment holds a list of elements using a @{RecyclerView}. A view at the top uses the first visible
39 | * position of the list to show a brief detail of the element in question.
40 | * This list also has a swipe-to-refresh type element attached to it. This is a modified version of
41 | *
42 | * @{SwipeRefreshLayout} that can be found on the Android Open Source Project, that exposes information about the
43 | * current scrolling state on the Y axis. This allows for the parent view controller to interact with this value.
44 | * In this specific case, a vector animation (that due to limitations on the current APIs is made out of other sub
45 | * vector animations) builds and shows itself as the user swipes down the view.
46 | *
47 | * Created by joseluisugia on 26/09/15.
48 | */
49 | public class StaticHeaderListFragment extends Fragment implements ClickableViewController {
50 |
51 | private static final int INVALID_INDEX = -1;
52 |
53 | private Contact[] contacts;
54 |
55 | private NoisySwipeRefreshLayout swipeRefreshLayout;
56 |
57 | private int currentAnimationStageIndex = INVALID_INDEX;
58 | private ViewGroup swipeRefreshAnimationContainer;
59 | private ImageView[] swipeRefreshImageViews;
60 | private AnimatedVectorDrawable[] swipeRefreshDrawables;
61 |
62 | private float[] animationCuePoints = new float[] { .05f, .1f, .1f, .15f, .16f, .18f, .2f, .22f, .221f, .222f,
63 | .5f, .52f, .55f, .7f, .72f, 1 };
64 |
65 | private RecyclerView recyclerView;
66 | private LinearLayoutManager layoutManager;
67 | private ContactListAdapter contactListAdapter;
68 |
69 | private ContactListHeaderViewHolder headerViewHolder;
70 |
71 | @Override
72 | public void onCreate(Bundle savedInstanceState) {
73 | super.onCreate(savedInstanceState);
74 |
75 | contacts = Poets.generate();
76 | contactListAdapter = new ContactListAdapter(contacts);
77 | }
78 |
79 | public static StaticHeaderListFragment newInstance() {
80 | return new StaticHeaderListFragment();
81 | }
82 |
83 | @Nullable
84 | @Override
85 | public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
86 |
87 | View rootView = inflater.inflate(R.layout.fragment_static_header_list, container, false);
88 | bindViews(rootView);
89 |
90 | return rootView;
91 | }
92 |
93 | private void bindViews(View view) {
94 |
95 | swipeRefreshLayout = (NoisySwipeRefreshLayout) view.findViewById(R.id.fshl_swipe_container);
96 | swipeRefreshAnimationContainer = (ViewGroup) view.findViewById(R.id.fshl_swipe_refresh_container);
97 | initializeSwipeRefreshLayout();
98 |
99 | recyclerView = (RecyclerView) view.findViewById(R.id.fl_recyclerview);
100 | initializeRecyclerView();
101 |
102 | View contactHeader = view.findViewById(R.id.fv_header_1);
103 | headerViewHolder = new ContactListHeaderViewHolder(contactHeader);
104 | }
105 |
106 | private void initializeSwipeRefreshLayout() {
107 |
108 | int swipeRefreshDimensions = (int) getResources().getDimension(R.dimen.swipe_refresh_height);
109 |
110 | ViewGroup.LayoutParams layoutParams = swipeRefreshAnimationContainer.getLayoutParams();
111 | layoutParams.height = swipeRefreshDimensions;
112 | layoutParams.width = swipeRefreshDimensions;
113 |
114 | swipeRefreshDrawables = new AnimatedVectorDrawable[] {
115 | loadVectorDrawable(R.drawable.branch_minified_grow_branch1),
116 | loadVectorDrawable(R.drawable.branch_minified_grow_leave1),
117 | loadVectorDrawable(R.drawable.branch_minified_grow_branch3),
118 | loadVectorDrawable(R.drawable.branch_minified_grow_leave2),
119 | loadVectorDrawable(R.drawable.branch_minified_grow_branch2),
120 | loadVectorDrawable(R.drawable.branch_minified_grow_leave3),
121 | loadVectorDrawable(R.drawable.branch_minified_grow_leave4),
122 | loadVectorDrawable(R.drawable.branch_minified_grow_leave5),
123 | loadVectorDrawable(R.drawable.branch_minified_grow_branch4),
124 | loadVectorDrawable(R.drawable.branch_minified_grow_leave6),
125 | loadVectorDrawable(R.drawable.branch_minified_grow_leave7),
126 | loadVectorDrawable(R.drawable.branch_minified_grow_branch5),
127 | loadVectorDrawable(R.drawable.branch_minified_grow_leave8),
128 | loadVectorDrawable(R.drawable.branch_minified_grow_branch6),
129 | loadVectorDrawable(R.drawable.branch_minified_grow_leave9),
130 | loadVectorDrawable(R.drawable.branch_minified_grow_source)
131 | };
132 |
133 | swipeRefreshImageViews = new ImageView[16];
134 | for (int i = 0; i < 16; i++) {
135 | swipeRefreshImageViews[i] = new ImageView(getActivity());
136 | swipeRefreshImageViews[i].setLayoutParams(layoutParams);
137 | swipeRefreshAnimationContainer.addView(swipeRefreshImageViews[i]);
138 | }
139 |
140 | swipeRefreshLayout.setOnRefreshListener(refreshListener);
141 | }
142 |
143 | private AnimatedVectorDrawable loadVectorDrawable(int resourceId) {
144 | return (AnimatedVectorDrawable) getResources().getDrawable(resourceId);
145 | }
146 |
147 | private void initializeRecyclerView() {
148 |
149 | recyclerView.setHasFixedSize(true);
150 | recyclerView.addOnScrollListener(scrollListener);
151 |
152 | layoutManager = new LinearLayoutManager(getActivity());
153 | recyclerView.setLayoutManager(layoutManager);
154 | recyclerView.setAdapter(contactListAdapter);
155 | }
156 |
157 | @Override
158 | public void buttonClicked(View view) {
159 |
160 | }
161 |
162 | private class ContactListHeaderViewHolder {
163 |
164 | private ImageView contactAvatarImageView;
165 | private TextView contactNameTextView;
166 | private TextView contactNumberTextView;
167 |
168 | private View activeConversationsView;
169 |
170 | public ContactListHeaderViewHolder(View view) {
171 |
172 | contactAvatarImageView = (ImageView) view.findViewById(R.id.vrh_avatar_imageview);
173 | contactNameTextView = (TextView) view.findViewById(R.id.vrh_name_textview);
174 | contactNumberTextView = (TextView) view.findViewById(R.id.vrh_number_textview);
175 |
176 | activeConversationsView = view.findViewById(R.id.vrh_active_conversation_imageview);
177 | }
178 |
179 | private void bindContact(Contact contact) {
180 |
181 | contactNameTextView.setText(contact.getName());
182 | contactNumberTextView.setText(contact.getPhoneNumber());
183 |
184 | int visibility = contact.hasRecentConversation() ? View.VISIBLE : View.GONE;
185 | activeConversationsView.setVisibility(visibility);
186 | }
187 | }
188 |
189 | private RecyclerView.OnScrollListener scrollListener = new RecyclerView.OnScrollListener() {
190 |
191 | @Override
192 | public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
193 | super.onScrolled(recyclerView, dx, dy);
194 |
195 | int position = layoutManager.findFirstVisibleItemPosition();
196 | headerViewHolder.bindContact(contacts[position]);
197 | }
198 | };
199 |
200 | private NoisySwipeRefreshLayout.OnRefreshListener refreshListener =
201 | new NoisySwipeRefreshLayout.OnRefreshListener() {
202 |
203 | @Override
204 | public void onCancel() {
205 | resetAnimations();
206 | }
207 |
208 | @Override
209 | public void onRefresh() {
210 | swipeRefreshLayout.setRefreshing(false);
211 | resetAnimations();
212 | }
213 |
214 | @Override
215 | public void onProgress(float progress) {
216 |
217 | int animationStateIndex = animationStateForProgress(progress);
218 |
219 | if (animationStateIndex > INVALID_INDEX && animationStateIndex > currentAnimationStageIndex) {
220 |
221 | for (int i = animationStateIndex; i > currentAnimationStageIndex; i--) {
222 | swipeRefreshImageViews[i].setImageDrawable(swipeRefreshDrawables[i]);
223 | swipeRefreshDrawables[i].start();
224 | }
225 | currentAnimationStageIndex = animationStateIndex;
226 | }
227 | }
228 |
229 | private void resetAnimations() {
230 |
231 | currentAnimationStageIndex = INVALID_INDEX;
232 | for (ImageView imageView : swipeRefreshImageViews) {
233 | imageView.setImageDrawable(null);
234 | }
235 | }
236 |
237 | /**
238 | * Determines the current checkpoint of the pieced animation based on the progress of the swipe
239 | * and the cue points specified.
240 | *
241 | * @param progress
242 | * @return
243 | */
244 | private int animationStateForProgress(float progress) {
245 |
246 | int length = animationCuePoints.length;
247 | for (int i = 0; i < length; i++) {
248 | if (animationCuePoints[i] >= progress) {
249 | return i;
250 | }
251 | }
252 |
253 | return INVALID_INDEX;
254 | }
255 | };
256 | }
257 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "{}"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright {yyyy} {name of copyright owner}
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
203 |
--------------------------------------------------------------------------------
/app/src/main/java/ugia/io/androidbeautytreatment/view/NoisySwipeRefreshLayout.java:
--------------------------------------------------------------------------------
1 | package ugia.io.androidbeautytreatment.view;
2 |
3 | /**
4 | * Created by joseluisugia on 29/07/14.
5 | */
6 | /*
7 | * Copyright (C) 2013 The Android Open Source Project
8 | *
9 | * Licensed under the Apache License, Version 2.0 (the "License");
10 | * you may not use this file except in compliance with the License.
11 | * You may obtain a copy of the License at
12 | *
13 | * http://www.apache.org/licenses/LICENSE-2.0
14 | *
15 | * Unless required by applicable law or agreed to in writing, software
16 | * distributed under the License is distributed on an "AS IS" BASIS,
17 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 | * See the License for the specific language governing permissions and
19 | * limitations under the License.
20 | */
21 |
22 | import android.content.Context;
23 | import android.content.res.TypedArray;
24 | import android.support.v4.view.ViewCompat;
25 | import android.util.AttributeSet;
26 | import android.util.DisplayMetrics;
27 | import android.view.MotionEvent;
28 | import android.view.View;
29 | import android.view.ViewConfiguration;
30 | import android.view.ViewGroup;
31 | import android.view.animation.AccelerateInterpolator;
32 | import android.view.animation.Animation;
33 | import android.view.animation.DecelerateInterpolator;
34 | import android.view.animation.Transformation;
35 | import android.widget.AbsListView;
36 |
37 | import ugia.io.androidbeautytreatment.R;
38 |
39 |
40 | /**
41 | * The SwipeRefreshLayout should be used whenever the user can refresh the
42 | * contents of a view via a vertical swipe gesture. The activity that
43 | * instantiates this view needs to add an OnRefreshListener in order to be notified
44 | * whenever the swipe to refresh gesture is completed. The SwipeRefreshLayout
45 | * will notify the listener each and every time the gesture is completed again;
46 | * the listener is responsible for correctly determining when to actually
47 | * initiate a refresh of its content. If the listener determines there should
48 | * not be a refresh, it must call setRefreshing(false) to cancel any visual
49 | * indication of a refresh. If an activity wishes to show just the progress
50 | * animation, it should call setRefreshing(true). To disable the gesture and progress
51 | * animation, call setEnabled(false) on the view.
52 | *
53 | *
This layout should be made the parent of the view that will be refreshed as a
54 | * result of the gesture and can only support one direct child. This view will
55 | * also be made the target of the gesture and will be forced to match both the
56 | * width and the height supplied in this layout. The SwipeRefreshLayout does not
57 | * provide accessibility events; instead, a menu item must be provided to allow
58 | * refresh of the content wherever this gesture is used.
59 | */
60 | public class NoisySwipeRefreshLayout extends ViewGroup {
61 |
62 | private static final long RETURN_TO_ORIGINAL_POSITION_TIMEOUT = 300;
63 | private static final float ACCELERATE_INTERPOLATION_FACTOR = 1.5f;
64 | private static final float DECELERATE_INTERPOLATION_FACTOR = 2f;
65 | private static final float PROGRESS_BAR_HEIGHT = 4;
66 | private static final float MAX_SWIPE_DISTANCE_FACTOR = .6f;
67 | private static final int REFRESH_TRIGGER_DISTANCE = 120;
68 |
69 | private View mTarget; //the content that gets pulled down
70 | private int mOriginalOffsetTop;
71 | private OnRefreshListener mListener;
72 | private MotionEvent mDownEvent;
73 | private int mFrom;
74 | private boolean mRefreshing = false;
75 | private int mTouchSlop;
76 | private float mDistanceToTriggerSync = -1;
77 | private float mPrevY;
78 | private int mMediumAnimationDuration;
79 | private float mFromPercentage = 0;
80 | private float mCurrPercentage = 0;
81 |
82 | private int mProgressBarHeight;
83 | private int mProgressBarOffsetTop = 100;
84 |
85 | private int mCurrentTargetOffsetTop;
86 | // Target is returning to its start offset because it was cancelled or a
87 | // refresh was triggered.
88 | private boolean mReturningToStart;
89 | private final DecelerateInterpolator mDecelerateInterpolator;
90 | private final AccelerateInterpolator mAccelerateInterpolator;
91 | private static final int[] LAYOUT_ATTRS = new int[] {
92 | android.R.attr.enabled
93 | };
94 |
95 | private final Animation mAnimateToStartPosition = new Animation() {
96 | @Override
97 | public void applyTransformation(float interpolatedTime, Transformation t) {
98 | int targetTop = 0;
99 | if (mFrom != mOriginalOffsetTop) {
100 | targetTop = (mFrom + (int) ((mOriginalOffsetTop - mFrom) * interpolatedTime));
101 | }
102 | int offset = targetTop - mTarget.getTop();
103 | final int currentTop = mTarget.getTop();
104 | if (offset + currentTop < 0) {
105 | offset = 0 - currentTop;
106 | }
107 | setTargetOffsetTopAndBottom(offset);
108 | }
109 | };
110 |
111 | private final Animation.AnimationListener mReturnToStartPositionListener = new BaseAnimationListener() {
112 | @Override
113 | public void onAnimationEnd(Animation animation) {
114 | // Once the target content has returned to its start position, reset
115 | // the target offset to 0
116 | mCurrentTargetOffsetTop = 0;
117 | }
118 | };
119 |
120 | private final Animation.AnimationListener mShrinkAnimationListener = new BaseAnimationListener() {
121 | @Override
122 | public void onAnimationEnd(Animation animation) {
123 | mCurrPercentage = 0;
124 | }
125 | };
126 |
127 | private final Runnable mReturnToStartPosition = new Runnable() {
128 |
129 | @Override
130 | public void run() {
131 | mReturningToStart = true;
132 | animateOffsetToStartPosition(mCurrentTargetOffsetTop + getPaddingTop(),
133 | mReturnToStartPositionListener);
134 | }
135 |
136 | };
137 |
138 | // Cancel the refresh gesture and animate everything back to its original state.
139 | private final Runnable mCancel = new Runnable() {
140 |
141 | @Override
142 | public void run() {
143 | mReturningToStart = true;
144 | animateOffsetToStartPosition(mCurrentTargetOffsetTop + getPaddingTop(),
145 | mReturnToStartPositionListener);
146 | }
147 |
148 | };
149 |
150 | /**
151 | * Simple constructor to use when creating a SwipeRefreshLayout from code.
152 | *
153 | * @param context
154 | */
155 | public NoisySwipeRefreshLayout(Context context) {
156 | this(context, null);
157 | }
158 |
159 | /**
160 | * Constructor that is called when inflating SwipeRefreshLayout from XML.
161 | *
162 | * @param context
163 | * @param attrs
164 | */
165 | public NoisySwipeRefreshLayout(Context context, AttributeSet attrs) {
166 | super(context, attrs);
167 |
168 | mTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop();
169 |
170 | mMediumAnimationDuration = getResources().getInteger(
171 | android.R.integer.config_mediumAnimTime);
172 |
173 | setWillNotDraw(false);
174 | final DisplayMetrics metrics = getResources().getDisplayMetrics();
175 | mDecelerateInterpolator = new DecelerateInterpolator(DECELERATE_INTERPOLATION_FACTOR);
176 | mAccelerateInterpolator = new AccelerateInterpolator(ACCELERATE_INTERPOLATION_FACTOR);
177 |
178 | final TypedArray a = context.obtainStyledAttributes(attrs, LAYOUT_ATTRS);
179 | setEnabled(a.getBoolean(0, true));
180 | a.recycle();
181 |
182 | final TypedArray va = context.obtainStyledAttributes(attrs, R.styleable.SuperSwipeRefreshLayout);
183 | mProgressBarOffsetTop = a.getDimensionPixelSize(R.styleable.SuperSwipeRefreshLayout_topOffset, 0);
184 | mProgressBarHeight = a.getDimensionPixelSize(R.styleable.SuperSwipeRefreshLayout_progressBarHeight,
185 | (int) (metrics.density * PROGRESS_BAR_HEIGHT));
186 | va.recycle();
187 | }
188 |
189 | @Override
190 | public void onAttachedToWindow() {
191 | super.onAttachedToWindow();
192 | removeCallbacks(mCancel);
193 | removeCallbacks(mReturnToStartPosition);
194 | }
195 |
196 | @Override
197 | public void onDetachedFromWindow() {
198 | super.onDetachedFromWindow();
199 | removeCallbacks(mReturnToStartPosition);
200 | removeCallbacks(mCancel);
201 | }
202 |
203 | public void setProgressBarTopOffset(int progressBarTopOffset) {
204 | mProgressBarOffsetTop = progressBarTopOffset;
205 | }
206 |
207 | private void animateOffsetToStartPosition(int from, Animation.AnimationListener listener) {
208 | mFrom = from;
209 | mAnimateToStartPosition.reset();
210 | mAnimateToStartPosition.setDuration(mMediumAnimationDuration);
211 | mAnimateToStartPosition.setAnimationListener(listener);
212 | mAnimateToStartPosition.setInterpolator(mDecelerateInterpolator);
213 | mTarget.startAnimation(mAnimateToStartPosition);
214 | }
215 |
216 | /**
217 | * Set the listener to be notified when a refresh is triggered via the swipe
218 | * gesture.
219 | */
220 | public void setOnRefreshListener(OnRefreshListener listener) {
221 | mListener = listener;
222 | }
223 |
224 | private void setTriggerPercentage(float percent) {
225 |
226 | if (mCurrPercentage == percent) return;
227 |
228 | if (percent == 0f) {
229 | // No-op. A null trigger means it's uninitialized, and setting it to zero-percent
230 | // means we're trying to reset state, so there's nothing to reset in this case.
231 | mCurrPercentage = 0;
232 | return;
233 | }
234 | if (mListener != null) {
235 | mListener.onProgress(percent);
236 | }
237 | mCurrPercentage = percent;
238 | }
239 |
240 | /**
241 | * Notify the widget that refresh state has changed. Do not call this when
242 | * refresh is triggered by a swipe gesture.
243 | *
244 | * @param refreshing Whether or not the view should show refresh progress.
245 | */
246 | public void setRefreshing(boolean refreshing) {
247 | if (mRefreshing != refreshing) {
248 | ensureTarget();
249 | mCurrPercentage = 0;
250 | mRefreshing = refreshing;
251 | }
252 | }
253 |
254 | /**
255 | * @return Whether the SwipeRefreshWidget is actively showing refresh
256 | * progress.
257 | */
258 | public boolean isRefreshing() {
259 | return mRefreshing;
260 | }
261 |
262 | private void ensureTarget() {
263 | // Don't bother getting the parent height if the parent hasn't been laid out yet.
264 | if (mTarget == null) {
265 | if (getChildCount() > 1 && !isInEditMode()) {
266 | throw new IllegalStateException(
267 | "SwipeRefreshLayout can host only one direct child");
268 | }
269 | mTarget = getChildAt(0);
270 | mOriginalOffsetTop = mTarget.getTop() + getPaddingTop();
271 | }
272 | if (mDistanceToTriggerSync == -1) {
273 | if (getParent() != null && ((View) getParent()).getHeight() > 0) {
274 | final DisplayMetrics metrics = getResources().getDisplayMetrics();
275 | mDistanceToTriggerSync = (int) Math.min(
276 | ((View) getParent()).getHeight() * MAX_SWIPE_DISTANCE_FACTOR,
277 | REFRESH_TRIGGER_DISTANCE * metrics.density);
278 | }
279 | }
280 | }
281 |
282 | @Override
283 | protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
284 | final int width = getMeasuredWidth();
285 | final int height = getMeasuredHeight();
286 | if (getChildCount() == 0) {
287 | return;
288 | }
289 | final View child = getChildAt(0);
290 | final int childLeft = getPaddingLeft();
291 | final int childTop = mCurrentTargetOffsetTop + getPaddingTop();
292 | final int childWidth = width - getPaddingLeft() - getPaddingRight();
293 | final int childHeight = height - getPaddingTop() - getPaddingBottom();
294 | child.layout(childLeft, childTop, childLeft + childWidth, childTop + childHeight);
295 | }
296 |
297 | @Override
298 | public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
299 | super.onMeasure(widthMeasureSpec, heightMeasureSpec);
300 | if (getChildCount() > 1 && !isInEditMode()) {
301 | throw new IllegalStateException("SwipeRefreshLayout can host only one direct child");
302 | }
303 | if (getChildCount() > 0) {
304 | getChildAt(0).measure(
305 | MeasureSpec.makeMeasureSpec(
306 | getMeasuredWidth() - getPaddingLeft() - getPaddingRight(),
307 | MeasureSpec.EXACTLY),
308 | MeasureSpec.makeMeasureSpec(
309 | getMeasuredHeight() - getPaddingTop() - getPaddingBottom(),
310 | MeasureSpec.EXACTLY)
311 | );
312 | }
313 | }
314 |
315 | /**
316 | * @return Whether it is possible for the child view of this layout to
317 | * scroll up. Override this if the child view is a custom view.
318 | */
319 | public boolean canChildScrollUp() {
320 | if (android.os.Build.VERSION.SDK_INT < 14) {
321 | if (mTarget instanceof AbsListView) {
322 | final AbsListView absListView = (AbsListView) mTarget;
323 | return absListView.getChildCount() > 0
324 | && (absListView.getFirstVisiblePosition() > 0 || absListView.getChildAt(0)
325 | .getTop() < absListView
326 | .getPaddingTop());
327 | } else {
328 | return mTarget.getScrollY() > 0;
329 | }
330 | } else {
331 | return ViewCompat.canScrollVertically(mTarget, -1);
332 | }
333 | }
334 |
335 | @Override
336 | public boolean onInterceptTouchEvent(MotionEvent ev) {
337 | ensureTarget();
338 | boolean handled = false;
339 | if (mReturningToStart && ev.getAction() == MotionEvent.ACTION_DOWN) {
340 | mReturningToStart = false;
341 | }
342 | if (isEnabled() && !mReturningToStart && !canChildScrollUp()) {
343 | handled = onTouchEvent(ev);
344 | }
345 | return !handled ? super.onInterceptTouchEvent(ev) : handled;
346 | }
347 |
348 | @Override
349 | public void requestDisallowInterceptTouchEvent(boolean b) {
350 | // Nope.
351 | }
352 |
353 | @Override
354 | public boolean onTouchEvent(MotionEvent event) {
355 | final int action = event.getAction();
356 | boolean handled = false;
357 | switch (action) {
358 | case MotionEvent.ACTION_DOWN:
359 | mCurrPercentage = 0;
360 | mDownEvent = MotionEvent.obtain(event);
361 | mPrevY = mDownEvent.getY();
362 | break;
363 | case MotionEvent.ACTION_MOVE:
364 | if (mDownEvent != null && !mReturningToStart) {
365 | final float eventY = event.getY();
366 | float yDiff = eventY - mDownEvent.getY();
367 | if (yDiff > mTouchSlop) {
368 | // User velocity passed min velocity; trigger a refresh
369 | if (yDiff > mDistanceToTriggerSync) {
370 | // User movement passed distance; trigger a refresh
371 | setTriggerPercentage(1f);
372 | handled = true;
373 | break;
374 | } else {
375 | // Just track the user's movement
376 | setTriggerPercentage(
377 | mAccelerateInterpolator.getInterpolation(
378 | yDiff / mDistanceToTriggerSync)
379 | );
380 | float offsetTop = yDiff;
381 | if (mPrevY > eventY) {
382 | offsetTop = yDiff - mTouchSlop;
383 | }
384 | updateContentOffsetTop((int) (offsetTop));
385 | if (mPrevY > eventY && (mTarget.getTop() < mTouchSlop)) {
386 | // If the user puts the view back at the top, we
387 | // don't need to. This shouldn't be considered
388 | // cancelling the gesture as the user can restart from the top.
389 | removeCallbacks(mCancel);
390 | }
391 | mPrevY = event.getY();
392 | handled = true;
393 | }
394 | }
395 | }
396 | break;
397 | case MotionEvent.ACTION_UP:
398 | case MotionEvent.ACTION_CANCEL:
399 |
400 | if (mCurrPercentage >= 1) startRefresh();
401 |
402 | removeCallbacks(mCancel);
403 | mReturnToStartPosition.run();
404 |
405 | if (mListener != null) {
406 | mListener.onCancel();
407 | }
408 |
409 | if (mDownEvent != null) {
410 | mDownEvent.recycle();
411 | mDownEvent = null;
412 | }
413 | break;
414 | }
415 | return handled;
416 | }
417 |
418 | private void startRefresh() {
419 | setRefreshing(true);
420 |
421 | if (mListener != null) {
422 | mListener.onRefresh();
423 | }
424 | }
425 |
426 | private void updateContentOffsetTop(int targetTop) {
427 | final int currentTop = mTarget.getTop();
428 | if (targetTop > mDistanceToTriggerSync) {
429 | targetTop = (int) mDistanceToTriggerSync;
430 | } else if (targetTop < 0) {
431 | targetTop = 0;
432 | }
433 | setTargetOffsetTopAndBottom(targetTop - currentTop);
434 | }
435 |
436 | private void setTargetOffsetTopAndBottom(int offset) {
437 | mTarget.offsetTopAndBottom(offset);
438 | mCurrentTargetOffsetTop = mTarget.getTop();
439 | }
440 |
441 | private void updatePositionTimeout() {
442 | removeCallbacks(mCancel);
443 | postDelayed(mCancel, RETURN_TO_ORIGINAL_POSITION_TIMEOUT);
444 | }
445 |
446 | /**
447 | * Classes that wish to be notified when the swipe gesture correctly
448 | * triggers a refresh should implement this interface.
449 | */
450 | public interface OnRefreshListener {
451 |
452 | void onCancel();
453 |
454 | void onRefresh();
455 |
456 | void onProgress(float progress);
457 | }
458 |
459 | /**
460 | * Simple AnimationListener to avoid having to implement unneeded methods in
461 | * AnimationListeners.
462 | */
463 | private class BaseAnimationListener implements Animation.AnimationListener {
464 | @Override
465 | public void onAnimationStart(Animation animation) {
466 | }
467 |
468 | @Override
469 | public void onAnimationEnd(Animation animation) {
470 | }
471 |
472 | @Override
473 | public void onAnimationRepeat(Animation animation) {
474 | }
475 | }
476 | }
477 |
--------------------------------------------------------------------------------