Example usage for android.widget LinearLayout setLayoutParams

List of usage examples for android.widget LinearLayout setLayoutParams

Introduction

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

Prototype

public void setLayoutParams(ViewGroup.LayoutParams params) 

Source Link

Document

Set the layout parameters associated with this view.

Usage

From source file:org.openmrs.mobile.activities.formdisplay.FormDisplayPageFragment.java

@Override
public void createAndAttachSelectQuestionRadioButton(Question question, LinearLayout sectionLinearLayout) {
    TextView textView = new TextView(getActivity());
    textView.setPadding(20, 0, 0, 0);/*  w w w  . ja  v a2 s.c o m*/
    textView.setText(question.getLabel());

    RadioGroup radioGroup = new RadioGroup(getActivity());

    for (Answer answer : question.getQuestionOptions().getAnswers()) {
        RadioButton radioButton = new RadioButton(getActivity());
        radioButton.setText(answer.getLabel());
        radioGroup.addView(radioButton);
    }

    SelectOneField radioGroupField = new SelectOneField(question.getQuestionOptions().getAnswers(),
            question.getQuestionOptions().getConcept());

    LinearLayout.LayoutParams linearLayoutParams = new LinearLayout.LayoutParams(
            LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);

    sectionLinearLayout.addView(textView);
    sectionLinearLayout.addView(radioGroup);

    sectionLinearLayout.setLayoutParams(linearLayoutParams);

    SelectOneField selectOneField = getSelectOneField(radioGroupField.getConcept());
    if (selectOneField != null) {
        if (selectOneField.getChosenAnswerPosition() != -1) {
            RadioButton radioButton = (RadioButton) radioGroup
                    .getChildAt(selectOneField.getChosenAnswerPosition());
            radioButton.setChecked(true);
        }
        setOnCheckedChangeListener(radioGroup, selectOneField);
    } else {
        setOnCheckedChangeListener(radioGroup, radioGroupField);
        selectOneFields.add(radioGroupField);
    }
}

From source file:com.brq.wallet.activity.modern.AccountsFragment.java

private LinearLayout createAccountViewList(String title, List<WalletAccount> accounts,
        WalletAccount selectedAccount, CurrencySum spendableBalance) {
    LinearLayout outer = new LinearLayout(getActivity());
    outer.setOrientation(LinearLayout.VERTICAL);
    outer.setLayoutParams(_outerLayoutParameters);

    // Add title/*from  ww w.  ja va 2s .  c  o m*/
    createTitle(outer, title, spendableBalance);

    if (accounts.isEmpty()) {
        return outer;
    }

    LinearLayout inner = new LinearLayout(getActivity());
    inner.setOrientation(LinearLayout.VERTICAL);
    inner.setLayoutParams(_innerLayoutParameters);
    inner.requestLayout();

    //      // Add records
    RecordRowBuilder builder = new RecordRowBuilder(_mbwManager, getResources(), _layoutInflater);
    for (WalletAccount account : accounts) {
        // Add separator
        inner.addView(createSeparator());

        // Add item
        boolean isSelected = account.equals(selectedAccount);
        View item = createAccountView(outer, account, isSelected, builder);
        inner.addView(item);
    }

    if (accounts.size() > 0) {
        // Add separator
        inner.addView(createSeparator());
    }

    outer.addView(inner);
    return outer;
}

From source file:se.liu.tddd77.bilsensor.MainActivity.java

@SuppressLint("UseValueOf")
public void addNewDynamicEventString(String name) {
    //TODO: Storlek p denna ruta mste hllas konstant.
    if (name == null || name.isEmpty()) {
        Toast.makeText(this, "Dynamic Events require a name.", Toast.LENGTH_SHORT).show();
        return;//from  w w w  .  j  a  v a2s  .c  om
    }
    //TODO: r this korrekt?

    LinearLayout layout = new LinearLayout(this);
    layout.setOrientation(LinearLayout.HORIZONTAL);

    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
            LinearLayout.LayoutParams.WRAP_CONTENT);//(LinearLayout.LayoutParams)layout.getLayoutParams();
    layout.setLayoutParams(params);

    Button button = new Button(this);
    buttonList.add(button);

    LinearLayout.LayoutParams buttonparams = new LinearLayout.LayoutParams(
            LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.MATCH_PARENT, 1.0f);
    button.setLayoutParams(buttonparams);
    button.setText(name);
    button.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            try {
                Backend.getInstance().sendDynamicMessage((Long) (System.currentTimeMillis() / 1000L),
                        ((Button) v).getText().toString());
            } catch (BackendError e) {
                e.printStackTrace();
            }

        }
    });

    Button rmEventButton = new Button(this);
    LinearLayout.LayoutParams rmButtonparams = new LinearLayout.LayoutParams(
            LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.MATCH_PARENT, 0.0f);
    rmEventButton.setLayoutParams(rmButtonparams);
    rmEventButton.setText("-");
    rmEventButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {

            //TODO: For-loop through trying to find the one with matching name?
            buttonList.remove(((Button) ((LinearLayout) v.getParent()).getChildAt(0)));
            ((LinearLayout) v.getParent().getParent()).removeView((LinearLayout) v.getParent());
        }
    });
    layout.addView(button);
    layout.addView(rmEventButton);
    ((LinearLayout) findViewById(R.id.dynamic_events_buttons_container)).addView(layout);
    //((LinearLayout)((LinearLayout)(view.getParent().getParent())).getChildAt(1)).addView(layout);
    //((LinearLayout) ((LinearLayout)(view.getParent().getParent()))findViewById(R.id.dynamic_events_buttons_container)).addView(button);

    //textfield.setText("");

}

From source file:com.wit.and.dialog.internal.BaseDialog.java

/**
 * <h5><i>protected View onCreateDialogView(LayoutInflater inflater,
 * ViewGroup container, Bundle savedInstanceState)</i></h5>
 * <p>//from w w  w . j a v a2 s. c  o m
 * Create the dialog main view into which will be placed title, body and
 * buttons view.
 * </p>
 *
 * @param inflater           Layout inflater.
 * @param container          Inflated dialog main view.
 * @param savedInstanceState Saved state.
 * @return Inflated dialog view.
 */
protected View onCreateDialogView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    LinearLayout layout = new LinearLayout(inflater.getContext());
    layout.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
            LinearLayout.LayoutParams.WRAP_CONTENT));
    layout.setOrientation(LinearLayout.VERTICAL);
    return layout;
}

From source file:edu.pitt.gis.uniapp.UniApp.java

/**
 * Shows the splash screen over the full Activity
 *//*w  ww  . jav  a2  s  . co  m*/
@SuppressWarnings("deprecation")
protected void showSplashScreen(final int time) {
    final UniApp that = this;

    Runnable runnable = new Runnable() {
        public void run() {
            // Get reference to display
            Display display = getWindowManager().getDefaultDisplay();

            // Create the layout for the dialog
            LinearLayout root = new LinearLayout(that.getActivity());
            root.setMinimumHeight(display.getHeight());
            root.setMinimumWidth(display.getWidth());
            root.setOrientation(LinearLayout.VERTICAL);
            root.setBackgroundColor(that.getIntegerProperty("backgroundColor", Color.BLACK));
            root.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
                    ViewGroup.LayoutParams.FILL_PARENT, 0.0F));
            root.setBackgroundResource(that.splashscreen);

            // Create and show the dialog
            splashDialog = new Dialog(that, android.R.style.Theme_Translucent_NoTitleBar);
            // check to see if the splash screen should be full screen
            if ((getWindow().getAttributes().flags
                    & WindowManager.LayoutParams.FLAG_FULLSCREEN) == WindowManager.LayoutParams.FLAG_FULLSCREEN) {
                splashDialog.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                        WindowManager.LayoutParams.FLAG_FULLSCREEN);
            }
            splashDialog.setContentView(root);
            splashDialog.setCancelable(false);
            splashDialog.show();

            // Set Runnable to remove splash screen just in case
            final Handler handler = new Handler();
            handler.postDelayed(new Runnable() {
                public void run() {
                    removeSplashScreen();
                }
            }, time);
        }
    };
    this.runOnUiThread(runnable);
}

