Example usage for android.view Gravity START

List of usage examples for android.view Gravity START

Introduction

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

Prototype

int START

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

Click Source Link

Document

Push object to x-axis position at the start of its container, not changing its size.

Usage

From source file:com.wanderingcan.persistentsearch.PersistentSearchView.java

@SuppressWarnings("deprecation")
private void initialize(Context context, AttributeSet attrs, int defStyleAttr) {
    mNavIcon = new ImageButton(context);
    mEndIcon = new ImageButton(context);
    mSearchText = new EditText(context);
    mSearchMenuView = new SearchMenuView(context);
    mDivider = new View(context);
    mDivider.setVisibility(GONE);/*from w  ww.  j  av a 2  s . c  o m*/

    mPresenter = new SearchMenuPresenter(context, new SearchMenuListener());

    mSearchMenuView.setAdapter(mPresenter.mAdapter);
    mSearchMenuView.addItemDecoration(new DividerItemDecoration(context, attrs));

    int[] attr = { android.R.attr.listDivider };
    TypedArray ta = context.obtainStyledAttributes(attr);
    Drawable divider = ta.getDrawable(0);
    ta.recycle();

    mOpened = false;
    mShowClearDrawable = false;
    mShowMenu = true;

    //Set up CardView
    setUseCompatPadding(true);
    setFocusable(true);
    setFocusableInTouchMode(true);

    //Set up TextView
    if (Build.VERSION.SDK_INT >= 16) {
        mSearchText.setBackground(null);
        mNavIcon.setBackground(null);
        mEndIcon.setBackground(null);
        mDivider.setBackground(divider);
    } else {
        mSearchText.setBackgroundDrawable(null);
        mNavIcon.setBackgroundDrawable(null);
        mEndIcon.setBackgroundDrawable(null);
        mDivider.setBackgroundDrawable(divider);
    }
    mSearchText.setSingleLine();
    mHintVisible = false;
    mSearchText.setOnFocusChangeListener(new SearchFocusListener());
    mSearchText.setOnEditorActionListener(new EditTextEditorAction());
    mSearchText.setImeOptions(EditorInfo.IME_ACTION_SEARCH);
    mSearchText.addTextChangedListener(new EditTextTextWatcher());

    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.PersistentSearchView, defStyleAttr, 0);
    Drawable drawable = a.getDrawable(R.styleable.PersistentSearchView_navSrc);
    setNavigationDrawable(drawable);
    mNavIcon.setScaleType(ImageView.ScaleType.FIT_CENTER);
    mNavIcon.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            if (mIconListener != null) {
                mIconListener.OnNavigationIconClick();
            }
        }
    });

    drawable = a.getDrawable(R.styleable.PersistentSearchView_endSrc);
    setEndDrawable(drawable);
    mClearDrawable = ContextCompat.getDrawable(getContext(), R.drawable.ic_action_cancel);
    mEndIcon.setScaleType(ImageView.ScaleType.FIT_CENTER);
    mEndIcon.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            if (mShowClearDrawable) {
                //Clears the text
                mSearchText.setText(EMPTY);
            } else {
                if (mIconListener != null) {
                    mIconListener.OnEndIconClick();
                }
            }
        }
    });

    mHint = a.getText(R.styleable.PersistentSearchView_hint);
    mHintAlwaysVisible = a.getBoolean(R.styleable.PersistentSearchView_hintAlwaysActive, false);
    if (mHintAlwaysVisible) {
        mSearchText.setHint(mHint);
    }
    a.recycle();

    Resources res = context.getResources();
    int imageDimen = res.getDimensionPixelSize(R.dimen.persistent_search_view_image_dimen);
    mImageMargin = res.getDimensionPixelSize(R.dimen.persistent_search_view_image_side_margin);
    int imageTopMargin = res.getDimensionPixelSize(R.dimen.persistent_search_view_image_top_margin);

    //Sets all of the locations of the views
    CardView.LayoutParams lpNav = generateDefaultLayoutParams();
    lpNav.width = lpNav.height = imageDimen;

    CardView.LayoutParams lpEnd = (LayoutParams) generateLayoutParams(lpNav);

    lpNav.gravity = Gravity.START;
    lpEnd.gravity = Gravity.END;

    if (Build.VERSION.SDK_INT >= 17) {
        mNavIcon.setPaddingRelative(mImageMargin, imageTopMargin, mImageMargin / 2, imageTopMargin);
        mEndIcon.setPaddingRelative(mImageMargin / 2, imageTopMargin, mImageMargin, imageTopMargin);
    } else {
        mNavIcon.setPadding(mImageMargin, imageTopMargin, mImageMargin / 2, imageTopMargin);
        mEndIcon.setPadding(mImageMargin / 2, imageTopMargin, mImageMargin, imageTopMargin);
    }

    CardView.LayoutParams lpText = generateDefaultLayoutParams();
    lpText.gravity = Gravity.TOP;
    lpText.height = lpNav.topMargin + lpNav.height;
    mTextMargin = res.getDimensionPixelSize(R.dimen.persistent_search_view_text_margin);
    if (Build.VERSION.SDK_INT >= 17) {
        lpText.setMarginStart(mTextMargin);
        lpText.setMarginEnd(mTextMargin);
    } else {
        lpText.leftMargin = lpText.rightMargin = mTextMargin;
    }
    lpText = setupSearchTextMargin(lpText);

    CardView.LayoutParams lpMenu = generateDefaultLayoutParams();
    lpMenu.topMargin = lpNav.topMargin + lpNav.height;
    lpMenu.height = RecyclerView.LayoutParams.WRAP_CONTENT;

    CardView.LayoutParams lpDivider = generateDefaultLayoutParams();
    if (divider != null) {
        lpDivider.height = divider.getIntrinsicHeight();
    }
    lpDivider.topMargin = lpNav.topMargin + lpNav.height;

    //Adds the views to the PersistentSearchView
    addView(mNavIcon, lpNav);
    addView(mEndIcon, lpEnd);
    addView(mSearchText, lpText);
    addView(mSearchMenuView, lpMenu);
    addView(mDivider, lpDivider);
}

