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:fr.cph.chicago.activity.StationActivity.java

@SuppressWarnings("unchecked")
@Override/*from  w ww .j  a  v a2  s.  com*/
protected final void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    ChicagoTracker.checkTrainData(this);
    if (!this.isFinishing()) {
        // Load data
        DataHolder dataHolder = DataHolder.getInstance();
        this.mTrainData = dataHolder.getTrainData();

        mIds = new HashMap<String, Integer>();

        // Load right xml
        setContentView(R.layout.activity_station);

        // Get station id from bundle extra
        if (mStationId == null) {
            mStationId = getIntent().getExtras().getInt("stationId");
        }

        // Get station from station id
        mStation = mTrainData.getStation(mStationId);

        MultiMap<String, String> reqParams = new MultiValueMap<String, String>();
        reqParams.put("mapid", String.valueOf(mStation.getId()));
        new LoadData().execute(reqParams);

        // Call google street api to load image
        new DisplayGoogleStreetPicture().execute(mStation.getStops().get(0).getPosition());

        this.mIsFavorite = isFavorite();

        TextView textView = (TextView) findViewById(R.id.activity_bike_station_station_name);
        textView.setText(mStation.getName().toString());

        mStreetViewImage = (ImageView) findViewById(R.id.activity_bike_station_streetview_image);

        mStreetViewText = (TextView) findViewById(R.id.activity_bike_station_steetview_text);

        mMapImage = (ImageView) findViewById(R.id.activity_bike_station_map_image);

        mDirectionImage = (ImageView) findViewById(R.id.activity_bike_station_map_direction);

        mFavoritesImage = (ImageView) findViewById(R.id.activity_bike_station_favorite_star);
        if (mIsFavorite) {
            mFavoritesImage.setImageDrawable(getResources().getDrawable(R.drawable.ic_save_active));
        }
        mFavoritesImage.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                StationActivity.this.switchFavorite();
            }
        });

        LinearLayout stopsView = (LinearLayout) findViewById(R.id.activity_bike_station_details);

        this.mParamsStop = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);

        Map<TrainLine, List<Stop>> stops = mStation.getStopByLines();
        CheckBox checkBox = null;
        for (Entry<TrainLine, List<Stop>> e : stops.entrySet()) {
            final TrainLine line = e.getKey();
            List<Stop> stopss = e.getValue();
            Collections.sort(stopss);
            LayoutInflater layoutInflater = (LayoutInflater) ChicagoTracker.getAppContext()
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            View view = layoutInflater.inflate(R.layout.activity_station_line_title, null);

            TextView lineTextView = (TextView) view.findViewById(R.id.activity_bus_station_value);
            lineTextView.setText(line.toStringWithLine());

            TextView lineColorTextView = (TextView) view.findViewById(R.id.activity_bus_color);
            lineColorTextView.setBackgroundColor(line.getColor());
            stopsView.addView(view);

            for (final Stop stop : stopss) {
                LinearLayout line2 = new LinearLayout(this);
                line2.setOrientation(LinearLayout.HORIZONTAL);
                line2.setLayoutParams(mParamsStop);

                checkBox = new CheckBox(this);
                checkBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
                    @Override
                    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                        Preferences.saveTrainFilter(mStationId, line, stop.getDirection(), isChecked);
                    }
                });
                checkBox.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        // Update timing
                        MultiMap<String, String> reqParams = new MultiValueMap<String, String>();
                        reqParams.put("mapid", String.valueOf(mStation.getId()));
                        new LoadData().execute(reqParams);
                    }
                });
                checkBox.setChecked(Preferences.getTrainFilter(mStationId, line, stop.getDirection()));
                checkBox.setText(stop.getDirection().toString());
                checkBox.setTextColor(getResources().getColor(R.color.grey));

                line2.addView(checkBox);
                stopsView.addView(line2);

                LinearLayout line3 = new LinearLayout(this);
                line3.setOrientation(LinearLayout.VERTICAL);
                line3.setLayoutParams(mParamsStop);
                int id3 = Util.generateViewId();
                line3.setId(id3);
                mIds.put(line.toString() + "_" + stop.getDirection().toString(), id3);

                stopsView.addView(line3);
            }

        }
        getActionBar().setDisplayHomeAsUpEnabled(true);

        Util.trackScreen(this, R.string.analytics_train_details);
    }
}

