Search in sources :

Example 16 with WindowManager

use of android.view.WindowManager in project android_frameworks_base by ParanoidAndroid.

the class WallpaperManager method generateBitmap.

static Bitmap generateBitmap(Context context, Bitmap bm, int width, int height) {
    if (bm == null) {
        return null;
    }
    WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    DisplayMetrics metrics = new DisplayMetrics();
    wm.getDefaultDisplay().getMetrics(metrics);
    bm.setDensity(metrics.noncompatDensityDpi);
    if (width <= 0 || height <= 0 || (bm.getWidth() == width && bm.getHeight() == height)) {
        return bm;
    }
    // This is the final bitmap we want to return.
    try {
        Bitmap newbm = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
        newbm.setDensity(metrics.noncompatDensityDpi);
        Canvas c = new Canvas(newbm);
        Rect targetRect = new Rect();
        targetRect.right = bm.getWidth();
        targetRect.bottom = bm.getHeight();
        int deltaw = width - targetRect.right;
        int deltah = height - targetRect.bottom;
        if (deltaw > 0 || deltah > 0) {
            // We need to scale up so it covers the entire area.
            float scale;
            if (deltaw > deltah) {
                scale = width / (float) targetRect.right;
            } else {
                scale = height / (float) targetRect.bottom;
            }
            targetRect.right = (int) (targetRect.right * scale);
            targetRect.bottom = (int) (targetRect.bottom * scale);
            deltaw = width - targetRect.right;
            deltah = height - targetRect.bottom;
        }
        targetRect.offset(deltaw / 2, deltah / 2);
        Paint paint = new Paint();
        paint.setFilterBitmap(true);
        paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC));
        c.drawBitmap(bm, null, targetRect, paint);
        bm.recycle();
        c.setBitmap(null);
        return newbm;
    } catch (OutOfMemoryError e) {
        Log.w(TAG, "Can't generate default bitmap", e);
        return bm;
    }
}
Also used : Bitmap(android.graphics.Bitmap) Rect(android.graphics.Rect) PorterDuffXfermode(android.graphics.PorterDuffXfermode) Canvas(android.graphics.Canvas) Paint(android.graphics.Paint) DisplayMetrics(android.util.DisplayMetrics) Paint(android.graphics.Paint) WindowManager(android.view.WindowManager)

Example 17 with WindowManager

use of android.view.WindowManager in project android_frameworks_base by ParanoidAndroid.

the class FakeApp method onCreate.

