Example usage for android.view View setAlpha

List of usage examples for android.view View setAlpha

Introduction

In this page you can find the example usage for android.view View setAlpha.

Prototype

public void setAlpha(@FloatRange(from = 0.0, to = 1.0) float alpha) 

Source Link

Document

Sets the opacity of the view to a value from 0 to 1, where 0 means the view is completely transparent and 1 means the view is completely opaque.

Usage

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

/**
 * Bind the items start-end from the list.
 *
 * Implementation of the method from LauncherModel.Callbacks.
 *///  w w w  .  j  ava2  s.c  om
public void bindItems(ArrayList<ItemInfo> shortcuts, int start, int end) {
    setLoadOnResume();

    // Get the list of added shortcuts and intersect them with the set of shortcuts here
    Set<String> newApps = new HashSet<String>();
    newApps = mSharedPrefs.getStringSet(InstallShortcutReceiver.NEW_APPS_LIST_KEY, newApps);

    Workspace workspace = mWorkspace;
    for (int i = start; i < end; i++) {
        final ItemInfo item = shortcuts.get(i);

        // Short circuit if we are loading dock items for a configuration which has no dock
        if (item.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT && mHotseat == null) {
            continue;
        }

        switch (item.itemType) {
        case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION:
        case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT:
            ShortcutInfo info = (ShortcutInfo) item;
            String uri = info.intent.toUri(0).toString();
            View shortcut = createShortcut(info);
            workspace.addInScreen(shortcut, item.container, item.screen, item.cellX, item.cellY, 1, 1, false);
            boolean animateIconUp = false;
            synchronized (newApps) {
                if (newApps.contains(uri)) {
                    animateIconUp = newApps.remove(uri);
                }
            }
            if (animateIconUp) {
                // Prepare the view to be animated up
                shortcut.setAlpha(0f);
                shortcut.setScaleX(0f);
                shortcut.setScaleY(0f);
                mNewShortcutAnimatePage = item.screen;
                if (!mNewShortcutAnimateViews.contains(shortcut)) {
                    mNewShortcutAnimateViews.add(shortcut);
                }
            }
            break;
        case LauncherSettings.Favorites.ITEM_TYPE_FOLDER:
            FolderIcon newFolder = FolderIcon.fromXml(R.layout.folder_icon, this,
                    (ViewGroup) workspace.getChildAt(workspace.getCurrentPage()), (FolderInfo) item,
                    mIconCache);
            workspace.addInScreen(newFolder, item.container, item.screen, item.cellX, item.cellY, 1, 1, false);
            break;
        }
    }

    workspace.requestLayout();
}

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

@Override
protected void screenScrolled(int screenCenter) {
    super.screenScrolled(screenCenter);

    for (int i = 0; i < getChildCount(); i++) {
        View v = getPageAt(i);
        if (v != null) {
            float scrollProgress = getScrollProgress(screenCenter, v, i);

            float interpolatedProgress = mZInterpolator.getInterpolation(Math.abs(Math.min(scrollProgress, 0)));
            float scale = (1 - interpolatedProgress) + interpolatedProgress * TRANSITION_SCALE_FACTOR;
            float translationX = Math.min(0, scrollProgress) * v.getMeasuredWidth();

            float alpha;

            if (scrollProgress < 0) {
                alpha = scrollProgress < 0 ? mAlphaInterpolator.getInterpolation(1 - Math.abs(scrollProgress))
                        : 1.0f;//from  w w w .ja  v a  2  s.c  o m
            } else {
                // On large screens we need to fade the page as it nears its leftmost position
                alpha = mLeftScreenAlphaInterpolator.getInterpolation(1 - scrollProgress);
            }

            v.setCameraDistance(mDensity * CAMERA_DISTANCE);
            int pageWidth = v.getMeasuredWidth();
            int pageHeight = v.getMeasuredHeight();

            if (PERFORM_OVERSCROLL_ROTATION) {
                if (i == 0 && scrollProgress < 0) {
                    // Overscroll to the left
                    v.setPivotX(TRANSITION_PIVOT * pageWidth);
                    v.setRotationY(-TRANSITION_MAX_ROTATION * scrollProgress);
                    scale = 1.0f;
                    alpha = 1.0f;
                    // On the first page, we don't want the page to have any lateral motion
                    translationX = 0;
                } else if (i == getChildCount() - 1 && scrollProgress > 0) {
                    // Overscroll to the right
                    v.setPivotX((1 - TRANSITION_PIVOT) * pageWidth);
                    v.setRotationY(-TRANSITION_MAX_ROTATION * scrollProgress);
                    scale = 1.0f;
                    alpha = 1.0f;
                    // On the last page, we don't want the page to have any lateral motion.
                    translationX = 0;
                } else {
                    v.setPivotY(pageHeight / 2.0f);
                    v.setPivotX(pageWidth / 2.0f);
                    v.setRotationY(0f);
                }
            }

            v.setTranslationX(translationX);
            v.setScaleX(scale);
            v.setScaleY(scale);
            v.setAlpha(alpha);

            // If the view has 0 alpha, we set it to be invisible so as to prevent
            // it from accepting touches
            if (alpha == 0) {
                v.setVisibility(INVISIBLE);
            } else if (v.getVisibility() != VISIBLE) {
                v.setVisibility(VISIBLE);
            }
        }
    }
}

