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

The following examples show how to use android.service.quicksettings.Tile#setLabel() . 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: ShadowsocksTileService.java    From Maying with Apache License 2.0 6 votes vote down vote up
@Override
public void stateChanged(int state, String profileName, String msg) throws RemoteException {
    Tile tile = getQsTile();
    if (tile != null) {
        switch (state) {
            case Constants.State.STOPPED:
                tile.setIcon(iconIdle);
                tile.setLabel(getString(R.string.app_name));
                tile.setState(Tile.STATE_INACTIVE);
                break;
            case Constants.State.CONNECTED:
                tile.setIcon(iconConnected);
                String label = profileName == null ? getString(R.string.app_name) : profileName;
                tile.setLabel(label);
                tile.setState(Tile.STATE_ACTIVE);
                break;
            default:
                tile.setIcon(iconBusy);
                tile.setLabel(getString(R.string.app_name));
                tile.setState(Tile.STATE_UNAVAILABLE);
                break;
        }
        tile.updateTile();
    }
}
 
Example 2
Source File: ShadowsocksTileService.java    From ShadowsocksRR with Apache License 2.0 6 votes vote down vote up
@Override
public void stateChanged(int state, String profileName, String msg) throws RemoteException {
    Tile tile = getQsTile();
    if (tile != null) {
        switch (state) {
            case Constants.State.STOPPED:
                tile.setIcon(iconIdle);
                tile.setLabel(getString(R.string.app_name));
                tile.setState(Tile.STATE_INACTIVE);
                break;
            case Constants.State.CONNECTED:
                tile.setIcon(iconConnected);
                String label = profileName == null ? getString(R.string.app_name) : profileName;
                tile.setLabel(label);
                tile.setState(Tile.STATE_ACTIVE);
                break;
            default:
                tile.setIcon(iconBusy);
                tile.setLabel(getString(R.string.app_name));
                tile.setState(Tile.STATE_UNAVAILABLE);
                break;
        }
        tile.updateTile();
    }
}
 
Example 3
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 4
Source File: QuickSettingsTapService.java    From ui with Apache License 2.0 6 votes vote down vote up
@Override
public void onStartListening() {
    Log.d(TAG, "onStartListening");
    boolean working = getServiceStatus();
    Tile tile = getQsTile();

    if (working) {
        //turn on the tile here.
        tile.setIcon(Icon.createWithResource(this, R.drawable.cooltile_on));
        tile.setLabel("Cool tile");
        tile.setContentDescription("cool tile is On");
        tile.setState(Tile.STATE_ACTIVE);
    } else {
        //turn on the tile here.
        tile.setIcon(Icon.createWithResource(this, R.drawable.cooltile_off));
        tile.setLabel("Cool tile");
        tile.setContentDescription("cool tile is Off");
        tile.setState(Tile.STATE_INACTIVE);
    }
    tile.updateTile();

}
 
Example 5
Source File: MyTileService.java    From journaldev with MIT License 6 votes vote down vote up
@Override
public void onClick() {
    super.onClick();

    Tile tile = getQsTile();

    boolean isActive = (tile.getState() == Tile.STATE_ACTIVE);
    if (isActive) {
        tile.setState(Tile.STATE_INACTIVE);
        startActivityAndCollapse(new Intent(this, MainActivity.class));
        tile.setLabel("Disabled");
        tile.setContentDescription("Test App");
        tile.setIcon(Icon.createWithResource(this, android.R.drawable.ic_media_play));
    } else {
        mSharedPreferences = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
        int counter = mSharedPreferences.getInt("counter", 0);
        tile.setState(Tile.STATE_ACTIVE);
        tile.setIcon(Icon.createWithResource(this, android.R.drawable.ic_media_pause));
        tile.setLabel("Count " + counter);
    }
    tile.updateTile();
}
 
Example 6
Source File: QuickService.java    From LLApp with Apache License 2.0 6 votes vote down vote up
@Override
public void onClick() {
    super.onClick();
    Log.d(TAG, "onClick");

    Tile tile = getQsTile();
    if (tile != null) {
        if (tile.getState() == Tile.STATE_ACTIVE) {
            tile.setLabel("QuickStart");
            tile.setState(Tile.STATE_INACTIVE);
        } else {
            tile.setLabel("Running...");
            tile.setState(Tile.STATE_ACTIVE);
        }

        tile.updateTile();
    }
}
 
