Example usage for android.widget ImageView setRotationY

List of usage examples for android.widget ImageView setRotationY

Introduction

In this page you can find the example usage for android.widget ImageView setRotationY.

Prototype

public void setRotationY(float rotationY) 

Source Link

Document

Sets the degrees that the view is rotated around the vertical axis through the pivot point.

Usage

From source file:Main.java

/**
 * Creates an animation that rotates an {@link ImageView}
 * around the Y axis by 180 degrees and changes the image
 * resource shown when the view is rotated 90 degrees to the user.
 *
 * @param imageView   the view to rotate.
 * @param drawableRes the drawable to set when the view
 *                    is rotated by 90 degrees.
 * @return an animation that will change the image shown by the view.
 *///from  w  w w . j av  a  2  s. co  m
@NonNull
public static Animation createRotationTransitionAnimation(@NonNull final ImageView imageView,
        @DrawableRes final int drawableRes) {
    Animation animation = new Animation() {

        private boolean mSetFinalDrawable;

        @Override
        protected void applyTransformation(float interpolatedTime, Transformation t) {
            if (interpolatedTime < 0.5f) {
                imageView.setRotationY(90 * interpolatedTime * 2f);
            } else {
                if (!mSetFinalDrawable) {
                    mSetFinalDrawable = true;
                    imageView.setImageResource(drawableRes);
                }
                imageView.setRotationY((-90) + (90 * (interpolatedTime - 0.5f) * 2f));
            }
        }
    };

    animation.setDuration(300);
    animation.setInterpolator(new AccelerateDecelerateInterpolator());

    return animation;
}

From source file:com.farmerbb.taskbar.service.TaskbarService.java

private View getView(List<AppEntry> list, int position) {
    View convertView = View.inflate(this, R.layout.icon, null);

    final AppEntry entry = list.get(position);
    final SharedPreferences pref = U.getSharedPreferences(this);

    ImageView imageView = (ImageView) convertView.findViewById(R.id.icon);
    ImageView imageView2 = (ImageView) convertView.findViewById(R.id.shortcut_icon);
    imageView.setImageDrawable(entry.getIcon(this));
    imageView2.setBackgroundColor(/*w w w  .  j a v  a  2s  .  c  om*/
            pref.getInt("accent_color", getResources().getInteger(R.integer.translucent_white)));

    String taskbarPosition = U.getTaskbarPosition(this);
    if (pref.getBoolean("shortcut_icon", true)) {
        boolean shouldShowShortcutIcon;
        if (taskbarPosition.contains("vertical"))
            shouldShowShortcutIcon = position >= list.size() - numOfPinnedApps;
        else
            shouldShowShortcutIcon = position < numOfPinnedApps;

        if (shouldShowShortcutIcon)
            imageView2.setVisibility(View.VISIBLE);
    }

    if (taskbarPosition.equals("bottom_right") || taskbarPosition.equals("top_right")) {
        imageView.setRotationY(180);
        imageView2.setRotationY(180);
    }

    FrameLayout layout = (FrameLayout) convertView.findViewById(R.id.entry);
    layout.setOnClickListener(view -> U.launchApp(TaskbarService.this, entry.getPackageName(),
            entry.getComponentName(), entry.getUserId(TaskbarService.this), null, true, false));

    layout.setOnLongClickListener(view -> {
        int[] location = new int[2];
        view.getLocationOnScreen(location);
        openContextMenu(entry, location);
        return true;
    });

    layout.setOnGenericMotionListener((view, motionEvent) -> {
        int action = motionEvent.getAction();

        if (action == MotionEvent.ACTION_BUTTON_PRESS
                && motionEvent.getButtonState() == MotionEvent.BUTTON_SECONDARY) {
            int[] location = new int[2];
            view.getLocationOnScreen(location);
            openContextMenu(entry, location);
        }

        if (action == MotionEvent.ACTION_SCROLL && pref.getBoolean("visual_feedback", true))
            view.setBackgroundColor(0);

        return false;
    });

    if (pref.getBoolean("visual_feedback", true)) {
        layout.setOnHoverListener((v, event) -> {
            if (event.getAction() == MotionEvent.ACTION_HOVER_ENTER) {
                int accentColor = U.getAccentColor(TaskbarService.this);
                accentColor = ColorUtils.setAlphaComponent(accentColor, Color.alpha(accentColor) / 2);
                v.setBackgroundColor(accentColor);
            }

            if (event.getAction() == MotionEvent.ACTION_HOVER_EXIT)
                v.setBackgroundColor(0);

            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
                v.setPointerIcon(PointerIcon.getSystemIcon(TaskbarService.this, PointerIcon.TYPE_DEFAULT));

            return false;
        });

        layout.setOnTouchListener((v, event) -> {
            v.setAlpha(
                    event.getAction() == MotionEvent.ACTION_DOWN || event.getAction() == MotionEvent.ACTION_MOVE
                            ? 0.5f
                            : 1);
            return false;
        });
    }

    return convertView;
}