/** Show the about popup */ private void showPopup() { if (mPopupWindow == null) { LayoutInflater inflater = (LayoutInflater) MainActivity.this.getSystemService(Context.LAYOUT_INFLATER_SERVICE); mPopupLayout = inflater.inflate(R.layout.about_popup, (ViewGroup) findViewById(R.id.popup_element)); mPopupLayout.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED); mPopupWindow = new DragablePopupWindow(mPopupLayout); int height = mPopupLayout.getMeasuredHeight(); int width = mPopupLayout.getMeasuredWidth(); mPopupWindow.setWidth(width); mPopupWindow.setHeight(height); TextView websiteLink = (TextView) mPopupLayout.findViewById(R.id.about_website); websiteLink.setOnClickListener( new View.OnClickListener() { public void onClick(View v) { // open the link on the default browser String url = "http://www.robbertvdzon.com"; Intent i = new Intent(Intent.ACTION_VIEW); i.setData(Uri.parse(url)); startActivity(i); } }); } mPopupWindow.showAtLocation(mPopupLayout, Gravity.CENTER, 0, 0); mPopupWindow.moveToLastPosition(); // in case popup was moved before }
/** * When the back key is pressed while the popup is visible, close the popup and keep the activity * open */ @Override public boolean onKeyDown(int keyCode, KeyEvent event) { if ((keyCode == KeyEvent.KEYCODE_BACK)) { if (keyCode == KeyEvent.KEYCODE_BACK) { if (mPopupWindow != null && mPopupWindow.isShowing()) { mPopupWindow.dismiss(); return true; } } } return super.onKeyDown(keyCode, event); }