Created
March 7, 2015 04:32
Keyboard "Open/Closed Event dispatcher" LinearLayout
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package corporation.view; | |
import android.content.Context; | |
import android.util.AttributeSet; | |
import android.widget.LinearLayout; | |
/** | |
* Created by juliorodrigues on 07/03/15. | |
*/ | |
public class KeyboardAwareLinearLayout extends LinearLayout { | |
private OnKeyboardChangedListener listener; | |
public KeyboardAwareLinearLayout(Context context) { | |
super(context); | |
} | |
public KeyboardAwareLinearLayout(Context context, AttributeSet attrs) { | |
super(context, attrs); | |
} | |
public KeyboardAwareLinearLayout(Context context, AttributeSet attrs, int defStyleAttr) { | |
super(context, attrs, defStyleAttr); | |
} | |
public void setOnKeyboardChangedListener(OnKeyboardChangedListener listener) { | |
this.listener = listener; | |
} | |
public interface OnKeyboardChangedListener { | |
public void onClosed(); | |
public void onOpened(); | |
} | |
@Override | |
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { | |
if (listener == null) { | |
super.onMeasure(widthMeasureSpec, heightMeasureSpec); | |
return; | |
} | |
final int proposedheight = MeasureSpec.getSize(heightMeasureSpec); | |
final int actualHeight = getHeight(); | |
if (actualHeight > proposedheight){ | |
listener.onOpened(); | |
} else { | |
listener.onClosed(); | |
} | |
super.onMeasure(widthMeasureSpec, heightMeasureSpec); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment