package com.base.browserwhite.ui.activity;

import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.ObjectAnimator;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Intent;
import android.content.res.Resources;
import android.graphics.Color;
import android.os.Build;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.util.Log;
import android.util.TypedValue;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.SearchView;
import androidx.appcompat.widget.Toolbar;
import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.coordinatorlayout.widget.CoordinatorLayout;
import androidx.fragment.app.FragmentManager;

import com.base.browserwhite.MyApplication;
import com.base.browserwhite.R;
import com.base.browserwhite.utils.BarUtils;
import com.google.android.material.appbar.AppBarLayout;

public class SearchActivity extends AppCompatActivity {
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        BarUtils.INSTANCE.setStatusBarLightMode(this, true);
        BarUtils.INSTANCE.setStatusBarColor(this, Color.TRANSPARENT);
        setContentView(R.layout.activity_search);
    }

    @SuppressLint("MissingSuperCall")
    @Override
    public void onBackPressed() {
        finish();
        setResult(10086);
        overridePendingTransition(0, 0);
    }


    public static void startActivityWithButtonAnimation(Activity currentActivity, View button) {

        Log.d("glc","getHeight:"+-button.getHeight());
        Log.d("glc","getHeight:"+(-button.getHeight()-32f));
        int finalPosition = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 48, currentActivity.getResources().getDisplayMetrics());

        ObjectAnimator animator = ObjectAnimator.ofFloat(button, "translationY", button.getTranslationY(), -finalPosition);
        animator.setDuration(500);
        animator.addListener(new Animator.AnimatorListener() {
            @Override
            public void onAnimationStart(Animator animation) {

            }

            @Override
            public void onAnimationEnd(Animator animation) {
                button.setVisibility(View.VISIBLE);
                Intent intent = new Intent(currentActivity, SearchActivity.class);
                currentActivity.startActivityForResult(intent, 10086);
                currentActivity.overridePendingTransition(R.anim.fade_in, R.anim.fade_out);
            }

            @Override
            public void onAnimationCancel(Animator animation) {
            }

            @Override
            public void onAnimationRepeat(Animator animation) {
            }
        });

        animator.start();
    }
}
