├── .gitignore ├── LICENSE.md ├── README.md ├── build.gradle ├── demoapp ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── com │ │ └── telenav │ │ └── demoapp │ │ ├── Book.java │ │ ├── BookAdapter.java │ │ ├── BookGridAdapter.java │ │ ├── MainActivity.java │ │ ├── OnItemClickedListener.java │ │ └── fragment │ │ ├── BookFragment.java │ │ ├── BookFragmentAdapter.java │ │ └── BookFragmentStateAdapter.java │ └── res │ ├── drawable-hdpi │ ├── ic_favorite_border_white_36dp.png │ ├── ic_library_add_white_36dp.png │ ├── ic_local_library_white_36dp.png │ └── ic_shopping_cart_white_36dp.png │ ├── drawable-mdpi │ ├── ic_favorite_border_white_36dp.png │ ├── ic_library_add_white_36dp.png │ ├── ic_local_library_white_36dp.png │ └── ic_shopping_cart_white_36dp.png │ ├── drawable-xhdpi │ ├── ic_favorite_border_white_36dp.png │ ├── ic_library_add_white_36dp.png │ ├── ic_local_library_white_36dp.png │ └── ic_shopping_cart_white_36dp.png │ ├── drawable-xxhdpi │ ├── ic_favorite_border_white_36dp.png │ ├── ic_library_add_white_36dp.png │ ├── ic_local_library_white_36dp.png │ └── ic_shopping_cart_white_36dp.png │ ├── drawable-xxxhdpi │ ├── ic_favorite_border_white_36dp.png │ ├── ic_library_add_white_36dp.png │ ├── ic_local_library_white_36dp.png │ └── ic_shopping_cart_white_36dp.png │ ├── layout-land │ └── page.xml │ ├── layout-large-land │ └── page.xml │ ├── layout-large │ ├── header.xml │ └── page.xml │ ├── layout │ ├── activity_main.xml │ ├── cell.xml │ ├── header.xml │ └── page.xml │ ├── menu │ └── menu.xml │ ├── mipmap-hdpi │ └── ic_launcher.png │ ├── mipmap-mdpi │ └── ic_launcher.png │ ├── mipmap-xhdpi │ └── ic_launcher.png │ ├── mipmap-xxhdpi │ └── ic_launcher.png │ ├── mipmap-xxxhdpi │ └── ic_launcher.png │ ├── values-large │ └── dimens.xml │ ├── values-w820dp │ └── dimens.xml │ └── values │ ├── colors.xml │ ├── dimens.xml │ ├── strings.xml │ └── styles.xml ├── expandablepager ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── com │ │ └── telenav │ │ └── expandablepager │ │ ├── ExpandablePager.java │ │ ├── SlidingContainer.java │ │ ├── adapter │ │ ├── ExpandableFragmentPagerAdapter.java │ │ ├── ExpandableFragmentStatePagerAdapter.java │ │ └── ExpandablePagerAdapter.java │ │ └── listener │ │ ├── OnItemSelectedListener.java │ │ ├── OnSlideListener.java │ │ └── OnSliderStateChangeListener.java │ └── res │ └── values │ └── attrs.xml ├── gif └── expandablepager.gif ├── gradle.properties ├── gradlew ├── gradlew.bat └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea 5 | .DS_Store 6 | /build 7 | /captures 8 | /gradle 9 | /javadoc 10 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | © 2016 Telenav, Inc. All Rights Reserved 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"). 4 | 5 | You may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0. Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 6 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [ ![Download](https://api.bintray.com/packages/dimatim/maven/ExpandablePager/images/download.svg) ](https://bintray.com/dimatim/maven/ExpandablePager/_latestVersion) 2 | [![Android Arsenal](https://img.shields.io/badge/Android%20Arsenal-ExpandablePager-blue.svg?style=flat)](http://android-arsenal.com/details/1/3278) 3 | 4 | # ExpandablePager 5 | Layout that contains a ViewPager and can slide vertically between 2 states (expanded and collapsed). 6 | 7 | ![alt tag](https://github.com/Telenav/ExpandablePager/blob/master/gif/expandablepager.gif?token=AMYIVqqzN85dOdOY4DOfk2wC-i8R7RxNks5W1HArwA%3D%3D "Demo") 8 | #Requirements 9 | Android 4.0+ (Ice Cream Sandwich and later) 10 | #Setup 11 | ###Step 1 12 | Add the following line to the ```dependencies``` section of your ```build.gradle``` file 13 | ```gradle 14 | compile 'com.telenav.expandablepager:expandablepager:0.2.1' 15 | ``` 16 | ###Step 2 17 | Extend desired adapter: 18 | - ExpandablePagerAdapter (don't forget to override `instantiateItem`) 19 | ```java 20 | public class MyAdapter extends ExpandablePagerAdapter { 21 | 22 | ... 23 | 24 | @Override 25 | public Object instantiateItem(ViewGroup container, int position) { 26 | final ViewGroup rootView = (ViewGroup) LayoutInflater.from(container.getContext()).inflate(R.layout.page, container, false); //inflate view 27 | 28 | ... 29 | 30 | return attach(container, rootView, position); //don't forget to return the result of attach() 31 | } 32 | } 33 | ``` 34 | - ExpandableFragmentPagerAdapter 35 | - ExpandableFragmentStatePagerAdapter 36 | 37 | ###Step 3 38 | Add ExpandablePager to a layout 39 | ```xml 40 | 41 | RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 42 | xmlns:app="http://schemas.android.com/apk/res-auto" 43 | android:layout_width="match_parent" 44 | android:layout_height="match_parent"> 45 | 46 | //pin the pager to the bootom of the screen using layout_gravity or layout_alignParentBottom 52 | 53 | ``` 54 | ###Step 4 55 | Create and pass your adapter to the ExpandablePager 56 | ```java 57 | MyAdapter adapter = new MyAdapter(myData); 58 | ExpandablePager pager = (ExpandablePager) findViewById(R.id.container); 59 | pager.setAdapter(adapter); 60 | ``` 61 | ###Step 5 (optional) 62 | * Set collapsed height & animation duration via xml 63 | ```xml 64 | app:animation_duration="200" 65 | app:collapsed_height="@dimen/header_height" 66 | ``` 67 | or programmatically 68 | ```java 69 | pager.setAnimationDuration(duration); 70 | pager.setCollapsedHeight((int) getResources().getDimension(R.dimen.header_height)); 71 | ``` 72 | * Set display mode (MODE_REGULAR or MODE_FIXED) 73 | ```java 74 | pager.setMode(ExpandablePager.MODE_REGULAR); 75 | ``` 76 | #Extras 77 | Change pager state (supported states are STATE_COLLAPSED, STATE_EXPANDED, and STATE_HIDDEN) 78 | ```java 79 | pager.setState(ExpandablePager.STATE_COLLAPSED) 80 | ``` 81 | Animate pager state change 82 | ```java 83 | pager.animateToState(ExpandablePager.STATE_COLLAPSED) 84 | ``` 85 | Set current item 86 | ```java 87 | pager.setCurrentItem(index, false); 88 | ``` 89 | Set listeners 90 | ```java 91 | pager.setOnSliderStateChangeListener(new OnSliderStateChangeListener() { 92 | 93 | @Override 94 | public void onStateChanged(View page, int index, int state) { 95 | ... 96 | } 97 | 98 | @Override 99 | public void onPageChanged(View page, int index, int state) { 100 | ... 101 | } 102 | }); 103 | 104 | pager.setOnItemSelectedListener(new OnItemSelectedListener() { 105 | @Override 106 | public void onItemSelected(List items, int index) { 107 | ... 108 | } 109 | }); 110 | ``` 111 | 112 | #Sample 113 | For a more detailed example check the [demoapp](https://github.com/Telenav/ExpandablePager/tree/master/demoapp) module. 114 | 115 | #License 116 | [Apache License, Version 2.0](https://github.com/Telenav/ExpandablePager/blob/master/LICENSE.md) 117 | -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 2 | 3 | buildscript { 4 | repositories { 5 | jcenter() 6 | } 7 | dependencies { 8 | classpath 'com.android.tools.build:gradle:2.0.0-beta6' 9 | 10 | // NOTE: Do not place your application dependencies here; they belong 11 | // in the individual module build.gradle files 12 | } 13 | } 14 | 15 | allprojects { 16 | repositories { 17 | jcenter() 18 | } 19 | } 20 | 21 | task clean(type: Delete) { 22 | delete rootProject.buildDir 23 | } 24 | -------------------------------------------------------------------------------- /demoapp/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /demoapp/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 23 5 | buildToolsVersion "23.0.2" 6 | 7 | defaultConfig { 8 | applicationId "com.telenav.expandableviewpager" 9 | minSdkVersion 16 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 | testCompile 'junit:junit:4.12' 25 | compile 'com.android.support:appcompat-v7:23.2.0' 26 | compile 'com.facebook.fresco:fresco:0.9.0+' 27 | compile 'com.android.support:recyclerview-v7:23.2.0' 28 | compile project(path: ':expandablepager') 29 | } 30 | -------------------------------------------------------------------------------- /demoapp/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 /home/dima/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 | -------------------------------------------------------------------------------- /demoapp/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /demoapp/src/main/java/com/telenav/demoapp/Book.java: -------------------------------------------------------------------------------- 1 | package com.telenav.demoapp; 2 | 3 | public class Book { 4 | private String title; 5 | private String author; 6 | private String description; 7 | private String url; 8 | 9 | public Book(String title) { 10 | this.title = title; 11 | } 12 | 13 | public String getTitle() { 14 | return title; 15 | } 16 | 17 | public Book setTitle(String title) { 18 | this.title = title; 19 | return this; 20 | } 21 | 22 | public String getAuthor() { 23 | return author; 24 | } 25 | 26 | public Book setAuthor(String author) { 27 | this.author = author; 28 | return this; 29 | } 30 | 31 | public String getDescription() { 32 | return description; 33 | } 34 | 35 | public Book setDescription(String description) { 36 | this.description = description; 37 | return this; 38 | } 39 | 40 | public String getUrl() { 41 | return url; 42 | } 43 | 44 | public Book setUrl(String url) { 45 | this.url = url; 46 | return this; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /demoapp/src/main/java/com/telenav/demoapp/BookAdapter.java: -------------------------------------------------------------------------------- 1 | package com.telenav.demoapp; 2 | 3 | import android.net.Uri; 4 | import android.text.Spannable; 5 | import android.text.SpannableString; 6 | import android.text.style.RelativeSizeSpan; 7 | import android.view.LayoutInflater; 8 | import android.view.ViewGroup; 9 | import android.widget.RelativeLayout; 10 | import android.widget.TextView; 11 | 12 | import com.facebook.drawee.view.SimpleDraweeView; 13 | 14 | import java.util.List; 15 | import java.util.regex.Matcher; 16 | import java.util.regex.Pattern; 17 | 18 | import com.telenav.expandablepager.adapter.ExpandablePagerAdapter; 19 | import com.telenav.expandableviewpager.R; 20 | 21 | public class BookAdapter extends ExpandablePagerAdapter { 22 | public BookAdapter(List items) { 23 | super(items); 24 | } 25 | 26 | @Override 27 | public Object instantiateItem(ViewGroup container, int position) { 28 | final ViewGroup rootView = (ViewGroup) LayoutInflater.from(container.getContext()).inflate(R.layout.page, container, false); 29 | rootView.setLayoutParams(new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT)); 30 | ((TextView) rootView.findViewById(R.id.text)).setText(items.get(position).getDescription()); 31 | ((TextView) rootView.findViewById(R.id.header_title)).setText(items.get(position).getTitle()); 32 | ((TextView) rootView.findViewById(R.id.header_subtitle)).setText(items.get(position).getAuthor()); 33 | ((SimpleDraweeView) rootView.findViewById(R.id.header_img)).setImageURI(Uri.parse(items.get(position).getUrl())); 34 | if (rootView.findViewById(R.id.cell_img) != null) 35 | ((SimpleDraweeView) rootView.findViewById(R.id.cell_img)).setImageURI(Uri.parse(items.get(position).getUrl())); 36 | 37 | TextView rating = ((TextView) rootView.findViewById(R.id.page_rating)); 38 | setSpan(rating, "\\d\\.\\d / \\d\\.\\d"); 39 | 40 | TextView reviews = ((TextView) rootView.findViewById(R.id.page_reviews)); 41 | setSpan(reviews, "\\d+"); 42 | 43 | TextView comments = ((TextView) rootView.findViewById(R.id.page_comments)); 44 | setSpan(comments, "\\d+,*\\d+"); 45 | 46 | return attach(container, rootView, position); 47 | } 48 | 49 | private void setSpan(TextView textView, String pattern) { 50 | float relativeSize = 1.5f; 51 | Pattern pat = Pattern.compile(pattern); 52 | Matcher m = pat.matcher(textView.getText()); 53 | if (m.find()) { 54 | SpannableString span = new SpannableString(textView.getText()); 55 | span.setSpan(new RelativeSizeSpan(relativeSize), 0, m.group(0).length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); 56 | textView.setText(span); 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /demoapp/src/main/java/com/telenav/demoapp/BookGridAdapter.java: -------------------------------------------------------------------------------- 1 | package com.telenav.demoapp; 2 | 3 | import android.net.Uri; 4 | import android.support.v7.widget.RecyclerView; 5 | import android.view.LayoutInflater; 6 | import android.view.View; 7 | import android.view.ViewGroup; 8 | import android.widget.RelativeLayout; 9 | import android.widget.TextView; 10 | 11 | import com.facebook.drawee.view.SimpleDraweeView; 12 | 13 | import java.util.List; 14 | 15 | import com.telenav.expandableviewpager.R; 16 | 17 | public class BookGridAdapter extends RecyclerView.Adapter { 18 | private OnItemClickedListener listener; 19 | private List mDataset; 20 | 21 | public static class ViewHolder extends RecyclerView.ViewHolder { 22 | public TextView title; 23 | public TextView subtitle; 24 | public SimpleDraweeView image; 25 | public ViewGroup container; 26 | 27 | public ViewHolder(RelativeLayout v) { 28 | super(v); 29 | container = v; 30 | title = (TextView) v.findViewById(R.id.cell_text); 31 | subtitle = (TextView) v.findViewById(R.id.cell_subtitle); 32 | image = (SimpleDraweeView) v.findViewById(R.id.cell_img); 33 | } 34 | } 35 | 36 | public BookGridAdapter(List dataset) { 37 | mDataset = dataset; 38 | } 39 | 40 | @Override 41 | public BookGridAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, 42 | int viewType) { 43 | RelativeLayout v = (RelativeLayout) LayoutInflater.from(parent.getContext()) 44 | .inflate(R.layout.cell, parent, false); 45 | return new ViewHolder(v); 46 | } 47 | 48 | @Override 49 | public void onBindViewHolder(final ViewHolder holder, final int position) { 50 | holder.title.setText(mDataset.get(position).getTitle()); 51 | holder.subtitle.setText(mDataset.get(position).getAuthor()); 52 | Uri uri = Uri.parse(mDataset.get(position).getUrl()); 53 | holder.image.setImageURI(uri); 54 | holder.container.setOnClickListener(new View.OnClickListener() { 55 | @Override 56 | public void onClick(View v) { 57 | if (listener != null) 58 | listener.onItemClicked(holder.getAdapterPosition()); 59 | } 60 | }); 61 | 62 | } 63 | 64 | @Override 65 | public int getItemCount() { 66 | return mDataset.size(); 67 | } 68 | 69 | public void setListener(OnItemClickedListener listener) { 70 | this.listener = listener; 71 | } 72 | } -------------------------------------------------------------------------------- /demoapp/src/main/java/com/telenav/demoapp/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.telenav.demoapp; 2 | 3 | import android.animation.ValueAnimator; 4 | import android.content.res.Configuration; 5 | import android.os.Bundle; 6 | import android.support.v4.view.animation.FastOutSlowInInterpolator; 7 | import android.support.v7.app.AppCompatActivity; 8 | import android.support.v7.widget.GridLayoutManager; 9 | import android.support.v7.widget.RecyclerView; 10 | import android.view.Menu; 11 | import android.view.MenuInflater; 12 | import android.view.MenuItem; 13 | import android.view.View; 14 | 15 | import com.facebook.drawee.backends.pipeline.Fresco; 16 | import com.facebook.imagepipeline.core.ImagePipelineConfig; 17 | import com.telenav.demoapp.fragment.BookFragmentAdapter; 18 | import com.telenav.demoapp.fragment.BookFragmentStateAdapter; 19 | import com.telenav.expandablepager.ExpandablePager; 20 | import com.telenav.expandablepager.listener.OnSliderStateChangeListener; 21 | import com.telenav.expandableviewpager.R; 22 | 23 | import java.util.ArrayList; 24 | import java.util.Arrays; 25 | import java.util.List; 26 | 27 | public class MainActivity extends AppCompatActivity { 28 | 29 | int duration = 200; 30 | boolean two = false; 31 | private List list2 = Arrays.asList( 32 | new Book("Crime and Punishment").setAuthor("Fyodor Dostoyevsky").setUrl("http://ecx.images-amazon.com/images/I/51M%2BDuxvjmL._SX311_BO1,204,203,200_.jpg").setDescription("Crime and Punishment (Russian: Преступлéние и наказáние, tr. Prestupleniye i nakazaniye; IPA: [prʲɪstʊˈplʲenʲɪɪ ɪ nəkɐˈzanʲɪɪ]) is a novel by the Russian author Fyodor Dostoyevsky. It was first published in the literary journal The Russian Messenger in twelve monthly installments during 1866. It was later published in a single volume. It is the second of Dostoyevsky's full-length novels following his return from 10 years of exile in Siberia. Crime and Punishment is considered the first great novel of his \"mature\" period of writing."), 33 | new Book("The Brothers Karamazov").setAuthor("Fyodor Dostoyevsky").setUrl("http://ecx.images-amazon.com/images/I/51FIyYKsCXL._SX333_BO1,204,203,200_.jpg").setDescription("The Brothers Karamazov (Russian: Бра́тья Карама́зовы, Brat'ya Karamazovy, pronounced [ˈbratʲjə kərɐˈmazəvɨ]), also translated as The Karamazov Brothers, is the final novel by the Russian author Fyodor Dostoyevsky. Dostoyevsky spent nearly two years writing The Brothers Karamazov, which was published as a serial in The Russian Messenger and completed in November 1880. The author died less than four months after its publication."), 34 | new Book("Demons").setAuthor("Fyodor Dostoyevsky").setUrl("http://ecx.images-amazon.com/images/I/41Q-p2N1neL._SX326_BO1,204,203,200_.jpg").setDescription("Demons (Russian: Бесы, Bésy) is an anti-nihilistic novel by Fyodor Dostoyevsky, first published in the journal The Russian Messenger in 1871-2. It is the third of the four great novels written by Dostoyevsky after his return from Siberian exile, the others being Crime and Punishment (1866), The Idiot (1869) and The Brothers Karamazov (1880). Demons is a social and political satire, a psychological drama, and large scale tragedy. Joyce Carol Oates has described it as \"Dostoevsky's most confused and violent novel, and his most satisfyingly 'tragic' work.\"") 35 | ); 36 | private List list = Arrays.asList( 37 | new Book("Crime and Punishment").setAuthor("Fyodor Dostoyevsky").setUrl("http://ecx.images-amazon.com/images/I/51M%2BDuxvjmL._SX311_BO1,204,203,200_.jpg").setDescription("Crime and Punishment (Russian: Преступлéние и наказáние, tr. Prestupleniye i nakazaniye; IPA: [prʲɪstʊˈplʲenʲɪɪ ɪ nəkɐˈzanʲɪɪ]) is a novel by the Russian author Fyodor Dostoyevsky. It was first published in the literary journal The Russian Messenger in twelve monthly installments during 1866. It was later published in a single volume. It is the second of Dostoyevsky's full-length novels following his return from 10 years of exile in Siberia. Crime and Punishment is considered the first great novel of his \"mature\" period of writing."), 38 | new Book("The Brothers Karamazov").setAuthor("Fyodor Dostoyevsky").setUrl("http://ecx.images-amazon.com/images/I/51FIyYKsCXL._SX333_BO1,204,203,200_.jpg").setDescription("The Brothers Karamazov (Russian: Бра́тья Карама́зовы, Brat'ya Karamazovy, pronounced [ˈbratʲjə kərɐˈmazəvɨ]), also translated as The Karamazov Brothers, is the final novel by the Russian author Fyodor Dostoyevsky. Dostoyevsky spent nearly two years writing The Brothers Karamazov, which was published as a serial in The Russian Messenger and completed in November 1880. The author died less than four months after its publication."), 39 | new Book("Demons").setAuthor("Fyodor Dostoyevsky").setUrl("http://ecx.images-amazon.com/images/I/41Q-p2N1neL._SX326_BO1,204,203,200_.jpg").setDescription("Demons (Russian: Бесы, Bésy) is an anti-nihilistic novel by Fyodor Dostoyevsky, first published in the journal The Russian Messenger in 1871-2. It is the third of the four great novels written by Dostoyevsky after his return from Siberian exile, the others being Crime and Punishment (1866), The Idiot (1869) and The Brothers Karamazov (1880). Demons is a social and political satire, a psychological drama, and large scale tragedy. Joyce Carol Oates has described it as \"Dostoevsky's most confused and violent novel, and his most satisfyingly 'tragic' work.\""), 40 | new Book("Catch-22").setAuthor("Joseph Heller").setUrl("http://ecx.images-amazon.com/images/I/51kqbC3YKvL._SX322_BO1,204,203,200_.jpg").setDescription("Catch-22 is a satirical novel by the American author Joseph Heller. He began writing it in 1953; the novel was first published in 1961. It is frequently cited as one of the greatest literary works of the twentieth century. It uses a distinctive non-chronological third-person omniscient narration, describing events from the points of view of different characters. The separate storylines are out of sequence so that the timeline develops along with the plot."), 41 | new Book("Animal Farm").setAuthor("George Orwell").setUrl("http://ecx.images-amazon.com/images/I/51EjU6rQjsL._SX318_BO1,204,203,200_.jpg").setDescription("Animal Farm is an allegorical and dystopian novella by George Orwell, first published in England on 17 August 1945. According to Orwell, the book reflects events leading up to the Russian Revolution of 1917 and then on into the Stalinist era of the Soviet Union. Orwell, a democratic socialist, was a critic of Joseph Stalin and hostile to Moscow-directed Stalinism, an attitude that was critically shaped by his experiences during the Spanish Civil War."), 42 | new Book("To Kill a Mockingbird").setAuthor("Harper Lee").setUrl("http://ecx.images-amazon.com/images/I/51grMGCKivL._SX307_BO1,204,203,200_.jpg").setDescription("To Kill a Mockingbird is a novel by Harper Lee published in 1960. It was immediately successful, winning the Pulitzer Prize, and has become a classic of modern American literature. The plot and characters are loosely based on the author's observations of her family and neighbors, as well as on an event that occurred near her hometown in 1936, when she was 10 years old."), 43 | new Book("Fahrenheit 451").setAuthor("Ray Bradbury").setUrl("http://ecx.images-amazon.com/images/I/41Cx8mY2UNL._SX324_BO1,204,203,200_.jpg").setDescription("Fahrenheit 451 is a dystopian novel by Ray Bradbury published in 1953. It is regarded as one of his best works. The novel presents a future American society where books are outlawed and \"firemen\" burn any that are found. The title refers to the temperature that Bradbury asserted to be the autoignition temperature of paper. (In reality, scientists place the autoignition temperature of paper anywhere from high 440 degrees Fahrenheit to some 30 degrees hotter, depending on the study and type of paper.)") 44 | ); 45 | private ExpandablePager pager; 46 | 47 | @Override 48 | protected void onCreate(Bundle savedInstanceState) { 49 | super.onCreate(savedInstanceState); 50 | ImagePipelineConfig config = ImagePipelineConfig.newBuilder(this) 51 | .setDownsampleEnabled(true) 52 | .build(); 53 | Fresco.initialize(this, config); 54 | setTitle("Books"); 55 | setContentView(R.layout.activity_main); 56 | 57 | if (getSupportActionBar() != null) { 58 | getSupportActionBar().setDisplayHomeAsUpEnabled(true); 59 | getSupportActionBar().setHomeButtonEnabled(true); 60 | } 61 | 62 | final List myList = new ArrayList<>(list); 63 | 64 | //use PageAdapter 65 | final BookAdapter adapter = new BookAdapter(myList); 66 | //or FragmentAdapter 67 | //final BookFragmentAdapter adapter = new BookFragmentAdapter(getSupportFragmentManager(), myList); 68 | //or FragmentStateAdapter 69 | //final BookFragmentStateAdapter adapter = new BookFragmentStateAdapter(getSupportFragmentManager(), myList); 70 | 71 | pager = (ExpandablePager) findViewById(R.id.container); 72 | //pager.setAnimationDuration(duration); 73 | //pager.setCollapsedHeight((int) getResources().getDimension(R.dimen.header_height)); 74 | //pager.setMode(ExpandablePager.MODE_REGULAR); 75 | pager.setAdapter(adapter); 76 | pager.setOnSliderStateChangeListener(new OnSliderStateChangeListener() { 77 | 78 | @Override 79 | public void onStateChanged(View page, int index, int state) { 80 | toggleContent(page, state, duration); 81 | } 82 | 83 | @Override 84 | public void onPageChanged(View page, int index, int state) { 85 | toggleContent(page, state, 0); 86 | } 87 | }); 88 | 89 | RecyclerView mRecyclerView = (RecyclerView) findViewById(R.id.book_list); 90 | mRecyclerView.setHasFixedSize(true); 91 | 92 | int columns = isTablet() ? 2 : 1; 93 | columns += isLandscape() ? 1 : 0; 94 | GridLayoutManager mLayoutManager = new GridLayoutManager(this, columns); 95 | mRecyclerView.setLayoutManager(mLayoutManager); 96 | 97 | BookGridAdapter a = new BookGridAdapter(list); 98 | 99 | a.setListener(new OnItemClickedListener() { 100 | @Override 101 | public void onItemClicked(int index) { 102 | pager.setCurrentItem(index, false); 103 | pager.animateToState(ExpandablePager.STATE_EXPANDED); 104 | } 105 | }); 106 | 107 | mRecyclerView.setAdapter(a); 108 | } 109 | 110 | @Override 111 | public boolean onCreateOptionsMenu(Menu menu) { 112 | MenuInflater inflater = getMenuInflater(); 113 | inflater.inflate(R.menu.menu, menu); 114 | return true; 115 | } 116 | 117 | @Override 118 | public boolean onOptionsItemSelected(MenuItem item) { 119 | switch (item.getItemId()) { 120 | case R.id.shbutton: 121 | pager.animateToState(pager.getSliderState() == ExpandablePager.STATE_HIDDEN ? ExpandablePager.STATE_COLLAPSED : ExpandablePager.STATE_HIDDEN); 122 | return true; 123 | 124 | case R.id.ccbutton: 125 | pager.setAdapter(new BookAdapter((two = !two) ? list2 : list)); 126 | return true; 127 | 128 | default: 129 | return super.onOptionsItemSelected(item); 130 | 131 | } 132 | } 133 | 134 | private void toggleContent(final View page, final int state, int duration) { 135 | final int headerHeight = (int) getResources().getDimension(R.dimen.header_height); 136 | if (page != null && isTablet()) { 137 | ValueAnimator animator = state == ExpandablePager.STATE_EXPANDED ? ValueAnimator.ofFloat(1, 0) : ValueAnimator.ofFloat(0, 1); 138 | animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { 139 | @Override 140 | public void onAnimationUpdate(ValueAnimator animation) { 141 | page.findViewById(R.id.header_title).setTranslationY(25 * (1 - ((Float) animation.getAnimatedValue()))); 142 | page.findViewById(R.id.header_title).setTranslationX(-headerHeight * (1 - ((Float) animation.getAnimatedValue()))); 143 | page.findViewById(R.id.header_subtitle).setAlpha(((Float) animation.getAnimatedValue())); 144 | page.findViewById(R.id.header_img).setAlpha(((Float) animation.getAnimatedValue())); 145 | page.findViewById(R.id.header_action).setAlpha(((Float) animation.getAnimatedValue())); 146 | } 147 | }); 148 | animator.setDuration((long) (duration * .5)); 149 | animator.setInterpolator(new FastOutSlowInInterpolator()); 150 | animator.start(); 151 | } 152 | if (getSupportActionBar() != null) 153 | getSupportActionBar().setElevation(state == ExpandablePager.STATE_EXPANDED ? 0 : getResources().getDisplayMetrics().density * 8); 154 | } 155 | 156 | private boolean isTablet() { 157 | int sizeMask = (getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK); 158 | return sizeMask == Configuration.SCREENLAYOUT_SIZE_LARGE 159 | || sizeMask == Configuration.SCREENLAYOUT_SIZE_XLARGE; 160 | } 161 | 162 | private boolean isLandscape() { 163 | return getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE; 164 | } 165 | } 166 | -------------------------------------------------------------------------------- /demoapp/src/main/java/com/telenav/demoapp/OnItemClickedListener.java: -------------------------------------------------------------------------------- 1 | package com.telenav.demoapp; 2 | 3 | public interface OnItemClickedListener { 4 | void onItemClicked(int index); 5 | } 6 | -------------------------------------------------------------------------------- /demoapp/src/main/java/com/telenav/demoapp/fragment/BookFragment.java: -------------------------------------------------------------------------------- 1 | package com.telenav.demoapp.fragment; 2 | 3 | import android.net.Uri; 4 | import android.os.Bundle; 5 | import android.support.v4.app.Fragment; 6 | import android.text.Spannable; 7 | import android.text.SpannableString; 8 | import android.text.style.RelativeSizeSpan; 9 | import android.view.LayoutInflater; 10 | import android.view.View; 11 | import android.view.ViewGroup; 12 | import android.widget.RelativeLayout; 13 | import android.widget.TextView; 14 | 15 | import com.facebook.drawee.view.SimpleDraweeView; 16 | import com.telenav.demoapp.Book; 17 | import com.telenav.expandableviewpager.R; 18 | 19 | import java.util.regex.Matcher; 20 | import java.util.regex.Pattern; 21 | 22 | public class BookFragment extends Fragment { 23 | 24 | private Book myBook; 25 | 26 | public static BookFragment init(Book myBook) { 27 | BookFragment frag = new BookFragment(); 28 | Bundle args = new Bundle(); 29 | args.putString("title", myBook.getTitle()); 30 | args.putString("author", myBook.getAuthor()); 31 | args.putString("description", myBook.getDescription()); 32 | args.putString("url", myBook.getUrl()); 33 | frag.setArguments(args); 34 | return frag; 35 | } 36 | 37 | @Override 38 | public void onCreate(Bundle savedInstanceState) { 39 | super.onCreate(savedInstanceState); 40 | if (getArguments() != null) { 41 | myBook = new Book(getArguments().getString("title")); 42 | myBook.setAuthor(getArguments().getString("author")); 43 | myBook.setDescription(getArguments().getString("description")); 44 | myBook.setUrl(getArguments().getString("url")); 45 | } 46 | } 47 | 48 | @Override 49 | public View onCreateView(LayoutInflater inflater, ViewGroup container, 50 | Bundle savedInstanceState) { 51 | final ViewGroup rootView = (ViewGroup) inflater.inflate(R.layout.page, container, false); 52 | rootView.setLayoutParams(new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT)); 53 | ((TextView) rootView.findViewById(R.id.text)).setText(myBook.getDescription()); 54 | ((TextView) rootView.findViewById(R.id.header_title)).setText(myBook.getTitle()); 55 | ((TextView) rootView.findViewById(R.id.header_subtitle)).setText(myBook.getAuthor()); 56 | ((SimpleDraweeView) rootView.findViewById(R.id.header_img)).setImageURI(Uri.parse(myBook.getUrl())); 57 | if (rootView.findViewById(R.id.cell_img) != null) 58 | ((SimpleDraweeView) rootView.findViewById(R.id.cell_img)).setImageURI(Uri.parse(myBook.getUrl())); 59 | 60 | TextView rating = ((TextView) rootView.findViewById(R.id.page_rating)); 61 | setSpan(rating, "\\d\\.\\d / \\d\\.\\d"); 62 | 63 | TextView reviews = ((TextView) rootView.findViewById(R.id.page_reviews)); 64 | setSpan(reviews, "\\d+"); 65 | 66 | TextView comments = ((TextView) rootView.findViewById(R.id.page_comments)); 67 | setSpan(comments, "\\d+,*\\d+"); 68 | return rootView; 69 | } 70 | 71 | private void setSpan(TextView textView, String pattern) { 72 | float relativeSize = 1.5f; 73 | Pattern pat = Pattern.compile(pattern); 74 | Matcher m = pat.matcher(textView.getText()); 75 | if (m.find()) { 76 | SpannableString span = new SpannableString(textView.getText()); 77 | span.setSpan(new RelativeSizeSpan(relativeSize), 0, m.group(0).length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); 78 | textView.setText(span); 79 | } 80 | } 81 | } -------------------------------------------------------------------------------- /demoapp/src/main/java/com/telenav/demoapp/fragment/BookFragmentAdapter.java: -------------------------------------------------------------------------------- 1 | package com.telenav.demoapp.fragment; 2 | 3 | import android.support.v4.app.Fragment; 4 | import android.support.v4.app.FragmentManager; 5 | 6 | import com.telenav.demoapp.Book; 7 | import com.telenav.expandablepager.adapter.ExpandableFragmentPagerAdapter; 8 | 9 | import java.util.List; 10 | 11 | public class BookFragmentAdapter extends ExpandableFragmentPagerAdapter { 12 | 13 | 14 | public BookFragmentAdapter(FragmentManager fm, List items) { 15 | super(fm, items); 16 | } 17 | 18 | @Override 19 | public Fragment getItem(int position) { 20 | return BookFragment.init(items.get(position)); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /demoapp/src/main/java/com/telenav/demoapp/fragment/BookFragmentStateAdapter.java: -------------------------------------------------------------------------------- 1 | package com.telenav.demoapp.fragment; 2 | 3 | import android.support.v4.app.Fragment; 4 | import android.support.v4.app.FragmentManager; 5 | 6 | import com.telenav.demoapp.Book; 7 | import com.telenav.expandablepager.adapter.ExpandableFragmentStatePagerAdapter; 8 | 9 | import java.util.List; 10 | 11 | public class BookFragmentStateAdapter extends ExpandableFragmentStatePagerAdapter { 12 | 13 | 14 | public BookFragmentStateAdapter(FragmentManager fm, List items) { 15 | super(fm, items); 16 | } 17 | 18 | @Override 19 | public Fragment getItem(int position) { 20 | return BookFragment.init(items.get(position)); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /demoapp/src/main/res/drawable-hdpi/ic_favorite_border_white_36dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Telenav/ExpandablePager/58de7e5f1f6c2ec85e3310f953e5226ddbd7d273/demoapp/src/main/res/drawable-hdpi/ic_favorite_border_white_36dp.png -------------------------------------------------------------------------------- /demoapp/src/main/res/drawable-hdpi/ic_library_add_white_36dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Telenav/ExpandablePager/58de7e5f1f6c2ec85e3310f953e5226ddbd7d273/demoapp/src/main/res/drawable-hdpi/ic_library_add_white_36dp.png -------------------------------------------------------------------------------- /demoapp/src/main/res/drawable-hdpi/ic_local_library_white_36dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Telenav/ExpandablePager/58de7e5f1f6c2ec85e3310f953e5226ddbd7d273/demoapp/src/main/res/drawable-hdpi/ic_local_library_white_36dp.png -------------------------------------------------------------------------------- /demoapp/src/main/res/drawable-hdpi/ic_shopping_cart_white_36dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Telenav/ExpandablePager/58de7e5f1f6c2ec85e3310f953e5226ddbd7d273/demoapp/src/main/res/drawable-hdpi/ic_shopping_cart_white_36dp.png -------------------------------------------------------------------------------- /demoapp/src/main/res/drawable-mdpi/ic_favorite_border_white_36dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Telenav/ExpandablePager/58de7e5f1f6c2ec85e3310f953e5226ddbd7d273/demoapp/src/main/res/drawable-mdpi/ic_favorite_border_white_36dp.png -------------------------------------------------------------------------------- /demoapp/src/main/res/drawable-mdpi/ic_library_add_white_36dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Telenav/ExpandablePager/58de7e5f1f6c2ec85e3310f953e5226ddbd7d273/demoapp/src/main/res/drawable-mdpi/ic_library_add_white_36dp.png -------------------------------------------------------------------------------- /demoapp/src/main/res/drawable-mdpi/ic_local_library_white_36dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Telenav/ExpandablePager/58de7e5f1f6c2ec85e3310f953e5226ddbd7d273/demoapp/src/main/res/drawable-mdpi/ic_local_library_white_36dp.png -------------------------------------------------------------------------------- /demoapp/src/main/res/drawable-mdpi/ic_shopping_cart_white_36dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Telenav/ExpandablePager/58de7e5f1f6c2ec85e3310f953e5226ddbd7d273/demoapp/src/main/res/drawable-mdpi/ic_shopping_cart_white_36dp.png -------------------------------------------------------------------------------- /demoapp/src/main/res/drawable-xhdpi/ic_favorite_border_white_36dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Telenav/ExpandablePager/58de7e5f1f6c2ec85e3310f953e5226ddbd7d273/demoapp/src/main/res/drawable-xhdpi/ic_favorite_border_white_36dp.png -------------------------------------------------------------------------------- /demoapp/src/main/res/drawable-xhdpi/ic_library_add_white_36dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Telenav/ExpandablePager/58de7e5f1f6c2ec85e3310f953e5226ddbd7d273/demoapp/src/main/res/drawable-xhdpi/ic_library_add_white_36dp.png -------------------------------------------------------------------------------- /demoapp/src/main/res/drawable-xhdpi/ic_local_library_white_36dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Telenav/ExpandablePager/58de7e5f1f6c2ec85e3310f953e5226ddbd7d273/demoapp/src/main/res/drawable-xhdpi/ic_local_library_white_36dp.png -------------------------------------------------------------------------------- /demoapp/src/main/res/drawable-xhdpi/ic_shopping_cart_white_36dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Telenav/ExpandablePager/58de7e5f1f6c2ec85e3310f953e5226ddbd7d273/demoapp/src/main/res/drawable-xhdpi/ic_shopping_cart_white_36dp.png -------------------------------------------------------------------------------- /demoapp/src/main/res/drawable-xxhdpi/ic_favorite_border_white_36dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Telenav/ExpandablePager/58de7e5f1f6c2ec85e3310f953e5226ddbd7d273/demoapp/src/main/res/drawable-xxhdpi/ic_favorite_border_white_36dp.png -------------------------------------------------------------------------------- /demoapp/src/main/res/drawable-xxhdpi/ic_library_add_white_36dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Telenav/ExpandablePager/58de7e5f1f6c2ec85e3310f953e5226ddbd7d273/demoapp/src/main/res/drawable-xxhdpi/ic_library_add_white_36dp.png -------------------------------------------------------------------------------- /demoapp/src/main/res/drawable-xxhdpi/ic_local_library_white_36dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Telenav/ExpandablePager/58de7e5f1f6c2ec85e3310f953e5226ddbd7d273/demoapp/src/main/res/drawable-xxhdpi/ic_local_library_white_36dp.png -------------------------------------------------------------------------------- /demoapp/src/main/res/drawable-xxhdpi/ic_shopping_cart_white_36dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Telenav/ExpandablePager/58de7e5f1f6c2ec85e3310f953e5226ddbd7d273/demoapp/src/main/res/drawable-xxhdpi/ic_shopping_cart_white_36dp.png -------------------------------------------------------------------------------- /demoapp/src/main/res/drawable-xxxhdpi/ic_favorite_border_white_36dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Telenav/ExpandablePager/58de7e5f1f6c2ec85e3310f953e5226ddbd7d273/demoapp/src/main/res/drawable-xxxhdpi/ic_favorite_border_white_36dp.png -------------------------------------------------------------------------------- /demoapp/src/main/res/drawable-xxxhdpi/ic_library_add_white_36dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Telenav/ExpandablePager/58de7e5f1f6c2ec85e3310f953e5226ddbd7d273/demoapp/src/main/res/drawable-xxxhdpi/ic_library_add_white_36dp.png -------------------------------------------------------------------------------- /demoapp/src/main/res/drawable-xxxhdpi/ic_local_library_white_36dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Telenav/ExpandablePager/58de7e5f1f6c2ec85e3310f953e5226ddbd7d273/demoapp/src/main/res/drawable-xxxhdpi/ic_local_library_white_36dp.png -------------------------------------------------------------------------------- /demoapp/src/main/res/drawable-xxxhdpi/ic_shopping_cart_white_36dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Telenav/ExpandablePager/58de7e5f1f6c2ec85e3310f953e5226ddbd7d273/demoapp/src/main/res/drawable-xxxhdpi/ic_shopping_cart_white_36dp.png -------------------------------------------------------------------------------- /demoapp/src/main/res/layout-land/page.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 11 | 12 | 13 | 17 | 25 | 26 | 38 | 39 | 40 | 47 | 48 | 52 | 53 | 62 | 63 | 69 | 70 | 71 | 75 | 76 | 85 | 86 | 87 | 91 | 92 | 101 | 102 | 108 | 109 | 110 | -------------------------------------------------------------------------------- /demoapp/src/main/res/layout-large-land/page.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 11 | 12 | 13 | 19 | 20 | 27 | 28 | 33 | 34 | 35 | 36 | 40 | 41 | 46 | 47 | 57 | 58 | 59 | 60 | 64 | 65 | 70 | 71 | 81 | 82 | 83 | 84 | 85 | 86 | 90 | 91 | 96 | 97 | 107 | 108 | 109 | 113 | 114 | 119 | 120 | 130 | 131 | 132 | 133 | 134 | 137 | 138 | 142 | 150 | 151 | 164 | 165 | 166 | 167 | 168 | 175 | 176 | 180 | 181 | 190 | 191 | 197 | 198 | 199 | 203 | 204 | 213 | 214 | 215 | 219 | 220 | 229 | 230 | 236 | 237 | 238 | -------------------------------------------------------------------------------- /demoapp/src/main/res/layout-large/header.xml: -------------------------------------------------------------------------------- 1 | 2 | 10 | 11 | 16 | 17 | 24 | 25 | 32 | 33 | 40 | 41 | 42 | 50 | -------------------------------------------------------------------------------- /demoapp/src/main/res/layout-large/page.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 11 | 13 | 14 | 20 | 21 | 27 | 28 | 33 | 34 | 35 | 36 | 40 | 41 | 46 | 47 | 57 | 58 | 59 | 60 | 64 | 65 | 70 | 71 | 81 | 82 | 83 | 84 | 85 | 86 | 90 | 91 | 96 | 97 | 107 | 108 | 109 | 113 | 114 | 119 | 120 | 130 | 131 | 132 | 133 | 134 | 135 | 142 | 143 | 147 | 148 | 157 | 158 | 164 | 165 | 166 | 170 | 171 | 180 | 181 | 182 | 186 | 187 | 196 | 197 | 203 | 204 | 205 | 206 | 214 | 215 | 227 | -------------------------------------------------------------------------------- /demoapp/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 18 | 19 | 26 | 27 | -------------------------------------------------------------------------------- /demoapp/src/main/res/layout/cell.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 15 | 16 | 21 | 22 | 28 | 29 | 38 | 39 | 40 | 49 | 50 | 51 | 59 | 60 | 61 | -------------------------------------------------------------------------------- /demoapp/src/main/res/layout/header.xml: -------------------------------------------------------------------------------- 1 | 2 | 10 | 11 | 16 | 17 | 24 | 25 | 32 | 33 | 40 | 41 | 42 | 52 | -------------------------------------------------------------------------------- /demoapp/src/main/res/layout/page.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 11 | 13 | 14 | 21 | 22 | 26 | 27 | 36 | 37 | 43 | 44 | 45 | 49 | 50 | 59 | 60 | 61 | 65 | 66 | 75 | 76 | 82 | 83 | 84 | 85 | 93 | 94 | 106 | -------------------------------------------------------------------------------- /demoapp/src/main/res/menu/menu.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 8 | 9 | 10 | 13 | -------------------------------------------------------------------------------- /demoapp/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Telenav/ExpandablePager/58de7e5f1f6c2ec85e3310f953e5226ddbd7d273/demoapp/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /demoapp/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Telenav/ExpandablePager/58de7e5f1f6c2ec85e3310f953e5226ddbd7d273/demoapp/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /demoapp/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Telenav/ExpandablePager/58de7e5f1f6c2ec85e3310f953e5226ddbd7d273/demoapp/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /demoapp/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Telenav/ExpandablePager/58de7e5f1f6c2ec85e3310f953e5226ddbd7d273/demoapp/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /demoapp/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Telenav/ExpandablePager/58de7e5f1f6c2ec85e3310f953e5226ddbd7d273/demoapp/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /demoapp/src/main/res/values-large/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 16dp 4 | 16dp 5 | 80dp 6 | 80dp 7 | 250dp 8 | 9 | -------------------------------------------------------------------------------- /demoapp/src/main/res/values-w820dp/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 64dp 6 | 7 | -------------------------------------------------------------------------------- /demoapp/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 8 | 9 | 17 | 18 | #0E3758 19 | #444444 20 | #0B2C47 21 | #0F3B5F 22 | #E7EBF0 23 | #227A3E48 24 | #E18942 25 | #D0E1F9 26 | #DD283655 27 | #134D7C 28 | #16588D 29 | #19639F 30 | #1C6DB0 31 | #1E78C2 32 | #2183D4 33 | 34 | -------------------------------------------------------------------------------- /demoapp/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 16dp 4 | 16dp 5 | 80dp 6 | 30dp 7 | 250dp 8 | 9 | -------------------------------------------------------------------------------- /demoapp/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | Expandable ViewPager 3 | 4 | -------------------------------------------------------------------------------- /demoapp/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /expandablepager/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /expandablepager/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | 3 | android { 4 | compileSdkVersion 23 5 | buildToolsVersion "23.0.2" 6 | 7 | defaultConfig { 8 | minSdkVersion 14 9 | targetSdkVersion 23 10 | versionCode 1 11 | versionName "1.0" 12 | } 13 | buildTypes { 14 | release { 15 | minifyEnabled false 16 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 17 | } 18 | } 19 | } 20 | 21 | dependencies { 22 | compile fileTree(dir: 'libs', include: ['*.jar']) 23 | compile 'com.android.support:appcompat-v7:23.2.0' 24 | } 25 | -------------------------------------------------------------------------------- /expandablepager/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 /home/dima/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 | -------------------------------------------------------------------------------- /expandablepager/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /expandablepager/src/main/java/com/telenav/expandablepager/ExpandablePager.java: -------------------------------------------------------------------------------- 1 | /** 2 | * © 2016 Telenav, Inc. All Rights Reserved 3 | *

