com.kubotaku.android.code4kyoto5374.fragments.OpenSourceLicenseDialog.java Source code

Java tutorial

Introduction

Here is the source code for com.kubotaku.android.code4kyoto5374.fragments.OpenSourceLicenseDialog.java

Source

/**
 * Copyright 2017 kubotaku1119 <kubotaku1119@gmail.com>
 * <p/>
 * 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
 * <p/>
 * http://www.apache.org/licenses/LICENSE-2.0
 * <p/>
 * 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 com.kubotaku.android.code4kyoto5374.fragments;

import android.app.Dialog;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.DialogFragment;
import android.util.DisplayMetrics;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.webkit.WebView;

import com.kubotaku.android.code4kyoto5374.R;

/**
 * 
 */
public class OpenSourceLicenseDialog extends DialogFragment {

    public static final String TAG = OpenSourceLicenseDialog.class.getSimpleName();

    public static OpenSourceLicenseDialog newInstance() {
        OpenSourceLicenseDialog instance = new OpenSourceLicenseDialog();
        Bundle args = new Bundle();
        instance.setArguments(args);
        return instance;
    }

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

        final Dialog dialog = getDialog();
        dialog.setCancelable(true);

        DisplayMetrics metrics = getResources().getDisplayMetrics();
        int dialogWidth = (int) (metrics.widthPixels * 0.95f);

        WindowManager.LayoutParams lp = dialog.getWindow().getAttributes();
        lp.width = dialogWidth;
        dialog.getWindow().setAttributes(lp);

        dialog.setCanceledOnTouchOutside(true);
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
            @Nullable Bundle savedInstanceState) {
        return inflater.inflate(R.layout.fragment_open_source_license_dialog, container, false);
    }

    @Override
    public void onStart() {
        super.onStart();

        setup();
    }

    private void setup() {
        View view = getView();

        final WebView webView = (WebView) view.findViewById(R.id.license_web_view);
        webView.loadUrl("file:///android_asset/open_source_license.html");
    }
}