Skip to content

Commit

Permalink
Update version to 1.0.2
Browse files Browse the repository at this point in the history
 - Fix back from outside with wrong position
  • Loading branch information
hearsilent committed Mar 10, 2017
1 parent f9a0db2 commit ea6048a
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 19 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ android {
applicationId "hearsilent.amazingavatar"
minSdkVersion 16
targetSdkVersion 25
versionCode 101
versionName "1.0.1"
versionCode 102
versionName "1.0.2"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
Expand Down
50 changes: 33 additions & 17 deletions app/src/main/java/hearsilent/amazingavatar/MainActivity.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package hearsilent.amazingavatar;

import android.graphics.Paint;
import android.graphics.Rect;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.support.design.widget.AppBarLayout;
import android.support.v4.widget.Space;
import android.support.v7.app.AppCompatActivity;
Expand Down Expand Up @@ -47,7 +47,6 @@ public class MainActivity extends AppCompatActivity {
private int[] mAvatarPoint = new int[2], mSpacePoint = new int[2], mToolbarTextPoint =
new int[2], mTitleTextViewPoint = new int[2];
private float mTitleTextSize;
private int mTitleTextViewWidth;

@Override
protected void onCreate(Bundle savedInstanceState) {
Expand Down Expand Up @@ -145,34 +144,51 @@ public void onSuccess(AvatarModel avatarModel) {
mTitleTextView.setText(
String.format(Locale.getDefault(), "%s %s", avatarModel.firstName,
avatarModel.lastName));
mTitleTextView.post(new Runnable() {
new Handler(Looper.getMainLooper()).post(new Runnable() {

@Override
public void run() {
Rect bounds = new Rect();
Paint textPaint = mTitleTextView.getPaint();
textPaint.setTextSize(mTitleTextSize);
textPaint.getTextBounds(mTitleTextView.getText().toString(), 0,
mTitleTextView.getText().length(), bounds);
mTitleTextViewPoint[0] -= (bounds.width() - mTitleTextViewWidth) / 2;
mTitleTextViewWidth = bounds.width();
translationView(mAppBarStateChangeListener.getCurrentOffset());
resetPoints();
}
});
}
});
}

@Override
public void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);
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;
mSpace.getLocationOnScreen(mSpacePoint);
mToolbarTextView.getLocationOnScreen(mToolbarTextPoint);
mToolbarTextPoint[0] += Utils.convertDpToPixelSize(24, this);
mTitleTextView.getLocationOnScreen(mTitleTextViewPoint);
mTitleTextViewWidth = mTitleTextView.getWidth();
mTitleTextView.post(new Runnable() {

@Override
public void run() {
mTitleTextView.getLocationOnScreen(mTitleTextViewPoint);
translationView(mAppBarStateChangeListener.getCurrentOffset());
}
});
}

@Override
public void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);
if (!hasFocus) {
return;
}
resetPoints();
}

private class Adapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
Expand Down

0 comments on commit ea6048a

Please sign in to comment.