Blame view

C5/statusBar/src/main/java/com/sunvote/statusbar/view/RootFrameLayout.java 1.53 KB
fac86401   孙向锦   初始化C5 Vote
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
  package com.sunvote.statusbar.view;
  
  import android.content.Context;
  import android.util.AttributeSet;
  import android.widget.FrameLayout;
  
  
  /**
   * 软键盘弹出或隐藏的回调的视图
   * {@link #setOnKeyboardStateListener(OnKeyboardStateListenter)} 可设置监听
   * @author
   */
  public class RootFrameLayout extends FrameLayout {
  
      private OnKeyboardStateListenter mKeyboradListener;
  
      public RootFrameLayout(Context context) {
          super(context);
      }
  
      public RootFrameLayout(Context context, AttributeSet attrs) {
          super(context, attrs);
      }
  
      public RootFrameLayout(Context context, AttributeSet attrs, int defStyle) {
          super(context, attrs, defStyle);
      }
  
      @Override
      protected void onSizeChanged(int w, int h, int oldw, int oldh) {
          super.onSizeChanged(w, h, oldw, oldh);
          boolean visible = false;
          if (0 != oldw && 0 != oldh) {
              if (h < oldh) {
                  visible = true;
              } else {
                  visible = false;
              }
              performKeyboardState(visible);
          }
      }
  
      public void setOnKeyboardStateListener(OnKeyboardStateListenter l){
          mKeyboradListener = l;
      }
  
      protected void performKeyboardState(boolean visible){
          if(mKeyboradListener != null){
              mKeyboradListener.onState(visible);
          }
      }
  
      /**
       * 键盘状态变更监听
       */
      public interface OnKeyboardStateListenter{
  
          /**
           *
           * @param visible
           */
          void onState(boolean visible);
      }
  }