4 changed files with 215 additions and 3 deletions
-
2app/src/main/AndroidManifest.xml
-
78app/src/main/java/com/ouxuan/oxface/LogTestActivity.java
-
62app/src/main/java/com/ouxuan/oxface/MainActivity.java
-
76app/src/main/java/com/ouxuan/oxface/utils/LogManager.java
@ -0,0 +1,78 @@ |
|||
package com.ouxuan.oxface; |
|||
|
|||
import android.app.Activity; |
|||
import android.os.Bundle; |
|||
import android.util.Log; |
|||
import android.widget.Button; |
|||
import android.widget.ScrollView; |
|||
import android.widget.TextView; |
|||
import android.widget.Toast; |
|||
|
|||
import com.ouxuan.oxface.utils.LogManager; |
|||
|
|||
/** |
|||
* 日志测试活动 |
|||
* 用于测试日志功能并显示日志路径信息 |
|||
*/ |
|||
public class LogTestActivity extends Activity { |
|||
|
|||
private static final String TAG = "LogTestActivity"; |
|||
private TextView pathInfoText; |
|||
private Button writeLogButton; |
|||
private Button refreshInfoButton; |
|||
|
|||
@Override |
|||
protected void onCreate(Bundle savedInstanceState) { |
|||
super.onCreate(savedInstanceState); |
|||
|
|||
// 创建简单的布局 |
|||
ScrollView scrollView = new ScrollView(this); |
|||
android.widget.LinearLayout layout = new android.widget.LinearLayout(this); |
|||
layout.setOrientation(android.widget.LinearLayout.VERTICAL); |
|||
layout.setPadding(20, 20, 20, 20); |
|||
|
|||
// 路径信息显示 |
|||
pathInfoText = new TextView(this); |
|||
pathInfoText.setTextSize(12); |
|||
pathInfoText.setBackgroundColor(0xFFF5F5F5); |
|||
pathInfoText.setPadding(10, 10, 10, 10); |
|||
layout.addView(pathInfoText); |
|||
|
|||
// 写入日志按钮 |
|||
writeLogButton = new Button(this); |
|||
writeLogButton.setText("写入测试日志"); |
|||
writeLogButton.setOnClickListener(v -> writeTestLogs()); |
|||
layout.addView(writeLogButton); |
|||
|
|||
// 刷新信息按钮 |
|||
refreshInfoButton = new Button(this); |
|||
refreshInfoButton.setText("刷新路径信息"); |
|||
refreshInfoButton.setOnClickListener(v -> refreshPathInfo()); |
|||
layout.addView(refreshInfoButton); |
|||
|
|||
scrollView.addView(layout); |
|||
setContentView(scrollView); |
|||
|
|||
// 显示初始路径信息 |
|||
refreshPathInfo(); |
|||
} |
|||
|
|||
private void writeTestLogs() { |
|||
LogManager.logInfo(TAG, "这是一条测试信息日志"); |
|||
LogManager.logWarning(TAG, "这是一条测试警告日志"); |
|||
LogManager.logError(TAG, "这是一条测试错误日志"); |
|||
LogManager.logOperation("测试操作", "写入测试日志成功"); |
|||
LogManager.logPerformance("测试性能", 100); |
|||
|
|||
Toast.makeText(this, "测试日志已写入", Toast.LENGTH_SHORT).show(); |
|||
|
|||
// 延迟刷新路径信息 |
|||
pathInfoText.postDelayed(this::refreshPathInfo, 1000); |
|||
} |
|||
|
|||
private void refreshPathInfo() { |
|||
String pathInfo = LogManager.getLogPathInfo(this); |
|||
pathInfoText.setText("日志路径信息:\n\n" + pathInfo); |
|||
Log.i(TAG, "日志路径信息:\n" + pathInfo); |
|||
} |
|||
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue