Example usage for android.widget LinearLayout addView

List of usage examples for android.widget LinearLayout addView

Introduction

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

Prototype

public void addView(View child) 

Source Link

Document

Adds a child view.

Usage

From source file:com.example.volunteerhandbook.MainActivity.java

void loopNewBox(LinearLayout iBox) {
    if (lastone <= 1) {
        show_what_I_thought();/*  w w  w  .ja  va 2  s .  c o m*/
        return;
    }
    if (iTh > 3 * thoughts.length + 2) {
        lastone--;
        return;
    }
    float bH = (int) (1.2 * iBox.getHeight());
    iBox.removeAllViews();
    for (int i = 0; i < thoughts.length / 4; i++) {
        iBox.addView(toMove[iTh++ % thoughts.length]);
    }
    //toMove.setTranslationY(600);
    //container.addView(textBox);
    iBox.setX(20);
    iBox.setY(2 * bH);
    //hBox += iBox.getHeight();
    float startY = iBox.getY();
    endY = (-1) * bH;
    int duration = 20000;
    ValueAnimator bounceAnim = ObjectAnimator.ofFloat(iBox, "y", startY, endY);
    bounceAnim.setDuration(duration);
    bounceAnim.setInterpolator(new LinearInterpolator());
    final LinearLayout fBox = iBox;
    bounceAnim.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            loopNewBox(fBox);
        }
    });
    bounceAnim.start();
}

From source file:com.google.android.gcm.demo.ui.GroupsFragment.java

@Override
public void refresh() {
    float density = getActivity().getResources().getDisplayMetrics().density;
    SimpleArrayMap<String, Sender> senders = mSenders.getSenders();
    LinearLayout sendersList = new LinearLayout(getActivity());
    sendersList.setOrientation(LinearLayout.VERTICAL);
    for (int i = 0; i < senders.size(); i++) {
        Sender sender = senders.valueAt(i);
        if (sender.groups.size() > 0) {
            LinearLayout senderRow = (LinearLayout) getActivity().getLayoutInflater()
                    .inflate(R.layout.widget_icon_text_button_row, sendersList, false);
            ImageView senderIcon = (ImageView) senderRow.findViewById(R.id.widget_itbr_icon);
            TextView senderText = (TextView) senderRow.findViewById(R.id.widget_itbr_text);
            senderRow.findViewById(R.id.widget_itbr_button).setVisibility(View.GONE);
            senderIcon.setImageResource(R.drawable.cloud_googblue);
            senderIcon.setPadding(0, 0, (int) (8 * density), 0);
            senderText.setText(getString(R.string.groups_sender_id, sender.senderId));
            sendersList.addView(senderRow);
            for (DeviceGroup deviceGroup : sender.groups.values()) {
                LinearLayout row = (LinearLayout) getActivity().getLayoutInflater()
                        .inflate(R.layout.widget_icon_text_button_row, sendersList, false);
                ImageView icon = (ImageView) row.findViewById(R.id.widget_itbr_icon);
                TextView label = (TextView) row.findViewById(R.id.widget_itbr_text);
                Button button = (Button) row.findViewById(R.id.widget_itbr_button);
                icon.setImageResource(R.drawable.group_grey600);
                label.setText(deviceGroup.notificationKeyName);
                label.setBackgroundResource(selectableBackgroundResource);
                label.setTag(R.id.tag_action, ACTION_OPEN_GROUP);
                label.setTag(R.id.tag_senderid, sender.senderId);
                label.setTag(R.id.tag_group, deviceGroup.notificationKeyName);
                label.setOnClickListener(this);

                button.setText(R.string.groups_delete);
                button.setTag(R.id.tag_action, ACTION_DELETE_GROUP);
                button.setTag(R.id.tag_senderid, sender.senderId);
                button.setTag(R.id.tag_group, deviceGroup.notificationKeyName);
                button.setOnClickListener(this);
                row.setPadding((int) (16 * density), 0, 0, 0);
                sendersList.addView(row);
            }//from ww  w . j  a va  2s.co m
        }
    }
    if (sendersList.getChildCount() == 0) {
        TextView noTokens = new TextView(getActivity());
        noTokens.setText(getString(R.string.groups_no_groups_available));
        noTokens.setTypeface(null, Typeface.ITALIC);
        sendersList.addView(noTokens);
    }
    FrameLayout topicsView = (FrameLayout) getActivity().findViewById(R.id.groups_list_wrapper);
    topicsView.removeAllViews();
    topicsView.addView(sendersList);
}

From source file:com.rsltc.profiledata.main.MainActivity.java

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

    Button loginButton = (Button) findViewById(R.id.button);
    loginButton.setOnClickListener(new View.OnClickListener() {
        @Override/*  w  w  w  .  j  a  va2 s .  c  o  m*/
        public void onClick(View v) {
            try {
                AlertDialog.Builder alert = new AlertDialog.Builder(thisActivity);
                alert.setTitle("Title here");

                StringBuilder query = new StringBuilder();

                query.append("redirect_uri=" + URLEncoder.encode(redirectUri, "utf-8"));
                query.append("&client_id=" + URLEncoder.encode(clientId, "utf-8"));
                query.append("&scope=" + URLEncoder.encode(scopes, "utf-8"));

                query.append("&response_type=code");
                URI uri = new URI("https://login.live.com/oauth20_authorize.srf?" + query.toString());

                URL url = uri.toURL();

                final WebView wv = new WebView(thisActivity);

                WebSettings webSettings = wv.getSettings();
                webSettings.setJavaScriptEnabled(true);
                wv.loadUrl(url.toString());
                wv.setWebViewClient(new WebViewClient() {
                    @Override
                    public boolean shouldOverrideUrlLoading(WebView view, String location) {
                        Log.e(TAG, location);
                        // TODO: extract to method
                        try {
                            URL url = new URL(location);

                            if (url.getPath().equalsIgnoreCase("/oauth20_desktop.srf")) {
                                System.out.println("Dit werkt al!");
                                System.out.println(url.getQuery());
                                Map<String, List<String>> result = splitQuery(url);
                                if (result.containsKey("code")) {
                                    System.out.println("bevat code");
                                    if (result.containsKey("error")) {
                                        System.out.println(String.format("{0}\r\n{1}", result.get("error"),
                                                result.get("errorDesc")));
                                    }
                                    System.out.println(result.get("code").get(0));
                                    String tokenError = GetToken(result.get("code").get(0), false);
                                    if (tokenError == null || "".equals(tokenError)) {
                                        System.out.println("Successful sign-in!");
                                        Log.e(TAG, "Successful sign-in!");
                                    } else {
                                        Log.e(TAG, "tokenError: " + tokenError);
                                    }
                                } else {
                                    System.out.println("Successful sign-out!");
                                }
                            }
                        } catch (IOException | URISyntaxException e) {
                            e.printStackTrace();
                        }

                        view.loadUrl(location);

                        return true;
                    }
                });
                LinearLayout linearLayout = new LinearLayout(thisActivity);
                linearLayout.setMinimumHeight(500);
                ArrayList<View> views = new ArrayList<View>();
                views.add(wv);
                linearLayout.addView(wv);
                EditText text = new EditText(thisActivity);
                text.setVisibility(View.GONE);
                linearLayout.addView(text);
                alert.setView(linearLayout);
                alert.setNegativeButton("Close", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int id) {
                        dialog.dismiss();
                    }
                });
                alert.show();
            } catch (Exception e) {
                Log.e(TAG, "dd");
            }
        }
    });
    Button showProfile = (Button) findViewById(R.id.button2);
    showProfile.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            showProfile();
        }
    });
    Button showSummmary = (Button) findViewById(R.id.button3);
    showSummmary.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            showSummaries();
        }
    });

    if (savedInstanceState != null)

    {
        authInProgress = savedInstanceState.getBoolean(AUTH_PENDING);
    }

    buildFitnessClient();
}

