-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
lmi: parts: Introduce Refresh Rate QS tile
- Loading branch information
1 parent
4edd6cb
commit 27c69f5
Showing
4 changed files
with
134 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?xml version="1.0"?> | ||
<vector xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:width="24dp" | ||
android:height="24dp" | ||
android:viewportWidth="24" | ||
android:viewportHeight="24" | ||
android:tint="?android:attr/colorControlNormal"> | ||
<path | ||
android:fillColor="#ff000000" | ||
android:pathData="M17 1.01L7 1C5.9 1 5 1.9 5 3v18c0 1.1 0.9 2 2 2h10c1.1 0 2-0.9 2-2V3c0-1.1-0.9-1.99-2-1.99zM17 21H7V3h10v18z"/> | ||
<path | ||
android:fillColor="#ff000000" | ||
android:pathData="M12 8c1.1 0 2.1 0.4 2.8 1.2L16 8v4h-4l1.8-1.8c-0.5-0.4-1.1-0.7-1.8-0.7c-1.4 0-2.5 1.1-2.5 2.5s1.1 2.5 2.5 2.5c0.8 0 1.5-0.4 2-1h1.7C15.1 15 13.7 16 12 16c-2.2 0-4-1.8-4-4s1.8-4 4-4z"/> | ||
</vector> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
106 changes: 106 additions & 0 deletions
106
parts/src/org/lineageos/settings/RefreshRateTileService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
/* | ||
* Copyright (C) 2021 crDroid Android Project | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.lineageos.settings; | ||
|
||
import android.content.Context; | ||
import android.provider.Settings; | ||
import android.service.quicksettings.Tile; | ||
import android.service.quicksettings.TileService; | ||
import android.view.Display; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Locale; | ||
|
||
public class RefreshRateTileService extends TileService { | ||
private static final String KEY_MIN_REFRESH_RATE = "min_refresh_rate"; | ||
private static final String KEY_PEAK_REFRESH_RATE = "peak_refresh_rate"; | ||
|
||
private Context context; | ||
private Tile tile; | ||
|
||
private final List<Integer> availableRates = new ArrayList<>(); | ||
private int activeRateMin; | ||
private int activeRateMax; | ||
|
||
@Override | ||
public void onCreate() { | ||
super.onCreate(); | ||
context = getApplicationContext(); | ||
Display.Mode mode = context.getDisplay().getMode(); | ||
Display.Mode[] modes = context.getDisplay().getSupportedModes(); | ||
for (Display.Mode m : modes) { | ||
int rate = (int) Math.round(m.getRefreshRate()); | ||
if (m.getPhysicalWidth() == mode.getPhysicalWidth() && | ||
m.getPhysicalHeight() == mode.getPhysicalHeight()) { | ||
availableRates.add(rate); | ||
} | ||
} | ||
syncFromSettings(); | ||
} | ||
|
||
private int getSettingOf(String key) { | ||
float rate = Settings.System.getFloat(context.getContentResolver(), key, 60); | ||
int active = availableRates.indexOf((int) Math.round(rate)); | ||
return Math.max(active, 0); | ||
} | ||
|
||
private void syncFromSettings() { | ||
activeRateMin = getSettingOf(KEY_MIN_REFRESH_RATE); | ||
activeRateMax = getSettingOf(KEY_PEAK_REFRESH_RATE); | ||
} | ||
|
||
private void cycleRefreshRate() { | ||
if (activeRateMin < availableRates.size() - 1) { | ||
activeRateMin++; | ||
} else { | ||
activeRateMin = 0; | ||
} | ||
|
||
float rate = availableRates.get(activeRateMin); | ||
Settings.System.putFloat(context.getContentResolver(), KEY_MIN_REFRESH_RATE, rate); | ||
Settings.System.putFloat(context.getContentResolver(), KEY_PEAK_REFRESH_RATE, rate); | ||
} | ||
|
||
private void updateTileView() { | ||
String displayText; | ||
int min = availableRates.get(activeRateMin); | ||
int max = availableRates.get(activeRateMax); | ||
|
||
displayText = String.format(Locale.US, min == max ? "%d Hz" : "%d - %d Hz", min, max); | ||
tile.setContentDescription(displayText); | ||
tile.setSubtitle(displayText); | ||
tile.setState(min == max ? Tile.STATE_ACTIVE : Tile.STATE_INACTIVE); | ||
tile.updateTile(); | ||
} | ||
|
||
@Override | ||
public void onStartListening() { | ||
super.onStartListening(); | ||
tile = getQsTile(); | ||
syncFromSettings(); | ||
updateTileView(); | ||
} | ||
|
||
@Override | ||
public void onClick() { | ||
super.onClick(); | ||
cycleRefreshRate(); | ||
syncFromSettings(); | ||
updateTileView(); | ||
} | ||
} |