Example usage for android.animation ObjectAnimator start

List of usage examples for android.animation ObjectAnimator start

Introduction

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

Prototype

@Override
    public void start() 

Source Link

Usage

From source file:com.gigabytedevelopersinc.app.calculator.Calculator.java

private void dismissCling(final Cling cling, final String flag, int duration) {
    setPagingEnabled(true);//from   ww  w.  jav a  2s  . co m
    clingActive = false;

    if (cling != null) {
        cling.dismiss();
        if (getActionBar() != null) {
            getActionBar().show();
        }
        getActionBar().setBackgroundDrawable(new ColorDrawable(Color.parseColor("#FFFFFF")));
        ObjectAnimator anim = ObjectAnimator.ofFloat(cling, "alpha", 0f);
        anim.setDuration(duration);
        anim.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                cling.setVisibility(View.GONE);
                cling.cleanup();
                CalculatorSettings.saveKey(getContext(), flag, true);
            }
        });
        anim.start();
    }
}

From source file:com.android.contacts.quickcontact.QuickContactActivity.java

private void updateStatusBarColor() {
    if (mScroller == null || !CompatUtils.isLollipopCompatible()) {
        return;//from  www . ja  v a  2  s.  c  om
    }
    final int desiredStatusBarColor;
    // Only use a custom status bar color if QuickContacts touches the top of the viewport.
    if (mScroller.getScrollNeededToBeFullScreen() <= 0) {
        desiredStatusBarColor = mStatusBarColor;
    } else {
        desiredStatusBarColor = Color.TRANSPARENT;
    }
    // Animate to the new color.
    final ObjectAnimator animation = ObjectAnimator.ofInt(getWindow(), "statusBarColor",
            getWindow().getStatusBarColor(), desiredStatusBarColor);
    animation.setDuration(ANIMATION_STATUS_BAR_COLOR_CHANGE_DURATION);
    animation.setEvaluator(new ArgbEvaluator());
    animation.start();
}

From source file:com.kenmeidearu.materialdatetimepicker.date.DatePickerDialog.java