4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | *

6 | * You may not use this file except in compliance with the License. You may obtain a copy of the 7 | * License at http://www.apache.org/licenses/LICENSE-2.0. Unless required by applicable law or 8 | * agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, 9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for 10 | * the specific language governing permissions and limitations under the License. 11 | */ 12 | 13 | package com.telenav.expandablepager; 14 | 15 | import android.content.Context; 16 | import android.content.res.TypedArray; 17 | import android.os.Build; 18 | import android.os.Parcel; 19 | import android.os.Parcelable; 20 | import android.support.annotation.IntDef; 21 | import android.support.v4.app.Fragment; 22 | import android.support.v4.app.FragmentPagerAdapter; 23 | import android.support.v4.app.FragmentStatePagerAdapter; 24 | import android.support.v4.view.PagerAdapter; 25 | import android.support.v4.view.ViewPager; 26 | import android.util.AttributeSet; 27 | import android.view.Gravity; 28 | import android.view.View; 29 | import android.view.ViewGroup; 30 | import android.view.ViewTreeObserver; 31 | import android.widget.FrameLayout; 32 | import android.widget.LinearLayout; 33 | import android.widget.RelativeLayout; 34 | 35 | import com.telenav.expandablepager.adapter.ExpandablePagerAdapter; 36 | import com.telenav.expandablepager.listener.OnItemSelectedListener; 37 | import com.telenav.expandablepager.listener.OnSliderStateChangeListener; 38 | 39 | import java.lang.annotation.Retention; 40 | import java.lang.annotation.RetentionPolicy; 41 | 42 | /** 43 | * Layout that contains a ViewPager and can slide vertically between 2 states (expanded and collapsed). Should be aligned to the bottom of the screen. 44 | */ 45 | public class ExpandablePager extends SlidingContainer { 46 | 47 | public static final byte MODE_REGULAR = 0, MODE_FIXED = 1; 48 | 49 | private ViewPager mPager; 50 | 51 | private float sliderStateThreshold; 52 | 53 | private OnItemSelectedListener onItemSelectedListener; 54 | 55 | private OnSliderStateChangeListener onSliderStateChangeListener; 56 | 57 | private int sliderState = STATE_COLLAPSED; 58 | 59 | private byte sliderMode = MODE_REGULAR; 60 | 61 | private float historicY; 62 | 63 | private int collapsedHeight = (int) (80 * getResources().getDisplayMetrics().density); 64 | 65 | public ExpandablePager(Context context) { 66 | super(context); 67 | init(); 68 | } 69 | 70 | public ExpandablePager(Context context, AttributeSet attrs) { 71 | super(context, attrs); 72 | init(); 73 | TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ExpandablePager, 0, 0); 74 | setAnimationDuration(a.getInt(R.styleable.ExpandablePager_animation_duration, 200)); 75 | collapsedHeight = (int) a.getDimension(R.styleable.ExpandablePager_collapsed_height, 80 * getResources().getDisplayMetrics().density); 76 | a.recycle(); 77 | } 78 | 79 | private void init() { 80 | mPager = new ViewPager(getContext()); 81 | mPager.setId(R.id.internal_pager_id); 82 | mPager.setLayoutParams(new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); 83 | mPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() { 84 | int idx = 0; 85 | 86 | @Override 87 | public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { 88 | idx = mPager.getCurrentItem() + (position < mPager.getCurrentItem() ? -1 : 1); 89 | } 90 | 91 | @Override 92 | public void onPageSelected(int position) { 93 | if (onItemSelectedListener != null) 94 | onItemSelectedListener.onItemSelected(((ExpandablePagerAdapter) mPager.getAdapter()).getDataItems(), position); 95 | } 96 | 97 | @Override 98 | public void onPageScrollStateChanged(int state) { 99 | notifyChange(idx); 100 | } 101 | 102 | private void notifyChange(int index) { 103 | if (onSliderStateChangeListener != null) { 104 | if (index < mPager.getAdapter().getCount()) 105 | onSliderStateChangeListener.onPageChanged(getPage(index), index, sliderState); 106 | } 107 | } 108 | }); 109 | addView(mPager); 110 | getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { 111 | @Override 112 | public void onGlobalLayout() { 113 | 114 | pinToBottom(); 115 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { 116 | getViewTreeObserver().removeOnGlobalLayoutListener(this); 117 | } else { 118 | getViewTreeObserver().removeGlobalOnLayoutListener(this); 119 | } 120 | if (onSliderStateChangeListener != null) { 121 | int index = mPager.getCurrentItem(); 122 | onSliderStateChangeListener.onPageChanged(getPage(index), index, sliderState); 123 | } 124 | } 125 | }); 126 | } 127 | 128 | /** 129 | * Move the layout to the bottom of the screen in case it was not moved in the xml file 130 | */ 131 | private void pinToBottom() { 132 | ViewGroup.LayoutParams params = getLayoutParams(); 133 | if (params != null) { 134 | if (params instanceof RelativeLayout.LayoutParams) { 135 | ((LayoutParams) params).addRule(RelativeLayout.ALIGN_PARENT_BOTTOM); 136 | } else if (params instanceof LinearLayout.LayoutParams) { 137 | ((LinearLayout.LayoutParams) params).gravity = Gravity.BOTTOM; 138 | } else if (params instanceof FrameLayout.LayoutParams) { 139 | ((FrameLayout.LayoutParams) params).gravity = Gravity.BOTTOM; 140 | } 141 | } 142 | } 143 | 144 | @SliderState 145 | public int getSliderState() { 146 | return sliderState; 147 | } 148 | 149 | /** 150 | * Animates the container to the selected state. 151 | * 152 | * @param state - available value are: STATE_COLLAPSED, STATE_EXPANDED, STATE_HIDDEN 153 | */ 154 | @Override 155 | public boolean animateToState(@SliderState int state) { 156 | sliderState = state; 157 | return mPager.getAdapter().getCount() > 0 && super.animateToState(state); 158 | } 159 | 160 | /** 161 | * Set the height of the pager in the collapsed state. 162 | * 163 | * @param collapsed collapsed height in pixels 164 | */ 165 | public void setCollapsedHeight(int collapsed) { 166 | collapsedHeight = collapsed; 167 | } 168 | 169 | /** 170 | * @return current slider mode 171 | */ 172 | @SliderMode 173 | public byte getMode() { 174 | return sliderMode; 175 | } 176 | 177 | /** 178 | * Set slider mode 179 | */ 180 | public void setMode(@SliderMode byte mode) { 181 | sliderMode = mode; 182 | if (mode == MODE_FIXED) 183 | setSliderMode(MODE_FIXED); 184 | } 185 | 186 | private void setSliderMode(@SliderMode byte mode) { 187 | switch (mode) { 188 | case MODE_REGULAR: // full screen 189 | int height = getHeight(); 190 | sliderStateThreshold = height / 2; 191 | sliderMode = MODE_REGULAR; 192 | setStopValues((float) height - collapsedHeight); 193 | break; 194 | case MODE_FIXED: 195 | sliderStateThreshold = Integer.MAX_VALUE; 196 | sliderMode = MODE_FIXED; 197 | getLayoutParams().height = collapsedHeight; 198 | setStopValues(0f); 199 | break; 200 | } 201 | enableSlide(mode != MODE_FIXED); 202 | } 203 | 204 | /** 205 | * Set the currently selected page. 206 | * 207 | * @param index Item index to select 208 | * @param smoothScroll True to smoothly scroll to the new item, false to transition immediately 209 | */ 210 | public void setCurrentItem(int index, boolean smoothScroll) { 211 | mPager.setCurrentItem(index, smoothScroll); 212 | } 213 | 214 | public int getCurrentItem() { 215 | return mPager.getCurrentItem(); 216 | } 217 | 218 | public void setAdapter(PagerAdapter adapter) { 219 | int index = mPager.getCurrentItem(); 220 | mPager.setAdapter(adapter); 221 | mPager.setCurrentItem(Math.min(index, adapter.getCount() - 1)); 222 | mPager.post(new Runnable() { 223 | @Override 224 | public void run() { 225 | if (onSliderStateChangeListener != null) { 226 | int index = mPager.getCurrentItem(); 227 | onSliderStateChangeListener.onPageChanged(getPage(index), index, sliderState); 228 | } 229 | } 230 | }); 231 | } 232 | 233 | public void setOnSliderStateChangeListener(OnSliderStateChangeListener onSliderStateChangeListener) { 234 | this.onSliderStateChangeListener = onSliderStateChangeListener; 235 | } 236 | 237 | public void setOnItemSelectedListener(OnItemSelectedListener listener) { 238 | onItemSelectedListener = listener; 239 | } 240 | 241 | private View getPage(int position) { 242 | if (mPager.getAdapter() != null && position >= 0 && position < mPager.getAdapter().getCount()) { 243 | if (mPager.getAdapter() instanceof FragmentPagerAdapter || 244 | mPager.getAdapter() instanceof FragmentStatePagerAdapter) 245 | return ((Fragment) mPager.getAdapter().instantiateItem(mPager, position)).getView(); 246 | else 247 | return findViewById(R.id.internal_page_id % 10000 + position); 248 | } else 249 | return null; 250 | } 251 | 252 | @Override 253 | protected void notifySlideEvent(float yPosition) { 254 | super.notifySlideEvent(yPosition); 255 | if (historicY <= sliderStateThreshold && yPosition >= sliderStateThreshold) { 256 | //down 257 | if (sliderState != STATE_HIDDEN) 258 | sliderState = STATE_COLLAPSED; 259 | if (onSliderStateChangeListener != null) { 260 | int index = mPager.getCurrentItem(); 261 | onSliderStateChangeListener.onStateChanged(getPage(index), index, sliderState); 262 | } 263 | } else if (historicY >= sliderStateThreshold && yPosition < sliderStateThreshold) { 264 | //up 265 | sliderState = STATE_EXPANDED; 266 | if (onSliderStateChangeListener != null) { 267 | int index = mPager.getCurrentItem(); 268 | onSliderStateChangeListener.onStateChanged(getPage(index), index, sliderState); 269 | } 270 | } 271 | historicY = yPosition; 272 | } 273 | 274 | @Override 275 | protected void onSettled(int slideValueIndex) { 276 | } 277 | 278 | @Override 279 | protected Parcelable onSaveInstanceState() { 280 | Parcelable superState = super.onSaveInstanceState(); 281 | SavedState ss = new SavedState(superState); 282 | 283 | ss.sliderState = sliderState; 284 | ss.sliderMode = sliderMode; 285 | if (mPager != null) 286 | ss.currentIndex = mPager.getCurrentItem(); 287 | 288 | return ss; 289 | } 290 | 291 | @Override 292 | protected void onSizeChanged(int w, int h, int oldw, int oldh) { 293 | super.onSizeChanged(w, h, oldw, oldh); 294 | switch (sliderState) { 295 | case STATE_COLLAPSED: 296 | historicY = h - collapsedHeight; 297 | break; 298 | case STATE_EXPANDED: 299 | historicY = 0; 300 | break; 301 | case STATE_HIDDEN: 302 | historicY = h; 303 | break; 304 | } 305 | if (sliderMode == MODE_REGULAR) { 306 | setSliderMode(sliderMode); 307 | } 308 | setState(sliderState); 309 | } 310 | 311 | @Override 312 | protected void onRestoreInstanceState(Parcelable state) { 313 | if (!(state instanceof SavedState)) { 314 | super.onRestoreInstanceState(state); 315 | return; 316 | } 317 | 318 | SavedState ss = (SavedState) state; 319 | super.onRestoreInstanceState(ss.getSuperState()); 320 | 321 | sliderState = ss.sliderState; 322 | sliderMode = ss.sliderMode; 323 | if (mPager != null) 324 | mPager.setCurrentItem(ss.currentIndex); 325 | } 326 | 327 | 328 | @Retention(RetentionPolicy.SOURCE) 329 | @IntDef({MODE_REGULAR, MODE_FIXED}) 330 | public @interface SliderMode { 331 | } 332 | 333 | static class SavedState extends BaseSavedState { 334 | public static final Parcelable.Creator CREATOR = 335 | new Parcelable.Creator() { 336 | public SavedState createFromParcel(Parcel in) { 337 | return new SavedState(in); 338 | } 339 | 340 | public SavedState[] newArray(int size) { 341 | return new SavedState[size]; 342 | } 343 | }; 344 | int currentIndex; 345 | int sliderState; 346 | byte sliderMode; 347 | 348 | SavedState(Parcelable superState) { 349 | super(superState); 350 | } 351 | 352 | private SavedState(Parcel in) { 353 | super(in); 354 | this.currentIndex = in.readInt(); 355 | this.sliderState = in.readInt(); 356 | this.sliderMode = in.readByte(); 357 | } 358 | 359 | @Override 360 | public void writeToParcel(Parcel out, int flags) { 361 | super.writeToParcel(out, flags); 362 | out.writeInt(this.currentIndex); 363 | out.writeInt(this.sliderState); 364 | out.writeByte(this.sliderMode); 365 | } 366 | } 367 | } 368 | -------------------------------------------------------------------------------- /expandablepager/src/main/java/com/telenav/expandablepager/SlidingContainer.java: -------------------------------------------------------------------------------- 1 | /** 2 | * © 2016 Telenav, Inc. All Rights Reserved 3 | *

