129 lines
4.7 KiB
Java
Executable File
129 lines
4.7 KiB
Java
Executable File
package de.rumpold.androiddsky.ui;
|
|
|
|
import android.os.Bundle;
|
|
import android.os.Handler;
|
|
import android.support.annotation.IdRes;
|
|
import android.support.v7.app.AppCompatActivity;
|
|
import android.view.HapticFeedbackConstants;
|
|
import android.view.View;
|
|
import android.widget.Button;
|
|
import android.widget.TextView;
|
|
|
|
import de.rumpold.androiddsky.DSKY;
|
|
import de.rumpold.androiddsky.R;
|
|
|
|
/**
|
|
* An example full-screen activity that shows and hides the system UI (i.e.
|
|
* status bar and navigation/system bar) with user interaction.
|
|
*/
|
|
public class DSKYActivity extends AppCompatActivity {
|
|
/**
|
|
* 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 mViewHandler = new Handler();
|
|
|
|
private final DSKY dsky = new DSKY(this);
|
|
private int rightActiveColor;
|
|
private int activeColor;
|
|
private int passiveColor;
|
|
private int compActyColor;
|
|
|
|
public void updateIndicator(@IdRes final int id, final boolean state) {
|
|
mViewHandler.post(new Runnable() {
|
|
@Override
|
|
public void run() {
|
|
TextView indicator = (TextView) findViewById(id);
|
|
if (indicator == null) {
|
|
return;
|
|
}
|
|
|
|
if (state) {
|
|
final int color;
|
|
if ("right".equals(indicator.getTag())) {
|
|
color = rightActiveColor;
|
|
} else if ("comp acty".equals(indicator.getTag())) {
|
|
color = compActyColor;
|
|
} else {
|
|
color = activeColor;
|
|
}
|
|
indicator.setBackgroundColor(color);
|
|
} else {
|
|
indicator.setBackgroundColor(passiveColor);
|
|
}
|
|
}
|
|
});
|
|
}
|
|
|
|
public void updateDisplay(@IdRes final int id, final String value) {
|
|
mViewHandler.post(new Runnable() {
|
|
@Override
|
|
public void run() {
|
|
TextView display = (TextView) findViewById(id);
|
|
display.setText(value);
|
|
}
|
|
});
|
|
}
|
|
|
|
@Override
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
super.onCreate(savedInstanceState);
|
|
|
|
setContentView(R.layout.activity_dsky);
|
|
|
|
// Colors
|
|
rightActiveColor = getResources().getColor(R.color.indicatorRightActive);
|
|
activeColor = getResources().getColor(R.color.indicatorActive);
|
|
passiveColor = getResources().getColor(R.color.indicatorPassive);
|
|
compActyColor = getResources().getColor(R.color.compActy);
|
|
|
|
createButtonListeners();
|
|
}
|
|
|
|
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());
|
|
}
|
|
};
|
|
|
|
findViewById(R.id.btn_verb).setOnClickListener(buttonListener);
|
|
findViewById(R.id.btn_noun).setOnClickListener(buttonListener);
|
|
findViewById(R.id.btn_plus).setOnClickListener(buttonListener);
|
|
findViewById(R.id.btn_minus).setOnClickListener(buttonListener);
|
|
findViewById(R.id.btn_0).setOnClickListener(buttonListener);
|
|
findViewById(R.id.btn_1).setOnClickListener(buttonListener);
|
|
findViewById(R.id.btn_2).setOnClickListener(buttonListener);
|
|
findViewById(R.id.btn_3).setOnClickListener(buttonListener);
|
|
findViewById(R.id.btn_4).setOnClickListener(buttonListener);
|
|
findViewById(R.id.btn_5).setOnClickListener(buttonListener);
|
|
findViewById(R.id.btn_6).setOnClickListener(buttonListener);
|
|
findViewById(R.id.btn_7).setOnClickListener(buttonListener);
|
|
findViewById(R.id.btn_8).setOnClickListener(buttonListener);
|
|
findViewById(R.id.btn_9).setOnClickListener(buttonListener);
|
|
findViewById(R.id.btn_clr).setOnClickListener(buttonListener);
|
|
findViewById(R.id.btn_pro).setOnClickListener(buttonListener);
|
|
findViewById(R.id.btn_key_rel).setOnClickListener(buttonListener);
|
|
findViewById(R.id.btn_entr).setOnClickListener(buttonListener);
|
|
findViewById(R.id.btn_rset).setOnClickListener(buttonListener);
|
|
}
|
|
|
|
@Override
|
|
protected void onPostCreate(Bundle savedInstanceState) {
|
|
super.onPostCreate(savedInstanceState);
|
|
dsky.connect();
|
|
}
|
|
|
|
@Override
|
|
protected void onDestroy() {
|
|
super.onDestroy();
|
|
dsky.disconnect();
|
|
}
|
|
}
|