From source file:com.utils.widget.head.HeaderFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    final Activity activity = getActivity();
    assert activity != null;
    mFrameLayout = new FrameLayout(activity);

    mHeader = onCreateHeaderView(inflater, mFrameLayout);
    mHeaderHeader = mHeader.findViewById(android.R.id.title);
    mHeaderBackground = mHeader.findViewById(android.R.id.background);
    assert mHeader.getLayoutParams() != null;
    mHeaderHeight = mHeader.getLayoutParams().height;
    mFakeHeader = new Space(activity);
    mFakeHeader.setLayoutParams(new ListView.LayoutParams(0, mHeaderHeight));

    View content = onCreateContentView(inflater, mFrameLayout);
    if (content instanceof ListView) {
        isListViewEmpty = true;/*from   w  w w  .  j a  v  a2s  .  com*/

        final ListView listView = (ListView) content;
        listView.addHeaderView(mFakeHeader);
        listView.setOnScrollListener(new AbsListView.OnScrollListener() {

            @Override
            public void onScrollStateChanged(AbsListView absListView, int scrollState) {
                if (mOnScrollListener != null) {
                    mOnScrollListener.onScrollStateChanged(absListView, scrollState);
                }
            }

            @Override
            public void onScroll(AbsListView absListView, int firstVisibleItem, int visibleItemCount,
                    int totalItemCount) {
                if (mOnScrollListener != null) {
                    mOnScrollListener.onScroll(absListView, firstVisibleItem, visibleItemCount, totalItemCount);
                }

                if (isListViewEmpty) {
                    scrollHeaderTo(0);
                } else {
                    final View child = absListView.getChildAt(0);
                    assert child != null;
                    scrollHeaderTo(child == mFakeHeader ? child.getTop() : -mHeaderHeight);
                }
            }
        });
    } else {

        // Merge fake header view and content view.
        final LinearLayout view = new LinearLayout(activity);
        view.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.MATCH_PARENT));
        view.setOrientation(LinearLayout.VERTICAL);
        view.addView(mFakeHeader);
        view.addView(content);

        // Put merged content to ScrollView
        final NotifyingScrollView scrollView = new NotifyingScrollView(activity);
        scrollView.addView(view);
        scrollView.setOnScrollChangedListener(new NotifyingScrollView.OnScrollChangedListener() {
            @Override
            public void onScrollChanged(ScrollView who, int l, int t, int oldl, int oldt) {
                scrollHeaderTo(-t);
            }
        });
        content = scrollView;
    }

    mFrameLayout.addView(content);
    mFrameLayout.addView(mHeader);

    // Content overlay view always shows at the top of content.
    if ((mContentOverlay = onCreateContentOverlayView(inflater, mFrameLayout)) != null) {
        mFrameLayout.addView(mContentOverlay, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.MATCH_PARENT));
    }

    // Post initial scroll
    mFrameLayout.post(new Runnable() {
        @Override
        public void run() {
            scrollHeaderTo(0, true);
        }
    });

    return mFrameLayout;
}

From source file:com.research.widget.PagerSlidingTabStrip.java

private void addTextTab(final int position, String title) {

    LinearLayout item = new LinearLayout(getContext());
    item.setOrientation(LinearLayout.HORIZONTAL);
    item.setGravity(Gravity.CENTER_HORIZONTAL | Gravity.CENTER_VERTICAL);

    TextView tab = new TextView(getContext());
    tab.setText(title);//from  w  ww  . j  ava2  s .c om
    tab.setGravity(Gravity.CENTER);
    tab.setSingleLine();

    TextView msgTipText = new TextView(getContext());
    msgTipText.setGravity(Gravity.CENTER);
    msgTipText.setTextSize(TypedValue.COMPLEX_UNIT_SP, 10);
    msgTipText.setSingleLine();
    msgTipText.setTextColor(Color.parseColor("#ffffff"));
    if (position != 0) {
        msgTipText.setBackgroundDrawable(getContext().getResources().getDrawable(R.drawable.main_find_icon));
        LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
                FeatureFunction.dip2px(BMapApiApp.getInstance(), 10),
                FeatureFunction.dip2px(BMapApiApp.getInstance(), 10));
        msgTipText.setLayoutParams(params);
    } else {
        msgTipText.setBackgroundDrawable(getContext().getResources().getDrawable(R.drawable.message_count_bg));
    }

    msgTipText.setVisibility(View.GONE);

    item.addView(tab);
    item.addView(msgTipText);

    addTab(position, item);
}

From source file:rdx.andro.forexcapplugins.childBrowser.ChildBrowser.java

/**
 * Display a new browser with the specified URL.
 * /*w  w w .java 2s  . c o m*/
 * @param url
 *            The url to load.
 * @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);

            // 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);

            // 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/childbrowser/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/childbrowser/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/childbrowser/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.setPluginState(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.nextgis.mobile.map.LocalTMSLayer.java

