Home | History | Annotate | Download | only in hdrviewfinder
      1 /*
      2  * Copyright (C) 2014 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 package com.example.android.hdrviewfinder;
     18 
     19 import android.app.Dialog;
     20 import android.os.Bundle;
     21 import android.support.annotation.NonNull;
     22 import android.support.v7.app.AlertDialog;
     23 import android.support.v7.app.AppCompatDialogFragment;
     24 
     25 public class MessageDialogFragment extends AppCompatDialogFragment {
     26 
     27     private static final String ARG_MESSAGE_INT = "message_int";
     28     private static final String ARG_MESSAGE_STRING = "message_string";
     29 
     30     public static MessageDialogFragment newInstance(int message) {
     31         MessageDialogFragment fragment = new MessageDialogFragment();
     32         Bundle args = new Bundle();
     33         args.putInt(ARG_MESSAGE_INT, message);
     34         fragment.setArguments(args);
     35         return fragment;
     36     }
     37 
     38     public static MessageDialogFragment newInstance(String message) {
     39         MessageDialogFragment fragment = new MessageDialogFragment();
     40         Bundle args = new Bundle();
     41         args.putString(ARG_MESSAGE_STRING, message);
     42         fragment.setArguments(args);
     43         return fragment;
     44     }
     45 
     46     @NonNull
     47     @Override
     48     public Dialog onCreateDialog(Bundle savedInstanceState) {
     49         AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
     50         builder.setPositiveButton(android.R.string.ok, null);
     51         Bundle args = getArguments();
     52         if (args.containsKey(ARG_MESSAGE_INT)) {
     53             builder.setMessage(args.getInt(ARG_MESSAGE_INT));
     54         } else if (args.containsKey(ARG_MESSAGE_STRING)) {
     55             builder.setMessage(args.getString(ARG_MESSAGE_STRING));
     56         }
     57         return builder.create();
     58     }
     59 
     60 }
     61