Example usage for android.widget LinearLayout layout

List of usage examples for android.widget LinearLayout layout

Introduction

In this page you can find the example usage for android.widget LinearLayout layout.

Prototype

@Override
    public final void layout(int l, int t, int r, int b) 

Source Link

Usage

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);/*ww w  .ja  va  2  s.c  o  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);//from  w  ww  .j  a va  2s .  c o  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  ww  .j  a va2s.co  m
    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);
}

From source file:com.thingsee.tracker.MainActivity.java

public static void refreshTrackerMarker(String serial) {
    TrackerModel trackerModel = trackers.get(serial);
    if (trackerModel != null) {
        LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        LinearLayout tv = (LinearLayout) inflater.inflate(R.layout.tracker_map_marker, null, false);
        ImageView image2 = (ImageView) tv.findViewById(R.id.tracker_marker_icon);
        TextView name = (TextView) tv.findViewById(R.id.tracker_name);
        name.setText(trackerModel.getName());
        ImageView trackerBg = (ImageView) trackerModel.getView().findViewById(R.id.tracker_image_bg);
        if (trackerModel.isLocationTimeoutAlarmOn()) {
            image2.setColorFilter(mResources.getColor(R.color.red));
            trackerBg.setColorFilter(mResources.getColor(R.color.red));
            name.setTextColor(mResources.getColor(R.color.white_effect));
        } else {// w  ww  .j av  a  2 s . c o m
            image2.clearColorFilter();
            trackerBg.setColorFilter(mResources.getColor(R.color.green));
            name.setTextColor(mResources.getColor(R.color.black_effect));
        }
        tv.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED),
                MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
        tv.layout(0, 0, tv.getMeasuredWidth(), tv.getMeasuredHeight());
        tv.setDrawingCacheEnabled(true);
        tv.buildDrawingCache();
        Bitmap bm = tv.getDrawingCache();
        tv = null;
        if (trackerModel.getMarker() != null) {
            trackerModel.getMarker().setIcon(BitmapDescriptorFactory.fromBitmap(bm));
        }
        if (trackerModelWithMarker != null) {
            if (onChildOnMapView) {
                trackerModelWithMarker.getMarker().showInfoWindow();
            }
        }
    }
}

From source file:com.example.SmartBoard.DrawingView.java

public Bitmap textToBitmap(String text, int color, float posX, float posY, int size) {
    TextView textView = new TextView(getContext());
    textView.setVisibility(View.VISIBLE);
    textView.setTextColor(color);/*from w  w w  .j a v  a  2 s .c om*/
    textView.setMaxWidth(500);
    textView.setMaxHeight(500);
    textView.setMaxLines(4);
    textView.setX(posX);
    textView.setY(posY);
    textView.setText(text);
    textView.setTextSize(size);

    LinearLayout layout = new LinearLayout(getContext());
    layout.addView(textView);
    layout.measure(500, 500);
    layout.layout(0, 0, 500, 500);

    textView.setDrawingCacheEnabled(true);
    textView.buildDrawingCache();
    Bitmap bm = textView.getDrawingCache();
    return bm;
}

From source file:com.thingsee.tracker.MainActivity.java

@SuppressLint("InflateParams")
private Marker makeMarkerToMap(LatLng latLng, boolean visible, boolean alarmActive, String name,
        double timeStamp, double accuracy) {
    String snippet;/*from w  ww .ja v a  2 s  .co  m*/
    LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    LinearLayout tv = (LinearLayout) inflater.inflate(R.layout.tracker_map_marker, null, false);
    TextView trackerName = (TextView) tv.findViewById(R.id.tracker_name);
    trackerName.setText(name);
    ImageView image2 = (ImageView) tv.findViewById(R.id.tracker_marker_icon);
    if (alarmActive) {
        image2.setColorFilter(mResources.getColor(R.color.red));
        trackerName.setTextColor(mResources.getColor(R.color.white_effect));
    } else {
        image2.setColorFilter(mResources.getColor(R.color.dark_blue));
        trackerName.setTextColor(mResources.getColor(R.color.white_effect));
    }
    tv.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED),
            MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
    tv.layout(0, 0, tv.getMeasuredWidth(), tv.getMeasuredHeight());
    tv.setDrawingCacheEnabled(true);
    tv.buildDrawingCache();
    Bitmap bm = tv.getDrawingCache();
    tv = null;

    if (accuracy != -1) {
        snippet = String.format(mResources.getString(R.string.tracker_accuracy), accuracy);
    } else {
        snippet = String.format(mResources.getString(R.string.tracker_accuracy), 0.0f);
    }
    if (timeStamp != 0) {
        String timeStampText = Utilities.getSmartTimeStampString(mContext, mResources, timeStamp);
        snippet = snippet + "\n" + mResources.getString(R.string.tracker_timestamp) + " " + timeStampText;
    } else {
        snippet = snippet + "\n" + mResources.getString(R.string.tracker_timestamp) + " - ";
    }
    return mMap.addMarker(new MarkerOptions().position(latLng).icon(BitmapDescriptorFactory.fromBitmap(bm))
            .visible(visible).title(name).snippet(snippet));
}