From source file:com.n2hsu.launcher.Page.java

private Runnable createPostDeleteAnimationRunnable(final View dragView) {
    return new Runnable() {
        @Override//from www  .j a va  2 s .  c  om
        public void run() {
            int dragViewIndex = indexOfChild(dragView);

            // For each of the pages around the drag view, animate them from
            // the previous
            // position to the new position in the layout (as a result of
            // the drag view moving
            // in the layout)
            // NOTE: We can make an assumption here because we have
            // side-bound pages that we
            // will always have pages to animate in from the left
            getOverviewModePages(mTempVisiblePagesRange);
            boolean isLastWidgetPage = (mTempVisiblePagesRange[0] == mTempVisiblePagesRange[1]);
            boolean slideFromLeft = (isLastWidgetPage || dragViewIndex > mTempVisiblePagesRange[0]);

            // Setup the scroll to the correct page before we swap the views
            if (slideFromLeft) {
                snapToPageImmediately(dragViewIndex - 1);
            }

            int firstIndex = (isLastWidgetPage ? 0 : mTempVisiblePagesRange[0]);
            int lastIndex = Math.min(mTempVisiblePagesRange[1], getPageCount() - 1);
            int lowerIndex = (slideFromLeft ? firstIndex : dragViewIndex + 1);
            int upperIndex = (slideFromLeft ? dragViewIndex - 1 : lastIndex);
            ArrayList<Animator> animations = new ArrayList<Animator>();
            for (int i = lowerIndex; i <= upperIndex; ++i) {
                View v = getChildAt(i);
                // dragViewIndex < pageUnderPointIndex, so after we remove
                // the
                // drag view all subsequent views to pageUnderPointIndex
                // will
                // shift down.
                int oldX = 0;
                int newX = 0;
                if (slideFromLeft) {
                    if (i == 0) {
                        // Simulate the page being offscreen with the page
                        // spacing
                        oldX = getViewportOffsetX() + getChildOffset(i) - getChildWidth(i) - mPageSpacing;
                    } else {
                        oldX = getViewportOffsetX() + getChildOffset(i - 1);
                    }
                    newX = getViewportOffsetX() + getChildOffset(i);
                } else {
                    oldX = getChildOffset(i) - getChildOffset(i - 1);
                    newX = 0;
                }

                // Animate the view translation from its old position to its
                // new
                // position
                AnimatorSet anim = (AnimatorSet) v.getTag();
                if (anim != null) {
                    anim.cancel();
                }

                // Note: Hacky, but we want to skip any optimizations to not
                // draw completely
                // hidden views
                v.setAlpha(Math.max(v.getAlpha(), 0.01f));
                v.setTranslationX(oldX - newX);
                anim = new AnimatorSet();
                anim.playTogether(ObjectAnimator.ofFloat(v, "translationX", 0f),
                        ObjectAnimator.ofFloat(v, "alpha", 1f));
                animations.add(anim);
                v.setTag(ANIM_TAG_KEY, anim);
            }

            AnimatorSet slideAnimations = new AnimatorSet();
            slideAnimations.playTogether(animations);
            slideAnimations.setDuration(DELETE_SLIDE_IN_SIDE_PAGE_DURATION);
            slideAnimations.addListener(new AnimatorListenerAdapter() {
                @Override
                public void onAnimationEnd(Animator animation) {
                    mDeferringForDelete = false;
                    onEndReordering();
                    onRemoveViewAnimationCompleted();
                }
            });
            slideAnimations.start();

            removeView(dragView);
            onRemoveView(dragView, true);
        }
    };
}

From source file:fr.shywim.antoinedaniel.ui.fragment.VideoDetailsFragment.java

