Skip to content

Commit 318dc9f

Browse files
committed
required min sdk version changed to 15,
you can now set custom layer type
1 parent 6dd58c9 commit 318dc9f

File tree

17 files changed

+242
-321
lines changed

17 files changed

+242
-321
lines changed

app/build.gradle

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
apply plugin: 'com.android.application'
22

33
android {
4-
compileSdkVersion 22
5-
buildToolsVersion "22.0.1"
4+
compileSdkVersion 23
5+
buildToolsVersion "23.0.2"
66

77
defaultConfig {
88
applicationId "io.codetail.circualrevealsample"
9-
minSdkVersion 9
10-
targetSdkVersion 22
9+
minSdkVersion 15
10+
targetSdkVersion 23
1111
versionCode 1
1212
versionName "1.0"
1313
}
@@ -21,10 +21,10 @@ dependencies {
2121
compile fileTree(dir: 'libs', include: ['*.jar'])
2222
compile project(':circualreveal')
2323

24-
compile 'com.android.support:appcompat-v7:22.2.0'
25-
compile 'com.android.support:recyclerview-v7:22.2.0'
26-
compile 'com.android.support:cardview-v7:22.2.0'
27-
compile 'com.android.support:design:22.2.0'
24+
compile 'com.android.support:appcompat-v7:23.1.1'
25+
compile 'com.android.support:recyclerview-v7:23.1.1'
26+
compile 'com.android.support:cardview-v7:23.1.1'
27+
compile 'com.android.support:design:23.1.1'
2828

2929
compile 'com.jakewharton:butterknife:6.0.0'
3030
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
package io.codetail.circualrevealsample;
2+
3+
import android.animation.Animator;
4+
import android.graphics.Color;
5+
import android.os.Bundle;
6+
import android.support.annotation.Nullable;
7+
import android.support.v4.app.Fragment;
8+
import android.view.LayoutInflater;
9+
import android.view.View;
10+
import android.view.ViewGroup;
11+
import android.view.ViewTreeObserver;
12+
import android.view.animation.AccelerateDecelerateInterpolator;
13+
import android.widget.FrameLayout;
14+
import android.widget.ImageView;
15+
16+
import io.codetail.animation.ViewAnimationUtils;
17+
import io.codetail.widget.RevealFrameLayout;
18+
19+
import static android.view.ViewGroup.LayoutParams.MATCH_PARENT;
20+
import static android.view.ViewGroup.LayoutParams.WRAP_CONTENT;
21+
22+
public class FragmentRevealExample extends Fragment {
23+
24+
private Animator mRevealAnimator;
25+
26+
@Nullable
27+
@Override
28+
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
29+
final FrameLayout frameLayout = new RevealFrameLayout(getContext());
30+
31+
final FrameLayout content = new FrameLayout(getContext());
32+
content.setBackgroundColor(Color.WHITE);
33+
content.setVisibility(View.INVISIBLE);
34+
35+
frameLayout.addView(content, new FrameLayout.LayoutParams(MATCH_PARENT, MATCH_PARENT));
36+
37+
final ImageView imageView = new ImageView(getContext());
38+
imageView.setImageResource(R.drawable.example_raw_image);
39+
40+
FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(MATCH_PARENT, WRAP_CONTENT);
41+
lp.topMargin = 16;
42+
lp.leftMargin = 16;
43+
lp.rightMargin = 16;
44+
lp.bottomMargin = 16;
45+
46+
content.addView(imageView, lp);
47+
48+
content.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
49+
@Override
50+
public boolean onPreDraw() {
51+
content.getViewTreeObserver().removeOnPreDrawListener(this);
52+
content.setVisibility(View.VISIBLE);
53+
54+
// actually you need to set visibility before stating animation in listener
55+
56+
mRevealAnimator = ViewAnimationUtils.createCircularReveal(content, 0, 0, 0,
57+
MainActivity.hypo(content.getWidth(), content.getHeight()));
58+
mRevealAnimator.setDuration(500);
59+
mRevealAnimator.setStartDelay(100);
60+
mRevealAnimator.setInterpolator(new AccelerateDecelerateInterpolator());
61+
mRevealAnimator.start();
62+
return true;
63+
}
64+
});
65+
66+
return frameLayout;
67+
}
68+
69+
}

app/src/main/java/io/codetail/circualrevealsample/MainActivity.java

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package io.codetail.circualrevealsample;
22

3+
import android.animation.ObjectAnimator;
34
import android.content.Intent;
45
import android.os.Bundle;
56
import android.support.design.widget.FloatingActionButton;
@@ -21,9 +22,6 @@
2122
import android.view.animation.Interpolator;
2223
import android.widget.Toast;
2324

24-
import com.nineoldandroids.animation.ObjectAnimator;
25-
import com.nineoldandroids.view.ViewHelper;
26-
2725
import java.lang.ref.WeakReference;
2826

2927
import butterknife.ButterKnife;
@@ -62,6 +60,7 @@ protected void onCreate(Bundle savedInstanceState) {
6260
mCardsAdapter = new RecycleAdapter();
6361
mCardsAdapter.setHasStableIds(true);
6462

63+
mCardsGroup.addOnScrollListener(new HideExtraOnScroll(mToolbar));
6564
mCardsGroup.setHasFixedSize(true);
6665
mCardsGroup.setItemViewCacheSize(3);
6766
mCardsGroup.setClipToPadding(false);
@@ -158,20 +157,6 @@ static float hypo(int a, int b){
158157
return (float) Math.sqrt(Math.pow(a, 2) + Math.pow(b, 2));
159158
}
160159

161-
@Override
162-
protected void onStart() {
163-
super.onStart();
164-
mCardsGroup.setOnScrollListener(new HideExtraOnScroll(mToolbar));
165-
}
166-
167-
@Override
168-
protected void onStop() {
169-
super.onStop();
170-
171-
// Prevent memory leaks, fuck yeah!
172-
mCardsGroup.setOnScrollListener(null);
173-
}
174-
175160
public static class RecycleAdapter extends RecyclerView.Adapter<CardHolder>{
176161

177162
@Override
@@ -302,14 +287,14 @@ public boolean isVisible(View target){
302287

303288
public void hide(final View target, float distance){
304289
ObjectAnimator animator = ObjectAnimator.ofFloat(target, "translationY",
305-
ViewHelper.getTranslationY(target), distance);
290+
target.getTranslationY(), distance);
306291
animator.setInterpolator(DECELERATE);
307292
animator.start();
308293
}
309294

310295
public void show(final View target){
311296
ObjectAnimator animator = ObjectAnimator.ofFloat(target, "translationY",
312-
ViewHelper.getTranslationY(target), 0f);
297+
target.getTranslationY(), 0f);
313298
animator.setInterpolator(ACCELERATE);
314299
animator.start();
315300
}
@@ -327,13 +312,23 @@ public boolean onOptionsItemSelected(MenuItem item) {
327312
Intent intent = null;
328313

329314
switch (item.getItemId()){
330-
case R.id.sampl2:
315+
case R.id.sample2:
331316
intent = new Intent(this, Sample2Activity.class);
332317
break;
333318

334-
case R.id.sampl3:
319+
case R.id.sample3:
335320
intent = new Intent(this, Sample3Activity.class);
336321
break;
322+
323+
case R.id.sample4:
324+
325+
getSupportFragmentManager()
326+
.beginTransaction()
327+
.add(android.R.id.content, new FragmentRevealExample(), "fragment:reveal")
328+
.addToBackStack("fragment:reveal")
329+
.commit();
330+
331+
return true;
337332
}
338333

339334
startActivity(intent);
Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
11
package io.codetail.circualrevealsample;
22

3-
import android.graphics.Rect;
4-
import android.os.Build;
53
import android.os.Bundle;
64
import android.support.v7.app.AppCompatActivity;
75
import android.view.View;
86
import android.view.ViewTreeObserver;
7+
import android.view.ViewTreeObserver.OnPreDrawListener;
98
import android.view.animation.AccelerateDecelerateInterpolator;
109

1110
import io.codetail.animation.SupportAnimator;
1211
import io.codetail.animation.ViewAnimationUtils;
1312

1413
public class Sample3Activity extends AppCompatActivity
15-
implements ViewTreeObserver.OnGlobalLayoutListener{
14+
implements OnPreDrawListener{
1615

1716
private CardViewPlus mContentView;
1817

@@ -23,7 +22,7 @@ protected void onCreate(Bundle savedInstanceState) {
2322

2423
mContentView = (CardViewPlus) findViewById(R.id.content);
2524

26-
getViewTreeObserver().addOnGlobalLayoutListener(this);
25+
getViewTreeObserver().addOnPreDrawListener(this);
2726
}
2827

2928
protected View getRootView(){
@@ -35,23 +34,19 @@ protected ViewTreeObserver getViewTreeObserver(){
3534
}
3635

3736
protected void startRevealTransition(){
38-
final Rect bounds = new Rect();
39-
getRootView().getHitRect(bounds);
4037
SupportAnimator animator = ViewAnimationUtils.createCircularReveal(getRootView(),
41-
bounds.right, bounds.bottom, 0, Sample2Activity.hypo(bounds.height(), bounds.width()));
38+
getRootView().getRight(), getRootView().getBottom(), 0,
39+
Sample2Activity.hypo(getRootView().getHeight(), getRootView().getWidth()),
40+
View.LAYER_TYPE_SOFTWARE);
4241
animator.setDuration(1000);
4342
animator.setInterpolator(new AccelerateDecelerateInterpolator());
4443
animator.start();
4544
}
4645

4746
@Override
48-
public void onGlobalLayout() {
49-
if(Build.VERSION.SDK_INT >= 16) {
50-
getViewTreeObserver().removeOnGlobalLayoutListener(this);
51-
}else{
52-
getViewTreeObserver().removeGlobalOnLayoutListener(this);
53-
}
54-
47+
public boolean onPreDraw() {
48+
getViewTreeObserver().removeOnPreDrawListener(this);
5549
startRevealTransition();
50+
return true;
5651
}
5752
}
89.9 KB
Loading
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<shape android:shape="rectangle" xmlns:android="http://schemas.android.com/apk/res/android">
3+
<stroke android:width="4dp" android:color="#fff" />
4+
</shape>

app/src/main/res/menu/menu_main.xml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,18 @@
22
xmlns:app="http://schemas.android.com/apk/res-auto"
33
xmlns:tools="http://schemas.android.com/tools" tools:context=".MainActivity">
44

5-
<item android:id="@+id/sampl2"
5+
<item android:id="@+id/sample2"
66
android:title="Sample2"
77
android:orderInCategory="100"
88
app:showAsAction="never" />
99

10-
<item android:id="@+id/sampl3"
10+
<item android:id="@+id/sample3"
1111
android:title="Sample2"
1212
android:orderInCategory="100"
1313
app:showAsAction="never" />
14+
15+
<item android:id="@+id/sample4"
16+
android:title="FragmentSample"
17+
android:orderInCategory="100"
18+
app:showAsAction="never" />
1419
</menu>

app/src/main/res/values/styles.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
</attr>
4747
<!-- Defines whether the foreground drawable should be drawn inside the padding.
4848
This property is turned on by default. -->
49-
<attr name="foregroundInsidePadding" format="boolean" />
49+
<attr name="foregroundInsidePadding" />
5050
<!-- Determines whether to measure all children or just those in
5151
the VISIBLE or INVISIBLE state when measuring. Defaults to false. -->
5252
<attr name="measureAllChildren" format="boolean" />

build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ buildscript {
55
jcenter()
66
}
77
dependencies {
8-
classpath 'com.android.tools.build:gradle:1.2.3'
9-
classpath 'com.github.dcendents:android-maven-plugin:1.2'
8+
classpath 'com.android.tools.build:gradle:1.5.0'
9+
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.3'
1010
// NOTE: Do not place your application dependencies here; they belong
1111
// in the individual module build.gradle files
1212
}

circualreveal/build.gradle

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,37 @@
11
apply plugin: 'com.android.library'
2-
apply plugin: 'android-maven'
2+
apply plugin: 'com.github.dcendents.android-maven'
33

44
android {
5-
compileSdkVersion 22
6-
buildToolsVersion "22.0.1"
5+
compileSdkVersion 23
6+
buildToolsVersion "23.0.2"
77

88

99
defaultConfig {
10-
minSdkVersion 9
11-
targetSdkVersion 22
10+
minSdkVersion 15
11+
targetSdkVersion 23
1212
}
1313
}
1414

15-
dependencies {
16-
compile 'com.nineoldandroids:library:2.4.0'
15+
// build a jar with source files
16+
task sourcesJar(type: Jar) {
17+
from android.sourceSets.main.java.srcDirs
18+
classifier = 'sources'
19+
}
20+
21+
task javadoc(type: Javadoc) {
22+
failOnError false
23+
source = android.sourceSets.main.java.sourceFiles
24+
classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
25+
classpath += configurations.compile
26+
}
27+
28+
// build a jar with javadoc
29+
task javadocJar(type: Jar, dependsOn: javadoc) {
30+
classifier = 'javadoc'
31+
from javadoc.destinationDir
32+
}
33+
34+
artifacts {
35+
archives sourcesJar
36+
archives javadocJar
1737
}

0 commit comments

Comments
 (0)