From source file:com.activiti.android.app.fragments.settings.GeneralSettingsFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    setRootView(inflater.inflate(R.layout.fr_settings, container, false));

    // TITLE/*from w  w w  .  jav a 2  s .  c om*/
    getToolbar().setTitle(R.string.settings);
    getToolbar().setSubtitle(null);

    // ADD Accounts
    List<ActivitiAccount> accounts = ActivitiAccountManager.retrieveAccounts(getActivity());
    View accountView;
    LinearLayout accountContainer = (LinearLayout) viewById(R.id.settings_accounts_container);
    TwoLinesViewHolder vh;
    for (ActivitiAccount account : accounts) {
        accountView = inflater.inflate(R.layout.row_two_lines_borderless, accountContainer, false);
        accountView.setTag(account.getId());
        HolderUtils.configure(accountView, account.getUsername(), account.getLabel(),
                R.drawable.ic_account_circle_grey);
        accountView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                AccountSettingsFragment.with(getActivity()).accountId((Long) v.getTag())
                        .back(DisplayUtils.hasCentralPane(getActivity())).display();
            }
        });
        accountContainer.addView(accountView);
    }

    // PLay Store
    vh = HolderUtils.configure(viewById(R.id.settings_google_play),
            getString(R.string.settings_google_play_title), getString(R.string.settings_google_play_summary),
            -1);
    viewById(R.id.settings_google_play).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            startPlayStore();
        }
    });

    // Version Number
    String versionNumber;
    try {
        StringBuilder sb = new StringBuilder().append(
                getActivity().getPackageManager().getPackageInfo(getActivity().getPackageName(), 0).versionName)
                .append(".").append(getText(R.string.bamboo_buildnumber));
        versionNumber = sb.toString();
    } catch (PackageManager.NameNotFoundException e) {
        versionNumber = "X.x.x.x";
    }
    HolderUtils.configure(viewById(R.id.settings_version), getString(R.string.settings_about_version),
            versionNumber, -1);

    // Terms and conditions
    HolderUtils.configure(viewById(R.id.settings_about_clu), getString(R.string.settings_about_clu), null, -1);
    viewById(R.id.settings_about_clu).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            IntentUtils.startWebBrowser(getActivity(), "http://www.alfresco.com/legal/agreements/cloud");
        }
    });

    // Terms and conditions
    HolderUtils.configure(viewById(R.id.settings_about_thirdparty),
            getString(R.string.settings_about_thirdparty), null, -1);
    viewById(R.id.settings_about_thirdparty).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            new LibsBuilder().withActivityTitle(getString(R.string.settings_about_thirdparty))
                    .withLibraries("MaterialEdittext", "MaterialDialogs", "AndroidSwipeLayout",
                            "CircleIndicator", "Otto", "AppCompat Library")
                    .withLicenseDialog(true).withVersionShown(false).withAnimations(false)
                    .withLicenseShown(true).withFields(R.string.class.getFields())
                    .withActivityStyle(Libs.ActivityStyle.LIGHT_DARK_TOOLBAR).start(getActivity());
        }
    });

    // Feedback - Email
    vh = HolderUtils.configure(viewById(R.id.settings_feedback_email_container),
            getString(R.string.settings_feedback_email), null, -1);
    viewById(R.id.settings_feedback_email_container).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            IntentUtils.actionSendFeedbackEmail(GeneralSettingsFragment.this);
        }
    });

    recreate();

    return getRootView();
}

From source file:com.example.android.naradaoffline.DatagramFragment.java

/**
 * Set up the UI and background operations for chat.
 *///from  ww  w. ja v  a2  s  . c  o m
private void setupChat() {
    Log.d(TAG);

    // Initialize the array adapter for the conversation thread
    mConversationArrayAdapter = new ArrayAdapter<String>(getActivity(), R.layout.message);

    //mConversationView.setAdapter(mConversationArrayAdapter);

    // Initialize the compose field with a listener for the return key
    //        mOutEditText.setOnEditorActionListener(mWriteListener);

    // Initialize the send button with a listener that for click events

    mGetNewsPaper.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            // Send a message using content of the edit text widget
            View view = getView();
            if (null != view) {

                //                    TextView textView = (TextView) view.findViewById(R.id.edit_text_out);
                DatagramRequest d = new DatagramRequest(DatagramRequestType.GET_NEWSPAPER,
                        mConnectedDeviceName);
                sendDatagramRequest(d);
            }
        }
    });

    // Initialize the send button with a listener that for click events
    mGetEmail.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            // Send a message using content of the edit text widget
            View view = getView();
            if (null != view) {
                //                    TextView textView = (TextView) view.findViewById(R.id.edit_text_out);

                Log.i(TAG, "button clicked");

                AlertDialog.Builder builder = new AlertDialog.Builder(DatagramFragment.this.getContext());
                builder.setTitle("Write your email here");

                LinearLayout layout = new LinearLayout(getContext());
                layout.setOrientation(LinearLayout.VERTICAL);

                // Set up the input
                final EditText email = new EditText(DatagramFragment.this.getContext());
                email.setHint("Recipient e-mail address");
                // Specify the type of input expected; this, for example, sets the input as a password, and will mask the text
                email.setInputType(InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS);
                layout.addView(email);
                final EditText input = new EditText(DatagramFragment.this.getContext());
                // Specify the type of input expected; this, for example, sets the input as a password, and will mask the text
                input.setHint("Type your e-mail here");
                input.setInputType(InputType.TYPE_CLASS_TEXT);
                layout.addView(input);

                builder.setView(layout);
                // Set up the buttons
                builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        mEmail = email.getText().toString();
                        mText = input.getText().toString();
                        DatagramRequest d = new DatagramRequest(DatagramRequestType.SEND_EMAIL,
                                mConnectedDeviceName, "", mEmail, mText);
                        sendDatagramRequest(d);

                    }
                });
                builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.cancel();
                    }
                });

                builder.show();

            }
        }
    });

    // Initialize the BluetoothDatagramService to perform bluetooth connections
    mChatService = new BluetoothDatagramService(getActivity(), mHandler);

    // Initialize the buffer for outgoing messages
    mOutStringBuffer = new StringBuffer("");
}

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

private void displayMessage(String messageTitle, String message) {
    AlertDialog.Builder myalert = new AlertDialog.Builder(this);

    TextView title = new TextView(this);
    title.setTypeface(Typeface.SANS_SERIF);
    title.setTextSize(20);//from w  ww.j a v a  2 s  .c  o m
    title.setTextColor(getResources().getColor(R.color.blue));
    title.setPadding(8, 8, 8, 8);
    title.setText("Synchronization");
    title.setGravity(Gravity.CENTER_VERTICAL);

    LinearLayout layout = new LinearLayout(this);
    TextView text = new TextView(this);
    text.setTypeface(Typeface.SANS_SERIF);
    text.setTextSize(20);
    text.setPadding(10, 10, 10, 10);
    text.setText(message);
    layout.addView(text);

    myalert.setView(layout);
    myalert.setCustomTitle(title);
    myalert.setCancelable(true);
    myalert.show();

}

From source file:fr.shywim.antoinedaniel.ui.MainActivity.java

private void createNavDrawerItems() {
    LinearLayout navDrawer = (LinearLayout) findViewById(R.id.nav_drawer);
    if (navDrawer == null) {
        return;//from  w  w w  . j  av  a2s .  c  om
    }

    mNavDrawerItemViews = new View[mNavDrawerItems.size()];
    navDrawer.removeAllViews();
    for (int i = 0; i < mNavDrawerItems.size(); i++) {
        mNavDrawerItemViews[i] = makeNavDrawerItem(mNavDrawerItems.get(i), navDrawer);
        navDrawer.addView(mNavDrawerItemViews[i]);
    }
}

From source file:com.codeslap.topy.BaseMultiPaneActivity.java

public View getTwoColumns(Fragment firstFragment, float firstWeight, Fragment secondFragment,
        float secondWeight) {
    LinearLayout linearLayout = new LinearLayout(this);
    linearLayout.setOrientation(LinearLayout.HORIZONTAL);

    int firstId = 1;
    int secondId = 2;

    FrameLayout firstLayout = new FrameLayout(this);
    LinearLayout.LayoutParams firstParams = new LinearLayout.LayoutParams(0,
            LinearLayout.LayoutParams.FILL_PARENT);
    firstParams.weight = firstWeight;//from w  w  w. j a  v  a 2s  .  co  m
    firstLayout.setLayoutParams(firstParams);
    firstLayout.setId(firstId);

    FrameLayout secondLayout = new FrameLayout(this);
    LinearLayout.LayoutParams secondParams = new LinearLayout.LayoutParams(0,
            LinearLayout.LayoutParams.FILL_PARENT);
    secondLayout.setLayoutParams(secondParams);
    secondParams.weight = secondWeight;
    secondLayout.setId(secondId);

    FragmentManager fm = getSupportFragmentManager();
    FragmentTransaction ft = fm.beginTransaction();
    ft.add(firstId, firstFragment);
    ft.add(2, secondFragment);
    ft.commit();

    linearLayout.addView(firstLayout);
    linearLayout.addView(secondLayout);

    return linearLayout;
}

