Example usage for android.widget LinearLayout setPadding

List of usage examples for android.widget LinearLayout setPadding

Introduction

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

Prototype

public void setPadding(int left, int top, int right, int bottom) 

Source Link

Document

Sets the padding.

Usage

From source file:org.yammp.dialog.SleepTimerDialog.java

@Override
public void onCreate(Bundle icicle) {

    super.onCreate(icicle);
    mUtils = ((YAMMPApplication) getApplication()).getMediaUtils();
    setContentView(new LinearLayout(this));

    DisplayMetrics dm = new DisplayMetrics();
    dm = getResources().getDisplayMetrics();

    action = getIntent().getAction();//from w ww  .j  a  va2  s.  c o  m

    mSleepTimerDialog = new AlertDialog.Builder(this).create();
    mSleepTimerDialog.setVolumeControlStream(AudioManager.STREAM_MUSIC);

    mRemained = (int) mUtils.getSleepTimerRemained() / 1000 / 60;

    LinearLayout mContainer = new LinearLayout(this);
    mContainer.setOrientation(LinearLayout.VERTICAL);
    mContainer.setPadding((int) dm.density * 8, 0, (int) dm.density * 8, 0);
    mTimeView = new TextView(this);
    mContainer.addView(mTimeView);
    mSetTime = new SeekBar(this);
    mSetTime.setMax(120);
    mContainer.addView(mSetTime);

    if (mRemained > 0) {
        mSetTime.setProgress(mRemained);
    } else {
        mSetTime.setProgress(30);
    }

    mSetTime.setOnSeekBarChangeListener(this);

    mProgress = mSetTime.getProgress();
    mTimerTime = mProgress;
    if (mTimerTime >= 1) {
        mPrompt = SleepTimerDialog.this.getResources().getQuantityString(R.plurals.NNNminutes, mTimerTime,
                mTimerTime);
    } else {
        mPrompt = SleepTimerDialog.this.getResources().getString(R.string.disabled);
    }
    mTimeView.setText(mPrompt);

    if (INTENT_SLEEP_TIMER.equals(action)) {
        mSleepTimerDialog.setIcon(android.R.drawable.ic_dialog_info);
        mSleepTimerDialog.setTitle(R.string.set_time);
        mSleepTimerDialog.setView(mContainer);
        mSleepTimerDialog.setButton(Dialog.BUTTON_POSITIVE, getString(android.R.string.ok),
                new OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {

                        if (mTimerTime >= 1) {
                            long milliseconds = mTimerTime * 60 * 1000;
                            boolean gentle = new PreferencesEditor(getApplicationContext())
                                    .getBooleanPref(KEY_GENTLE_SLEEPTIMER, true);
                            mUtils.startSleepTimer(milliseconds, gentle);
                        } else {
                            mUtils.stopSleepTimer();
                        }
                        finish();
                    }
                });
        mSleepTimerDialog.setButton(Dialog.BUTTON_NEGATIVE, getString(android.R.string.cancel),
                new OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {

                        finish();
                    }
                });
        mSleepTimerDialog.setOnCancelListener(new OnCancelListener() {

            @Override
            public void onCancel(DialogInterface dialog) {

                finish();
            }
        });
    } else {
        Toast.makeText(this, R.string.error_bad_parameters, Toast.LENGTH_SHORT).show();
        finish();
    }
}

From source file:org.telegram.ui.ChangePhoneHelpActivity.java

@Override
public View createView(Context context) {
    actionBar.setBackButtonImage(R.drawable.ic_ab_back);
    actionBar.setAllowOverlayTitle(true);

    TLRPC.User user = UserConfig.getCurrentUser();
    String value;// w  w  w .  j av a2  s  .com
    if (user != null && user.phone != null && user.phone.length() != 0) {
        value = PhoneFormat.getInstance().format("+" + user.phone);
    } else {
        value = LocaleController.getString("NumberUnknown", R.string.NumberUnknown);
    }

    actionBar.setTitle(value);
    actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
        @Override
        public void onItemClick(int id) {
            if (id == -1) {
                finishFragment();
            }
        }
    });

    fragmentView = new RelativeLayout(context);
    fragmentView.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            return true;
        }
    });

    RelativeLayout relativeLayout = (RelativeLayout) fragmentView;

    ScrollView scrollView = new ScrollView(context);
    relativeLayout.addView(scrollView);
    RelativeLayout.LayoutParams layoutParams3 = (RelativeLayout.LayoutParams) scrollView.getLayoutParams();
    layoutParams3.width = LayoutHelper.MATCH_PARENT;
    layoutParams3.height = LayoutHelper.WRAP_CONTENT;
    layoutParams3.addRule(RelativeLayout.CENTER_VERTICAL, RelativeLayout.TRUE);
    scrollView.setLayoutParams(layoutParams3);

    LinearLayout linearLayout = new LinearLayout(context);
    linearLayout.setOrientation(LinearLayout.VERTICAL);
    linearLayout.setPadding(0, AndroidUtilities.dp(20), 0, AndroidUtilities.dp(20));
    scrollView.addView(linearLayout);
    ScrollView.LayoutParams layoutParams = (ScrollView.LayoutParams) linearLayout.getLayoutParams();
    layoutParams.width = ScrollView.LayoutParams.MATCH_PARENT;
    layoutParams.height = ScrollView.LayoutParams.WRAP_CONTENT;
    linearLayout.setLayoutParams(layoutParams);

    ImageView imageView = new ImageView(context);
    imageView.setImageResource(R.drawable.phone_change);
    linearLayout.addView(imageView);
    LinearLayout.LayoutParams layoutParams2 = (LinearLayout.LayoutParams) imageView.getLayoutParams();
    layoutParams2.width = LayoutHelper.WRAP_CONTENT;
    layoutParams2.height = LayoutHelper.WRAP_CONTENT;
    layoutParams2.gravity = Gravity.CENTER_HORIZONTAL;
    imageView.setLayoutParams(layoutParams2);

    TextView textView = new TextView(context);
    textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
    textView.setGravity(Gravity.CENTER_HORIZONTAL);
    //textView.setTextColor(0xff212121);

    try {
        textView.setText(AndroidUtilities
                .replaceTags(LocaleController.getString("PhoneNumberHelp", R.string.PhoneNumberHelp)));
    } catch (Exception e) {
        FileLog.e("tmessages", e);
        textView.setText(LocaleController.getString("PhoneNumberHelp", R.string.PhoneNumberHelp));
    }
    linearLayout.addView(textView);
    layoutParams2 = (LinearLayout.LayoutParams) textView.getLayoutParams();
    layoutParams2.width = LayoutHelper.WRAP_CONTENT;
    layoutParams2.height = LayoutHelper.WRAP_CONTENT;
    layoutParams2.gravity = Gravity.CENTER_HORIZONTAL;
    layoutParams2.leftMargin = AndroidUtilities.dp(20);
    layoutParams2.rightMargin = AndroidUtilities.dp(20);
    layoutParams2.topMargin = AndroidUtilities.dp(56);
    textView.setLayoutParams(layoutParams2);

    textView = new TextView(context);
    textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
    textView.setGravity(Gravity.CENTER_HORIZONTAL);
    textView.setTextColor(ContextCompat.getColor(context, R.color.colorAccent) /*0xff4d83b3*/);
    textView.setText(LocaleController.getString("PhoneNumberChange", R.string.PhoneNumberChange));
    textView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
    textView.setPadding(AndroidUtilities.dp(16), AndroidUtilities.dp(12), AndroidUtilities.dp(16),
            AndroidUtilities.dp(12));
    textView.setBackground(context.getDrawable(R.drawable.list_selector));
    linearLayout.addView(textView);
    layoutParams2 = (LinearLayout.LayoutParams) textView.getLayoutParams();
    layoutParams2.width = LayoutHelper.WRAP_CONTENT;
    layoutParams2.height = LayoutHelper.WRAP_CONTENT;
    layoutParams2.gravity = Gravity.CENTER_HORIZONTAL;
    layoutParams2.leftMargin = AndroidUtilities.dp(20);
    layoutParams2.rightMargin = AndroidUtilities.dp(20);
    layoutParams2.topMargin = AndroidUtilities.dp(46);
    textView.setLayoutParams(layoutParams2);

    textView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (getParentActivity() == null) {
                return;
            }
            AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
            builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
            builder.setMessage(LocaleController.getString("PhoneNumberAlert", R.string.PhoneNumberAlert));
            builder.setPositiveButton(LocaleController.getString("OK", R.string.OK),
                    new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialogInterface, int i) {
                            presentFragment(new ChangePhoneActivity(), true);
                        }
                    });
            builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
            showDialog(builder.create());
        }
    });

    return fragmentView;
}

