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:com.grarak.kerneladiutor.utils.ViewUtils.java

public static Dialog dialogEditText(String text, final DialogInterface.OnClickListener negativeListener,
        final OnDialogEditTextListener onDialogEditTextListener, int inputType, Context context) {
    LinearLayout layout = new LinearLayout(context);
    int padding = (int) context.getResources().getDimension(R.dimen.dialog_padding);
    layout.setPadding(padding, padding, padding, padding);

    final AppCompatEditText editText = new AppCompatEditText(context);
    editText.setGravity(Gravity.CENTER);
    editText.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));
    if (text != null) {
        editText.append(text);// www .ja  v a  2 s .  co m
    }
    editText.setSingleLine(true);
    if (inputType >= 0) {
        editText.setInputType(inputType);
    }

    layout.addView(editText);

    Dialog dialog = new Dialog(context).setView(layout);
    if (negativeListener != null) {
        dialog.setNegativeButton(context.getString(R.string.cancel), negativeListener);
    }
    if (onDialogEditTextListener != null) {
        dialog.setPositiveButton(context.getString(R.string.ok), new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                onDialogEditTextListener.onClick(editText.getText().toString());
            }
        }).setOnDismissListener(new DialogInterface.OnDismissListener() {
            @Override
            public void onDismiss(DialogInterface dialog) {
                if (negativeListener != null) {
                    negativeListener.onClick(dialog, 0);
                }
            }
        });
    }
    return dialog;
}

From source file:com.grarak.kerneladiutor.utils.ViewUtils.java

public static Dialog dialogEditTexts(String text, String text2, String hint, String hint2,
        final DialogInterface.OnClickListener negativeListener,
        final onDialogEditTextsListener onDialogEditTextListener, Context context) {
    LinearLayout layout = new LinearLayout(context);
    layout.setOrientation(LinearLayout.VERTICAL);
    int padding = (int) context.getResources().getDimension(R.dimen.dialog_padding);
    layout.setPadding(padding, padding, padding, padding);

    final AppCompatEditText editText = new AppCompatEditText(context);
    editText.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));
    if (text != null) {
        editText.append(text);//from   ww w  .jav a  2s.c o m
    }
    if (hint != null) {
        editText.setHint(hint);
    }
    editText.setSingleLine(true);

    final AppCompatEditText editText2 = new AppCompatEditText(context);
    editText2.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
            LinearLayout.LayoutParams.MATCH_PARENT));
    if (text2 != null) {
        editText2.setText(text2);
    }
    if (hint2 != null) {
        editText2.setHint(hint2);
    }
    editText2.setSingleLine(true);

    layout.addView(editText);
    layout.addView(editText2);

    Dialog dialog = new Dialog(context).setView(layout);
    if (negativeListener != null) {
        dialog.setNegativeButton(context.getString(R.string.cancel), negativeListener);
    }
    if (onDialogEditTextListener != null) {
        dialog.setPositiveButton(context.getString(R.string.ok), new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                onDialogEditTextListener.onClick(editText.getText().toString(), editText2.getText().toString());
            }
        }).setOnDismissListener(new DialogInterface.OnDismissListener() {
            @Override
            public void onDismiss(DialogInterface dialog) {
                if (negativeListener != null) {
                    negativeListener.onClick(dialog, 0);
                }
            }
        });
    }
    return dialog;
}

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  w  ww.jav  a2 s  . 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  .  ja  v a 2  s .c om

    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.actionbarsherlock.sample.demos.app.ActionBarActionItemCustomView.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    MenuItem item = menu.add(0, android.R.id.copy, 0, "Test");

    final int twentyDp = (int) (20 * getResources().getDisplayMetrics().density);

    TypedArray a = getTheme().obtainStyledAttributes(R.styleable.SherlockTheme);
    final int abHeight = a.getLayoutDimension(R.styleable.SherlockTheme_abHeight, LayoutParams.FILL_PARENT);
    a.recycle();//from   w  ww .ja  v  a  2s  .c  om

    LinearLayout l = new LinearLayout(this);
    l.setPadding(twentyDp, 0, twentyDp, 20);
    l.setBackgroundColor(0x55FF0000);

    TextView tv = new TextView(this);
    tv.setText("HI!!");
    tv.setGravity(Gravity.CENTER);
    tv.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, abHeight));
    l.addView(tv);

    l.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Toast.makeText(ActionBarActionItemCustomView.this, "Got custom action item click!",
                    Toast.LENGTH_SHORT).show();
        }
    });

    item.setActionView(l);
    item.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);

    return super.onCreateOptionsMenu(menu);
}

