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.starfishrespect.myconsumption.android.ui.BaseActivity.java

/**
 * Sets up the navigation drawer as appropriate. Note that the nav drawer will be
 * different depending on whether the attendee indicated that they are attending the
 * event on-site vs. attending remotely.
 *///from www  .  j av a  2  s. c  om
private void setupNavDrawer() {
    // What nav drawer item should be selected?
    int selfItem = getSelfNavDrawerItem();

    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    if (mDrawerLayout == null) {
        return;
    }
    mDrawerLayout.setStatusBarBackgroundColor(getResources().getColor(R.color.theme_primary_dark));
    ScrimInsetsScrollView navDrawer = (ScrimInsetsScrollView) mDrawerLayout.findViewById(R.id.navdrawer);
    if (selfItem == NAVDRAWER_ITEM_INVALID) {
        // do not show a nav drawer
        if (navDrawer != null) {
            ((ViewGroup) navDrawer.getParent()).removeView(navDrawer);
        }
        mDrawerLayout = null;
        return;
    }

    if (navDrawer != null) {
        final View chosenAccountContentView = findViewById(R.id.chosen_account_content_view);
        final View chosenAccountView = findViewById(R.id.chosen_account_view);
        final int navDrawerChosenAccountHeight = getResources()
                .getDimensionPixelSize(R.dimen.navdrawer_chosen_account_height);
        navDrawer.setOnInsetsCallback(new ScrimInsetsScrollView.OnInsetsCallback() {
            @Override
            public void onInsetsChanged(Rect insets) {
                ViewGroup.MarginLayoutParams lp = (ViewGroup.MarginLayoutParams) chosenAccountContentView
                        .getLayoutParams();
                lp.topMargin = insets.top;
                chosenAccountContentView.setLayoutParams(lp);

                ViewGroup.LayoutParams lp2 = chosenAccountView.getLayoutParams();
                lp2.height = navDrawerChosenAccountHeight + insets.top;
                chosenAccountView.setLayoutParams(lp2);
            }
        });
    }

    if (mActionBarToolbar != null) {
        mActionBarToolbar.setNavigationIcon(R.drawable.ic_drawer);
        mActionBarToolbar.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                mDrawerLayout.openDrawer(Gravity.START);
            }
        });
    }

    mDrawerLayout.setDrawerListener(new DrawerLayout.DrawerListener() {
        @Override
        public void onDrawerClosed(View drawerView) {
            // run deferred action, if we have one
            if (mDeferredOnDrawerClosedRunnable != null) {
                mDeferredOnDrawerClosedRunnable.run();
                mDeferredOnDrawerClosedRunnable = null;
            }
            onNavDrawerStateChanged(false, false);
        }

        @Override
        public void onDrawerOpened(View drawerView) {
            onNavDrawerStateChanged(true, false);
        }

        @Override
        public void onDrawerStateChanged(int newState) {
            onNavDrawerStateChanged(isNavDrawerOpen(), newState != DrawerLayout.STATE_IDLE);
        }

        @Override
        public void onDrawerSlide(View drawerView, float slideOffset) {
            onNavDrawerSlide(slideOffset);
        }
    });

    mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, Gravity.START);

    // populate the nav drawer with the correct items
    populateNavDrawer();

    // TODO could be interesting
    //        // When the user runs the app for the first time, we want to land them with the
    //        // navigation drawer open. But just the first time.
    //        if (!PrefUtils.isWelcomeDone(this)) {
    //            // first run of the app starts with the nav drawer open
    //            PrefUtils.markWelcomeDone(this);
    //            mDrawerLayout.openDrawer(Gravity.START);
    //        }
}

From source file:edu.ptu.navpattern.tooltip.Tooltip.java

