Skip to content

Commit

Permalink
Add Tasker/Locale action plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
mueller-ma committed Jun 4, 2019
1 parent 02b9321 commit 5d2f4ad
Show file tree
Hide file tree
Showing 11 changed files with 920 additions and 4 deletions.
11 changes: 11 additions & 0 deletions mobile/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,13 @@
android:name="de.duenndns.ssl.MemorizingActivity"
android:excludeFromRecents="true"
android:theme="@style/Theme.AppCompat.Translucent" />
<activity android:name=".ui.ItemPickerActivity"
android:label="@string/item_picker" >
<intent-filter>
<action android:name="com.twofortyfouram.locale.intent.action.EDIT_CONDITION" />
<action android:name="com.twofortyfouram.locale.intent.action.EDIT_SETTING" />
</intent-filter>
</activity>

<service
android:name=".core.VoiceService"
Expand Down Expand Up @@ -119,6 +126,10 @@
<intent-filter>
<action android:name="android.intent.action.LOCALE_CHANGED" />
</intent-filter>
<intent-filter>
<action android:name="com.twofortyfouram.locale.intent.action.QUERY_CONDITION" />
<action android:name="com.twofortyfouram.locale.intent.action.FIRE_SETTING" />
</intent-filter>
</receiver>

<activity
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Build;
import android.os.Bundle;
import android.os.Parcel;
import android.os.Parcelable;
import android.preference.PreferenceManager;
Expand All @@ -25,6 +26,10 @@
import org.openhab.habdroid.ui.widget.ItemUpdatingPreference;
import org.openhab.habdroid.util.Constants;
import org.openhab.habdroid.util.Util;
import org.openhab.habdroid.ui.ItemPickerActivity;
import org.openhab.habdroid.ui.widget.ItemUpdatingPreference;
import org.openhab.habdroid.util.Constants;
import org.openhab.habdroid.util.TaskerIntent;

import java.util.Arrays;
import java.util.HashMap;
Expand All @@ -39,6 +44,7 @@ public class BackgroundTasksManager extends BroadcastReceiver {

private static final String WORKER_TAG_ITEM_UPLOADS = "itemUploads";
static final String WORKER_TAG_PREFIX_NFC = "nfc-";
private static final String WORKER_TAG_PREFIX_TASKER = "tasker-";

static final List<String> KNOWN_KEYS = Arrays.asList(
Constants.PREFERENCE_ALARM_CLOCK
Expand Down Expand Up @@ -66,19 +72,32 @@ public static void initialize(Context context) {

@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
Log.d(TAG, "onReceive() with intent " + intent.getAction());

if (AlarmManager.ACTION_NEXT_ALARM_CLOCK_CHANGED.equals(intent.getAction())) {
if (AlarmManager.ACTION_NEXT_ALARM_CLOCK_CHANGED.equals(action)) {
Log.d(TAG, "Alarm clock changed");
scheduleWorker(context, Constants.PREFERENCE_ALARM_CLOCK);
} else if (Intent.ACTION_LOCALE_CHANGED.equals(intent.getAction())) {
} else if (Intent.ACTION_LOCALE_CHANGED.equals(action)) {
Log.d(TAG, "Locale changed, recreate notification channels");
NotificationUpdateObserver.createNotificationChannels(context);
} else if (ACTION_RETRY_UPLOAD.equals(intent.getAction())) {
} else if (ACTION_RETRY_UPLOAD.equals(action)) {
List<RetryInfo> retryInfos = intent.getParcelableArrayListExtra(EXTRA_RETRY_INFOS);
for (RetryInfo info : retryInfos) {
enqueueItemUpload(info.mTag, info.mItemName, info.mValue);
}
} else if (TaskerIntent.ACTION_QUERY_CONDITION.equals(action)
|| TaskerIntent.ACTION_FIRE_SETTING.equals(action)) {
Bundle bundle = intent.getBundleExtra(TaskerIntent.EXTRA_BUNDLE);
if (bundle == null) {
return;
}
String itemName = bundle.getString(ItemPickerActivity.EXTRA_ITEM_NAME);
String state = bundle.getString(ItemPickerActivity.EXTRA_ITEM_STATE);
if (TextUtils.isEmpty(itemName) || TextUtils.isEmpty(state)) {
return;
}
enqueueItemUpload(WORKER_TAG_PREFIX_TASKER + itemName, itemName, state);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import android.security.KeyChainException;
import android.util.Log;
import androidx.annotation.VisibleForTesting;
import androidx.annotation.WorkerThread;
import androidx.core.util.Pair;

import de.duenndns.ssl.MemorizingTrustManager;
Expand Down Expand Up @@ -159,6 +160,7 @@ public static void shutdown() {
*
* It MUST NOT be called from the main thread.
*/
@WorkerThread
public static void waitForInitialization() {
sInstance.triggerConnectionUpdateIfNeededAndPending();
synchronized (sInstance.mInitializationLock) {
Expand Down
4 changes: 4 additions & 0 deletions mobile/src/main/java/org/openhab/habdroid/model/Item.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ public enum Type {

public abstract String name();
public abstract String label();
@Nullable
public abstract String icon();
public abstract Type type();
@Nullable
public abstract Type groupType();
Expand All @@ -67,6 +69,7 @@ public boolean isOfTypeOrGroupType(Type type) {
abstract static class Builder {
public abstract Builder name(String name);
public abstract Builder label(String label);
public abstract Builder icon(String icon);
public abstract Builder type(Type type);
public abstract Builder groupType(Type type);
public abstract Builder state(@Nullable ParsedState state);
Expand Down Expand Up @@ -197,6 +200,7 @@ private static Item.Builder parseFromJson(JSONObject jsonObject) throws JSONExce
.name(name)
.label(jsonObject.optString("label", name))
.link(jsonObject.optString("link", null))
.icon(jsonObject.optString("category", null))
.members(members)
.options(options)
.state(ParsedState.from(state, numberPattern))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

public abstract class AbstractBaseActivity extends AppCompatActivity {
private static final String TAG = AbstractBaseActivity.class.getSimpleName();
private boolean mForceNonFullscreen = false;

@Override
@CallSuper
Expand All @@ -41,6 +42,15 @@ protected void onResume() {
checkFullscreen();
}

/**
* Activities, that aren't called from an app component directly, e.g. through a third-party app
* can use this function to avoid being shown in full screen. Must be called before
* {@link #onCreate(Bundle)}
*/
protected void forceNonFullscreen() {
mForceNonFullscreen = true;
}

protected void checkFullscreen() {
checkFullscreen(isFullscreenEnabled());
}
Expand All @@ -50,7 +60,7 @@ protected void checkFullscreen(boolean isEnabled) {
final int flags = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
| View.SYSTEM_UI_FLAG_FULLSCREEN;
if (isEnabled) {
if (isEnabled && !mForceNonFullscreen) {
uiOptions |= flags;
} else {
uiOptions &= ~flags;
Expand Down

0 comments on commit 5d2f4ad

Please sign in to comment.