Giter Club home page Giter Club logo

jkeyboardpanelswitch's Introduction

The handler for the keyboard and panel layout conflict in Android

Download Build Status

中文文档


This solution was built When I was working in WeChat, what is used for resolving the layout conflict when you switch between the keyboard and the emoji-panel/function-panel.


There is a post to declaration the core rules of this solution: Switching between the panel and the keyboard in Wechat


Welcome PR


INSTALLATION

JKeyboardPanelSwitch is installed by adding the following dependency to your build.gradle file:

compile 'cn.dreamtobe.kpswitch:library:1.6.1'

If you want to import snapshot version, We have already publish the snapshot version to the sonatype so you can import snapshot version after declare the following repository:

allprojects {
  repositories {
      maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
  }
}

USAGE

Recommend clone the demo project and run it, I has already cover cases as much as possible in the demo project.

PRINCIPLE

License

Copyright 2015 Jacks gong.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

jkeyboardpanelswitch's People

Contributors

jacksgong avatar szitguy avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

jkeyboardpanelswitch's Issues

如果页面配置了 横竖屏切换,则按钮点击无效!

    <activity
        android:name=".activity.ChattingResolvedActivity"
        android:label="@string/activity_chatting_resolved_title"
        android:configChanges="orientation|keyboardHidden|screenSize"
        android:windowSoftInputMode="adjustResize"/>

如上配置,则切换横屏后按钮点击无效!

三星S7手机,有一定几率会被遮盖住

首先感谢作者的代码,不过在使用过程中发现,
Translucent status with fitsSystemWindows=false 的情况下,在三星S7手机上,有一定概率,键盘会被遮挡住一部分,而遮挡的高度恰好就是状态栏的高度,效果图如下:

image

试着给面板增加了状态栏的高度,但是在别的手机上又会有问题,求解 :)

多个面板切换问题

当我实现多面板切换时,通过增加KPSwitchPanelLinearLayout来实现的话,此时点击输入框时新增的KPSwitchPanelLinearLayout会被弹出的键盘顶到键盘上面而不是被键盘遮住,而点击原先那一个的话,却又正常,并且我把第一个相差的代码全部注释只留自己增加的那一个时,仍然会跑到键盘上面去,我想问一下这是什么原因?

问一下使用listview时,并且输入框高度改变时回滚到最底部,怎么实现

如题,如果键盘的高度改变时,输入框的高度也改变,这时需要listview内容回滚到最底部。

阅读源码发现只有键盘showing的监听事件KeyboardUtil.OnKeyboardShowingListener,而且KeyboardUtil.KeyboardStatusListener中只针对Keyboard高度"特别的"改变才进行KPSwitchPanelLinearLayout.refreshHeight

可以添加一个类似于OnKBHeightChangeListener吗?或者还有什么简单的方法?

PanelLayout的onMeasure()当mIsHide时,为什么要将width和height设置为0?

@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    if (mIsHide) {
        setVisibility(View.GONE);
        widthMeasureSpec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.EXACTLY);
        heightMeasureSpec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.EXACTLY);
    }
    super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}

我尝试去掉设置成0的代码就会出现问题,输入法弹出来的时候,输入框被顶上,面板空白,然后我尝试一下改成下面的样子

@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    if (mIsHide) {
        post(new Runnable() {
            @Override
            public void run() {
                setVisibility(View.GONE);
            }
        });
    }
    super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}

也没有问题

设置了windowsTranslucentStatus为true的时候,计算有问题

这几行的判断有些问题,透明状态栏时会进入这个判断

 if (phoneDisplayHeight == actionBarOverlayLayoutHeight) {
          // no space to settle down the status bar, switch to fullscreen,
          // only in the case of paused and opened the fullscreen page.
          Log.w(TAG, String.format("skip the keyboard status calculate, the current" +
                     " activity is paused. and phone-display-height %d," +
                    " root-height+actionbar-height %d", phoneDisplayHeight,
                    actionBarOverlayLayoutHeight));
         return;

}

问题我已经解决了,希望你有时间能merge一下

