Office Hours — Today, February 8

Yesterday, February 7

Feb 8
9:55 AM
Mark M.
has entered the room
Mark M.
turned on guest access
10:00 AM
Oliver
has entered the room
Mark M.
hello, Oliver!
how can I help you today?
Oliver
Hey Mark...just a quick question
I have you all to myself ;)
thanks for the time
so the question
In an app similar to MyTracks
we are loading 'tracks' or paths over the map
great
in our old app we just dumped the database...and had content observers
it worked...
now...I am liking loaders quite a lot
_but_ I cannot think of a good way to use loaders in this instance
because I am essentially needing a loader with give me everything since
that leaves me with some options
bulk load from a loader...then observe / or get changes from a service
are you following me so far?
Mark M.
not exactly
"we just dumped the database" -- what does this phrase mean?
and, why are you bothering with Loaders, given that you have working code?
Oliver
SELECT * FROM POINTS WHERE session = x
that sort of thing
Mark M.
so, "dump" == "query"?
Oliver
then SELECT * FROM POINTS WHERE session = X and ID > somevalue
yup
10:05 AM
Oliver
sorry...being sloppy
10:05 AM
Mark M.
how are you "dumping" presently, if you are not using a Loader?
Oliver
actually it is fairly old code...so a managedCursor query
Mark M.
yeah, that's not ideal
so, why would there be a difference in using a Loader to replace your existing code, beyond the actual query itself?
never mind
stupid question
Oliver
I think the point is we need change only updates
cos the map already has the track plotted so far
Mark M.
OK
to me, this indicates that a Loader probably is not a good choice
replace your managedQuery() with using query() on a ContentResolver in an AsyncTask, to get it off the main application thread
and stick with the rest of your existing logic
Loader is designed to keep reloading your original Cursor, which it sounds like is not what you need, and therefore adds unnecessary overhead
Oliver
sure...and if possible save the loaded data in saveInstanceState?
10:10 AM
Oliver
for screen rotation etc.
Mark M.
my guess is that your data is too big for that
Oliver
I could have out[data, lastIdLoaded]
erm...not sure on size limitations...maybe 10,000 points...
x,y values
Mark M.
that's a bit big
use a retained fragment or onRetainNonConfigurationInstance() for data of that size
the Bundle used in onSaveInstanceState() can live for a while and cross process boundaries
Kadrov N.
has entered the room
Mark M.
hello, Kadrov!
Kadrov N.
Hi
Mark M.
Oliver: let me take a question from Kadrov, and I will be back with you shortly
Oliver
Thanks Mark...I'll let Kardov chip in.
Mark M.
Kadrov: do you have a question?
Oliver
np
Kadrov N.
Yes.
I'm trying to find legal way to get default selection color for buttons. Do you know one?
Mark M.
no, because it's not a color
it's a nine-patch PNG file that is part of a StateListDrawable
at least, by default
different devices may have done different things with the default device theme
10:15 AM
Mark M.
what are you trying to achieve?
Kadrov N.
I have application that should work on 2.2+ and 4.0+. At first case I use default lights theme and on second Holo.Light. But I have several custom controls and what to have same selection color for them as for default controls!
So, what's the best way to do it?
Mark M.
again, there is no "selection color", but rather an image that is used in the selected state as a background
if you cannot use the existing background images, you cannot sync with the device's default theme
hence, if you want consistency, set your own StateListDrawable for all widgets (e.g., buttons), so you control what it looks like everywhere within your app
Kadrov N.
ok, how to use this background image in my custom Selector?
Mark M.
there may be a way to achieve that via having a style refer to a value from another style, but that's beyond my style-handling expertise
I apologize for not being able to help much on this issue
10:20 AM
Kadrov N.
ok. So another way is setting my own StateListDrawable for all widgets. How to do it?
10:20 AM
Mark M.
copy the stock Android one from the SDK, and modify to suit
btn_default.xml is the background for a Button, for example
it will look something like this (pulled from android-10):
View paste (1 more line)
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_window_focused="false" android:state_enabled="true"
        android:drawable="@drawable/btn_default_normal" />
    <item android:state_window_focused="false" android:state_enabled="false"
        android:drawable="@drawable/btn_default_normal_disable" />
    <item android:state_pressed="true" 
        android:drawable="@drawable/btn_default_pressed" />
    <item android:state_focused="true" android:state_enabled="true"
        android:drawable="@drawable/btn_default_selected" />
    <item android:state_enabled="true"
        android:drawable="@drawable/btn_default_normal" />
    <item android:state_focused="true"
        android:drawable="@drawable/btn_default_normal_disable_focused" />
    <item
         android:drawable="@drawable/btn_default_normal_disable" />
