Advertisement
Guest User

Untitled

a guest
Mar 30th, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.23 KB | None | 0 0
  1. package com.example.android.pozytywni.views;
  2.  
  3. import android.content.Context;
  4. import android.support.annotation.Nullable;
  5. import android.util.AttributeSet;
  6. import android.view.LayoutInflater;
  7. import android.view.View;
  8. import android.widget.ImageView;
  9. import android.widget.LinearLayout;
  10.  
  11. import com.example.android.pozytywni.R;
  12.  
  13. import java.util.List;
  14.  
  15. import butterknife.BindViews;
  16. import butterknife.ButterKnife;
  17.  
  18. /**
  19. * Created by Stramek on 28.03.2017.
  20. */
  21.  
  22. public class OptionsView extends LinearLayout {
  23.  
  24. @BindViews({R.id.reception, R.id.option1, R.id.option2, R.id.option3, R.id.option4, R.id.option5, R.id.option6, R.id.option7, R.id.option8})
  25. List<ImageView> optionList;
  26.  
  27. private boolean is_set;
  28.  
  29. public OptionsView(Context context, @Nullable AttributeSet attrs) {
  30. super(context, attrs);
  31. View mainView = LayoutInflater.from(context).inflate(R.layout.view_options, this);
  32. ButterKnife.bind(this, mainView);
  33.  
  34. for (ImageView imageView : optionList) {
  35. imageView.setTag(false);
  36. imageView.setAlpha(0.5f);
  37. }
  38. }
  39.  
  40. @Override
  41. protected void onFinishInflate() {
  42. super.onFinishInflate();
  43. for (ImageView imageView : optionList) {
  44. imageView.setOnClickListener(this::radioGroupLogic);
  45. }
  46. }
  47.  
  48. private void radioGroupLogic(View optionView) {
  49. if(is_set) return;
  50. Boolean tag = (Boolean) optionView.getTag();
  51. if ((tag != null) && !tag) {
  52. for (ImageView imageView : optionList) {
  53. if ((Boolean) imageView.getTag()) {
  54. imageView.setAlpha(0.5f);
  55. imageView.setTag(false);
  56. }
  57. }
  58. optionView.setAlpha(1.0f);
  59. optionView.setTag(true);
  60. is_set = true;
  61. }
  62. }
  63.  
  64. public boolean isOptionSelected() {
  65. for (View vehicle : optionList) {
  66. if ((Boolean) vehicle.getTag()) return true;
  67. }
  68. return false;
  69. }
  70.  
  71. public int getSelectedOption() {
  72. for (int i = 0; i < optionList.size(); ++i) {
  73. if ((Boolean) optionList.get(i).getTag()) return (i + 10);
  74. }
  75. return -1;
  76. }
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement