Skip to content
This repository has been archived by the owner on Aug 7, 2024. It is now read-only.

22 home work #20

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ android {

defaultConfig {
applicationId "com.github.krottv.tmstemp"
minSdk 24
minSdk 23
targetSdk 31
versionCode 1
versionName "1.0"
Expand All @@ -29,10 +29,14 @@ android {
kotlinOptions {
jvmTarget = '1.8'
}
buildFeatures {
viewBinding true
}
}

dependencies {

implementation "io.coil-kt:coil:2.0.0-rc02"
implementation 'androidx.core:core-ktx:1.7.0'
implementation 'androidx.appcompat:appcompat:1.4.1'
implementation 'com.google.android.material:material:1.5.0'
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.github.krottv.tmstemp">
<uses-permission android:name="android.permission.INTERNET"/>

<application
android:allowBackup="true"
Expand All @@ -10,7 +11,7 @@
android:supportsRtl="true"
android:theme="@style/Theme.TmsTemp">
<activity
android:name=".MainActivity"
android:name=".view.MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
Expand Down
11 changes: 0 additions & 11 deletions app/src/main/java/com/github/krottv/tmstemp/MainActivity.kt

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
package com.github.krottv.tmstemp.animation

import android.animation.ObjectAnimator
import android.animation.PropertyValuesHolder
import android.animation.ValueAnimator
import android.annotation.SuppressLint
import android.app.Activity
import android.view.View
import android.view.animation.AccelerateInterpolator
import android.view.animation.LinearInterpolator
import android.widget.ImageView
import android.widget.TextView
import androidx.constraintlayout.helper.widget.Layer
import androidx.transition.*
import coil.load
import com.github.krottv.tmstemp.R
import com.github.krottv.tmstemp.databinding.ActivityStartBinding


class MainTransitionController(
private val activity: Activity,
private val binding: ActivityStartBinding
) {

private var transitionStep: TransitionStep = TransitionStep.EMPTY

enum class TransitionStep {
EMPTY, FIRST, SECOND
}

private val customTransition = TransitionSet().apply {
addTransition(ChangeBounds())
addTransition(Fade(Fade.IN))
}

fun performTransition(): Unit = when (transitionStep) {
TransitionStep.EMPTY -> {
transitionToFirst()
}
TransitionStep.FIRST -> {
transitionToSecond()
}
TransitionStep.SECOND -> {
transitionToFirst()
}
}

@SuppressLint("CutPasteId")
private fun transitionToFirst() {
transitionStep = TransitionStep.FIRST

val scene = Scene.getSceneForLayout(binding.sceneRoot, R.layout.activity_first, activity)

scene.setEnterAction {

scene.sceneRoot.findViewById<ImageView>(R.id.imageViewFirst)
.load("https://images.unsplash.com/photo-1568127861543-b0c0696c735f?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=470&q=80")
scene.sceneRoot.findViewById<ImageView>(R.id.imageViewSecond)
.load("https://images.unsplash.com/photo-1563452965085-2e77e5bf2607?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=470&q=80")
scene.sceneRoot.findViewById<ImageView>(R.id.imageViewThird)
.load("https://images.unsplash.com/photo-1575439047055-83e6174df3b9?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=470&q=80")

val valueAnimator = ValueAnimator().apply {
duration = 1000
repeatCount = ObjectAnimator.INFINITE
repeatMode = ObjectAnimator.REVERSE
interpolator = LinearInterpolator()
setFloatValues(1f, 1.05f)
}

valueAnimator.addUpdateListener {
val value = it.animatedValue as Float
scene.sceneRoot.findViewById<Layer>(R.id.layerFirst).scaleX = value
scene.sceneRoot.findViewById<Layer>(R.id.layerFirst).scaleY = value
}

valueAnimator.start()

fadeAnimation(
scene.sceneRoot.findViewById<ImageView>(R.id.imageViewThird),
scene.sceneRoot.findViewById<ImageView>(R.id.textViewThird),
scene.sceneRoot.findViewById<ImageView>(R.id.textViewThirdPoint)
)

scene.sceneRoot.findViewById<Layer>(R.id.layerSecond).setOnClickListener {
valueAnimator.end()
performTransition()
}
}
TransitionManager.go(scene, customTransition)
}

private fun transitionToSecond() {
transitionStep = TransitionStep.SECOND

val scene = Scene.getSceneForLayout(binding.sceneRoot, R.layout.activity_second, activity)


scene.setEnterAction {

scene.sceneRoot.findViewById<ImageView>(R.id.imageViewSecondBig)
.load("https://images.unsplash.com/photo-1563452965085-2e77e5bf2607?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=470&q=80")
scene.sceneRoot.findViewById<ImageView>(R.id.imageClose).load(R.drawable.ic_close)

ObjectAnimator().apply {
target = scene.sceneRoot.findViewById<ImageView>(R.id.imageClose)
duration = 2000
repeatCount = ObjectAnimator.INFINITE
interpolator = LinearInterpolator()
setValues(PropertyValuesHolder.ofFloat("rotation", 0f, 360f))
start()
}

scene.sceneRoot.findViewById<ImageView>(R.id.imageClose).setOnClickListener {
performTransition()
}
scene.sceneRoot.findViewById<TextView>(R.id.textViewClose).setOnClickListener {
performTransition()
}
}

TransitionManager.go(scene, customTransition)
}

private fun fadeAnimation(vararg views: View) {

for (view in views) {
ObjectAnimator().apply {
target = view
duration = 1500
repeatCount = ObjectAnimator.INFINITE
repeatMode = ObjectAnimator.REVERSE
interpolator = AccelerateInterpolator()
setValues(PropertyValuesHolder.ofFloat("alpha", 0f, 1f))
start()
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.github.krottv.tmstemp.binder

interface MainActivityDataBinder {
fun bind()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.github.krottv.tmstemp.binder

import android.app.Activity
import android.view.LayoutInflater
import com.github.krottv.tmstemp.animation.MainTransitionController
import com.github.krottv.tmstemp.databinding.ActivityStartBinding

class MainActivitySceneDataBinder(private val activity: Activity): MainActivityDataBinder {
override fun bind() {

val startLayout = ActivityStartBinding.inflate(LayoutInflater.from(activity))
activity.setContentView(startLayout.root)

val transitionController = MainTransitionController(activity, startLayout)
transitionController.performTransition()
}
}
16 changes: 16 additions & 0 deletions app/src/main/java/com/github/krottv/tmstemp/view/MainActivity.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.github.krottv.tmstemp.view

import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import com.github.krottv.tmstemp.binder.MainActivityDataBinder
import com.github.krottv.tmstemp.binder.MainActivitySceneDataBinder

class MainActivity : AppCompatActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

val mainActivityDataBinder: MainActivityDataBinder = MainActivitySceneDataBinder(this)
mainActivityDataBinder.bind()
}
}
18 changes: 18 additions & 0 deletions app/src/main/res/drawable/ic_close.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="16dp"
android:height="16dp"
android:viewportWidth="16"
android:viewportHeight="16">
<path
android:pathData="M14,14L2,2"
android:strokeWidth="3"
android:fillColor="#00000000"
android:strokeColor="#000000"
android:strokeLineCap="round"/>
<path
android:pathData="M14,2L2,14"
android:strokeWidth="3"
android:fillColor="#00000000"
android:strokeColor="#000000"
android:strokeLineCap="round"/>
</vector>
Loading