org.mariotaku.twidere.fragment.LicenseFragment.java Source code

Java tutorial

Introduction

Here is the source code for org.mariotaku.twidere.fragment.LicenseFragment.java

Source

/*
 *              Copyright (C) 2011 The MusicMod Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *            http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.mariotaku.twidere.fragment;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.webkit.WebView;

public class LicenseFragment extends WebViewFragment {

    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        loadUrl("file:///android_asset/gpl-3.0-standalone.html");
        setWebViewClient(new LicenseWebViewClient(getActivity()));

    }

    private class LicenseWebViewClient extends DefaultWebViewClient {

        private FragmentActivity mActivity;

        public LicenseWebViewClient(FragmentActivity activity) {
            super(activity);
            mActivity = activity;
        }

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

        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
            return true;
        }
    }
}