hu.naturlecso.naturshutd.dialog.AboutDialogFragment.java Source code

Java tutorial

Introduction

Here is the source code for hu.naturlecso.naturshutd.dialog.AboutDialogFragment.java

Source

/*
 * Copyright (C) 2013 Jozsef Szilvasi <jozsef.szilvasi@gmail.com>
 * 
 * This file is part of NaturShutd.
 *
 * NaturShutd is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * NaturShutd is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with NaturShutd.  If not, see <http://www.gnu.org/licenses/>. 
 */

package hu.naturlecso.naturshutd.dialog;

import android.content.Intent;
import android.content.pm.PackageManager.NameNotFoundException;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import hu.naturlecso.naturshutd.R;

public class AboutDialogFragment extends DialogFragment {

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View rootView = inflater.inflate(R.layout.dialog_about, container, false);

        // set title
        String title;
        try {
            title = getString(R.string.app_name) + " " + getActivity().getPackageManager()
                    .getPackageInfo(getActivity().getPackageName(), 0).versionName;
        } catch (NameNotFoundException e) {
            title = "";
        }
        getDialog().setTitle(title);

        // handle button clicks
        rootView.findViewById(R.id.dialog_about_contact).setOnClickListener(v -> {
            Intent intent = new Intent(Intent.ACTION_SEND);
            intent.setType("message/rfc822");
            intent.putExtra(Intent.EXTRA_EMAIL, new String[] { getString(R.string.dialog_about_contact_email) });
            intent.putExtra(Intent.EXTRA_SUBJECT, getString(R.string.dialog_about_contact_subject));
            startActivity(Intent.createChooser(intent, getString(R.string.dialog_about_contact)));
        });

        rootView.findViewById(R.id.dialog_about_license).setOnClickListener(v -> {
            Intent intent = new Intent(Intent.ACTION_VIEW);
            intent.setData(Uri.parse(getString(R.string.dialog_about_license_url)));
            startActivity(intent);
        });

        return rootView;
    }
}