Example usage for android.view Gravity LEFT

List of usage examples for android.view Gravity LEFT

Introduction

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

Prototype

int LEFT

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

Click Source Link

Document

Push object to the left of its container, not changing its size.

Usage

From source file:com.facebook.android.friendsmash.ScoreboardFragment.java

private void populateScoreboard() {
    // Ensure all components are firstly removed from scoreboardContainer
    scoreboardContainer.removeAllViews();

    // Ensure the progress spinner is hidden
    progressContainer.setVisibility(View.INVISIBLE);

    // Ensure scoreboardEntriesList is not null and not empty first
    if (application.getScoreboardEntriesList() == null || application.getScoreboardEntriesList().size() <= 0) {
        closeAndShowError(getResources().getString(R.string.error_no_scores));
    } else {/*from ww w.  j  av a  2  s .c o m*/
        // Iterate through scoreboardEntriesList, creating new UI elements for each entry
        int index = 0;
        Iterator<ScoreboardEntry> scoreboardEntriesIterator = application.getScoreboardEntriesList().iterator();
        while (scoreboardEntriesIterator.hasNext()) {
            // Get the current scoreboard entry
            final ScoreboardEntry currentScoreboardEntry = scoreboardEntriesIterator.next();

            // FrameLayout Container for the currentScoreboardEntry ...

            // Create and add a new FrameLayout to display the details of this entry
            FrameLayout frameLayout = new FrameLayout(getActivity());
            scoreboardContainer.addView(frameLayout);

            // Set the attributes for this frameLayout
            int topPadding = getResources().getDimensionPixelSize(R.dimen.scoreboard_entry_top_margin);
            frameLayout.setPadding(0, topPadding, 0, 0);

            // ImageView background image ...
            {
                // Create and add an ImageView for the background image to this entry
                ImageView backgroundImageView = new ImageView(getActivity());
                frameLayout.addView(backgroundImageView);

                // Set the image of the backgroundImageView
                String uri = "drawable/scores_stub_even";
                if (index % 2 != 0) {
                    // Odd entry
                    uri = "drawable/scores_stub_odd";
                }
                int imageResource = getResources().getIdentifier(uri, null, getActivity().getPackageName());
                Drawable image = getResources().getDrawable(imageResource);
                backgroundImageView.setImageDrawable(image);

                // Other attributes of backgroundImageView to modify
                FrameLayout.LayoutParams backgroundImageViewLayoutParams = new FrameLayout.LayoutParams(
                        FrameLayout.LayoutParams.WRAP_CONTENT, FrameLayout.LayoutParams.WRAP_CONTENT);
                int backgroundImageViewMarginTop = getResources()
                        .getDimensionPixelSize(R.dimen.scoreboard_background_imageview_margin_top);
                backgroundImageViewLayoutParams.setMargins(0, backgroundImageViewMarginTop, 0, 0);
                backgroundImageViewLayoutParams.gravity = Gravity.LEFT;
                if (index % 2 != 0) {
                    // Odd entry
                    backgroundImageViewLayoutParams.gravity = Gravity.RIGHT;
                }
                backgroundImageView.setLayoutParams(backgroundImageViewLayoutParams);
            }

            // ProfilePictureView of the current user ...
            {
                // Create and add a ProfilePictureView for the current user entry's profile picture
                ProfilePictureView profilePictureView = new ProfilePictureView(getActivity());
                frameLayout.addView(profilePictureView);

                // Set the attributes of the profilePictureView
                int profilePictureViewWidth = getResources()
                        .getDimensionPixelSize(R.dimen.scoreboard_profile_picture_view_width);
                FrameLayout.LayoutParams profilePictureViewLayoutParams = new FrameLayout.LayoutParams(
                        profilePictureViewWidth, profilePictureViewWidth);
                int profilePictureViewMarginLeft = 0;
                int profilePictureViewMarginTop = getResources()
                        .getDimensionPixelSize(R.dimen.scoreboard_profile_picture_view_margin_top);
                int profilePictureViewMarginRight = 0;
                int profilePictureViewMarginBottom = 0;
                if (index % 2 == 0) {
                    profilePictureViewMarginLeft = getResources()
                            .getDimensionPixelSize(R.dimen.scoreboard_profile_picture_view_margin_left);
                } else {
                    profilePictureViewMarginRight = getResources()
                            .getDimensionPixelSize(R.dimen.scoreboard_profile_picture_view_margin_right);
                }
                profilePictureViewLayoutParams.setMargins(profilePictureViewMarginLeft,
                        profilePictureViewMarginTop, profilePictureViewMarginRight,
                        profilePictureViewMarginBottom);
                profilePictureViewLayoutParams.gravity = Gravity.LEFT;
                if (index % 2 != 0) {
                    // Odd entry
                    profilePictureViewLayoutParams.gravity = Gravity.RIGHT;
                }
                profilePictureView.setLayoutParams(profilePictureViewLayoutParams);

                // Finally set the id of the user to show their profile pic
                profilePictureView.setProfileId(currentScoreboardEntry.getId());
            }

            // LinearLayout to hold the text in this entry

            // Create and add a LinearLayout to hold the TextViews
            LinearLayout textViewsLinearLayout = new LinearLayout(getActivity());
            frameLayout.addView(textViewsLinearLayout);

            // Set the attributes for this textViewsLinearLayout
            FrameLayout.LayoutParams textViewsLinearLayoutLayoutParams = new FrameLayout.LayoutParams(
                    FrameLayout.LayoutParams.WRAP_CONTENT, FrameLayout.LayoutParams.WRAP_CONTENT);
            int textViewsLinearLayoutMarginLeft = 0;
            int textViewsLinearLayoutMarginTop = getResources()
                    .getDimensionPixelSize(R.dimen.scoreboard_textviews_linearlayout_margin_top);
            int textViewsLinearLayoutMarginRight = 0;
            int textViewsLinearLayoutMarginBottom = 0;
            if (index % 2 == 0) {
                textViewsLinearLayoutMarginLeft = getResources()
                        .getDimensionPixelSize(R.dimen.scoreboard_textviews_linearlayout_margin_left);
            } else {
                textViewsLinearLayoutMarginRight = getResources()
                        .getDimensionPixelSize(R.dimen.scoreboard_textviews_linearlayout_margin_right);
            }
            textViewsLinearLayoutLayoutParams.setMargins(textViewsLinearLayoutMarginLeft,
                    textViewsLinearLayoutMarginTop, textViewsLinearLayoutMarginRight,
                    textViewsLinearLayoutMarginBottom);
            textViewsLinearLayoutLayoutParams.gravity = Gravity.LEFT;
            if (index % 2 != 0) {
                // Odd entry
                textViewsLinearLayoutLayoutParams.gravity = Gravity.RIGHT;
            }
            textViewsLinearLayout.setLayoutParams(textViewsLinearLayoutLayoutParams);
            textViewsLinearLayout.setOrientation(LinearLayout.VERTICAL);

            // TextView with the position and name of the current user
            {
                // Set the text that should go in this TextView first
                int position = index + 1;
                String currentScoreboardEntryTitle = position + ". " + currentScoreboardEntry.getName();

                // Create and add a TextView for the current user position and first name
                TextView titleTextView = new TextView(getActivity());
                textViewsLinearLayout.addView(titleTextView);

                // Set the text and other attributes for this TextView
                titleTextView.setText(currentScoreboardEntryTitle);
                titleTextView.setTextAppearance(getActivity(), R.style.ScoreboardPlayerNameFont);
            }

            // TextView with the score of the current user
            {
                // Create and add a TextView for the current user score
                TextView scoreTextView = new TextView(getActivity());
                textViewsLinearLayout.addView(scoreTextView);

                // Set the text and other attributes for this TextView
                scoreTextView.setText("Score: " + currentScoreboardEntry.getScore());
                scoreTextView.setTextAppearance(getActivity(), R.style.ScoreboardPlayerScoreFont);
            }

            // Finally make this frameLayout clickable so that a game starts with the user smashing
            // the user represented by this frameLayout in the scoreContainer
            frameLayout.setOnTouchListener(new OnTouchListener() {

                @Override
                public boolean onTouch(View v, MotionEvent event) {
                    if (event.getAction() == MotionEvent.ACTION_UP) {
                        Bundle bundle = new Bundle();
                        bundle.putString("user_id", currentScoreboardEntry.getId());

                        Intent i = new Intent();
                        i.putExtras(bundle);

                        getActivity().setResult(Activity.RESULT_FIRST_USER, i);
                        getActivity().finish();
                        return false;
                    } else {
                        return true;
                    }
                }

            });

            // Increment the index before looping back
            index++;
        }
    }
}

