Example usage for android.view Gravity CENTER_HORIZONTAL

List of usage examples for android.view Gravity CENTER_HORIZONTAL

Introduction

In this page you can find the example usage for android.view Gravity CENTER_HORIZONTAL.

Prototype

int CENTER_HORIZONTAL

To view the source code for android.view Gravity CENTER_HORIZONTAL.

Click Source Link

Document

Place object in the horizontal center of its container, not changing its size.

Usage

From source file:org.telegram.ui.Components.ChatAttachAlert.java

public ChatAttachAlert(Context context, final ChatActivity parentFragment) {
    super(context, false);
    baseFragment = parentFragment;/* w ww  .j a  v  a2s.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:org.telegram.ui.ChannelAdminLogActivity.java

@Override
public View createView(Context context) {
    if (chatMessageCellsCache.isEmpty()) {
        for (int a = 0; a < 8; a++) {
            chatMessageCellsCache.add(new ChatMessageCell(context));
        }/*from   www .  jav a2s . c  o m*/
    }

    searchWas = false;
    hasOwnBackground = true;

    Theme.createChatResources(context, false);

    actionBar.setAddToContainer(false);
    actionBar.setOccupyStatusBar(Build.VERSION.SDK_INT >= 21 && !AndroidUtilities.isTablet());
    actionBar.setBackButtonDrawable(new BackDrawable(false));
    actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
        @Override
        public void onItemClick(final int id) {
            if (id == -1) {
                finishFragment();
            }
        }
    });

    avatarContainer = new ChatAvatarContainer(context, null, false);
    avatarContainer.setOccupyStatusBar(!AndroidUtilities.isTablet());
    actionBar.addView(avatarContainer, 0, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT,
            LayoutHelper.MATCH_PARENT, Gravity.TOP | Gravity.LEFT, 56, 0, 40, 0));

    ActionBarMenu menu = actionBar.createMenu();
    searchItem = menu.addItem(0, R.drawable.ic_ab_search).setIsSearchField(true)
            .setActionBarMenuItemSearchListener(new ActionBarMenuItem.ActionBarMenuItemSearchListener() {

                @Override
                public void onSearchCollapse() {
                    searchQuery = "";
                    avatarContainer.setVisibility(View.VISIBLE);
                    if (searchWas) {
                        searchWas = false;
                        loadMessages(true);
                    }
                    /*highlightMessageId = Integer.MAX_VALUE;
                    updateVisibleRows();
                    scrollToLastMessage(false);
                    */
                    updateBottomOverlay();
                }

                @Override
                public void onSearchExpand() {
                    avatarContainer.setVisibility(View.GONE);
                    updateBottomOverlay();
                }

                @Override
                public void onSearchPressed(EditText editText) {
                    searchWas = true;
                    searchQuery = editText.getText().toString();
                    loadMessages(true);
                    //updateSearchButtons(0, 0, 0);
                }
            });
    searchItem.setSearchFieldHint(LocaleController.getString("Search", R.string.Search));

    avatarContainer.setEnabled(false);

    avatarContainer.setTitle(currentChat.title);
    avatarContainer.setSubtitle(LocaleController.getString("EventLogAllEvents", R.string.EventLogAllEvents));
    avatarContainer.setChatAvatar(currentChat);

    fragmentView = new SizeNotifierFrameLayout(context) {

        @Override
        protected void onAttachedToWindow() {
            super.onAttachedToWindow();
            MessageObject messageObject = MediaController.getInstance().getPlayingMessageObject();
            if (messageObject != null && messageObject.isRoundVideo() && messageObject.eventId != 0
                    && messageObject.getDialogId() == -currentChat.id) {
                MediaController.getInstance().setTextureView(createTextureView(false), aspectRatioFrameLayout,
                        roundVideoContainer, true);
            }
        }

        @Override
        protected boolean drawChild(Canvas canvas, View child, long drawingTime) {
            boolean result = super.drawChild(canvas, child, drawingTime);
            if (child == actionBar && parentLayout != null) {
                parentLayout.drawHeaderShadow(canvas,
                        actionBar.getVisibility() == VISIBLE ? actionBar.getMeasuredHeight() : 0);
            }
            return result;
        }

        @Override
        protected boolean isActionBarVisible() {
            return actionBar.getVisibility() == VISIBLE;
        }

        @Override
        protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
            int allHeight;
            int widthSize = MeasureSpec.getSize(widthMeasureSpec);
            int heightSize = MeasureSpec.getSize(heightMeasureSpec);

            setMeasuredDimension(widthSize, heightSize);
            heightSize -= getPaddingTop();

            measureChildWithMargins(actionBar, widthMeasureSpec, 0, heightMeasureSpec, 0);
            int actionBarHeight = actionBar.getMeasuredHeight();
            if (actionBar.getVisibility() == VISIBLE) {
                heightSize -= actionBarHeight;
            }

            int keyboardSize = getKeyboardHeight();

            int childCount = getChildCount();

            for (int i = 0; i < childCount; i++) {
                View child = getChildAt(i);
                if (child == null || child.getVisibility() == GONE || child == actionBar) {
                    continue;
                }
                if (child == chatListView || child == progressView) {
                    int contentWidthSpec = MeasureSpec.makeMeasureSpec(widthSize, MeasureSpec.EXACTLY);
                    int contentHeightSpec = MeasureSpec.makeMeasureSpec(
                            Math.max(AndroidUtilities.dp(10), heightSize - AndroidUtilities.dp(48 + 2)),
                            MeasureSpec.EXACTLY);
                    child.measure(contentWidthSpec, contentHeightSpec);
                } else if (child == emptyViewContainer) {
                    int contentWidthSpec = MeasureSpec.makeMeasureSpec(widthSize, MeasureSpec.EXACTLY);
                    int contentHeightSpec = MeasureSpec.makeMeasureSpec(heightSize, MeasureSpec.EXACTLY);
                    child.measure(contentWidthSpec, contentHeightSpec);
                } else {
                    measureChildWithMargins(child, widthMeasureSpec, 0, heightMeasureSpec, 0);
                }
            }
        }

        @Override
        protected void onLayout(boolean changed, int l, int t, int r, int b) {
            final int count = getChildCount();

            for (int i = 0; i < count; i++) {
                final View child = getChildAt(i);
                if (child.getVisibility() == GONE) {
                    continue;
                }
                final LayoutParams lp = (LayoutParams) child.getLayoutParams();

                final int width = child.getMeasuredWidth();
                final int height = child.getMeasuredHeight();

                int childLeft;
                int childTop;

                int gravity = lp.gravity;
                if (gravity == -1) {
                    gravity = Gravity.TOP | Gravity.LEFT;
                }

                final int absoluteGravity = gravity & Gravity.HORIZONTAL_GRAVITY_MASK;
                final int verticalGravity = gravity & Gravity.VERTICAL_GRAVITY_MASK;

                switch (absoluteGravity & Gravity.HORIZONTAL_GRAVITY_MASK) {
                case Gravity.CENTER_HORIZONTAL:
                    childLeft = (r - l - width) / 2 + lp.leftMargin - lp.rightMargin;
                    break;
                case Gravity.RIGHT:
                    childLeft = r - width - lp.rightMargin;
                    break;
                case Gravity.LEFT:
                default:
                    childLeft = lp.leftMargin;
                }

                switch (verticalGravity) {
                case Gravity.TOP:
                    childTop = lp.topMargin + getPaddingTop();
                    if (child != actionBar && actionBar.getVisibility() == VISIBLE) {
                        childTop += actionBar.getMeasuredHeight();
                    }
                    break;
                case Gravity.CENTER_VERTICAL:
                    childTop = (b - t - height) / 2 + lp.topMargin - lp.bottomMargin;
                    break;
                case Gravity.BOTTOM:
                    childTop = (b - t) - height - lp.bottomMargin;
                    break;
                default:
                    childTop = lp.topMargin;
                }

                if (child == emptyViewContainer) {
                    childTop -= AndroidUtilities.dp(24)
                            - (actionBar.getVisibility() == VISIBLE ? actionBar.getMeasuredHeight() / 2 : 0);
                } else if (child == actionBar) {
                    childTop -= getPaddingTop();
                }
                child.layout(childLeft, childTop, childLeft + width, childTop + height);
            }

            updateMessagesVisisblePart();
            notifyHeightChanged();
        }
    };

    contentView = (SizeNotifierFrameLayout) fragmentView;

    contentView.setOccupyStatusBar(!AndroidUtilities.isTablet());
    contentView.setBackgroundImage(Theme.getCachedWallpaper(), Theme.isWallpaperMotion());

    emptyViewContainer = new FrameLayout(context);
    emptyViewContainer.setVisibility(View.INVISIBLE);
    contentView.addView(emptyViewContainer,
            LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, Gravity.CENTER));
    emptyViewContainer.setOnTouchListener((v, event) -> true);

    emptyView = new TextView(context);
    emptyView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
    emptyView.setGravity(Gravity.CENTER);
    emptyView.setTextColor(Theme.getColor(Theme.key_chat_serviceText));
    emptyView.setBackgroundDrawable(
            Theme.createRoundRectDrawable(AndroidUtilities.dp(10), Theme.getServiceMessageColor()));
    emptyView.setPadding(AndroidUtilities.dp(16), AndroidUtilities.dp(16), AndroidUtilities.dp(16),
            AndroidUtilities.dp(16));
    emptyViewContainer.addView(emptyView, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT,
            LayoutHelper.WRAP_CONTENT, Gravity.CENTER, 16, 0, 16, 0));

    chatListView = new RecyclerListView(context) {

        @Override
        public boolean drawChild(Canvas canvas, View child, long drawingTime) {
            boolean result = super.drawChild(canvas, child, drawingTime);
            if (child instanceof ChatMessageCell) {
                ChatMessageCell chatMessageCell = (ChatMessageCell) child;
                ImageReceiver imageReceiver = chatMessageCell.getAvatarImage();
                if (imageReceiver != null) {
                    int top = child.getTop();
                    if (chatMessageCell.isPinnedBottom()) {
                        ViewHolder holder = chatListView.getChildViewHolder(child);
                        if (holder != null) {
                            holder = chatListView
                                    .findViewHolderForAdapterPosition(holder.getAdapterPosition() + 1);
                            if (holder != null) {
                                imageReceiver.setImageY(-AndroidUtilities.dp(1000));
                                imageReceiver.draw(canvas);
                                return result;
                            }
                        }
                    }
                    if (chatMessageCell.isPinnedTop()) {
                        ViewHolder holder = chatListView.getChildViewHolder(child);
                        if (holder != null) {
                            while (true) {
                                holder = chatListView
                                        .findViewHolderForAdapterPosition(holder.getAdapterPosition() - 1);
                                if (holder != null) {
                                    top = holder.itemView.getTop();
                                    if (!(holder.itemView instanceof ChatMessageCell)
                                            || !((ChatMessageCell) holder.itemView).isPinnedTop()) {
                                        break;
                                    }
                                } else {
                                    break;
                                }
                            }
                        }
                    }
                    int y = child.getTop() + chatMessageCell.getLayoutHeight();
                    int maxY = chatListView.getHeight() - chatListView.getPaddingBottom();
                    if (y > maxY) {
                        y = maxY;
                    }
                    if (y - AndroidUtilities.dp(48) < top) {
                        y = top + AndroidUtilities.dp(48);
                    }
                    imageReceiver.setImageY(y - AndroidUtilities.dp(44));
                    imageReceiver.draw(canvas);
                }
            }
            return result;
        }
    };
    chatListView.setOnItemClickListener((view, position) -> createMenu(view));
    chatListView.setTag(1);
    chatListView.setVerticalScrollBarEnabled(true);
    chatListView.setAdapter(chatAdapter = new ChatActivityAdapter(context));
    chatListView.setClipToPadding(false);
    chatListView.setPadding(0, AndroidUtilities.dp(4), 0, AndroidUtilities.dp(3));
    chatListView.setItemAnimator(null);
    chatListView.setLayoutAnimation(null);
    chatLayoutManager = new LinearLayoutManager(context) {
        @Override
        public boolean supportsPredictiveItemAnimations() {
            return false;
        }

        @Override
        public void smoothScrollToPosition(RecyclerView recyclerView, RecyclerView.State state, int position) {
            LinearSmoothScrollerMiddle linearSmoothScroller = new LinearSmoothScrollerMiddle(
                    recyclerView.getContext());
            linearSmoothScroller.setTargetPosition(position);
            startSmoothScroll(linearSmoothScroller);
        }
    };
    chatLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
    chatLayoutManager.setStackFromEnd(true);
    chatListView.setLayoutManager(chatLayoutManager);
    contentView.addView(chatListView,
            LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
    chatListView.setOnScrollListener(new RecyclerView.OnScrollListener() {

        private float totalDy = 0;
        private final int scrollValue = AndroidUtilities.dp(100);

        @Override
        public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
            if (newState == RecyclerView.SCROLL_STATE_DRAGGING) {
                scrollingFloatingDate = true;
                checkTextureViewPosition = true;
            } else if (newState == RecyclerView.SCROLL_STATE_IDLE) {
                scrollingFloatingDate = false;
                checkTextureViewPosition = false;
                hideFloatingDateView(true);
            }
        }

        @Override
        public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
            chatListView.invalidate();
            if (dy != 0 && scrollingFloatingDate && !currentFloatingTopIsNotMessage) {
                if (floatingDateView.getTag() == null) {
                    if (floatingDateAnimation != null) {
                        floatingDateAnimation.cancel();
                    }
                    floatingDateView.setTag(1);
                    floatingDateAnimation = new AnimatorSet();
                    floatingDateAnimation.setDuration(150);
                    floatingDateAnimation.playTogether(ObjectAnimator.ofFloat(floatingDateView, "alpha", 1.0f));
                    floatingDateAnimation.addListener(new AnimatorListenerAdapter() {
                        @Override
                        public void onAnimationEnd(Animator animation) {
                            if (animation.equals(floatingDateAnimation)) {
                                floatingDateAnimation = null;
                            }
                        }
                    });
                    floatingDateAnimation.start();
                }
            }
            checkScrollForLoad(true);
            updateMessagesVisisblePart();
        }
    });
    if (scrollToPositionOnRecreate != -1) {
        chatLayoutManager.scrollToPositionWithOffset(scrollToPositionOnRecreate, scrollToOffsetOnRecreate);
        scrollToPositionOnRecreate = -1;
    }

    progressView = new FrameLayout(context);
    progressView.setVisibility(View.INVISIBLE);
    contentView.addView(progressView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT,
            LayoutHelper.MATCH_PARENT, Gravity.TOP | Gravity.LEFT));

    progressView2 = new View(context);
    progressView2.setBackgroundResource(R.drawable.system_loader);
    progressView2.getBackground().setColorFilter(Theme.colorFilter);
    progressView.addView(progressView2, LayoutHelper.createFrame(36, 36, Gravity.CENTER));

    progressBar = new RadialProgressView(context);
    progressBar.setSize(AndroidUtilities.dp(28));
    progressBar.setProgressColor(Theme.getColor(Theme.key_chat_serviceText));
    progressView.addView(progressBar, LayoutHelper.createFrame(32, 32, Gravity.CENTER));

    floatingDateView = new ChatActionCell(context);
    floatingDateView.setAlpha(0.0f);
    contentView.addView(floatingDateView, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT,
            LayoutHelper.WRAP_CONTENT, Gravity.TOP | Gravity.CENTER_HORIZONTAL, 0, 4, 0, 0));

    contentView.addView(actionBar);

    bottomOverlayChat = new FrameLayout(context) {
        @Override
        public void onDraw(Canvas canvas) {
            int bottom = Theme.chat_composeShadowDrawable.getIntrinsicHeight();
            Theme.chat_composeShadowDrawable.setBounds(0, 0, getMeasuredWidth(), bottom);
            Theme.chat_composeShadowDrawable.draw(canvas);
            canvas.drawRect(0, bottom, getMeasuredWidth(), getMeasuredHeight(),
                    Theme.chat_composeBackgroundPaint);
        }
    };
    bottomOverlayChat.setWillNotDraw(false);
    bottomOverlayChat.setPadding(0, AndroidUtilities.dp(3), 0, 0);
    contentView.addView(bottomOverlayChat,
            LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 51, Gravity.BOTTOM));
    bottomOverlayChat.setOnClickListener(view -> {
        if (getParentActivity() == null) {
            return;
        }
        AdminLogFilterAlert adminLogFilterAlert = new AdminLogFilterAlert(getParentActivity(), currentFilter,
                selectedAdmins, currentChat.megagroup);
        adminLogFilterAlert.setCurrentAdmins(admins);
        adminLogFilterAlert.setAdminLogFilterAlertDelegate((filter, admins) -> {
            currentFilter = filter;
            selectedAdmins = admins;
            if (currentFilter != null || selectedAdmins != null) {
                avatarContainer.setSubtitle(
                        LocaleController.getString("EventLogSelectedEvents", R.string.EventLogSelectedEvents));
            } else {
                avatarContainer.setSubtitle(
                        LocaleController.getString("EventLogAllEvents", R.string.EventLogAllEvents));
            }
            loadMessages(true);
        });
        showDialog(adminLogFilterAlert);
    });

    bottomOverlayChatText = new TextView(context);
    bottomOverlayChatText.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 15);
    bottomOverlayChatText.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
    bottomOverlayChatText.setTextColor(Theme.getColor(Theme.key_chat_fieldOverlayText));
    bottomOverlayChatText.setText(LocaleController.getString("SETTINGS", R.string.SETTINGS).toUpperCase());
    bottomOverlayChat.addView(bottomOverlayChatText,
            LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.CENTER));

    bottomOverlayImage = new ImageView(context);
    bottomOverlayImage.setImageResource(R.drawable.log_info);
    bottomOverlayImage.setColorFilter(new PorterDuffColorFilter(Theme.getColor(Theme.key_chat_fieldOverlayText),
            PorterDuff.Mode.MULTIPLY));
    bottomOverlayImage.setScaleType(ImageView.ScaleType.CENTER);
    bottomOverlayChat.addView(bottomOverlayImage,
            LayoutHelper.createFrame(48, 48, Gravity.RIGHT | Gravity.TOP, 3, 0, 0, 0));
    bottomOverlayImage.setOnClickListener(v -> {
        AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
        if (currentChat.megagroup) {
            builder.setMessage(AndroidUtilities.replaceTags(
                    LocaleController.getString("EventLogInfoDetail", R.string.EventLogInfoDetail)));
        } else {
            builder.setMessage(AndroidUtilities.replaceTags(LocaleController
                    .getString("EventLogInfoDetailChannel", R.string.EventLogInfoDetailChannel)));
        }
        builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), null);
        builder.setTitle(LocaleController.getString("EventLogInfoTitle", R.string.EventLogInfoTitle));
        showDialog(builder.create());
    });

    searchContainer = new FrameLayout(context) {
        @Override
        public void onDraw(Canvas canvas) {
            int bottom = Theme.chat_composeShadowDrawable.getIntrinsicHeight();
            Theme.chat_composeShadowDrawable.setBounds(0, 0, getMeasuredWidth(), bottom);
            Theme.chat_composeShadowDrawable.draw(canvas);
            canvas.drawRect(0, bottom, getMeasuredWidth(), getMeasuredHeight(),
                    Theme.chat_composeBackgroundPaint);
        }
    };
    searchContainer.setWillNotDraw(false);
    searchContainer.setVisibility(View.INVISIBLE);
    searchContainer.setFocusable(true);
    searchContainer.setFocusableInTouchMode(true);
    searchContainer.setClickable(true);
    searchContainer.setPadding(0, AndroidUtilities.dp(3), 0, 0);
    contentView.addView(searchContainer,
            LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 51, Gravity.BOTTOM));

    /*searchUpButton = new ImageView(context);
    searchUpButton.setScaleType(ImageView.ScaleType.CENTER);
    searchUpButton.setImageResource(R.drawable.search_up);
    searchUpButton.setColorFilter(new PorterDuffColorFilter(Theme.getColor(Theme.key_chat_searchPanelIcons), PorterDuff.Mode.MULTIPLY));
    searchContainer.addView(searchUpButton, LayoutHelper.createFrame(48, 48));
    searchUpButton.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View view) {
        MessagesSearchQuery.searchMessagesInChat(null, dialog_id, mergeDialogId, classGuid, 1);
    }
    });
            
    searchDownButton = new ImageView(context);
    searchDownButton.setScaleType(ImageView.ScaleType.CENTER);
    searchDownButton.setImageResource(R.drawable.search_down);
    searchDownButton.setColorFilter(new PorterDuffColorFilter(Theme.getColor(Theme.key_chat_searchPanelIcons), PorterDuff.Mode.MULTIPLY));
    searchContainer.addView(searchDownButton, LayoutHelper.createFrame(48, 48, Gravity.LEFT | Gravity.TOP, 48, 0, 0, 0));
    searchDownButton.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View view) {
        MessagesSearchQuery.searchMessagesInChat(null, dialog_id, mergeDialogId, classGuid, 2);
    }
    });*/

    searchCalendarButton = new ImageView(context);
    searchCalendarButton.setScaleType(ImageView.ScaleType.CENTER);
    searchCalendarButton.setImageResource(R.drawable.search_calendar);
    searchCalendarButton.setColorFilter(new PorterDuffColorFilter(
            Theme.getColor(Theme.key_chat_searchPanelIcons), PorterDuff.Mode.MULTIPLY));
    searchContainer.addView(searchCalendarButton,
            LayoutHelper.createFrame(48, 48, Gravity.RIGHT | Gravity.TOP));
    searchCalendarButton.setOnClickListener(view -> {
        if (getParentActivity() == null) {
            return;
        }
        AndroidUtilities.hideKeyboard(searchItem.getSearchField());
        Calendar calendar = Calendar.getInstance();
        int year = calendar.get(Calendar.YEAR);
        int monthOfYear = calendar.get(Calendar.MONTH);
        int dayOfMonth = calendar.get(Calendar.DAY_OF_MONTH);
        try {
            DatePickerDialog dialog = new DatePickerDialog(getParentActivity(),
                    (view1, year1, month, dayOfMonth1) -> {
                        Calendar calendar1 = Calendar.getInstance();
                        calendar1.clear();
                        calendar1.set(year1, month, dayOfMonth1);
                        int date = (int) (calendar1.getTime().getTime() / 1000);
                        loadMessages(true);
                    }, year, monthOfYear, dayOfMonth);
            final DatePicker datePicker = dialog.getDatePicker();
            datePicker.setMinDate(1375315200000L);
            datePicker.setMaxDate(System.currentTimeMillis());
            dialog.setButton(DialogInterface.BUTTON_POSITIVE,
                    LocaleController.getString("JumpToDate", R.string.JumpToDate), dialog);
            dialog.setButton(DialogInterface.BUTTON_NEGATIVE,
                    LocaleController.getString("Cancel", R.string.Cancel), (dialog12, which) -> {

                    });
            if (Build.VERSION.SDK_INT >= 21) {
                dialog.setOnShowListener(dialog1 -> {
                    int count = datePicker.getChildCount();
                    for (int a = 0; a < count; a++) {
                        View child = datePicker.getChildAt(a);
                        ViewGroup.LayoutParams layoutParams = child.getLayoutParams();
                        layoutParams.width = LayoutHelper.MATCH_PARENT;
                        child.setLayoutParams(layoutParams);
                    }
                });
            }
            showDialog(dialog);
        } catch (Exception e) {
            FileLog.e(e);
        }
    });

    searchCountText = new SimpleTextView(context);
    searchCountText.setTextColor(Theme.getColor(Theme.key_chat_searchPanelText));
    searchCountText.setTextSize(15);
    searchCountText.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
    searchContainer.addView(searchCountText, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT,
            LayoutHelper.WRAP_CONTENT, Gravity.LEFT | Gravity.CENTER_VERTICAL, 108, 0, 0, 0));

    chatAdapter.updateRows();
    if (loading && messages.isEmpty()) {
        progressView.setVisibility(View.VISIBLE);
        chatListView.setEmptyView(null);
    } else {
        progressView.setVisibility(View.INVISIBLE);
        chatListView.setEmptyView(emptyViewContainer);
    }

    updateEmptyPlaceholder();

    return fragmentView;
}

