Example usage for android.view Gravity BOTTOM

List of usage examples for android.view Gravity BOTTOM

Introduction

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

Prototype

int BOTTOM

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

Click Source Link

Document

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

Usage

From source file:info.hl.mediam.MyProfileActivity.java

@Override
protected Dialog onCreateDialog(int id) {
    switch (id) {
    case GET_IMAGE_DIALOG:
        mGetImageDialog = new Dialog(MyProfileActivity.this, R.style.TransparentDialogTheme);
        mGetImageDialog.getWindow().setGravity(Gravity.BOTTOM);
        mGetImageDialog.setContentView(R.layout.dialog_get_image);
        WindowManager.LayoutParams params = new WindowManager.LayoutParams();
        Window window = mGetImageDialog.getWindow();
        params.copyFrom(window.getAttributes());
        params.width = WindowManager.LayoutParams.MATCH_PARENT;
        params.height = WindowManager.LayoutParams.WRAP_CONTENT;
        window.setAttributes(params);// w  w w  .j ava 2  s .c  om

        final Button btnGallery = (Button) mGetImageDialog.findViewById(R.id.btnGallery);
        btnGallery.setTypeface(MediamApp.getTfMyriadProBold(), Typeface.BOLD);
        btnGallery.setOnClickListener(new OnClickListener() {

            public void onClick(View v) {

                Intent galleryIntent = new Intent(MyProfileActivity.this, CameraCropActivity.class);
                galleryIntent.putExtra("type", "gallery");
                galleryIntent.putExtra("profile", true);
                MyProfileActivity.this.startActivityForResult(galleryIntent, UPDATE_IMAGE_REQUEST_CODE);
                mGetImageDialog.dismiss();

            }
        });

        final Button btnCamera = (Button) mGetImageDialog.findViewById(R.id.btnCamera);
        btnCamera.setTypeface(MediamApp.getTfMyriadProBold(), Typeface.BOLD);
        btnCamera.setOnClickListener(new OnClickListener() {

            public void onClick(View v) {

                Intent cameraIntent = new Intent(MyProfileActivity.this, CameraCropActivity.class);
                cameraIntent.putExtra("type", "camera");
                cameraIntent.putExtra("profile", true);
                MyProfileActivity.this.startActivityForResult(cameraIntent, UPDATE_IMAGE_REQUEST_CODE);
                mGetImageDialog.dismiss();

            }
        });

        final Button btnRemovePhoto = (Button) mGetImageDialog.findViewById(R.id.btnRemovePhoto);
        btnRemovePhoto.setTypeface(MediamApp.getTfMyriadProBold(), Typeface.BOLD);
        btnRemovePhoto.setOnClickListener(new OnClickListener() {

            public void onClick(View v) {

                mNewAvatarId = "";
                gProfileImage = null;
                Utils.displayImage(mNewAvatarId, mIvProfileImage, mPbLoading, ImageLoader.LARGE,
                        R.drawable.user_stub_large, false);
                mGetImageDialog.dismiss();

            }
        });

        return mGetImageDialog;
    case GET_BIRTHDAY_DIALOG:

        int intMaxYear = Calendar.getInstance().get(Calendar.YEAR);
        int intMaxMonth = Calendar.getInstance().get(Calendar.MONTH);
        int intMaxDay = Calendar.getInstance().get(Calendar.DAY_OF_MONTH);

        mGetBirthdayDialog = new DatePickerDialogWithRange(this, new DatePickerDialog.OnDateSetListener() {
            public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
                Time chosenDate = new Time();
                chosenDate.set(dayOfMonth, monthOfYear, year);
                mNewBirthday = chosenDate.toMillis(true) / 1000;
                CharSequence stringDate = DateFormat.format(getString(R.string.hookup_date_format),
                        chosenDate.toMillis(true));
                mEtUserBirthday.setText(stringDate.toString());
            }
        }, intMaxYear, intMaxMonth, intMaxDay);
        mGetBirthdayDialog.setMessage(getString(R.string.when_is_your_birthday));
        return mGetBirthdayDialog;
    default:
        return null;
    }
}

From source file:com.mobicage.rogerthat.plugins.friends.ServiceActionMenuActivity.java

private void populateScreen(final ServiceMenu menu) {
    menuBrandingHash = menu.branding;//from   w w w .j a v  a 2s . c  o m
    final FriendsPlugin friendsPlugin = mService.getPlugin(FriendsPlugin.class);
    final MessagingPlugin messagingPlugin = mService.getPlugin(MessagingPlugin.class);
    final FriendStore store = friendsPlugin.getStore();

    List<Cell> usedCells = new ArrayList<Cell>();
    if (page == 0) {
        addAboutHandler(usedCells, menu.aboutLabel);
        addHistoryHandler(usedCells, store, menu.messagesLabel);
        addCallHandler(menu, usedCells, menu.callLabel);
        if (CloudConstants.isYSAAA()) {
            addScanHandler(menu, usedCells, null);
        } else {
            addShareHandler(menu, usedCells, menu.shareLabel);
        }
    }
    boolean[] rows = new boolean[] { false, false, false };
    if (page == 0)
        rows[0] = true;
    for (final ServiceMenuItem item : menu.itemList) {
        rows[(int) item.coords[1]] = true;
        final Cell cell = cells[(int) item.coords[0]][(int) item.coords[1]];
        View.OnClickListener onClickListener = new SafeViewOnClickListener() {
            @Override
            public void safeOnClick(View v) {
                pressMenuItem(menu, messagingPlugin, store, item);
            }
        };
        ((View) cell.icon.getParent()).setOnClickListener(onClickListener);
        cell.icon.setImageBitmap(BitmapFactory.decodeByteArray(item.icon, 0, item.icon.length));
        cell.icon.setVisibility(View.VISIBLE);
        cell.label.setText(item.label);
        cell.label.setVisibility(View.VISIBLE);
        usedCells.add(cell);
    }
    for (int i = 2; i >= 0; i--) {
        if (rows[i])
            break;
        tableRows[i].setVisibility(View.GONE);
    }
    boolean showBranded = false;
    boolean useDarkScheme = false;
    Integer menuItemColor = null;
    if (menu.branding != null) {
        try {
            BrandingMgr brandingMgr = messagingPlugin.getBrandingMgr();
            Friend friend = store.getExistingFriend(email);
            if (brandingMgr.isBrandingAvailable(menu.branding)) {
                BrandingResult br = brandingMgr.prepareBranding(menu.branding, friend, false);
                WebSettings settings = branding.getSettings();
                settings.setJavaScriptEnabled(false);
                settings.setBlockNetworkImage(false);
                branding.setVisibility(View.VISIBLE);
                branding.setVerticalScrollBarEnabled(false);

                final int displayWidth = UIUtils.getDisplayWidth(this);
                final int calculatedHeight = BrandingMgr.calculateHeight(br, displayWidth);
                final long start = System.currentTimeMillis();
                branding.getViewTreeObserver().addOnPreDrawListener(new OnPreDrawListener() {
                    @Override
                    public boolean onPreDraw() {
                        int height = branding.getMeasuredHeight();
                        if (height > calculatedHeight * 90 / 100 || System.currentTimeMillis() - start > 3000) {
                            if (calculatedHeight > 0) {
                                setBrandingHeight(height);
                            } else {
                                mService.postDelayedOnUIHandler(new SafeRunnable() {
                                    @Override
                                    protected void safeRun() throws Exception {
                                        setBrandingHeight(branding.getMeasuredHeight());
                                    }
                                }, 100);
                            }
                            branding.getViewTreeObserver().removeOnPreDrawListener(this);
                        }
                        return false;
                    }
                });
                branding.loadUrl("file://" + br.file.getAbsolutePath());

                if (br.color != null) {
                    branding.setBackgroundColor(br.color);
                    activity.setBackgroundColor(br.color);
                }
                if (br.scheme == ColorScheme.dark) {
                    for (Cell cell : usedCells) {
                        cell.label.setTextColor(darkSchemeTextColor);
                        cell.label.setShadowLayer(2, 1, 1, Color.BLACK);
                    }
                    useDarkScheme = true;
                }
                menuItemColor = br.menuItemColor;

                final ImageView watermarkView = (ImageView) findViewById(R.id.watermark);
                if (br.watermark != null) {
                    BitmapDrawable watermark = new BitmapDrawable(getResources(),
                            BitmapFactory.decodeFile(br.watermark.getAbsolutePath()));
                    watermark.setGravity(Gravity.BOTTOM | Gravity.RIGHT);

                    watermarkView.setImageDrawable(watermark);
                    final LayoutParams layoutParams = watermarkView.getLayoutParams();
                    layoutParams.width = layoutParams.height = displayWidth;
                } else {
                    watermarkView.setImageDrawable(null);
                }

                showBranded = true;
            } else {
                friend.actionMenu = menu;
                friend.actionMenu.items = menu.itemList.toArray(new ServiceMenuItemTO[] {});
                brandingMgr.queue(friend);
            }
        } catch (BrandingFailureException e) {
            L.bug("Could not display service action menu with branding.", e);
        }
    }
    if (!showBranded) {
        setNavigationBarVisible(AppConstants.SHOW_NAV_HEADER);
        setNavigationBarTitle(menu.name);
        title.setVisibility(View.GONE);
        title.setText(menu.name);
    }

    for (final Cell cell : usedCells) {
        final View p = (View) cell.icon.getParent();
        final Drawable d = getResources().getDrawable(
                useDarkScheme ? R.drawable.mc_smi_background_light : R.drawable.mc_smi_background_dark);
        p.setBackgroundDrawable(d);
    }

    if (menuItemColor == null)
        menuItemColor = Color.parseColor("#646464");

    for (Cell cell : new Cell[] { cells[0][0], cells[1][0], cells[2][0], cells[3][0] })
        cell.faIcon.setTextColor(menuItemColor);

    if (menu.maxPage > 0) {
        for (int i = 0; i <= menu.maxPage; i++) {
            ImageView bolleke = (ImageView) getLayoutInflater().inflate(R.layout.page, pages, false);
            if (page == i) {
                if (useDarkScheme) {
                    bolleke.setImageResource(R.drawable.current_page_dark);
                } else {
                    bolleke.setImageResource(R.drawable.current_page_light);
                }
            } else {
                if (useDarkScheme) {
                    bolleke.setImageResource(R.drawable.other_page_dark);
                } else {
                    bolleke.setImageResource(R.drawable.other_page_light);
                }
            }
            pages.addView(bolleke);
        }
        pages.setVisibility(View.VISIBLE);
    }
    final int leftPage = page - 1;
    final int rightPage = page + 1;
    final String service = email;
    Slider instance = new Slider(this, this, page == menu.maxPage ? null : new Slider.Swiper() {
        @Override
        public Intent onSwipe() {
            return new Intent(ServiceActionMenuActivity.this, ServiceActionMenuActivity.class)
                    .putExtra(SERVICE_EMAIL, service).putExtra(MENU_PAGE, rightPage);
        }
    }, page == 0 ? null : new Slider.Swiper() {
        @Override
        public Intent onSwipe() {
            return new Intent(ServiceActionMenuActivity.this, ServiceActionMenuActivity.class)
                    .putExtra(SERVICE_EMAIL, service).putExtra(MENU_PAGE, leftPage);
        }
    });
    mGestureScanner = new GestureDetector(this, instance);
}