private void bindSound(View view, Cursor cursor) {
    AppState appState = AppState.getInstance();

    final View card = view;
    final View downloadFrame = view.findViewById(R.id.sound_download_frame);
    final TextView tv = (TextView) view.findViewById(R.id.grid_text);
    final SquareImageView siv = (SquareImageView) view.findViewById(R.id.grid_image);
    final ImageView star = (ImageView) view.findViewById(R.id.ic_sound_fav);
    final ImageView menu = (ImageView) view.findViewById(R.id.ic_sound_menu);

    final String soundName = cursor
            .getString(cursor.getColumnIndex(ProviderContract.SoundEntry.COLUMN_SOUND_NAME));
    String imgId = cursor.getString(cursor.getColumnIndex(ProviderContract.SoundEntry.COLUMN_IMAGE_NAME));
    final String description = cursor.getString(cursor.getColumnIndex(ProviderContract.SoundEntry.COLUMN_DESC));
    final boolean favorite = appState.favSounds.contains(soundName)
            || cursor.getInt(cursor.getColumnIndex(ProviderContract.SoundEntry.COLUMN_FAVORITE)) == 1;
    final boolean widget = appState.widgetSounds.contains(soundName)
            || cursor.getInt(cursor.getColumnIndex(ProviderContract.SoundEntry.COLUMN_WIDGET)) == 1;
    final boolean downloaded = cursor
            .getInt(cursor.getColumnIndex(ProviderContract.SoundEntry.COLUMN_DOWNLOADED)) != 0;

    new Handler().post(new Runnable() {
        @Override//  w w  w .  ja v  a2 s. com
        public void run() {
            ContentValues cv = new ContentValues();
            File sndFile = new File(mContext.getExternalFilesDir(null) + "/snd/" + soundName + ".ogg");

            if (downloaded && !sndFile.exists()) {
                cv.put(ProviderContract.SoundEntry.COLUMN_DOWNLOADED, 0);
                mContext.getContentResolver().update(
                        Uri.withAppendedPath(ProviderConstants.SOUND_DOWNLOAD_NOTIFY_URI, soundName), cv, null,
                        null);
            }
        }
    });

    final View.OnClickListener playSound = new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            String category = mContext.getString(R.string.ana_cat_sound);
            String action = mContext.getString(R.string.ana_act_play);

            Bundle extras = new Bundle();
            extras.putString(SoundFragment.SOUND_TO_PLAY, soundName);
            extras.putBoolean(SoundFragment.LOOP, SoundUtils.isLoopingSet());
            Intent intent = new Intent(mContext, SoundService.class);
            intent.putExtras(extras);

            mContext.startService(intent);
            AnalyticsUtils.sendEvent(category, action, soundName);
        }
    };

    final View.OnClickListener downloadSound = new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            card.setOnClickListener(null);
            RotateAnimation animation = new RotateAnimation(0, 360, Animation.RELATIVE_TO_SELF, 0.5f,
                    Animation.RELATIVE_TO_SELF, 0.5f);
            animation.setInterpolator(new BounceInterpolator());
            animation.setFillAfter(true);
            animation.setFillEnabled(true);
            animation.setDuration(1000);
            animation.setRepeatCount(Animation.INFINITE);
            animation.setRepeatMode(Animation.RESTART);
            downloadFrame.findViewById(R.id.sound_download_icon).startAnimation(animation);

            DownloadService.startActionDownloadSound(mContext, soundName,
                    new SoundUtils.DownloadResultReceiver(new Handler(), downloadFrame, playSound, this));
        }
    };

    if (downloaded) {
        downloadFrame.setVisibility(View.GONE);
        downloadFrame.findViewById(R.id.sound_download_icon).clearAnimation();
        card.setOnClickListener(playSound);
    } else {
        downloadFrame.setAlpha(1);
        downloadFrame.findViewById(R.id.sound_download_icon).setScaleX(1);
        downloadFrame.findViewById(R.id.sound_download_icon).setScaleY(1);
        downloadFrame.setVisibility(View.VISIBLE);
        card.setOnClickListener(downloadSound);
    }

    menu.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            final ImageView menuIc = (ImageView) v;
            PopupMenu popup = new PopupMenu(mContext, menuIc);
            Menu menu = popup.getMenu();
            popup.getMenuInflater().inflate(R.menu.sound_menu, menu);

            if (favorite)
                menu.findItem(R.id.action_sound_fav).setTitle("Retirer des favoris");
            if (widget)
                menu.findItem(R.id.action_sound_wid).setTitle("Retirer du widget");

            popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
                @Override
                public boolean onMenuItemClick(MenuItem item) {
                    switch (item.getItemId()) {
                    case R.id.action_sound_fav:
                        SoundUtils.addRemoveFavorite(mContext, soundName);
                        return true;
                    case R.id.action_sound_wid:
                        SoundUtils.addRemoveWidget(mContext, soundName);
                        return true;
                    /*case R.id.action_sound_add:
                       return true;*/
                    case R.id.action_sound_ring:
                        SoundUtils.addRingtone(mContext, soundName, description);
                        return true;
                    case R.id.action_sound_share:
                        AnalyticsUtils.sendEvent(mContext.getString(R.string.ana_cat_soundcontext),
                                mContext.getString(R.string.ana_act_weblink), soundName);
                        ClipboardManager clipboard = (ClipboardManager) mContext
                                .getSystemService(Context.CLIPBOARD_SERVICE);
                        ClipData clip = ClipData.newPlainText("BAD link", "http://bad.shywim.fr/" + soundName);
                        clipboard.setPrimaryClip(clip);
                        Toast.makeText(mContext, R.string.toast_link_copied, Toast.LENGTH_LONG).show();
                        return true;
                    case R.id.action_sound_delete:
                        SoundUtils.delete(mContext, soundName);
                        return true;
                    default:
                        return false;
                    }
                }
            });

            popup.setOnDismissListener(new PopupMenu.OnDismissListener() {
                @Override
                public void onDismiss(PopupMenu menu) {
                    menuIc.setColorFilter(mContext.getResources().getColor(R.color.text_caption_dark));
                }
            });
            menuIc.setColorFilter(mContext.getResources().getColor(R.color.black));

            popup.show();
        }
    });

    tv.setText(description);
    siv.setTag(imgId);

    if (appState.favSounds.contains(soundName)) {
        star.setVisibility(View.VISIBLE);
    } else if (favorite) {
        star.setVisibility(View.VISIBLE);
        appState.favSounds.add(soundName);
    } else {
        star.setVisibility(View.INVISIBLE);
    }

    File file = new File(mContext.getExternalFilesDir(null) + "/img/" + imgId + ".jpg");
    Picasso.with(mContext).load(file).placeholder(R.drawable.noimg).fit().into(siv);
}

