diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 0ab3320..c6f0d7a 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -11,24 +11,24 @@ android:supportsRtl="true" android:theme="@style/Theme.MyApplication" tools:targetApi="31"> - + + - - - \ No newline at end of file diff --git a/app/src/main/java/cc/liuyx/app/MainActivity.java b/app/src/main/java/cc/liuyx/app/MainActivity.java new file mode 100644 index 0000000..84fbb13 --- /dev/null +++ b/app/src/main/java/cc/liuyx/app/MainActivity.java @@ -0,0 +1,45 @@ +package cc.liuyx.app; + +import android.annotation.SuppressLint; +import android.content.SharedPreferences; +import android.os.Bundle; +import android.util.Log; +import android.view.View; + +import androidx.appcompat.app.AppCompatActivity; +import androidx.fragment.app.FragmentManager; +import androidx.fragment.app.FragmentTransaction; + +import cc.liuyx.app.fragment.MainFragment; +import cc.liuyx.app.fragment.InfoFragment; + +public class MainActivity extends AppCompatActivity { + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_main); + + SharedPreferences preferences = getSharedPreferences("loginStatus", MODE_PRIVATE); + Log.i("log", preferences.getString("username", "no name")); + } + + @SuppressLint("NonConstantResourceId") + public void selectFragment(View view) { + FragmentManager fm = getSupportFragmentManager(); + FragmentTransaction ft = fm.beginTransaction(); + + MainFragment firstFragment = new MainFragment(); + InfoFragment infoFragment = new InfoFragment(); + + switch (view.getId()) { + case R.id.page_main: + ft.replace(R.id.page_blank, firstFragment); + break; + case R.id.page_info: + ft.replace(R.id.page_blank, infoFragment); + break; + } + ft.commit(); + } +} \ No newline at end of file diff --git a/app/src/main/java/cc/liuyx/app/RegisterActivity.java b/app/src/main/java/cc/liuyx/app/RegisterActivity.java index 715f9ba..ad0f5d4 100644 --- a/app/src/main/java/cc/liuyx/app/RegisterActivity.java +++ b/app/src/main/java/cc/liuyx/app/RegisterActivity.java @@ -53,7 +53,7 @@ public class RegisterActivity extends AppCompatActivity implements View.OnClickL } private void validateRegister() { - Intent intent = new Intent(RegisterActivity.this, UserInfoActivity.class); + Intent intent = new Intent(RegisterActivity.this, MainActivity.class); username = usernameEdit.getText().toString(); passwd = passwdEdit.getText().toString(); diff --git a/app/src/main/java/cc/liuyx/app/fragment/InfoFragment.java b/app/src/main/java/cc/liuyx/app/fragment/InfoFragment.java new file mode 100644 index 0000000..38631bd --- /dev/null +++ b/app/src/main/java/cc/liuyx/app/fragment/InfoFragment.java @@ -0,0 +1,19 @@ +package cc.liuyx.app.fragment; + +import android.os.Bundle; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; + +import androidx.fragment.app.Fragment; + +import cc.liuyx.app.R; + +public class InfoFragment extends Fragment { + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) { + return inflater.inflate(R.layout.fragment_info, container, false); + } +} \ No newline at end of file diff --git a/app/src/main/java/cc/liuyx/app/fragment/MainFragment.java b/app/src/main/java/cc/liuyx/app/fragment/MainFragment.java new file mode 100644 index 0000000..489aee9 --- /dev/null +++ b/app/src/main/java/cc/liuyx/app/fragment/MainFragment.java @@ -0,0 +1,19 @@ +package cc.liuyx.app.fragment; + +import android.os.Bundle; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; + +import androidx.fragment.app.Fragment; + +import cc.liuyx.app.R; + +public class MainFragment extends Fragment { + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) { + return inflater.inflate(R.layout.fragment_main, container, false); + } +} \ No newline at end of file diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml new file mode 100644 index 0000000..6737081 --- /dev/null +++ b/app/src/main/res/layout/activity_main.xml @@ -0,0 +1,43 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_info.xml b/app/src/main/res/layout/fragment_info.xml new file mode 100644 index 0000000..35f158b --- /dev/null +++ b/app/src/main/res/layout/fragment_info.xml @@ -0,0 +1,207 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +