Example usage for android.view.animation AlphaAnimation AlphaAnimation

List of usage examples for android.view.animation AlphaAnimation AlphaAnimation

Introduction

In this page you can find the example usage for android.view.animation AlphaAnimation AlphaAnimation.

Prototype

public AlphaAnimation(float fromAlpha, float toAlpha) 

Source Link

Document

Constructor to use when building an AlphaAnimation from code

Usage

From source file:adventure_fragments.Climbing.java

@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
        @Nullable Bundle savedInstanceState) {
    final View rootView = inflater.inflate(R.layout.climbing_fragment_layout, container, false);
    this.rootView = rootView;
    db = new DataBaseHelper(getActivity());
    list = db.getAllItemsClimbing();/*from w w w .  ja v a  2 s.  c om*/

    adapt = new CustomAdapter1(getActivity(), R.layout.item_layout, list);
    listItem = (ListView) rootView.findViewById(R.id.listview_climb);
    listItem.setAdapter(adapt);
    nothingtext = (TextView) rootView.findViewById(R.id.nothing_here_climb);
    count = listItem.getCount();
    if (count > 0) {
        nothingtext.setVisibility(View.GONE);
    } else if (count == 0) {
        nothingtext.setVisibility(View.VISIBLE);
    }

    final ImageButton imageButton = (ImageButton) rootView.findViewById(R.id.climb_button);
    listItem.setOnScrollListener(new AbsListView.OnScrollListener() {

        @Override
        public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {

        }

        @Override
        public void onScrollStateChanged(AbsListView view, int scrollState) {
            // TODO Auto-generated method stub
            switch (scrollState) {
            case 2: // SCROLL_STATE_FLING
                //hide button here
                imageButton.setVisibility(View.GONE);
                break;

            case 1: // SCROLL_STATE_TOUCH_SCROLL
                //hide button here
                imageButton.setVisibility(View.GONE);
                break;

            case 0: // SCROLL_STATE_IDLE
                //show button here
                imageButton.setVisibility(View.VISIBLE);
                break;

            default:
                //show button here
                imageButton.setVisibility(View.VISIBLE);
                break;
            }
        }
    });

    imageButton.setOnLongClickListener(new View.OnLongClickListener() {
        @Override
        public boolean onLongClick(View v) {
            CountDownTimer timer = new CountDownTimer(4000, 1000) {

                @Override
                public void onTick(long millisUntilFinished) {
                    imageButton.setVisibility(View.GONE);
                }

                @Override
                public void onFinish() {
                    imageButton.setVisibility(View.VISIBLE);
                }

            };

            timer.start();

            return true;
        }
    });

    imageButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            AddItemNow();
            AlphaAnimation animation1 = new AlphaAnimation(0.2f, 1.0f);
            animation1.setDuration(500);
            imageButton.startAnimation(animation1);

        }
    });

    return rootView;

}

From source file:adventure_fragments.Biking.java

