use of com.tumblr.backboard.imitator.ToggleImitator in project Backboard by tumblr.
the class BloomFragment method onCreateView.
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
mRootView = (RelativeLayout) inflater.inflate(R.layout.fragment_bloom, container, false);
mCircles = new View[6];
float diameter = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, DIAMETER, getResources().getDisplayMetrics());
final TypedArray circles = getResources().obtainTypedArray(R.array.circles);
// layout params
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams((int) diameter, (int) diameter);
params.addRule(RelativeLayout.CENTER_IN_PARENT);
// create the circle views
int colorIndex = 0;
for (int i = 0; i < mCircles.length; i++) {
mCircles[i] = new View(getActivity());
mCircles[i].setLayoutParams(params);
mCircles[i].setBackgroundDrawable(getResources().getDrawable(circles.getResourceId(colorIndex, -1)));
colorIndex++;
if (colorIndex >= circles.length()) {
colorIndex = 0;
}
mRootView.addView(mCircles[i]);
}
circles.recycle();
/* Animations! */
final SpringSystem springSystem = SpringSystem.create();
// create spring
final Spring spring = springSystem.createSpring();
// add listeners along arc
double arc = 2 * Math.PI / mCircles.length;
for (int i = 0; i < mCircles.length; i++) {
View view = mCircles[i];
// map spring to a line segment from the center to the edge of the ring
spring.addListener(new MapPerformer(view, View.TRANSLATION_X, 0, 1, 0, (float) (RING_DIAMETER * Math.cos(i * arc))));
spring.addListener(new MapPerformer(view, View.TRANSLATION_Y, 0, 1, 0, (float) (RING_DIAMETER * Math.sin(i * arc))));
spring.setEndValue(CLOSED);
}
mRootView.setOnTouchListener(new ToggleImitator(spring, CLOSED, OPEN));
return mRootView;
}
use of com.tumblr.backboard.imitator.ToggleImitator in project Backboard by tumblr.
the class FlowerFragment method onCreateView.
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
mRootView = (RelativeLayout) inflater.inflate(R.layout.fragment_flower, container, false);
mCircles = new View[6];
mCircle = mRootView.findViewById(R.id.circle);
final float diameter = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, DIAMETER, getResources().getDisplayMetrics());
final TypedArray circles = getResources().obtainTypedArray(R.array.circles);
// layout params
final RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams((int) diameter, (int) diameter);
params.addRule(RelativeLayout.CENTER_IN_PARENT);
// create the circle views
int colorIndex = 0;
for (int i = 0; i < mCircles.length; i++) {
mCircles[i] = new View(getActivity());
mCircles[i].setLayoutParams(params);
mCircles[i].setBackgroundDrawable(getResources().getDrawable(circles.getResourceId(colorIndex, -1)));
colorIndex++;
if (colorIndex >= circles.length()) {
colorIndex = 0;
}
mRootView.addView(mCircles[i], 0);
}
circles.recycle();
/* Animations! */
final SpringSystem springSystem = SpringSystem.create();
// create spring
final Spring spring = springSystem.createSpring();
// add listeners along arc
final double arc = 2 * Math.PI / mCircles.length;
for (int i = 0; i < mCircles.length; i++) {
View view = mCircles[i];
// map spring to a line segment from the center to the edge of the ring
spring.addListener(new MapPerformer(view, View.TRANSLATION_X, 0, 1, 0, (float) (RING_DIAMETER * Math.cos(i * arc))));
spring.addListener(new MapPerformer(view, View.TRANSLATION_Y, 0, 1, 0, (float) (RING_DIAMETER * Math.sin(i * arc))));
spring.setEndValue(CLOSED);
}
final ToggleImitator imitator = new ToggleImitator(spring, CLOSED, OPEN);
// move circle using finger, snap when near another circle, and bloom when touched
new Actor.Builder(SpringSystem.create(), mCircle).addMotion(new SnapImitator(MotionProperty.X), View.TRANSLATION_X).addMotion(new SnapImitator(MotionProperty.Y), View.TRANSLATION_Y).onTouchListener(imitator).build();
return mRootView;
}
use of com.tumblr.backboard.imitator.ToggleImitator in project Backboard by tumblr.
the class PressFragment method onCreateView.
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
final View rootView = inflater.inflate(R.layout.fragment_press, container, false);
new Actor.Builder(SpringSystem.create(), rootView.findViewById(R.id.circle)).addMotion(new ToggleImitator(null, 1.0, 0.5), View.SCALE_X, View.SCALE_Y).build();
return rootView;
}
Aggregations