List of usage examples for android.widget LinearLayout draw
@CallSuper public void draw(Canvas canvas)
From source file:rosmi.acagild.alarmclock.ringing.ShareFragment.java
private static void drawStamp(Context context, Bitmap bitmap, String question) { Canvas canvas = new Canvas(bitmap); canvas.drawBitmap(bitmap, 0, 0, null); float opacity = 0.7f; int horizontalPadding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 10, context.getResources().getDisplayMetrics()); int verticalPadding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 10, context.getResources().getDisplayMetrics()); int textSize = 16; // defined in SP int height = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, 16, context.getResources().getDisplayMetrics()); LinearLayout layout = new LinearLayout(context); layout.setOrientation(LinearLayout.HORIZONTAL); layout.setBackgroundResource(R.drawable.rounded_corners); layout.getBackground().setAlpha((int) (opacity * 255)); layout.setPadding(horizontalPadding, verticalPadding, horizontalPadding, verticalPadding); ImageView logo = new ImageView(context); logo.setImageDrawable(ContextCompat.getDrawable(context, R.mipmap.ic_launcher)); layout.addView(logo);//from ww w . ja v a 2s . co m TextView textView = new TextView(context); textView.setVisibility(View.VISIBLE); if (question != null) { textView.setText(question); } else { textView.setText("Mimicker"); } textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, textSize); textView.setPadding(horizontalPadding, 0, 0, 0); LinearLayout.LayoutParams centerInParent = new LinearLayout.LayoutParams( ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); centerInParent.gravity = Gravity.CENTER_VERTICAL; layout.addView(textView, centerInParent); layout.measure(canvas.getWidth(), height); layout.layout(0, 0, layout.getMeasuredWidth(), layout.getMeasuredHeight()); canvas.translate(horizontalPadding, (float) (canvas.getHeight() * 0.8 - height)); float scale = Math.min(1.0f, canvas.getWidth() / 1080f); canvas.scale(scale, scale); layout.draw(canvas); }
From source file:com.microsoft.mimickeralarm.ringing.ShareFragment.java
private static void drawStamp(Context context, Bitmap bitmap, String question) { Canvas canvas = new Canvas(bitmap); canvas.drawBitmap(bitmap, 0, 0, null); float opacity = 0.7f; int horizontalPadding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 10, context.getResources().getDisplayMetrics()); int verticalPadding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 10, context.getResources().getDisplayMetrics()); int textSize = 16; // defined in SP int height = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, 16, context.getResources().getDisplayMetrics()); LinearLayout layout = new LinearLayout(context); layout.setOrientation(LinearLayout.HORIZONTAL); layout.setBackgroundResource(R.drawable.rounded_corners); layout.getBackground().setAlpha((int) (opacity * 255)); layout.setPadding(horizontalPadding, verticalPadding, horizontalPadding, verticalPadding); ImageView logo = new ImageView(context); logo.setImageDrawable(ContextCompat.getDrawable(context, R.mipmap.ic_launcher_no_bg)); layout.addView(logo);// w w w. j ava 2s . co m TextView textView = new TextView(context); textView.setVisibility(View.VISIBLE); if (question != null) { textView.setText(question); } else { textView.setText("Mimicker"); } textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, textSize); textView.setPadding(horizontalPadding, 0, 0, 0); LinearLayout.LayoutParams centerInParent = new LinearLayout.LayoutParams( ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); centerInParent.gravity = Gravity.CENTER_VERTICAL; layout.addView(textView, centerInParent); layout.measure(canvas.getWidth(), height); layout.layout(0, 0, layout.getMeasuredWidth(), layout.getMeasuredHeight()); canvas.translate(horizontalPadding, (float) (canvas.getHeight() * 0.8 - height)); float scale = Math.min(1.0f, canvas.getWidth() / 1080f); canvas.scale(scale, scale); layout.draw(canvas); }
From source file:com.microsoft.mimickeralarm.mimics.MimicTongueTwisterFragment.java
private void createSharableBitmap() { Bitmap sharableBitmap = Bitmap.createBitmap(getView().getWidth(), getView().getHeight(), Bitmap.Config.ARGB_8888);//from w w w . ja v a 2 s. c om Canvas canvas = new Canvas(sharableBitmap); canvas.drawColor(ContextCompat.getColor(getContext(), R.color.white)); // Load the view for the sharable. This will be drawn to the bitmap LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); LinearLayout layout = (LinearLayout) inflater.inflate(R.layout.fragment_sharable_tongue_twister, null); TextView textView = (TextView) layout.findViewById(R.id.twister_sharable_tongue_twister); textView.setText(mQuestion); textView = (TextView) layout.findViewById(R.id.twister_sharable_i_said); textView.setText(mUnderstoodText); textView = (TextView) layout.findViewById(R.id.mimic_twister_share_success); textView.setText(mSuccessMessage); // Perform the layout using the dimension of the bitmap int widthSpec = View.MeasureSpec.makeMeasureSpec(canvas.getWidth(), View.MeasureSpec.EXACTLY); int heightSpec = View.MeasureSpec.makeMeasureSpec(canvas.getHeight(), View.MeasureSpec.EXACTLY); layout.measure(widthSpec, heightSpec); layout.layout(0, 0, layout.getMeasuredWidth(), layout.getMeasuredHeight()); // Draw the generated view to canvas layout.draw(canvas); String title = getString(R.string.app_short_name) + ": " + getString(R.string.mimic_twister_name); mSharableUri = ShareFragment.saveShareableBitmap(getActivity(), sharableBitmap, title); }