Skip to content

Commit

Permalink
Update sample
Browse files Browse the repository at this point in the history
  • Loading branch information
amyu committed Aug 4, 2015
1 parent ef356e4 commit ed1a4f1
Show file tree
Hide file tree
Showing 13 changed files with 68 additions and 91 deletions.

This file was deleted.

This file was deleted.

6 changes: 1 addition & 5 deletions library/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
<?xml version="1.0" encoding="utf-8"?>

<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="jp.co.recruit_lifestyle.android.widget"/>
<manifest package="jp.co.recruit_lifestyle.android.widget"/>
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import android.view.View;
import android.view.ViewConfiguration;
import android.view.ViewGroup;
import android.widget.AbsListView;

/**
* @author amyu_san
Expand Down Expand Up @@ -96,7 +95,7 @@ public BeerSwipeRefreshLayout(Context context, AttributeSet attrs, int defStyleA
final int childRight = thisWidth - getPaddingRight();
final int childBottom = thisHeight - getPaddingBottom();
mTarget.layout(getPaddingLeft(), getPaddingTop(), childRight, childBottom);
mBeerView.layout(l, t, r, b);
mBeerView.layout(getPaddingLeft(), getPaddingTop() + 30, childRight, childBottom + 30);
mBeerView.bringToFront();
}

Expand All @@ -107,6 +106,7 @@ public BeerSwipeRefreshLayout(Context context, AttributeSet attrs, int defStyleA
mTarget.measure(
makeMeasureSpecExactly(getMeasuredWidth() - (getPaddingLeft() + getPaddingRight())),
makeMeasureSpecExactly(getMeasuredHeight() - (getPaddingTop() + getPaddingBottom())));
mBeerView.measure(widthMeasureSpec, heightMeasureSpec);
}

@Override protected void onAttachedToWindow() {
Expand All @@ -122,9 +122,10 @@ public BeerSwipeRefreshLayout(Context context, AttributeSet attrs, int defStyleA
@Override public boolean onInterceptTouchEvent(MotionEvent event) {
ensureTarget();

if (!isEnabled() || canChildScrollUp() || isRefreshing()) {
if (!isEnabled()) {
return false;
}

if (mBeerView.isReverseAnimationRunning() || mBeerView.isMax()) {
return false;
}
Expand Down Expand Up @@ -159,8 +160,7 @@ public BeerSwipeRefreshLayout(Context context, AttributeSet attrs, int defStyleA
final float yDiff = currentY - mFirstTouchDownPointY;

// State is changed to drag if over slop
if (yDiff > ViewConfiguration.get(getContext())
.getScaledTouchSlop() && !isRefreshing()) {
if (yDiff > ViewConfiguration.get(getContext()).getScaledTouchSlop()) {
return true;
}

Expand All @@ -175,9 +175,11 @@ public BeerSwipeRefreshLayout(Context context, AttributeSet attrs, int defStyleA
}

@Override public boolean onTouchEvent(@NonNull MotionEvent event) {
if (!isEnabled() || canChildScrollUp() /*|| isRefreshing()*/) {
if (!isEnabled()) {
return false;
}


if (mBeerView.isReverseAnimationRunning() || mBeerView.isMax()) {
return false;
}
Expand Down Expand Up @@ -206,6 +208,7 @@ public BeerSwipeRefreshLayout(Context context, AttributeSet attrs, int defStyleA
mBeerView.drawGlass(0);
return false;
} else {
mBeerView.setAlpha(1);
setRefreshing(true, true);
}
float touchMoveDegree = Math.max(-(diffY - mFirstTouchDownPointY) / 3, -110);
Expand Down Expand Up @@ -233,9 +236,6 @@ public BeerSwipeRefreshLayout(Context context, AttributeSet attrs, int defStyleA
if (!isRefreshing()) {
mBeerView.startDisappearAnimator();
}
if (touchMoveDegree > 0) {
return false;
}

mBeerView.startReverseBottleAnimator(touchMoveDegree);
break;
Expand Down Expand Up @@ -336,24 +336,6 @@ private void ensureTarget() {
}
}

public boolean canChildScrollUp() {
if (mTarget == null) {
return false;
}

if (android.os.Build.VERSION.SDK_INT < 14) {
if (mTarget instanceof AbsListView) {
final AbsListView absListView = (AbsListView) mTarget;
return absListView.getChildCount() > 0 && (absListView.getFirstVisiblePosition() > 0
|| absListView.getChildAt(0).getTop() < absListView.getPaddingTop());
} else {
return mTarget.getScrollY() > 0;
}
} else {
return ViewCompat.canScrollVertically(mTarget, -1);
}
}

public void setOnRefreshListener(OnRefreshListener listener) {
mListener = listener;
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
import android.os.Bundle;
import android.os.Handler;
import android.support.v7.app.AppCompatActivity;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;
import java.util.ArrayList;
import jp.co.recruit_lifestyle.android.widget.BeerSwipeRefreshLayout;

Expand All @@ -16,26 +17,27 @@ public class MainActivity extends AppCompatActivity {
private BeerSwipeRefreshLayout mBeerSwipeRefreshLayout;

@Override protected void onCreate(Bundle savedInstanceState) {
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);

super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

initView();
setSampleData();


}

private void initView() {
mBeerSwipeRefreshLayout = (BeerSwipeRefreshLayout) findViewById(R.id.main_beer_view);
mBeerSwipeRefreshLayout = (BeerSwipeRefreshLayout) findViewById(R.id.main_beer);
mBeerSwipeRefreshLayout.setOnRefreshListener(new BeerSwipeRefreshLayout.OnRefreshListener() {
@Override public void onRefresh() {
Toast.makeText(getApplicationContext(), "onRefresh", Toast.LENGTH_SHORT).show();
//Toast.makeText(getApplicationContext(), "onRefresh", Toast.LENGTH_SHORT).show();
new Handler().postDelayed(new Runnable() {
@Override public void run() {
mBeerSwipeRefreshLayout.setRefreshing(false);
Toast.makeText(getApplicationContext(), "setRefreshing(false)", Toast.LENGTH_SHORT).show();
//Toast.makeText(getApplicationContext(), "setRefreshing(false)", Toast.LENGTH_SHORT).show();
}
}, 10000);
}, 7000);
}
});
mListview = (ListView) findViewById(R.id.main_list);
Expand All @@ -44,7 +46,7 @@ private void initView() {
private void setSampleData() {
ArrayList<String> sampleArrayStr = new ArrayList<>();
for (int i = 0; i < 60; i++) {
sampleArrayStr.add("sample" + i);
sampleArrayStr.add("");
}
ArrayAdapter<String> adapter = new ArrayAdapter<>(getApplicationContext(), android.R.layout.simple_list_item_1, sampleArrayStr);
mListview.setAdapter(adapter);
Expand Down
45 changes: 33 additions & 12 deletions sample/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
@@ -1,20 +1,41 @@
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/main_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
android:orientation="vertical"
tools:context=".MainActivity"
>

<jp.co.recruit_lifestyle.android.widget.BeerSwipeRefreshLayout
<View
android:layout_width="match_parent"
android:layout_height="25dip"
android:background="@color/primary_dark"
/>

<android.support.v7.widget.Toolbar
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:minHeight="?attr/actionBarSize"
android:background="@color/primary"
android:id="@+id/toolbar"
/>


<jp.co.recruit_lifestyle.android.widget.BeerSwipeRefreshLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:id="@+id/main_beer"
>

<ListView
android:id="@+id/main_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/main_beer_view"
>
/>

<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/main_list"
/>
</jp.co.recruit_lifestyle.android.widget.BeerSwipeRefreshLayout>
</jp.co.recruit_lifestyle.android.widget.BeerSwipeRefreshLayout>

</RelativeLayout>
</LinearLayout>
10 changes: 10 additions & 0 deletions sample/src/main/res/values-v21/styles.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>

<style name="AppTheme"
parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:colorPrimary">@color/primary</item>
<item name="android:statusBarColor">@color/primary_dark</item>
<item name="android:navigationBarColor">@color/primary</item>
</style>
</resources>
5 changes: 5 additions & 0 deletions sample/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="primary">#FFC107</color>
<color name="primary_dark">#FFA000</color>
</resources>
Binary file modified sc/animation_beer.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified sc/sc1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified sc/sc2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified sc/sc3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit ed1a4f1

Please sign in to comment.