Android Assignment

master
Chloe Fontenot 🏳️‍⚧️ 2024-03-25 09:25:36 +07:00
parent a0c43c41d0
commit ca4d18d1b6
12 changed files with 101 additions and 57 deletions

@ -4,18 +4,18 @@
<value>
<entry key="app">
<State>
<targetSelectedWithDropDown>
<runningDeviceTargetSelectedWithDropDown>
<Target>
<type value="QUICK_BOOT_TARGET" />
<type value="RUNNING_DEVICE_TARGET" />
<deviceKey>
<Key>
<type value="VIRTUAL_DEVICE_PATH" />
<value value="$USER_HOME$/.android/avd/Pixel_3a_API_34_extension_level_7_x86_64.avd" />
<type value="SERIAL_NUMBER" />
<value value="29261FDH3008Z2" />
</Key>
</deviceKey>
</Target>
</targetSelectedWithDropDown>
<timeTargetWasSelectedWithDropDown value="2024-03-18T14:22:25.262676Z" />
</runningDeviceTargetSelectedWithDropDown>
<timeTargetWasSelectedWithDropDown value="2024-03-22T22:39:37.121280231Z" />
</State>
</entry>
</value>

@ -8,7 +8,7 @@ android {
defaultConfig {
applicationId = "asdv.lisset.criminalintent3"
minSdk = 21
minSdk = 24
targetSdk = 34
versionCode = 1
versionName = "1.0"

@ -3,6 +3,9 @@ package asdv.lisset.criminalintent;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import androidx.annotation.Nullable;
import androidx.fragment.app.DialogFragment;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
@ -32,6 +35,7 @@ public class CrimeFragment extends Fragment {
private static final String DIALOG_DATE =
"DialogDate";
private static final int REQUEST_DATE = 0;
public static final int REQUEST_TIME = 101;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@ -64,6 +68,7 @@ public class CrimeFragment extends Fragment {
@Override
public void onClick(View v)
{
// Open DatePickerFragment
FragmentManager manager = getFragmentManager();
DatePickerFragment dialog = DatePickerFragment.newInstance(crime.getDate());
dialog.setTargetFragment(CrimeFragment.this, REQUEST_DATE);
@ -107,19 +112,37 @@ public class CrimeFragment extends Fragment {
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode != Activity.RESULT_OK) {
return;
}
public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == REQUEST_DATE) {
Date date = (Date) data
.getSerializableExtra(DatePickerFragment.EXTRA_DATE);
crime.setDate(date);
// Open TimePickerFragment
DialogFragment timePicker = new TimePickerFragment();
timePicker.show(getActivity().getSupportFragmentManager(), "timePicker");
updateDate();
Intent intent = new Intent();
intent.putExtra("CRIME", crime);
getActivity().setResult(777, intent);
}
if (requestCode == REQUEST_TIME) {
int hour = data.getIntExtra("TIME_HOUR",0);
int minute = data.getIntExtra("TIME_MINUTE", 0);
Date date = crime.getDate();
date.setHours(hour);
date.setMinutes(minute);
crime.setDate(date);
updateDate();
getActivity().setResult(778, data);
}
//if (resultCode != Activity.RESULT_OK) {
// return;
//}
}
private void updateDate()

@ -1,39 +0,0 @@
package asdv.lisset.criminalintent;
import android.content.Context;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
public class CrimeLab {
private static CrimeLab crimeLab;
private List<Crime> crimes;
public static CrimeLab get(Context context) {
if (crimeLab == null) {
crimeLab = new CrimeLab(context);
}
return crimeLab;
}
private CrimeLab(Context context) {
crimes = new ArrayList<>();
for (int i =0; i < 100; ++i)
{
Crime crime = new Crime();
crime.setTitle("Crime #" + i);
crime.setSolved(i % 2 == 0); //every other one
crimes.add(crime);
}
}
public List<Crime> getCrimes() {
return crimes;
}
public Crime getCrime(UUID id) {
for (Crime crime : crimes) {
if (crime.getId().equals(id)) {
return crime;
}
}
return null;
}
}

@ -35,7 +35,17 @@ public class CrimeListActivity extends SingleFragmentActivity {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == 777) {
newCrime = (Crime) data.getSerializableExtra("CRIME");
int x = 10;
for (int i = 0; i < crimes.size(); ++i) {
if (crimes.get(i).getId().equals(newCrime.getId())) {
crimes.set(i, newCrime);
break;
}
}
}
CrimeListFragment crimeList = (CrimeListFragment) this.getFragment();
Bundle bundle = new Bundle();
bundle.putSerializable("CrimeArrayList", (Serializable) crimes);
crimeList.setArguments(bundle);
}
}

@ -67,6 +67,8 @@ public class CrimeListFragment extends Fragment {
}
//CRIME HOLDER
// ... it holds crimes
// CRIMES AGAINST PROGRAMMING
private class CrimeHolder extends RecyclerView.ViewHolder implements View.OnClickListener{
private Crime crime;
private TextView titleTextView;

@ -3,15 +3,18 @@ package asdv.lisset.criminalintent;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.TimePickerDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.DatePicker;
import android.widget.TimePicker;
import androidx.fragment.app.DialogFragment;
import java.sql.Time;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
@ -47,15 +50,12 @@ public class DatePickerFragment extends DialogFragment
@Override
public Dialog onCreateDialog(Bundle savedInstanceState)
{
// Date date = (Date) getArguments().getSerializable(ARG_DATE);
Date date = (Date) getArguments().getSerializable(ARG_DATE);
Bundle b = getArguments();
this.crimeList = (List<Crime>) b.getSerializable("CrimeArrayList");
UUID crimeUUID = (UUID) b.getSerializable("CRIME_ID");
Calendar calendar = Calendar.getInstance();
//calendar.setTime(date);
calendar.setTime(date);
int year = calendar.get(Calendar.YEAR);
int month = calendar.get(Calendar.MONTH);
int day = calendar.get(Calendar.DAY_OF_MONTH);

@ -0,0 +1,41 @@
package asdv.lisset.criminalintent;
import static android.app.PendingIntent.getActivity;
import android.app.Activity;
import android.app.Dialog;
import android.app.TimePickerDialog;
import android.content.Intent;
import android.icu.util.Calendar;
import android.os.Bundle;
import android.text.format.DateFormat;
import android.widget.TimePicker;
import androidx.fragment.app.DialogFragment;
public class TimePickerFragment extends DialogFragment implements TimePickerDialog.OnTimeSetListener {
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
// Use the current time as the default values for the picker.
final Calendar c = Calendar.getInstance();
int hour = c.get(Calendar.HOUR_OF_DAY);
int minute = c.get(Calendar.MINUTE);
// Create a new instance of TimePickerDialog and return it.
return new TimePickerDialog(getActivity(), this, hour, minute,
DateFormat.is24HourFormat(getActivity()));
}
public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
// Pass data back to our caller.
Intent i = new Intent();
i.putExtra("TIME_HOUR", hourOfDay);
i.putExtra("TIME_MINUTE", minute);
getActivity().setResult(CrimeFragment.REQUEST_TIME, i);
//getActivity().finish();
}
}

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<TimePicker xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/timePickerDialog"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="visible" />

@ -13,9 +13,10 @@
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="16dp"
android:text="Crime Title"
android:textColor="#000000"
android:textSize="18sp"
app:layout_constraintBottom_toTopOf="@+id/crime_date"
app:layout_constraintEnd_toStartOf="@+id/imageView_green_cross"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />