showPopupWindow();,注册广播接收者,

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_app_manager);
        initView();
        initData();
        // 注册卸载的广播接收者
        IntentFilter filter = new IntentFilter();
        filter.addAction(Intent.ACTION_PACKAGE_REMOVED);//行动,包,删除
        filter.setPriority(IntentFilter.SYSTEM_HIGH_PRIORITY);//优先级高
        filter.addDataScheme("package"); // 这个方法一定要调用, 否则收不到广播
        registerReceiver(mUninstallReceiver, filter );
    }

   @Override
        public void onReceive(Context context, Intent intent) {
            String dataString = intent.getDataString();
            System.out.println("data:"+dataString);
            // package:com.itheima.mobilesafe79
            String packageName = dataString.replace("package:", "");
            // 遍历过程中移除
            ListIterator<AppInfo> listIterator = mUserDatas.listIterator();
            while (listIterator.hasNext()) {
                AppInfo appInfo = listIterator.next();
                if(TextUtils.equals(appInfo.mPackageName, packageName)) {
                    listIterator.remove();
                }
            }
            // 刷新ListView
            mAdapter.notifyDataSetChanged();
        }
    };



    @Override
    protected void onDestroy() {
        super.onDestroy();
        unregisterReceiver(mUninstallReceiver);
    }


private void showPopupWindow(View view) {//传入view是要显示在此view的相对位置
    if (mPopupWindow == null) {
        int width = ViewGroup.LayoutParams.WRAP_CONTENT;
        int height = ViewGroup.LayoutParams.WRAP_CONTENT;
        View contentView = View
                .inflate(getApplicationContext(), R.layout.view_pop_window, null);
        TextView tvUninstall = (TextView) contentView.findViewById(R.id.tv_pop_uninstall);
        TextView tvOpen = (TextView) contentView.findViewById(R.id.tv_pop_open);
        TextView tvShare = (TextView) contentView.findViewById(R.id.tv_pop_share);
        TextView tvInfo = (TextView) contentView.findViewById(R.id.tv_pop_info);
        tvUninstall.setOnClickListener(this);
        tvOpen.setOnClickListener(this);
        tvShare.setOnClickListener(this);
        tvInfo.setOnClickListener(this);
         PopupWindow mPopupWindow = new PopupWindow(contentView, width, height);
        // 表示能获取焦点
        mPopupWindow.setFocusable(true);
        // 设置背景, 必须设置背景才能在点击别的位置时消失, 或者按返回键消失
        mPopupWindow.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
        // 设置动画的样式, 主要是改 Interpolator
        mPopupWindow.setAnimationStyle(R.style.PopWindowAnimation);
    }
    // anchor: 锚点, View, popupWindow显示出来的时候显示在这个View的下面
    mPopupWindow.showAsDropDown(view, 60, -view.getHeight()); // 后面两个参数是x,y轴的偏移量
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值