Example usage for android.view View setY

List of usage examples for android.view View setY

Introduction

In this page you can find the example usage for android.view View setY.

Prototype

public void setY(float y) 

Source Link

Document

Sets the visual y position of this view, in pixels.

Usage

From source file:Main.java

public static void setY(View view, int y) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        view.setY(y);
    } else {/*ww  w  . j av  a2s.  co  m*/
        ViewGroup.MarginLayoutParams marginParams = getOrCreateMarginLayoutParams(view);
        marginParams.topMargin = y - view.getTop();
        view.setLayoutParams(marginParams);
    }
}

From source file:Main.java

public static void linearAnimation(final View view, final int startX, final int startY, final int endX,
        final int endY, long duration, final Runnable callback) {
    Animation anim = new TranslateAnimation(startX, endX, startY, endY);
    anim.setDuration(duration);//from w w w  .  j  a v a  2  s .  co m
    anim.setInterpolator(new DecelerateInterpolator());
    view.startAnimation(anim);

    anim.setAnimationListener(new Animation.AnimationListener() {
        @Override
        public void onAnimationStart(Animation animation) {
        }

        @Override
        public void onAnimationEnd(Animation animation) {
            view.clearAnimation();
            view.setX(view.getX() + endX);
            view.setY(view.getY() + endY);

            if (callback != null)
                callback.run();
        }

        @Override
        public void onAnimationRepeat(Animation animation) {
        }
    });
}

From source file:net.nym.napply.library.behavior.BelowBehavior.java

@Override
public boolean onDependentViewChanged(CoordinatorLayout parent, View child, View dependency) {
    child.setY(dependency.getY() + dependency.getHeight());
    //        ViewCompat.offsetTopAndBottom(child, (dependency.getBottom() - child.getTop()));
    return true;/*from   www  . j  ava 2s  .c om*/
}

From source file:io.github.hidroh.materialistic.widget.NavFloatingActionButton.java

@Synthetic
void startDrag(float startX, float startY) {
    mVibrator.vibrate(VIBRATE_DURATION_MS * 2);
    Toast.makeText(getContext(), R.string.hint_drag, Toast.LENGTH_SHORT).show();
    //noinspection Convert2Lambda
    super.setOnTouchListener(new OnTouchListener() {
        @SuppressLint("ClickableViewAccessibility")
        @TargetApi(Build.VERSION_CODES.HONEYCOMB)
        @Override//from w w  w  . jav a  2s. c  o  m
        public boolean onTouch(View view, MotionEvent motionEvent) {
            switch (motionEvent.getAction()) {
            case MotionEvent.ACTION_MOVE:
                view.setX(motionEvent.getRawX() - startX); // TODO compensate shift
                view.setY(motionEvent.getRawY() - startY);
                break;
            case MotionEvent.ACTION_CANCEL:
            case MotionEvent.ACTION_UP:
                bindNavigationPad();
                break;
            default:
                return false;
            }
            return true;
        }
    });
}

From source file:com.eggwall.SoundSleep.SleepActivity.java

/**
 * Moves the icons to some random location.
 *///w  w  w  .ja  v  a 2s.c  om
private void changeIconLocation() {
    populateTopLevelDimen();
    setGlobalScreenSettings();
    if (cloudSize == null || noteSize == null) {
        return;
    }
    final double locationX = Math.random();
    // The top half of the screen is for the note.
    final int noteY = 0;
    // The bottom half of the screen is for white noise.
    final int cloudY = mHeight - cloudSize.mSecond;
    // The cloud and the note mirror each other on opposite sides to
    // increase visual separation.
    final int cloudX = (int) (locationX * (mWidth - cloudSize.mFirst));
    final float newCloudAlpha = (float) (.35 - (mAlphaDecrement / 100.0));
    final float newNoteAlpha = (float) (.50 - (mAlphaDecrement / 100.0));
    final int noteX = (int) ((1 - locationX) * (mWidth - noteSize.mFirst));
    mAlphaDecrement += 5;
    if (mAlphaDecrement > 20) {
        mAlphaDecrement = 20;
    }
    final View cloud = findViewById(R.id.cloud);
    final View note = findViewById(R.id.note);
    if (SDK >= 11) {
        cloud.setY(cloudY);
        cloud.animate().x(cloudX).alpha(newCloudAlpha);
        note.setY(noteY);
        note.animate().x(noteX).alpha(newNoteAlpha);
    } else {
        cloud.setPadding(cloudX, cloudY, 0, 0);
        note.setPadding(noteX, noteY, 0, 0);
    }
}

From source file:co.com.parsoniisolutions.custombottomsheetbehavior.lib.MergedAppBarLayoutBehavior.java

