1 /* 2 * Copyright (C) 2013 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.example.android.cardemulation; 18 19 import android.os.Bundle; 20 import android.support.v4.app.Fragment; 21 import android.text.Editable; 22 import android.text.TextWatcher; 23 import android.view.LayoutInflater; 24 import android.view.View; 25 import android.view.ViewGroup; 26 import android.widget.EditText; 27 28 /** 29 * Generic UI for sample discovery. 30 */ 31 public class CardEmulationFragment extends Fragment { 32 33 public static final String TAG = "CardEmulationFragment"; 34 35 /** Called when sample is created. Displays generic UI with welcome text. */ 36 @Override 37 public void onCreate(Bundle savedInstanceState) { 38 super.onCreate(savedInstanceState); 39 } 40 41 @Override 42 public View onCreateView(LayoutInflater inflater, ViewGroup container, 43 Bundle savedInstanceState) { 44 // Inflate the layout for this fragment 45 View v = inflater.inflate(R.layout.main_fragment, container, false); 46 EditText account = (EditText) v.findViewById(R.id.card_account_field); 47 account.setText(AccountStorage.GetAccount(getActivity())); 48 account.addTextChangedListener(new AccountUpdater()); 49 return v; 50 } 51 52 53 private class AccountUpdater implements TextWatcher { 54 @Override 55 public void beforeTextChanged(CharSequence s, int start, int count, int after) { 56 // Not implemented. 57 } 58 59 @Override 60 public void onTextChanged(CharSequence s, int start, int before, int count) { 61 // Not implemented. 62 } 63 64 @Override 65 public void afterTextChanged(Editable s) { 66 String account = s.toString(); 67 AccountStorage.SetAccount(getActivity(), account); 68 } 69 } 70 }