Courses / Mobile Application Development (CDE-315) – BS CS 5th Semester

Project Step 6 – Profile, Feedback with Undo Countdown, and HTML5 About Page (Labs 2, 3, 6, 11, 13, 15, 17)

Course Project (Java) – Build a Modern Cloud App Step by Step (CampusPulse + 7 ideas) · 150 min read · 5 MCQs to check yourself

Load local HTML files into a WebView

Goal

Finish the remaining screens:

6.1 Profile – fragment_profile.xml

Add your photo as res/drawable/avatar.png (or use @drawable/ic_person).

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent" android:layout_height="match_parent">
<LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content"
    android:orientation="vertical" android:padding="16dp">

    <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content"
        android:background="@drawable/bg_gradient" android:gravity="center_vertical"
        android:orientation="horizontal" android:padding="20dp">
        <com.google.android.material.imageview.ShapeableImageView android:id="@+id/imgAvatar"
            android:layout_width="72dp" android:layout_height="72dp" android:scaleType="centerCrop"
            android:src="@drawable/ic_person" android:background="@color/white"
            app:shapeAppearanceOverlay="@style/CircleImage" android:contentDescription="Profile photo" />
        <LinearLayout android:layout_width="0dp" android:layout_weight="1" android:layout_height="wrap_content"
            android:layout_marginStart="16dp" android:orientation="vertical">
            <TextView android:id="@+id/tvName" android:layout_width="wrap_content" android:layout_height="wrap_content"
                android:textColor="@color/white" android:textSize="20sp" android:textStyle="bold" />
            <TextView android:id="@+id/tvEmail" android:layout_width="wrap_content" android:layout_height="wrap_content"
                android:textColor="@color/white" android:alpha="0.85" />
        </LinearLayout>
    </LinearLayout>

    <com.google.android.material.materialswitch.MaterialSwitch android:id="@+id/swDark"
        android:layout_width="match_parent" android:layout_height="wrap_content"
        android:layout_marginTop="16dp" android:text="Dark mode" />

    <Button android:id="@+id/btnHelpline" style="@style/Widget.Material3.Button.TonalButton"
        android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="8dp"
        android:text="Call the helpline" />
    <Button android:id="@+id/btnWebsite" style="@style/Widget.Material3.Button.TonalButton"
        android:layout_width="match_parent" android:layout_height="wrap_content" android:text="Visit the university website" />
    <Button android:id="@+id/btnInvite" style="@style/Widget.Material3.Button.TonalButton"
        android:layout_width="match_parent" android:layout_height="wrap_content" android:text="Invite a friend by SMS" />
    <Button android:id="@+id/btnSupport" style="@style/Widget.Material3.Button.TonalButton"
        android:layout_width="match_parent" android:layout_height="wrap_content" android:text="Email support" />
    <Button android:id="@+id/btnAbout" style="@style/Widget.Material3.Button.TonalButton"
        android:layout_width="match_parent" android:layout_height="wrap_content" android:text="About this app" />
    <Button android:id="@+id/btnSignOut" style="@style/Widget.Material3.Button.OutlinedButton"
        android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="8dp"
        android:text="Sign out" />
</LinearLayout>
</ScrollView>

ui/ProfileFragment.java

package pk.edu.uni.campuspulse.ui;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import pk.edu.uni.campuspulse.AboutActivity;
import pk.edu.uni.campuspulse.MainActivity;
import pk.edu.uni.campuspulse.Prefs;
import pk.edu.uni.campuspulse.R;
import pk.edu.uni.campuspulse.Util;
import pk.edu.uni.campuspulse.databinding.FragmentProfileBinding;

public class ProfileFragment extends Fragment {

    public ProfileFragment() {
        super(R.layout.fragment_profile);
    }

    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        FragmentProfileBinding b = FragmentProfileBinding.bind(view);
        b.tvName.setText(Prefs.getFullName() != null ? Prefs.getFullName() : "Student");
        b.tvEmail.setText(Prefs.getEmail() != null ? Prefs.getEmail() : "");

        b.swDark.setChecked(Prefs.isDarkMode());
        b.swDark.setOnCheckedChangeListener((button, on) -> Prefs.setDarkMode(on));                      // Lab 10

