List of usage examples for android.widget RadioButton setChecked
@Override public void setChecked(boolean checked)
Changes the checked state of this button.
From source file:de.evilbrain.sendtosftp.Main.java
public void serverListFill() { // Vars// ww w . j a va2s. co m JSONObject jsonServer = null; int index = 0; String actualServer = null; // clean list serverList.removeAllViews(); // get the default server and select it String defaultServer = conf.getDefaultServer(); // iterate through the server jsonServer = conf.getServer(index); while (jsonServer != null) { actualServer = config.getServerName(jsonServer); // Create radio button RadioButton RadioButton1 = new RadioButton(this); RadioButton1.setText(actualServer); RadioButton1.setId(index); // This is the default server if (defaultServer.equals(actualServer)) { RadioButton1.setChecked(true); } // Add it serverList.addView(RadioButton1); //the RadioButtons are added to the radioGroup instead of the layout index++; jsonServer = conf.getServer(index); } serverList.bringToFront(); }
From source file:com.uoit.freeroomfinder.Results.java
/** * SetupUpTableView Set all the default values for the table view and instantiate handles to the * interface elements.//from w ww . j a v a2 s . c o m * * @param inflater The inflater for the layout. * @param container The ViewGroup container for the view. * @param index The index for the table view. * * @return Returns a handle to the first table row. */ public TableRow SetupUpTableView(LayoutInflater inflater, ViewGroup container, final int index) { View newView = inflater.inflate(R.layout.room_item, container, false); TextView room = (TextView) newView.findViewById(R.id.room); TextView start = (TextView) newView.findViewById(R.id.stime); TextView end = (TextView) newView.findViewById(R.id.etime); RadioButton ch = (RadioButton) newView.findViewById(R.id.radio_button); // Provides the logic for the selectable table rows. ch.setOnClickListener(new OnClickListener() { /* * (non-Javadoc) * * @see android.view.View.OnClickListener#onClick(android.view.View) */ @Override public void onClick(View v) { RadioButton rb = (RadioButton) v; // A different row has been selected. if (checked != rb) { // Check if it's been checked the first time. if (checked != null) { checked.setChecked(false); } checked = rb; rb.setChecked(true); isNotChecked = false; } // The same row has been selected. else if (checked == rb) { rb.setChecked(isNotChecked); checked = rb; v = (View) rb; isNotChecked = !isNotChecked; } // Prepare the button if a row is selected, otherwise disable it. if (isNotChecked) { book.setEnabled(false); indexOfChecked = -1; } else { indexOfChecked = index; book.setEnabled(true); } rb.refreshDrawableState(); } }); // Grab the results and format the dates according to the values therein. Rooms first = results.get(index); room.setText(first.getRoom()); start.setText(DateTimeUtility.formatTime(new Date(first.getStartTime()))); end.setText(DateTimeUtility.formatTime(new Date(first.getEndTime()))); TableRow tr = (TableRow) newView.findViewById(R.id.room_row); // Provide the logic for selecting a table row. tr.setOnClickListener(new OnClickListener() { /* * (non-Javadoc) * * @see android.view.View.OnClickListener#onClick(android.view.View) */ @Override public void onClick(View v) { TableRow d = (TableRow) v; // Note the location of the relative layout is hard coded here as the last element in the table row. // Also, the radio button is hard coded here as the first (and only) element in the relative layout. ((RelativeLayout) d.getChildAt(d.getChildCount() - 1)).getChildAt(0).performClick(); } }); return tr; }
From source file:com.kunze.androidlocaltodo.TaskActivityFragment.java
private void InitializeViewFields(View rootView, Task task) { final EditText nameEdit = (EditText) rootView.findViewById(R.id.task_name_edit); final TextView nameStatic = (TextView) rootView.findViewById(R.id.task_name_static); nameStatic.setText(task.mName);//w ww. ja va 2 s .c om nameEdit.setText(task.mName); final TextView descriptionEdit = (TextView) rootView.findViewById(R.id.task_description_edit); descriptionEdit.setText(task.mDescription); final TextView dueDateView = (TextView) rootView.findViewById(R.id.due_date_text); SetFriendlyDueDateText(dueDateView, task.mDueDate); final Calendar dueDate = task.mDueDate; final DatePicker datePicker = (DatePicker) rootView.findViewById(R.id.due_date_calendar); datePicker.updateDate(dueDate.get(Calendar.YEAR), dueDate.get(Calendar.MONTH), dueDate.get(Calendar.DAY_OF_MONTH)); final CheckBox repeatCheck = (CheckBox) rootView.findViewById(R.id.repeat); Boolean repeat = task.mRepeatUnit != Task.RepeatUnit.NONE; repeatCheck.setChecked(repeat); SetRepeatVisibility(rootView, repeat); final EditText repeatTimeEdit = (EditText) rootView.findViewById(R.id.repeat_time); repeatTimeEdit.setText(Integer.toString(task.mRepeatTime)); final Spinner repeatUnitSpinner = (Spinner) rootView.findViewById(R.id.repeat_unit); int repeatUnitPos = 0; switch (task.mRepeatUnit) { case DAYS: repeatUnitPos = 0; break; case WEEKS: repeatUnitPos = 1; break; case MONTHS: repeatUnitPos = 2; break; case YEARS: repeatUnitPos = 3; break; case NONE: repeatUnitPos = 0; } repeatUnitSpinner.setSelection(repeatUnitPos); final RadioButton repeatFromComplete = (RadioButton) rootView.findViewById(R.id.repeat_from_complete); final RadioButton repeatFromDue = (RadioButton) rootView.findViewById(R.id.repeat_from_due); if (task.mRepeatFromComplete) { repeatFromComplete.setChecked(true); } else { repeatFromDue.setChecked(true); } }
From source file:gov.wa.wsdot.android.wsdot.ui.tollrates.SR167TollRatesFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { ViewGroup root = (ViewGroup) inflater.inflate(R.layout.fragment_dynamic_toll_rates, null); mRecyclerView = root.findViewById(R.id.my_recycler_view); mRecyclerView.setHasFixedSize(true); mLayoutManager = new LinearLayoutManager(getActivity()); mLayoutManager.setOrientation(LinearLayoutManager.VERTICAL); mRecyclerView.setLayoutManager(mLayoutManager); mAdapter = new SR167TollRatesItemAdapter(getActivity()); mRecyclerView.setAdapter(mAdapter);/*from w w w . j av a2s . com*/ mRecyclerView.addItemDecoration(new SimpleDividerItemDecoration(getActivity())); mRecyclerView.setPadding(0, 0, 0, 120); addDisclaimerView(root); directionRadioGroup = root.findViewById(R.id.segment_control); SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(getContext()); radioGroupDirectionIndex = sharedPref.getInt(getString(R.string.toll_rates_167_travel_direction_key), 0); if (radioGroupDirectionIndex == 0) { RadioButton leftSegment = root.findViewById(R.id.radio_left); leftSegment.setChecked(true); } else { RadioButton rightSegment = root.findViewById(R.id.radio_right); rightSegment.setChecked(true); } directionRadioGroup.setOnCheckedChangeListener((group, checkedId) -> { RadioButton selectedDirection = directionRadioGroup.findViewById(checkedId); mAdapter.setData(filterTollsForDirection(String.valueOf(selectedDirection.getText().charAt(0)))); mLayoutManager.scrollToPositionWithOffset(0, 0); SharedPreferences sharedPref1 = PreferenceManager.getDefaultSharedPreferences(getContext()); SharedPreferences.Editor editor = sharedPref1.edit(); radioGroupDirectionIndex = directionRadioGroup.indexOfChild(selectedDirection); TextView travelTimeView = root.findViewById(R.id.travel_time_text); travelTimeView.setText(getTravelTimeStringForDirection(radioGroupDirectionIndex == 0 ? "N" : "S")); editor.putInt(getString(R.string.toll_rates_167_travel_direction_key), radioGroupDirectionIndex); editor.apply(); }); // For some reason, if we omit this, NoSaveStateFrameLayout thinks we are // FILL_PARENT / WRAP_CONTENT, making the progress bar stick to the top of the activity. root.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); swipeRefreshLayout = root.findViewById(R.id.swipe_container); swipeRefreshLayout.setOnRefreshListener(this); swipeRefreshLayout.setColorSchemeResources(R.color.holo_blue_bright, R.color.holo_green_light, R.color.holo_orange_light, R.color.holo_red_light); mEmptyView = root.findViewById(R.id.empty_list_view); TextView header_link = root.findViewById(R.id.header_text); // create spannable string for underline SpannableString content = new SpannableString( getActivity().getResources().getString(R.string.sr167_info_link)); content.setSpan(new UnderlineSpan(), 0, content.length(), 0); header_link.setText(content); header_link.setTextColor(getResources().getColor(R.color.primary_default)); header_link.setOnClickListener(v -> { Intent intent = new Intent(); // GA tracker mTracker = ((WsdotApplication) getActivity().getApplication()).getDefaultTracker(); mTracker.setScreenName("/Toll Rates/Learn about SR-167"); mTracker.send(new HitBuilders.ScreenViewBuilder().build()); intent.setAction(Intent.ACTION_VIEW); intent.setData(Uri.parse("https://www.wsdot.wa.gov/Tolling/SR167HotLanes/HOTtollrates.htm")); startActivity(intent); }); viewModel = ViewModelProviders.of(this, viewModelFactory).get(TollRatesViewModel.class); viewModel.getResourceStatus().observe(this, resourceStatus -> { if (resourceStatus != null) { switch (resourceStatus.status) { case LOADING: swipeRefreshLayout.setRefreshing(true); break; case SUCCESS: swipeRefreshLayout.setRefreshing(false); break; case ERROR: swipeRefreshLayout.setRefreshing(false); Toast.makeText(this.getContext(), "connection error", Toast.LENGTH_LONG).show(); } } }); viewModel.getSR167TollRateItems().observe(this, tollRateGroups -> { if (tollRateGroups != null) { mEmptyView.setVisibility(View.GONE); Collections.sort(tollRateGroups, new SortTollGroupByLocation()); Collections.sort(tollRateGroups, new SortTollGroupByDirection()); tollGroups = new ArrayList<>(tollRateGroups); directionRadioGroup.getCheckedRadioButtonId(); RadioButton selectedDirection = directionRadioGroup .findViewById(directionRadioGroup.getCheckedRadioButtonId()); mAdapter.setData(filterTollsForDirection(String.valueOf(selectedDirection.getText().charAt(0)))); } }); viewModel.getTravelTimesForETLFor("167").observe(this, travelTimes -> { TextView travelTimeView = root.findViewById(R.id.travel_time_text); if (travelTimes.size() > 0) { travelTimeView.setVisibility(View.VISIBLE); this.travelTimes = new ArrayList<>(travelTimes); travelTimeView.setText(getTravelTimeStringForDirection(radioGroupDirectionIndex == 0 ? "N" : "S")); } else { travelTimeView.setVisibility(View.GONE); } }); timer = new Timer(); timer.schedule(new SR167TollRatesFragment.RatesTimerTask(), 0, 60000); // Schedule rates to update every 60 seconds return root; }
From source file:com.frostwire.android.gui.fragments.BrowsePeerFragment.java
private void changeSelectedRadioButton(byte currentFileType, byte nextFileType) { // browseFilesButtonClick(currentFileType) isn't enough, it won't update the radio button background. RadioButton currentButton = getRadioButton(currentFileType); RadioButton nextButton = getRadioButton(nextFileType); if (nextButton != null) { currentButton.setChecked(false); nextButton.setChecked(true);// ww w . j av a2 s.co m nextButton.callOnClick(); } }
From source file:com.blueverdi.rosietheriveter.SitesFragment.java
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { thisFragment = this; setRetainInstance(false);//from w w w . java2 s . com myTour = new MySqliteHelperMyTour(getActivity()); networkAvailable = Utils.isNetworkAvailable(getActivity()); buildSitesList(); view = inflater.inflate(R.layout.sites_fragment, container, false); viewContainer = (LinearLayout) view.findViewById(R.id.view_container); RadioGroup radioGroup = (RadioGroup) view.findViewById(R.id.radioGroup1); // implementation without nested fragments // first initialize the gallery view // --------------------------------- listLayout = (LinearLayout) inflater.inflate(R.layout.site_gallery_view, viewContainer, false); Display display = ((WindowManager) getActivity().getSystemService(Context.WINDOW_SERVICE)) .getDefaultDisplay(); int rotation = display.getRotation(); switch (rotation) { case Surface.ROTATION_0: case Surface.ROTATION_180: portrait = true; arrayLayout = R.layout.site_portrait; break; case Surface.ROTATION_90: case Surface.ROTATION_270: portrait = false; arrayLayout = R.layout.site_landscape; break; } // now initialize the map view // -------------------------- mapLayout = (LinearLayout) inflater.inflate(R.layout.site_map_view, viewContainer, false); try { MapsInitializer.initialize(this.getActivity()); } catch (Exception e) { e.printStackTrace(); } mapView = (MapView) mapLayout.findViewById(R.id.siteMap); mapView.onCreate(savedInstanceState); mapView.getMapAsync(new OnMapReadyCallback() { @Override public void onMapReady(GoogleMap googleMap) { map = googleMap; map.getUiSettings().setMyLocationButtonEnabled(false); if (!networkAvailable) { Toast.makeText(thisFragment.getActivity(), thisFragment.getActivity().getString(R.string.internet_required), Toast.LENGTH_LONG) .show(); } // map.setMyLocationEnabled(true); // CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngBounds(SITES, 0); // map.animateCamera(cameraUpdate); CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngBounds(SITES, 0); if (networkAvailable) { map.animateCamera(cameraUpdate); } else { map.moveCamera(cameraUpdate); } markers = new HashMap<String, Site>(); for (Site s : sites) { LatLng ll = new LatLng(Double.parseDouble(s.getString(Site.LATITUDE)), Double.parseDouble(s.getString(Site.LONGITUDE))); Marker marker = map.addMarker(new MarkerOptions().position(ll).title(s.getString(Site.NAME))); markers.put(marker.getId(), s); } map.setOnMarkerClickListener(new OnMarkerClickListener() { @Override public boolean onMarkerClick(Marker marker) { Site s = markers.get(marker.getId()); Intent i = new Intent(getActivity(), SiteActivity.class); i.putExtra(Site.PARCEL_NAME, s); SiteDetails sd = s.getDetails(); if (sd != null) { i.putExtra(SiteDetails.PARCEL_NAME, sd); } startActivity(i); getActivity().overridePendingTransition(R.anim.zoom_in, 0); return true; } }); } }); try { container.removeAllViews(); } catch (Exception e) { MyLog.d(TAG, "container evaporated inside onCreateView"); return view; } if (startInMapView) { RadioButton rb = (RadioButton) view.findViewById(R.id.radioMapView); rb.setChecked(true); setMap(); } else { setGallery(); } radioGroup.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override public void onCheckedChanged(RadioGroup group, int checkedId) { if (checkedId == R.id.radioListView) { setGallery(); } else { Toast.makeText(getActivity(), getString(R.string.getting_map), Toast.LENGTH_LONG).show(); setMap(); } } }); return view; }
From source file:com.adithya321.sharesanalysis.fragments.PurchaseShareFragment.java
private void setRecyclerViewAdapter() { sharesList = databaseHandler.getShares(); purchaseList = databaseHandler.getPurchases(); if (sharesList.size() < 1) { emptyTV.setVisibility(View.VISIBLE); arrow.setVisibility(View.VISIBLE); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { if (getResources().getConfiguration().orientation == 1) { arrow.setBackground(getResources().getDrawable(R.drawable.curved_line_vertical)); } else { arrow.setBackground((getResources().getDrawable(R.drawable.curved_line_horizontal))); }/* ww w .ja va 2s .c om*/ } } else { emptyTV.setVisibility(View.GONE); arrow.setVisibility(View.GONE); } PurchaseShareAdapter purchaseAdapter = new PurchaseShareAdapter(getContext(), purchaseList); purchaseAdapter.setOnItemClickListener(new PurchaseShareAdapter.OnItemClickListener() { @Override public void onItemClick(View itemView, int position) { final Purchase purchase = purchaseList.get(position); final Dialog dialog = new Dialog(getContext()); dialog.setTitle("Edit Share Purchase"); dialog.setContentView(R.layout.dialog_add_share_purchase); dialog.getWindow().setLayout(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.WRAP_CONTENT); dialog.show(); RadioButton newRB = (RadioButton) dialog.findViewById(R.id.radioBtn_new); RadioButton existingRB = (RadioButton) dialog.findViewById(R.id.radioBtn_existing); AutoCompleteTextView name = (AutoCompleteTextView) dialog.findViewById(R.id.share_name); newRB.setVisibility(View.GONE); existingRB.setChecked(true); name.setVisibility(View.GONE); final Spinner spinner = (Spinner) dialog.findViewById(R.id.existing_spinner); ArrayList<String> shares = new ArrayList<>(); int pos = 0; for (int i = 0; i < sharesList.size(); i++) { shares.add(sharesList.get(i).getName()); if (sharesList.get(i).getName().equals(purchase.getName())) pos = i; } ArrayAdapter<String> spinnerAdapter = new ArrayAdapter<>(getContext(), android.R.layout.simple_spinner_item, shares); spinnerAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); spinner.setAdapter(spinnerAdapter); spinner.setSelection(pos); spinner.setVisibility(View.VISIBLE); final EditText quantity = (EditText) dialog.findViewById(R.id.no_of_shares); final EditText price = (EditText) dialog.findViewById(R.id.buying_price); quantity.setText(String.valueOf(purchase.getQuantity())); price.setText(String.valueOf(purchase.getPrice())); Calendar calendar = Calendar.getInstance(); calendar.setTime(purchase.getDate()); year_start = calendar.get(Calendar.YEAR); month_start = calendar.get(Calendar.MONTH) + 1; day_start = calendar.get(Calendar.DAY_OF_MONTH); final Button selectDate = (Button) dialog.findViewById(R.id.select_date); selectDate.setText(new StringBuilder().append(day_start).append("/").append(month_start).append("/") .append(year_start)); selectDate.setOnClickListener(PurchaseShareFragment.this); Button addPurchaseBtn = (Button) dialog.findViewById(R.id.add_purchase_btn); addPurchaseBtn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Purchase p = new Purchase(); p.setId(purchase.getId()); String stringStartDate = year_start + " " + month_start + " " + day_start; DateFormat format = new SimpleDateFormat("yyyy MM dd", Locale.ENGLISH); try { Date date = format.parse(stringStartDate); p.setDate(date); } catch (Exception e) { Toast.makeText(getActivity(), "Invalid Date", Toast.LENGTH_SHORT).show(); return; } try { p.setQuantity(Integer.parseInt(quantity.getText().toString())); } catch (Exception e) { Toast.makeText(getActivity(), "Invalid Number of Shares", Toast.LENGTH_SHORT).show(); return; } try { p.setPrice(Double.parseDouble(price.getText().toString())); } catch (Exception e) { Toast.makeText(getActivity(), "Invalid Buying Price", Toast.LENGTH_SHORT).show(); return; } p.setType("buy"); p.setName(spinner.getSelectedItem().toString()); databaseHandler.updatePurchase(p); setRecyclerViewAdapter(); dialog.dismiss(); } }); } }); sharePurchasesRecyclerView.setHasFixedSize(true); sharePurchasesRecyclerView.setAdapter(purchaseAdapter); sharePurchasesRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity())); }
From source file:com.cw.litenote.config.Config.java
private void setButtonColor(RadioButton rBtn, int iBtnId) { rBtn.setBackgroundColor(ColorSet.mBG_ColorArray[iBtnId]); rBtn.setText(mItemArray[iBtnId]);/*from ww w . ja v a 2 s.com*/ rBtn.setTextColor(ColorSet.mText_ColorArray[iBtnId]); //set checked item if (iBtnId == Util.getNewPageStyle(mContext)) rBtn.setChecked(true); else rBtn.setChecked(false); }
From source file:gov.wa.wsdot.android.wsdot.ui.tollrates.I405TollRatesFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { ViewGroup root = (ViewGroup) inflater.inflate(R.layout.fragment_dynamic_toll_rates, null); mRecyclerView = root.findViewById(R.id.my_recycler_view); mRecyclerView.setHasFixedSize(true); mLayoutManager = new LinearLayoutManager(getActivity()); mLayoutManager.setOrientation(LinearLayoutManager.VERTICAL); mRecyclerView.setLayoutManager(mLayoutManager); mAdapter = new I405TollRatesItemAdapter(getActivity()); mRecyclerView.setAdapter(mAdapter);//from w ww . j a v a 2 s . c om mRecyclerView.addItemDecoration(new SimpleDividerItemDecoration(getActivity())); mRecyclerView.setPadding(0, 0, 0, 120); addDisclaimerView(root); directionRadioGroup = root.findViewById(R.id.segment_control); SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(getContext()); radioGroupDirectionIndex = sharedPref.getInt(getString(R.string.toll_rates_405_travel_direction_key), 0); if (radioGroupDirectionIndex == 0) { RadioButton leftSegment = root.findViewById(R.id.radio_left); leftSegment.setChecked(true); } else { RadioButton rightSegment = root.findViewById(R.id.radio_right); rightSegment.setChecked(true); } directionRadioGroup.setOnCheckedChangeListener((group, checkedId) -> { RadioButton selectedDirection = directionRadioGroup.findViewById(checkedId); mAdapter.setData(filterTollsForDirection(String.valueOf(selectedDirection.getText().charAt(0)))); mLayoutManager.scrollToPositionWithOffset(0, 0); SharedPreferences sharedPref1 = PreferenceManager.getDefaultSharedPreferences(getContext()); SharedPreferences.Editor editor = sharedPref1.edit(); radioGroupDirectionIndex = directionRadioGroup.indexOfChild(selectedDirection); TextView travelTimeView = root.findViewById(R.id.travel_time_text); travelTimeView.setText(getTravelTimeStringForDirection(radioGroupDirectionIndex == 0 ? "N" : "S")); editor.putInt(getString(R.string.toll_rates_405_travel_direction_key), radioGroupDirectionIndex); editor.apply(); }); // For some reason, if we omit this, NoSaveStateFrameLayout thinks we are // FILL_PARENT / WRAP_CONTENT, making the progress bar stick to the top of the activity. root.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); swipeRefreshLayout = root.findViewById(R.id.swipe_container); swipeRefreshLayout.setOnRefreshListener(this); swipeRefreshLayout.setColorSchemeResources(R.color.holo_blue_bright, R.color.holo_green_light, R.color.holo_orange_light, R.color.holo_red_light); mEmptyView = root.findViewById(R.id.empty_list_view); TextView header_link = root.findViewById(R.id.header_text); // create spannable string for underline SpannableString content = new SpannableString( getActivity().getResources().getString(R.string.i405_info_link)); content.setSpan(new UnderlineSpan(), 0, content.length(), 0); header_link.setText(content); header_link.setTextColor(getResources().getColor(R.color.primary_default)); header_link.setOnClickListener(v -> { Intent intent = new Intent(); // GA tracker mTracker = ((WsdotApplication) getActivity().getApplication()).getDefaultTracker(); mTracker.setScreenName("/Toll Rates/Learn about I-405"); mTracker.send(new HitBuilders.ScreenViewBuilder().build()); intent.setAction(Intent.ACTION_VIEW); intent.setData(Uri.parse("https://www.wsdot.wa.gov/Tolling/405/rates.htm")); startActivity(intent); }); viewModel = ViewModelProviders.of(this, viewModelFactory).get(TollRatesViewModel.class); viewModel.getResourceStatus().observe(this, resourceStatus -> { if (resourceStatus != null) { switch (resourceStatus.status) { case LOADING: swipeRefreshLayout.setRefreshing(true); break; case SUCCESS: swipeRefreshLayout.setRefreshing(false); break; case ERROR: swipeRefreshLayout.setRefreshing(false); Toast.makeText(this.getContext(), "connection error", Toast.LENGTH_LONG).show(); } } }); viewModel.getTravelTimesStatus().observe(this, resourceStatus -> { if (resourceStatus != null) { switch (resourceStatus.status) { case LOADING: break; case SUCCESS: root.findViewById(R.id.travel_time_text).setVisibility(View.VISIBLE); break; case ERROR: root.findViewById(R.id.travel_time_text).setVisibility(View.GONE); } } }); viewModel.getI405TollRateItems().observe(this, tollRateGroups -> { if (tollRateGroups != null) { mEmptyView.setVisibility(View.GONE); Collections.sort(tollRateGroups, new SortTollGroupByLocation()); Collections.sort(tollRateGroups, new SortTollGroupByDirection()); tollGroups = new ArrayList<>(tollRateGroups); directionRadioGroup.getCheckedRadioButtonId(); RadioButton selectedDirection = directionRadioGroup .findViewById(directionRadioGroup.getCheckedRadioButtonId()); mAdapter.setData(filterTollsForDirection(String.valueOf(selectedDirection.getText().charAt(0)))); } }); viewModel.getTravelTimesForETLFor("405").observe(this, travelTimes -> { TextView travelTimeView = root.findViewById(R.id.travel_time_text); if (travelTimes.size() > 0) { travelTimeView.setVisibility(View.VISIBLE); this.travelTimes = new ArrayList<>(travelTimes); travelTimeView.setText(getTravelTimeStringForDirection(radioGroupDirectionIndex == 0 ? "N" : "S")); } else { travelTimeView.setVisibility(View.GONE); } }); timer = new Timer(); timer.schedule(new RatesTimerTask(), 0, 60000); // Schedule rates to update every 60 seconds return root; }
From source file:com.nextgis.maplibui.dialog.LocalResourcesListAdapter.java
protected void setRadioButton(final RadioButton radioButton, final File file) { radioButton.setOnCheckedChangeListener(null); if (mCheckState.contains(file.getAbsolutePath())) { mUncheckBtn = radioButton;//from ww w .j a v a 2s . c om if (!radioButton.isChecked()) { radioButton.setChecked(true); } } else { if (radioButton.isChecked()) { radioButton.setChecked(false); } } radioButton.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton compoundButton, boolean b) { if (b) { if (mCheckState.isEmpty()) { mCheckState.add(file.getAbsolutePath()); } else { mCheckState.set(0, file.getAbsolutePath()); } if (null != mUncheckBtn && mUncheckBtn != radioButton) { mUncheckBtn.setChecked(false); } mUncheckBtn = radioButton; } mDialog.updateButtons(); } }); }