@Override
public void onCreate() {
    String processName = ActivityThread.currentProcessName();
    Slog.i("FakeOEMFeatures", "Creating app in process: " + processName);
    if (!getApplicationInfo().packageName.equals(processName)) {
        // our extra overhead stuff.
        return;
    }
    final WindowManager wm = (WindowManager) getSystemService(Context.WINDOW_SERVICE);
    final Display display = wm.getDefaultDisplay();
    // is a user build, WARN!  Do not want!
    if ("user".equals(android.os.Build.TYPE)) {
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setTitle("Should not be on user build");
        builder.setMessage("The app Fake OEM Features should not be installed on a " + "user build.  Please remove this .apk before shipping this build to " + " your customers!");
        builder.setCancelable(false);
        builder.setPositiveButton("I understand", null);
        Dialog dialog = builder.create();
        dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
        dialog.show();
    }
    // Make a fake window that is always around eating graphics resources.
    FakeView view = new FakeView(this);
    WindowManager.LayoutParams lp = new WindowManager.LayoutParams(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT, WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE | WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
    if (ActivityManager.isHighEndGfx()) {
        lp.flags |= WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED;
    }
    lp.width = ViewGroup.LayoutParams.MATCH_PARENT;
    lp.height = ViewGroup.LayoutParams.MATCH_PARENT;
    int maxSize = display.getMaximumSizeDimension();
    maxSize *= 2;
    lp.x = maxSize;
    lp.y = maxSize;
    lp.setTitle(getPackageName());
    wm.addView(view, lp);
    // Bind to a fake service we want to keep running in another process.
    bindService(new Intent(this, FakeCoreService.class), mServiceConnection, Context.BIND_AUTO_CREATE);
    bindService(new Intent(this, FakeCoreService2.class), mServiceConnection2, Context.BIND_AUTO_CREATE);
    bindService(new Intent(this, FakeCoreService3.class), mServiceConnection3, Context.BIND_AUTO_CREATE);
    // Start to a fake service that should run in the background of
    // another process.
    mHandler.sendEmptyMessage(MSG_TICK);
    // Make a fake allocation to consume some RAM.
    mStuffing = new int[STUFFING_SIZE_INTS];
    for (int i = 0; i < STUFFING_SIZE_BYTES / PAGE_SIZE; i++) {
        // Fill each page with a unique value.
        final int VAL = i * 2 + 100;
        final int OFF = (i * PAGE_SIZE) / 4;
        for (int j = 0; j < (PAGE_SIZE / 4); j++) {
            mStuffing[OFF + j] = VAL;
        }
    }
}
Also used : AlertDialog(android.app.AlertDialog) Intent(android.content.Intent) WindowManager(android.view.WindowManager) Dialog(android.app.Dialog) AlertDialog(android.app.AlertDialog) Display(android.view.Display)

Example 18 with WindowManager

use of android.view.WindowManager in project android_frameworks_base by ParanoidAndroid.

the class LoadAverageService method onCreate.

@Override
public void onCreate() {
    super.onCreate();
    mView = new LoadView(this);
    WindowManager.LayoutParams params = new WindowManager.LayoutParams(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.WRAP_CONTENT, WindowManager.LayoutParams.TYPE_SECURE_SYSTEM_OVERLAY, WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE, PixelFormat.TRANSLUCENT);
    params.gravity = Gravity.END | Gravity.TOP;
    params.setTitle("Load Average");
    WindowManager wm = (WindowManager) getSystemService(WINDOW_SERVICE);
    wm.addView(mView, params);
}
Also used : WindowManager(android.view.WindowManager)

Example 19 with WindowManager

use of android.view.WindowManager in project android_frameworks_base by ParanoidAndroid.

the class PhoneWindow method openPanel.

private void openPanel(PanelFeatureState st, KeyEvent event) {
    // Already open, return
    if (st.isOpen || isDestroyed()) {
        return;
    }
    // (The app should be using an action bar for menu items.)
    if (st.featureId == FEATURE_OPTIONS_PANEL) {
        Context context = getContext();
        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;
        }
    }
    Callback cb = getCallback();
    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 = getWindowManager();
    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;
        if (lp.width == ViewGroup.LayoutParams.MATCH_PARENT) {
            // If the contents is fill parent for the width, set the
            // corresponding background
            backgroundResId = st.fullBackground;
            width = MATCH_PARENT;
        } else {
            // Otherwise, set the normal panel background
            backgroundResId = st.background;
        }
        st.decorView.setWindowBackground(getContext().getResources().getDrawable(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.isInListMode()) {
        width = MATCH_PARENT;
    } 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.isOpen = true;
    st.isHandled = false;
    WindowManager.LayoutParams lp = new WindowManager.LayoutParams(width, WRAP_CONTENT, st.x, st.y, WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG, WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM | WindowManager.LayoutParams.FLAG_SPLIT_TOUCH, st.decorView.mDefaultOpacity);
    if (st.isCompact) {
        lp.gravity = getOptionsPanelGravity();
        sRotationWatcher.addWindow(this);
    } else {
        lp.gravity = st.gravity;
    }
    lp.windowAnimations = st.windowAnimations;
    wm.addView(st.decorView, lp);
// Log.v(TAG, "Adding main menu to window manager.");
}
Also used : Context(android.content.Context) LayoutParams(android.view.WindowManager.LayoutParams) Configuration(android.content.res.Configuration) ViewGroup(android.view.ViewGroup) ViewParent(android.view.ViewParent) LayoutParams(android.view.WindowManager.LayoutParams) WindowManager(android.view.WindowManager) IWindowManager(android.view.IWindowManager)

Example 20 with WindowManager

use of android.view.WindowManager in project android_frameworks_base by ParanoidAndroid.

the class PhoneWindowManager method enablePointerLocation.

private void enablePointerLocation() {
    if (mPointerLocationView == null) {
        mPointerLocationView = new PointerLocationView(mContext);
        mPointerLocationView.setPrintCoords(false);
        WindowManager.LayoutParams lp = new WindowManager.LayoutParams(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT);
        lp.type = WindowManager.LayoutParams.TYPE_SECURE_SYSTEM_OVERLAY;
        lp.flags = WindowManager.LayoutParams.FLAG_FULLSCREEN | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN;
        if (ActivityManager.isHighEndGfx()) {
            lp.flags |= WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED;
            lp.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_FORCE_HARDWARE_ACCELERATED;
        }
        lp.format = PixelFormat.TRANSLUCENT;
        lp.setTitle("PointerLocation");
        WindowManager wm = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
        lp.inputFeatures |= WindowManager.LayoutParams.INPUT_FEATURE_NO_INPUT_CHANNEL;
        wm.addView(mPointerLocationView, lp);
        mPointerLocationInputChannel = mWindowManagerFuncs.monitorInput("PointerLocationView");
        mPointerLocationInputEventReceiver = new PointerLocationInputEventReceiver(mPointerLocationInputChannel, Looper.myLooper(), mPointerLocationView);
    }
}
Also used : LayoutParams(android.view.WindowManager.LayoutParams) PointerLocationView(com.android.internal.widget.PointerLocationView) LayoutParams(android.view.WindowManager.LayoutParams) IWindowManager(android.view.IWindowManager) WindowManager(android.view.WindowManager)

Aggregations

WindowManager (android.view.WindowManager)394 Display (android.view.Display)177 Point (android.graphics.Point)121 DisplayMetrics (android.util.DisplayMetrics)100 View (android.view.View)42 IWindowManager (android.view.IWindowManager)37 Context (android.content.Context)34 Resources (android.content.res.Resources)25 ImageView (android.widget.ImageView)23 Configuration (android.content.res.Configuration)19 SuppressLint (android.annotation.SuppressLint)17 Camera (android.hardware.Camera)17 Intent (android.content.Intent)16 Rect (android.graphics.Rect)16 RemoteException (android.os.RemoteException)15 LayoutParams (android.view.WindowManager.LayoutParams)15 Dialog (android.app.Dialog)14 TextView (android.widget.TextView)14 Bitmap (android.graphics.Bitmap)10 PointerLocationView (com.android.internal.widget.PointerLocationView)10