Example usage for android.widget LinearLayout setOrientation

List of usage examples for android.widget LinearLayout setOrientation

Introduction

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

Prototype

public void setOrientation(@OrientationMode int orientation) 

Source Link

Document

Should the layout be a column or a row.

Usage

From source file:com.phonegap.plugins.ChildBrowser.java

/**
* Display a new browser with the specified URL.
*
* @param url The url to load.//from w ww .  j  a v  a2s  . co  m
* @param jsonObject
*/
public String showWebPage(final String url, JSONObject options) {
    // Determine if we should hide the location bar.
    if (options != null) {
        showLocationBar = options.optBoolean("showLocationBar", true);
    }

    // Create dialog in new thread
    Runnable runnable = new Runnable() {
        /**
        * Convert our DIP units to Pixels
        *
        * @return int
        */
        private int dpToPixels(int dipValue) {
            int value = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, (float) dipValue,
                    cordova.getActivity().getResources().getDisplayMetrics());

            return value;
        }

        public void run() {
            // Let's create the main dialog
            dialog = new Dialog(cordova.getActivity(), android.R.style.Theme_NoTitleBar);
            dialog.getWindow().getAttributes().windowAnimations = android.R.style.Animation_Dialog;
            dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
            dialog.setCancelable(true);
            dialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
                public void onDismiss(DialogInterface dialog) {
                    try {
                        JSONObject obj = new JSONObject();
                        obj.put("type", CLOSE_EVENT);

                        sendUpdate(obj, false);
                    } catch (JSONException e) {
                        Log.d(LOG_TAG, "Should never happen");
                    }
                }
            });

            // Main container layout
            LinearLayout main = new LinearLayout(cordova.getActivity());
            main.setOrientation(LinearLayout.VERTICAL);

            // Toolbar layout
            RelativeLayout toolbar = new RelativeLayout(cordova.getActivity());
            toolbar.setLayoutParams(
                    new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT, this.dpToPixels(44)));
            toolbar.setPadding(this.dpToPixels(2), this.dpToPixels(2), this.dpToPixels(2), this.dpToPixels(2));
            toolbar.setHorizontalGravity(Gravity.LEFT);
            toolbar.setVerticalGravity(Gravity.TOP);
            toolbar.setVisibility(View.GONE);

            // Action Button Container layout
            RelativeLayout actionButtonContainer = new RelativeLayout(cordova.getActivity());
            actionButtonContainer.setLayoutParams(
                    new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
            actionButtonContainer.setHorizontalGravity(Gravity.LEFT);
            actionButtonContainer.setVerticalGravity(Gravity.CENTER_VERTICAL);
            actionButtonContainer.setId(1);
            actionButtonContainer.setVisibility(View.GONE);

            // Back button
            ImageButton back = new ImageButton(cordova.getActivity());
            RelativeLayout.LayoutParams backLayoutParams = new RelativeLayout.LayoutParams(
                    LayoutParams.WRAP_CONTENT, LayoutParams.FILL_PARENT);
            backLayoutParams.addRule(RelativeLayout.ALIGN_LEFT);
            back.setLayoutParams(backLayoutParams);
            back.setContentDescription("Back Button");
            back.setId(2);
            try {
                back.setImageBitmap(loadDrawable("www/images/icon_arrow_left.png"));
            } catch (IOException e) {
                Log.e(LOG_TAG, e.getMessage(), e);
            }
            back.setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {
                    goBack();
                }
            });

            // Forward button
            ImageButton forward = new ImageButton(cordova.getActivity());
            RelativeLayout.LayoutParams forwardLayoutParams = new RelativeLayout.LayoutParams(
                    LayoutParams.WRAP_CONTENT, LayoutParams.FILL_PARENT);
            forwardLayoutParams.addRule(RelativeLayout.RIGHT_OF, 2);
            forward.setLayoutParams(forwardLayoutParams);
            forward.setContentDescription("Forward Button");
            forward.setId(3);
            try {
                forward.setImageBitmap(loadDrawable("www/images/icon_arrow_right.png"));
            } catch (IOException e) {
                Log.e(LOG_TAG, e.getMessage(), e);
            }
            forward.setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {
                    goForward();
                }
            });

            // Edit Text Box
            edittext = new EditText(cordova.getActivity());
            RelativeLayout.LayoutParams textLayoutParams = new RelativeLayout.LayoutParams(
                    LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
            textLayoutParams.addRule(RelativeLayout.RIGHT_OF, 1);
            textLayoutParams.addRule(RelativeLayout.LEFT_OF, 5);
            edittext.setLayoutParams(textLayoutParams);
            edittext.setId(4);
            edittext.setSingleLine(true);
            edittext.setText(url);
            edittext.setInputType(InputType.TYPE_TEXT_VARIATION_URI);
            edittext.setImeOptions(EditorInfo.IME_ACTION_GO);
            edittext.setInputType(InputType.TYPE_NULL); // Will not except input... Makes the text NON-EDITABLE
            edittext.setOnKeyListener(new View.OnKeyListener() {
                public boolean onKey(View v, int keyCode, KeyEvent event) {
                    // If the event is a key-down event on the "enter" button
                    if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) {
                        navigate(edittext.getText().toString());
                        return true;
                    }
                    return false;
                }
            });

            // Close button
            ImageButton close = new ImageButton(cordova.getActivity());
            RelativeLayout.LayoutParams closeLayoutParams = new RelativeLayout.LayoutParams(
                    LayoutParams.WRAP_CONTENT, LayoutParams.FILL_PARENT);
            closeLayoutParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
            close.setLayoutParams(closeLayoutParams);
            forward.setContentDescription("Close Button");
            close.setId(5);
            try {
                close.setImageBitmap(loadDrawable("www/images/icon_close.png"));
            } catch (IOException e) {
                Log.e(LOG_TAG, e.getMessage(), e);
            }
            close.setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {
                    closeDialog();
                }
            });

            // WebView
            webview = new WebView(cordova.getActivity());
            webview.setLayoutParams(
                    new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
            webview.setWebChromeClient(new WebChromeClient());
            WebViewClient client = new ChildBrowserClient(edittext);
            webview.setWebViewClient(client);
            WebSettings settings = webview.getSettings();
            settings.setJavaScriptEnabled(true);
            settings.setJavaScriptCanOpenWindowsAutomatically(true);
            settings.setBuiltInZoomControls(true);
            settings.setPluginsEnabled(true);
            settings.setDomStorageEnabled(true);
            webview.loadUrl(url);
            webview.setId(6);
            webview.getSettings().setLoadWithOverviewMode(true);
            webview.getSettings().setUseWideViewPort(true);
            webview.requestFocus();
            webview.requestFocusFromTouch();

            // Add the back and forward buttons to our action button container layout
            actionButtonContainer.addView(back);
            actionButtonContainer.addView(forward);

            // Add the views to our toolbar
            toolbar.addView(actionButtonContainer);
            toolbar.addView(edittext);
            toolbar.addView(close);

            // Don't add the toolbar if its been disabled
            if (getShowLocationBar()) {
                // Add our toolbar to our main view/layout
                main.addView(toolbar);
            }

            // Add our webview to our main view/layout
            main.addView(webview);

            WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
            lp.copyFrom(dialog.getWindow().getAttributes());
            lp.width = WindowManager.LayoutParams.FILL_PARENT;
            lp.height = WindowManager.LayoutParams.FILL_PARENT;

            dialog.setContentView(main);
            dialog.show();
            dialog.getWindow().setAttributes(lp);
        }

        private Bitmap loadDrawable(String filename) throws java.io.IOException {
            InputStream input = cordova.getActivity().getAssets().open(filename);
            return BitmapFactory.decodeStream(input);
        }
    };
    this.cordova.getActivity().runOnUiThread(runnable);
    return "";
}

