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.hichinaschool.flashcards.anki.multimediacard.activity.TranslationActivity.java

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

    if (savedInstanceState != null) {
        boolean b = savedInstanceState.getBoolean(BUNDLE_KEY_SHUT_OFF, false);
        if (b) {//  ww  w .jav  a  2 s  . c  o  m
            finishCancel();
            return;
        }
    }

    setContentView(R.layout.activity_translation);

    try {
        mSource = getIntent().getExtras().getString(EXTRA_SOURCE).toString();
    } catch (Exception e) {
        mSource = "";
    }

    // If translation fails this is a default - source will be returned.
    mTranslation = mSource;

    LinearLayout linearLayout = (LinearLayout) findViewById(R.id.MainLayoutInTranslationActivity);

    TextView tv = new TextView(this);
    tv.setText(getText(R.string.multimedia_editor_trans_poweredglosbe));
    linearLayout.addView(tv);

    TextView tvFrom = new TextView(this);
    tvFrom.setText(getText(R.string.multimedia_editor_trans_from));
    linearLayout.addView(tvFrom);

    mLanguageLister = new LanguagesListerGlosbe(this);

    mSpinnerFrom = new Spinner(this);
    ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item,
            mLanguageLister.getLanguages());
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    mSpinnerFrom.setAdapter(adapter);
    linearLayout.addView(mSpinnerFrom);

    TextView tvTo = new TextView(this);
    tvTo.setText(getText(R.string.multimedia_editor_trans_to));
    linearLayout.addView(tvTo);

    mSpinnerTo = new Spinner(this);
    ArrayAdapter<String> adapterTo = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item,
            mLanguageLister.getLanguages());
    adapterTo.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    mSpinnerTo.setAdapter(adapterTo);
    linearLayout.addView(mSpinnerTo);

    Button btnDone = new Button(this);
    btnDone.setText(getText(R.string.multimedia_editor_trans_translate));
    btnDone.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            translate();
        }
    });

    linearLayout.addView(btnDone);

}

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

/**
 * Creates the UI for the interactive authentication process
 * /*from w ww  . ja v a  2 s. c om*/
 * @param provider
 *            The provider used for the 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
 */
