@Override protected void onPause() { if (mSensorManager != null) stopAccelerometer(); super.onDestroy(); // unregisterReceiver(mMessageUpdateReceiver); super.onPause(); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); setAmbientEnabled(); mContainerView = (BoxInsetLayout) findViewById(R.id.container); mImageView = (ImageView) findViewById(R.id.imageView); gestureDetector = new GestureDetector(getApplicationContext(), new GameGestureListener()); mImageView.setOnTouchListener( new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { return gestureDetector.onTouchEvent(event); } }); mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE); mGyroSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_GYROSCOPE); mHeartSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_HEART_RATE); mGoogleApiClient = new GoogleApiClient.Builder(this) .addApi(Wearable.API) .addConnectionCallbacks(this) .addOnConnectionFailedListener(this) .build(); // up vector cal mHeadTracker = HeadTracker.createFromContext(getApplicationContext()); headView = new float[16]; }
@Override protected void onPause() { super.onPause(); if (mGoogleApiClient != null) Wearable.DataApi.removeListener(mGoogleApiClient, this); if (mSensorManager != null) mSensorManager.unregisterListener(this); if (mGoogleApiClient != null && mGoogleApiClient.isConnected()) mGoogleApiClient.disconnect(); if (mHeadTracker != null) mHeadTracker.stopTracking(); }
@Override protected void onResume() { // registerReceiver(mMessageUpdateReceiver, mMessageIntentFilter); super.onResume(); accelButton = (ToggleButton) findViewById(R.id.MonitorButton); accelButton.setChecked(isAccelRunning); }
// This callback is invoked when the Speech Recognizer returns. // This is where you process the intent and extract the speech text from the intent. @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == SPEECH_REQUEST_CODE && resultCode == RESULT_OK) { List<String> results = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS); String spokenText = results.get(0); confirmText(spokenText); } super.onActivityResult(requestCode, resultCode, data); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); setAmbientEnabled(); wearableListView = (WearableListView) findViewById(R.id.conference_list_view); googleApiClient = new GoogleApiWrapper<>().build(this); }
@Override protected void onStop() { if (dataApiHandler != null) { dataApiHandler.disconnect(); } LocalBroadcastManager.getInstance(this).unregisterReceiver(broadcastReceiver); super.onStop(); }
@Override protected void onResume() { super.onResume(); if (mSensorManager != null) { mSensorManager.registerListener(this, mGyroSensor, SensorManager.SENSOR_DELAY_NORMAL); mSensorManager.registerListener(this, mHeartSensor, SensorManager.SENSOR_DELAY_NORMAL); } if (mGoogleApiClient != null) mGoogleApiClient.connect(); if (mHeadTracker != null) mHeadTracker.startTracking(); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); setAmbientEnabled(); mContainerView = (BoxInsetLayout) findViewById(R.id.container); mTextView = (TextView) findViewById(R.id.text); mClockView = (TextView) findViewById(R.id.clock); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); setAmbientEnabled(); mContainerView = (BoxInsetLayout) findViewById(R.id.container); mStartGameButton = (Button) findViewById(R.id.start_game); mStartGameButton.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { displaySpeechRecognizer(); } }); mDelayedView = (DelayedConfirmationView) findViewById(R.id.delayed_confirm); mDelayedView.setListener(mDelayedConfirmationListener); mCategoryTextView = (TextView) findViewById(R.id.selected_category); mCategoryLayout = findViewById(R.id.category_layout); mGoogleApiClient = new GoogleApiClient.Builder(this) .addConnectionCallbacks( new GoogleApiClient.ConnectionCallbacks() { @Override public void onConnected(Bundle bundle) { Log.d(TAG, "onConnected"); Wearable.MessageApi.addListener(mGoogleApiClient, MainActivity.this); } @Override public void onConnectionSuspended(int i) { Log.d(TAG, "onConnectionSuspended"); } }) .addOnConnectionFailedListener( new GoogleApiClient.OnConnectionFailedListener() { @Override public void onConnectionFailed(ConnectionResult connectionResult) { Log.d(TAG, "onConnectionFailed"); } }) .addApi(Wearable.API) .build(); }
@Override protected void onStart() { super.onStart(); if (dataApiHandler != null) { dataApiHandler.connect(); } try { ArrayList<Scene> newScenes = (ArrayList<Scene>) getIntent().getSerializableExtra(ListenerService.SCENE_DATA); replaceSceneList(newScenes); } catch (Exception e) { e.printStackTrace(); } LocalBroadcastManager.getInstance(this) .registerReceiver(broadcastReceiver, new IntentFilter(ListenerService.DATA_UPDATED)); }
@Override public void onDestroy() { if (mAsyncTask != null) { mAsyncTask.cancel(true); try { Thread.sleep(100); } catch (InterruptedException e) { e.printStackTrace(); } } if (mSensorManager != null) stopAccelerometer(); super.onDestroy(); try { mRawAccOutputStream.close(); } catch (Exception ex) { } }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setAmbientEnabled(); // Make sure we start up the LockService when the Activity is started. This needs to happen // because // the app might have just been installed, and the service won't run until we reboot the device, // or // until a new onDataChanged arrives. if (!mPermanentService) { Log.d( Const.TAG_ACTIVITY, "mPermanentService is not set, so starting LockService to configure device state with current value"); Intent startServiceIntent = new Intent(this, LockService.class); startService(startServiceIntent); mPermanentService = true; } }
protected void onPause() { super.onPause(); mSensorManager.unregisterListener(this); }
@Override public void onExitAmbient() { updateDisplay(); super.onExitAmbient(); }
@Override public void onUpdateAmbient() { super.onUpdateAmbient(); updateDisplay(); }
@Override public void onEnterAmbient(Bundle ambientDetails) { super.onEnterAmbient(ambientDetails); updateDisplay(); }
@Override protected void onStop() { super.onStop(); googleApiClient.disconnect(); }
@Override protected void onStart() { super.onStart(); googleApiClient.connect(); }
@Override public void onEnterAmbient(Bundle b) { super.onEnterAmbient(b); setUiVisibility(false); }
protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // setContentView(mCustomDrawableView); // Register the sensor listeners setContentView(R.layout.activity_orientation); // setAmbientEnabled(); // Intent viewIntent = new Intent(this, OrientationActivity.class); // // viewIntent.putExtra(EXTRA_EVENT_ID, eventId); // PendingIntent viewPendingIntent = // PendingIntent.getActivity(this, 0, viewIntent, 0); // final NotificationCompat.Builder notificationBuilder = // new NotificationCompat.Builder(this) // .setSmallIcon(R.drawable.button) // .setContentTitle("Time for exercise!") // .setContentText("Do some wrist moves") // .setContentIntent(viewPendingIntent); // Get an instance of the NotificationManager service // notificationManager = NotificationManagerCompat.from(this); mContainerView = (BoxInsetLayout) findViewById(R.id.container); mStatusView = (TextView) findViewById(R.id.status); mPitchView = (TextView) findViewById(R.id.pitch); mRollView = (TextView) findViewById(R.id.roll); mTimer = (TextView) findViewById(R.id.timer); mProgress = (ProgressBar) findViewById(R.id.progressBar); mButton = (Button) findViewById(R.id.ack); mButton.setOnClickListener( new View.OnClickListener() { public void onClick(View v) { Intent exerciseActivity = new Intent(getApplicationContext(), ExerciseActivity.class); startActivity(exerciseActivity); } }); final Typeface introTf = Typeface.createFromAsset(getAssets(), "fonts/Intro.otf"); final Typeface introInlineTf = Typeface.createFromAsset(getAssets(), "fonts/Intro Inline.otf"); mStatusView.setText("Observing..."); mTimer.setTypeface(introTf); mSensorManager = (SensorManager) getSystemService(SENSOR_SERVICE); accelerometer = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER); Log.i( "ACCELEROMETER ", String.valueOf( mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER).getMaximumRange())); magnetometer = mSensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD); Log.i( "TYPE_MAGNETIC_FIELD ", String.valueOf( mSensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD).getMaximumRange())); mVibrator = (Vibrator) getSystemService(VIBRATOR_SERVICE); currentProgress = 0.0; // Set exercise to trigger in constant unless wrist movement is detected final Handler sample = new Handler(); sample.postDelayed( new Runnable() { @Override public void run() { samples.add(accelTotal); accelTotal = 0L; if (samples.size() > 10) { samples.remove(0); } float totalNow = 0L; for (int i = 0; i < samples.size(); i++) { totalNow += (float) samples.get(i); } averageAccel = totalNow / samples.size(); // mTimer.setText("Accel: \n" + Float.toString(averageAccel)); sample.postDelayed(this, 1000); } }, 1000); // exerciseCountdown = createCountDown(EXERCISE_INTERVAL); final Handler h = new Handler(); h.postDelayed( new Runnable() { @Override public void run() { double progress = (currentProgress / 100) * 100; if (progress < 10000.0) { int roundProgress = (int) progress; mProgress.setProgress(roundProgress); if (averageAccel > 50) { currentProgress -= 5; } else if (averageAccel > 200) { currentProgress -= 30; } else { currentProgress += 40; } mStatusView.setText(Integer.toString(roundProgress / 100) + "%"); h.postDelayed(this, 100); } else { mStatusView.setText("EXERCISE!"); mStatusView.setTypeface(introInlineTf); mButton.setVisibility(View.VISIBLE); mProgress.setProgress(10000); mVibrator.vibrate(1000L); mPitchView.setVisibility(View.INVISIBLE); mRollView.setVisibility(View.INVISIBLE); } } }, 100); }
@Override public void onExitAmbient() { super.onExitAmbient(); }
@Override public void onUpdateAmbient() { super.onUpdateAmbient(); }
@Override public void onExitAmbient() { super.onExitAmbient(); setUiVisibility(true); }
@Override public void onUpdateAmbient() { super.onUpdateAmbient(); // Nothing to refresh here }
@Override protected void onCreate(Bundle savedInstanceState) { // set Theme before anything else in onCreate switch (WearablePreferencesHandler.getTheme()) { case SettingsConstants.THEME_DARK_BLUE: setTheme(R.style.PowerSwitchWearTheme_Dark_Blue); break; case SettingsConstants.THEME_DARK_RED: setTheme(R.style.PowerSwitchWearTheme_Dark_Red); break; case SettingsConstants.THEME_LIGHT_BLUE: setTheme(R.style.PowerSwitchWearTheme_Light_Blue); break; case SettingsConstants.THEME_LIGHT_RED: setTheme(R.style.PowerSwitchWearTheme_Light_Red); break; default: setTheme(R.style.PowerSwitchWearTheme_Dark_Blue); break; } super.onCreate(savedInstanceState); setContentView(R.layout.activity_scenes); // allow always-on screen setAmbientEnabled(); dataApiHandler = new DataApiHandler(getApplicationContext()); // BroadcastReceiver to get notifications from background service if room data has changed broadcastReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { Log.d("MainActivity", "received intent: " + intent.getAction()); ArrayList<Scene> scenes = (ArrayList<Scene>) intent.getSerializableExtra(ListenerService.SCENE_DATA); replaceSceneList(scenes); refreshUI(); } }; final WatchViewStub stub = (WatchViewStub) findViewById(R.id.watch_view_stub); stub.setOnLayoutInflatedListener( new WatchViewStub.OnLayoutInflatedListener() { @Override public void onLayoutInflated(WatchViewStub stub) { relativeLayoutAmbientMode = (RelativeLayout) findViewById(R.id.relativeLayout_ambientMode); scenesRecyclerView = (RecyclerView) findViewById(R.id.scenes_recyclerView); sceneRecyclerViewAdapter = new SceneRecyclerViewAdapter( getApplicationContext(), scenesRecyclerView, sceneList, dataApiHandler); scenesRecyclerView.setAdapter(sceneRecyclerViewAdapter); SnappingLinearLayoutManager layoutManager = new SnappingLinearLayoutManager( getApplicationContext(), LinearLayoutManager.VERTICAL, false); scenesRecyclerView.setLayoutManager(layoutManager); } }); }
@Override public void onExitAmbient() { scenesRecyclerView.setVisibility(View.VISIBLE); relativeLayoutAmbientMode.setVisibility(View.GONE); super.onExitAmbient(); }
@Override public void onEnterAmbient(Bundle ambientDetails) { super.onEnterAmbient(ambientDetails); scenesRecyclerView.setVisibility(View.INVISIBLE); relativeLayoutAmbientMode.setVisibility(View.VISIBLE); }
protected void onResume() { super.onResume(); mSensorManager.registerListener(this, accelerometer, SensorManager.SENSOR_DELAY_UI); mSensorManager.registerListener(this, magnetometer, SensorManager.SENSOR_DELAY_UI); }
@Override public void onEnterAmbient(Bundle ambientDetails) { super.onEnterAmbient(ambientDetails); }