From source file:com.cloverstudio.spika.MyProfileActivity.java

@Override
protected Dialog onCreateDialog(int id) {
    switch (id) {
    case GET_IMAGE_DIALOG:
        mGetImageDialog = new Dialog(MyProfileActivity.this, R.style.TransparentDialogTheme);
        mGetImageDialog.getWindow().setGravity(Gravity.BOTTOM);
        mGetImageDialog.setContentView(R.layout.dialog_get_image);
        WindowManager.LayoutParams params = new WindowManager.LayoutParams();
        Window window = mGetImageDialog.getWindow();
        params.copyFrom(window.getAttributes());
        params.width = WindowManager.LayoutParams.MATCH_PARENT;
        params.height = WindowManager.LayoutParams.WRAP_CONTENT;
        window.setAttributes(params);//w w w.  j a  va  2 s.c om

        final Button btnGallery = (Button) mGetImageDialog.findViewById(R.id.btnGallery);
        btnGallery.setTypeface(SpikaApp.getTfMyriadProBold(), Typeface.BOLD);
        btnGallery.setOnClickListener(new OnClickListener() {

            public void onClick(View v) {

                Intent galleryIntent = new Intent(MyProfileActivity.this, CameraCropActivity.class);
                galleryIntent.putExtra("type", "gallery");
                galleryIntent.putExtra("profile", true);
                MyProfileActivity.this.startActivityForResult(galleryIntent, UPDATE_IMAGE_REQUEST_CODE);
                mGetImageDialog.dismiss();

            }
        });

        final Button btnCamera = (Button) mGetImageDialog.findViewById(R.id.btnCamera);
        btnCamera.setTypeface(SpikaApp.getTfMyriadProBold(), Typeface.BOLD);
        btnCamera.setOnClickListener(new OnClickListener() {

            public void onClick(View v) {

                Intent cameraIntent = new Intent(MyProfileActivity.this, CameraCropActivity.class);
                cameraIntent.putExtra("type", "camera");
                cameraIntent.putExtra("profile", true);
                MyProfileActivity.this.startActivityForResult(cameraIntent, UPDATE_IMAGE_REQUEST_CODE);
                mGetImageDialog.dismiss();

            }
        });

        final Button btnRemovePhoto = (Button) mGetImageDialog.findViewById(R.id.btnRemovePhoto);
        btnRemovePhoto.setTypeface(SpikaApp.getTfMyriadProBold(), Typeface.BOLD);
        btnRemovePhoto.setOnClickListener(new OnClickListener() {

            public void onClick(View v) {

                mNewAvatarId = "";
                gProfileImage = null;
                Utils.displayImage(mNewAvatarId, mIvProfileImage, mPbLoading, ImageLoader.LARGE,
                        R.drawable.user_stub_large, false);
                mGetImageDialog.dismiss();

            }
        });

        return mGetImageDialog;
    case GET_BIRTHDAY_DIALOG:

        int intMaxYear = Calendar.getInstance().get(Calendar.YEAR);
        int intMaxMonth = Calendar.getInstance().get(Calendar.MONTH);
        int intMaxDay = Calendar.getInstance().get(Calendar.DAY_OF_MONTH);

        mGetBirthdayDialog = new DatePickerDialogWithRange(this, new DatePickerDialog.OnDateSetListener() {
            public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
                Time chosenDate = new Time();
                chosenDate.set(dayOfMonth, monthOfYear, year);
                mNewBirthday = chosenDate.toMillis(true) / 1000;
                CharSequence stringDate = DateFormat.format(getString(R.string.hookup_date_format),
                        chosenDate.toMillis(true));
                mEtUserBirthday.setText(stringDate.toString());
            }
        }, intMaxYear, intMaxMonth, intMaxDay);
        mGetBirthdayDialog.setMessage(getString(R.string.when_is_your_birthday));
        return mGetBirthdayDialog;
    default:
        return null;
    }
}

From source file:com.android.mail.browse.ConversationContainer.java

private static OverlayPosition calculatePosition(final ConversationOverlayItem adapterItem, final int withinTop,
        final int withinBottom, final int forceGravity) {
    if (adapterItem.getHeight() == 0) {
        // "place" invisible items at the bottom of their region to stay consistent with the
        // stacking algorithm in positionOverlays(), unless gravity is forced to the top
        final int y = (forceGravity == Gravity.TOP) ? withinTop : withinBottom;
        return new OverlayPosition(y, y);
    }/*from   www.j a  va  2  s  . c om*/

    final int v = ((forceGravity != Gravity.NO_GRAVITY) ? forceGravity : adapterItem.getGravity())
            & Gravity.VERTICAL_GRAVITY_MASK;
    switch (v) {
    case Gravity.BOTTOM:
        return new OverlayPosition(withinBottom - adapterItem.getHeight(), withinBottom);
    case Gravity.TOP:
        return new OverlayPosition(withinTop, withinTop + adapterItem.getHeight());
    default:
        throw new UnsupportedOperationException("unsupported gravity: " + v);
    }
}

