commit
0f720781aa
Binary file not shown.
@ -1,16 +1,163 @@
|
||||
package com.example.leudaemialikeme.Activity;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.os.Bundle;
|
||||
import android.text.Editable;
|
||||
import android.text.TextWatcher;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.widget.EditText;
|
||||
import android.widget.RadioButton;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
|
||||
import com.example.leudaemialikeme.Dao.InvitationDao;
|
||||
import com.example.leudaemialikeme.R;
|
||||
import com.example.leudaemialikeme.Utils.Data;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Locale;
|
||||
|
||||
public class SendInvitationActivity extends AppCompatActivity {
|
||||
|
||||
EditText titleView;
|
||||
EditText detailView;
|
||||
TextView cancelView;
|
||||
TextView commitView;
|
||||
TextView titleCountView;
|
||||
String title;
|
||||
String detail;
|
||||
String type;
|
||||
InvitationDao invitation=new InvitationDao();
|
||||
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_send_invitation);
|
||||
|
||||
initView();
|
||||
setWatcher();
|
||||
setClick();
|
||||
}
|
||||
|
||||
private void setClick() {
|
||||
cancelView.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
SendInvitationActivity.this.finish();
|
||||
}
|
||||
});
|
||||
|
||||
commitView.setOnClickListener(new View.OnClickListener(){
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
title=titleView.getText().toString();
|
||||
detail=detailView.getText().toString();
|
||||
if(title.length()<10){
|
||||
Log.e("输入的title:", String.valueOf(title.length()));
|
||||
Toast.makeText(SendInvitationActivity.this,
|
||||
"您输入的字数尚不足,请完善您的帖子标题",Toast.LENGTH_SHORT).show();}
|
||||
long timeCurrent = System.currentTimeMillis();
|
||||
SimpleDateFormat sdf =new SimpleDateFormat("yyyy-MM-dd", Locale.getDefault());
|
||||
String time = sdf.format(timeCurrent);
|
||||
Log.e("输入的time:", time);
|
||||
new Thread(new Runnable(){
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
Data app = (Data)getApplication();
|
||||
Log.e("type",type);
|
||||
invitation.iInsert(app.uid,type,title,detail,time,0,0);
|
||||
runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Toast.makeText(SendInvitationActivity.this,
|
||||
"提交成功",Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
});
|
||||
} catch (Exception exception) {
|
||||
exception.printStackTrace();
|
||||
runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Toast.makeText(SendInvitationActivity.this,
|
||||
"帖子提交失败,请检查您的网络状况",Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
}).start();
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@SuppressLint("NonConstantResourceId")
|
||||
public void onRadioButtonClicked(View view) {
|
||||
RadioButton button = (RadioButton) view;
|
||||
boolean isChecked = button.isChecked();
|
||||
switch (view.getId()) {
|
||||
case R.id.SendInvitation_radio_bad:
|
||||
case R.id.SendInvitation_radio_recover:
|
||||
case R.id.SendInvitation_radio_experience:
|
||||
case R.id.SendInvitation_radio_knowledge:
|
||||
if (isChecked) {
|
||||
type=button.getText().toString();
|
||||
}
|
||||
break;
|
||||
default:
|
||||
type="经验帖";
|
||||
break;
|
||||
}
|
||||
}
|
||||
public void initView(){
|
||||
titleView=(EditText)findViewById(R.id.invitation_title);
|
||||
detailView=(EditText)findViewById(R.id.invitation_detail);
|
||||
cancelView=(TextView)findViewById(R.id.invitation_cancel);
|
||||
commitView=(TextView)findViewById(R.id.invitation_commit);
|
||||
titleCountView=(TextView)findViewById(R.id.invitation_title_count);
|
||||
}
|
||||
|
||||
public void setWatcher(){
|
||||
titleView.addTextChangedListener(new TextWatcher() {
|
||||
private CharSequence temp;
|
||||
@Override
|
||||
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
||||
temp=s;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterTextChanged(Editable s) {
|
||||
int editStart = titleView.getSelectionStart();
|
||||
int editEnd = titleView.getSelectionEnd();
|
||||
titleCountView.setText(temp.length()+"/40");
|
||||
if(temp.length()>40){
|
||||
Toast.makeText(SendInvitationActivity.this,
|
||||
"您输入的字数已经超过限制",Toast.LENGTH_SHORT).show();
|
||||
s.delete(editStart-1,editEnd);
|
||||
int tempSelection=editStart;
|
||||
titleView.setText(s);
|
||||
try{
|
||||
titleView.setSelection(tempSelection);
|
||||
} catch (Exception exception) {
|
||||
titleView.setText(s);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,16 +1,180 @@
|
||||
package com.example.leudaemialikeme.Activity;
|
||||
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.os.Bundle;
|
||||
import android.text.Editable;
|
||||
import android.text.TextWatcher;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.widget.EditText;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
|
||||
import com.example.leudaemialikeme.Dao.QuestionDao;
|
||||
import com.example.leudaemialikeme.R;
|
||||
import com.example.leudaemialikeme.Utils.Data;
|
||||
|
||||
public class SendQuestionActivity extends AppCompatActivity {
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Locale;
|
||||
|
||||
public class SendQuestionActivity extends AppCompatActivity{
|
||||
|
||||
EditText titleText;
|
||||
EditText detailText;
|
||||
TextView cancelView;
|
||||
TextView commitView;
|
||||
TextView textCountView;
|
||||
TextView titleCountView;
|
||||
String title;
|
||||
String detail;
|
||||
QuestionDao question=new QuestionDao();
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_send_question);
|
||||
initViews();
|
||||
setWatcher();
|
||||
setClick();
|
||||
}
|
||||
|
||||
private void setClick() {
|
||||
cancelView.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
SendQuestionActivity.this.finish();
|
||||
}
|
||||
});
|
||||
|
||||
commitView.setOnClickListener(new View.OnClickListener(){
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
title=titleText.getText().toString();
|
||||
detail=detailText.getText().toString();
|
||||
if(titleText.getText().toString().length()<10){
|
||||
Log.e("输入的title:", String.valueOf(title.length()));
|
||||
Toast.makeText(SendQuestionActivity.this,
|
||||
"您输入的字数尚不足,请完善您的问题以便获得更好的回答",Toast.LENGTH_SHORT).show();}
|
||||
long timeCurrent = System.currentTimeMillis();
|
||||
SimpleDateFormat sdf =new SimpleDateFormat("yyyy-MM-dd", Locale.getDefault());
|
||||
String time = sdf.format(timeCurrent);
|
||||
Log.e("输入的time:", time);
|
||||
new Thread(new Runnable(){
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
Data app = (Data)getApplication();
|
||||
question.qInsert(app.uid,title,detail,time,0,0,0);
|
||||
runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Toast.makeText(SendQuestionActivity.this,
|
||||
"提交成功",Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
});
|
||||
} catch (Exception exception) {
|
||||
exception.printStackTrace();
|
||||
runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Toast.makeText(SendQuestionActivity.this,
|
||||
"问题提交失败,请检查您的网络状况",Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
}).start();
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
public void initViews(){
|
||||
titleText=(EditText)findViewById(R.id.editText_question);
|
||||
detailText=(EditText)findViewById(R.id.editText_question_detail);
|
||||
cancelView=(TextView)findViewById(R.id.cancel);
|
||||
commitView=(TextView)findViewById(R.id.commit);
|
||||
textCountView=(TextView)findViewById(R.id.text_count);
|
||||
titleCountView=(TextView)findViewById(R.id.title_count);
|
||||
// title=titleText.getText().toString();
|
||||
// detail=detailText.getText().toString();
|
||||
}
|
||||
|
||||
public void setWatcher(){
|
||||
titleText.addTextChangedListener(new TextWatcher() {
|
||||
private CharSequence temp;
|
||||
@Override
|
||||
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
||||
temp=s;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterTextChanged(Editable s) {
|
||||
int editStart = titleText.getSelectionStart();
|
||||
int editEnd = titleText.getSelectionEnd();
|
||||
titleCountView.setText(temp.length()+"/40");
|
||||
if(temp.length()>40){
|
||||
Toast.makeText(SendQuestionActivity.this,
|
||||
"您输入的字数已经超过限制",Toast.LENGTH_SHORT).show();
|
||||
s.delete(editStart-1,editEnd);
|
||||
int tempSelection=editStart;
|
||||
detailText.setText(s);
|
||||
try{
|
||||
detailText.setSelection(tempSelection);
|
||||
} catch (Exception exception) {
|
||||
detailText.setText(s);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
detailText.addTextChangedListener(new TextWatcher() {
|
||||
private CharSequence temp;
|
||||
|
||||
@Override
|
||||
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
||||
|
||||
}
|
||||
@Override
|
||||
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
||||
temp=s;
|
||||
}
|
||||
@SuppressLint("SetTextI18n")
|
||||
@Override
|
||||
public void afterTextChanged(Editable s) {
|
||||
int editStart = detailText.getSelectionStart();
|
||||
int editEnd = detailText.getSelectionEnd();
|
||||
textCountView.setText(temp.length()+"/200");
|
||||
if(temp.length()>200){
|
||||
Toast.makeText(SendQuestionActivity.this,
|
||||
"您输入的字数已经超过限制",Toast.LENGTH_SHORT).show();
|
||||
s.delete(editStart-1,editEnd);
|
||||
int tempSelection=editStart;
|
||||
detailText.setText(s);
|
||||
try{
|
||||
detailText.setSelection(tempSelection);
|
||||
} catch (Exception exception) {
|
||||
detailText.setText(s);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -0,0 +1,28 @@
|
||||
package com.example.leudaemialikeme.Dao;
|
||||
|
||||
import com.example.leudaemialikeme.Utils.DBUtils;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.Statement;
|
||||
|
||||
public class InvitationDao {
|
||||
public boolean iInsert(int uid,String type,String title,String content,String time,int likeNum,int collectNum)throws Exception{
|
||||
Connection conn=null;
|
||||
Statement state=null;
|
||||
ResultSet rs=null;
|
||||
try{
|
||||
conn= DBUtils.getConnect();
|
||||
state=conn.createStatement();
|
||||
String sql="insert blog(uid,utype,utitle,ucontent,utime,ulikeNum,ucollectNum) values('"+
|
||||
uid+"','"+type+"','"+title+"','"+content+"','"+time+"','"+likeNum+"','"+collectNum+"')";
|
||||
state.execute(sql);
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}finally {
|
||||
DBUtils.release(conn,state,rs);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,60 @@
|
||||
package com.example.leudaemialikeme.Model;
|
||||
|
||||
public class User {
|
||||
private static final long serialVersionUID = 1L;
|
||||
private int uid;
|
||||
private int id;
|
||||
private String username;
|
||||
private String name;
|
||||
private String phone;
|
||||
private String password;
|
||||
|
||||
public int getUid(){
|
||||
return uid;
|
||||
}
|
||||
public void setUid(int uid){
|
||||
this.uid=uid;
|
||||
}
|
||||
public void setId(int id){
|
||||
this.id=id;
|
||||
}
|
||||
public int getId(){
|
||||
return id;
|
||||
}
|
||||
public void setUsername(String username){
|
||||
this.username=username;
|
||||
}
|
||||
public String getUsername(){
|
||||
return username;
|
||||
}
|
||||
public void setName(String name){
|
||||
this.name=name;
|
||||
}
|
||||
public String getName(){
|
||||
return name;
|
||||
}
|
||||
public void setPhone(String phone){
|
||||
this.phone=phone;
|
||||
}
|
||||
public String getPhone(){
|
||||
return phone;
|
||||
}
|
||||
public void setPassword(String password){
|
||||
this.password=password;
|
||||
}
|
||||
public String getPassword(){
|
||||
return password;
|
||||
}
|
||||
public User(int uid,int id,String username,String name, String phone,String password){
|
||||
this.uid=uid;
|
||||
this.id=id;
|
||||
this.username=username;
|
||||
this.name=name;
|
||||
this.phone=phone;
|
||||
this.password=password;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,56 @@
|
||||
package com.example.leudaemialikeme.Utils;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.Statement;
|
||||
|
||||
public class DBUtils {
|
||||
|
||||
private final static String driver = "com.mysql.jdbc.Driver";
|
||||
private final static String url = "jdbc:mysql://192.168.80.1:3306/leukemia?serverTimezone=UTC&useSSL=false&characterEncoding=utf8";
|
||||
|
||||
private final static String username = "root";
|
||||
private final static String password = "123456";
|
||||
|
||||
Connection conn=null;
|
||||
Statement st=null;
|
||||
ResultSet rs=null;
|
||||
|
||||
static {
|
||||
try {
|
||||
Class.forName(driver);
|
||||
Log.v("mysql","加载驱动成功");
|
||||
} catch (ClassNotFoundException e) {
|
||||
Log.e("mysql","加载驱动错误");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//2. 获取连接
|
||||
public static Connection getConnect() throws Exception {
|
||||
Connection conn=DriverManager.getConnection(url, username, password);
|
||||
Log.v("mysql","成功获取数据库");
|
||||
return conn;
|
||||
}
|
||||
|
||||
//3. 释放连接资源
|
||||
|
||||
public static void release(Connection conn, Statement st, ResultSet rs) throws Exception {
|
||||
if (rs != null) {
|
||||
rs.close();
|
||||
}
|
||||
if (st != null) {
|
||||
st.close();
|
||||
}
|
||||
if (conn != null) {
|
||||
conn.close();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,20 @@
|
||||
package com.example.leudaemialikeme.Utils;
|
||||
public class Data extends android.app.Application {
|
||||
public int uid=1;
|
||||
public String id="430481200101220131";
|
||||
public String name="abc";
|
||||
|
||||
public int getUid(){
|
||||
return uid;
|
||||
}
|
||||
public void setUid(int uid){
|
||||
this.uid= uid;
|
||||
}
|
||||
|
||||
public String getId(){
|
||||
return this.id;
|
||||
}
|
||||
public void setId(String id){
|
||||
this.id= id;
|
||||
}
|
||||
}
|
Loading…
Reference in new issue