private void setCurrentView(final int viewIndex) {
    long millis = mCalendar.getTimeInMillis();
    switch (viewIndex) {
    case MONTH_AND_DAY_VIEW:
        ObjectAnimator pulseAnimator = Utils.getPulseAnimator(mDayOfWeekView, 0.9f, 1.05f);
        if (mDelayAnimation) {
            pulseAnimator.setStartDelay(ANIMATION_DELAY);
            mDelayAnimation = false;/*w w  w . jav  a 2  s . com*/
        }
        mDayPickerView.onDateChanged();
        if (mCurrentView != viewIndex) {
            mMonthAndDayView.setSelected(true);
            mSelectedDayTextView.setSelected(true);//tadinya month and day view
            mSelectedMonthTextView.setSelected(false);
            mYearView.setSelected(false);
            mHourView.setSelected(false);
            mMinuteView.setSelected(false);
            mSecondView.setSelected(false);
            mAmPmTextView.setSelected(false);
            mHourView.setTextColor(getResources().getColor(R.color.mdtp_accent_color_focused));
            mMinuteView.setTextColor(getResources().getColor(R.color.mdtp_accent_color_focused));
            mSecondView.setTextColor(getResources().getColor(R.color.mdtp_accent_color_focused));
            mAnimator.setDisplayedChild(MONTH_AND_DAY_VIEW);
            mCurrentView = viewIndex;
        }
        pulseAnimator.start();

        int flags = DateUtils.FORMAT_SHOW_DATE;
        String dayString = DateUtils.formatDateTime(getActivity(), millis, flags);
        mAnimator.setContentDescription(mDayPickerDescription + ": " + dayString);
        Utils.tryAccessibilityAnnounce(mAnimator, mSelectDay);
        break;
    case MONTH_VIEW:
        pulseAnimator = Utils.getPulseAnimator(mSelectedMonthTextView, 0.85f, 1.1f);
        if (mDelayAnimation) {
            pulseAnimator.setStartDelay(ANIMATION_DELAY);
            mDelayAnimation = false;
        }
        mMonthPickerView.onDateChanged();
        if (mCurrentView != viewIndex) {
            mMonthAndDayView.setSelected(true);
            mSelectedDayTextView.setSelected(false);
            mSelectedMonthTextView.setSelected(true);
            mYearView.setSelected(false);
            mHourView.setSelected(false);
            mMinuteView.setSelected(false);
            mSecondView.setSelected(false);
            mAmPmTextView.setSelected(false);
            mHourView.setTextColor(getResources().getColor(R.color.mdtp_accent_color_focused));
            mMinuteView.setTextColor(getResources().getColor(R.color.mdtp_accent_color_focused));
            mSecondView.setTextColor(getResources().getColor(R.color.mdtp_accent_color_focused));
            mAnimator.setDisplayedChild(MONTH_VIEW);
            mCurrentView = viewIndex;
        }
        pulseAnimator.start();

        CharSequence monthString = MONTH_FORMAT.format(millis);
        mAnimator.setContentDescription(mMonthPickerDescription + ": " + monthString);
        Utils.tryAccessibilityAnnounce(mAnimator, mSelectMonth);
        break;
    case YEAR_VIEW:
        pulseAnimator = Utils.getPulseAnimator(mYearView, 0.85f, 1.1f);
        if (mDelayAnimation) {
            pulseAnimator.setStartDelay(ANIMATION_DELAY);
            mDelayAnimation = false;
        }
        mYearPickerView.onDateChanged();
        if (mCurrentView != viewIndex) {
            mMonthAndDayView.setSelected(false);
            mSelectedDayTextView.setSelected(false);
            mSelectedMonthTextView.setSelected(false);
            mYearView.setSelected(true);
            mHourView.setSelected(false);
            mMinuteView.setSelected(false);
            mSecondView.setSelected(false);
            mAmPmTextView.setSelected(false);
            mHourView.setTextColor(getResources().getColor(R.color.mdtp_accent_color_focused));
            mMinuteView.setTextColor(getResources().getColor(R.color.mdtp_accent_color_focused));
            mSecondView.setTextColor(getResources().getColor(R.color.mdtp_accent_color_focused));
            mAnimator.setDisplayedChild(YEAR_VIEW);
            mCurrentView = viewIndex;
        }
        pulseAnimator.start();

        CharSequence yearString = YEAR_FORMAT.format(millis);
        mAnimator.setContentDescription(mYearPickerDescription + ": " + yearString);
        Utils.tryAccessibilityAnnounce(mAnimator, mSelectYear);
        break;
    case HOUR_INDEX:
        pulseAnimator = Utils.getPulseAnimator(mHourView, 0.85f, 1.1f);
        if (mDelayAnimation) {
            pulseAnimator.setStartDelay(ANIMATION_DELAY);
            mDelayAnimation = false;
        }
        mHourPickerView.onDateChanged();
        if (mCurrentView != viewIndex) {
            mMonthAndDayView.setSelected(true);
            mSelectedDayTextView.setSelected(false);
            mSelectedMonthTextView.setSelected(false);
            mYearView.setSelected(false);
            mHourView.setSelected(true);
            mMinuteView.setSelected(false);
            mSecondView.setSelected(false);
            mAmPmTextView.setSelected(false);
            mHourView.setTextColor(getResources().getColor(R.color.mdtp_white));
            mMinuteView.setTextColor(getResources().getColor(R.color.mdtp_accent_color_focused));
            mSecondView.setTextColor(getResources().getColor(R.color.mdtp_accent_color_focused));
            mAnimator.setDisplayedChild(HOUR_INDEX);
            mCurrentView = viewIndex;
        }
        pulseAnimator.start();

        CharSequence hourString = MONTH_FORMAT.format(millis);
        mAnimator.setContentDescription(mHourPickerDescription + ": " + hourString);
        Utils.tryAccessibilityAnnounce(mAnimator, mSelectHours);
        break;
    case MINUTE_INDEX:
        pulseAnimator = Utils.getPulseAnimator(mMinuteView, 0.85f, 1.1f);
        if (mDelayAnimation) {
            pulseAnimator.setStartDelay(ANIMATION_DELAY);
            mDelayAnimation = false;
        }
        mMinutePickerView.onDateChanged();
        if (mCurrentView != viewIndex) {
            mMonthAndDayView.setSelected(true);
            mSelectedDayTextView.setSelected(false);
            mSelectedMonthTextView.setSelected(false);
            mYearView.setSelected(false);
            mHourView.setSelected(false);
            mMinuteView.setSelected(true);
            mSecondView.setSelected(false);
            mAmPmTextView.setSelected(false);
            mHourView.setTextColor(getResources().getColor(R.color.mdtp_accent_color_focused));
            mMinuteView.setTextColor(getResources().getColor(R.color.mdtp_white));
            mSecondView.setTextColor(getResources().getColor(R.color.mdtp_accent_color_focused));
            mAnimator.setDisplayedChild(MINUTE_INDEX);
            mCurrentView = viewIndex;
        }
        pulseAnimator.start();

        CharSequence minuteString = MONTH_FORMAT.format(millis);
        mAnimator.setContentDescription(mMinutePickerDescription + ": " + minuteString);
        Utils.tryAccessibilityAnnounce(mAnimator, mSelectMinutes);
        break;
    case SECOND_INDEX:
        pulseAnimator = Utils.getPulseAnimator(mSecondView, 0.85f, 1.1f);
        if (mDelayAnimation) {
            pulseAnimator.setStartDelay(ANIMATION_DELAY);
            mDelayAnimation = false;
        }
        mSecondPickerView.onDateChanged();
        if (mCurrentView != viewIndex) {
            mMonthAndDayView.setSelected(true);
            mSelectedDayTextView.setSelected(false);
            mSelectedMonthTextView.setSelected(false);
            mYearView.setSelected(false);
            mHourView.setSelected(false);
            mMinuteView.setSelected(false);
            mSecondView.setSelected(true);
            mAmPmTextView.setSelected(false);
            mHourView.setTextColor(getResources().getColor(R.color.mdtp_accent_color_focused));
            mMinuteView.setTextColor(getResources().getColor(R.color.mdtp_accent_color_focused));
            mSecondView.setTextColor(getResources().getColor(R.color.mdtp_white));
            mAnimator.setDisplayedChild(SECOND_INDEX);
            mCurrentView = viewIndex;
        }
        pulseAnimator.start();

        CharSequence secondString = MONTH_FORMAT.format(millis);
        mAnimator.setContentDescription(mSecondPickerDescription + ": " + secondString);
        Utils.tryAccessibilityAnnounce(mAnimator, mSelectSeconds);
        break;
    }
}

