Example usage for android.widget LinearLayout setBackgroundDrawable

List of usage examples for android.widget LinearLayout setBackgroundDrawable

Introduction

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

Prototype

@Deprecated
public void setBackgroundDrawable(Drawable background) 

Source Link

Usage

From source file:com.example.app_2.utils.Utils.java

public static void setWallpaper(android.view.ViewGroup vg, int reqWidth, int reqHeight, Bitmap wallpaper,
        ScalingLogic sl) {//w  w w .  java2 s. c  om

    if (wallpaper == null) {
        WallpaperManager wallpaperManager = WallpaperManager.getInstance(App_2.getAppContext());
        Drawable wallpaperDrawable = wallpaperManager.getDrawable();
        wallpaper = BitmapCalc.drawableToBitmap(wallpaperDrawable);
    }

    if (reqHeight == 0 || reqWidth == 0) {
        reqHeight = App_2.getMaxHeight();
        reqWidth = App_2.getMaxWidth();
    }

    Resources r = App_2.getAppContext().getResources();
    int orientation = r.getConfiguration().orientation;

    switch (orientation) {
    case Configuration.ORIENTATION_LANDSCAPE: // landscape
        Bitmap wallpaperLandscape = ScalingUtilities.createScaledBitmap(wallpaper, reqHeight, reqWidth, sl);
        if (Utils.hasJellyBean())
            vg.setBackground(new BitmapDrawable(r, wallpaperLandscape));
        else {
            if (vg instanceof LinearLayout) {
                LinearLayout ll = (LinearLayout) vg;
                ll.setBackgroundDrawable(new BitmapDrawable(r, wallpaperLandscape));
            } else if (vg instanceof DrawerLayout) {
                DrawerLayout dl = (DrawerLayout) vg;
                dl.setBackgroundDrawable(new BitmapDrawable(r, wallpaperLandscape));
            }

        }
        //wallpaperLandscape.recycle();
        break;
    case Configuration.ORIENTATION_PORTRAIT: // portrait
        Bitmap wallpaperPortrait = ScalingUtilities.createScaledBitmap(wallpaper, reqWidth, reqHeight, sl);

        if (Utils.hasJellyBean())
            vg.setBackground(new BitmapDrawable(r, wallpaperPortrait));
        else {
            if (vg instanceof LinearLayout) {
                LinearLayout ll = (LinearLayout) vg;
                ll.setBackgroundDrawable(new BitmapDrawable(r, wallpaperPortrait));
            } else if (vg instanceof DrawerLayout) {
                DrawerLayout dl = (DrawerLayout) vg;
                dl.setBackgroundDrawable(new BitmapDrawable(r, wallpaperPortrait));
            }
        }
        //wallpaperPortrait.recycle();
        break;
    default:
        //ll.setBackgroundDrawable(App_2.wallpaperDrawable);
        break;
    }
}

From source file:fi.tuukka.weather.utils.Utils.java

public static void setBackGroundDrawable(Activity activity, LinearLayout layout, Bitmap bmp) {
    // int sdk = android.os.Build.VERSION.SDK_INT;
    // if (sdk < android.os.Build.VERSION_CODES.JELLY_BEAN) {
    layout.setBackgroundDrawable(new BitmapDrawable(activity.getResources(), bmp));
    // } else {/* w w w.j  a  v  a 2s  .c om*/
    // layout.setBackground(new BitmapDrawable(activity.getResources(), bmp));
    // }
}

From source file:it.redturtle.mobile.apparpav.MeteogramAdapter.java

/**
 * SINGLE IMAGE ROW//from   w w w  .  ja  v  a  2  s.c  o  m
 * @param att
 * @param linear
 * @return
 */
