Example usage for android.content Context WINDOW_SERVICE

List of usage examples for android.content Context WINDOW_SERVICE

Introduction

In this page you can find the example usage for android.content Context WINDOW_SERVICE.

Prototype

String WINDOW_SERVICE

To view the source code for android.content Context WINDOW_SERVICE.

Click Source Link

Document

Use with #getSystemService(String) to retrieve a android.view.WindowManager for accessing the system's window manager.

Usage

From source file:com.klinker.android.sliding.MultiShrinkScroller.java

public void reverseExpansionAnimation() {

    final Interpolator interpolator;

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        interpolator = AnimationUtils.loadInterpolator(getContext(), android.R.interpolator.linear_out_slow_in);
    } else {/*from   w  w w  .  jav  a2 s.c om*/
        interpolator = new DecelerateInterpolator();
    }

    WindowManager wm = (WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE);
    Display display = wm.getDefaultDisplay();
    Point size = new Point();
    display.getSize(size);
    int screenHeight = size.y;
    int screenWidth = size.x;

    final ValueAnimator heightExpansion = ValueAnimator.ofInt(screenHeight, expansionViewHeight);
    heightExpansion.setInterpolator(interpolator);
    heightExpansion.setDuration(ANIMATION_DURATION);
    heightExpansion.addUpdateListener(new AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            int val = (int) animation.getAnimatedValue();

            ViewGroup.LayoutParams params = getLayoutParams();
            params.height = val;
            setLayoutParams(params);
        }
    });
    heightExpansion.start();

    final ValueAnimator widthExpansion = ValueAnimator.ofInt(getWidth(), expansionViewWidth);
    widthExpansion.setInterpolator(interpolator);
    widthExpansion.setDuration(ANIMATION_DURATION);
    widthExpansion.addUpdateListener(new AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            int val = (int) animation.getAnimatedValue();

            ViewGroup.LayoutParams params = getLayoutParams();
            params.width = val;
            setLayoutParams(params);
        }
    });
    widthExpansion.start();

    ObjectAnimator translationX = ObjectAnimator.ofFloat(this, View.TRANSLATION_X, 0f, expansionLeftOffset);
    translationX.setInterpolator(interpolator);
    translationX.setDuration(ANIMATION_DURATION);
    translationX.start();

    ObjectAnimator translationY = ObjectAnimator.ofFloat(this, View.TRANSLATION_Y, 0f, expansionTopOffset);
    translationY.setInterpolator(interpolator);
    translationY.setDuration(ANIMATION_DURATION);
    translationY.addListener(exitAnimationListner);
    translationY.start();
}

From source file:com.android.tv.MainActivity.java

@Override
public void onDetachedFromWindow() {
    super.onDetachedFromWindow();
    ((WindowManager) getSystemService(Context.WINDOW_SERVICE)).removeView(mOverlayRootView);
}

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;//w w  w .ja  v a  2s  .c  om
    }

    // 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:org.planetmono.dcuploader.ActivityUploader.java

private void initViews() {
    WindowManager wm = (WindowManager) getSystemService(Context.WINDOW_SERVICE);
    if (wm.getDefaultDisplay().getOrientation() == 0)
        setContentView(R.layout.upload_portrait);
    else//from   w  w w.  j  av  a2 s.co  m
        setContentView(R.layout.upload_landscape);

    EditText uploadTarget = (EditText) findViewById(R.id.upload_target);
    EditText uploadTitle = (EditText) findViewById(R.id.upload_title);
    EditText uploadText = (EditText) findViewById(R.id.upload_text);
    Button uploadVisit = (Button) findViewById(R.id.upload_visit);
    Button uploadPhotoTake = (Button) findViewById(R.id.upload_photo_take);
    Button uploadPhotoAdd = (Button) findViewById(R.id.upload_photo_add);
    Button uploadPhotoDelete = (Button) findViewById(R.id.upload_photo_delete);
    CheckBox uploadEnclosePosition = (CheckBox) findViewById(R.id.upload_enclose_position);
    Button uploadOk = (Button) findViewById(R.id.upload_ok);
    Button uploadCancel = (Button) findViewById(R.id.upload_cancel);

    /* set button behavior */

    if (passThrough)
        uploadTarget.setClickable(false);
    else {
        uploadTarget.setClickable(true);
        registerForContextMenu(uploadTarget);
    }

    uploadTarget.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            if (!passThrough)
                openContextMenu(v);
        }
    });

    registerForContextMenu(uploadVisit);
    uploadVisit.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            openContextMenu(v);
        }
    });

    uploadPhotoTake.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            try {
                tempFile = File.createTempFile("dcuploader_photo_", ".jpg");
            } catch (IOException e) {
                Toast.makeText(ActivityUploader.this, " ??   .",
                        Toast.LENGTH_SHORT).show();

                tempFile = null;

                return;
            }

            Intent i = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
            if (tempFile != null)
                i.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(tempFile));

            startActivityForResult(i, Application.ACTION_TAKE_PHOTO);
        }
    });

    uploadPhotoAdd.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            Intent i = new Intent(Intent.ACTION_GET_CONTENT);
            i.setType("image/*");
            i.addCategory(Intent.CATEGORY_DEFAULT);

            startActivityForResult(i, Application.ACTION_ADD_PHOTO);
        }
    });

    uploadPhotoDelete.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            Gallery g = (Gallery) findViewById(R.id.upload_images);

            int pos = g.getSelectedItemPosition();
            if (pos == -1)
                return;

            contents.remove(pos);
            bitmaps.remove(pos);

            updateGallery();
            updateImageButtons();

            if (contents.size() == 0)
                pos = -1;
            else if (pos >= contents.size())
                --pos;

            g.setSelection(pos);
        }
    });

    uploadOk.setOnClickListener(proceedHandler);

    uploadCancel.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            finish();
        }
    });

    uploadEnclosePosition.setChecked(formLocation);

    uploadEnclosePosition.setOnCheckedChangeListener(new OnCheckedChangeListener() {
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            locationEnabled = isChecked;

            queryLocation(isChecked);
        }
    });

    /* restore data when orientation changes */
    if (formGallery != null) {
        if (target != null) {
            uploadTarget.setText(formGallery);
            formGallery = null;
        }
    }

    if (formTitle != null) {
        uploadTitle.setText(formTitle);
        formTitle = null;
    }

    if (formBody != null) {
        uploadText.setText(formBody);
        formBody = null;
    }

    updateImageButtons();
    updateGallery();
}

From source file:com.danilov.supermanga.core.view.SlidingLayer.java

@SuppressWarnings("deprecation")
private int getScreenSideAuto(int newLeft, int newRight) {

    int newScreenSide;

    if (mScreenSide == STICK_TO_AUTO) {
        int screenWidth;
        Display display = ((WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE))
                .getDefaultDisplay();//w  ww.j a  v a 2  s  .  c om
        try {
            Class<?> cls = Display.class;
            Class<?>[] parameterTypes = { Point.class };
            Point parameter = new Point();
            Method method = cls.getMethod("getSize", parameterTypes);
            method.invoke(display, parameter);
            screenWidth = parameter.x;
        } catch (Exception e) {
            screenWidth = display.getWidth();
        }

        boolean boundToLeftBorder = newLeft == 0;
        boolean boundToRightBorder = newRight == screenWidth;

        if (boundToLeftBorder == boundToRightBorder
                && getLayoutParams().width == android.view.ViewGroup.LayoutParams.MATCH_PARENT) {
            newScreenSide = STICK_TO_MIDDLE;
        } else if (boundToLeftBorder) {
            newScreenSide = STICK_TO_LEFT;
        } else {
            newScreenSide = STICK_TO_RIGHT;
        }
    } else {
        newScreenSide = mScreenSide;
    }

    return newScreenSide;
}

From source file:com.ferdi2005.secondgram.AndroidUtilities.java

