DetailsNormal.java revision b48e53f3178264a47c145f9205e3b804d35ebdce
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.ContactLoader;
20import com.android.loaderapp.model.ContactLoader.ContactData;
21
22import android.app.patterns.Loader;
23import android.app.patterns.LoaderActivity;
24import android.net.Uri;
25import android.os.Bundle;
26
27public class DetailsNormal extends LoaderActivity<ContactData> {
28    static final String ARG_URI = "uri";
29    static final int LOADER_DETAILS = 1;
30
31    ContactCoupler mCoupler;
32    Uri mUri;
33
34    @Override
35    public void onCreate(Bundle savedState) {
36        super.onCreate(savedState);
37
38        setContentView(R.layout.contact_details);
39        mCoupler = new ContactCoupler(this, findViewById(R.id.contact_details));
40        mCoupler.setController(new ContactCoupler.DefaultController(this));
41
42        mUri = getIntent().getData();
43    }
44
45    @Override
46    public void onInitializeLoaders() {
47        Bundle args = new Bundle();
48        args.putParcelable(ARG_URI, getIntent().getData());
49        startLoading(LOADER_DETAILS, args);
50    }
51
52    @Override
53    protected Loader onCreateLoader(int id, Bundle args) {
54        switch (id) {
55            case LOADER_DETAILS: {
56                Uri uri = args.getParcelable(ARG_URI);
57                return new ContactLoader(this, uri);
58            }
59        }
60        return null;
61    }
62
63    @Override
64    public void onLoadFinished(Loader loader, ContactData data) {
65        switch (loader.getId()) {
66            case LOADER_DETAILS: {
67                mCoupler.setData(data);
68                break;
69            }
70        }
71    }
72}
73