Updated version

- Update display on each received packet
- Cleaned up layout
- Proper handling of signs for register display
This commit is contained in:
Adrian Rumpold
2017-06-11 16:47:59 +02:00
parent 1322ec2664
commit b2ffcab986
13 changed files with 480 additions and 665 deletions

View File

@@ -1,13 +1,13 @@
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
compileSdkVersion 25
buildToolsVersion "26.0.0"
defaultConfig {
applicationId "rumpold.de.androiddsky"
minSdkVersion 21
targetSdkVersion 23
targetSdkVersion 25
versionCode 1
versionName "1.0"
}
@@ -22,6 +22,8 @@ android {
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.4.0'
compile 'com.android.support:support-v4:23.4.0'
def supportLibVersion = "25.4.0"
compile "com.android.support:appcompat-v7:$supportLibVersion"
compile "com.android.support:support-v4:$supportLibVersion"
}

View File

@@ -7,8 +7,6 @@ import java.io.IOException;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import de.rumpold.androiddsky.network.YaAgcClient;
import de.rumpold.androiddsky.ui.DSKYActivity;
@@ -17,8 +15,7 @@ import de.rumpold.androiddsky.ui.DSKYActivity;
* Created by Adriano on 17.05.2016.
*/
public class DSKY {
public static final String TAG = "TAG";
public static final int UPDATE_RATE = 25;
private static final String TAG = "TAG";
private final DSKYActivity activity;
private final YaAgcClient client;
@@ -30,9 +27,10 @@ public class DSKY {
private char signR1;
private char signR2;
private char signR3;
private String[] register1 = new String[5];
private String[] register2 = new String[5];
private String[] register3 = new String[5];
private char[] register1 = new char[5];
private char[] register2 = new char[5];
private char[] register3 = new char[5];
private boolean compActy;
private boolean uplinkActy;
@@ -47,9 +45,9 @@ public class DSKY {
private boolean oprErr;
private boolean stby;
private boolean restart;
private final ScheduledThreadPoolExecutor executor;
private final Map<String, Integer> keycodeMap = new HashMap<>();
{
keycodeMap.put("0", 16);
keycodeMap.put("1", 1);
@@ -69,17 +67,20 @@ public class DSKY {
keycodeMap.put("ENTR", 28);
keycodeMap.put("CLR", 30);
keycodeMap.put("NOUN", 31);
keycodeMap.put("PRO", 1 << 13);
}
public DSKY(DSKYActivity activity) {
this.activity = activity;
this.client = new YaAgcClient(this);
this.executor = new ScheduledThreadPoolExecutor(1);
Arrays.fill(register1, ' ');
Arrays.fill(register2, ' ');
Arrays.fill(register3, ' ');
}
Arrays.fill(register1, "");
Arrays.fill(register2, "");
Arrays.fill(register3, "");
public DSKYActivity getActivity() {
return activity;
}
public void connect() {
@@ -93,10 +94,9 @@ public class DSKY {
}
}
});
}
executor.scheduleAtFixedRate(new Runnable() {
@Override
public void run() {
public void refreshDisplay() {
activity.updateIndicator(R.id.lbl_gimbalLock, gimbalLock);
activity.updateIndicator(R.id.lbl_noAtt, noAtt);
activity.updateIndicator(R.id.lbl_uplinkActy, uplinkActy);
@@ -112,24 +112,21 @@ public class DSKY {
activity.updateDisplay(R.id.lbl_verb, verb);
activity.updateDisplay(R.id.lbl_noun, noun);
activity.updateDisplay(R.id.lbl_R1, concat(register1));
activity.updateDisplay(R.id.lbl_R2, concat(register2));
activity.updateDisplay(R.id.lbl_R3, concat(register3));
activity.updateDisplay(R.id.lbl_R1, join(register1));
activity.updateDisplay(R.id.lbl_R2, join(register2));
activity.updateDisplay(R.id.lbl_R3, join(register3));
activity.updateDisplay(R.id.lbl_sign_R1, String.valueOf(signR1));
activity.updateDisplay(R.id.lbl_sign_R2, String.valueOf(signR2));
activity.updateDisplay(R.id.lbl_sign_R3, String.valueOf(signR3));
}
}, UPDATE_RATE, UPDATE_RATE, TimeUnit.MILLISECONDS);
}
private String concat(String[] array) {
final StringBuffer buffer = new StringBuffer();
for (int i = 0; i < array.length; i++) {
buffer.append(array[i]);
private static String join(char[] chars) {
final StringBuilder builder = new StringBuilder(chars.length);
for (char ch : chars) {
builder.append(ch);
}
return buffer.toString();
return builder.toString();
}
public void disconnect() {
@@ -143,8 +140,6 @@ public class DSKY {
}
}
});
executor.shutdownNow();
}
public void setCompActy(boolean compActy) {
@@ -211,46 +206,59 @@ public class DSKY {
this.verb = verb;
}
public void setRegister1(int index, String digit) {
public void setRegister1(int index, char digit) {
Log.d(TAG, "setRegister1: " + index + ", " + digit);
this.register1[index] = digit;
}
public void setRegister2(int index, String digit) {
public void setRegister2(int index, char digit) {
Log.d(TAG, "setRegister2: " + index + ", " + digit);
this.register2[index] = digit;
}
public void setRegister3(int index, String digit) {
public void setRegister3(int index, char digit) {
Log.d(TAG, "setRegister3: " + index + ", " + digit);
this.register3[index] = digit;
}
public void setSignR1(char signR1) {
this.signR1 = signR1;
public void setSignR1(boolean signR1P, boolean signR1N) {
if (signR1N == signR1P) {
signR1 = ' ';
} else if (signR1P) {
signR1 = '+';
} else {
signR1 = '-';
}
}
public void setSignR2(char signR2) {
this.signR2 = signR2;
public void setSignR2(boolean signR2P, boolean signR2N) {
if (signR2N == signR2P) {
signR2 = ' ';
} else if (signR2P) {
signR2 = '+';
} else {
signR2 = '-';
}
}
public void setSignR3(char signR3) {
this.signR3 = signR3;
public void setSignR3(boolean signR3P, boolean signR3N) {
if (signR3N == signR3P) {
signR3 = ' ';
} else if (signR3P) {
signR3 = '+';
} else {
signR3 = '-';
}
}
public void buttonPressed(final String button) {
Log.d(TAG, "buttonPressed: " + button);
AsyncTask.execute(new Runnable() {
@Override
public void run() {
try {
if ("PRO".equals(button)) {
client.sendProceed();
} else {
final Integer keyCode = keycodeMap.get(button);
client.sendKeyCode(keyCode);
}
} catch (IOException e) {
Log.w(TAG, "buttonPressed: Could not send key press", e);
}

View File

@@ -1,13 +1,15 @@
package de.rumpold.androiddsky.network;
import android.util.Log;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
/**
* Created by Adriano on 17.05.2016.
*/
public class AgcPacket {
public static final int PACKET_LENGTH = 4;
private static final int PACKET_LENGTH = 4;
private static final String TAG = AgcPacket.class.getSimpleName();
private final boolean u;
private final boolean t;
@@ -31,19 +33,10 @@ public class AgcPacket {
*/
public static AgcPacket parseAgcPacket(ByteBuffer bytes) {
try {
bytes.rewind();
/*final StringBuilder sb = new StringBuilder();
for (byte b : bytes.array()) {
sb.append(String.format("%8s", Integer.toBinaryString(((int) b) & 0xff)).replace(' ', '0'));
sb.append(' ');
}
Log.d("AGCPacket", "AgcPacket: " + sb.toString());*/
bytes.order(ByteOrder.BIG_ENDIAN);
if (bytes.remaining() != PACKET_LENGTH) {
// invalid packet length
throw new IllegalArgumentException("packet length");
//throw new IllegalArgumentException("packet length, " + bytes.remaining() + " != " + PACKET_LENGTH);
return null;
}
/* PARSE BYTE #1 */
@@ -80,14 +73,16 @@ public class AgcPacket {
return new AgcPacket(dataCode, u, t, ioPort);
} catch (Exception e) {
Log.w(TAG, "parseAgcPacket: ", e);
return null;
}
}
private static void validateByteHeader(char c, int byteNum) {
if ((c & 0b1100_0000) >> 6 != byteNum) {
final int header = (c & 0b1100_0000) >> 6;
if (header != byteNum) {
// invalid byte header
throw new IllegalArgumentException("packet byte header in byte #" + byteNum);
throw new IllegalArgumentException("packet byte header in byte #" + byteNum + ", got " + header);
}
}
@@ -99,14 +94,6 @@ public class AgcPacket {
return ioPort;
}
public boolean t() {
return t;
}
public boolean u() {
return u;
}
@Override
public String toString() {
return "AgcPacket{" +

View File

@@ -1,6 +1,7 @@
package de.rumpold.androiddsky.network;
import android.util.Log;
import android.widget.Toast;
import java.io.IOException;
import java.net.InetSocketAddress;
@@ -13,32 +14,50 @@ import de.rumpold.androiddsky.DSKY;
* Created by Adriano on 17.05.2016.
*/
public class YaAgcClient {
public static final int YAAGC_SERVER_PORT = 19698;
private static final String TAG = "YaAGC client";
public static final int KEYBOARD_CHANNEL = 015;
private final DSKY dsky;
private static final String YAAGC_HOST = "192.168.178.67";
private static final int YAAGC_SERVER_PORT = 19698;
private static final String TAG = YaAgcClient.class.getSimpleName();
private static final int KEYBOARD_CHANNEL = 015;
private final DSKY dsky;
private SocketChannel agcChannel;
private Thread handler;
/* Last state of the +/- indicators for each register */
private boolean lastR1P = false;
private boolean lastR1N = false;
private boolean lastR2P = false;
private boolean lastR2N = false;
private boolean lastR3P = false;
private boolean lastR3N = false;
private class DSKYHandler implements Runnable {
@Override
public void run() {
final ByteBuffer buf = ByteBuffer.allocate(4);
final ByteBuffer buf = ByteBuffer.allocate(64);
while (!Thread.interrupted()) {
try {
buf.rewind();
if (!agcChannel.isConnected()) {
Thread.sleep(500);
Thread.sleep(100);
continue;
}
agcChannel.read(buf);
buf.rewind();
int numRead = agcChannel.read(buf);
buf.rewind();
handleAgcPacket(AgcPacket.parseAgcPacket(buf));
final int subPacketCount = numRead / 4;
for (int index = 0; index < subPacketCount; ++index) {
final ByteBuffer subPacket = (ByteBuffer) buf.slice().limit(4);
handleAgcPacket(AgcPacket.parseAgcPacket(subPacket));
buf.position(buf.position() + 4);
}
} catch (IOException | InterruptedException e) {
e.printStackTrace();
Toast.makeText(dsky.getActivity().getApplicationContext(),
"Connection failure",
Toast.LENGTH_SHORT).show();
Log.w(TAG, "Connection error", e);
}
}
}
@@ -50,7 +69,7 @@ public class YaAgcClient {
public void connect() throws IOException {
agcChannel = SocketChannel.open();
agcChannel.connect(new InetSocketAddress("137.250.170.198", YAAGC_SERVER_PORT));
agcChannel.connect(new InetSocketAddress(YAAGC_HOST, YAAGC_SERVER_PORT));
handler = new Thread(new DSKYHandler(), "DSKY I/O Handler");
handler.start();
@@ -68,16 +87,11 @@ public class YaAgcClient {
agcChannel.close();
}
public void sendProceed() throws IOException {
sendChannelOutput(KEYBOARD_CHANNEL, 1 << 13);
}
public void sendKeyCode(int keyCode) throws IOException {
sendChannelOutput(KEYBOARD_CHANNEL, keyCode);
}
protected void sendChannelOutput(int channel, int data) throws IOException {
private void sendChannelOutput(int channel, int data) throws IOException {
final byte[] packet = new byte[]{
(byte) (((channel >> 3) & 0b1111) & 0xff),
(byte) ((0b0100_0000 | (channel & 0b111) << 3 | ((data >> 12) & 0b111)) & 0xff),
@@ -90,55 +104,94 @@ public class YaAgcClient {
agcChannel.write(buffer);
}
protected String extractDigit(int digitCode) {
private char extractDigit(int digitCode) {
switch (digitCode) {
case 0:
return " ";
return ' ';
case 21:
return "0";
return '0';
case 3:
return "1";
return '1';
case 25:
return "2";
return '2';
case 27:
return "3";
return '3';
case 15:
return "4";
return '4';
case 30:
return "5";
return '5';
case 28:
return "6";
return '6';
case 19:
return "7";
return '7';
case 29:
return "8";
return '8';
case 31:
return "9";
return '9';
default:
throw new IllegalArgumentException("Invalid TAG digit code: " + digitCode);
throw new IllegalArgumentException("Invalid digit code: " + digitCode);
}
}
protected void handleAgcPacket(AgcPacket packet) {
private void handleAgcPacket(AgcPacket packet) {
if (packet == null) {
return;
}
switch (packet.getIoPort()) {
case 010: {
// TAG 7-segment displays
case 010:
handleChannel10(packet);
break;
case 011:
handleChannel11(packet);
break;
}
// Update register sign indicator displays
dsky.setSignR1(lastR1P, lastR1N);
dsky.setSignR2(lastR2P, lastR2N);
dsky.setSignR3(lastR3P, lastR3N);
dsky.refreshDisplay();
}
/**
* Handle changes of the indicator lights, transmitted on I/O channel 11
*
* @param packet
*/
private void handleChannel11(AgcPacket packet) {
final boolean compActy = (packet.getDataCode() & 0b0000_0010) != 0;
final boolean uplinkActy = (packet.getDataCode() & 0b0000_0100) != 0;
final boolean temp = (packet.getDataCode() & 0b0000_1000) != 0;
dsky.setCompActy(compActy);
dsky.setUplinkActy(uplinkActy);
dsky.setTemp(temp);
Log.d(TAG, String.format("[DSKY indicators] compActy = %s, uplinkActy = %s, temp = %s",
compActy, uplinkActy, temp));
}
/**
* Handle changes of display segments, transmitted on I/O channel 10
*
* @param packet
*/
private void handleChannel10(AgcPacket packet) {
final int digitIdx = (packet.getDataCode() >> 11) & 0b1111;
final int data = packet.getDataCode() & 0b1_11111_11111;
@@ -149,8 +202,7 @@ public class YaAgcClient {
switch (digitIdx) {
case 11: {
// PROG digits
final String prog = extractDigit(c) + extractDigit(d);
final String prog = "" + extractDigit(c) + extractDigit(d);
dsky.setProg(prog);
Log.d(TAG, "[DSKY PROG] " + prog);
@@ -159,7 +211,7 @@ public class YaAgcClient {
case 10: {
// Verb digits
final String verb = extractDigit(c) + extractDigit(d);
final String verb = "" + extractDigit(c) + extractDigit(d);
dsky.setVerb(verb);
Log.d(TAG, "[DSKY VERB] " + verb);
@@ -168,7 +220,7 @@ public class YaAgcClient {
case 9: {
// Noun digits
final String noun = extractDigit(c) + extractDigit(d);
final String noun = "" + extractDigit(c) + extractDigit(d);
dsky.setNoun(noun);
Log.d(TAG, "[DSKY NOUN] " + noun);
@@ -185,7 +237,10 @@ public class YaAgcClient {
// 2nd & 3rd digit of R1, + sign R1
dsky.setRegister1(1, extractDigit(c));
dsky.setRegister1(2, extractDigit(d));
dsky.setSignR1(b > 0 ? '+' : ' ');
lastR1P = b > 0;
if (lastR1P) {
lastR1N = false;
}
break;
}
@@ -193,7 +248,10 @@ public class YaAgcClient {
// 4th & 5th digit of R1, - sign R1
dsky.setRegister1(3, extractDigit(c));
dsky.setRegister1(4, extractDigit(d));
dsky.setSignR1(b > 0 ? '-' : ' ');
lastR1N = b > 0;
if (lastR1N) {
lastR1P = false;
}
break;
}
@@ -201,7 +259,7 @@ public class YaAgcClient {
// 1st & 2nd digit of R2, + sign R2
dsky.setRegister2(0, extractDigit(c));
dsky.setRegister2(1, extractDigit(d));
dsky.setSignR2(b > 0 ? '+' : ' ');
lastR2P = b > 0;
break;
}
@@ -209,7 +267,7 @@ public class YaAgcClient {
// 3rd & 4th digit of R2, - sign R2
dsky.setRegister2(2, extractDigit(c));
dsky.setRegister2(3, extractDigit(d));
dsky.setSignR2(b > 0 ? '-' : ' ');
lastR2N = b > 0;
break;
}
@@ -224,7 +282,7 @@ public class YaAgcClient {
// 2nd & 3rd digit of R3, + sign R3
dsky.setRegister3(1, extractDigit(c));
dsky.setRegister3(2, extractDigit(d));
dsky.setSignR3(b > 0 ? '+' : ' ');
lastR3P = b > 0;
break;
}
@@ -232,7 +290,7 @@ public class YaAgcClient {
// 4th & 5th digit of R3, - sign R3
dsky.setRegister3(3, extractDigit(c));
dsky.setRegister3(4, extractDigit(d));
dsky.setSignR3(b > 0 ? '-' : ' ');
lastR3N = b > 0;
break;
}
@@ -256,30 +314,6 @@ public class YaAgcClient {
vel, noAtt, alt, gimbalLock, tracker, prog));
break;
}
default:
}
break;
}
case 011: {
// TAG indicator lights
final boolean compActy = (packet.getDataCode() & 0b0000_0010) != 0;
final boolean uplinkActy = (packet.getDataCode() & 0b0000_0100) != 0;
final boolean temp = (packet.getDataCode() & 0b0000_1000) != 0;
dsky.setCompActy(compActy);
dsky.setUplinkActy(uplinkActy);
dsky.setTemp(temp);
Log.d(TAG, String.format("[DSKY indicators] compActy = %s, uplinkActy = %s, temp = %s",
compActy, uplinkActy, temp));
break;
}
default:
}
}
}

View File

@@ -1,13 +1,10 @@
package de.rumpold.androiddsky.ui;
import android.annotation.SuppressLint;
import android.graphics.Color;
import android.os.Bundle;
import android.os.Handler;
import android.support.annotation.IdRes;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.view.MotionEvent;
import android.view.HapticFeedbackConstants;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
@@ -20,91 +17,45 @@ import de.rumpold.androiddsky.R;
* status bar and navigation/system bar) with user interaction.
*/
public class DSKYActivity extends AppCompatActivity {
/**
* Whether or not the system UI should be auto-hidden after
* {@link #AUTO_HIDE_DELAY_MILLIS} milliseconds.
*/
private static final boolean AUTO_HIDE = true;
/**
* If {@link #AUTO_HIDE} is set, the number of milliseconds to wait after
* user interaction before hiding the system UI.
*/
private static final int AUTO_HIDE_DELAY_MILLIS = 3000;
/**
* Some older devices needs a small delay between UI widget updates
* and a change of the status and navigation bar.
*/
private static final int UI_ANIMATION_DELAY = 300;
private final Handler mHideHandler = new Handler();
private View mContentView;
private final Runnable mHidePart2Runnable = new Runnable() {
@SuppressLint("InlinedApi")
@Override
public void run() {
// Delayed removal of status and navigation bar
// Note that some of these constants are new as of API 16 (Jelly Bean)
// and API 19 (KitKat). It is safe to use them, as they are inlined
// at compile-time and do nothing on earlier devices.
mContentView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE
| View.SYSTEM_UI_FLAG_FULLSCREEN
| View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
}
};
private View mControlsView;
private final Runnable mShowPart2Runnable = new Runnable() {
@Override
public void run() {
// Delayed display of UI elements
ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
actionBar.show();
}
mControlsView.setVisibility(View.VISIBLE);
}
};
private boolean mVisible;
private final Runnable mHideRunnable = new Runnable() {
@Override
public void run() {
hide();
}
};
private final Handler mViewHandler = new Handler();
private final DSKY dsky = new DSKY(this);
private int rightActiveColor;
private int activeColor;
private int passiveColor;
public void updateIndicator(@IdRes final int id, final boolean state) {
mHideHandler.post(new Runnable() {
mViewHandler.post(new Runnable() {
@Override
public void run() {
TextView indicator = (TextView) findViewById(id);
if (indicator != null) {
if (indicator == null) {
return;
}
if (state) {
final int color;
if ("right".equals(indicator.getTag())) {
color = getResources().getColor(R.color.indicatorRightActive);
color = rightActiveColor;
} else {
color = getResources().getColor(R.color.indicatorActive);
color = activeColor;
}
indicator.setBackgroundColor(color);
} else {
indicator.setBackgroundColor(getResources().getColor(R.color.indicatorPassive));
}
indicator.setBackgroundColor(passiveColor);
}
}
});
}
public void updateDisplay(@IdRes final int id, final String value) {
mHideHandler.post(new Runnable() {
mViewHandler.post(new Runnable() {
@Override
public void run() {
TextView display = (TextView) findViewById(id);
@@ -113,48 +64,27 @@ public class DSKYActivity extends AppCompatActivity {
});
}
/**
* Touch listener to use for in-layout UI controls to delay hiding the
* system UI. This is to prevent the jarring behavior of controls going away
* while interacting with activity UI.
*/
private final View.OnTouchListener mDelayHideTouchListener = new View.OnTouchListener() {
@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
if (AUTO_HIDE) {
delayedHide(AUTO_HIDE_DELAY_MILLIS);
}
return false;
}
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_dsky);
mVisible = true;
mControlsView = findViewById(R.id.controlBar);
mContentView = findViewById(R.id.contentView);
// Colors
rightActiveColor = getResources().getColor(R.color.indicatorRightActive);
activeColor = getResources().getColor(R.color.indicatorActive);
passiveColor = getResources().getColor(R.color.indicatorPassive);
// Set up the user interaction to manually show or hide the system UI.
mContentView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
toggle();
createButtonListeners();
}
});
// Upon interacting with UI controls, delay any scheduled hide()
// operations to prevent the jarring behavior of controls going away
// while interacting with the UI.
View.OnClickListener buttonListener = new View.OnClickListener() {
private void createButtonListeners() {
final View.OnClickListener buttonListener = new View.OnClickListener() {
@Override
public void onClick(View view) {
final Button button = (Button) view;
button.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY,
HapticFeedbackConstants.FLAG_IGNORE_GLOBAL_SETTING);
dsky.buttonPressed(button.getText().toString());
}
};
@@ -183,12 +113,6 @@ public class DSKYActivity extends AppCompatActivity {
@Override
protected void onPostCreate(Bundle savedInstanceState) {
super.onPostCreate(savedInstanceState);
// Trigger the initial hide() shortly after the activity has been
// created, to briefly hint to the user that UI controls
// are available.
delayedHide(100);
dsky.connect();
}
@@ -197,47 +121,4 @@ public class DSKYActivity extends AppCompatActivity {
super.onDestroy();
dsky.disconnect();
}
private void toggle() {
if (mVisible) {
hide();
} else {
show();
}
}
private void hide() {
// Hide UI first
ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
actionBar.hide();
}
mControlsView.setVisibility(View.GONE);
mVisible = false;
// Schedule a runnable to remove the status and navigation bar after a delay
mHideHandler.removeCallbacks(mShowPart2Runnable);
mHideHandler.postDelayed(mHidePart2Runnable, UI_ANIMATION_DELAY);
}
@SuppressLint("InlinedApi")
private void show() {
// Show the system bar
mContentView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);
mVisible = true;
// Schedule a runnable to display UI elements after a delay
mHideHandler.removeCallbacks(mHidePart2Runnable);
mHideHandler.postDelayed(mShowPart2Runnable, UI_ANIMATION_DELAY);
}
/**
* Schedules a call to hide() in [delay] milliseconds, canceling any
* previously scheduled calls.
*/
private void delayedHide(int delayMillis) {
mHideHandler.removeCallbacks(mHideRunnable);
mHideHandler.postDelayed(mHideRunnable, delayMillis);
}
}

View File

@@ -0,0 +1,31 @@
package de.rumpold.androiddsky.util;
import android.util.Log;
import org.apache.commons.lang3.StringUtils;
import java.nio.ByteBuffer;
/**
* Created by Adriano on 11.06.2017.
*/
public class BufferUtils {
private static void printBuffer(String tag, ByteBuffer buf) {
buf.rewind();
int index = 0;
while (buf.remaining() > 0) {
++index;
final int b = (int) buf.get();
if (b == 0) {
continue;
}
final String bitString = StringUtils.leftPad(Integer.toBinaryString(b), 32, '0').substring(24);
Log.d(tag, "printBuffer: " + index + ": " + bitString);
}
Log.d(tag, "--------------------------------------------------");
buf.rewind();
}
}

View File

@@ -1,47 +1,26 @@
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="#0099cc"
android:background="@android:color/background_light"
tools:context=".ui.DSKYActivity">
<!-- The primary full-screen view. This can be replaced with whatever view
is needed to present your content, e.g. VideoView, SurfaceView,
TextureView, etc. -->
<!-- This FrameLayout insets its children based on system windows using
android:fitsSystemWindows. -->
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="left|top"
android:id="@+id/controlBar"></LinearLayout>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/material_grey_100">
<include
android:id="@+id/contentView"
layout="@layout/layout_indicator_lights"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
layout="@layout/layout_indicator_lights"
android:layout_gravity="left|top"
android:id="@+id/contentView" />
android:layout_gravity="start|top" />
<include
android:layout_width="449dp"
android:layout_height="wrap_content"
layout="@layout/layout_7seg"
android:layout_gravity="right|top" />
android:layout_width="300dp"
android:layout_height="wrap_content"
android:layout_gravity="end|top" />
<include
android:layout_width="match_parent"
android:layout_height="282dp"
layout="@layout/layout_keyboard"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal|bottom" />
</FrameLayout>
</FrameLayout>

View File

@@ -1,15 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentStart="true"
android:stretchColumns="*">
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="16dp">
android:stretchColumns="*">
<TableRow android:paddingBottom="16dp">
<TextView
android:id="@+id/lbl_compActy"
@@ -22,191 +17,101 @@
android:textAppearance="?android:attr/textAppearanceLarge" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="PROG"
android:textAppearance="?android:attr/textAppearanceLarge"
android:layout_gravity="center_horizontal" />
style="@style/number_label"
android:text="PROG" />
<TextView
android:id="@+id/lbl_progId"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="00"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="64dp"
android:layout_gravity="center_horizontal"
android:gravity="bottom" />
style="@style/number_display"
android:text="00" />
</LinearLayout>
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TableRow>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout android:orientation="vertical">
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="VERB"
android:textAppearance="?android:attr/textAppearanceLarge" />
style="@style/number_label"
android:text="VERB" />
<TextView
android:id="@+id/lbl_verb"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="00"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="64sp"
android:layout_gravity="center_horizontal" />
style="@style/number_display"
android:text="00" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout android:orientation="vertical">
<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="NOUN"
android:textAppearance="?android:attr/textAppearanceLarge"
android:layout_gravity="center_horizontal" />
style="@style/number_label"
android:text="NOUN" />
<TextView
android:id="@+id/lbl_noun"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="00"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="64dp"
android:layout_gravity="center_horizontal" />
style="@style/number_display"
android:text="00" />
</LinearLayout>
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TableRow>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_horizontal"
android:layout_gravity="center"
android:layout_span="2">
<TextView
android:id="@+id/lbl_sign_R1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="+"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="64sp"
android:layout_gravity="center_horizontal"
android:singleLine="false"
android:phoneNumber="false"
android:layout_span="2" />
style="@style/number_display"
android:text="+" />
<TextView
android:id="@+id/lbl_R1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="00000"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="64sp"
android:singleLine="false"
android:phoneNumber="false"
android:layout_span="2" />
style="@style/number_display"
android:text="00000" />
</LinearLayout>
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TableRow>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_horizontal"
android:layout_gravity="center"
android:layout_span="2">
<TextView
android:id="@+id/lbl_sign_R2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="+"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="64sp"
android:layout_gravity="center_horizontal"
android:singleLine="false"
android:phoneNumber="false"
android:layout_span="2" />
style="@style/number_display"
android:text="+" />
<TextView
android:id="@+id/lbl_R2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="00000"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="64sp"
android:singleLine="false"
android:phoneNumber="false"
android:layout_span="2" />
style="@style/number_display"
android:text="00000" />
</LinearLayout>
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TableRow>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_horizontal"
android:layout_gravity="center"
android:layout_span="2">
<TextView
android:id="@+id/lbl_sign_R3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="+"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="64sp"
android:layout_gravity="center_horizontal"
android:singleLine="false"
android:phoneNumber="false"
android:layout_span="2" />
style="@style/number_display"
android:text="+" />
<TextView
android:id="@+id/lbl_R3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="00000"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="64sp"
android:singleLine="false"
android:phoneNumber="false"
android:layout_span="2" />
style="@style/number_display"
android:text="00000" />
</LinearLayout>
</TableRow>
</TableLayout>

View File

@@ -1,189 +1,153 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal" android:layout_width="wrap_content"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center">
android:gravity="center"
android:orientation="horizontal">
<LinearLayout
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="center_vertical">
android:gravity="center_vertical"
android:orientation="vertical">
<Button
android:text="VERB"
android:id="@+id/btn_verb"
android:elegantTextHeight="false"
style="@style/dsky_button" />
style="@style/dsky_button"
android:text="VERB" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="NOUN"
android:id="@+id/btn_noun"
style="@style/dsky_button" />
style="@style/dsky_button"
android:text="NOUN" />
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="center_vertical">
android:gravity="center_vertical"
android:orientation="vertical">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="+"
android:id="@+id/btn_plus"
style="@style/dsky_button" />
style="@style/dsky_button"
android:text="+" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="-"
android:id="@+id/btn_minus"
style="@style/dsky_button" />
style="@style/dsky_button"
android:text="-" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="0"
android:id="@+id/btn_0"
style="@style/dsky_button" />
style="@style/dsky_button"
android:text="0" />
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="center_vertical">
android:gravity="center_vertical"
android:orientation="vertical">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="7"
android:id="@+id/btn_7"
style="@style/dsky_button" />
style="@style/dsky_button"
android:text="7" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="4"
android:id="@+id/btn_4"
style="@style/dsky_button" />
style="@style/dsky_button"
android:text="4" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="1"
android:id="@+id/btn_1"
style="@style/dsky_button" />
style="@style/dsky_button"
android:text="1" />
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="center_vertical">
android:gravity="center_vertical"
android:orientation="vertical">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="8"
android:id="@+id/btn_8"
style="@style/dsky_button" />
style="@style/dsky_button"
android:text="8" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="5"
android:id="@+id/btn_5"
style="@style/dsky_button" />
style="@style/dsky_button"
android:text="5" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="2"
android:id="@+id/btn_2"
style="@style/dsky_button" />
style="@style/dsky_button"
android:text="2" />
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="center_vertical">
android:gravity="center_vertical"
android:orientation="vertical">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="9"
android:id="@+id/btn_9"
style="@style/dsky_button" />
style="@style/dsky_button"
android:text="9" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="6"
android:id="@+id/btn_6"
style="@style/dsky_button" />
style="@style/dsky_button"
android:text="6" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="3"
android:id="@+id/btn_3"
style="@style/dsky_button" />
style="@style/dsky_button"
android:text="3" />
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="center_vertical">
android:gravity="center_vertical"
android:orientation="vertical">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="CLR"
android:id="@+id/btn_clr"
style="@style/dsky_button" />
style="@style/dsky_button"
android:text="CLR" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="PRO"
android:id="@+id/btn_pro"
style="@style/dsky_button" />
style="@style/dsky_button"
android:text="PRO" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="KEY\nREL"
android:id="@+id/btn_key_rel"
style="@style/dsky_button" />
style="@style/dsky_button"
android:text="KEY\nREL" />
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="center_vertical" >
android:gravity="center_vertical"
android:orientation="vertical">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="ENTR"
android:id="@+id/btn_entr"
style="@style/dsky_button" />
style="@style/dsky_button"
android:text="ENTR" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="RSET"
android:id="@+id/btn_rset"
style="@style/dsky_button" />
style="@style/dsky_button"
android:text="RSET" />
</LinearLayout>
</LinearLayout>

View File

@@ -5,7 +5,7 @@
<color name="colorAccent">#FF4081</color>
<color name="indicatorPassive">#e0e0e0</color>
<color name="indicatorActive">#9aff57</color>
<color name="indicatorActive">#78e143</color>
<color name="indicatorRightActive">#ffd35c</color>
<color name="black_overlay">#66000000</color>

View File

@@ -22,12 +22,17 @@
<style name="indicator">
<item name="android:textAppearance">?android:attr/textAppearanceLarge</item>
<item name="android:layout_column">0</item>
<item name="android:textAlignment">center</item>
<item name="android:fontFamily">monospace</item>
<item name="android:textStyle">bold</item>
<item name="android:textSize">18sp</item>
<item name="android:width">128dp</item>
<item name="android:height">64dp</item>
<item name="android:gravity">center</item>
<item name="android:textColor">@android:color/black</item>
<item name="android:layout_gravity">center</item>
</style>
@@ -40,14 +45,30 @@
</style>
<style name="dsky_button">
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:width">96dp</item>
<item name="android:height">96dp</item>
<item name="android:layout_width">80dp</item>
<item name="android:layout_height">80dp</item>
<item name="android:textStyle">bold</item>
<item name="android:textSize">18dp</item>
<item name="android:textSize">18sp</item>
<item name="android:textColor">#ffffff</item>
<item name="android:backgroundTint">#000000</item>
<item name="android:hapticFeedbackEnabled">true</item>
</style>
<style name="number_label">
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:fontFamily">monospace</item>
<item name="android:textSize">18sp</item>
<item name="android:textStyle">bold</item>
<item name="android:layout_gravity">center_horizontal</item>
</style>
<style name="number_display">
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:fontFamily">monospace</item>
<item name="android:textSize">64sp</item>
<item name="android:textColor">@color/indicatorActive</item>
<item name="android:layout_gravity">center_horizontal</item>
</style>
</resources>

View File

@@ -5,7 +5,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.1.2'
classpath 'com.android.tools.build:gradle:2.3.3'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
@@ -15,6 +15,9 @@ buildscript {
allprojects {
repositories {
jcenter()
maven {
url("http://maven.google.com")
}
}
}