From source file:com.android.contacts.quickcontact.QuickContactActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    Trace.beginSection("onCreate()");
    super.onCreate(savedInstanceState);

    if (RequestPermissionsActivity.startPermissionActivity(this)
            || RequestDesiredPermissionsActivity.startPermissionActivity(this)) {
        return;/*from w w w  . j  a  v  a2  s .  co m*/
    }

    final int previousScreenType = getIntent().getIntExtra(EXTRA_PREVIOUS_SCREEN_TYPE, ScreenType.UNKNOWN);
    Logger.logScreenView(this, ScreenType.QUICK_CONTACT, previousScreenType);

    if (CompatUtils.isLollipopCompatible()) {
        getWindow().setStatusBarColor(Color.TRANSPARENT);
    }

    processIntent(getIntent());

    // Show QuickContact in front of soft input
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM,
            WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);

    setContentView(R.layout.quickcontact_activity);

    mMaterialColorMapUtils = new MaterialColorMapUtils(getResources());

    mScroller = (MultiShrinkScroller) findViewById(R.id.multiscroller);

    mContactCard = (ExpandingEntryCardView) findViewById(R.id.communication_card);
    mNoContactDetailsCard = (ExpandingEntryCardView) findViewById(R.id.no_contact_data_card);
    mRecentCard = (ExpandingEntryCardView) findViewById(R.id.recent_card);
    mAboutCard = (ExpandingEntryCardView) findViewById(R.id.about_card);

    mCollapsedSuggestionCardView = (CardView) findViewById(R.id.collapsed_suggestion_card);
    mExpandSuggestionCardView = (CardView) findViewById(R.id.expand_suggestion_card);
    mCollapasedSuggestionHeader = findViewById(R.id.collapsed_suggestion_header);
    mCollapsedSuggestionCardTitle = (TextView) findViewById(R.id.collapsed_suggestion_card_title);
    mExpandSuggestionCardTitle = (TextView) findViewById(R.id.expand_suggestion_card_title);
    mSuggestionSummaryPhoto = (ImageView) findViewById(R.id.suggestion_icon);
    mSuggestionForName = (TextView) findViewById(R.id.suggestion_for_name);
    mSuggestionContactsNumber = (TextView) findViewById(R.id.suggestion_for_contacts_number);
    mSuggestionList = (LinearLayout) findViewById(R.id.suggestion_list);
    mSuggestionsCancelButton = (Button) findViewById(R.id.cancel_button);
    mSuggestionsLinkButton = (Button) findViewById(R.id.link_button);
    if (savedInstanceState != null) {
        mIsSuggestionListCollapsed = savedInstanceState.getBoolean(KEY_IS_SUGGESTION_LIST_COLLAPSED, true);
        mPreviousContactId = savedInstanceState.getLong(KEY_PREVIOUS_CONTACT_ID);
        mSuggestionsShouldAutoSelected = savedInstanceState.getBoolean(KEY_SUGGESTIONS_AUTO_SELECTED, true);
        mSelectedAggregationIds = (TreeSet<Long>) savedInstanceState
                .getSerializable(KEY_SELECTED_SUGGESTION_CONTACTS);
    } else {
        mIsSuggestionListCollapsed = true;
        mSelectedAggregationIds.clear();
    }
    if (mSelectedAggregationIds.isEmpty()) {
        disableLinkButton();
    } else {
        enableLinkButton();
    }
    mCollapasedSuggestionHeader.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View view) {
            mCollapsedSuggestionCardView.setVisibility(View.GONE);
            mExpandSuggestionCardView.setVisibility(View.VISIBLE);
            mIsSuggestionListCollapsed = false;
            mExpandSuggestionCardTitle.requestFocus();
            mExpandSuggestionCardTitle.sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
        }
    });

    mSuggestionsCancelButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View view) {
            mCollapsedSuggestionCardView.setVisibility(View.VISIBLE);
            mExpandSuggestionCardView.setVisibility(View.GONE);
            mIsSuggestionListCollapsed = true;
        }
    });

    mNoContactDetailsCard.setOnClickListener(mEntryClickHandler);
    mContactCard.setOnClickListener(mEntryClickHandler);
    mContactCard.setExpandButtonText(getResources().getString(R.string.expanding_entry_card_view_see_all));
    mContactCard.setOnCreateContextMenuListener(mEntryContextMenuListener);

    mRecentCard.setOnClickListener(mEntryClickHandler);
    mRecentCard.setTitle(getResources().getString(R.string.recent_card_title));

    mAboutCard.setOnClickListener(mEntryClickHandler);
    mAboutCard.setOnCreateContextMenuListener(mEntryContextMenuListener);

    mPhotoView = (QuickContactImageView) findViewById(R.id.photo);
    final View transparentView = findViewById(R.id.transparent_view);
    if (mScroller != null) {
        transparentView.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                mScroller.scrollOffBottom();
            }
        });
    }

    // Allow a shadow to be shown under the toolbar.
    ViewUtil.addRectangularOutlineProvider(findViewById(R.id.toolbar_parent), getResources());

    final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setActionBar(toolbar);
    getActionBar().setTitle(null);
    // Put a TextView with a known resource id into the ActionBar. This allows us to easily
    // find the correct TextView location & size later.
    toolbar.addView(getLayoutInflater().inflate(R.layout.quickcontact_title_placeholder, null));

    mHasAlreadyBeenOpened = savedInstanceState != null;
    mIsEntranceAnimationFinished = mHasAlreadyBeenOpened;
    mWindowScrim = new ColorDrawable(SCRIM_COLOR);
    mWindowScrim.setAlpha(0);
    getWindow().setBackgroundDrawable(mWindowScrim);

    mScroller.initialize(mMultiShrinkScrollerListener, mExtraMode == MODE_FULLY_EXPANDED);
    // mScroller needs to perform asynchronous measurements after initalize(), therefore
    // we can't mark this as GONE.
    mScroller.setVisibility(View.INVISIBLE);

    setHeaderNameText(R.string.missing_name);

    mSelectAccountFragmentListener = (SelectAccountDialogFragmentListener) getFragmentManager()
            .findFragmentByTag(FRAGMENT_TAG_SELECT_ACCOUNT);
    if (mSelectAccountFragmentListener == null) {
        mSelectAccountFragmentListener = new SelectAccountDialogFragmentListener();
        getFragmentManager().beginTransaction()
                .add(0, mSelectAccountFragmentListener, FRAGMENT_TAG_SELECT_ACCOUNT).commit();
        mSelectAccountFragmentListener.setRetainInstance(true);
    }
    mSelectAccountFragmentListener.setQuickContactActivity(this);

    SchedulingUtils.doOnPreDraw(mScroller, /* drawNextFrame = */ true, new Runnable() {
        @Override
        public void run() {
            if (!mHasAlreadyBeenOpened) {
                // The initial scrim opacity must match the scrim opacity that would be
                // achieved by scrolling to the starting position.
                final float alphaRatio = mExtraMode == MODE_FULLY_EXPANDED ? 1
                        : mScroller.getStartingTransparentHeightRatio();
                final int duration = getResources().getInteger(android.R.integer.config_shortAnimTime);
                final int desiredAlpha = (int) (0xFF * alphaRatio);
                ObjectAnimator o = ObjectAnimator.ofInt(mWindowScrim, "alpha", 0, desiredAlpha)
                        .setDuration(duration);

                o.start();
            }
        }
    });

    if (savedInstanceState != null) {
        final int color = savedInstanceState.getInt(KEY_THEME_COLOR, 0);
        SchedulingUtils.doOnPreDraw(mScroller, /* drawNextFrame = */ false, new Runnable() {
            @Override
            public void run() {
                // Need to wait for the pre draw before setting the initial scroll
                // value. Prior to pre draw all scroll values are invalid.
                if (mHasAlreadyBeenOpened) {
                    mScroller.setVisibility(View.VISIBLE);
                    mScroller.setScroll(mScroller.getScrollNeededToBeFullScreen());
                }
                // Need to wait for pre draw for setting the theme color. Setting the
                // header tint before the MultiShrinkScroller has been measured will
                // cause incorrect tinting calculations.
                if (color != 0) {
                    setThemeColor(mMaterialColorMapUtils.calculatePrimaryAndSecondaryColor(color));
                }
            }
        });
    }

    Trace.endSection();
}

From source file:com.amaze.filemanager.activities.MainActivity.java

void revealShow(final View view, boolean reveal) {

    if (reveal) {
        ObjectAnimator animator = ObjectAnimator.ofFloat(view, View.ALPHA, 0f, 1f);
        animator.setDuration(300); //ms
        animator.addListener(new AnimatorListenerAdapter() {
            @Override/*from  www . j  a va 2 s  .c o  m*/
            public void onAnimationStart(Animator animation) {
                view.setVisibility(View.VISIBLE);
            }
        });
        animator.start();
    } else {

        ObjectAnimator animator = ObjectAnimator.ofFloat(view, View.ALPHA, 1f, 0f);
        animator.setDuration(300); //ms
        animator.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                view.setVisibility(View.GONE);
            }
        });
        animator.start();

    }

}

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//from w  ww  . ja v a2 s.  c  om
        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:org.telegram.ui.Components.ChatAttachAlert.java

public ChatAttachAlert(Context context, final ChatActivity parentFragment) {
    super(context, false);
    baseFragment = parentFragment;/*from w  ww.  ja va2s . c  o  m*/
    setDelegate(this);
    setUseRevealAnimation(true);
    checkCamera(false);
    if (deviceHasGoodCamera) {
        CameraController.getInstance().initCamera();
    }
    NotificationCenter.getInstance().addObserver(this, NotificationCenter.albumsDidLoaded);
    NotificationCenter.getInstance().addObserver(this, NotificationCenter.reloadInlineHints);
    NotificationCenter.getInstance().addObserver(this, NotificationCenter.cameraInitied);
    shadowDrawable = context.getResources().getDrawable(R.drawable.sheet_shadow);

    containerView = listView = new RecyclerListView(context) {

        private int lastWidth;
        private int lastHeight;

        @Override
        public void requestLayout() {
            if (ignoreLayout) {
                return;
            }
            super.requestLayout();
        }

        @Override
        public boolean onInterceptTouchEvent(MotionEvent ev) {
            if (cameraAnimationInProgress) {
                return true;
            } else if (cameraOpened) {
                return processTouchEvent(ev);
            } else if (ev.getAction() == MotionEvent.ACTION_DOWN && scrollOffsetY != 0
                    && ev.getY() < scrollOffsetY) {
                dismiss();
                return true;
            }
            return super.onInterceptTouchEvent(ev);
        }

        @Override
        public boolean onTouchEvent(MotionEvent event) {
            if (cameraAnimationInProgress) {
                return true;
            } else if (cameraOpened) {
                return processTouchEvent(event);
            }
            return !isDismissed() && super.onTouchEvent(event);
        }

        @Override
        protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
            int height = MeasureSpec.getSize(heightMeasureSpec);
            if (Build.VERSION.SDK_INT >= 21) {
                height -= AndroidUtilities.statusBarHeight;
            }
            int contentSize = backgroundPaddingTop + AndroidUtilities.dp(294)
                    + (SearchQuery.inlineBots.isEmpty() ? 0
                            : ((int) Math.ceil(SearchQuery.inlineBots.size() / 4.0f) * AndroidUtilities.dp(100)
                                    + AndroidUtilities.dp(12)));
            int padding = contentSize == AndroidUtilities.dp(294) ? 0
                    : Math.max(0, (height - AndroidUtilities.dp(294)));
            if (padding != 0 && contentSize < height) {
                padding -= (height - contentSize);
            }
            if (padding == 0) {
                padding = backgroundPaddingTop;
            }
            if (getPaddingTop() != padding) {
                ignoreLayout = true;
                setPadding(backgroundPaddingLeft, padding, backgroundPaddingLeft, 0);
                ignoreLayout = false;
            }
            super.onMeasure(widthMeasureSpec,
                    MeasureSpec.makeMeasureSpec(Math.min(contentSize, height), MeasureSpec.EXACTLY));
        }

        @Override
        protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
            int width = right - left;
            int height = bottom - top;

            int newPosition = -1;
            int newTop = 0;

            int count = listView.getChildCount();
            int lastVisibleItemPosition = -1;
            int lastVisibleItemPositionTop = 0;
            if (count > 0) {
                View child = listView.getChildAt(listView.getChildCount() - 1);
                Holder holder = (Holder) listView.findContainingViewHolder(child);
                if (holder != null) {
                    lastVisibleItemPosition = holder.getAdapterPosition();
                    lastVisibleItemPositionTop = child.getTop();
                }
            }

            if (lastVisibleItemPosition >= 0 && height - lastHeight != 0) {
                newPosition = lastVisibleItemPosition;
                newTop = lastVisibleItemPositionTop + height - lastHeight - getPaddingTop();
            }

            super.onLayout(changed, left, top, right, bottom);

            if (newPosition != -1) {
                ignoreLayout = true;
                layoutManager.scrollToPositionWithOffset(newPosition, newTop);
                super.onLayout(false, left, top, right, bottom);
                ignoreLayout = false;
            }

            lastHeight = height;
            lastWidth = width;

            updateLayout();
            checkCameraViewPosition();
        }

        @Override
        public void onDraw(Canvas canvas) {
            if (useRevealAnimation && Build.VERSION.SDK_INT <= 19) {
                canvas.save();
                canvas.clipRect(backgroundPaddingLeft, scrollOffsetY,
                        getMeasuredWidth() - backgroundPaddingLeft, getMeasuredHeight());
                if (revealAnimationInProgress) {
                    canvas.drawCircle(revealX, revealY, revealRadius, ciclePaint);
                } else {
                    canvas.drawRect(backgroundPaddingLeft, scrollOffsetY,
                            getMeasuredWidth() - backgroundPaddingLeft, getMeasuredHeight(), ciclePaint);
                }
                canvas.restore();
            } else {
                shadowDrawable.setBounds(0, scrollOffsetY - backgroundPaddingTop, getMeasuredWidth(),
                        getMeasuredHeight());
                shadowDrawable.draw(canvas);
            }
        }

        @Override
        public void setTranslationY(float translationY) {
            super.setTranslationY(translationY);
            checkCameraViewPosition();
        }
    };

    listView.setWillNotDraw(false);
    listView.setClipToPadding(false);
    listView.setLayoutManager(layoutManager = new LinearLayoutManager(getContext()));
    layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
    listView.setAdapter(adapter = new ListAdapter(context));
    listView.setVerticalScrollBarEnabled(false);
    listView.setEnabled(true);
    listView.setGlowColor(0xfff5f6f7);
    listView.addItemDecoration(new RecyclerView.ItemDecoration() {
        @Override
        public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
            outRect.left = 0;
            outRect.right = 0;
            outRect.top = 0;
            outRect.bottom = 0;
        }
    });

    listView.setOnScrollListener(new RecyclerView.OnScrollListener() {
        @Override
        public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
            if (listView.getChildCount() <= 0) {
                return;
            }
            if (hintShowed) {
                if (layoutManager.findLastVisibleItemPosition() > 1) {
                    hideHint();
                    hintShowed = false;
                    ApplicationLoader.applicationContext
                            .getSharedPreferences("mainconfig", Activity.MODE_PRIVATE).edit()
                            .putBoolean("bothint", true).commit();
                }
            }
            updateLayout();
            checkCameraViewPosition();
        }
    });
    containerView.setPadding(backgroundPaddingLeft, 0, backgroundPaddingLeft, 0);

    attachView = new FrameLayout(context) {
        @Override
        protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
            super.onMeasure(widthMeasureSpec,
                    MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(294), MeasureSpec.EXACTLY));
        }

        @Override
        protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
            int width = right - left;
            int height = bottom - top;
            int t = AndroidUtilities.dp(8);
            attachPhotoRecyclerView.layout(0, t, width, t + attachPhotoRecyclerView.getMeasuredHeight());
            progressView.layout(0, t, width, t + progressView.getMeasuredHeight());
            lineView.layout(0, AndroidUtilities.dp(96), width,
                    AndroidUtilities.dp(96) + lineView.getMeasuredHeight());
            hintTextView.layout(width - hintTextView.getMeasuredWidth() - AndroidUtilities.dp(5),
                    height - hintTextView.getMeasuredHeight() - AndroidUtilities.dp(5),
                    width - AndroidUtilities.dp(5), height - AndroidUtilities.dp(5));

            int diff = (width - AndroidUtilities.dp(85 * 4 + 20)) / 3;
            for (int a = 0; a < 8; a++) {
                int y = AndroidUtilities.dp(105 + 95 * (a / 4));
                int x = AndroidUtilities.dp(10) + (a % 4) * (AndroidUtilities.dp(85) + diff);
                views[a].layout(x, y, x + views[a].getMeasuredWidth(), y + views[a].getMeasuredHeight());
            }
        }
    };

    views[8] = attachPhotoRecyclerView = new RecyclerListView(context);
    attachPhotoRecyclerView.setVerticalScrollBarEnabled(true);
    attachPhotoRecyclerView.setAdapter(photoAttachAdapter = new PhotoAttachAdapter(context));
    attachPhotoRecyclerView.setClipToPadding(false);
    attachPhotoRecyclerView.setPadding(AndroidUtilities.dp(8), 0, AndroidUtilities.dp(8), 0);
    attachPhotoRecyclerView.setItemAnimator(null);
    attachPhotoRecyclerView.setLayoutAnimation(null);
    attachPhotoRecyclerView.setOverScrollMode(RecyclerListView.OVER_SCROLL_NEVER);
    attachView.addView(attachPhotoRecyclerView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 80));
    attachPhotoLayoutManager = new LinearLayoutManager(context) {
        @Override
        public boolean supportsPredictiveItemAnimations() {
            return false;
        }
    };
    attachPhotoLayoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
    attachPhotoRecyclerView.setLayoutManager(attachPhotoLayoutManager);
    attachPhotoRecyclerView.setOnItemClickListener(new RecyclerListView.OnItemClickListener() {
        @SuppressWarnings("unchecked")
        @Override
        public void onItemClick(View view, int position) {
            if (baseFragment == null || baseFragment.getParentActivity() == null) {
                return;
            }
            if (!deviceHasGoodCamera || position != 0) {
                if (deviceHasGoodCamera) {
                    position--;
                }
                if (MediaController.allPhotosAlbumEntry == null) {
                    return;
                }
                ArrayList<Object> arrayList = (ArrayList) MediaController.allPhotosAlbumEntry.photos;
                if (position < 0 || position >= arrayList.size()) {
                    return;
                }
                PhotoViewer.getInstance().setParentActivity(baseFragment.getParentActivity());
                PhotoViewer.getInstance().openPhotoForSelect(arrayList, position, 0, ChatAttachAlert.this,
                        baseFragment);
                AndroidUtilities.hideKeyboard(baseFragment.getFragmentView().findFocus());
            } else {
                openCamera();
            }
        }
    });
    attachPhotoRecyclerView.setOnScrollListener(new RecyclerView.OnScrollListener() {
        @Override
        public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
            checkCameraViewPosition();
        }
    });

    views[9] = progressView = new EmptyTextProgressView(context);
    if (Build.VERSION.SDK_INT >= 23 && getContext().checkSelfPermission(
            Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
        progressView.setText(LocaleController.getString("PermissionStorage", R.string.PermissionStorage));
        progressView.setTextSize(16);
    } else {
        progressView.setText(LocaleController.getString("NoPhotos", R.string.NoPhotos));
        progressView.setTextSize(20);
    }
    attachView.addView(progressView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 80));
    attachPhotoRecyclerView.setEmptyView(progressView);

    views[10] = lineView = new View(getContext()) {
        @Override
        public boolean hasOverlappingRendering() {
            return false;
        }
    };
    lineView.setBackgroundColor(ContextCompat.getColor(context, R.color.divider));
    attachView.addView(lineView,
            new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 1, Gravity.TOP | Gravity.LEFT));
    CharSequence[] items = new CharSequence[] { LocaleController.getString("ChatCamera", R.string.ChatCamera),
            LocaleController.getString("ChatGallery", R.string.ChatGallery),
            LocaleController.getString("ChatVideo", R.string.ChatVideo),
            LocaleController.getString("AttachMusic", R.string.AttachMusic),
            LocaleController.getString("ChatDocument", R.string.ChatDocument),
            LocaleController.getString("AttachContact", R.string.AttachContact),
            LocaleController.getString("ChatLocation", R.string.ChatLocation), "" };
    for (int a = 0; a < 8; a++) {
        AttachButton attachButton = new AttachButton(context);
        attachButton.setTextAndIcon(items[a], Theme.attachButtonDrawables[a]);
        attachView.addView(attachButton, LayoutHelper.createFrame(85, 90, Gravity.LEFT | Gravity.TOP));
        attachButton.setTag(a);
        views[a] = attachButton;
        if (a == 7) {
            sendPhotosButton = attachButton;
            sendPhotosButton.imageView.setPadding(0, AndroidUtilities.dp(4), 0, 0);
        }
        attachButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                delegate.didPressedButton((Integer) v.getTag());
            }
        });
    }

    hintTextView = new TextView(context);
    hintTextView.setBackgroundResource(R.drawable.tooltip);
    hintTextView.setTextColor(Theme.CHAT_GIF_HINT_TEXT_COLOR);
    hintTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
    hintTextView.setPadding(AndroidUtilities.dp(10), 0, AndroidUtilities.dp(10), 0);
    hintTextView.setText(LocaleController.getString("AttachBotsHelp", R.string.AttachBotsHelp));
    hintTextView.setGravity(Gravity.CENTER_VERTICAL);
    hintTextView.setVisibility(View.INVISIBLE);
    hintTextView.setCompoundDrawablesWithIntrinsicBounds(R.drawable.scroll_tip, 0, 0, 0);
    hintTextView.setCompoundDrawablePadding(AndroidUtilities.dp(8));
    attachView.addView(hintTextView, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, 32,
            Gravity.RIGHT | Gravity.BOTTOM, 5, 0, 5, 5));

    for (int a = 0; a < 8; a++) {
        viewsCache.add(photoAttachAdapter.createHolder());
    }

    if (loading) {
        progressView.showProgress();
    } else {
        progressView.showTextView();
    }

    if (Build.VERSION.SDK_INT >= 16) {
        recordTime = new TextView(context);
        recordTime.setBackgroundResource(R.drawable.system);
        recordTime.getBackground()
                .setColorFilter(new PorterDuffColorFilter(0x66000000, PorterDuff.Mode.MULTIPLY));
        recordTime.setText("00:00");
        recordTime.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 15);
        recordTime.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
        recordTime.setAlpha(0.0f);
        recordTime.setTextColor(0xffffffff);
        recordTime.setPadding(AndroidUtilities.dp(10), AndroidUtilities.dp(5), AndroidUtilities.dp(10),
                AndroidUtilities.dp(5));
        container.addView(recordTime, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT,
                LayoutHelper.WRAP_CONTENT, Gravity.CENTER_HORIZONTAL | Gravity.TOP, 0, 16, 0, 0));

        cameraPanel = new FrameLayout(context) {
            @Override
            protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
                int cx = getMeasuredWidth() / 2;
                int cy = getMeasuredHeight() / 2;
                int cx2;
                int cy2;
                shutterButton.layout(cx - shutterButton.getMeasuredWidth() / 2,
                        cy - shutterButton.getMeasuredHeight() / 2, cx + shutterButton.getMeasuredWidth() / 2,
                        cy + shutterButton.getMeasuredHeight() / 2);
                if (getMeasuredWidth() == AndroidUtilities.dp(100)) {
                    cx = cx2 = getMeasuredWidth() / 2;
                    cy2 = cy + cy / 2 + AndroidUtilities.dp(17);
                    cy = cy / 2 - AndroidUtilities.dp(17);
                } else {
                    cx2 = cx + cx / 2 + AndroidUtilities.dp(17);
                    cx = cx / 2 - AndroidUtilities.dp(17);
                    cy = cy2 = getMeasuredHeight() / 2;
                }
                switchCameraButton.layout(cx2 - switchCameraButton.getMeasuredWidth() / 2,
                        cy2 - switchCameraButton.getMeasuredHeight() / 2,
                        cx2 + switchCameraButton.getMeasuredWidth() / 2,
                        cy2 + switchCameraButton.getMeasuredHeight() / 2);
                for (int a = 0; a < 2; a++) {
                    flashModeButton[a].layout(cx - flashModeButton[a].getMeasuredWidth() / 2,
                            cy - flashModeButton[a].getMeasuredHeight() / 2,
                            cx + flashModeButton[a].getMeasuredWidth() / 2,
                            cy + flashModeButton[a].getMeasuredHeight() / 2);
                }
            }
        };
        cameraPanel.setVisibility(View.GONE);
        cameraPanel.setAlpha(0.0f);
        container.addView(cameraPanel,
                LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 100, Gravity.LEFT | Gravity.BOTTOM));

        shutterButton = new ShutterButton(context);
        cameraPanel.addView(shutterButton, LayoutHelper.createFrame(84, 84, Gravity.CENTER));
        shutterButton.setDelegate(new ShutterButton.ShutterButtonDelegate() {
            @Override
            public void shutterLongPressed() {
                if (takingPhoto || baseFragment == null || baseFragment.getParentActivity() == null) {
                    return;
                }
                if (Build.VERSION.SDK_INT >= 23) {
                    if (baseFragment.getParentActivity().checkSelfPermission(
                            Manifest.permission.RECORD_AUDIO) != PackageManager.PERMISSION_GRANTED) {
                        baseFragment.getParentActivity()
                                .requestPermissions(new String[] { Manifest.permission.RECORD_AUDIO }, 21);
                        return;
                    }
                }
                for (int a = 0; a < 2; a++) {
                    flashModeButton[a].setAlpha(0.0f);
                }
                switchCameraButton.setAlpha(0.0f);
                cameraFile = AndroidUtilities.generateVideoPath();
                recordTime.setAlpha(1.0f);
                recordTime.setText("00:00");
                videoRecordTime = 0;
                videoRecordRunnable = new Runnable() {
                    @Override
                    public void run() {
                        if (videoRecordRunnable == null) {
                            return;
                        }
                        videoRecordTime++;
                        recordTime.setText(
                                String.format("%02d:%02d", videoRecordTime / 60, videoRecordTime % 60));
                        AndroidUtilities.runOnUIThread(videoRecordRunnable, 1000);
                    }
                };
                AndroidUtilities.lockOrientation(parentFragment.getParentActivity());
                CameraController.getInstance().recordVideo(cameraView.getCameraSession(), cameraFile,
                        new CameraController.VideoTakeCallback() {
                            @Override
                            public void onFinishVideoRecording(final Bitmap thumb) {
                                if (cameraFile == null || baseFragment == null) {
                                    return;
                                }
                                PhotoViewer.getInstance().setParentActivity(baseFragment.getParentActivity());
                                cameraPhoto = new ArrayList<>();
                                cameraPhoto.add(new MediaController.PhotoEntry(0, 0, 0,
                                        cameraFile.getAbsolutePath(), 0, true));
                                PhotoViewer.getInstance().openPhotoForSelect(cameraPhoto, 0, 2,
                                        new PhotoViewer.EmptyPhotoViewerProvider() {
                                            @Override
                                            public Bitmap getThumbForPhoto(MessageObject messageObject,
                                                    TLRPC.FileLocation fileLocation, int index) {
                                                return thumb;
                                            }

                                            @TargetApi(16)
                                            @Override
                                            public boolean cancelButtonPressed() {
                                                if (cameraOpened && cameraView != null && cameraFile != null) {
                                                    cameraFile.delete();
                                                    AndroidUtilities.runOnUIThread(new Runnable() {
                                                        @Override
                                                        public void run() {
                                                            if (cameraView != null && !isDismissed()
                                                                    && Build.VERSION.SDK_INT >= 21) {
                                                                cameraView.setSystemUiVisibility(
                                                                        View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                                                                                | View.SYSTEM_UI_FLAG_FULLSCREEN);
                                                            }
                                                        }
                                                    }, 1000);
                                                    CameraController.getInstance()
                                                            .startPreview(cameraView.getCameraSession());
                                                    cameraFile = null;
                                                }
                                                return true;
                                            }

                                            @Override
                                            public void sendButtonPressed(int index) {
                                                if (cameraFile == null) {
                                                    return;
                                                }
                                                AndroidUtilities
                                                        .addMediaToGallery(cameraFile.getAbsolutePath());
                                                baseFragment.sendMedia(
                                                        (MediaController.PhotoEntry) cameraPhoto.get(0),
                                                        PhotoViewer.getInstance().isMuteVideo());
                                                closeCamera(false);
                                                dismiss();
                                                cameraFile = null;
                                            }
                                        }, baseFragment);
                            }
                        });
                AndroidUtilities.runOnUIThread(videoRecordRunnable, 1000);
                shutterButton.setState(ShutterButton.State.RECORDING, true);
            }

            @Override
            public void shutterCancel() {
                cameraFile.delete();
                resetRecordState();
                CameraController.getInstance().stopVideoRecording(cameraView.getCameraSession(), true);
            }

            @Override
            public void shutterReleased() {
                if (takingPhoto) {
                    return;
                }
                if (shutterButton.getState() == ShutterButton.State.RECORDING) {
                    resetRecordState();
                    CameraController.getInstance().stopVideoRecording(cameraView.getCameraSession(), false);
                    shutterButton.setState(ShutterButton.State.DEFAULT, true);
                    return;
                }
                cameraFile = AndroidUtilities.generatePicturePath();
                takingPhoto = CameraController.getInstance().takePicture(cameraFile,
                        cameraView.getCameraSession(), new Runnable() {
                            @Override
                            public void run() {
                                takingPhoto = false;
                                if (cameraFile == null || baseFragment == null) {
                                    return;
                                }
                                PhotoViewer.getInstance().setParentActivity(baseFragment.getParentActivity());
                                cameraPhoto = new ArrayList<>();
                                int orientation = 0;
                                try {
                                    ExifInterface ei = new ExifInterface(cameraFile.getAbsolutePath());
                                    int exif = ei.getAttributeInt(ExifInterface.TAG_ORIENTATION,
                                            ExifInterface.ORIENTATION_NORMAL);
                                    switch (exif) {
                                    case ExifInterface.ORIENTATION_ROTATE_90:
                                        orientation = 90;
                                        break;
                                    case ExifInterface.ORIENTATION_ROTATE_180:
                                        orientation = 180;
                                        break;
                                    case ExifInterface.ORIENTATION_ROTATE_270:
                                        orientation = 270;
                                        break;
                                    }
                                } catch (Exception e) {
                                    FileLog.e("tmessages", e);
                                }
                                cameraPhoto.add(new MediaController.PhotoEntry(0, 0, 0,
                                        cameraFile.getAbsolutePath(), orientation, false));
                                PhotoViewer.getInstance().openPhotoForSelect(cameraPhoto, 0, 2,
                                        new PhotoViewer.EmptyPhotoViewerProvider() {
                                            @TargetApi(16)
                                            @Override
                                            public boolean cancelButtonPressed() {
                                                if (cameraOpened && cameraView != null && cameraFile != null) {
                                                    cameraFile.delete();
                                                    AndroidUtilities.runOnUIThread(new Runnable() {
                                                        @Override
                                                        public void run() {
                                                            if (cameraView != null && !isDismissed()
                                                                    && Build.VERSION.SDK_INT >= 21) {
                                                                cameraView.setSystemUiVisibility(
                                                                        View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                                                                                | View.SYSTEM_UI_FLAG_FULLSCREEN);
                                                            }
                                                        }
                                                    }, 1000);
                                                    CameraController.getInstance()
                                                            .startPreview(cameraView.getCameraSession());
                                                    cameraFile = null;
                                                }
                                                return true;
                                            }

                                            @Override
                                            public void sendButtonPressed(int index) {
                                                if (cameraFile == null) {
                                                    return;
                                                }
                                                AndroidUtilities
                                                        .addMediaToGallery(cameraFile.getAbsolutePath());
                                                baseFragment.sendMedia(
                                                        (MediaController.PhotoEntry) cameraPhoto.get(0), false);
                                                closeCamera(false);
                                                dismiss();
                                                cameraFile = null;
                                            }

                                            @Override
                                            public boolean scaleToFill() {
                                                return true;
                                            }
                                        }, baseFragment);
                            }
                        });
            }
        });

        switchCameraButton = new ImageView(context);
        switchCameraButton.setScaleType(ImageView.ScaleType.CENTER);
        cameraPanel.addView(switchCameraButton,
                LayoutHelper.createFrame(48, 48, Gravity.RIGHT | Gravity.CENTER_VERTICAL));
        switchCameraButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (takingPhoto || cameraView == null || !cameraView.isInitied()) {
                    return;
                }
                cameraInitied = false;
                cameraView.switchCamera();
                ObjectAnimator animator = ObjectAnimator.ofFloat(switchCameraButton, "scaleX", 0.0f)
                        .setDuration(100);
                animator.addListener(new AnimatorListenerAdapterProxy() {
                    @Override
                    public void onAnimationEnd(Animator animator) {
                        switchCameraButton.setImageResource(cameraView.isFrontface() ? R.drawable.camera_revert1
                                : R.drawable.camera_revert2);
                        ObjectAnimator.ofFloat(switchCameraButton, "scaleX", 1.0f).setDuration(100).start();
                    }
                });
                animator.start();
            }
        });

        for (int a = 0; a < 2; a++) {
            flashModeButton[a] = new ImageView(context);
            flashModeButton[a].setScaleType(ImageView.ScaleType.CENTER);
            flashModeButton[a].setVisibility(View.INVISIBLE);
            cameraPanel.addView(flashModeButton[a],
                    LayoutHelper.createFrame(48, 48, Gravity.LEFT | Gravity.TOP));
            flashModeButton[a].setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(final View currentImage) {
                    if (flashAnimationInProgress || cameraView == null || !cameraView.isInitied()
                            || !cameraOpened) {
                        return;
                    }
                    String current = cameraView.getCameraSession().getCurrentFlashMode();
                    String next = cameraView.getCameraSession().getNextFlashMode();
                    if (current.equals(next)) {
                        return;
                    }
                    cameraView.getCameraSession().setCurrentFlashMode(next);
                    flashAnimationInProgress = true;
                    ImageView nextImage = flashModeButton[0] == currentImage ? flashModeButton[1]
                            : flashModeButton[0];
                    nextImage.setVisibility(View.VISIBLE);
                    setCameraFlashModeIcon(nextImage, next);
                    AnimatorSet animatorSet = new AnimatorSet();
                    animatorSet.playTogether(
                            ObjectAnimator.ofFloat(currentImage, "translationY", 0, AndroidUtilities.dp(48)),
                            ObjectAnimator.ofFloat(nextImage, "translationY", -AndroidUtilities.dp(48), 0),
                            ObjectAnimator.ofFloat(currentImage, "alpha", 1.0f, 0.0f),
                            ObjectAnimator.ofFloat(nextImage, "alpha", 0.0f, 1.0f));
                    animatorSet.setDuration(200);
                    animatorSet.addListener(new AnimatorListenerAdapterProxy() {
                        @Override
                        public void onAnimationEnd(Animator animator) {
                            flashAnimationInProgress = false;
                            currentImage.setVisibility(View.INVISIBLE);
                        }
                    });
                    animatorSet.start();
                }
            });
        }
    }
}

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

