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 package com.android.ex.chips.sample; 17 18 import android.os.Bundle; 19 import android.text.util.Rfc822Tokenizer; 20 import android.widget.MultiAutoCompleteTextView; 21 import android.app.Activity; 22 import android.util.Log; 23 24 import com.android.ex.chips.BaseRecipientAdapter; 25 import com.android.ex.chips.RecipientEditTextView; 26 import com.android.ex.chips.RecipientEditTextView.PermissionsRequestItemClickedListener; 27 import com.android.ex.chips.RecipientEditTextView.RecipientChipAddedListener; 28 import com.android.ex.chips.RecipientEditTextView.RecipientChipDeletedListener; 29 import com.android.ex.chips.RecipientEntry; 30 31 public class MainActivity extends Activity 32 implements PermissionsRequestItemClickedListener, RecipientChipDeletedListener, 33 RecipientChipAddedListener { 34 35 private RecipientEditTextView mEmailRetv; 36 private RecipientEditTextView mPhoneRetv; 37 38 @Override onCreate(final Bundle savedInstanceState)39 protected void onCreate(final Bundle savedInstanceState) { 40 super.onCreate(savedInstanceState); 41 setContentView(R.layout.activity_main); 42 43 mEmailRetv = (RecipientEditTextView) findViewById(R.id.email_retv); 44 mEmailRetv.setTokenizer(new Rfc822Tokenizer()); 45 final BaseRecipientAdapter emailAdapter = new BaseRecipientAdapter(this); 46 emailAdapter.setShowRequestPermissionsItem(true); 47 mEmailRetv.setAdapter(emailAdapter); 48 mEmailRetv.setPermissionsRequestItemClickedListener(this); 49 50 51 mPhoneRetv = (RecipientEditTextView) findViewById(R.id.phone_retv); 52 mPhoneRetv.setTokenizer(new MultiAutoCompleteTextView.CommaTokenizer()); 53 final BaseRecipientAdapter phoneAdapter = 54 new BaseRecipientAdapter(BaseRecipientAdapter.QUERY_TYPE_PHONE, this); 55 phoneAdapter.setShowRequestPermissionsItem(true); 56 mPhoneRetv.setAdapter(phoneAdapter); 57 mPhoneRetv.setPermissionsRequestItemClickedListener(this); 58 mEmailRetv.setRecipientChipAddedListener(this); 59 mEmailRetv.setRecipientChipDeletedListener(this); 60 } 61 62 @Override onPermissionsRequestItemClicked( RecipientEditTextView view, String[] permissions)63 public void onPermissionsRequestItemClicked( 64 RecipientEditTextView view, String[] permissions) { 65 requestPermissions(permissions, 0 /* requestCode */); 66 } 67 68 @Override onPermissionRequestDismissed()69 public void onPermissionRequestDismissed() { 70 mEmailRetv.getAdapter().setShowRequestPermissionsItem(false); 71 mPhoneRetv.getAdapter().setShowRequestPermissionsItem(false); 72 } 73 74 @Override onRecipientChipAdded(RecipientEntry entry)75 public void onRecipientChipAdded(RecipientEntry entry) { 76 Log.i("ChipsSample", entry.getDisplayName() + " recipient chip added"); 77 } 78 79 @Override onRecipientChipDeleted(RecipientEntry entry)80 public void onRecipientChipDeleted(RecipientEntry entry) { 81 Log.i("ChipsSample", entry.getDisplayName() + " recipient chip removed"); 82 } 83 } 84