mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2025-01-12 18:57:36 +01:00
Fix calls to unsupported API functions
This commit is contained in:
parent
51b7f28a8b
commit
28a26710d9
@ -79,6 +79,7 @@ import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Hashtable;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
@ -145,29 +146,24 @@ public class GBDeviceAdapterv2 extends ListAdapter<GBDevice, GBDeviceAdapterv2.V
|
||||
}
|
||||
|
||||
private List<GBDevice> enrichDeviceListWithFolder(List<GBDevice> deviceList) {
|
||||
ArrayList<GBDevice> enrichedList = new ArrayList<>();
|
||||
Set<String> folders = new ArraySet<>();
|
||||
for(GBDevice device : deviceList){
|
||||
String parentFolder = device.getParentFolder();
|
||||
if(StringUtils.isNullOrEmpty(parentFolder)){
|
||||
final Map<String, List<GBDevice>> devicesPerFolder = new LinkedHashMap<>();
|
||||
final List<GBDevice> enrichedList = new ArrayList<>();
|
||||
|
||||
for (GBDevice device : deviceList) {
|
||||
String folder = device.getParentFolder();
|
||||
if (StringUtils.isNullOrEmpty(folder)){
|
||||
enrichedList.add(device);
|
||||
continue;
|
||||
}
|
||||
folders.add(parentFolder);
|
||||
if (!devicesPerFolder.containsKey(folder)) {
|
||||
devicesPerFolder.put(folder, new ArrayList<>());
|
||||
}
|
||||
devicesPerFolder.get(folder).add(device);
|
||||
}
|
||||
|
||||
for(String folder : folders){
|
||||
enrichedList.add(new GBDeviceFolder(folder));
|
||||
for(GBDevice potentialChild : deviceList){
|
||||
String parentFolder = potentialChild.getParentFolder();
|
||||
if(StringUtils.isNullOrEmpty(parentFolder)){
|
||||
continue;
|
||||
}
|
||||
if(!parentFolder.equals(folder)){
|
||||
continue;
|
||||
}
|
||||
enrichedList.add(potentialChild);
|
||||
}
|
||||
for (final Map.Entry<String, List<GBDevice>> folder : devicesPerFolder.entrySet()) {
|
||||
enrichedList.add(new GBDeviceFolder(folder.getKey()));
|
||||
enrichedList.addAll(folder.getValue());
|
||||
}
|
||||
|
||||
return enrichedList;
|
||||
|
@ -93,7 +93,7 @@ public class HybridHRWatchfaceWidgetActivity extends AbstractSettingsActivity {
|
||||
super.onCreate(savedInstanceState);
|
||||
addPreferencesFromResource(R.xml.fossil_hr_widget_settings);
|
||||
|
||||
widgetTypes = HybridHRWatchfaceWidget.getAvailableWidgetTypes(getContext());
|
||||
widgetTypes = HybridHRWatchfaceWidget.getAvailableWidgetTypes(getActivity().getBaseContext());
|
||||
ListPreference widgetType = (ListPreference) findPreference("pref_hybridhr_widget_type");
|
||||
widgetType.setOnPreferenceChangeListener(this);
|
||||
widgetType.setEntries(widgetTypes.values().toArray(new String[0]));
|
||||
|
@ -105,14 +105,14 @@ public class ImageConverter {
|
||||
public static Bitmap decodeFromRLEImage(byte[] rleImage) {
|
||||
ByteBuffer buf = ByteBuffer.wrap(rleImage);
|
||||
buf.order(ByteOrder.LITTLE_ENDIAN);
|
||||
int width = Byte.toUnsignedInt(buf.get());
|
||||
int height = Byte.toUnsignedInt(buf.get());
|
||||
int width = buf.get() & 0xff;
|
||||
int height = buf.get() & 0xff;
|
||||
Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
|
||||
int posX = 0;
|
||||
int posY = 0;
|
||||
while (buf.remaining() > 2) {
|
||||
int repetitions = Byte.toUnsignedInt(buf.get());
|
||||
int pixel = Byte.toUnsignedInt(buf.get());
|
||||
int repetitions = buf.get() & 0xff;
|
||||
int pixel = buf.get() & 0xff;
|
||||
int color = pixel << 6;
|
||||
int combinedColor = Color.rgb(color, color, color);
|
||||
for (int i=0; i<repetitions; i++) {
|
||||
@ -139,7 +139,7 @@ public class ImageConverter {
|
||||
int posX = 239;
|
||||
int posY = 239;
|
||||
while (buf.remaining() > 0) {
|
||||
int currentPixels = Byte.toUnsignedInt(buf.get());
|
||||
int currentPixels = buf.get() & 0xff;
|
||||
for (int shift=6; shift>=0; shift-=2) {
|
||||
int color = ((currentPixels >> shift) & 0b00000011) << 6;
|
||||
int combinedColor = Color.rgb(color, color, color);
|
||||
|
@ -0,0 +1,62 @@
|
||||
/* Copyright (C) 2022 José Rebelo
|
||||
|
||||
This file is part of Gadgetbridge.
|
||||
|
||||
Gadgetbridge is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as published
|
||||
by the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
Gadgetbridge is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
package nodomain.freeyourgadget.gadgetbridge.util;
|
||||
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* An API21-compatible alternative to java.util.Optional.
|
||||
*/
|
||||
public final class Optional<T> {
|
||||
private final T value;
|
||||
|
||||
private Optional() {
|
||||
this.value = null;
|
||||
}
|
||||
|
||||
private Optional(final T value) {
|
||||
this.value = Objects.requireNonNull(value);
|
||||
}
|
||||
|
||||
public T get() {
|
||||
if (value == null) {
|
||||
throw new NoSuchElementException("No value present");
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
public boolean isPresent() {
|
||||
return value != null;
|
||||
}
|
||||
|
||||
public T orElse(final T other) {
|
||||
return value != null ? value : other;
|
||||
}
|
||||
|
||||
public static <T> Optional<T> empty() {
|
||||
return new Optional<>();
|
||||
}
|
||||
|
||||
public static <T> Optional<T> of(final T value) {
|
||||
return new Optional<>(value);
|
||||
}
|
||||
|
||||
public static <T> Optional<T> ofNullable(final T value) {
|
||||
return value == null ? empty() : of(value);
|
||||
}
|
||||
}
|
@ -16,10 +16,9 @@
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
package nodomain.freeyourgadget.gadgetbridge.util.language.impl;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.text.Normalizer;
|
||||
import java.text.Normalizer.Form;
|
||||
|
||||
import nodomain.freeyourgadget.gadgetbridge.util.Optional;
|
||||
import nodomain.freeyourgadget.gadgetbridge.util.language.Transliterator;
|
||||
|
||||
// Implements Revised Romanization of Korean as well as we can without understanding any grammar.
|
||||
|
Loading…
x
Reference in New Issue
Block a user