1 package com.intel.realsense.camera;
3 import android.app.Activity;
4 import android.app.AlertDialog;
5 import android.app.Dialog;
6 import android.app.DialogFragment;
7 import android.graphics.Color;
8 import android.graphics.drawable.ColorDrawable;
9 import android.os.Bundle;
10 import android.util.Log;
11 import android.view.Gravity;
12 import android.view.LayoutInflater;
13 import android.view.View;
14 import android.view.ViewGroup;
15 import android.widget.BaseAdapter;
16 import android.widget.ListView;
17 import android.widget.RadioButton;
18 import android.widget.RadioGroup;
19 import android.widget.TextView;
27 import java.util.List;
44 mSelectedOptionIndex = -1;
54 final Activity activity = getActivity();
55 LayoutInflater inflater = activity.getLayoutInflater();
56 View fragmentView = inflater.inflate(
R.layout.controls_dialog, null);
61 mDevice =
devices.createDevice(0);
62 if (mDevice == null) {
63 Log.e(TAG,
"No device could be found");
64 dismissAllowingStateLoss();
69 boolean isEmitterOptionSupported =
false;
72 int indexOfCurrentEmitter = 0;
77 isEmitterOptionSupported =
true;
82 if (numOfControls > 0) {
89 if (isEmitterOptionSupported) {
94 controlParams.
mName =
"Projector";
95 controlParams.
mValues = emitterDescriptions;
100 mControlsParams[controlIndex++] = controlParams;
104 ListView controlsList = fragmentView.findViewById(
R.id.controls_list);
105 CustomAdapter customAdapter =
new CustomAdapter();
106 controlsList.setAdapter(customAdapter);
109 View closeButton = fragmentView.findViewById(
R.id.controls_close_button);
110 closeButton.setOnClickListener(
new View.OnClickListener() {
112 public void onClick(View
v) {
113 dismissAllowingStateLoss();
118 AlertDialog.Builder builder =
new AlertDialog.Builder(getActivity());
119 builder.setView(fragmentView);
120 AlertDialog rv = builder.create();
121 rv.getWindow().setBackgroundDrawable(
new ColorDrawable(
Color.TRANSPARENT));
122 rv.getWindow().setGravity(Gravity.CENTER_HORIZONTAL | Gravity.TOP);
127 String[] optionDescriptions;
130 if (
s.supports(option)) {
131 int minValue = (int)
s.getMinRange(option);
132 int maxValue = (int)
s.getMaxRange(option);
133 optionDescriptions =
new String[maxValue - minValue + 1];
134 for (
int i = minValue;
i <= maxValue; ++
i) {
135 optionDescriptions[
i] =
s.valueDescription(option,
i);
137 return optionDescriptions;
143 class CustomAdapter
extends BaseAdapter {
146 public int getCount() {
151 public Object getItem(
int position) {
156 public long getItemId(
int position) {
161 public View getView(
int position, View convertView, ViewGroup parent) {
162 final Activity activity = getActivity();
163 convertView = activity.getLayoutInflater().inflate(
R.layout.controls_dialog_row, null);
166 TextView control_name = convertView.findViewById(
R.id.control_name);
167 control_name.setText(mControlsParams[position].
mName);
170 final RadioGroup control_options = convertView.findViewById(
R.id.control_options_list);
172 for (
int i = 0;
i < mControlsParams[position].
mValues.length; ++
i) {
175 button.setText(mControlsParams[position].
mValues[
i]);
176 button.setTextColor(getResources().getColor(
R.color.white));
178 control_options.addView(button);
181 final int positionFinal = position;
182 control_options.setOnCheckedChangeListener(
new RadioGroup.OnCheckedChangeListener() {
184 public void onCheckedChanged(RadioGroup
group,
int checkedId) {
187 if (
s.supports(mControlsParams[positionFinal].
mOption)) {
IMGUI_API bool RadioButton(const char *label, bool active)
::rosgraph_msgs::Log_< std::allocator< void > > Log
::std_msgs::String_< std::allocator< void > > String
Dialog onCreateDialog(Bundle savedInstanceState)
String [] getOptionDescriptions(Option option)
detail::group1< detail::group0 > group()
List< Sensor > querySensors()
ControlParams [] mControlsParams