Skip to content Skip to sidebar Skip to footer

How To Get Application Menu Over A Currently Running Screen

I want to get an application menu bar on the left hand side of the screen without disturbing the task that is already running for eg.a live wallpaper or video.How can it be achieve

Solution 1:

Please use this service class. by starting this service from your activity you will get an image in your mobile screen. by adjusting that you can set any where in the mobile. and you can remove it by stopping the service any time.

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Date; 
import android.app.Service;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.content.res.Configuration;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.PixelFormat;
import android.os.Environment;
import android.os.IBinder;
import android.os.RemoteException;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnTouchListener;
import android.view.ViewDebug;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.Toast;

publicclassHUDextendsService {
    HUDView mView;

    @Overridepublic IBinder onBind(Intent intent) {
        returnnull;
    }

    @OverridepublicvoidonCreate() {
        super.onCreate();

        mView = newHUDView(this);
        mView.setId(R.id.button);
        WindowManager.LayoutParamsparamsOrg=newWindowManager.LayoutParams(
                WindowManager.LayoutParams.WRAP_CONTENT,
                WindowManager.LayoutParams.WRAP_CONTENT,
                WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY,

                WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH,
                PixelFormat.TRANSLUCENT);




        WindowManager.LayoutParamsparams=newWindowManager.LayoutParams(100, 100, 2007, 8, -3);
        Button bb=newButton(this);
        bb.setText("Button");
        bb.setOnClickListener(newOnClickListener() {

            @OverridepublicvoidonClick(View v) {
                // TODO Auto-generated method stub
                System.out.println("Clicked----><<<<<<<");
            }
        });

        bb.setOnTouchListener(newOnTouchListener() {

            @OverridepublicbooleanonTouch(View v, MotionEvent event) {
                // TODO Auto-generated method stub
                System.out.println("Touched =----- > ");
                returnfalse;
            }
        });

        params.gravity = Gravity.RIGHT | Gravity.TOP;
        params.setTitle("Load Average");
        WindowManagerwm= (WindowManager) getSystemService(WINDOW_SERVICE);




        wm.addView(bb, params);



    }


    @OverridepublicvoidonDestroy() {
        super.onDestroy();
        //Toast.makeText(getBaseContext(),"onDestroy", Toast.LENGTH_LONG).show();if(mView != null)
        {
            ((WindowManager) getSystemService(WINDOW_SERVICE)).removeView(mView);
            mView = null;
        }
    }

    @OverridepublicvoidonConfigurationChanged(Configuration newConfig) {
        super.onConfigurationChanged(newConfig);

        // Checks the orientation of the screenif (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
            //Toast.makeText(this, "landscape", Toast.LENGTH_SHORT).show();
            restartService();
        } elseif (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT){
            //Toast.makeText(this, "portrait", Toast.LENGTH_SHORT).show();
            restartService();
        }

    }

    privatevoidrestartService() {
        // TODO Auto-generated method stub
        stopService(newIntent(getBaseContext(), HUD.class));
        startService(newIntent(getBaseContext(), HUD.class));
    }
}

classHUDViewextendsViewGroup {
    private Paint mLoadPaint;
    private Float XMAX=280f;
    private Float YMAX=26f;
    privateint XPOS=0;     

    publicHUDView(Context context) {
        super(context);


        mLoadPaint = newPaint();
        mLoadPaint.setAntiAlias(true);
        mLoadPaint.setTextSize(10);
        mLoadPaint.setARGB(255, 255, 0, 0);


        context.bindService(intents, aslServiceConnection, Context.BIND_AUTO_CREATE);


        WindowManagerwind= (WindowManager)context.getSystemService(Service.WINDOW_SERVICE);
        XPOS=wind.getDefaultDisplay().getWidth();

    }

    @OverrideprotectedvoidonDraw(Canvas canvas) {
        super.onDraw(canvas);
        //canvas.drawText("Hello World", 5, 15, mLoadPaint);//canvas.drawText("Hello World", 100, 100, mLoadPaint);BitmaptileImage= BitmapFactory.decodeResource(getResources(), R.drawable.image);

        canvas.drawBitmap(tileImage, XPOS-35, 0, null);
        XMAX=Float.parseFloat(""+(XPOS-35));

    }

    @OverrideprotectedvoidonLayout(boolean arg0, int arg1, int arg2, int arg3, int arg4) {
    }

    @OverridepublicbooleanonTouchEvent(MotionEvent event) {

        Float x=event.getX();
        Float y=event.getY();
        System.out.println("Mview has been touched  --->  "+x +" x "+y);
        if(x > 0 && y > 0)
        {
            if(x > XMAX && y < YMAX){

                TakeMyScreen(getContext());


            }

        }



        returntrue;
    }




    @OverridepublicbooleanonKeyDown(int keyCode, KeyEvent event) {
        // TODO Auto-generated method stubreturnsuper.onKeyDown(keyCode, event);
    }


}

Solution 2:

You can use NewPopupMenu libarary from github.

It will create instant popup menu at any location on screen on any listner.

You just have to download library and extract it, copy the source file into project, and modify code at this line mPopupWindow.showAtLocation(parent, Gravity.CENTER, 0, 0); and place your menu where ever you wants.

Solution 3:

Must use the permission into your project manifest otherwise window has not been attach

android:name="android.permission.SYSTEM_ALERT_WINDOW"

Post a Comment for "How To Get Application Menu Over A Currently Running Screen"