Java Code Examples for android.view.animation.Animation#RELATIVE_TO_PARENT

The following examples show how to use android.view.animation.Animation#RELATIVE_TO_PARENT . 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: CustomCaptureActvity.java    From imsdk-android with MIT License 6 votes vote down vote up
private void initCamera()
{
    autoFocusHandler = new Handler();
    mCameraManager = new CameraManager(this);
    try {
        mCameraManager.openDriver();
    } catch (Exception e) {
        LogUtil.e(TAG,"ERROR",e);
        finish();
    }

    mCamera = mCameraManager.getCamera();
    mPreview = new CameraPreview(this, mCamera, previewCb, autoFocusCB);
    scanPreview.addView(mPreview);

    TranslateAnimation animation = new TranslateAnimation(Animation.RELATIVE_TO_PARENT, 0.0f, Animation.RELATIVE_TO_PARENT, 0.0f, Animation.RELATIVE_TO_PARENT, 0.0f, Animation.RELATIVE_TO_PARENT,
            0.85f);
    animation.setDuration(3000);
    animation.setRepeatCount(-1);
    animation.setRepeatMode(Animation.REVERSE);
    scanLine.startAnimation(animation);
}
 
Example 2
Source File: MaterialScrollBar.java    From MaterialScrollBar with Apache License 2.0 6 votes vote down vote up
private void generalSetup() {
    recyclerView.setVerticalScrollBarEnabled(false); // disable any existing scrollbars
    recyclerView.addOnScrollListener(new ScrollListener()); // lets us read when the recyclerView scrolls

    setTouchIntercept(); // catches touches on the bar

    identifySwipeRefreshParents();

    checkCustomScrolling();

    for(int i = 0; i < onAttach.size(); i++) {
        onAttach.get(i).run();
    }

    //Hides the view
    TranslateAnimation anim = new TranslateAnimation(
            Animation.RELATIVE_TO_PARENT, 0.0f,
            Animation.RELATIVE_TO_SELF, rtl ? -getHideRatio() : getHideRatio(),
            Animation.RELATIVE_TO_PARENT, 0.0f,
            Animation.RELATIVE_TO_PARENT, 0.0f);
    anim.setDuration(0);
    anim.setFillAfter(true);
    hidden = true;
    startAnimation(anim);
}
 
Example 3
Source File: SquashPageAnimator.java    From Paginize with MIT License 6 votes vote down vote up
private void initAnimations() {
  DecelerateInterpolator interpolator = new DecelerateInterpolator(3.0f);
  mExpandInFromRightAnimation = new ScaleAnimation(0, 1, 1, 1, Animation.RELATIVE_TO_PARENT, 1, Animation.RELATIVE_TO_PARENT, 0);
  mExpandInFromRightAnimation.setInterpolator(interpolator);
  mExpandInFromRightAnimation.setDuration(ANIMATION_DURATION);

  mShrinkOutFromRightAnimation = new ScaleAnimation(1, 0, 1, 1, Animation.RELATIVE_TO_PARENT, 0, Animation.RELATIVE_TO_PARENT, 0);
  mShrinkOutFromRightAnimation.setInterpolator(interpolator);
  mShrinkOutFromRightAnimation.setDuration(ANIMATION_DURATION);

  mExpanndInFromLeftAnimation = new ScaleAnimation(0, 1, 1, 1, Animation.RELATIVE_TO_PARENT, 0, Animation.RELATIVE_TO_PARENT, 0);
  mExpanndInFromLeftAnimation.setInterpolator(interpolator);
  mExpanndInFromLeftAnimation.setDuration(ANIMATION_DURATION);

  mShrinkOutFromLeftAnimation = new ScaleAnimation(1, 0, 1, 1, Animation.RELATIVE_TO_PARENT, 1, Animation.RELATIVE_TO_PARENT, 0);
  mShrinkOutFromLeftAnimation.setInterpolator(interpolator);
  mShrinkOutFromLeftAnimation.setDuration(ANIMATION_DURATION);
}
 
