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.Fragments;
17 
18 import com.android.cts.verifier.R;
19 import com.android.cts.verifier.sensors.sixdof.Activities.TestActivity;
20 
21 import android.os.Bundle;
22 import android.app.Fragment;
23 import android.view.LayoutInflater;
24 import android.view.View;
25 import android.view.ViewGroup;
26 import android.widget.Button;
27 import android.widget.TextView;
28 
29 /**
30  * Provides the instructions for a particular phase before it starts.
31  */
32 public class PhaseStartFragment extends Fragment {
33     // Identifier for setting and retrieving the phase this Fragment was designed for.
34     private static final String ARG_PHASE = "ArgPhase";
35 
36     Button mBtnStart;
37     TextView mTvDesc;
38 
39     TestActivity.CTSTest mPhase;
40     TestActivity mActivity;
41 
newInstance(TestActivity.CTSTest phase)42     public static PhaseStartFragment newInstance(TestActivity.CTSTest phase) {
43         PhaseStartFragment fragment = new PhaseStartFragment();
44         Bundle arguments = new Bundle();
45         arguments.putSerializable(ARG_PHASE, phase);
46         fragment.setArguments(arguments);
47 
48         return fragment;
49     }
50 
51     @Override
onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)52     public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
53         View rootView = inflater.inflate(R.layout.fragment_start_phase, container, false);
54         mBtnStart = (Button) rootView.findViewById(R.id.btnStart);
55         mTvDesc = (TextView) rootView.findViewById(R.id.tvDesc);
56         mActivity = (TestActivity) getActivity();
57 
58         mPhase = (TestActivity.CTSTest) getArguments().getSerializable(ARG_PHASE);
59 
60         switch (mPhase) {
61             case ACCURACY:
62                 mTvDesc.setText(getString(R.string.phase1_description));
63                 getActivity().setTitle(getResources().getStringArray(R.array.phase)[TestActivity.CTSTest.ACCURACY.ordinal()]);
64                 break;
65             case ROBUSTNESS:
66                 mTvDesc.setText(getString(R.string.phase2_description));
67                 getActivity().setTitle(getResources().getStringArray(R.array.phase)[TestActivity.CTSTest.ROBUSTNESS.ordinal()]);
68                 break;
69             case COMPLEX_MOVEMENT:
70                 mTvDesc.setText(getString(R.string.phase3_description));
71                 getActivity().setTitle(getResources().getStringArray(R.array.phase)[TestActivity.CTSTest.COMPLEX_MOVEMENT.ordinal()]);
72                 break;
73             default:
74                 throw new AssertionError("Trying to start a test that doesn't exist");
75         }
76 
77         mBtnStart.setOnClickListener(new View.OnClickListener() {
78             @Override
79             public void onClick(View view) {
80                 mActivity.switchToTestFragment(mPhase);
81             }
82         });
83 
84         return rootView;
85     }
86 }
87