From source file:com.mixiaoxiao.mxxedgeeffect.widget.MxxPagerTitleStrip.java

void updateTextPositions(int position, float positionOffset, boolean force) {
    // position??item,currText
    // onPageScrolledpositionOffset>0.5fposition+1
    if (position != mLastKnownCurrentPage) {
        updateText(position, mPager.getAdapter());
    } else if (!force && positionOffset == mLastKnownPositionOffset) {
        return;//from w  w  w .  ja va 2 s  .c o m
    }

    // ///////////////
    if (positionOffset == 0f) {
        mPrevText.setTextColor(convertTextColor(0f));
        mCurrText.setTextColor(convertTextColor(1f));
        mNextText.setTextColor(convertTextColor(0f));
    } else {
        //         Log.d(TAG, "position->" + position + "  positionOffset->" + positionOffset);
        float currPercent = positionOffset;// positionOffset=0.6
        // currOffset=0.1
        // boolean isOffsetAdding = (positionOffset -
        // mLastKnownPositionOffset)>0f;//offset
        if (currPercent <= 0.5f) {// 
            mPrevText.setTextColor(convertTextColor(0f));
            mCurrText.setTextColor(convertTextColor((1f - currPercent)));
            // if(isOffsetAdding){

            mNextText.setTextColor(convertTextColor(currPercent));
            // }

        } else {// 
                // currPercent -= 0.5f;
            mPrevText.setTextColor(convertTextColor(1f - currPercent));
            mCurrText.setTextColor(convertTextColor(currPercent));
            mNextText.setTextColor(convertTextColor(0));
        }
        // if (currPercent > 0.5f) {
        // currPercent -= 0.5f;
        // }
        // mPrevText.setTextColor(convertTextColor(currPercent));

    }

    // mNextText.setTextColor(transparentColor);

    mUpdatingPositions = true;

    final int prevWidth = mPrevText.getMeasuredWidth();
    final int currWidth = mCurrText.getMeasuredWidth();
    final int nextWidth = mNextText.getMeasuredWidth();
    final int halfCurrWidth = 0;// currWidth / 2;

    final int stripWidth = getWidth();
    final int stripHeight = getHeight();
    final int paddingLeft = getPaddingLeft();
    final int paddingRight = getPaddingRight();
    final int paddingTop = getPaddingTop();
    final int paddingBottom = getPaddingBottom();
    //      final int textPaddedLeft = paddingLeft + halfCurrWidth;
    //      final int textPaddedRight = paddingRight + halfCurrWidth;
    //      final int contentWidth = prevWidth + currWidth + nextWidth;// stripWidth
    // -
    // textPaddedLeft
    // -
    // textPaddedRight;

    float currOffset = positionOffset + 0.5f;// positionOffset=0.6
    // currOffset=0.1
    if (currOffset > 1.f) {
        currOffset -= 1.f;
    }
    // float currOffset = positionOffset;
    // if (currOffset > 1.f) {
    // currOffset -= 1.f;
    // }
    final int currCenter = stripWidth / 2 - (int) (currWidth * (currOffset - 0.5f));// stripWidth
    // -
    // textPaddedRight
    // -
    // (int)
    // (contentWidth
    // *
    // currOffset);

    final int currLeft = currCenter - currWidth / 2;
    final int currRight = currLeft + currWidth;

    final int prevBaseline = mPrevText.getBaseline();
    final int currBaseline = mCurrText.getBaseline();
    final int nextBaseline = mNextText.getBaseline();
    final int maxBaseline = Math.max(Math.max(prevBaseline, currBaseline), nextBaseline);
    final int prevTopOffset = maxBaseline - prevBaseline;
    final int currTopOffset = maxBaseline - currBaseline;
    final int nextTopOffset = maxBaseline - nextBaseline;
    final int alignedPrevHeight = prevTopOffset + mPrevText.getMeasuredHeight();
    final int alignedCurrHeight = currTopOffset + mCurrText.getMeasuredHeight();
    final int alignedNextHeight = nextTopOffset + mNextText.getMeasuredHeight();
    final int maxTextHeight = Math.max(Math.max(alignedPrevHeight, alignedCurrHeight), alignedNextHeight);

    final int vgrav = mGravity & Gravity.VERTICAL_GRAVITY_MASK;

    int prevTop;
    int currTop;
    int nextTop;
    switch (vgrav) {
    default:
    case Gravity.TOP:
        prevTop = paddingTop + prevTopOffset;
        currTop = paddingTop + currTopOffset;
        nextTop = paddingTop + nextTopOffset;
        break;
    case Gravity.CENTER_VERTICAL:
        final int paddedHeight = stripHeight - paddingTop - paddingBottom;
        final int centeredTop = (paddedHeight - maxTextHeight) / 2;
        prevTop = centeredTop + prevTopOffset;
        currTop = centeredTop + currTopOffset;
        nextTop = centeredTop + nextTopOffset;
        break;
    case Gravity.BOTTOM:
        final int bottomGravTop = stripHeight - paddingBottom - maxTextHeight;
        prevTop = bottomGravTop + prevTopOffset;
        currTop = bottomGravTop + currTopOffset;
        nextTop = bottomGravTop + nextTopOffset;
        break;
    }

    mCurrText.layout(currLeft, currTop, currRight, currTop + mCurrText.getMeasuredHeight());

    final int prevLeft = currLeft - mScaledTextSpacing - prevWidth;// Math.min(paddingLeft,
    // currLeft
    // -
    // mScaledTextSpacing
    // -
    // prevWidth);
    mPrevText.layout(prevLeft, prevTop, prevLeft + prevWidth, prevTop + mPrevText.getMeasuredHeight());

    final int nextLeft = currRight + mScaledTextSpacing;// Math.max(stripWidth
    // - paddingRight -
    // nextWidth,
    // currRight + mScaledTextSpacing);
    mNextText.layout(nextLeft, nextTop, nextLeft + nextWidth, nextTop + mNextText.getMeasuredHeight());

    mLastKnownPositionOffset = positionOffset;
    mUpdatingPositions = false;
}

