List of usage examples for android.net Uri toString
public abstract String toString();
From source file:com.tuxpan.foregroundcameragalleryplugin.ForegroundCameraLauncher.java
/** * Called when the camera view exits./*from w w w. j av a 2 s. c o m*/ * * @param requestCode The request code originally supplied to startActivityForResult(), * allowing you to identify who this result came from. * @param resultCode The integer result code returned by the child activity through its setResult(). * @param intent An Intent, which can return result data to the caller (various data can be attached to Intent "extras"). */ public void onActivityResult(int requestCode, int resultCode, Intent intent) { // Get src and dest types from request code int srcType = (requestCode / 16) - 1; int destType = (requestCode % 16) - 1; int rotate = 0; // If CAMERA if (srcType == CAMERA) { // If image available if (resultCode == Activity.RESULT_OK) { try { // Create an ExifHelper to save the exif data that is lost during compression ExifHelper exif = new ExifHelper(); try { if (this.encodingType == JPEG) { exif.createInFile(getTempDirectoryPath() + "/.Pic.jpg"); exif.readExifData(); rotate = exif.getOrientation(); } } catch (IOException e) { e.printStackTrace(); } Bitmap bitmap = null; Uri uri = null; // If sending base64 image back if (destType == DATA_URL) { bitmap = getScaledBitmap(FileHelper.stripFileProtocol(imageUri.toString())); if (bitmap == null) { // Try to get the bitmap from intent. bitmap = (Bitmap) intent.getExtras().get("data"); } // Double-check the bitmap. if (bitmap == null) { Log.d(LOG_TAG, "I either have a null image path or bitmap"); this.failPicture("Unable to create bitmap!"); return; } if (rotate != 0 && this.correctOrientation) { bitmap = getRotatedBitmap(rotate, bitmap, exif); } this.processPicture(bitmap); checkForDuplicateImage(DATA_URL); } // If sending filename back else if (destType == FILE_URI || destType == NATIVE_URI) { if (this.saveToPhotoAlbum) { Uri inputUri = getUriFromMediaStore(); //Just because we have a media URI doesn't mean we have a real file, we need to make it uri = Uri.fromFile(new File(FileHelper.getRealPath(inputUri, this.cordova))); } else { uri = Uri.fromFile( new File(getTempDirectoryPath(), System.currentTimeMillis() + ".jpg")); } if (uri == null) { this.failPicture("Error capturing image - no media storage found."); } // If all this is true we shouldn't compress the image. if (this.targetHeight == -1 && this.targetWidth == -1 && this.mQuality == 100 && !this.correctOrientation) { writeUncompressedImage(uri); this.callbackContext.success(uri.toString()); } else { bitmap = getScaledBitmap(FileHelper.stripFileProtocol(imageUri.toString())); if (rotate != 0 && this.correctOrientation) { bitmap = getRotatedBitmap(rotate, bitmap, exif); } // Add compressed version of captured image to returned media store Uri OutputStream os = this.cordova.getActivity().getContentResolver().openOutputStream(uri); bitmap.compress(Bitmap.CompressFormat.JPEG, this.mQuality, os); os.close(); // Restore exif data to file if (this.encodingType == JPEG) { String exifPath; if (this.saveToPhotoAlbum) { exifPath = FileHelper.getRealPath(uri, this.cordova); } else { exifPath = uri.getPath(); } exif.createOutFile(exifPath); exif.writeExifData(); } } // Send Uri back to JavaScript for viewing image this.callbackContext.success(uri.toString()); } this.cleanup(FILE_URI, this.imageUri, uri, bitmap); bitmap = null; } catch (IOException e) { e.printStackTrace(); this.failPicture("Error capturing image."); } } // If cancelled else if (resultCode == Activity.RESULT_CANCELED) { this.failPicture("Camera cancelled."); } // If something else else { this.failPicture("Did not complete!"); } } // If retrieving photo from library else if ((srcType == PHOTOLIBRARY) || (srcType == SAVEDPHOTOALBUM)) { if (resultCode == Activity.RESULT_OK) { Uri uri = intent.getData(); // If you ask for video or all media type you will automatically get back a file URI // and there will be no attempt to resize any returned data if (this.mediaType != PICTURE) { this.callbackContext.success(uri.toString()); } else { // This is a special case to just return the path as no scaling, // rotating, nor compressing needs to be done if (this.targetHeight == -1 && this.targetWidth == -1 && (destType == FILE_URI || destType == NATIVE_URI) && !this.correctOrientation) { this.callbackContext.success(uri.toString()); } else { String uriString = uri.toString(); // Get the path to the image. Makes loading so much easier. String mimeType = FileHelper.getMimeType(uriString, this.cordova); // If we don't have a valid image so quit. if (!("image/jpeg".equalsIgnoreCase(mimeType) || "image/png".equalsIgnoreCase(mimeType))) { Log.d(LOG_TAG, "I either have a null image path or bitmap"); this.failPicture("Unable to retrieve path to picture!"); return; } Bitmap bitmap = null; try { bitmap = getScaledBitmap(uriString); } catch (IOException e) { e.printStackTrace(); } if (bitmap == null) { Log.d(LOG_TAG, "I either have a null image path or bitmap"); this.failPicture("Unable to create bitmap!"); return; } if (this.correctOrientation) { rotate = getImageOrientation(uri); if (rotate != 0) { // Matrix matrix = new Matrix(); // matrix.setRotate(rotate); // bitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true); RotateTask r = new RotateTask(bitmap, srcType, destType, rotate, intent); r.execute(); return; } } returnImageToProcess(bitmap, srcType, destType, intent, rotate); } } } else if (resultCode == Activity.RESULT_CANCELED) { this.failPicture("Selection cancelled."); } else { this.failPicture("Selection did not complete!"); } } }
From source file:io.strider.camera.CameraLauncher.java
/** * Called when the camera view exits.//from ww w .java 2s . c o m * * @param requestCode The request code originally supplied to startActivityForResult(), * allowing you to identify who this result came from. * @param resultCode The integer result code returned by the child activity through its setResult(). * @param intent An Intent, which can return result data to the caller (various data can be attached to Intent "extras"). */ public void onActivityResult(int requestCode, int resultCode, Intent intent) { // Get src and dest types from request code int srcType = (requestCode / 16) - 1; int destType = (requestCode % 16) - 1; int rotate = 0; // If CAMERA if (srcType == CAMERA) { // If image available if (resultCode == Activity.RESULT_OK) { try { // Create an ExifHelper to save the exif data that is lost during compression ExifHelper exif = new ExifHelper(); try { if (this.encodingType == JPEG) { exif.createInFile(getTempDirectoryPath() + "/.Pic.jpg"); exif.readExifData(); rotate = exif.getOrientation(); } } catch (IOException e) { e.printStackTrace(); } Bitmap bitmap = null; Uri uri = null; // If sending base64 image back if (destType == DATA_URL) { bitmap = getScaledBitmap(FileHelper.stripFileProtocol(imageUri.toString())); if (bitmap == null) { // Try to get the bitmap from intent. bitmap = (Bitmap) intent.getExtras().get("data"); } // Double-check the bitmap. if (bitmap == null) { Log.d(LOG_TAG, "I either have a null image path or bitmap"); this.failPicture("Unable to create bitmap!"); return; } if (rotate != 0 && this.correctOrientation) { bitmap = getRotatedBitmap(rotate, bitmap, exif); } this.processPicture(bitmap); checkForDuplicateImage(DATA_URL); } // If sending filename back else if (destType == FILE_URI || destType == NATIVE_URI) { if (this.saveToPhotoAlbum) { Uri inputUri = getUriFromMediaStore(); //Just because we have a media URI doesn't mean we have a real file, we need to make it uri = Uri.fromFile(new File(FileHelper.getRealPath(inputUri, this.cordova))); } else { uri = Uri.fromFile( new File(getTempDirectoryPath(), System.currentTimeMillis() + ".jpg")); } if (uri == null) { this.failPicture("Error capturing image - no media storage found."); } // If all this is true we shouldn't compress the image. if (this.targetHeight == -1 && this.targetWidth == -1 && this.mQuality == 100 && !this.correctOrientation) { writeUncompressedImage(uri); this.callbackContext.success(uri.toString()); } else { bitmap = getScaledBitmap(FileHelper.stripFileProtocol(imageUri.toString())); if (rotate != 0 && this.correctOrientation) { bitmap = getRotatedBitmap(rotate, bitmap, exif); } // Add compressed version of captured image to returned media store Uri OutputStream os = this.cordova.getActivity().getContentResolver().openOutputStream(uri); bitmap.compress(Bitmap.CompressFormat.JPEG, this.mQuality, os); os.close(); // Restore exif data to file if (this.encodingType == JPEG) { String exifPath; if (this.saveToPhotoAlbum) { exifPath = FileHelper.getRealPath(uri, this.cordova); } else { exifPath = uri.getPath(); } exif.createOutFile(exifPath); exif.writeExifData(); } } // Send Uri back to JavaScript for viewing image this.callbackContext.success(uri.toString()); } this.cleanup(FILE_URI, this.imageUri, uri, bitmap); bitmap = null; } catch (IOException e) { e.printStackTrace(); this.failPicture("Error capturing image."); } } // If cancelled else if (resultCode == Activity.RESULT_CANCELED) { this.failPicture("Camera cancelled."); } // If something else else { this.failPicture("Did not complete!"); } } // // If retrieving photo from library // else if ((srcType == PHOTOLIBRARY) || (srcType == SAVEDPHOTOALBUM)) { // if (resultCode == Activity.RESULT_OK) { // Uri uri = intent.getData(); // // // If you ask for video or all media type you will automatically get back a file URI // // and there will be no attempt to resize any returned data // if (this.mediaType != PICTURE) { // this.callbackContext.success(uri.toString()); // } // else { // // This is a special case to just return the path as no scaling, // // rotating, nor compressing needs to be done // if (this.targetHeight == -1 && this.targetWidth == -1 && // (destType == FILE_URI || destType == NATIVE_URI) && !this.correctOrientation) { // this.callbackContext.success(uri.toString()); // } else { // String uriString = uri.toString(); // // Get the path to the image. Makes loading so much easier. // String mimeType = FileHelper.getMimeType(uriString, this.cordova); // // If we don't have a valid image so quit. // if (!("image/jpeg".equalsIgnoreCase(mimeType) || "image/png".equalsIgnoreCase(mimeType))) { // Log.d(LOG_TAG, "I either have a null image path or bitmap"); // this.failPicture("Unable to retrieve path to picture!"); // return; // } // Bitmap bitmap = null; // try { // bitmap = getScaledBitmap(uriString); // } catch (IOException e) { // e.printStackTrace(); // } // if (bitmap == null) { // Log.d(LOG_TAG, "I either have a null image path or bitmap"); // this.failPicture("Unable to create bitmap!"); // return; // } // // if (this.correctOrientation) { // rotate = getImageOrientation(uri); // if (rotate != 0) { // Matrix matrix = new Matrix(); // matrix.setRotate(rotate); // bitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true); // } // } // // // If sending base64 image back // if (destType == DATA_URL) { // this.processPicture(bitmap); // } // // // If sending filename back // else if (destType == FILE_URI || destType == NATIVE_URI) { // // Do we need to scale the returned file // if (this.targetHeight > 0 && this.targetWidth > 0) { // try { // // Create an ExifHelper to save the exif data that is lost during compression // String resizePath = getTempDirectoryPath() + "/resize.jpg"; // // Some content: URIs do not map to file paths (e.g. picasa). // String realPath = FileHelper.getRealPath(uri, this.cordova); // ExifHelper exif = new ExifHelper(); // if (realPath != null && this.encodingType == JPEG) { // try { // exif.createInFile(realPath); // exif.readExifData(); // rotate = exif.getOrientation(); // } catch (IOException e) { // e.printStackTrace(); // } // } // // OutputStream os = new FileOutputStream(resizePath); // bitmap.compress(Bitmap.CompressFormat.JPEG, this.mQuality, os); // os.close(); // // // Restore exif data to file // if (realPath != null && this.encodingType == JPEG) { // exif.createOutFile(resizePath); // exif.writeExifData(); // } // // // The resized image is cached by the app in order to get around this and not have to delete you // // application cache I'm adding the current system time to the end of the file url. // this.callbackContext.success("file://" + resizePath + "?" + System.currentTimeMillis()); // } catch (Exception e) { // e.printStackTrace(); // this.failPicture("Error retrieving image."); // } // } // else { // this.callbackContext.success(uri.toString()); // } // } // if (bitmap != null) { // bitmap.recycle(); // bitmap = null; // } // System.gc(); // } // } // } // else if (resultCode == Activity.RESULT_CANCELED) { // this.failPicture("Selection cancelled."); // } // else { // this.failPicture("Selection did not complete!"); // } // } }
From source file:com.markupartist.sthlmtraveling.provider.planner.Planner.java
private Response doJourneyQuery(final Context context, JourneyQuery query, int scrollDirection) throws IOException, BadResponse { Uri u = Uri.parse(apiEndpoint2()); Uri.Builder b = u.buildUpon();//from w w w . j a va2 s.c o m b.appendEncodedPath("v1/journey/"); if (scrollDirection > -1) { b.appendQueryParameter("dir", String.valueOf(scrollDirection)); b.appendQueryParameter("ident", query.ident); b.appendQueryParameter("seq", query.seqnr); } else { if (query.origin.hasLocation()) { b.appendQueryParameter("origin", query.origin.name); b.appendQueryParameter("origin_latitude", String.valueOf(query.origin.latitude / 1E6)); b.appendQueryParameter("origin_longitude", String.valueOf(query.origin.longitude / 1E6)); } else { b.appendQueryParameter("origin", String.valueOf(query.origin.getNameOrId())); } if (query.destination.hasLocation()) { b.appendQueryParameter("destination", query.destination.name); b.appendQueryParameter("destination_latitude", String.valueOf(query.destination.latitude / 1E6)); b.appendQueryParameter("destination_longitude", String.valueOf(query.destination.longitude / 1E6)); } else { b.appendQueryParameter("destination", String.valueOf(query.destination.getNameOrId())); } for (String transportMode : query.transportModes) { b.appendQueryParameter("transport", transportMode); } if (query.time != null) { b.appendQueryParameter("date", query.time.format("%d.%m.%Y")); b.appendQueryParameter("time", query.time.format("%H:%M")); } if (!query.isTimeDeparture) { b.appendQueryParameter("arrival", "1"); } if (query.hasVia()) { b.appendQueryParameter("via", query.via.name); } if (query.alternativeStops) { b.appendQueryParameter("alternative", "1"); } } // Include intermediate stops. //b.appendQueryParameter("intermediate_stops", "1"); u = b.build(); HttpHelper httpHelper = HttpHelper.getInstance(context); HttpURLConnection connection = httpHelper.getConnection(u.toString()); Response r = null; String rawContent; int statusCode = connection.getResponseCode(); switch (statusCode) { case 200: rawContent = httpHelper.getBody(connection); try { JSONObject baseResponse = new JSONObject(rawContent); if (baseResponse.has("journey")) { r = Response.fromJson(baseResponse.getJSONObject("journey")); } else { Log.w(TAG, "Invalid response"); } } catch (JSONException e) { Log.d(TAG, "Could not parse the reponse..."); throw new IOException("Could not parse the response."); } break; case 400: rawContent = httpHelper.getErrorBody(connection); BadResponse br; try { br = BadResponse.fromJson(new JSONObject(rawContent)); } catch (JSONException e) { Log.d(TAG, "Could not parse the reponse..."); throw new IOException("Could not parse the response."); } throw br; default: Log.d(TAG, "Status code not OK from API, was " + statusCode); throw new IOException("A remote server error occurred when getting deviations."); } return r; }
From source file:com.piusvelte.sonet.core.SonetService.java
private void buildScrollableWidget(Integer appWidgetId, int scrollableVersion, boolean display_profile) { // set widget as scrollable Intent replaceDummy = new Intent(LauncherIntent.Action.ACTION_SCROLL_WIDGET_START); replaceDummy.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId); replaceDummy.putExtra(LauncherIntent.Extra.EXTRA_VIEW_ID, R.id.messages); replaceDummy.putExtra(LauncherIntent.Extra.Scroll.EXTRA_LISTVIEW_LAYOUT_ID, R.layout.widget_listview); replaceDummy.putExtra(LauncherIntent.Extra.Scroll.EXTRA_DATA_PROVIDER_ALLOW_REQUERY, true); replaceDummy.putExtra(LauncherIntent.Extra.Scroll.EXTRA_ITEM_CHILDREN_CLICKABLE, true); //provider//from w w w . j ava 2s. com Uri uri = Uri.withAppendedPath(Statuses_styles.getContentUri(SonetService.this), Integer.toString(appWidgetId)); replaceDummy.putExtra(LauncherIntent.Extra.Scroll.EXTRA_DATA_URI, uri.toString()); String[] projection; if (display_profile) projection = new String[] { Statuses_styles._ID, Statuses_styles.FRIEND, Statuses_styles.PROFILE, Statuses_styles.MESSAGE, Statuses_styles.CREATEDTEXT, Statuses_styles.MESSAGES_COLOR, Statuses_styles.FRIEND_COLOR, Statuses_styles.CREATED_COLOR, Statuses_styles.MESSAGES_TEXTSIZE, Statuses_styles.FRIEND_TEXTSIZE, Statuses_styles.CREATED_TEXTSIZE, Statuses_styles.STATUS_BG, Statuses_styles.ICON, Statuses_styles.PROFILE_BG, Statuses_styles.FRIEND_BG, Statuses_styles.IMAGE_BG, Statuses_styles.IMAGE }; else projection = new String[] { Statuses_styles._ID, Statuses_styles.FRIEND, Statuses_styles.PROFILE, Statuses_styles.MESSAGE, Statuses_styles.CREATEDTEXT, Statuses_styles.MESSAGES_COLOR, Statuses_styles.FRIEND_COLOR, Statuses_styles.CREATED_COLOR, Statuses_styles.MESSAGES_TEXTSIZE, Statuses_styles.FRIEND_TEXTSIZE, Statuses_styles.CREATED_TEXTSIZE, Statuses_styles.STATUS_BG, Statuses_styles.ICON, Statuses_styles.FRIEND_BG, Statuses_styles.IMAGE_BG, Statuses_styles.IMAGE }; String sortOrder = Statuses_styles.CREATED + " DESC"; replaceDummy.putExtra(LauncherIntent.Extra.Scroll.EXTRA_PROJECTION, projection); replaceDummy.putExtra(LauncherIntent.Extra.Scroll.EXTRA_SORT_ORDER, sortOrder); String whereClause = Statuses_styles.WIDGET + "=?"; String[] selectionArgs = new String[] { Integer.toString(appWidgetId) }; replaceDummy.putExtra(LauncherIntent.Extra.Scroll.EXTRA_SELECTION, whereClause); replaceDummy.putExtra(LauncherIntent.Extra.Scroll.EXTRA_SELECTION_ARGUMENTS, selectionArgs); replaceDummy.putExtra(LauncherIntent.Extra.Scroll.EXTRA_ITEM_ACTION_VIEW_URI_INDEX, SonetProvider.StatusesStylesColumns._id.ordinal()); switch (scrollableVersion) { case 1: if (display_profile) { replaceDummy.putExtra(LauncherIntent.Extra.Scroll.EXTRA_ITEM_LAYOUT_ID, R.layout.widget_item); int[] cursorIndices = new int[] { SonetProvider.StatusesStylesColumns.friend.ordinal(), SonetProvider.StatusesStylesColumns.message.ordinal(), SonetProvider.StatusesStylesColumns.status_bg.ordinal(), SonetProvider.StatusesStylesColumns.profile.ordinal(), SonetProvider.StatusesStylesColumns.friend.ordinal(), SonetProvider.StatusesStylesColumns.createdtext.ordinal(), SonetProvider.StatusesStylesColumns.message.ordinal(), SonetProvider.StatusesStylesColumns.icon.ordinal(), SonetProvider.StatusesStylesColumns.profile_bg.ordinal(), SonetProvider.StatusesStylesColumns.friend_bg.ordinal(), SonetProvider.StatusesStylesColumns.image_bg.ordinal(), SonetProvider.StatusesStylesColumns.image.ordinal() }; int[] viewTypes = new int[] { LauncherIntent.Extra.Scroll.Types.TEXTVIEW, LauncherIntent.Extra.Scroll.Types.TEXTVIEW, LauncherIntent.Extra.Scroll.Types.IMAGEBLOB, LauncherIntent.Extra.Scroll.Types.IMAGEBLOB, LauncherIntent.Extra.Scroll.Types.TEXTVIEW, LauncherIntent.Extra.Scroll.Types.TEXTVIEW, LauncherIntent.Extra.Scroll.Types.TEXTVIEW, LauncherIntent.Extra.Scroll.Types.IMAGEBLOB, LauncherIntent.Extra.Scroll.Types.IMAGEBLOB, LauncherIntent.Extra.Scroll.Types.IMAGEBLOB, LauncherIntent.Extra.Scroll.Types.IMAGEBLOB, LauncherIntent.Extra.Scroll.Types.IMAGEBLOB }; int[] layoutIds = new int[] { R.id.friend_bg_clear, R.id.message_bg_clear, R.id.status_bg, R.id.profile, R.id.friend, R.id.created, R.id.message, R.id.icon, R.id.profile_bg, R.id.friend_bg, R.id.image_clear, R.id.image }; int[] defaultResource = new int[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; boolean[] clickable = new boolean[] { false, false, true, false, false, false, false, false, false, false, false, false }; replaceDummy.putExtra(LauncherIntent.Extra.Scroll.Mapping.EXTRA_CURSOR_INDICES, cursorIndices); replaceDummy.putExtra(LauncherIntent.Extra.Scroll.Mapping.EXTRA_VIEW_TYPES, viewTypes); replaceDummy.putExtra(LauncherIntent.Extra.Scroll.Mapping.EXTRA_VIEW_IDS, layoutIds); replaceDummy.putExtra(LauncherIntent.Extra.Scroll.Mapping.EXTRA_DEFAULT_RESOURCES, defaultResource); replaceDummy.putExtra(LauncherIntent.Extra.Scroll.Mapping.EXTRA_VIEW_CLICKABLE, clickable); } else { replaceDummy.putExtra(LauncherIntent.Extra.Scroll.EXTRA_ITEM_LAYOUT_ID, R.layout.widget_item_noprofile); int[] cursorIndices = new int[] { SonetProvider.StatusesStylesColumnsNoProfile.friend.ordinal(), SonetProvider.StatusesStylesColumnsNoProfile.message.ordinal(), SonetProvider.StatusesStylesColumnsNoProfile.status_bg.ordinal(), SonetProvider.StatusesStylesColumnsNoProfile.friend.ordinal(), SonetProvider.StatusesStylesColumnsNoProfile.createdtext.ordinal(), SonetProvider.StatusesStylesColumnsNoProfile.message.ordinal(), SonetProvider.StatusesStylesColumnsNoProfile.icon.ordinal(), SonetProvider.StatusesStylesColumnsNoProfile.friend_bg.ordinal(), SonetProvider.StatusesStylesColumnsNoProfile.image_bg.ordinal(), SonetProvider.StatusesStylesColumnsNoProfile.image.ordinal() }; int[] viewTypes = new int[] { LauncherIntent.Extra.Scroll.Types.TEXTVIEW, LauncherIntent.Extra.Scroll.Types.TEXTVIEW, LauncherIntent.Extra.Scroll.Types.IMAGEBLOB, LauncherIntent.Extra.Scroll.Types.TEXTVIEW, LauncherIntent.Extra.Scroll.Types.TEXTVIEW, LauncherIntent.Extra.Scroll.Types.TEXTVIEW, LauncherIntent.Extra.Scroll.Types.IMAGEBLOB, LauncherIntent.Extra.Scroll.Types.IMAGEBLOB, LauncherIntent.Extra.Scroll.Types.IMAGEBLOB, LauncherIntent.Extra.Scroll.Types.IMAGEBLOB }; int[] layoutIds = new int[] { R.id.friend_bg_clear, R.id.message_bg_clear, R.id.status_bg, R.id.friend, R.id.created, R.id.message, R.id.icon, R.id.friend_bg, R.id.image_clear, R.id.image }; int[] defaultResource = new int[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; boolean[] clickable = new boolean[] { false, false, true, false, false, false, false, false, false, false }; replaceDummy.putExtra(LauncherIntent.Extra.Scroll.Mapping.EXTRA_CURSOR_INDICES, cursorIndices); replaceDummy.putExtra(LauncherIntent.Extra.Scroll.Mapping.EXTRA_VIEW_TYPES, viewTypes); replaceDummy.putExtra(LauncherIntent.Extra.Scroll.Mapping.EXTRA_VIEW_IDS, layoutIds); replaceDummy.putExtra(LauncherIntent.Extra.Scroll.Mapping.EXTRA_DEFAULT_RESOURCES, defaultResource); replaceDummy.putExtra(LauncherIntent.Extra.Scroll.Mapping.EXTRA_VIEW_CLICKABLE, clickable); } break; case 2: if (display_profile) { BoundRemoteViews itemViews = new BoundRemoteViews(R.layout.widget_item); Intent i = Sonet.getPackageIntent(SonetService.this, SonetWidget.class) .setAction(LauncherIntent.Action.ACTION_VIEW_CLICK).setData(uri) .putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId); PendingIntent pi = PendingIntent.getBroadcast(SonetService.this, 0, i, 0); itemViews.SetBoundOnClickIntent(R.id.item, pi, LauncherIntent.Extra.Scroll.EXTRA_ITEM_POS, SonetProvider.StatusesStylesColumns._id.ordinal()); itemViews.setBoundCharSequence(R.id.friend_bg_clear, "setText", SonetProvider.StatusesStylesColumns.friend.ordinal(), 0); itemViews.setBoundFloat(R.id.friend_bg_clear, "setTextSize", SonetProvider.StatusesStylesColumns.friend_textsize.ordinal()); itemViews.setBoundCharSequence(R.id.message_bg_clear, "setText", SonetProvider.StatusesStylesColumns.message.ordinal(), 0); itemViews.setBoundFloat(R.id.message_bg_clear, "setTextSize", SonetProvider.StatusesStylesColumns.messages_textsize.ordinal()); itemViews.setBoundBitmap(R.id.status_bg, "setImageBitmap", SonetProvider.StatusesStylesColumns.status_bg.ordinal(), 0); itemViews.setBoundBitmap(R.id.image_clear, "setImageBitmap", SonetProvider.StatusesStylesColumns.image_bg.ordinal(), 0); itemViews.setBoundBitmap(R.id.image, "setImageBitmap", SonetProvider.StatusesStylesColumns.image.ordinal(), 0); itemViews.setBoundBitmap(R.id.profile, "setImageBitmap", SonetProvider.StatusesStylesColumns.profile.ordinal(), 0); itemViews.setBoundCharSequence(R.id.friend, "setText", SonetProvider.StatusesStylesColumns.friend.ordinal(), 0); itemViews.setBoundCharSequence(R.id.created, "setText", SonetProvider.StatusesStylesColumns.createdtext.ordinal(), 0); itemViews.setBoundCharSequence(R.id.message, "setText", SonetProvider.StatusesStylesColumns.message.ordinal(), 0); itemViews.setBoundInt(R.id.friend, "setTextColor", SonetProvider.StatusesStylesColumns.friend_color.ordinal()); itemViews.setBoundInt(R.id.created, "setTextColor", SonetProvider.StatusesStylesColumns.created_color.ordinal()); itemViews.setBoundInt(R.id.message, "setTextColor", SonetProvider.StatusesStylesColumns.messages_color.ordinal()); itemViews.setBoundFloat(R.id.friend, "setTextSize", SonetProvider.StatusesStylesColumns.friend_textsize.ordinal()); itemViews.setBoundFloat(R.id.created, "setTextSize", SonetProvider.StatusesStylesColumns.created_textsize.ordinal()); itemViews.setBoundFloat(R.id.message, "setTextSize", SonetProvider.StatusesStylesColumns.messages_textsize.ordinal()); itemViews.setBoundBitmap(R.id.icon, "setImageBitmap", SonetProvider.StatusesStylesColumns.icon.ordinal(), 0); itemViews.setBoundBitmap(R.id.profile_bg, "setImageBitmap", SonetProvider.StatusesStylesColumns.profile_bg.ordinal(), 0); itemViews.setBoundBitmap(R.id.friend_bg, "setImageBitmap", SonetProvider.StatusesStylesColumns.friend_bg.ordinal(), 0); replaceDummy.putExtra(LauncherIntent.Extra.Scroll.EXTRA_ITEM_LAYOUT_REMOTEVIEWS, itemViews); } else { BoundRemoteViews itemViews = new BoundRemoteViews(R.layout.widget_item_noprofile); Intent i = Sonet.getPackageIntent(SonetService.this, SonetWidget.class) .setAction(LauncherIntent.Action.ACTION_VIEW_CLICK).setData(uri) .putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId); PendingIntent pi = PendingIntent.getBroadcast(SonetService.this, 0, i, 0); itemViews.SetBoundOnClickIntent(R.id.item, pi, LauncherIntent.Extra.Scroll.EXTRA_ITEM_POS, SonetProvider.StatusesStylesColumnsNoProfile._id.ordinal()); itemViews.setBoundCharSequence(R.id.friend_bg_clear, "setText", SonetProvider.StatusesStylesColumnsNoProfile.friend.ordinal(), 0); itemViews.setBoundFloat(R.id.friend_bg_clear, "setTextSize", SonetProvider.StatusesStylesColumnsNoProfile.friend_textsize.ordinal()); itemViews.setBoundCharSequence(R.id.message_bg_clear, "setText", SonetProvider.StatusesStylesColumnsNoProfile.message.ordinal(), 0); itemViews.setBoundFloat(R.id.message_bg_clear, "setTextSize", SonetProvider.StatusesStylesColumnsNoProfile.messages_textsize.ordinal()); itemViews.setBoundBitmap(R.id.status_bg, "setImageBitmap", SonetProvider.StatusesStylesColumnsNoProfile.status_bg.ordinal(), 0); itemViews.setBoundBitmap(R.id.image_clear, "setImageBitmap", SonetProvider.StatusesStylesColumnsNoProfile.image_bg.ordinal(), 0); itemViews.setBoundBitmap(R.id.image, "setImageBitmap", SonetProvider.StatusesStylesColumnsNoProfile.image.ordinal(), 0); itemViews.setBoundCharSequence(R.id.friend, "setText", SonetProvider.StatusesStylesColumnsNoProfile.friend.ordinal(), 0); itemViews.setBoundCharSequence(R.id.created, "setText", SonetProvider.StatusesStylesColumnsNoProfile.createdtext.ordinal(), 0); itemViews.setBoundCharSequence(R.id.message, "setText", SonetProvider.StatusesStylesColumnsNoProfile.message.ordinal(), 0); itemViews.setBoundInt(R.id.friend, "setTextColor", SonetProvider.StatusesStylesColumnsNoProfile.friend_color.ordinal()); itemViews.setBoundInt(R.id.created, "setTextColor", SonetProvider.StatusesStylesColumnsNoProfile.created_color.ordinal()); itemViews.setBoundInt(R.id.message, "setTextColor", SonetProvider.StatusesStylesColumnsNoProfile.messages_color.ordinal()); itemViews.setBoundFloat(R.id.friend, "setTextSize", SonetProvider.StatusesStylesColumnsNoProfile.friend_textsize.ordinal()); itemViews.setBoundFloat(R.id.created, "setTextSize", SonetProvider.StatusesStylesColumnsNoProfile.created_textsize.ordinal()); itemViews.setBoundFloat(R.id.message, "setTextSize", SonetProvider.StatusesStylesColumnsNoProfile.messages_textsize.ordinal()); itemViews.setBoundBitmap(R.id.icon, "setImageBitmap", SonetProvider.StatusesStylesColumnsNoProfile.icon.ordinal(), 0); itemViews.setBoundBitmap(R.id.friend_bg, "setImageBitmap", SonetProvider.StatusesStylesColumnsNoProfile.friend_bg.ordinal(), 0); replaceDummy.putExtra(LauncherIntent.Extra.Scroll.EXTRA_ITEM_LAYOUT_REMOTEVIEWS, itemViews); } break; } sendBroadcast(replaceDummy); }
From source file:cgeo.geocaching.CacheDetailActivity.java
@Override public void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState, R.layout.cachedetail_activity); // get parameters final Bundle extras = getIntent().getExtras(); final Uri uri = AndroidBeam.getUri(getIntent()); // try to get data from extras String name = null;/*w ww.j av a 2s. c o m*/ String guid = null; if (extras != null) { geocode = extras.getString(Intents.EXTRA_GEOCODE); name = extras.getString(Intents.EXTRA_NAME); guid = extras.getString(Intents.EXTRA_GUID); } // When clicking a cache in MapsWithMe, we get back a PendingIntent if (StringUtils.isEmpty(geocode)) { geocode = MapsMeCacheListApp.getCacheFromMapsWithMe(this, getIntent()); } if (geocode == null && uri != null) { geocode = ConnectorFactory.getGeocodeFromURL(uri.toString()); } // try to get data from URI if (geocode == null && guid == null && uri != null) { final String uriHost = uri.getHost().toLowerCase(Locale.US); final String uriPath = uri.getPath().toLowerCase(Locale.US); final String uriQuery = uri.getQuery(); if (uriQuery != null) { Log.i("Opening URI: " + uriHost + uriPath + "?" + uriQuery); } else { Log.i("Opening URI: " + uriHost + uriPath); } if (uriHost.contains("geocaching.com")) { if (StringUtils.startsWith(uriPath, "/geocache/gc")) { geocode = StringUtils.substringBefore(uriPath.substring(10), "_").toUpperCase(Locale.US); } else { geocode = uri.getQueryParameter("wp"); guid = uri.getQueryParameter("guid"); if (StringUtils.isNotBlank(geocode)) { geocode = geocode.toUpperCase(Locale.US); guid = null; } else if (StringUtils.isNotBlank(guid)) { geocode = null; guid = guid.toLowerCase(Locale.US); } else { showToast(res.getString(R.string.err_detail_open)); finish(); return; } } } } // no given data if (geocode == null && guid == null) { showToast(res.getString(R.string.err_detail_cache)); finish(); return; } // If we open this cache from a search, let's properly initialize the title bar, even if we don't have cache details setCacheTitleBar(geocode, name, null); final LoadCacheHandler loadCacheHandler = new LoadCacheHandler(this, progress); try { String title = res.getString(R.string.cache); if (StringUtils.isNotBlank(name)) { title = name; } else if (geocode != null && StringUtils.isNotBlank(geocode)) { // can't be null, but the compiler doesn't understand StringUtils.isNotBlank() title = geocode; } progress.show(this, title, res.getString(R.string.cache_dialog_loading_details), true, loadCacheHandler.disposeMessage()); } catch (final RuntimeException ignored) { // nothing, we lost the window } final int pageToOpen = savedInstanceState != null ? savedInstanceState.getInt(STATE_PAGE_INDEX, 0) : Settings.isOpenLastDetailsPage() ? Settings.getLastDetailsPage() : 1; createViewPager(pageToOpen, new OnPageSelectedListener() { @Override public void onPageSelected(final int position) { if (Settings.isOpenLastDetailsPage()) { Settings.setLastDetailsPage(position); } // lazy loading of cache images if (getPage(position) == Page.IMAGES) { loadCacheImages(); } requireGeodata = getPage(position) == Page.DETAILS; startOrStopGeoDataListener(false); // dispose contextual actions on page change if (currentActionMode != null) { currentActionMode.finish(); } } }); requireGeodata = pageToOpen == 1; final String realGeocode = geocode; final String realGuid = guid; AndroidRxUtils.networkScheduler.scheduleDirect(new Runnable() { @Override public void run() { search = Geocache.searchByGeocode(realGeocode, StringUtils.isBlank(realGeocode) ? realGuid : null, false, loadCacheHandler); loadCacheHandler.sendMessage(Message.obtain()); } }); // Load Generic Trackables if (StringUtils.isNotBlank(geocode)) { AndroidRxUtils.bindActivity(this, // Obtain the active connectors and load trackables in parallel. Observable.fromIterable(ConnectorFactory.getGenericTrackablesConnectors()) .flatMap(new Function<TrackableConnector, Observable<Trackable>>() { @Override public Observable<Trackable> apply(final TrackableConnector trackableConnector) { processedBrands.add(trackableConnector.getBrand()); return Observable.defer(new Callable<Observable<Trackable>>() { @Override public Observable<Trackable> call() { return Observable .fromIterable(trackableConnector.searchTrackables(geocode)); } }).subscribeOn(AndroidRxUtils.networkScheduler); } }).toList()) .subscribe(new Consumer<List<Trackable>>() { @Override public void accept(final List<Trackable> trackables) { // Todo: this is not really a good method, it may lead to duplicates ; ie: in OC connectors. // Store trackables. genericTrackables.addAll(trackables); if (!trackables.isEmpty()) { // Update the UI if any trackables were found. notifyDataSetChanged(); } } }); } locationUpdater = new CacheDetailsGeoDirHandler(this); // If we have a newer Android device setup Android Beam for easy cache sharing AndroidBeam.enable(this, this); }
From source file:com.shafiq.myfeedle.core.MyfeedleService.java
private void buildScrollableWidget(Integer appWidgetId, int scrollableVersion, boolean display_profile) { // set widget as scrollable Intent replaceDummy = new Intent(LauncherIntent.Action.ACTION_SCROLL_WIDGET_START); replaceDummy.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId); replaceDummy.putExtra(LauncherIntent.Extra.EXTRA_VIEW_ID, R.id.messages); replaceDummy.putExtra(LauncherIntent.Extra.Scroll.EXTRA_LISTVIEW_LAYOUT_ID, R.layout.widget_listview); replaceDummy.putExtra(LauncherIntent.Extra.Scroll.EXTRA_DATA_PROVIDER_ALLOW_REQUERY, true); replaceDummy.putExtra(LauncherIntent.Extra.Scroll.EXTRA_ITEM_CHILDREN_CLICKABLE, true); //provider// www . j a va 2 s .co m Uri uri = Uri.withAppendedPath(Statuses_styles.getContentUri(MyfeedleService.this), Integer.toString(appWidgetId)); replaceDummy.putExtra(LauncherIntent.Extra.Scroll.EXTRA_DATA_URI, uri.toString()); String[] projection; if (display_profile) projection = new String[] { Statuses_styles._ID, Statuses_styles.FRIEND, Statuses_styles.PROFILE, Statuses_styles.MESSAGE, Statuses_styles.CREATEDTEXT, Statuses_styles.MESSAGES_COLOR, Statuses_styles.FRIEND_COLOR, Statuses_styles.CREATED_COLOR, Statuses_styles.MESSAGES_TEXTSIZE, Statuses_styles.FRIEND_TEXTSIZE, Statuses_styles.CREATED_TEXTSIZE, Statuses_styles.STATUS_BG, Statuses_styles.ICON, Statuses_styles.PROFILE_BG, Statuses_styles.FRIEND_BG, Statuses_styles.IMAGE_BG, Statuses_styles.IMAGE }; else projection = new String[] { Statuses_styles._ID, Statuses_styles.FRIEND, Statuses_styles.PROFILE, Statuses_styles.MESSAGE, Statuses_styles.CREATEDTEXT, Statuses_styles.MESSAGES_COLOR, Statuses_styles.FRIEND_COLOR, Statuses_styles.CREATED_COLOR, Statuses_styles.MESSAGES_TEXTSIZE, Statuses_styles.FRIEND_TEXTSIZE, Statuses_styles.CREATED_TEXTSIZE, Statuses_styles.STATUS_BG, Statuses_styles.ICON, Statuses_styles.FRIEND_BG, Statuses_styles.IMAGE_BG, Statuses_styles.IMAGE }; String sortOrder = Statuses_styles.CREATED + " DESC"; replaceDummy.putExtra(LauncherIntent.Extra.Scroll.EXTRA_PROJECTION, projection); replaceDummy.putExtra(LauncherIntent.Extra.Scroll.EXTRA_SORT_ORDER, sortOrder); String whereClause = Statuses_styles.WIDGET + "=?"; String[] selectionArgs = new String[] { Integer.toString(appWidgetId) }; replaceDummy.putExtra(LauncherIntent.Extra.Scroll.EXTRA_SELECTION, whereClause); replaceDummy.putExtra(LauncherIntent.Extra.Scroll.EXTRA_SELECTION_ARGUMENTS, selectionArgs); replaceDummy.putExtra(LauncherIntent.Extra.Scroll.EXTRA_ITEM_ACTION_VIEW_URI_INDEX, MyfeedleProvider.StatusesStylesColumns._id.ordinal()); switch (scrollableVersion) { case 1: if (display_profile) { replaceDummy.putExtra(LauncherIntent.Extra.Scroll.EXTRA_ITEM_LAYOUT_ID, R.layout.widget_item); int[] cursorIndices = new int[] { MyfeedleProvider.StatusesStylesColumns.friend.ordinal(), MyfeedleProvider.StatusesStylesColumns.message.ordinal(), MyfeedleProvider.StatusesStylesColumns.status_bg.ordinal(), MyfeedleProvider.StatusesStylesColumns.profile.ordinal(), MyfeedleProvider.StatusesStylesColumns.friend.ordinal(), MyfeedleProvider.StatusesStylesColumns.createdtext.ordinal(), MyfeedleProvider.StatusesStylesColumns.message.ordinal(), MyfeedleProvider.StatusesStylesColumns.icon.ordinal(), MyfeedleProvider.StatusesStylesColumns.profile_bg.ordinal(), MyfeedleProvider.StatusesStylesColumns.friend_bg.ordinal(), MyfeedleProvider.StatusesStylesColumns.image_bg.ordinal(), MyfeedleProvider.StatusesStylesColumns.image.ordinal() }; int[] viewTypes = new int[] { LauncherIntent.Extra.Scroll.Types.TEXTVIEW, LauncherIntent.Extra.Scroll.Types.TEXTVIEW, LauncherIntent.Extra.Scroll.Types.IMAGEBLOB, LauncherIntent.Extra.Scroll.Types.IMAGEBLOB, LauncherIntent.Extra.Scroll.Types.TEXTVIEW, LauncherIntent.Extra.Scroll.Types.TEXTVIEW, LauncherIntent.Extra.Scroll.Types.TEXTVIEW, LauncherIntent.Extra.Scroll.Types.IMAGEBLOB, LauncherIntent.Extra.Scroll.Types.IMAGEBLOB, LauncherIntent.Extra.Scroll.Types.IMAGEBLOB, LauncherIntent.Extra.Scroll.Types.IMAGEBLOB, LauncherIntent.Extra.Scroll.Types.IMAGEBLOB }; int[] layoutIds = new int[] { R.id.friend_bg_clear, R.id.message_bg_clear, R.id.status_bg, R.id.profile, R.id.friend, R.id.created, R.id.message, R.id.icon, R.id.profile_bg, R.id.friend_bg, R.id.image_clear, R.id.image }; int[] defaultResource = new int[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; boolean[] clickable = new boolean[] { false, false, true, false, false, false, false, false, false, false, false, false }; replaceDummy.putExtra(LauncherIntent.Extra.Scroll.Mapping.EXTRA_CURSOR_INDICES, cursorIndices); replaceDummy.putExtra(LauncherIntent.Extra.Scroll.Mapping.EXTRA_VIEW_TYPES, viewTypes); replaceDummy.putExtra(LauncherIntent.Extra.Scroll.Mapping.EXTRA_VIEW_IDS, layoutIds); replaceDummy.putExtra(LauncherIntent.Extra.Scroll.Mapping.EXTRA_DEFAULT_RESOURCES, defaultResource); replaceDummy.putExtra(LauncherIntent.Extra.Scroll.Mapping.EXTRA_VIEW_CLICKABLE, clickable); } else { replaceDummy.putExtra(LauncherIntent.Extra.Scroll.EXTRA_ITEM_LAYOUT_ID, R.layout.widget_item_noprofile); int[] cursorIndices = new int[] { MyfeedleProvider.StatusesStylesColumnsNoProfile.friend.ordinal(), MyfeedleProvider.StatusesStylesColumnsNoProfile.message.ordinal(), MyfeedleProvider.StatusesStylesColumnsNoProfile.status_bg.ordinal(), MyfeedleProvider.StatusesStylesColumnsNoProfile.friend.ordinal(), MyfeedleProvider.StatusesStylesColumnsNoProfile.createdtext.ordinal(), MyfeedleProvider.StatusesStylesColumnsNoProfile.message.ordinal(), MyfeedleProvider.StatusesStylesColumnsNoProfile.icon.ordinal(), MyfeedleProvider.StatusesStylesColumnsNoProfile.friend_bg.ordinal(), MyfeedleProvider.StatusesStylesColumnsNoProfile.image_bg.ordinal(), MyfeedleProvider.StatusesStylesColumnsNoProfile.image.ordinal() }; int[] viewTypes = new int[] { LauncherIntent.Extra.Scroll.Types.TEXTVIEW, LauncherIntent.Extra.Scroll.Types.TEXTVIEW, LauncherIntent.Extra.Scroll.Types.IMAGEBLOB, LauncherIntent.Extra.Scroll.Types.TEXTVIEW, LauncherIntent.Extra.Scroll.Types.TEXTVIEW, LauncherIntent.Extra.Scroll.Types.TEXTVIEW, LauncherIntent.Extra.Scroll.Types.IMAGEBLOB, LauncherIntent.Extra.Scroll.Types.IMAGEBLOB, LauncherIntent.Extra.Scroll.Types.IMAGEBLOB, LauncherIntent.Extra.Scroll.Types.IMAGEBLOB }; int[] layoutIds = new int[] { R.id.friend_bg_clear, R.id.message_bg_clear, R.id.status_bg, R.id.friend, R.id.created, R.id.message, R.id.icon, R.id.friend_bg, R.id.image_clear, R.id.image }; int[] defaultResource = new int[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; boolean[] clickable = new boolean[] { false, false, true, false, false, false, false, false, false, false }; replaceDummy.putExtra(LauncherIntent.Extra.Scroll.Mapping.EXTRA_CURSOR_INDICES, cursorIndices); replaceDummy.putExtra(LauncherIntent.Extra.Scroll.Mapping.EXTRA_VIEW_TYPES, viewTypes); replaceDummy.putExtra(LauncherIntent.Extra.Scroll.Mapping.EXTRA_VIEW_IDS, layoutIds); replaceDummy.putExtra(LauncherIntent.Extra.Scroll.Mapping.EXTRA_DEFAULT_RESOURCES, defaultResource); replaceDummy.putExtra(LauncherIntent.Extra.Scroll.Mapping.EXTRA_VIEW_CLICKABLE, clickable); } break; case 2: if (display_profile) { BoundRemoteViews itemViews = new BoundRemoteViews(R.layout.widget_item); Intent i = Myfeedle.getPackageIntent(MyfeedleService.this, MyfeedleWidget.class) .setAction(LauncherIntent.Action.ACTION_VIEW_CLICK).setData(uri) .putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId); PendingIntent pi = PendingIntent.getBroadcast(MyfeedleService.this, 0, i, 0); itemViews.SetBoundOnClickIntent(R.id.item, pi, LauncherIntent.Extra.Scroll.EXTRA_ITEM_POS, MyfeedleProvider.StatusesStylesColumns._id.ordinal()); itemViews.setBoundCharSequence(R.id.friend_bg_clear, "setText", MyfeedleProvider.StatusesStylesColumns.friend.ordinal(), 0); itemViews.setBoundFloat(R.id.friend_bg_clear, "setTextSize", MyfeedleProvider.StatusesStylesColumns.friend_textsize.ordinal()); itemViews.setBoundCharSequence(R.id.message_bg_clear, "setText", MyfeedleProvider.StatusesStylesColumns.message.ordinal(), 0); itemViews.setBoundFloat(R.id.message_bg_clear, "setTextSize", MyfeedleProvider.StatusesStylesColumns.messages_textsize.ordinal()); itemViews.setBoundBitmap(R.id.status_bg, "setImageBitmap", MyfeedleProvider.StatusesStylesColumns.status_bg.ordinal(), 0); itemViews.setBoundBitmap(R.id.image_clear, "setImageBitmap", MyfeedleProvider.StatusesStylesColumns.image_bg.ordinal(), 0); itemViews.setBoundBitmap(R.id.image, "setImageBitmap", MyfeedleProvider.StatusesStylesColumns.image.ordinal(), 0); itemViews.setBoundBitmap(R.id.profile, "setImageBitmap", MyfeedleProvider.StatusesStylesColumns.profile.ordinal(), 0); itemViews.setBoundCharSequence(R.id.friend, "setText", MyfeedleProvider.StatusesStylesColumns.friend.ordinal(), 0); itemViews.setBoundCharSequence(R.id.created, "setText", MyfeedleProvider.StatusesStylesColumns.createdtext.ordinal(), 0); itemViews.setBoundCharSequence(R.id.message, "setText", MyfeedleProvider.StatusesStylesColumns.message.ordinal(), 0); itemViews.setBoundInt(R.id.friend, "setTextColor", MyfeedleProvider.StatusesStylesColumns.friend_color.ordinal()); itemViews.setBoundInt(R.id.created, "setTextColor", MyfeedleProvider.StatusesStylesColumns.created_color.ordinal()); itemViews.setBoundInt(R.id.message, "setTextColor", MyfeedleProvider.StatusesStylesColumns.messages_color.ordinal()); itemViews.setBoundFloat(R.id.friend, "setTextSize", MyfeedleProvider.StatusesStylesColumns.friend_textsize.ordinal()); itemViews.setBoundFloat(R.id.created, "setTextSize", MyfeedleProvider.StatusesStylesColumns.created_textsize.ordinal()); itemViews.setBoundFloat(R.id.message, "setTextSize", MyfeedleProvider.StatusesStylesColumns.messages_textsize.ordinal()); itemViews.setBoundBitmap(R.id.icon, "setImageBitmap", MyfeedleProvider.StatusesStylesColumns.icon.ordinal(), 0); itemViews.setBoundBitmap(R.id.profile_bg, "setImageBitmap", MyfeedleProvider.StatusesStylesColumns.profile_bg.ordinal(), 0); itemViews.setBoundBitmap(R.id.friend_bg, "setImageBitmap", MyfeedleProvider.StatusesStylesColumns.friend_bg.ordinal(), 0); replaceDummy.putExtra(LauncherIntent.Extra.Scroll.EXTRA_ITEM_LAYOUT_REMOTEVIEWS, itemViews); } else { BoundRemoteViews itemViews = new BoundRemoteViews(R.layout.widget_item_noprofile); Intent i = Myfeedle.getPackageIntent(MyfeedleService.this, MyfeedleWidget.class) .setAction(LauncherIntent.Action.ACTION_VIEW_CLICK).setData(uri) .putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId); PendingIntent pi = PendingIntent.getBroadcast(MyfeedleService.this, 0, i, 0); itemViews.SetBoundOnClickIntent(R.id.item, pi, LauncherIntent.Extra.Scroll.EXTRA_ITEM_POS, MyfeedleProvider.StatusesStylesColumnsNoProfile._id.ordinal()); itemViews.setBoundCharSequence(R.id.friend_bg_clear, "setText", MyfeedleProvider.StatusesStylesColumnsNoProfile.friend.ordinal(), 0); itemViews.setBoundFloat(R.id.friend_bg_clear, "setTextSize", MyfeedleProvider.StatusesStylesColumnsNoProfile.friend_textsize.ordinal()); itemViews.setBoundCharSequence(R.id.message_bg_clear, "setText", MyfeedleProvider.StatusesStylesColumnsNoProfile.message.ordinal(), 0); itemViews.setBoundFloat(R.id.message_bg_clear, "setTextSize", MyfeedleProvider.StatusesStylesColumnsNoProfile.messages_textsize.ordinal()); itemViews.setBoundBitmap(R.id.status_bg, "setImageBitmap", MyfeedleProvider.StatusesStylesColumnsNoProfile.status_bg.ordinal(), 0); itemViews.setBoundBitmap(R.id.image_clear, "setImageBitmap", MyfeedleProvider.StatusesStylesColumnsNoProfile.image_bg.ordinal(), 0); itemViews.setBoundBitmap(R.id.image, "setImageBitmap", MyfeedleProvider.StatusesStylesColumnsNoProfile.image.ordinal(), 0); itemViews.setBoundCharSequence(R.id.friend, "setText", MyfeedleProvider.StatusesStylesColumnsNoProfile.friend.ordinal(), 0); itemViews.setBoundCharSequence(R.id.created, "setText", MyfeedleProvider.StatusesStylesColumnsNoProfile.createdtext.ordinal(), 0); itemViews.setBoundCharSequence(R.id.message, "setText", MyfeedleProvider.StatusesStylesColumnsNoProfile.message.ordinal(), 0); itemViews.setBoundInt(R.id.friend, "setTextColor", MyfeedleProvider.StatusesStylesColumnsNoProfile.friend_color.ordinal()); itemViews.setBoundInt(R.id.created, "setTextColor", MyfeedleProvider.StatusesStylesColumnsNoProfile.created_color.ordinal()); itemViews.setBoundInt(R.id.message, "setTextColor", MyfeedleProvider.StatusesStylesColumnsNoProfile.messages_color.ordinal()); itemViews.setBoundFloat(R.id.friend, "setTextSize", MyfeedleProvider.StatusesStylesColumnsNoProfile.friend_textsize.ordinal()); itemViews.setBoundFloat(R.id.created, "setTextSize", MyfeedleProvider.StatusesStylesColumnsNoProfile.created_textsize.ordinal()); itemViews.setBoundFloat(R.id.message, "setTextSize", MyfeedleProvider.StatusesStylesColumnsNoProfile.messages_textsize.ordinal()); itemViews.setBoundBitmap(R.id.icon, "setImageBitmap", MyfeedleProvider.StatusesStylesColumnsNoProfile.icon.ordinal(), 0); itemViews.setBoundBitmap(R.id.friend_bg, "setImageBitmap", MyfeedleProvider.StatusesStylesColumnsNoProfile.friend_bg.ordinal(), 0); replaceDummy.putExtra(LauncherIntent.Extra.Scroll.EXTRA_ITEM_LAYOUT_REMOTEVIEWS, itemViews); } break; } sendBroadcast(replaceDummy); }
From source file:com.adobe.phonegap.contentsync.Sync.java
private boolean download(final String source, final File file, final JSONObject headers, final ProgressEvent progress, final CallbackContext callbackContext, final boolean trustEveryone) { Log.d(LOG_TAG, "download " + source); if (!Patterns.WEB_URL.matcher(source).matches()) { sendErrorMessage("Invalid URL", INVALID_URL_ERROR, callbackContext); return false; }/*from w w w. j av a 2 s . c om*/ final CordovaResourceApi resourceApi = webView.getResourceApi(); final Uri sourceUri = resourceApi.remapUri(Uri.parse(source)); int uriType = CordovaResourceApi.getUriType(sourceUri); final boolean useHttps = uriType == CordovaResourceApi.URI_TYPE_HTTPS; final boolean isLocalTransfer = !useHttps && uriType != CordovaResourceApi.URI_TYPE_HTTP; synchronized (progress) { if (progress.isAborted()) { return false; } } HttpURLConnection connection = null; HostnameVerifier oldHostnameVerifier = null; SSLSocketFactory oldSocketFactory = null; PluginResult result = null; TrackingInputStream inputStream = null; boolean cached = false; OutputStream outputStream = null; try { OpenForReadResult readResult = null; final Uri targetUri = resourceApi.remapUri(Uri.fromFile(file)); progress.setTargetFile(file); progress.setStatus(STATUS_DOWNLOADING); Log.d(LOG_TAG, "Download file: " + sourceUri); Log.d(LOG_TAG, "Target file: " + file); Log.d(LOG_TAG, "size = " + file.length()); if (isLocalTransfer) { readResult = resourceApi.openForRead(sourceUri); if (readResult.length != -1) { progress.setTotal(readResult.length); } inputStream = new SimpleTrackingInputStream(readResult.inputStream); } else { // connect to server // Open a HTTP connection to the URL based on protocol connection = resourceApi.createHttpConnection(sourceUri); if (useHttps && trustEveryone) { // Setup the HTTPS connection class to trust everyone HttpsURLConnection https = (HttpsURLConnection) connection; oldSocketFactory = trustAllHosts(https); // Save the current hostnameVerifier oldHostnameVerifier = https.getHostnameVerifier(); // Setup the connection not to verify hostnames https.setHostnameVerifier(DO_NOT_VERIFY); } connection.setRequestMethod("GET"); // TODO: Make OkHttp use this CookieManager by default. String cookie = getCookies(sourceUri.toString()); if (cookie != null) { connection.setRequestProperty("cookie", cookie); } // This must be explicitly set for gzip progress tracking to work. connection.setRequestProperty("Accept-Encoding", "gzip"); // Handle the other headers if (headers != null) { addHeadersToRequest(connection, headers); } connection.connect(); if (connection.getResponseCode() == HttpURLConnection.HTTP_NOT_MODIFIED) { cached = true; connection.disconnect(); sendErrorMessage("Resource not modified: " + source, CONNECTION_ERROR, callbackContext); return false; } else { if (connection.getContentEncoding() == null || connection.getContentEncoding().equalsIgnoreCase("gzip")) { // Only trust content-length header if we understand // the encoding -- identity or gzip int connectionLength = connection.getContentLength(); if (connectionLength != -1) { if (connectionLength > getFreeSpace()) { cached = true; connection.disconnect(); sendErrorMessage("Not enough free space to download", CONNECTION_ERROR, callbackContext); return false; } else { progress.setTotal(connectionLength); } } } inputStream = getInputStream(connection); } } if (!cached) { try { synchronized (progress) { if (progress.isAborted()) { return false; } //progress.connection = connection; } // write bytes to file byte[] buffer = new byte[MAX_BUFFER_SIZE]; int bytesRead = 0; outputStream = resourceApi.openOutputStream(targetUri); while ((bytesRead = inputStream.read(buffer)) > 0) { synchronized (progress) { if (progress.isAborted()) { return false; } } Log.d(LOG_TAG, "bytes read = " + bytesRead); outputStream.write(buffer, 0, bytesRead); // Send a progress event. progress.setLoaded(inputStream.getTotalRawBytesRead()); updateProgress(callbackContext, progress); } } finally { synchronized (progress) { //progress.connection = null; } safeClose(inputStream); safeClose(outputStream); } } } catch (Throwable e) { sendErrorMessage(e.getLocalizedMessage(), CONNECTION_ERROR, callbackContext); } finally { if (connection != null) { // Revert back to the proper verifier and socket factories if (trustEveryone && useHttps) { HttpsURLConnection https = (HttpsURLConnection) connection; https.setHostnameVerifier(oldHostnameVerifier); https.setSSLSocketFactory(oldSocketFactory); } } } return true; }
From source file:org.getlantern.firetweet.util.Utils.java
public static String getStatusShareText(final Context context, final ParcelableStatus status) { final Uri link = LinkCreator.getTwitterStatusLink(status.user_screen_name, status.id); return context.getString(R.string.status_share_text_format_with_link, status.text_plain, link.toString()); }