public LinearLayout getSingleImageRow(Map<String, String> att, LinearLayout linear) {

    LinearLayout container_layout = new LinearLayout(context);
    container_layout.setBackgroundDrawable(context.getResources().getDrawable(R.drawable.view_shape_meteo));
    container_layout.setMinimumHeight(46);
    container_layout.setVerticalGravity(Gravity.CENTER);

    LinearLayout.LayoutParams value = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT,
            LayoutParams.WRAP_CONTENT, 0.5f);
    TextView tx = new TextView(context);
    tx.setText(att.get("title"));
    tx.setTextSize(11);
    tx.setTypeface(null, Typeface.BOLD);
    tx.setGravity(Gravity.LEFT);
    tx.setPadding(3, 0, 0, 2);
    tx.setTextColor(Color.rgb(66, 66, 66));
    container_layout.addView(tx, value);

    LinearLayout.LayoutParams value_params = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, 40, 0.5f);
    ImageView img = new ImageView(context);
    String path = "it.redturtle.mobile.apparpav:drawable/" + FilenameUtils.removeExtension(att.get("value"));
    img.setImageResource(context.getResources().getIdentifier(path, null, null));
    img.setPadding(0, 3, 0, 3);
    container_layout.addView(img, value_params);

    linear.addView(container_layout);
    return linear;
}

From source file:it.redturtle.mobile.apparpav.MeteogramAdapter.java

/**
 * SINGLE TEXT ROW/*  w  w w . jav  a 2  s  . co  m*/
 * @param att
 * @param linear
 * @return
 */
public LinearLayout getSingleTextRow(Map<String, String> att, LinearLayout linear) {

    LinearLayout container_layout = new LinearLayout(context);
    container_layout.setBackgroundDrawable(context.getResources().getDrawable(R.drawable.view_shape_meteo));
    container_layout.setMinimumHeight(46);
    container_layout.setVerticalGravity(Gravity.CENTER);

    LinearLayout.LayoutParams value = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT,
            LayoutParams.WRAP_CONTENT, 0.5f);
    TextView tx = new TextView(context);
    tx.setText(att.get("title"));
    tx.setTextSize(11);
    tx.setTypeface(null, Typeface.BOLD);
    tx.setGravity(Gravity.LEFT);
    tx.setPadding(3, 0, 0, 2);
    tx.setTextColor(Color.rgb(66, 66, 66));
    container_layout.addView(tx, value);

    LinearLayout.LayoutParams value_params = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT,
            LayoutParams.WRAP_CONTENT, 0.5f);
    TextView t2 = new TextView(context);
    t2.setText(att.get("value").equals("") ? " - " : att.get("value"));
    t2.setTextSize(11);
    t2.setGravity(Gravity.CENTER_HORIZONTAL);
    t2.setPadding(2, 0, 0, 2);
    t2.setTextColor(Color.rgb(66, 66, 66));
    container_layout.addView(t2, value_params);

    linear.addView(container_layout);
    return linear;
}

From source file:it.redturtle.mobile.apparpav.MeteogramAdapter.java

/**
 * DOUBLE IMAGE ROW//from w ww  .j av  a  2s .  co  m
 * @param att
 * @param linear
 * @return
 */
public LinearLayout getDoubleImageRow(Map<String, String> att, LinearLayout linear) {

    LinearLayout container_layout = new LinearLayout(context);
    container_layout.setBackgroundDrawable(context.getResources().getDrawable(R.drawable.view_shape_meteo));
    container_layout.setMinimumHeight(46);
    container_layout.setVerticalGravity(Gravity.CENTER);

    LinearLayout.LayoutParams value_params = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT,
            LayoutParams.WRAP_CONTENT, 0.3f);
    TextView tx = new TextView(context);
    tx.setText(att.get("title"));
    tx.setTextSize(11);
    tx.setTypeface(null, Typeface.BOLD);
    tx.setGravity(Gravity.LEFT);
    tx.setPadding(3, 0, 0, 2);
    tx.setTextColor(Color.rgb(66, 66, 66));
    container_layout.addView(tx, value_params);

    LinearLayout.LayoutParams value_one_params = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, 46,
            0.35f);
    ImageView img1 = new ImageView(context);
    String path = "it.redturtle.mobile.apparpav:drawable/" + FilenameUtils.removeExtension(att.get("value1"));
    img1.setImageResource(context.getResources().getIdentifier(path, null, null));
    img1.setPadding(0, 3, 0, 3);
    container_layout.addView(img1, value_one_params);

    LinearLayout.LayoutParams value_two_params = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, 46,
            0.35f);
    ImageView img2 = new ImageView(context);
    path = "it.redturtle.mobile.apparpav:drawable/" + FilenameUtils.removeExtension(att.get("value2"));
    img2.setImageResource(context.getResources().getIdentifier(path, null, null));
    img2.setPadding(0, 3, 0, 3);
    container_layout.addView(img2, value_two_params);

    linear.addView(container_layout);

    return linear;
}