From source file:org.floens.chan.ui.controller.DrawerController.java

@Override
public void onPinLongClocked(final Pin pin) {
    LinearLayout wrap = new LinearLayout(context);
    wrap.setPadding(dp(16), dp(16), dp(16), 0);
    final EditText text = new EditText(context);
    text.setSingleLine();/*  www  .jav  a 2  s.  com*/
    text.setText(pin.loadable.title);
    wrap.addView(text, LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);

    AlertDialog dialog = new AlertDialog.Builder(context)
            .setPositiveButton(R.string.action_rename, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    String value = text.getText().toString();

                    if (!TextUtils.isEmpty(value)) {
                        pin.loadable.title = value;
                        Chan.getWatchManager().updatePin(pin);
                    }
                }
            }).setNegativeButton(R.string.cancel, null).setTitle(R.string.action_rename_pin).setView(wrap)
            .create();

    AndroidUtils.requestKeyboardFocus(dialog, text);

    dialog.show();
}

From source file:org.mdc.chess.SeekBarPreference.java

@Override
protected View onCreateView(ViewGroup parent) {
    TextView name = new TextView(getContext());
    name.setText(getTitle());//from   w  w w  . j  av a2s.  co m
    //name.setTextAppearance(getContext(), android.R.style.TextAppearance_Large);
    TextViewCompat.setTextAppearance(name, android.R.style.TextAppearance_Large);
    name.setGravity(Gravity.START);
    LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
            LinearLayout.LayoutParams.WRAP_CONTENT);
    lp.gravity = Gravity.START;
    lp.weight = 1.0f;
    name.setLayoutParams(lp);

    currValBox = new TextView(getContext());
    currValBox.setTextSize(12);
    currValBox.setTypeface(Typeface.MONOSPACE, Typeface.ITALIC);
    currValBox.setPadding(2, 5, 0, 0);
    currValBox.setText(valToString());
    lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
            LinearLayout.LayoutParams.WRAP_CONTENT);
    lp.gravity = Gravity.CENTER;
    currValBox.setLayoutParams(lp);

    LinearLayout row1 = new LinearLayout(getContext());
    row1.setOrientation(LinearLayout.HORIZONTAL);
    row1.addView(name);
    row1.addView(currValBox);

    final SeekBar bar = new SeekBar(getContext());
    bar.setMax(maxValue);
    bar.setProgress(currVal);
    bar.setOnSeekBarChangeListener(this);
    lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
            LinearLayout.LayoutParams.WRAP_CONTENT);
    lp.gravity = Gravity.END;
    bar.setLayoutParams(lp);

    CharSequence summaryCharSeq = getSummary();
    boolean haveSummary = (summaryCharSeq != null) && (summaryCharSeq.length() > 0);
    TextView summary = null;
    if (haveSummary) {
        summary = new TextView(getContext());
        summary.setText(getSummary());
        //            summary.setTextAppearance(getContext(), android.R.style.TextAppearance_Large);
        summary.setGravity(Gravity.START);
        lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
                LinearLayout.LayoutParams.WRAP_CONTENT);
        lp.gravity = Gravity.START;
        lp.weight = 1.0f;
        summary.setLayoutParams(lp);
    }

    LinearLayout layout = new LinearLayout(getContext());
    layout.setPadding(25, 5, 25, 5);
    layout.setOrientation(LinearLayout.VERTICAL);
    layout.addView(row1);
    layout.addView(bar);
    if (summary != null) {
        layout.addView(summary);
    }
    layout.setId(android.R.id.widget_frame);

    currValBox.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            View content = View.inflate(SeekBarPreference.this.getContext(), R.layout.select_percentage, null);
            final AlertDialog.Builder builder = new AlertDialog.Builder(SeekBarPreference.this.getContext());
            builder.setView(content);
            String title = "";
            String key = getKey();
            if (key.equals("strength")) {
                title = getContext().getString(R.string.edit_strength);
            } else if (key.equals("bookRandom")) {
                title = getContext().getString(R.string.edit_randomization);
            }
            builder.setTitle(title);
            final EditText valueView = (EditText) content.findViewById(R.id.selpercentage_number);
            valueView.setText(currValBox.getText().toString().replaceAll("%", "").replaceAll(",", "."));
            final Runnable selectValue = new Runnable() {
                public void run() {
                    try {
                        String txt = valueView.getText().toString();
                        int value = (int) (Double.parseDouble(txt) * 10 + 0.5);
                        if (value < 0)
                            value = 0;
                        if (value > maxValue)
                            value = maxValue;
                        onProgressChanged(bar, value, false);
                    } catch (NumberFormatException ignored) {

                    }
                }
            };
            valueView.setOnKeyListener(new OnKeyListener() {
                public boolean onKey(View v, int keyCode, KeyEvent event) {
                    if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) {
                        selectValue.run();
                        return true;
                    }
                    return false;
                }
            });
            builder.setPositiveButton("Ok", new Dialog.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    selectValue.run();
                }
            });
            builder.setNegativeButton("Cancel", null);

            builder.create().show();
        }
    });

    return layout;
}

