Example usage for android.view.animation TranslateAnimation TranslateAnimation

List of usage examples for android.view.animation TranslateAnimation TranslateAnimation

Introduction

In this page you can find the example usage for android.view.animation TranslateAnimation TranslateAnimation.

Prototype

public TranslateAnimation(float fromXDelta, float toXDelta, float fromYDelta, float toYDelta) 

Source Link

Document

Constructor to use when building a TranslateAnimation from code

Usage

From source file:johmphot.card.bluetooth.MultiplayerGameActivity.java

@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {

    yourBlood[0] = (ImageView) view.findViewById(R.id.blood11);
    yourBlood[1] = (ImageView) view.findViewById(R.id.blood12);
    yourBlood[2] = (ImageView) view.findViewById(R.id.blood13);
    yourBlood[3] = (ImageView) view.findViewById(R.id.blood14);
    yourBlood[0].setImageResource(R.drawable.ghp);
    yourBlood[1].setImageResource(R.drawable.yhp);
    yourBlood[2].setImageResource(R.drawable.ohp);
    yourBlood[3].setImageResource(R.drawable.rhp);

    opponentBlood[0] = (ImageView) view.findViewById(R.id.blood21);
    opponentBlood[1] = (ImageView) view.findViewById(R.id.blood22);
    opponentBlood[2] = (ImageView) view.findViewById(R.id.blood23);
    opponentBlood[3] = (ImageView) view.findViewById(R.id.blood24);
    opponentBlood[0].setImageResource(R.drawable.ghp);
    opponentBlood[1].setImageResource(R.drawable.yhp);
    opponentBlood[2].setImageResource(R.drawable.ohp);
    opponentBlood[3].setImageResource(R.drawable.rhp);

    handCard[0] = (ImageView) view.findViewById(R.id.card1);
    handCard[1] = (ImageView) view.findViewById(R.id.card2);
    handCard[2] = (ImageView) view.findViewById(R.id.card3);
    handCard[3] = (ImageView) view.findViewById(R.id.card4);

    fieldCardImage = (ImageView) view.findViewById(R.id.field_card);
    fieldCardImage.setVisibility(View.INVISIBLE);

    shieldIcon = (ImageView) view.findViewById(R.id.shieldIcon);
    shieldIcon.setImageResource(R.drawable.shield);
    shieldIcon.setVisibility(View.INVISIBLE);

    opponentShieldIcon = (ImageView) view.findViewById(R.id.opponentShieldIcon);
    opponentShieldIcon.setImageResource(R.drawable.shield);
    opponentShieldIcon.setVisibility(View.INVISIBLE);

    endTurnButton = (Button) view.findViewById(R.id.end_button);

    yourturnText = (TextView) view.findViewById(R.id.yourturn_text);
    yourturnText.setVisibility(View.INVISIBLE);

    final int amountToMoveRight = 0;
    final int amountToMoveDown = 200;
    anim = new TranslateAnimation(0, amountToMoveRight, 0, amountToMoveDown);
    anim.setDuration(1000);/*from   w w w .  j  a  va 2  s  .  c  om*/
    anim.setAnimationListener(new TranslateAnimation.AnimationListener() {

        @Override
        public void onAnimationStart(Animation animation) {
        }

        @Override
        public void onAnimationRepeat(Animation animation) {
        }

        @Override
        public void onAnimationEnd(Animation animation) {
            RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) fieldCardImage.getLayoutParams();
            params.topMargin += amountToMoveDown;
            params.leftMargin += amountToMoveRight;
            fieldCardImage.setLayoutParams(params);
        }
    });

    vibrator = (Vibrator) getActivity().getSystemService(Context.VIBRATOR_SERVICE);
}

From source file:com.breadwallet.tools.animation.BRAnimator.java

/**
 * Animate the transition on wipe wallet fragment
 *//*from   w  w  w  .  j a  va 2s .  c o  m*/

