1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2024-11-29 07:24:13 +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:
James Cotton 2012-08-08 12:41:57 -05:00
parent 95dfc88f95
commit 11a08c186c
5 changed files with 37 additions and 16 deletions

View File

@ -5,11 +5,17 @@
android:layout_gravity="center" >
<fragment
android:name="org.openpilot.androidgcs.SystemAlarmsFragment"
android:name="org.openpilot.androidgcs.fragments.SystemAlarmsFragment"
android:id="@+id/viewer"
android:layout_width="wrap_content"
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
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/system_alarms_status"

View File

@ -161,7 +161,9 @@ public abstract class ObjectManagerActivity extends Activity {
protected void registerObjectUpdates(UAVObject 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));
}
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));
if (DEBUG) Log.d(TAG, "Connecting " + frag + " there are now " + connectionListeners.countObservers());
if (mConnected)

View File

@ -24,8 +24,9 @@
* 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;
package org.openpilot.androidgcs.fragments;
import org.openpilot.androidgcs.ObjectManagerActivity;
import org.openpilot.uavtalk.UAVObject;
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
protected void onOPConnected(UAVObjectManager objMngr) {
public void onOPConnected(UAVObjectManager objMngr) {
this.objMngr = objMngr;
if (DEBUG) Log.d(TAG,"onOPConnected");
}
protected void onOPDisconnected() {
public void onOPDisconnected() {
objMngr = null;
if (DEBUG) Log.d(TAG,"onOPDisconnected");
}
@ -87,7 +88,7 @@ public class ObjectManagerFragment extends Fragment {
/**
* Called whenever any objects subscribed to via registerObjects
*/
protected void objectUpdated(UAVObject obj) {
public void objectUpdated(UAVObject obj) {
}

View File

@ -22,11 +22,14 @@
* 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.UAVObjectManager;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
@ -65,18 +68,25 @@ public class PFD extends ObjectManagerFragment {
* Called whenever any objects subscribed to via registerObjects
*/
@Override
protected void objectUpdated(UAVObject obj) {
public 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();
// TODO: These checks, while sensible, are necessary because the
// 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.setPitch(pitch);
attitude.invalidate();
}
}

View File

@ -21,10 +21,11 @@
* 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;
package org.openpilot.androidgcs.fragments;
import java.util.List;
import org.openpilot.androidgcs.R;
import org.openpilot.uavtalk.UAVObject;
import org.openpilot.uavtalk.UAVObjectField;
import org.openpilot.uavtalk.UAVObjectManager;
@ -67,7 +68,7 @@ public class SystemAlarmsFragment extends ObjectManagerFragment {
* Called whenever any objects subscribed to via registerObjects
*/
@Override
protected void objectUpdated(UAVObject obj) {
public void objectUpdated(UAVObject obj) {
if (DEBUG)
Log.d(TAG, "Updated");
if (obj.getName().compareTo("SystemAlarms") == 0) {