Example usage for android.view.animation LinearInterpolator LinearInterpolator

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

Introduction

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

Prototype

public LinearInterpolator() 

Source Link

Usage

From source file:io.github.carlorodriguez.morningritual.MainActivity.java

private ObjectAnimator setAnimation(final ProgressBar progressBar, final TextView title, final TextView quote,
        final MorningRitual morningRitual, final FloatingActionButton fab) {
    final ObjectAnimator animator = ObjectAnimator.ofInt(progressBar, "progress", 0, 200000);

    animator.setDuration(getStepDurationInMillis(morningRitual));

    animator.setInterpolator(new LinearInterpolator());

    animator.addListener(new Animator.AnimatorListener() {
        @Override/*from  ww w .  j av  a2 s  .  c  om*/
        public void onAnimationStart(Animator animation) {

        }

        @Override
        public void onAnimationEnd(Animator animation) {
            notifyStepFinish();

            morningRitual.nextStep();

            setNextMorningRitualStep(progressBar, title, quote, morningRitual, fab);
        }

        @Override
        public void onAnimationCancel(Animator animation) {

        }

        @Override
        public void onAnimationRepeat(Animator animation) {

        }
    });

    return animator;
}

From source file:cn.oddcloud.www.navigationtabbar.ntb.NavigationTabBar.java

@SuppressWarnings("ResourceAsColor")
public NavigationTabBar(final Context context, final AttributeSet attrs, final int defStyleAttr) {
    super(context, attrs, defStyleAttr);
    //Init NTB/*from   w w w.  java  2 s  .c  o m*/

    // Always draw
    setWillNotDraw(false);
    // Speed and fix for pre 17 API
    ViewCompat.setLayerType(this, ViewCompat.LAYER_TYPE_SOFTWARE, null);
    setLayerType(LAYER_TYPE_SOFTWARE, null);

    final TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.NavigationTabBar);
    try {
        setIsTitled(typedArray.getBoolean(R.styleable.NavigationTabBar_ntb_titled, false));
        setIsBadged(typedArray.getBoolean(R.styleable.NavigationTabBar_ntb_badged, false));
        setIsScaled(typedArray.getBoolean(R.styleable.NavigationTabBar_ntb_scaled, true));
        setIsTinted(typedArray.getBoolean(R.styleable.NavigationTabBar_ntb_tinted, true));
        setIsSwiped(typedArray.getBoolean(R.styleable.NavigationTabBar_ntb_swiped, true));
        setTitleSize(typedArray.getDimension(R.styleable.NavigationTabBar_ntb_title_size, AUTO_SIZE));
        setIsBadgeUseTypeface(
                typedArray.getBoolean(R.styleable.NavigationTabBar_ntb_badge_use_typeface, false));

        setTitleMode(typedArray.getInt(R.styleable.NavigationTabBar_ntb_title_mode, TitleMode.ALL_INDEX));
        setBadgeSize(typedArray.getDimension(R.styleable.NavigationTabBar_ntb_badge_size, AUTO_SIZE));
        setBadgePosition(
                typedArray.getInt(R.styleable.NavigationTabBar_ntb_badge_position, BadgePosition.RIGHT_INDEX));
        setBadgeGravity(
                typedArray.getInt(R.styleable.NavigationTabBar_ntb_badge_gravity, BadgeGravity.TOP_INDEX));
        setBadgeBgColor(typedArray.getColor(R.styleable.NavigationTabBar_ntb_badge_bg_color, AUTO_COLOR));
        setBadgeTitleColor(typedArray.getColor(R.styleable.NavigationTabBar_ntb_badge_title_color, AUTO_COLOR));

        setTypeface(typedArray.getString(R.styleable.NavigationTabBar_ntb_typeface));
        setInactiveColor(
                typedArray.getColor(R.styleable.NavigationTabBar_ntb_inactive_color, DEFAULT_INACTIVE_COLOR));
        setActiveColor(
                typedArray.getColor(R.styleable.NavigationTabBar_ntb_active_color, DEFAULT_ACTIVE_COLOR));
        setBgColor(typedArray.getColor(R.styleable.NavigationTabBar_ntb_bg_color, DEFAULT_BG_COLOR));
        setAnimationDuration(typedArray.getInteger(R.styleable.NavigationTabBar_ntb_animation_duration,
                DEFAULT_ANIMATION_DURATION));
        setCornersRadius(typedArray.getDimension(R.styleable.NavigationTabBar_ntb_corners_radius, 0.0F));
        setIconSizeFraction(
                typedArray.getFloat(R.styleable.NavigationTabBar_ntb_icon_size_fraction, AUTO_SCALE));

        // Init animator
        mAnimator.setFloatValues(MIN_FRACTION, MAX_FRACTION);
        mAnimator.setInterpolator(new LinearInterpolator());
        mAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(final ValueAnimator animation) {
                updateIndicatorPosition((Float) animation.getAnimatedValue());
            }
        });

        // Set preview models
        if (isInEditMode()) {
            // Get preview colors
            String[] previewColors = null;
            try {
                final int previewColorsId = typedArray
                        .getResourceId(R.styleable.NavigationTabBar_ntb_preview_colors, 0);
                previewColors = previewColorsId == 0 ? null
                        : typedArray.getResources().getStringArray(previewColorsId);
            } catch (Exception exception) {
                previewColors = null;
                exception.printStackTrace();
            } finally {
                if (previewColors == null)
                    previewColors = typedArray.getResources().getStringArray(R.array.default_preview);

                for (String previewColor : previewColors)
                    mModels.add(new Model.Builder(null, Color.parseColor(previewColor)).build());
                requestLayout();
            }
        }
    } finally {
        typedArray.recycle();
    }
}

From source file:com.cocoa.cocoautils.widget.navigationtabbar.ntb.NavigationTabBar.java

@SuppressWarnings("ResourceAsColor")
public NavigationTabBar(final Context context, final AttributeSet attrs, final int defStyleAttr) {
    super(context, attrs, defStyleAttr);
    //Init NTB//www  .  j  av a 2  s  .  com

    // Always draw
    setWillNotDraw(false);
    // Speed and fix for pre 17 API
    ViewCompat.setLayerType(this, ViewCompat.LAYER_TYPE_SOFTWARE, null);
    setLayerType(LAYER_TYPE_SOFTWARE, null);

    final TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.NavigationTabBar);
    try {
        setIsTitled(typedArray.getBoolean(R.styleable.NavigationTabBar_ntb_titled, false));
        setIsBadged(typedArray.getBoolean(R.styleable.NavigationTabBar_ntb_badged, false));
        setIsScaled(typedArray.getBoolean(R.styleable.NavigationTabBar_ntb_scaled, true));
        setIsTinted(typedArray.getBoolean(R.styleable.NavigationTabBar_ntb_tinted, true));
        setIsSwiped(typedArray.getBoolean(R.styleable.NavigationTabBar_ntb_swiped, true));
        setTitleSize(typedArray.getDimension(R.styleable.NavigationTabBar_ntb_title_size, -2f));
        setIsBadgeUseTypeface(
                typedArray.getBoolean(R.styleable.NavigationTabBar_ntb_badge_use_typeface, false));

        setTitleMode(typedArray.getInt(R.styleable.NavigationTabBar_ntb_title_mode, TitleMode.ALL_INDEX));
        setBadgeSize(typedArray.getDimension(R.styleable.NavigationTabBar_ntb_badge_size, -2f));
        setBadgePosition(
                typedArray.getInt(R.styleable.NavigationTabBar_ntb_badge_position, BadgePosition.RIGHT_INDEX));
        setBadgeGravity(
                typedArray.getInt(R.styleable.NavigationTabBar_ntb_badge_gravity, BadgeGravity.TOP_INDEX));
        setBadgeBgColor(typedArray.getColor(R.styleable.NavigationTabBar_ntb_badge_bg_color, AUTO_COLOR));
        setBadgeTitleColor(typedArray.getColor(R.styleable.NavigationTabBar_ntb_badge_title_color, AUTO_COLOR));

        setTypeface(typedArray.getString(R.styleable.NavigationTabBar_ntb_typeface));
        setInactiveColor(
                typedArray.getColor(R.styleable.NavigationTabBar_ntb_inactive_color, DEFAULT_INACTIVE_COLOR));
        setActiveColor(
                typedArray.getColor(R.styleable.NavigationTabBar_ntb_active_color, DEFAULT_ACTIVE_COLOR));
        setBgColor(typedArray.getColor(R.styleable.NavigationTabBar_ntb_bg_color, DEFAULT_BG_COLOR));
        setAnimationDuration(typedArray.getInteger(R.styleable.NavigationTabBar_ntb_animation_duration,
                DEFAULT_ANIMATION_DURATION));
        setCornersRadius(typedArray.getDimension(R.styleable.NavigationTabBar_ntb_corners_radius, 0.0F));
        setIconSizeFraction(
                typedArray.getFloat(R.styleable.NavigationTabBar_ntb_icon_size_fraction, AUTO_SCALE));

        // Init animator
        mAnimator.setFloatValues(MIN_FRACTION, MAX_FRACTION);
        mAnimator.setInterpolator(new LinearInterpolator());
        mAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(final ValueAnimator animation) {
                updateIndicatorPosition((Float) animation.getAnimatedValue());
            }
        });

        // Set preview models
        if (isInEditMode()) {
            // Get preview colors
            String[] previewColors = null;
            try {
                final int previewColorsId = typedArray
                        .getResourceId(R.styleable.NavigationTabBar_ntb_preview_colors, 0);
                previewColors = previewColorsId == 0 ? null
                        : typedArray.getResources().getStringArray(previewColorsId);
            } catch (Exception exception) {
                previewColors = null;
                exception.printStackTrace();
            } finally {
                if (previewColors == null)
                    previewColors = typedArray.getResources().getStringArray(R.array.default_preview);

                for (String previewColor : previewColors)
                    mModels.add(new Model.Builder(null, Color.parseColor(previewColor)).build());
                requestLayout();
            }
        }
    } finally {
        typedArray.recycle();
    }
}

From source file:devlight.io.library.ntb.NavigationTabBar.java

