/* * Copyright (C) 2016 venshine.cn@gmail.com * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package cn.com.basic.face.dialog.wheelview.util; import android.content.Context; import android.text.TextUtils; import android.util.Log; import android.view.View; import android.view.ViewGroup; import android.widget.TextView; import java.util.Collection; /** * 滚轮工具类 * * @author venshine */ public class WheelUtils { private static final String TAG = "WheelView"; /** * 打印日志 * * @param msg */ public static void log(String msg) { if (!TextUtils.isEmpty(msg)) { Log.d(TAG, msg); } } /** * 判断集合是否为空 * * @param c * @param * @return */ public static boolean isEmpty(Collection c) { return (c == null || c.size() == 0); } /** * 遍历查找TextView * * @param view * @return */ public static TextView findTextView(View view) { if (view instanceof TextView) { return (TextView) view; } else { if (view instanceof ViewGroup) { return findTextView(((ViewGroup) view).getChildAt(0)); } else { return null; } } } /** * dip转换到px * * @param context * @param dp * @return */ public static int dip2px(Context context, float dp) { final float scale = context.getResources().getDisplayMetrics().density; return (int) (dp * scale + 0.5f); } /** * sp转换到px * * @param context * @param sp * @return */ public static int sp2px(Context context, float sp) { final float fontScale = context.getResources().getDisplayMetrics().scaledDensity; return (int) (sp * fontScale + 0.5f); } }