diff --git a/实验六/.gitignore b/实验六/.gitignore new file mode 100644 index 0000000..aa724b7 --- /dev/null +++ b/实验六/.gitignore @@ -0,0 +1,15 @@ +*.iml +.gradle +/local.properties +/.idea/caches +/.idea/libraries +/.idea/modules.xml +/.idea/workspace.xml +/.idea/navEditor.xml +/.idea/assetWizardSettings.xml +.DS_Store +/build +/captures +.externalNativeBuild +.cxx +local.properties diff --git a/实验六/.idea/.gitignore b/实验六/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/实验六/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/实验六/.idea/compiler.xml b/实验六/.idea/compiler.xml new file mode 100644 index 0000000..b589d56 --- /dev/null +++ b/实验六/.idea/compiler.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/实验六/.idea/deploymentTargetDropDown.xml b/实验六/.idea/deploymentTargetDropDown.xml new file mode 100644 index 0000000..0c0c338 --- /dev/null +++ b/实验六/.idea/deploymentTargetDropDown.xml @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file diff --git a/实验六/.idea/gradle.xml b/实验六/.idea/gradle.xml new file mode 100644 index 0000000..0897082 --- /dev/null +++ b/实验六/.idea/gradle.xml @@ -0,0 +1,19 @@ + + + + + + + \ No newline at end of file diff --git a/实验六/.idea/migrations.xml b/实验六/.idea/migrations.xml new file mode 100644 index 0000000..f8051a6 --- /dev/null +++ b/实验六/.idea/migrations.xml @@ -0,0 +1,10 @@ + + + + + + \ No newline at end of file diff --git a/实验六/.idea/misc.xml b/实验六/.idea/misc.xml new file mode 100644 index 0000000..0ad17cb --- /dev/null +++ b/实验六/.idea/misc.xml @@ -0,0 +1,10 @@ + + + + + + + + + \ No newline at end of file diff --git a/实验六/app/.gitignore b/实验六/app/.gitignore new file mode 100644 index 0000000..42afabf --- /dev/null +++ b/实验六/app/.gitignore @@ -0,0 +1 @@ +/build \ No newline at end of file diff --git a/实验六/app/build.gradle.kts b/实验六/app/build.gradle.kts new file mode 100644 index 0000000..de530ef --- /dev/null +++ b/实验六/app/build.gradle.kts @@ -0,0 +1,46 @@ +plugins { + alias(libs.plugins.androidApplication) +} + +android { + namespace = "com.example.my" + compileSdk = 34 + + defaultConfig { + applicationId = "com.example.my" + minSdk = 24 + targetSdk = 34 + versionCode = 1 + versionName = "1.0" + + testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" + } + + buildTypes { + release { + isMinifyEnabled = false + proguardFiles( + getDefaultProguardFile("proguard-android-optimize.txt"), + "proguard-rules.pro" + ) + } + } + compileOptions { + sourceCompatibility = JavaVersion.VERSION_1_8 + targetCompatibility = JavaVersion.VERSION_1_8 + } + buildFeatures { + aidl = true + } +} + +dependencies { + + implementation(libs.appcompat) + implementation(libs.material) + implementation(libs.activity) + implementation(libs.constraintlayout) + testImplementation(libs.junit) + androidTestImplementation(libs.ext.junit) + androidTestImplementation(libs.espresso.core) +} \ No newline at end of file diff --git a/实验六/app/proguard-rules.pro b/实验六/app/proguard-rules.pro new file mode 100644 index 0000000..481bb43 --- /dev/null +++ b/实验六/app/proguard-rules.pro @@ -0,0 +1,21 @@ +# Add project specific ProGuard rules here. +# You can control the set of applied configuration files using the +# proguardFiles setting in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile \ No newline at end of file diff --git a/实验六/app/src/androidTest/java/com/example/my/ExampleInstrumentedTest.java b/实验六/app/src/androidTest/java/com/example/my/ExampleInstrumentedTest.java new file mode 100644 index 0000000..962e700 --- /dev/null +++ b/实验六/app/src/androidTest/java/com/example/my/ExampleInstrumentedTest.java @@ -0,0 +1,26 @@ +package com.example.my; + +import android.content.Context; + +import androidx.test.platform.app.InstrumentationRegistry; +import androidx.test.ext.junit.runners.AndroidJUnit4; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import static org.junit.Assert.*; + +/** + * Instrumented test, which will execute on an Android device. + * + * @see Testing documentation + */ +@RunWith(AndroidJUnit4.class) +public class ExampleInstrumentedTest { + @Test + public void useAppContext() { + // Context of the app under test. + Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext(); + assertEquals("com.example.my", appContext.getPackageName()); + } +} \ No newline at end of file diff --git a/实验六/app/src/main/AndroidManifest.xml b/实验六/app/src/main/AndroidManifest.xml new file mode 100644 index 0000000..66d6fb6 --- /dev/null +++ b/实验六/app/src/main/AndroidManifest.xml @@ -0,0 +1,48 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/实验六/app/src/main/java/com/example/my/Adapter/LeftListAdapter.java b/实验六/app/src/main/java/com/example/my/Adapter/LeftListAdapter.java new file mode 100644 index 0000000..87918dd --- /dev/null +++ b/实验六/app/src/main/java/com/example/my/Adapter/LeftListAdapter.java @@ -0,0 +1,88 @@ +package com.example.my.Adapter; + +import android.annotation.SuppressLint; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.TextView; + +import androidx.annotation.NonNull; +import androidx.recyclerview.widget.RecyclerView; + +import com.example.my.R; + +import java.util.ArrayList; +import java.util.List; + +public class LeftListAdapter extends RecyclerView.Adapter { + + private List dataList = new ArrayList<>(); + + private int currentIndex=0; + + public LeftListAdapter(List dataList) { + this.dataList = dataList; + } + + @NonNull + @Override + public MyHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { + View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.left_list_item, null); + return new MyHolder(view); + } + + @Override + @SuppressLint("RecyclerView") + public void onBindViewHolder(@NonNull MyHolder holder, int position) { + //绑定数据 + String name = dataList.get(position); + holder.name.setText(name); + + //分类的点击事件 + holder.itemView.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + if (null != mLeftListOnClickItemListener) { + mLeftListOnClickItemListener.onItemClick(position); + } + } + }); + + if (currentIndex == position) { + holder.itemView.setBackgroundResource(R.drawable.type_select_bg); + }else { + holder.itemView.setBackgroundResource(R.drawable.type_selected_no); + } + } + + @Override + public int getItemCount() { + return dataList.size(); + } + + static class MyHolder extends RecyclerView.ViewHolder { + TextView name; + + public MyHolder(@NonNull View itemView) { + super(itemView); + name = itemView.findViewById(R.id.name); + } + } + + private LeftListOnClickItemListener mLeftListOnClickItemListener; + + + public void setmLeftListOnClickItemListener(LeftListOnClickItemListener mLeftListOnClickItemListener) { + this.mLeftListOnClickItemListener = mLeftListOnClickItemListener; + } + + public interface LeftListOnClickItemListener { + void onItemClick(int position); + } + + public void setCurrentIndex(int position) { + this.currentIndex = position; + notifyDataSetChanged(); + } + +} diff --git a/实验六/app/src/main/java/com/example/my/Adapter/RightListAdapter.java b/实验六/app/src/main/java/com/example/my/Adapter/RightListAdapter.java new file mode 100644 index 0000000..ea4f3dd --- /dev/null +++ b/实验六/app/src/main/java/com/example/my/Adapter/RightListAdapter.java @@ -0,0 +1,67 @@ +package com.example.my.Adapter; + +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.ImageView; +import android.widget.TextView; + +import androidx.annotation.NonNull; +import androidx.recyclerview.widget.RecyclerView; + +import com.example.my.R; +import com.example.my.entity.ProductInfo; + +import java.util.ArrayList; +import java.util.List; + +public class RightListAdapter extends RecyclerView.Adapter { + + private List mProductInfo = new ArrayList<>(); + + public void setListData(List list) { + this.mProductInfo = list; + //刷新 + notifyDataSetChanged(); + } + + @NonNull + @Override + public MyHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { + View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.right_list_item, null); + return new MyHolder(view); + + } + + @Override + public void onBindViewHolder(@NonNull MyHolder holder, int position) { + //绑定数据 + ProductInfo productInfo = mProductInfo.get(position); + holder.pro_img.setImageResource(productInfo.getImg()); + holder.pro_title.setText(productInfo.getTitle()); + holder.pro_detail.setText(productInfo.getDetails()); + holder.pro_price.setText("¥" + productInfo.getPrice()); //int+String 变成文本类型 + + } + + @Override + public int getItemCount() { + return mProductInfo.size(); + } + + static class MyHolder extends RecyclerView.ViewHolder { + ImageView pro_img; + TextView pro_title; + TextView pro_detail; + TextView pro_price; + + public MyHolder(@NonNull View itemView) { + super(itemView); + pro_img = itemView.findViewById(R.id.pro_img); + pro_title = itemView.findViewById(R.id.pro_title); + pro_detail = itemView.findViewById(R.id.pro_detail); + pro_price = itemView.findViewById(R.id.pro_price); + + } + } +} diff --git a/实验六/app/src/main/java/com/example/my/BlankActivity.java b/实验六/app/src/main/java/com/example/my/BlankActivity.java new file mode 100644 index 0000000..3861daa --- /dev/null +++ b/实验六/app/src/main/java/com/example/my/BlankActivity.java @@ -0,0 +1,61 @@ +package com.example.my; + +import android.content.Intent; +import android.database.sqlite.SQLiteDatabase; +import android.os.Bundle; +import android.view.View; +import android.widget.Button; + +import androidx.appcompat.app.AppCompatActivity; + +public class BlankActivity extends AppCompatActivity implements View.OnClickListener { + + public MySQLiteOpenHelper user; + public SQLiteDatabase sqL_read; + private Button search_del_btn, insert_btn, update_btn; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_blank); + user = new MySQLiteOpenHelper(BlankActivity.this); + System.out.println("userDB=" + user); + /*只有调用getReadableDatabase()或者getWriteableDatabase()函数后才能返回一个SQLiteDatabase对象*/ + sqL_read = user.getReadableDatabase(); + System.out.println("sqLiteDatabase=" + sqL_read); + + init(); + } + + //组件初始化方法 + public void init() { + search_del_btn = findViewById(R.id.search_delete); + insert_btn = findViewById(R.id.add); + update_btn = findViewById(R.id.update); + //添加监听 + search_del_btn.setOnClickListener(this); + insert_btn.setOnClickListener(this); + update_btn.setOnClickListener(this); + } + + @Override + public void onClick(View view) { + Intent intent; + if (view.getId() == R.id.search_delete) { + intent = new Intent(BlankActivity.this, Sea_deluser_Activity.class); + startActivity(intent); + } else if (view.getId() == R.id.add) { + intent = new Intent(BlankActivity.this, RegisterActivity.class); + startActivity(intent); + } else if (view.getId() == R.id.update) { + intent = new Intent(BlankActivity.this, Updareuser_Activity.class); + startActivity(intent); + } else if (view.getId() == R.id.button){ + intent = new Intent(BlankActivity.this, MainActivity.class); + startActivity(intent); + } + else{ + //默认情况 + } + } +} \ No newline at end of file diff --git a/实验六/app/src/main/java/com/example/my/LoginActivity.java b/实验六/app/src/main/java/com/example/my/LoginActivity.java new file mode 100644 index 0000000..9437bf7 --- /dev/null +++ b/实验六/app/src/main/java/com/example/my/LoginActivity.java @@ -0,0 +1,80 @@ +package com.example.my; + +import android.annotation.SuppressLint; +import android.content.Intent; +import android.os.Bundle; +import android.view.View; +import android.widget.Button; +import android.widget.EditText; +import android.widget.TextView; +import android.widget.Toast; + +import androidx.activity.EdgeToEdge; +import androidx.appcompat.app.AppCompatActivity; +import androidx.core.graphics.Insets; +import androidx.core.view.ViewCompat; +import androidx.core.view.WindowInsetsCompat; + +import com.example.my.entity.User; + +public class LoginActivity extends AppCompatActivity implements View.OnClickListener { + private TextView register, login; + private EditText username, password; + private MySQLiteOpenHelper mySQLiteOpenHelper; + + @Override + protected void onCreate(Bundle savedInstanceState) { + mySQLiteOpenHelper = new MySQLiteOpenHelper(this); + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_login); + find(); + + } + public void find(){ + login = findViewById(R.id.login); + register = findViewById(R.id.register); + username = findViewById(R.id.userEdit); + password = findViewById(R.id.passEdit); + login.setOnClickListener(this); + register.setOnClickListener(this); + } + @Override + public void onClick(View v) { + if (v.getId() == R.id.login) { + String n = username.getText().toString(); + String p = password.getText().toString(); + if (n.equals("")) { + Toast.makeText(this, "请输入账号", Toast.LENGTH_SHORT).show(); + } else if (p.equals("")) { + Toast.makeText(this, "请输入密码", Toast.LENGTH_SHORT).show(); + } else { + boolean login = mySQLiteOpenHelper.login(n, p); + if (login) { + Toast.makeText(this, "登录成功!", Toast.LENGTH_SHORT).show(); + User select = mySQLiteOpenHelper.select(n); + Intent home = new Intent(LoginActivity.this, MainActivity.class); + Bundle bundle = new Bundle(); + bundle.putString("username", select.username); + bundle.putString("emil", select.email); + bundle.putString("phone", select.phone); + home.putExtras(bundle); + username.setText(""); + password.setText(""); + startActivity(home); + } else { + Toast.makeText(this, "账号或密码错误,请重新输入", Toast.LENGTH_SHORT).show(); + password.setText(""); + } + } + } + else if(v.getId()==R.id.register){ + Intent re = new Intent(LoginActivity.this, RegisterActivity.class); + startActivity(re); + } + } + @Override + public void onPointerCaptureChanged(boolean hasCapture) { + super.onPointerCaptureChanged(hasCapture); + } + +} diff --git a/实验六/app/src/main/java/com/example/my/MainActivity.java b/实验六/app/src/main/java/com/example/my/MainActivity.java new file mode 100644 index 0000000..eda5ff9 --- /dev/null +++ b/实验六/app/src/main/java/com/example/my/MainActivity.java @@ -0,0 +1,124 @@ +package com.example.my; + +import android.app.FragmentTransaction; +import android.content.Intent; +import android.os.Bundle; +import android.view.MenuItem; + +import androidx.activity.EdgeToEdge; +import androidx.annotation.NonNull; +import androidx.appcompat.app.AppCompatActivity; +import androidx.core.graphics.Insets; +import androidx.core.view.ViewCompat; +import androidx.core.view.WindowInsetsCompat; + +import com.example.my.fragment.BlankFragment; +import com.example.my.fragment.ChatFragment; +import com.example.my.fragment.HomeFragment; +import com.example.my.fragment.RegFragment; +import com.example.my.fragment.SearchFragment; +import com.google.android.material.bottomnavigation.BottomNavigationView; + +public class MainActivity extends AppCompatActivity { + + private HomeFragment homeFragment; + private ChatFragment chatFragment; + private SearchFragment searchFragment; + private RegFragment regFragment; + private BlankFragment blankFragment; + + private BottomNavigationView bottomNavigationView; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_main); + + //初始化控件 + bottomNavigationView = findViewById(R.id.BottomNavigation); + //bottomNavigationView设置点击事件 + bottomNavigationView.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() { + @Override + public boolean onNavigationItemSelected(@NonNull MenuItem menuItem) { + if (menuItem.getItemId() == R.id.home) { + selectedFragment(0); + } else if (menuItem.getItemId() == R.id.chat) { + selectedFragment(1); + } else if (menuItem.getItemId() == R.id.search) { + selectedFragment(2); + } else if (menuItem.getItemId() == R.id.reg) { + selectedFragment(3); + } else { + selectedFragment(4); + } + return true; + } + }); + //默认首页选中 + selectedFragment(0); + } + + + private void selectedFragment(int position) { + androidx.fragment.app.FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction(); + hideFragment(fragmentTransaction); + if (position == 0) { + if (homeFragment == null) { + homeFragment = new HomeFragment(); + fragmentTransaction.add(R.id.content, homeFragment); + } else { + fragmentTransaction.show(homeFragment); + } + } else if (position == 1) { + if (chatFragment == null) { + chatFragment = new ChatFragment(); + fragmentTransaction.add(R.id.content, chatFragment); + } else { + fragmentTransaction.show(chatFragment); + } + } else if (position == 2) { + if (searchFragment == null) { + searchFragment = new SearchFragment(); + fragmentTransaction.add(R.id.content, searchFragment); + } else { + fragmentTransaction.show(searchFragment); + } + } else if (position == 3) { + if (regFragment == null) { + regFragment = new RegFragment(); + fragmentTransaction.add(R.id.content, regFragment); + } else { + fragmentTransaction.show(regFragment); + } + } else { + if (blankFragment == null) { + blankFragment = new BlankFragment(); + fragmentTransaction.add(R.id.content, blankFragment); + } else { + fragmentTransaction.show(blankFragment); + } + } + + //提交 + fragmentTransaction.commit(); + + } + + private void hideFragment(androidx.fragment.app.FragmentTransaction fragmentTransaction) { + if (homeFragment != null) { + fragmentTransaction.hide(homeFragment); + } + if (chatFragment != null) { + fragmentTransaction.hide(chatFragment); + } + if (searchFragment != null) { + fragmentTransaction.hide(searchFragment); + } + if (regFragment != null) { + fragmentTransaction.hide(regFragment); + } + if (blankFragment != null) { + fragmentTransaction.hide(blankFragment); + } + } +} diff --git a/实验六/app/src/main/java/com/example/my/MySQLiteOpenHelper.java b/实验六/app/src/main/java/com/example/my/MySQLiteOpenHelper.java new file mode 100644 index 0000000..44a67b6 --- /dev/null +++ b/实验六/app/src/main/java/com/example/my/MySQLiteOpenHelper.java @@ -0,0 +1,172 @@ +package com.example.my; + + +import android.annotation.SuppressLint; +import android.content.ContentValues; +import android.content.Context; +import android.database.Cursor; +import android.database.sqlite.SQLiteConstraintException; +import android.database.sqlite.SQLiteDatabase; +import android.database.sqlite.SQLiteOpenHelper; +import android.util.Log; + +import androidx.annotation.Nullable; + +import com.example.my.entity.User; + +import java.util.ArrayList; +import java.util.List; + +public class MySQLiteOpenHelper extends SQLiteOpenHelper { + + //数据库名字 + private static final String DATABASE_NAME = "mydatabase"; + private static final int DATABASE_VERSION = 1; + private static final String TABLE_USERS = "users"; + private static final String COLUMN_ID = "id"; + private static final String COLUMN_USERNAME = "username"; + private static final String COLUMN_EMAIL = "email"; + private static final String COLUMN_PHONE = "phone"; + private static final String COLUMN_PASSWORD = "password"; + + // 数据库创建语句 + private static final String DATABASE_CREATE = + "CREATE TABLE " + TABLE_USERS + " (" + + COLUMN_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, " + + COLUMN_USERNAME + " TEXT NOT NULL, " + + COLUMN_EMAIL + " TEXT NOT NULL, " + + COLUMN_PHONE + " TEXT NOT NULL, " + + COLUMN_PASSWORD + " TEXT NOT NULL);"; + + public MySQLiteOpenHelper(Context context) { + super(context, DATABASE_NAME, null, DATABASE_VERSION); + } + + @Override + public void onCreate(SQLiteDatabase database) { + database.execSQL(DATABASE_CREATE); + } + + @Override + public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { + + } + + public long register(User user) { + SQLiteDatabase db = getWritableDatabase(); + ContentValues values = new ContentValues(); + values.put("username", user.getUsername()); + values.put("password", user.getPassword()); + values.put("phone", user.getPhone()); + values.put("email", user.getEmil()); + + try { + long userId = db.insert("users", null, values); + // 添加日志记录以便调试 + Log.d("Register", "New user inserted with ID: " + userId); + return userId; + } catch (SQLiteConstraintException e) { + // 处理主键冲突等异常 + Log.e("Register", "Error inserting new user: " + e.getMessage()); + return -1; + } catch (Exception e) { + // 处理其他可能的异常 + Log.e("Register", "Error inserting new user: " + e.getMessage()); + return -1; + } + } + + //登录方法实现 + public boolean login(String username, String password) { + SQLiteDatabase db = getWritableDatabase(); + boolean result = false; + Cursor users = db.query("users", null, "username like?", new String[]{username}, null, null, null); + if (users != null) { + while (users.moveToNext()) { + @SuppressLint("Range") String username1 = users.getString(users.getColumnIndex("username")); + Log.i("users", "login: " + username1); + @SuppressLint("Range") String password1 = users.getString(users.getColumnIndex("password")); + Log.i("users", "login: " + password1); + // 假设我们在这里验证密码 + if (password1.equals(password)) { + result = true; + break; // 找到匹配的用户名和密码,退出循环 + } + } + users.close(); + } + return result; + } + + //根据用户名查找当前登录用户信息 + public User select(String username) { + SQLiteDatabase db = getWritableDatabase(); + User SelectUser = new User(); + Cursor user = db.query("users", new String[]{"username", "phone", "email"}, "username=?", new String[]{username}, null, null, null); + while (user.moveToNext()) { + @SuppressLint("Range") String uname = user.getString(user.getColumnIndex("username")); + @SuppressLint("Range") String phone = user.getString(user.getColumnIndex("phone")); + @SuppressLint("Range") String email = user.getString(user.getColumnIndex("email")); + SelectUser.setUsername(uname); + SelectUser.setPhone(phone); + SelectUser.setEmail(email); + } + user.close(); + return SelectUser; + } + + public void adddata(SQLiteDatabase sqLiteDatabase, String username, String paswd, String email, String phone) { + ContentValues values = new ContentValues(); + values.put("username", username); + values.put("paswd", paswd); + values.put("email", email); + values.put("phone", phone); + sqLiteDatabase.insert("users", null, values); + sqLiteDatabase.close(); + } + + //删除数据 + public void delete(SQLiteDatabase sqLiteDatabase, int id) { + /*第一个参数:表名;第二个参数:需要删除的属性名,?代表占位符;第三个参数:属性名的属性值*/ + sqLiteDatabase.delete("users", "id=?", new String[]{id + ""}); + sqLiteDatabase.close(); + } + + //更新数据 + public void update(SQLiteDatabase sqLiteDatabase, int id, String username, + String paswd, String phone, int email) { + //创建一个ContentValues对象 + ContentValues values = new ContentValues(); + //以键值对的形式插入 + values.put("username", username); + values.put("paswd", paswd); + values.put("phone", phone); + values.put("email", email); + //执行修改的方法 + sqLiteDatabase.update("users", values, "id=?", new String[]{id + ""}); + sqLiteDatabase.close(); + } + + //查询数据 + public List querydata(SQLiteDatabase sqLiteDatabase) { + Cursor cursor = sqLiteDatabase.query("users", null, null, null, null, null, "id ASC"); + List list = new ArrayList(); + while (cursor.moveToNext()) { + @SuppressLint("Range") int id = cursor.getInt(cursor.getColumnIndex("id")); + Log.i("SQLite", "id=" + id); + String username = cursor.getString(0); + Log.i("SQLite", "username=" + username); + String paswd = cursor.getString(1); + Log.i("SQLite", "paswd=" + paswd); + String phone = cursor.getString(2); + Log.i("SQLite", "phone=" + phone); + String email = cursor.getString(4); + Log.i("SQLite", "email=" + email); + list.add(new User(id, username, paswd, phone, email)); + } + cursor.close(); + sqLiteDatabase.close(); + return list; + } + +} \ No newline at end of file diff --git a/实验六/app/src/main/java/com/example/my/RegisterActivity.java b/实验六/app/src/main/java/com/example/my/RegisterActivity.java new file mode 100644 index 0000000..1a5f200 --- /dev/null +++ b/实验六/app/src/main/java/com/example/my/RegisterActivity.java @@ -0,0 +1,105 @@ +package com.example.my; + +import android.content.Intent; +import android.os.Bundle; +import android.view.View; +import android.widget.Button; +import android.widget.EditText; +import android.widget.Toast; + +import androidx.activity.EdgeToEdge; +import androidx.appcompat.app.AppCompatActivity; + +import com.example.my.entity.User; + +public class RegisterActivity extends AppCompatActivity implements View.OnClickListener { + + private String name_str = ""; + private String phone_str = " "; + private String email_str = " "; + private String paswd_str = " "; + EditText name_edit, phone_edit, email_edit, paswd_edit; + Button button; + //使用MySQLiteOpenHelper类中的方法 + private MySQLiteOpenHelper mySQLiteOpenHelper; + + + //控制注册按钮点击完后不给点击了 + boolean flag = false; + + + @Override + protected void onCreate(Bundle savedInstanceState) { + mySQLiteOpenHelper = new MySQLiteOpenHelper(this); + super.onCreate(savedInstanceState); + EdgeToEdge.enable(this); + setContentView(R.layout.activity_register); + +// 组件初始化 + name_edit = (EditText) findViewById(R.id.nameEdit); + phone_edit = (EditText) findViewById(R.id.pnumEdit); + email_edit = (EditText) findViewById(R.id.userEdit); + paswd_edit = (EditText) findViewById(R.id.passEdit); +// 添加监听事件 + button = (Button) findViewById(R.id.submit); + button.setOnClickListener((View.OnClickListener) this); + } + + @Override + public void onClick(View view) { + if (view.getId() == R.id.submit) { +// name_str = name_edit.getText().toString(); +// phone_str = phone_edit.getText().toString(); +// email_str = email_edit.getText().toString(); +// paswd_str = paswd_edit.getText().toString(); +// Intent intent = new Intent(RegisterActivity.this, RegisterActivity2.class); +// Bundle bundle = new Bundle(); +// bundle.putString("name", name_str); +// bundle.putString("phone", phone_str); +// bundle.putString("email", email_str); +// bundle.putString("paswd", paswd_str); +// intent.putExtras(bundle); +// startActivity(intent); + register(); + gobak(view); + } + } + + public void register(){ + String ru = name_edit.getText().toString(); + String rps = paswd_edit.getText().toString(); + String rph = phone_edit.getText().toString(); + String rem = email_edit.getText().toString(); + User user = new User(ru,rps,rph,rem); + if(ru.equals("")){ + Toast.makeText(this, "账号不能为空!", Toast.LENGTH_SHORT).show(); + } else if (rps.equals("")) { + Toast.makeText(this, "密码不能为空!", Toast.LENGTH_SHORT).show(); + } else if (rph.equals("")) { + Toast.makeText(this, "电话不能为空!", Toast.LENGTH_SHORT).show(); + }else if(rem.equals("")){ + Toast.makeText(this, "邮箱不能为空!", Toast.LENGTH_SHORT).show(); + }else{ + long r1 = mySQLiteOpenHelper.register(user); + button.setEnabled(false); + button.setTextColor(0xFFD0EFC6); + if(r1!=-1){ + Toast.makeText(this, "注册成功", Toast.LENGTH_SHORT).show(); + }else{ + Toast.makeText(this, "注册失败!", Toast.LENGTH_SHORT).show(); + } + } + } + //跳转回登录页面 + public void gobak(View view){ + Intent gl = new Intent(RegisterActivity.this,LoginActivity.class); + startActivity(gl); + } + @Override + public void onPointerCaptureChanged(boolean hasCapture) { + super.onPointerCaptureChanged(hasCapture); + } + + + +} \ No newline at end of file diff --git a/实验六/app/src/main/java/com/example/my/Sea_deluser_Activity.java b/实验六/app/src/main/java/com/example/my/Sea_deluser_Activity.java new file mode 100644 index 0000000..3e78111 --- /dev/null +++ b/实验六/app/src/main/java/com/example/my/Sea_deluser_Activity.java @@ -0,0 +1,104 @@ +package com.example.my; + +import android.app.AlertDialog; +import android.content.DialogInterface; +import android.content.Intent; +import android.database.sqlite.SQLiteDatabase; +import android.os.Bundle; +import android.util.Log; +import android.view.View; +import android.view.Window; +import android.widget.AdapterView; +import android.widget.ArrayAdapter; +import android.widget.ListView; +import android.widget.Toast; + +import androidx.appcompat.app.AppCompatActivity; + +import com.example.my.entity.User; + +import java.util.List; + +public class Sea_deluser_Activity extends AppCompatActivity { + public ListView user_list; + private List list; + private SQLiteDatabase sqLiteDatabase; + //假设数据库用户不超过10个 + private String[] user_mes; + + @Override + protected void onCreate(Bundle savedInstanceState) { + + super.onCreate(savedInstanceState); + Log.i("SQLite","Sea_del"); + requestWindowFeature(Window.FEATURE_NO_TITLE); + setContentView(R.layout.user_search_delete); + user_list=findViewById(R.id.mes); + MySQLiteOpenHelper users=new MySQLiteOpenHelper(Sea_deluser_Activity.this); + sqLiteDatabase=users.getReadableDatabase(); + //获取从数据库查询到的数据 + list=users.querydata(sqLiteDatabase); + Log.i("SQLite","list.size()="+list.size()); + //把获取到的信息添加到用户名数组中 + if (list != null && list.size() > 0) { + // 把获取到的信息添加到用户名数组中 + user_mes = new String[list.size()]; + for (int i = 0; i < list.size(); i++) { + user_mes[i] = list.get(i).getUsername() + " " + + list.get(i).getPassword() + " " + + list.get(i).getPhone() + " " + + list.get(i).getEmil(); + } + + // 把用户名显示在ListView上 + final ArrayAdapter adapter = new ArrayAdapter( + Sea_deluser_Activity.this, android.R.layout.simple_list_item_1, user_mes); + + // 检查user_mes是否为空 + if (user_mes != null && user_mes.length > 0) { + user_list.setAdapter(adapter); + } else { + // user_mes为空的情况处理 + Toast.makeText(Sea_deluser_Activity.this, "没有数据可显示", Toast.LENGTH_SHORT).show(); + } + } else { + // list为空的情况处理 + Toast.makeText(Sea_deluser_Activity.this, "查询没有返回任何数据", Toast.LENGTH_SHORT).show(); + } + + + //为listview每个元素添加点击事件 + user_list.setOnItemClickListener(new AdapterView.OnItemClickListener() { + @Override + public void onItemClick(AdapterView adapterView, View view, int i, long l) { + final int id=list.get(i).getId(); + //弹出一个对话框 + new AlertDialog.Builder(Sea_deluser_Activity.this).setTitle("系统提示") + //设置显示的内容 + .setMessage("确定删除该条数据吗!") + //添加确定按钮 + .setPositiveButton("确定",new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int which) { + //删除数据操作,首先获取到id + MySQLiteOpenHelper user_database=new MySQLiteOpenHelper(Sea_deluser_Activity.this); + SQLiteDatabase sqLiteDatabase=user_database.getWritableDatabase(); + user_database.delete(sqLiteDatabase,id); + refresh(); + Toast.makeText(Sea_deluser_Activity.this,"删除成功",Toast.LENGTH_SHORT).show(); + } + }).setNegativeButton("取消",new DialogInterface.OnClickListener() {//添加返回按钮 + @Override + public void onClick(DialogInterface dialog, int which) { + + } + }).show();//在按键响应事件中显示此对话框 + } + }); + } + //刷新页面方法 + private void refresh() { + finish(); + Intent intent = new Intent(Sea_deluser_Activity.this, Sea_deluser_Activity.class); + startActivity(intent); + } +} diff --git a/实验六/app/src/main/java/com/example/my/Updareuser_Activity.java b/实验六/app/src/main/java/com/example/my/Updareuser_Activity.java new file mode 100644 index 0000000..0435c23 --- /dev/null +++ b/实验六/app/src/main/java/com/example/my/Updareuser_Activity.java @@ -0,0 +1,13 @@ +package com.example.my; + +import android.os.Bundle; + +import androidx.appcompat.app.AppCompatActivity; + +public class Updareuser_Activity extends AppCompatActivity { + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + } +} diff --git a/实验六/app/src/main/java/com/example/my/entity/DataService.java b/实验六/app/src/main/java/com/example/my/entity/DataService.java new file mode 100644 index 0000000..788db18 --- /dev/null +++ b/实验六/app/src/main/java/com/example/my/entity/DataService.java @@ -0,0 +1,37 @@ +package com.example.my.entity; + +import com.example.my.R; + +import java.util.ArrayList; +import java.util.List; + +public class DataService { + + public static List getListData(int position) { + List list = new ArrayList<>(); + if (position == 0) { + list.add(new ProductInfo(0, R.drawable.zz1, "张江碧云苑", "张江集团专浦东地区人员量身定制的服务型租赁社区,坐落于张江高科园南区毗邻中环线申江路段。国企房源,品质有保证", 8500)); + list.add(new ProductInfo(0, R.drawable.zz2, "云湖壹号", "该项目小区规划得分高于90.6%本区同类型物业楼盘,社区内配备了访客系统、可视对讲系统、周界防范警报系统等等", 12000)); + list.add(new ProductInfo(0, R.drawable.zz3, "新江湾城", "该户型拥有270°观景阳台,超明亮采光,小区生活、交通便捷,环境宜人,物业完备", 8233)); + } else if (position == 1) { + list.add(new ProductInfo(0, R.drawable.zz2, "云湖壹号", "该项目小区规划得分高于90.6%本区同类型物业楼盘,社区内配备了访客系统、可视对讲系统、周界防范警报系统等等", 12000)); + list.add(new ProductInfo(0, R.drawable.zz3, "新江湾城", "该户型拥有270°观景阳台,超明亮采光,小区生活、交通便捷,环境宜人,物业完备", 8233)); + } else if (position == 2) { + list.add(new ProductInfo(0, R.drawable.zz1, "张江碧云苑", "张江集团专浦东地区人员量身定制的服务型租赁社区,坐落于张江高科园南区毗邻中环线申江路段。国企房源,品质有保证", 8500)); + list.add(new ProductInfo(0, R.drawable.zz2, "云湖壹号", "该项目小区规划得分高于90.6%本区同类型物业楼盘,社区内配备了访客系统、可视对讲系统、周界防范警报系统等等", 12000)); + list.add(new ProductInfo(0, R.drawable.zz3, "新江湾城", "该户型拥有270°观景阳台,超明亮采光,小区生活、交通便捷,环境宜人,物业完备", 8233)); + } else if (position == 3) { + list.add(new ProductInfo(0, R.drawable.zz2, "云湖壹号", "该项目小区规划得分高于90.6%本区同类型物业楼盘,社区内配备了访客系统、可视对讲系统、周界防范警报系统等等", 12000)); + list.add(new ProductInfo(0, R.drawable.zz3, "新江湾城", "该户型拥有270°观景阳台,超明亮采光,小区生活、交通便捷,环境宜人,物业完备", 8233)); + + } else if (position == 4) { + list.add(new ProductInfo(0, R.drawable.zz1, "张江碧云苑", "张江集团专浦东地区人员量身定制的服务型租赁社区,坐落于张江高科园南区毗邻中环线申江路段。国企房源,品质有保证", 8500)); + list.add(new ProductInfo(0, R.drawable.zz2, "云湖壹号", "该项目小区规划得分高于90.6%本区同类型物业楼盘,社区内配备了访客系统、可视对讲系统、周界防范警报系统等等", 12000)); + list.add(new ProductInfo(0, R.drawable.zz3, "新江湾城", "该户型拥有270°观景阳台,超明亮采光,小区生活、交通便捷,环境宜人,物业完备", 8233)); + } else if (position == 5) { + list.add(new ProductInfo(0, R.drawable.zz1, "张江碧云苑", "张江集团专浦东地区人员量身定制的服务型租赁社区,坐落于张江高科园南区毗邻中环线申江路段。国企房源,品质有保证", 8500)); + list.add(new ProductInfo(0, R.drawable.zz2, "云湖壹号", "该项目小区规划得分高于90.6%本区同类型物业楼盘,社区内配备了访客系统、可视对讲系统、周界防范警报系统等等", 12000)); + } + return list; + } +} diff --git a/实验六/app/src/main/java/com/example/my/entity/ProductInfo.java b/实验六/app/src/main/java/com/example/my/entity/ProductInfo.java new file mode 100644 index 0000000..6fb2ccc --- /dev/null +++ b/实验六/app/src/main/java/com/example/my/entity/ProductInfo.java @@ -0,0 +1,57 @@ +package com.example.my.entity; + +public class ProductInfo { + private int id; + private int img; + private String title; + private String details; + private int price; + + public ProductInfo(int id, int img, String title, String details, int price) { + this.id = id; + this.img = img; + this.title = title; + this.details = details; + this.price = price; + } + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public int getImg() { + return img; + } + + public void setImg(int img) { + this.img = img; + } + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } + + public String getDetails() { + return details; + } + + public void setDetails(String details) { + this.details = details; + } + + public int getPrice() { + return price; + } + + public void setPrice(int price) { + this.price = price; + } +} diff --git a/实验六/app/src/main/java/com/example/my/entity/User.java b/实验六/app/src/main/java/com/example/my/entity/User.java new file mode 100644 index 0000000..b223b26 --- /dev/null +++ b/实验六/app/src/main/java/com/example/my/entity/User.java @@ -0,0 +1,99 @@ +package com.example.my.entity; + +public class User { + public String username; + public String password; + public String phone; + public String email; + + public String age; + + public String sex; + + public int id; + + public User() { + } + + public User(String username, String password, String phone, String emil) { + this.username = username; + this.password = password; + this.phone = phone; + this.email = emil; + } + + public User(int id,String username, String password, String phone, String emil ) { + this.username = username; + this.password = password; + this.phone = phone; + this.email = emil; + this.id = id; + } + + public String getUsername() { + return username; + } + + public void setUsername(String username) { + this.username = username; + } + + public String getPassword() { + return password; + } + + public void setPassword(String password) { + this.password = password; + } + + public String getPhone() { + return phone; + } + + public void setPhone(String phone) { + this.phone = phone; + } + + public String getEmil() { + return email; + } + + public void setEmail(String email) { + this.email = email; + } + + public String getAge() { + return age; + } + + public void setAge(String age) { + this.age = age; + } + + public String getSex() { + return sex; + } + + public void setSex(String sex) { + this.sex = sex; + } + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + @Override + public String toString() { + return "User{" + + "username='" + username + '\'' + + ", password='" + password + '\'' + + ", phone='" + phone + '\'' + + ", emil='" + email + '\'' + + ", id=" + id + + '}'; + } +} diff --git a/实验六/app/src/main/java/com/example/my/fragment/BlankFragment.java b/实验六/app/src/main/java/com/example/my/fragment/BlankFragment.java new file mode 100644 index 0000000..45e6d82 --- /dev/null +++ b/实验六/app/src/main/java/com/example/my/fragment/BlankFragment.java @@ -0,0 +1,45 @@ +package com.example.my.fragment; + +import android.app.Activity; +import android.app.AlertDialog; +import android.content.DialogInterface; +import android.content.Intent; +import android.database.sqlite.SQLiteDatabase; +import android.os.Bundle; + +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.Button; + +import androidx.fragment.app.Fragment; + +import com.example.my.BlankActivity; +import com.example.my.MySQLiteOpenHelper; +import com.example.my.R; + +public class BlankFragment extends Fragment { + private View rootView; + private Button button; + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + } + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) { + rootView = inflater.inflate(R.layout.fragment_blank, container, false); + //查看用户注册信息 + rootView.findViewById(R.id.more).setOnClickListener(new View.OnClickListener(){ + @Override + public void onClick(View v){ + Intent intent=new Intent(getActivity(), BlankActivity.class); + startActivity(intent); + } + }); + return rootView; + } + +} \ No newline at end of file diff --git a/实验六/app/src/main/java/com/example/my/fragment/ChatFragment.java b/实验六/app/src/main/java/com/example/my/fragment/ChatFragment.java new file mode 100644 index 0000000..0a2769b --- /dev/null +++ b/实验六/app/src/main/java/com/example/my/fragment/ChatFragment.java @@ -0,0 +1,188 @@ +package com.example.my.fragment; + + +import android.content.ComponentName; +import android.content.Context; +import android.content.Intent; +import android.content.ServiceConnection; +import android.os.Bundle; + +import androidx.annotation.Nullable; +import androidx.fragment.app.Fragment; + +import android.os.Handler; +import android.os.IBinder; +import android.os.Looper; +import android.os.Message; +import android.util.Log; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.Button; +import android.widget.EditText; +import android.widget.TextView; + +import com.example.my.R; + +import java.util.Calendar; +import java.util.TimeZone; +import java.util.Timer; +import java.util.TimerTask; + + +public class ChatFragment extends Fragment implements View.OnClickListener, ServiceConnection { + + private View rootView; + EditText etInput; + TextView tvOut; + TextView textView; + Button btnStartService, btnStopService, btnBindService, btnUnbindService, btnSync; + Intent serviceIntent; + MyService.MyBinder binder = null; + + private TextView tvTime; + private Timer timer;//添加计时器 + // private Handler mHandler; + private Calendar mCalendar; + + + + + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) { + rootView = inflater.inflate(R.layout.fragment_chat, container, false); + initComponent(); //初始化组件 + btnClickListener(); //按钮添加事件监听 + serviceIntent = new Intent(getActivity(), MyService.class); + return rootView; + } + + private void initComponent() { + etInput = rootView.findViewById(R.id.etInput); + tvOut = rootView.findViewById(R.id.tvOut); + btnStartService = rootView.findViewById(R.id.btnStartService); + btnStopService = rootView.findViewById(R.id.btnStopService); + btnBindService = rootView.findViewById(R.id.btnBindService); + btnUnbindService = rootView.findViewById(R.id.btnUnBindService); + btnSync = rootView.findViewById(R.id.btnSync); + tvTime= rootView.findViewById(R.id.tv_Time); + textView = rootView.findViewById(R.id.YMD_Time); + timer = new Timer();//创建timer对象 + timer.schedule(new TimerTask() { + @Override + public void run() { +// Log.v("Timer", "run()..."); + mCalendar = Calendar.getInstance(TimeZone.getTimeZone("GMT+08:00")); + + int year = mCalendar.get(Calendar.YEAR); + int month = mCalendar.get(Calendar.MONTH) + 1; // 月份是从0开始的 + int day = mCalendar.get(Calendar.DAY_OF_MONTH); + int hour = mCalendar.get(Calendar.HOUR_OF_DAY); // 24小时制小时 + int minute = mCalendar.get(Calendar.MINUTE); // 分钟 + int second = mCalendar.get(Calendar.SECOND) + 1; // 秒数 + + // 调整秒数 + if (second == 60) { + second = 0; + minute += 1; + } + + // 调整分钟 + if (minute == 60) { + minute = 0; + hour += 1; + } + + String time = String.format("%d:%02d:%02d", hour, minute, second); + // 设置小时,分钟和秒 + mCalendar.set(Calendar.HOUR_OF_DAY, hour); + mCalendar.set(Calendar.MINUTE, minute); + mCalendar.set(Calendar.SECOND, second); + Message message=new Message(); + message.what=0; + message.obj=time; + mHandler.sendMessage(message); + // 在TextView中显示年月日 + textView.setText(year + "-" + month + "-" + day); + } + },0,1000); + + } + + private void btnClickListener() { + btnStartService.setOnClickListener(this); + btnStopService.setOnClickListener(this); + btnBindService.setOnClickListener(this); + btnUnbindService.setOnClickListener(this); + btnSync.setOnClickListener(this); + } + + @Override + public void onClick(View view) { + if (view.getId() == R.id.btnStartService) { + serviceIntent.putExtra("data", etInput.getText().toString()); + getActivity().startService(serviceIntent); // Start service with parameters + } else if (view.getId() == R.id.btnStopService) { + getActivity().stopService(serviceIntent); + } else if (view.getId() == R.id.btnBindService) { + getActivity().bindService(serviceIntent, this, Context.BIND_AUTO_CREATE); + } else if (view.getId() == R.id.btnUnBindService) { + getActivity().unbindService(this); + } else if (view.getId() == R.id.btnSync) { + if (binder != null) { // 绑定服务后同步数据 + binder.setData(etInput.getText().toString()); + } + } + } + + @Override + public void onServiceConnected(ComponentName name, IBinder iBinder) { + binder = (MyService.MyBinder) iBinder; + binder.getService().setCallback(new MyService.CallBack() { + @Override + public void dataChanged(String data) { + Message msg = new Message(); + Bundle b = new Bundle(); + b.putString("data", data); + msg.setData(b); + handler.sendMessage(msg); + } + }); + } + + @Override + public void onServiceDisconnected(ComponentName name) { + binder = null; + } + + Handler handler = new Handler(Looper.getMainLooper()) { + @Override + public void handleMessage(Message msg) { + super.handleMessage(msg); + tvOut.setText(msg.getData().getString("data")); + } + }; + + + Handler mHandler=new Handler(){ + @Override + public void handleMessage(Message msg) { +// Log.v("Timer","handleMessage().."); + super.handleMessage(msg); + String str=(String)msg.obj; + tvTime.setText(str); + } + }; + + @Override + public void onDestroy() { + super.onDestroy(); + if(timer!=null){ + timer.cancel();//关闭timer + } + } + + +} diff --git a/实验六/app/src/main/java/com/example/my/fragment/HomeFragment.java b/实验六/app/src/main/java/com/example/my/fragment/HomeFragment.java new file mode 100644 index 0000000..d83094e --- /dev/null +++ b/实验六/app/src/main/java/com/example/my/fragment/HomeFragment.java @@ -0,0 +1,78 @@ +package com.example.my.fragment; + +import android.os.Bundle; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.fragment.app.Fragment; +import androidx.recyclerview.widget.RecyclerView; + +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.Toast; + +import com.example.my.Adapter.LeftListAdapter; +import com.example.my.Adapter.RightListAdapter; +import com.example.my.R; +import com.example.my.entity.DataService; + +import java.util.ArrayList; +import java.util.List; + + +public class HomeFragment extends Fragment { + + private View rootView; + private RecyclerView leftRecyclerView; + private LeftListAdapter mLeftListAdapter; + + private List left_date = new ArrayList<>(); + private RecyclerView rightRecyclerView; + + private RightListAdapter mRightListAdapter; + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) { + + // Inflate the layout for this fragment + rootView = inflater.inflate(R.layout.fragment_home, container, false); + + //初始化控件 + leftRecyclerView = rootView.findViewById(R.id.leftlist); + rightRecyclerView=rootView.findViewById(R.id.rightlist); + return rootView; + } + + @Override + public void onActivityCreated(@Nullable Bundle savedInstanceState) { + super.onActivityCreated(savedInstanceState); + + left_date.add("整租"); + left_date.add("合租"); + left_date.add("短租"); + left_date.add("公寓"); + left_date.add("新房"); + left_date.add("二手房"); + + mLeftListAdapter = new LeftListAdapter(left_date); + leftRecyclerView.setAdapter(mLeftListAdapter); + + mRightListAdapter=new RightListAdapter(); + rightRecyclerView.setAdapter(mRightListAdapter); + //默认加载数据 + mRightListAdapter.setListData(DataService.getListData(0)); + + //点击事件 + mLeftListAdapter.setmLeftListOnClickItemListener(new LeftListAdapter.LeftListOnClickItemListener() { + @Override + public void onItemClick(int position) { + mLeftListAdapter.setCurrentIndex(position); + //点击左侧分类切换对应的列表数据 + mRightListAdapter.setListData(DataService.getListData(position)); + + } + }); + } +} \ No newline at end of file diff --git a/实验六/app/src/main/java/com/example/my/fragment/MyService.java b/实验六/app/src/main/java/com/example/my/fragment/MyService.java new file mode 100644 index 0000000..033332e --- /dev/null +++ b/实验六/app/src/main/java/com/example/my/fragment/MyService.java @@ -0,0 +1,87 @@ +package com.example.my.fragment; + +import android.app.Service; +import android.content.Intent; +import android.os.Binder; +import android.os.IBinder; +import android.util.Log; + +public class MyService extends Service { + boolean running=false; //定义启动服务和停止服务的标志 + String str="来自服务器的信息..."; //初始默认的显示信息 + public MyService() { + } + @Override + public IBinder onBind(Intent intent) { + // TODO: Return the communication channel to the service. + Log.i("MyService", "onBind()"); + return new MyBinder(); //匿名类形式返回MyBinder类的对象 + } + //自定义内部类MyBinder类继承Binder类 + class MyBinder extends Binder { + void setData(String s){ + MyService.this.str=s; //修改MyService中的值 + } + MyService getService() { + return MyService.this; + } + } + @Override + public void onCreate() { + super.onCreate(); + Log.i("MyService", " onCreate ()"); + //启动一个新的线程 + new Thread(){ + @Override + public void run() { + super.run(); + running=true; + int i=1; + while(running) { + try { + String s1=i+":"+str; + Log.i("MyService", s1); + i++; + if(callback!=null){ + //调用接口中的方法获取数据 + callback.dataChanged(s1); + } + sleep(1000); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + } + }.start(); + } + @Override + public int onStartCommand(Intent intent, int flags, int startId) { + Log.i("MyService", " onStartCommand ()"); + str=intent.getStringExtra("data"); //intent 传递参数 + return super.onStartCommand(intent, flags, startId); + } + @Override + public void onDestroy() { + super.onDestroy(); + Log.i("MyService", " onDestroy ()"); + running=false; + } + @Override + public boolean onUnbind(Intent intent) { + Log.i("MyService", " onUnbind ()"); + return super.onUnbind(intent); + } + //自定义一个接口,用于监听数据的改变 + static interface CallBack{ + void dataChanged(String data); + } + //定义Callback 的对象,以及getter/setter 的方法 + CallBack callback; + public CallBack getCallback() { + return callback; + } + public void setCallback(CallBack callback) { + this.callback = callback; + } + +} diff --git a/实验六/app/src/main/java/com/example/my/fragment/RegFragment.java b/实验六/app/src/main/java/com/example/my/fragment/RegFragment.java new file mode 100644 index 0000000..ed3bda7 --- /dev/null +++ b/实验六/app/src/main/java/com/example/my/fragment/RegFragment.java @@ -0,0 +1,23 @@ +package com.example.my.fragment; + +import android.os.Bundle; + +import androidx.fragment.app.Fragment; + +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; + +import com.example.my.R; + + +public class RegFragment extends Fragment { + + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) { + // Inflate the layout for this fragment + return inflater.inflate(R.layout.fragment_reg, container, false); + } +} \ No newline at end of file diff --git a/实验六/app/src/main/java/com/example/my/fragment/SearchFragment.java b/实验六/app/src/main/java/com/example/my/fragment/SearchFragment.java new file mode 100644 index 0000000..31dad2f --- /dev/null +++ b/实验六/app/src/main/java/com/example/my/fragment/SearchFragment.java @@ -0,0 +1,75 @@ +package com.example.my.fragment; + +import android.os.Bundle; + +import androidx.annotation.Nullable; +import androidx.fragment.app.Fragment; +import androidx.recyclerview.widget.RecyclerView; + +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; + +import com.example.my.Adapter.LeftListAdapter; +import com.example.my.Adapter.RightListAdapter; +import com.example.my.R; +import com.example.my.entity.DataService; + +import java.util.ArrayList; +import java.util.List; + +public class SearchFragment extends Fragment { + + private View rootView; + private RecyclerView leftRecyclerView; + private LeftListAdapter nLeftListAdapter; + + private List left_date1 = new ArrayList<>(); + private RecyclerView rightRecyclerView; + + private RightListAdapter nRightListAdapter; + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) { + // Inflate the layout for this fragment + rootView = inflater.inflate(R.layout.fragment_search, container, false); + + + //初始化控件 + leftRecyclerView = rootView.findViewById(R.id.leftlist); + rightRecyclerView = rootView.findViewById(R.id.rightlist); + return rootView; + } + + @Override + public void onActivityCreated(@Nullable Bundle savedInstanceState) { + super.onActivityCreated(savedInstanceState); + + left_date1.add("整租"); + left_date1.add("合租"); + left_date1.add("短租"); + left_date1.add("公寓"); + left_date1.add("新房"); + left_date1.add("二手房"); + + nLeftListAdapter = new LeftListAdapter(left_date1); + leftRecyclerView.setAdapter(nLeftListAdapter); + + nRightListAdapter = new RightListAdapter(); + rightRecyclerView.setAdapter(nRightListAdapter); + //默认加载数据 + nRightListAdapter.setListData(DataService.getListData(0)); + + //点击事件 + nLeftListAdapter.setmLeftListOnClickItemListener(new LeftListAdapter.LeftListOnClickItemListener() { + @Override + public void onItemClick(int position) { + nLeftListAdapter.setCurrentIndex(position); + //点击左侧分类切换对应的列表数据 + nRightListAdapter.setListData(DataService.getListData(position)); + + } + }); + } +} \ No newline at end of file diff --git a/实验六/app/src/main/res/drawable/add.png b/实验六/app/src/main/res/drawable/add.png new file mode 100644 index 0000000..ef9d9c7 Binary files /dev/null and b/实验六/app/src/main/res/drawable/add.png differ diff --git a/实验六/app/src/main/res/drawable/bookmark.png b/实验六/app/src/main/res/drawable/bookmark.png new file mode 100644 index 0000000..39d5255 Binary files /dev/null and b/实验六/app/src/main/res/drawable/bookmark.png differ diff --git a/实验六/app/src/main/res/drawable/chat.png b/实验六/app/src/main/res/drawable/chat.png new file mode 100644 index 0000000..ffc321f Binary files /dev/null and b/实验六/app/src/main/res/drawable/chat.png differ diff --git a/实验六/app/src/main/res/drawable/darkgreen_button_background.xml b/实验六/app/src/main/res/drawable/darkgreen_button_background.xml new file mode 100644 index 0000000..b50816a --- /dev/null +++ b/实验六/app/src/main/res/drawable/darkgreen_button_background.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/实验六/app/src/main/res/drawable/edit_shape.xml b/实验六/app/src/main/res/drawable/edit_shape.xml new file mode 100644 index 0000000..ade080f --- /dev/null +++ b/实验六/app/src/main/res/drawable/edit_shape.xml @@ -0,0 +1,8 @@ + + + + + + \ No newline at end of file diff --git a/实验六/app/src/main/res/drawable/edittext_background.xml b/实验六/app/src/main/res/drawable/edittext_background.xml new file mode 100644 index 0000000..d8cc039 --- /dev/null +++ b/实验六/app/src/main/res/drawable/edittext_background.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/实验六/app/src/main/res/drawable/edittext_background2.xml b/实验六/app/src/main/res/drawable/edittext_background2.xml new file mode 100644 index 0000000..43cd1b8 --- /dev/null +++ b/实验六/app/src/main/res/drawable/edittext_background2.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/实验六/app/src/main/res/drawable/exit.png b/实验六/app/src/main/res/drawable/exit.png new file mode 100644 index 0000000..5fd8696 Binary files /dev/null and b/实验六/app/src/main/res/drawable/exit.png differ diff --git a/实验六/app/src/main/res/drawable/facebook.png b/实验六/app/src/main/res/drawable/facebook.png new file mode 100644 index 0000000..5a8d3ef Binary files /dev/null and b/实验六/app/src/main/res/drawable/facebook.png differ diff --git a/实验六/app/src/main/res/drawable/favorite.png b/实验六/app/src/main/res/drawable/favorite.png new file mode 100644 index 0000000..444ac0a Binary files /dev/null and b/实验六/app/src/main/res/drawable/favorite.png differ diff --git a/实验六/app/src/main/res/drawable/favorite2.png b/实验六/app/src/main/res/drawable/favorite2.png new file mode 100644 index 0000000..88dfab5 Binary files /dev/null and b/实验六/app/src/main/res/drawable/favorite2.png differ diff --git a/实验六/app/src/main/res/drawable/google.png b/实验六/app/src/main/res/drawable/google.png new file mode 100644 index 0000000..17d2576 Binary files /dev/null and b/实验六/app/src/main/res/drawable/google.png differ diff --git a/实验六/app/src/main/res/drawable/grey_background.xml b/实验六/app/src/main/res/drawable/grey_background.xml new file mode 100644 index 0000000..81458c2 --- /dev/null +++ b/实验六/app/src/main/res/drawable/grey_background.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/实验六/app/src/main/res/drawable/home.png b/实验六/app/src/main/res/drawable/home.png new file mode 100644 index 0000000..0428cf1 Binary files /dev/null and b/实验六/app/src/main/res/drawable/home.png differ diff --git a/实验六/app/src/main/res/drawable/home1.png b/实验六/app/src/main/res/drawable/home1.png new file mode 100644 index 0000000..803878c Binary files /dev/null and b/实验六/app/src/main/res/drawable/home1.png differ diff --git a/实验六/app/src/main/res/drawable/ic_launcher_background.xml b/实验六/app/src/main/res/drawable/ic_launcher_background.xml new file mode 100644 index 0000000..07d5da9 --- /dev/null +++ b/实验六/app/src/main/res/drawable/ic_launcher_background.xml @@ -0,0 +1,170 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/实验六/app/src/main/res/drawable/ic_launcher_foreground.xml b/实验六/app/src/main/res/drawable/ic_launcher_foreground.xml new file mode 100644 index 0000000..2b068d1 --- /dev/null +++ b/实验六/app/src/main/res/drawable/ic_launcher_foreground.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/实验六/app/src/main/res/drawable/light_green_background.xml b/实验六/app/src/main/res/drawable/light_green_background.xml new file mode 100644 index 0000000..a48e9f8 --- /dev/null +++ b/实验六/app/src/main/res/drawable/light_green_background.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/实验六/app/src/main/res/drawable/location.png b/实验六/app/src/main/res/drawable/location.png new file mode 100644 index 0000000..b125927 Binary files /dev/null and b/实验六/app/src/main/res/drawable/location.png differ diff --git a/实验六/app/src/main/res/drawable/login.png b/实验六/app/src/main/res/drawable/login.png new file mode 100644 index 0000000..37a2da7 Binary files /dev/null and b/实验六/app/src/main/res/drawable/login.png differ diff --git a/实验六/app/src/main/res/drawable/menu.png b/实验六/app/src/main/res/drawable/menu.png new file mode 100644 index 0000000..464608c Binary files /dev/null and b/实验六/app/src/main/res/drawable/menu.png differ diff --git a/实验六/app/src/main/res/drawable/more.png b/实验六/app/src/main/res/drawable/more.png new file mode 100644 index 0000000..9ddfd57 Binary files /dev/null and b/实验六/app/src/main/res/drawable/more.png differ diff --git a/实验六/app/src/main/res/drawable/pearson.png b/实验六/app/src/main/res/drawable/pearson.png new file mode 100644 index 0000000..90cf0eb Binary files /dev/null and b/实验六/app/src/main/res/drawable/pearson.png differ diff --git a/实验六/app/src/main/res/drawable/product.png b/实验六/app/src/main/res/drawable/product.png new file mode 100644 index 0000000..8f5cb21 Binary files /dev/null and b/实验六/app/src/main/res/drawable/product.png differ diff --git a/实验六/app/src/main/res/drawable/reg.png b/实验六/app/src/main/res/drawable/reg.png new file mode 100644 index 0000000..a1dd758 Binary files /dev/null and b/实验六/app/src/main/res/drawable/reg.png differ diff --git a/实验六/app/src/main/res/drawable/register.png b/实验六/app/src/main/res/drawable/register.png new file mode 100644 index 0000000..e547ccd Binary files /dev/null and b/实验六/app/src/main/res/drawable/register.png differ diff --git a/实验六/app/src/main/res/drawable/register2.png b/实验六/app/src/main/res/drawable/register2.png new file mode 100644 index 0000000..7faaaff Binary files /dev/null and b/实验六/app/src/main/res/drawable/register2.png differ diff --git a/实验六/app/src/main/res/drawable/search.png b/实验六/app/src/main/res/drawable/search.png new file mode 100644 index 0000000..ffe191f Binary files /dev/null and b/实验六/app/src/main/res/drawable/search.png differ diff --git a/实验六/app/src/main/res/drawable/setting.png b/实验六/app/src/main/res/drawable/setting.png new file mode 100644 index 0000000..34c2f2f Binary files /dev/null and b/实验六/app/src/main/res/drawable/setting.png differ diff --git a/实验六/app/src/main/res/drawable/shoppingcart.png b/实验六/app/src/main/res/drawable/shoppingcart.png new file mode 100644 index 0000000..76c06de Binary files /dev/null and b/实验六/app/src/main/res/drawable/shoppingcart.png differ diff --git a/实验六/app/src/main/res/drawable/star.png b/实验六/app/src/main/res/drawable/star.png new file mode 100644 index 0000000..58d700e Binary files /dev/null and b/实验六/app/src/main/res/drawable/star.png differ diff --git a/实验六/app/src/main/res/drawable/submit_button.xml b/实验六/app/src/main/res/drawable/submit_button.xml new file mode 100644 index 0000000..a170839 --- /dev/null +++ b/实验六/app/src/main/res/drawable/submit_button.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/实验六/app/src/main/res/drawable/twitter.png b/实验六/app/src/main/res/drawable/twitter.png new file mode 100644 index 0000000..77d7481 Binary files /dev/null and b/实验六/app/src/main/res/drawable/twitter.png differ diff --git a/实验六/app/src/main/res/drawable/type_select_bg.xml b/实验六/app/src/main/res/drawable/type_select_bg.xml new file mode 100644 index 0000000..434845a --- /dev/null +++ b/实验六/app/src/main/res/drawable/type_select_bg.xml @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/实验六/app/src/main/res/drawable/type_selected_no.xml b/实验六/app/src/main/res/drawable/type_selected_no.xml new file mode 100644 index 0000000..eda3ba2 --- /dev/null +++ b/实验六/app/src/main/res/drawable/type_selected_no.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/实验六/app/src/main/res/drawable/zz1.png b/实验六/app/src/main/res/drawable/zz1.png new file mode 100644 index 0000000..2acaed6 Binary files /dev/null and b/实验六/app/src/main/res/drawable/zz1.png differ diff --git a/实验六/app/src/main/res/drawable/zz2.jpg b/实验六/app/src/main/res/drawable/zz2.jpg new file mode 100644 index 0000000..2942705 Binary files /dev/null and b/实验六/app/src/main/res/drawable/zz2.jpg differ diff --git a/实验六/app/src/main/res/drawable/zz3.jpg b/实验六/app/src/main/res/drawable/zz3.jpg new file mode 100644 index 0000000..bb49de8 Binary files /dev/null and b/实验六/app/src/main/res/drawable/zz3.jpg differ diff --git a/实验六/app/src/main/res/layout/activity_blank.xml b/实验六/app/src/main/res/layout/activity_blank.xml new file mode 100644 index 0000000..5bda57e --- /dev/null +++ b/实验六/app/src/main/res/layout/activity_blank.xml @@ -0,0 +1,48 @@ + + + +