Example usage for android.animation ObjectAnimator ofFloat

List of usage examples for android.animation ObjectAnimator ofFloat

Introduction

In this page you can find the example usage for android.animation ObjectAnimator ofFloat.

Prototype

public static <T> ObjectAnimator ofFloat(T target, Property<T, Float> xProperty, Property<T, Float> yProperty,
        Path path) 

Source Link

Document

Constructs and returns an ObjectAnimator that animates coordinates along a Path using two properties.

Usage

From source file:com.google.samples.apps.topeka.widget.TextResizeTransition.java

@Override
public Animator createAnimator(ViewGroup sceneRoot, TransitionValues startValues, TransitionValues endValues) {
    if (startValues == null || endValues == null) {
        return null;
    }/* w w w .j a v a 2 s .co m*/

    float initialTextSize = (float) startValues.values.get(PROPERTY_NAME_TEXT_RESIZE);
    float targetTextSize = (float) endValues.values.get(PROPERTY_NAME_TEXT_RESIZE);
    TextView targetView = (TextView) endValues.view;
    targetView.setTextSize(TypedValue.COMPLEX_UNIT_PX, initialTextSize);

    int initialPaddingStart = (int) startValues.values.get(PROPERTY_NAME_PADDING_RESIZE);
    int targetPaddingStart = (int) endValues.values.get(PROPERTY_NAME_PADDING_RESIZE);

    AnimatorSet animatorSet = new AnimatorSet();
    animatorSet.playTogether(
            ObjectAnimator.ofFloat(targetView, ViewUtils.PROPERTY_TEXT_SIZE, initialTextSize, targetTextSize),
            ObjectAnimator.ofInt(targetView, ViewUtils.PROPERTY_TEXT_PADDING_START, initialPaddingStart,
                    targetPaddingStart));
    return animatorSet;
}

