Android Open Source - ExampleApp Float Scroller






From Project

Back to project page ExampleApp.

License

The source code is released under:

Copyright (c) 2014, Altinn All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redis...

If you think the Android project ExampleApp listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

/*
 * Copyright (C) 2006 The Android Open Source Project
 *//w ww  .java2 s . co  m
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package net.simonvt.menudrawer;

import android.view.animation.AnimationUtils;
import android.view.animation.Interpolator;

/**
 * This class encapsulates scrolling.  The duration of the scroll
 * can be passed in the constructor and specifies the maximum time that
 * the scrolling animation should take.  Past this time, the scrolling is
 * automatically moved to its final stage and computeScrollOffset()
 * will always return false to indicate that scrolling is over.
 */
class FloatScroller {

    private float mStart;
    private float mFinal;

    private float mCurr;
    private long mStartTime;
    private int mDuration;
    private float mDurationReciprocal;
    private float mDeltaX;
    private boolean mFinished;
    private Interpolator mInterpolator;

    /**
     * Create a Scroller with the specified interpolator. If the interpolator is
     * null, the default (viscous) interpolator will be used. Specify whether or
     * not to support progressive "flywheel" behavior in flinging.
     */
    public FloatScroller(Interpolator interpolator) {
        mFinished = true;
        mInterpolator = interpolator;
    }

    /**
     * Returns whether the scroller has finished scrolling.
     *
     * @return True if the scroller has finished scrolling, false otherwise.
     */
    public final boolean isFinished() {
        return mFinished;
    }

    /**
     * Force the finished field to a particular value.
     *
     * @param finished The new finished value.
     */
    public final void forceFinished(boolean finished) {
        mFinished = finished;
    }

    /**
     * Returns how long the scroll event will take, in milliseconds.
     *
     * @return The duration of the scroll in milliseconds.
     */
    public final int getDuration() {
        return mDuration;
    }

    /**
     * Returns the current offset in the scroll.
     *
     * @return The new offset as an absolute distance from the origin.
     */
    public final float getCurr() {
        return mCurr;
    }

    /**
     * Returns the start offset in the scroll.
     *
     * @return The start offset as an absolute distance from the origin.
     */
    public final float getStart() {
        return mStart;
    }

    /**
     * Returns where the scroll will end. Valid only for "fling" scrolls.
     *
     * @return The final offset as an absolute distance from the origin.
     */
    public final float getFinal() {
        return mFinal;
    }

    public boolean computeScrollOffset() {
        if (mFinished) {
            return false;
        }

        int timePassed = (int) (AnimationUtils.currentAnimationTimeMillis() - mStartTime);

        if (timePassed < mDuration) {
            float x = timePassed * mDurationReciprocal;
            x = mInterpolator.getInterpolation(x);
            mCurr = mStart + x * mDeltaX;

        } else {
            mCurr = mFinal;
            mFinished = true;
        }
        return true;
    }

    public void startScroll(float start, float delta, int duration) {
        mFinished = false;
        mDuration = duration;
        mStartTime = AnimationUtils.currentAnimationTimeMillis();
        mStart = start;
        mFinal = start + delta;
        mDeltaX = delta;
        mDurationReciprocal = 1.0f / (float) mDuration;
    }

    /**
     * Stops the animation. Contrary to {@link #forceFinished(boolean)},
     * aborting the animating cause the scroller to move to the final x and y
     * position
     *
     * @see #forceFinished(boolean)
     */
    public void abortAnimation() {
        mCurr = mFinal;
        mFinished = true;
    }

    /**
     * Extend the scroll animation. This allows a running animation to scroll
     * further and longer, when used with {@link #setFinal(float)}.
     *
     * @param extend Additional time to scroll in milliseconds.
     * @see #setFinal(float)
     */
    public void extendDuration(int extend) {
        int passed = timePassed();
        mDuration = passed + extend;
        mDurationReciprocal = 1.0f / mDuration;
        mFinished = false;
    }

    /**
     * Returns the time elapsed since the beginning of the scrolling.
     *
     * @return The elapsed time in milliseconds.
     */
    public int timePassed() {
        return (int) (AnimationUtils.currentAnimationTimeMillis() - mStartTime);
    }

    public void setFinal(float newVal) {
        mFinal = newVal;
        mDeltaX = mFinal - mStart;
        mFinished = false;
    }
}




Java Source Code List

