Skip to content
Snippets Groups Projects
Commit d374a7cd authored by maniac103's avatar maniac103 Committed by mueller-ma
Browse files

General code cleanup (#1029)


* Use lambdas where appropriate.

Signed-off-by: default avatarDanny Baumann <dannybaumann@web.de>

* Use diamond operator where appropriate.

Signed-off-by: default avatarDanny Baumann <dannybaumann@web.de>

* Use foreach.

Signed-off-by: default avatarDanny Baumann <dannybaumann@web.de>

* Remove unused imports.

Signed-off-by: default avatarDanny Baumann <dannybaumann@web.de>

* Remove a few redundant casts.

Signed-off-by: default avatarDanny Baumann <dannybaumann@web.de>

* Code cleanup

- Name variables consistently
- Cleanup some whitespace
- Remove unneeded throws statements
- Remove some unused stuff

Signed-off-by: default avatarDanny Baumann <dannybaumann@web.de>

* Drop redundant 'OpenHAB' prefix from class names.

Signed-off-by: default avatarDanny Baumann <dannybaumann@web.de>

* Update checkstyle config to better match our style.

Signed-off-by: default avatarDanny Baumann <dannybaumann@web.de>

* Fix coding style issues.

Signed-off-by: default avatarDanny Baumann <dannybaumann@web.de>

* Don't generate IDs in android package.

Signed-off-by: default avatarDanny Baumann <dannybaumann@web.de>

* Improve some comments.

Signed-off-by: default avatarDanny Baumann <dannybaumann@web.de>

* Fix checkstyle issues in tests.

Signed-off-by: default avatarDanny Baumann <dannybaumann@web.de>
parent 59d119d3
No related branches found
No related tags found
No related merge requests found
Showing
with 214 additions and 200 deletions
...@@ -12,7 +12,7 @@ package org.openhab.habdroid; ...@@ -12,7 +12,7 @@ package org.openhab.habdroid;
import android.app.Application; import android.app.Application;
import android.test.ApplicationTestCase; import android.test.ApplicationTestCase;
/** /*
* <a href="http://d.android.com/tools/testing/testing_android.html">Testing Fundamentals</a> * <a href="http://d.android.com/tools/testing/testing_android.html">Testing Fundamentals</a>
*/ */
public class ApplicationTest extends ApplicationTestCase<Application> { public class ApplicationTest extends ApplicationTestCase<Application> {
......
...@@ -5,9 +5,8 @@ import android.support.test.espresso.IdlingResource; ...@@ -5,9 +5,8 @@ import android.support.test.espresso.IdlingResource;
import android.support.v4.app.Fragment; import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentManager;
import org.openhab.habdroid.ui.OpenHABWidgetListFragment; import org.openhab.habdroid.ui.WidgetListFragment;
import org.openhab.habdroid.ui.activity.ContentController; import org.openhab.habdroid.ui.activity.ContentController;
import org.openhab.habdroid.ui.activity.PageConnectionHolderFragment;
public class FragmentStatusIdlingResource implements IdlingResource { public class FragmentStatusIdlingResource implements IdlingResource {
private final String mName; private final String mName;
...@@ -43,8 +42,8 @@ public class FragmentStatusIdlingResource implements IdlingResource { ...@@ -43,8 +42,8 @@ public class FragmentStatusIdlingResource implements IdlingResource {
if (f instanceof ContentController.ProgressFragment) { if (f instanceof ContentController.ProgressFragment) {
return true; return true;
} }
if (f instanceof OpenHABWidgetListFragment) { if (f instanceof WidgetListFragment) {
if (((OpenHABWidgetListFragment) f).mRecyclerView.hasPendingAdapterUpdates()) { if (((WidgetListFragment) f).mRecyclerView.hasPendingAdapterUpdates()) {
return true; return true;
} }
} }
......
...@@ -3,23 +3,17 @@ package org.openhab.habdroid; ...@@ -3,23 +3,17 @@ package org.openhab.habdroid;
import android.support.test.espresso.IdlingRegistry; import android.support.test.espresso.IdlingRegistry;
import android.support.test.espresso.IdlingResource; import android.support.test.espresso.IdlingResource;
import android.support.test.espresso.intent.rule.IntentsTestRule; import android.support.test.espresso.intent.rule.IntentsTestRule;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.view.View; import android.view.View;
import org.junit.After; import org.junit.After;
import org.junit.Before; import org.junit.Before;
import org.junit.Rule; import org.junit.Rule;
import org.openhab.habdroid.ui.OpenHABMainActivity; import org.openhab.habdroid.ui.MainActivity;
import org.openhab.habdroid.ui.OpenHABWidgetListFragment;
import org.openhab.habdroid.ui.activity.ContentController;
import org.openhab.habdroid.ui.activity.PageConnectionHolderFragment;
public abstract class ProgressbarAwareTest { public abstract class ProgressbarAwareTest {
@Rule @Rule
public IntentsTestRule<OpenHABMainActivity> mActivityTestRule = new IntentsTestRule<> public IntentsTestRule<MainActivity> mActivityTestRule =
(OpenHABMainActivity.class, true, false); new IntentsTestRule<>(MainActivity.class, true, false);
private IdlingResource mProgressbarIdlingResource; private IdlingResource mProgressbarIdlingResource;
private IdlingResource mFragmentIdlingResource; private IdlingResource mFragmentIdlingResource;
...@@ -36,9 +30,10 @@ public abstract class ProgressbarAwareTest { ...@@ -36,9 +30,10 @@ public abstract class ProgressbarAwareTest {
protected IdlingResource getProgressbarIdlingResource() { protected IdlingResource getProgressbarIdlingResource() {
if (mProgressbarIdlingResource == null) { if (mProgressbarIdlingResource == null) {
View progressBar = mActivityTestRule.getActivity().findViewById(R.id.toolbar_progress_bar); final View progressBar =
mProgressbarIdlingResource = new OpenHABProgressbarIdlingResource("Progressbar " + mActivityTestRule.getActivity().findViewById(R.id.toolbar_progress_bar);
"IdleResource", progressBar); mProgressbarIdlingResource =
new ProgressbarIdlingResource("Progressbar IdleResource", progressBar);
} }
return mProgressbarIdlingResource; return mProgressbarIdlingResource;
} }
......
...@@ -4,32 +4,33 @@ import android.support.annotation.NonNull; ...@@ -4,32 +4,33 @@ import android.support.annotation.NonNull;
import android.support.test.espresso.IdlingResource; import android.support.test.espresso.IdlingResource;
import android.view.View; import android.view.View;
public class OpenHABProgressbarIdlingResource implements IdlingResource { public class ProgressbarIdlingResource implements IdlingResource {
private String name; private String mName;
private View progressBar; private View mProgressBar;
private ResourceCallback callback; private ResourceCallback mCallback;
public OpenHABProgressbarIdlingResource(@NonNull String name, @NonNull View progressBar) { public ProgressbarIdlingResource(@NonNull String name, @NonNull View progressBar) {
this.name = name; mName = name;
this.progressBar = progressBar; mProgressBar = progressBar;
} }
@Override @Override
public String getName() { public String getName() {
return this.name; return mName;
} }
@Override @Override
public boolean isIdleNow() { public boolean isIdleNow() {
boolean idle = progressBar.getVisibility() == View.INVISIBLE; boolean idle = mProgressBar.getVisibility() == View.INVISIBLE;
if (idle && callback != null) if (idle && mCallback != null) {
callback.onTransitionToIdle(); mCallback.onTransitionToIdle();
}
return idle; return idle;
} }
@Override @Override
public void registerIdleTransitionCallback(ResourceCallback callback) { public void registerIdleTransitionCallback(ResourceCallback callback) {
this.callback = callback; mCallback = callback;
} }
} }
...@@ -6,7 +6,6 @@ import android.support.test.InstrumentationRegistry; ...@@ -6,7 +6,6 @@ import android.support.test.InstrumentationRegistry;
import org.openhab.habdroid.util.Constants; import org.openhab.habdroid.util.Constants;
public abstract class TestWithIntro extends ProgressbarAwareTest { public abstract class TestWithIntro extends ProgressbarAwareTest {
@Override @Override
public void setup() { public void setup() {
PreferenceManager PreferenceManager
......
package org.openhab.habdroid.screengrab; package org.openhab.habdroid.screengrab;
import android.support.annotation.IdRes;
import android.support.test.espresso.DataInteraction;
import android.support.test.espresso.UiController;
import android.support.test.espresso.ViewAction;
import android.support.test.espresso.ViewInteraction; import android.support.test.espresso.ViewInteraction;
import android.support.test.espresso.contrib.RecyclerViewActions; import android.support.test.espresso.contrib.RecyclerViewActions;
import android.support.test.espresso.matcher.BoundedMatcher;
import android.support.test.runner.AndroidJUnit4; import android.support.test.runner.AndroidJUnit4;
import android.support.v7.widget.RecyclerView;
import android.test.suitebuilder.annotation.LargeTest; import android.test.suitebuilder.annotation.LargeTest;
import android.view.View;
import org.hamcrest.Description;
import org.hamcrest.Matcher;
import org.junit.ClassRule; import org.junit.ClassRule;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.openhab.habdroid.BuildConfig;
import org.openhab.habdroid.R; import org.openhab.habdroid.R;
import org.openhab.habdroid.TestWithoutIntro; import org.openhab.habdroid.TestWithoutIntro;
import org.openhab.habdroid.ui.BasicWidgetTest;
import tools.fastlane.screengrab.Screengrab;
import tools.fastlane.screengrab.UiAutomatorScreenshotStrategy;
import tools.fastlane.screengrab.locale.LocaleTestRule; import tools.fastlane.screengrab.locale.LocaleTestRule;
import static android.support.test.espresso.Espresso.onData;
import static android.support.test.espresso.Espresso.onView; import static android.support.test.espresso.Espresso.onView;
import static android.support.test.espresso.Espresso.pressBack; import static android.support.test.espresso.Espresso.pressBack;
import static android.support.test.espresso.action.ViewActions.click; import static android.support.test.espresso.action.ViewActions.click;
import static android.support.test.espresso.action.ViewActions.longClick;
import static android.support.test.espresso.assertion.ViewAssertions.matches;
import static android.support.test.espresso.contrib.RecyclerViewActions.actionOnItemAtPosition;
import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed;
import static android.support.test.espresso.matcher.ViewMatchers.withClassName;
import static android.support.test.espresso.matcher.ViewMatchers.withId; import static android.support.test.espresso.matcher.ViewMatchers.withId;
import static android.support.test.espresso.matcher.ViewMatchers.withText; import static tools.fastlane.screengrab.Screengrab.screenshot;
import static org.hamcrest.Matchers.anything;
import static org.hamcrest.Matchers.is;
import static org.openhab.habdroid.ui.BasicWidgetTest.atPositionOnView;
import static org.openhab.habdroid.ui.BasicWidgetTest.onChildView;
import static tools.fastlane.screengrab.Screengrab.*;
@LargeTest @LargeTest
@RunWith(AndroidJUnit4.class) @RunWith(AndroidJUnit4.class)
......
package org.openhab.habdroid.ui; package org.openhab.habdroid.ui;
import android.support.annotation.IdRes; import android.support.annotation.IdRes;
import android.support.test.espresso.DataInteraction; import android.support.test.espresso.DataInteraction;
import android.support.test.espresso.UiController; import android.support.test.espresso.UiController;
...@@ -15,8 +14,6 @@ import android.view.View; ...@@ -15,8 +14,6 @@ import android.view.View;
import org.hamcrest.Description; import org.hamcrest.Description;
import org.hamcrest.Matcher; import org.hamcrest.Matcher;
import org.hamcrest.TypeSafeMatcher;
import org.junit.ClassRule;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.openhab.habdroid.BuildConfig; import org.openhab.habdroid.BuildConfig;
...@@ -27,6 +24,8 @@ import static android.support.test.espresso.Espresso.onData; ...@@ -27,6 +24,8 @@ import static android.support.test.espresso.Espresso.onData;
import static android.support.test.espresso.Espresso.onView; import static android.support.test.espresso.Espresso.onView;
import static android.support.test.espresso.action.ViewActions.click; import static android.support.test.espresso.action.ViewActions.click;
import static android.support.test.espresso.assertion.ViewAssertions.matches; import static android.support.test.espresso.assertion.ViewAssertions.matches;
import static android.support.test.espresso.contrib.RecyclerViewActions.actionOnItemAtPosition;
import static android.support.test.espresso.contrib.RecyclerViewActions.scrollToPosition;
import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed; import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed;
import static android.support.test.espresso.matcher.ViewMatchers.withClassName; import static android.support.test.espresso.matcher.ViewMatchers.withClassName;
import static android.support.test.espresso.matcher.ViewMatchers.withId; import static android.support.test.espresso.matcher.ViewMatchers.withId;
...@@ -38,35 +37,36 @@ import static org.hamcrest.Matchers.is; ...@@ -38,35 +37,36 @@ import static org.hamcrest.Matchers.is;
@RunWith(AndroidJUnit4.class) @RunWith(AndroidJUnit4.class)
public class BasicWidgetTest extends TestWithoutIntro { public class BasicWidgetTest extends TestWithoutIntro {
@Test @Test
public void openHABMainActivityTest() throws InterruptedException { public void mainActivityTest() {
ViewInteraction recyclerView = onView(withId(R.id.recyclerview)); ViewInteraction recyclerView = onView(withId(R.id.recyclerview));
recyclerView recyclerView
.perform(RecyclerViewActions.scrollToPosition(0)) .perform(scrollToPosition(0))
.check(matches(atPositionOnView(0, isDisplayed(), R.id.widgetlabel))) .check(matches(atPositionOnView(0, isDisplayed(), R.id.widgetlabel)))
.check(matches(atPositionOnView(0, withText("First Floor"), R.id.widgetlabel))); .check(matches(atPositionOnView(0, withText("First Floor"), R.id.widgetlabel)));
recyclerView recyclerView
.perform(RecyclerViewActions.scrollToPosition(6)) .perform(scrollToPosition(6))
.check(matches(atPositionOnView(6, isDisplayed(), R.id.widgetlabel))) .check(matches(atPositionOnView(6, isDisplayed(), R.id.widgetlabel)))
.check(matches(atPositionOnView(6, withText("Astronomical Data"), R.id.widgetlabel))); .check(matches(
atPositionOnView(6, withText("Astronomical Data"), R.id.widgetlabel)));
// does it show "garden"? // does it show "garden"?
recyclerView recyclerView
.perform(RecyclerViewActions.scrollToPosition(3)) .perform(scrollToPosition(3))
.check(matches(atPositionOnView(3, isDisplayed(), R.id.widgetlabel))) .check(matches(atPositionOnView(3, isDisplayed(), R.id.widgetlabel)))
.check(matches(atPositionOnView(3, withText("Garden"), R.id.widgetlabel))); .check(matches(atPositionOnView(3, withText("Garden"), R.id.widgetlabel)));
// open widget overview // open widget overview
recyclerView recyclerView
.perform(RecyclerViewActions.actionOnItemAtPosition(10, click())); .perform(actionOnItemAtPosition(10, click()));
// check whether selection widget appears and click on it // check whether selection widget appears and click on it
recyclerView recyclerView
.perform(RecyclerViewActions.scrollToPosition(4)) .perform(scrollToPosition(4))
.check(matches(atPositionOnView(4, withText("Scene Selection"), R.id.widgetlabel))) .check(matches(atPositionOnView(4, withText("Scene Selection"), R.id.widgetlabel)))
.check(matches(atPositionOnView(4, isDisplayed(), R.id.spinner))) .check(matches(atPositionOnView(4, isDisplayed(), R.id.spinner)))
.perform(RecyclerViewActions.actionOnItemAtPosition(4, onChildView(click(), R.id.spinner))); .perform(actionOnItemAtPosition(4, onChildView(click(), R.id.spinner)));
DataInteraction appCompatCheckedTextView = onData(anything()) DataInteraction appCompatCheckedTextView = onData(anything())
.inAdapterView(withClassName( .inAdapterView(withClassName(
...@@ -77,33 +77,33 @@ public class BasicWidgetTest extends TestWithoutIntro { ...@@ -77,33 +77,33 @@ public class BasicWidgetTest extends TestWithoutIntro {
// check whether scene radio button group is present // check whether scene radio button group is present
recyclerView recyclerView
.perform(RecyclerViewActions.scrollToPosition(5)) .perform(scrollToPosition(5))
.check(matches(atPositionOnView(5, isDisplayed(), R.id.switchgroup))); .check(matches(atPositionOnView(5, isDisplayed(), R.id.switchgroup)));
// check whether switch is displayed // check whether switch is displayed
recyclerView recyclerView
.perform(RecyclerViewActions.scrollToPosition(1)) .perform(scrollToPosition(1))
.check(matches(atPositionOnView(1, isDisplayed(), R.id.toggle))); .check(matches(atPositionOnView(1, isDisplayed(), R.id.toggle)));
// check whether slider is displayed // check whether slider is displayed
recyclerView recyclerView
.perform(RecyclerViewActions.scrollToPosition(8)) .perform(scrollToPosition(8))
.check(matches(atPositionOnView(8, isDisplayed(), R.id.seekbar))); .check(matches(atPositionOnView(8, isDisplayed(), R.id.seekbar)));
// check whether color control button is displayed // check whether color control button is displayed
recyclerView recyclerView
.perform(RecyclerViewActions.scrollToPosition(9)) .perform(scrollToPosition(9))
.check(matches(atPositionOnView(9, isDisplayed(), R.id.select_color_button))); .check(matches(atPositionOnView(9, isDisplayed(), R.id.select_color_button)));
// check whether roller shutter button is displayed // check whether roller shutter button is displayed
recyclerView recyclerView
.perform(RecyclerViewActions.scrollToPosition(10)) .perform(scrollToPosition(10))
.check(matches(atPositionOnView(10, isDisplayed(), R.id.stop_button))); .check(matches(atPositionOnView(10, isDisplayed(), R.id.stop_button)));
if (BuildConfig.FLAVOR.equals("full")) { if (BuildConfig.FLAVOR.equals("full")) {
// check whether map view is displayed // check whether map view is displayed
recyclerView recyclerView
.perform(RecyclerViewActions.scrollToPosition(13)) .perform(scrollToPosition(13))
.check(matches(atPositionOnView(13, isDisplayed(), "MapView"))); .check(matches(atPositionOnView(13, isDisplayed(), "MapView")));
} }
} }
...@@ -132,7 +132,8 @@ public class BasicWidgetTest extends TestWithoutIntro { ...@@ -132,7 +132,8 @@ public class BasicWidgetTest extends TestWithoutIntro {
@Override @Override
public boolean matchesSafely(final RecyclerView recyclerView) { public boolean matchesSafely(final RecyclerView recyclerView) {
RecyclerView.ViewHolder viewHolder = recyclerView.findViewHolderForAdapterPosition(position); RecyclerView.ViewHolder viewHolder =
recyclerView.findViewHolderForAdapterPosition(position);
View targetView = childCb.findChild(viewHolder.itemView); View targetView = childCb.findChild(viewHolder.itemView);
return itemMatcher.matches(targetView); return itemMatcher.matches(targetView);
} }
......
package org.openhab.habdroid.ui; package org.openhab.habdroid.ui;
import android.support.test.espresso.IdlingRegistry;
import android.support.test.espresso.ViewInteraction; import android.support.test.espresso.ViewInteraction;
import android.support.test.runner.AndroidJUnit4; import android.support.test.runner.AndroidJUnit4;
import android.test.suitebuilder.annotation.LargeTest; import android.test.suitebuilder.annotation.LargeTest;
import android.view.View;
import org.hamcrest.CoreMatchers; import org.hamcrest.CoreMatchers;
import org.hamcrest.core.IsInstanceOf;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.openhab.habdroid.R; import org.openhab.habdroid.R;
...@@ -23,42 +19,35 @@ import static android.support.test.espresso.matcher.ViewMatchers.withId; ...@@ -23,42 +19,35 @@ import static android.support.test.espresso.matcher.ViewMatchers.withId;
import static android.support.test.espresso.matcher.ViewMatchers.withParent; import static android.support.test.espresso.matcher.ViewMatchers.withParent;
import static android.support.test.espresso.matcher.ViewMatchers.withText; import static android.support.test.espresso.matcher.ViewMatchers.withText;
import static org.hamcrest.Matchers.allOf; import static org.hamcrest.Matchers.allOf;
import static org.openhab.habdroid.TestUtils.childAtPosition; import static org.openhab.habdroid.TestUtils.childAtPosition;
@LargeTest @LargeTest
@RunWith(AndroidJUnit4.class) @RunWith(AndroidJUnit4.class)
public class IntroActivityTest extends TestWithIntro { public class IntroActivityTest extends TestWithIntro {
@Test @Test
public void appShowsIntro() { public void appShowsIntro() {
ViewInteraction textView = onView( ViewInteraction textView = onView(allOf(
allOf(withId(R.id.title), withText("Welcome to openHAB"), withId(R.id.title),
childAtPosition( withText("Welcome to openHAB"),
allOf(withId(R.id.main), childAtPosition(allOf(withId(R.id.main), withParent(withId(R.id.view_pager))), 0),
withParent(withId(R.id.view_pager))),
0),
isDisplayed())); isDisplayed()));
textView.check(matches(withText("Welcome to openHAB"))); textView.check(matches(withText("Welcome to openHAB")));
ViewInteraction imageView = onView( ViewInteraction imageView = onView(allOf(
allOf(withId(R.id.image), withId(R.id.image),
childAtPosition( childAtPosition(childAtPosition(withId(R.id.main), 1), 0),
childAtPosition(
withId(R.id.main),
1),
0),
isDisplayed())); isDisplayed()));
imageView.check(matches(isDisplayed())); imageView.check(matches(isDisplayed()));
ViewInteraction textView2 = onView( final String descLabel =
allOf(withId(R.id.description), withText("A vendor and technology agnostic open source automation software for your home"), "A vendor and technology agnostic open source automation software for your home";
childAtPosition( ViewInteraction textView2 = onView(allOf(
childAtPosition( withId(R.id.description),
withId(R.id.main), withText(descLabel),
2), childAtPosition(childAtPosition(withId(R.id.main), 2), 0),
0),
isDisplayed())); isDisplayed()));
textView2.check(matches(withText("A vendor and technology agnostic open source automation software for your home"))); textView2.check(matches(withText(descLabel)));
ViewInteraction button = onView(allOf(withId(R.id.skip))); ViewInteraction button = onView(allOf(withId(R.id.skip)));
button.check(matches(isDisplayed())); button.check(matches(isDisplayed()));
...@@ -67,13 +56,12 @@ public class IntroActivityTest extends TestWithIntro { ...@@ -67,13 +56,12 @@ public class IntroActivityTest extends TestWithIntro {
imageButton.check(matches(isDisplayed())); imageButton.check(matches(isDisplayed()));
// skip intro // skip intro
ViewInteraction appCompatButton = onView( ViewInteraction appCompatButton = onView(allOf(
allOf(withId(R.id.skip), withText("SKIP"), withId(R.id.skip),
childAtPosition( withText("SKIP"),
allOf(withId(R.id.bottomContainer), childAtPosition(allOf(
childAtPosition( withId(R.id.bottomContainer),
withId(R.id.bottom), childAtPosition(withId(R.id.bottom), 1)),
1)),
1), 1),
isDisplayed())); isDisplayed()));
appCompatButton.perform(click()); appCompatButton.perform(click());
...@@ -87,7 +75,7 @@ public class IntroActivityTest extends TestWithIntro { ...@@ -87,7 +75,7 @@ public class IntroActivityTest extends TestWithIntro {
// Do we see the sitemap? // Do we see the sitemap?
ViewInteraction firstfloor = onView( ViewInteraction firstfloor = onView(
CoreMatchers.allOf(withId(R.id.widgetlabel), withText("First Floor"), isDisplayed())); allOf(withId(R.id.widgetlabel), withText("First Floor"), isDisplayed()));
firstfloor.check(matches(withText("First Floor"))); firstfloor.check(matches(withText("First Floor")));
} }
...@@ -96,26 +84,23 @@ public class IntroActivityTest extends TestWithIntro { ...@@ -96,26 +84,23 @@ public class IntroActivityTest extends TestWithIntro {
// click next // click next
ViewInteraction appCompatImageButton; ViewInteraction appCompatImageButton;
for (int i = 0; i < 3; i++) { for (int i = 0; i < 3; i++) {
appCompatImageButton = onView( appCompatImageButton = onView(allOf(
CoreMatchers.allOf(withId(R.id.next), withId(R.id.next),
childAtPosition( childAtPosition(allOf(
CoreMatchers.allOf(withId(R.id.bottomContainer), withId(R.id.bottomContainer),
childAtPosition( childAtPosition(withId(R.id.bottom), 1)),
withId(R.id.bottom),
1)),
3), 3),
isDisplayed())); isDisplayed()));
appCompatImageButton.perform(click()); appCompatImageButton.perform(click());
} }
// close intro // close intro
ViewInteraction appCompatButton = onView( ViewInteraction appCompatButton = onView(allOf(
CoreMatchers.allOf(withId(R.id.done), withText("DONE"), withId(R.id.done),
childAtPosition( withText("DONE"),
CoreMatchers.allOf(withId(R.id.bottomContainer), childAtPosition(allOf(
childAtPosition( withId(R.id.bottomContainer),
withId(R.id.bottom), childAtPosition(withId(R.id.bottom), 1)),
1)),
4), 4),
isDisplayed())); isDisplayed()));
appCompatButton.perform(click()); appCompatButton.perform(click());
...@@ -129,7 +114,7 @@ public class IntroActivityTest extends TestWithIntro { ...@@ -129,7 +114,7 @@ public class IntroActivityTest extends TestWithIntro {
// Do we see the sitemap? // Do we see the sitemap?
ViewInteraction firstfloor = onView( ViewInteraction firstfloor = onView(
CoreMatchers.allOf(withId(R.id.widgetlabel), withText("First Floor"), isDisplayed())); allOf(withId(R.id.widgetlabel), withText("First Floor"), isDisplayed()));
firstfloor.check(matches(withText("First Floor"))); firstfloor.check(matches(withText("First Floor")));
} }
} }
package org.openhab.habdroid.ui; package org.openhab.habdroid.ui;
import android.content.Context; import android.content.Context;
import android.support.annotation.StringRes;
import android.support.test.InstrumentationRegistry; import android.support.test.InstrumentationRegistry;
import android.support.test.espresso.ViewInteraction; import android.support.test.espresso.ViewInteraction;
import android.support.test.espresso.contrib.RecyclerViewActions; import android.support.test.espresso.contrib.RecyclerViewActions;
...@@ -8,7 +9,6 @@ import android.support.test.runner.AndroidJUnit4; ...@@ -8,7 +9,6 @@ import android.support.test.runner.AndroidJUnit4;
import android.test.suitebuilder.annotation.LargeTest; import android.test.suitebuilder.annotation.LargeTest;
import org.hamcrest.core.IsInstanceOf; import org.hamcrest.core.IsInstanceOf;
import org.junit.ClassRule;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.openhab.habdroid.R; import org.openhab.habdroid.R;
...@@ -28,7 +28,7 @@ import static org.hamcrest.Matchers.allOf; ...@@ -28,7 +28,7 @@ import static org.hamcrest.Matchers.allOf;
@RunWith(AndroidJUnit4.class) @RunWith(AndroidJUnit4.class)
public class NfcTest extends TestWithoutIntro { public class NfcTest extends TestWithoutIntro {
@Test @Test
public void nfcTest() throws InterruptedException { public void nfcTest() {
ViewInteraction recyclerView = onView(withId(R.id.recyclerview)); ViewInteraction recyclerView = onView(withId(R.id.recyclerview));
Context context = InstrumentationRegistry.getTargetContext(); Context context = InstrumentationRegistry.getTargetContext();
...@@ -43,21 +43,21 @@ public class NfcTest extends TestWithoutIntro { ...@@ -43,21 +43,21 @@ public class NfcTest extends TestWithoutIntro {
withText(context.getString(R.string.nfc_dialog_title)))); withText(context.getString(R.string.nfc_dialog_title))));
title.check(matches(withText(context.getString(R.string.nfc_dialog_title)))); title.check(matches(withText(context.getString(R.string.nfc_dialog_title))));
ViewInteraction onButton = onView(withText(context.getString(R.string.nfc_action_on))); checkViewWithText(context, R.string.nfc_action_off);
onButton.check(matches(withText(context.getString(R.string.nfc_action_on)))); checkViewWithText(context, R.string.nfc_action_toggle);
checkViewWithText(context, R.string.nfc_action_to_sitemap_page);
ViewInteraction offButton = onView(withText(context.getString(R.string.nfc_action_off)));
offButton.check(matches(withText(context.getString(R.string.nfc_action_off))));
ViewInteraction toggleButton = onView(withText(context.getString(R.string.nfc_action_toggle)));
toggleButton.check(matches(withText(context.getString(R.string.nfc_action_toggle))));
ViewInteraction sitemapButton = onView(withText(context.getString(R.string.nfc_action_to_sitemap_page)));
sitemapButton.check(matches(withText(context.getString(R.string.nfc_action_to_sitemap_page))));
ViewInteraction onButton = checkViewWithText(context, R.string.nfc_action_on);
onButton.perform(click()); onButton.perform(click());
ViewInteraction imageView = onView(withId(R.id.nfc_watermark)); ViewInteraction imageView = onView(withId(R.id.nfc_watermark));
imageView.check(matches(isDisplayed())); imageView.check(matches(isDisplayed()));
} }
private ViewInteraction checkViewWithText(Context context, @StringRes int stringResId) {
String title = context.getString(stringResId);
ViewInteraction view = onView(withText(title));
view.check(matches(withText(title)));
return view;
}
} }
package org.openhab.habdroid.ui; package org.openhab.habdroid.ui;
import android.content.Context;
import android.speech.SpeechRecognizer; import android.speech.SpeechRecognizer;
import android.support.test.InstrumentationRegistry; import android.support.test.InstrumentationRegistry;
import android.support.test.espresso.ViewInteraction; import android.support.test.espresso.ViewInteraction;
...@@ -20,21 +21,23 @@ import static org.hamcrest.CoreMatchers.allOf; ...@@ -20,21 +21,23 @@ import static org.hamcrest.CoreMatchers.allOf;
import static org.junit.Assume.assumeTrue; import static org.junit.Assume.assumeTrue;
public class VoiceRecognitionTest extends TestWithoutIntro { public class VoiceRecognitionTest extends TestWithoutIntro {
@Rule @Rule
public ActivityTestRule<OpenHABMainActivity> mActivityTestRule = new ActivityTestRule<> public ActivityTestRule<MainActivity> mActivityTestRule =
(OpenHABMainActivity.class, true, false); new ActivityTestRule<>(MainActivity.class, true, false);
@Before @Before
public void checkVoiceRecognitionAvailableOnDevice() { public void checkVoiceRecognitionAvailableOnDevice() {
final Context context = InstrumentationRegistry.getTargetContext();
assumeTrue("Voice recognition not available, skipping tests for it.", assumeTrue("Voice recognition not available, skipping tests for it.",
SpeechRecognizer.isRecognitionAvailable(InstrumentationRegistry.getTargetContext())); SpeechRecognizer.isRecognitionAvailable(context));
} }
@Test @Test
public void checkVoiceAvailbility() { public void checkVoiceAvailbility() {
ViewInteraction voice = onView( ViewInteraction voice = onView(allOf(
allOf(withId(R.id.mainmenu_voice_recognition), withContentDescription("Voice recognition"), isDisplayed())); withId(R.id.mainmenu_voice_recognition),
withContentDescription("Voice recognition"),
isDisplayed()));
voice.check(matches(isDisplayed())); voice.check(matches(isDisplayed()));
} }
......
...@@ -5,32 +5,39 @@ import android.support.test.InstrumentationRegistry; ...@@ -5,32 +5,39 @@ import android.support.test.InstrumentationRegistry;
import android.support.v7.view.ContextThemeWrapper; import android.support.v7.view.ContextThemeWrapper;
import org.junit.Test; import org.junit.Test;
import org.openhab.habdroid.R;
import org.openhab.habdroid.ui.WidgetAdapter.ColorMapper;
import static junit.framework.Assert.assertEquals; import static junit.framework.Assert.assertEquals;
import org.openhab.habdroid.R;
import org.openhab.habdroid.ui.OpenHABWidgetAdapter.ColorMapper;
public class WidgetAdapterTest { public class WidgetAdapterTest {
private Context context = InstrumentationRegistry.getTargetContext(); private Context mContext = InstrumentationRegistry.getTargetContext();
@Test @Test
public void testColorMappingDarkTheme() { public void testColorMappingDarkTheme() {
ColorMapper colorMapper = new ColorMapper(new ContextThemeWrapper(context, R.style.HABDroid_Basic_ui_dark)); final ColorMapper colorMapper =
assertEquals("Map #ffffff", Integer.valueOf(0xffffffff), colorMapper.mapColor("#ffffff")); new ColorMapper(new ContextThemeWrapper(mContext, R.style.HABDroid_Basic_ui_dark));
assertEquals("Must return \"null\" for invalid colors", null, colorMapper.mapColor("#fffzzz")); testMapping(colorMapper, "Map #ffffff", "#ffffff", 0xffffffff);
assertEquals("Map white => #ffffff in dark themes", Integer.valueOf(0xffffffff), colorMapper.mapColor("white")); testMapping(colorMapper, "Must return \"null\" for invalid colors", "#fffzzz", null);
assertEquals("Map red => #ff0000 in dark themes", Integer.valueOf(0xffff0000), colorMapper.mapColor("red")); testMapping(colorMapper, "Map white => #ffffff in dark themes", "white", 0xffffffff);
assertEquals("Map yellow => #ffff00 in dark themes", Integer.valueOf(0xffffff00), colorMapper.mapColor("yellow")); testMapping(colorMapper, "Map red => #ff0000 in dark themes", "red", 0xffff0000);
testMapping(colorMapper, "Map yellow => #ffff00 in dark themes", "yellow", 0xffffff00);
} }
@Test @Test
public void testColorMappingBrightTheme() { public void testColorMappingBrightTheme() {
ColorMapper colorMapper = new ColorMapper(new ContextThemeWrapper(context, R.style.HABDroid_Basic_ui)); final ColorMapper colorMapper =
assertEquals("Map #ffffff", Integer.valueOf(0xffffffff), colorMapper.mapColor("#ffffff")); new ColorMapper(new ContextThemeWrapper(mContext, R.style.HABDroid_Basic_ui));
assertEquals("Must return \"null\" for invalid colors", null, colorMapper.mapColor("#fffzzz")); testMapping(colorMapper, "Map #ffffff", "#ffffff", 0xffffffff);
assertEquals("Map white => #000000 in bright themes", Integer.valueOf(0xff000000), colorMapper.mapColor("white")); testMapping(colorMapper, "Must return \"null\" for invalid colors", "#fffzzz", null);
assertEquals("Map red => #ff0000 in bright themes", Integer.valueOf(0xffff0000), colorMapper.mapColor("red")); testMapping(colorMapper, "Map white => #000000 in bright themes", "white", 0xff000000);
assertEquals("Map yellow => #fdd835 in bright themes", Integer.valueOf(0xfffdd835), colorMapper.mapColor("yellow")); testMapping(colorMapper, "Map red => #ff0000 in bright themes", "red", 0xffff0000);
testMapping(colorMapper, "Map yellow => #fdd835 in bright themes", "yellow", 0xfffdd835);
}
private static void testMapping(ColorMapper mapper, String message,
String value, Integer expected) {
assertEquals(message, expected != null ? Integer.valueOf(expected) : null,
mapper.mapColor(value));
} }
} }
...@@ -6,8 +6,8 @@ import android.view.ViewGroup; ...@@ -6,8 +6,8 @@ import android.view.ViewGroup;
import org.openhab.habdroid.core.connection.Connection; import org.openhab.habdroid.core.connection.Connection;
public class MapViewHelper { public class MapViewHelper {
public static OpenHABWidgetAdapter.ViewHolder createViewHolder(LayoutInflater inflater, public static WidgetAdapter.ViewHolder createViewHolder(LayoutInflater inflater,
ViewGroup parent, Connection connection, OpenHABWidgetAdapter.ColorMapper colorMapper) { ViewGroup parent, Connection connection, WidgetAdapter.ColorMapper colorMapper) {
return new OpenHABWidgetAdapter.GenericViewHolder(inflater, parent, connection, colorMapper); return new WidgetAdapter.GenericViewHolder(inflater, parent, connection, colorMapper);
} }
} }
...@@ -30,7 +30,7 @@ ...@@ -30,7 +30,7 @@
</service> </service>
<service <service
android:name="org.openhab.habdroid.core.GcmInstanceIDListenerService" android:name="org.openhab.habdroid.core.GcmInstanceIdListenerService"
android:exported="false"> android:exported="false">
<intent-filter> <intent-filter>
<action android:name="com.google.android.gms.iid.InstanceID" /> <action android:name="com.google.android.gms.iid.InstanceID" />
......
...@@ -30,7 +30,8 @@ public class CloudMessagingHelper { ...@@ -30,7 +30,8 @@ public class CloudMessagingHelper {
} }
public static void onNotificationSelected(Context context, Intent intent) { public static void onNotificationSelected(Context context, Intent intent) {
int notificationId = intent.getIntExtra(GcmMessageListenerService.EXTRA_NOTIFICATION_ID, -1); int notificationId = intent.getIntExtra(
GcmMessageListenerService.EXTRA_NOTIFICATION_ID, -1);
if (notificationId >= 0) { if (notificationId >= 0) {
GcmRegistrationService.scheduleHideNotification(context, notificationId); GcmRegistrationService.scheduleHideNotification(context, notificationId);
} }
......
...@@ -11,7 +11,7 @@ package org.openhab.habdroid.core; ...@@ -11,7 +11,7 @@ package org.openhab.habdroid.core;
import com.google.android.gms.iid.InstanceIDListenerService; import com.google.android.gms.iid.InstanceIDListenerService;
public class GcmInstanceIDListenerService extends InstanceIDListenerService { public class GcmInstanceIdListenerService extends InstanceIDListenerService {
@Override @Override
public void onTokenRefresh() { public void onTokenRefresh() {
GcmRegistrationService.scheduleRegistration(this); GcmRegistrationService.scheduleRegistration(this);
......
...@@ -32,7 +32,7 @@ import com.google.android.gms.gcm.GcmListenerService; ...@@ -32,7 +32,7 @@ import com.google.android.gms.gcm.GcmListenerService;
import org.openhab.habdroid.R; import org.openhab.habdroid.R;
import org.openhab.habdroid.core.connection.Connection; import org.openhab.habdroid.core.connection.Connection;
import org.openhab.habdroid.core.connection.ConnectionFactory; import org.openhab.habdroid.core.connection.ConnectionFactory;
import org.openhab.habdroid.ui.OpenHABMainActivity; import org.openhab.habdroid.ui.MainActivity;
import org.openhab.habdroid.util.Constants; import org.openhab.habdroid.util.Constants;
import org.openhab.habdroid.util.SyncHttpClient; import org.openhab.habdroid.util.SyncHttpClient;
...@@ -103,15 +103,17 @@ public class GcmMessageListenerService extends GcmListenerService { ...@@ -103,15 +103,17 @@ public class GcmMessageListenerService extends GcmListenerService {
} }
} }
break; break;
default:
break;
} }
} }
private PendingIntent makeNotificationClickIntent(String persistedId, int notificationId) { private PendingIntent makeNotificationClickIntent(String persistedId, int notificationId) {
Intent contentIntent = new Intent(this, OpenHABMainActivity.class) Intent contentIntent = new Intent(this, MainActivity.class)
.setAction(OpenHABMainActivity.ACTION_NOTIFICATION_SELECTED) .setAction(MainActivity.ACTION_NOTIFICATION_SELECTED)
.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP) .setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP)
.putExtra(EXTRA_NOTIFICATION_ID, notificationId) .putExtra(EXTRA_NOTIFICATION_ID, notificationId)
.putExtra(OpenHABMainActivity.EXTRA_PERSISTED_NOTIFICATION_ID, persistedId); .putExtra(MainActivity.EXTRA_PERSISTED_NOTIFICATION_ID, persistedId);
return PendingIntent.getActivity(this, notificationId, return PendingIntent.getActivity(this, notificationId,
contentIntent, PendingIntent.FLAG_UPDATE_CURRENT); contentIntent, PendingIntent.FLAG_UPDATE_CURRENT);
} }
...@@ -149,7 +151,8 @@ public class GcmMessageListenerService extends GcmListenerService { ...@@ -149,7 +151,8 @@ public class GcmMessageListenerService extends GcmListenerService {
.setSound(Uri.parse(toneSetting)) .setSound(Uri.parse(toneSetting))
.setContentText(msg) .setContentText(msg)
.setContentIntent(contentIntent) .setContentIntent(contentIntent)
.setDeleteIntent(GcmRegistrationService.createHideNotificationIntent(this, notificationId)) .setDeleteIntent(GcmRegistrationService.createHideNotificationIntent(this,
notificationId))
.setVisibility(NotificationCompat.VISIBILITY_PRIVATE) .setVisibility(NotificationCompat.VISIBILITY_PRIVATE)
.setPublicVersion(publicVersion) .setPublicVersion(publicVersion)
.build(); .build();
...@@ -172,7 +175,8 @@ public class GcmMessageListenerService extends GcmListenerService { ...@@ -172,7 +175,8 @@ public class GcmMessageListenerService extends GcmListenerService {
.setContentText(text) .setContentText(text)
.setPublicVersion(publicVersion) .setPublicVersion(publicVersion)
.setContentIntent(clickIntent) .setContentIntent(clickIntent)
.setDeleteIntent(GcmRegistrationService.createHideNotificationIntent(this, SUMMARY_NOTIFICATION_ID)) .setDeleteIntent(GcmRegistrationService.createHideNotificationIntent(this,
SUMMARY_NOTIFICATION_ID))
.build(); .build();
} }
...@@ -182,9 +186,11 @@ public class GcmMessageListenerService extends GcmListenerService { ...@@ -182,9 +186,11 @@ public class GcmMessageListenerService extends GcmListenerService {
String vibration = prefs.getString(Constants.PREFERENCE_NOTIFICATION_VIBRATION, ""); String vibration = prefs.getString(Constants.PREFERENCE_NOTIFICATION_VIBRATION, "");
if (getString(R.string.settings_notification_vibration_value_short).equals(vibration)) { if (getString(R.string.settings_notification_vibration_value_short).equals(vibration)) {
vibrationPattern = new long[] {0, 500, 500}; vibrationPattern = new long[] {0, 500, 500};
} else if (getString(R.string.settings_notification_vibration_value_long).equals(vibration)) { } else if (getString(R.string.settings_notification_vibration_value_long)
.equals(vibration)) {
vibrationPattern = new long[] {0, 1000, 1000}; vibrationPattern = new long[] {0, 1000, 1000};
} else if (getString(R.string.settings_notification_vibration_value_twice).equals(vibration)) { } else if (getString(R.string.settings_notification_vibration_value_twice)
.equals(vibration)) {
vibrationPattern = new long[] {0, 1000, 1000, 1000, 1000}; vibrationPattern = new long[] {0, 1000, 1000, 1000, 1000};
} else { } else {
vibrationPattern = new long[] {0}; vibrationPattern = new long[] {0};
...@@ -206,9 +212,9 @@ public class GcmMessageListenerService extends GcmListenerService { ...@@ -206,9 +212,9 @@ public class GcmMessageListenerService extends GcmListenerService {
@TargetApi(23) @TargetApi(23)
private int getGcmNotificationCount(StatusBarNotification[] active) { private int getGcmNotificationCount(StatusBarNotification[] active) {
int count = 0; int count = 0;
for (int i = 0; i < active.length; i++) { for (StatusBarNotification n : active) {
String groupKey = active[i].getGroupKey(); String groupKey = n.getGroupKey();
if (active[i].getId() != 0 && groupKey != null && groupKey.endsWith("gcm")) { if (n.getId() != 0 && groupKey != null && groupKey.endsWith("gcm")) {
count++; count++;
} }
} }
......
...@@ -38,7 +38,8 @@ public class GcmRegistrationService extends JobIntentService { ...@@ -38,7 +38,8 @@ public class GcmRegistrationService extends JobIntentService {
private static final int JOB_ID = 1000; private static final int JOB_ID = 1000;
private static final String ACTION_REGISTER = "org.openhab.habdroid.action.REGISTER_GCM"; private static final String ACTION_REGISTER = "org.openhab.habdroid.action.REGISTER_GCM";
private static final String ACTION_HIDE_NOTIFICATION = "org.openhab.habdroid.action.HIDE_NOTIFICATION"; private static final String ACTION_HIDE_NOTIFICATION =
"org.openhab.habdroid.action.HIDE_NOTIFICATION";
private static final String EXTRA_NOTIFICATION_ID = "notificationId"; private static final String EXTRA_NOTIFICATION_ID = "notificationId";
static void scheduleRegistration(Context context) { static void scheduleRegistration(Context context) {
...@@ -87,31 +88,35 @@ public class GcmRegistrationService extends JobIntentService { ...@@ -87,31 +88,35 @@ public class GcmRegistrationService extends JobIntentService {
CloudMessagingHelper.sRegistrationDone = true; CloudMessagingHelper.sRegistrationDone = true;
break; break;
case ACTION_HIDE_NOTIFICATION: case ACTION_HIDE_NOTIFICATION:
int notificationId = intent.getIntExtra(EXTRA_NOTIFICATION_ID, -1); int id = intent.getIntExtra(EXTRA_NOTIFICATION_ID, -1);
if (notificationId >= 0) { if (id >= 0) {
try { try {
sendHideNotificationRequest(notificationId, connection.getMessagingSenderId()); sendHideNotificationRequest(id, connection.getMessagingSenderId());
} catch (IOException e) { } catch (IOException e) {
Log.e(TAG, "Failed sending notification hide message", e); Log.e(TAG, "Failed sending notification hide message", e);
} }
} }
break; break;
default:
break;
} }
} }
private void registerGcm(CloudConnection connection) throws IOException { private void registerGcm(CloudConnection connection) throws IOException {
InstanceID instanceID = InstanceID.getInstance(this); InstanceID instanceId = InstanceID.getInstance(this);
String token = instanceID.getToken(connection.getMessagingSenderId(), String token = instanceId.getToken(connection.getMessagingSenderId(),
GoogleCloudMessaging.INSTANCE_ID_SCOPE, null); GoogleCloudMessaging.INSTANCE_ID_SCOPE, null);
String deviceModel = URLEncoder.encode(Build.MODEL, "UTF-8"); String deviceModel = URLEncoder.encode(Build.MODEL, "UTF-8");
String deviceId = Settings.Secure.getString(getContentResolver(), Settings.Secure.ANDROID_ID); String deviceId =
Settings.Secure.getString(getContentResolver(), Settings.Secure.ANDROID_ID);
String regUrl = String.format(Locale.US, String regUrl = String.format(Locale.US,
"addAndroidRegistration?deviceId=%s&deviceModel=%s&regId=%s", "addAndroidRegistration?deviceId=%s&deviceModel=%s&regId=%s",
deviceId, deviceModel, token); deviceId, deviceModel, token);
Log.d(TAG, "Register device at openHAB-cloud with URL: " + regUrl); Log.d(TAG, "Register device at openHAB-cloud with URL: " + regUrl);
SyncHttpClient.HttpStatusResult result = connection.getSyncHttpClient().get(regUrl).asStatus(); SyncHttpClient.HttpStatusResult result =
connection.getSyncHttpClient().get(regUrl).asStatus();
if (result.isSuccessful()) { if (result.isSuccessful()) {
Log.d(TAG, "GCM reg id success"); Log.d(TAG, "GCM reg id success");
} else { } else {
...@@ -120,7 +125,8 @@ public class GcmRegistrationService extends JobIntentService { ...@@ -120,7 +125,8 @@ public class GcmRegistrationService extends JobIntentService {
CloudMessagingHelper.sRegistrationFailureReason = result.error; CloudMessagingHelper.sRegistrationFailureReason = result.error;
} }
private void sendHideNotificationRequest(int notificationId, String senderId) throws IOException { private void sendHideNotificationRequest(int notificationId, String senderId)
throws IOException {
GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(this); GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(this);
Bundle sendBundle = new Bundle(); Bundle sendBundle = new Bundle();
sendBundle.putString("type", "hideNotification"); sendBundle.putString("type", "hideNotification");
......
...@@ -17,30 +17,30 @@ import com.google.android.gms.maps.model.MarkerOptions; ...@@ -17,30 +17,30 @@ import com.google.android.gms.maps.model.MarkerOptions;
import org.openhab.habdroid.R; import org.openhab.habdroid.R;
import org.openhab.habdroid.core.connection.Connection; import org.openhab.habdroid.core.connection.Connection;
import org.openhab.habdroid.model.OpenHABItem; import org.openhab.habdroid.model.Item;
import org.openhab.habdroid.model.OpenHABWidget; import org.openhab.habdroid.model.Widget;
import org.openhab.habdroid.util.Util; import org.openhab.habdroid.util.Util;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Locale; import java.util.Locale;
public class MapViewHelper { public class MapViewHelper {
public static OpenHABWidgetAdapter.ViewHolder createViewHolder(LayoutInflater inflater, public static WidgetAdapter.ViewHolder createViewHolder(LayoutInflater inflater,
ViewGroup parent, Connection connection, OpenHABWidgetAdapter.ColorMapper colorMapper) { ViewGroup parent, Connection connection, WidgetAdapter.ColorMapper colorMapper) {
MapsInitializer.initialize(inflater.getContext()); MapsInitializer.initialize(inflater.getContext());
return new GoogleMapsViewHolder(inflater, parent, connection, colorMapper); return new GoogleMapsViewHolder(inflater, parent, connection, colorMapper);
} }
private static class GoogleMapsViewHolder extends OpenHABWidgetAdapter.LabeledItemBaseViewHolder private static class GoogleMapsViewHolder extends WidgetAdapter.LabeledItemBaseViewHolder
implements GoogleMap.OnMarkerDragListener { implements GoogleMap.OnMarkerDragListener {
private final MapView mMapView; private final MapView mMapView;
private final int mRowHeightPixels; private final int mRowHeightPixels;
private GoogleMap mMap; private GoogleMap mMap;
private OpenHABItem mBoundItem; private Item mBoundItem;
private boolean mStarted; private boolean mStarted;
public GoogleMapsViewHolder(LayoutInflater inflater, ViewGroup parent, public GoogleMapsViewHolder(LayoutInflater inflater, ViewGroup parent,
Connection connection, OpenHABWidgetAdapter.ColorMapper colorMapper) { Connection connection, WidgetAdapter.ColorMapper colorMapper) {
super(inflater, parent, R.layout.openhabwidgetlist_mapitem, connection, colorMapper); super(inflater, parent, R.layout.openhabwidgetlist_mapitem, connection, colorMapper);
mMapView = itemView.findViewById(R.id.mapview); mMapView = itemView.findViewById(R.id.mapview);
...@@ -61,7 +61,7 @@ public class MapViewHelper { ...@@ -61,7 +61,7 @@ public class MapViewHelper {
} }
@Override @Override
public void bind(OpenHABWidget widget) { public void bind(Widget widget) {
super.bind(widget); super.bind(widget);
ViewGroup.LayoutParams lp = mMapView.getLayoutParams(); ViewGroup.LayoutParams lp = mMapView.getLayoutParams();
...@@ -113,7 +113,7 @@ public class MapViewHelper { ...@@ -113,7 +113,7 @@ public class MapViewHelper {
public void onMarkerDragEnd(Marker marker) { public void onMarkerDragEnd(Marker marker) {
String newState = String.format(Locale.US, "%f,%f", String newState = String.format(Locale.US, "%f,%f",
marker.getPosition().latitude, marker.getPosition().longitude); marker.getPosition().latitude, marker.getPosition().longitude);
OpenHABItem item = (OpenHABItem) marker.getTag(); Item item = (Item) marker.getTag();
Util.sendItemCommand(mConnection.getAsyncHttpClient(), item, newState); Util.sendItemCommand(mConnection.getAsyncHttpClient(), item, newState);
} }
...@@ -147,7 +147,7 @@ public class MapViewHelper { ...@@ -147,7 +147,7 @@ public class MapViewHelper {
boolean canDragMarker = allowDrag && !mBoundItem.readOnly(); boolean canDragMarker = allowDrag && !mBoundItem.readOnly();
if (!mBoundItem.members().isEmpty()) { if (!mBoundItem.members().isEmpty()) {
ArrayList<LatLng> positions = new ArrayList<>(); ArrayList<LatLng> positions = new ArrayList<>();
for (OpenHABItem item : mBoundItem.members()) { for (Item item : mBoundItem.members()) {
LatLng position = parseLocation(item.state()); LatLng position = parseLocation(item.state());
if (position != null) { if (position != null) {
setMarker(map, position, item, item.label(), canDragMarker); setMarker(map, position, item, item.label(), canDragMarker);
...@@ -174,7 +174,7 @@ public class MapViewHelper { ...@@ -174,7 +174,7 @@ public class MapViewHelper {
} }
} }
private static void setMarker(GoogleMap map, LatLng position, OpenHABItem item, private static void setMarker(GoogleMap map, LatLng position, Item item,
CharSequence label, boolean canDrag) { CharSequence label, boolean canDrag) {
MarkerOptions marker = new MarkerOptions() MarkerOptions marker = new MarkerOptions()
.draggable(canDrag) .draggable(canDrag)
......
...@@ -24,9 +24,9 @@ ...@@ -24,9 +24,9 @@
android:supportsPictureInPicture="false" android:supportsPictureInPicture="false"
android:theme="@style/HABDroid.Light" android:theme="@style/HABDroid.Light"
android:supportsRtl="true" android:supportsRtl="true"
android:name=".core.OpenHABApplication"> android:name=".core.HabDroidApplication">
<activity <activity
android:name="org.openhab.habdroid.ui.OpenHABPreferencesActivity" android:name="org.openhab.habdroid.ui.PreferencesActivity"
android:label="@string/app_preferences_name"> android:label="@string/app_preferences_name">
<intent-filter> <intent-filter>
<action android:name="android.intent.action.APPLICATION_PREFERENCES" /> <action android:name="android.intent.action.APPLICATION_PREFERENCES" />
...@@ -34,13 +34,13 @@ ...@@ -34,13 +34,13 @@
</intent-filter> </intent-filter>
<meta-data <meta-data
android:name="android.support.PARENT_ACTIVITY" android:name="android.support.PARENT_ACTIVITY"
android:value="org.openhab.habdroid.ui.OpenHABMainActivity" /> android:value="org.openhab.habdroid.ui.MainActivity" />
</activity> </activity>
<activity <activity
android:name="org.openhab.habdroid.ui.AboutActivity" android:name="org.openhab.habdroid.ui.AboutActivity"
android:label="@string/about_title"/> android:label="@string/about_title"/>
<activity <activity
android:name="org.openhab.habdroid.ui.OpenHABMainActivity" android:name="org.openhab.habdroid.ui.MainActivity"
android:label="@string/app_name" android:label="@string/app_name"
android:launchMode="singleTop"> android:launchMode="singleTop">
<!-- for Nougat --> <!-- for Nougat -->
...@@ -69,7 +69,7 @@ ...@@ -69,7 +69,7 @@
</intent-filter> </intent-filter>
</activity> </activity>
<activity <activity
android:name="org.openhab.habdroid.ui.OpenHABWriteTagActivity" android:name="org.openhab.habdroid.ui.WriteTagActivity"
android:label="@string/title_activity_openhabwritetag" /> android:label="@string/title_activity_openhabwritetag" />
<activity android:name="org.openhab.habdroid.ui.IntroActivity" <activity android:name="org.openhab.habdroid.ui.IntroActivity"
android:label="@string/app_intro"/> android:label="@string/app_intro"/>
...@@ -77,7 +77,7 @@ ...@@ -77,7 +77,7 @@
android:theme="@style/Theme.AppCompat.Translucent" android:theme="@style/Theme.AppCompat.Translucent"
android:excludeFromRecents="true" /> android:excludeFromRecents="true" />
<service <service
android:name=".core.OpenHABVoiceService" android:name=".core.VoiceService"
android:exported="false" /> android:exported="false" />
<receiver <receiver
......
...@@ -53,7 +53,7 @@ public class MemorizingActivity extends Activity ...@@ -53,7 +53,7 @@ public class MemorizingActivity extends Activity
@Override @Override
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
mThemedContext = new ContextThemeWrapper(this, Util.getActivityThemeID(this)); mThemedContext = new ContextThemeWrapper(this, Util.getActivityThemeId(this));
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
TypedValue typedValue = new TypedValue(); TypedValue typedValue = new TypedValue();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment