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.eng.arab.translator.androidtranslator.activity.NumberViewActivity.java

private void setupFloatingSearch() {
    mSearchView.setOnHomeActionClickListener(new FloatingSearchView.OnHomeActionClickListener() {
        @Override//from www .j ava  2s . c om
        public void onHomeClicked() {

        }
    });

    mSearchView.setOnQueryChangeListener(new FloatingSearchView.OnQueryChangeListener() {

        @Override
        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.
                NumberDataHelper.findSuggestions(getApplicationContext(), newQuery, 5,
                        FIND_SUGGESTION_SIMULATED_DELAY, new NumberDataHelper.OnFindSuggestionsListener() {

                            @Override
                            public void onResults(List<NumberSuggestion> 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(final SearchSuggestion searchSuggestion) {

            NumberSuggestion numberSuggestion = (NumberSuggestion) searchSuggestion;
            NumberDataHelper.findNumbers(getApplicationContext(), numberSuggestion.getWord(),
                    new NumberDataHelper.OnFindNumberListener() {

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

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

            mLastQuery = searchSuggestion.getWord();
        }

        @Override
        public void onSearchAction(String query) {
            mLastQuery = query;

            NumberDataHelper.findNumbers(getApplicationContext(), query,
                    new NumberDataHelper.OnFindNumberListener() {

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

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

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

            //show suggestions when search bar gains focus (typically history suggestions)
            //                NumberDataHelper cdh = new NumberDataHelper();
            //                cdh.setContext(getApplicationContext());
            mSearchView.swapSuggestions(NumberDataHelper.getHistory(getApplicationContext(), 5));

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

        @Override
        public void onFocusCleared() {

            //set the title of the bar so that when focus is returned a new query begins
            mSearchView.setSearchBarTitle(mLastQuery);

            //you can also set setSearchText(...) to make keep the query there when not focused and when focus returns
            //mSearchView.setSearchText(searchSuggestion.getWord());

            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_refresh_list) {

                /*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"));*/
                populateCardList();
            } else if (item.getItemId() == R.id.action_voice_rec) {
                Intent voiceRecognize = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
                voiceRecognize.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE,
                        getClass().getPackage().getName());
                voiceRecognize.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
                        RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
                voiceRecognize.putExtra(RecognizerIntent.EXTRA_LANGUAGE, "ar-EG");
                voiceRecognize.putExtra(RecognizerIntent.EXTRA_PROMPT, "Say the letter in ARABIC...");
                /*voiceRecognize.putExtra(RecognizerIntent.EXTRA_PARTIAL_RESULTS, true); */
                voiceRecognize.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS, 100);
                startActivityForResult(voiceRecognize, REQUEST_CODE);
            } else {

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

        }
    });

    //use this listener to listen to menu clicks when app:floatingSearch_leftAction="showHome"
    mSearchView.setOnHomeActionClickListener(new FloatingSearchView.OnHomeActionClickListener() {
        @Override
        public void onHomeClicked() {
            startActivity(new Intent(NumberViewActivity.this, MainActivity.class)
                    .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP));
            overridePendingTransition(R.anim.left_to_right, R.anim.right_to_left);
            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) {
            NumberSuggestion numberSuggestion = (NumberSuggestion) item;

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

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

                Util.setIconColor(leftIcon, Color.parseColor(textColor));
                leftIcon.setAlpha(.36f);
            } else {
                leftIcon.setImageDrawable(ResourcesCompat.getDrawable(getResources(),
                        R.drawable.ic_lightbulb_outline_black_24dp, null));

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

            textView.setTextColor(Color.parseColor(textColor));
            String text = numberSuggestion.getWord().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:pl.kodujdlapolski.na4lapy.ui.introduction.IntroductionPageTransformer.java

public void transformPage(View view, float position) {
    int pageWidth = view.getWidth();
    View text = view.findViewById(R.id.introduction_text);
    ImageView tut_a_3 = (ImageView) view.findViewById(R.id.tut_a_3);
    ImageView tut_a_2 = (ImageView) view.findViewById(R.id.tut_a_2);

    ImageView tut_b_3 = (ImageView) view.findViewById(R.id.tut_b_3);
    ImageView tut_b_2 = (ImageView) view.findViewById(R.id.tut_b_2);

    ImageView tut_c_2 = (ImageView) view.findViewById(R.id.tut_c_2);
    ImageView tut_c_3 = (ImageView) view.findViewById(R.id.tut_c_3);

    ImageView tut_d_2 = (ImageView) view.findViewById(R.id.tut_d_2);
    ImageView tut_d_3 = (ImageView) view.findViewById(R.id.tut_d_3);
    ImageView tut_d_4 = (ImageView) view.findViewById(R.id.tut_d_4);

    ImageView tut_e_2 = (ImageView) view.findViewById(R.id.tut_e_2);
    ImageView tut_e_3 = (ImageView) view.findViewById(R.id.tut_e_3);
    ImageView tut_e_4 = (ImageView) view.findViewById(R.id.tut_e_4);
    RelativeLayout lastIntroContainer = (RelativeLayout) view.findViewById(R.id.last_intro_container);

    if (position <= -1.0f || position >= 1.0f) {
    } else if (position == 0.0f) {
    } else {//w  w  w  .j  a va  2 s. c o  m
        if (lastIntroContainer != null && position < 0) { // set alpha for fading last element to only one side
            lastIntroContainer.setAlpha(1.0f - Math.abs(position));
        }
        if (text != null) {
            text.setAlpha(1.0f - Math.abs(position));
        }
        if (tut_a_2 != null) {
            tut_a_2.setAlpha(1.0f - Math.abs(position * 2));
            tut_a_2.setTranslationY(pageWidth / 20 * position);
        }
        if (tut_a_3 != null) {
            tut_a_3.setTranslationX(pageWidth / 10 * position);
        }

        if (tut_a_2 != null) {
            tut_a_2.setAlpha(1.0f - Math.abs(position * 2));
        }
        if (tut_b_2 != null) {
            tut_b_2.setAlpha(1.0f - Math.abs(position * 2));
        }
        if (tut_b_3 != null) {
            tut_b_3.setTranslationX(pageWidth / 20 * position * -1);
        }
        if (tut_c_2 != null) {
            tut_c_2.setTranslationX(pageWidth / 20 * position * -1);
        }
        if (tut_c_3 != null) {
            tut_c_3.setTranslationX(pageWidth / 10 * position);
        }
        if (tut_d_2 != null) {
            tut_d_2.setTranslationX(pageWidth / 10 * position * -1);
        }
        if (tut_d_3 != null) {
            tut_d_3.setTranslationX(pageWidth / 10 * position);
        }
        if (tut_d_4 != null) {
            tut_d_4.setAlpha(1.0f - Math.abs(position * 2));
            tut_d_4.setTranslationY(pageWidth / 20 * position);
        }
        if (tut_e_2 != null) {
            tut_e_2.setTranslationX(pageWidth / 10 * position);
        }
        if (tut_e_3 != null) {
            tut_e_3.setTranslationX(pageWidth / 10 * position);
            tut_e_3.setAlpha(1.0f - Math.abs(position));
        }
        if (tut_e_4 != null) {
            tut_e_4.setTranslationY(pageWidth / 20 * position * -1);

        }
    }
}

From source file:br.edu.ifpb.breath.slidingtabs.SlidingTabLayout.java

private void populateTabStrip() {
    final PagerAdapter adapter = mViewPager.getAdapter();
    final OnClickListener tabClickListener = new TabClickListener();

    for (int i = 0; i < adapter.getCount(); i++) {
        View tabView = null;//w  ww.j  a  v  a 2 s .c om
        TextView tabTitleView = null;
        ImageView tabIconView = null;

        if (mTabViewLayoutId != 0) {
            // If there is a custom tab view layout id set, try and inflate it
            tabView = LayoutInflater.from(getContext()).inflate(mTabViewLayoutId, mTabStrip, false);
            tabTitleView = (TextView) tabView.findViewById(mTabViewTextViewId);
            tabIconView = (ImageView) tabView.findViewById(mTabViewImageViewId);
        }

        if (tabView == null && !mUseIcons) {
            tabView = createDefaultTabView(getContext(), 0);
            tabView.setAlpha(i == 0 ? 1.0f : 0.25f);
        }

        if (tabView == null && mUseIcons) {
            tabView = createDefaultTabView(getContext(), 1);
            tabView.setAlpha(i == 0 ? 1.0f : 0.25f);
        }

        if (tabTitleView == null && TextView.class.isInstance(tabView)) {
            tabTitleView = (TextView) tabView;
            tabTitleView.setAlpha(i == 0 ? 1.0f : 0.25f);
        }

        if (tabIconView == null && ImageView.class.isInstance(tabView)) {
            tabIconView = (ImageView) tabView;
            tabIconView.setAlpha(i == 0 ? 1.0f : 0.25f);
        }

        if (mDistributeEvenly) {
            LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) tabView.getLayoutParams();
            lp.width = 0;
            lp.weight = 1;
        }

        if (mUseIcons) {
            tabIconView.setVisibility(View.VISIBLE);
            if (tabTitleView != null)
                tabTitleView.setVisibility(View.GONE);

            if (mIcons.containsKey(i))
                tabIconView.setImageDrawable(mIcons.get(i));
        } else {
            tabTitleView.setVisibility(View.VISIBLE);
            if (tabIconView != null)
                tabIconView.setVisibility(View.GONE);

            tabTitleView.setText(adapter.getPageTitle(i));
            tabTitleView.setTextColor(mTextColor);
        }

        tabView.setOnClickListener(tabClickListener);
        String desc = mContentDescriptions.get(i, null);
        if (desc != null) {
            tabView.setContentDescription(desc);
        }

        mTabStrip.addView(tabView);
        if (i == mViewPager.getCurrentItem()) {
            tabView.setSelected(true);
        }
    }
}

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

@SuppressLint("NewApi")
@Override//from   www  .  j ava2s  . c  o  m
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    if (isInEditMode() || (tabCount == 0)) {
        return;
    }
    final int height = getHeight();
    // draw underline
    rectPaint.setColor(underlineColor);
    canvas.drawRect(0, height - underlineHeight, tabsContainer.getWidth(), height, rectPaint);
    // draw indicator line
    rectPaint.setColor(indicatorColor);
    // default: line below current tab
    View currentTab = tabsContainer.getChildAt(currentPosition);
    float lineLeft = currentTab.getLeft();
    float lineRight = currentTab.getRight();
    // if there is an offset, start interpolating left and right coordinates between current and next tab
    if ((currentPositionOffset > 0f) && (currentPosition < (tabCount - 1))) {
        View nextTab = tabsContainer.getChildAt(currentPosition + 1);
        final float nextTabLeft = nextTab.getLeft();
        final float nextTabRight = nextTab.getRight();
        lineLeft = ((currentPositionOffset * nextTabLeft) + ((1f - currentPositionOffset) * lineLeft));
        lineRight = ((currentPositionOffset * nextTabRight) + ((1f - currentPositionOffset) * lineRight));
    }
    if (currentTab.findViewById(R.id.img_click) != null) {
        int counts = tabsContainer.getChildCount();
        View vNow = currentTab.findViewById(R.id.tab_name);
        ImageView imgNowOn = (ImageView) currentTab.findViewById(R.id.img_click);
        View tabViewNext;
        View vNext;
        ImageView imgNextOn;
        if ((currentPosition + 1) == counts) {
            tabViewNext = tabsContainer.getChildAt(0);
            vNext = tabViewNext.findViewById(R.id.tab_name);
            imgNextOn = (ImageView) tabViewNext.findViewById(R.id.img_click);
        } else {
            tabViewNext = tabsContainer.getChildAt(currentPosition + 1);
            vNext = tabViewNext.findViewById(R.id.tab_name);
            imgNextOn = (ImageView) tabViewNext.findViewById(R.id.img_click);
        }
        int colorTo = ToolColor.getChangeColor(80, 84, 98, 255, 0, 0, currentPositionOffset);
        int colorRe = ToolColor.getChangeColor(255, 0, 0, 80, 84, 98, currentPositionOffset);
        TextView tab = (TextView) vNext;
        TextView tab2 = (TextView) vNow;
        tab.setTextColor(colorTo);
        tab2.setTextColor(colorRe);
        if (VERSION.SDK_INT >= VERSION_CODES.HONEYCOMB) {
            imgNextOn.setAlpha(currentPositionOffset);
            imgNowOn.setAlpha(1 - currentPositionOffset);
        }
    } else {
    }
    canvas.drawRect(lineLeft, height - indicatorHeight, lineRight, height, rectPaint);
    //         draw divider
    dividerPaint.setColor(dividerColor);
    for (int i = 0; i < (tabCount - 1); i++) {
        View tab = tabsContainer.getChildAt(i);
        canvas.drawLine(tab.getRight(), dividerPadding, tab.getRight(), height - dividerPadding, dividerPaint);
    }
}

From source file:com.arlib.floatingsearchview.FloatingSearchView.java

private void changeIcon(ImageView imageView, Drawable newIcon, boolean withAnim) {

    imageView.setImageDrawable(newIcon);
    if (withAnim) {
        ObjectAnimator fadeInVoiceInputOrClear = new ObjectAnimator().ofFloat(imageView, "alpha", 0.0f, 1.0f);
        fadeInVoiceInputOrClear.start();
    } else {//from w  ww.  ja va 2  s  .  co  m
        imageView.setAlpha(1.0f);
    }
}

From source file:com.arlib.floatingsearchview.FloatingSearchView.java

private void changeIcon(ImageView imageView, Drawable newIcon, boolean withAnim) {
    imageView.setImageDrawable(newIcon);
    if (withAnim) {
        ObjectAnimator fadeInVoiceInputOrClear = ObjectAnimator.ofFloat(imageView, "alpha", 0.0f, 1.0f);
        fadeInVoiceInputOrClear.start();
    } else {/*from  w  w  w  . j  a v a2 s  .c  o m*/
        imageView.setAlpha(1.0f);
    }
}

From source file:org.sirimangalo.meditationplus.AdapterMed.java

@Override
public View getView(final int position, View convertView, ViewGroup parent) {

    View rowView;//from w  w w  .  j a v  a 2  s .  co m

    if (convertView == null) {
        LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        rowView = inflater.inflate(R.layout.list_item_med, parent, false);
    } else {
        rowView = convertView;
    }

    JSONObject p = values.get(position);

    TextView walk = (TextView) rowView.findViewById(R.id.one_walking);
    TextView sit = (TextView) rowView.findViewById(R.id.one_sitting);
    ImageView status = (ImageView) rowView.findViewById(R.id.one_status);
    TextView name = (TextView) rowView.findViewById(R.id.one_med);
    ImageView flag = (ImageView) rowView.findViewById(R.id.one_flag);

    View anuView = rowView.findViewById(R.id.anumodana_shell);
    TextView anuText = (TextView) rowView.findViewById(R.id.anumodana);

    try {
        String wo = p.getString("walking");
        String so = p.getString("sitting");
        int wi = Integer.parseInt(wo);
        int si = Integer.parseInt(so);
        int ti = Integer.parseInt(p.getString("start"));
        int ei = Integer.parseInt(p.getString("end"));

        long nowL = System.currentTimeMillis() / 1000;

        int now = (int) nowL;

        boolean finished = false;

        String ws = "0";
        String ss = "0";

        if (ei > now) {

            float secs = now - ti;

            if (secs > wi * 60 || wi == 0) { //walking done
                float ssecs = (int) (secs - (wi * 60));
                if (ssecs < si * 60) // still sitting
                    ss = Integer.toString((int) Math.floor(si - ssecs / 60));
                status.setImageResource(R.drawable.sitting_icon);
            } else { // still walking
                ws = Integer.toString((int) Math.floor(wi - secs / 60));
                ss = so;
                status.setImageResource(R.drawable.walking_icon);
            }

            ws += "/" + wo;
            ss += "/" + so;
        } else {
            ws = wo;
            ss = so;

            double age = 1 - (now - ei) / MAX_AGE;

            String ageColor = Integer.toHexString((int) (255 * age));

            if (ageColor.length() == 1)
                ageColor = "0" + ageColor;

            int alpha = Color.parseColor("#" + ageColor + "000000");

            walk.setTextColor(alpha);
            sit.setTextColor(alpha);
            name.setTextColor(alpha);
            status.setAlpha((float) age);
            flag.setAlpha((float) age);

        }

        walk.setText(ws);
        sit.setText(ss);

        if (p.has("country")) {
            int id = context.getResources().getIdentifier("flag_" + p.getString("country").toLowerCase(),
                    "drawable", context.getPackageName());
            flag.setImageResource(id);
            flag.setVisibility(View.VISIBLE);
        }

        final String username = p.getString("username");
        final String edit = p.getString("can_edit");
        name.setText(username);

        name.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                context.showProfile(username);
            }
        });

        String type = p.getString("type");
        if ("love".equals(type))
            status.setImageResource(R.drawable.love_icon);

        String anu = p.getString("anumodana");
        if (!anu.equals("0"))
            anuText.setText(anu);

        if (p.getString("anu_me").equals("1")) {
            anuText.setTextColor(0xFF00BB00);
            anuText.setTypeface(null, Typeface.BOLD);
        }

        final String sid = p.getString("sid");

        anuView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Log.d(TAG, "anu clicked");
                SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
                String loggedUsername = prefs.getString("username", "");
                String loginToken = prefs.getString("login_token", "");
                ArrayList<NameValuePair> nvp = new ArrayList<NameValuePair>();
                nvp.add(new BasicNameValuePair("form_id", "anumed_" + sid));
                nvp.add(new BasicNameValuePair("login_token", loginToken));
                nvp.add(new BasicNameValuePair("submit", "Refresh"));
                nvp.add(new BasicNameValuePair("username", loggedUsername));
                nvp.add(new BasicNameValuePair("source", "android"));
                PostTaskRunner postTask = new PostTaskRunner(postHandler, context);
                postTask.doPostTask(nvp);

            }
        });

    } catch (Exception e) {
        e.printStackTrace();
    }
    return rowView;
}

From source file:cw.kop.autobackground.sources.SourceListFragment.java

/**
 * Shows LocalImageFragment to view images
 *
 * @param view  source card which was selected
 * @param index position of source in listAdapter
 *///w ww  .  jav  a 2s .  c  om
private void showViewImageFragment(final View view, final int index) {
    sourceList.setOnItemClickListener(null);
    sourceList.setEnabled(false);

    listAdapter.saveData();
    Source item = listAdapter.getItem(index);
    String type = item.getType();
    String directory;
    if (type.equals(AppSettings.FOLDER)) {
        directory = item.getData().split(AppSettings.DATA_SPLITTER)[0];
    } else {
        directory = AppSettings.getDownloadPath() + "/" + item.getTitle() + " " + AppSettings.getImagePrefix();
    }

    Log.i(TAG, "Directory: " + directory);

    final RelativeLayout sourceContainer = (RelativeLayout) view.findViewById(R.id.source_container);
    final ImageView sourceImage = (ImageView) view.findViewById(R.id.source_image);
    final View imageOverlay = view.findViewById(R.id.source_image_overlay);
    final EditText sourceTitle = (EditText) view.findViewById(R.id.source_title);
    final ImageView deleteButton = (ImageView) view.findViewById(R.id.source_delete_button);
    final ImageView viewButton = (ImageView) view.findViewById(R.id.source_view_image_button);
    final ImageView editButton = (ImageView) view.findViewById(R.id.source_edit_button);
    final LinearLayout sourceExpandContainer = (LinearLayout) view.findViewById(R.id.source_expand_container);

    final float viewStartHeight = sourceContainer.getHeight();
    final float viewStartY = view.getY();
    final float overlayStartAlpha = imageOverlay.getAlpha();
    final float listHeight = sourceList.getHeight();
    Log.i(TAG, "listHeight: " + listHeight);
    Log.i(TAG, "viewStartHeight: " + viewStartHeight);

    final LocalImageFragment localImageFragment = new LocalImageFragment();
    Bundle arguments = new Bundle();
    arguments.putString("view_path", directory);
    localImageFragment.setArguments(arguments);

    Animation animation = new Animation() {

        private boolean needsFragment = true;

        @Override
        protected void applyTransformation(float interpolatedTime, Transformation t) {

            if (needsFragment && interpolatedTime >= 1) {
                needsFragment = false;
                getFragmentManager().beginTransaction()
                        .add(R.id.content_frame, localImageFragment, "image_fragment").addToBackStack(null)
                        .setTransition(FragmentTransaction.TRANSIT_NONE).commit();
            }
            ViewGroup.LayoutParams params = sourceContainer.getLayoutParams();
            params.height = (int) (viewStartHeight + (listHeight - viewStartHeight) * interpolatedTime);
            sourceContainer.setLayoutParams(params);
            view.setY(viewStartY - interpolatedTime * viewStartY);
            deleteButton.setAlpha(1.0f - interpolatedTime);
            viewButton.setAlpha(1.0f - interpolatedTime);
            editButton.setAlpha(1.0f - interpolatedTime);
            sourceTitle.setAlpha(1.0f - interpolatedTime);
            imageOverlay.setAlpha(overlayStartAlpha - overlayStartAlpha * (1.0f - interpolatedTime));
            sourceExpandContainer.setAlpha(1.0f - interpolatedTime);
        }

        @Override
        public boolean willChangeBounds() {
            return true;
        }
    };

    animation.setAnimationListener(new Animation.AnimationListener() {
        @Override
        public void onAnimationStart(Animation animation) {
        }

        @Override
        public void onAnimationEnd(Animation animation) {
            if (needsListReset) {
                Parcelable state = sourceList.onSaveInstanceState();
                sourceList.setAdapter(null);
                sourceList.setAdapter(listAdapter);
                sourceList.onRestoreInstanceState(state);
                sourceList.setOnItemClickListener(SourceListFragment.this);
                sourceList.setEnabled(true);
                needsListReset = false;
            }
        }

        @Override
        public void onAnimationRepeat(Animation animation) {

        }
    });

    ValueAnimator cardColorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(),
            AppSettings.getDialogColor(appContext),
            getResources().getColor(AppSettings.getBackgroundColorResource()));
    cardColorAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {

        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            sourceContainer.setBackgroundColor((Integer) animation.getAnimatedValue());
        }

    });

    DecelerateInterpolator decelerateInterpolator = new DecelerateInterpolator(1.5f);

    animation.setDuration(INFO_ANIMATION_TIME);
    cardColorAnimation.setDuration(INFO_ANIMATION_TIME);

    animation.setInterpolator(decelerateInterpolator);
    cardColorAnimation.setInterpolator(decelerateInterpolator);

    needsListReset = true;
    cardColorAnimation.start();
    view.startAnimation(animation);

}

