Example usage for android.view Gravity FILL_HORIZONTAL

List of usage examples for android.view Gravity FILL_HORIZONTAL

Introduction

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

Prototype

int FILL_HORIZONTAL

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

Click Source Link

Document

Grow the horizontal size of the object if needed so it completely fills its container.

Usage

From source file:id.co.datascrip.dtswarehousesystem.custom.StepPagerStrip.java

private int hitTest(float x) {
    if (mPageCount == 0) {
        return -1;
    }/*ww w  .  j  av a  2s. co m*/

    float totalWidth = mPageCount * (mTabWidth + mTabSpacing) - mTabSpacing;
    float totalLeft;
    boolean fillHorizontal = false;

    switch (mGravity & Gravity.HORIZONTAL_GRAVITY_MASK) {
    case Gravity.CENTER_HORIZONTAL:
        totalLeft = (getWidth() - totalWidth) / 2;
        break;
    case Gravity.RIGHT:
        totalLeft = getWidth() - getPaddingRight() - totalWidth;
        break;
    case Gravity.FILL_HORIZONTAL:
        totalLeft = getPaddingLeft();
        fillHorizontal = true;
        break;
    default:
        totalLeft = getPaddingLeft();
    }

    float tabWidth = mTabWidth;
    if (fillHorizontal) {
        tabWidth = (getWidth() - getPaddingRight() - getPaddingLeft() - (mPageCount - 1) * mTabSpacing)
                / mPageCount;
    }

    float totalRight = totalLeft + (mPageCount * (tabWidth + mTabSpacing));
    if (x >= totalLeft && x <= totalRight && totalRight > totalLeft) {
        return (int) (((x - totalLeft) / (totalRight - totalLeft)) * mPageCount);
    } else {
        return -1;
    }
}

From source file:org.catrobat.catroid.ui.dialogs.AddBrickDialog.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.dialog_brick_add, null);

    ImageButton closeButton = (ImageButton) rootView.findViewById(R.id.dialog_brick_title_button_close);
    TextView textView = (TextView) rootView.findViewById(R.id.dialog_brick_title_text_view_title);
    listView = (ListView) rootView.findViewById(R.id.dialog_brick_add_list_view);

    closeButton.setOnClickListener(new View.OnClickListener() {
        @Override//from   w w  w.  j  av a 2s  .co m
        public void onClick(View v) {
            dismiss();
        }
    });

    textView.setText(selectedCategory);

    Window window = getDialog().getWindow();
    window.requestFeature(Window.FEATURE_NO_TITLE);
    window.setGravity(Gravity.CENTER | Gravity.FILL_HORIZONTAL | Gravity.FILL_VERTICAL);
    window.setLayout(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
    window.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);

    return rootView;
}

From source file:io.plaidapp.ui.DribbbleLogin.java

private void showLoggedInUser() {
    Gson gson = new GsonBuilder().setDateFormat(DribbbleService.DATE_FORMAT).create();

    RestAdapter restAdapter = new RestAdapter.Builder().setEndpoint(DribbbleService.ENDPOINT)
            .setConverter(new GsonConverter(gson))
            .setRequestInterceptor(new AuthInterceptor(dribbblePrefs.getAccessToken())).build();

    DribbbleService dribbbleApi = restAdapter.create((DribbbleService.class));
    dribbbleApi.getAuthenticatedUser(new Callback<User>() {
        @Override// w w  w. j  a va 2 s  .c  o m
        public void success(User user, Response response) {
            dribbblePrefs.setLoggedInUser(user);
            Toast confirmLogin = new Toast(getApplicationContext());
            View v = LayoutInflater.from(DribbbleLogin.this).inflate(R.layout.toast_logged_in_confirmation,
                    null, false);
            ((TextView) v.findViewById(R.id.name)).setText(user.name);
            // need to use app context here as the activity will be destroyed shortly
            Glide.with(getApplicationContext()).load(user.avatar_url).placeholder(R.drawable.ic_player)
                    .transform(new CircleTransform(getApplicationContext()))
                    .into((ImageView) v.findViewById(R.id.avatar));
            v.findViewById(R.id.scrim).setBackground(ScrimUtil.makeCubicGradientScrimDrawable(
                    ContextCompat.getColor(DribbbleLogin.this, R.color.scrim), 5, Gravity.BOTTOM));
            confirmLogin.setView(v);
            confirmLogin.setGravity(Gravity.BOTTOM | Gravity.FILL_HORIZONTAL, 0, 0);
            confirmLogin.setDuration(Toast.LENGTH_LONG);
            confirmLogin.show();
        }

        @Override
        public void failure(RetrofitError error) {
        }
    });
}

