Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
E
echo-adr-Deprecated
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
echo
echo-adr-Deprecated
Commits
50ad9037
Commit
50ad9037
authored
Jul 23, 2020
by
Administrator
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
日志页面
parent
34974e57
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
179 additions
and
4 deletions
+179
-4
EchoApplication.java
app/src/main/java/com/virjar/echo/adr/EchoApplication.java
+2
-0
LogServices.java
.../main/java/com/virjar/echo/adr/component/LogServices.java
+82
-0
LogFragment.java
app/src/main/java/com/virjar/echo/adr/ui/LogFragment.java
+53
-3
MainActivity.java
app/src/main/java/com/virjar/echo/adr/ui/MainActivity.java
+5
-1
fragment_log.xml
app/src/main/res/layout/fragment_log.xml
+37
-0
No files found.
app/src/main/java/com/virjar/echo/adr/EchoApplication.java
View file @
50ad9037
...
...
@@ -2,6 +2,7 @@ package com.virjar.echo.adr;
import
android.app.Application
;
import
com.virjar.echo.adr.component.LogServices
;
import
com.virjar.echo.adr.repo.EchoConfig
;
public
class
EchoApplication
extends
Application
{
...
...
@@ -9,6 +10,7 @@ public class EchoApplication extends Application {
@Override
public
void
onCreate
()
{
super
.
onCreate
();
LogServices
.
init
();
EchoConfig
.
init
(
this
);
}
}
app/src/main/java/com/virjar/echo/adr/component/LogServices.java
0 → 100644
View file @
50ad9037
package
com
.
virjar
.
echo
.
adr
.
component
;
import
com.virjar.echo.nat.log.EchoLogger
;
import
com.virjar.echo.nat.log.ILogger
;
import
java.util.concurrent.atomic.AtomicLong
;
public
class
LogServices
{
private
static
final
int
bufferSize
=
30
;
private
static
String
[]
buffer
;
private
static
AtomicLong
index
=
new
AtomicLong
(
0
);
private
static
class
EchoPrintLogger
implements
ILogger
{
private
ILogger
delegate
;
public
EchoPrintLogger
(
ILogger
delegate
)
{
this
.
delegate
=
delegate
;
}
@Override
public
void
info
(
String
msg
)
{
addLog
(
msg
);
delegate
.
info
(
msg
);
}
@Override
public
void
info
(
String
msg
,
Throwable
throwable
)
{
addLog
(
msg
);
delegate
.
info
(
msg
,
throwable
);
}
@Override
public
void
warn
(
String
msg
)
{
addLog
(
msg
);
delegate
.
warn
(
msg
);
}
@Override
public
void
warn
(
String
msg
,
Throwable
throwable
)
{
addLog
(
msg
);
delegate
.
warn
(
msg
,
throwable
);
}
@Override
public
void
error
(
String
msg
)
{
addLog
(
msg
);
delegate
.
error
(
msg
);
}
@Override
public
void
error
(
String
msg
,
Throwable
throwable
)
{
addLog
(
msg
);
delegate
.
error
(
msg
,
throwable
);
}
}
public
static
void
init
()
{
buffer
=
new
String
[
bufferSize
];
ILogger
logger
=
EchoLogger
.
getLogger
();
EchoLogger
.
setLogger
(
new
EchoPrintLogger
(
logger
));
}
public
static
void
addLog
(
String
message
)
{
long
insertIndex
=
index
.
getAndIncrement
();
buffer
[(
int
)
(
insertIndex
%
buffer
.
length
)]
=
message
;
}
public
static
StringBuffer
logSnapshot
()
{
StringBuffer
stringBuffer
=
new
StringBuffer
(
20
*
32
);
int
readStartIndex
=
(
int
)
(
index
.
get
()
%
buffer
.
length
)
+
buffer
.
length
-
1
;
for
(
int
i
=
0
;
i
<
buffer
.
length
;
i
++)
{
int
readIndex
=
(
readStartIndex
-
i
)
%
buffer
.
length
;
String
log
=
buffer
[
readIndex
];
if
(
log
==
null
)
{
break
;
}
stringBuffer
.
append
(
log
).
append
(
"\n"
);
}
return
stringBuffer
;
}
}
app/src/main/java/com/virjar/echo/adr/ui/LogFragment.java
View file @
50ad9037
package
com
.
virjar
.
echo
.
adr
.
ui
;
import
android.os.Bundle
;
import
android.os.Handler
;
import
android.os.Looper
;
import
android.view.LayoutInflater
;
import
android.view.View
;
import
android.view.ViewGroup
;
import
android.widget.TextView
;
import
androidx.annotation.NonNull
;
import
androidx.annotation.Nullable
;
import
androidx.fragment.app.Fragment
;
import
com.virjar.echo.adr.R
;
import
com.virjar.echo.adr.component.LogServices
;
public
class
LogFragment
extends
Fragment
{
private
String
fragmentText
;
public
LogFragment
(
String
fragmentText
)
{
this
.
fragmentText
=
fragmentText
;
private
TextView
logView
;
private
boolean
running
=
false
;
@Nullable
@Override
public
View
onCreateView
(
@NonNull
LayoutInflater
inflater
,
@Nullable
ViewGroup
container
,
@Nullable
Bundle
savedInstanceState
)
{
View
view
=
inflater
.
inflate
(
R
.
layout
.
fragment_log
,
container
,
false
);
logView
=
view
.
findViewById
(
R
.
id
.
tv_log
);
logView
.
setText
(
LogServices
.
logSnapshot
());
return
view
;
}
public
void
start
()
{
if
(
running
)
{
return
;
}
running
=
true
;
updateLog
();
}
public
void
stop
()
{
running
=
false
;
}
private
void
updateLog
()
{
if
(
logView
!=
null
)
{
logView
.
setText
(
LogServices
.
logSnapshot
());
}
if
(!
running
)
{
return
;
}
new
Handler
(
Looper
.
getMainLooper
()).
postDelayed
(
new
Runnable
()
{
@Override
public
void
run
()
{
updateLog
();
}
},
500
);
}
}
app/src/main/java/com/virjar/echo/adr/ui/MainActivity.java
View file @
50ad9037
...
...
@@ -53,16 +53,20 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
FragmentTransaction
fragmentTransaction
=
mfragmentManger
.
beginTransaction
();
//只能是局部变量,不能为全局变量,否则不能重复commit
//FragmentTransaction只能使用一次
hideAllFragment
(
fragmentTransaction
);
if
(
R
.
id
.
main_log
!=
view
.
getId
()
&&
logFragment
!=
null
)
{
logFragment
.
stop
();
}
switch
(
view
.
getId
())
{
case
R
.
id
.
main_log
:
setAllFalse
();
logLinear
.
setSelected
(
true
);
if
(
logFragment
==
null
)
{
logFragment
=
new
LogFragment
(
"Log"
);
logFragment
=
new
LogFragment
();
fragmentTransaction
.
add
(
R
.
id
.
fragment_frame
,
logFragment
);
}
else
{
fragmentTransaction
.
show
(
logFragment
);
}
logFragment
.
start
();
break
;
case
R
.
id
.
main_setting
:
setAllFalse
();
...
...
app/src/main/res/layout/fragment_log.xml
0 → 100644
View file @
50ad9037
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
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"
tools:context=
".ui.LogFragment"
>
<LinearLayout
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
android:orientation=
"vertical"
>
<LinearLayout
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:orientation=
"horizontal"
>
<TextView
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:text=
"当前出口:"
/>
<TextView
android:id=
"@+id/tv_mapping_proxy"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
/>
</LinearLayout>
<TextView
android:id=
"@+id/tv_log"
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
/>
</LinearLayout>
</FrameLayout>
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment