Java tutorial
/* * MIT License * * Copyright (c) 2016. Dmytro Karataiev * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. * */ package com.adkdevelopment.movieslist.ui; import android.annotation.SuppressLint; import android.app.Dialog; import android.content.DialogInterface; import android.os.Bundle; import android.support.annotation.NonNull; import android.support.v4.app.DialogFragment; import android.support.v7.app.AlertDialog; import android.view.LayoutInflater; import android.view.View; import android.widget.ImageView; import android.widget.TextView; import com.adkdevelopment.movieslist.R; import com.adkdevelopment.movieslist.data.services.DialogService; import com.adkdevelopment.movieslist.ui.utils.Utilities; import com.squareup.picasso.Picasso; /** * Custom AlertDialog showing time. * Created by karataev on 9/15/16. */ public class TimeDialog extends DialogFragment { private long mCurrentTime = 0L; public static TimeDialog newInstance(long time) { TimeDialog timeDialog = new TimeDialog(); Bundle args = new Bundle(); args.putLong(DialogService.CUR_TIME, time); timeDialog.setArguments(args); return timeDialog; } @NonNull @Override public Dialog onCreateDialog(Bundle savedInstanceState) { if (getArguments() != null) { mCurrentTime = getArguments().getLong(DialogService.CUR_TIME, System.currentTimeMillis()); } AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); // Get the layout inflater LayoutInflater inflater = getActivity().getLayoutInflater(); @SuppressLint("InflateParams") View dialogView = inflater.inflate(R.layout.dialog_time, null); Picasso.with(getContext()).load(getString(R.string.dialog_watchlink)) .into((ImageView) dialogView.findViewById(R.id.dialog_image)); ((TextView) dialogView.findViewById(R.id.dialog_time)) .setText(String.format(getString(R.string.dialog_time), Utilities.getFormattedDate(mCurrentTime))); // Inflate and set the layout for the dialog // Pass null as the parent view because its going in the dialog layout builder.setView(dialogView) // Add action buttons .setPositiveButton(R.string.dialog_ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int id) { } }); return builder.create(); } }