Example usage for android.view Gravity CENTER_VERTICAL

List of usage examples for android.view Gravity CENTER_VERTICAL

Introduction

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

Prototype

int CENTER_VERTICAL

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

Click Source Link

Document

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

Usage

From source file:org.chromium.chrome.browser.widget.findinpage.FindToolbar.java

@Override
public void onFinishInflate() {
    super.onFinishInflate();

    setOrientation(HORIZONTAL);//from  www. j  av  a2s. co m
    setGravity(Gravity.CENTER_VERTICAL);

    mFindQuery = (FindQuery) findViewById(R.id.find_query);
    mFindQuery.setFindToolbar(this);
    mFindQuery.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_FILTER);
    mFindQuery.setSelectAllOnFocus(true);
    mFindQuery.setOnFocusChangeListener(new View.OnFocusChangeListener() {
        @Override
        public void onFocusChange(View v, boolean hasFocus) {
            mAccessibilityDidActivateResult = false;
            if (!hasFocus) {
                if (mFindQuery.getText().length() > 0) {
                    mSearchKeyShouldTriggerSearch = true;
                }
                UiUtils.hideKeyboard(mFindQuery);
            }
        }
    });
    mFindQuery.addTextChangedListener(new TextWatcher() {
        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            if (mFindInPageBridge == null)
                return;

            mAccessibilityDidActivateResult = false;
            setPrevNextEnabled(s.length() > 0);

            if (mSettingFindTextProgrammatically)
                return;

            // If we're called during onRestoreInstanceState() the current
            // view won't have been set yet. TODO(husky): Find a better fix.
            assert mCurrentTab != null;
            assert mCurrentTab.getContentViewCore() != null;
            if (mCurrentTab.getContentViewCore() == null)
                return;

            if (s.length() > 0) {
                // Don't clearResults() as that would cause flicker.
                // Just wait until onFindResultReceived updates it.
                mSearchKeyShouldTriggerSearch = false;
                mFindInPageBridge.startFinding(s.toString(), true, false);
            } else {
                clearResults();
                mFindInPageBridge.stopFinding(true);
            }

            if (!mCurrentTab.isIncognito()) {
                mLastUserSearch = s.toString();
            }
        }

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

        @Override
        public void afterTextChanged(Editable s) {
        }
    });
    mFindQuery.setOnEditorActionListener(new TextView.OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if (event != null && event.getAction() == KeyEvent.ACTION_UP)
                return false;

            if (mFindInPageBridge == null)
                return false;

            // Only trigger a new find if the text was set programmatically.
            // Otherwise just revisit the current active match.
            if (mSearchKeyShouldTriggerSearch) {
                mSearchKeyShouldTriggerSearch = false;
                hideKeyboardAndStartFinding(true);
            } else {
                UiUtils.hideKeyboard(mFindQuery);
                mFindInPageBridge.activateFindInPageResultForAccessibility();
                mAccessibilityDidActivateResult = true;
            }
            return true;
        }
    });

    mFindStatus = (TextView) findViewById(R.id.find_status);

    mFindPrevButton = (TintedImageButton) findViewById(R.id.find_prev_button);
    mFindPrevButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            hideKeyboardAndStartFinding(false);
        }
    });

    mFindNextButton = (TintedImageButton) findViewById(R.id.find_next_button);
    mFindNextButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            hideKeyboardAndStartFinding(true);
        }
    });

    setPrevNextEnabled(false);

    mCloseFindButton = (TintedImageButton) findViewById(R.id.close_find_button);
    mCloseFindButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            deactivate();
        }
    });
}

From source file:com.google.android.apps.gutenberg.ScannerActivity.java