From source file:fm.krui.kruifm.ScheduleFragment.java

/**
 * Adds a show to the schedule.//from w ww  .j  a v a 2 s  .c  om
 * @param title Title of show to display
 * @param description Description of show to display
 * @param startTime Start time of show in minutes from midnight
 * @param endTime End time of show in minutes from midnight
 * @param category Format of this show, required to correctly color the event.
 *
 * Valid settings for category include:
 *                 1 - Regular Rotation
 *                 2 - Music Speciality
 *                 3 - Sports
 *                 4 - News/Talk
 *                 5 - Specials
 */
private void addShow(String title, String description, int startTime, int endTime, int category) {

    /* Build the LinearLayout to function as the container for this show. Since the size of the container is to represent
    the length of the show, its height must be proportional (1dp = 1 minute) to the length. Determine length by finding the difference
    between the start and end times. */

    // Fix for corner case of shows ending at midnight.
    if (endTime == 0) {
        endTime = 1440;
    }
    int difference = endTime - startTime;

    /* Define the margins of this show. All shows must not overlap the displayed times, which are 50dp in width.
    Add 5 more (to the right and left) to see the schedule lines for clarity. Push the show down to align with the appropriate time marker using the top margin value set to the
    difference (in minutes) between midnight and the start of the show. */

    Log.v(TAG, "Configuring " + title);
    //Log.v(TAG, "Start time: " + startTime + " End time: " + endTime);
    //Log.v(TAG, "Setting parameters for " + title);
    RelativeLayout.LayoutParams rrLayoutParams = new RelativeLayout.LayoutParams(
            RelativeLayout.LayoutParams.MATCH_PARENT, dpToPixels(difference));
    rrLayoutParams.leftMargin = dpToPixels(55);
    //Log.v(TAG, "Left margin: " + rrLayoutParams.leftMargin);
    rrLayoutParams.topMargin = dpToPixels(startTime);
    //Log.v(TAG, "Top margin: " + rrLayoutParams.topMargin);
    rrLayoutParams.rightMargin = dpToPixels(5);
    //Log.v(TAG, "Right margin: " + rrLayoutParams.rightMargin);

    /* Build LinearLayout and apply parameters */
    LinearLayout eventLL = new LinearLayout(getActivity());
    eventLL.setOrientation(LinearLayout.VERTICAL);
    eventLL.setPadding(dpToPixels(5), dpToPixels(2), dpToPixels(5), dpToPixels(5));

    // Get background for this event
    eventLL.setBackgroundResource(getEventBackground(category));

    /* Add title of event to LinearLayout */
    TextView titleTV = new TextView(getActivity());

    // Title of a show should be bolded
    titleTV.setText(title);
    titleTV.setTypeface(null, Typeface.BOLD);
    titleTV.setPadding(dpToPixels(5), 0, dpToPixels(5), 0);
    eventLL.addView(titleTV);

    /* Determine length of event to see if we have room to attach a description (if one was passed) */
    int length = endTime - startTime;

    /* Attach a description with a size that depends on the event length (longer events can hold more description text). */
    if (description != null) {
        TextView descriptionTV = new TextView(getActivity());
        descriptionTV.setPadding(dpToPixels(5), dpToPixels(5), dpToPixels(5), dpToPixels(5));
        descriptionTV.setText(description);

        // ~hour long shows can display 1 line of description
        if (difference >= 30 && difference <= 60) {
            descriptionTV.setMaxLines(1);
        }

        // 1:30 long shows can display 2 lines of description
        else if (difference >= 60 && difference <= 90) {
            descriptionTV.setMaxLines(2);
        }

        // 2:00 long shows can display 4 lines of description
        else if (difference >= 120) {
            descriptionTV.setMaxLines(4);
        }

        descriptionTV.setEllipsize(TextUtils.TruncateAt.END);
        descriptionTV.setPadding(dpToPixels(5), dpToPixels(5), dpToPixels(5), dpToPixels(5));
        eventLL.addView(descriptionTV);
    }

    /* Add this view to the schedule UI */
    RelativeLayout rl = (RelativeLayout) rootView.findViewById(R.id.schedule_container_relativelayout);
    rl.addView(eventLL, rrLayoutParams);
}

