Skip to content

Commit

Permalink
Merge pull request ftctechnh#1 from FROGbots-4634/master
Browse files Browse the repository at this point in the history
Add enhanced log viewer
  • Loading branch information
NoahAndrews committed Oct 17, 2017
2 parents c0e392b + aea23fc commit e13e838
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,19 @@ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
package com.qualcomm.ftccommon;

import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Color;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.preference.PreferenceManager;
import android.text.Spannable;
import android.text.SpannableString;
import android.text.style.ForegroundColorSpan;
import android.view.View;
import android.view.ViewGroup;
import android.widget.HorizontalScrollView;
import android.widget.LinearLayout;
import android.widget.ScrollView;
import android.widget.TextView;

Expand Down Expand Up @@ -72,13 +77,25 @@ protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_view_logs);

SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
boolean wrapLines = sharedPreferences.getBoolean(getString(R.string.pref_line_wrap_log), false);


LinearLayout rootLayout = (LinearLayout)findViewById(R.id.viewLogsActivityLinearLayout);
HorizontalScrollView horizontalScrollView = (HorizontalScrollView) findViewById(R.id.horizontalScrollView);
final ScrollView verticalScrollView = (ScrollView) findViewById(R.id.verticalScrollView);
textAdbLogs = (TextView) findViewById(R.id.textAdbLogs);

final ScrollView scrollView = ((ScrollView) findViewById(R.id.scrollView));
scrollView.post(new Runnable() {
if(wrapLines) {
horizontalScrollView.removeView(verticalScrollView);
rootLayout.removeView(horizontalScrollView);
rootLayout.addView(verticalScrollView);
}

verticalScrollView.post(new Runnable() {
@Override
public void run() {
scrollView.fullScroll(ScrollView.FOCUS_DOWN);
verticalScrollView.fullScroll(ScrollView.FOCUS_DOWN);
}
});
}
Expand Down Expand Up @@ -115,8 +132,10 @@ public boolean onLongClick(View v) {
public void run() {
try {
String output = readNLines(DEFAULT_NUMBER_OF_LINES);

Spannable colorized = colorize(output);
textAdbLogs.setText(colorized);

} catch (IOException e) {
RobotLog.e(e.toString());
textAdbLogs.setText("File not found: " + filepath);
Expand Down Expand Up @@ -168,7 +187,7 @@ private Spannable colorize(String output) {
String[] lines = output.split("\\n");
int currentStringIndex = 0;
for (String line : lines) {
if (line.contains("E/RobotCore") || line.contains(RobotLog.ERROR_PREPEND)) {
if (line.contains("E RobotCore") || line.contains(RobotLog.ERROR_PREPEND)) {
span.setSpan(new ForegroundColorSpan(Color.RED),
currentStringIndex, currentStringIndex + line.length(),
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
Expand Down
57 changes: 35 additions & 22 deletions FtcCommon/src/main/res/layout/activity_view_logs.xml
Original file line number Diff line number Diff line change
@@ -1,23 +1,36 @@
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:keepScreenOn="true"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context="com.qualcomm.ftccommon.ViewLogsActivity">

<ScrollView
android:id="@+id/scrollView"
<!--Padding is hardcoded because this activity doesn't have typical UI features,
and standard padding consequently looks weird-->
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/textAdbLogs"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="12sp"/>
</ScrollView>
</RelativeLayout>
android:layout_height="match_parent"
android:keepScreenOn="true"
android:id="@+id/viewLogsActivityLinearLayout"
android:paddingStart="8dp"
android:paddingEnd="0dp"
android:paddingTop="0dp"
android:paddingBottom="0dp"
tools:context="com.qualcomm.ftccommon.ViewLogsActivity"
android:orientation="vertical">

<HorizontalScrollView
android:id="@+id/horizontalScrollView"
android:layout_width="match_parent"
android:layout_height="match_parent">

<ScrollView
android:id="@+id/verticalScrollView"
android:layout_width="wrap_content"
android:layout_height="match_parent">

<TextView
android:id="@+id/textAdbLogs"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="12sp" />

</ScrollView>

</HorizontalScrollView>
</LinearLayout>
6 changes: 6 additions & 0 deletions FtcCommon/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="pref_line_wrap_log_title">Line Wrap</string>
<string name="pref_line_wrap_log_summary">Limits scrolling to the vertical axis</string>
<string name="pref_line_wrap_log">line_wrap_log</string>
</resources>
30 changes: 21 additions & 9 deletions FtcRobotController/src/main/res/xml/app_settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ See https://developer.android.com/guide/topics/ui/settings.html
android:title="@string/prefedit_device_name_rc"
android:summary="@string/prefedit_device_name_summary_rc"
android:key="@string/pref_device_name"
android:defaultValue=""
/>

<org.firstinspires.ftc.robotcore.internal.ui.ColorListPreference
Expand Down Expand Up @@ -79,15 +78,28 @@ See https://developer.android.com/guide/topics/ui/settings.html
/>
</PreferenceScreen>

<PreferenceScreen
android:title="@string/prefedit_view_logs"
android:summary="@string/prefedit_view_logs_summary"
android:key="@string/pref_launch_viewlogs">
<intent
android:targetPackage="@string/packageName"
android:targetClass="com.qualcomm.ftccommon.ViewLogsActivity" />
</PreferenceScreen>


</PreferenceCategory>

<PreferenceCategory
android:title="@string/prefcat_logging">

<SwitchPreference
android:title="@string/pref_line_wrap_log_title"
android:summary="@string/pref_line_wrap_log_summary"
android:key="@string/pref_line_wrap_log"
android:defaultValue="false"
/>

<PreferenceScreen
android:title="@string/prefedit_view_logs"
android:summary="@string/prefedit_view_logs_summary"
android:key="@string/pref_launch_viewlogs">
<intent
android:targetPackage="@string/packageName"
android:targetClass="com.qualcomm.ftccommon.ViewLogsActivity" />
</PreferenceScreen>
</PreferenceCategory>

</PreferenceScreen>

0 comments on commit e13e838

Please sign in to comment.