虚拟键盘手机windowTranslucentNavigation为true时,calculateKeyboardShowing计算出错

isKeyboardShowing = actionBarOverlayLayoutHeight > displayHeight; 这句会一直为true,超出一个NavigationBar高度;
这里我简单处理为:
// 以下是我新增的代码,但hasPermanentMenuKey一直返回false,所以对于没有虚拟键盘的手机也会多减naviHeight的值,虽然也能正确判断键盘被收起,但不完美(原来键盘收起时actionBarOverlayLayoutHeight == displayHeight,看作者能否更优雅的处理呢)
int naviHeight = 0;
Resources resources = getContext().getResources();
int resourceId = resources.getIdentifier("navigation_bar_height", "dimen", "android");
if (resourceId > 0 && !ViewConfiguration.get(getContext()).hasPermanentMenuKey()) {
naviHeight = resources.getDimensionPixelSize(resourceId);
}

final int actionBarOverlayLayoutHeight = actionBarOverlayLayout.getHeight() -
actionBarOverlayLayout.getPaddingTop() - naviHeight;

我的联系方式qq/wechat: 105636147

navigationBar的隐藏和显示,会使该库的逻辑错误。

华为手机下面的NavigationBar隐藏和显示,也通知OnGlobalLayout方法,你的逻辑误认为是键盘弹出导致的。

other issues:
如果使用Fragment的话,那么通过查找系统根节点进行监听
final ViewGroup contentView = (ViewGroup) activity.findViewById(android.R.id.content); contentView.getViewTreeObserver(). addOnGlobalLayoutListener( new KeyboardStatusListener(isFullScreen, isTranslucentStatus, isFitSystemWindows, contentView, target, listener));
当重复进入聊天Fragment的时候,会对聊天界面中的输入框进行多次注册,导致了重复的逻辑。

第一次加载布局,直接点击右侧按钮,不能弹出底部面板

 private void calculateKeyboardShowing(final int nowHeight) {

            boolean isKeyboardShowing;
            if (isFullScreen) {
                // the height of content parent = contentView.height + actionBar.height
                final View actionBarOverlayLayout = (View)contentView.getParent();
                isKeyboardShowing = actionBarOverlayLayout.getHeight() != nowHeight;
            } else {
                isKeyboardShowing = nowHeight <= previousHeight;
                //如果是页面初始化,isKeyboardShowing  状态为true 。则点击右侧按钮无效

            }
            if (lastKeyboardShowing != isKeyboardShowing) {
                Log.d(TAG, String.format("keyboard status change: %B", isKeyboardShowing));
                this.panelHeightTarget.onKeyboardShowing(isKeyboardShowing);
            }
            lastKeyboardShowing = isKeyboardShowing;

        }

怎样设置键盘不遮盖页面?也就是把页面推上去

比如在列表中可以显示最后一行
还有一个问题,在相同的页面下,我使用pulltorefreshlistview 键盘和表情面板弹出还是会闪动但是切换不会闪,替换成listview则一切正常,请问怎样解决?页面需要上下拉刷新功能

想请问一下 最外层的布局必须是线性布局么?

如题, 我在demo中尝试用相对布局实现, 但是这样就无法定位panle出现的位置。那么如果布局非常复杂的情况下,线性布局嵌套层次就会非常多,比如斗鱼tv手机直播的页面。
能不能给个什么建议?

使用KPSwitchPanelRelativeLayout作为根布局异常

你好,

我使用KPSwitchPanelRelativeLayout作为根布局时
应该怎么设置布局
要是加上
 android:layout_above="@+id/panel_root"
android:layout_alignWithParentIfMissing="true"

输入法就不会把他顶起来了。。

我的整个布局是在自定义View上的,不是在MainActivity上。

Adapt the case of DialogFragment

因为不一定是聊天界面才有这样的布局 我想抽出来一个公用的评论空间 DialogFragment 这样的 不知道能不能使用??

继承自FragmentActivity 时,计算键盘是否显示出现偏差

对比两个栈

使用 FragmentActivityActivity时 整个布局的层级关系:

