mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2025-02-11 01:54:14 +01:00
AndroidGCS: Move the PFD functionality into a fragment and then
programmatically instantiate that from the test PFD activity
This commit is contained in:
parent
ce52b4d199
commit
95dfc88f95
@ -24,7 +24,7 @@
|
|||||||
</activity>
|
</activity>
|
||||||
|
|
||||||
<activity android:name="ObjectBrowser" android:label="@string/object_browser_name" />
|
<activity android:name="ObjectBrowser" android:label="@string/object_browser_name" />
|
||||||
<activity android:name="PFD" android:label="PFD" />
|
<activity android:name="PfdActivity" android:label="PFD" />
|
||||||
<activity android:name="Controller" android:label="@string/controller_name" />
|
<activity android:name="Controller" android:label="@string/controller_name" />
|
||||||
<activity android:name="Preferences" android:label="@string/preference_title" />
|
<activity android:name="Preferences" android:label="@string/preference_title" />
|
||||||
<activity android:name="UAVLocation" android:label="@string/location_name" />
|
<activity android:name="UAVLocation" android:label="@string/location_name" />
|
||||||
|
@ -83,13 +83,11 @@ public class AttitudeView extends View {
|
|||||||
private float roll;
|
private float roll;
|
||||||
public void setRoll(double roll) {
|
public void setRoll(double roll) {
|
||||||
this.roll = (float) roll;
|
this.roll = (float) roll;
|
||||||
postInvalidate();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private float pitch;
|
private float pitch;
|
||||||
public void setPitch(double d) {
|
public void setPitch(double d) {
|
||||||
this.pitch = (float) d;
|
this.pitch = (float) d;
|
||||||
postInvalidate();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -48,7 +48,7 @@ public class HomePage extends ObjectManagerActivity {
|
|||||||
pfd.setOnClickListener(new OnClickListener() {
|
pfd.setOnClickListener(new OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View arg0) {
|
public void onClick(View arg0) {
|
||||||
startActivity(new Intent(HomePage.this, PFD.class));
|
startActivity(new Intent(HomePage.this, PfdActivity.class));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -2,8 +2,9 @@
|
|||||||
******************************************************************************
|
******************************************************************************
|
||||||
* @file PFD.java
|
* @file PFD.java
|
||||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012.
|
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012.
|
||||||
* @brief Shows the PFD activity.
|
* @brief The PFD display fragment
|
||||||
* @see The GNU Public License (GPL) Version 3
|
* @see The GNU Public License (GPL) Version 3
|
||||||
|
*
|
||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
/*
|
/*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* This program is free software; you can redistribute it and/or modify
|
||||||
@ -24,58 +25,59 @@
|
|||||||
package org.openpilot.androidgcs;
|
package org.openpilot.androidgcs;
|
||||||
|
|
||||||
import org.openpilot.uavtalk.UAVObject;
|
import org.openpilot.uavtalk.UAVObject;
|
||||||
|
import org.openpilot.uavtalk.UAVObjectManager;
|
||||||
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.util.Log;
|
||||||
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
|
||||||
public class PFD extends ObjectManagerActivity {
|
public class PFD extends ObjectManagerFragment {
|
||||||
|
|
||||||
final long MIN_UPDATE_PERIOD = 50;
|
private static final String TAG = ObjectManagerFragment.class
|
||||||
long lastUpdateMs;
|
.getSimpleName();
|
||||||
double heading;
|
private static final int LOGLEVEL = 0;
|
||||||
double roll;
|
// private static boolean WARN = LOGLEVEL > 1;
|
||||||
double pitch;
|
private static final boolean DEBUG = LOGLEVEL > 0;
|
||||||
|
|
||||||
/**
|
// @Override
|
||||||
* Update the UI whenever the attitude is updated
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
protected void objectUpdated(UAVObject obj) {
|
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||||
// Throttle the UI redraws. Eventually this should maybe come from a periodic task
|
Bundle savedInstanceState) {
|
||||||
if ((System.currentTimeMillis() - lastUpdateMs) < MIN_UPDATE_PERIOD)
|
// Inflate the layout for this fragment
|
||||||
return;
|
return inflater.inflate(R.layout.pfd, container, false);
|
||||||
if (obj.getName().compareTo("AttitudeActual") != 0)
|
|
||||||
return;
|
|
||||||
|
|
||||||
lastUpdateMs = System.currentTimeMillis();
|
|
||||||
|
|
||||||
heading = obj.getField("Yaw").getDouble();
|
|
||||||
pitch = obj.getField("Pitch").getDouble();
|
|
||||||
roll = obj.getField("Roll").getDouble();
|
|
||||||
|
|
||||||
/*
|
|
||||||
* CompassView compass = (CompassView) findViewById(R.id.compass_view);
|
|
||||||
* compass.setBearing((int) heading); compass.invalidate();
|
|
||||||
*/
|
|
||||||
|
|
||||||
AttitudeView attitude = (AttitudeView) findViewById(R.id.attitude_view);
|
|
||||||
attitude.setRoll(roll);
|
|
||||||
attitude.setPitch(pitch);
|
|
||||||
attitude.invalidate();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onOPConnected(UAVObjectManager objMngr) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onOPConnected(objMngr);
|
||||||
setContentView(R.layout.pfd);
|
if (DEBUG)
|
||||||
}
|
Log.d(TAG, "On connected");
|
||||||
|
|
||||||
@Override
|
|
||||||
void onOPConnected() {
|
|
||||||
super.onOPConnected();
|
|
||||||
|
|
||||||
// Connect the update method to AttitudeActual
|
|
||||||
UAVObject obj = objMngr.getObject("AttitudeActual");
|
UAVObject obj = objMngr.getObject("AttitudeActual");
|
||||||
if (obj != null)
|
if (obj != null)
|
||||||
registerObjectUpdates(obj);
|
registerObjectUpdates(obj);
|
||||||
|
objectUpdated(obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called whenever any objects subscribed to via registerObjects
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
protected void objectUpdated(UAVObject obj) {
|
||||||
|
if (DEBUG)
|
||||||
|
Log.d(TAG, "Updated");
|
||||||
|
|
||||||
|
double pitch = obj.getField("Pitch").getDouble();
|
||||||
|
double roll = obj.getField("Roll").getDouble();
|
||||||
|
|
||||||
|
AttitudeView attitude = (AttitudeView) getActivity().findViewById(
|
||||||
|
R.id.attitude_view);
|
||||||
|
attitude.setRoll(roll);
|
||||||
|
attitude.setPitch(pitch);
|
||||||
|
attitude.invalidate();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
58
androidgcs/src/org/openpilot/androidgcs/PfdActivity.java
Normal file
58
androidgcs/src/org/openpilot/androidgcs/PfdActivity.java
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
/**
|
||||||
|
******************************************************************************
|
||||||
|
* @file PfdActivity.java
|
||||||
|
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012.
|
||||||
|
* @brief Shows the PFD activity.
|
||||||
|
* @see The GNU Public License (GPL) Version 3
|
||||||
|
*****************************************************************************/
|
||||||
|
/*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||||
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||||
|
* for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along
|
||||||
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
|
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.openpilot.androidgcs;
|
||||||
|
|
||||||
|
import org.openpilot.androidgcs.fragments.PFD;
|
||||||
|
|
||||||
|
import android.app.FragmentTransaction;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.view.View;
|
||||||
|
import android.widget.AbsListView;
|
||||||
|
import android.widget.LinearLayout;
|
||||||
|
|
||||||
|
public class PfdActivity extends ObjectManagerActivity {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
setContentView(createUI());
|
||||||
|
}
|
||||||
|
|
||||||
|
private View createUI() {
|
||||||
|
LinearLayout layout = new LinearLayout(this);
|
||||||
|
|
||||||
|
layout.setOrientation(LinearLayout.HORIZONTAL);
|
||||||
|
layout.setLayoutParams(new LinearLayout.LayoutParams(
|
||||||
|
AbsListView.LayoutParams.MATCH_PARENT,
|
||||||
|
AbsListView.LayoutParams.MATCH_PARENT));
|
||||||
|
layout.setId(0x101);
|
||||||
|
{
|
||||||
|
FragmentTransaction fragmentTransaction = getFragmentManager()
|
||||||
|
.beginTransaction();
|
||||||
|
fragmentTransaction.add(0x101, new PFD());
|
||||||
|
fragmentTransaction.commit();
|
||||||
|
}
|
||||||
|
return layout;
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user