Example usage for android.graphics Rect Rect

List of usage examples for android.graphics Rect Rect

Introduction

In this page you can find the example usage for android.graphics Rect Rect.

Prototype

public Rect() 

Source Link

Document

Create a new empty Rect.

Usage

From source file:com.ezartech.ezar.videooverlay.ezAR.java

public void setFocus(int x, int y, final CallbackContext callbackContext) {
    int FOCUS_AREA_WIDTH = 100, FOCUS_AREA_HT = 100;

    if (!isPreviewing()) {
        //error - not in preview mode

    } else if (!focusAreaSupported) {
        //todo inform user manual focus is not supported

        return;/* w ww.j  ava2s.  com*/
    }

    Size sz = getWebViewSize();
    ArrayList<Area> focusArea = new ArrayList<Area>();
    focusArea.add(new Area(new Rect(), 1));
    ArrayList<Area> meteringArea = new ArrayList<Area>();
    meteringArea.add(new Area(new Rect(), 1));

    calculateFocusArea(FOCUS_AREA_WIDTH, FOCUS_AREA_HT, 1f, x, y, sz.width, sz.height, focusArea.get(0).rect);
    calculateFocusArea(FOCUS_AREA_WIDTH, FOCUS_AREA_HT, 1.5f, x, y, sz.width, sz.height,
            meteringArea.get(0).rect);

    Parameters parameters = camera.getParameters();
    parameters.setFocusMode(Parameters.FOCUS_MODE_CONTINUOUS_VIDEO);
    parameters.setFocusAreas(focusArea);

    if (meteringAreaSupported) {
        // Use the same area for focus and metering.
        parameters.setMeteringAreas(meteringArea);
    }

    camera.setParameters(parameters);
    camera.autoFocus(null);
}

From source file:ac.robinson.paperchains.PaperChainsActivity.java

private void processScribble(Path scribble) {
    try {/*from w w  w .  j av  a2  s. c  om*/
        // the file we're given via createTempFile is unplayable, but the name creation routine is useful...
        File outputFile = File.createTempFile(getString(R.string.app_name), ".mp4", getCacheDir());
        String outputFilePath = outputFile.getAbsolutePath();
        if (outputFile.delete()) {
            // get the bounding box and add to our list
            RectF scribbleBox = new RectF();
            scribble.computeBounds(scribbleBox, true);
            Rect audioArea = new Rect();
            scribbleBox.roundOut(audioArea);
            int scribbleWidth = Math
                    .round(getResources().getDimensionPixelSize(R.dimen.scribble_stroke_width) / 2f); // expand to include stroke width (half either side of line)
            audioArea.inset(-scribbleWidth, -scribbleWidth);

            // initialise recording
            resetRecordingInterface();
            mAudioRecorder = AudioRecorder.build(PaperChainsActivity.this, outputFilePath);

            mCurrentAudioRect = audioArea;
            mImageView.addAudioAreaRect(audioArea);
            mImageView.setScribbleEnabled(false);

            // position the recording buttons
            PointF centrePoint = mImageView
                    .imagePointToScreenPoint(new Point(audioArea.centerX(), audioArea.centerY()));
            initialiseRecordingButtons(centrePoint);
        } else {
            Toast.makeText(PaperChainsActivity.this, getString(R.string.audio_recording_setup_error),
                    Toast.LENGTH_SHORT).show();
        }

    } catch (IOException | IllegalArgumentException e) {
        Toast.makeText(PaperChainsActivity.this, getString(R.string.audio_recording_setup_error),
                Toast.LENGTH_SHORT).show();
    }
}

From source file:android.support.v17.leanback.widget.GridWidgetTest.java

public void testItemDecorationAndMarginsAndOpticalBounds() throws Throwable {
    final int leftMargin = 3;
    final int topMargin = 4;
    final int rightMargin = 7;
    final int bottomMargin = 8;
    final int itemHeight = 100;
    final int ninePatchDrawableResourceId = R.drawable.lb_card_shadow_focused;

    mInstrumentation = getInstrumentation();
    Intent intent = new Intent(mInstrumentation.getContext(), GridActivity.class);
    intent.putExtra(GridActivity.EXTRA_LAYOUT_RESOURCE_ID, R.layout.vertical_linear);
    intent.putExtra(GridActivity.EXTRA_ITEMS, new int[] { itemHeight, itemHeight, itemHeight });
    intent.putExtra(GridActivity.EXTRA_CHILD_LAYOUT_ID, R.layout.relative_layout);
    intent.putExtra(GridActivity.EXTRA_LAYOUT_MARGINS,
            new int[] { leftMargin, topMargin, rightMargin, bottomMargin });
    intent.putExtra(GridActivity.EXTRA_NINEPATCH_SHADOW, ninePatchDrawableResourceId);
    initActivity(intent);//  ww  w  .jav a 2 s . c  o  m
    mOrientation = BaseGridView.VERTICAL;
    mNumRows = 1;

    final int paddingLeft = mGridView.getPaddingLeft();
    final int paddingTop = mGridView.getPaddingTop();
    final int verticalSpace = mGridView.getVerticalMargin();
    final int decorationLeft = 17;
    final int decorationTop = 1;
    final int decorationRight = 19;
    final int decorationBottom = 2;

    final Rect opticalPaddings = new Rect();
    mGridView.getContext().getDrawable(ninePatchDrawableResourceId).getPadding(opticalPaddings);
    final int opticalInsetsLeft = opticalPaddings.left;
    final int opticalInsetsTop = opticalPaddings.top;
    final int opticalInsetsRight = opticalPaddings.right;
    final int opticalInsetsBottom = opticalPaddings.bottom;
    assertTrue(opticalInsetsLeft > 0);
    assertTrue(opticalInsetsTop > 0);
    assertTrue(opticalInsetsRight > 0);
    assertTrue(opticalInsetsBottom > 0);

    runTestOnUiThread(new Runnable() {
        public void run() {
            mGridView.addItemDecoration(
                    new DividerDecoration(decorationLeft, decorationTop, decorationRight, decorationBottom));
        }
    });
    waitForScrollIdle();

    View child0 = mGridView.getChildAt(0);
    View child1 = mGridView.getChildAt(1);
    View child2 = mGridView.getChildAt(2);

    assertEquals(itemHeight + opticalInsetsTop + opticalInsetsBottom, child0.getBottom() - child0.getTop());

    // verify left margins decoration and optical insets
    assertEquals(paddingLeft + leftMargin + decorationLeft - opticalInsetsLeft, child0.getLeft());
    assertEquals(paddingLeft + leftMargin + decorationLeft - opticalInsetsLeft, child1.getLeft());
    assertEquals(paddingLeft + leftMargin + decorationLeft - opticalInsetsLeft, child2.getLeft());
    // verify top bottom margins decoration offset and optical insets
    assertEquals(paddingTop + topMargin + decorationTop, child0.getTop() + opticalInsetsTop);
    assertEquals(bottomMargin + decorationBottom + verticalSpace + decorationTop + topMargin,
            (child1.getTop() + opticalInsetsTop) - (child0.getBottom() - opticalInsetsBottom));
    assertEquals(bottomMargin + decorationBottom + verticalSpace + decorationTop + topMargin,
            (child2.getTop() + opticalInsetsTop) - (child1.getBottom() - opticalInsetsBottom));

}

From source file:me.ububble.speakall.fragment.ConversationGroupFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_conversation_group, container, false);
    activity = getActivity();//from w  ww  .j  a  v a 2s.  c  om
    f = new Finder(activity);
    ButterKnife.inject(this, view);
    ((MainActivity) activity).menuBottom.setVisibility(View.GONE);
    ((MainActivity) activity).actionBar.setVisibility(View.VISIBLE);
    //        if (!setted)
    if (BackgroundFragment.getBackgroundChat(activity) != 0)
        backgroundChat.setImageDrawable(
                activity.getResources().getDrawable(BackgroundFragment.getBackgroundChat(activity)));

    messageText.conversationGroupFragment = this;
    TFCache.apply(activity, messageSend, TFCache.TF_SPEAKALL);
    TFCache.apply(activity, messageTranslate, TFCache.TF_SPEAKALL);
    TFCache.apply(activity, messageClock, TFCache.TF_SPEAKALL);
    TFCache.apply(activity, messageText, TFCache.TF_WHITNEY_LIGHT);
    TFCache.apply(activity, temporLanel, TFCache.TF_WHITNEY_BOLD);
    TFCache.apply(activity, temporizadorCancel, TFCache.TF_WHITNEY_LIGHT);
    TFCache.apply(activity, temporizadorAcept, TFCache.TF_WHITNEY_LIGHT);
    TFCache.apply(activity, textRecordingPress, TFCache.TF_WHITNEY_LIGHT);
    temporizadorAcept.setVisibility(View.INVISIBLE);

    TFCache.apply(activity, adjuntContact, TFCache.TF_SPEAKALL);
    TFCache.apply(activity, adjuntPhoto, TFCache.TF_SPEAKALL);
    TFCache.apply(activity, adjuntAudio, TFCache.TF_SPEAKALL);
    TFCache.apply(activity, adjuntLocation, TFCache.TF_SPEAKALL);
    TFCache.apply(activity, adjuntVideo, TFCache.TF_SPEAKALL);
    TFCache.apply(activity, adjuntImage, TFCache.TF_SPEAKON);

    messageText.setOnClickListener(this);
    messageTranslate.setOnClickListener(this);
    messageClock.setOnClickListener(this);
    temporizadorAcept.setOnClickListener(this);
    temporizadorCancel.setOnClickListener(this);
    adjuntContact.setOnClickListener(this);
    adjuntPhoto.setOnClickListener(this);
    adjuntAudio.setOnClickListener(this);
    adjuntLocation.setOnClickListener(this);
    adjuntVideo.setOnClickListener(this);
    adjuntImage.setOnClickListener(this);
    time1.setOnClickListener(this);
    time2.setOnClickListener(this);
    time3.setOnClickListener(this);
    time4.setOnClickListener(this);
    time5.setOnClickListener(this);
    time6.setOnClickListener(this);
    time7.setOnClickListener(this);
    time8.setOnClickListener(this);
    time9.setOnClickListener(this);
    time10.setOnClickListener(this);
    time11.setOnClickListener(this);
    time12.setOnClickListener(this);
    recordAudioButton.setOnTouchListener(this);
    messageText.requestFocus();

    messageSend.setText(Finder.STRING.ICN_SEND_MSJ.toString());
    messageTranslate.setText(Finder.STRING.ICN_TRANSLATE.toString());
    messageClock.setText(Finder.STRING.ICN_TEMPORIZER.toString());
    sv.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            return true;
        }
    });
    sv.setVerticalScrollBarEnabled(false);
    sv.setHorizontalScrollBarEnabled(false);
    final SharedPreferences settings = activity.getSharedPreferences(Finder.STRING.APP_PREF.toString(),
            Context.MODE_PRIVATE);
    keyBoardHeight = settings.getInt("INPUTKEY", 0);
    if (keyBoardHeight == 0) {
        getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
        messageText.postDelayed(new Runnable() {
            @Override
            public void run() { // TODO Auto-generated method stub
                InputMethodManager keyboard = (InputMethodManager) getActivity()
                        .getSystemService(Context.INPUT_METHOD_SERVICE);
                keyboard.showSoftInput(messageText, 0);
            }
        }, 50);
        isShowKeyboard = true;
        final Window mRootWindow = activity.getWindow();
        final View mRootView = mRootWindow.getDecorView().findViewById(android.R.id.content);
        mRootView.getViewTreeObserver()
                .addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
                    public void onGlobalLayout() {
                        Rect r = new Rect();
                        View view = mRootWindow.getDecorView();
                        view.getWindowVisibleDisplayFrame(r);
                        if (prevSize == 0)
                            prevSize = r.bottom;
                        else if (prevSize != r.bottom) {
                            if (prevSize - r.bottom > 150) {
                                keyBoardHeight = prevSize - r.bottom;
                                SharedPreferences.Editor editor = settings.edit();
                                editor.putInt("INPUTKEY", keyBoardHeight);
                                editor.apply();
                                keyboardLayout.setLayoutParams(new LinearLayout.LayoutParams(
                                        ViewGroup.LayoutParams.MATCH_PARENT, keyBoardHeight));
                                isShowKeyboard = true;
                                isShowKeyboard = true;
                                isShowCustomKeyboard = false;
                                mRootView.getViewTreeObserver().removeGlobalOnLayoutListener(this);
                            }
                        }
                        // r.left, r.top, r.right, r.bottom
                    }//2464   -- 1772 -- 692
                     //1184    -- 660  -- 524
                });
    } else {
        isShowKeyboard = false;
        getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_NOTHING);
        keyboardLayout.setLayoutParams(
                new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, keyBoardHeight));
        Log.e("tamao teclado",
                keyBoardHeight + " : " + pxFromDp(activity, 240) + " : " + pxFromDp(activity, 180));
        if (keyBoardHeight > pxFromDp(activity, 240)) {
            ((LinearLayout.LayoutParams) seekBarContent.getLayoutParams()).width = (int) pxFromDp(activity,
                    180);
            ((LinearLayout.LayoutParams) seekBarContent.getLayoutParams()).height = (int) pxFromDp(activity,
                    180);

            ((RelativeLayout.LayoutParams) tapsContent.getLayoutParams()).width = (int) pxFromDp(activity, 180);
            ((RelativeLayout.LayoutParams) tapsContent.getLayoutParams()).height = (int) pxFromDp(activity,
                    180);

            ((RelativeLayout.LayoutParams) temporizadorSeek.getLayoutParams()).width = (int) pxFromDp(activity,
                    140);
            ((RelativeLayout.LayoutParams) temporizadorSeek.getLayoutParams()).height = (int) pxFromDp(activity,
                    140);
            temporizadorSeek.atributesCode(20, 16, 25);
            temporLanel.setTextSize(18);

            ((RelativeLayout.LayoutParams) time1.getLayoutParams()).height = (int) pxFromDp(activity, 30);
            ((RelativeLayout.LayoutParams) time1.getLayoutParams()).width = (int) pxFromDp(activity, 30);
            ((RelativeLayout.LayoutParams) time1.getLayoutParams()).topMargin = (int) pxFromDp(activity, 25);
            ((RelativeLayout.LayoutParams) time1.getLayoutParams()).leftMargin = (int) pxFromDp(activity, 90);

            ((RelativeLayout.LayoutParams) time2.getLayoutParams()).height = (int) pxFromDp(activity, 30);
            ((RelativeLayout.LayoutParams) time2.getLayoutParams()).width = (int) pxFromDp(activity, 30);
            ((RelativeLayout.LayoutParams) time2.getLayoutParams()).topMargin = (int) pxFromDp(activity, 35);
            ((RelativeLayout.LayoutParams) time2.getLayoutParams()).leftMargin = (int) pxFromDp(activity, 115);

            ((RelativeLayout.LayoutParams) time3.getLayoutParams()).height = (int) pxFromDp(activity, 30);
            ((RelativeLayout.LayoutParams) time3.getLayoutParams()).width = (int) pxFromDp(activity, 30);
            ((RelativeLayout.LayoutParams) time3.getLayoutParams()).topMargin = (int) pxFromDp(activity, 65);
            ((RelativeLayout.LayoutParams) time3.getLayoutParams()).leftMargin = (int) pxFromDp(activity, 128);

            ((RelativeLayout.LayoutParams) time4.getLayoutParams()).height = (int) pxFromDp(activity, 30);
            ((RelativeLayout.LayoutParams) time4.getLayoutParams()).width = (int) pxFromDp(activity, 30);
            ((RelativeLayout.LayoutParams) time4.getLayoutParams()).topMargin = (int) pxFromDp(activity, 92);
            ((RelativeLayout.LayoutParams) time4.getLayoutParams()).leftMargin = (int) pxFromDp(activity, 128);

            ((RelativeLayout.LayoutParams) time5.getLayoutParams()).height = (int) pxFromDp(activity, 30);
            ((RelativeLayout.LayoutParams) time5.getLayoutParams()).width = (int) pxFromDp(activity, 30);
            ((RelativeLayout.LayoutParams) time5.getLayoutParams()).topMargin = (int) pxFromDp(activity, 118);
            ((RelativeLayout.LayoutParams) time5.getLayoutParams()).leftMargin = (int) pxFromDp(activity, 115);

            ((RelativeLayout.LayoutParams) time6.getLayoutParams()).height = (int) pxFromDp(activity, 30);
            ((RelativeLayout.LayoutParams) time6.getLayoutParams()).width = (int) pxFromDp(activity, 30);
            ((RelativeLayout.LayoutParams) time6.getLayoutParams()).topMargin = (int) pxFromDp(activity, 130);
            ((RelativeLayout.LayoutParams) time6.getLayoutParams()).leftMargin = (int) pxFromDp(activity, 90);

            ((RelativeLayout.LayoutParams) time7.getLayoutParams()).height = (int) pxFromDp(activity, 30);
            ((RelativeLayout.LayoutParams) time7.getLayoutParams()).width = (int) pxFromDp(activity, 30);
            ((RelativeLayout.LayoutParams) time7.getLayoutParams()).topMargin = (int) pxFromDp(activity, 130);
            ((RelativeLayout.LayoutParams) time7.getLayoutParams()).leftMargin = (int) pxFromDp(activity, 60);

            ((RelativeLayout.LayoutParams) time8.getLayoutParams()).height = (int) pxFromDp(activity, 30);
            ((RelativeLayout.LayoutParams) time8.getLayoutParams()).width = (int) pxFromDp(activity, 30);
            ((RelativeLayout.LayoutParams) time8.getLayoutParams()).topMargin = (int) pxFromDp(activity, 118);
            ((RelativeLayout.LayoutParams) time8.getLayoutParams()).leftMargin = (int) pxFromDp(activity, 37);

            ((RelativeLayout.LayoutParams) time9.getLayoutParams()).height = (int) pxFromDp(activity, 30);
            ((RelativeLayout.LayoutParams) time9.getLayoutParams()).width = (int) pxFromDp(activity, 30);
            ((RelativeLayout.LayoutParams) time9.getLayoutParams()).topMargin = (int) pxFromDp(activity, 92);
            ((RelativeLayout.LayoutParams) time9.getLayoutParams()).leftMargin = (int) pxFromDp(activity, 24);

            ((RelativeLayout.LayoutParams) time10.getLayoutParams()).height = (int) pxFromDp(activity, 30);
            ((RelativeLayout.LayoutParams) time10.getLayoutParams()).width = (int) pxFromDp(activity, 30);
            ((RelativeLayout.LayoutParams) time10.getLayoutParams()).topMargin = (int) pxFromDp(activity, 65);
            ((RelativeLayout.LayoutParams) time10.getLayoutParams()).leftMargin = (int) pxFromDp(activity, 24);

            ((RelativeLayout.LayoutParams) time11.getLayoutParams()).height = (int) pxFromDp(activity, 30);
            ((RelativeLayout.LayoutParams) time11.getLayoutParams()).width = (int) pxFromDp(activity, 30);
            ((RelativeLayout.LayoutParams) time11.getLayoutParams()).topMargin = (int) pxFromDp(activity, 35);
            ((RelativeLayout.LayoutParams) time11.getLayoutParams()).leftMargin = (int) pxFromDp(activity, 37);

            ((RelativeLayout.LayoutParams) time12.getLayoutParams()).height = (int) pxFromDp(activity, 30);
            ((RelativeLayout.LayoutParams) time12.getLayoutParams()).width = (int) pxFromDp(activity, 30);
            ((RelativeLayout.LayoutParams) time12.getLayoutParams()).topMargin = (int) pxFromDp(activity, 25);
            ((RelativeLayout.LayoutParams) time12.getLayoutParams()).leftMargin = (int) pxFromDp(activity, 60);
        } else if (keyBoardHeight > pxFromDp(activity, 180)) {
            ((LinearLayout.LayoutParams) seekBarContent.getLayoutParams()).width = (int) pxFromDp(activity,
                    130);
            ((LinearLayout.LayoutParams) seekBarContent.getLayoutParams()).height = (int) pxFromDp(activity,
                    130);

            ((RelativeLayout.LayoutParams) tapsContent.getLayoutParams()).width = (int) pxFromDp(activity, 130);
            ((RelativeLayout.LayoutParams) tapsContent.getLayoutParams()).height = (int) pxFromDp(activity,
                    130);

            ((RelativeLayout.LayoutParams) temporizadorSeek.getLayoutParams()).width = (int) pxFromDp(activity,
                    110);
            ((RelativeLayout.LayoutParams) temporizadorSeek.getLayoutParams()).height = (int) pxFromDp(activity,
                    110);
            temporizadorSeek.atributesCode(15, 16, 9);
            temporLanel.setTextSize(14);

            ((RelativeLayout.LayoutParams) time1.getLayoutParams()).height = (int) pxFromDp(activity, 20);
            ((RelativeLayout.LayoutParams) time1.getLayoutParams()).width = (int) pxFromDp(activity, 20);
            ((RelativeLayout.LayoutParams) time1.getLayoutParams()).topMargin = (int) pxFromDp(activity, 19);
            ((RelativeLayout.LayoutParams) time1.getLayoutParams()).leftMargin = (int) pxFromDp(activity, 66);

            ((RelativeLayout.LayoutParams) time2.getLayoutParams()).height = (int) pxFromDp(activity, 20);
            ((RelativeLayout.LayoutParams) time2.getLayoutParams()).width = (int) pxFromDp(activity, 20);
            ((RelativeLayout.LayoutParams) time2.getLayoutParams()).topMargin = (int) pxFromDp(activity, 29);
            ((RelativeLayout.LayoutParams) time2.getLayoutParams()).leftMargin = (int) pxFromDp(activity, 85);

            ((RelativeLayout.LayoutParams) time3.getLayoutParams()).height = (int) pxFromDp(activity, 20);
            ((RelativeLayout.LayoutParams) time3.getLayoutParams()).width = (int) pxFromDp(activity, 20);
            ((RelativeLayout.LayoutParams) time3.getLayoutParams()).topMargin = (int) pxFromDp(activity, 47);
            ((RelativeLayout.LayoutParams) time3.getLayoutParams()).leftMargin = (int) pxFromDp(activity, 94);

            ((RelativeLayout.LayoutParams) time4.getLayoutParams()).height = (int) pxFromDp(activity, 20);
            ((RelativeLayout.LayoutParams) time4.getLayoutParams()).width = (int) pxFromDp(activity, 20);
            ((RelativeLayout.LayoutParams) time4.getLayoutParams()).topMargin = (int) pxFromDp(activity, 67);
            ((RelativeLayout.LayoutParams) time4.getLayoutParams()).leftMargin = (int) pxFromDp(activity, 94);

            ((RelativeLayout.LayoutParams) time5.getLayoutParams()).height = (int) pxFromDp(activity, 20);
            ((RelativeLayout.LayoutParams) time5.getLayoutParams()).width = (int) pxFromDp(activity, 20);
            ((RelativeLayout.LayoutParams) time5.getLayoutParams()).topMargin = (int) pxFromDp(activity, 85);
            ((RelativeLayout.LayoutParams) time5.getLayoutParams()).leftMargin = (int) pxFromDp(activity, 85);

            ((RelativeLayout.LayoutParams) time6.getLayoutParams()).height = (int) pxFromDp(activity, 20);
            ((RelativeLayout.LayoutParams) time6.getLayoutParams()).width = (int) pxFromDp(activity, 20);
            ((RelativeLayout.LayoutParams) time6.getLayoutParams()).topMargin = (int) pxFromDp(activity, 95);
            ((RelativeLayout.LayoutParams) time6.getLayoutParams()).leftMargin = (int) pxFromDp(activity, 66);

            ((RelativeLayout.LayoutParams) time7.getLayoutParams()).height = (int) pxFromDp(activity, 20);
            ((RelativeLayout.LayoutParams) time7.getLayoutParams()).width = (int) pxFromDp(activity, 20);
            ((RelativeLayout.LayoutParams) time7.getLayoutParams()).topMargin = (int) pxFromDp(activity, 95);
            ((RelativeLayout.LayoutParams) time7.getLayoutParams()).leftMargin = (int) pxFromDp(activity, 45);

            ((RelativeLayout.LayoutParams) time8.getLayoutParams()).height = (int) pxFromDp(activity, 20);
            ((RelativeLayout.LayoutParams) time8.getLayoutParams()).width = (int) pxFromDp(activity, 20);
            ((RelativeLayout.LayoutParams) time8.getLayoutParams()).topMargin = (int) pxFromDp(activity, 85);
            ((RelativeLayout.LayoutParams) time8.getLayoutParams()).leftMargin = (int) pxFromDp(activity, 28);

            ((RelativeLayout.LayoutParams) time9.getLayoutParams()).height = (int) pxFromDp(activity, 20);
            ((RelativeLayout.LayoutParams) time9.getLayoutParams()).width = (int) pxFromDp(activity, 20);
            ((RelativeLayout.LayoutParams) time9.getLayoutParams()).topMargin = (int) pxFromDp(activity, 67);
            ((RelativeLayout.LayoutParams) time9.getLayoutParams()).leftMargin = (int) pxFromDp(activity, 18);

            ((RelativeLayout.LayoutParams) time10.getLayoutParams()).height = (int) pxFromDp(activity, 20);
            ((RelativeLayout.LayoutParams) time10.getLayoutParams()).width = (int) pxFromDp(activity, 20);
            ((RelativeLayout.LayoutParams) time10.getLayoutParams()).topMargin = (int) pxFromDp(activity, 47);
            ((RelativeLayout.LayoutParams) time10.getLayoutParams()).leftMargin = (int) pxFromDp(activity, 18);

            ((RelativeLayout.LayoutParams) time11.getLayoutParams()).height = (int) pxFromDp(activity, 20);
            ((RelativeLayout.LayoutParams) time11.getLayoutParams()).width = (int) pxFromDp(activity, 20);
            ((RelativeLayout.LayoutParams) time11.getLayoutParams()).topMargin = (int) pxFromDp(activity, 29);
            ((RelativeLayout.LayoutParams) time11.getLayoutParams()).leftMargin = (int) pxFromDp(activity, 28);

            ((RelativeLayout.LayoutParams) time12.getLayoutParams()).height = (int) pxFromDp(activity, 20);
            ((RelativeLayout.LayoutParams) time12.getLayoutParams()).width = (int) pxFromDp(activity, 20);
            ((RelativeLayout.LayoutParams) time12.getLayoutParams()).topMargin = (int) pxFromDp(activity, 19);
            ((RelativeLayout.LayoutParams) time12.getLayoutParams()).leftMargin = (int) pxFromDp(activity, 45);

        }
    }
    messagesList.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
        @Override
        public void onGlobalLayout() {
            if (scrollOnBottom) {
                messagesListScroll.scrollTo(0, messagesList.getBottom());
            } else {
                messagesListScroll.scrollTo(0, ((messagesList.getHeight() - messagesValuePrev) + scrollValue)
                        + (scrollHeight - messagesListScroll.getHeight()));
                messagesListScroll.setVerticalScrollBarEnabled(true);
            }

        }
    });
    messagesListScroll.getViewTreeObserver()
            .addOnScrollChangedListener(new ViewTreeObserver.OnScrollChangedListener() {
                @Override
                public void onScrollChanged() {
                    if (messagesList.getHeight() - messagesListScroll.getScrollY() <= messagesListScroll
                            .getHeight()) {
                        scrollOnBottom = true;
                    } else {
                        scrollOnBottom = false;
                        messagesValuePrev = messagesList.getHeight();
                        scrollValue = messagesListScroll.getScrollY();
                        scrollHeight = messagesListScroll.getHeight();
                    }
                }
            });

    messageSend.setOnClickListener(this);
    messageText.addTextChangedListener(new TextWatcher() {
        @Override
        public void afterTextChanged(Editable arg0) {
        }

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            if (messageText.getText().length() > 0) {
                messageSend.setVisibility(View.VISIBLE);
                messageSednDivider.setVisibility(View.VISIBLE);
            } else {
                messageSend.setVisibility(View.GONE);
                messageSednDivider.setVisibility(View.GONE);
            }
        }
    });
    u = new Select().from(User.class).executeSingle();
    ((MainActivity) activity).setOnBackPressedListener(null);

    return view;
}

