您好,在编译我的应用程序时出现这样的错误。这是什么警告,无法找到问题。 使用未经检查或不安全的操作。 重新编译-Xlint:未检查详细信息。
任何人都可以解决问题。在下面的代码中,名为selecttimeractivity的类很简单,它显示了不安全的操作并重新编译。
public class SelectTimerActivity extends AppCompatActivity {
private static final String TAG = SelectTimerActivity.class.getSimpleName();
@BindView(R.id.back)
TextView mBack;
@BindView(R.id.setTimer)
TextView mSetTimer;
@BindView(R.id.toolBar)
Toolbar mToolBar;
@BindView(R.id.customeSeekBar)
RangeSeekBar mCustomeSeekBar;
@BindView(R.id.dimming_picker)
NumberPicker mDimmingPicker;
private SharedPreferences mPref;
private SolarBLEPacket mSolarBlePacket = new SolarBLEPacket();
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_select_timer);
ButterKnife.bind(this);
mPref = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
final String[] dimmingValues = new String[]{"0%", "10%", "20%", "30%", "40%", "50%", "60%", "70%", "80%", "90%", "100%"};
initDimmingPicker(dimmingValues);
Long currentMin = 1L, currentMax = 66000L;
mCustomeSeekBar.setRangeValues(currentMin, currentMax);
attachColorToNumberPicker();
}
private void attachColorToNumberPicker() {
int count = mDimmingPicker.getChildCount();
for (int i = 0; i < count; i++) {
View child = mDimmingPicker.getChildAt(i);
if (child instanceof EditText) {
try {
Field selectorWheelPaintField = mDimmingPicker.getClass()
.getDeclaredField("mSelectorWheelPaint");
selectorWheelPaintField.setAccessible(true);
((Paint) selectorWheelPaintField.get(mDimmingPicker)).setColor(Color.WHITE);
((EditText) child).setTextColor(Color.WHITE);
mDimmingPicker.invalidate();
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
private void initDimmingPicker(String[] dimmingValues) {
mDimmingPicker.setEnabled(true);
mDimmingPicker.setMinValue(0);
mDimmingPicker.setMaxValue(dimmingValues.length - 1);
mDimmingPicker.setDisplayedValues(dimmingValues);
mDimmingPicker.setDescendantFocusability(NumberPicker.FOCUS_BLOCK_DESCENDANTS);
mDimmingPicker.setWrapSelectorWheel(false);
}
@OnClick({R.id.back, R.id.setTimer})
public void onClick(View view) {
switch (view.getId()) {
case R.id.back:
setResult(RESULT_OK, new Intent());
finish();
break;
case R.id.setTimer:
Number selectedMinValue = mCustomeSeekBar.getSelectedMinValue();
Number selectedMaxValue = mCustomeSeekBar.getSelectedMaxValue();
String timer1 = mCustomeSeekBar.convertSecondsToHMmSs(selectedMinValue.longValue());
String timer2 = mCustomeSeekBar.getDiffTime(selectedMinValue.longValue(), selectedMaxValue.longValue());
String timer1Command = buildDimDurnCmd(timer1);
String timer2Command = builtDimmOffCommand(timer2);
String brighnessCommand = builtBrightnessCommand();
mPref.edit().putString(Constants.TIMER_ONE_CMD, timer1Command).commit();
mPref.edit().putString(Constants.TIMER_TWO_CMD, timer2Command).commit();
mPref.edit().putString(Constants.BRIGHTNESS_CMD, brighnessCommand).commit();
Intent intent = new Intent();
setResult(RESULT_OK, intent);
finish();
break;
}
}
private String builtBrightnessCommand() {
final String[] dimmingValues = new String[]{"0%", "10%", "20%", "30%", "40%", "50%", "60%", "70%", "80%", "90%", "100%"};
String dimmingValue = dimmingValues[mDimmingPicker.getValue()];
String replacedString = dimmingValue.replace("%", "");
String command = "";
if (!TextUtils.isEmpty(replacedString)) {
if (replacedString.length() == 1) {
command = "bright 00" + replacedString;
} else if (replacedString.length() == 2) {
command = "bright 0" + replacedString;
} else {
command = "bright " + replacedString;
}
}
Log.d(TAG, "!! Built with Brightness Command...." + command);
return mSolarBlePacket.generatePacket(command, "00");
}
private String buildDimDurnCmd(String command) {
String[] commandArray = command.split(":");
String hour = commandArray[0];
String min = commandArray[1];
String timerCommand = "dimdurn " + hour + "h" + min;
Log.d(TAG, "!! Final Timer Command is " + timerCommand);
return mSolarBlePacket.generatePacket(timerCommand, "00");
}
private String builtDimmOffCommand(String command) {
String[] commandArray = command.split(":");
String hour = commandArray[0];
String min = commandArray[1];
String timerCommand = "dimmoff " + hour + "h" + min;
Log.d(TAG, "!! Final Timer Command is " + timerCommand);
return mSolarBlePacket.generatePacket(timerCommand, "00");
}