4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | *

6 | * You may not use this file except in compliance with the License. You may obtain a copy of the 7 | * License at http://www.apache.org/licenses/LICENSE-2.0. Unless required by applicable law or 8 | * agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, 9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for 10 | * the specific language governing permissions and limitations under the License. 11 | */ 12 | 13 | package com.telenav.expandablepager; 14 | 15 | import android.animation.Animator; 16 | import android.animation.ObjectAnimator; 17 | import android.animation.ValueAnimator; 18 | import android.content.Context; 19 | import android.support.annotation.IntDef; 20 | import android.support.v4.view.MotionEventCompat; 21 | import android.support.v4.view.animation.FastOutSlowInInterpolator; 22 | import android.util.AttributeSet; 23 | import android.view.MotionEvent; 24 | import android.view.View; 25 | import android.view.animation.Interpolator; 26 | import android.view.animation.LinearInterpolator; 27 | import android.widget.RelativeLayout; 28 | 29 | import java.lang.annotation.Retention; 30 | import java.lang.annotation.RetentionPolicy; 31 | import java.util.ArrayList; 32 | import java.util.Arrays; 33 | import java.util.Collections; 34 | import java.util.Iterator; 35 | import java.util.List; 36 | import java.util.SortedSet; 37 | import java.util.TreeSet; 38 | 39 | import com.telenav.expandablepager.listener.OnSlideListener; 40 | 41 | /** 42 | * Container that slides vertically between provided slide values. 43 | */ 44 | public class SlidingContainer extends RelativeLayout { 45 | 46 | public static final int STATE_COLLAPSED = 0, STATE_EXPANDED = 1, STATE_HIDDEN = -1; 47 | private static final int SLIDE_THRESHOLD_DIPS = 20; 48 | private final float DEFAULT_SLIDE_THRESHOLD; 49 | /** 50 | * Each slide event must pass this threshold in order not to be ignored. 51 | */ 52 | private float slideThreshold; 53 | private int viewHeight; 54 | /** 55 | * The container will stop sliding when it reaches one of the stopValues. 56 | */ 57 | private List stopValues = new ArrayList<>(); 58 | private int stopValueIndex = 0; 59 | private float startYCoordinate; 60 | /** 61 | * Difference between start touch Y coordinate and current Y coordinate. 62 | */ 63 | private float touchDelta; 64 | /** 65 | * Current translationY value 66 | */ 67 | private float translated = 0; 68 | private OnSlideListener slideListener; 69 | private int duration = 200; 70 | 71 | public SlidingContainer(Context context) { 72 | super(context); 73 | slideThreshold = context.getResources().getDisplayMetrics().density * SLIDE_THRESHOLD_DIPS; 74 | DEFAULT_SLIDE_THRESHOLD = slideThreshold; 75 | } 76 | 77 | public SlidingContainer(Context context, AttributeSet attrs) { 78 | super(context, attrs); 79 | slideThreshold = context.getResources().getDisplayMetrics().density * SLIDE_THRESHOLD_DIPS; 80 | DEFAULT_SLIDE_THRESHOLD = slideThreshold; 81 | } 82 | 83 | public void setSlideListener(OnSlideListener slideListener) { 84 | this.slideListener = slideListener; 85 | } 86 | 87 | public void setAnimationDuration(int duration) { 88 | this.duration = duration; 89 | } 90 | 91 | @Override 92 | protected void onSizeChanged(int w, int h, int oldw, int oldh) { 93 | super.onSizeChanged(w, h, oldw, oldh); 94 | if (viewHeight == 0) { 95 | viewHeight = h; 96 | Iterator iter = stopValues.iterator(); 97 | while (iter.hasNext()) { 98 | Float i = iter.next(); 99 | if (i >= viewHeight || i < 0) 100 | iter.remove(); 101 | } 102 | } 103 | } 104 | 105 | @Override 106 | public boolean onInterceptTouchEvent(MotionEvent event) { 107 | return !translate(event); 108 | } 109 | 110 | @Override 111 | public boolean onTouchEvent(MotionEvent event) { 112 | translate(event); 113 | return true; 114 | } 115 | 116 | protected void enableSlide(boolean enable) { 117 | slideThreshold = enable ? DEFAULT_SLIDE_THRESHOLD : Integer.MAX_VALUE; 118 | } 119 | 120 | private boolean translate(MotionEvent ev) { 121 | final int action = MotionEventCompat.getActionMasked(ev); 122 | int stepSize = stopValues.size(); 123 | 124 | switch (action) { 125 | case MotionEvent.ACTION_DOWN: { 126 | startYCoordinate = ev.getRawY(); 127 | translated = 0; 128 | break; 129 | } 130 | case MotionEvent.ACTION_MOVE: { 131 | touchDelta = (startYCoordinate - ev.getRawY()); 132 | if (Math.abs(touchDelta) > slideThreshold) { 133 | float startingPointY, nextPointY, maxDiff, tempDelta, auxDelta = 0; 134 | tempDelta = touchDelta + (touchDelta < 0 ? 1 : -1) * slideThreshold; 135 | startingPointY = stopValues.get(stopValueIndex); 136 | if (!isUpwardGesture() && stopValueIndex >= 1) { 137 | nextPointY = stopValues.get(stopValueIndex - 1); 138 | maxDiff = nextPointY - stopValues.get(stopValueIndex); 139 | auxDelta = Math.min(-tempDelta, maxDiff); 140 | } else if (isUpwardGesture() && stopValueIndex < stepSize - 1) { 141 | nextPointY = stopValues.get(stopValueIndex + 1); 142 | maxDiff = nextPointY - stopValues.get(stopValueIndex); 143 | auxDelta = Math.max(-tempDelta, maxDiff); 144 | } 145 | float preTranslated = translated; 146 | translated = startingPointY + auxDelta; 147 | setTranslationY(translated); 148 | if (preTranslated != translated) 149 | notifySlideEvent(translated); 150 | return false; 151 | } 152 | return true; 153 | } 154 | case MotionEvent.ACTION_UP: { 155 | if (Math.abs(touchDelta) > slideThreshold) { 156 | if (!isUpwardGesture() && stopValueIndex > 0) 157 | stopValueIndex--; 158 | else if (isUpwardGesture() && stopValueIndex < stepSize - 1) 159 | stopValueIndex++; 160 | if (!stopValues.contains(translated)) { 161 | animate(stopValues.get(stopValueIndex)); 162 | } else 163 | onSettled(stopValueIndex); 164 | startYCoordinate = -1; 165 | touchDelta = 0; 166 | } 167 | break; 168 | } 169 | case MotionEvent.ACTION_CANCEL: { 170 | break; 171 | } 172 | case MotionEvent.ACTION_POINTER_UP: { 173 | break; 174 | } 175 | } 176 | return true; 177 | } 178 | 179 | protected void onSettled(int slideValueIndex) { 180 | } 181 | 182 | /** 183 | * indicates that that the finger moved up 184 | */ 185 | private boolean isUpwardGesture() { 186 | return touchDelta > 0; 187 | } 188 | 189 | /** 190 | * Convenience method, uses FastOutSlowInInterpolator and default animation duration. See {@link SlidingContainer#animate(float, int, Interpolator)} 191 | * @param amount translationY amount 192 | */ 193 | private void animate(float amount) { 194 | animate(amount, duration, new LinearInterpolator()); 195 | } 196 | 197 | /** 198 | * Convenience method, uses FastOutSlowInInterpolator. See {@link SlidingContainer#animate(float, int, Interpolator)} 199 | * @param amount translationY amount 200 | * @param duration animation duration 201 | */ 202 | private void animate(float amount, int duration) { 203 | animate(amount, duration, new FastOutSlowInInterpolator()); 204 | } 205 | 206 | /** 207 | * Animate translationY to the next stopValue 208 | * @param amount translationY amount 209 | * @param duration animation duration 210 | * @param interpolator animation interpolator 211 | */ 212 | private void animate(final float amount, int duration, Interpolator interpolator) { 213 | ObjectAnimator oa = ObjectAnimator.ofFloat(this, View.TRANSLATION_Y, amount) 214 | .setDuration(duration); 215 | oa.setInterpolator(interpolator); 216 | oa.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { 217 | @Override 218 | public void onAnimationUpdate(ValueAnimator animation) { 219 | notifySlideEvent(Math.round(((Float) animation.getAnimatedValue()))); 220 | } 221 | }); 222 | oa.addListener(new CustomAnimationListener() { 223 | @Override 224 | public void onAnimationEnd(Animator animator) { 225 | onSettled(stopValueIndex); 226 | } 227 | }); 228 | oa.start(); 229 | } 230 | 231 | public List getStopValues() { 232 | return stopValues; 233 | } 234 | 235 | /** 236 | * Stops sliding at the specified values. 237 | * @param stopValues list of stop values 238 | */ 239 | public void setStopValues(Float... stopValues) { 240 | SortedSet s = new TreeSet<>(Collections.reverseOrder()); 241 | s.addAll(Arrays.asList(stopValues)); 242 | this.stopValues.clear(); 243 | this.stopValues.addAll(s); 244 | this.stopValues.add(0f); 245 | stopValueIndex = 0; 246 | } 247 | 248 | public Float getCurrentStopValue() { 249 | return stopValues.get(stopValueIndex); 250 | } 251 | 252 | /** 253 | * Sets the container position to a given state. No animation occurs. For an animated alternative see {@link SlidingContainer#animateToState(int, int)} 254 | */ 255 | public boolean setState(@SliderState int state) { 256 | if (!stopValues.isEmpty()) 257 | switch (state) { 258 | case STATE_COLLAPSED: 259 | setTranslationY(stopValues.get(0)); 260 | stopValueIndex = 0; 261 | return true; 262 | case STATE_EXPANDED: 263 | setTranslationY(0); 264 | stopValueIndex = stopValues.size() - 1; 265 | return true; 266 | case STATE_HIDDEN: 267 | setTranslationY(getHeight()); 268 | return true; 269 | } 270 | return false; 271 | } 272 | 273 | /** 274 | * Convenience method, uses default duration. See {@link SlidingContainer#animateToState(int, int)} 275 | */ 276 | public boolean animateToState(@SliderState int toState) { 277 | return animateToState(toState, duration); 278 | } 279 | 280 | /** 281 | * Animate the container position to a given state. For a non-animated alternative see {@link SlidingContainer#setState(int)} 282 | */ 283 | public boolean animateToState(@SliderState int toState, int duration) { 284 | if (!stopValues.isEmpty()) { 285 | switch (toState) { 286 | case STATE_COLLAPSED: 287 | animate(stopValues.get(0), duration); 288 | stopValueIndex = 0; 289 | return true; 290 | case STATE_EXPANDED: 291 | animate(0, duration); 292 | stopValueIndex = stopValues.size() - 1; 293 | return true; 294 | case STATE_HIDDEN: 295 | animate(getHeight(), duration); 296 | return true; 297 | } 298 | } 299 | return false; 300 | } 301 | 302 | protected void notifySlideEvent(float yPosition) { 303 | if (slideListener != null) { 304 | slideListener.onSlide(yPosition); 305 | } 306 | } 307 | 308 | public @SliderState int getState() { 309 | int translation = (int) getTranslationY(); 310 | if (translation == 0) 311 | return STATE_EXPANDED; 312 | else if (translation == viewHeight) 313 | return STATE_HIDDEN; 314 | else if (stopValues.size() >= 2 && translation == stopValues.get(stopValues.size() - 2)) 315 | return STATE_COLLAPSED; 316 | return STATE_COLLAPSED;//check this later 317 | } 318 | 319 | @Retention(RetentionPolicy.SOURCE) 320 | @IntDef({STATE_COLLAPSED, STATE_EXPANDED, STATE_HIDDEN}) 321 | public @interface SliderState { 322 | } 323 | 324 | private static class CustomAnimationListener implements Animator.AnimatorListener { 325 | @Override 326 | public void onAnimationStart(Animator animator) { 327 | 328 | } 329 | 330 | @Override 331 | public void onAnimationEnd(Animator animator) { 332 | 333 | } 334 | 335 | @Override 336 | public void onAnimationCancel(Animator animator) { 337 | 338 | } 339 | 340 | @Override 341 | public void onAnimationRepeat(Animator animator) { 342 | 343 | } 344 | } 345 | } -------------------------------------------------------------------------------- /expandablepager/src/main/java/com/telenav/expandablepager/adapter/ExpandableFragmentPagerAdapter.java: -------------------------------------------------------------------------------- 1 | /** 2 | * © 2016 Telenav, Inc. All Rights Reserved 3 | *

