package com.p3.bewoplaner.utils.ui;

import com.p3.bewoplaner.R;

import android.app.Activity;
import android.content.Context;
import android.graphics.PorterDuff;
import android.os.Build;
import android.support.v4.content.ContextCompat;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.ProgressBar;


/**
 * Helper methods for view related classes
 * <p>
 * Created by BoldijarPaul on 03/08/16.
 */
public abstract class ViewUtils {

    private ViewUtils() {

    }

    public static void setProgressBarColorToOrange(ProgressBar progressBar) {
        setProgressBarColor(progressBar, R.color.colorDefault);
    }

    public static void setProgressBarColor(ProgressBar progressBar, int color) {
        if (progressBar == null) {
            return;
        }
        Context context = progressBar.getContext();
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
            progressBar.getIndeterminateDrawable().mutate()
                    .setColorFilter(ContextCompat.getColor(context, color), PorterDuff.Mode.SRC_IN);
            return;
        }
        progressBar.getIndeterminateDrawable().setColorFilter(
                ContextCompat.getColor(context, color), PorterDuff.Mode.SRC_IN);
    }

    public static void hideKeyboard(Activity activity) {
        InputMethodManager imm = (InputMethodManager) activity.getSystemService(Activity.INPUT_METHOD_SERVICE);
        View view = activity.getCurrentFocus();
        if (view == null) {
            view = new View(activity);
        }
        imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
    }

}