From source file:plugin.google.maps.GoogleMaps.java

@SuppressWarnings("unused")
private void showDialog(final JSONArray args, final CallbackContext callbackContext) {
    if (windowLayer != null) {
        return;//from  ww  w  .  j  a  v a  2 s .com
    }

    // window layout
    windowLayer = new LinearLayout(activity);
    windowLayer.setPadding(0, 0, 0, 0);
    LayoutParams layoutParams = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
    layoutParams.gravity = Gravity.TOP | Gravity.LEFT;
    windowLayer.setLayoutParams(layoutParams);

    // dialog window layer
    FrameLayout dialogLayer = new FrameLayout(activity);
    dialogLayer.setLayoutParams(layoutParams);
    //dialogLayer.setPadding(15, 15, 15, 0);
    dialogLayer.setBackgroundColor(Color.LTGRAY);
    windowLayer.addView(dialogLayer);

    // map frame
    final FrameLayout mapFrame = new FrameLayout(activity);
    mapFrame.setPadding(0, 0, 0, (int) (40 * density));
    dialogLayer.addView(mapFrame);

    if (this.mPluginLayout != null && this.mPluginLayout.getMyView() != null) {
        this.mPluginLayout.detachMyView();
    }

    ViewGroup.LayoutParams lParams = (ViewGroup.LayoutParams) mapView.getLayoutParams();
    if (lParams == null) {
        lParams = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.MATCH_PARENT);
    }
    lParams.width = ViewGroup.LayoutParams.MATCH_PARENT;
    lParams.height = ViewGroup.LayoutParams.MATCH_PARENT;
    if (lParams instanceof AbsoluteLayout.LayoutParams) {
        AbsoluteLayout.LayoutParams params = (AbsoluteLayout.LayoutParams) lParams;
        params.x = 0;
        params.y = 0;
        mapView.setLayoutParams(params);
    } else if (lParams instanceof LinearLayout.LayoutParams) {
        LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) lParams;
        params.topMargin = 0;
        params.leftMargin = 0;
        mapView.setLayoutParams(params);
    } else if (lParams instanceof FrameLayout.LayoutParams) {
        FrameLayout.LayoutParams params = (FrameLayout.LayoutParams) lParams;
        params.topMargin = 0;
        params.leftMargin = 0;
        mapView.setLayoutParams(params);
    }
    mapFrame.addView(this.mapView);

    // button frame
    LinearLayout buttonFrame = new LinearLayout(activity);
    buttonFrame.setOrientation(LinearLayout.HORIZONTAL);
    buttonFrame.setGravity(Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM);
    LinearLayout.LayoutParams buttonFrameParams = new LinearLayout.LayoutParams(
            LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT);
    buttonFrame.setLayoutParams(buttonFrameParams);
    dialogLayer.addView(buttonFrame);

    //close button
    LinearLayout.LayoutParams buttonParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
            LayoutParams.WRAP_CONTENT, 1.0f);
    TextView closeLink = new TextView(activity);
    closeLink.setText("Close");
    closeLink.setLayoutParams(buttonParams);
    closeLink.setTextColor(Color.BLUE);
    closeLink.setTextSize(20);
    closeLink.setGravity(Gravity.LEFT);
    closeLink.setPadding((int) (10 * density), 0, 0, (int) (10 * density));
    closeLink.setOnClickListener(GoogleMaps.this);
    closeLink.setId(CLOSE_LINK_ID);
    buttonFrame.addView(closeLink);

    //license button
    TextView licenseLink = new TextView(activity);
    licenseLink.setText("Legal Notices");
    licenseLink.setTextColor(Color.BLUE);
    licenseLink.setLayoutParams(buttonParams);
    licenseLink.setTextSize(20);
    licenseLink.setGravity(Gravity.RIGHT);
    licenseLink.setPadding((int) (10 * density), (int) (20 * density), (int) (10 * density),
            (int) (10 * density));
    licenseLink.setOnClickListener(GoogleMaps.this);
    licenseLink.setId(LICENSE_LINK_ID);
    buttonFrame.addView(licenseLink);

    webView.setVisibility(View.GONE);
    root.addView(windowLayer);

    //Dummy view for the back-button event
    FrameLayout dummyLayout = new FrameLayout(activity);

    /*
    this.webView.showCustomView(dummyLayout, new WebChromeClient.CustomViewCallback() {
            
      @Override
      public void onCustomViewHidden() {
        mapFrame.removeView(mapView);
        if (mPluginLayout != null &&
    mapDivLayoutJSON != null) {
          mPluginLayout.attachMyView(mapView);
          mPluginLayout.updateViewPosition();
        }
        root.removeView(windowLayer);
        webView.setVisibility(View.VISIBLE);
        windowLayer = null;
                
                
        GoogleMaps.this.onMapEvent("map_close");
      }
    });
    */

    this.sendNoResult(callbackContext);
}

From source file:info.icefilms.icestream.browse.BrowseFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    // Inflate our xml layout
    LinearLayout layout = (LinearLayout) inflater.inflate(R.layout.browse_fragment, container, false);

    // Add the ad layout
    mAdLayout = new AdLayout(getActivity(), 30000, true);
    LinearLayout.LayoutParams adLayoutLP = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
            (int) (50f * getResources().getDisplayMetrics().density + 0.5f));
    adLayoutLP.gravity = Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL;
    layout.addView(mAdLayout, adLayoutLP);

    return layout;
}

From source file:org.chromium.chrome.browser.payments.ui.PaymentRequestUI.java

private void changeSpinnerVisibility(boolean showSpinner) {
    if (mIsShowingSpinner == showSpinner)
        return;/*from  www  . j a v  a 2s .  c  o m*/
    mIsShowingSpinner = showSpinner;

    if (showSpinner) {
        mRequestView.removeView(mPaymentContainer);
        mRequestView.removeView(mButtonBar);
        mRequestView.addView(mSpinnyLayout);

        // Turn the bottom sheet back into a collapsed bottom sheet showing only the spinner.
        // TODO(dfalcantara): Animate this: https://crbug.com/621955
        FrameLayout.LayoutParams params = (FrameLayout.LayoutParams) mRequestView.getLayoutParams();
        params.width = LayoutParams.MATCH_PARENT;
        params.height = LayoutParams.WRAP_CONTENT;
        params.gravity = Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM;
        mRequestView.requestLayout();
    } else {
        mRequestView.removeView(mSpinnyLayout);
        mRequestView.addView(mPaymentContainer);
        mRequestView.addView(mButtonBar);

        if (mIsShowingEditDialog)
            expand(mSelectedSection);
    }
}