From source file:io.plaidapp.ui.DesignerNewsLogin.java

@SuppressLint("InflateParams")
void showLoggedInUser() {
    final Call<User> authedUser = designerNewsPrefs.getApi().getAuthedUser();
    authedUser.enqueue(new Callback<User>() {
        @Override//from   w  w  w.j a  va2s .  c  o m
        public void onResponse(Call<User> call, Response<User> response) {
            if (!response.isSuccessful())
                return;
            final User user = response.body();
            designerNewsPrefs.setLoggedInUser(user);
            final Toast confirmLogin = new Toast(getApplicationContext());
            final View v = LayoutInflater.from(DesignerNewsLogin.this)
                    .inflate(R.layout.toast_logged_in_confirmation, null, false);
            ((TextView) v.findViewById(R.id.name)).setText(user.display_name.toLowerCase());
            // need to use app context here as the activity will be destroyed shortly
            Glide.with(getApplicationContext()).load(user.portrait_url)
                    .placeholder(R.drawable.avatar_placeholder)
                    .transform(new CircleTransform(getApplicationContext()))
                    .into((ImageView) v.findViewById(R.id.avatar));
            v.findViewById(R.id.scrim).setBackground(ScrimUtil.makeCubicGradientScrimDrawable(
                    ContextCompat.getColor(DesignerNewsLogin.this, R.color.scrim), 5, Gravity.BOTTOM));
            confirmLogin.setView(v);
            confirmLogin.setGravity(Gravity.BOTTOM | Gravity.FILL_HORIZONTAL, 0, 0);
            confirmLogin.setDuration(Toast.LENGTH_LONG);
            confirmLogin.show();
        }

        @Override
        public void onFailure(Call<User> call, Throwable t) {
            Log.e(getClass().getCanonicalName(), t.getMessage(), t);
        }
    });
}