From source file:com.example.drugsformarinemammals.Dose_Information.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.dose_information);

    Bundle parameters = this.getIntent().getExtras();
    if (parameters != null) {
        TextView textViewDrug = (TextView) findViewById(R.id.textView_drug_name);
        textViewDrug.setTypeface(Typeface.SANS_SERIF);
        textViewDrug.setText(parameters.getString("drugName"));
        TextView textViewGroupName = (TextView) findViewById(R.id.textView_group_name);
        textViewGroupName.setTypeface(Typeface.SANS_SERIF);
        textViewGroupName.setText("(" + parameters.getString("groupName") + ")");
        layoutDose = (LinearLayout) findViewById(R.id.layout_dose);

        helper = new Handler_Sqlite(this);
        SQLiteDatabase db = helper.open();
        ArrayList<String> notes_index = new ArrayList<String>();
        ArrayList<String> references = new ArrayList<String>();
        ArrayList<Article_Reference> references_index = new ArrayList<Article_Reference>();
        reference_index = 'a';
        ArrayList<String> families = new ArrayList<String>();
        if (db != null)
            families = helper.read_animals_family(parameters.getString("drugName"),
                    parameters.getString("groupName"));

        for (int l = 0; l < families.size(); l++) {
            //if exists animals family

            TextView textView_family = new TextView(this);
            textView_family.setText(families.get(l));
            textView_family.setTextSize(20);
            textView_family.setTextColor(getResources().getColor(R.color.darkGray));
            textView_family.setTypeface(Typeface.SANS_SERIF, Typeface.DEFAULT_BOLD.getStyle());

            LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
                    LayoutParams.WRAP_CONTENT);
            params.leftMargin = 30;/*  w  ww .j av a  2 s . c om*/
            params.topMargin = 20;
            layoutDose.addView(textView_family, layoutDose.getChildCount(), params);

            //dose information

            LinearLayout layout_dose_information = new LinearLayout(this);
            layout_dose_information.setOrientation(LinearLayout.VERTICAL);
            layout_dose_information
                    .setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
            layout_dose_information.setBackgroundResource(R.drawable.layout_border);

            ArrayList<Dose_Data> dose = new ArrayList<Dose_Data>();
            if (db != null) {
                dose = helper.read_dose_information(parameters.getString("drugName"),
                        parameters.getString("groupName"), families.get(l), "", "");
            }
            TableLayout doseTable = new TableLayout(this);
            doseTable.setStretchAllColumns(true);

            screenWidth = Integer.parseInt(getString(R.string.display));

            TableRow header = new TableRow(this);

            //Amount

            TextView textView_dose_amount = new TextView(this);
            textView_dose_amount.setText("Dose");
            textView_dose_amount.setSingleLine(true);
            textView_dose_amount.setTextColor(getResources().getColor(R.color.darkGray));
            textView_dose_amount.setTextSize(17);
            textView_dose_amount.setTypeface(Typeface.SANS_SERIF, Typeface.DEFAULT_BOLD.getStyle());
            TableRow.LayoutParams paramsAmount = new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT,
                    TableRow.LayoutParams.WRAP_CONTENT);
            paramsAmount.gravity = Gravity.CENTER;
            header.addView(textView_dose_amount, paramsAmount);

            //Posology
            TextView textView_posology = new TextView(this);
            if (screenWidth >= 720)
                textView_posology.setText("Posology");
            else
                textView_posology.setText("Pos");
            textView_posology.setSingleLine(true);
            textView_posology.setTextColor(getResources().getColor(R.color.darkGray));
            textView_posology.setTextSize(17);
            textView_posology.setTypeface(Typeface.SANS_SERIF, Typeface.DEFAULT_BOLD.getStyle());
            TableRow.LayoutParams paramsPosology = new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT,
                    TableRow.LayoutParams.WRAP_CONTENT);
            paramsPosology.gravity = Gravity.CENTER;
            if ((screenWidth < 600 && !isCollapsed(parameters.getString("drugName"),
                    parameters.getString("groupName"), families.get(l), "Posology")) || screenWidth >= 600)
                header.addView(textView_posology, paramsPosology);

            //Route

            TextView textView_route = new TextView(this);
            textView_route.setText("Route");
            textView_route.setSingleLine(true);
            textView_route.setTextColor(getResources().getColor(R.color.darkGray));
            textView_route.setTextSize(17);
            textView_route.setTypeface(Typeface.SANS_SERIF, Typeface.DEFAULT_BOLD.getStyle());
            TableRow.LayoutParams paramsRoute = new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT,
                    TableRow.LayoutParams.WRAP_CONTENT);
            paramsRoute.gravity = Gravity.CENTER;
            header.addView(textView_route, paramsRoute);

            //Reference

            TextView textView_reference = new TextView(this);
            textView_reference.setText("Ref");
            textView_reference.setSingleLine(true);
            textView_reference.setTextColor(getResources().getColor(R.color.darkGray));
            textView_reference.setTextSize(17);
            textView_reference.setTypeface(Typeface.SANS_SERIF, Typeface.DEFAULT_BOLD.getStyle());
            TableRow.LayoutParams paramsReference = new TableRow.LayoutParams(
                    TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT);
            paramsReference.gravity = Gravity.CENTER;
            header.addView(textView_reference, paramsReference);

            //Specific Note

            TextView textView_specific_note = new TextView(this);
            textView_specific_note.setText("Note");
            textView_specific_note.setSingleLine(true);
            textView_specific_note.setTextColor(getResources().getColor(R.color.darkGray));
            textView_specific_note.setTextSize(17);
            textView_specific_note.setTypeface(Typeface.SANS_SERIF, Typeface.DEFAULT_BOLD.getStyle());
            TableRow.LayoutParams paramsSpecificNote = new TableRow.LayoutParams(
                    TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT);
            paramsSpecificNote.gravity = Gravity.CENTER;
            if ((screenWidth < 600 && !isCollapsed(parameters.getString("drugName"),
                    parameters.getString("groupName"), families.get(l), "Note")) || screenWidth >= 600)
                header.addView(textView_specific_note, paramsSpecificNote);

            TableRow doseData = new TableRow(this);
            doseTable.addView(header);

            //General Dose

            if (dose.size() > 0) {
                show_dose(dose, doseTable, doseData, parameters.getString("drugName"),
                        parameters.getString("groupName"), families.get(l), "", "", notes_index, references,
                        references_index);
            }

            HashMap<String, ArrayList<String>> animal_information = new HashMap<String, ArrayList<String>>();
            if (db != null)
                animal_information = helper.read_animal_information(parameters.getString("drugName"),
                        parameters.getString("groupName"), families.get(l));

            String animalName;
            Object[] animalsName = animal_information.keySet().toArray();
            for (int i = 0; i < animalsName.length; i++) {
                doseData = new TableRow(this);

                //if exists animal name
                animalName = (String) animalsName[i];
                TextView textView_animal_name = new TextView(this);
                if (!animalName.equals("")) {

                    //Animal name

                    textView_animal_name.setText(animalName);
                    textView_animal_name.setSingleLine(false);
                    textView_animal_name.setTextColor(getResources().getColor(R.color.darkGray));
                    textView_animal_name.setTextSize(15);
                    textView_animal_name.setTypeface(Typeface.SANS_SERIF, Typeface.DEFAULT_BOLD.getStyle());
                }

                //if exists category
                ArrayList<String> categories = animal_information.get(animalName);
                String animalCategory;
                for (int j = 0; j < categories.size(); j++) {

                    animalCategory = categories.get(j);

                    if (!animalCategory.equals("")) {

                        //Animal category

                        TextView textView_animal_category = new TextView(this);
                        textView_animal_category.setText(animalCategory);
                        textView_animal_category.setSingleLine(false);
                        textView_animal_category.setTextColor(Color.BLACK);
                        textView_animal_category.setTextSize(15);
                        textView_animal_category.setTypeface(Typeface.SANS_SERIF);
                        if (!animalName.equals("")) {
                            if (j == 0) {
                                TableRow.LayoutParams paramsAnimalName = new TableRow.LayoutParams(
                                        TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT);
                                if (screenWidth < 600
                                        && isCollapsed(parameters.getString("drugName"),
                                                parameters.getString("groupName"), families.get(l), "Posology")
                                        && isCollapsed(parameters.getString("drugName"),
                                                parameters.getString("groupName"), families.get(l), "Note"))
                                    paramsAnimalName.span = 3;
                                else if (screenWidth < 600 && (isCollapsed(parameters.getString("drugName"),
                                        parameters.getString("groupName"), families.get(l), "Posology")
                                        || isCollapsed(parameters.getString("drugName"),
                                                parameters.getString("groupName"), families.get(l), "Note")))
                                    paramsAnimalName.span = 4;
                                else
                                    paramsAnimalName.span = 5;

                                doseData.addView(textView_animal_name, paramsAnimalName);
                                doseTable.addView(doseData);
                            }

                            if (db != null)
                                dose = helper.read_dose_information(parameters.getString("drugName"),
                                        parameters.getString("groupName"), families.get(l), animalName,
                                        animalCategory);

                            doseData = new TableRow(this);
                            textView_animal_category.setTypeface(Typeface.SANS_SERIF, Typeface.ITALIC);
                            TableRow.LayoutParams paramsCategoryName = new TableRow.LayoutParams(
                                    TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT);
                            if (screenWidth < 600
                                    && isCollapsed(parameters.getString("drugName"),
                                            parameters.getString("groupName"), families.get(l), "Posology")
                                    && isCollapsed(parameters.getString("drugName"),
                                            parameters.getString("groupName"), families.get(l), "Note"))
                                paramsCategoryName.span = 3;
                            else if (screenWidth < 600 && (isCollapsed(parameters.getString("drugName"),
                                    parameters.getString("groupName"), families.get(l), "Posology")
                                    || isCollapsed(parameters.getString("drugName"),
                                            parameters.getString("groupName"), families.get(l), "Note")))
                                paramsCategoryName.span = 4;
                            else
                                paramsCategoryName.span = 5;
                            if (screenWidth < 600)
                                paramsCategoryName.leftMargin = 15;
                            else if (screenWidth >= 600 && screenWidth < 720)
                                paramsCategoryName.leftMargin = 20;
                            else
                                paramsCategoryName.leftMargin = 30;
                            doseData.addView(textView_animal_category, paramsCategoryName);
                            doseTable.addView(doseData);
                            doseData = new TableRow(this);
                            show_dose(dose, doseTable, doseData, parameters.getString("drugName"),
                                    parameters.getString("groupName"), families.get(l), animalName,
                                    animalCategory, notes_index, references, references_index);

                            doseData = new TableRow(this);
                        } else {
                            if (db != null)
                                dose = helper.read_dose_information(parameters.getString("drugName"),
                                        parameters.getString("groupName"), families.get(l), animalName,
                                        animalCategory);

                            textView_animal_category.setTypeface(Typeface.SANS_SERIF,
                                    Typeface.DEFAULT_BOLD.getStyle());
                            textView_animal_category.setTextColor(getResources().getColor(R.color.darkGray));
                            TableRow.LayoutParams paramsCategoryName = new TableRow.LayoutParams(
                                    TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT);
                            if (screenWidth < 600
                                    && isCollapsed(parameters.getString("drugName"),
                                            parameters.getString("groupName"), families.get(l), "Posology")
                                    && isCollapsed(parameters.getString("drugName"),
                                            parameters.getString("groupName"), families.get(l), "Note"))
                                paramsCategoryName.span = 3;
                            else if (screenWidth < 600 && (isCollapsed(parameters.getString("drugName"),
                                    parameters.getString("groupName"), families.get(l), "Posology")
                                    || isCollapsed(parameters.getString("drugName"),
                                            parameters.getString("groupName"), families.get(l), "Note")))
                                paramsCategoryName.span = 4;
                            else
                                paramsCategoryName.span = 5;
                            doseData.addView(textView_animal_category, paramsCategoryName);
                            doseTable.addView(doseData);
                            doseData = new TableRow(this);
                            show_dose(dose, doseTable, doseData, parameters.getString("drugName"),
                                    parameters.getString("groupName"), families.get(l), animalName,
                                    animalCategory, notes_index, references, references_index);

                            doseData = new TableRow(this);
                        }

                    }

                    if (!animalName.equals("") && animalCategory.equals("")) {
                        if (db != null)
                            dose = helper.read_dose_information(parameters.getString("drugName"),
                                    parameters.getString("groupName"), families.get(l), animalName,
                                    animalCategory);

                        TableRow.LayoutParams paramsAnimalName = new TableRow.LayoutParams(
                                TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT);
                        if (screenWidth < 600
                                && isCollapsed(parameters.getString("drugName"),
                                        parameters.getString("groupName"), families.get(l), "Posology")
                                && isCollapsed(parameters.getString("drugName"),
                                        parameters.getString("groupName"), families.get(l), "Note"))
                            paramsAnimalName.span = 3;
                        else if (screenWidth < 600 && (isCollapsed(parameters.getString("drugName"),
                                parameters.getString("groupName"), families.get(l), "Posology")
                                || isCollapsed(parameters.getString("drugName"),
                                        parameters.getString("groupName"), families.get(l), "Note")))
                            paramsAnimalName.span = 4;
                        else
                            paramsAnimalName.span = 5;
                        doseData.addView(textView_animal_name, paramsAnimalName);
                        doseTable.addView(doseData);
                        doseData = new TableRow(this);
                        show_dose(dose, doseTable, doseData, parameters.getString("drugName"),
                                parameters.getString("groupName"), families.get(l), animalName, animalCategory,
                                notes_index, references, references_index);

                        doseData = new TableRow(this);
                    }
                }

            }

            LinearLayout.LayoutParams paramsDoseTable = new LinearLayout.LayoutParams(
                    LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
            if (screenWidth >= 600) {
                paramsDoseTable.topMargin = 5;
                paramsDoseTable.leftMargin = 50;
                paramsDoseTable.rightMargin = 50;
            } else {
                paramsDoseTable.topMargin = 5;
                paramsDoseTable.leftMargin = 60;
                paramsDoseTable.rightMargin = 30;
            }
            layout_dose_information.addView(doseTable, paramsDoseTable);

            layoutDose.addView(layout_dose_information, layoutDose.getChildCount());
        }
        helper.close();

        //Notes
        additionalInformationInterface("GENERAL NOTES", parameters.getString("drugName"),
                parameters.getString("groupName"), notes_index, references_index);
        additionalInformationInterface("SPECIFIC NOTES", parameters.getString("drugName"),
                parameters.getString("groupName"), notes_index, references_index);
        //References
        additionalInformationInterface("REFERENCES", parameters.getString("drugName"),
                parameters.getString("groupName"), notes_index, references_index);

    }

}

From source file:mobisocial.musubi.ui.fragments.AccountLinkDialog.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    LinearLayout window = new LinearLayout(mActivity);
    window.setLayoutParams(CommonLayouts.FULL_SCREEN);
    window.setOrientation(LinearLayout.VERTICAL);

    LinearLayout socialBox = new LinearLayout(mActivity);
    socialBox.setLayoutParams(CommonLayouts.FULL_WIDTH);
    socialBox.setOrientation(LinearLayout.HORIZONTAL);
    socialBox.setWeightSum(1.0f * DISPLAYED_SERVICES);

    /** Google **/
    ImageButton google = new ImageButton(mActivity);
    google.setImageResource(R.drawable.google);
    google.setOnClickListener(mGoogleClickListener);
    google.setLayoutParams(//  w w w .j a  v a  2s . c  o  m
            new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT, 1.0f));
    google.setAdjustViewBounds(true);
    socialBox.addView(google);

    /** Facebook **/
    ImageButton facebook = new ImageButton(mActivity);
    facebook.setImageResource(R.drawable.facebook);
    facebook.setOnClickListener(mFacebookClickListener);
    facebook.setLayoutParams(
            new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT, 1.0f));
    facebook.setAdjustViewBounds(true);
    socialBox.addView(facebook);

    /** Phone Number **/
    ImageButton phone = new ImageButton(mActivity);
    phone.setImageResource(R.drawable.phone);
    phone.setOnClickListener(mPhoneClickListener);
    phone.setLayoutParams(
            new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT, 1.0f));
    phone.setAdjustViewBounds(true);
    //socialBox.addView(phone);

    /** List of known accounts **/
    TextView chooseService = new TextView(mActivity);
    chooseService.setText("Choose a service to connect.");
    chooseService.setVisibility(View.GONE);
    chooseService.setLayoutParams(CommonLayouts.FULL_SCREEN);
    chooseService.setTextSize(20);
    mAccountAdapter = new AccountAdapter(getActivity());
    mAccountList = new ListView(getActivity());
    mAccountList.setAdapter(mAccountAdapter);
    mAccountList.setPadding(6, 10, 6, 0);
    mAccountList.setLayoutParams(CommonLayouts.FULL_SCREEN);
    mAccountList.setEmptyView(chooseService);

    /** Put it together **/
    window.addView(socialBox);
    window.addView(mAccountList);
    window.addView(chooseService);

    initialize();

    return window;
}