Example 4
Source File: SquashPageAnimator.java    From Paginize with MIT License 6 votes vote down vote up
private void initAnimations() {
  DecelerateInterpolator interpolator = new DecelerateInterpolator(3.0f);
  mExpandInFromRightAnimation = new ScaleAnimation(0, 1, 1, 1,
      Animation.RELATIVE_TO_PARENT, 1, Animation.RELATIVE_TO_PARENT, 0);
  mExpandInFromRightAnimation.setInterpolator(interpolator);
  mExpandInFromRightAnimation.setDuration(ANIMATION_DURATION);

  mShrinkOutFromRightAnimation = new ScaleAnimation(1, 0, 1, 1,
      Animation.RELATIVE_TO_PARENT, 0, Animation.RELATIVE_TO_PARENT, 0);
  mShrinkOutFromRightAnimation.setInterpolator(interpolator);
  mShrinkOutFromRightAnimation.setDuration(ANIMATION_DURATION);

  mExpanndInFromLeftAnimation = new ScaleAnimation(0, 1, 1, 1,
      Animation.RELATIVE_TO_PARENT, 0, Animation.RELATIVE_TO_PARENT, 0);
  mExpanndInFromLeftAnimation.setInterpolator(interpolator);
  mExpanndInFromLeftAnimation.setDuration(ANIMATION_DURATION);

  mShrinkOutFromLeftAnimation = new ScaleAnimation(1, 0, 1, 1,
      Animation.RELATIVE_TO_PARENT, 1, Animation.RELATIVE_TO_PARENT, 0);
  mShrinkOutFromLeftAnimation.setInterpolator(interpolator);
  mShrinkOutFromLeftAnimation.setDuration(ANIMATION_DURATION);
}
 
Example 5
Source File: WheelPicker.java    From RecyclerWheelPicker with Apache License 2.0 6 votes vote down vote up
public void doEnterAnim(final View contentView, long animDuration) {
    if (builder.gravity == Gravity.BOTTOM) {
        ValueAnimator enterAnimator = ValueAnimator.ofFloat(contentView.getHeight(), 0);
        enterAnimator.setDuration(animDuration);
        enterAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator animation) {
                float value = (float) animation.getAnimatedValue();
                contentView.setTranslationY(value);
            }
        });
        enterAnimator.start();
    } else {
        ScaleAnimation scaleAnimation = new ScaleAnimation(0F, 1.0F, 0F, 1.0F,
                Animation.RELATIVE_TO_PARENT, 0.5F, Animation.RELATIVE_TO_PARENT, 0.5F);
        scaleAnimation.setDuration(animDuration);
        scaleAnimation.setFillAfter(true);
        contentView.startAnimation(scaleAnimation);
    }
}
 
Example 6
Source File: WheelPicker.java    From RecyclerWheelPicker with Apache License 2.0 6 votes vote down vote up
public void doExitAnim(final View contentView, long animDuration) {
    if (builder.gravity == Gravity.BOTTOM) {
        ValueAnimator exitAnimator = ValueAnimator.ofFloat(0, contentView.getHeight());
        exitAnimator.setDuration(animDuration);
        exitAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator animation) {
                float value = (float) animation.getAnimatedValue();
                contentView.setTranslationY(value);
            }
        });
        exitAnimator.start();
    } else {
        ScaleAnimation scaleAnimation = new ScaleAnimation(1.0F, 0.0F, 1.0F, 0.0F,
                Animation.RELATIVE_TO_PARENT, 0.5F, Animation.RELATIVE_TO_PARENT, 0.5F);
        scaleAnimation.setDuration(animDuration);
        scaleAnimation.setFillAfter(true);
        contentView.startAnimation(scaleAnimation);
    }
}
 
Example 7
Source File: EBrowserWidget.java    From appcan-android with GNU Lesser General Public License v3.0 5 votes vote down vote up
public void goMySpace(View view) {
    addView(view);
    TranslateAnimation anim = new TranslateAnimation(
            Animation.RELATIVE_TO_PARENT, 0.0f,
            Animation.RELATIVE_TO_PARENT, 0.0f,
            Animation.RELATIVE_TO_PARENT, 1.0f,
            Animation.RELATIVE_TO_PARENT, 0.0f);
    anim.setDuration(250);
    DecelerateInterpolator di = new DecelerateInterpolator();
    anim.setInterpolator(di);
    view.startAnimation(anim);
    mBroWindow.setVisibility(GONE);
}
 
Example 8
Source File: AnimationUtil.java    From appinventor-extensions with Apache License 2.0 5 votes vote down vote up
private static void ApplyHorizontalScrollAnimation(View view, boolean left, int speed) {
  float sign = left ? 1f : -1f;
  AnimationSet animationSet = new AnimationSet(true);
  animationSet.setRepeatCount(Animation.INFINITE);
  animationSet.setRepeatMode(Animation.RESTART);

  TranslateAnimation move = new TranslateAnimation(Animation.RELATIVE_TO_PARENT, sign * 0.70f,
      Animation.RELATIVE_TO_PARENT, sign * -0.70f, Animation.RELATIVE_TO_PARENT, 0,
      Animation.RELATIVE_TO_PARENT, 0);
  move.setStartOffset(0);
  move.setDuration(speed);
  move.setFillAfter(true);
  animationSet.addAnimation(move);
  view.startAnimation(animationSet);
}
 
