@Override
 public boolean onOptionsItemSelected(MenuItem item) {
   switch (item.getItemId()) {
     case android.R.id.home:
       if (NavUtils.getParentActivityName(getActivity()) != null) {
         NavUtils.navigateUpFromSameTask(getActivity());
       }
       return true;
     case R.id.menu_item_delete_single_crime:
       CrimeLab.get(getActivity()).deleteCrime(mCrime);
       if (NavUtils.getParentActivityName(getActivity()) != null) {
         NavUtils.navigateUpFromSameTask(getActivity());
       }
       return true;
     default:
       return super.onOptionsItemSelected(item);
   }
 }
Beispiel #2
0
 @Override
 public boolean onOptionsItemSelected(MenuItem item) {
   switch (item.getItemId()) {
     case android.R.id.home:
       if (NavUtils.getParentActivityName(this) != null) {
         NavUtils.navigateUpFromSameTask(this);
       }
       return true;
     default:
       return super.onOptionsItemSelected(item);
   }
 }
  @Nullable
  @Override
  @TargetApi(11)
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View v = inflater.inflate(R.layout.fragment_crime, container, false);

    titleField = (EditText) v.findViewById(R.id.crime_title);
    titleField.setText(crime.getTitle());
    titleField.addTextChangedListener(
        new TextWatcher() {
          @Override
          public void beforeTextChanged(CharSequence s, int start, int count, int after) {}

          @Override
          public void onTextChanged(CharSequence s, int start, int before, int count) {
            crime.setTitle(s.toString());
          }

          @Override
          public void afterTextChanged(Editable s) {}
        });

    dateButton = (Button) v.findViewById(R.id.crime_date);
    updateDate();
    dateButton.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            FragmentManager fm = getActivity().getSupportFragmentManager();
            DatePickerFragment dialog = DatePickerFragment.newInstance(crime.getDate());
            dialog.setTargetFragment(CrimeFragment.this, REQUEST_DATE);
            dialog.show(fm, DIALOG_DATE);
          }
        });
    solvedCheckbox = (CheckBox) v.findViewById(R.id.crime_solved);
    solvedCheckbox.setChecked(crime.isSolved());
    solvedCheckbox.setOnCheckedChangeListener(
        new CompoundButton.OnCheckedChangeListener() {
          @Override
          public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            crime.setSolved(isChecked);
          }
        });

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
      if (NavUtils.getParentActivityName(getActivity()) != null) {
        ((AppCompatActivity) getActivity()).getSupportActionBar().setDisplayHomeAsUpEnabled(true);
      }
    }

    return v;
  }
Beispiel #4
0
 public Intent getParentActivityIntent(Activity paramActivity) {
   String str = NavUtils.getParentActivityName(paramActivity);
   if (str == null) {
     return null;
   }
   ComponentName localComponentName = new ComponentName(paramActivity, str);
   Object localObject;
   try {
     if (NavUtils.getParentActivityName(paramActivity, localComponentName) == null) {
       localObject = IntentCompat.makeMainActivity(localComponentName);
     } else {
       Intent localIntent = new Intent().setComponent(localComponentName);
       localObject = localIntent;
     }
   } catch (PackageManager.NameNotFoundException localNameNotFoundException) {
     Log.e(
         "NavUtils",
         "getParentActivityIntent: bad parentActivityName '" + str + "' in manifest");
     return null;
   }
   return localObject;
 }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_full_player);

    mAudioUri = Uri.parse(getIntent().getStringExtra(EXTRA_AUDIO_PATH));
    mLrcUri = Uri.parse(getIntent().getStringExtra(EXTRA_LRC_PATH));

    String path = mLrcUri.getPath();
    String[] pathParts = path.split("/");
    String title = pathParts[pathParts.length - 1];

    // Enables the "home" icon to be some kind of button and displays the "<".
    // should also add meta-data "android.support.PARENT_ACTIVITY" in manifest.
    if (Build.VERSION.SDK_INT > Build.VERSION_CODES.HONEYCOMB) {
      if (NavUtils.getParentActivityName(this) != null) {
        ActionBar actionBar = getActionBar();
        if (actionBar != null) {
          actionBar.setTitle(title);
          actionBar.setDisplayHomeAsUpEnabled(true);
        }
      }
    }

    mPlayPauseView = (ImageView) findViewById(R.id.catcher_playPause);
    mSkipPrevView = (ImageView) findViewById(R.id.catcher_skipPrev);
    mSkipNextView = (ImageView) findViewById(R.id.catcher_skipNext);
    mSeekBar = (SeekBar) findViewById(R.id.catcher_seekbar);
    mCurrentTimeLabel = (TextView) findViewById(R.id.catcher_currentTimeLabel);
    mDurationLabel = (TextView) findViewById(R.id.catcher_durationLabel);

    mPlayDrawable = getResources().getDrawable(R.drawable.ic_play_arrow_white_48dp);
    mPauseDrawable = getResources().getDrawable(R.drawable.ic_pause_white_48dp);

    mPlayPauseView.setOnClickListener(mPlayPauseViewOnClickListener);
    mSeekBar.setOnSeekBarChangeListener(mSeekBarOnSeekBarChangeListener);

    FragmentManager fm = getSupportFragmentManager();
    FragmentTransaction ft = fm.beginTransaction();
    Fragment oldLrcFragment = fm.findFragmentById(R.id.catcher_lrcFragmentContainer);
    Fragment newLrcFragment = LrcFragment.newInstance("test2.lrc");
    mLrcFragment = (LrcFragment) newLrcFragment;
    if (oldLrcFragment != null) {
      ft.remove(oldLrcFragment);
    }
    ft.add(R.id.catcher_lrcFragmentContainer, newLrcFragment);
    ft.commit();
  }
  @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;
  }