Example usage for android.view WindowManager addView

List of usage examples for android.view WindowManager addView

Introduction

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

Prototype

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

Source Link

Document

Assign the passed LayoutParams to the passed View and add the view to the window.

Usage

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

void createView() {
    LayoutInflater inflater = (LayoutInflater) this.context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    this.unlockToContinueView = inflater.inflate(R.layout.lockscreen_unlock_to_continue_view, null);
    this.widgetView = inflater.inflate(R.layout.lockscreen_widget, null);
    this.rootView = new InterceptTouchFrameLayout(this.context);
    LayoutParams params = new LayoutParams(-1, -2, 2010, 16777496, -3);
    WindowManager windowManager = (WindowManager) this.context.getSystemService("window");
    params.gravity = 51;/* ww  w. j a v  a2  s  .  co  m*/
    params.y = 0;
    windowManager.addView(this.rootView, params);
    this.rootView.addView(this.widgetView);
    this.widgetView.setAlpha(0.0f);
    this.fullscreenView = new LinearLayout(this.context);
    params = new LayoutParams(-1, -2, 2010, 16777496, -3);
    params.gravity = 51;
    params.width = -1;
    params.height = -1;
    windowManager.addView(this.fullscreenView, params);
    this.fullscreenView.setAlpha(DefaultRetryPolicy.DEFAULT_BACKOFF_MULT);
    this.pagerView = (ViewPager) this.widgetView.findViewById(R.id.lockscreen_widget_pager);
    this.pagesView = (LockscreenWidgetPagesLayout) this.widgetView.findViewById(R.id.lockscreen_widget_pages);
    this.pagerAdapter = new LockScreenWidgetPagerAdapter();
    this.pagerAdapter.start(this.context, this.showSinceLastMessageId, 5);
    this.pagerView.setAdapter(this.pagerAdapter);
    this.pagerView.setOnPageChangeListener(new OnPageChangeListener() {
        public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
        }

        public void onPageSelected(int position) {
            LockScreenWidget.this.pagesView.setSelectedPage(position);
        }

        public void onPageScrollStateChanged(int state) {
            if (state == 0) {
                Log.d(LockScreenWidget.TAG, "Pager is NOT being dragged");
                LockScreenWidget.this.isPagerBeingDragged = false;
                return;
            }
            Log.d(LockScreenWidget.TAG, "Pager is being dragged");
            LockScreenWidget.this.isPagerBeingDragged = true;
        }
    });
    resetPageAdapter();
}

From source file:de.localtoast.launchit.BackgroundService.java

private void switchToSidebar() {
    if (!sidebarVisible) {
        sidebarVisible = true;// w w  w  .ja  v a2s  .com

        Context context = getBaseContext();

        WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
        WindowManager.LayoutParams params = new WindowManager.LayoutParams(225,
                WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.TYPE_PHONE,
                WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH
                        | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL,
                PixelFormat.TRANSLUCENT);
        params.gravity = Gravity.TOP | Gravity.RIGHT;

        removeView();
        wm.addView(sidebar, params);
        // TODO move this animation stuff in some sort of gui class or directly to the view
        Animation animation = AnimationUtils.loadAnimation(context, R.anim.slide_in_right);
        animation.setDuration(FADING_DURATION_MS);
        appListView.startAnimation(animation);
        appListView.setVisibility(View.VISIBLE);
    }
}

From source file:at.andreasrohner.spartantimelapserec.BackgroundService.java

@SuppressWarnings("deprecation")
@Override/*from www.j a  v a2 s. c om*/
public void onCreate() {
    created = true;

    settings = new RecSettings();
    settings.load(getApplicationContext(),
            PreferenceManager.getDefaultSharedPreferences(getApplicationContext()));

    createNotification(NOTIFICATION_ID);

    if (settings.isSchedRecEnabled() && settings.getSchedRecTime() > System.currentTimeMillis() + 10000) {
        AlarmManager alarmMgr = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
        Intent intent = new Intent(getApplicationContext(), ScheduleReceiver.class);
        PendingIntent alarmIntent = PendingIntent.getBroadcast(getApplicationContext(), 0, intent, 0);

        alarmMgr.set(AlarmManager.RTC_WAKEUP, settings.getSchedRecTime(), alarmIntent);

        stopSelf();
        return;
    }

    // Create new SurfaceView, set its size to 1x1, move
    // it to the top left corner and set this service as a callback
    WindowManager winMgr = (WindowManager) getSystemService(Context.WINDOW_SERVICE);
    surfaceView = new SurfaceView(this);
    // deprecated setting, but required on Android versions prior to 3.0
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB)
        surfaceView.getHolder().setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
    surfaceView.getHolder().addCallback(this);

    LayoutParams layoutParams = new WindowManager.LayoutParams(1, 1,
            WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY, WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH,
            PixelFormat.TRANSLUCENT);
    layoutParams.gravity = Gravity.LEFT | Gravity.TOP;
    winMgr.addView(surfaceView, layoutParams);

    PowerManager powerManager = (PowerManager) getSystemService(POWER_SERVICE);
    wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, TAG);
    wakeLock.setReferenceCounted(false);
    wakeLock.acquire();
}

From source file:com.example.accessibility.OverlayManager.java

void createFeedbackClickView(Context context) {
    //The overlay with visual feedback and scroll buttons is created here. It's a FeedbackClickView.

    mContext = context;/*from  w  w w .  j a va2  s  . c  om*/
    // ////////////////////////////////////////////////////////////////////////////////
    // FeedbackClickView
    LayoutParams feedbackParams = new LayoutParams();
    feedbackParams.setTitle("OverlayManager");

    // Set a transparent background
    feedbackParams.format = PixelFormat.TRANSLUCENT;

    // Create an always on top type of window:
    //  TYPE_SYSTEM_ALERT   = touch events are intercepted
    feedbackParams.type = LayoutParams.TYPE_PHONE | LayoutParams.TYPE_SYSTEM_OVERLAY;

    // The whole screen is covered (including status bar)
    feedbackParams.flags = LayoutParams.FLAG_NOT_FOCUSABLE | LayoutParams.FLAG_LAYOUT_IN_SCREEN;
    // ////////////////////////////////////////////////////////////////////////////////

    WindowManager wm = (WindowManager) getSystemService(WINDOW_SERVICE);

    if (mFCV == null) {

        mFCV = new FeedbackClickView(this.getApplicationContext());

        showScrollButtons();
        wm.addView(mFCV, feedbackParams);
    }
    Log.i("prints", "acaba createFeedbackClickView del Overlay");
}

From source file:com.example.accessibility.OverlayManager.java

void createOverlayView(Context context) {
    //The overlay with global buttons that listens touch events is created here. It's a ListenerView.

    mContext = context;/*from   w  w w .  j  a  va  2s  .  c o  m*/
    // ////////////////////////////////////////////////////////////////////////////////
    // ListenerView
    LayoutParams listenerParams = new LayoutParams();
    listenerParams.setTitle("OverlayManager");

    // Set a transparent background
    listenerParams.format = PixelFormat.TRANSLUCENT;

    // Create an always on top type of window:
    //  TYPE_SYSTEM_ALERT   = touch events are intercepted
    listenerParams.type = LayoutParams.TYPE_SYSTEM_ALERT | LayoutParams.TYPE_PHONE
            | LayoutParams.TYPE_SYSTEM_OVERLAY;

    // The whole screen is covered (including status bar)
    listenerParams.flags = LayoutParams.FLAG_NOT_FOCUSABLE | LayoutParams.FLAG_LAYOUT_IN_SCREEN;
    // ////////////////////////////////////////////////////////////////////////////////

    showScrollButtons();

    WindowManager wm = (WindowManager) getSystemService(WINDOW_SERVICE);

    if (mLV == null) {
        mLV = new ListenerView(this.getApplicationContext());
        //LV.setTouchable(true);
        mLV.setOnTouchListener(this);
        wm.addView(mLV, listenerParams);
    }
    Log.i("prints", "acaba createOverlayView del Overlay");
}

From source file:og.android.tether.MainActivity.java

private void openAdBar() {
    LayoutInflater li = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    final View ad_view = li.inflate(R.layout.ad_view, null);
    ad_view.setBackgroundColor(Color.TRANSPARENT);

    final WindowManager wm = getWindowManager();
    WindowManager.LayoutParams wmParams = new WindowManager.LayoutParams();
    wmParams.height = WindowManager.LayoutParams.WRAP_CONTENT;
    wmParams.width = WindowManager.LayoutParams.WRAP_CONTENT;
    wmParams.gravity = Gravity.BOTTOM;/* w  ww .  j  a va2s.  c  o  m*/
    wmParams.y = 100;
    wmParams.flags = WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL;
    wmParams.format = PixelFormat.TRANSLUCENT;

    wm.addView(ad_view, wmParams);

    View ad_open = ad_view.findViewById(R.id.ad_open);
    View ad_close = ad_view.findViewById(R.id.ad_close);

    OnClickListener adListener = new OnClickListener() {
        @Override
        public void onClick(View v) {
            switch (v.getId()) {
            case R.id.ad_open:
                Log.i(MSG_TAG, "ad_open");
                Intent i = new Intent();
                i.setAction(Intent.ACTION_VIEW);
                i.addCategory(Intent.CATEGORY_BROWSABLE);
                i.setData(Uri.parse(
                        "market://details?id=com.opengarden.radiofreenet&referrer=utm_source%3Dog.android.tether%26utm_medium%3Dandroid%26utm_campaign%3Dbanner%26utm_content%3Dinstall"));
                try {
                    startActivity(i);
                } catch (android.content.ActivityNotFoundException e) {
                    Log.e(MSG_TAG, "", e);
                    MainActivity.this.application.displayToastMessage(e.toString());
                }
                break;

            case R.id.ad_close:
                Log.i(MSG_TAG, "ad_close");
                wm.removeView(ad_view);
                break;

            default:
                Log.i(MSG_TAG, "default");
                break;
            }
        }
    };
    ad_open.setOnClickListener(adListener);
    ad_close.setOnClickListener(adListener);
}

From source file:android.support.v7.app.AppCompatDelegateImplV7.java

private void openPanel(final PanelFeatureState st, KeyEvent event) {
    // Already open, return
    if (st.isOpen || isDestroyed()) {
        return;/*ww  w.j av  a  2 s .c  o m*/
    }

    // Don't open an options panel for honeycomb apps on xlarge devices.
    // (The app should be using an action bar for menu items.)
    if (st.featureId == FEATURE_OPTIONS_PANEL) {
        Context context = mContext;
        Configuration config = context.getResources().getConfiguration();
        boolean isXLarge = (config.screenLayout
                & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_XLARGE;
        boolean isHoneycombApp = context
                .getApplicationInfo().targetSdkVersion >= android.os.Build.VERSION_CODES.HONEYCOMB;

        if (isXLarge && isHoneycombApp) {
            return;
        }
    }

    Window.Callback cb = getWindowCallback();
    if ((cb != null) && (!cb.onMenuOpened(st.featureId, st.menu))) {
        // Callback doesn't want the menu to open, reset any state
        closePanel(st, true);
        return;
    }

    final WindowManager wm = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
    if (wm == null) {
        return;
    }

    // Prepare panel (should have been done before, but just in case)
    if (!preparePanel(st, event)) {
        return;
    }

    int width = WRAP_CONTENT;
    if (st.decorView == null || st.refreshDecorView) {
        if (st.decorView == null) {
            // Initialize the panel decor, this will populate st.decorView
            if (!initializePanelDecor(st) || (st.decorView == null))
                return;
        } else if (st.refreshDecorView && (st.decorView.getChildCount() > 0)) {
            // Decor needs refreshing, so remove its views
            st.decorView.removeAllViews();
        }

        // This will populate st.shownPanelView
        if (!initializePanelContent(st) || !st.hasPanelItems()) {
            return;
        }

        ViewGroup.LayoutParams lp = st.shownPanelView.getLayoutParams();
        if (lp == null) {
            lp = new ViewGroup.LayoutParams(WRAP_CONTENT, WRAP_CONTENT);
        }

        int backgroundResId = st.background;
        st.decorView.setBackgroundResource(backgroundResId);

        ViewParent shownPanelParent = st.shownPanelView.getParent();
        if (shownPanelParent != null && shownPanelParent instanceof ViewGroup) {
            ((ViewGroup) shownPanelParent).removeView(st.shownPanelView);
        }
        st.decorView.addView(st.shownPanelView, lp);

        /*
         * Give focus to the view, if it or one of its children does not
         * already have it.
         */
        if (!st.shownPanelView.hasFocus()) {
            st.shownPanelView.requestFocus();
        }
    } else if (st.createdPanelView != null) {
        // If we already had a panel view, carry width=MATCH_PARENT through
        // as we did above when it was created.
        ViewGroup.LayoutParams lp = st.createdPanelView.getLayoutParams();
        if (lp != null && lp.width == ViewGroup.LayoutParams.MATCH_PARENT) {
            width = MATCH_PARENT;
        }
    }

    st.isHandled = false;

    WindowManager.LayoutParams lp = new WindowManager.LayoutParams(width, WRAP_CONTENT, st.x, st.y,
            WindowManager.LayoutParams.TYPE_APPLICATION_SUB_PANEL,
            WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM | WindowManager.LayoutParams.FLAG_SPLIT_TOUCH,
            PixelFormat.TRANSLUCENT);

    lp.gravity = st.gravity;
    lp.windowAnimations = st.windowAnimations;

    wm.addView(st.decorView, lp);
    st.isOpen = 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  ww  w  .  jav a  2  s.  c o  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;
    }/* w w  w  .  ja va  2 s.c o  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", 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;
}

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;
    }/*w  w w  .  j  a v  a  2s. c o 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;
}