添加主要服务启动设置
This commit is contained in:
parent
b9f740c386
commit
3734a659ff
@ -1,8 +1,8 @@
|
|||||||
#Created by .winboll/winboll_app_build.gradle
|
#Created by .winboll/winboll_app_build.gradle
|
||||||
#Tue Feb 25 19:32:36 GMT 2025
|
#Tue Feb 25 20:33:54 GMT 2025
|
||||||
stageCount=2
|
stageCount=2
|
||||||
libraryProject=
|
libraryProject=
|
||||||
baseVersion=1.0
|
baseVersion=1.0
|
||||||
publishVersion=1.0.1
|
publishVersion=1.0.1
|
||||||
buildCount=34
|
buildCount=41
|
||||||
baseBetaVersion=1.0.2
|
baseBetaVersion=1.0.2
|
||||||
|
@ -47,6 +47,8 @@ import java.util.ArrayList;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
import cc.winboll.studio.contacts.activities.SettingsActivity;
|
import cc.winboll.studio.contacts.activities.SettingsActivity;
|
||||||
|
import cc.winboll.studio.contacts.beans.MainServiceBean;
|
||||||
|
import cc.winboll.studio.contacts.services.MainService;
|
||||||
|
|
||||||
final public class MainActivity extends AppCompatActivity implements IWinBollActivity, ViewPager.OnPageChangeListener, View.OnClickListener {
|
final public class MainActivity extends AppCompatActivity implements IWinBollActivity, ViewPager.OnPageChangeListener, View.OnClickListener {
|
||||||
|
|
||||||
@ -140,7 +142,15 @@ final public class MainActivity extends AppCompatActivity implements IWinBollAct
|
|||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
// });
|
// });
|
||||||
MainService.startMainService(MainActivity.this);
|
|
||||||
|
MainServiceBean mMainServiceBean = MainServiceBean.loadBean(this, MainServiceBean.class);
|
||||||
|
if (mMainServiceBean == null) {
|
||||||
|
mMainServiceBean = new MainServiceBean();
|
||||||
|
MainServiceBean.saveBean(this, mMainServiceBean);
|
||||||
|
}
|
||||||
|
if (mMainServiceBean.isEnable()) {
|
||||||
|
MainService.startMainService(this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//初始化view,即显示的图片
|
//初始化view,即显示的图片
|
||||||
|
@ -28,6 +28,8 @@ import com.hjq.toast.ToastUtils;
|
|||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import android.widget.SeekBar;
|
import android.widget.SeekBar;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
import cc.winboll.studio.contacts.beans.MainServiceBean;
|
||||||
|
import cc.winboll.studio.contacts.services.MainService;
|
||||||
|
|
||||||
public class SettingsActivity extends AppCompatActivity implements IWinBollActivity {
|
public class SettingsActivity extends AppCompatActivity implements IWinBollActivity {
|
||||||
|
|
||||||
@ -39,6 +41,7 @@ public class SettingsActivity extends AppCompatActivity implements IWinBollActiv
|
|||||||
TextView mtvVolume;
|
TextView mtvVolume;
|
||||||
int mnStreamMaxVolume;
|
int mnStreamMaxVolume;
|
||||||
int mnStreamVolume;
|
int mnStreamVolume;
|
||||||
|
Switch mswMainService;
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -85,6 +88,23 @@ public class SettingsActivity extends AppCompatActivity implements IWinBollActiv
|
|||||||
}
|
}
|
||||||
getSupportActionBar().setSubtitle(getTag());
|
getSupportActionBar().setSubtitle(getTag());
|
||||||
|
|
||||||
|
mswMainService = findViewById(R.id.sw_mainservice);
|
||||||
|
MainServiceBean mMainServiceBean = MainServiceBean.loadBean(this, MainServiceBean.class);
|
||||||
|
mswMainService.setChecked(mMainServiceBean.isEnable());
|
||||||
|
mswMainService.setOnClickListener(new View.OnClickListener(){
|
||||||
|
@Override
|
||||||
|
public void onClick(View arg0) {
|
||||||
|
// TODO: Implement this method
|
||||||
|
if (mswMainService.isChecked()) {
|
||||||
|
//ToastUtils.show("Is Checked");
|
||||||
|
MainService.startMainService(SettingsActivity.this);
|
||||||
|
} else {
|
||||||
|
//ToastUtils.show("Not Checked");
|
||||||
|
MainService.stopMainService(SettingsActivity.this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
msbVolume = findViewById(R.id.bellvolume);
|
msbVolume = findViewById(R.id.bellvolume);
|
||||||
mtvVolume = findViewById(R.id.tv_volume);
|
mtvVolume = findViewById(R.id.tv_volume);
|
||||||
final AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
|
final AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
|
||||||
@ -95,7 +115,7 @@ public class SettingsActivity extends AppCompatActivity implements IWinBollActiv
|
|||||||
// 获取当前铃声音量并设置为SeekBar的初始进度
|
// 获取当前铃声音量并设置为SeekBar的初始进度
|
||||||
mnStreamVolume = audioManager.getStreamVolume(AudioManager.STREAM_RING);
|
mnStreamVolume = audioManager.getStreamVolume(AudioManager.STREAM_RING);
|
||||||
msbVolume.setProgress(mnStreamVolume);
|
msbVolume.setProgress(mnStreamVolume);
|
||||||
|
|
||||||
updateStreamVolumeTextView();
|
updateStreamVolumeTextView();
|
||||||
|
|
||||||
msbVolume.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
|
msbVolume.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
|
||||||
@ -127,7 +147,7 @@ public class SettingsActivity extends AppCompatActivity implements IWinBollActiv
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void updateStreamVolumeTextView() {
|
void updateStreamVolumeTextView() {
|
||||||
mtvVolume.setText(String.format("%d/%d", mnStreamVolume, mnStreamMaxVolume));
|
mtvVolume.setText(String.format("%d/%d", mnStreamVolume, mnStreamMaxVolume));
|
||||||
}
|
}
|
||||||
|
@ -30,6 +30,9 @@ import cc.winboll.studio.libappbase.bean.APPSOSBean;
|
|||||||
import cc.winboll.studio.contacts.dun.Rules;
|
import cc.winboll.studio.contacts.dun.Rules;
|
||||||
import android.media.AudioManager;
|
import android.media.AudioManager;
|
||||||
import com.hjq.toast.ToastUtils;
|
import com.hjq.toast.ToastUtils;
|
||||||
|
import java.util.Timer;
|
||||||
|
import java.util.TimerTask;
|
||||||
|
import cc.winboll.studio.contacts.beans.RingTongBean;
|
||||||
|
|
||||||
public class MainService extends Service {
|
public class MainService extends Service {
|
||||||
|
|
||||||
@ -48,8 +51,8 @@ public class MainService extends Service {
|
|||||||
AssistantService mAssistantService;
|
AssistantService mAssistantService;
|
||||||
boolean isBound = false;
|
boolean isBound = false;
|
||||||
MainReceiver mMainReceiver;
|
MainReceiver mMainReceiver;
|
||||||
|
Timer mStreamVolumeCheckTimer;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IBinder onBind(Intent intent) {
|
public IBinder onBind(Intent intent) {
|
||||||
return new MyBinder();
|
return new MyBinder();
|
||||||
@ -71,9 +74,35 @@ public class MainService extends Service {
|
|||||||
mMyServiceConnection = new MyServiceConnection();
|
mMyServiceConnection = new MyServiceConnection();
|
||||||
}
|
}
|
||||||
mMainServiceHandler = new MainServiceHandler(this);
|
mMainServiceHandler = new MainServiceHandler(this);
|
||||||
|
|
||||||
|
// 铃声检查定时器
|
||||||
|
mStreamVolumeCheckTimer = new Timer();
|
||||||
|
mStreamVolumeCheckTimer.schedule(new TimerTask() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
AudioManager audioManager = (AudioManager) getSystemService(AUDIO_SERVICE);
|
||||||
|
|
||||||
|
// 恢复铃声音量,预防其他意外条件导致的音量变化问题
|
||||||
|
//
|
||||||
|
|
||||||
|
// 读取应用配置,未配置就初始化配置文件
|
||||||
|
RingTongBean bean = RingTongBean.loadBean(MainService.this, RingTongBean.class);
|
||||||
|
if (bean == null) {
|
||||||
|
// 初始化配置
|
||||||
|
bean = new RingTongBean();
|
||||||
|
RingTongBean.saveBean(MainService.this, bean);
|
||||||
|
}
|
||||||
|
// 如果当前音量和应用保存的不一致就恢复为应用设定值
|
||||||
|
// 恢复铃声音量
|
||||||
|
try {
|
||||||
|
audioManager.setStreamVolume(AudioManager.STREAM_RING, bean.getStreamVolume(), 0);
|
||||||
|
//audioManager.setMode(AudioManager.RINGER_MODE_NORMAL);
|
||||||
|
} catch (java.lang.SecurityException e) {
|
||||||
|
LogUtils.d(TAG, e, Thread.currentThread().getStackTrace());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, 1000, 60000);
|
||||||
|
|
||||||
// 运行服务内容
|
// 运行服务内容
|
||||||
mainService();
|
mainService();
|
||||||
}
|
}
|
||||||
@ -104,11 +133,11 @@ public class MainService extends Service {
|
|||||||
mMainReceiver = new MainReceiver(this);
|
mMainReceiver = new MainReceiver(this);
|
||||||
mMainReceiver.registerAction(this);
|
mMainReceiver.registerAction(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
Rules.getInstance(this);
|
Rules.getInstance(this);
|
||||||
//Rules.getInstance(this).add("18888888888", true);
|
//Rules.getInstance(this).add("18888888888", true);
|
||||||
//Rules.getInstance(this).add("16769764848", true);
|
//Rules.getInstance(this).add("16769764848", true);
|
||||||
|
|
||||||
startPhoneCallListener();
|
startPhoneCallListener();
|
||||||
|
|
||||||
MainServiceThread.getInstance(this, mMainServiceHandler).start();
|
MainServiceThread.getInstance(this, mMainServiceHandler).start();
|
||||||
@ -137,7 +166,7 @@ public class MainService extends Service {
|
|||||||
// LogUtils.d(TAG, "startService(intent)");
|
// LogUtils.d(TAG, "startService(intent)");
|
||||||
// bindService(new Intent(this, AssistantService.class), mMyServiceConnection, Context.BIND_IMPORTANT);
|
// bindService(new Intent(this, AssistantService.class), mMyServiceConnection, Context.BIND_IMPORTANT);
|
||||||
}
|
}
|
||||||
|
|
||||||
void startPhoneCallListener() {
|
void startPhoneCallListener() {
|
||||||
Intent callListener = new Intent(this, CallListenerService.class);
|
Intent callListener = new Intent(this, CallListenerService.class);
|
||||||
startService(callListener);
|
startService(callListener);
|
||||||
@ -168,7 +197,7 @@ public class MainService extends Service {
|
|||||||
|
|
||||||
// 停止主要进程
|
// 停止主要进程
|
||||||
MainServiceThread.getInstance(this, mMainServiceHandler).setIsExit(true);
|
MainServiceThread.getInstance(this, mMainServiceHandler).setIsExit(true);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
super.onDestroy();
|
super.onDestroy();
|
||||||
|
@ -18,6 +18,25 @@
|
|||||||
android:layout_height="0dp"
|
android:layout_height="0dp"
|
||||||
android:layout_weight="1.0">
|
android:layout_weight="1.0">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="服务设置:"/>
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:orientation="horizontal"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content">
|
||||||
|
|
||||||
|
<Switch
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="主要服务"
|
||||||
|
android:id="@+id/sw_mainservice"
|
||||||
|
android:layout_margin="10dp"/>
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user