基于Android Studio 蜜雪冰城(奶茶饮品点餐)—原创

打印 上一主题 下一主题

主题 1006|帖子 1006|积分 3018

目录
一、项目演示
二、开发情况
三、项目详情


四、项目完备源码


一、项目演示

本项目素材、数据和布局页面参考均来自《蜜雪冰城》,在此特别声明感谢!
     基于Android Studio 蜜雪冰城(奶茶饮品)—原创
  
二、开发情况


三、项目详情

1.启动页

这段代码是一个简朴的Android应用程序启动活动(Activity),详细功能如下:
1. **耽误进入登录页面:**
   - 在 `onCreate()` 方法中,使用 `Handler` 和 `Runnable` 实现了一个耽误实行的功能,耽误时间为3秒。
   - `runnable` 对象的 `run()` 方法调用了 `tomainActive()` 方法,在耽误结束后启动 `LoginRegisterActivity` 并关闭当前的 `StartActivity`。
2. **计时器功能:**
   - 界说了一个内部类 `TimeCount`,继续自 `CountDownTimer`,用于实行一个四秒的倒计时利用,每隔一秒触发一次。
   - `onFinish()` 方法中,倒计时结束后移除了 `handler` 中的 `runnable` 对象,确保不会在倒计时结束后再次跳转到登录页面。
3. **Activity 生命周期方法:**
   - `onCreate()` 方法中,设置了布局文件 `activity_start.xml` 作为界面显示内容,并启动了耽误实行和计时器。
   - `onDestroy()` 方法中未显示重写,但在 `toMainActive()` 方法中的 `finish()` 方法确保了在跳转完成后关闭当前 Activity。
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3.     android:layout_width="fill_parent"
  4.     android:layout_height="fill_parent"
  5.     android:background="#fff">
  6.     <ImageView
  7.         android:id="@+id/image_mxbc"
  8.         android:layout_width="214.0dip"
  9.         android:layout_height="wrap_content"
  10.         android:layout_centerHorizontal="true"
  11.         android:layout_marginTop="166.0dip"
  12.         android:scaleType="centerInside"
  13.         android:src="@drawable/img_mxbc" />
  14.     <TextView
  15.         android:layout_width="wrap_content"
  16.         android:layout_height="wrap_content"
  17.         android:layout_alignParentBottom="true"
  18.         android:layout_centerHorizontal="true"
  19.         android:layout_marginBottom="60.0dip"
  20.         android:text="豫ICP备13006352号-7A"
  21.         android:textColor="#777777"
  22.         android:textSize="10sp" />
  23.     <TextView
  24.         android:id="@+id/count_down"
  25.         android:layout_width="56.0dip"
  26.         android:layout_height="28.0dip"
  27.         android:layout_alignParentRight="true"
  28.         android:layout_alignParentBottom="true"
  29.         android:layout_marginRight="20.0dip"
  30.         android:layout_marginBottom="50.0dip"
  31.         android:background="@drawable/bg_splash_count_down"
  32.         android:gravity="center"
  33.         android:text="跳过"
  34.         android:textColor="#fff"
  35.         android:textSize="11sp" />
  36. </RelativeLayout>
复制代码
2.注册、登录

这段代码实现了一个基本的注册页面功能:
- **视图与控件**:包罗关闭页面按钮、手机号、密码、确认密码的输入框以及跳转登录页面按钮和注册按钮。
- **功能与逻辑**:
  - 点击关闭按钮或跳转登录按钮可退出当前页面。
  - 注册按钮点击后,进行输入验证:
    - 查抄手机号、密码和确认密码是否为空。
    - 查抄确认密码与密码是否同等。
  - 使用 `UserHelper` 类进行数据库利用,将用户信息添加到数据库中。
  - 根据利用效果显示注册乐成或失败的提示消息,并结束当前页面。
这段代码通过简朴的逻辑和界面设计,实现了用户注册的基本流程,确保了基本的输入验证和数据库利用功能。
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3.     xmlns:app="http://schemas.android.com/apk/res-auto"
  4.     xmlns:tools="http://schemas.android.com/tools"
  5.     android:layout_width="match_parent"
  6.     android:layout_height="match_parent"
  7.     tools:context=".Activity.RegisterActivity">
  8.     <LinearLayout
  9.         android:layout_width="match_parent"
  10.         android:layout_height="match_parent"
  11.         android:orientation="vertical"
  12.         android:padding="10dp"
  13.         app:layout_constraintBottom_toBottomOf="parent"
  14.         app:layout_constraintEnd_toEndOf="parent"
  15.         app:layout_constraintStart_toStartOf="parent"
  16.         app:layout_constraintTop_toTopOf="parent">
  17.         <ImageView
  18.             android:id="@+id/page_close"
  19.             android:layout_width="20dp"
  20.             android:layout_height="20dp"
  21.             android:layout_gravity="left"
  22.             android:src="@drawable/icon_cart_close" />
  23.         <ImageView
  24.             android:layout_width="match_parent"
  25.             android:layout_height="150dp"
  26.             android:layout_marginTop="40dp"
  27.             android:src="@drawable/img_mxbc" />
  28.         <EditText
  29.             android:id="@+id/register_phone_number"
  30.             android:layout_width="fill_parent"
  31.             android:layout_height="40dp"
  32.             android:layout_marginLeft="15dp"
  33.             android:layout_marginTop="40dp"
  34.             android:layout_marginRight="15dp"
  35.             android:background="@drawable/bg_corner_solid_f5f5f5_6dp"
  36.             android:hint="手机号码"
  37.             android:inputType="number"
  38.             android:paddingLeft="20.0dip"
  39.             android:textColor="@color/black"
  40.             android:textColorHint="@color/grey_AAAAAA"
  41.             android:textCursorDrawable="@drawable/shape_cursor_color"
  42.             android:textSize="@dimen/text_size_13sp" />
  43.         <EditText
  44.             android:id="@+id/register_password"
  45.             android:layout_width="match_parent"
  46.             android:layout_height="40dp"
  47.             android:layout_marginLeft="15dp"
  48.             android:layout_marginTop="20dp"
  49.             android:layout_marginRight="15dp"
  50.             android:background="@drawable/bg_corner_solid_f5f5f5_6dp"
  51.             android:hint="用户密码"
  52.             android:inputType="textPassword"
  53.             android:paddingLeft="20.0dip"
  54.             android:textColor="@color/black"
  55.             android:textColorHint="@color/grey_AAAAAA"
  56.             android:textCursorDrawable="@drawable/shape_cursor_color"
  57.             android:textSize="@dimen/text_size_13sp" />
  58.         <EditText
  59.             android:id="@+id/register_rpassword"
  60.             android:layout_width="match_parent"
  61.             android:layout_height="40dp"
  62.             android:layout_marginLeft="15dp"
  63.             android:layout_marginTop="20dp"
  64.             android:layout_marginRight="15dp"
  65.             android:background="@drawable/bg_corner_solid_f5f5f5_6dp"
  66.             android:hint="用户密码"
  67.             android:inputType="textPassword"
  68.             android:paddingLeft="20.0dip"
  69.             android:textColor="@color/black"
  70.             android:textColorHint="@color/grey_AAAAAA"
  71.             android:textCursorDrawable="@drawable/shape_cursor_color"
  72.             android:textSize="@dimen/text_size_13sp" />
  73.         <TextView
  74.             android:id="@+id/tv_login"
  75.             android:layout_width="match_parent"
  76.             android:layout_height="wrap_content"
  77.             android:layout_marginTop="20dp"
  78.             android:layout_marginRight="15dp"
  79.             android:gravity="center|right"
  80.             android:text="已有帐号,立即登录!"
  81.             android:textColor="@color/black" />
  82.         <TextView
  83.             android:id="@+id/register_action"
  84.             android:layout_width="fill_parent"
  85.             android:layout_height="40dp"
  86.             android:layout_marginLeft="@dimen/default_left_padding"
  87.             android:layout_marginTop="50dp"
  88.             android:layout_marginRight="@dimen/default_right_padding"
  89.             android:background="@drawable/bg_login_action"
  90.             android:enabled="true"
  91.             android:gravity="center"
  92.             android:text="立 即 注 册"
  93.             android:textColor="@color/white"
  94.             android:textSize="@dimen/text_size_16sp" />
  95.     </LinearLayout>
  96. </androidx.constraintlayout.widget.ConstraintLayout>
复制代码

这段代码实现了一个登录页面的功能,详细功能和特点如下:
1. **界面元素和事件绑定**:
   - 声明了各个控件(如关闭按钮、手机号输入框、密码输入框、获取验证码按钮、注册链接、登录按钮等)和辅助类(`UserHelper`)。
   - 在 `onCreate` 方法中进行了布局初始化和事件监听的设置。
2. **获取验证码功能**:
   - 当手机号输入框内容发生变化时,监听器查抄手机号是否为空。如果不为空,则启用获取验证码按钮,而且设置点击事件显示固定的验证码(这里是 "1234")。
3. **登录功能实现**:
   - 使用了 `TextWatcher` 监听器来检测手机号、密码和验证码输入框的变化。
   - 当所有字段都非空时,启用登录按钮。点击登录按钮时,首先查抄验证码是否为 "1234",如果不是则提示验证码错误;否则,使用 `UserHelper` 类的方法查抄用户的手机号和密码是否匹配。
   - 如果匹配乐成,则提示登录乐成,并将用户手机号生存到 `SharedPreferences` 中,并关闭登录界面;否则提示登录失败。
4. **注册链接处理**:
   - 点击注册链接 (`tvRegister`) 启动 `RegisterActivity`,答应用户注册新账号。
5. **关闭页面按钮处理**:
   - 点击关闭按钮 (`pageClose`) 关闭当前登录页面。
总体来说,该代码实现了基本的用户登录流程,包罗输入验证、验证码获取、登录验证和跳转注册等功能,适适用于一个简朴的用户认证和管理系统。
  1.   @Override
  2.     protected void onCreate(Bundle savedInstanceState) {
  3.         super.onCreate(savedInstanceState);
  4.         setContentView(R.layout.activity_login);
  5.         // 初始化界面元素和事件监听
  6.         initView();
  7.         setupCloseButton();
  8.         setupRegisterLink();
  9.         setupLoginFunctionality();
  10.         setupSmsCodeListener();
  11.     }
复制代码
3.首页

这段代码是一个Android的片断(Fragment),实现了以下功能:
- 显示一个轮播广告(使用了第三方库 `Banner`)。
- 根据用户登录状态显示不同的内容:已登录则显示用户信息和订单选项,未登录则显示登录提示和登录按钮。
- 点击订单选项(inshop 和 takeout)时跳转到相应的订单处理页面。
- 点击用户信息地区时根据登录状态跳转到个人信息页面或登录页面。
主要用到了 `Glide` 库加载图片,并进行了一些视图初始化和点击事件处理的设置。
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3.     xmlns:app="http://schemas.android.com/apk/res-auto"
  4.     xmlns:tools="http://schemas.android.com/tools"
  5.     android:layout_width="match_parent"
  6.     android:layout_height="match_parent"
  7.     android:background="@color/grey_f4f4f7"
  8.     android:orientation="vertical"
  9.     tools:context=".Fragment.HomeFragment">
  10.     <ScrollView
  11.         android:layout_width="match_parent"
  12.         android:scrollbars="none"
  13.         android:layout_height="match_parent">
  14.         <LinearLayout
  15.             android:layout_width="match_parent"
  16.             android:layout_height="match_parent"
  17.             android:orientation="vertical">
  18.             <LinearLayout
  19.                 android:id="@+id/home_user_layout"
  20.                 android:layout_width="fill_parent"
  21.                 android:layout_height="70dp"
  22.                 android:layout_marginLeft="8.0dip"
  23.                 android:layout_marginTop="-37.0dip"
  24.                 android:layout_marginRight="8.0dip"
  25.                 android:background="@drawable/home_01"
  26.                 android:gravity="center"
  27.                 android:orientation="horizontal">
  28.                 <androidx.appcompat.widget.AppCompatImageView
  29.                     android:id="@+id/header_avatar"
  30.                     android:layout_width="32.0dip"
  31.                     android:layout_height="32.0dip"
  32.                     android:layout_marginLeft="16.0dip"
  33.                     android:src="@drawable/icon_not_login_user" />
  34.                 <LinearLayout
  35.                     android:layout_width="0.0dip"
  36.                     android:layout_height="wrap_content"
  37.                     android:layout_marginLeft="14.0dip"
  38.                     android:layout_weight="1"
  39.                     android:orientation="vertical">
  40.                     <TextView
  41.                         android:id="@+id/user_name"
  42.                         android:layout_width="wrap_content"
  43.                         android:layout_height="wrap_content"
  44.                         android:text="尊敬的会员"
  45.                         android:textColor="@color/black"
  46.                         android:textSize="@dimen/text_size_16sp"
  47.                         android:textStyle="bold" />
  48.                 </LinearLayout>
  49.                 <TextView
  50.                     android:id="@+id/tv_login"
  51.                     android:layout_width="wrap_content"
  52.                     android:layout_height="wrap_content"
  53.                     android:layout_marginRight="20.0dip"
  54.                     android:text="注册/登录"
  55.                     android:textColor="@color/themeRedColor"
  56.                     android:textSize="@dimen/text_size_13sp"
  57.                     android:textStyle="bold"
  58.                     android:visibility="gone" />
  59.                 <LinearLayout
  60.                     android:id="@+id/ll_show"
  61.                     android:layout_width="wrap_content"
  62.                     android:layout_height="match_parent"
  63.                     android:orientation="horizontal">
  64.                     <LinearLayout
  65.                         android:layout_width="match_parent"
  66.                         android:layout_height="match_parent"
  67.                         android:layout_weight="1"
  68.                         android:gravity="center"
  69.                         android:orientation="vertical">
  70.                         <TextView
  71.                             android:id="@+id/textView5"
  72.                             android:layout_width="match_parent"
  73.                             android:layout_height="wrap_content"
  74.                             android:gravity="center"
  75.                             android:text="0"
  76.                             android:textColor="@color/black" />
  77.                         <TextView
  78.                             android:id="@+id/textView7"
  79.                             android:layout_width="match_parent"
  80.                             android:layout_height="wrap_content"
  81.                             android:layout_marginTop="4dp"
  82.                             android:gravity="center"
  83.                             android:text="雪王币"
  84.                             android:textColor="@color/black" />
  85.                     </LinearLayout>
  86.                     <LinearLayout
  87.                         android:layout_width="match_parent"
  88.                         android:layout_height="match_parent"
  89.                         android:layout_marginLeft="15dp"
  90.                         android:layout_marginRight="15dp"
  91.                         android:layout_weight="1"
  92.                         android:gravity="center"
  93.                         android:orientation="vertical">
  94.                         <TextView
  95.                             android:id="@+id/textView6"
  96.                             android:layout_width="match_parent"
  97.                             android:layout_height="wrap_content"
  98.                             android:gravity="center"
  99.                             android:text="0"
  100.                             android:textColor="@color/black" />
  101.                         <TextView
  102.                             android:id="@+id/textView8"
  103.                             android:layout_width="match_parent"
  104.                             android:layout_height="wrap_content"
  105.                             android:layout_marginTop="4dp"
  106.                             android:gravity="center"
  107.                             android:text="优惠卷"
  108.                             android:textColor="@color/black" />
  109.                     </LinearLayout>
  110.                 </LinearLayout>
  111.             </LinearLayout>
  112.             <LinearLayout
  113.                 android:layout_width="match_parent"
  114.                 android:layout_height="wrap_content"
  115.                 android:layout_marginLeft="8dp"
  116.                 android:layout_marginTop="10dp"
  117.                 android:layout_marginRight="8dp"
  118.                 android:background="@drawable/home_01"
  119.                 android:orientation="vertical">
  120.                 <LinearLayout
  121.                     android:layout_width="match_parent"
  122.                     android:layout_height="wrap_content"
  123.                     android:orientation="horizontal">
  124.                     <ImageView
  125.                         android:id="@+id/inshop"
  126.                         android:layout_width="match_parent"
  127.                         android:layout_height="150dp"
  128.                         android:layout_weight="1"
  129.                         android:src="@drawable/inshop" />
  130.                     <ImageView
  131.                         android:id="@+id/takeout"
  132.                         android:layout_width="match_parent"
  133.                         android:layout_height="150dp"
  134.                         android:layout_weight="1"
  135.                         android:src="@drawable/takeout" />
  136.                 </LinearLayout>
  137.                 <View
  138.                     android:id="@+id/view4"
  139.                     android:layout_width="match_parent"
  140.                     android:layout_height="1dp"
  141.                     android:layout_marginLeft="16.0dip"
  142.                     android:layout_marginTop="5dp"
  143.                     android:layout_marginRight="16.0dip"
  144.                     android:background="@color/grey_150A5E_5" />
  145.                 <LinearLayout
  146.                     android:layout_width="match_parent"
  147.                     android:layout_height="match_parent"
  148.                     android:layout_marginTop="5dp"
  149.                     android:orientation="horizontal">
  150.                     <ImageView
  151.                         android:id="@+id/imageView4"
  152.                         android:layout_width="match_parent"
  153.                         android:layout_height="90dp"
  154.                         android:layout_weight="1"
  155.                         android:src="@drawable/home_03" />
  156.                     <ImageView
  157.                         android:id="@+id/imageView5"
  158.                         android:layout_width="match_parent"
  159.                         android:layout_height="90dp"
  160.                         android:layout_weight="1"
  161.                         android:src="@drawable/home_04" />
  162.                     <ImageView
  163.                         android:id="@+id/imageView6"
  164.                         android:layout_width="match_parent"
  165.                         android:layout_height="90dp"
  166.                         android:layout_weight="1"
  167.                         android:src="@drawable/home_001" />
  168.                     <ImageView
  169.                         android:id="@+id/imageView7"
  170.                         android:layout_width="match_parent"
  171.                         android:layout_height="90dp"
  172.                         android:layout_weight="1"
  173.                         android:src="@drawable/home_02" />
  174.                 </LinearLayout>
  175.             </LinearLayout>
  176.             <TextView
  177.                 android:id="@+id/tab_"
  178.                 android:layout_width="match_parent"
  179.                 android:layout_height="wrap_content"
  180.                 android:layout_gravity="center"
  181.                 android:layout_marginLeft="8dp"
  182.                 android:layout_marginTop="15dp"
  183.                 android:layout_marginRight="8dp"
  184.                 android:text="甜蜜资讯"
  185.                 android:textColor="@color/black"
  186.                 android:textSize="@dimen/text_size_16sp"
  187.                 android:textStyle="bold" />
  188.             <ImageView
  189.                 android:id="@+id/img_1"
  190.                 android:layout_width="match_parent"
  191.                 android:layout_height="120dp"
  192.                 android:layout_marginLeft="8dp"
  193.                 android:layout_marginTop="10dp"
  194.                 android:layout_marginRight="8dp"
  195.                 android:scaleType="fitXY"
  196.                 android:src="@drawable/banner2" />
  197.             <ImageView
  198.                 android:id="@+id/img_2"
  199.                 android:layout_width="match_parent"
  200.                 android:layout_height="120dp"
  201.                 android:layout_marginLeft="8dp"
  202.                 android:layout_marginTop="10dp"
  203.                 android:layout_marginRight="8dp"
  204.                 android:scaleType="fitXY"
  205.                 android:src="@drawable/banner3" />
  206.         </LinearLayout>
  207.     </ScrollView>
  208. </LinearLayout>
