diff --git a/app/build.gradle b/app/build.gradle
index 2d8ca32..bdcacad 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -20,8 +20,9 @@ android {
}
dependencies {
+ compile project(':keyboard')
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:25.3.1'
- compile project(':keyboard')
+ compile 'com.android.support:recyclerview-v7:25.3.1'
}
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 91d57fa..8eb6508 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -17,6 +17,8 @@
+
+
diff --git a/app/src/main/java/cn/hadcn/keyboard_example/ListviewActivity.java b/app/src/main/java/cn/hadcn/keyboard_example/ListviewActivity.java
new file mode 100644
index 0000000..476d8cb
--- /dev/null
+++ b/app/src/main/java/cn/hadcn/keyboard_example/ListviewActivity.java
@@ -0,0 +1,210 @@
+package cn.hadcn.keyboard_example;
+
+import android.Manifest;
+import android.os.Bundle;
+import android.support.v4.app.ActivityCompat;
+import android.support.v7.app.AppCompatActivity;
+import android.support.v7.widget.Toolbar;
+import android.view.Menu;
+import android.view.MenuItem;
+import android.view.MotionEvent;
+import android.view.View;
+import android.widget.ListView;
+import android.widget.Toast;
+
+import java.util.ArrayList;
+
+import cn.hadcn.keyboard.ChatKeyboardLayout;
+import cn.hadcn.keyboard.RecordingLayout;
+import cn.hadcn.keyboard.media.MediaBean;
+
+public class ListviewActivity extends AppCompatActivity implements View.OnClickListener, MediaBean
+ .MediaListener, ChatKeyboardLayout.OnChatKeyBoardListener {
+ private static final int PERMISSION_REQUEST_CODE = 0;
+ private ChatKeyboardLayout keyboardLayout = null;
+ private SimpleChatAdapter mAdapter;
+ private RecordingLayout rlRecordArea;
+ private String mVoicePath;
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_listview);
+
+ setSupportActionBar((Toolbar) findViewById(R.id.toolbar));
+
+ keyboardLayout = (ChatKeyboardLayout) findViewById(R.id.kv_bar);
+
+ ArrayList popupModels = new ArrayList<>();
+ popupModels.add(new MediaBean(0, R.drawable.icon_camera, "拍照", this));
+ popupModels.add(new MediaBean(1, R.drawable.icon_photo, "照片", this));
+ popupModels.add(new MediaBean(2, R.drawable.icon_camera, "拍照", this));
+ popupModels.add(new MediaBean(3, R.drawable.icon_photo, "照片", this));
+ popupModels.add(new MediaBean(4, R.drawable.icon_camera, "拍照", this));
+ popupModels.add(new MediaBean(5, R.drawable.icon_photo, "照片", this));
+ popupModels.add(new MediaBean(6, R.drawable.icon_camera, "拍照", this));
+ popupModels.add(new MediaBean(7, R.drawable.icon_photo, "照片", this));
+ popupModels.add(new MediaBean(8, R.drawable.icon_camera, "拍照", this));
+ popupModels.add(new MediaBean(9, R.drawable.pic_select_n, "照片", this));
+ keyboardLayout.initMediaContents(popupModels);
+
+ ListView listView = (ListView) findViewById(R.id.list_view);
+ mAdapter = new SimpleChatAdapter(this);
+ listView.setOnTouchListener(new View.OnTouchListener() {
+ @Override
+ public boolean onTouch(View view, MotionEvent motionEvent) {
+ keyboardLayout.hideKeyboard();
+ return false;
+ }
+ });
+ listView.setAdapter(mAdapter);
+
+ rlRecordArea = (RecordingLayout) findViewById(R.id.recording_area);
+
+ keyboardLayout.setOnChatKeyBoardListener(this);
+
+ findViewById(R.id.keyboard_show_hide).setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(final View v) {
+ hideShow(v);
+ }
+ });
+ findViewById(R.id.keyboard_pop_back).setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(final View v) {
+ popBack(v);
+ }
+ });
+ }
+
+ @Override
+ public boolean onCreateOptionsMenu(Menu menu) {
+ // Inflate the menu; this adds items to the action bar if it is present.
+ getMenuInflater().inflate(R.menu.menu_main, menu);
+ return true;
+ }
+
+ @Override
+ public boolean onOptionsItemSelected(MenuItem item) {
+ // Handle action bar item clicks here. The action bar will
+ // automatically handle clicks on the Home/Up button, so long
+ // as you specify a parent activity in AndroidManifest.xml.
+ int id = item.getItemId();
+
+ //noinspection SimplifiableIfStatement
+ switch (id) {
+ case R.id.action_text_only:
+ keyboardLayout.setKeyboardStyle(ChatKeyboardLayout.Style.TEXT_ONLY);
+ return true;
+ case R.id.action_text_emoticon:
+ keyboardLayout.setKeyboardStyle(ChatKeyboardLayout.Style.TEXT_EMOTICON);
+ return true;
+ case R.id.action_chat_style:
+ keyboardLayout.setKeyboardStyle(ChatKeyboardLayout.Style.CHAT_STYLE);
+ keyboardLayout.setShowRightIcon(true);
+ return true;
+ default:
+ return super.onOptionsItemSelected(item);
+ }
+ }
+
+ public void hideShow(View view) {
+ if (keyboardLayout.isLayoutVisible()) {
+ keyboardLayout.hideLayout();
+ } else {
+ keyboardLayout.showLayout();
+ }
+ }
+
+ public void popBack(View view) {
+ if (keyboardLayout.isKeyboardPopped()) {
+ keyboardLayout.hideKeyboard();
+ } else {
+ keyboardLayout.popKeyboard();
+ }
+ }
+
+ @Override
+ public void onClick(View view) {
+
+ }
+
+ @Override
+ public void onMediaClick(int id) {
+
+ }
+
+ @Override
+ public void onSendButtonClicked(String msg) {
+ mAdapter.addItem(new ChatBean(null, msg));
+ keyboardLayout.clearInputContent();
+ }
+
+ @Override
+ public void onInputTextChanged(final String text) {
+
+ }
+
+ @Override
+ public void onRecordingAction(ChatKeyboardLayout.RecordingAction action) {
+ switch (action) {
+ case START:
+ mVoicePath = AudioLib.getInstance().generatePath(this);
+ AudioLib.getInstance().start(mVoicePath, new AudioListener());
+ rlRecordArea.show(1);
+ break;
+ case RESTORE:
+ rlRecordArea.show(1);
+ break;
+ case READY_CANCEL:
+ rlRecordArea.show(0);
+ break;
+ case CANCELED:
+ AudioLib.getInstance().cancel();
+ rlRecordArea.hide();
+ break;
+ case COMPLETE:
+ if (AudioLib.getInstance().complete() < 0) {
+ Toast.makeText(this, "time is too short", Toast.LENGTH_SHORT).show();
+ }
+ rlRecordArea.hide();
+ break;
+ case PERMISSION_NOT_GRANTED:
+ ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.RECORD_AUDIO}, PERMISSION_REQUEST_CODE);
+ break;
+ }
+ }
+
+ private class AudioListener implements AudioLib.OnAudioListener {
+ @Override
+ public void onDbChange(double db) {
+ int level = 0;
+ LogUtil.e("", "onDbChange db = " + db);
+ if (db > 40) {
+ level = ((int) db - 40) / 7;
+ }
+ LogUtil.e("", "onDbChange level = " + level);
+ rlRecordArea.setVoiceLevel(level);
+ }
+ }
+
+ @Override
+ public void onUserDefEmoticonClicked(String tag, String uri) {
+ mAdapter.addItem(new ChatBean(tag, null));
+ }
+
+ @Override
+ public void onKeyboardHeightChanged(final int height) {
+ LogUtil.e("", "height = " + height);
+ }
+
+ @Override
+ public boolean onLeftIconClicked(final View view) {
+ return false;
+ }
+
+ @Override
+ public boolean onRightIconClicked(final View view) {
+ return false;
+ }
+}
diff --git a/app/src/main/java/cn/hadcn/keyboard_example/MainActivity.java b/app/src/main/java/cn/hadcn/keyboard_example/MainActivity.java
index 00a2971..5c04700 100644
--- a/app/src/main/java/cn/hadcn/keyboard_example/MainActivity.java
+++ b/app/src/main/java/cn/hadcn/keyboard_example/MainActivity.java
@@ -1,210 +1,31 @@
package cn.hadcn.keyboard_example;
-import android.Manifest;
+import android.content.Intent;
import android.os.Bundle;
-import android.support.v4.app.ActivityCompat;
import android.support.v7.app.AppCompatActivity;
-import android.support.v7.widget.Toolbar;
-import android.view.Menu;
-import android.view.MenuItem;
-import android.view.MotionEvent;
import android.view.View;
-import android.widget.ListView;
-import android.widget.Toast;
-import java.util.ArrayList;
-
-import cn.hadcn.keyboard.ChatKeyboardLayout;
-import cn.hadcn.keyboard.RecordingLayout;
-import cn.hadcn.keyboard.media.MediaBean;
-
-public class MainActivity extends AppCompatActivity implements View.OnClickListener, MediaBean
- .MediaListener, ChatKeyboardLayout.OnChatKeyBoardListener {
- private static final int PERMISSION_REQUEST_CODE = 0;
- private ChatKeyboardLayout keyboardLayout = null;
- private SimpleChatAdapter mAdapter;
- private RecordingLayout rlRecordArea;
- private String mVoicePath;
+public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
- setSupportActionBar((Toolbar) findViewById(R.id.toolbar));
-
- keyboardLayout = (ChatKeyboardLayout) findViewById(R.id.kv_bar);
-
- ArrayList popupModels = new ArrayList<>();
- popupModels.add(new MediaBean(0, R.drawable.icon_camera, "拍照", this));
- popupModels.add(new MediaBean(1, R.drawable.icon_photo, "照片", this));
- popupModels.add(new MediaBean(2, R.drawable.icon_camera, "拍照", this));
- popupModels.add(new MediaBean(3, R.drawable.icon_photo, "照片", this));
- popupModels.add(new MediaBean(4, R.drawable.icon_camera, "拍照", this));
- popupModels.add(new MediaBean(5, R.drawable.icon_photo, "照片", this));
- popupModels.add(new MediaBean(6, R.drawable.icon_camera, "拍照", this));
- popupModels.add(new MediaBean(7, R.drawable.icon_photo, "照片", this));
- popupModels.add(new MediaBean(8, R.drawable.icon_camera, "拍照", this));
- popupModels.add(new MediaBean(9, R.drawable.pic_select_n, "照片", this));
- keyboardLayout.initMediaContents(popupModels);
-
- ListView listView = (ListView) findViewById(R.id.list_view);
- mAdapter = new SimpleChatAdapter(this);
- listView.setOnTouchListener(new View.OnTouchListener() {
+ findViewById(R.id.main_lv).setOnClickListener(new View.OnClickListener() {
@Override
- public boolean onTouch(View view, MotionEvent motionEvent) {
- keyboardLayout.hideKeyboard();
- return false;
+ public void onClick(View v) {
+ Intent intent = new Intent(MainActivity.this, ListviewActivity.class);
+ startActivity(intent);
}
});
- listView.setAdapter(mAdapter);
-
- rlRecordArea = (RecordingLayout) findViewById(R.id.recording_area);
-
- keyboardLayout.setOnChatKeyBoardListener(this);
- findViewById(R.id.keyboard_show_hide).setOnClickListener(new View.OnClickListener() {
+ findViewById(R.id.main_rv).setOnClickListener(new View.OnClickListener() {
@Override
- public void onClick(final View v) {
- hideShow(v);
+ public void onClick(View v) {
+ Intent intent = new Intent(MainActivity.this, RecyclerviewActivity.class);
+ startActivity(intent);
}
});
- findViewById(R.id.keyboard_pop_back).setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(final View v) {
- popBack(v);
- }
- });
- }
-
- @Override
- public boolean onCreateOptionsMenu(Menu menu) {
- // Inflate the menu; this adds items to the action bar if it is present.
- getMenuInflater().inflate(R.menu.menu_main, menu);
- return true;
- }
-
- @Override
- public boolean onOptionsItemSelected(MenuItem item) {
- // Handle action bar item clicks here. The action bar will
- // automatically handle clicks on the Home/Up button, so long
- // as you specify a parent activity in AndroidManifest.xml.
- int id = item.getItemId();
-
- //noinspection SimplifiableIfStatement
- switch (id) {
- case R.id.action_text_only:
- keyboardLayout.setKeyboardStyle(ChatKeyboardLayout.Style.TEXT_ONLY);
- return true;
- case R.id.action_text_emoticon:
- keyboardLayout.setKeyboardStyle(ChatKeyboardLayout.Style.TEXT_EMOTICON);
- return true;
- case R.id.action_chat_style:
- keyboardLayout.setKeyboardStyle(ChatKeyboardLayout.Style.CHAT_STYLE);
- keyboardLayout.setShowRightIcon(true);
- return true;
- default:
- return super.onOptionsItemSelected(item);
- }
- }
-
- public void hideShow(View view) {
- if (keyboardLayout.isLayoutVisible()) {
- keyboardLayout.hideLayout();
- } else {
- keyboardLayout.showLayout();
- }
- }
-
- public void popBack(View view) {
- if (keyboardLayout.isKeyboardPopped()) {
- keyboardLayout.hideKeyboard();
- } else {
- keyboardLayout.popKeyboard();
- }
- }
-
- @Override
- public void onClick(View view) {
-
- }
-
- @Override
- public void onMediaClick(int id) {
-
- }
-
- @Override
- public void onSendButtonClicked(String msg) {
- mAdapter.addItem(new ChatBean(null, msg));
- keyboardLayout.clearInputContent();
- }
-
- @Override
- public void onInputTextChanged(final String text) {
-
- }
-
- @Override
- public void onRecordingAction(ChatKeyboardLayout.RecordingAction action) {
- switch (action) {
- case START:
- mVoicePath = AudioLib.getInstance().generatePath(this);
- AudioLib.getInstance().start(mVoicePath, new AudioListener());
- rlRecordArea.show(1);
- break;
- case RESTORE:
- rlRecordArea.show(1);
- break;
- case READY_CANCEL:
- rlRecordArea.show(0);
- break;
- case CANCELED:
- AudioLib.getInstance().cancel();
- rlRecordArea.hide();
- break;
- case COMPLETE:
- if (AudioLib.getInstance().complete() < 0) {
- Toast.makeText(this, "time is too short", Toast.LENGTH_SHORT).show();
- }
- rlRecordArea.hide();
- break;
- case PERMISSION_NOT_GRANTED:
- ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.RECORD_AUDIO}, PERMISSION_REQUEST_CODE);
- break;
- }
- }
-
- private class AudioListener implements AudioLib.OnAudioListener {
- @Override
- public void onDbChange(double db) {
- int level = 0;
- LogUtil.e("", "onDbChange db = " + db);
- if (db > 40) {
- level = ((int) db - 40) / 7;
- }
- LogUtil.e("", "onDbChange level = " + level);
- rlRecordArea.setVoiceLevel(level);
- }
- }
-
- @Override
- public void onUserDefEmoticonClicked(String tag, String uri) {
- mAdapter.addItem(new ChatBean(tag, null));
- }
-
- @Override
- public void onKeyboardHeightChanged(final int height) {
- LogUtil.e("", "height = " + height);
- }
-
- @Override
- public boolean onLeftIconClicked(final View view) {
- return false;
- }
-
- @Override
- public boolean onRightIconClicked(final View view) {
- return false;
}
}
diff --git a/app/src/main/java/cn/hadcn/keyboard_example/RecyclerviewActivity.java b/app/src/main/java/cn/hadcn/keyboard_example/RecyclerviewActivity.java
new file mode 100644
index 0000000..6bfa1fc
--- /dev/null
+++ b/app/src/main/java/cn/hadcn/keyboard_example/RecyclerviewActivity.java
@@ -0,0 +1,241 @@
+package cn.hadcn.keyboard_example;
+
+import android.Manifest;
+import android.os.Bundle;
+import android.support.v4.app.ActivityCompat;
+import android.support.v4.widget.SwipeRefreshLayout;
+import android.support.v7.app.AppCompatActivity;
+import android.support.v7.widget.LinearLayoutManager;
+import android.support.v7.widget.RecyclerView;
+import android.support.v7.widget.Toolbar;
+import android.view.Menu;
+import android.view.MenuItem;
+import android.view.MotionEvent;
+import android.view.View;
+import android.view.ViewStub;
+import android.widget.Toast;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import cn.hadcn.keyboard.ChatKeyboardLayout;
+import cn.hadcn.keyboard.RecordingLayout;
+import cn.hadcn.keyboard.media.MediaBean;
+
+public class RecyclerviewActivity extends AppCompatActivity implements View.OnClickListener, MediaBean
+ .MediaListener, ChatKeyboardLayout.OnChatKeyBoardListener {
+ private static final int PERMISSION_REQUEST_CODE = 0;
+ private ChatKeyboardLayout keyboardLayout = null;
+ private RecordingLayout rlRecordArea;
+ private String mVoicePath;
+ private SwipeRefreshLayout swipeRefreshLayout;
+ private RecyclerView recyclerView;
+ private SimpleChatRvAdapter adapter;
+ private ViewStub viewStub;
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_recyclerview);
+
+ setSupportActionBar((Toolbar) findViewById(R.id.toolbar));
+
+ keyboardLayout = (ChatKeyboardLayout) findViewById(R.id.kv_bar);
+ viewStub = (ViewStub) findViewById(R.id.recording_layout_viewstub);
+
+ ArrayList popupModels = new ArrayList<>();
+ popupModels.add(new MediaBean(0, R.drawable.icon_camera, "拍照", this));
+ popupModels.add(new MediaBean(1, R.drawable.icon_photo, "照片", this));
+ popupModels.add(new MediaBean(2, R.drawable.icon_camera, "拍照", this));
+ popupModels.add(new MediaBean(3, R.drawable.icon_photo, "照片", this));
+ popupModels.add(new MediaBean(4, R.drawable.icon_camera, "拍照", this));
+ popupModels.add(new MediaBean(5, R.drawable.icon_photo, "照片", this));
+ popupModels.add(new MediaBean(6, R.drawable.icon_camera, "拍照", this));
+ popupModels.add(new MediaBean(7, R.drawable.icon_photo, "照片", this));
+ popupModels.add(new MediaBean(8, R.drawable.icon_camera, "拍照", this));
+ popupModels.add(new MediaBean(9, R.drawable.pic_select_n, "照片", this));
+ keyboardLayout.initMediaContents(popupModels);
+
+ swipeRefreshLayout = ((SwipeRefreshLayout) findViewById(R.id.srlt));
+ swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
+ @Override
+ public void onRefresh() {
+ swipeRefreshLayout.postDelayed(new Runnable() {
+ @Override
+ public void run() {
+ swipeRefreshLayout.setRefreshing(false);
+ }
+ }, 1000);
+ }
+ });
+
+ recyclerView = (RecyclerView) findViewById(R.id.rv);
+ recyclerView.setLayoutManager(new LinearLayoutManager(this));
+ recyclerView.setOnTouchListener(new View.OnTouchListener() {
+ @Override
+ public boolean onTouch(View v, MotionEvent event) {
+ if (event.getAction() == MotionEvent.ACTION_DOWN && keyboardLayout.isKeyboardPopped()) {
+ keyboardLayout.hideKeyboard();
+ return true;
+ }
+ return false;
+ }
+ });
+
+ List list = new ArrayList<>();
+ adapter = new SimpleChatRvAdapter(this, list);
+ recyclerView.setAdapter(adapter);
+
+ keyboardLayout.setOnChatKeyBoardListener(this);
+
+ findViewById(R.id.keyboard_show_hide).setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(final View v) {
+ hideShow(v);
+ }
+ });
+ findViewById(R.id.keyboard_pop_back).setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(final View v) {
+ popBack(v);
+ }
+ });
+ }
+
+ @Override
+ public boolean onCreateOptionsMenu(Menu menu) {
+ // Inflate the menu; this adds items to the action bar if it is present.
+ getMenuInflater().inflate(R.menu.menu_main, menu);
+ return true;
+ }
+
+ @Override
+ public boolean onOptionsItemSelected(MenuItem item) {
+ // Handle action bar item clicks here. The action bar will
+ // automatically handle clicks on the Home/Up button, so long
+ // as you specify a parent activity in AndroidManifest.xml.
+ int id = item.getItemId();
+
+ //noinspection SimplifiableIfStatement
+ switch (id) {
+ case R.id.action_text_only:
+ keyboardLayout.setKeyboardStyle(ChatKeyboardLayout.Style.TEXT_ONLY);
+ return true;
+ case R.id.action_text_emoticon:
+ keyboardLayout.setKeyboardStyle(ChatKeyboardLayout.Style.TEXT_EMOTICON);
+ return true;
+ case R.id.action_chat_style:
+ keyboardLayout.setKeyboardStyle(ChatKeyboardLayout.Style.CHAT_STYLE);
+ keyboardLayout.setShowRightIcon(true);
+ return true;
+ default:
+ return super.onOptionsItemSelected(item);
+ }
+ }
+
+ public void hideShow(View view) {
+ if (keyboardLayout.isLayoutVisible()) {
+ keyboardLayout.hideLayout();
+ } else {
+ keyboardLayout.showLayout();
+ }
+ }
+
+ public void popBack(View view) {
+ if (keyboardLayout.isKeyboardPopped()) {
+ keyboardLayout.hideKeyboard();
+ } else {
+ keyboardLayout.popKeyboard();
+ }
+ }
+
+ @Override
+ public void onClick(View view) {
+
+ }
+
+ @Override
+ public void onMediaClick(int id) {
+
+ }
+
+ @Override
+ public void onSendButtonClicked(String msg) {
+ adapter.addItem(new ChatBean(null, msg));
+ keyboardLayout.clearInputContent();
+ }
+
+ @Override
+ public void onInputTextChanged(final String text) {
+
+ }
+
+ @Override
+ public void onRecordingAction(ChatKeyboardLayout.RecordingAction action) {
+ if (rlRecordArea == null) {
+ rlRecordArea = (RecordingLayout) viewStub.inflate();
+ }
+ switch (action) {
+ case START:
+ mVoicePath = AudioLib.getInstance().generatePath(this);
+ AudioLib.getInstance().start(mVoicePath, new AudioListener());
+ rlRecordArea.show(1);
+ break;
+ case RESTORE:
+ rlRecordArea.show(1);
+ break;
+ case READY_CANCEL:
+ rlRecordArea.show(0);
+ break;
+ case CANCELED:
+ AudioLib.getInstance().cancel();
+ rlRecordArea.hide();
+ break;
+ case COMPLETE:
+ if (AudioLib.getInstance().complete() < 0) {
+ Toast.makeText(this, "time is too short", Toast.LENGTH_SHORT).show();
+ }
+ rlRecordArea.hide();
+ break;
+ case PERMISSION_NOT_GRANTED:
+ ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.RECORD_AUDIO}, PERMISSION_REQUEST_CODE);
+ break;
+ }
+ }
+
+ private class AudioListener implements AudioLib.OnAudioListener {
+ @Override
+ public void onDbChange(double db) {
+ int level = 0;
+ LogUtil.e("", "onDbChange db = " + db);
+ if (db > 40) {
+ level = ((int) db - 40) / 7;
+ }
+ LogUtil.e("", "onDbChange level = " + level);
+ rlRecordArea.setVoiceLevel(level);
+ }
+ }
+
+ @Override
+ public void onUserDefEmoticonClicked(String tag, String uri) {
+ adapter.addItem(new ChatBean(tag, null));
+ }
+
+ @Override
+ public void onKeyboardHeightChanged(final int height) {
+ LogUtil.e("", "height = " + height);
+ if (keyboardLayout.isKeyboardPopped()) {
+ recyclerView.scrollToPosition(adapter.getItemCount() - 1);
+ }
+ }
+
+ @Override
+ public boolean onLeftIconClicked(final View view) {
+ return false;
+ }
+
+ @Override
+ public boolean onRightIconClicked(final View view) {
+ return false;
+ }
+}
diff --git a/app/src/main/java/cn/hadcn/keyboard_example/SimpleChatRvAdapter.java b/app/src/main/java/cn/hadcn/keyboard_example/SimpleChatRvAdapter.java
new file mode 100644
index 0000000..965d0c4
--- /dev/null
+++ b/app/src/main/java/cn/hadcn/keyboard_example/SimpleChatRvAdapter.java
@@ -0,0 +1,58 @@
+package cn.hadcn.keyboard_example;
+
+import android.content.Context;
+import android.support.v7.widget.RecyclerView;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.ImageView;
+
+import java.util.List;
+
+import cn.hadcn.keyboard.ChatTextView;
+
+public class SimpleChatRvAdapter extends RecyclerView.Adapter {
+
+ private Context context;
+ private List list;
+
+ public SimpleChatRvAdapter(Context context, List list) {
+ this.context = context;
+ this.list = list;
+ }
+
+ public void addItem(ChatBean bean) {
+ int size = list.size();
+ list.add(bean);
+ notifyItemInserted(size);
+ }
+
+ @Override
+ public SimpleChatRvViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
+ LayoutInflater inflater = LayoutInflater.from(context);
+ View view = inflater.inflate(R.layout.item_list, parent, false);
+ return new SimpleChatRvViewHolder(view);
+ }
+
+ @Override
+ public void onBindViewHolder(SimpleChatRvViewHolder holder, int position) {
+ ChatBean bean = list.get(position);
+ holder.chatTextView.setText(bean.getTextMsg());
+ }
+
+ @Override
+ public int getItemCount() {
+ return list.size();
+ }
+
+ public static class SimpleChatRvViewHolder extends RecyclerView.ViewHolder {
+ private ImageView imageView;
+ private ChatTextView chatTextView;
+
+ public SimpleChatRvViewHolder(View itemView) {
+ super(itemView);
+ imageView = (ImageView) itemView.findViewById(R.id.item_image);
+ chatTextView = (ChatTextView) itemView.findViewById(R.id.item_text);
+ }
+ }
+}
diff --git a/app/src/main/res/layout/activity_listview.xml b/app/src/main/res/layout/activity_listview.xml
new file mode 100644
index 0000000..eb381ee
--- /dev/null
+++ b/app/src/main/res/layout/activity_listview.xml
@@ -0,0 +1,47 @@
+
+
+
+
+
+
+
+
+
+
+
diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml
index eb381ee..19bc197 100644
--- a/app/src/main/res/layout/activity_main.xml
+++ b/app/src/main/res/layout/activity_main.xml
@@ -2,46 +2,21 @@
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
-
-
-
-
-
-
-
-
-
+ android:text="listview版本"
+ android:layout_alignParentTop="true"
+ android:layout_alignParentLeft="true"
+ android:layout_alignParentStart="true"/>
+
+
diff --git a/app/src/main/res/layout/activity_recyclerview.xml b/app/src/main/res/layout/activity_recyclerview.xml
new file mode 100644
index 0000000..ce438bd
--- /dev/null
+++ b/app/src/main/res/layout/activity_recyclerview.xml
@@ -0,0 +1,52 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/app/src/main/res/layout/item_list.xml b/app/src/main/res/layout/item_list.xml
index ec019ee..87846ea 100644
--- a/app/src/main/res/layout/item_list.xml
+++ b/app/src/main/res/layout/item_list.xml
@@ -1,7 +1,7 @@
+ android:layout_height="wrap_content">
+
\ No newline at end of file