Example 7
Source File: MyTileService.java    From journaldev with MIT License 6 votes vote down vote up
@Override
public void onStartListening() {
    super.onStartListening();

    Tile tile = getQsTile();

    if (tile.getState() == Tile.STATE_ACTIVE) {
        mSharedPreferences = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
        int counter = mSharedPreferences.getInt("counter", 0);

        mSharedPreferences.edit().putInt("counter", ++counter).apply();
        tile.setLabel("Count " + counter);
    }

    tile.updateTile();

}
 
Example 8
Source File: ki4aQuickSettingsService.java    From ki4a with Apache License 2.0 6 votes vote down vote up
protected static void updateTile(TileService context) {
    if(context == null) return;

    Tile tile = context.getQsTile();

    if (ki4aService.current_status == Util.STATUS_SOCKS) {
        tile.setLabel(context.getString(R.string.text_status_connected));
        tile.setState(Tile.STATE_ACTIVE);
    }
    else if (ki4aService.current_status == Util.STATUS_CONNECTING) {
        tile.setLabel(context.getString(R.string.text_status_connecting));
        tile.setState(Tile.STATE_INACTIVE);
    }
    else if (ki4aService.current_status == Util.STATUS_DISCONNECT) {
        tile.setLabel(context.getString(R.string.text_status_disconnected));
        tile.setState(Tile.STATE_INACTIVE);
    }

    tile.updateTile();
}
 
Example 9
Source File: FakeOperatorTile.java    From LocationReportEnabler with GNU General Public License v3.0 6 votes vote down vote up
private void updateTile() {
    TelephonyManager manager = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
    String code = manager.getSimOperator();
    String country = manager.getSimCountryIso();

    SharedPreferences preferences = PropUtil.getProtecredSharedPreferences(this);

    Tile tile = getQsTile();
    tile.setLabel(String.format("%s %s", code, country));
    if (preferences.getBoolean(PropUtil.PREFERENCE_ENABLED, PropUtil.PREFERENCE_ENABLED_DEFAULT)) {
        tile.setState(Tile.STATE_ACTIVE);
    }
    else {
        tile.setState(Tile.STATE_INACTIVE);
    }
    tile.updateTile();
}
 
Example 10
Source File: WadbTileService.java    From WADB with Apache License 2.0 5 votes vote down vote up
private void showStateOn(String ip, int port) {
    Log.d(TAG, "showStateOn");

    final Tile tile = getQsTile();
    final String label = ip + ":" + port;
    if (tile.getState() == Tile.STATE_ACTIVE
            && label.equals(tile.getLabel().toString())) {
        return;
    }
    final Context context = this;
    tile.setState(Tile.STATE_ACTIVE);
    tile.setIcon(Icon.createWithResource(context, R.drawable.ic_qs_network_adb_on));
    tile.setLabel(label);
    tile.updateTile();
}
 
Example 11
Source File: ToggleKeepActivities.java    From KeepActivitiesTile with Apache License 2.0 5 votes vote down vote up
private void updateTile() {
    final boolean keepActivities = getKeepActivities(getContentResolver());
    final Tile tile = getQsTile();
    tile.setIcon(Icon.createWithResource(getApplicationContext(), getIcon(keepActivities)));
    tile.setLabel(getString(getLabel(keepActivities)));
    tile.updateTile();
}
 
Example 12
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 13
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 14
Source File: QSTileService.java    From NetUpDown with Apache License 2.0 5 votes vote down vote up
private void switchState(boolean isActive) {
    Tile tile = getQsTile();
    if (tile != null) {
        tile.setLabel(getString(R.string.tile_run));
        if (isActive) {
            tile.setState(Tile.STATE_ACTIVE);
        } else {
            tile.setState(Tile.STATE_INACTIVE);
        }

        tile.updateTile();
    }
}
 
Example 15
Source File: KLapseTile.java    From SmartPack-Kernel-Manager with GNU General Public License v3.0 5 votes vote down vote up
private void resetTileStatus() {
int status = KLapse.getklapseEnable();
       Tile tile = this.getQsTile();
       String newLabel;
       int newState;

       // Update tile
       if (!(KLapse.supported())) {
           newLabel = "No K-Lapse support";
           newState = Tile.STATE_INACTIVE;
       } else {
           if (status == 2) {
	newLabel = "K-Lapse\nBrightness";
	newState = Tile.STATE_ACTIVE;
           } else if (status == 1){
	newLabel = "K-Lapse\nTime";
	newState = Tile.STATE_ACTIVE;
           } else {
	newLabel = "K-Lapse\nTurned-Off";
	newState = Tile.STATE_ACTIVE;
           }
       }

       // Change the UI of the tile.
       tile.setLabel(newLabel);
       tile.setState(newState);
       tile.updateTile();
   }
 
Example 16
Source File: KLapseTile.java    From SmartPack-Kernel-Manager with GNU General Public License v3.0 5 votes vote down vote up
private void updateTile() {
      Tile tile = this.getQsTile();
      String newLabel;
      int newState;

      // Update tile and set profile
      if (!(KLapse.supported())) {
          newLabel = "No K-Lapse support";
          newState = Tile.STATE_INACTIVE;
      } else {
          if (id == 1) {
newLabel = "K-Lapse\nBrightness";
newState = Tile.STATE_ACTIVE;
id +=1;
KLapse.setklapseEnable(2, this);
KLapse.setklapseRed(nightR, this);
KLapse.setklapseGreen(nightG, this);
KLapse.setklapseBlue(nightB, this);
          } else if (id == 2) {
newLabel = "K-Lapse\nTurned-Off";
newState = Tile.STATE_ACTIVE;
id +=1;
KLapse.setklapseEnable(0, this);
          } else {
newLabel = "K-Lapse\nTime";
newState = Tile.STATE_ACTIVE;
id = 1;
KLapse.setklapseEnable(1, this);
KLapse.setklapseRed(nightR, this);
KLapse.setklapseGreen(nightG, this);
KLapse.setklapseBlue(nightB, this);
          }
      }

      // Change the UI of the tile.
      tile.setLabel(newLabel);
      tile.setState(newState);
      tile.updateTile();
  }
 
Example 17
Source File: BatteryTileService.java    From SystemUITuner2 with MIT License 5 votes vote down vote up
private void setBat(Intent intent) {
        int status = intent.getIntExtra(BatteryManager.EXTRA_STATUS, -1);

        mIsCharging = status == BatteryManager.BATTERY_STATUS_CHARGING ||
                status == BatteryManager.BATTERY_STATUS_FULL;

//        int scale = intent.getIntExtra(BatteryManager.EXTRA_SCALE, -1);

        mBatteryPercent = intent.getIntExtra(BatteryManager.EXTRA_LEVEL, -1);

        Tile battery = getQsTile();

        int resId;

        if (mBatteryPercent >= 95) {
             resId = mIsCharging ? R.drawable.ic_battery_charging_full : R.drawable.ic_battery;
        } else if (mBatteryPercent >= 85) {
            resId = mIsCharging ? R.drawable.ic_battery_charging_90 : R.drawable.ic_battery_90;
        } else if (mBatteryPercent >= 70) {
            resId = mIsCharging ? R.drawable.ic_battery_charging_80 : R.drawable.ic_battery_80;
        } else if (mBatteryPercent >= 55) {
            resId = mIsCharging ? R.drawable.ic_battery_charging_60 : R.drawable.ic_battery_60;
        } else if (mBatteryPercent >= 40) {
            resId = mIsCharging ? R.drawable.ic_battery_charging_50 : R.drawable.ic_battery_50;
        } else if (mBatteryPercent >= 25) {
            resId = mIsCharging ? R.drawable.ic_battery_charging_30 : R.drawable.ic_battery_30;
        } else if (mBatteryPercent >= 15) {
            resId = mIsCharging ? R.drawable.ic_battery_charging_20 : R.drawable.ic_battery_20;
        } else {
            resId = mIsCharging ? R.drawable.ic_battery_charging_20 : R.drawable.ic_battery_alert;
        }

        battery.setIcon(Icon.createWithResource(this, resId));
        battery.setLabel(String.valueOf(mBatteryPercent).concat("%"));
        battery.updateTile();
    }
 
