Skip to content
This repository has been archived by the owner on Mar 3, 2023. It is now read-only.

Commit

Permalink
improved the layout of chat screen
Browse files Browse the repository at this point in the history
  • Loading branch information
smukov committed Jun 26, 2016
1 parent 9634283 commit 76da927
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,44 +84,44 @@ public void add(List<ChatMessage> messages) {

private void setAlignment(ViewHolder holder, boolean isMe) {
if (!isMe) {
holder.contentWithBG.setBackgroundResource(R.drawable.in_message_bg);
holder.contentWithBG.setBackgroundResource(R.drawable.out_message_bg);

LinearLayout.LayoutParams layoutParams =
(LinearLayout.LayoutParams) holder.contentWithBG.getLayoutParams();
layoutParams.gravity = Gravity.RIGHT;
layoutParams.gravity = Gravity.LEFT;
holder.contentWithBG.setLayoutParams(layoutParams);

RelativeLayout.LayoutParams lp =
(RelativeLayout.LayoutParams) holder.content.getLayoutParams();
lp.addRule(RelativeLayout.ALIGN_PARENT_LEFT, 0);
lp.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
lp.addRule(RelativeLayout.ALIGN_PARENT_RIGHT, 0);
lp.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
holder.content.setLayoutParams(lp);
layoutParams = (LinearLayout.LayoutParams) holder.txtMessage.getLayoutParams();
layoutParams.gravity = Gravity.RIGHT;
layoutParams.gravity = Gravity.LEFT;
holder.txtMessage.setLayoutParams(layoutParams);

layoutParams = (LinearLayout.LayoutParams) holder.txtInfo.getLayoutParams();
layoutParams.gravity = Gravity.RIGHT;
layoutParams.gravity = Gravity.LEFT;
holder.txtInfo.setLayoutParams(layoutParams);
} else {
holder.contentWithBG.setBackgroundResource(R.drawable.out_message_bg);
holder.contentWithBG.setBackgroundResource(R.drawable.in_message_bg);

LinearLayout.LayoutParams layoutParams =
(LinearLayout.LayoutParams) holder.contentWithBG.getLayoutParams();
layoutParams.gravity = Gravity.LEFT;
layoutParams.gravity = Gravity.RIGHT;
holder.contentWithBG.setLayoutParams(layoutParams);

RelativeLayout.LayoutParams lp =
(RelativeLayout.LayoutParams) holder.content.getLayoutParams();
lp.addRule(RelativeLayout.ALIGN_PARENT_RIGHT, 0);
lp.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
lp.addRule(RelativeLayout.ALIGN_PARENT_LEFT, 0);
lp.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
holder.content.setLayoutParams(lp);
layoutParams = (LinearLayout.LayoutParams) holder.txtMessage.getLayoutParams();
layoutParams.gravity = Gravity.LEFT;
layoutParams.gravity = Gravity.RIGHT;
holder.txtMessage.setLayoutParams(layoutParams);

layoutParams = (LinearLayout.LayoutParams) holder.txtInfo.getLayoutParams();
layoutParams.gravity = Gravity.LEFT;
layoutParams.gravity = Gravity.RIGHT;
holder.txtInfo.setLayoutParams(layoutParams);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
package com.thesis.smukov.anative;

import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.support.v7.app.AppCompatActivity;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.thesis.smukov.anative.Chat.ChatAdapter;
import com.thesis.smukov.anative.Chat.ChatMessage;
Expand All @@ -17,11 +16,11 @@
import java.util.ArrayList;
import java.util.Date;

public class ChatActivity extends ActionBarActivity {
public class ChatActivity extends AppCompatActivity {

private EditText messageET;
private ListView messagesContainer;
private Button sendBtn;
private ImageButton sendBtn;
private ChatAdapter adapter;
private ArrayList<ChatMessage> chatHistory;

Expand All @@ -35,12 +34,9 @@ protected void onCreate(Bundle savedInstanceState) {
private void initControls() {
messagesContainer = (ListView) findViewById(R.id.messagesContainer);
messageET = (EditText) findViewById(R.id.messageEdit);
sendBtn = (Button) findViewById(R.id.chatSendButton);
sendBtn = (ImageButton) findViewById(R.id.chatSendButton);

TextView meLabel = (TextView) findViewById(R.id.meLbl);
TextView companionLabel = (TextView) findViewById(R.id.friendLabel);
RelativeLayout container = (RelativeLayout) findViewById(R.id.container);
companionLabel.setText("My Buddy");// Hard Coded
loadDummyHistory();

sendBtn.setOnClickListener(new View.OnClickListener() {
Expand Down
56 changes: 22 additions & 34 deletions Android/app/src/main/res/layout/activity_chat.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,30 @@
android:orientation="vertical"
android:padding="20dp">

<EditText
android:id="@+id/messageEdit"
<LinearLayout
android:id="@+id/chatControls"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_toLeftOf="@+id/chatSendButton"
android:inputType="text"
android:hint="type message" />
android:layout_alignParentBottom="true">

<Button
android:id="@+id/chatSendButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:background="@color/background_floating_material_dark"
android:text="Send MSG"
android:textColor="@color/background_material_light"/>
<EditText
android:id="@+id/messageEdit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="textMultiLine"
android:hint="@string/typeMessage"
android:layout_weight="0.8"/>

<ImageButton
android:id="@+id/chatSendButton"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:src="@drawable/ic_menu_send"
android:background="@android:color/transparent"
android:layout_weight="0.2"/>

</LinearLayout>

<ListView
android:id="@+id/messagesContainer"
Expand All @@ -37,29 +43,11 @@
android:layout_alignParentLeft="false"
android:layout_alignParentTop="false"
android:layout_marginBottom="20dp"
android:layout_above="@+id/messageEdit"
android:layout_below="@+id/meLbl"
android:layout_above="@+id/chatControls"
android:layout_marginTop="10dp"
android:listSelector="@android:color/transparent"
android:transcriptMode="alwaysScroll"
android:divider="@null" />

<TextView
android:id="@+id/meLbl"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left|center_vertical"
android:text="MySelf"
android:singleLine="false"
android:textSize="20dp" />

<TextView
android:id="@+id/friendLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:text="Friend"
android:textSize="20dp" />

</RelativeLayout>
</LinearLayout>
5 changes: 5 additions & 0 deletions Android/app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,15 @@
<string name="sign_in_linkedin">LinkedIn</string>
<string name="welcome">Welcome to Native</string>
<string name="sign_in_with">Sign In With:</string>

<!-- My Profile and Contact screen -->
<string name="hint_faculty">Attended Hopkins University 1979-1984</string>
<string name="hint_employment">Head of Diagnostic @ PPT Hospital</string>
<string name="hint_interests">Chemistry, Piano , Guitar, Android, Economy, Football...</string>
<string name="hint_knowledgeable">Classical Music, Fitness, Movie Trivia, HTML5, Android, JavaScript...</string>
<string name="hint_goals">Learn Ionic2, Find a team for basketball...</string>
<string name="title_activity_chat">ChatActivity</string>

<!-- Chat Activity -->
<string name="typeMessage">Type to compose</string>
</resources>

0 comments on commit 76da927

Please sign in to comment.