From source file:com.cloverstudio.spika.CameraCropActivity.java

public void scaleView() {
    // instantiate the views
    View top_view = findViewById(R.id.topView);
    View bottom_view = findViewById(R.id.bottomView);
    LinearLayout footer = (LinearLayout) findViewById(R.id.llFooter);
    LinearLayout crop_frame = (LinearLayout) findViewById(R.id.llCropFrame);
    Display display = getWindowManager().getDefaultDisplay();
    int width = display.getWidth();
    int height = display.getHeight();

    // 90% of width
    crop_container_size = (int) ((float) width * (1f - (10f / 100f)));

    // 10% margins
    float margin = ((float) width * (1f - (90f / 100f)));

    // Parameters for white crop border
    LinearLayout.LayoutParams par = new LinearLayout.LayoutParams(crop_container_size, crop_container_size);
    par.gravity = Gravity.CENTER_HORIZONTAL | Gravity.CENTER_VERTICAL;
    par.setMargins((int) (margin / 2f), 0, (int) (margin / 2f), 0);
    crop_frame.setLayoutParams(par);

    // Margins for other transparent views
    float top_view_height = ((float) (height - crop_container_size - footer.getHeight())) / (float) 2;
    top_view.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, (int) top_view_height));
    bottom_view/*from   w  w w  . j  a  v  a 2s. c  o m*/
            .setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, (int) top_view_height));

    // Image container
    RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(crop_container_size,
            crop_container_size);
    params.setMargins((int) (margin / 2f), (int) top_view_height, (int) (margin / 2f), 0);
    mImageView.setLayoutParams(params);
    mImageView.setImageBitmap(mBitmap);
    mImageView.setMaxZoom(4f);
}