4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | *

6 | * You may not use this file except in compliance with the License. You may obtain a copy of the 7 | * License at http://www.apache.org/licenses/LICENSE-2.0. Unless required by applicable law or 8 | * agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, 9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for 10 | * the specific language governing permissions and limitations under the License. 11 | */ 12 | 13 | package com.telenav.expandablepager.adapter; 14 | 15 | import android.support.v4.app.FragmentManager; 16 | import android.support.v4.app.FragmentPagerAdapter; 17 | import android.support.v4.view.PagerAdapter; 18 | 19 | import com.telenav.expandablepager.ExpandablePager; 20 | 21 | import java.util.List; 22 | 23 | /** 24 | * FragmentPagerAdapter for ExpandablePager. Extend this class and pass it to your pager via {@link ExpandablePager#setAdapter(PagerAdapter)} 25 | */ 26 | public abstract class ExpandableFragmentPagerAdapter extends FragmentPagerAdapter { 27 | 28 | protected List items; 29 | 30 | public ExpandableFragmentPagerAdapter(FragmentManager fm, List items) { 31 | super(fm); 32 | this.items = items; 33 | } 34 | 35 | @Override 36 | public int getCount() { 37 | return items.size(); 38 | } 39 | 40 | public List getDataItems() { 41 | return items; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /expandablepager/src/main/java/com/telenav/expandablepager/adapter/ExpandableFragmentStatePagerAdapter.java: -------------------------------------------------------------------------------- 1 | /** 2 | * © 2016 Telenav, Inc. All Rights Reserved 3 | *

