List of usage examples for android.widget LinearLayout addView
public void addView(View child)
Adds a child view.
From source file:com.aware.ui.ESM_UI.java
@Override public Dialog onCreateDialog(Bundle savedInstanceState) { // getActivity().getWindow().setType(WindowManager.LayoutParams.TYPE_PRIORITY_PHONE); // getActivity().getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); // getActivity().getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED); // getActivity().getWindow().addFlags(WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON); builder = new AlertDialog.Builder(getActivity()); inflater = (LayoutInflater) getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE); inputManager = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE); TAG = Aware.getSetting(getActivity().getApplicationContext(), Aware_Preferences.DEBUG_TAG).length() > 0 ? Aware.getSetting(getActivity().getApplicationContext(), Aware_Preferences.DEBUG_TAG) : TAG;// w w w. ja v a 2s .com Cursor visible_esm = getActivity().getContentResolver().query(ESM_Data.CONTENT_URI, null, ESM_Data.STATUS + "=" + ESM.STATUS_NEW, null, ESM_Data.TIMESTAMP + " ASC LIMIT 1"); if (visible_esm != null && visible_esm.moveToFirst()) { esm_id = visible_esm.getInt(visible_esm.getColumnIndex(ESM_Data._ID)); //Fixed: set the esm as not new anymore, to avoid displaying the same ESM twice due to changes in orientation ContentValues update_state = new ContentValues(); update_state.put(ESM_Data.STATUS, ESM.STATUS_VISIBLE); getActivity().getContentResolver().update(ESM_Data.CONTENT_URI, update_state, ESM_Data._ID + "=" + esm_id, null); esm_type = visible_esm.getInt(visible_esm.getColumnIndex(ESM_Data.TYPE)); expires_seconds = visible_esm.getInt(visible_esm.getColumnIndex(ESM_Data.EXPIRATION_THREASHOLD)); builder.setTitle(visible_esm.getString(visible_esm.getColumnIndex(ESM_Data.TITLE))); View ui = null; switch (esm_type) { case ESM.TYPE_ESM_TEXT: ui = inflater.inflate(R.layout.esm_text, null); break; case ESM.TYPE_ESM_RADIO: ui = inflater.inflate(R.layout.esm_radio, null); break; case ESM.TYPE_ESM_CHECKBOX: ui = inflater.inflate(R.layout.esm_checkbox, null); break; case ESM.TYPE_ESM_LIKERT: ui = inflater.inflate(R.layout.esm_likert, null); break; case ESM.TYPE_ESM_QUICK_ANSWERS: ui = inflater.inflate(R.layout.esm_quick, null); break; } final View layout = ui; builder.setView(layout); current_dialog = builder.create(); sContext = current_dialog.getContext(); TextView esm_instructions = (TextView) layout.findViewById(R.id.esm_instructions); esm_instructions.setText(visible_esm.getString(visible_esm.getColumnIndex(ESM_Data.INSTRUCTIONS))); switch (esm_type) { case ESM.TYPE_ESM_TEXT: final EditText feedback = (EditText) layout.findViewById(R.id.esm_feedback); Button cancel_text = (Button) layout.findViewById(R.id.esm_cancel); cancel_text.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { inputManager.hideSoftInputFromWindow(feedback.getWindowToken(), 0); current_dialog.cancel(); } }); Button submit_text = (Button) layout.findViewById(R.id.esm_submit); submit_text.setText(visible_esm.getString(visible_esm.getColumnIndex(ESM_Data.SUBMIT))); submit_text.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { inputManager.hideSoftInputFromWindow(feedback.getWindowToken(), 0); if (expires_seconds > 0 && expire_monitor != null) expire_monitor.cancel(true); ContentValues rowData = new ContentValues(); rowData.put(ESM_Data.ANSWER_TIMESTAMP, System.currentTimeMillis()); rowData.put(ESM_Data.ANSWER, feedback.getText().toString()); rowData.put(ESM_Data.STATUS, ESM.STATUS_ANSWERED); sContext.getContentResolver().update(ESM_Data.CONTENT_URI, rowData, ESM_Data._ID + "=" + esm_id, null); Intent answer = new Intent(ESM.ACTION_AWARE_ESM_ANSWERED); getActivity().sendBroadcast(answer); if (Aware.DEBUG) Log.d(TAG, "Answer:" + rowData.toString()); current_dialog.dismiss(); } }); break; case ESM.TYPE_ESM_RADIO: try { final RadioGroup radioOptions = (RadioGroup) layout.findViewById(R.id.esm_radio); final JSONArray radios = new JSONArray( visible_esm.getString(visible_esm.getColumnIndex(ESM_Data.RADIOS))); for (int i = 0; i < radios.length(); i++) { final RadioButton radioOption = new RadioButton(getActivity()); radioOption.setId(i); radioOption.setText(radios.getString(i)); radioOptions.addView(radioOption); if (radios.getString(i).equals("Other")) { radioOption.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { final Dialog editOther = new Dialog(getActivity()); editOther.setTitle("Can you be more specific, please?"); editOther.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT); editOther.getWindow().setGravity(Gravity.TOP); editOther.getWindow().setLayout(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); LinearLayout editor = new LinearLayout(getActivity()); editor.setOrientation(LinearLayout.VERTICAL); editOther.setContentView(editor); editOther.show(); final EditText otherText = new EditText(getActivity()); editor.addView(otherText); Button confirm = new Button(getActivity()); confirm.setText("OK"); confirm.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (otherText.length() > 0) radioOption.setText(otherText.getText()); inputManager.hideSoftInputFromWindow(otherText.getWindowToken(), 0); editOther.dismiss(); } }); editor.addView(confirm); } }); } } Button cancel_radio = (Button) layout.findViewById(R.id.esm_cancel); cancel_radio.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { current_dialog.cancel(); } }); Button submit_radio = (Button) layout.findViewById(R.id.esm_submit); submit_radio.setText(visible_esm.getString(visible_esm.getColumnIndex(ESM_Data.SUBMIT))); submit_radio.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (expires_seconds > 0 && expire_monitor != null) expire_monitor.cancel(true); ContentValues rowData = new ContentValues(); rowData.put(ESM_Data.ANSWER_TIMESTAMP, System.currentTimeMillis()); RadioGroup radioOptions = (RadioGroup) layout.findViewById(R.id.esm_radio); if (radioOptions.getCheckedRadioButtonId() != -1) { RadioButton selected = (RadioButton) radioOptions .getChildAt(radioOptions.getCheckedRadioButtonId()); rowData.put(ESM_Data.ANSWER, selected.getText().toString()); } rowData.put(ESM_Data.STATUS, ESM.STATUS_ANSWERED); sContext.getContentResolver().update(ESM_Data.CONTENT_URI, rowData, ESM_Data._ID + "=" + esm_id, null); Intent answer = new Intent(ESM.ACTION_AWARE_ESM_ANSWERED); getActivity().sendBroadcast(answer); if (Aware.DEBUG) Log.d(TAG, "Answer:" + rowData.toString()); current_dialog.dismiss(); } }); } catch (JSONException e) { e.printStackTrace(); } break; case ESM.TYPE_ESM_CHECKBOX: try { final LinearLayout checkboxes = (LinearLayout) layout.findViewById(R.id.esm_checkboxes); final JSONArray checks = new JSONArray( visible_esm.getString(visible_esm.getColumnIndex(ESM_Data.CHECKBOXES))); for (int i = 0; i < checks.length(); i++) { final CheckBox checked = new CheckBox(getActivity()); checked.setText(checks.getString(i)); checked.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(final CompoundButton buttonView, boolean isChecked) { if (isChecked) { if (buttonView.getText().equals("Other")) { checked.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { final Dialog editOther = new Dialog(getActivity()); editOther.setTitle("Can you be more specific, please?"); editOther.getWindow() .setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT); editOther.getWindow().setGravity(Gravity.TOP); editOther.getWindow().setLayout(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); LinearLayout editor = new LinearLayout(getActivity()); editor.setOrientation(LinearLayout.VERTICAL); editOther.setContentView(editor); editOther.show(); final EditText otherText = new EditText(getActivity()); editor.addView(otherText); Button confirm = new Button(getActivity()); confirm.setText("OK"); confirm.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (otherText.length() > 0) { inputManager.hideSoftInputFromWindow( otherText.getWindowToken(), 0); selected_options .remove(buttonView.getText().toString()); checked.setText(otherText.getText()); selected_options.add(otherText.getText().toString()); } editOther.dismiss(); } }); editor.addView(confirm); } }); } else { selected_options.add(buttonView.getText().toString()); } } else { selected_options.remove(buttonView.getText().toString()); } } }); checkboxes.addView(checked); } Button cancel_checkbox = (Button) layout.findViewById(R.id.esm_cancel); cancel_checkbox.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { current_dialog.cancel(); } }); Button submit_checkbox = (Button) layout.findViewById(R.id.esm_submit); submit_checkbox.setText(visible_esm.getString(visible_esm.getColumnIndex(ESM_Data.SUBMIT))); submit_checkbox.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (expires_seconds > 0 && expire_monitor != null) expire_monitor.cancel(true); ContentValues rowData = new ContentValues(); rowData.put(ESM_Data.ANSWER_TIMESTAMP, System.currentTimeMillis()); if (selected_options.size() > 0) { rowData.put(ESM_Data.ANSWER, selected_options.toString()); } rowData.put(ESM_Data.STATUS, ESM.STATUS_ANSWERED); sContext.getContentResolver().update(ESM_Data.CONTENT_URI, rowData, ESM_Data._ID + "=" + esm_id, null); Intent answer = new Intent(ESM.ACTION_AWARE_ESM_ANSWERED); getActivity().sendBroadcast(answer); if (Aware.DEBUG) Log.d(TAG, "Answer:" + rowData.toString()); current_dialog.dismiss(); } }); } catch (JSONException e) { e.printStackTrace(); } break; case ESM.TYPE_ESM_LIKERT: final RatingBar ratingBar = (RatingBar) layout.findViewById(R.id.esm_likert); ratingBar.setMax(visible_esm.getInt(visible_esm.getColumnIndex(ESM_Data.LIKERT_MAX))); ratingBar.setStepSize( (float) visible_esm.getDouble(visible_esm.getColumnIndex(ESM_Data.LIKERT_STEP))); ratingBar.setNumStars(visible_esm.getInt(visible_esm.getColumnIndex(ESM_Data.LIKERT_MAX))); TextView min_label = (TextView) layout.findViewById(R.id.esm_min); min_label.setText(visible_esm.getString(visible_esm.getColumnIndex(ESM_Data.LIKERT_MIN_LABEL))); TextView max_label = (TextView) layout.findViewById(R.id.esm_max); max_label.setText(visible_esm.getString(visible_esm.getColumnIndex(ESM_Data.LIKERT_MAX_LABEL))); Button cancel = (Button) layout.findViewById(R.id.esm_cancel); cancel.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { current_dialog.cancel(); } }); Button submit = (Button) layout.findViewById(R.id.esm_submit); submit.setText(visible_esm.getString(visible_esm.getColumnIndex(ESM_Data.SUBMIT))); submit.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (expires_seconds > 0 && expire_monitor != null) expire_monitor.cancel(true); ContentValues rowData = new ContentValues(); rowData.put(ESM_Data.ANSWER_TIMESTAMP, System.currentTimeMillis()); rowData.put(ESM_Data.ANSWER, ratingBar.getRating()); rowData.put(ESM_Data.STATUS, ESM.STATUS_ANSWERED); sContext.getContentResolver().update(ESM_Data.CONTENT_URI, rowData, ESM_Data._ID + "=" + esm_id, null); Intent answer = new Intent(ESM.ACTION_AWARE_ESM_ANSWERED); getActivity().sendBroadcast(answer); if (Aware.DEBUG) Log.d(TAG, "Answer:" + rowData.toString()); current_dialog.dismiss(); } }); break; case ESM.TYPE_ESM_QUICK_ANSWERS: try { final JSONArray answers = new JSONArray( visible_esm.getString(visible_esm.getColumnIndex(ESM_Data.QUICK_ANSWERS))); final LinearLayout answersHolder = (LinearLayout) layout.findViewById(R.id.esm_answers); //If we have more than 3 possibilities, better that the UI is vertical for UX if (answers.length() > 3) { answersHolder.setOrientation(LinearLayout.VERTICAL); } for (int i = 0; i < answers.length(); i++) { final Button answer = new Button(getActivity()); LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT, 1.0f); answer.setLayoutParams(params); answer.setText(answers.getString(i)); answer.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (expires_seconds > 0 && expire_monitor != null) expire_monitor.cancel(true); ContentValues rowData = new ContentValues(); rowData.put(ESM_Data.ANSWER_TIMESTAMP, System.currentTimeMillis()); rowData.put(ESM_Data.STATUS, ESM.STATUS_ANSWERED); rowData.put(ESM_Data.ANSWER, (String) answer.getText()); sContext.getContentResolver().update(ESM_Data.CONTENT_URI, rowData, ESM_Data._ID + "=" + esm_id, null); Intent answer = new Intent(ESM.ACTION_AWARE_ESM_ANSWERED); getActivity().sendBroadcast(answer); if (Aware.DEBUG) Log.d(TAG, "Answer:" + rowData.toString()); current_dialog.dismiss(); } }); answersHolder.addView(answer); } } catch (JSONException e) { e.printStackTrace(); } break; } } if (visible_esm != null && !visible_esm.isClosed()) visible_esm.close(); //Start dialog visibility threshold if (expires_seconds > 0) { expire_monitor = new ESMExpireMonitor(System.currentTimeMillis(), expires_seconds, esm_id); expire_monitor.execute(); } //Fixed: doesn't dismiss the dialog if touched outside or ghost touches current_dialog.setCanceledOnTouchOutside(false); return current_dialog; }
From source file:com.astuetz.PagerSlidingTabStripPlus.java
/** * Add new text view to the linear layout that contains the tab title* * @param position of the linear layout in the tabsContainer * @param text is the text of the subtitle */// w w w .j a va2 s .com public void addSubtitleAtTab(int position, String text) { LinearLayout tab = getSingleTabLayoutAtPosition(position); tab.setWeightSum(tab.getChildCount() + 1); if (tab.getChildCount() == 1) { tab.getChildAt(0).setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, 0, 1)); } ((TextView) tab.getChildAt(0)).setGravity(Gravity.CENTER_HORIZONTAL); TextView newSubTab = new TextView(getContext()); newSubTab.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, 0, 1)); newSubTab.setText(text); newSubTab.setGravity(Gravity.CENTER_HORIZONTAL); tab.addView(newSubTab); updateTabStyles(); }
From source file:org.sirimangalo.meditationplus.AdapterCommit.java
@Override public View getView(final int position, View convertView, ViewGroup parent) { LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); View rowView = inflater.inflate(R.layout.list_item_commit, parent, false); final View shell = rowView.findViewById(R.id.detail_shell); rowView.setOnClickListener(new View.OnClickListener() { @Override/* w w w. j a va 2 s . c om*/ public void onClick(View view) { boolean visible = shell.getVisibility() == View.VISIBLE; shell.setVisibility(visible ? View.GONE : View.VISIBLE); context.setCommitVisible(position, !visible); } }); final JSONObject p = values.get(position); TextView title = (TextView) rowView.findViewById(R.id.title); TextView descV = (TextView) rowView.findViewById(R.id.desc); TextView defV = (TextView) rowView.findViewById(R.id.def); TextView usersV = (TextView) rowView.findViewById(R.id.users); TextView youV = (TextView) rowView.findViewById(R.id.you); try { if (p.getBoolean("open")) shell.setVisibility(View.VISIBLE); title.setText(p.getString("title")); descV.setText(p.getString("description")); String length = p.getString("length"); String time = p.getString("time"); final String cid = p.getString("cid"); String def = ""; boolean repeat = false; if (length.indexOf(":") > 0) { repeat = true; String[] lengtha = length.split(":"); def += lengtha[0] + " minutes walking and " + lengtha[1] + " minutes sitting"; } else def += length + " minutes total meditation"; String period = p.getString("period"); String day = p.getString("day"); if (period.equals("daily")) { if (repeat) def += " every day"; else def += " per day"; } else if (period.equals("weekly")) { if (repeat) def += " every " + dow[Integer.parseInt(day)]; else def += " per week"; } else if (period.equals("monthly")) { if (repeat) def += " on the " + day + (day.substring(day.length() - 1).equals("1") ? "st" : (day.substring(day.length() - 1).equals("2") ? "nd" : (day.substring(day.length() - 1).equals("3") ? "rd" : "th"))) + " day of the month"; else def += " per month"; } else if (period.equals("yearly")) { if (repeat) def += " on the " + day + (day.substring(day.length() - 1).equals("1") ? "st" : (day.substring(day.length() - 1).equals("2") ? "nd" : (day.substring(day.length() - 1).equals("3") ? "rd" : "th"))) + " day of the year"; else def += " per year"; } if (!time.equals("any")) { Calendar utc = Calendar.getInstance(TimeZone.getTimeZone("UTC")); utc.set(Calendar.HOUR_OF_DAY, Integer.parseInt(time.split(":")[0])); utc.set(Calendar.MINUTE, Integer.parseInt(time.split(":")[1])); Calendar here = Calendar.getInstance(); here.setTimeInMillis(utc.getTimeInMillis()); int hours = here.get(Calendar.HOUR_OF_DAY); int minutes = here.get(Calendar.MINUTE); def += " at " + (time.length() == 4 ? "0" : "") + time.replace(":", "") + "h UTC <i>(" + (hours > 12 ? hours - 12 : hours) + ":" + ((minutes < 10 ? "0" : "") + minutes) + " " + (hours > 11 && hours < 24 ? "PM" : "AM") + " your time)</i>"; } defV.setText(Html.fromHtml(def)); JSONObject usersJ = p.getJSONObject("users"); ArrayList<String> committedArray = new ArrayList<String>(); // collect into array for (int i = 0; i < usersJ.names().length(); i++) { try { String j = usersJ.names().getString(i); String k = j; // if(j.equals(p.getString("creator"))) // k = "["+j+"]"; committedArray.add(k); } catch (JSONException e) { e.printStackTrace(); } } String text = context.getString(R.string.committed) + " "; // add spans int committed = -1; int pos = text.length(); // start after "Committed: " text += TextUtils.join(", ", committedArray); Spannable span = new SpannableString(text); span.setSpan(new StyleSpan(Typeface.BOLD), 0, pos, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); // bold the "Online: " for (int i = 0; i < committedArray.size(); i++) { try { final String oneCom = committedArray.get(i); String userCom = usersJ.getString(oneCom); //String userCom = usersJ.getString(oneCom.replace("[", "").replace("]", "")); //if(oneCom.replace("[","").replace("]","").equals(loggedUser)) if (oneCom.equals(loggedUser)) committed = Integer.parseInt(userCom); int end = pos + oneCom.length(); ClickableSpan clickable = new ClickableSpan() { @Override public void onClick(View widget) { context.showProfile(oneCom); } }; span.setSpan(clickable, pos, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); span.setSpan(new UnderlineSpan() { public void updateDrawState(TextPaint tp) { tp.setUnderlineText(false); } }, pos, end, 0); String color = Utils.makeRedGreen(Integer.parseInt(userCom), true); span.setSpan(new ForegroundColorSpan(Color.parseColor("#FF" + color)), pos, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); pos += oneCom.length() + 2; } catch (JSONException e) { e.printStackTrace(); } } usersV.setText(span); usersV.setMovementMethod(new LinkMovementMethod()); if (loggedUser != null && loggedUser.length() > 0) { LinearLayout bl = (LinearLayout) rowView.findViewById(R.id.commit_buttons); if (!usersJ.has(loggedUser)) { Button commitB = new Button(context); commitB.setId(R.id.commit_button); commitB.setText(R.string.commit); commitB.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { ArrayList<NameValuePair> nvp = new ArrayList<NameValuePair>(); nvp.add(new BasicNameValuePair("full_update", "true")); context.doSubmit("commitform_" + cid, nvp, true); } }); bl.addView(commitB); } else { Button commitB = new Button(context); commitB.setId(R.id.uncommit_button); commitB.setText(R.string.uncommit); commitB.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { ArrayList<NameValuePair> nvp = new ArrayList<NameValuePair>(); nvp.add(new BasicNameValuePair("full_update", "true")); context.doSubmit("uncommitform_" + cid, nvp, true); } }); bl.addView(commitB); } if (loggedUser.equals(p.getString("creator")) || context.isAdmin) { Button commitB2 = new Button(context); commitB2.setId(R.id.edit_commit_button); commitB2.setText(R.string.edit); commitB2.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Intent i = new Intent(context, ActivityCommit.class); i.putExtra("commitment", p.toString()); context.startActivity(i); } }); bl.addView(commitB2); Button commitB3 = new Button(context); commitB3.setId(R.id.uncommit_button); commitB3.setText(R.string.delete); commitB3.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { ArrayList<NameValuePair> nvp = new ArrayList<NameValuePair>(); nvp.add(new BasicNameValuePair("full_update", "true")); context.doSubmit("delcommitform_" + cid, nvp, true); } }); bl.addView(commitB3); } } if (committed > -1) { int color = Color.parseColor("#FF" + Utils.makeRedGreen(committed, false)); rowView.setBackgroundColor(color); } if (committed != -1) { youV.setText(String.format(context.getString(R.string.you_commit_x), committed)); youV.setVisibility(View.VISIBLE); } } catch (Exception e) { e.printStackTrace(); } return rowView; }
From source file:net.mypapit.mobile.myrepeater.DisplayMap.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_display_map); overridePendingTransition(R.anim.activity_open_translate, R.anim.activity_close_scale); hashMap = new HashMap<Marker, MapInfoObject>(); if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB) { getActionBar().setDisplayHomeAsUpEnabled(true); }/*w w w . ja v a 2 s . co m*/ map = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap(); if (map == null) { // Log.e("Map NULL", "MAP NULL"); Toast.makeText(this, "Unable to display Map", Toast.LENGTH_SHORT).show(); } else { LatLng latlng = (LatLng) getIntent().getExtras().get("LatLong"); Repeater xlocation = new Repeater("", new Double[] { latlng.latitude, latlng.longitude }); rl = RepeaterListActivity.loadData(R.raw.repeaterdata5, this); xlocation.calcDistanceAll(rl); rl.sort(); map.setMyLocationEnabled(true); map.setOnInfoWindowClickListener(this); map.getUiSettings().setZoomControlsEnabled(true); AdView mAdView = (AdView) findViewById(R.id.adViewMap); mAdView.loadAd(new AdRequest.Builder().build()); // counter i, for mapping marker with integer int i = 0; for (Repeater repeater : rl) { MarkerOptions marking = new MarkerOptions(); marking.position(new LatLng(repeater.getLatitude(), repeater.getLongitude())); marking.title(repeater.getCallsign() + " - " + repeater.getDownlink() + "MHz (" + repeater.getClub() + ")"); marking.snippet("Tone: " + repeater.getTone() + " Shift: " + repeater.getShift()); RepeaterMapInfo rmi = new RepeaterMapInfo(repeater); rmi.setIndex(i); hashMap.put(map.addMarker(marking), rmi); i++; } // Marker RKG = map.addMarker(new MarkerOptions().position(new // LatLng(6.1,100.3)).title("9M4RKG")); map.moveCamera(CameraUpdateFactory.newLatLngZoom(latlng, 10)); map.animateCamera(CameraUpdateFactory.zoomTo(10), 2000, null); cache = this.getSharedPreferences(CACHE_PREFS, 0); Date cachedate = new Date(cache.getLong(CACHE_TIME, new Date(20000).getTime())); long secs = (new Date().getTime() - cachedate.getTime()) / 1000; long hours = secs / 3600L; secs = secs % 3600L; long mins = secs / 60L; if (mins < 5) { String jsoncache = cache.getString(CACHE_JSON, "none"); if (jsoncache.compareToIgnoreCase("none") == 0) { new GetUserInfo(latlng, this).execute(); } else { loadfromCache(jsoncache); // Toast.makeText(this, "Loaded from cache: " + mins + // " mins", Toast.LENGTH_SHORT).show(); } } else { new GetUserInfo(latlng, this).execute(); } map.setInfoWindowAdapter(new GoogleMap.InfoWindowAdapter() { @Override public View getInfoWindow(Marker marker) { // TODO Auto-generated method stub return null; } @Override public View getInfoContents(Marker marker) { Context context = getApplicationContext(); // or // getActivity(), // YourActivity.this, // etc. LinearLayout info = new LinearLayout(context); info.setOrientation(LinearLayout.VERTICAL); TextView title = new TextView(context); title.setTextColor(Color.BLACK); title.setGravity(Gravity.CENTER); title.setTypeface(null, Typeface.BOLD); title.setText(marker.getTitle()); TextView snippet = new TextView(context); snippet.setTextColor(Color.GRAY); snippet.setText(marker.getSnippet()); info.addView(title); info.addView(snippet); return info; } }); } }
From source file:com.moonpi.tapunlock.MainActivity.java
@Override protected Dialog onCreateDialog(int id) { // Scan NFC Tag dialog, inflate image LayoutInflater factory = LayoutInflater.from(MainActivity.this); final View view = factory.inflate(R.layout.scan_tag_image, null); // Ask for tagTitle (tagName) in dialog final EditText tagTitle = new EditText(this); tagTitle.setHint(getResources().getString(R.string.set_tag_name_dialog_hint)); tagTitle.setSingleLine(true);//from w ww.j a v a 2s.c o m tagTitle.setInputType(InputType.TYPE_TEXT_FLAG_CAP_SENTENCES); // Set tagTitle maxLength int maxLength = 50; InputFilter[] array = new InputFilter[1]; array[0] = new InputFilter.LengthFilter(maxLength); tagTitle.setFilters(array); final LinearLayout l = new LinearLayout(this); l.setOrientation(LinearLayout.VERTICAL); l.addView(tagTitle); // Dialog that shows scan tag image if (id == DIALOG_READ) { return new AlertDialog.Builder(this).setTitle(R.string.scan_tag_dialog_title).setView(view) .setCancelable(false) .setNeutralButton(android.R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialogCancelled = true; killForegroundDispatch(); dialog.cancel(); } }).create(); } // Dialog that asks for tagName and stores it after 'Ok' pressed else if (id == DIALOG_SET_TAGNAME) { tagTitle.requestFocus(); return new AlertDialog.Builder(this).setTitle(R.string.set_tag_name_dialog_title).setView(l) .setCancelable(false) .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { JSONObject newTag = new JSONObject(); try { newTag.put("tagName", tagTitle.getText()); newTag.put("tagID", tagID); } catch (JSONException e) { e.printStackTrace(); } tags.put(newTag); writeToJSON(); adapter.notifyDataSetChanged(); updateListViewHeight(listView); if (tags.length() == 0) noTags.setVisibility(View.VISIBLE); else noTags.setVisibility(View.INVISIBLE); Toast toast = Toast.makeText(getApplicationContext(), R.string.toast_tag_added, Toast.LENGTH_SHORT); toast.show(); imm.hideSoftInputFromWindow(tagTitle.getWindowToken(), 0); tagID = ""; tagTitle.setText(""); } }).setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { tagID = ""; tagTitle.setText(""); imm.hideSoftInputFromWindow(tagTitle.getWindowToken(), 0); dialog.cancel(); } }).create(); } return null; }
From source file:com.example.hllut.app.Deprecated.MainActivity.java
/** * Fills "amount of planets" textView as well as drawing the planets *///from w ww .j a va 2 s . co m private void drawPlanets() { //TODO use the bundle int numberOfPlanets = (int) (TOTAL_CO2 / MAX_CO2_PER_PERSON); TextView need = (TextView) findViewById(R.id.planetsTextView); need.setText("We would need " + numberOfPlanets + " planets"); TableLayout layout = (TableLayout) findViewById(R.id.planetContainer); TableRow tbr = new TableRow(this); LinearLayout linearLayout = new LinearLayout(this); linearLayout.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT, 1f)); //TODO tbr.setLayoutParams( new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT, TableRow.LayoutParams.MATCH_PARENT)); tbr.setPadding(10, 10, 10, 10); for (int i = 1; i < numberOfPlanets + 1; i++) { // TODO: Too many planets fuck up formatting // Create images ImageView im = new ImageView(this); im.setImageResource(R.drawable.earth); im.setLayoutParams( new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, 1f)); im.setPadding(10, 10, 10, 10); //planets per row = 5 if (i % 5 == 0) { // if you have gone 5 laps // print what you have linearLayout.addView(im); tbr.addView(linearLayout, new TableRow.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT, 1f)); layout.addView(tbr, new TableLayout.LayoutParams(TableLayout.LayoutParams.MATCH_PARENT, TableLayout.LayoutParams.MATCH_PARENT)); tbr = new TableRow(this); linearLayout = new LinearLayout(this); linearLayout.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT, 1f)); tbr.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT, TableRow.LayoutParams.MATCH_PARENT)); tbr.setPadding(10, 10, 10, 10); } else { linearLayout.addView(im); } } tbr.addView(linearLayout, new TableRow.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT, 1f)); // layout.addView(tbr, new TableLayout.LayoutParams(TableLayout.LayoutParams.MATCH_PARENT, TableLayout.LayoutParams.MATCH_PARENT)); }
From source file:com.microsoft.live.sample.skydrive.SkyDriveActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.skydrive);/*from ww w . j a va2 s.c o m*/ mPrevFolderIds = new Stack<String>(); ListView lv = getListView(); lv.setTextFilterEnabled(true); lv.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { SkyDriveObject skyDriveObj = (SkyDriveObject) parent.getItemAtPosition(position); skyDriveObj.accept(new Visitor() { @Override public void visit(SkyDriveAlbum album) { mPrevFolderIds.push(mCurrentFolderId); loadFolder(album.getId()); } @Override public void visit(SkyDrivePhoto photo) { ViewPhotoDialog dialog = new ViewPhotoDialog(SkyDriveActivity.this, photo); dialog.setOwnerActivity(SkyDriveActivity.this); dialog.show(); } @Override public void visit(SkyDriveFolder folder) { mPrevFolderIds.push(mCurrentFolderId); loadFolder(folder.getId()); } @Override public void visit(SkyDriveFile file) { Bundle b = new Bundle(); b.putString(JsonKeys.ID, file.getId()); b.putString(JsonKeys.NAME, file.getName()); showDialog(DIALOG_DOWNLOAD_ID, b); } @Override public void visit(SkyDriveVideo video) { PlayVideoDialog dialog = new PlayVideoDialog(SkyDriveActivity.this, video); dialog.setOwnerActivity(SkyDriveActivity.this); dialog.show(); } @Override public void visit(SkyDriveAudio audio) { PlayAudioDialog audioDialog = new PlayAudioDialog(SkyDriveActivity.this, audio); audioDialog.show(); } }); } }); LinearLayout layout = new LinearLayout(this); Button newFolderButton = new Button(this); newFolderButton.setText("New Folder"); newFolderButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { NewFolderDialog dialog = new NewFolderDialog(SkyDriveActivity.this); dialog.setOwnerActivity(SkyDriveActivity.this); dialog.show(); } }); layout.addView(newFolderButton); Button uploadFileButton = new Button(this); uploadFileButton.setText("Upload File"); uploadFileButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(getApplicationContext(), FilePicker.class); startActivityForResult(intent, FilePicker.PICK_FILE_REQUEST); } }); layout.addView(uploadFileButton); lv.addHeaderView(layout); mPhotoAdapter = new SkyDriveListAdapter(this); setListAdapter(mPhotoAdapter); LiveSdkSampleApplication app = (LiveSdkSampleApplication) getApplication(); mClient = app.getConnectClient(); }
From source file:com.mikecorrigan.trainscorekeeper.ActivityNewGame.java
private void addContent() { Log.vc(VERBOSE, TAG, "addContent"); LinearLayout linearLayout = (LinearLayout) findViewById(R.id.linear_layout); Resources res = getResources(); AssetManager am = res.getAssets();//from w ww . j av a 2 s. co m String files[]; try { files = am.list(ASSETS_BASE); if (files == null || files.length == 0) { Log.e(TAG, "addContent: empty asset list"); return; } for (final String file : files) { final String path = ASSETS_BASE + File.separator + file; JSONObject jsonRoot = JsonUtils.readFromAssets(this /* context */, path); if (jsonRoot == null) { Log.e(file, "addContent: failed to read read asset"); continue; } final String name = jsonRoot.optString(JsonSpec.ROOT_NAME); if (TextUtils.isEmpty(name)) { Log.e(file, "addContent: failed to read asset name"); continue; } final String description = jsonRoot.optString(JsonSpec.ROOT_DESCRIPTION, name); TextView textView = new TextView(this /* context */); textView.setText(name); linearLayout.addView(textView); Button button = new Button(this /* context */); button.setText(description); button.setOnClickListener(new OnRulesClickListener(path)); linearLayout.addView(button); } } catch (IOException e) { Log.th(TAG, e, "addContent: asset list failed"); } }
From source file:com.doodle.android.chips.ChipsView.java
private void init() { mDensity = getResources().getDisplayMetrics().density; mChipsContainer = new RelativeLayout(getContext()); addView(mChipsContainer);/*from w ww .j ava2s . com*/ // Dummy item to prevent AutoCompleteTextView from receiving focus LinearLayout linearLayout = new LinearLayout(getContext()); ViewGroup.LayoutParams params = new ViewGroup.LayoutParams(0, 0); linearLayout.setLayoutParams(params); linearLayout.setFocusable(true); linearLayout.setFocusableInTouchMode(true); mChipsContainer.addView(linearLayout); mEditText = new ChipsEditText(getContext(), this); RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams( ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); layoutParams.topMargin = (int) (SPACING_TOP * mDensity); layoutParams.bottomMargin = (int) (SPACING_BOTTOM * mDensity) + mVerticalSpacing; mEditText.setLayoutParams(layoutParams); mEditText.setMinHeight((int) (CHIP_HEIGHT * mDensity)); mEditText.setPadding(0, 0, 0, 0); mEditText.setLineSpacing(mVerticalSpacing, (CHIP_HEIGHT * mDensity) / mEditText.getLineHeight()); mEditText.setBackgroundColor(Color.argb(0, 0, 0, 0)); mEditText.setImeOptions(EditorInfo.IME_FLAG_NO_EXTRACT_UI | EditorInfo.IME_ACTION_UNSPECIFIED); mEditText.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS | InputType.TYPE_TEXT_FLAG_MULTI_LINE); mEditText.setHint(mChipsHintText); mChipsContainer.addView(mEditText); mRootChipsLayout = new ChipsVerticalLinearLayout(getContext(), mVerticalSpacing); mRootChipsLayout.setOrientation(LinearLayout.VERTICAL); mRootChipsLayout.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)); mRootChipsLayout.setPadding(0, (int) (SPACING_TOP * mDensity), 0, 0); mChipsContainer.addView(mRootChipsLayout); initListener(); if (isInEditMode()) { // preview chips LinearLayout editModeLinLayout = new LinearLayout(getContext()); editModeLinLayout.setOrientation(LinearLayout.HORIZONTAL); mChipsContainer.addView(editModeLinLayout); View view = new Chip("Test Chip", null, new Contact(null, null, "Test", "asd@asd.de", null)).getView(); view.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED), MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED)); editModeLinLayout.addView(view); View view2 = new Chip("Indelible", null, new Contact(null, null, "Test", "asd@asd.de", null), true) .getView(); view2.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED), MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED)); editModeLinLayout.addView(view2); } }
From source file:bruce.kk.brucetodos.MainActivity.java
/** * ???// w ww. java 2s . c om * * @param position */ private void modifyItem(final int position) { final UnFinishItem item = dataList.get(position); LogDetails.d(item); LinearLayout linearLayout = new LinearLayout(MainActivity.this); LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); linearLayout.setLayoutParams(layoutParams); linearLayout.setOrientation(LinearLayout.VERTICAL); linearLayout.setBackgroundColor(getResources().getColor(android.R.color.black)); final EditText editText = new EditText(MainActivity.this); editText.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)); editText.setTextSize(TypedValue.COMPLEX_UNIT_SP, 18); editText.setTextColor(getResources().getColor(android.R.color.holo_green_light)); editText.setHint(item.content); editText.setHintTextColor(getResources().getColor(android.R.color.holo_orange_dark)); linearLayout.addView(editText); Button btnModify = new Button(MainActivity.this); btnModify.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)); btnModify.setText(""); btnModify.setTextSize(TypedValue.COMPLEX_UNIT_SP, 18); btnModify.setTextColor(getResources().getColor(android.R.color.holo_blue_bright)); btnModify.setBackgroundColor(getResources().getColor(android.R.color.black)); linearLayout.addView(btnModify); Button btnDeleteItem = new Button(MainActivity.this); btnDeleteItem.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)); btnDeleteItem.setText(""); btnDeleteItem.setTextSize(TypedValue.COMPLEX_UNIT_SP, 18); btnDeleteItem.setTextColor(getResources().getColor(android.R.color.holo_blue_bright)); btnDeleteItem.setBackgroundColor(getResources().getColor(android.R.color.black)); linearLayout.addView(btnDeleteItem); final PopupWindow popupWindow = new PopupWindow(linearLayout, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); popupWindow.setBackgroundDrawable(new BitmapDrawable()); // ? popupWindow.setTouchable(true); popupWindow.setFocusable(true); popupWindow.setOutsideTouchable(true); popupWindow.showAtLocation(contentMain, Gravity.CENTER, 0, 0); btnModify.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { LogDetails.d(": " + editText.getText().toString()); if (!TextUtils.isEmpty(editText.getText().toString().trim())) { Date date = new Date(); item.content = editText.getText().toString().trim(); item.modifyDay = date; item.finishDay = null; ProgressDialogUtils.showProgressDialog(); presenter.modifyItem(item); dataList.set(position, item); refreshData(true); popupWindow.dismiss(); } else { Toast.makeText(MainActivity.this, "~", Toast.LENGTH_SHORT).show(); } } }); btnDeleteItem.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { dataList.remove(position); presenter.deleteItem(item); refreshData(false); popupWindow.dismiss(); } }); }