Example usage for android.service.quicksettings TileService requestListeningState

List of usage examples for android.service.quicksettings TileService requestListeningState

Introduction

In this page you can find the example usage for android.service.quicksettings TileService requestListeningState.

Prototype

public static final void requestListeningState(Context context, ComponentName component) 

Source Link

Document

Requests that a tile be put in the listening state so it can send an update.

Usage

From source file:net.hyx.app.volumenotification.NotificationFactory.java

void create() {
    cancel();/*from   ww  w.  j ava  2s.co m*/
    if (settings.getEnabled()) {
        NotificationCompat.Builder builder = new NotificationCompat.Builder(context).setOngoing(true)
                .setPriority(getPriority()).setVisibility(getVisibility())
                .setCustomContentView(getCustomContentView()).setSmallIcon(
                        (settings.getHideStatus()) ? android.R.color.transparent : R.drawable.ic_launcher);
        manager.notify(1, builder.build());
    }
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
        for (int pos = 1; pos <= BUTTONS_SELECTION_SIZE; pos++) {
            TileService.requestListeningState(context,
                    new ComponentName(_package, _package + ".ServiceTile" + pos));
        }
    }
}

From source file:net.hyx.app.volumenotification.factory.NotificationFactory.java

@TargetApi(Build.VERSION_CODES.N)
public void requestListeningTiles() {
    for (int pos = 0; pos < items.size(); pos++) {
        VolumeControl item = items.get(pos);
        TileService.requestListeningState(context,
                new ComponentName(context, _package + ".service.TileService" + item.id));
    }//from   w w  w .j a  v  a  2 s .c o  m
}

From source file:com.farmerbb.taskbar.service.NotificationService.java

@TargetApi(Build.VERSION_CODES.M)
@Override/*from  w w  w.  jav a 2  s  .  c  o m*/
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);
            String label = getString(isHidden ? R.string.action_show : R.string.action_hide);

            Intent intent = new Intent(this, MainActivity.class);
            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);

            PendingIntent contentIntent = PendingIntent.getActivity(this, 0, intent,
                    PendingIntent.FLAG_CANCEL_CURRENT);
            PendingIntent receiverIntent = PendingIntent.getBroadcast(this, 0,
                    new Intent("com.farmerbb.taskbar.SHOW_HIDE_TASKBAR"), PendingIntent.FLAG_UPDATE_CURRENT);
            PendingIntent receiverIntent2 = PendingIntent.getBroadcast(this, 0,
                    new Intent("com.farmerbb.taskbar.QUIT"), PendingIntent.FLAG_UPDATE_CURRENT);

            NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(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))
                    .addAction(0, label, receiverIntent)
                    .addAction(0, getString(R.string.action_quit), receiverIntent2)
                    .setPriority(Notification.PRIORITY_MIN).setShowWhen(false).setOngoing(true);

            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();
}

From source file:com.farmerbb.taskbar.service.NotificationService.java

@Override
public void onDestroy() {
    SharedPreferences pref = U.getSharedPreferences(this);
    if (pref.getBoolean("is_restarting", false))
        pref.edit().remove("is_restarting").apply();
    else {/*from   www  .  ja v a  2 s  . c o  m*/
        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))
            LocalBroadcastManager.getInstance(this)
                    .sendBroadcast(new Intent("com.farmerbb.taskbar.FINISH_FREEFORM_ACTIVITY"));
    }

    super.onDestroy();

    if (!isHidden) {
        unregisterReceiver(userForegroundReceiver);
        unregisterReceiver(userBackgroundReceiver);
    }
}