4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | *

6 | * You may not use this file except in compliance with the License. You may obtain a copy of the 7 | * License at http://www.apache.org/licenses/LICENSE-2.0. Unless required by applicable law or 8 | * agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, 9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for 10 | * the specific language governing permissions and limitations under the License. 11 | */ 12 | 13 | package com.telenav.expandablepager.adapter; 14 | 15 | import android.support.v4.app.FragmentManager; 16 | import android.support.v4.app.FragmentStatePagerAdapter; 17 | import android.support.v4.view.PagerAdapter; 18 | 19 | import com.telenav.expandablepager.ExpandablePager; 20 | 21 | import java.util.List; 22 | 23 | /** 24 | * FragmentStatePagerAdapter for ExpandablePager. Extend this class and pass it to your pager via {@link ExpandablePager#setAdapter(PagerAdapter)} 25 | */ 26 | public abstract class ExpandableFragmentStatePagerAdapter extends FragmentStatePagerAdapter { 27 | 28 | protected List items; 29 | 30 | public ExpandableFragmentStatePagerAdapter(FragmentManager fm, List items) { 31 | super(fm); 32 | this.items = items; 33 | } 34 | 35 | @Override 36 | public int getCount() { 37 | return items.size(); 38 | } 39 | 40 | public List getDataItems() { 41 | return items; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /expandablepager/src/main/java/com/telenav/expandablepager/adapter/ExpandablePagerAdapter.java: -------------------------------------------------------------------------------- 1 | /** 2 | * © 2016 Telenav, Inc. All Rights Reserved 3 | *