复制代码
4.点餐页面

这段代码实现了一个点单页面的 Android Fragment,主要功能包罗:
- 展示菜单分类和产物列表,并支持根据搜索关键字进行筛选显示。
- 根据用户登录状态动态展示地址选择、结算功能,并处理相应的点击事件。
- 使用 `Gson` 解析本地 JSON 数据来加载菜单信息。
- 及时更新总代价显示,并支持用户在不同订单类型(自提或外送)之间切换。
该代码还包罗了处理返回按钮、清空订单和地址信息等相关逻辑。
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3.     xmlns:app="http://schemas.android.com/apk/res-auto"
  4.     xmlns:tools="http://schemas.android.com/tools"
  5.     android:layout_width="match_parent"
  6.     android:layout_height="match_parent"
  7.     android:id="@+id/fragment_takeOrder"
  8.     tools:context=".Fragment.TakeOrderFragment">
  9.     <LinearLayout
  10.         android:id="@+id/linearLayout3"
  11.         android:layout_width="0dp"
  12.         android:layout_height="30dp"
  13.         android:layout_marginStart="8dp"
  14.         android:layout_marginTop="8dp"
  15.         android:layout_marginEnd="8dp"
  16.         android:orientation="horizontal"
  17.         app:layout_constraintEnd_toEndOf="parent"
  18.         app:layout_constraintStart_toStartOf="parent"
  19.         app:layout_constraintTop_toTopOf="parent">
  20.         <TextView
  21.             android:id="@+id/tv_inshop"
  22.             android:layout_width="50dp"
  23.             android:layout_height="match_parent"
  24.             android:gravity="center"
  25.             android:text="自提"
  26.             android:textColor="@color/black"
  27.             android:textSize="18sp"
  28.             android:textStyle="bold" />
  29.         <TextView
  30.             android:id="@+id/tv_takeout"
  31.             android:layout_width="50dp"
  32.             android:layout_height="match_parent"
  33.             android:layout_marginLeft="10dp"
  34.             android:gravity="center"
  35.             android:text="外送"
  36.             android:textColor="@color/black_40"
  37.             android:textSize="18sp"
  38.             android:textStyle="bold" />
  39.         <LinearLayout
  40.             android:layout_width="match_parent"
  41.             android:layout_height="match_parent"
  42.             android:background="@drawable/bg_corner_solid_f5f5f5_6dp"
  43.             android:gravity="center|left"
  44.             android:orientation="horizontal"
  45.             android:padding="3dp">
  46.             <ImageView
  47.                 android:id="@+id/img_search"
  48.                 android:layout_width="15dp"
  49.                 android:layout_height="15dp"
  50.                 android:layout_marginLeft="10dp"
  51.                 android:src="@drawable/icon_search" />
  52.             <EditText
  53.                 android:id="@+id/et_search"
  54.                 android:layout_width="wrap_content"
  55.                 android:layout_height="wrap_content"
  56.                 android:layout_marginLeft="5dp"
  57.                 android:layout_weight="1"
  58.                 android:background="@color/grey_E6E6E6"
  59.                 android:ems="10"
  60.                 android:hint="冰鲜柠檬茶"
  61.                 android:inputType="textPersonName"
  62.                 android:textSize="12sp" />
  63.         </LinearLayout>
  64.     </LinearLayout>
  65.     <LinearLayout
  66.         android:id="@+id/linearLayout4"
  67.         android:layout_width="0dp"
  68.         android:layout_height="wrap_content"
  69.         android:layout_marginTop="10dp"
  70.         android:orientation="vertical"
  71.         app:layout_constraintEnd_toEndOf="@+id/linearLayout3"
  72.         app:layout_constraintStart_toStartOf="@+id/linearLayout3"
  73.         app:layout_constraintTop_toBottomOf="@+id/linearLayout3">
  74.         <LinearLayout
  75.             android:id="@+id/ll_address"
  76.             android:layout_width="match_parent"
  77.             android:layout_height="match_parent"
  78.             android:layout_marginBottom="10dp"
  79.             android:gravity="center|left"
  80.             android:orientation="horizontal"
  81.             android:visibility="gone">
  82.             <TextView
  83.                 android:id="@+id/tv_address"
  84.                 android:layout_width="wrap_content"
  85.                 android:layout_height="wrap_content"
  86.                 android:text="配送至 · 陕西省"
  87.                 android:textColor="@color/black"
  88.                 android:textSize="16sp" />
  89.             <ImageView
  90.                 android:id="@+id/imageView2"
  91.                 android:layout_width="10dp"
  92.                 android:layout_height="10dp"
  93.                 android:layout_marginLeft="2dp"
  94.                 android:src="@drawable/icon_arrow_dark_next" />
  95.         </LinearLayout>
  96.         <TextView
  97.             android:id="@+id/textView11"
  98.             android:layout_width="match_parent"
  99.             android:layout_height="wrap_content"
  100.             android:text="蜜雪冰城(总店)"
  101.             android:textColor="@color/black" />
  102.     </LinearLayout>
  103.     <LinearLayout
  104.         android:id="@+id/linearLayout5"
  105.         android:layout_width="0dp"
  106.         android:layout_height="0dp"
  107.         android:layout_marginTop="8dp"
  108.         android:layout_marginBottom="2dp"
  109.         android:orientation="horizontal"
  110.         app:layout_constraintBottom_toTopOf="@+id/bottom_layout"
  111.         app:layout_constraintEnd_toEndOf="parent"
  112.         app:layout_constraintStart_toStartOf="parent"
  113.         app:layout_constraintTop_toBottomOf="@+id/linearLayout4">
  114.         <androidx.recyclerview.widget.RecyclerView
  115.             android:id="@+id/rv_menu"
  116.             android:layout_width="80dp"
  117.             android:layout_height="match_parent" />
  118.         <androidx.recyclerview.widget.RecyclerView
  119.             android:id="@+id/rv_menuItem"
  120.             android:layout_width="match_parent"
  121.             android:layout_height="match_parent"
  122.             android:layout_marginLeft="10dp"
  123.             android:layout_weight="1"></androidx.recyclerview.widget.RecyclerView>
  124.     </LinearLayout>
  125.     <LinearLayout
  126.         android:id="@+id/bottom_layout"
  127.         android:layout_width="0dp"
  128.         android:layout_height="wrap_content"
  129.         android:layout_weight="1"
  130.         android:background="@color/white"
  131.         android:clipChildren="false"
  132.         android:orientation="vertical"
  133.         android:padding="5dp"
  134.         app:layout_constraintBottom_toBottomOf="parent"
  135.         app:layout_constraintEnd_toEndOf="parent"
  136.         app:layout_constraintStart_toStartOf="parent">
  137.         <FrameLayout
  138.             android:layout_width="fill_parent"
  139.             android:layout_height="fill_parent"
  140.             android:orientation="horizontal">
  141.             <FrameLayout
  142.                 android:id="@+id/cart_anim"
  143.                 android:layout_width="38.0dip"
  144.                 android:layout_height="40.0dip"
  145.                 android:layout_gravity="center_vertical"
  146.                 android:layout_marginLeft="9.0dip"
  147.                 android:layout_marginRight="12.0dip">
  148.                 <ImageView
  149.                     android:id="@+id/order_cart"
  150.                     android:layout_width="31.0dip"
  151.                     android:layout_height="35.0dip"
  152.                     android:layout_gravity="center_vertical"
  153.                     android:layout_marginBottom="2.0dip"
  154.                     android:src="@drawable/icon_cart" />
  155.                 <TextView
  156.                     android:id="@+id/order_goods_count"
  157.                     android:layout_width="wrap_content"
  158.                     android:layout_height="wrap_content"
  159.                     android:layout_gravity="center|right|top"
  160.                     android:background="@drawable/icon_bg_number_tip"
  161.                     android:gravity="center"
  162.                     android:textColor="@color/white"
  163.                     android:textSize="@dimen/text_size_10sp"
  164.                     android:visibility="gone" />
  165.             </FrameLayout>
  166.             <RelativeLayout
  167.                 android:layout_width="wrap_content"
  168.                 android:layout_height="wrap_content"
  169.                 android:layout_gravity="center|right"
  170.                 android:layout_marginRight="123.0dip"
  171.                 android:orientation="vertical">
  172.                 <RelativeLayout
  173.                     android:id="@+id/price_layout"
  174.                     android:layout_width="wrap_content"
  175.                     android:layout_height="wrap_content"
  176.                     android:layout_centerVertical="true"
  177.                     android:orientation="horizontal">
  178.                     <TextView
  179.                         android:id="@+id/delivery_fee"
  180.                         android:layout_width="wrap_content"
  181.                         android:layout_height="match_parent"
  182.                         android:layout_alignBottom="@id/total_price"
  183.                         android:layout_alignParentTop="true"
  184.                         android:layout_marginTop="0dp"
  185.                         android:layout_marginRight="6.0dip"
  186.                         android:layout_marginBottom="2.0dip"
  187.                         android:layout_toLeftOf="@id/total_tip"
  188.                         android:gravity="bottom"
  189.                         android:text="另需配送费¥2"
  190.                         android:textColor="@color/grey_FFAAAAAA"
  191.                         android:textSize="@dimen/text_size_12sp"
  192.                         android:visibility="invisible" />
  193.                     <TextView
  194.                         android:id="@+id/total_price"
  195.                         android:layout_width="wrap_content"
  196.                         android:layout_height="wrap_content"
  197.                         android:layout_alignParentRight="true"
  198.                         android:text="¥0"
  199.                         android:textColor="@color/black_333333"
  200.                         android:textSize="16sp"
  201.                         android:textStyle="bold" />
  202.                     <TextView
  203.                         android:id="@+id/total_tip"
  204.                         android:layout_width="wrap_content"
  205.                         android:layout_height="wrap_content"
  206.                         android:layout_alignBottom="@id/total_price"
  207.                         android:layout_marginBottom="2.0dip"
  208.                         android:layout_toLeftOf="@id/total_price"
  209.                         android:text="合计:"
  210.                         android:textColor="@color/black"
  211.                         android:textSize="@dimen/text_size_12sp" />
  212.                 </RelativeLayout>
  213.     </LinearLayout>
  214. </androidx.constraintlayout.widget.ConstraintLayout>