From source file:com.hss01248.toast.supertoast.SuperActivityToast.java

/**
 * Modify various attributes of the SuperActivityToast before being shown.
 *///from w  ww . j  a v a 2  s.  c  om
@Override
protected void onPrepareShow() {
    super.onPrepareShow(); // This will take care of many modifications

    final FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(this.mStyle.width,
            this.mStyle.height);

    // Make some type specific tweaks
    switch (this.mStyle.type) {

    case Style.TYPE_STANDARD:
        break;

    case Style.TYPE_BUTTON:
        // If NOT Lollipop frame, give padding on each side
        if (this.mStyle.frame != Style.FRAME_LOLLIPOP) {
            this.mStyle.width = FrameLayout.LayoutParams.MATCH_PARENT;
            this.mStyle.xOffset = BackgroundUtils.convertToDIP(24);
            this.mStyle.yOffset = BackgroundUtils.convertToDIP(24);
        }

        // On a big screen device, show the SuperActivityToast on the bottom left
        if ((this.mContext.getResources().getConfiguration().screenLayout
                & Configuration.SCREENLAYOUT_SIZE_MASK) >= Configuration.SCREENLAYOUT_SIZE_LARGE) {
            this.mStyle.width = BackgroundUtils.convertToDIP(568);
            this.mStyle.gravity = Gravity.BOTTOM | Gravity.START;
        }

        // Set up the Button attributes
        final Button button = (Button) this.mView.findViewById(R.id.button);
        button.setBackgroundResource(BackgroundUtils.getButtonBackgroundResource(this.mStyle.frame));
        button.setText(this.mStyle.buttonText != null ? this.mStyle.buttonText.toUpperCase() : "");
        button.setTypeface(button.getTypeface(), this.mStyle.buttonTypefaceStyle);
        button.setTextColor(this.mStyle.buttonTextColor);
        button.setTextSize(this.mStyle.buttonTextSize);

        if (this.mStyle.frame != Style.FRAME_LOLLIPOP) {
            this.mView.findViewById(R.id.divider).setBackgroundColor(this.mStyle.buttonDividerColor);

            // Set an icon resource if desired
            if (this.mStyle.buttonIconResource > 0) {
                button.setCompoundDrawablesWithIntrinsicBounds(
                        ResourcesCompat.getDrawable(mContext.getResources(), this.mStyle.buttonIconResource,
                                mContext.getTheme()),
                        null, null, null);
            }
        }

        if (this.mOnButtonClickListener != null) {
            button.setOnClickListener(new View.OnClickListener() {

                short clicked = 0;

                @Override
                public void onClick(View view) {
                    // Prevent button spamming
                    if (clicked > 0)
                        return;
                    clicked++;

                    mOnButtonClickListener.onClick(view, getButtonToken());
                    SuperActivityToast.this.dismiss();
                }
            });
        }
        break;

    case Style.TYPE_PROGRESS_CIRCLE:
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            this.mProgressBar.setIndeterminateTintMode(PorterDuff.Mode.SRC_IN);
            this.mProgressBar.setIndeterminateTintList(ColorStateList.valueOf(this.mStyle.progressBarColor));
        }
        break;

    case Style.TYPE_PROGRESS_BAR:
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            this.mProgressBar.setIndeterminateTintMode(PorterDuff.Mode.SRC_IN);
            this.mProgressBar.setIndeterminateTintList(ColorStateList.valueOf(this.mStyle.progressBarColor));
            this.mProgressBar.setProgressTintMode(PorterDuff.Mode.SRC_IN);
            this.mProgressBar.setProgressTintList(ColorStateList.valueOf(this.mStyle.progressBarColor));
        }
        this.mProgressBar.setProgress(this.mStyle.progress);
        this.mProgressBar.setMax(this.mStyle.progressMax);
        this.mProgressBar.setIndeterminate(this.mStyle.progressIndeterminate);
        break;
    }

    layoutParams.width = this.mStyle.width;
    layoutParams.height = this.mStyle.height;
    layoutParams.gravity = this.mStyle.gravity;
    layoutParams.bottomMargin = this.mStyle.yOffset;
    layoutParams.topMargin = this.mStyle.yOffset;
    layoutParams.leftMargin = this.mStyle.xOffset;
    layoutParams.rightMargin = this.mStyle.xOffset;

    this.mView.setLayoutParams(layoutParams);

    // Set up touch to dismiss
    if (this.mStyle.touchToDismiss) {
        mView.setOnTouchListener(new View.OnTouchListener() {

            int timesTouched;

            @Override
            public boolean onTouch(View v, MotionEvent motionEvent) {
                // Prevent repetitive touch events
                if (timesTouched == 0 && motionEvent.getAction() == MotionEvent.ACTION_DOWN)
                    dismiss();
                timesTouched++;

                return false; // Do not consume the event in case a Button listener is set
            }
        });
    } else {
        // Make sure no listener is set
        mView.setOnTouchListener(null);
    }
}