protected static void showPropertiesDialog(final MapBase map, final boolean bCreate, String layerName, int type,
        final Uri uri, final LocalTMSLayer layer) {
    final LinearLayout linearLayout = new LinearLayout(map.getContext());
    final EditText input = new EditText(map.getContext());
    input.setText(layerName);//w ww .ja  v  a  2  s. c  om

    final ArrayAdapter<CharSequence> adapter = new ArrayAdapter<CharSequence>(map.getContext(),
            android.R.layout.simple_spinner_item);
    final Spinner spinner = new Spinner(map.getContext());
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spinner.setAdapter(adapter);

    adapter.add(map.getContext().getString(R.string.tmstype_qtiles));
    adapter.add(map.getContext().getString(R.string.tmstype_osm));
    adapter.add(map.getContext().getString(R.string.tmstype_normal));
    adapter.add(map.getContext().getString(R.string.tmstype_ngw));

    if (type == TMSTYPE_OSM) {
        spinner.setSelection(1);
    } else {
        spinner.setSelection(2);
    }

    final TextView stLayerName = new TextView(map.getContext());
    stLayerName.setText(map.getContext().getString(R.string.layer_name) + ":");

    final TextView stLayerType = new TextView(map.getContext());
    stLayerType.setText(map.getContext().getString(R.string.layer_type) + ":");

    linearLayout.setOrientation(LinearLayout.VERTICAL);
    linearLayout.addView(stLayerName);
    linearLayout.addView(input);
    linearLayout.addView(stLayerType);
    linearLayout.addView(spinner);

    new AlertDialog.Builder(map.getContext())
            .setTitle(bCreate ? R.string.input_layer_properties : R.string.change_layer_properties)
            //                                    .setMessage(message)
            .setView(linearLayout).setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {
                    int tmsType = 0;
                    switch (spinner.getSelectedItemPosition()) {
                    case 0:
                    case 1:
                        tmsType = TMSTYPE_OSM;
                        break;
                    case 2:
                    case 3:
                        tmsType = TMSTYPE_NORMAL;
                        break;
                    }

                    if (bCreate) {
                        create(map, input.getText().toString(), tmsType, uri);
                    } else {
                        layer.setName(input.getText().toString());
                        layer.setTMSType(tmsType);
                        map.onLayerChanged(layer);
                    }
                }
            }).setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {
                    // Do nothing.
                    Toast.makeText(map.getContext(), R.string.error_cancel_by_user, Toast.LENGTH_SHORT).show();
                }
            }).show();
}

From source file:ca.appvelopers.mcgillmobile.ui.ScheduleActivity.java

/**
 * Renders the landscape view//from ww w.  j  a v a 2  s.  co  m
 */
private void renderLandscapeView() {
    //Make sure that the necessary views are present in the layout
    Assert.assertNotNull(timetableContainer);
    Assert.assertNotNull(scheduleContainer);

    //Leave space at the top for the day names
    View dayView = View.inflate(this, R.layout.fragment_day_name, null);
    //Black line to separate the timetable from the schedule
    View dayViewLine = dayView.findViewById(R.id.day_line);
    dayViewLine.setVisibility(View.VISIBLE);

    //Add the day view to the top of the timetable
    timetableContainer.addView(dayView);

    //Find the index of the given date
    int currentDayIndex = date.getDayOfWeek().getValue();

    //Go through the 7 days of the week
    for (int i = 1; i < 8; i++) {
        DayOfWeek day = DayOfWeek.of(i);

        //Set up the day name
        dayView = View.inflate(this, R.layout.fragment_day_name, null);
        TextView dayViewTitle = (TextView) dayView.findViewById(R.id.day_name);
        dayViewTitle.setText(DayUtils.getString(this, day));
        scheduleContainer.addView(dayView);

        //Set up the schedule container for that one day
        LinearLayout scheduleContainer = new LinearLayout(this);
        scheduleContainer.setOrientation(LinearLayout.VERTICAL);
        scheduleContainer.setLayoutParams(new LinearLayout.LayoutParams(
                getResources().getDimensionPixelSize(R.dimen.cell_landscape_width),
                ViewGroup.LayoutParams.WRAP_CONTENT));

        //Fill the schedule for the current day
        fillSchedule(this.timetableContainer, scheduleContainer, date.plusDays(i - currentDayIndex), false);

        //Add the current day to the schedule container
        this.scheduleContainer.addView(scheduleContainer);

        //Line
        View line = new View(this);
        line.setBackgroundColor(Color.BLACK);
        line.setLayoutParams(
                new ViewGroup.LayoutParams(getResources().getDimensionPixelSize(R.dimen.schedule_line),
                        ViewGroup.LayoutParams.MATCH_PARENT));
        this.scheduleContainer.addView(line);
    }
}

From source file:com.nextgis.mobile.map.RemoteTMSLayer.java

protected static void showPropertiesDialog(final MapBase map, final boolean bCreate, String layerName,
        String layerUrl, int type, final RemoteTMSLayer layer) {
    final LinearLayout linearLayout = new LinearLayout(map.getContext());
    final EditText input = new EditText(map.getContext());
    input.setText(layerName);//from w w w . ja  v a 2 s  .  c o  m

    final EditText url = new EditText(map.getContext());
    url.setText(layerUrl);

    final TextView stLayerName = new TextView(map.getContext());
    stLayerName.setText(map.getContext().getString(R.string.layer_name) + ":");

    final TextView stLayerUrl = new TextView(map.getContext());
    stLayerUrl.setText(map.getContext().getString(R.string.layer_url) + ":");

    final TextView stLayerType = new TextView(map.getContext());
    stLayerType.setText(map.getContext().getString(R.string.layer_type) + ":");

    final ArrayAdapter<CharSequence> adapter = new ArrayAdapter<CharSequence>(map.getContext(),
            android.R.layout.simple_spinner_item);
    final Spinner spinner = new Spinner(map.getContext());
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spinner.setAdapter(adapter);

    adapter.add(map.getContext().getString(R.string.tmstype_osm));
    adapter.add(map.getContext().getString(R.string.tmstype_normal));
    adapter.add(map.getContext().getString(R.string.tmstype_ngw));

    if (type == TMSTYPE_OSM) {
        spinner.setSelection(0);
    } else {
        spinner.setSelection(1);
    }

    linearLayout.setOrientation(LinearLayout.VERTICAL);
    linearLayout.addView(stLayerName);
    linearLayout.addView(input);
    linearLayout.addView(stLayerUrl);
    linearLayout.addView(url);
    linearLayout.addView(stLayerType);
    linearLayout.addView(spinner);

    new AlertDialog.Builder(map.getContext())
            .setTitle(bCreate ? R.string.input_layer_properties : R.string.change_layer_properties)
            //                                    .setMessage(message)
            .setView(linearLayout).setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {
                    int tmsType = 0;
                    switch (spinner.getSelectedItemPosition()) {
                    case 0:
                    case 1:
                        tmsType = TMSTYPE_OSM;
                        break;
                    case 2:
                    case 3:
                        tmsType = TMSTYPE_NORMAL;
                        break;
                    }

                    if (bCreate) {
                        create(map, input.getText().toString(), url.getText().toString(), tmsType);
                    } else {
                        layer.setName(input.getText().toString());
                        layer.setTMSType(tmsType);
                        map.onLayerChanged(layer);
                    }
                }
            }).setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {
                    // Do nothing.
                    Toast.makeText(map.getContext(), R.string.error_cancel_by_user, Toast.LENGTH_SHORT).show();
                }
            }).show();
}

From source file:com.taobao.weex.extend.module.actionsheet.WXActionSheet.java

private void ensureTitle() {
    if (!TextUtils.isEmpty(titleText) || !TextUtils.isEmpty(messageText)) {
        LinearLayout titleContainer = new LinearLayout(getActivity());
        titleContainer.setOrientation(LinearLayout.VERTICAL);
        titleContainer.setGravity(Gravity.CENTER);
        titleContainer.setBackgroundColor(Color.WHITE);
        titleContainer/*from   www  .jav a  2s .co m*/
                .setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, dp2px(56)));

        if (!TextUtils.isEmpty(titleText)) {
            TextView title = new TextView(getActivity());
            title.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                    ViewGroup.LayoutParams.WRAP_CONTENT));
            title.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
            title.setText(titleText);
            title.setGravity(Gravity.CENTER_HORIZONTAL);
            title.setTextColor(COLOR_TITLE);
            title.getPaint().setFakeBoldText(true);
            titleContainer.addView(title);
        }

        if (!TextUtils.isEmpty(messageText)) {
            TextView message = new TextView(getActivity());
            message.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                    ViewGroup.LayoutParams.WRAP_CONTENT));
            message.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 12);
            message.setGravity(Gravity.CENTER_HORIZONTAL);
            message.setText(messageText);
            message.setTextColor(COLOR_TITLE);
            titleContainer.addView(message);
        }

        titleContainer.setClickable(true);
        titleContainer.setFocusableInTouchMode(true);

        sheetContainer.addView(titleContainer);
        sheetContainer.addView(createLine());
    }
}

From source file:com.microsoft.windowsazure.mobileservices.authentication.LoginManager.java