public static void pressWipeWallet(final MainActivity context, final Fragment to) {
    try {
        if (!wipeWalletOpen) {
            wipeWalletOpen = true;
            FragmentTransaction fragmentTransaction = context.getFragmentManager().beginTransaction();
            fragmentTransaction.replace(R.id.main_layout, to, to.getClass().getName());
            fragmentTransaction.commit();
            new Handler().postDelayed(new Runnable() {
                @Override
                public void run() {
                    TranslateAnimation trans = new TranslateAnimation(0, 0, 1920, 0);
                    trans.setDuration(500);
                    trans.setInterpolator(new DecelerateOvershootInterpolator(3f, 0.5f));
                    View view = to.getView();
                    if (view != null)
                        view.startAnimation(trans);
                }
            }, 1);

        } else {
            wipeWalletOpen = false;
            FragmentTransaction fragmentTransaction = context.getFragmentManager().beginTransaction();
            fragmentTransaction.setCustomAnimations(R.animator.from_top, R.animator.to_bottom);
            fragmentTransaction.replace(R.id.main_layout, new FragmentSettings(),
                    FragmentSettings.class.getName());
            fragmentTransaction.commit();
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:cn.jmessage.android.uikit.pickerimage.view.BaseZoomableImageView.java

protected void center(boolean vertical, boolean horizontal, boolean animate) {
    if (mBitmap == null)
        return;//from  w  ww . j  a  v  a  2  s  .c  om

    Matrix m = getImageViewMatrix();

    float[] topLeft = new float[] { 0, 0 };
    float[] botRight = new float[] { mBitmap.getWidth(), mBitmap.getHeight() };

    translatePoint(m, topLeft);
    translatePoint(m, botRight);

    float height = botRight[1] - topLeft[1];
    float width = botRight[0] - topLeft[0];

    float deltaX = 0, deltaY = 0;

    if (vertical) {
        int viewHeight = getHeight();
        if (height < viewHeight) {
            deltaY = (viewHeight - height) / 2 - topLeft[1];
        } else if (topLeft[1] > 0) {
            deltaY = -topLeft[1];
        } else if (botRight[1] < viewHeight) {
            deltaY = getHeight() - botRight[1];
        }
    }

    if (horizontal) {
        int viewWidth = getWidth();
        if (width < viewWidth) {
            deltaX = (viewWidth - width) / 2 - topLeft[0];
        } else if (topLeft[0] > 0) {
            deltaX = -topLeft[0];
        } else if (botRight[0] < viewWidth) {
            deltaX = viewWidth - botRight[0];
        }
    }

    postTranslate(deltaX, deltaY);
    if (animate) {
        Animation a = new TranslateAnimation(-deltaX, 0, -deltaY, 0);
        a.setStartTime(SystemClock.elapsedRealtime());
        a.setDuration(250);
        setAnimation(a);
    }
    setImageMatrix(getImageViewMatrix());
}

From source file:de.Maxr1998.xposed.maxlock.ui.settings.appslist.AppListAdapter.java

@Override
public void onBindViewHolder(final AppsListViewHolder hld, final int position) {
    final String sTitle = (String) mItemList.get(position).get("title");
    final String key = (String) mItemList.get(position).get("key");
    final Drawable dIcon = (Drawable) mItemList.get(position).get("icon");

    hld.appName.setText(sTitle);/*from  ww  w.j  a va 2s. com*/
    hld.appIcon.setImageDrawable(dIcon);

    if (prefsPackages.getBoolean(key, false)) {
        hld.toggle.setChecked(true);
        hld.options.setVisibility(View.VISIBLE);
    } else {
        hld.toggle.setChecked(false);
        hld.options.setVisibility(View.GONE);
    }

    hld.appIcon.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (key.equals("com.android.packageinstaller"))
                return;
            Intent it = mContext.getPackageManager().getLaunchIntentForPackage(key);
            it.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
            mContext.startActivity(it);
        }
    });

    hld.options.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            // AlertDialog View
            // Fake die checkbox
            View checkBoxView = View.inflate(mContext, R.layout.per_app_settings, null);
            CheckBox fakeDie = (CheckBox) checkBoxView.findViewById(R.id.cb_fake_die);
            fakeDie.setChecked(prefsPackages.getBoolean(key + "_fake", false));
            fakeDie.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    CheckBox cb = (CheckBox) v;
                    boolean value = cb.isChecked();
                    prefsPackages.edit().putBoolean(key + "_fake", value).commit();
                }
            });
            // Custom password checkbox
            CheckBox customPassword = (CheckBox) checkBoxView.findViewById(R.id.cb_custom_pw);
            customPassword.setChecked(prefsPerApp.contains(key));
            customPassword.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    CheckBox cb = (CheckBox) v;
                    boolean checked = cb.isChecked();
                    if (checked) {
                        dialog.dismiss();
                        final AlertDialog.Builder choose_lock = new AlertDialog.Builder(mContext);
                        CharSequence[] cs = new CharSequence[] {
                                mContext.getString(R.string.pref_locking_type_password),
                                mContext.getString(R.string.pref_locking_type_pin),
                                mContext.getString(R.string.pref_locking_type_knockcode),
                                mContext.getString(R.string.pref_locking_type_pattern) };
                        choose_lock.setItems(cs, new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialogInterface, int i) {
                                dialogInterface.dismiss();
                                Fragment frag = new Fragment();
                                switch (i) {
                                case 0:
                                    Util.setPassword(mContext, key);
                                    break;
                                case 1:
                                    frag = new PinSetupFragment();
                                    break;
                                case 2:
                                    frag = new KnockCodeSetupFragment();
                                    break;
                                case 3:
                                    Intent intent = new Intent(LockPatternActivity.ACTION_CREATE_PATTERN, null,
                                            mContext, LockPatternActivity.class);
                                    mFragment.startActivityForResult(intent, Util.getPatternCode(position));
                                    break;
                                }
                                if (i == 1 || i == 2) {
                                    Bundle b = new Bundle(1);
                                    b.putString(Common.INTENT_EXTRAS_CUSTOM_APP, key);
                                    frag.setArguments(b);
                                    ((SettingsActivity) mContext).getSupportFragmentManager().beginTransaction()
                                            .replace(R.id.frame_container, frag).addToBackStack(null).commit();
                                }
                            }
                        }).show();
                    } else
                        prefsPerApp.edit().remove(key).remove(key + Common.APP_KEY_PREFERENCE).apply();

                }
            });
            // Finish dialog
            dialog = new AlertDialog.Builder(mContext)
                    .setTitle(mContext.getString(R.string.dialog_title_settings)).setIcon(dIcon)
                    .setView(checkBoxView)
                    .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dlg, int id) {
                            dlg.dismiss();
                        }
                    }).setNeutralButton(R.string.dialog_button_exclude_activities,
                            new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialogInterface, int i) {
                                    new ActivityLoader().execute(key);
                                }
                            })
                    .show();
        }
    });
    hld.toggle.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            RadioButton rb = (RadioButton) v;
            boolean value = prefsPackages.getBoolean(key, false);

            if (!value) {
                prefsPackages.edit().putBoolean(key, true).commit();
                AnimationSet anim = new AnimationSet(true);
                anim.addAnimation(AnimationUtils.loadAnimation(mContext, R.anim.appslist_settings_rotate));
                anim.addAnimation(AnimationUtils.loadAnimation(mContext, R.anim.appslist_settings_translate));
                hld.options.startAnimation(anim);
                hld.options.setVisibility(View.VISIBLE);
                rb.setChecked(true);
            } else {
                prefsPackages.edit().remove(key).commit();
                rb.setChecked(true);

                AnimationSet animOut = new AnimationSet(true);
                animOut.addAnimation(
                        AnimationUtils.loadAnimation(mContext, R.anim.appslist_settings_rotate_out));
                animOut.addAnimation(
                        AnimationUtils.loadAnimation(mContext, R.anim.appslist_settings_translate_out));
                animOut.setAnimationListener(new Animation.AnimationListener() {
                    @Override
                    public void onAnimationStart(Animation animation) {

                    }

                    @Override
                    public void onAnimationEnd(Animation animation) {
                        animation = new TranslateAnimation(0.0f, 0.0f, 0.0f, 0.0f);
                        animation.setDuration(1);
                        hld.options.startAnimation(animation);
                        hld.options.setVisibility(View.GONE);
                        hld.options.clearAnimation();
                    }

                    @Override
                    public void onAnimationRepeat(Animation animation) {

                    }
                });
                hld.options.startAnimation(animOut);
            }

            notifyDataSetChanged();
        }

    });
}

