mirror of
https://github.com/aljazceru/Android-nRF-Toolbox.git
synced 2026-01-21 23:54:33 +01:00
Version 1.16.4 - Selection of EOL in UART added, support for Marshmallow in Wear
This commit is contained in:
@@ -128,9 +128,9 @@ public class UARTActivity extends BleProfileServiceReadyActivity<UARTService.UAR
|
||||
private boolean mEditMode;
|
||||
|
||||
public interface ConfigurationListener {
|
||||
public void onConfigurationModified();
|
||||
public void onConfigurationChanged(final UartConfiguration configuration);
|
||||
public void setEditMode(final boolean editMode);
|
||||
void onConfigurationModified();
|
||||
void onConfigurationChanged(final UartConfiguration configuration);
|
||||
void setEditMode(final boolean editMode);
|
||||
}
|
||||
|
||||
public void setConfigurationListener(final ConfigurationListener listener) {
|
||||
@@ -318,8 +318,7 @@ public class UARTActivity extends BleProfileServiceReadyActivity<UARTService.UAR
|
||||
return;
|
||||
}
|
||||
if (mEditMode) {
|
||||
final UARTControlFragment fragment = (UARTControlFragment) getSupportFragmentManager().findFragmentById(R.id.fragment_control);
|
||||
fragment.setEditMode(false);
|
||||
setEditMode(false);
|
||||
return;
|
||||
}
|
||||
super.onBackPressed();
|
||||
@@ -554,11 +553,12 @@ public class UARTActivity extends BleProfileServiceReadyActivity<UARTService.UAR
|
||||
}
|
||||
}
|
||||
|
||||
public void onCommandChanged(final int index, final String message, final boolean active, final int iconIndex) {
|
||||
public void onCommandChanged(final int index, final String message, final boolean active, final int eol, final int iconIndex) {
|
||||
final Command command = mConfiguration.getCommands()[index];
|
||||
|
||||
command.setCommand(message);
|
||||
command.setActive(active);
|
||||
command.setEol(eol);
|
||||
command.setIconIndex(iconIndex);
|
||||
mConfigurationListener.onConfigurationModified();
|
||||
saveConfiguration();
|
||||
@@ -808,6 +808,7 @@ public class UARTActivity extends BleProfileServiceReadyActivity<UARTService.UAR
|
||||
final Command command = new Command();
|
||||
command.setCommand(cmd);
|
||||
command.setActive(mPreferences.getBoolean(PREFS_BUTTON_ENABLED + i, false));
|
||||
command.setEol(0); // default one
|
||||
command.setIconIndex(mPreferences.getInt(PREFS_BUTTON_ICON + i, 0));
|
||||
commands[i] = command;
|
||||
}
|
||||
|
||||
@@ -102,9 +102,19 @@ public class UARTControlFragment extends Fragment implements GridView.OnItemClic
|
||||
final UARTEditDialog dialog = UARTEditDialog.getInstance(position, command);
|
||||
dialog.show(getChildFragmentManager(), null);
|
||||
} else {
|
||||
final String command = ((Command)mAdapter.getItem(position)).getCommand();
|
||||
final Command command = (Command)mAdapter.getItem(position);
|
||||
final Command.Eol eol = command.getEol();
|
||||
String text = command.getCommand();
|
||||
switch (eol) {
|
||||
case CR_LF:
|
||||
text = text.replaceAll("\n", "\r\n");
|
||||
break;
|
||||
case CR:
|
||||
text = text.replaceAll("\n", "\r");
|
||||
break;
|
||||
}
|
||||
final UARTInterface uart = (UARTInterface) getActivity();
|
||||
uart.send(command);
|
||||
uart.send(text);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -23,9 +23,7 @@
|
||||
package no.nordicsemi.android.nrftoolbox.uart;
|
||||
|
||||
import android.app.Dialog;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Bundle;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.v4.app.DialogFragment;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
@@ -41,6 +39,7 @@ import android.widget.CompoundButton;
|
||||
import android.widget.EditText;
|
||||
import android.widget.GridView;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.RadioGroup;
|
||||
|
||||
import no.nordicsemi.android.nrftoolbox.R;
|
||||
import no.nordicsemi.android.nrftoolbox.uart.domain.Command;
|
||||
@@ -48,11 +47,13 @@ import no.nordicsemi.android.nrftoolbox.uart.domain.Command;
|
||||
public class UARTEditDialog extends DialogFragment implements View.OnClickListener, GridView.OnItemClickListener {
|
||||
private final static String ARG_INDEX = "index";
|
||||
private final static String ARG_COMMAND = "command";
|
||||
private final static String ARG_EOL = "eol";
|
||||
private final static String ARG_ICON_INDEX = "iconIndex";
|
||||
private int mActiveIcon;
|
||||
|
||||
private EditText mField;
|
||||
private CheckBox mCheckBox;
|
||||
private CheckBox mActiveCheckBox;
|
||||
private RadioGroup mEOLGroup;
|
||||
private IconAdapter mIconAdapter;
|
||||
|
||||
public static UARTEditDialog getInstance(final int index, final Command command) {
|
||||
@@ -61,6 +62,7 @@ public class UARTEditDialog extends DialogFragment implements View.OnClickListen
|
||||
final Bundle args = new Bundle();
|
||||
args.putInt(ARG_INDEX, index);
|
||||
args.putString(ARG_COMMAND, command.getCommand());
|
||||
args.putInt(ARG_EOL, command.getEol().index);
|
||||
args.putInt(ARG_ICON_INDEX, command.getIconIndex());
|
||||
fragment.setArguments(args);
|
||||
|
||||
@@ -76,6 +78,7 @@ public class UARTEditDialog extends DialogFragment implements View.OnClickListen
|
||||
final Bundle args = getArguments();
|
||||
final int index = args.getInt(ARG_INDEX);
|
||||
final String command = args.getString(ARG_COMMAND);
|
||||
final int eol = args.getInt(ARG_EOL);
|
||||
final int iconIndex = args.getInt(ARG_ICON_INDEX);
|
||||
final boolean active = true; // change to active by default
|
||||
mActiveIcon = iconIndex;
|
||||
@@ -84,7 +87,7 @@ public class UARTEditDialog extends DialogFragment implements View.OnClickListen
|
||||
final View view = inflater.inflate(R.layout.feature_uart_dialog_edit, null);
|
||||
final EditText field = mField = (EditText) view.findViewById(R.id.field);
|
||||
final GridView grid = (GridView) view.findViewById(R.id.grid);
|
||||
final CheckBox checkBox = mCheckBox = (CheckBox) view.findViewById(R.id.active);
|
||||
final CheckBox checkBox = mActiveCheckBox = (CheckBox) view.findViewById(R.id.active);
|
||||
checkBox.setOnCheckedChangeListener(new CheckBox.OnCheckedChangeListener() {
|
||||
@Override
|
||||
public void onCheckedChanged(final CompoundButton buttonView, final boolean isChecked) {
|
||||
@@ -95,6 +98,20 @@ public class UARTEditDialog extends DialogFragment implements View.OnClickListen
|
||||
}
|
||||
});
|
||||
|
||||
final RadioGroup eolGroup = mEOLGroup = (RadioGroup) view.findViewById(R.id.uart_eol);
|
||||
switch (Command.Eol.values()[eol]) {
|
||||
case CR_LF:
|
||||
eolGroup.check(R.id.uart_eol_cr_lf);
|
||||
break;
|
||||
case CR:
|
||||
eolGroup.check(R.id.uart_eol_cr);
|
||||
break;
|
||||
case LF:
|
||||
default:
|
||||
eolGroup.check(R.id.uart_eol_lf);
|
||||
break;
|
||||
}
|
||||
|
||||
field.setText(command);
|
||||
field.setEnabled(active);
|
||||
checkBox.setChecked(active);
|
||||
@@ -112,13 +129,22 @@ public class UARTEditDialog extends DialogFragment implements View.OnClickListen
|
||||
|
||||
@Override
|
||||
public void onClick(final View v) {
|
||||
final boolean active = mCheckBox.isChecked();
|
||||
final boolean active = mActiveCheckBox.isChecked();
|
||||
final String command = mField.getText().toString();
|
||||
if (active && TextUtils.isEmpty(command)) {
|
||||
mField.setError(getString(R.string.uart_edit_command_error));
|
||||
return;
|
||||
int eol;
|
||||
|
||||
switch (mEOLGroup.getCheckedRadioButtonId()) {
|
||||
case R.id.uart_eol_cr_lf:
|
||||
eol = Command.Eol.CR_LF.index;
|
||||
break;
|
||||
case R.id.uart_eol_cr:
|
||||
eol = Command.Eol.CR.index;
|
||||
break;
|
||||
case R.id.uart_eol_lf:
|
||||
default:
|
||||
eol = Command.Eol.LF.index;
|
||||
break;
|
||||
}
|
||||
mField.setError(null);
|
||||
|
||||
// Save values
|
||||
final Bundle args = getArguments();
|
||||
@@ -126,7 +152,7 @@ public class UARTEditDialog extends DialogFragment implements View.OnClickListen
|
||||
|
||||
dismiss();
|
||||
final UARTActivity parent = (UARTActivity) getActivity();
|
||||
parent.onCommandChanged(index, command, active, mActiveIcon);
|
||||
parent.onCommandChanged(index, command, active, eol, mActiveIcon);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -161,7 +187,7 @@ public class UARTEditDialog extends DialogFragment implements View.OnClickListen
|
||||
}
|
||||
final ImageView image = (ImageView) view;
|
||||
image.setImageLevel(position);
|
||||
image.setActivated(position == mActiveIcon && mCheckBox.isChecked());
|
||||
image.setActivated(position == mActiveIcon && mActiveCheckBox.isChecked());
|
||||
return view;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,5 +25,5 @@ package no.nordicsemi.android.nrftoolbox.uart;
|
||||
|
||||
public interface UARTInterface {
|
||||
|
||||
public void send(final String text);
|
||||
void send(final String text);
|
||||
}
|
||||
|
||||
@@ -50,9 +50,21 @@ public class Command {
|
||||
NUMBER_8(18),
|
||||
NUMBER_9(19);
|
||||
|
||||
public int index;
|
||||
public final int index;
|
||||
|
||||
private Icon(final int index) {
|
||||
Icon(final int index) {
|
||||
this.index = index;
|
||||
}
|
||||
}
|
||||
|
||||
public enum Eol {
|
||||
LF(0),
|
||||
CR(1),
|
||||
CR_LF(2);
|
||||
|
||||
public final int index;
|
||||
|
||||
Eol(final int index) {
|
||||
this.index = index;
|
||||
}
|
||||
}
|
||||
@@ -63,6 +75,9 @@ public class Command {
|
||||
@Attribute(required = false)
|
||||
private boolean active = false;
|
||||
|
||||
@Attribute(required = false)
|
||||
private Eol eol = Eol.LF;
|
||||
|
||||
@Attribute(required = false)
|
||||
private Icon icon = Icon.LEFT;
|
||||
|
||||
@@ -78,10 +93,18 @@ public class Command {
|
||||
* Sets whether the command is active.
|
||||
* @param active true to make it active
|
||||
*/
|
||||
public void setActive(boolean active) {
|
||||
public void setActive(final boolean active) {
|
||||
this.active = active;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the new line type.
|
||||
* @param eol end of line terminator
|
||||
*/
|
||||
public void setEol(final int eol) {
|
||||
this.eol = Eol.values()[eol];
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the icon index.
|
||||
* @param index index of the icon.
|
||||
@@ -106,6 +129,14 @@ public class Command {
|
||||
return active;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the new line type.
|
||||
* @return end of line terminator
|
||||
*/
|
||||
public Eol getEol() {
|
||||
return eol;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the icon index.
|
||||
* @return the icon index
|
||||
@@ -113,4 +144,11 @@ public class Command {
|
||||
public int getIconIndex() {
|
||||
return icon.index;
|
||||
}
|
||||
/**
|
||||
* Returns the EOL index.
|
||||
* @return the EOL index
|
||||
*/
|
||||
public int getEolIndex() {
|
||||
return eol.index;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -99,6 +99,7 @@ public class UARTConfigurationSynchronizer {
|
||||
final DataMap item = new DataMap();
|
||||
item.putInt(Constants.UART.Configuration.Command.ICON_ID, command.getIconIndex());
|
||||
item.putString(Constants.UART.Configuration.Command.MESSAGE, command.getCommand());
|
||||
item.putInt(Constants.UART.Configuration.Command.EOL, command.getEolIndex());
|
||||
commands.add(item);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user