Example usage for android.view WindowManager updateViewLayout

List of usage examples for android.view WindowManager updateViewLayout

Introduction

In this page you can find the example usage for android.view WindowManager updateViewLayout.

Prototype

public void updateViewLayout(View view, ViewGroup.LayoutParams params);

Source Link

Usage

From source file:com.appsimobile.appsii.HotspotHelperImpl.java

private void setSwipeLocationForHotspotDrag(SidebarHotspot hotspot, int localX, int deltaY, boolean left) {
    long id = hotspot.getHotspotId();
    HotspotContainerHelper helper = mSidebarHotspots.get(id);
    WindowManager wm = mWindowManager;
    WindowManager.LayoutParams params = (WindowManager.LayoutParams) helper.mHotspotParent.getLayoutParams();
    int y = mHotspotY - deltaY;
    params = updateLayoutParams(left, y, params);
    wm.updateViewLayout(helper.mHotspotParent, params);
}

From source file:io.bunnyblue.noticedog.app.lockscreen.ui.LockScreenWidget.java

void enableTouchOnRootView(boolean enableTouch) {
    WindowManager wm = (WindowManager) this.context.getSystemService("window");
    LayoutParams layoutParams = (LayoutParams) this.rootView.getLayoutParams();
    boolean isTouchEnabled = (layoutParams.flags & 16) == 0;
    if (isTouchEnabled && !enableTouch) {
        layoutParams.flags |= 16;/*from  w  w w . j  av a  2 s .  c o  m*/
        wm.updateViewLayout(this.rootView, layoutParams);
    } else if (!isTouchEnabled && enableTouch) {
        layoutParams.flags &= -17;
        wm.updateViewLayout(this.rootView, layoutParams);
    }
}

From source file:io.bunnyblue.noticedog.app.lockscreen.ui.LockScreenWidget.java

