List of usage examples for android.view Gravity CENTER_VERTICAL
int CENTER_VERTICAL
To view the source code for android.view Gravity CENTER_VERTICAL.
Click Source Link
From source file:org.zywx.wbpalmstar.engine.universalex.EUExBase.java
protected final void adptLayoutParams(RelativeLayout.LayoutParams rParms, FrameLayout.LayoutParams outParm) { if (null == rParms) { return;// ww w .j ava2 s. co m } int TRUE = RelativeLayout.TRUE; int ALIGN_PARENT_LEFT = RelativeLayout.ALIGN_PARENT_LEFT; int ALIGN_PARENT_TOP = RelativeLayout.ALIGN_PARENT_TOP; int ALIGN_PARENT_RIGHT = RelativeLayout.ALIGN_PARENT_RIGHT; int ALIGN_PARENT_BOTTOM = RelativeLayout.ALIGN_PARENT_BOTTOM; int CENTER_IN_PARENT = RelativeLayout.CENTER_IN_PARENT; int CENTER_HORIZONTAL = RelativeLayout.CENTER_HORIZONTAL; int CENTER_VERTICAL = RelativeLayout.CENTER_VERTICAL; try { int[] rules = rParms.getRules(); if (rules[ALIGN_PARENT_LEFT] == TRUE) { outParm.gravity |= Gravity.LEFT; } if (rules[ALIGN_PARENT_TOP] == TRUE) { outParm.gravity |= Gravity.TOP; } if (rules[ALIGN_PARENT_RIGHT] == TRUE) { outParm.gravity |= Gravity.RIGHT; } if (rules[ALIGN_PARENT_BOTTOM] == TRUE) { outParm.gravity |= Gravity.BOTTOM; } if (rules[CENTER_IN_PARENT] == TRUE) { outParm.gravity |= Gravity.CENTER; } if (rules[CENTER_HORIZONTAL] == TRUE) { outParm.gravity |= Gravity.CENTER_HORIZONTAL; } if (rules[CENTER_VERTICAL] == TRUE) { outParm.gravity |= Gravity.CENTER_VERTICAL; } } catch (Exception e) { ; } }
From source file:com.aidy.bottomdrawerlayout.DrawerLayout.java
@Override protected void onLayout(boolean changed, int l, int t, int r, int b) { Log.i(TAG, "onLayout()"); mInLayout = true;//from w w w . j av a 2 s. com 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.android.inputmethod.latin.suggestions.SuggestionStripLayoutHelper.java
public void layoutAddToDictionaryHint(final String word, final ViewGroup addToDictionaryStrip) { final boolean shouldShowUiToAcceptTypedWord = Settings.getInstance() .getCurrent().mShouldShowUiToAcceptTypedWord; final int stripWidth = addToDictionaryStrip.getWidth(); final int width = shouldShowUiToAcceptTypedWord ? stripWidth : stripWidth - mDividerWidth - mPadding * 2; final TextView wordView = (TextView) addToDictionaryStrip.findViewById(R.id.word_to_save); wordView.setTextColor(mColorTypedWord); final int wordWidth = (int) (width * mCenterSuggestionWeight); final CharSequence wordToSave = getEllipsizedText(word, wordWidth, wordView.getPaint()); final float wordScaleX = wordView.getTextScaleX(); wordView.setText(wordToSave);/*from ww w . j a v a2 s .c om*/ wordView.setTextScaleX(wordScaleX); setLayoutWeight(wordView, mCenterSuggestionWeight, ViewGroup.LayoutParams.MATCH_PARENT); final int wordVisibility = shouldShowUiToAcceptTypedWord ? View.GONE : View.VISIBLE; wordView.setVisibility(wordVisibility); addToDictionaryStrip.findViewById(R.id.word_to_save_divider).setVisibility(wordVisibility); final Resources res = addToDictionaryStrip.getResources(); final CharSequence hintText; final int hintWidth; final float hintWeight; final TextView hintView = (TextView) addToDictionaryStrip.findViewById(R.id.hint_add_to_dictionary); if (shouldShowUiToAcceptTypedWord) { hintText = res.getText(R.string.hint_add_to_dictionary_without_word); hintWidth = width; hintWeight = 1.0f; hintView.setGravity(Gravity.CENTER); } else { final boolean isRtlLanguage = (ViewCompat .getLayoutDirection(addToDictionaryStrip) == ViewCompat.LAYOUT_DIRECTION_RTL); final String arrow = isRtlLanguage ? RIGHTWARDS_ARROW : LEFTWARDS_ARROW; final boolean isRtlSystem = SubtypeLocaleUtils.isRtlLanguage(res.getConfiguration().locale); final CharSequence hint = res.getText(R.string.hint_add_to_dictionary); hintText = (isRtlLanguage == isRtlSystem) ? (arrow + hint) : (hint + arrow); hintWidth = width - wordWidth; hintWeight = 1.0f - mCenterSuggestionWeight; hintView.setGravity(Gravity.CENTER_VERTICAL | Gravity.START); } hintView.setTextColor(mColorAutoCorrect); final float hintScaleX = getTextScaleX(hintText, hintWidth, hintView.getPaint()); hintView.setText(hintText); hintView.setTextScaleX(hintScaleX); setLayoutWeight(hintView, hintWeight, ViewGroup.LayoutParams.MATCH_PARENT); }
From source file:android.widget.Gallery.java
/** * Figure out vertical placement based on mGravity * //from ww w . j av a 2 s.co m * @param child Child to place * @return Where the top of the child should be */ private int calculateTop(View child, boolean duringLayout) { int myHeight = duringLayout ? getMeasuredHeight() : getHeight(); int childHeight = duringLayout ? child.getMeasuredHeight() : child.getHeight(); int childTop = 0; switch (mGravity) { case Gravity.TOP: childTop = mSpinnerPadding.top; break; case Gravity.CENTER_VERTICAL: int availableSpace = myHeight - mSpinnerPadding.bottom - mSpinnerPadding.top - childHeight; childTop = mSpinnerPadding.top + (availableSpace / 2); break; case Gravity.BOTTOM: childTop = myHeight - mSpinnerPadding.bottom - childHeight; break; } return childTop; }
From source file:com.matthewlogan.reversedrawerlayout.library.ReverseDrawerLayout.java
@Override protected void onLayout(boolean changed, int l, int t, int r, int b) { mInLayout = true;// www . j a va 2s.c o m final int width = r - l; mDrawerOverhangDecimalOffset = mDrawerOverhang / (float) width; 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. if (mFirstLayout) { openDrawer(child); } child.setClickable(true); 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.telegram.ui.Components.ChatAttachAlert.java
public ChatAttachAlert(Context context, final ChatActivity parentFragment) { super(context, false); baseFragment = parentFragment;/* w w w . j a va2 s .co m*/ setDelegate(this); setUseRevealAnimation(true); checkCamera(false); if (deviceHasGoodCamera) { CameraController.getInstance().initCamera(); } NotificationCenter.getInstance().addObserver(this, NotificationCenter.albumsDidLoaded); NotificationCenter.getInstance().addObserver(this, NotificationCenter.reloadInlineHints); NotificationCenter.getInstance().addObserver(this, NotificationCenter.cameraInitied); shadowDrawable = context.getResources().getDrawable(R.drawable.sheet_shadow); containerView = listView = new RecyclerListView(context) { private int lastWidth; private int lastHeight; @Override public void requestLayout() { if (ignoreLayout) { return; } super.requestLayout(); } @Override public boolean onInterceptTouchEvent(MotionEvent ev) { if (cameraAnimationInProgress) { return true; } else if (cameraOpened) { return processTouchEvent(ev); } else if (ev.getAction() == MotionEvent.ACTION_DOWN && scrollOffsetY != 0 && ev.getY() < scrollOffsetY) { dismiss(); return true; } return super.onInterceptTouchEvent(ev); } @Override public boolean onTouchEvent(MotionEvent event) { if (cameraAnimationInProgress) { return true; } else if (cameraOpened) { return processTouchEvent(event); } return !isDismissed() && super.onTouchEvent(event); } @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { int height = MeasureSpec.getSize(heightMeasureSpec); if (Build.VERSION.SDK_INT >= 21) { height -= AndroidUtilities.statusBarHeight; } int contentSize = backgroundPaddingTop + AndroidUtilities.dp(294) + (SearchQuery.inlineBots.isEmpty() ? 0 : ((int) Math.ceil(SearchQuery.inlineBots.size() / 4.0f) * AndroidUtilities.dp(100) + AndroidUtilities.dp(12))); int padding = contentSize == AndroidUtilities.dp(294) ? 0 : Math.max(0, (height - AndroidUtilities.dp(294))); if (padding != 0 && contentSize < height) { padding -= (height - contentSize); } if (padding == 0) { padding = backgroundPaddingTop; } if (getPaddingTop() != padding) { ignoreLayout = true; setPadding(backgroundPaddingLeft, padding, backgroundPaddingLeft, 0); ignoreLayout = false; } super.onMeasure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(Math.min(contentSize, height), MeasureSpec.EXACTLY)); } @Override protected void onLayout(boolean changed, int left, int top, int right, int bottom) { int width = right - left; int height = bottom - top; int newPosition = -1; int newTop = 0; int count = listView.getChildCount(); int lastVisibleItemPosition = -1; int lastVisibleItemPositionTop = 0; if (count > 0) { View child = listView.getChildAt(listView.getChildCount() - 1); Holder holder = (Holder) listView.findContainingViewHolder(child); if (holder != null) { lastVisibleItemPosition = holder.getAdapterPosition(); lastVisibleItemPositionTop = child.getTop(); } } if (lastVisibleItemPosition >= 0 && height - lastHeight != 0) { newPosition = lastVisibleItemPosition; newTop = lastVisibleItemPositionTop + height - lastHeight - getPaddingTop(); } super.onLayout(changed, left, top, right, bottom); if (newPosition != -1) { ignoreLayout = true; layoutManager.scrollToPositionWithOffset(newPosition, newTop); super.onLayout(false, left, top, right, bottom); ignoreLayout = false; } lastHeight = height; lastWidth = width; updateLayout(); checkCameraViewPosition(); } @Override public void onDraw(Canvas canvas) { if (useRevealAnimation && Build.VERSION.SDK_INT <= 19) { canvas.save(); canvas.clipRect(backgroundPaddingLeft, scrollOffsetY, getMeasuredWidth() - backgroundPaddingLeft, getMeasuredHeight()); if (revealAnimationInProgress) { canvas.drawCircle(revealX, revealY, revealRadius, ciclePaint); } else { canvas.drawRect(backgroundPaddingLeft, scrollOffsetY, getMeasuredWidth() - backgroundPaddingLeft, getMeasuredHeight(), ciclePaint); } canvas.restore(); } else { shadowDrawable.setBounds(0, scrollOffsetY - backgroundPaddingTop, getMeasuredWidth(), getMeasuredHeight()); shadowDrawable.draw(canvas); } } @Override public void setTranslationY(float translationY) { super.setTranslationY(translationY); checkCameraViewPosition(); } }; listView.setWillNotDraw(false); listView.setClipToPadding(false); listView.setLayoutManager(layoutManager = new LinearLayoutManager(getContext())); layoutManager.setOrientation(LinearLayoutManager.VERTICAL); listView.setAdapter(adapter = new ListAdapter(context)); listView.setVerticalScrollBarEnabled(false); listView.setEnabled(true); listView.setGlowColor(0xfff5f6f7); listView.addItemDecoration(new RecyclerView.ItemDecoration() { @Override public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) { outRect.left = 0; outRect.right = 0; outRect.top = 0; outRect.bottom = 0; } }); listView.setOnScrollListener(new RecyclerView.OnScrollListener() { @Override public void onScrolled(RecyclerView recyclerView, int dx, int dy) { if (listView.getChildCount() <= 0) { return; } if (hintShowed) { if (layoutManager.findLastVisibleItemPosition() > 1) { hideHint(); hintShowed = false; ApplicationLoader.applicationContext .getSharedPreferences("mainconfig", Activity.MODE_PRIVATE).edit() .putBoolean("bothint", true).commit(); } } updateLayout(); checkCameraViewPosition(); } }); containerView.setPadding(backgroundPaddingLeft, 0, backgroundPaddingLeft, 0); attachView = new FrameLayout(context) { @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { super.onMeasure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(294), MeasureSpec.EXACTLY)); } @Override protected void onLayout(boolean changed, int left, int top, int right, int bottom) { int width = right - left; int height = bottom - top; int t = AndroidUtilities.dp(8); attachPhotoRecyclerView.layout(0, t, width, t + attachPhotoRecyclerView.getMeasuredHeight()); progressView.layout(0, t, width, t + progressView.getMeasuredHeight()); lineView.layout(0, AndroidUtilities.dp(96), width, AndroidUtilities.dp(96) + lineView.getMeasuredHeight()); hintTextView.layout(width - hintTextView.getMeasuredWidth() - AndroidUtilities.dp(5), height - hintTextView.getMeasuredHeight() - AndroidUtilities.dp(5), width - AndroidUtilities.dp(5), height - AndroidUtilities.dp(5)); int diff = (width - AndroidUtilities.dp(85 * 4 + 20)) / 3; for (int a = 0; a < 8; a++) { int y = AndroidUtilities.dp(105 + 95 * (a / 4)); int x = AndroidUtilities.dp(10) + (a % 4) * (AndroidUtilities.dp(85) + diff); views[a].layout(x, y, x + views[a].getMeasuredWidth(), y + views[a].getMeasuredHeight()); } } }; views[8] = attachPhotoRecyclerView = new RecyclerListView(context); attachPhotoRecyclerView.setVerticalScrollBarEnabled(true); attachPhotoRecyclerView.setAdapter(photoAttachAdapter = new PhotoAttachAdapter(context)); attachPhotoRecyclerView.setClipToPadding(false); attachPhotoRecyclerView.setPadding(AndroidUtilities.dp(8), 0, AndroidUtilities.dp(8), 0); attachPhotoRecyclerView.setItemAnimator(null); attachPhotoRecyclerView.setLayoutAnimation(null); attachPhotoRecyclerView.setOverScrollMode(RecyclerListView.OVER_SCROLL_NEVER); attachView.addView(attachPhotoRecyclerView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 80)); attachPhotoLayoutManager = new LinearLayoutManager(context) { @Override public boolean supportsPredictiveItemAnimations() { return false; } }; attachPhotoLayoutManager.setOrientation(LinearLayoutManager.HORIZONTAL); attachPhotoRecyclerView.setLayoutManager(attachPhotoLayoutManager); attachPhotoRecyclerView.setOnItemClickListener(new RecyclerListView.OnItemClickListener() { @SuppressWarnings("unchecked") @Override public void onItemClick(View view, int position) { if (baseFragment == null || baseFragment.getParentActivity() == null) { return; } if (!deviceHasGoodCamera || position != 0) { if (deviceHasGoodCamera) { position--; } if (MediaController.allPhotosAlbumEntry == null) { return; } ArrayList<Object> arrayList = (ArrayList) MediaController.allPhotosAlbumEntry.photos; if (position < 0 || position >= arrayList.size()) { return; } PhotoViewer.getInstance().setParentActivity(baseFragment.getParentActivity()); PhotoViewer.getInstance().openPhotoForSelect(arrayList, position, 0, ChatAttachAlert.this, baseFragment); AndroidUtilities.hideKeyboard(baseFragment.getFragmentView().findFocus()); } else { openCamera(); } } }); attachPhotoRecyclerView.setOnScrollListener(new RecyclerView.OnScrollListener() { @Override public void onScrolled(RecyclerView recyclerView, int dx, int dy) { checkCameraViewPosition(); } }); views[9] = progressView = new EmptyTextProgressView(context); if (Build.VERSION.SDK_INT >= 23 && getContext().checkSelfPermission( Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { progressView.setText(LocaleController.getString("PermissionStorage", R.string.PermissionStorage)); progressView.setTextSize(16); } else { progressView.setText(LocaleController.getString("NoPhotos", R.string.NoPhotos)); progressView.setTextSize(20); } attachView.addView(progressView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 80)); attachPhotoRecyclerView.setEmptyView(progressView); views[10] = lineView = new View(getContext()) { @Override public boolean hasOverlappingRendering() { return false; } }; lineView.setBackgroundColor(ContextCompat.getColor(context, R.color.divider)); attachView.addView(lineView, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 1, Gravity.TOP | Gravity.LEFT)); CharSequence[] items = new CharSequence[] { LocaleController.getString("ChatCamera", R.string.ChatCamera), LocaleController.getString("ChatGallery", R.string.ChatGallery), LocaleController.getString("ChatVideo", R.string.ChatVideo), LocaleController.getString("AttachMusic", R.string.AttachMusic), LocaleController.getString("ChatDocument", R.string.ChatDocument), LocaleController.getString("AttachContact", R.string.AttachContact), LocaleController.getString("ChatLocation", R.string.ChatLocation), "" }; for (int a = 0; a < 8; a++) { AttachButton attachButton = new AttachButton(context); attachButton.setTextAndIcon(items[a], Theme.attachButtonDrawables[a]); attachView.addView(attachButton, LayoutHelper.createFrame(85, 90, Gravity.LEFT | Gravity.TOP)); attachButton.setTag(a); views[a] = attachButton; if (a == 7) { sendPhotosButton = attachButton; sendPhotosButton.imageView.setPadding(0, AndroidUtilities.dp(4), 0, 0); } attachButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { delegate.didPressedButton((Integer) v.getTag()); } }); } hintTextView = new TextView(context); hintTextView.setBackgroundResource(R.drawable.tooltip); hintTextView.setTextColor(Theme.CHAT_GIF_HINT_TEXT_COLOR); hintTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14); hintTextView.setPadding(AndroidUtilities.dp(10), 0, AndroidUtilities.dp(10), 0); hintTextView.setText(LocaleController.getString("AttachBotsHelp", R.string.AttachBotsHelp)); hintTextView.setGravity(Gravity.CENTER_VERTICAL); hintTextView.setVisibility(View.INVISIBLE); hintTextView.setCompoundDrawablesWithIntrinsicBounds(R.drawable.scroll_tip, 0, 0, 0); hintTextView.setCompoundDrawablePadding(AndroidUtilities.dp(8)); attachView.addView(hintTextView, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, 32, Gravity.RIGHT | Gravity.BOTTOM, 5, 0, 5, 5)); for (int a = 0; a < 8; a++) { viewsCache.add(photoAttachAdapter.createHolder()); } if (loading) { progressView.showProgress(); } else { progressView.showTextView(); } if (Build.VERSION.SDK_INT >= 16) { recordTime = new TextView(context); recordTime.setBackgroundResource(R.drawable.system); recordTime.getBackground() .setColorFilter(new PorterDuffColorFilter(0x66000000, PorterDuff.Mode.MULTIPLY)); recordTime.setText("00:00"); recordTime.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 15); recordTime.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf")); recordTime.setAlpha(0.0f); recordTime.setTextColor(0xffffffff); recordTime.setPadding(AndroidUtilities.dp(10), AndroidUtilities.dp(5), AndroidUtilities.dp(10), AndroidUtilities.dp(5)); container.addView(recordTime, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.CENTER_HORIZONTAL | Gravity.TOP, 0, 16, 0, 0)); cameraPanel = new FrameLayout(context) { @Override protected void onLayout(boolean changed, int left, int top, int right, int bottom) { int cx = getMeasuredWidth() / 2; int cy = getMeasuredHeight() / 2; int cx2; int cy2; shutterButton.layout(cx - shutterButton.getMeasuredWidth() / 2, cy - shutterButton.getMeasuredHeight() / 2, cx + shutterButton.getMeasuredWidth() / 2, cy + shutterButton.getMeasuredHeight() / 2); if (getMeasuredWidth() == AndroidUtilities.dp(100)) { cx = cx2 = getMeasuredWidth() / 2; cy2 = cy + cy / 2 + AndroidUtilities.dp(17); cy = cy / 2 - AndroidUtilities.dp(17); } else { cx2 = cx + cx / 2 + AndroidUtilities.dp(17); cx = cx / 2 - AndroidUtilities.dp(17); cy = cy2 = getMeasuredHeight() / 2; } switchCameraButton.layout(cx2 - switchCameraButton.getMeasuredWidth() / 2, cy2 - switchCameraButton.getMeasuredHeight() / 2, cx2 + switchCameraButton.getMeasuredWidth() / 2, cy2 + switchCameraButton.getMeasuredHeight() / 2); for (int a = 0; a < 2; a++) { flashModeButton[a].layout(cx - flashModeButton[a].getMeasuredWidth() / 2, cy - flashModeButton[a].getMeasuredHeight() / 2, cx + flashModeButton[a].getMeasuredWidth() / 2, cy + flashModeButton[a].getMeasuredHeight() / 2); } } }; cameraPanel.setVisibility(View.GONE); cameraPanel.setAlpha(0.0f); container.addView(cameraPanel, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 100, Gravity.LEFT | Gravity.BOTTOM)); shutterButton = new ShutterButton(context); cameraPanel.addView(shutterButton, LayoutHelper.createFrame(84, 84, Gravity.CENTER)); shutterButton.setDelegate(new ShutterButton.ShutterButtonDelegate() { @Override public void shutterLongPressed() { if (takingPhoto || baseFragment == null || baseFragment.getParentActivity() == null) { return; } if (Build.VERSION.SDK_INT >= 23) { if (baseFragment.getParentActivity().checkSelfPermission( Manifest.permission.RECORD_AUDIO) != PackageManager.PERMISSION_GRANTED) { baseFragment.getParentActivity() .requestPermissions(new String[] { Manifest.permission.RECORD_AUDIO }, 21); return; } } for (int a = 0; a < 2; a++) { flashModeButton[a].setAlpha(0.0f); } switchCameraButton.setAlpha(0.0f); cameraFile = AndroidUtilities.generateVideoPath(); recordTime.setAlpha(1.0f); recordTime.setText("00:00"); videoRecordTime = 0; videoRecordRunnable = new Runnable() { @Override public void run() { if (videoRecordRunnable == null) { return; } videoRecordTime++; recordTime.setText( String.format("%02d:%02d", videoRecordTime / 60, videoRecordTime % 60)); AndroidUtilities.runOnUIThread(videoRecordRunnable, 1000); } }; AndroidUtilities.lockOrientation(parentFragment.getParentActivity()); CameraController.getInstance().recordVideo(cameraView.getCameraSession(), cameraFile, new CameraController.VideoTakeCallback() { @Override public void onFinishVideoRecording(final Bitmap thumb) { if (cameraFile == null || baseFragment == null) { return; } PhotoViewer.getInstance().setParentActivity(baseFragment.getParentActivity()); cameraPhoto = new ArrayList<>(); cameraPhoto.add(new MediaController.PhotoEntry(0, 0, 0, cameraFile.getAbsolutePath(), 0, true)); PhotoViewer.getInstance().openPhotoForSelect(cameraPhoto, 0, 2, new PhotoViewer.EmptyPhotoViewerProvider() { @Override public Bitmap getThumbForPhoto(MessageObject messageObject, TLRPC.FileLocation fileLocation, int index) { return thumb; } @TargetApi(16) @Override public boolean cancelButtonPressed() { if (cameraOpened && cameraView != null && cameraFile != null) { cameraFile.delete(); AndroidUtilities.runOnUIThread(new Runnable() { @Override public void run() { if (cameraView != null && !isDismissed() && Build.VERSION.SDK_INT >= 21) { cameraView.setSystemUiVisibility( View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_FULLSCREEN); } } }, 1000); CameraController.getInstance() .startPreview(cameraView.getCameraSession()); cameraFile = null; } return true; } @Override public void sendButtonPressed(int index) { if (cameraFile == null) { return; } AndroidUtilities .addMediaToGallery(cameraFile.getAbsolutePath()); baseFragment.sendMedia( (MediaController.PhotoEntry) cameraPhoto.get(0), PhotoViewer.getInstance().isMuteVideo()); closeCamera(false); dismiss(); cameraFile = null; } }, baseFragment); } }); AndroidUtilities.runOnUIThread(videoRecordRunnable, 1000); shutterButton.setState(ShutterButton.State.RECORDING, true); } @Override public void shutterCancel() { cameraFile.delete(); resetRecordState(); CameraController.getInstance().stopVideoRecording(cameraView.getCameraSession(), true); } @Override public void shutterReleased() { if (takingPhoto) { return; } if (shutterButton.getState() == ShutterButton.State.RECORDING) { resetRecordState(); CameraController.getInstance().stopVideoRecording(cameraView.getCameraSession(), false); shutterButton.setState(ShutterButton.State.DEFAULT, true); return; } cameraFile = AndroidUtilities.generatePicturePath(); takingPhoto = CameraController.getInstance().takePicture(cameraFile, cameraView.getCameraSession(), new Runnable() { @Override public void run() { takingPhoto = false; if (cameraFile == null || baseFragment == null) { return; } PhotoViewer.getInstance().setParentActivity(baseFragment.getParentActivity()); cameraPhoto = new ArrayList<>(); int orientation = 0; try { ExifInterface ei = new ExifInterface(cameraFile.getAbsolutePath()); int exif = ei.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL); switch (exif) { case ExifInterface.ORIENTATION_ROTATE_90: orientation = 90; break; case ExifInterface.ORIENTATION_ROTATE_180: orientation = 180; break; case ExifInterface.ORIENTATION_ROTATE_270: orientation = 270; break; } } catch (Exception e) { FileLog.e("tmessages", e); } cameraPhoto.add(new MediaController.PhotoEntry(0, 0, 0, cameraFile.getAbsolutePath(), orientation, false)); PhotoViewer.getInstance().openPhotoForSelect(cameraPhoto, 0, 2, new PhotoViewer.EmptyPhotoViewerProvider() { @TargetApi(16) @Override public boolean cancelButtonPressed() { if (cameraOpened && cameraView != null && cameraFile != null) { cameraFile.delete(); AndroidUtilities.runOnUIThread(new Runnable() { @Override public void run() { if (cameraView != null && !isDismissed() && Build.VERSION.SDK_INT >= 21) { cameraView.setSystemUiVisibility( View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_FULLSCREEN); } } }, 1000); CameraController.getInstance() .startPreview(cameraView.getCameraSession()); cameraFile = null; } return true; } @Override public void sendButtonPressed(int index) { if (cameraFile == null) { return; } AndroidUtilities .addMediaToGallery(cameraFile.getAbsolutePath()); baseFragment.sendMedia( (MediaController.PhotoEntry) cameraPhoto.get(0), false); closeCamera(false); dismiss(); cameraFile = null; } @Override public boolean scaleToFill() { return true; } }, baseFragment); } }); } }); switchCameraButton = new ImageView(context); switchCameraButton.setScaleType(ImageView.ScaleType.CENTER); cameraPanel.addView(switchCameraButton, LayoutHelper.createFrame(48, 48, Gravity.RIGHT | Gravity.CENTER_VERTICAL)); switchCameraButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (takingPhoto || cameraView == null || !cameraView.isInitied()) { return; } cameraInitied = false; cameraView.switchCamera(); ObjectAnimator animator = ObjectAnimator.ofFloat(switchCameraButton, "scaleX", 0.0f) .setDuration(100); animator.addListener(new AnimatorListenerAdapterProxy() { @Override public void onAnimationEnd(Animator animator) { switchCameraButton.setImageResource(cameraView.isFrontface() ? R.drawable.camera_revert1 : R.drawable.camera_revert2); ObjectAnimator.ofFloat(switchCameraButton, "scaleX", 1.0f).setDuration(100).start(); } }); animator.start(); } }); for (int a = 0; a < 2; a++) { flashModeButton[a] = new ImageView(context); flashModeButton[a].setScaleType(ImageView.ScaleType.CENTER); flashModeButton[a].setVisibility(View.INVISIBLE); cameraPanel.addView(flashModeButton[a], LayoutHelper.createFrame(48, 48, Gravity.LEFT | Gravity.TOP)); flashModeButton[a].setOnClickListener(new View.OnClickListener() { @Override public void onClick(final View currentImage) { if (flashAnimationInProgress || cameraView == null || !cameraView.isInitied() || !cameraOpened) { return; } String current = cameraView.getCameraSession().getCurrentFlashMode(); String next = cameraView.getCameraSession().getNextFlashMode(); if (current.equals(next)) { return; } cameraView.getCameraSession().setCurrentFlashMode(next); flashAnimationInProgress = true; ImageView nextImage = flashModeButton[0] == currentImage ? flashModeButton[1] : flashModeButton[0]; nextImage.setVisibility(View.VISIBLE); setCameraFlashModeIcon(nextImage, next); AnimatorSet animatorSet = new AnimatorSet(); animatorSet.playTogether( ObjectAnimator.ofFloat(currentImage, "translationY", 0, AndroidUtilities.dp(48)), ObjectAnimator.ofFloat(nextImage, "translationY", -AndroidUtilities.dp(48), 0), ObjectAnimator.ofFloat(currentImage, "alpha", 1.0f, 0.0f), ObjectAnimator.ofFloat(nextImage, "alpha", 0.0f, 1.0f)); animatorSet.setDuration(200); animatorSet.addListener(new AnimatorListenerAdapterProxy() { @Override public void onAnimationEnd(Animator animator) { flashAnimationInProgress = false; currentImage.setVisibility(View.INVISIBLE); } }); animatorSet.start(); } }); } } }
From source file:com.hughes.android.dictionary.DictionaryActivity.java
void onLanguageButtonLongClick(final Context context) { final Dialog dialog = new Dialog(context); dialog.setContentView(R.layout.select_dictionary_dialog); dialog.setTitle(R.string.selectDictionary); final List<DictionaryInfo> installedDicts = application.getDictionariesOnDevice(null); ListView listView = (ListView) dialog.findViewById(android.R.id.list); final Button button = new Button(listView.getContext()); final String name = getString(R.string.dictionaryManager); button.setText(name);//from w ww . j a v a 2 s. c o m final IntentLauncher intentLauncher = new IntentLauncher(listView.getContext(), DictionaryManagerActivity.getLaunchIntent(getApplicationContext())) { @Override protected void onGo() { dialog.dismiss(); DictionaryActivity.this.finish(); } }; button.setOnClickListener(intentLauncher); listView.addHeaderView(button); listView.setAdapter(new BaseAdapter() { @Override public View getView(int position, View convertView, ViewGroup parent) { final DictionaryInfo dictionaryInfo = getItem(position); final LinearLayout result = new LinearLayout(parent.getContext()); for (int i = 0; i < dictionaryInfo.indexInfos.size(); ++i) { final IndexInfo indexInfo = dictionaryInfo.indexInfos.get(i); final View button = application.createButton(parent.getContext(), dictionaryInfo, indexInfo); final IntentLauncher intentLauncher = new IntentLauncher(parent.getContext(), getLaunchIntent(getApplicationContext(), application.getPath(dictionaryInfo.uncompressedFilename), indexInfo.shortName, searchView.getQuery().toString())) { @Override protected void onGo() { dialog.dismiss(); DictionaryActivity.this.finish(); } }; button.setOnClickListener(intentLauncher); if (i == indexIndex && dictFile != null && dictFile.getName().equals(dictionaryInfo.uncompressedFilename)) { button.setPressed(true); } result.addView(button); } final TextView nameView = new TextView(parent.getContext()); final String name = application.getDictionaryName(dictionaryInfo.uncompressedFilename); nameView.setText(name); final LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams( ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); layoutParams.width = 0; layoutParams.weight = 1.0f; nameView.setLayoutParams(layoutParams); nameView.setGravity(Gravity.CENTER_VERTICAL); result.addView(nameView); return result; } @Override public long getItemId(int position) { return position; } @Override public DictionaryInfo getItem(int position) { return installedDicts.get(position); } @Override public int getCount() { return installedDicts.size(); } }); dialog.show(); }
From source file:com.hotstar.player.adplayer.player.PlayerFragment.java
/** * Set the player view size with givent width and height * /* w w w . ja v a 2s .c o m*/ * @param movieWidth * the width of the player view to be set to * @param movieHeight * the height of the player view to be set to */ private void setPlayerViewSize(long movieWidth, long movieHeight) { if (mediaPlayer == null || mediaPlayer.getView() == null) { AdVideoApplication.logger.w(LOG_TAG + "#setPlayerViewSize", "Unable to find player view."); return; } AdVideoApplication.logger.i(LOG_TAG + "#setPlayerViewSize", "Original movie size: " + movieWidth + "x" + movieHeight); FrameLayout layout = (FrameLayout) playerFragmentView.findViewById(R.id.playerFrame); int layoutWidth = layout.getWidth(); int layoutHeight = layout.getHeight(); float screenAspectRatio = (float) layoutWidth / layoutHeight; if (movieWidth == 0 || movieHeight == 0) { // If movie size is not available, fill the screen. movieWidth = layoutWidth; movieHeight = layoutHeight; } float movieAspectRatio = (float) movieWidth / movieHeight; int width, height; if (movieAspectRatio <= screenAspectRatio) { // Resize to fill height. width = (int) (layoutHeight * movieAspectRatio); height = layoutHeight; } else { // Resize to fill width. width = layoutWidth; height = (int) (layoutWidth * (1 / movieAspectRatio)); } AdVideoApplication.logger.i(LOG_TAG + "#setPlayerViewSize", "Movie width x height: " + movieWidth + "x" + movieHeight); AdVideoApplication.logger.i(LOG_TAG + "#setPlayerViewSize", "Setting player view size to: " + width + "x" + height); mediaPlayer.getView().setLayoutParams( new FrameLayout.LayoutParams(width, height, Gravity.CENTER_VERTICAL | Gravity.CENTER_HORIZONTAL)); RelativeLayout overlayAdLayout = (RelativeLayout) playerFragmentView.findViewById(R.id.OverlayAdLayout); RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(width, height); layoutParams.addRule(RelativeLayout.CENTER_HORIZONTAL, 1); layoutParams.addRule(RelativeLayout.ABOVE, controlBar.getView().getId()); overlayAdLayout.setLayoutParams(layoutParams); }
From source file:com.adarshahd.indianrailinfo.donate.TrainDetails.java
private void createTableLayoutTrainAvailability() { if (mPage.contains("SORRY")) { TextView textViewTrnDtls = new TextView(mActivity); textViewTrnDtls.setText("Not a valid class, Please select a different class and try again."); textViewTrnDtls.setTextAppearance(mActivity, android.R.style.TextAppearance_DeviceDefault_Large); textViewTrnDtls.setPadding(10, 10, 10, 10); textViewTrnDtls.setTextColor(Color.RED); mFrameLayout.removeAllViews();//from w w w. ja v a 2s .co m mFrameLayout.addView(textViewTrnDtls); if (mDialog.isShowing()) { mDialog.cancel(); } return; } if (mPage.contains("ISL Of")) { TextView textViewTrnDtls = new TextView(mActivity); textViewTrnDtls.setText("Station is not in ISL Of the Train. \nPlease modify the source/destination!"); textViewTrnDtls.setTextAppearance(mActivity, android.R.style.TextAppearance_DeviceDefault_Large); textViewTrnDtls.setPadding(10, 10, 10, 10); textViewTrnDtls.setTextColor(Color.RED); mFrameLayout.removeAllViews(); mFrameLayout.addView(textViewTrnDtls); if (mDialog.isShowing()) { mDialog.cancel(); } return; } if (mPage.contains("ERROR")) { TextView textViewTrnDtls = new TextView(mActivity); textViewTrnDtls.setText("Your request resulted in an error.\nPlease check!"); textViewTrnDtls.setTextAppearance(mActivity, android.R.style.TextAppearance_DeviceDefault_Large); textViewTrnDtls.setPadding(10, 10, 10, 10); textViewTrnDtls.setTextColor(Color.RED); mFrameLayout.removeAllViews(); mFrameLayout.addView(textViewTrnDtls); if (mDialog.isShowing()) { mDialog.cancel(); } return; } if (mPage.contains("Network Connectivity")) { TextView textViewTrnDtls = new TextView(mActivity); textViewTrnDtls.setText("Looks like the server is busy.\nPlease try later!"); textViewTrnDtls.setTextAppearance(mActivity, android.R.style.TextAppearance_DeviceDefault_Large); textViewTrnDtls.setPadding(10, 10, 10, 10); textViewTrnDtls.setTextColor(Color.RED); mFrameLayout.removeAllViews(); mFrameLayout.addView(textViewTrnDtls); if (mDialog.isShowing()) { mDialog.cancel(); } return; } if (mPage.contains("unavailable")) { TextView textViewTrnDtls = new TextView(mActivity); textViewTrnDtls.setText( "Response from server:\n\nYour request could not be processed now.\nPlease try again later!"); textViewTrnDtls.setTextAppearance(mActivity, android.R.style.TextAppearance_DeviceDefault_Large); textViewTrnDtls.setPadding(10, 10, 10, 10); textViewTrnDtls.setTextColor(Color.RED); mFrameLayout.removeAllViews(); mFrameLayout.addView(textViewTrnDtls); if (mDialog.isShowing()) { mDialog.cancel(); } return; } if (mDetails == null || !mDetails.getTrainNumber().equals(mTrainNumber)) { Iterator iterator = null; try { iterator = mElements.first().parent().parent().parent().getElementsByTag("tr").iterator(); } catch (Exception e) { Log.i("TrainDetails", mPage); e.printStackTrace(); return; } mListAv = new ArrayList<List<String>>(); List<String> list; Element tmp; tmp = (Element) iterator.next(); list = new ArrayList<String>(); list.add(tmp.select("th").get(0).text()); list.add("Date"); list.add(tmp.select("th").get(2).text()); //list.add(tmp.select("th").get(3).text()); mListAv.add(list); while (iterator.hasNext()) { tmp = (Element) iterator.next(); if (!tmp.hasText()) { continue; } list = new ArrayList<String>(); list.add(tmp.select("td").get(0).text()); list.add(tmp.select("td").get(1).text()); list.add(tmp.select("td").get(2).text()); //list.add(tmp.select("td").get(3).text()); mListAv.add(list); } mDetails = new Details(mListAv, TrainEnquiry.AVAILABILITY, mTrainNumber); } else { mListAv = mDetails.getList(); } mTblLayoutAv = new TableLayout(mActivity); TableRow row; TextView tv1, tv2, tv3; mTblLayoutAv.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)); for (int i = 0; i < mListAv.size(); i++) { row = new TableRow(mActivity); tv1 = new TextView(mActivity); tv2 = new TextView(mActivity); tv3 = new TextView(mActivity); //tv4 = new TextView(mActivity); tv1.setText(" " + mListAv.get(i).get(0)); tv2.setText(" " + mListAv.get(i).get(1)); tv3.setText(" " + mListAv.get(i).get(2)); //tv4.setText(" " + mListAv.get(i).get(3)); tv1.setTextAppearance(mActivity, android.R.style.TextAppearance_DeviceDefault_Medium); tv2.setTextAppearance(mActivity, android.R.style.TextAppearance_DeviceDefault_Medium); tv3.setTextAppearance(mActivity, android.R.style.TextAppearance_DeviceDefault_Medium); //tv4.setTextAppearance(mActivity,android.R.style.TextAppearance_DeviceDefault_Medium); tv1.setPadding(5, 5, 5, 5); tv2.setPadding(5, 5, 5, 5); tv3.setPadding(5, 5, 5, 5); //tv4.setPadding(5,5,5,5); /*tv2.setBackgroundResource(R.drawable.card_divider); tv3.setBackgroundResource(R.drawable.card_divider); tv4.setBackgroundResource(R.drawable.card_divider);*/ row.addView(tv1); row.addView(tv2); row.addView(tv3); //row.addView(tv4); row.setBackgroundResource(R.drawable.button_selector); row.setGravity(Gravity.CENTER_HORIZONTAL | Gravity.CENTER_VERTICAL); row.setOnClickListener(this); mTblLayoutAv.addView(row); } LinearLayout ll = new LinearLayout(mActivity); ScrollView scrollView = new ScrollView(mActivity); TextView textViewTrnDtls = new TextView(mActivity); textViewTrnDtls.setText("Availability details:"); textViewTrnDtls.setTextAppearance(mActivity, android.R.style.TextAppearance_DeviceDefault_Large); textViewTrnDtls.setPadding(10, 10, 10, 10); ll.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); ll.setOrientation(LinearLayout.VERTICAL); ll.addView(textViewTrnDtls); ll.addView(mTblLayoutAv); scrollView.addView(ll); mFrameLayout.removeAllViews(); mFrameLayout.addView(scrollView); if (mDialog.isShowing()) { mDialog.cancel(); } }
From source file:com.dk.view.FolderDrawerLayout.java
@Override protected void onLayout(boolean changed, int l, int t, int r, int b) { mInLayout = true;// ww w . ja va 2 s . c o 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; }