Search in sources :

Example 91 with Display

use of android.view.Display in project platform_frameworks_base by android.

the class BigCache method onCreate.

@Override
protected void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    final LinearLayout testBed = new LinearLayout(this);
    testBed.setOrientation(LinearLayout.VERTICAL);
    testBed.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
    final int cacheSize = ViewConfiguration.getMaximumDrawingCacheSize();
    final Display display = getWindowManager().getDefaultDisplay();
    final int screenWidth = display.getWidth();
    final int screenHeight = display.getHeight();
    final View tiny = new View(this);
    tiny.setId(R.id.a);
    tiny.setBackgroundColor(0xFFFF0000);
    tiny.setLayoutParams(new LinearLayout.LayoutParams(screenWidth, screenHeight));
    final View large = new View(this);
    large.setId(R.id.b);
    large.setBackgroundColor(0xFF00FF00);
    // Compute the height of the view assuming a cache size based on ARGB8888
    final int height = 2 * (cacheSize / 2) / screenWidth;
    large.setLayoutParams(new LinearLayout.LayoutParams(screenWidth, height));
    final ScrollView scroller = new ScrollView(this);
    scroller.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
    testBed.addView(tiny);
    testBed.addView(large);
    scroller.addView(testBed);
    setContentView(scroller);
}
Also used : ScrollView(android.widget.ScrollView) ViewGroup(android.view.ViewGroup) ScrollView(android.widget.ScrollView) View(android.view.View) LinearLayout(android.widget.LinearLayout) Display(android.view.Display)

Example 92 with Display

use of android.view.Display in project platform_frameworks_base by android.

the class Screenshooter method takeScreenshot.

/**
     * Takes a screenshot.
     *
     * @return The screenshot bitmap on success, null otherwise.
     */
static Bitmap takeScreenshot() {
    Display display = DisplayManagerGlobal.getInstance().getRealDisplay(Display.DEFAULT_DISPLAY);
    Point displaySize = new Point();
    display.getRealSize(displaySize);
    final int displayWidth = displaySize.x;
    final int displayHeight = displaySize.y;
    final float screenshotWidth;
    final float screenshotHeight;
    final int rotation = display.getRotation();
    switch(rotation) {
        case ROTATION_FREEZE_0:
            {
                screenshotWidth = displayWidth;
                screenshotHeight = displayHeight;
            }
            break;
        case ROTATION_FREEZE_90:
            {
                screenshotWidth = displayHeight;
                screenshotHeight = displayWidth;
            }
            break;
        case ROTATION_FREEZE_180:
            {
                screenshotWidth = displayWidth;
                screenshotHeight = displayHeight;
            }
            break;
        case ROTATION_FREEZE_270:
            {
                screenshotWidth = displayHeight;
                screenshotHeight = displayWidth;
            }
            break;
        default:
            {
                throw new IllegalArgumentException("Invalid rotation: " + rotation);
            }
    }
    Log.d(TAG, "Taking screenshot of dimensions " + displayWidth + " x " + displayHeight);
    // Take the screenshot
    Bitmap screenShot = SurfaceControl.screenshot((int) screenshotWidth, (int) screenshotHeight);
    if (screenShot == null) {
        Log.e(TAG, "Failed to take screenshot of dimensions " + screenshotWidth + " x " + screenshotHeight);
        return null;
    }
    // Rotate the screenshot to the current orientation
    if (rotation != ROTATION_FREEZE_0) {
        Bitmap unrotatedScreenShot = Bitmap.createBitmap(displayWidth, displayHeight, Bitmap.Config.ARGB_8888);
        Canvas canvas = new Canvas(unrotatedScreenShot);
        canvas.translate(unrotatedScreenShot.getWidth() / 2, unrotatedScreenShot.getHeight() / 2);
        canvas.rotate(getDegreesForRotation(rotation));
        canvas.translate(-screenshotWidth / 2, -screenshotHeight / 2);
        canvas.drawBitmap(screenShot, 0, 0, null);
        canvas.setBitmap(null);
        screenShot.recycle();
        screenShot = unrotatedScreenShot;
    }
    // Optimization
    screenShot.setHasAlpha(false);
    return screenShot;
}
Also used : Bitmap(android.graphics.Bitmap) Canvas(android.graphics.Canvas) Point(android.graphics.Point) Point(android.graphics.Point) Display(android.view.Display)

Example 93 with Display

use of android.view.Display in project platform_frameworks_base by android.

the class TaskCardView method getStartingCardThumbnailRectForStartPosition.

private static Rect getStartingCardThumbnailRectForStartPosition(Context context, boolean hasFocus) {
    Resources res = context.getResources();
    int width = res.getDimensionPixelOffset(R.dimen.recents_tv_card_width);
    int totalSpacing = res.getDimensionPixelOffset(R.dimen.recents_tv_gird_card_spacing) * 2;
    if (hasFocus) {
        totalSpacing += res.getDimensionPixelOffset(R.dimen.recents_tv_gird_focused_card_delta);
    }
    int height = res.getDimensionPixelOffset(R.dimen.recents_tv_screenshot_height);
    int topMargin = res.getDimensionPixelOffset(R.dimen.recents_tv_gird_row_top_margin);
    int headerHeight = res.getDimensionPixelOffset(R.dimen.recents_tv_card_extra_badge_size) + res.getDimensionPixelOffset(R.dimen.recents_tv_icon_padding_bottom);
    WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    Display display = wm.getDefaultDisplay();
    Point size = new Point();
    display.getSize(size);
    int screenWidth = size.x;
    return new Rect(screenWidth / 2 + width / 2 + totalSpacing, topMargin + headerHeight, screenWidth / 2 + width / 2 + totalSpacing + width, topMargin + headerHeight + height);
}
Also used : Rect(android.graphics.Rect) Resources(android.content.res.Resources) Point(android.graphics.Point) Point(android.graphics.Point) WindowManager(android.view.WindowManager) Display(android.view.Display)

Example 94 with Display

use of android.view.Display in project platform_frameworks_base by android.

the class TouchUtils method dragQuarterScreenUp.

/**
     * Simulate touching in the center of the screen and dragging one quarter of the way up
     * @param test The test case that is being run
     * @param activity The activity that is in the foreground of the test case
     */
public static void dragQuarterScreenUp(InstrumentationTestCase test, Activity activity) {
    Display display = activity.getWindowManager().getDefaultDisplay();
    final Point size = new Point();
    display.getSize(size);
    final float x = size.x / 2.0f;
    final float fromY = size.y * 0.5f;
    final float toY = size.y * 0.25f;
    drag(test, x, x, fromY, toY, 4);
}
Also used : Point(android.graphics.Point) Display(android.view.Display)

Example 95 with Display

use of android.view.Display in project platform_frameworks_base by android.

the class Session method performDrag.

public boolean performDrag(IWindow window, IBinder dragToken, int touchSource, float touchX, float touchY, float thumbCenterX, float thumbCenterY, ClipData data) {
    if (DEBUG_DRAG) {
        Slog.d(TAG_WM, "perform drag: win=" + window + " data=" + data);
    }
    synchronized (mService.mWindowMap) {
        if (mService.mDragState == null) {
            Slog.w(TAG_WM, "No drag prepared");
            throw new IllegalStateException("performDrag() without prepareDrag()");
        }
        if (dragToken != mService.mDragState.mToken) {
            Slog.w(TAG_WM, "Performing mismatched drag");
            throw new IllegalStateException("performDrag() does not match prepareDrag()");
        }
        WindowState callingWin = mService.windowForClientLocked(null, window, false);
        if (callingWin == null) {
            Slog.w(TAG_WM, "Bad requesting window " + window);
            // !!! TODO: throw here?
            return false;
        }
        // !!! TODO: if input is not still focused on the initiating window, fail
        // the drag initiation (e.g. an alarm window popped up just as the application
        // called performDrag()
        mService.mH.removeMessages(H.DRAG_START_TIMEOUT, window.asBinder());
        // !!! TODO: extract the current touch (x, y) in screen coordinates.  That
        // will let us eliminate the (touchX,touchY) parameters from the API.
        // !!! FIXME: put all this heavy stuff onto the mH looper, as well as
        // the actual drag event dispatch stuff in the dragstate
        final DisplayContent displayContent = callingWin.getDisplayContent();
        if (displayContent == null) {
            return false;
        }
        Display display = displayContent.getDisplay();
        mService.mDragState.register(display);
        mService.mInputMonitor.updateInputWindowsLw(true);
        if (!mService.mInputManager.transferTouchFocus(callingWin.mInputChannel, mService.mDragState.mServerChannel)) {
            Slog.e(TAG_WM, "Unable to transfer touch focus");
            mService.mDragState.unregister();
            mService.mDragState = null;
            mService.mInputMonitor.updateInputWindowsLw(true);
            return false;
        }
        mService.mDragState.mData = data;
        mService.mDragState.broadcastDragStartedLw(touchX, touchY);
        mService.mDragState.overridePointerIconLw(touchSource);
        // remember the thumb offsets for later
        mService.mDragState.mThumbOffsetX = thumbCenterX;
        mService.mDragState.mThumbOffsetY = thumbCenterY;
        // Make the surface visible at the proper location
        final SurfaceControl surfaceControl = mService.mDragState.mSurfaceControl;
        if (SHOW_LIGHT_TRANSACTIONS)
            Slog.i(TAG_WM, ">>> OPEN TRANSACTION performDrag");
        SurfaceControl.openTransaction();
        try {
            surfaceControl.setPosition(touchX - thumbCenterX, touchY - thumbCenterY);
            surfaceControl.setLayer(mService.mDragState.getDragLayerLw());
            surfaceControl.setLayerStack(display.getLayerStack());
            surfaceControl.show();
        } finally {
            SurfaceControl.closeTransaction();
            if (SHOW_LIGHT_TRANSACTIONS)
                Slog.i(TAG_WM, "<<< CLOSE TRANSACTION performDrag");
        }
        mService.mDragState.notifyLocationLw(touchX, touchY);
    }
    // success!
    return true;
}
Also used : SurfaceControl(android.view.SurfaceControl) Display(android.view.Display)

Aggregations

Display (android.view.Display)697 Point (android.graphics.Point)356 WindowManager (android.view.WindowManager)349 DisplayMetrics (android.util.DisplayMetrics)126 View (android.view.View)57 TextView (android.widget.TextView)54 LinearLayout (android.widget.LinearLayout)45 SuppressLint (android.annotation.SuppressLint)43 Method (java.lang.reflect.Method)41 ImageView (android.widget.ImageView)39 Bitmap (android.graphics.Bitmap)38 Resources (android.content.res.Resources)36 Intent (android.content.Intent)34 Camera (android.hardware.Camera)31 Context (android.content.Context)26 Rect (android.graphics.Rect)25 IOException (java.io.IOException)24 ViewGroup (android.view.ViewGroup)23 Canvas (android.graphics.Canvas)22 RemoteException (android.os.RemoteException)22