private void growAndFadeOutFolderIcon(FolderIcon fi) {
    if (fi == null)
        return;/*w ww.j ava2  s . co m*/
    PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 0);
    PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.5f);
    PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.5f);

    FolderInfo info = (FolderInfo) fi.getTag();
    if (info.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
        CellLayout cl = (CellLayout) fi.getParent().getParent();
        CellLayout.LayoutParams lp = (CellLayout.LayoutParams) fi.getLayoutParams();
        cl.setFolderLeaveBehindCell(lp.cellX, lp.cellY);
    }

    // Push an ImageView copy of the FolderIcon into the DragLayer and hide the original
    copyFolderIconToImage(fi);
    fi.setVisibility(View.INVISIBLE);

    ObjectAnimator oa = LauncherAnimUtils.ofPropertyValuesHolder(mFolderIconImageView, alpha, scaleX, scaleY);
    oa.setDuration(getResources().getInteger(R.integer.config_folderAnimDuration));
    oa.start();
}

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

private void shrinkAndFadeInFolderIcon(final FolderIcon fi) {
    if (fi == null)
        return;/*from   w  ww  .j  a v a 2s.c  o  m*/
    PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 1.0f);
    PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.0f);
    PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.0f);

    final CellLayout cl = (CellLayout) fi.getParent().getParent();

    // We remove and re-draw the FolderIcon in-case it has changed
    mDragLayer.removeView(mFolderIconImageView);
    copyFolderIconToImage(fi);
    ObjectAnimator oa = LauncherAnimUtils.ofPropertyValuesHolder(mFolderIconImageView, alpha, scaleX, scaleY);
    oa.setDuration(getResources().getInteger(R.integer.config_folderAnimDuration));
    oa.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            if (cl != null) {
                cl.clearFolderLeaveBehind();
                // Remove the ImageView copy of the FolderIcon and make the original visible.
                mDragLayer.removeView(mFolderIconImageView);
                fi.setVisibility(View.VISIBLE);
            }
        }
    });
    oa.start();
}

