├── .gitignore
├── README.md
├── app
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── xyz
│ │ └── royliu
│ │ └── useravatar
│ │ └── ExampleInstrumentedTest.java
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── xyz
│ │ │ └── royliu
│ │ │ └── useravatar
│ │ │ ├── AnimateImageView.java
│ │ │ ├── AvatarLayout.java
│ │ │ ├── BlurBitmapUtil.java
│ │ │ ├── MainActivity.java
│ │ │ ├── PullToRefeshLayout.java
│ │ │ ├── ScreenUtil.java
│ │ │ └── ViewTrackController.java
│ └── res
│ │ ├── drawable-xxhdpi
│ │ ├── avatar.jpg
│ │ └── bg_empty_personal_update.png
│ │ ├── layout
│ │ └── activity_main.xml
│ │ ├── mipmap-hdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-mdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-xhdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-xxhdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-xxxhdpi
│ │ └── ic_launcher.png
│ │ ├── values-w820dp
│ │ └── dimens.xml
│ │ └── values
│ │ ├── colors.xml
│ │ ├── dimens.xml
│ │ ├── strings.xml
│ │ └── styles.xml
│ └── test
│ └── java
│ └── xyz
│ └── royliu
│ └── useravatar
│ └── ExampleUnitTest.java
├── build.gradle
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── screenshot
└── jike.gif
└── settings.gradle
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/workspace.xml
5 | /.idea/libraries
6 | .DS_Store
7 | /build
8 | /captures
9 | .externalNativeBuild
10 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # 仿即刻APP android端个人主页
2 |
3 | 
4 |
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 25
5 | buildToolsVersion "25.0.0"
6 | defaultConfig {
7 | applicationId "xyz.royliu.useravatar"
8 | minSdkVersion 19
9 | targetSdkVersion 25
10 | versionCode 1
11 | versionName "1.0"
12 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
13 |
14 | renderscriptTargetApi 19
15 | renderscriptSupportModeEnabled true
16 | }
17 | buildTypes {
18 | release {
19 | minifyEnabled false
20 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
21 | }
22 | }
23 | }
24 |
25 | dependencies {
26 | compile fileTree(dir: 'libs', include: ['*.jar'])
27 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
28 | exclude group: 'com.android.support', module: 'support-annotations'
29 | })
30 | compile 'com.android.support:appcompat-v7:25.0.0'
31 | testCompile 'junit:junit:4.12'
32 | compile 'de.hdodenhof:circleimageview:2.1.0'
33 | compile 'com.facebook.rebound:rebound:0.3.8'
34 | }
35 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in D:\Program Files\Android\sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/xyz/royliu/useravatar/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package xyz.royliu.useravatar;
2 |
3 | import android.content.Context;
4 | import android.support.test.InstrumentationRegistry;
5 | import android.support.test.runner.AndroidJUnit4;
6 |
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 |
10 | import static org.junit.Assert.*;
11 |
12 | /**
13 | * Instrumentation test, which will execute on an Android device.
14 | *
15 | * @see Testing documentation
16 | */
17 | @RunWith(AndroidJUnit4.class)
18 | public class ExampleInstrumentedTest {
19 | @Test
20 | public void useAppContext() throws Exception {
21 | // Context of the app under test.
22 | Context appContext = InstrumentationRegistry.getTargetContext();
23 |
24 | assertEquals("xyz.royliu.useravatar", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/app/src/main/java/xyz/royliu/useravatar/AnimateImageView.java:
--------------------------------------------------------------------------------
1 | package xyz.royliu.useravatar;
2 |
3 | import android.content.Context;
4 | import android.util.AttributeSet;
5 |
6 |
7 | import com.facebook.rebound.SimpleSpringListener;
8 | import com.facebook.rebound.Spring;
9 | import com.facebook.rebound.SpringSystem;
10 |
11 | import de.hdodenhof.circleimageview.CircleImageView;
12 |
13 | /**
14 | * Created by xmuSistone.
15 | */
16 | public class AnimateImageView extends CircleImageView {
17 | private Spring springX, springY;
18 | private SimpleSpringListener followerListenerX, followerListenerY; // 此为跟踪的回调,当前面一个view移动的时候,此为后面的view,需要更新endValue
19 |
20 | public AnimateImageView(Context context) {
21 | this(context, null);
22 | }
23 |
24 | public AnimateImageView(Context context, AttributeSet attrs) {
25 | this(context, attrs, 0);
26 | }
27 |
28 | public AnimateImageView(Context context, AttributeSet attrs, int defStyleAttr) {
29 | super(context, attrs, defStyleAttr);
30 |
31 | SpringSystem mSpringSystem = SpringSystem.create();
32 | springX = mSpringSystem.createSpring();
33 | springY = mSpringSystem.createSpring();
34 |
35 | springX.addListener(new SimpleSpringListener() {
36 | @Override
37 | public void onSpringUpdate(Spring spring) {
38 | int xPos = (int) spring.getCurrentValue();
39 | setScreenX(xPos);
40 | }
41 | });
42 |
43 | springY.addListener(new SimpleSpringListener() {
44 | @Override
45 | public void onSpringUpdate(Spring spring) {
46 | int yPos = (int) spring.getCurrentValue();
47 | setScreenY(yPos);
48 | }
49 | });
50 |
51 | followerListenerX = new SimpleSpringListener() {
52 | @Override
53 | public void onSpringUpdate(Spring spring) {
54 | int xPos = (int) spring.getCurrentValue();
55 | springX.setEndValue(xPos);
56 | }
57 | };
58 |
59 | followerListenerY = new SimpleSpringListener() {
60 | @Override
61 | public void onSpringUpdate(Spring spring) {
62 | int yPos = (int) spring.getCurrentValue();
63 | springY.setEndValue(yPos);
64 | }
65 | };
66 | }
67 |
68 | private void setScreenX(int screenX) {
69 | this.offsetLeftAndRight(screenX - getLeft());
70 | }
71 |
72 | private void setScreenY(int screenY) {
73 | this.offsetTopAndBottom(screenY - getTop());
74 | }
75 |
76 | public void animTo(int xPos, int yPos) {
77 | springX.setEndValue(xPos);
78 | springY.setEndValue(yPos);
79 | }
80 |
81 | /**
82 | * 顶部ImageView强行停止动画
83 | */
84 | public void stopAnimation() {
85 | springX.setAtRest();
86 | springY.setAtRest();
87 | }
88 |
89 | /**
90 | * 只为最顶部的view调用,触点松开后,回归原点
91 | */
92 | public void onRelease(int xPos, int yPos) {
93 | setCurrentSpringPos(getLeft(), getTop());
94 | animTo(xPos, yPos);
95 | }
96 |
97 | /**
98 | * 设置当前spring位置
99 | */
100 | public void setCurrentSpringPos(int xPos, int yPos) {
101 | springX.setCurrentValue(xPos);
102 | springY.setCurrentValue(yPos);
103 | }
104 |
105 | public Spring getSpringX() {
106 | return springX;
107 | }
108 |
109 | public Spring getSpringY() {
110 | return springY;
111 | }
112 |
113 | public SimpleSpringListener getFollowerListenerX() {
114 | return followerListenerX;
115 | }
116 |
117 | public SimpleSpringListener getFollowerListenerY() {
118 | return followerListenerY;
119 | }
120 | }
121 |
--------------------------------------------------------------------------------
/app/src/main/java/xyz/royliu/useravatar/AvatarLayout.java:
--------------------------------------------------------------------------------
1 | package xyz.royliu.useravatar;
2 |
3 | import android.content.Context;
4 | import android.graphics.Color;
5 | import android.support.v4.view.ViewCompat;
6 | import android.support.v4.widget.ViewDragHelper;
7 | import android.util.AttributeSet;
8 | import android.util.Log;
9 | import android.view.MotionEvent;
10 | import android.view.View;
11 | import android.widget.RelativeLayout;
12 |
13 | import java.util.ArrayList;
14 | import java.util.List;
15 |
16 | /**
17 | * Created by Roy on 2017/1/4.
18 | * desc:
19 | */
20 |
21 | public class AvatarLayout extends RelativeLayout {
22 | private static final String TAG = "AvatarLayout";
23 | AnimateImageView circleImageView;
24 | Context mContext;
25 | PullToRefeshLayout mPullLayout;
26 | ViewDragHelper mDragHelper;
27 |
28 | List mIvList;
29 |
30 | ViewTrackController mViewTrackController;
31 |
32 | public AvatarLayout(Context context, AttributeSet attrs, int defStyleAttr) {
33 | super(context, attrs, defStyleAttr);
34 | }
35 |
36 | public AvatarLayout(Context context, AttributeSet attrs) {
37 | super(context, attrs);
38 | mContext = context;
39 | mDragHelper = ViewDragHelper.create(this, 1.0f, new MyViewDragHelper());
40 | mDragHelper.setEdgeTrackingEnabled(ViewDragHelper.EDGE_TOP);
41 | mViewTrackController = ViewTrackController.create();
42 | }
43 |
44 | @Override
45 | protected void onFinishInflate() {
46 | super.onFinishInflate();
47 | RelativeLayout.LayoutParams params = new LayoutParams(ScreenUtil.dip2px(mContext, 80), ScreenUtil.dip2px(mContext, 80));
48 | params.topMargin = ScreenUtil.dip2px(mContext, 180 - 80 / 2);
49 | params.leftMargin = ScreenUtil.getScreenWidth(mContext) / 2 - ScreenUtil.dip2px(mContext, 80) / 2;
50 | mIvList = new ArrayList<>();
51 | for (int i = 0; i < 5; i++) {
52 | AnimateImageView circleImageView = new AnimateImageView(mContext);
53 | circleImageView.setImageResource(R.drawable.avatar);
54 | circleImageView.setBorderWidth(ScreenUtil.dip2px(mContext, 1));
55 | circleImageView.setBorderColor(Color.WHITE);
56 | circleImageView.setLayoutParams(params);
57 | addView(circleImageView);
58 | if (i == 4) {
59 | this.circleImageView = circleImageView;
60 | } else {
61 | circleImageView.setAlpha(0.3f);
62 | }
63 | mIvList.add(circleImageView);
64 | }
65 |
66 | mViewTrackController.init(mIvList);
67 |
68 | mPullLayout = (PullToRefeshLayout) getChildAt(0);
69 | mPullLayout.setmListener(new PullToRefeshLayout.OnPullRefreshListener() {
70 | @Override
71 | public void onMoveY(float distance) {
72 | if (circleImageView != null) {
73 | circleImageView.setTranslationY(distance);
74 | mViewTrackController.setOtherVisiable(false);
75 | }
76 | }
77 |
78 | @Override
79 | public void onMoveEnd() {
80 | if (circleImageView != null) {
81 | circleImageView.animate().translationY(0);
82 | }
83 | }
84 | });
85 |
86 | }
87 |
88 | private class MyViewDragHelper extends ViewDragHelper.Callback {
89 | @Override
90 | public boolean tryCaptureView(View child, int pointerId) {
91 | if (child == circleImageView) {
92 | circleImageView.stopAnimation();
93 | return true;
94 | }
95 | return false;
96 | }
97 |
98 | @Override
99 | public int getViewVerticalDragRange(View child) {
100 | return 1;
101 | }
102 |
103 | @Override
104 | public int clampViewPositionHorizontal(View child, int left, int dx) {
105 | return left;
106 | }
107 |
108 | @Override
109 | public int clampViewPositionVertical(View child, int top, int dy) {
110 | return top;
111 | }
112 |
113 | @Override
114 | public void onViewReleased(View releasedChild, float xvel, float yvel) {
115 | mViewTrackController.onRelease();
116 | }
117 |
118 | @Override
119 | public void onViewPositionChanged(View changedView, int left, int top, int dx, int dy) {
120 | super.onViewPositionChanged(changedView, left, top, dx, dy);
121 | mViewTrackController.setOtherVisiable(true);
122 | mViewTrackController.onTopViewPosChanged(left, top);
123 | }
124 | }
125 |
126 | @Override
127 | public void computeScroll() {
128 | if (mDragHelper.continueSettling(true)) {
129 | ViewCompat.postInvalidateOnAnimation(this);
130 | }
131 | }
132 |
133 | @Override
134 | public boolean onInterceptTouchEvent(MotionEvent event) {
135 | if (event.getAction() == MotionEvent.ACTION_DOWN && clickInAvatarView(event)) {
136 | return true;
137 | }
138 | Log.d(TAG, "onInterceptTouchEvent: " + mDragHelper.shouldInterceptTouchEvent(event));
139 | return mDragHelper.shouldInterceptTouchEvent(event);
140 | }
141 |
142 | @Override
143 | public boolean onTouchEvent(MotionEvent event) {
144 | Log.d(TAG, "onTouchEvent: ");
145 | mDragHelper.processTouchEvent(event);
146 | return true;
147 | }
148 |
149 | @Override
150 | protected void onLayout(boolean changed, int l, int t, int r, int b) {
151 | super.onLayout(changed, l, t, r, b);
152 | mViewTrackController.setOriginPos(circleImageView.getLeft(), circleImageView.getTop());
153 | }
154 |
155 | /**
156 | * 判断点击位置是否位于头像圆形的里面
157 | */
158 | private boolean clickInAvatarView(MotionEvent event) {
159 | boolean isInCircle = true;
160 | int clickX = (int) event.getRawX();
161 | int clickY = (int) event.getRawY();
162 |
163 | //获取控件在屏幕的位置
164 | int[] location = new int[2];
165 | circleImageView.getLocationOnScreen(location);
166 |
167 | //控件相对于屏幕的x与y坐标
168 | int x = location[0];
169 | int y = location[1];
170 |
171 | //圆半径 通过左右坐标计算获得getLeft
172 | int r = (circleImageView.getRight() - circleImageView.getLeft()) / 2;
173 |
174 | //圆心坐标
175 | int vCenterX = x + r;
176 | int vCenterY = y + r;
177 |
178 | //点击位置x坐标与圆心的x坐标的距离
179 | int distanceX = Math.abs(vCenterX - clickX);
180 | //点击位置y坐标与圆心的y坐标的距离
181 | int distanceY = Math.abs(vCenterY - clickY);
182 | //点击位置与圆心的直线距离
183 | int distanceZ = (int) Math.sqrt(Math.pow(distanceX, 2) + Math.pow(distanceY, 2));
184 | if (distanceZ > r) {
185 | return false;
186 | }
187 | return isInCircle;
188 | }
189 | }
190 |
--------------------------------------------------------------------------------
/app/src/main/java/xyz/royliu/useravatar/BlurBitmapUtil.java:
--------------------------------------------------------------------------------
1 | package xyz.royliu.useravatar;
2 |
3 | import android.content.Context;
4 | import android.graphics.Bitmap;
5 | import android.renderscript.Allocation;
6 | import android.renderscript.Element;
7 | import android.renderscript.RenderScript;
8 | import android.renderscript.ScriptIntrinsicBlur;
9 |
10 | /**
11 | * @author Qiushui
12 | * @description 模糊图片工具类
13 | * @revision Xiarui 16.09.05
14 | */
15 | public class BlurBitmapUtil {
16 | //图片缩放比例
17 | private static final float BITMAP_SCALE = 0.4f;
18 |
19 | /**
20 | * 模糊图片的具体方法
21 | *
22 | * @param context 上下文对象
23 | * @param image 需要模糊的图片
24 | * @return 模糊处理后的图片
25 | */
26 | public static Bitmap blurBitmap(Context context, Bitmap image, float blurRadius) {
27 | // 计算图片缩小后的长宽
28 | int width = Math.round(image.getWidth() * BITMAP_SCALE);
29 | int height = Math.round(image.getHeight() * BITMAP_SCALE);
30 |
31 | // 将缩小后的图片做为预渲染的图片
32 | Bitmap inputBitmap = Bitmap.createScaledBitmap(image, width, height, false);
33 | // 创建一张渲染后的输出图片
34 | Bitmap outputBitmap = Bitmap.createBitmap(inputBitmap);
35 |
36 | // 创建RenderScript内核对象
37 | RenderScript rs = RenderScript.create(context);
38 | // 创建一个模糊效果的RenderScript的工具对象
39 | ScriptIntrinsicBlur blurScript = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));
40 |
41 | // 由于RenderScript并没有使用VM来分配内存,所以需要使用Allocation类来创建和分配内存空间
42 | // 创建Allocation对象的时候其实内存是空的,需要使用copyTo()将数据填充进去
43 | Allocation tmpIn = Allocation.createFromBitmap(rs, inputBitmap);
44 | Allocation tmpOut = Allocation.createFromBitmap(rs, outputBitmap);
45 |
46 | // 设置渲染的模糊程度, 25f是最大模糊度
47 | blurScript.setRadius(blurRadius);
48 | // 设置blurScript对象的输入内存
49 | blurScript.setInput(tmpIn);
50 | // 将输出数据保存到输出内存中
51 | blurScript.forEach(tmpOut);
52 |
53 | // 将数据填充到Allocation中
54 | tmpOut.copyTo(outputBitmap);
55 |
56 | return outputBitmap;
57 | }
58 | }
--------------------------------------------------------------------------------
/app/src/main/java/xyz/royliu/useravatar/MainActivity.java:
--------------------------------------------------------------------------------
1 | package xyz.royliu.useravatar;
2 |
3 | import android.graphics.Bitmap;
4 | import android.graphics.BitmapFactory;
5 | import android.os.Build;
6 | import android.os.Bundle;
7 | import android.support.v7.app.AppCompatActivity;
8 | import android.view.Window;
9 | import android.view.WindowManager;
10 | import android.widget.ImageView;
11 |
12 | public class MainActivity extends AppCompatActivity {
13 |
14 | ImageView ivBackGround;
15 |
16 | @Override
17 | protected void onCreate(Bundle savedInstanceState) {
18 | super.onCreate(savedInstanceState);
19 | setContentView(R.layout.activity_main);
20 | getSupportActionBar().hide();
21 | ivBackGround = (ImageView) findViewById(R.id.iv_bg);
22 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
23 | Window window = getWindow();
24 | window.setFlags(
25 | WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS,
26 | WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
27 | }
28 |
29 | Bitmap bitmap = BlurBitmapUtil.blurBitmap(this, BitmapFactory.decodeResource(getResources(), R.drawable.avatar), 3f);
30 | ivBackGround.setImageBitmap(bitmap);
31 | }
32 |
33 | }
34 |
--------------------------------------------------------------------------------
/app/src/main/java/xyz/royliu/useravatar/PullToRefeshLayout.java:
--------------------------------------------------------------------------------
1 | package xyz.royliu.useravatar;
2 |
3 | import android.content.Context;
4 | import android.util.AttributeSet;
5 | import android.util.Log;
6 | import android.view.MotionEvent;
7 | import android.view.View;
8 | import android.widget.LinearLayout;
9 |
10 | /**
11 | * Created by Roy on 2016/12/28.
12 | * desc:
13 | */
14 |
15 | public class PullToRefeshLayout extends LinearLayout {
16 | private static final String TAG = "PullToRefeshLayout";
17 | private int mHeaderOffsetTop = 0;
18 | private int mHeaderOffsetBottom = 0;
19 |
20 | private float mStratY;
21 | private OnPullRefreshListener mListener;
22 |
23 | public PullToRefeshLayout(Context context, AttributeSet attrs) {
24 | super(context, attrs);
25 | mHeaderOffsetTop = ScreenUtil.dip2px(context, 100);
26 | mHeaderOffsetBottom = ScreenUtil.dip2px(context, 100);
27 | }
28 |
29 | @Override
30 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
31 | int widthMode = MeasureSpec.getMode(widthMeasureSpec);
32 | int sizeWidth = MeasureSpec.getSize(widthMeasureSpec);
33 | int heightMode = MeasureSpec.getMode(heightMeasureSpec);
34 | int sizeHeight = MeasureSpec.getSize(heightMeasureSpec);
35 | measureChildren(widthMeasureSpec, heightMeasureSpec);
36 | setMeasuredDimension(sizeWidth, sizeHeight);
37 | }
38 |
39 | @Override
40 | protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
41 | int count = getChildCount();
42 | if (count != 2) {
43 | throw new RuntimeException("should have 2 child views!");
44 | }
45 | int headHeight = 0;
46 | for (int i = 0; i < count; i++) {
47 | View childView = getChildAt(i);
48 |
49 | if (i == 0) {
50 | headHeight = childView.getMeasuredHeight();
51 | childView.layout(0, -mHeaderOffsetTop, childView.getMeasuredWidth(), headHeight - mHeaderOffsetTop);
52 | } else if (i == 1) {
53 | childView.layout(0, headHeight - mHeaderOffsetTop - mHeaderOffsetBottom, childView.getMeasuredWidth(), headHeight - mHeaderOffsetTop - mHeaderOffsetBottom + childView.getMeasuredHeight());
54 | }
55 | }
56 | }
57 |
58 | @Override
59 | public boolean onTouchEvent(MotionEvent event) {
60 | switch (event.getAction()) {
61 | case MotionEvent.ACTION_DOWN:
62 | mStratY = event.getY();
63 | return true;
64 | case MotionEvent.ACTION_MOVE:
65 | float mCurrentY = event.getY();
66 | if (mCurrentY - mStratY < 0) {
67 | return true;
68 | }
69 | if ((mCurrentY - mStratY) / 4 > mHeaderOffsetTop) {
70 |
71 | } else {
72 | getChildAt(0).setTranslationY((mCurrentY - mStratY) / 4);
73 | getChildAt(1).setTranslationY((mCurrentY - mStratY) / 2);
74 | if (mListener != null) {
75 | mListener.onMoveY((mCurrentY - mStratY) / 2);
76 | }
77 | }
78 | return true;
79 | case MotionEvent.ACTION_UP:
80 | getChildAt(0).animate().translationY(0);
81 | getChildAt(1).animate().translationY(0);
82 | if (mListener != null) {
83 | mListener.onMoveEnd();
84 | }
85 | return true;
86 | default:
87 | break;
88 | }
89 | return super.onTouchEvent(event);
90 | }
91 |
92 | public void setmListener(OnPullRefreshListener mListener) {
93 | this.mListener = mListener;
94 | }
95 |
96 | interface OnPullRefreshListener {
97 | void onMoveY(float distance);
98 |
99 | void onMoveEnd();
100 | }
101 | }
102 |
--------------------------------------------------------------------------------
/app/src/main/java/xyz/royliu/useravatar/ScreenUtil.java:
--------------------------------------------------------------------------------
1 | package xyz.royliu.useravatar;
2 |
3 | import android.content.Context;
4 | import android.util.DisplayMetrics;
5 |
6 | /**
7 | * Created by roy on 2016/8/9.
8 | * desc:
9 | */
10 | public class ScreenUtil {
11 | /**
12 | * dip转px
13 | */
14 | public static int dip2px(Context context, float dipValue) {
15 | final float scale = context.getResources().getDisplayMetrics().density;
16 | return (int) (dipValue * scale + 0.5f);
17 | }
18 |
19 | /**
20 | * px转dip
21 | */
22 | public static int px2dip(Context context, float pxValue) {
23 | final float scale = context.getResources().getDisplayMetrics().density;
24 | return (int) (pxValue / scale + 0.5f);
25 | }
26 |
27 | /**
28 | * 获取屏幕高度
29 | * @param context
30 | * @return
31 | */
32 | public static int getScreenHeight(Context context){
33 | if (null == context) {
34 | return 0;
35 | }
36 | DisplayMetrics dm = new DisplayMetrics();
37 | dm = context.getApplicationContext().getResources().getDisplayMetrics();
38 | return dm.heightPixels;
39 | }
40 |
41 | public static int getScreenWidth(Context context){
42 | if (null == context) {
43 | return 0;
44 | }
45 | DisplayMetrics dm = new DisplayMetrics();
46 | dm = context.getApplicationContext().getResources().getDisplayMetrics();
47 | return dm.widthPixels;
48 | }
49 |
50 | /**
51 | * 将px值转换为sp值,保证文字大小不变
52 | * (DisplayMetrics类中属性scaledDensity)
53 | * @return
54 | */
55 | public static int px2sp(Context context, float pxValue) {
56 | final float fontScale = context.getResources().getDisplayMetrics().scaledDensity;
57 | return (int) (pxValue / fontScale + 0.5f);
58 | }
59 |
60 | /**
61 | * 将sp值转换为px值,保证文字大小不变
62 | * (DisplayMetrics类中属性scaledDensity)
63 | * @return
64 | */
65 | public static int sp2px(Context context, float spValue) {
66 | final float fontScale = context.getResources().getDisplayMetrics().scaledDensity;
67 | return (int) (spValue * fontScale + 0.5f);
68 | }
69 |
70 | }
71 |
--------------------------------------------------------------------------------
/app/src/main/java/xyz/royliu/useravatar/ViewTrackController.java:
--------------------------------------------------------------------------------
1 | package xyz.royliu.useravatar;
2 |
3 | import android.view.View;
4 |
5 | import java.util.List;
6 |
7 | /**
8 | * Created by xmuSistone
9 | */
10 | public class ViewTrackController {
11 | private List imageViewList;
12 | private AnimateImageView topView;
13 | private AnimateImageView topFollowerView;
14 | private int resetPosX, resetPosY;
15 |
16 | private ViewTrackController() {
17 | }
18 |
19 | public static ViewTrackController create() {
20 | return new ViewTrackController();
21 | }
22 |
23 | public void init(List imageViewList) {
24 | this.imageViewList = imageViewList;
25 |
26 | int len = imageViewList.size();
27 | this.topView = imageViewList.get(len - 1);
28 | this.topFollowerView = imageViewList.get(len - 2);
29 |
30 | for (int i = 1; i < len; i++) {
31 | AnimateImageView view1 = imageViewList.get(i - 1);
32 | AnimateImageView view2 = imageViewList.get(i);
33 | view2.getSpringX().addListener(view1.getFollowerListenerX());
34 | view2.getSpringY().addListener(view1.getFollowerListenerY());
35 | }
36 | }
37 |
38 | /**
39 | * 拖动view的位置改变,后面的view会自动跟着变
40 | */
41 | public void onTopViewPosChanged(int xPos, int yPos) {
42 | // 第一个跟随者移动了,后面的跟随者会自动移动
43 | topFollowerView.animTo(xPos, yPos);
44 | }
45 |
46 | /**
47 | * 手指松开的时候调用
48 | */
49 | public void onRelease() {
50 | topView.onRelease(resetPosX, resetPosY);
51 | }
52 |
53 | /**
54 | * 设置view最初的原始位置
55 | */
56 | public void setOriginPos(int xPos, int yPos) {
57 | resetPosX = xPos;
58 | resetPosY = yPos;
59 |
60 | int len = imageViewList.size();
61 | for (int i = 0; i < len; i++) {
62 | imageViewList.get(i).setCurrentSpringPos(xPos, yPos);
63 | }
64 | }
65 |
66 | public void setOtherVisiable(boolean visiable) {
67 | int len = imageViewList.size();
68 | for (int i = 0; i < len; i++) {
69 | if (i != len - 1) {
70 | imageViewList.get(i).setVisibility(visiable ? View.VISIBLE : View.GONE);
71 | }
72 | }
73 | }
74 | }
75 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/avatar.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lololiu/jike-useravatar-layout/1bdbeca85fc2c99f32d1f712e086400400750085/app/src/main/res/drawable-xxhdpi/avatar.jpg
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/bg_empty_personal_update.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lololiu/jike-useravatar-layout/1bdbeca85fc2c99f32d1f712e086400400750085/app/src/main/res/drawable-xxhdpi/bg_empty_personal_update.png
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
15 |
16 |
21 |
22 |
28 |
29 |
34 |
35 |
44 |
45 |
50 |
51 |
56 |
57 |
63 |
64 |
70 |
71 |
72 |
77 |
78 |
84 |
85 |
91 |
92 |
93 |
98 |
99 |
105 |
106 |
112 |
113 |
114 |
115 |
120 |
121 |
122 |
128 |
129 |
136 |
137 |
138 |
139 |
140 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lololiu/jike-useravatar-layout/1bdbeca85fc2c99f32d1f712e086400400750085/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lololiu/jike-useravatar-layout/1bdbeca85fc2c99f32d1f712e086400400750085/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lololiu/jike-useravatar-layout/1bdbeca85fc2c99f32d1f712e086400400750085/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lololiu/jike-useravatar-layout/1bdbeca85fc2c99f32d1f712e086400400750085/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lololiu/jike-useravatar-layout/1bdbeca85fc2c99f32d1f712e086400400750085/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | jike-useravatar-layout
3 |
4 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/app/src/test/java/xyz/royliu/useravatar/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package xyz.royliu.useravatar;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() throws Exception {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 | repositories {
5 | jcenter()
6 | }
7 | dependencies {
8 | classpath 'com.android.tools.build:gradle:2.2.2'
9 |
10 | // NOTE: Do not place your application dependencies here; they belong
11 | // in the individual module build.gradle files
12 | }
13 | }
14 |
15 | allprojects {
16 | repositories {
17 | jcenter()
18 | }
19 | }
20 |
21 | task clean(type: Delete) {
22 | delete rootProject.buildDir
23 | }
24 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | ## Project-wide Gradle settings.
2 | #
3 | # For more details on how to configure your build environment visit
4 | # http://www.gradle.org/docs/current/userguide/build_environment.html
5 | #
6 | # Specifies the JVM arguments used for the daemon process.
7 | # The setting is particularly useful for tweaking memory settings.
8 | # Default value: -Xmx1024m -XX:MaxPermSize=256m
9 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
10 | #
11 | # When configured, Gradle will run in incubating parallel mode.
12 | # This option should only be used with decoupled projects. More details, visit
13 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
14 | # org.gradle.parallel=true
15 | #Thu Dec 29 14:58:36 CST 2016
16 | systemProp.http.proxyHost=127.0.0.1
17 | org.gradle.jvmargs=-Xmx1536m
18 | systemProp.http.proxyPort=8087
19 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lololiu/jike-useravatar-layout/1bdbeca85fc2c99f32d1f712e086400400750085/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Mon Dec 28 10:00:20 PST 2015
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip
7 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/screenshot/jike.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lololiu/jike-useravatar-layout/1bdbeca85fc2c99f32d1f712e086400400750085/screenshot/jike.gif
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
2 |
--------------------------------------------------------------------------------