1 /*
2  * Copyright (C) 2016 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 package com.android.cts.verifier.sensors.sixdof.Dialogs;
17 
18 import com.android.cts.verifier.R;
19 import com.android.cts.verifier.sensors.sixdof.Utils.ResultObjects.ResultObject;
20 
21 import android.app.Dialog;
22 import android.os.Bundle;
23 import android.app.DialogFragment;
24 import android.app.AlertDialog;
25 import android.view.View;
26 import android.widget.TextView;
27 
28 import java.util.HashMap;
29 
30 /**
31  * Class that sets up the displaying of test results in a dialog.
32  */
33 public abstract class BaseResultsDialog extends DialogFragment {
34     public enum ResultType {
35         WAYPOINT,
36         PATH,
37         TIME,
38         ROTATION,
39         RINGS
40     }
41 
42     protected ResultObject mResult;
43     protected HashMap<ResultType, TextView> mTextViews;
44     protected AlertDialog.Builder mBuilder;
45     protected View mRootView;
46 
setup(ResultObject result)47     protected void setup(ResultObject result) {
48         mResult = result;
49         mTextViews = new HashMap<>();
50     }
51 
52     @Override
onCreateDialog(Bundle savedInstanceState)53     public Dialog onCreateDialog(Bundle savedInstanceState) {
54         // Please override and call super.onCreateDialog after setting up mRootView and mBuilder.
55         String title = getString(R.string.passed);
56         for (ResultType resultType : mResult.getResults().keySet()) {
57             if (mResult.getResults().get(resultType)) {
58                 mTextViews.get(resultType).setText(getString(R.string.passed));
59             } else {
60                 title = getString(R.string.failed);
61                 mTextViews.get(resultType).setText(getString(R.string.failed));
62             }
63         }
64 
65         mBuilder.setView(mRootView);
66 
67         mBuilder.setTitle(title)
68                 .setPositiveButton(R.string.got_it, null);
69 
70         // Create the AlertDialog object and return it.
71         return mBuilder.create();
72     }
73 }
74