From source file:app.jorge.mobile.com.transportalert.ScrollingActivity.java

private void addCard(LinearLayout item, CardFactory.TUBE_LINE line) {

    CardTube card = CardFactory.getCard(line);
    View child = getLayoutInflater().inflate(R.layout.tube_line, null);

    ImageView imageView = (ImageView) child.findViewById(R.id.iconTube);
    //imageView.setImageResource(card.getIcon());
    imageView.setImageBitmap(decodeSampledBitmapFromResource(getResources(), card.getIcon(), 100, 100));

    TextView lineName = (TextView) child.findViewById(R.id.tubeName);
    lineName.setText(card.getName());/*from w w w  .  j a v  a2 s  .  co m*/
    lineName.setTextColor(Color.parseColor(card.getColour()));

    TextView text = (TextView) child.findViewById(R.id.tubeStatus);
    text.setText(card.getStatus());

    item.addView(child);

    child.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            View imageView = v.findViewById(R.id.iconTube);
            imageView.setTransitionName(getString(R.string.activity_image_trans));

            View textTubeNameView = v.findViewById(R.id.tubeName);
            textTubeNameView.setTransitionName(getString(R.string.activity_text_tube_name));

            View textStatusView = v.findViewById(R.id.tubeStatus);
            textStatusView.setTransitionName(getString(R.string.activity_text_tube_status));

            Intent intent = new Intent(ScrollingActivity.this, DetailActivity.class);
            Pair<View, String> pair1 = Pair.create(imageView, imageView.getTransitionName());
            Pair<View, String> pair2 = Pair.create(textTubeNameView, textTubeNameView.getTransitionName());
            Pair<View, String> pair3 = Pair.create(textStatusView, textStatusView.getTransitionName());

            ActivityOptionsCompat options = ActivityOptionsCompat
                    .makeSceneTransitionAnimation(ScrollingActivity.this, pair1, pair2, pair3);

            String line = ((TextView) textTubeNameView).getText().toString();
            String status = ((TextView) textStatusView).getText().toString();

            LineStatuses ls = tubeStatus.get(line);
            if ((ls != null) && (ls.getDisruption() != null)) {
                intent.putExtra(getString(R.string.activity_info_category), ls.getDisruption().getCategory());
                intent.putExtra(getString(R.string.activity_info_description),
                        ls.getDisruption().getDescription());
                intent.putExtra(getString(R.string.activity_info_additional),
                        ls.getDisruption().getAdditionalInfo());
                intent.putExtra(getString(R.string.activity_info_icon), line);
                intent.putExtra(getString(R.string.activity_info_status), status);

                startActivity(intent, options.toBundle());
            }

        }
    });

}

From source file:com.gh4a.fragment.UserFragment.java

public void fillOrganizations(List<User> organizations) {
    ViewGroup llOrgs = (ViewGroup) mContentView.findViewById(R.id.ll_orgs);
    LinearLayout llOrg = (LinearLayout) mContentView.findViewById(R.id.ll_org);
    int count = organizations != null ? organizations.size() : 0;
    LayoutInflater inflater = getLayoutInflater(null);

    llOrg.removeAllViews();// w ww. ja v  a2s . c  om
    llOrgs.setVisibility(count > 0 ? View.VISIBLE : View.GONE);

    for (int i = 0; i < count; i++) {
        User org = organizations.get(i);
        View rowView = inflater.inflate(R.layout.selectable_label_with_avatar, llOrg, false);

        rowView.setOnClickListener(this);
        rowView.setTag(org);

        ImageView avatar = (ImageView) rowView.findViewById(R.id.iv_gravatar);
        AvatarHandler.assignAvatar(avatar, org);

        TextView nameView = (TextView) rowView.findViewById(R.id.tv_title);
        nameView.setText(org.getLogin());

        llOrg.addView(rowView);
    }
}