private void updateMqttStatus() { if (mMqttMenuItem == null) return; // Hack: Sometimes this could have not been initialized so we don't update icons MqttManager mqttManager = mMqttManager.getInstance(this); MqttManager.MqqtConnectionStatus status = mqttManager.getClientStatus(); if (status == MqttManager.MqqtConnectionStatus.CONNECTING) { final int kConnectingAnimationDrawableIds[] = { R.drawable.mqtt_connecting1, R.drawable.mqtt_connecting2, R.drawable.mqtt_connecting3 }; mMqttMenuItem.setIcon(kConnectingAnimationDrawableIds[mMqttMenuItemAnimationFrame]); mMqttMenuItemAnimationFrame = (mMqttMenuItemAnimationFrame + 1) % kConnectingAnimationDrawableIds.length; } else if (status == MqttManager.MqqtConnectionStatus.CONNECTED) { mMqttMenuItem.setIcon(R.drawable.mqtt_connected); mMqttMenuItemAnimationHandler.removeCallbacks(mMqttMenuItemAnimationRunnable); } else { mMqttMenuItem.setIcon(R.drawable.mqtt_disconnected); mMqttMenuItemAnimationHandler.removeCallbacks(mMqttMenuItemAnimationRunnable); } }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_uart); mBleManager = BleManager.getInstance(this); restoreRetainedDataFragment(); // Choose UI controls component based on available width /* if (!kShowUartControlsInTopBar) { LinearLayout headerLayout = (LinearLayout) findViewById(R.id.headerLayout); ViewGroup controlsLayout = (ViewGroup) getLayoutInflater().inflate(R.layout.layout_uart_singleline_controls, headerLayout, false); controlsLayout.measure(0, 0); int controlWidth = controlsLayout.getMeasuredWidth(); Display display = getWindowManager().getDefaultDisplay(); Point size = new Point(); display.getSize(size); int rootWidth = size.x; if (controlWidth > rootWidth) // control too big, use a smaller version { controlsLayout = (ViewGroup) getLayoutInflater().inflate(R.layout.layout_uart_multiline_controls, headerLayout, false); } //Log.d(TAG, "width: " + controlWidth + " baseWidth: " + rootWidth); headerLayout.addView(controlsLayout); } */ // Get default theme colors TypedValue typedValue = new TypedValue(); Resources.Theme theme = getTheme(); theme.resolveAttribute(R.attr.colorPrimaryDark, typedValue, true); mTxColor = typedValue.data; theme.resolveAttribute(R.attr.colorControlActivated, typedValue, true); mRxColor = typedValue.data; // UI mBufferListView = (ListView) findViewById(R.id.bufferListView); mBufferListAdapter = new TimestampListAdapter(this, R.layout.layout_uart_datachunkitem); mBufferListView.setAdapter(mBufferListAdapter); mBufferListView.setDivider(null); mBufferTextView = (EditText) findViewById(R.id.bufferTextView); mBufferTextView.setKeyListener(null); // make it not editable mSendEditText = (EditText) findViewById(R.id.sendEditText); mSendEditText.setOnEditorActionListener( new TextView.OnEditorActionListener() { @Override public boolean onEditorAction(TextView textView, int actionId, KeyEvent keyEvent) { if (actionId == EditorInfo.IME_ACTION_SEND) { onClickSend(null); return true; } return false; } }); mSendEditText.setOnFocusChangeListener( new View.OnFocusChangeListener() { public void onFocusChange(View view, boolean hasFocus) { if (!hasFocus) { // Dismiss keyboard when sendEditText loses focus dismissKeyboard(view); } } }); mSentBytesTextView = (TextView) findViewById(R.id.sentBytesTextView); mReceivedBytesTextView = (TextView) findViewById(R.id.receivedBytesTextView); // Read shared preferences maxPacketsToPaintAsText = PreferencesFragment.getUartTextMaxPackets(this); // Log.d(TAG, "maxPacketsToPaintAsText: "+maxPacketsToPaintAsText); // Read local preferences SharedPreferences preferences = getSharedPreferences(kPreferences, MODE_PRIVATE); mShowDataInHexFormat = !preferences.getBoolean(kPreferences_asciiMode, true); final boolean isTimestampDisplayMode = preferences.getBoolean(kPreferences_timestampDisplayMode, false); setDisplayFormatToTimestamp(isTimestampDisplayMode); mIsEchoEnabled = preferences.getBoolean(kPreferences_echo, true); mIsEolEnabled = preferences.getBoolean(kPreferences_eol, true); invalidateOptionsMenu(); // udpate options menu with current values /* if (!kShowUartControlsInTopBar) { Switch mEchoSwitch; Switch mEolSwitch; mEchoSwitch = (Switch) findViewById(R.id.echoSwitch); mEchoSwitch.setChecked(mIsEchoEnabled); mEolSwitch = (Switch) findViewById(R.id.eolSwitch); mEolSwitch.setChecked(mIsEolEnabled); RadioButton asciiFormatRadioButton = (RadioButton) findViewById(R.id.asciiFormatRadioButton); asciiFormatRadioButton.setChecked(!mShowDataInHexFormat); asciiFormatRadioButton.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { mShowDataInHexFormat = !isChecked; } }); RadioButton hexFormatRadioButton = (RadioButton) findViewById(R.id.hexFormatRadioButton); hexFormatRadioButton.setChecked(mShowDataInHexFormat); hexFormatRadioButton.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { mShowDataInHexFormat = isChecked; } }); RadioButton textDisplayFormatRadioButton = (RadioButton) findViewById(R.id.textDisplayModeRadioButton); textDisplayFormatRadioButton.setChecked(!mIsTimestampDisplayMode); textDisplayFormatRadioButton.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { mIsTimestampDisplayMode = !isChecked; } }); RadioButton timestampDisplayFormatRadioButton = (RadioButton) findViewById(R.id.timestampDisplayModeRadioButton); timestampDisplayFormatRadioButton.setChecked(mIsTimestampDisplayMode); timestampDisplayFormatRadioButton.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { mIsTimestampDisplayMode = isChecked; } }); setDisplayFormatToTimestamp(mIsTimestampDisplayMode); } */ // Continue onServicesDiscovered(); // Mqtt init mMqttManager = MqttManager.getInstance(this); if (MqttSettings.getInstance(this).isConnected()) { mMqttManager.connectFromSavedSettings(this); } }