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.aidy.bottomdrawerlayout.AllDrawerLayout.java
/** * Check the lock mode of the given drawer view. * /*from w ww. j a v a 2 s . c o m*/ * @param drawerView * Drawer view to check lock mode * @return one of {@link #LOCK_MODE_UNLOCKED}, * {@link #LOCK_MODE_LOCKED_CLOSED} or * {@link #LOCK_MODE_LOCKED_OPEN}. */ public int getDrawerLockMode(View drawerView) { final int absGravity = getDrawerViewAbsoluteGravity(drawerView); switch (absGravity) { case Gravity.LEFT: return mLockModeLeft; case Gravity.RIGHT: return mLockModeRight; case Gravity.TOP: return mLockModeTop; case Gravity.BOTTOM: return mLockModeBottom; default: return LOCK_MODE_UNLOCKED; } }
From source file:com.android.mail.browse.ConversationContainer.java
/** * Positions the overlays given an updated y position for the container. * @param y the current top position on screen * @param postAddView If {@code true}, posts all calls to * {@link #addViewInLayoutWrapper(android.view.View, boolean)} * to the UI thread rather than adding it immediately. If {@code false}, * calls {@link #addViewInLayoutWrapper(android.view.View, boolean)} * immediately./*from ww w . ja va 2s .c om*/ */ private void positionOverlays(int y, boolean postAddView) { mOffsetY = y; /* * The scale value that WebView reports is inaccurate when measured during WebView * initialization. This bug is present in ICS, so to work around it, we ignore all * reported values and use a calculated expected value from ConversationWebView instead. * Only when the user actually begins to touch the view (to, say, begin a zoom) do we begin * to pay attention to WebView-reported scale values. */ if (mTouchInitialized) { mScale = mWebView.getScale(); } else if (mScale == 0) { mScale = mWebView.getInitialScale(); } traceLayout("in positionOverlays, raw scale=%f, effective scale=%f", mWebView.getScale(), mScale); if (mOverlayPositions == null || mOverlayAdapter == null) { return; } // recycle scrolled-off views and add newly visible views // we want consecutive spacers/overlays to stack towards the bottom // so iterate from the bottom of the conversation up // starting with the last spacer bottom and the last adapter item, position adapter views // in a single stack until you encounter a non-contiguous expanded message header, // then decrement to the next spacer. traceLayout("IN positionOverlays, spacerCount=%d overlayCount=%d", mOverlayPositions.length, mOverlayAdapter.getCount()); mSnapIndex = -1; mAdditionalBottomBorderOverlayTop = 0; int adapterLoopIndex = mOverlayAdapter.getCount() - 1; int spacerIndex = mOverlayPositions.length - 1; while (spacerIndex >= 0 && adapterLoopIndex >= 0) { final int spacerTop = getOverlayTop(spacerIndex); final int spacerBottom = getOverlayBottom(spacerIndex); final boolean flip; final int flipOffset; final int forceGravity; // flip direction from bottom->top to top->bottom traversal on the very first spacer // to facilitate top-aligned headers at spacer index = 0 if (spacerIndex == 0) { flip = true; flipOffset = adapterLoopIndex; forceGravity = Gravity.TOP; } else { flip = false; flipOffset = 0; forceGravity = Gravity.NO_GRAVITY; } int adapterIndex = flip ? flipOffset - adapterLoopIndex : adapterLoopIndex; // always place at least one overlay per spacer ConversationOverlayItem adapterItem = mOverlayAdapter.getItem(adapterIndex); OverlayPosition itemPos = calculatePosition(adapterItem, spacerTop, spacerBottom, forceGravity); traceLayout("in loop, spacer=%d overlay=%d t/b=%d/%d (%s)", spacerIndex, adapterIndex, itemPos.top, itemPos.bottom, adapterItem); positionOverlay(adapterIndex, itemPos.top, itemPos.bottom, postAddView); // and keep stacking overlays unconditionally if we are on the first spacer, or as long // as overlays are contiguous while (--adapterLoopIndex >= 0) { adapterIndex = flip ? flipOffset - adapterLoopIndex : adapterLoopIndex; adapterItem = mOverlayAdapter.getItem(adapterIndex); if (spacerIndex > 0 && !adapterItem.isContiguous()) { // advance to the next spacer, but stay on this adapter item break; } // place this overlay in the region of the spacer above or below the last item, // depending on direction of iteration final int regionTop = flip ? itemPos.bottom : spacerTop; final int regionBottom = flip ? spacerBottom : itemPos.top; itemPos = calculatePosition(adapterItem, regionTop, regionBottom, forceGravity); traceLayout("in contig loop, spacer=%d overlay=%d t/b=%d/%d (%s)", spacerIndex, adapterIndex, itemPos.top, itemPos.bottom, adapterItem); positionOverlay(adapterIndex, itemPos.top, itemPos.bottom, postAddView); } spacerIndex--; } positionSnapHeader(mSnapIndex); positionAdditionalBottomBorder(postAddView); }
From source file:com.neka.cordova.inappbrowser.InAppBrowser.java
/** * Display a new browser with the specified URL. * * @param url The url to load. * @param jsonObject/*from ww w . ja va 2 s . co m*/ */ public String showWebPage(final String url, HashMap<String, Boolean> features) { // Determine if we should hide the location bar. showLocationBar = true; openWindowHidden = false; if (features != null) { Boolean show = features.get(LOCATION); if (show != null) { showLocationBar = show.booleanValue(); } Boolean hidden = features.get(HIDDEN); if (hidden != null) { openWindowHidden = hidden.booleanValue(); } Boolean cache = features.get(CLEAR_ALL_CACHE); if (cache != null) { clearAllCache = cache.booleanValue(); } else { cache = features.get(CLEAR_SESSION_CACHE); if (cache != null) { clearSessionCache = cache.booleanValue(); } } } final CordovaWebView thatWebView = this.webView; // Create dialog in new thread Runnable runnable = new Runnable() { /** * Convert our DIP units to Pixels * * @return int */ private int dpToPixels(int dipValue) { int value = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, (float) dipValue, cordova.getActivity().getResources().getDisplayMetrics()); return value; } public void run() { // Let's create the main dialog dialog = new InAppBrowserDialog(cordova.getActivity(), android.R.style.Theme_NoTitleBar); dialog.getWindow().getAttributes().windowAnimations = android.R.style.Animation_Dialog; dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); dialog.setCancelable(true); dialog.setInAppBroswer(getInAppBrowser()); // Main container layout LinearLayout main = new LinearLayout(cordova.getActivity()); main.setOrientation(LinearLayout.VERTICAL); // Toolbar layout RelativeLayout toolbar = new RelativeLayout(cordova.getActivity()); //Please, no more black! toolbar.setBackgroundColor(android.graphics.Color.LTGRAY); toolbar.setLayoutParams( new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, this.dpToPixels(44))); toolbar.setPadding(this.dpToPixels(2), this.dpToPixels(2), this.dpToPixels(2), this.dpToPixels(2)); toolbar.setHorizontalGravity(Gravity.LEFT); toolbar.setVerticalGravity(Gravity.TOP); // Action Button Container layout RelativeLayout actionButtonContainer = new RelativeLayout(cordova.getActivity()); actionButtonContainer.setLayoutParams( new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); actionButtonContainer.setHorizontalGravity(Gravity.LEFT); actionButtonContainer.setVerticalGravity(Gravity.CENTER_VERTICAL); actionButtonContainer.setId(1); // Back button Button back = new Button(cordova.getActivity()); RelativeLayout.LayoutParams backLayoutParams = new RelativeLayout.LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT); backLayoutParams.addRule(RelativeLayout.ALIGN_LEFT); back.setLayoutParams(backLayoutParams); back.setContentDescription("Back Button"); back.setId(2); /* back.setText("<"); */ Resources activityRes = cordova.getActivity().getResources(); int backResId = activityRes.getIdentifier("ic_action_previous_item", "drawable", cordova.getActivity().getPackageName()); Drawable backIcon = activityRes.getDrawable(backResId); if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN) { back.setBackgroundDrawable(backIcon); } else { back.setBackground(backIcon); } back.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { goBack(); } }); // Forward button Button forward = new Button(cordova.getActivity()); RelativeLayout.LayoutParams forwardLayoutParams = new RelativeLayout.LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT); forwardLayoutParams.addRule(RelativeLayout.RIGHT_OF, 2); forward.setLayoutParams(forwardLayoutParams); forward.setContentDescription("Forward Button"); forward.setId(3); //forward.setText(">"); int fwdResId = activityRes.getIdentifier("ic_action_next_item", "drawable", cordova.getActivity().getPackageName()); Drawable fwdIcon = activityRes.getDrawable(fwdResId); if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN) { forward.setBackgroundDrawable(fwdIcon); } else { forward.setBackground(fwdIcon); } forward.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { goForward(); } }); // 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.setId(4); 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; } }); // Close button Button close = new Button(cordova.getActivity()); RelativeLayout.LayoutParams closeLayoutParams = new RelativeLayout.LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT); closeLayoutParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT); close.setLayoutParams(closeLayoutParams); forward.setContentDescription("Close Button"); close.setId(5); //close.setText(buttonLabel); int closeResId = activityRes.getIdentifier("ic_action_remove", "drawable", cordova.getActivity().getPackageName()); Drawable closeIcon = activityRes.getDrawable(closeResId); if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN) { close.setBackgroundDrawable(closeIcon); } else { close.setBackground(closeIcon); } close.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { closeDialog(); } }); // WebView inAppWebView = new WebView(cordova.getActivity()); inAppWebView.setLayoutParams( new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)); inAppWebView.setWebChromeClient(new InAppChromeClient(thatWebView)); WebViewClient client = new InAppBrowserClient(thatWebView, edittext); inAppWebView.setWebViewClient(client); WebSettings settings = inAppWebView.getSettings(); settings.setJavaScriptEnabled(true); settings.setJavaScriptCanOpenWindowsAutomatically(true); settings.setBuiltInZoomControls(true); settings.setPluginState(android.webkit.WebSettings.PluginState.ON); //Toggle whether this is enabled or not! Bundle appSettings = cordova.getActivity().getIntent().getExtras(); boolean enableDatabase = appSettings == null ? true : appSettings.getBoolean("InAppBrowserStorageEnabled", true); if (enableDatabase) { String databasePath = cordova.getActivity().getApplicationContext() .getDir("inAppBrowserDB", Context.MODE_PRIVATE).getPath(); settings.setDatabasePath(databasePath); settings.setDatabaseEnabled(true); } settings.setDomStorageEnabled(true); if (clearAllCache) { CookieManager.getInstance().removeAllCookie(); } else if (clearSessionCache) { CookieManager.getInstance().removeSessionCookie(); } inAppWebView.loadUrl(url); inAppWebView.setId(6); inAppWebView.getSettings().setLoadWithOverviewMode(true); inAppWebView.getSettings().setUseWideViewPort(true); inAppWebView.requestFocus(); inAppWebView.requestFocusFromTouch(); // Add the back and forward buttons to our action button container layout actionButtonContainer.addView(back); actionButtonContainer.addView(forward); // Add the views to our toolbar //toolbar.addView(actionButtonContainer); //toolbar.addView(edittext); toolbar.addView(close); // Don't add the toolbar if its been disabled if (getShowLocationBar()) { // Add our toolbar to our main view/layout main.addView(toolbar); } // Add our webview to our main view/layout 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 (openWindowHidden) { dialog.hide(); } } }; this.cordova.getActivity().runOnUiThread(runnable); return ""; }
From source file:com.hippo.widget.slidingdrawerlayout.SlidingDrawerLayout.java
@Override protected void onLayout(boolean changed, int l, int t, int r, int b) { mInLayout = true;/*from ww w . j a v a2 s . c om*/ 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(); int paddingTop = 0; int paddingBottom = mFitPaddingBottom; if (child instanceof DrawerLayoutChild) { DrawerLayoutChild dlc = (DrawerLayoutChild) child; paddingTop = dlc.getLayoutPaddingTop(); paddingBottom = dlc.getLayoutPaddingBottom() + mFitPaddingBottom; } if (child == mContentView) { child.layout(lp.leftMargin, lp.topMargin + paddingTop, lp.leftMargin + child.getMeasuredWidth(), lp.topMargin + paddingTop + child.getMeasuredHeight()); } else if (child == mShadow) { child.layout(0, 0, child.getMeasuredWidth(), 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; float percent; if (child == mLeftDrawer) { percent = mLeftPercent; childLeft = -childWidth + (int) (childWidth * percent); } else { // Right; onMeasure checked for us. percent = mRightPercent; childLeft = width - (int) (childWidth * percent); } final int vgrav = lp.gravity & Gravity.VERTICAL_GRAVITY_MASK; switch (vgrav) { default: case Gravity.TOP: { child.layout(childLeft, lp.topMargin + paddingTop, childLeft + childWidth, lp.topMargin + paddingTop + childHeight); break; } case Gravity.BOTTOM: { final int height = b - t; child.layout(childLeft, height - lp.bottomMargin - paddingBottom - child.getMeasuredHeight(), childLeft + childWidth, height - lp.bottomMargin - paddingBottom); break; } case Gravity.CENTER_VERTICAL: { final int height = b - t; int childTop = (height - childHeight - paddingTop - paddingBottom - lp.topMargin - lp.bottomMargin) / 2 + paddingTop; // Offset for margins. If things don't fit right because of // bad measurement before, oh well. if (childTop < lp.topMargin + paddingTop) { childTop = lp.topMargin + paddingTop; } else if (childTop + childHeight > height - paddingBottom - lp.bottomMargin) { childTop = height - paddingBottom - lp.bottomMargin - childHeight; } child.layout(childLeft, childTop, childLeft + childWidth, childTop + childHeight); break; } } final int newVisibility = percent > 0 ? VISIBLE : INVISIBLE; if (child.getVisibility() != newVisibility) { child.setVisibility(newVisibility); } } } mInLayout = false; }
From source file:com.sonvp.tooltip.Tooltip.java
/** * change gravity tooltip if anchorView intersect display screen *//*from w w w . j a v a2 s. co m*/ private void changeGravityToolTip() { Context context = container.getContext(); if (!(context instanceof Activity)) { return; } DisplayMetrics displayMetrics = new DisplayMetrics(); ((Activity) context).getWindowManager().getDefaultDisplay().getMetrics(displayMetrics); int displayHeight = displayMetrics.heightPixels; int displayWidth = displayMetrics.widthPixels; int displayTop = getStatusBarHeight(); int anchorTop = rectAnchorView.top; int anchorLeft = rectAnchorView.left; int anchorHeight = anchorView.getHeight(); int anchorWidth = anchorView.getWidth(); int widthMeasureSpec = View.MeasureSpec.makeMeasureSpec(displayWidth, View.MeasureSpec.AT_MOST); int heightMeasureSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED); viewTooltip.measure(widthMeasureSpec, heightMeasureSpec); int textHeight = viewTooltip.getMeasuredHeight(); // height multi line int heightToolTip = textHeight + // with Gravity is Top and Bottom (int) builder.arrowHeight + (int) builder.topPadding + (int) builder.bottomPadding + (int) builder.toolTipMargin; int textWidth = viewTooltip.getMeasuredHeight(); int widthToolTip = textWidth + // with Gravity is Left and Right (int) builder.arrowWidth + (int) builder.leftPadding + (int) builder.rightPadding + (int) builder.toolTipMargin; switch (gravity) { case Gravity.LEFT: if (!(viewTooltip instanceof TextView)) { if (anchorLeft < widthToolTip) { if (anchorTop > heightToolTip) { gravity = Gravity.TOP; } else { gravity = Gravity.BOTTOM; } } } case Gravity.RIGHT: if (!(viewTooltip instanceof TextView)) { int anchorRight = anchorLeft + anchorWidth; if (anchorRight + widthToolTip > displayWidth) { if (anchorTop > heightToolTip) { gravity = Gravity.TOP; } else { gravity = Gravity.BOTTOM; } } } default: // with Gravity is Left and Right int anchorVerticalCenter = anchorTop + anchorHeight / 2; int bottomArrow = anchorVerticalCenter + (int) builder.arrowHeight / 2; int topArrow = anchorVerticalCenter - (int) builder.arrowHeight / 2; if (bottomArrow + builder.radius + builder.toolTipMargin > displayHeight) { gravity = Gravity.TOP; } else if (topArrow < getStatusBarHeight() + builder.radius + builder.toolTipMargin) { gravity = Gravity.BOTTOM; } break; case Gravity.TOP: if (anchorTop - displayTop < heightToolTip) { gravity = Gravity.BOTTOM; } break; case Gravity.BOTTOM: int anchorBottom = displayHeight - (anchorTop + anchorHeight); if (anchorBottom < heightToolTip) { gravity = Gravity.TOP; } break; } }
From source file:com.goftagram.telegram.ui.Components.PasscodeView.java
public PasscodeView(final Context context) { super(context); setWillNotDraw(false);//from ww w. j a v a 2s .c om setVisibility(GONE); backgroundFrameLayout = new FrameLayout(context); addView(backgroundFrameLayout); LayoutParams layoutParams = (LayoutParams) backgroundFrameLayout.getLayoutParams(); layoutParams.width = LayoutHelper.MATCH_PARENT; layoutParams.height = LayoutHelper.MATCH_PARENT; backgroundFrameLayout.setLayoutParams(layoutParams); passwordFrameLayout = new FrameLayout(context); addView(passwordFrameLayout); layoutParams = (LayoutParams) passwordFrameLayout.getLayoutParams(); layoutParams.width = LayoutHelper.MATCH_PARENT; layoutParams.height = LayoutHelper.MATCH_PARENT; layoutParams.gravity = Gravity.TOP | Gravity.LEFT; passwordFrameLayout.setLayoutParams(layoutParams); ImageView imageView = new ImageView(context); imageView.setScaleType(ImageView.ScaleType.FIT_XY); imageView.setImageResource(R.drawable.passcode_logo); passwordFrameLayout.addView(imageView); layoutParams = (LayoutParams) imageView.getLayoutParams(); if (AndroidUtilities.density < 1) { layoutParams.width = AndroidUtilities.dp(30); layoutParams.height = AndroidUtilities.dp(30); } else { layoutParams.width = AndroidUtilities.dp(40); layoutParams.height = AndroidUtilities.dp(40); } layoutParams.gravity = Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM; layoutParams.bottomMargin = AndroidUtilities.dp(100); imageView.setLayoutParams(layoutParams); passcodeTextView = new TextView(context); passcodeTextView.setTextColor(0xffffffff); passcodeTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14); passcodeTextView.setGravity(Gravity.CENTER_HORIZONTAL); passwordFrameLayout.addView(passcodeTextView); layoutParams = (LayoutParams) passcodeTextView.getLayoutParams(); layoutParams.width = LayoutHelper.WRAP_CONTENT; layoutParams.height = LayoutHelper.WRAP_CONTENT; layoutParams.bottomMargin = AndroidUtilities.dp(62); layoutParams.gravity = Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL; passcodeTextView.setLayoutParams(layoutParams); passwordEditText2 = new AnimatingTextView(context); passwordFrameLayout.addView(passwordEditText2); layoutParams = (FrameLayout.LayoutParams) passwordEditText2.getLayoutParams(); layoutParams.height = LayoutHelper.WRAP_CONTENT; layoutParams.width = LayoutHelper.MATCH_PARENT; layoutParams.leftMargin = AndroidUtilities.dp(70); layoutParams.rightMargin = AndroidUtilities.dp(70); layoutParams.bottomMargin = AndroidUtilities.dp(6); layoutParams.gravity = Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL; passwordEditText2.setLayoutParams(layoutParams); passwordEditText = new EditText(context); passwordEditText.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 36); passwordEditText.setTextColor(0xffffffff); passwordEditText.setMaxLines(1); passwordEditText.setLines(1); passwordEditText.setGravity(Gravity.CENTER_HORIZONTAL); passwordEditText.setSingleLine(true); passwordEditText.setImeOptions(EditorInfo.IME_ACTION_DONE); passwordEditText.setTypeface(Typeface.DEFAULT); passwordEditText.setBackgroundDrawable(null); AndroidUtilities.clearCursorDrawable(passwordEditText); passwordFrameLayout.addView(passwordEditText); layoutParams = (FrameLayout.LayoutParams) passwordEditText.getLayoutParams(); layoutParams.height = LayoutHelper.WRAP_CONTENT; layoutParams.width = LayoutHelper.MATCH_PARENT; layoutParams.leftMargin = AndroidUtilities.dp(70); layoutParams.rightMargin = AndroidUtilities.dp(70); layoutParams.bottomMargin = AndroidUtilities.dp(6); layoutParams.gravity = Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL; passwordEditText.setLayoutParams(layoutParams); passwordEditText.setOnEditorActionListener(new TextView.OnEditorActionListener() { @Override public boolean onEditorAction(TextView textView, int i, KeyEvent keyEvent) { if (i == EditorInfo.IME_ACTION_DONE) { processDone(false); return true; } return false; } }); passwordEditText.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { } @Override public void afterTextChanged(Editable s) { if (passwordEditText.length() == 4 && UserConfig.passcodeType == 0) { processDone(false); } } }); if (android.os.Build.VERSION.SDK_INT < 11) { passwordEditText.setOnCreateContextMenuListener(new View.OnCreateContextMenuListener() { public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) { menu.clear(); } }); } else { passwordEditText.setCustomSelectionActionModeCallback(new ActionMode.Callback() { public boolean onPrepareActionMode(ActionMode mode, Menu menu) { return false; } public void onDestroyActionMode(ActionMode mode) { } public boolean onCreateActionMode(ActionMode mode, Menu menu) { return false; } public boolean onActionItemClicked(ActionMode mode, MenuItem item) { return false; } }); } checkImage = new ImageView(context); checkImage.setImageResource(R.drawable.passcode_check); checkImage.setScaleType(ImageView.ScaleType.CENTER); checkImage.setBackgroundResource(R.drawable.bar_selector_lock); passwordFrameLayout.addView(checkImage); layoutParams = (LayoutParams) checkImage.getLayoutParams(); layoutParams.width = AndroidUtilities.dp(60); layoutParams.height = AndroidUtilities.dp(60); layoutParams.bottomMargin = AndroidUtilities.dp(4); layoutParams.rightMargin = AndroidUtilities.dp(10); layoutParams.gravity = Gravity.BOTTOM | Gravity.RIGHT; checkImage.setLayoutParams(layoutParams); checkImage.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { processDone(false); } }); FrameLayout lineFrameLayout = new FrameLayout(context); lineFrameLayout.setBackgroundColor(0x26ffffff); passwordFrameLayout.addView(lineFrameLayout); layoutParams = (LayoutParams) lineFrameLayout.getLayoutParams(); layoutParams.width = LayoutHelper.MATCH_PARENT; layoutParams.height = AndroidUtilities.dp(1); layoutParams.gravity = Gravity.BOTTOM | Gravity.LEFT; layoutParams.leftMargin = AndroidUtilities.dp(20); layoutParams.rightMargin = AndroidUtilities.dp(20); lineFrameLayout.setLayoutParams(layoutParams); numbersFrameLayout = new FrameLayout(context); addView(numbersFrameLayout); layoutParams = (LayoutParams) numbersFrameLayout.getLayoutParams(); layoutParams.width = LayoutHelper.MATCH_PARENT; layoutParams.height = LayoutHelper.MATCH_PARENT; layoutParams.gravity = Gravity.TOP | Gravity.LEFT; numbersFrameLayout.setLayoutParams(layoutParams); lettersTextViews = new ArrayList<>(10); numberTextViews = new ArrayList<>(10); numberFrameLayouts = new ArrayList<>(10); for (int a = 0; a < 10; a++) { TextView textView = new TextView(context); textView.setTextColor(0xffffffff); textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 36); textView.setGravity(Gravity.CENTER); textView.setText(String.format(Locale.US, "%d", a)); numbersFrameLayout.addView(textView); layoutParams = (LayoutParams) textView.getLayoutParams(); layoutParams.width = AndroidUtilities.dp(50); layoutParams.height = AndroidUtilities.dp(50); layoutParams.gravity = Gravity.TOP | Gravity.LEFT; textView.setLayoutParams(layoutParams); numberTextViews.add(textView); textView = new TextView(context); textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 12); textView.setTextColor(0x7fffffff); textView.setGravity(Gravity.CENTER); numbersFrameLayout.addView(textView); layoutParams = (LayoutParams) textView.getLayoutParams(); layoutParams.width = AndroidUtilities.dp(50); layoutParams.height = AndroidUtilities.dp(20); layoutParams.gravity = Gravity.TOP | Gravity.LEFT; textView.setLayoutParams(layoutParams); switch (a) { case 0: textView.setText("+"); break; case 2: textView.setText("ABC"); break; case 3: textView.setText("DEF"); break; case 4: textView.setText("GHI"); break; case 5: textView.setText("JKL"); break; case 6: textView.setText("MNO"); break; case 7: textView.setText("PQRS"); break; case 8: textView.setText("TUV"); break; case 9: textView.setText("WXYZ"); break; default: break; } lettersTextViews.add(textView); } eraseView = new ImageView(context); eraseView.setScaleType(ImageView.ScaleType.CENTER); eraseView.setImageResource(R.drawable.passcode_delete); numbersFrameLayout.addView(eraseView); layoutParams = (LayoutParams) eraseView.getLayoutParams(); layoutParams.width = AndroidUtilities.dp(50); layoutParams.height = AndroidUtilities.dp(50); layoutParams.gravity = Gravity.TOP | Gravity.LEFT; eraseView.setLayoutParams(layoutParams); for (int a = 0; a < 11; a++) { FrameLayout frameLayout = new FrameLayout(context); frameLayout.setBackgroundResource(R.drawable.bar_selector_lock); frameLayout.setTag(a); if (a == 10) { frameLayout.setOnLongClickListener(new OnLongClickListener() { @Override public boolean onLongClick(View v) { passwordEditText.setText(""); passwordEditText2.eraseAllCharacters(true); return true; } }); } frameLayout.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { int tag = (Integer) v.getTag(); switch (tag) { case 0: passwordEditText2.appendCharacter("0"); break; case 1: passwordEditText2.appendCharacter("1"); break; case 2: passwordEditText2.appendCharacter("2"); break; case 3: passwordEditText2.appendCharacter("3"); break; case 4: passwordEditText2.appendCharacter("4"); break; case 5: passwordEditText2.appendCharacter("5"); break; case 6: passwordEditText2.appendCharacter("6"); break; case 7: passwordEditText2.appendCharacter("7"); break; case 8: passwordEditText2.appendCharacter("8"); break; case 9: passwordEditText2.appendCharacter("9"); break; case 10: passwordEditText2.eraseLastCharacter(); break; } if (passwordEditText2.lenght() == 4) { processDone(false); } } }); numberFrameLayouts.add(frameLayout); } for (int a = 10; a >= 0; a--) { FrameLayout frameLayout = numberFrameLayouts.get(a); numbersFrameLayout.addView(frameLayout); layoutParams = (LayoutParams) frameLayout.getLayoutParams(); layoutParams.width = AndroidUtilities.dp(100); layoutParams.height = AndroidUtilities.dp(100); layoutParams.gravity = Gravity.TOP | Gravity.LEFT; frameLayout.setLayoutParams(layoutParams); } }
From source file:com.actionbarsherlock.custom.widget.VerticalDrawerLayout.java
/** * Simple gravity to string - only supports TOP and BOTTOM for debugging output. * * @param gravity Absolute gravity value * @return TOP or BOTTOM as appropriate, or a hex string */// w ww. ja va 2 s .co m static String gravityToString(int gravity) { if ((gravity & Gravity.TOP) == Gravity.TOP) { return "TOP"; } if ((gravity & Gravity.BOTTOM) == Gravity.BOTTOM) { return "BOTTOM"; } return Integer.toHexString(gravity); }
From source file:ca.nehil.rter.streamingapp2.StreamingActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Orientation listenever implementation myOrientationEventListener = new OrientationEventListener(this, SensorManager.SENSOR_DELAY_NORMAL) { @Override/*from w w w . j av a2s. c o m*/ public void onOrientationChanged(int orientation) { int rotation = getWindowManager().getDefaultDisplay().getRotation(); if (rotation == Surface.ROTATION_270) { flipVideo = true; } else { flipVideo = false; } } }; myOrientationEventListener.enable(); // stopService(new Intent(StreamingActivity.this, // BackgroundService.class)); Log.e(TAG, "onCreate"); AndroidId = Settings.Secure.getString(getContentResolver(), Settings.Secure.ANDROID_ID); frameInfo = new FrameInfo(); // openGL overlay overlay = new OverlayController(this); // orientation mSensorManager = (SensorManager) getSystemService(SENSOR_SERVICE); mAcc = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER); mMag = mSensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD); //setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); setContentView(R.layout.activity_streaming); // Find the total number of cameras available numberOfCameras = Camera.getNumberOfCameras(); cookies = getSharedPreferences("RterUserCreds", MODE_PRIVATE); prefEditor = cookies.edit(); setUsername = cookies.getString("Username", "not-set"); setRterCredentials = cookies.getString("RterCreds", "not-set"); if (setRterCredentials.equalsIgnoreCase("not-set") || setRterCredentials == null) { Log.e("PREFS", "Login Not successful, please restart"); } Log.d("PREFS", "Prefs ==> rter_Creds:" + setRterCredentials); // Get the location manager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); // Define the criteria how to select the location provider -> use // default if (!locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) { Log.e(TAG, "GPS not available"); } Criteria criteria = new Criteria(); provider = locationManager.getBestProvider(criteria, true); Log.d(TAG, "Requesting location"); locationManager.requestLocationUpdates(provider, 0, 1, this); // register the overlay control for location updates as well, so we get // the geomagnetic field locationManager.requestLocationUpdates(provider, 0, 1000, overlay); if (provider != null) { Location location = locationManager.getLastKnownLocation(provider); // Initialize the location fields if (location != null) { System.out.println("Provider " + provider + " has been selected. and location " + location); onLocationChanged(location); } else { Toast toast = Toast.makeText(this, "Location not available", Toast.LENGTH_LONG); toast.setGravity(Gravity.TOP, 0, 0); toast.show(); lati = (float) (45.505958f); longi = (float) (-73.576254f); Log.d(TAG, "Location not available"); } } // power manager PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); mWakeLock = pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK, CLASS_LABEL); mWakeLock.acquire(); // test, set desired orienation to north overlay.letFreeRoam(false); overlay.setDesiredOrientation(0.0f); // CharSequence text = "Tap to start.."; // int duration = Toast.LENGTH_SHORT; // // Toast toast = Toast.makeText(this, text, duration); // toast.setGravity(Gravity.TOP|Gravity.RIGHT, 0, 0); // toast.show(); }
From source file:com.actionbarsherlock.custom.widget.VerticalDrawerLayout.java
void moveDrawerToOffset(View drawerView, float slideOffset) { final float oldOffset = getDrawerViewOffset(drawerView); final int height = drawerView.getHeight(); final int oldPos = (int) (height * oldOffset); final int newPos = (int) (height * slideOffset); final int dx = newPos - oldPos; drawerView.offsetTopAndBottom(checkDrawerViewGravity(drawerView, Gravity.TOP) ? dx : -dx); setDrawerViewOffset(drawerView, slideOffset); }
From source file:com.htc.dotdesign.ToolBoxService.java
private void initDragButton() { //Initialize drag button if (mDragButton != null) { mCurrFuncIcon = (ImageView) mDragButton.findViewById(R.id.curr_func_icon); if (mDragBtnColorIcon != null) { mDragBtnColorIcon.setColor(mCurrBrushColor); mCurrFuncIcon.setBackground(mDragBtnColorIcon); }// ww w. j a va 2 s . co m mDragButton.setOnTouchListener(new OnTouchListener() { //private int initialX; private int initialY; private float initialTouchX; private float initialTouchY; private boolean mIsMoving = false; private boolean mIsTryMoving = false; @Override public boolean onTouch(View v, MotionEvent event) { Log.d(DotDesignConstants.LOG_TAG, LOG_PREFIX + "onTouch"); switch (event.getAction()) { case MotionEvent.ACTION_DOWN: Log.d(DotDesignConstants.LOG_TAG, LOG_PREFIX + "onTouch, ACTION_DOWN"); //initialX = mDragButtonParams.x; initialY = mDragButtonParams.y; initialTouchX = event.getRawX(); initialTouchY = event.getRawY(); break; case MotionEvent.ACTION_UP: Log.d(DotDesignConstants.LOG_TAG, LOG_PREFIX + "onTouch, ACTION_UP"); if (!mIsMoving && !mIsTryMoving) { if (!mbIsAnimationPlaying) { if (mIsToolBarOpen) { if (mIsToolBarExtend) { setToolPanelVisibility(false); } else { mToolBar.clearAnimation(); if (mCurrLayoutMode == LayoutMode.LEFT_SIDE) { playAnimation(mToolBar, mLeftOut); } else if (mCurrLayoutMode == LayoutMode.RIGHT_SIDE) { playAnimation(mToolBar, mRightOut); } } } else { if (mCurrLayoutMode == LayoutMode.LEFT_SIDE) { mToolBarParams.gravity = Gravity.START; } else if (mCurrLayoutMode == LayoutMode.RIGHT_SIDE) { mToolBarParams.gravity = Gravity.END; } mToolBarParams.gravity = Gravity.TOP | mToolBarParams.gravity; mToolBarParams.x = 0; mToolBarParams.y = mDragButtonParams.y; mWindowManager.updateViewLayout(mToolBarParent, mToolBarParams); mToolBarParent.setVisibility(View.VISIBLE); mToolBar.clearAnimation(); mToolBar.setVisibility(View.VISIBLE); if (mCurrLayoutMode == LayoutMode.LEFT_SIDE) { playAnimation(mToolBar, mLeftIn); } else if (mCurrLayoutMode == LayoutMode.RIGHT_SIDE) { playAnimation(mToolBar, mRightIn); } } } } else { mIsTryMoving = false; mIsMoving = false; /*if (mDragButtonParams.x <= mScreenWidth / 2) { mDragButtonParams.x = 0; mWindowManager.updateViewLayout(mDragButton, mDragButtonParams); mCurrLayoutMode = LayoutMode.LEFT_SIDE; } else { mDragButtonParams.x = mScreenWidth - mDragButtonWidth; mWindowManager.updateViewLayout(mDragButton, mDragButtonParams); mCurrLayoutMode = LayoutMode.RIGHT_SIDE; }*/ } // mDragButton.setBackgroundResource(R.drawable.floating2); break; case MotionEvent.ACTION_MOVE: Log.d(DotDesignConstants.LOG_TAG, LOG_PREFIX + "onTouch, ACTION_MOVE, mToolBox.getHeight()" + mToolBar.getHeight()); if (Math.abs(event.getRawX() - initialTouchX) > 10 || Math.abs(event.getRawY() - initialTouchY) > 10) { mIsTryMoving = true; } if (/*!mIsToolBarExtend && */mIsTryMoving) { mIsMoving = true; // paramsF.x = initialX + (int) (event.getRawX() - initialTouchX); mDragButtonParams.y = initialY + (int) (event.getRawY() - initialTouchY); if (mDragButtonParams.y < 0) { mDragButtonParams.y = 0; } else if (mDragButtonParams.y > mScreenHeight - mDragButtonHeight) { mDragButtonParams.y = mScreenHeight - mDragButtonHeight; } mWindowManager.updateViewLayout(mDragButton, mDragButtonParams); // mDragButton.setBackgroundResource(R.drawable.ic_launcher); if (mIsToolBarOpen) { mToolBarParams.y = mDragButtonParams.y; mWindowManager.updateViewLayout(mToolBarParent, mToolBarParams); } if (mIsToolBarExtend) { setToolPanelVisibility(false); } } break; } return true; } }); } }