private void showLoginUI(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;

    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:org.mifos.androidclient.main.CustomerDetailsActivity.java

private void updateContent(CustomerDetailsEntity details) {
    if (details != null) {
        mDetails = details;/*ww w . java  2s  .  co m*/
        LinearLayout tabContent = (LinearLayout) findViewById(R.id.customer_overview);
        ViewBuilderFactory factory = new ViewBuilderFactory(this);
        CustomerDetailsViewBuilder builder = factory.createCustomerDetailsViewBuilder(details);
        View view;

        if (tabContent.getChildCount() > 0) {
            tabContent.removeAllViews();
        }
        tabContent.addView(builder.buildOverviewView());

        tabContent = (LinearLayout) findViewById(R.id.customer_accounts);
        if (tabContent.getChildCount() > 0) {
            tabContent.removeAllViews();
        }
        view = builder.buildAccountsView();
        setupAccountsListListeners(view);
        tabContent.addView(view);

        tabContent.addView(builder.buildAccountsView());

        tabContent = (LinearLayout) findViewById(R.id.customer_additional);
        if (tabContent.getChildCount() > 0) {
            tabContent.removeAllViews();
        }
        tabContent.addView(builder.buildAdditionalView());
    }
}

From source file:com.neuron.fantecremote.FantecActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.navigate);//from ww  w .ja  va  2 s . com
    prefs = getSharedPreferences("fantecremote", 0);

    /*
     * Setup toolbar
     */
    actionBar = (ActionBar) findViewById(R.id.actionbar);
    // You can also assign the title programmatically by passing a
    // CharSequence or resource id.
    //actionBar.setTitle(R.string.some_title);
    //actionBar.setHomeAction(new IntentAction(this, HomeActivity.createIntent(this), R.drawable.ic_title_home_default));
    actionBar.setTitle("Fantec Remote");
    actionBar.addAction(new SettingsAction());

    // Look up the AdView as a resource and load a request.
    /*AdView adView = (AdView)this.findViewById(R.id.adView);
    adView.loadAd(new AdRequest());*/
    // Create the adView
    AdView adView = new AdView(this, AdSize.BANNER, "a14dd8d8827bacc");
    // Lookup your LinearLayout assuming its been given
    // the attribute android:id="@+id/mainLayout"
    LinearLayout layout = (LinearLayout) findViewById(R.id.mainLayout);
    // Add the adView to it
    //layout.addView(adView, new LayoutParams())
    layout.addView(adView);
    // Initiate a generic request to load it with an ad
    AdRequest adRequest = new AdRequest();
    //adRequest.addTestDevice("F7C9180F318B9F36622B5A61C79AD7BF");
    adView.loadAd(adRequest);
    //adView.setGravity(Gravity.BOTTOM | Gravity.CENTER);

    /*if (Settings.GetApiUrl(prefs) == null) {
      Intent i = new Intent(this, Settings.class);
      startActivityForResult(i, Intent.FLAG_ACTIVITY_CLEAR_TOP);
    } */

    ImageButton button = (ImageButton) findViewById(R.id.imageButton1);
    button.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            send("CMD_GUIDE");
        }
    });

    button = (ImageButton) findViewById(R.id.imageButton2);
    button.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            send("CMD_UP");
        }
    });

    button = (ImageButton) findViewById(R.id.imageButton3);
    button.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            send("CMD_RETURN");
        }
    });

    button = (ImageButton) findViewById(R.id.imageButton4);
    button.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            send("CMD_LEFT");
        }
    });

    button = (ImageButton) findViewById(R.id.imageButton5);
    button.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            send("CMD_SELECT");
        }
    });

    button = (ImageButton) findViewById(R.id.imageButton6);
    button.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            send("CMD_RIGHT");
        }
    });

    button = (ImageButton) findViewById(R.id.imageButton7);
    button.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            send("CMD_EDIT");
        }
    });

    button = (ImageButton) findViewById(R.id.imageButton8);
    button.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            send("CMD_DOWN");
        }
    });

    button = (ImageButton) findViewById(R.id.imageButton9);
    button.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            send("CMD_SETUP");
        }
    });

    /** The playback controls */

    button = (ImageButton) findViewById(R.id.imageButton10);
    button.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            send("CMD_STOP");
        }
    });

    button = (ImageButton) findViewById(R.id.imageButton11);
    button.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            send("CMD_MELE_PLAYPAUSE");
        }
    });

    button = (ImageButton) findViewById(R.id.imageButton12);
    button.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            send("CMD_DISPLAY");
        }
    });

    button = (ImageButton) findViewById(R.id.imageButton13);
    button.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            send("CMD_FRWD");
        }
    });

    button = (ImageButton) findViewById(R.id.imageButton14);
    button.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            send("CMD_FFWD");
        }
    });

    button = (ImageButton) findViewById(R.id.imageButton15);
    button.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            send("CMD_STITLE");
        }
    });

    button = (ImageButton) findViewById(R.id.imageButton16);
    button.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            send("CMD_PREV");
        }
    });

    button = (ImageButton) findViewById(R.id.imageButton17);
    button.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            send("CMD_NEXT");
        }
    });

    button = (ImageButton) findViewById(R.id.imageButton18);
    button.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            send("CMD_MUTE");
        }
    });
}