From source file:com.aliyun.homeshell.Folder.java

public void animateOpen() {
    positionAndSizeAsIcon();/*w ww. ja  v a 2 s . c  om*/
    if (!(getParent() instanceof DragLayer))
        return;
    centerAboutIcon();
    PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 1);
    PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.0f);
    PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.0f);
    final ObjectAnimator oa = LauncherAnimUtils.ofPropertyValuesHolder(this, alpha, scaleX, scaleY);

    oa.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationStart(Animator animation) {
            sendCustomAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED,
                    String.format(getContext().getString(R.string.folder_opened), mContent.getCountX(),
                            mContent.getCountY()));
            mState = STATE_ANIMATING;
        }

        @Override
        public void onAnimationEnd(Animator animation) {
            mState = STATE_OPEN;
            setLayerType(LAYER_TYPE_NONE, null);

            /* YUNOS BEGIN */
            // ##date:2013/11/27 ##author:zhangqiang.zq
            // remove cling
            /*
             * Cling cling = mLauncher.showFirstRunFoldersCling(); if (cling
             * != null) { cling.bringToFront(); }
             */
            /* YUNOS END */
            setFocusOnFirstChild();
            setAlpha(1);
            setScaleX(1);
            setScaleY(1);
            /*YUNOS BEGIN*/
            //##date:2014/06/10 ##author:guoshuai.lgs ##BugID:
            //support the folder feature in mainmenu
            if (mInfo.isMainmenuFolder() && (LauncherApplication.isMainmenuMode())) {
                mLauncher.getAppsCustomizeTabHost().setVisibility(View.INVISIBLE);
            }
            /*YUNOS END*/
        }
    });
    oa.setDuration(mExpandDuration);
    setLayerType(LAYER_TYPE_HARDWARE, null);
    oa.start();
}