public SpringListenerViewActivity(Context context) : base(context) { mBitmap = BitmapFactory.DecodeResource(Resources, Resource.Drawable.Icon); SpringSystem ss = SpringSystem.Create(); Spring s; for (int i = 0; i < NUM_ELEMS; i++) { s = ss.CreateSpring(); s.SetSpringConfig(new MySpringConfig(200, i == 0 ? 8 : 15 + i * 2, i, true)); s.AddListener(this); mXSprings[i] = s; s = ss.CreateSpring(); s.SetSpringConfig(new MySpringConfig(200, i == 0 ? 8 : 15 + i * 2, i, false)); s.AddListener(this); mYSprings[i] = s; } }
private static void createCircle(Context context, ViewGroup rootView, SpringSystem springSystem, SpringConfig coasting, SpringConfig gravity, int diameter, Drawable backgroundDrawable) { Spring xSpring = springSystem.CreateSpring().SetSpringConfig(coasting); Spring ySpring = springSystem.CreateSpring().SetSpringConfig(gravity); // create view View view = new View(context); RelativeLayout.LayoutParams paramss = new RelativeLayout.LayoutParams(diameter, diameter); paramss.AddRule(LayoutRules.CenterInParent); view.LayoutParameters = paramss; view.Background = backgroundDrawable; rootView.AddView(view); // generate random direction and magnitude double magnitude = new Random().NextDouble() * 1000 + 3000; double angle = new Random().NextDouble() * System.Math.PI / 2 + System.Math.PI / 4; xSpring.SetVelocity(magnitude * System.Math.Cos(angle)); ySpring.SetVelocity(-magnitude * System.Math.Sin(angle)); int maxX = rootView.MeasuredWidth / 2 + diameter; xSpring.AddListener(new Destroyer(rootView, view, -maxX, maxX)); int maxY = rootView.MeasuredHeight / 2 + diameter; ySpring.AddListener(new Destroyer(rootView, view, -maxY, maxY)); xSpring.AddListener(new Performer(view, ViewHelper.TranslationX)); ySpring.AddListener(new Performer(view, ViewHelper.TranslationY)); // set a different end value to cause the animation to play xSpring.SetEndValue(2); ySpring.SetEndValue(9001); }
public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.Inflate(Resource.Layout.fragment_scale, container, false); View rect = rootView.FindViewById(Resource.Id.rect); SpringSystem springSystem = SpringSystem.Create(); Spring spring = springSystem.CreateSpring(); spring.AddListener(new Performer(rect, View.ScaleXs)); spring.AddListener(new Performer(rect, View.ScaleYs)); rootView.Touch += (sender, e) => { switch (e.Event.Action) { case MotionEventActions.Down: spring.SetVelocity(0); goto case MotionEventActions.Move; //break; case MotionEventActions.Move: // can't use Imitation here because there is no nice mapping from // an event property to a Spring float scaleX, scaleY; float delta = e.Event.GetX() - (rect.GetX() + rect.MeasuredWidth / 2); scaleX = Math.Abs(delta) / (rect.MeasuredWidth / 2); delta = e.Event.GetY() - (rect.GetY() + rect.MeasuredHeight / 2); scaleY = Math.Abs(delta) / (rect.MeasuredHeight / 2); float scale = Math.Max(scaleX, scaleY); spring.SetEndValue(scale); break; case MotionEventActions.Up: spring.SetEndValue(1f); break; } e.Handled = true; //return true; }; return(rootView); }
public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Use this to return your custom view for this Fragment // return inflater.Inflate(Resource.Layout.YourFragment, container, false); //return base.OnCreateView(inflater, container, savedInstanceState); View rootView = inflater.Inflate(Resource.Layout.origami_example, container, false); mPhotoGrid = rootView.FindViewById <View>(Resource.Id.grid); mSelectedPhoto = rootView.FindViewById <View>(Resource.Id.selection); mFeedbackBar = rootView.FindViewById <View>(Resource.Id.feedback); SpringSystem springSystem = SpringSystem.Create(); mSpring = springSystem.CreateSpring().SetSpringConfig(ORIGAMI_SPRING_CONFIG); mSpring.AddListener(new MapPerformer(mSelectedPhoto, View.ScaleXs, 0f, 1f, 0.33f, 1)); mSpring.AddListener(new MapPerformer(mSelectedPhoto, View.ScaleYs, 0f, 1f, 0.33f, 1)); mSpring.AddListener(new MapPerformer(mSelectedPhoto, ViewHelper.TranslationX, 0, 1, Util.DpToPx(-106.667f, Resources), 0)); mSpring.AddListener(new MapPerformer(mSelectedPhoto, ViewHelper.TranslationY, 0, 1, Util.DpToPx(46.667f, Resources), 0)); mSpring.AddListener(new MapPerformer(mPhotoGrid, ViewHelper.Alpha, 0, 1, 1, 0)); mSpring.AddListener(new MapPerformer(mPhotoGrid, View.ScaleXs, 0f, 1f, 1f, 0.95f)); mSpring.AddListener(new MapPerformer(mPhotoGrid, View.ScaleYs, 0f, 1f, 1f, 0.95f)); EventHandler globalHandler = null; globalHandler += (sender, e) => { float barPosition = (float)SpringUtil.MapValueFromRangeToRange(mSpring.CurrentValue, 0, 1, mFeedbackBar.Height, 0); mFeedbackBar.TranslationY = barPosition; mSpring.AddListener(new MapPerformer(mFeedbackBar, ViewHelper.TranslationY, 0, 1, mFeedbackBar.Height, 0)); rootView.ViewTreeObserver.GlobalLayout -= globalHandler; }; rootView.ViewTreeObserver.GlobalLayout += globalHandler; ToggleImitator imitator = new ToggleImitator(mSpring, 0, 1); rootView.SetOnTouchListener(imitator); mSpring.SetCurrentValue(0); return(rootView); }
public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.Inflate(Resource.Layout.fragment_scale, container, false); View rect = rootView.FindViewById(Resource.Id.rect); SpringSystem springSystem = SpringSystem.Create(); Spring spring = springSystem.CreateSpring(); spring.AddListener(new Performer(rect, View.ScaleXs)); spring.AddListener(new Performer(rect, View.ScaleYs)); spring.SetCurrentValue(1.0f); ScaleGestureDetector scaleGestureDetector = new ScaleGestureDetector(this.Activity, new OnScaleGestureListener(spring)); rootView.Touch += (sender, e) => { e.Handled = scaleGestureDetector.OnTouchEvent(e.Event); }; return(rootView); }
public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { mRootView = (RelativeLayout)inflater.Inflate(Resource.Layout.fragment_bloom, container, false); mCircles = new View[6]; float diameter = TypedValue.ApplyDimension(ComplexUnitType.Dip, DIAMETER, Resources.DisplayMetrics); TypedArray circles = Resources.ObtainTypedArray(Resource.Array.circles); // layout params RelativeLayout.LayoutParams paramss = new RelativeLayout.LayoutParams((int)diameter, (int)diameter); paramss.AddRule(LayoutRules.CenterInParent); // create the circle views int colorIndex = 0; for (int i = 0; i < mCircles.Length; i++) { mCircles[i] = new View(Activity); mCircles[i].LayoutParameters = paramss; mCircles[i].SetBackgroundDrawable(Resources.GetDrawable(circles.GetResourceId(colorIndex, -1))); colorIndex++; if (colorIndex >= circles.Length()) { colorIndex = 0; } mRootView.AddView(mCircles[i]); } circles.Recycle(); /* Animations! */ SpringSystem springSystem = SpringSystem.Create(); // create spring 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, ViewHelper.TranslationX, 0, 1, 0, (float)(RING_DIAMETER * Math.Cos(i * arc)))); spring.AddListener(new MapPerformer(view, ViewHelper.TranslationY, 0, 1, 0, (float)(RING_DIAMETER * Math.Sin(i * arc)))); spring.SetEndValue(CLOSED); } mRootView.SetOnTouchListener(new ToggleImitator(spring, CLOSED, OPEN)); return(mRootView); }
public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Use this to return your custom view for this Fragment // return inflater.Inflate(Resource.Layout.YourFragment, container, false); mRootView = (ViewGroup)inflater.Inflate(Resource.Layout.fragment_follow, container, false); mCircle = mRootView.FindViewById(Resource.Id.circle); FrameLayout.LayoutParams leaderParams = (FrameLayout.LayoutParams)mCircle.LayoutParameters; mFollowers = new View[4]; float diameter = TypedValue.ApplyDimension(ComplexUnitType.Dip, DIAMETER, Resources.DisplayMetrics); Android.Content.Res.TypedArray circles = Resources.ObtainTypedArray(Resource.Array.circles); // create the circle views int colorIndex = 1; for (int i = 0; i < mFollowers.Length; i++) { mFollowers[i] = new View(this.Activity); FrameLayout.LayoutParams par = new FrameLayout.LayoutParams((int)diameter, (int)diameter); par.Gravity = leaderParams.Gravity; mFollowers[i].LayoutParameters = par; mFollowers[i].SetBackgroundDrawable(Resources.GetDrawable(circles.GetResourceId(colorIndex, -1))); colorIndex++; if (colorIndex >= circles.Length()) { colorIndex = 0; } mRootView.AddView(mFollowers[i]); } circles.Recycle(); /* Animation code */ SpringSystem springSystem = SpringSystem.Create(); // create the springs that control movement Spring springX = springSystem.CreateSpring(); Spring springY = springSystem.CreateSpring(); // bind circle movement to events new Actor.Builder(springSystem, mCircle).AddMotion(springX, MotionProperty.X).AddMotion(springY, MotionProperty.Y).Build(); // add springs to connect between the views Spring[] followsX = new Spring[mFollowers.Length]; Spring[] followsY = new Spring[mFollowers.Length]; Random rnd = new Random(); for (int i = 0; i < mFollowers.Length; i++) { // create spring to bind views followsX[i] = springSystem.CreateSpring(); followsY[i] = springSystem.CreateSpring(); //followsX[i] = springSystem.CreateSpring().SetSpringConfig(new SpringConfig(rnd.Next(300), rnd.Next(22))); //followsY[i] = springSystem.CreateSpring().SetSpringConfig(new SpringConfig(rnd.Next(300), rnd.Next(22))); followsX[i].AddListener(new Performer(mFollowers[i], ViewHelper.TranslationX)); followsY[i].AddListener(new Performer(mFollowers[i], ViewHelper.TranslationY)); // imitates another character SpringImitator followX = new SpringImitator(followsX[i]); SpringImitator followY = new SpringImitator(followsY[i]); // imitate the previous character if (i == 0) { springX.AddListener(followX); springY.AddListener(followY); } else { followsX[i - 1].AddListener(followX); followsY[i - 1].AddListener(followY); } } return(mRootView); }
private SpringConfig SPRING_CONFIG;//= SpringConfig.FromOrigamiTensionAndFriction(40, 3); protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); // Set our view from the "main" layout resource SetContentView(Resource.Layout.Main); // Get our button from the layout resource, // and attach an event to it EditText tension = FindViewById <EditText>(Resource.Id.editTextTension); EditText friction = FindViewById <EditText>(Resource.Id.editTextFriction); //Spring Dynamics SpringSystem _springSystem = SpringSystem.Create(); //Click Button button = FindViewById <Button>(Resource.Id.MyButton); Spring _spring = _springSystem.CreateSpring(); _spring.AddListener(new SimpleSpringListener(button, "click")); button.Click += delegate { SPRING_CONFIG = SpringConfig.FromOrigamiTensionAndFriction(100, 12);//Best Values: 100,12 _spring.SetSpringConfig(SPRING_CONFIG); _spring.SetCurrentValue(1); _spring.SetEndValue(0.2); _spring.SetOvershootClampingEnabled(true); }; //Tilt Button buttonTilt = FindViewById <Button>(Resource.Id.buttonTilt); Spring _spring2 = _springSystem.CreateSpring(); _spring2.AddListener(new SimpleSpringListener(buttonTilt, "tilt")); buttonTilt.Click += delegate { SPRING_CONFIG = SpringConfig.FromOrigamiTensionAndFriction(100, 12);//Best Values: 100,12 _spring2.SetSpringConfig(SPRING_CONFIG); _spring2.SetCurrentValue(0); _spring2.SetEndValue(0.2); }; //BounceIn Button buttonBounceIn = FindViewById <Button>(Resource.Id.buttonBounceIn); Spring _spring3 = _springSystem.CreateSpring(); _spring3.AddListener(new SimpleSpringListener(buttonBounceIn, "bouncein")); buttonBounceIn.Click += delegate { SPRING_CONFIG = SpringConfig.FromOrigamiTensionAndFriction(Convert.ToDouble(tension.Text), Convert.ToDouble(friction.Text));//Best Values: 10,2 _spring3.SetSpringConfig(SPRING_CONFIG); _spring3.SetCurrentValue(1); _spring3.SetEndValue(0); }; //BounceOut Button buttonBounceOut = FindViewById <Button>(Resource.Id.buttonBounceOut); Spring _spring4 = _springSystem.CreateSpring(); _spring4.AddListener(new SimpleSpringListener(buttonBounceOut, "bounceout")); buttonBounceOut.Click += delegate { SPRING_CONFIG = SpringConfig.FromOrigamiTensionAndFriction(Convert.ToDouble(tension.Text), Convert.ToDouble(friction.Text));//Best Values: 10,2 _spring4.SetSpringConfig(SPRING_CONFIG); _spring4.SetCurrentValue(0); _spring4.SetEndValue(1); }; //BounceFadeIn Button buttonBounceFadeIn = FindViewById <Button>(Resource.Id.buttonBounceFadeIn); //Spring _spring5 = _springSystem.CreateSpring(); //_spring5.AddListener(new SimpleSpringListener(buttonBounceFadeIn, "bouncefadein")); buttonBounceFadeIn.Click += delegate { //SPRING_CONFIG = SpringConfig.FromOrigamiTensionAndFriction(Convert.ToDouble(tension.Text), Convert.ToDouble(friction.Text));//Best Values: 10,2 //_spring5.SetSpringConfig(SPRING_CONFIG); //_spring5.SetCurrentValue(1); //_spring5.SetEndValue(0); StartActivity(typeof(ChatBubbleActivity)); }; Button buttonReset = FindViewById <Button>(Resource.Id.buttonReset); //buttonReset.Visibility = ViewStates.Gone; buttonReset.Click += (s, e) => { _spring4.SetEndValue(0); _spring4.SetCurrentValue(0); buttonBounceFadeIn.Background.SetAlpha(256); }; //ImageView img = FindViewById<ImageView>(Resource.Id.imageView1); // //Spring _spring6 = _springSystem.CreateSpring(); // // _spring6.AddListener(new SpringListenerViewActivity(this, img)); //img.SetOnDragListener(new SpringListenerViewActivity(this)); }
public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { mRootView = inflater.Inflate(Resource.Layout.fragment_appear, container, false); // grab the circles mCircles = new View[6]; mCircles[0] = mRootView.FindViewById(Resource.Id.circle0); mCircles[1] = mRootView.FindViewById(Resource.Id.circle1); mCircles[2] = mRootView.FindViewById(Resource.Id.circle2); mCircles[3] = mRootView.FindViewById(Resource.Id.circle3); mCircles[4] = mRootView.FindViewById(Resource.Id.circle4); mCircles[5] = mRootView.FindViewById(Resource.Id.circle5); springSystem = SpringSystem.Create(); springs = new Spring[6]; actors = new Actor[6]; // attach listeners for (int i = 0; i < mCircles.Length; i++) { springs[i] = springSystem.CreateSpring(); springs[i].AddListener(new Performer(mCircles[i], ViewHelper.TranslationY)); mCircles[i].Tag = springs[i]; mCircles[i].SetOnClickListener(new CustomClickListener(this)); actors[i] = new Actor.Builder(springSystem, mCircles[i]) .AddTranslateMotion(MotionProperty.X) .AddTranslateMotion(MotionProperty.Y) .Build(); } mRootView.Touch += (sender, e) => { // grab location of root view so we can compensate for it int[] rootLocation = new int[2]; ((View)sender).GetLocationInWindow(rootLocation); int[] location = new int[2]; for (int i = 0; i < mCircles.Length; i++) { if (springs[i].EndValue == 0) { // hide mCircles[i].GetLocationInWindow(location); // if the end values are different, they will move at different speeds springs[i].SetEndValue(mRootView.MeasuredHeight - location[1] + rootLocation[1] + 2 * new Random().Next() * mCircles[i].MeasuredHeight); } else { actors[i].SetTouchEnabled(true); foreach (Actor.Motion motion in actors[i].GetMotions()) { foreach (EventImitator imitator in motion.GetImitators()) { if (imitator is MotionImitator) { MotionImitator motionImitator = (MotionImitator)imitator; imitator.GetSpring().SetCurrentValue(0); // TODO: re-enable the y motion. // if (imitator.getProperty() == MotionProperty.Y && !imitator.getSpring().isRegistered()) { // imitator.getSpring().register(); // } } } } springs[i].SetEndValue(0); // appear } } }; return(mRootView); }
/** * Uses the default {@link com.facebook.rebound.SpringConfig} to animate the view. * * @param properties * the event fields to imitate and the view properties to animate. * @return this builder for chaining */ public Builder AddTranslateMotion(params MotionProperty[] properties) { return(AddMotion(mSpringSystem.CreateSpring(), properties)); }