From source file:com.hss01248.lib.supertoast.SuperActivityToast.java

/**
 * Modify various attributes of the SuperActivityToast before being shown.         
 *///w w  w .ja v  a  2  s  . c om
@Override
protected void onPrepareShow() {
    super.onPrepareShow(); // This will take care of many modifications 

    final FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(this.mStyle.width,
            this.mStyle.height);

    // Make some type specific tweaks
    switch (this.mStyle.type) {

    case Style.TYPE_STANDARD:
        break;

    case Style.TYPE_BUTTON:
        // If NOT Lollipop frame, give padding on each side
        if (this.mStyle.frame != Style.FRAME_LOLLIPOP) {
            this.mStyle.width = FrameLayout.LayoutParams.MATCH_PARENT;
            this.mStyle.xOffset = BackgroundUtils.convertToDIP(24);
            this.mStyle.yOffset = BackgroundUtils.convertToDIP(24);
        }

        // On a big screen device, show the SuperActivityToast on the bottom left
        if ((this.mContext.getResources().getConfiguration().screenLayout
                & Configuration.SCREENLAYOUT_SIZE_MASK) >= Configuration.SCREENLAYOUT_SIZE_LARGE) {
            this.mStyle.width = BackgroundUtils.convertToDIP(568);
            this.mStyle.gravity = Gravity.BOTTOM | Gravity.START;
        }

        // Set up the Button attributes
        final Button button = (Button) this.mView.findViewById(R.id.button);
        button.setBackgroundResource(BackgroundUtils.getButtonBackgroundResource(this.mStyle.frame));
        button.setText(this.mStyle.buttonText != null ? this.mStyle.buttonText.toUpperCase() : "");
        button.setTypeface(button.getTypeface(), this.mStyle.buttonTypefaceStyle);
        button.setTextColor(this.mStyle.buttonTextColor);
        button.setTextSize(this.mStyle.buttonTextSize);

        if (this.mStyle.frame != Style.FRAME_LOLLIPOP) {
            this.mView.findViewById(R.id.divider).setBackgroundColor(this.mStyle.buttonDividerColor);

            // Set an icon resource if desired
            if (this.mStyle.buttonIconResource > 0) {
                button.setCompoundDrawablesWithIntrinsicBounds(
                        ResourcesCompat.getDrawable(mContext.getResources(), this.mStyle.buttonIconResource,
                                mContext.getTheme()),
                        null, null, null);
            }
        }

        if (this.mOnButtonClickListener != null) {
            button.setOnClickListener(new View.OnClickListener() {

                short clicked = 0;

                @Override
                public void onClick(View view) {
                    // Prevent button spamming
                    if (clicked > 0)
                        return;
                    clicked++;

                    mOnButtonClickListener.onClick(view, getButtonToken());
                    SuperActivityToast.this.dismiss();
                }
            });
        }
        break;

    case Style.TYPE_PROGRESS_CIRCLE:
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            this.mProgressBar.setIndeterminateTintMode(PorterDuff.Mode.SRC_IN);
            this.mProgressBar.setIndeterminateTintList(ColorStateList.valueOf(this.mStyle.progressBarColor));
        }
        break;

    case Style.TYPE_PROGRESS_BAR:
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            this.mProgressBar.setIndeterminateTintMode(PorterDuff.Mode.SRC_IN);
            this.mProgressBar.setIndeterminateTintList(ColorStateList.valueOf(this.mStyle.progressBarColor));
            this.mProgressBar.setProgressTintMode(PorterDuff.Mode.SRC_IN);
            this.mProgressBar.setProgressTintList(ColorStateList.valueOf(this.mStyle.progressBarColor));
        }
        this.mProgressBar.setProgress(this.mStyle.progress);
        this.mProgressBar.setMax(this.mStyle.progressMax);
        this.mProgressBar.setIndeterminate(this.mStyle.progressIndeterminate);
        break;
    }

    layoutParams.width = this.mStyle.width;
    layoutParams.height = this.mStyle.height;
    layoutParams.gravity = this.mStyle.gravity;
    layoutParams.bottomMargin = this.mStyle.yOffset;
    layoutParams.topMargin = this.mStyle.yOffset;
    layoutParams.leftMargin = this.mStyle.xOffset;
    layoutParams.rightMargin = this.mStyle.xOffset;

    this.mView.setLayoutParams(layoutParams);

    // Set up touch to dismiss
    if (this.mStyle.touchToDismiss) {
        mView.setOnTouchListener(new View.OnTouchListener() {

            int timesTouched;

            @Override
            public boolean onTouch(View v, MotionEvent motionEvent) {
                // Prevent repetitive touch events
                if (timesTouched == 0 && motionEvent.getAction() == MotionEvent.ACTION_DOWN)
                    dismiss();
                timesTouched++;

                return false; // Do not consume the event in case a Button listener is set
            }
        });
    } else {
        // Make sure no listener is set
        mView.setOnTouchListener(null);
    }
}

