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:it.chefacile.app.MainActivity.java

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    mContext = this;
    chefacileDb = new DatabaseHelper(this);
    // FilterButton = (ImageButton) findViewById(R.id.buttonfilter);
    TutorialButton = (ImageButton) findViewById(R.id.button);
    //  AddButton = (ImageButton) findViewById(R.id.button2);
    responseView = (TextView) findViewById(R.id.responseView);
    editText = (EditText) findViewById(R.id.ingredientText);
    progressBar = (ProgressBar) findViewById(R.id.progressBar);
    //Show = (ImageButton) findViewById(R.id.buttonShow);
    //Show2 = (ImageButton) findViewById(R.id.buttonShow2);
    materialAnimatedSwitch = (MaterialAnimatedSwitch) findViewById(R.id.pin);
    //buttoncuisine = (ImageButton) findViewById(R.id.btn_cuisine);
    //buttondiet = (ImageButton) findViewById(R.id.btn_diet);
    //buttonintol = (ImageButton) findViewById(R.id.btn_intoll);
    //Mostra = (Button) findViewById(R.id.btn_mostra);

    final Animation animation = new AlphaAnimation(1, 0); // Change alpha from fully visible to invisible
    animation.setDuration(1000); // duration - half a second
    animation.setInterpolator(new LinearInterpolator()); // do not alter animation rate
    animation.setRepeatCount(5); // Repeat animation infinitely
    animation.setRepeatMode(Animation.REVERSE);

    ImageView icon = new ImageView(this); // Create an icon
    icon.setImageDrawable(getResources().getDrawable(R.drawable.logo));

    final com.oguzdev.circularfloatingactionmenu.library.FloatingActionButton actionButton = new com.oguzdev.circularfloatingactionmenu.library.FloatingActionButton.Builder(
            this).setPosition(
                    com.oguzdev.circularfloatingactionmenu.library.FloatingActionButton.POSITION_RIGHT_CENTER)
                    .setContentView(icon).build();

    SubActionButton.Builder itemBuilder = new SubActionButton.Builder(this);
    // repeat many times:
    ImageView dietIcon = new ImageView(this);
    dietIcon.setImageDrawable(getResources().getDrawable(R.drawable.diet));
    SubActionButton button1 = itemBuilder.setContentView(dietIcon).build();
    button1.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            showSingleChoiceDialogDiet(v);
        }/* w ww  .ja v  a  2s. c om*/
    });

    ImageView intolIcon = new ImageView(this);
    intolIcon.setImageDrawable(getResources().getDrawable(R.drawable.intoll));
    SubActionButton button2 = itemBuilder.setContentView(intolIcon).build();
    button2.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            showMultiChoiceDialogIntol(v);
        }
    });

    ImageView cuisineIcon = new ImageView(this);
    cuisineIcon.setImageDrawable(getResources().getDrawable(R.drawable.cook12));
    SubActionButton button3 = itemBuilder.setContentView(cuisineIcon).build();
    button3.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            showMultiChoiceDialogCuisine(v);
        }
    });

    ImageView favouriteIcon = new ImageView(this);
    favouriteIcon.setImageDrawable(getResources().getDrawable(R.drawable.favorite));
    SubActionButton button4 = itemBuilder.setContentView(favouriteIcon).build();
    button4.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            showSimpleListDialogFav(v);
        }
    });

    ImageView wandIcon = new ImageView(this);
    wandIcon.setImageDrawable(getResources().getDrawable(R.drawable.wand));
    SubActionButton button5 = itemBuilder.setContentView(wandIcon).build();
    button5.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            sugg = getSuggestion();
            suggOccurrences = getCount();
            showSimpleListDialogSuggestions(v);
        }
    });

    final FloatingActionButton actionABC = (FloatingActionButton) findViewById(R.id.action_abc);

    actionABC.bringToFront();
    actionABC.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (ingredients.length() < 2) {
                Snackbar.make(responseView, "Insert at least one ingredient", Snackbar.LENGTH_LONG)
                        .setAction("Action", null).show();
            } else {
                new RetrieveFeedTask().execute();
            }
        }

        // Snackbar.make(view, "Non disponibile, mangia l'aria", Snackbar.LENGTH_LONG)
        //         .setAction("Action", null).show();

    });

    FloatingActionMenu actionMenu = new FloatingActionMenu.Builder(this).setStartAngle(90).setEndAngle(270)
            .addSubActionView(button1).addSubActionView(button2).addSubActionView(button3)
            .addSubActionView(button4).addSubActionView(button5).attachTo(actionButton).build();

    startDatabase(chefacileDb);

    for (int j = 0; j < cuisineItems.length; j++) {
        cuisineItems[j] = cuisineItems[j].substring(0, 1).toUpperCase() + cuisineItems[j].substring(1);
    }
    Arrays.sort(cuisineItems);

    for (int i = 0; i < 24; i++) {
        cuisineBool[i] = false;
    }

    Arrays.sort(intolItems);

    for (int i = 0; i < 11; i++) {
        intolBool[i] = false;
    }

    mListView = (MaterialListView) findViewById(R.id.material_listview);

    adapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1);

    TutorialButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            startActivity(new Intent(MainActivity.this, IntroScreenActivity.class));
            overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out);

        }
    });

    iv = (ImageView) findViewById(R.id.imageView);
    iv.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            clicks++;
            Log.d("CLICKS", String.valueOf(clicks));
            if (clicks == 15) {
                Log.d("IMAGE SHOWN", "mai vero");
                setBackground(iv);
            }
        }
    });

    materialAnimatedSwitch.setOnCheckedChangeListener(new MaterialAnimatedSwitch.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(boolean isChecked) {
            if (isChecked == true) {
                ranking = 2;
                Toast.makeText(getApplicationContext(), "Minimize missing ingredients", Toast.LENGTH_SHORT)
                        .show();
            } else {
                ranking = 1;
                Toast.makeText(getApplicationContext(), "Maximize used ingredients", Toast.LENGTH_SHORT).show();
            }
            Log.d("Ranking", String.valueOf(ranking));
        }
    });

    final CharSequence[] items = { "Maximize used ingredients", "Minimize missing ingredients" };

    editText.setOnKeyListener(new View.OnKeyListener() {
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if (event.getAction() == KeyEvent.ACTION_DOWN) {
                switch (keyCode) {
                case KeyEvent.KEYCODE_DPAD_CENTER:
                case KeyEvent.KEYCODE_ENTER:
                    if (!(editText.getText().toString().trim().equals(""))) {

                        String input;
                        String s1 = editText.getText().toString().substring(0, 1).toUpperCase();
                        String s2 = editText.getText().toString().substring(1);
                        input = s1 + s2;

                        Log.d("INPUT: ", input);
                        searchedIngredients.add(input);
                        Log.d("SEARCHED INGR LIST", searchedIngredients.toString());

                        if (!chefacileDb.findIngredientPREF(input)) {
                            if (chefacileDb.findIngredient(input)) {
                                chefacileDb.updateCount(input);
                                mapIngredients = chefacileDb.getDataInMapIngredient();
                                Map<String, Integer> map2;
                                map2 = sortByValue(mapIngredients);
                                Log.d("MAPPACOUNT: ", map2.toString());

                            } else {
                                if (chefacileDb.occursExceeded()) {
                                    //chefacileDb.deleteMinimum(input);
                                    // chefacileDb.insertDataIngredient(input);
                                    mapIngredients = chefacileDb.getDataInMapIngredient();
                                    Map<String, Integer> map3;
                                    map3 = sortByValue(mapIngredients);
                                    Log.d("MAPPAINGREDIENTE: ", map3.toString());

                                } else {
                                    chefacileDb.insertDataIngredient(input);
                                    mapIngredients = chefacileDb.getDataInMapIngredient();
                                    Map<String, Integer> map3;
                                    map3 = sortByValue(mapIngredients);
                                    Log.d("MAPPAINGREDIENTE: ", map3.toString());
                                }
                            }
                        }
                    }

                    if (editText.getText().toString().trim().equals("")) {
                        ingredients += editText.getText().toString().trim() + "";
                        editText.getText().clear();

                    } else {
                        ingredients += editText.getText().toString().replaceAll(" ", "+").trim().toLowerCase()
                                + ",";
                        singleIngredient = editText.getText().toString().trim().toLowerCase();
                        currentIngredient = singleIngredient;
                        new RetrieveIngredientTask().execute();

                        //adapter.add(singleIngredient.substring(0,1).toUpperCase() + singleIngredient.substring(1));
                    }

                    InputMethodManager in = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);

                    in.hideSoftInputFromWindow(editText.getApplicationWindowToken(),
                            InputMethodManager.HIDE_NOT_ALWAYS);

                    actionABC.startAnimation(animation);

                    return true;
                default:
                    break;
                }
            }
            return false;
        }
    });

    responseView = (TextView) findViewById(R.id.responseView);
    editText = (EditText) findViewById(R.id.ingredientText);
    progressBar = (ProgressBar) findViewById(R.id.progressBar);

}

