List of usage examples for android.util Log v
public static int v(String tag, String msg)
From source file:Main.java
/** * Scales an image maintaining aspect ratio * * @param original original image//from ww w . j a va 2 s .co m * @param maxWidth maximum width * @param maxHeight maximum height * @return a Bitmap representing the thumbnail */ public static Bitmap createThumbnailForImage(Bitmap original, int maxWidth, int maxHeight) { int width = original.getWidth(); int height = original.getHeight(); Log.v("Pictures", "Width and height are " + width + "--" + height); if (width > height) { // landscape float ratio = (float) width / maxWidth; width = maxWidth; height = (int) (height / ratio); } else if (height > width) { // portrait float ratio = (float) height / maxHeight; height = maxHeight; width = (int) (width / ratio); } else { // square height = maxHeight; width = maxWidth; } Log.v("Pictures", "after scaling Width and height are " + width + "--" + height); return Bitmap.createScaledBitmap(original, width, height, true); }
From source file:Main.java
public static byte[] makeFontBitmap(String font, String code, int size, float[] arrayOfPos) { Log.v(TAG, String.format("makeFontBitmap called(Java): font=%s code=%s", font, code)); Canvas c = new Canvas(); Paint p = new Paint(); // Log.v(TAG, "get density"); float density = context.getResources().getDisplayMetrics().density; Log.v(TAG, String.format("makeFontBitmap density: %f", density)); p.setTextSize((float) size * density); p.setAntiAlias(true);/* ww w .ja va2 s . c o m*/ Rect textBounds = new Rect(); p.getTextBounds(code, 0, code.length(), textBounds); Log.v(TAG, String.format("makeFontBitmap textBounds: %d,%d,%d,%d", textBounds.left, textBounds.top, textBounds.right, textBounds.bottom)); Rect textBoundsAxA = new Rect(); String axa = String.format("A%sA", code); p.getTextBounds(axa, 0, axa.length(), textBoundsAxA); Rect textBoundsAA = new Rect(); String aa = "AA"; p.getTextBounds(aa, 0, aa.length(), textBoundsAA); // cache.distDelta = Vec2(0, 0); arrayOfPos[0] = textBounds.left; arrayOfPos[1] = textBounds.top; // cache.srcWidth = Vec2(16, 16); arrayOfPos[2] = textBounds.width(); arrayOfPos[3] = textBounds.height(); // cache.step = 16; // arrayOfPos[4] = textBounds.width() + 1; arrayOfPos[4] = textBoundsAxA.width() - textBoundsAA.width(); if (textBounds.width() == 0 || textBounds.height() == 0) { Log.v(TAG, "makeFontBitmap: empty"); return null; } Bitmap b = Bitmap.createBitmap(textBounds.width(), textBounds.height(), Bitmap.Config.ARGB_8888); c.setBitmap(b); Rect r = new Rect(0, 0, textBounds.width(), textBounds.height()); // p.setColor(Color.RED); p.setARGB(0, 0, 0, 0); c.drawRect(r, p); p.setARGB(255, 255, 255, 255); // Log.v(TAG, "makeFontBitmap: drawText"); c.drawText(code, -textBounds.left, -textBounds.top, p); Log.v(TAG, String.format("makeFontBitmap: w=%.2f h=%.2f", arrayOfPos[2], arrayOfPos[3])); ByteBuffer buf = ByteBuffer.allocate(textBounds.width() * textBounds.height() * 4); // ByteBuffer buf = ByteBuffer.allocate(b.getRowBytes()); Log.v(TAG, String.format("makeFontBitmap: b.getRowBytes() %d", b.getRowBytes())); buf.position(0); b.copyPixelsToBuffer(buf); Log.v(TAG, String.format("makeFontBitmap results: capacity=%d", buf.capacity())); // byte bytes[] = buf.array(); // for (int i = 0; i < size * size * 2; i++) // bytes[i] = (byte)(Math.random() * 255); return buf.array(); }
From source file:Main.java
public static String downloadPage(String url) { Log.v(DEBUG_TAG, url); String page = ""; BufferedReader in = null;//from ww w .java 2 s . c o m try { HttpClient client = new DefaultHttpClient(); HttpGet request = new HttpGet(url); HttpParams params = request.getParams(); HttpConnectionParams.setSoTimeout(params, 60000); // 1 minute timeout HttpResponse response = client.execute(request); //Predifined buffer size /* * in = new BufferedReader( new InputStreamReader( response.getEntity().getContent()),8*2000); * * */ in = new BufferedReader(new InputStreamReader(response.getEntity().getContent())); StringBuffer sb = new StringBuffer(""); String line = ""; //String NL = System.getProperty("line.separator"); while ((line = in.readLine()) != null) { sb.append(line); } in.close(); page = sb.toString(); Log.v(DEBUG_TAG, "Pagina descargada --> " + page); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } finally { if (in != null) { try { in.close(); } catch (IOException e) { Log.v(DEBUG_TAG, "Error en la descarga de la pagina"); e.printStackTrace(); } } } return page; }
From source file:Main.java
public static String makeRequest1(String url, String json) { Log.v(TAG, "URL-->" + url); Log.v(TAG, "input-->" + json); try {//w ww .j a v a 2 s. c o m HttpPost httpPost = new HttpPost(url); httpPost.setEntity(new StringEntity(json)); HttpResponse httpResponse = new DefaultHttpClient().execute(httpPost); // receive response as inputStream InputStream inputStream = httpResponse.getEntity().getContent(); // convert inputstream to string if (inputStream != null) { String result = convertInputStreamToString(inputStream); Log.v(TAG, "output-->" + result); return result; } } catch (UnsupportedEncodingException e) { e.printStackTrace(); } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return ""; }
From source file:Main.java
static public void setImageColor(ImageView view, Bitmap sourceBitmap, int rgbcolor)// ,Bitmap sourceBitmap) { if (sourceBitmap != null) { float R = Color.red(rgbcolor); float G = Color.green(rgbcolor); float B = Color.blue(rgbcolor); Log.v("R:G:B", R + ":" + G + ":" + B); // float[] colorTransform = { R / 255f, 0, 0, 0, 0, // R color 0, G / 255f, 0, 0, 0 // G color , 0, 0, B / 255f, 0, 0 // B color , 0, 0, 0, 1f, 0f };//from w ww . j a v a 2 s .c o m ColorMatrix colorMatrix = new ColorMatrix(); colorMatrix.setSaturation(0f); // Remove Colour colorMatrix.set(colorTransform); ColorMatrixColorFilter colorFilter = new ColorMatrixColorFilter(colorMatrix); Paint paint = new Paint(); paint.setColorFilter(colorFilter); Bitmap mutableBitmap = sourceBitmap.copy(Bitmap.Config.ARGB_8888, true); view.setImageBitmap(mutableBitmap); Canvas canvas = new Canvas(mutableBitmap); canvas.drawBitmap(mutableBitmap, 0, 0, paint); } }
From source file:Main.java
public static String makeRequest3(String url, String json) { Log.v(TAG, "URL-->" + url); Log.v(TAG, "input-->" + json); try {//from www. ja va 2 s .c om HttpPost httpPost = new HttpPost(url); httpPost.setEntity(new StringEntity(json)); //httpPost.setHeader("sessionToken",AuthToken); // httpPost.setHeader("Accept", "application/json"); // httpPost.setHeader("Content-type", "application/json"); //text/html HttpResponse httpResponse = new DefaultHttpClient().execute(httpPost); // receive response as inputStream InputStream inputStream = httpResponse.getEntity().getContent(); // convert inputstream to string if (inputStream != null) { String result = convertInputStreamToString(inputStream); Log.d("tag", "outputtttttttttt-->" + result); return result; } } catch (UnsupportedEncodingException e) { e.printStackTrace(); } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return ""; }
From source file:Main.java
public static String makeRequest55(String url, String json) { Log.v(TAG, "URL-->" + url); Log.v(TAG, "input-->" + json); try {//from w ww. jav a 2 s. c om HttpPost httpPost = new HttpPost(url); httpPost.setEntity(new StringEntity(json)); httpPost.setHeader("Accept", "application/json"); httpPost.setHeader("Content-type", "application/json"); //text/html HttpResponse httpResponse = new DefaultHttpClient().execute(httpPost); // receive response as inputStream InputStream inputStream = httpResponse.getEntity().getContent(); // convert inputstream to string if (inputStream != null) { String result = convertInputStreamToString(inputStream); Log.v(TAG, "output-->" + result); return result; } } catch (UnsupportedEncodingException e) { e.printStackTrace(); } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return ""; }
From source file:Main.java
public static String makeRequest(String url, String json) { Log.v(TAG, "URL-->" + url); Log.v(TAG, "input-->" + json); try {// w ww. j a v a 2s .c o m HttpPost httpPost = new HttpPost(url); httpPost.setEntity(new StringEntity(json)); httpPost.setHeader("Accept", "application/json"); httpPost.setHeader("Content-type", "application/json"); httpPost.setHeader("sessionToken", "61"); //text/html HttpResponse httpResponse = new DefaultHttpClient().execute(httpPost); // receive response as inputStream InputStream inputStream = httpResponse.getEntity().getContent(); // convert inputstream to string if (inputStream != null) { String result = convertInputStreamToString(inputStream); Log.v(TAG, "output-->" + result); return result; } } catch (UnsupportedEncodingException e) { e.printStackTrace(); } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return ""; }
From source file:Main.java
/** * Converts time to a string, e.g. "1:59:30.1" * or "3.6" or "5:33.2"./* ww w .j a v a 2 s . co m*/ * Rolled my own because JDK 7's DateFormat class seemed * to require some unnatural contortions. JDK 8 has a much * richer library. * * @param milliseconds Time in millseconds since start of meeting * @return String formatted time interval string in "H:MM:SS.m" format. */ public static String timeToHMMSSm(long milliseconds) { Log.v(TAG, "timeToHMMSSm(" + milliseconds + ")"); double seconds = (milliseconds % 60_000) / 1000.0; int minutes = (int) (milliseconds / 60_000) % 60; int hours = (int) (milliseconds / 3600_000); String hms; if (hours >= 1) { hms = String.format(Locale.getDefault(), "%d:%02d:%04.1f", hours, minutes, seconds); } else if (minutes >= 1) { hms = String.format(Locale.getDefault(), "%d:%04.1f", minutes, seconds); } else { hms = String.format(Locale.getDefault(), "%1.1f", seconds); } return hms; }
From source file:Main.java
/** * Check to see if the network is available. * @return true if there is access to the internet, false otherwise. *///from w w w. j a v a2 s. co m public static boolean isNetworkAvailable(Context context) { ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo info = manager.getActiveNetworkInfo(); boolean isAvailable = false; if (info != null && info.isConnected()) { isAvailable = true; } Log.v("TheNetUtil", "isNetworkAvailable(). net is " + isAvailable); return isAvailable; }