Android Open Source - AndroidMemoryLogger System Overlay






From Project

Back to project page AndroidMemoryLogger.

License

The source code is released under:

MIT License

If you think the Android project AndroidMemoryLogger listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.otiasj.memoryLogger.view;
/*from   w ww .j a va  2  s  .  c  om*/
import android.content.Context;
import android.graphics.PixelFormat;
import android.view.View;
import android.view.WindowManager;

/**
 * A system overlay holding a view, this requires additional permission in the manifest :
 * 
 * <pre>
 * {@code
 * <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
 * }
 * </pre>
 */
public class SystemOverlay {
    private WindowManager.LayoutParams mWMParams;
    private final Context mContext;
    private View mView;

    public SystemOverlay(final Context context) {
        mContext = context;
    }

    /**
     * Show the layout
     */
    public void showWindow(final View view) {
        mView = view;
        mWMParams = new WindowManager.LayoutParams(android.view.ViewGroup.LayoutParams.WRAP_CONTENT,
                android.view.ViewGroup.LayoutParams.WRAP_CONTENT, WindowManager.LayoutParams.TYPE_SYSTEM_ALERT,
                WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_FULLSCREEN
                        | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL
                        | WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, PixelFormat.TRANSLUCENT);
        final WindowManager wm = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
        wm.addView(mView, mWMParams);
        moveTo(0, 0);
    }

    /**
     * hide the layout
     */
    public void removeWindow() {
        final WindowManager wm = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
        wm.removeView(mView);
    }

    /**
     * Move the window to given coordinates
     * 
     * @param x
     * @param y
     */
    public void moveTo(final int x, final int y) {
        mWMParams.x = x;
        mWMParams.y = y;
        final WindowManager wm = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
        wm.updateViewLayout(mView.getRootView(), mWMParams);
    }

    /**
     * translate the window by given values
     * 
     * @param tx
     * @param ty
     */
    public void moveBy(final int tx, final int ty) {
        mWMParams.x -= tx;
        mWMParams.y -= ty;
        final WindowManager wm = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
        wm.updateViewLayout(mView.getRootView(), mWMParams);
    }

}




Java Source Code List

com.otiasj.memoryLogger.Memory.java
com.otiasj.memoryLogger.loggers.FileLogger.java
com.otiasj.memoryLogger.loggers.MemoryLogger.java
com.otiasj.memoryLogger.loggers.OnMemoryLog.java
com.otiasj.memoryLogger.loggers.WidgetLogger.java
com.otiasj.memoryLogger.utils.MemoryUtils.java
com.otiasj.memoryLogger.view.MemoryLoggerGraphView.java
com.otiasj.memoryLogger.view.OnClickOverlayListener.java
com.otiasj.memoryLogger.view.OnWidgetRefreshListener.java
com.otiasj.memoryLogger.view.OverlayWidget.java
com.otiasj.memoryLogger.view.SystemOverlay.java
com.otiasj.memoryLogger.view.WidgetView.java