From source file:com.hippo.widget.slidingdrawerlayout.SlidingDrawerLayout.java

public void setDrawerLockMode(int lockMode, int gravity) {
    if (gravity == Gravity.LEFT)
        setDrawerLockMode(lockMode, mLeftDrawer);
    else if (gravity == Gravity.RIGHT)
        setDrawerLockMode(lockMode, mRightDrawer);
    else/*from w ww  .j a  va  2  s .c o  m*/
        throw new IllegalArgumentException("gravity must be Gravity.LEFT or Gravity.RIGHT");
}

From source file:com.hp.map.CustomerMapActivity.java

public void menuDialog() {
    final Dialog dialog = new Dialog(this);
    LayoutInflater li = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View v = li.inflate(R.layout.menu_dialog, null, false);
    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    dialog.setContentView(v);/* w  w w  . j a va2 s  . co  m*/

    dialog.setTitle("Danh mc chnh");

    Display display = getWindowManager().getDefaultDisplay();

    dialog.getWindow().setLayout(2 * display.getWidth() / 3, LayoutParams.FILL_PARENT);
    dialog.getWindow().getAttributes().gravity = Gravity.LEFT | Gravity.CENTER_VERTICAL;

    lv = (ListView) dialog.findViewById(R.id.menu_list_view);

    lv.setAdapter(
            new DialogArrayAdapter(context, android.R.layout.simple_list_item_1, DetailListData.MENU_LIST));
    lv.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
            // TODO Auto-generated method stub
            DetailsList selectedValue = (DetailsList) lv.getAdapter().getItem(arg2);
            if (selectedValue.activityClass != null) {
                //if sigout
                if (selectedValue.activityClass == LoginActivity.class) {
                    //LoginActivity.threadLooper.quit();
                }
                startActivity(new Intent(context, selectedValue.activityClass));
            }
        }
    });

    dialog.show();

    //      ImageView iv = (ImageView)dialog.findViewById(R.id.menu_list_view);
    //      iv.setImageResource(1);
}

From source file:com.hippo.widget.slidingdrawerlayout.ActionBarDrawerToggle.java

/**
 * Enable or disable the drawer indicator. The indicator defaults to enabled.
 *
 * <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>// w w w  . j av  a  2s .  c o  m
 *
 * @param enable true to enable, false to disable
 */
public void setDrawerIndicatorEnabled(boolean enable) {
    if (enable != mDrawerIndicatorEnabled) {
        if (enable) {
            setActionBarUpIndicator((Drawable) mSlider,
                    mDrawerLayout.isDrawerOpen(Gravity.LEFT) ? mCloseDrawerContentDescRes
                            : mOpenDrawerContentDescRes);
        } else {
            setActionBarUpIndicator(mHomeAsUpIndicator, 0);
        }
        mDrawerIndicatorEnabled = enable;
    }
}

From source file:com.hippo.drawerlayout.DrawerLayout.java

public boolean isDrawerOpen(int gravity) {
    if (gravity == Gravity.LEFT) {
        return isDrawerOpen(mLeftDrawer);
    } else if (gravity == Gravity.RIGHT) {
        return isDrawerOpen(mRightDrawer);
    } else {//  w w w. ja  v a2s. c o  m
        throw new IllegalArgumentException("gravity must be Gravity.LEFT or Gravity.RIGHT");
    }
}

From source file:it.redturtle.mobile.apparpav.MeteogramAdapter.java

/**
 * DOUBLE TEXT ROW//from   w w  w .  ja v  a2  s . c  om
 * @param att
 * @param linear
 * @return
 */
public LinearLayout getDoubleTextRow(Map<String, String> att, LinearLayout linear) {

    LinearLayout container_layout = new LinearLayout(context);
    container_layout.setBackgroundDrawable(context.getResources().getDrawable(R.drawable.view_shape_meteo));
    container_layout.setMinimumHeight(46);
    container_layout.setVerticalGravity(Gravity.CENTER);

    LinearLayout.LayoutParams value_params = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT,
            LayoutParams.WRAP_CONTENT, 0.3f);
    TextView tx = new TextView(context);
    tx.setText(att.get("title"));
    tx.setTextSize(11);
    tx.setTypeface(null, Typeface.BOLD);
    tx.setGravity(Gravity.LEFT);
    tx.setPadding(2, 0, 0, 2);
    tx.setTextColor(Color.rgb(66, 66, 66));
    container_layout.addView(tx, value_params);

    LinearLayout.LayoutParams value_one_params = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT,
            LayoutParams.WRAP_CONTENT, 0.35f);
    TextView t1 = new TextView(context);
    t1.setText(att.get("value1").equals("") ? " - " : att.get("value1"));
    t1.setTextSize(11);
    t1.setGravity(Gravity.CENTER_HORIZONTAL);
    t1.setPadding(2, 0, 0, 2);
    t1.setTextColor(Color.rgb(66, 66, 66));
    container_layout.addView(t1, value_one_params);

    LinearLayout.LayoutParams value_two_params = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT,
            LayoutParams.WRAP_CONTENT, 0.35f);
    TextView t2 = new TextView(context);
    t2.setTextSize(11);
    t2.setText(att.get("value2").equals("") ? " - " : att.get("value2"));
    t2.setGravity(Gravity.CENTER_HORIZONTAL);
    t2.setPadding(2, 0, 0, 2);
    t2.setTextColor(Color.rgb(66, 66, 66));
    container_layout.addView(t2, value_two_params);

    linear.addView(container_layout);

    return linear;
}