From source file:com.breadwallet.tools.animation.BRAnimator.java

/**
 * Animates the fragment transition on button_regular_blue "Settings" pressed
 *//*from   w ww  . jav  a  2 s . co m*/
public static void animateSlideToLeft(final MainActivity context, final Fragment to,
        Fragment previousFragment) {
    try {
        if (!checkTheHorizontalSlideAvailability())
            return;
        level++;
        if (level > 1)
            context.setBurgerButtonImage(BRConstants.BACK);
        FragmentTransaction fragmentTransaction = context.getFragmentManager().beginTransaction();
        fragmentTransaction.replace(R.id.main_layout, to, to.getClass().getName());
        if (previousFragment != null)
            previous.add(previousFragment);
        fragmentTransaction.commit();
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                TranslateAnimation trans = new TranslateAnimation(MainActivity.screenParametersPoint.x, 0, 0,
                        0);
                trans.setDuration(horizontalSlideDuration);
                trans.setInterpolator(new DecelerateOvershootInterpolator(1f, 0.5f));
                View view = to.getView();
                if (view != null)
                    view.startAnimation(trans);
            }
        }, 1);
    } catch (Exception e) {
        e.printStackTrace();
    }

}

From source file:com.mappn.gfan.ui.HomeTabActivity.java

@Override
public void onTabChanged(String tabId) {

    // ?//from ww w.j  a  v  a2s . c om
    if (TAB_APP.equals(tabId)) {
        Utils.trackEvent(getApplicationContext(), Constants.GROUP_4, Constants.CLICK_MANAGER_TAB);
    } else if (TAB_CATEGORY.equals(tabId)) {
        Utils.trackEvent(getApplicationContext(), Constants.GROUP_4, Constants.CLICK_CATEGORY_TAB);
    } else if (TAB_RANK.equals(tabId)) {
        Utils.trackEvent(getApplicationContext(), Constants.GROUP_4, Constants.CLICK_RANK_TAB);
    } else if (TAB_HOME.equals(tabId)) {
        Utils.trackEvent(getApplicationContext(), Constants.GROUP_4, Constants.CLICK_HOME_TAB);
    }
    final View tab = getTabHost().getCurrentTabView();
    final int endX = tab.getLeft();

    final TranslateAnimation animation = new TranslateAnimation(mStartX, endX, 0, 0);
    animation.setDuration(200);
    animation.setFillAfter(true);
    if (mMover == null) {
        initTabAnimationParameter();
    }
    mMover.startAnimation(animation);
    mStartX = endX;
}

From source file:net.xisberto.work_schedule.alarm.AlarmMessageActivity.java

@Override
public boolean onTouch(View view, MotionEvent event) {
    if (event.getPointerCount() > 1) {
        return super.onTouchEvent(event);
    }//  w w  w .j a  v  a2s  . c o m

    RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) view.getLayoutParams();

    int action = MotionEventCompat.getActionMasked(event);
    if (view.getId() == R.id.frame_bottom || view.getId() == R.id.frame_top) {
        switch (action) {
        case MotionEvent.ACTION_DOWN:
            initialPoint = event.getRawY();
            moving = true;
            break;
        case MotionEvent.ACTION_MOVE:
            if (moving) {
                hinter.interrupt();
                currentPoint = event.getRawY();

                DisplayMetrics displayMetrics = new DisplayMetrics();
                getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
                int screenHeight = displayMetrics.heightPixels;

                if (view.getId() == R.id.frame_top) {
                    int new_margin = (int) (currentPoint - initialPoint);
                    params.topMargin = (new_margin > 0) ? new_margin : 0;
                    if ((new_margin > (screenHeight / 3)) && (!isFinishing())) {
                        snoozeAlarm();
                        break;
                    }
                } else {
                    int new_margin = (int) (initialPoint - currentPoint);
                    params.bottomMargin = (new_margin > 0) ? new_margin : 0;
                    if ((new_margin > (screenHeight / 3)) && (!isFinishing())) {
                        cancelAlarm();
                        break;
                    }
                }
                view.setLayoutParams(params);
                view.invalidate();
            }
            break;
        case MotionEvent.ACTION_UP:
            initialPoint = 0;
            TranslateAnimation ta;
            if (view.getId() == R.id.frame_top) {
                ta = new TranslateAnimation(0, 0, params.topMargin, 0);
                params.topMargin = 0;
            } else {
                ta = new TranslateAnimation(0, 0, -params.bottomMargin, 0);
                params.bottomMargin = 0;
            }
            ta.setDuration(100);
            view.setLayoutParams(params);
            view.startAnimation(ta);
            moving = false;
            startHinter();
            break;
        default:
            return super.onTouchEvent(event);
        }
    }
    return true;
}