From source file:com.battlelancer.seriesguide.ui.BaseNavDrawerActivity.java

@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
    Intent launchIntent = null;/*from   www .  j a  v  a2s .co  m*/

    switch (position) {
    case MENU_ITEM_SHOWS_POSITION:
        if (this instanceof ShowsActivity) {
            break;
        }
        launchIntent = new Intent(this, ShowsActivity.class).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP
                | Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP);
        Utils.trackAction(this, TAG_NAV_DRAWER, "Shows");
        break;
    case MENU_ITEM_LISTS_POSITION:
        if (this instanceof ListsActivity) {
            break;
        }
        launchIntent = new Intent(this, ListsActivity.class).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
        Utils.trackAction(this, TAG_NAV_DRAWER, "Lists");
        break;
    case MENU_ITEM_MOVIES_POSITION:
        if (this instanceof MoviesActivity) {
            break;
        }
        launchIntent = new Intent(this, MoviesActivity.class).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
        Utils.trackAction(this, TAG_NAV_DRAWER, "Movies");
        break;
    case MENU_ITEM_STATS_POSITION:
        if (this instanceof StatsActivity) {
            break;
        }
        launchIntent = new Intent(this, StatsActivity.class).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
        Utils.trackAction(this, TAG_NAV_DRAWER, "Statistics");
        break;
    case MENU_ITEM_SETTINGS_POSITION:
        launchIntent = new Intent(this, SeriesGuidePreferences.class);
        Utils.trackAction(this, TAG_NAV_DRAWER, "Settings");
        break;
    case MENU_ITEM_HELP_POSITION:
        launchIntent = new Intent(this, HelpActivity.class);
        Utils.trackAction(this, TAG_NAV_DRAWER, "Help");
        break;
    case MENU_ITEM_SUBSCRIBE_POSITION:
        if (Utils.isAmazonVersion()) {
            launchIntent = new Intent(this, AmazonBillingActivity.class);
        } else {
            launchIntent = new Intent(this, BillingActivity.class);
        }
        Utils.trackAction(this, TAG_NAV_DRAWER, "Unlock");
        break;
    }

    // already displaying correct screen
    if (launchIntent != null) {
        final Intent finalLaunchIntent = launchIntent;
        mHandler.postDelayed(new Runnable() {
            @Override
            public void run() {
                goToNavDrawerItem(finalLaunchIntent);
            }
        }, NAVDRAWER_CLOSE_DELAY);
    }

    mDrawerLayout.closeDrawer(Gravity.START);
}

From source file:ti.modules.titanium.ui.widget.TiUIDrawerLayout.java

public boolean isLeftVisible() {
    return layout.isDrawerVisible(Gravity.START);
}

From source file:com.iangclifton.android.floatlabel.FloatLabel.java

