Example usage for android.animation AnimatorSet start

List of usage examples for android.animation AnimatorSet start

Introduction

In this page you can find the example usage for android.animation AnimatorSet start.

Prototype

@SuppressWarnings("unchecked")
@Override
public void start() 

Source Link

Document

Starting this AnimatorSet will, in turn, start the animations for which it is responsible.

Usage

From source file:com.android.launcher2.AsyncTaskCallback.java

@Override
public void onClick(View v) {
    // When we have exited all apps or are in transition, disregard clicks
    if (!mLauncher.isAllAppsVisible() || mLauncher.getWorkspace().isSwitchingState())
        return;//from www.  j a  v  a 2s.  co  m

    if (v instanceof PagedViewIcon) {
        // Animate some feedback to the click
        final ApplicationInfo appInfo = (ApplicationInfo) v.getTag();

        // Lock the drawable state to pressed until we return to Launcher
        if (mPressedIcon != null) {
            mPressedIcon.lockDrawableState();
        }

        // NOTE: We want all transitions from launcher to act as if the wallpaper were enabled
        // to be consistent.  So re-enable the flag here, and we will re-disable it as necessary
        // when Launcher resumes and we are still in AllApps.
        mLauncher.updateWallpaperVisibility(true);
        mLauncher.startActivitySafely(v, appInfo.intent, appInfo);

    } else if (v instanceof PagedViewWidget) {
        // Let the user know that they have to long press to add a widget
        if (mWidgetInstructionToast != null) {
            mWidgetInstructionToast.cancel();
        }
        mWidgetInstructionToast = Toast.makeText(getContext(), R.string.long_press_widget_to_add,
                Toast.LENGTH_SHORT);
        mWidgetInstructionToast.show();

        // Create a little animation to show that the widget can move
        float offsetY = getResources().getDimensionPixelSize(R.dimen.dragViewOffsetY);
        final ImageView p = (ImageView) v.findViewById(R.id.widget_preview);
        AnimatorSet bounce = LauncherAnimUtils.createAnimatorSet();
        ValueAnimator tyuAnim = LauncherAnimUtils.ofFloat(p, "translationY", offsetY);
        tyuAnim.setDuration(125);
        ValueAnimator tydAnim = LauncherAnimUtils.ofFloat(p, "translationY", 0f);
        tydAnim.setDuration(100);
        bounce.play(tyuAnim).before(tydAnim);
        bounce.setInterpolator(new AccelerateInterpolator());
        bounce.start();
    }
}

From source file:com.tmall.wireless.tangram3.ext.SwipeItemTouchListener.java

private void resetViews(RecyclerView recyclerView, final int swipingType, final boolean reachActionEdge,
        final int direction) {
    if (enableAnim) {
        int contentWidth = recyclerView.getWidth();
        AnimatorSet animatorSet = new AnimatorSet();
        List<Animator> list = new ArrayList<>();
        String translation = "translationX";
        if (swipingType == SWIPING_VER) {
            translation = "translationY";
        }//from w  ww .java  2  s  .  co m
        for (View view : mChildList) {
            ObjectAnimator animator;
            if (reachActionEdge) {
                animator = ObjectAnimator.ofFloat(view, translation, contentWidth * direction)
                        .setDuration(ANIMATE_DURATION);
                animator.setInterpolator(new AccelerateInterpolator());
            } else {
                animator = ObjectAnimator.ofFloat(view, translation, 0).setDuration(ANIMATE_DURATION);
                animator.setInterpolator(new DecelerateInterpolator());
            }
            list.add(animator);
        }
        animatorSet.playTogether(list);
        animatorSet.addListener(new Animator.AnimatorListener() {
            @Override
            public void onAnimationStart(Animator animation) {

            }

            @Override
            public void onAnimationEnd(Animator animation) {
                if (swipingType == SWIPING_HOR && reachActionEdge) {
                    if (mSwipeCardRef != null && mSwipeCardRef.get() != null) {
                        SwipeCard swipeCard = mSwipeCardRef.get();
                        swipeCard.switchTo(swipeCard.getCurrentIndex() - direction);
                    }
                }
                mChildList.clear();
            }

            @Override
            public void onAnimationCancel(Animator animation) {

            }

            @Override
            public void onAnimationRepeat(Animator animation) {

            }
        });
        animatorSet.start();
    } else {
        if (swipingType == SWIPING_HOR && reachActionEdge) {
            if (mSwipeCardRef != null && mSwipeCardRef.get() != null) {
                SwipeCard swipeCard = mSwipeCardRef.get();
                swipeCard.switchTo(swipeCard.getCurrentIndex() - direction);
            }
        }
        mChildList.clear();
    }

    if (swipingType == SWIPING_VER) {
        if (pullFromEndListener != null) {
            if (mDistanceY < 0 && (mDistanceY < -pullFromEndListener.getPullEdge())) {
                pullFromEndListener.onAction();
            } else {
                pullFromEndListener.onReset();
            }
        }
    }

    swipeType = SWIPING_NONE;
}

From source file:kr.wdream.ui.MediaActivity.java

private boolean onItemLongClick(MessageObject item, View view, int a) {
    if (actionBar.isActionModeShowed()) {
        return false;
    }//from   w w  w .j  a  va2  s .c o  m
    AndroidUtilities.hideKeyboard(getParentActivity().getCurrentFocus());
    selectedFiles[item.getDialogId() == dialog_id ? 0 : 1].put(item.getId(), item);
    if (!item.canDeleteMessage(null)) {
        cantDeleteMessagesCount++;
    }
    actionBar.createActionMode().getItem(delete)
            .setVisibility(cantDeleteMessagesCount == 0 ? View.VISIBLE : View.GONE);
    selectedMessagesCountTextView.setNumber(1, false);
    AnimatorSet animatorSet = new AnimatorSet();
    ArrayList<Animator> animators = new ArrayList<>();
    for (int i = 0; i < actionModeViews.size(); i++) {
        View view2 = actionModeViews.get(i);
        AndroidUtilities.clearDrawableAnimation(view2);
        animators.add(ObjectAnimator.ofFloat(view2, "scaleY", 0.1f, 1.0f));
    }
    animatorSet.playTogether(animators);
    animatorSet.setDuration(250);
    animatorSet.start();
    scrolling = false;
    if (view instanceof SharedDocumentCell) {
        ((SharedDocumentCell) view).setChecked(true, true);
    } else if (view instanceof SharedPhotoVideoCell) {
        ((SharedPhotoVideoCell) view).setChecked(a, true, true);
    } else if (view instanceof SharedLinkCell) {
        ((SharedLinkCell) view).setChecked(true, true);
    }
    actionBar.showActionMode();
    return true;
}

From source file:com.github.shareme.gwsmaterialdrawer.library.DrawerView.java

private void animateToProfile(DrawerProfile profile) {
    Log.d(TAG, "animateToProfile(*" + profile.getId() + ")");

    if (mProfileAdapter.getCount() > 1) {
        List<Animator> animators = new ArrayList<>();
        List<Animator.AnimatorListener> listeners = new ArrayList<>();

        final DrawerProfile oldProfile = mProfileAdapter.getItem(0);
        final DrawerProfile newProfile = profile;

        /* Background animation */

        AlphaSatColorMatrixEvaluator evaluator = new AlphaSatColorMatrixEvaluator();
        final AnimatableColorMatrixColorFilter filter = new AnimatableColorMatrixColorFilter(
                evaluator.getColorMatrix());

        ObjectAnimator backgroundAnimator = ObjectAnimator.ofObject(filter, "colorMatrix", evaluator,
                evaluator.getColorMatrix());
        backgroundAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @Override/*from  w ww .ja  v  a2  s  . c om*/
            public void onAnimationUpdate(ValueAnimator animation) {
                imageViewProfileBackgroundOverlay.setColorFilter(filter.getColorFilter());
            }
        });
        animators.add(backgroundAnimator);

        listeners.add(new Animator.AnimatorListener() {
            @Override
            public void onAnimationStart(Animator animation) {
                imageViewProfileBackground.setImageDrawable(oldProfile.getBackground());

                imageViewProfileBackgroundOverlay.setImageDrawable(newProfile.getBackground());
                imageViewProfileBackgroundOverlay.setColorFilter(filter.getColorFilter());
                imageViewProfileBackgroundOverlay.setVisibility(VISIBLE);

                imageViewProfileAvatarSecondary.setClickable(false);
            }

            @Override
            public void onAnimationEnd(Animator animation) {
                imageViewProfileBackground.setImageDrawable(newProfile.getBackground());

                if (newProfile.getBackground() instanceof BitmapDrawable) {
                    new Palette.Builder(((BitmapDrawable) newProfile.getBackground()).getBitmap())
                            .resizeBitmapSize(500).generate(new Palette.PaletteAsyncListener() {
                                @Override
                                public void onGenerated(Palette palette) {
                                    Palette.Swatch vibrantSwatch = palette.getVibrantSwatch();
                                    if (vibrantSwatch != null) {
                                        textViewProfileAvatarCount
                                                .setTextColor(vibrantSwatch.getTitleTextColor());
                                        textViewProfileAvatarCount.getBackground()
                                                .setColorFilter(vibrantSwatch.getRgb(), PorterDuff.Mode.SRC_IN);
                                    }
                                }
                            });
                }

                imageViewProfileBackgroundOverlay.setVisibility(GONE);

                if (hasOnProfileSwitchListener()) {
                    onProfileSwitchListener.onSwitch(oldProfile, oldProfile.getId(), newProfile,
                            newProfile.getId());
                }
            }

            @Override
            public void onAnimationCancel(Animator animation) {
            }

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

        /* Text animation */

        AnimatorSet textSet = new AnimatorSet();

        AnimatorSet textOutSet = new AnimatorSet();
        textOutSet.playTogether(ObjectAnimator.ofFloat(linearLayoutProfileTextContainer, "alpha", 1, 0),
                ObjectAnimator.ofFloat(linearLayoutProfileTextContainer, "translationX", 0, getWidth() / 4));
        textOutSet.addListener(new Animator.AnimatorListener() {
            @Override
            public void onAnimationStart(Animator animation) {
            }

            @Override
            public void onAnimationEnd(Animator animation) {
                updateProfileTheme();
                if (newProfile.hasName()) {
                    textViewProfileName.setText(newProfile.getName());
                    textViewProfileName.setVisibility(VISIBLE);
                } else {
                    textViewProfileName.setVisibility(GONE);
                }
                if (newProfile.hasDescription()) {
                    textViewProfileDescription.setText(newProfile.getDescription());
                    textViewProfileDescription.setVisibility(VISIBLE);
                } else {
                    textViewProfileDescription.setVisibility(GONE);
                }
            }

            @Override
            public void onAnimationCancel(Animator animation) {
            }

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

        AnimatorSet textInSet = new AnimatorSet();
        textInSet.playTogether(ObjectAnimator.ofFloat(linearLayoutProfileTextContainer, "alpha", 0, 1),
                ObjectAnimator.ofFloat(linearLayoutProfileTextContainer, "translationX", -getWidth() / 4, 0));

        textSet.playSequentially(textOutSet, textInSet);
        animators.add(textSet);

        AnimatorSet profileSet = new AnimatorSet();
        if (mProfileAdapter.getCount() == 2) {

            /* Avatar animation */

            int translation = imageViewProfileAvatarSecondary.getLeft()
                    - getResources().getDimensionPixelSize(R.dimen.md_baseline);
            float scale = getResources().getDimension(R.dimen.md_avatar_size)
                    / getResources().getDimension(R.dimen.md_big_avatar_size);
            float translationCorrect = (getResources().getDimension(R.dimen.md_avatar_size)
                    - getResources().getDimension(R.dimen.md_big_avatar_size)) / 2;

            listeners.add(new Animator.AnimatorListener() {
                @Override
                public void onAnimationStart(Animator animation) {
                    imageViewProfileAvatarSecondary.setPivotX(0);
                    imageViewProfileAvatarSecondary.setPivotY(0);
                }

                @Override
                public void onAnimationEnd(Animator animation) {

                    imageViewProfileAvatar.setTranslationX(0);
                    imageViewProfileAvatar.setTranslationY(0);
                    imageViewProfileAvatar.setScaleX(1);
                    imageViewProfileAvatar.setScaleY(1);
                    imageViewProfileAvatarSecondary.setTranslationX(0);
                    imageViewProfileAvatarSecondary.setScaleX(1);
                    imageViewProfileAvatarSecondary.setScaleY(1);

                    if (oldProfile.hasAvatar()) {

                        imageViewProfileAvatarSecondary.setImageDrawable(oldProfile.getAvatar());
                        imageViewProfileAvatarSecondary.setVisibility(VISIBLE);
                    } else {
                        imageViewProfileAvatarSecondary.setVisibility(INVISIBLE);
                    }

                    if (newProfile.hasAvatar()) {

                        imageViewProfileAvatar.setImageDrawable(newProfile.getAvatar());
                        imageViewProfileAvatar.setVisibility(VISIBLE);
                        imageViewProfileAvatarSecondary.setClickable(true);
                    } else {
                        imageViewProfileAvatar.setVisibility(INVISIBLE);
                        imageViewProfileAvatarSecondary.setClickable(false);
                    }
                }

                @Override
                public void onAnimationCancel(Animator animation) {
                }

                @Override
                public void onAnimationRepeat(Animator animation) {
                }
            });
            if (oldProfile.hasAvatar()) {

                ObjectAnimator stepTranslateXAnimator = ObjectAnimator.ofFloat(imageViewProfileAvatar,
                        "translationX", 0, translation + translationCorrect);
                stepTranslateXAnimator.setInterpolator(new StepInterpolator());
                animators.add(stepTranslateXAnimator);

                ObjectAnimator stepTranslateYAnimator = ObjectAnimator.ofFloat(imageViewProfileAvatar,
                        "translationY", 0, translationCorrect);
                stepTranslateYAnimator.setInterpolator(new StepInterpolator());
                animators.add(stepTranslateYAnimator);

                animators.add(ObjectAnimator.ofFloat(imageViewProfileAvatar, "alpha", 1, 0, 1));
                animators.add(ObjectAnimator.ofFloat(imageViewProfileAvatar, "scaleX", 1, 0.5f, scale));
                animators.add(ObjectAnimator.ofFloat(imageViewProfileAvatar, "scaleY", 1, 0.5f, scale));
            }

            if (newProfile.hasAvatar()) {
                animators.add(ObjectAnimator.ofFloat(imageViewProfileAvatarSecondary, "translationX", 0,
                        -translation));
                animators.add(ObjectAnimator.ofFloat(imageViewProfileAvatarSecondary, "scaleX", 1, 1 / scale));
                animators.add(ObjectAnimator.ofFloat(imageViewProfileAvatarSecondary, "scaleY", 1, 1 / scale));
            }
        } else {
            AnimatorSet profileOutSet = new AnimatorSet();
            profileOutSet.playTogether(ObjectAnimator.ofFloat(imageViewProfileAvatar, "alpha", 1, 0),
                    ObjectAnimator.ofFloat(imageViewProfileAvatar, "scaleX", 1, 0.5f),
                    ObjectAnimator.ofFloat(imageViewProfileAvatar, "scaleY", 1, 0.5f));
            profileOutSet.addListener(new Animator.AnimatorListener() {
                @Override
                public void onAnimationStart(Animator animation) {
                    linearListViewProfileList.setOnItemClickListener(new LinearListView.OnItemClickListener() {
                        @Override
                        public void onItemClick(LinearListView parent, View view, int position, long id) {
                        }
                    });
                }

                @Override
                public void onAnimationEnd(Animator animation) {
                    imageViewProfileAvatar.setImageDrawable(newProfile.getAvatar());

                    linearListViewProfileList.setOnItemClickListener(new LinearListView.OnItemClickListener() {
                        @Override
                        public void onItemClick(LinearListView parent, View view, int position, long id) {
                            if (position != 0) {
                                selectProfile(mProfileAdapter.getItem(position));
                            }
                        }
                    });
                }

                @Override
                public void onAnimationCancel(Animator animation) {
                }

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

            AnimatorSet profileInSet = new AnimatorSet();
            profileInSet.playTogether(ObjectAnimator.ofFloat(imageViewProfileAvatar, "alpha", 0, 1),
                    ObjectAnimator.ofFloat(imageViewProfileAvatar, "scaleX", 0.5f, 1),
                    ObjectAnimator.ofFloat(imageViewProfileAvatar, "scaleY", 0.5f, 1));

            profileSet.playSequentially(profileOutSet, profileInSet);
            animators.add(profileSet);
        }
        if (animators.size() > 0) {
            /* Play animation */
            AnimatorSet set = new AnimatorSet();
            set.playTogether(animators);
            set.setDuration(getResources().getInteger(R.integer.md_profile_switching_anim_time));
            textSet.setDuration(getResources().getInteger(R.integer.md_profile_switching_anim_time) / 2);
            profileSet.setDuration(getResources().getInteger(R.integer.md_profile_switching_anim_time) / 2);
            for (Animator.AnimatorListener listener : listeners) {
                set.addListener(listener);
            }
            set.start();
        }
    }
}

From source file:org.pouyadr.ui.LocationActivity.java

@Override
public View createView(Context context) {
    actionBar.setBackButtonImage(R.drawable.ic_ab_back);
    actionBar.setAllowOverlayTitle(true);
    if (AndroidUtilities.isTablet()) {
        actionBar.setOccupyStatusBar(false);
    }//from  www .  j a va  2 s .c  om
    actionBar.setAddToContainer(messageObject != null);

    actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
        @Override
        public void onItemClick(int id) {
            if (id == -1) {
                finishFragment();
            } else if (id == map_list_menu_map) {
                if (googleMap != null) {
                    googleMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
                }
            } else if (id == map_list_menu_satellite) {
                if (googleMap != null) {
                    googleMap.setMapType(GoogleMap.MAP_TYPE_SATELLITE);
                }
            } else if (id == map_list_menu_hybrid) {
                if (googleMap != null) {
                    googleMap.setMapType(GoogleMap.MAP_TYPE_HYBRID);
                }
            } else if (id == share) {
                try {
                    double lat = messageObject.messageOwner.media.geo.lat;
                    double lon = messageObject.messageOwner.media.geo._long;
                    getParentActivity().startActivity(new Intent(android.content.Intent.ACTION_VIEW,
                            Uri.parse("geo:" + lat + "," + lon + "?q=" + lat + "," + lon)));
                } catch (Exception e) {
                    FileLog.e("tmessages", e);
                }
            }
        }
    });

    ActionBarMenu menu = actionBar.createMenu();
    if (messageObject != null) {
        if (messageObject.messageOwner.media.title != null
                && messageObject.messageOwner.media.title.length() > 0) {
            actionBar.setTitle(messageObject.messageOwner.media.title);
            if (messageObject.messageOwner.media.address != null
                    && messageObject.messageOwner.media.address.length() > 0) {
                actionBar.setSubtitle(messageObject.messageOwner.media.address);
            }
        } else {
            actionBar.setTitle(LocaleController.getString("ChatLocation", R.string.ChatLocation));
        }
        menu.addItem(share, R.drawable.share);
    } else {
        actionBar.setTitle(LocaleController.getString("ShareLocation", R.string.ShareLocation));

        ActionBarMenuItem item = menu.addItem(0, R.drawable.ic_ab_search).setIsSearchField(true)
                .setActionBarMenuItemSearchListener(new ActionBarMenuItem.ActionBarMenuItemSearchListener() {
                    @Override
                    public void onSearchExpand() {
                        searching = true;
                        listView.setVisibility(View.GONE);
                        mapViewClip.setVisibility(View.GONE);
                        searchListView.setVisibility(View.VISIBLE);
                        searchListView.setEmptyView(emptyTextLayout);
                    }

                    @Override
                    public void onSearchCollapse() {
                        searching = false;
                        searchWas = false;
                        searchListView.setEmptyView(null);
                        listView.setVisibility(View.VISIBLE);
                        mapViewClip.setVisibility(View.VISIBLE);
                        searchListView.setVisibility(View.GONE);
                        emptyTextLayout.setVisibility(View.GONE);
                        searchAdapter.searchDelayed(null, null);
                    }

                    @Override
                    public void onTextChanged(EditText editText) {
                        if (searchAdapter == null) {
                            return;
                        }
                        String text = editText.getText().toString();
                        if (text.length() != 0) {
                            searchWas = true;
                        }
                        searchAdapter.searchDelayed(text, userLocation);
                    }
                });
        item.getSearchField().setHint(LocaleController.getString("Search", R.string.Search));
    }

    ActionBarMenuItem item = menu.addItem(0, R.drawable.ic_ab_other);
    item.addSubItem(map_list_menu_map, LocaleController.getString("Map", R.string.Map), 0);
    item.addSubItem(map_list_menu_satellite, LocaleController.getString("Satellite", R.string.Satellite), 0);
    item.addSubItem(map_list_menu_hybrid, LocaleController.getString("Hybrid", R.string.Hybrid), 0);
    fragmentView = new FrameLayout(context) {
        private boolean first = true;

        @Override
        protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
            super.onLayout(changed, left, top, right, bottom);

            if (changed) {
                fixLayoutInternal(first);
                first = false;
            }
        }
    };
    FrameLayout frameLayout = (FrameLayout) fragmentView;

    locationButton = new ImageView(context);
    locationButton.setBackgroundResource(R.drawable.floating_user_states);
    locationButton.setImageResource(R.drawable.myloc_on);
    locationButton.setScaleType(ImageView.ScaleType.CENTER);
    if (Build.VERSION.SDK_INT >= 21) {
        StateListAnimator animator = new StateListAnimator();
        animator.addState(new int[] { android.R.attr.state_pressed },
                ObjectAnimator
                        .ofFloat(locationButton, "translationZ", AndroidUtilities.dp(2), AndroidUtilities.dp(4))
                        .setDuration(200));
        animator.addState(new int[] {},
                ObjectAnimator
                        .ofFloat(locationButton, "translationZ", AndroidUtilities.dp(4), AndroidUtilities.dp(2))
                        .setDuration(200));
        locationButton.setStateListAnimator(animator);
        locationButton.setOutlineProvider(new ViewOutlineProvider() {
            @Override
            public void getOutline(View view, Outline outline) {
                outline.setOval(0, 0, AndroidUtilities.dp(56), AndroidUtilities.dp(56));
            }
        });
    }

    if (messageObject != null) {
        mapView = new MapView(context);
        frameLayout.setBackgroundDrawable(new MapPlaceholderDrawable());
        mapView.onCreate(null);
        try {
            MapsInitializer.initialize(context);
            //                googleMap = mapView.getMap();
        } catch (Exception e) {
            FileLog.e("tmessages", e);
        }

        FrameLayout bottomView = new FrameLayout(context);
        bottomView.setBackgroundResource(R.drawable.location_panel);
        frameLayout.addView(bottomView,
                LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 60, Gravity.LEFT | Gravity.BOTTOM));
        bottomView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (userLocation != null) {
                    LatLng latLng = new LatLng(userLocation.getLatitude(), userLocation.getLongitude());
                    if (googleMap != null) {
                        CameraUpdate position = CameraUpdateFactory.newLatLngZoom(latLng,
                                googleMap.getMaxZoomLevel() - 4);
                        googleMap.animateCamera(position);
                    }
                }
            }
        });

        avatarImageView = new BackupImageView(context);
        avatarImageView.setRoundRadius(AndroidUtilities.dp(20));
        bottomView.addView(avatarImageView,
                LayoutHelper.createFrame(40, 40,
                        Gravity.TOP | (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT),
                        LocaleController.isRTL ? 0 : 12, 12, LocaleController.isRTL ? 12 : 0, 0));

        nameTextView = new TextView(context);
        nameTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
        nameTextView.setTextColor(0xff212121);
        nameTextView.setMaxLines(1);
        nameTextView.setTypeface(AndroidUtilities.getTypeface(org.pouyadr.finalsoft.Fonts.CurrentFont()));
        nameTextView.setEllipsize(TextUtils.TruncateAt.END);
        nameTextView.setSingleLine(true);
        nameTextView.setGravity(LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT);
        bottomView.addView(nameTextView,
                LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT,
                        Gravity.TOP | (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT),
                        LocaleController.isRTL ? 12 : 72, 10, LocaleController.isRTL ? 72 : 12, 0));

        distanceTextView = new TextView(context);
        distanceTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
        distanceTextView.setTextColor(0xff2f8cc9);
        distanceTextView.setMaxLines(1);
        distanceTextView.setEllipsize(TextUtils.TruncateAt.END);
        distanceTextView.setSingleLine(true);
        distanceTextView.setGravity(LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT);
        bottomView.addView(distanceTextView,
                LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT,
                        Gravity.TOP | (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT),
                        LocaleController.isRTL ? 12 : 72, 33, LocaleController.isRTL ? 72 : 12, 0));

        userLocation = new Location("network");
        userLocation.setLatitude(messageObject.messageOwner.media.geo.lat);
        userLocation.setLongitude(messageObject.messageOwner.media.geo._long);
        if (googleMap != null) {
            LatLng latLng = new LatLng(userLocation.getLatitude(), userLocation.getLongitude());
            try {
                googleMap.addMarker(new MarkerOptions().position(latLng)
                        .icon(BitmapDescriptorFactory.fromResource(R.drawable.map_pin)));
            } catch (Exception e) {
                FileLog.e("tmessages", e);
            }
            CameraUpdate position = CameraUpdateFactory.newLatLngZoom(latLng, googleMap.getMaxZoomLevel() - 4);
            googleMap.moveCamera(position);
        }

        ImageView routeButton = new ImageView(context);
        routeButton.setBackgroundResource(R.drawable.floating_states);
        routeButton.setImageResource(R.drawable.navigate);
        routeButton.setScaleType(ImageView.ScaleType.CENTER);
        if (Build.VERSION.SDK_INT >= 21) {
            StateListAnimator animator = new StateListAnimator();
            animator.addState(new int[] { android.R.attr.state_pressed }, ObjectAnimator
                    .ofFloat(routeButton, "translationZ", AndroidUtilities.dp(2), AndroidUtilities.dp(4))
                    .setDuration(200));
            animator.addState(new int[] {}, ObjectAnimator
                    .ofFloat(routeButton, "translationZ", AndroidUtilities.dp(4), AndroidUtilities.dp(2))
                    .setDuration(200));
            routeButton.setStateListAnimator(animator);
            routeButton.setOutlineProvider(new ViewOutlineProvider() {
                @Override
                public void getOutline(View view, Outline outline) {
                    outline.setOval(0, 0, AndroidUtilities.dp(56), AndroidUtilities.dp(56));
                }
            });
        }
        frameLayout.addView(routeButton,
                LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT,
                        (LocaleController.isRTL ? Gravity.LEFT : Gravity.RIGHT) | Gravity.BOTTOM,
                        LocaleController.isRTL ? 14 : 0, 0, LocaleController.isRTL ? 0 : 14, 28));
        routeButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (Build.VERSION.SDK_INT >= 23) {
                    Activity activity = getParentActivity();
                    if (activity != null) {
                        if (activity.checkSelfPermission(
                                Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
                            showPermissionAlert(true);
                            return;
                        }
                    }
                }
                if (myLocation != null) {
                    try {
                        Intent intent = new Intent(android.content.Intent.ACTION_VIEW,
                                Uri.parse(String.format(Locale.US,
                                        "http://maps.google.com/maps?saddr=%f,%f&daddr=%f,%f",
                                        myLocation.getLatitude(), myLocation.getLongitude(),
                                        messageObject.messageOwner.media.geo.lat,
                                        messageObject.messageOwner.media.geo._long)));
                        getParentActivity().startActivity(intent);
                    } catch (Exception e) {
                        FileLog.e("tmessages", e);
                    }
                }
            }
        });

        frameLayout.addView(locationButton,
                LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT,
                        (LocaleController.isRTL ? Gravity.LEFT : Gravity.RIGHT) | Gravity.BOTTOM,
                        LocaleController.isRTL ? 14 : 0, 0, LocaleController.isRTL ? 0 : 14, 100));
        locationButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (Build.VERSION.SDK_INT >= 23) {
                    Activity activity = getParentActivity();
                    if (activity != null) {
                        if (activity.checkSelfPermission(
                                Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
                            showPermissionAlert(true);
                            return;
                        }
                    }
                }
                if (myLocation != null && googleMap != null) {
                    googleMap.animateCamera(CameraUpdateFactory.newLatLngZoom(
                            new LatLng(myLocation.getLatitude(), myLocation.getLongitude()),
                            googleMap.getMaxZoomLevel() - 4));
                }
            }
        });
    } else {
        searchWas = false;
        searching = false;
        mapViewClip = new FrameLayout(context);
        mapViewClip.setBackgroundDrawable(new MapPlaceholderDrawable());
        if (adapter != null) {
            adapter.destroy();
        }
        if (searchAdapter != null) {
            searchAdapter.destroy();
        }

        listView = new ListView(context);
        listView.setAdapter(adapter = new LocationActivityAdapter(context));
        listView.setVerticalScrollBarEnabled(false);
        listView.setDividerHeight(0);
        listView.setDivider(null);
        frameLayout.addView(listView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT,
                LayoutHelper.MATCH_PARENT, Gravity.LEFT | Gravity.TOP));
        listView.setOnScrollListener(new AbsListView.OnScrollListener() {
            @Override
            public void onScrollStateChanged(AbsListView view, int scrollState) {

            }

            @Override
            public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount,
                    int totalItemCount) {
                if (totalItemCount == 0) {
                    return;
                }
                updateClipView(firstVisibleItem);
            }
        });
        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                if (position == 1) {
                    if (delegate != null && userLocation != null) {
                        TLRPC.TL_messageMediaGeo location = new TLRPC.TL_messageMediaGeo();
                        location.geo = new TLRPC.TL_geoPoint();
                        location.geo.lat = userLocation.getLatitude();
                        location.geo._long = userLocation.getLongitude();
                        delegate.didSelectLocation(location);
                    }
                    finishFragment();
                } else {
                    TLRPC.TL_messageMediaVenue object = adapter.getItem(position);
                    if (object != null && delegate != null) {
                        delegate.didSelectLocation(object);
                    }
                    finishFragment();
                }
            }
        });
        adapter.setDelegate(new BaseLocationAdapter.BaseLocationAdapterDelegate() {
            @Override
            public void didLoadedSearchResult(ArrayList<TLRPC.TL_messageMediaVenue> places) {
                if (!wasResults && !places.isEmpty()) {
                    wasResults = true;
                }
            }
        });
        adapter.setOverScrollHeight(overScrollHeight);

        frameLayout.addView(mapViewClip, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT,
                LayoutHelper.MATCH_PARENT, Gravity.LEFT | Gravity.TOP));

        mapView = new MapView(context) {
            @Override
            public boolean onInterceptTouchEvent(MotionEvent ev) {
                if (Build.VERSION.SDK_INT >= 11) {
                    if (ev.getAction() == MotionEvent.ACTION_DOWN) {
                        if (animatorSet != null) {
                            animatorSet.cancel();
                        }
                        animatorSet = new AnimatorSet();
                        animatorSet.setDuration(200);
                        animatorSet.playTogether(
                                ObjectAnimator.ofFloat(markerImageView, "translationY",
                                        markerTop + -AndroidUtilities.dp(10)),
                                ObjectAnimator.ofFloat(markerXImageView, "alpha", 1.0f));
                        animatorSet.start();
                    } else if (ev.getAction() == MotionEvent.ACTION_UP) {
                        if (animatorSet != null) {
                            animatorSet.cancel();
                        }
                        animatorSet = new AnimatorSet();
                        animatorSet.setDuration(200);
                        animatorSet.playTogether(
                                ObjectAnimator.ofFloat(markerImageView, "translationY", markerTop),
                                ObjectAnimator.ofFloat(markerXImageView, "alpha", 0.0f));
                        animatorSet.start();
                    }
                }
                if (ev.getAction() == MotionEvent.ACTION_MOVE) {
                    if (!userLocationMoved) {
                        if (Build.VERSION.SDK_INT >= 11) {
                            AnimatorSet animatorSet = new AnimatorSet();
                            animatorSet.setDuration(200);
                            animatorSet.play(ObjectAnimator.ofFloat(locationButton, "alpha", 1.0f));
                            animatorSet.start();
                        } else {
                            locationButton.setVisibility(VISIBLE);
                        }
                        userLocationMoved = true;
                    }
                    if (googleMap != null && userLocation != null) {
                        userLocation.setLatitude(googleMap.getCameraPosition().target.latitude);
                        userLocation.setLongitude(googleMap.getCameraPosition().target.longitude);
                    }
                    adapter.setCustomLocation(userLocation);
                }
                return super.onInterceptTouchEvent(ev);
            }
        };
        try {
            mapView.onCreate(null);
        } catch (Exception e) {
            FileLog.e("tmessages", e);
        }
        try {
            MapsInitializer.initialize(context);
            //                googleMap = mapView.getMap();
        } catch (Exception e) {
            FileLog.e("tmessages", e);
        }

        View shadow = new View(context);
        shadow.setBackgroundResource(R.drawable.header_shadow_reverse);
        mapViewClip.addView(shadow,
                LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 3, Gravity.LEFT | Gravity.BOTTOM));

        markerImageView = new ImageView(context);
        markerImageView.setImageResource(R.drawable.map_pin);
        mapViewClip.addView(markerImageView,
                LayoutHelper.createFrame(24, 42, Gravity.TOP | Gravity.CENTER_HORIZONTAL));

        if (Build.VERSION.SDK_INT >= 11) {
            markerXImageView = new ImageView(context);
            markerXImageView.setAlpha(0.0f);
            markerXImageView.setImageResource(R.drawable.place_x);
            mapViewClip.addView(markerXImageView,
                    LayoutHelper.createFrame(14, 14, Gravity.TOP | Gravity.CENTER_HORIZONTAL));
        }

        mapViewClip.addView(locationButton,
                LayoutHelper.createFrame(Build.VERSION.SDK_INT >= 21 ? 56 : 60,
                        Build.VERSION.SDK_INT >= 21 ? 56 : 60,
                        (LocaleController.isRTL ? Gravity.LEFT : Gravity.RIGHT) | Gravity.BOTTOM,
                        LocaleController.isRTL ? 14 : 0, 0, LocaleController.isRTL ? 0 : 14, 14));
        locationButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (Build.VERSION.SDK_INT >= 23) {
                    Activity activity = getParentActivity();
                    if (activity != null) {
                        if (activity.checkSelfPermission(
                                Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
                            showPermissionAlert(false);
                            return;
                        }
                    }
                }
                if (myLocation != null && googleMap != null) {
                    if (Build.VERSION.SDK_INT >= 11) {
                        AnimatorSet animatorSet = new AnimatorSet();
                        animatorSet.setDuration(200);
                        animatorSet.play(ObjectAnimator.ofFloat(locationButton, "alpha", 0.0f));
                        animatorSet.start();
                    } else {
                        locationButton.setVisibility(View.INVISIBLE);
                    }
                    adapter.setCustomLocation(null);
                    userLocationMoved = false;
                    googleMap.animateCamera(CameraUpdateFactory
                            .newLatLng(new LatLng(myLocation.getLatitude(), myLocation.getLongitude())));
                }
            }
        });
        if (Build.VERSION.SDK_INT >= 11) {
            locationButton.setAlpha(0.0f);
        } else {
            locationButton.setVisibility(View.INVISIBLE);
        }

        emptyTextLayout = new LinearLayout(context);
        emptyTextLayout.setVisibility(View.GONE);
        emptyTextLayout.setOrientation(LinearLayout.VERTICAL);
        frameLayout.addView(emptyTextLayout, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT,
                LayoutHelper.MATCH_PARENT, Gravity.LEFT | Gravity.TOP, 0, 100, 0, 0));
        emptyTextLayout.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                return true;
            }
        });

        TextView emptyTextView = new TextView(context);
        emptyTextView.setTextColor(0xff808080);
        emptyTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 20);
        emptyTextView.setGravity(Gravity.CENTER);
        emptyTextView.setText(LocaleController.getString("NoResult", R.string.NoResult));
        emptyTextLayout.addView(emptyTextView,
                LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, 0.5f));

        FrameLayout frameLayoutEmpty = new FrameLayout(context);
        emptyTextLayout.addView(frameLayoutEmpty,
                LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, 0.5f));

        searchListView = new ListView(context);
        searchListView.setVisibility(View.GONE);
        searchListView.setDividerHeight(0);
        searchListView.setDivider(null);
        searchListView.setAdapter(searchAdapter = new LocationActivitySearchAdapter(context));
        frameLayout.addView(searchListView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT,
                LayoutHelper.MATCH_PARENT, Gravity.LEFT | Gravity.TOP));
        searchListView.setOnScrollListener(new AbsListView.OnScrollListener() {
            @Override
            public void onScrollStateChanged(AbsListView view, int scrollState) {
                if (scrollState == SCROLL_STATE_TOUCH_SCROLL && searching && searchWas) {
                    AndroidUtilities.hideKeyboard(getParentActivity().getCurrentFocus());
                }
            }

            @Override
            public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount,
                    int totalItemCount) {

            }
        });
        searchListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                TLRPC.TL_messageMediaVenue object = searchAdapter.getItem(position);
                if (object != null && delegate != null) {
                    delegate.didSelectLocation(object);
                }
                finishFragment();
            }
        });

        if (googleMap != null) {
            userLocation = new Location("network");
            userLocation.setLatitude(20.659322);
            userLocation.setLongitude(-11.406250);
        }

        frameLayout.addView(actionBar);
    }

    if (googleMap != null) {
        try {
            googleMap.setMyLocationEnabled(true);
        } catch (Exception e) {
            FileLog.e("tmessages", e);
        }
        googleMap.getUiSettings().setMyLocationButtonEnabled(false);
        googleMap.getUiSettings().setZoomControlsEnabled(false);
        googleMap.getUiSettings().setCompassEnabled(false);
        googleMap.setOnMyLocationChangeListener(new GoogleMap.OnMyLocationChangeListener() {
            @Override
            public void onMyLocationChange(Location location) {
                positionMarker(location);
            }
        });
        positionMarker(myLocation = getLastLocation());
    }

    return fragmentView;
}