From source file:com.example.fan.horizontalscrollview.PagerSlidingTabStrip.java

private void addRedDotTab(final int position, String title, int resId) {
    LinearLayout tabLayout = new LinearLayout(getContext());
    tabLayout.setOrientation(LinearLayout.HORIZONTAL);
    tabLayout.setGravity(Gravity.CENTER);
    TextView tab = new TextView(getContext());
    tab.setText(title);//ww  w  . jav a  2  s .com
    tab.setFocusable(true);
    tab.setGravity(Gravity.CENTER);

    tab.setSingleLine();
    tab.setTextColor(getResources().getColorStateList(R.color.pst_tab_text_selector));
    tab.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18.0f);
    tabLayout.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            if (null != mOnPageClickedLisener) {
                mOnPageClickedLisener.onPageClicked(position);
            }
            pager.setCurrentItem(position);
        }
    });

    tabLayout.addView(tab, 0);
    ImageView tabImg = new ImageView(getContext());
    LinearLayout.LayoutParams tabImgParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
            LayoutParams.WRAP_CONTENT);
    tabImgParams.setMargins(DeviceUtils.dip2px(getContext(), 5), DeviceUtils.dip2px(getContext(), 10), 0, 0);
    tabImgParams.gravity = Gravity.TOP;
    tabImg.setLayoutParams(tabImgParams);

    tabLayout.addView(tabImg, 1);
    tabsContainer.addView(tabLayout);
}

