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.njlabs.amrita.aid.landing.Landing.java

public void checkForUpdates() {

    OkHttpClient client = new OkHttpClient.Builder().followRedirects(true).followSslRedirects(true).build();

    Request.Builder request = new Request.Builder().url("https://api.codezero.xyz/aid/latest");

    client.newCall(request.build()).enqueue(new Callback() {
        @Override//from w w w .  j a va 2 s  .c o  m
        public void onFailure(Call call, IOException e) {
            Ln.e(e);
        }

        @Override
        public void onResponse(Call call, final Response rawResponse) throws IOException {
            final String responseString = rawResponse.body().string();
            ((Activity) baseContext).runOnUiThread(new Runnable() {
                @Override
                public void run() {

                    JSONObject response;

                    try {
                        response = new JSONObject(responseString);

                        String status = "";
                        status = response.getString("status");

                        if (status.equals("ok")) {
                            Double Latest = 0.0;
                            String Description = null;
                            try {
                                Latest = response.getDouble("version");
                                Description = response.getString("description");
                            } catch (JSONException e) {
                                FirebaseCrash.report(e);
                            }
                            if (Latest > BuildConfig.VERSION_CODE) {

                                AlertDialog.Builder updateDialogBuilder = new AlertDialog.Builder(Landing.this);

                                LayoutInflater factory = LayoutInflater.from(Landing.this);
                                final View changelogView = factory.inflate(R.layout.webview_dialog, null);
                                LinearLayout WebViewDialogLayout = (LinearLayout) changelogView
                                        .findViewById(R.id.WebViewDialogLayout);
                                WebViewDialogLayout.setPadding(5, 5, 5, 5);
                                WebView changelogWebView = (WebView) changelogView
                                        .findViewById(R.id.LicensesView);
                                changelogWebView.loadData(String.format("%s", Description), "text/html",
                                        "utf-8");
                                changelogWebView.setPadding(5, 5, 5, 5);
                                changelogWebView.setBackgroundColor(0);
                                changelogWebView.setOnLongClickListener(new View.OnLongClickListener() {
                                    @Override
                                    public boolean onLongClick(View v) {
                                        return true;
                                    }
                                });
                                changelogWebView.setLongClickable(false);
                                updateDialogBuilder.setView(changelogView).setCancelable(true)
                                        .setCancelable(false)
                                        .setNegativeButton("Dismiss", new DialogInterface.OnClickListener() {
                                            public void onClick(DialogInterface dialog, int id) {
                                                dialog.cancel();
                                            }
                                        })
                                        .setPositiveButton("Update Now", new DialogInterface.OnClickListener() {
                                            public void onClick(DialogInterface dialog, int id) {
                                                Uri uri = Uri
                                                        .parse("market://details?id=com.njlabs.amrita.aid");
                                                Intent it = new Intent(Intent.ACTION_VIEW, uri);
                                                startActivity(it);
                                            }
                                        });
                                AlertDialog alert = updateDialogBuilder.create();
                                alert.setTitle("Update Available");
                                alert.setIcon(R.mipmap.ic_launcher);
                                alert.show();
                            }
                        }

                    } catch (Exception e) {
                        Ln.e(e);
                    }
                }
            });
        }
    });
}

From source file:de.gebatzens.ggvertretungsplan.fragment.MensaFragment.java

@Override
public void createView(LayoutInflater inflater, ViewGroup view) {
    Display display = ((WindowManager) getActivity().getApplicationContext()
            .getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
    int rotation = display.getRotation();
    Log.d("Screen orientation", String.valueOf(rotation));
    if ((rotation == 3) || (rotation == 1)) {
        screen_orientation_horizotal = true;
    } else {/*from w  ww . j  av  a  2 s.  c om*/
        screen_orientation_horizotal = false;
    }
    final ScrollView sv = new ScrollView(getActivity());
    sv.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));
    sv.setTag("mensa_scroll");
    ((LinearLayout) view.findViewById(R.id.mensa_content)).addView(sv);
    final LinearLayout l = new LinearLayout(getActivity());
    l.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));
    l.setOrientation(LinearLayout.VERTICAL);
    int p = toPixels(6);
    l.setPadding(p, p, p, p);
    sv.addView(l);
    for (Mensa.MensaItem item : GGApp.GG_APP.mensa) {
        if (!item.isPast())
            l.addView(createCardItem(item, inflater));

    }
}

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

