mirror of
https://github.com/ArcaneChat/android.git
synced 2026-07-03 14:05:24 +02:00
Merge pull request #963 from Ampli-fier/master
Added saving the log to file
This commit is contained in:
@@ -7,6 +7,7 @@ import android.view.MenuInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.widget.Toast;
|
||||
|
||||
import org.thoughtcrime.securesms.database.NoExternalStorageException;
|
||||
import org.thoughtcrime.securesms.util.DynamicLanguage;
|
||||
import org.thoughtcrime.securesms.util.DynamicTheme;
|
||||
import org.thoughtcrime.securesms.util.Util;
|
||||
@@ -57,10 +58,22 @@ public class LogViewActivity extends BaseActionBarActivity {
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
super.onOptionsItemSelected(item);
|
||||
Float newSize;
|
||||
|
||||
switch (item.getItemId()) {
|
||||
case android.R.id.home:
|
||||
finish();
|
||||
return true;
|
||||
case R.id.save_log:
|
||||
try {
|
||||
if (logViewFragment.saveLogFile())
|
||||
Toast.makeText(getApplicationContext(), R.string.pref_saved_log, Toast.LENGTH_LONG).show();
|
||||
else
|
||||
Toast.makeText(getApplicationContext(), R.string.pref_save_log_failed, Toast.LENGTH_LONG).show();
|
||||
} catch (NoExternalStorageException e) {
|
||||
e.printStackTrace();
|
||||
Toast.makeText(getApplicationContext(), R.string.pref_save_log_failed, Toast.LENGTH_LONG).show();
|
||||
}
|
||||
return true;
|
||||
case R.id.copy_log_to_clipboard:
|
||||
Util.writeTextToClipboard(this, logViewFragment.getLogText());
|
||||
Toast.makeText(getApplicationContext(), R.string.done, Toast.LENGTH_SHORT).show();
|
||||
|
||||
@@ -39,12 +39,19 @@ import android.widget.EditText;
|
||||
import com.b44t.messenger.DcContext;
|
||||
|
||||
import org.thoughtcrime.securesms.connect.DcHelper;
|
||||
import org.thoughtcrime.securesms.database.NoExternalStorageException;
|
||||
import org.thoughtcrime.securesms.util.Scrubber;
|
||||
import org.thoughtcrime.securesms.util.StorageUtil;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.Locale;
|
||||
|
||||
public class LogViewFragment extends Fragment {
|
||||
@@ -87,14 +94,49 @@ public class LogViewFragment extends Fragment {
|
||||
|
||||
public Float getLogTextSize() { return logPreview.getTextSize(); }
|
||||
|
||||
public void setLogTextSize(Float Textsize) {
|
||||
logPreview.setTextSize(TypedValue.COMPLEX_UNIT_PX, Textsize);
|
||||
public void setLogTextSize(Float textSize) {
|
||||
logPreview.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
|
||||
}
|
||||
|
||||
public void scrollDownLog() { logPreview.setSelection(logPreview.getText().length()); }
|
||||
|
||||
public void scrollUpLog() { logPreview.setSelection(0); }
|
||||
|
||||
public boolean saveLogFile() throws NoExternalStorageException {
|
||||
|
||||
File outputDir = null;
|
||||
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd-HHmmss");
|
||||
Date now = new Date();
|
||||
String logFileName = "deltachat-log-" + dateFormat.format(now) + ".txt";
|
||||
|
||||
try {
|
||||
outputDir = StorageUtil.getDownloadDir();
|
||||
try {
|
||||
String logText = logPreview.getText().toString();
|
||||
if(!logText.trim().equals("")){
|
||||
File logFile = new File(outputDir + "/" + logFileName);
|
||||
|
||||
if(!logFile.exists()){
|
||||
logFile.createNewFile();
|
||||
}
|
||||
|
||||
FileWriter logFileWriter = new FileWriter(logFile, false);
|
||||
BufferedWriter logFileBufferWriter = new BufferedWriter(logFileWriter);
|
||||
logFileBufferWriter.write(logText);
|
||||
logFileBufferWriter.close();
|
||||
}
|
||||
}
|
||||
catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
} catch (NoExternalStorageException e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private static String grabLogcat() {
|
||||
try {
|
||||
final Process process = Runtime.getRuntime().exec("logcat -v threadtime -d");
|
||||
|
||||
Reference in New Issue
Block a user