FirmwareUpdateDialog.java
Go to the documentation of this file.
1 package com.intel.realsense.camera;
2 
3 import android.app.Activity;
4 import android.app.AlertDialog;
5 import android.app.Dialog;
6 import android.app.DialogFragment;
7 import android.content.Context;
8 import android.content.Intent;
9 import android.content.SharedPreferences;
10 import android.graphics.Color;
11 import android.graphics.drawable.ColorDrawable;
12 import android.os.Bundle;
13 import android.view.LayoutInflater;
14 import android.view.View;
15 import android.widget.Button;
16 import android.widget.CheckBox;
17 import android.widget.CompoundButton;
18 import android.widget.TextView;
19 
27 
28 public class FirmwareUpdateDialog extends DialogFragment {
29 
32  private CheckBox mDontAskAgainCheckBox;
33  private TextView mMessage;
34  private TextView mTitle;
35 
36  private boolean mDontShowAgain = false;
37  private boolean mAlreadyLatestInstalled = false;
38 
42  final String fw = device.getInfo(CameraInfo.FIRMWARE_VERSION);
43  if (recFw.equals(fw)){
44  mAlreadyLatestInstalled = true;
45  return "The recommended firmware is already installed";
46  }
47  return "The firmware of the connected device is: " + fw +
48  "\n\nThe recommended firmware for this device is: " + recFw;
49  }
50 
51  @Override
52  public Dialog onCreateDialog(Bundle savedInstanceState) {
53  final Activity activity = getActivity();
54  Bundle bundle = getArguments();
55 
56  final boolean fwUpdateRequest = bundle == null ? false : bundle.getBoolean(getString(R.string.firmware_update_request), false);
57  final boolean fwUpdateRequired = bundle == null ? false : bundle.getBoolean(getString(R.string.firmware_update_required), false);
58 
59  LayoutInflater inflater = activity.getLayoutInflater();
60  View fragmentView = inflater.inflate(R.layout.firmware_update_notification, null);
61 
62  mDontAskAgainCheckBox = fragmentView.findViewById(R.id.dontAskFwUpdateCheckBox);
63  mFwUpdateButton = fragmentView.findViewById(R.id.startFwUpdateButton);
64  mSkipFwUpdateButton = fragmentView.findViewById(R.id.skipFwUpdateButton);
65  mMessage = fragmentView.findViewById(R.id.firmwareUpdateMessage);
66  mTitle = fragmentView.findViewById(R.id.firmwareUpdateTitle);
67 
68  if(fwUpdateRequest){
69  mTitle.setText("Firmware update");
70  mSkipFwUpdateButton.setText("Cancel");
71  }
72 
73  final RsContext rsContext = new RsContext();
74  try(DeviceList dl = rsContext.queryDevices()){
75  if(dl.getDeviceCount() > 0){
76  try(Device device = dl.createDevice(0)){
77  if(fwUpdateRequired)
78  mMessage.setText("The current firmware version of the connected device is not supported by this librealsense version, update is required");
79  else
80  mMessage.setText(getFirmwareUpdateMessage(device));
81  }
82  }
83  }
84 
85  mFwUpdateButton = fragmentView.findViewById(R.id.startFwUpdateButton);
86  mFwUpdateButton.setOnClickListener(new View.OnClickListener() {
87  @Override
88  public void onClick(View view) {
89  dismissAllowingStateLoss();
90  try(DeviceList dl = rsContext.queryDevices(ProductLine.DEPTH)){
91  try(Device d = dl.createDevice(0)){
92  if(d != null && d.is(Extension.UPDATABLE))
93  d.<Updatable>as(Extension.UPDATABLE).enterUpdateState();
94  else
95  dismissAllowingStateLoss();
96  }
97  }
98  }
99  });
100 
101  if (mAlreadyLatestInstalled)
102  mFwUpdateButton.setEnabled(false);
103 
104  mSkipFwUpdateButton = fragmentView.findViewById(R.id.skipFwUpdateButton);
105  mSkipFwUpdateButton.setOnClickListener(new View.OnClickListener() {
106  @Override
107  public void onClick(View view) {
108  dismissAllowingStateLoss();
109  if(!fwUpdateRequest){
110  Intent intent = new Intent(activity, PreviewActivity.class);
111  startActivity(intent);
112  }
113  }
114  });
115 
116  if(fwUpdateRequired)
117  mSkipFwUpdateButton.setVisibility(View.GONE);
118 
119  mDontAskAgainCheckBox = fragmentView.findViewById(R.id.dontAskFwUpdateCheckBox);
120  mDontAskAgainCheckBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
121  @Override
122  public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
123  SharedPreferences sharedPref = activity.getSharedPreferences(getString(R.string.app_settings), Context.MODE_PRIVATE);
124  SharedPreferences.Editor editor = sharedPref.edit();
125  mDontShowAgain = !mDontShowAgain;
126  editor.putBoolean(getString(R.string.show_update_firmware), !mDontShowAgain);
127  editor.commit();
128  }
129  });
130  if(fwUpdateRequest || fwUpdateRequired)
131  mDontAskAgainCheckBox.setVisibility(View.GONE);
132 
133  AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
134  builder.setView(fragmentView);
135  AlertDialog rv = builder.create();
136  rv.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
137  return rv;
138  }
139 }
GLboolean GLboolean GLboolean b
String getInfo(CameraInfo info)
Definition: Device.java:25
T as(const std::vector< uint8_t > &data, size_t index)
Definition: uvc-types.h:407
d
Definition: rmse.py:171
::std_msgs::String_< std::allocator< void > > String
Definition: String.h:47
Dialog onCreateDialog(Bundle savedInstanceState)
IMGUI_API bool Button(const char *label, const ImVec2 &size=ImVec2(0, 0))
Definition: imgui.cpp:5573
auto device
Definition: pyrs_net.cpp:17
boolean supportsInfo(CameraInfo info)
Definition: Device.java:21


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