From source file:com.ichi2.anki.multimediacard.activity.TranslationActivity.java

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

    if (savedInstanceState != null) {
        boolean b = savedInstanceState.getBoolean(BUNDLE_KEY_SHUT_OFF, false);
        if (b) {// w  ww  .  j a v  a 2s .  c o  m
            finishCancel();
            return;
        }
    }

    setContentView(R.layout.activity_translation);

    try {
        mSource = getIntent().getExtras().getString(EXTRA_SOURCE).toString();
    } catch (Exception e) {
        mSource = "";
    }

    // If translation fails this is a default - source will be returned.
    mTranslation = mSource;

    LinearLayout linearLayout = (LinearLayout) findViewById(R.id.MainLayoutInTranslationActivity);

    TextView tv = new TextView(this);
    tv.setText(getText(R.string.multimedia_editor_trans_poweredglosbe));
    linearLayout.addView(tv);

    TextView tvFrom = new TextView(this);
    tvFrom.setText(getText(R.string.multimedia_editor_trans_from));
    linearLayout.addView(tvFrom);

    mLanguageLister = new LanguagesListerGlosbe(this);

    mSpinnerFrom = new Spinner(this);
    ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item,
            mLanguageLister.getLanguages());
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    mSpinnerFrom.setAdapter(adapter);
    linearLayout.addView(mSpinnerFrom);

    TextView tvTo = new TextView(this);
    tvTo.setText(getText(R.string.multimedia_editor_trans_to));
    linearLayout.addView(tvTo);

    mSpinnerTo = new Spinner(this);
    ArrayAdapter<String> adapterTo = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item,
            mLanguageLister.getLanguages());
    adapterTo.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    mSpinnerTo.setAdapter(adapterTo);
    linearLayout.addView(mSpinnerTo);

    final SharedPreferences preferences = AnkiDroidApp.getSharedPrefs(getBaseContext());

    // Try to set spinner value to last selected position
    String fromLang = preferences.getString("translatorLastLanguageFrom", "");
    String toLang = preferences.getString("translatorLastLanguageTo", "");
    mSpinnerFrom.setSelection(getSpinnerIndex(mSpinnerFrom, fromLang));
    mSpinnerTo.setSelection(getSpinnerIndex(mSpinnerTo, toLang));
    // Setup button
    Button btnDone = new Button(this);
    btnDone.setText(getText(R.string.multimedia_editor_trans_translate));
    btnDone.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            // Remember currently selected language
            String fromLang = mSpinnerFrom.getSelectedItem().toString();
            String toLang = mSpinnerTo.getSelectedItem().toString();
            preferences.edit().putString("translatorLastLanguageFrom", fromLang).commit();
            preferences.edit().putString("translatorLastLanguageTo", toLang).commit();
            // Get translation
            translate();
        }
    });

    linearLayout.addView(btnDone);

}

From source file:com.fuse.qreader.BarcodeCaptureActivity.java

/**
 * Initializes the UI and creates the detector pipeline.
 */// w w  w . ja va  2 s .  c o m
@Override
public void onCreate(Bundle icicle) {

    super.onCreate(icicle);

    LinearLayout linLayout = new LinearLayout(this);
    linLayout.setOrientation(LinearLayout.VERTICAL);
    LayoutParams linLayoutParam = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
    mPreview = new CameraSourcePreview(this);
    mGraphicOverlay = new GraphicOverlay<BarcodeGraphic>(this);
    mPreview.addView(mGraphicOverlay);
    linLayout.addView(mPreview);

    setContentView(linLayout, linLayoutParam);

    // Check for the camera permission before accessing the camera.  If the
    // permission is not granted yet, request permission.
    int rc = ActivityCompat.checkSelfPermission(this, Manifest.permission.CAMERA);
    if (rc == PackageManager.PERMISSION_GRANTED) {
        createCameraSource(true);
    } else {
        requestCameraPermission();
    }

}

From source file:info.semanticsoftware.semassist.android.activity.SemanticAssistantsActivity.java

/** Attaches a click listener to the list of available assistants. 
 * Upon selecting an assistant from the list, it shows additional information
 * about the assistants in a new layout.
 * @param list list of available assistants
 * @param view view// ww  w . j av  a  2 s.  c o  m
 * @param position position of the selected item
 * @param id id of the selected item
 */
@Override
protected void onListItemClick(ListView list, View view, int position, long id) {
    list.setVisibility(View.GONE);
    lblAvAssist.setVisibility(View.GONE);
    LinearLayout linearLayout = (LinearLayout) findViewById(R.id.servicesLayout);
    selectedService = (String) list.getItemAtPosition(position);
    linearLayout.addView(getServiceDescLayout());
}