com.altinn.apps.fisher.AppContext.java
com.altinn.apps.fisher.CacheManager.java
com.altinn.apps.fisher.common.AppConstants.java
com.altinn.apps.fisher.common.IStatusMessage.java
com.altinn.apps.fisher.common.MenuItem.java
com.altinn.apps.fisher.common.StatusMessage.java
com.altinn.apps.fisher.db.DataBaseHelper.java
com.altinn.apps.fisher.db.FactoryDBHelper.java
com.altinn.apps.fisher.db.FishCategoryDBHelper.java
com.altinn.apps.fisher.db.FormDBHelper.java
com.altinn.apps.fisher.db.IDBHelper.java
com.altinn.apps.fisher.db.RegsDBHelper.java
com.altinn.apps.fisher.db.VesselDBHelper.java
com.altinn.apps.fisher.gps.CLocationProvider.java
com.altinn.apps.fisher.gps.ILocationUpdateListner.java
com.altinn.apps.fisher.models.CaughtInfoData.java
com.altinn.apps.fisher.models.InfoData.java
com.altinn.apps.fisher.models.ReportInfoData.java
com.altinn.apps.fisher.models.UserProfile.java
com.altinn.apps.fisher.net.AbstractWorkerTask.java
com.altinn.apps.fisher.net.CookieHelper.java
com.altinn.apps.fisher.net.IParser.java
com.altinn.apps.fisher.net.JSParser.java
com.altinn.apps.fisher.net.ParseManager.java
com.altinn.apps.fisher.net.TaskNotifier.java
com.altinn.apps.fisher.net.jsobj.AttachmentObj.java
com.altinn.apps.fisher.net.jsobj.FormObj.java
com.altinn.apps.fisher.net.jsobj.JSConstants.java
com.altinn.apps.fisher.net.jsobj.JsonObj.java
com.altinn.apps.fisher.net.jsobj.LinkItemObj.java
com.altinn.apps.fisher.net.jsobj.LinkObj.java
com.altinn.apps.fisher.net.jsobj.MessageObj.java
com.altinn.apps.fisher.net.jsobj.MessagesEmbedded.java
com.altinn.apps.fisher.net.jsobj.OrganisationObj.java
com.altinn.apps.fisher.net.tasks.LoginTask.java
com.altinn.apps.fisher.net.tasks.RefreshTokenTask.java
com.altinn.apps.fisher.net.tasks.SendReportTask.java
com.altinn.apps.fisher.net.tasks.UserProfileTask.java
com.altinn.apps.fisher.settings.FactoryDetails.java
com.altinn.apps.fisher.settings.FishDetails.java
com.altinn.apps.fisher.settings.SettingItem.java
com.altinn.apps.fisher.settings.VesselsDetails.java
com.altinn.apps.fisher.ui.component.DurationTimePickDialog.java
com.altinn.apps.fisher.ui.component.RAutoCompleteTextView.java
com.altinn.apps.fisher.ui.component.RButton.java
com.altinn.apps.fisher.ui.component.REditText.java
com.altinn.apps.fisher.ui.component.RTextView.java
com.altinn.apps.fisher.ui.screen.BaseActivity.java
com.altinn.apps.fisher.ui.screen.BrowserActivity.java
com.altinn.apps.fisher.ui.screen.FactoryDetailsActivity.java
com.altinn.apps.fisher.ui.screen.HomeActivity.java
com.altinn.apps.fisher.ui.screen.InformationActivity.java
com.altinn.apps.fisher.ui.screen.MenuNavigationActivity.java
com.altinn.apps.fisher.ui.screen.ReportActivity.java
com.altinn.apps.fisher.ui.screen.ReportReceivedFishActivity.java
com.altinn.apps.fisher.ui.screen.ReportSendDetailActivity.java
com.altinn.apps.fisher.ui.screen.SplashActivity.java
com.altinn.apps.fisher.ui.screen.UserProfileActivity.java
com.altinn.apps.fisher.utils.PreferenceUtils.java
com.altinn.apps.fisher.utils.Utils.java
net.simonvt.menudrawer.BuildLayerFrameLayout.java
net.simonvt.menudrawer.ColorDrawable.java
net.simonvt.menudrawer.DraggableDrawer.java
net.simonvt.menudrawer.FloatScroller.java
net.simonvt.menudrawer.MenuDrawer.java
net.simonvt.menudrawer.NoClickThroughFrameLayout.java
net.simonvt.menudrawer.OverlayDrawer.java
net.simonvt.menudrawer.PeekInterpolator.java
net.simonvt.menudrawer.Position.java
net.simonvt.menudrawer.Scroller.java
net.simonvt.menudrawer.SinusoidalInterpolator.java
net.simonvt.menudrawer.SlideDrawable.java
net.simonvt.menudrawer.SlidingDrawer.java
net.simonvt.menudrawer.SmoothInterpolator.java
net.simonvt.menudrawer.StaticDrawer.java
net.simonvt.menudrawer.ViewHelper.java
net.simonvt.menudrawer.compat.ActionBarHelperCompat.java
net.simonvt.menudrawer.compat.ActionBarHelperNative.java
net.simonvt.menudrawer.compat.ActionBarHelper.java