From source file:trendoidtechnologies.com.navigationdrawerlibrary.DrawerView.java

private void animateToProfile(DrawerProfile profile) {
    if (loggingEnabled)
        Log.d(TAG, "animateToProfile(*" + profile.getId() + ")");

    if (mProfileAdapter.getCount() > 1) {
        List<Animator> animators = new ArrayList<>();
        List<Animator.AnimatorListener> listeners = new ArrayList<>();

        final DrawerProfile oldProfile = mProfileAdapter.getItem(0);
        final DrawerProfile newProfile = profile;

        boolean isRtl = Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1
                && TextUtilsCompat.getLayoutDirectionFromLocale(Locale.getDefault()) == LAYOUT_DIRECTION_RTL;
        int rtlSign = isRtl ? -1 : 1;

        /* Background animation */

        AlphaSatColorMatrixEvaluator evaluator = new AlphaSatColorMatrixEvaluator();
        final AnimatableColorMatrixColorFilter filter = new AnimatableColorMatrixColorFilter(
                evaluator.getColorMatrix());

        ObjectAnimator backgroundAnimator = ObjectAnimator.ofObject(filter, "colorMatrix", evaluator,
                evaluator.getColorMatrix());
        backgroundAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @Override//from  w  w w .ja v  a2s.  c o m
            public void onAnimationUpdate(ValueAnimator animation) {
                imageViewProfileBackgroundOverlay.setColorFilter(filter.getColorFilter());
            }
        });
        animators.add(backgroundAnimator);

        listeners.add(new Animator.AnimatorListener() {
            @Override
            public void onAnimationStart(Animator animation) {
                imageViewProfileBackground.setImageDrawable(oldProfile.getBackground());

                imageViewProfileBackgroundOverlay.setImageDrawable(newProfile.getBackground());
                imageViewProfileBackgroundOverlay.setColorFilter(filter.getColorFilter());
                imageViewProfileBackgroundOverlay.setVisibility(VISIBLE);

                imageViewProfileAvatarSecondary.setClickable(false);
            }

            @Override
            public void onAnimationEnd(Animator animation) {
                imageViewProfileBackground.setImageDrawable(newProfile.getBackground());

                if (newProfile.getBackground() instanceof BitmapDrawable) {
                    new Palette.Builder(((BitmapDrawable) newProfile.getBackground()).getBitmap())
                            .resizeBitmapSize(500).generate(new Palette.PaletteAsyncListener() {
                                @Override
                                public void onGenerated(Palette palette) {
                                    Palette.Swatch vibrantSwatch = palette.getVibrantSwatch();
                                    if (vibrantSwatch != null) {
                                        textViewProfileAvatarCount
                                                .setTextColor(vibrantSwatch.getTitleTextColor());
                                        textViewProfileAvatarCount.getBackground()
                                                .setColorFilter(vibrantSwatch.getRgb(), PorterDuff.Mode.SRC_IN);
                                    }
                                }
                            });
                }

                imageViewProfileBackgroundOverlay.setVisibility(GONE);

                if (hasOnProfileSwitchListener()) {
                    onProfileSwitchListener.onSwitch(oldProfile, oldProfile.getId(), newProfile,
                            newProfile.getId());
                }
            }

            @Override
            public void onAnimationCancel(Animator animation) {
            }

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

        /* Text animation */

        AnimatorSet textSet = new AnimatorSet();

        AnimatorSet textOutSet = new AnimatorSet();
        textOutSet.playTogether(ObjectAnimator.ofFloat(linearLayoutProfileTextContainer, "alpha", 1, 0),
                ObjectAnimator.ofFloat(linearLayoutProfileTextContainer, "translationX", 0,
                        getWidth() / 4 * rtlSign));
        textOutSet.addListener(new Animator.AnimatorListener() {
            @Override
            public void onAnimationStart(Animator animation) {
            }

            @Override
            public void onAnimationEnd(Animator animation) {
                updateProfileTheme();
                if (newProfile.hasName()) {
                    textViewProfileName.setText(newProfile.getName());
                    textViewProfileName.setVisibility(VISIBLE);
                } else {
                    textViewProfileName.setVisibility(GONE);
                }
                if (newProfile.hasDescription()) {
                    textViewProfileDescription.setText(newProfile.getDescription());
                    textViewProfileDescription.setVisibility(VISIBLE);
                } else {
                    textViewProfileDescription.setVisibility(GONE);
                }
            }

            @Override
            public void onAnimationCancel(Animator animation) {
            }

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

        AnimatorSet textInSet = new AnimatorSet();
        textInSet.playTogether(ObjectAnimator.ofFloat(linearLayoutProfileTextContainer, "alpha", 0, 1),
                ObjectAnimator.ofFloat(linearLayoutProfileTextContainer, "translationX",
                        -getWidth() / 4 * rtlSign, 0));

        textSet.playSequentially(textOutSet, textInSet);
        animators.add(textSet);

        AnimatorSet profileSet = new AnimatorSet();
        if (mProfileAdapter.getCount() == 2) {

            /* Avatar animation */

            int translation = isRtl
                    ? (relativeLayoutProfileContent.getWidth()
                            - getResources().getDimensionPixelSize(R.dimen.md_big_avatar_size)
                            - 2 * getResources().getDimensionPixelSize(R.dimen.md_baseline))
                    : (imageViewProfileAvatarSecondary.getLeft()
                            - getResources().getDimensionPixelSize(R.dimen.md_baseline));
            float scale = getResources().getDimension(R.dimen.md_avatar_size)
                    / getResources().getDimension(R.dimen.md_big_avatar_size);
            float translationCorrect = (getResources().getDimension(R.dimen.md_avatar_size)
                    - getResources().getDimension(R.dimen.md_big_avatar_size)) / 2;

            listeners.add(new Animator.AnimatorListener() {
                @Override
                public void onAnimationStart(Animator animation) {
                    imageViewProfileAvatarSecondary.setPivotX(0);
                    imageViewProfileAvatarSecondary.setPivotY(0);
                }

                @Override
                public void onAnimationEnd(Animator animation) {

                    imageViewProfileAvatar.setTranslationX(0);
                    imageViewProfileAvatar.setTranslationY(0);
                    imageViewProfileAvatar.setScaleX(1);
                    imageViewProfileAvatar.setScaleY(1);
                    imageViewProfileAvatarSecondary.setTranslationX(0);
                    imageViewProfileAvatarSecondary.setScaleX(1);
                    imageViewProfileAvatarSecondary.setScaleY(1);

                    if (oldProfile.hasAvatar()) {

                        imageViewProfileAvatarSecondary.setImageDrawable(oldProfile.getAvatar());
                        imageViewProfileAvatarSecondary.setVisibility(VISIBLE);
                    } else {
                        imageViewProfileAvatarSecondary.setVisibility(INVISIBLE);
                    }

                    if (newProfile.hasAvatar()) {

                        imageViewProfileAvatar.setImageDrawable(newProfile.getAvatar());
                        imageViewProfileAvatar.setVisibility(VISIBLE);
                        imageViewProfileAvatarSecondary.setClickable(true);
                    } else {
                        imageViewProfileAvatar.setVisibility(INVISIBLE);
                        imageViewProfileAvatarSecondary.setClickable(false);
                    }
                }

                @Override
                public void onAnimationCancel(Animator animation) {
                }

                @Override
                public void onAnimationRepeat(Animator animation) {
                }
            });
            if (oldProfile.hasAvatar()) {

                ObjectAnimator stepTranslateXAnimator = ObjectAnimator.ofFloat(imageViewProfileAvatar,
                        "translationX", 0, translation * rtlSign + translationCorrect);
                stepTranslateXAnimator.setInterpolator(new StepInterpolator());
                animators.add(stepTranslateXAnimator);

                ObjectAnimator stepTranslateYAnimator = ObjectAnimator.ofFloat(imageViewProfileAvatar,
                        "translationY", 0, translationCorrect);
                stepTranslateYAnimator.setInterpolator(new StepInterpolator());
                animators.add(stepTranslateYAnimator);

                animators.add(ObjectAnimator.ofFloat(imageViewProfileAvatar, "alpha", 1, 0, 1));
                animators.add(ObjectAnimator.ofFloat(imageViewProfileAvatar, "scaleX", 1, 0.5f, scale));
                animators.add(ObjectAnimator.ofFloat(imageViewProfileAvatar, "scaleY", 1, 0.5f, scale));
            }

            if (newProfile.hasAvatar()) {
                animators.add(ObjectAnimator.ofFloat(imageViewProfileAvatarSecondary, "translationX", 0,
                        -translation * rtlSign));
                animators.add(ObjectAnimator.ofFloat(imageViewProfileAvatarSecondary, "scaleX", 1, 1 / scale));
                animators.add(ObjectAnimator.ofFloat(imageViewProfileAvatarSecondary, "scaleY", 1, 1 / scale));
            }
        } else {
            AnimatorSet profileOutSet = new AnimatorSet();
            profileOutSet.playTogether(ObjectAnimator.ofFloat(imageViewProfileAvatar, "alpha", 1, 0),
                    ObjectAnimator.ofFloat(imageViewProfileAvatar, "scaleX", 1, 0.5f),
                    ObjectAnimator.ofFloat(imageViewProfileAvatar, "scaleY", 1, 0.5f));
            profileOutSet.addListener(new Animator.AnimatorListener() {
                @Override
                public void onAnimationStart(Animator animation) {
                    linearListViewProfileList.setOnItemClickListener(new LinearListView.OnItemClickListener() {
                        @Override
                        public void onItemClick(LinearListView parent, View view, int position, long id) {
                        }
                    });
                }

                @Override
                public void onAnimationEnd(Animator animation) {
                    imageViewProfileAvatar.setImageDrawable(newProfile.getAvatar());

                    linearListViewProfileList.setOnItemClickListener(new LinearListView.OnItemClickListener() {
                        @Override
                        public void onItemClick(LinearListView parent, View view, int position, long id) {
                            if (position != 0) {
                                selectProfile(mProfileAdapter.getItem(position));
                            }
                        }
                    });
                }

                @Override
                public void onAnimationCancel(Animator animation) {
                }

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

            AnimatorSet profileInSet = new AnimatorSet();
            profileInSet.playTogether(ObjectAnimator.ofFloat(imageViewProfileAvatar, "alpha", 0, 1),
                    ObjectAnimator.ofFloat(imageViewProfileAvatar, "scaleX", 0.5f, 1),
                    ObjectAnimator.ofFloat(imageViewProfileAvatar, "scaleY", 0.5f, 1));

            profileSet.playSequentially(profileOutSet, profileInSet);
            animators.add(profileSet);
        }
        if (animators.size() > 0) {
            /* Play animation */
            AnimatorSet set = new AnimatorSet();
            set.playTogether(animators);
            set.setDuration(getResources().getInteger(R.integer.md_profile_switching_anim_time));
            textSet.setDuration(getResources().getInteger(R.integer.md_profile_switching_anim_time) / 2);
            profileSet.setDuration(getResources().getInteger(R.integer.md_profile_switching_anim_time) / 2);
            for (Animator.AnimatorListener listener : listeners) {
                set.addListener(listener);
            }
            set.start();
        }
    }
}

From source file:ir.besteveryeverapp.ui.ActionBar.BottomSheet.java

public void dismissWithButtonClick(final int item) {
    if (dismissed) {
        return;/*from   w w w.  jav a2 s . c  o m*/
    }
    dismissed = true;
    cancelSheetAnimation();
    AnimatorSet animatorSet = new AnimatorSet();
    animatorSet.playTogether(
            ObjectAnimator.ofFloat(containerView, "translationY",
                    containerView.getMeasuredHeight() + AndroidUtilities.dp(10)),
            ObjectAnimator.ofInt(backDrawable, "alpha", 0));
    animatorSet.setDuration(180);
    animatorSet.setInterpolator(new AccelerateInterpolator());
    animatorSet.addListener(new AnimatorListenerAdapterProxy() {
        @Override
        public void onAnimationEnd(Animator animation) {
            if (currentSheetAnimation != null && currentSheetAnimation.equals(animation)) {
                currentSheetAnimation = null;
                if (onClickListener != null) {
                    onClickListener.onClick(BottomSheet.this, item);
                }
                AndroidUtilities.runOnUIThread(new Runnable() {
                    @Override
                    public void run() {
                        try {
                            BottomSheet.super.dismiss();
                        } catch (Exception e) {
                            FileLog.e("tmessages", e);
                        }
                    }
                });
            }
        }

        @Override
        public void onAnimationCancel(Animator animation) {
            if (currentSheetAnimation != null && currentSheetAnimation.equals(animation)) {
                currentSheetAnimation = null;
            }
        }
    });
    animatorSet.start();
    currentSheetAnimation = animatorSet;
}

From source file:com.b44t.ui.ActionBar.BottomSheet.java

public void dismissWithButtonClick(final int item) {
    if (dismissed) {
        return;// w w w.j a v  a 2 s  .c  om
    }
    dismissed = true;
    cancelSheetAnimation();
    AnimatorSet animatorSet = new AnimatorSet();
    animatorSet.playTogether(
            ObjectAnimator.ofFloat(containerView, "translationY",
                    containerView.getMeasuredHeight() + AndroidUtilities.dp(10)),
            ObjectAnimator.ofInt(backDrawable, "alpha", 0));
    animatorSet.setDuration(180);
    animatorSet.setInterpolator(new AccelerateInterpolator());
    animatorSet.addListener(new AnimatorListenerAdapterProxy() {
        @Override
        public void onAnimationEnd(Animator animation) {
            if (currentSheetAnimation != null && currentSheetAnimation.equals(animation)) {
                currentSheetAnimation = null;
                if (onClickListener != null) {
                    onClickListener.onClick(BottomSheet.this, item);
                }
                AndroidUtilities.runOnUIThread(new Runnable() {
                    @Override
                    public void run() {
                        try {
                            BottomSheet.super.dismiss();
                        } catch (Exception e) {
                            FileLog.e("messenger", e);
                        }
                    }
                });
            }
        }

        @Override
        public void onAnimationCancel(Animator animation) {
            if (currentSheetAnimation != null && currentSheetAnimation.equals(animation)) {
                currentSheetAnimation = null;
            }
        }
    });
    animatorSet.start();
    currentSheetAnimation = animatorSet;
}

From source file:com.google.android.apps.santatracker.village.Village.java

private void setIsDay(final boolean isDay, boolean smoothTransition) {
    ObjectAnimator sunAnim = ObjectAnimator.ofInt(this, "sunOffset", sunOffset, isDay ? 0 : mViewHeight);
    sunAnim.setInterpolator(new AnticipateOvershootInterpolator());
    sunAnim.setDuration(smoothTransition ? ImageWithAlphaAndSize.ANIM_DURATION : 0);
    sunAnim.addListener(new Animator.AnimatorListener() {
        @Override/*  ww  w.j  a v  a 2  s  .  c o  m*/
        public void onAnimationStart(Animator animation) {
            if (isDay) {
                mImageSun.setAlpha(ImageWithAlphaAndSize.OPAQUE);
            }
        }

        @Override
        public void onAnimationEnd(Animator animation) {
            if (!isDay) {
                mImageSun.setAlpha(ImageWithAlphaAndSize.INVISIBLE);
            }
        }

        @Override
        public void onAnimationCancel(Animator animation) {
        }

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

    AnimatorSet dayAnims = new AnimatorSet();
    dayAnims.playTogether(
            // Day values
            mImageSkyDay.fadeTransition(isDay, smoothTransition),
            mImageMountainsDay.fadeTransition(isDay, smoothTransition),
            mPaintMountainsDay.fadeTransition(isDay, smoothTransition));

    ObjectAnimator moonAnim = ObjectAnimator.ofInt(this, "moonOffset", moonOffset, isDay ? -mViewHeight : 0);
    moonAnim.setInterpolator(new AnticipateOvershootInterpolator());
    moonAnim.setDuration(smoothTransition ? ImageWithAlphaAndSize.ANIM_DURATION : 0);
    moonAnim.addListener(new Animator.AnimatorListener() {
        @Override
        public void onAnimationStart(Animator animation) {
            if (!isDay) {
                mImageMoon.setAlpha(ImageWithAlphaAndSize.OPAQUE);
            }
        }

        @Override
        public void onAnimationEnd(Animator animation) {
            if (isDay) {
                mImageMoon.setAlpha(ImageWithAlphaAndSize.INVISIBLE);
            }
        }

        @Override
        public void onAnimationCancel(Animator animation) {
        }

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

    AnimatorSet nightAnims = new AnimatorSet();
    nightAnims.playTogether(
            // Night values
            mImageSkyNight.fadeTransition(!isDay, !isDay && smoothTransition),
            mImageMountainsNight.fadeTransition(!isDay, !isDay && smoothTransition),
            mPaintMountainsNight.fadeTransition(!isDay, !isDay && smoothTransition));
    // When going to the day, delay night animation till after day time has kicked in
    if (isDay) {
        nightAnims.setStartDelay(ImageWithAlphaAndSize.ANIM_DURATION);
    }

    mFinalAnimations = nightAnims;

    sunAnim.start();
    dayAnims.start();
    moonAnim.start();
    nightAnims.start();
}

From source file:com.phonemetra.turbo.launcher.AsyncTaskCallback.java

@Override
public void onClick(View v) {
    // When we have exited all apps or are in transition, disregard clicks
    if (!mLauncher.isAllAppsVisible() || mLauncher.getWorkspace().isSwitchingState())
        return;//from  www.j av a  2s.co  m

    if (v instanceof PagedViewIcon) {
        // Animate some feedback to the click
        final AppInfo appInfo = (AppInfo) v.getTag();

        // Lock the drawable state to pressed until we return to Launcher
        if (mPressedIcon != null) {
            mPressedIcon.lockDrawableState();
        }
        mLauncher.startActivitySafely(v, appInfo.intent, appInfo);
        mLauncher.getStats().recordLaunch(appInfo.intent);
    } else if (v instanceof PagedViewWidget) {
        // Let the user know that they have to long press to add a widget
        if (mWidgetInstructionToast != null) {
            mWidgetInstructionToast.cancel();
        }
        mWidgetInstructionToast = Toast.makeText(getContext(), R.string.long_press_widget_to_add,
                Toast.LENGTH_SHORT);
        mWidgetInstructionToast.show();

        // Create a little animation to show that the widget can move
        float offsetY = getResources().getDimensionPixelSize(R.dimen.dragViewOffsetY);
        final ImageView p = (ImageView) v.findViewById(R.id.widget_preview);
        AnimatorSet bounce = LauncherAnimUtils.createAnimatorSet();
        ValueAnimator tyuAnim = LauncherAnimUtils.ofFloat(p, "translationY", offsetY);
        tyuAnim.setDuration(125);
        ValueAnimator tydAnim = LauncherAnimUtils.ofFloat(p, "translationY", 0f);
        tydAnim.setDuration(100);
        bounce.play(tyuAnim).before(tydAnim);
        bounce.setInterpolator(new AccelerateInterpolator());
        bounce.start();
    }
}