Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
169 additions
and
399 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
#Fri Jul 10 11:04:38 BST 2015 | ||
#Tue Aug 23 20:49:24 BST 2016 | ||
distributionBase=GRADLE_USER_HOME | ||
distributionPath=wrapper/dists | ||
zipStoreBase=GRADLE_USER_HOME | ||
zipStorePath=wrapper/dists | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-2.7-all.zip | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
104 changes: 104 additions & 0 deletions
104
jellyrefresh/src/main/java/uk/co/imallan/jellyrefresh/JellyLayout.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
package uk.co.imallan.jellyrefresh; | ||
|
||
import android.content.Context; | ||
import android.graphics.Canvas; | ||
import android.graphics.Color; | ||
import android.graphics.Outline; | ||
import android.graphics.Paint; | ||
import android.graphics.Path; | ||
import android.os.Build; | ||
import android.support.annotation.ColorInt; | ||
import android.support.annotation.RequiresApi; | ||
import android.util.AttributeSet; | ||
import android.util.Log; | ||
import android.view.View; | ||
import android.view.ViewOutlineProvider; | ||
import android.widget.FrameLayout; | ||
|
||
public class JellyLayout extends FrameLayout { | ||
private static final String TAG = "JellyLayout"; | ||
|
||
private Paint mPaint; | ||
private Path mPath; | ||
@ColorInt | ||
private int mColor = Color.GRAY; | ||
// FIXME: 23/08/2016 hardcoded | ||
private int mHeaderHeight = 200; | ||
private int mPullHeight = 400; | ||
private ViewOutlineProvider mViewOutlineProvider; | ||
private float mPointX; | ||
|
||
public JellyLayout(Context context) { | ||
this(context, null); | ||
} | ||
|
||
public JellyLayout(Context context, AttributeSet attrs) { | ||
this(context, attrs, 0); | ||
} | ||
|
||
public JellyLayout(Context context, AttributeSet attrs, int defStyleAttr) { | ||
super(context, attrs, defStyleAttr); | ||
init(); | ||
} | ||
|
||
private void init() { | ||
setWillNotDraw(false); | ||
|
||
mPaint = new Paint(Paint.ANTI_ALIAS_FLAG); | ||
mPaint.setStyle(Paint.Style.FILL); | ||
|
||
mPath = new Path(); | ||
|
||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { | ||
mViewOutlineProvider = new ViewOutlineProvider() { | ||
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) | ||
@Override | ||
public void getOutline(View view, Outline outline) { | ||
if (mPath.isConvex()) outline.setConvexPath(mPath); | ||
} | ||
}; | ||
|
||
} | ||
} | ||
|
||
public void setColor(int color) { | ||
mColor = color; | ||
} | ||
|
||
public void setPointX(float pointX) { | ||
boolean needInvalidate = pointX != mPointX; | ||
mPointX = pointX; | ||
if (needInvalidate) invalidate(); | ||
} | ||
|
||
|
||
@Override | ||
protected void onDraw(Canvas canvas) { | ||
super.onDraw(canvas); | ||
final int width = canvas.getWidth(); | ||
Log.d(TAG, "onDraw: height: " + getHeight()); | ||
|
||
mHeaderHeight = getHeight() / 2; | ||
mPullHeight = getHeight(); | ||
|
||
mPaint.setColor(mColor); | ||
|
||
float mDisplayX = (mPointX - width / 2f) * 0.5f + width / 2f; | ||
|
||
mPath.rewind(); | ||
mPath.moveTo(0, 0); | ||
mPath.lineTo(0, mHeaderHeight); | ||
mPath.quadTo(mDisplayX, mPullHeight, width, mHeaderHeight); | ||
mPath.lineTo(width, 0); | ||
mPath.close(); | ||
|
||
canvas.drawPath(mPath, mPaint); | ||
|
||
canvas.drawLine(0, mPullHeight, width, mPullHeight, mPaint); | ||
|
||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { | ||
setOutlineProvider(mViewOutlineProvider); | ||
} | ||
|
||
} | ||
} |
Oops, something went wrong.