Example usage for android.view.animation AlphaAnimation AlphaAnimation

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

Introduction

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

Prototype

public AlphaAnimation(float fromAlpha, float toAlpha) 

Source Link

Document

Constructor to use when building an AlphaAnimation from code

Usage

From source file:com.benefit.buy.library.http.query.callback.BitmapAjaxCallback.java

private static void setBmAnimate(ImageView iv, Bitmap bm, Bitmap preset, int fallback, int animation,
        float ratio, float anchor, int source) {
    bm = filter(iv, bm, fallback);// www.  j  a  v  a2  s . c  o m
    if (bm == null) {
        iv.setImageBitmap(null);
        return;
    }
    Drawable d = makeDrawable(iv, bm, ratio, anchor);
    Animation anim = null;
    if (fadeIn(animation, source)) {
        if (preset == null) {
            anim = new AlphaAnimation(0, 1);
            anim.setInterpolator(new DecelerateInterpolator());
            anim.setDuration(FADE_DUR);
        } else {
            Drawable pd = makeDrawable(iv, preset, ratio, anchor);
            Drawable[] ds = new Drawable[] { pd, d };
            TransitionDrawable td = new TransitionDrawable(ds);
            td.setCrossFadeEnabled(true);
            td.startTransition(FADE_DUR);
            d = td;
        }
    } else if (animation > 0) {
        anim = AnimationUtils.loadAnimation(iv.getContext(), animation);
    }
    iv.setImageDrawable(d);
    if (anim != null) {
        anim.setStartTime(AnimationUtils.currentAnimationTimeMillis());
        iv.startAnimation(anim);
    } else {
        iv.setAnimation(null);
    }
}

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

public static void fadeScaleBubble(final View... views) {
    if (views == null || views.length == 0)
        return;//www . j  av a2s.c  o  m
    for (final View v : views) {
        if (v == null || v.getVisibility() != View.VISIBLE)
            continue;
        Animation animation = new AlphaAnimation(1f, 0f);
        animation.setDuration(150);
        animation.setAnimationListener(new Animation.AnimationListener() {
            @Override
            public void onAnimationStart(Animation animation) {
            }

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

            @Override
            public void onAnimationRepeat(Animation animation) {

            }
        });
        v.startAnimation(animation);
    }

}

From source file:com.appbase.androidquery.callback.BitmapAjaxCallback.java

private static void setBmAnimate(ImageView iv, Bitmap bm, Bitmap preset, int fallback, int animation,
        float ratio, float anchor, int source) {

    bm = filter(iv, bm, fallback);/*from www  .  jav  a2s  .  c o  m*/
    if (bm == null) {
        iv.setImageBitmap(null);
        return;
    }

    Drawable d = makeDrawable(iv, bm, ratio, anchor);
    Animation anim = null;

    if (fadeIn(animation, source)) {
        if (preset == null) {
            anim = new AlphaAnimation(0, 1);
            anim.setInterpolator(new DecelerateInterpolator());
            anim.setDuration(FADE_DUR);
        } else {

            Drawable pd = makeDrawable(iv, preset, ratio, anchor);
            Drawable[] ds = new Drawable[] { pd, d };
            TransitionDrawable td = new TransitionDrawable(ds);
            td.setCrossFadeEnabled(true);
            td.startTransition(FADE_DUR);
            d = td;
        }
    } else if (animation > 0) {
        anim = AnimationUtils.loadAnimation(iv.getContext(), animation);
    }

    iv.setImageDrawable(d);

    if (anim != null) {
        anim.setStartTime(AnimationUtils.currentAnimationTimeMillis());
        iv.startAnimation(anim);
    } else {
        iv.setAnimation(null);
    }
}

From source file:com.aero2.android.DefaultActivities.SmogMapActivity.java

