[
https://issues.apache.org/jira/browse/CB-3018?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13633026#comment-13633026
]
Mike Kwan edited comment on CB-3018 at 4/16/13 5:18 PM:
--------------------------------------------------------
Hi Joe. I appreciate the prompt response - are you advising that Cordova not be
used with Fragments? What is the recommended way of supporting multiple
CordovaWebViews from within an Activity? Fragments seems an ideal solution for
this usecase allowing us to modularise and decompose logic.
I understand this is not a support forum but perhaps it is worth re-evaluating
design decisions based on old Android APIs which are now deprecated.
My current workaround has two requirements:
- Copy and paste boilerplate CordovaInterface implementation from DroidGap to
my Activity
- Hold a mapping of currently active Fragments within the Activity and access
this from within CordovaPlugin
A Fragment reference is obtained from a CordovaPlugin by passing its WebView
reference to the Activity which performs logic similar to this:
{code:java}
private final Set<Fragment> weakFragments = Collections.newSetFromMap(new
WeakHashMap<Fragment, Boolean>)());
public Fragment getFragmentFromView(View view) {
for(Fragment fragment : this.weakFragments) {
if(fragment != null && fragment.getView().equals(view)) {
return fragment;
}
}
return null;
}
{code}
This creates an unnecessary coupling and a rigid requirement the Fragment's
view to be the CordovaWebView. Would it be worthwhile to revisit the
accessibility of Cordova from Fragments?
was (Author: mike kwan):
Hi Joe. I appreciate the prompt response - are you advising that Cordova
not be used with Fragments? What is the recommended way of supporting multiple
CordovaWebViews from within an Activity? Fragments seems an ideal solution for
this usecase allowing us to modularise and decompose logic.
I understand this is not a support forum but perhaps it is worth re-evaluating
design decisions based on old Android APIs which are now deprecated.
My current workaround has two requirements:
- Copy and paste boilerplate CordovaInterface implementation from DroidGap to
my Activity
- Hold a mapping of currently active Fragments within the Activity and access
this from within CordovaPlugin
A Fragment reference is obtained from a CordovaPlugin by passing its WebView
reference to the Activity which performs logic similar to this:
private final Set<Fragment> weakFragments = Collections.newSetFromMap(new
WeakHashMap<Fragment, Boolean>)());
public Fragment getFragmentFromView(View view) {
for(Fragment fragment : this.weakFragments) {
if(fragment != null && fragment.getView().equals(view)) {
return fragment;
}
}
return null;
}
This creates an unnecessary coupling and a rigid requirement the Fragment's
view to be the CordovaWebView. Would it be worthwhile to revisit the
accessibility of Cordova from Fragments?
> Allow Cordova to be more accessible from Fragments
> --------------------------------------------------
>
> Key: CB-3018
> URL: https://issues.apache.org/jira/browse/CB-3018
> Project: Apache Cordova
> Issue Type: Improvement
> Components: Android
> Affects Versions: 2.5.0
> Reporter: Mike Kwan
> Assignee: Joe Bowser
>
> It is difficult to use Cordova when using the Fragment API added in API level
> 11 (Android 3.0). A cursory search reveals other developers are having
> similar problems or have created workarounds:
> http://stackoverflow.com/questions/13070205/android-phonegap-and-fragments
> https://groups.google.com/forum/?fromgroups=#!topic/phonegap/aVvf1bnDavM
> A typical usecase for CordovaWebView within Fragments is if an app wants to
> support multiple independent CordovaWebViews within an Activity. With the
> deprecation of TabActivity in 3.0 we are seeing an increasing move to the
> recommended Fragment architecture. The usage of Fragments in standard Android
> apps is significant and I believe it would make sense to allow Cordova to be
> more accessible from this paradigm.
> The Android implementation of Cordova is heavily biased towards users who
> want to use CordovaWebView from within an Activity. In comparison, using
> CordovaWebView from within a Fragment can be rather unwieldy.
> - Cordova provides DroidGap which extends Activity and conveniently provides:
> 1. A standard implementation of CordovaInterface.
> 2. A standard configuration of the CordovaWebView class (vanilla
> CordovaWebViewClient and CordovaChromeClient)
> When using a Fragment the developer is forced to reimplement this
> boilerplate code (see the workaround provided at
> http://www.infil00p.org/advanced-tutorial-using-cordovawebview-on-android/).
> The configuration of the CordovaWebView itself is trivial in comparison to
> the code that has to be duplicated for CordovaInterface.
> - CordovaPlugin provides a reference to a CordovaInterface which in turn
> provides access to the containing Activity. As far as I am aware it is not
> possible to get access to the associated Fragment without storing a Fragment
> to CordovaWebView mapping within the Activity:
> http://stackoverflow.com/questions/13070205/android-phonegap-and-fragments
> Rather than working around Cordova it would be really great if the library
> added support for Fragments. One solution I suggest is:
> - Extract the implementation of CordovaInterface out from DroidGap.
> CordovaImpl can then be instantiated and reused for Fragments.
> - Refactoring CordovaInterface properly to work with Fragments rather than
> Activity will require a substantial change - I need to look deeper into the
> code before commenting here. This issue presents a major barrier to using
> Cordova to its full capacity with Fragments.
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira