Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#8 #284 综合编程 #1764

Merged
merged 1 commit into from
May 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions students/soft1714080902407/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,27 +1,28 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="edu.hzuapps.androidlabs.soft1714080902407">

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.AppCompat.Light.NoActionBar">
<activity android:name=".Soft1714080902407Activity">
<activity android:name=".Login_Activity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".Detail_Activity"></activity>
<activity android:name=".Soft1714080902407Activity"/>
<activity android:name=".Detail_Activity" />
</application>

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package edu.hzuapps.androidlabs.soft1714080902407;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import java.util.List;

public class ChatAdapter extends BaseAdapter {
private List<Message> list;
private Context context;

public void setList(List<Message> list){
this.list=list;
notifyDataSetChanged();
}
public ChatAdapter(List<Message> list,Context context){
this.list=list;
this.context=context;
}

class HolderView{
TextView chattime,chatmsg;
}

@Override
public int getCount(){
return list.size();
}

@Override
public Object getItem(int position) {
return list.get(position);
}

@Override
public long getItemId(int position) {
return position;
}

@Override
public boolean isEnabled(int position) {
return false;
}


@Override
public View getView(int position, View convertView, ViewGroup parent) {
HolderView holderView = null;
Message message = list.get(position);
boolean isMeSend = message.getSend();
if (holderView == null) {
holderView = new HolderView();
if (isMeSend == true) {
convertView = View.inflate(context, R.layout.item_chat_right_bubble, null);
holderView.chatmsg = (TextView) convertView.findViewById(R.id.tv_chatmsg);
holderView.chatmsg.setText(message.getMsg());
holderView.chattime = (TextView) convertView.findViewById(R.id.tv_chattime);
holderView.chattime.setText(message.getTime());
} else {
convertView = View.inflate(context, R.layout.item_chat_left_bubble, null);

}
convertView.setTag(holderView);
} else {
holderView = (HolderView) convertView.getTag();
}
return convertView;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,13 @@
import java.io.FileInputStream;
import java.io.FileNotFoundException;

public class Detail_Activity extends AppCompatActivity implements View.OnClickListener {
public class Detail_Activity extends AppCompatActivity {
private Button mCheckButton;
private Button mDownloadImageButton;
private Button mloadimgButton;
private TextView mNetworkText;
private ImageView mimageView;
private File mPrivateRootDir;
private File mImagesDir;
private boolean mConnected;
private NetworkFileDownloader mFileDownloader;
public static final String TAG = Detail_Activity.class.getSimpleName();
public static final String IMAGE_URL_PREFIX = "https://github.com/Firethecode/android-labs-2019/raw/master/students/soft1714080902407/app/src/main/res/drawable/";
Expand All @@ -43,61 +41,27 @@ protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.detail_activity);

mCheckButton = (Button) findViewById(R.id.button_check);
mDownloadImageButton = (Button) findViewById(R.id.button_download_image);
mNetworkText = (TextView) findViewById(R.id.text_network);
mimageView = (ImageView) findViewById(R.id.image);
mloadimgButton = (Button) findViewById(R.id.button_loadimg);

mCheckButton.setOnClickListener(this);
mDownloadImageButton.setOnClickListener(this);
mloadimgButton.setOnClickListener(this);

mPrivateRootDir = getFilesDir();

mImagesDir = new File(mPrivateRootDir, "images");

}

@Override
public void onClick(View view) {
if (view.getId() == R.id.button_check) {
checkNetworkState();
} else if (view.getId() == R.id.button_download_image) {
if (view.getId() == R.id.button_download_image) {
downloadImages();
}else if (view.getId() == R.id.button_loadimg) {
}else if(view.getId() == R.id.button_loadimg) {
showjpg();
}else if(view.getId()==R.id.button_back){
Intent intent = new Intent(Detail_Activity.this,Soft1714080902407Activity.class);
startActivity(intent);
}
}

private void checkNetworkState() {
ConnectivityManager connMgr = (ConnectivityManager)
getSystemService(Context.CONNECTIVITY_SERVICE);

NetworkInfo networkInfo = connMgr.getActiveNetworkInfo();
if (networkInfo != null && networkInfo.isConnected()) {
mConnected = true;
} else {
mConnected = false;
}

String types = "";

networkInfo = connMgr.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
boolean isWifiConn = networkInfo != null && networkInfo.isConnected();
types += isWifiConn ? "Wi-Fi" : "";

networkInfo = connMgr.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
boolean isMobileConn = networkInfo != null && networkInfo.isConnected();
types += isMobileConn ? "流量" : "";

networkInfo = connMgr.getNetworkInfo(ConnectivityManager.TYPE_BLUETOOTH);
boolean isBluetoothConn = networkInfo != null && networkInfo.isConnected();
types += isBluetoothConn ? ", 蓝牙" : "";

mNetworkText.setTextColor(mConnected ? Color.GREEN : Color.RED);
mNetworkText.setText(mConnected ? "网络正常 (" +types + ")" : "网络未连接!");
}

private void downloadImages() {
mFileDownloader = new NetworkFileDownloader(new NetworkFileDownloader.OnImageDownloadListener() {
Expand Down Expand Up @@ -134,10 +98,6 @@ public void onBitmapSaveError(String error) {
mFileDownloader.download(imageUrl, true);
}
}
public void onClick1(View view){
Intent intent = new Intent(Detail_Activity.this,Soft1714080902407Activity.class);
startActivity(intent);
}

public void showjpg(){
Bitmap bitmap = getLoacalBitmap("/data/user/0/edu.hzuapps.androidlabs.Soft1714080902407/files/images/zjq.jpg");
Expand All @@ -153,4 +113,4 @@ public static Bitmap getLoacalBitmap(String url) {
e.printStackTrace();
return null;
}
}}
}}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package edu.hzuapps.androidlabs.soft1714080902407;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;

public class Login_Activity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.login_activity);
boolean conn = ConnectionUtil.isConn(Login_Activity.this);

if (!conn) {
ConnectionUtil.setNetworkMethod(Login_Activity.this);
}
}

