本文整理汇总了Java中android.service.quicksettings.TileService.requestListeningState方法的典型用法代码示例。如果您正苦于以下问题:Java TileService.requestListeningState方法的具体用法?Java TileService.requestListeningState怎么用?Java TileService.requestListeningState使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.service.quicksettings.TileService
的用法示例。
在下文中一共展示了TileService.requestListeningState方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onDestroy
import android.service.quicksettings.TileService; //导入方法依赖的package包/类
@Override
public void onDestroy() {
SharedPreferences pref = U.getSharedPreferences(this);
if(pref.getBoolean("is_restarting", false))
pref.edit().remove("is_restarting").apply();
else {
LocalBroadcastManager.getInstance(this).sendBroadcast(new Intent("com.farmerbb.taskbar.UPDATE_SWITCH"));
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
TileService.requestListeningState(this, new ComponentName(BuildConfig.APPLICATION_ID, QuickSettingsTileService.class.getName()));
if(!U.launcherIsDefault(this) || U.isChromeOs(this))
LocalBroadcastManager.getInstance(this).sendBroadcast(new Intent("com.farmerbb.taskbar.FINISH_FREEFORM_ACTIVITY"));
}
super.onDestroy();
if(!isHidden) {
unregisterReceiver(userForegroundReceiver);
unregisterReceiver(userBackgroundReceiver);
}
}
示例2: setNightMode
import android.service.quicksettings.TileService; //导入方法依赖的package包/类
public static void setNightMode(Context context, int nightModeValue) {
SharedPreferences pref = getSharedPreferences(context);
pref.edit().remove("is_snoozed").apply();
try {
Settings.Secure.putInt(context.getContentResolver(), "tuner_night_mode_adjust_tint", 1);
Settings.Secure.putInt(context.getContentResolver(), "twilight_mode", nightModeValue);
Intent intent = new Intent(context, NotificationService.class);
if(nightModeValue == 1)
context.startService(intent);
else
context.stopService(intent);
LocalBroadcastManager.getInstance(context).sendBroadcast(new Intent("com.farmerbb.nightlight.UPDATE_SWITCH"));
TileService.requestListeningState(context, new ComponentName(BuildConfig.APPLICATION_ID, QuickSettingsTileService.class.getName()));
Intent query = new Intent(com.twofortyfouram.locale.api.Intent.ACTION_REQUEST_QUERY)
.putExtra(com.twofortyfouram.locale.api.Intent.EXTRA_STRING_ACTIVITY_CLASS_NAME, TaskerConditionActivity.class.getName());
context.sendBroadcast(query);
} catch (SecurityException e) { /* Gracefully fail */ }
}
示例3: onCheckedChanged
import android.service.quicksettings.TileService; //导入方法依赖的package包/类
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
if (b) {
editor = settings.edit();
editor.putBoolean("serviceEnabled", true);
editor.apply();
serviceEnabled = true;
textViewStatus.setText(R.string.service_active);
if (!Utils.isMyServiceRunning(ForceDozeService.class, MainActivity.this)) {
Log.i(TAG, "Enabling ForceDoze");
startService(new Intent(MainActivity.this, ForceDozeService.class));
}
showForceDozeActiveDialog();
} else {
editor = settings.edit();
editor.putBoolean("serviceEnabled", false);
editor.apply();
serviceEnabled = false;
textViewStatus.setText(R.string.service_inactive);
if (Utils.isMyServiceRunning(ForceDozeService.class, MainActivity.this)) {
Log.i(TAG, "Disabling ForceDoze");
stopService(new Intent(MainActivity.this, ForceDozeService.class));
}
}
if (Utils.isDeviceRunningOnN()) {
TileService.requestListeningState(this, new ComponentName(this, ForceDozeTileService.class.getName()));
}
}
示例4: onCreate
import android.service.quicksettings.TileService; //导入方法依赖的package包/类
@TargetApi(Build.VERSION_CODES.M)
@Override
public void onCreate() {
super.onCreate();
SharedPreferences pref = U.getSharedPreferences(this);
if(pref.getBoolean("taskbar_active", false)) {
if(Build.VERSION.SDK_INT < Build.VERSION_CODES.M || Settings.canDrawOverlays(this)) {
isHidden = U.getSharedPreferences(this).getBoolean("is_hidden", false);
Intent intent = new Intent(this, MainActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
Intent receiverIntent = new Intent("com.farmerbb.taskbar.SHOW_HIDE_TASKBAR");
receiverIntent.setPackage(BuildConfig.APPLICATION_ID);
Intent receiverIntent2 = new Intent("com.farmerbb.taskbar.QUIT");
receiverIntent2.setPackage(BuildConfig.APPLICATION_ID);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT);
PendingIntent receiverPendingIntent = PendingIntent.getBroadcast(this, 0, receiverIntent, PendingIntent.FLAG_UPDATE_CURRENT);
PendingIntent receiverPendingIntent2 = PendingIntent.getBroadcast(this, 0, receiverIntent2, PendingIntent.FLAG_UPDATE_CURRENT);
NotificationCompat.Builder mBuilder = CompatUtils.getNotificationBuilder(this)
.setSmallIcon(pref.getBoolean("app_drawer_icon", false) ? R.drawable.ic_system : R.drawable.ic_allapps)
.setContentIntent(contentIntent)
.setContentTitle(getString(R.string.taskbar_is_active))
.setContentText(getString(R.string.click_to_open_settings))
.setColor(ContextCompat.getColor(this, R.color.colorPrimary))
.setPriority(Notification.PRIORITY_MIN)
.setShowWhen(false)
.setOngoing(true);
String showHideLabel;
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.N && !U.isChromeOs(this)) {
String freeformLabel = getString(pref.getBoolean("freeform_hack", false) ? R.string.freeform_off : R.string.freeform_on);
Intent freeformIntent = new Intent("com.farmerbb.taskbar.TOGGLE_FREEFORM_MODE");
freeformIntent.setPackage(BuildConfig.APPLICATION_ID);
PendingIntent freeformPendingIntent = PendingIntent.getBroadcast(this, 0, freeformIntent, PendingIntent.FLAG_UPDATE_CURRENT);
mBuilder.addAction(0, freeformLabel, freeformPendingIntent);
showHideLabel = getString(isHidden ? R.string.action_show_alt : R.string.action_hide_alt);
} else
showHideLabel = getString(isHidden ? R.string.action_show : R.string.action_hide);
mBuilder.addAction(0, showHideLabel, receiverPendingIntent)
.addAction(0, getString(R.string.action_quit), receiverPendingIntent2);
startForeground(8675309, mBuilder.build());
LocalBroadcastManager.getInstance(this).sendBroadcast(new Intent("com.farmerbb.taskbar.UPDATE_SWITCH"));
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
TileService.requestListeningState(this, new ComponentName(BuildConfig.APPLICATION_ID, QuickSettingsTileService.class.getName()));
if(!isHidden) {
registerReceiver(userForegroundReceiver, new IntentFilter(Intent.ACTION_USER_FOREGROUND));
registerReceiver(userBackgroundReceiver, new IntentFilter(Intent.ACTION_USER_BACKGROUND));
}
} else {
pref.edit().putBoolean("taskbar_active", false).apply();
stopSelf();
}
} else stopSelf();
}
示例5: registerNextReceiver
import android.service.quicksettings.TileService; //导入方法依赖的package包/类
private static void registerNextReceiver(Context context, String key, String value, DateTime now) {
Intent broadcastIntent = new Intent(context, NightLightReceiver.class);
long nextStartTime = -1;
long nextEndTime = -1;
SharedPreferences pref = getSharedPreferences(context);
String autoMode;
if(key != null && key.equals("turn_on_automatically"))
autoMode = value;
else
autoMode = pref.getString("turn_on_automatically", "never");
if(!autoMode.equals("never") || pref.getBoolean("is_snoozed", false)) {
String[] startTime = null;
String[] endTime = null;
String divider = ":";
if(key != null) {
if(key.equals("start_time"))
startTime = value.split(divider);
if(key.equals("end_time"))
endTime = value.split(divider);
}
if(startTime == null) startTime = pref.getString("start_time", "20:00").split(divider);
if(endTime == null) endTime = pref.getString("end_time", "06:00").split(divider);
DateTime startTimeCalendar =
now.withHourOfDay(Integer.parseInt(startTime[0]))
.withMinuteOfHour(Integer.parseInt(startTime[1]))
.withSecondOfMinute(0)
.withMillisOfSecond(0);
nextStartTime = startTimeCalendar.isBefore(now)
? startTimeCalendar.plusDays(1).getMillis()
: startTimeCalendar.getMillis();
DateTime endTimeCalendar =
now.withHourOfDay(Integer.parseInt(endTime[0]))
.withMinuteOfHour(Integer.parseInt(endTime[1]))
.withSecondOfMinute(0)
.withMillisOfSecond(0);
if(autoMode.equals("never"))
nextEndTime = Long.MAX_VALUE;
else
nextEndTime = endTimeCalendar.isBefore(now)
? endTimeCalendar.plusDays(1).getMillis()
: endTimeCalendar.getMillis();
broadcastIntent.putExtra("action", nextStartTime < nextEndTime ? "start" : "end");
}
// Re-register NightLightReceiver
PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 123456, broadcastIntent, PendingIntent.FLAG_CANCEL_CURRENT);
AlarmManager manager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
SharedPreferences.Editor editor = pref.edit();
if(nextStartTime != -1 && nextEndTime != -1) {
manager.setExactAndAllowWhileIdle(AlarmManager.RTC_WAKEUP, nextStartTime < nextEndTime ? nextStartTime : nextEndTime, pendingIntent);
editor.putLong("next_start_time", nextStartTime);
editor.putLong("next_end_time", nextEndTime);
editor.putString("time_zone", TimeZone.getDefault().getID());
} else {
manager.cancel(pendingIntent);
editor.remove("next_start_time");
editor.remove("next_end_time");
editor.remove("time_zone");
}
editor.apply();
// Check if we need to restart the NotificationService
if(isNightModeOn(context) && !isServiceRunning(context)) {
context.startService(new Intent(context, NotificationService.class));
}
TileService.requestListeningState(context, new ComponentName(BuildConfig.APPLICATION_ID, QuickSettingsTileService.class.getName()));
}