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.content.res.Resources;
8 import android.graphics.Color;
9 import android.graphics.drawable.ColorDrawable;
10 import android.os.Bundle;
11 import android.util.Log;
12 import android.view.Gravity;
13 import android.view.LayoutInflater;
14 import android.view.View;
15 import android.widget.RadioButton;
16 import android.widget.RadioGroup;
17 import android.widget.TextView;
23 import java.io.ByteArrayOutputStream;
24 import java.io.IOException;
25 import java.io.InputStream;
36 final Activity activity = getActivity();
37 LayoutInflater inflater = activity.getLayoutInflater();
38 View fragmentView = inflater.inflate(
R.layout.presets_dialog, null);
40 TextView
message = fragmentView.findViewById(
R.id.presets_list_title);
41 mResources = getResources();
44 mPresets = mResources.getAssets().list(
"presets");
45 }
catch (IOException
e) {
46 message.setText(
"No presets found");
50 if(mPresets.length == 0) {
51 message.setText(
"No presets found");
54 message.setText(
"Select a preset:");
57 final RadioGroup presets_group = fragmentView.findViewById(
R.id.presets_list_items);
59 for (
int i = 0;
i < mPresets.length; ++
i) {
62 button.setText(mPresets[
i].substring(0, mPresets[
i].lastIndexOf(
'.')));
63 button.setTextSize(16);
64 button.setTextColor(getResources().getColor(
R.color.white));
65 button.setChecked(
i == mSelectedItem);
66 presets_group.addView(button);
70 presets_group.setOnCheckedChangeListener(
new RadioGroup.OnCheckedChangeListener() {
72 public void onCheckedChanged(RadioGroup
group,
int checkedId) {
73 mSelectedItem = checkedId;
77 View okButton = fragmentView.findViewById(
R.id.presets_ok_button);
78 okButton.setOnClickListener(
new View.OnClickListener() {
80 public void onClick(View
v) {
83 if (
devices.getDeviceCount() == 0) {
84 Log.e(TAG,
"failed to set preset, no device found");
89 Log.e(TAG,
"failed to set preset, device not in advanced mode");
94 InputStream is = mResources.getAssets().open(
"presets/" + item);
97 ByteArrayOutputStream baos =
new ByteArrayOutputStream();
101 device.loadPresetFromJson(buffer);
102 }
catch (IOException e) {
103 Log.e(TAG,
"failed to set preset, failed to open preset file, error: " + e.getMessage());
104 }
catch (Exception e) {
105 Log.e(TAG,
"failed to set preset, error: " + e.getMessage());
111 Log.i(TAG,
"preset set to: " + finalPresets[mSelectedItem]);
112 dismissAllowingStateLoss();
117 View cancelButton = fragmentView.findViewById(
R.id.presets_cancel_button);
118 cancelButton.setOnClickListener(
new View.OnClickListener() {
120 public void onClick(View
v) {
121 dismissAllowingStateLoss();
126 AlertDialog.Builder builder =
new AlertDialog.Builder(getActivity());
127 builder.setView(fragmentView);
128 AlertDialog rv = builder.create();
129 rv.getWindow().setBackgroundDrawable(
new ColorDrawable(
Color.TRANSPARENT));
130 rv.getWindow().setGravity(Gravity.CENTER_HORIZONTAL | Gravity.TOP);
GLenum GLuint GLenum GLsizei const GLchar * message
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)
DeviceList queryDevices()