From source file:android.support.designox.widget.CoordinatorLayout.java

/**
 * Calculate the desired child rect relative to an anchor rect, respecting both
 * gravity and anchorGravity./*from  w  ww  . jav  a 2 s .  c o m*/
 *
 * @param child child view to calculate a rect for
 * @param layoutDirection the desired layout direction for the CoordinatorLayout
 * @param anchorRect rect in CoordinatorLayout coordinates of the anchor view area
 * @param out rect to set to the output values
 */
void getDesiredAnchoredChildRect(View child, int layoutDirection, Rect anchorRect, Rect out) {
    final LayoutParams lp = (LayoutParams) child.getLayoutParams();
    final int absGravity = GravityCompat.getAbsoluteGravity(resolveAnchoredChildGravity(lp.gravity),
            layoutDirection);
    final int absAnchorGravity = GravityCompat.getAbsoluteGravity(resolveGravity(lp.anchorGravity),
            layoutDirection);

    final int hgrav = absGravity & Gravity.HORIZONTAL_GRAVITY_MASK;
    final int vgrav = absGravity & Gravity.VERTICAL_GRAVITY_MASK;
    final int anchorHgrav = absAnchorGravity & Gravity.HORIZONTAL_GRAVITY_MASK;
    final int anchorVgrav = absAnchorGravity & Gravity.VERTICAL_GRAVITY_MASK;

    final int childWidth = child.getMeasuredWidth();
    final int childHeight = child.getMeasuredHeight();

    int left;
    int top;

    // Align to the anchor. This puts us in an assumed right/bottom child view gravity.
    // If this is not the case we will subtract out the appropriate portion of
    // the child size below.
    switch (anchorHgrav) {
    default:
    case Gravity.LEFT:
        left = anchorRect.left;
        break;
    case Gravity.RIGHT:
        left = anchorRect.right;
        break;
    case Gravity.CENTER_HORIZONTAL:
        left = anchorRect.left + anchorRect.width() / 2;
        break;
    }

    switch (anchorVgrav) {
    default:
    case Gravity.TOP:
        top = anchorRect.top;
        break;
    case Gravity.BOTTOM:
        top = anchorRect.bottom;
        break;
    case Gravity.CENTER_VERTICAL:
        top = anchorRect.top + anchorRect.height() / 2;
        break;
    }

    // Offset by the child view's gravity itself. The above assumed right/bottom gravity.
    switch (hgrav) {
    default:
    case Gravity.LEFT:
        left -= childWidth;
        break;
    case Gravity.RIGHT:
        // Do nothing, we're already in position.
        break;
    case Gravity.CENTER_HORIZONTAL:
        left -= childWidth / 2;
        break;
    }

    switch (vgrav) {
    default:
    case Gravity.TOP:
        top -= childHeight;
        break;
    case Gravity.BOTTOM:
        // Do nothing, we're already in position.
        break;
    case Gravity.CENTER_VERTICAL:
        top -= childHeight / 2;
        break;
    }

    final int width = getWidth();
    final int height = getHeight();

    // Obey margins and padding
    left = Math.max(getPaddingLeft() + lp.leftMargin,
            Math.min(left, width - getPaddingRight() - childWidth - lp.rightMargin));
    top = Math.max(getPaddingTop() + lp.topMargin,
            Math.min(top, height - getPaddingBottom() - childHeight - lp.bottomMargin));

    out.set(left, top, left + childWidth, top + childHeight);
}

From source file:android.support.v7.internal.widget.ActionBarView.java

@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    final int childCount = getChildCount();
    if (mIsCollapsable) {
        int visibleChildren = 0;
        for (int i = 0; i < childCount; i++) {
            final View child = getChildAt(i);
            if (child.getVisibility() != GONE && !(child == mMenuView && mMenuView.getChildCount() == 0)) {
                visibleChildren++;/*ww  w .j ava2s.  c om*/
            }
        }

        if (visibleChildren == 0) {
            // No size for an empty action bar when collapsable.
            setMeasuredDimension(0, 0);
            mIsCollapsed = true;
            return;
        }
    }
    mIsCollapsed = false;

    int widthMode = MeasureSpec.getMode(widthMeasureSpec);
    if (widthMode != MeasureSpec.EXACTLY) {
        throw new IllegalStateException(getClass().getSimpleName() + " can only be used "
                + "with android:layout_width=\"MATCH_PARENT\" (or fill_parent)");
    }

    int heightMode = MeasureSpec.getMode(heightMeasureSpec);
    if (heightMode != MeasureSpec.AT_MOST) {
        throw new IllegalStateException(getClass().getSimpleName() + " can only be used "
                + "with android:layout_height=\"wrap_content\"");
    }

    int contentWidth = MeasureSpec.getSize(widthMeasureSpec);

    int maxHeight = mContentHeight > 0 ? mContentHeight : MeasureSpec.getSize(heightMeasureSpec);

    final int verticalPadding = getPaddingTop() + getPaddingBottom();
    final int paddingLeft = getPaddingLeft();
    final int paddingRight = getPaddingRight();
    final int height = maxHeight - verticalPadding;
    final int childSpecHeight = MeasureSpec.makeMeasureSpec(height, MeasureSpec.AT_MOST);

    int availableWidth = contentWidth - paddingLeft - paddingRight;
    int leftOfCenter = availableWidth / 2;
    int rightOfCenter = leftOfCenter;

    HomeView homeLayout = mExpandedActionView != null ? mExpandedHomeLayout : mHomeLayout;

    if (homeLayout.getVisibility() != GONE) {
        final ViewGroup.LayoutParams lp = homeLayout.getLayoutParams();
        int homeWidthSpec;
        if (lp.width < 0) {
            homeWidthSpec = MeasureSpec.makeMeasureSpec(availableWidth, MeasureSpec.AT_MOST);
        } else {
            homeWidthSpec = MeasureSpec.makeMeasureSpec(lp.width, MeasureSpec.EXACTLY);
        }
        homeLayout.measure(homeWidthSpec, MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY));
        final int homeWidth = homeLayout.getMeasuredWidth() + homeLayout.getLeftOffset();
        availableWidth = Math.max(0, availableWidth - homeWidth);
        leftOfCenter = Math.max(0, availableWidth - homeWidth);
    }

    if (mMenuView != null && mMenuView.getParent() == this) {
        availableWidth = measureChildView(mMenuView, availableWidth, childSpecHeight, 0);
        rightOfCenter = Math.max(0, rightOfCenter - mMenuView.getMeasuredWidth());
    }

    if (mIndeterminateProgressView != null && mIndeterminateProgressView.getVisibility() != GONE) {
        availableWidth = measureChildView(mIndeterminateProgressView, availableWidth, childSpecHeight, 0);
        rightOfCenter = Math.max(0, rightOfCenter - mIndeterminateProgressView.getMeasuredWidth());
    }

    final boolean showTitle = mTitleLayout != null && mTitleLayout.getVisibility() != GONE
            && (mDisplayOptions & ActionBar.DISPLAY_SHOW_TITLE) != 0;

    if (mExpandedActionView == null) {
        switch (mNavigationMode) {
        case ActionBar.NAVIGATION_MODE_LIST:
            if (mListNavLayout != null) {
                final int itemPaddingSize = showTitle ? mItemPadding * 2 : mItemPadding;
                availableWidth = Math.max(0, availableWidth - itemPaddingSize);
                leftOfCenter = Math.max(0, leftOfCenter - itemPaddingSize);
                mListNavLayout.measure(MeasureSpec.makeMeasureSpec(availableWidth, MeasureSpec.AT_MOST),
                        MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY));
                final int listNavWidth = mListNavLayout.getMeasuredWidth();
                availableWidth = Math.max(0, availableWidth - listNavWidth);
                leftOfCenter = Math.max(0, leftOfCenter - listNavWidth);
            }
            break;
        case ActionBar.NAVIGATION_MODE_TABS:
            if (mTabScrollView != null) {
                final int itemPaddingSize = showTitle ? mItemPadding * 2 : mItemPadding;
                availableWidth = Math.max(0, availableWidth - itemPaddingSize);
                leftOfCenter = Math.max(0, leftOfCenter - itemPaddingSize);
                mTabScrollView.measure(MeasureSpec.makeMeasureSpec(availableWidth, MeasureSpec.AT_MOST),
                        MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY));
                final int tabWidth = mTabScrollView.getMeasuredWidth();
                availableWidth = Math.max(0, availableWidth - tabWidth);
                leftOfCenter = Math.max(0, leftOfCenter - tabWidth);
            }
            break;
        }
    }

    View customView = null;
    if (mExpandedActionView != null) {
        customView = mExpandedActionView;
    } else if ((mDisplayOptions & ActionBar.DISPLAY_SHOW_CUSTOM) != 0 && mCustomNavView != null) {
        customView = mCustomNavView;
    }

    if (customView != null) {
        final ViewGroup.LayoutParams lp = generateLayoutParams(customView.getLayoutParams());
        final ActionBar.LayoutParams ablp = lp instanceof ActionBar.LayoutParams ? (ActionBar.LayoutParams) lp
                : null;

        int horizontalMargin = 0;
        int verticalMargin = 0;
        if (ablp != null) {
            horizontalMargin = ablp.leftMargin + ablp.rightMargin;
            verticalMargin = ablp.topMargin + ablp.bottomMargin;
        }

        // If the action bar is wrapping to its content height, don't allow a custom
        // view to FILL_PARENT.
        int customNavHeightMode;
        if (mContentHeight <= 0) {
            customNavHeightMode = MeasureSpec.AT_MOST;
        } else {
            customNavHeightMode = lp.height != LayoutParams.WRAP_CONTENT ? MeasureSpec.EXACTLY
                    : MeasureSpec.AT_MOST;
        }
        final int customNavHeight = Math.max(0,
                (lp.height >= 0 ? Math.min(lp.height, height) : height) - verticalMargin);

        final int customNavWidthMode = lp.width != LayoutParams.WRAP_CONTENT ? MeasureSpec.EXACTLY
                : MeasureSpec.AT_MOST;
        int customNavWidth = Math.max(0,
                (lp.width >= 0 ? Math.min(lp.width, availableWidth) : availableWidth) - horizontalMargin);
        final int hgrav = (ablp != null ? ablp.gravity : DEFAULT_CUSTOM_GRAVITY)
                & Gravity.HORIZONTAL_GRAVITY_MASK;

        // Centering a custom view is treated specially; we try to center within the whole
        // action bar rather than in the available space.
        if (hgrav == Gravity.CENTER_HORIZONTAL && lp.width == LayoutParams.FILL_PARENT) {
            customNavWidth = Math.min(leftOfCenter, rightOfCenter) * 2;
        }

        customView.measure(MeasureSpec.makeMeasureSpec(customNavWidth, customNavWidthMode),
                MeasureSpec.makeMeasureSpec(customNavHeight, customNavHeightMode));
        availableWidth -= horizontalMargin + customView.getMeasuredWidth();
    }

    if (mExpandedActionView == null && showTitle) {
        availableWidth = measureChildView(mTitleLayout, availableWidth,
                MeasureSpec.makeMeasureSpec(mContentHeight, MeasureSpec.EXACTLY), 0);
        leftOfCenter = Math.max(0, leftOfCenter - mTitleLayout.getMeasuredWidth());
    }

    if (mContentHeight <= 0) {
        int measuredHeight = 0;
        for (int i = 0; i < childCount; i++) {
            View v = getChildAt(i);
            int paddedViewHeight = v.getMeasuredHeight() + verticalPadding;
            if (paddedViewHeight > measuredHeight) {
                measuredHeight = paddedViewHeight;
            }
        }
        setMeasuredDimension(contentWidth, measuredHeight);
    } else {
        setMeasuredDimension(contentWidth, maxHeight);
    }

    if (mContextView != null) {
        mContextView.setContentHeight(getMeasuredHeight());
    }

    if (mProgressView != null && mProgressView.getVisibility() != GONE) {
        mProgressView.measure(
                MeasureSpec.makeMeasureSpec(contentWidth - mProgressBarPadding * 2, MeasureSpec.EXACTLY),
                MeasureSpec.makeMeasureSpec(getMeasuredHeight(), MeasureSpec.AT_MOST));
    }
}

From source file:ab.util.AbDialogUtil.java

/**
 * popupwindow/*from   w  ww.  ja v a  2s . com*/
 */
public static PopupWindow showPopWindow3(Context context, View targetView, View contentView, Integer width) {
    PopupWindow popupWindow = null;
    popupWindow = new PopupWindow(contentView, -2, -2);
    popupWindow.setBackgroundDrawable(new ColorDrawable(Color.WHITE));
    if (width != null) {
        popupWindow.setWidth(width);
    }
    popupWindow.setOutsideTouchable(true);
    popupWindow.showAtLocation(targetView, Gravity.CENTER_VERTICAL | Gravity.CENTER_HORIZONTAL, 0, 0);
    return popupWindow;
}

From source file:de.mrapp.android.preference.activity.PreferenceActivity.java

/**
 * Adapts the GUI, depending on whether the navigation is currently hidden or not.
 *
 * @param navigationHidden// w  w  w  .j  a  va2  s.  c om
 *         True, if the navigation is currently hidden, false otherwise
 */
private void adaptNavigation(final boolean navigationHidden) {
    if (isSplitScreen()) {
        getPreferenceHeaderParentView().setVisibility(navigationHidden ? View.GONE : View.VISIBLE);
        FrameLayout.LayoutParams preferenceScreenLayoutParams = (FrameLayout.LayoutParams) getPreferenceScreenContainer()
                .getLayoutParams();
        preferenceScreenLayoutParams.leftMargin = (navigationHidden
                ? getResources().getDimensionPixelSize(R.dimen.preference_screen_horizontal_margin)
                : dpToPixels(this, getNavigationWidth()))
                - getResources().getDimensionPixelSize(R.dimen.card_view_intrinsic_margin);
        preferenceScreenLayoutParams.rightMargin = getResources()
                .getDimensionPixelSize(navigationHidden ? R.dimen.preference_screen_horizontal_margin
                        : R.dimen.preference_screen_margin_right)
                - getResources().getDimensionPixelSize(R.dimen.card_view_intrinsic_margin);
        preferenceScreenLayoutParams.gravity = navigationHidden ? Gravity.CENTER_HORIZONTAL
                : Gravity.NO_GRAVITY;
        getPreferenceScreenContainer().requestLayout();
        toolbarLarge.hideNavigation(navigationHidden);
    } else {
        if (isPreferenceHeaderSelected()) {
            if (navigationHidden) {
                hideToolbarNavigationIcon();
            } else {
                showToolbarNavigationIcon();
            }
        } else if (navigationHidden) {
            if (getListAdapter() != null && !getListAdapter().isEmpty()) {
                showPreferenceScreen(getListAdapter().getItem(0), null, false);
            } else if (getListAdapter() != null) {
                finish();
            }
        }
    }
}

From source file:com.skytree.epubtest.BookViewActivity.java

public void makeSeekBox() {
    RelativeLayout.LayoutParams param = new RelativeLayout.LayoutParams(
            RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT); // width,height
    seekBox = new SkyBox(this);
    seekBox.setBoxColor(Color.DKGRAY);
    seekBox.setArrowDirection(true); // to Down Arrow
    seekBox.setArrowHeight(ps(25));// w  w w . j  a v a  2s.c o  m
    param.leftMargin = ps(0);
    param.topMargin = ps(0);
    param.width = ps(300);
    param.height = ps(65);
    seekBox.setLayoutParams(param);
    // public TextView makeLabel(int id, String text, int gravity,float textSize,int textColor, int width, int height) {
    seekLabel = this.makeLabel(2000, "", Gravity.CENTER_HORIZONTAL, 13, Color.WHITE);
    this.setLocation(seekLabel, ps(10), ps(6));
    seekBox.addView(seekLabel);
    //      rv.customView.addView(seekBox);
    ePubView.addView(seekBox);
    this.hideSeekBox();
}