        b.btnHelpline.setOnClickListener(v -> Util.dial(requireContext(), getString(R.string.helpline_phone))); // Lab 6
        b.btnWebsite.setOnClickListener(v -> Util.browse(requireContext(), getString(R.string.uni_website)));   // Lab 6
        b.btnInvite.setOnClickListener(v -> Util.sms(requireContext(),                                          // Lab 11
                "Join me on " + getString(R.string.app_name) + " – " + getString(R.string.tagline)));
        b.btnSupport.setOnClickListener(v -> Util.email(requireContext(), getString(R.string.support_email),     // Lab 11
                getString(R.string.app_name) + " support", "Hello,\n\n"));
        b.btnAbout.setOnClickListener(v -> startActivity(new Intent(requireContext(), AboutActivity.class)));
        b.btnSignOut.setOnClickListener(v -> ((MainActivity) requireActivity()).signOut());
    }
}

6.2 Feedback – Lab 17 inside the app

fragment_feedback.xml

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent" android:layout_height="match_parent">
<LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content"
    android:orientation="vertical" android:padding="16dp">

    <TextView android:layout_width="wrap_content" android:layout_height="wrap_content"
        android:text="How are we doing?" android:textAppearance="?attr/textAppearanceHeadlineSmall" />

    <TextView android:id="@+id/tvRating" android:layout_width="wrap_content" android:layout_height="wrap_content"
        android:layout_marginTop="12dp" android:text="Rating: 4 / 5" />
    <com.google.android.material.slider.Slider android:id="@+id/slider"
        android:layout_width="match_parent" android:layout_height="wrap_content"
        android:valueFrom="1" android:valueTo="5" android:stepSize="1" android:value="4" />

    <RadioGroup android:id="@+id/rgType" android:layout_width="match_parent"
        android:layout_height="wrap_content" android:orientation="horizontal">
        <RadioButton android:id="@+id/rbSuggestion" android:layout_width="wrap_content"
            android:layout_height="wrap_content" android:text="Suggestion" android:checked="true" />
        <RadioButton android:id="@+id/rbComplaint" android:layout_width="wrap_content"
            android:layout_height="wrap_content" android:layout_marginStart="16dp" android:text="Complaint" />
        <RadioButton android:id="@+id/rbPraise" android:layout_width="wrap_content"
            android:layout_height="wrap_content" android:layout_marginStart="16dp" android:text="Praise" />
    </RadioGroup>

    <com.google.android.material.textfield.TextInputLayout android:id="@+id/tilMessage"
        android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="8dp"
        android:hint="Your message" style="@style/Widget.Material3.TextInputLayout.OutlinedBox">
        <com.google.android.material.textfield.TextInputEditText android:id="@+id/etMessage"
            android:layout_width="match_parent" android:layout_height="wrap_content"
            android:inputType="textMultiLine|textCapSentences" android:minLines="4" android:gravity="top" />
    </com.google.android.material.textfield.TextInputLayout>

    <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content"
        android:gravity="center_vertical" android:orientation="horizontal">
        <TextView android:id="@+id/tvLocation" android:layout_width="0dp" android:layout_weight="1"
            android:layout_height="wrap_content" android:text="📍 Location not attached" />
        <Button android:id="@+id/btnLocation" style="@style/Widget.Material3.Button.TextButton"
            android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Attach location" />
    </LinearLayout>

    <Button android:id="@+id/btnSubmit" android:layout_width="match_parent" android:layout_height="wrap_content"
        android:layout_marginTop="8dp" android:text="Submit" />

    <!-- 10-second undo window (Lab 13 + Lab 17) -->
    <LinearLayout android:id="@+id/countdownBox" android:layout_width="match_parent"
        android:layout_height="wrap_content" android:gravity="center_vertical"
        android:orientation="horizontal" android:visibility="gone">
        <TextView android:id="@+id/tvCountdown" android:layout_width="0dp" android:layout_weight="1"
            android:layout_height="wrap_content" android:textSize="18sp" android:textStyle="bold" />
        <Button android:id="@+id/btnCancel" style="@style/Widget.Material3.Button.OutlinedButton"
            android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Cancel" />
    </LinearLayout>
</LinearLayout>
</ScrollView>

ui/FeedbackFragment.java

package pk.edu.uni.campuspulse.ui;

import android.Manifest;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.view.View;

import androidx.activity.result.ActivityResultLauncher;
import androidx.activity.result.contract.ActivityResultContracts;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import com.google.android.material.snackbar.Snackbar;

import java.util.Locale;

import pk.edu.uni.campuspulse.Prefs;
import pk.edu.uni.campuspulse.R;
import pk.edu.uni.campuspulse.Util;
import pk.edu.uni.campuspulse.data.Feedback;
import pk.edu.uni.campuspulse.data.Repository;
import pk.edu.uni.campuspulse.databinding.FragmentFeedbackBinding;

public class FeedbackFragment extends Fragment {
    private FragmentFeedbackBinding b;
    private CountDownTimer timer;
    private Double lat, lng;

    private final ActivityResultLauncher<String[]> locationPermission = registerForActivityResult(
            new ActivityResultContracts.RequestMultiplePermissions(), result -> {
                if (result.containsValue(true)) attachLocation();
                else Util.toast(getContext(), "Location permission denied");
            });

    public FeedbackFragment() {
        super(R.layout.fragment_feedback);
    }

    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        b = FragmentFeedbackBinding.bind(view);
        b.slider.addOnChangeListener((slider, value, fromUser) ->
                b.tvRating.setText("Rating: " + (int) value + " / 5"));
        b.btnLocation.setOnClickListener(v -> locationPermission.launch(new String[]{
                Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.ACCESS_COARSE_LOCATION}));
        b.btnSubmit.setOnClickListener(v -> startUndoWindow());
        b.btnCancel.setOnClickListener(v -> cancelUndoWindow());
    }

    private void attachLocation() {
        b.tvLocation.setText("📍 Finding you…");
        Util.currentLocation(requireContext(), loc -> {
            if (b == null) return;
            if (loc == null) {
                b.tvLocation.setText("📍 Location unavailable");
                return;
            }
            lat = loc.getLatitude();
            lng = loc.getLongitude();
            b.tvLocation.setText(String.format(Locale.US, "📍 %.5f, %.5f", lat, lng));
        });
    }

    private String category() {
        int id = b.rgType.getCheckedRadioButtonId();
        if (id == R.id.rbComplaint) return "Complaint";
        if (id == R.id.rbPraise) return "Praise";
        return "Suggestion";
    }

    // Lab 13 + 17: 10 seconds to change your mind
    private void startUndoWindow() {
        if (String.valueOf(b.etMessage.getText()).trim().length() < 10) {
            b.tilMessage.setError("Write at least 10 characters");
            return;
        }
        b.tilMessage.setError(null);
        b.btnSubmit.setEnabled(false);
        b.countdownBox.setVisibility(View.VISIBLE);
        timer = new CountDownTimer(10_000, 1_000) {
            @Override
            public void onTick(long left) {
                b.tvCountdown.setText(getString(R.string.sending_in, (int) ((left + 999) / 1000)));
            }

            @Override
            public void onFinish() {
                send();
            }
        }.start();
    }

    private void cancelUndoWindow() {
        if (timer != null) timer.cancel();
        b.countdownBox.setVisibility(View.GONE);
        b.btnSubmit.setEnabled(true);
    }

    private void send() {
        Feedback feedback = new Feedback((int) b.slider.getValue(), category(),
                String.valueOf(b.etMessage.getText()).trim(), lat, lng);
        b.countdownBox.setVisibility(View.GONE);
        Repository.sendFeedback(feedback, new Repository.Result<Void>() {
            @Override
            public void ok(Void nothing) {
                if (b == null) return;
                b.btnSubmit.setEnabled(true);
                b.etMessage.setText("");
                Snackbar.make(b.getRoot(), "Thank you! Feedback sent ✅", Snackbar.LENGTH_LONG)
                        .setAction("Email a copy", v -> emailCopy(feedback))
                        .show();
            }

            @Override
            public void fail(String message) {
                if (b != null) b.btnSubmit.setEnabled(true);
                Util.toast(getContext(), message);
            }
        });
    }

    private void emailCopy(Feedback f) {
        String where = f.lat != null ? "\nLocation: https://maps.google.com/?q=" + f.lat + "," + f.lng : "";
        String from = (Prefs.getFullName() != null ? Prefs.getFullName() : "") + " (" + (Prefs.getEmail() != null ? Prefs.getEmail() : "") + ")";
        Util.email(requireContext(), getString(R.string.support_email),
                f.category + " – " + getString(R.string.app_name),
                "From: " + from + "\nRating: " + f.rating + "/5\n\n" + f.message + where);
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        if (timer != null) timer.cancel();   // never leave a timer running for a closed screen
        b = null;
    }
}