From source file:com.aidy.bottomdrawerlayout.AllDrawerLayout.java

/**
 * Set a simple drawable used for the left or right shadow. The drawable
 * provided must have a nonzero intrinsic width.
 * /*from w  w  w . j av a2s.c  om*/
 * @param shadowDrawable
 *            Shadow drawable to use at the edge of a drawer
 * @param gravity
 *            Which drawer the shadow should apply to
 */
public void setDrawerShadow(Drawable shadowDrawable, int gravity) {
    /*
     * TODO Someone someday might want to set more complex drawables here.
     * They're probably nuts, but we might want to consider registering
     * callbacks, setting states, etc. properly.
     */

    final int absGravity = GravityCompat.getAbsoluteGravity(gravity, ViewCompat.getLayoutDirection(this));
    if ((absGravity & Gravity.LEFT) == Gravity.LEFT) {
        mShadowLeft = shadowDrawable;
        invalidate();
    }
    if ((absGravity & Gravity.RIGHT) == Gravity.RIGHT) {
        mShadowRight = shadowDrawable;
        invalidate();
    }
    if ((absGravity & Gravity.TOP) == Gravity.TOP) {
        mShadowTop = shadowDrawable;
        invalidate();
    }
    if ((absGravity & Gravity.BOTTOM) == Gravity.BOTTOM) {
        mShadowBottom = shadowDrawable;
        invalidate();
    }
}

From source file:com.hippo.drawerlayout.DrawerLayout.java

public void setDrawerShadow(Drawable shadowDrawable, int gravity) {
    switch (gravity) {
    case Gravity.LEFT:
        mShadow.setShadowLeft(shadowDrawable);
        break;//from   www  .j  a va2 s . c  o m
    case Gravity.RIGHT:
        mShadow.setShadowRight(shadowDrawable);
        break;
    default:
        throw new IllegalStateException("setDrawerShadow only support Gravity.LEFT and Gravity.RIGHT");
    }
    invalidate();
}

From source file:com.abewy.android.apps.klyph.widget.KlyphDrawerLayout.java

/**
 * Enable or disable interaction with all drawers.
 *
 * <p>This allows the application to restrict the user's ability to open or close
 * any drawer within this layout. DrawerLayout will still respond to calls to
 * {@link #openDrawer(int)}, {@link #closeDrawer(int)} and friends if a drawer is locked.</p>
 *
 * <p>Locking drawers open or closed will implicitly open or close
 * any drawers as appropriate.</p>
 *
 * @param lockMode The new lock mode for the given drawer. One of {@link #LOCK_MODE_UNLOCKED},
 *                 {@link #LOCK_MODE_LOCKED_CLOSED} or {@link #LOCK_MODE_LOCKED_OPEN}.
 *//*from  w w w .  j  a v  a 2 s  .  co m*/
public void setDrawerLockMode(int lockMode) {
    setDrawerLockMode(lockMode, Gravity.LEFT);
    setDrawerLockMode(lockMode, Gravity.RIGHT);
}

From source file:com.itude.mobile.mobbl.core.view.components.tabbar.MBDefaultActionBarBuilder.java