From source file:org.odk.collect.android.fragments.dialogs.RankingWidgetDialog.java

private ScrollView setUpRankingLayout(List<String> values, FormIndex formIndex) {
    LinearLayout rankingLayout = new LinearLayout(getContext());
    rankingLayout.setOrientation(LinearLayout.HORIZONTAL);
    rankingLayout.addView(setUpPositionsLayout(values));
    rankingLayout.addView(setUpRecyclerView(values, formIndex));
    rankingLayout.setPadding(10, 0, 10, 0);

    ScrollView scrollView = new ScrollView(getContext());
    scrollView.addView(rankingLayout);// w ww.ja v a  2 s.c  om
    return scrollView;
}

From source file:org.anurag.file.quest.GraphAnalysis.java

/**
 * restyles the system UI like status bar or navigation bar if present....
 *//*  w ww.j  a v  a  2s .co m*/
private void init_system_ui() {
    // TODO Auto-generated method stub
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT)
        return;
    SystemBarTintManager tint = new SystemBarTintManager(GraphAnalysis.this);
    tint.setStatusBarTintEnabled(true);
    tint.setStatusBarTintColor(Constants.COLOR_STYLE);
    SystemBarConfig conf = tint.getConfig();
    boolean hasNavBar = conf.hasNavigtionBar();
    if (hasNavBar) {
        tint.setNavigationBarTintEnabled(true);
        tint.setNavigationBarTintColor(Constants.COLOR_STYLE);
    }
    LinearLayout main = (LinearLayout) findViewById(R.id.main);
    main.setPadding(0, getStatusBarHeight(), 0, hasNavBar ? getNavigationBarHeight() : 0);
    main.setBackgroundColor(Constants.COLOR_STYLE);
}

