Skip to content

Commit

Permalink
init commit
Browse files Browse the repository at this point in the history
  • Loading branch information
imallan committed Aug 23, 2016
1 parent d72433c commit 254fc02
Show file tree
Hide file tree
Showing 12 changed files with 169 additions and 399 deletions.
6 changes: 3 additions & 3 deletions app/build.gradle
@@ -1,13 +1,13 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 22
compileSdkVersion 24
buildToolsVersion "22.0.1"

defaultConfig {
applicationId "uk.co.imallan.jellyrefreshlayout"
minSdkVersion 19
targetSdkVersion 22
targetSdkVersion 24
versionCode 1
versionName "1.0"
}
Expand All @@ -21,6 +21,6 @@ android {

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:22.2.0'
compile 'com.android.support:appcompat-v7:24.2.0'
compile project(":jellyrefresh")
}
Expand Up @@ -6,7 +6,7 @@
import android.view.Menu;
import android.view.MenuItem;

import uk.co.imallan.jellyrefresh.JellyRefreshLayout;
import uk.co.imallan.jellyrefresh.PullToRefreshLayout;

public class MainActivity extends AppCompatActivity {

Expand All @@ -17,18 +17,29 @@ protected void onCreate(Bundle savedInstanceState) {
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
setTitle("Jelly");
final JellyRefreshLayout jellyLayout = (JellyRefreshLayout) findViewById(R.id.jelly_refresh);
jellyLayout.setRefreshListener(new JellyRefreshLayout.JellyRefreshListener() {
final PullToRefreshLayout jellyLayout = (PullToRefreshLayout) findViewById(R.id.jelly_refresh);
jellyLayout.setPullToRefreshListener(new PullToRefreshLayout.PullToRefreshListener() {
@Override
public void onRefresh(final JellyRefreshLayout jellyRefreshLayout) {
jellyRefreshLayout.postDelayed(new Runnable() {
public void onRefresh(PullToRefreshLayout pullToRefreshLayout) {
pullToRefreshLayout.postDelayed(new Runnable() {
@Override
public void run() {
jellyRefreshLayout.finishRefreshing();
jellyLayout.finishRefreshing();
}
}, 3000);
}
});
// new JellyRefreshLayout.JellyRefreshListener() {
// @Override
// public void onRefresh(final JellyRefreshLayout jellyRefreshLayout) {
// jellyRefreshLayout.postDelayed(new Runnable() {
// @Override
// public void run() {
// jellyRefreshLayout.finishRefreshing();
// }
// }, 3000);
// }
// });
}

@Override
Expand Down
22 changes: 11 additions & 11 deletions app/src/main/res/layout/activity_main.xml
@@ -1,28 +1,28 @@
<RelativeLayout 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:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">

<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:animateLayoutChanges="true"
android:background="?attr/colorPrimary"
android:elevation="0dp"
android:elevation="4dp"
android:minHeight="?attr/actionBarSize"
android:theme="@style/Toolbar.Light" />
android:theme="@style/Toolbar.Light"/>

<uk.co.imallan.jellyrefresh.JellyRefreshLayout
android:id="@+id/jelly_refresh"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@id/toolbar"
android:text="@string/loading"
android:textColor="@android:color/white"
app:jellyColor="@color/primary">
android:elevation="4dp"
android:text="@string/loading">
<!--android:textColor="@android:color/white"-->
<!--app:jellyColor="@color/primary">-->

<ScrollView
android:layout_width="match_parent"
Expand All @@ -33,7 +33,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="16dp"
android:text="@string/lorem_ipsum" />
android:text="@string/lorem_ipsum"/>

</ScrollView>

Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Expand Up @@ -6,7 +6,7 @@ buildscript {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.3.0'
classpath 'com.android.tools.build:gradle:2.1.3'
classpath 'me.tatarka:gradle-retrolambda:3.2.0'

// NOTE: Do not place your application dependencies here; they belong
Expand Down
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
@@ -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
6 changes: 3 additions & 3 deletions jellyrefresh/build.gradle
Expand Up @@ -6,12 +6,12 @@ apply plugin: 'com.android.library'
apply plugin: 'me.tatarka.retrolambda'

android {
compileSdkVersion 22
compileSdkVersion 24
buildToolsVersion "22.0.1"

defaultConfig {
minSdkVersion 19
targetSdkVersion 22
targetSdkVersion 24
versionCode 1
versionName "1.0"
}
Expand All @@ -30,5 +30,5 @@ android {

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:22.2.0'
compile 'com.android.support:appcompat-v7:24.2.0'
}
104 changes: 104 additions & 0 deletions jellyrefresh/src/main/java/uk/co/imallan/jellyrefresh/JellyLayout.java
@@ -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);
}

}
}

0 comments on commit 254fc02

Please sign in to comment.