private void showCheckinAnimation(Checkin checkin) {
    if (mLastAnimator != null) {
        mLastAnimator.cancel();//from   ww w  . java 2s  .  c o m
    }
    final FrameLayout cover = (FrameLayout) findViewById(R.id.item_cover);
    cover.setVisibility(View.VISIBLE);
    final FrameLayout layer = (FrameLayout) findViewById(R.id.animation_layer);
    final CheckinHolder holder = new CheckinHolder(getLayoutInflater(), layer);
    FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT,
            FrameLayout.LayoutParams.WRAP_CONTENT);
    lp.gravity = Gravity.CENTER_VERTICAL;
    holder.setWillAnimate(true);
    holder.bind(checkin, mImageLoader);
    holder.itemView.setBackgroundColor(Color.rgb(0xf0, 0xf0, 0xf0));
    float elevation = getResources().getDimension(R.dimen.popup_elevation);
    ViewCompat.setTranslationZ(holder.itemView, elevation);
    holder.setLines(false, false);
    layer.addView(holder.itemView, lp);
    // Interpolator for animators
    FastOutSlowInInterpolator interpolator = new FastOutSlowInInterpolator();
    // Pop-up
    Animator popUpAnim = AnimatorInflater.loadAnimator(this, R.animator.pop_up);
    popUpAnim.setTarget(holder.itemView);
    popUpAnim.setInterpolator(interpolator);
    popUpAnim.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            holder.animateCheckin();
        }
    });
    // Wait
    ObjectAnimator waitAnim = new ObjectAnimator();
    waitAnim.setTarget(holder.itemView);
    waitAnim.setPropertyName("translationY");
    waitAnim.setFloatValues(0.f, 0.f);
    waitAnim.setDuration(2000);
    // Slide-down
    ObjectAnimator slideDownAnim = new ObjectAnimator();
    slideDownAnim.setTarget(holder.itemView);
    slideDownAnim.setPropertyName("translationY");
    slideDownAnim.setFloatValues(0.f, calcSlideDistance());
    slideDownAnim.setInterpolator(interpolator);
    // Landing anim
    ObjectAnimator landingAnim = new ObjectAnimator();
    landingAnim.setTarget(holder.itemView);
    landingAnim.setPropertyName("translationZ");
    landingAnim.setFloatValues(elevation, 0.f);
    landingAnim.setInterpolator(interpolator);
    landingAnim.setDuration(500);
    // Play the animators
    AnimatorSet set = new AnimatorSet();
    set.setInterpolator(interpolator);
    set.playSequentially(popUpAnim, waitAnim, slideDownAnim, landingAnim);
    set.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            clean();
        }

        @Override
        public void onAnimationCancel(Animator animation) {
            clean();
        }

        private void clean() {
            mLastAnimator = null;
            layer.removeAllViews();
            cover.setVisibility(View.INVISIBLE);
        }
    });
    mLastAnimator = set;
    set.start();
}

From source file:com.research.widget.PagerSlidingTabStrip.java

private void addTextTab(final int position, String title) {

    LinearLayout item = new LinearLayout(getContext());
    item.setOrientation(LinearLayout.HORIZONTAL);
    item.setGravity(Gravity.CENTER_HORIZONTAL | Gravity.CENTER_VERTICAL);

    TextView tab = new TextView(getContext());
    tab.setText(title);/*from w ww .j a va  2 s  . c  om*/
    tab.setGravity(Gravity.CENTER);
    tab.setSingleLine();

    TextView msgTipText = new TextView(getContext());
    msgTipText.setGravity(Gravity.CENTER);
    msgTipText.setTextSize(TypedValue.COMPLEX_UNIT_SP, 10);
    msgTipText.setSingleLine();
    msgTipText.setTextColor(Color.parseColor("#ffffff"));
    if (position != 0) {
        msgTipText.setBackgroundDrawable(getContext().getResources().getDrawable(R.drawable.main_find_icon));
        LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
                FeatureFunction.dip2px(BMapApiApp.getInstance(), 10),
                FeatureFunction.dip2px(BMapApiApp.getInstance(), 10));
        msgTipText.setLayoutParams(params);
    } else {
        msgTipText.setBackgroundDrawable(getContext().getResources().getDrawable(R.drawable.message_count_bg));
    }

    msgTipText.setVisibility(View.GONE);

    item.addView(tab);
    item.addView(msgTipText);

    addTab(position, item);
}

From source file:com.openatk.planting.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    dbHelper = new DatabaseHelper(this);

    FragmentManager fm = getSupportFragmentManager();
    fragMap = (SupportMapFragment) fm.findFragmentById(R.id.map);

    fragmentEditField = (FragmentEditJobPopup) fm.findFragmentByTag("edit_job");

    if (savedInstanceState == null) {
        // First incarnation of this activity.
        fragMap.setRetainInstance(true);
    } else {//  www  .j  a  va2  s  .c  o  m
        // Reincarnated activity. The obtained map is the same map instance
        // in the previous
        // activity life cycle. There is no need to reinitialize it.
        map = fragMap.getMap();
    }
    checkGPS();

    actionBar = getActionBar();
    // Specify that a dropdown list should be displayed in the action bar.
    // actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);

    // Hide the title
    actionBar.setDisplayShowTitleEnabled(false);
    actionBar.setDisplayUseLogoEnabled(false);

    actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM, ActionBar.DISPLAY_SHOW_CUSTOM);
    View view;
    LayoutInflater inflater = (LayoutInflater) this.getApplicationContext()
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    view = inflater.inflate(R.layout.action_bar, null);
    RelativeLayout item = (RelativeLayout) view.findViewById(R.id.action_bar_layout);
    spinnerMenu = (Spinner) view.findViewById(R.id.action_bar_operation_spinner);
    actionBarSearch = (EditText) view.findViewById(R.id.action_bar_search_box);
    actionBar.setCustomView(item, new ActionBar.LayoutParams(ActionBar.LayoutParams.WRAP_CONTENT,
            ActionBar.LayoutParams.WRAP_CONTENT, Gravity.CENTER_VERTICAL | Gravity.LEFT));

    actionBarSearch.setOnFocusChangeListener(new OnFocusChangeListener() {
        @Override
        public void onFocusChange(View v, boolean hasFocus) {
            if (hasFocus == false) {
                InputMethodManager imm = (InputMethodManager) v.getContext()
                        .getSystemService(Context.INPUT_METHOD_SERVICE);
                imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
            }
        }
    });
    actionBarSearch.addTextChangedListener(new TextWatcher() {
        @Override
        public void afterTextChanged(Editable s) {
            if (fragmentListView != null)
                fragmentListView.search(s.toString());
        }

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

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {

        }
    });

    Fragment fragment = fm.findFragmentById(R.id.list_view);
    FragmentTransaction ft = fm.beginTransaction();
    ft.hide(fragment);
    ft.commit();

    //Trello
    trelloController = new TrelloController(getApplicationContext());
    syncController = new SyncController(getApplicationContext(), trelloController, this);
    trelloController.setSyncController(syncController);

    // Get last selected operation
    if (savedInstanceState != null) {
        // Find current field
        currentField = FindFieldById(savedInstanceState.getInt("currentField"));

        // Find current job
        currentJob = FindJobById(savedInstanceState.getInt("currentJob"));

        // Find current operation
        currentOperationId = savedInstanceState.getInt("currentOperationId");

        editIsShowing = savedInstanceState.getInt("editIsShowing");
        addIsShowing = savedInstanceState.getInt("addIsShowing");

        this.addingBoundary = savedInstanceState.getString("drawingBoundary", "");

        // Switch to correct state
        setState(savedInstanceState.getInt("mCurrentState"), false);
    }

    // Load operations from database
    loadOperations();

    // Specify a SpinnerAdapter to populate the dropdown list.
    spinnerMenuAdapter = new ArrayAdapter<Operation>(this, R.layout.operation_list_item, operationsList);
    spinnerMenu.setAdapter(spinnerMenuAdapter);
    // Load current from preferences
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
    currentOperationId = prefs.getInt("currentOperationId", 0);
    this.showingHazards = prefs.getBoolean("showingHazards", false);
    selectCurrentOperationInSpinner();
    spinnerMenu.setOnItemSelectedListener(this);

    setUpMapIfNeeded();

    Intent intent = this.getIntent();
    String todo = intent.getStringExtra("todo");
    if (todo != null) {
        if (todo.contentEquals("sync")) {
            trelloController.sync();
        }
    }
    getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
}

From source file:com.waz.zclient.ui.cursor.CursorLayout.java