复制代码

5.订单页、订单详情页

这段代码实现了一个订单页面的 Android Fragment,主要功能包罗:
- 根据用户登录状态,显示对应手机号的订单列表。
- 当用户未登录时,显示登录提示信息。
- 当用户已登录且有订单时,显示订单列表,并提供适配器来展示订单信息。
- 提供了 onResume 方法来在 Fragment 可见时革新订单列表。
- 包罗一个返回按钮的处理逻辑,但详细利用未实现。
该代码使用了 `ListView` 来展示订单,通过 `SharedPreferences` 获取用户手机号,并使用 `OrderHelper` 类来利用订单数据。
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3.     xmlns:app="http://schemas.android.com/apk/res-auto"
  4.     xmlns:tools="http://schemas.android.com/tools"
  5.     android:layout_width="match_parent"
  6.     android:layout_height="match_parent"
  7.     android:background="@color/grey_F5F5F5"
  8.     tools:context=".Fragment.OrderFragment">
  9.     <LinearLayout
  10.         android:id="@+id/linearLayout6"
  11.         android:layout_width="0dp"
  12.         android:layout_height="40dp"
  13.         android:background="@color/white"
  14.         android:orientation="horizontal"
  15.         app:layout_constraintEnd_toEndOf="parent"
  16.         app:layout_constraintStart_toStartOf="parent"
  17.         app:layout_constraintTop_toTopOf="parent">
  18.         <TextView
  19.             android:id="@+id/tv_title"
  20.             android:layout_width="wrap_content"
  21.             android:layout_height="match_parent"
  22.             android:layout_weight="1"
  23.             android:gravity="center"
  24.             android:text="订单管理"
  25.             android:textColor="@color/black"
  26.             android:textSize="18sp"
  27.             android:textStyle="bold" />
  28.     </LinearLayout>
  29.     <ListView
  30.         android:id="@+id/lv"
  31.         android:layout_width="0dp"
  32.         android:layout_height="0dp"
  33.         android:layout_marginStart="4dp"
  34.         android:layout_marginTop="8dp"
  35.         android:layout_marginEnd="4dp"
  36.         android:divider="@android:color/transparent"
  37.         android:dividerHeight="0dp"
  38.         android:scrollbars="none"
  39.         app:layout_constraintBottom_toBottomOf="parent"
  40.         app:layout_constraintEnd_toEndOf="parent"
  41.         app:layout_constraintStart_toStartOf="parent"
  42.         app:layout_constraintTop_toBottomOf="@+id/linearLayout6" />
  43.     <ImageView
  44.         android:id="@+id/img_null"
  45.         android:layout_width="0dp"
  46.         android:layout_height="0dp"
  47.         android:src="@drawable/img_empty_order"
  48.         android:visibility="visible"
  49.         app:layout_constraintBottom_toBottomOf="parent"
  50.         app:layout_constraintEnd_toEndOf="parent"
  51.         app:layout_constraintStart_toStartOf="parent"
  52.         app:layout_constraintTop_toBottomOf="@+id/linearLayout6" />
  53. </androidx.constraintlayout.widget.ConstraintLayout>
复制代码

这段代码实现了一个订单详情页面的 Android 活动(Activity),功能包罗:
- 根据传入的意图显示订单的详细信息,包罗订单类型(自提或外送)、时间、订单号、商品数量和总金额。
- 根据订单类型调整显示内容,包罗是否显示外送费用和外送布局的可见性。
- 根据用户手机号和订单号查询订单数据,并使用自界说的适配器 `OrderDetailsAdapter` 显示订单详情列表。
- 提供了返回按钮和再来一单按钮的点击事件处理逻辑。
该活动通过 `SharedPreferences` 获取用户手机号,并使用 `OrderHelper` 类来利用订单数据。

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3.     xmlns:app="http://schemas.android.com/apk/res-auto"
  4.     xmlns:tools="http://schemas.android.com/tools"
  5.     android:layout_width="match_parent"
  6.     android:layout_height="match_parent"
  7.     android:background="@color/grey_F8F8F8"
  8.     tools:context=".Activity.OrderDetailsActivity">
  9.     <FrameLayout
  10.         android:id="@+id/page_title_layout"
  11.         android:layout_width="match_parent"
  12.         android:layout_height="150dp"
  13.         android:background="@drawable/img_order_detail_bg"
  14.         android:orientation="horizontal"
  15.         app:layout_constraintEnd_toEndOf="parent"
  16.         app:layout_constraintStart_toStartOf="parent"
  17.         app:layout_constraintTop_toTopOf="parent">
  18.         <FrameLayout
  19.             android:layout_width="fill_parent"
  20.             android:layout_height="fill_parent">
  21.             <ImageView
  22.                 android:id="@id/page_back"
  23.                 android:layout_width="45.0dip"
  24.                 android:layout_height="60dp"
  25.                 android:paddingLeft="12.0dip"
  26.                 android:paddingTop="15dp"
  27.                 android:paddingRight="12.0dip"
  28.                 android:paddingBottom="12.0dip"
  29.                 android:scaleType="centerInside"
  30.                 android:src="@drawable/icon_page_back_white" />
  31.             <LinearLayout
  32.                 android:layout_width="wrap_content"
  33.                 android:layout_height="wrap_content"
  34.                 android:orientation="vertical">
  35.                 <TextView
  36.                     android:id="@+id/page_title"
  37.                     android:layout_width="wrap_content"
  38.                     android:layout_height="wrap_content"
  39.                     android:layout_marginLeft="28.0dip"
  40.                     android:layout_marginTop="60dp"
  41.                     android:ellipsize="none"
  42.                     android:maxWidth="260.0dip"
  43.                     android:singleLine="true"
  44.                     android:text="订单已完成"
  45.                     android:textColor="@color/white"
  46.                     android:textSize="@dimen/text_size_18sp"
  47.                     android:textStyle="bold" />
  48.                 <TextView
  49.                     android:id="@+id/page_status_tip"
  50.                     android:layout_width="wrap_content"
  51.                     android:layout_height="wrap_content"
  52.                     android:layout_marginLeft="28.0dip"
  53.                     android:layout_marginTop="12.0dip"
  54.                     android:ellipsize="none"
  55.                     android:maxWidth="200.0dip"
  56.                     android:maxLines="2"
  57.                     android:text="如未取餐,请及时到店领取,祝您用餐愉快"
  58.                     android:textColor="@color/white"
  59.                     android:textSize="@dimen/text_size_12sp" />
  60.             </LinearLayout>
  61.             <ImageView
  62.                 android:id="@+id/page_img_action"
  63.                 android:layout_width="130.0dip"
  64.                 android:layout_height="90.0dip"
  65.                 android:layout_gravity="bottom|center|right"
  66.                 android:layout_marginRight="@dimen/default_right_padding"
  67.                 android:layout_marginBottom="15dp"
  68.                 android:src="@drawable/img_order_finish_king" />
  69.             <LinearLayout
  70.                 android:layout_width="fill_parent"
  71.                 android:layout_height="10.0dip"
  72.                 android:layout_gravity="bottom"
  73.                 android:background="@drawable/bg_corner_solid_ffffff_top_12dp" />
  74.         </FrameLayout>
  75.     </FrameLayout>
  76.     <ScrollView
  77.         android:id="@+id/scrollView2"
  78.         android:layout_width="0dp"
  79.         android:layout_height="0dp"
  80.         android:layout_marginStart="8dp"
  81.         android:layout_marginEnd="8dp"
  82.         android:layout_marginBottom="8dp"
  83.         android:scrollbars="none"
  84.         app:layout_constraintBottom_toTopOf="@+id/linearLayout9"
  85.         app:layout_constraintEnd_toEndOf="parent"
  86.         app:layout_constraintStart_toStartOf="parent"
  87.         app:layout_constraintTop_toBottomOf="@+id/page_title_layout">
  88.         <LinearLayout
  89.             android:layout_width="match_parent"
  90.             android:layout_height="wrap_content"
  91.             android:orientation="vertical">
  92.             <LinearLayout
  93.                 android:layout_width="match_parent"
  94.                 android:layout_height="match_parent"
  95.                 android:layout_marginTop="5dp"
  96.                 android:background="@drawable/bg_corner_solid_ffffff_12dp"
  97.                 android:gravity="center"
  98.                 android:orientation="vertical"
  99.                 android:padding="10dp">
  100.                 <LinearLayout
  101.                     android:layout_width="match_parent"
  102.                     android:layout_height="wrap_content"
  103.                     android:orientation="horizontal">
  104.                     <LinearLayout
  105.                         android:layout_width="match_parent"
  106.                         android:layout_height="wrap_content"
  107.                         android:layout_weight="1"
  108.                         android:orientation="vertical">
  109.                         <TextView
  110.                             android:id="@+id/textView9"
  111.                             android:layout_width="match_parent"
  112.                             android:layout_height="wrap_content"
  113.                             android:text="蜜雪冰城(总店)"
  114.                             android:textColor="@color/black"
  115.                             android:textSize="16sp"
  116.                             android:textStyle="bold" />
  117.                         <TextView
  118.                             android:id="@+id/textView24"
  119.                             android:layout_width="250dp"
  120.                             android:layout_height="wrap_content"
  121.                             android:layout_marginTop="4dp"
  122.                             android:text="河南省郑州市金水区文化路与北环交叉口瀚海·北金商务A座16楼"
  123.                             android:textSize="12sp" />
  124.                     </LinearLayout>
  125.                     <ImageView
  126.                         android:id="@+id/imageView11"
  127.                         android:layout_width="25dp"
  128.                         android:layout_height="25dp"
  129.                         app:srcCompat="@drawable/icon_order_location" />
  130.                     <ImageView
  131.                         android:id="@+id/imageView12"
  132.                         android:layout_width="25dp"
  133.                         android:layout_height="25dp"
  134.                         android:layout_marginLeft="20dp"
  135.                         android:layout_marginRight="10dp"
  136.                         app:srcCompat="@drawable/icon_order_phone" />
  137.                 </LinearLayout>
  138.                 <View
  139.                     android:id="@+id/view8"
  140.                     android:layout_width="match_parent"
  141.                     android:layout_height="1.0dip"
  142.                     android:layout_marginLeft="4dp"
  143.                     android:layout_marginTop="10dp"
  144.                     android:layout_marginRight="4dp"
  145.                     android:layout_marginBottom="10dp"
  146.                     android:layout_weight="1"
  147.                     android:background="@color/grey_F5F5F5" />
  148.                 <ListView
  149.                     android:id="@+id/lv"
  150.                     android:layout_width="match_parent"
  151.                     android:layout_height="wrap_content"
  152.                     android:scrollbars="none" />
  153.                 <View
  154.                     android:id="@+id/view9"
  155.                     android:layout_width="match_parent"
  156.                     android:layout_height="1.0dip"
  157.                     android:layout_marginLeft="4dp"
  158.                     android:layout_marginTop="10dp"
  159.                     android:layout_marginRight="4dp"
  160.                     android:layout_marginBottom="10dp"
  161.                     android:layout_weight="1"
  162.                     android:background="@color/grey_F5F5F5" />
  163.                 <LinearLayout
  164.                     android:id="@+id/ll_peisong"
  165.                     android:layout_width="match_parent"
  166.                     android:layout_height="match_parent"
  167.                     android:gravity="center"
  168.                     android:orientation="horizontal">
  169.                     <TextView
  170.                         android:id="@+id/textView22"
  171.                         android:layout_width="wrap_content"
  172.                         android:layout_height="wrap_content"
  173.                         android:text="配送费"
  174.                         android:textColor="@color/black" />
  175.                     <ImageView
  176.                         android:id="@+id/imageView10"
  177.                         android:layout_width="20dp"
  178.                         android:layout_height="20dp"
  179.                         app:srcCompat="@drawable/icon_question" />
  180.                     <LinearLayout
  181.                         android:layout_width="match_parent"
  182.                         android:layout_height="match_parent"
  183.                         android:layout_weight="1"
  184.                         android:gravity="center|right"
  185.                         android:orientation="horizontal">
  186.                         <TextView
  187.                             android:id="@+id/tv_peisong"
  188.                             android:layout_width="wrap_content"
  189.                             android:layout_height="wrap_content"
  190.                             android:layout_marginLeft="4dp"
  191.                             android:text="¥2"
  192.                             android:textColor="@color/black"
  193.                             android:textSize="14sp" />
  194.                     </LinearLayout>
  195.                 </LinearLayout>
  196.                 <View
  197.                     android:id="@+id/view_peisong"
  198.                     android:layout_width="match_parent"
  199.                     android:layout_height="1.0dip"
  200.                     android:layout_marginLeft="4dp"
  201.                     android:layout_marginTop="10dp"
  202.                     android:layout_marginRight="4dp"
  203.                     android:layout_marginBottom="10dp"
  204.                     android:layout_weight="1"
  205.                     android:background="@color/grey_F5F5F5" />
  206.                 <LinearLayout
  207.                     android:layout_width="match_parent"
  208.                     android:layout_height="match_parent"
  209.                     android:layout_marginLeft="@dimen/default_left_padding"
  210.                     android:layout_marginTop="5dip"
  211.                     android:layout_marginRight="@dimen/default_right_padding"
  212.                     android:layout_marginBottom="9dip"
  213.                     android:gravity="bottom|center|right"
  214.                     android:orientation="horizontal">
  215.       
  216.             </LinearLayout>
  217.                         <LinearLayout
  218.                     android:layout_width="fill_parent"
  219.                     android:layout_height="fill_parent"
  220.                     android:layout_marginTop="12.0dip"
  221.                     android:layout_marginBottom="12.0dip"
  222.                     android:orientation="vertical">
  223.                     <LinearLayout
  224.                         android:layout_width="fill_parent"
  225.                         android:layout_height="wrap_content"
  226.                         android:gravity="center_vertical"
  227.                         android:orientation="horizontal">
  228.                         <TextView
  229.                             android:layout_width="wrap_content"
  230.                             android:layout_height="wrap_content"
  231.                             android:layout_marginLeft="16.0dip"
  232.                             android:text="下单时间"
  233.                             android:textColor="@color/black"
  234.                             android:textSize="@dimen/text_size_13sp" />
  235.                         <TextView
  236.                             android:id="@+id/order_time"
  237.                             android:layout_width="wrap_content"
  238.                             android:layout_height="wrap_content"
  239.                             android:layout_marginLeft="16.0dip"
  240.                             android:textColor="@color/black"
  241.                             android:textSize="@dimen/text_size_13sp" />
  242.                     </LinearLayout>
  243.                     <RelativeLayout
  244.                         android:layout_width="fill_parent"
  245.                         android:layout_height="wrap_content"
  246.                         android:layout_marginTop="8.0dip">
  247.                         <TextView
  248.                             android:id="@+id/orderId_tip"
  249.                             android:layout_width="wrap_content"
  250.                             android:layout_height="wrap_content"
  251.                             android:layout_alignParentLeft="true"
  252.                             android:layout_centerVertical="true"
  253.                             android:layout_marginLeft="16.0dip"
  254.                             android:text="订单号码"
  255.                             android:textColor="@color/black"
  256.                             android:textSize="@dimen/text_size_13sp" />
  257.                         <TextView
  258.                             android:id="@+id/orderId"
  259.                             android:layout_width="wrap_content"
  260.                             android:layout_height="wrap_content"
  261.                             android:layout_centerVertical="true"
  262.                             android:layout_marginLeft="16.0dip"
  263.                             android:layout_toRightOf="@id/orderId_tip"
  264.                             android:ellipsize="end"
  265.                             android:maxWidth="185.0dip"
  266.                             android:maxLines="1"
  267.                             android:textColor="@color/black"
  268.                             android:textSize="@dimen/text_size_13sp" />
  269.                     </RelativeLayout>
  270.                     <LinearLayout
  271.                         android:id="@id/remark_layout"
  272.                         android:layout_width="fill_parent"
  273.                         android:layout_height="wrap_content"
  274.                         android:layout_marginTop="8.0dip"
  275.                         android:orientation="horizontal">
  276.                         <TextView
  277.                             android:layout_width="wrap_content"
  278.                             android:layout_height="wrap_content"
  279.                             android:layout_marginLeft="16.0dip"
  280.                             android:text="备注"
  281.                             android:textColor="@color/black"
  282.                             android:textSize="@dimen/text_size_13sp" />
  283.                         <TextView
  284.                             android:id="@id/remark"
  285.                             android:layout_width="wrap_content"
  286.                             android:layout_height="wrap_content"
  287.                             android:layout_marginLeft="42.0dip"
  288.                             android:text="无"
  289.                             android:textColor="@color/black"
  290.                             android:textSize="@dimen/text_size_13sp" />
  291.                     </LinearLayout>
  292.                 </LinearLayout>
  293.             </FrameLayout>
  294.         </LinearLayout>
  295.     </ScrollView>
  296.     <LinearLayout
  297.         android:id="@+id/linearLayout9"
  298.         android:layout_width="match_parent"
  299.         android:layout_height="50dp"
  300.         android:background="@color/white"
  301.         android:gravity="center|right"
  302.         android:orientation="horizontal"
  303.         app:layout_constraintBottom_toBottomOf="parent"
  304.         app:layout_constraintEnd_toEndOf="parent"
  305.         app:layout_constraintStart_toStartOf="parent">
  306.         <TextView
  307.             android:id="@+id/one_more"
  308.             android:layout_width="70dp"
  309.             android:layout_height="25dp"
  310.             android:layout_below="@id/price_layout"
  311.             android:layout_alignParentRight="true"
  312.             android:layout_marginRight="10dp"
  313.             android:background="@drawable/bg_corner_solid_fc3f41_4dp"
  314.             android:enabled="true"
  315.             android:gravity="center"
  316.             android:text="再来一单"
  317.             android:textColor="@color/red_FC3F41"
  318.             android:textSize="@dimen/text_size_12sp" />
  319.     </LinearLayout>
  320. </androidx.constraintlayout.widget.ConstraintLayout>
复制代码
6.地址页面、修改增长页



7.结算页面

这段代码实现了一个支付页面的 Android 活动(Activity),功能包罗:
- 根据订单类型(自提或外送)显示相应的配送地址和费用信息。
- 根据用户选择的支付方式(微信或支付宝)更新支付利用。
- 显示用户的订单列表,并提供支付利用的点击事件处理逻辑。
- 使用 `SharedPreferences` 获取用户的地址信息和手机号,使用 `TakeOrderHelper` 和 `OrderHelper` 处理订单数据的存储和获取。
该活动答应用户选择支付方式,并在确认支付后生存订单并返回到主界面。 
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3.     xmlns:app="http://schemas.android.com/apk/res-auto"
  4.     xmlns:tools="http://schemas.android.com/tools"
  5.     android:layout_width="match_parent"
  6.     android:layout_height="match_parent"
  7.     tools:context=".Activity.PayActivity">
  8.     <LinearLayout
  9.         android:id="@+id/linearLayout6"
  10.         android:layout_width="0dp"
  11.         android:layout_height="40dp"
  12.         android:background="@color/red_FC3F41"
  13.         android:orientation="horizontal"
  14.         app:layout_constraintEnd_toEndOf="parent"
  15.         app:layout_constraintStart_toStartOf="parent"
  16.         app:layout_constraintTop_toTopOf="parent">
  17.       
  18.         android:layout_height="0dp"
  19.         android:layout_marginStart="8dp"
  20.         android:layout_marginTop="10dp"
  21.         android:layout_marginEnd="8dp"
  22.         android:layout_marginBottom="8dp"
  23.         android:scrollbars="none"
  24.         app:layout_constraintBottom_toTopOf="@+id/frameLayout"
  25.         app:layout_constraintEnd_toEndOf="parent"
  26.         app:layout_constraintStart_toStartOf="parent"
  27.         app:layout_constraintTop_toBottomOf="@+id/linearLayout6">
  28.         <LinearLayout
  29.             android:layout_width="match_parent"
  30.             android:layout_height="wrap_content"
  31.             android:orientation="vertical">
  32.             <LinearLayout
  33.                 android:layout_width="match_parent"
  34.                 android:layout_height="match_parent"
  35.                 android:background="@drawable/bg_corner_solid_ffffff_12dp"
  36.                 android:orientation="vertical">
  37.                 <TextView
  38.                     android:id="@+id/tv_title"
  39.                     android:layout_width="match_parent"
  40.                     android:layout_height="wrap_content"
  41.                     android:layout_marginLeft="@dimen/default_left_padding"
  42.                     android:layout_marginTop="9.0dip"
  43.                     android:layout_marginRight="@dimen/default_right_padding"
  44.                     android:text="TextView"
  45.                     android:textColor="@color/red_FF0F4B"
  46.                     android:textSize="18sp"
  47.                     android:textStyle="bold" />
  48.                 <TextView
  49.                     android:id="@+id/tv_address"
  50.                     android:layout_width="match_parent"
  51.                     android:layout_height="wrap_content"
  52.                     android:layout_marginLeft="@dimen/default_left_padding"
  53.                     android:layout_marginTop="10dp"
  54.                     android:layout_marginRight="@dimen/default_right_padding"
  55.                     android:text="TextView"
  56.                     android:textColor="@color/black" />
  57.                 <TextView
  58.                     android:id="@+id/tv_name_phone"
  59.                     android:layout_width="match_parent"
  60.                     android:layout_height="wrap_content"
  61.                     android:layout_marginLeft="@dimen/default_left_padding"
  62.                     android:layout_marginTop="5dp"
  63.                     android:layout_marginRight="@dimen/default_right_padding"
  64.                     android:ellipsize="end"
  65.                     android:maxLines="1"
  66.                     android:text="TextView" />
  67.                 <LinearLayout
  68.                     android:id="@+id/ll_dianpu"
  69.                     android:layout_width="match_parent"
  70.                     android:layout_height="match_parent"
  71.                     android:layout_marginLeft="@dimen/default_left_padding"
  72.                     android:layout_marginTop="10dp"
  73.                     android:layout_marginRight="@dimen/default_right_padding"
  74.                     android:layout_marginBottom="10dp"
  75.                     android:orientation="horizontal">
  76.                     <TextView
  77.                         android:id="@+id/textView34"
  78.                         android:layout_width="wrap_content"
  79.                         android:layout_height="wrap_content"
  80.                         android:text="蜜雪冰城(总店)" />
  81.                     <TextView
  82.                         android:id="@+id/textView35"
  83.                         android:layout_width="wrap_content"
  84.                         android:layout_height="wrap_content"
  85.                         android:layout_weight="1"
  86.                         android:gravity="center|right"
  87.                         android:text="订单由第三方骑手配送"
  88.                         android:textColor="@android:color/holo_red_light" />
  89.                 </LinearLayout>
  90.             </LinearLayout>
  91.             <LinearLayout
  92.                 android:layout_width="match_parent"
  93.                 android:layout_height="match_parent"
  94.                 android:layout_marginTop="15dp"
  95.                 android:background="@drawable/bg_corner_solid_ffffff_12dp"
  96.                 android:orientation="vertical">
  97.                 <ListView
  98.                     android:id="@+id/lv"
  99.                     android:layout_width="match_parent"
  100.                     android:layout_height="wrap_content"
  101.                     android:layout_marginLeft="@dimen/default_left_padding"
  102.                     android:layout_marginTop="9.0dip"
  103.                     android:layout_marginRight="@dimen/default_right_padding"
  104.                     android:scrollbars="none" />
  105.                 <LinearLayout
  106.                     android:layout_width="match_parent"
  107.                     android:layout_height="match_parent"
  108.                     android:layout_marginLeft="@dimen/default_left_padding"
  109.                     android:layout_marginTop="9.0dip"
  110.                     android:layout_marginRight="@dimen/default_right_padding"
  111.                     android:gravity="center"
  112.                     android:orientation="horizontal">
  113.                     <TextView
  114.                         android:id="@+id/textView22"
  115.                         android:layout_width="wrap_content"
  116.                         android:layout_height="wrap_content"
  117.                         android:text="配送费"
  118.                         android:textColor="@color/black" />
  119.                     <ImageView
  120.                         android:id="@+id/imageView10"
  121.                         android:layout_width="20dp"
  122.                         android:layout_height="20dp"
  123.                         app:srcCompat="@drawable/icon_question" />
  124.                     <LinearLayout
  125.                         android:layout_width="match_parent"
  126.                         android:layout_height="match_parent"
  127.                         android:layout_weight="1"
  128.                         android:gravity="center|right"
  129.                         android:orientation="horizontal">
  130.                         <TextView
  131.                             android:id="@+id/tv_peisong"
  132.                             android:layout_width="wrap_content"
  133.                             android:layout_height="wrap_content"
  134.                             android:layout_marginLeft="4dp"
  135.                             android:text="¥2"
  136.                             android:textColor="@color/black"
  137.                             android:textSize="14sp" />
  138.                     </LinearLayout>
  139.                 </LinearLayout>
  140.                 <LinearLayout
  141.                     android:layout_width="match_parent"
  142.                     android:layout_height="match_parent"
  143.                     android:layout_marginLeft="@dimen/default_left_padding"
  144.                     android:layout_marginTop="9.0dip"
  145.                     android:layout_marginRight="@dimen/default_right_padding"
  146.                     android:orientation="horizontal">
  147.                     <TextView
  148.                         android:id="@+id/textView26"
  149.                         android:layout_width="wrap_content"
  150.                         android:layout_height="wrap_content"
  151.                         android:layout_weight="1"
  152.                         android:text="打包费"
  153.                         android:textColor="@color/black" />
  154.                     <TextView
  155.                         android:id="@+id/textView27"
  156.                         android:layout_width="wrap_content"
  157.                         android:layout_height="wrap_content"
  158.                         android:layout_weight="1"
  159.                         android:gravity="center|right"
  160.                         android:text="¥0"
  161.                         android:textColor="@color/black" />
  162.                 </LinearLayout>
  163.                 <View
  164.                     android:id="@+id/view6"
  165.                     android:layout_width="match_parent"
  166.                     android:layout_height="1.0dip"
  167.                     android:layout_marginLeft="12.0dip"
  168.                     android:layout_marginTop="10dp"
  169.                     android:layout_marginRight="12.0dip"
  170.                     android:layout_marginBottom="10dp"
  171.                     android:background="@color/grey_F5F5F5" />
  172.               
  173.                 <View
  174.                     android:id="@+id/view7"
  175.                     android:layout_width="match_parent"
  176.                     android:layout_height="1.0dip"
  177.                     android:layout_marginLeft="12.0dip"
  178.                     android:layout_marginTop="10dp"
  179.                     android:layout_marginRight="12.0dip"
  180.                     android:layout_marginBottom="10dp"
  181.                     android:background="@color/grey_F5F5F5" />
  182.                 <LinearLayout
  183.                     android:layout_width="match_parent"
  184.                     android:layout_height="match_parent"
  185.                     android:layout_marginLeft="@dimen/default_left_padding"
  186.                     android:layout_marginTop="5dip"
  187.                     android:layout_marginRight="@dimen/default_right_padding"
  188.                     android:layout_marginBottom="9dip"
  189.                     android:gravity="bottom|center|right"
  190.                     android:orientation="horizontal">
  191.                     <TextView
  192.                         android:id="@+id/tv_num"
  193.                         android:layout_width="wrap_content"
  194.                         android:layout_height="wrap_content"
  195.                         android:text="共计10件,合计 " />
  196.                     <TextView
  197.                         android:id="@+id/tv_total"
  198.                         android:layout_width="wrap_content"
  199.                         android:layout_height="wrap_content"
  200.                         android:text="¥55"
  201.                         android:textColor="@color/black"
  202.                         android:textSize="16sp"
  203.                         android:textStyle="bold" />
  204.                 </LinearLayout>
  205.             </LinearLayout>
  206.             <LinearLayout
  207.                 android:layout_width="match_parent"
  208.                 android:layout_height="match_parent"
  209.                 android:layout_marginTop="15dp"
  210.                 android:background="@drawable/bg_corner_solid_ffffff_12dp"
  211.                 android:orientation="vertical">
  212.                 <TextView
  213.                     android:id="@+id/textView19"
  214.                     android:layout_width="match_parent"
  215.                     android:layout_height="wrap_content"
  216.                     android:layout_marginLeft="@dimen/default_left_padding"
  217.                     android:layout_marginTop="9.0dip"
  218.                     android:layout_marginRight="@dimen/default_right_padding"
  219.                     android:text="支付方式"
  220.                     android:textColor="@color/black"
  221.                     android:textSize="@dimen/text_size_16sp"
  222.                     android:textStyle="bold" />
  223.                 <LinearLayout
  224.                     android:layout_width="match_parent"
  225.                     android:layout_height="match_parent"
  226.                     android:layout_marginLeft="@dimen/default_left_padding"
  227.                     android:layout_marginTop="9.0dip"
  228.                     android:layout_marginRight="@dimen/default_right_padding"
  229.                     android:layout_marginBottom="9dip"
  230.                     android:orientation="vertical">
  231.                     <LinearLayout
  232.                         android:layout_width="match_parent"
  233.                         android:layout_height="wrap_content"
  234.                         android:gravity="center"
  235.                         android:orientation="horizontal">
  236.                         <ImageView
  237.                             android:id="@+id/imageView3"
  238.                             android:layout_width="25dp"
  239.                             android:layout_height="25dp"
  240.                             app:srcCompat="@drawable/icon_pay_wechat" />
  241.                         <TextView
  242.                             android:id="@+id/textView20"
  243.                             android:layout_width="match_parent"
  244.                             android:layout_height="match_parent"
  245.                             android:layout_marginLeft="5dp"
  246.                             android:layout_weight="1"
  247.                             android:gravity="center|left"
  248.                             android:text="微信"
  249.                             android:textColor="@color/black" />
  250.                         <RadioButton
  251.                             android:id="@+id/rb_weixin"
  252.                             android:layout_width="wrap_content"
  253.                             android:layout_height="wrap_content"
  254.                             android:buttonTint="@color/red_FF0F4B"
  255.                             android:checked="true" />
  256.                     </LinearLayout>
  257.                     <LinearLayout
  258.                         android:layout_width="match_parent"
  259.                         android:layout_height="wrap_content"
  260.                         android:layout_marginTop="15dp"
  261.                         android:gravity="center"
  262.                         android:orientation="horizontal">
  263.                         <ImageView
  264.                             android:id="@+id/imageView9"
  265.                             android:layout_width="25dp"
  266.                             android:layout_height="25dp"
  267.                             app:srcCompat="@drawable/icon_pay_alipay" />
  268.                         <TextView
  269.                             android:id="@+id/textView21"
  270.                             android:layout_width="match_parent"
  271.                             android:layout_height="match_parent"
  272.                             android:layout_marginLeft="5dp"
  273.                             android:layout_weight="1"
  274.                             android:gravity="center|left"
  275.                             android:text="支付宝"
  276.                             android:textColor="@color/black" />
  277.                         <RadioButton
  278.                             android:id="@+id/rb_zhifubao"
  279.                             android:layout_width="wrap_content"
  280.                             android:layout_height="wrap_content"
  281.                             android:buttonTint="@color/red_FF0F4B" />
  282.                     </LinearLayout>
  283.                 </LinearLayout>
  284.             </LinearLayout>
  285.             <LinearLayout
  286.                 android:layout_width="fill_parent"
  287.                 android:layout_height="fill_parent"
  288.                 android:layout_gravity="center"
  289.                 android:layout_marginTop="15dp"
  290.                 android:layout_marginBottom="15dp"
  291.                 android:background="@drawable/bg_corner_solid_ffffff_12dp"
  292.                 android:orientation="vertical">
  293.                 <LinearLayout
  294.                     android:id="@+id/tableware_layout"
  295.                     android:layout_width="fill_parent"
  296.                     android:layout_height="wrap_content"
  297.                     android:layout_marginLeft="@dimen/default_left_padding"
  298.                     android:layout_marginTop="9.0dip"
  299.                     android:layout_marginRight="@dimen/default_right_padding"
  300.                     android:layout_marginBottom="4.0dip"
  301.                     android:gravity="center_vertical"
  302.                     android:orientation="horizontal"
  303.                     android:paddingTop="12.0dip"
  304.                     android:paddingBottom="12.0dip">
  305.                     <TextView
  306.                         android:layout_width="wrap_content"
  307.                         android:layout_height="wrap_content"
  308.                         android:layout_marginLeft="12.0dip"
  309.                         android:text="餐具"
  310.                         android:textColor="@color/black"
  311.                         android:textSize="@dimen/text_size_14sp" />
  312.                     <TextView
  313.                         android:id="@+id/tableware"
  314.                         android:layout_width="0.0dip"
  315.                         android:layout_height="wrap_content"
  316.                         android:layout_marginLeft="12.0dip"
  317.                         android:layout_marginRight="4.0dip"
  318.                         android:layout_weight="1.0"
  319.                         android:gravity="center|right"
  320.                         android:hint="按餐量提供"
  321.                         android:singleLine="true"
  322.                         android:textColor="@color/black"
  323.                         android:textSize="@dimen/text_size_14sp" />
  324.                 </LinearLayout>
  325.                 <LinearLayout
  326.                     android:id="@+id/remark_layout"
  327.                     android:layout_width="fill_parent"
  328.                     android:layout_height="wrap_content"
  329.                     android:layout_marginLeft="@dimen/default_left_padding"
  330.                     android:layout_marginTop="5dip"
  331.                     android:layout_marginRight="@dimen/default_right_padding"
  332.                     android:gravity="center_vertical"
  333.                     android:orientation="horizontal"
  334.                     android:paddingTop="12.0dip"
  335.                     android:paddingBottom="12.0dip">
  336.                     <TextView
  337.                         android:layout_width="wrap_content"
  338.                         android:layout_height="wrap_content"
  339.                         android:layout_marginLeft="12.0dip"
  340.                         android:text="备注"
  341.                         android:textColor="@color/black"
  342.                         android:textSize="@dimen/text_size_14sp" />
  343.                     <TextView
  344.                         android:id="@+id/remark"
  345.                         android:layout_width="0.0dip"
  346.                         android:layout_height="wrap_content"
  347.                         android:layout_gravity="center_vertical"
  348.                         android:layout_marginLeft="12.0dip"
  349.                         android:layout_marginRight="4.0dip"
  350.                         android:layout_weight="1.0"
  351.                         android:ellipsize="end"
  352.                         android:gravity="center|right"
  353.                         android:hint="暂不支持通过备注定制口味"
  354.                         android:singleLine="true"
  355.                         android:textColor="@color/black"
  356.                         android:textSize="@dimen/text_size_14sp" />
  357.                 </LinearLayout>
  358.             </LinearLayout>
  359.         </LinearLayout>
  360.     </ScrollView>
  361.     <FrameLayout
  362.         android:id="@+id/frameLayout"
  363.         android:layout_width="match_parent"
  364.         android:layout_height="wrap_content"
  365.         android:layout_gravity="bottom"
  366.         android:background="@color/white"
  367.         android:orientation="horizontal"
  368.         app:layout_constraintBottom_toBottomOf="parent"
  369.         app:layout_constraintEnd_toEndOf="parent"
  370.         app:layout_constraintStart_toStartOf="parent">
  371.         <View
  372.             android:id="@+id/bottom_line"
  373.             android:layout_width="fill_parent"
  374.             android:layout_height="0.5dip"
  375.             android:background="@color/grey_eeeeee" />
  376.         <TextView
  377.             android:layout_width="wrap_content"
  378.             android:layout_height="64.0dip"
  379.             android:layout_marginLeft="@dimen/default_left_padding"
  380.             android:gravity="center"
  381.             android:text="实付:"
  382.             android:textColor="@color/black"
  383.             android:textSize="@dimen/text_size_12sp" />
  384.     </FrameLayout>
  385. </androidx.constraintlayout.widget.ConstraintLayout>
