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