List of usage examples for android.util Log i
public static int i(String tag, String msg)
From source file:Main.java
public static Point findBestPreviewSizeValue(Camera.Parameters parameters, Point screenResolution) { List<Camera.Size> rawSupportedSizes = parameters.getSupportedPreviewSizes(); if (rawSupportedSizes == null) { Log.w(TAG, "Device returned no supported preview sizes; using default"); Camera.Size defaultSize = parameters.getPreviewSize(); if (defaultSize == null) { throw new IllegalStateException("Parameters contained no preview size!"); }//from ww w . j a v a 2 s . c om return new Point(defaultSize.width, defaultSize.height); } // Sort by size, descending List<Camera.Size> supportedPreviewSizes = new ArrayList<Camera.Size>(rawSupportedSizes); Collections.sort(supportedPreviewSizes, new Comparator<Camera.Size>() { @Override public int compare(Camera.Size a, Camera.Size b) { int aPixels = a.height * a.width; int bPixels = b.height * b.width; if (bPixels < aPixels) { return -1; } if (bPixels > aPixels) { return 1; } return 0; } }); if (Log.isLoggable(TAG, Log.INFO)) { StringBuilder previewSizesString = new StringBuilder(); for (Camera.Size supportedPreviewSize : supportedPreviewSizes) { previewSizesString.append(supportedPreviewSize.width).append('x') .append(supportedPreviewSize.height).append(' '); } Log.i(TAG, "Supported preview sizes: " + previewSizesString); } double screenAspectRatio = (double) screenResolution.x / (double) screenResolution.y; // Remove sizes that are unsuitable Iterator<Camera.Size> it = supportedPreviewSizes.iterator(); while (it.hasNext()) { Camera.Size supportedPreviewSize = it.next(); int realWidth = supportedPreviewSize.width; int realHeight = supportedPreviewSize.height; if (realWidth * realHeight < MIN_PREVIEW_PIXELS) { it.remove(); continue; } boolean isCandidatePortrait = realWidth < realHeight; int maybeFlippedWidth = isCandidatePortrait ? realHeight : realWidth; int maybeFlippedHeight = isCandidatePortrait ? realWidth : realHeight; double aspectRatio = (double) maybeFlippedWidth / (double) maybeFlippedHeight; double distortion = Math.abs(aspectRatio - screenAspectRatio); if (distortion > MAX_ASPECT_DISTORTION) { it.remove(); continue; } if (maybeFlippedWidth == screenResolution.x && maybeFlippedHeight == screenResolution.y) { Point exactPoint = new Point(realWidth, realHeight); Log.i(TAG, "Found preview size exactly matching screen size: " + exactPoint); return exactPoint; } } // If no exact match, use largest preview size. This was not a great idea on older devices because // of the additional computation needed. We're likely to get here on newer Android 4+ devices, where // the CPU is much more powerful. if (!supportedPreviewSizes.isEmpty()) { Camera.Size largestPreview = supportedPreviewSizes.get(0); Point largestSize = new Point(largestPreview.width, largestPreview.height); Log.i(TAG, "Using largest suitable preview size: " + largestSize); return largestSize; } // If there is nothing at all suitable, return current preview size Camera.Size defaultPreview = parameters.getPreviewSize(); if (defaultPreview == null) { throw new IllegalStateException("Parameters contained no preview size!"); } Point defaultSize = new Point(defaultPreview.width, defaultPreview.height); Log.i(TAG, "No suitable preview sizes, using default: " + defaultSize); return defaultSize; }
From source file:me.ziccard.secureit.async.upload.DelegatedPositionUploaderTask.java
@Override protected Void doInBackground(Void... params) { while (true) { Log.i("DelegatedPositionUploaderTask", "Started"); HttpClient client = new DefaultHttpClient(); /*/*from w w w . j av a2 s . c o m*/ * Send the last * detected position to /phone/phoneId/position [POST] */ HttpPost request = new HttpPost( Remote.HOST + Remote.PHONES + "/" + phoneId + Remote.DELEGATED_UPLOAD_POSITION); /* * Adding latitude and longitude */ List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2); nameValuePairs.add(new BasicNameValuePair("lat", "" + lat)); nameValuePairs.add(new BasicNameValuePair("long", "" + lng)); nameValuePairs.add(new BasicNameValuePair("access_key", accessKey)); try { request.setEntity(new UrlEncodedFormEntity(nameValuePairs)); HttpResponse response = client.execute(request); BufferedReader reader = new BufferedReader( new InputStreamReader(response.getEntity().getContent(), "UTF-8")); StringBuilder builder = new StringBuilder(); for (String line = null; (line = reader.readLine()) != null;) { builder.append(line).append("\n"); } Log.i("PeriodicPositionUploaderTask", "Response:\n" + builder.toString()); if (response.getStatusLine().getStatusCode() != 200) { throw new HttpException(); } } catch (Exception e) { Log.e("DelegatedPositionUploaderTask", "Error uploading delegated location"); } } }
From source file:org.artags.android.app.util.http.HttpUtil.java
/** * Post data and attachements//from ww w . ja v a 2 s . co m * @param url The POST url * @param params Parameters * @param files Files * @return The return value * @throws HttpException If an error occurs */ public static String post(String url, HashMap<String, String> params, HashMap<String, File> files) throws HttpException { String ret = ""; try { HttpClient client = new DefaultHttpClient(); HttpPost post = new HttpPost(url); MultipartEntity reqEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE); for (String key : files.keySet()) { FileBody bin = new FileBody(files.get(key)); reqEntity.addPart(key, bin); } for (String key : params.keySet()) { String val = params.get(key); reqEntity.addPart(key, new StringBody(val, Charset.forName("UTF-8"))); } post.setEntity(reqEntity); HttpResponse response = client.execute(post); HttpEntity resEntity = response.getEntity(); if (resEntity != null) { ret = EntityUtils.toString(resEntity); Log.i("ARTags:HttpUtil:Post:Response", ret); } //return response; } catch (Exception e) { Log.e("ARTags:HttpUtil", "Error : " + e.getMessage()); throw new HttpException(e.getMessage()); } return ret; }
From source file:org.zywx.wbpalmstar.platform.push.PushEngineEventListener.java
@Override public void onWidgetStart(int wgtType, WWidgetData wgtData, Context context) { Log.i("push", "wgtType==" + wgtType); if (wgtType == WGT_TYPE_MAIN) { wgtData.m_appkey = EUExUtil.getString("appkey"); wgtData.m_appkey = PushReportUtility.decodeStr(wgtData.m_appkey); // PushReportAgent.m_appId = wgtData.m_appId; // PushReportAgent.m_appKey = wgtData.m_appkey; PushReportAgent.mCurWgt = wgtData; pushReportAgent.initPush(wgtData, context); Log.i("zyp", "Push onMainWidgetStart"); }// www . j a va 2s . c o m }
From source file:com.feedhenry.apps.BlankNativeAndroidApp.FHStarterActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_fhstarter); //call FH.init to initialize FH service FH.init(this, new FHActCallback() { @Override/*ww w . j av a 2s . co m*/ public void success(FHResponse resp) { //NOTE: other FH methods can only be called after FH.init succeeds Log.i("init", "Hi. I have just successfully done an init"); try { callCloud(); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } try { loginWithFh(); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } @Override public void fail(FHResponse arg0) { Log.i("init", "YOU HAVE FAIL"); } }); }
From source file:ca.ualberta.cs.swapmyride.Misc.DeletePhotoRunnable.java
public void run() { HttpClient httpClient = new DefaultHttpClient(); HttpDelete httpDelete = new HttpDelete(url); httpDelete.setHeader("Accept", "application/json"); try {//from ww w. j a v a 2s . co m HttpResponse response = httpClient.execute(httpDelete); String status = response.getStatusLine().toString(); Log.i("NetworkDataManager", status); } catch (Exception e) { e.printStackTrace(); } }
From source file:at.tugraz.ist.catroid.test.utils.XMLValidationUtil.java
public static void sendProjectXMLToServerForValidating(String fullPathFilename) throws IOException, JSONException { String xmlContent = readTextFile(fullPathFilename); HashMap<String, String> postValues = new HashMap<String, String>(); postValues.put("xmlToValidate", xmlContent); ConnectionWrapper connection = new ConnectionWrapper(); String responce = connection.doHttpPost(XML_VALIDATING_URL, postValues); JSONObject jsonResponce = new JSONObject(responce); Log.i(LOG_TAG, "json responce: " + jsonResponce.toString()); boolean valid = jsonResponce.getBoolean("valid"); String message = jsonResponce.optString("message"); Assert.assertTrue(message, valid);/*from w ww. java2 s.co m*/ }
From source file:at.bitfire.davdroid.webdav.DavRedirectStrategy.java
@Override public HttpUriRequest getRedirect(HttpRequest request, HttpResponse response, HttpContext context) throws ProtocolException { RequestLine line = request.getRequestLine(); String location = getLocation(request, response, context).toString(); Log.i(TAG, "Following redirection: " + line.getMethod() + " " + line.getUri() + " -> " + location); return RequestBuilder.copy(request).setUri(location).removeHeaders("Content-Length") // Content-Length will be set again automatically, if required; // remove it now to avoid duplicate header .build();//from w ww.ja v a2 s . c o m }
From source file:org.lol.reddit.receivers.NewMessageChecker.java
public static void checkForNewMessages(Context context) { Log.i("RedReader", "Checking for new messages."); boolean notificationsEnabled = PrefsUtility.pref_behaviour_notifications(context, PreferenceManager.getDefaultSharedPreferences(context)); if (!notificationsEnabled) return;//from w ww . java 2 s . com final RedditAccount user = RedditAccountManager.getInstance(context).getDefaultAccount(); if (user.isAnonymous()) { return; } final CacheManager cm = CacheManager.getInstance(context); final URI url = Constants.Reddit.getUri("/message/unread.json?limit=2"); final CacheRequest request = new CacheRequest(url, user, null, Constants.Priority.API_INBOX_LIST, 0, CacheRequest.DownloadType.FORCE, Constants.FileType.INBOX_LIST, true, true, true, context) { @Override protected void onDownloadNecessary() { } @Override protected void onDownloadStarted() { } @Override protected void onCallbackException(final Throwable t) { BugReportActivity.handleGlobalError(context, t); } @Override protected void onFailure(final RequestFailureType type, final Throwable t, final StatusLine status, final String readableMessage) { Log.e("NewMessageChecker", "Request failed", t); } @Override protected void onProgress(final long bytesRead, final long totalBytes) { } @Override protected void onSuccess(final CacheManager.ReadableCacheFile cacheFile, final long timestamp, final UUID session, final boolean fromCache, final String mimetype) { } @Override public void onJsonParseStarted(final JsonValue value, final long timestamp, final UUID session, final boolean fromCache) { try { final JsonBufferedObject root = value.asObject(); final JsonBufferedObject data = root.getObject("data"); final JsonBufferedArray children = data.getArray("children"); children.join(); final int messageCount = children.getCurrentItemCount(); if (messageCount < 1) { return; } final RedditThing thing = children.get(0).asObject(RedditThing.class); String title; final String text = context.getString(R.string.notification_message_action); final String messageID; final long messageTimestamp; switch (thing.getKind()) { case COMMENT: { final RedditComment comment = thing.asComment(); title = comment.author + " " + context.getString(R.string.notification_comment); messageID = comment.name; messageTimestamp = comment.created_utc; break; } case MESSAGE: { final RedditMessage message = thing.asMessage(); title = message.author + " " + context.getString(R.string.notification_message); messageID = message.name; messageTimestamp = message.created_utc; break; } default: { throw new RuntimeException("Unknown item in list."); } } // Check if the previously saved message is the same as the one we just received final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); final String oldMessageId = prefs.getString(PREFS_SAVED_MESSAGE_ID, ""); final long oldMessageTimestamp = prefs.getLong(PREFS_SAVED_MESSAGE_TIMESTAMP, 0); if (oldMessageId == null || (!messageID.equals(oldMessageId) && oldMessageTimestamp <= messageTimestamp)) { prefs.edit().putString(PREFS_SAVED_MESSAGE_ID, messageID) .putLong(PREFS_SAVED_MESSAGE_TIMESTAMP, messageTimestamp).commit(); if (messageCount > 1) { title = context.getString(R.string.notification_message_multiple); } createNotification(title, text, context); } } catch (Throwable t) { notifyFailure(RequestFailureType.PARSE, t, null, "Parse failure"); } } }; cm.makeRequest(request); }