This commit is contained in:
Harald Hoyer 2017-04-27 16:10:50 +02:00
parent 5092d120a7
commit 9f7836f4f2
7 changed files with 96 additions and 198 deletions

View file

@ -35,7 +35,8 @@
<activity
android:name=".MainActivity"
android:configChanges="orientation|keyboardHidden"
android:label="@string/app_name">
android:label="@string/app_name" android:launchMode="singleTop">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
@ -47,6 +48,6 @@
android:configChanges="orientation|keyboardHidden"
android:label="@string/select_device"
android:theme="@android:style/Theme.Holo.Dialog"/>
<service android:name=".BluetoothChatService"></service>
<service android:name=".BluetoothChatService" android:exported="false"></service>
</application>
</manifest>

View file

@ -53,7 +53,6 @@ public class BluetoothChatFragment extends Fragment {
// Intent request codes
private static final int REQUEST_CONNECT_DEVICE_SECURE = 1;
private static final int REQUEST_CONNECT_DEVICE_INSECURE = 2;
private static final int REQUEST_ENABLE_BT = 3;
// Layout Views
@ -159,9 +158,9 @@ public class BluetoothChatFragment extends Fragment {
mStopButton = (Button) view.findViewById(R.id.button_stop);
mDisconnectButton = (Button) view.findViewById(R.id.button_disconnect);
mLevel = (NumberPicker) view.findViewById(R.id.Level);
mLevel.setMaxValue(16);
mLevel.setMaxValue(32);
mLevel.setMinValue(1);
mLevel.setValue(5);
mLevel.setValue(1);
mLevel.setWrapSelectorWheel(false);
mLevel.setDescendantFocusability(NumberPicker.FOCUS_BLOCK_DESCENDANTS);
mSpeedText = (TextView) view.findViewById(R.id.Speed);
@ -411,12 +410,6 @@ public class BluetoothChatFragment extends Fragment {
connectDevice(data, true);
}
break;
case REQUEST_CONNECT_DEVICE_INSECURE:
// When DeviceListActivity returns with a device to connect
if (resultCode == Activity.RESULT_OK) {
connectDevice(data, false);
}
break;
case REQUEST_ENABLE_BT:
// When the request to enable Bluetooth returns
if (resultCode == Activity.RESULT_OK) {
@ -463,17 +456,6 @@ public class BluetoothChatFragment extends Fragment {
startActivityForResult(serverIntent, REQUEST_CONNECT_DEVICE_SECURE);
return true;
}
case R.id.insecure_connect_scan: {
// Launch the DeviceListActivity to see devices and do scan
Intent serverIntent = new Intent(getActivity(), DeviceListActivity.class);
startActivityForResult(serverIntent, REQUEST_CONNECT_DEVICE_INSECURE);
return true;
}
case R.id.discoverable: {
// Ensure this device is discoverable by others
ensureDiscoverable();
return true;
}
}
return false;
}

View file

@ -196,10 +196,12 @@ public class BluetoothChatService extends Service {
private void showNotification() {
// In this sample, we'll use the same text for the ticker and the expanded notification
CharSequence text = getText(R.string.local_service_started);
Intent myIntent = new Intent(getApplicationContext(), MainActivity.class);
myIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
// The PendingIntent to launch our activity if the user selects this notification
PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
new Intent(this, MainActivity.class), 0);
PendingIntent contentIntent = PendingIntent.getActivity(getApplicationContext(), 0,
myIntent, 0);
// Set the info for the views that show in the notification panel.
Notification notification = new Notification.Builder(this)

View file

@ -68,59 +68,6 @@ public class MainActivity extends FragmentActivity {
Log.i(TAG, "Service started");
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
MenuItem logToggle = menu.findItem(R.id.menu_toggle_log);
//logToggle.setVisible(findViewById(R.id.sample_output) instanceof ViewAnimator);
logToggle.setTitle(mLogShown ? R.string.sample_hide_log : R.string.sample_show_log);
return super.onPrepareOptionsMenu(menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
/*
switch(item.getItemId()) {
case R.id.menu_toggle_log:
mLogShown = !mLogShown;
ViewAnimator output = (ViewAnimator) findViewById(R.id.sample_output);
if (mLogShown) {
output.setDisplayedChild(1);
} else {
output.setDisplayedChild(0);
}
supportInvalidateOptionsMenu();
return true;
}
*/
return super.onOptionsItemSelected(item);
}
/*
public void initializeLogging() {
// Wraps Android's native log framework.
LogWrapper logWrapper = new LogWrapper();
// Using Log, front-end to the logging chain, emulates android.util.log method signatures.
Log.setLogNode(logWrapper);
// Filter strips out everything except the message text.
MessageOnlyLogFilter msgFilter = new MessageOnlyLogFilter();
logWrapper.setNext(msgFilter);
// On screen logging via a fragment with a TextView.
LogFragment logFragment = (LogFragment) getSupportFragmentManager()
.findFragmentById(R.id.log_fragment);
msgFilter.setNext(logFragment.getLogView());
Log.i(TAG, "Ready");
}
*/
@Override
protected void onDestroy() {
stopService(new Intent(this, BluetoothChatService.class));

View file

@ -27,85 +27,87 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="RPM"
android:layout_marginBottom="8dp"
app:layout_constraintBottom_toTopOf="@+id/RPM"
app:layout_constraintRight_toLeftOf="@+id/guideline"
app:layout_constraintRight_toLeftOf="@+id/guidelineright"
android:layout_marginRight="16dp"
android:layout_marginLeft="16dp"
app:layout_constraintLeft_toLeftOf="@+id/guideline3"
app:layout_constraintTop_toTopOf="@+id/guideline6"
android:layout_marginTop="16dp" />
app:layout_constraintLeft_toLeftOf="@+id/guidelineleft"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
app:layout_constraintBaseline_toBaselineOf="@+id/textView7" />
<TextView
android:id="@+id/textView7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Calories"
android:layout_marginBottom="8dp"
android:layout_marginBottom="16dp"
app:layout_constraintBottom_toTopOf="@+id/Calories"
app:layout_constraintRight_toLeftOf="@+id/guideline3"
app:layout_constraintRight_toLeftOf="@+id/guidelineleft"
android:layout_marginRight="16dp"
android:layout_marginLeft="16dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="@+id/guideline6"
android:layout_marginTop="16dp" />
android:layout_marginTop="16dp"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp" />
<TextView
android:id="@+id/textView6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Heart"
android:layout_marginBottom="8dp"
app:layout_constraintBottom_toTopOf="@+id/Heart"
android:layout_marginLeft="16dp"
app:layout_constraintLeft_toLeftOf="@+id/guideline3"
app:layout_constraintRight_toLeftOf="@+id/guideline"
app:layout_constraintLeft_toLeftOf="@+id/guidelineleft"
app:layout_constraintRight_toLeftOf="@+id/guidelineright"
android:layout_marginRight="16dp"
app:layout_constraintTop_toTopOf="@+id/guideline4"
android:layout_marginTop="16dp" />
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
app:layout_constraintBaseline_toBaselineOf="@+id/textView4" />
<TextView
android:id="@+id/textView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Distance"
android:layout_marginBottom="8dp"
app:layout_constraintBottom_toTopOf="@+id/Distance"
android:layout_marginLeft="16dp"
app:layout_constraintLeft_toLeftOf="@+id/guideline3"
app:layout_constraintRight_toLeftOf="@+id/guideline"
app:layout_constraintLeft_toLeftOf="@+id/guidelineleft"
app:layout_constraintRight_toLeftOf="@+id/guidelineright"
android:layout_marginRight="16dp"
app:layout_constraintTop_toTopOf="@+id/guideline5"
android:layout_marginTop="16dp" />
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
app:layout_constraintBaseline_toBaselineOf="@+id/textView3" />
<TextView
android:id="@+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Speed"
android:layout_marginBottom="8dp"
android:layout_marginBottom="16dp"
app:layout_constraintBottom_toTopOf="@+id/Speed"
app:layout_constraintRight_toLeftOf="@+id/guideline3"
app:layout_constraintRight_toLeftOf="@+id/guidelineleft"
android:layout_marginRight="16dp"
android:layout_marginLeft="16dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="@+id/guideline4"
android:layout_marginTop="16dp" />
android:layout_marginTop="16dp"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp" />
<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginBottom="16dp"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_marginTop="16dp"
android:text="Power"
app:layout_constraintBottom_toTopOf="@+id/Power"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toLeftOf="@+id/guideline3"
app:layout_constraintRight_toLeftOf="@+id/guidelineleft"
app:layout_constraintTop_toTopOf="@+id/guideline5"
app:layout_constraintVertical_bias="0.333" />
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"/>
<TextView
android:id="@+id/textView2"
@ -118,10 +120,11 @@
android:text="Time"
android:textAppearance="@android:style/TextAppearance.DeviceDefault.Medium"
app:layout_constraintBottom_toTopOf="@+id/Time"
app:layout_constraintHorizontal_bias="0.501"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
app:layout_constraintTop_toTopOf="parent"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp" />
<NumberPicker
android:id="@+id/Level"
@ -135,11 +138,11 @@
android:layout_marginTop="16dp"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
app:layout_constraintBottom_toTopOf="@+id/guideline2"
app:layout_constraintLeft_toLeftOf="@+id/guideline"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintLeft_toLeftOf="@+id/guidelineright"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="@+id/guideline4"
app:layout_constraintHorizontal_bias="0.484"
app:layout_constraintVertical_bias="0.671" />
app:layout_constraintTop_toTopOf="@+id/guideline5"
app:layout_constraintVertical_bias="0.0" />
<TextView
android:id="@+id/Time"
@ -159,7 +162,9 @@
app:layout_constraintHorizontal_bias="0.501"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
app:layout_constraintTop_toTopOf="parent"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp" />
<TextView
android:id="@+id/Speed"
@ -178,8 +183,9 @@
android:textStyle="bold"
app:layout_constraintBottom_toTopOf="@+id/guideline6"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toLeftOf="@+id/guideline3"
app:layout_constraintTop_toTopOf="@+id/guideline4" />
app:layout_constraintRight_toLeftOf="@+id/guidelineleft"
app:layout_constraintTop_toTopOf="@+id/guideline4"
android:layout_marginStart="16dp" />
<TextView
android:id="@+id/Power"
@ -199,51 +205,44 @@
android:textStyle="bold"
app:layout_constraintBottom_toTopOf="@+id/guideline4"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toLeftOf="@+id/guideline3"
app:layout_constraintRight_toLeftOf="@+id/guidelineleft"
app:layout_constraintTop_toTopOf="@+id/guideline5" />
<TextView
android:id="@+id/RPM"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
android:layout_marginEnd="16dp"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:fontFamily="monospace"
android:gravity="center"
android:text="@string/rpm_n0"
android:textAlignment="center"
android:textAppearance="@android:style/TextAppearance.DeviceDefault.Medium"
android:textStyle="bold"
app:layout_constraintBottom_toTopOf="@+id/guideline2"
app:layout_constraintLeft_toLeftOf="@+id/guideline3"
app:layout_constraintRight_toLeftOf="@+id/guideline"
app:layout_constraintTop_toTopOf="@+id/guideline6" />
app:layout_constraintLeft_toLeftOf="@+id/guidelineleft"
app:layout_constraintRight_toLeftOf="@+id/guidelineright"
app:layout_constraintBaseline_toBaselineOf="@+id/Calories" />
<TextView
android:id="@+id/Distance"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
android:layout_marginEnd="16dp"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:fontFamily="monospace"
android:gravity="center"
android:text="@string/distance_n0_0_km"
android:textAlignment="center"
android:textAppearance="@android:style/TextAppearance.DeviceDefault.Medium"
android:textStyle="bold"
app:layout_constraintBottom_toTopOf="@+id/guideline4"
app:layout_constraintLeft_toLeftOf="@+id/guideline3"
app:layout_constraintRight_toLeftOf="@+id/guideline"
app:layout_constraintTop_toTopOf="@+id/guideline5"
app:layout_constraintVertical_bias="0.538" />
app:layout_constraintLeft_toLeftOf="@+id/guidelineleft"
app:layout_constraintRight_toLeftOf="@+id/guidelineright"
app:layout_constraintBaseline_toBaselineOf="@+id/Power" />
<TextView
android:id="@+id/Calories"
@ -264,39 +263,52 @@
app:layout_constraintBottom_toTopOf="@+id/guideline2"
app:layout_constraintHorizontal_bias="0.507"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toLeftOf="@+id/guideline3"
app:layout_constraintRight_toLeftOf="@+id/guidelineleft"
app:layout_constraintTop_toTopOf="@+id/guideline6" />
<TextView
android:id="@+id/Heart"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_marginStart="16dp"
android:fontFamily="monospace"
android:gravity="center"
android:text="@string/heart_n0"
android:textAlignment="center"
android:textAppearance="@android:style/TextAppearance.DeviceDefault.Medium"
android:textStyle="bold"
app:layout_constraintLeft_toLeftOf="@+id/guidelineleft"
app:layout_constraintRight_toLeftOf="@+id/guidelineright"
app:layout_constraintBaseline_toBaselineOf="@+id/Speed" />
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
android:layout_marginEnd="16dp"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:fontFamily="monospace"
android:gravity="center"
android:text="@string/heart_n0"
android:textAlignment="center"
android:textAppearance="@android:style/TextAppearance.DeviceDefault.Medium"
android:textStyle="bold"
app:layout_constraintBottom_toTopOf="@+id/guideline6"
app:layout_constraintLeft_toLeftOf="@+id/guideline3"
app:layout_constraintRight_toLeftOf="@+id/guideline"
app:layout_constraintTop_toTopOf="@+id/guideline4"
app:layout_constraintVertical_bias="0.461" />
android:text="@string/level"
app:layout_constraintBottom_toTopOf="@+id/guideline5"
app:layout_constraintHorizontal_bias="0.509"
app:layout_constraintLeft_toLeftOf="@+id/guidelineright"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<android.support.constraint.Guideline
<android.support.constraint.Guideline
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/guideline3"
app:layout_constraintGuide_percent="0.4"
android:id="@+id/guidelineleft"
app:layout_constraintGuide_percent="0.35"
android:orientation="vertical"
tools:layout_editor_absoluteY="0dp"
tools:layout_editor_absoluteX="237dp" />
tools:layout_editor_absoluteX="154dp" />
<android.support.constraint.Guideline
android:layout_width="wrap_content"
@ -304,7 +316,7 @@
android:id="@+id/guideline4"
app:layout_constraintGuide_percent="0.4"
android:orientation="horizontal"
tools:layout_editor_absoluteY="125dp"
tools:layout_editor_absoluteY="205dp"
tools:layout_editor_absoluteX="0dp" />
<android.support.constraint.Guideline
@ -313,7 +325,7 @@
android:id="@+id/guideline5"
app:layout_constraintGuide_percent="0.2"
android:orientation="horizontal"
tools:layout_editor_absoluteY="62dp"
tools:layout_editor_absoluteY="102dp"
tools:layout_editor_absoluteX="0dp" />
<android.support.constraint.Guideline
@ -322,46 +334,30 @@
android:id="@+id/guideline6"
app:layout_constraintGuide_percent="0.6"
android:orientation="horizontal"
tools:layout_editor_absoluteY="187dp"
tools:layout_editor_absoluteY="307dp"
tools:layout_editor_absoluteX="0dp" />
<android.support.constraint.Guideline
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/guideline"
app:layout_constraintGuide_percent="0.8"
android:id="@+id/guidelineright"
app:layout_constraintGuide_percent="0.7"
android:orientation="vertical"
tools:layout_editor_absoluteY="0dp"
tools:layout_editor_absoluteX="474dp" />
tools:layout_editor_absoluteX="307dp" />
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/level"
android:layout_marginRight="16dp"
app:layout_constraintRight_toRightOf="parent"
android:layout_marginLeft="16dp"
app:layout_constraintLeft_toLeftOf="@+id/guideline"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
android:layout_marginBottom="16dp"
app:layout_constraintBottom_toTopOf="@+id/guideline4"
app:layout_constraintTop_toTopOf="@+id/guideline5"
android:layout_marginTop="16dp" />
<android.support.constraint.Guideline
<android.support.constraint.Guideline
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/guideline2"
app:layout_constraintGuide_percent="0.8"
android:orientation="horizontal"
tools:layout_editor_absoluteY="249dp"
tools:layout_editor_absoluteY="409dp"
tools:layout_editor_absoluteX="0dp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
android:layout_marginEnd="16dp"

View file

@ -21,14 +21,5 @@
android:showAsAction="ifRoom"
android:title="@string/secure_connect"/>
<item
android:id="@+id/insecure_connect_scan"
android:showAsAction="never"
android:title="@string/insecure_connect"/>
<item
android:id="@+id/discoverable"
android:showAsAction="never"
android:title="@string/discoverable"/>
</menu>

View file

@ -1,21 +0,0 @@
<!--
Copyright 2013 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/menu_toggle_log"
android:showAsAction="always"
android:title="@string/sample_show_log" />
</menu>