Java tutorial
/* * Copyright (C) 2015 Victor Apoyan. * * 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 com.armtimes.dialogs; import android.app.AlertDialog; import android.app.Dialog; import android.content.pm.PackageInfo; import android.content.pm.PackageManager; import android.os.Bundle; import android.support.v4.app.DialogFragment; import android.text.method.LinkMovementMethod; import android.view.View; import android.widget.TextView; import com.armtimes.R; public class DialogAboutUs extends DialogFragment { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setRetainInstance(true); } @SuppressWarnings("NullableProblems") @Override public Dialog onCreateDialog(Bundle savedInstanceState) { View dialogView = getActivity().getLayoutInflater().inflate(R.layout.dialog_about_us, null); TextView tvVersion = (TextView) dialogView.findViewById(R.id.tvAboutUsVersion); try { PackageManager manager = getActivity().getPackageManager(); PackageInfo info = manager.getPackageInfo(getActivity().getPackageName(), 0); tvVersion.setText(tvVersion.getText() + " " + info.versionName); } catch (PackageManager.NameNotFoundException e) { tvVersion.setVisibility(View.GONE); } // Makes the link in the text view clickable. TextView t2 = (TextView) dialogView.findViewById(R.id.tvAboutUsDeveloper); t2.setMovementMethod(LinkMovementMethod.getInstance()); // Creates About Us Alert dialog which extends from DialogFragment. return new AlertDialog.Builder(getActivity()).setTitle(R.string.about_us) .setNeutralButton(R.string.about_us_close, null).setView(dialogView).create(); } }