Re: [android-developers] Re: Share Loader's data between multiple fragment
Couldn't you abstract the different ways of loading data inside the loader? ...and pass some sort of "unique data ID" to each fragment to identity the data, but not the actual way of obtaining it (network, content provider, etc.). Then you'd be able to package this ID into each fragment's arguments, leveraging the framework's persistence mechanism for orientation changes, activity re-creation, etc...? -- K 2014-06-04 20:03 GMT+04:00 Nathan Barraille : > Yeah, I guess I can do that, but if I do I need to write custom code for > retaining the arguments across instance change, which I would have liked > the framework to be able to do for me, as described here: > https://groups.google.com/forum/#!topic/android-developers/bCc5tjOHQ1o > > > On Wed, Jun 4, 2014 at 8:47 AM, MathieuB wrote: > >> Like Doug said. That's sort of how i'm doing it and had no problem. >> >> So #2 kind of. >> >> Here's my onLoadFinished : >> >> @Override >> public void onLoadFinished(Loader> loader, >> ArrayList data) { >> >> CatalogTabFeatured featuredFragment = (CatalogTabFeatured) >> getSupportFragmentManager().findFragmentByTag(makeFragmentName(mViewPager.getId(), >> 0)); >> >> featuredFragment.setData(data); >> >> >> CatalogTabRecents recentsFragment = (CatalogTabRecents) >> getSupportFragmentManager().findFragmentByTag(makeFragmentName(mViewPager.getId(), >> 1)); >> >> recentsFragment.setData(data); >> >> CatalogTabRated ratedFragment = (CatalogTabRated) >> getSupportFragmentManager().findFragmentByTag(makeFragmentName(mViewPager.getId(), >> 2)); >> >> ratedFragment.setData(data); >> >> } >> >> -- >> You received this message because you are subscribed to the Google >> Groups "Android Developers" group. >> To post to this group, send email to android-developers@googlegroups.com >> To unsubscribe from this group, send email to >> android-developers+unsubscr...@googlegroups.com >> For more options, visit this group at >> http://groups.google.com/group/android-developers?hl=en >> --- >> You received this message because you are subscribed to a topic in the >> Google Groups "Android Developers" group. >> To unsubscribe from this topic, visit >> https://groups.google.com/d/topic/android-developers/rFQDqknx8VM/unsubscribe >> . >> To unsubscribe from this group and all its topics, send an email to >> android-developers+unsubscr...@googlegroups.com. >> >> For more options, visit https://groups.google.com/d/optout. >> > > -- > You received this message because you are subscribed to the Google > Groups "Android Developers" group. > To post to this group, send email to android-developers@googlegroups.com > To unsubscribe from this group, send email to > android-developers+unsubscr...@googlegroups.com > For more options, visit this group at > http://groups.google.com/group/android-developers?hl=en > --- > You received this message because you are subscribed to the Google Groups > "Android Developers" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to android-developers+unsubscr...@googlegroups.com. > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en --- You received this message because you are subscribed to the Google Groups "Android Developers" group. To unsubscribe from this group and stop receiving emails from it, send an email to android-developers+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[android-developers] Re: Camera preview "center crop" without SurfaceTexture
Note to others: the solution was to use a textureview (android 14+) On Friday, 25 April 2014 17:57:11 UTC+1, Sam Duke wrote: > > Im trying to show a camera preview to the user of arbitrary size. What I'd > like to do is pick an appropriate camera size based on the size of the > preview, then effectively do a center-crop of the camera output into this > (ie maintain aspect-ratio of the camera preview). As far as i can tell, the > camera by default stretches the camera onto the surface view so i need to > make the surface view have the same aspect as the chosen camera size and > then use another view to crop this. > > I've had some success by adapting the code from the (rather complicated) > android Camera app. (from here) > https://android.googlesource.com/platform/packages/apps/Camera.git/+/master > I noticed that the app uses two modes of operation depending on whether > surface textures are available. I didn't want to get into manually drawing > onto canvases as that seems overkill for this so I essentially tried to > take the surfaceholder implementation and flip the equality test in > "PreviewFrameLayout" like so: > > if (longSide < shortSide * mAspectRatio) > > Right now i have the correct behaviour in a small preview, but if i try to > make it the start of the screen the application seems to just quit (i think > drawing off the screen causes an issue). > > SO I'm basically back at square 1 and I've been working at this for so > long i figure i must just be doing something wrong. can anyone tell me what > im doing wrong or if this is even possible? It feels like there is some > fundamental limitation preventing me from having one view crop another... > -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en --- You received this message because you are subscribed to the Google Groups "Android Developers" group. To unsubscribe from this group and stop receiving emails from it, send an email to android-developers+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: [android-developers] Re: Share Loader's data between multiple fragment
Yeah, I guess I can do that, but if I do I need to write custom code for retaining the arguments across instance change, which I would have liked the framework to be able to do for me, as described here: https://groups.google.com/forum/#!topic/android-developers/bCc5tjOHQ1o On Wed, Jun 4, 2014 at 8:47 AM, MathieuB wrote: > Like Doug said. That's sort of how i'm doing it and had no problem. > > So #2 kind of. > > Here's my onLoadFinished : > > @Override > public void onLoadFinished(Loader> loader, ArrayList > data) { > > CatalogTabFeatured featuredFragment = (CatalogTabFeatured) > getSupportFragmentManager().findFragmentByTag(makeFragmentName(mViewPager.getId(), > 0)); > > featuredFragment.setData(data); > > > CatalogTabRecents recentsFragment = (CatalogTabRecents) > getSupportFragmentManager().findFragmentByTag(makeFragmentName(mViewPager.getId(), > 1)); > > recentsFragment.setData(data); > > CatalogTabRated ratedFragment = (CatalogTabRated) > getSupportFragmentManager().findFragmentByTag(makeFragmentName(mViewPager.getId(), > 2)); > > ratedFragment.setData(data); > > } > > -- > You received this message because you are subscribed to the Google > Groups "Android Developers" group. > To post to this group, send email to android-developers@googlegroups.com > To unsubscribe from this group, send email to > android-developers+unsubscr...@googlegroups.com > For more options, visit this group at > http://groups.google.com/group/android-developers?hl=en > --- > You received this message because you are subscribed to a topic in the > Google Groups "Android Developers" group. > To unsubscribe from this topic, visit > https://groups.google.com/d/topic/android-developers/rFQDqknx8VM/unsubscribe > . > To unsubscribe from this group and all its topics, send an email to > android-developers+unsubscr...@googlegroups.com. > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en --- You received this message because you are subscribed to the Google Groups "Android Developers" group. To unsubscribe from this group and stop receiving emails from it, send an email to android-developers+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[android-developers] Re: Share Loader's data between multiple fragment
Like Doug said. That's sort of how i'm doing it and had no problem. So #2 kind of. Here's my onLoadFinished : @Override public void onLoadFinished(Loader> loader, ArrayList data) { CatalogTabFeatured featuredFragment = (CatalogTabFeatured) getSupportFragmentManager().findFragmentByTag(makeFragmentName(mViewPager.getId(), 0)); featuredFragment.setData(data); CatalogTabRecents recentsFragment = (CatalogTabRecents) getSupportFragmentManager().findFragmentByTag(makeFragmentName(mViewPager.getId(), 1)); recentsFragment.setData(data); CatalogTabRated ratedFragment = (CatalogTabRated) getSupportFragmentManager().findFragmentByTag(makeFragmentName(mViewPager.getId(), 2)); ratedFragment.setData(data); } -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en --- You received this message because you are subscribed to the Google Groups "Android Developers" group. To unsubscribe from this group and stop receiving emails from it, send an email to android-developers+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[android-developers] well, when tracking location in Google maps (eg. every 5sec) what i must use?
In HTML5 hybrid development (eg with PhoneGap) in Android or iOS or BB or WP Is best when google map find current location use accuracy HIGH with fall back to LOW... well, when tracking location in Google maps (eg. every 5sec) what i must use and how? can you give urls to sample code... -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en --- You received this message because you are subscribed to the Google Groups "Android Developers" group. To unsubscribe from this group and stop receiving emails from it, send an email to android-developers+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[android-developers] Re: Share Loader's data between multiple fragment
I would do #2, except don't use setArguments to pass the data in. When the loader callbacks fire, just reach into each fragment instance directly and call a custom method to pass the model in. You might have to check fragment class types and cast to implement this. Personally I would make all the fragments implement an interface such as ModelReceiver which a method receiveModel(Model) so they can get the model object. Doug On Tuesday, June 3, 2014 3:53:41 PM UTC-7, Nathan Barraille wrote: > > Hello, > I have a problem with the Android framework for which I'm not able to find > any ideal design solution. > I have an activity that contains multiple fragments, all those fragments > need to access the same model object. This model object can be loaded from > a memory cache, ContentProvider or network, depending on a bunch of > parameters. I wanted to use a Loader to load that model object, so that it > doesn't have to be loaded again when the activity is recreated, and it can > be observed if it changes. > All my fragments don't really have a purpose without the model object > loaded, as they don't have any data to display. > Here are the options I considered: > > *#1: Have the activity initialize the loader in its onCreate() method, and > add the fragments to the activity when the model finishes loading: * > *Problem:* It is unsafe to make fragment transactions in a callback > method, because the activity state might be paused, according to > http://developer.android.com/reference/android/app/LoaderManager.LoaderCallbacks.html#onLoadFinished(android.content.Loader, > > D) > > *#2: Have the activity initialize the loader and add the fragments in its > onCreate() method, and call a custom method on the fragment to set the > model* > *Problem:* I cannot use the recommended setArguments() method to set > the data on the fragment, which means that if my fragment is re-created by > the system, it won't have a reference to the model anymore > > *#3: Have the activity initialize the loader and add the fragments in its > onCreate() method, and have the fragments access the model through the > activity* > *Problem*: The fragments won't know whether or not the model is > loaded in the activity, and if I add a method on the fragment for the > activity to let it know, I'll have the same problem as #2 > > *#4: Have all my fragments initialize a loader independently and load the > data on their own.* > *Problem:* That's really inefficient, especially if the model needs > to be loaded from the network > > I'm kind of thinking now that I could do something like #3, and having an > additional call in my fragments' onResume() that checks whether or not the > model is set in the activity to set its state, but that seems hacky... > > Is there a cleaner way of doing this? > > Thanks! > -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en --- You received this message because you are subscribed to the Google Groups "Android Developers" group. To unsubscribe from this group and stop receiving emails from it, send an email to android-developers+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.