From source file:free.yhc.netmbuddy.utils.Utils.java

/**
 * Only available when status bar is showing.
 * @param activity/*from  ww w .  j av a 2  s.  c o  m*/
 * @return
 */
public static int getStatusBarHeight(Activity activity) {
    Rect rect = new Rect();
    Window window = activity.getWindow();
    window.getDecorView().getWindowVisibleDisplayFrame(rect);
    // Below is for future reference.
    // int StatusBarHeight = rect.top;
    // int contentViewTop = window.findViewById(Window.ID_ANDROID_CONTENT).getTop();
    // int TitleBarHeight= contentViewTop - StatusBarHeight;
    return rect.top;
}

From source file:me.ububble.speakall.fragment.ConversationChatFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_conversation_chat, container, false);
    activity = getActivity();//  ww  w .j a v a 2 s . c o m
    f = new Finder(activity);
    ButterKnife.inject(this, view);
    ((MainActivity) activity).actionBar.setVisibility(View.VISIBLE);
    ((MainActivity) activity).menuBottom.setVisibility(View.GONE);

    if (BackgroundFragment.getBackgroundChat(activity) != 0)
        backgroundChat.setImageDrawable(
                activity.getResources().getDrawable(BackgroundFragment.getBackgroundChat(activity)));

    messageText.conversationChatFragment = this;
    TFCache.apply(activity, messageSend, TFCache.TF_SPEAKALL);
    TFCache.apply(activity, messageTranslate, TFCache.TF_SPEAKALL);
    TFCache.apply(activity, messageClock, TFCache.TF_SPEAKALL);
    TFCache.apply(activity, messageText, TFCache.TF_WHITNEY_LIGHT);
    TFCache.apply(activity, temporLanel, TFCache.TF_WHITNEY_BOLD);
    TFCache.apply(activity, addToContacts, TFCache.TF_WHITNEY_LIGHT);
    TFCache.apply(activity, temporizadorCancel, TFCache.TF_WHITNEY_LIGHT);
    TFCache.apply(activity, temporizadorAcept, TFCache.TF_WHITNEY_LIGHT);
    TFCache.apply(activity, textRecording, TFCache.TF_WHITNEY_LIGHT);
    TFCache.apply(activity, textRecordingPress, TFCache.TF_WHITNEY_LIGHT);
    TFCache.apply(activity, timerAudio, TFCache.TF_WHITNEY_LIGHT);
    TFCache.apply(activity, cancelAudio, TFCache.TF_WHITNEY_LIGHT);
    TFCache.apply(activity, audioRecordBackground, TFCache.TF_WHITNEY_LIGHT);
    temporizadorAcept.setVisibility(View.INVISIBLE);
    longclick = false;
    saveAudio = false;

    TFCache.apply(activity, adjuntContact, TFCache.TF_SPEAKALL);
    TFCache.apply(activity, adjuntPhoto, TFCache.TF_SPEAKALL);
    TFCache.apply(activity, adjuntAudio, TFCache.TF_SPEAKALL);
    TFCache.apply(activity, adjuntLocation, TFCache.TF_SPEAKALL);
    TFCache.apply(activity, adjuntVideo, TFCache.TF_SPEAKALL);
    TFCache.apply(activity, adjuntImage, TFCache.TF_SPEAKALL);

    messageText.setOnClickListener(this);
    messageTranslate.setOnClickListener(this);
    messageClock.setOnClickListener(this);
    temporizadorAcept.setOnClickListener(this);
    temporizadorCancel.setOnClickListener(this);
    adjuntContact.setOnClickListener(this);
    adjuntPhoto.setOnClickListener(this);
    adjuntAudio.setOnClickListener(this);
    adjuntLocation.setOnClickListener(this);
    adjuntVideo.setOnClickListener(this);
    adjuntImage.setOnClickListener(this);
    addToContacts.setOnClickListener(this);
    time1.setOnClickListener(this);
    time2.setOnClickListener(this);
    time3.setOnClickListener(this);
    time4.setOnClickListener(this);
    time5.setOnClickListener(this);
    time6.setOnClickListener(this);
    time7.setOnClickListener(this);
    time8.setOnClickListener(this);
    time9.setOnClickListener(this);
    time10.setOnClickListener(this);
    time11.setOnClickListener(this);
    time12.setOnClickListener(this);
    recordAudioButton.setOnTouchListener(this);
    messageText.requestFocus();

    dateDay1 = new SimpleDateFormat("d");
    dateDayText1 = new SimpleDateFormat("EEEE");
    dateMonth1 = new SimpleDateFormat("MMMM");
    dateYear1 = new SimpleDateFormat("yyyy");
    timeFormat1 = new SimpleDateFormat("h:mm a");

    messageSend.setText(Finder.STRING.ICN_SEND_MSJ.toString());
    messageTranslate.setText(Finder.STRING.ICN_TRANSLATE.toString());
    messageClock.setText(Finder.STRING.ICN_TEMPORIZER.toString());
    sv.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            return true;
        }
    });
    sv.setVerticalScrollBarEnabled(false);
    sv.setHorizontalScrollBarEnabled(false);

    final SharedPreferences settings = activity.getSharedPreferences(Finder.STRING.APP_PREF.toString(),
            Context.MODE_PRIVATE);
    keyBoardHeight = settings.getInt("INPUTKEY", 0);

    if (keyBoardHeight == 0) {
        getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
        messageText.postDelayed(new Runnable() {
            @Override
            public void run() {
                InputMethodManager keyboard = (InputMethodManager) getActivity()
                        .getSystemService(Context.INPUT_METHOD_SERVICE);
                keyboard.showSoftInput(messageText, 0);

            }
        }, 50);
        isShowKeyboard = true;
        final Window mRootWindow = activity.getWindow();
        final View mRootView = mRootWindow.getDecorView().findViewById(android.R.id.content);
        mRootView.getViewTreeObserver()
                .addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
                    public void onGlobalLayout() {

                        Rect r = new Rect();
                        View view = mRootWindow.getDecorView();
                        view.getWindowVisibleDisplayFrame(r);
                        if (prevSize == 0)
                            prevSize = r.bottom;
                        else if (prevSize != r.bottom) {
                            if (prevSize - r.bottom > 150) {
                                keyBoardHeight = prevSize - r.bottom;
                                SharedPreferences.Editor editor = settings.edit();
                                editor.putInt("INPUTKEY", keyBoardHeight);
                                editor.apply();
                                keyboardLayout.setLayoutParams(new LinearLayout.LayoutParams(
                                        ViewGroup.LayoutParams.MATCH_PARENT, keyBoardHeight));
                                isShowKeyboard = true;
                                isShowCustomKeyboard = false;
                                mRootView.getViewTreeObserver().removeGlobalOnLayoutListener(this);

                            }
                        }
                    }
                });

    } else {
        isShowKeyboard = false;
        getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_NOTHING);
        keyboardLayout.setLayoutParams(
                new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, keyBoardHeight));
        if (keyBoardHeight > pxFromDp(activity, 240)) {
            ((LinearLayout.LayoutParams) seekBarContent.getLayoutParams()).width = (int) pxFromDp(activity,
                    180);
            ((LinearLayout.LayoutParams) seekBarContent.getLayoutParams()).height = (int) pxFromDp(activity,
                    180);

            ((RelativeLayout.LayoutParams) tapsContent.getLayoutParams()).width = (int) pxFromDp(activity, 180);
            ((RelativeLayout.LayoutParams) tapsContent.getLayoutParams()).height = (int) pxFromDp(activity,
                    180);

            ((RelativeLayout.LayoutParams) temporizadorSeek.getLayoutParams()).width = (int) pxFromDp(activity,
                    140);
            ((RelativeLayout.LayoutParams) temporizadorSeek.getLayoutParams()).height = (int) pxFromDp(activity,
                    140);
            temporizadorSeek.atributesCode(20, 16, 25);
            temporLanel.setTextSize(18);

            ((RelativeLayout.LayoutParams) time1.getLayoutParams()).height = (int) pxFromDp(activity, 30);
            ((RelativeLayout.LayoutParams) time1.getLayoutParams()).width = (int) pxFromDp(activity, 30);
            ((RelativeLayout.LayoutParams) time1.getLayoutParams()).topMargin = (int) pxFromDp(activity, 25);
            ((RelativeLayout.LayoutParams) time1.getLayoutParams()).leftMargin = (int) pxFromDp(activity, 90);

            ((RelativeLayout.LayoutParams) time2.getLayoutParams()).height = (int) pxFromDp(activity, 30);
            ((RelativeLayout.LayoutParams) time2.getLayoutParams()).width = (int) pxFromDp(activity, 30);
            ((RelativeLayout.LayoutParams) time2.getLayoutParams()).topMargin = (int) pxFromDp(activity, 35);
            ((RelativeLayout.LayoutParams) time2.getLayoutParams()).leftMargin = (int) pxFromDp(activity, 115);

            ((RelativeLayout.LayoutParams) time3.getLayoutParams()).height = (int) pxFromDp(activity, 30);
            ((RelativeLayout.LayoutParams) time3.getLayoutParams()).width = (int) pxFromDp(activity, 30);
            ((RelativeLayout.LayoutParams) time3.getLayoutParams()).topMargin = (int) pxFromDp(activity, 65);
            ((RelativeLayout.LayoutParams) time3.getLayoutParams()).leftMargin = (int) pxFromDp(activity, 128);

            ((RelativeLayout.LayoutParams) time4.getLayoutParams()).height = (int) pxFromDp(activity, 30);
            ((RelativeLayout.LayoutParams) time4.getLayoutParams()).width = (int) pxFromDp(activity, 30);
            ((RelativeLayout.LayoutParams) time4.getLayoutParams()).topMargin = (int) pxFromDp(activity, 92);
            ((RelativeLayout.LayoutParams) time4.getLayoutParams()).leftMargin = (int) pxFromDp(activity, 128);

            ((RelativeLayout.LayoutParams) time5.getLayoutParams()).height = (int) pxFromDp(activity, 30);
            ((RelativeLayout.LayoutParams) time5.getLayoutParams()).width = (int) pxFromDp(activity, 30);
            ((RelativeLayout.LayoutParams) time5.getLayoutParams()).topMargin = (int) pxFromDp(activity, 118);
            ((RelativeLayout.LayoutParams) time5.getLayoutParams()).leftMargin = (int) pxFromDp(activity, 115);

            ((RelativeLayout.LayoutParams) time6.getLayoutParams()).height = (int) pxFromDp(activity, 30);
            ((RelativeLayout.LayoutParams) time6.getLayoutParams()).width = (int) pxFromDp(activity, 30);
            ((RelativeLayout.LayoutParams) time6.getLayoutParams()).topMargin = (int) pxFromDp(activity, 130);
            ((RelativeLayout.LayoutParams) time6.getLayoutParams()).leftMargin = (int) pxFromDp(activity, 90);

            ((RelativeLayout.LayoutParams) time7.getLayoutParams()).height = (int) pxFromDp(activity, 30);
            ((RelativeLayout.LayoutParams) time7.getLayoutParams()).width = (int) pxFromDp(activity, 30);
            ((RelativeLayout.LayoutParams) time7.getLayoutParams()).topMargin = (int) pxFromDp(activity, 130);
            ((RelativeLayout.LayoutParams) time7.getLayoutParams()).leftMargin = (int) pxFromDp(activity, 60);

            ((RelativeLayout.LayoutParams) time8.getLayoutParams()).height = (int) pxFromDp(activity, 30);
            ((RelativeLayout.LayoutParams) time8.getLayoutParams()).width = (int) pxFromDp(activity, 30);
            ((RelativeLayout.LayoutParams) time8.getLayoutParams()).topMargin = (int) pxFromDp(activity, 118);
            ((RelativeLayout.LayoutParams) time8.getLayoutParams()).leftMargin = (int) pxFromDp(activity, 37);

            ((RelativeLayout.LayoutParams) time9.getLayoutParams()).height = (int) pxFromDp(activity, 30);
            ((RelativeLayout.LayoutParams) time9.getLayoutParams()).width = (int) pxFromDp(activity, 30);
            ((RelativeLayout.LayoutParams) time9.getLayoutParams()).topMargin = (int) pxFromDp(activity, 92);
            ((RelativeLayout.LayoutParams) time9.getLayoutParams()).leftMargin = (int) pxFromDp(activity, 24);

            ((RelativeLayout.LayoutParams) time10.getLayoutParams()).height = (int) pxFromDp(activity, 30);
            ((RelativeLayout.LayoutParams) time10.getLayoutParams()).width = (int) pxFromDp(activity, 30);
            ((RelativeLayout.LayoutParams) time10.getLayoutParams()).topMargin = (int) pxFromDp(activity, 65);
            ((RelativeLayout.LayoutParams) time10.getLayoutParams()).leftMargin = (int) pxFromDp(activity, 24);

            ((RelativeLayout.LayoutParams) time11.getLayoutParams()).height = (int) pxFromDp(activity, 30);
            ((RelativeLayout.LayoutParams) time11.getLayoutParams()).width = (int) pxFromDp(activity, 30);
            ((RelativeLayout.LayoutParams) time11.getLayoutParams()).topMargin = (int) pxFromDp(activity, 35);
            ((RelativeLayout.LayoutParams) time11.getLayoutParams()).leftMargin = (int) pxFromDp(activity, 37);

            ((RelativeLayout.LayoutParams) time12.getLayoutParams()).height = (int) pxFromDp(activity, 30);
            ((RelativeLayout.LayoutParams) time12.getLayoutParams()).width = (int) pxFromDp(activity, 30);
            ((RelativeLayout.LayoutParams) time12.getLayoutParams()).topMargin = (int) pxFromDp(activity, 25);
            ((RelativeLayout.LayoutParams) time12.getLayoutParams()).leftMargin = (int) pxFromDp(activity, 60);
        } else if (keyBoardHeight > pxFromDp(activity, 180)) {
            ((LinearLayout.LayoutParams) seekBarContent.getLayoutParams()).width = (int) pxFromDp(activity,
                    130);
            ((LinearLayout.LayoutParams) seekBarContent.getLayoutParams()).height = (int) pxFromDp(activity,
                    130);

            ((RelativeLayout.LayoutParams) tapsContent.getLayoutParams()).width = (int) pxFromDp(activity, 130);
            ((RelativeLayout.LayoutParams) tapsContent.getLayoutParams()).height = (int) pxFromDp(activity,
                    130);

            ((RelativeLayout.LayoutParams) temporizadorSeek.getLayoutParams()).width = (int) pxFromDp(activity,
                    110);
            ((RelativeLayout.LayoutParams) temporizadorSeek.getLayoutParams()).height = (int) pxFromDp(activity,
                    110);
            temporizadorSeek.atributesCode(15, 16, 9);
            temporLanel.setTextSize(14);

            ((RelativeLayout.LayoutParams) time1.getLayoutParams()).height = (int) pxFromDp(activity, 20);
            ((RelativeLayout.LayoutParams) time1.getLayoutParams()).width = (int) pxFromDp(activity, 20);
            ((RelativeLayout.LayoutParams) time1.getLayoutParams()).topMargin = (int) pxFromDp(activity, 19);
            ((RelativeLayout.LayoutParams) time1.getLayoutParams()).leftMargin = (int) pxFromDp(activity, 66);

            ((RelativeLayout.LayoutParams) time2.getLayoutParams()).height = (int) pxFromDp(activity, 20);
            ((RelativeLayout.LayoutParams) time2.getLayoutParams()).width = (int) pxFromDp(activity, 20);
            ((RelativeLayout.LayoutParams) time2.getLayoutParams()).topMargin = (int) pxFromDp(activity, 29);
            ((RelativeLayout.LayoutParams) time2.getLayoutParams()).leftMargin = (int) pxFromDp(activity, 85);

            ((RelativeLayout.LayoutParams) time3.getLayoutParams()).height = (int) pxFromDp(activity, 20);
            ((RelativeLayout.LayoutParams) time3.getLayoutParams()).width = (int) pxFromDp(activity, 20);
            ((RelativeLayout.LayoutParams) time3.getLayoutParams()).topMargin = (int) pxFromDp(activity, 47);
            ((RelativeLayout.LayoutParams) time3.getLayoutParams()).leftMargin = (int) pxFromDp(activity, 94);

            ((RelativeLayout.LayoutParams) time4.getLayoutParams()).height = (int) pxFromDp(activity, 20);
            ((RelativeLayout.LayoutParams) time4.getLayoutParams()).width = (int) pxFromDp(activity, 20);
            ((RelativeLayout.LayoutParams) time4.getLayoutParams()).topMargin = (int) pxFromDp(activity, 67);
            ((RelativeLayout.LayoutParams) time4.getLayoutParams()).leftMargin = (int) pxFromDp(activity, 94);

            ((RelativeLayout.LayoutParams) time5.getLayoutParams()).height = (int) pxFromDp(activity, 20);
            ((RelativeLayout.LayoutParams) time5.getLayoutParams()).width = (int) pxFromDp(activity, 20);
            ((RelativeLayout.LayoutParams) time5.getLayoutParams()).topMargin = (int) pxFromDp(activity, 85);
            ((RelativeLayout.LayoutParams) time5.getLayoutParams()).leftMargin = (int) pxFromDp(activity, 85);

            ((RelativeLayout.LayoutParams) time6.getLayoutParams()).height = (int) pxFromDp(activity, 20);
            ((RelativeLayout.LayoutParams) time6.getLayoutParams()).width = (int) pxFromDp(activity, 20);
            ((RelativeLayout.LayoutParams) time6.getLayoutParams()).topMargin = (int) pxFromDp(activity, 95);
            ((RelativeLayout.LayoutParams) time6.getLayoutParams()).leftMargin = (int) pxFromDp(activity, 66);

            ((RelativeLayout.LayoutParams) time7.getLayoutParams()).height = (int) pxFromDp(activity, 20);
            ((RelativeLayout.LayoutParams) time7.getLayoutParams()).width = (int) pxFromDp(activity, 20);
            ((RelativeLayout.LayoutParams) time7.getLayoutParams()).topMargin = (int) pxFromDp(activity, 95);
            ((RelativeLayout.LayoutParams) time7.getLayoutParams()).leftMargin = (int) pxFromDp(activity, 45);

            ((RelativeLayout.LayoutParams) time8.getLayoutParams()).height = (int) pxFromDp(activity, 20);
            ((RelativeLayout.LayoutParams) time8.getLayoutParams()).width = (int) pxFromDp(activity, 20);
            ((RelativeLayout.LayoutParams) time8.getLayoutParams()).topMargin = (int) pxFromDp(activity, 85);
            ((RelativeLayout.LayoutParams) time8.getLayoutParams()).leftMargin = (int) pxFromDp(activity, 28);

            ((RelativeLayout.LayoutParams) time9.getLayoutParams()).height = (int) pxFromDp(activity, 20);
            ((RelativeLayout.LayoutParams) time9.getLayoutParams()).width = (int) pxFromDp(activity, 20);
            ((RelativeLayout.LayoutParams) time9.getLayoutParams()).topMargin = (int) pxFromDp(activity, 67);
            ((RelativeLayout.LayoutParams) time9.getLayoutParams()).leftMargin = (int) pxFromDp(activity, 18);

            ((RelativeLayout.LayoutParams) time10.getLayoutParams()).height = (int) pxFromDp(activity, 20);
            ((RelativeLayout.LayoutParams) time10.getLayoutParams()).width = (int) pxFromDp(activity, 20);
            ((RelativeLayout.LayoutParams) time10.getLayoutParams()).topMargin = (int) pxFromDp(activity, 47);
            ((RelativeLayout.LayoutParams) time10.getLayoutParams()).leftMargin = (int) pxFromDp(activity, 18);

            ((RelativeLayout.LayoutParams) time11.getLayoutParams()).height = (int) pxFromDp(activity, 20);
            ((RelativeLayout.LayoutParams) time11.getLayoutParams()).width = (int) pxFromDp(activity, 20);
            ((RelativeLayout.LayoutParams) time11.getLayoutParams()).topMargin = (int) pxFromDp(activity, 29);
            ((RelativeLayout.LayoutParams) time11.getLayoutParams()).leftMargin = (int) pxFromDp(activity, 28);

            ((RelativeLayout.LayoutParams) time12.getLayoutParams()).height = (int) pxFromDp(activity, 20);
            ((RelativeLayout.LayoutParams) time12.getLayoutParams()).width = (int) pxFromDp(activity, 20);
            ((RelativeLayout.LayoutParams) time12.getLayoutParams()).topMargin = (int) pxFromDp(activity, 19);
            ((RelativeLayout.LayoutParams) time12.getLayoutParams()).leftMargin = (int) pxFromDp(activity, 45);

        }
    }
    messagesList.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
        @Override
        public void onGlobalLayout() {
            if (scrollOnBottom) {
                messagesListScroll.scrollTo(0, messagesList.getBottom());
            } else {
                messagesListScroll.scrollTo(0, ((messagesList.getHeight() - messagesValuePrev) + scrollValue)
                        + (scrollHeight - messagesListScroll.getHeight()));
                messagesListScroll.setVerticalScrollBarEnabled(true);
            }

        }
    });
    messagesListScroll.getViewTreeObserver()
            .addOnScrollChangedListener(new ViewTreeObserver.OnScrollChangedListener() {
                @Override
                public void onScrollChanged() {
                    if (messagesList.getHeight() - messagesListScroll.getScrollY() <= messagesListScroll
                            .getHeight()) {
                        scrollOnBottom = true;
                    } else {
                        scrollOnBottom = false;
                        messagesValuePrev = messagesList.getHeight();
                        scrollValue = messagesListScroll.getScrollY();
                        scrollHeight = messagesListScroll.getHeight();
                    }
                }
            });

    messageSend.setOnClickListener(this);
    messageText.addTextChangedListener(new TextWatcher() {
        boolean delayed = false;

        @Override
        public void afterTextChanged(Editable arg0) {
        }

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        private void sendWritingStatus() {
            if (SpeakSocket.isRunning()) {
                try {
                    JSONObject data = new JSONObject();
                    data.put("source", u.id);
                    data.put("target", contact.idContacto);
                    data.put("type", 1);
                    if (SpeakSocket.mSocket != null)
                        if (SpeakSocket.mSocket.connected())
                            SpeakSocket.mSocket.emit("contact-status", data);
                    Log.e("STATUS WRITE", data.toString());
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            if (messageText.getText().length() > 0) {
                messageSend.setVisibility(View.VISIBLE);
                messageSednDivider.setVisibility(View.VISIBLE);
                if (!delayed) {
                    delayed = true;
                    sendWritingStatus();
                    new Handler().postDelayed(new Runnable() {
                        @Override
                        public void run() {
                            delayed = false;
                        }
                    }, C.CONTACT_STATUS_DELAY_MS);
                }
            } else {
                messageSend.setVisibility(View.GONE);
                messageSednDivider.setVisibility(View.GONE);
            }

        }
    });
    u = new Select().from(User.class).executeSingle();

    handlerContactStatus = new Handler();
    runnableContactStatus = new Runnable() {

        @Override
        public void run() {
            JSONObject dataLastSeen = new JSONObject();
            try {
                dataLastSeen.put("source", u.id);
                dataLastSeen.put("target", contact.idContacto);
                if (SpeakSocket.mSocket != null)
                    if (SpeakSocket.mSocket.connected()) {
                        Log.e("Pidiendo lastseen", dataLastSeen.toString());
                        SpeakSocket.mSocket.emit("contact-lastseen", dataLastSeen);
                    }
            } catch (JSONException e) {
                e.printStackTrace();
            }
            handlerContactStatus.postDelayed(runnableContactStatus, 5000);
        }
    };
    handlerContactStatus.postDelayed(runnableContactStatus, 500);
    Contact contAdd = new Select().from(Contact.class).where("id_contact = ?", contact.idContacto)
            .executeSingle();
    if (contAdd == null) {
        addToContacts.setVisibility(View.VISIBLE);
    } else {
        addToContacts.setVisibility(View.GONE);
    }

    return view;
}

From source file:free.yhc.netmbuddy.utils.Utils.java

public static Rect getVisibleFrame(Activity activity) {
    Rect rect = new Rect();
    Window window = activity.getWindow();
    window.getDecorView().getWindowVisibleDisplayFrame(rect);
    return rect;//from   w w  w .  j a v  a 2  s. c o  m
}

From source file:app.umitems.greenclock.widget.sgv.StaggeredGridView.java

/**
 * Return the child view specified by the coordinates if
 * there exists a child there.//ww  w  .jav  a2 s.c  o  m
 *
 * @return the child in this StaggeredGridView at the coordinates, null otherwise.
 */
private View getChildAtCoordinate(int x, int y) {
    if (y < 0) {
        // TODO: If we've dragged off the screen, return null for now until we know what
        // we'd like the experience to be like.
        return null;
    }

    final Rect frame = new Rect();
    final int count = getChildCount();
    for (int i = 0; i < count; i++) {

        final View childView = getChildAt(i);
        childView.getHitRect(frame);
        if (frame.contains(x, y)) {
            return getChildAt(i);
        }
    }

    // No child view at this coordinate.
    return null;
}

From source file:android.support.v7.app.MediaRouteControllerDialog.java

/**
 * Updates the height of views and hide artwork or metadata if space is limited.
 *///from ww w . ja  va  2 s  .  co  m
private void updateLayoutHeightInternal(boolean animate) {
    // Measure the size of widgets and get the height of main components.
    int oldHeight = getLayoutHeight(mMediaMainControlLayout);
    setLayoutHeight(mMediaMainControlLayout, ViewGroup.LayoutParams.FILL_PARENT);
    updateMediaControlVisibility(canShowPlaybackControlLayout());
    View decorView = getWindow().getDecorView();
    decorView.measure(MeasureSpec.makeMeasureSpec(getWindow().getAttributes().width, MeasureSpec.EXACTLY),
            MeasureSpec.UNSPECIFIED);
    setLayoutHeight(mMediaMainControlLayout, oldHeight);
    int artViewHeight = 0;
    if (mCustomControlView == null && mArtView.getDrawable() instanceof BitmapDrawable) {
        Bitmap art = ((BitmapDrawable) mArtView.getDrawable()).getBitmap();
        if (art != null) {
            artViewHeight = getDesiredArtHeight(art.getWidth(), art.getHeight());
            mArtView.setScaleType(art.getWidth() >= art.getHeight() ? ImageView.ScaleType.FIT_XY
                    : ImageView.ScaleType.FIT_CENTER);
        }
    }
    int mainControllerHeight = getMainControllerHeight(canShowPlaybackControlLayout());
    int volumeGroupListCount = mGroupMemberRoutes.size();
    // Scale down volume group list items in landscape mode.
    int expandedGroupListHeight = getGroup() == null ? 0
            : mVolumeGroupListItemHeight * getGroup().getRoutes().size();
    if (volumeGroupListCount > 0) {
        expandedGroupListHeight += mVolumeGroupListPaddingTop;
    }
    expandedGroupListHeight = Math.min(expandedGroupListHeight, mVolumeGroupListMaxHeight);
    int visibleGroupListHeight = mIsGroupExpanded ? expandedGroupListHeight : 0;

    int desiredControlLayoutHeight = Math.max(artViewHeight, visibleGroupListHeight) + mainControllerHeight;
    Rect visibleRect = new Rect();
    decorView.getWindowVisibleDisplayFrame(visibleRect);
    // Height of non-control views in decor view.
    // This includes title bar, button bar, and dialog's vertical padding which should be
    // always shown.
    int nonControlViewHeight = mDialogAreaLayout.getMeasuredHeight()
            - mDefaultControlLayout.getMeasuredHeight();
    // Maximum allowed height for controls to fit screen.
    int maximumControlViewHeight = visibleRect.height() - nonControlViewHeight;

    // Show artwork if it fits the screen.
    if (mCustomControlView == null && artViewHeight > 0
            && desiredControlLayoutHeight <= maximumControlViewHeight) {
        mArtView.setVisibility(View.VISIBLE);
        setLayoutHeight(mArtView, artViewHeight);
    } else {
        if (getLayoutHeight(mVolumeGroupList)
                + mMediaMainControlLayout.getMeasuredHeight() >= mDefaultControlLayout.getMeasuredHeight()) {
            mArtView.setVisibility(View.GONE);
        }
        artViewHeight = 0;
        desiredControlLayoutHeight = visibleGroupListHeight + mainControllerHeight;
    }
    // Show the playback control if it fits the screen.
    if (canShowPlaybackControlLayout() && desiredControlLayoutHeight <= maximumControlViewHeight) {
        mPlaybackControlLayout.setVisibility(View.VISIBLE);
    } else {
        mPlaybackControlLayout.setVisibility(View.GONE);
    }
    updateMediaControlVisibility(mPlaybackControlLayout.getVisibility() == View.VISIBLE);
    mainControllerHeight = getMainControllerHeight(mPlaybackControlLayout.getVisibility() == View.VISIBLE);
    desiredControlLayoutHeight = Math.max(artViewHeight, visibleGroupListHeight) + mainControllerHeight;

    // Limit the volume group list height to fit the screen.
    if (desiredControlLayoutHeight > maximumControlViewHeight) {
        visibleGroupListHeight -= (desiredControlLayoutHeight - maximumControlViewHeight);
        desiredControlLayoutHeight = maximumControlViewHeight;
    }
    // Update the layouts with the computed heights.
    mMediaMainControlLayout.clearAnimation();
    mVolumeGroupList.clearAnimation();
    mDefaultControlLayout.clearAnimation();
    if (animate) {
        animateLayoutHeight(mMediaMainControlLayout, mainControllerHeight);
        animateLayoutHeight(mVolumeGroupList, visibleGroupListHeight);
        animateLayoutHeight(mDefaultControlLayout, desiredControlLayoutHeight);
    } else {
        setLayoutHeight(mMediaMainControlLayout, mainControllerHeight);
        setLayoutHeight(mVolumeGroupList, visibleGroupListHeight);
        setLayoutHeight(mDefaultControlLayout, desiredControlLayoutHeight);
    }
    // Maximize the window size with a transparent layout in advance for smooth animation.
    setLayoutHeight(mExpandableAreaLayout, visibleRect.height());
    rebuildVolumeGroupList(animate);
}

From source file:com.roger.lineselectionwebview.LSWebView.java

/**
 * Puts up the selection view.// w  ww  .  ja v  a2  s. c om
 * 
 * @param range
 * @param text
 * @param handleBounds
 * @return
 */
protected void handleSelection(String range, String text, String handleBounds) {
    try {
        JSONObject selectionBoundsObject = new JSONObject(handleBounds);

        float scale = getDensityIndependentValue(getScale(), mContext);

        Rect handleRect = new Rect();
        handleRect.left = (int) (getDensityDependentValue(selectionBoundsObject.getInt("left"), getContext())
                * scale);
        handleRect.top = (int) (getDensityDependentValue(selectionBoundsObject.getInt("top"), getContext())
                * scale);
        handleRect.right = (int) (getDensityDependentValue(selectionBoundsObject.getInt("right"), getContext())
                * scale);
        handleRect.bottom = (int) (getDensityDependentValue(selectionBoundsObject.getInt("bottom"),
                getContext()) * scale);

        mSelectionBounds = handleRect;
        mSelectedRange = range;
        mSelectedText = text;

        if (!isInSelectionMode()) {
            startSelectionMode();
        }

        drawSelectionHandles();

    } catch (JSONException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}