@SuppressWarnings({ "ResourceAsColor", "ResourceType" })
public NavigationTabBar(final Context context, final AttributeSet attrs, final int defStyleAttr) {
    super(context, attrs, defStyleAttr);
    //Init NTB//w  ww . j av  a2 s.c  o m

    // Always draw
    setWillNotDraw(false);
    // Speed and fix for pre 17 API
    ViewCompat.setLayerType(this, ViewCompat.LAYER_TYPE_SOFTWARE, null);
    setLayerType(LAYER_TYPE_SOFTWARE, null);

    final TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.NavigationTabBar);
    try {
        setIsTitled(typedArray.getBoolean(R.styleable.NavigationTabBar_ntb_titled, false));
        setIsBadged(typedArray.getBoolean(R.styleable.NavigationTabBar_ntb_badged, false));
        setIsScaled(typedArray.getBoolean(R.styleable.NavigationTabBar_ntb_scaled, true));
        setIsTinted(typedArray.getBoolean(R.styleable.NavigationTabBar_ntb_tinted, true));
        setIsSwiped(typedArray.getBoolean(R.styleable.NavigationTabBar_ntb_swiped, true));
        setTitleSize(typedArray.getDimension(R.styleable.NavigationTabBar_ntb_title_size, AUTO_SIZE));
        setIsBadgeUseTypeface(
                typedArray.getBoolean(R.styleable.NavigationTabBar_ntb_badge_use_typeface, false));

        setTitleMode(typedArray.getInt(R.styleable.NavigationTabBar_ntb_title_mode, TitleMode.ALL_INDEX));
        setBadgeSize(typedArray.getDimension(R.styleable.NavigationTabBar_ntb_badge_size, AUTO_SIZE));
        setBadgePosition(
                typedArray.getInt(R.styleable.NavigationTabBar_ntb_badge_position, BadgePosition.RIGHT_INDEX));
        setBadgeGravity(
                typedArray.getInt(R.styleable.NavigationTabBar_ntb_badge_gravity, BadgeGravity.TOP_INDEX));
        setBadgeBgColor(typedArray.getColor(R.styleable.NavigationTabBar_ntb_badge_bg_color, AUTO_COLOR));
        setBadgeTitleColor(typedArray.getColor(R.styleable.NavigationTabBar_ntb_badge_title_color, AUTO_COLOR));

        setTypeface(typedArray.getString(R.styleable.NavigationTabBar_ntb_typeface));
        setInactiveColor(
                typedArray.getColor(R.styleable.NavigationTabBar_ntb_inactive_color, DEFAULT_INACTIVE_COLOR));
        setActiveColor(
                typedArray.getColor(R.styleable.NavigationTabBar_ntb_active_color, DEFAULT_ACTIVE_COLOR));
        setBgColor(typedArray.getColor(R.styleable.NavigationTabBar_ntb_bg_color, DEFAULT_BG_COLOR));
        setAnimationDuration(typedArray.getInteger(R.styleable.NavigationTabBar_ntb_animation_duration,
                DEFAULT_ANIMATION_DURATION));
        setCornersRadius(typedArray.getDimension(R.styleable.NavigationTabBar_ntb_corners_radius, 0.0F));
        setIconSizeFraction(
                typedArray.getFloat(R.styleable.NavigationTabBar_ntb_icon_size_fraction, AUTO_SCALE));

        // Init animator
        mAnimator.setFloatValues(MIN_FRACTION, MAX_FRACTION);
        mAnimator.setInterpolator(new LinearInterpolator());
        mAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(final ValueAnimator animation) {
                updateIndicatorPosition((Float) animation.getAnimatedValue());
            }
        });

        // Set preview models
        if (isInEditMode()) {
            // Get preview colors
            String[] previewColors = null;
            try {
                final int previewColorsId = typedArray
                        .getResourceId(R.styleable.NavigationTabBar_ntb_preview_colors, 0);
                previewColors = previewColorsId == 0 ? null
                        : typedArray.getResources().getStringArray(previewColorsId);
            } catch (Exception exception) {
                previewColors = null;
                exception.printStackTrace();
            } finally {
                if (previewColors == null)
                    previewColors = typedArray.getResources().getStringArray(R.array.default_preview);

                for (String previewColor : previewColors)
                    mModels.add(new Model.Builder(null, Color.parseColor(previewColor)).build());
                requestLayout();
            }
        }
    } finally {
        typedArray.recycle();
    }
}

From source file:org.kontalk.ui.AudioDialog.java

private void animate(final CircularSeekBar progressBar, final AnimatorListener listener, final float progress,
        final float maxProgress, final long duration) {
    mProgressBarAnimator = ObjectAnimator.ofFloat(progressBar, "progress", maxProgress);
    mProgressBarAnimator.setInterpolator(new LinearInterpolator());
    mProgressBarAnimator.setDuration(duration);

    mProgressBarAnimator.addListener(new AnimatorListener() {

        @Override//from   w w  w .java 2  s .  com
        public void onAnimationCancel(final Animator animation) {
        }

        @Override
        public void onAnimationEnd(final Animator animation) {
            if (mStatus == STATUS_RECORDING)
                stopRecord();
        }

        @Override
        public void onAnimationRepeat(final Animator animation) {
        }

        @Override
        public void onAnimationStart(final Animator animation) {
            progressBar.setOnTouchListener(new OnTouchListener() {
                @Override
                public boolean onTouch(View v, MotionEvent event) {
                    if (mStatus == STATUS_RECORDING) {
                        return true;
                    }
                    if (event.getAction() == android.view.MotionEvent.ACTION_DOWN
                            && (mStatus == STATUS_PLAYING || mStatus == STATUS_PAUSED)) {
                        progressBar.setPointerAlpha(135);
                        progressBar.setPointerAlphaOnTouch(100);
                        mCheckSeek = mStatus;
                        pauseAudio();
                    } else if (event.getAction() == android.view.MotionEvent.ACTION_UP) {
                        progressBar.setPointerAlpha(0);
                        progressBar.setPointerAlphaOnTouch(0);
                        mData.getPlayer().seekTo(mPlayerSeekTo);
                        if (mCheckSeek == STATUS_PLAYING)
                            resumeAudio();
                    } else if (event.getAction() == android.view.MotionEvent.ACTION_MOVE
                            && (mStatus == STATUS_PLAYING || mStatus == STATUS_PAUSED)) {
                        mPlayerSeekTo = (int) (progressBar.getProgress() / mTimeCircle);
                        mTimeTxt.setText(DateUtils.formatElapsedTime(mPlayerSeekTo / 1000));
                    }
                    return false;
                }
            });
        }
    });
    if (listener != null) {
        mProgressBarAnimator.addListener(listener);
    }
    mProgressBarAnimator.addUpdateListener(new AnimatorUpdateListener() {
        public void onAnimationUpdate(final ValueAnimator animation) {
            progressBar.setProgress((Float) animation.getAnimatedValue());
            long time = animation.getCurrentPlayTime();
            mTimeTxt.setText(DateUtils.formatElapsedTime(time / 1000));
        }
    });
    progressBar.setProgress(progress);
    mProgressBarAnimator.start();
    if (progress > 0) {
        mProgressBarAnimator.setCurrentPlayTime((long) (progress * MAX_AUDIO_DURATION / 100));
    }
}