From source file:com.anyline.reactnative.Document4Activity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(getResources().getIdentifier("activity_scan_scanview", "layout", getPackageName()));

    // takes care of fading the error message out after some time with no error reported from the SDK
    errorMessageCleanup = new Runnable() {
        @Override/*from w w  w .j av a2s.c om*/
        public void run() {
            if (Document4Activity.this.isFinishing()) {
                return;
            }
            if (System.currentTimeMillis() > lastErrorRecieved + ERROR_MESSAGE_DELAY) {
                if (errorMessage == null || errorMessageAnimator == null) {
                    return;
                }
                if (errorMessage.getAlpha() == 0f) {
                    errorMessage.setText("");
                } else if (!errorMessageAnimator.isRunning()) {
                    errorMessageAnimator = ObjectAnimator.ofFloat(errorMessage, "alpha",
                            errorMessage.getAlpha(), 0f);
                    errorMessageAnimator.setDuration(ERROR_MESSAGE_DELAY);
                    errorMessageAnimator.setInterpolator(new AccelerateInterpolator());
                    errorMessageAnimator.start();
                }
            }
            handler.postDelayed(errorMessageCleanup, ERROR_MESSAGE_DELAY);

        }
    };

    // Set the flag to keep the screen on (otherwise the screen may go dark during scanning)
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

    imageViewResult = (ImageView) findViewById(
            getResources().getIdentifier("image_result", "id", getPackageName()));
    errorMessageLayout = (FrameLayout) findViewById(
            getResources().getIdentifier("error_message_layout", "id", getPackageName()));
    errorMessage = (TextView) findViewById(
            getResources().getIdentifier("error_message", "id", getPackageName()));

    documentScanView = (ScanView) findViewById(
            getResources().getIdentifier("document_scan_view", "id", getPackageName()));
    // add a camera open listener that will be called when the camera is opened or an error occurred
    // this is optional (if not set a RuntimeException will be thrown if an error occurs)
    documentScanView.setCameraOpenListener(this);
    // the view can be configured via a json file in the assets, and this config is set here

    try {
        final JSONObject json = new JSONObject(configJson);
        documentScanView.setScanConfig(json, licenseKey);
    } catch (Exception e) {
        e.printStackTrace();
    }

    // initialize Anyline with the license key and a Listener that is called if a result is found
    documentScanView.getScanViewPlugin().addScanResultListener(new DocumentScanResultListener() {
        @Override
        public void onResult(ScanResult documentResult) {

            // handle the result document images here
            if (progressDialog != null && progressDialog.isShowing()) {
                progressDialog.dismiss();
            }

            AnylineImage transformedImage = (AnylineImage) documentResult.getResult();
            AnylineImage fullFrame = documentResult.getFullImage();

            // resize display view based on larger side of document, and display document
            int widthDP, heightDP;
            Bitmap bmpTransformedImage = transformedImage.getBitmap();

            if (bmpTransformedImage.getHeight() > bmpTransformedImage.getWidth()) {
                widthDP = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 100,
                        getResources().getDisplayMetrics());
                heightDP = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 160,
                        getResources().getDisplayMetrics());
                //Add a comment to this line

                imageViewResult.getLayoutParams().width = widthDP;
                imageViewResult.getLayoutParams().height = ViewGroup.LayoutParams.WRAP_CONTENT;
            } else {
                widthDP = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 160,
                        getResources().getDisplayMetrics());
                heightDP = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 100,
                        getResources().getDisplayMetrics());

                imageViewResult.getLayoutParams().width = ViewGroup.LayoutParams.WRAP_CONTENT;
                imageViewResult.getLayoutParams().height = heightDP;
            }

            imageViewResult.setImageBitmap(
                    Bitmap.createScaledBitmap(transformedImage.getBitmap(), widthDP, heightDP, false));

            /**
             * IMPORTANT: cache provided frames here, and release them at the end of this onResult. Because
             * keeping them in memory (e.g. setting the full frame to an ImageView)
             * will result in a OutOfMemoryError soon. This error is reported in {@link #onTakePictureError
             * (Throwable)}
             *
             * Use a DiskCache http://developer.android.com/training/displaying-bitmaps/cache-bitmap.html#disk-cache
             * for example
             *
             */
            File outDir = new File(getCacheDir(), "ok");
            outDir.mkdir();
            // change the file ending to png if you want a png
            JSONObject jsonResult = new JSONObject();
            try {
                // convert the transformed image into a gray scaled image internally
                // transformedImage.getGrayCvMat(false);
                // get the transformed image as bitmap
                // Bitmap bmp = transformedImage.getBitmap();
                // save the image with quality 100 (only used for jpeg, ignored for png)
                File imageFile = TempFileUtil.createTempFileCheckCache(Document4Activity.this,
                        UUID.randomUUID().toString(), ".jpg");
                transformedImage.save(imageFile, quality);
                showToast(getString(
                        getResources().getIdentifier("document_image_saved_to", "string", getPackageName()))
                        + " " + imageFile.getAbsolutePath());

                jsonResult.put("imagePath", imageFile.getAbsolutePath());

                // Save the Full Frame Image
                if (fullFrame != null) {
                    imageFile = TempFileUtil.createTempFileCheckCache(Document4Activity.this,
                            UUID.randomUUID().toString(), ".jpg");
                    fullFrame.save(imageFile, quality);
                    jsonResult.put("fullImagePath", imageFile.getAbsolutePath());
                }
                // Put outline and conficence to result
                jsonResult.put("outline", jsonForOutline(documentResult.getOutline()));
                jsonResult.put("confidence", documentResult.getConfidence());
            } catch (IOException e) {
                e.printStackTrace();
            } catch (JSONException jsonException) {
                //should not be possible
                Log.e(TAG, "Error while putting image path to json.", jsonException);
            }

            // release the images
            transformedImage.release();
            fullFrame.release();

            Boolean cancelOnResult = true;

            JSONObject jsonObject;
            try {
                jsonObject = new JSONObject(configJson);
                cancelOnResult = jsonObject.getBoolean("cancelOnResult");
            } catch (Exception e) {
                Log.d(TAG, e.getLocalizedMessage());
            }

            if (cancelOnResult) {
                ResultReporter.onResult(jsonResult, true);
                setResult(AnylineSDKPlugin.RESULT_OK);
                finish();
            } else {
                ResultReporter.onResult(jsonResult, false);
            }

        }

        @Override
        public void onPreviewProcessingSuccess(AnylineImage anylineImage) {
            // this is called after the preview of the document is completed, and a full picture will be
            // processed automatically
        }

        @Override
        public void onPreviewProcessingFailure(DocumentScanViewPlugin.DocumentError documentError) {
            // this is called on any error while processing the document image
            // Note: this is called every time an error occurs in a run, so that might be quite often
            // An error message should only be presented to the user after some time

            showErrorMessageFor(documentError);
        }

        @Override
        public void onPictureProcessingFailure(DocumentScanViewPlugin.DocumentError documentError) {

            showErrorMessageFor(documentError, true);
            if (progressDialog != null && progressDialog.isShowing()) {
                progressDialog.dismiss();
            }

            // if there is a problem, here is how images could be saved in the error case
            // this will be a full, not cropped, not transformed image
            AnylineImage image = ((DocumentScanViewPlugin) documentScanView.getScanViewPlugin())
                    .getCurrentFullImage();

            if (image != null) {
                File outDir = new File(getCacheDir(), "error");
                outDir.mkdir();
                File outFile = new File(outDir,
                        "" + System.currentTimeMillis() + documentError.name() + ".jpg");
                try {
                    image.save(outFile, 100);
                    Log.d(TAG, "error image saved to " + outFile.getAbsolutePath());
                } catch (IOException e) {
                    e.printStackTrace();
                }
                image.release();
            }
        }

        @Override
        public boolean onDocumentOutlineDetected(List rect, boolean documentShapeAndBrightnessValid) {
            // is called when the outline of the document is detected. return true if the outline is consumed by
            // the implementation here, false if the outline should be drawn by the DocumentScanView
            lastOutline = rect; // saving the outline for the animations
            return true;
        }

        @Override
        public void onTakePictureSuccess() {
            // this is called after the image has been captured from the camera and is about to be processed
            progressDialog = ProgressDialog.show(Document4Activity.this,
                    getString(getResources().getIdentifier("document_processing_picture_header", "string",
                            getPackageName())),
                    getString(getResources().getIdentifier("document_processing_picture", "string",
                            getPackageName())),
                    true);

            if (errorMessageAnimator != null && errorMessageAnimator.isRunning()) {

                handler.post(new Runnable() {
                    @Override
                    public void run() {
                        errorMessageAnimator.cancel();
                        errorMessageLayout.setVisibility(View.GONE);
                    }
                });

            }
        }

        @Override
        public void onTakePictureError(Throwable throwable) {
            // This is called if the image could not be captured from the camera (most probably because of an
            // OutOfMemoryError)
            throw new RuntimeException(throwable);
        }

        @Override
        public void onPictureCornersDetected(AnylineImage anylineImage, List rect) {
            // this is called after manual corner detection was requested
            // Note: not implemented in this example
        }

        @Override
        public void onPictureTransformed(AnylineImage anylineImage) {
            // this is called after a full frame image and 4 corners were passed to the SDK for
            // transformation (e.g. when a user manually selected the corners in an image)
            // Note: not implemented in this example
        }

        @Override
        public void onPictureTransformError(DocumentScanViewPlugin.DocumentError documentError) {
            // this is called on any error while transforming the document image from the 4 corners
            // Note: not implemented in this example
        }

    });

    // optionally stop the scan once a valid result was returned
    // documentScanView.setCancelOnResult(cancelOnResult);

}

