Skip to content

Commit 11e0030

Browse files
authored
Merge branch 'feature/android-auto-dev' into alpha-development
2 parents bfc62bb + ecd7c66 commit 11e0030

File tree

41 files changed

+548
-4
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+548
-4
lines changed

app/build.gradle

+1
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ dependencies {
195195
implementation 'com.google.android.material:material:1.6.1'
196196
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
197197
implementation 'androidx.annotation:annotation:1.3.0'
198+
implementation 'com.google.android.libraries.car:car-app:1.0.0-beta.1'
198199
implementation 'org.reactivestreams:reactive-streams:1.0.3'
199200
implementation 'io.reactivex.rxjava2:rxjava:2.2.10'
200201
implementation 'com.revenuecat.purchases:purchases:5.0.0-rc3'

app/src/main/AndroidManifest.xml

+12-1
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,8 @@
425425
<meta-data
426426
android:name="com.google.android.gms.vision.DEPENDENCIES"
427427
android:value="barcode" />
428-
428+
<meta-data android:name="com.google.android.gms.car.application"
429+
android:resource="@xml/automotive_app_desc"/>
429430
<meta-data
430431
android:name="com.google.android.gms.ads.APPLICATION_ID"
431432
android:value="@string/ADMOB_APP_KEY" />
@@ -590,5 +591,15 @@
590591
android:name="org.apache.http.legacy"
591592
android:required="false" />
592593

594+
<service
595+
android:name="nl.hnogames.domoticz.service.AutoService"
596+
android:exported="true"
597+
android:label="@string/app_name_domoticz"
598+
android:icon="@mipmap/ic_launcher">
599+
<intent-filter>
600+
<action android:name="com.google.android.car.action.CAR_APP"/>
601+
<category android:name="com.google.android.car.category.CHARGING"/>
602+
</intent-filter>
603+
</service>
593604
</application>
594605
</manifest>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
/*
2+
* Copyright (C) 2015 Domoticz - Mark Heinis
3+
*
4+
* Licensed to the Apache Software Foundation (ASF) under one
5+
* or more contributor license agreements. See the NOTICE file
6+
* distributed with this work for additional information
7+
* regarding copyright ownership. The ASF licenses this file
8+
* to you under the Apache License, Version 2.0 (the
9+
* "License"); you may not use this file except in compliance
10+
* with the License. You may obtain a copy of the License at
11+
*
12+
* http://www.apache.org/licenses/LICENSE-2.0
13+
*
14+
* Unless required by applicable law or agreed to in writing,
15+
* software distributed under the License is distributed on an
16+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17+
* KIND, either express or implied. See the License for the
18+
* specific language governing permissions and limitations
19+
* under the License.
20+
*/
21+
22+
package nl.hnogames.domoticz.preference;
23+
24+
import android.content.Context;
25+
import android.content.res.TypedArray;
26+
import android.util.AttributeSet;
27+
import android.util.Log;
28+
29+
import java.util.ArrayList;
30+
import java.util.HashSet;
31+
import java.util.List;
32+
import java.util.Set;
33+
34+
import androidx.preference.MultiSelectListPreference;
35+
import nl.hnogames.domoticz.R;
36+
import nl.hnogames.domoticz.helpers.StaticHelper;
37+
import nl.hnogames.domoticzapi.Containers.DevicesInfo;
38+
import nl.hnogames.domoticzapi.Domoticz;
39+
import nl.hnogames.domoticzapi.Interfaces.DevicesReceiver;
40+
41+
public class AutoMultiSelectListPreference extends MultiSelectListPreference {
42+
private static final String TAG = AutoMultiSelectListPreference.class.getName();
43+
private final boolean selectAllValuesByDefault;
44+
private CharSequence[] mEntryValues;
45+
46+
public AutoMultiSelectListPreference(Context context, AttributeSet attrs) {
47+
super(context, attrs);
48+
TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.CustomListPreference);
49+
selectAllValuesByDefault = typedArray.getBoolean(R.styleable.CustomListPreference_selectAllValuesByDefault, false);
50+
typedArray.recycle();
51+
initSwitches();
52+
}
53+
54+
private void initSwitches() {
55+
StaticHelper.getDomoticz(getContext()).getDevices(new DevicesReceiver() {
56+
@Override
57+
public void onReceiveDevices(ArrayList<DevicesInfo> mDevicesInfo) {
58+
ArrayList<DevicesInfo> supportedSwitches = new ArrayList<>();
59+
for (DevicesInfo mExtendedStatusInfo : mDevicesInfo) {
60+
String name = mExtendedStatusInfo.getName();
61+
if (!name.startsWith(Domoticz.HIDDEN_CHARACTER)) {
62+
supportedSwitches.add(mExtendedStatusInfo);
63+
}
64+
}
65+
if (supportedSwitches.size() > 0)
66+
processSwitches(supportedSwitches);
67+
}
68+
69+
@Override
70+
public void onReceiveDevice(DevicesInfo mDevicesInfo) {
71+
}
72+
73+
@Override
74+
public void onError(Exception error) {
75+
if (error != null && error.getMessage() != null && error.getMessage().length() > 0)
76+
Log.e(TAG, error.getMessage());
77+
}
78+
}, 0, "all");
79+
}
80+
81+
private void processSwitches(ArrayList<DevicesInfo> switches) {
82+
CharSequence[] mEntries = getEntries();
83+
mEntryValues = getEntryValues();
84+
85+
if (switches != null) {
86+
List<String> entries = new ArrayList<>();
87+
List<String> entryValues = new ArrayList<>();
88+
89+
for (DevicesInfo s : switches) {
90+
entryValues.add(s.getIdx() + "");
91+
entries.add(s.getIdx() + " - " + s.getName());
92+
}
93+
94+
if (entries != null && entryValues != null && !entries.isEmpty() && !entryValues.isEmpty()) {
95+
CharSequence[] dynamicEntries = entries.toArray(new CharSequence[entries.size()]);
96+
CharSequence[] dynamicEntryValues = entryValues.toArray(new CharSequence[entryValues.size()]);
97+
98+
//if either of the android attributes for specifying the entries and their values have been left empty, then ignore both and use only the dynamic providers
99+
if (mEntries == null || mEntryValues == null) {
100+
mEntries = dynamicEntries;
101+
mEntryValues = dynamicEntryValues;
102+
} else {
103+
CharSequence[] fullEntriesList = new CharSequence[mEntries.length + dynamicEntries.length];
104+
CharSequence[] fullEntryValuesList = new CharSequence[mEntryValues.length + dynamicEntryValues.length];
105+
106+
int i, j;
107+
for (i = 0; i <= mEntries.length - 1; i++) {
108+
fullEntriesList[i] = mEntries[i];
109+
fullEntryValuesList[i] = mEntryValues[i];
110+
}
111+
112+
try {
113+
for (i = mEntries.length, j = 0; j <= dynamicEntries.length - 1; i++, j++) {
114+
fullEntriesList[i] = dynamicEntries[j];
115+
fullEntryValuesList[i] = dynamicEntryValues[j];
116+
}
117+
} catch (ArrayIndexOutOfBoundsException ex) {
118+
}
119+
120+
//replace the entries and entryValues arrays with the new lists
121+
mEntries = fullEntriesList;
122+
mEntryValues = fullEntryValuesList;
123+
124+
setEntries(mEntries);
125+
setEntryValues(mEntryValues);
126+
}
127+
}
128+
}
129+
}
130+
131+
@Override
132+
protected void onSetInitialValue(boolean restoreValue, Object defaultValue) {
133+
if (!restoreValue && selectAllValuesByDefault && mEntryValues != null) {
134+
final Set<String> result = new HashSet<>();
135+
136+
for (CharSequence mEntryValue : mEntryValues) {
137+
result.add(mEntryValue.toString());
138+
}
139+
setValues(result);
140+
return;
141+
}
142+
super.onSetInitialValue(restoreValue, defaultValue);
143+
}
144+
}

app/src/main/java/nl/hnogames/domoticz/preference/PreferenceFragment.java

+12-1
Original file line numberDiff line numberDiff line change
@@ -250,9 +250,11 @@ private void setPreferences() {
250250

251251
// Geofence settings
252252
Preference GeoSettings = findPreference("geo_settings");
253-
253+
254254
// NFC settings
255255
SwitchPreference EnableNFCPreference = findPreference("enableNFC");
256+
SwitchPreference AutoPreference = findPreference("enableAutoItems");
257+
256258
Preference NFCPreference = findPreference("nfc_settings");
257259

258260
// Speech settings
@@ -808,6 +810,15 @@ public void onError(Exception error) {
808810
return true;
809811
});
810812

813+
if (AutoPreference != null)
814+
AutoPreference.setOnPreferenceChangeListener((preference, newValue) -> {
815+
if (BuildConfig.LITE_VERSION || !mSharedPrefs.isAPKValidated()) {
816+
showPremiumSnackbar(getString(R.string.category_auto));
817+
return false;
818+
}
819+
return true;
820+
});
821+
811822
if (AlwaysOnPreference != null)
812823
AlwaysOnPreference.setOnPreferenceChangeListener((preference, newValue) -> {
813824
if (!AppController.IsPremiumEnabled || !mSharedPrefs.isAPKValidated()) {

0 commit comments

Comments
 (0)