From source file:com.androcast.illusion.illusionmod.fragments.PathReaderFragment.java

private void showDialog(final String file, String value) {
    LinearLayout layout = new LinearLayout(getActivity());
    layout.setPadding(30, 30, 30, 30);/*from   w w  w .  ja v  a2  s  .  com*/

    final EditText editText = new EditText(getActivity());
    editText.setGravity(Gravity.CENTER);
    editText.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));
    if (!Utils.DARKTHEME)
        editText.setTextColor(getResources().getColor(R.color.black));
    editText.setText(value);

    layout.addView(editText);

    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    builder.setView(layout)
            .setNegativeButton(getString(R.string.cancel), new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                }
            }).setPositiveButton(getString(R.string.ok), new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    Control.runCommand(editText.getText().toString(), file, Control.CommandType.GENERIC,
                            getActivity());
                    refreshLayout.setRefreshing(true);
                    getHandler().postDelayed(refresh, 500);
                }
            }).show();
}

From source file:com.ess.tudarmstadt.de.sleepsense.mgraph.SleepEstimGPlotFragment.java

private void createGraph(String graphTitle, GraphViewSeries series, final int Rid, boolean isBarChart) {
    GraphView graphView = null;/*from w w w. ja v  a 2  s .  c  o  m*/

    if (isBarChart) {
        graphView = new BarGraphView(getActivity().getApplicationContext(), graphTitle);
        // ((BarGraphView) graphView).setColWidth(1.09f);
        // graphView.setVerticalLabels(new String[] { "high", "mid", "low"
        // });
        // graphView.setManualYAxisBounds(11.0d, 9.0d);
    } else {
        graphView = new LineGraphView(getActivity().getApplicationContext(), graphTitle);

    }
    // add data
    graphView.addSeries(series);
    // graphView.setScrollable(true);
    // graphView.setViewPort(0, 23);
    // optional - activate scaling / zooming
    // graphView.setScalable(true);
    // optional - legend
    // graphView.setShowLegend(true);

    graphView.setCustomLabelFormatter(new CustomLabelFormatter() {
        @Override
        public String formatLabel(double axis_value, boolean isValueX) {
            if (isValueX) {
                // X-Axis
                // decompose x_axis from adding up before
                double value = axis_value;
                if (axis_value >= 200) {
                    value = axis_value - 200;
                } else if (axis_value >= 100)
                    value = axis_value - 100;

                // convert (double) hour.mm to hour:mm
                // make sure not have smth like 4:60 or 11:83 in the time frame!
                double whole = value;
                double fractionalPart = value % 1;
                double integralPart = value - fractionalPart;
                if (fractionalPart >= 0.60) {
                    whole = integralPart + 1.0d + (fractionalPart - 0.60);
                }

                return new DecimalFormat("00.00").format(whole).replaceAll("\\,", ":");
            } else {
                // Y-Axis
                return ""; //new DecimalFormat("#0.0").format(axis_value);
            }
        }
    });

    graphView.getGraphViewStyle().setNumVerticalLabels(4);
    graphView.getGraphViewStyle().setNumHorizontalLabels(0); //AUTO
    graphView.getGraphViewStyle().setTextSize(17f);
    graphView.getGraphViewStyle().setVerticalLabelsAlign(Align.CENTER);
    graphView.getGraphViewStyle().setVerticalLabelsWidth(0);
    graphView.getGraphViewStyle().setGridColor(Color.WHITE);

    LinearLayout layout = (LinearLayout) rootView.findViewById(Rid);
    layout.removeAllViews();
    layout.addView(graphView);
    rootView.postInvalidate();
    layout.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            openBig();
        }
    });

}

From source file:com.example.drugsformarinemammals.ViewPager_Pinnipeds.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);/*  w w  w.j av  a 2s . c o m*/
    title.setTextColor(getResources().getColor(R.color.blue));
    title.setPadding(8, 8, 8, 8);
    title.setText("");
    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();

}