mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2024-12-02 10:24:11 +01:00
AndroidGCS: Refactor the Fragments into their own package to keep the UI
"components" segregated. Is this good practice though? It means making a lot of functions for the API between ObjectManagerActivity and Fragment public.
This commit is contained in:
parent
95dfc88f95
commit
11a08c186c
@ -5,11 +5,17 @@
|
|||||||
android:layout_gravity="center" >
|
android:layout_gravity="center" >
|
||||||
|
|
||||||
<fragment
|
<fragment
|
||||||
android:name="org.openpilot.androidgcs.SystemAlarmsFragment"
|
android:name="org.openpilot.androidgcs.fragments.SystemAlarmsFragment"
|
||||||
android:id="@+id/viewer"
|
android:id="@+id/viewer"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="match_parent" />
|
android:layout_height="match_parent" />
|
||||||
|
|
||||||
|
<fragment
|
||||||
|
android:name="org.openpilot.androidgcs.fragments.PFD"
|
||||||
|
android:id="@+id/pfd"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="match_parent" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:id="@+id/system_alarms_status"
|
android:id="@+id/system_alarms_status"
|
||||||
|
@ -161,7 +161,9 @@ public abstract class ObjectManagerActivity extends Activity {
|
|||||||
protected void registerObjectUpdates(UAVObject object) {
|
protected void registerObjectUpdates(UAVObject object) {
|
||||||
object.addUpdatedObserver(new ActivityUpdatedObserver(object));
|
object.addUpdatedObserver(new ActivityUpdatedObserver(object));
|
||||||
}
|
}
|
||||||
protected void registerObjectUpdates(UAVObject object, ObjectManagerFragment frag) {
|
|
||||||
|
public void registerObjectUpdates(UAVObject object,
|
||||||
|
ObjectManagerFragment frag) {
|
||||||
object.addUpdatedObserver(new FragmentUpdatedObserver(object, frag));
|
object.addUpdatedObserver(new FragmentUpdatedObserver(object, frag));
|
||||||
}
|
}
|
||||||
protected void registerObjectUpdates(List<List<UAVObject>> objects) {
|
protected void registerObjectUpdates(List<List<UAVObject>> objects) {
|
||||||
@ -326,7 +328,8 @@ public abstract class ObjectManagerActivity extends Activity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
} ;
|
} ;
|
||||||
void addOnConnectionListenerFragment(ObjectManagerFragment frag) {
|
|
||||||
|
public void addOnConnectionListenerFragment(ObjectManagerFragment frag) {
|
||||||
connectionListeners.addObserver(new OnConnectionListener(frag));
|
connectionListeners.addObserver(new OnConnectionListener(frag));
|
||||||
if (DEBUG) Log.d(TAG, "Connecting " + frag + " there are now " + connectionListeners.countObservers());
|
if (DEBUG) Log.d(TAG, "Connecting " + frag + " there are now " + connectionListeners.countObservers());
|
||||||
if (mConnected)
|
if (mConnected)
|
||||||
|
@ -24,8 +24,9 @@
|
|||||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
*/
|
*/
|
||||||
package org.openpilot.androidgcs;
|
package org.openpilot.androidgcs.fragments;
|
||||||
|
|
||||||
|
import org.openpilot.androidgcs.ObjectManagerActivity;
|
||||||
import org.openpilot.uavtalk.UAVObject;
|
import org.openpilot.uavtalk.UAVObject;
|
||||||
import org.openpilot.uavtalk.UAVObjectManager;
|
import org.openpilot.uavtalk.UAVObjectManager;
|
||||||
|
|
||||||
@ -74,12 +75,12 @@ public class ObjectManagerFragment extends Fragment {
|
|||||||
|
|
||||||
|
|
||||||
// The below methods should all be called by the parent activity at the appropriate times
|
// The below methods should all be called by the parent activity at the appropriate times
|
||||||
protected void onOPConnected(UAVObjectManager objMngr) {
|
public void onOPConnected(UAVObjectManager objMngr) {
|
||||||
this.objMngr = objMngr;
|
this.objMngr = objMngr;
|
||||||
if (DEBUG) Log.d(TAG,"onOPConnected");
|
if (DEBUG) Log.d(TAG,"onOPConnected");
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void onOPDisconnected() {
|
public void onOPDisconnected() {
|
||||||
objMngr = null;
|
objMngr = null;
|
||||||
if (DEBUG) Log.d(TAG,"onOPDisconnected");
|
if (DEBUG) Log.d(TAG,"onOPDisconnected");
|
||||||
}
|
}
|
||||||
@ -87,7 +88,7 @@ public class ObjectManagerFragment extends Fragment {
|
|||||||
/**
|
/**
|
||||||
* Called whenever any objects subscribed to via registerObjects
|
* Called whenever any objects subscribed to via registerObjects
|
||||||
*/
|
*/
|
||||||
protected void objectUpdated(UAVObject obj) {
|
public void objectUpdated(UAVObject obj) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -22,11 +22,14 @@
|
|||||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.openpilot.androidgcs;
|
package org.openpilot.androidgcs.fragments;
|
||||||
|
|
||||||
|
import org.openpilot.androidgcs.AttitudeView;
|
||||||
|
import org.openpilot.androidgcs.R;
|
||||||
import org.openpilot.uavtalk.UAVObject;
|
import org.openpilot.uavtalk.UAVObject;
|
||||||
import org.openpilot.uavtalk.UAVObjectManager;
|
import org.openpilot.uavtalk.UAVObjectManager;
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
@ -65,18 +68,25 @@ public class PFD extends ObjectManagerFragment {
|
|||||||
* Called whenever any objects subscribed to via registerObjects
|
* Called whenever any objects subscribed to via registerObjects
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected void objectUpdated(UAVObject obj) {
|
public void objectUpdated(UAVObject obj) {
|
||||||
if (DEBUG)
|
if (DEBUG)
|
||||||
Log.d(TAG, "Updated");
|
Log.d(TAG, "Updated");
|
||||||
|
|
||||||
double pitch = obj.getField("Pitch").getDouble();
|
double pitch = obj.getField("Pitch").getDouble();
|
||||||
double roll = obj.getField("Roll").getDouble();
|
double roll = obj.getField("Roll").getDouble();
|
||||||
|
|
||||||
AttitudeView attitude = (AttitudeView) getActivity().findViewById(
|
// TODO: These checks, while sensible, are necessary because the
|
||||||
R.id.attitude_view);
|
// callbacks aren't
|
||||||
|
// removed when we switch to different activities sharing this fragment
|
||||||
|
Activity parent = getActivity();
|
||||||
|
AttitudeView attitude = null;
|
||||||
|
if (parent != null)
|
||||||
|
attitude = (AttitudeView) parent.findViewById(R.id.attitude_view);
|
||||||
|
if (attitude != null) {
|
||||||
attitude.setRoll(roll);
|
attitude.setRoll(roll);
|
||||||
attitude.setPitch(pitch);
|
attitude.setPitch(pitch);
|
||||||
attitude.invalidate();
|
attitude.invalidate();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -21,10 +21,11 @@
|
|||||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
*/
|
*/
|
||||||
package org.openpilot.androidgcs;
|
package org.openpilot.androidgcs.fragments;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.openpilot.androidgcs.R;
|
||||||
import org.openpilot.uavtalk.UAVObject;
|
import org.openpilot.uavtalk.UAVObject;
|
||||||
import org.openpilot.uavtalk.UAVObjectField;
|
import org.openpilot.uavtalk.UAVObjectField;
|
||||||
import org.openpilot.uavtalk.UAVObjectManager;
|
import org.openpilot.uavtalk.UAVObjectManager;
|
||||||
@ -67,7 +68,7 @@ public class SystemAlarmsFragment extends ObjectManagerFragment {
|
|||||||
* Called whenever any objects subscribed to via registerObjects
|
* Called whenever any objects subscribed to via registerObjects
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected void objectUpdated(UAVObject obj) {
|
public void objectUpdated(UAVObject obj) {
|
||||||
if (DEBUG)
|
if (DEBUG)
|
||||||
Log.d(TAG, "Updated");
|
Log.d(TAG, "Updated");
|
||||||
if (obj.getName().compareTo("SystemAlarms") == 0) {
|
if (obj.getName().compareTo("SystemAlarms") == 0) {
|
Loading…
Reference in New Issue
Block a user