@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
        @Nullable Bundle savedInstanceState) {
    final View rootView = inflater.inflate(R.layout.biking_fragment_layout, container, false);

    this.rootView = rootView;
    db = new DataBaseHelper(getActivity());
    list = db.getAllItemsBiking();/*from  ww w .j  a v  a2 s.  c o  m*/
    listItem = (ListView) rootView.findViewById(R.id.listview_bike);
    adapt = new CustomAdapter(getActivity(), R.layout.item_layout, list);
    listItem.setAdapter(adapt);
    nothingtext = (TextView) rootView.findViewById(R.id.nothing_here_bike);
    count = listItem.getCount();
    if (count > 0) {
        nothingtext.setVisibility(View.GONE);
    } else if (count == 0) {
        nothingtext.setVisibility(View.VISIBLE);
    }
    Log.i("Count = ", "" + count);

    final ImageButton imageButton = (ImageButton) rootView.findViewById(R.id.refresh);

    listItem.setOnScrollListener(new AbsListView.OnScrollListener() {

        @Override
        public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {

        }

        @Override
        public void onScrollStateChanged(AbsListView view, int scrollState) {
            // TODO Auto-generated method stub
            switch (scrollState) {
            case 2: // SCROLL_STATE_FLING
                //hide button here
                imageButton.setVisibility(View.GONE);
                break;

            case 1: // SCROLL_STATE_TOUCH_SCROLL
                //hide button here
                imageButton.setVisibility(View.GONE);
                break;

            case 0: // SCROLL_STATE_IDLE
                //show button here
                imageButton.setVisibility(View.VISIBLE);
                break;

            default:
                //show button here
                imageButton.setVisibility(View.VISIBLE);
                break;
            }
        }
    });

    imageButton.setOnLongClickListener(new View.OnLongClickListener() {
        @Override
        public boolean onLongClick(View v) {
            CountDownTimer timer = new CountDownTimer(4000, 1000) {

                @Override
                public void onTick(long millisUntilFinished) {
                    imageButton.setVisibility(View.GONE);
                }

                @Override
                public void onFinish() {
                    imageButton.setVisibility(View.VISIBLE);
                }

            };

            timer.start();

            return true;
        }
    });

    imageButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            AddItemNow();
            AlphaAnimation animation1 = new AlphaAnimation(0.2f, 1.0f);
            animation1.setDuration(500);
            imageButton.startAnimation(animation1);

        }
    });

    return rootView;

}

From source file:aarddict.android.ArticleViewActivity.java

@Override
void initUI() {/*  www  .ja  v  a 2  s  .  c  o m*/
    this.scrollPositionsH = Collections.synchronizedMap(new HashMap<Article, ScrollXY>());
    this.scrollPositionsV = Collections.synchronizedMap(new HashMap<Article, ScrollXY>());
    loadAssets();

    if (DeviceInfo.EINK_SCREEN) {
        useAnimation = false;
        setContentView(R.layout.eink_article_view);
        articleView = (ArticleView) findViewById(R.id.EinkArticleView);
        N2EpdController.n2MainActivity = this;
        EinkScreen.ResetController(2, articleView); // force full screen
                                                    // refresh when changing
                                                    // articles
    }
    // Setup animations only on non-eink screens
    else {
        useAnimation = true;
        fadeOutAnimation = new AlphaAnimation(1f, 0f);
        fadeOutAnimation.setDuration(600);
        fadeOutAnimation.setAnimationListener(new AnimationAdapter() {
            public void onAnimationEnd(Animation animation) {
                Button nextButton = (Button) findViewById(R.id.NextButton);
                nextButton.setVisibility(Button.GONE);
            }
        });

        getWindow().requestFeature(Window.FEATURE_PROGRESS);
        setContentView(R.layout.article_view);
        articleView = (ArticleView) findViewById(R.id.ArticleView);
    }

    timer = new Timer();

    backItems = Collections.synchronizedList(new LinkedList<HistoryItem>());

    if (android.os.Build.VERSION.SDK_INT >= 11) {
        try {
            showFindDialogMethod = articleView.getClass().getMethod("showFindDialog", String.class,
                    boolean.class);
        } catch (NoSuchMethodException e1) {
            Log.d(TAG, "showFindDialog method not found");
        }

    }

    articleView.setOnScrollListener(new ArticleView.ScrollListener() {
        public void onScroll(int l, int t, int oldl, int oldt) {
            saveScrollPos(l, t);
        }
    });

    articleView.getSettings().setJavaScriptEnabled(true);
    articleView.addJavascriptInterface(new SectionMatcher(), "matcher");
    articleView.addJavascriptInterface(articleView, "scrollControl");

    articleView.setWebChromeClient(new WebChromeClient() {

        @Override
        public boolean onJsAlert(WebView view, String url, String message, JsResult result) {
            Log.d(TAG + ".js", String.format("[%s]: %s", url, message));
            result.cancel();
            return true;
        }

        public void onProgressChanged(WebView view, int newProgress) {
            Log.d(TAG, "Progress: " + newProgress);
            setProgress(5000 + newProgress * 50);
        }
    });

    articleView.setWebViewClient(new WebViewClient() {

        @Override
        public void onPageFinished(WebView view, String url) {
            Log.d(TAG, "Page finished: " + url);
            currentTask = null;
            String section = null;

            if (url.contains("#")) {
                LookupWord lookupWord = LookupWord.splitWord(url);
                section = lookupWord.section;
                if (backItems.size() > 0) {
                    HistoryItem currentHistoryItem = backItems.get(backItems.size() - 1);
                    HistoryItem h = new HistoryItem(currentHistoryItem);
                    h.article.section = section;
                    backItems.add(h);
                }
            } else if (backItems.size() > 0) {
                Article current = backItems.get(backItems.size() - 1).article;
                section = current.section;
            }
            if (!restoreScrollPos()) {
                goToSection(section);
            }
            updateNextButtonVisibility();
        }

        @Override
        public boolean shouldOverrideUrlLoading(WebView view, final String url) {
            Log.d(TAG, "URL clicked: " + url);
            String urlLower = url.toLowerCase();
            if (urlLower.startsWith("http://") || urlLower.startsWith("https://")
                    || urlLower.startsWith("ftp://") || urlLower.startsWith("sftp://")
                    || urlLower.startsWith("mailto:")) {
                Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
                startActivity(browserIntent);
            } else {
                if (currentTask == null) {
                    currentTask = new TimerTask() {
                        public void run() {
                            try {
                                Article currentArticle = backItems.get(backItems.size() - 1).article;
                                try {
                                    Iterator<Entry> currentIterator = dictionaryService.followLink(url,
                                            currentArticle.volumeId);
                                    List<Entry> result = new ArrayList<Entry>();
                                    while (currentIterator.hasNext() && result.size() < 20) {
                                        result.add(currentIterator.next());
                                    }
                                    showNext(new HistoryItem(result));
                                } catch (ArticleNotFound e) {
                                    showMessage(getString(R.string.msgArticleNotFound, e.word.toString()));
                                }
                            } catch (Exception e) {
                                StringBuilder msgBuilder = new StringBuilder(
                                        "There was an error following link ").append("\"").append(url)
                                                .append("\"");
                                if (e.getMessage() != null) {
                                    msgBuilder.append(": ").append(e.getMessage());
                                }
                                final String msg = msgBuilder.toString();
                                Log.e(TAG, msg, e);
                                showError(msg);
                            }
                        }
                    };
                    try {
                        timer.schedule(currentTask, 0);
                    } catch (Exception e) {
                        Log.d(TAG, "Failed to schedule task", e);
                    }
                }
            }
            return true;
        }
    });
    final Button nextButton = (Button) findViewById(R.id.NextButton);
    nextButton.getBackground().setAlpha(180);
    nextButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            if (nextButton.getVisibility() == View.VISIBLE) {
                updateNextButtonVisibility();
                nextArticle();
                updateNextButtonVisibility();
            }
        }
    });
    articleView.setOnTouchListener(new View.OnTouchListener() {
        public boolean onTouch(View v, MotionEvent event) {
            updateNextButtonVisibility();
            return false;
        }
    });

    setProgressBarVisibility(true);
}

From source file:com.example.testtab.fragment.GalleryPageFragment.java

public void onItemSelected(AdapterView<?> parent, View v, int position, long id) {
    this.mImageView.setImageResource(this.mThumbIds[position]);

    if (this.mThumbIds[position] != null) {
        AnimationSet set = new AnimationSet(true);

        AlphaAnimation alpha = new AlphaAnimation(0.0f, 1.0f);

        set.addAnimation(alpha);//from  w ww .  j  a  va 2s.c  o  m
        set.setDuration(500);
        set.setFillAfter(true);

        this.mImageView.startAnimation(set);
    }

}

From source file:com.poloure.simplerss.AsyncNewTagAdapters.java