From source file:it.redturtle.mobile.apparpav.MeteogramAdapter.java

/**
 * DOUBLE TEXT ROW/*w  w w. j av  a2s . com*/
 * @param att
 * @param linear
 * @return
 */
public LinearLayout getDoubleTextRow(Map<String, String> att, LinearLayout linear) {

    LinearLayout container_layout = new LinearLayout(context);
    container_layout.setBackgroundDrawable(context.getResources().getDrawable(R.drawable.view_shape_meteo));
    container_layout.setMinimumHeight(46);
    container_layout.setVerticalGravity(Gravity.CENTER);

    LinearLayout.LayoutParams value_params = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT,
            LayoutParams.WRAP_CONTENT, 0.3f);
    TextView tx = new TextView(context);
    tx.setText(att.get("title"));
    tx.setTextSize(11);
    tx.setTypeface(null, Typeface.BOLD);
    tx.setGravity(Gravity.LEFT);
    tx.setPadding(2, 0, 0, 2);
    tx.setTextColor(Color.rgb(66, 66, 66));
    container_layout.addView(tx, value_params);

    LinearLayout.LayoutParams value_one_params = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT,
            LayoutParams.WRAP_CONTENT, 0.35f);
    TextView t1 = new TextView(context);
    t1.setText(att.get("value1").equals("") ? " - " : att.get("value1"));
    t1.setTextSize(11);
    t1.setGravity(Gravity.CENTER_HORIZONTAL);
    t1.setPadding(2, 0, 0, 2);
    t1.setTextColor(Color.rgb(66, 66, 66));
    container_layout.addView(t1, value_one_params);

    LinearLayout.LayoutParams value_two_params = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT,
            LayoutParams.WRAP_CONTENT, 0.35f);
    TextView t2 = new TextView(context);
    t2.setTextSize(11);
    t2.setText(att.get("value2").equals("") ? " - " : att.get("value2"));
    t2.setGravity(Gravity.CENTER_HORIZONTAL);
    t2.setPadding(2, 0, 0, 2);
    t2.setTextColor(Color.rgb(66, 66, 66));
    container_layout.addView(t2, value_two_params);

    linear.addView(container_layout);

    return linear;
}

From source file:it.redturtle.mobile.apparpav.MeteogramAdapter.java

/**
 * SINGLE TITLE ROW/*from   w w  w.  ja va  2s.c o m*/
 * @param att
 * @param linear
 * @return
 */
public LinearLayout getSingleTitleRow(Map<String, String> att, LinearLayout linear) {
    LinearLayout container_layout = new LinearLayout(context);
    container_layout.setMinimumHeight(30);
    container_layout
            .setBackgroundDrawable(context.getResources().getDrawable(R.drawable.view_shape_meteo_blue));
    container_layout.setVerticalGravity(Gravity.CENTER);

    LinearLayout.LayoutParams value_params = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT,
            LayoutParams.WRAP_CONTENT, 0.5f);
    TextView tx = new TextView(context);
    tx.setTextColor(Color.rgb(66, 66, 66));
    container_layout.addView(tx, value_params);

    LinearLayout.LayoutParams ltext1 = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT,
            LayoutParams.WRAP_CONTENT, 0.5f);
    TextView t1 = new TextView(context);
    t1.setText(att.get("value"));
    t1.setTextSize(11);
    t1.setGravity(Gravity.CENTER_HORIZONTAL);
    t1.setPadding(2, 0, 0, 2);
    t1.setTextColor(Color.rgb(255, 255, 255));
    container_layout.addView(t1, ltext1);

    linear.addView(container_layout);
    return linear;
}

From source file:com.uzmap.pkg.uzmodules.uzBMap.mode.Billboard.java

@SuppressWarnings("deprecation")
public View billboardView() {
    LinearLayout billboardLayout = new LinearLayout(context);
    LayoutParams layoutParams = null;/*from  w ww  .j a v a2  s . c  o m*/
    if (bgImg != null) {
        billboardLayout.setBackgroundDrawable(new BitmapDrawable(bgImg));
        layoutParams = new LayoutParams(UZCoreUtil.dipToPix(width), UZCoreUtil.dipToPix(height));
    } else {
        billboardLayout.setBackgroundResource(UZResourcesIDFinder.getResDrawableID("mo_bmap_popupmap"));
        layoutParams = new LayoutParams(LayoutParams.WRAP_CONTENT, UZCoreUtil.dipToPix(height));
    }
    billboardLayout.setLayoutParams(layoutParams);
    billboardLayout.setOrientation(LinearLayout.HORIZONTAL);
    if (getIconAlign().equals("left")) {
        if (iconStr != null && !iconStr.isEmpty())
            billboardLayout.addView(icon());
        billboardLayout.addView(titleLayout());
    } else {
        billboardLayout.addView(titleLayout());
        if (iconStr != null && !iconStr.isEmpty())
            billboardLayout.addView(icon());
    }
    return billboardLayout;
}

From source file:com.uzmap.pkg.uzmodules.uzBMap.mode.Billboard.java

@SuppressWarnings("deprecation")
public View billboardView(ImageView icon) {
    LinearLayout billboardLayout = new LinearLayout(context);
    LayoutParams layoutParams = null;/*from  ww  w  .j  a  v a  2s .  c  o  m*/
    if (bgImg != null) {
        billboardLayout.setBackgroundDrawable(new BitmapDrawable(bgImg));
        layoutParams = new LayoutParams(UZCoreUtil.dipToPix(width), UZCoreUtil.dipToPix(height));
    } else {
        billboardLayout.setBackgroundResource(UZResourcesIDFinder.getResDrawableID("mo_bmap_popupmap"));
        layoutParams = new LayoutParams(LayoutParams.WRAP_CONTENT, UZCoreUtil.dipToPix(height));
    }
    billboardLayout.setLayoutParams(layoutParams);
    billboardLayout.setOrientation(LinearLayout.HORIZONTAL);
    if (getIconAlign().equals("left")) {
        if (iconStr != null && !iconStr.isEmpty())
            billboardLayout.addView(icon);
        billboardLayout.addView(titleLayout());
    } else {
        billboardLayout.addView(titleLayout());
        if (iconStr != null && !iconStr.isEmpty())
            billboardLayout.addView(icon());
    }
    return billboardLayout;
}

From source file:it.redturtle.mobile.apparpav.MeteogramAdapter.java

/**
 * DOUBLE TITLE ROW//from   ww  w . j av  a  2 s.  c om
 * @param att
 * @param linear
 * @return
 */
public LinearLayout getDoubleTitleRow(Map<String, String> att, LinearLayout linear) {
    LinearLayout container_layout = new LinearLayout(context);
    container_layout.setMinimumHeight(30);
    container_layout
            .setBackgroundDrawable(context.getResources().getDrawable(R.drawable.view_shape_meteo_blue));
    container_layout.setVerticalGravity(Gravity.CENTER);
    container_layout.setOrientation(LinearLayout.HORIZONTAL);

    LinearLayout.LayoutParams value_params = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT,
            LayoutParams.WRAP_CONTENT, 0.3f);
    TextView tx = new TextView(context);
    tx.setText("");
    tx.setTextColor(Color.rgb(66, 66, 66));
    container_layout.addView(tx, value_params);

    LinearLayout.LayoutParams ltext1 = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT,
            LayoutParams.WRAP_CONTENT, 0.35f);
    TextView t1 = new TextView(context);
    t1.setText(att.get("value1"));
    t1.setTextSize(11);
    t1.setGravity(Gravity.CENTER_HORIZONTAL);
    t1.setPadding(2, 0, 0, 2);
    t1.setTextColor(Color.rgb(255, 255, 255));
    container_layout.addView(t1, ltext1);

    LinearLayout.LayoutParams ltext2 = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT,
            LayoutParams.WRAP_CONTENT, 0.35f);
    TextView t2 = new TextView(context);
    t2.setText(att.get("value2"));
    t2.setTextSize(11);
    t2.setGravity(Gravity.CENTER_HORIZONTAL);
    t2.setPadding(2, 0, 0, 2);
    t2.setTextColor(Color.rgb(255, 255, 255));
    container_layout.addView(t2, ltext2);

    linear.addView(container_layout);
    return linear;
}