Example 18
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 19
Source File: ProfileTile.java    From MTweaks-KernelAdiutorMOD with GNU General Public License v3.0 4 votes vote down vote up
private void resetTileStatus() {
    int profile = Spectrum.getProfile(getApplicationContext());
    Tile tile = this.getQsTile();
    Icon newIcon;
    String newLabel;
    int newState;

    // Update tile
    if (!Spectrum.supported(getApplicationContext())){
        newLabel = "No Spectrum support";
        newIcon = Icon.createWithResource(getApplicationContext(), R.drawable.ic_spectrum_tile_logo);
        newState = Tile.STATE_INACTIVE;
    }else {
        if (profile == 3) {
            newLabel = "Spectrum Gaming";
            newIcon = Icon.createWithResource(getApplicationContext(), R.drawable.ic_spectrum_tile_game);
            newState = Tile.STATE_ACTIVE;
            click = false;
        } else if (profile == 2) {
            newLabel = "Spectrum Battery";
            newIcon = Icon.createWithResource(getApplicationContext(), R.drawable.ic_spectrum_tile_battery);
            newState = Tile.STATE_ACTIVE;
            click = true;
        } else if (profile == 1) {
            newLabel = "Spectrum Performance";
            newIcon = Icon.createWithResource(getApplicationContext(), R.drawable.ic_spectrum_tile_performance);
            newState = Tile.STATE_ACTIVE;
            click = true;
        } else if (profile == 0) {
            newLabel = "Spectrum Balance";
            newIcon = Icon.createWithResource(getApplicationContext(), R.drawable.ic_spectrum_tile_balanced);
            newState = Tile.STATE_ACTIVE;
            click = false;
        } else {
            newLabel = "Spectrum Custom";
            newIcon = Icon.createWithResource(getApplicationContext(), R.drawable.ic_spectrum_tile_logo);
            newState = Tile.STATE_ACTIVE;
            click = false;
        }
    }

    // Change the UI of the tile.
    tile.setLabel(newLabel);
    tile.setIcon(newIcon);
    tile.setState(newState);
    tile.updateTile();
}
 
Example 20
Source File: ProfileTile.java    From MTweaks-KernelAdiutorMOD with GNU General Public License v3.0 4 votes vote down vote up
private void updateTile() {
    Tile tile = this.getQsTile();
    boolean isActive = getServiceStatus();
    Icon newIcon;
    String newLabel;
    int newState;

    // Update tile and set profile
    if (!Spectrum.supported(getApplicationContext())){
        newLabel = "No Spectrum support";
        newIcon = Icon.createWithResource(getApplicationContext(), R.drawable.ic_spectrum_tile_logo);
        newState = Tile.STATE_INACTIVE;
    }else {
        if (isActive && click) {
            newLabel = "Spectrum Gaming";
            newIcon = Icon.createWithResource(getApplicationContext(), R.drawable.ic_spectrum_tile_game);
            newState = Tile.STATE_ACTIVE;
            click = false;
            Spectrum.setProfile(3, getApplicationContext());
        } else if (!isActive && click) {
            newLabel = "Spectrum Battery";
            newIcon = Icon.createWithResource(getApplicationContext(), R.drawable.ic_spectrum_tile_battery);
            newState = Tile.STATE_ACTIVE;
            click = true;
            Spectrum.setProfile(2, getApplicationContext());
        } else if (isActive && !click) {
            newLabel = "Spectrum Performance";
            newIcon = Icon.createWithResource(getApplicationContext(), R.drawable.ic_spectrum_tile_performance);
            newState = Tile.STATE_ACTIVE;
            click = true;
            Spectrum.setProfile(1, getApplicationContext());
        } else {
            newLabel = "Spectrum Balance";
            newIcon = Icon.createWithResource(getApplicationContext(), R.drawable.ic_spectrum_tile_balanced);
            newState = Tile.STATE_ACTIVE;
            click = false;
            Spectrum.setProfile(0, getApplicationContext());
        }
    }

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