/** * Sets the {@link com.facebook.rebound.Spring} that this imitator should use. This class * attaches itself as a {@link com.facebook.rebound.SpringListener} and stores the * {@link com.facebook.rebound.SpringConfig} to use when the user is dragging. * * @param spring * the spring to use */ public override void SetSpring(Spring spring) { base.SetSpring(spring); spring.AddListener(this); mOriginalConfig = spring.SpringConfig; }
private SpringChain( int mainTension, int mainFriction, int attachmentTension, int attachmentFriction) { mMainSpringConfig = SpringConfig.fromOrigamiTensionAndFriction(mainTension, mainFriction); mAttachmentSpringConfig = SpringConfig.fromOrigamiTensionAndFriction(attachmentTension, attachmentFriction); registry.addSpringConfig(mMainSpringConfig, "main spring " + id++); registry.addSpringConfig(mAttachmentSpringConfig, "attachment spring " + id++); }
/** * update the position of the seekbars based on the spring value; * @param springConfig current editing spring */ private void updateSeekBarsForSpringConfig(SpringConfig springConfig) { float tension = (float)OrigamiValueConverter.origamiValueFromTension(springConfig.tension); float tensionRange = MAX_TENSION - MIN_TENSION; int scaledTension = Java.Lang.Math.Round(((tension - MIN_TENSION) * MAX_SEEKBAR_VAL) / tensionRange); float friction = (float)OrigamiValueConverter.origamiValueFromFriction(springConfig.friction); float frictionRange = MAX_FRICTION - MIN_FRICTION; int scaledFriction = Java.Lang.Math.Round(((friction - MIN_FRICTION) * MAX_SEEKBAR_VAL) / frictionRange); mTensionSeekBar.Progress = scaledTension; mFrictionSeekBar.Progress = scaledFriction; }
public override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); mHandler = new Handler(); mSpringSystem = SpringSystem.Create(); mCoasting = SpringConfig.FromOrigamiTensionAndFriction(0, 0); mCoasting.Tension = 0; // this is very much a hack, since the end value is set to 9001 to simulate constant // acceleration. mGravity = SpringConfig.FromOrigamiTensionAndFriction(0, 0); mGravity.Tension = 1; // Create your fragment here }
public static void makeText(Context context, string msg, ToastLength length, int type) { Toast toast = new Toast(context); View layout; TextView text; switch (type) { case 1: layout = LayoutInflater.From(context).Inflate(Resource.Layout.success_toast_layout, null, false); text = (TextView)layout.FindViewById(Resource.Id.toastMessage); text.Text = msg; successToastView = (SuccessToastView)layout.FindViewById(Resource.Id.successView); successToastView.startAnim(); text.SetBackgroundResource(Resource.Drawable.success_toast); text.SetTextColor(Color.ParseColor("#FFFFFF")); toast.View = layout; break; case 2: layout = LayoutInflater.From(context).Inflate(Resource.Layout.warning_toast_layout, null, false); text = (TextView)layout.FindViewById(Resource.Id.toastMessage); text.Text = msg; warningToastView = (WarningToastView)layout.FindViewById(Resource.Id.warningView); SpringSystem springSystem = SpringSystem.create(); Spring spring = springSystem.createSpring(); spring.setCurrentValue(1.8); SpringConfig config = new SpringConfig(40, 5); spring.setSpringConfig(config); spring.addListener(new SimpleSpringListener() { SpringUpdate = (_spring) => { float value = (float)_spring.getCurrentValue(); float scale = (float)(0.9f - (value * 0.5f)); warningToastView.ScaleX = scale; warningToastView.ScaleY = scale; } }); Thread t = new Thread(new Runnable(() => { try { Thread.Sleep(500); } catch (InterruptedException e) { } spring.setEndValue(0.4f); })); t.Start(); text.SetBackgroundResource(Resource.Drawable.warning_toast); text.SetTextColor(Color.ParseColor("#FFFFFF")); toast.View = layout; break; case 3: layout = LayoutInflater.From(context).Inflate(Resource.Layout.error_toast_layout, null, false); text = (TextView)layout.FindViewById(Resource.Id.toastMessage); text.Text = msg; errorToastView = (ErrorToastView)layout.FindViewById(Resource.Id.errorView); errorToastView.startAnim(); text.SetBackgroundResource(Resource.Drawable.error_toast); text.SetTextColor(Color.ParseColor("#FFFFFF")); toast.View = layout; break; case 4: layout = LayoutInflater.From(context).Inflate(Resource.Layout.info_toast_layout, null, false); text = (TextView)layout.FindViewById(Resource.Id.toastMessage); text.Text = msg; infoToastView = (InfoToastView)layout.FindViewById(Resource.Id.infoView); infoToastView.startAnim(); text.SetBackgroundResource(Resource.Drawable.info_toast); text.SetTextColor(Color.ParseColor("#FFFFFF")); toast.View = layout; break; case 5: layout = LayoutInflater.From(context).Inflate(Resource.Layout.default_toast_layout, null, false); text = (TextView)layout.FindViewById(Resource.Id.toastMessage); text.Text = msg; defaultToastView = (DefaultToastView)layout.FindViewById(Resource.Id.defaultView); defaultToastView.startAnim(); text.SetBackgroundResource(Resource.Drawable.default_toast); text.SetTextColor(Color.ParseColor("#FFFFFF")); toast.View = layout; break; case 6: layout = LayoutInflater.From(context).Inflate(Resource.Layout.confusing_toast_layout, null, false); text = (TextView)layout.FindViewById(Resource.Id.toastMessage); text.Text = msg; confusingToastView = (ConfusingToastView)layout.FindViewById(Resource.Id.confusingView); confusingToastView.startAnim(); text.SetBackgroundResource(Resource.Drawable.confusing_toast); text.SetTextColor(Color.ParseColor("#FFFFFF")); toast.View = layout; break; } toast.Duration = length; toast.Show(); }
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)); }
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); }
// @TargetApi(Build.VERSION_CODES.HONEYCOMB) public SpringConfiguratorView(Context context, IAttributeSet attrs, int defStyle) : base(context, attrs, defStyle) { SpringSystem springSystem = SpringSystem.create(); springConfigRegistry = SpringConfigRegistry.getInstance(); spinnerAdapter = new SpinnerAdapter(context); Resources resources = this.Resources; mRevealPx = Util.dpToPx(40, resources); mStashPx = Util.dpToPx(280, resources); mRevealerSpring = springSystem.createSpring(); mRevealerSpring .setCurrentValue(1) .setEndValue(1) .addListener(new SimpleSpringListener() { SpringUpdate = (spring) => { float val = (float)spring.getCurrentValue(); float minTranslate = mRevealPx; float maxTranslate = mStashPx; float range = maxTranslate - minTranslate; float yTranslate = (val * range) + minTranslate; this.TranslationY = yTranslate; } }); AddView(generateHierarchy(context)); SeekbarListener seekbarListener = new SeekbarListener() { ProgressChanged = (seekBar, val, b) => { float tensionRange = MAX_TENSION - MIN_TENSION; float frictionRange = MAX_FRICTION - MIN_FRICTION; if (seekBar == mTensionSeekBar) { float scaledTension = ((val) * tensionRange) / MAX_SEEKBAR_VAL + MIN_TENSION; mSelectedSpringConfig.tension = OrigamiValueConverter.tensionFromOrigamiValue(scaledTension); string roundedTensionLabel = DECIMAL_FORMAT.Format(scaledTension); mTensionLabel.Text = "T:" + roundedTensionLabel; } if (seekBar == mFrictionSeekBar) { float scaledFriction = ((val) * frictionRange) / MAX_SEEKBAR_VAL + MIN_FRICTION; mSelectedSpringConfig.friction = OrigamiValueConverter.frictionFromOrigamiValue(scaledFriction); string roundedFrictionLabel = DECIMAL_FORMAT.Format(scaledFriction); mFrictionLabel.Text = "F:" + roundedFrictionLabel; } } }; mTensionSeekBar.Max = MAX_SEEKBAR_VAL; mTensionSeekBar.SetOnSeekBarChangeListener(seekbarListener); mFrictionSeekBar.Max = MAX_SEEKBAR_VAL; mFrictionSeekBar.SetOnSeekBarChangeListener(seekbarListener); mSpringSelectorSpinner.Adapter = spinnerAdapter; mSpringSelectorSpinner.OnItemSelectedListener = new SpringSelectedListener() { ItemSelected = (ad, v, i, l) => { mSelectedSpringConfig = mSpringConfigs[i]; updateSeekBarsForSpringConfig(mSelectedSpringConfig); } }; refreshSpringConfigurations(); this.TranslationY = mStashPx; }