Example usage for android.widget ImageView setAlpha

List of usage examples for android.widget ImageView setAlpha

Introduction

In this page you can find the example usage for android.widget ImageView setAlpha.

Prototype

@Deprecated
@RemotableViewMethod
public void setAlpha(int alpha) 

Source Link

Document

Sets the alpha value that should be applied to the image.

Usage

From source file:com.github.antoniodisanto92.swipeselector.SwipeAdapter.java

@SuppressWarnings("deprecation")
private void setAlpha(float alpha, ImageView button) {
    if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        button.setAlpha(alpha);
    } else {// w w  w  .jav a2 s .  c o  m
        button.setAlpha((int) (alpha * 255));
    }
}

From source file:jahirfiquitiva.iconshowcase.activities.ShowcaseActivity.java

public static void setupToolbarHeader(Context context, ImageView toolbarHeader) {

    if (themeMode) {
        wallpaperDrawable = ContextCompat.getDrawable(context, R.drawable.heroimage);
        toolbarHeader.setImageDrawable(wallpaperDrawable);
        toolbarHeaderImage = Utils.drawableToBitmap(wallpaperDrawable);
    } else if (ENABLE_USER_WALLPAPER_IN_TOOLBAR && mPrefs.getWallpaperAsToolbarHeaderEnabled()) {
        WallpaperManager wm = WallpaperManager.getInstance(context);

        if (wm != null) {
            Drawable currentWallpaper = wm.getFastDrawable();
            if (currentWallpaper != null) {
                toolbarHeader.setAlpha(0.9f);
                toolbarHeader.setImageDrawable(currentWallpaper);
                wallpaperDrawable = currentWallpaper;
                toolbarHeaderImage = Utils.drawableToBitmap(currentWallpaper);
            }/*www .  j a  v  a2 s . co m*/
        }
    } else {
        String[] wallpapers = context.getResources().getStringArray(R.array.wallpapers);

        if (wallpapers.length > 0) {
            int res;
            ArrayList<Integer> wallpapersArray = new ArrayList<>();

            for (String wallpaper : wallpapers) {
                res = context.getResources().getIdentifier(wallpaper, "drawable", context.getPackageName());
                if (res != 0) {
                    final int thumbRes = context.getResources().getIdentifier(wallpaper, "drawable",
                            context.getPackageName());
                    if (thumbRes != 0) {
                        wallpapersArray.add(thumbRes);
                    }
                }
            }

            Random random = new Random();

            if (wallpaper == -1) {
                wallpaper = random.nextInt(wallpapersArray.size());
            }

            wallpaperDrawable = ContextCompat.getDrawable(context, wallpapersArray.get(wallpaper));
            toolbarHeader.setImageDrawable(wallpaperDrawable);
            toolbarHeaderImage = Utils
                    .drawableToBitmap(ContextCompat.getDrawable(context, wallpapersArray.get(wallpaper)));
        }
    }

    toolbarHeader.setVisibility(View.VISIBLE);
}

From source file:net.henryco.opalette.application.StartUpActivity.java

private void initSplash() {
    findViewById(R.id.startUpAdViewBottom).setVisibility(View.GONE);
    findViewById(R.id.imageButtonGall).setVisibility(View.GONE);
    findViewById(R.id.textView).setVisibility(View.GONE);
    findViewById(R.id.firstPickLayout).setVisibility(View.GONE);
    ImageView logo = (ImageView) findViewById(R.id.logoImageVIew);
    logo.setVisibility(View.VISIBLE);

    new Thread(() -> {
        long t0 = System.currentTimeMillis();
        while (System.currentTimeMillis() < t0 + SPLASH_LOADING_TIME) {
            synchronized (this) {
                try {
                    float nt = ((float) (System.currentTimeMillis() - t0) / SPLASH_LOADING_TIME);
                    logo.setAlpha((float) Math.min(1., Math.sin(Math.PI * nt) * 1.25));
                    Thread.sleep(1);
                } catch (Exception ignored) {
                }/*from w w w  .ja va 2 s .  c o m*/
            }
        }
        runOnUiThread(() -> {
            logo.setVisibility(View.GONE);
            loadAfterSplash();
        });
    }).start();
}

From source file:com.conferenceengineer.android.iosched.ui.SessionDetailFragment.java