void changeState(WidgetState nextState) {
    Log.d(TAG, "Switching state from: " + this.currentState + " to: " + nextState);
    LayoutParams layoutParams;/*from  w  ww.j a  v  a 2  s.c o  m*/
    switch (nextState) {
    case stateShown:
        this.widgetView.clearAnimation();
        this.widgetView.setX(0.0f);
        this.widgetView.setAlpha(0.0f);
        this.widgetView.animate().alpha(0.0f).setDuration(0).withEndAction(new Runnable() {
            public void run() {
                LockScreenWidget.this.widgetView.animate().alpha(DefaultRetryPolicy.DEFAULT_BACKOFF_MULT)
                        .setDuration(200).setInterpolator(new DecelerateInterpolator())
                        .withEndAction(new Runnable() {
                            public void run() {
                                LockScreenWidget.this.enableTouchOnRootView(true);
                                LockScreenWidget.this.currentState = WidgetState.stateShown;
                            }
                        });
            }
        });
        this.currentState = WidgetState.stateInterpolatingToShown;
        return;
    case stateUnlockToContinueShown:
        enableTouchOnRootView(false);
        this.unlockToContinueView = ((LayoutInflater) this.context
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE))
                        .inflate(R.layout.lockscreen_unlock_to_continue_view, null);
        addToFullscreenView(this.unlockToContinueView);
        ViewGroup.LayoutParams layoutParams2 = this.unlockToContinueView.getLayoutParams();
        layoutParams2.width = -1;
        this.unlockToContinueView.setLayoutParams(layoutParams2);
        this.unlockToContinueView.setAlpha(0.0f);
        this.widgetView.clearAnimation();
        this.widgetView.animate().alpha(0.0f).setDuration(200).setInterpolator(new AccelerateInterpolator())
                .withEndAction(new Runnable() {
                    public void run() {
                        LockScreenWidget.this.unlockToContinueView.animate()
                                .alpha(DefaultRetryPolicy.DEFAULT_BACKOFF_MULT).setDuration(200)
                                .setStartDelay(100).setInterpolator(new DecelerateInterpolator())
                                .withEndAction(new Runnable() {
                                    public void run() {
                                        LockScreenWidget.this.currentState = WidgetState.stateUnlockToContinueShown;
                                    }
                                });
                    }
                });
        this.currentState = WidgetState.stateInterpolatingToUnlockToContinueShown;
        return;
    case stateUnlockToContinueHidden:
        enableTouchOnRootView(false);
        this.widgetView.clearAnimation();
        this.unlockToContinueView.clearAnimation();
        this.unlockToContinueView.animate().alpha(0.0f).setDuration(200)
                .setInterpolator(new AccelerateInterpolator()).withEndAction(new Runnable() {
                    public void run() {
                        LockScreenWidget.this.widgetView.animate()
                                .alpha(DefaultRetryPolicy.DEFAULT_BACKOFF_MULT).setDuration(200)
                                .setStartDelay(100).setInterpolator(new DecelerateInterpolator())
                                .withEndAction(new Runnable() {
                                    public void run() {
                                        LockScreenWidget.this.currentState = WidgetState.stateShown;
                                        LockScreenWidget.this.clearFullscreenView();
                                        LockScreenWidget.this.unlockToContinueView = null;
                                        LockScreenWidget.this.enableTouchOnRootView(true);
                                        LockScreenWidget.this.currentState = WidgetState.stateShown;
                                    }
                                });
                    }
                });
        this.currentState = WidgetState.stateInterpolatingToUnlockToContinueHidden;
        return;
    case stateCleared:
        enableTouchOnRootView(false);
        this.widgetView.clearAnimation();
        this.widgetView.animate().alpha(0.0f).setDuration(200).setInterpolator(new AccelerateInterpolator())
                .withEndAction(new Runnable() {
                    public void run() {
                        if (LockScreenWidget.this.listener != null) {
                            LockScreenWidget.this.listener.onWidgetCleared();
                        }
                        LockScreenWidget.this.currentState = WidgetState.stateCleared;
                    }
                });
        this.currentState = WidgetState.stateInterpolatingToCleared;
        return;
    case stateMoving:
        this.widgetView.clearAnimation();
        layoutParams = (LayoutParams) this.rootView.getLayoutParams();
        this.screenshotView = duplicateView(this.widgetView);
        this.screenshotView.setY((float) layoutParams.y);
        Log.d(TAG, "Setting widget view screenshot to Y position = " + layoutParams.y);
        addToFullscreenView(this.screenshotView);
        this.widgetView.animate().alpha(0.0f).setDuration(0).setStartDelay(100);
        this.screenshotView.animate().scaleX(RELOCATE_WINDOW_SCALE).scaleY(RELOCATE_WINDOW_SCALE)
                .setDuration(200).withEndAction(new Runnable() {
                    public void run() {
                        LockScreenWidget.this.currentState = WidgetState.stateMoving;
                    }
                });
        this.screenshotView.performHapticFeedback(3, 2);
        this.currentState = WidgetState.stateInterpolatingToMoving;
        return;
    case stateStopMoving:
        WindowManager windowManager = (WindowManager) this.context.getSystemService("window");
        layoutParams = (LayoutParams) this.rootView.getLayoutParams();
        layoutParams.y = (int) this.screenshotView.getY();
        windowManager.updateViewLayout(this.rootView, layoutParams);
        this.screenshotView.setScaleY(RELOCATE_WINDOW_SCALE);
        this.screenshotView.setScaleX(RELOCATE_WINDOW_SCALE);
        this.screenshotView.animate().scaleY(DefaultRetryPolicy.DEFAULT_BACKOFF_MULT)
                .scaleX(DefaultRetryPolicy.DEFAULT_BACKOFF_MULT).setDuration(200).withEndAction(new Runnable() {
                    public void run() {
                        LockScreenWidget.this.widgetView.animate()
                                .alpha(DefaultRetryPolicy.DEFAULT_BACKOFF_MULT).setDuration(0)
                                .withEndAction(new Runnable() {
                                    public void run() {
                                        LockScreenWidget.this.clearFullscreenView();
                                        LockScreenWidget.this.screenshotView = null;
                                        LockScreenWidget.this.currentState = WidgetState.stateShown;
                                    }
                                });
                    }
                });
        ((Settings) GuiceModule.get().getInstance(Settings.class))
                .updateLockscreenWidgetY(this.screenshotView.getY());
        this.currentState = WidgetState.stateInterpolatingToStopMoving;
        Log.d(TAG, "Restoring widget view at Y position = " + layoutParams.y + " with height = "
                + layoutParams.height);
        return;
    case stateHidden:
        enableTouchOnRootView(false);
        this.widgetView.clearAnimation();
        this.widgetView.animate().alpha(0.0f).setDuration(200).setInterpolator(new AccelerateInterpolator())
                .withEndAction(new Runnable() {
                    public void run() {
                        LockScreenWidget.this.enableTouchOnRootView(false);
                        LockScreenWidget.this.currentState = WidgetState.stateHidden;
                    }
                });
        this.currentState = WidgetState.stateInterpolatingToHidden;
        return;
    case stateTerminated:
        enableTouchOnRootView(false);
        this.widgetView.clearAnimation();
        this.fullscreenView.clearAnimation();
        if (this.unlockToContinueView != null) {
            this.unlockToContinueView.clearAnimation();
            this.unlockToContinueView.animate().alpha(0.0f).setDuration(200)
                    .setInterpolator(new AccelerateInterpolator());
        }
        this.widgetView.animate().alpha(0.0f).setDuration(200).setInterpolator(new AccelerateInterpolator())
                .withEndAction(new Runnable() {
                    public void run() {
                        WindowManager wm = (WindowManager) LockScreenWidget.this.context
                                .getSystemService("window");
                        try {
                            wm.removeView(LockScreenWidget.this.fullscreenView);
                        } catch (Exception e) {
                        }
                        try {
                            wm.removeView(LockScreenWidget.this.rootView);
                        } catch (Exception e2) {
                        }
                        LockScreenWidget.this.widgetView = null;
                        LockScreenWidget.this.screenshotView = null;
                        LockScreenWidget.this.unlockToContinueView = null;
                        LockScreenWidget.this.fullscreenView = null;
                        LockScreenWidget.this.rootView = null;
                        LockScreenWidget.this.context = null;
                        LockScreenWidget.this.currentState = WidgetState.stateTerminated;
                    }
                });
        this.currentState = WidgetState.stateInterpolatingToTerminated;
        return;
    default:
        return;
    }
}

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