private void populateActionBar(final ActionBar actionBar) {
    MBViewManager.getInstance().runOnUiThread(new Runnable() {
        @Override/*from  ww  w. j  a  v a2 s  . c o m*/
        public void run() {
            MBTabBar tabBar = new MBTabBar(_context);

            for (String dialogName : MBViewManager.getInstance().getDialogManager().getSortedDialogNames()) {
                MBDialogDefinition dialogDefinition = MBMetadataService.getInstance()
                        .getDefinitionForDialogName(dialogName);

                if (dialogDefinition.isPreConditionValid() && dialogDefinition.isShowAsTab()) {
                    if (dialogDefinition.getDomain() != null) {
                        MBDomainDefinition domainDef = MBMetadataService.getInstance()
                                .getDefinitionForDomainName(dialogDefinition.getDomain());

                        final MBTabSpinnerAdapter tabSpinnerAdapter = new MBTabSpinnerAdapter(_context,
                                android.R.layout.simple_spinner_dropdown_item);

                        for (MBDomainValidatorDefinition domDef : domainDef.getDomainValidators()) {
                            tabSpinnerAdapter.add(domDef.getTitle());
                        }

                        Drawable drawable = MBResourceService.getInstance().getImageByID("tab-spinner-leaf");

                        MBTab tab = new MBTab(_context);
                        tab.setAdapter(tabSpinnerAdapter);
                        tab.setSelectedBackground(drawable);
                        if (dialogDefinition.getIcon() != null) {
                            tab.setIcon(
                                    MBResourceService.getInstance().getImageByID(dialogDefinition.getIcon()));
                        }
                        setTabText(dialogDefinition, tab, tabBar);

                        tab.setName(dialogName);
                        tab.setListener(new MBTabListener(dialogName));

                        tabBar.addTab(tab);

                        if (ComparisonUtil.safeEquals(dialogName,
                                MBViewManager.getInstance().getActiveDialogName()))
                            tabBar.selectTab(tab, true);
                    } else {
                        MBTab tab = new MBTab(_context);
                        setTabText(dialogDefinition, tab, tabBar);

                        tab.setListener(new MBTabListener(dialogName));
                        tab.setName(dialogName);

                        if (dialogDefinition.getIcon() != null) {
                            tab.setIcon(
                                    MBResourceService.getInstance().getImageByID(dialogDefinition.getIcon()));
                        }
                        tabBar.addTab(tab);

                        if (ComparisonUtil.safeEquals(dialogName,
                                MBViewManager.getInstance().getActiveDialogName()))
                            tabBar.selectTab(tab, true);
                    }
                }
            }

            MBStyleHandler styleHandler = MBViewBuilderFactory.getInstance().getStyleHandler();

            //fix the Home icon padding
            View homeIcon = null;
            if (DeviceUtil.getInstance().hasNativeActionBarSupport()) {
                homeIcon = MBViewManager.getInstance().findViewById(R.id.home);
            } else {
                homeIcon = MBViewManager.getInstance().findViewById(android.support.v7.appcompat.R.id.home);
            }

            if (homeIcon != null) {
                styleHandler.styleHomeIcon(homeIcon);
                actionBar.setHomeButtonEnabled(true);
            }

            styleHandler.styleActionBar(actionBar);

            int actionBarDisplayOptions = ActionBar.DISPLAY_SHOW_CUSTOM | ActionBar.DISPLAY_SHOW_HOME
                    | ActionBar.DISPLAY_USE_LOGO;
            actionBar.setDisplayOptions(actionBarDisplayOptions);

            final View customView;
            if (!tabBar.isEmpty()) {
                customView = tabBar;
            } else {
                //          LinearLayout linearLayout = new LinearLayout(MBNextGenViewManager.this);
                //          linearLayout.setGravity(Gravity.CENTER_VERTICAL);
                //
                //          TextView textView = new TextView(MBNextGenViewManager.this);
                //          textView.setText(getTitle());
                //          linearLayout.addView(textView);

                MBHeader header = new MBHeader(_context);
                header.setTitleText((String) MBViewManager.getInstance().getTitle());

                styleHandler.styleActionBarHeader(header);
                styleHandler.styleActionBarHeaderTitle(header.getTitleView());

                customView = header;
            }

            actionBar.setCustomView(customView, new ActionBar.LayoutParams(ActionBar.LayoutParams.MATCH_PARENT,
                    ActionBar.LayoutParams.MATCH_PARENT, Gravity.LEFT));
        }

        private void setTabText(MBDialogDefinition dialogDefinition, MBTab tab, MBTabBar tabBar) {
            String title;

            if (_context.getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) {
                title = dialogDefinition.getTitlePortrait();
            } else {
                title = dialogDefinition.getTitle();
            }

            if (StringUtil.isNotBlank(title)) {
                tab.setText(title);
                tabBar.setTabPadding(0, 0, ScreenConstants.SIXTEEN, 0);
            } else {
                tabBar.setTabPadding(0, 0, 0, 0);
            }
        }
    });
}