Skip to content

Commit

Permalink
Code format, debug CallOut, changed info on AboutPanel.
Browse files Browse the repository at this point in the history
  • Loading branch information
hugofqueiros committed Jun 2, 2014
1 parent 27dc78b commit 3721c1e
Show file tree
Hide file tree
Showing 5 changed files with 585 additions and 571 deletions.
78 changes: 40 additions & 38 deletions src/pt/lsts/accu/AboutPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,42 +8,44 @@
import android.view.View;
import android.widget.TextView;

public class AboutPanel extends AccuBasePanel
{
public AboutPanel(Context context) {
super(context);
}

@Override
public void onStart()
{
String html = "<p><b>A</b>ndroid <b>C</b>ommand and <b>C</>ontrol <b>U</>nit </p><p>";
TextView title = (TextView)getLayout().findViewWithTag("title");
TextView version = (TextView)getLayout().findViewWithTag("version");
TextView authors = (TextView)getLayout().findViewWithTag("authors");
TextView lab = (TextView)getLayout().findViewWithTag("lab");

title.setText(Html.fromHtml(html));
version.setText("Version: 1.0 Date: 15 Nov 2011 IMC version: " + IMCDefinition.getInstance().getVersion());
authors.setText("Authors: José Quadrado Correia");
lab.setText("Laboratório Sistemas e Tecnologias Subaquáticas");
}

@Override
public void onStop() {

}

@Override
public View buildLayout() {
View v = inflateFromResource(R.layout.about_layout);

return v;
}

@Override
public int getIcon() {
return R.drawable.icon;
}

public class AboutPanel extends AccuBasePanel
{
public AboutPanel(Context context) {
super(context);
}

@Override
public void onStart()
{
String html = "<p><b>A</b>ndroid <b>C</b>ommand and <b>C</>ontrol <b>U</>nit </p><p>";
TextView title = (TextView)getLayout().findViewWithTag("title");
TextView version = (TextView)getLayout().findViewWithTag("version");
TextView authors = (TextView)getLayout().findViewWithTag("authors");
TextView contributors = (TextView) getLayout().findViewWithTag("contributors");
TextView lab = (TextView)getLayout().findViewWithTag("lab");

title.setText(Html.fromHtml(html));
version.setText("Version: 1.2 Date: 2 Jun 2014 IMC version: " + IMCDefinition.getInstance().getVersion());
authors.setText("Author: José Quadrado Correia");
contributors.setText("Contributors: José Pinto, Hugo Queirós");
lab.setText("Laboratório Sistemas e Tecnologias Subaquáticas");
}

@Override
public void onStop() {

}

@Override
public View buildLayout() {
View v = inflateFromResource(R.layout.about_layout);

return v;
}

@Override
public int getIcon() {
return R.drawable.icon;
}

}
280 changes: 140 additions & 140 deletions src/pt/lsts/accu/components/controlpad/ControlPad2.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,161 +19,161 @@
public class ControlPad2 extends Container
implements JoystickPadChangeListener, PadButtonListener
{
public static final String TAG = "ControlPad2";
Context context;
View view;
public ArrayList<View> viewList; // List of pad components
LinkedHashMap<View,String> actions = new LinkedHashMap<View,String>();

PadStateListener listener;
PadEventListener listener2;

ArrayList<PadTextField> textFields = new ArrayList<PadTextField>();

int layoutID;

public ControlPad2(Context context) {
super(context);
initialize(context);
}
public ControlPad2(Context context, AttributeSet attrs) {
super(context, attrs);
layoutID = attrs.getAttributeResourceValue(null, "pad_layout", 0);
initialize(context);
}
public static final String TAG = "ControlPad2";
Context context;
View view;
public ArrayList<View> viewList; // List of pad components
LinkedHashMap<View,String> actions = new LinkedHashMap<View,String>();

void initialize(Context context)
{
// Do un-setup of previous pad, if available... // FIXME jqcorreia
if(viewList != null)
{
for(View v : viewList)
{
if(v instanceof SensorPad)
{
((SensorManager)getContext().getSystemService(Context.SENSOR_SERVICE)).unregisterListener((SensorPad)v);
}
}
}
removeAllViews(); // Remove previous graphical pad components

this.context = context;
LayoutInflater.from(context).inflate(layoutID,this,true);
PadStateListener listener;
PadEventListener listener2;

viewList = flattenLayout(this);
ArrayList<PadTextField> textFields = new ArrayList<PadTextField>();

setupPad();
}

/**
* Registers Layout components as pad components in the padState and the listeners too
*/
private void setupPad()
int layoutID;

public ControlPad2(Context context) {
super(context);
initialize(context);
}
public ControlPad2(Context context, AttributeSet attrs) {
super(context, attrs);
layoutID = attrs.getAttributeResourceValue(null, "pad_layout", 0);
initialize(context);
}

void initialize(Context context)
{
// Do un-setup of previous pad, if available... // FIXME jqcorreia
if(viewList != null)
{
for(View v : viewList)
for(View v : viewList)
{
if(v instanceof SensorPad)
{
if(v instanceof JoystickPad)
{
((JoystickPad)v).setOnPadChangeListener(this);
}
else if(v instanceof PadButton)
{
((PadButton)v).setPadButtonListener(this);
}
else if( v instanceof PadToggleButton)
{
((PadToggleButton)v).setPadButtonListener(this);
}
else if(v instanceof PadTextField)
{
textFields.add((PadTextField)v);
}
((SensorManager)getContext().getSystemService(Context.SENSOR_SERVICE)).unregisterListener((SensorPad)v);
}
}
}
public void setPadLayout(int layoutId)
{
this.layoutID = layoutId;
initialize(context); // Re-run initialize for the new pad layout
}

/**
* Recursive function that flattens a root layout and returns all the child Views independent of
* layout level.
* @param viewgroup The root viewroup to be analized
* @return an ArrayList containing all the views below the original ViewGroup
*/
ArrayList<View> flattenLayout(ViewGroup viewgroup)
{
ArrayList<View> viewList = new ArrayList<View>();

for(int i = 0; i < viewgroup.getChildCount();i++)
{
View v = viewgroup.getChildAt(i);
if(v instanceof ViewGroup)
{
viewList.addAll(flattenLayout((ViewGroup)v));
}
else if(v instanceof View)
{
viewList.add((View)v);
}
}
return viewList;
}

public void setPadEventListener(PadEventListener l)
removeAllViews(); // Remove previous graphical pad components

this.context = context;
LayoutInflater.from(context).inflate(layoutID,this,true);

viewList = flattenLayout(this);

setupPad();
}

/**
* Registers Layout components as pad components in the padState and the listeners too
*/
private void setupPad()
{
for(View v : viewList)
{
listener2 = l;
if(v instanceof JoystickPad)
{
((JoystickPad)v).setOnPadChangeListener(this);
}
else if(v instanceof PadButton)
{
((PadButton)v).setPadButtonListener(this);
}
else if( v instanceof PadToggleButton)
{
((PadToggleButton)v).setPadButtonListener(this);
}
else if(v instanceof PadTextField)
{
textFields.add((PadTextField)v);
}
}
void notifyEventListener(PadEvent event)
}
public void setPadLayout(int layoutId)
{
this.layoutID = layoutId;
initialize(context); // Re-run initialize for the new pad layout
}

/**
* Recursive function that flattens a root layout and returns all the child Views independent of
* layout level.
* @param viewgroup The root viewroup to be analized
* @return an ArrayList containing all the views below the original ViewGroup
*/
ArrayList<View> flattenLayout(ViewGroup viewgroup)
{
ArrayList<View> viewList = new ArrayList<View>();

for(int i = 0; i < viewgroup.getChildCount();i++)
{
if(listener2!=null)
listener2.onPadEvent(event);
View v = viewgroup.getChildAt(i);
if(v instanceof ViewGroup)
{
viewList.addAll(flattenLayout((ViewGroup)v));
}
else if(v instanceof View)
{
viewList.add(v);
}
}

@Override
public void onJoystickPadChange(View v, int axisX, int axisY)
return viewList;
}

public void setPadEventListener(PadEventListener l)
{
listener2 = l;
}
void notifyEventListener(PadEvent event)
{
if(listener2!=null)
listener2.onPadEvent(event);
}

@Override
public void onJoystickPadChange(View v, int axisX, int axisY)
{
PadEvent padEvent = new PadEvent(v,axisX,axisY,((JoystickPad)v).getAxisXAction(),((JoystickPad)v).getAxisYAction(),0);
notifyEventListener(padEvent);
}

@Override
public void onPadButtonTouch(View v, MotionEvent event) {
PadEvent padEvent=null;

// For now the difference between ToggleButton and Button is hardcoded
if(v instanceof PadToggleButton)
{
PadEvent padEvent = new PadEvent(v,(float)axisX,(float)axisY,((JoystickPad)v).getAxisXAction(),((JoystickPad)v).getAxisYAction(),0);

if(event.getAction()==MotionEvent.ACTION_DOWN)
{
padEvent = new PadEvent(v,1f,-1f,((PadToggleButton)v).getAction(),null,-1);
notifyEventListener(padEvent);
}
if(event.getAction()==MotionEvent.ACTION_UP)
{
padEvent = new PadEvent(v,0f,-1f,((PadToggleButton)v).getAction(),null,-1);
notifyEventListener(padEvent);
}
}

@Override
public void onPadButtonTouch(View v, MotionEvent event) {
PadEvent padEvent=null;

// For now the difference between ToggleButton and Button is hardcoded
if(v instanceof PadToggleButton)
{

if(event.getAction()==MotionEvent.ACTION_DOWN)
{
padEvent = new PadEvent(v,1f,-1f,((PadToggleButton)v).getAction(),null,-1);
notifyEventListener(padEvent);
}
if(event.getAction()==MotionEvent.ACTION_UP)
{
padEvent = new PadEvent(v,0f,-1f,((PadToggleButton)v).getAction(),null,-1);
notifyEventListener(padEvent);
}
}
else
{
if(event.getAction()==MotionEvent.ACTION_DOWN||event.getAction()==MotionEvent.ACTION_MOVE)
{
padEvent = new PadEvent(v,1f,-1f,((PadButton)v).getAction(),null,-1);
}
if(event.getAction()==MotionEvent.ACTION_UP)
{
padEvent = new PadEvent(v,0f,-1f,((PadButton)v).getAction(),null,-1);
}
notifyEventListener(padEvent);
}
}

public ArrayList<PadTextField> getTextFields()
else
{
return textFields;
if(event.getAction()==MotionEvent.ACTION_DOWN||event.getAction()==MotionEvent.ACTION_MOVE)
{
padEvent = new PadEvent(v,1f,-1f,((PadButton)v).getAction(),null,-1);
}
if(event.getAction()==MotionEvent.ACTION_UP)
{
padEvent = new PadEvent(v,0f,-1f,((PadButton)v).getAction(),null,-1);
}
notifyEventListener(padEvent);
}
}

public ArrayList<PadTextField> getTextFields()
{
return textFields;
}
}

Loading

0 comments on commit 3721c1e

Please sign in to comment.