commit
175fef36d5
@ -0,0 +1,80 @@
|
|||||||
|
package com.android.SQL;
|
||||||
|
|
||||||
|
|
||||||
|
import android.content.ContentValues;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.res.Resources;
|
||||||
|
import android.content.res.TypedArray;
|
||||||
|
import android.database.sqlite.SQLiteDatabase;
|
||||||
|
import android.database.sqlite.SQLiteOpenHelper;
|
||||||
|
import android.view.View;
|
||||||
|
|
||||||
|
import com.android.R;
|
||||||
|
import com.android.bean.DeliveryAdr;
|
||||||
|
|
||||||
|
public class MySQLiteOpenHelper extends SQLiteOpenHelper {
|
||||||
|
View view;
|
||||||
|
private static final String SQL_CREATE_ENTRIES =
|
||||||
|
"CREATE TABLE " + DeliveryAdr.DeliveryEntry.TABLE_NAME + " (" +
|
||||||
|
DeliveryAdr.DeliveryEntry._ID + " INTEGER PRIMARY KEY, " +
|
||||||
|
DeliveryAdr.DeliveryEntry.COLUMN_PEOPLE_NAME + " VARCHAR(200), " +
|
||||||
|
DeliveryAdr.DeliveryEntry.COLUMN_PEOPLE_TELE + " VARCHAR(200), " +
|
||||||
|
DeliveryAdr.DeliveryEntry.COLUMN_DETAIL_ADR + " VARCHAR(100), " +
|
||||||
|
DeliveryAdr.DeliveryEntry.COLUMN_IS_RAW + " VARCHAR(100) " +
|
||||||
|
")" ;
|
||||||
|
|
||||||
|
private static final String SQL_DELETE_ENTRIES =
|
||||||
|
"DROP TABLE IF EXISTS " + DeliveryAdr.DeliveryEntry.TABLE_NAME;
|
||||||
|
|
||||||
|
public static final int DATABASE_VERSION = 1;
|
||||||
|
public static final String DATABASE_NAME = "deliverys.db";
|
||||||
|
|
||||||
|
private Context mContext;
|
||||||
|
public MySQLiteOpenHelper(Context context) {
|
||||||
|
super(context, DATABASE_NAME, null, DATABASE_VERSION);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCreate(SQLiteDatabase sqLiteDatabase) {
|
||||||
|
sqLiteDatabase.execSQL(SQL_CREATE_ENTRIES);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public void onUpgrade(SQLiteDatabase sqLiteDatabase,
|
||||||
|
int oldVersion, int newVersion) {
|
||||||
|
sqLiteDatabase.execSQL(SQL_DELETE_ENTRIES);
|
||||||
|
onCreate(sqLiteDatabase);
|
||||||
|
}
|
||||||
|
|
||||||
|
// private void initDb(SQLiteDatabase sqLiteDatabase) {
|
||||||
|
//
|
||||||
|
// Resources resources = mContext.getResources();
|
||||||
|
// String[] titles = resources.getStringArray(R.array.titles);
|
||||||
|
// String[] authors = resources.getStringArray(R.array.authors);
|
||||||
|
// String[] contents = resources.getStringArray(R.array.contents);
|
||||||
|
// TypedArray images = resources.obtainTypedArray(R.array.images);
|
||||||
|
//
|
||||||
|
// int length = 0;
|
||||||
|
// length = Math.min(titles.length, authors.length);
|
||||||
|
// length = Math.min(length, contents.length);
|
||||||
|
// length = Math.min(length, images.length());
|
||||||
|
//
|
||||||
|
// for (int i = 0; i < length; i++) {
|
||||||
|
// ContentValues values = new ContentValues();
|
||||||
|
// values.put(DeliveryAdr.DeliveryEntry.COLUMN_PEOPLE_NAME ,
|
||||||
|
// titles[i]);
|
||||||
|
// values.put(DeliveryAdr.DeliveryEntry.COLUMN_PEOPLE_TELE,
|
||||||
|
// authors[i]);
|
||||||
|
// values.put(DeliveryAdr.DeliveryEntry.COLUMN_DETAIL_ADR ,
|
||||||
|
// contents[i]);
|
||||||
|
// values.put(DeliveryAdr.DeliveryEntry.COLUMN_IS_RAW ,
|
||||||
|
// images.getString(i));
|
||||||
|
//
|
||||||
|
// long r = sqLiteDatabase.insert(
|
||||||
|
// DeliveryAdr.DeliveryEntry.TABLE_NAME,
|
||||||
|
// null,
|
||||||
|
// values);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
}
|
@ -0,0 +1,83 @@
|
|||||||
|
package com.android.activity;
|
||||||
|
|
||||||
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
|
import androidx.appcompat.widget.SwitchCompat;
|
||||||
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
|
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.database.Cursor;
|
||||||
|
import android.database.sqlite.SQLiteDatabase;
|
||||||
|
import android.graphics.Bitmap;
|
||||||
|
import android.graphics.BitmapFactory;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.view.View;
|
||||||
|
import android.widget.Button;
|
||||||
|
import android.widget.ListView;
|
||||||
|
|
||||||
|
import com.android.R;
|
||||||
|
import com.android.SQL.MySQLiteOpenHelper;
|
||||||
|
import com.android.activity.adapter.DeliverysAdapter;
|
||||||
|
import com.android.bean.DeliveryAdr;
|
||||||
|
import com.android.model.Delivery;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class DeliverActivity extends AppCompatActivity {
|
||||||
|
|
||||||
|
MySQLiteOpenHelper myDbHelper;
|
||||||
|
SQLiteDatabase db;
|
||||||
|
private List<Delivery> deliList = new ArrayList<>();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
setContentView(R.layout.activity_delivery);
|
||||||
|
|
||||||
|
Button new_addr = findViewById(R.id.btn_delivery_add);
|
||||||
|
new_addr.setOnClickListener(new View.OnClickListener() {
|
||||||
|
public void onClick(View v) {
|
||||||
|
Intent intent = new Intent(DeliverActivity.this,
|
||||||
|
DetailDeliveryActivity.class);
|
||||||
|
startActivity(intent);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
//查询数据
|
||||||
|
myDbHelper = new MySQLiteOpenHelper(DeliverActivity.this);
|
||||||
|
db = myDbHelper.getReadableDatabase();
|
||||||
|
Cursor cursor = db.query(
|
||||||
|
DeliveryAdr.DeliveryEntry.TABLE_NAME,
|
||||||
|
null, null, null, null, null, null);
|
||||||
|
|
||||||
|
int nameIndex = cursor.getColumnIndex(
|
||||||
|
DeliveryAdr.DeliveryEntry.COLUMN_PEOPLE_NAME);
|
||||||
|
int teleIndex = cursor.getColumnIndex(
|
||||||
|
DeliveryAdr.DeliveryEntry.COLUMN_PEOPLE_TELE);
|
||||||
|
int adrIndex = cursor.getColumnIndex(
|
||||||
|
DeliveryAdr.DeliveryEntry.COLUMN_DETAIL_ADR);
|
||||||
|
int swIndex = cursor.getColumnIndex(
|
||||||
|
DeliveryAdr.DeliveryEntry.COLUMN_IS_RAW);
|
||||||
|
|
||||||
|
while (cursor.moveToNext()) {
|
||||||
|
Delivery delivers = new Delivery();
|
||||||
|
|
||||||
|
String name = cursor.getString(nameIndex);
|
||||||
|
String tel = cursor.getString(teleIndex);
|
||||||
|
String adr = cursor.getString(adrIndex);
|
||||||
|
String sw = cursor.getString(swIndex);
|
||||||
|
|
||||||
|
|
||||||
|
delivers.setReceiver(name);
|
||||||
|
delivers.setPhone(tel);
|
||||||
|
delivers.setLocation(adr);
|
||||||
|
deliList.add(delivers);
|
||||||
|
}
|
||||||
|
DeliverysAdapter deliAdapter = new DeliverysAdapter(
|
||||||
|
DeliverActivity.this,
|
||||||
|
R.layout.item_delivery,
|
||||||
|
deliList);
|
||||||
|
ListView lvdelisList = findViewById(R.id.rv_delivery);
|
||||||
|
|
||||||
|
lvdelisList.setAdapter(deliAdapter);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,67 @@
|
|||||||
|
package com.android.activity;
|
||||||
|
|
||||||
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
|
import androidx.appcompat.widget.SwitchCompat;
|
||||||
|
|
||||||
|
import android.content.ContentValues;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.database.sqlite.SQLiteDatabase;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.util.Log;
|
||||||
|
import android.view.View;
|
||||||
|
import android.widget.Button;
|
||||||
|
import android.widget.EditText;
|
||||||
|
import android.widget.TextView;
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
import com.android.R;
|
||||||
|
import com.android.SQL.MySQLiteOpenHelper;
|
||||||
|
import com.android.bean.DeliveryAdr;
|
||||||
|
|
||||||
|
public class DetailDeliveryActivity extends AppCompatActivity {
|
||||||
|
|
||||||
|
MySQLiteOpenHelper myDbHelper;
|
||||||
|
SQLiteDatabase db;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
setContentView(R.layout.activity_delivery_detail);
|
||||||
|
|
||||||
|
myDbHelper = new MySQLiteOpenHelper(DetailDeliveryActivity.this);
|
||||||
|
db = myDbHelper.getReadableDatabase();
|
||||||
|
|
||||||
|
Toast.makeText(this, "创建数据库", Toast.LENGTH_SHORT).show();
|
||||||
|
|
||||||
|
|
||||||
|
EditText evtel = findViewById(R.id.et_delivery_phone);
|
||||||
|
EditText evname = findViewById(R.id.et_delivery_receiver);
|
||||||
|
EditText evloc = findViewById(R.id.et_delivery_location);
|
||||||
|
SwitchCompat scdef = findViewById(R.id.sc_delivery_default);
|
||||||
|
Button btsave = findViewById(R.id.btn_save);
|
||||||
|
|
||||||
|
btsave.setOnClickListener(new View.OnClickListener() {
|
||||||
|
public void onClick(View v) {
|
||||||
|
ContentValues values = new ContentValues();
|
||||||
|
values.put(DeliveryAdr.DeliveryEntry.COLUMN_PEOPLE_NAME ,
|
||||||
|
evname.getText().toString());
|
||||||
|
values.put(DeliveryAdr.DeliveryEntry.COLUMN_PEOPLE_TELE,
|
||||||
|
evtel.getText().toString());
|
||||||
|
values.put(DeliveryAdr.DeliveryEntry.COLUMN_DETAIL_ADR ,
|
||||||
|
evloc.getText().toString());
|
||||||
|
if(scdef.isChecked())
|
||||||
|
values.put(DeliveryAdr.DeliveryEntry.COLUMN_IS_RAW ,
|
||||||
|
"true");
|
||||||
|
else
|
||||||
|
values.put(DeliveryAdr.DeliveryEntry.COLUMN_IS_RAW ,
|
||||||
|
"false");
|
||||||
|
long r = db.insert(
|
||||||
|
DeliveryAdr.DeliveryEntry.TABLE_NAME,
|
||||||
|
null,
|
||||||
|
values);
|
||||||
|
db.close();
|
||||||
|
Log.e("TAG", "保存数据");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,47 @@
|
|||||||
|
package com.android.activity.adapter;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
import android.widget.ArrayAdapter;
|
||||||
|
import android.widget.ImageView;
|
||||||
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import com.android.R;
|
||||||
|
import com.android.activity.DeliverActivity;
|
||||||
|
import com.android.model.Delivery;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class DeliverysAdapter extends ArrayAdapter<Delivery> {
|
||||||
|
|
||||||
|
|
||||||
|
private List<Delivery> mNewsData;
|
||||||
|
private Context mContext;
|
||||||
|
private int resourceId;
|
||||||
|
|
||||||
|
public DeliverysAdapter(Context context, int resourceId, List<Delivery> data) {
|
||||||
|
super(context, resourceId, data);
|
||||||
|
this.mContext = context;
|
||||||
|
this.mNewsData = data;
|
||||||
|
this.resourceId = resourceId;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public View getView(int position, View convertView, ViewGroup parent) {
|
||||||
|
Delivery deliverys = getItem(position);
|
||||||
|
View view ;
|
||||||
|
|
||||||
|
view = LayoutInflater.from(getContext()).inflate(resourceId, parent, false);
|
||||||
|
|
||||||
|
TextView tvreceiver = view.findViewById(R.id.tv_delivery_receiver);
|
||||||
|
TextView tvphone = view.findViewById(R.id.tv_delivery_phone);
|
||||||
|
TextView tvloc = view.findViewById(R.id.tv_delivery_location);
|
||||||
|
|
||||||
|
tvreceiver.setText(deliverys.getReceiver());
|
||||||
|
tvphone.setText(deliverys.getPhone());
|
||||||
|
tvloc.setText(deliverys.getLocation());
|
||||||
|
return view;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,16 @@
|
|||||||
|
package com.android.bean;
|
||||||
|
|
||||||
|
import android.provider.BaseColumns;
|
||||||
|
|
||||||
|
public final class DeliveryAdr {
|
||||||
|
|
||||||
|
private DeliveryAdr() {}
|
||||||
|
|
||||||
|
public static class DeliveryEntry implements BaseColumns {
|
||||||
|
public static final String TABLE_NAME = "tbl_deli";
|
||||||
|
public static final String COLUMN_PEOPLE_NAME = "rece_people";
|
||||||
|
public static final String COLUMN_PEOPLE_TELE = "tele";
|
||||||
|
public static final String COLUMN_DETAIL_ADR = "adr";
|
||||||
|
public static final String COLUMN_IS_RAW = "false";
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,119 @@
|
|||||||
|
package com.android.model;
|
||||||
|
|
||||||
|
|
||||||
|
import androidx.appcompat.widget.SwitchCompat;
|
||||||
|
|
||||||
|
public class Delivery {
|
||||||
|
|
||||||
|
private int id;
|
||||||
|
private String account;
|
||||||
|
private String receiver;
|
||||||
|
private String phone;
|
||||||
|
private String province;
|
||||||
|
private String city;
|
||||||
|
private String district;
|
||||||
|
private String location;
|
||||||
|
private SwitchCompat defaults;
|
||||||
|
|
||||||
|
public Delivery() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public Delivery(int id, String account, String receiver, String phone, String province, String city, String district, String location, SwitchCompat defaults) {
|
||||||
|
this.id = id;
|
||||||
|
this.account = account;
|
||||||
|
this.receiver = receiver;
|
||||||
|
this.phone = phone;
|
||||||
|
this.province = province;
|
||||||
|
this.city = city;
|
||||||
|
this.district = district;
|
||||||
|
this.location = location;
|
||||||
|
this.defaults = defaults;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(int id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getAccount() {
|
||||||
|
return account;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAccount(String account) {
|
||||||
|
this.account = account;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getReceiver() {
|
||||||
|
return receiver;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setReceiver(String receiver) {
|
||||||
|
this.receiver = receiver;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPhone() {
|
||||||
|
return phone;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPhone(String phone) {
|
||||||
|
this.phone = phone;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getProvince() {
|
||||||
|
return province;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setProvince(String province) {
|
||||||
|
this.province = province;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getCity() {
|
||||||
|
return city;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCity(String city) {
|
||||||
|
this.city = city;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDistrict() {
|
||||||
|
return district;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDistrict(String district) {
|
||||||
|
this.district = district;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getLocation() {
|
||||||
|
return location;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLocation(String location) {
|
||||||
|
this.location = location;
|
||||||
|
}
|
||||||
|
|
||||||
|
public SwitchCompat getDefaults() {
|
||||||
|
return defaults;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDefaults(SwitchCompat defaults) {
|
||||||
|
this.defaults = defaults;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "Delivery{" +
|
||||||
|
"id=" + id +
|
||||||
|
", account='" + account + '\'' +
|
||||||
|
", receiver='" + receiver + '\'' +
|
||||||
|
", phone='" + phone + '\'' +
|
||||||
|
", province='" + province + '\'' +
|
||||||
|
", city='" + city + '\'' +
|
||||||
|
", district='" + district + '\'' +
|
||||||
|
", location='" + location + '\'' +
|
||||||
|
", defaults=" + defaults +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
|
}
|
After Width: | Height: | Size: 2.5 KiB |
After Width: | Height: | Size: 2.2 KiB |
After Width: | Height: | Size: 2.6 KiB |
@ -0,0 +1,34 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<resources>
|
||||||
|
<declare-styleable name="CustomToolBar">
|
||||||
|
<attr name="left_btn_visible" format="boolean"/>
|
||||||
|
<attr name="left_btn_src" format="reference|color"/>
|
||||||
|
<attr name="left_tv_visible" format="boolean"/>
|
||||||
|
<attr name="left_tv_text" format="string"/>
|
||||||
|
<attr name="right_btn_visible" format="boolean"/>
|
||||||
|
<attr name="right_btn_src" format="reference|color"/>
|
||||||
|
<attr name="right_tv_visible" format="boolean"/>
|
||||||
|
<attr name="right_tv_text" format="string"/>
|
||||||
|
<attr name="title_visible" format="boolean"/>
|
||||||
|
<attr name="title_text" format="string"/>
|
||||||
|
<attr name="barBackground" format="color|reference"/>
|
||||||
|
</declare-styleable>
|
||||||
|
|
||||||
|
<declare-styleable name="CircleImageView">
|
||||||
|
<attr name="border_width" format="dimension" />
|
||||||
|
<attr name="border_color" format="color" />
|
||||||
|
</declare-styleable>
|
||||||
|
|
||||||
|
<!-- 自定义TextView -->
|
||||||
|
<declare-styleable name="RichText">
|
||||||
|
<attr name="drawable_src" format="reference" />
|
||||||
|
<attr name="drawable_height" format="dimension" />
|
||||||
|
<attr name="drawable_width" format="dimension" />
|
||||||
|
<attr name="drawable_location">
|
||||||
|
<enum name="left" value="1" />
|
||||||
|
<enum name="top" value="2" />
|
||||||
|
<enum name="right" value="3" />
|
||||||
|
<enum name="bottom" value="4" />
|
||||||
|
</attr>
|
||||||
|
</declare-styleable>
|
||||||
|
</resources>
|
Loading…
Reference in new issue