Java Code Examples for android.service.quicksettings.Tile#updateTile()

The following examples show how to use android.service.quicksettings.Tile#updateTile() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: QuickStartTileService.java    From Virtual-Hosts with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onClick() {
    Tile tile = getQsTile();
    if (tile==null)return;
    int state = tile.getState();
    if (state == Tile.STATE_ACTIVE) {
        tile.setState(Tile.STATE_INACTIVE);
        VhostsService.stopVService(this.getApplicationContext());
   } else if(state == Tile.STATE_INACTIVE){
        tile.setState(Tile.STATE_ACTIVE);
        VhostsService.startVService(this.getApplicationContext(),1);
    }else{
        tile.setState(Tile.STATE_UNAVAILABLE);
    }
    tile.updateTile();
}
 
Example 2
Source File: QuickSettingsToggle.java    From always-on-amoled with GNU General Public License v3.0 6 votes vote down vote up
private void setCurrentState(int state) {
    initPrefs();
    Tile tile = getQsTile();
    if (tile != null) {
        tile.setState(state);
        switch (state) {
            case Tile.STATE_ACTIVE:
                tile.setLabel(getString(R.string.quick_settings_title) + " " + getString(R.string.quick_settings_service_active));
                Log("Active");
                break;
            case Tile.STATE_INACTIVE:
                tile.setLabel(getString(R.string.quick_settings_title) + " " + getString(R.string.quick_settings_service_inactive));
                Log("Inactive");
                break;
            default:
                tile.setLabel(getString(R.string.quick_settings_title) + " " + (prefs.enabled ? getString(R.string.quick_settings_service_active) : getString(R.string.quick_settings_service_inactive)));
                Log("Active");
                break;
        }
        tile.updateTile();
    }
}
 
Example 3
Source File: ServerService.java    From FireFiles with Apache License 2.0 6 votes vote down vote up
private void updateTileState(int state) {
    Tile tile = getQsTile();
    if (tile != null) {
        tile.setState(state);
        Icon icon = tile.getIcon();
        switch (state) {
            case Tile.STATE_ACTIVE:
                icon.setTint(Color.WHITE);
                break;
            case Tile.STATE_INACTIVE:
            case Tile.STATE_UNAVAILABLE:
            default:
                icon.setTint(Color.GRAY);
                break;
        }
        tile.updateTile();
    }
}
 
Example 4
Source File: IgniterTileService.java    From igniter with GNU General Public License v3.0 6 votes vote down vote up
private void updateTile(final @ProxyService.ProxyState int state) {
    Tile tile = getQsTile();
    if (tile == null) {
        return;
    }
    LogHelper.i(TAG, "updateTile with state: " + state);
    switch (state) {
        case ProxyService.STATE_NONE:
            tile.setState(Tile.STATE_INACTIVE);
            break;
        case ProxyService.STOPPED:
            break;
        case ProxyService.STARTED:
            tile.setState(Tile.STATE_ACTIVE);
            break;
        case ProxyService.STARTING:
        case ProxyService.STOPPING:
            tile.setState(Tile.STATE_UNAVAILABLE);
            break;
        default:
            LogHelper.e(TAG, "Unknown state: " + state);
            break;
    }
    tile.updateTile();
}
 
Example 5
Source File: TileService.java    From GeometricWeather with GNU Lesser General Public License v3.0 6 votes vote down vote up
private static void refreshTile(Context context, Tile tile) {
    if (tile == null) {
        return;
    }
    Location location = DatabaseHelper.getInstance(context).readLocationList().get(0);
    Weather weather = DatabaseHelper.getInstance(context).readWeather(location);
    if (weather != null) {
        tile.setIcon(
                ResourceHelper.getMinimalIcon(
                        ResourcesProviderFactory.getNewInstance(),
                        weather.getCurrent().getWeatherCode(),
                        TimeManager.getInstance(context).isDayTime()
                )
        );
        tile.setLabel(
                weather.getCurrent().getTemperature().getTemperature(
                        context,
                        SettingsOptionManager.getInstance(context).getTemperatureUnit())
        );
        tile.setState(Tile.STATE_INACTIVE);
        tile.updateTile();
    }
}
 
