Example usage for android.view.animation RotateAnimation setFillEnabled

List of usage examples for android.view.animation RotateAnimation setFillEnabled

Introduction

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

Prototype

public void setFillEnabled(boolean fillEnabled) 

Source Link

Document

If fillEnabled is true, the animation will apply the value of fillBefore.

Usage

From source file:Main.java

public static void rotate(final View view, float fromDegrees, float toDegrees, long duration) {
    if (Build.VERSION.SDK_INT >= 12) {
        if (duration == 0)
            view.setRotation(toDegrees);
        else/*from ww w  .  j  ava2  s  .  co m*/
            view.animate().rotation(toDegrees).setDuration(duration).start();
    } else {
        RotateAnimation rotate = new RotateAnimation(fromDegrees, toDegrees, Animation.RELATIVE_TO_SELF, 0.5f,
                Animation.RELATIVE_TO_SELF, 0.5f);
        rotate.setDuration(duration);
        rotate.setFillEnabled(true);
        rotate.setFillBefore(true);
        rotate.setFillAfter(true);
        addAnimation(view, rotate);
    }
}

From source file:net.willwebberley.gowertides.ui.DayFragment.java

private void setWeatherInfo() {
    Weather weather = day.getWeather();/*  ww w . j ava  2  s .  c o  m*/
    String weather_description = weather.description;
    String unitType = prefs.getString("unitFormat", "true");
    Boolean metric = false;
    if (unitType.equals("true")) {
        metric = true;
    }

    int max_temp = weather.getMaxTemp(metric);
    int min_temp = weather.getMinTemp(metric);
    int wind_speed = weather.getWindSpeed(metric);
    Double prep = weather.precipitation;
    String direction = weather.wind_direction;
    Spanned temp = null, wind = null;
    if (metric) {
        temp = Html.fromHtml("<b>" + min_temp + "&deg;C - " + max_temp + "&deg;C</b>");
        wind = Html.fromHtml("<b>" + wind_speed + "km/h</b> from <b>" + direction + "</b>");

    } else {
        temp = Html.fromHtml("<b>" + min_temp + "&deg;F - " + max_temp + "&deg;F</b>");
        wind = Html.fromHtml("<b>" + wind_speed + "mph</b> from <b>" + direction + "</b>");
    }
    Spanned precipitation = Html.fromHtml("<b>" + prep + "mm</b>");

    ((TextView) layoutView.findViewById(R.id.weather_description)).setText(weather_description);
    ((TextView) layoutView.findViewById(R.id.weatherTemp)).setText(temp);
    ((TextView) layoutView.findViewById(R.id.weatherTemp)).setTextColor(Color.rgb(100, 100, 100));
    ((TextView) layoutView.findViewById(R.id.weatherWind)).setText(wind);
    ((TextView) layoutView.findViewById(R.id.weatherWind)).setTextColor(Color.rgb(100, 100, 100));
    ((TextView) layoutView.findViewById(R.id.weatherPrecipitation)).setText(precipitation);
    ((TextView) layoutView.findViewById(R.id.weatherPrecipitation)).setTextColor(Color.rgb(100, 100, 100));
    String icon = weather.getWeatherIcon();
    try {
        InputStream ims = getActivity().getAssets().open("icons/" + icon);
        Drawable d = Drawable.createFromStream(ims, null);
        ((ImageView) layoutView.findViewById(R.id.weatherIcon)).setImageDrawable(d);
        InputStream ims2 = getActivity().getAssets().open("icons/arrow.png");
        Drawable d2 = Drawable.createFromStream(ims2, null);
        ((ImageView) layoutView.findViewById(R.id.weatherWindIcon)).setImageDrawable(d2);

        RotateAnimation rAnim = new RotateAnimation(0, weather.wind_degree, Animation.RELATIVE_TO_SELF, 0.5f,
                Animation.RELATIVE_TO_SELF, 0.5f);
        rAnim.setDuration(500);
        rAnim.setFillEnabled(true);
        rAnim.setFillAfter(true);
        ((ImageView) layoutView.findViewById(R.id.weatherWindIcon)).startAnimation(rAnim);
    } catch (Exception e) {
        System.err.println(e);
    }
}

From source file:com.itude.mobile.mobbl.core.view.components.tabbar.MBDefaultActionBarBuilder.java