From source file:com.seraphim.chips.ChipsVerticalLinearLayout.java

private LinearLayout createHorizontalView() {
    LinearLayout ll = new LinearLayout(getContext());
    ll.setPadding(0, 0, 0, rowSpacing);
    ll.setOrientation(HORIZONTAL);/* w w  w  . j a v  a  2  s .  c  o m*/
    ll.setDividerDrawable(ContextCompat.getDrawable(getContext(), R.drawable.amc_empty_vertical_divider));
    ll.setShowDividers(SHOW_DIVIDER_MIDDLE);
    addView(ll);
    lineLayouts.add(ll);
    return ll;
}

From source file:com.eggsoftware.flingsolver.gui.DrawSolutionPageAdapter.java

@Override
public Object instantiateItem(View collection, int position) {
    // Create the "Step N of T" TextView
    TextView stepTextView = new TextView(this.context);
    stepTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
    stepTextView.setTextColor(Color.rgb(113, 113, 113));
    stepTextView.setGravity(Gravity.CENTER);
    stepTextView.setText(String.format(this.context.getResources().getString(R.string.step_of), position + 1,
            this.solution.size()));

    // Create the boar with the current step of the solution
    BoardCanvas board = new BoardCanvas(this.context);
    board.setBoardRepresentation(this.solution.get(position).getBoard());
    board.setArrow(this.solution.get(position).getRow(), this.solution.get(position).getCol(),
            this.solution.get(position).getDirection());

    // Add the components to the layout
    LinearLayout layout = new LinearLayout(this.context);
    layout.setOrientation(LinearLayout.VERTICAL);
    layout.setPadding(16, 20, 16, 16);

    RelativeLayout relativeLatout = new RelativeLayout(this.context);
    relativeLatout.setLayoutParams(/*from ww w  .  j  a  v a 2 s . c  o  m*/
            new TableLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, 1f));
    relativeLatout.addView(board);

    layout.addView(relativeLatout);
    layout.addView(stepTextView);
    ((ViewPager) collection).addView(layout, 0);
    return layout;
}

From source file:com.androcast.illusion.illusionmod.fragments.PathReaderFragment.java

private void showDialog(final String file, String value) {
    LinearLayout layout = new LinearLayout(getActivity());
    layout.setPadding(30, 30, 30, 30);

    final EditText editText = new EditText(getActivity());
    editText.setGravity(Gravity.CENTER);
    editText.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));
    if (!Utils.DARKTHEME)
        editText.setTextColor(getResources().getColor(R.color.black));
    editText.setText(value);// w w w .j av  a 2 s.c o m

    layout.addView(editText);

    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    builder.setView(layout)
            .setNegativeButton(getString(R.string.cancel), new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                }
            }).setPositiveButton(getString(R.string.ok), new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    Control.runCommand(editText.getText().toString(), file, Control.CommandType.GENERIC,
                            getActivity());
                    refreshLayout.setRefreshing(true);
                    getHandler().postDelayed(refresh, 500);
                }
            }).show();
}

From source file:drawnzer.anurag.kollosal.KollosalPlayer.java

private void init_system_ui() {
    // TODO Auto-generated method stub
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT)
        return;//  w  ww .j av  a 2  s  . c  o  m

    SystemBarTintManager tinter = new SystemBarTintManager(KollosalPlayer.this);
    SystemBarTintManager.SystemBarConfig conf = tinter.getConfig();
    boolean isNavBar = conf.hasNavigtionBar();
    if (isNavBar) {
        tinter.setNavigationBarTintEnabled(true);
        tinter.setNavigationBarTintColor(currentColor);
    }
    tinter.setStatusBarTintEnabled(true);
    tinter.setStatusBarTintColor(currentColor);
    LinearLayout ls = (LinearLayout) findViewById(R.id.lists_layout);
    LinearLayout frame = (LinearLayout) findViewById(R.id.frame_container);
    frame.setPadding(0, getStatusBarHeight(), 0, isNavBar ? getNavigationBarHeight() : 0);
    ls.setPadding(0, getStatusBarHeight(), 0, isNavBar ? getNavigationBarHeight() : 0);
}

From source file:org.musicmod.android.dialog.SleepTimerDialog.java

@Override
public void onCreate(Bundle icicle) {

    super.onCreate(icicle);

    setContentView(new LinearLayout(this));

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

    action = getIntent().getAction();/*from w  ww.  j a v  a2s  .co  m*/

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

    mRemained = (int) MusicUtils.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);
                            MusicUtils.startSleepTimer(milliseconds, gentle);
                        } else {
                            MusicUtils.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();
    }
}