From source file:com.dwdesign.tweetings.activity.HomeActivity.java

@Override
public boolean onPrepareOptionsMenu(final Menu menu) {
    final boolean bottom_actions = mPreferences.getBoolean(PREFERENCE_KEY_COMPOSE_BUTTON, false);
    final boolean leftside_compose_button = mPreferences.getBoolean(PREFERENCE_KEY_LEFTSIDE_COMPOSE_BUTTON,
            false);/* w ww.  j  a  v a  2  s  .  c  o m*/
    int icon = R.drawable.ic_menu_tweet, title = R.string.compose;
    if (mViewPager != null && mAdapter != null) {
        final int position = mViewPager.getCurrentItem();
        int messagesPosition = TAB_POSITION_MESSAGES;
        if (mShowHomeTab == false) {
            messagesPosition--;
        }
        if (mShowMentionsTab == false) {
            messagesPosition--;
        }
        if (position == mAdapter.getCount() - 1 && mShowAccountsTab) {
            icon = R.drawable.ic_menu_add;
            title = R.string.add_account;
        } else {
            title = R.string.compose;
            if (mShowMessagesTab && position == messagesPosition) {
                icon = R.drawable.ic_menu_compose;
            } else {
                icon = R.drawable.ic_menu_tweet;
            }
        }
        final MenuItem composeItem = menu.findItem(MENU_COMPOSE);
        if (composeItem != null) {
            composeItem.setIcon(icon);
            composeItem.setTitle(title);
            composeItem.setVisible(!bottom_actions && mViewPager.getVisibility() == View.VISIBLE);
        }
        if (mComposeButton != null) {
            mComposeButton.setImageResource(icon);
            mComposeButton.setVisibility(
                    bottom_actions && mViewPager.getVisibility() == View.VISIBLE ? View.VISIBLE : View.GONE);
            if (bottom_actions) {
                final FrameLayout.LayoutParams compose_lp = (FrameLayout.LayoutParams) mComposeButton
                        .getLayoutParams();
                compose_lp.gravity = Gravity.BOTTOM | (leftside_compose_button ? Gravity.LEFT : Gravity.RIGHT);
                mComposeButton.setLayoutParams(compose_lp);
            }
        }
    }
    return super.onPrepareOptionsMenu(menu);
}

From source file:com.b44t.ui.ActionBar.BottomSheet.java

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

    Window window = getWindow();//from   w ww  .j a  va 2  s . co m
    window.setWindowAnimations(R.style.DialogNoAnimation);
    setContentView(container, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));

    if (containerView == null) {
        containerView = new FrameLayout(getContext()) {
            @Override
            public boolean hasOverlappingRendering() {
                return false;
            }
        };
        containerView.setBackgroundDrawable(shadowDrawable);
        containerView.setPadding(backgroundPaddingLeft,
                (applyTopPadding ? AndroidUtilities.dp(8) : 0) + backgroundPaddingTop, backgroundPaddingLeft,
                (applyBottomPadding ? AndroidUtilities.dp(8) : 0));
    }
    if (Build.VERSION.SDK_INT >= 21) {
        containerView.setFitsSystemWindows(true);
    }
    containerView.setVisibility(View.INVISIBLE);
    container.addView(containerView, 0,
            LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, Gravity.BOTTOM));

    if (customView != null) {
        if (customView.getParent() != null) {
            ViewGroup viewGroup = (ViewGroup) customView.getParent();
            viewGroup.removeView(customView);
        }
        containerView.addView(customView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT,
                LayoutHelper.WRAP_CONTENT, Gravity.LEFT | Gravity.TOP));
    } else {
        int topOffset = 0;
        if (title != null) {
            TextView titleView = new TextView(getContext());
            titleView.setLines(1);
            titleView.setSingleLine(true);
            titleView.setText(title);
            titleView.setTextColor(0xff757575);
            titleView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
            titleView.setEllipsize(TextUtils.TruncateAt.MIDDLE);
            titleView.setPadding(AndroidUtilities.dp(16), 0, AndroidUtilities.dp(16), AndroidUtilities.dp(8));
            titleView.setGravity(Gravity.CENTER_VERTICAL);
            containerView.addView(titleView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 48));
            titleView.setOnTouchListener(new View.OnTouchListener() {
                @Override
                public boolean onTouch(View v, MotionEvent event) {
                    return true;
                }
            });
            topOffset += 48;
        }
        if (items != null) {
            FrameLayout rowLayout = null;
            int lastRowLayoutNum = 0;
            for (int a = 0; a < items.length; a++) {
                BottomSheetCell cell = new BottomSheetCell(getContext(), 0);
                cell.setTextAndIcon(items[a], itemIcons != null ? itemIcons[a] : 0);
                containerView.addView(cell, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 48,
                        Gravity.LEFT | Gravity.TOP, 0, topOffset, 0, 0));
                topOffset += 48;
                cell.setTag(a);
                cell.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        dismissWithButtonClick((Integer) v.getTag());
                    }
                });
                itemViews.add(cell);
            }
        }
    }

    WindowManager.LayoutParams params = window.getAttributes();
    params.width = ViewGroup.LayoutParams.MATCH_PARENT;
    params.gravity = Gravity.TOP | Gravity.LEFT;
    params.dimAmount = 0;
    params.flags &= ~WindowManager.LayoutParams.FLAG_DIM_BEHIND;
    if (!focusable) {
        params.flags |= WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM;
    }
    params.height = ViewGroup.LayoutParams.MATCH_PARENT;
    window.setAttributes(params);
}