@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
private void setOrAnimateIconTo(final ImageView imageView, final int imageResId, boolean animate) {
    if (UIUtils.hasICS() && imageView.getTag() != null) {
        if (imageView.getTag() instanceof Animator) {
            Animator anim = (Animator) imageView.getTag();
            anim.end();/*from w  ww .j  ava2 s. c  o  m*/
            imageView.setAlpha(1f);
        }
    }

    animate = animate && UIUtils.hasICS();
    if (animate) {
        int duration = getResources().getInteger(android.R.integer.config_shortAnimTime);

        Animator outAnimator = ObjectAnimator.ofFloat(imageView, View.ALPHA, 0f);
        outAnimator.setDuration(duration / 2);
        outAnimator.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                imageView.setImageResource(imageResId);
            }
        });

        AnimatorSet inAnimator = new AnimatorSet();
        inAnimator.setDuration(duration);
        inAnimator.playTogether(ObjectAnimator.ofFloat(imageView, View.ALPHA, 1f),
                ObjectAnimator.ofFloat(imageView, View.SCALE_X, 0f, 1f),
                ObjectAnimator.ofFloat(imageView, View.SCALE_Y, 0f, 1f));

        AnimatorSet set = new AnimatorSet();
        set.playSequentially(outAnimator, inAnimator);
        set.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                imageView.setTag(null);
            }
        });
        imageView.setTag(set);
        set.start();
    } else {
        mHandler.post(new Runnable() {
            @Override
            public void run() {
                imageView.setImageResource(imageResId);
            }
        });
    }
}

From source file:com.benefit.buy.library.viewpagerindicator.PagerSlidingTabStrip.java

@SuppressLint("NewApi")
private void updateTabStyles() {
    for (int i = 0; i < tabCount; i++) {
        View v = tabsContainer.getChildAt(i);
        v.setBackgroundResource(tabBackgroundResId);
        if (v instanceof TextView) {
            TextView tab = (TextView) v;
            tab.setTextSize(TypedValue.COMPLEX_UNIT_PX, tabTextSize);
            tab.setTypeface(tabTypeface, tabTypefaceStyle);
            tab.setTextColor(tabTextColor);
            // setAllCaps() is only available from API 14, so the upper case is made manually if we are on a
            // pre-ICS-build
            if (textAllCaps) {
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
                    tab.setAllCaps(true);
                } else {
                    tab.setText(tab.getText().toString().toUpperCase(locale));
                }//w ww .j a  va 2 s.  com
            }
            if (i == selectedPosition) {
                tab.setTextColor(selectedTabTextColor);
            }
        } else {
            View vImg = v.findViewById(R.id.img_click);
            View vText = v.findViewById(R.id.tab_name);
            if (vText instanceof TextView) {
                TextView tab = (TextView) vText;
                tab.setTextSize(TypedValue.COMPLEX_UNIT_PX, tabTextSize);
                tab.setTypeface(tabTypeface, tabTypefaceStyle);
                tab.setTextColor(tabTextColor);
                // setAllCaps() is only available from API 14, so the upper case is made manually if we are on a
                // pre-ICS-build
                if (textAllCaps) {
                    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
                        tab.setAllCaps(true);
                    } else {
                        tab.setText(tab.getText().toString().toUpperCase(locale));
                    }
                }
            }
            if (vImg instanceof ImageView) {
                ImageView img = (ImageView) vImg;
                if (VERSION.SDK_INT >= VERSION_CODES.HONEYCOMB) {
                    if ((i == selectedPosition) || (i == (selectedPosition + 1))
                            || (i == (selectedPosition - 1))) {
                        //                    tab.setTextColor(selectedTabTextColor);
                        img.setAlpha(0f);
                        img.setVisibility(View.VISIBLE);
                    } else {
                        img.setVisibility(View.INVISIBLE);
                    }
                } else {
                    if ((i == selectedPosition)) {
                        //                    tab.setTextColor(selectedTabTextColor);
                        img.setVisibility(View.VISIBLE);
                    } else {
                        img.setVisibility(View.INVISIBLE);
                    }
                }
            }
        }
    }
}

From source file:jahirfiquitiva.iconshowcase.utilities.color.ToolbarTinter.java

private void colorOverflowMenuItem(ImageView overflow) {
    if (overflow != null) {
        if (overflowDrawableId != null) {
            overflow.setImageResource(overflowDrawableId);
        }//from  w w w .  jav  a 2 s .  c  o m
        if (iconsColor != null) {
            overflow.setColorFilter(iconsColor);
        }
        if (iconsAlpha == null) {
            iconsAlpha = 255;
        }
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
            overflow.setImageAlpha(iconsAlpha);
        } else {
            overflow.setAlpha(iconsAlpha);
        }
    }
}

From source file:com.gdgdevfest.android.apps.devfestbcn.ui.SessionDetailFragment.java

@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
private void setOrAnimateIconTo(final ImageView imageView, final int imageResId, boolean animate) {
    if (UIUtils.hasICS() && imageView.getTag() != null) {
        if (imageView.getTag() instanceof Animator) {
            Animator anim = (Animator) imageView.getTag();
            anim.end();//from   ww  w.  jav a  2s .  c  o m
            imageView.setAlpha(1f);
        }
    }

    animate = animate && UIUtils.hasICS();
    if (animate) {
        int duration = getResources().getInteger(android.R.integer.config_shortAnimTime);

        Animator outAnimator = ObjectAnimator.ofFloat(imageView, View.ALPHA, 0f);
        outAnimator.setDuration(duration / 2);
        outAnimator.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                imageView.setImageResource(imageResId);
            }
        });

        AnimatorSet inAnimator = new AnimatorSet();
        outAnimator.setDuration(duration);
        inAnimator.playTogether(ObjectAnimator.ofFloat(imageView, View.ALPHA, 1f),
                ObjectAnimator.ofFloat(imageView, View.SCALE_X, 0f, 1f),
                ObjectAnimator.ofFloat(imageView, View.SCALE_Y, 0f, 1f));

        AnimatorSet set = new AnimatorSet();
        set.playSequentially(outAnimator, inAnimator);
        set.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                imageView.setTag(null);
            }
        });
        imageView.setTag(set);
        set.start();
    } else {
        mHandler.post(new Runnable() {
            @Override
            public void run() {
                imageView.setImageResource(imageResId);
            }
        });
    }
}

From source file:com.arlib.floatingsearchviewdemo.MainActivity.java

private void setupFloatingSearch() {
    mSearchView.setOnQueryChangeListener(new FloatingSearchView.OnQueryChangeListener() {

        @Override//from w  w  w  . j a va2 s. c  om
        public void onSearchTextChanged(String oldQuery, final String newQuery) {

            if (!oldQuery.equals("") && newQuery.equals("")) {
                mSearchView.clearSuggestions();
            } else {

                //this shows the top left circular progress
                //you can call it where ever you want, but
                //it makes sense to do it when loading something in
                //the background.
                mSearchView.showProgress();

                //simulates a query call to a data source
                //with a new query.
                DataHelper.findSuggestions(MainActivity.this, newQuery, 5, FIND_SUGGESTION_SIMULATED_DELAY,
                        new DataHelper.OnFindSuggestionsListener() {

                            @Override
                            public void onResults(List<ColorSuggestion> results) {

                                //this will swap the data and
                                //render the collapse/expand animations as necessary
                                mSearchView.swapSuggestions(results);

                                //let the users know that the background
                                //process has completed
                                mSearchView.hideProgress();
                            }
                        });
            }

            Log.d(TAG, "onSearchTextChanged()");
        }
    });

    mSearchView.setOnSearchListener(new FloatingSearchView.OnSearchListener() {
        @Override
        public void onSuggestionClicked(SearchSuggestion searchSuggestion) {

            ColorSuggestion colorSuggestion = (ColorSuggestion) searchSuggestion;
            DataHelper.findColors(MainActivity.this, colorSuggestion.getBody(),
                    new DataHelper.OnFindColorsListener() {

                        @Override
                        public void onResults(List<ColorWrapper> results) {
                            mSearchResultsAdapter.swapData(results);
                        }

                    });
            Log.d(TAG, "onSuggestionClicked()");
        }

        @Override
        public void onSearchAction(String query) {

            DataHelper.findColors(MainActivity.this, query, new DataHelper.OnFindColorsListener() {

                @Override
                public void onResults(List<ColorWrapper> results) {
                    mSearchResultsAdapter.swapData(results);
                }

            });
            Log.d(TAG, "onSearchAction()");
        }
    });

    mSearchView.setOnFocusChangeListener(new FloatingSearchView.OnFocusChangeListener() {
        @Override
        public void onFocus() {
            mSearchView.clearQuery();

            //show suggestions when search bar gains focus (typically history suggestions)
            mSearchView.swapSuggestions(DataHelper.getHistory(MainActivity.this, 3));

            Log.d(TAG, "onFocus()");
        }

        @Override
        public void onFocusCleared() {

            Log.d(TAG, "onFocusCleared()");
        }
    });

    //handle menu clicks the same way as you would
    //in a regular activity
    mSearchView.setOnMenuItemClickListener(new FloatingSearchView.OnMenuItemClickListener() {
        @Override
        public void onActionMenuItemSelected(MenuItem item) {

            if (item.getItemId() == R.id.action_change_colors) {

                mIsDarkSearchTheme = true;

                //demonstrate setting colors for items
                mSearchView.setBackgroundColor(Color.parseColor("#787878"));
                mSearchView.setViewTextColor(Color.parseColor("#e9e9e9"));
                mSearchView.setHintTextColor(Color.parseColor("#e9e9e9"));
                mSearchView.setActionMenuOverflowColor(Color.parseColor("#e9e9e9"));
                mSearchView.setMenuItemIconColor(Color.parseColor("#e9e9e9"));
                mSearchView.setLeftActionIconColor(Color.parseColor("#e9e9e9"));
                mSearchView.setClearBtnColor(Color.parseColor("#e9e9e9"));
                mSearchView.setDividerColor(Color.parseColor("#BEBEBE"));
                mSearchView.setLeftActionIconColor(Color.parseColor("#e9e9e9"));
            } else {

                //just print action
                Toast.makeText(getApplicationContext(), item.getTitle(), Toast.LENGTH_SHORT).show();
            }

        }
    });

    //use this listener to listen to menu clicks when app:floatingSearch_leftAction="showHamburger"
    mSearchView.setOnLeftMenuClickListener(new FloatingSearchView.OnLeftMenuClickListener() {
        @Override
        public void onMenuOpened() {

            Log.d(TAG, "onMenuOpened()");
            mDrawerLayout.openDrawer(GravityCompat.START);
        }

        @Override
        public void onMenuClosed() {
            Log.d(TAG, "onMenuClosed()");
        }
    });

    //use this listener to listen to menu clicks when app:floatingSearch_leftAction="showHome"
    mSearchView.setOnHomeActionClickListener(new FloatingSearchView.OnHomeActionClickListener() {
        @Override
        public void onHomeClicked() {

            Log.d(TAG, "onHomeClicked()");
        }
    });

    /*
     * Here you have access to the left icon and the text of a given suggestion
     * item after as it is bound to the suggestion list. You can utilize this
     * callback to change some properties of the left icon and the text. For example, you
     * can load the left icon images using your favorite image loading library, or change text color.
     *
     *
     * Important:
     * Keep in mind that the suggestion list is a RecyclerView, so views are reused for different
     * items in the list.
     */
    mSearchView.setOnBindSuggestionCallback(new SearchSuggestionsAdapter.OnBindSuggestionCallback() {
        @Override
        public void onBindSuggestion(View suggestionView, ImageView leftIcon, TextView textView,
                SearchSuggestion item, int itemPosition) {
            ColorSuggestion colorSuggestion = (ColorSuggestion) item;

            String textColor = mIsDarkSearchTheme ? "#ffffff" : "#000000";
            String textLight = mIsDarkSearchTheme ? "#bfbfbf" : "#787878";

            if (colorSuggestion.getIsHistory()) {
                leftIcon.setImageDrawable(
                        ResourcesCompat.getDrawable(getResources(), R.drawable.ic_history_black_24dp, null));

                Util.setIconColor(leftIcon, Color.parseColor(textColor));
                leftIcon.setAlpha(.36f);
            } else {
                leftIcon.setAlpha(0.0f);
                leftIcon.setImageDrawable(null);
            }

            textView.setTextColor(Color.parseColor(textColor));
            String text = colorSuggestion.getBody().replaceFirst(mSearchView.getQuery(),
                    "<font color=\"" + textLight + "\">" + mSearchView.getQuery() + "</font>");
            textView.setText(Html.fromHtml(text));
        }

    });

    //listen for when suggestion list expands/shrinks in order to move down/up the
    //search results list
    mSearchView.setOnSuggestionsListHeightChanged(new FloatingSearchView.OnSuggestionsListHeightChanged() {
        @Override
        public void onSuggestionsListHeightChanged(float newHeight) {
            mSearchResultsList.setTranslationY(newHeight);
        }
    });
}

From source file:co.carlosjimenez.android.currencyalerts.app.MenuTint.java

private void colorOverflowMenuItem(ImageView overflow) {
    if (overflow != null) {
        if (overflowDrawableId != null) {
            overflow.setImageResource(overflowDrawableId);
        }/*from ww w .  j av a  2  s  .  c  o m*/
        if (menuItemIconColor != null) {
            overflow.setColorFilter(menuItemIconColor);
        }
        if (menuItemIconAlpha != null) {
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
                overflow.setImageAlpha(menuItemIconAlpha);
            } else {
                overflow.setAlpha(menuItemIconAlpha);
            }
        }
    }
}

From source file:de.kuschku.util.ui.MenuTint.java

private void colorOverflowMenuItem(ImageView overflow) {
    if (overflow != null) {
        if (overflowDrawableId != null) {
            overflow.setImageResource(overflowDrawableId);
        }//from  w ww  . jav  a  2  s.c om
        if (menuItemIconColor != null) {
            overflow.setColorFilter(menuItemIconColor);
        }
        if (menuItemIconAlpha != null) {
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
                overflow.setImageAlpha(menuItemIconAlpha);
            } else {
                //noinspection deprecation
                overflow.setAlpha(menuItemIconAlpha);
            }
        }
    }
}