复制代码
8.我的页面、关于我们页面


 这两个页面只用来显示登录和退出登录然后跳转编辑资料页面使用
9.编辑资料页面

这段代码实现了一个用户信息管理页面的 Android 活动(Activity),功能包罗:
- 显示用户的手机号、用户名和密码,并答应用户修改并生存这些信息。
- 使用 `SharedPreferences` 获取用户的手机号,通过 `UserHelper` 类从数据库中获取和更新用户信息。
- 提供返回按钮和生存按钮的点击事件监听,以及生存乐成或失败时的提示信息。
该活动答应用户查看和修改用户名和密码,并将修改后的信息更新到数据库中。

  1. /**
  2.      * 初始化视图组件
  3.      */
  4.     private void initView() {
  5.         // 通过 ID 查找视图组件
  6.         pageBack = findViewById(R.id.page_back);
  7.         etName = findViewById(R.id.et_name);
  8.         etPassword = findViewById(R.id.et_password);
  9.         tvPhone = findViewById(R.id.tv_phone);
  10.         btnSave = findViewById(R.id.btn_save);
  11.         userHelper = new UserHelper(this); // 创建 UserHelper 实例
  12.     }
  13.     /**
  14.      * 设置监听器
  15.      */
  16.     private void setUpListeners() {
  17.         // 设置返回按钮的点击事件
  18.         pageBack.setOnClickListener(v -> finish());
  19.         // 设置保存按钮的点击事件
  20.         btnSave.setOnClickListener(v -> saveUserInfo());
  21.     }
复制代码

四、项目完备源码

   
回复

使用道具 举报

0 个回复

倒序浏览

快速回复

您需要登录后才可以回帖 登录 or 立即注册

本版积分规则

莱莱

论坛元老
这个人很懒什么都没写!
快速回复 返回顶部 返回列表