From 7d83ccaa0a87cb6d18f9abaec0f8098a8e06cfff Mon Sep 17 00:00:00 2001 From: czx <2487755025@qq.com> Date: Mon, 10 Jun 2024 21:55:17 +0800 Subject: [PATCH] 4 --- src/main/AndroidManifest.xml | 3 + .../coffee/AddLocationActivity.java | 14 ++++ .../coffee/HaveLocationFragment.java | 64 +++++++++++++++++++ .../coffee/LocationActivity.java | 18 +++++- .../c202201020117/coffee/MineFragment.java | 5 +- src/main/res/layout/activity_add_location.xml | 9 +++ src/main/res/layout/activity_location.xml | 4 +- .../res/layout/fragment_have_location.xml | 14 ++++ .../res/layout/fragment_none_location.xml | 37 ++++++----- 9 files changed, 147 insertions(+), 21 deletions(-) create mode 100644 src/main/java/com/hnucm/c202201020117/coffee/AddLocationActivity.java create mode 100644 src/main/java/com/hnucm/c202201020117/coffee/HaveLocationFragment.java create mode 100644 src/main/res/layout/activity_add_location.xml create mode 100644 src/main/res/layout/fragment_have_location.xml diff --git a/src/main/AndroidManifest.xml b/src/main/AndroidManifest.xml index 57f4228..18c7532 100644 --- a/src/main/AndroidManifest.xml +++ b/src/main/AndroidManifest.xml @@ -8,6 +8,9 @@ android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/Theme.MyApplication"> + diff --git a/src/main/java/com/hnucm/c202201020117/coffee/AddLocationActivity.java b/src/main/java/com/hnucm/c202201020117/coffee/AddLocationActivity.java new file mode 100644 index 0000000..5207255 --- /dev/null +++ b/src/main/java/com/hnucm/c202201020117/coffee/AddLocationActivity.java @@ -0,0 +1,14 @@ +package com.hnucm.c202201020117.coffee; + +import androidx.appcompat.app.AppCompatActivity; + +import android.os.Bundle; + +public class AddLocationActivity extends AppCompatActivity { + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_add_location); + } +} \ No newline at end of file diff --git a/src/main/java/com/hnucm/c202201020117/coffee/HaveLocationFragment.java b/src/main/java/com/hnucm/c202201020117/coffee/HaveLocationFragment.java new file mode 100644 index 0000000..06c18f5 --- /dev/null +++ b/src/main/java/com/hnucm/c202201020117/coffee/HaveLocationFragment.java @@ -0,0 +1,64 @@ +package com.hnucm.c202201020117.coffee; + +import android.os.Bundle; + +import androidx.fragment.app.Fragment; + +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; + +/** + * A simple {@link Fragment} subclass. + * Use the {@link HaveLocationFragment#newInstance} factory method to + * create an instance of this fragment. + */ +public class HaveLocationFragment extends Fragment { + + // TODO: Rename parameter arguments, choose names that match + // the fragment initialization parameters, e.g. ARG_ITEM_NUMBER + private static final String ARG_PARAM1 = "param1"; + private static final String ARG_PARAM2 = "param2"; + + // TODO: Rename and change types of parameters + private String mParam1; + private String mParam2; + + public HaveLocationFragment() { + // Required empty public constructor + } + + /** + * Use this factory method to create a new instance of + * this fragment using the provided parameters. + * + * @param param1 Parameter 1. + * @param param2 Parameter 2. + * @return A new instance of fragment HaveLocationFragment. + */ + // TODO: Rename and change types and number of parameters + public static HaveLocationFragment newInstance(String param1, String param2) { + HaveLocationFragment fragment = new HaveLocationFragment(); + Bundle args = new Bundle(); + args.putString(ARG_PARAM1, param1); + args.putString(ARG_PARAM2, param2); + fragment.setArguments(args); + return fragment; + } + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + if (getArguments() != null) { + mParam1 = getArguments().getString(ARG_PARAM1); + mParam2 = getArguments().getString(ARG_PARAM2); + } + } + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) { + // Inflate the layout for this fragment + return inflater.inflate(R.layout.fragment_have_location, container, false); + } +} \ No newline at end of file diff --git a/src/main/java/com/hnucm/c202201020117/coffee/LocationActivity.java b/src/main/java/com/hnucm/c202201020117/coffee/LocationActivity.java index 2f2ea7a..594b151 100644 --- a/src/main/java/com/hnucm/c202201020117/coffee/LocationActivity.java +++ b/src/main/java/com/hnucm/c202201020117/coffee/LocationActivity.java @@ -19,10 +19,10 @@ public class LocationActivity extends AppCompatActivity { super.onCreate(savedInstanceState); setContentView(R.layout.activity_location); - ConstraintLayout constraintLayout = findViewById(R.id.constraintLayout20); ConstraintLayout constraintLayout1 = findViewById(R.id.AddAdress); ImageView imageView = findViewById(R.id.imageView2); NoneLocationFragment noneLocationFragment = new NoneLocationFragment(); + HaveLocationFragment haveLocationFragment = new HaveLocationFragment(); imageView.setOnClickListener(new View.OnClickListener() { @Override @@ -33,14 +33,28 @@ public class LocationActivity extends AppCompatActivity { } }); + constraintLayout1.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + Intent intent = new Intent(LocationActivity.this,AddLocationActivity.class); + startActivity(intent); + } + }); + getSupportFragmentManager() .beginTransaction() - .add(R.id.constraintLayout,noneLocationFragment) + .add(R.id.constraintLayout20,noneLocationFragment) + .commit(); + + getSupportFragmentManager() + .beginTransaction() + .add(R.id.constraintLayout20,haveLocationFragment) .commit(); getSupportFragmentManager() .beginTransaction() .show(noneLocationFragment) + .hide(haveLocationFragment) .commit(); } } \ No newline at end of file diff --git a/src/main/java/com/hnucm/c202201020117/coffee/MineFragment.java b/src/main/java/com/hnucm/c202201020117/coffee/MineFragment.java index 7307bad..83b39cf 100644 --- a/src/main/java/com/hnucm/c202201020117/coffee/MineFragment.java +++ b/src/main/java/com/hnucm/c202201020117/coffee/MineFragment.java @@ -3,6 +3,7 @@ package com.hnucm.c202201020117.coffee; import android.content.Intent; import android.os.Bundle; +import androidx.constraintlayout.widget.ConstraintLayout; import androidx.fragment.app.Fragment; import android.view.LayoutInflater; @@ -15,13 +16,15 @@ public class MineFragment extends Fragment { public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.fragment_mine, container, false); - view.findViewById(R.id.constraintLayout15).setOnClickListener(new View.OnClickListener() { + ConstraintLayout constraintLayout = view.findViewById(R.id.constraintLayout15); + constraintLayout.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(getActivity(),LocationActivity.class); startActivity(intent); } }); + // Inflate the layout for this fragment return view; } } \ No newline at end of file diff --git a/src/main/res/layout/activity_add_location.xml b/src/main/res/layout/activity_add_location.xml new file mode 100644 index 0000000..95bedb5 --- /dev/null +++ b/src/main/res/layout/activity_add_location.xml @@ -0,0 +1,9 @@ + + + + \ No newline at end of file diff --git a/src/main/res/layout/activity_location.xml b/src/main/res/layout/activity_location.xml index 25c609c..7d00b66 100644 --- a/src/main/res/layout/activity_location.xml +++ b/src/main/res/layout/activity_location.xml @@ -41,7 +41,7 @@ android:id="@+id/constraintLayout20" android:layout_width="match_parent" android:layout_height="700dp" - android:layout_marginBottom="111dp" + android:layout_marginBottom="110dp" android:background="#F6F6F6" app:layout_constraintBottom_toBottomOf="@+id/AddAdress" app:layout_constraintEnd_toEndOf="parent" @@ -53,7 +53,7 @@ + + + + + + \ No newline at end of file diff --git a/src/main/res/layout/fragment_none_location.xml b/src/main/res/layout/fragment_none_location.xml index 510110b..c309bc7 100644 --- a/src/main/res/layout/fragment_none_location.xml +++ b/src/main/res/layout/fragment_none_location.xml @@ -1,23 +1,28 @@ - - + - - - \ No newline at end of file + + \ No newline at end of file