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