@TargetApi(11) public SpringConfiguratorView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); this.mSpringConfigs = new ArrayList(); this.mTextColor = Color.argb(255, Opcodes.SHR_INT_LIT8, Opcodes.SHR_INT_LIT8, Opcodes .SHR_INT_LIT8); SpringSystem springSystem = SpringSystem.create(); this.springConfigRegistry = SpringConfigRegistry.getInstance(); this.spinnerAdapter = new SpinnerAdapter(context); Resources resources = getResources(); this.mRevealPx = (float) Util.dpToPx(40.0f, resources); this.mStashPx = (float) Util.dpToPx(280.0f, resources); this.mRevealerSpring = springSystem.createSpring(); this.mRevealerSpring.setCurrentValue(PathListView.NO_ZOOM).setEndValue(PathListView .NO_ZOOM).addListener(new RevealerSpringListener()); addView(generateHierarchy(context)); SeekbarListener seekbarListener = new SeekbarListener(); this.mTensionSeekBar.setMax(MAX_SEEKBAR_VAL); this.mTensionSeekBar.setOnSeekBarChangeListener(seekbarListener); this.mFrictionSeekBar.setMax(MAX_SEEKBAR_VAL); this.mFrictionSeekBar.setOnSeekBarChangeListener(seekbarListener); this.mSpringSelectorSpinner.setAdapter(this.spinnerAdapter); this.mSpringSelectorSpinner.setOnItemSelectedListener(new SpringSelectedListener()); refreshSpringConfigurations(); setTranslationY(this.mStashPx); }
private PopMenu(Builder builder) { this.mMenuItems = new ArrayList(); this.isShowing = false; this.mSpringSystem = SpringSystem.create(); this.mActivity = builder.activity; this.mMenuItems.clear(); this.mMenuItems.addAll(builder.itemList); this.mColumnCount = builder.columnCount; this.mDuration = builder.duration; this.mTension = builder.tension; this.mFriction = builder.friction; this.mHorizontalPadding = builder.horizontalPadding; this.mVerticalPadding = builder.verticalPadding; this.mPopMenuItemListener = builder.popMenuItemListener; this.mScreenWidth = this.mActivity.getResources().getDisplayMetrics().widthPixels; this.mScreenHeight = this.mActivity.getResources().getDisplayMetrics().heightPixels; }
private void setSpringSystem() { mSpringSystem = SpringSystem.create(); mSpringsAlpha = mSpringSystem.createSpring() .setSpringConfig(alphaconfig) .setCurrentValue(1); mSpringsAlpha.addListener(new SimpleSpringListener() { @Override public void onSpringUpdate(Spring mSpring) { float value = (float) mSpring.getCurrentValue(); mLockView.setAlpha(value); } }); }
public Floating(Activity activity){ if (activity == null){ throw new NullPointerException("Activity should not be null"); } ViewGroup rootView = (ViewGroup) activity.findViewById(Window.ID_ANDROID_CONTENT); View decorView = rootView.findViewById(R.id.floating_decor); if (decorView instanceof FloatingDecorView){ mFloatingDecorView = (FloatingDecorView) decorView; }else { mFloatingDecorView = new FloatingDecorView(activity); mFloatingDecorView.setId(R.id.floating_decor); rootView.addView(mFloatingDecorView); } if (mSpringSystem == null){ mSpringSystem = SpringSystem.create(); } }
public void setup(AttributeSet attrs) { paint = new Paint(Paint.ANTI_ALIAS_FLAG); paint.setStyle(Style.FILL); paint.setStrokeCap(Cap.ROUND); springSystem = SpringSystem.create(); spring = springSystem.createSpring(); spring.setSpringConfig(SpringConfig.fromOrigamiTensionAndFriction(50, 7)); this.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { toggle(); } }); TypedArray typedArray = getContext().obtainStyledAttributes(attrs, R.styleable.IOSToggleButton); offBorderColor = typedArray.getColor(R.styleable.IOSToggleButton_btnOffBorderColor, offBorderColor); onColor = typedArray.getColor(R.styleable.IOSToggleButton_btnOnColor, onColor); spotColor = typedArray.getColor(R.styleable.IOSToggleButton_btnSpotColor, spotColor); offColor = typedArray.getColor(R.styleable.IOSToggleButton_btnOffColor, offColor); borderWidth = typedArray.getDimensionPixelSize(R.styleable.IOSToggleButton_btnBorderWidth, borderWidth); typedArray.recycle(); }
private void applyBloomOpenAnimation() { final SpringSystem springSystem = SpringSystem.create(); for (int i = 0; i < mMenuItemCount; i++) { // create the springs that control movement final Spring springX = springSystem.createSpring(); final Spring springY = springSystem.createSpring(); MenuItemView menuItemView = mMenuItemViews.get(i); springX.addListener(new MapPerformer(menuItemView, View.X, mFAB.getLeft(), menuItemView.getLeft())); springY.addListener(new MapPerformer(menuItemView, View.Y, mFAB.getTop(), menuItemView.getTop())); DestroySelfSpringListener destroySelfSpringListener = new DestroySelfSpringListener(this,mContainerView,true); springX.addListener(destroySelfSpringListener); springY.addListener(destroySelfSpringListener); springX.setEndValue(1); springY.setEndValue(1); } }
private void applyBloomCloseAnimation() { final SpringSystem springSystem = SpringSystem.create(); for (int i = 0; i < mMenuItemCount; i++) { // create the springs that control movement final Spring springX = springSystem.createSpring(); final Spring springY = springSystem.createSpring(); MenuItemView menuItemView = mMenuItemViews.get(i); springX.addListener(new MapPerformer(menuItemView, View.X, menuItemView.getLeft(), mFAB.getLeft())); springY.addListener(new MapPerformer(menuItemView, View.Y, menuItemView.getTop(), mFAB.getTop())); DestroySelfSpringListener destroySelfSpringListener = new DestroySelfSpringListener(this,mContainerView,false); springX.addListener(destroySelfSpringListener); springY.addListener(destroySelfSpringListener); springX.setEndValue(1); springY.setEndValue(1); } }
private void applyPressAnimation() { SpringSystem springSystem = SpringSystem.create(); final Spring spring = springSystem.createSpring(); spring.addListener(new Performer(mBtn, View.SCALE_X)); spring.addListener(new Performer(mBtn, View.SCALE_Y)); mBtn.setOnTouchListener(new ToggleImitator(spring, 1, 1.2){ @Override public void imitate(MotionEvent event) { super.imitate(event); switch (event.getAction()) { case MotionEvent.ACTION_DOWN: break; case MotionEvent.ACTION_UP: callOnClick(); break; default: } } }); spring.setCurrentValue(1); }
public YOLOComboView(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); BaseSpringSystem springSystem = SpringSystem.create(); mComboSpring = springSystem.createSpring(); mComboSpring.setSpringConfig(SpringConfig.fromOrigamiTensionAndFriction(600, 9)); mYOLOLogo = new ImageView(context); FrameLayout.LayoutParams params = new LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); mYOLOLogo.setLayoutParams(params); mYOLOLogo.setImageResource(R.drawable.ic_yolo); addView(mYOLOLogo); mComboText = new TextView(context); params = new LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT, Gravity.RIGHT); params.rightMargin = 30; mComboText.setLayoutParams(params); mComboText.setTextColor(context.getResources().getColor(android.R.color.holo_red_light)); mComboText.setTextSize(TypedValue.COMPLEX_UNIT_SP, 20); addView(mComboText); mSpringListener = new ComboSpringListener(mComboText); setAlpha(0); }
public void setup(AttributeSet attrs) { paint = new Paint(Paint.ANTI_ALIAS_FLAG); paint.setStyle(Style.FILL); paint.setStrokeCap(Cap.ROUND); springSystem = SpringSystem.create(); spring = springSystem.createSpring(); spring.setSpringConfig(SpringConfig.fromOrigamiTensionAndFriction(50, 7)); this.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { toggle(); } }); TypedArray typedArray = getContext().obtainStyledAttributes(attrs, R.styleable.ToggleButton); offBorderColor = typedArray.getColor(R.styleable.ToggleButton_offBorderColor, offBorderColor); onColor = typedArray.getColor(R.styleable.ToggleButton_onColor, onColor); spotColor = typedArray.getColor(R.styleable.ToggleButton_spotColor, spotColor); offColor = typedArray.getColor(R.styleable.ToggleButton_offColor, offColor); borderWidth = typedArray.getDimensionPixelSize(R.styleable.ToggleButton_borderWidth, borderWidth); typedArray.recycle(); }
protected void initializeMotionPhysics() { SpringConfig config = getSpringConfig(); SpringSystem springSystem = getSpringSystem(); xSpring = createXSpring(springSystem, config); ySpring = createYSpring(springSystem, config); motionImitatorX = new MagnetImitator(MotionProperty.X, Imitator.TRACK_ABSOLUTE, Imitator.FOLLOW_SPRING, 0, 0); motionImitatorY = new MagnetImitator(MotionProperty.Y, Imitator.TRACK_ABSOLUTE, Imitator.FOLLOW_SPRING, 0, 0); xWindowManagerPerformer = new WindowManagerPerformer(MotionProperty.X); yWindowManagerPerformer = new WindowManagerPerformer(MotionProperty.Y); actor = new Actor.Builder(springSystem, iconView).addMotion(xSpring, motionImitatorX, xWindowManagerPerformer) .addMotion(ySpring, motionImitatorY, yWindowManagerPerformer) .onTouchListener(this) .build(); iconView.getViewTreeObserver().addOnGlobalLayoutListener(this); }
private void init(int startAnim, int endAnim) { this.time_start_animation = startAnim; this.time_end_animation = endAnim; springSystem = SpringSystem.create(); mSpring = springSystem.createSpring(); SpringConfig config = new SpringConfig(TENSION, DAMPER); mSpring.setSpringConfig(config); }
/** * Constructor for with Animation Type + Spring config + animation Values * * @param springConfig config class for the spring * @param type SpringyAnimationType instance for animation type * @param tension Spring tension for animation type * @param fraction Spring fraction value for animation * @param startValue where animation start from * @param endValue where animation ends to * **/ public SpringyAnimator(SpringAnimationType type, double tension, double fraction, float startValue, float endValue) { this.tension = tension; this.fraction = fraction; this.startValue = startValue; this.endValue = endValue; springSystem = SpringSystem.create(); animationType = type; }
/** * Constructor for with Animation Type + default config for spring + animation Values * * @param springConfig config class for the spring * @param type SpringyAnimationType instance for animation type * @param startValue where animation start from * @param endValue where animation ends to * **/ public SpringyAnimator(SpringAnimationType type, float startValue, float endValue) { this.tension = DEFAULT_TENSION; this.fraction = DEFAULT_FRACTION; this.startValue = startValue; this.endValue = endValue; springSystem = SpringSystem.create(); animationType = type; }
private void init(int startAnim, int endAnim) { this.timeStartAnimation = startAnim; this.timeEndAnimation = endAnim; springSystem = SpringSystem.create(); mSpring = springSystem.createSpring(); SpringConfig config = new SpringConfig(TENSION, DAMPER); mSpring.setSpringConfig(config); }
public void start(){ SpringSystem springSystem = SpringSystem.create(); Spring spring = springSystem.createSpring(); if (mConfig == 0){ spring.setSpringConfig(SpringConfig.fromBouncinessAndSpeed(mConfigValueOne, mConfigValueTwo)); }else if (mConfig == 1){ spring.setSpringConfig(SpringConfig.fromOrigamiTensionAndFriction(mConfigValueOne, mConfigValueTwo)); } start(spring); }
public void setup(AttributeSet attrs) { paint = new Paint(Paint.ANTI_ALIAS_FLAG); paint.setStyle(Style.FILL); paint.setStrokeCap(Cap.ROUND); springSystem = SpringSystem.create(); spring = springSystem.createSpring(); spring.setSpringConfig(SpringConfig.fromOrigamiTensionAndFriction(50, 7)); this.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { toggle(defaultAnimate); } }); TypedArray typedArray = getContext().obtainStyledAttributes(attrs, R.styleable.SwitchButton); offBorderColor = typedArray.getColor(R.styleable.SwitchButton_offBorderColor, offBorderColor); onColor = typedArray.getColor(R.styleable.SwitchButton_onColor, onColor); spotColor = typedArray.getColor(R.styleable.SwitchButton_spotColor, spotColor); offColor = typedArray.getColor(R.styleable.SwitchButton_offColor, offColor); borderWidth = typedArray.getDimensionPixelSize(R.styleable.SwitchButton_insetBorderWidth, borderWidth); defaultAnimate = typedArray.getBoolean(R.styleable.SwitchButton_animate, defaultAnimate); typedArray.recycle(); borderColor = offBorderColor; }
public RefreshImageView(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); RefreshDrawable refreshDrawable = new RefreshDrawable(this); setBackgroundDrawable(refreshDrawable); mScaleSpringListener = new ScaleSpringListener(this); mScaleSpring = SpringSystem.create().createSpring().setSpringConfig(ORIGAMI_SPRING_CONFIG); }
public ReboundImageView(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); mScaleSpringListener = new MySpringListener(this); mScaleSpring = SpringSystem.create().createSpring().setSpringConfig(ORIGAMI_SPRING_CONFIG); setClickable(true); }
public void showLabel() { SpringSystem springSystem = SpringSystem.create(); final Spring spring = springSystem.createSpring(); spring.addListener(new MapPerformer(mLabel, View.SCALE_X, 0, 1)); spring.addListener(new MapPerformer(mLabel, View.SCALE_Y, 0, 1)); spring.setCurrentValue(0); new Handler().postDelayed(new Runnable() { @Override public void run() { spring.setEndValue(1); } }, 200); }
public void setup(AttributeSet attrs) { mDensity = getResources().getDisplayMetrics().density; paint = new Paint(Paint.ANTI_ALIAS_FLAG); paint.setStyle(Style.FILL); paint.setStrokeCap(Cap.ROUND); springSystem = SpringSystem.create(); spring = springSystem.createSpring(); spring.setSpringConfig(SpringConfig.fromOrigamiTensionAndFriction(50, 7)); this.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { toggle(defaultAnimate); } }); TypedArray typedArray = getContext().obtainStyledAttributes(attrs, R.styleable.ToggleButton); offBorderColor = typedArray.getColor(R.styleable.ToggleButton_offBorderColor, offBorderColor); onColor = typedArray.getColor(R.styleable.ToggleButton_onColor, onColor); spotColor = typedArray.getColor(R.styleable.ToggleButton_spotColor, spotColor); offColor = typedArray.getColor(R.styleable.ToggleButton_offColor, offColor); borderWidth = typedArray.getDimensionPixelSize(R.styleable.ToggleButton_borderWidth, (int)(borderWidth * mDensity)); defaultAnimate = typedArray.getBoolean(R.styleable.ToggleButton_animate, defaultAnimate); typedArray.recycle(); borderColor = offBorderColor; }
@TargetApi(Build.VERSION_CODES.HONEYCOMB) public SpringConfiguratorView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); SpringSystem springSystem = SpringSystem.create(); springConfigRegistry = SpringConfigRegistry.getInstance(); spinnerAdapter = new SpinnerAdapter(context); Resources resources = getResources(); mRevealPx = dpToPx(40, resources); mStashPx = dpToPx(280, resources); mRevealerSpring = springSystem.createSpring(); SpringListener revealerSpringListener = new RevealerSpringListener(); mRevealerSpring .setCurrentValue(1) .setEndValue(1) .addListener(revealerSpringListener); addView(generateHierarchy(context)); SeekbarListener seekbarListener = new SeekbarListener(); mTensionSeekBar.setMax(MAX_SEEKBAR_VAL); mTensionSeekBar.setOnSeekBarChangeListener(seekbarListener); mFrictionSeekBar.setMax(MAX_SEEKBAR_VAL); mFrictionSeekBar.setOnSeekBarChangeListener(seekbarListener); mSpringSelectorSpinner.setAdapter(spinnerAdapter); mSpringSelectorSpinner.setOnItemSelectedListener(new SpringSelectedListener()); refreshSpringConfigurations(); this.setTranslationY(mStashPx); }
public void setup(AttributeSet attrs) { paint = new Paint(Paint.ANTI_ALIAS_FLAG); paint.setStyle(Style.FILL); paint.setStrokeCap(Cap.ROUND); springSystem = SpringSystem.create(); spring = springSystem.createSpring(); spring.setSpringConfig(SpringConfig.fromOrigamiTensionAndFriction(50, 7)); this.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { toggle(defaultAnimate); } }); TypedArray typedArray = getContext().obtainStyledAttributes(attrs, R.styleable.ToggleButton); offBorderColor = typedArray.getColor(R.styleable.ToggleButton_offBorderColor, offBorderColor); onColor = typedArray.getColor(R.styleable.ToggleButton_onColor, onColor); spotColor = typedArray.getColor(R.styleable.ToggleButton_spotColor, spotColor); offColor = typedArray.getColor(R.styleable.ToggleButton_offColor, offColor); borderWidth = typedArray.getDimensionPixelSize(R.styleable.ToggleButton_borderWidthToggleButton, borderWidth); defaultAnimate = typedArray.getBoolean(R.styleable.ToggleButton_animate, defaultAnimate); isDefaultOn = typedArray.getBoolean(R.styleable.ToggleButton_isDefaultOn, isDefaultOn); typedArray.recycle(); borderColor = offBorderColor; if (isDefaultOn) { toggleOn(); } }
public void setup(AttributeSet attrs) { paint = new Paint(Paint.ANTI_ALIAS_FLAG); paint.setStyle(Style.FILL); paint.setStrokeCap(Cap.ROUND); springSystem = SpringSystem.create(); spring = springSystem.createSpring(); spring.setSpringConfig(SpringConfig.fromOrigamiTensionAndFriction(50, 7)); this.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { toggle(defaultAnimate); } }); TypedArray typedArray = getContext().obtainStyledAttributes(attrs, R.styleable.ToggleButton); offBorderColor = typedArray.getColor(R.styleable.ToggleButton_offBorderColor, offBorderColor); onColor = typedArray.getColor(R.styleable.ToggleButton_onColor, onColor); spotColor = typedArray.getColor(R.styleable.ToggleButton_spotColor, spotColor); offColor = typedArray.getColor(R.styleable.ToggleButton_offColor, offColor); borderWidth = typedArray.getDimensionPixelSize(R.styleable.ToggleButton_button_border_width, borderWidth); defaultAnimate = typedArray.getBoolean(R.styleable.ToggleButton_animate, defaultAnimate); isDefaultOn = typedArray.getBoolean(R.styleable.ToggleButton_isDefaultOn, isDefaultOn); typedArray.recycle(); borderColor = offBorderColor; if (isDefaultOn) { toggleOn(); } }
private static Spring initializeSpring(final View view, final int startTranslationX, final int startTranslationY, boolean overshoot) { view.setTranslationX(startTranslationX); view.setTranslationY(startTranslationY); view.setVisibility(View.VISIBLE); // Create a system to run the physics loop for a set of springs. SpringSystem springSystem = SpringSystem.create(); // Add a spring to the system. Spring spring = springSystem.createSpring(); spring.setSpringConfig(SpringConfig.fromOrigamiTensionAndFriction(80, 7)); spring.setOvershootClampingEnabled(!overshoot); return spring; }
public BallExample(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); COASTING = SpringConfig.fromOrigamiTensionAndFriction(0, 0.5); COASTING.tension = 0; setBackgroundColor(Color.WHITE); springSystem = SpringSystem.create(); springSystem.addListener(this); xSpring = springSystem.createSpring(); ySpring = springSystem.createSpring(); xSpring.addListener(this); ySpring.addListener(this); paint = new Paint(Paint.ANTI_ALIAS_FLAG); getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { @Override public void onGlobalLayout() { centerX = getWidth() / 2f; centerY = getHeight() / 2f; xSpring.setCurrentValue(centerX).setAtRest(); ySpring.setCurrentValue(centerY).setAtRest(); getViewTreeObserver().removeOnGlobalLayoutListener(this); int offsetH = (int) ((getHeight() - (2 * radius)) % 800) / 2; int offsetW = (int) ((getWidth() - (2 * radius)) % 800) / 2; for (float i = offsetH + radius; i < getHeight() - offsetH; i += 400) { for (float j = offsetW + radius; j < getWidth() - offsetW; j += 400) { points.add(new PointF(j, i)); } } } }); }
public SpringOverScroller(Context context, Interpolator interpolator, boolean flywheel) { mSpringSystem = SpringSystem.create(); mSpringX = mSpringSystem .createSpring() .addListener(this); mSpringY = mSpringSystem .createSpring() .addListener(this); SpringConfigRegistry .getInstance() .addSpringConfig(RUBBERBANDING_CONFIG, "rubber-banding"); SpringConfigRegistry .getInstance() .addSpringConfig(COASTING_CONFIG, "coasting"); }
public ExampleContainerView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); mSpringSystem = SpringSystem.create(); mTransitionSpring = mSpringSystem.createSpring(); setClickable(true); setLayoutParams(new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { @Override public void onGlobalLayout() { mTransitionSpring.setCurrentValue(1).setAtRest(); getViewTreeObserver().removeOnGlobalLayoutListener(this); } }); setBackgroundColor(Color.WHITE); }
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment_move, container, false); new Actor.Builder(SpringSystem.create(), rootView.findViewById(R.id.circle)) .addTranslateMotion(Imitator.TRACK_DELTA, Imitator.FOLLOW_EXACT, MotionProperty.X) .addTranslateMotion(Imitator.TRACK_DELTA, Imitator.FOLLOW_EXACT, MotionProperty.Y) .build(); return rootView; }
private static void createCircle(Context context, ViewGroup rootView, SpringSystem springSystem, SpringConfig coasting, SpringConfig gravity, int diameter, Drawable backgroundDrawable) { final Spring xSpring = springSystem.createSpring().setSpringConfig(coasting); final Spring ySpring = springSystem.createSpring().setSpringConfig(gravity); // create view View view = new View(context); RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(diameter, diameter); params.addRule(RelativeLayout.CENTER_IN_PARENT); view.setLayoutParams(params); view.setBackgroundDrawable(backgroundDrawable); rootView.addView(view); // generate random direction and magnitude double magnitude = Math.random() * 1000 + 3000; double angle = Math.random() * Math.PI / 2 + Math.PI / 4; xSpring.setVelocity(magnitude * Math.cos(angle)); ySpring.setVelocity(-magnitude * Math.sin(angle)); int maxX = rootView.getMeasuredWidth() / 2 + diameter; xSpring.addListener(new Destroyer(rootView, view, -maxX, maxX)); int maxY = rootView.getMeasuredHeight() / 2 + diameter; ySpring.addListener(new Destroyer(rootView, view, -maxY, maxY)); xSpring.addListener(new Performer(view, View.TRANSLATION_X)); ySpring.addListener(new Performer(view, View.TRANSLATION_Y)); // set a different end value to cause the animation to play xSpring.setEndValue(2); ySpring.setEndValue(9001); }
@Override public void onCreate(Bundle savedInstanceState) { super.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; }
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { final View rootView = inflater.inflate(R.layout.fragment_snap, container, false); final View circle = rootView.findViewById(R.id.circle); new Actor.Builder(SpringSystem.create(), circle) .addTranslateMotion(MotionProperty.Y) .addMotion( new MotionImitator(MotionProperty.X) { @Override public void release(MotionEvent event) { // snap to left or right depending on current location if (mSpring.getCurrentValue() > rootView.getMeasuredWidth() / 2 - circle.getMeasuredWidth() / 2) { mSpring.setEndValue(rootView.getMeasuredWidth() - circle.getMeasuredWidth()); } else { mSpring.setEndValue(0); } } }, View.TRANSLATION_X ) .build(); return rootView; }
@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; }
private void init(Context context, AttributeSet attrs) { if(attrs != null) { TypedArray attrArray = context .obtainStyledAttributes(attrs, R.styleable.DragLayout); for (int i = 0; i < attrArray.getIndexCount(); ++i) { int attr = attrArray.getIndex(i); if (attr == R.styleable.DragLayout_scale) { scale = attrArray.getFloat(attr, DEFAULT_SCALE); } else if (attr == R.styleable.DragLayout_springFriction) { friction = attrArray.getFloat(attr, DEFAULT_FRICTION); } else if (attr == R.styleable.DragLayout_springTension) { tension = attrArray.getFloat(attr, DEFAULT_TENSION); } else if (attr == R.styleable.DragLayout_intercepting) { intercepting = attrArray.getBoolean(attr, DEFAULT_INTERCEPT_TOUCH_EVENT); } } attrArray.recycle(); } setClickable(true); setOnTouchListener(this); setOnLongClickListener(this); SpringSystem springSystem = SpringSystem.create(); pushSpring = springSystem.createSpring(); pushSpring.addListener(this); pushSpring.setSpringConfig(new SpringConfig(tension, friction)); }
public Spring slideButtonSpring() { if(slideButtonSpring == null) { synchronized (Spring.class) { if(slideButtonSpring == null) { slideButtonSpring = SpringSystem .create() .createSpring() .setSpringConfig(SpringConfig.fromOrigamiTensionAndFriction(slideButtonTension, slideButtonFriction)); } } } return slideButtonSpring; }
public Spring fabButtonSpring() { if(fabButtonSpring == null) { synchronized (Spring.class) { if(fabButtonSpring == null) { fabButtonSpring = SpringSystem .create() .createSpring() .setSpringConfig(SpringConfig.fromOrigamiTensionAndFriction(fabButtonTension, fabButtonFriction)); } } } return fabButtonSpring; }
public Spring scaleButtonSpring() { if(scaleButtonSpring == null) { synchronized (Spring.class) { if(scaleButtonSpring == null) { scaleButtonSpring = SpringSystem .create() .createSpring() .setSpringConfig(SpringConfig.fromOrigamiTensionAndFriction(fabButtonTension, fabButtonFriction)); } } } return scaleButtonSpring; }