QuickContactActivity.java revision b4da2cd498c4f7d3db22d69bc41baf0ebdbcb6bc
1/*
2 * Copyright (C) 2009 The Android Open Source Project
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.contacts.quickcontact;
18
19import com.android.contacts.ContactsActivity;
20
21import android.content.ContentUris;
22import android.content.Intent;
23import android.graphics.Rect;
24import android.net.Uri;
25import android.os.Bundle;
26import android.provider.ContactsContract.QuickContact;
27import android.provider.ContactsContract.RawContacts;
28import android.util.Log;
29
30/**
31 * Stub translucent activity that just shows {@link QuickContactWindow} floating
32 * above the caller. This temporary hack should eventually be replaced with
33 * direct framework support.
34 */
35public final class QuickContactActivity extends ContactsActivity
36        implements QuickContactWindow.OnDismissListener {
37    private static final String TAG = "QuickContactActivity";
38
39    static final boolean LOGV = false;
40    static final boolean FORCE_CREATE = true;
41
42    private QuickContactWindow mQuickContact;
43
44    @Override
45    protected void onCreate(Bundle icicle) {
46        super.onCreate(icicle);
47        if (LOGV) Log.d(TAG, "onCreate");
48
49        this.onNewIntent(getIntent());
50    }
51
52    @Override
53    public void onNewIntent(Intent intent) {
54        super.onNewIntent(intent);
55        if (LOGV) Log.d(TAG, "onNewIntent");
56
57        if (QuickContactWindow.TRACE_LAUNCH) {
58            android.os.Debug.startMethodTracing(QuickContactWindow.TRACE_TAG);
59        }
60
61        if (mQuickContact == null || FORCE_CREATE) {
62            if (LOGV) Log.d(TAG, "Preparing window");
63            mQuickContact = new QuickContactWindow(this, this);
64        }
65
66        // Use our local window token for now
67        Uri lookupUri = intent.getData();
68        // Check to see whether it comes from the old version.
69        if (android.provider.Contacts.AUTHORITY.equals(lookupUri.getAuthority())) {
70            final long rawContactId = ContentUris.parseId(lookupUri);
71            lookupUri = RawContacts.getContactLookupUri(getContentResolver(),
72                    ContentUris.withAppendedId(RawContacts.CONTENT_URI, rawContactId));
73        }
74        final Bundle extras = intent.getExtras();
75
76        // Read requested parameters for displaying
77        final Rect target = intent.getSourceBounds();
78        final int mode = extras.getInt(QuickContact.EXTRA_MODE, QuickContact.MODE_MEDIUM);
79        final String[] excludeMimes = extras.getStringArray(QuickContact.EXTRA_EXCLUDE_MIMES);
80
81        mQuickContact.show(lookupUri, target, mode, excludeMimes);
82    }
83
84    /** {@inheritDoc} */
85    @Override
86    public void onBackPressed() {
87        if (LOGV) Log.w(TAG, "Unexpected back captured by stub activity");
88        finish();
89    }
90
91    @Override
92    protected void onPause() {
93        super.onPause();
94        if (LOGV) Log.d(TAG, "onPause");
95
96        // Dismiss any dialog when pausing
97        mQuickContact.dismiss();
98    }
99
100    @Override
101    protected void onDestroy() {
102        super.onDestroy();
103        if (LOGV) Log.d(TAG, "onDestroy");
104    }
105
106    /** {@inheritDoc} */
107    @Override
108    public void onDismiss(QuickContactWindow dialog) {
109        if (LOGV) Log.d(TAG, "onDismiss");
110
111        if (isTaskRoot() && !FORCE_CREATE) {
112            // Instead of stopping, simply push this to the back of the stack.
113            // This is only done when running at the top of the stack;
114            // otherwise, we have been launched by someone else so need to
115            // allow the user to go back to the caller.
116            moveTaskToBack(false);
117        } else {
118            finish();
119        }
120    }
121}
122