4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | *

6 | * You may not use this file except in compliance with the License. You may obtain a copy of the 7 | * License at http://www.apache.org/licenses/LICENSE-2.0. Unless required by applicable law or 8 | * agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, 9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for 10 | * the specific language governing permissions and limitations under the License. 11 | */ 12 | 13 | package com.telenav.expandablepager.adapter; 14 | 15 | import android.support.v4.view.PagerAdapter; 16 | import android.view.View; 17 | import android.view.ViewGroup; 18 | 19 | import com.telenav.expandablepager.ExpandablePager; 20 | import com.telenav.expandablepager.R; 21 | 22 | import java.util.List; 23 | 24 | /** 25 | * PagerAdapter for ExpandablePager. Extend this class and pass it to your pager via {@link ExpandablePager#setAdapter(PagerAdapter)} 26 | */ 27 | public class ExpandablePagerAdapter extends PagerAdapter { 28 | 29 | protected List items; 30 | 31 | public ExpandablePagerAdapter(List items) { 32 | this.items = items; 33 | } 34 | 35 | @Override 36 | public int getCount() { 37 | return items.size(); 38 | } 39 | 40 | @Override 41 | public void destroyItem(ViewGroup container, int position, Object object) { 42 | container.removeView((View) object); 43 | } 44 | 45 | @Override 46 | public boolean isViewFromObject(View view, Object object) { 47 | return view == object; 48 | } 49 | 50 | public List getDataItems() { 51 | return items; 52 | } 53 | 54 | /** 55 | * Attaches the view to the container and gives it a specific id. Return the result of this method when overriding {@link #instantiateItem(ViewGroup, int)} 56 | * @param container view container 57 | * @param v inflated view 58 | * @param position position of the view in the adapter 59 | * @return inflated view 60 | */ 61 | protected View attach(ViewGroup container, View v, int position) { 62 | v.setId(R.id.internal_page_id % 10000 + position); 63 | container.addView(v); 64 | return v; 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /expandablepager/src/main/java/com/telenav/expandablepager/listener/OnItemSelectedListener.java: -------------------------------------------------------------------------------- 1 | /** 2 | * © 2016 Telenav, Inc. All Rights Reserved 3 | *