From source file:com.cachirulop.moneybox.fragment.MoneyboxFragment.java

/**
 * Create dynamically an android animation for a coin or a bill droping into
 * the moneybox./*  w ww .  j  a  v a2 s  .  com*/
 * 
 * @param img
 *            ImageView to receive the animation
 * @param layout
 *            Layout that paint the image
 * @param curr
 *            Currency value of the image
 * @return Set of animations to apply to the image
 */
private AnimationSet createDropAnimation(ImageView img, View layout, CurrencyValueDef curr) {
    AnimationSet result;

    result = new AnimationSet(false);
    result.setFillAfter(true);

    // Fade in
    AlphaAnimation fadeIn;

    fadeIn = new AlphaAnimation(0.0f, 1.0f);
    fadeIn.setDuration(300);
    result.addAnimation(fadeIn);

    // drop
    TranslateAnimation drop;
    int bottom;

    bottom = Math.abs(layout.getHeight() - img.getLayoutParams().height);
    drop = new TranslateAnimation(1.0f, 1.0f, 1.0f, bottom);
    drop.setStartOffset(300);
    drop.setDuration(1500);

    if (curr.getType() == CurrencyValueDef.MoneyType.COIN) {
        drop.setInterpolator(new BounceInterpolator());
    } else {
        // drop.setInterpolator(new DecelerateInterpolator(0.7f));
        drop.setInterpolator(new AnticipateOvershootInterpolator());
    }

    result.addAnimation(drop);

    return result;
}

From source file:com.findme.views.ExpandableTextView.java

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
private static void applyAlphaAnimation(View view, float alpha) {
    if (isPostHoneycomb()) {
        view.setAlpha(alpha);/*w  w w.j a  v  a 2s.c o m*/
    } else {
        AlphaAnimation alphaAnimation = new AlphaAnimation(alpha, alpha);
        // make it instant
        alphaAnimation.setDuration(0);
        alphaAnimation.setFillAfter(true);
        view.startAnimation(alphaAnimation);
    }
}

From source file:net.eledge.android.europeana.gui.fragment.SearchResultsFragment.java

private void hideStatusText() {
    if ((mStatusTextView == null) || !mStatusTextView.isShown()) {
        return;/*from   www .  j a va  2s .  c  om*/
    }
    Animation fadeOut = new AlphaAnimation(1, 0);
    fadeOut.setDuration(400);
    fadeOut.setAnimationListener(new AnimationListener() {
        @Override
        public void onAnimationStart(Animation animation) {
        }

        @Override
        public void onAnimationRepeat(Animation animation) {
        }

        @Override
        public void onAnimationEnd(Animation animation) {
            mStatusTextView.setVisibility(View.GONE);
        }
    });
    mStatusTextView.startAnimation(fadeOut);
}

From source file:com.justwayward.reader.view.recyclerview.adapter.BaseViewHolder.java

public BaseViewHolder setAlpha(int viewId, float value) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        getView(viewId).setAlpha(value);
    } else {//from www.  j  av a 2 s.c o  m
        AlphaAnimation alpha = new AlphaAnimation(value, value);
        alpha.setDuration(0);
        alpha.setFillAfter(true);
        getView(viewId).startAnimation(alpha);
    }
    return this;
}

From source file:org.digitalcampus.oppia.fragments.CourseScorecardFragment.java

