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 
17 package com.android.cts.verifier.managedprovisioning;
18 
19 import android.content.Intent;
20 import android.graphics.Color;
21 import android.os.Bundle;
22 import android.view.View;
23 import android.widget.EditText;
24 import android.widget.Toast;
25 
26 import com.android.cts.verifier.PassFailButtons;
27 import com.android.cts.verifier.R;
28 
29 /**
30  * Test class to verify Organization Info.
31  */
32 public class OrganizationInfoTestActivity extends PassFailButtons.Activity
33         implements View.OnClickListener {
34 
35     public static final String EXTRA_ORGANIZATION_NAME = "extra_organization_name";
36     public static final String EXTRA_ORGANIZATION_COLOR = "extra_organization_color";
37 
38     private int mOrganizationColor;
39 
40     @Override
onCreate(Bundle savedInstanceState)41     protected void onCreate(Bundle savedInstanceState) {
42         super.onCreate(savedInstanceState);
43         setContentView(R.layout.organization_info);
44         setPassFailButtonClickListeners();
45         setButtonClickListeners();
46     }
47 
setButtonClickListeners()48     private void setButtonClickListeners() {
49         findViewById(R.id.organization_info_set_button).setOnClickListener(this);
50         findViewById(R.id.go_button).setOnClickListener(this);
51     }
52 
53     @Override
onClick(View view)54     public void onClick(View view) {
55         if (view.getId() == R.id.organization_info_set_button) {
56             EditText organizationNameEditText = (EditText) findViewById(
57                     R.id.organization_name_edit_text);
58             Intent intent = new Intent(ByodHelperActivity.ACTION_SET_ORGANIZATION_INFO);
59             intent.putExtra(EXTRA_ORGANIZATION_NAME, organizationNameEditText.getText().toString());
60             if (isOrganizationColorSet()) {
61                 intent.putExtra(EXTRA_ORGANIZATION_COLOR, mOrganizationColor);
62             }
63             startActivity(intent);
64         } else if (view.getId() == R.id.go_button) {
65             Intent intent = new Intent(ByodHelperActivity.ACTION_LAUNCH_CONFIRM_WORK_CREDENTIALS);
66             startActivity(intent);
67         }
68     }
69 
isOrganizationColorSet()70     private boolean isOrganizationColorSet() {
71         EditText organizationColorEditText = (EditText) findViewById(
72                 R.id.organization_color_edit_text);
73         try {
74             mOrganizationColor = Color.parseColor(organizationColorEditText.getText().toString());
75         } catch (Exception e) {
76             Toast.makeText(this, "Not a valid Color value", Toast.LENGTH_SHORT).show();
77             return false;
78         }
79         return true;
80     }
81 }
82