List of usage examples for android.widget CheckBox CheckBox
public CheckBox(Context context)
From source file:org.odk.collect.android.widgets.SelectMultiWidgetGridLayout.java
@SuppressWarnings("unchecked") public SelectMultiWidgetGridLayout(Context context, FormEntryPrompt prompt) { super(context, prompt); mPrompt = prompt;// w ww .ja va2s.c o m mCheckboxes = new ArrayList<CheckBox>(); // SurveyCTO-added support for dynamic select content (from .csv files) XPathFuncExpr xPathFuncExpr = ExternalDataUtil.getSearchXPathExpression(prompt.getAppearanceHint()); if (xPathFuncExpr != null) { mItems = ExternalDataUtil.populateExternalChoices(prompt, xPathFuncExpr); } else { mItems = prompt.getSelectChoices(); } setOrientation(LinearLayout.VERTICAL); Vector<Selection> ve = new Vector<Selection>(); if (prompt.getAnswerValue() != null) { ve = (Vector<Selection>) prompt.getAnswerValue().getValue(); } WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); Display display = wm.getDefaultDisplay(); Point size = new Point(); display.getSize(size); int screenWidth = size.x; int height = size.y; int halfScreenWidth = (int) (screenWidth * 0.5); int quarterScreenWidth = (int) (halfScreenWidth * 0.5); glayout = new GridLayout(getContext()); glayout.setOrientation(0); glayout.setColumnCount(2); //glayout.setRowCount(2); int row_index = 0; int col_index = 0; if (mItems != null) { for (int i = 0; i < mItems.size(); i++) { // no checkbox group so id by answer + offset CheckBox c = new CheckBox(getContext()); c.setTag(Integer.valueOf(i)); c.setId(QuestionWidget.newUniqueId()); c.setText(prompt.getSelectChoiceText(mItems.get(i))); c.setTextSize(TypedValue.COMPLEX_UNIT_DIP, mAnswerFontsize); c.setFocusable(!prompt.isReadOnly()); c.setEnabled(!prompt.isReadOnly()); for (int vi = 0; vi < ve.size(); vi++) { // match based on value, not key if (mItems.get(i).getValue().equals(ve.elementAt(vi).getValue())) { c.setChecked(true); break; } } mCheckboxes.add(c); // when clicked, check for readonly before toggling c.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (!mCheckboxInit && mPrompt.isReadOnly()) { if (buttonView.isChecked()) { buttonView.setChecked(false); Collect.getInstance().getActivityLogger().logInstanceAction(this, "onItemClick.deselect", mItems.get((Integer) buttonView.getTag()).getValue(), mPrompt.getIndex()); } else { buttonView.setChecked(true); Collect.getInstance().getActivityLogger().logInstanceAction(this, "onItemClick.select", mItems.get((Integer) buttonView.getTag()).getValue(), mPrompt.getIndex()); } } } }); String audioURI = null; audioURI = prompt.getSpecialFormSelectChoiceText(mItems.get(i), FormEntryCaption.TEXT_FORM_AUDIO); String imageURI; if (mItems.get(i) instanceof ExternalSelectChoice) { imageURI = ((ExternalSelectChoice) mItems.get(i)).getImage(); } else { imageURI = prompt.getSpecialFormSelectChoiceText(mItems.get(i), FormEntryCaption.TEXT_FORM_IMAGE); } String videoURI = null; videoURI = prompt.getSpecialFormSelectChoiceText(mItems.get(i), "video"); String bigImageURI = null; bigImageURI = prompt.getSpecialFormSelectChoiceText(mItems.get(i), "big-image"); MediaLayout mediaLayout = new MediaLayout(getContext()); mediaLayout.setAVT(prompt.getIndex(), "." + Integer.toString(i), c, audioURI, imageURI, videoURI, bigImageURI); // mediaLayout.setAVT(index, selectionDesignator, text, audioURI, imageURI, videoURI, bigImageURI); // addView(mediaLayout); row_index = i / 2 + 1; col_index = i % 2; int orientation = display.getOrientation(); if (orientation == 1) { halfScreenWidth = height / 2; } else { halfScreenWidth = screenWidth / 2; } Spec row = GridLayout.spec(row_index); Spec col = GridLayout.spec(col_index); GridLayout.LayoutParams first = new GridLayout.LayoutParams(row, col); first.width = halfScreenWidth; // first.height = quarterScreenWidth * 2; glayout.addView(mediaLayout, first); // Last, add the dividing line between elements (except for the last element) ImageView divider = new ImageView(getContext()); divider.setBackgroundResource(android.R.drawable.divider_horizontal_bright); if (i != mItems.size() - 1) { if (col_index == 0) glayout.addView(divider); } } } addView(glayout); mCheckboxInit = false; }
From source file:de.uni_weimar.m18.anatomiederstadt.element.QuizMulti.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Inflate the layout for this fragment View view = inflater.inflate(R.layout.fragment_quiz_multi, container, false); LinearLayout linearLayout = (LinearLayout) view.findViewById(R.id.quizMultiLayout); final ArrayList<CheckBox> checkBoxes = new ArrayList<>(); for (int i = 0; i < mOptions.size(); ++i) { CheckBox checkBox = new CheckBox(getActivity()); LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); layoutParams.setMargins(16, 0, 0, 0); checkBox.setLayoutParams(layoutParams); checkBox.setText(mOptions.get(i)); linearLayout.addView(checkBox);//from w ww . jav a 2 s . co m checkBoxes.add(checkBox); } Button button = new Button(getActivity()); LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT); layoutParams.gravity = Gravity.CENTER; button.setLayoutParams(layoutParams); button.setText("Eingeben"); linearLayout.addView(button); button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // evaluate score int correct = 0; int notcorrect = 0; for (int i = 0; i < checkBoxes.size(); ++i) { if (checkBoxes.get(i).isChecked()) { if (mCorrect.get(i).equals("true")) { correct += 1; } else { notcorrect += 1; } } else { if (mCorrect.get(i).equals("false")) { //correct += 1; } else { notcorrect += 1; } } } int totalcorrect = correct - notcorrect; if (totalcorrect < 0) totalcorrect = 0; int score = totalcorrect * mPoints; // TODO: submit score submitPointsToBackend(score); String congratulations = ""; if (totalcorrect == 2) { congratulations = String.format(getString(R.string.congratulations_exact_format_string), score); } else if (totalcorrect == 1) { congratulations = String.format(getString(R.string.congratulations_not_quite_format_string), score); } else { congratulations = String.format(getString(R.string.congratulations_wrong_format_string), score); } SnackbarManager.show(Snackbar.with(getActivity()).position(Snackbar.SnackbarPosition.TOP) .margin(32, 32).backgroundDrawable(R.drawable.points_snackbar_shape).text(congratulations) .eventListener(new EventListener() { @Override public void onShow(Snackbar snackbar) { } @Override public void onShowByReplace(Snackbar snackbar) { } @Override public void onShown(Snackbar snackbar) { } @Override public void onDismiss(Snackbar snackbar) { } @Override public void onDismissByReplace(Snackbar snackbar) { } @Override public void onDismissed(Snackbar snackbar) { if (mListener != null) { mListener.onMultiClick(mTargetId); } } })); } }); return view; }
From source file:alaindc.crowdroid.View.StakeholdersActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_stakeholders); linearLayout = (LinearLayout) findViewById(R.id.subscribesLinearLayout); updateStakeButton = (Button) findViewById(R.id.updateStakeButton); sendStakeButton = (Button) findViewById(R.id.sendStakeButton); updateStakeButton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { Intent subscrIntent = new Intent(getApplicationContext(), SendIntentService.class); subscrIntent.setAction(Constants.ACTION_GETSUBSCRIPTION); getApplicationContext().startService(subscrIntent); }//from ww w . j a v a 2 s . c o m }); sendStakeButton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { try { JSONArray jsonArr = new JSONArray(); JSONObject jsonObj = new JSONObject(); jsonObj.put("user", RadioUtils.getMyDeviceId(getApplicationContext())); jsonArr.put(jsonObj); for (int i = 0; i < linearLayout.getChildCount(); i++) { View view = linearLayout.getChildAt(i); if (view instanceof CheckBox) { CheckBox c = (CheckBox) view; if (c.isChecked()) { jsonObj = new JSONObject(); jsonObj.put("id", c.getId()); jsonArr.put(jsonObj); } } } String body = jsonArr.toString(); Intent subscrIntent = new Intent(getApplicationContext(), SendIntentService.class); subscrIntent.setAction(Constants.ACTION_UPDATESUBSCRIPTION); subscrIntent.putExtra(Constants.EXTRA_BODY_UPDATESUBSCRIPTION, body); getApplicationContext().startService(subscrIntent); } catch (JSONException e) { return; } } }); Intent subscrIntent = new Intent(getApplicationContext(), SendIntentService.class); subscrIntent.setAction(Constants.ACTION_GETSUBSCRIPTION); getApplicationContext().startService(subscrIntent); BroadcastReceiver receiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { if (intent.getAction().equals(Constants.INTENTVIEW_RECEIVED_SUBSCRIPTION)) { String response = intent.getStringExtra(Constants.EXTRAVIEW_RECEIVED_SUBSCRIPTION); //Toast.makeText(getApplicationContext(), response, Toast.LENGTH_LONG).show(); linearLayout.removeAllViews(); try { JSONArray jsonArray = new JSONArray(response); for (int i = 0; i < jsonArray.length(); i++) { JSONObject jsonObject = jsonArray.getJSONObject(i); int id = jsonObject.getInt("id"); String name = jsonObject.getString("name"); boolean subscribed = jsonObject.getInt("subscribed") == 1; CheckBox checkBox = new CheckBox(getApplicationContext()); checkBox.setTextColor(Color.BLACK); checkBox.setText(name); checkBox.setId(id); checkBox.setChecked(subscribed); linearLayout.addView(checkBox); int idx = linearLayout.indexOfChild(checkBox); checkBox.setTag(Integer.toString(idx)); } } catch (JSONException e) { return; } } else { Log.d("", ""); } } }; IntentFilter rcvDataIntFilter = new IntentFilter(Constants.INTENTVIEW_RECEIVED_SUBSCRIPTION); LocalBroadcastManager.getInstance(this).registerReceiver(receiver, rcvDataIntFilter); }
From source file:at.alladin.rmbt.android.fragments.history.RMBTFilterFragment.java
@Override public View onCreateView(final LayoutInflater inflater, final ViewGroup container, final Bundle savedInstanceState) { super.onCreateView(inflater, container, savedInstanceState); view = inflater.inflate(R.layout.history_filter, container, false); deviceListView = (LinearLayout) view.findViewById(R.id.deviceList); networkListView = (LinearLayout) view.findViewById(R.id.networkList); final RelativeLayout resultLimitView = (RelativeLayout) view.findViewById(R.id.Limit25Wrapper); limit25CheckBox = (CheckBox) view.findViewById(R.id.Limit25CheckBox); if (activity.getHistoryResultLimit() == 250) limit25CheckBox.setChecked(true); else//from w w w. j av a 2 s. co m limit25CheckBox.setChecked(false); resultLimitView.setOnClickListener(new OnClickListener() { @Override public void onClick(final View v) { if (limit25CheckBox.isChecked()) { limit25CheckBox.setChecked(false); activity.setHistoryResultLimit(0); } else { limit25CheckBox.setChecked(true); activity.setHistoryResultLimit(250); } } }); devicesToShow = activity.getHistoryFilterDevicesFilter(); networksToShow = activity.getHistoryFilterNetworksFilter(); if (devicesToShow == null && networksToShow == null) { devicesToShow = new ArrayList<String>(); networksToShow = new ArrayList<String>(); } final float scale = activity.getResources().getDisplayMetrics().density; final int leftRightItem = Helperfunctions.dpToPx(5, scale); // int topBottomItem = Helperfunctions.dpToPx(5, scale); // int leftRightDiv = Helperfunctions.dpToPx(0, scale); // int topBottomDiv = Helperfunctions.dpToPx(0, scale); final int heightDiv = Helperfunctions.dpToPx(1, scale); // int topBottomImg = Helperfunctions.dpToPx(1, scale); final String historyDevices[] = activity.getHistoryFilterDevices(); if (historyDevices != null) { for (int i = 0; i < historyDevices.length; i++) { final RelativeLayout singleItemLayout = new RelativeLayout(activity); // (LinearLayout)measurememtItemView.findViewById(R.id.measurement_item); singleItemLayout.setId(i); singleItemLayout.setClickable(true); singleItemLayout.setBackgroundResource(R.drawable.list_selector); singleItemLayout.setLayoutParams( new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT)); final TextView itemTitle = new TextView(activity, null, R.style.textMediumLight); RelativeLayout.LayoutParams layout = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT); layout.addRule(RelativeLayout.ALIGN_PARENT_LEFT); layout.addRule(RelativeLayout.CENTER_VERTICAL); // itemTitle.setLayoutParams(layout); itemTitle.setGravity(Gravity.LEFT); itemTitle.setPadding(leftRightItem, 0, leftRightItem, 0); itemTitle.setText(historyDevices[i]); singleItemLayout.addView(itemTitle, layout); final CheckBox itemCheck = new CheckBox(activity); layout = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT); layout.addRule(RelativeLayout.ALIGN_PARENT_RIGHT); layout.addRule(RelativeLayout.CENTER_VERTICAL); // itemCheck.setLayoutParams(layout); itemCheck.setGravity(Gravity.RIGHT); itemCheck.setPadding(leftRightItem, 0, leftRightItem, 0); itemCheck.setOnClickListener(null); itemCheck.setClickable(false); itemCheck.setId(i + historyDevices.length); if (devicesToShow.isEmpty() || devicesToShow.contains(historyDevices[i])) itemCheck.setChecked(true); else itemCheck.setChecked(false); singleItemLayout.addView(itemCheck, layout); // layout = new // RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, // RelativeLayout.LayoutParams.WRAP_CONTENT); // singleItemLayout.setLayoutParams(layout); singleItemLayout.setOnClickListener(new OnClickListener() { @Override public void onClick(final View v) { final CheckBox check = (CheckBox) v.findViewById(v.getId() + historyDevices.length); if (check.isChecked()) { check.setChecked(false); devicesToShow.remove(historyDevices[v.getId()]); } else { check.setChecked(true); devicesToShow.add(historyDevices[v.getId()]); } } }); deviceListView.addView(singleItemLayout); final View divider = new View(activity); layout = new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, heightDiv); divider.setBackgroundResource(R.drawable.bg_trans_light_10); deviceListView.addView(divider, layout); } deviceListView.invalidate(); } final String historyNetworks[] = activity.getHistoryFilterNetworks(); if (historyNetworks != null) { for (int i = 0; i < historyNetworks.length; i++) { final RelativeLayout singleItemLayout = new RelativeLayout(activity); // (LinearLayout)measurememtItemView.findViewById(R.id.measurement_item); singleItemLayout.setId(i); singleItemLayout.setClickable(true); singleItemLayout.setBackgroundResource(R.drawable.list_selector); singleItemLayout.setLayoutParams( new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT)); final TextView itemTitle = new TextView(activity, null, R.style.textMediumLight); RelativeLayout.LayoutParams layout = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT); layout.addRule(RelativeLayout.ALIGN_PARENT_LEFT); layout.addRule(RelativeLayout.CENTER_VERTICAL); // itemTitle.setLayoutParams(layout); itemTitle.setGravity(Gravity.LEFT); itemTitle.setPadding(leftRightItem, 0, leftRightItem, 0); itemTitle.setText(historyNetworks[i]); singleItemLayout.addView(itemTitle, layout); final CheckBox itemCheck = new CheckBox(activity); layout = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT); layout.addRule(RelativeLayout.ALIGN_PARENT_RIGHT); layout.addRule(RelativeLayout.CENTER_VERTICAL); // itemCheck.setLayoutParams(layout); itemCheck.setGravity(Gravity.RIGHT); itemCheck.setPadding(leftRightItem, 0, leftRightItem, 0); itemCheck.setOnClickListener(null); itemCheck.setClickable(false); itemCheck.setId(i + historyNetworks.length); if (networksToShow.isEmpty() || networksToShow.contains(historyNetworks[i])) itemCheck.setChecked(true); else itemCheck.setChecked(false); singleItemLayout.addView(itemCheck, layout); singleItemLayout.setOnClickListener(new OnClickListener() { @Override public void onClick(final View v) { final CheckBox check = (CheckBox) v.findViewById(v.getId() + historyNetworks.length); if (check.isChecked()) { check.setChecked(false); networksToShow.remove(historyNetworks[v.getId()]); } else { check.setChecked(true); networksToShow.add(historyNetworks[v.getId()]); } System.out.println(networksToShow.toString()); } }); networkListView.addView(singleItemLayout); final View divider = new View(activity); layout = new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, heightDiv); divider.setBackgroundResource(R.drawable.bg_trans_light_10); networkListView.addView(divider, layout); } networkListView.invalidate(); } /* * // Set option as Multiple Choice. So that user can able to select * more the one option from list deviceListView.setAdapter(new * ArrayAdapter<String>(activity, * android.R.layout.simple_list_item_multiple_choice, historyDevices)); * deviceListView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE); * * for (int i = 0; i < historyDevices.length; i++) { * //deviceListView.setItemChecked(i, true); } * * deviceListView.setOnItemClickListener(new OnItemClickListener() { * * @Override public void onItemClick(AdapterView<?> l, View v, int * position, long id) { * * } * * }); * * * // Set option as Multiple Choice. So that user can able to select * more the one option from list networkListView.setAdapter(new * ArrayAdapter<String>(activity, * android.R.layout.simple_list_item_multiple_choice, networkDevices)); * networkListView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE); * * for (int i = 0; i < networkDevices.length; i++) { * networkListView.setItemChecked(i, true); } * * SparseBooleanArray checked = * deviceListView.getCheckedItemPositions(); ArrayList<String> * devicesToShow = new ArrayList<String>(); for(int i = 0; i < * checked.size()+1; i++){ if(checked.get(i)) * devicesToShow.add(historyDevices[i]); } */ return view; }
From source file:org.odk.collect.android.widgets.SelectMultiWidget.java
@SuppressWarnings("unchecked") public SelectMultiWidget(Context context, FormEntryPrompt prompt) { super(context, prompt); mPrompt = prompt;/*from w w w.j a v a 2 s. co m*/ mCheckboxes = new ArrayList<CheckBox>(); // SurveyCTO-added support for dynamic select content (from .csv files) XPathFuncExpr xPathFuncExpr = ExternalDataUtil.getSearchXPathExpression(prompt.getAppearanceHint()); if (xPathFuncExpr != null) { mItems = ExternalDataUtil.populateExternalChoices(prompt, xPathFuncExpr); } else { mItems = prompt.getSelectChoices(); } setOrientation(LinearLayout.VERTICAL); String fieldElementReference = prompt.getFormElement().getBind().getReference().toString(); fieldName = getFieldID(fieldElementReference); if (fieldName.equalsIgnoreCase("typedirt")) { if (PropertiesUtils.getiAnswer32() == 1) { setVisibility(VISIBLE); } else setVisibility(INVISIBLE); PropertiesUtils.setLayoutQuestion321(this); } if (fieldName.equalsIgnoreCase("taste1")) { if (PropertiesUtils.getiAns33() == 0) { setVisibility(INVISIBLE); } else { if (PropertiesUtils.getiAns332() == 0) { setVisibility(INVISIBLE); } else setVisibility(VISIBLE); } PropertiesUtils.setLayoutQues333(this); } Vector<Selection> ve = new Vector<Selection>(); if (prompt.getAnswerValue() != null) { ve = (Vector<Selection>) prompt.getAnswerValue().getValue(); } // int row_index = 0 ; // int col_index = 0 ; Boolean isNewRow = false; Boolean isAddDirect = false; Boolean isTextView = false; Boolean isAddDivider = false; int itemCount = 0; LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, 0.5f); if (mItems != null) { for (int i = 0; i < mItems.size(); i++) { // no checkbox group so id by answer + offset View c; //Check text of the Choice Start With ($), i must be category if (prompt.getSelectChoiceText(mItems.get(i)).startsWith("$")) { StringBuilder sb = new StringBuilder(prompt.getSelectChoiceText(mItems.get(i))); String str = sb.deleteCharAt(0).toString(); c = new TextView(getContext()); ((TextView) c).setText(str); ((TextView) c).setTextSize(TypedValue.COMPLEX_UNIT_DIP, mQuestionFontsize + 1); ((TextView) c).setTypeface(null, Typeface.BOLD_ITALIC); c.setPadding(70, 10, 10, 10); c.setId(QuestionWidget.newUniqueId()); // assign random id isNewRow = true; itemCount = 0; isTextView = true; mCheckboxes.add(new CheckBox(context)); } else { // checkbox isNewRow = true; isTextView = false; itemCount++; c = new CheckBox(getContext()); c.setTag(Integer.valueOf(i)); c.setId(QuestionWidget.newUniqueId()); ((CheckBox) c).setText(prompt.getSelectChoiceText(mItems.get(i))); ((CheckBox) c).setTextSize(TypedValue.COMPLEX_UNIT_DIP, mAnswerFontsize); c.setFocusable(!prompt.isReadOnly()); c.setEnabled(!prompt.isReadOnly()); c.setPadding(10, 10, 10, 10); ((CheckBox) c).setLineSpacing(1, 1.15f); mCheckboxes.add((CheckBox) c); } if (!isTextView) for (int vi = 0; vi < ve.size(); vi++) { // match based on value, not key if (mItems.get(i).getValue().equals(ve.elementAt(vi).getValue())) { ((CheckBox) c).setChecked(true); break; } } if (!prompt.getSelectChoiceText(mItems.get(i)).startsWith("$")) { // when clicked, check for readonly before toggling ((CheckBox) c).setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { try { if (fieldName.equalsIgnoreCase("typedirt")) { if (mItems.get((Integer) buttonView.getTag()).getValue() .equalsIgnoreCase("other")) { if (isChecked) { PropertiesUtils.getTvQuestion321Other().setVisibility(VISIBLE); PropertiesUtils.getEdQuestion321Other().setVisibility(VISIBLE); PropertiesUtils.setiAnswer321(1); PropertiesUtils.setIsOther321Checked(true); } else { PropertiesUtils.getTvQuestion321Other().setVisibility(INVISIBLE); PropertiesUtils.getEdQuestion321Other().setVisibility(INVISIBLE); PropertiesUtils.setiAnswer321(0); PropertiesUtils.setIsOther321Checked(false); } } else { PropertiesUtils.getTvQuestion321Other().setVisibility(INVISIBLE); PropertiesUtils.getEdQuestion321Other().setVisibility(INVISIBLE); if (PropertiesUtils.isIsOther321Checked() == true) { PropertiesUtils.getTvQuestion321Other().setVisibility(VISIBLE); PropertiesUtils.getEdQuestion321Other().setVisibility(VISIBLE); PropertiesUtils.setiAnswer321(1); } } } if (fieldName.equalsIgnoreCase("taste1")) { if (mItems.get((Integer) buttonView.getTag()).getValue() .equalsIgnoreCase("other_taste")) { if (isChecked) { PropertiesUtils.setiAns333(1); PropertiesUtils.getTvQues333Other().setVisibility(VISIBLE); PropertiesUtils.getEdQues333Other().setVisibility(VISIBLE); PropertiesUtils.setIsOther333Checked(true); } else { PropertiesUtils.setiAns333(0); PropertiesUtils.getTvQues333Other().setVisibility(INVISIBLE); PropertiesUtils.getEdQues333Other().setVisibility(INVISIBLE); PropertiesUtils.setIsOther333Checked(false); } } else { PropertiesUtils.getTvQues333Other().setVisibility(INVISIBLE); PropertiesUtils.getEdQues333Other().setVisibility(INVISIBLE); if (PropertiesUtils.isIsOther333Checked() == true) { PropertiesUtils.getTvQues333Other().setVisibility(VISIBLE); PropertiesUtils.getEdQues333Other().setVisibility(VISIBLE); PropertiesUtils.setiAns333(1); } } } } catch (Exception e) { e.printStackTrace(); } if (!mCheckboxInit && mPrompt.isReadOnly()) { if (buttonView.isChecked()) { buttonView.setChecked(false); Collect.getInstance().getActivityLogger().logInstanceAction(this, "onItemClick.deselect", mItems.get((Integer) buttonView.getTag()).getValue(), mPrompt.getIndex()); } else { buttonView.setChecked(true); Collect.getInstance().getActivityLogger().logInstanceAction(this, "onItemClick.select", mItems.get((Integer) buttonView.getTag()).getValue(), mPrompt.getIndex()); } } } }); } String audioURI = null; audioURI = prompt.getSpecialFormSelectChoiceText(mItems.get(i), FormEntryCaption.TEXT_FORM_AUDIO); String imageURI; if (mItems.get(i) instanceof ExternalSelectChoice) { imageURI = ((ExternalSelectChoice) mItems.get(i)).getImage(); } else { imageURI = prompt.getSpecialFormSelectChoiceText(mItems.get(i), FormEntryCaption.TEXT_FORM_IMAGE); } String videoURI = null; videoURI = prompt.getSpecialFormSelectChoiceText(mItems.get(i), "video"); String bigImageURI = null; bigImageURI = prompt.getSpecialFormSelectChoiceText(mItems.get(i), "big-image"); MediaLayout mediaLayout = new MediaLayout(getContext()); if (isTextView) { mediaLayout.setAVT(prompt.getIndex(), "." + Integer.toString(i), (TextView) c, audioURI, imageURI, videoURI, bigImageURI); } else { mediaLayout.setAVT(prompt.getIndex(), "." + Integer.toString(i), (CheckBox) c, audioURI, imageURI, videoURI, bigImageURI); } mediaLayout.setLayoutParams(params); // row_index = i/2 +1; // col_index = i%2; if (itemCount == 2) { isNewRow = false; itemCount = 0; } if (isNewRow) { ll = null; ll = new LinearLayout(getContext()); ll.setOrientation(LinearLayout.HORIZONTAL); ll.addView(mediaLayout); isNewRow = false; isAddDirect = false; isAddDivider = false; try { //if textview (category in choices) or the next element is textView , so must add direct if (isTextView || prompt.getSelectChoiceText(mItems.get(i + 1)).startsWith("$")) isAddDirect = true; } catch (Exception e) { isAddDirect = true; } if (isAddDirect) { addView(ll); isAddDivider = true; } } else { ll.addView(mediaLayout); addView(ll); isAddDivider = true; } // add the dividing line between elements (except for the last element) but not last ImageView divider = new ImageView(getContext()); divider.setBackgroundResource(android.R.drawable.divider_horizontal_bright); int size = mItems.size() / 2; // if ( (i+1)/2< size && (i+1)%2==0) { if (isAddDivider && i < mItems.size() - 1) addView(divider); // } } } mCheckboxInit = false; }
From source file:com.morlunk.mumbleclient.channel.ChannelMenu.java
@Override public boolean onMenuItemClick(MenuItem item) { boolean adding = false; switch (item.getItemId()) { case R.id.context_channel_join: mService.joinChannel(mChannel.getId()); break;//from w w w .ja v a 2s . co m case R.id.context_channel_add: adding = true; case R.id.context_channel_edit: ChannelEditFragment addFragment = new ChannelEditFragment(); Bundle args = new Bundle(); if (adding) args.putInt("parent", mChannel.getId()); else args.putInt("channel", mChannel.getId()); args.putBoolean("adding", adding); addFragment.setArguments(args); addFragment.show(mFragmentManager, "ChannelAdd"); break; case R.id.context_channel_remove: AlertDialog.Builder adb = new AlertDialog.Builder(mContext); adb.setTitle(R.string.confirm); adb.setMessage(R.string.confirm_delete_channel); adb.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { mService.removeChannel(mChannel.getId()); } }); adb.setNegativeButton(android.R.string.cancel, null); adb.show(); break; case R.id.context_channel_view_description: Bundle commentArgs = new Bundle(); commentArgs.putInt("channel", mChannel.getId()); commentArgs.putString("comment", mChannel.getDescription()); commentArgs.putBoolean("editing", false); DialogFragment commentFragment = (DialogFragment) Fragment.instantiate(mContext, ChannelDescriptionFragment.class.getName(), commentArgs); commentFragment.show(mFragmentManager, ChannelDescriptionFragment.class.getName()); break; case R.id.context_channel_pin: long serverId = mService.getConnectedServer().getId(); boolean pinned = mDatabase.isChannelPinned(serverId, mChannel.getId()); if (!pinned) mDatabase.addPinnedChannel(serverId, mChannel.getId()); else mDatabase.removePinnedChannel(serverId, mChannel.getId()); break; case R.id.context_channel_link: { IChannel channel = mService.getSessionChannel(); if (!item.isChecked()) { mService.linkChannels(channel, mChannel); } else { mService.unlinkChannels(channel, mChannel); } break; } case R.id.context_channel_unlink_all: mService.unlinkAllChannels(mChannel); break; case R.id.context_channel_shout: { AlertDialog.Builder builder = new AlertDialog.Builder(mContext); builder.setTitle(R.string.shout_configure); LinearLayout layout = new LinearLayout(mContext); layout.setOrientation(LinearLayout.VERTICAL); final CheckBox subchannelBox = new CheckBox(mContext); subchannelBox.setText(R.string.shout_include_subchannels); layout.addView(subchannelBox); final CheckBox linkedBox = new CheckBox(mContext); linkedBox.setText(R.string.shout_include_linked); layout.addView(linkedBox); builder.setView(layout); builder.setPositiveButton(R.string.confirm, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { if (mService == null || mService.getConnectionState() != JumbleService.ConnectionState.CONNECTED) return; // Unregister any existing voice target. if (mService.getVoiceTargetMode() == VoiceTargetMode.WHISPER) { mService.unregisterWhisperTarget(mService.getVoiceTargetId()); } WhisperTargetChannel channelTarget = new WhisperTargetChannel(mChannel, linkedBox.isChecked(), subchannelBox.isChecked(), null); byte id = mService.registerWhisperTarget(channelTarget); if (id > 0) { mService.setVoiceTargetId(id); } else { Toast.makeText(mContext, R.string.shout_failed, Toast.LENGTH_LONG).show(); } } }); builder.setNegativeButton(android.R.string.cancel, null); builder.show(); break; } default: return false; } return true; }
From source file:com.ae.apps.tripmeter.fragments.expenses.AddExpenseDialogFragment.java
private void addMembersToContainer() { LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); CheckBox checkBox;/*from ww w. jav a2 s.c om*/ for (ContactVo contactVo : trip.getMembers()) { checkBox = new CheckBox(getActivity()); checkBox.setLayoutParams(layoutParams); checkBox.setText(contactVo.getName()); checkBox.setTag(contactVo.getId()); checkBox.setChecked(true); // Do we require an id to be supplied for each dynamically created view? // checkBox.setid(generateViewId()); mMembersContainer.addView(checkBox); } }
From source file:fr.cph.chicago.activity.StationActivity.java
@SuppressWarnings("unchecked") @Override/*from w w w . j a v a 2 s . c o m*/ 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.emobc.android.activities.generators.FormActivityGenerator.java
private View insertCheckField(Activity activity, FormDataItem dataItem) { CheckBox checkBox = new CheckBox(activity); checkBox.setTag(dataItem.getFieldName()); return checkBox; }
From source file:syncthing.android.ui.sessionsettings.EditDevicePresenter.java
@BindingAdapter("addShareFolders") public static void addSharedFolders(LinearLayout shareFoldersContainer, EditDevicePresenter presenter) { if (presenter == null) return;/*from ww w .j a v a 2s. co m*/ shareFoldersContainer.removeAllViews(); for (Map.Entry<String, Boolean> e : presenter.sharedFolders.entrySet()) { final String id = e.getKey(); CheckBox checkBox = new CheckBox(shareFoldersContainer.getContext()); checkBox.setText(id); checkBox.setChecked(e.getValue()); shareFoldersContainer.addView(checkBox); presenter.bindingSubscriptions().add(RxCompoundButton.checkedChanges(checkBox).subscribe(checked -> { presenter.setFolderShared(id, checked); })); } }