/*
 * COPYRIGHT (c) 2018 All rights reserved by HANWHA LIFE.
 */
package kr.co.zumo.app.lifeplus.util;

import android.content.res.ColorStateList;
import android.support.annotation.ArrayRes;
import android.support.annotation.ColorRes;
import android.support.annotation.IdRes;
import android.support.annotation.StringRes;
import android.util.TypedValue;

import kr.co.zumo.app.lifeplus.application.App;

/**
 * ResourceUtil
 * <pre>
 * </pre>
 *
 * @author 민효동
 * @version 1.0
 * @history 민효동   [2018. 9. 12.]   [최초 작성]
 * @since 2018. 9. 12.
 */
public class ResourceUtil {

  /**
   * 뷰 찾기
   *
   * @param idName "title"
   * @return R.id.title
   */
  @IdRes
  public static int getId(String idName) {
    return App.getInstance().getContext().getResources().getIdentifier(idName, "id", App.getInstance().getPackageName());
  }

  /**
   * string resId 로 text 가져오기
   *
   * @param resId R.string.name
   * @return "text"
   */
  public static String getString(@StringRes int resId) {
    return App.getInstance().getString(resId);
  }

  /**
   * string resId 로 text 가져오기
   *
   * @param resId      R.string.name
   * @param formatArgs The format arguments that will be used for
   *                   substitution.
   * @return The string data associated with the resource, formatted and
   * stripped of styled text information.
   */
  public static String getString(@StringRes int resId, Object... formatArgs) {
    return App.getInstance().getContext().getString(resId, formatArgs);
  }

  /**
   * array 가져오기
   *
   * @param idName "mobile_company"
   * @return ["1", "2", ...]
   */
  public static String[] getStringArray(String idName) {
    @ArrayRes int resId = App.getInstance().getContext().getResources().getIdentifier(idName, "array", App.getInstance().getPackageName());
    return App.getInstance().getResources().getStringArray(resId);
  }

  /**
   * color 가져오기
   *
   * @param colorId
   * @return
   */
  public static int getColor(@ColorRes int colorId) {
    return App.getInstance().getContext().getResources().getColor(colorId);
  }

  /**
   * color 가져오기
   *
   * @param colorId
   * @return
   */
  public static ColorStateList getColorStateList(@ColorRes int colorId) {
    return App.getInstance().getContext().getResources().getColorStateList(colorId);
  }


  /**
   * DP to pixel
   *
   * @param dp
   * @return
   */
  public static int dpToPx(float dp) {
    //(dp * App.getInstance().getContext().getResources().getDisplayMetrics().density + 0.5f);
    return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp, App.getInstance().getContext().getResources().getDisplayMetrics());
  }

}