Example 6
Source File: ServiceTileGraph.java    From NetGuard with GNU General Public License v3.0 5 votes vote down vote up
private void update() {
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
    boolean stats = prefs.getBoolean("show_stats", false);
    Tile tile = getQsTile();
    if (tile != null) {
        tile.setState(stats ? Tile.STATE_ACTIVE : Tile.STATE_INACTIVE);
        tile.setIcon(Icon.createWithResource(this, stats ? R.drawable.ic_equalizer_white_24dp : R.drawable.ic_equalizer_white_24dp_60));
        tile.updateTile();
    }
}
 
Example 7
Source File: SpectrumTile.java    From SmartPack-Kernel-Manager with GNU General Public License v3.0 5 votes vote down vote up
private void resetTileStatus() {
      int profile = Utils.strToInt(Spectrum.getProfile());
      Tile tile = this.getQsTile();
      Icon newIcon;
      String newLabel;
      int newState;

      // Update tile
      if (!(Spectrum.supported())) {
          newLabel = "No Spectrum support";
          newIcon = Icon.createWithResource(getApplicationContext(), R.drawable.ic_spectrum_logo);
          newState = Tile.STATE_INACTIVE;
      }else {
          if (profile == 3) {
newLabel = "Gaming";
newIcon = Icon.createWithResource(getApplicationContext(), R.drawable.ic_spectrum_game);
newState = Tile.STATE_ACTIVE;
          } else if (profile == 2) {
newLabel = "Battery";
newIcon = Icon.createWithResource(getApplicationContext(), R.drawable.ic_spectrum_battery);
newState = Tile.STATE_ACTIVE;
          } else if (profile == 1) {
newLabel = "Performance";
newIcon = Icon.createWithResource(getApplicationContext(), R.drawable.ic_spectrum_performance);
newState = Tile.STATE_ACTIVE;
          } else {
newLabel = "Balance";
newIcon = Icon.createWithResource(getApplicationContext(), R.drawable.ic_spectrum_balanced);
newState = Tile.STATE_ACTIVE;
          }
      }

      // Change the UI of the tile.
      tile.setLabel(newLabel);
      tile.setIcon(newIcon);
      tile.setState(newState);
      tile.updateTile();
  }
 
Example 8
Source File: QSTileService.java    From NetUpDown with Apache License 2.0 5 votes vote down vote up
private void updateTitle(String title) {
    if (title == null) {
        return;
    }
    Tile tile = getQsTile();
    if (tile != null) {
        tile.setLabel(title);
        tile.updateTile();
    }
}
 
Example 9
Source File: QuickToggleService.java    From Status with Apache License 2.0 5 votes vote down vote up
@Override
public void onTileAdded() {
    super.onTileAdded();
    Tile tile = getQsTile();
    if (tile != null) {
        tile.setIcon(Icon.createWithResource(this, StaticUtils.isStatusServiceRunning(this) ? R.drawable.ic_check_box_enabled : R.drawable.ic_check_box_disabled));
        tile.updateTile();
    }
}
 
Example 10
Source File: MaskTileService.java    From Blackbulb with GNU General Public License v3.0 5 votes vote down vote up
private void updateActiveTile(Tile tile) {
    Icon activeIcon = Icon
            .createWithResource(getApplicationContext(),
                    R.drawable.ic_qs_night_mode_on);

    tile.setIcon(activeIcon);
    tile.setState(Tile.STATE_ACTIVE);
    tile.updateTile();
}
 
Example 11
Source File: QuickRecordTile.java    From screenrecorder with GNU Affero General Public License v3.0 5 votes vote down vote up
private void changeTileState() {
    Tile tile = super.getQsTile();
    int activeState = isTileActive ?
            Tile.STATE_ACTIVE : Tile.STATE_INACTIVE;

    if (!isTileActive)
        tile.setLabel(getString(R.string.quick_settings_tile_start_title));
    else
        tile.setLabel(getString(R.string.quick_settings_tile_stop_title));

    tile.setState(activeState);
    tile.updateTile();

}
 
Example 12
Source File: NightModeTileService.java    From SystemUITuner2 with MIT License 5 votes vote down vote up
@Override
    public void onStartListening() {
        final Tile nightMode = getQsTile();
        boolean isActive;

        if (Build.VERSION.SDK_INT == 24) isActive = Settings.Secure.getInt(getContentResolver(), "twilight_mode", 0) == 1;
        else {
            isActive = Settings.Secure.getInt(getContentResolver(), NIGHT_DISPLAY_ACTIVATED, 0) == 1;
            nightMode.setLabel(getResources().getText(R.string.night_display));
        }

        nightMode.setState(isActive ? Tile.STATE_ACTIVE : Tile.STATE_INACTIVE);
        nightMode.updateTile();

//        service = this;

        mToggleIntent = new Intent("toggle_night");

        mToggleReceiver = new BroadcastReceiver() {
            @Override
            public void onReceive(Context context, Intent intent) {
                if (intent.getAction().equals("toggle_night")) {
                    boolean state = intent.getBooleanExtra("state", false);
                    nightMode.setState(state ? Tile.STATE_ACTIVE : Tile.STATE_INACTIVE);
                    nightMode.updateTile();
                }
            }
        };

        IntentFilter filter = new IntentFilter("toggle_night");
        registerReceiver(mToggleReceiver, filter);
    }
 
Example 13
Source File: FavoriteAppTileService.java    From Taskbar with Apache License 2.0 5 votes vote down vote up
private void updateState() {
    Tile tile = getQsTile();
    if(tile == null) return;

    SharedPreferences pref = U.getSharedPreferences(this);
    if(pref.getBoolean(prefix + "added", false)) {
        tile.setState(Tile.STATE_ACTIVE);
        tile.setLabel(pref.getString(prefix + "label", getString(R.string.tb_new_shortcut)));

        String componentName = pref.getString(prefix + "component_name", null);
        float threshold = pref.getFloat(prefix + "icon_threshold", -1);

        if(componentName != null && threshold >= 0) {
            UserManager userManager = (UserManager) getSystemService(USER_SERVICE);
            LauncherApps launcherApps = (LauncherApps) getSystemService(LAUNCHER_APPS_SERVICE);
            long userId = pref.getLong(prefix + "user_id", userManager.getSerialNumberForUser(Process.myUserHandle()));

            Intent intent = new Intent();
            intent.setComponent(ComponentName.unflattenFromString(componentName));
            LauncherActivityInfo info = launcherApps.resolveActivity(intent, userManager.getUserForSerialNumber(userId));

            IconCache cache = IconCache.getInstance(this);
            BitmapDrawable icon = U.convertToMonochrome(this, cache.getIcon(this, info), threshold);

            tile.setIcon(Icon.createWithBitmap(icon.getBitmap()));
        } else
            tile.setIcon(Icon.createWithResource(this, R.drawable.tb_favorite_app_tile));
    } else {
        tile.setState(Tile.STATE_INACTIVE);
        tile.setLabel(getString(R.string.tb_new_shortcut));
        tile.setIcon(Icon.createWithResource(this, R.drawable.tb_favorite_app_tile));
    }

    tile.updateTile();
}
 
Example 14
Source File: HyperionGrabberTileService.java    From hyperion-android-grabber with MIT License 5 votes vote down vote up
@Override
public void onClick() {
    Tile tile = getQsTile();
    tile.updateTile();
    int tileState = tile.getState();
    if (tileState == Tile.STATE_ACTIVE) {
        Intent intent = new Intent(this, HyperionScreenService.class);
        intent.setAction(HyperionScreenService.ACTION_EXIT);
        startService(intent);
    } else {
        Runnable runner = () -> {

            boolean setupStarted = startSetupIfNeeded();

            if (!setupStarted){
                final Intent i = new Intent(this, BootActivity.class);
                i.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION
                        |Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS
                        |Intent.FLAG_ACTIVITY_NO_HISTORY);
                startActivity(i);
            }

        };
        if (isLocked()) {
            unlockAndRun(runner);
        } else {
            runner.run();
        }
    }
}
 
