Example usage for android.view Gravity START

List of usage examples for android.view Gravity START

Introduction

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

Prototype

int START

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

Click Source Link

Document

Push object to x-axis position at the start of its container, not changing its size.

Usage

From source file:com.mishiranu.dashchan.ui.navigator.NavigatorActivity.java

private void handleDataAfterAnimation(PageHolder.Content content, String chanName, String boardName,
        String threadNumber, String postNumber, String threadTitle, String searchQuery, boolean fromCache,
        boolean animated, boolean returnable) {
    clearListAnimator();//from w  w w. j a v  a  2 s  . co  m
    allowScaleAnimation = animated;
    setActionBarLocked(LOCKER_HANDLE, false);
    watcherServiceClient.updateConfiguration(chanName);
    drawerForm.updateConfiguration(chanName);
    page = pageManager.newPage(content);
    sendPrepareMenuToPage = false; // Will be changed in onCreateOptionsMenu
    PageHolder pageHolder = null;
    switch (content) {
    case THREADS: {
        pageHolder = pageManager.add(content, chanName, boardName, null, null, null)
                .setInitialThreadsData(fromCache);
        break;
    }
    case POSTS: {
        pageHolder = pageManager.add(content, chanName, boardName, threadNumber, threadTitle, null)
                .setInitialPostsData(fromCache, postNumber);
        break;
    }
    case SEARCH: {
        pageHolder = pageManager.add(content, chanName, boardName, null, null, searchQuery)
                .setInitialSearchData(fromCache);
        break;
    }
    case ARCHIVE:
    case ALL_BOARDS:
    case USER_BOARDS:
    case HISTORY: {
        pageHolder = pageManager.add(content, chanName, boardName, null, null, null);
        break;
    }
    }
    if (pageHolder == null) {
        throw new RuntimeException();
    }
    pageHolder.returnable = returnable;
    uiManager.view().resetPages();
    page.init(this, this, pageHolder, listView, uiManager, actionIconSet);
    if (!wideMode && !drawerLayout.isDrawerOpen(Gravity.START)) {
        drawerListView.setSelection(0);
    }
    setSearchMode(false);
    invalidateOptionsMenu();
    invalidateHomeUpState();
    notifyTitleChanged();
    allowScaleAnimation = true;
}

From source file:com.github.howeyc.slideshow.activities.MainActivity.java

private void tutorial() {
    if (!AppData.getTutorial()) {
        return;//from w  w  w  .  ja v  a2  s  .co m
    }
    AlertDialog.Builder click_on_settings_dialog_builder = new AlertDialog.Builder(MainActivity.this);
    click_on_settings_dialog_builder.setMessage(R.string.main_dialog_tutorial_text)
            .setPositiveButton(R.string.main_dialog_tutorial_okButton, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialogInterface, int i) {
                }
            }).setNeutralButton(R.string.main_dialog_tutorial_dontShowAgainButton,
                    new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialogInterface, int i) {
                            AppData.setTutorial(false);
                        }
                    })
            .setNegativeButton(R.string.main_dialog_tutorial_openSettingsNowButton,
                    new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialogInterface, int i) {
                            dialogInterface.dismiss();
                            startActivity(getSettingsActivityIntent());
                        }
                    });
    click_on_settings_dialog = click_on_settings_dialog_builder.create();
    click_on_settings_dialog.getWindow().setGravity(Gravity.TOP | Gravity.START);
    click_on_settings_dialog.setCancelable(true);
    click_on_settings_dialog.show();
    showActionBar();
}

From source file:cz.metaverse.android.bilingualreader.ReaderActivity.java

/**
 * Called when user presses any button inside the navigation drawer.
 *//*from  w  w  w  . ja  v a2  s.c o  m*/
