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.android.tv.settings.system;
18 
19 import android.app.Activity;
20 import android.app.FragmentManager;
21 import android.app.FragmentTransaction;
22 import android.content.Intent;
23 import android.content.res.Resources;
24 import android.os.Bundle;
25 import android.text.TextUtils;
26 import android.util.Log;
27 import android.view.View;
28 import android.widget.Toast;
29 
30 import com.android.tv.settings.R;
31 import com.android.tv.settings.connectivity.setup.TextInputWizardFragment;
32 import com.android.tv.settings.util.ThemeHelper;
33 
34 /**
35  * Activity that changes TV input label
36  */
37 public class InputsCustomLabelActivity extends Activity
38         implements TextInputWizardFragment.Listener {
39 
40     private static final String TAG = "InputsCustomLabelActivity";
41     private static final boolean DEBUG = false;
42 
43     public static final String KEY_ID = "id";
44     public static final String KEY_LABEL = "label";
45     public static final int REULST_OK = 0;
46 
47     private String mId;
48 
49     @Override
onCreate(Bundle savedInstanceState)50     protected void onCreate(Bundle savedInstanceState) {
51         super.onCreate(savedInstanceState);
52         setTheme(ThemeHelper.getThemeResource(getIntent()));
53         setContentView(R.layout.setup_auth_activity);
54 
55         findViewById(R.id.progress_bar).setVisibility(View.GONE);
56 
57         Intent intent = getIntent();
58         mId = intent.getStringExtra(KEY_ID);
59         displayTextInputFragment(
60                 intent.getStringExtra(KEY_LABEL));
61     }
62 
63     @Override
onTextInputComplete(String name)64     public boolean onTextInputComplete(String name) {
65         if (TextUtils.isEmpty(name)) {
66             return false;
67         }
68 
69         Intent intent = new Intent();
70         intent.putExtra(KEY_ID, mId);
71         intent.putExtra(KEY_LABEL, name);
72         setResult(RESULT_OK, intent);
73         finish();
74         return true;
75     }
76 
77     /**
78      * Show the fragment that allows the user to give a custom name to their device
79      */
displayTextInputFragment(String customLabel)80     private void displayTextInputFragment(String customLabel) {
81         // Magically TextInputWizardFragment hopes its enclosing activity is an instance of
82         // its listener type, and we are so, onTextInputComplete(String) is automatically
83         // called here
84         TextInputWizardFragment fragment = TextInputWizardFragment.newInstance(
85                 getString(R.string.inputs_custom_title),
86                 null,
87                 TextInputWizardFragment.INPUT_TYPE_NORMAL,
88                 customLabel);
89         getFragmentManager().beginTransaction()
90                 .replace(R.id.content, fragment)
91                 .commit();
92     }
93 }
94