Yes it drove me nuts last time I was trying to write my google maps plugin.
https://github.com/imhotep/MapsPlugin/blob/master/GMPlugin.java ctx.getContext() as you see in the file above definitely looks stupid and broke my plugin that was working initially. My vote goes for trashing ctx. -a On Mon, Jun 18, 2012 at 2:58 PM, Filip Maj <[email protected]> wrote: > Sure thing. > > So from the early PhoneGap/Cordova days, the plugin interface (see [1] for > old code ref from 0.9.6) has had a "ctx" member which pointed to a > PhoneGapActivity (later renamed CordovaActivity) member which was an > interface that extended the Android Activity class. The Activity class > extends the Context class. So, in terms of naming, this made a lot of > sense. In plugins back in the days of yore, you could do this in your > plugin code: > > (Context)this.ctx > > .. And get access to Android Context info. Standard Java casting ceremony. > Nothing out of the ordinary. > > Since CordovaWebView came into the picture, it is no longer necessary that > the top-level class housing the cordova web view is an activity. All that > we require now is that the housing class implement the CordovaInterface. > Therefore we don't have the guarantee that "ctx" is a Context. > > This changes things. You can no longer cast a plugin's "ctx" member to > Context. > > For me it's just about labeling. Rename this to something not resembling > "Context" so it is _less_ confusing. > > Hope that makes sense. > > [1] > https://github.com/apache/incubator-cordova-android/blob/f3d7ce8fc368609e73 > 923ca17913f0129f3620cd/framework/src/com/phonegap/api/Plugin.java#L23 > > On 6/18/12 2:45 PM, "Brian LeRoux" <[email protected]> wrote: > > >cool w/ that, and of course I trust you, but can you explain the > >problem with ctx, a familiar convention since the earliest days of > >phonegap/android, so I understand the benefit of the proposed > >solution? > > > >(breaking plugins will cause some backlash and, as I mentioned, > >creating a more abstract interface does increase ramp up for new > >native devs) > > > > > >On Mon, Jun 18, 2012 at 4:35 PM, Filip Maj <[email protected]> wrote: > >> Brian, we're doing Android devs (potential plugin authors) a favor here, > >> trust me. > >> > >> 2.0 is our chance to break interfaces. > >> > >> Also, +1 to Bryce's comment re: get this change in for 1.9, deprecate > >>the > >> .ctx member in 1.9 as well, and axe it in 2.0. > >> > >> On 6/18/12 12:15 PM, "Brian LeRoux" <[email protected]> wrote: > >> > >>>I'm of the opinion that native impl should *not* abstract the > >>>platforms at the plugin level. It breaks old plugins, which is fine, > >>>but for what benefit? Conceptual purity at that level will make it > >>>harder to recruit plugin authors from their respective navtive > >>>platforms. > >>> > >>>On Mon, Jun 18, 2012 at 3:06 PM, Michael Brooks > >>><[email protected]> wrote: > >>>> If we are planning to rename the Cordova interface object, then we > >>>>should > >>>> do it for each platform in a consistent manner. There should be a > >>>>parent > >>>> JIRA issue with sub-tasks for each Cordova platform. > >>>> > >>>> On Mon, Jun 18, 2012 at 11:50 AM, Filip Maj <[email protected]> wrote: > >>>> > >>>>> Yeh "ctx" implies Context, especially for Android peoples, so +1 to > >>>>> renaming to something less Android-ey. > >>>>> > >>>>> On 6/18/12 11:45 AM, "Joe Bowser" <[email protected]> wrote: > >>>>> > >>>>> >Hey > >>>>> > > >>>>> >Since we're approaching 2.0 and since part of the goals of 2.0 is to > >>>>> >improve the plugin architecture, I'm wondering if we should take the > >>>>> >opportunity to give the CordovaInterface variable on Plugin.java a > >>>>>name > >>>>> >other than ctx, which on Android usually refers to a context. The > >>>>>reason > >>>>> >for this is the fact that there's a use case where the > >>>>>CordovaInterface > >>>>> >may > >>>>> >not be a Context. I propose that we change the name to cordova. > >>>>> > > >>>>> >I'm not sure if this needs a JIRA ticket or not. > >>>>> > > >>>>> >Any thoughts? > >>>>> > > >>>>> >Joe > >>>>> > >>>>> > >> > >