View Hierarchy:
      com.android.internal.policy.PhoneWindow$DecorView{287b762 V.E..... ... 0,0-1080,1920}
        android.widget.LinearLayout{b8a7d7b V.E..... ... 0,0-1080,1776}
          android.view.ViewStub{32bf62d G.E..... ... 0,0-0,0 #10203ab android:id/action_mode_bar_stub}
          android.widget.FrameLayout{4551798 V.E..... ... 0,72-1080,1776 #1020002 android:id/content}
            cn.dreamtobe.kpswitch.widget.KPSwitchRootLinearLayout{5ea5536 V.E..... ... 0,0-1080,1704 #7f0b0052 app:id/rootView}
              android.support.v7.widget.RecyclerView{880ec37 VFED.... F.. 0,0-1080,1539 #7f0b0068 app:id/content_ryv}
              android.widget.LinearLayout{6785a4 VFE..... ... 0,1539-1080,1704 #7f0b0053 app:id/sendMsgLayout}
                android.widget.ImageView{7a40f0d V.ED.... ... 30,34-126,130 #7f0b0054 app:id/voice_text_switch_iv}
                android.widget.RelativeLayout{e7e8ec2 V.E..... ... 150,25-900,139}
                  android.widget.EditText{76e14d3 VFED..CL ... 0,0-750,114 #7f0b0055 app:id/send_edt}
                  android.widget.TextView{2695810 G.ED..C. ... 0,0-0,0 #7f0b0056 app:id/send_voice_btn}
                android.widget.RelativeLayout{c0f8f09 V.E..... ... 900,0-1080,165}
                  android.widget.ImageView{a2ad50e V.ED..C. ... 42,34-138,130 #7f0b0057 app:id/plus_iv}
                  android.widget.TextView{7fb2b2f G.ED..C. ... 0,0-0,0 #7f0b0058 app:id/send_btn}
              cn.dreamtobe.kpswitch.widget.KPSwitchPanelLinearLayout{273e53c G.E..... ... 0,0-0,0 #7f0b0051 app:id/panel_root}
                android.view.View{39912c5 V.ED.... ... 0,0-0,0}
                android.widget.LinearLayout{543341a V.E..... ... 0,0-0,0 #7f0b0059 app:id/panel_content}
                  android.widget.TextView{d994b4b V.ED..C. ... 0,0-0,0 #7f0b005a app:id/send_img_tv}
                  android.widget.TextView{6381928 V.ED.... ... 0,0-0,0}
        android.view.View{a7d1641 V.ED.... ... 0,1776-1080,1920 #1020030 android:id/navigationBarBackground}
        android.view.View{57520f3 V.ED.... ... 0,0-1080,72 #102002f android:id/statusBarBackground}

使用 AppCompatActivity时 整个布局的层级关系:

View Hierarchy:
      com.android.internal.policy.PhoneWindow$DecorView{9b17588 V.E..... ... 0,0-1080,1920}
        android.widget.LinearLayout{18eab21 V.E..... ... 0,0-1080,1776}
          android.view.ViewStub{e691b46 G.E..... ... 0,0-0,0 #10203ab android:id/action_mode_bar_stub}
          android.widget.FrameLayout{7342107 V.E..... ... 0,72-1080,1776}
            android.support.v7.widget.ActionBarOverlayLayout{5ac6234 V.E..... ... 0,0-1080,1704 #7f0b0040 app:id/decor_content_parent}
              android.support.v7.widget.ContentFrameLayout{889d85d V.E..... ... 0,168-1080,1704 #1020002 android:id/content}
                cn.dreamtobe.kpswitch.widget.KPSwitchRootLinearLayout{78ba5d2 V.E..... ... 0,0-1080,1536 #7f0b0052 app:id/rootView}
                  android.support.v7.widget.RecyclerView{567c6a3 VFED.... F.. 0,0-1080,1371 #7f0b0068 app:id/content_ryv}
                  android.widget.LinearLayout{c76da0 VFE..... ... 0,1371-1080,1536 #7f0b0053 app:id/sendMsgLayout}
                    android.support.v7.widget.AppCompatImageView{2109d59 V.ED.... ... 30,34-126,130 #7f0b0054 app:id/voice_text_switch_iv}
                    android.widget.RelativeLayout{cda4d1e V.E..... ... 150,25-900,139}
                      android.support.v7.widget.AppCompatEditText{fa629ff VFED..CL ... 0,0-750,114 #7f0b0055 app:id/send_edt}
                      android.support.v7.widget.AppCompatTextView{4c5c3cc G.ED..C. ... 0,0-0,0 #7f0b0056 app:id/send_voice_btn}
                    android.widget.RelativeLayout{5a4b615 V.E..... ... 900,0-1080,165}
                      android.support.v7.widget.AppCompatImageView{fda1d2a V.ED..C. ... 42,34-138,130 #7f0b0057 app:id/plus_iv}
                      android.support.v7.widget.AppCompatTextView{d3d671b G.ED..C. ... 0,0-0,0 #7f0b0058 app:id/send_btn}
                  cn.dreamtobe.kpswitch.widget.KPSwitchPanelLinearLayout{27150b8 G.E..... ... 0,0-0,0 #7f0b0051 app:id/panel_root}
                    android.view.View{7279e91 V.ED.... ... 0,0-0,0}
                    android.widget.LinearLayout{354e1f6 V.E..... ... 0,0-0,0 #7f0b0059 app:id/panel_content}
                      android.support.v7.widget.AppCompatTextView{24159f7 V.ED..C. ... 0,0-0,0 #7f0b005a app:id/send_img_tv}
                      android.support.v7.widget.AppCompatTextView{b46c064 V.ED.... ... 0,0-0,0}
              android.support.v7.widget.ActionBarContainer{d1692cd V.ED.... ... 0,0-1080,168 #7f0b0041 app:id/action_bar_container}
                android.support.v7.widget.Toolbar{ae52782 V.E..... ... 0,0-1080,168 #7f0b0042 app:id/action_bar}
                  android.widget.TextView{6279e93 V.ED.... ... 48,43-468,124}
                  android.support.v7.widget.ActionMenuView{9e17ed0 V.E..... ... 1080,0-1080,168}
                android.support.v7.widget.ActionBarContextView{e868ec9 G.E..... ... 0,0-0,0 #7f0b0043 app:id/action_context_bar}
        android.view.View{74239ce V.ED.... ... 0,1776-1080,1920 #1020030 android:id/navigationBarBackground}
        android.view.View{82390ef V.ED.... ... 0,0-1080,72 #102002f android:id/statusBarBackground}

其实整个项目是根据 AppCompatActivity适配起来的。

而很显然在 ActivityFragmentActivity 的布局中 contentViewparentandroid.widget.LinearLayout{b8a7d7b V.E..... ... 0,0-1080,1776} 而这个布局的父布局直接就是 DecorView,并且通过分析,获知 这边这个 contentViewparent的高度会等于 DecorViewHeight - NavigationBarHeight,因此就我们的适配中的键盘高度计算,是依赖这个布局的高度变化的只考虑了 AppCompatActivity 的情况,没有覆盖这个情况,这边需要对这个情况进行覆盖,以防止键盘是否显示计算出错。

Demo 给voice按钮点击事件问题

在demo中
给 voice_text_switch_iv 设置点击事件
当软键盘是弹起状态时 几乎点很多次才会触发一次 而当软键盘隐时 响应是没问题的

状态栏显示问题

使用theme:

    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
    </style>
    <style name="AppTheme.NoActionBar">
        <item name="windowActionBar">false</item>
        <item name="windowNoTitle">true</item>
    </style>

并使用Toolbar:
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar);
结果状态栏灰白,如下图:
screenshot_20161028-153911

我仔细拜读了您的代码,但自己内力尚浅,不能完全理解,最终未能找到解决此问题的方法,您有时间看一下哈~

点击plusButton,不起作用

当我点plus 按钮时setVisibility 会调用2次第一次visibility == 0 第二次 visibility == 8,导致下面召唤不出来。
请问,是布局的问题,还是什么其他问题。

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.