Exemple #1
0
  @Override
  public boolean onNavigationItemSelected(int position, long id) {
    if (position == 0) {
      if (std == null) {
        std = DemoCameraFragment.newInstance(false);
      }

      current = std;
    } else {
      if (ffc == null) {
        ffc = DemoCameraFragment.newInstance(true);
      }

      current = ffc;
    }

    getFragmentManager().beginTransaction().replace(R.id.container, current).commit();

    findViewById(android.R.id.content)
        .post(
            new Runnable() {
              @Override
              public void run() {
                current.lockToLandscape(isLockedToLandscape);
              }
            });

    return (true);
  }
Exemple #2
0
  @Override
  public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_CAMERA
        && current != null
        && !current.isSingleShotProcessing()) {
      current.takePicture();

      return (true);
    }

    return (super.onKeyDown(keyCode, event));
  }
Exemple #3
0
  @Override
  public void onRestoreInstanceState(Bundle savedInstanceState) {
    if (hasTwoCameras) {
      if (savedInstanceState.containsKey(STATE_SELECTED_NAVIGATION_ITEM)) {
        getActionBar()
            .setSelectedNavigationItem(savedInstanceState.getInt(STATE_SELECTED_NAVIGATION_ITEM));
      }
    }

    setSingleShotMode(savedInstanceState.getBoolean(STATE_SINGLE_SHOT));
    isLockedToLandscape = savedInstanceState.getBoolean(STATE_LOCK_TO_LANDSCAPE);

    if (current != null) {
      current.lockToLandscape(isLockedToLandscape);
    }
  }
Exemple #4
0
  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
    if (item.getItemId() == R.id.content) {
      Intent i = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
      File dir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM);
      File output = new File(dir, "CameraContentDemo.jpeg");

      i.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(output));

      startActivityForResult(i, CONTENT_REQUEST);
    } else if (item.getItemId() == R.id.landscape) {
      item.setChecked(!item.isChecked());
      current.lockToLandscape(item.isChecked());
      isLockedToLandscape = item.isChecked();
    }

    return (super.onOptionsItemSelected(item));
  }
Exemple #5
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_main);

    if (hasTwoCameras) {
      final ActionBar actionBar = getActionBar();

      actionBar.setDisplayShowTitleEnabled(false);
      actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);

      ArrayAdapter<CharSequence> adapter =
          ArrayAdapter.createFromResource(
              actionBar.getThemedContext(), R.array.nav, android.R.layout.simple_list_item_1);

      actionBar.setListNavigationCallbacks(adapter, this);
    } else {
      current = DemoCameraFragment.newInstance(false);

      getFragmentManager().beginTransaction().replace(R.id.container, current).commit();
    }
  }