From source file:com.folioreader.activity.FolioActivity.java

private void toolbarAnimateHide() {
    mToolbar.animate().translationY(-mToolbar.getHeight()).setInterpolator(new LinearInterpolator())
            .setDuration(180).setListener(new AnimatorListenerAdapter() {
                @Override//w  ww. j a  va2s . c  o  m
                public void onAnimationEnd(Animator animation) {
                    toolbarSetElevation(0);
                }
            });
    mIsActionBarVisible = false;
}

From source file:com.itude.mobile.mobbl.core.view.components.tabbar.MBDefaultActionBarBuilder.java

private ImageView getRotationImage() {
    RotateAnimation rotateAnimation = new RotateAnimation(0, 360, Animation.RELATIVE_TO_SELF, 0.5f,
            Animation.RELATIVE_TO_SELF, 0.5f);
    rotateAnimation.setDuration(1000L);//from   ww w  . j  a  v a 2s  .  c om
    rotateAnimation.setRepeatMode(Animation.INFINITE);
    rotateAnimation.setRepeatCount(Animation.INFINITE);
    rotateAnimation.setFillEnabled(false);
    rotateAnimation.setInterpolator(new LinearInterpolator());

    Drawable drawable = MBResourceService.getInstance().getImageByID(_refreshToolDef.getIcon());
    ImageView rotationImage = new ImageView(_context);
    rotationImage.setImageDrawable(drawable);
    rotationImage.setAnimation(rotateAnimation);

    return rotationImage;
}

From source file:io.plaidapp.core.ui.transitions.ReflowText.java

/**
 * Create Animators to transition each run of text from start to end position and size.
 */// w  w w  .ja v  a2  s.  c om
@NonNull
private List<Animator> createRunAnimators(View view, ReflowData startData, ReflowData endData, Bitmap startText,
        Bitmap endText, List<Run> runs) {
    List<Animator> animators = new ArrayList<>(runs.size());
    int dx = startData.bounds.left - endData.bounds.left;
    int dy = startData.bounds.top - endData.bounds.top;
    long startDelay = 0L;
    // move text closest to the destination first i.e. loop forward or backward over the runs
    boolean upward = startData.bounds.centerY() > endData.bounds.centerY();
    boolean first = true;
    boolean lastRightward = true;
    LinearInterpolator linearInterpolator = new LinearInterpolator();

    for (int i = upward ? 0 : runs.size() - 1; ((upward && i < runs.size())
            || (!upward && i >= 0)); i += (upward ? 1 : -1)) {
        Run run = runs.get(i);

        // skip text runs which aren't visible in either state
        if (!run.startVisible && !run.endVisible)
            continue;

        // create & position the drawable which displays the run; add it to the overlay.
        SwitchDrawable drawable = new SwitchDrawable(startText, run.start, startData.textSize, endText, run.end,
                endData.textSize);
        drawable.setBounds(run.start.left + dx, run.start.top + dy, run.start.right + dx,
                run.start.bottom + dy);
        view.getOverlay().add(drawable);

        PropertyValuesHolder topLeft = PropertyValuesHolder.ofObject(SwitchDrawable.TOP_LEFT, null,
                getPathMotion().getPath(run.start.left + dx, run.start.top + dy, run.end.left, run.end.top));
        PropertyValuesHolder width = PropertyValuesHolder.ofInt(SwitchDrawable.WIDTH, run.start.width(),
                run.end.width());
        PropertyValuesHolder height = PropertyValuesHolder.ofInt(SwitchDrawable.HEIGHT, run.start.height(),
                run.end.height());
        // the progress property drives the switching behaviour
        PropertyValuesHolder progress = PropertyValuesHolder.ofFloat(SwitchDrawable.PROGRESS, 0f, 1f);
        Animator runAnim = ObjectAnimator.ofPropertyValuesHolder(drawable, topLeft, width, height, progress);

        boolean rightward = run.start.centerX() + dx < run.end.centerX();
        if ((run.startVisible && run.endVisible) && !first && rightward != lastRightward) {
            // increase the start delay (by a decreasing amount) for the next run
            // (if it's visible throughout) to stagger the movement and try to minimize overlaps
            startDelay += staggerDelay;
            staggerDelay *= STAGGER_DECAY;
        }
        lastRightward = rightward;
        first = false;

        runAnim.setStartDelay(startDelay);
        long animDuration = Math.max(minDuration, duration - (startDelay / 2));
        runAnim.setDuration(animDuration);
        animators.add(runAnim);

        if (run.startVisible != run.endVisible) {
            // if run is appearing/disappearing then fade it in/out
            ObjectAnimator fade = ObjectAnimator.ofInt(drawable, SwitchDrawable.ALPHA,
                    run.startVisible ? OPAQUE : TRANSPARENT, run.endVisible ? OPAQUE : TRANSPARENT);
            fade.setDuration((duration + startDelay) / 2);
            if (!run.startVisible) {
                drawable.setAlpha(TRANSPARENT);
                fade.setStartDelay((duration + startDelay) / 2);
            } else {
                fade.setStartDelay(startDelay);
            }
            animators.add(fade);
        } else {
            // slightly fade during transition to minimize movement
            ObjectAnimator fade = ObjectAnimator.ofInt(drawable, SwitchDrawable.ALPHA, OPAQUE,
                    OPACITY_MID_TRANSITION, OPAQUE);
            fade.setStartDelay(startDelay);
            fade.setDuration(duration + startDelay);
            fade.setInterpolator(linearInterpolator);
            animators.add(fade);
        }
    }
    return animators;
}

From source file:com.arlib.floatingsearchview.util.view.MenuView.java

/**
 * Shows all the menu items that were hidden by hideIfRoomItems(boolean withAnim)
 *
 * @param withAnim/*from   ww  w. ja  v  a  2s . c o m*/
 */
public void showIfRoomItems(boolean withAnim) {

    if (mMenu == -1)
        return;

    cancelChildAnimListAndClear();

    if (mMenuItems.isEmpty())
        return;

    anims = new ArrayList<>();

    for (int i = 0; i < getChildCount(); i++) {

        final View currentView = getChildAt(i);

        if (i < mActionItems.size()) {
            ImageView action = (ImageView) currentView;
            final MenuItem actionItem = mActionItems.get(i);
            action.setImageDrawable(Util.setIconColor(actionItem.getIcon(), mActionIconColor));

            action.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {

                    if (mMenuCallback != null)
                        mMenuCallback.onMenuItemSelected(mMenuBuilder, actionItem);
                }
            });
        }

        //todo go over logic
        int animDuration = withAnim ? SHOW_IF_ROOM_ITEMS_ANIM_DURATION : 0;

        Interpolator interpolator = new DecelerateInterpolator();

        //todo check logic
        if (i > mActionShowAlwaysItems.size() - 1)
            interpolator = new LinearInterpolator();

        currentView.setClickable(true);
        anims.add(ViewPropertyObjectAnimator.animate(currentView).addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {

                currentView.setTranslationX(0);
            }
        }).setInterpolator(interpolator).setDuration(animDuration).translationX(0).get());
        anims.add(ViewPropertyObjectAnimator.animate(currentView).addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {

                currentView.setScaleX(1.0f);
            }
        }).setInterpolator(interpolator).setDuration(animDuration).scaleX(1.0f).get());
        anims.add(ViewPropertyObjectAnimator.animate(currentView).addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {

                currentView.setScaleY(1.0f);
            }
        }).setInterpolator(interpolator).setDuration(animDuration).scaleY(1.0f).get());
        anims.add(ViewPropertyObjectAnimator.animate(currentView).addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {

                currentView.setAlpha(1.0f);
            }
        }).setInterpolator(interpolator).setDuration(animDuration).alpha(1.0f).get());
    }

    AnimatorSet animSet = new AnimatorSet();

    //temporary, from laziness
    if (!withAnim)
        animSet.setDuration(0);
    animSet.playTogether(anims.toArray(new ObjectAnimator[anims.size()]));
    animSet.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {

            if (mOnVisibleWidthChanged != null)
                mOnVisibleWidthChanged.onVisibleWidthChanged(
                        (getChildCount() * (int) ACTION_DIMENSION_PX) - (mHasOverflow ? Util.dpToPx(8) : 0));
        }
    });
    animSet.start();

}

From source file:com.guardtrax.ui.screens.HomeScreen.java