...
the images referred to in the <item> elements are nine-patch PNGs, which are available in various densities
you would need to change whatever you want for however you wanted to use it
let me take a question from Oliver, and I will be back with you shortly
Oliver: do you have another question?
Kadrov N.
hm... so, I have to copy style xml-s for all controls that I use in my app localy to my APK and then modify colors. Am I correct?
Mark M.
Kadrov: not so much style XML but the background image resources, which you would then refer to from your own style XML
10:25 AM
Mark M.
for the Holo theme, this sort of customization can be somewhat automated using the Android Holo Theme Generator
I am not aware of an equivalent for pre-Holo themes
Oilver: do you have another question?
Oliver
Hi Mark, I think I am good. I have looked at MyTracks for an hour or so...and they really go to town. I will look at retaining the fragment data and do as you suggest. I think it will turn out to be quite simple.
10:30 AM
Mark M.
OK
Kadrov: if you have another question, go ahead
Kadrov N.
thanks for your help, Mark! I have no another question
Oliver
ok Mark...one small question...you will have to forgive me for fuzziness.
The question is regarding a search activity
say you have a list of items
and you want to search through them
_is_ the recommendation to have a dedicated search activity
(actually I aliased the list activity)
(therefore reused code)
Mark M.
you do not need a dedicated search results activity
however, the activity should make it obvious to the user what they are viewing
for example, you might indicate the list scope in the action bar title ("Search Results for: ...")
10:35 AM
Oliver
thanks Mark...so are you thinking of _not_ overlaying the activities?
state 1) list everything
state 2) commence search (typing in action bar)
user presses enter...
new activity launched _or_ list is just filtered?
Mark M.
either is appropriate
Oliver
ok...and if an activity is launched
and the user presses a search icon again
should the previous search activity be on the back stack?
list all > search a > search b etc.?
or list all > search
Mark M.
AFAIK, that's more or less up to you
Oliver
right...that sounds great
Mark M.
if you think that past search results will be important to the user, offering a back stack might be a good idea
but that's going to be fairly app-specific, I would imagine
and it'
(never mind last partial comment)
10:40 AM
Oliver
super...I think I'll leave it there...I'll try and make your next office hours with some further questions.
really appreciate your time
Mark M.
happy to help!
Kadrov: if you have additional questions, go ahead
Oliver
has left the room
10:45 AM
Kadrov N.
Mark, do you know any services for providing normal (well secure) trial period for android applications?
Mark M.
no -- I do not pay much attention to licensing engines
I think the preferred pattern today is the free app with in-app purchases to unlock additional features or content
Kadrov N.
I'm thinking about this schem: free application that will work during 14 days and after this period it'll ask user to buy full lifetime license (throw in-app purchase) or uninstall application.
Do you think it is ok?
Mark M.
I am not aware of time-limited apps being particularly popular
you might consider doing a search of the Play Store for "14 days" and the like, and see what sort of comments they get
10:50 AM
Kadrov N.
good idea!
Mark M.
from a technical standpoint, so long as you are not worried about rooted device users, it should be fairly simple to set up
Kadrov N.
only on problem. secure of trial period
I mean that user cud just uninstall and install again application after end of trial period!
how to protect this simple scenario?
Mark M.
correct
personally, I wouldn't use a trial period
beyond that, you would need to store some device identifier on your server and check for matches
however, there is no great device identifier
10:55 AM
Mark M.
Kadrov N.
yes, that's the way i thinking about...
so, you prefer free application with unlock of some futures by in-app purchases?
Mark M.
I think that works better for all parties, personally
Oliver
has entered the room
Oliver
has left the room
11:00 AM
Kadrov N.
and actually easier to implement then time limited application... you do not need server and so on...
Mark M.
correct
the key is having enough free-forever features to entice the user into trying the app and eventually upgrading
and that is a wrap for today's office hours chat
the transcript will be posted at http://commonsware.com/office-hours/ shortly
the next chat is Tuesday at 7:30pm Eastern Time
have a pleasant day!
Kadrov N.
Ok, Mark. Thanks for your advise and your help!
by
Kadrov N.
has left the room
Mark M.
turned off guest access

Yesterday, February 7

 

Office Hours

People in this transcript

  • Kadrov Nikita
  • Mark Murphy
  • Oliver