Skip to content

Commit

Permalink
Update version to 1.0.6, Handle long name
Browse files Browse the repository at this point in the history
  • Loading branch information
hearsilent committed Jun 12, 2018
1 parent 894b522 commit 8518db9
Show file tree
Hide file tree
Showing 9 changed files with 44 additions and 38 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ An android amazing avatar anim in CollapsingToolbarLayout.
<img src="https://raw.githubusercontent.com/hearsilent/AmazingAvatar/master/screenshots/screenrecord.gif" height="500">

### Expanded
<img src="https://raw.githubusercontent.com/hearsilent/AmazingAvatar/master/screenshots/device-2018-06-12-173327.png" height="500">
<img src="https://raw.githubusercontent.com/hearsilent/AmazingAvatar/master/screenshots/device-2018-06-12-230517.png" height="500">

### Collapsed
<img src="https://raw.githubusercontent.com/hearsilent/AmazingAvatar/master/screenshots/device-2018-06-12-173349.png" height="500">
<img src="https://raw.githubusercontent.com/hearsilent/AmazingAvatar/master/screenshots/device-2018-06-12-230536.png" height="500">

## Usage

Expand Down
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 27
versionCode 105
versionName "1.0.5"
versionCode 106
versionName "1.0.6"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
Expand Down
40 changes: 21 additions & 19 deletions app/src/main/java/hearsilent/amazingavatar/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -121,23 +121,24 @@ private void translationView(float offset) {
float xAvatarOffset =
(mSpacePoint[0] - mAvatarPoint[0] - (expandAvatarSize - newAvatarSize) / 2f) *
offset;
// If avatar center in vertical, just half `(expandAvatarSize - newAvatarSize)`
float yAvatarOffset =
(mSpacePoint[1] - mAvatarPoint[1] - (expandAvatarSize - newAvatarSize) / 2f) *
offset;
(mSpacePoint[1] - mAvatarPoint[1] - (expandAvatarSize - newAvatarSize)) * offset;
mAvatarImageView.getLayoutParams().width = Math.round(newAvatarSize);
mAvatarImageView.getLayoutParams().height = Math.round(newAvatarSize);
mAvatarImageView.setTranslationX(xAvatarOffset);
mAvatarImageView.setTranslationY(yAvatarOffset);

float newTextSize =
mTitleTextSize - (mTitleTextSize - mToolbarTextView.getTextSize()) * offset;
Paint paint = new Paint();
Paint paint = new Paint(mTitleTextView.getPaint());
paint.setTextSize(newTextSize);
float newTextWidth = Utils.getTextWidth(paint, mTitleTextView.getText().toString());
paint.setTextSize(mTitleTextSize);
float originTextWidth = Utils.getTextWidth(paint, mTitleTextView.getText().toString());
float xTitleOffset = (mToolbarTextPoint[0] - mTitleTextViewPoint[0] -
(originTextWidth - newTextWidth) / 2f) * offset;
(mToolbarTextView.getWidth() > newTextWidth ?
(originTextWidth - newTextWidth) / 2f : 0)) * offset;
float yTitleOffset = (mToolbarTextPoint[1] - mTitleTextViewPoint[1]) * offset;
mTitleTextView.setTextSize(TypedValue.COMPLEX_UNIT_PX, newTextSize);
mTitleTextView.setTranslationX(xTitleOffset);
Expand All @@ -164,14 +165,14 @@ public void onSuccess(AvatarModel avatarModel) {

@Override
public void run() {
resetPoints();
resetPoints(true);
}
});
}
});
}

private void resetPoints() {
private void resetPoints(boolean isTextChanged) {
final float offset = mAppBarStateChangeListener.getCurrentOffset();

float newAvatarSize = Utils.convertDpToPixel(
Expand All @@ -183,8 +184,9 @@ private void resetPoints() {
mAvatarImageView.getLocationOnScreen(avatarPoint);
mAvatarPoint[0] = avatarPoint[0] - mAvatarImageView.getTranslationX() -
(expandAvatarSize - newAvatarSize) / 2f;
// If avatar center in vertical, just half `(expandAvatarSize - newAvatarSize)`
mAvatarPoint[1] = avatarPoint[1] - mAvatarImageView.getTranslationY() -
(expandAvatarSize - newAvatarSize) / 2f;
(expandAvatarSize - newAvatarSize);

int[] spacePoint = new int[2];
mSpace.getLocationOnScreen(spacePoint);
Expand All @@ -196,26 +198,26 @@ private void resetPoints() {
mToolbarTextPoint[0] = toolbarTextPoint[0];
mToolbarTextPoint[1] = toolbarTextPoint[1];

float newTextSize =
mTitleTextSize - (mTitleTextSize - mToolbarTextView.getTextSize()) * offset;
Paint paint = new Paint();
paint.setTextSize(newTextSize);
Paint paint = new Paint(mTitleTextView.getPaint());
float newTextWidth = Utils.getTextWidth(paint, mTitleTextView.getText().toString());
paint.setTextSize(mTitleTextSize);
float originTextWidth = Utils.getTextWidth(paint, mTitleTextView.getText().toString());
int[] titleTextViewPoint = new int[2];
mTitleTextView.getLocationOnScreen(titleTextViewPoint);
mTitleTextViewPoint[0] = titleTextViewPoint[0] - mTitleTextView.getTranslationX() -
(originTextWidth - newTextWidth) / 2f;
(mToolbarTextView.getWidth() > newTextWidth ?
(originTextWidth - newTextWidth) / 2f : 0);
mTitleTextViewPoint[1] = titleTextViewPoint[1] - mTitleTextView.getTranslationY();

new Handler().post(new Runnable() {
if (isTextChanged) {
new Handler().post(new Runnable() {

@Override
public void run() {
translationView(offset);
}
});
@Override
public void run() {
translationView(offset);
}
});
}
}

@Override
Expand All @@ -224,7 +226,7 @@ public void onWindowFocusChanged(boolean hasFocus) {
if (!hasFocus) {
return;
}
resetPoints();
resetPoints(false);
}

private class Adapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
Expand Down
34 changes: 19 additions & 15 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -56,25 +56,31 @@
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipChildren="false"
android:clipToPadding="false"
android:paddingEnd="48dp"
android:paddingStart="48dp"
app:layout_collapseMode="parallax"
app:layout_collapseParallaxMultiplier="1">

<TextView
android:id="@+id/textView_title_shadow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
android:layout_marginTop="2dp"
android:textSize="24sp"
android:visibility="invisible"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/space_avatar"/>
app:layout_constraintTop_toBottomOf="@+id/guideline"/>

<TextView
android:id="@+id/textView_title"
android:layout_width="wrap_content"
android:layout_height="?attr/actionBarSize"
android:gravity="center"
android:ellipsize="end"
android:gravity="center_vertical"
android:maxLines="1"
android:text="HearSilent"
android:textColor="#FFF"
android:textSize="24sp"
Expand All @@ -83,25 +89,23 @@
app:layout_constraintStart_toStartOf="@+id/textView_title_shadow"
app:layout_constraintTop_toTopOf="@+id/textView_title_shadow"/>

<android.support.constraint.Guideline
android:id="@+id/guideline"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_percent="0.6"/>

<de.hdodenhof.circleimageview.CircleImageView
android:id="@+id/imageView_avatar"
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_marginBottom="2dp"
android:background="@drawable/avatar_background"
android:padding="1dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"/>

<Space
android:id="@+id/space_avatar"
android:layout_width="80dp"
android:layout_height="80dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintBottom_toTopOf="@+id/guideline"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
app:layout_constraintStart_toStartOf="parent"/>
</android.support.constraint.ConstraintLayout>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
Expand Down
Binary file removed screenshots/device-2018-06-12-173327.png
Binary file not shown.
Binary file removed screenshots/device-2018-06-12-173349.png
Binary file not shown.
Binary file added screenshots/device-2018-06-12-230517.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added screenshots/device-2018-06-12-230536.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified screenshots/screenrecord.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 8518db9

Please sign in to comment.