4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | *

6 | * You may not use this file except in compliance with the License. You may obtain a copy of the 7 | * License at http://www.apache.org/licenses/LICENSE-2.0. Unless required by applicable law or 8 | * agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, 9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for 10 | * the specific language governing permissions and limitations under the License. 11 | */ 12 | 13 | package com.telenav.expandablepager.listener; 14 | 15 | import java.util.List; 16 | 17 | /** 18 | * Listener for ViewPager page selected events 19 | */ 20 | public interface OnItemSelectedListener { 21 | /** 22 | * Fires each time a page from the ViewPages is selected 23 | * @param items list of adapter items 24 | * @param index index of the selected item 25 | */ 26 | void onItemSelected(List items, int index); 27 | } 28 | -------------------------------------------------------------------------------- /expandablepager/src/main/java/com/telenav/expandablepager/listener/OnSlideListener.java: -------------------------------------------------------------------------------- 1 | /** 2 | * © 2016 Telenav, Inc. All Rights Reserved 3 | *

4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | *

6 | * You may not use this file except in compliance with the License. You may obtain a copy of the 7 | * License at http://www.apache.org/licenses/LICENSE-2.0. Unless required by applicable law or 8 | * agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, 9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for 10 | * the specific language governing permissions and limitations under the License. 11 | */ 12 | 13 | package com.telenav.expandablepager.listener; 14 | 15 | 16 | /** 17 | * Listens for slide events. 18 | */ 19 | public interface OnSlideListener { 20 | /** 21 | * Fires each time the SlidingContainer is moving. 22 | * @param amount represents the current translationY of the container 23 | */ 24 | void onSlide(float amount); 25 | } 26 | -------------------------------------------------------------------------------- /expandablepager/src/main/java/com/telenav/expandablepager/listener/OnSliderStateChangeListener.java: -------------------------------------------------------------------------------- 1 | /** 2 | * © 2016 Telenav, Inc. All Rights Reserved 3 | *