public void onClick(View view) {
if (view.getId() == R.id.button_login) {
Intent intent = new Intent(Login_Activity.this,Soft1714080902407Activity.class);
startActivity(intent);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
public class Message {
private Long id;
private String msg;
private String time;
private Boolean send;

public Long getId() {
return id;
Expand All @@ -20,18 +22,32 @@ public void setMsg(String msg) {
this.msg = msg;
}

public Message(Long id,String msg){
super();
this.id=id;
this.msg=msg;
public String getTime() {
return time;
}

public Message(String msg){
super();
this.msg=msg;
public void setTime(String time) {
this.time = time;
}

public boolean getSend() {
return send;
}

public void setSend(boolean send) {
this.send = send;
}

public Message(){
super();
public Message(){

}


public Message(Long id,String msg,String time,Boolean send){
this.id=id;
this.msg=msg;
this.time=time;
this.send=send;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,42 @@
import java.util.List;

public class MessageDao {
private MyHelper myHelper;
private SQLiteHelper sqLiteHelper;

public MessageDao(Context context){
myHelper=new MyHelper(context);
sqLiteHelper=new SQLiteHelper(context);
}

public void insert(Message message){
SQLiteDatabase db=myHelper.getWritableDatabase();
ContentValues values=new ContentValues();
values.put("msg",message.getMsg());
long id=db.insert("message",null,values);
SQLiteDatabase sqLiteDatabase=sqLiteHelper.getWritableDatabase();
ContentValues contentValues=new ContentValues();
contentValues.put("msg",message.getMsg());
contentValues.put("time",message.getTime());
contentValues.put("send",message.getSend());
long id=sqLiteDatabase.insert("message",null,contentValues);
message.setId(id);
db.close();
sqLiteDatabase.close();
}

public List<Message> queryAll(){
SQLiteDatabase db=myHelper.getReadableDatabase();
Cursor cursor=db.query("message",null,null,null,null,null,null);
List<Message>list=new ArrayList<Message>();
while(cursor.moveToNext()){
long id= cursor.getLong(cursor.getColumnIndex("_id"));
String msg= cursor.getString(1);
list.add(new Message(id,msg));
SQLiteDatabase sqLiteDatabase=sqLiteHelper.getReadableDatabase();
Cursor cursor=sqLiteDatabase.query("message",null,null,null,null,null,null);
List<Message> list=new ArrayList<Message>();
while (cursor.moveToNext()){
long id=cursor.getLong(cursor.getColumnIndex("id"));
String msg=cursor.getString(1);
String time=cursor.getString(2);
int type=cursor.getInt(3);
boolean send;
if(type==1)
{
send=true;
}
else send=false;
list.add(new Message(id,msg,time,send));
}
cursor.close();
db.close();
sqLiteDatabase.close();
return list;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

public class MyHelper extends SQLiteOpenHelper {
public MyHelper(Context context){
public class SQLiteHelper extends SQLiteOpenHelper {
public SQLiteHelper(Context context){
super(context,"itcast.db",null,2);
}
public void onCreate(SQLiteDatabase db){
System.out.println("onCreate");
db.execSQL("CREATE TABLE message(_id INTEGER PRIMARY KEY AUTOINCREMENT,msg varchar(100))");
db.execSQL("CREATE TABLE Message(id INTEGER PRIMARY KEY AUTOINCREMENT,msg varchar(100),time varchar(100),send boolean)");
}
public void onUpgrade(SQLiteDatabase db,int OldVersion,int NewVersion){
System.out.println("onUpgrade");
Expand Down
Loading