version:1.2
fix: update:完善快捷控制,监听home键
This commit is contained in:
@@ -93,6 +93,8 @@ public class ControlActivity extends AppCompatActivity {
|
||||
ConstraintLayout cl_battery;
|
||||
@BindView(R.id.cl_flashlight)
|
||||
ConstraintLayout cl_flashlight;
|
||||
@BindView(R.id.cl_location)
|
||||
ConstraintLayout cl_location;
|
||||
|
||||
|
||||
private ContentResolver crv;
|
||||
@@ -518,8 +520,10 @@ public class ControlActivity extends AppCompatActivity {
|
||||
private void getFlashlight() {
|
||||
if (isFlashlightEnabled()) {
|
||||
tv_flashlight_switch.setText("开");
|
||||
cl_flashlight.setBackground(getDrawable(R.drawable.control_background_item));
|
||||
} else {
|
||||
tv_flashlight_switch.setText("关");
|
||||
cl_flashlight.setBackground(getDrawable(R.drawable.control_background_item_dis));
|
||||
}
|
||||
cl_flashlight.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
@@ -528,10 +532,12 @@ public class ControlActivity extends AppCompatActivity {
|
||||
Settings.Secure.putInt(crv, Settings.Secure.FLASHLIGHT_ENABLED, 0);
|
||||
sendBroadcast(new Intent(ACTION_FLASHLIGHT_CHANGED));
|
||||
tv_flashlight_switch.setText("关");
|
||||
cl_flashlight.setBackground(getDrawable(R.drawable.control_background_item_dis));
|
||||
} else {
|
||||
Settings.Secure.putInt(crv, Settings.Secure.FLASHLIGHT_ENABLED, 1);
|
||||
sendBroadcast(new Intent(ACTION_FLASHLIGHT_CHANGED));
|
||||
tv_flashlight_switch.setText("开");
|
||||
cl_flashlight.setBackground(getDrawable(R.drawable.control_background_item));
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -602,6 +608,8 @@ public class ControlActivity extends AppCompatActivity {
|
||||
});
|
||||
}
|
||||
|
||||
private LocationClient locationClient;
|
||||
|
||||
private void getLocation() {
|
||||
BDLocation bdLocation = AmapManager.getInstance().getNowMapLocation();
|
||||
if (bdLocation != null) {
|
||||
@@ -615,7 +623,19 @@ public class ControlActivity extends AppCompatActivity {
|
||||
} else {
|
||||
tv_location.setText("定位失败");
|
||||
}
|
||||
LocationClient locationClient = AmapManager.getInstance().getLocationClient();
|
||||
startLocation();
|
||||
cl_location.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
startLocation();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void startLocation() {
|
||||
if (locationClient == null) {
|
||||
locationClient = AmapManager.getInstance().getLocationClient();
|
||||
}
|
||||
locationClient.stop();
|
||||
locationClient.start();
|
||||
locationClient.registerLocationListener(new BDAbstractLocationListener() {
|
||||
|
||||
@@ -38,6 +38,7 @@ import com.uiuios.aios.fragment.SecondFragment;
|
||||
import com.uiuios.aios.service.NotificationService;
|
||||
import com.uiuios.aios.utils.ApkUtils;
|
||||
import com.uiuios.aios.utils.AppUsedTimeUtils;
|
||||
import com.uiuios.aios.utils.HomeWatcher;
|
||||
import com.uiuios.aios.utils.ToastUtil;
|
||||
import com.uiuios.aios.view.ScaleCircleNavigator;
|
||||
|
||||
@@ -52,7 +53,7 @@ import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
|
||||
public class MainActivity extends BaseActivity implements MainContact.MainView {
|
||||
private static String TAG = MainActivity.class.getSimpleName();
|
||||
private static final String TAG = MainActivity.class.getSimpleName();
|
||||
private MainPresenter mMainPresenter;
|
||||
|
||||
@BindView(R.id.viewPager)
|
||||
@@ -71,6 +72,8 @@ public class MainActivity extends BaseActivity implements MainContact.MainView {
|
||||
private int appListIndex = 1;
|
||||
private int defaultCurrent = 0;
|
||||
|
||||
private HomeWatcher mHomeWatcher;
|
||||
|
||||
@Override
|
||||
public int getLayoutId() {
|
||||
return R.layout.activity_main;
|
||||
@@ -141,6 +144,22 @@ public class MainActivity extends BaseActivity implements MainContact.MainView {
|
||||
if (mFragments.size() > 1) {
|
||||
mViewPager.setCurrentItem(defaultCurrent);
|
||||
}
|
||||
mHomeWatcher = new HomeWatcher(this);
|
||||
mHomeWatcher.setOnHomePressedListener(new HomeWatcher.OnHomePressedListener() {
|
||||
@Override
|
||||
public void onHomePressed() {
|
||||
//按了HOME键
|
||||
Log.e(TAG, "onHomePressed: ");
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onHomeLongPressed() {
|
||||
Log.e(TAG, "onHomeLongPressed: ");
|
||||
//长按HOME键
|
||||
}
|
||||
});
|
||||
mHomeWatcher.startWatch();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -346,6 +365,7 @@ public class MainActivity extends BaseActivity implements MainContact.MainView {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void onRestart() {
|
||||
super.onRestart();
|
||||
@@ -370,6 +390,9 @@ public class MainActivity extends BaseActivity implements MainContact.MainView {
|
||||
if (mNewAppReceiver != null) {
|
||||
unregisterReceiver(mNewAppReceiver);
|
||||
}
|
||||
if (mHomeWatcher != null) {
|
||||
mHomeWatcher.stopWatch();// 在销毁时停止监听,不然会报错的。
|
||||
}
|
||||
}
|
||||
|
||||
private void registmNewAppReceiver() {
|
||||
|
||||
Reference in New Issue
Block a user