/* * Copyright 2015 MbientLab Inc. All rights reserved. * * IMPORTANT: Your use of this Software is limited to those specific rights * granted under the terms of a software license agreement between the user who * downloaded the software, his/her employer (which must be your employer) and * MbientLab Inc, (the "License"). You may not use this Software unless you * agree to abide by the terms of the License which can be found at * www.mbientlab.com/terms . The License limits your use, and you acknowledge, * that the Software may not be modified, copied or distributed and can be used * solely and exclusively in conjunction with a MbientLab Inc, product. Other * than for the foregoing purpose, you may not use, reproduce, copy, prepare * derivative works of, modify, distribute, perform, display or sell this * Software and/or its documentation for any purpose. * * YOU FURTHER ACKNOWLEDGE AND AGREE THAT THE SOFTWARE AND DOCUMENTATION ARE * PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, * INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY, TITLE, * NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL * MBIENTLAB OR ITS LICENSORS BE LIABLE OR OBLIGATED UNDER CONTRACT, NEGLIGENCE, * STRICT LIABILITY, CONTRIBUTION, BREACH OF WARRANTY, OR OTHER LEGAL EQUITABLE * THEORY ANY DIRECT OR INDIRECT DAMAGES OR EXPENSES INCLUDING BUT NOT LIMITED * TO ANY INCIDENTAL, SPECIAL, INDIRECT, PUNITIVE OR CONSEQUENTIAL DAMAGES, LOST * PROFITS OR LOST DATA, COST OF PROCUREMENT OF SUBSTITUTE GOODS, TECHNOLOGY, * SERVICES, OR ANY CLAIMS BY THIRD PARTIES (INCLUDING BUT NOT LIMITED TO ANY * DEFENSE THEREOF), OR OTHER SIMILAR COSTS. * * Should you have any questions regarding your right to use this Software, * contact MbientLab Inc, at www.mbientlab.com. */ package com.mbientlab.metawear.tutorial.starter; import android.app.Activity; import android.bluetooth.BluetoothDevice; import android.content.ComponentName; import android.content.Context; import android.content.Intent; import android.content.ServiceConnection; import android.os.IBinder; import android.support.v4.app.Fragment; import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import com.mbientlab.metawear.MetaWearBoard; import com.mbientlab.metawear.android.BtleService; import com.mbientlab.metawear.module.Accelerometer; import com.mbientlab.metawear.module.Led; import com.mbientlab.metawear.module.Switch; /** * A placeholder fragment containing a simple view. */ public class DeviceSetupActivityFragment extends Fragment implements ServiceConnection { public interface FragmentSettings { BluetoothDevice getBtDevice(); } private MetaWearBoard metawear = null; private FragmentSettings settings; public DeviceSetupActivityFragment() { } @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Activity owner= getActivity(); if (!(owner instanceof FragmentSettings)) { throw new ClassCastException("Owning activity must implement the FragmentSettings interface"); } settings= (FragmentSettings) owner; owner.getApplicationContext().bindService(new Intent(owner, BtleService.class), this, Context.BIND_AUTO_CREATE); } @Override public void onDestroy() { super.onDestroy(); ///< Unbind the service when the activity is destroyed getActivity().getApplicationContext().unbindService(this); } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { setRetainInstance(true); return inflater.inflate(R.layout.fragment_device_setup, container, false); } @Override public void onViewCreated(View view, Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); ((Switch) view.findViewById(R.id.led_ctrl)).setOnClickListener((buttonView, isChecked) -> { Led led= metawear.getModule(Led.class); if (isChecked) { led.editPattern(Led.Color.BLUE, Led.PatternPreset.SOLID) .repeatCount(Led.PATTERN_REPEAT_INDEFINITELY) .commit(); led.play(); } else { led.stop(true); } }); } @Override public void onServiceDisconnected(ComponentName name) { } /** * Called when the app has reconnected to the board */ public void reconnected() { } }