From source file:com.example.diplimadoapp.SuperAwesomeCardFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);

    FrameLayout fl = new FrameLayout(getActivity());
    fl.setLayoutParams(params);//from  www .  j av a2s . c  om

    final int margin = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8,
            getResources().getDisplayMetrics());

    switch (position) {
    case 0:

        LinearLayout ll = new LinearLayout(getActivity());
        ll.setLayoutParams(new FrameLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
        ll.setOrientation(LinearLayout.VERTICAL);

        ImageView iv = new ImageView(getActivity());
        iv.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, 1020));
        //iv.setLayoutParams(new  LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT,LayoutParams.MATCH_PARENT));
        iv.setMaxHeight(520);
        iv.setImageResource(R.drawable.contact);
        ll.addView(iv);

        TableLayout tl = new TableLayout(getActivity());
        tl.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));

        TableRow tr = new TableRow(getActivity());
        tr.setLayoutParams(new TableLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
        tr.setGravity(Gravity.FILL_HORIZONTAL);
        tr.setPadding(5, 5, 5, 5);

        List<RssItem> lecturaitems = null;
        try {
            // Create RSS reader
            RssReader rssReader = new RssReader(
                    "http://www.senalradionica.gov.co/index.php/home/articulos/itemlist?format=feed");
            // Get a ListView from main view
            //ListView itcItems = (ListView) findViewById(R.id.listMainView);

            lecturaitems = rssReader.getItems();

        } catch (Exception e) {
            Log.e("Diplomado App Reader", e.getMessage());
        }

        TextView v1 = new TextView(getActivity());
        params.setMargins(margin, margin, margin, margin);
        v1.setLayoutParams(new TableRow.LayoutParams(0, LayoutParams.WRAP_CONTENT, 2));
        v1.setGravity(Gravity.CENTER);
        v1.setBackgroundResource(R.drawable.background_card);
        if (lecturaitems != null) {
            v1.setText(lecturaitems.get(0).getTitle());
            String urlnoticia = lecturaitems.get(0).getLink();
            v1.setOnClickListener(new NoticiaDestacadaOnClickListener(urlnoticia));
        } else {
            v1.setText("No Registra nuevas noticias");
        }

        tr.addView(v1);

        ImageButton ib = new ImageButton(getActivity());
        ib.setLayoutParams(new TableRow.LayoutParams(0, LayoutParams.WRAP_CONTENT, 1));
        ib.setImageResource(R.drawable.facebook);

        ib.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                Intent myWebLink = new Intent(android.content.Intent.ACTION_VIEW);
                myWebLink.setData(Uri.parse("http://www.facebook.com"));
                startActivity(myWebLink);
            }
        });

        tr.addView(ib);

        ImageButton ib2 = new ImageButton(getActivity());
        ib2.setLayoutParams(new TableRow.LayoutParams(0, LayoutParams.WRAP_CONTENT, 1));
        ib2.setImageResource(R.drawable.twitter);

        ib2.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                Intent myWebLink = new Intent(android.content.Intent.ACTION_VIEW);
                myWebLink.setData(Uri.parse("http://www.twitter.com"));
                startActivity(myWebLink);
            }
        });

        tr.addView(ib2);

        ImageButton ib3 = new ImageButton(getActivity());
        ib3.setLayoutParams(new TableRow.LayoutParams(0, LayoutParams.WRAP_CONTENT, 1));
        ib3.setImageResource(R.drawable.youtube);

        ib3.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                Intent myWebLink = new Intent(android.content.Intent.ACTION_VIEW);
                myWebLink.setData(Uri.parse("http://www.youtube.com"));
                startActivity(myWebLink);
            }
        });

        tr.addView(ib3);

        tl.addView(tr);

        ll.addView(tl);

        fl.addView(ll);

        break;

    case 1:

        LinearLayout ll2 = new LinearLayout(getActivity());
        ll2.setLayoutParams(new FrameLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
        ll2.setOrientation(LinearLayout.VERTICAL);

        TableLayout tl2 = new TableLayout(getActivity());
        tl2.setLayoutParams(
                new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));

        TableRow tr2 = new TableRow(getActivity());
        tr2.setLayoutParams(new TableLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
        tr2.setGravity(Gravity.FILL_HORIZONTAL);
        tr2.setPadding(5, 5, 5, 5);

        TextView v0 = new TextView(getActivity());
        params.setMargins(margin, margin, margin, margin);
        v0.setLayoutParams(new TableRow.LayoutParams(0, LayoutParams.WRAP_CONTENT, 2));
        v0.setGravity(Gravity.CENTER);
        v0.setText("Acusticos Radionoca. Lunes a Viernes 8:00 a.m. - 9:00 a.m.");
        tr2.addView(v0);

        ImageButton ib20 = new ImageButton(getActivity());
        ib20.setLayoutParams(new TableRow.LayoutParams(0, LayoutParams.WRAP_CONTENT, 1));
        ib20.setImageResource(R.drawable.pacusticos);
        ib20.setBackgroundDrawable(null);

        tr2.addView(ib20);

        tl2.addView(tr2);

        TableRow tr3 = new TableRow(getActivity());
        tr3.setLayoutParams(new TableLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
        tr3.setGravity(Gravity.FILL_HORIZONTAL);
        tr3.setPadding(5, 5, 5, 5);

        TextView v03 = new TextView(getActivity());
        params.setMargins(margin, margin, margin, margin);
        v03.setLayoutParams(new TableRow.LayoutParams(0, LayoutParams.WRAP_CONTENT, 2));
        v03.setGravity(Gravity.CENTER);
        v03.setText("Acusticos Radionoca. Lunes a Viernes 8:00 a.m. - 9:00 a.m.");
        tr3.addView(v03);

        ImageButton ib30 = new ImageButton(getActivity());
        ib30.setLayoutParams(new TableRow.LayoutParams(0, LayoutParams.WRAP_CONTENT, 1));
        ib30.setImageResource(R.drawable.pradionica_lacarta);
        ib30.setBackgroundDrawable(null);

        tr3.addView(ib30);

        tl2.addView(tr3);

        TableRow tr4 = new TableRow(getActivity());
        tr4.setLayoutParams(new TableLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
        tr4.setGravity(Gravity.FILL_HORIZONTAL);
        tr4.setPadding(5, 5, 5, 5);

        TextView v04 = new TextView(getActivity());
        params.setMargins(margin, margin, margin, margin);
        v04.setLayoutParams(new TableRow.LayoutParams(0, LayoutParams.WRAP_CONTENT, 2));
        v04.setGravity(Gravity.CENTER);
        v04.setText("Acusticos Radionoca. Lunes a Viernes 8:00 a.m. - 9:00 a.m.");
        tr4.addView(v04);

        tl2.addView(tr4);

        ImageButton ib40 = new ImageButton(getActivity());
        ib40.setLayoutParams(new TableRow.LayoutParams(0, LayoutParams.WRAP_CONTENT, 1));
        ib40.setImageResource(R.drawable.prockeros);
        ib40.setBackgroundDrawable(null);

        tr4.addView(ib40);

        ll2.addView(tl2);

        /*
        VideoView videoView = new VideoView(getActivity());
                
        Uri path = Uri.parse("rtmp://cdns840stu0010.multistream.net:80/rtvcRadionicalive/?pass=|radionica|");
                
        videoView.setVideoURI(path);
        videoView.start(); 
                
        TableRow tr5 =new TableRow(getActivity());
        tr5.setLayoutParams(new TableLayout.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));
        tr5.setGravity(Gravity.FILL_HORIZONTAL);
        tr5.setPadding(5,5,5,5);
        tr5.addView(videoView);
                
        ll2.addView(tr5);*/

        fl.addView(ll2);
        break;
    case 2:
        ListView lv = new ListView(getActivity());
        params.setMargins(margin, margin, margin, margin);
        lv.setLayoutParams(params);
        lv.setLayoutParams(params);
        lv.setBackgroundResource(R.drawable.background_card);
        try {
            // Create RSS reader
            RssReader rssReader = new RssReader(
                    "http://www.senalradionica.gov.co/index.php/home/articulos/itemlist?format=feed");
            // Get a ListView from main view
            //ListView itcItems = (ListView) findViewById(R.id.listMainView);

            List<RssItem> lecturaitems2 = rssReader.getItems();
            // Create a list adapter
            ArrayAdapter<RssItem> adapter = new ArrayAdapter<RssItem>(getActivity(),
                    android.R.layout.simple_list_item_1, lecturaitems2);
            // Set list adapter for the ListView
            lv.setAdapter(adapter);

            // Set list view item click listener
            lv.setOnItemClickListener(new ListListener(lecturaitems2, getActivity()));

        } catch (Exception e) {
            Log.e("Diplomado App Reader", e.getMessage());
        }
        fl.addView(lv);
        break;
    }

    return fl;
}

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

@NonNull
private LinearLayout createBikeLine(@NonNull final BikeStation bikeStation, final boolean firstLine) {
    final LinearLayout.LayoutParams lineParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
            LayoutParams.WRAP_CONTENT);/* w  w w.ja  v a2  s .  c  om*/
    final LinearLayout line = new LinearLayout(context);
    line.setOrientation(LinearLayout.HORIZONTAL);
    line.setLayoutParams(lineParams);

    // Left
    final LinearLayout.LayoutParams leftParam = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
            LayoutParams.WRAP_CONTENT);
    final RelativeLayout left = new RelativeLayout(context);
    left.setLayoutParams(leftParam);

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

    final RelativeLayout.LayoutParams availableParam = new RelativeLayout.LayoutParams(
            LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    availableParam.addRule(RelativeLayout.RIGHT_OF, lineId);
    availableParam.setMargins(pixelsHalf, 0, 0, 0);

    final TextView boundCustomTextView = new TextView(context);
    boundCustomTextView.setText(activity.getString(R.string.bike_available_docks));
    boundCustomTextView.setSingleLine(true);
    boundCustomTextView.setLayoutParams(availableParam);
    boundCustomTextView.setTextColor(grey5);
    int availableId = Util.generateViewId();
    boundCustomTextView.setId(availableId);

    final RelativeLayout.LayoutParams availableValueParam = new RelativeLayout.LayoutParams(
            LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    availableValueParam.addRule(RelativeLayout.RIGHT_OF, availableId);
    availableValueParam.setMargins(pixelsHalf, 0, 0, 0);

    final TextView amountBike = new TextView(context);
    final String text = firstLine ? activity.getString(R.string.bike_available_bikes)
            : activity.getString(R.string.bike_available_docks);
    boundCustomTextView.setText(text);
    final Integer data = firstLine ? bikeStation.getAvailableBikes() : bikeStation.getAvailableDocks();
    if (data == null) {
        amountBike.setText("?");
        amountBike.setTextColor(ContextCompat.getColor(context, R.color.orange));
    } else {
        amountBike.setText(String.valueOf(data));
        final int color = data == 0 ? R.color.red : R.color.green;
        amountBike.setTextColor(ContextCompat.getColor(context, color));
    }
    amountBike.setLayoutParams(availableValueParam);

    left.addView(lineIndication);
    left.addView(boundCustomTextView);
    left.addView(amountBike);
    line.addView(left);
    return line;
}

From source file:net.opendasharchive.openarchive.ReviewMediaActivity.java

private void deleteMedia() {
    final Switch swDeleteLocal = new Switch(this);
    final Switch swDeleteRemote = new Switch(this);

    LinearLayout linearLayoutGroup = new LinearLayout(this);
    linearLayoutGroup.setOrientation(LinearLayout.VERTICAL);
    linearLayoutGroup.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.WRAP_CONTENT));

    swDeleteLocal.setTextOn(getString(R.string.answer_yes));
    swDeleteLocal.setTextOff(getString(R.string.answer_no));

    TextView tvLocal = new TextView(this);
    tvLocal.setText(R.string.delete_local);

    LinearLayout linearLayout = new LinearLayout(this);
    linearLayout.setOrientation(LinearLayout.HORIZONTAL);
    linearLayout.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.WRAP_CONTENT));
    linearLayout.setGravity(Gravity.CENTER_HORIZONTAL);

    linearLayout.addView(tvLocal);/*from  w  w w.  j a v a  2  s.c o m*/
    linearLayout.addView(swDeleteLocal);

    linearLayoutGroup.addView(linearLayout);

    if (mMedia.getServerUrl() != null) {
        swDeleteRemote.setTextOn(getString(R.string.answer_yes));
        swDeleteRemote.setTextOff(getString(R.string.answer_no));

        TextView tvRemote = new TextView(this);
        tvRemote.setText(R.string.delete_remote);

        LinearLayout linearLayoutRemote = new LinearLayout(this);
        linearLayoutRemote.setOrientation(LinearLayout.HORIZONTAL);
        linearLayoutRemote.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.WRAP_CONTENT));
        linearLayoutRemote.setGravity(Gravity.CENTER_HORIZONTAL);

        linearLayoutRemote.addView(tvRemote);
        linearLayoutRemote.addView(swDeleteRemote);
        linearLayoutGroup.addView(linearLayoutRemote);

    }

    AlertDialog.Builder build = new AlertDialog.Builder(ReviewMediaActivity.this).setTitle(R.string.menu_delete)
            .setMessage(R.string.alert_delete_media).setView(linearLayoutGroup).setCancelable(true)
            .setNegativeButton(R.string.dialog_cancel, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialogInterface, int i) {
                    //do nothing
                }
            })

            .setPositiveButton(R.string.dialog_ok, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {

                    deleteMedia(swDeleteLocal.isChecked(), swDeleteRemote.isChecked());
                    finish();

                }
            });

    build.create().show();
}