private ImageView getRotationImage() {
    RotateAnimation rotateAnimation = new RotateAnimation(0, 360, Animation.RELATIVE_TO_SELF, 0.5f,
            Animation.RELATIVE_TO_SELF, 0.5f);
    rotateAnimation.setDuration(1000L);//from  w w  w .  j a v a  2s.  c o m
    rotateAnimation.setRepeatMode(Animation.INFINITE);
    rotateAnimation.setRepeatCount(Animation.INFINITE);
    rotateAnimation.setFillEnabled(false);
    rotateAnimation.setInterpolator(new LinearInterpolator());

    Drawable drawable = MBResourceService.getInstance().getImageByID(_refreshToolDef.getIcon());
    ImageView rotationImage = new ImageView(_context);
    rotationImage.setImageDrawable(drawable);
    rotationImage.setAnimation(rotateAnimation);

    return rotationImage;
}

From source file:fr.shywim.antoinedaniel.ui.fragment.VideoDetailsFragment.java

private void bindSound(View view, Cursor cursor) {
    AppState appState = AppState.getInstance();

    final View card = view;
    final View downloadFrame = view.findViewById(R.id.sound_download_frame);
    final TextView tv = (TextView) view.findViewById(R.id.grid_text);
    final SquareImageView siv = (SquareImageView) view.findViewById(R.id.grid_image);
    final ImageView star = (ImageView) view.findViewById(R.id.ic_sound_fav);
    final ImageView menu = (ImageView) view.findViewById(R.id.ic_sound_menu);

    final String soundName = cursor
            .getString(cursor.getColumnIndex(ProviderContract.SoundEntry.COLUMN_SOUND_NAME));
    String imgId = cursor.getString(cursor.getColumnIndex(ProviderContract.SoundEntry.COLUMN_IMAGE_NAME));
    final String description = cursor.getString(cursor.getColumnIndex(ProviderContract.SoundEntry.COLUMN_DESC));
    final boolean favorite = appState.favSounds.contains(soundName)
            || cursor.getInt(cursor.getColumnIndex(ProviderContract.SoundEntry.COLUMN_FAVORITE)) == 1;
    final boolean widget = appState.widgetSounds.contains(soundName)
            || cursor.getInt(cursor.getColumnIndex(ProviderContract.SoundEntry.COLUMN_WIDGET)) == 1;
    final boolean downloaded = cursor
            .getInt(cursor.getColumnIndex(ProviderContract.SoundEntry.COLUMN_DOWNLOADED)) != 0;

    new Handler().post(new Runnable() {
        @Override/*from  www .  j  a  va 2 s  .c o m*/
        public void run() {
            ContentValues cv = new ContentValues();
            File sndFile = new File(mContext.getExternalFilesDir(null) + "/snd/" + soundName + ".ogg");

            if (downloaded && !sndFile.exists()) {
                cv.put(ProviderContract.SoundEntry.COLUMN_DOWNLOADED, 0);
                mContext.getContentResolver().update(
                        Uri.withAppendedPath(ProviderConstants.SOUND_DOWNLOAD_NOTIFY_URI, soundName), cv, null,
                        null);
            }
        }
    });

    final View.OnClickListener playSound = new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            String category = mContext.getString(R.string.ana_cat_sound);
            String action = mContext.getString(R.string.ana_act_play);

            Bundle extras = new Bundle();
            extras.putString(SoundFragment.SOUND_TO_PLAY, soundName);
            extras.putBoolean(SoundFragment.LOOP, SoundUtils.isLoopingSet());
            Intent intent = new Intent(mContext, SoundService.class);
            intent.putExtras(extras);

            mContext.startService(intent);
            AnalyticsUtils.sendEvent(category, action, soundName);
        }
    };

    final View.OnClickListener downloadSound = new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            card.setOnClickListener(null);
            RotateAnimation animation = new RotateAnimation(0, 360, Animation.RELATIVE_TO_SELF, 0.5f,
                    Animation.RELATIVE_TO_SELF, 0.5f);
            animation.setInterpolator(new BounceInterpolator());
            animation.setFillAfter(true);
            animation.setFillEnabled(true);
            animation.setDuration(1000);
            animation.setRepeatCount(Animation.INFINITE);
            animation.setRepeatMode(Animation.RESTART);
            downloadFrame.findViewById(R.id.sound_download_icon).startAnimation(animation);

            DownloadService.startActionDownloadSound(mContext, soundName,
                    new SoundUtils.DownloadResultReceiver(new Handler(), downloadFrame, playSound, this));
        }
    };

    if (downloaded) {
        downloadFrame.setVisibility(View.GONE);
        downloadFrame.findViewById(R.id.sound_download_icon).clearAnimation();
        card.setOnClickListener(playSound);
    } else {
        downloadFrame.setAlpha(1);
        downloadFrame.findViewById(R.id.sound_download_icon).setScaleX(1);
        downloadFrame.findViewById(R.id.sound_download_icon).setScaleY(1);
        downloadFrame.setVisibility(View.VISIBLE);
        card.setOnClickListener(downloadSound);
    }

    menu.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            final ImageView menuIc = (ImageView) v;
            PopupMenu popup = new PopupMenu(mContext, menuIc);
            Menu menu = popup.getMenu();
            popup.getMenuInflater().inflate(R.menu.sound_menu, menu);

            if (favorite)
                menu.findItem(R.id.action_sound_fav).setTitle("Retirer des favoris");
            if (widget)
                menu.findItem(R.id.action_sound_wid).setTitle("Retirer du widget");

            popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
                @Override
                public boolean onMenuItemClick(MenuItem item) {
                    switch (item.getItemId()) {
                    case R.id.action_sound_fav:
                        SoundUtils.addRemoveFavorite(mContext, soundName);
                        return true;
                    case R.id.action_sound_wid:
                        SoundUtils.addRemoveWidget(mContext, soundName);
                        return true;
                    /*case R.id.action_sound_add:
                       return true;*/
                    case R.id.action_sound_ring:
                        SoundUtils.addRingtone(mContext, soundName, description);
                        return true;
                    case R.id.action_sound_share:
                        AnalyticsUtils.sendEvent(mContext.getString(R.string.ana_cat_soundcontext),
                                mContext.getString(R.string.ana_act_weblink), soundName);
                        ClipboardManager clipboard = (ClipboardManager) mContext
                                .getSystemService(Context.CLIPBOARD_SERVICE);
                        ClipData clip = ClipData.newPlainText("BAD link", "http://bad.shywim.fr/" + soundName);
                        clipboard.setPrimaryClip(clip);
                        Toast.makeText(mContext, R.string.toast_link_copied, Toast.LENGTH_LONG).show();
                        return true;
                    case R.id.action_sound_delete:
                        SoundUtils.delete(mContext, soundName);
                        return true;
                    default:
                        return false;
                    }
                }
            });

            popup.setOnDismissListener(new PopupMenu.OnDismissListener() {
                @Override
                public void onDismiss(PopupMenu menu) {
                    menuIc.setColorFilter(mContext.getResources().getColor(R.color.text_caption_dark));
                }
            });
            menuIc.setColorFilter(mContext.getResources().getColor(R.color.black));

            popup.show();
        }
    });

    tv.setText(description);
    siv.setTag(imgId);

    if (appState.favSounds.contains(soundName)) {
        star.setVisibility(View.VISIBLE);
    } else if (favorite) {
        star.setVisibility(View.VISIBLE);
        appState.favSounds.add(soundName);
    } else {
        star.setVisibility(View.INVISIBLE);
    }

    File file = new File(mContext.getExternalFilesDir(null) + "/img/" + imgId + ".jpg");
    Picasso.with(mContext).load(file).placeholder(R.drawable.noimg).fit().into(siv);
}

