Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Y
YGOMobile
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
fallenstardust
YGOMobile
Commits
1ed0ec84
Commit
1ed0ec84
authored
Nov 09, 2018
by
fallenstardust
Committed by
GitHub
Nov 09, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #13 from Shinobirds/master
即使退出应用,某些手机上仍然在状态栏显示“YGOMobile正在运行”;
parents
c5ca00c5
f84d22be
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
130 additions
and
1 deletion
+130
-1
mobile/src/main/AndroidManifest.xml
mobile/src/main/AndroidManifest.xml
+1
-0
mobile/src/main/java/cn/garymb/ygomobile/ui/plus/ServiceDuelAssistant.java
...ava/cn/garymb/ygomobile/ui/plus/ServiceDuelAssistant.java
+89
-1
mobile/src/main/res/layout/notification_view_duel_assistant.xml
.../src/main/res/layout/notification_view_duel_assistant.xml
+40
-0
No files found.
mobile/src/main/AndroidManifest.xml
View file @
1ed0ec84
...
...
@@ -21,6 +21,7 @@
<uses-permission
android:name=
"android.permission.EXPAND_STATUS_BAR"
/>
<uses-permission
android:name=
"android.permission.SYSTEM_ALERT_WINDOW"
/>
<uses-permission
android:name=
"android.permission.REQUEST_INSTALL_PACKAGES"
/>
<uses-permission
android:name=
"android.permission.EXPAND_STATUS_BAR"
/>
<uses-sdk
tools:overrideLibrary=
"com.toptoche.searchablespinnerlibrary"
/>
...
...
mobile/src/main/java/cn/garymb/ygomobile/ui/plus/ServiceDuelAssistant.java
View file @
1ed0ec84
package
cn.garymb.ygomobile.ui.plus
;
import
android.annotation.SuppressLint
;
import
android.app.Notification
;
import
android.app.PendingIntent
;
import
android.app.Service
;
import
android.content.ClipData
;
import
android.content.ClipboardManager
;
...
...
@@ -11,6 +13,7 @@ import android.os.Build;
import
android.os.Handler
;
import
android.os.IBinder
;
import
android.text.TextUtils
;
import
android.util.Log
;
import
android.view.Gravity
;
import
android.view.LayoutInflater
;
import
android.view.View
;
...
...
@@ -18,11 +21,13 @@ import android.view.View.OnClickListener;
import
android.view.WindowManager
;
import
android.widget.Button
;
import
android.widget.LinearLayout
;
import
android.widget.RemoteViews
;
import
android.widget.TextView
;
import
java.io.File
;
import
java.io.FileInputStream
;
import
java.io.InputStream
;
import
java.lang.reflect.Method
;
import
cn.garymb.ygomobile.Constants
;
import
cn.garymb.ygomobile.bean.ServerInfo
;
...
...
@@ -30,6 +35,7 @@ import cn.garymb.ygomobile.bean.ServerList;
import
cn.garymb.ygomobile.lite.R
;
import
cn.garymb.ygomobile.ui.adapters.ServerListAdapter
;
import
cn.garymb.ygomobile.ui.cards.CardSearchAcitivity
;
import
cn.garymb.ygomobile.ui.home.MainActivity
;
import
cn.garymb.ygomobile.ui.home.ServerListManager
;
import
cn.garymb.ygomobile.utils.IOUtils
;
import
cn.garymb.ygomobile.utils.XmlUtils
;
...
...
@@ -39,6 +45,13 @@ import static cn.garymb.ygomobile.Constants.ASSET_SERVER_LIST;
public
class
ServiceDuelAssistant
extends
Service
{
private
final
static
String
TAG
=
ServiceDuelAssistant
.
class
.
getSimpleName
();
private
final
static
String
DUEL_ASSISTANT_SERVICE_ACTION
=
"YGOMOBILE:ACTION_DUEL_ASSISTANT_SERVICE"
;
private
final
static
String
CMD_NAME
=
"CMD"
;
private
final
static
String
CMD_START_GAME
=
"CMD : START GAME"
;
private
final
static
String
CMD_STOP_SERVICE
=
"CMD : STOP SERVICE"
;
public
static
String
cardSearchMessage
;
//卡查关键字
private
String
[]
cardSearchKey
=
new
String
[]{
"?"
,
"?"
};
...
...
@@ -78,12 +91,87 @@ public class ServiceDuelAssistant extends Service {
return
null
;
}
private
void
collapseStatusBar
()
{
try
{
@SuppressLint
(
"WrongConstant"
)
Object
statusBarManager
=
getSystemService
(
"statusbar"
);
if
(
null
==
statusBarManager
)
{
return
;
}
Class
<?>
clazz
=
statusBarManager
.
getClass
();
if
(
null
==
clazz
)
{
return
;
}
Method
methodCollapse
;
if
(
Build
.
VERSION
.
SDK_INT
<=
Build
.
VERSION_CODES
.
JELLY_BEAN
)
{
methodCollapse
=
clazz
.
getMethod
(
"collapse"
);
}
else
{
methodCollapse
=
clazz
.
getMethod
(
"collapsePanels"
);
}
if
(
null
==
methodCollapse
)
{
return
;
}
methodCollapse
.
invoke
(
statusBarManager
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
}
@Override
public
int
onStartCommand
(
Intent
intent
,
int
flags
,
int
startId
)
{
String
action
=
intent
.
getAction
();
Log
.
d
(
TAG
,
"rev action:"
+
action
);
if
(
DUEL_ASSISTANT_SERVICE_ACTION
.
equals
(
action
))
{
String
cmd
=
intent
.
getStringExtra
(
CMD_NAME
);
Log
.
d
(
TAG
,
"rev cmd:"
+
cmd
);
if
(
null
==
cmd
)
{
Log
.
e
(
TAG
,
"cmd null"
);
}
else
{
switch
(
cmd
)
{
case
CMD_STOP_SERVICE:
stopSelf
();
break
;
case
CMD_START_GAME:
startActivity
(
new
Intent
(
this
,
MainActivity
.
class
));
break
;
default
:
Log
.
e
(
TAG
,
"unknown cmd:"
+
cmd
);
break
;
}
collapseStatusBar
();
}
}
return
super
.
onStartCommand
(
intent
,
flags
,
startId
);
}
@Override
public
void
onCreate
()
{
// TODO: Implement this method
super
.
onCreate
();
if
(
Build
.
VERSION
.
SDK_INT
>=
Build
.
VERSION_CODES
.
O
)
{
startForeground
(
1
,
new
Notification
());
RemoteViews
remoteViews
=
new
RemoteViews
(
getPackageName
(),
R
.
layout
.
notification_view_duel_assistant
);
Intent
intent
=
new
Intent
(
this
,
this
.
getClass
());
intent
.
setAction
(
DUEL_ASSISTANT_SERVICE_ACTION
);
PendingIntent
pendingIntent
;
intent
.
putExtra
(
CMD_NAME
,
CMD_START_GAME
);
pendingIntent
=
PendingIntent
.
getService
(
this
,
1
,
intent
,
PendingIntent
.
FLAG_UPDATE_CURRENT
);
remoteViews
.
setOnClickPendingIntent
(
R
.
id
.
notification_view_duel_assistant
,
pendingIntent
);
intent
.
putExtra
(
CMD_NAME
,
CMD_STOP_SERVICE
);
pendingIntent
=
PendingIntent
.
getService
(
this
,
2
,
intent
,
PendingIntent
.
FLAG_UPDATE_CURRENT
);
remoteViews
.
setOnClickPendingIntent
(
R
.
id
.
buttonStopService
,
pendingIntent
);
Notification
.
Builder
builder
=
new
Notification
.
Builder
(
this
);
builder
.
setSmallIcon
(
R
.
drawable
.
ic_icon
);
builder
.
setCustomContentView
(
remoteViews
);
startForeground
(
1
,
builder
.
build
());
}
//lc = new ArrayList<Card>();
...
...
mobile/src/main/res/layout/notification_view_duel_assistant.xml
0 → 100644
View file @
1ed0ec84
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android=
"http://schemas.android.com/apk/res/android"
android:id=
"@+id/notification_view_duel_assistant"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
>
<ImageView
android:id=
"@+id/imageViewIcon"
android:layout_width=
"40dp"
android:layout_height=
"40dp"
android:layout_alignParentStart=
"true"
android:layout_alignParentLeft=
"true"
android:layout_centerVertical=
"true"
android:src=
"@drawable/ic_icon"
/>
<Button
android:id=
"@+id/buttonStopService"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_alignParentEnd=
"true"
android:layout_alignParentRight=
"true"
android:layout_centerVertical=
"true"
android:padding=
"15dp"
android:textColor=
"@color/colorAccent"
android:text=
"关闭"
/>
<TextView
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_toEndOf=
"@id/imageViewIcon"
android:layout_toRightOf=
"@id/imageViewIcon"
android:layout_toStartOf=
"@id/buttonStopService"
android:layout_toLeftOf=
"@id/buttonStopService"
android:layout_marginStart=
"5dp"
android:layout_marginEnd=
"5dp"
android:layout_centerVertical=
"true"
android:textSize=
"18sp"
android:text=
"决斗助手运行中"
/>
</RelativeLayout>
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