Example 15
Source File: HyperionGrabberTileService.java    From hyperion-android-grabber with MIT License 5 votes vote down vote up
@Override
public void onReceive(Context context, Intent intent) {
    Tile tile = getQsTile();
    boolean running = intent.getBooleanExtra(HyperionScreenService.BROADCAST_TAG, false);
    String error = intent.getStringExtra(HyperionScreenService.BROADCAST_ERROR);
    tile.setState(running ? Tile.STATE_ACTIVE : Tile.STATE_INACTIVE);
    tile.updateTile();
    if (error != null) {
        Toast.makeText(getBaseContext(), error, Toast.LENGTH_LONG).show();
    }
}
 
Example 16
Source File: ServiceTileSynchronize.java    From FairEmail with GNU General Public License v3.0 5 votes vote down vote up
private void update() {
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
    boolean enabled = prefs.getBoolean("enabled", true);
    Log.i("Update tile synchronize=" + enabled);

    Tile tile = getQsTile();
    if (tile != null) {
        tile.setState(enabled ? Tile.STATE_ACTIVE : Tile.STATE_INACTIVE);
        tile.setIcon(Icon.createWithResource(this,
                enabled ? R.drawable.baseline_sync_24 : R.drawable.baseline_sync_disabled_24));
        tile.updateTile();
    }
}
 
Example 17
Source File: QuickToggleService.java    From Status with Apache License 2.0 5 votes vote down vote up
@Override
public void onStartListening() {
    super.onStartListening();
    Tile tile = getQsTile();
    if (tile != null) {
        tile.setIcon(Icon.createWithResource(this, StaticUtils.isStatusServiceRunning(this) ? R.drawable.ic_check_box_enabled : R.drawable.ic_check_box_disabled));
        tile.updateTile();
    }
}
 
Example 18
Source File: ToggleAnimatorDuration.java    From AnimatorDurationTile with Apache License 2.0 4 votes vote down vote up
private void updateTile() {
    final float scale = getAnimatorScale(getContentResolver());
    final Tile tile = getQsTile();
    tile.setIcon(Icon.createWithResource(getApplicationContext(), getIcon(scale)));
    tile.updateTile();
}
 
Example 19
Source File: MyTileService.java    From journaldev with MIT License 4 votes vote down vote up
@Override
public void onTileAdded() {
    super.onTileAdded();


    Tile tile = getQsTile();
    tile.setState(Tile.STATE_ACTIVE);


    mSharedPreferences = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
    int counter = mSharedPreferences.getInt("counter", 0);

    tile.setLabel("Count " + counter);

    tile.setIcon(Icon.createWithResource(this, android.R.drawable.ic_media_pause));
    tile.updateTile();

    Toast.makeText(getApplicationContext(), "tile added", Toast.LENGTH_SHORT).show();
}
 
Example 20
Source File: QuickSettingsService.java    From android-n-quick-settings with Apache License 2.0 4 votes vote down vote up
private void updateTile() {

        Tile tile = this.getQsTile();
        boolean isActive = getServiceStatus();

        Icon newIcon;
        String newLabel;
        int newState;

        // Change the tile to match the service status.
        if (isActive) {

            newLabel = String.format(Locale.US,
                    "%s %s",
                    getString(R.string.tile_label),
                    getString(R.string.service_active));

            newIcon = Icon.createWithResource(getApplicationContext(),
                    ic_android_black_24dp);

            newState = Tile.STATE_ACTIVE;

        } else {
            newLabel = String.format(Locale.US,
                    "%s %s",
                    getString(R.string.tile_label),
                    getString(R.string.service_inactive));

            newIcon =
                    Icon.createWithResource(getApplicationContext(),
                            android.R.drawable.ic_dialog_alert);

            newState = Tile.STATE_INACTIVE;
        }

        // Change the UI of the tile.
        tile.setLabel(newLabel);
        tile.setIcon(newIcon);
        tile.setState(newState);

        // Need to call updateTile for the tile to pick up changes.
        tile.updateTile();
    }