public void toggleLightControl(boolean on) {
   if (on) {
     // Update UI
     switch (mCurrentMode) {
       case R.id.mode_lightbulb:
       case R.id.mode_viewfinder:
         mDrawable.startTransition(200);
         break;
       case R.id.mode_lightswitch:
         mLightswitch.setChecked(true);
         break;
     }
   } else {
     // Update UI
     switch (mCurrentMode) {
       case R.id.mode_lightbulb:
       case R.id.mode_viewfinder:
         mDrawable.reverseTransition(300);
         break;
       case R.id.mode_lightswitch:
         mLightswitch.setChecked(false);
         break;
     }
   }
 }
  @Override
  public void onResume() {

    // to fade the settings button
    ImageButton settingsButton = (ImageButton) getActivity().findViewById(R.id.button_settings);

    switch (mCurrentMode) {
      case R.id.mode_lightswitch:
        mLightswitch = (LightSwitch) getActivity().findViewById(R.id.button_lightswitch);
        mLightswitch.setChecked(false);
        if (mOn) mLightswitch.setChecked(true);
        mLightswitch.setOnCheckedChangeListener(
            new OnCheckedChangeListener() {
              @Override
              public void onCheckedChanged(CompoundButton button, boolean isChecked) {
                mListener.onLightControlClick(isChecked);
              }
            });
        settingsButton.setAlpha(255);
        break;
      case R.id.mode_blackout:
        Button image = (Button) getActivity().findViewById(R.id.button_black);
        Animation fadeOut = AnimationUtils.loadAnimation(getActivity(), R.anim.fade_out);
        image.startAnimation(fadeOut);
        settingsButton.setAlpha(90);
        break;
      case R.id.mode_viewfinder:
      case R.id.mode_lightbulb:
        mBulb = (ImageButton) getActivity().findViewById(R.id.button_bulb);
        mDrawable = (TransitionDrawable) mBulb.getDrawable();
        mDrawable.setCrossFadeEnabled(true);
        if (mOn) mDrawable.startTransition(0);
        settingsButton.setAlpha(255);

        break;
    }

    PreviewSurface surface = (PreviewSurface) getActivity().findViewById(R.id.surface);
    if (mCurrentMode == R.id.mode_viewfinder) {
      surface.setLayoutParams(
          new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
    } else {
      surface.setLayoutParams(new LayoutParams(1, 1));
    }

    super.onResume();
  }
Exemplo n.º 3
0
  private void insertDummyData() throws SQLException {
    LightSwitch gpio00LightSwitch = new LightSwitch("Button 1", false, 0);
    gpio00LightSwitch.commit();

    LightSwitch gpio02LightSwitch = new LightSwitch("Button 2", false, 2);
    gpio02LightSwitch.commit();

    LightSwitch gpio03LightSwitch = new LightSwitch("Button 3", false, 3);
    gpio03LightSwitch.commit();

    LightSwitch gpio04LightSwitch = new LightSwitch("Button 4", false, 4);
    gpio04LightSwitch.commit();
  }