From source file:com.mishiranu.dashchan.content.service.AudioPlayerActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    context = new ContextThemeWrapper(this, Preferences.getThemeResource());
    setVolumeControlStream(AudioManager.STREAM_MUSIC);
    float density = ResourceUtils.obtainDensity(this);
    LinearLayout linearLayout = new LinearLayout(context);
    linearLayout.setOrientation(LinearLayout.VERTICAL);
    int padding = getResources().getDimensionPixelSize(R.dimen.dialog_padding_view);
    linearLayout.setPadding(padding, padding, padding, C.API_LOLLIPOP ? (int) (8f * density) : padding);
    textView = new TextView(context, null, android.R.attr.textAppearanceListItem);
    linearLayout.addView(textView, LinearLayout.LayoutParams.MATCH_PARENT,
            LinearLayout.LayoutParams.WRAP_CONTENT);
    textView.setPadding(0, 0, 0, 0);// w w w  . j a v a  2 s  .co m
    textView.setEllipsize(TextUtils.TruncateAt.END);
    textView.setSingleLine(true);
    LinearLayout horizontal = new LinearLayout(context);
    horizontal.setOrientation(LinearLayout.HORIZONTAL);
    horizontal.setGravity(Gravity.CENTER_VERTICAL);
    horizontal.setPadding(0, (int) (16f * density), 0, 0);
    linearLayout.addView(horizontal, LinearLayout.LayoutParams.MATCH_PARENT,
            LinearLayout.LayoutParams.WRAP_CONTENT);
    seekBar = new SeekBar(context);
    horizontal.addView(seekBar, new LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.WRAP_CONTENT, 1));
    seekBar.setPadding((int) (8f * density), 0, (int) (16f * density), 0);
    seekBar.setOnSeekBarChangeListener(this);
    button = new ImageButton(context);
    horizontal.addView(button, (int) (48f * density), (int) (48f * density));
    button.setBackgroundResource(
            ResourceUtils.getResourceId(context, android.R.attr.listChoiceBackgroundIndicator, 0));
    setPlayState(false);
    button.setOnClickListener(this);
    alertDialog = new AlertDialog.Builder(context).setView(linearLayout).setOnCancelListener(this)
            .setPositiveButton(R.string.action_stop, this).show();
    IntentFilter intentFilter = new IntentFilter();
    intentFilter.addAction(AudioPlayerService.ACTION_TOGGLE);
    intentFilter.addAction(AudioPlayerService.ACTION_CANCEL);
    LocalBroadcastManager.getInstance(this).registerReceiver(audioPlayerReceiver, intentFilter);
    bindService(new Intent(this, AudioPlayerService.class), this, 0);
}

From source file:com.woodblockwithoutco.quickcontroldock.ui.ControlService.java

public void attachTemporaryView(Drawable icon, String appName) {
    LinearLayout l = new LinearLayout(getApplicationContext());
    l.setGravity(Gravity.CENTER_VERTICAL);
    l.setOrientation(LinearLayout.HORIZONTAL);
    l.setPadding(NOTIFICATION_TOAST_PADDING_PX, NOTIFICATION_TOAST_PADDING_PX, NOTIFICATION_TOAST_PADDING_PX,
            NOTIFICATION_TOAST_PADDING_PX);

    l.setBackgroundResource(R.drawable.notification_toast_bg);

    TextView tv = new TextView(getApplicationContext());
    tv.setGravity(Gravity.CENTER);/*w w  w  .jav a 2 s  .c o m*/
    tv.setCompoundDrawablePadding(COMPOUND_DRAWABLE_PADDING_PX);
    tv.setCompoundDrawablesWithIntrinsicBounds(icon, null, null, null);

    String notificationText = getString(R.string.notification_from) + "\n" + appName;
    tv.setText(notificationText);
    tv.setTextColor(COLOR_WHITE);

    l.addView(tv);

    Toast toast = new Toast(getApplicationContext());
    toast.setView(l);
    toast.show();
}