From source file:com.microsoft.mimickeralarm.appcore.AlarmListItemTouchHelperCallback.java

@Override
public void onChildDraw(Canvas canvas, RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, float dX,
        float dY, int actionState, boolean isCurrentlyActive) {

    if (actionState == ItemTouchHelper.ACTION_STATE_SWIPE) {

        View itemView = viewHolder.itemView;
        Resources resources = AlarmApplication.getAppContext().getResources();
        Bitmap icon = BitmapFactory.decodeResource(resources, R.drawable.delete_trash_can);
        int iconPadding = resources.getDimensionPixelOffset(R.dimen.alarm_list_delete_icon_padding);
        int maxDrawWidth = (iconPadding * 2) + icon.getWidth();

        Paint paint = new Paint();
        paint.setColor(ContextCompat.getColor(AlarmApplication.getAppContext(), R.color.red));

        int x = Math.round(Math.abs(dX));

        // Reset the dismiss flag if the view resets to its default position
        if (x == 0) {
            mCanDismiss = false;//from  w  w  w  .  j  av a 2  s .co m
        }

        // If we have travelled beyond the icon area via direct user interaction
        // we will dismiss when we get a swipe callback.  We do this to try to avoid
        // unwanted swipe dismissal
        if ((x > maxDrawWidth) && isCurrentlyActive) {
            mCanDismiss = true;
        }

        int drawWidth = Math.min(x, maxDrawWidth);
        // Cap the height of the drawable area to the selectable area - this improves the visual
        // for the first taller item in the alarm list
        int itemTop = itemView.getBottom() - resources.getDimensionPixelSize(R.dimen.alarm_list_item_height);

        if (dX > 0) {
            // Handle swiping to the right
            // Draw red background in area that we vacate up to maxDrawWidth
            canvas.drawRect((float) itemView.getLeft(), (float) itemTop, drawWidth,
                    (float) itemView.getBottom(), paint);

            // Only draw icon when we've past the padding threshold
            if (x > iconPadding) {

                Rect destRect = new Rect();
                destRect.left = itemView.getLeft() + iconPadding;
                destRect.top = itemTop + (itemView.getBottom() - itemTop - icon.getHeight()) / 2;
                int maxRight = destRect.left + icon.getWidth();
                destRect.right = Math.min(x, maxRight);
                destRect.bottom = destRect.top + icon.getHeight();

                // Only draw the appropriate parts of the bitmap as it is revealed
                Rect srcRect = null;
                if (x < maxRight) {
                    srcRect = new Rect();
                    srcRect.top = 0;
                    srcRect.left = 0;
                    srcRect.bottom = icon.getHeight();
                    srcRect.right = x - iconPadding;
                }

                canvas.drawBitmap(icon, srcRect, destRect, paint);
            }

        } else {
            // Handle swiping to the left
            // Draw red background in area that we vacate  up to maxDrawWidth
            canvas.drawRect((float) itemView.getRight() - drawWidth, (float) itemTop,
                    (float) itemView.getRight(), (float) itemView.getBottom(), paint);

            // Only draw icon when we've past the padding threshold
            if (x > iconPadding) {
                int fromLeftX = itemView.getRight() - x;
                Rect destRect = new Rect();
                destRect.right = itemView.getRight() - iconPadding;
                destRect.top = itemTop + (itemView.getBottom() - itemTop - icon.getHeight()) / 2;
                int maxFromLeft = destRect.right - icon.getWidth();
                destRect.left = Math.max(fromLeftX, maxFromLeft);
                destRect.bottom = destRect.top + icon.getHeight();

                // Only draw the appropriate parts of the bitmap as it is revealed
                Rect srcRect = null;
                if (fromLeftX > maxFromLeft) {
                    srcRect = new Rect();
                    srcRect.top = 0;
                    srcRect.right = icon.getWidth();
                    srcRect.bottom = icon.getHeight();
                    srcRect.left = srcRect.right - (x - iconPadding);
                }

                canvas.drawBitmap(icon, srcRect, destRect, paint);
            }
        }

        // Fade out the item as we swipe it
        float alpha = 1.0f - Math.abs(dX) / (float) itemView.getWidth();
        itemView.setAlpha(alpha);
        itemView.setTranslationX(dX);
    } else {
        super.onChildDraw(canvas, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive);
    }
}

