Next Steps
Next Steps
Map Integration: For the BusTrackingActivity, you could integrate Google Maps or
other map APIs to show live bus locations.
Backend Integration: For RouteInfoActivity, you could pull real-time bus route data
from a backend server using APIs.
Payment Gateway: For the TicketingActivity, you could integrate a payment system
for ticket purchases (such as Google Pay, Razorpay, etc.).
Styling & Design: You can improve the user interface by adding custom styles and
making the layout responsive for different screen sizes.
gradle
dependencies {
implementation 'com.google.android.gms:play-services-maps:17.0.1'
implementation 'com.google.android.gms:play-services-location:17.0.0'
}
<application
android:name=".MyApplication"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/Theme.AppCompat.Light">
<activity android:name=".BusTrackingActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
import android.os.Bundle;
import androidx.fragment.app.FragmentActivity;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_bus_tracking);
@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
// You can update the bus's location in real-time with the location data
from your server
}
}
<fragment
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</RelativeLayout>
gradle
dependencies {
implementation 'com.squareup.retrofit2:retrofit:2.9.0'
implementation 'com.squareup.retrofit2:converter-gson:2.9.0'
}
package com.example.pmpmlapp;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;
java
package com.example.pmpmlapp;
import retrofit2.Call;
import retrofit2.http.GET;
public interface BusRouteService {
java
package com.example.pmpmlapp;
import com.google.gson.annotations.SerializedName;
import java.util.List;
@SerializedName("routes")
private List<String> routes;
package com.example.pmpmlapp;
import android.os.Bundle;
import android.widget.TextView;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_route_info);
routeInfo = findViewById(R.id.routeInfo);
BusRouteService service =
RetrofitClient.getClient().create(BusRouteService.class);
Call<BusRouteResponse> call = service.getBusRoutes();
call.enqueue(new Callback<BusRouteResponse>() {
@Override
public void onResponse(Call<BusRouteResponse> call,
Response<BusRouteResponse> response) {
if (response.isSuccessful() && response.body() != null) {
StringBuilder routeList = new StringBuilder("Available Routes:\
n");
for (String route : response.body().getRoutes()) {
routeList.append(route).append("\n");
}
routeInfo.setText(routeList.toString());
} else {
Toast.makeText(RouteInfoActivity.this, "Failed to fetch
routes", Toast.LENGTH_SHORT).show();
}
}
@Override
public void onFailure(Call<BusRouteResponse> call, Throwable t) {
Toast.makeText(RouteInfoActivity.this, "Error: " + t.getMessage(),
Toast.LENGTH_SHORT).show();
}
});
}
}
To integrate a payment gateway like Razorpay or Google Pay, you would need to
follow the official SDK integration guide. Below is an outline for using Razorpay:
gradle
dependencies {
implementation 'com.razorpay:checkout:1.6.15'
}
package com.example.pmpmlapp;
import android.os.Bundle;
import android.widget.Button;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
import com.razorpay.Checkout;
import com.razorpay.PaymentResultListener;
import org.json.JSONObject;
Button buyTicketButton;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_ticketing);
buyTicketButton = findViewById(R.id.buyTicketButton);
Checkout.preload(getApplicationContext());
buyTicketButton.setOnClickListener(v -> {
startPayment();
});
}
try {
JSONObject options = new JSONObject();
options.put("name", "PMPML");
options.put("description", "Bus Ticket");
options.put("currency", "INR");
options.put("amount", 100 * 100); // 100 INR in paise
checkout.open(this, options);
} catch (Exception e) {
Toast.makeText(this, "Payment Error: " + e.getMessage(),
Toast.LENGTH_SHORT).show();
}
}
@Override
public void onPaymentSuccess(String s) {
Toast.makeText(this, "Payment Success: " + s, Toast.LENGTH_SHORT).show();
}
@Override
public void onPaymentError(int i, String s) {
Toast.makeText(this, "Payment Failed: " + s, Toast.LENGTH_SHORT).show();
}
}