@Override protected void onStart() { super.onStart(); Apphance.onStart(this); if (fitClient != null) { fitClient.connect(); } }
@Override protected void onStop() { super.onStop(); Apphance.onStop(this); if (fitClient != null) { if (fitClient.isConnected()) { fitClient.disconnect(); } } }
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_login); Configuration configuration = new Configuration.Builder(this) .withAPIKey(APP_KEY) .withMode(Mode.QA) .withReportOnShakeEnabled(true) .build(); Apphance.startNewSession(LoginActivity.this, configuration); fitClient = HealthDataRetriever.getClient(this); if (!fitClient.isConnected()) { fitClient.connect(); } mPatientText = (EditText) findViewById(R.id.patient_id); mPasswordText = (EditText) findViewById(R.id.password); Button loginButton = (Button) findViewById(R.id.login_button); TextView loginTitle = (TextView) findViewById(R.id.login_title); mProgressDialog = AndroidUtils.circularProgressDialog(this); // set custom type faces for necessary views Typeface robotoThin = AndroidUtils.robotoThin(this); Typeface robotoBold = AndroidUtils.robotoBold(this); mPatientText.setTypeface(robotoThin); mPasswordText.setTypeface(robotoThin); loginButton.setTypeface(robotoThin); loginTitle.setTypeface(robotoBold); // route soft keyboard login completion to submitLogin listener mPasswordText.setOnEditorActionListener( new TextView.OnEditorActionListener() { @Override public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { boolean handled = false; if (actionId == EditorInfo.IME_ACTION_DONE) { submitLogin(v); handled = true; } return handled; } }); // connect to WL and register challenge handler for authentication WLClient wlClient = WLClient.createInstance(this); wlClient.connect( new WLResponseListener() { @Override public void onSuccess(WLResponse wlResponse) { Log.i(TAG, "Connected to Worklight!"); } @Override public void onFailure(WLFailResponse wlFailResponse) { Log.i(TAG, "Could not connect to Worklight!"); } }, WLProcedureCaller.defaultOptions()); wlClient.registerChallengeHandler(new ReadyAppsChallengeHandler(this, "SingleStepAuthRealm")); }