@Override
public void onSizeChanged(int height) {
    Rect localRect = new Rect();
    parentActivity.getWindow().getDecorView().getWindowVisibleDisplayFrame(localRect);

    WindowManager manager = (WindowManager) ApplicationLoader.applicationContext
            .getSystemService(Activity.WINDOW_SERVICE);
    int rotation = manager.getDefaultDisplay().getRotation();

    if (height > Emoji.scale(50)) {
        if (rotation == Surface.ROTATION_270 || rotation == Surface.ROTATION_90) {
            keyboardHeightLand = height;
            parentActivity.getSharedPreferences("emoji", 0).edit()
                    .putInt("kbd_height_land3", keyboardHeightLand).commit();
        } else {//  w  w  w .  jav  a  2  s.  c o m
            keyboardHeight = height;
            parentActivity.getSharedPreferences("emoji", 0).edit().putInt("kbd_height", keyboardHeight)
                    .commit();
        }
    }

    if (emojiPopup != null && emojiPopup.isShowing()) {
        WindowManager wm = (WindowManager) parentActivity.getSystemService(Context.WINDOW_SERVICE);
        final WindowManager.LayoutParams layoutParams = (WindowManager.LayoutParams) emojiPopup.getContentView()
                .getLayoutParams();
        layoutParams.width = contentView.getWidth();
        if (rotation == Surface.ROTATION_270 || rotation == Surface.ROTATION_90) {
            layoutParams.height = keyboardHeightLand;
        } else {
            layoutParams.height = keyboardHeight;
        }
        wm.updateViewLayout(emojiPopup.getContentView(), layoutParams);
        if (!keyboardVisible) {
            contentView.post(new Runnable() {
                @Override
                public void run() {
                    contentView.setPadding(0, 0, 0, layoutParams.height);
                    contentView.requestLayout();
                }
            });
        }
    }

    boolean oldValue = keyboardVisible;
    keyboardVisible = height > 0;
    if (keyboardVisible && contentView.getPaddingBottom() > 0) {
        showEmojiPopup(false);
    } else if (!keyboardVisible && keyboardVisible != oldValue && emojiPopup != null
            && emojiPopup.isShowing()) {
        showEmojiPopup(false);
    }
}

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

public void collapse() {
    if (parentActivity == null || !isVisible || checkAnimation()) {
        return;/*ww w. j a  v  a 2s.  c  o m*/
    }
    if (fullscreenVideoContainer.getVisibility() == View.VISIBLE) {
        if (customView != null) {
            fullscreenVideoContainer.setVisibility(View.INVISIBLE);
            customViewCallback.onCustomViewHidden();
            fullscreenVideoContainer.removeView(customView);
            customView = null;
        } else if (fullscreenedVideo != null) {
            fullscreenedVideo.exitFullscreen();
        }
    }
    if (isPhotoVisible) {
        closePhoto(false);
    }
    try {
        if (visibleDialog != null) {
            visibleDialog.dismiss();
            visibleDialog = null;
        }
    } catch (Exception e) {
        FileLog.e(e);
    }

    AnimatorSet animatorSet = new AnimatorSet();
    animatorSet.playTogether(
            ObjectAnimator.ofFloat(containerView, "translationX",
                    containerView.getMeasuredWidth() - AndroidUtilities.dp(56)),
            ObjectAnimator.ofFloat(containerView, "translationY",
                    ActionBar.getCurrentActionBarHeight()
                            + (Build.VERSION.SDK_INT >= 21 ? AndroidUtilities.statusBarHeight : 0)),
            ObjectAnimator.ofFloat(windowView, "alpha", 0.0f), ObjectAnimator.ofFloat(listView, "alpha", 0.0f),
            ObjectAnimator.ofFloat(listView, "translationY", -AndroidUtilities.dp(56)),
            ObjectAnimator.ofFloat(headerView, "translationY", 0),

            ObjectAnimator.ofFloat(backButton, "scaleX", 1.0f),
            ObjectAnimator.ofFloat(backButton, "scaleY", 1.0f),
            ObjectAnimator.ofFloat(backButton, "translationY", 0),
            ObjectAnimator.ofFloat(shareContainer, "scaleX", 1.0f),
            ObjectAnimator.ofFloat(shareContainer, "translationY", 0),
            ObjectAnimator.ofFloat(shareContainer, "scaleY", 1.0f));
    collapsed = true;
    animationInProgress = 2;
    animationEndRunnable = new Runnable() {
        @Override
        public void run() {
            if (containerView == null) {
                return;
            }
            if (Build.VERSION.SDK_INT >= 18) {
                containerView.setLayerType(View.LAYER_TYPE_NONE, null);
            }
            animationInProgress = 0;

            //windowLayoutParams.flags |= WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE;
            WindowManager wm = (WindowManager) parentActivity.getSystemService(Context.WINDOW_SERVICE);
            wm.updateViewLayout(windowView, windowLayoutParams);

            //onClosed();
            //containerView.setScaleX(1.0f);
            //containerView.setScaleY(1.0f);
        }
    };
    animatorSet.setInterpolator(new DecelerateInterpolator());
    animatorSet.setDuration(250);
    animatorSet.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            if (animationEndRunnable != null) {
                animationEndRunnable.run();
                animationEndRunnable = null;
            }
        }
    });
    transitionAnimationStartTime = System.currentTimeMillis();
    if (Build.VERSION.SDK_INT >= 18) {
        containerView.setLayerType(View.LAYER_TYPE_HARDWARE, null);
    }
    backDrawable.setRotation(1, true);
    animatorSet.start();
}

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