From source file:com.example.fan.horizontalscrollview.PagerSlidingTabStrip.java

private void addWarningTab(final int position, String title, int resId) {
    LinearLayout tabLayout = new LinearLayout(getContext());
    tabLayout.setOrientation(LinearLayout.HORIZONTAL);
    tabLayout.setGravity(Gravity.CENTER);

    ImageView tabImg = new ImageView(getContext());
    int width = DimenUtils.dp2px(getContext(), 18);
    LinearLayout.LayoutParams tabImgParams = new LinearLayout.LayoutParams(width, width);
    tabImgParams.setMargins(0, 0, DimenUtils.dp2px(getContext(), 10), 0);
    tabImgParams.gravity = Gravity.CENTER;
    tabImg.setLayoutParams(tabImgParams);
    if (resId != -1) {
        tabImg.setBackgroundResource(resId);
        tabImg.setVisibility(View.VISIBLE);
    } else {//  ww  w . j a  v  a 2 s  . c om
        tabImg.setVisibility(View.GONE);
    }
    tabLayout.addView(tabImg, 0);

    TextView tab = new TextView(getContext());
    tab.setText(title);
    tab.setFocusable(true);
    tab.setGravity(Gravity.CENTER);
    tab.setSingleLine();
    tab.setTextColor(getResources().getColorStateList(
            mTextChangeable ? R.color.pst_tab_changeable_text_selector : R.color.pst_tab_text_selector));
    tab.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18.0f);
    tabLayout.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            if (null != mOnPageClickedLisener) {
                mOnPageClickedLisener.onPageClicked(position);
            }
            pager.setCurrentItem(position);
        }
    });
    tabLayout.addView(tab, 1);

    tabsContainer.addView(tabLayout);
}