public void animateExit() {
    RelativeLayout layout = (RelativeLayout) findViewById(R.id.map_layout);
    AlphaAnimation animation = new AlphaAnimation(1.0f, 0.0f);
    animation.setFillAfter(true);//from   w w w .j av  a2  s  . c  o  m
    animation.setDuration(1000);
    //apply the animation ( fade In ) to your LAyout
    layout.startAnimation(animation);

}

From source file:com.eutectoid.dosomething.picker.PickerFragment.java

private static void setAlpha(View view, float alpha) {
    // Set the alpha appropriately (setAlpha is API >= 11, this technique works on all API levels).
    AlphaAnimation alphaAnimation = new AlphaAnimation(alpha, alpha);
    alphaAnimation.setDuration(0);//from   w  w  w.  j  a v a2 s  .c  om
    alphaAnimation.setFillAfter(true);
    view.startAnimation(alphaAnimation);
}

From source file:de.gebatzens.sia.MainActivity.java

public void toggleShareToolbar(final boolean show) {
    final Toolbar shareToolbar = (Toolbar) findViewById(R.id.share_toolbar);

    AlphaAnimation anim = new AlphaAnimation(show ? 0.f : 1.f, show ? 1.f : 0.f);
    anim.setDuration(200);//ww w. jav  a 2s . com

    anim.setAnimationListener(new Animation.AnimationListener() {
        @Override
        public void onAnimationStart(Animation animation) {
            if (show) {
                shareToolbar.setVisibility(View.VISIBLE);
            }
        }

        @Override
        public void onAnimationEnd(Animation animation) {
            if (!show) {
                shareToolbar.setVisibility(View.GONE);
            }
        }

        @Override
        public void onAnimationRepeat(Animation animation) {

        }
    });

    shareToolbar.startAnimation(anim);
}

From source file:ly.kite.journey.selection.ProductOverviewFragment.java

/*****************************************************
 *
 * Called when the details control is clicked.
 *
 *****************************************************/
private void toggleSliderState() {
    // We want to animation the following:
    //   - Overlaid start button fade in / out
    //   - Sliding drawer up / down
    //   - Open / close drawer icon rotation

    boolean sliderWillBeOpening = !mSlidingOverlayFrame.sliderIsExpanded();

    float overlaidComponentsInitialAlpha;
    float overlaidComponentsFinalAlpha;

    float openCloseIconInitialRotation;
    float openCloseIconFinalRotation;

    if (sliderWillBeOpening) {
        overlaidComponentsInitialAlpha = 1f;
        overlaidComponentsFinalAlpha = 0f;

        openCloseIconInitialRotation = OPEN_CLOSE_ICON_ROTATION_UP;
        openCloseIconFinalRotation = OPEN_CLOSE_ICON_ROTATION_DOWN;
    } else {//  ww w  . j  av a 2 s.  c o  m
        overlaidComponentsInitialAlpha = 0f;
        overlaidComponentsFinalAlpha = 1f;

        openCloseIconInitialRotation = OPEN_CLOSE_ICON_ROTATION_DOWN;
        openCloseIconFinalRotation = OPEN_CLOSE_ICON_ROTATION_UP;
    }

    // Create the overlaid components animation
    Animation overlaidComponentsAnimation = new AlphaAnimation(overlaidComponentsInitialAlpha,
            overlaidComponentsFinalAlpha);
    overlaidComponentsAnimation.setDuration(SLIDE_ANIMATION_DURATION_MILLIS);
    overlaidComponentsAnimation.setFillAfter(true);

    // Create the open/close icon animation.
    // The rotation is delayed, but will finish at the same time as the slide animation.
    Animation openCloseIconAnimation = new RotateAnimation(openCloseIconInitialRotation,
            openCloseIconFinalRotation, mOpenCloseDrawerIconImageView.getWidth() * 0.5f,
            mOpenCloseDrawerIconImageView.getHeight() * 0.5f);
    openCloseIconAnimation.setStartOffset(OPEN_CLOSE_ICON_ANIMATION_DELAY_MILLIS);
    openCloseIconAnimation.setDuration(OPEN_CLOSE_ICON_ANIMATION_DURATION_MILLIS);
    openCloseIconAnimation.setFillAfter(true);

    if (mOverlaidComponents != null) {
        mOverlaidComponents.setAlpha(1f); // Clear any alpha already applied
        mOverlaidComponents.startAnimation(overlaidComponentsAnimation);
    }

    if (mOpenCloseDrawerIconImageView != null) {
        mOpenCloseDrawerIconImageView.setRotation(0f); // Clear any rotation already applied
        mOpenCloseDrawerIconImageView.startAnimation(openCloseIconAnimation);
    }

    mSlidingOverlayFrame.animateToExpandedState(sliderWillBeOpening);
}