From source file:com.blueoxfords.peacecorpstinder.activities.MainActivity.java

public void getLegalInfo(View v) {
    String photoId = v.getTag() + "";
    ImageRestClient.get().getInfoFromImageId(photoId, new Callback<ImageService.ImageInfoWrapper>() {
        @Override/*from  www .j  a  va2s. co m*/
        public void success(ImageService.ImageInfoWrapper imageInfoWrapper, Response response) {
            AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.activity);

            ScrollView wrapper = new ScrollView(MainActivity.activity);
            LinearLayout infoLayout = new LinearLayout(MainActivity.activity);
            infoLayout.setOrientation(LinearLayout.VERTICAL);
            infoLayout.setPadding(35, 35, 35, 35);

            TextView imageOwner = new TextView(MainActivity.activity);
            imageOwner.setText(Html.fromHtml("<b>Image By: </b>" + imageInfoWrapper.photo.owner.username));
            if (imageInfoWrapper.photo.owner.realname.length() > 0) {
                imageOwner.setText(imageOwner.getText() + " (" + imageInfoWrapper.photo.owner.realname + ")");
            }
            infoLayout.addView(imageOwner);

            if (getLicenseUrl(Integer.parseInt(imageInfoWrapper.photo.license)).length() > 0) {
                TextView licenseLink = new TextView(MainActivity.activity);
                licenseLink.setText(Html
                        .fromHtml("<a href=\"" + getLicenseUrl(Integer.parseInt(imageInfoWrapper.photo.license))
                                + "\"><b>Licensing</b></a>"));
                licenseLink.setMovementMethod(LinkMovementMethod.getInstance());
                infoLayout.addView(licenseLink);
            }

            if (imageInfoWrapper.photo.urls.url.size() > 0) {
                TextView imageLink = new TextView(MainActivity.activity);
                imageLink.setText(Html.fromHtml("<a href=\"" + imageInfoWrapper.photo.urls.url.get(0)._content
                        + "\"><b>Image Link</b></a>"));
                imageLink.setMovementMethod(LinkMovementMethod.getInstance());
                infoLayout.addView(imageLink);
            }

            if (imageInfoWrapper.photo.title._content.length() > 0) {
                TextView photoTitle = new TextView(MainActivity.activity);
                photoTitle
                        .setText(Html.fromHtml("<b>Image Title: </b>" + imageInfoWrapper.photo.title._content));
                infoLayout.addView(photoTitle);
            }

            if (imageInfoWrapper.photo.description._content.length() > 0) {
                TextView description = new TextView(MainActivity.activity);
                description.setText(Html
                        .fromHtml("<b>Image Description: </b>" + imageInfoWrapper.photo.description._content));
                infoLayout.addView(description);
            }

            TextView contact = new TextView(MainActivity.activity);
            contact.setText(
                    Html.fromHtml("<br><i>To remove this photo, please email pcorpsconnect@gmail.com</i>"));
            infoLayout.addView(contact);

            wrapper.addView(infoLayout);

            builder.setTitle("Photo Information");
            builder.setPositiveButton("Close", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {

                }
            });
            builder.setView(wrapper);
            builder.create().show();
        }

        @Override
        public void failure(RetrofitError error) {
            Log.i("testing", "could not retrieve legal/attribution info");
        }
    });
}