private boolean setToolbarVisible(boolean visible, final View child) {
    ViewPropertyAnimator mAppBarLayoutAnimation;
    boolean childMoved = false;
    if (visible && !mVisible) {
        childMoved = true;/* w w w .  j a v a2 s .  c  o  m*/
        child.setY(-child.getHeight() / 3);
        mAppBarLayoutAnimation = child.animate()
                .setDuration(mContext.getResources().getInteger(android.R.integer.config_shortAnimTime));
        mAppBarLayoutAnimation.setListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationStart(Animator animation) {
                super.onAnimationStart(animation);
                child.setVisibility(View.VISIBLE);
            }

            @Override
            public void onAnimationEnd(Animator animation) {
                super.onAnimationEnd(animation);
                ((AppCompatActivity) mContext).setSupportActionBar(mToolbar);
                mToolbar.setNavigationOnClickListener(mOnNavigationClickListener);
                ActionBar actionBar = ((AppCompatActivity) mContext).getSupportActionBar();
                if (actionBar != null) {
                    actionBar.setDisplayHomeAsUpEnabled(true);
                }
                mVisible = true;
            }
        });
        mAppBarLayoutAnimation.alpha(1).y(mInitialY).start();
    } else if (!visible && mVisible) {
        mAppBarLayoutAnimation = child.animate()
                .setDuration(mContext.getResources().getInteger(android.R.integer.config_shortAnimTime));
        mAppBarLayoutAnimation.setListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationStart(Animator animation) {
                super.onAnimationStart(animation);
                child.setVisibility(View.INVISIBLE);
            }

            @Override
            public void onAnimationEnd(Animator animation) {
                super.onAnimationEnd(animation);
                ((AppCompatActivity) mContext).setSupportActionBar(null);
                mVisible = false;
            }
        });
        mAppBarLayoutAnimation.alpha(0).start();
    }

    return childMoved;
}

From source file:com.bottomsheetbehavior.MergedAppBarLayoutBehavior.java

private boolean setToolbarVisible(boolean visible, final View child) {
    ViewPropertyAnimator mAppBarLayoutAnimation;
    boolean childMoved = false;
    if (visible && !mVisible) {
        childMoved = true;//  w  w  w  .java2s.c o m
        child.setY(-child.getHeight() / 3);
        mAppBarLayoutAnimation = child.animate()
                .setDuration(mContext.getResources().getInteger(android.R.integer.config_shortAnimTime));
        mAppBarLayoutAnimation.setListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationStart(Animator animation) {
                super.onAnimationStart(animation);
                child.setVisibility(View.VISIBLE);
            }

            @Override
            public void onAnimationEnd(Animator animation) {
                super.onAnimationEnd(animation);
                mVisible = true;
            }
        });
        mAppBarLayoutAnimation.alpha(1).y(mInitialY).start();
    } else if (!visible && mVisible) {
        mAppBarLayoutAnimation = child.animate()
                .setDuration(mContext.getResources().getInteger(android.R.integer.config_shortAnimTime));
        mAppBarLayoutAnimation.setListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationStart(Animator animation) {
                super.onAnimationStart(animation);
                child.setVisibility(View.INVISIBLE);
            }

            @Override
            public void onAnimationEnd(Animator animation) {
                super.onAnimationEnd(animation);
                mVisible = false;
            }
        });
        mAppBarLayoutAnimation.alpha(0).start();
    }

    return childMoved;
}

From source file:com.jaspersoft.android.jaspermobile.widget.DraggableViewsContainer.java

@Override
public boolean onDrag(View v, DragEvent event) {
    int viewId;/*from  w  w w  . j  a  va 2  s. c om*/
    View noteView;
    switch (event.getAction()) {
    case DragEvent.ACTION_DRAG_STARTED:
        viewId = Integer.parseInt(event.getClipDescription().getLabel().toString());
        noteView = findViewById(viewId);
        noteView.setVisibility(View.GONE);
        return true;
    case DragEvent.ACTION_DROP:
        viewId = Integer.parseInt(event.getClipDescription().getLabel().toString());
        noteView = findViewById(viewId);
        noteView.setX(event.getX() - noteView.getWidth() / 2);
        noteView.setY(event.getY() - noteView.getHeight() / 2);
        noteView.setVisibility(View.VISIBLE);
        return true;
    default:
        return false;
    }
}

From source file:ca.zadrox.dota2esportticker.ui.LiveContentView.java

