HomeNormal.java revision 97c81c1fe35dd80a96e0d3297de31f3e8255893b
1/* 2 * Copyright (C) 2010 Google Inc. 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.loaderapp; 18 19import com.android.loaderapp.ContactsListView.SimpleViewFactory; 20import com.android.loaderapp.model.ContactsListLoader; 21 22import android.app.patterns.CursorLoader; 23import android.app.patterns.Loader; 24import android.app.patterns.LoaderActivity; 25import android.content.Intent; 26import android.database.Cursor; 27import android.net.Uri; 28import android.os.Bundle; 29import android.view.View; 30import android.widget.AdapterView; 31import android.widget.AdapterView.OnItemClickListener; 32 33public class HomeNormal extends LoaderActivity<Cursor> implements OnItemClickListener { 34 static final int LOADER_LIST = 1; 35 36 ContactsListView mList; 37 CursorLoader mLoader; 38 39 @Override 40 public void onCreate(Bundle savedState) { 41 super.onCreate(savedState); 42 43 setContentView(R.layout.normal_home); 44 45 mList = (ContactsListView) findViewById(android.R.id.list); 46 mList.setViewFactory(new SimpleViewFactory(R.layout.normal_list_item)); 47 mList.setOnItemClickListener(this); 48 } 49 50 @Override 51 public void onInitializeLoaders() { 52 startLoading(LOADER_LIST, null); 53 } 54 55 @Override 56 protected Loader onCreateLoader(int id, Bundle args) { 57 switch (id) { 58 case LOADER_LIST: { 59 return ContactsListLoader.newVisibleContactsLoader(this); 60 } 61 } 62 return null; 63 } 64 65 @Override 66 public void onLoadComplete(Loader loader, Cursor data) { 67 switch (loader.getId()) { 68 case LOADER_LIST: 69 mList.setCursor(data); 70 break; 71 } 72 } 73 74 public void onItemClick(AdapterView<?> parent, View view, int position, long id) { 75 // The user clicked on an item in the the list, start an activity to view it 76 Uri contactUri = mList.getContactUri(position); 77 if (contactUri != null) { 78 Intent intent = new Intent(this, DetailsNormal.class); 79 intent.setData(contactUri); 80 startActivity(intent); 81 } 82 } 83} 84