Office Hours — Today, October 5

Saturday, October 3

Oct 5
7:20 PM
Mark M.
has entered the room
Mark M.
turned on guest access
7:25 PM
MyWay
has entered the room
Mark M.
hello, MyWay!
how can I help you today?
MyWay
hi Mark :)
I switched Activity to AppCompatActivity for Material Design, now I'd like to do the same for PreferenceActivity, but I see there is no AppCompatPreferenceActivity and I see you're extending Activity in your book, should I extend AppCompatActivity? What's the difference?
Mark M.
in your case, use the new android.support.v14.preference.PreferenceFragment in an AppCompatActivity, I imagine
MyWay
ah, I was using android.preference.PreferenceFragment
Mark M.
actually, there's also android.support.v7.preference.PreferenceFragmentCompat
I'm not sure what the role of one is versus the other
7:30 PM
Mark M.
since their docs are just copy-and-paste jobs from the original PreferenceFragment
MyWay
in my case I'm on minSdk >= 14
Mark M.
I still don't really know which of those two classes is the right answer
but, I'm sure it's one of them :-)
MyWay
eheh
and what about ListActivity? Should I change something?
Mark M.
just use AppCompatActivity and put in your own ListView
or ListFragment
it's not like ListActivity had all that much to it
MyWay
yeah
7:35 PM
MyWay
for DialogFragment I should do something or just apply a style?
Mark M.
there is AppCompatDialogFragment
to be honest, I haven't done much with the whole AppCompat ecosystem
MyWay
ah, didn't notice it, thanks
If I understand correctly: as I'm switching PreferenceFragment (the support v14 one), I just have to move the call to addPreferencesFromResource inside onCreatePreferences instead of onCreate, because onCreatePreferences is called when onCreate is, right?
Mark M.
um, I guess so
I have never used this class
I just know that it exists
MyWay
ah
Mark M.
did I mention that I haven't done much with the whole AppCompat ecosystem? :-)
MyWay
yes it seems they splitted them
ahah
7:40 PM
MyWay
one last thing, after switching to AppCompatActivity I've noticed that the logo/icon isn't used anymore (they motivated it "the icon shouldn't be that important if you give it a nice look, or something like that), to me it does not seems that bad, but only if there is a navigation drawer, can I restore the old logo/icon on the actionbar?
Mark M.
yeah, but you probably won't want to
MyWay
or you think it's better to not restore the logo/icon?
Mark M.
I tried it, and while it works, the icon does not get sized properly
MyWay
ah
Mark M.
then again, I haven't tried it in a year, and so it might have gotten better
MyWay
didn't know, nice
Mark M.
I forget the exact recipe for doing it, though
MyWay
what do you think about it?
Mark M.
what do I think about what?
MyWay
about their motivation to not use a icon anymore
Mark M.
I never understood the rationale
(for the change, that is)
MyWay
yes
I will try to restore it and see if there are sizing problems again
thank you very much as always :P
Mark M.
you are very welcome
7:50 PM
MyWay
https://plus.google.com/+AndroidDevelopers/post... (So what about the preferences-v14 library? You’ll find it offers the same API as the preferences-v7 library, but built on framework Fragments and DialogFragments.)
apparently no other differences
Mark M.
OK, so for AppCompat, you'll want the preferences-v7 one
and PreferenceFragmentCompat
MyWay
and apparently no more isValidFragment
Mark M.
that's a PreferenceActivity thing
MyWay
ah, that's why
Mark M.
since there's no PreferenceActivity in the AppCompat scenario, there's no isValidFragment() to have to fuss with
7:55 PM
MyWay
before I was using onBuildHeaders to loadHeadersFromResource (load my header), but now that I'm inside AppCompatActivity how should I load it?
8:00 PM
Mark M.
according to that G+ post you linked to, there's no preference header support
"One thing you’ll note isn’t in here is preference headers and you’d be totally right. However, that doesn’t mean a single list of preferences need to span a 10” tablet screen. Instead, your Activity can implement OnPreferenceStartFragmentCallback (http://goo.gl/IZWZBP) to handle preferences with an app:fragment attribute or OnPreferenceStartScreenCallback (http://goo.gl/CFp5Cr) to handle PreferenceScreen preferences. This allows you to construct a ‘header’ style PreferenceFragmentCompat in one pane and use those callbacks to replace a second pane without working in two separate types of XML files."
8:20 PM
Bryan
has entered the room
Bryan
Hello
Mark M.
hello, Bryan!
Bryan
I have a couple questions, hopefully quick
Mark M.
the chat ends soonish -- how can I help you?
go right ahead
Bryan
I am saving a file to the downloads directory
and it is not showing up
here is what I am using to get the mediascanner to see it
but it doesn't seem to work
getting it....
View paste
ArrayList<String> toBeScanned = new ArrayList<String>();
                    toBeScanned.add(file.getAbsolutePath());
                    String[] toBeScannedStr = new String[toBeScanned.size()];
                    toBeScannedStr = toBeScanned.toArray(toBeScannedStr);
                        MediaScannerConnection.scanFile(getActivity(), toBeScannedStr, null, new MediaScannerConnection.OnScanCompletedListener() {

                        @Override
                        public void onScanCompleted(String path, Uri uri) {
                           Log.d("SAVE SCAN COMPLETED: ", path+" / "+uri);

                        }
                    });
Mark M.
is your callback being invoked?
Bryan
View paste
10-05 20:23:11.679 25025-25025/com.novvia.fispy I/saveData: Data Saved - /storage/emulated/0/Download/bryan4.txt
10-05 20:23:11.843 25025-25063/com.novvia.fispy D/SAVE SCAN COMPLETED:: /storage/emulated/0/Download/bryan4.txt / content://media/external/file/19314
yeah
and the file is there (if I use a 3rd party file explorer)
Mark M.
but you're not seeing it on your desktop OS?
Bryan
but if I go to "downloads" in my app drawer on my nexus 6
it isn't there
Mark M.
oh, it's not going to show up there
Bryan
i'll check on desktop (mac)
Mark M.
that's only for files downloaded via DownloadManager
Bryan
ok
that makes sense then
so what I am wanting to do is offer a download to csv of a "history" in my app
what is the best way to do that and get it into something "easy" for the user to find it
I was hoping to just pop it into download
8:25 PM
Bryan
I was even going to use the download manager, but it will only take http/s
8:25 PM
Bryan
it feels like a trivial exercise that is actually a lot harder than it would seem it should be
Mark M.
"easy", IMHO, would be ACTION_SEND, to allow the user to share the content via their preferred mechanism
Bryan
ok, that makes sense, and I could do that with a generated file?
Mark M.
sure
just write the file out first, before triggering the share option
Bryan
so I could pop up a dialog with spinner while the file builds and then throw up the share intent?
Mark M.
sure
Bryan
ok, another quick question?
<4 min
Mark M.
type quickly! :-)
Bryan
we are trying to refactor a project and we are using lint
it is suggesting we take ALL strings out of the code
including log comments and json declarations, etc etc
things that don't need to be translated
lets say there are 400 of those
I don't want to have to add 400 suppressions
but want to continue to use lint
your expert opinion?
Mark M.
ummm... I think you're out of luck
perhaps isolate the strings into a Constants class somewhere and suppress the lint warnings on the class?
Bryan
not what I wanted to hear, I wanted some sort of commonsware magical answer that made it easy and make sense
ooooooh, I like it!
there you go!
Mark M.
I haven't tried suppressing that particular Lint warning at the class level, so it might not work
Bryan
I think I will do something like that
Mark M.
and then you have 400 refactorings to do
Bryan
lol
Mark M.
which may not be a net improvement over 400 suppressions
Bryan
do you leave strings in your code?
Mark M.
sure, ones akin to the ones that you describe
Bryan
ok, cool
Thanks, just got in under the wire! Have a good nite
8:30 PM
Mark M.
you too!
that's a wrap for today's chat
the transcript will be posted to https://commonsware.com/office-hours/ shortly
the next chat is tomorrow at 4pm US Eastern
MyWay
has left the room
Bryan
has left the room
Mark M.
turned off guest access

Saturday, October 3

 

Office Hours

People in this transcript

  • Bryan
  • Mark Murphy
  • MyWay