4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | *

6 | * You may not use this file except in compliance with the License. You may obtain a copy of the 7 | * License at http://www.apache.org/licenses/LICENSE-2.0. Unless required by applicable law or 8 | * agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, 9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for 10 | * the specific language governing permissions and limitations under the License. 11 | */ 12 | 13 | package com.telenav.expandablepager.listener; 14 | 15 | import android.view.View; 16 | 17 | import com.telenav.expandablepager.SlidingContainer; 18 | 19 | /** 20 | * Listener for slider state change events 21 | */ 22 | public interface OnSliderStateChangeListener { 23 | /** 24 | * Fires when slider state changes as a result of a slide. Ex: change from expanded state to collapsed state. 25 | * 26 | * @param page view linked with the page whose state being changed 27 | * @param index page index 28 | * @param state new slider state 29 | */ 30 | void onStateChanged(View page, int index, @SlidingContainer.SliderState int state); 31 | 32 | /** 33 | * Fires when the state changes for a page different from the current page (most often the next page offscreen) or when the view size changes 34 | * 35 | * @param page view linked with the page whose state being changed 36 | * @param index page index 37 | * @param state new slider state 38 | */ 39 | void onPageChanged(View page, int index, @SlidingContainer.SliderState int state); 40 | } 41 | -------------------------------------------------------------------------------- /expandablepager/src/main/res/values/attrs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /gif/expandablepager.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Telenav/ExpandablePager/58de7e5f1f6c2ec85e3310f953e5226ddbd7d273/gif/expandablepager.gif -------------------------------------------------------------------------------- /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 -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':demoapp', ':expandablepager' 2 | --------------------------------------------------------------------------------