android more like screw you droid
This commit is contained in:
@@ -21,6 +21,9 @@
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".CrimeActivity">
|
||||
</activity>
|
||||
</application>
|
||||
|
||||
</manifest>
|
@@ -4,11 +4,25 @@ import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.fragment.app.FragmentManager;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class CrimeActivity extends SingleFragmentActivity {
|
||||
@Override
|
||||
protected Fragment createFragment() {
|
||||
return new CrimeFragment();
|
||||
//return new CrimeFragment();
|
||||
UUID crimeId = (UUID) getIntent().getSerializableExtra(EXTRA_CRIME_ID);
|
||||
return CrimeFragment.newInstance(crimeId);
|
||||
}
|
||||
|
||||
private static final String EXTRA_CRIME_ID = "com.example.criminalintentchapte.crime_id";
|
||||
public static Intent newIntent(Context packageContext, UUID crimeID) {
|
||||
Intent intent = new Intent(packageContext, CrimeActivity.class);
|
||||
intent.putExtra(EXTRA_CRIME_ID, crimeID);
|
||||
return intent;
|
||||
}
|
||||
|
||||
}
|
@@ -16,13 +16,21 @@ import android.widget.EditText;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Locale;
|
||||
import java.util.UUID;
|
||||
|
||||
public class CrimeFragment extends Fragment {
|
||||
private static final String ARG_CRIME_ID = "crime_id";
|
||||
private Crime mCrime;
|
||||
private EditText mTitleField;
|
||||
private CheckBox mSolvedCheckBox;
|
||||
private Button mDateButton;
|
||||
|
||||
public static CrimeFragment newInstance(UUID crimeID) {
|
||||
Bundle args = new Bundle();
|
||||
args.putSerializable(ARG_CRIME_ID, crimeID);
|
||||
CrimeFragment fragment = new CrimeFragment();
|
||||
fragment.setArguments(args);
|
||||
return fragment;
|
||||
}
|
||||
public CrimeFragment() {
|
||||
// Required empty public constructor
|
||||
}
|
||||
@@ -31,7 +39,9 @@ public class CrimeFragment extends Fragment {
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
mCrime = new Crime();
|
||||
//mCrime = new Crime();
|
||||
UUID crimeID = (UUID) getActivity().getIntent().getSerializableExtra(CrimeActivity.EXTRA_CRIME_ID);
|
||||
mCrime = CrimeLab.get(getActivity()).getCrime(crimeID);
|
||||
|
||||
}
|
||||
|
||||
@@ -43,6 +53,7 @@ public class CrimeFragment extends Fragment {
|
||||
|
||||
mTitleField = (EditText)
|
||||
v.findViewById(R.id.crime_title);
|
||||
mTitleField.setText(mCrime.getTitle());
|
||||
mTitleField.addTextChangedListener(new TextWatcher() {
|
||||
@Override
|
||||
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
||||
@@ -61,6 +72,7 @@ public class CrimeFragment extends Fragment {
|
||||
});
|
||||
|
||||
mSolvedCheckBox = (CheckBox) v.findViewById(R.id.crime_solved);
|
||||
mSolvedCheckBox.setChecked(mCrime.isSolved());
|
||||
|
||||
mSolvedCheckBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener()
|
||||
{
|
||||
|
@@ -1,12 +1,16 @@
|
||||
package com.example.criminalintentchapter8;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.graphics.Rect;
|
||||
import android.media.Image;
|
||||
import android.os.Bundle;
|
||||
import android.text.Layout;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
@@ -31,22 +35,33 @@ public class CrimeListFragment extends Fragment {
|
||||
return view;
|
||||
}
|
||||
|
||||
private class CrimeHolder extends RecyclerView.ViewHolder {
|
||||
private class CrimeHolder extends RecyclerView.ViewHolder implements View.OnClickListener{
|
||||
private TextView mTitleTextView;
|
||||
private TextView mDateTextView;
|
||||
private ImageView mSolvedImageView;
|
||||
private Crime mCrime;
|
||||
public void bind(Crime crime) {
|
||||
mCrime = crime;
|
||||
mTitleTextView.setText(mCrime.getTitle());
|
||||
mDateTextView.setText(mCrime.getDate().toString());
|
||||
mSolvedImageView.setVisibility(crime.isSolved() ? View.VISIBLE : View.GONE);
|
||||
}
|
||||
public CrimeHolder(LayoutInflater inflater,
|
||||
ViewGroup parent) {
|
||||
super(inflater.inflate(R.layout.list_item_crime, parent, false));
|
||||
|
||||
itemView.setOnClickListener(this);
|
||||
mTitleTextView = (TextView) itemView.findViewById(R.id.crime_title);
|
||||
mDateTextView = (TextView) itemView.findViewById(R.id.crime_date);
|
||||
mSolvedImageView = (ImageView) itemView.findViewById(R.id.crime_solved);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Intent intent = CrimeActivity.newIntent(getActivity(), mCrime.getId());
|
||||
startActivity(intent);
|
||||
/*
|
||||
Toast.makeText(getActivity(), mCrime.getTitle() + " clicked!", Toast.LENGTH_SHORT).show();
|
||||
*/
|
||||
}
|
||||
}
|
||||
private class CrimeAdapter extends RecyclerView.Adapter<CrimeHolder> {
|
||||
|
Binary file not shown.
After Width: | Height: | Size: 8.2 KiB |
@@ -24,17 +24,15 @@ android:text="@string/crime_details_label"/>
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="horizontal"
|
||||
android:layout_gravity="center">
|
||||
android:layout_gravity="center"
|
||||
android:orientation="vertical">
|
||||
|
||||
<Button
|
||||
android:id="@+id/crime_date"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="16dp"
|
||||
android:layout_marginRight="16dp"
|
||||
android:paddingLeft="16dp"
|
||||
/>
|
||||
android:layout_marginRight="16dp" />
|
||||
|
||||
<CheckBox
|
||||
android:id="@+id/crime_solved"
|
||||
|
@@ -1,6 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
<androidx.recyclerview.widget.RecyclerView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/crime_recycler_view"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_width="wrap_content" />
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" />
|
||||
|
@@ -1,19 +1,38 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:orientation="vertical"
|
||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
android:padding="8dp">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/crime_title"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Crime title" />
|
||||
android:text="Crime title"
|
||||
android:textSize="18sp"
|
||||
app:layout_constraintEnd_toStartOf="@+id/crime_solved"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<TextView
|
||||
android:id="@id/crime_date"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Crime date"/>
|
||||
</LinearLayout>
|
||||
android:text="Crime date"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toStartOf="@+id/crime_solved"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/crime_title" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/crime_solved"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:srcCompat="@drawable/ic_solved" />
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
Reference in New Issue
Block a user