@Override
 public void onResume() {
   super.onResume();
   mHandler.postDelayed(mTimeUpdateRunnable, REFRESH_INTERVAL_MILLIS);
   mCore = KegbotCore.getInstance(getActivity());
   mCore.getBus().register(this);
 }
 @Override
 protected void onPause() {
   Log.d(TAG, "onPause");
   mHandler.removeCallbacks(REFRESH_FLOWS_RUNNABLE);
   mCore.getBus().unregister(this);
   super.onPause();
 }
 @Override
 protected void onResume() {
   super.onResume();
   Log.d(TAG, "onResume");
   mCore.getBus().register(this);
   mHandler.post(REFRESH_FLOWS_RUNNABLE);
 }
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    final TapManager tapManager = KegbotCore.getInstance(getActivity()).getTapManager();
    mTaps.addAll(tapManager.getTaps());

    mAdapter =
        new KegTapAdapter(
            getActivity(),
            android.R.layout.simple_list_item_activated_1,
            android.R.id.text1,
            mTaps);

    mBus = KegbotCore.getInstance(getActivity()).getBus();

    mBus.register(this);
  }
 @Override
 protected void onStart() {
   super.onStart();
   synchronized (mTapsLock) {
     for (final KegTap tap : mCore.getTapManager().getVisibleTaps()) {
       mTapList.add(tap);
     }
     mPouringTapAdapter.notifyDataSetChanged();
   }
 }
  private void updateControlsForFlow(Flow flow) {
    if (flow == null) {
      // Tap is inactive.
      mControlsFlipper.setDisplayedChild(0);
      return;
    }

    mControlsFlipper.setDisplayedChild(1);

    if (!mConfig.useAccounts()) {
      mClaimPourButton.setVisibility(View.GONE);
      mShoutText.setVisibility(View.GONE);
      mDrinkerName.setVisibility(View.GONE);
      mDrinkerImage.setVisibility(View.GONE);
    } else {
      boolean imageWasReplaced = false;
      mClaimPourButton.setEnabled(true);

      if (flow.isAnonymous()) {
        mClaimPourButton.setVisibility(View.VISIBLE);
        mDrinkerName.setVisibility(View.GONE);
      } else {
        final String username = flow.getUsername();
        mClaimPourButton.setVisibility(View.GONE);
        mDrinkerName.setVisibility(View.VISIBLE);
        mDrinkerName.setText("Pouring: " + username);

        final AuthenticationManager authManager = mCore.getAuthenticationManager();
        final User user = authManager.getUserDetail(username);
        if (user != null && user.hasImage()) {
          // NOTE(mikey): Use the full-sized image rather than the thumbnail;
          // in many cases the former will already be in the cache from
          // DrinkerSelectActivity.
          final String thumbnailUrl = user.getImage().getThumbnailUrl();
          if (!Strings.isNullOrEmpty(thumbnailUrl)) {
            mImageDownloader.download(thumbnailUrl, mDrinkerImage);
            imageWasReplaced = true;
          }
        } else {
          Log.d(TAG, "No user info.");
        }
      }

      if (!imageWasReplaced) {
        mDrinkerImage.setImageBitmap(null);
        Utils.setBackground(mDrinkerImage, getResources().getDrawable(R.drawable.unknown_drinker));
      }
    }
  }
  private void handleUserAuthed(Context context, Intent intent) {
    Log.d(TAG, "handleUserAuthed: " + intent);

    final String username = intent.getStringExtra(KegtabBroadcast.USER_AUTHED_EXTRA_USERNAME);
    final String tapName = intent.getStringExtra(KegtabBroadcast.DRINKER_SELECT_EXTRA_TAP_NAME);

    final TapManager tapManager = KegbotCore.getInstance(context).getTapManager();

    if (!Strings.isNullOrEmpty(tapName)) {
      final KegTap tap = tapManager.getTapForMeterName(tapName);
      AuthenticatingActivity.startAndAuthenticate(context, username, tap);
    } else {
      AuthenticatingActivity.startAndAuthenticate(context, username, (KegTap) null);
    }
  }
    private String getTitle(SystemEvent eventDetail) {
      final String kind = eventDetail.getKind();
      final Drink drink = eventDetail.getDrink();
      String result;

      if ("keg_ended".equals(kind)) {
        result = "ended";
      } else if ("keg_tapped".equals(kind)) {
        result = "tapped";
      } else if ("drink_poured".equals(kind)) {
        final AppConfiguration appConfig = KegbotCore.getInstance(getContext()).getConfiguration();
        Pair<String, String> qty = Units.localize(appConfig, drink.getVolumeMl());
        result = String.format("poured %s %s", qty.first, qty.second);
      } else if ("session_joined".equals(kind)) {
        result = "started drinking";
      } else if ("session_started".equals(kind)) {
        result = "started a new session";
      } else {
        result = "Unknown event";
      }
      return result;
    }
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Log.d(TAG, "onCreate()");

    mCore = KegbotCore.getInstance(this);
    mFlowManager = mCore.getFlowManager();
    mConfig = mCore.getConfiguration();
    mImageDownloader = mCore.getImageDownloader();

    final ActionBar actionBar = getActionBar();
    if (actionBar != null) {
      actionBar.hide();
    }
    setContentView(R.layout.pour_in_progress_activity);

    mTapPager = (ViewPager) findViewById(R.id.tapPager);
    mPouringTapAdapter = new PouringTapAdapter(getFragmentManager());
    mTapPager.setAdapter(mPouringTapAdapter);
    mTapPager.setOnPageChangeListener(mPageChangeListener);

    mControlsFlipper = (ViewFlipper) findViewById(R.id.pour_controls_flipper);
    mClaimPourButton = (Button) findViewById(R.id.claimPourButton);
    mDrinkerName = (TextView) findViewById(R.id.pourDrinkerName);
    mDoneButton = (Button) findViewById(R.id.pourEndButton);
    mDrinkerImage = (ImageView) findViewById(R.id.pourDrinkerImage);
    mShoutText = (TextView) findViewById(R.id.shoutText);

    mClaimPourButton.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            final Flow flow = getCurrentlyFocusedFlow();
            if (flow == null || flow.isAuthenticated() || flow.isFinished()) {
              return;
            }

            Log.d(TAG, "Attempting to claim flow id=" + flow.getFlowId());
            final Intent intent =
                KegtabCommon.getAuthDrinkerActivityIntent(PourInProgressActivity.this);
            intent.putExtra(EXTRA_FLOW_ID, flow.getFlowId());
            startActivityForResult(intent, REQUEST_AUTH_DRINKER);
          }
        });

    mDoneButton.setOnClickListener(
        new OnClickListener() {
          @Override
          public void onClick(View v) {
            final FlowManager flowManager = mCore.getFlowManager();
            final Flow flow = getCurrentlyFocusedFlow();
            if (flow == null) {
              return;
            }
            Log.d(TAG, "Done button pressed, ending flow " + flow.getFlowId());
            flowManager.endFlow(flow);

            // If we're finishing a non-dormant flow, and other dormant flows
            // exist, assume those were started optimistically and finish them
            // now.
            if (flow.getVolumeMl() > 0) {
              final AppConfiguration config = mCore.getConfiguration();
              final long minVolume = config.getMinimumVolumeMl();
              for (final Flow suspectFlow : flowManager.getAllActiveFlows()) {
                if (suspectFlow.getVolumeMl() < minVolume) {
                  Log.d(TAG, "Also ending dormant flow: " + suspectFlow.getFlowId());
                  flowManager.endFlow(suspectFlow);
                }
              }
            }
          }
        });

    mShoutText = (EditText) findViewById(R.id.shoutText);
    mShoutText.addTextChangedListener(
        new TextWatcher() {
          @Override
          public void onTextChanged(CharSequence s, int start, int before, int count) {}

          @Override
          public void beforeTextChanged(CharSequence s, int start, int count, int after) {}

          @Override
          public void afterTextChanged(Editable s) {
            final Flow flow = getCurrentlyFocusedFlow();
            if (flow == null) {
              Log.w(TAG, "Flow went away, dropping shout.");
              return;
            }
            flow.setShout(s.toString());
            flow.pokeActivity();
          }
        });

    mShowCamera = true;
    mCameraFragment = (CameraFragment) getFragmentManager().findFragmentById(R.id.camera);
    if (!mConfig.getUseCamera()) {
      mShowCamera = false;
      getFragmentManager().beginTransaction().hide(mCameraFragment).commit();
    }

    refreshFlows();
  }
 @Override
 public void onPause() {
   mCore.getBus().unregister(this);
   mHandler.removeCallbacks(mTimeUpdateRunnable);
   super.onPause();
 }
 @Override
 public void onAttach(Activity activity) {
   super.onAttach(activity);
   mImageDownloader = KegbotCore.getInstance(activity).getImageDownloader();
 }