Example 9
Source File: ViewFlipperTestActivity.java    From coursera-android with MIT License 5 votes vote down vote up
private Animation inFromRightAnimation() {
	Animation inFromRight = new TranslateAnimation(
			Animation.RELATIVE_TO_PARENT, +1.0f,
			Animation.RELATIVE_TO_PARENT, 0.0f,
			Animation.RELATIVE_TO_PARENT, 0.0f,
			Animation.RELATIVE_TO_PARENT, 0.0f);
	inFromRight.setDuration(500);
	inFromRight.setInterpolator(new LinearInterpolator());
	return inFromRight;
}
 
Example 10
Source File: Push.java    From mobile-sdk-android with Apache License 2.0 5 votes vote down vote up
private Animation getAnimation(float[] direction, Interpolator interpolator, long duration){
    Animation animation = new TranslateAnimation(
                    Animation.RELATIVE_TO_PARENT, direction[0], Animation.RELATIVE_TO_PARENT, direction[1],
                    Animation.RELATIVE_TO_PARENT, direction[2], Animation.RELATIVE_TO_PARENT, direction[3]
            );
    animation.setInterpolator(interpolator);
    animation.setDuration(duration);
    return animation;
}
 
Example 11
Source File: AnimationUtils.java    From proteus with Apache License 2.0 5 votes vote down vote up
/**
 * Size descriptions can appear in three forms:
 * <ol>
 * <li>An absolute size. This is represented by a number.</li>
 * <li>A size relative to the size of the object being animated. This
 * is represented by a number followed by "%".</li> *
 * <li>A size relative to the size of the parent of object being
 * animated. This is represented by a number followed by "%p".</li>
 * </ol>
 *
 * @param value The Json value to parse
 * @return The parsed version of the description
 */
static Description parseValue(Value value) {
  Description d = new Description();
  d.type = Animation.ABSOLUTE;
  d.value = 0;
  if (value != null && value.isPrimitive()) {
    if (value.getAsPrimitive().isNumber()) {
      d.type = Animation.ABSOLUTE;
      d.value = value.getAsPrimitive().getAsFloat();
    } else {
      String stringValue = value.getAsPrimitive().getAsString();
      if (stringValue.endsWith(PERCENT_SELF)) {
        stringValue = stringValue.substring(0, stringValue.length() - PERCENT_SELF.length());
        d.value = Float.parseFloat(stringValue) / 100;
        d.type = Animation.RELATIVE_TO_SELF;
      } else if (stringValue.endsWith(PERCENT_RELATIVE_PARENT)) {
        stringValue = stringValue.substring(0, stringValue.length() - PERCENT_RELATIVE_PARENT.length());
        d.value = Float.parseFloat(stringValue) / 100;
        d.type = Animation.RELATIVE_TO_PARENT;
      } else {
        d.type = Animation.ABSOLUTE;
        d.value = value.getAsPrimitive().getAsFloat();
      }
    }
  }

  return d;
}
 
Example 12
Source File: Category.java    From Trivia-Knowledge with Apache License 2.0 5 votes vote down vote up
private Animation inFromLeftAnimation() {
    Animation inFromLeft = new TranslateAnimation(
            Animation.RELATIVE_TO_PARENT, -1.0f,
            Animation.RELATIVE_TO_PARENT, 0.0f,
            Animation.RELATIVE_TO_PARENT, 0.0f,
            Animation.RELATIVE_TO_PARENT, 0.0f);
    inFromLeft.setDuration(600);
    inFromLeft.setInterpolator(new AccelerateInterpolator());
    return inFromLeft;
}
 
Example 13
Source File: ViewFlipperTestActivity.java    From coursera-android with MIT License 5 votes vote down vote up
private Animation inFromRightAnimation() {
	Animation inFromRight = new TranslateAnimation(
			Animation.RELATIVE_TO_PARENT, +1.0f,
			Animation.RELATIVE_TO_PARENT, 0.0f,
			Animation.RELATIVE_TO_PARENT, 0.0f,
			Animation.RELATIVE_TO_PARENT, 0.0f);
	inFromRight.setDuration(500);
	inFromRight.setInterpolator(new LinearInterpolator());
	return inFromRight;
}
 