private PointF calculateLocation() {
    PointF location = new PointF();

    final RectF anchorRect = calculateRectInWindow(mAnchorView);
    final PointF anchorCenter = new PointF(anchorRect.centerX(), anchorRect.centerY());

    switch (mGravity) {
    case Gravity.START:
        location.x = anchorRect.left - mContentView.getWidth() - mMargin;
        location.y = anchorCenter.y - mContentView.getHeight() / 2f;
        break;//from  ww w.j ava 2  s.c om
    case Gravity.END:
        location.x = anchorRect.right + mMargin;
        location.y = anchorCenter.y - mContentView.getHeight() / 2f;
        break;
    case Gravity.TOP:
        location.x = anchorCenter.x - mContentView.getWidth() / 2f;
        location.y = anchorRect.top - mContentView.getHeight() - mMargin;
        break;
    case Gravity.BOTTOM:
        location.x = anchorCenter.x - mContentView.getWidth() / 2f;
        location.y = anchorRect.bottom + mMargin;
        break;
    }

    return location;
}

From source file:ch.citux.td.ui.TDActivity.java

@Override
public void onBackPressed() {
    if (drawerLayout != null && drawerLayout.isDrawerOpen(Gravity.START)) {
        drawerLayout.closeDrawers();/*from   w  w w.ja v a2  s  .c  o  m*/
    } else {
        super.onBackPressed();
    }
}

From source file:com.htc.dotdesign.ToolBoxService.java

