Mobile SDK Android: EPZWebViewFragment
From ePrize Developers Wiki
Contents |
Overview
The EPZWebViewFragment class is a Fragment class that contains all necessary logic to load web pages and fully integrate with core EPrizeMobileSDK logic. It is used in the SDK's built-in EPZPromoWebViewController. You can also use this class in your own custom Activities if you do not wish to use the SDK's built-in web view controller.
Sample Integration
If you do not wish to use the SDK's built-in EPZPromoWebViewController, you can use this class in your own Activities. For instance, you can include the following Fragment tag in your Activity's layout XML file:
<fragment android:id="@+id/epzWebViewFragment" android:layout_width="match_parent" android:layout_height="match_parent" android:name="com.eprize.mobile.eprizemobilesdk.EPZWebViewFragment" />
If you wish to include your own toolbar/menu with "Back", "Forward", "Refresh" buttons, you will want to subscribe to the EPZWebViewOnPageStartedEvent and EPZWebViewOnPageFinishedEvent so you can know when to enable/disable your buttons/menu items, as seen in the sample below.
private EPZWebViewFragment mEpzWebViewFragment; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); ... mEpzWebViewFragment = getFragmentManager().findFragmentById(R.id.epzWebViewFragment); mEpzWebViewFragment.loadUrl("http://www.helloworld.com/"); ... } private void refreshMenuItems() { if (mEpzWebViewFragment.canGoBack()) { // Safe to enable a "back" button. } if (mEpzWebViewFragment.canGoForward()) { // Safe to enable a "forward" button. } } // Method called when "back" button is clicked. public void goBack() { if (mEpzWebViewFragment.canGoBack()) { mEpzWebViewFragment.goBack(); } else { this.finish(); } } // Method called when "forward" button is clicked. public void goForward() { mEpzWebViewFragment.goForward(); } // Method called when "refresh" button is clicked. public void reload() { mEpzWebViewFragment.reload(); } // Subscribe to web view events. @Subscribe public void handleEPZWebViewOnPageStartedEvent(EPZWebViewOnPageStartedEvent event) { setProgressBarIndeterminateVisibility(true); refreshMenuItems(); } @Subscribe public void handleEPZWebViewOnPageFinishedEvent(EPZWebViewOnPageFinishedEvent event) { setProgressBarIndeterminateVisibility(false); refreshMenuItems(); }
Public Methods
loadUrl
public void loadUrl(String url)
Method to load the specified URL into the top web view of the fragment.
Parameters
url The URL string to load into the active web view window.
getActiveWindow
public EPZWebView getActiveWindow()
Returns
EPZWebView The top-most, active web view window.
getNumberOfWindows
public int getNumberOfWindows()
Returns
int Number of web view windows in the fragment.
getCurrentUrl
public String getCurrentUrl()
Returns
String The current URL that is loaded in the web view.
getIsLoading
public boolean getIsLoading()
Returns
boolean Flag for whether or not the active window is loading.
canGoBack
public boolean canGoBack()
Returns
boolean Flag for whether or not the active web view window can navigate back.
canGoForward
public boolean canGoForward()
Returns
boolean Flag for whether or not the active web view window can navigate forward.
goBack
public void goBack()
Method to navigate back in the active web view window. If the active web view window cannot navigate back, it will be removed (if it is not the only web view instance), or the EPZPromoWebViewLifecycleEvent will dispatch with eventName value of EPZConstants.LIFECYCLE_EVENT_CLOSE, alerting the parent Activity that it can finish (or otherwise handle the EPZWebViewFragment).
goForward
public void goForward()
Method to navigate forward in the active web view window, if available.
reload
public void reload()
Method to reload the current page in the active web view window.
closeActiveWebView
public EPZWebView getActiveWindow()
Method to close the active web view window. If the active web view is the only web view instance, the EPZPromoWebViewLifecycleEvent will dispatch with eventName value of EPZConstants.LIFECYCLE_EVENT_CLOSE, alerting the parent Activity that it can finish (or otherwise handle the EPZWebViewFragment).