-
Notifications
You must be signed in to change notification settings - Fork 19
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
Feature: using custom master chooser #55
Conversation
-Toolbar working -Menu display added with no actions
… run functionality.
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); |
There was a problem hiding this comment.
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!
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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() { |
There was a problem hiding this comment.
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.
There was a problem hiding this 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) { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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?
There was a problem hiding this 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()); |
There was a problem hiding this comment.
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; | |||
|
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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.
Thanks for your reviews, the comments have been addressed. |
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.