Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: using custom master chooser #55

Merged
merged 5 commits into from
Mar 17, 2017
Merged

Feature: using custom master chooser #55

merged 5 commits into from
Mar 17, 2017

Conversation

jubeira
Copy link
Contributor

@jubeira jubeira commented Mar 16, 2017

This PR adds a settings activity that replaces the standard Master Chooser.
This allows connecting automatically to ROS master upon app start, as well as eventually adding more features to the Activity.

The MasterChooserSettingsActivity could be upstreamed to Rosjava once this is reviewed, corrected and ready.

mSharedPref = PreferenceManager.getDefaultSharedPreferences(getBaseContext());

// This activity requires a method to force its start when "show settings" is off.
boolean editSettings = getIntent().getBooleanExtra("edit_settings", false);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if this is the best way of doing this. Comments are welcome!

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI, in TangoRosStreamer we overrided startMasterChooser in the RunningActivity to start the SettingsActivity when a certain boolean is true. In this case, this boolean corresponds to showSettings I believe?
Did you think of doing something similar?

Copy link
Contributor Author

@jubeira jubeira Mar 17, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes! Let me explain a bit further:
A few days ago we introduced some changes in RosActivity. The idea was to provide a standard method of using a custom MasterChooser without needing to override startMasterChooser or any other method.
That PR in android_core allows to set a custom Activity when the RosActivity is created, so instead of starting the standard MasterChooser, it will start a custom activity like this one. The "problem" here is that in your case, you have access to the shared preferences in the overridden startMasterChooser (so you can decide what to execute at that point). I don't have access to those variables in my MainActivity constructor, so I needed another mechanism to implement the auto-connection.
Then, I added a shared pref (show_settings_on_startup), so the user can skip the preferences activity the next time the app is launched. The problem is that this flag would prevent the settings activity to be launched ever again if there was no way to force it. And that's where this "edit_settings" extra comes in: if the "show_settings_on_startup" is off, it allows launching the settings activity.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand the issue. I think it's not super clean, but I think it is acceptable for now. Perhaps I'd change the name edit_settings to force_show_settings , ignore_show_settings_on_startup or something like that.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jubeira Thanks for the explanation.

}

@Override
public void onBackPressed() {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I implemented this functionality in the back button callback because it's the fastest way of using the existing functionality of the standard RosActivity (basically, returning what the standard onActivityResult expects).
The onActivityResult callback could be modified using setOnActivityResultCallback from RosActivity too as an alternative.

Copy link
Collaborator

@PerrineAguiar PerrineAguiar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks good, but I have some comments/questions about the MasterChooserSettingsActivity.

// This activity requires a method to force its start when "show settings" is off.
boolean editSettings = getIntent().getBooleanExtra("edit_settings", false);
boolean showSettings = mSharedPref.getBoolean(getString(R.string.pref_show_settings_on_startup_key), true);
if (!showSettings && !editSettings) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you explain the difference between showSettings and editSettings?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(see comment above).
Basically, showSettings is intended to skip the settings activity the next time the app is launched. And editSettings forces its execution if showSettings is disabled (for example, when you click the "settings" menu button in the MainActivity to edit the settings again).
Now that you mention it, perhaps the variable naming is not the best.

mSharedPref = PreferenceManager.getDefaultSharedPreferences(getBaseContext());

// This activity requires a method to force its start when "show settings" is off.
boolean editSettings = getIntent().getBooleanExtra("edit_settings", false);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI, in TangoRosStreamer we overrided startMasterChooser in the RunningActivity to start the SettingsActivity when a certain boolean is true. In this case, this boolean corresponds to showSettings I believe?
Did you think of doing something similar?

Copy link
Member

@adamantivm adamantivm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

some comments but from my perspective it's good for now.


@Override
public boolean onOptionsItemSelected(MenuItem item) {
mLog.info("Option selected: " + item.getItemId());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you need to leave this logging (also below)?

@@ -0,0 +1,153 @@
package com.ekumen.tangobot.application;

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: extra line

@@ -0,0 +1,153 @@
package com.ekumen.tangobot.application;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing license header


// Set the summary to reflect the new value.
preference.setSummary(
index >= 0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the indentation here looks odd

mSharedPref = PreferenceManager.getDefaultSharedPreferences(getBaseContext());

// This activity requires a method to force its start when "show settings" is off.
boolean editSettings = getIntent().getBooleanExtra("edit_settings", false);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand the issue. I think it's not super clean, but I think it is acceptable for now. Perhaps I'd change the name edit_settings to force_show_settings , ignore_show_settings_on_startup or something like that.

@@ -0,0 +1,22 @@
package com.ekumen.tangobot.application;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing copyright header

-Fix for preference change after attempting a connection for the first time.
@jubeira
Copy link
Contributor Author

jubeira commented Mar 17, 2017

Thanks for your reviews, the comments have been addressed.
I also addressed a problem with the display of the Snackbar when changing the settings after a connection attempt (as the settings activity can be shown on startup even after the first run, there was case that wasn't being handled properly). Merging now.

@jubeira jubeira merged commit 212fe78 into ekumenlabs:master Mar 17, 2017
@jubeira jubeira deleted the dev/using_custom_master_chooser branch March 22, 2017 12:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants