package robot.com.myapplication;
import android.view.View;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import org.json.JSONException;
import org.json.JSONObject;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;
public class MainActivity extends AppCompatActivity implements
HttpGetDataListener,View.OnClickListener {
private HttpData httpData;// �첽�������
private List<ListData> lists;
private ListView lv;
private EditText et_sendText;
private Button btn_send;
private String content_str; // �惦��EditText�@ȡ���Ĕ���
private TextAdapter adapter;
private String[] welcome_arry;//��ӭ��
private double currentTime,oldTime = 0;//�Ի�ʱ��
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Log.i("haha7", "----------7");
initView();
Log.i("haha8", "----------8");
}
/**
* ʵ��������
*/
private void initView(){
lists = new ArrayList<ListData>();
lv = (ListView) findViewById(R.id.lv);
et_sendText = (EditText) findViewById(R.id.et_sendText);
btn_send = (Button) findViewById(R.id.btn_send);
btn_send.setOnClickListener(this);
adapter = new TextAdapter(lists, this);
lv.setAdapter(adapter);//��adapter
ListData listData;
listData = new ListData(getRandomWelcomeTips(),ListData.RECEIVE, getTime());
lists.add(listData);//��ӻ�ӭ��
}
/**
* ���û�ӭ��
*/
public String getRandomWelcomeTips(){
// String welcome_tip = null;
// welcome_arry = this.getResources().getStringArray(getResources().getString(R.string.welcome_tips));//��string.xml�л�ȡ��Ϊwelcome_tips���ַ�������
// int index = (int)(Math.random()*(welcome_arry.length - 1));//��ȡһ�������
// welcome_tip = welcome_arry[index];
return getResources().getString(R.string.welcome_tips);
}
/**
* ����ʱ��
* @return
*/
private String getTime(){
currentTime = System.currentTimeMillis();
SimpleDateFormat format = new SimpleDateFormat("yyyy��MM��dd�� HH:mm:ss");
Date curDate = new Date();
String str = format.format(curDate);
if(currentTime - oldTime >= 5*60*1000){//�������5���ӣ���ʾʱ��
oldTime = currentTime;
return str;
}else{
return "";
}
}
@Override
public void getDataUrl(String data) {
Log.i("haha---data=","------" + data);
parseText(data);
}
public void parseText(String str){//����json
try {
JSONObject jb = new JSONObject(str);
ListData listData;
listData = new ListData(jb.getString("text"),ListData.RECEIVE, getTime());
lists.add(listData);
adapter.notifyDataSetChanged();//�����m�䣿��
} catch (JSONException e) {
e.printStackTrace();
}
}
@Override
public void onClick(View v) {
getTime();//����ʱ��
content_str = et_sendText.getText().toString();//�@ȡEditText����
et_sendText.setText("");
String dropk = content_str.replace(" ", "");//ȥ���ո�
String droph = dropk.replace("\n", "");//ȥ���س�
ListData listData;
listData = new ListData(content_str, ListData.SEND, getTime());
lists.add(listData);
Log.i("haha9", "----------content_str="+content_str);
adapter.notifyDataSetChanged();//ˢ��
Log.i("haha6", "----------content_str="+content_str);
httpData = (HttpData) new HttpData(
"http://www.tuling123.com/openapi/api?key=02dfb86de93f8a3e81dabd214a50c8fa&info=" + droph + "&userid=15602229049",
this).execute();// �����Ѿ�ȥ���ո�ͻس�content_str������droph ; execute()�����첽ͨ��
Log.i("haha5", "----------"+httpData);
if(lists.size() > 30){//�����Ļ�ϵĶԻ����ݶ���30�����Ƴ�ǰ�������
for (int i = 0; i < lists.size(); i++) {
lists.remove(i);
}
}
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
Android之Android studio实现智能聊天 (102个子文件)
gradlew.bat 2KB
fileSnapshots.bin 1.8MB
classAnalysis.bin 1.02MB
jarAnalysis.bin 430KB
fileHashes.bin 243KB
taskHistory.bin 138KB
taskHistory.bin 60KB
taskJars.bin 23KB
resourceHashesCache.bin 20KB
last-build.bin 1B
built.bin 0B
.gitignore 127B
.gitignore 8B
build.gradle 914B
build.gradle 573B
settings.gradle 16B
gradlew 5KB
app.iml 11KB
MyApplication2.iml 868B
httpclient-4.2.5.jar 423KB
commons-codec-1.6.jar 227KB
httpcore-4.2.4.jar 222KB
httpclient-cache-4.2.5.jar 113KB
commons-logging-1.1.1.jar 59KB
gradle-wrapper.jar 52KB
httpmime-4.2.5.jar 26KB
fluent-hc-4.2.5.jar 21KB
MainActivity.java 5KB
HttpData.java 3KB
TextAdapter.java 2KB
ListData.java 792B
ExampleInstrumentedTest.java 773B
ExampleUnitTest.java 417B
HttpGetDataListener.java 111B
person1.jpg 25KB
person2.jpg 21KB
person3.jpg 20KB
fileContent.lock 17B
fileHashes.lock 17B
javaCompile.lock 17B
taskHistory.lock 17B
cache.properties.lock 2B
ic_launcher_round.png 15KB
ic_launcher_round.png 10KB
ic_launcher.png 9KB
ic_launcher.png 7KB
ic_launcher_round.png 7KB
ic_launcher.png 6KB
ic_launcher_round.png 5KB
ic_launcher.png 4KB
ic_launcher.png 3KB
ic_launcher_round.png 3KB
left.9.png 3KB
right.9.png 2KB
ic_launcher.png 2KB
proguard-rules.pro 772B
gradle.properties 776B
local.properties 419B
gradle-wrapper.properties 236B
cache.properties 51B
workspace.xml 166KB
ic_launcher_background.xml 6KB
misc.xml 2KB
ic_launcher_foreground.xml 2KB
activity_main.xml 2KB
rightitem.xml 1KB
leftitem.xml 1KB
AndroidManifest.xml 808B
com_android_support_animated_vector_drawable_26_1_0.xml 742B
com_android_support_support_vector_drawable_26_1_0.xml 737B
com_android_support_support_media_compat_26_1_0.xml 722B
com_android_support_support_core_utils_26_1_0.xml 712B
com_android_support_support_fragment_26_1_0.xml 702B
com_android_support_support_core_ui_26_1_0.xml 697B
com_android_support_support_compat_26_1_0.xml 692B
com_android_support_appcompat_v7_26_1_0.xml 682B
com_android_support_support_v4_26_1_0.xml 672B
android_arch_lifecycle_runtime_1_0_0.xml 658B
gradle.xml 626B
com_android_support_support_annotations_26_1_0_jar.xml 608B
runConfigurations.xml 564B
android_arch_lifecycle_common_1_0_0_jar.xml 548B
org_hamcrest_hamcrest_core_1_3_jar.xml 543B
android_arch_core_common_1_0_0_jar.xml 533B
com_android_support_constraint_constraint_layout_1_1_3.xml 501B
junit_junit_4_12_jar.xml 487B
bg_button.xml 463B
com_android_support_constraint_constraint_layout_solver_1_1_3_jar.xml 425B
styles.xml 394B
modules.xml 365B
__local_aars___F__MyApplication2_app_libs_httpclient_cache_4_2_5_jar_unspecified_jar.xml 309B
__local_aars___F__MyApplication2_app_libs_commons_logging_1_1_1_jar_unspecified_jar.xml 307B
strings.xml 304B
__local_aars___F__MyApplication2_app_libs_commons_codec_1_6_jar_unspecified_jar.xml 299B
__local_aars___F__MyApplication2_app_libs_httpclient_4_2_5_jar_unspecified_jar.xml 297B
__local_aars___F__MyApplication2_app_libs_fluent_hc_4_2_5_jar_unspecified_jar.xml 295B
__local_aars___F__MyApplication2_app_libs_httpcore_4_2_4_jar_unspecified_jar.xml 293B
__local_aars___F__MyApplication2_app_libs_httpmime_4_2_5_jar_unspecified_jar.xml 293B
bg_edittext_selector.xml 282B
ic_launcher.xml 276B
共 102 条
- 1
- 2
资源评论
- weixin_480434062021-06-22运行不了,我以前都是这样导的
- S_M_youzipi2020-04-13可以了可以了,感谢,很不错,我想问问你这个机器人每天可以说几次话?或者可以自己导一个数据库让他匹配该说的话吗?zpf_2020-08-07那你就是改的多了,就是不走图灵机器人接口了
- qq_406435932018-12-21导包之后。。报错啊zpf_2019-05-25你导错包了吧
zpf_
- 粉丝: 280
- 资源: 10
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功