public void onDrawerButtonClicked(View view) {
    // Handle the pressed navigation drawer button.
    switch (view.getId()) {

    // Book title 1 - open Table of Contents
    case R.id.drawer_book_title_1_button:
        if (!governor.getPanelHolder(0).displayToC()) {
            errorMessage(getString(R.string.error_tocNotFound));
        }
        break;

    // Open book 1
    case R.id.drawer_open_book_1_button:
        startOpenFileActivity(0);
        break;

    // Book title 2 - open Table of Contents
    case R.id.drawer_book_title_2_button:
        // If two books are open or if we're reading a bilingual book
        if (!governor.exactlyOneBookOpen() || governor.isReadingBilingualEbook()) {
            // Open ToC of the second book
            if (!governor.getPanelHolder(1).displayToC()) {
                errorMessage(getString(R.string.error_tocNotFound));
            }
        } else {
            // If only one non-bilingual book is opened, act like open_book_2_button.
            startOpenFileActivity(1);
        }
        break;

    // Open book 2
    case R.id.drawer_open_book_2_button:
        startOpenFileActivity(1);
        break;

    // Close panel
    case R.id.drawer_close_panel_button:
        new CloseOrHidePanelDialog(true).show(getFragmentManager(), "close_or_hide_panel_dialog");
        break;

    // Hide panel / Reappear panel
    case R.id.drawer_hide_panel_button:
        if (governor.isAnyPanelHidden()) {
            // Reappear (un-hide) the hidden panel.
            governor.reappearPanel();

        } else if (governor.isOnlyOnePanelOpen()) {
            // Can't hide the only open panel.
            Toast.makeText(this, R.string.Cannot_hide_the_only_open_panel, Toast.LENGTH_SHORT).show();

        } else {
            // Open a HidePanelDialog.
            new CloseOrHidePanelDialog(false).show(getFragmentManager(), "close_or_hide_panel_dialog");
        }
        break;

    // SRS Database
    case R.id.drawer_SRS_database_button:
        startActivityForResult(new Intent(this, SRSDatabaseActivity.class), ACTIVITY_RESULT_SRS_DATABASE);
        break;

    // Dictionary
    case R.id.drawer_dictionary_button:
        openSettings();
        break;

    // Would You Like To Know More? - Info Texts
    case R.id.drawer_infotext_button:
        new InfotextBrowserDialog().show(getFragmentManager(), "InfotextBrowserDialog");
        break;

    // Visual Options
    case R.id.drawer_visual_options_button:
        new VisualOptionsDialog().show(getFragmentManager(), "InfotextBrowserDialog");
        break;

    // Exit
    case R.id.drawer_exit_button:
        finish();
        break;
    }

    navigationDrawerLayout.closeDrawer(Gravity.START);
}

From source file:android.support.v17.leanback.app.OnboardingSupportFragment.java

/**
 * Called when the page changes./*from  w w  w . ja  va2s  . co  m*/
 */
private void onPageChangedInternal(int previousPage) {
    if (mAnimator != null) {
        mAnimator.end();
    }
    mPageIndicator.onPageSelected(mCurrentPageIndex, true);

    List<Animator> animators = new ArrayList<>();
    // Header animation
    Animator fadeAnimator = null;
    if (previousPage < getCurrentPageIndex()) {
        // sliding to left
        animators.add(createAnimator(mTitleView, false, Gravity.START, 0));
        animators.add(fadeAnimator = createAnimator(mDescriptionView, false, Gravity.START,
                DESCRIPTION_START_DELAY_MS));
        animators.add(createAnimator(mTitleView, true, Gravity.END, HEADER_APPEAR_DELAY_MS));
        animators.add(createAnimator(mDescriptionView, true, Gravity.END,
                HEADER_APPEAR_DELAY_MS + DESCRIPTION_START_DELAY_MS));
    } else {
        // sliding to right
        animators.add(createAnimator(mTitleView, false, Gravity.END, 0));
        animators.add(fadeAnimator = createAnimator(mDescriptionView, false, Gravity.END,
                DESCRIPTION_START_DELAY_MS));
        animators.add(createAnimator(mTitleView, true, Gravity.START, HEADER_APPEAR_DELAY_MS));
        animators.add(createAnimator(mDescriptionView, true, Gravity.START,
                HEADER_APPEAR_DELAY_MS + DESCRIPTION_START_DELAY_MS));
    }
    final int currentPageIndex = getCurrentPageIndex();
    fadeAnimator.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            mTitleView.setText(getPageTitle(currentPageIndex));
            mDescriptionView.setText(getPageDescription(currentPageIndex));
        }
    });

    // Animator for switching between page indicator and button.
    if (getCurrentPageIndex() == getPageCount() - 1) {
        mStartButton.setVisibility(View.VISIBLE);
        Animator navigatorFadeOutAnimator = AnimatorInflater.loadAnimator(getActivity(),
                R.animator.lb_onboarding_page_indicator_fade_out);
        navigatorFadeOutAnimator.setTarget(mPageIndicator);
        navigatorFadeOutAnimator.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                mPageIndicator.setVisibility(View.GONE);
            }
        });
        animators.add(navigatorFadeOutAnimator);
        Animator buttonFadeInAnimator = AnimatorInflater.loadAnimator(getActivity(),
                R.animator.lb_onboarding_start_button_fade_in);
        buttonFadeInAnimator.setTarget(mStartButton);
        animators.add(buttonFadeInAnimator);
    } else if (previousPage == getPageCount() - 1) {
        mPageIndicator.setVisibility(View.VISIBLE);
        Animator navigatorFadeInAnimator = AnimatorInflater.loadAnimator(getActivity(),
                R.animator.lb_onboarding_page_indicator_fade_in);
        navigatorFadeInAnimator.setTarget(mPageIndicator);
        animators.add(navigatorFadeInAnimator);
        Animator buttonFadeOutAnimator = AnimatorInflater.loadAnimator(getActivity(),
                R.animator.lb_onboarding_start_button_fade_out);
        buttonFadeOutAnimator.setTarget(mStartButton);
        buttonFadeOutAnimator.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                mStartButton.setVisibility(View.GONE);
            }
        });
        animators.add(buttonFadeOutAnimator);
    }
    mAnimator = new AnimatorSet();
    mAnimator.playTogether(animators);
    mAnimator.start();
    onPageChanged(mCurrentPageIndex, previousPage);
}

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

