Android Open Source - Gazetti_Newspaper_Reader Web View Fragment






From Project

Back to project page Gazetti_Newspaper_Reader.

License

The source code is released under:

MIT License

If you think the Android project Gazetti_Newspaper_Reader listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package in.sahildave.gazetti.news_activities;
/*from   w  w  w  .  j a  v  a 2s  . c  o m*/
import android.graphics.Bitmap;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ProgressBar;
import in.sahildave.gazetti.R;

/**
 * Created by sahil on 5/10/14.
 */
public class WebViewFragment extends Fragment {

    private WebView mWebView;
    private String mURL;
    private ProgressBar mProgressBar;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

        View view = inflater.inflate(R.layout.fragment_webview, container, false);
        mProgressBar = (ProgressBar) view.findViewById(R.id.article_webview_progress);
        mWebView = (WebView) view.findViewById(R.id.article_webview);
        return view;
    }

    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);

        WebSettings webSettings = mWebView.getSettings();
        webSettings.setJavaScriptEnabled(true);
        webSettings.setSupportZoom(true);
        webSettings.setJavaScriptCanOpenWindowsAutomatically(true);
        webSettings.setBuiltInZoomControls(true);

        if(getArguments()!=null){
            mURL = getArguments().getString("URL");
        }

        if(mURL!=null){
                mWebView.loadUrl(mURL);
        }

        mWebView.setWebViewClient(new WebViewClient(){
            @Override
            public void onPageStarted(WebView view, String url, Bitmap favicon) {
                super.onPageStarted(view, url, favicon);
                showProgressBar();
            }

            @Override
            public void onPageFinished(WebView view, String url) {
                super.onPageFinished(view, url);
                hideProgressBar();
            }
        });

        mWebView.setWebChromeClient(new WebChromeClient(){
            @Override
            public void onProgressChanged(WebView view, int newProgress) {
                super.onProgressChanged(view, newProgress);
                setProgressBar(newProgress);
            }
        });
    }

    private void setProgressBar(int newProgress) {
        mProgressBar.setProgress(newProgress);
    }

    private void hideProgressBar() {
        mProgressBar.setVisibility(View.GONE);
    }

    private void showProgressBar() {
        mProgressBar.setVisibility(View.VISIBLE);
    }

    @Override
    public void onDestroy() {
        mWebView.getSettings().setBuiltInZoomControls(false);
        super.onDestroy();
        mWebView.setVisibility(View.GONE);
        mWebView.destroy();
    }
}




Java Source Code List

in.sahildave.gazetti.StarterApplication.java
in.sahildave.gazetti.bookmarks.BookmarkAdapter.java
in.sahildave.gazetti.bookmarks.BookmarkDetailActivity.java
in.sahildave.gazetti.bookmarks.BookmarkDetailFragment.java
in.sahildave.gazetti.bookmarks.BookmarkListActivity.java
in.sahildave.gazetti.bookmarks.BookmarkListFragment.java
in.sahildave.gazetti.bookmarks.BookmarkLoadingCallback.java
in.sahildave.gazetti.bookmarks.sqlite.BookmarkDataSource.java
in.sahildave.gazetti.bookmarks.sqlite.BookmarkModel.java
in.sahildave.gazetti.bookmarks.sqlite.SQLiteHelper.java
in.sahildave.gazetti.homescreen.HomeScreenActivity.java
in.sahildave.gazetti.homescreen.HomeScreenFragment.java
in.sahildave.gazetti.homescreen.adapter.AddCellDialogFragment.java
in.sahildave.gazetti.homescreen.adapter.CellModel.java
in.sahildave.gazetti.homescreen.adapter.EditCellDialogFragment.java
in.sahildave.gazetti.homescreen.adapter.GridAdapter.java
in.sahildave.gazetti.homescreen.adapter.NewsCatModel.java
in.sahildave.gazetti.homescreen.newcontent.DialogNewContentExpListAdaper.java
in.sahildave.gazetti.homescreen.newcontent.DialogNewContent.java
in.sahildave.gazetti.news_activities.ArticleLoadingCallback.java
in.sahildave.gazetti.news_activities.WebViewFragment.java
in.sahildave.gazetti.news_activities.WebsiteDetailActivity.java
in.sahildave.gazetti.news_activities.WebsiteDetailFragment.java
in.sahildave.gazetti.news_activities.WebsiteListActivity.java
in.sahildave.gazetti.news_activities.WebsiteListFragment.java
in.sahildave.gazetti.news_activities.adapter.NavDrawerListAdapter.java
in.sahildave.gazetti.news_activities.adapter.NewsAdapter.java
in.sahildave.gazetti.news_activities.adapter.RobotoLight.java
in.sahildave.gazetti.news_activities.fetch.firstPost.java
in.sahildave.gazetti.news_activities.fetch.hindu.java
in.sahildave.gazetti.news_activities.fetch.indianExpressBusiness.java
in.sahildave.gazetti.news_activities.fetch.indianExpress.java
in.sahildave.gazetti.news_activities.fetch.toi.java
in.sahildave.gazetti.preference.FeedSelectFragment.java
in.sahildave.gazetti.preference.FeedSelectSettingsActivity.java
in.sahildave.gazetti.preference.LicensesActivity.java
in.sahildave.gazetti.preference.PreferenceExpListAdapter.java
in.sahildave.gazetti.preference.SettingsActivity.java
in.sahildave.gazetti.util.BitmapTransform.java
in.sahildave.gazetti.util.ConfigService.java
in.sahildave.gazetti.util.Constants.java
in.sahildave.gazetti.util.GazettiEnums.java
in.sahildave.gazetti.util.JsonHelper.java
in.sahildave.gazetti.util.NewsCatFileUtil.java
in.sahildave.gazetti.util.ShareButtonListener.java
in.sahildave.gazetti.util.UserPrefUtil.java
in.sahildave.gazetti.welcomescreen.WelcomeScreenExpListAdapter.java
in.sahildave.gazetti.welcomescreen.WelcomeScreenFragmentExpList.java
in.sahildave.gazetti.welcomescreen.WelcomeScreenFragmentFirst.java
in.sahildave.gazetti.welcomescreen.WelcomeScreenViewPagerActivity.java