From source file:it.imwatch.nfclottery.dialogs.InsertContactDialog.java

/**
 * Hides the email error textview.//www  .j a  va  2s  . co m
 */
private void hideEmailError() {
    mEmailErrorState = 0;

    // Re-enable the positive button of the dialog iif the name is also valid
    setFormIsValidated(mNameErrorState == 0);

    if (mEmailErrorTextView.getVisibility() == View.GONE) {
        return; // No need to animate out the textview, it's already gone
    }

    AnimationSet fadeOutSet = new AnimationSet(true);
    fadeOutSet.addAnimation(new AlphaAnimation(1f, 0f));
    fadeOutSet.addAnimation(new TranslateAnimation(0f, 0f, 0f, -mErrorAnimTranslateY));
    fadeOutSet.setDuration(300);
    fadeOutSet.setAnimationListener(new Animation.AnimationListener() {
        @Override
        public void onAnimationStart(Animation animation) {
            // Don't care
        }

        @Override
        public void onAnimationEnd(Animation animation) {
            mEmailErrorTextView.setVisibility(View.GONE);
        }

        @Override
        public void onAnimationRepeat(Animation animation) {
            // Don't care
        }
    });

    mEmailErrorTextView.startAnimation(fadeOutSet);
}

From source file:com.breadwallet.tools.animation.BRAnimator.java

public static void animateSlideToRight(final MainActivity context) {
    try {/*from   w  w w . j  a  va  2  s  .c  o m*/
        if (!checkTheHorizontalSlideAvailability())
            return;
        final Fragment tmp = previous.pop();
        level--;
        if (level < 1)
            context.setBurgerButtonImage(BRConstants.BURGER);
        if (level == 1)
            context.setBurgerButtonImage(BRConstants.CLOSE);
        FragmentTransaction fragmentTransaction = context.getFragmentManager().beginTransaction();
        fragmentTransaction.replace(R.id.main_layout, tmp, tmp.getClass().getName());
        fragmentTransaction.commit();
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                TranslateAnimation trans = new TranslateAnimation(-MainActivity.screenParametersPoint.x, 0, 0,
                        0);
                trans.setDuration(horizontalSlideDuration);
                trans.setInterpolator(new DecelerateOvershootInterpolator(1f, 0.5f));
                View view = tmp.getView();
                if (view != null)
                    view.startAnimation(trans);
            }
        }, 1);
    } catch (Exception e) {
        e.printStackTrace();
    }

}

From source file:com.breadwallet.presenter.activities.IntroActivity.java

private void animateSlide(final Fragment from, final Fragment to, int direction) {
    if (to instanceof IntroRecoverWalletFragment) {
        if (Utils.isUsingCustomInputMethod(to.getActivity()))
            ((IntroRecoverWalletFragment) to).disableEditText();
    }/*  w w  w . j  av  a2 s  .c om*/
    int screenWidth = screenParametersPoint.x;
    int screenHeigth = screenParametersPoint.y;

    showHideFragments(from, to);
    TranslateAnimation transFrom = direction == RIGHT ? new TranslateAnimation(0, -screenWidth, 0, 0)
            : new TranslateAnimation(0, screenWidth, 0, 0);
    transFrom.setDuration(BRAnimator.horizontalSlideDuration);
    transFrom.setInterpolator(new DecelerateOvershootInterpolator(1f, 0.5f));
    View fromView = from.getView();
    if (fromView != null)
        fromView.startAnimation(transFrom);
    TranslateAnimation transTo = direction == RIGHT ? new TranslateAnimation(screenWidth, 0, 0, 0)
            : new TranslateAnimation(-screenWidth, 0, 0, 0);
    transTo.setDuration(BRAnimator.horizontalSlideDuration);
    transTo.setInterpolator(new DecelerateOvershootInterpolator(1f, 0.5f));
    transTo.setAnimationListener(new Animation.AnimationListener() {
        @Override
        public void onAnimationStart(Animation animation) {

        }

        @Override
        public void onAnimationEnd(Animation animation) {
            showHideFragments(to);
        }

        @Override
        public void onAnimationRepeat(Animation animation) {

        }
    });
    View toView = to.getView();
    if (toView != null)
        toView.startAnimation(transTo);
}