List of usage examples for android.view Window ID_ANDROID_CONTENT
int ID_ANDROID_CONTENT
To view the source code for android.view Window ID_ANDROID_CONTENT.
Click Source Link
From source file:kr.co.cashqc.MainActivity.java
private int getScreenSize() { Display display = MainActivity.this.getWindowManager().getDefaultDisplay(); int screenHeight = display.getHeight();// ? ? ? Window window = getWindow();//from w w w . j a va 2 s .c o m int topBarHeight = window.findViewById(Window.ID_ANDROID_CONTENT).getTop();// ? // ?? // ? // ?. return screenHeight - topBarHeight; }
From source file:com.appfeel.cordova.admob.AdMobAds.java
/** * Parses the show ad input parameters and runs the show ad action on the UI thread. * /* ww w . j a va 2 s . c o m*/ * @param inputs The JSONArray representing input parameters. This function expects the first object in the array to be a JSONObject with the input * parameters. * @return A PluginResult representing whether or not an ad was requested succcessfully. Listen for onReceiveAd() and onFailedToReceiveAd() callbacks to see * if an ad was successfully retrieved. */ private PluginResult executeShowBannerAd(final boolean show, final CallbackContext callbackContext) { if (adView == null) { return new PluginResult(Status.ERROR, "adView is null, call createBannerView first."); } cordova.getActivity().runOnUiThread(new Runnable() { @Override public void run() { if (show == isBannerVisible) { // no change } else if (show) { if (adView.getParent() != null) { ((ViewGroup) adView.getParent()).removeView(adView); } if (isBannerOverlap) { RelativeLayout.LayoutParams params2 = new RelativeLayout.LayoutParams( RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT); if (isOffsetStatusBar) { int titleBarHeight = 0; Rect rectangle = new Rect(); Window window = AdMobAds.this.cordova.getActivity().getWindow(); window.getDecorView().getWindowVisibleDisplayFrame(rectangle); if (isBannerAtTop) { if (rectangle.top == 0) { int contentViewTop = window.findViewById(Window.ID_ANDROID_CONTENT).getTop(); titleBarHeight = contentViewTop - rectangle.top; } params2.topMargin = titleBarHeight; } else { if (rectangle.top > 0) { int contentViewBottom = window.findViewById(Window.ID_ANDROID_CONTENT) .getBottom(); titleBarHeight = contentViewBottom - rectangle.bottom; } params2.bottomMargin = titleBarHeight; } } else if (isBannerAtTop) { params2.addRule(RelativeLayout.ALIGN_PARENT_TOP); } else { params2.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM); } if (adViewLayout == null) { adViewLayout = new RelativeLayout(cordova.getActivity()); RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams( RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT); if (CORDOVA_4) { ((ViewGroup) webView.getView().getParent()).addView(adViewLayout, params); } else { ((ViewGroup) webView).addView(adViewLayout, params); } } adViewLayout.addView(adView, params2); adViewLayout.bringToFront(); } else { if (CORDOVA_4) { ViewGroup wvParentView = (ViewGroup) webView.getView().getParent(); if (parentView == null) { parentView = new LinearLayout(webView.getContext()); } if (wvParentView != null && wvParentView != parentView) { wvParentView.removeView(webView.getView()); ((LinearLayout) parentView).setOrientation(LinearLayout.VERTICAL); parentView.setLayoutParams( new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT, 0.0F)); webView.getView().setLayoutParams( new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT, 1.0F)); parentView.addView(webView.getView()); cordova.getActivity().setContentView(parentView); } } else { parentView = (ViewGroup) ((ViewGroup) webView).getParent(); } if (isBannerAtTop) { parentView.addView(adView, 0); } else { parentView.addView(adView); } parentView.bringToFront(); parentView.requestLayout(); } adView.setVisibility(View.VISIBLE); isBannerVisible = true; } else { adView.setVisibility(View.GONE); isBannerVisible = false; } if (callbackContext != null) { callbackContext.success(); } } }); return null; }
From source file:com.jomendezdev.cordova.admob.AdMobAds.java
/** * Parses the show ad input parameters and runs the show ad action on the UI thread. * //from w w w . jav a 2s.com * @param inputs The JSONArray representing input parameters. This function expects the first object in the array to be a JSONObject with the input * parameters. * @return A PluginResult representing whether or not an ad was requested succcessfully. Listen for onReceiveAd() and onFailedToReceiveAd() callbacks to see * if an ad was successfully retrieved. */ private PluginResult executeShowBannerAd(final boolean show, final CallbackContext callbackContext) { if (adView == null) { return new PluginResult(Status.ERROR, "adView is null, call createBannerView first."); } cordova.getActivity().runOnUiThread(new Runnable() { @Override public void run() { if (show == isBannerVisible) { // no change } else if (show) { if (adView.getParent() != null) { ((ViewGroup) adView.getParent()).removeView(adView); } if (isBannerOverlap) { RelativeLayout.LayoutParams params2 = new RelativeLayout.LayoutParams( RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT); if (isOffsetStatusBar) { int titleBarHeight = 0; Rect rectangle = new Rect(); Window window = AdMobAds.this.cordova.getActivity().getWindow(); window.getDecorView().getWindowVisibleDisplayFrame(rectangle); if (isBannerAtTop) { if (rectangle.top == 0) { int contentViewTop = window.findViewById(Window.ID_ANDROID_CONTENT).getTop(); titleBarHeight = contentViewTop - rectangle.top; } params2.topMargin = titleBarHeight; } else { if (rectangle.top > 0) { int contentViewBottom = window.findViewById(Window.ID_ANDROID_CONTENT) .getBottom(); titleBarHeight = contentViewBottom - rectangle.bottom; } params2.bottomMargin = titleBarHeight; } } else if (isBannerAtTop) { params2.addRule(RelativeLayout.ALIGN_PARENT_TOP); } else { params2.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM); } adViewLayout.addView(adView, params2); adViewLayout.bringToFront(); } else { ViewGroup parentView = (ViewGroup) webView.getParent(); if (isBannerAtTop) { parentView.addView(adView, 0); } else { parentView.addView(adView); } parentView.bringToFront(); } adView.setVisibility(View.VISIBLE); isBannerVisible = true; } else { adView.setVisibility(View.GONE); isBannerVisible = false; } if (callbackContext != null) { callbackContext.success(); } } }); return null; }
From source file:org.de.jmg.learn._MainActivity.java
private void resize() { RelativeLayout.LayoutParams params;//from w w w . j a v a2 s .com Resources resources = context.getResources(); DisplayMetrics metrics = resources.getDisplayMetrics(); int height = metrics.heightPixels; width = metrics.widthPixels; int viewTop = _main.findViewById(Window.ID_ANDROID_CONTENT).getTop(); height = height - viewTop; scale = (double) height / (double) 950; double ratio = Math.pow((double) width / (double) height, .5d); boolean blnHorizontal = width > height; if (scale < .5f) { _isSmallDevice = true; _main.isSmallDevice = true; if (scale < .4f) { scale = .4f; } } /* * lib.ShowMessage(this, "Meaning3 Bottom: " +_txtMeaning3.getBottom() + * "\nbtnRight.Top: " + _btnRight.getTop() + "\nDisplayHeight: " + * height); */ if (scale != 1) { // lib.ShowToast(_main, "Scaling font by " + scale + " Screenheight = " //+ height); float tSize = _txtMeaning1.getTextSize(); if (tSize == 40 || (_vok.getCardMode() && tSize == 25)) { _txtMeaning1.setTextSize(TypedValue.COMPLEX_UNIT_PX, (float) (_txtMeaning1.getTextSize() * scale)); } params = (android.widget.RelativeLayout.LayoutParams) _txtMeaning1.getLayoutParams(); if (params.topMargin == 120) { if (!_isSmallDevice) { params.topMargin = (int) (params.topMargin * scale); } else { params.topMargin = (int) (params.topMargin * .1f); } _txtMeaning1.setLayoutParams(params); } if (_txtMeaning2.getTextSize() == 40) { _txtMeaning2.setTextSize(TypedValue.COMPLEX_UNIT_PX, (float) (_txtMeaning2.getTextSize() * scale)); } params = (android.widget.RelativeLayout.LayoutParams) _txtMeaning2.getLayoutParams(); if (params.topMargin == 56) { params.topMargin = (int) (params.topMargin * scale); _txtMeaning2.setLayoutParams(params); } if (_txtMeaning3.getTextSize() == 40) { _txtMeaning3.setTextSize(TypedValue.COMPLEX_UNIT_PX, (float) (_txtMeaning3.getTextSize() * scale)); } params = (android.widget.RelativeLayout.LayoutParams) _txtMeaning3.getLayoutParams(); if (params.topMargin == 56) { params.topMargin = (int) (params.topMargin * scale); _txtMeaning3.setLayoutParams(params); } float size = _txtWord.getTextSize(); if (size == 60) { size *= scale; _txtWord.setTextSize(TypedValue.COMPLEX_UNIT_PX, size); } if (_txtKom.getTextSize() == 35) { _txtKom.setTextSize(TypedValue.COMPLEX_UNIT_PX, (float) (_txtKom.getTextSize() * scale)); } if (_txtedWord.getTextSize() == 60) { _txtedWord.setTextSize(TypedValue.COMPLEX_UNIT_PX, (float) (_txtedWord.getTextSize() * scale)); } if (_txtedKom.getTextSize() == 35) { _txtedKom.setTextSize(TypedValue.COMPLEX_UNIT_PX, (float) (_txtedKom.getTextSize() * scale)); } if (_vok != null && _vok.getCardMode()) { SetViewsToCardmode(); } else { SetViewsToVokMode(); } /* * _txtMeaning1.setOnFocusChangeListener(new * View.OnFocusChangeListener() { * * @Override public void onFocusChange(View v, boolean hasFocus) { * if (_firstFocus && hasFocus) { * hideKeyboard(); _firstFocus = false; } } }); */ } if (scale != 1) { int widthButtons = _btnEdit.getRight() - _btnSkip.getLeft(); int allButtonsWidth = 520; /*_btnEdit.getWidth() +_btnRight.getWidth() +_btnView.getWidth() +_btnWrong.getWidth() +_btnEdit.getWidth(); */ if (widthButtons < allButtonsWidth) { widthButtons = allButtonsWidth; blnWrongWidth = true; } ScaleWidth = (width - 50) / (double) widthButtons; if (ScaleWidth < .7) { _btnEdit.setVisibility(View.GONE); _btnSkip.setVisibility(View.GONE); widthButtons = _btnWrong.getRight() - _btnRight.getLeft(); if (widthButtons < 330) { widthButtons = 330; blnWrongWidth = true; } ScaleWidth = ((double) (_txtMeaning1.getRight() - _txtMeaning1.getLeft())) / (double) widthButtons; if (ScaleWidth < .4d) ScaleWidth = .4d; ScaleTextButtons = ((scale > ScaleWidth) ? scale : ScaleWidth); } else { ScaleTextButtons = ((scale < ScaleWidth) ? scale : ScaleWidth); } RelativeLayout layoutButtons = (RelativeLayout) findViewById(R.id.layoutButtonsInner); params = (android.widget.RelativeLayout.LayoutParams) layoutButtons.getLayoutParams(); if (!blnWrongWidth) { params.bottomMargin = (int) (params.bottomMargin * scale); } else { params.bottomMargin = (int) (0 * ScaleWidth); } layoutButtons.setLayoutParams(params); params = (android.widget.RelativeLayout.LayoutParams) _btnRight.getLayoutParams(); if (!blnWrongWidth) { params.height = (int) (params.height * scale); params.bottomMargin = (int) (params.bottomMargin * scale); } else { params.height = (int) (60 * ScaleWidth); params.bottomMargin = (int) (0 * ScaleWidth); _btnRight.setPadding((int) (_btnRight.getPaddingLeft() * ScaleWidth), (int) (_btnRight.getPaddingTop() * ScaleWidth), (int) (_btnRight.getPaddingRight() * ScaleWidth), (int) (_btnRight.getPaddingBottom() * ScaleWidth)); } params.width = (int) (params.width * ScaleWidth); double ScaleTextButtonsOrig = ScaleTextButtons; if (blnHorizontal) { params.height *= ratio; ScaleTextButtons *= ratio; } _btnRight.setLayoutParams(params); params = (android.widget.RelativeLayout.LayoutParams) _btnWrong.getLayoutParams(); if (!blnWrongWidth) { params.height = (int) (params.height * scale); params.bottomMargin = (int) (params.bottomMargin * scale); } else { params.height = (int) (60 * ScaleWidth); params.bottomMargin = (int) (0 * ScaleWidth); _btnWrong.setPadding((int) (_btnWrong.getPaddingLeft() * ScaleWidth), (int) (_btnWrong.getPaddingTop() * ScaleWidth), (int) (_btnWrong.getPaddingRight() * ScaleWidth), (int) (_btnWrong.getPaddingBottom() * ScaleWidth)); } params.width = (int) (params.width * ScaleWidth); if (blnHorizontal) params.height *= ratio; _btnWrong.setLayoutParams(params); params = (android.widget.RelativeLayout.LayoutParams) _btnSkip.getLayoutParams(); if (!blnWrongWidth) { params.height = (int) (params.height * scale); params.bottomMargin = (int) (params.bottomMargin * scale); } else { params.height = (int) (60 * ScaleWidth); params.bottomMargin = (int) (0 * ScaleWidth); } params.width = (int) (params.width * ScaleWidth); if (blnHorizontal) params.height *= ratio; _btnSkip.setLayoutParams(params); params = (android.widget.RelativeLayout.LayoutParams) _btnView.getLayoutParams(); if (!blnWrongWidth) { params.height = (int) (params.height * scale); params.bottomMargin = (int) (params.bottomMargin * scale); } else { params.height = (int) (60 * ScaleWidth); params.bottomMargin = (int) (0 * ScaleWidth); _btnView.setPadding((int) (_btnView.getPaddingLeft() * ScaleWidth), (int) (_btnView.getPaddingTop() * ScaleWidth), (int) (_btnView.getPaddingRight() * ScaleWidth), (int) (_btnView.getPaddingBottom() * ScaleWidth)); } params.width = (int) (params.width * ScaleWidth); if (blnHorizontal) params.height *= ratio; _btnView.setLayoutParams(params); params = (android.widget.RelativeLayout.LayoutParams) _btnEdit.getLayoutParams(); if (!blnWrongWidth) { params.height = (int) (params.height * scale); params.bottomMargin = (int) (params.bottomMargin * scale); } else { params.height = (int) (60 * ScaleWidth); params.bottomMargin = (int) (0 * ScaleWidth); } params.width = (int) (params.width * ScaleWidth); if (blnHorizontal) params.height *= ratio; _btnEdit.setLayoutParams(params); params = (android.widget.RelativeLayout.LayoutParams) _txtStatus.getLayoutParams(); if (!blnWrongWidth) { params.topMargin = (int) (params.topMargin * scale); } else { params.topMargin = (int) (0 * ScaleWidth); } _txtStatus.setLayoutParams(params); _btnRight.setTextSize(TypedValue.COMPLEX_UNIT_PX, (float) (_btnRight.getTextSize() * ScaleTextButtons)); _btnSkip.setTextSize(TypedValue.COMPLEX_UNIT_PX, (float) (_btnSkip.getTextSize() * ScaleTextButtons)); _btnView.setTextSize(TypedValue.COMPLEX_UNIT_PX, (float) (_btnView.getTextSize() * ScaleTextButtons)); _btnWrong.setTextSize(TypedValue.COMPLEX_UNIT_PX, (float) (_btnWrong.getTextSize() * ScaleTextButtons)); _btnEdit.setTextSize(TypedValue.COMPLEX_UNIT_PX, (float) (_btnEdit.getTextSize() * ScaleTextButtons)); _txtStatus.setTextSize(TypedValue.COMPLEX_UNIT_PX, (float) (_txtStatus.getTextSize() * ScaleTextButtonsOrig)); //_main.ActionBarOriginalTextSize = 0; resizeActionbar(0); Runnable r = new resetLayoutTask(null); rFlashs.add(r); handler.post(r); } }
From source file:org.de.jmg.learn.MainActivity.java
@Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. try {/*from w w w. j a va2 s. c om*/ getMenuInflater().inflate(R.menu.main, menu); //findViewById(R.menu.main).setBackgroundColor(Color.BLACK); //.setBackgroundColor(Color.BLACK); //resize(); OptionsMenu = menu; if (OptionsMenu != null) { mnuAddNew = menu.findItem(R.id.mnuAddWord); mnuUploadToQuizlet = menu.findItem(R.id.mnuUploadToQuizlet); Resources resources = context.getResources(); DisplayMetrics metrics = resources.getDisplayMetrics(); int height = metrics.heightPixels; int viewTop = this.findViewById(Window.ID_ANDROID_CONTENT).getTop(); height = height - viewTop; double scale = (double) height / (double) 950; if (scale < .5f) { isSmallDevice = true; } if (Build.VERSION.SDK_INT < 11) { menu.findItem(R.id.mnuOpenQuizlet).setVisible(false); menu.findItem(R.id.mnuUploadToQuizlet).setVisible(false); } /* if (isSmallDevice) { MenuItemCompat.setShowAsAction(menu.findItem(R.id.mnuSaveAs), MenuItemCompat.SHOW_AS_ACTION_IF_ROOM); } */ MenuItem mnuQuizlet = menu.findItem(R.id.mnuLoginQuizlet); mnuQuizlet.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem item) { //throw new RuntimeException("Test"); return false; } }); if (BuildConfig.DEBUG) { mnuQuizlet.setVisible(true); } else { mnuQuizlet.setVisible(false); } MenuItem mnuAskReverse = OptionsMenu.findItem(R.id.mnuAskReverse); mnuAskReverse.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem item) { item.setChecked(!item.isChecked()); vok.reverse = item.isChecked(); setMnuReverse(); return true; } }); setMnuReverse(); /* if (isSmallDevice) { MenuItem m = menu.findItem(R.id.mnuHome); MenuItemCompat.setShowAsAction(m,MenuItemCompat.SHOW_AS_ACTION_IF_ROOM); m = menu.findItem(R.id.mnuFileOpen); MenuItemCompat.setShowAsAction(m,MenuItemCompat.SHOW_AS_ACTION_IF_ROOM); m = menu.findItem(R.id.mnuSaveAs); MenuItemCompat.setShowAsAction(m,MenuItemCompat.SHOW_AS_ACTION_IF_ROOM); m = menu.findItem(R.id.mnuAddWord); MenuItemCompat.setShowAsAction(m,MenuItemCompat.SHOW_AS_ACTION_IF_ROOM); //lib.ShowToast(this,"Menus set to IF_ROOM!"); } */ mainView.getViewTreeObserver() .addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { @Override public void onGlobalLayout() { // Ensure you call it only once : lib.removeLayoutListener(mainView.getViewTreeObserver(), this); //MainActivity.this.SetShowAsAction(mnuUploadToQuizlet); } }); return true; } throw new RuntimeException("menu is null!"); } catch (Exception ex) { lib.ShowException(this, ex); } return false; }
From source file:org.de.jmg.learn.MainActivity.java
private void _SetShowAsAction(final MenuItem m) { final View tb = this.findViewById(R.id.action_bar); int SizeOther = 0; int width;/*from w ww.j a v a2 s. c om*/ ActionMenu = null; if (tb != null) { width = tb.getWidth(); Resources resources = context.getResources(); DisplayMetrics metrics = resources.getDisplayMetrics(); double height = metrics.heightPixels; int viewTop = this.findViewById(Window.ID_ANDROID_CONTENT).getTop(); double scale = (height - viewTop) / (double) 950; if (scale < .5f) { isSmallDevice = true; } double ActionBarHeight = tb.getHeight(); if (isSmallDevice && ActionBarHeight / height > .15f) { try { FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) tb.getLayoutParams(); layoutParams.height = (int) (height * .15f); tb.setMinimumHeight((int) (height * .15f)); tb.setLayoutParams(layoutParams); tb.requestLayout(); } catch (Exception ex) { Log.e("SetToolbarHeight", ex.getMessage(), ex); } } if (width > 0) { ViewGroup g = (ViewGroup) tb; for (int i = 0; i < g.getChildCount(); i++) { View v = g.getChildAt(i); if ((v instanceof android.support.v7.widget.ActionMenuView)) { SizeOther += v.getWidth(); ActionMenu = (android.support.v7.widget.ActionMenuView) v; } } if (SizeOther < width * .7) _blnReverse = true; if ((_blnReverse || SizeOther > width * .7) && ActionMenu != null) { if (_blnReverse) { //if (!_hasBeenDownsized || _hasBeenDownsized) //{ MenuBuilder mm = (MenuBuilder) ActionMenu.getMenu(); int Actions = mm.getActionItems().size(); try { MenuItem mmm = ActionMenu.getMenu().getItem(Actions + _invisibleCount); if (mmm.isVisible()) { MenuItemCompat.setShowAsAction(mmm, MenuItemCompat.SHOW_AS_ACTION_ALWAYS); } else { _invisibleCount += 1; _SetShowAsAction(mmm); } } catch (IndexOutOfBoundsException ex) { return; } //} } else { MenuItemCompat.setShowAsAction(m, MenuItemCompat.SHOW_AS_ACTION_NEVER); _hasBeenDownsized = true; } ActionMenu.getViewTreeObserver() .addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { @Override public void onGlobalLayout() { if (ActionMenu != null) { lib.removeLayoutListener(ActionMenu.getViewTreeObserver(), this); int SizeNew = ActionMenu.getWidth(); Log.v("Test", "" + SizeNew); MenuBuilder mm = (MenuBuilder) ActionMenu.getMenu(); int count = mm.getActionItems().size(); if (count >= 1 && !(_blnReverse && SizeNew > tb.getWidth() * .7)) { MenuItem m = mm.getActionItems().get(count - 1); _SetShowAsAction(m); } } } }); } } } }