private void initMapView() {
    DisplayMetrics displayMetrics = getResources().getDisplayMetrics();

    int minHeight = displayMetrics.widthPixels > displayMetrics.heightPixels
            ? displayMetrics.heightPixels - UIUtils.calculateActionBarSize(this)
            : displayMetrics.widthPixels;

    mapX = mapY = minHeight - getResources().getDimensionPixelSize(R.dimen.keyline_1) * 2;

    Picasso.with(this).load(R.drawable.dota2_map).config(Bitmap.Config.RGB_565).resize(mapX, mapY).into(mapView,
            mLoadMapCallback);/*from   ww w.  java 2 s. c  o  m*/

    for (int i = 0; i < DotaMapModel.DIRE_TOWERS.length; i++) {
        int x = DotaMapModel.scaleToNewMapSize(DotaMapModel.DIRE_TOWERS_X[i], mapX);
        int y = DotaMapModel.scaleToNewMapSize(DotaMapModel.DIRE_TOWERS_Y[i], mapY);

        View v = findViewById(DotaMapModel.DIRE_TOWERS[i]);
        v.setX(x);
        v.setY(y);
        v.setBackground(getResources().getDrawable(R.drawable.dire_tower));
    }

    for (int i = 0; i < DotaMapModel.DIRE_STRUCTURES.length; i++) {
        int x = DotaMapModel.scaleToNewMapSize(DotaMapModel.DIRE_STRUCTURES_X[i], mapX);
        int y = DotaMapModel.scaleToNewMapSize(DotaMapModel.DIRE_STRUCTURES_Y[i], mapY);

        View v = findViewById(DotaMapModel.DIRE_STRUCTURES[i]);
        v.setX(x);
        v.setY(y);
        v.setBackground(getResources().getDrawable(R.drawable.dire_hero_oval));
    }

    for (int i = 0; i < DotaMapModel.RADIANT_TOWERS.length; i++) {
        int x = DotaMapModel.scaleToNewMapSize(DotaMapModel.RADIANT_TOWERS_X[i], mapX);
        int y = DotaMapModel.scaleToNewMapSize(DotaMapModel.RADIANT_TOWERS_Y[i], mapY);

        View v = findViewById(DotaMapModel.RADIANT_TOWERS[i]);
        v.setX(x);
        v.setY(y);
        v.setBackground(getResources().getDrawable(R.drawable.radiant_tower));
    }

    for (int i = 0; i < DotaMapModel.RADIANT_STRUCTURES.length; i++) {
        int x = DotaMapModel.scaleToNewMapSize(DotaMapModel.RADIANT_STRUCTURES_X[i], mapX);
        int y = DotaMapModel.scaleToNewMapSize(DotaMapModel.RADIANT_STRUCTURES_Y[i], mapY);

        View v = findViewById(DotaMapModel.RADIANT_STRUCTURES[i]);
        v.setX(x);
        v.setY(y);
        v.setBackground(getResources().getDrawable(R.drawable.radiant_hero_oval));
    }

    final int iconSizeRoshan = Math.round(
            TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 20, getResources().getDisplayMetrics()));

    ImageView v = (ImageView) findViewById(DotaMapModel.ROSHAN);
    v.setX(DotaMapModel.scaleToNewMapSize(DotaMapModel.ROSHAN_X, mapX));
    v.setY(DotaMapModel.scaleToNewMapSize(DotaMapModel.ROSHAN_Y, mapY));

    Picasso.with(this).load(R.drawable.drawable_map_roshan).resize(iconSizeRoshan, iconSizeRoshan).centerCrop()
            .into(v);
}

From source file:co.com.parsoniisolutions.custombottomsheetbehavior.lib.ScrollingAppBarLayoutBehavior.java

private boolean init(CoordinatorLayout parent, View child, View dependency) {
    /**/*w  w  w . ja  v  a 2  s  . c  om*/
     * First we need to know if dependency view is upper or lower compared with
     * {@link BottomSheetBehaviorGoogleMapsLike#getPeekHeight()} Y position to know if need to show the AppBar at beginning.
     */
    getBottomSheetBehavior(parent);
    if (mBottomSheetBehaviorRef == null || mBottomSheetBehaviorRef.get() == null)
        getBottomSheetBehavior(parent);
    int mCollapsedY = dependency.getHeight() - mBottomSheetBehaviorRef.get().getPeekHeight();
    mVisible = (dependency.getY() >= mCollapsedY);

    setStatusBarBackgroundVisible(mVisible);
    if (!mVisible)
        child.setY((int) child.getY() - child.getHeight() - getStatusBarHeight());
    mInit = true;
    /**
     * Following {@link #onDependentViewChanged} docs, we need to return true if the
     * Behavior changed the child view's size or position, false otherwise.
     * In our case we only move it if mVisible got false in this method.
     */
    return !mVisible;
}