private void setToolPanelVisibility(boolean bShow) {
    if (mCurrExtend != null) {
        mWindowManager.removeView(mCurrExtend);
        mCurrExtend = null;/*from  w  w  w . jav  a 2s .  c  o  m*/
    }

    if (bShow) {
        mIsToolBarExtend = true;
        if (mCurrFun == FunType.Fun_Palette) {
            Resources res = getResources();
            WindowManager.LayoutParams params = new WindowManager.LayoutParams(
                    WindowManager.LayoutParams.WRAP_CONTENT, WindowManager.LayoutParams.WRAP_CONTENT,
                    WindowManager.LayoutParams.TYPE_PHONE, WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
                    PixelFormat.TRANSLUCENT);
            params.gravity = Gravity.START;
            if (mDragButtonParams.y < mScreenHeight / 2) {
                params.gravity = Gravity.TOP | params.gravity;
                params.y = mDragButtonParams.y + mDragButtonHeight;
                View top_arrow = mPalette.findViewById(R.id.top_arrow);
                top_arrow.setVisibility(View.VISIBLE);
                View bottom_arrow = mPalette.findViewById(R.id.bottom_arrow);
                bottom_arrow.setVisibility(View.GONE);
            } else {
                params.gravity = Gravity.BOTTOM | params.gravity;
                params.y = mScreenHeight - mDragButtonParams.y;
                View top_arrow = mPalette.findViewById(R.id.top_arrow);
                top_arrow.setVisibility(View.GONE);
                View bottom_arrow = mPalette.findViewById(R.id.bottom_arrow);
                bottom_arrow.setVisibility(View.VISIBLE);
            }
            int[] locations = new int[2];
            mBtnPalette.getLocationOnScreen(locations);
            int x = locations[0];
            params.x = (x + mBtnPalette.getWidth() / 2)
                    - (mArrowWidth / 2 + res.getDimensionPixelSize(R.dimen.h02));

            mPalette.setVisibility(View.VISIBLE);
            mWindowManager.addView(mPalette, params);
            mCurrExtend = mPalette;
            initBrushSize();
        } else if (mCurrFun == FunType.Fun_Eraser) {
            Resources res = getResources();
            WindowManager.LayoutParams params = new WindowManager.LayoutParams(
                    WindowManager.LayoutParams.WRAP_CONTENT, WindowManager.LayoutParams.WRAP_CONTENT,
                    WindowManager.LayoutParams.TYPE_PHONE, WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
                    PixelFormat.TRANSLUCENT);
            params.gravity = Gravity.START;
            if (mDragButtonParams.y < mScreenHeight / 2) {
                params.gravity = Gravity.TOP | params.gravity;
                params.y = mDragButtonParams.y + mDragButtonHeight;
                View top_arrow = mEraser.findViewById(R.id.top_arrow);
                top_arrow.setVisibility(View.VISIBLE);
                View bottom_arrow = mEraser.findViewById(R.id.bottom_arrow);
                bottom_arrow.setVisibility(View.GONE);
            } else {
                params.gravity = Gravity.BOTTOM | params.gravity;
                params.y = mScreenHeight - mDragButtonParams.y;
                View top_arrow = mEraser.findViewById(R.id.top_arrow);
                top_arrow.setVisibility(View.GONE);
                View bottom_arrow = mEraser.findViewById(R.id.bottom_arrow);
                bottom_arrow.setVisibility(View.VISIBLE);
            }
            int[] locations = new int[2];
            mBtnEraser.getLocationOnScreen(locations);
            int x = locations[0];
            params.x = (x + mBtnEraser.getWidth() / 2)
                    - (mArrowWidth / 2 + res.getDimensionPixelSize(R.dimen.h02));

            mEraser.setVisibility(View.VISIBLE);
            mWindowManager.addView(mEraser, params);
            mCurrExtend = mEraser;
            initBrushSize();
        } else if (mCurrFun == FunType.Fun_VirtualDot) {

        } else if (mCurrFun == FunType.Fun_Menu) {
            Resources res = getResources();
            WindowManager.LayoutParams params = new WindowManager.LayoutParams(
                    WindowManager.LayoutParams.WRAP_CONTENT, WindowManager.LayoutParams.WRAP_CONTENT,
                    WindowManager.LayoutParams.TYPE_PHONE, WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
                    PixelFormat.TRANSLUCENT);
            params.gravity = Gravity.END;
            if (mDragButtonParams.y < mScreenHeight / 2) {
                params.gravity = Gravity.TOP | params.gravity;
                params.y = mDragButtonParams.y + mDragButtonHeight;
                // Set top_arrow to visible and align to parent right.
                View top_arrow = mMenu.findViewById(R.id.top_arrow);
                top_arrow.setVisibility(View.VISIBLE);
                LinearLayout.LayoutParams arrowParams = (LinearLayout.LayoutParams) top_arrow.getLayoutParams();
                arrowParams.setMarginEnd(res.getDimensionPixelSize(R.dimen.h02));
                arrowParams.gravity = Gravity.END;
                top_arrow.setLayoutParams(arrowParams);
                // Set bottom_arrow to gone
                View bottom_arrow = mMenu.findViewById(R.id.bottom_arrow);
                bottom_arrow.setVisibility(View.GONE);
            } else {
                params.gravity = Gravity.BOTTOM | params.gravity;
                params.y = mScreenHeight - mDragButtonParams.y;
                // Set top_arrow to gone
                View top_arrow = mMenu.findViewById(R.id.top_arrow);
                top_arrow.setVisibility(View.GONE);
                // Set bottom_arrow to visible and align to parent right.
                View bottom_arrow = mMenu.findViewById(R.id.bottom_arrow);
                LinearLayout.LayoutParams arrowParams = (LinearLayout.LayoutParams) bottom_arrow
                        .getLayoutParams();
                arrowParams.setMarginEnd(res.getDimensionPixelSize(R.dimen.h02));
                arrowParams.gravity = Gravity.END;
                bottom_arrow.setLayoutParams(arrowParams);
                bottom_arrow.setVisibility(View.VISIBLE);
            }
            int[] locations = new int[2];
            mBtnMenu.getLocationOnScreen(locations);
            int x = locations[0];
            //params.x = (x + mBtnMenu.getWidth()/2) - (mArrowWidth/2 + res.getDimensionPixelSize(R.dimen.h02));
            params.x = mScreenWidth - (x + mBtnMenu.getWidth() / 2)
                    - (mArrowWidth / 2 + res.getDimensionPixelSize(R.dimen.h02));

            mMenu.setVisibility(View.VISIBLE);
            mWindowManager.addView(mMenu, params);
            mCurrExtend = mMenu;
        }
    } else {
        mIsToolBarExtend = false;
    }

    updateToolBarFunIconColor();
}

From source file:org.chromium.chrome.browser.download.ui.DownloadManagerUi.java

/**
 * Called when the UI needs to react to the back button being pressed.
 *
 * @return Whether the back button was handled.
 *///from   w  ww.ja v a  2s  .c  om
public boolean onBackPressed() {
    if (mMainView instanceof DrawerLayout) {
        DrawerLayout drawerLayout = (DrawerLayout) mMainView;
        if (drawerLayout.isDrawerOpen(Gravity.START)) {
            closeDrawer();
            return true;
        }
    }
    if (mBackendProvider.getSelectionDelegate().isSelectionEnabled()) {
        mBackendProvider.getSelectionDelegate().clearSelection();
        return true;
    }
    return false;
}

From source file:com.mobimvp.cliques.ui.BaseActivity.java

/**
 * Sets up the navigation drawer as appropriate. Note that the nav drawer will be
 * different depending on whether the attendee indicated that they are attending the
 * event on-site vs. attending remotely.
 *//*w  w  w .ja  va2s .  c om*/
private void setupNavDrawer() {
    // What nav drawer item should be selected?
    int selfItem = getSelfNavDrawerItem();

    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    if (mDrawerLayout == null) {
        return;
    }
    mDrawerLayout.setStatusBarBackgroundColor(getResources().getColor(R.color.theme_primary_dark));
    ScrimInsetsScrollView navDrawer = (ScrimInsetsScrollView) mDrawerLayout.findViewById(R.id.navdrawer);
    if (selfItem == NAVDRAWER_ITEM_INVALID) {
        // do not show a nav drawer
        if (navDrawer != null) {
            ((ViewGroup) navDrawer.getParent()).removeView(navDrawer);
        }
        mDrawerLayout = null;
        return;
    }

    if (navDrawer != null) {
        final View chosenAccountContentView = findViewById(R.id.chosen_account_content_view);
        final View chosenAccountView = findViewById(R.id.chosen_account_view);
        final int navDrawerChosenAccountHeight = getResources()
                .getDimensionPixelSize(R.dimen.navdrawer_chosen_account_height);
        navDrawer.setOnInsetsCallback(new ScrimInsetsScrollView.OnInsetsCallback() {
            @Override
            public void onInsetsChanged(Rect insets) {
                ViewGroup.MarginLayoutParams lp = (ViewGroup.MarginLayoutParams) chosenAccountContentView
                        .getLayoutParams();
                lp.topMargin = insets.top;
                chosenAccountContentView.setLayoutParams(lp);

                ViewGroup.LayoutParams lp2 = chosenAccountView.getLayoutParams();
                lp2.height = navDrawerChosenAccountHeight + insets.top;
                chosenAccountView.setLayoutParams(lp2);
            }
        });
    }

    if (mActionBarToolbar != null) {
        mActionBarToolbar.setNavigationIcon(R.drawable.ic_drawer);
        mActionBarToolbar.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                mDrawerLayout.openDrawer(Gravity.START);
            }
        });
    }

    mDrawerLayout.setDrawerListener(new DrawerLayout.DrawerListener() {
        @Override
        public void onDrawerClosed(View drawerView) {
            // run deferred action, if we have one
            if (mDeferredOnDrawerClosedRunnable != null) {
                mDeferredOnDrawerClosedRunnable.run();
                mDeferredOnDrawerClosedRunnable = null;
            }
            onNavDrawerStateChanged(false, false);
        }

        @Override
        public void onDrawerOpened(View drawerView) {
            onNavDrawerStateChanged(true, false);
        }

        @Override
        public void onDrawerStateChanged(int newState) {
            onNavDrawerStateChanged(isNavDrawerOpen(), newState != DrawerLayout.STATE_IDLE);
        }

        @Override
        public void onDrawerSlide(View drawerView, float slideOffset) {
            onNavDrawerSlide(slideOffset);
        }
    });

    mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, Gravity.START);

    // populate the nav drawer with the correct items
    populateNavDrawer();

}