From source file:nz.ac.otago.psyanlab.common.designer.program.stage.EditPropPropertiesFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    Bundle args = getArguments();/*from  w w w .  ja  va 2 s.  co m*/
    if (args.containsKey(ARG_PROP)) {
        mProp = args.getParcelable(ARG_PROP);
    } else {
        mProp = mCallbacks.getProp(args.getInt(ARG_PROP_ID)).getProp();
    }

    mFieldMap = new HashMap<String, Field>();
    mViewMap = new HashMap<String, View>();

    // Run through the fields of the prop and build groups and mappings for
    // the fields and views to allow the user to change the property values.
    Field[] fields = mProp.getClass().getFields();
    for (int i = 0; i < fields.length; i++) {
        Field field = fields[i];
        PALEPropProperty annotation = field.getAnnotation(PALEPropProperty.class);
        if (annotation != null) {
            String fieldName = annotation.value();
            View view;
            if (field.getType().isAssignableFrom(Integer.TYPE)) {
                try {
                    view = newIntegerInputView(annotation.isSigned(), field.getInt(mProp));
                } catch (IllegalArgumentException e) {
                    throw new RuntimeException("Should never get here.", e);
                } catch (IllegalAccessException e) {
                    throw new RuntimeException("Should never get here.", e);
                }
            } else if (field.getType().isAssignableFrom(Float.TYPE)) {
                try {
                    view = newFloatInputView(annotation.isSigned(), field.getFloat(mProp));
                } catch (IllegalArgumentException e) {
                    throw new RuntimeException("Should never get here.", e);
                } catch (IllegalAccessException e) {
                    throw new RuntimeException("Should never get here.", e);
                }
            } else if (field.getType().isAssignableFrom(String.class)) {
                try {
                    view = newStringInputView((String) field.get(mProp));
                } catch (IllegalArgumentException e) {
                    throw new RuntimeException("Should never get here.", e);
                } catch (IllegalAccessException e) {
                    throw new RuntimeException("Should never get here.", e);
                }
            } else {
                continue;
            }
            mFieldMap.put(fieldName, field);
            mViewMap.put(fieldName, view);

            if (mGroupings.containsKey(annotation.group())) {
                mGroupings.get(annotation.group()).add(fieldName);
            } else {
                ArrayList<String> list = new ArrayList<String>();
                list.add(fieldName);
                mGroupings.put(annotation.group(), list);
            }
        }
    }

    // Initialise grid layout.
    GridLayout grid = new GridLayout(getActivity());
    grid.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.WRAP_CONTENT));
    grid.setAlignmentMode(GridLayout.ALIGN_BOUNDS);
    grid.setColumnCount(2);
    grid.setUseDefaultMargins(true);

    // Run through groupings of properties adding the created views to the
    // GridLayout in sections.
    for (String group : mGroupings.keySet()) {
        if (!TextUtils.isEmpty(group) && !TextUtils.equals(group, "")) {
            TextView sectionBreak = (TextView) inflater.inflate(R.layout.prop_property_section_break, grid,
                    false);
            sectionBreak.setText(group);
            GridLayout.LayoutParams sectionBreakParams = new GridLayout.LayoutParams();
            sectionBreakParams.columnSpec = GridLayout.spec(0, 2);
            sectionBreak.setLayoutParams(sectionBreakParams);
            grid.addView(sectionBreak);
        }

        for (String name : mGroupings.get(group)) {
            TextView propertyLabel = (TextView) inflater.inflate(R.layout.prop_property_label, grid, false);
            GridLayout.LayoutParams params = new GridLayout.LayoutParams();
            propertyLabel.setLayoutParams(params);
            propertyLabel.setText(getResources().getString(R.string.format_property_label, name));

            View propertyView = mViewMap.get(name);
            params = new GridLayout.LayoutParams();
            params.setGravity(Gravity.FILL_HORIZONTAL);
            propertyView.setLayoutParams(params);

            grid.addView(propertyLabel);
            grid.addView(propertyView);
        }
    }

    return grid;
}

From source file:au.org.ala.fielddata.mobile.CollectSurveyData.java

private void buildCustomActionBar() {
    getSupportActionBar().setDisplayShowTitleEnabled(false);
    getSupportActionBar().setDisplayShowHomeEnabled(false);

    View customNav = LayoutInflater.from(this).inflate(R.layout.cancel_done, null);

    customNav.findViewById(R.id.action_done).setOnClickListener(customActionBarListener);
    customNav.findViewById(R.id.action_cancel).setOnClickListener(customActionBarListener);

    LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT,
            Gravity.FILL_HORIZONTAL);
    getSupportActionBar().setCustomView(customNav, params);
    getSupportActionBar().setDisplayShowCustomEnabled(true);
}

From source file:io.plaidapp.ui.DesignerNewsLogin.java

private void showLoggedInUser() {
    DesignerNewsService designerNewsService = new RestAdapter.Builder()
            .setEndpoint(DesignerNewsService.ENDPOINT)
            .setRequestInterceptor(new ClientAuthInterceptor(designerNewsPrefs.getAccessToken(),
                    BuildConfig.DESIGNER_NEWS_CLIENT_ID))
            .build().create(DesignerNewsService.class);
    designerNewsService.getAuthedUser(new Callback<UserResponse>() {
        @Override//from   ww  w. jav  a 2  s  .  c o m
        public void success(UserResponse userResponse, Response response) {
            final User user = userResponse.user;
            designerNewsPrefs.setLoggedInUser(user);
            Toast confirmLogin = new Toast(getApplicationContext());
            View v = LayoutInflater.from(DesignerNewsLogin.this).inflate(R.layout.toast_logged_in_confirmation,
                    null, false);
            ((TextView) v.findViewById(R.id.name)).setText(user.display_name);
            // need to use app context here as the activity will be destroyed shortly
            Glide.with(getApplicationContext()).load(user.portrait_url)
                    .placeholder(R.drawable.avatar_placeholder)
                    .transform(new CircleTransform(getApplicationContext()))
                    .into((ImageView) v.findViewById(R.id.avatar));
            v.findViewById(R.id.scrim).setBackground(ScrimUtil.makeCubicGradientScrimDrawable(
                    ContextCompat.getColor(DesignerNewsLogin.this, R.color.scrim), 5, Gravity.BOTTOM));
            confirmLogin.setView(v);
            confirmLogin.setGravity(Gravity.BOTTOM | Gravity.FILL_HORIZONTAL, 0, 0);
            confirmLogin.setDuration(Toast.LENGTH_LONG);
            confirmLogin.show();
        }

        @Override
        public void failure(RetrofitError error) {
            Log.e(getClass().getCanonicalName(), error.getMessage(), error);
        }
    });
}