/**
 * restyles the system UI like status bar or navigation bar if present....
 *//*from  ww w .j  a  v a2s  .  c  o  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(FileProperties.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.setBackgroundColor(Constants.COLOR_STYLE);
    main.setPadding(0, getStatusBarHeight(), 0, hasNavBar ? getNavigationBarHeight() : 0);
}

From source file:de.gebatzens.sia.fragment.RemoteDataFragment.java

/**
 *
 * @return horizontal screen orientation
 *///  w w w  . ja  v a2s.  com
public boolean createRootLayout(LinearLayout l) {
    l.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));
    l.setOrientation(LinearLayout.VERTICAL);
    if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
        l.setPadding(toPixels(55), toPixels(4), toPixels(55), toPixels(4));
        return true;
    } else if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) {
        l.setPadding(toPixels(4), toPixels(4), toPixels(4), toPixels(4));
    }
    return false;
}

From source file:com.androcast.illusion.illusionmod.MainActivity.java

/**
 * Dialog which asks the user to enter his password
 *
 * @param password current encoded password
 *//*from   ww  w  . ja  v a 2s .co  m*/
private void askPassword(final String password) {
    LinearLayout linearLayout = new LinearLayout(this);
    linearLayout.setOrientation(LinearLayout.VERTICAL);
    linearLayout.setGravity(Gravity.CENTER);
    linearLayout.setPadding(30, 20, 30, 20);

    final AppCompatEditText mPassword = new AppCompatEditText(this);
    mPassword.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
    mPassword.setHint(getString(R.string.password));
    linearLayout.addView(mPassword);

    new AlertDialog.Builder(this).setView(linearLayout).setCancelable(false)
            .setPositiveButton(getString(R.string.ok), new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialogInterface, int i) {
                    if (mPassword.getText().toString().equals(Utils.decodeString(password)))
                        new Task().execute();
                    else {
                        Utils.toast(getString(R.string.password_wrong), MainActivity.this);
                        finish();
                    }
                }
            }).show();
}

