content: /*
   * Copyright (C) 2015-present, Ant Financial Services Group
   *
   * 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 com.alipay.hulu.common.utils;
  
  import android.content.res.Resources;
  
  import com.google.android.material.tabs.TabLayout;
  import android.util.TypedValue;
  import android.view.View;
  import android.widget.LinearLayout;
  
  import java.lang.reflect.Field;
  
  /**
   * Created by lezhou.wyl on 2018/1/11.
   */
  
  public class MiscUtil {
      private static final String TAG = "MiscUtil";
  
      public static void sleep(long time) {
          try {
              Thread.sleep(time);
          } catch (InterruptedException e) {
              LogUtil.e(TAG, "Sleep cause Exception: " + e.getLocalizedMessage(), e);
          }
      }
  
      public static String stackTraceToString(StackTraceElement[] stackTraceElements) {
          if (stackTraceElements == null || stackTraceElements.length <= 0) {
              return "";
          }
  
          StringBuilder sb = new StringBuilder();
          for (StackTraceElement element : stackTraceElements) {
              sb.append(element.toString());
              sb.append("\n");
          }
          return sb.toString();
      }
  
      public static String getCurrentStrackTraceString() {
          return stackTraceToString(Thread.currentThread().getStackTrace());
      }
  
  
      public interface LogCallback {
          void onLogFinished();
      }
  
      public static void setIndicator(TabLayout tabs, int leftDip, int rightDip) {
          Class<?> tabLayout = tabs.getClass();
          Field tabStrip;
          try {
              tabStrip = tabLayout.getDeclaredField("mTabStrip");
          } catch (NoSuchFieldException e) {
              return;
          }
  
          tabStrip.setAccessible(true);
          LinearLayout llTab;
          try {
              llTab = (LinearLayout) tabStrip.get(tabs);
          } catch (IllegalAccessException e) {
              return;
          }
  
          int left = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, leftDip, Resources.getSystem().getDisplayMetrics());
          int right = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, rightDip, Resources.getSystem().getDisplayMetrics());
  
          for (int i = 0; i < llTab.getChildCount(); i++) {
              View child = llTab.getChildAt(i);
              child.setPadding(0, 0, 0, 0);
              LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.MATCH_PARENT, 1);
              params.leftMargin = left;
              params.rightMargin = right;
              child.setLayoutParams(params);
              child.invalidate();
          }
      }
  }
  