From source file:com.klisly.bookbox.widget.draglistview.BoardView.java

public DragItemRecyclerView addColumnList(final DragItemAdapter adapter, final View header,
        boolean hasFixedItemSize) {
    final DragItemRecyclerView recyclerView = new DragItemRecyclerView(getContext());
    recyclerView.setMotionEventSplittingEnabled(false);
    recyclerView.setDragItem(mDragItem);
    recyclerView.setLayoutParams(//from   w w  w  .  jav  a 2 s.  co m
            new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT));
    recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
    recyclerView.setHasFixedSize(hasFixedItemSize);
    recyclerView.setItemAnimator(new DefaultItemAnimator());
    recyclerView.setDragItemListener(new DragItemRecyclerView.DragItemListener() {
        @Override
        public void onDragStarted(int itemPosition, float x, float y) {
            mDragStartColumn = getColumnOfList(recyclerView);
            mDragStartRow = itemPosition;
            mCurrentRecyclerView = recyclerView;
            mDragItem.setOffset(((View) mCurrentRecyclerView.getParent()).getX(), mCurrentRecyclerView.getY());
            if (mBoardListener != null) {
                mBoardListener.onItemDragStarted(mDragStartColumn, mDragStartRow);
            }
            invalidate();
        }

        @Override
        public void onDragging(int itemPosition, float x, float y) {
        }

        @Override
        public void onDragEnded(int newItemPosition) {
            if (mBoardListener != null) {
                mBoardListener.onItemDragEnded(mDragStartColumn, mDragStartRow, getColumnOfList(recyclerView),
                        newItemPosition);
            }
        }
    });

    recyclerView.setAdapter(adapter);
    recyclerView.setDragEnabled(mDragEnabled);
    adapter.setDragStartedListener(new DragItemAdapter.DragStartCallback() {
        @Override
        public boolean startDrag(View itemView, long itemId) {
            return recyclerView.startDrag(itemView, itemId, getListTouchX(recyclerView),
                    getListTouchY(recyclerView));
        }

        @Override
        public boolean isDragging() {
            return recyclerView.isDragging();
        }
    });

    LinearLayout layout = new LinearLayout(getContext());
    layout.setOrientation(LinearLayout.VERTICAL);
    layout.setLayoutParams(new LayoutParams(mColumnWidth, LayoutParams.MATCH_PARENT));
    if (header != null) {
        layout.addView(header);
        mHeaders.put(mLists.size(), header);
    }
    layout.addView(recyclerView);

    mLists.add(recyclerView);
    mColumnLayout.addView(layout);
    return recyclerView;
}

From source file:com.mooshim.mooshimeter.main.ScanActivity.java

private void addDevice(final MooshimeterDevice d) {
    mEmptyMsg.setVisibility(View.GONE);

    if (mMeterList.contains(d)) {
        // The meter as already been added
        Log.e(TAG, "Tried to add the same meter twice");
        return;/*w  w  w.j  a v a 2s.com*/
    }

    mMeterList.add(d);
    mMeterDict.put(d.getAddress(), d);

    final LinearLayout wrapper = new LinearLayout(this);
    wrapper.setOrientation(LinearLayout.VERTICAL);
    wrapper.setLayoutParams(mDeviceScrollView.getLayoutParams());

    wrapper.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if (d.mConnectionState == BluetoothProfile.STATE_CONNECTED
                    || d.mConnectionState == BluetoothProfile.STATE_CONNECTING) {
                startSingleMeterActivity(d);
            } else {
                final Button bv = (Button) view.findViewById(R.id.btnConnect);
                toggleConnectionState(bv, d);
            }
        }
    });

    wrapper.addView(mInflater.inflate(R.layout.element_mm_titlebar, wrapper, false));
    //wrapper.setTag(Integer.valueOf(R.layout.element_mm_titlebar));

    refreshMeterTile(d, wrapper);
    mDeviceScrollView.addView(wrapper);
    mTileList.add(wrapper);

    if (mMeterList.size() > 1)
        setStatus(mMeterList.size() + " devices");
    else
        setStatus("1 device");
}

