List of usage examples for android.view Gravity TOP
int TOP
To view the source code for android.view Gravity TOP.
Click Source Link
From source file:com.initialxy.cordova.themeablebrowser.ThemeableBrowser.java
/** * Display a new browser with the specified URL. * * @param url//from www .ja v a 2 s . c o m * @param features * @return */ public String showWebPage(final String url, final Options features) { final CordovaWebView thatWebView = this.webView; // Create dialog in new thread Runnable runnable = new Runnable() { @SuppressLint("NewApi") public void run() { // Let's create the main dialog dialog = new ThemeableBrowserDialog(cordova.getActivity(), android.R.style.Theme_Black_NoTitleBar, features.hardwareback); if (!features.disableAnimation) { dialog.getWindow().getAttributes().windowAnimations = android.R.style.Animation_Dialog; } dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); dialog.setCancelable(true); dialog.setThemeableBrowser(getThemeableBrowser()); // Main container layout ViewGroup main = null; if (features.fullscreen) { main = new FrameLayout(cordova.getActivity()); } else { main = new LinearLayout(cordova.getActivity()); ((LinearLayout) main).setOrientation(LinearLayout.VERTICAL); } // Toolbar layout Toolbar toolbarDef = features.toolbar; FrameLayout toolbar = new FrameLayout(cordova.getActivity()); toolbar.setBackgroundColor(hexStringToColor( toolbarDef != null && toolbarDef.color != null ? toolbarDef.color : "#ffffffff")); toolbar.setLayoutParams(new ViewGroup.LayoutParams(LayoutParams.MATCH_PARENT, dpToPixels(toolbarDef != null ? toolbarDef.height : TOOLBAR_DEF_HEIGHT))); if (toolbarDef != null && (toolbarDef.image != null || toolbarDef.wwwImage != null)) { try { Drawable background = getImage(toolbarDef.image, toolbarDef.wwwImage, toolbarDef.wwwImageDensity); setBackground(toolbar, background); } catch (Resources.NotFoundException e) { emitError(ERR_LOADFAIL, String.format("Image for toolbar, %s, failed to load", toolbarDef.image)); } catch (IOException ioe) { emitError(ERR_LOADFAIL, String.format("Image for toolbar, %s, failed to load", toolbarDef.wwwImage)); } } // Left Button Container layout LinearLayout leftButtonContainer = new LinearLayout(cordova.getActivity()); FrameLayout.LayoutParams leftButtonContainerParams = new FrameLayout.LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); leftButtonContainerParams.gravity = Gravity.LEFT | Gravity.CENTER_VERTICAL; leftButtonContainer.setLayoutParams(leftButtonContainerParams); leftButtonContainer.setVerticalGravity(Gravity.CENTER_VERTICAL); // Right Button Container layout LinearLayout rightButtonContainer = new LinearLayout(cordova.getActivity()); FrameLayout.LayoutParams rightButtonContainerParams = new FrameLayout.LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); rightButtonContainerParams.gravity = Gravity.RIGHT | Gravity.CENTER_VERTICAL; rightButtonContainer.setLayoutParams(rightButtonContainerParams); rightButtonContainer.setVerticalGravity(Gravity.CENTER_VERTICAL); // Edit Text Box edittext = new EditText(cordova.getActivity()); RelativeLayout.LayoutParams textLayoutParams = new RelativeLayout.LayoutParams( LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT); textLayoutParams.addRule(RelativeLayout.RIGHT_OF, 1); textLayoutParams.addRule(RelativeLayout.LEFT_OF, 5); edittext.setLayoutParams(textLayoutParams); edittext.setSingleLine(true); edittext.setText(url); edittext.setInputType(InputType.TYPE_TEXT_VARIATION_URI); edittext.setImeOptions(EditorInfo.IME_ACTION_GO); edittext.setInputType(InputType.TYPE_NULL); // Will not except input... Makes the text NON-EDITABLE edittext.setOnKeyListener(new View.OnKeyListener() { public boolean onKey(View v, int keyCode, KeyEvent event) { // If the event is a key-down event on the "enter" button if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) { navigate(edittext.getText().toString()); return true; } return false; } }); // Back button final Button back = createButton(features.backButton, "back button", new View.OnClickListener() { public void onClick(View v) { emitButtonEvent(features.backButton, inAppWebView.getUrl()); if (features.backButtonCanClose && !canGoBack()) { closeDialog(); } else { goBack(); } } }); if (back != null) { back.setEnabled(features.backButtonCanClose); } // Forward button final Button forward = createButton(features.forwardButton, "forward button", new View.OnClickListener() { public void onClick(View v) { emitButtonEvent(features.forwardButton, inAppWebView.getUrl()); goForward(); } }); if (forward != null) { forward.setEnabled(false); } // Close/Done button Button close = createButton(features.closeButton, "close button", new View.OnClickListener() { public void onClick(View v) { emitButtonEvent(features.closeButton, inAppWebView.getUrl()); closeDialog(); } }); // Menu button Spinner menu = features.menu != null ? new MenuSpinner(cordova.getActivity()) : null; if (menu != null) { menu.setLayoutParams( new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); menu.setContentDescription("menu button"); setButtonImages(menu, features.menu, DISABLED_ALPHA); // We are not allowed to use onClickListener for Spinner, so we will use // onTouchListener as a fallback. menu.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { if (event.getAction() == MotionEvent.ACTION_UP) { emitButtonEvent(features.menu, inAppWebView.getUrl()); } return false; } }); if (features.menu.items != null) { HideSelectedAdapter<EventLabel> adapter = new HideSelectedAdapter<EventLabel>( cordova.getActivity(), android.R.layout.simple_spinner_item, features.menu.items); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); menu.setAdapter(adapter); menu.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) { if (inAppWebView != null && i < features.menu.items.length) { emitButtonEvent(features.menu.items[i], inAppWebView.getUrl(), i); } } @Override public void onNothingSelected(AdapterView<?> adapterView) { } }); } } // Title final TextView title = features.title != null ? new TextView(cordova.getActivity()) : null; final TextView subtitle = features.title != null ? new TextView(cordova.getActivity()) : null; if (title != null) { FrameLayout.LayoutParams titleParams = new FrameLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.FILL_PARENT); titleParams.gravity = Gravity.CENTER; title.setLayoutParams(titleParams); title.setSingleLine(); title.setEllipsize(TextUtils.TruncateAt.END); title.setGravity(Gravity.CENTER | Gravity.TOP); title.setTextColor( hexStringToColor(features.title.color != null ? features.title.color : "#000000ff")); title.setTypeface(title.getTypeface(), Typeface.BOLD); title.setTextSize(TypedValue.COMPLEX_UNIT_PT, 8); FrameLayout.LayoutParams subtitleParams = new FrameLayout.LayoutParams( LayoutParams.MATCH_PARENT, LayoutParams.FILL_PARENT); titleParams.gravity = Gravity.CENTER; subtitle.setLayoutParams(subtitleParams); subtitle.setSingleLine(); subtitle.setEllipsize(TextUtils.TruncateAt.END); subtitle.setGravity(Gravity.CENTER | Gravity.BOTTOM); subtitle.setTextColor(hexStringToColor( features.title.subColor != null ? features.title.subColor : "#000000ff")); subtitle.setTextSize(TypedValue.COMPLEX_UNIT_PT, 6); subtitle.setVisibility(View.GONE); if (features.title.staticText != null) { title.setGravity(Gravity.CENTER); title.setText(features.title.staticText); } else { subtitle.setVisibility(View.VISIBLE); } } // WebView inAppWebView = new WebView(cordova.getActivity()); final ViewGroup.LayoutParams inAppWebViewParams = features.fullscreen ? new FrameLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT) : new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, 0); if (!features.fullscreen) { ((LinearLayout.LayoutParams) inAppWebViewParams).weight = 1; } inAppWebView.setLayoutParams(inAppWebViewParams); inAppWebView.setWebChromeClient(new InAppChromeClient(thatWebView)); WebViewClient client = new ThemeableBrowserClient(thatWebView, new PageLoadListener() { @Override public void onPageStarted(String url) { if (inAppWebView != null && title != null && features.title != null && features.title.staticText == null && features.title.showPageTitle && features.title.loadingText != null) { title.setText(features.title.loadingText); subtitle.setText(url); } } @Override public void onPageFinished(String url, boolean canGoBack, boolean canGoForward) { if (inAppWebView != null && title != null && features.title != null && features.title.staticText == null && features.title.showPageTitle) { title.setText(inAppWebView.getTitle()); subtitle.setText(inAppWebView.getUrl()); } if (back != null) { back.setEnabled(canGoBack || features.backButtonCanClose); } if (forward != null) { forward.setEnabled(canGoForward); } } }); inAppWebView.setWebViewClient(client); WebSettings settings = inAppWebView.getSettings(); settings.setJavaScriptEnabled(true); settings.setJavaScriptCanOpenWindowsAutomatically(true); settings.setBuiltInZoomControls(features.zoom); settings.setDisplayZoomControls(false); settings.setPluginState(android.webkit.WebSettings.PluginState.ON); //Toggle whether this is enabled or not! Bundle appSettings = cordova.getActivity().getIntent().getExtras(); boolean enableDatabase = appSettings == null || appSettings.getBoolean("ThemeableBrowserStorageEnabled", true); if (enableDatabase) { String databasePath = cordova.getActivity().getApplicationContext() .getDir("themeableBrowserDB", Context.MODE_PRIVATE).getPath(); settings.setDatabasePath(databasePath); settings.setDatabaseEnabled(true); } settings.setDomStorageEnabled(true); if (features.clearcache) { CookieManager.getInstance().removeAllCookie(); } else if (features.clearsessioncache) { CookieManager.getInstance().removeSessionCookie(); } inAppWebView.loadUrl(url); inAppWebView.getSettings().setLoadWithOverviewMode(true); inAppWebView.getSettings().setUseWideViewPort(true); inAppWebView.requestFocus(); inAppWebView.requestFocusFromTouch(); // Add buttons to either leftButtonsContainer or // rightButtonsContainer according to user's alignment // configuration. int leftContainerWidth = 0; int rightContainerWidth = 0; if (features.customButtons != null) { for (int i = 0; i < features.customButtons.length; i++) { final BrowserButton buttonProps = features.customButtons[i]; final int index = i; Button button = createButton(buttonProps, String.format("custom button at %d", i), new View.OnClickListener() { @Override public void onClick(View view) { if (inAppWebView != null) { emitButtonEvent(buttonProps, inAppWebView.getUrl(), index); } } }); if (ALIGN_RIGHT.equals(buttonProps.align)) { rightButtonContainer.addView(button); rightContainerWidth += button.getLayoutParams().width; } else { leftButtonContainer.addView(button, 0); leftContainerWidth += button.getLayoutParams().width; } } } // Back and forward buttons must be added with special ordering logic such // that back button is always on the left of forward button if both buttons // are on the same side. if (forward != null && features.forwardButton != null && !ALIGN_RIGHT.equals(features.forwardButton.align)) { leftButtonContainer.addView(forward, 0); leftContainerWidth += forward.getLayoutParams().width; } if (back != null && features.backButton != null && ALIGN_RIGHT.equals(features.backButton.align)) { rightButtonContainer.addView(back); rightContainerWidth += back.getLayoutParams().width; } if (back != null && features.backButton != null && !ALIGN_RIGHT.equals(features.backButton.align)) { leftButtonContainer.addView(back, 0); leftContainerWidth += back.getLayoutParams().width; } if (forward != null && features.forwardButton != null && ALIGN_RIGHT.equals(features.forwardButton.align)) { rightButtonContainer.addView(forward); rightContainerWidth += forward.getLayoutParams().width; } if (menu != null) { if (features.menu != null && ALIGN_RIGHT.equals(features.menu.align)) { rightButtonContainer.addView(menu); rightContainerWidth += menu.getLayoutParams().width; } else { leftButtonContainer.addView(menu, 0); leftContainerWidth += menu.getLayoutParams().width; } } if (close != null) { if (features.closeButton != null && ALIGN_RIGHT.equals(features.closeButton.align)) { rightButtonContainer.addView(close); rightContainerWidth += close.getLayoutParams().width; } else { leftButtonContainer.addView(close, 0); leftContainerWidth += close.getLayoutParams().width; } } // Add the views to our toolbar toolbar.addView(leftButtonContainer); // Don't show address bar. // toolbar.addView(edittext); toolbar.addView(rightButtonContainer); if (title != null) { int titleMargin = Math.max(leftContainerWidth, rightContainerWidth); FrameLayout.LayoutParams titleParams = (FrameLayout.LayoutParams) title.getLayoutParams(); titleParams.setMargins(titleMargin, 8, titleMargin, 0); toolbar.addView(title); } if (subtitle != null) { int subtitleMargin = Math.max(leftContainerWidth, rightContainerWidth); FrameLayout.LayoutParams subtitleParams = (FrameLayout.LayoutParams) subtitle.getLayoutParams(); subtitleParams.setMargins(subtitleMargin, 0, subtitleMargin, 8); toolbar.addView(subtitle); } if (features.fullscreen) { // If full screen mode, we have to add inAppWebView before adding toolbar. main.addView(inAppWebView); } // Don't add the toolbar if its been disabled if (features.location) { // Add our toolbar to our main view/layout main.addView(toolbar); } if (!features.fullscreen) { // If not full screen, we add inAppWebView after adding toolbar. main.addView(inAppWebView); } WindowManager.LayoutParams lp = new WindowManager.LayoutParams(); lp.copyFrom(dialog.getWindow().getAttributes()); lp.width = WindowManager.LayoutParams.MATCH_PARENT; lp.height = WindowManager.LayoutParams.MATCH_PARENT; dialog.setContentView(main); dialog.show(); dialog.getWindow().setAttributes(lp); // the goal of openhidden is to load the url and not display it // Show() needs to be called to cause the URL to be loaded if (features.hidden) { dialog.hide(); } } }; this.cordova.getActivity().runOnUiThread(runnable); return ""; }
From source file:com.example.verticaldrawerlayout.VerticalDrawerLayout.java
@Override protected void onLayout(boolean changed, int l, int t, int r, int b) { mInLayout = true;/*from ww w .j av a 2s .c om*/ final int height = b - t; final int childCount = getChildCount(); for (int i = 0; i < childCount; i++) { final View child = getChildAt(i); if (child.getVisibility() == GONE) { continue; } final LayoutParams lp = (LayoutParams) child.getLayoutParams(); if (isContentView(child)) { child.layout(lp.leftMargin, lp.topMargin, lp.leftMargin + child.getMeasuredWidth(), lp.topMargin + child.getMeasuredHeight()); } else { // Drawer, if it wasn't onMeasure would have thrown an // exception. final int childWidth = child.getMeasuredWidth(); final int childHeight = child.getMeasuredHeight(); int childTop; final float newOffset; if (checkDrawerViewAbsoluteGravity(child, Gravity.TOP)) { childTop = -childHeight + (int) (childHeight * lp.onScreen); newOffset = (float) (childHeight + childTop) / childHeight; } else { // Right; onMeasure checked for us. childTop = height - (int) (childHeight * lp.onScreen); newOffset = (float) (height - childTop) / childHeight; } final boolean changeOffset = newOffset != lp.onScreen; final int vgrav = lp.gravity & Gravity.VERTICAL_GRAVITY_MASK; switch (vgrav) { default: case Gravity.LEFT: { child.layout(lp.leftMargin, childTop, lp.leftMargin + childWidth, childTop + childHeight); break; } case Gravity.RIGHT: { final int width = r - l; child.layout(width - lp.rightMargin - childWidth, childTop, width - lp.rightMargin, childTop + childHeight); break; } case Gravity.CENTER_HORIZONTAL: { final int width = r - l; int childLeft = (width - childWidth) / 2; // Offset for margins. If things don't fit right because of // bad measurement before, oh well. if (childLeft < lp.leftMargin) { childLeft = lp.leftMargin; } else if (childLeft + childWidth > width - lp.rightMargin) { childLeft = width - lp.rightMargin - childWidth; } child.layout(childLeft, childTop, childLeft + childWidth, childTop + childHeight); break; } } if (changeOffset) { setDrawerViewOffset(child, newOffset); } final int newVisibility = lp.onScreen > 0 ? VISIBLE : INVISIBLE; if (child.getVisibility() != newVisibility) { child.setVisibility(newVisibility); } } } mInLayout = false; mFirstLayout = false; }
From source file:org.csp.everyaware.offline.Map.java
/****************** OTTIENE RIFERIMENTO AI BOTTONI *********************************/ public void getButtonRefs() { mZoomControls = (LinearLayout) findViewById(R.id.zoomLinearLayout); mZoomControls.setVisibility(View.GONE); mTrackLengthBtn = (Button) findViewById(R.id.trackLengthBtn); mFollowCamBtn = (Button) findViewById(R.id.followCameraBtn); mZoomOutBtn = (Button) findViewById(R.id.zoomOutBtn); mZoomInBtn = (Button) findViewById(R.id.zoomInBtn); mInsertAnnBtn = (Button) findViewById(R.id.insertAnnBtn); mShareBtn = (Button) findViewById(R.id.shareBtn); mTrackLengthBtn.setVisibility(View.GONE); mInsertAnnBtn.setVisibility(View.GONE); mZoomOutBtn.setOnClickListener(new OnClickListener() { @Override/*w w w . ja v a 2s . c om*/ public void onClick(View arg0) { // Zoom out try { mGoogleMap.moveCamera(CameraUpdateFactory.zoomBy(-1f)); } catch (NullPointerException e) { e.printStackTrace(); } //read and save actual zoom level mZoom = mGoogleMap.getCameraPosition().zoom; } }); mZoomInBtn.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { // Zoom in try { mGoogleMap.moveCamera(CameraUpdateFactory.zoomBy(1f)); } catch (NullPointerException e) { e.printStackTrace(); } //read and save actual zoom level mZoom = mGoogleMap.getCameraPosition().zoom; } }); mShareBtn.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { mFacebookManager = FacebookManager.getInstance(Map.this, mFacebookHandler); mTwitterManager = TwitterManager.getInstance(Map.this); final Dialog dialog = new Dialog(Map.this); dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); dialog.setContentView(R.layout.share_dialog); //dialog.setTitle("Activate login on..."); getShareButtonsRef(dialog); dialog.show(); } }); mFollowCamBtn.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { //mCameraTrackOn = !mCameraTrackOn; setCameraTracking(); if (mCameraTrackOn) { try { if (Utils.lastPhoneLocation != null) mGoogleMap.animateCamera( CameraUpdateFactory.newLatLng(new LatLng(Utils.lastPhoneLocation.getLatitude(), Utils.lastPhoneLocation.getLongitude()))); else if (Utils.lastNetworkLocation != null) mGoogleMap.animateCamera(CameraUpdateFactory .newLatLng(new LatLng(Utils.lastNetworkLocation.getLatitude(), Utils.lastNetworkLocation.getLongitude()))); } catch (NullPointerException e) { e.printStackTrace(); } } } }); mShareBtn.setOnLongClickListener(new OnLongClickListener() { @Override public boolean onLongClick(View arg0) { Toast toast = Toast.makeText(getApplicationContext(), getResources().getString(R.string.share_btn_text), Toast.LENGTH_LONG); toast.setGravity(Gravity.TOP | Gravity.RIGHT, 0, 250); //250 from top on a 480x800 screen toast.show(); return false; } }); //status icons references mGpsStatus = (ImageView) findViewById(R.id.gpsStatusIv); mInterUplStatus = (ImageView) findViewById(R.id.interUplStatusIv); //gps status icon initialization mGpsStatus.setBackgroundResource(R.drawable.gps_off); //read network type index on which upload data is allowed: 0 - only wifi; 1 - both wifi and mobile int networkTypeIndex = Utils.getUploadNetworkTypeIndex(getApplicationContext()); //1 - is internet connection available? boolean[] connectivity = Utils.haveNetworkConnection(getApplicationContext()); //if user wants to upload only on wifi networks, connectivity[0] (network connectivity) must be true if (networkTypeIndex == 0) { if (connectivity[0]) mConnectivityOn = true; else mConnectivityOn = false; } else //if user wants to upload both on wifi/mobile networks mConnectivityOn = connectivity[0] || connectivity[1]; //network status icon initialization if (mConnectivityOn) { mInterUplStatus.setBackgroundResource(R.drawable.internet_on); Utils.uploadOn = Constants.INTERNET_ON_INT; } else { mInterUplStatus.setBackgroundResource(R.drawable.internet_off); Utils.uploadOn = Constants.INTERNET_OFF_INT; } //button to get from server black carbon levels around user mGetBcLevelsBtn = (Button) findViewById(R.id.getBcLevelsBtn); mGetBcLevelsBtn.setVisibility(View.VISIBLE); mGetBcLevelsBtn.setOnClickListener(mGetBcLevelsOnClickListener); //bcLayout.addView(mGetBcLevelsBtn); mSpectrum = (LinearLayout) findViewById(R.id.spectrumLinearLayout); mSpectrum.setVisibility(View.VISIBLE); }
From source file:com.dk.view.FolderDrawerLayout.java
@Override protected void onLayout(boolean changed, int l, int t, int r, int b) { mInLayout = true;//from www.j a v a 2 s . co m final int width = r - l; final int childCount = getChildCount(); for (int i = 0; i < childCount; i++) { final View child = getChildAt(i); if (child.getVisibility() == GONE) { continue; } final LayoutParams lp = (LayoutParams) child.getLayoutParams(); if (isContentView(child)) { child.layout(lp.leftMargin, lp.topMargin, lp.leftMargin + child.getMeasuredWidth(), lp.topMargin + child.getMeasuredHeight()); } else { // Drawer, if it wasn't onMeasure would have thrown an // exception. final int childWidth = child.getMeasuredWidth(); final int childHeight = child.getMeasuredHeight(); int childLeft; final float newOffset; if (checkDrawerViewAbsoluteGravity(child, Gravity.LEFT)) { childLeft = -childWidth + (int) (childWidth * lp.onScreen); newOffset = (float) (childWidth + childLeft) / childWidth; } else { // Right; onMeasure checked for us. childLeft = width - (int) (childWidth * lp.onScreen); newOffset = (float) (width - childLeft) / childWidth; } final boolean changeOffset = newOffset != lp.onScreen; final int vgrav = lp.gravity & Gravity.VERTICAL_GRAVITY_MASK; switch (vgrav) { default: case Gravity.TOP: { child.layout(childLeft, lp.topMargin, childLeft + childWidth, lp.topMargin + childHeight); break; } case Gravity.BOTTOM: { final int height = b - t; child.layout(childLeft, height - lp.bottomMargin - child.getMeasuredHeight(), childLeft + childWidth, height - lp.bottomMargin); break; } case Gravity.CENTER_VERTICAL: { final int height = b - t; int childTop = (height - childHeight) / 2; // Offset for margins. If things don't fit right because of // bad measurement before, oh well. if (childTop < lp.topMargin) { childTop = lp.topMargin; } else if (childTop + childHeight > height - lp.bottomMargin) { childTop = height - lp.bottomMargin - childHeight; } child.layout(childLeft, childTop, childLeft + childWidth, childTop + childHeight); break; } } if (changeOffset) { setDrawerViewOffset(child, newOffset); } final int newVisibility = lp.onScreen > 0 ? VISIBLE : INVISIBLE; if (child.getVisibility() != newVisibility) { child.setVisibility(newVisibility); } } } mInLayout = false; mFirstLayout = false; }
From source file:com.actionbarsherlock.custom.widget.VerticalDrawerLayout.java
boolean isDrawerView(View child) { final int gravity = ((LayoutParams) child.getLayoutParams()).gravity; final int absGravity = GravityCompat.getAbsoluteGravity(gravity, ViewCompat.getLayoutDirection(child)); return (absGravity & (Gravity.TOP | Gravity.BOTTOM)) != 0; }
From source file:android.support.wear.widget.drawer.WearableDrawerLayout.java
/** * Peeks the given drawer if it is not {@code null} and has a peek view. *///from w w w . ja va 2 s . c om private void maybePeekDrawer(WearableDrawerView drawerView) { if (drawerView == null) { return; } View peekView = drawerView.getPeekContainer(); if (peekView == null) { return; } View drawerContent = drawerView.getDrawerContent(); int layoutGravity = ((FrameLayout.LayoutParams) drawerView.getLayoutParams()).gravity; int gravity = layoutGravity == Gravity.NO_GRAVITY ? drawerView.preferGravity() : layoutGravity; drawerView.setIsPeeking(true); peekView.setAlpha(1); peekView.setScaleX(1); peekView.setScaleY(1); peekView.setVisibility(VISIBLE); if (drawerContent != null) { drawerContent.setAlpha(0); drawerContent.setVisibility(GONE); } if (gravity == Gravity.BOTTOM) { mBottomDrawerDragger.smoothSlideViewTo(drawerView, 0 /* finalLeft */, getHeight() - peekView.getHeight()); } else if (gravity == Gravity.TOP) { mTopDrawerDragger.smoothSlideViewTo(drawerView, 0 /* finalLeft */, -(drawerView.getHeight() - peekView.getHeight())); if (!mIsAccessibilityEnabled) { // Don't automatically close the top drawer when in accessibility mode. closeDrawerDelayed(gravity, PEEK_AUTO_CLOSE_DELAY_MS); } } invalidate(); }
From source file:com.google.fpl.voltair.VoltAirActivity.java
private void showAchievementToast(final String prefix, final String achievementName) { runOnUiThread(new Runnable() { public void run() { Toast toast = Toast.makeText(VoltAirActivity.this, String.format("%s: %s", prefix, getAchievementTitle(achievementName)), Toast.LENGTH_LONG); toast.setGravity(Gravity.TOP | Gravity.CENTER_HORIZONTAL, 0, 0); toast.show();/*w w w . ja v a 2 s . co m*/ } }); }
From source file:com.doubleTwist.drawerlib.ADrawerLayout.java
private void readViews() { mContent = getChildAt(0);/*from w w w. j a v a2 s .com*/ for (int i = 1, count = getChildCount(); i < count; i++) { View v = getChildAt(i); if (v.getId() == DIMMER_VIEW_ID) continue; LayoutParams params = (LayoutParams) v.getLayoutParams(); switch (params.gravity) { case Gravity.LEFT: // left mLeft = v; mDrawerState.mLeftEnabled = true; break; case Gravity.RIGHT: // right mRight = v; mDrawerState.mRightEnabled = true; break; case Gravity.TOP: // top mTop = v; mDrawerState.mTopEnabled = true; break; case Gravity.BOTTOM: // bottom mBottom = v; mDrawerState.mBottomEnabled = true; break; default: mLeft = v; break; } } }
From source file:android.support.wear.widget.drawer.WearableDrawerLayout.java
/** * @param gravity the gravity of the child to return. * @return the drawer with the specified gravity *//*from w w w.j a v a2 s . c om*/ @Nullable private WearableDrawerView findDrawerWithGravity(int gravity) { switch (gravity) { case Gravity.TOP: return mTopDrawerView; case Gravity.BOTTOM: return mBottomDrawerView; default: Log.w(TAG, "Invalid drawer gravity: " + gravity); return null; } }
From source file:com.aidy.bottomdrawerlayout.AllDrawerLayout.java
/** * 12-03 22:59:19.686: I/BottomDrawerLayout(12480): onLayout() -- left = 0 * -- top = 0 -- right = 1080 -- b = 1675 12-03 22:59:19.686: * I/BottomDrawerLayout(12480): onLayout() -- childWidth = 750 -- * childHeight = 1675 -- lp.onScreen = 0.0 12-03 22:59:19.686: * I/BottomDrawerLayout(12480): onLayout() -- childLeft = -750 -- newOffset * = 0.0 12-03 22:59:19.686: I/BottomDrawerLayout(12480): onLayout() -- * childWidth = 750 -- childHeight = 1675 -- lp.onScreen = 0.0 12-03 * 22:59:19.686: I/BottomDrawerLayout(12480): onLayout() -- childLeft = 1080 * -- newOffset = 0.0/*from ww w . j a v a2 s .com*/ */ @Override protected void onLayout(boolean changed, int l, int t, int r, int b) { Log.i(TAG, "onLayout() -- left = " + l + " -- top = " + t + " -- right = " + r + " -- b = " + b); mInLayout = true; final int width = r - l;// final int height = b - t;// final int childCount = getChildCount(); for (int i = 0; i < childCount; i++) { final View child = getChildAt(i); if (child.getVisibility() == GONE) { continue; } final LayoutParams lp = (LayoutParams) child.getLayoutParams(); if (isContentView(child)) { child.layout(lp.leftMargin, lp.topMargin, lp.leftMargin + child.getMeasuredWidth(), lp.topMargin + child.getMeasuredHeight()); } else { // ?view final int childWidth = child.getMeasuredWidth(); final int childHeight = child.getMeasuredHeight(); // Log.i(TAG, "onLayout() -- childWidth = " + childWidth + // " -- childHeight = " + childHeight // + " -- lp.onScreen = " + lp.onScreen); int childLeft = 0;// int childTop = 0;// float newOffset = 0;// switch (getDrawerViewAbsoluteGravity(child)) { case Gravity.LEFT: if (checkDrawerViewAbsoluteGravity(child, Gravity.LEFT)) { // Log.i(TAG, "onLayout() -- 1"); childLeft = -childWidth + (int) (childWidth * lp.onScreen); newOffset = (float) (childWidth + childLeft) / childWidth;// ? } break; case Gravity.RIGHT: if (checkDrawerViewAbsoluteGravity(child, Gravity.RIGHT)) { // Log.i(TAG, "onLayout() -- 2"); childLeft = width - (int) (childWidth * lp.onScreen); newOffset = (float) (width - childLeft) / childWidth;// ? } break; case Gravity.TOP: if (checkDrawerViewAbsoluteGravity(child, Gravity.TOP)) { // Log.i(TAG, "onLayout() -- 3"); childTop = -childHeight + (int) (childHeight * lp.onScreen); newOffset = (float) (childHeight + childTop) / childHeight;// ? } break; case Gravity.BOTTOM: if (checkDrawerViewAbsoluteGravity(child, Gravity.BOTTOM)) { // Log.i(TAG, "onLayout() -- 4"); childTop = height - (int) (childHeight * lp.onScreen); newOffset = (float) (height - childTop) / childHeight;// ? } break; default: childTop = height - (int) (childHeight * lp.onScreen); newOffset = (float) (height - childTop) / childHeight;// ? break; } // ///////////////////////////////////////// // Log.i(TAG, "onLayout() -- childLeft = " + childLeft + // " -- newOffset = " + newOffset); final boolean changeOffset = newOffset != lp.onScreen; final int vgrav = lp.gravity & Gravity.VERTICAL_GRAVITY_MASK; switch (vgrav) { // case Gravity.TOP: { // Log.i(TAG, "onLayout() -- Gravity.TOP"); // child.layout(childLeft, lp.topMargin, childLeft + childWidth, // lp.topMargin + childHeight); // break; // } // case Gravity.BOTTOM: { // Log.i(TAG, "onLayout() -- Gravity.BOTTOM"); // child.layout(childLeft, height - lp.bottomMargin - // child.getMeasuredHeight(), childLeft // + childWidth, height - lp.bottomMargin); // break; // } case Gravity.CENTER_VERTICAL: { // Log.i(TAG, "onLayout() -- Gravity.CENTER_VERTICAL"); int childTop_cv = (height - childHeight) / 2; // Offset for margins. If things don't fit right because of // bad measurement before, oh well. if (childTop_cv < lp.topMargin) { childTop_cv = lp.topMargin; } else if (childTop_cv + childHeight > height - lp.bottomMargin) { childTop_cv = height - lp.bottomMargin - childHeight; } child.layout(childLeft, childTop_cv, childLeft + childWidth, childTop_cv + childHeight); break; } } // ///////////////////////////////////////// if (changeOffset) { setDrawerViewOffset(child, newOffset); } final int newVisibility = lp.onScreen > 0 ? VISIBLE : INVISIBLE; if (child.getVisibility() != newVisibility) { child.setVisibility(newVisibility); } } } mInLayout = false; mFirstLayout = false; }