From source file:xyz.klinker.blur.launcher3.Workspace.java

private void setTranslationAndAlpha(View v, float transX, float alpha) {
    if (v != null) {
        v.setTranslationX(transX);//from w ww . j  a va 2  s.  co  m
        v.setAlpha(alpha);
    }
}

From source file:org.telegram.ui.ChannelAdminLogActivity.java

private void updateMessagesVisisblePart() {
    if (chatListView == null) {
        return;/*w w w .j a  v  a2s . c  om*/
    }
    int count = chatListView.getChildCount();
    int height = chatListView.getMeasuredHeight();
    int minPositionHolder = Integer.MAX_VALUE;
    int minPositionDateHolder = Integer.MAX_VALUE;
    View minDateChild = null;
    View minChild = null;
    View minMessageChild = null;
    boolean foundTextureViewMessage = false;
    for (int a = 0; a < count; a++) {
        View view = chatListView.getChildAt(a);
        if (view instanceof ChatMessageCell) {
            ChatMessageCell messageCell = (ChatMessageCell) view;
            int top = messageCell.getTop();
            int bottom = messageCell.getBottom();
            int viewTop = top >= 0 ? 0 : -top;
            int viewBottom = messageCell.getMeasuredHeight();
            if (viewBottom > height) {
                viewBottom = viewTop + height;
            }
            messageCell.setVisiblePart(viewTop, viewBottom - viewTop);

            MessageObject messageObject = messageCell.getMessageObject();
            if (roundVideoContainer != null && messageObject.isRoundVideo()
                    && MediaController.getInstance().isPlayingMessage(messageObject)) {
                ImageReceiver imageReceiver = messageCell.getPhotoImage();
                roundVideoContainer.setTranslationX(imageReceiver.getImageX());
                roundVideoContainer
                        .setTranslationY(fragmentView.getPaddingTop() + top + imageReceiver.getImageY());
                fragmentView.invalidate();
                roundVideoContainer.invalidate();
                foundTextureViewMessage = true;
            }
        }
        if (view.getBottom() <= chatListView.getPaddingTop()) {
            continue;
        }
        int position = view.getBottom();
        if (position < minPositionHolder) {
            minPositionHolder = position;
            if (view instanceof ChatMessageCell || view instanceof ChatActionCell) {
                minMessageChild = view;
            }
            minChild = view;
        }
        if (view instanceof ChatActionCell && ((ChatActionCell) view).getMessageObject().isDateObject) {
            if (view.getAlpha() != 1.0f) {
                view.setAlpha(1.0f);
            }
            if (position < minPositionDateHolder) {
                minPositionDateHolder = position;
                minDateChild = view;
            }
        }
    }
    if (roundVideoContainer != null) {
        if (!foundTextureViewMessage) {
            roundVideoContainer.setTranslationY(-AndroidUtilities.roundMessageSize - 100);
            fragmentView.invalidate();
            MessageObject messageObject = MediaController.getInstance().getPlayingMessageObject();
            if (messageObject != null && messageObject.isRoundVideo() && checkTextureViewPosition) {
                MediaController.getInstance().setCurrentVideoVisible(false);
            }
        } else {
            MediaController.getInstance().setCurrentVideoVisible(true);
        }
    }
    if (minMessageChild != null) {
        MessageObject messageObject;
        if (minMessageChild instanceof ChatMessageCell) {
            messageObject = ((ChatMessageCell) minMessageChild).getMessageObject();
        } else {
            messageObject = ((ChatActionCell) minMessageChild).getMessageObject();
        }
        floatingDateView.setCustomDate(messageObject.messageOwner.date);
    }
    currentFloatingDateOnScreen = false;
    currentFloatingTopIsNotMessage = !(minChild instanceof ChatMessageCell
            || minChild instanceof ChatActionCell);
    if (minDateChild != null) {
        if (minDateChild.getTop() > chatListView.getPaddingTop() || currentFloatingTopIsNotMessage) {
            if (minDateChild.getAlpha() != 1.0f) {
                minDateChild.setAlpha(1.0f);
            }
            hideFloatingDateView(!currentFloatingTopIsNotMessage);
        } else {
            if (minDateChild.getAlpha() != 0.0f) {
                minDateChild.setAlpha(0.0f);
            }
            if (floatingDateAnimation != null) {
                floatingDateAnimation.cancel();
                floatingDateAnimation = null;
            }
            if (floatingDateView.getTag() == null) {
                floatingDateView.setTag(1);
            }
            if (floatingDateView.getAlpha() != 1.0f) {
                floatingDateView.setAlpha(1.0f);
            }
            currentFloatingDateOnScreen = true;
        }
        int offset = minDateChild.getBottom() - chatListView.getPaddingTop();
        if (offset > floatingDateView.getMeasuredHeight()
                && offset < floatingDateView.getMeasuredHeight() * 2) {
            floatingDateView.setTranslationY(-floatingDateView.getMeasuredHeight() * 2 + offset);
        } else {
            floatingDateView.setTranslationY(0);
        }
    } else {
        hideFloatingDateView(true);
        floatingDateView.setTranslationY(0);
    }
}

