需要替代com.android.internal.policy.PolicyManager.makeNewWindow(上下文上下文)

时间:2015-12-16 18:37:46

标签: android window android-mediaplayer internal

为视频视图设置浮动窗口的代码运行良好。直到Android 6.0 - 它现在抛出NoClassDefFoundError。此外,在将项目迁移到Android Studio时,gradle拒绝编译项目,因为该行。读了一下,我意识到尝试复制/粘贴android内部源代码是不明智的。如何为我的Playback Controller获取一个新窗口?

 private void initFloatingWindow() {
            mWindowManager = (WindowManager) mActivity.getSystemService(Context.WINDOW_SERVICE);
            **// original**
            mWindow = com.android.internal.policy.PolicyManager.makeNewWindow(mActivity.getApplicationContext());
            // attempt instead of PolicyManager, but it really needs a new window
            // mWindow = mActivity.getWindow();
            mWindow.setWindowManager(mWindowManager, null, null);
            mWindow.requestFeature(Window.FEATURE_NO_TITLE);

            mDecor = mWindow.getDecorView();
            mDecor.setOnTouchListener(mTouchListener);
            mWindow.setContentView(mViewGroup);
            mWindow.setBackgroundDrawableResource(android.R.color.transparent);

            // While the media controller is up, the volume control keys should
            // affect the media stream type
            mWindow.setVolumeControlStream(AudioManager.STREAM_MUSIC);

            mViewGroup.setFocusable(true);
            mViewGroup.setFocusableInTouchMode(true);
            mViewGroup.setDescendantFocusability(ViewGroup.FOCUS_AFTER_DESCENDANTS);
            mViewGroup.requestFocus();
            mViewGroup.setOnKeyListener(new View.OnKeyListener() {

                @Override
                public boolean onKey(View v, int keyCode, KeyEvent event) {
                    LLog.d(LOG_TAG, "onKey keyCode=" + keyCode);
                    if (keyCode == KeyEvent.KEYCODE_BACK
                            || keyCode == KeyEvent.KEYCODE_MENU) {
                        hideControlLayout();
                        InputMethodManager mInputManager = (InputMethodManager) mActivity
                                .getSystemService(Context.INPUT_METHOD_SERVICE);
                        mInputManager.hideSoftInputFromWindow(
                                mDecor.getWindowToken(), 0);
                        return true;
                    }
                    return false;
                }
            });
        }

0 个答案:

没有答案