/**
 * Modify various attributes of the SuperActivityToast before being shown.
 *///  w ww .  j a  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:fr.paug.droidcon.ui.BaseActivity.java

private void populateAccountList(List<Account> accounts) {
    mAccountListContainer.removeAllViews();

    LayoutInflater layoutInflater = LayoutInflater.from(this);
    for (Account account : accounts) {
        View itemView = layoutInflater.inflate(R.layout.list_item_account, mAccountListContainer, false);
        ((TextView) itemView.findViewById(R.id.profile_email_text)).setText(account.name);
        final String accountName = account.name;
        itemView.setOnClickListener(new View.OnClickListener() {
            @Override//  w  w w .ja  v a 2 s .  c  o  m
            public void onClick(View view) {
                ConnectivityManager cm = (ConnectivityManager) getSystemService(CONNECTIVITY_SERVICE);
                NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
                if (activeNetwork == null || !activeNetwork.isConnected()) {
                    // if there's no network, don't try to change the selected account
                    Toast.makeText(BaseActivity.this, R.string.no_connection_cant_login, Toast.LENGTH_SHORT)
                            .show();
                    mDrawerLayout.closeDrawer(Gravity.START);
                    return;
                } else {
                    LOGD(TAG, "User requested switch to account: " + accountName);
                    AccountUtils.setActiveAccount(BaseActivity.this, accountName);
                    onAccountChangeRequested();
                    startLoginProcess();
                    mAccountBoxExpanded = false;
                    setupAccountBoxToggle();
                    mDrawerLayout.closeDrawer(Gravity.START);
                    setupAccountBox();
                }
            }
        });
        mAccountListContainer.addView(itemView);
    }
}

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

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

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

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

From source file:com.android.launcher3.allapps.AllAppsGridAdapter.java

@Override
public void onBindViewHolder(ViewHolder holder, int position) {
    switch (holder.getItemViewType()) {
    case ICON_VIEW_TYPE: {
        AppInfo info = mApps.getAdapterItems().get(position).appInfo;
        BubbleTextView icon = (BubbleTextView) holder.mContent;
        icon.applyFromApplicationInfo(info);
        icon.setAccessibilityDelegate(LauncherAppState.getInstance().getAccessibilityDelegate());
        break;//from  w w w  .j av a 2s  . c  o m
    }
    case PREDICTION_ICON_VIEW_TYPE: {
        AppInfo info = mApps.getAdapterItems().get(position).appInfo;
        BubbleTextView icon = (BubbleTextView) holder.mContent;
        icon.applyFromApplicationInfo(info);
        icon.setAccessibilityDelegate(LauncherAppState.getInstance().getAccessibilityDelegate());
        break;
    }
    case EMPTY_SEARCH_VIEW_TYPE:
        TextView emptyViewText = (TextView) holder.mContent;
        emptyViewText.setText(mEmptySearchMessage);
        emptyViewText.setGravity(
                mApps.hasNoFilteredResults() ? Gravity.CENTER : Gravity.START | Gravity.CENTER_VERTICAL);
        break;
    case SEARCH_MARKET_VIEW_TYPE:
        TextView searchView = (TextView) holder.mContent;
        if (mMarketSearchIntent != null) {
            searchView.setVisibility(View.VISIBLE);
            searchView.setContentDescription(mMarketSearchMessage);
            searchView.setGravity(
                    mApps.hasNoFilteredResults() ? Gravity.CENTER : Gravity.START | Gravity.CENTER_VERTICAL);
            searchView.setText(mMarketSearchMessage);
        } else {
            searchView.setVisibility(View.GONE);
        }
        break;
    }
    if (mBindViewCallback != null) {
        mBindViewCallback.onBindView(holder);
    }
}