@Override public void onClick(View view) { Toast.makeText(getActivity(), mCrime.getTitle() + " clicked", Toast.LENGTH_SHORT).show(); Intent intent = CrimePagerActivity.newIntent(getActivity(), mCrime.getId()); CrimeListFragment.setCrimePosition(getAdapterPosition()); startActivity(intent); }
@Override public View getView(int position, View convertView, ViewGroup parent) { Crime crime = getItem(position); ViewHolder viewHolder = null; if (convertView == null) { convertView = getActivity().getLayoutInflater().inflate(R.layout.list_item_crime, null); viewHolder = new ViewHolder(); viewHolder.titleTextView = (TextView) convertView.findViewById(R.id.crime_list_item_titleTextView); viewHolder.dateTextView = (TextView) convertView.findViewById(R.id.crime_list_item_dateTextView); viewHolder.solvedCheckBox = (CheckBox) convertView.findViewById(R.id.crime_list_item_solvedCheckBox); convertView.setTag(viewHolder); } else { viewHolder = (ViewHolder) convertView.getTag(); } viewHolder.titleTextView.setText(crime.getTitle()); viewHolder.dateTextView.setText(crime.getDate().toString()); viewHolder.solvedCheckBox.setChecked(crime.isSolved()); return convertView; }
@Override public void onListItemClick(ListView l, View v, int position, long id) { Crime c = (Crime) (getListAdapter()).getItem(position); Log.d(TAG, c.getTitle() + " was clicked."); // Start CrimePagerActivity - shows detailed info about the crime in a new activity Intent i = new Intent(getActivity(), CrimePagerActivity.class); i.putExtra(CrimeFragment.EXTRA_CRIME_ID, c.getId()); startActivity(i); }
private static ContentValues getContentValues(Crime crime) { ContentValues values = new ContentValues(); values.put(CrimeTable.Cols.UUID, crime.getId().toString()); values.put(CrimeTable.Cols.TITLE, crime.getTitle()); values.put(CrimeTable.Cols.DATE, crime.getDate().getTime()); values.put(CrimeTable.Cols.SOLVED, crime.isSolved() ? 1 : 0); values.put(CrimeTable.Cols.SUSPECT, crime.getSuspect()); return values; }
@Override public View getView(int position, View convertView, ViewGroup parent) { if (convertView == null) { convertView = getActivity().getLayoutInflater().inflate(R.layout.list_item_crime, null); } Crime c = getItem(position); TextView titleTextView = (TextView) convertView.findViewById(R.id.crime_list_item_titleTextView); titleTextView.setText(c.getTitle()); TextView dateTextView = (TextView) convertView.findViewById(R.id.crime_list_item_dateTextView); dateTextView.setText(c.getDate().toString()); CheckBox solvedCheckBox = (CheckBox) convertView.findViewById(R.id.crime_list_item_solvedCheckBox); solvedCheckBox.setChecked(c.isSolved()); return convertView; }
private String getCrimeReport() { String solvedString = null; if (mCrime.isSolved()) { solvedString = getString(R.string.crime_report_solved); } else { solvedString = getString(R.string.crime_report_unsolved); } String dateFormat = "EEE, MMM dd"; String dateString = DateFormat.format(dateFormat, mCrime.getDate()).toString(); String suspect = mCrime.getSuspect(); if (suspect == null) { suspect = getString(R.string.crime_report_no_suspect); } else { suspect = getString(R.string.crime_report_suspect, suspect); } String report = getString(R.string.crime_report, mCrime.getTitle(), dateString, solvedString, suspect); return report; }
@Override public View getView(int position, View convertView, ViewGroup parent) { // if we weren't given a view, inflate one if (null == convertView) { convertView = getActivity().getLayoutInflater().inflate(R.layout.list_item_crime, null); } // configure the view for this Crime Crime c = getItem(position); TextView titleTextView = (TextView) convertView.findViewById(R.id.crime_list_item_titleTextView); titleTextView.setText(c.getTitle()); TextView dateTextView = (TextView) convertView.findViewById(R.id.crime_list_item_dateTextView); dateTextView.setText(c.getDate().toString()); CheckBox solvedCheckBox = (CheckBox) convertView.findViewById(R.id.crime_list_item_solvedCheckBox); solvedCheckBox.setChecked(c.isSolved()); return convertView; }
@TargetApi(11) @Override public View onCreateView(LayoutInflater inflater, ViewGroup parent, Bundle savedInstance) { // Get view for fragment View v = inflater.inflate(R.layout.fragment_crime, parent, false); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { if (NavUtils.getParentActivityName(getActivity()) != null) { getActivity().getActionBar().setDisplayHomeAsUpEnabled(true); } } // Crime Title mTitleField = (EditText) v.findViewById(R.id.crime_title); mTitleField.setText(mCrime.getTitle()); mTitleField.addTextChangedListener( new TextWatcher() { public void onTextChanged(CharSequence c, int start, int before, int count) { mCrime.setTitle(c.toString()); mCallbacks.onCrimeUpdated(mCrime); } public void beforeTextChanged(CharSequence c, int start, int count, int after) { // Do something? } public void afterTextChanged(Editable c) { // Do something? } }); Log.d("KIO", "Crime title is: " + mTitleField); // Date Button mDateButton = (Button) v.findViewById(R.id.crime_date); updateDate(); mDateButton.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { FragmentManager fm = getActivity().getSupportFragmentManager(); DatePickerFragment dialog = DatePickerFragment.newInstance(mCrime.getDate()); dialog.setTargetFragment(CrimeFragment.this, REQUEST_DATE); dialog.show(fm, DIALOG_DATE); } }); Log.d("KIO", "Date is: " + mDateButton); // Time Button mTimeButton = (Button) v.findViewById(R.id.crime_time); Log.d("KIO", "Time is: " + mTimeButton); updateTime(); mTimeButton.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { FragmentManager fm = getActivity().getSupportFragmentManager(); TimePickerFragment dialog = TimePickerFragment.newInstance(mCrime.getDate()); dialog.setTargetFragment(CrimeFragment.this, REQUEST_TIME); dialog.show(fm, DIALOG_TIME); } }); Log.d("KIO", "Time is: " + mTimeButton); // "Solved" Check box mSolvedCheckBox = (CheckBox) v.findViewById(R.id.crime_solved); mSolvedCheckBox.setChecked(mCrime.isSolved()); mSolvedCheckBox.setOnCheckedChangeListener( new OnCheckedChangeListener() { public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { // Set the crime's solved property mCrime.setSolved(isChecked); mCallbacks.onCrimeUpdated(mCrime); } }); // Photo Button mPhotoButton = (ImageButton) v.findViewById(R.id.crime_imageButton); mPhotoButton.setOnClickListener( new OnClickListener() { @Override public void onClick(View v) { Intent i = new Intent(getActivity(), CrimeCameraActivity.class); startActivityForResult(i, REQUEST_PHOTO); } }); // If a camera is not available, disable the camera functionality PackageManager pm = getActivity().getPackageManager(); boolean hasACamera = pm.hasSystemFeature(PackageManager.FEATURE_CAMERA) || pm.hasSystemFeature(PackageManager.FEATURE_CAMERA) || (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD && Camera.getNumberOfCameras() > 0); if (!hasACamera) { mPhotoButton.setEnabled(false); } // Photographic Evidence mPhotoView = (ImageView) v.findViewById(R.id.crime_imageView); mPhotoView.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { Photo p = mCrime.getPhoto(); if (p == null) { return; } FragmentManager fm = getActivity().getSupportFragmentManager(); String path = getActivity().getFileStreamPath(p.getFilename()).getAbsolutePath(); ImageFragment.newInstance(path).show(fm, DIALOG_IMAGE); } }); // Crime Report Button reportButton = (Button) v.findViewById(R.id.crime_reportButton); reportButton.setOnClickListener( new OnClickListener() { @Override public void onClick(View v) { Intent i = new Intent(Intent.ACTION_SEND); i.setType("text/plain"); i.putExtra(Intent.EXTRA_TEXT, getCrimeReport()); i.putExtra(Intent.EXTRA_SUBJECT, getString(R.string.crime_report_subject)); // Always show the chooser, even if the user has set a default app i = Intent.createChooser(i, getString(R.string.send_report)); startActivity(i); } }); // Suspect mSuspectButton = (Button) v.findViewById(R.id.crime_suspectButton); mSuspectButton.setOnClickListener( new OnClickListener() { @Override public void onClick(View v) { Intent i = new Intent(Intent.ACTION_PICK, ContactsContract.Contacts.CONTENT_URI); startActivityForResult(i, REQUEST_CONTACT); } }); if (mCrime.getSuspect() != null) { mSuspectButton.setText(mCrime.getSuspect()); } return v; }
public void bindCrime(Crime crime) { mCrime = crime; mTitleTextView.setText(mCrime.getTitle()); mDateTextView.setText(mCrime.getDate().toString()); mSolvedCheckBox.setChecked(mCrime.isSolved()); }
@Override public View onCreateView( LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View v = inflater.inflate(R.layout.fragment_crime, container, false); mTitleField = (EditText) v.findViewById(R.id.crime_title); mTitleField.setText(mCrime.getTitle()); mTitleField.addTextChangedListener( new TextWatcher() { @Override public void beforeTextChanged( CharSequence charSequence, int i, int i1, int i2) { // Intentionally blank } @Override public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) { mCrime.setTitle(charSequence.toString()); } @Override public void afterTextChanged(Editable editable) { // Intentionally blank } }); mDateButton = (Button) v.findViewById(R.id.crime_date); mDateButton.setText(new DateFormat().format("EEE, MMM dd, yyyy", mCrime.getDate())); mDateButton.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { FragmentManager manager = getFragmentManager(); DatePickerFragment dialog = DatePickerFragment.newInstance(mCrime.getDate()); dialog.setTargetFragment(CrimeFragment.this, REQUEST_DATE); dialog.show(manager, DIALOG_DATE); } }); mTimeButton = (Button) v.findViewById(R.id.crime_time); updateTime(); mTimeButton.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { FragmentManager manager = getFragmentManager(); TimePickerFragment dialog = TimePickerFragment.newInstance(mCrime.getDate()); dialog.setTargetFragment(CrimeFragment.this, REQUEST_TIME); dialog.show(manager, DIALOG_TIME); } }); mSolvedCheckBox = (CheckBox) v.findViewById(R.id.crime_solved); mSolvedCheckBox.setChecked(mCrime.isSolved()); mSolvedCheckBox.setOnCheckedChangeListener( new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { mCrime.setSolved(isChecked); } }); mReportButton = (Button) v.findViewById(R.id.crime_report); mReportButton.setOnClickListener( new View.OnClickListener() { public void onClick(View v) { Intent i = new Intent(Intent.ACTION_SEND); i.setType("text/plain"); i.putExtra(Intent.EXTRA_TEXT, getCrimeReport()); i.putExtra(Intent.EXTRA_SUBJECT, getString(R.string.crime_report_subject)); startActivity(i); } }); final Intent pickContact = new Intent(Intent.ACTION_PICK, ContactsContract.Contacts.CONTENT_URI); mSuspectButton = (Button) v.findViewById(R.id.crime_suspect); mSuspectButton.setOnClickListener( new View.OnClickListener() { public void onClick(View v) { startActivityForResult(pickContact, REQUEST_CONTACT); } }); if (mCrime.getSuspect() != null) { mSuspectButton.setText(mCrime.getSuspect()); } PackageManager packageManager = getActivity().getPackageManager(); if (packageManager.resolveActivity(pickContact, PackageManager.MATCH_DEFAULT_ONLY) == null) { mSuspectButton.setEnabled(false); } return v; }