public static Point getRealScreenSize() {
    Point size = new Point();
    try {/*  w  w  w  .j  a  v  a  2 s .c om*/
        WindowManager windowManager = (WindowManager) ApplicationLoader.applicationContext
                .getSystemService(Context.WINDOW_SERVICE);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
            windowManager.getDefaultDisplay().getRealSize(size);
        } else {
            try {
                Method mGetRawW = Display.class.getMethod("getRawWidth");
                Method mGetRawH = Display.class.getMethod("getRawHeight");
                size.set((Integer) mGetRawW.invoke(windowManager.getDefaultDisplay()),
                        (Integer) mGetRawH.invoke(windowManager.getDefaultDisplay()));
            } catch (Exception e) {
                size.set(windowManager.getDefaultDisplay().getWidth(),
                        windowManager.getDefaultDisplay().getHeight());
                FileLog.e(e);
            }
        }
    } catch (Exception e) {
        FileLog.e(e);
    }
    return size;
}

From source file:bk.vinhdo.taxiads.utils.view.SlidingLayer.java

@SuppressWarnings("deprecation")
private int getScreenSideAuto(int newLeft, int newRight) {

    int newScreenSide;

    if (mScreenSide == STICK_TO_AUTO) {
        int screenWidth;
        Display display = ((WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE))
                .getDefaultDisplay();//from   w  ww  . j  av  a 2s .c  o m
        try {
            Class<?> cls = Display.class;
            Class<?>[] parameterTypes = { Point.class };
            Point parameter = new Point();
            Method method = cls.getMethod("getSize", parameterTypes);
            method.invoke(display, parameter);
            screenWidth = parameter.x;
        } catch (Exception e) {
            screenWidth = display.getWidth();
        }

        boolean boundToLeftBorder = newLeft == 0;
        boolean boundToRightBorder = newRight == screenWidth;

        if (boundToLeftBorder == boundToRightBorder && getLayoutParams().width == LayoutParams.MATCH_PARENT) {
            newScreenSide = STICK_TO_MIDDLE;
        } else if (boundToLeftBorder) {
            newScreenSide = STICK_TO_LEFT;
        } else {
            newScreenSide = STICK_TO_RIGHT;
        }
    } else {
        newScreenSide = mScreenSide;
    }

    return newScreenSide;
}

From source file:com.aimfire.demo.CameraActivity.java

public int getDeviceDefaultOrientation() {
    WindowManager windowManager = (WindowManager) getSystemService(Context.WINDOW_SERVICE);

    Configuration config = getResources().getConfiguration();

    int rotation = windowManager.getDefaultDisplay().getRotation();

    if (((rotation == Surface.ROTATION_0 || rotation == Surface.ROTATION_180)
            && config.orientation == Configuration.ORIENTATION_LANDSCAPE)
            || ((rotation == Surface.ROTATION_90 || rotation == Surface.ROTATION_270)
                    && config.orientation == Configuration.ORIENTATION_PORTRAIT)) {
        return Configuration.ORIENTATION_LANDSCAPE;
    } else {//ww  w. jav a2  s.com
        return Configuration.ORIENTATION_PORTRAIT;
    }
}

From source file:com.appfeel.cordova.admob.AdMobAds.java

public static DisplayMetrics DisplayInfo(Context p_context) {
    DisplayMetrics metrics = null;//  w w w.  j  av  a 2 s. c om
    try {
        metrics = new DisplayMetrics();
        ((android.view.WindowManager) p_context.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay()
                .getMetrics(metrics);
        //p_activity.getWindowManager().getDefaultDisplay().getMetrics(metrics);
    } catch (Exception e) {
    }
    return metrics;
}

From source file:com.farmerbb.taskbar.service.TaskbarService.java

private int getNavBarSize() {
    Point size = new Point();
    Point realSize = new Point();

    WindowManager wm = (WindowManager) getSystemService(Context.WINDOW_SERVICE);
    Display display = wm.getDefaultDisplay();
    display.getSize(size);//from w  w  w . jav a2 s.  c  om
    display.getRealSize(realSize);

    return realSize.y - size.y;
}