@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
private void layoutChild(View child, int parentLeft, int parentTop, int parentRight, int parentBottom) {
    if (child.getVisibility() != GONE) {
        final LayoutParams lp = (LayoutParams) child.getLayoutParams();

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

        int childLeft;
        final int childTop = parentTop + lp.topMargin;

        int gravity = lp.gravity;
        if (gravity == -1) {
            gravity = Gravity.TOP | Gravity.START;
        }//w w  w .j  a va  2  s  .c o  m

        final int layoutDirection;
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) {
            layoutDirection = LAYOUT_DIRECTION_LTR;
        } else {
            layoutDirection = getLayoutDirection();
        }

        final int absoluteGravity = GravityCompat.getAbsoluteGravity(gravity, layoutDirection);

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

        child.layout(childLeft, childTop, childLeft + width, childTop + height);
    }
}

From source file:org.openmrs.mobile.activities.formdisplay.FormDisplayPageFragment.java

@Override
public void createAndAttachSelectQuestionDropdown(Question question, LinearLayout sectionLinearLayout) {
    TextView textView = new TextView(getActivity());
    textView.setPadding(20, 0, 0, 0);/*w  w w.j av a 2 s  .  c  o  m*/
    textView.setText(question.getLabel());
    Spinner spinner = (Spinner) getActivity().getLayoutInflater().inflate(R.layout.form_dropdown, null);

    LinearLayout questionLinearLayout = new LinearLayout(getActivity());
    LinearLayout.LayoutParams questionLinearLayoutParams = new LinearLayout.LayoutParams(
            LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
    questionLinearLayout.setOrientation(LinearLayout.VERTICAL);
    questionLinearLayoutParams.gravity = Gravity.START;
    questionLinearLayout.setLayoutParams(questionLinearLayoutParams);

    List<String> answerLabels = new ArrayList<>();
    for (Answer answer : question.getQuestionOptions().getAnswers()) {
        answerLabels.add(answer.getLabel());
    }

    SelectOneField spinnerField = new SelectOneField(question.getQuestionOptions().getAnswers(),
            question.getQuestionOptions().getConcept());

    ArrayAdapter arrayAdapter = new ArrayAdapter(getActivity(), android.R.layout.simple_spinner_item,
            answerLabels);
    spinner.setAdapter(arrayAdapter);

    LinearLayout.LayoutParams linearLayoutParams = new LinearLayout.LayoutParams(
            LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);

    questionLinearLayout.addView(textView);
    questionLinearLayout.addView(spinner);

    sectionLinearLayout.setLayoutParams(linearLayoutParams);
    sectionLinearLayout.addView(questionLinearLayout);

    SelectOneField selectOneField = getSelectOneField(spinnerField.getConcept());
    if (selectOneField != null) {
        spinner.setSelection(selectOneField.getChosenAnswerPosition());
        setOnItemSelectedListener(spinner, selectOneField);
    } else {
        setOnItemSelectedListener(spinner, spinnerField);
        selectOneFields.add(spinnerField);
    }
}

From source file:android.support.transition.Slide.java

/**
 * Change the edge that Views appear and disappear from.
 *
 * @param slideEdge The edge of the scene to use for Views appearing and disappearing. One of
 *                  {@link android.view.Gravity#LEFT}, {@link android.view.Gravity#TOP},
 *                  {@link android.view.Gravity#RIGHT}, {@link android.view.Gravity#BOTTOM},
 *                  {@link android.view.Gravity#START}, {@link android.view.Gravity#END}.
 *//* ww  w.  jav  a2  s .  c o  m*/
public void setSlideEdge(@GravityFlag int slideEdge) {
    switch (slideEdge) {
    case Gravity.LEFT:
        mSlideCalculator = sCalculateLeft;
        break;
    case Gravity.TOP:
        mSlideCalculator = sCalculateTop;
        break;
    case Gravity.RIGHT:
        mSlideCalculator = sCalculateRight;
        break;
    case Gravity.BOTTOM:
        mSlideCalculator = sCalculateBottom;
        break;
    case Gravity.START:
        mSlideCalculator = sCalculateStart;
        break;
    case Gravity.END:
        mSlideCalculator = sCalculateEnd;
        break;
    default:
        throw new IllegalArgumentException("Invalid slide direction");
    }
    mSlideEdge = slideEdge;
    SidePropagation propagation = new SidePropagation();
    propagation.setSide(slideEdge);
    setPropagation(propagation);
}

From source file:me.xiaopan.android.spear.sample.activity.MainActivity.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_MENU) {
        if (drawerLayout.isDrawerOpen(Gravity.START)) {
            drawerLayout.closeDrawer(Gravity.START);
        } else {//from   w  w  w . jav  a2 s .  c  o m
            drawerLayout.openDrawer(Gravity.START);
        }
        return true;
    } else {
        return super.onKeyDown(keyCode, event);
    }
}

