how can i put my PopupWindow to system desk or other app?
how can i use this permission:INTERNAL_SYSTEM_WINDOW
Any examples?Thanks!
views:
64answers:
2
A:
ok,the problem is resolved. i use WindowManager.addView in a service, and WindowManager.LayoutParams.type = TYPE_SYSTEM_ALERT, then it's ok! you can try it!
yuankai
2010-09-20 15:35:16
@yuankai, Could you please share the Source Code? I'd be very gratefull. :)
st0le
2010-09-21 07:33:46
ok, how can i share my code here, can i put some files here?
yuankai
2010-09-21 09:59:34
@yunkai, i didn't notice your comment till now...just edit your answer and put your code there. that'll do. Thanks a lot! :)
st0le
2010-09-27 04:36:42
@yuankai, btw, FYI if you're addressing someone using comments use `@username` that'll notify that user of your comment. Cheers! :)
st0le
2010-09-27 04:37:18
@st0le,thank you very much!
yuankai
2010-10-08 01:14:49
+1
A:
public class PopupService extends Service implements IPopupTouchPosListener
{
public final static String FIELD_EVENT = "event";
/**
* 开启
*/
public final static int EVENT_SWITCH_ON = 1;
/**
* 关闭
*/
public final static int EVENT_SWITCH_OFF = 2;
private CustomPopupView mPopupView;
private int mCurrentY;
private RelativeLayout mLayout;
private WindowManager mWindowManager;
private WindowManager.LayoutParams mWmlp;
@Override
public void onCreate()
{
// TODO Auto-generated method stub
super.onCreate();
mWindowManager = (WindowManager)getSystemService(Context.WINDOW_SERVICE);
// 获取屏幕宽度
DisplayMetrics outMetrics = new DisplayMetrics();
mWindowManager.getDefaultDisplay().getMetrics(outMetrics);
int width = outMetrics.widthPixels;
mWmlp = new WindowManager.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
mWmlp.alpha = 0.5f;
mWmlp.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE; // 不能抢占聚焦点
mWmlp.flags = mWmlp.flags | WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH;
mWmlp.flags = mWmlp.flags | WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS; // 排版不受限制
mWmlp.type = WindowManager.LayoutParams.TYPE_SYSTEM_ALERT; // 系统提示类型
mWmlp.width = width;
mWmlp.height = 30;
mWmlp.gravity = 2;
mWmlp.format = -1;
mWmlp.token = null;
mWmlp.x = 0;
mWmlp.y = 200;
mCurrentY = mWmlp.y;
mLayout = new RelativeLayout(this);
mLayout.setBackgroundColor(0x00FFFFFF);
mLayout.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
mPopupView = new CustomPopupView(this);
mPopupView.setTouchPosListener(this);
RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT, 30);
lp.bottomMargin = 0;
lp.leftMargin = 0;
mLayout.addView(mPopupView, lp);
}
@Override
public void onStart(Intent intent, int startId)
{
super.onStart(intent, startId);
Log.i(Constants.LOG_TAG, "popup service onstart");
String action = intent.getAction();
if(action != null && action.equals(ActionDef.ACTION_POPUP_SERVICE))
{
Bundle bundle = intent.getExtras();
if(bundle != null)
{
int event = bundle.getInt(FIELD_EVENT);
if(event == EVENT_SWITCH_ON)
{
// 显示
mWindowManager.addView(mLayout, mWmlp);
}
else
{
mWindowManager.removeView(mLayout);
}
}
}
}
@Override
public IBinder onBind(Intent intent)
{
// TODO Auto-generated method stub
return null;
}
@Override
public void onMove(float x, float y)
{
if(mLayout != null)
{
Log.i(Constants.LOG_TAG, "y = " + y);
if(y > mLayout.getHeight())
{
mCurrentY = (int)y + mCurrentY - mLayout.getHeight();
}
else if(y < 0)
{
mCurrentY = (int)y + mCurrentY;
}
// 只更新位置
mWmlp.y = mCurrentY;
mWindowManager.updateViewLayout(mLayout, mWmlp);
}
}
}
yuankai
2010-09-28 01:54:08