@Override
protected void onPostExecute(TreeMap<Long, FeedItem>[] result) {
    ViewPager pager = (ViewPager) m_activity.findViewById(R.id.viewpager);
    PagerAdapter pagerAdapter = pager.getAdapter();
    int pageCount = pagerAdapter.getCount();

    for (int i = 0; pageCount > i; i++) {
        // Get the tag page and skip ListViews that are null.
        ListFragmentTag fragment = FragmentFeeds.getViewPagerFragment(i);
        LinkedMapAdapter<Long, FeedItem> adapterTag = fragment.getListAdapter();
        ListViewFeeds listView = fragment.getListView();

        if (null == adapterTag) {
            fragment.setListAdapter(new AdapterFeedItems(m_activity, result[i]));
            listView.setSelectionOldestUnread(m_activity.getReadItemTimes());
        } else {/*from   ww  w .j  av  a2 s.com*/
            long topKeyBefore = 0L;
            int top = 0;

            // If there are items in the currently viewed page, save the position.
            boolean firstLoad = null == listView || 0 == listView.getCount();
            if (!firstLoad) {
                // Get the time of the top item.
                int topVisibleItem = listView.getFirstVisiblePosition();
                topKeyBefore = adapterTag.getKey(topVisibleItem);

                View v = listView.getChildAt(0);
                top = null == v ? 0 : v.getTop();
            }

            // Update the feedItems in the adapter.
            adapterTag.replaceAll(result[i]);

            // Now find the position of the item with the time timeBefore.
            if (firstLoad) {
                listView.setSelectionOldestUnread(m_activity.getReadItemTimes());
            } else {
                int newPos = adapterTag.indexOf(topKeyBefore);
                listView.setSelectionFromTop(newPos, top - listView.getPaddingTop());
            }
        }
    }

    // If the pager is invisible, use a fade in animation.
    if (View.VISIBLE != pager.getVisibility()) {
        pager.setVisibility(View.VISIBLE);
        AlphaAnimation animation = new AlphaAnimation(0.0F, 1.0F);
        animation.setDuration(300);
        pager.startAnimation(animation);
    }
}

From source file:com.charbgr.BlurNavigationDrawer.v4.BlurActionBarDrawerToggle.java

private void setAlpha(View view, float alpha, long durationMillis) {
    if (Build.VERSION.SDK_INT < 11) {
        final AlphaAnimation animation = new AlphaAnimation(alpha, alpha);
        animation.setDuration(durationMillis);
        animation.setFillAfter(true);//  www  .  j  a va 2s .c o m
        view.startAnimation(animation);
    } else {
        view.setAlpha(alpha);
    }
}

From source file:com.freshdigitable.udonroad.UserInfoActivity.java

private void setUpAppbar() {
    binding.userInfoToolbar.setTitle("");

    final TextView toolbarTitle = binding.userInfoToolbarTitle;
    binding.userInfoAppbarLayout.addOnOffsetChangedListener(new OnOffsetChangedListener() {
        private boolean isTitleVisible = toolbarTitle.getVisibility() == View.VISIBLE;

        @Override// w w w. j a  va 2  s.  c  o m
        public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) {
            final int totalScrollRange = appBarLayout.getTotalScrollRange();
            final float percent = (float) Math.abs(verticalOffset) / (float) totalScrollRange;
            if (percent > 0.9) {
                if (!isTitleVisible) {
                    startAnimation(toolbarTitle, View.VISIBLE);
                    isTitleVisible = true;
                }
            } else {
                if (isTitleVisible) {
                    startAnimation(toolbarTitle, View.INVISIBLE);
                    isTitleVisible = false;
                }
            }
        }

        private void startAnimation(View v, int visibility) {
            AlphaAnimation animation = (visibility == View.VISIBLE) ? new AlphaAnimation(0f, 1f)
                    : new AlphaAnimation(1f, 0f);
            animation.setDuration(200);
            animation.setFillAfter(true);
            v.startAnimation(animation);
        }
    });
}

