From 854561e4d7345780fdc9c2a2e8b14082fa417607 Mon Sep 17 00:00:00 2001 From: HearSilent Date: Thu, 31 May 2018 16:07:13 +0800 Subject: [PATCH] Update version to 1.0.4, Improve performance when resume --- app/build.gradle | 28 ++++++------ .../amazingavatar/MainActivity.java | 44 +++++++++---------- .../callbacks/AvatarCallback.java | 3 -- .../amazingavatar/libs/FlingBehavior.java | 10 +++-- app/src/main/res/layout/activity_main.xml | 2 +- build.gradle | 2 +- gradle/wrapper/gradle-wrapper.properties | 4 +- 7 files changed, 44 insertions(+), 49 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index dd7269a..90129ee 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,14 +1,14 @@ apply plugin: 'com.android.application' android { - compileSdkVersion 25 - buildToolsVersion "25.0.2" + compileSdkVersion 27 + buildToolsVersion "27.0.3" defaultConfig { applicationId "hearsilent.amazingavatar" minSdkVersion 16 - targetSdkVersion 25 - versionCode 103 - versionName "1.0.3" + targetSdkVersion 27 + versionCode 104 + versionName "1.0.4" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" } buildTypes { @@ -20,15 +20,15 @@ android { } dependencies { - compile fileTree(dir: 'libs', include: ['*.jar']) - androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { + implementation fileTree(dir: 'libs', include: ['*.jar']) + androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', { exclude group: 'com.android.support', module: 'support-annotations' }) - compile 'com.android.support:appcompat-v7:25.2.0' - compile 'com.android.support:recyclerview-v7:25.2.0' - compile 'com.android.support:design:25.2.0' - compile 'de.hdodenhof:circleimageview:2.1.0' - compile 'com.loopj.android:android-async-http:1.4.9' - compile 'com.nostra13.universalimageloader:universal-image-loader:1.9.5' - testCompile 'junit:junit:4.12' + implementation 'com.android.support:appcompat-v7:27.1.1' + implementation 'com.android.support:recyclerview-v7:27.1.1' + implementation 'com.android.support:design:27.1.1' + implementation 'de.hdodenhof:circleimageview:2.2.0' + implementation 'com.loopj.android:android-async-http:1.4.9' + implementation 'com.nostra13.universalimageloader:universal-image-loader:1.9.5' + testImplementation 'junit:junit:4.12' } diff --git a/app/src/main/java/hearsilent/amazingavatar/MainActivity.java b/app/src/main/java/hearsilent/amazingavatar/MainActivity.java index bf2cfa0..b723fad 100644 --- a/app/src/main/java/hearsilent/amazingavatar/MainActivity.java +++ b/app/src/main/java/hearsilent/amazingavatar/MainActivity.java @@ -3,8 +3,8 @@ import android.os.Bundle; import android.os.Handler; import android.os.Looper; +import android.support.annotation.NonNull; import android.support.design.widget.AppBarLayout; -import android.support.v4.widget.Space; import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.DefaultItemAnimator; import android.support.v7.widget.DividerItemDecoration; @@ -15,6 +15,7 @@ import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; +import android.widget.Space; import android.widget.TextView; import com.nostra13.universalimageloader.core.ImageLoader; @@ -59,13 +60,13 @@ protected void onCreate(Bundle savedInstanceState) { } private void findViews() { - mAppBarLayout = (AppBarLayout) findViewById(R.id.app_bar); - mAvatarImageView = (CircleImageView) findViewById(R.id.imageView_avatar); - mToolbarTextView = (TextView) findViewById(R.id.toolbar_title); - mTitleTextView = (TextView) findViewById(R.id.textView_title); - mSpace = (Space) findViewById(R.id.space); - mToolBar = (Toolbar) findViewById(R.id.toolbar); - mRecyclerView = (RecyclerView) findViewById(recyclerView); + mAppBarLayout = findViewById(R.id.app_bar); + mAvatarImageView = findViewById(R.id.imageView_avatar); + mToolbarTextView = findViewById(R.id.toolbar_title); + mTitleTextView = findViewById(R.id.textView_title); + mSpace = findViewById(R.id.space); + mToolBar = findViewById(R.id.toolbar); + mRecyclerView = findViewById(recyclerView); } private void setUpViews() { @@ -155,28 +156,22 @@ public void run() { }); } - private void clearAnim() { - mAvatarImageView.setTranslationX(0); - mAvatarImageView.setTranslationY(0); - mTitleTextView.setTextSize(TypedValue.COMPLEX_UNIT_PX, mTitleTextSize); - mTitleTextView.setTranslationX(0); - mTitleTextView.setTranslationY(0); - } - private void resetPoints() { - clearAnim(); - int avatarSize = Utils.convertDpToPixelSize(EXPAND_AVATAR_SIZE_DP, this); mAvatarImageView.getLocationOnScreen(mAvatarPoint); - mAvatarPoint[0] -= (avatarSize - mAvatarImageView.getWidth()) / 2; + mAvatarPoint[0] -= mAvatarImageView.getTranslationX() + + (avatarSize - mAvatarImageView.getWidth()) / 2f; + mAvatarPoint[1] -= mAvatarImageView.getTranslationY(); mSpace.getLocationOnScreen(mSpacePoint); mToolbarTextView.getLocationOnScreen(mToolbarTextPoint); mToolbarTextPoint[0] += Utils.convertDpToPixelSize(16, this); - mTitleTextView.post(new Runnable() { + mTitleTextView.getLocationOnScreen(mTitleTextViewPoint); + mTitleTextViewPoint[0] -= mTitleTextView.getTranslationX(); + mTitleTextViewPoint[1] -= mTitleTextView.getTranslationY(); + new Handler().post(new Runnable() { @Override public void run() { - mTitleTextView.getLocationOnScreen(mTitleTextViewPoint); translationView(mAppBarStateChangeListener.getCurrentOffset()); } }); @@ -200,18 +195,19 @@ private class DemoViewHolder extends RecyclerView.ViewHolder { private DemoViewHolder(View view) { super(view); - textView = (TextView) view.findViewById(R.id.textView); + textView = view.findViewById(R.id.textView); } } + @NonNull @Override - public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { + public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { return new DemoViewHolder(LayoutInflater.from(parent.getContext()) .inflate(R.layout.item_demo, parent, false)); } @Override - public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) { + public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) { ((DemoViewHolder) holder).textView .setText(String.format(Locale.getDefault(), "HearSilent %d", position)); } diff --git a/app/src/main/java/hearsilent/amazingavatar/callbacks/AvatarCallback.java b/app/src/main/java/hearsilent/amazingavatar/callbacks/AvatarCallback.java index 570cd86..1e9af83 100644 --- a/app/src/main/java/hearsilent/amazingavatar/callbacks/AvatarCallback.java +++ b/app/src/main/java/hearsilent/amazingavatar/callbacks/AvatarCallback.java @@ -7,9 +7,6 @@ public class AvatarCallback { public void onSuccess(AvatarModel avatarModel) { } - public void onFail(String errorMessage) { - } - public void onFail() { } } \ No newline at end of file diff --git a/app/src/main/java/hearsilent/amazingavatar/libs/FlingBehavior.java b/app/src/main/java/hearsilent/amazingavatar/libs/FlingBehavior.java index 3921aa9..c2c0cbf 100644 --- a/app/src/main/java/hearsilent/amazingavatar/libs/FlingBehavior.java +++ b/app/src/main/java/hearsilent/amazingavatar/libs/FlingBehavior.java @@ -1,6 +1,7 @@ package hearsilent.amazingavatar.libs; import android.content.Context; +import android.support.annotation.NonNull; import android.support.design.widget.AppBarLayout; import android.support.design.widget.CoordinatorLayout; import android.support.v7.widget.RecyclerView; @@ -20,8 +21,9 @@ public FlingBehavior(Context context, AttributeSet attrs) { } @Override - public boolean onNestedFling(CoordinatorLayout coordinatorLayout, AppBarLayout child, - View target, float velocityX, float velocityY, boolean consumed) { + public boolean onNestedFling(@NonNull CoordinatorLayout coordinatorLayout, + @NonNull AppBarLayout child, @NonNull View target, float velocityX, + float velocityY, boolean consumed) { if (velocityY > 0 && !isPositive || velocityY < 0 && isPositive) { velocityY = velocityY * -1; } @@ -37,8 +39,8 @@ public boolean onNestedFling(CoordinatorLayout coordinatorLayout, AppBarLayout c @Override public void onNestedPreScroll(CoordinatorLayout coordinatorLayout, AppBarLayout child, - View target, int dx, int dy, int[] consumed) { - super.onNestedPreScroll(coordinatorLayout, child, target, dx, dy, consumed); + View target, int dx, int dy, int[] consumed, int type) { + super.onNestedPreScroll(coordinatorLayout, child, target, dx, dy, consumed, type); isPositive = dy > 0; } } \ No newline at end of file diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 08d0647..353d4e2 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -38,7 +38,7 @@ app:layout_collapseMode="parallax" app:layout_collapseParallaxMultiplier="1"> -