From source file:org.telegram.ui.Adapters.ContactsAdapter.java

@SuppressLint("NewApi")
@Override/* www . j a  v a2s  .  c  o  m*/
public View getItemView(int section, int position, View convertView, ViewGroup parent) {
    int type = getItemViewType(section, position);
    if (type == 4) {
        if (convertView == null) {
            convertView = new DividerCell(mContext);
            convertView.setPadding(AndroidUtilities.dp(LocaleController.isRTL ? 28 : 72), 0,
                    AndroidUtilities.dp(LocaleController.isRTL ? 72 : 28), 0);
            convertView.setBackgroundColor(ContextCompat.getColor(mContext, R.color.chat_list_background));
            convertView.setElevation(AndroidUtilities.dp(2));
        }
    } else if (type == 3) {
        if (convertView == null) {
            convertView = new GreySectionCell(mContext);
            ((GreySectionCell) convertView)
                    .setText(LocaleController.getString("Contacts", R.string.Contacts).toUpperCase());
            //convertView.setBackgroundColor(ContextCompat.getColor(mContext, R.color.s));
            convertView.setElevation(AndroidUtilities.dp(2));
        }
    } else if (type == 2) {
        if (convertView == null) {
            convertView = new TextCell(mContext);
            convertView.setBackgroundColor(ContextCompat.getColor(mContext, R.color.chat_list_background));
        }
        TextCell actionCell = (TextCell) convertView;
        if (needPhonebook) {
            actionCell.setTextAndIcon(LocaleController.getString("InviteFriends", R.string.InviteFriends),
                    R.drawable.menu_invite);
        } else if (isAdmin) {
            actionCell.setTextAndIcon(
                    LocaleController.getString("InviteToGroupByLink", R.string.InviteToGroupByLink),
                    R.drawable.menu_invite);
        } else {
            if (position == 0) {
                actionCell.setTextAndIcon(LocaleController.getString("NewGroup", R.string.NewGroup),
                        R.drawable.menu_newgroup);
            } else if (position == 1) {
                actionCell.setTextAndIcon(LocaleController.getString("NewSecretChat", R.string.NewSecretChat),
                        R.drawable.menu_secret);
            } else if (position == 2) {
                actionCell.setTextAndIcon(LocaleController.getString("NewChannel", R.string.NewChannel),
                        R.drawable.menu_broadcast);
            }
        }
    } else if (type == 1) {
        if (convertView == null) {
            convertView = new TextCell(mContext);
            convertView.setBackgroundColor(ContextCompat.getColor(mContext, R.color.chat_list_background));
        }
        ContactsController.Contact contact = ContactsController.getInstance().phoneBookContacts.get(position);
        TextCell textCell = (TextCell) convertView;
        if (contact.first_name != null && contact.last_name != null) {
            textCell.setText(contact.first_name + " " + contact.last_name);
        } else if (contact.first_name != null && contact.last_name == null) {
            textCell.setText(contact.first_name);
        } else {
            textCell.setText(contact.last_name);
        }
    } else if (type == 0) {
        if (convertView == null) {
            convertView = new UserCell(mContext, 58, 1, false);
            convertView.setBackgroundColor(ContextCompat.getColor(mContext, R.color.chat_list_background));
            ((UserCell) convertView).setStatusColors(0xffa8a8a8, 0xff3b84c0);
        }

        HashMap<String, ArrayList<TLRPC.TL_contact>> usersSectionsDict = onlyUsers == 2
                ? ContactsController.getInstance().usersMutualSectionsDict
                : ContactsController.getInstance().usersSectionsDict;
        ArrayList<String> sortedUsersSectionsArray = onlyUsers == 2
                ? ContactsController.getInstance().sortedUsersMutualSectionsArray
                : ContactsController.getInstance().sortedUsersSectionsArray;

        ArrayList<TLRPC.TL_contact> arr = usersSectionsDict
                .get(sortedUsersSectionsArray.get(section - (onlyUsers != 0 && !isAdmin ? 0 : 1)));
        TLRPC.User user = MessagesController.getInstance().getUser(arr.get(position).user_id);
        ((UserCell) convertView).setData(user, null, null, 0);
        if (checkedMap != null) {
            ((UserCell) convertView).setChecked(checkedMap.containsKey(user.id), !scrolling);
        }
        if (ignoreUsers != null) {
            if (ignoreUsers.containsKey(user.id)) {
                convertView.setAlpha(0.5f);
            } else {
                convertView.setAlpha(1.0f);
            }
        }
    }
    if (type != 4) {
        if (convertView instanceof ForegroundFrameLayout) {
            ((ForegroundFrameLayout) convertView).setForeground(R.drawable.list_selector);
        }
    }
    return convertView;
}

From source file:com.klinker.android.launcher.launcher3.Launcher.java

private void setupDrawer() {
    mWorkspace.setOnPageChangedListener(new Workspace.OnPageChangeListener() {
        @Override// w  w  w .ja  v a 2  s. c o  m
        public void onPageChanged(int page) {
            if (mLauncherDrawer == null) {
                return;
            }

            if (mLauncherDrawer.getDrawerLockMode(Gravity.LEFT) == LauncherDrawerLayout.LOCK_MODE_LOCKED_CLOSED
                    && !mWorkspace.isSmall()) {
                lockLauncherDrawer(false);
            }

            if (page == 0) {
                // on the first page
                mLauncherDrawer.setDrawerLeftEdgeSize(Launcher.this, 1.0f);
            } else {
                // somewhere in the middle
                mLauncherDrawer.setDrawerLeftEdgeSize(Launcher.this, .07f);
            }
        }

        @Override
        public void onScrollStart() {
            lockLauncherDrawer(true);
        }

        @Override
        public void onScrollEnd() {

        }
    });

    mDrawerPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
        @Override
        public void onPageSelected(int position) {
            mLauncherDrawer.setCurrentDrawerPage(position);
        }
    });

    mLauncherDrawer.setDrawerListener(new LauncherDrawerLayout.DrawerListener() {
        @Override
        public void onDrawerSlide(View drawerView, float slideOffset) {
            if (drawerView == mDrawerPager) {
                mDragLayer.setTranslationX(getScreenWidth() * slideOffset);
                ((PagesFragmentAdapter) mDrawerPager.getAdapter())
                        .adjustFragmentBackgroundAlpha(mDrawerPager.getCurrentItem(), slideOffset);
            } else {
                mDragLayer.setTranslationX(getScreenWidth() * slideOffset * -1);
                for (View v : ((BaseLauncherPage) extraFragment).getBackground()) {
                    v.setAlpha(slideOffset);
                }
            }
        }

        @Override
        public void onDrawerOpened(View drawerView) {
            if (drawerView == mDrawerPager) {
                mDragLayer.setTranslationX(getScreenWidth());
            } else {
                mDragLayer.setTranslationX(getScreenWidth() * -1);
            }

            sendBroadcast(new Intent("com.klinker.android.launcher.FRAGMENTS_OPENED"));
        }

        @Override
        public void onDrawerClosed(View drawerView) {
            mDragLayer.setTranslationX(0);
            sendBroadcast(new Intent("com.klinker.android.launcher.FRAGMENTS_CLOSED"));

            InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.hideSoftInputFromWindow(mLauncherDrawer.getWindowToken(), 0);
        }

        @Override
        public void onDrawerStateChanged(int newState) {
        }

        private int screenWidth = -1;

        private int getScreenWidth() {
            if (screenWidth == -1) {
                Display display = getWindowManager().getDefaultDisplay();
                Point size = new Point();
                display.getSize(size);
                screenWidth = size.x;
            }

            return screenWidth;
        }
    });

}

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