From source file:pl.bcichecki.rms.client.android.dialogs.RegisterDialog.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    context = getActivity();//from  w  w w  .  j a v  a2 s  . c om

    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    builder.setTitle(getString(R.string.dialog_register_title));
    builder.setMessage(getString(R.string.dialog_register_message));

    final EditText usernameEditText = new EditText(getActivity());
    usernameEditText.setHint(getString(R.string.dialog_register_enter_username_hint));
    usernameEditText.setMaxLines(1);
    usernameEditText.setSingleLine();
    usernameEditText.setImeOptions(EditorInfo.IME_ACTION_NEXT);
    usernameEditText.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            usernameEditText.setError(null);
        }

    });

    final EditText passwordEditText = new EditText(getActivity());
    passwordEditText.setHint(getString(R.string.dialog_register_enter_password_hint));
    passwordEditText.setMaxLines(1);
    passwordEditText.setSingleLine();
    passwordEditText.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
    passwordEditText.setImeOptions(EditorInfo.IME_ACTION_NEXT);
    passwordEditText.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            passwordEditText.setError(null);
        }

    });

    final EditText emailEditText = new EditText(getActivity());
    emailEditText.setHint(getString(R.string.dialog_register_enter_email_hint));
    emailEditText.setMaxLines(1);
    emailEditText.setSingleLine();
    emailEditText.setImeOptions(EditorInfo.IME_ACTION_DONE);
    emailEditText.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            emailEditText.setError(null);
        }

    });

    final LinearLayout layout = new LinearLayout(getActivity());
    layout.setOrientation(LinearLayout.VERTICAL);
    layout.setGravity(Gravity.CENTER_HORIZONTAL);
    int space = (int) AppUtils.convertDpToPixel(getActivity(), 16);
    layout.setPadding(space, 0, space, 0);

    layout.addView(usernameEditText);
    layout.addView(passwordEditText);
    layout.addView(emailEditText);

    builder.setView(layout);

    builder.setPositiveButton(getString(R.string.dialog_register_ok), new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int whichButton) {
            return;
        }
    });

    builder.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {

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

    final AlertDialog dialog = builder.create();

    dialog.setOnShowListener(new DialogInterface.OnShowListener() {

        @Override
        public void onShow(DialogInterface dialogInterface) {
            utilitiesRestClient = new UtilitiesRestClient(getActivity(),
                    SharedPreferencesWrapper.getServerAddress(), SharedPreferencesWrapper.getServerPort(),
                    SharedPreferencesWrapper.getWebserviceContextPath());

            final Button positiveButton = dialog.getButton(DialogInterface.BUTTON_POSITIVE);
            positiveButton.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    if (!AppUtils.checkInternetConnection(getActivity())) {
                        Log.d(TAG, "There is NO network connected!");
                        return;
                    }

                    usernameEditText.setError(null);
                    passwordEditText.setError(null);
                    emailEditText.setError(null);

                    if (StringUtils.isBlank(usernameEditText.getText().toString())) {
                        usernameEditText.setError(getString(R.string.dialog_register_field_required));
                        return;
                    }
                    if (StringUtils.isBlank(passwordEditText.getText().toString())) {
                        passwordEditText.setError(getString(R.string.dialog_register_field_required));
                        return;
                    }
                    if (StringUtils.isBlank(emailEditText.getText().toString())) {
                        emailEditText.setError(getString(R.string.dialog_register_field_required));
                        return;
                    }
                    if (!AppUtils.validateEmail(emailEditText.getText().toString())) {
                        emailEditText.setError(getString(R.string.dialog_register_email_not_valid));
                        return;
                    }

                    final User user = new User();
                    user.setUsername(usernameEditText.getText().toString());
                    user.setPassword(SecurityUtils.hashSHA512Base64(passwordEditText.getText().toString()));
                    user.setEmail(StringUtils.lowerCase(emailEditText.getText().toString()));
                    user.setAddress(new AddressData());

                    utilitiesRestClient.registerUser(user, new AsyncHttpResponseHandler() {

                        @Override
                        public void onFailure(Throwable error, String content) {
                            Log.d(TAG,
                                    "Registering user failed. [error= " + error + ", content=" + content + "]");
                            AppUtils.showCenteredToast(context, getString(R.string.dialog_register_failed),
                                    Toast.LENGTH_LONG);
                        }

                        @Override
                        public void onFinish() {
                            positiveButton.setEnabled(true);
                        }

                        @Override
                        public void onStart() {
                            Log.d(TAG, "Registering user: " + user.toString());
                            AppUtils.showCenteredToast(context, getString(R.string.dialog_register_in_progress),
                                    Toast.LENGTH_SHORT);
                            positiveButton.setEnabled(false);
                        }

                        @Override
                        public void onSuccess(int statusCode, String content) {
                            Log.d(TAG, "Registered user successfully.");
                            AppUtils.showCenteredToast(context, getString(R.string.dialog_register_successful),
                                    Toast.LENGTH_SHORT);

                            SharedPreferencesWrapper.setUsername(user.getUsername());
                            SharedPreferencesWrapper.setPasswordHash(user.getPassword());
                            SharedPreferencesWrapper.setRememberUser(true);

                            dialog.dismiss();
                        }

                    });

                }
            });

            final Button negativeButton = dialog.getButton(DialogInterface.BUTTON_NEGATIVE);
            negativeButton.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    cancelRequests();
                    dialog.dismiss();
                }
            });

        }
    });

    return dialog;
}

From source file:com.appfirst.activities.details.AFServerDetail.java

/**
 * @return//ww  w .  j a  v a 2s  .com
 */
private LinearLayout createTableRow(int orientation) {
    LinearLayout row = new LinearLayout(this);
    row.setPadding(0, 0, 0, 5);
    row.setOrientation(orientation);
    row.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
    return row;
}

From source file:fr.cph.chicago.core.adapter.NearbyAdapter.java

private View handleBikes(final int position, @NonNull final ViewGroup parent) {
    final LayoutInflater vi = (LayoutInflater) parent.getContext()
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    final View convertView = vi.inflate(R.layout.list_nearby, parent, false);

    final int index = position - (stations.size() + busStops.size());
    final BikeStation bikeStation = bikeStations.get(index);

    final LinearLayout favoritesData = (LinearLayout) convertView.findViewById(R.id.nearby_results);

    final ImageView imageView = (ImageView) convertView.findViewById(R.id.icon);
    imageView.setImageDrawable(//from   w  w  w .  j  a v  a  2 s. c o  m
            ContextCompat.getDrawable(parent.getContext(), R.drawable.ic_directions_bike_white_24dp));

    final TextView routeView = (TextView) convertView.findViewById(R.id.station_name);
    routeView.setText(bikeStation.getName());

    final LinearLayout llh = new LinearLayout(context);
    llh.setOrientation(LinearLayout.HORIZONTAL);
    llh.setPadding(line1PaddingColor, stopsPaddingTop, 0, 0);

    final LinearLayout availableLayout = new LinearLayout(context);
    availableLayout.setOrientation(LinearLayout.VERTICAL);

    final LinearLayout.LayoutParams leftParam = new LinearLayout.LayoutParams(
            ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    final RelativeLayout availableBikes = new RelativeLayout(context);
    availableBikes.setLayoutParams(leftParam);
    availableBikes.setPadding(line1PaddingColor, 0, 0, 0);

    final RelativeLayout lineIndication = LayoutUtil.createColoredRoundForFavorites(context, TrainLine.NA);
    int lineId = Util.generateViewId();
    lineIndication.setId(lineId);

    final RelativeLayout.LayoutParams availableParam = new RelativeLayout.LayoutParams(
            ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    availableParam.addRule(RelativeLayout.RIGHT_OF, lineId);
    availableParam.setMargins(Util.convertDpToPixel(context, 10), 0, 0, 0);

    final TextView availableBike = new TextView(context);
    availableBike.setText(context.getString(R.string.bike_available_bikes));
    availableBike.setTextColor(ContextCompat.getColor(context, R.color.grey_5));
    availableBike.setLayoutParams(availableParam);
    int availableBikeId = Util.generateViewId();
    availableBike.setId(availableBikeId);

    final RelativeLayout.LayoutParams amountParam = new RelativeLayout.LayoutParams(
            ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    amountParam.addRule(RelativeLayout.RIGHT_OF, availableBikeId);

    final TextView amountBike = new TextView(context);
    final String amountBikeText = String.valueOf(bikeStation.getAvailableBikes());
    amountBike.setText(amountBikeText);
    int color = bikeStation.getAvailableBikes() == 0 ? R.color.red : R.color.green;
    amountBike.setTextColor(ContextCompat.getColor(context, color));
    amountBike.setLayoutParams(amountParam);

    availableBikes.addView(lineIndication);
    availableBikes.addView(availableBike);
    availableBikes.addView(amountBike);

    final LinearLayout.LayoutParams leftParam2 = new LinearLayout.LayoutParams(
            ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    final RelativeLayout availableDocks = new RelativeLayout(context);
    availableDocks.setLayoutParams(leftParam2);
    availableDocks.setPadding(line1PaddingColor, 0, 0, 0);

    final RelativeLayout lineIndication2 = LayoutUtil.createColoredRoundForFavorites(context, TrainLine.NA);
    int lineId2 = Util.generateViewId();
    lineIndication2.setId(lineId2);

    final RelativeLayout.LayoutParams availableDockParam = new RelativeLayout.LayoutParams(
            ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    availableDockParam.addRule(RelativeLayout.RIGHT_OF, lineId2);
    availableDockParam.setMargins(Util.convertDpToPixel(context, 10), 0, 0, 0);

    final TextView availableDock = new TextView(context);
    availableDock.setText(context.getString(R.string.bike_available_docks));
    availableDock.setTextColor(ContextCompat.getColor(context, R.color.grey_5));
    availableDock.setLayoutParams(availableDockParam);
    int availableDockBikeId = Util.generateViewId();
    availableDock.setId(availableDockBikeId);

    final RelativeLayout.LayoutParams amountParam2 = new RelativeLayout.LayoutParams(
            ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    amountParam2.addRule(RelativeLayout.RIGHT_OF, availableDockBikeId);

    final TextView amountDock = new TextView(context);
    final String amountDockText = String.valueOf(bikeStation.getAvailableDocks());
    amountDock.setText(amountDockText);
    color = bikeStation.getAvailableDocks() == 0 ? R.color.red : R.color.green;
    amountDock.setTextColor(ContextCompat.getColor(context, color));

    amountDock.setLayoutParams(amountParam2);

    availableDocks.addView(lineIndication2);
    availableDocks.addView(availableDock);
    availableDocks.addView(amountDock);

    availableLayout.addView(availableBikes);
    availableLayout.addView(availableDocks);

    llh.addView(availableLayout);

    favoritesData.addView(llh);

    convertView.setOnClickListener(new NearbyOnClickListener(googleMap, markers, bikeStation.getId(),
            bikeStation.getLatitude(), bikeStation.getLongitude()));
    return convertView;
}

From source file:com.facebook.android.FbDialog.java

private void setUpWebView(int margin) {
    LinearLayout webViewContainer = new LinearLayout(getContext());
    mWebView = new WebView(getContext());
    mWebView.setVerticalScrollBarEnabled(false);
    mWebView.setHorizontalScrollBarEnabled(false);
    mWebView.setWebViewClient(new FbDialog.FbWebViewClient());
    mWebView.getSettings().setJavaScriptEnabled(true);
    mWebView.loadUrl(mUrl);//from   ww w  . j av  a2  s .  co m
    mWebView.setLayoutParams(FILL);
    mWebView.setVisibility(View.INVISIBLE);

    webViewContainer.setPadding(margin, margin, margin, margin);
    webViewContainer.addView(mWebView);
    mContent.addView(webViewContainer);
}

From source file:edu.csh.coursebrowser.SettingsActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_settings);
    this.setTitle("Settings");
    final SharedPreferences sp = SchoolActivity.sp;
    LinearLayout ll = (LinearLayout) this.findViewById(R.id.settings_layout);
    ll.setGravity(Gravity.CENTER);//  w w w  .j a v a2 s .c  o  m
    final TextView tv = new TextView(this);
    if (!sp.contains("quarter")) {
        SharedPreferences.Editor e = sp.edit();
        e.putString("quarter", "20122");
        e.commit();
    }
    tv.setText("Current Quarter: " + sp.getString("quarter", "20122"));
    Button b = new Button(this);
    b.setText("Change Quarter");
    ll.addView(tv);
    ll.addView(b);
    ll.setPadding(10, 10, 10, 10);
    b.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {
            AlertDialog.Builder changeQuarter = new AlertDialog.Builder(SettingsActivity.this);
            changeQuarter.setTitle("Change Quarter");
            changeQuarter.setMessage("Select New Quarter");
            final RadioButton ld = new RadioButton(SettingsActivity.this);
            ld.setText("20121");
            ld.setId(1);
            final RadioButton s = new RadioButton(SettingsActivity.this);
            s.setText("20122 (Current)");
            s.setId(2);
            final RadioButton d = new RadioButton(SettingsActivity.this);
            d.setText("20123");
            d.setId(3);
            final RadioGroup rg = new RadioGroup(SettingsActivity.this);
            rg.addView(ld);
            rg.addView(s);
            rg.addView(d);
            changeQuarter.setView(rg);

            changeQuarter.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    // TODO Auto-generated method stub
                }

            });
            changeQuarter.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {
                    String q;
                    int n = rg.getCheckedRadioButtonId();
                    if (n == 1)
                        q = "20121";
                    else if (n == 2)
                        q = "20122";
                    else
                        q = "20123";
                    SharedPreferences.Editor edit = sp.edit();
                    edit.putString("quarter", q);
                    edit.commit();
                    SettingsActivity.this.finish();
                }
            });

            changeQuarter.show();
        }

    });

}