From source file:android.support.v7.app.AppCompatDelegateImplV7.java

@Override
ActionMode startSupportActionModeFromWindow(ActionMode.Callback callback) {
    if (mActionMode != null) {
        mActionMode.finish();//  w  ww.j  a va2 s  .co  m
    }

    final ActionMode.Callback wrappedCallback = new ActionModeCallbackWrapper(callback);
    final Context context = getActionBarThemedContext();

    if (mActionModeView == null) {
        if (mIsFloating) {
            mActionModeView = new ActionBarContextView(context);
            mActionModePopup = new PopupWindow(context, null, R.attr.actionModePopupWindowStyle);
            mActionModePopup.setContentView(mActionModeView);
            mActionModePopup.setWidth(ViewGroup.LayoutParams.MATCH_PARENT);

            TypedValue heightValue = new TypedValue();
            mContext.getTheme().resolveAttribute(R.attr.actionBarSize, heightValue, true);
            final int height = TypedValue.complexToDimensionPixelSize(heightValue.data,
                    mContext.getResources().getDisplayMetrics());
            mActionModeView.setContentHeight(height);
            mActionModePopup.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT);
            mShowActionModePopup = new Runnable() {
                public void run() {
                    mActionModePopup.showAtLocation(mActionModeView, Gravity.TOP | Gravity.FILL_HORIZONTAL, 0,
                            0);
                }
            };
        } else {
            ViewStubCompat stub = (ViewStubCompat) mSubDecor.findViewById(R.id.action_mode_bar_stub);
            if (stub != null) {
                // Set the layout inflater so that it is inflated with the action bar's context
                stub.setLayoutInflater(LayoutInflater.from(context));
                mActionModeView = (ActionBarContextView) stub.inflate();
            }
        }
    }

    if (mActionModeView != null) {
        mActionModeView.killMode();
        ActionMode mode = new StandaloneActionMode(context, mActionModeView, wrappedCallback,
                mActionModePopup == null);
        if (callback.onCreateActionMode(mode, mode.getMenu())) {
            mode.invalidate();
            mActionModeView.initForMode(mode);
            mActionModeView.setVisibility(View.VISIBLE);
            mActionMode = mode;
            if (mActionModePopup != null) {
                mWindow.getDecorView().post(mShowActionModePopup);
            }
            mActionModeView.sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);

            if (mActionModeView.getParent() != null) {
                ViewCompat.requestApplyInsets((View) mActionModeView.getParent());
            }
        } else {
            mActionMode = null;
        }
    }
    if (mActionMode != null && mAppCompatCallback != null) {
        mAppCompatCallback.onSupportActionModeStarted(mActionMode);
    }
    return mActionMode;
}

From source file:android.support.v7ox.app.AppCompatDelegateImplV7.java

