Skip to content
This repository was archived by the owner on Sep 6, 2024. It is now read-only.

Commit

Permalink
Show WifDirect passphrase on robot controller screen
Browse files Browse the repository at this point in the history
Former-commit-id: 725f55df4cf8e24fac319e9591f2da2f329a23c2
Former-commit-id: 6892bf5
  • Loading branch information
rgatkinson committed Oct 2, 2015
1 parent 3b1dc79 commit edc733f
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,13 @@ public class FtcRobotControllerActivity extends Activity {
protected TextView textDeviceName;
protected TextView textWifiDirectStatus;
protected TextView textRobotStatus;
protected TextView textWifiDirectPassphrase;
protected TextView[] textGamepad = new TextView[NUM_GAMEPADS];
protected TextView textOpMode;
protected TextView textErrorMessage;
protected ImmersiveMode immersion;

protected UpdateUI updateUI;
protected UpdateUIHook updateUI;
protected Dimmer dimmer;
protected LinearLayout entireScreenLayout;

Expand Down Expand Up @@ -156,18 +157,19 @@ public void onClick(View v) {
textRobotStatus = (TextView) findViewById(R.id.textRobotStatus);
textOpMode = (TextView) findViewById(R.id.textOpMode);
textErrorMessage = (TextView) findViewById(R.id.textErrorMessage);
textWifiDirectPassphrase = (TextView) findViewById(R.id.textWifiDirectPassphrase);
textGamepad[0] = (TextView) findViewById(R.id.textGamepad1);
textGamepad[1] = (TextView) findViewById(R.id.textGamepad2);
immersion = new ImmersiveMode(getWindow().getDecorView());
dimmer = new Dimmer(this);
dimmer.longBright();
Restarter restarter = new RobotRestarter();

updateUI = new UpdateUI(this, dimmer);
updateUI = new UpdateUIHook(this, dimmer);
updateUI.setRestarter(restarter);
updateUI.setTextViews(textWifiDirectStatus, textRobotStatus,
textGamepad, textOpMode, textErrorMessage, textDeviceName);
callback = updateUI.new Callback();
textGamepad, textOpMode, textErrorMessage, textDeviceName);
callback = updateUI.new CallbackHook();

PreferenceManager.setDefaultValues(this, R.xml.preferences, false);
preferences = PreferenceManager.getDefaultSharedPreferences(this);
Expand Down Expand Up @@ -386,4 +388,75 @@ public void run() {
}
});
}
}

class UpdateUIHook extends UpdateUI
{
//------------------------------------------------------------------------------------------------
// State
//------------------------------------------------------------------------------------------------

FtcRobotControllerActivity activity;
FtcRobotControllerService controllerService;

//------------------------------------------------------------------------------------------------
// Construction
//------------------------------------------------------------------------------------------------

UpdateUIHook(FtcRobotControllerActivity activity, Dimmer dimmer)
{
super(activity, dimmer);
this.activity = activity;
this.controllerService = null;
}

@Override public void setControllerService(FtcRobotControllerService controllerService)
{
super.setControllerService(controllerService);
this.controllerService = controllerService;
}

//------------------------------------------------------------------------------------------------
// Operations
//------------------------------------------------------------------------------------------------

class CallbackHook extends UpdateUI.Callback
{
@Override public void wifiDirectUpdate(WifiDirectAssistant.Event event)
{
super.wifiDirectUpdate(event);

final String message = controllerService == null
? "" :
String.format("Wifi Direct passphrase: %s", controllerService.getWifiDirectAssistant().getPassphrase());

UpdateUIHook.this.activity.runOnUiThread(new Runnable()
{
@Override public void run()
{
activity.textWifiDirectPassphrase.setText(message);
}
});
}
}
}
}




















Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,18 @@
android:text="" />

<TextView
android:id="@+id/textRobotStatus"
android:id="@+id/textWifiDirectPassphrase"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_below="@+id/textWifiDirectStatus"
android:text="" />

<TextView
android:id="@+id/textRobotStatus"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/textWifiDirectPassphrase"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="" />

Expand Down

0 comments on commit edc733f

Please sign in to comment.