Example usage for android.content.res Configuration SCREENLAYOUT_SIZE_LARGE

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

Introduction

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

Prototype

int SCREENLAYOUT_SIZE_LARGE

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

Click Source Link

Document

Constant for #screenLayout : a #SCREENLAYOUT_SIZE_MASK value indicating the screen is at least approximately 480x640 dp units, corresponds to the large resource qualifier.

Usage

From source file:com.prasanna.android.stacknetwork.utils.MarkdownFormatter.java

private static float getTextSize(Context context) {
    float textSize = 12f;
    int screentLayoutSize = context.getResources().getConfiguration().screenLayout
            & Configuration.SCREENLAYOUT_SIZE_MASK;
    if (screentLayoutSize == Configuration.SCREENLAYOUT_SIZE_LARGE
            || screentLayoutSize == Configuration.SCREENLAYOUT_SIZE_XLARGE)
        textSize = 15f;//from w  ww .  j  av  a  2 s. c  o m
    return textSize;
}

From source file:com.taobao.weex.utils.WXUtils.java

public static boolean isTabletDevice() {
    try {//w  ww .ja v  a  2  s.c o  m
        return (WXEnvironment.getApplication().getResources().getConfiguration().screenLayout
                & Configuration.SCREENLAYOUT_SIZE_MASK) >= Configuration.SCREENLAYOUT_SIZE_LARGE;
    } catch (Exception e) {
        WXLogUtils.e("[WXUtils] isTabletDevice:", e);
    }
    return false;
}

From source file:org.smilec.smile.student.CourseList.java

@Override
public void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    getWindow().requestFeature(Window.FEATURE_PROGRESS);

    Resources res = getResources(); //get resources
    language_list = res.getStringArray(R.array.language_list);
    category_arr = res.getStringArray(R.array.category_list);

    // First Extract the bundle from intent
    Bundle bundle = getIntent().getExtras();
    // Next extract the values using the key as
    curusertype = 1; // fixed (student)

    curusername = bundle.getString("USERNAME");
    cururi = bundle.getString("URI");
    curlanguage = bundle.getString("CHOSEN_LANGUAGE");
    String manufacturer = android.os.Build.MANUFACTURER;
    //showToast(manufacturer);

    resultSize1 = returnPixels(16.0f);// w w w  .  j a v a  2 s.  co  m
    resultSize2 = returnPixels(18.0f);

    if ((getResources().getConfiguration().screenLayout
            & Configuration.SCREENLAYOUT_SIZE_MASK) >= Configuration.SCREENLAYOUT_SIZE_LARGE) { // 480x640 dp units
        draw_piechart = new piechart(this, returnPixels(200.0f));
        titleSize1 = "<big>";
        titleSize2 = "</big>";
        resultSize1 = returnPixels(24.0f);
        resultSize2 = returnPixels(26.0f);
    } else if (manufacturer != null && manufacturer.toLowerCase().equals("samsung")) {
        draw_piechart = new piechart(this, returnPixels(150.0f));
        draw_piechart.setFontSize(returnPixels(12.0f));
    } else
        draw_piechart = new piechart(this, returnPixels(150.0f)); // to draw the piechart

    draw_piechart.onStart(100, 0);

    add_pic_g = new AndroidCustomGallery(this); // on 3/19/2012s

    answer_arr = new Vector<Integer>();
    rating_arr = new Vector<Integer>();
    my_score = new Vector<Integer>();
    right_answer = new Vector<Integer>();

    score_winner_name = new Vector<String>();
    rating_winner_name = new Vector<String>();
    final_avg_ratings = new Vector<String>();
    r_answer_percents = new Vector<String>();

    // connection_created = false;
    _act = this;

    chkimg = 0; // no image
    image_qa = null;

    student = null; // student communicator is created by make_connection()

    // Adding quick action menu
    image_quickaction();

    MY_IP = get_IP();

    getStoredFileURL();
    create_connection();
    show_todo_view();

    // student.send_initial_message();
    uploadErrorLog(cururi);
}

From source file:de.Maxr1998.xposed.maxlock.ui.LockFragment.java

private void setupPatternLayout() {
    // Pattern View
    lockPatternView = (LockPatternView) rootView.findViewById(R.id.pattern_view);
    // Pattern Listener
    patternListener = new LockPatternView.OnPatternListener() {
        @Override//ww  w. j  a v a 2s  . c  o  m
        public void onPatternStart() {
            lockPatternView.removeCallbacks(mLockPatternViewReloader);
        }

        @Override
        public void onPatternCleared() {
            lockPatternView.removeCallbacks(mLockPatternViewReloader);
            lockPatternView.setDisplayMode(LockPatternView.DisplayMode.Correct);
        }

        @Override
        public void onPatternCellAdded(List<LockPatternView.Cell> pattern) {

        }

        @Override
        public void onPatternDetected(List<LockPatternView.Cell> pattern) {
            key.setLength(0);
            key.append(pattern);
            if (!checkInput()) {
                lockPatternView.setDisplayMode(LockPatternView.DisplayMode.Wrong);
                lockPatternView.postDelayed(mLockPatternViewReloader, DateUtils.SECOND_IN_MILLIS);
            }
        }
    };
    // Layout
    switch (getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) {
    case Configuration.SCREENLAYOUT_SIZE_LARGE:
    case Configuration.SCREENLAYOUT_SIZE_XLARGE: {
        final int size = getResources().getDimensionPixelSize(
                com.haibison.android.lockpattern.R.dimen.alp_42447968_lockpatternview_size);
        ViewGroup.LayoutParams lp = lockPatternView.getLayoutParams();
        lp.width = size;
        lp.height = size;
        lockPatternView.setLayoutParams(lp);
        break;
    }
    }
    lockPatternView.setOnPatternListener(patternListener);
    lockPatternView.setInStealthMode(!prefs.getBoolean(Common.PATTERN_SHOW_PATH, true));
    lockPatternView.setTactileFeedbackEnabled(prefs.getBoolean(Common.PATTERN_FEEDBACK, true));
}

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;
    }/*from   www.  j  a va2  s .  co m*/

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

    return false;
}

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

/**
 * Initializes UI.../*from  ww  w.j  ava  2  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   w w w .j  a v a  2  s .  c om*/
    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 {/*w w  w.  ja  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  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.         
 *///from  w w w . j a  va 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);
    }
}