hitherejoe / animate Goto Github PK
View Code? Open in Web Editor NEWAn application demoing meaningful motion on Android
Home Page: https://medium.com/ribot-labs/exploring-meaningful-motion-on-android-1cd95a4bc61d
An application demoing meaningful motion on Android
Home Page: https://medium.com/ribot-labs/exploring-meaningful-motion-on-android-1cd95a4bc61d
Hi there, I was reviewing the code, it's awesome. I think it would be better if some parts are changed for better readability and future extensions. They are mentioned below.
I've seen two very big methods, setupSharedElementTransitionsFab() and setupSharedElementTransitionsButton(). And I think these ones would be refactored into creating a new abstract class with some common methods, with a new interface for setting up transitions. I think it would be better explained in the UML class diagram presented below.
And I also share the code snippets proposals I had reffered to,
app/src/main/java/com/hitherejoe/animate/ui/activity/SharedElementTransition.java
package com.hitherejoe.animate.ui.activity;
public abstract class SharedElementTransition implements ShareableElementTransition{
protected ArcMotion arcMotion;
protected Interpolator easeInOut;
protected int color;
protected ChangeBounds sharedEnter;
protected ChangeBounds sharedReturn;
public SharedElementTransition() {
setUpArcMotion();
setUpInterpolator();
setUpColor();
}
void setUpArcMotion(){
arcMotion = new ArcMotion();
arcMotion.setMinimumHorizontalAngle(50f);
arcMotion.setMinimumVerticalAngle(50f);
}
void setUpInterpolator() {
easeInOut =
AnimationUtils.loadInterpolator(activity, android.R.interpolator.fast_out_slow_in);
}
void setUpColor() {
color = ContextCompat.getColor(activity, R.color.accent);
}
@Override
public void setupSharedElementTransitions(Activity activity, View target) {
setUpMorphToDialog();
setUpMorphFromDialog();
if (target != null) {
sharedEnter.addTarget(target);
sharedReturn.addTarget(target);
}
activity.getWindow().setSharedElementEnterTransition(sharedEnter);
activity.getWindow().setSharedElementReturnTransition(sharedReturn);
}
abstract void setUpMorphToDialog();
abstract void setUpMorphFromDialog();
}
app/src/main/java/com/hitherejoe/animate/ui/activity/ShareableElementTransition.java
package com.hitherejoe.animate.ui.activity;
public interface ShareableElementTransition {
void setupSharedElementTransitions(Activity activity, View target);
}
app/src/main/java/com/hitherejoe/animate/ui/activity/ButtonSharedElementTransition.java
package com.hitherejoe.animate.ui.activity;
import com.hitherejoe.animate.util.MorphButtonToDialog;
import com.hitherejoe.animate.util.MorphDialogToButton;
public class ButtonSharedElementTransition
extends SharedElementTransition {
@Override
void setUpMorphToDialog() {
super.sharedEnter = new MorphButtonToDialog(super.color);
super.sharedEnter.setPathMotion(arcMotion);
super.sharedEnter.setInterpolator(easeInOut);
}
@Override
void setUpMorphFromDialog() {
super.sharedReturn = new MorphDialogToButton(color);
super.sharedReturn.setPathMotion(arcMotion);
super.sharedReturn.setInterpolator(easeInOut);
}
}
app/src/main/java/com/hitherejoe/animate/ui/activity/FabSharedElementTransition.java
package com.hitherejoe.animate.ui.activity;
import com.hitherejoe.animate.util.MorphDialogToFab;
import com.hitherejoe.animate.util.MorphFabToDialog;
public class FabSharedElementTransition
extends SharedElementTransition {
private int dialogCornerRadius;
public FabSharedElementTransition(int dialogCornerRadius) {
this.dialogCornerRadius = dialogCornerRadius;
}
@Override
void setUpMorphToDialog() {
sharedEnter = new MorphFabToDialog(color, dialogCornerRadius);
sharedEnter.setPathMotion(arcMotion);
sharedEnter.setInterpolator(easeInOut);
}
@Override
void setUpMorphFromDialog() {
sharedReturn = new MorphDialogToFab(color);
sharedReturn.setPathMotion(arcMotion);
sharedReturn.setInterpolator(easeInOut);
}
}
app/src/main/java/com/hitherejoe/animate/ui/activity/PopupActivity.java
package com.hitherejoe.animate.ui.activity;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
public class PopupActivity extends Activity {
boolean isDismissing = false;
public static final String EXTRA_MORPH_TYPE = "morph_type";
public static final String MORPH_TYPE_BUTTON = "morph_type_button";
public static final String MORPH_TYPE_FAB = "morph_type_fab";
public static Intent getStartIntent(Context context, String type) {
Intent intent = new Intent(context, PopupActivity.class);
intent.putExtra(EXTRA_MORPH_TYPE, type);
return intent;
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_popup);
String type = getIntent().getStringExtra(EXTRA_MORPH_TYPE);
ShareableElementTransition transition = createTransitionForType(type);
if (transition != null) {
View container = (ViewGroup) findViewById(R.id.container);
transition.setupSharedElementTransitions(this, container);
}
}
private ShareableElementTransition createTransitionForType(String type) {
if (type.equals(MORPH_TYPE_BUTTON)) {
return new ButtonSharedElementTransition();
} else if (type.equals(MORPH_TYPE_FAB)) {
return new FabSharedElementTransition(
getResources().getDimensionPixelSize(R.dimen.dialog_corners));
}
return null;
}
@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
}
public void dismiss(View view) {
isDismissing = true;
setResult(Activity.RESULT_CANCELED);
finishAfterTransition();
}
@Override
public void onBackPressed() {
dismiss(null);
}
}
Note: At this moment, I did not considered to make a pull request for android dependecies I hadn't put enough effort to link with the code, but even with that I had written based on the code project. Have a nice day!
Good day, I am a graphic designer and i have a design here that fits on your project. Just reply on this issue if you want the design.
Crashes on Window Content -> Slide right
Sugerencia 1:
Encontre una manera de mejorar la clase MorphTransitionsActivity para que cumpla con el Principio de Sustitución de Liskov (LSP)
En esta clase se inicia PopupActivity y especificaría un tipo de "morph" como argumento. Esto podría violar el Principio de Sustitución de Liskov (LSP) si PopupActivity no pudiera funcionar consistentemente con cualquier tipo de "morph." Las subclases deberían poder sustituirse sin afectar el comportamiento general de la aplicación.
Para resolver el problema y cumplir con el Principio de Sustitución de Liskov (LSP), podemos generalizar la creación de Intent y dejar que PopupActivity determine el tipo de "morph" necesario. Esto permitirá que PopupActivity funcione de manera coherente con cualquier tipo de "morph."
Sugerencia 2:
Se puede mejorar la clase InterpolatorActivity para que cumpla con el principio ISP
Para abordar el problema de la violación del ISP y mejorar la organización del código, se puede dividir las responsabilidades en interfaces y clases separadas. En este caso, se puede crear una interfaz para la gestión de animaciones y una clase separada para la selección de interpoladores.
Sugerencia 3:
Se puede mejorar la clase AnimatedVectorDrawablesActivity para que cumpla con el principio ISP
En la solución, se puede divididir las responsabilidades de la clase AnimatedVectorDrawablesActivity y la gestión de eventos de clic y animaciones en la clase AnimationManager. La interfaz ImageClickListener se utiliza para notificar la actividad sobre los eventos de clic en las imágenes. Esto mejora la organización del código y sigue el principio de segregación de interfaz (ISP).
Is there a possibility to use these animations with fragments or dialogfragments?
I really enjoyed exploring this library and be amazed on features but unfortunately due to the lack of lower api support, it would be difficult for me to use this on my app.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.