From source file:com.github.johnpersano.supertoasts.library.SuperActivityToast.java

/**
 * Modify various attributes of the SuperActivityToast before being shown.         
 *//*from  w  w  w.  jav  a  2  s  .co  m*/
@Override
protected void onPrepareShow() {
    super.onPrepareShow(); // This will take care of many modifications 

    final FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(this.mStyle.width,
            this.mStyle.height);

    // Make some type specific tweaks
    switch (this.mStyle.type) {

    case Style.TYPE_STANDARD:
        break;

    case Style.TYPE_BUTTON:
        // If NOT Lollipop frame, give padding on each side
        if (this.mStyle.frame != Style.FRAME_LOLLIPOP) {
            this.mStyle.width = FrameLayout.LayoutParams.MATCH_PARENT;
            this.mStyle.xOffset = BackgroundUtils.convertToDIP(24);
            this.mStyle.yOffset = BackgroundUtils.convertToDIP(24);
        }

        // On a big screen device, show the SuperActivityToast on the bottom left
        if ((this.mContext.getResources().getConfiguration().screenLayout
                & Configuration.SCREENLAYOUT_SIZE_MASK) >= Configuration.SCREENLAYOUT_SIZE_LARGE) {
            this.mStyle.width = BackgroundUtils.convertToDIP(568);
            this.mStyle.gravity = Gravity.BOTTOM | Gravity.START;
        }

        // Set up the Button attributes
        final Button button = (Button) this.mView.findViewById(R.id.button);
        button.setBackgroundResource(BackgroundUtils.getButtonBackgroundResource(this.mStyle.frame));
        button.setText(this.mStyle.buttonText != null ? this.mStyle.buttonText.toUpperCase() : "");
        button.setTypeface(button.getTypeface(), this.mStyle.buttonTypefaceStyle);
        button.setTextColor(this.mStyle.buttonTextColor);
        button.setTextSize(this.mStyle.buttonTextSize);

        if (this.mStyle.frame != Style.FRAME_LOLLIPOP) {
            this.mView.findViewById(R.id.divider).setBackgroundColor(this.mStyle.buttonDividerColor);

            // Set an icon resource if desired
            if (this.mStyle.buttonIconResource > 0) {
                button.setCompoundDrawablesWithIntrinsicBounds(
                        ResourcesCompat.getDrawable(mContext.getResources(), this.mStyle.buttonIconResource,
                                mContext.getTheme()),
                        null, null, null);
            }
        }

        if (this.mOnButtonClickListener != null) {
            button.setOnClickListener(new View.OnClickListener() {

                short clicked = 0;

                @Override
                public void onClick(View view) {
                    // Prevent button spamming
                    if (clicked > 0)
                        return;
                    clicked++;

                    mOnButtonClickListener.onClick(view, getButtonToken());
                    SuperActivityToast.this.dismiss();
                }
            });
        }
        break;

    case Style.TYPE_PROGRESS_CIRCLE:
        if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            this.mProgressBar.setIndeterminateTintMode(PorterDuff.Mode.SRC_IN);
            this.mProgressBar.setIndeterminateTintList(ColorStateList.valueOf(this.mStyle.progressBarColor));
        }
        break;

    case Style.TYPE_PROGRESS_BAR:
        if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            this.mProgressBar.setIndeterminateTintMode(PorterDuff.Mode.SRC_IN);
            this.mProgressBar.setIndeterminateTintList(ColorStateList.valueOf(this.mStyle.progressBarColor));
            this.mProgressBar.setProgressTintMode(PorterDuff.Mode.SRC_IN);
            this.mProgressBar.setProgressTintList(ColorStateList.valueOf(this.mStyle.progressBarColor));
        }
        this.mProgressBar.setProgress(this.mStyle.progress);
        this.mProgressBar.setMax(this.mStyle.progressMax);
        this.mProgressBar.setIndeterminate(this.mStyle.progressIndeterminate);
        break;
    }

    layoutParams.width = this.mStyle.width;
    layoutParams.height = this.mStyle.height;
    layoutParams.gravity = this.mStyle.gravity;
    layoutParams.bottomMargin = this.mStyle.yOffset;
    layoutParams.topMargin = this.mStyle.yOffset;
    layoutParams.leftMargin = this.mStyle.xOffset;
    layoutParams.rightMargin = this.mStyle.xOffset;

    this.mView.setLayoutParams(layoutParams);

    // Set up touch to dismiss
    if (this.mStyle.touchToDismiss) {
        mView.setOnTouchListener(new View.OnTouchListener() {

            int timesTouched;

            @Override
            public boolean onTouch(View v, MotionEvent motionEvent) {
                // Prevent repetitive touch events
                if (timesTouched == 0 && motionEvent.getAction() == MotionEvent.ACTION_DOWN)
                    dismiss();
                timesTouched++;

                return false; // Do not consume the event in case a Button listener is set
            }
        });
    } else {
        // Make sure no listener is set
        mView.setOnTouchListener(null);
    }
}