@Override
protected void onFinishInflate() {
    super.onFinishInflate();

    editMessageBackgroundView = ViewUtils.getView(this, R.id.fl__edit_message__background);
    cursorToolbarFrame = ViewUtils.getView(this, R.id.cal__cursor);
    newCursorEditText = ViewUtils.getView(this, R.id.cet__cursor);
    shieldViewWithBanner = ViewUtils.getView(this, R.id.svwb);
    mainToolbar = ViewUtils.getView(this, R.id.c__cursor__main);
    secondaryToolbar = ViewUtils.getView(this, R.id.c__cursor__secondary);
    editMessageCursorToolbar = ViewUtils.getView(this, R.id.emct__edit_message__toolbar);
    topBorder = ViewUtils.getView(this, R.id.v__top_bar__cursor);
    tooltip = ViewUtils.getView(this, R.id.ctv__cursor);
    hintView = ViewUtils.getView(this, R.id.ttv__cursor_hint);
    dividerView = ViewUtils.getView(this, R.id.v__cursor__divider);
    FrameLayout emojiButtonContainer = ViewUtils.getView(this, R.id.fl__cursor__emoji_container);
    FrameLayout sendButtonContainer = ViewUtils.getView(this, R.id.fl__cursor__send_button_container);

    mainToolbar.setCursorItems(mainCursorItems);
    secondaryToolbar.setCursorItems(secondaryCursorItems);
    editMessageCursorToolbar.setVisibility(GONE);
    editMessageCursorToolbar.setCallback(this);

    cursorHeight = getResources().getDimensionPixelSize(R.dimen.new_cursor_height);
    secondaryToolbar.setTranslationY(2 * cursorHeight);
    cursorToolbarAnimationDuration = getResources().getInteger(R.integer.wire__animation__delay__regular);
    tooltip.setVisibility(View.GONE);
    connectEditText();/*w w  w  . j av a2 s.c o  m*/
    editMessageBackgroundView.setVisibility(GONE);

    defaultEditTextColor = newCursorEditText.getCurrentTextColor();
    ColorDrawable dividerBg = (ColorDrawable) dividerView.getBackground();
    defaultDividerColor = dividerBg.getColor();

    // Emoji button
    LayoutInflater inflater = LayoutInflater.from(getContext());
    emojiButton = (CursorIconButton) inflater.inflate(R.layout.cursor__item, this, false);
    emojiButton.setText(R.string.glyph__emoji);
    emojiButton.setPressedBackgroundColor(ContextCompat.getColor(getContext(), R.color.light_graphite));
    int buttonWidth = getResources().getDimensionPixelSize(R.dimen.cursor__menu_button__diameter);
    FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(buttonWidth, buttonWidth);
    params.gravity = Gravity.END | Gravity.CENTER_VERTICAL;
    params.setMarginEnd(getResources().getDimensionPixelSize(R.dimen.chathead__margin));
    emojiButtonContainer.addView(emojiButton, params);
    emojiButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View view) {
            if (cursorCallback == null) {
                return;
            }
            mainToolbar.unselectItems();
            if (getContext().getString(R.string.glyph__emoji).equals(emojiButton.getText())) {
                emojiButton.setText(R.string.glyph__keyboard);
                cursorCallback.onEmojiButtonClicked(true);
            } else {
                emojiButton.setText(R.string.glyph__emoji);
                cursorCallback.onEmojiButtonClicked(false);
            }
        }
    });

    // Send button
    sendButton = (CursorIconButton) inflater.inflate(R.layout.cursor__item, this, false);
    sendButton.setText(R.string.glyph__send);
    if (!ThemeUtils.isDarkTheme(getContext())) {
        sendButton.setTextColor(ContextCompat.getColor(getContext(), R.color.text__primary_dark));
    } else {
        sendButton.setTextColor(ContextCompat.getColor(getContext(), R.color.text__primary_light));
    }
    sendButtonContainer.addView(sendButton, new FrameLayout.LayoutParams(buttonWidth, buttonWidth));
    sendButton.setVisibility(View.INVISIBLE);
}

From source file:com.example.drugsformarinemammals.ViewPager_Pinnipeds.java

private void displayMessage(String messageTitle, String message) {
    AlertDialog.Builder myalert = new AlertDialog.Builder(this);

    TextView title = new TextView(this);
    title.setTypeface(Typeface.SANS_SERIF);
    title.setTextSize(20);//w ww  . j  a va 2  s.co m
    title.setTextColor(getResources().getColor(R.color.blue));
    title.setPadding(8, 8, 8, 8);
    title.setText("");
    title.setGravity(Gravity.CENTER_VERTICAL);

    LinearLayout layout = new LinearLayout(this);
    TextView text = new TextView(this);
    text.setTypeface(Typeface.SANS_SERIF);
    text.setTextSize(20);
    text.setPadding(10, 10, 10, 10);
    text.setText(message);
    layout.addView(text);

    myalert.setView(layout);
    myalert.setCustomTitle(title);
    myalert.setCancelable(true);
    myalert.show();

}

From source file:com.tr4android.support.extension.widget.FlexibleToolbarLayout.java

public FlexibleToolbarLayout(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);

    mTitleCollapsingTextHelper = new CollapsingTextHelper(this);
    mTitleCollapsingTextHelper.setTextSizeInterpolator(AnimationUtils.LINEAR_INTERPOLATOR);
    mSubtitleCollapsingTextHelper = new CollapsingTextHelper(this);
    mSubtitleCollapsingTextHelper.setTextSizeInterpolator(AnimationUtils.LINEAR_INTERPOLATOR);
    mIconCollapsingHelper = new CollapsingDrawableHelper(this);
    mIconCollapsingHelper.setIconSizeInterpolator(AnimationUtils.LINEAR_INTERPOLATOR);

    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.FlexibleToolbarLayout, defStyleAttr,
            R.style.Widget_Design_FlexibleToolbarLayout);

    int expandedVerticalGravity = a.getInt(R.styleable.FlexibleToolbarLayout_expandedGravity,
            Gravity.CENTER_VERTICAL);

    mTitleCollapsingTextHelper.setExpandedTextGravity(GravityCompat.START | expandedVerticalGravity);
    mTitleCollapsingTextHelper.setCollapsedTextGravity(GravityCompat.START | Gravity.CENTER_VERTICAL);
    mSubtitleCollapsingTextHelper.setExpandedTextGravity(GravityCompat.START | expandedVerticalGravity);
    mSubtitleCollapsingTextHelper.setCollapsedTextGravity(GravityCompat.START | Gravity.CENTER_VERTICAL);

    mExpandedMarginLeft = mExpandedMarginTop = mExpandedMarginRight = mExpandedMarginBottom = a
            .getDimensionPixelSize(R.styleable.FlexibleToolbarLayout_expandedMargin, 0);

    final boolean isRtl = ViewCompat.getLayoutDirection(this) == ViewCompat.LAYOUT_DIRECTION_RTL;
    if (a.hasValue(R.styleable.FlexibleToolbarLayout_expandedMarginStart)) {
        final int marginStart = a.getDimensionPixelSize(R.styleable.FlexibleToolbarLayout_expandedMarginStart,
                0);/*  ww  w .  j  a v  a2  s  .c  o  m*/
        if (isRtl) {
            mExpandedMarginRight = marginStart;
        } else {
            mExpandedMarginLeft = marginStart;
        }
    }
    if (a.hasValue(R.styleable.FlexibleToolbarLayout_expandedMarginEnd)) {
        final int marginEnd = a.getDimensionPixelSize(R.styleable.FlexibleToolbarLayout_expandedMarginEnd, 0);
        if (isRtl) {
            mExpandedMarginLeft = marginEnd;
        } else {
            mExpandedMarginRight = marginEnd;
        }
    }
    if (a.hasValue(R.styleable.FlexibleToolbarLayout_expandedMarginTop)) {
        mExpandedMarginTop = a.getDimensionPixelSize(R.styleable.FlexibleToolbarLayout_expandedMarginTop, 0);
    }
    if (a.hasValue(R.styleable.FlexibleToolbarLayout_expandedMarginBottom)) {
        mExpandedMarginBottom = a.getDimensionPixelSize(R.styleable.FlexibleToolbarLayout_expandedMarginBottom,
                0);
    }

    mCollapsingTitleEnabled = a.getBoolean(R.styleable.FlexibleToolbarLayout_titleFlexibleEnabled, true);
    setTitle(a.getText(R.styleable.FlexibleToolbarLayout_title));
    mCollapsingSubtitleEnabled = a.getBoolean(R.styleable.FlexibleToolbarLayout_subtitleFlexibleEnabled, true);
    setSubtitle(a.getText(R.styleable.FlexibleToolbarLayout_subtitle));
    mCollapsingIconEnabled = a.getBoolean(R.styleable.FlexibleToolbarLayout_iconFlexibleEnabled, true);
    setIcon(a.getDrawable(R.styleable.FlexibleToolbarLayout_icon));

    // First load the default text appearances
    mTitleCollapsingTextHelper
            .setExpandedTextAppearance(R.style.TextAppearance_Design_FlexibleToolbarLayout_ExpandedTitle);
    mTitleCollapsingTextHelper
            .setCollapsedTextAppearance(R.style.TextAppearance_Design_FlexibleToolbarLayout_CollapsedTitle);
    mSubtitleCollapsingTextHelper
            .setExpandedTextAppearance(R.style.TextAppearance_Design_FlexibleToolbarLayout_Subtitle);
    mSubtitleCollapsingTextHelper
            .setCollapsedTextAppearance(R.style.TextAppearance_Design_FlexibleToolbarLayout_Subtitle);

    // Now overlay any custom text appearances
    if (a.hasValue(R.styleable.FlexibleToolbarLayout_titleExpandedTextAppearance)) {
        mTitleCollapsingTextHelper.setExpandedTextAppearance(
                a.getResourceId(R.styleable.FlexibleToolbarLayout_titleExpandedTextAppearance, 0));
    }
    if (a.hasValue(R.styleable.FlexibleToolbarLayout_titleCollapsedTextAppearance)) {
        mTitleCollapsingTextHelper.setCollapsedTextAppearance(
                a.getResourceId(R.styleable.FlexibleToolbarLayout_titleCollapsedTextAppearance, 0));

    }
    if (a.hasValue(R.styleable.FlexibleToolbarLayout_subtitleExpandedTextAppearance)) {
        mSubtitleCollapsingTextHelper.setExpandedTextAppearance(
                a.getResourceId(R.styleable.FlexibleToolbarLayout_subtitleExpandedTextAppearance, 0));
    }
    if (a.hasValue(R.styleable.FlexibleToolbarLayout_subtitleCollapsedTextAppearance)) {
        mSubtitleCollapsingTextHelper.setCollapsedTextAppearance(
                a.getResourceId(R.styleable.FlexibleToolbarLayout_subtitleCollapsedTextAppearance, 0));

    }

    // Load the icon sizes
    mIconCollapsingHelper.setCollapsedIconSize(
            a.getDimensionPixelSize(R.styleable.FlexibleToolbarLayout_iconCollapsedSize, 0));
    mIconCollapsingHelper.setExpandedIconSize(
            a.getDimensionPixelSize(R.styleable.FlexibleToolbarLayout_iconExpandedSize, 0));

    mSpaceTitleSubtitle = a.getDimensionPixelSize(R.styleable.FlexibleToolbarLayout_spaceTitleSubtitle, 0);
    mSpaceIconTitles = a.getDimensionPixelSize(R.styleable.FlexibleToolbarLayout_spaceIconTitles, 0);

    setContentScrim(a.getDrawable(R.styleable.FlexibleToolbarLayout_contentScrimColor));
    setStatusBarScrim(a.getDrawable(R.styleable.FlexibleToolbarLayout_statusBarScrimColor));

    mToolbarId = a.getResourceId(R.styleable.FlexibleToolbarLayout_toolbarRefId, -1);

    a.recycle();

    setWillNotDraw(false);

    ViewCompat.setOnApplyWindowInsetsListener(this, new android.support.v4.view.OnApplyWindowInsetsListener() {
        @Override
        public WindowInsetsCompat onApplyWindowInsets(View v, WindowInsetsCompat insets) {
            mLastInsets = insets;
            requestLayout();
            return insets.consumeSystemWindowInsets();
        }
    });
}