From source file:com.android.launcher2.Workspace.java

void setFadeForOverScroll(float fade) {
    if (!isScrollingIndicatorEnabled())
        return;/*from w  ww  .j  a  v a 2s . c  o m*/

    mOverscrollFade = fade;
    float reducedFade = 0.5f + 0.5f * (1 - fade);
    final ViewGroup parent = (ViewGroup) getParent();
    final ImageView qsbDivider = (ImageView) (parent.findViewById(R.id.qsb_divider));
    final ImageView dockDivider = (ImageView) (parent.findViewById(R.id.dock_divider));
    final View scrollIndicator = getScrollingIndicator();

    cancelScrollingIndicatorAnimations();
    if (qsbDivider != null)
        qsbDivider.setAlpha(reducedFade);
    if (dockDivider != null)
        dockDivider.setAlpha(reducedFade);
    scrollIndicator.setAlpha(1 - fade);
}

From source file:com.android.tv.settings.dialog.old.BaseDialogFragment.java

public void performEntryTransition(final Activity activity, final ViewGroup contentView, int iconResourceId,
        Uri iconResourceUri, final ImageView icon, final TextView title, final TextView description,
        final TextView breadcrumb) {
    // Pull out the root layout of the dialog and set the background drawable, to be
    // faded in during the transition.
    final ViewGroup twoPane = (ViewGroup) contentView.getChildAt(0);
    twoPane.setVisibility(View.INVISIBLE);

    // If the appropriate data is embedded in the intent and there is an icon specified
    // in the content fragment, we animate the icon from its initial position to the final
    // position. Otherwise, we perform a simpler transition in which the ActionFragment
    // slides in and the ContentFragment text fields slide in.
    mIntroAnimationInProgress = true;/*ww  w  . j  a v  a 2  s.  co m*/
    List<TransitionImage> images = TransitionImage.readMultipleFromIntent(activity, activity.getIntent());
    TransitionImageAnimation ltransitionAnimation = null;
    final Uri iconUri;
    final int color;
    if (images != null && images.size() > 0) {
        if (iconResourceId != 0) {
            iconUri = Uri.parse(UriUtils.getAndroidResourceUri(activity, iconResourceId));
        } else if (iconResourceUri != null) {
            iconUri = iconResourceUri;
        } else {
            iconUri = null;
        }
        TransitionImage src = images.get(0);
        color = src.getBackground();
        if (iconUri != null) {
            ltransitionAnimation = new TransitionImageAnimation(contentView);
            ltransitionAnimation.addTransitionSource(src);
            ltransitionAnimation.transitionDurationMs(ANIMATE_IN_DURATION).transitionStartDelayMs(0)
                    .interpolator(new DecelerateInterpolator(1f));
        }
    } else {
        iconUri = null;
        color = 0;
    }
    final TransitionImageAnimation transitionAnimation = ltransitionAnimation;

    // Fade out the old activity, and hard cut the new activity.
    activity.overridePendingTransition(R.anim.hard_cut_in, R.anim.fade_out);

    int bgColor = mFragment.getResources().getColor(R.color.dialog_activity_background);
    mBgDrawable.setColor(bgColor);
    mBgDrawable.setAlpha(0);
    twoPane.setBackground(mBgDrawable);

    // If we're animating the icon, we create a new ImageView in which to place the embedded
    // bitmap. We place it in the root layout to match its location in the previous activity.
    mShadowLayer = (FrameLayoutWithShadows) twoPane.findViewById(R.id.shadow_layout);
    if (transitionAnimation != null) {
        transitionAnimation.listener(new TransitionImageAnimation.Listener() {
            @Override
            public void onRemovedView(TransitionImage src, TransitionImage dst) {
                if (icon != null) {
                    //want to make sure that users still see at least the source image
                    // if the dst image is too large to finish downloading before the
                    // animation is done. Check if the icon is not visible. This mean
                    // BaseContentFragement have not finish downloading the image yet.
                    if (icon.getVisibility() != View.VISIBLE) {
                        icon.setImageDrawable(src.getBitmap());
                        int intrinsicWidth = icon.getDrawable().getIntrinsicWidth();
                        LayoutParams lp = icon.getLayoutParams();
                        lp.height = lp.width * icon.getDrawable().getIntrinsicHeight() / intrinsicWidth;
                        icon.setVisibility(View.VISIBLE);
                    }
                    icon.setAlpha(1f);
                }
                if (mShadowLayer != null) {
                    mShadowLayer.setShadowsAlpha(1f);
                }
                onIntroAnimationFinished();
            }
        });
        icon.setAlpha(0f);
        if (mShadowLayer != null) {
            mShadowLayer.setShadowsAlpha(0f);
        }
    }

    // We need to defer the remainder of the animation preparation until the first
    // layout has occurred, as we don't yet know the final location of the icon.
    twoPane.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
        @Override
        public void onGlobalLayout() {
            twoPane.getViewTreeObserver().removeOnGlobalLayoutListener(this);
            // if we buildLayer() at this time,  the texture is actually not created
            // delay a little so we can make sure all hardware layer is created before
            // animation, in that way we can avoid the jittering of start animation
            twoPane.postOnAnimationDelayed(mEntryAnimationRunnable, ANIMATE_DELAY);
        }

        final Runnable mEntryAnimationRunnable = new Runnable() {
            @Override
            public void run() {
                if (!mFragment.isAdded()) {
                    // We have been detached before this could run, so just bail
                    return;
                }

                twoPane.setVisibility(View.VISIBLE);
                final int secondaryDelay = SLIDE_IN_DISTANCE;

                // Fade in the activity background protection
                ObjectAnimator oa = ObjectAnimator.ofInt(mBgDrawable, "alpha", 255);
                oa.setDuration(ANIMATE_IN_DURATION);
                oa.setStartDelay(secondaryDelay);
                oa.setInterpolator(new DecelerateInterpolator(1.0f));
                oa.start();

                View actionFragmentView = activity.findViewById(mActionAreaId);
                boolean isRtl = ViewCompat.getLayoutDirection(contentView) == ViewCompat.LAYOUT_DIRECTION_RTL;
                int startDist = isRtl ? SLIDE_IN_DISTANCE : -SLIDE_IN_DISTANCE;
                int endDist = isRtl ? -actionFragmentView.getMeasuredWidth()
                        : actionFragmentView.getMeasuredWidth();

                // Fade in and slide in the ContentFragment TextViews from the start.
                prepareAndAnimateView(title, 0, startDist, secondaryDelay, ANIMATE_IN_DURATION,
                        new DecelerateInterpolator(1.0f), false);
                prepareAndAnimateView(breadcrumb, 0, startDist, secondaryDelay, ANIMATE_IN_DURATION,
                        new DecelerateInterpolator(1.0f), false);
                prepareAndAnimateView(description, 0, startDist, secondaryDelay, ANIMATE_IN_DURATION,
                        new DecelerateInterpolator(1.0f), false);

                // Fade in and slide in the ActionFragment from the end.
                prepareAndAnimateView(actionFragmentView, 0, endDist, secondaryDelay, ANIMATE_IN_DURATION,
                        new DecelerateInterpolator(1.0f), false);

                if (icon != null && transitionAnimation != null) {
                    // now we get the icon view in place,  update the transition target
                    TransitionImage target = new TransitionImage();
                    target.setUri(iconUri);
                    target.createFromImageView(icon);
                    if (icon.getBackground() instanceof ColorDrawable) {
                        ColorDrawable d = (ColorDrawable) icon.getBackground();
                        target.setBackground(d.getColor());
                    }
                    transitionAnimation.addTransitionTarget(target);
                    transitionAnimation.startTransition();
                } else if (icon != null) {
                    prepareAndAnimateView(icon, 0, startDist, secondaryDelay, ANIMATE_IN_DURATION,
                            new DecelerateInterpolator(1.0f), true /* is the icon */);
                    if (mShadowLayer != null) {
                        mShadowLayer.setShadowsAlpha(0f);
                    }
                }
            }
        };
    });
}