├── .gitignore
├── README.md
├── app
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── iammert
│ │ └── com
│ │ └── view
│ │ └── scalinglayout
│ │ └── ExampleInstrumentedTest.java
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── iammert
│ │ │ └── com
│ │ │ └── view
│ │ │ └── scalinglayout
│ │ │ ├── CollapsingDemoActivity.java
│ │ │ ├── FABDemo.java
│ │ │ ├── MainActivity.java
│ │ │ └── SearchBarDemoActivity.java
│ └── res
│ │ ├── drawable
│ │ ├── ic_arrow_back_white_24dp.xml
│ │ ├── ic_date_range_white_24dp.xml
│ │ ├── ic_sort_white_24dp.xml
│ │ ├── ic_star_white_24dp.xml
│ │ ├── ic_tv_white_24dp.xml
│ │ ├── ic_watch_later_white_24dp.xml
│ │ └── img_cover.png
│ │ ├── layout
│ │ ├── activity_collapsing.xml
│ │ ├── activity_fab.xml
│ │ ├── activity_main.xml
│ │ └── activity_search.xml
│ │ ├── mipmap-hdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-mdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-xhdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-xxhdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-xxxhdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ └── values
│ │ ├── colors.xml
│ │ ├── strings.xml
│ │ └── styles.xml
│ └── test
│ └── java
│ └── iammert
│ └── com
│ └── view
│ └── scalinglayout
│ └── ExampleUnitTest.java
├── art
├── cover_scaling.png
├── gif_behavior.gif
├── gif_coordinator.gif
├── gif_fab.gif
└── gif_searchbar.gif
├── build.gradle
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── scalinglib
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ └── main
│ ├── AndroidManifest.xml
│ ├── java
│ └── iammert
│ │ └── com
│ │ └── view
│ │ └── scalinglib
│ │ ├── ScalingLayout.java
│ │ ├── ScalingLayoutBehavior.java
│ │ ├── ScalingLayoutListener.java
│ │ ├── ScalingLayoutOutlineProvider.java
│ │ ├── ScalingLayoutSettings.java
│ │ └── State.java
│ └── res
│ ├── animator
│ └── sl_state_animator.xml
│ └── values
│ ├── attrs.xml
│ ├── dimens.xml
│ └── strings.xml
└── settings.gradle
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/workspace.xml
5 | /.idea/libraries
6 | .DS_Store
7 | /build
8 | /captures
9 | .externalNativeBuild
10 | .idea
11 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # ScalingLayout
2 | Scale your layout on user interaction. [Live Demo](https://www.youtube.com/watch?v=wA41H0UMoHQ)
3 |
4 | Motivated by layout in [Blinkist](https://play.google.com/store/apps/details?id=com.blinkslabs.blinkist.android) app and search bar in [Spotify](https://play.google.com/store/apps/details?id=com.spotify.music) app.
5 |
6 |
7 |
8 | ## Demo
9 |
10 |
11 | ## Fab Demo
12 |
13 |
14 | ## Spotify Search Demo
15 |
16 |
17 | ## Usage
18 | ```xml
19 |
24 |
25 |
26 |
27 |
28 | ```
29 |
30 | ```java
31 | scalingLayout.expand(); //use this if you want to expand all
32 | scalingLayout.collapse(); //user this if you want to collapse view to initial state.
33 | scalingLayout.setProgress(float progress); //1 is fully expanded, 0 is initial state.
34 | ```
35 |
36 | ## Listener
37 | ```java
38 | scalingLayout.setListener(new ScalingLayoutListener() {
39 | @Override
40 | public void onCollapsed() {}
41 |
42 | @Override
43 | public void onExpanded() {}
44 |
45 | @Override
46 | public void onProgress(float progress) {}
47 | });
48 | ```
49 |
50 | ## Attribute
51 | ```app:radiusFactor``` value is between 0 and 1 float value. 1 = full rounded corner. 0 = no rounded corner.
52 |
53 | ## ScalingLayoutBehaviour
54 |
55 |
56 | ```xml
57 |
63 |
64 |
65 |
66 |
67 | ```
68 |
69 | ## Download
70 |
71 |
72 |
73 | ```gradle
74 | maven { url 'https://jitpack.io' }
75 | ```
76 |
77 | ```gradle
78 | dependencies {
79 | compile 'com.github.iammert:ScalingLayout:1.2.1'
80 | }
81 | ```
82 | License
83 | --------
84 |
85 |
86 | Copyright 2017 Mert Şimşek.
87 |
88 | Licensed under the Apache License, Version 2.0 (the "License");
89 | you may not use this file except in compliance with the License.
90 | You may obtain a copy of the License at
91 |
92 | http://www.apache.org/licenses/LICENSE-2.0
93 |
94 | Unless required by applicable law or agreed to in writing, software
95 | distributed under the License is distributed on an "AS IS" BASIS,
96 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
97 | See the License for the specific language governing permissions and
98 | limitations under the License.
99 |
100 |
101 |
102 |
103 |
104 |
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | # Built application files
2 | *.apk
3 | *.ap_
4 |
5 | # Files for the ART/Dalvik VM
6 | *.dex
7 |
8 | # Java class files
9 | *.class
10 |
11 | # Generated files
12 | bin/
13 | gen/
14 | out/
15 |
16 | # Gradle files
17 | .gradle/
18 | build/
19 |
20 | # Local configuration file (sdk path, etc)
21 | local.properties
22 |
23 | # Proguard folder generated by Eclipse
24 | proguard/
25 |
26 | # Log Files
27 | *.log
28 |
29 | # Android Studio Navigation editor temp files
30 | .navigation/
31 |
32 | # Android Studio captures folder
33 | captures/
34 |
35 | # Intellij
36 | *.iml
37 | .idea/workspace.xml
38 | .idea/tasks.xml
39 | .idea/gradle.xml
40 | .idea/dictionaries
41 | .idea/libraries
42 |
43 | # Keystore files
44 | *.jks
45 |
46 | # External native build folder generated in Android Studio 2.2 and later
47 | .externalNativeBuild
48 |
49 | # Google Services (e.g. APIs or Firebase)
50 | google-services.json
51 |
52 | # Freeline
53 | freeline.py
54 | freeline/
55 | freeline_project_description.json
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 26
5 | buildToolsVersion "26.0.2"
6 | defaultConfig {
7 | applicationId "iammert.com.view.scalinglayout"
8 | minSdkVersion 15
9 | targetSdkVersion 26
10 | versionCode 1
11 | versionName "1.0"
12 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
13 | }
14 | buildTypes {
15 | release {
16 | minifyEnabled false
17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
18 | }
19 | }
20 | }
21 |
22 | dependencies {
23 | compile fileTree(include: ['*.jar'], dir: 'libs')
24 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
25 | exclude group: 'com.android.support', module: 'support-annotations'
26 | })
27 | compile 'com.android.support:appcompat-v7:26.1.0'
28 | testCompile 'junit:junit:4.12'
29 | compile project(':scalinglib')
30 | }
31 |
--------------------------------------------------------------------------------
/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/mertsimsek/Library/Android/sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
19 | # Uncomment this to preserve the line number information for
20 | # debugging stack traces.
21 | #-keepattributes SourceFile,LineNumberTable
22 |
23 | # If you keep the line number information, uncomment this to
24 | # hide the original source file name.
25 | #-renamesourcefileattribute SourceFile
26 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/iammert/com/view/scalinglayout/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package iammert.com.view.scalinglayout;
2 |
3 | import android.content.Context;
4 | import android.support.test.InstrumentationRegistry;
5 | import android.support.test.runner.AndroidJUnit4;
6 |
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 |
10 | import static org.junit.Assert.*;
11 |
12 | /**
13 | * Instrumentation test, which will execute on an Android device.
14 | *
15 | * @see Testing documentation
16 | */
17 | @RunWith(AndroidJUnit4.class)
18 | public class ExampleInstrumentedTest {
19 | @Test
20 | public void useAppContext() throws Exception {
21 | // Context of the app under test.
22 | Context appContext = InstrumentationRegistry.getTargetContext();
23 |
24 | assertEquals("iammert.com.view.scalinglayout", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/app/src/main/java/iammert/com/view/scalinglayout/CollapsingDemoActivity.java:
--------------------------------------------------------------------------------
1 | package iammert.com.view.scalinglayout;
2 |
3 | import android.os.Bundle;
4 | import android.support.annotation.Nullable;
5 | import android.support.v7.app.AppCompatActivity;
6 | import android.support.v7.widget.Toolbar;
7 |
8 | /**
9 | * Created by mertsimsek on 01/10/2017.
10 | */
11 |
12 | public class CollapsingDemoActivity extends AppCompatActivity {
13 |
14 | @Override
15 | protected void onCreate(@Nullable Bundle savedInstanceState) {
16 | super.onCreate(savedInstanceState);
17 | setContentView(R.layout.activity_collapsing);
18 |
19 | Toolbar toolbar = findViewById(R.id.toolbar);
20 | setSupportActionBar(toolbar);
21 | getSupportActionBar().setDisplayHomeAsUpEnabled(true);
22 | getSupportActionBar().setDisplayShowHomeEnabled(true);
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/app/src/main/java/iammert/com/view/scalinglayout/FABDemo.java:
--------------------------------------------------------------------------------
1 | package iammert.com.view.scalinglayout;
2 |
3 | import android.os.Bundle;
4 | import android.support.annotation.Nullable;
5 | import android.support.v4.view.ViewCompat;
6 | import android.support.v4.view.ViewPropertyAnimatorListener;
7 | import android.support.v7.app.AppCompatActivity;
8 | import android.view.View;
9 | import android.widget.ImageView;
10 | import android.widget.LinearLayout;
11 |
12 | import iammert.com.view.scalinglib.ScalingLayout;
13 | import iammert.com.view.scalinglib.ScalingLayoutListener;
14 | import iammert.com.view.scalinglib.State;
15 |
16 | /**
17 | * Created by mertsimsek on 01/10/2017.
18 | */
19 |
20 | public class FABDemo extends AppCompatActivity {
21 |
22 | @Override
23 | protected void onCreate(@Nullable Bundle savedInstanceState) {
24 | super.onCreate(savedInstanceState);
25 | setContentView(R.layout.activity_fab);
26 |
27 | final ImageView fabIcon = findViewById(R.id.fabIcon);
28 | final LinearLayout filterLayout = findViewById(R.id.filterLayout);
29 | final ScalingLayout scalingLayout = findViewById(R.id.scalingLayout);
30 |
31 | scalingLayout.setListener(new ScalingLayoutListener() {
32 | @Override
33 | public void onCollapsed() {
34 | ViewCompat.animate(fabIcon).alpha(1).setDuration(150).start();
35 | ViewCompat.animate(filterLayout).alpha(0).setDuration(150).setListener(new ViewPropertyAnimatorListener() {
36 | @Override
37 | public void onAnimationStart(View view) {
38 | fabIcon.setVisibility(View.VISIBLE);
39 | }
40 |
41 | @Override
42 | public void onAnimationEnd(View view) {
43 | filterLayout.setVisibility(View.INVISIBLE);
44 | }
45 |
46 | @Override
47 | public void onAnimationCancel(View view) {
48 |
49 | }
50 | }).start();
51 | }
52 |
53 | @Override
54 | public void onExpanded() {
55 | ViewCompat.animate(fabIcon).alpha(0).setDuration(200).start();
56 | ViewCompat.animate(filterLayout).alpha(1).setDuration(200).setListener(new ViewPropertyAnimatorListener() {
57 | @Override
58 | public void onAnimationStart(View view) {
59 | filterLayout.setVisibility(View.VISIBLE);
60 | }
61 |
62 | @Override
63 | public void onAnimationEnd(View view) {
64 | fabIcon.setVisibility(View.INVISIBLE);
65 | }
66 |
67 | @Override
68 | public void onAnimationCancel(View view) {
69 |
70 | }
71 | }).start();
72 | }
73 |
74 | @Override
75 | public void onProgress(float progress) {
76 | if (progress > 0) {
77 | fabIcon.setVisibility(View.INVISIBLE);
78 | }
79 |
80 | if(progress < 1){
81 | filterLayout.setVisibility(View.INVISIBLE);
82 | }
83 | }
84 | });
85 |
86 | scalingLayout.setOnClickListener(new View.OnClickListener() {
87 | @Override
88 | public void onClick(View view) {
89 | if (scalingLayout.getState() == State.COLLAPSED) {
90 | scalingLayout.expand();
91 | }
92 | }
93 | });
94 |
95 |
96 | findViewById(R.id.rootLayout).setOnClickListener(new View.OnClickListener() {
97 | @Override
98 | public void onClick(View view) {
99 | if (scalingLayout.getState() == State.EXPANDED) {
100 | scalingLayout.collapse();
101 | }
102 | }
103 | });
104 |
105 | }
106 | }
107 |
--------------------------------------------------------------------------------
/app/src/main/java/iammert/com/view/scalinglayout/MainActivity.java:
--------------------------------------------------------------------------------
1 | package iammert.com.view.scalinglayout;
2 |
3 | import android.content.Intent;
4 | import android.os.Bundle;
5 | import android.support.v7.app.AppCompatActivity;
6 | import android.view.View;
7 |
8 | public class MainActivity extends AppCompatActivity {
9 |
10 | @Override
11 | protected void onCreate(Bundle savedInstanceState) {
12 | super.onCreate(savedInstanceState);
13 | setContentView(R.layout.activity_main);
14 |
15 |
16 | findViewById(R.id.demo1).setOnClickListener(new View.OnClickListener() {
17 | @Override
18 | public void onClick(View view) {
19 | startActivity(new Intent(MainActivity.this, CollapsingDemoActivity.class));
20 | }
21 | });
22 |
23 | findViewById(R.id.demo2).setOnClickListener(new View.OnClickListener() {
24 | @Override
25 | public void onClick(View view) {
26 | startActivity(new Intent(MainActivity.this, FABDemo.class));
27 | }
28 | });
29 |
30 | findViewById(R.id.demo3).setOnClickListener(new View.OnClickListener() {
31 | @Override
32 | public void onClick(View view) {
33 | startActivity(new Intent(MainActivity.this, SearchBarDemoActivity.class));
34 | }
35 | });
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/app/src/main/java/iammert/com/view/scalinglayout/SearchBarDemoActivity.java:
--------------------------------------------------------------------------------
1 | package iammert.com.view.scalinglayout;
2 |
3 | import android.os.Bundle;
4 | import android.support.annotation.Nullable;
5 | import android.support.v4.view.ViewCompat;
6 | import android.support.v4.view.ViewPropertyAnimatorListener;
7 | import android.support.v7.app.AppCompatActivity;
8 | import android.view.View;
9 | import android.widget.RelativeLayout;
10 | import android.widget.TextView;
11 |
12 | import iammert.com.view.scalinglib.ScalingLayout;
13 | import iammert.com.view.scalinglib.ScalingLayoutListener;
14 | import iammert.com.view.scalinglib.State;
15 |
16 | /**
17 | * Created by mertsimsek on 01/10/2017.
18 | */
19 |
20 | public class SearchBarDemoActivity extends AppCompatActivity {
21 |
22 | @Override
23 | protected void onCreate(@Nullable Bundle savedInstanceState) {
24 | super.onCreate(savedInstanceState);
25 | setContentView(R.layout.activity_search);
26 |
27 | final TextView textViewSearch = findViewById(R.id.textViewSearch);
28 | final RelativeLayout searchLayout = findViewById(R.id.searchLayout);
29 |
30 | final ScalingLayout scalingLayout = findViewById(R.id.scalingLayout);
31 | scalingLayout.setListener(new ScalingLayoutListener() {
32 | @Override
33 | public void onCollapsed() {
34 | ViewCompat.animate(textViewSearch).alpha(1).setDuration(150).start();
35 | ViewCompat.animate(searchLayout).alpha(0).setDuration(150).setListener(new ViewPropertyAnimatorListener() {
36 | @Override
37 | public void onAnimationStart(View view) {
38 | textViewSearch.setVisibility(View.VISIBLE);
39 | }
40 |
41 | @Override
42 | public void onAnimationEnd(View view) {
43 | searchLayout.setVisibility(View.INVISIBLE);
44 | }
45 |
46 | @Override
47 | public void onAnimationCancel(View view) {
48 |
49 | }
50 | }).start();
51 | }
52 |
53 | @Override
54 | public void onExpanded() {
55 | ViewCompat.animate(textViewSearch).alpha(0).setDuration(200).start();
56 | ViewCompat.animate(searchLayout).alpha(1).setDuration(200).setListener(new ViewPropertyAnimatorListener() {
57 | @Override
58 | public void onAnimationStart(View view) {
59 | searchLayout.setVisibility(View.VISIBLE);
60 | }
61 |
62 | @Override
63 | public void onAnimationEnd(View view) {
64 | textViewSearch.setVisibility(View.INVISIBLE);
65 | }
66 |
67 | @Override
68 | public void onAnimationCancel(View view) {
69 |
70 | }
71 | }).start();
72 | }
73 |
74 | @Override
75 | public void onProgress(float progress) {
76 |
77 | }
78 | });
79 | scalingLayout.setOnClickListener(new View.OnClickListener() {
80 | @Override
81 | public void onClick(View view) {
82 | if (scalingLayout.getState() == State.COLLAPSED) {
83 | scalingLayout.expand();
84 | }
85 | }
86 | });
87 |
88 | findViewById(R.id.rootLayout).setOnClickListener(new View.OnClickListener() {
89 | @Override
90 | public void onClick(View view) {
91 | if (scalingLayout.getState() == State.EXPANDED) {
92 | scalingLayout.collapse();
93 | }
94 | }
95 | });
96 | }
97 | }
98 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_arrow_back_white_24dp.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_date_range_white_24dp.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_sort_white_24dp.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_star_white_24dp.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_tv_white_24dp.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_watch_later_white_24dp.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/img_cover.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/iammert/ScalingLayout/f19164d4c4e08f93ddeb9f40aaa39e2025d1b866/app/src/main/res/drawable/img_cover.png
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_collapsing.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
13 |
14 |
20 |
21 |
28 |
29 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
50 |
51 |
56 |
57 |
64 |
65 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
87 |
88 |
96 |
97 |
102 |
103 |
109 |
110 |
121 |
122 |
123 |
124 |
129 |
130 |
136 |
137 |
148 |
149 |
150 |
151 |
152 |
153 |
154 |
155 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_fab.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
19 |
20 |
24 |
25 |
31 |
32 |
41 |
42 |
47 |
48 |
54 |
55 |
66 |
67 |
68 |
69 |
74 |
75 |
81 |
82 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
12 |
13 |
18 |
19 |
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_search.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
21 |
22 |
26 |
27 |
34 |
35 |
41 |
42 |
51 |
52 |
53 |
54 |
55 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/iammert/ScalingLayout/f19164d4c4e08f93ddeb9f40aaa39e2025d1b866/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/iammert/ScalingLayout/f19164d4c4e08f93ddeb9f40aaa39e2025d1b866/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/iammert/ScalingLayout/f19164d4c4e08f93ddeb9f40aaa39e2025d1b866/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/iammert/ScalingLayout/f19164d4c4e08f93ddeb9f40aaa39e2025d1b866/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/iammert/ScalingLayout/f19164d4c4e08f93ddeb9f40aaa39e2025d1b866/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/iammert/ScalingLayout/f19164d4c4e08f93ddeb9f40aaa39e2025d1b866/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/iammert/ScalingLayout/f19164d4c4e08f93ddeb9f40aaa39e2025d1b866/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/iammert/ScalingLayout/f19164d4c4e08f93ddeb9f40aaa39e2025d1b866/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/iammert/ScalingLayout/f19164d4c4e08f93ddeb9f40aaa39e2025d1b866/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/iammert/ScalingLayout/f19164d4c4e08f93ddeb9f40aaa39e2025d1b866/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #071C24
4 | #06151b
5 | #00D474
6 |
7 |
8 | #444444
9 | #121212
10 |
11 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | ScalingLayout
3 |
4 | Lorem ipsum dolor sit amet, an sit fugit officiis deserunt, audiam disputando at sit. Eu mel expetenda voluptatibus. Ius no accusam scripserit.\n\n Sea error iracundia ne, duo ne dicat partem sententiae. Nibh admodum facilisi ius in. Ius legere intellegam ei, in zril deserunt qui.At alii audire scripta mea, errem disputando quo in.\n\n Elit vocent legimus cum ei. Eu nonumes eligendi pericula sit. Ceteros omnesque facilisis id vix, at dico choro perpetua est, et dolore oblique vituperata qui. \n\nLorem ipsum dolor sit amet, an sit fugit officiis deserunt, audiam disputando at sit. Eu mel expetenda voluptatibus. Ius no accusam scripserit.\n\n Sea error iracundia ne, duo ne dicat partem sententiae. Nibh admodum facilisi ius in. Ius legere intellegam ei, in zril deserunt qui.At alii audire scripta mea, errem disputando quo in.\n\n Elit vocent legimus cum ei. Eu nonumes eligendi pericula sit. Ceteros omnesque facilisis id vix, at dico choro perpetua est, et dolore oblique vituperata qui.\n\nLorem ipsum dolor sit amet, an sit fugit officiis deserunt, audiam disputando at sit. Eu mel expetenda voluptatibus. Ius no accusam scripserit.\n\n Sea error iracundia ne, duo ne dicat partem sententiae. Nibh admodum facilisi ius in. Ius legere intellegam ei, in zril deserunt qui.At alii audire scripta mea, errem disputando quo in.\n\n Elit vocent legimus cum ei. Eu nonumes eligendi pericula sit. Ceteros omnesque facilisis id vix, at dico choro perpetua est, et dolore oblique vituperata qui. \n\nLorem ipsum dolor sit amet, an sit fugit officiis deserunt, audiam disputando at sit. Eu mel expetenda voluptatibus. Ius no accusam scripserit.\n\n Sea error iracundia ne, duo ne dicat partem sententiae. Nibh admodum facilisi ius in. Ius legere intellegam ei, in zril deserunt qui.At alii audire scripta mea, errem disputando quo in.\n\n Elit vocent legimus cum ei. Eu nonumes eligendi pericula sit. Ceteros omnesque facilisis id vix, at dico choro perpetua est, et dolore oblique vituperata qui.
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/test/java/iammert/com/view/scalinglayout/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package iammert.com.view.scalinglayout;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() throws Exception {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/art/cover_scaling.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/iammert/ScalingLayout/f19164d4c4e08f93ddeb9f40aaa39e2025d1b866/art/cover_scaling.png
--------------------------------------------------------------------------------
/art/gif_behavior.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/iammert/ScalingLayout/f19164d4c4e08f93ddeb9f40aaa39e2025d1b866/art/gif_behavior.gif
--------------------------------------------------------------------------------
/art/gif_coordinator.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/iammert/ScalingLayout/f19164d4c4e08f93ddeb9f40aaa39e2025d1b866/art/gif_coordinator.gif
--------------------------------------------------------------------------------
/art/gif_fab.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/iammert/ScalingLayout/f19164d4c4e08f93ddeb9f40aaa39e2025d1b866/art/gif_fab.gif
--------------------------------------------------------------------------------
/art/gif_searchbar.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/iammert/ScalingLayout/f19164d4c4e08f93ddeb9f40aaa39e2025d1b866/art/gif_searchbar.gif
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 |
5 | repositories {
6 | maven { url 'https://maven.google.com' }
7 | jcenter()
8 | }
9 | dependencies {
10 | classpath 'com.android.tools.build:gradle:3.0.1'
11 |
12 | // NOTE: Do not place your application dependencies here; they belong
13 | // in the individual module build.gradle files
14 | }
15 | }
16 |
17 | allprojects {
18 | repositories {
19 | jcenter()
20 | maven { url 'https://maven.google.com' }
21 | }
22 | }
23 |
24 | task clean(type: Delete) {
25 | delete rootProject.buildDir
26 | }
27 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | org.gradle.jvmargs=-Xmx1536m
13 |
14 | # When configured, Gradle will run in incubating parallel mode.
15 | # This option should only be used with decoupled projects. More details, visit
16 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
17 | # org.gradle.parallel=true
18 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/iammert/ScalingLayout/f19164d4c4e08f93ddeb9f40aaa39e2025d1b866/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Sat Sep 30 14:01:47 EEST 2017
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip
7 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/scalinglib/.gitignore:
--------------------------------------------------------------------------------
1 | # Built application files
2 | *.apk
3 | *.ap_
4 |
5 | # Files for the ART/Dalvik VM
6 | *.dex
7 |
8 | # Java class files
9 | *.class
10 |
11 | # Generated files
12 | bin/
13 | gen/
14 | out/
15 |
16 | # Gradle files
17 | .gradle/
18 | build/
19 |
20 | # Local configuration file (sdk path, etc)
21 | local.properties
22 |
23 | # Proguard folder generated by Eclipse
24 | proguard/
25 |
26 | # Log Files
27 | *.log
28 |
29 | # Android Studio Navigation editor temp files
30 | .navigation/
31 |
32 | # Android Studio captures folder
33 | captures/
34 |
35 | # Intellij
36 | *.iml
37 | .idea/workspace.xml
38 | .idea/tasks.xml
39 | .idea/gradle.xml
40 | .idea/dictionaries
41 | .idea/libraries
42 |
43 | # Keystore files
44 | *.jks
45 |
46 | # External native build folder generated in Android Studio 2.2 and later
47 | .externalNativeBuild
48 |
49 | # Google Services (e.g. APIs or Firebase)
50 | google-services.json
51 |
52 | # Freeline
53 | freeline.py
54 | freeline/
55 | freeline_project_description.json
--------------------------------------------------------------------------------
/scalinglib/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 |
3 |
4 | android {
5 | compileSdkVersion 26
6 | buildToolsVersion "26.0.2"
7 |
8 |
9 | defaultConfig {
10 | minSdkVersion 15
11 | targetSdkVersion 26
12 | versionCode 1
13 | versionName "1.0"
14 |
15 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
16 |
17 | }
18 | buildTypes {
19 | release {
20 | minifyEnabled false
21 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
22 | }
23 | }
24 | }
25 |
26 | dependencies {
27 | compile fileTree(dir: 'libs', include: ['*.jar'])
28 | compile 'com.android.support:design:26.1.0'
29 | }
30 |
--------------------------------------------------------------------------------
/scalinglib/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/mertsimsek/Library/Android/sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
19 | # Uncomment this to preserve the line number information for
20 | # debugging stack traces.
21 | #-keepattributes SourceFile,LineNumberTable
22 |
23 | # If you keep the line number information, uncomment this to
24 | # hide the original source file name.
25 | #-renamesourcefileattribute SourceFile
26 |
--------------------------------------------------------------------------------
/scalinglib/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
--------------------------------------------------------------------------------
/scalinglib/src/main/java/iammert/com/view/scalinglib/ScalingLayout.java:
--------------------------------------------------------------------------------
1 | package iammert.com.view.scalinglib;
2 |
3 | import android.animation.ValueAnimator;
4 | import android.annotation.SuppressLint;
5 | import android.annotation.TargetApi;
6 | import android.content.Context;
7 | import android.graphics.Canvas;
8 | import android.graphics.Outline;
9 | import android.graphics.Paint;
10 | import android.graphics.Path;
11 | import android.graphics.PorterDuff;
12 | import android.graphics.PorterDuffXfermode;
13 | import android.graphics.RectF;
14 | import android.os.Build;
15 | import android.support.annotation.NonNull;
16 | import android.support.annotation.Nullable;
17 | import android.support.v4.view.ViewCompat;
18 | import android.util.AttributeSet;
19 | import android.view.View;
20 | import android.view.ViewGroup;
21 | import android.view.ViewOutlineProvider;
22 | import android.widget.FrameLayout;
23 |
24 | /**
25 | * Created by mertsimsek on 30/09/2017.
26 | */
27 |
28 | public class ScalingLayout extends FrameLayout {
29 |
30 | /**
31 | * Settings
32 | */
33 | ScalingLayoutSettings settings;
34 |
35 | /**
36 | * Current radius
37 | */
38 | private float currentRadius;
39 |
40 | /**
41 | * Width is dependent value. It depends on
42 | * radius. If radius gets updated,
43 | * layout width will be updated according to this change.
44 | */
45 | private int currentWidth;
46 |
47 | /**
48 | * If layout has margins, margin has to be change
49 | * according to radius.
50 | */
51 | private float[] maxMargins;
52 | private float[] currentMargins;
53 |
54 | /**
55 | * State for layout.
56 | */
57 | private State state;
58 |
59 | /**
60 | * Values to draw rounded on layout
61 | */
62 | private Path path;
63 | private Path outlinePath;
64 | private RectF rectF;
65 | private Paint maskPaint;
66 |
67 | /**
68 | * Animator to expand and collapse
69 | */
70 | private ValueAnimator valueAnimator;
71 |
72 | /**
73 | * Listener to notify observer about
74 | * progress and collapse/expand
75 | */
76 | private ScalingLayoutListener scalingLayoutListener;
77 |
78 | /**
79 | * CustomOutline for elevation shadows
80 | */
81 | @Nullable
82 | private ScalingLayoutOutlineProvider viewOutline;
83 |
84 |
85 | public ScalingLayout(@NonNull Context context) {
86 | super(context);
87 | init(context, null);
88 | }
89 |
90 | public ScalingLayout(@NonNull Context context, @Nullable AttributeSet attrs) {
91 | super(context, attrs);
92 | init(context, attrs);
93 | }
94 |
95 | public ScalingLayout(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
96 | super(context, attrs, defStyleAttr);
97 | init(context, attrs);
98 | }
99 |
100 | @SuppressLint("NewApi")
101 | public ScalingLayout(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr, int defStyleRes) {
102 | super(context, attrs, defStyleAttr, defStyleRes);
103 | init(context, attrs);
104 | }
105 |
106 | /**
107 | * Initialize layout
108 | *
109 | * @param context
110 | * @param attributeSet
111 | */
112 | public void init(Context context, AttributeSet attributeSet) {
113 | settings = new ScalingLayoutSettings(context, attributeSet);
114 | settings.setElevation(ViewCompat.getElevation(this));
115 | state = State.COLLAPSED;
116 |
117 | path = new Path();
118 | outlinePath = new Path();
119 | rectF = new RectF(0, 0, 0, 0);
120 |
121 | maskPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
122 | maskPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_IN));
123 |
124 | setLayerType(LAYER_TYPE_HARDWARE, null);
125 |
126 | valueAnimator = ValueAnimator.ofFloat(0, 0);
127 | valueAnimator.setDuration(200);
128 | valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
129 | @Override
130 | public void onAnimationUpdate(ValueAnimator valueAnimator) {
131 | setRadius((Float) valueAnimator.getAnimatedValue());
132 | }
133 | });
134 | }
135 |
136 | @Override
137 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
138 | super.onMeasure(widthMeasureSpec, heightMeasureSpec);
139 | if (maxMargins == null) {
140 | maxMargins = new float[4];
141 | currentMargins = new float[4];
142 | ViewGroup.MarginLayoutParams marginLayoutParams = ((ViewGroup.MarginLayoutParams) getLayoutParams());
143 | currentMargins[0] = maxMargins[0] = marginLayoutParams.leftMargin;
144 | currentMargins[1] = maxMargins[1] = marginLayoutParams.topMargin;
145 | currentMargins[2] = maxMargins[2] = marginLayoutParams.rightMargin;
146 | currentMargins[3] = maxMargins[3] = marginLayoutParams.bottomMargin;
147 | }
148 | }
149 |
150 | @Override
151 | protected void onSizeChanged(int w, int h, int oldw, int oldh) {
152 | super.onSizeChanged(w, h, oldw, oldh);
153 | if (!settings.isInitialized()) {
154 | settings.initialize(w, h);
155 | currentWidth = w;
156 | currentRadius = settings.getMaxRadius();
157 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
158 | viewOutline = new ScalingLayoutOutlineProvider(w, h, currentRadius);
159 | }
160 | }
161 |
162 | rectF.set(0, 0, w, h);
163 | updateViewOutline(h, currentWidth, currentRadius);
164 | invalidate();
165 | }
166 |
167 | @Override
168 | protected void dispatchDraw(Canvas canvas) {
169 | int save = canvas.save();
170 | super.dispatchDraw(canvas);
171 | canvas.restoreToCount(save);
172 |
173 | path.reset();
174 | path.addRoundRect(rectF, currentRadius, currentRadius, Path.Direction.CCW);
175 | canvas.drawPath(path, maskPaint);
176 | }
177 |
178 | /**
179 | * Provides current {@link ScalingLayoutSettings}
180 | *
181 | * @return
182 | */
183 | public ScalingLayoutSettings getSettings() {
184 | return settings;
185 | }
186 |
187 | /**
188 | * get current state of layout
189 | *
190 | * @return
191 | */
192 | public State getState() {
193 | return state;
194 | }
195 |
196 | /**
197 | * Expand layout to screen
198 | */
199 | public void expand() {
200 | valueAnimator.setFloatValues(settings.getMaxRadius(), 0);
201 | valueAnimator.start();
202 | }
203 |
204 | /**
205 | * Collapse layout to initial position
206 | */
207 | public void collapse() {
208 | valueAnimator.setFloatValues(0, settings.getMaxRadius());
209 | valueAnimator.start();
210 | }
211 |
212 | /**
213 | * This method takes a progress parameter value
214 | * between 0.0f and 1.0f. And apply this
215 | * progress value to layout.
216 | *
217 | * @param progress
218 | */
219 | public void setProgress(float progress) {
220 | if (progress > 1.0f || progress < 0.0f) {
221 | return;
222 | }
223 | setRadius(settings.getMaxRadius() - settings.getMaxRadius() * progress);
224 | }
225 |
226 | public void setListener(ScalingLayoutListener scalingLayoutListener) {
227 | this.scalingLayoutListener = scalingLayoutListener;
228 | }
229 |
230 | /**
231 | * Updates view outline borders and radius
232 | *
233 | * @param height
234 | * @param width
235 | * @param radius
236 | */
237 | private void updateViewOutline(int height, int width, float radius) {
238 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && ViewCompat.getElevation(this) > 0f) {
239 | try {
240 | viewOutline.setHeight(height);
241 | viewOutline.setWidth(width);
242 | viewOutline.setRadius(radius);
243 | setOutlineProvider(viewOutline);
244 | } catch (Exception e) {
245 | e.printStackTrace();
246 | }
247 | }
248 | }
249 |
250 | /**
251 | * Set radius will update layout radius
252 | * Also layouts margins and width depend on
253 | * radius. So If you update radius, your layout's width
254 | * and margins will be updated.
255 | *
256 | * @param radius
257 | */
258 | private void setRadius(float radius) {
259 | if (radius < 0) {
260 | return;
261 | }
262 |
263 | updateCurrentRadius(radius);
264 | updateCurrentWidth(currentRadius);
265 | updateCurrentMargins(currentRadius);
266 | updateState(currentRadius);
267 | updateCurrentElevation();
268 |
269 | getLayoutParams().width = currentWidth;
270 | ((ViewGroup.MarginLayoutParams) getLayoutParams())
271 | .setMargins((int) currentMargins[0],
272 | (int) currentMargins[1],
273 | (int) currentMargins[2],
274 | (int) currentMargins[3]);
275 | requestLayout();
276 | }
277 |
278 | /**
279 | * Update current radius
280 | *
281 | * @param radius
282 | */
283 | private void updateCurrentRadius(float radius) {
284 | currentRadius = radius < settings.getMaxRadius() ? radius : settings.getMaxRadius();
285 | }
286 |
287 | /**
288 | * Update layout width with given radius value
289 | *
290 | * @param currentRadius
291 | */
292 | private void updateCurrentWidth(float currentRadius) {
293 | int diffPixel = settings.getMaxWidth() - settings.getInitialWidth();
294 | float calculatedWidth = (diffPixel - (currentRadius * diffPixel / settings.getMaxRadius())) + settings.getInitialWidth();
295 | if (calculatedWidth > settings.getMaxWidth()) {
296 | currentWidth = settings.getMaxWidth();
297 | } else if (calculatedWidth < settings.getInitialWidth()) {
298 | currentWidth = settings.getInitialWidth();
299 | } else {
300 | currentWidth = (int) calculatedWidth;
301 | }
302 | }
303 |
304 | /**
305 | * Update layout margins with given radius value
306 | *
307 | * @param currentRadius
308 | */
309 | private void updateCurrentMargins(float currentRadius) {
310 | currentMargins[0] = maxMargins[0] * currentRadius / settings.getMaxRadius();
311 | currentMargins[1] = maxMargins[1] * currentRadius / settings.getMaxRadius();
312 | currentMargins[2] = maxMargins[2] * currentRadius / settings.getMaxRadius();
313 | currentMargins[3] = maxMargins[3] * currentRadius / settings.getMaxRadius();
314 | }
315 |
316 | /**
317 | * Updates layout state
318 | *
319 | * @param currentRadius
320 | */
321 | private void updateState(float currentRadius) {
322 | if (currentRadius == 0) {
323 | state = State.EXPANDED;
324 | } else if (currentRadius == settings.getMaxRadius()) {
325 | state = State.COLLAPSED;
326 | } else {
327 | state = State.PROGRESSING;
328 | }
329 | notifyListener();
330 | }
331 |
332 | private void updateCurrentElevation() {
333 | ViewCompat.setElevation(this, settings.getElevation());
334 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && ViewCompat.getElevation(this) > 0f) {
335 | try {
336 | setOutlineProvider(getOutlineProvider());
337 | } catch (Exception e) {
338 | e.printStackTrace();
339 | }
340 | }
341 | }
342 |
343 | /**
344 | * Notify observers about change
345 | */
346 | private void notifyListener() {
347 | if (scalingLayoutListener != null) {
348 | if (state == State.COLLAPSED) {
349 | scalingLayoutListener.onCollapsed();
350 | } else if (state == State.EXPANDED) {
351 | scalingLayoutListener.onExpanded();
352 | } else {
353 | scalingLayoutListener.onProgress(currentRadius / settings.getMaxRadius());
354 | }
355 | }
356 | }
357 |
358 | @TargetApi(Build.VERSION_CODES.LOLLIPOP)
359 | @Override
360 | public ViewOutlineProvider getOutlineProvider() {
361 | return new ViewOutlineProvider() {
362 | @Override
363 | public void getOutline(View view, Outline outline) {
364 | outline.setConvexPath(path);
365 | }
366 | };
367 | }
368 | }
369 |
--------------------------------------------------------------------------------
/scalinglib/src/main/java/iammert/com/view/scalinglib/ScalingLayoutBehavior.java:
--------------------------------------------------------------------------------
1 | package iammert.com.view.scalinglib;
2 |
3 | import android.content.Context;
4 | import android.support.design.widget.AppBarLayout;
5 | import android.support.design.widget.CoordinatorLayout;
6 | import android.util.AttributeSet;
7 | import android.view.View;
8 |
9 | /**
10 | * Created by mertsimsek on 30/09/2017.
11 | */
12 |
13 | public class ScalingLayoutBehavior extends CoordinatorLayout.Behavior {
14 |
15 | private final float toolbarHeightInPixel;
16 |
17 | public ScalingLayoutBehavior(Context context, AttributeSet attrs) {
18 | super(context, attrs);
19 | toolbarHeightInPixel = context.getResources().getDimensionPixelSize(R.dimen.sl_toolbar_size);
20 | }
21 |
22 | @Override
23 | public boolean layoutDependsOn(CoordinatorLayout parent, ScalingLayout child, View dependency) {
24 | return dependency instanceof AppBarLayout;
25 | }
26 |
27 | @Override
28 | public boolean onDependentViewChanged(CoordinatorLayout parent, ScalingLayout child, View dependency) {
29 | int totalScrollRange = ((AppBarLayout) dependency).getTotalScrollRange();
30 | child.setProgress((-dependency.getY()) / totalScrollRange);
31 | if (totalScrollRange + dependency.getY() > (float) child.getMeasuredHeight() / 2) {
32 | child.setTranslationY(totalScrollRange + dependency.getY() + toolbarHeightInPixel - (float) child.getMeasuredHeight() / 2);
33 | } else {
34 | child.setTranslationY(toolbarHeightInPixel);
35 | }
36 | return super.onDependentViewChanged(parent, child, dependency);
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/scalinglib/src/main/java/iammert/com/view/scalinglib/ScalingLayoutListener.java:
--------------------------------------------------------------------------------
1 | package iammert.com.view.scalinglib;
2 |
3 | /**
4 | * Created by mertsimsek on 01/10/2017.
5 | */
6 |
7 | public interface ScalingLayoutListener {
8 |
9 | void onCollapsed();
10 |
11 | void onExpanded();
12 |
13 | void onProgress(float progress);
14 | }
15 |
--------------------------------------------------------------------------------
/scalinglib/src/main/java/iammert/com/view/scalinglib/ScalingLayoutOutlineProvider.java:
--------------------------------------------------------------------------------
1 | package iammert.com.view.scalinglib;
2 |
3 | import android.graphics.Outline;
4 | import android.os.Build;
5 | import android.support.annotation.RequiresApi;
6 | import android.view.View;
7 | import android.view.ViewOutlineProvider;
8 |
9 | /**
10 | * Created by mertsimsek on 08/01/2018.
11 | */
12 | @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
13 | public class ScalingLayoutOutlineProvider extends ViewOutlineProvider {
14 |
15 | private int width;
16 | private int height;
17 | private float radius;
18 |
19 | ScalingLayoutOutlineProvider(int width, int height, float radius) {
20 | this.width = width;
21 | this.height = height;
22 | this.radius = radius;
23 | }
24 |
25 | @Override
26 | public void getOutline(View view, Outline outline) {
27 | outline.setRoundRect(0, 0, width, height, radius);
28 | }
29 |
30 | public int getWidth() {
31 | return width;
32 | }
33 |
34 | public void setWidth(int width) {
35 | this.width = width;
36 | }
37 |
38 | public int getHeight() {
39 | return height;
40 | }
41 |
42 | public void setHeight(int height) {
43 | this.height = height;
44 | }
45 |
46 | public float getRadius() {
47 | return radius;
48 | }
49 |
50 | public void setRadius(float radius) {
51 | this.radius = radius;
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/scalinglib/src/main/java/iammert/com/view/scalinglib/ScalingLayoutSettings.java:
--------------------------------------------------------------------------------
1 | package iammert.com.view.scalinglib;
2 |
3 | import android.content.Context;
4 | import android.content.res.TypedArray;
5 | import android.util.AttributeSet;
6 |
7 | /**
8 | * Created by mertsimsek on 30/09/2017.
9 | */
10 |
11 | public class ScalingLayoutSettings {
12 |
13 | private static final float DEFAULT_RADIUS_FACTOR = 1.0f;
14 |
15 | private float radiusFactor;
16 | private int initialWidth;
17 | private int maxWidth;
18 | private float maxRadius;
19 | private float elevation;
20 | private boolean isInitialized = false;
21 |
22 | public ScalingLayoutSettings(Context context, AttributeSet attributeSet) {
23 | TypedArray typedArray = context.obtainStyledAttributes(attributeSet, R.styleable.ScalingLayout);
24 | radiusFactor = typedArray.getFloat(R.styleable.ScalingLayout_radiusFactor, DEFAULT_RADIUS_FACTOR);
25 | maxWidth = context.getResources().getDisplayMetrics().widthPixels;
26 | typedArray.recycle();
27 |
28 | if (radiusFactor > DEFAULT_RADIUS_FACTOR) {
29 | radiusFactor = DEFAULT_RADIUS_FACTOR;
30 | }
31 | }
32 |
33 | public void initialize(int width, int height) {
34 | if (!isInitialized) {
35 | isInitialized = true;
36 | initialWidth = width;
37 | float radiusLimit = height / 2;
38 | maxRadius = radiusLimit * radiusFactor;
39 | }
40 | }
41 |
42 | public int getInitialWidth() {
43 | return initialWidth;
44 | }
45 |
46 | public int getMaxWidth() {
47 | return maxWidth;
48 | }
49 |
50 | public float getMaxRadius() {
51 | return maxRadius;
52 | }
53 |
54 | public boolean isInitialized() {
55 | return isInitialized;
56 | }
57 |
58 | public void setElevation(float elevation) {
59 | this.elevation = elevation;
60 | }
61 |
62 | public float getElevation() {
63 | return elevation;
64 | }
65 | }
66 |
--------------------------------------------------------------------------------
/scalinglib/src/main/java/iammert/com/view/scalinglib/State.java:
--------------------------------------------------------------------------------
1 | package iammert.com.view.scalinglib;
2 |
3 | /**
4 | * Created by mertsimsek on 01/10/2017.
5 | */
6 |
7 | public enum State {
8 | EXPANDED, COLLAPSED, PROGRESSING
9 | }
10 |
--------------------------------------------------------------------------------
/scalinglib/src/main/res/animator/sl_state_animator.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | -
5 |
6 |
11 |
12 |
17 |
18 |
23 |
24 |
25 |
26 |
27 | -
28 |
29 |
34 |
35 |
40 |
41 |
46 |
47 |
48 |
49 |
--------------------------------------------------------------------------------
/scalinglib/src/main/res/values/attrs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/scalinglib/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 56dp
4 |
--------------------------------------------------------------------------------
/scalinglib/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | scalinglib
3 |
4 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app', ':scalinglib'
2 |
--------------------------------------------------------------------------------