private boolean open(final MessageObject messageObject, boolean first) {
    if (parentActivity == null || isVisible && !collapsed || messageObject == null) {
        return false;
    }//from   w  ww .j  av  a 2 s  .co  m

    if (first) {
        TLRPC.TL_messages_getWebPage req = new TLRPC.TL_messages_getWebPage();
        req.url = messageObject.messageOwner.media.webpage.url;
        if (messageObject.messageOwner.media.webpage.cached_page instanceof TLRPC.TL_pagePart) {
            req.hash = 0;
        } else {
            req.hash = messageObject.messageOwner.media.webpage.hash;
        }
        ConnectionsManager.getInstance().sendRequest(req, new RequestDelegate() {
            @Override
            public void run(TLObject response, TLRPC.TL_error error) {
                if (response instanceof TLRPC.TL_webPage) {
                    final TLRPC.TL_webPage webPage = (TLRPC.TL_webPage) response;
                    if (webPage.cached_page == null) {
                        return;
                    }
                    AndroidUtilities.runOnUIThread(new Runnable() {
                        @Override
                        public void run() {
                            if (!pagesStack.isEmpty()
                                    && pagesStack.get(0) == messageObject.messageOwner.media.webpage
                                    && webPage.cached_page != null) {
                                messageObject.messageOwner.media.webpage = webPage;
                                pagesStack.set(0, webPage);
                                if (pagesStack.size() == 1) {
                                    currentPage = webPage;
                                    ApplicationLoader.applicationContext
                                            .getSharedPreferences("articles", Activity.MODE_PRIVATE).edit()
                                            .remove("article" + currentPage.id).commit();
                                    updateInterfaceForCurrentPage(false);
                                }
                            }
                        }
                    });
                    HashMap<Long, TLRPC.WebPage> webpages = new HashMap<>();
                    webpages.put(webPage.id, webPage);
                    MessagesStorage.getInstance().putWebPages(webpages);
                }
            }
        });
    }

    pagesStack.clear();
    collapsed = false;
    backDrawable.setRotation(0, false);
    containerView.setTranslationX(0);
    containerView.setTranslationY(0);
    listView.setTranslationY(0);
    listView.setAlpha(1.0f);
    windowView.setInnerTranslationX(0);

    actionBar.setVisibility(View.GONE);
    bottomLayout.setVisibility(View.GONE);
    captionTextViewNew.setVisibility(View.GONE);
    captionTextViewOld.setVisibility(View.GONE);
    shareContainer.setAlpha(0.0f);
    backButton.setAlpha(0.0f);
    layoutManager.scrollToPositionWithOffset(0, 0);
    checkScroll(-AndroidUtilities.dp(56));

    TLRPC.WebPage webPage = messageObject.messageOwner.media.webpage;
    String webPageUrl = webPage.url.toLowerCase();
    int index;
    String anchor = null;
    for (int a = 0; a < messageObject.messageOwner.entities.size(); a++) {
        TLRPC.MessageEntity entity = messageObject.messageOwner.entities.get(a);
        if (entity instanceof TLRPC.TL_messageEntityUrl) {
            try {
                String url = messageObject.messageOwner.message
                        .substring(entity.offset, entity.offset + entity.length).toLowerCase();
                if (url.contains(webPageUrl) || webPageUrl.contains(url)) {
                    if ((index = url.lastIndexOf('#')) != -1) {
                        anchor = url.substring(index + 1);
                    }
                    break;
                }
            } catch (Exception e) {
                FileLog.e(e);
            }
        }
    }
    addPageToStack(webPage, anchor);

    lastInsets = null;
    if (!isVisible) {
        WindowManager wm = (WindowManager) parentActivity.getSystemService(Context.WINDOW_SERVICE);
        if (attachedToWindow) {
            try {
                wm.removeView(windowView);
            } catch (Exception e) {
                //ignore
            }
        }
        try {
            if (Build.VERSION.SDK_INT >= 21) {
                windowLayoutParams.flags = WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN
                        | WindowManager.LayoutParams.FLAG_LAYOUT_INSET_DECOR
                        | WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS;
            }
            windowLayoutParams.flags |= WindowManager.LayoutParams.FLAG_FULLSCREEN
                    | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
            windowView.setFocusable(false);
            containerView.setFocusable(false);
            wm.addView(windowView, windowLayoutParams);
        } catch (Exception e) {
            FileLog.e(e);
            return false;
        }
    } else {
        windowLayoutParams.flags &= ~WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE;
        WindowManager wm = (WindowManager) parentActivity.getSystemService(Context.WINDOW_SERVICE);
        wm.updateViewLayout(windowView, windowLayoutParams);
    }
    isVisible = true;
    animationInProgress = 1;
    windowView.setAlpha(0);
    containerView.setAlpha(0);

    final AnimatorSet animatorSet = new AnimatorSet();
    animatorSet.playTogether(ObjectAnimator.ofFloat(windowView, "alpha", 0, 1.0f),
            ObjectAnimator.ofFloat(containerView, "alpha", 0.0f, 1.0f),
            ObjectAnimator.ofFloat(windowView, "translationX", AndroidUtilities.dp(56), 0));

    animationEndRunnable = new Runnable() {
        @Override
        public void run() {
            if (containerView == null || windowView == null) {
                return;
            }
            if (Build.VERSION.SDK_INT >= 18) {
                containerView.setLayerType(View.LAYER_TYPE_NONE, null);
            }
            animationInProgress = 0;
        }
    };

    animatorSet.setDuration(150);
    animatorSet.setInterpolator(interpolator);
    animatorSet.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            AndroidUtilities.runOnUIThread(new Runnable() {
                @Override
                public void run() {
                    NotificationCenter.getInstance().setAnimationInProgress(false);
                    if (animationEndRunnable != null) {
                        animationEndRunnable.run();
                        animationEndRunnable = null;
                    }
                }
            });
        }
    });
    transitionAnimationStartTime = System.currentTimeMillis();
    AndroidUtilities.runOnUIThread(new Runnable() {
        @Override
        public void run() {
            NotificationCenter.getInstance()
                    .setAllowedNotificationsDutingAnimation(new int[] { NotificationCenter.dialogsNeedReload,
                            NotificationCenter.closeChats, NotificationCenter.mediaCountDidLoaded,
                            NotificationCenter.mediaDidLoaded, NotificationCenter.dialogPhotosLoaded });
            NotificationCenter.getInstance().setAnimationInProgress(true);
            animatorSet.start();
        }
    });
    if (Build.VERSION.SDK_INT >= 18) {
        containerView.setLayerType(View.LAYER_TYPE_HARDWARE, null);
    }
    showActionBar(200);
    return true;
}

From source file:net.bluehack.ui.PhotoViewer.java

public boolean openPhoto(final MessageObject messageObject, final TLRPC.FileLocation fileLocation,
        final ArrayList<MessageObject> messages, final ArrayList<Object> photos, final int index,
        final PhotoViewerProvider provider, ChatActivity chatActivity, long dialogId, long mDialogId) {
    if (parentActivity == null || isVisible || provider == null && checkAnimation()
            || messageObject == null && fileLocation == null && messages == null && photos == null) {
        return false;
    }//from w  w w  .  j  av  a 2 s .co m

    final PlaceProviderObject object = provider.getPlaceForPhoto(messageObject, fileLocation, index);
    if (object == null && photos == null) {
        return false;
    }

    WindowManager wm = (WindowManager) parentActivity.getSystemService(Context.WINDOW_SERVICE);
    if (attachedToWindow) {
        try {
            wm.removeView(windowView);
        } catch (Exception e) {
            //don't promt
        }
    }

    try {
        windowLayoutParams.type = WindowManager.LayoutParams.LAST_APPLICATION_WINDOW;
        if (Build.VERSION.SDK_INT >= 21) {
            windowLayoutParams.flags = WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN
                    | WindowManager.LayoutParams.FLAG_LAYOUT_INSET_DECOR
                    | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
                    | WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS;
        } else {
            windowLayoutParams.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
        }
        windowLayoutParams.softInputMode = WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE
                | WindowManager.LayoutParams.SOFT_INPUT_IS_FORWARD_NAVIGATION;
        windowView.setFocusable(false);
        containerView.setFocusable(false);
        wm.addView(windowView, windowLayoutParams);
    } catch (Exception e) {
        FileLog.e("tmessages", e);
        return false;
    }

    parentChatActivity = chatActivity;

    actionBar.setTitle(LocaleController.formatString("Of", R.string.Of, 1, 1));
    NotificationCenter.getInstance().addObserver(this, NotificationCenter.FileDidFailedLoad);
    NotificationCenter.getInstance().addObserver(this, NotificationCenter.FileDidLoaded);
    NotificationCenter.getInstance().addObserver(this, NotificationCenter.FileLoadProgressChanged);
    NotificationCenter.getInstance().addObserver(this, NotificationCenter.mediaCountDidLoaded);
    NotificationCenter.getInstance().addObserver(this, NotificationCenter.mediaDidLoaded);
    NotificationCenter.getInstance().addObserver(this, NotificationCenter.dialogPhotosLoaded);
    NotificationCenter.getInstance().addObserver(this, NotificationCenter.emojiDidLoaded);

    placeProvider = provider;
    mergeDialogId = mDialogId;
    currentDialogId = dialogId;

    if (velocityTracker == null) {
        velocityTracker = VelocityTracker.obtain();
    }

    isVisible = true;
    toggleActionBar(true, false);

    if (object != null) {
        disableShowCheck = true;
        animationInProgress = 1;
        if (messageObject != null) {
            currentAnimation = object.imageReceiver.getAnimation();
        }

        onPhotoShow(messageObject, fileLocation, messages, photos, index, object);

        final Rect drawRegion = object.imageReceiver.getDrawRegion();
        int orientation = object.imageReceiver.getOrientation();
        int animatedOrientation = object.imageReceiver.getAnimatedOrientation();
        if (animatedOrientation != 0) {
            orientation = animatedOrientation;
        }

        animatingImageView.setVisibility(View.VISIBLE);
        animatingImageView.setRadius(object.radius);
        animatingImageView.setOrientation(orientation);
        animatingImageView.setNeedRadius(object.radius != 0);
        animatingImageView.setImageBitmap(object.thumb);

        animatingImageView.setAlpha(1.0f);
        animatingImageView.setPivotX(0.0f);
        animatingImageView.setPivotY(0.0f);
        animatingImageView.setScaleX(object.scale);
        animatingImageView.setScaleY(object.scale);
        animatingImageView.setTranslationX(object.viewX + drawRegion.left * object.scale);
        animatingImageView.setTranslationY(object.viewY + drawRegion.top * object.scale);
        final ViewGroup.LayoutParams layoutParams = animatingImageView.getLayoutParams();
        layoutParams.width = (drawRegion.right - drawRegion.left);
        layoutParams.height = (drawRegion.bottom - drawRegion.top);
        animatingImageView.setLayoutParams(layoutParams);

        float scaleX = (float) AndroidUtilities.displaySize.x / layoutParams.width;
        float scaleY = (float) (AndroidUtilities.displaySize.y
                + (Build.VERSION.SDK_INT >= 21 ? AndroidUtilities.statusBarHeight : 0)) / layoutParams.height;
        float scale = scaleX > scaleY ? scaleY : scaleX;
        float width = layoutParams.width * scale;
        float height = layoutParams.height * scale;
        float xPos = (AndroidUtilities.displaySize.x - width) / 2.0f;
        float yPos = ((AndroidUtilities.displaySize.y
                + (Build.VERSION.SDK_INT >= 21 ? AndroidUtilities.statusBarHeight : 0)) - height) / 2.0f;
        int clipHorizontal = Math.abs(drawRegion.left - object.imageReceiver.getImageX());
        int clipVertical = Math.abs(drawRegion.top - object.imageReceiver.getImageY());

        int coords2[] = new int[2];
        object.parentView.getLocationInWindow(coords2);
        int clipTop = coords2[1] - (Build.VERSION.SDK_INT >= 21 ? 0 : AndroidUtilities.statusBarHeight)
                - (object.viewY + drawRegion.top) + object.clipTopAddition;
        if (clipTop < 0) {
            clipTop = 0;
        }
        int clipBottom = (object.viewY + drawRegion.top + layoutParams.height)
                - (coords2[1] + object.parentView.getHeight()
                        - (Build.VERSION.SDK_INT >= 21 ? 0 : AndroidUtilities.statusBarHeight))
                + object.clipBottomAddition;
        if (clipBottom < 0) {
            clipBottom = 0;
        }
        clipTop = Math.max(clipTop, clipVertical);
        clipBottom = Math.max(clipBottom, clipVertical);

        animationValues[0][0] = animatingImageView.getScaleX();
        animationValues[0][1] = animatingImageView.getScaleY();
        animationValues[0][2] = animatingImageView.getTranslationX();
        animationValues[0][3] = animatingImageView.getTranslationY();
        animationValues[0][4] = clipHorizontal * object.scale;
        animationValues[0][5] = clipTop * object.scale;
        animationValues[0][6] = clipBottom * object.scale;
        animationValues[0][7] = animatingImageView.getRadius();

        animationValues[1][0] = scale;
        animationValues[1][1] = scale;
        animationValues[1][2] = xPos;
        animationValues[1][3] = yPos;
        animationValues[1][4] = 0;
        animationValues[1][5] = 0;
        animationValues[1][6] = 0;
        animationValues[1][7] = 0;

        animatingImageView.setAnimationProgress(0);
        backgroundDrawable.setAlpha(0);
        containerView.setAlpha(0);

        final AnimatorSet animatorSet = new AnimatorSet();
        animatorSet.playTogether(ObjectAnimator.ofFloat(animatingImageView, "animationProgress", 0.0f, 1.0f),
                ObjectAnimator.ofInt(backgroundDrawable, "alpha", 0, 255),
                ObjectAnimator.ofFloat(containerView, "alpha", 0.0f, 1.0f));

        animationEndRunnable = new Runnable() {
            @Override
            public void run() {
                if (containerView == null || windowView == null) {
                    return;
                }
                if (Build.VERSION.SDK_INT >= 18) {
                    containerView.setLayerType(View.LAYER_TYPE_NONE, null);
                }
                animationInProgress = 0;
                transitionAnimationStartTime = 0;
                setImages();
                containerView.invalidate();
                animatingImageView.setVisibility(View.GONE);
                if (showAfterAnimation != null) {
                    showAfterAnimation.imageReceiver.setVisible(true, true);
                }
                if (hideAfterAnimation != null) {
                    hideAfterAnimation.imageReceiver.setVisible(false, true);
                }
                if (photos != null && sendPhotoType != 3) {
                    if (Build.VERSION.SDK_INT >= 21) {
                        windowLayoutParams.flags = WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN
                                | WindowManager.LayoutParams.FLAG_LAYOUT_INSET_DECOR
                                | WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS;
                    } else {
                        windowLayoutParams.flags = 0;
                    }
                    windowLayoutParams.softInputMode = WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE
                            | WindowManager.LayoutParams.SOFT_INPUT_IS_FORWARD_NAVIGATION;
                    WindowManager wm = (WindowManager) parentActivity.getSystemService(Context.WINDOW_SERVICE);
                    wm.updateViewLayout(windowView, windowLayoutParams);
                    windowView.setFocusable(true);
                    containerView.setFocusable(true);
                }
            }
        };

        animatorSet.setDuration(200);
        animatorSet.addListener(new AnimatorListenerAdapterProxy() {
            @Override
            public void onAnimationEnd(Animator animation) {
                AndroidUtilities.runOnUIThread(new Runnable() {
                    @Override
                    public void run() {
                        NotificationCenter.getInstance().setAnimationInProgress(false);
                        if (animationEndRunnable != null) {
                            animationEndRunnable.run();
                            animationEndRunnable = null;
                        }
                    }
                });
            }
        });
        transitionAnimationStartTime = System.currentTimeMillis();
        AndroidUtilities.runOnUIThread(new Runnable() {
            @Override
            public void run() {
                NotificationCenter.getInstance()
                        .setAllowedNotificationsDutingAnimation(new int[] {
                                NotificationCenter.dialogsNeedReload, NotificationCenter.closeChats,
                                NotificationCenter.mediaCountDidLoaded, NotificationCenter.mediaDidLoaded,
                                NotificationCenter.dialogPhotosLoaded });
                NotificationCenter.getInstance().setAnimationInProgress(true);
                animatorSet.start();
            }
        });
        if (Build.VERSION.SDK_INT >= 18) {
            containerView.setLayerType(View.LAYER_TYPE_HARDWARE, null);
        }
        backgroundDrawable.drawRunnable = new Runnable() {
            @Override
            public void run() {
                disableShowCheck = false;
                object.imageReceiver.setVisible(false, true);
            }
        };
    } else {
        if (photos != null && sendPhotoType != 3) {
            if (Build.VERSION.SDK_INT >= 21) {
                windowLayoutParams.flags = WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN
                        | WindowManager.LayoutParams.FLAG_LAYOUT_INSET_DECOR
                        | WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS;
            } else {
                windowLayoutParams.flags = 0;
            }
            windowLayoutParams.softInputMode = WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE
                    | WindowManager.LayoutParams.SOFT_INPUT_IS_FORWARD_NAVIGATION;
            wm.updateViewLayout(windowView, windowLayoutParams);
            windowView.setFocusable(true);
            containerView.setFocusable(true);
        }

        backgroundDrawable.setAlpha(255);
        containerView.setAlpha(1.0f);
        onPhotoShow(messageObject, fileLocation, messages, photos, index, object);
    }
    return true;
}

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

