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:org.weyoung.xianbicycle.BaseActivity.java

private void onNavDrawerItemClicked(final int itemId) {
    if (itemId == getCurrentNavDrawerItem()) {
        mDrawerLayout.closeDrawer(Gravity.START);
        return;/*from  ww w.j  a v a 2  s .c om*/
    }

    currentItem = itemId;

    // launch the target Activity after a short delay, to allow the close animation to play
    mHandler.postDelayed(new Runnable() {
        @Override
        public void run() {
            goToNavDrawerItem(itemId);
        }
    }, NAVDRAWER_LAUNCH_DELAY);

    // change the active item on the list so the user can see the item changed
    setSelectedNavDrawerItem(itemId);

    mDrawerLayout.closeDrawer(Gravity.START);
}

From source file:com.mishiranu.dashchan.ui.navigator.NavigatorActivity.java

@TargetApi(Build.VERSION_CODES.LOLLIPOP)
@Override/*w w  w .  java 2  s.c  om*/
public void onCreate(Bundle savedInstanceState) {
    currentPreferences = Preferences.getCurrent();
    if (C.API_LOLLIPOP) {
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        requestWindowFeature(Window.FEATURE_ACTION_MODE_OVERLAY);
    }
    ResourceUtils.applyPreferredTheme(this);
    expandedScreen = new ExpandedScreen(this, Preferences.isExpandedScreen());
    super.onCreate(savedInstanceState);
    getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
    float density = ResourceUtils.obtainDensity(this);
    setContentView(R.layout.activity_main);
    ClickableToast.register(clickableToastHolder);
    FavoritesStorage.getInstance().getObservable().register(this);
    watcherServiceClient.bind(this);
    pageManager = new PageManager();
    actionIconSet = new ActionIconSet(this);
    progressView = findViewById(R.id.progress);
    errorView = findViewById(R.id.error);
    errorText = (TextView) findViewById(R.id.error_text);
    listView = (PullableListView) findViewById(android.R.id.list);
    registerForContextMenu(listView);
    drawerCommon = (ViewGroup) findViewById(R.id.drawer_common);
    drawerWide = (ViewGroup) findViewById(R.id.drawer_wide);
    TypedArray typedArray = obtainStyledAttributes(new int[] { R.attr.styleDrawerSpecial });
    int drawerResId = typedArray.getResourceId(0, 0);
    typedArray.recycle();
    ContextThemeWrapper styledContext = drawerResId != 0 ? new ContextThemeWrapper(this, drawerResId) : this;
    int drawerBackground = ResourceUtils.getColor(styledContext, R.attr.backgroundDrawer);
    drawerCommon.setBackgroundColor(drawerBackground);
    drawerWide.setBackgroundColor(drawerBackground);
    drawerListView = new SortableListView(styledContext, this);
    drawerListView.setId(android.R.id.tabcontent);
    drawerListView.setOnSortingStateChangedListener(this);
    drawerForm = new DrawerForm(styledContext, this, this, watcherServiceClient);
    drawerForm.bind(drawerListView);
    drawerParent = new FrameLayout(this);
    drawerParent.addView(drawerListView);
    drawerCommon.addView(drawerParent);
    uiManager = new UiManager(this, this, expandedScreen);
    drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    if (C.API_LOLLIPOP) {
        FrameLayout foreground = new FrameLayout(this);
        drawerLayout.addView(foreground, drawerLayout.indexOfChild(drawerCommon), new DrawerLayout.LayoutParams(
                DrawerLayout.LayoutParams.MATCH_PARENT, DrawerLayout.LayoutParams.MATCH_PARENT));
        getLayoutInflater().inflate(R.layout.widget_toolbar, foreground);
        Toolbar toolbar = (Toolbar) foreground.findViewById(R.id.toolbar);
        setActionBar(toolbar);
        toolbarView = toolbar;
        expandedScreen.setToolbar(toolbar, foreground);
    } else {
        getActionBar().setIcon(R.drawable.ic_logo); // Show white logo on search
    }
    drawerToggle = new DrawerToggle(this, drawerLayout);
    if (C.API_LOLLIPOP) {
        drawerCommon.setElevation(6f * density);
        drawerWide.setElevation(4f * density);
    } else {
        drawerLayout.setDrawerShadow(R.drawable.drawer_shadow, Gravity.START);
    }
    drawerLayout.addDrawerListener(drawerToggle);
    drawerLayout.addDrawerListener(drawerForm);
    if (toolbarView == null) {
        drawerLayout.addDrawerListener(new ExpandedScreenDrawerLocker());
    }
    ViewUtils.applyToolbarStyle(this, toolbarView);
    if (Preferences.isActiveScrollbar()) {
        listView.setFastScrollEnabled(true);
        if (!C.API_LOLLIPOP) {
            ListViewUtils.colorizeListThumb4(listView);
        }
    }
    listView.setOnItemClickListener(this);
    listView.setOnItemLongClickListener(this);
    listView.getWrapper().setOnPullListener(this);
    listView.getWrapper().setPullStateListener(this);
    listView.setClipToPadding(false);
    ScrollListenerComposite scrollListenerComposite = new ScrollListenerComposite();
    listView.setOnScrollListener(scrollListenerComposite);
    scrollListenerComposite.add(new BusyScrollListener(this));
    updateWideConfiguration(true);
    expandedScreen.setDrawerOverToolbarEnabled(!wideMode);
    expandedScreen.setContentListView(listView, scrollListenerComposite);
    expandedScreen.setDrawerListView(drawerParent, drawerListView, drawerForm.getHeaderView());
    expandedScreen.addAdditionalView(progressView, true);
    expandedScreen.addAdditionalView(errorView, true);
    expandedScreen.finishInitialization();
    LocalBroadcastManager.getInstance(this).registerReceiver(newPostReceiver,
            new IntentFilter(C.ACTION_POST_SENT));
    if (savedInstanceState == null) {
        savedInstanceState = pageManager.readFromStorage();
    }
    PageHolder savedCurrentPageHolder = pageManager.restore(savedInstanceState);
    if (savedCurrentPageHolder != null) {
        navigatePageHolder(savedCurrentPageHolder, false);
    } else {
        navigateIntent(getIntent(), false);
    }
    if (savedInstanceState == null) {
        startUpdateTask();
        int drawerInitialPosition = Preferences.getDrawerInitialPosition();
        if (drawerInitialPosition != Preferences.DRAWER_INITIAL_POSITION_CLOSED) {
            if (!wideMode) {
                drawerLayout.post(() -> drawerLayout.openDrawer(Gravity.START));
            }
            if (drawerInitialPosition == Preferences.DRAWER_INITIAL_POSITION_FORUMS) {
                drawerForm.setChanSelectMode(true);
            }
        }
    }
}