/**
 * Creates the UI for the interactive authentication process
 *
 * @param startUrl The initial URL for the authentication process
 * @param endUrl   The final URL for the authentication process
 * @param context  The context used to create the authentication dialog
 * @param callback Callback to invoke when the authentication process finishes
 *//*ww  w .jav  a  2s .c o m*/
private void showLoginUIInternal(final String startUrl, final String endUrl, final Context context,
        LoginUIOperationCallback callback) {
    if (startUrl == null || startUrl == "") {
        throw new IllegalArgumentException("startUrl can not be null or empty");
    }

    if (endUrl == null || endUrl == "") {
        throw new IllegalArgumentException("endUrl can not be null or empty");
    }

    if (context == null) {
        throw new IllegalArgumentException("context can not be null");
    }

    final LoginUIOperationCallback externalCallback = callback;
    final AlertDialog.Builder builder = new AlertDialog.Builder(context);
    // Create the Web View to show the login page
    final WebView wv = new WebView(context);
    builder.setOnCancelListener(new DialogInterface.OnCancelListener() {

        @Override
        public void onCancel(DialogInterface dialog) {
            if (externalCallback != null) {
                externalCallback.onCompleted(null, new MobileServiceException("User Canceled"));
            }
        }
    });

    wv.getSettings().setJavaScriptEnabled(true);

    DisplayMetrics displaymetrics = new DisplayMetrics();
    ((Activity) context).getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
    int webViewHeight = displaymetrics.heightPixels - 100;

    wv.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, webViewHeight));

    wv.requestFocus(View.FOCUS_DOWN);
    wv.setOnTouchListener(new View.OnTouchListener() {

        @Override
        public boolean onTouch(View view, MotionEvent event) {
            int action = event.getAction();
            if (action == MotionEvent.ACTION_DOWN || action == MotionEvent.ACTION_UP) {
                if (!view.hasFocus()) {
                    view.requestFocus();
                }
            }

            return false;
        }
    });

    // Create a LinearLayout and add the WebView to the Layout
    LinearLayout layout = new LinearLayout(context);
    layout.setOrientation(LinearLayout.VERTICAL);
    layout.addView(wv);

    // Add a dummy EditText to the layout as a workaround for a bug
    // that prevents showing the keyboard for the WebView on some devices
    EditText dummyEditText = new EditText(context);
    dummyEditText.setVisibility(View.GONE);
    layout.addView(dummyEditText);

    // Add the layout to the dialog
    builder.setView(layout);

    final AlertDialog dialog = builder.create();

    wv.setWebViewClient(new WebViewClient() {

        @Override
        public void onPageStarted(WebView view, String url, Bitmap favicon) {
            // If the URL of the started page matches with the final URL
            // format, the login process finished

            if (isFinalUrl(url)) {
                if (externalCallback != null) {
                    externalCallback.onCompleted(url, null);
                }

                dialog.dismiss();
            }

            super.onPageStarted(view, url, favicon);
        }

        // Checks if the given URL matches with the final URL's format
        private boolean isFinalUrl(String url) {
            if (url == null) {
                return false;
            }

            return url.startsWith(endUrl);
        }

        // Checks if the given URL matches with the start URL's format
        private boolean isStartUrl(String url) {
            if (url == null) {
                return false;
            }

            return url.startsWith(startUrl);
        }

        @Override
        public void onPageFinished(WebView view, String url) {
            if (isStartUrl(url)) {
                if (externalCallback != null) {
                    externalCallback.onCompleted(null, new MobileServiceException(
                            "Logging in with the selected authentication provider is not enabled"));
                }

                dialog.dismiss();
            }
        }
    });

    wv.loadUrl(startUrl);
    dialog.show();
}

From source file:com.yktx.check.widget.OldPagerSlidingTabStrip.java

private void addIconAndTextTab(final int position, int resId, String title) {
    LinearLayout layout = new LinearLayout(getContext());
    layout.setGravity(Gravity.CENTER);/*from w w w.  j  av a 2 s .  c o  m*/
    layout.setOrientation(LinearLayout.VERTICAL);
    ImageView tabImage = new ImageView(getContext());
    tabImage.setImageResource(resId);
    tabImage.setId(R.id.image);
    TextView tabText = new TextView(getContext());
    tabText.setText(title);
    tabText.setSingleLine();
    tabText.setId(R.id.text);
    tabText.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
    tabText.setGravity(Gravity.CENTER_HORIZONTAL);
    tabText.setPadding(0, 3, 0, 0);
    layout.addView(tabImage);
    layout.addView(tabText);

    addTab(position, layout);

}