public boolean openPhoto(final MessageObject messageObject, final TLRPC.FileLocation fileLocation,
        final ArrayList<MessageObject> messages, final ArrayList<Object> photos, final int index,
        final PhotoViewerProvider provider, ChatActivity chatActivity, long dialogId, long mDialogId) {
    if (parentActivity == null || isVisible || provider == null && checkAnimation()
            || messageObject == null && fileLocation == null && messages == null && photos == null) {
        return false;
    }//www .  j  a  v a 2 s.c  om

    final PlaceProviderObject object = provider.getPlaceForPhoto(messageObject, fileLocation, index);
    if (object == null && photos == null) {
        return false;
    }

    WindowManager wm = (WindowManager) parentActivity.getSystemService(Context.WINDOW_SERVICE);
    if (attachedToWindow) {
        try {
            wm.removeView(windowView);
        } catch (Exception e) {
            //don't promt
        }
    }

    try {
        windowLayoutParams.type = WindowManager.LayoutParams.LAST_APPLICATION_WINDOW;
        if (Build.VERSION.SDK_INT >= 21) {
            windowLayoutParams.flags = WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN
                    | WindowManager.LayoutParams.FLAG_LAYOUT_INSET_DECOR
                    | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
                    | WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS;
        } else {
            windowLayoutParams.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
        }
        windowLayoutParams.softInputMode = WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE
                | WindowManager.LayoutParams.SOFT_INPUT_IS_FORWARD_NAVIGATION;
        windowView.setFocusable(false);
        containerView.setFocusable(false);
        wm.addView(windowView, windowLayoutParams);
    } catch (Exception e) {
        FileLog.e("tmessages", e);
        return false;
    }

    parentChatActivity = chatActivity;

    actionBar.setTitle(LocaleController.formatString("Of", kr.wdream.storyshop.R.string.Of, 1, 1));
    NotificationCenter.getInstance().addObserver(this, NotificationCenter.FileDidFailedLoad);
    NotificationCenter.getInstance().addObserver(this, NotificationCenter.FileDidLoaded);
    NotificationCenter.getInstance().addObserver(this, NotificationCenter.FileLoadProgressChanged);
    NotificationCenter.getInstance().addObserver(this, NotificationCenter.mediaCountDidLoaded);
    NotificationCenter.getInstance().addObserver(this, NotificationCenter.mediaDidLoaded);
    NotificationCenter.getInstance().addObserver(this, NotificationCenter.dialogPhotosLoaded);
    NotificationCenter.getInstance().addObserver(this, NotificationCenter.emojiDidLoaded);

    placeProvider = provider;
    mergeDialogId = mDialogId;
    currentDialogId = dialogId;

    if (velocityTracker == null) {
        velocityTracker = VelocityTracker.obtain();
    }

    isVisible = true;
    toggleActionBar(true, false);

    if (object != null) {
        disableShowCheck = true;
        animationInProgress = 1;
        if (messageObject != null) {
            currentAnimation = object.imageReceiver.getAnimation();
        }

        onPhotoShow(messageObject, fileLocation, messages, photos, index, object);

        final Rect drawRegion = object.imageReceiver.getDrawRegion();
        int orientation = object.imageReceiver.getOrientation();
        int animatedOrientation = object.imageReceiver.getAnimatedOrientation();
        if (animatedOrientation != 0) {
            orientation = animatedOrientation;
        }

        animatingImageView.setVisibility(View.VISIBLE);
        animatingImageView.setRadius(object.radius);
        animatingImageView.setOrientation(orientation);
        animatingImageView.setNeedRadius(object.radius != 0);
        animatingImageView.setImageBitmap(object.thumb);

        animatingImageView.setAlpha(1.0f);
        animatingImageView.setPivotX(0.0f);
        animatingImageView.setPivotY(0.0f);
        animatingImageView.setScaleX(object.scale);
        animatingImageView.setScaleY(object.scale);
        animatingImageView.setTranslationX(object.viewX + drawRegion.left * object.scale);
        animatingImageView.setTranslationY(object.viewY + drawRegion.top * object.scale);
        final ViewGroup.LayoutParams layoutParams = animatingImageView.getLayoutParams();
        layoutParams.width = (drawRegion.right - drawRegion.left);
        layoutParams.height = (drawRegion.bottom - drawRegion.top);
        animatingImageView.setLayoutParams(layoutParams);

        float scaleX = (float) AndroidUtilities.displaySize.x / layoutParams.width;
        float scaleY = (float) (AndroidUtilities.displaySize.y
                + (Build.VERSION.SDK_INT >= 21 ? AndroidUtilities.statusBarHeight : 0)) / layoutParams.height;
        float scale = scaleX > scaleY ? scaleY : scaleX;
        float width = layoutParams.width * scale;
        float height = layoutParams.height * scale;
        float xPos = (AndroidUtilities.displaySize.x - width) / 2.0f;
        float yPos = ((AndroidUtilities.displaySize.y
                + (Build.VERSION.SDK_INT >= 21 ? AndroidUtilities.statusBarHeight : 0)) - height) / 2.0f;
        int clipHorizontal = Math.abs(drawRegion.left - object.imageReceiver.getImageX());
        int clipVertical = Math.abs(drawRegion.top - object.imageReceiver.getImageY());

        int coords2[] = new int[2];
        object.parentView.getLocationInWindow(coords2);
        int clipTop = coords2[1] - (Build.VERSION.SDK_INT >= 21 ? 0 : AndroidUtilities.statusBarHeight)
                - (object.viewY + drawRegion.top) + object.clipTopAddition;
        if (clipTop < 0) {
            clipTop = 0;
        }
        int clipBottom = (object.viewY + drawRegion.top + layoutParams.height)
                - (coords2[1] + object.parentView.getHeight()
                        - (Build.VERSION.SDK_INT >= 21 ? 0 : AndroidUtilities.statusBarHeight))
                + object.clipBottomAddition;
        if (clipBottom < 0) {
            clipBottom = 0;
        }
        clipTop = Math.max(clipTop, clipVertical);
        clipBottom = Math.max(clipBottom, clipVertical);

        animationValues[0][0] = animatingImageView.getScaleX();
        animationValues[0][1] = animatingImageView.getScaleY();
        animationValues[0][2] = animatingImageView.getTranslationX();
        animationValues[0][3] = animatingImageView.getTranslationY();
        animationValues[0][4] = clipHorizontal * object.scale;
        animationValues[0][5] = clipTop * object.scale;
        animationValues[0][6] = clipBottom * object.scale;
        animationValues[0][7] = animatingImageView.getRadius();

        animationValues[1][0] = scale;
        animationValues[1][1] = scale;
        animationValues[1][2] = xPos;
        animationValues[1][3] = yPos;
        animationValues[1][4] = 0;
        animationValues[1][5] = 0;
        animationValues[1][6] = 0;
        animationValues[1][7] = 0;

        animatingImageView.setAnimationProgress(0);
        backgroundDrawable.setAlpha(0);
        containerView.setAlpha(0);

        final AnimatorSet animatorSet = new AnimatorSet();
        animatorSet.playTogether(ObjectAnimator.ofFloat(animatingImageView, "animationProgress", 0.0f, 1.0f),
                ObjectAnimator.ofInt(backgroundDrawable, "alpha", 0, 255),
                ObjectAnimator.ofFloat(containerView, "alpha", 0.0f, 1.0f));

        animationEndRunnable = new Runnable() {
            @Override
            public void run() {
                if (containerView == null || windowView == null) {
                    return;
                }
                if (Build.VERSION.SDK_INT >= 18) {
                    containerView.setLayerType(View.LAYER_TYPE_NONE, null);
                }
                animationInProgress = 0;
                transitionAnimationStartTime = 0;
                setImages();
                containerView.invalidate();
                animatingImageView.setVisibility(View.GONE);
                if (showAfterAnimation != null) {
                    showAfterAnimation.imageReceiver.setVisible(true, true);
                }
                if (hideAfterAnimation != null) {
                    hideAfterAnimation.imageReceiver.setVisible(false, true);
                }
                if (photos != null && sendPhotoType != 3) {
                    if (Build.VERSION.SDK_INT >= 21) {
                        windowLayoutParams.flags = WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN
                                | WindowManager.LayoutParams.FLAG_LAYOUT_INSET_DECOR
                                | WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS;
                    } else {
                        windowLayoutParams.flags = 0;
                    }
                    windowLayoutParams.softInputMode = WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE
                            | WindowManager.LayoutParams.SOFT_INPUT_IS_FORWARD_NAVIGATION;
                    WindowManager wm = (WindowManager) parentActivity.getSystemService(Context.WINDOW_SERVICE);
                    wm.updateViewLayout(windowView, windowLayoutParams);
                    windowView.setFocusable(true);
                    containerView.setFocusable(true);
                }
            }
        };

        animatorSet.setDuration(200);
        animatorSet.addListener(new AnimatorListenerAdapterProxy() {
            @Override
            public void onAnimationEnd(Animator animation) {
                AndroidUtilities.runOnUIThread(new Runnable() {
                    @Override
                    public void run() {
                        NotificationCenter.getInstance().setAnimationInProgress(false);
                        if (animationEndRunnable != null) {
                            animationEndRunnable.run();
                            animationEndRunnable = null;
                        }
                    }
                });
            }
        });
        transitionAnimationStartTime = System.currentTimeMillis();
        AndroidUtilities.runOnUIThread(new Runnable() {
            @Override
            public void run() {
                NotificationCenter.getInstance()
                        .setAllowedNotificationsDutingAnimation(new int[] {
                                NotificationCenter.dialogsNeedReload, NotificationCenter.closeChats,
                                NotificationCenter.mediaCountDidLoaded, NotificationCenter.mediaDidLoaded,
                                NotificationCenter.dialogPhotosLoaded });
                NotificationCenter.getInstance().setAnimationInProgress(true);
                animatorSet.start();
            }
        });
        if (Build.VERSION.SDK_INT >= 18) {
            containerView.setLayerType(View.LAYER_TYPE_HARDWARE, null);
        }
        backgroundDrawable.drawRunnable = new Runnable() {
            @Override
            public void run() {
                disableShowCheck = false;
                object.imageReceiver.setVisible(false, true);
            }
        };
    } else {
        if (photos != null && sendPhotoType != 3) {
            if (Build.VERSION.SDK_INT >= 21) {
                windowLayoutParams.flags = WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN
                        | WindowManager.LayoutParams.FLAG_LAYOUT_INSET_DECOR
                        | WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS;
            } else {
                windowLayoutParams.flags = 0;
            }
            windowLayoutParams.softInputMode = WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE
                    | WindowManager.LayoutParams.SOFT_INPUT_IS_FORWARD_NAVIGATION;
            wm.updateViewLayout(windowView, windowLayoutParams);
            windowView.setFocusable(true);
            containerView.setFocusable(true);
        }

        backgroundDrawable.setAlpha(255);
        containerView.setAlpha(1.0f);
        onPhotoShow(messageObject, fileLocation, messages, photos, index, object);
    }
    return true;
}