public void onParseComplete(CompleteCourse parsed) {

    ArrayList<Activity> baseline = parsed.getBaselineActivities();

    DbHelper db = DbHelper.getInstance(super.getActivity());
    long userId = db.getUserId(SessionManager.getUsername(getActivity()));
    ArrayList<Activity> quizActs = db.getCourseQuizzes(course.getCourseId());
    ArrayList<QuizStats> quizzes = new ArrayList<>();
    for (Activity a : quizActs) {
        // get the max score for the quiz for the user
        QuizStats qs = db.getQuizAttempt(a.getDigest(), userId);
        quizzes.add(qs);/*from  w  ww . j  av  a2s .  com*/
    }

    int quizzesAttempted = 0, quizzesPassed = 0;

    for (QuizStats qs : quizzes) {
        if (qs.isAttempted()) {
            quizzesAttempted++;
        }
        if (qs.isPassed()) {
            quizzesPassed++;
        }
    }

    int pretestScore = -1;
    for (Activity baselineAct : baseline) {
        if (!baselineAct.getActType().equals("quiz"))
            continue;
        QuizStats pretest = db.getQuizAttempt(baselineAct.getDigest(), userId);
        pretestScore = pretest.getPercent();
    }

    quizStats.clear();
    quizStats.addAll(quizzes);
    if (quizStats.size() == 0) {
        quizzesContainer.setVisibility(View.GONE);
        return;
    }

    highlightPretest.setText(pretestScore >= 0 ? (pretestScore + "%") : "-");
    highlightAttempted.setText("" + quizzesAttempted);
    highlightPassed.setText("" + quizzesPassed);
    quizzesAdapter.notifyDataSetChanged();

    AlphaAnimation fadeInAnimation = new AlphaAnimation(0f, 1f);
    fadeInAnimation.setDuration(700);
    fadeInAnimation.setFillAfter(true);

    quizzesProgressBar.setProgress(0);
    quizzesProgressBar.setSecondaryProgress(0);

    quizzesView.setVisibility(View.VISIBLE);
    quizzesView.startAnimation(fadeInAnimation);

    quizzesProgressBar.setMax(quizStats.size());
    ProgressBarAnimator animator = new ProgressBarAnimator(quizzesProgressBar);
    animator.setStartDelay(500);
    animator.animateBoth(quizzesPassed, quizzesAttempted);
}

From source file:com.libreteam.driver.Driver_RideOffer.java

private void blinkCountDown() {
    //      MediaPlayer  mp = MediaPlayer.create(getActivity(), R.raw.alert);
    //      mp.start();
    Animation anim = new AlphaAnimation(0.0f, 1.0f);
    anim.setDuration(150);//from w  w w  .ja v a2 s .c o m
    anim.setStartOffset(120);
    anim.setRepeatMode(Animation.REVERSE);
    anim.setRepeatCount(Animation.INFINITE);
    txtCountDown.startAnimation(anim);
}

From source file:io.realm.realmtasks.list.ItemViewHolder.java

public void setHintPanelVisible(boolean visible) {
    final int visibility = hintPanel.getVisibility();
    boolean previousVisible = visibility == View.VISIBLE;
    if (previousVisible == visible) {
        return;//  w  w  w .  ja  va  2s .c om
    }
    if (visible) {
        hintPanel.setVisibility(View.VISIBLE);
        final AlphaAnimation alphaAnimation = new AlphaAnimation(0.2f, 1.0f);
        alphaAnimation.setDuration(150);
        hintPanel.setAnimation(alphaAnimation);
        final RotateAnimation rotateAnimation = new RotateAnimation(-90, 0, RotateAnimation.RELATIVE_TO_SELF,
                0.5f, RotateAnimation.RELATIVE_TO_SELF, 0.5f);
        rotateAnimation.setDuration(500);
        arrow.startAnimation(rotateAnimation);
    } else {
        hintPanel.setVisibility(View.GONE);
    }
}

From source file:uk.org.ngo.squeezer.itemlist.AlarmView.java

private View getAdapterView(View convertView, final ViewGroup parent) {
    AlarmViewHolder currentViewHolder = (convertView != null && convertView.getTag() instanceof AlarmViewHolder)
            ? (AlarmViewHolder) convertView.getTag()
            : null;// ww w  .  j  a v a 2  s. c om

    if (currentViewHolder == null) {
        convertView = getLayoutInflater().inflate(R.layout.list_item_alarm, parent, false);
        final View alarmView = convertView;
        final AlarmViewHolder viewHolder = new AlarmViewHolder();
        viewHolder.is24HourFormat = DateFormat.is24HourFormat(getActivity());
        viewHolder.timeFormat = viewHolder.is24HourFormat ? "%02d:%02d" : "%d:%02d";
        String[] amPmStrings = new DateFormatSymbols().getAmPmStrings();
        viewHolder.am = amPmStrings[0];
        viewHolder.pm = amPmStrings[1];
        viewHolder.time = (TextView) convertView.findViewById(R.id.time);
        viewHolder.amPm = (TextView) convertView.findViewById(R.id.am_pm);
        viewHolder.amPm.setVisibility(viewHolder.is24HourFormat ? View.GONE : View.VISIBLE);
        viewHolder.enabled = new CompoundButtonWrapper((CompoundButton) convertView.findViewById(R.id.enabled));
        viewHolder.enabled.setOncheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
                if (getActivity().getService() != null) {
                    viewHolder.alarm.setEnabled(b);
                    getActivity().getService().alarmEnable(viewHolder.alarm.getId(), b);
                }
            }
        });
        viewHolder.repeat = new CompoundButtonWrapper((CompoundButton) convertView.findViewById(R.id.repeat));
        viewHolder.repeat.setOncheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
                if (getActivity().getService() != null) {
                    viewHolder.alarm.setRepeat(b);
                    getActivity().getService().alarmRepeat(viewHolder.alarm.getId(), b);
                    viewHolder.dowHolder.setVisibility(b ? View.VISIBLE : View.GONE);
                }
            }
        });
        viewHolder.repeat.getButton().setText(ServerString.ALARM_ALARM_REPEAT.getLocalizedString());
        viewHolder.delete = (ImageView) convertView.findViewById(R.id.delete);
        viewHolder.playlist = (Spinner) convertView.findViewById(R.id.playlist);
        viewHolder.dowHolder = (LinearLayout) convertView.findViewById(R.id.dow);
        for (int day = 0; day < 7; day++) {
            ViewGroup dowButton = (ViewGroup) viewHolder.dowHolder.getChildAt(day);
            final int finalDay = day;
            dowButton.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (getActivity().getService() != null) {
                        final Alarm alarm = viewHolder.alarm;
                        boolean wasChecked = alarm.isDayActive(finalDay);
                        if (wasChecked) {
                            alarm.clearDay(finalDay);
                            getActivity().getService().alarmRemoveDay(alarm.getId(), finalDay);
                        } else {
                            alarm.setDay(finalDay);
                            getActivity().getService().alarmAddDay(alarm.getId(), finalDay);
                        }
                        setDowText(viewHolder, finalDay);
                    }
                }
            });
            viewHolder.dowTexts[day] = (TextView) dowButton.getChildAt(0);
        }
        viewHolder.delete.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(final View view) {
                final AnimationSet animationSet = new AnimationSet(true);
                animationSet.addAnimation(new ScaleAnimation(1F, 1F, 1F, 0.5F));
                animationSet.addAnimation(new AlphaAnimation(1F, 0F));
                animationSet.setDuration(ANIMATION_DURATION);
                animationSet.setAnimationListener(new AnimationEndListener() {
                    @Override
                    public void onAnimationEnd(Animation animation) {
                        mActivity.getItemAdapter().removeItem(viewHolder.position);
                        UndoBarController.show(getActivity(), ServerString.ALARM_DELETING.getLocalizedString(),
                                new UndoListener(viewHolder.position, viewHolder.alarm));
                    }
                });

                alarmView.startAnimation(animationSet);
            }
        });
        viewHolder.playlist.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                final AlarmPlaylist selectedAlarmPlaylist = mAlarmPlaylists.get(position);
                final Alarm alarm = viewHolder.alarm;
                if (getActivity().getService() != null && selectedAlarmPlaylist.getId() != null
                        && !selectedAlarmPlaylist.getId().equals(alarm.getUrl())) {
                    alarm.setUrl(selectedAlarmPlaylist.getId());
                    getActivity().getService().alarmSetPlaylist(alarm.getId(), selectedAlarmPlaylist);
                }
            }

            @Override
            public void onNothingSelected(AdapterView<?> parent) {
            }
        });

        convertView.setTag(viewHolder);
    }

    return convertView;
}

From source file:net.eledge.android.europeana.gui.fragment.SearchResultsFragment.java

private void showStatusText() {
    if (mStatusTextView.isShown()) {
        return;/*from  www.j a v a  2  s  .  com*/
    }
    Animation fadeOut = new AlphaAnimation(0, 1);
    fadeOut.setDuration(400);
    fadeOut.setAnimationListener(new AnimationListener() {
        @Override
        public void onAnimationStart(Animation animation) {
            mStatusTextView.setVisibility(View.VISIBLE);
        }

        @Override
        public void onAnimationRepeat(Animation animation) {
        }

        @Override
        public void onAnimationEnd(Animation animation) {
        }
    });
    mStatusTextView.startAnimation(fadeOut);
}