6.3 About page – HTML5 in a WebView (Lab 2)

  1. Right-click app → New → Folder → Assets Folder → Finish.
  2. In app/src/main/assets create about.html:
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>About CampusPulse</title>
  <style>
    :root { --accent: #6C4DFF; --teal: #00C2B2; --bg: #ffffff; --text: #1b1b1f; }
    @media (prefers-color-scheme: dark) { :root { --bg: #0B1026; --text: #e7e7ee; } }
    body { margin: 0; font-family: system-ui, sans-serif; background: var(--bg); color: var(--text); }
    header { padding: 32px 20px; color: #fff; background: linear-gradient(135deg, var(--accent), var(--teal)); }
    h1 { margin: 0; font-size: 1.8rem; }
    main { padding: 20px; max-width: 640px; margin: auto; }
    .card { border: 1px solid rgba(127,127,127,.25); border-radius: 16px; padding: 16px; margin: 12px 0; }
    img { max-width: 100%; height: auto; }
    a.btn { display: inline-block; padding: 12px 18px; border-radius: 999px; background: var(--accent);
            color: #fff; text-decoration: none; }
    input, textarea { width: 100%; box-sizing: border-box; padding: 10px; margin: 6px 0;
                      border-radius: 10px; border: 1px solid #999; font: inherit; }
  </style>
</head>
<body>
  <header>
    <h1>CampusPulse</h1>
    <p>Your campus, live.</p>
  </header>
  <main>
    <section class="card">
      <h2>What it does</h2>
      <ul>
        <li>See upcoming campus events with a live countdown</li>
        <li>Find the venue on the map, call or email the organiser</li>
        <li>Post events and send feedback – stored securely in the cloud</li>
      </ul>
    </section>
    <section class="card">
      <h2>Built with</h2>
      <p>Java · Material 3 · Retrofit · Supabase (PostgreSQL)</p>
    </section>
    <section class="card">
      <h2>Suggest a feature</h2>
      <form action="mailto:support@example.edu.pk" method="post" enctype="text/plain">
        <input name="name" placeholder="Your name" required>
        <textarea name="idea" rows="3" placeholder="Your idea" required></textarea>
        <a class="btn" href="mailto:support@example.edu.pk?subject=CampusPulse%20idea">Send by email</a>
      </form>
    </section>
    <p>Version 1.0 · Made by BSCS-5 students</p>
  </main>
</body>
</html>
  1. Create AboutActivity (Empty Views Activity). Layout activity_about.xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical">
    <com.google.android.material.appbar.MaterialToolbar android:id="@+id/toolbar"
        android:layout_width="match_parent" android:layout_height="?attr/actionBarSize" app:title="About" />
    <WebView android:id="@+id/web" android:layout_width="match_parent" android:layout_height="match_parent" />
</LinearLayout>

AboutActivity.java

package pk.edu.uni.campuspulse;

import android.os.Bundle;
import android.webkit.WebResourceRequest;
import android.webkit.WebView;
import android.webkit.WebViewClient;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;

import pk.edu.uni.campuspulse.databinding.ActivityAboutBinding;

public class AboutActivity extends AppCompatActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        EdgeToEdge.enable(this);
        ActivityAboutBinding b = ActivityAboutBinding.inflate(getLayoutInflater());
        setContentView(b.getRoot());
        Util.applyInsets(b.getRoot(), true);
        setSupportActionBar(b.toolbar);
        if (getSupportActionBar() != null) getSupportActionBar().setDisplayHomeAsUpEnabled(true); // back arrow
        b.toolbar.setNavigationOnClickListener(v -> finish());

        // Open links (mailto:, https:) in the right app instead of inside the WebView
        b.web.setWebViewClient(new WebViewClient() {
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
                String url = request.getUrl().toString();
                if (url.startsWith("mailto:")) {
                    String to = url.substring("mailto:".length()).split("\\?")[0];
                    Util.email(AboutActivity.this, to, "CampusPulse idea", "");
                } else {
                    Util.browse(AboutActivity.this, url);
                }
                return true;
            }
        });
        b.web.loadUrl("file:///android_asset/about.html");
    }
}

Manifest: Android Studio already added AboutActivity; add android:parentActivityName=".MainActivity" to it. Now restore the real action_refresh and action_about code in MainActivity (Step 2) if you replaced it with toasts.

Check before moving on

Adapt it to your project

Change the About page text and colours, the helpline and website strings, and the feedback categories (e.g. HealthMate – Doctor, Clinic, App).

🎉 Your app now works fully offline – a good point for the mid-term demo. Next: the cloud.

Short and long questions

1. Project viva: Why is there a 10-second countdown before feedback is sent?

Model answer

It gives the user an undo window (like Gmail "undo send"). A CountDownTimer shows "Sending in N s"; Cancel stops it; onFinish calls send(), which saves the feedback through the Repository and offers to email a copy.

This lesson ends with a quiz of 5 MCQs. Open the lesson on PrepOasis to take it and save your progress.

Previous: Project Step 5 – Post an Event: Date/Time Pickers, Current Location and Notification (Labs 6, 7, 15) · Next: Project Step 7 – Supabase Backend for Your App: Tables, Row Level Security and Email Sign-in

All lessons in Mobile Application Development (CDE-315) – BS CS 5th Semester