-
Notifications
You must be signed in to change notification settings - Fork 249
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve design of NotificationSignals.
- Loading branch information
Gabor Keszthelyi
committed
Sep 7, 2017
1 parent
011b091
commit 4b37347
Showing
14 changed files
with
352 additions
and
75 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
34 changes: 34 additions & 0 deletions
34
opentasks/src/main/java/org/dmfs/tasks/notification/signals/AllSignal.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,34 @@ | ||
/* | ||
* Copyright 2017 dmfs GmbH | ||
* | ||
* 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.dmfs.tasks.notification.signals; | ||
|
||
import android.app.Notification; | ||
|
||
|
||
/** | ||
* Represents {@link NotificationSignal} for {@link Notification#DEFAULT_ALL}. | ||
* | ||
* @author Gabor Keszthelyi | ||
*/ | ||
public final class AllSignal implements NotificationSignal | ||
{ | ||
@Override | ||
public int value() | ||
{ | ||
return Notification.DEFAULT_ALL; | ||
} | ||
} |
62 changes: 0 additions & 62 deletions
62
opentasks/src/main/java/org/dmfs/tasks/notification/signals/CustomizableSignal.java
This file was deleted.
Oops, something went wrong.
40 changes: 40 additions & 0 deletions
40
...tasks/src/main/java/org/dmfs/tasks/notification/signals/DelegatingNotificationSignal.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,40 @@ | ||
/* | ||
* Copyright 2017 dmfs GmbH | ||
* | ||
* 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.dmfs.tasks.notification.signals; | ||
|
||
/** | ||
* Abstract base class for {@link NotificationSignal}s that simply delegate to another instance, composed in the constructor. | ||
* | ||
* @author Gabor Keszthelyi | ||
*/ | ||
public abstract class DelegatingNotificationSignal implements NotificationSignal | ||
{ | ||
private final NotificationSignal mDelegate; | ||
|
||
|
||
public DelegatingNotificationSignal(NotificationSignal delegate) | ||
{ | ||
mDelegate = delegate; | ||
} | ||
|
||
|
||
@Override | ||
public final int value() | ||
{ | ||
return mDelegate.value(); | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
opentasks/src/main/java/org/dmfs/tasks/notification/signals/Lights.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,47 @@ | ||
/* | ||
* Copyright 2017 dmfs GmbH | ||
* | ||
* 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.dmfs.tasks.notification.signals; | ||
|
||
import android.app.Notification; | ||
|
||
|
||
/** | ||
* {@link NotificationSignal} for representing, adding, or toggling {@link Notification#DEFAULT_LIGHTS} | ||
* value. | ||
* | ||
* @author Gabor Keszthelyi | ||
*/ | ||
public final class Lights extends DelegatingNotificationSignal | ||
{ | ||
public Lights(boolean enable, NotificationSignal original) | ||
{ | ||
super(new Toggled(Notification.DEFAULT_LIGHTS, enable, original)); | ||
} | ||
|
||
|
||
public Lights(NotificationSignal original) | ||
{ | ||
super(new Toggled(Notification.DEFAULT_LIGHTS, true, original)); | ||
} | ||
|
||
|
||
public Lights() | ||
{ | ||
super(new Toggled(Notification.DEFAULT_LIGHTS, true, new NoSignal())); | ||
} | ||
|
||
} |
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
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
47 changes: 47 additions & 0 deletions
47
opentasks/src/main/java/org/dmfs/tasks/notification/signals/Sound.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,47 @@ | ||
/* | ||
* Copyright 2017 dmfs GmbH | ||
* | ||
* 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.dmfs.tasks.notification.signals; | ||
|
||
import android.app.Notification; | ||
|
||
|
||
/** | ||
* {@link NotificationSignal} for representing, adding, or toggling {@link Notification#DEFAULT_SOUND} | ||
* value. | ||
* | ||
* @author Gabor Keszthelyi | ||
*/ | ||
public final class Sound extends DelegatingNotificationSignal | ||
{ | ||
public Sound(boolean enable, NotificationSignal original) | ||
{ | ||
super(new Toggled(Notification.DEFAULT_SOUND, enable, original)); | ||
} | ||
|
||
|
||
public Sound(NotificationSignal original) | ||
{ | ||
super(new Toggled(Notification.DEFAULT_SOUND, true, original)); | ||
} | ||
|
||
|
||
public Sound() | ||
{ | ||
super(new Toggled(Notification.DEFAULT_SOUND, true, new NoSignal())); | ||
} | ||
|
||
} |
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
60 changes: 60 additions & 0 deletions
60
opentasks/src/main/java/org/dmfs/tasks/notification/signals/Toggled.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,60 @@ | ||
/* | ||
* Copyright 2017 dmfs GmbH | ||
* | ||
* 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.dmfs.tasks.notification.signals; | ||
|
||
import android.app.Notification; | ||
|
||
import org.dmfs.tasks.utils.BitFlagUtils; | ||
|
||
|
||
/** | ||
* Decorator for {@link NotificationSignal} that toggles a flag value. Flag must be one of | ||
* {@link Notification#DEFAULT_LIGHTS}, {@link Notification#DEFAULT_SOUND}, {@link Notification#DEFAULT_VIBRATE}. | ||
* <p> | ||
* Intended for internal use in the package only since it exposes the bit flag mechanism. | ||
* | ||
* @author Gabor Keszthelyi | ||
*/ | ||
final class Toggled implements NotificationSignal | ||
{ | ||
private final int mFlag; | ||
private final boolean mEnable; | ||
private final NotificationSignal mOriginal; | ||
|
||
|
||
/** | ||
* @param flag | ||
* must be one of {@link Notification#DEFAULT_LIGHTS}, {@link Notification#DEFAULT_SOUND}, {@link Notification#DEFAULT_VIBRATE} | ||
*/ | ||
Toggled(int flag, boolean enable, NotificationSignal original) | ||
{ | ||
if (flag != Notification.DEFAULT_VIBRATE && flag != Notification.DEFAULT_SOUND && flag != Notification.DEFAULT_LIGHTS) | ||
{ | ||
throw new IllegalArgumentException("Notification signal flag is not valid: " + flag); | ||
} | ||
mFlag = flag; | ||
mEnable = enable; | ||
mOriginal = original; | ||
} | ||
|
||
|
||
@Override | ||
public int value() | ||
{ | ||
return mEnable ? BitFlagUtils.addFlag(mOriginal.value(), mFlag) : mOriginal.value(); | ||
} | ||
} |
Oops, something went wrong.