From source file:com.example.office.ui.Office365DemoActivity.java

/**
 * Initializes activity UI elements.//from  w ww .  j av  a 2  s  .  c  o m
 */
private void initUi() {
    if (!mIsInitialized) {
        setContentView(R.layout.main_activity);

        mTitle = mDrawerTitle = getTitle();

        // Setting up Action Bar and Tabs.
        ActionBar actionBar = getActionBar();
        actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
        actionBar.setDisplayShowTitleEnabled(true);
        actionBar.setLogo(R.drawable.ic_action_mail);

        Tab tab = actionBar.newTab().setText(UI.Screen.CONTACTS.getName(this))
                .setTag(UI.Screen.CONTACTS.getName(this)).setTabListener(new TabListener<ContactsFragment>(this,
                        UI.Screen.CONTACTS.getName(this), ContactsFragment.class));
        actionBar.addTab(tab);

        tab = actionBar.newTab().setText(UI.Screen.MAILBOX.getName(this))
                .setTag(UI.Screen.MAILBOX.getName(this)).setTabListener(new TabListener<DraftsFragment>(this,
                        UI.Screen.MAILBOX.getName(this), DraftsFragment.class));
        actionBar.addTab(tab, true);

        tab = actionBar.newTab().setText(UI.Screen.CALENDAR.getName(this))
                .setTag(UI.Screen.CALENDAR.getName(this)).setTabListener(new TabListener<CalendarFragment>(this,
                        UI.Screen.CALENDAR.getName(this), CalendarFragment.class));
        actionBar.addTab(tab);

        // Setting up sliding drawer.
        mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
        mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, Gravity.START);
        mDrawerList = (ListView) findViewById(R.id.left_drawer);

        SlidingDrawerAdapter drawerAdapter = new SlidingDrawerAdapter(OfficeApplication.getContext(),
                R.layout.drawer_list_item, R.layout.drawer_delimiter);
        mDrawerList.setAdapter(drawerAdapter);

        mDrawerList.setOnItemClickListener(new ListView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                try {
                    Screen[] drawerScreens = ScreenGroup.DRAWER.getMembers().toArray(new Screen[0]);
                    Screen currentScreen = DEFAULT_SCREEN;

                    // use id instead of position here because some positions used by delimiters, id contains real index of clicked item
                    if (drawerScreens != null && drawerScreens.length - 1 >= id) {
                        currentScreen = drawerScreens[(int) id];
                    }
                    switchScreen(currentScreen);
                } catch (Exception e) {
                    Logger.logApplicationException(e, getClass().getSimpleName() + "onItemClick(): Error.");
                }
            }
        });

        actionBar.setHomeButtonEnabled(true);

        // ActionBarDrawerToggle ties together the the proper interactions
        // between the sliding drawer and the action bar app icon
        mDrawerToggle = new ActionBarDrawerToggle(this,
                /* host Activity */mDrawerLayout, /* DrawerLayout object */
                R.drawable.ic_drawer, /* drawer navigation image replacing '<' */
                R.string.drawer_open, R.string.drawer_close) {
            public void onDrawerClosed(View view) {
                getActionBar().setTitle(mTitle);
                invalidateOptionsMenu();
            }

            public void onDrawerOpened(View drawerView) {
                getActionBar().setTitle(mDrawerTitle);
                invalidateOptionsMenu();
            }
        };
        mDrawerLayout.setDrawerListener(mDrawerToggle);
        mIsInitialized = true;
    }

    if (mSavedFragmentTag == null) {
        switchScreen(DEFAULT_SCREEN);
    } else {
        // This is not used mostly as we're going back to this activity when it
        // is at the top of the back stack. So (as it does have 'singleTop' in parameters) it is
        // simply restored and onNewIntent() is called instead of onCreate().
        // So savedInstanceState will usually be null. This is added to anticipate other future use cases.
        switchScreen(Screen.getByTag(mSavedFragmentTag, this));
    }
}

From source file:io.github.douglasjunior.androidSimpleTooltip.SimpleTooltip.java

private void configContentView() {
    if (mContentView instanceof TextView) {
        TextView tv = (TextView) mContentView;
        tv.setText(mText);//from w  w w  .  java 2  s.c o m
    } else {
        TextView tv = (TextView) mContentView.findViewById(mTextViewId);
        if (tv != null)
            tv.setText(mText);
    }

    mContentView.setPadding(mPadding, mPadding, mPadding, mPadding);

    if (mShowArrow) {
        mArrowView = new ImageView(mContext);
        mArrowView.setImageDrawable(mArrowDrawable);
        LinearLayoutCompat.LayoutParams arrowLayoutParams;
        if (mGravity == Gravity.TOP || mGravity == Gravity.BOTTOM) {
            arrowLayoutParams = new LinearLayoutCompat.LayoutParams((int) mArrowWidth, (int) mArrowHeight, 0);
        } else {
            arrowLayoutParams = new LinearLayoutCompat.LayoutParams((int) mArrowHeight, (int) mArrowWidth, 0);
        }
        mArrowView.setLayoutParams(arrowLayoutParams);
        LinearLayoutCompat linearLayout = new LinearLayoutCompat(mContext);
        linearLayout.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
                ViewGroup.LayoutParams.WRAP_CONTENT));
        linearLayout.setOrientation(
                mGravity == Gravity.START || mGravity == Gravity.END ? LinearLayoutCompat.HORIZONTAL
                        : LinearLayoutCompat.VERTICAL);
        int padding = mAnimated ? mAnimationPadding : (int) SimpleTooltipUtils.pxFromDp(4);
        linearLayout.setPadding(padding, padding, padding, padding);

        if (mGravity == Gravity.TOP || mGravity == Gravity.START) {
            linearLayout.addView(mContentView);
            linearLayout.addView(mArrowView);
        } else {
            linearLayout.addView(mArrowView);
            linearLayout.addView(mContentView);
        }

        LinearLayoutCompat.LayoutParams contentViewParams = new LinearLayoutCompat.LayoutParams(
                ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT, 0);
        contentViewParams.gravity = Gravity.CENTER;
        mContentView.setLayoutParams(contentViewParams);

        mContentLayout = linearLayout;
    } else {
        mContentLayout = mContentView;
        mContentView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
                ViewGroup.LayoutParams.WRAP_CONTENT));
    }
    mContentLayout.setVisibility(View.INVISIBLE);
    mPopupWindow.setContentView(mContentLayout);
}

From source file:com.amaze.filemanager.ui.views.drawer.Drawer.java

private void setNavViewDimension(CustomNavigationView navView) {
    int screenWidth = AppConfig.getInstance().getScreenUtils().getScreenWidthInDp();
    int desiredWidthInDp = screenWidth - ScreenUtils.TOOLBAR_HEIGHT_IN_DP;
    int desiredWidthInPx = AppConfig.getInstance().getScreenUtils().convertDbToPx(desiredWidthInDp);

    navView.setLayoutParams(new DrawerLayout.LayoutParams(desiredWidthInPx,
            LinearLayout.LayoutParams.MATCH_PARENT, Gravity.START));
}

From source file:com.alburivan.slickform.tooltip.SimpleTooltip.java

private void configContentView() {
    if (mContentView instanceof TextView) {
        TextView tv = (TextView) mContentView;
        tv.setText(mText);//  ww  w . j a va2  s. c  o m
    } else {
        TextView tv = (TextView) mContentView.findViewById(mTextViewId);
        if (tv != null)
            tv.setText(mText);
    }

    mContentView.setPadding((int) mPadding, (int) mPadding, (int) mPadding, (int) mPadding);

    if (mShowArrow) {
        mArrowView = new ImageView(mContext);
        mArrowView.setImageDrawable(mArrowDrawable);
        LinearLayoutCompat.LayoutParams arrowLayoutParams;
        if (mGravity == Gravity.TOP || mGravity == Gravity.BOTTOM) {
            arrowLayoutParams = new LinearLayoutCompat.LayoutParams((int) mArrowWidth, (int) mArrowHeight, 0);
        } else {
            arrowLayoutParams = new LinearLayoutCompat.LayoutParams((int) mArrowHeight, (int) mArrowWidth, 0);
        }
        mArrowView.setLayoutParams(arrowLayoutParams);
        LinearLayoutCompat linearLayout = new LinearLayoutCompat(mContext);
        linearLayout.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
                ViewGroup.LayoutParams.WRAP_CONTENT));
        linearLayout.setOrientation(
                mGravity == Gravity.START || mGravity == Gravity.END ? LinearLayoutCompat.HORIZONTAL
                        : LinearLayoutCompat.VERTICAL);
        int padding = mAnimated ? mAnimationPadding : (int) SimpleTooltipUtils.pxFromDp(4);
        linearLayout.setPadding(padding, padding, padding, padding);

        if (mGravity == Gravity.TOP || mGravity == Gravity.START) {
            linearLayout.addView(mContentView);
            linearLayout.addView(mArrowView);
        } else {
            linearLayout.addView(mArrowView);
            linearLayout.addView(mContentView);
        }

        LinearLayoutCompat.LayoutParams contentViewParams = new LinearLayoutCompat.LayoutParams(
                ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT, 0);
        contentViewParams.gravity = Gravity.CENTER;
        mContentView.setLayoutParams(contentViewParams);

        mContentLayout = linearLayout;
    } else {
        mContentLayout = mContentView;
        mContentView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
                ViewGroup.LayoutParams.WRAP_CONTENT));
    }
    mContentLayout.setVisibility(View.INVISIBLE);
    mPopupWindow.setContentView(mContentLayout);
}

