| | |
| | | import android.view.View; |
| | | import android.view.ViewGroup; |
| | | import android.view.inputmethod.EditorInfo; |
| | | import android.widget.AdapterView; |
| | | import android.widget.BaseAdapter; |
| | | |
| | | import android.widget.CheckBox; |
| | |
| | | |
| | | import androidx.annotation.NonNull; |
| | | import androidx.annotation.Nullable; |
| | | import androidx.appcompat.widget.AppCompatSpinner; |
| | | import androidx.appcompat.widget.Toolbar; |
| | | import androidx.lifecycle.Observer; |
| | | import androidx.lifecycle.ViewModelProviders; |
| | |
| | | import com.google.gson.Gson; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.Arrays; |
| | | import java.util.HashMap; |
| | | import java.util.Iterator; |
| | | import java.util.List; |
| | |
| | | |
| | | import me.yokeyword.fragmentation.SupportFragment; |
| | | import safeluck.drive.evaluation.Constant; |
| | | import safeluck.drive.evaluation.DB.WorkRoomDataBase; |
| | | import safeluck.drive.evaluation.DB.signalConfigdb.SignalConfigViewModel; |
| | | import safeluck.drive.evaluation.DB.signalConfigdb.SingalConfig; |
| | | import safeluck.drive.evaluation.R; |
| | | import safeluck.drive.evaluation.bean.SignalConfigBean; |
| | | import safeluck.drive.evaluation.bean.SignalConfigRemote; |
| | | import safeluck.drive.evaluation.util.CThreadPoolExecutor; |
| | | import safeluck.drive.evaluation.util.Utils; |
| | | |
| | | |
| | |
| | | private static final int INDEX = 1; |
| | | private static final int HIGHLEVEL = 2; |
| | | private static final int MAINBOARD = 3; |
| | | private Handler handler = new Handler(){ |
| | | @Override |
| | | public void handleMessage(Message msg) { |
| | | super.handleMessage(msg); |
| | | int id = msg.arg1; |
| | | int sig = msg.arg2; |
| | | switch (msg.what){ |
| | | case INDEX: |
| | | signalConfigViewModel.updateindex(sig,id); |
| | | break; |
| | | case HIGHLEVEL: |
| | | break; |
| | | case MAINBOARD: |
| | | break; |
| | | } |
| | | } |
| | | }; |
| | | |
| | | |
| | | private String[] arr_strs; |
| | | |
| | | |
| | | private List<SignalConfigBean> signalConfiglist =new ArrayList<>(); |
| | |
| | | } |
| | | |
| | | private void initView(View view) { |
| | | arr_strs = getResources().getStringArray(R.array.signals_name); |
| | | mToobar = view.findViewById(R.id.toolbar); |
| | | linearLayout = view.findViewById(R.id.ll_container); |
| | | mToobar.setTitle("信号配置"); |
| | |
| | | |
| | | SingalConfig singalConfig = singalConfigs.get(i); |
| | | i++; |
| | | SingalConfig singalConfig1 = singalConfigs.get(i); |
| | | signalConfiglist .add(new SignalConfigBean(singalConfig.getSignalName(),singalConfig1.getSignalName(),singalConfig.getHighLevel()==1?true:false,singalConfig.getMainBoard()==1?true:false, |
| | | singalConfig1.getHighLevel()==1?true:false,singalConfig1.getMainBoard()==1?true:false,singalConfig.getIndex(),singalConfig1.getIndex())); |
| | | mySignalsAdapter.notifyDataSetChanged(); |
| | | if (i<singalConfigs.size()){ |
| | | SingalConfig singalConfig1 = singalConfigs.get(i); |
| | | signalConfiglist .add(new SignalConfigBean(singalConfig.getSignalName(),singalConfig1.getSignalName(),singalConfig.getHighLevel()==1?true:false,singalConfig.getMainBoard()==1?true:false, |
| | | singalConfig1.getHighLevel()==1?true:false,singalConfig1.getMainBoard()==1?true:false,singalConfig.getIndex(),singalConfig1.getIndex())); |
| | | mySignalsAdapter.notifyDataSetChanged(); |
| | | } |
| | | |
| | | } |
| | | }); |
| | | |
| | |
| | | |
| | | |
| | | } |
| | | private Gson gson = new Gson(); |
| | | |
| | | |
| | | |
| | |
| | | viewHolder.checkBox1.setTag(signalConfiglist.get(position)); |
| | | viewHolder.checkBox3.setTag(signalConfiglist.get(position)); |
| | | } |
| | | viewHolder.editText1.setTag(position*2); |
| | | viewHolder.editText2.setTag((position*2+1)); |
| | | viewHolder.editText1.setTag(position*2+1); |
| | | viewHolder.editText2.setTag((2*(1+position))); |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | final SignalConfigBean signalConfigItem = getItem(position); |
| | | viewHolder.textView1.setText(signalConfigItem.getSignal_name_first()); |
| | | viewHolder.textView2.setText(signalConfigItem.getSignal_name_second()); |
| | | viewHolder.textView1.setText(String.valueOf(position*2+1)); |
| | | viewHolder.textView2.setText(String.valueOf(2*(1+position))); |
| | | |
| | | |
| | | viewHolder.editText1.setText(String.valueOf(signalConfigItem.getPort_one())); |
| | | viewHolder.editText2.setText(String.valueOf(signalConfigItem.getPort_two())); |
| | | CThreadPoolExecutor.runInBackground(new Runnable() { |
| | | @Override |
| | | public void run() { |
| | | String signName1=WorkRoomDataBase.getWorkRoomDataBase(getActivity()).getSignalConfigDao().getSignalName(position*2+1); |
| | | String s2=WorkRoomDataBase.getWorkRoomDataBase(getActivity()).getSignalConfigDao().getSignalName((position+1)*2); |
| | | |
| | | getActivity().runOnUiThread(new Runnable() { |
| | | @Override |
| | | public void run() { |
| | | |
| | | viewHolder.editText1.setSelection(getSigal2Pos(signName1)); |
| | | viewHolder.editText2.setSelection(getSigal2Pos(s2)); |
| | | } |
| | | }); |
| | | |
| | | } |
| | | }); |
| | | |
| | | |
| | | |
| | | viewHolder.checkBox1.setChecked(signalConfigItem.isOne()); |
| | | viewHolder.checkBox3.setChecked(signalConfigItem.isThree()); |
| | |
| | | class ViewHolder{ |
| | | CheckBox checkBox1; |
| | | CheckBox checkBox3; |
| | | EditText editText1; |
| | | EditText editText2; |
| | | AppCompatSpinner editText1; |
| | | AppCompatSpinner editText2; |
| | | TextView textView1; |
| | | TextView textView2; |
| | | |
| | |
| | | |
| | | editText1 = convertView.findViewById(R.id.et_signal1_port); |
| | | editText2 = convertView.findViewById(R.id.et_signal2_port); |
| | | editText1.setInputType(EditorInfo.TYPE_CLASS_NUMBER); |
| | | editText2.setInputType(EditorInfo.TYPE_CLASS_NUMBER); |
| | | editText1.setImeOptions(EditorInfo.IME_ACTION_DONE); |
| | | editText2.setImeOptions(EditorInfo.IME_ACTION_DONE); |
| | | editText1.setSingleLine(); |
| | | editText2.setSingleLine(); |
| | | |
| | | |
| | | editText1.addTextChangedListener(new TextWatcher() { |
| | | editText1.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { |
| | | @Override |
| | | public void beforeTextChanged(CharSequence s, int start, int count, int after) { |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public void onTextChanged(CharSequence s, int start, int before, int count) { |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public void afterTextChanged(Editable s) { |
| | | public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { |
| | | int pos = (int) editText1.getTag(); |
| | | String str = s.toString(); |
| | | if (!TextUtils.isEmpty(str)&& Utils.isDigital(str)){ |
| | | int a = Integer.parseInt(str); |
| | | if (a== list.get(pos).getGpio_num()){ |
| | | Log.i(TAG,String.format("Spinner1 pos=%d,position=%d对应的信号名称=%s",pos,position |
| | | ,arr_strs[position])); |
| | | signalConfigViewModel.updateindex(pos,position); |
| | | } |
| | | |
| | | }else{ |
| | | handler.removeMessages(INDEX); |
| | | Message message = Message.obtain(); |
| | | message.what = INDEX; |
| | | message.arg1 = pos; |
| | | message.arg2 = a; |
| | | handler.sendMessageDelayed(message,1500); |
| | | } |
| | | } |
| | | @Override |
| | | public void onNothingSelected(AdapterView<?> parent) { |
| | | |
| | | } |
| | | }); |
| | | editText2.addTextChangedListener(new TextWatcher() { |
| | | editText2.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { |
| | | @Override |
| | | public void beforeTextChanged(CharSequence s, int start, int count, int after) { |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public void onTextChanged(CharSequence s, int start, int before, int count) { |
| | | } |
| | | |
| | | @Override |
| | | public void afterTextChanged(Editable s) { |
| | | public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { |
| | | int pos = (int) editText2.getTag(); |
| | | String str = s.toString(); |
| | | if (!TextUtils.isEmpty(str)&& Utils.isDigital(str)){ |
| | | int a = Integer.parseInt(str); |
| | | if (a== list.get(pos).getGpio_num()){ |
| | | Log.i(TAG,String.format("Spinner2 pos=%d,position=%d对应的信号名称=%s",pos,position |
| | | ,arr_strs[position])); |
| | | signalConfigViewModel.updateindex(pos,position); |
| | | } |
| | | |
| | | }else{ |
| | | handler.removeMessages(INDEX); |
| | | Message message = Message.obtain(); |
| | | message.what = INDEX; |
| | | message.arg1 = pos; |
| | | message.arg2 = a; |
| | | handler.sendMessageDelayed(message,1500); |
| | | } |
| | | @Override |
| | | public void onNothingSelected(AdapterView<?> parent) { |
| | | |
| | | } |
| | | } |
| | | }); |
| | | |
| | | |
| | | |
| | | |
| | |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void onResume() { |
| | | super.onResume(); |
| | | Log.i(TAG, "onResume: "); |
| | | |
| | | private int getSigal2Pos(String signalConfigItem) { |
| | | for (int i = 0; i < arr_strs.length; i++) { |
| | | if (arr_strs[i].equals(signalConfigItem)){ |
| | | // Log.i(TAG,"信号名称="+signalConfigItem+" i="+i); |
| | | return i; |
| | | }else{ |
| | | continue; |
| | | } |
| | | } |
| | | return -1; |
| | | } |
| | | |
| | | @Override |
| | | public void onStop() { |
| | | super.onStop(); |
| | | Log.i(TAG, "onStop: "); |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public void onPause() { |
| | | super.onPause(); |
| | | Log.i(TAG, "onPause: "); |
| | | } |
| | | } |