Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

chat: use custom title view for status icon

  • Loading branch information...
commit f387d7031fe4c99d028248c8b940af5a69ebeba3 1 parent e45e330
@ge0rg ge0rg authored
View
48 res/layout/chat_action_title.xml
@@ -0,0 +1,48 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2010 The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:orientation="horizontal"
+ android:paddingRight="16dip"
+ android:enabled="false">
+
+ <ImageView android:id="@+id/action_bar_status"
+ android:layout_gravity="center_vertical|left"
+ android:layout_width="wrap_content"
+ android:paddingRight="4dp"
+ android:layout_height="wrap_content" />
+
+ <LinearLayout android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_gravity="center_vertical|left"
+ android:orientation="vertical" >
+
+ <TextView android:id="@+id/action_bar_title"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:singleLine="true"
+ android:ellipsize="end" />
+ <TextView android:id="@+id/action_bar_subtitle"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_marginTop="-3dp"
+ android:layout_marginBottom="5dip"
+ android:singleLine="true"
+ android:ellipsize="end"
+ android:visibility="gone" />
+ </LinearLayout>
+</LinearLayout>
View
22 src/org/yaxim/androidclient/chat/ChatWindow.java
@@ -70,6 +70,9 @@
R.id.chat_from, R.id.chat_message };
private ContentObserver mContactObserver = new ContactObserver();
+ private ImageView mStatusMode;
+ private TextView mTitle;
+ private TextView mSubTitle;
private Button mSendButton = null;
private EditText mChatInput = null;
private String mWithJabberID = null;
@@ -116,11 +119,24 @@ public void onCreate(Bundle savedInstanceState) {
titleUserid = mWithJabberID;
}
- setTitle(titleUserid);
+ setCustomTitle(titleUserid);
setChatWindowAdapter();
}
+ private void setCustomTitle(String title) {
+ LayoutInflater inflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
+ View layout = inflater.inflate(R.layout.chat_action_title, null);
+ mStatusMode = (ImageView)layout.findViewById(R.id.action_bar_status);
+ mTitle = (TextView)layout.findViewById(R.id.action_bar_title);
+ mSubTitle = (TextView)layout.findViewById(R.id.action_bar_subtitle);
+ mTitle.setText(title);
+
+ setTitle(null);
+ getSupportActionBar().setCustomView(layout);
+ getSupportActionBar().setDisplayShowCustomEnabled(true);
+ }
+
private void setChatWindowAdapter() {
String selection = ChatConstants.JID + "='" + mWithJabberID + "'";
Cursor cursor = managedQuery(ChatProvider.CONTENT_URI, PROJECTION_FROM,
@@ -488,6 +504,10 @@ private void updateContactStatus() {
int status_mode = cursor.getInt(MODE_IDX);
String status_message = cursor.getString(MSG_IDX);
Log.d(TAG, "contact status changed: " + status_mode + " " + status_message);
+ mSubTitle.setVisibility((status_message != null && status_message.length() != 0)?
+ View.VISIBLE : View.GONE);
+ mSubTitle.setText(status_message);
+ mStatusMode.setImageResource(StatusMode.values()[status_mode].getDrawableId());
}
cursor.close();
}
Please sign in to comment.
Something went wrong with that request. Please try again.