From source file:ca.zadrox.dota2esportticker.ui.BaseActivity.java

protected boolean isNavDrawerOpen() {
    return mDrawerLayout != null && mDrawerLayout.isDrawerOpen(Gravity.START);
}

From source file:com.davisosa.structura.activities.base.BaseActivity.java

protected ActionBarDrawerToggleWrapper setupDrawerToggle(Toolbar toolbar, DrawerLayout drawerLayout,
        final DrawerLayout.DrawerListener drawerListener) {
    ActionBarDrawerToggle drawerToggle = new ActionBarDrawerToggle(this, /* host Activity */
            drawerLayout, /* DrawerLayout object */
            toolbar, /* action bar Toolbar */
            R.string.drawer_open, /* "open drawer" description for accessibility */
            R.string.drawer_close /* "close drawer" description for accessibility */
    ) {//from w w w. j a  va 2 s  . com
        @Override
        public void onDrawerClosed(View drawerView) {
            super.onDrawerClosed(drawerView);
            drawerListener.onDrawerClosed(drawerView);
        }

        @Override
        public void onDrawerOpened(View drawerView) {
            super.onDrawerOpened(drawerView);
            drawerListener.onDrawerOpened(drawerView);
        }

        @Override
        public void onDrawerStateChanged(int newState) {
            super.onDrawerStateChanged(newState);
            drawerListener.onDrawerStateChanged(newState);
        }

        @Override
        public void onDrawerSlide(View drawerView, float slideOffset) {
            super.onDrawerSlide(drawerView, slideOffset);
            drawerListener.onDrawerSlide(drawerView, slideOffset);
        }
    };

    drawerToggle.setToolbarNavigationClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            mDrawerLayout.openDrawer(Gravity.START);
        }
    });

    drawerLayout.setDrawerListener(drawerToggle);
    return new ActionBarDrawerToggleWrapper(drawerToggle);
}

From source file:com.cyanogenmod.filemanager.ui.widgets.ActionBarDrawerToggle.java

/**
 * Enable or disable the drawer indicator. The indicator defaults to
 * enabled./*from w ww  .  j a v a2  s . com*/
 *
 * <p>
 * When the indicator is disabled, the <code>ActionBar</code> will revert to
 * displaying the home-as-up indicator provided by the <code>Activity</code>
 * 's theme in the <code>android.R.attr.homeAsUpIndicator</code> attribute
 * instead of the animated drawer glyph.
 * </p>
 *
 * @param enable
 *            true to enable, false to disable
 */
public void setDrawerIndicatorEnabled(boolean enable) {
    if (enable != mDrawerIndicatorEnabled) {
        if (enable) {
            setActionBarUpIndicator(mSlider,
                    mDrawerLayout.isDrawerOpen(Gravity.START) ? mCloseDrawerContentDescRes
                            : mOpenDrawerContentDescRes);
        } else {
            setActionBarUpIndicator(mThemeImage, 0);
        }
        mDrawerIndicatorEnabled = enable;
    }
}

From source file:com.syncedsynapse.kore2.ui.NavigationDrawerFragment.java

private void selectItem(DrawerItem item, int position) {
    if (item.type == DrawerItem.TYPE_DIVIDER)
        return;//  w  ww. j a va  2  s  .c om

    if (mDrawerListView != null) {
        mDrawerListView.setItemChecked(position, true);
    }
    mDrawerLayout.closeDrawer(Gravity.START);

    // Same activity, just return
    if (item.id == getItemIdFromActivity())
        return;

    final Intent launchIntentFinal = new Intent(getActivity(), activityItemIdMap.get(item.id))
            .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    mDrawerLayout.postDelayed(new Runnable() {
        @Override
        public void run() {
            startActivity(launchIntentFinal);
            getActivity().overridePendingTransition(R.anim.activity_in, R.anim.activity_out);
        }
    }, CLOSE_DELAY);
}