From source file:com.maskyn.fileeditorpro.activity.MainActivity.java

@Override
public void onBackPressed() {

    try {/*from w w  w. j  a  va 2 s.  c o m*/
        // if we should ignore the back button
        if (PreferenceHelper.getIgnoreBackButton(this))
            return;

        if (mDrawerLayout.isDrawerOpen(Gravity.START) && fileOpened) {
            mDrawerLayout.closeDrawer(Gravity.START);
        } else if (mDrawerLayout.isDrawerOpen(Gravity.END) && fileOpened) {
            mDrawerLayout.closeDrawer(Gravity.END);
        } else if (fileOpened && mEditor.canSaveFile()) {
            new SaveFileDialog(greatUri, pageSystem.getAllText(mEditor.getText().toString()), currentEncoding)
                    .show(getFragmentManager(), "dialog");
        } else if (fileOpened) {

            // remove editor fragment
            hideTextEditor();

            // Set the default title
            getSupportActionBar().setTitle(getString(R.string.nome_app_turbo_editor));

            closedTheFile();

            mDrawerLayout.openDrawer(Gravity.START);
            mDrawerLayout.closeDrawer(Gravity.END);
        } else {
            showInterstitial();
            super.onBackPressed();
        }
    } catch (Exception e) {
        // maybe something is null, who knows
    }
}

From source file:com.aniruddhc.acemusic.player.MainActivity.MainActivity.java

/**
 * Loads the specified fragment into the target layout.
 *//* ww w .  j a v a  2 s.  c  om*/
public void switchContent(Fragment fragment) {
    // Reset action bar
    getActionBar().setDisplayHomeAsUpEnabled(true);
    getActionBar().setDisplayShowHomeEnabled(true);
    getActionBar().setDisplayShowCustomEnabled(false);

    getSupportFragmentManager().beginTransaction().replace(R.id.mainActivityContainer, fragment).commit();

    //Close the drawer(s).
    mDrawerLayout.closeDrawer(Gravity.START);
    invalidateOptionsMenu();

}

From source file:com.cachirulop.moneybox.activity.MainActivity.java

public void selectMoneybox(Moneybox m) {
    _drawerLayout.closeDrawer(Gravity.START);

    refresh(false);
}

From source file:sharedcode.turboeditor.activity.MainActivity.java

@Override
public void onBackPressed() {

    try {//from  w  w  w .  j  a va  2  s. co m
        // if we should ignore the back button
        if (PreferenceHelper.getIgnoreBackButton(this))
            return;

        if (mDrawerLayout.isDrawerOpen(Gravity.START) && fileOpened) {
            mDrawerLayout.closeDrawer(Gravity.START);
        } else if (mDrawerLayout.isDrawerOpen(Gravity.END) && fileOpened) {
            mDrawerLayout.closeDrawer(Gravity.END);
        } else if (fileOpened && mEditor.canSaveFile()) {
            SaveFileDialog.newInstance(sFilePath, pageSystem.getAllText(mEditor.getText().toString()),
                    currentEncoding).show(getFragmentManager(), "dialog");
        } else if (fileOpened) {

            // remove editor fragment
            hideTextEditor();

            // Set the default title
            getSupportActionBar().setTitle(getString(R.string.nome_app_turbo_editor));

            onEvent(new EventBusEvents.ClosedAFile());

            mDrawerLayout.openDrawer(Gravity.START);
            mDrawerLayout.closeDrawer(Gravity.END);
        } else {
            displayInterstitial();
            super.onBackPressed();
        }
    } catch (Exception e) {
        // maybe something is null, who knows
    }
}