From source file:com.willowtreeapps.spurceexampleapp.fragments.ListViewFragment.java

private void initSpruce() {
    spruceAnimator = new Spruce.SpruceBuilder(listView).sortWith(new DefaultSort(100))
            .animateWith(DefaultAnimations.shrinkAnimator(listView, 800),
                    ObjectAnimator.ofFloat(listView, "translationX", -listView.getWidth(), 0f).setDuration(800))
            .start();/* w  w  w .j  a v  a 2s.c  o  m*/
}

From source file:com.crust87.centercropvideoviewsample.LoadImageTask.java

private static void fadeInView(View view) {
    ObjectAnimator fadeIn = ObjectAnimator.ofFloat(view, "alpha", 0.0f, 1f);
    fadeIn.setDuration(500);//from w w w. j a  v a  2s  .c  o  m
    AnimatorSet fadeSet = new AnimatorSet();
    fadeSet.play(fadeIn);
    fadeSet.start();
}

From source file:com.gyz.androiddevelope.view.cardslidepanel.DrawShadowFrameLayout.java

public void setShadowVisible(boolean shadowVisible, boolean animate) {
    this.mShadowVisible = shadowVisible;
    if (mAnimator != null) {
        mAnimator.cancel();/*w w w  .  ja v  a  2  s  . co m*/
        mAnimator = null;
    }

    if (animate && mShadowDrawable != null) {
        mAnimator = ObjectAnimator.ofFloat(this, SHADOW_ALPHA, shadowVisible ? 0f : 1f,
                shadowVisible ? 1f : 0f);
        mAnimator.setDuration(100);
        mAnimator.start();
    }

    ViewCompat.postInvalidateOnAnimation(this);
    setWillNotDraw(!mShadowVisible || mShadowDrawable == null);
}

From source file:com.metinkale.prayerapp.compass._2D.Frag2D.java

