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