@Override
ActionMode startSupportActionModeFromWindow(ActionMode.Callback callback) {
    endOnGoingFadeAnimation();//  ww  w  . j  a v a  2s.c  om
    if (mActionMode != null) {
        mActionMode.finish();
    }

    final ActionMode.Callback wrappedCallback = new ActionModeCallbackWrapperV7(callback);
    ActionMode mode = null;
    if (mAppCompatCallback != null && !isDestroyed()) {
        try {
            mode = mAppCompatCallback.onWindowStartingSupportActionMode(wrappedCallback);
        } catch (AbstractMethodError ame) {
            // Older apps might not implement this callback method.
        }
    }

    if (mode != null) {
        mActionMode = mode;
    } else {
        if (mActionModeView == null) {
            if (mIsFloating) {
                // Use the action bar theme.
                final TypedValue outValue = new TypedValue();
                final Resources.Theme baseTheme = mContext.getTheme();
                baseTheme.resolveAttribute(R.attr.actionBarTheme_ox, outValue, true);

                final Context actionBarContext;
                if (outValue.resourceId != 0) {
                    final Resources.Theme actionBarTheme = mContext.getResources().newTheme();
                    actionBarTheme.setTo(baseTheme);
                    actionBarTheme.applyStyle(outValue.resourceId, true);

                    actionBarContext = new ContextThemeWrapper(mContext, 0);
                    actionBarContext.getTheme().setTo(actionBarTheme);
                } else {
                    actionBarContext = mContext;
                }

                mActionModeView = new ActionBarContextView(actionBarContext);
                mActionModePopup = new PopupWindow(actionBarContext, null,
                        R.attr.actionModePopupWindowStyle_ox);
                PopupWindowCompat.setWindowLayoutType(mActionModePopup,
                        WindowManager.LayoutParams.TYPE_APPLICATION);
                mActionModePopup.setContentView(mActionModeView);
                mActionModePopup.setWidth(ViewGroup.LayoutParams.MATCH_PARENT);

                actionBarContext.getTheme().resolveAttribute(R.attr.actionBarSize_ox, outValue, true);
                final int height = TypedValue.complexToDimensionPixelSize(outValue.data,
                        actionBarContext.getResources().getDisplayMetrics());
                mActionModeView.setContentHeight(height);
                mActionModePopup.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT);
                mShowActionModePopup = new Runnable() {
                    public void run() {
                        mActionModePopup.showAtLocation(mActionModeView, Gravity.TOP | Gravity.FILL_HORIZONTAL,
                                0, 0);
                        endOnGoingFadeAnimation();
                        ViewCompat.setAlpha(mActionModeView, 0f);
                        mFadeAnim = ViewCompat.animate(mActionModeView).alpha(1f);
                        mFadeAnim.setListener(new ViewPropertyAnimatorListenerAdapter() {
                            @Override
                            public void onAnimationEnd(View view) {
                                ViewCompat.setAlpha(mActionModeView, 1f);
                                mFadeAnim.setListener(null);
                                mFadeAnim = null;
                            }

                            @Override
                            public void onAnimationStart(View view) {
                                mActionModeView.setVisibility(View.VISIBLE);
                            }
                        });
                    }
                };
            } else {
                ViewStubCompat stub = (ViewStubCompat) mSubDecor.findViewById(R.id.action_mode_bar_stub);
                if (stub != null) {
                    // Set the layout inflater so that it is inflated with the action bar's context
                    stub.setLayoutInflater(LayoutInflater.from(getActionBarThemedContext()));
                    mActionModeView = (ActionBarContextView) stub.inflate();
                }
            }
        }

        if (mActionModeView != null) {
            endOnGoingFadeAnimation();
            mActionModeView.killMode();
            mode = new StandaloneActionMode(mActionModeView.getContext(), mActionModeView, wrappedCallback,
                    mActionModePopup == null);
            if (callback.onCreateActionMode(mode, mode.getMenu())) {
                mode.invalidate();
                mActionModeView.initForMode(mode);
                mActionMode = mode;
                ViewCompat.setAlpha(mActionModeView, 0f);
                mFadeAnim = ViewCompat.animate(mActionModeView).alpha(1f);
                mFadeAnim.setListener(new ViewPropertyAnimatorListenerAdapter() {
                    @Override
                    public void onAnimationEnd(View view) {
                        ViewCompat.setAlpha(mActionModeView, 1f);
                        mFadeAnim.setListener(null);
                        mFadeAnim = null;
                    }

                    @Override
                    public void onAnimationStart(View view) {
                        mActionModeView.setVisibility(View.VISIBLE);
                        mActionModeView.sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
                        if (mActionModeView.getParent() != null) {
                            ViewCompat.requestApplyInsets((View) mActionModeView.getParent());
                        }
                    }
                });
                if (mActionModePopup != null) {
                    mWindow.getDecorView().post(mShowActionModePopup);
                }
            } else {
                mActionMode = null;
            }
        }
    }
    if (mActionMode != null && mAppCompatCallback != null) {
        mAppCompatCallback.onSupportActionModeStarted(mActionMode);
    }
    return mActionMode;
}