From source file:com.tct.mail.ui.OnePaneController.java

@Override
public boolean onCreate(Bundle savedInstanceState) {
    mDrawerContainer = (DrawerLayout) mActivity.findViewById(R.id.drawer_container);
    mDrawerContainer.setDrawerTitle(Gravity.START,
            mActivity.getActivityContext().getString(R.string.drawer_title));
    final String drawerPulloutTag = mActivity.getString(R.string.drawer_pullout_tag);
    mDrawerPullout = mDrawerContainer.findViewWithTag(drawerPulloutTag);
    mDrawerPullout.setBackgroundResource(R.color.list_background_color);

    // CV is initially GONE on 1-pane (mode changes trigger visibility changes)
    mActivity.findViewById(R.id.conversation_pager).setVisibility(View.GONE);

    // The parent class sets the correct viewmode and starts the application off.
    return super.onCreate(savedInstanceState);
}

From source file:com.vinfotech.widget.FloatLabel.java

@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
private void layoutChild(View child, int parentLeft, int parentTop, int parentRight, int parentBottom) {
    if (child.getVisibility() != GONE) {
        final LayoutParams lp = (LayoutParams) child.getLayoutParams();

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

        int childLeft;
        final int childTop = parentTop + lp.topMargin;

        int gravity = lp.gravity;
        if (gravity == -1) {
            gravity = Gravity.TOP | Gravity.START;
        }//from   w  ww.  ja v  a 2  s  . c o m

        final int layoutDirection;
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) {
            layoutDirection = LAYOUT_DIRECTION_LTR;
        } else {
            layoutDirection = getLayoutDirection();
        }

        final int absoluteGravity = GravityCompat.getAbsoluteGravity(gravity, layoutDirection);

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

        default:
            childLeft = parentLeft + lp.leftMargin;
        }

        child.layout(childLeft, childTop, childLeft + width, childTop + height);
    }
}

From source file:com.cryart.sabbathschool.ui.activity.SSMainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.ss_main_activity);
    setupWidgets();/*www  . ja  va2  s . co  m*/

    setSupportActionBar(_SSToolbar);

    for (int i = 0; i < _SSToolbar.getChildCount(); i++) {
        if (_SSToolbar.getChildAt(i) instanceof TextView) {
            _SSToolbarTitle = (TextView) _SSToolbar.getChildAt(i);
            break;
        }
    }

    _SSActionBarToggle.setDrawerIndicatorEnabled(true);

    _SSDrawerLayout.setDrawerListener(_SSActionBarToggle);
    _SSDrawerLayout.setDrawerShadow(R.drawable.ss_menu_shadow, Gravity.START);

    _SSCurrentLesson = _SSCore.ssGetTodaysLesson();
    _SSDays = _SSCore.ssGetDaysByLessonSerial(_SSCurrentLesson._serial);

    _SSPager.setAdapter(new SSTabsAdapter(this, getSupportFragmentManager(), new ArrayList<SSDay>()));

    _SSPager.setOffscreenPageLimit(SSConstants.SS_PAGER_OFFSCREEN_PAGE_LIMIT);

    ViewGroup.LayoutParams lp = _SSStatusBar.getLayoutParams();
    lp.height = SSHelper.getStatusBarHeight(this);
    _SSStatusBar.setLayoutParams(lp);

    _SSTabs.setCustomTabView(R.layout.ss_tab_indicator, android.R.id.text1);
    _SSTabs.setViewPager(_SSPager);

    setToolbarStatusBarAlpha(SS_TOOLBAR_STATUS_BAR_ALPHA);
    _SSTabs.setBackgroundColor(getResources().getColor(R.color.ss_primary));

    _SSMenu.setAdapter(new SSMenuAdapter(this, new LinkedHashMap<Object, ArrayList<?>>()));

    this.setMainView();
    this.setTab(_SSCore.ssGetDay(_SSCore.ssTodaysDate()));

    _SSMenu.setOnGroupClickListener(this);
    _SSMenu.setOnChildClickListener(this);
    _SSPreferences.registerOnSharedPreferenceChangeListener(this);

    AppRate.with(this).setInstallDays(SSConstants.SS_APP_RATE_INSTALL_DAYS).monitor();
    AppRate.showRateDialogIfMeetsConditions(this);
}