From source file:com.moods_final.moods.entertainment.VideoListDemoActivity.java

/**
 * Sets up the layout programatically for the three different states. Portrait, landscape or
 * fullscreen+landscape. This has to be done programmatically because we handle the orientation
 * changes ourselves in order to get fluent fullscreen transitions, so the xml layout resources
 * do not get reloaded.//from w ww .java2 s .  c o m
 */
private void layout() {
    boolean isPortrait = getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT;

    listFragment.getView().setVisibility(isFullscreen ? View.GONE : View.VISIBLE);
    listFragment.setLabelVisibility(isPortrait);
    closeButton.setVisibility(isPortrait ? View.VISIBLE : View.GONE);

    if (isFullscreen) {
        videoBox.setTranslationY(0); // Reset any translation that was applied in portrait.
        setLayoutSize(videoFragment.getView(), MATCH_PARENT, MATCH_PARENT);
        setLayoutSizeAndGravity(videoBox, MATCH_PARENT, MATCH_PARENT, Gravity.TOP | Gravity.LEFT);
    } else if (isPortrait) {
        setLayoutSize(listFragment.getView(), MATCH_PARENT, MATCH_PARENT);
        setLayoutSize(videoFragment.getView(), MATCH_PARENT, WRAP_CONTENT);
        setLayoutSizeAndGravity(videoBox, MATCH_PARENT, WRAP_CONTENT, Gravity.BOTTOM);
    } else {
        videoBox.setTranslationY(0); // Reset any translation that was applied in portrait.
        int screenWidth = dpToPx(getResources().getConfiguration().screenWidthDp);
        setLayoutSize(listFragment.getView(), screenWidth / 4, MATCH_PARENT);
        int videoWidth = screenWidth - screenWidth / 4 - dpToPx(LANDSCAPE_VIDEO_PADDING_DP);
        setLayoutSize(videoFragment.getView(), videoWidth, WRAP_CONTENT);
        setLayoutSizeAndGravity(videoBox, videoWidth, WRAP_CONTENT, Gravity.RIGHT | Gravity.CENTER_VERTICAL);
    }
}

