Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add another effect. #47

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ android {
}

dependencies {
compile 'com.android.support:appcompat-v7:25+'
compile 'com.android.support:design:25.1.0'
compile project(':liboverscroll')
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support:design:25.1.0'
compile 'com.android.support:support-v4:25.3.1'
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,17 @@
import me.everything.overscrolldemo.view.RecyclerViewDemoFragment;
import me.everything.overscrolldemo.view.RecyclerViewStaggeredGridDemoFragment;
import me.everything.overscrolldemo.view.ScrollViewDemoFragment;
import me.everything.overscrolldemo.view.SwitchEffectFragment;
import me.everything.overscrolldemo.view.ViewPagerDemoFragment;

public class OverScrollDemoActivity extends AppCompatActivity
implements NavigationView.OnNavigationItemSelectedListener {

public static final int EFFECT_BOUNCE = 0;
public static final int EFFECT_SCALE = 1;

public static int mCurrentEffect = EFFECT_BOUNCE;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Expand Down Expand Up @@ -63,8 +69,11 @@ public void onBackPressed() {
public boolean onNavigationItemSelected(MenuItem item) {
final int id = item.getItemId();
item.setChecked(true);

switch (id) {
case R.id.switch_effect:
mCurrentEffect = mCurrentEffect == EFFECT_BOUNCE ? EFFECT_SCALE : EFFECT_BOUNCE;
replaceMainFragment(new SwitchEffectFragment(), R.string.switch_effect);
break;
case R.id.drawer_item_recyclerview_demo:
replaceMainFragment(new RecyclerViewDemoFragment(), R.string.recycler_view_demo_title);
break;
Expand All @@ -81,7 +90,7 @@ public boolean onNavigationItemSelected(MenuItem item) {
replaceMainFragment(new ScrollViewDemoFragment(), R.string.scroll_view_demo_title);
break;
case R.id.drawer_item_viewpager_demo:
replaceMainFragment(new ViewPagerDemoFragment(),R.string.viewpager_demo_title);
replaceMainFragment(new ViewPagerDemoFragment(), R.string.viewpager_demo_title);
break;
case R.id.drawer_item_nested_scrollview_demo:
replaceMainFragment(new NestedScrollViewDemoFragment(), R.string.nested_scrollview_demo_title);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import java.util.List;

import me.everything.android.ui.overscroll.OverScrollDecoratorHelper;
import me.everything.overscrolldemo.OverScrollDemoActivity;
import me.everything.overscrolldemo.R;
import me.everything.overscrolldemo.control.DemoContentHelper;
import me.everything.overscrolldemo.control.DemoItem;
Expand All @@ -31,7 +32,10 @@ private void initVerticalGridView(List<DemoItem> content, GridView gridView) {
LayoutInflater appInflater = LayoutInflater.from(getActivity().getApplicationContext());
ListAdapter adapter = new DemoGridAdapter(appInflater, content);
gridView.setAdapter(adapter);

OverScrollDecoratorHelper.setUpOverScroll(gridView);
if (OverScrollDemoActivity.mCurrentEffect == OverScrollDemoActivity.EFFECT_BOUNCE) {
OverScrollDecoratorHelper.setUpOverScroll(gridView);
} else {
OverScrollDecoratorHelper.setUpScaleOverScroll(gridView, 2);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import java.util.List;

import me.everything.android.ui.overscroll.OverScrollDecoratorHelper;
import me.everything.overscrolldemo.OverScrollDemoActivity;
import me.everything.overscrolldemo.R;
import me.everything.overscrolldemo.control.DemoContentHelper;
import me.everything.overscrolldemo.control.DemoItem;
Expand All @@ -33,7 +34,10 @@ private void initVerticalListView(List<DemoItem> content, ListView listView) {
LayoutInflater appInflater = LayoutInflater.from(getActivity().getApplicationContext());
ListAdapter adapter = new DemoListAdapter(appInflater, content);
listView.setAdapter(adapter);

OverScrollDecoratorHelper.setUpOverScroll(listView);
if (OverScrollDemoActivity.mCurrentEffect == OverScrollDemoActivity.EFFECT_BOUNCE) {
OverScrollDecoratorHelper.setUpOverScroll(listView);
} else {
OverScrollDecoratorHelper.setUpScaleOverScroll(listView, 2);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import android.widget.Chronometer;

import me.everything.android.ui.overscroll.OverScrollDecoratorHelper;
import me.everything.overscrolldemo.OverScrollDemoActivity;
import me.everything.overscrolldemo.R;

/**
Expand All @@ -24,16 +25,28 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa
View fragmentView = inflater.inflate(R.layout.misc_overscroll_demo, null, false);

View textView = fragmentView.findViewById(R.id.demo_text);
OverScrollDecoratorHelper.setUpStaticOverScroll(textView, OverScrollDecoratorHelper.ORIENTATION_HORIZONTAL);
if (OverScrollDemoActivity.mCurrentEffect == OverScrollDemoActivity.EFFECT_BOUNCE) {
OverScrollDecoratorHelper.setUpStaticOverScroll(textView, OverScrollDecoratorHelper.ORIENTATION_HORIZONTAL);
} else {
OverScrollDecoratorHelper.setUpScaleStaticOverScroll(textView, OverScrollDecoratorHelper.ORIENTATION_HORIZONTAL, 2);
}

View imageView = fragmentView.findViewById(R.id.demo_image);
OverScrollDecoratorHelper.setUpStaticOverScroll(imageView, OverScrollDecoratorHelper.ORIENTATION_VERTICAL);
if (OverScrollDemoActivity.mCurrentEffect == OverScrollDemoActivity.EFFECT_BOUNCE) {
OverScrollDecoratorHelper.setUpStaticOverScroll(imageView, OverScrollDecoratorHelper.ORIENTATION_VERTICAL);
} else {
OverScrollDecoratorHelper.setUpScaleStaticOverScroll(imageView, OverScrollDecoratorHelper.ORIENTATION_VERTICAL, 2);
}

mChrono = (Chronometer) fragmentView.findViewById(R.id.demo_chronometer);
if (savedInstanceState != null) {
mChrono.setBase(savedInstanceState.getLong(CHRONO_TIME_SAVE_ID));
}
OverScrollDecoratorHelper.setUpStaticOverScroll(mChrono, OverScrollDecoratorHelper.ORIENTATION_HORIZONTAL);
if (OverScrollDemoActivity.mCurrentEffect == OverScrollDemoActivity.EFFECT_BOUNCE) {
OverScrollDecoratorHelper.setUpStaticOverScroll(mChrono, OverScrollDecoratorHelper.ORIENTATION_HORIZONTAL);
} else {
OverScrollDecoratorHelper.setUpScaleStaticOverScroll(mChrono, OverScrollDecoratorHelper.ORIENTATION_HORIZONTAL, 2);
}
mChrono.start();

return fragmentView;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,19 @@
import android.widget.ScrollView;

import me.everything.android.ui.overscroll.OverScrollDecoratorHelper;
import me.everything.overscrolldemo.OverScrollDemoActivity;
import me.everything.overscrolldemo.R;

public class NestedScrollViewDemoFragment extends Fragment {

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
final ScrollView rootView = (ScrollView) inflater.inflate(R.layout.nested_scrollview_demo, null, false);
OverScrollDecoratorHelper.setUpOverScroll(rootView);
if (OverScrollDemoActivity.mCurrentEffect == OverScrollDemoActivity.EFFECT_BOUNCE) {
OverScrollDecoratorHelper.setUpOverScroll(rootView);
} else {
OverScrollDecoratorHelper.setUpScaleOverScroll(rootView, 2);
}
return rootView;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@
import me.everything.android.ui.overscroll.IOverScrollUpdateListener;
import me.everything.android.ui.overscroll.OverScrollDecoratorHelper;
import me.everything.android.ui.overscroll.VerticalOverScrollBounceEffectDecorator;
import me.everything.android.ui.overscroll.VerticalOverScrollScaleEffectDecorator;
import me.everything.android.ui.overscroll.adapters.RecyclerViewOverScrollDecorAdapter;
import me.everything.overscrolldemo.OverScrollDemoActivity;
import me.everything.overscrolldemo.R;
import me.everything.overscrolldemo.control.DemoContentHelper;

Expand All @@ -36,6 +38,7 @@ public class RecyclerViewDemoFragment extends Fragment {

private TextView mHorizScrollMeasure;
private TextView mVertScrollMeasure;
private int mEffectType;

private IOverScrollDecor mHorizOverScrollEffect;
private IOverScrollDecor mVertOverScrollEffect;
Expand Down Expand Up @@ -91,7 +94,11 @@ private void initHorizontalRecyclerView(RecyclerView recyclerView) {
recyclerView.setLayoutManager(new LinearLayoutManager(getActivity(), LinearLayoutManager.HORIZONTAL, false));

// Apply over-scroll in 'standard form' - i.e. using the helper.
mHorizOverScrollEffect = OverScrollDecoratorHelper.setUpOverScroll(recyclerView, OverScrollDecoratorHelper.ORIENTATION_HORIZONTAL);
if (OverScrollDemoActivity.mCurrentEffect == OverScrollDemoActivity.EFFECT_BOUNCE) {
mHorizOverScrollEffect = OverScrollDecoratorHelper.setUpOverScroll(recyclerView, OverScrollDecoratorHelper.ORIENTATION_HORIZONTAL);
} else {
mHorizOverScrollEffect = OverScrollDecoratorHelper.setUpScaleOverScroll(recyclerView, OverScrollDecoratorHelper.ORIENTATION_HORIZONTAL, 2);
}

// Over-scroll listeners can be applied in standard form as well.
mHorizOverScrollEffect.setOverScrollUpdateListener(new IOverScrollUpdateListener() {
Expand Down Expand Up @@ -159,7 +166,11 @@ public void onClick(DialogInterface dialog, int which) {
};

// Apply over-scroll in 'advanced form' - i.e. create an instance manually.
mVertOverScrollEffect = new VerticalOverScrollBounceEffectDecorator(new RecyclerViewOverScrollDecorAdapter(recyclerView, itemTouchHelperCallback));
if (OverScrollDemoActivity.mCurrentEffect == OverScrollDemoActivity.EFFECT_BOUNCE) {
mVertOverScrollEffect = new VerticalOverScrollBounceEffectDecorator(new RecyclerViewOverScrollDecorAdapter(recyclerView, itemTouchHelperCallback));
} else {
mVertOverScrollEffect = new VerticalOverScrollScaleEffectDecorator(new RecyclerViewOverScrollDecorAdapter(recyclerView, itemTouchHelperCallback), 2);
}

// Over-scroll listeners are applied here via the mVertOverScrollEffect explicitly.
mVertOverScrollEffect.setOverScrollUpdateListener(new IOverScrollUpdateListener() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import java.util.ArrayList;

import me.everything.android.ui.overscroll.OverScrollDecoratorHelper;
import me.everything.overscrolldemo.OverScrollDemoActivity;
import me.everything.overscrolldemo.R;
import me.everything.overscrolldemo.control.DemoContentHelper;

Expand All @@ -36,7 +37,11 @@ private void initVerticalRecyclerView(RecyclerView recyclerView) {
recyclerView.setAdapter(adapter);

recyclerView.setLayoutManager(new StaggeredGridLayoutManager(GRID_SPAN_COUNT, StaggeredGridLayoutManager.VERTICAL));
OverScrollDecoratorHelper.setUpOverScroll(recyclerView, OverScrollDecoratorHelper.ORIENTATION_VERTICAL);
if (OverScrollDemoActivity.mCurrentEffect == OverScrollDemoActivity.EFFECT_BOUNCE) {
OverScrollDecoratorHelper.setUpOverScroll(recyclerView, OverScrollDecoratorHelper.ORIENTATION_VERTICAL);
} else {
OverScrollDecoratorHelper.setUpScaleOverScroll(recyclerView, OverScrollDecoratorHelper.ORIENTATION_VERTICAL, 2);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import android.widget.ScrollView;

import me.everything.android.ui.overscroll.OverScrollDecoratorHelper;
import me.everything.overscrolldemo.OverScrollDemoActivity;
import me.everything.overscrolldemo.R;

/**
Expand All @@ -27,11 +28,19 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa
}

private void initHorizontalScrollView(HorizontalScrollView scrollView) {
OverScrollDecoratorHelper.setUpOverScroll(scrollView);
if (OverScrollDemoActivity.mCurrentEffect == OverScrollDemoActivity.EFFECT_BOUNCE) {
OverScrollDecoratorHelper.setUpOverScroll(scrollView);
} else {
OverScrollDecoratorHelper.setUpScaleOverScroll(scrollView, 2);
}
}

private void initVerticalScrollView(ScrollView scrollView) {
OverScrollDecoratorHelper.setUpOverScroll(scrollView);
if (OverScrollDemoActivity.mCurrentEffect == OverScrollDemoActivity.EFFECT_BOUNCE) {
OverScrollDecoratorHelper.setUpOverScroll(scrollView);
} else {
OverScrollDecoratorHelper.setUpScaleOverScroll(scrollView, 2);
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package me.everything.overscrolldemo.view;


import android.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import me.everything.overscrolldemo.OverScrollDemoActivity;
import me.everything.overscrolldemo.R;

/**
* A simple {@link Fragment} subclass.
*/
public class SwitchEffectFragment extends Fragment {

TextView mTvEffect;

public SwitchEffectFragment() {
}


@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View fragmentView = inflater.inflate(R.layout.fragment_switch_effect, container, false);
mTvEffect = (TextView) fragmentView.findViewById(R.id.tv_effect_type);
if (OverScrollDemoActivity.mCurrentEffect == OverScrollDemoActivity.EFFECT_BOUNCE) {
mTvEffect.setText("current effect is bounce");
} else {
mTvEffect.setText("current effect is scale");
}
return fragmentView;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import java.util.List;

import me.everything.android.ui.overscroll.OverScrollDecoratorHelper;
import me.everything.overscrolldemo.OverScrollDemoActivity;
import me.everything.overscrolldemo.R;
import me.everything.overscrolldemo.control.DemoContentHelper;
import me.everything.overscrolldemo.control.DemoItem;
Expand All @@ -29,7 +30,7 @@ public class ViewPagerDemoFragment extends Fragment {
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
return inflater.inflate(R.layout.viewpager_overscroll_demo,null,false);
return inflater.inflate(R.layout.viewpager_overscroll_demo, null, false);
}

@Override
Expand All @@ -42,13 +43,18 @@ private void initHorizontalViewPager(List<DemoItem> items, ViewPager viewPager)

ViewPagerAdapter adapter = new ViewPagerAdapter(items);
viewPager.setAdapter(adapter);
OverScrollDecoratorHelper.setUpOverScroll(viewPager);
if (OverScrollDemoActivity.mCurrentEffect == OverScrollDemoActivity.EFFECT_BOUNCE) {
OverScrollDecoratorHelper.setUpOverScroll(viewPager);
} else {
OverScrollDecoratorHelper.setUpScaleOverScroll(viewPager, 2);
}
}

public static class ViewPagerAdapter extends PagerAdapter{
public static class ViewPagerAdapter extends PagerAdapter {

private List<DemoItem> items;
public ViewPagerAdapter(List<DemoItem> items){

public ViewPagerAdapter(List<DemoItem> items) {
this.items = items;
}

Expand Down
18 changes: 6 additions & 12 deletions app/src/main/res/layout/activity_overscroll_demo.xml
Original file line number Diff line number Diff line change
@@ -1,32 +1,26 @@
<?xml version="1.0" encoding="utf-8"?>

<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"

android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start"
>
tools:openDrawer="start">

<include layout="@layout/activity_overscroll_demo_content"
<include
layout="@layout/activity_overscroll_demo_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
android:layout_height="match_parent" />

<android.support.design.widget.NavigationView
android:id="@+id/drawer_nav"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"

app:headerLayout="@layout/drawer_header_overscroll_demo"
app:menu="@menu/activity_overscroll_demo_drawer_items"

app:itemBackground="@drawable/drawer_items_bkg"
/>
app:menu="@menu/activity_overscroll_demo_drawer_items" />

</android.support.v4.widget.DrawerLayout>
Loading