List of usage examples for android.widget LinearLayout setOrientation
public void setOrientation(@OrientationMode int orientation)
From source file:org.yammp.dialog.SleepTimerDialog.java
@Override public void onCreate(Bundle icicle) { super.onCreate(icicle); mUtils = ((YAMMPApplication) getApplication()).getMediaUtils(); setContentView(new LinearLayout(this)); DisplayMetrics dm = new DisplayMetrics(); dm = getResources().getDisplayMetrics(); action = getIntent().getAction();//from w w w . ja v a 2 s . c om mSleepTimerDialog = new AlertDialog.Builder(this).create(); mSleepTimerDialog.setVolumeControlStream(AudioManager.STREAM_MUSIC); mRemained = (int) mUtils.getSleepTimerRemained() / 1000 / 60; LinearLayout mContainer = new LinearLayout(this); mContainer.setOrientation(LinearLayout.VERTICAL); mContainer.setPadding((int) dm.density * 8, 0, (int) dm.density * 8, 0); mTimeView = new TextView(this); mContainer.addView(mTimeView); mSetTime = new SeekBar(this); mSetTime.setMax(120); mContainer.addView(mSetTime); if (mRemained > 0) { mSetTime.setProgress(mRemained); } else { mSetTime.setProgress(30); } mSetTime.setOnSeekBarChangeListener(this); mProgress = mSetTime.getProgress(); mTimerTime = mProgress; if (mTimerTime >= 1) { mPrompt = SleepTimerDialog.this.getResources().getQuantityString(R.plurals.NNNminutes, mTimerTime, mTimerTime); } else { mPrompt = SleepTimerDialog.this.getResources().getString(R.string.disabled); } mTimeView.setText(mPrompt); if (INTENT_SLEEP_TIMER.equals(action)) { mSleepTimerDialog.setIcon(android.R.drawable.ic_dialog_info); mSleepTimerDialog.setTitle(R.string.set_time); mSleepTimerDialog.setView(mContainer); mSleepTimerDialog.setButton(Dialog.BUTTON_POSITIVE, getString(android.R.string.ok), new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { if (mTimerTime >= 1) { long milliseconds = mTimerTime * 60 * 1000; boolean gentle = new PreferencesEditor(getApplicationContext()) .getBooleanPref(KEY_GENTLE_SLEEPTIMER, true); mUtils.startSleepTimer(milliseconds, gentle); } else { mUtils.stopSleepTimer(); } finish(); } }); mSleepTimerDialog.setButton(Dialog.BUTTON_NEGATIVE, getString(android.R.string.cancel), new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { finish(); } }); mSleepTimerDialog.setOnCancelListener(new OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { finish(); } }); } else { Toast.makeText(this, R.string.error_bad_parameters, Toast.LENGTH_SHORT).show(); finish(); } }
From source file:net.peterkuterna.android.apps.devoxxfrsched.ui.ProgressFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { final Context context = getActivity(); FrameLayout root = new FrameLayout(context); LinearLayout pframe = new LinearLayout(context); pframe.setId(INTERNAL_PROGRESS_CONTAINER_ID); pframe.setOrientation(LinearLayout.VERTICAL); pframe.setVisibility(View.GONE); pframe.setGravity(Gravity.CENTER);/* w w w . j a v a 2 s . com*/ ProgressBar progress = new ProgressBar(context, null, android.R.attr.progressBarStyleLarge); pframe.addView(progress, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT)); root.addView(pframe, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT)); FrameLayout cframe = new FrameLayout(context); cframe.setId(INTERNAL_CONTENT_CONTAINER_ID); TextView tv = new TextView(context); tv.setId(INTERNAL_EMPTY_ID); tv.setGravity(Gravity.CENTER); cframe.addView(tv, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT)); View contentView = onCreateContentView(inflater, cframe, savedInstanceState); cframe.addView(contentView, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT)); root.addView(cframe, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT)); root.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT)); return root; }
From source file:com.google.android.car.kitchensink.input.InputTestFragment.java
private void addButtonsToPanel(LinearLayout root, List<View> buttons) { LinearLayout panel = null; for (View button : buttons) { if (button == BREAK_LINE || panel == null) { panel = new LinearLayout(getContext()); panel.setOrientation(LinearLayout.HORIZONTAL); root.addView(panel);// w w w . j ava 2s . c o m } else { panel.addView(button); } } }
From source file:me.diskstation.ammon.gpsrunner.ui.RunDetailsFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Inflate the layout for this fragment View view = inflater.inflate(R.layout.fragment_run_details, container, false); context = getActivity();//from www.j a va 2s . c o m //Get all Layouts LinearLayout distanceLayout = (LinearLayout) view.findViewById(R.id.distanceLayout); LinearLayout timeIntervalLayout = (LinearLayout) view.findViewById(R.id.intervalLayout); LinearLayout maxVelocityLayout = (LinearLayout) view.findViewById(R.id.maxVelocityLayout); LinearLayout avgVelocityLayout = (LinearLayout) view.findViewById(R.id.avgVelocityLayout); LinearLayout ascentLayout = (LinearLayout) view.findViewById(R.id.ascIntervalLayout); LinearLayout descentLayout = (LinearLayout) view.findViewById(R.id.descIntervalLayout); LinearLayout breakTimeLayout = (LinearLayout) view.findViewById(R.id.totalBreakLayout); //Generate all the value layouts LinearLayout distanceValueLayout = new LinearLayout(context); distanceValueLayout.setOrientation(LinearLayout.VERTICAL); distanceLayout.addView(distanceValueLayout); LinearLayout timeIntervalValueLayout = new LinearLayout(context); timeIntervalValueLayout.setOrientation(LinearLayout.VERTICAL); timeIntervalLayout.addView(timeIntervalValueLayout); LinearLayout maxVelocityValueLayout = new LinearLayout(context); maxVelocityValueLayout.setOrientation(LinearLayout.VERTICAL); maxVelocityLayout.addView(maxVelocityValueLayout); LinearLayout avgVelocityValueLayout = new LinearLayout(context); avgVelocityValueLayout.setOrientation(LinearLayout.VERTICAL); avgVelocityLayout.addView(avgVelocityValueLayout); LinearLayout ascentValueLayout = new LinearLayout(context); ascentValueLayout.setOrientation(LinearLayout.VERTICAL); ascentLayout.addView(ascentValueLayout); LinearLayout descentValueLayout = new LinearLayout(context); descentValueLayout.setOrientation(LinearLayout.VERTICAL); descentLayout.addView(descentValueLayout); LinearLayout breakTimeValueLayout = new LinearLayout(context); breakTimeValueLayout.setOrientation(LinearLayout.VERTICAL); breakTimeLayout.addView(breakTimeValueLayout); //populate Layouts with TextViews and values for (int i = 0; i < runs.size(); i++) { Run run = runs.get(i); //set up all TextViews TextView distanceView = new TextView(context); distanceView.setText(vf.formatDistance(run.distance)); setUpTextView(distanceView, i); TextView timeIntervalView = new TextView(context); timeIntervalView.setText(vf.formatTimeInterval(run.timeInterval)); setUpTextView(timeIntervalView, i); TextView maxVelocityView = new TextView(context); maxVelocityView.setText(vf.formatVelocity(run.maxVelocity)); setUpTextView(maxVelocityView, i); TextView avgVelocityView = new TextView(context); avgVelocityView.setText(vf.formatVelocity(run.medVelocity)); setUpTextView(avgVelocityView, i); TextView ascentView = new TextView(context); ascentView.setText(vf.formatDistance(run.ascendInterval)); setUpTextView(ascentView, i); TextView descentView = new TextView(context); descentView.setText(vf.formatDistance(run.descendInterval)); setUpTextView(descentView, i); TextView breakView = new TextView(context); breakView.setText(vf.formatTimeInterval(run.breakTime)); setUpTextView(breakView, i); //add TextViews to value layouts distanceValueLayout.addView(distanceView); timeIntervalValueLayout.addView(timeIntervalView); maxVelocityValueLayout.addView(maxVelocityView); avgVelocityValueLayout.addView(avgVelocityView); ascentValueLayout.addView(ascentView); descentValueLayout.addView(descentView); breakTimeValueLayout.addView(breakView); } return view; }
From source file:net.abcdroid.devfest12.ui.tablet.MapMultiPaneActivity.java
@Override public void onConfigurationChanged(Configuration newConfig) { super.onConfigurationChanged(newConfig); boolean landscape = (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE); LinearLayout spacerView = (LinearLayout) findViewById(R.id.map_detail_spacer); spacerView.setOrientation(landscape ? LinearLayout.HORIZONTAL : LinearLayout.VERTICAL); spacerView.setGravity(landscape ? Gravity.RIGHT : Gravity.BOTTOM); View popupView = findViewById(R.id.map_detail_popup); LinearLayout.LayoutParams popupLayoutParams = (LinearLayout.LayoutParams) popupView.getLayoutParams(); popupLayoutParams.width = landscape ? 0 : ViewGroup.LayoutParams.MATCH_PARENT; popupLayoutParams.height = landscape ? ViewGroup.LayoutParams.MATCH_PARENT : 0; popupView.setLayoutParams(popupLayoutParams); popupView.requestLayout();/* w w w . j ava2 s. co m*/ }
From source file:com.geecko.QuickLyric.AboutActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this); int[] themes = new int[] { R.style.Theme_QuickLyric, R.style.Theme_QuickLyric_Red, R.style.Theme_QuickLyric_Purple, R.style.Theme_QuickLyric_Indigo, R.style.Theme_QuickLyric_Green, R.style.Theme_QuickLyric_Lime, R.style.Theme_QuickLyric_Brown, R.style.Theme_QuickLyric_Dark }; int themeNum = Integer.valueOf(sharedPref.getString("pref_theme", "0")); boolean nightMode = sharedPref.getBoolean("pref_night_mode", false); if (nightMode && NightTimeVerifier.check(this)) setTheme(R.style.Theme_QuickLyric_Night); else/*w ww . j a v a 2 s .c o m*/ setTheme(themes[themeNum]); TypedValue primaryColor = new TypedValue(); getTheme().resolveAttribute(R.attr.colorPrimary, primaryColor, true); setStatusBarColor(null); LinearLayout linearLayout = new LinearLayout(this); linearLayout.setOrientation(LinearLayout.VERTICAL); Toolbar toolbar = new Toolbar(this); toolbar.setTitle(R.string.pref_about); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) toolbar.setElevation(8f); toolbar.setBackgroundColor(primaryColor.data); toolbar.setTitleTextColor(Color.WHITE); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { ActivityManager.TaskDescription taskDescription = new ActivityManager.TaskDescription(null, null, primaryColor.data); this.setTaskDescription(taskDescription); } View.OnClickListener productTourAction = new View.OnClickListener() { @Override public void onClick(View v) { setupDemoScreen(); } }; Element productTourElement = new Element().setTitle(getString(R.string.about_product_tour)); productTourElement.setOnClickListener(productTourAction); Element crowdinElement = new Element().setTitle(getString(R.string.about_crowdin)); crowdinElement .setIntent(new Intent(Intent.ACTION_VIEW, Uri.parse("https://crowdin.com/project/quicklyric"))); Element ossLicensesElement = new Element().setTitle("Open Source Licenses"); ossLicensesElement.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { WebView webView = new WebView(AboutActivity.this); String data = getResources().getString(R.string.open_source_librairies_licenses); webView.loadData(data, "text/html; charset=utf-8", "UTF-8"); new AlertDialog.Builder(AboutActivity.this).setView(webView).show(); } }); Element tosElement = new Element().setTitle(getString(R.string.about_read_ToS)); tosElement.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { WebView webView = new WebView(AboutActivity.this); String data = getResources().getString(R.string.QL_EULA); webView.loadData(data, "text/html; charset=utf-8", "UTF-8"); new AlertDialog.Builder(AboutActivity.this).setView(webView).show(); } }); Element cookElement = new Element().setTitle("Icon Designer"); cookElement.setIntent(new Intent(Intent.ACTION_VIEW, Uri.parse("https://cookicons.co/"))); View aboutView = new AboutPage(this).setDescription("QuickLyric is made with love in Brussels, Belgium.") // FixMe .addEmail("contact@QuickLyric.be").addFacebook("QuickLyric").addGitHub("geecko86/QuickLyric") .addPlayStore("test").addTwitter("QuickLyric").addWebsite("http://www.quicklyric.be") .setImage(R.drawable.icon).addItem(productTourElement).addItem(crowdinElement).addItem(cookElement) .addItem(ossLicensesElement).addItem(tosElement).create(); aboutView.setLayoutParams(new ScrollView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); linearLayout.addView(toolbar); linearLayout.addView(aboutView); setContentView(linearLayout); final Drawable upArrow; if (Build.VERSION.SDK_INT >= 21) { upArrow = getResources().getDrawable(R.drawable.abc_ic_ab_back_material); upArrow.setColorFilter(Color.WHITE, PorterDuff.Mode.SRC_ATOP); } else upArrow = getResources().getDrawable(R.drawable.ic_arrow_back); setSupportActionBar(toolbar); getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setHomeAsUpIndicator(upArrow); }
From source file:com.picogram.awesomeness.SettingsActivity.java
public boolean onPreferenceClick(final Preference preference) { if (preference.getKey().equals("statistics")) { //TODO/*from w w w. ja v a 2s . co m*/ Crouton.makeText(this, "This is not yet implemented", Style.INFO).show(); final AlertDialog dialog = new AlertDialog.Builder(this).create(); final String[] scoresTitles = new String[] { "Games Played", "Games Won", "Taps", "Taps per Puzzle", "Tapes per Minute", "Times Played" }; final int gamesPlayed = 0, gamesWon = 0, taps = 0, tapsPerPuzzle = 0, tapsPerMinute = 0, timePlayed = 0; final int[] scores = { gamesPlayed, gamesWon, taps, tapsPerPuzzle, tapsPerMinute, timePlayed }; // TODO: Implement the preferences and what not. final LinearLayout ll = new LinearLayout(this); ll.setOrientation(LinearLayout.VERTICAL); for (int i = 0; i != scores.length; ++i) { final LinearLayout sub = new LinearLayout(this); sub.setLayoutParams(new LinearLayout.LayoutParams(android.view.ViewGroup.LayoutParams.FILL_PARENT, android.view.ViewGroup.LayoutParams.WRAP_CONTENT)); sub.setOrientation(LinearLayout.HORIZONTAL); TextView tv = new TextView(this); tv.setLayoutParams(new TableLayout.LayoutParams(android.view.ViewGroup.LayoutParams.WRAP_CONTENT, android.view.ViewGroup.LayoutParams.WRAP_CONTENT, 1f)); tv.setText(scoresTitles[i]); sub.addView(tv); tv = new TextView(this); tv.setLayoutParams(new TableLayout.LayoutParams(android.view.ViewGroup.LayoutParams.WRAP_CONTENT, android.view.ViewGroup.LayoutParams.WRAP_CONTENT, 1f)); tv.setText(scores[i] + ""); sub.addView(tv); ll.addView(sub); } dialog.setView(ll); dialog.setButton("OK", new DialogInterface.OnClickListener() { public void onClick(final DialogInterface dialog, final int which) { dialog.dismiss(); } }); dialog.getWindow().getAttributes().windowAnimations = R.style.DialogTheme; dialog.show(); dialog.dismiss(); return true; } else if (preference.getKey().equals("changelog")) { // Launch change log dialog final ChangeLogDialog _ChangelogDialog = new ChangeLogDialog(this); _ChangelogDialog.show(); } else if (preference.getKey().equals("licenses")) { // Launch the licenses stuff. Dialog ld = new LicensesDialog(this, R.raw.licenses, false, false).create(); ld.getWindow().getAttributes().windowAnimations = R.style.DialogTheme; ld.show(); } else if (preference.getKey().equals("email")) { final String email = "warner.73+Picogram@wright.edu"; final String subject = "Picogram - <SUBJECT>"; final String message = "Picogram,\n\n<MESSAGE>"; // Contact me. final Intent emailIntent = new Intent(Intent.ACTION_SEND); emailIntent.putExtra(Intent.EXTRA_EMAIL, new String[] { email }); emailIntent.putExtra(Intent.EXTRA_SUBJECT, subject); emailIntent.putExtra(Intent.EXTRA_TEXT, message); emailIntent.setType("message/rfc822"); this.startActivity(Intent.createChooser(emailIntent, "Send Mail Using :")); overridePendingTransition(R.anim.fadein, R.anim.exit_left); } else if (preference.getKey().equals("rateapp")) { // TODO fix this when we publish. this.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=Picogram"))); overridePendingTransition(R.anim.fadein, R.anim.exit_left); final Editor editor = this.prefs.edit(); editor.putBoolean(RateMeMaybe.PREF.DONT_SHOW_AGAIN, true); editor.commit(); } else if (preference.getKey().equals("logoutgoogle")) { //TODO Crouton.makeText(this, "This is not currently supported.", Style.INFO).show(); } else if (preference.getKey().equals("logoutfacebook")) { //TODO Crouton.makeText(this, "This is not currently supported.", Style.INFO).show(); } else if (preference.getKey().equals("resetusername")) { Util.getPreferences(this).edit().putString("username", "").commit(); Util.getPreferences(this).edit().putBoolean("hasLoggedInUsername", false).commit(); } return false; }
From source file:com.mikecorrigan.trainscorekeeper.FragmentButton.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { Log.vc(VERBOSE, TAG, "onCreateView: inflater=" + inflater + ", container=" + container + ", savedInstanceState=" + Utils.bundleToString(savedInstanceState)); View rootView = inflater.inflate(R.layout.fragment_button, container, false); Bundle args = getArguments();//from w ww . ja va 2 s . co m if (args == null) { Log.e(TAG, "onCreateView: missing arguments"); return rootView; } // The activity must support a standard OnClickListener. final MainActivity mainActivity = (MainActivity) getActivity(); final Context context = mainActivity; players = mainActivity.getPlayers(); if (players != null) { players.addListener(mPlayersListener); } // final int index = args.getInt(ARG_INDEX); final String tabSpec = args.getString(ARG_TAB_SPEC); try { JSONObject jsonTab = new JSONObject(tabSpec); final String tabName = jsonTab.optString(JsonSpec.TAB_NAME, JsonSpec.DEFAULT_TAB_NAME); if (!TextUtils.isEmpty(tabName)) { TextView tv = (TextView) rootView.findViewById(R.id.text_view_name); tv.setText(tabName); } tabLayout = (LinearLayout) rootView; JSONArray jsonSections = jsonTab.getJSONArray(JsonSpec.SECTIONS_KEY); for (int i = 0; i < jsonSections.length(); i++) { JSONObject jsonSection = jsonSections.getJSONObject(i); LinearLayout sectionLayout = new LinearLayout(context); sectionLayout.setOrientation(LinearLayout.VERTICAL); tabLayout.addView(sectionLayout); // If a section is named, label it. final String sectionName = jsonSection.optString(JsonSpec.SECTION_NAME, JsonSpec.DEFAULT_SECTION_NAME); if (!TextUtils.isEmpty(sectionName)) { TextView textView = new TextView(context); textView.setText(sectionName); sectionLayout.addView(textView); } int numColumns = jsonSection.optInt(JsonSpec.SECTION_COLUMNS, JsonSpec.DEFAULT_SECTION_COLUMNS); List<View> buttonViews = new LinkedList<View>(); JSONArray buttons = jsonSection.getJSONArray(JsonSpec.BUTTONS_KEY); for (int k = 0; k < buttons.length(); k++) { JSONObject jsonButton = buttons.getJSONObject(k); ScoreButton buttonView = new ScoreButton(context); buttonView.setButtonSpec(jsonButton); buttonView.setOnClickListener(mainActivity.getScoreClickListener()); // Add the button to the section. buttonViews.add(buttonView); } GridView gridView = new GridView(context); gridView.setNumColumns(numColumns); gridView.setAdapter(new ViewAdapter(context, buttonViews)); sectionLayout.addView(gridView); } } catch (JSONException e) { Log.th(TAG, e, "onCreateView: failed to parse JSON"); } updateUi(); return rootView; }
From source file:org.openmrs.mobile.activities.fragments.FormPageFragment.java
void addQuestion(Question question, LinearLayout parent) { if (question.getQuestionOptions().getRendering().equals("group")) { LinearLayout questionLL = new LinearLayout(getActivity()); questionLL.setOrientation(LinearLayout.VERTICAL); LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); questionLL.setGravity(Gravity.CENTER); parent.addView(questionLL);//from www. j av a 2 s. c o m Resources r = getActivity().getResources(); float pxLeftMargin = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 5, r.getDisplayMetrics()); float pxTopMargin = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 5, r.getDisplayMetrics()); float pxRightMargin = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 5, r.getDisplayMetrics()); float pxBottomMargin = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 5, r.getDisplayMetrics()); layoutParams.setMargins(Math.round(pxLeftMargin), Math.round(pxTopMargin), Math.round(pxRightMargin), Math.round(pxBottomMargin)); TextView tv = new TextView(getActivity()); tv.setText(question.getLabel()); tv.setTextSize(TypedValue.COMPLEX_UNIT_SP, 18); tv.setTextColor(ContextCompat.getColor(getActivity(), R.color.primary)); questionLL.addView(tv, layoutParams); for (Question subquestion : question.getQuestions()) { addQuestion(subquestion, questionLL); } } if (question.getQuestionOptions().getRendering().equals("number")) { LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); Resources r = getActivity().getResources(); float pxLeftMargin = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 5, r.getDisplayMetrics()); float pxTopMargin = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 5, r.getDisplayMetrics()); float pxRightMargin = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 5, r.getDisplayMetrics()); float pxBottomMargin = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 5, r.getDisplayMetrics()); layoutParams.setMargins(Math.round(pxLeftMargin), Math.round(pxTopMargin), Math.round(pxRightMargin), Math.round(pxBottomMargin)); RangeEditText ed = new RangeEditText(getActivity()); ed.setName(question.getLabel()); if (question.getQuestionOptions().getMax() != null) { ed.setHint(question.getLabel() + " [" + question.getQuestionOptions().getMin() + "-" + question.getQuestionOptions().getMax() + "]"); ed.setUpperlimit(Double.parseDouble(question.getQuestionOptions().getMax())); ed.setLowerlimit(Double.parseDouble(question.getQuestionOptions().getMin())); } else { ed.setHint(question.getLabel()); ed.setLowerlimit(-1.0); ed.setUpperlimit(-1.0); } ed.setTextSize(TypedValue.COMPLEX_UNIT_SP, 16); ed.setRawInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL); int id = InputField.generateViewId(); InputField field = new InputField(); ed.setId(id); field.setId(id); field.setConcept(question.getQuestionOptions().getConcept()); inputFields.add(field); parent.addView(ed, layoutParams); } }
From source file:co.ldln.android.ObjectReadFragment.java
@Override public void onReadSchemaResult(Schema schema) { mSchema = schema;/*from w w w.ja va2 s . c om*/ HashMap<String, String> keyValueMap = mSyncableObject.getKeyValueMap(); for (SchemaField schemaField : mSchema.getFields(mActivity)) { String label = schemaField.getLabel(); String value = keyValueMap.get(label); String type = schemaField.getType(); // Create a linear layout to hold the field LinearLayout ll = new LinearLayout(mActivity); LayoutParams llParams = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); ll.setLayoutParams(llParams); ll.setOrientation(LinearLayout.HORIZONTAL); // TODO: different UI for different field types // Default to TextView TextView labelTv = new TextView(mActivity); LayoutParams labelTvParams = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); labelTv.setLayoutParams(labelTvParams); labelTv.setText(label); labelTv.setPadding(0, 0, 20, 0); labelTv.setTypeface(Typeface.DEFAULT_BOLD); ll.addView(labelTv); TextView valueTv = new TextView(mActivity); LayoutParams valueTvParams = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); valueTv.setLayoutParams(valueTvParams); valueTv.setText(value); ll.addView(valueTv); mFormHolder.addView(ll); } }