From source file:Steps.StepsFragment.java

/**
 * Animate the new sticker rotating them on left and right and back again
 *
 * @param sticker//from   w  w  w  .  jav a 2  s.c om
 * @param durationMillis
 */
private void animate(final RelativeLayout sticker, long durationMillis) {

    //final AnimationSet as = new AnimationSet(true);
    as.setFillEnabled(true);
    as.setFillAfter(true);
    //left rotations
    final RotateAnimation rotateLeft = new RotateAnimation((float) 320, (float) 375,
            RotateAnimation.RELATIVE_TO_SELF, 0.5f, RotateAnimation.RELATIVE_TO_SELF, 0.5f);
    rotateLeft.setDuration(durationMillis);
    rotateLeft.setFillEnabled(true);

    if (firstTime)
        as.addAnimation(rotateLeft);
    //right rotations
    Animation rotateRight = new RotateAnimation((float) 375, (float) 320, RotateAnimation.RELATIVE_TO_SELF,
            0.5f, RotateAnimation.RELATIVE_TO_SELF, 0.5f);
    rotateRight.setStartOffset(durationMillis);
    rotateRight.setDuration(durationMillis);
    rotateRight.setFillEnabled(true);
    rotateRight.setFillAfter(true);

    if (firstTime)
        as.addAnimation(rotateRight);
    //sticker.clearAnimation();
    sticker.startAnimation(as);
    firstTime = false;
}