Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
32 changed files
with
380 additions
and
99 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,3 +6,7 @@ | |
.DS_Store | ||
/build | ||
/captures | ||
libs/ | ||
chatmessageview/libs/ | ||
example/libs/ | ||
example/src/main/res/drawable/ |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
100 changes: 94 additions & 6 deletions
100
chatmessageview/src/main/java/jp/bassaer/chatmessageview/ChatView.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,116 @@ | ||
package jp.bassaer.chatmessageview; | ||
|
||
import android.content.Context; | ||
import android.graphics.Bitmap; | ||
import android.graphics.BitmapFactory; | ||
import android.text.Editable; | ||
import android.text.TextWatcher; | ||
import android.util.AttributeSet; | ||
import android.widget.ListView; | ||
import android.view.View; | ||
import android.widget.EditText; | ||
import android.widget.ImageButton; | ||
import android.widget.LinearLayout; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Calendar; | ||
|
||
/** | ||
* Created by nakayama on 2016/08/08. | ||
*/ | ||
public class ChatView extends ListView { | ||
|
||
public class ChatView extends LinearLayout { | ||
private MessageView mMessageView; | ||
private EditText mInputText; | ||
private ImageButton mSendButton; | ||
|
||
public ChatView(Context context) { | ||
super(context); | ||
} | ||
private String mUserName; | ||
private Bitmap mUserIcon; | ||
|
||
|
||
public ChatView(Context context, AttributeSet attrs) { | ||
super(context, attrs); | ||
init(context); | ||
} | ||
|
||
public ChatView(Context context, AttributeSet attrs, int defStyleAttr) { | ||
super(context, attrs, defStyleAttr); | ||
init(context); | ||
} | ||
|
||
private void init(Context context) { | ||
mMessageView = new MessageView(context); | ||
mInputText = (EditText)findViewById(R.id.message_edit_text); | ||
mSendButton = (ImageButton)findViewById(R.id.send_button); | ||
|
||
setUserName(context.getString(R.string.unknown)); | ||
setUserIcon(BitmapFactory.decodeResource(context.getResources(), R.drawable.face_1)); | ||
|
||
mSendButton.setOnClickListener(new OnClickListener() { | ||
@Override | ||
public void onClick(View view) { | ||
Message message = new Message.Builder() | ||
.setRightMessage(true) | ||
.setUserName(getUserName()) | ||
.setUserIcon(getUserIcon()) | ||
.setMessageText(mInputText.getText().toString()) | ||
.setDateCell(false) | ||
.setCreatedAt(Calendar.getInstance()) | ||
.build(); | ||
|
||
send(message); | ||
mInputText.setText(""); | ||
} | ||
}); | ||
|
||
mInputText.addTextChangedListener(new TextWatcher() { | ||
@Override | ||
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) { | ||
|
||
} | ||
|
||
@Override | ||
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) { | ||
|
||
} | ||
|
||
@Override | ||
public void afterTextChanged(Editable editable) { | ||
String input = editable.toString(); | ||
|
||
//Cannot send when input is empty | ||
if (input.length() == 0) { | ||
mSendButton.setEnabled(false); | ||
} else { | ||
mSendButton.setEnabled(true); | ||
} | ||
} | ||
}); | ||
} | ||
|
||
public void send(Message message) { | ||
mMessageView.setMessage(message); | ||
} | ||
|
||
public void receive(Message message) { | ||
mMessageView.setMessage(message); | ||
} | ||
|
||
public void setMessages(ArrayList<Message> list) { | ||
mMessageView.setMessageList(list); | ||
} | ||
|
||
public Bitmap getUserIcon() { | ||
return mUserIcon; | ||
} | ||
|
||
public void setUserIcon(Bitmap userIcon) { | ||
mUserIcon = userIcon; | ||
} | ||
|
||
public String getUserName() { | ||
return mUserName; | ||
} | ||
|
||
public void setUserName(String userName) { | ||
mUserName = userName; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:orientation="vertical" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent"> | ||
|
||
<jp.bassaer.chatmessageview.MessageView | ||
android:id="@+id/message_view" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:layout_weight="1"/> | ||
|
||
<LinearLayout | ||
android:orientation="horizontal" | ||
android:layout_width="match_parent" | ||
android:layout_height="@dimen/icon_normal" | ||
android:background="@color/blueGray50" | ||
> | ||
|
||
<EditText | ||
android:id="@+id/message_edit_text" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:hint="@string/input_hint" | ||
android:layout_weight="1"/> | ||
|
||
<ImageButton | ||
android:id="@+id/send_button" | ||
android:layout_width="@dimen/icon_normal" | ||
android:layout_height="@dimen/icon_normal" | ||
android:src="@drawable/ic_action_send" | ||
android:tint="@color/lightBlue500" | ||
android:background="@android:color/transparent" | ||
/> | ||
|
||
</LinearLayout> | ||
|
||
</LinearLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.