Animator getChangeStateAnimation(final State state, boolean animated, int delay, int snapPage) {
    if (mState == state) {
        return null;
    }/*from w ww.  j  a v  a 2  s  .c  om*/

    // Initialize animation arrays for the first time if necessary
    initAnimationArrays();

    AnimatorSet anim = animated ? LauncherAnimUtils.createAnimatorSet() : null;

    final State oldState = mState;
    final boolean oldStateIsNormal = (oldState == State.NORMAL);
    final boolean oldStateIsOverview = (oldState == State.OVERVIEW);
    setState(state);
    final boolean stateIsNormal = (state == State.NORMAL);
    final boolean stateIsOverview = (state == State.OVERVIEW);
    float finalBackgroundAlpha = stateIsOverview ? 1.0f : 0f;
    float finalPageIndicatorAlpha = stateIsOverview ? 0f : 1f;
    float finalOverviewPanelAlpha = stateIsOverview ? 1f : 0f;
    float finalWorkspaceTranslationY = stateIsOverview ? getOverviewModeTranslationY() : 0;

    boolean workspaceToOverview = (oldStateIsNormal && stateIsOverview);
    boolean overviewToWorkspace = (oldStateIsOverview && stateIsNormal);

    mNewScale = 1.0f;

    if (state != State.NORMAL) {
        if (stateIsOverview) {
            mNewScale = mOverviewModeShrinkFactor;
        }
    }

    final int duration = getResources().getInteger(R.integer.config_overviewTransitionTime);

    for (int i = 0; i < getChildCount(); i++) {
        final CellLayout cl = (CellLayout) getChildAt(i);
        float finalAlpha = 1f;

        if (stateIsOverview) {
            cl.setVisibility(VISIBLE);
            cl.setTranslationX(0f);
            cl.setTranslationY(0f);
            cl.setPivotX(cl.getMeasuredWidth() * 0.5f);
            cl.setPivotY(cl.getMeasuredHeight() * 0.5f);
            cl.setRotation(0f);
            cl.setRotationY(0f);
            cl.setRotationX(0f);
            cl.setScaleX(1f);
            cl.setScaleY(1f);
            cl.setShortcutAndWidgetAlpha(1f);
        }

        mOldAlphas[i] = cl.getShortcutsAndWidgets().getAlpha();
        mNewAlphas[i] = finalAlpha;
        if (animated) {
            mOldBackgroundAlphas[i] = cl.getBackgroundAlpha();
            mNewBackgroundAlphas[i] = finalBackgroundAlpha;
        } else {
            cl.setBackgroundAlpha(finalBackgroundAlpha);
            cl.setShortcutAndWidgetAlpha(finalAlpha);
        }
    }

    final View overviewPanel = mLauncher.getOverviewPanel();
    if (animated) {
        anim.setDuration(duration);
        LauncherViewPropertyAnimator scale = new LauncherViewPropertyAnimator(this);
        scale.scaleX(mNewScale).scaleY(mNewScale).translationY(finalWorkspaceTranslationY)
                .setInterpolator(mZoomInInterpolator);
        anim.play(scale);
        ValueAnimator invalidate = ValueAnimator.ofFloat(0f, 1f);
        invalidate.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator animation) {
                invalidate();
            }
        });
        anim.play(invalidate);
        ObjectAnimator pageIndicatorAlpha = null;
        if (getPageIndicator() != null) {
            pageIndicatorAlpha = ObjectAnimator.ofFloat(getPageIndicator(), "alpha", finalPageIndicatorAlpha);
        }
        ObjectAnimator overviewPanelAlpha = ObjectAnimator.ofFloat(overviewPanel, "alpha",
                finalOverviewPanelAlpha);

        overviewPanelAlpha.addListener(new AlphaUpdateListener(overviewPanel));

        if (overviewToWorkspace) {
            overviewPanelAlpha.setInterpolator(new DecelerateInterpolator(2));
        }

        if (getPageIndicator() != null) {
            pageIndicatorAlpha.addListener(new AlphaUpdateListener(getPageIndicator()));
        }

        anim.play(overviewPanelAlpha);
        anim.play(pageIndicatorAlpha);

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

            final CellLayout cl = (CellLayout) getChildAt(i);
            if (mOldAlphas[i] == 0 && mNewAlphas[i] == 0) {
                cl.setBackgroundAlpha(mNewBackgroundAlphas[i]);
                cl.getShortcutsAndWidgets().setAlpha(mNewAlphas[i]);
            } else {
                LauncherViewPropertyAnimator a = new LauncherViewPropertyAnimator(cl.getShortcutsAndWidgets());
                a.alpha(mNewAlphas[i]).setDuration(duration).setInterpolator(mZoomInInterpolator);
                anim.play(a);
                if (mOldBackgroundAlphas[i] != 0 || mNewBackgroundAlphas[i] != 0) {
                    ValueAnimator bgAnim = LauncherAnimUtils.ofFloat(cl, 0f, 1f);
                    bgAnim.setInterpolator(mZoomInInterpolator);
                    bgAnim.addUpdateListener(new LauncherAnimatorUpdateListener() {
                        public void onAnimationUpdate(float a, float b) {
                            cl.setBackgroundAlpha(a * mOldBackgroundAlphas[i] + b * mNewBackgroundAlphas[i]);
                        }
                    });
                    anim.play(bgAnim);
                }
            }
        }

        anim.setStartDelay(delay);
    } else {
        overviewPanel.setAlpha(finalOverviewPanelAlpha);
        AlphaUpdateListener.updateVisibility(overviewPanel);
        if (getPageIndicator() != null) {
            getPageIndicator().setAlpha(finalPageIndicatorAlpha);
            AlphaUpdateListener.updateVisibility(getPageIndicator());
        }
        setScaleX(mNewScale);
        setScaleY(mNewScale);
        setTranslationY(finalWorkspaceTranslationY);
    }
    return anim;
}