@Override public boolean onOptionsItemSelected(MenuItem mItem) { switch (mItem.getItemId()) { case R.id.action_settings: startActivity(new Intent(this, SettingsActivity.class)); return true; case R.id.action_help: startActivity(new Intent(this, HelpActivity.class)); return true; case R.id.action_bluetooth_settings: startActivity(new Intent().setAction(Settings.ACTION_BLUETOOTH_SETTINGS)); return true; case R.id.action_bluetooth: startActivityForResult( new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE), REQUEST_ENABLE_BT); return true; case R.id.action_save: LocalBroadcastManager.getInstance(this).sendBroadcast(new Intent(RecordFragment.SAVE_DATA)); return true; case R.id.action_clear_data: LocalBroadcastManager.getInstance(this) .sendBroadcast(new Intent(RecordFragment.CLEAR_DATA)); return true; case R.id.action_rescan: fConnect.scanForDevices(true); return true; default: return super.onOptionsItemSelected(mItem); } }
/** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.framework); PreferenceManager.setDefaultValues(this, R.xml.preferences, false); mPrefs = PreferenceManager.getDefaultSharedPreferences(this); mPrefs.edit().putInt(PREFERENCE_CURRENT_ID, 0).commit(); mToolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(mToolbar); getSupportActionBar().setTitle(getString(R.string.app_title)); mAdapter = new PageFragmentAdapter(getSupportFragmentManager()); fConnect = new ConnectFragment(); fConnect.setParent(this); fRecord = new RecordFragment(); fRecord.setParent(this); mAdapter.addFragment(fConnect, "Connect"); mAdapter.addFragment(fRecord, "Record"); // mAdapter.addFragment(new StatusFragment(), "Status"); mPager = (ViewPager) findViewById(R.id.view_pager); mPager.setAdapter(mAdapter); mTabLayout = (TabLayout) findViewById(R.id.tab_layout); mTabLayout.setupWithViewPager(mPager); if (!getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH_LE)) { Toast.makeText(this, "BLE not supported", Toast.LENGTH_SHORT).show(); finish(); } if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle("File Access"); builder.setMessage("Please enable the app to write external storage"); builder.setPositiveButton(android.R.string.ok, null); builder.setOnDismissListener( new DialogInterface.OnDismissListener() { @Override public void onDismiss(DialogInterface dialog) { requestPermissions(new String[] {Manifest.permission.WRITE_EXTERNAL_STORAGE}, 1); } }); builder.show(); } // mPlayer = MediaPlayer.create(this, R.raw.received); }