HomeNormal.java revision 2ea5555755ffbfadf2f26b269b2af4def936d92a
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.VisibleContactsLoader;
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 new VisibleContactsLoader(this);
60        }
61        return null;
62    }
63
64    @Override
65    public void onLoadComplete(Loader loader, Cursor data) {
66        switch (loader.getId()) {
67            case LOADER_LIST:
68                mList.setCursor(data);
69                break;
70        }
71    }
72
73    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
74        // The user clicked on an item in the the list, start an activity to view it
75        Uri contactUri = mList.getContactUri(position);
76        if (contactUri != null) {
77            Intent intent = new Intent(this, DetailsNormal.class);
78            intent.setData(contactUri);
79            startActivity(intent);
80        }
81    }
82}
83