Skip to content

Commit

Permalink
final
Browse files Browse the repository at this point in the history
  • Loading branch information
Lavanyagaur22 committed Sep 29, 2018
1 parent 857a0f8 commit 3368c13
Show file tree
Hide file tree
Showing 7 changed files with 81 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ public void onClick(View v) {

Log.e("TAG", "onClick12345: "+holder.number.toString());
Intent callIntent = new Intent(Intent.ACTION_CALL);
callIntent.setData(Uri.parse("tel://"+holder.number.toString()));//change the number
callIntent.setData(Uri.parse("tel://"+holder.number.getText().toString()));//change the number
startActivity(callIntent);

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ protected void onCreate(Bundle savedInstanceState) {
Log.d("TAG", "onCreate: "+estimatedArrivalTime.toString());

Intent alarmIntent = new Intent(OngoingTripActivity.this, YesNoActivity.class);
alarmIntent.putExtra(getString(R.string.vehicle_number), getIntent().getStringExtra(getString(R.string.vehicle_number)));
alarmIntent.putExtra(getString(R.string.transport_mode), getIntent().getStringExtra(getString(R.string.transport_mode)));
PendingIntent pendingIntent = PendingIntent.getActivity(OngoingTripActivity.this, 0,
alarmIntent, PendingIntent.FLAG_UPDATE_CURRENT);

Expand All @@ -74,6 +76,8 @@ protected void onCreate(Bundle savedInstanceState) {
@Override
public void onClick(View view) {
Intent endIntent = new Intent(OngoingTripActivity.this, YesNoActivity.class);
endIntent.putExtra(getString(R.string.vehicle_number), getIntent().getStringExtra(getString(R.string.vehicle_number)));
endIntent.putExtra(getString(R.string.transport_mode), getIntent().getStringExtra(getString(R.string.transport_mode)));
startActivity(endIntent);
}
});
Expand Down
14 changes: 13 additions & 1 deletion app/src/main/java/com/codingblocks/suraksha/Police.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import android.Manifest;
import android.animation.LayoutTransition;
import android.annotation.SuppressLint;
import android.app.LauncherActivity;
import android.app.ProgressDialog;
import android.content.Context;
Expand Down Expand Up @@ -48,13 +49,24 @@ public Viewholder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
}

@Override
public void onBindViewHolder(@NonNull Viewholder viewholder, int i) {
public void onBindViewHolder(@NonNull final Viewholder viewholder, int i) {

PoliceDetail p=policeDetails.get(i);
viewholder.number.setText(p.getNumber());
viewholder.name.setText(p.getPoliceStation());
viewholder.imageView.setImageResource(R.drawable.police);

viewholder.name.setOnClickListener(new View.OnClickListener() {
@SuppressLint("MissingPermission")
@Override
public void onClick(View v) {
Log.e("TAG", "onClick12345: "+viewholder.number.toString());
Intent callIntent = new Intent(Intent.ACTION_CALL);
callIntent.setData(Uri.parse("tel://"+viewholder.number.getText().toString()));//change the number
context.startActivity(callIntent);
}
});

}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ProgressBar;
import android.widget.Spinner;
import android.widget.TextView;

Expand All @@ -27,15 +29,22 @@ public class StartTripActivity extends AppCompatActivity {

private static final String TAG = "TAG";
TextView tvTime;
EditText etVehicleNo;
Spinner transportDropdown;
ProgressBar p;


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_start_trip);

etVehicleNo=findViewById(R.id.etVehicleNo);
final Spinner startDropdown = findViewById(R.id.spinnerStart);
final Spinner endDropdown = findViewById(R.id.spinnerDestination);
final Spinner transportDropdown = findViewById(R.id.spinnerTransportMode);
transportDropdown = findViewById(R.id.spinnerTransportMode);

p=findViewById(R.id.progressbar);

tvTime = findViewById(R.id.tvTime);
Button btnEstimate = findViewById(R.id.btnEstimate);
Expand Down Expand Up @@ -81,6 +90,7 @@ public void fetchRouteDetails(final int transportMode, Context context, String s
String apiKey = context.getString(R.string.api_key);
String url = baseUrl+start+":"+end+json+apiKey;

p.setVisibility(View.VISIBLE);
Log.d(TAG, "fetchRouteDetails: "+url);
OkHttpClient okHttpClient = new OkHttpClient();
final Request request = new Request.Builder()
Expand All @@ -91,13 +101,26 @@ public void fetchRouteDetails(final int transportMode, Context context, String s
@Override
public void onFailure(Call call, IOException e) {

StartTripActivity.this.runOnUiThread(new Runnable() {
@Override
public void run() {
p.setVisibility(View.INVISIBLE);
}
});
}

@Override
public void onResponse(Call call, Response response) throws IOException {
Gson gson = new Gson();
String result1 = response.body().string();
String result = result1.replace("callback(", "");
StartTripActivity.this.runOnUiThread(new Runnable() {
@Override
public void run() {
p.setVisibility(View.INVISIBLE);
}
});

result = result.substring(0, result.length()-1);
final RouteDetails routeDetails = gson.fromJson(result, RouteDetails.class);
Log.d(TAG, "onResponse: "+routeDetails.getRoutes()[0].getSummary().getTravelTimeInSeconds());
Expand All @@ -111,6 +134,10 @@ public void run() {
Intent ongoingIntent = new Intent(StartTripActivity.this, OngoingTripActivity.class);
String finalEstimationTime = getEstimationTime(transportMode, routeDetails.getRoutes()[0].getSummary().getTravelTimeInSeconds());
ongoingIntent.putExtra(getString(R.string.estimated_time), finalEstimationTime);


ongoingIntent.putExtra(getString(R.string.vehicle_number),etVehicleNo.getText().toString());
ongoingIntent.putExtra(getString(R.string.transport_mode), transportDropdown.getSelectedItem().toString());
startActivity(ongoingIntent);
}
});
Expand Down
13 changes: 12 additions & 1 deletion app/src/main/java/com/codingblocks/suraksha/YesNoActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,18 @@ private void gameOver() {
// );


String sms = "I am in trouble . Please help me out! My current location is :- \n\n https://www.google.com/maps/@28.7298838,76.7325634,11z";
String sms = "I am in trouble. Please help me out! My current location is :- \n\n https://www.google.com/maps/@28.7298838,76.7325634,11z";
String vehicleNo = getIntent().getStringExtra(getString(R.string.vehicle_number));
String transportMode = getIntent().getStringExtra(getString(R.string.transport_mode));

if(transportMode.length()!=0){
sms+=" I last boarded in a "+transportMode+". ";
}

if(vehicleNo.length()>4){
sms+="The vehicle number was "+vehicleNo;
}

// Create the intent.
Intent smsIntent = new Intent(Intent.ACTION_SENDTO);
// Set the data for the intent as the phone number.
Expand Down
22 changes: 21 additions & 1 deletion app/src/main/res/layout/activity_start_trip.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,37 @@
android:layout_width="match_parent"
android:layout_height="56dp"
android:layout_margin="5dp"
android:textColor="@android:color/white"
android:textColorHint="#FEF7E8"

android:hint="Enter Vehicle Number"/>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">



<Button
android:id="@+id/btnEstimate"
android:layout_width="150dp"
android:layout_width="0dp"
android:layout_weight="2"
android:layout_height="55dp"
android:layout_gravity="center"
android:layout_margin="20dp"
android:layout_marginLeft="20dp"
android:background="#FEF7E8"
android:text="Estimate Time" />

<ProgressBar
android:layout_marginTop="18dp"
android:id="@+id/progressbar"
android:visibility="invisible"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content" />

</LinearLayout>

</LinearLayout>
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,7 @@
<string name="title_activity_yes_no">YesNoActivity</string>
<string name="appwidget_text">EXAMPLE</string>
<string name="add_widget">Add widget</string>
<string name="vehicle_number">Vehicle number</string>
<string name="transport_mode">Transportation mode</string>

</resources>

0 comments on commit 3368c13

Please sign in to comment.