博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
悬浮窗
阅读量:6149 次
发布时间:2019-06-21

本文共 4639 字,大约阅读时间需要 15 分钟。

activity:复制代码

initAudioView(LayoutInflater.from(context), R.layout.teana_audio_hc);public void initAudioView(LayoutInflater inflater, int layout) {    if (mAudioFloadView == null) {        mAudioFloadView = new FloatView(mContext);        mAudioFloadView.inflateLayout(layout);        mAudioFloadView.setLayoutParams(getSoundUiLayoutParams());    } else {        android.util.Log.e(TAG, "initAudioView called more than once!!!!");    }}protected WindowManager.LayoutParams getSoundUiLayoutParams() {    Context context = mCanbusManager.getContext();    WindowManager.LayoutParams lp = new WindowManager.LayoutParams();    lp.width = WindowManager.LayoutParams.MATCH_PARENT;    lp.height = WindowManager.LayoutParams.MATCH_PARENT;    lp.type = WindowManager.LayoutParams.TYPE_SYSTEM_ALERT;    lp.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN;    lp.format = PixelFormat.RGBA_8888;    lp.gravity = Gravity.CENTER;    lp.packageName = context.getPackageName();    lp.windowAnimations = R.style.AirAnimation;    lp.setTitle("CarSound");    return lp;}复制代码

package android.car.ui;import android.content.Context;import android.view.LayoutInflater;import android.view.View;import android.view.ViewGroup;import android.view.WindowManager;import android.view.WindowManager.LayoutParams;public class FloatView {    protected Context mContext;    protected WindowManager mWindowManager;    protected LayoutParams mLayoutParams = new LayoutParams();    private View mRootView;    private boolean mIsAttach;    protected FloatView.OnAttachListener mOnAttachListener;    public FloatView(Context context) {        this.mContext = context;        this.mWindowManager = (WindowManager)this.mContext.getSystemService("window");    }    public LayoutParams getLayoutParams() {        return this.mLayoutParams;    }    public void setLayoutParams(LayoutParams lp) {        this.mLayoutParams.copyFrom(lp);    }    public View inflateLayout(int layout) {        if(this.mRootView != null) {            throw new IllegalStateException("mRootView has been created!");        } else {            LayoutInflater li = LayoutInflater.from(this.mContext);            this.mRootView = li.inflate(layout, (ViewGroup)null);            this.onInflateFinish();            return this.mRootView;        }    }    protected void onInflateFinish() {    }    public View setView(View view) {        if(this.mRootView != null) {            throw new IllegalStateException("mRootView has been created!");        } else {            this.mRootView = view;            this.onInflateFinish();            return this.mRootView;        }    }    public View getView() {        return this.mRootView;    }    private void setIsAttach(boolean isAttach) {        if(this.mIsAttach != isAttach) {            this.mIsAttach = isAttach;            if(this.mOnAttachListener != null) {                this.mOnAttachListener.onAttach(this, this.mIsAttach);            }        }    }    public boolean isAttach() {        return this.mIsAttach;    }    public void attach() {        if(this.mWindowManager != null && this.mRootView != null && this.mLayoutParams != null && !this.mIsAttach) {            this.mWindowManager.addView(this.mRootView, this.mLayoutParams);            this.setIsAttach(true);        }    }    public void detach() {        this.detach(false);    }    public void detach(boolean immediate) {        if(this.mWindowManager != null && this.mRootView != null && this.mIsAttach) {            if(immediate) {                this.mWindowManager.removeViewImmediate(this.mRootView);            } else {                this.mWindowManager.removeView(this.mRootView);            }            this.setIsAttach(false);        }    }    public void setShow(boolean show) {        if(show) {            this.attach();        } else {            this.detach();        }    }    public void updateLayout() {        if(this.mWindowManager != null && this.mRootView != null && this.mIsAttach) {            this.mWindowManager.updateViewLayout(this.mRootView, this.mLayoutParams);        }    }    public View findViewById(int id) {        return this.mRootView != null?this.mRootView.findViewById(id):null;    }    public void setBackgroundColor(int color) {        if(this.mRootView != null) {            this.mRootView.setBackgroundColor(color);        }    }    public void setOnAttachListener(FloatView.OnAttachListener l) {        this.mOnAttachListener = l;    }    public interface OnAttachListener {        void onAttach(FloatView var1, boolean var2);    }}复制代码

转载于:https://juejin.im/post/5bfcfd64f265da611c26aabb

你可能感兴趣的文章
angularjs表达式中的HTML内容,如何不转义,直接表现为html元素
查看>>
css技巧
查看>>
Tyvj 1728 普通平衡树
查看>>
[Usaco2015 dec]Max Flow
查看>>
javascript性能优化
查看>>
多路归并排序之败者树
查看>>
java连接MySql数据库
查看>>
转:Vue keep-alive实践总结
查看>>
深入python的set和dict
查看>>
C++ 11 lambda
查看>>
Hadoop2.5.0 搭建实录
查看>>
实验吧 recursive write up
查看>>
Android JSON数据解析
查看>>
DEV实现日期时间效果
查看>>
java注解【转】
查看>>
Oracle表分区
查看>>
centos 下安装g++
查看>>
嵌入式,代码调试----GDB扫盲
查看>>
类斐波那契数列的奇妙性质
查看>>
配置设置[Django]引入模版之后报错Requested setting TEMPLATE_DEBUG, but settings are not configured....
查看>>