public void onCreate(Bundle savedInstanceState) {
    ctx = this.getApplicationContext();

    super.onCreate(savedInstanceState);

    //restore saved instances if necessary
    if (savedInstanceState != null) {
        Toast.makeText(HomeScreen.this, savedInstanceState.getString("message"), Toast.LENGTH_LONG).show();

        GTConstants.darfileName = savedInstanceState.getString("darfileName");
        GTConstants.tarfileName = savedInstanceState.getString("tarfileName");
        GTConstants.trpfilename = savedInstanceState.getString("trpfilename");
        GTConstants.srpfileName = savedInstanceState.getString("srpfileName");
        Utility.setcurrentState(savedInstanceState.getString("currentState"));
        Utility.setsessionStart(savedInstanceState.getString("getsessionStart"));
        selectedCode = savedInstanceState.getString("selectedCode");
        lunchTime = savedInstanceState.getString("lunchTime");
        breakTime = savedInstanceState.getString("breakTime");
        signaturefileName = savedInstanceState.getString("signaturefileName");
        GTConstants.tourName = savedInstanceState.getString("tourName");
        tourTime = savedInstanceState.getString("tourTime");
        tourEnd = savedInstanceState.getLong("tourEnd");
        lunchoutLocation = savedInstanceState.getInt("lunchoutLocation");
        breakoutLocation = savedInstanceState.getInt("breakoutLocation");
        touritemNumber = savedInstanceState.getInt("touritemNumber");
        chekUpdate = savedInstanceState.getBoolean("chekUpdate");
        GTConstants.sendData = savedInstanceState.getBoolean("send_data");
        GTConstants.isTour = savedInstanceState.getBoolean("isTour");
        GTConstants.isGeoFence = savedInstanceState.getBoolean("isGeoFence");
    } else {//  w ww .  j a v a  2  s  .co  m
        //set the current state
        Utility.setcurrentState(GTConstants.offShift);

        //set the default startup code to start shift
        selectedCode = "start_shift";
    }

    /*
    //Determine screen size
     if ((getResources().getConfiguration().screenLayout &      Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_LARGE) {     
         Toast.makeText(this, "Large screen",Toast.LENGTH_LONG).show();
     }
     else if ((getResources().getConfiguration().screenLayout &      Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_NORMAL) {     
         Toast.makeText(this, "Normal sized screen" , Toast.LENGTH_LONG).show();
     } 
     else if ((getResources().getConfiguration().screenLayout &      Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_SMALL) {     
         Toast.makeText(this, "Small sized screen" , Toast.LENGTH_LONG).show();
     }
     else {
         Toast.makeText(this, "Screen size is neither large, normal or small" , Toast.LENGTH_LONG).show();
     }
             
      //initialize receiver to monitor for screen on / off
    /*
      IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_ON);
      filter.addAction(Intent.ACTION_SCREEN_OFF);
      BroadcastReceiver mReceiver = new ScreenReceiver();
      registerReceiver(mReceiver, filter);
      */

    setContentView(R.layout.homescreen);

    //Create object to call the Database class
    myDatabase = new GuardTraxDB(this);
    preferenceDB = new PreferenceDB(this);
    ftpdatabase = new ftpDataBase(this);
    gtDB = new GTParams(this);
    aDB = new accountsDB(this);
    trafficDB = new trafficDataBase(this);
    tourDB = new tourDataBase(this);

    //check for updates
    if (chekUpdate) {
        //reset the preference value
        chekUpdate = false;

        //check for application updates
        checkUpdate();
    }

    //initialize the message timer
    //initializeOnModeTimerEvent();

    //get the version number and set it in constants
    String version_num = "";

    PackageManager manager = this.getPackageManager();
    try {
        PackageInfo info = manager.getPackageInfo(this.getPackageName(), 0);
        version_num = info.versionName.toString();

    } catch (NameNotFoundException e) {
        version_num = "0.00.00";
    }
    GTConstants.version = version_num;

    //final TextView version = (TextView) findViewById(R.id.textVersion);
    //version.setText(version_num);

    //set up the animation
    animation.setDuration(500); // duration - half a second
    animation.setInterpolator(new LinearInterpolator()); // do not alter animation rate
    animation.setRepeatCount(Animation.INFINITE); // Repeat animation infinitely
    animation.setRepeatMode(Animation.REVERSE); // Reverse animation at the end so the button will fade back in

    buttonClick.setDuration(50); // duration - half a second
    buttonClick.setInterpolator(new LinearInterpolator()); // do not alter animation rate
    buttonClick.setRepeatCount(1); // Repeat animation once
    buttonClick.setRepeatMode(Animation.REVERSE); // Reverse animation at the end so the button will fade back in

    textWarning = (TextView) findViewById(R.id.txtWarning);
    textWarning.setWidth(500);
    textWarning.setGravity(Gravity.CENTER);

    //allow the text to be clicked if necessary 
    textWarning.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (GTConstants.isTour && GTConstants.tourName.length() > 1)
                displaytourInfo();
        }
    });

    //goto scan page button
    btn_scan_screen = (Button) findViewById(R.id.btn_goto_scan);

    btn_scan_screen.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            btn_scan_screen.startAnimation(buttonClick);

            //Utility.showScan(HomeScreen.this);
            scan_click(false);
        }
    });

    //goto report page button
    btn_report_screen = (Button) findViewById(R.id.btn_goto_report);
    btn_report_screen.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            btn_report_screen.startAnimation(buttonClick);

            report_click();
        }
    });

    //goto dial page button
    btn_dial_screen = (Button) findViewById(R.id.btn_goto_dial);
    btn_dial_screen.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            btn_dial_screen.startAnimation(buttonClick);

            dial_click();
        }
    });

    //microphone button
    btn_mic = (Button) findViewById(R.id.btn_mic);
    btn_mic.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            btn_mic.startAnimation(buttonClick);

            voice_click();
        }

    });

    //camera button
    btn_camera = (Button) findViewById(R.id.btn_camera);
    btn_camera.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            btn_camera.startAnimation(buttonClick);

            camera_click();
        }
    });

    //video button
    btn_video = (Button) findViewById(R.id.btn_video);
    btn_video.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            btn_video.startAnimation(buttonClick);

            video_click();
        }

    });

    // Register a callback to be invoked when this view is clicked. If this view is not clickable, it becomes clickable.
    btn_send = (Button) findViewById(R.id.btn_Send);
    btn_send.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            //prevent multiple fast clicking
            if (SystemClock.elapsedRealtime() - mLastClickTime < 2000)
                return;

            mLastClickTime = SystemClock.elapsedRealtime();

            incidentcodeSent = true;

            btn_send.startAnimation(buttonClick);

            //if start shift has not been sent then the device is in do not send data mode.  Warn the user 
            if (Utility.getcurrentState().equals(GTConstants.offShift) && !selectedCode.equals("start_shift")) {
                show_alert_title = "Error";
                show_alert_message = "You must start your shift!";
                showAlert(show_alert_title, show_alert_message, true);

                //set spinner back to start shift
                spinner.setSelection(0);
            } else {
                if (Utility.deviceRegistered()) {
                    show_alert_title = "Success";
                    show_alert_message = "Action success";
                } else {
                    show_alert_title = "Warning";
                    show_alert_message = "You are NOT registered!";

                    showAlert(show_alert_title, show_alert_message, true);
                }

                if (selectedCode.equals("start_shift")) {
                    //if shift already started
                    if (Utility.getcurrentState().equals(GTConstants.onShift)) {
                        show_alert_title = "Warning";
                        show_alert_message = "You must end shift!";

                        showAlert(show_alert_title, show_alert_message, true);

                        //set spinner back to all clear
                        spinner.setSelection(2);
                    } else {
                        ToastMessage.displayToastFromResource(HomeScreen.this, 5, Gravity.CENTER,
                                (ViewGroup) findViewById(R.id.toast_layout_root));

                        pdialog = ProgressDialog.show(HomeScreen.this, "Please wait", "Starting shift ...",
                                true);

                        //set the current state
                        Utility.setcurrentState(GTConstants.onShift);
                        setuserBanner();

                        //wait for start shift actions to complete (or timeout occurs) before dismissing wait dialog
                        new CountDownTimer(5000, 1000) {
                            @Override
                            public void onTick(long millisUntilFinished) {
                                if (start_shift_wait)
                                    pdialog.dismiss();
                            }

                            @Override
                            public void onFinish() {
                                if (!(pdialog == null))
                                    pdialog.dismiss();
                            }
                        }.start();

                        //create dar file
                        try {
                            //create the dar file name
                            GTConstants.darfileName = GTConstants.LICENSE_ID.substring(7) + "_"
                                    + Utility.getUTCDate() + "_" + Utility.getUTCTime() + ".dar";

                            //write the version to the dar file
                            Utility.write_to_file(HomeScreen.this,
                                    GTConstants.dardestinationFolder + GTConstants.darfileName,
                                    "Version;" + GTConstants.version + "\r\n", false);

                            //write the start shift event to the dar file
                            Utility.write_to_file(HomeScreen.this,
                                    GTConstants.dardestinationFolder + GTConstants.darfileName,
                                    "Start shift;" + GTConstants.currentBatteryPercent + ";"
                                            + Utility.getLocalTime() + ";" + Utility.getLocalDate() + "\r\n",
                                    true);

                            //create the tar file name if module installed
                            if (GTConstants.isTimeandAttendance) {
                                GTConstants.tarfileName = GTConstants.LICENSE_ID.substring(7) + "_"
                                        + Utility.getUTCDate() + "_" + Utility.getUTCTime() + ".tar";

                                //write the start shift event to the tar file
                                Utility.write_to_file(HomeScreen.this,
                                        GTConstants.dardestinationFolder + GTConstants.tarfileName,
                                        "Name;" + GTConstants.report_name + "\r\n" + "Start shift;"
                                                + Utility.getLocalTime() + ";" + Utility.getLocalDate()
                                                + "\r\n",
                                        false);
                            }

                        } catch (Exception e) {
                            Toast.makeText(HomeScreen.this, "error = " + e, Toast.LENGTH_LONG).show();
                        }

                        GTConstants.sendData = true;

                        //if not time and attendance then send start shift event now, otherwise wait till after location scan
                        send_event("11");

                        //set the session start time
                        SimpleDateFormat sdf = new SimpleDateFormat("MM-dd-yy HH:mm:ss");
                        Utility.setsessionStart(sdf.format(new Date()));

                        //reset the server connection flag
                        Utility.resetisConnecting();

                        //start the GPS location service
                        MainService.openLocationListener();

                        //set spinner back to all clear
                        spinner.setSelection(2);

                        setwarningText("");

                        if (GTConstants.isTimeandAttendance) {
                            show_taa_scan(true, false);
                        }
                    }

                } else if (selectedCode.equals("end_shift")) {
                    if (!Utility.getcurrentState().equals(GTConstants.onShift)
                            && GTConstants.isTimeandAttendance) {
                        show_alert_title = "Error";
                        show_alert_message = "You must end your Lunch / Break!";
                        showAlert(show_alert_title, show_alert_message, true);

                        //set spinner back to start shift
                        spinner.setSelection(2);
                    } else {
                        btn_send.setEnabled(false);
                        if (GTConstants.isTimeandAttendance) {
                            show_taa_scan(false, true);
                        } else
                            endshiftCode();
                    }
                } else {
                    if (Utility.isselectionValid(HomeScreen.this, selectedCode)) {
                        //if time and attendance then write to file
                        if (selectedCode.equalsIgnoreCase(GTConstants.lunchin)
                                || selectedCode.equalsIgnoreCase(GTConstants.lunchout)
                                || selectedCode.equalsIgnoreCase(GTConstants.startbreak)
                                || selectedCode.equalsIgnoreCase(GTConstants.endbreak)) {
                            if (GTConstants.isTimeandAttendance)
                                Utility.write_to_file(HomeScreen.this,
                                        GTConstants.dardestinationFolder + GTConstants.tarfileName,
                                        spinner.getSelectedItem().toString() + ";" + Utility.getLocalTime()
                                                + ";" + Utility.getLocalDate() + "\r\n",
                                        true);

                            if (selectedCode.equalsIgnoreCase(GTConstants.lunchin)) {
                                Utility.setcurrentState(GTConstants.onLunch);
                                Utility.setlunchStart(true);
                                setuserBanner();
                            }

                            if (selectedCode.equalsIgnoreCase(GTConstants.startbreak)) {
                                Utility.setcurrentState(GTConstants.onBreak);
                                Utility.setbreakStart(true);
                                setuserBanner();
                            }

                            if (selectedCode.equalsIgnoreCase(GTConstants.lunchout)) {
                                Utility.setcurrentState(GTConstants.onShift);
                                lunchTime = Utility.gettimeDiff(Utility.getlunchStart(),
                                        Utility.getLocalDateTime());
                                setuserBanner();
                            }

                            if (selectedCode.equalsIgnoreCase(GTConstants.endbreak)) {
                                Utility.setcurrentState(GTConstants.onShift);
                                breakTime = Utility.gettimeDiff(Utility.getbreakStart(),
                                        Utility.getLocalDateTime());
                                setuserBanner();
                            }
                        }

                        ToastMessage.displayToastFromResource(HomeScreen.this, 5, Gravity.CENTER,
                                (ViewGroup) findViewById(R.id.toast_layout_root));

                        //save the event description as may be needed for incident report
                        incidentDescription = spinner.getSelectedItem().toString();

                        //write to dar
                        Utility.write_to_file(HomeScreen.this,
                                GTConstants.dardestinationFolder + GTConstants.darfileName,
                                "Event; " + incidentDescription + ";" + Utility.getLocalTime() + ";"
                                        + Utility.getLocalDate() + "\r\n",
                                true);

                        //write to srp
                        if (GTConstants.srpfileName.length() > 1)
                            Utility.write_to_file(HomeScreen.this,
                                    GTConstants.dardestinationFolder + GTConstants.srpfileName,
                                    "Event; " + incidentDescription + ";" + Utility.getLocalTime() + ";"
                                            + Utility.getLocalDate() + "\r\n",
                                    true);

                        //send the data
                        send_event(selectedCode);

                        //ask if user wants to create an incident report.  If the last character is a space, that indicates not to ask for report
                        if (!(incidentDescription.charAt(incidentDescription.length() - 1) == ' ')
                                && !trafficIncident)
                            showYesNoAlert("Report", "Create an Incident Report?", incidentreportScreen);
                        if (!(incidentDescription.charAt(incidentDescription.length() - 1) == ' ')
                                && trafficIncident)
                            showYesNoAlert("Report", "Create a Traffic Violation?", incidentreportScreen);

                        //if last two characters are spaces then ask to write a note
                        if (incidentDescription.charAt(incidentDescription.length() - 1) == ' '
                                && incidentDescription.charAt(incidentDescription.length() - 2) == ' ')
                            showYesNoAlert("Report", "Create a Note?", createNote);

                    }

                    //set spinner back to required state
                    if (selectedCode.equalsIgnoreCase(GTConstants.lunchin))
                        spinner.setSelection(lunchoutLocation);
                    else if (selectedCode.equalsIgnoreCase(GTConstants.startbreak))
                        spinner.setSelection(breakoutLocation);
                    else
                        spinner.setSelection(2);

                }
            }
        }

    });

    //Finds a view that was identified by the id attribute from the XML that was processed in onCreate(Bundle).
    spinner = (Spinner) findViewById(R.id.spinner_list);

    //method initialize the spinner action
    initializeSpinnerControl();

    if (GTConstants.service_intent == null) {
        //Condition to check whether the Database exist and if so load data into constants
        try {
            if (preferenceDB.checkDataBase()) {
                preferenceDB.open();

                Cursor cursor = preferenceDB.getRecordByRowID("1");

                preferenceDB.close();

                if (cursor == null)
                    loadPreferenceDataBase();
                else {
                    saveInConstants(cursor);
                    cursor.close();
                }
                syncDB();
                syncFTP();
                syncftpUpload();
            } else {
                preferenceDB.open();
                preferenceDB.close();
                //Toast.makeText(HomeScreen.this, "Path = " + preferenceDB.get_path(), Toast.LENGTH_LONG).show();
                //Toast.makeText(HomeScreen.this, "No database found", Toast.LENGTH_LONG).show();

                loadPreferenceDataBase();

                syncDB();
                syncFTP();
                syncftpUpload();
            }
        } catch (Exception e) {
            preferenceDB.createDataBase();
            loadPreferenceDataBase();
            Toast.makeText(HomeScreen.this, "Creating database", Toast.LENGTH_LONG).show();
        }

        //setup the auxiliary databases
        if (!aDB.checkDataBase()) {
            aDB.open();
            aDB.close();
        }

        if (!ftpdatabase.checkDataBase()) {
            ftpdatabase.open();
            ftpdatabase.close();
        }

        if (!gtDB.checkDataBase()) {
            gtDB.open();
            gtDB.close();
        }

        if (!trafficDB.checkDataBase()) {
            trafficDB.open();
            trafficDB.close();
        }

        if (!tourDB.checkDataBase()) {
            tourDB.open();
            tourDB.close();
        }

        //get the parameters from the parameter database
        loadGTParams();

        //this code starts the main service running which contains all the event timers
        if (Utility.deviceRegistered()) {
            //this is the application started event - sent once when application starts up
            if (savedInstanceState == null)
                send_event("PU");

            initService();
        }
    }

    //if device not registered than go straight to scan screen
    if (!Utility.deviceRegistered()) {
        newRegistration = true;
        //send_data = true;
        scan_click(false);
    }

    //setup the user banner
    setuserBanner();

    //set the warning text
    setwarningText("");

}