Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (1.49 MB, 89 trang )
<span class="text_page_counter">Trang 1</span><div class="page_container" data-page="1">
<i>Figure 1 Login </i>
public class MainActivity extends AppCompatActivity { private EditText usernameEditText, passwordEditText; private SharedPreferences sharedPreferences;
private static final String PREFS_NAME = "MyPrefs";
public void onLoginClick(View view) { String username = getUsernameInput(); String password = getPasswordInput();
private String getUsernameInput() {
return usernameEditText.getText().toString(); }
</div><span class="text_page_counter">Trang 9</span><div class="page_container" data-page="9"><?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android=" xmlns:app="
private String getPasswordInput() {
return passwordEditText.getText().toString(); }
private boolean isUsernameRegistered(String username) { return sharedPreferences.contains(username);
}
private String getSavedPassword(String username) { return sharedPreferences.getString(username, "");
private void showLoginSuccessMessage() {
<i> Toast.makeText(this, </i>"Logged in successfully", Toast.LENGTH_SHORT).show();
}
private Intent createMainScreenIntent(String username) { Intent mainScreenIntent = new Intent(this, Home.class); mainScreenIntent.putExtra("username", username);
return mainScreenIntent; }
private void showPasswordErrorMessage() {
<i> Toast.makeText(this, </i>"Password error", Toast.LENGTH_SHORT).show();
}
private void showUsernameNotFoundMessage() {
<i> Toast.makeText(this, </i>"Username not found",
private void startRegisterActivity() {
Intent intent = new Intent(MainActivity.this, RegisterActivity.class);
startActivity(intent); }
}
</div><span class="text_page_counter">Trang 10</span><div class="page_container" data-page="10">xmlns:tools=" android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/background_walking" android:orientation="vertical"
android:padding="16dp"
tools:context="com.example.HikingApp_GCS200222.MainActivity"> <ImageView
android:id="@+id/imageView5"
android:layout_width="wrap_content"
android:id="@+id/usernameEditText" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="16dp" android:hint="Username"
android:minHeight="48dp" /> <EditText
android:id="@+id/passwordEditText" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="16dp" android:hint="Password"
android:inputType="textPassword" android:minHeight="48dp" /> <Button
android:id="@+id/loginButton"
android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="16dp"
android:backgroundTint="@android:color/holo_blue_light" android:text="Login"
android:onClick="onLoginClick" /> <Button
android:id="@+id/registerButton" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="16dp"
android:backgroundTint="@android:color/holo_blue_light" android:text="Register"
android:onClick="onRegisterClick" /> </LinearLayout>
<i>Figure 2 Register </i>
package com.example.HikingApp_GCS200222; import android.content.Intent;
import android.content.SharedPreferences; import android.os.Bundle;
</div><span class="text_page_counter">Trang 13</span><div class="page_container" data-page="13">public class RegisterActivity extends AppCompatActivity { private EditText fullNameEditText, namescreenEditText, usernameEditText, passwordEditText, confirmPasswordEditText; private SharedPreferences sharedPreferences;
private static final String PREFS_NAME = "MyPrefs";
public void onRegisterClick(View view) {
String fullName = getEditTextValue(fullNameEditText); String namescreen = getEditTextValue(namescreenEditText); String username = getEditTextValue(usernameEditText); String password = getEditTextValue(passwordEditText);
private boolean validateRegistration(String fullName, String
namescreen, String username, String password, String confirmPassword) {
</div><span class="text_page_counter">Trang 14</span><div class="page_container" data-page="14">if (isEmpty(fullName) || isEmpty(namescreen) || isEmpty(username)
private void saveUserInformation(String username, String password, String fullName, String namescreen) {
SharedPreferences.Editor editor = sharedPreferences.edit(); editor.putString(username, password);
editor.putString(username + "_fullname", fullName); editor.putString(username + "_namescreen", namescreen); editor.apply();
}
private void startMainActivity() {
Intent intent = new Intent(RegisterActivity.this, MainActivity.class);
startActivity(intent); finish();
}
private void showRegistrationFailedMessage() {
<i> Toast.makeText(this, </i>"Registration failed", Toast.LENGTH_SHORT).show();
} }
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android=" xmlns:app="
xmlns:tools=" android:layout_width="match_parent"
android:layout_height="match_parent" android:orientation="vertical"
android:padding="16dp"
android:background="@drawable/background_walking"
tools:context="com.example.HikingApp_GCS200222.RegisterActivity"> <ImageView
android:id="@+id/imageView5"
android:layout_width="match_parent" android:layout_height="236dp"
app:srcCompat="@drawable/pathfit3" />
</div><span class="text_page_counter">Trang 15</span><div class="page_container" data-page="15"><EditText
android:id="@+id/fullNameEditText" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="16dp" android:hint="Full Name"
android:minHeight="48dp" /> <EditText
android:id="@+id/namescreenEditText" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="16dp" android:hint="Namescreen"
android:minHeight="48dp" /> <EditText
android:id="@+id/usernameEditText" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="16dp" android:hint="Username"
android:minHeight="48dp" /> <EditText
android:id="@+id/passwordEditText" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="16dp" android:hint="Password"
android:inputType="textPassword" android:minHeight="48dp" /> <EditText
android:id="@+id/confirmPasswordEditText" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_marginTop="16dp" android:hint="Confirm Password" android:inputType="textPassword" android:minHeight="48dp" /> <Button
android:id="@+id/registerButton" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="16dp"
android:backgroundTint="@android:color/holo_blue_light" android:text="Register"
android:textColor="#E9EFE9" android:textStyle="bold"
android:onClick="onRegisterClick" /> </LinearLayout>
</div><span class="text_page_counter">Trang 16</span><div class="page_container" data-page="16"><i>Figure 3 MainScreen </i>
import androidx.appcompat.app.AppCompatActivity; import com.example.myproject.R;
public class Home extends AppCompatActivity {
private TextView fullNameTextView, namescreenTextView; private SharedPreferences sharedPreferences;
private static final String PREFS_NAME = "MyPrefs"; private VideoView videoView;
private void setupVideoView() {
<i> Uri videoUri = Uri.parse(</i>"android.resource://" + getPackageName()
String username = getIntent().getStringExtra("username"); String fullName = sharedPreferences.getString(username +
fullNameTextView.setText("Full Name"); namescreenTextView.setText("Name Screen");
</div><span class="text_page_counter">Trang 19</span><div class="page_container" data-page="19">public void onClick(View v) {
Intent intent = new Intent(Home.this, destinationClass); startActivity(intent);
} }); }
private void setLogoutButtonAction(int buttonId) { Button logOutButton = findViewById(buttonId);
private void clearUserSession() {
SharedPreferences.Editor editor = sharedPreferences.edit(); editor.remove("username");
editor.apply(); }
private void navigateToLoginScreen() {
Intent loginIntent = new Intent(Home.this, MainActivity.class);
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="
</div><span class="text_page_counter">Trang 20</span><div class="page_container" data-page="20">xmlns:app=" xmlns:tools=" android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/background_walking" android:orientation="vertical"
android:padding="16dp"
tools:context="com.example.HikingApp_GCS200222.Home"> <!-- Full Name -->
<RelativeLayout
android:layout_width="match_parent" android:layout_height="wrap_content"
tools:context="com.example.HikingApp_GCS200222.Home" tools:ignore="ExtraText">
<!-- TextView cho tên đầy đủ --> <TextView
android:id="@+id/fullNameTextView" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentStart="true" android:layout_alignParentTop="true" android:text="Account"
android:textSize="15dp"
tools:ignore="DuplicateIds,TextSizeCheck" /> <!-- TextView cho namescreen -->
<TextView
android:id="@+id/namescreenTextView" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentStart="true" android:layout_below="@id/fullNameTextView"
android:id="@+id/addHikeButton" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="16dp" android:text="Record a Hike"
android:backgroundTint="@android:color/holo_blue_light" /> <Button
android:id="@+id/recordHikeButton" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="16dp" android:text="Google Map"
</div><span class="text_page_counter">Trang 21</span><div class="page_container" data-page="21">android:backgroundTint="@android:color/holo_blue_light" /> <Button
android:id="@+id/planHikeButton" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="16dp" android:text="Observe a Hike"
android:backgroundTint="@android:color/holo_blue_light" /> <Button
android:id="@+id/searchTrailsButton" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="16dp"
android:backgroundTint="@android:color/holo_blue_light" android:text="Shoping" />
<LinearLayout
android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="horizontal">
android:backgroundTint="@android:color/holo_blue_light" android:text="Hiking Rating" /> android:text="Hiking Guide"
android:backgroundTint="@android:color/holo_blue_light" /> android:text="Hiking Chat"
android:backgroundTint="@android:color/holo_blue_light" />
</div><span class="text_page_counter">Trang 22</span><div class="page_container" data-page="22">android:backgroundTint="@android:color/holo_blue_light" /> </LinearLayout>
<Button
android:id="@+id/logoutButton" android:layout_width="wrap_content" android:layout_height="wrap_content"
android:backgroundTint="@android:color/holo_blue_light" android:text="Log Out" />
<VideoView
android:id="@+id/videoView"
android:layout_width="wrap_content" android:layout_height="253dp"
android:layout_marginTop="16dp" /> </LinearLayout>
<i>Figure 4 Hike Planning </i>
package com.example.HikingApp_GCS200222; import android.content.Context;
import android.content.Intent;
</div><span class="text_page_counter">Trang 24</span><div class="page_container" data-page="24">public class AddAHike extends AppCompatActivity {
private EditText hikeNameEditText, hikeLocationEditText,
hikeDateEditText, hikeDistanceEditText, descriptionEditText; private CheckBox parkingCheckBox;
private Spinner difficultySpinner;
private void setupButtonClickListeners() {
Button addHikeButton = findViewById(R.id.addHikeButton); Button listButton = findViewById(R.id.listButton);
Button backButton = findViewById(R.id.backButton);
addHikeButton.setOnClickListener(new View.OnClickListener() {
</div><span class="text_page_counter">Trang 25</span><div class="page_container" data-page="25">private boolean validateFields() {
String hikeName = hikeNameEditText.getText().toString().trim();
</div><span class="text_page_counter">Trang 26</span><div class="page_container" data-page="26">getSharedPreferences("HikeData", Context.MODE_PRIVATE);
int hikeCount = sharedPreferences.getInt("HikeCount", 0) + 1;
SharedPreferences.Editor editor = sharedPreferences.edit(); editor.putString("HikeName" + hikeCount,
private void showSuccessMessage() {
<i> Toast.makeText(AddAHike.this, </i>"Hike added successfully!",
private void startListActivity() {
Intent intent = new Intent(AddAHike.this, Listmain.class); startActivity(intent);
}
private void returnToHomeActivity() {
Intent mainIntent = new Intent(AddAHike.this, Home.class); startActivity(mainIntent);
</div><span class="text_page_counter">Trang 27</span><div class="page_container" data-page="27">android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/background_walking" android:padding="16dp"
tools:context="com.example.HikingApp_GCS200222.AddAHike"> <LinearLayout
android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical"> <EditText
android:id="@+id/hikeNameEditText" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginBottom="16dp" android:hint="Hike Name"
android:inputType="text" android:minHeight="48dp" android:textStyle="bold" />
<EditText
android:id="@+id/hikeLocationEditText" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginBottom="16dp" android:hint="Location"
android:inputType="text" android:minHeight="48dp" android:textStyle="bold" />
<EditText
android:id="@+id/hikeDateEditText" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginBottom="16dp" android:hint="Date"
android:inputType="date"
</div><span class="text_page_counter">Trang 28</span><div class="page_container" data-page="28">android:layout_height="wrap_content" android:layout_marginBottom="16dp"
android:entries="@array/difficulty_levels" android:minHeight="48dp"
tools:ignore="DuplicateIds" android:textStyle="bold" />
<EditText
android:id="@+id/hikeDistanceEditText" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginBottom="16dp" android:hint="Hike Distance (in km)" android:inputType="numberDecimal" android:minHeight="48dp"
android:textStyle="bold" />
<EditText
android:id="@+id/descriptionEditText" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginBottom="16dp" android:hint="Description (Optional)" android:inputType="textMultiLine"
android:id="@+id/parkingCheckBox" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginBottom="16dp" android:text="Has Parking"
android:textStyle="bold" />
<Button
android:id="@+id/addHikeButton" android:layout_width="wrap_content" android:layout_height="wrap_content"
android:backgroundTint="@android:color/holo_blue_light" android:text="Add Hike"
/>
</div><span class="text_page_counter">Trang 29</span><div class="page_container" data-page="29"><Button
android:id="@+id/backButton"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:backgroundTint="@android:color/holo_blue_light" android:text="Back to Main Screen"
android:textStyle="bold"
android:layout_marginTop="25dp" android:layout_marginLeft="150dp" />
<Button
android:id="@+id/listButton"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:backgroundTint="@android:color/holo_blue_light" android:text="List"
<i>Figure 5 Observation </i>
public class ObserveHikeActivity extends AppCompatActivity { private EditText locationEditText, timeEditText,
eventDescriptionEditText,
additionalInfoEditText, noteEditText, titleEditText;
private Button addButton, clearButton, backButton, takePhotoButton; private ListView observationListView;
private Adapter observationAdapter;
private List<Observation> observationList; private ImageView photoImageView;
private SharedPreferences sharedPreferences;
private static final String OBSERVATION_PREFS = "observation_prefs"; private static final int REQUEST_IMAGE_CAPTURE = 1;
</div><span class="text_page_counter">Trang 32</span><div class="page_container" data-page="32">observationListView = findViewById(R.id.observationListView); sharedPreferences = getSharedPreferences(OBSERVATION_PREFS, MODE_PRIVATE);
String json = sharedPreferences.getString("observations", null); Type type = new TypeToken<List<Observation>>() {}.getType(); observationList = new ArrayList<>();
public void onClick(View v) {
Intent intent = new Intent(ObserveHikeActivity.this,
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
</div><span class="text_page_counter">Trang 33</span><div class="page_container" data-page="33">Intent takePictureIntent = new
super.onActivityResult(requestCode, resultCode, data); if (requestCode == REQUEST_IMAGE_CAPTURE && resultCode == RESULT_OK) {
Bundle extras = data.getExtras();
Bitmap imageBitmap = (Bitmap) extras.get("data"); photoImageView.setImageBitmap(imageBitmap);
photoImageView.setVisibility(View.VISIBLE); }
}
private void addObservation() {
String location = locationEditText.getText().toString(); String time = timeEditText.getText().toString();
String eventDescription =
eventDescriptionEditText.getText().toString(); String additionalInfo =
additionalInfoEditText.getText().toString();
String note = noteEditText.getText().toString(); String title = titleEditText.getText().toString();
Observation observation = new Observation(location, time, eventDescription, additionalInfo, note, title);
SharedPreferences.Editor editor = sharedPreferences.edit(); editor.putString("observations", new
Gson().toJson(observationList)); editor.apply();
</div><span class="text_page_counter">Trang 34</span><div class="page_container" data-page="34">SharedPreferences.Editor editor = sharedPreferences.edit(); editor.putString("observations", new android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/background_walking" android:padding="16dp"
tools:context="com.example.HikingApp_GCS200222.ObserveHikeActivity"> <EditText
android:id="@+id/locationEditText" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginBottom="8dp" android:hint="Location"
android:minHeight="48dp" /> <EditText
android:id="@+id/timeEditText" android:layout_width="match_parent"
</div><span class="text_page_counter">Trang 35</span><div class="page_container" data-page="35">android:layout_height="wrap_content"
android:layout_below="@+id/locationEditText" android:layout_marginBottom="8dp"
android:hint="Time"
android:minHeight="48dp" /> <EditText
android:id="@+id/eventDescriptionEditText" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_below="@+id/timeEditText" android:layout_marginBottom="8dp"
android:hint="Event Description" android:minHeight="48dp" /> <EditText
android:id="@+id/additionalInfoEditText" android:layout_width="match_parent" android:layout_height="wrap_content"
android:layout_below="@+id/eventDescriptionEditText" android:layout_marginBottom="8dp"
android:hint="Additional Info" android:minHeight="48dp" /> <EditText
android:id="@+id/noteEditText" android:layout_width="match_parent" android:layout_height="wrap_content"
android:layout_below="@+id/additionalInfoEditText"
android:layout_height="wrap_content" android:layout_below="@+id/noteEditText" android:layout_marginBottom="16dp"
android:hint="Title"
android:minHeight="48dp" /> <Button
android:id="@+id/addButton"
android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/titleEditText" android:layout_marginTop="-2dp"
android:text="Add"
android:backgroundTint="@android:color/holo_blue_light" />
<ListView
android:id="@+id/observationListView" android:layout_width="wrap_content" android:layout_height="189dp"
android:layout_below="@+id/addButton"
</div><span class="text_page_counter">Trang 36</span><div class="page_container" data-page="36">android:layout_marginTop="11dp" /> <Button
android:id="@+id/clearButton"
android:layout_width="wrap_content" android:layout_height="50dp"
android:layout_below="@+id/observationListView" android:layout_marginTop="6dp"
android:minHeight="48dp"
android:text="Clear Observations" tools:ignore="TouchTargetSizeCheck"
android:text="Back"
tools:ignore="TouchTargetSizeCheck"
android:layout_above="@+id/observationListView" android:layout_below="@+id/addButton"
android:layout_alignEnd="@+id/titleEditText" android:layout_marginTop="-54dp"
android:layout_marginEnd="15dp" android:layout_marginBottom="5dp"
android:backgroundTint="@android:color/holo_blue_light" android:text="Take Photo" />
<ImageView
android:id="@+id/photoImageView" android:layout_width="match_parent" android:layout_height="wrap_content"
android:layout_below="@+id/takePhotoButton" android:layout_marginTop="16dp"
android:scaleType="centerCrop" android:visibility="gone" />
</RelativeLayout>
</div><span class="text_page_counter">Trang 37</span><div class="page_container" data-page="37"><i>Figure 6 Google Maps </i>
public class GoogleMapActivity extends AppCompatActivity {
private static final int LOCATION_PERMISSION_REQUEST_CODE = 1;
private void initializeWebViewSettings(WebView webView) { WebSettings webSettings = webView.getSettings(); webSettings.setJavaScriptEnabled(true);
webSettings.setGeolocationEnabled(true);
webView.setWebViewClient(new WebViewClient());
</div><span class="text_page_counter">Trang 40</span><div class="page_container" data-page="40">private void navigateToHomeScreen() {
Intent mainScreenIntent = new Intent(GoogleMapActivity.this, Home.class);
startActivity(mainScreenIntent); }
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull
String[] permissions, @NonNull int[] grantResults) {
android:layout_width="match_parent" android:layout_height="match_parent"> <WebView
android:id="@+id/webView"
android:layout_width="match_parent" android:layout_height="match_parent" />
</div>