From source file:com.mina.breathitout.AnalyzeActivity.java

public void fadeInText() {
    AlphaAnimation fadeIn = new AlphaAnimation(0.0f, 1.0f);
    AlphaAnimation fadeOut = new AlphaAnimation(1.0f, 0.0f);
    txtView.startAnimation(fadeIn);/*from  w  w w  .  jav  a 2 s  .c  o m*/
    txtView.startAnimation(fadeOut);
    fadeIn.setDuration(4000);
    fadeIn.setFillAfter(true);
    fadeOut.setDuration(4000);
    fadeOut.setFillAfter(true);
    fadeIn.setStartOffset(4200);
}

From source file:org.akvo.caddisfly.sensor.colorimetry.strip.camera.InstructionFragment.java

@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    // Inflate the layout for this fragment
    View rootView = inflater.inflate(R.layout.fragment_instruction, container, false);
    final Button buttonStart = (Button) rootView.findViewById(R.id.button_start);
    buttonStart.setEnabled(false);//from w  ww.  j  a  v  a 2 s .  c  o  m
    buttonStart.setAlpha(BUTTON_START_ALPHA);
    LinearLayout linearLayout = (LinearLayout) rootView.findViewById(R.id.layout_information);

    TextView textTitle = (TextView) rootView.findViewById(R.id.textToolbarTitle);
    if (textTitle != null) {
        textTitle.setText(R.string.instructions);
    }

    if (getArguments() != null) {

        String uuid = getArguments().getString(Constant.UUID);
        int phase = getArguments().getInt(Constant.PHASE);

        StripTest stripTest = new StripTest();
        JSONArray instructions = stripTest.getBrand(uuid).getInstructions();

        if (phase == 1) {
            showInstruction(linearLayout, getString(R.string.success_quality_checks), BOLD);
        }

        if (instructions != null) {
            try {
                for (int i = 0; i < instructions.length(); i++) {

                    JSONObject object = instructions.getJSONObject(i);
                    Object item = instructions.getJSONObject(i).get("text");

                    if ((object.has("phase") ? object.getInt("phase") : 1) == phase) {
                        JSONArray jsonArray;

                        if (item instanceof JSONArray) {
                            jsonArray = (JSONArray) item;
                        } else {
                            String text = (String) item;
                            jsonArray = new JSONArray();
                            jsonArray.put(text);
                        }

                        for (int j = 0; j < jsonArray.length(); j++) {
                            showInstruction(linearLayout, jsonArray.getString(j), Typeface.NORMAL);
                        }
                    }
                }
            } catch (JSONException e) {
                Timber.e(e);
            }
        }

    }

    buttonStart.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            mListener.nextFragment();
        }
    });

    (new Handler()).postDelayed(new Runnable() {
        public void run() {
            buttonStart.setEnabled(true);
            AlphaAnimation animation = new AlphaAnimation(BUTTON_START_ALPHA, 1f);
            buttonStart.setAlpha(1f);
            animation.setDuration(ANIMATION_DURATION_MILLIS);
            buttonStart.startAnimation(animation);
        }
    }, BUTTON_ENABLE_DELAY);

    return rootView;
}

From source file:com.carver.paul.truesight.Ui.CounterPicker.CounterPickerFragment.java

/**
 * Shows the loading text and pulses it. Ensures everything else is hidden
 *///w w w.  java2  s  .co m
protected void startLoadingAnimation() {
    mLoadingText.setVisibility(View.VISIBLE);
    mLoadingText.setAlpha(1f);

    AlphaAnimation pulseAlphaAnimation = new AlphaAnimation(0.2f, 1f);
    pulseAlphaAnimation.setDuration(300);
    pulseAlphaAnimation.setRepeatCount(Animation.INFINITE);
    pulseAlphaAnimation.setRepeatMode(Animation.REVERSE);
    mLoadingText.startAnimation(pulseAlphaAnimation);
}