List of usage examples for android.view Gravity LEFT
int LEFT
To view the source code for android.view Gravity LEFT.
Click Source Link
From source file:com.klinker.android.launcher.addons.view.LauncherDrawerLayout.java
@Override protected boolean drawChild(Canvas canvas, View child, long drawingTime) { final int height = getHeight(); final boolean drawingContent = isContentView(child); int clipLeft = 0, clipRight = getWidth(); final int restoreCount = canvas.save(); if (drawingContent) { final int childCount = getChildCount(); for (int i = 0; i < childCount; i++) { final View v = getChildAt(i); if (v == child || v.getVisibility() != VISIBLE || !hasOpaqueBackground(v) || !isDrawerView(v) || v.getHeight() < height) { continue; }/* w ww.j a v a 2 s . c o m*/ if (checkDrawerViewAbsoluteGravity(v, Gravity.LEFT)) { final int vright = v.getRight(); if (vright > clipLeft) clipLeft = vright; } else { final int vleft = v.getLeft(); if (vleft < clipRight) clipRight = vleft; } } canvas.clipRect(clipLeft, 0, clipRight, getHeight()); } final boolean result = super.drawChild(canvas, child, drawingTime); canvas.restoreToCount(restoreCount); if (mScrimOpacity > 0 && drawingContent) { final int baseAlpha = (mScrimColor & 0xff000000) >>> 24; final int imag = (int) (baseAlpha * mScrimOpacity); final int color = imag << 24 | (mScrimColor & 0xffffff); mScrimPaint.setColor(color); canvas.drawRect(clipLeft, 0, clipRight, getHeight(), mScrimPaint); } else if (mShadowLeft != null && checkDrawerViewAbsoluteGravity(child, Gravity.LEFT)) { final int shadowWidth = mShadowLeft.getIntrinsicWidth(); final int childRight = child.getRight(); final int drawerPeekDistance = mLeftDragger.getEdgeSize(); final float alpha = Math.max(0, Math.min((float) childRight / drawerPeekDistance, 1.f)); mShadowLeft.setBounds(childRight, child.getTop(), childRight + shadowWidth, child.getBottom()); mShadowLeft.setAlpha((int) (0xff * alpha)); mShadowLeft.draw(canvas); } else if (mShadowRight != null && checkDrawerViewAbsoluteGravity(child, Gravity.RIGHT)) { final int shadowWidth = mShadowRight.getIntrinsicWidth(); final int childLeft = child.getLeft(); final int showing = getWidth() - childLeft; final int drawerPeekDistance = mRightDragger.getEdgeSize(); final float alpha = Math.max(0, Math.min((float) showing / drawerPeekDistance, 1.f)); mShadowRight.setBounds(childLeft - shadowWidth, child.getTop(), childLeft, child.getBottom()); mShadowRight.setAlpha((int) (0xff * alpha)); mShadowRight.draw(canvas); } return result; }
From source file:ca.co.rufus.androidboilerplate.ui.DebugDrawerLayout.java
@Override protected void onLayout(boolean changed, int l, int t, int r, int b) { mInLayout = true;/* ww w.j av 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(); 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:org.linphone.LinphoneService.java
void addFloatingWindows() { view = LayoutInflater.from(this).inflate(R.layout.callingactivity, null); windowManager = (WindowManager) this.getSystemService(WINDOW_SERVICE); /*/*from w ww. j av a 2 s . c o m*/ * LayoutParams.TYPE_SYSTEM_ERRORView * LayoutParams.FLAG_NOT_FOCUSABLE: * PixelFormat.TRANSPARENT */ LayoutParams layoutParams = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT, LayoutParams.TYPE_SYSTEM_ERROR, LayoutParams.FLAG_NOT_FOCUSABLE, PixelFormat.TRANSPARENT); // layoutParams.gravity = Gravity.RIGHT|Gravity.BOTTOM; // layoutParams.gravity = Gravity.LEFT | Gravity.TOP; layoutParams.type = WindowManager.LayoutParams.TYPE_SYSTEM_ALERT; final Button Answer = (Button) view.findViewById(R.id.buttonAnswer); Answer.setVisibility(View.VISIBLE); Answer.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { LinphoneCore lLinphoneCore = LinphoneService.instance().getLinphoneCore(); if (lLinphoneCore.isInComingInvitePending()) { try { lLinphoneCore.acceptCall(lLinphoneCore.getCurrentCall()); Answer.setVisibility(View.GONE); } catch (LinphoneCoreException e) { lLinphoneCore.terminateCall(lLinphoneCore.getCurrentCall()); // Toast toast = Toast.makeText(DialerActivity.this // ,String.format(getString(R.string.warning_wrong_destination_address),mAddress.getText().toString()) // ,Toast.LENGTH_LONG); // toast.show(); // finish(); } return; } } }); Button guaDuanDianhua = (Button) view.findViewById(R.id.buttonGuaDuanDianhua); guaDuanDianhua.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // LinphoneCore lLinphoneCore = LinphoneService.instance() // .getLinphoneCore(); // lLinphoneCore.terminateCall(lLinphoneCore.getCurrentCall()); // Intent intent = new Intent(); // intent.setClass(CallingActivity.this, CallEndActivity.class); // startActivity(intent); // finish(); try { Log.i("mayingcai", "classType: "); Class classType = Class.forName("com.android.internal.telephony.ITelephony"); Log.i("mayingcai", "classType: 1"); Object invokeTester = classType.newInstance(); Log.i("mayingcai", "classType: 2"); Method addMethod = classType.getMethod("endCall", null); Log.i("mayingcai", "classType: 3"); addMethod.invoke(invokeTester); Log.i("mayingcai", "classType: 4"); } catch (Exception e) { // TODO Auto-generated catch block Log.i("mayingcai", "classType: 5"); e.printStackTrace(); } } }); windowManager.addView(view, layoutParams); }
From source file:com.android.calendar.EventInfoFragment.java
private void applyDialogParams() { Dialog dialog = getDialog();/*from w w w .ja v a2s . c om*/ dialog.setCanceledOnTouchOutside(true); Window window = dialog.getWindow(); window.addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND); WindowManager.LayoutParams a = window.getAttributes(); a.dimAmount = .4f; a.width = mDialogWidth; a.height = mDialogHeight; // On tablets , do smart positioning of dialog // On phones , use the whole screen if (mX != -1 || mY != -1) { a.x = mX - mDialogWidth / 2; a.y = mY - mDialogHeight / 2; if (a.y < mMinTop) { a.y = mMinTop + DIALOG_TOP_MARGIN; } a.gravity = Gravity.LEFT | Gravity.TOP; } window.setAttributes(a); }
From source file:com.nickandjerry.dynamiclayoutinflator.DynamicLayoutInflator.java
public static void createViewRunnables() { viewRunnables = new HashMap<>(30); viewRunnables.put("scaleType", new ViewParamRunnable() { @Override/*w w w .j av a2 s .c o m*/ public void apply(View view, String value, ViewGroup parent, Map<String, String> attrs) { if (view instanceof ImageView) { ImageView.ScaleType scaleType = ((ImageView) view).getScaleType(); switch (value.toLowerCase()) { case "center": scaleType = ImageView.ScaleType.CENTER; break; case "center_crop": scaleType = ImageView.ScaleType.CENTER_CROP; break; case "center_inside": scaleType = ImageView.ScaleType.CENTER_INSIDE; break; case "fit_center": scaleType = ImageView.ScaleType.FIT_CENTER; break; case "fit_end": scaleType = ImageView.ScaleType.FIT_END; break; case "fit_start": scaleType = ImageView.ScaleType.FIT_START; break; case "fit_xy": scaleType = ImageView.ScaleType.FIT_XY; break; case "matrix": scaleType = ImageView.ScaleType.MATRIX; break; } ((ImageView) view).setScaleType(scaleType); } } }); viewRunnables.put("orientation", new ViewParamRunnable() { @Override public void apply(View view, String value, ViewGroup parent, Map<String, String> attrs) { if (view instanceof LinearLayout) { ((LinearLayout) view).setOrientation( value.equals("vertical") ? LinearLayout.VERTICAL : LinearLayout.HORIZONTAL); } } }); viewRunnables.put("text", new ViewParamRunnable() { @Override public void apply(View view, String value, ViewGroup parent, Map<String, String> attrs) { if (view instanceof TextView) { ((TextView) view).setText(value); } } }); viewRunnables.put("textSize", new ViewParamRunnable() { @Override public void apply(View view, String value, ViewGroup parent, Map<String, String> attrs) { if (view instanceof TextView) { ((TextView) view).setTextSize(TypedValue.COMPLEX_UNIT_PX, DimensionConverter.stringToDimension(value, view.getResources().getDisplayMetrics())); } } }); viewRunnables.put("textColor", new ViewParamRunnable() { @Override public void apply(View view, String value, ViewGroup parent, Map<String, String> attrs) { if (view instanceof TextView) { ((TextView) view).setTextColor(parseColor(view, value)); } } }); viewRunnables.put("textStyle", new ViewParamRunnable() { @Override public void apply(View view, String value, ViewGroup parent, Map<String, String> attrs) { if (view instanceof TextView) { int typeFace = Typeface.NORMAL; if (value.contains("bold")) typeFace |= Typeface.BOLD; else if (value.contains("italic")) typeFace |= Typeface.ITALIC; ((TextView) view).setTypeface(null, typeFace); } } }); viewRunnables.put("textAlignment", new ViewParamRunnable() { @Override public void apply(View view, String value, ViewGroup parent, Map<String, String> attrs) { if (Build.VERSION.SDK_INT > Build.VERSION_CODES.KITKAT) { int alignment = View.TEXT_ALIGNMENT_TEXT_START; switch (value) { case "center": alignment = View.TEXT_ALIGNMENT_CENTER; break; case "left": case "textStart": break; case "right": case "textEnd": alignment = View.TEXT_ALIGNMENT_TEXT_END; break; } view.setTextAlignment(alignment); } else { int gravity = Gravity.LEFT; switch (value) { case "center": gravity = Gravity.CENTER; break; case "left": case "textStart": break; case "right": case "textEnd": gravity = Gravity.RIGHT; break; } ((TextView) view).setGravity(gravity); } } }); viewRunnables.put("ellipsize", new ViewParamRunnable() { @Override public void apply(View view, String value, ViewGroup parent, Map<String, String> attrs) { if (view instanceof TextView) { TextUtils.TruncateAt where = TextUtils.TruncateAt.END; switch (value) { case "start": where = TextUtils.TruncateAt.START; break; case "middle": where = TextUtils.TruncateAt.MIDDLE; break; case "marquee": where = TextUtils.TruncateAt.MARQUEE; break; case "end": break; } ((TextView) view).setEllipsize(where); } } }); viewRunnables.put("singleLine", new ViewParamRunnable() { @Override public void apply(View view, String value, ViewGroup parent, Map<String, String> attrs) { if (view instanceof TextView) { ((TextView) view).setSingleLine(); } } }); viewRunnables.put("hint", new ViewParamRunnable() { @Override public void apply(View view, String value, ViewGroup parent, Map<String, String> attrs) { if (view instanceof EditText) { ((EditText) view).setHint(value); } } }); viewRunnables.put("inputType", new ViewParamRunnable() { @Override public void apply(View view, String value, ViewGroup parent, Map<String, String> attrs) { if (view instanceof TextView) { int inputType = 0; switch (value) { case "textEmailAddress": inputType |= InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS; break; case "number": inputType |= InputType.TYPE_CLASS_NUMBER; break; case "phone": inputType |= InputType.TYPE_CLASS_PHONE; break; } if (inputType > 0) ((TextView) view).setInputType(inputType); } } }); viewRunnables.put("gravity", new ViewParamRunnable() { @Override public void apply(View view, String value, ViewGroup parent, Map<String, String> attrs) { int gravity = parseGravity(value); if (view instanceof TextView) { ((TextView) view).setGravity(gravity); } else if (view instanceof LinearLayout) { ((LinearLayout) view).setGravity(gravity); } else if (view instanceof RelativeLayout) { ((RelativeLayout) view).setGravity(gravity); } } }); viewRunnables.put("src", new ViewParamRunnable() { @Override public void apply(View view, String value, ViewGroup parent, Map<String, String> attrs) { if (view instanceof ImageView) { String imageName = value; if (imageName.startsWith("//")) imageName = "http:" + imageName; if (imageName.startsWith("http")) { if (imageLoader != null) { if (attrs.containsKey("cornerRadius")) { int radius = DimensionConverter.stringToDimensionPixelSize( attrs.get("cornerRadius"), view.getResources().getDisplayMetrics()); imageLoader.loadRoundedImage((ImageView) view, imageName, radius); } else { imageLoader.loadImage((ImageView) view, imageName); } } } else if (imageName.startsWith("@drawable/")) { imageName = imageName.substring("@drawable/".length()); ((ImageView) view).setImageDrawable(getDrawableByName(view, imageName)); } } } }); viewRunnables.put("visibility", new ViewParamRunnable() { @Override public void apply(View view, String value, ViewGroup parent, Map<String, String> attrs) { int visibility = View.VISIBLE; String visValue = value.toLowerCase(); if (visValue.equals("gone")) visibility = View.GONE; else if (visValue.equals("invisible")) visibility = View.INVISIBLE; view.setVisibility(visibility); } }); viewRunnables.put("clickable", new ViewParamRunnable() { @Override public void apply(View view, String value, ViewGroup parent, Map<String, String> attrs) { view.setClickable(value.equals("true")); } }); viewRunnables.put("tag", new ViewParamRunnable() { @Override public void apply(View view, String value, ViewGroup parent, Map<String, String> attrs) { // Sigh, this is dangerous because we use tags for other purposes if (view.getTag() == null) view.setTag(value); } }); viewRunnables.put("onClick", new ViewParamRunnable() { @Override public void apply(View view, String value, ViewGroup parent, Map<String, String> attrs) { view.setOnClickListener(getClickListener(parent, value)); } }); }
From source file:com.klinker.android.launcher.addons.view.LauncherDrawerLayout.java
@Override public boolean onInterceptTouchEvent(MotionEvent ev) { final int action = MotionEventCompat.getActionMasked(ev); // "|" used deliberately here; both methods should be invoked. final boolean interceptForDrag = !isDrawerOpen(Gravity.LEFT) ? (mLeftDragger.shouldInterceptTouchEvent(ev) | mRightDragger.shouldInterceptTouchEvent(ev)) : mLeftDragger.shouldInterceptTouchEvent(ev); if (DEBUG) {/*from w ww.j a va2 s . c o m*/ Log.v("intercept_drag", "intercepting: " + interceptForDrag); } boolean interceptForTap = false; boolean draggedLeft = false; boolean draggedRight = false; switch (action) { case MotionEvent.ACTION_DOWN: { final float x = ev.getX(); final float y = ev.getY(); mInitialMotionX = x; mInitialMotionY = y; if (mScrimOpacity > 0 && isContentView(mLeftDragger.findTopChildUnder((int) x, (int) y))) { interceptForTap = true; } mDisallowInterceptRequested = false; mChildrenCanceledTouch = false; break; } case MotionEvent.ACTION_MOVE: { // If we cross the touch slop, don't perform the delayed peek for an edge touch. if (mLeftDragger.checkTouchSlop(ViewDragHelper.DIRECTION_ALL)) { mLeftCallback.removeCallbacks(); mRightCallback.removeCallbacks(); } float x = ev.getX(); float dx = mInitialMotionX - x; float y = ev.getY(); float dy = mInitialMotionY - y; float slope = Math.abs(dy / dx); if (slope >= 2) { return false; } if (dx >= 5) { draggedLeft = true; } if (dx <= -5) { draggedRight = true; } break; } case MotionEvent.ACTION_CANCEL: case MotionEvent.ACTION_UP: { closeDrawers(true); mDisallowInterceptRequested = false; mChildrenCanceledTouch = false; } } interceptForTap = false; if (!isDrawerOpen(Gravity.LEFT)) { return interceptForDrag || interceptForTap || hasPeekingDrawer() || mChildrenCanceledTouch; } else { Point displaySize = new Point(); ((Activity) getContext()).getWindowManager().getDefaultDisplay().getSize(displaySize); if (mInitialMotionX > displaySize.x * .95) { return interceptForDrag || interceptForTap || hasPeekingDrawer() || mChildrenCanceledTouch; } else { if (draggedLeft && currentDrawerPage == maxDrawerPage) { return true; } else { return false; } } } }
From source file:com.goftagram.telegram.ui.Components.EmojiView.java
public EmojiView(boolean needStickers, Context context) { super(context); showStickers = needStickers;//w w w . j a v a 2 s. co m for (int i = 0; i < EmojiData.dataColored.length + 1; i++) { GridView gridView = new GridView(context); if (AndroidUtilities.isTablet()) { gridView.setColumnWidth(AndroidUtilities.dp(60)); } else { gridView.setColumnWidth(AndroidUtilities.dp(45)); } gridView.setNumColumns(-1); views.add(gridView); EmojiGridAdapter emojiGridAdapter = new EmojiGridAdapter(i - 1); gridView.setAdapter(emojiGridAdapter); AndroidUtilities.setListViewEdgeEffectColor(gridView, 0xfff5f6f7); adapters.add(emojiGridAdapter); } if (showStickers) { StickersQuery.checkStickers(); stickersGridView = new GridView(context) { @Override public boolean onInterceptTouchEvent(MotionEvent event) { if (event.getAction() == MotionEvent.ACTION_DOWN) { int x = (int) event.getX(); int y = (int) event.getY(); int count = stickersGridView.getChildCount(); for (int a = 0; a < count; a++) { View view = stickersGridView.getChildAt(a); int top = view.getTop(); int bottom = view.getBottom(); int left = view.getLeft(); int right = view.getRight(); if (top > y || bottom < y || left > x || right < x) { continue; } if (!(view instanceof StickerEmojiCell) || !((StickerEmojiCell) view).showingBitmap()) { return super.onInterceptTouchEvent(event); } startX = x; startY = y; currentStickerPreviewCell = (StickerEmojiCell) view; openStickerPreviewRunnable = new Runnable() { @Override public void run() { if (openStickerPreviewRunnable == null) { return; } stickersGridView.setOnItemClickListener(null); stickersGridView.requestDisallowInterceptTouchEvent(true); openStickerPreviewRunnable = null; StickerPreviewViewer.getInstance().setParentActivity((Activity) getContext()); StickerPreviewViewer.getInstance() .setKeyboardHeight(EmojiView.this.getMeasuredHeight()); StickerPreviewViewer.getInstance().open(currentStickerPreviewCell.getSticker()); currentStickerPreviewCell.setScaled(true); } }; AndroidUtilities.runOnUIThread(openStickerPreviewRunnable, 200); return true; } } return false; } }; stickersGridView.setSelector(R.drawable.transparent); stickersGridView.setColumnWidth(AndroidUtilities.dp(72)); stickersGridView.setNumColumns(-1); stickersGridView.setPadding(0, AndroidUtilities.dp(4), 0, 0); stickersGridView.setClipToPadding(false); views.add(stickersGridView); stickersGridAdapter = new StickersGridAdapter(context); stickersGridView.setAdapter(stickersGridAdapter); stickersGridView.setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { if (openStickerPreviewRunnable != null || StickerPreviewViewer.getInstance().isVisible()) { if (event.getAction() == MotionEvent.ACTION_UP || event.getAction() == MotionEvent.ACTION_CANCEL || event.getAction() == MotionEvent.ACTION_POINTER_UP) { AndroidUtilities.runOnUIThread(new Runnable() { @Override public void run() { stickersGridView.setOnItemClickListener(stickersOnItemClickListener); } }, 150); if (openStickerPreviewRunnable != null) { AndroidUtilities.cancelRunOnUIThread(openStickerPreviewRunnable); openStickerPreviewRunnable = null; } else if (StickerPreviewViewer.getInstance().isVisible()) { StickerPreviewViewer.getInstance().close(); if (currentStickerPreviewCell != null) { currentStickerPreviewCell.setScaled(false); currentStickerPreviewCell = null; } } } else if (event.getAction() != MotionEvent.ACTION_DOWN) { if (StickerPreviewViewer.getInstance().isVisible()) { if (event.getAction() == MotionEvent.ACTION_MOVE) { int x = (int) event.getX(); int y = (int) event.getY(); int count = stickersGridView.getChildCount(); for (int a = 0; a < count; a++) { View view = stickersGridView.getChildAt(a); int top = view.getTop(); int bottom = view.getBottom(); int left = view.getLeft(); int right = view.getRight(); if (top > y || bottom < y || left > x || right < x) { continue; } if (!(view instanceof StickerEmojiCell) || view == currentStickerPreviewCell) { break; } if (currentStickerPreviewCell != null) { currentStickerPreviewCell.setScaled(false); } currentStickerPreviewCell = (StickerEmojiCell) view; StickerPreviewViewer.getInstance() .setKeyboardHeight(EmojiView.this.getMeasuredHeight()); StickerPreviewViewer.getInstance() .open(currentStickerPreviewCell.getSticker()); currentStickerPreviewCell.setScaled(true); return true; } } return true; } else if (openStickerPreviewRunnable != null) { if (event.getAction() == MotionEvent.ACTION_MOVE) { if (Math.hypot(startX - event.getX(), startY - event.getY()) > AndroidUtilities .dp(10)) { AndroidUtilities.cancelRunOnUIThread(openStickerPreviewRunnable); openStickerPreviewRunnable = null; } } else { AndroidUtilities.cancelRunOnUIThread(openStickerPreviewRunnable); openStickerPreviewRunnable = null; } } } } return false; } }); stickersOnItemClickListener = new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long i) { if (!(view instanceof StickerEmojiCell)) { return; } if (openStickerPreviewRunnable != null) { AndroidUtilities.cancelRunOnUIThread(openStickerPreviewRunnable); openStickerPreviewRunnable = null; } if (currentStickerPreviewCell != null) { currentStickerPreviewCell.setScaled(false); currentStickerPreviewCell = null; } StickerEmojiCell cell = (StickerEmojiCell) view; if (cell.isDisabled()) { return; } cell.disable(); TLRPC.Document document = cell.getSticker(); Integer count = stickersUseHistory.get(document.id); if (count == null) { count = 0; } if (count == 0 && stickersUseHistory.size() > 19) { for (int a = recentStickers.size() - 1; a >= 0; a--) { TLRPC.Document sticker = recentStickers.get(a); stickersUseHistory.remove(sticker.id); recentStickers.remove(a); if (stickersUseHistory.size() <= 19) { break; } } } stickersUseHistory.put(document.id, ++count); saveRecentStickers(); if (listener != null) { listener.onStickerSelected(document); } } }; stickersGridView.setOnItemClickListener(stickersOnItemClickListener); AndroidUtilities.setListViewEdgeEffectColor(stickersGridView, 0xfff5f6f7); stickersWrap = new FrameLayout(context); stickersWrap.addView(stickersGridView); TextView textView = new TextView(context); textView.setText(LocaleController.getString("NoStickers", R.string.NoStickers)); textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18); textView.setTextColor(0xff888888); stickersWrap.addView(textView, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.CENTER)); stickersGridView.setEmptyView(textView); scrollSlidingTabStrip = new ScrollSlidingTabStrip(context) { boolean startedScroll; float lastX; float lastTranslateX; boolean first = true; @Override public boolean onInterceptTouchEvent(MotionEvent ev) { if (getParent() != null) { getParent().requestDisallowInterceptTouchEvent(true); } return super.onInterceptTouchEvent(ev); } @Override public boolean onTouchEvent(MotionEvent ev) { if (Build.VERSION.SDK_INT >= 11) { if (first) { first = false; lastX = ev.getX(); } float newTranslationX = ViewProxy.getTranslationX(scrollSlidingTabStrip); if (scrollSlidingTabStrip.getScrollX() == 0 && newTranslationX == 0) { if (!startedScroll && lastX - ev.getX() < 0) { if (pager.beginFakeDrag()) { startedScroll = true; lastTranslateX = ViewProxy.getTranslationX(scrollSlidingTabStrip); } } else if (startedScroll && lastX - ev.getX() > 0) { if (pager.isFakeDragging()) { pager.endFakeDrag(); startedScroll = false; } } } if (startedScroll) { int dx = (int) (ev.getX() - lastX + newTranslationX - lastTranslateX); try { pager.fakeDragBy(dx); lastTranslateX = newTranslationX; } catch (Exception e) { try { pager.endFakeDrag(); } catch (Exception e2) { //don't promt } startedScroll = false; FileLog.e("tmessages", e); } } lastX = ev.getX(); if (ev.getAction() == MotionEvent.ACTION_CANCEL || ev.getAction() == MotionEvent.ACTION_UP) { first = true; if (startedScroll) { pager.endFakeDrag(); startedScroll = false; } } return startedScroll || super.onTouchEvent(ev); } return super.onTouchEvent(ev); } }; scrollSlidingTabStrip.setUnderlineHeight(AndroidUtilities.dp(1)); scrollSlidingTabStrip.setIndicatorColor(0xffe2e5e7); scrollSlidingTabStrip.setUnderlineColor(0xffe2e5e7); scrollSlidingTabStrip.setVisibility(INVISIBLE); addView(scrollSlidingTabStrip, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 48, Gravity.LEFT | Gravity.TOP)); ViewProxy.setTranslationX(scrollSlidingTabStrip, AndroidUtilities.displaySize.x); updateStickerTabs(); scrollSlidingTabStrip.setDelegate(new ScrollSlidingTabStrip.ScrollSlidingTabStripDelegate() { @Override public void onPageSelected(int page) { if (page == 0) { pager.setCurrentItem(0); return; } else if (page == 1 && !recentStickers.isEmpty()) { views.get(6).setSelection(0); return; } int index = page - (recentStickers.isEmpty() ? 1 : 2); if (index == stickerSets.size()) { if (listener != null) { listener.onStickersSettingsClick(); } return; } if (index >= stickerSets.size()) { index = stickerSets.size() - 1; } views.get(6).setSelection(stickersGridAdapter.getPositionForPack(stickerSets.get(index))); } }); stickersGridView.setOnScrollListener(new AbsListView.OnScrollListener() { @Override public void onScrollStateChanged(AbsListView view, int scrollState) { } @Override public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) { int count = view.getChildCount(); for (int a = 0; a < count; a++) { View child = view.getChildAt(a); if (child.getHeight() + child.getTop() < AndroidUtilities.dp(5)) { firstVisibleItem++; } else { break; } } scrollSlidingTabStrip .onPageScrolled(stickersGridAdapter.getTabForPosition(firstVisibleItem) + 1, 0); } }); } setBackgroundColor(0xfff5f6f7); pager = new ViewPager(context) { @Override public boolean onInterceptTouchEvent(MotionEvent ev) { if (getParent() != null) { getParent().requestDisallowInterceptTouchEvent(true); } return super.onInterceptTouchEvent(ev); } }; pager.setAdapter(new EmojiPagesAdapter()); pagerSlidingTabStripContainer = new LinearLayout(context) { @Override public boolean onInterceptTouchEvent(MotionEvent ev) { if (getParent() != null) { getParent().requestDisallowInterceptTouchEvent(true); } return super.onInterceptTouchEvent(ev); } }; pagerSlidingTabStripContainer.setOrientation(LinearLayout.HORIZONTAL); pagerSlidingTabStripContainer.setBackgroundColor(0xfff5f6f7); addView(pagerSlidingTabStripContainer, LayoutHelper.createFrame(LayoutParams.MATCH_PARENT, 48)); PagerSlidingTabStrip pagerSlidingTabStrip = new PagerSlidingTabStrip(context); pagerSlidingTabStrip.setViewPager(pager); pagerSlidingTabStrip.setShouldExpand(true); pagerSlidingTabStrip.setIndicatorHeight(AndroidUtilities.dp(2)); pagerSlidingTabStrip.setUnderlineHeight(AndroidUtilities.dp(1)); pagerSlidingTabStrip.setIndicatorColor(0xff2b96e2); pagerSlidingTabStrip.setUnderlineColor(0xffe2e5e7); pagerSlidingTabStripContainer.addView(pagerSlidingTabStrip, LayoutHelper.createLinear(0, 48, 1.0f)); pagerSlidingTabStrip.setOnPageChangeListener(new ViewPager.OnPageChangeListener() { @Override public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { EmojiView.this.onPageScrolled(position, getMeasuredWidth(), positionOffsetPixels); } @Override public void onPageSelected(int position) { } @Override public void onPageScrollStateChanged(int state) { } }); FrameLayout frameLayout = new FrameLayout(context); pagerSlidingTabStripContainer.addView(frameLayout, LayoutHelper.createLinear(52, 48)); backspaceButton = new ImageView(context) { @Override public boolean onTouchEvent(MotionEvent event) { if (event.getAction() == MotionEvent.ACTION_DOWN) { backspacePressed = true; backspaceOnce = false; postBackspaceRunnable(350); } else if (event.getAction() == MotionEvent.ACTION_CANCEL || event.getAction() == MotionEvent.ACTION_UP) { backspacePressed = false; if (!backspaceOnce) { if (listener != null && listener.onBackspace()) { backspaceButton.performHapticFeedback(HapticFeedbackConstants.KEYBOARD_TAP); } } } super.onTouchEvent(event); return true; } }; backspaceButton.setImageResource(R.drawable.ic_smiles_backspace); backspaceButton.setBackgroundResource(R.drawable.ic_emoji_backspace); backspaceButton.setScaleType(ImageView.ScaleType.CENTER); frameLayout.addView(backspaceButton, LayoutHelper.createFrame(52, 48)); View view = new View(context); view.setBackgroundColor(0xffe2e5e7); frameLayout.addView(view, LayoutHelper.createFrame(52, 1, Gravity.LEFT | Gravity.BOTTOM)); recentsWrap = new FrameLayout(context); recentsWrap.addView(views.get(0)); TextView textView = new TextView(context); textView.setText(LocaleController.getString("NoRecent", R.string.NoRecent)); textView.setTextSize(18); textView.setTextColor(0xff888888); textView.setGravity(Gravity.CENTER); recentsWrap.addView(textView); views.get(0).setEmptyView(textView); addView(pager, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, Gravity.LEFT | Gravity.TOP, 0, 48, 0, 0)); emojiSize = AndroidUtilities.dp(AndroidUtilities.isTablet() ? 40 : 32); pickerView = new EmojiColorPickerView(context); pickerViewPopup = new EmojiPopupWindow(pickerView, popupWidth = AndroidUtilities.dp((AndroidUtilities.isTablet() ? 40 : 32) * 6 + 10 + 4 * 5), popupHeight = AndroidUtilities.dp(AndroidUtilities.isTablet() ? 64 : 56)); pickerViewPopup.setOutsideTouchable(true); pickerViewPopup.setClippingEnabled(true); pickerViewPopup.setInputMethodMode(EmojiPopupWindow.INPUT_METHOD_NOT_NEEDED); pickerViewPopup.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_UNSPECIFIED); pickerViewPopup.getContentView().setFocusableInTouchMode(true); pickerViewPopup.getContentView().setOnKeyListener(new OnKeyListener() { @Override public boolean onKey(View v, int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_MENU && event.getRepeatCount() == 0 && event.getAction() == KeyEvent.ACTION_UP && pickerViewPopup != null && pickerViewPopup.isShowing()) { pickerViewPopup.dismiss(); return true; } return false; } }); loadRecents(); }
From source file:com.baidu.zhuanche.view.LazyViewPager.java
@Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { // For simple implementation, or internal size is always 0. // We depend on the container to specify the layout size of // our view. We can't really know what it is since we will be // adding and removing different arbitrary views and do not // want the layout to change as this happens. setMeasuredDimension(getDefaultSize(0, widthMeasureSpec), getDefaultSize(0, heightMeasureSpec)); // Children are just made to fill our space. int childWidthSize = getMeasuredWidth() - getPaddingLeft() - getPaddingRight(); int childHeightSize = getMeasuredHeight() - getPaddingTop() - getPaddingBottom(); /*// ww w .j a v a2s. co m * Make sure all children have been properly measured. Decor views first. * Right now we cheat and make this less complicated by assuming decor * views won't intersect. We will pin to edges based on gravity. */ int size = getChildCount(); for (int i = 0; i < size; ++i) { final View child = getChildAt(i); if (child.getVisibility() != GONE) { final LayoutParams lp = (LayoutParams) child.getLayoutParams(); if (lp != null && lp.isDecor) { final int hgrav = lp.gravity & Gravity.HORIZONTAL_GRAVITY_MASK; final int vgrav = lp.gravity & Gravity.VERTICAL_GRAVITY_MASK; Log.d(TAG, "gravity: " + lp.gravity + " hgrav: " + hgrav + " vgrav: " + vgrav); int widthMode = MeasureSpec.AT_MOST; int heightMode = MeasureSpec.AT_MOST; boolean consumeVertical = vgrav == Gravity.TOP || vgrav == Gravity.BOTTOM; boolean consumeHorizontal = hgrav == Gravity.LEFT || hgrav == Gravity.RIGHT; if (consumeVertical) { widthMode = MeasureSpec.EXACTLY; } else if (consumeHorizontal) { heightMode = MeasureSpec.EXACTLY; } final int widthSpec = MeasureSpec.makeMeasureSpec(childWidthSize, widthMode); final int heightSpec = MeasureSpec.makeMeasureSpec(childHeightSize, heightMode); child.measure(widthSpec, heightSpec); if (consumeVertical) { childHeightSize -= child.getMeasuredHeight(); } else if (consumeHorizontal) { childWidthSize -= child.getMeasuredWidth(); } } } } mChildWidthMeasureSpec = MeasureSpec.makeMeasureSpec(childWidthSize, MeasureSpec.EXACTLY); mChildHeightMeasureSpec = MeasureSpec.makeMeasureSpec(childHeightSize, MeasureSpec.EXACTLY); // Make sure we have created all fragments that we need to have shown. mInLayout = true; populate(); mInLayout = false; // Page views next. size = getChildCount(); for (int i = 0; i < size; ++i) { final View child = getChildAt(i); if (child.getVisibility() != GONE) { if (DEBUG) Log.v(TAG, "Measuring #" + i + " " + child + ": " + mChildWidthMeasureSpec); final LayoutParams lp = (LayoutParams) child.getLayoutParams(); if (lp == null || !lp.isDecor) { child.measure(mChildWidthMeasureSpec, mChildHeightMeasureSpec); } } } }
From source file:com.chenglong.muscle.ui.LazyViewPager.java
@Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { // For simple implementation, or internal size is always 0. // We depend on the container to specify the layout size of // our view. We can't really know what it is since we will be // adding and removing different arbitrary views and do not // want the layout to change as this happens. setMeasuredDimension(getDefaultSize(0, widthMeasureSpec), getDefaultSize(0, heightMeasureSpec)); // Children are just made to fill our space. int childWidthSize = getMeasuredWidth() - getPaddingLeft() - getPaddingRight(); int childHeightSize = getMeasuredHeight() - getPaddingTop() - getPaddingBottom(); /*//from w w w . j a v a 2s.c o m * Make sure all children have been properly measured. Decor views * first. Right now we cheat and make this less complicated by assuming * decor views won't intersect. We will pin to edges based on gravity. */ int size = getChildCount(); for (int i = 0; i < size; ++i) { final View child = getChildAt(i); if (child.getVisibility() != GONE) { final LayoutParams lp = (LayoutParams) child.getLayoutParams(); if (lp != null && lp.isDecor) { final int hgrav = lp.gravity & Gravity.HORIZONTAL_GRAVITY_MASK; final int vgrav = lp.gravity & Gravity.VERTICAL_GRAVITY_MASK; Log.d(TAG, "gravity: " + lp.gravity + " hgrav: " + hgrav + " vgrav: " + vgrav); int widthMode = MeasureSpec.AT_MOST; int heightMode = MeasureSpec.AT_MOST; boolean consumeVertical = vgrav == Gravity.TOP || vgrav == Gravity.BOTTOM; boolean consumeHorizontal = hgrav == Gravity.LEFT || hgrav == Gravity.RIGHT; if (consumeVertical) { widthMode = MeasureSpec.EXACTLY; } else if (consumeHorizontal) { heightMode = MeasureSpec.EXACTLY; } final int widthSpec = MeasureSpec.makeMeasureSpec(childWidthSize, widthMode); final int heightSpec = MeasureSpec.makeMeasureSpec(childHeightSize, heightMode); child.measure(widthSpec, heightSpec); if (consumeVertical) { childHeightSize -= child.getMeasuredHeight(); } else if (consumeHorizontal) { childWidthSize -= child.getMeasuredWidth(); } } } } mChildWidthMeasureSpec = MeasureSpec.makeMeasureSpec(childWidthSize, MeasureSpec.EXACTLY); mChildHeightMeasureSpec = MeasureSpec.makeMeasureSpec(childHeightSize, MeasureSpec.EXACTLY); // Make sure we have created all fragments that we need to have shown. mInLayout = true; populate(); mInLayout = false; // Page views next. size = getChildCount(); for (int i = 0; i < size; ++i) { final View child = getChildAt(i); if (child.getVisibility() != GONE) { if (DEBUG) Log.v(TAG, "Measuring #" + i + " " + child + ": " + mChildWidthMeasureSpec); final LayoutParams lp = (LayoutParams) child.getLayoutParams(); if (lp == null || !lp.isDecor) { child.measure(mChildWidthMeasureSpec, mChildHeightMeasureSpec); } } } }