-
Notifications
You must be signed in to change notification settings - Fork 406
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
90 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
app/src/main/java/name/gudong/translate/service/QuickSettingService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package name.gudong.translate.service; | ||
|
||
import android.annotation.TargetApi; | ||
import android.content.Intent; | ||
import android.os.Build; | ||
import android.service.quicksettings.Tile; | ||
import android.service.quicksettings.TileService; | ||
import android.util.Log; | ||
|
||
import name.gudong.translate.listener.ListenClipboardService; | ||
import name.gudong.translate.manager.ReciteModulePreference; | ||
|
||
@TargetApi(Build.VERSION_CODES.N) | ||
public class QuickSettingService extends TileService { | ||
private static final String TAG = "QuickSettingService"; | ||
ReciteModulePreference mRecitePreference; | ||
|
||
@Override | ||
public void onCreate() { | ||
super.onCreate(); | ||
mRecitePreference = new ReciteModulePreference(getBaseContext()); | ||
} | ||
|
||
|
||
@Override | ||
public int onStartCommand(Intent intent, int flags, int startId) { | ||
if(getQsTile() == null){ | ||
return super.onStartCommand(intent, flags, startId); | ||
} | ||
if(mRecitePreference.isReciteOpenOrNot()){ | ||
getQsTile().setState(Tile.STATE_ACTIVE);// 更改成非活跃状态 | ||
}else{ | ||
getQsTile().setState(Tile.STATE_INACTIVE);// 更改成非活跃状态 | ||
} | ||
return super.onStartCommand(intent, flags, startId); | ||
} | ||
|
||
@Override | ||
public void onClick() { | ||
int state = getQsTile().getState(); | ||
Log.d(TAG, "onClick state = " + Integer.toString(getQsTile().getState())); | ||
if (state == Tile.STATE_INACTIVE) { | ||
getQsTile().setState(Tile.STATE_ACTIVE);// 更改成活跃状态 | ||
mRecitePreference.setReciteOpenOrNot(true); | ||
} else { | ||
getQsTile().setState(Tile.STATE_INACTIVE);//更改成非活跃状态 | ||
mRecitePreference.setReciteOpenOrNot(false); | ||
} | ||
getQsTile().updateTile();//更新Tile | ||
shiftRecite(); | ||
} | ||
|
||
private void shiftRecite() { | ||
//利用 Service 生命周期巧妙控制开关 | ||
ListenClipboardService.start(getBaseContext()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters