gt:         return Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT;
context: /*
  * Part of Protocoder http://www.protocoder.org
  * A prototyping platform for Android devices 
  *
  * Copyright (C) 2013 Victor Diaz Barrales victormdb@gmail.com
  * 
  * Protocoder is free software: you can redistribute it and/or modify
  * it under the terms of the GNU Lesser General Public License as published by
  * the Free Software Foundation, either version 3 of the License, or
  * (at your option) any later version.
  *
  * Protocoder is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
  * 
  * You should have received a copy of the GNU Lesser General Public License
  * along with Protocoder. If not, see <http://www.gnu.org/licenses/>.
  */
  
  package org.protocoderrunner.utils;
  
  import android.annotation.TargetApi;
  import android.content.ContentResolver;
  import android.content.Context;
  import android.content.Intent;
  import android.content.res.Configuration;
  import android.content.res.Resources;
  import android.graphics.Bitmap;
  import android.graphics.Color;
  import android.graphics.Outline;
  import android.graphics.Path;
  import android.graphics.Rect;
  import android.media.AudioManager;
  import android.os.Build;
  import android.os.Bundle;
  import android.os.PowerManager;
  import android.provider.Settings;
  import android.util.DisplayMetrics;
  import android.view.MotionEvent;
  import android.view.View;
  import android.view.ViewOutlineProvider;
  
  import org.protocoderrunner.AppSettings;
  import org.protocoderrunner.R;
  
  import java.io.File;
  import java.io.FileNotFoundException;
  import java.io.FileOutputStream;
  import java.io.IOException;
  import java.io.OutputStream;
  import java.io.UnsupportedEncodingException;
  import java.lang.reflect.InvocationTargetException;
  import java.lang.reflect.Method;
  import java.security.MessageDigest;
  import java.security.NoSuchAlgorithmException;
  
  public class AndroidUtils {
  
      private static final String TAG = "AndroidUtils";
  
      public static void takeScreenshot(String where, String name, View v) {
  
          // image naming and path to include sd card appending name you choose
          // for file
          String mPath = where + "/" + name;
  
          // create bitmap screen capture
          Bitmap bitmap;
          View v1 = v.getRootView();
          v1.setDrawingCacheEnabled(true);
          bitmap = Bitmap.createBitmap(v1.getDrawingCache());
          v1.setDrawingCacheEnabled(false);
  
          OutputStream fout = null;
          File imageFile = new File(mPath);
  
          try {
              fout = new FileOutputStream(imageFile);
              bitmap.compress(Bitmap.CompressFormat.PNG, 90, fout);
              fout.flush();
              fout.close();
  
          } catch (FileNotFoundException e) {
              e.printStackTrace();
          } catch (IOException e) {
              e.printStackTrace();
          }
  
      }
  
      public static Bitmap takeScreenshotView(String where, String name, View v) {
  
          // image naming and path to include sd card appending name you choose
          // for file
          String mPath = where + "/" + name;
  
          // create bitmap screen capture
          Bitmap bitmap;
          v.setDrawingCacheEnabled(true);
          bitmap = Bitmap.createBitmap(v.getDrawingCache());
          v.setDrawingCacheEnabled(false);
  
          // save if path is given
          if (name.equals("") != true) {
              MLog.d("qq", mPath + "entra");
              OutputStream fout = null;
              File imageFile = new File(mPath);
  
              try {
                  fout = new FileOutputStream(imageFile);
                  bitmap.compress(Bitmap.CompressFormat.PNG, 90, fout);
                  fout.flush();
                  fout.close();
  
              } catch (FileNotFoundException e) {
                  e.printStackTrace();
              } catch (IOException e) {
                  e.printStackTrace();
              }
          }
  
          return bitmap;
  
      }
  
      public static int pixelsToDp(Context c, int px) {
  
          Resources resources = c.getResources();
          DisplayMetrics metrics = resources.getDisplayMetrics();
          float dp = px / (metrics.densityDpi / 160f);
  
          return (int) dp;
      }
  
      public static int dpToPixels(Context c, int dp) {
  
          Resources resources = c.getResources();
          DisplayMetrics metrics = resources.getDisplayMetrics();
          float px = dp * (metrics.densityDpi / 160f);
  
          return (int) px;
      }
  
      /**
       * Show an event in the LogCat view, for debugging
       */
      public static void dumpMotionEvent(MotionEvent event) {
          String names[] = {"DOWN", "UP", "MOVE", "CANCEL", "OUTSIDE", "POINTER_DOWN", "POINTER_UP", "7?", "8?", "9?"};
          StringBuilder sb = new StringBuilder();
          int action = event.getAction();
          int actionCode = action & MotionEvent.ACTION_MASK;
          sb.append("event ACTION_").append(names[actionCode]);
          if (actionCode == MotionEvent.ACTION_POINTER_DOWN || actionCode == MotionEvent.ACTION_POINTER_UP) {
              sb.append("(pid ").append(action >> MotionEvent.ACTION_POINTER_INDEX_SHIFT);
              sb.append(")");
          }
          sb.append("[");
          for (int i = 0; i < event.getPointerCount(); i++) {
              sb.append("#").append(i);
              sb.append("(pid ").append(event.getPointerId(i));
              sb.append(")=").append((int) event.getX(i));
              sb.append(",").append((int) event.getY(i));
              if (i + 1 < event.getPointerCount()) {
                  sb.append(";");
              }
          }
          sb.append("]");
          MLog.d(TAG, sb.toString());
      }
  
      public static void setViewGenericShadow(View v, int w, int h) {
          if (isVersionLollipop()) {
              setViewGenericShadow(v, CLIP_RECT, 0, 0, w, h, 10);
          }
      }
  
      public static int CLIP_RECT = 0;
      public static int CLIP_ROUND = 1;
  
      @TargetApi(Build.VERSION_CODES.LOLLIPOP)
      public static void setViewGenericShadow(View v, int type, final int x, final int y, final int w, final int h, final int r) {
          // MLog.d("qq", "no android L " + Build.VERSION.SDK + " " + L);
  
          if (isVersionLollipop()) {
  
              ViewOutlineProvider viewOutlineProvider = null;
  
              //MLog.d("qq", "is android L");
              if (type == CLIP_RECT) {
  
                  viewOutlineProvider = new ViewOutlineProvider() {
                      @Override
                      public void getOutline(View view, Outline outline) {
                          // Or read size directly from the view's width/height
                          outline.setRoundRect(new Rect(x, y, w, h), r);
                      }
                  };
  
              } else if (type == CLIP_ROUND) {
  
                  viewOutlineProvider = new ViewOutlineProvider() {
                      @Override
                      public void getOutline(View view, Outline outline) {
                          // Or read size directly from the view's width/height
                          outline.setOval(x, y, w, h);
                      }
                  };
  
  
              } else {
                  Path path = new Path();
                  path.moveTo(10, 10);
                  path.lineTo(100, 100);
                  path.lineTo(100, 200);
                  path.lineTo(10, 10);
                  path.close();
                  //outline.setConvexPath(path);
  
                  // return;
              }
              v.setClipToOutline(true);
  
              if (viewOutlineProvider != null) {
                  v.setOutlineProvider(viewOutlineProvider);
              }
              v.invalidate();
  
              //    RippleDrawable rippleDrawable = (RippleDrawable) v.getBackground();
              //     GradientDrawable rippleBackground = (GradientDrawable) rippleDrawable.getDrawable(0);
              //    rippleBackground.setColor(Color.parseColor("#FF0000"));
              //     rippleDrawable.setColor(ColorStateList.valueOf(Color.WHITE));
              // rippleDrawable.setHotspot(0, 0);
  
          }
      }
  
      public static boolean isVersionLollipop() {
          return Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP;
      }
  
      public static boolean isVersionKitKat() {
  