From source file:com.adarshahd.indianrailinfo.donate.PNRStat.java

private void combineTrainAndPsnDetails() {
    if (mPageResult.contains("FLUSHED PNR / ") || mPageResult.contains("Invalid PNR")) {
        mTextViewPNRSts.setText("The PNR entered is either invalid or expired! Please check.");
        mFrameLayout.removeAllViews();/*w  w w .j  a  va 2s.c  o  m*/
        mFrameLayout.addView(mTextViewPNRSts);
        return;
    }
    if (mPageResult.contains("Connectivity Failure") || mPageResult.contains("try again")) {
        mTextViewPNRSts.setText("Looks like server is busy or currently unavailable. Please try again later!");
        mFrameLayout.removeAllViews();
        mFrameLayout.addView(mTextViewPNRSts);
        return;
    }
    //Combine both Train & Passenger details table into a single LinearLayout and add it to FrameLayout
    LinearLayout ll = new LinearLayout(mActivity);
    TextView textViewTrnDtls = new TextView(mActivity);
    TextView textViewPsnDtls = new TextView(mActivity);

    textViewTrnDtls.setText("Train Details: " + mPNRNumber);
    textViewTrnDtls.setFocusable(true);
    textViewPsnDtls.setText("Passenger Details");
    textViewTrnDtls.setTextAppearance(mActivity, android.R.style.TextAppearance_DeviceDefault_Large);
    textViewPsnDtls.setTextAppearance(mActivity, android.R.style.TextAppearance_DeviceDefault_Large);
    textViewTrnDtls.setPadding(10, 10, 10, 10);
    textViewPsnDtls.setPadding(10, 10, 10, 10);
    textViewTrnDtls.setGravity(Gravity.CENTER_HORIZONTAL | Gravity.CENTER_VERTICAL);
    textViewPsnDtls.setGravity(Gravity.CENTER_HORIZONTAL | Gravity.CENTER_VERTICAL);
    ll.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));
    ll.setOrientation(LinearLayout.VERTICAL);
    ll.addView(textViewTrnDtls);
    ll.addView(mTableLayoutTrn);
    ll.addView(textViewPsnDtls);
    ll.addView(mTableLayoutPsn);
    mFrameLayout.removeAllViews();
    mFrameLayout.addView(ll);
    if (isWaitingList && !mPNRList.contains(mPNRNumber)) {
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setTitle("Track this PNR?");
        builder.setMessage("Would you like this PNR to be tracked for status change?");
        builder.setPositiveButton("Track", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                //save the pnr
                pnrDB.addPNRToTrack(mPNRNumber);
                dialog.dismiss();
            }
        });
        builder.setNegativeButton("No thanks", null);
        builder.create().show();
    }

}

