Example usage for android.content.res Configuration SCREENLAYOUT_SIZE_MASK

List of usage examples for android.content.res Configuration SCREENLAYOUT_SIZE_MASK

Introduction

In this page you can find the example usage for android.content.res Configuration SCREENLAYOUT_SIZE_MASK.

Prototype

int SCREENLAYOUT_SIZE_MASK

To view the source code for android.content.res Configuration SCREENLAYOUT_SIZE_MASK.

Click Source Link

Document

Constant for #screenLayout : bits that encode the size.

Usage

From source file:com.m2dl.mini_projet.mini_projet_android.MainActivity.java

private boolean screenIsLarge() {
    int screenMask = getResources().getConfiguration().screenLayout;
    if ((screenMask & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_LARGE) {
        return true;
    }//w  w  w. ja  v a  2 s  . c o  m

    if ((screenMask & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_XLARGE) {
        return true;
    }

    return false;
}

From source file:com.yozio.android.YozioHelper.java

private void setScreenInfo() {
    try {// w w w . j a  v a  2  s.c om
        // This is a backwards compatibility fix for Android 1.5 which has no
        // display metric API.
        // If this is 1.6 or higher, then load the class, otherwise the class
        // never loads and
        // no crash occurs.
        if (Integer.parseInt(android.os.Build.VERSION.SDK) > 3) {
            DisplayMetrics displayMetrics = new DisplayMetrics();
            WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
            windowManager.getDefaultDisplay().getMetrics(displayMetrics);
            Configuration configuration = context.getResources().getConfiguration();

            deviceScreenDensity = "" + displayMetrics.densityDpi;
            deviceScreenLayoutSize = "" + (configuration.screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK);
        }
    } catch (Exception e) {
    }
}

From source file:de.baumann.thema.RequestActivity.java

private static boolean isXLargeTablet(Context context) {
    return (context.getResources().getConfiguration().screenLayout
            & Configuration.SCREENLAYOUT_SIZE_MASK) >= Configuration.SCREENLAYOUT_SIZE_XLARGE;
}

From source file:com.haibison.android.lockpattern.LockPatternFragment.java

/**
 * Initializes UI...//from w w w. j  a va2  s .  c o m
 */
private void initContentView() {
    /*
     * Save all controls' state to restore later.
     */
    CharSequence infoText = mTextInfo != null ? mTextInfo.getText() : null;
    Boolean btnOkEnabled = mBtnConfirm != null ? mBtnConfirm.isEnabled() : null;
    LockPatternView.DisplayMode lastDisplayMode = mLockPatternView != null ? mLockPatternView.getDisplayMode()
            : null;
    List<Cell> lastPattern = mLockPatternView != null ? mLockPatternView.getPattern() : null;

    fa.setContentView(R.layout.alp_42447968_lock_pattern_fragment);
    UI.adjustDialogSizeForLargeScreens(fa.getWindow());

    mTextInfo = (TextView) getView().findViewById(R.id.alp_42447968_textview_info);
    mLockPatternView = (LockPatternView) getView().findViewById(R.id.alp_42447968_view_lock_pattern);

    mFooter = getView().findViewById(R.id.alp_42447968_viewgroup_footer);
    mBtnCancel = (Button) getView().findViewById(R.id.alp_42447968_button_cancel);
    mBtnConfirm = (Button) getView().findViewById(R.id.alp_42447968_button_confirm);

    /*
     * LOCK PATTERN VIEW
     */

    switch (getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) {
    case Configuration.SCREENLAYOUT_SIZE_LARGE:
    case Configuration.SCREENLAYOUT_SIZE_XLARGE: {
        final int size = getResources().getDimensionPixelSize(R.dimen.alp_42447968_lockpatternview_size);
        LayoutParams lp = mLockPatternView.getLayoutParams();
        lp.width = size;
        lp.height = size;
        mLockPatternView.setLayoutParams(lp);

        break;
    } // LARGE / XLARGE
    }

    /*
     * Haptic feedback.
     */
    boolean hapticFeedbackEnabled = false;
    try {
        hapticFeedbackEnabled = android.provider.Settings.System.getInt(fa.getContentResolver(),
                android.provider.Settings.System.HAPTIC_FEEDBACK_ENABLED, 0) != 0;
    } catch (Throwable t) {
        /*
         * Ignore it.
         */
    }
    mLockPatternView.setTactileFeedbackEnabled(hapticFeedbackEnabled);

    mLockPatternView
            .setInStealthMode(mStealthMode && !ACTION_VERIFY_CAPTCHA.equals(fa.getIntent().getAction()));
    mLockPatternView.setOnPatternListener(mLockPatternViewListener);
    if (lastPattern != null && lastDisplayMode != null
            && !ACTION_VERIFY_CAPTCHA.equals(fa.getIntent().getAction()))
        mLockPatternView.setPattern(lastDisplayMode, lastPattern);

    /*
     * COMMAND BUTTONS
     */

    if (ACTION_CREATE_PATTERN.equals(fa.getIntent().getAction())) {
        mBtnCancel.setOnClickListener(mBtnCancelOnClickListener);
        mBtnConfirm.setOnClickListener(mBtnConfirmOnClickListener);

        mBtnCancel.setVisibility(View.VISIBLE);
        mFooter.setVisibility(View.VISIBLE);

        if (infoText != null)
            mTextInfo.setText(infoText);
        else
            mTextInfo.setText(R.string.alp_42447968_msg_draw_an_unlock_pattern);

        /*
         * BUTTON OK
         */
        if (mBtnOkCmd == null)
            mBtnOkCmd = ButtonOkCommand.CONTINUE;
        switch (mBtnOkCmd) {
        case CONTINUE:
            mBtnConfirm.setText(R.string.alp_42447968_cmd_continue);
            break;
        case DONE:
            mBtnConfirm.setText(R.string.alp_42447968_cmd_confirm);
            break;
        default:
            /*
             * Do nothing.
             */
            break;
        }
        if (btnOkEnabled != null)
            mBtnConfirm.setEnabled(btnOkEnabled);
    } // ACTION_CREATE_PATTERN
    else if (ACTION_COMPARE_PATTERN.equals(fa.getIntent().getAction())) {
        if (TextUtils.isEmpty(infoText))
            mTextInfo.setText(R.string.alp_42447968_msg_draw_pattern_to_unlock);
        else
            mTextInfo.setText(infoText);
        if (fa.getIntent().hasExtra(EXTRA_PENDING_INTENT_FORGOT_PATTERN)) {
            mBtnConfirm.setOnClickListener(mBtnConfirmOnClickListener);
            mBtnConfirm.setText(R.string.alp_42447968_cmd_forgot_pattern);
            mBtnConfirm.setEnabled(true);
            mFooter.setVisibility(View.VISIBLE);
        }
    } // ACTION_COMPARE_PATTERN
    else if (ACTION_VERIFY_CAPTCHA.equals(fa.getIntent().getAction())) {
        mTextInfo.setText(R.string.alp_42447968_msg_redraw_pattern_to_confirm);

        /*
         * NOTE: EXTRA_PATTERN should hold a char[] array. In getActivity() case we
         * use it as a temporary variable to hold a list of Cell.
         */

        final ArrayList<Cell> pattern;
        if (fa.getIntent().hasExtra(EXTRA_PATTERN))
            pattern = fa.getIntent().getParcelableArrayListExtra(EXTRA_PATTERN);
        else
            fa.getIntent().putParcelableArrayListExtra(EXTRA_PATTERN,
                    pattern = LockPatternUtils.genCaptchaPattern(mCaptchaWiredDots));

        mLockPatternView.setPattern(DisplayMode.Animate, pattern);
    } // ACTION_VERIFY_CAPTCHA
}

From source file:uk.co.threeonefour.android.snowball.activities.game.GameActivity.java

void dbgScreenSize() {

    // Determine screen size
    int screenSize = getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK;
    switch (screenSize) {
    case Configuration.SCREENLAYOUT_SIZE_XLARGE:
        Toast.makeText(this, "XLarge screen", Toast.LENGTH_LONG).show();
        break;/*from ww w . ja  v a2s . c  o m*/
    case Configuration.SCREENLAYOUT_SIZE_LARGE:
        Toast.makeText(this, "Large screen", Toast.LENGTH_LONG).show();
        break;
    case Configuration.SCREENLAYOUT_SIZE_NORMAL:
        Toast.makeText(this, "Normal sized screen", Toast.LENGTH_LONG).show();
        break;
    case Configuration.SCREENLAYOUT_SIZE_SMALL:
        Toast.makeText(this, "Small sized screen", Toast.LENGTH_LONG).show();
        break;
    default:
        Toast.makeText(this, "Unknown screen size", Toast.LENGTH_LONG).show();
        break;
    }
}

From source file:com.freerdp.freerdpcore.presentation.SessionActivity.java

private void connect(BookmarkBase bookmark) {
    session = GlobalApp.createSession(bookmark);
    session.setUIEventListener(this);
    // set writeable data directory
    LibFreeRDP.setDataDirectory(session.getInstance(), getFilesDir().toString());

    BookmarkBase.ScreenSettings screenSettings = session.getBookmark().getActiveScreenSettings();
    Log.v(TAG, "Screen Resolution: " + screenSettings.getResolutionString());
    if (screenSettings.isAutomatic()) {
        if ((getResources().getConfiguration().screenLayout
                & Configuration.SCREENLAYOUT_SIZE_MASK) >= Configuration.SCREENLAYOUT_SIZE_LARGE) {
            screenSettings.setHeight(screen_height);
            screenSettings.setWidth(screen_width);
        } else {/*from   w  w  w .j  a v  a  2 s  .  c  om*/
            // small screen device i.e. phone:
            // Automatic uses the largest side length of the screen and makes a 16:10 resolution setting out of it             
            int screenMax = (screen_width > screen_height) ? screen_width : screen_height;
            //            screenSettings.setHeight(screenMax);            
            //            screenSettings.setWidth((int)((float)screenMax * 1.6f));
            screenSettings.setHeight(screen_height);
            screenSettings.setWidth(screen_width);
        }
    }
    if (screenSettings.isFitScreen()) {
        screenSettings.setHeight(screen_height);
        screenSettings.setWidth(screen_width);
    }
    session.connect();
}

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

/**
 * Modify various attributes of the SuperActivityToast before being shown.
 *//*from w w  w.ja  v  a 2s.  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 (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.         
 *///from   www  .  j a v  a 2 s.c  o 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 (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:supertoast.utils.SuperActivityToast.java

/**
 * Modify various attributes of the SuperActivityToast before being shown.
 *//*  w w w .  ja v  a2  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 (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);
    }
}

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

/**
 * Modify various attributes of the SuperActivityToast before being shown.         
 *//*  w w  w .  j  a v  a 2  s .  c  o  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);
    }
}