[Xposed General] arnabJ:
Hello,

I am trying to add the sender's and receiver's contact image in WhatsApp conversation activity.

The layout of this activity is divided into several layout xmls.

The sender's image is present in a layout named "conversation_actionbar.xml"

It's content :

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout android:id="@id/custom_view" android:clipChildren="false" android:layout_width="fill_parent" android:layout_height="?actionBarSize"
xmlns:android="http://schemas.android.com/apk/res/android">
<LinearLayout android:enabled="false" android:orientation="horizontal" android:id="@id/back" android:padding="@dimen/abc_action_bar_default_padding_material" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_centerVertical="true" android:contentDescription="@string/abc_action_bar_up_description" style="@style/ActionBarButtonStyle">
<ImageView android:layout_gravity="left|center" android:id="@id/up" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="?homeAsUpIndicator" android:scaleType="center" />
<FrameLayout android:layout_gravity="left|center" android:id="@id/conversation_contact_photo_frame" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginRight="0.0dip">
[COLOR="Red"]<ImageView android:id="@id/conversation_contact_photo" android:layout_width="35.0dip" android:layout_height="35.0dip" android:scaleType="fitCenter" />[/COLOR]
<View android:id="@id/transition_start" android:layout_width="35.0dip" android:layout_height="35.0dip" />
<ProgressBar android:layout_gravity="center" android:id="@id/change_photo_progress" android:visibility="gone" android:layout_width="35.0dip" android:layout_height="35.0dip" style="?android:attr/progressBarStyleSmallInverse" />
</FrameLayout>
</LinearLayout>
<LinearLayout android:orientation="vertical" android:id="@id/conversation_contact" android:paddingLeft="4.0dip" android:paddingTop="0.0dip" android:paddingRight="0.0dip" android:paddingBottom="2.0dip" android:clickable="true" android:clipChildren="false" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_toRightOf="@id/back" android:layout_centerVertical="true" style="@style/ActionBarButtonStyle">
<com.whatsapp.TextEmojiLabel android:ellipsize="end" android:gravity="left" android:layout_gravity="left" android:id="@id/conversation_contact_name" android:layout_width="wrap_content" android:layout_height="wrap_content" android:lines="1" android:scrollHorizontally="true" android:singleLine="true" style="@style/Theme.ActionBar.TitleTextStyle.Condensed" />
<LinearLayout android:layout_gravity="left" android:orientation="horizontal" android:id="@id/conversation_contact_status_holder" android:clipChildren="false" android:clipToPadding="false" android:layout_width="fill_parent" android:layout_height="wrap_content">
<TextView android:layout_gravity="left" android:id="@id/conversation_contact_status_prefix" android:paddingRight="3.5sp" android:visibility="gone" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/conversation_last_seen" android:lines="1" android:singleLine="true" style="@style/Theme.ActionBar.SubtitleTextStyle" />
<TextView android:ellipsize="end" android:layout_gravity="left" android:id="@id/conversation_contact_status" android:layout_width="wrap_content" android:layout_height="wrap_content" android:lines="1" android:singleLine="true" style="@style/Theme.ActionBar.SubtitleTextStyle" />
<View android:layout_width="0.0dip" android:layout_height="1.0dip" android:layout_weight="1.0" />
</LinearLayout>
</LinearLayout>
</RelativeLayout>

The message incoming bubble is in another layout named "conversation_row_text_right.xml"

It's content:

<?xml version="1.0" encoding="utf-8"?>
<merge
xmlns:android="http://schemas.android.com/apk/res/android">
<com.whatsapp.DividerView android:id="@id/date_divider" style="@style/DateDivider" />
<LinearLayout android:gravity="right|center" android:orientation="horizontal" android:id="@id/text_layout" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="40.0dip" android:minHeight="30.0dip" android:layout_below="@id/date_divider" android:layout_alignParentRight="true">
<LinearLayout android:orientation="horizontal" android:id="@id/text_content_layout" android:paddingRight="2.0dip" android:paddingBottom="2.0dip" android:layout_width="wrap_content" android:layout_height="wrap_content">
<RelativeLayout android:paddingLeft="4.0dip" android:paddingTop="2.0dip" android:paddingBottom="1.0dip" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1.0">
<ImageView android:id="@id/message_image" android:paddingRight="4.0dip" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="2.0dip" android:scaleType="fitCenter" />
<com.whatsapp.TextEmojiLabel android:textSize="@dimen/conversation_text_row_tv" android:textColor="#ff000000" android:gravity="center_vertical" android:id="@id/message_text" android:paddingLeft="4.0dip" android:paddingRight="4.0dip" android:paddingBottom="2.0dip" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_toRightOf="@id/message_image" />
</RelativeLayout>
<LinearLayout android:layout_gravity="bottom|right|center" android:orientation="horizontal" android:id="@id/date_wrapper" android:paddingBottom="1.0dip" android:layout_width="wrap_content" android:layout_height="wrap_content">
<TextView android:gravity="right" android:layout_gravity="bottom|right|center" android:id="@id/date" android:paddingLeft="4.0dip" android:layout_width="wrap_content" android:layout_height="wrap_content" style="@style/ConversationDate" />
<ImageView android:layout_gravity="bottom|right|center" android:id="@id/status" android:paddingLeft="4.0dip" android:paddingRight="5.0dip" android:paddingBottom="3.0dip" android:layout_width="wrap_content" android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
</merge>

I have successfully added a blank image view to the layout using xposed where the contact image will be shown.

My issue arises here that now can I get access to

<ImageView android:id="@id/conversation_contact_photo" android:layout_width="35.0dip" android:layout_height="35.0dip" android:scaleType="fitCenter" />

present in "conversation_actionbar.xml" in here :

resparam.res.hookLayout("com.whatsapp", "layout", "conversation_row_text_right", new XC_LayoutInflated() {
@Override
public void handleLayoutInflated(XC_LayoutInflated.LayoutInflatedParam liparam) throws Throwable {
LinearLayout textContentLayout = (LinearLayout) liparam.view.findViewById(liparam.res.getIdentifier("text_content_layout", "id", "com.whatsapp"));
[COLOR="blue"]// The Below Line seems to not work.[/COLOR]
[COLOR="red"]ImageView contactAvatar = (ImageView) liparam.view.findViewById(liparam.res.getIdentifier("conversation_contact_photo", "id", "com.whatsapp"));[/COLOR]
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(50, 50);
ImageView mAvatar = new ImageView(textContentLayout.getContext());
mAvatar.setId(R.id.conversation_text_contact_photo);
[COLOR="Blue"]//The below line has NullPointerException.[/COLOR]
mAvatar.setImageDrawable(contactAvatar.getDrawable());
mAvatar.setLayoutParams(params);
textContentLayout.addView(mAvatar, 2);
}
});