public void show() {
    mHidden = false;//from  w w  w  .  ja  v a 2s  . c  o m
    mCompassView.post(new Runnable() {
        @Override
        public void run() {
            ObjectAnimator scaleX = ObjectAnimator.ofFloat(mCompassView, "scaleX", 0, 1);
            ObjectAnimator scaleY = ObjectAnimator.ofFloat(mCompassView, "scaleY", 0, 1);

            ObjectAnimator scaleX2 = ObjectAnimator.ofFloat(mInfo, "scaleX", 0, 1);
            ObjectAnimator scaleY2 = ObjectAnimator.ofFloat(mInfo, "scaleY", 0, 1);
            AnimatorSet animSetXY = new AnimatorSet();
            animSetXY.playTogether(scaleX, scaleY, scaleX2, scaleY2);
            animSetXY.setInterpolator(overshootInterpolator);
            animSetXY.setDuration(300);
            animSetXY.start();
        }
    });

}

From source file:com.hippo.widget.ProgressView.java

private void setupAnimators() {
    ObjectAnimator trimStart = ObjectAnimator.ofFloat(this, "trimStart", 0.0f, 0.75f);
    trimStart.setDuration(1333L);/*from  w w  w. j  a  v a  2 s.  com*/
    trimStart.setInterpolator(TRIM_START_INTERPOLATOR);
    trimStart.setRepeatCount(Animation.INFINITE);

    ObjectAnimator trimEnd = ObjectAnimator.ofFloat(this, "trimEnd", 0.0f, 0.75f);
    trimEnd.setDuration(1333L);
    trimEnd.setInterpolator(TRIM_END_INTERPOLATOR);
    trimEnd.setRepeatCount(Animation.INFINITE);

    ObjectAnimator trimOffset = ObjectAnimator.ofFloat(this, "trimOffset", 0.0f, 0.25f);
    trimOffset.setDuration(1333L);
    trimOffset.setInterpolator(LINEAR_INTERPOLATOR);
    trimOffset.setRepeatCount(Animation.INFINITE);

    ObjectAnimator trimRotation = ObjectAnimator.ofFloat(this, "trimRotation", 0.0f, 720.0f);
    trimRotation.setDuration(6665L);
    trimRotation.setInterpolator(LINEAR_INTERPOLATOR);
    trimRotation.setRepeatCount(Animation.INFINITE);

    mAnimators.add(trimStart);
    mAnimators.add(trimEnd);
    mAnimators.add(trimOffset);
    mAnimators.add(trimRotation);
}

From source file:eu.davidea.flexibleadapter.helpers.AnimatorHelper.java

/**
 * Item will scale to {@code 1.0f}.//from w  w  w  .jav a 2s  .  co m
 *
 * @param animators user defined list
 * @param view      itemView to animate
 * @param scaleFrom initial scale value
 * @since 5.0.0-b1
 */
public static void scaleAnimator(@NonNull List<Animator> animators, @NonNull View view,
        @FloatRange(from = 0.0, to = 1.0) float scaleFrom) {
    alphaAnimator(animators, view, 0f);
    animators.add(ObjectAnimator.ofFloat(view, "scaleX", scaleFrom, 1f));
    animators.add(ObjectAnimator.ofFloat(view, "scaleY", scaleFrom, 1f));
    if (FlexibleAdapter.DEBUG)
        Log.v(TAG, "Added SCALE Animator");
}

From source file:com.negaheno.ui.IntroActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    setTheme(R.style.Theme_TMessages);/*w ww . jav  a  2 s. c  o  m*/
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);

    if (AndroidUtilities.isTablet()) {
        setContentView(R.layout.intro_layout_tablet);
    } else {
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
        setContentView(R.layout.intro_layout);
    }

    if (LocaleController.isRTL) {
        icons = new int[] { R.drawable.intro7, R.drawable.intro6, R.drawable.intro5, R.drawable.intro4,
                R.drawable.intro3, R.drawable.intro2, R.drawable.intro1 };
        titles = new int[] { R.string.Page7Title, R.string.Page6Title, R.string.Page5Title, R.string.Page4Title,
                R.string.Page3Title, R.string.Page2Title, R.string.Page1Title };
        messages = new int[] { R.string.Page7Message, R.string.Page6Message, R.string.Page5Message,
                R.string.Page4Message, R.string.Page3Message, R.string.Page2Message, R.string.Page1Message };
    } else {
        icons = new int[] { R.drawable.intro1, R.drawable.intro2, R.drawable.intro3, R.drawable.intro4,
                R.drawable.intro5, R.drawable.intro6, R.drawable.intro7 };
        titles = new int[] { R.string.Page1Title, R.string.Page2Title, R.string.Page3Title, R.string.Page4Title,
                R.string.Page5Title, R.string.Page6Title, R.string.Page7Title };
        messages = new int[] { R.string.Page1Message, R.string.Page2Message, R.string.Page3Message,
                R.string.Page4Message, R.string.Page5Message, R.string.Page6Message, R.string.Page7Message };
    }
    viewPager = (ViewPager) findViewById(R.id.intro_view_pager);
    TextView startMessagingButton = (TextView) findViewById(R.id.start_messaging_button);
    startMessagingButton
            .setText(LocaleController.getString("StartMessaging", R.string.StartMessaging).toUpperCase());
    if (Build.VERSION.SDK_INT >= 21) {
        StateListAnimator animator = new StateListAnimator();
        animator.addState(new int[] { android.R.attr.state_pressed }, ObjectAnimator
                .ofFloat(startMessagingButton, "translationZ", AndroidUtilities.dp(2), AndroidUtilities.dp(4))
                .setDuration(200));
        animator.addState(new int[] {}, ObjectAnimator
                .ofFloat(startMessagingButton, "translationZ", AndroidUtilities.dp(4), AndroidUtilities.dp(2))
                .setDuration(200));
        startMessagingButton.setStateListAnimator(animator);
    }
    topImage1 = (ImageView) findViewById(R.id.icon_image1);
    topImage2 = (ImageView) findViewById(R.id.icon_image2);
    bottomPages = (ViewGroup) findViewById(R.id.bottom_pages);
    topImage2.setVisibility(View.GONE);
    viewPager.setAdapter(new IntroAdapter());
    viewPager.setPageMargin(0);
    viewPager.setOffscreenPageLimit(1);
    viewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
        @Override
        public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

        }

        @Override
        public void onPageSelected(int i) {

        }

        @Override
        public void onPageScrollStateChanged(int i) {
            if (i == ViewPager.SCROLL_STATE_IDLE || i == ViewPager.SCROLL_STATE_SETTLING) {
                if (lastPage != viewPager.getCurrentItem()) {
                    lastPage = viewPager.getCurrentItem();

                    final ImageView fadeoutImage;
                    final ImageView fadeinImage;
                    if (topImage1.getVisibility() == View.VISIBLE) {
                        fadeoutImage = topImage1;
                        fadeinImage = topImage2;

                    } else {
                        fadeoutImage = topImage2;
                        fadeinImage = topImage1;
                    }

                    fadeinImage.bringToFront();
                    fadeinImage.setImageResource(icons[lastPage]);
                    fadeinImage.clearAnimation();
                    fadeoutImage.clearAnimation();

                    Animation outAnimation = AnimationUtils.loadAnimation(IntroActivity.this,
                            R.anim.icon_anim_fade_out);
                    outAnimation.setAnimationListener(new Animation.AnimationListener() {
                        @Override
                        public void onAnimationStart(Animation animation) {
                        }

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

                        @Override
                        public void onAnimationRepeat(Animation animation) {

                        }
                    });

                    Animation inAnimation = AnimationUtils.loadAnimation(IntroActivity.this,
                            R.anim.icon_anim_fade_in);
                    inAnimation.setAnimationListener(new Animation.AnimationListener() {
                        @Override
                        public void onAnimationStart(Animation animation) {
                            fadeinImage.setVisibility(View.VISIBLE);
                        }

                        @Override
                        public void onAnimationEnd(Animation animation) {
                        }

                        @Override
                        public void onAnimationRepeat(Animation animation) {

                        }
                    });

                    fadeoutImage.startAnimation(outAnimation);
                    fadeinImage.startAnimation(inAnimation);
                }
            }
        }
    });

    startMessagingButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if (startPressed) {
                return;
            }
            startPressed = true;
            Intent intent2 = new Intent(IntroActivity.this, LaunchActivity.class);
            intent2.putExtra("fromIntro", true);
            startActivity(intent2);
            finish();
        }
    });

    justCreated = true;
}

From source file:com.flexible.flexibleadapter.helpers.AnimatorHelper.java

/**
 * Item will scale to {@code 1.0f}.//from ww  w .  ja v  a2 s  .  c o m
 *
 * @param animators user defined list of animators
 * @param view      itemView to animate
 * @param scaleFrom initial scale value
 * @since 5.0.0-b1
 */
public static void scaleAnimator(@NonNull List<Animator> animators, @NonNull View view,
        @FloatRange(from = 0.0, to = 1.0) float scaleFrom) {
    alphaAnimator(animators, view, 0f);
    animators.add(ObjectAnimator.ofFloat(view, "scaleX", scaleFrom, 1f));
    animators.add(ObjectAnimator.ofFloat(view, "scaleY", scaleFrom, 1f));
    if (FlexibleAdapter.DEBUG)
        Log.v(TAG, " Added SCALE Animator");
}