com.facebook.rebound.SpringSystem Java Examples
The following examples show how to use
com.facebook.rebound.SpringSystem.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SwitchButton.java From FimiX8-RE with MIT License | 6 votes |
public void setup(AttributeSet attrs) { this.paint = new Paint(1); this.paint.setStyle(Style.STROKE); this.paint.setStrokeCap(Cap.ROUND); this.springSystem = SpringSystem.create(); this.spring = this.springSystem.createSpring(); this.spring.setSpringConfig(SpringConfig.fromOrigamiTensionAndFriction(50.0d, 7.0d)); setOnClickListener(new OnClickListener() { public void onClick(View arg0) { SwitchButton.this.onViewSwitch(); } }); TypedArray typedArray = getContext().obtainStyledAttributes(attrs, R.styleable.SwitchButton); this.onSpotColor = typedArray.getColor(R.styleable.SwitchButton_onColor, this.onSpotColor); this.offSpotColor = typedArray.getColor(R.styleable.SwitchButton_spotColor, this.offSpotColor); this.toggleOn = typedArray.getBoolean(R.styleable.SwitchButton_onToggle, this.toggleOn); this.spotColor = this.offSpotColor; this.borderWidth = typedArray.getDimensionPixelSize(R.styleable.SwitchButton_borderWidth, (int) AbViewUtil.dip2px(getContext(), (float) this.borderWidth)); this.defaultAnimate = typedArray.getBoolean(R.styleable.SwitchButton_animate, this.defaultAnimate); typedArray.recycle(); }
Example #2
Source File: Magnet.java From Magnet with MIT License | 6 votes |
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); }
Example #3
Source File: MenuItemView.java From SpringFloatingActionMenu with Apache License 2.0 | 6 votes |
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); }
Example #4
Source File: SpringFloatingActionMenu.java From SpringFloatingActionMenu with Apache License 2.0 | 6 votes |
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); } }
Example #5
Source File: SpringFloatingActionMenu.java From SpringFloatingActionMenu with Apache License 2.0 | 6 votes |
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); } }
Example #6
Source File: YOLOComboView.java From RxComboDetector with MIT License | 6 votes |
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); }
Example #7
Source File: Floating.java From FloatingView with Apache License 2.0 | 6 votes |
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(); } }
Example #8
Source File: ToggleButton.java From light-novel-library_Wenku8_Android with GNU General Public License v2.0 | 6 votes |
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(); }
Example #9
Source File: SpringConfiguratorView.java From light-novel-library_Wenku8_Android with GNU General Public License v2.0 | 5 votes |
@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); }
Example #10
Source File: ToggleButton.java From ToggleButton with MIT License | 5 votes |
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_tbOffBorderColor, offBorderColor); onColor = typedArray.getColor(R.styleable.ToggleButton_tbOnColor, onColor); spotColor = typedArray.getColor(R.styleable.ToggleButton_tbSpotColor, spotColor); offColor = typedArray.getColor(R.styleable.ToggleButton_tbOffColor, offColor); borderWidth = typedArray.getDimensionPixelSize(R.styleable.ToggleButton_tbBorderWidth, borderWidth); defaultAnimate = typedArray.getBoolean(R.styleable.ToggleButton_tbAnimate, defaultAnimate); isDefaultOn = typedArray.getBoolean(R.styleable.ToggleButton_tbAsDefaultOn, isDefaultOn); typedArray.recycle(); borderColor = offBorderColor; if (isDefaultOn) { toggleOn(); } }
Example #11
Source File: SpringHelper.java From FloatingView with Apache License 2.0 | 5 votes |
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); }
Example #12
Source File: PrismActivity.java From PrismView with Apache License 2.0 | 5 votes |
/** * Create a new Instance of moveSpring if it's needed. * @return Instance of moveSpring. */ private Spring moveSpring() { SpringConfig springConfig = null; if (springType == SpringType.ORIGAMI) { if (isValuesNotSet()) { firstValue = DEFAULT_TENSION; secondValue = DEFAULT_FRICTION; } springConfig = SpringConfig.fromOrigamiTensionAndFriction(firstValue, secondValue); } else if (springType == SpringType.SPEEDBOUNCINESS) { if (isValuesNotSet()) { firstValue = DEFAULT_BOUNCENESS; secondValue = DEFAULT_SPEED; } springConfig = SpringConfig.fromBouncinessAndSpeed(firstValue, secondValue); } if (moveSpring == null) { if (springConfig != null) { moveSpring = SpringSystem.create().createSpring().setSpringConfig(springConfig); } } else { moveSpring.setSpringConfig(springConfig); } return moveSpring; }
Example #13
Source File: DefaultChatHeadManager.java From springy-heads with Apache License 2.0 | 5 votes |
private void init(Context context, ChatHeadConfig chatHeadDefaultConfig) { chatHeadContainer.onInitialized(this); DisplayMetrics metrics = new DisplayMetrics(); WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); windowManager.getDefaultDisplay().getMetrics(metrics); this.displayMetrics = metrics; this.config = chatHeadDefaultConfig; //TODO : needs cleanup chatHeads = new ArrayList<>(5); arrowLayout = new UpArrowLayout(context); arrowLayout.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); chatHeadContainer.addView(arrowLayout, arrowLayout.getLayoutParams()); arrowLayout.setVisibility(View.GONE); springSystem = SpringSystem.create(); closeButton = new ChatHeadCloseButton(context, this, maxHeight, maxWidth); ViewGroup.LayoutParams layoutParams = chatHeadContainer.createLayoutParams(chatHeadDefaultConfig.getCloseButtonHeight(), chatHeadDefaultConfig.getCloseButtonWidth(), Gravity.TOP | Gravity.START, 0); closeButton.setListener(this); chatHeadContainer.addView(closeButton, layoutParams); closeButtonShadow = new ImageView(getContext()); ViewGroup.LayoutParams shadowLayoutParams = chatHeadContainer.createLayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.MATCH_PARENT, Gravity.BOTTOM, 0); closeButtonShadow.setImageResource(R.drawable.dismiss_shadow); closeButtonShadow.setVisibility(View.GONE); chatHeadContainer.addView(closeButtonShadow, shadowLayoutParams); arrangements.put(MinimizedArrangement.class, new MinimizedArrangement(this)); arrangements.put(MaximizedArrangement.class, new MaximizedArrangement<T>(this)); setupOverlay(context); setConfig(chatHeadDefaultConfig); SpringConfigRegistry.getInstance().addSpringConfig(SpringConfigsHolder.DRAGGING, "dragging mode"); SpringConfigRegistry.getInstance().addSpringConfig(SpringConfigsHolder.NOT_DRAGGING, "not dragging mode"); }
Example #14
Source File: ChatHead.java From springy-heads with Apache License 2.0 | 5 votes |
public ChatHead(ChatHeadManager manager, SpringSystem springsHolder, Context context, boolean isSticky) { super(context); this.manager = manager; this.springSystem = springsHolder; this.isSticky = isSticky; init(); }
Example #15
Source File: DraggerView.java From Dragger with Apache License 2.0 | 5 votes |
/** * The global default {@link Spring} instance. * * This instance is automatically initialized with defaults that are suitable to most * implementations. * */ private Spring getSpring() { if (singleton == null) { synchronized (Spring.class) { if (singleton == null) { singleton = SpringSystem .create() .createSpring() .setSpringConfig(SpringConfig.fromOrigamiTensionAndFriction(tension, friction)); } } } return singleton; }
Example #16
Source File: SpringConfiguratorView.java From KugouLayout with MIT License | 5 votes |
@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); }
Example #17
Source File: PressFragment.java From Backboard with Apache License 2.0 | 5 votes |
@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; }
Example #18
Source File: SnapFragment.java From Backboard with Apache License 2.0 | 5 votes |
@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; }
Example #19
Source File: ExplosionFragment.java From Backboard with Apache License 2.0 | 5 votes |
@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; }
Example #20
Source File: ExplosionFragment.java From Backboard with Apache License 2.0 | 5 votes |
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); }
Example #21
Source File: ReboundModule.java From MediaPickerInstagram with Apache License 2.0 | 5 votes |
public void init(ImageView imageView) { if (mSpringSystem == null) { mSpringSystem = SpringSystem.create(); if (mSpring == null) { mSpring = mSpringSystem.createSpring(); } } addListener(imageView); imageView.setOnTouchListener(addOnTouchListener()); }
Example #22
Source File: MoveFragment.java From Backboard with Apache License 2.0 | 5 votes |
@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; }
Example #23
Source File: MenuItemView.java From SpringFloatingActionMenu with Apache License 2.0 | 5 votes |
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); }
Example #24
Source File: DefaultChatHeadManager.java From springy-heads with Apache License 2.0 | 4 votes |
@Override public SpringSystem getSpringSystem() { return springSystem; }
Example #25
Source File: YumFloating.java From FloatingView with Apache License 2.0 | 4 votes |
public YumFloating(View targetView, SpringSystem springSystem) { mTargetViewWeakReference = new WeakReference<View>(targetView); this.mSpringSystem = springSystem; }
Example #26
Source File: SpringFloatingActionMenu.java From SpringFloatingActionMenu with Apache License 2.0 | 4 votes |
private void applyFollowAnimation() { /* Animation code */ final SpringSystem springSystem = SpringSystem.create(); // create the springs that control movement final Spring springX = springSystem.createSpring(); final Spring springY = springSystem.createSpring(); // bind circle movement to events new Actor.Builder(springSystem, mFAB) .addMotion(springX, Imitator.TRACK_DELTA, Imitator.FOLLOW_EXACT, MotionProperty.X) .addMotion(springY, Imitator.TRACK_DELTA, Imitator.FOLLOW_EXACT, MotionProperty.Y) .build(); // add springs to connect between the views final Spring[] followsX = new Spring[mMenuItemCount]; final Spring[] followsY = new Spring[mMenuItemCount]; for (int i = 0; i < mFollowCircles.size(); i++) { // create spring to bind views followsX[i] = springSystem.createSpring(); followsY[i] = springSystem.createSpring(); followsX[i].addListener(new Performer(mFollowCircles.get(i), View.TRANSLATION_X)); followsY[i].addListener(new Performer(mFollowCircles.get(i), View.TRANSLATION_Y)); // imitates another character final SpringImitator followX = new SpringImitator(followsX[i]); final 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); } } }
Example #27
Source File: MagnetTest.java From Magnet with MIT License | 4 votes |
@Before public void setUp() throws Exception { final Display displayMock = mock(Display.class); final Resources resourcesMock = mock(Resources.class); final Context contextMock = mock(Context.class); final ViewTreeObserver viewTreeObserverMock = mock(ViewTreeObserver.class); final SpringConfig config = SpringConfig.fromBouncinessAndSpeed(1, 20); displayMetricsMock = mock(DisplayMetrics.class); displayMetricsMock.widthPixels = initialX; displayMetricsMock.heightPixels = initialY; removeViewMock = mock(RemoveView.class); buttonMock = mock(View.class); windowManagerMock = mock(WindowManager.class); iconCallbackMock = mock(IconCallback.class); iconViewMock = mock(ImageView.class); paramsMock = mock(LayoutParams.class); mockXSpring = mock(Spring.class); mockYSpring = mock(Spring.class); doReturn(viewTreeObserverMock).when(iconViewMock).getViewTreeObserver(); doReturn(windowManagerMock).when(contextMock).getSystemService(Context.WINDOW_SERVICE); doReturn(displayMetricsMock).when(resourcesMock).getDisplayMetrics(); doReturn(displayMock).when(windowManagerMock).getDefaultDisplay(); doReturn(resourcesMock).when(contextMock).getResources(); setInternalState(removeViewMock, "button", buttonMock); whenNew(RemoveView.class).withArguments(contextMock).thenReturn(removeViewMock); whenNew(DisplayMetrics.class).withNoArguments().thenReturn(displayMetricsMock); whenNew(WindowManager.LayoutParams.class).withAnyArguments().thenReturn(paramsMock); doReturn(config).when(mockXSpring).getSpringConfig(); doReturn(config).when(mockYSpring).getSpringConfig(); Magnet instance = Magnet.newBuilder(contextMock).setIconView(iconViewMock) .setIconCallback(iconCallbackMock) .setRemoveIconResId(R.drawable.ic_close) .setRemoveIconShadow(R.drawable.bottom_shadow) .setShouldStickToWall(true) .setRemoveIconShouldBeResponsive(true) .setInitialPosition(initialX, initialY) .setIconWidth(iconWidth) .setIconHeight(iconHeight) .build(); magnet = spy(instance); doReturn(mockXSpring).when(magnet).createXSpring(any(SpringSystem.class), any(SpringConfig.class)); doReturn(mockYSpring).when(magnet).createYSpring(any(SpringSystem.class), any(SpringConfig.class)); setInternalState(magnet, "layoutParams", paramsMock); }
Example #28
Source File: Magnet.java From Magnet with MIT License | 4 votes |
protected Spring createYSpring(SpringSystem springSystem, SpringConfig config) { Spring spring = springSystem.createSpring(); spring.setSpringConfig(config); spring.setRestSpeedThreshold(restVelocity); return spring; }
Example #29
Source File: Magnet.java From Magnet with MIT License | 4 votes |
protected Spring createXSpring(SpringSystem springSystem, SpringConfig config) { Spring spring = springSystem.createSpring(); spring.setSpringConfig(config); spring.setRestSpeedThreshold(restVelocity); return spring; }
Example #30
Source File: Magnet.java From Magnet with MIT License | 4 votes |
@NonNull protected SpringSystem getSpringSystem() { return SpringSystem.create(); }