Created
July 28, 2013 12:07
-
-
Save nagakenjs/6098350 to your computer and use it in GitHub Desktop.
Helper class for ActionBarActivity
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package jp.nagakenjs.appcompathelper.app; | |
import android.app.Activity; | |
import android.support.v4.app.Fragment; | |
import android.support.v7.app.ActionBarActivity; | |
public class ActionBarFragment extends Fragment { | |
private ActionBarActivity mActivity; | |
public ActionBarActivity getActionBarActivity() { | |
return mActivity; | |
} | |
@Override | |
public void onAttach(Activity activity) { | |
if (!(activity instanceof ActionBarActivity)) { | |
throw new IllegalStateException(getClass().getSimpleName() | |
+ " must be attached to a ActionBarActivity."); | |
} | |
mActivity = (ActionBarActivity) activity; | |
super.onAttach(activity); | |
} | |
@Override | |
public void onDetach() { | |
mActivity = null; | |
super.onDetach(); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package jp.nagakenjs.appcompathelper.app; | |
import android.app.Activity; | |
import android.support.v4.app.ListFragment; | |
import android.support.v7.app.ActionBarActivity; | |
public class ActionBarListFragment extends ListFragment { | |
private ActionBarActivity mActivity; | |
public ActionBarActivity getActionBarActivity() { | |
return mActivity; | |
} | |
@Override | |
public void onAttach(Activity activity) { | |
if (!(activity instanceof ActionBarActivity)) { | |
throw new IllegalStateException(getClass().getSimpleName() | |
+ " must be attached to a ActionBarActivity."); | |
} | |
mActivity = (ActionBarActivity) activity; | |
super.onAttach(activity); | |
} | |
@Override | |
public void onDetach() { | |
mActivity = null; | |
super.onDetach(); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package jp.nagakenjs.appcompathelper.app; | |
import android.os.Bundle; | |
import android.view.LayoutInflater; | |
import android.view.View; | |
import android.view.ViewGroup; | |
import android.webkit.WebView; | |
public class WebViewFragment extends ActionBarFragment { | |
private WebView mWebView; | |
private boolean mIsWebViewAvailable; | |
@Override | |
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { | |
if (mWebView != null) { | |
mWebView.destroy(); | |
} | |
mWebView = new WebView(getActivity()); | |
mIsWebViewAvailable = true; | |
return mWebView; | |
} | |
@Override | |
public void onPause() { | |
super.onPause(); | |
mWebView.onPause(); | |
} | |
@Override | |
public void onResume() { | |
super.onResume(); | |
mWebView.onResume(); | |
} | |
@Override | |
public void onDestroyView() { | |
mIsWebViewAvailable = false; | |
super.onDestroyView(); | |
} | |
@Override | |
public void onDestroy() { | |
if (mWebView != null) { | |
mWebView.destroy(); | |
mWebView = null; | |
} | |
super.onDestroy(); | |
} | |
public WebView getWebView() { | |
return mIsWebViewAvailable ? mWebView : null; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment