mirror of
https://github.com/syncthing/syncthing-android.git
synced 2024-11-30 08:11:17 +00:00
Merge branch 'log' of https://github.com/Zillode/syncthing-android into Zillode-log
Conflicts: src/main/java/com/nutomic/syncthingandroid/syncthing/GetTask.java
This commit is contained in:
commit
74062e8269
8 changed files with 250 additions and 3 deletions
|
@ -25,7 +25,6 @@
|
||||||
android:launchMode="singleTop">
|
android:launchMode="singleTop">
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="android.intent.action.MAIN" />
|
<action android:name="android.intent.action.MAIN" />
|
||||||
|
|
||||||
<category android:name="android.intent.category.LAUNCHER" />
|
<category android:name="android.intent.category.LAUNCHER" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
</activity>
|
</activity>
|
||||||
|
@ -44,6 +43,18 @@
|
||||||
android:name="android.support.PARENT_ACTIVITY"
|
android:name="android.support.PARENT_ACTIVITY"
|
||||||
android:value=".activities.MainActivity" />
|
android:value=".activities.MainActivity" />
|
||||||
</activity>
|
</activity>
|
||||||
|
<activity
|
||||||
|
android:name=".activities.LogActivity"
|
||||||
|
android:label="@string/log_title"
|
||||||
|
android:parentActivityName=".activities.SettingsActivity">
|
||||||
|
<intent-filter>
|
||||||
|
<action android:name=".activities.LogActivity" />
|
||||||
|
<category android:name="android.intent.category.DEFAULT" />
|
||||||
|
</intent-filter>
|
||||||
|
<meta-data
|
||||||
|
android:name="android.support.PARENT_ACTIVITY"
|
||||||
|
android:value=".activities.SettingsActivity" />
|
||||||
|
</activity>
|
||||||
|
|
||||||
<service android:name=".syncthing.SyncthingService" />
|
<service android:name=".syncthing.SyncthingService" />
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,160 @@
|
||||||
|
package com.nutomic.syncthingandroid.activities;
|
||||||
|
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.os.AsyncTask;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.support.v7.widget.ShareActionProvider;
|
||||||
|
import android.util.Log;
|
||||||
|
import android.view.Menu;
|
||||||
|
import android.view.MenuInflater;
|
||||||
|
import android.view.MenuItem;
|
||||||
|
import android.widget.EditText;
|
||||||
|
|
||||||
|
import android.support.v4.view.MenuItemCompat;
|
||||||
|
import android.widget.ScrollView;
|
||||||
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import com.nutomic.syncthingandroid.R;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.DataOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Shows the log information from Syncthing.
|
||||||
|
*/
|
||||||
|
public class LogActivity extends SyncthingActivity {
|
||||||
|
|
||||||
|
private final static String TAG = "LogActivity";
|
||||||
|
|
||||||
|
private TextView mLog;
|
||||||
|
private boolean mSyncthingLog = true;
|
||||||
|
private AsyncTask mFetchLogTask;
|
||||||
|
private ScrollView mScrollView;
|
||||||
|
private Intent mShareIntent;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initialize Log.
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
|
setContentView(R.layout.log_activity);
|
||||||
|
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
||||||
|
|
||||||
|
if (savedInstanceState != null) {
|
||||||
|
mSyncthingLog = savedInstanceState.getBoolean("syncthingLog");
|
||||||
|
invalidateOptionsMenu();
|
||||||
|
}
|
||||||
|
|
||||||
|
mLog = (TextView) findViewById(R.id.log);
|
||||||
|
mScrollView = (ScrollView) findViewById(R.id.scroller);
|
||||||
|
|
||||||
|
updateLog();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onSaveInstanceState(Bundle outState) {
|
||||||
|
super.onSaveInstanceState(outState);
|
||||||
|
outState.putBoolean("syncthingLog", mSyncthingLog);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onCreateOptionsMenu(Menu menu) {
|
||||||
|
MenuInflater inflater = getMenuInflater();
|
||||||
|
inflater.inflate(R.menu.log_list, menu);
|
||||||
|
|
||||||
|
MenuItem switchLog = menu.findItem(R.id.switch_logs);
|
||||||
|
switchLog.setTitle(mSyncthingLog ? R.string.log_android_title : R.string.log_syncthing_title);
|
||||||
|
|
||||||
|
// Add the share button
|
||||||
|
MenuItem shareItem = menu.findItem(R.id.menu_share);
|
||||||
|
ShareActionProvider actionProvider = (ShareActionProvider) MenuItemCompat.getActionProvider(shareItem);
|
||||||
|
mShareIntent = new Intent();
|
||||||
|
mShareIntent.setAction(Intent.ACTION_SEND);
|
||||||
|
mShareIntent.setType("text/plain");
|
||||||
|
mShareIntent.putExtra(android.content.Intent.EXTRA_TEXT, mLog.getText());
|
||||||
|
actionProvider.setShareIntent(mShareIntent);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onOptionsItemSelected(MenuItem item) {
|
||||||
|
switch (item.getItemId()) {
|
||||||
|
case R.id.switch_logs:
|
||||||
|
mSyncthingLog = !mSyncthingLog;
|
||||||
|
item.setTitle(mSyncthingLog ? R.string.log_android_title : R.string.log_syncthing_title);
|
||||||
|
updateLog();
|
||||||
|
return true;
|
||||||
|
default:
|
||||||
|
return super.onOptionsItemSelected(item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void scrollToBottom() {
|
||||||
|
mScrollView.post(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
mScrollView.scrollTo(0, mLog.getBottom());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateLog() {
|
||||||
|
if (mFetchLogTask != null)
|
||||||
|
mFetchLogTask.cancel(true);
|
||||||
|
mLog.setText("Retrieving logs...");
|
||||||
|
mFetchLogTask = new AsyncTask<Void, Void, String>() {
|
||||||
|
@Override
|
||||||
|
protected String doInBackground(Void... params) {
|
||||||
|
return getLog(mSyncthingLog);
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
protected void onPostExecute(String log) {
|
||||||
|
mLog.setText(log);
|
||||||
|
if (mShareIntent != null)
|
||||||
|
mShareIntent.putExtra(android.content.Intent.EXTRA_TEXT, log);
|
||||||
|
scrollToBottom();
|
||||||
|
}
|
||||||
|
}.execute();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Queries logcat to obtain a log.
|
||||||
|
*
|
||||||
|
* @param syncthingLog Filter on Syncthing's native messages.
|
||||||
|
*/
|
||||||
|
private String getLog(final boolean syncthingLog) {
|
||||||
|
Process process = null;
|
||||||
|
try {
|
||||||
|
ProcessBuilder pb;
|
||||||
|
if (syncthingLog) {
|
||||||
|
pb = new ProcessBuilder("/system/bin/logcat", "-t", "300", "-s", "SyncthingNativeCode");
|
||||||
|
} else {
|
||||||
|
pb = new ProcessBuilder("/system/bin/logcat", "-t", "300", "'*'");
|
||||||
|
}
|
||||||
|
pb.redirectErrorStream(true);
|
||||||
|
process = pb.start();
|
||||||
|
BufferedReader bufferedReader = new BufferedReader(
|
||||||
|
new InputStreamReader(process.getInputStream()), 8192);
|
||||||
|
StringBuilder log = new StringBuilder();
|
||||||
|
String line = "";
|
||||||
|
while ((line = bufferedReader.readLine()) != null) {
|
||||||
|
log.append(line);
|
||||||
|
log.append(System.getProperty("line.separator"));
|
||||||
|
}
|
||||||
|
return log.toString();
|
||||||
|
} catch (IOException e) {
|
||||||
|
Log.w(TAG, "Error reading Android log", e);
|
||||||
|
} finally {
|
||||||
|
if (process != null) {
|
||||||
|
process.destroy();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -43,7 +43,7 @@ public class SettingsActivity extends SyncthingActivity {
|
||||||
if (savedInstanceState != null) {
|
if (savedInstanceState != null) {
|
||||||
mFragment = fm.getFragment(savedInstanceState,
|
mFragment = fm.getFragment(savedInstanceState,
|
||||||
savedInstanceState.getString("fragment_name"));
|
savedInstanceState.getString("fragment_name"));
|
||||||
} else {
|
} else if (getIntent().getAction() != null) {
|
||||||
switch (getIntent().getAction()) {
|
switch (getIntent().getAction()) {
|
||||||
case ACTION_APP_SETTINGS_FRAGMENT:
|
case ACTION_APP_SETTINGS_FRAGMENT:
|
||||||
setTitle(R.string.settings_title);
|
setTitle(R.string.settings_title);
|
||||||
|
@ -65,6 +65,9 @@ public class SettingsActivity extends SyncthingActivity {
|
||||||
throw new IllegalArgumentException(
|
throw new IllegalArgumentException(
|
||||||
"You must provide the requested fragment type as an extra.");
|
"You must provide the requested fragment type as an extra.");
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
setTitle(R.string.settings_title);
|
||||||
|
mFragment = new SettingsFragment();
|
||||||
}
|
}
|
||||||
|
|
||||||
fm.beginTransaction()
|
fm.beginTransaction()
|
||||||
|
|
|
@ -93,7 +93,7 @@ public class GetTask extends AsyncTask<String, Void, String> {
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
Log.w(TAG, e);
|
Log.w(TAG, e);
|
||||||
}
|
}
|
||||||
Log.w(TAG, "Retrying GetTask Rest API call ("+i+")");
|
Log.w(TAG, "Retrying GetTask Rest API call ("+(i+1)+"/10)");
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
24
src/main/res/layout/log_activity.xml
Normal file
24
src/main/res/layout/log_activity.xml
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
|
||||||
|
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent">
|
||||||
|
|
||||||
|
<ScrollView
|
||||||
|
android:id="@+id/scroller"
|
||||||
|
android:layout_width="fill_parent"
|
||||||
|
android:layout_height="fill_parent"
|
||||||
|
android:scrollbars="vertical"
|
||||||
|
android:fillViewport="true">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/log"
|
||||||
|
android:gravity="top"
|
||||||
|
android:textSize="10sp"
|
||||||
|
android:textIsSelectable="true"
|
||||||
|
android:layout_width="fill_parent"
|
||||||
|
android:layout_height="fill_parent" />
|
||||||
|
|
||||||
|
</ScrollView>
|
||||||
|
|
||||||
|
</RelativeLayout>
|
17
src/main/res/menu/log_list.xml
Normal file
17
src/main/res/menu/log_list.xml
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
|
||||||
|
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||||
|
|
||||||
|
<item
|
||||||
|
android:id="@+id/switch_logs"
|
||||||
|
android:title="@string/log_android_title"
|
||||||
|
app:showAsAction="always" />
|
||||||
|
|
||||||
|
<item
|
||||||
|
android:id="@+id/menu_share"
|
||||||
|
android:title="@string/share_title"
|
||||||
|
app:actionProviderClass="android.support.v7.widget.ShareActionProvider"
|
||||||
|
app:showAsAction="always" />
|
||||||
|
|
||||||
|
</menu>
|
|
@ -288,6 +288,12 @@ Please report any problems you encounter via Github.</string>
|
||||||
|
|
||||||
<string name="category_about">About</string>
|
<string name="category_about">About</string>
|
||||||
|
|
||||||
|
<!-- Settings item that opens the log activity -->
|
||||||
|
<string name="open_log">Open Log</string>
|
||||||
|
|
||||||
|
<!-- Summary for the log activity -->
|
||||||
|
<string name="open_log_summary">Open the Syncthing and Android log window</string>
|
||||||
|
|
||||||
<!-- Settings item that opens issue tracker -->
|
<!-- Settings item that opens issue tracker -->
|
||||||
<string name="report_issue_title">Report Issue</string>
|
<string name="report_issue_title">Report Issue</string>
|
||||||
|
|
||||||
|
@ -323,6 +329,25 @@ Please report any problems you encounter via Github.</string>
|
||||||
|
|
||||||
<string name="create_folder_failed">Failed to create folder</string>
|
<string name="create_folder_failed">Failed to create folder</string>
|
||||||
|
|
||||||
|
<!-- LogActivity -->
|
||||||
|
|
||||||
|
|
||||||
|
<!-- Title of the "log" activity -->
|
||||||
|
<string name="log_title">Log</string>
|
||||||
|
|
||||||
|
<!-- Title of the "log android" menu button -->
|
||||||
|
<string name="log_android_title">View Android Log</string>
|
||||||
|
|
||||||
|
<!-- Title of the "log Syncthing" menu button -->
|
||||||
|
<string name="log_syncthing_title">View Syncthing Log</string>
|
||||||
|
|
||||||
|
<!-- Title of the "share log" menu action -->
|
||||||
|
<string name="share_log_title">Share Log</string>
|
||||||
|
|
||||||
|
<!-- Title of the "share log" menu button -->
|
||||||
|
<string name="share_title">Share</string>
|
||||||
|
|
||||||
|
|
||||||
<!-- SyncthingService -->
|
<!-- SyncthingService -->
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -120,6 +120,13 @@
|
||||||
<PreferenceCategory
|
<PreferenceCategory
|
||||||
android:title="@string/category_about">
|
android:title="@string/category_about">
|
||||||
|
|
||||||
|
<Preference
|
||||||
|
android:title="@string/open_log"
|
||||||
|
android:summary="@string/open_log_summary">
|
||||||
|
<intent
|
||||||
|
android:action=".activities.LogActivity" />
|
||||||
|
</Preference>
|
||||||
|
|
||||||
<Preference
|
<Preference
|
||||||
android:title="@string/report_issue_title"
|
android:title="@string/report_issue_title"
|
||||||
android:summary="@string/report_issue_summary">
|
android:summary="@string/report_issue_summary">
|
||||||
|
|
Loading…
Reference in a new issue