From source file:com.segma.trim.MainActivity.java

private void showWarning(final String string) {

    //(findViewById(R.id.bt_go)).setEnabled(false);
    //(findViewById(R.id.save_file)).setEnabled(false);
    //textView.setEnabled(false);
    lockScreen();//from   ww w.  j  av a2 s  .  c om
    final Animation in = new AlphaAnimation(0f, 1f) {
        {
            setDuration(250);
        }
    };
    final Animation out = new AlphaAnimation(1f, 0f) {
        {
            setDuration(250);
        }
    };
    out.setAnimationListener(new Animation.AnimationListener() {
        @Override
        public void onAnimationStart(Animation animation) {
        }

        @Override
        public void onAnimationEnd(Animation animation) {
            textView.setText(string);
            textView.startAnimation(in);
        }

        @Override
        public void onAnimationRepeat(Animation animation) {
        }
    });
    in.setAnimationListener(new Animation.AnimationListener() {
        @Override
        public void onAnimationStart(Animation animation) {

        }

        @Override
        public void onAnimationEnd(Animation animation) {
            if (!textView.getText().toString().equals(WARNING_NO_IMAGE_IMPORTED)) {
                //textView.setEnabled(true);
                //(findViewById(R.id.bt_go)).setEnabled(true);
                //(findViewById(R.id.save_file)).setEnabled(true);
                unlockScreen();
            }
        }

        @Override
        public void onAnimationRepeat(Animation animation) {

        }
    });

    textView.startAnimation(out);
    new Handler().postDelayed(new Runnable() {
        @Override
        public void run() {
            out.setAnimationListener(new Animation.AnimationListener() {
                @Override
                public void onAnimationStart(Animation animation) {
                }

                @Override
                public void onAnimationEnd(Animation animation) {
                    textView.setText(MESSAGE_STARTUP);
                    textView.startAnimation(in);
                }

                @Override
                public void onAnimationRepeat(Animation animation) {
                }
            });
            textView.startAnimation(out);
        }
    }, 1500);
}

From source file:com.google.android.apps.santatracker.rocketsleigh.RocketSleighActivity.java

@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
@Override/* ww w.  j  av  a2s.  c o  m*/
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    Log.d(LOG_TAG, "onCreate() : " + savedInstanceState);

    setContentView(R.layout.activity_jet_pack_elf);

    // App Invites
    mInvitesFragment = AppInvitesFragment.getInstance(this);

    // App Measurement
    mMeasurement = FirebaseAnalytics.getInstance(this);
    MeasurementManager.recordScreenView(mMeasurement, getString(R.string.analytics_screen_rocket));

    // [ANALYTICS SCREEN]: Rocket Sleigh
    AnalyticsManager.initializeAnalyticsTracker(this);
    AnalyticsManager.sendScreenView(R.string.analytics_screen_rocket);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        ImmersiveModeHelper.setImmersiveSticky(getWindow());
        ImmersiveModeHelper.installSystemUiVisibilityChangeListener(getWindow());
    }

    mIntroVideo = (VideoView) findViewById(R.id.intro_view);
    mIntroControl = findViewById(R.id.intro_control_view);
    if (savedInstanceState == null) {
        String path = "android.resource://" + getPackageName() + "/" + R.raw.jp_background;
        mBackgroundPlayer = new MediaPlayer();
        try {
            mBackgroundPlayer.setDataSource(this, Uri.parse(path));
            mBackgroundPlayer.setLooping(true);
            mBackgroundPlayer.prepare();
            mBackgroundPlayer.start();
        } catch (IOException e) {
            e.printStackTrace();
        }

        boolean nomovie = false;
        if (getIntent().getBooleanExtra("nomovie", false)) {
            nomovie = true;
        } else if (Build.MANUFACTURER.toUpperCase().contains("SAMSUNG")) {
            //                nomovie = true;
        }
        if (!nomovie) {
            mIntroControl.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {
                    endIntro();
                }
            });
            path = "android.resource://" + getPackageName() + "/" + R.raw.intro_wipe;
            mIntroVideo.setVideoURI(Uri.parse(path));
            mIntroVideo.setOnCompletionListener(this);
            mIntroVideo.start();
            mMoviePlaying = true;
        } else {
            mIntroControl.setOnClickListener(null);
            mIntroControl.setVisibility(View.GONE);
            mIntroVideo.setVisibility(View.GONE);
        }
    } else {
        mIntroControl.setOnClickListener(null);
        mIntroControl.setVisibility(View.GONE);
        mIntroVideo.setVisibility(View.GONE);
    }

    mVibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE); // For hit indication.

    mHandler = new Handler(); // Get the main UI handler for posting update events

    DisplayMetrics dm = new DisplayMetrics();
    getWindowManager().getDefaultDisplay().getMetrics(dm);

    Log.d(LOG_TAG, "Width: " + dm.widthPixels + " Height: " + dm.heightPixels + " Density: " + dm.density);

    mScreenHeight = dm.heightPixels;
    mScreenWidth = dm.widthPixels;
    mSlotWidth = mScreenWidth / SLOTS_PER_SCREEN;

    // Setup the random number generator
    mRandom = new Random();
    mRandom.setSeed(System.currentTimeMillis()); // This is ok.  We are not looking for cryptographically secure random here!

    mInflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);

    // Setup the background/foreground
    mBackgroundLayout = (LinearLayout) findViewById(R.id.background_layout);
    mBackgroundScroll = (HorizontalScrollView) findViewById(R.id.background_scroll);
    mForegroundLayout = (LinearLayout) findViewById(R.id.foreground_layout);
    mForegroundScroll = (HorizontalScrollView) findViewById(R.id.foreground_scroll);

    mBackgrounds = new Bitmap[6];
    mBackgrounds2 = new Bitmap[6];
    mExitTransitions = new Bitmap[6];
    mEntryTransitions = new Bitmap[6];

    // Need to vertically scale background to fit the screen.  Checkthe image size
    // compared to screen size and scale appropriately.  We will also use the matrix to translate
    // as we move through the level.
    Bitmap bmp = BitmapFactory.decodeResource(getResources(), BACKGROUNDS[0]);
    Log.d(LOG_TAG, "Bitmap Width: " + bmp.getWidth() + " Height: " + bmp.getHeight() + " Screen Width: "
            + dm.widthPixels + " Height: " + dm.heightPixels);
    mScaleY = (float) dm.heightPixels / (float) bmp.getHeight();
    mScaleX = (float) (dm.widthPixels * 2) / (float) bmp.getWidth(); // Ensure that a single bitmap is 2 screens worth of time.  (Stock xxhdpi image is 3840x1080)

    if ((mScaleX != 1.0f) || (mScaleY != 1.0f)) {
        Bitmap tmp = Bitmap.createScaledBitmap(bmp, mScreenWidth * 2, mScreenHeight, false);
        if (tmp != bmp) {
            bmp.recycle();
            bmp = tmp;
        }
    }
    BackgroundLoadTask.createTwoBitmaps(bmp, mBackgrounds, mBackgrounds2, 0);

    // Load the initial background view
    addNextImages(0);
    addNextImages(0);

    mWoodObstacles = new TreeMap<Integer, Bitmap>();
    mWoodObstacleList = new ArrayList<Integer>();
    mWoodObstacleIndex = 0;
    // We need the bitmaps, so we do pre-load here synchronously.
    initObstaclesAndPreLoad(WOOD_OBSTACLES, 3, mWoodObstacles, mWoodObstacleList);

    mCaveObstacles = new TreeMap<Integer, Bitmap>();
    mCaveObstacleList = new ArrayList<Integer>();
    mCaveObstacleIndex = 0;
    initObstacles(CAVE_OBSTACLES, 2, mCaveObstacleList);

    mFactoryObstacles = new TreeMap<Integer, Bitmap>();
    mFactoryObstacleList = new ArrayList<Integer>();
    mFactoryObstacleIndex = 0;
    initObstacles(FACTORY_OBSTACLES, 2, mFactoryObstacleList);

    // Setup the elf
    mElf = (ImageView) findViewById(R.id.elf_image);
    mThrust = (ImageView) findViewById(R.id.thrust_image);
    mElfLayout = (LinearLayout) findViewById(R.id.elf_container);
    loadElfImages();
    updateElf(false);
    // Elf should be the same height relative to the height of the screen on any platform.
    Matrix scaleMatrix = new Matrix();
    mElfScale = ((float) dm.heightPixels * 0.123f) / (float) mElfBitmap.getHeight(); // On a 1920x1080 xxhdpi screen, this makes the elf 133 pixels which is the height of the drawable.
    scaleMatrix.preScale(mElfScale, mElfScale);
    mElf.setImageMatrix(scaleMatrix);
    mThrust.setImageMatrix(scaleMatrix);
    mElfPosX = (dm.widthPixels * 15) / 100; // 15% Into the screen
    mElfPosY = (dm.heightPixels - ((float) mElfBitmap.getHeight() * mElfScale)) / 2; // About 1/2 way down.
    mElfVelX = (float) dm.widthPixels / 3000.0f; // We start at 3 seconds for a full screen to scroll.
    mGravityAccelY = (float) (2 * dm.heightPixels) / (float) Math.pow((1.2 * 1000.0), 2.0); // a = 2*d/t^2 Where d = height in pixels and t = 1.2 seconds
    mThrustAccelY = (float) (2 * dm.heightPixels) / (float) Math.pow((0.7 * 1000.0), 2.0); // a = 2*d/t^2 Where d = height in pixels and t = 0.7 seconds

    // Setup the control view
    mControlView = findViewById(R.id.control_view);
    mGestureDetector = new GestureDetector(this, this);
    mGestureDetector.setIsLongpressEnabled(true);
    mGestureDetector.setOnDoubleTapListener(this);

    mScoreLabel = getString(R.string.score);
    mScoreText = (TextView) findViewById(R.id.score_text);
    mScoreText.setText("0");

    mPlayPauseButton = (ImageView) findViewById(R.id.play_pause_button);
    mExit = (ImageView) findViewById(R.id.exit);

    // Is Tv?
    mIsTv = TvUtil.isTv(this);
    if (mIsTv) {
        mScoreText.setText(mScoreLabel + ": 0");
        mPlayPauseButton.setVisibility(View.GONE);
        mExit.setVisibility(View.GONE);
        // move scoreLayout position to the Top-Right corner.
        View scoreLayout = findViewById(R.id.score_layout);
        RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) scoreLayout.getLayoutParams();
        params.removeRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
        params.addRule(RelativeLayout.ALIGN_PARENT_TOP);
        params.removeRule(RelativeLayout.ALIGN_PARENT_RIGHT);
        params.addRule(RelativeLayout.ALIGN_PARENT_LEFT);

        final int marginTop = getResources().getDimensionPixelOffset(R.dimen.overscan_margin_top);
        final int marginLeft = getResources().getDimensionPixelOffset(R.dimen.overscan_margin_left);

        params.setMargins(marginLeft, marginTop, 0, 0);
        scoreLayout.setLayoutParams(params);
        scoreLayout.setBackground(null);
        scoreLayout.findViewById(R.id.score_text_seperator).setVisibility(View.GONE);
    } else {
        mPlayPauseButton.setEnabled(false);
        mPlayPauseButton.setOnClickListener(this);
        mExit.setOnClickListener(this);
    }

    mBigPlayButtonLayout = findViewById(R.id.big_play_button_layout);
    mBigPlayButtonLayout.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            // No interaction with the screen below this one.
            return true;
        }
    });
    mBigPlayButton = (ImageButton) findViewById(R.id.big_play_button);
    mBigPlayButton.setOnClickListener(this);

    // For showing points when getting presents.
    mPlus100 = (ImageView) findViewById(R.id.plus_100);
    m100Anim = new AlphaAnimation(1.0f, 0.0f);
    m100Anim.setDuration(1000);
    m100Anim.setFillBefore(true);
    m100Anim.setFillAfter(true);
    mPlus500 = (ImageView) findViewById(R.id.plus_500);
    m500Anim = new AlphaAnimation(1.0f, 0.0f);
    m500Anim.setDuration(1000);
    m500Anim.setFillBefore(true);
    m500Anim.setFillAfter(true);

    // Get the obstacle layouts ready.  No obstacles on the first screen of a level.
    // Prime with a screen full of obstacles.
    mObstacleLayout = (LinearLayout) findViewById(R.id.obstacles_layout);
    mObstacleScroll = (HorizontalScrollView) findViewById(R.id.obstacles_scroll);

    // Initialize the present bitmaps.  These are used repeatedly so we keep them loaded.
    mGiftBoxes = new Bitmap[GIFT_BOXES.length];
    for (int i = 0; i < GIFT_BOXES.length; i++) {
        mGiftBoxes[i] = BitmapFactory.decodeResource(getResources(), GIFT_BOXES[i]);
    }

    // Add starting obstacles.  First screen has presents.  Next 3 get obstacles.
    addFirstScreenPresents();
    //        addFinalPresentRun();  // This adds 2 screens of presents
    //        addNextObstacles(0, 1);
    addNextObstacles(0, 3);

    // Setup the sound pool
    mSoundPool = new SoundPool(4, AudioManager.STREAM_MUSIC, 0);
    mSoundPool.setOnLoadCompleteListener(this);
    mCrashSound1 = mSoundPool.load(this, R.raw.jp_crash_1, 1);
    mCrashSound2 = mSoundPool.load(this, R.raw.jp_crash_2, 1);
    mCrashSound3 = mSoundPool.load(this, R.raw.jp_crash_3, 1);
    mGameOverSound = mSoundPool.load(this, R.raw.jp_game_over, 1);
    mJetThrustSound = mSoundPool.load(this, R.raw.jp_jet_thrust, 1);
    mLevelUpSound = mSoundPool.load(this, R.raw.jp_level_up, 1);
    mScoreBigSound = mSoundPool.load(this, R.raw.jp_score_big, 1);
    mScoreSmallSound = mSoundPool.load(this, R.raw.jp_score_small, 1);
    mJetThrustStream = 0;

    if (!mMoviePlaying) {
        doCountdown();
    }
}

From source file:com.zhongsou.souyue.activity.SplashActivity.java

private void animationHide(ImageView iv) {
    try {//  www  .jav a2 s  . c  o m
        AlphaAnimation ai = new AlphaAnimation(1.0f, 0.0f);
        ai.setDuration(500);
        ai.setFillAfter(true);
        iv.startAnimation(ai);
    } catch (Exception ex) {

    }
}