Example #1
0
  private String getCrimeReport() {
    String solvedString = null;
    if (mCrime.ismSolved()) {
      solvedString = getString(R.string.crime_report_solved);
    } else {
      solvedString = getString(R.string.crime_report_unresolved);
    }

    String dateFormat = "EEE, MMM dd";
    String dateString = DateFormat.format(dateFormat, mCrime.getmDate()).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.getmTitle(), dateString, solvedString, suspect);

    return report;
  }
Example #2
0
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View v = inflater.inflate(R.layout.fragment_crime, container, false);

    // wire-up widget to response user's operations
    mTitleField = (EditText) v.findViewById(R.id.crime_title);
    mTitleField.setText(mCrime.getmTitle());
    mTitleField.addTextChangedListener(
        new TextWatcher() {
          @Override
          public void beforeTextChanged(CharSequence s, int start, int count, int after) {
            // This space intentionally left blank
          }

          @Override
          public void onTextChanged(CharSequence s, int start, int before, int count) {
            mCrime.setmTitle(s.toString());
            updateCrime();
          }

          @Override
          public void afterTextChanged(Editable s) {
            // This space intentionally left blank
          }
        });

    mDateButton = (Button) v.findViewById(R.id.crime_date);
    updateDate();
    mDateButton.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            FragmentManager manager = getFragmentManager();
            DatePickerFragment dialog = DatePickerFragment.newInstance(mCrime.getmDate());
            dialog.setTargetFragment(CrimeFragment.this, REQUEST_DATE);
            dialog.show(manager, DIALOG_DATE);
          }
        });
    // extract newest date from the date button and update crime's date
    mDateButton.addTextChangedListener(
        new TextWatcher() {
          @Override
          public void beforeTextChanged(CharSequence s, int start, int count, int after) {
            // This sapce intentionally left blank
          }

          @Override
          public void onTextChanged(CharSequence s, int start, int before, int count) {
            // This sapce intentionally left blank
          }

          @Override
          public void afterTextChanged(Editable s) {
            // This sapce intentionally left blank
            // mCrime.setmDate(new Date()s.toString());
          }
        });

    mSolvedCheckBox = (CheckBox) v.findViewById(R.id.crime_solved);
    mSolvedCheckBox.setChecked(mCrime.ismSolved());
    mSolvedCheckBox.setOnCheckedChangeListener(
        new OnCheckedChangeListener() {
          @Override
          public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            // Set the crime's solved property
            mCrime.setmSolved(isChecked);
            updateCrime();
          }
        });

    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));
            i = Intent.createChooser(i, getString(R.string.send_report));
            startActivity(i);
          }
        });

    final Intent pickContact =
        new Intent(Intent.ACTION_PICK, ContactsContract.Contacts.CONTENT_URI);
    //        pickContact.addCategory(Intent.CATEGORY_HOME);
    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 pm = getActivity().getPackageManager();
    if (pm.resolveActivity(pickContact, PackageManager.MATCH_DEFAULT_ONLY) == null) {
      mSuspectButton.setEnabled(false);
    }

    mPhotoButton = (ImageButton) v.findViewById(R.id.crime_camera);
    final Intent captureImg = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);

    boolean canTakePhoto = mPhotoFile != null && captureImg.resolveActivity(pm) != null;
    mPhotoButton.setEnabled(canTakePhoto);

    if (canTakePhoto) {
      Uri uri = Uri.fromFile(mPhotoFile);
      captureImg.putExtra(MediaStore.EXTRA_OUTPUT, uri);
    }

    mPhotoButton.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            startActivityForResult(captureImg, REQUEST_PHOTO);
          }
        });

    mPhotoView = (ImageView) v.findViewById(R.id.crime_photo);
    updatePhotoView();

    return v;
  }