Example 14
Source File: PinView.java    From financisto with GNU General Public License v2.0 5 votes vote down vote up
private Animation outToLeftAnimation() {
	Animation outtoLeft = new TranslateAnimation(
			Animation.RELATIVE_TO_PARENT, 0.0f,
			Animation.RELATIVE_TO_PARENT, -1.0f,
			Animation.RELATIVE_TO_PARENT, 0.0f,
			Animation.RELATIVE_TO_PARENT, 0.0f);
	outtoLeft.setDuration(300);
	outtoLeft.setInterpolator(new AccelerateInterpolator());
	return outtoLeft;
}
 
Example 15
Source File: TouchScrollBar.java    From MaterialScrollBar with Apache License 2.0 5 votes vote down vote up
/**
 * Provides the ability to programmatically alter whether the scrollbar
 * should hide after a period of inactivity or not.
 * @param hide sets whether the bar should hide or not.
 *
 *             This method is experimental
 */
public TouchScrollBar setAutoHide(Boolean hide) {
    if(!hide) {
        TranslateAnimation anim = new TranslateAnimation(Animation.RELATIVE_TO_PARENT, 0.0f,
                Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_PARENT, 0.0f, Animation.RELATIVE_TO_PARENT, 0.0f);
        anim.setFillAfter(true);
        startAnimation(anim);
    }
    //This is not obeyed. If you print `hide` outside of this method it disagrees with what is
    //set here. I have no idea wtf is going on so if anyone could figure that out that'd be
    //great.
    this.hide = hide;
    return this;
}
 
Example 16
Source File: RearrangeableLayout.java    From RearrangeableLayout with MIT License 5 votes vote down vote up
private void init(Context context, AttributeSet attrs) {
    mStartTouch = null;
    mSelectedChild = null;
    mContainer = new SparseArray<Parcelable>(5);
    mListener = null;
    mChildStartRect = null;
    mChildEndRect = null;

    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.RearrangeableLayout);
    float strokeWidth = a.getDimension(R.styleable.RearrangeableLayout_outlineWidth, 2.0f);
    int color = a.getColor(R.styleable.RearrangeableLayout_outlineColor, Color.GRAY);
    float alpha = a.getFloat(R.styleable.RearrangeableLayout_selectionAlpha, 0.5f);
    mSelectionZoom = a.getFloat(R.styleable.RearrangeableLayout_selectionZoom, 1.2f);
    a.recycle();

    float filter[] = new float[] {
            1f, 0f, 0f, 0f, 0f,
            0f, 1f, 0f, 0f, 0f,
            0f, 0f, 1f, 0f, 0f,
            0f, 0f, 0f, alpha, 0f
    };
    ColorMatrixColorFilter colorFilter = new ColorMatrixColorFilter(new ColorMatrix(filter));

    mOutlinePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mOutlinePaint.setStyle(Paint.Style.STROKE);
    mOutlinePaint.setStrokeWidth(strokeWidth);
    mOutlinePaint.setColor(color);
    mOutlinePaint.setColorFilter(colorFilter);

    mSelectionPaint = new Paint();
    mSelectionPaint.setColorFilter(colorFilter);

    Animation trans = new TranslateAnimation(Animation.ABSOLUTE, 0, Animation.ABSOLUTE, 0,
            Animation.RELATIVE_TO_PARENT, 1, Animation.RELATIVE_TO_PARENT, 0);
    trans.setDuration(500);
    trans.setInterpolator(new AccelerateInterpolator(1.0f));

    LayoutAnimationController c = new LayoutAnimationController(trans, 0.25f);
    setLayoutAnimation(c);
}
 
Example 17
Source File: WindowStack.java    From NetCloud_android with GNU General Public License v2.0 5 votes vote down vote up
public WindowStack(Context context){
    mStack = new Stack<>();
    mRoot = new StackView(context);
    mRoot.setBackgroundColor(Color.TRANSPARENT);

    mAnimIn = new TranslateAnimation(Animation.RELATIVE_TO_PARENT,1,Animation.RELATIVE_TO_PARENT,0,
            Animation.RELATIVE_TO_PARENT,0,Animation.RELATIVE_TO_PARENT,0);
    mAnimIn.setDuration(300);
    mAnimOut = new TranslateAnimation(Animation.RELATIVE_TO_PARENT,0,Animation.RELATIVE_TO_PARENT,1,
            Animation.RELATIVE_TO_PARENT,0,Animation.RELATIVE_TO_PARENT,0);
    mAnimOut.setDuration(300);

    mSwipeDetector = new SwipeDectector(this);
}
 
Example 18
Source File: MoveIn.java    From mobile-sdk-android with Apache License 2.0 5 votes vote down vote up
private void setInAnimation(float[] direction, Interpolator interpolator, long duration){
    inAnimation = new TranslateAnimation(
            Animation.RELATIVE_TO_PARENT, direction[0], Animation.RELATIVE_TO_PARENT, direction[1],
            Animation.RELATIVE_TO_PARENT, direction[2], Animation.RELATIVE_TO_PARENT, direction[3]
    );
    inAnimation.setInterpolator(interpolator);
    inAnimation.setDuration(duration);
}
 
Example 19
Source File: QrCodeScanActivity.java    From FamilyChat with Apache License 2.0 4 votes vote down vote up
protected void initUI()
{
    //全屏设置
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT)
    {
        View statusBar = findViewById(R.id.view_qrcode_actionbar_status);
        statusBar.setVisibility(View.VISIBLE);
        ViewGroup.LayoutParams layoutParams = statusBar.getLayoutParams();
        layoutParams.height = OtherUtils.getStatusBarHeight(this);
        statusBar.setLayoutParams(layoutParams);
    }

    //闪光灯
    mImgLight = (ImageView) findViewById(R.id.img_qrcode_light);

    mScanPreview = (SurfaceView) findViewById(R.id.capture_preview);
    mScanContainer = (RelativeLayout) findViewById(R.id.capture_container);
    mScanCropView = (RelativeLayout) findViewById(R.id.capture_crop_view);
    mScanLine = (ImageView) findViewById(R.id.capture_scan_line);
    //设置阴影
    View shadowTop = findViewById(R.id.capture_mask_top);
    View shadowBottom = findViewById(R.id.capture_mask_bottom);
    View shadowLeft = findViewById(R.id.capture_mask_left);
    View shadowRight = findViewById(R.id.capture_mask_right);
    shadowTop.setAlpha(0.5f);
    shadowBottom.setAlpha(0.5f);
    shadowLeft.setAlpha(0.5f);
    shadowRight.setAlpha(0.5f);

    mInactivityTimer = new InactivityTimer(this);
    mBeepManager = new BeepManager(this);

    TranslateAnimation animation = new TranslateAnimation(Animation.RELATIVE_TO_PARENT, 0.0f, Animation
            .RELATIVE_TO_PARENT, 0.0f, Animation.RELATIVE_TO_PARENT, 0.0f, Animation.RELATIVE_TO_PARENT,
            0.85f);
    animation.setDuration(2500);
    animation.setRepeatCount(-1);
    animation.setInterpolator(new AccelerateDecelerateInterpolator(QrCodeScanActivity.this, null));
    animation.setRepeatMode(Animation.RESTART);
    mScanLine.startAnimation(animation);

    findViewById(R.id.ll_qrcode_actionbar_left_back).setOnClickListener(this);
    mImgLight.setOnClickListener(this);
}
 
Example 20
Source File: CaptureActivity.java    From GOpenSource_AppKit_Android_AS with MIT License 4 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);

	/**
	 * 设置为竖屏
	 */
	if (getRequestedOrientation() != ActivityInfo.SCREEN_ORIENTATION_PORTRAIT) {
		setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
	}

	Window window = getWindow();
	window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
	setContentView(R.layout.activity_gos_capture);

	scanPreview = (SurfaceView) findViewById(R.id.capture_preview);
	scanContainer = (RelativeLayout) findViewById(R.id.capture_container);
	scanCropView = (RelativeLayout) findViewById(R.id.capture_crop_view);
	scanLine = (ImageView) findViewById(R.id.capture_scan_line);

	inactivityTimer = new InactivityTimer(this);

	TranslateAnimation animation = new TranslateAnimation(Animation.RELATIVE_TO_PARENT, 0.0f,
			Animation.RELATIVE_TO_PARENT, 0.0f, Animation.RELATIVE_TO_PARENT, -1.0f, Animation.RELATIVE_TO_PARENT,
			0.0f);
	animation.setDuration(4500);
	animation.setRepeatCount(-1);
	animation.setRepeatMode(Animation.RESTART);
	scanLine.startAnimation(animation);

	btnCancel = (Button) findViewById(R.id.btn_cancel);
	ivReturn = (ImageView) findViewById(R.id.iv_return);
	OnClickListener myClick = new OnClickListener() {
		@Override
		public void onClick(View arg0) {
			CaptureActivity.this.finish();
		}
	};
	btnCancel.setOnClickListener(myClick);
	ivReturn.setOnClickListener(myClick);
}