From source file:edu.ptu.navpattern.tooltip.Tooltip.java

private View getContentView(final Builder builder) {
    GradientDrawable drawable = new GradientDrawable();
    drawable.setColor(builder.mBackgroundColor);
    drawable.setCornerRadius(builder.mCornerRadius);
    LinearLayout vgContent = new LinearLayout(builder.mContext);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        vgContent.setBackground(drawable);
    } else {/* w  w w  . j  a  v  a 2  s. c o m*/
        //noinspection deprecation
        vgContent.setBackgroundDrawable(drawable);
    }
    int padding = (int) builder.mPadding;
    vgContent.setPadding(padding, padding, padding, padding);
    vgContent.setOrientation(LinearLayout.VERTICAL);
    LinearLayout.LayoutParams textViewParams = new LinearLayout.LayoutParams(
            ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT, 0);
    textViewParams.gravity = Gravity.CENTER;
    textViewParams.topMargin = 1;
    vgContent.setLayoutParams(textViewParams);
    vgContent.setDividerDrawable(vgContent.getResources().getDrawable(R.drawable.divider_line));
    vgContent.setShowDividers(LinearLayout.SHOW_DIVIDER_MIDDLE);

    if (builder.itemText != null && builder.itemText.length > 0) {
        for (int i = 0; i < builder.itemText.length; i++) {

            TextView textView = new TextView(builder.mContext);
            textView.setText(builder.itemText[i]);
            textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 44);
            textView.setTextColor(0xffffffff);
            textView.setGravity(Gravity.CENTER_VERTICAL);
            if (builder.itemLogo != null && builder.itemLogo.length > i) {
                Drawable drawableLeft = builder.mContext.getResources().getDrawable(builder.itemLogo[i]);
                /// ??,??.
                //                    drawableLeft.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());
                //                    textView.setCompoundDrawables(drawableLeft, null, null, null);
                //                    textView.setCompoundDrawablePadding(4);
                //                    textView.setBackgroundDrawable(drawableLeft);
                LinearLayout linearLayout = new LinearLayout(builder.mContext);
                linearLayout.setMinimumHeight((int) dpToPx(44f));
                linearLayout.setOrientation(LinearLayout.HORIZONTAL);
                linearLayout.setGravity(Gravity.CENTER_VERTICAL);
                ImageView icon = new ImageView(builder.mContext);
                icon.setImageDrawable(drawableLeft);
                linearLayout.addView(icon);
                linearLayout.addView(textView);
                vgContent.addView(linearLayout);
                final int position = i;
                linearLayout.setClickable(false);
                linearLayout.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        if (builder.mOnItemClickListener != null) {
                            builder.mOnItemClickListener.onClick(position);
                        }
                        mTouchListener.onTouch(v,
                                MotionEvent.obtain(SystemClock.uptimeMillis(), SystemClock.uptimeMillis(),
                                        MotionEvent.ACTION_UP, v.getLeft() + 5, v.getTop() + 5, 0));
                    }
                });
            } else {
                vgContent.addView(textView);
                final int position = i;
                textView.setClickable(false);
                textView.setMinimumHeight((int) dpToPx(44f));
                textView.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        if (builder.mOnItemClickListener != null) {
                            builder.mOnItemClickListener.onClick(position);
                        }
                        mTouchListener.onTouch(v, null);
                    }
                });
            }
        }

    }

    mArrowView = new ImageView(builder.mContext);
    mArrowView.setImageDrawable(builder.mArrowDrawable);

    LinearLayout.LayoutParams arrowLayoutParams;
    if (mGravity == Gravity.TOP || mGravity == Gravity.BOTTOM) {
        arrowLayoutParams = new LinearLayout.LayoutParams((int) builder.mArrowWidth, (int) builder.mArrowHeight,
                0);
    } else {
        arrowLayoutParams = new LinearLayout.LayoutParams((int) builder.mArrowHeight, (int) builder.mArrowWidth,
                0);
    }
    arrowLayoutParams.gravity = Gravity.CENTER;
    mArrowView.setLayoutParams(arrowLayoutParams);

    mContentView = new LinearLayout(builder.mContext);
    mContentView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT));
    mContentView.setOrientation(mGravity == Gravity.START || mGravity == Gravity.END ? LinearLayout.HORIZONTAL
            : LinearLayout.VERTICAL);

    padding = (int) dpToPx(5);

    switch (mGravity) {
    case Gravity.START:
        mContentView.setPadding(0, 0, padding, 0);
        break;
    case Gravity.TOP:
    case Gravity.BOTTOM:
        mContentView.setPadding(padding, 0, padding, 0);
        break;
    case Gravity.END:
        mContentView.setPadding(padding, 0, 0, 0);
        break;
    }

    if (mGravity == Gravity.TOP || mGravity == Gravity.START) {
        mContentView.addView(vgContent);
        mContentView.addView(mArrowView);
    } else {
        mContentView.addView(mArrowView);
        mContentView.addView(vgContent);
    }

    if (builder.isCancelable || builder.isDismissOnClick) {
        mContentView.setOnTouchListener(mTouchListener);
    }
    return mContentView;
}