List of usage examples for android.widget RelativeLayout getMeasuredWidth
public final int getMeasuredWidth()
From source file:org.coursera.android.shift.ShiftIconFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { final RelativeLayout layout = (RelativeLayout) inflater.inflate(R.layout.shift_menu, container, false); mHead = layout.findViewById(R.id.head); final RelativeLayout.LayoutParams iconParams; iconParams = (RelativeLayout.LayoutParams) mHead.getLayoutParams(); final GestureDetector gestureDetector = new GestureDetector(getActivity(), new SingleTapConfirm()); mHead.setOnTouchListener(new View.OnTouchListener() { private int initialX; private int initialY; private float initialTouchX; private float initialTouchY; @Override/*from w w w . j a v a 2 s .c o m*/ public boolean onTouch(View v, MotionEvent event) { final int yLimit = layout.getMeasuredHeight() - mHead.getMeasuredHeight(); final int xLimit = layout.getMeasuredWidth() - mHead.getMeasuredWidth(); // single tap if (gestureDetector.onTouchEvent(event)) { mShiftLauncherView.showShiftMenu(getActivity()); return true; } // drag icon switch (event.getAction()) { case MotionEvent.ACTION_DOWN: initialX = iconParams.leftMargin; initialY = iconParams.topMargin; initialTouchX = event.getRawX(); initialTouchY = event.getRawY(); return true; case MotionEvent.ACTION_CANCEL: return false; case MotionEvent.ACTION_UP: return true; case MotionEvent.ACTION_MOVE: int newX = initialX + (int) (event.getRawX() - initialTouchX); int newY = initialY + (int) (event.getRawY() - initialTouchY); iconParams.leftMargin = newX < 0 ? 0 : Math.min(newX, xLimit); iconParams.topMargin = newY < 0 ? 0 : Math.min(newY, yLimit); layout.updateViewLayout(mHead, iconParams); return true; } return false; } }); return layout; }
From source file:cl.ipp.katbag.fragment.Player.java
public Bitmap createBitmapFromRelativeLayout(RelativeLayout view) { view.setLayoutParams(new LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT)); view.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED), MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED)); view.layout(0, 0, view.getMeasuredWidth(), view.getMeasuredHeight()); Bitmap bitmap = Bitmap.createBitmap(view.getMeasuredWidth(), view.getMeasuredHeight(), Bitmap.Config.ARGB_8888);// ww w . j ava2 s .com Canvas c = new Canvas(bitmap); view.draw(c); return bitmap; }
From source file:com.mobileman.moments.android.frontend.fragments.StreamListFragment.java
private void doIt() { // View v = ((LayoutInflater) getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(R.layout.overlay_thumbnail, null, false); /* Bitmap overlayBitmap = Bitmap.createBitmap(getResources().getDimensionPixelOffset(R.dimen.thumbnailWidth), getResources().getDimensionPixelOffset(R.dimen.thumbnailHeight),Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(overlayBitmap); Drawable bgDrawable = overlayView.getBackground(); if (bgDrawable!=null)/*from w w w. ja v a 2 s . c o m*/ bgDrawable.draw(canvas); else canvas.drawColor(Color.WHITE); overlayView.draw(canvas); */ LayoutInflater mInflater = (LayoutInflater) getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE); //Inflate the layout into a view and configure it the way you like RelativeLayout view = new RelativeLayout(getActivity()); mInflater.inflate(R.layout.overlay_thumbnail, view, true); // TextView tv = (TextView) findViewById(R.id.my_text); // tv.setText("Beat It!!"); //Provide it with a layout params. It should necessarily be wrapping the //content as we not really going to have a parent for it. view.setLayoutParams(new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT)); //Pre-measure the view so that height and width don't remain null. view.measure(View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED), View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED)); //Assign a size and position to the view and all of its descendants view.layout(0, 0, view.getMeasuredWidth(), view.getMeasuredHeight()); //Create the bitmap Bitmap bitmap = Bitmap.createBitmap(view.getMeasuredWidth(), view.getMeasuredHeight(), Bitmap.Config.ARGB_8888); //Create a canvas with the specified bitmap to draw into Canvas c = new Canvas(bitmap); //Render this view (and all of its children) to the given Canvas view.draw(c); String path = Environment.getExternalStorageDirectory().toString(); OutputStream fOut = null; File file = new File(path, "testing.jpg"); // the File to save to try { fOut = new FileOutputStream(file); } catch (FileNotFoundException e) { e.printStackTrace(); } bitmap.compress(Bitmap.CompressFormat.JPEG, 85, fOut); // saving the Bitmap to a file compressed as a JPEG with 85% compression rate try { fOut.flush(); } catch (IOException e) { e.printStackTrace(); } finally { try { fOut.close(); // do not forget to close the stream } catch (IOException e) { e.printStackTrace(); } } }
From source file:ch.uzh.supersede.feedbacklibrary.AnnotateImageActivity.java
@Override public boolean onOptionsItemSelected(MenuItem item) { int id = item.getItemId(); // In both cases whether the action is accepted or cancelled, the temporary stored files need to be deleted List<File> tempFiles = annotateImageView.getCroppedImageLists(); for (int i = 1; i < tempFiles.size(); ++i) { tempFiles.get(i).delete();// w w w . ja v a2s .c o m } tempFiles.clear(); if (id == R.id.supersede_feedbacklibrary_action_annotate_cancel) { super.onBackPressed(); return true; } if (id == R.id.supersede_feedbacklibrary_action_annotate_accept) { RelativeLayout relativeLayout = (RelativeLayout) findViewById( R.id.supersede_feedbacklibrary_annotate_image_layout); if (relativeLayout != null) { // Remove all the annotation which are out of bounds removeOutOfBoundsAnnotations(); // Hide all control items hideAllControlItems(relativeLayout); // Process all the sticker annotations HashMap<Integer, String> allStickerAnnotations = processStickerAnnotations(relativeLayout); // Process all the text annotations HashMap<Integer, String> allTextAnnotations = processTextAnnotations(relativeLayout); String annotatedImagePathWithoutStickers = null; if (allStickerAnnotations.size() > 0 || allTextAnnotations.size() > 0) { // Get the bitmap (image without stickers if there are any) Bitmap annotatedBitmapWithoutStickers = annotateImageView.getBitmap(); annotatedImagePathWithoutStickers = Utils.saveBitmapToInternalStorage(getApplicationContext(), "imageDir", mechanismViewId + FeedbackActivity.ANNOTATED_IMAGE_NAME_WITHOUT_STICKERS, annotatedBitmapWithoutStickers, Context.MODE_PRIVATE, Bitmap.CompressFormat.PNG, 100); } // Convert the ViewGroup, i.e., the supersede_feedbacklibrary_annotate_picture_layout into a bitmap (image with stickers) relativeLayout.measure( View.MeasureSpec.makeMeasureSpec(annotateImageView.getBitmapWidth(), View.MeasureSpec.EXACTLY), View.MeasureSpec.makeMeasureSpec(annotateImageView.getBitmapHeight(), View.MeasureSpec.EXACTLY)); relativeLayout.layout(0, 0, relativeLayout.getMeasuredWidth(), relativeLayout.getMeasuredHeight()); Bitmap annotatedBitmapWithStickers = Bitmap.createBitmap(relativeLayout.getLayoutParams().width, relativeLayout.getLayoutParams().height, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(annotatedBitmapWithStickers); relativeLayout.draw(canvas); Bitmap croppedBitmap = Bitmap.createBitmap(annotatedBitmapWithStickers, 0, 0, annotateImageView.getBitmapWidth(), annotateImageView.getBitmapHeight()); String annotatedImagePathWithStickers = Utils.saveBitmapToInternalStorage(getApplicationContext(), "imageDir", mechanismViewId + FeedbackActivity.ANNOTATED_IMAGE_NAME_WITH_STICKERS, croppedBitmap, Context.MODE_PRIVATE, Bitmap.CompressFormat.PNG, 100); Intent intent = new Intent(); intent.putExtra(Utils.EXTRA_KEY_MECHANISM_VIEW_ID, mechanismViewId); intent.putExtra(Utils.EXTRA_KEY_ANNOTATED_IMAGE_PATH_WITHOUT_STICKERS, annotatedImagePathWithoutStickers); intent.putExtra(Utils.EXTRA_KEY_ANNOTATED_IMAGE_PATH_WITH_STICKERS, annotatedImagePathWithStickers); intent.putExtra(Utils.EXTRA_KEY_HAS_STICKER_ANNOTATIONS, allStickerAnnotations.size() > 0); intent.putExtra(Utils.EXTRA_KEY_ALL_STICKER_ANNOTATIONS, allStickerAnnotations); intent.putExtra(Utils.EXTRA_KEY_HAS_TEXT_ANNOTATIONS, allTextAnnotations.size() > 0); intent.putExtra(Utils.EXTRA_KEY_ALL_TEXT_ANNOTATIONS, allTextAnnotations); setResult(RESULT_OK, intent); } super.onBackPressed(); return true; } return super.onOptionsItemSelected(item); }