Skip to content

Commit

Permalink
add animate to material button
Browse files Browse the repository at this point in the history
  • Loading branch information
mateuszKataMobitouch authored and skustra committed Feb 23, 2023
1 parent 2ad4b28 commit 6f388ab
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat

continueButton = view.findViewById(R.id.welcome_continue_button);
continueButton.setOnClickListener(this::continueClicked);
continueButton.setupAnimation();

Button restoreFromBackup = view.findViewById(R.id.welcome_transfer_or_restore);
restoreFromBackup.setOnClickListener(this::restoreFromBackupClicked);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,13 @@ class CircularProgressMaterialButton @JvmOverloads constructor(
val label = getString(R.styleable.CircularProgressMaterialButton_circularProgressMaterialButton__label)

materialButton.text = label
materialButton.onFocusTextChangeListener()
}
}

fun setupAnimation(){
materialButton.onFocusTextChangeListener()
}

fun setText(@StringRes resId: Int) {
materialButton.setText(resId)
}
Expand Down
37 changes: 29 additions & 8 deletions app/src/main/java/pigeon/extensions/KotilinExtensions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,37 @@ package pigeon.extensions

import android.view.View
import android.widget.TextView
import org.thoughtcrime.securesms.BuildConfig
import androidx.core.view.ViewCompat


fun TextView.onFocusTextChangeListener() {
val focus = View.OnFocusChangeListener { _, hasFocus ->
val textSize = if (hasFocus) {
36f
} else {
24f

if (!isSignalVersion()) {
val BUTTON_SCALE_FOCUS = 1.3f
val BUTTON_SCALE_NON_FOCUS = 1.0f
val BUTTON_TRANSLATION_X_FOCUS = 12.0f
val BUTTON_TRANSLATION_X_NON_FOCUS = 1.0f

val focus = View.OnFocusChangeListener { _, hasFocus ->
val scale: Float = if (hasFocus) {
BUTTON_SCALE_FOCUS
} else {
BUTTON_SCALE_NON_FOCUS
}

val translationX: Float = if (hasFocus) {
BUTTON_TRANSLATION_X_FOCUS
} else {
BUTTON_TRANSLATION_X_NON_FOCUS
}

ViewCompat.animate(this)
.scaleX(scale)
.scaleY(scale)
.translationX(translationX)
.start()

}
this.textSize = textSize
this.onFocusChangeListener = focus
}
this.onFocusChangeListener = focus
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
android:id="@+id/button"
style="@style/Mp02.Signal.Text.MaterialTextButton"
android:layout_width="match_parent"
android:layout_marginStart="@dimen/pigeon_start_margin"
android:layout_height="wrap_content"
tools:text="Material Button"
tools:textColor="@color/focused_text_color"
Expand Down
14 changes: 8 additions & 6 deletions app/src/main/res/layout-small/fragment_registration_welcome.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
android:layout_marginStart="@dimen/pigeon_normal_margin"
android:layout_marginTop="@dimen/pigeon_normal_margin"
android:gravity="center"
android:visibility="gone"
android:text="@string/RegistrationActivity_take_privacy_with_you_be_yourself_in_every_message"
android:textColor="@color/white_not_focus"
app:layout_constraintStart_toStartOf="@+id/welcome_continue_button"
Expand All @@ -39,21 +40,22 @@
style="@style/Mp02.Signal.Text.CommonTextButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/pigeon_normal_margin"
android:ellipsize="end"
android:gravity="center"
android:gravity="start"
android:layout_marginStart="@dimen/pigeon_start_margin"
android:layout_marginTop="@dimen/pigeon_top_margin"
android:text="@string/RegistrationActivity_terms_and_privacy"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/title" />
app:layout_constraintTop_toTopOf="parent" />

<org.thoughtcrime.securesms.util.views.CircularProgressMaterialButton
android:id="@+id/welcome_continue_button"
android:layout_width="wrap_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/pigeon_small_margin"
app:circularProgressMaterialButton__label="@string/RegistrationActivity_continue"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/welcome_terms_button"
app:layout_goneMarginBottom="@dimen/registration_button_bottom_margin" />
app:layout_constraintTop_toBottomOf="@+id/welcome_terms_button" />

<com.google.android.material.button.MaterialButton
android:id="@+id/welcome_transfer_or_restore"
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values/dimens.xml
Original file line number Diff line number Diff line change
Expand Up @@ -223,4 +223,6 @@
<dimen name="pigeon_big_margin">40dp</dimen>
<dimen name="pigeon_normal_margin">25dp</dimen>
<dimen name="pigeon_small_margin">5dp</dimen>
<dimen name="pigeon_top_margin">64dp</dimen>
<dimen name="pigeon_start_margin">30dp</dimen>
</resources>

0 comments on commit 6f388ab

Please sign in to comment.