HomeXLarge.java revision 4e5a9e4ee5c1ecab0a7a8eebee883f3f189f5cb4
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.fragments.ContactFragment;
20import com.android.loaderapp.fragments.ContactFragment;
21import com.android.loaderapp.fragments.ContactsListFragment;
22import com.android.ui.phat.PhatTitleBar;
23import com.android.ui.phat.PhatTitleBar.OnActionListener;
24
25import android.app.Activity;
26import android.app.FragmentTransaction;
27import android.content.Intent;
28import android.content.res.Resources;
29import android.net.Uri;
30import android.os.Bundle;
31import android.provider.ContactsContract;
32
33public class HomeXLarge extends Activity implements ContactsListFragment.Controller, OnActionListener {
34    private static final int ACTION_ID_SEARCH = 0;
35    private static final int ACTION_ID_ADD = 1;
36
37    ContactsListFragment mList;
38    ContactFragment mDetails;
39
40    @Override
41    public void onCreate(Bundle savedState) {
42        super.onCreate(savedState);
43
44        setContentView(R.layout.home_xlarge);
45
46        mList = new ContactsListFragment();
47        mList.setController(this);
48        mDetails = new ContactFragment(null, new ContactFragment.DefaultController(this));
49        FragmentTransaction transaction = openFragmentTransaction();
50        transaction.add(mList, R.id.contacts_list);
51        transaction.add(mDetails, R.id.contact_details);
52        transaction.commit();
53
54        final PhatTitleBar titleBar = (PhatTitleBar) findViewById(R.id.title_bar);
55        final Resources resources = getResources();
56
57        titleBar.addAction(ACTION_ID_SEARCH, resources.getDrawable(android.R.drawable.ic_menu_search),
58                "Search", this);
59        titleBar.addAction(ACTION_ID_ADD, resources.getDrawable(android.R.drawable.ic_menu_add),
60                "Add", this);
61
62        Intent intent = getIntent();
63        if (Intent.ACTION_VIEW.equals(intent.getAction())) {
64            mDetails.loadContact(intent.getData());
65        }
66    }
67
68    public void onAction(int id) {
69        switch (id) {
70            case ACTION_ID_SEARCH:
71                startSearch(null, false, null, true);
72                break;
73
74            case ACTION_ID_ADD:
75                startActivity(new Intent(Intent.ACTION_INSERT, ContactsContract.Contacts.CONTENT_URI));
76                break;
77        }
78    }
79
80    public void onContactSelected(Uri contactUri) {
81        // The user clicked on an item in the left side pane, start loading the data for it
82        mDetails.loadContact(contactUri);
83    }
84}
85