This commit is contained in:
Milos Kozak 2017-02-09 22:29:21 +01:00
parent ed7dd48612
commit 90061c6f25
6 changed files with 84 additions and 7 deletions

View file

@ -37,7 +37,7 @@
<ConfirmationsSetting value="0" id="Add" />
<ConfirmationsSetting value="0" id="Remove" />
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" default="true" assert-keyword="true" jdk-15="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" assert-keyword="true" jdk-15="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" />
</component>
<component name="ProjectType">

View file

@ -9,7 +9,6 @@ import android.os.Build;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.v4.app.ActivityCompat;
import android.support.v4.app.Fragment;
import android.support.v4.content.ContextCompat;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AlertDialog;
@ -29,10 +28,9 @@ import info.nightscout.androidaps.events.EventAppExit;
import info.nightscout.androidaps.events.EventPreferenceChange;
import info.nightscout.androidaps.events.EventRefreshGui;
import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.plugins.DanaR.Services.ExecutionService;
import info.nightscout.androidaps.receivers.KeepAliveReceiver;
import info.nightscout.androidaps.tabs.SlidingTabLayout;
import info.nightscout.androidaps.tabs.TabPageAdapter;
import info.nightscout.utils.LogDialog;
import info.nightscout.utils.ImportExportPrefs;
import info.nightscout.utils.LocaleHelper;
@ -145,6 +143,9 @@ public class MainActivity extends AppCompatActivity {
ImportExportPrefs.verifyStoragePermissions(this);
ImportExportPrefs.importSharedPreferences(this);
break;
case R.id.nav_show_logcat:
LogDialog.showLogcat(this);
break;
// case R.id.nav_test_alarm:
// final int REQUEST_CODE_ASK_PERMISSIONS = 2355;
// int permission = ActivityCompat.checkSelfPermission(this, Manifest.permission.SYSTEM_ALERT_WINDOW);

View file

@ -0,0 +1,68 @@
package info.nightscout.utils;
import android.app.AlertDialog;
import android.content.ClipData;
import android.content.Context;
import android.content.DialogInterface;
import android.content.ClipboardManager;
import android.widget.TextView;
import com.crashlytics.android.Crashlytics;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
/**
* Created by mike on 09.02.2017.
*/
public class LogDialog {
public static void showLogcat(Context context) {
String logCat = "no logs";
final String processId = Integer.toString(android.os.Process.myPid());
try {
Process process = Runtime.getRuntime().exec("logcat -d " + MainApp.sResources.getString(R.string.app_name) + ":D");
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(process.getInputStream()));
StringBuilder log = new StringBuilder();
String line;
while ((line = bufferedReader.readLine()) != null) {
if (line.contains(processId)) log.append(line + "\n");
}
logCat = log.toString();
} catch (IOException e) {
logCat = e.getLocalizedMessage();
} finally {
showAlertText(logCat, context);
}
}
public static void showAlertText(final String msg, final Context context) {
try {
AlertDialog alertDialog = new AlertDialog.Builder(context)
.setMessage(msg)
.setPositiveButton(MainApp.sResources.getString(R.string.copy_to_clipboard), new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
clipboard.setPrimaryClip(ClipData.newPlainText(null, msg));
ToastUtils.showToastInUiThread(context, MainApp.sResources.getString(R.string.copied_to_clipboard));
}
})
.setNegativeButton(android.R.string.cancel, null)
.show();
if (msg.length() > 100) {
TextView textView = (TextView) alertDialog.findViewById(android.R.id.message);
textView.setTextSize(10);
}
} catch (Exception e) {
// crashing on screen rotation
}
}
}

View file

@ -14,8 +14,8 @@
android:id="@+id/nav_import"
android:title="@string/nav_import" />
<item
android:id="@+id/nav_test_alarm"
android:title="@string/nav_test_alert" />
android:id="@+id/nav_show_logcat"
android:title="@string/nav_show_logcat" />
<item
android:id="@+id/nav_exit"
android:title="@string/nav_exit" />

View file

@ -240,7 +240,6 @@
<string name="manual">Jiný</string>
<string name="glucosetype_sensor">Senzor</string>
<string name="danarprofile">DanaR profil</string>
<string name="danarprofile_dia">Celková doba aktivity inzulínu[h]</string>
<string name="failedupdatebasalprofile">Chyba při nastavení dočasného bazálu</string>
<string name="danar_alarm">alarm</string>
<string name="danar_basalhour">hodinový bazál</string>
@ -441,4 +440,10 @@
<string name="virtualpump_firmware_label">Firmware:</string>
<string name="smscommunicator_invalidphonennumber">Špatné telefonní číslo</string>
<string name="tempbasaldeliveryerror">Chyba nastavování dočasného bazálu</string>
<string name="copied_to_clipboard">Nakopírováno do schránky</string>
<string name="copy_to_clipboard">Kopírovat do schránky</string>
<string name="danarprofile_dia_summary">Celková doba aktivity inzulínu</string>
<string name="danarprofile_dia">DIA [h]</string>
<string name="error_field_must_not_be_empty"></string>
<string name="nav_show_logcat">Zobrazit log</string>
</resources>

View file

@ -476,4 +476,7 @@
<string name="error_field_must_not_be_empty">The field must not be empty</string>
<string name="error_phone_not_valid">Phone number not valid</string>
<string name="smscommunicator_invalidphonennumber">Invalid SMS phone number</string>
<string name="copy_to_clipboard">Copy To Clipboard</string>
<string name="copied_to_clipboard">Copied to clipboard</string>
<string name="nav_show_logcat">Show log</string>
</resources>