From source file:org.telegram.ui.ActionBar.ActionBarMenuItem.java

public TextView addSubItem(int id, String text, int icon) {
    if (popupLayout == null) {
        rect = new Rect();
        location = new int[2];
        popupLayout = new ActionBarPopupWindow.ActionBarPopupWindowLayout(getContext());
        popupLayout.setOnTouchListener(new OnTouchListener() {
            @Override//from  w ww  . j av a2  s .c o  m
            public boolean onTouch(View v, MotionEvent event) {
                if (event.getActionMasked() == MotionEvent.ACTION_DOWN) {
                    if (popupWindow != null && popupWindow.isShowing()) {
                        v.getHitRect(rect);
                        if (!rect.contains((int) event.getX(), (int) event.getY())) {
                            popupWindow.dismiss();
                        }
                    }
                }
                return false;
            }
        });
        popupLayout.setDispatchKeyEventListener(new ActionBarPopupWindow.OnDispatchKeyEventListener() {
            @Override
            public void onDispatchKeyEvent(KeyEvent keyEvent) {
                if (keyEvent.getKeyCode() == KeyEvent.KEYCODE_BACK && keyEvent.getRepeatCount() == 0
                        && popupWindow != null && popupWindow.isShowing()) {
                    popupWindow.dismiss();
                }
            }
        });
    }
    TextView textView = new TextView(getContext());
    textView.setTextColor(ContextCompat.getColor(getContext(), R.color.primary_text));
    textView.setBackgroundResource(R.drawable.list_selector);
    if (!LocaleController.isRTL) {
        textView.setGravity(Gravity.CENTER_VERTICAL);
    } else {
        textView.setGravity(Gravity.CENTER_VERTICAL | Gravity.RIGHT);
    }
    textView.setPadding(AndroidUtilities.dp(16), 0, AndroidUtilities.dp(16), 0);
    textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
    textView.setMinWidth(AndroidUtilities.dp(196));
    textView.setTag(id);
    textView.setText(text);
    if (icon != 0) {
        textView.setCompoundDrawablePadding(AndroidUtilities.dp(12));
        if (!LocaleController.isRTL) {
            textView.setCompoundDrawablesWithIntrinsicBounds(getResources().getDrawable(icon), null, null,
                    null);
        } else {
            textView.setCompoundDrawablesWithIntrinsicBounds(null, null, getResources().getDrawable(icon),
                    null);
        }
    }
    popupLayout.setShowedFromBotton(showFromBottom);
    popupLayout.addView(textView);
    LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) textView.getLayoutParams();
    if (LocaleController.isRTL) {
        layoutParams.gravity = Gravity.RIGHT;
    }
    layoutParams.width = LayoutHelper.MATCH_PARENT;
    layoutParams.height = AndroidUtilities.dp(48);
    textView.setLayoutParams(layoutParams);
    textView.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View view) {
            if (popupWindow != null && popupWindow.isShowing()) {
                if (processedPopupClick) {
                    return;
                }
                processedPopupClick = true;
                popupWindow.dismiss(allowCloseAnimation);
            }
            if (parentMenu != null) {
                parentMenu.onItemClick((Integer) view.getTag());
            } else if (delegate != null) {
                delegate.onItemClick((Integer) view.getTag());
            }
        }
    });
    menuHeight += layoutParams.height;
    return textView;
}

From source file:com.tune.news.fragment.EntriesListFragment.java

@Override
public View inflateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.fragment_entry_list, container, true);

    if (mEntriesCursorAdapter != null) {
        setListAdapter(mEntriesCursorAdapter);
    }//www  .j a va 2  s. c o m

    mListView = (ListView) rootView.findViewById(android.R.id.list);
    mListView.setFastScrollEnabled(true);
    //        mListView.setOnTouchListener(new SwipeGestureListener(mListView.getContext()));

    if (PrefUtils.getBoolean(PrefUtils.DISPLAY_TIP, true)) {
        final TextView header = new TextView(mListView.getContext());
        header.setMinimumHeight(UiUtils.dpToPixel(70));
        int footerPadding = UiUtils.dpToPixel(10);
        header.setPadding(footerPadding, footerPadding, footerPadding, footerPadding);
        header.setText(R.string.tip_sentence);
        header.setGravity(Gravity.CENTER_VERTICAL);
        header.setCompoundDrawablePadding(UiUtils.dpToPixel(5));
        header.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_action_about, 0,
                R.drawable.ic_action_cancel, 0);
        header.setClickable(true);
        header.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                mListView.removeHeaderView(header);
                PrefUtils.putBoolean(PrefUtils.DISPLAY_TIP, false);
            }
        });
        mListView.addHeaderView(header);
    }

    UiUtils.addEmptyFooterView(mListView, 90);

    mHideReadButton = (FloatingActionButton) rootView.findViewById(R.id.hide_read_button);
    mHideReadButton.setOnLongClickListener(new View.OnLongClickListener() {
        @Override
        public boolean onLongClick(View view) {
            UiUtils.displayHideReadButtonAction(mListView.getContext());
            return true;
        }
    });
    UiUtils.updateHideReadButton(mHideReadButton);

    mRefreshListBtn = (Button) rootView.findViewById(R.id.refreshListBtn);
    mRefreshListBtn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            mNewEntriesNumber = 0;
            mListDisplayDate = new Date().getTime();

            refreshUI();
            if (mUri != null) {
                restartLoaders();
            }
        }
    });

    mSearchView = (SearchView) rootView.findViewById(R.id.searchView);
    if (savedInstanceState != null) {
        refreshUI(); // To hide/show the search bar
    }

    mSearchView.post(new Runnable() { // Do this AFTER the text has been restored from saveInstanceState
        @Override
        public void run() {
            mSearchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
                @Override
                public boolean onQueryTextSubmit(String s) {
                    InputMethodManager imm = (InputMethodManager) getActivity()
                            .getSystemService(Context.INPUT_METHOD_SERVICE);
                    imm.hideSoftInputFromWindow(mSearchView.getWindowToken(), 0);
                    return false;
                }

                @Override
                public boolean onQueryTextChange(String s) {
                    setData(EntryColumns.SEARCH_URI(s), true);
                    return false;
                }
            });
        }
    });

    disableSwipe();

    return rootView;
}