StreamProfileAdapter.java
Go to the documentation of this file.
1 package com.intel.realsense.camera;
2 
3 import android.app.Activity;
4 import android.content.Context;
5 import android.view.LayoutInflater;
6 import android.view.View;
7 import android.view.ViewGroup;
8 import android.widget.AdapterView;
9 import android.widget.ArrayAdapter;
10 import android.widget.CompoundButton;
11 import android.widget.Spinner;
12 import android.widget.Switch;
13 
17 
18 import java.util.ArrayList;
19 import java.util.HashSet;
20 import java.util.Set;
21 
22 public class StreamProfileAdapter extends ArrayAdapter<StreamProfileSelector> {
23  private static final int mLayoutResourceId = R.layout.stream_profile_list_view;
25  private final LayoutInflater mLayoutInflater;
26  private final Listener mListener;
27  private Context mContext;
28 
29  public StreamProfileAdapter(Context context, StreamProfileSelector[] data, Listener listener){
30  super(context, mLayoutResourceId, data);
31  mLayoutInflater = ((Activity) context).getLayoutInflater();
32  mStreamProfileCells = data;
33  mListener = listener;
34  mContext = context;
35  }
36 
37  public class Holder {
38  private Switch type;
39  private Spinner index;
40  private Spinner resolution;
41  private Spinner fps;
42  private Spinner format;
43  }
44 
45  @Override
46  public View getView(int position, View rawView, final ViewGroup parent){
47  rawView = mLayoutInflater.inflate(mLayoutResourceId, parent, false);
48  StreamProfileSelector listViewLine = mStreamProfileCells[position];
49 
50  final Holder holder;
51  holder = new Holder();
52  holder.type = rawView.findViewById(R.id.stream_type_switch);
53  holder.resolution = rawView.findViewById(R.id.resolution_spinner);
54  holder.fps = rawView.findViewById(R.id.fps_spinner);
55  holder.format = rawView.findViewById(R.id.format_spinner);
56 
57  holder.type.setText(listViewLine.getName());
58  holder.type.setChecked(listViewLine.isEnabled());
59  holder.type.setTag(position);
60 
61  createSpinners(holder, position, listViewLine);
62 
63  return rawView;
64  }
65 
66  interface Listener{
67  void onCheckedChanged(StreamProfileSelector holder);
68  }
69 
70  void createSpinners(final Holder holder, final int position, StreamProfileSelector sps){
71  Set<String> formatsSet = new HashSet<>();
72  Set<String> frameRatesSet = new HashSet<>();
73  Set<String> resolutionsSet = new HashSet<>();
74 
75  for(StreamProfile sp : sps.getProfiles()){
76  formatsSet.add(sp.getFormat().name());
77  frameRatesSet.add(String.valueOf(sp.getFrameRate()));
78  if(!sp.is(Extension.VIDEO_PROFILE))
79  continue;
81  resolutionsSet.add(String.valueOf(vsp.getWidth()) + "x" + String.valueOf(vsp.getHeight()));
82  }
83 
84  ArrayList<String> formats = new ArrayList<>(formatsSet);
85  ArrayList<String> frameRates = new ArrayList<>(frameRatesSet);
86  ArrayList<String> resolutions = new ArrayList<>(resolutionsSet);
87 
88  //formats
89  ArrayAdapter<String> formatsAdapter = new ArrayAdapter<>(mContext, android.R.layout.simple_spinner_item, formats);
90  formatsAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
91  holder.format.setAdapter(formatsAdapter);
92  holder.format.setSelection(formats.indexOf(sps.getProfile().getFormat().name()));
93  holder.format.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
94  @Override
95  public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
96  StreamProfileSelector s = mStreamProfileCells[position];
97  String str = (String) adapterView.getItemAtPosition(i);
98  s.updateFormat(str);
99  mListener.onCheckedChanged(s);
100  }
101  @Override
102  public void onNothingSelected(AdapterView<?> adapterView) { }
103  });
104 
105  //frame rates
106  ArrayAdapter<String> frameRatesAdapter = new ArrayAdapter<>(mContext, android.R.layout.simple_spinner_item, frameRates);
107  frameRatesAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
108  holder.fps.setAdapter(frameRatesAdapter);
109  holder.fps.setSelection(frameRates.indexOf(String.valueOf(sps.getProfile().getFrameRate())));
110  holder.fps.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
111  @Override
112  public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
113  StreamProfileSelector s = mStreamProfileCells[position];
114  String str = (String) adapterView.getItemAtPosition(i);
115  s.updateFrameRate(str);
116  mListener.onCheckedChanged(s);
117  }
118  @Override
119  public void onNothingSelected(AdapterView<?> adapterView) { }
120  });
121 
122  //resolutions
123  ArrayAdapter<String> resolutionsAdapter = new ArrayAdapter<>(mContext, android.R.layout.simple_spinner_item, resolutions);
124  resolutionsAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
125  holder.resolution.setAdapter(resolutionsAdapter);
126  holder.resolution.setSelection(resolutions.indexOf(sps.getResolutionString()));
127  holder.resolution.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
128  @Override
129  public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
130  StreamProfileSelector s = mStreamProfileCells[position];
131  String str = (String) adapterView.getItemAtPosition(i);
132  s.updateResolution(str);
133  mListener.onCheckedChanged(s);
134  }
135  @Override
136  public void onNothingSelected(AdapterView<?> adapterView) { }
137  });
138 
139  holder.type.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
140  @Override
141  public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
142  int position = (int) compoundButton.getTag();
143  StreamProfileSelector s = mStreamProfileCells[position];
144  s.updateEnabled(b);
145  mListener.onCheckedChanged(s);
146 
147  }
148  });
149  }
150 }
151 
GLboolean GLboolean GLboolean b
uvc_xu_option< int > super
Definition: l500-options.h:32
GLdouble s
::std_msgs::String_< std::allocator< void > > String
Definition: String.h:47
StreamProfileAdapter(Context context, StreamProfileSelector[] data, Listener listener)
View getView(int position, View rawView, final ViewGroup parent)
int i
GLboolean * data
Definition: parser.hpp:150


librealsense2
Author(s): Sergey Dorodnicov , Doron Hirshberg , Mark Horn , Reagan Lopez , Itay Carpis
autogenerated on Mon May 3 2021 02:50:11