I have a cutstom DialogFragment to show a loading message to the user. For the loading message image, I created an animation that goes from the left part of the screen (starting from outside the screen) to the right of the screen (finishing outside the screen). To do so, I thought of starting the animation on y=-imageWith and finish in y=imageWith+dialogWith:
public class MensajeDialogFragment extends DialogFragment {
TextView mTvMensaje;
TextView mTvTitulo;
#Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
LayoutInflater inflater = getActivity().getLayoutInflater();
ImageView loadingImage = (ImageView) dialogView.findViewById(R.id.ivBus);
View dialogView = inflater.inflate(R.layout.layout_mensaje_dialog, null);
TextView mTvTitulo = (TextView) dialogView.findViewById(R.id.tvTitulo);
TextView mTvMensaje = (TextView) dialogView.findViewById(R.id.tvMensaje);
mTvTitulo.setText(getArguments().getString(getString(R.string.bundle_titulo), ""));
mTvMensaje.setText(getArguments().getString(getString(R.string.bundle_mensaje), ""));
builder.setView(dialogView);
TranslateAnimation izqADerAnimacion = new TranslateAnimation(-loadingImage.getWidth(), dialogView.getWidth()+loadingImage.getWidth(), 0, 0);
izqADerAnimacion.setDuration(3500);
izqADerAnimacion.setRepeatCount(Animation.INFINITE);
loadingImage.startAnimation(izqADerAnimacion);
return builder.create();
}
}
But for some reason, the loadingImage.getWidth() and dialogView.getWidth() are returning 0. What can I do to solve this without hardcoding the starting and finishing positions?
loadingImage.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
#Override
public void onGlobalLayout() {
if (Build.VERSION.SDK_INT > 16)
loadingImage.getViewTreeObserver().removeOnGlobalLayoutListener(this);
else
loadingImage.getViewTreeObserver().removeGlobalOnLayoutListener(this);
//do animation
}
});
hope this works
TranslateAnimation izqADerAnimacion =
new TranslateAnimation(-loadingImage.getWidth(),
dialogView.getWidth()+loadingImage.getWidth(), 0, 0);
In your code above mentioned you can directly give some value like
TranslateAnimation animation = new TranslateAnimation(-970.0f, 2000.0f, 0.0f, 0.0f);
It works nicely in Nexus 9 tab.
Related
I created TapTargetView (or TapTargetSequence) in all of my activities and it displaying well, but for inner views of popup menu, it hides behind my popup menu window! exactly between under activity and popup menu. how can I bring it to top, please? Is parameter of TapTargetSequence ((Activity) context) correct? "context" or "this" occurs error !
public class Popup_Menu implements OnClickListener {
PopupWindow popup; View layout; Context context;
WindowManager wm;
void showPopup(final Activity context) {
this.context=context;
// Inflate the popup_layout.xml
LinearLayout viewGroup = (LinearLayout) ((Activity) context).findViewById(R.id.popup);
LayoutInflater layoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
layout = layoutInflater.inflate(R.layout.popup_layout_menu, viewGroup);
// Creating the PopupWindow
popup = new PopupWindow(context);
popup.setContentView(layout);
// Clear the default translucent background
popup.setBackgroundDrawable(new BitmapDrawable());
popup.showAtLocation(layout, Gravity.BOTTOM, 30 ,0 );
tapTarget_menu();
} /////////////////// close of showPopup() !
// TapTaget_menu
public void tapTarget_menu() {
new TapTargetSequence((Activity) context)
.targets(
TapTarget.forView(layout.findViewById(R.id.chkb_menu_remem), "remember", "last lesson")
// first target
.targetCircleColor(R.color.sabz_seyedi)
.outerCircleColor(R.color.sabzabi_kmrng)
.dimColor(R.color.sabz_seyedi)
.titleTextSize(22)
.descriptionTextSize(16)
.textColor(R.color.white)
.drawShadow(true)
.transparentTarget(true)
.cancelable(false)
.targetRadius(60),
// second target
TapTarget.forView(layout.findViewById(R.id.ll_call_menu), "call", "connecting friends!")
.targetCircleColor(R.color.sabz_seyedi)
.outerCircleColor(R.color.sabzabi_tireh)
.dimColor(R.color.sabz_seyedi)
.titleTextSize(22)
.descriptionTextSize(16)
.textColor(R.color.white)
.drawShadow(true)
.transparentTarget(true)
.cancelable(false)
.targetRadius(60)
).start();
}
}
I found my solution ! I have changed this code after popup.showAtLocation(), like following and it can display tapTargetView on top of PopupWindow.
VIVA ME !!!
WindowManager.LayoutParams layoutParams = new WindowManager.LayoutParams(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT);
layoutParams.packageName = context.getPackageName();
layoutParams.format = PixelFormat.TRANSLUCENT;
layoutParams.flags = WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM;
then, out of showPopup() method:
public void tapTarget_menu1(){
TapTarget target = TapTarget.forView(layout.findViewById(R.id.ll_call_menu), "remember", "last lesson");
.targetCircleColor(R.color.sabz_seyedi)
.outerCircleColor(R.color.sabzabi_tireh)
.titleTextSize(24)
.descriptionTextSize(18)
.textColor(R.color.black)
.drawShadow(true)
.cancelable(false)
.transparentTarget(true)
.targetRadius(60);
content = (ViewGroup) layout.findViewById(android.R.id.content);
final TapTargetView tapTarget_menu1 = new TapTargetView(context, wm, content, target, new TapTargetView.Listener(){
#Override
public void onTargetClick(TapTargetView view) {
tapTarget_menu2();
super.onTargetClick(view);
}
});
((WindowManager)context.getSystemService(Context.WINDOW_SERVICE)).addView(tapTarget_menu1, layoutParams);
}
I hard to implement popup like softkeyboard. I mean, when you open popup in android the views under popup is disable (you can't do anything until the popup dismiss). But when then softkeyboard open, the views always above the softkeyboard.
Note : dont need trick like view.setVisibility(View.GONE) or view.setVisibility(View.VISIBLE)
EDIT
As simply, how to make layout/view up when popup display from bottom to up look like softkeyboard?
Yes, you can create Custom Dialog with two translate animation from bottom.
Check droid kid answer he is already done in your way.
Answer
For this you have to create a custom view that pop up,you have to create a different xml file for your view and define the height width of that,make height wrap content.And your views are not affected by this like other Dialog popup which disable anything in the background.
Example :- lets say you have xml for pop up named dialog_pop_up,
public void showPopUpDialog(Context context,ImageView imagebuttonPopUP) {
try {
View v = ((LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(R.layout.dialog_pop_up, null, false);
int[] location = new int[2];
//This is the button which triggers pop up
imagebuttonPopUP.getLocationOnScreen(location);
//Initialize the Point with x, and y positions
Point p = new Point();
p.x = location[0];
p.y = location[1];
int popupWidth = mActivity.getResources().getDimensionPixelOffset(R.dimen.home_screen_dialog_width);//Utility.dpToPx(mActivity,133);
int OFFSET_Y = imagebuttonPopUP.getHeight();
int OFFSET_X = imagebuttonPopUP.getWidth();
final PopupWindow window = new PopupWindow(v, WindowManager.LayoutParams.WRAP_CONTENT, WindowManager.LayoutParams.WRAP_CONTENT, true);
window.setWidth(popupWidth);
window.setOutsideTouchable(true);
window.setTouchable(true);
window.setFocusable(true);
window.setBackgroundDrawable(new BitmapDrawable());
//Initialize your view here.
TextView TextView1 = (TextView) v.findViewById(R.id.textview1);
TextView TextView2 = (TextView) v.findViewById(R.id.textview2);
LinearLayout Layout = (LinearLayout) v.findViewById(R.id.linearlayout2);
View dividerView = v.findViewById(R.id.view_divider);
//Click listeners of your views
TextView.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
//your code here
//to dismiss window
window.dismiss();
}
});
TextView2.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
//code
}
});
window.showAtLocation(imagebuttonPopUP, Gravity.NO_GRAVITY, p.x + OFFSET_X - popupWidth, p.y + OFFSET_Y);
} catch (Exception ex) {
Logger.e(TAG, ex.getMessage());
}
}
I wanted to know if my textview is within the visible screen region or not..
I have looked at links as:
Android - Get the visible area of a view?
Android: how to check if a View inside of ScrollView is visible?
But nothing seems to work for me.
Code that i used to check is
Rect rect = new Rect();
//textview intialized in onCreate as text1
text1.getHitRect(rect);
text1.measure(0, 0);
//layout is the parent layout (linear) in which i am adding the text view
Rect acctualView = new Rect(Math.round(layout.getX()), Math.round(layout.getY()),
Math.round(layout.getX() + layout.getWidth()), Math.round(layout.getY() +layout.getHeight()));
if(Rect.intersects(acctualView, rect))
{
Toast.makeText(context, "visible", Toast.LENGTH_LONG).show();
}else {
Toast.makeText(context, "Not visible ", Toast.LENGTH_LONG).show();
}
Every width and height of textview and layout is giving me 0 "zero",
Please let me know how to fix this and know whether a view is inside the visible region or not
Here is my complete activity code
public class MainActivity extends Activity {
private TextView text1, text2, text3, text4, text5, text6;
private Context context;
private LinearLayout layout;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
context = getLayoutInflater().getContext();
layout = (LinearLayout) findViewById(R.id.parentLayout);
setTextViews();
checkViewAndUpdate();
}
private void checkViewAndUpdate() {
Rect rect = new Rect();
layout.getHitRect(rect);
if (text1.getLocalVisibleRect(rect)) {
Toast.makeText(context, "visible", Toast.LENGTH_LONG).show();
} else {
Toast.makeText(context, "Not visible", Toast.LENGTH_LONG).show();
}
}
private void setTextViews() {
text1 = new TextView(context);
text2 = new TextView(context);
text3 = new TextView(context);
text4 = new TextView(context);
text5 = new TextView(context);
text6 = new TextView(context);
text1.setText("text1");
text2.setText("text2");
text3.setText("text3");
text4.setText("text4");
text5.setText("text5");
text6.setText("text6");
text1.setTextSize(30);
text2.setTextSize(30);
text3.setTextSize(30);
text4.setTextSize(30);
text5.setTextSize(30);
text6.setTextSize(30);
//layout.removeAllViews();
layout.addView(text1);
layout.addView(text2);
layout.addView(text3);
layout.addView(text4);
layout.addView(text5);
layout.addView(text6);
}
}
and my layout only contains LinearLayout (empty)
as i wrote on comment, checking visible rect at onCreate won't work.
Try this code at end of onCreate (instead of call checkAndUpdate() directly).
layout.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
#Override
public void onGlobalLayout() {
checkViewAndUpdate();
}
});
View layout does not finish though if you added view at onCreate. yes, this time user cannot see the actual activity and view's actual size are not set.
onGlobalLayout will call when view layout is ended (and activity is visible).
at that timing, we can now get size and position of them!
FYI, you can remove this listener by calling layout.getViewTreeObserver().removeOnGlobalLayoutListener(this) in onGlobalLayout()
try with this:
if (yourView.getParent().getVisibility() == View.VISIBLE) {
// visible
} else{
// hiden
}
Or this:
Rect rect = new Rect();
parentView.getHitRect(rect);
if (imageView.getLocalVisibleRect(rect)) {
// imageView is within the visible window
} else {
// imageView is not within the visible window
}
Why don't you use the for method?
for(int i = 0; i < 6; i++){
TextView tv = new TextView(context);
tv.setTextSize(30);
layout.addView(tv);
//Maybe set some listeners...
}
I am trying to have the same navigation style as Viber's interface (the discussion page), without using a third-part Library such as SlidingMenu.
I thought that they have used SlidingPaneLayout to achieve this nice effect, but when I tried to code it, I noticed that the last pane is always over the second.
My questions :
Is this really a SlidingPaneLayout ?
If yes how to achieve this please ?
If no, is there an android native way to do the same thing ?!
Left Pane
Right Pane
First of all declare this all variable in your Class
/** Sliding Menu */
boolean alreadyShowing = false;
private int windowWidth;
private Animation animationClasses;
private RelativeLayout classesSlider;
LayoutInflater layoutInflaterClasses;
then inside onCreate method declare this, this will help you to get screen's height and width
Display display = getWindowManager().getDefaultDisplay();
windowWidth = display.getWidth();
display.getHeight();
layoutInflaterClasses = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
and then any of your button or image where by clicking you want to open slider put below code.
findViewById(R.id.slidermenu).setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
if (!alreadyShowing) {
alreadyShowing = true;
openSlidingMenu();
}
}
});
and then outside the onCreate declare openSlidingMenu() as below.
private void openSlidingMenu() {
// showFadePopup();
int width = (int) (windowWidth * 0.8f);
translateView((float) (width));
#SuppressWarnings("deprecation")
int height = LayoutParams.FILL_PARENT;
// creating a popup
final View layout = layoutInflaterClasses.inflate(
R.layout.option_popup_layout,
(ViewGroup) findViewById(R.id.popup_element));
ImageView imageViewassignment = (ImageView) layout
.findViewById(R.id.assignment);
imageViewassignment.setOnClickListener(this);
final PopupWindow optionsPopup = new PopupWindow(layout, width, height,
true);
optionsPopup.setBackgroundDrawable(new PaintDrawable());
optionsPopup.showAtLocation(layout, Gravity.NO_GRAVITY, 0, 0);
optionsPopup.setOnDismissListener(new PopupWindow.OnDismissListener() {
public void onDismiss() {
// to clear the previous animation transition in
cleanUp();
// move the view out
translateView(0);
// to clear the latest animation transition out
cleanUp();
// resetting the variable
alreadyShowing = false;
}
});
}
just replace
final View layout = layoutInflaterClasses.inflate(
R.layout.option_popup_layout,
(ViewGroup) findViewById(R.id.popup_element));
this above code with your custom screen XML name and by it's ID. and here is other methos's which you need.
private void translateView(float right) {
animationClasses = new TranslateAnimation(0f, right, 0f, 0f);
animationClasses.setDuration(100);
animationClasses.setFillEnabled(true);
animationClasses.setFillAfter(true);
classesSlider = (RelativeLayout) findViewById(R.id.classes_slider);
classesSlider.startAnimation(animationClasses);
classesSlider.setVisibility(View.VISIBLE);
}
private void cleanUp() {
if (null != classesSlider) {
classesSlider.clearAnimation();
classesSlider = null;
}
if (null != animationClasses) {
animationClasses.cancel();
animationClasses = null;
}
}
remember here animationClasses = new TranslateAnimation(0f, right, 0f, 0f); you can play with this parameter for some different effect and also do not forget to change this line's ID with your current screen's ID like for example check below id
classesSlider = (RelativeLayout) findViewById(R.id.classes_slider);
here you need to replace this ID with your Current java screen's XML file's ID.
Hope this will help you.
I want to know how it's possible to add View on top of Keyboard like WhatsApp and Hangout. In chat screen, they insert emoticons view on top of the opened soft keyboard.
Does anyone know how to achieve this behavior?
Well, I have created a sample keyboard for chatting here...
Here, I use popup window for showing popup window and height of popup is calculated dynamically by height of keyboard
// Initially defining default height of keyboard which is equal to 230 dip
final float popUpheight = getResources().getDimension(
R.dimen.keyboard_height);
changeKeyboardHeight((int) popUpheight);
// Creating a pop window for emoticons keyboard
popupWindow = new PopupWindow(popUpView, LayoutParams.MATCH_PARENT,
(int) keyboardHeight, false);
and height is calculated using this function :
/**
* Checking keyboard height and keyboard visibility
*/
int previousHeightDiffrence = 0;
private void checkKeyboardHeight(final View parentLayout) {
parentLayout.getViewTreeObserver().addOnGlobalLayoutListener(
new ViewTreeObserver.OnGlobalLayoutListener() {
#Override
public void onGlobalLayout() {
Rect r = new Rect();
parentLayout.getWindowVisibleDisplayFrame(r);
int screenHeight = parentLayout.getRootView()
.getHeight();
int heightDifference = screenHeight - (r.bottom);
if (previousHeightDiffrence - heightDifference > 50) {
popupWindow.dismiss();
}
previousHeightDiffrence = heightDifference;
if (heightDifference > 100) {
isKeyBoardVisible = true;
changeKeyboardHeight(heightDifference);
} else {
isKeyBoardVisible = false;
}
}
});
}
Using all these stuff i am able to make a perfect overlapping keyboard....
then i inflate popup window with viewpager and gridview for emoticons.
Also, i use spannable string for showing these emoticons in listview and chat window
After a heavy time of research and try-and-error, I've found another solution similar to the one of Chirag Jain above, but using a custom Dialog.
mDialogKeyboard = new Dialog(this,android.R.style.Theme_NoTitleBar);
mDialogKeyboard.setContentView(R.layout.your_custom_layout);
mDialogKeyboard.getWindow().setFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL,WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL);
mDialogKeyboard.getWindow().setFlags(WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH,WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH);
mDialogKeyboard.getWindow().setFlags(WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM,WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
mDialogKeyboard.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
WindowManager.LayoutParams lp=mDialogKeyboard.getWindow().getAttributes();
lp.width=WindowManager.LayoutParams.MATCH_PARENT;
lp.height=mSoftKeyboardHeight;
lp.gravity=Gravity.BOTTOM | Gravity.LEFT;
lp.dimAmount=0;
Despite the fact that Chirag Jain answer seems to be more clean, I'll post this here for have an alternative method.
As far as I know you can draw on other applications, yes. I myself have designed such an app. As for drawing on an application such as the keyboard or any other application in specific, I guess, you'll have to define a layout with a height that's exactly that of the keyboard. So, that would vary from device to device. So, this isn't possible.
I still stick to my notion that WhatsApp merely dismisses the soft keyboard on pressing the smiley button and calls it's own fragment.
If you would still like to pursue this, here's how you draw a "window" over other applications. These should be it's layout parameters.
params = new WindowManager.LayoutParams(
WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY,
WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN,
PixelFormat.TRANSLUCENT);
Albeit, your width will change to an absolute pixel value since you'd like the activity to be over the keyboard only.
If I've misunderstood the question, please correct me.
what my thinking is they have created their own keypad for smiles, and on click of smile icon or keypad icon they are hiding smile keypad and showing the normal keypad. there are two scenarios in whats app case 1) if you don't focus 1st time of editext then you can not see the show keypad button,and the height of smile keypad is exactly same as normal keypad,we will get the keypad height only after our view layout is changed, means only after the keypad is shown, that means they are creating their own keypad.. 2) if you focus the edittext and click of smile button then it will show the option of show keypad button Please correct me if i am not right on this
I recently had to implement a view which would be above a soft keyboard. #Chirag Jain's solution is almost right, but it does not count with the system buttons in the bottom of the screen! This will make the keyboard height incorrect on some devices like NEXUS 6. This solution should work across all devices:
1) create layout which contains your view
<RelativeLayout
android:id="#+id/keyboard_info_container"
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_alignParentBottom="true"
android:background="#color/C12"
android:padding="10dp"
android:visibility="invisible">
....
</RelativeLayout>
2) Bind view
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootview = inflater.inflate(R.layout.notifications_email_settings_fragment, container, false);
ButterKnife.bind(this, rootview);
checkKeyboardHeight(rootview);
3) keyboard check and view margin settings
private void checkKeyboardHeight(final View parentLayout) {
parentLayout.getViewTreeObserver().addOnGlobalLayoutListener(
new ViewTreeObserver.OnGlobalLayoutListener() {
int previousHeightDiffrence = 0;
int systemBarHigh = 999999;
#Override
public void onGlobalLayout() {
Rect r = new Rect();
parentLayout.getWindowVisibleDisplayFrame(r);
int screenHeight = parentLayout.getRootView()
.getHeight();
int keyboardHeight = screenHeight - (r.bottom);
if(systemBarHigh > keyboardHeight) {
systemBarHigh = keyboardHeight;
}
if (keyboardHeight > 250) {
int keyboardHightWithoutSystemBar = keyboardHeight - systemBarHigh;
// no need to update when the keyboard goes down
if (previousHeightDiffrence != keyboardHightWithoutSystemBar) { // if (Math.abs(previousHeightDiffrence - keyboardHeight) > 10) {
adjustKeyboard(keyboardHightWithoutSystemBar);
}
keyboardInfoContainer.setVisibility(View.VISIBLE);
isKeyBoardVisible = true;
previousHeightDiffrence = keyboardHightWithoutSystemBar;
} else {
isKeyBoardVisible = false;
if (keyboardInfoContainer != null) {
keyboardInfoContainer.setVisibility(View.INVISIBLE);
}
}
}
});
}
private void adjustKeyboard(int keyboardHeight) {
RelativeLayout.LayoutParams lp = (RelativeLayout.LayoutParams) keyboardInfoContainer.getLayoutParams();
lp.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
lp.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
lp.bottomMargin = keyboardHeight;
keyboardInfoContainer.requestLayout();
}
#jirkarrr, Why don't you add the keyboardInfoContainer like this:
WindowManager wm = getWindowManager();
WindowManager.LayoutParams lps = new WindowManager.LayoutParams();
lps.x = 0; lps.y = keyboardHeight;
wm.addView(keyboardInfoContainer, lps);
I do as your code, but it cannot show out the keyboardInfoContainer.
I use a popup to put view over the keyboard:
public void showPopUpKeyboard() {
mIsPopupVisible = true;
// Initialize a new instance of LayoutInflater service
LayoutInflater inflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
// Inflate the custom layout/view
View customView = inflater.inflate(R.layout.popup_in_keyboard, null);
mScrollView = (ScrollView) customView.findViewById(R.id.keyboard_layout_view);
// Initialize a new instance of popup window
mPopupWindow = new PopupWindow(
customView,
RelativeLayout.LayoutParams.MATCH_PARENT,
RelativeLayout.LayoutParams.MATCH_PARENT
);
setSizeForSoftKeyboard();
// Get a reference for the custom view close button
Button closeButton = (Button) customView.findViewById(R.id.ib_close);
// Set a click listener for the popup window close button
closeButton.setOnClickListener((View view) -> {
// Dismiss the popup window
mIsPopupVisible = false;
mPopupWindow.dismiss();
});
mPopupWindow.showAtLocation(mParentLayout, Gravity.CENTER, 0, 0);
}
Then I try to know keyboard's height:
mParentLayout.getViewTreeObserver().addOnGlobalLayoutListener(() -> {
Rect r = new Rect();
mParentLayout.getWindowVisibleDisplayFrame(r);
int heightDiff = mParentLayout.getRootView().getHeight() - (r.bottom - r.top);
if (heightDiff > 100) {
//enter your code here
if (mIsPopupVisible) {
keepKeyboard();
mIsPopupVisible = false;
mPopupWindow.dismiss();
}
} else {
//enter code for hid
}
});
You can check this tutorial and this example in GitHub