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