From source file:paulscode.android.mupen64plusae.SplashActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Get app data and user preferences
    mAppData = new AppData(this);
    mGlobalPrefs = new GlobalPrefs(this, mAppData);
    mGlobalPrefs.enforceLocale(this);
    mPrefs = PreferenceManager.getDefaultSharedPreferences(this);

    // Ensure that any missing preferences are populated with defaults (e.g. preference added to
    // new release)
    PreferenceManager.setDefaultValues(this, R.xml.preferences_audio, false);
    PreferenceManager.setDefaultValues(this, R.xml.preferences_data, false);
    PreferenceManager.setDefaultValues(this, R.xml.preferences_display, false);
    PreferenceManager.setDefaultValues(this, R.xml.preferences_input, false);
    PreferenceManager.setDefaultValues(this, R.xml.preferences_library, false);
    PreferenceManager.setDefaultValues(this, R.xml.preferences_touchscreen, false);

    // Ensure that selected plugin names and other list preferences are valid
    // @formatter:off
    final Resources res = getResources();
    PrefUtil.validateListPreference(res, mPrefs, DISPLAY_ORIENTATION, R.string.displayOrientation_default,
            R.array.displayOrientation_values);
    PrefUtil.validateListPreference(res, mPrefs, DISPLAY_POSITION, R.string.displayPosition_default,
            R.array.displayPosition_values);
    PrefUtil.validateListPreference(res, mPrefs, DISPLAY_SCALING, R.string.displayScaling_default,
            R.array.displayScaling_values);
    PrefUtil.validateListPreference(res, mPrefs, VIDEO_HARDWARE_TYPE, R.string.videoHardwareType_default,
            R.array.videoHardwareType_values);
    PrefUtil.validateListPreference(res, mPrefs, AUDIO_PLUGIN, R.string.audioPlugin_default,
            R.array.audioPlugin_values);
    PrefUtil.validateListPreference(res, mPrefs, AUDIO_SDL_BUFFER_SIZE, R.string.audioSDLBufferSize_default,
            R.array.audioSDLBufferSize_values);
    PrefUtil.validateListPreference(res, mPrefs, AUDIO_SLES_BUFFER_SIZE, R.string.audioSLESBufferSize_default,
            R.array.audioSLESBufferSize_values);
    PrefUtil.validateListPreference(res, mPrefs, TOUCHSCREEN_AUTO_HOLD, R.string.touchscreenAutoHold_default,
            R.array.touchscreenAutoHold_values);
    PrefUtil.validateListPreference(res, mPrefs, NAVIGATION_MODE, R.string.navigationMode_default,
            R.array.navigationMode_values);

    if (!mPrefs.getBoolean("seen_survey", false)) {
        LinearLayout dialogLayout = new LinearLayout(this);
        dialogLayout.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
                LinearLayout.LayoutParams.WRAP_CONTENT));
        dialogLayout.setOrientation(LinearLayout.VERTICAL);
        TextView message = new TextView(this);
        message.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
                LinearLayout.LayoutParams.WRAP_CONTENT));
        message.setText("We have recently changed our icon and we want your feedback!\n\n"
                + "Please take a few moments to fill out this feedback form so we can make improvements. "
                + "You will need a Google account to fill out this form. This is so we don't have duplicates.");
        message.setPadding(16, 16, 16, 16);
        dialogLayout.addView(message);/* www .  j  a  v  a  2  s .c  o  m*/
        ImageView icon = new ImageView(this);
        icon.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
                LinearLayout.LayoutParams.WRAP_CONTENT));
        icon.setAdjustViewBounds(true);
        icon.setPadding(16, 16, 16, 16);
        icon.setImageResource(R.drawable.ic_playstore_ouya);
        dialogLayout.addView(icon);
        AlertDialog dialog = new AlertDialog.Builder().setTitle("We want your feedback!").setView(iconLayout)
                .setPositiveButton(getString(android.R.string.ok), new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(
                                "https://docs.google.com/forms/d/1F2stkHvb0Rx5vfmaz50OtTfT73XjHK2GEXZj9a_x-yw/viewform"));
                        SplashActivity.this.startActivity(i);
                    }
                }).setNegativeButton(getString(android.R.string.cancel), null).create();
        mPrefs.edit().putBoolean("seen_survey", true).apply();
        dialog.show();
    }
    //Check for invalid data path
    String dataPathString = mPrefs.getString(DATA_PATH, null);

    if (dataPathString == null || dataPathString.isEmpty()
            || dataPathString.contains(res.getString(R.string.pathGameSaves_default))) {
        String defValue = res.getString(R.string.pathGameSaves_default);
        String newDefValue = PathPreference.validate(defValue);

        mPrefs.edit().putString(DATA_PATH, newDefValue).commit();
    }

    // @formatter:on

    // Refresh the preference data wrapper
    mGlobalPrefs = new GlobalPrefs(this, mAppData);

    // Make sure custom skin directory exist
    new File(mGlobalPrefs.touchscreenCustomSkinsDir).mkdirs();

    // Initialize the OUYA interface if running on OUYA
    if (AppData.IS_OUYA_HARDWARE)
        OuyaFacade.getInstance().init(this, DEVELOPER_ID);

    // Initialize the toast/status bar notifier
    Notifier.initialize(this);

    // Don't let the activity sleep in the middle of extraction
    getWindow().setFlags(LayoutParams.FLAG_KEEP_SCREEN_ON, LayoutParams.FLAG_KEEP_SCREEN_ON);

    // Lay out the content
    setContentView(R.layout.splash_activity);
    mTextView = (TextView) findViewById(R.id.mainText);

    if (mGlobalPrefs.isBigScreenMode) {
        final ImageView splash = (ImageView) findViewById(R.id.mainImage);
        splash.setImageResource(R.drawable.publisherlogo_ouya);
    }

    requestPermissions();

    // Popup a warning if the installation appears to be corrupt
    if (!mAppData.isValidInstallation()) {
        Popups.showInvalidInstall(this);
    }
}