1 /* 2 * Copyright (C) 2007-2008 Esmertec AG. 3 * Copyright (C) 2007-2008 The Android Open Source Project 4 * 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 18 package com.android.im.app; 19 20 import android.app.Activity; 21 import android.content.ContentResolver; 22 import android.content.Intent; 23 import android.content.res.Resources; 24 import android.database.Cursor; 25 import android.graphics.drawable.Drawable; 26 import android.net.Uri; 27 import android.os.Bundle; 28 import android.text.SpannableString; 29 import android.text.TextUtils; 30 import android.text.style.ImageSpan; 31 import android.util.Log; 32 import android.view.View; 33 import android.widget.ImageView; 34 import android.widget.TextView; 35 36 import com.android.im.R; 37 import com.android.im.plugin.BrandingResourceIDs; 38 import com.android.im.provider.Imps; 39 40 public class ContactPresenceActivity extends Activity { 41 42 @Override 43 public void onCreate(Bundle icicle) { 44 super.onCreate(icicle); 45 46 setTheme(android.R.style.Theme_Dialog); 47 setContentView(R.layout.contact_presence_activity); 48 49 ImageView imgAvatar = (ImageView) findViewById(R.id.imgAvatar); 50 TextView labelName = (TextView) findViewById(R.id.labelName); 51 TextView txtName = (TextView) findViewById(R.id.txtName); 52 TextView txtStatus = (TextView) findViewById(R.id.txtStatus); 53 TextView txtClientType = (TextView) findViewById(R.id.txtClientType); 54 TextView txtCustomStatus = (TextView) findViewById(R.id.txtStatusText); 55 56 Intent i = getIntent(); 57 Uri uri = i.getData(); 58 if(uri == null) { 59 warning("No data to show"); 60 finish(); 61 return; 62 } 63 64 ContentResolver cr = getContentResolver(); 65 Cursor c = cr.query(uri, null, null, null, null); 66 if(c == null) { 67 warning("Database error when query " + uri); 68 finish(); 69 return; 70 } 71 72 if(c.moveToFirst()) { 73 long providerId = c.getLong(c.getColumnIndexOrThrow(Imps.Contacts.PROVIDER)); 74 String username = c.getString(c.getColumnIndexOrThrow(Imps.Contacts.USERNAME)); 75 String nickname = c.getString(c.getColumnIndexOrThrow(Imps.Contacts.NICKNAME)); 76 int status = c.getInt(c.getColumnIndexOrThrow(Imps.Contacts.PRESENCE_STATUS)); 77 int clientType = c.getInt(c.getColumnIndexOrThrow(Imps.Contacts.CLIENT_TYPE)); 78 String customStatus = c.getString(c.getColumnIndexOrThrow(Imps.Contacts.PRESENCE_CUSTOM_STATUS)); 79 80 ImApp app = ImApp.getApplication(this); 81 BrandingResources brandingRes = app.getBrandingResource(providerId); 82 setTitle(brandingRes.getString(BrandingResourceIDs.STRING_CONTACT_INFO_TITLE)); 83 84 Drawable avatar = DatabaseUtils.getAvatarFromCursor(c, 85 c.getColumnIndexOrThrow(Imps.Contacts.AVATAR_DATA)); 86 if (avatar != null) { 87 imgAvatar.setImageDrawable(avatar); 88 } else { 89 imgAvatar.setImageResource(R.drawable.avatar_unknown); 90 } 91 92 labelName.setText(brandingRes.getString( 93 BrandingResourceIDs.STRING_LABEL_USERNAME)); 94 txtName.setText(ImpsAddressUtils.getDisplayableAddress(username)); 95 96 String statusString = brandingRes.getString( 97 PresenceUtils.getStatusStringRes(status)); 98 SpannableString s = new SpannableString("+ " + statusString); 99 Drawable statusIcon = brandingRes.getDrawable( 100 PresenceUtils.getStatusIconId(status)); 101 statusIcon.setBounds(0, 0, statusIcon.getIntrinsicWidth(), 102 statusIcon.getIntrinsicHeight()); 103 s.setSpan(new ImageSpan(statusIcon), 0, 1, 104 SpannableString.SPAN_EXCLUSIVE_EXCLUSIVE); 105 txtStatus.setText(s); 106 107 txtClientType.setText(getClientTypeString(clientType)); 108 109 if (!TextUtils.isEmpty(customStatus)) { 110 txtCustomStatus.setVisibility(View.VISIBLE); 111 txtCustomStatus.setText("\"" + customStatus + "\""); 112 } else { 113 txtCustomStatus.setVisibility(View.GONE); 114 } 115 } 116 c.close(); 117 } 118 119 private String getClientTypeString(int clientType) { 120 Resources res = getResources(); 121 switch (clientType) { 122 case Imps.Contacts.CLIENT_TYPE_MOBILE: 123 return res.getString(R.string.client_type_mobile); 124 125 default: 126 return res.getString(R.string.client_type_computer); 127 } 128 } 129 130 private static void warning(String msg) { 131 Log.w(ImApp.LOG_TAG, "<ContactPresenceActivity> " + msg); 132 } 133 } 134