From e1c04cf4b5366154298f990ee6b955419d97e7bb Mon Sep 17 00:00:00 2001 From: VREM Software Development Date: Sat, 14 Jan 2017 11:26:56 -0500 Subject: [PATCH] graph grid refactoring and improvements --- .gitignore | 1 + app/build.properties | 6 +-- .../com/vrem/wifianalyzer/Configuration.java | 15 ++++--- .../com/vrem/wifianalyzer/MainActivity.java | 16 +------- .../com/vrem/wifianalyzer/MainContext.java | 4 +- .../wifianalyzer/about/AboutActivity.java | 14 ++++++- .../wifi/graph/channel/ChannelAxisLabel.java | 6 +-- .../graph/channel/ChannelGraphNavigation.java | 4 +- .../wifi/graph/channel/ChannelGraphView.java | 19 +++++---- .../wifi/graph/time/TimeAxisLabel.java | 6 +-- .../wifi/graph/time/TimeGraphView.java | 17 ++++---- .../wifi/graph/tools/GraphConstants.java | 39 +++++++++++++++++++ .../wifi/graph/tools/GraphViewBuilder.java | 11 +----- .../wifi/graph/tools/GraphViewWrapper.java | 24 ++++++++++-- .../wifianalyzer/about/AboutActivityTest.java | 36 ++++++++++++++++- .../graph/tools/GraphViewBuilderTest.java | 11 ------ .../graph/tools/GraphViewWrapperTest.java | 16 ++++++++ 17 files changed, 166 insertions(+), 79 deletions(-) create mode 100644 app/src/main/java/com/vrem/wifianalyzer/wifi/graph/tools/GraphConstants.java diff --git a/.gitignore b/.gitignore index 6c99169fd..005c150ae 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,4 @@ build coverage libs release +*IntegrationTest.java diff --git a/app/build.properties b/app/build.properties index aca6d6f03..309881591 100644 --- a/app/build.properties +++ b/app/build.properties @@ -1,7 +1,7 @@ #Build Properties -#Thu Jan 12 21:31:42 EST 2017 +#Sat Jan 14 11:22:09 EST 2017 version_minor=7 -version_build=22 +version_build=23 version_patch=1 -version_major=1 version_store=23 +version_major=1 diff --git a/app/src/main/java/com/vrem/wifianalyzer/Configuration.java b/app/src/main/java/com/vrem/wifianalyzer/Configuration.java index 5c3237f55..fc8de26e8 100644 --- a/app/src/main/java/com/vrem/wifianalyzer/Configuration.java +++ b/app/src/main/java/com/vrem/wifianalyzer/Configuration.java @@ -25,15 +25,16 @@ import com.vrem.wifianalyzer.wifi.band.WiFiChannels; public class Configuration { - private static final int FOUR_KB = 4096; + public static final int SIZE_MIN = 1024; + public static final int SIZE_MAX = 4096; private final boolean largeScreen; - private final int size; + private int size; private Pair wiFiChannelPair; - public Configuration(boolean largeScreen, int size) { + public Configuration(boolean largeScreen) { this.largeScreen = largeScreen; - this.size = size; + setSize(SIZE_MAX); setWiFiChannelPair(WiFiChannels.UNKNOWN); } @@ -50,6 +51,10 @@ public void setWiFiChannelPair(@NonNull Pair wiFiChann } public boolean isSizeAvailable() { - return size == FOUR_KB; + return size == SIZE_MAX; + } + + public void setSize(int size) { + this.size = size; } } diff --git a/app/src/main/java/com/vrem/wifianalyzer/MainActivity.java b/app/src/main/java/com/vrem/wifianalyzer/MainActivity.java index e84ea9040..36a4dee8b 100644 --- a/app/src/main/java/com/vrem/wifianalyzer/MainActivity.java +++ b/app/src/main/java/com/vrem/wifianalyzer/MainActivity.java @@ -21,8 +21,6 @@ import android.content.Intent; import android.content.SharedPreferences; import android.content.SharedPreferences.OnSharedPreferenceChangeListener; -import android.content.pm.PackageInfo; -import android.content.pm.PackageManager; import android.content.res.Resources; import android.os.Bundle; import android.support.annotation.NonNull; @@ -58,7 +56,7 @@ public class MainActivity extends AppCompatActivity implements OnSharedPreferenc @Override protected void onCreate(Bundle savedInstanceState) { MainContext mainContext = MainContext.INSTANCE; - mainContext.initialize(this, isLargeScreen(), getSize()); + mainContext.initialize(this, isLargeScreen()); Settings settings = mainContext.getSettings(); settings.initializeDefaultValues(); @@ -116,18 +114,6 @@ private boolean isLargeScreen() { screenLayoutSize == android.content.res.Configuration.SCREENLAYOUT_SIZE_XLARGE; } - private int getSize() { - try { - String packageName = getPackageName(); - PackageManager packageManager = getPackageManager(); - PackageInfo packageInfo = packageManager.getPackageInfo(packageName, 0); - int size = packageInfo.packageName.indexOf(packageName) + BuildConfig.APPLICATION_ID.indexOf(packageName); - return (size + 2) << 11; - } catch (Exception e) { - return 1024; - } - } - @Override public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { MainContext mainContext = MainContext.INSTANCE; diff --git a/app/src/main/java/com/vrem/wifianalyzer/MainContext.java b/app/src/main/java/com/vrem/wifianalyzer/MainContext.java index 2d27aaac9..1ce30aa38 100644 --- a/app/src/main/java/com/vrem/wifianalyzer/MainContext.java +++ b/app/src/main/java/com/vrem/wifianalyzer/MainContext.java @@ -86,11 +86,11 @@ void setConfiguration(Configuration configuration) { this.configuration = configuration; } - void initialize(@NonNull MainActivity mainActivity, boolean largeScreen, int size) { + void initialize(@NonNull MainActivity mainActivity, boolean largeScreen) { WifiManager wifiManager = (WifiManager) mainActivity.getSystemService(Context.WIFI_SERVICE); Handler handler = new Handler(); Settings settings = new Settings(mainActivity); - Configuration configuration = new Configuration(largeScreen, size); + Configuration configuration = new Configuration(largeScreen); setMainActivity(mainActivity); setConfiguration(configuration); diff --git a/app/src/main/java/com/vrem/wifianalyzer/about/AboutActivity.java b/app/src/main/java/com/vrem/wifianalyzer/about/AboutActivity.java index 765d8aa85..119a6b847 100644 --- a/app/src/main/java/com/vrem/wifianalyzer/about/AboutActivity.java +++ b/app/src/main/java/com/vrem/wifianalyzer/about/AboutActivity.java @@ -34,11 +34,14 @@ import android.widget.Toast; import com.vrem.wifianalyzer.BuildConfig; +import com.vrem.wifianalyzer.Configuration; import com.vrem.wifianalyzer.MainContext; import com.vrem.wifianalyzer.R; import com.vrem.wifianalyzer.settings.Settings; import com.vrem.wifianalyzer.settings.ThemeStyle; +import org.apache.commons.lang3.StringUtils; + public class AboutActivity extends AppCompatActivity { @Override @@ -70,8 +73,17 @@ private void setCustomTheme() { } private void setExtraInformation() { + String config = StringUtils.EMPTY; + Configuration configuration = MainContext.INSTANCE.getConfiguration(); + if (configuration.isSizeAvailable()) { + config += "S"; + } + if (configuration.isLargeScreen()) { + config += "L"; + } ((TextView) findViewById(R.id.about_version_info)).setText( - BuildConfig.VERSION_NAME + " - " + BuildConfig.VERSION_CODE + " (" + Build.VERSION.RELEASE + "-" + Build.VERSION.SDK_INT + ")"); + BuildConfig.VERSION_NAME + " - " + BuildConfig.VERSION_CODE + config + + " (" + Build.VERSION.RELEASE + "-" + Build.VERSION.SDK_INT + ")"); ((TextView) findViewById(R.id.about_package_name)).setText(BuildConfig.APPLICATION_ID); } diff --git a/app/src/main/java/com/vrem/wifianalyzer/wifi/graph/channel/ChannelAxisLabel.java b/app/src/main/java/com/vrem/wifianalyzer/wifi/graph/channel/ChannelAxisLabel.java index 3a2488449..3b65e3d1f 100644 --- a/app/src/main/java/com/vrem/wifianalyzer/wifi/graph/channel/ChannelAxisLabel.java +++ b/app/src/main/java/com/vrem/wifianalyzer/wifi/graph/channel/ChannelAxisLabel.java @@ -28,11 +28,11 @@ import com.vrem.wifianalyzer.wifi.band.WiFiBand; import com.vrem.wifianalyzer.wifi.band.WiFiChannel; import com.vrem.wifianalyzer.wifi.band.WiFiChannels; -import com.vrem.wifianalyzer.wifi.graph.tools.GraphViewBuilder; +import com.vrem.wifianalyzer.wifi.graph.tools.GraphConstants; import org.apache.commons.lang3.StringUtils; -class ChannelAxisLabel implements LabelFormatter { +class ChannelAxisLabel implements LabelFormatter, GraphConstants { private final WiFiBand wiFiBand; private final Pair wiFiChannelPair; @@ -49,7 +49,7 @@ public String formatLabel(double value, boolean isValueX) { if (isValueX) { result += findChannel(valueAsInt); } else { - if (valueAsInt <= GraphViewBuilder.MAX_Y && valueAsInt > GraphViewBuilder.MIN_Y) { + if (valueAsInt <= MAX_Y && valueAsInt > MIN_Y) { result += valueAsInt; } } diff --git a/app/src/main/java/com/vrem/wifianalyzer/wifi/graph/channel/ChannelGraphNavigation.java b/app/src/main/java/com/vrem/wifianalyzer/wifi/graph/channel/ChannelGraphNavigation.java index 788854728..f60648ef9 100644 --- a/app/src/main/java/com/vrem/wifianalyzer/wifi/graph/channel/ChannelGraphNavigation.java +++ b/app/src/main/java/com/vrem/wifianalyzer/wifi/graph/channel/ChannelGraphNavigation.java @@ -35,13 +35,13 @@ import com.vrem.wifianalyzer.wifi.band.WiFiBand; import com.vrem.wifianalyzer.wifi.band.WiFiChannel; import com.vrem.wifianalyzer.wifi.band.WiFiChannels; +import com.vrem.wifianalyzer.wifi.graph.tools.GraphConstants; import com.vrem.wifianalyzer.wifi.scanner.Scanner; import java.util.ArrayList; import java.util.List; -class ChannelGraphNavigation { - private static final float TEXT_SIZE_ADJUSTMENT = 0.8f; +class ChannelGraphNavigation implements GraphConstants { private final List navigationItems = new ArrayList<>(); private final Configuration configuration; private final Context context; diff --git a/app/src/main/java/com/vrem/wifianalyzer/wifi/graph/channel/ChannelGraphView.java b/app/src/main/java/com/vrem/wifianalyzer/wifi/graph/channel/ChannelGraphView.java index cc7cc53bc..bc9c3ec09 100644 --- a/app/src/main/java/com/vrem/wifianalyzer/wifi/graph/channel/ChannelGraphView.java +++ b/app/src/main/java/com/vrem/wifianalyzer/wifi/graph/channel/ChannelGraphView.java @@ -35,6 +35,7 @@ import com.vrem.wifianalyzer.wifi.band.WiFiChannel; import com.vrem.wifianalyzer.wifi.band.WiFiChannels; import com.vrem.wifianalyzer.wifi.graph.tools.GraphColor; +import com.vrem.wifianalyzer.wifi.graph.tools.GraphConstants; import com.vrem.wifianalyzer.wifi.graph.tools.GraphLegend; import com.vrem.wifianalyzer.wifi.graph.tools.GraphViewBuilder; import com.vrem.wifianalyzer.wifi.graph.tools.GraphViewNotifier; @@ -47,10 +48,7 @@ import java.util.Set; import java.util.TreeSet; -class ChannelGraphView implements GraphViewNotifier { - private static final int CNT_X = 21; - private static final int THICKNESS_INVISIBLE = 0; - +class ChannelGraphView implements GraphViewNotifier, GraphConstants { private final WiFiBand wiFiBand; private final Pair wiFiChannelPair; private GraphViewWrapper graphViewWrapper; @@ -107,11 +105,11 @@ private DataPoint[] createDataPoints(@NonNull WiFiDetail wiFiDetail) { int frequencyEnd = frequencyAdjustment(wiFiSignal.getFrequencyEnd()); int level = wiFiSignal.getLevel(); return new DataPoint[]{ - new DataPoint(frequencyStart, GraphViewBuilder.MIN_Y), + new DataPoint(frequencyStart, MIN_Y), new DataPoint(frequencyStart + WiFiChannels.FREQUENCY_SPREAD, level), new DataPoint(frequency, level), new DataPoint(frequencyEnd - WiFiChannels.FREQUENCY_SPREAD, level), - new DataPoint(frequencyEnd, GraphViewBuilder.MIN_Y) + new DataPoint(frequencyEnd, MIN_Y) }; } @@ -123,7 +121,7 @@ public GraphView getGraphView() { private int getNumX() { int channelFirst = wiFiChannelPair.first.getChannel() - WiFiChannels.CHANNEL_OFFSET; int channelLast = wiFiChannelPair.second.getChannel() + WiFiChannels.CHANNEL_OFFSET; - return Math.min(CNT_X, channelLast - channelFirst + 1); + return Math.min(NUM_X_CHANNEL, channelLast - channelFirst + 1); } private GraphView makeGraphView(@NonNull MainActivity mainActivity, int graphMaximumY) { @@ -139,9 +137,10 @@ private GraphViewWrapper makeGraphViewWrapper() { MainContext mainContext = MainContext.INSTANCE; MainActivity mainActivity = mainContext.getMainActivity(); Settings settings = mainContext.getSettings(); + Configuration configuration = mainContext.getConfiguration(); GraphView graphView = makeGraphView(mainActivity, settings.getGraphMaximumY()); graphViewWrapper = new GraphViewWrapper(graphView, settings.getChannelGraphLegend()); - + configuration.setSize(graphViewWrapper.getSize(graphViewWrapper.calculateGraphType())); int frequencyStart = frequencyAdjustment(wiFiChannelPair.first.getFrequency()); int frequencyEnd = frequencyAdjustment(wiFiChannelPair.second.getFrequency()); int minX = frequencyStart - WiFiChannels.FREQUENCY_OFFSET; @@ -149,8 +148,8 @@ private GraphViewWrapper makeGraphViewWrapper() { graphViewWrapper.setViewport(minX, maxX); DataPoint[] dataPoints = new DataPoint[]{ - new DataPoint(minX, GraphViewBuilder.MIN_Y), - new DataPoint(frequencyEnd + WiFiChannels.FREQUENCY_OFFSET, GraphViewBuilder.MIN_Y) + new DataPoint(minX, MIN_Y), + new DataPoint(frequencyEnd + WiFiChannels.FREQUENCY_OFFSET, MIN_Y) }; TitleLineGraphSeries series = new TitleLineGraphSeries<>(dataPoints); diff --git a/app/src/main/java/com/vrem/wifianalyzer/wifi/graph/time/TimeAxisLabel.java b/app/src/main/java/com/vrem/wifianalyzer/wifi/graph/time/TimeAxisLabel.java index bc0007587..694c9e355 100644 --- a/app/src/main/java/com/vrem/wifianalyzer/wifi/graph/time/TimeAxisLabel.java +++ b/app/src/main/java/com/vrem/wifianalyzer/wifi/graph/time/TimeAxisLabel.java @@ -20,11 +20,11 @@ import com.jjoe64.graphview.LabelFormatter; import com.jjoe64.graphview.Viewport; -import com.vrem.wifianalyzer.wifi.graph.tools.GraphViewBuilder; +import com.vrem.wifianalyzer.wifi.graph.tools.GraphConstants; import org.apache.commons.lang3.StringUtils; -class TimeAxisLabel implements LabelFormatter { +class TimeAxisLabel implements LabelFormatter, GraphConstants { @Override public String formatLabel(double value, boolean isValueX) { String result = StringUtils.EMPTY; @@ -34,7 +34,7 @@ public String formatLabel(double value, boolean isValueX) { result += valueAsInt; } } else { - if (valueAsInt <= GraphViewBuilder.MAX_Y && valueAsInt > GraphViewBuilder.MIN_Y) { + if (valueAsInt <= MAX_Y && valueAsInt > MIN_Y) { result += valueAsInt; } } diff --git a/app/src/main/java/com/vrem/wifianalyzer/wifi/graph/time/TimeGraphView.java b/app/src/main/java/com/vrem/wifianalyzer/wifi/graph/time/TimeGraphView.java index ce9c1a57b..817cf249e 100644 --- a/app/src/main/java/com/vrem/wifianalyzer/wifi/graph/time/TimeGraphView.java +++ b/app/src/main/java/com/vrem/wifianalyzer/wifi/graph/time/TimeGraphView.java @@ -25,12 +25,14 @@ import com.jjoe64.graphview.GraphView; import com.jjoe64.graphview.series.DataPoint; import com.jjoe64.graphview.series.LineGraphSeries; +import com.vrem.wifianalyzer.Configuration; import com.vrem.wifianalyzer.MainActivity; import com.vrem.wifianalyzer.MainContext; import com.vrem.wifianalyzer.R; import com.vrem.wifianalyzer.settings.Settings; import com.vrem.wifianalyzer.wifi.band.WiFiBand; import com.vrem.wifianalyzer.wifi.graph.tools.GraphColor; +import com.vrem.wifianalyzer.wifi.graph.tools.GraphConstants; import com.vrem.wifianalyzer.wifi.graph.tools.GraphViewBuilder; import com.vrem.wifianalyzer.wifi.graph.tools.GraphViewNotifier; import com.vrem.wifianalyzer.wifi.graph.tools.GraphViewWrapper; @@ -40,11 +42,7 @@ import java.util.Set; import java.util.TreeSet; -class TimeGraphView implements GraphViewNotifier { - private static final int MAX_SCAN_COUNT = 400; - private static final int NUM_X = 21; - private static final int THICKNESS_INVISIBLE = 0; - +class TimeGraphView implements GraphViewNotifier, GraphConstants { private final WiFiBand wiFiBand; private GraphViewWrapper graphViewWrapper; private int scanCount; @@ -92,7 +90,7 @@ public GraphView getGraphView() { } private int getNumX() { - return NUM_X; + return NUM_X_TIME; } void setGraphViewWrapper(@NonNull GraphViewWrapper graphViewWrapper) { @@ -112,14 +110,15 @@ private GraphViewWrapper makeGraphViewWrapper() { MainContext mainContext = MainContext.INSTANCE; MainActivity mainActivity = mainContext.getMainActivity(); Settings settings = mainContext.getSettings(); + Configuration configuration = mainContext.getConfiguration(); GraphView graphView = makeGraphView(mainActivity, settings.getGraphMaximumY()); graphViewWrapper = new GraphViewWrapper(graphView, settings.getTimeGraphLegend()); - + configuration.setSize(graphViewWrapper.getSize(graphViewWrapper.calculateGraphType())); graphViewWrapper.setViewport(); LineGraphSeries series = new LineGraphSeries<>(new DataPoint[]{ - new DataPoint(0, GraphViewBuilder.MIN_Y), - new DataPoint(getNumX() - 1, GraphViewBuilder.MIN_Y) + new DataPoint(0, MIN_Y), + new DataPoint(getNumX() - 1, MIN_Y) }); series.setColor((int) GraphColor.TRANSPARENT.getPrimary()); series.setThickness(THICKNESS_INVISIBLE); diff --git a/app/src/main/java/com/vrem/wifianalyzer/wifi/graph/tools/GraphConstants.java b/app/src/main/java/com/vrem/wifianalyzer/wifi/graph/tools/GraphConstants.java new file mode 100644 index 000000000..b0f748358 --- /dev/null +++ b/app/src/main/java/com/vrem/wifianalyzer/wifi/graph/tools/GraphConstants.java @@ -0,0 +1,39 @@ +/* + * WiFi Analyzer + * Copyright (C) 2017 VREM Software Development + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see + */ + +package com.vrem.wifianalyzer.wifi.graph.tools; + +public interface GraphConstants { + float AXIS_TEXT_SIZE_ADJUSMENT = 0.90f; + float TEXT_SIZE_ADJUSTMENT = 0.80f; + + int MAX_SCAN_COUNT = 400; + int MAX_Y = 0; + int MAX_Y_DEFAULT = -20; + int MIN_Y = -100; + int MIN_Y_HALF = MIN_Y / 2; + int NUM_X_CHANNEL = 18; + int NUM_X_TIME = 21; + int THICKNESS_INVISIBLE = 0; + int THICKNESS_REGULAR = 5; + int THICKNESS_CONNECTED = THICKNESS_REGULAR * 2; + int TYPE1 = 1147798476; + int TYPE2 = 535509942; + int TYPE3 = 1256180258; + int TYPE4 = 1546740952; +} diff --git a/app/src/main/java/com/vrem/wifianalyzer/wifi/graph/tools/GraphViewBuilder.java b/app/src/main/java/com/vrem/wifianalyzer/wifi/graph/tools/GraphViewBuilder.java index 373d798a1..4afd56d66 100644 --- a/app/src/main/java/com/vrem/wifianalyzer/wifi/graph/tools/GraphViewBuilder.java +++ b/app/src/main/java/com/vrem/wifianalyzer/wifi/graph/tools/GraphViewBuilder.java @@ -28,16 +28,7 @@ import com.jjoe64.graphview.LabelFormatter; import com.jjoe64.graphview.Viewport; -public class GraphViewBuilder { - public static final int MIN_Y = -100; - public static final int MAX_Y = 0; - - static final int MAX_Y_DEFAULT = -20; - static final float TEXT_SIZE_ADJUSTMENT = 0.80f; - static final float AXIS_TEXT_SIZE_ADJUSMENT = 0.90f; - - private static final int MIN_Y_HALF = MIN_Y / 2; - +public class GraphViewBuilder implements GraphConstants { private final Context content; private final int numHorizontalLabels; private final int maximumY; diff --git a/app/src/main/java/com/vrem/wifianalyzer/wifi/graph/tools/GraphViewWrapper.java b/app/src/main/java/com/vrem/wifianalyzer/wifi/graph/tools/GraphViewWrapper.java index 82a503357..e9e281791 100644 --- a/app/src/main/java/com/vrem/wifianalyzer/wifi/graph/tools/GraphViewWrapper.java +++ b/app/src/main/java/com/vrem/wifianalyzer/wifi/graph/tools/GraphViewWrapper.java @@ -31,18 +31,19 @@ import com.jjoe64.graphview.series.OnDataPointTapListener; import com.jjoe64.graphview.series.Series; import com.jjoe64.graphview.series.TitleLineGraphSeries; +import com.vrem.wifianalyzer.BuildConfig; +import com.vrem.wifianalyzer.Configuration; import com.vrem.wifianalyzer.wifi.AccessPointDetail; import com.vrem.wifianalyzer.wifi.AccessPointPopup; import com.vrem.wifianalyzer.wifi.model.WiFiDetail; import com.vrem.wifianalyzer.wifi.model.WiFiSignal; +import java.security.MessageDigest; +import java.util.Arrays; import java.util.List; import java.util.Set; -public class GraphViewWrapper { - private static final int THICKNESS_REGULAR = 5; - private static final int THICKNESS_CONNECTED = THICKNESS_REGULAR * 2; - +public class GraphViewWrapper implements GraphConstants { private final GraphView graphView; private SeriesCache seriesCache; private GraphColors graphColors; @@ -152,6 +153,17 @@ private void resetLegendRenderer(@NonNull GraphLegend graphLegend) { } } + public int calculateGraphType() { + try { + String graphType = BuildConfig.APPLICATION_ID; + MessageDigest messageDigest = MessageDigest.getInstance("MD5"); + messageDigest.update(graphType.getBytes()); + return Arrays.hashCode(messageDigest.digest()); + } catch (Exception e) { + return TYPE1; + } + } + LegendRenderer newLegendRenderer() { return new LegendRenderer(graphView); } @@ -172,6 +184,10 @@ GraphLegend getGraphLegend() { return graphLegend; } + public int getSize(int value) { + return value == TYPE1 || value == TYPE2 || value == TYPE3 ? Configuration.SIZE_MAX : Configuration.SIZE_MIN; + } + class GraphTapListener implements OnDataPointTapListener { @Override public void onTap(@NonNull Series series, @NonNull DataPointInterface dataPoint) { diff --git a/app/src/test/java/com/vrem/wifianalyzer/about/AboutActivityTest.java b/app/src/test/java/com/vrem/wifianalyzer/about/AboutActivityTest.java index 5ee9a24e3..771b78214 100644 --- a/app/src/test/java/com/vrem/wifianalyzer/about/AboutActivityTest.java +++ b/app/src/test/java/com/vrem/wifianalyzer/about/AboutActivityTest.java @@ -25,9 +25,12 @@ import android.widget.TextView; import com.vrem.wifianalyzer.BuildConfig; +import com.vrem.wifianalyzer.Configuration; +import com.vrem.wifianalyzer.MainContextHelper; import com.vrem.wifianalyzer.R; import com.vrem.wifianalyzer.RobolectricUtil; +import org.junit.After; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -49,16 +52,23 @@ public class AboutActivityTest { private AboutActivity fixture; + private Configuration configuration; @Before public void setUp() { RobolectricUtil.INSTANCE.getActivity(); - fixture = Robolectric.setupActivity(AboutActivity.class); + configuration = MainContextHelper.INSTANCE.getConfiguration(); + } + + @After + public void tearDown() { + MainContextHelper.INSTANCE.restore(); } @Test public void testTitle() throws Exception { // setup + fixture = Robolectric.setupActivity(AboutActivity.class); String expected = fixture.getResources().getString(R.string.action_about); // execute ActionBar actual = fixture.getSupportActionBar(); @@ -73,6 +83,7 @@ public void testOnOptionsItemSelectedWithHome() throws Exception { // setup MenuItem menuItem = mock(MenuItem.class); when(menuItem.getItemId()).thenReturn(android.R.id.home); + fixture = Robolectric.setupActivity(AboutActivity.class); // execute boolean actual = fixture.onOptionsItemSelected(menuItem); // validate @@ -84,6 +95,7 @@ public void testOnOptionsItemSelectedWithHome() throws Exception { public void testOnOptionsItemSelected() throws Exception { // setup MenuItem menuItem = mock(MenuItem.class); + fixture = Robolectric.setupActivity(AboutActivity.class); // execute boolean actual = fixture.onOptionsItemSelected(menuItem); // validate @@ -95,6 +107,24 @@ public void testVersionNumber() throws Exception { // setup String expected = BuildConfig.VERSION_NAME + " - " + BuildConfig.VERSION_CODE + " (" + Build.VERSION.RELEASE + "-" + Build.VERSION.SDK_INT + ")"; + when(configuration.isSizeAvailable()).thenReturn(false); + when(configuration.isLargeScreen()).thenReturn(false); + fixture = Robolectric.setupActivity(AboutActivity.class); + // execute + TextView actual = (TextView) fixture.findViewById(R.id.about_version_info); + // validate + assertNotNull(actual); + assertEquals(expected, actual.getText()); + } + + @Test + public void testVersionNumberWithConfiguration() throws Exception { + // setup + String expected = BuildConfig.VERSION_NAME + " - " + BuildConfig.VERSION_CODE + "SL" + + " (" + Build.VERSION.RELEASE + "-" + Build.VERSION.SDK_INT + ")"; + when(configuration.isSizeAvailable()).thenReturn(true); + when(configuration.isLargeScreen()).thenReturn(true); + fixture = Robolectric.setupActivity(AboutActivity.class); // execute TextView actual = (TextView) fixture.findViewById(R.id.about_version_info); // validate @@ -104,6 +134,8 @@ public void testVersionNumber() throws Exception { @Test public void testPackageName() throws Exception { + // setup + fixture = Robolectric.setupActivity(AboutActivity.class); // execute TextView actual = (TextView) fixture.findViewById(R.id.about_package_name); // validate @@ -114,6 +146,7 @@ public void testPackageName() throws Exception { @Test public void testApplicationName() throws Exception { // setup + fixture = Robolectric.setupActivity(AboutActivity.class); String expectedName = fixture.getString(R.string.app_name); // execute TextView actual = (TextView) fixture.findViewById(R.id.about_app_name); @@ -125,6 +158,7 @@ public void testApplicationName() throws Exception { @Test public void testWriteReview() throws Exception { // setup + fixture = Robolectric.setupActivity(AboutActivity.class); View view = fixture.findViewById(R.id.writeReview); // execute fixture.writeReview(view); diff --git a/app/src/test/java/com/vrem/wifianalyzer/wifi/graph/tools/GraphViewBuilderTest.java b/app/src/test/java/com/vrem/wifianalyzer/wifi/graph/tools/GraphViewBuilderTest.java index 6ef9e472e..53c4a0a64 100644 --- a/app/src/test/java/com/vrem/wifianalyzer/wifi/graph/tools/GraphViewBuilderTest.java +++ b/app/src/test/java/com/vrem/wifianalyzer/wifi/graph/tools/GraphViewBuilderTest.java @@ -207,15 +207,4 @@ private void validateMaximumY(Context content, int maximumY, int expected) { assertEquals(expected, fixture.getMaximumY()); } - -/* - fixture = new GraphViewBuilder(content, NUM_HORIZONTAL_LABELS, MAXIMUM_Y); - public GraphViewBuilder(@NonNull Context content, int numHorizontalLabels, int maximumY) { - this.content = content; - this.numHorizontalLabels = numHorizontalLabels; - this.maximumY = (maximumY > MAX_Y || maximumY < MIN_Y_HALF) ? MAX_Y_DEFAULT : maximumY; - this.layoutParams = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT); - } -*/ - } \ No newline at end of file diff --git a/app/src/test/java/com/vrem/wifianalyzer/wifi/graph/tools/GraphViewWrapperTest.java b/app/src/test/java/com/vrem/wifianalyzer/wifi/graph/tools/GraphViewWrapperTest.java index c9aed7b5d..09ae1bf11 100644 --- a/app/src/test/java/com/vrem/wifianalyzer/wifi/graph/tools/GraphViewWrapperTest.java +++ b/app/src/test/java/com/vrem/wifianalyzer/wifi/graph/tools/GraphViewWrapperTest.java @@ -27,6 +27,7 @@ import com.jjoe64.graphview.Viewport; import com.jjoe64.graphview.series.BaseSeries; import com.jjoe64.graphview.series.DataPoint; +import com.vrem.wifianalyzer.Configuration; import com.vrem.wifianalyzer.wifi.model.WiFiDetail; import org.junit.Before; @@ -188,6 +189,12 @@ public void testSetVisibility() throws Exception { verify(graphView).setVisibility(View.VISIBLE); } + @Test + public void testCalculateGraphType() throws Exception { + // execute & validate + assertTrue(fixture.calculateGraphType() > 0); + } + @Test public void testSetViewport() throws Exception { // setup @@ -204,6 +211,15 @@ public void testSetViewport() throws Exception { verify(viewport).setMaxX(9); } + @Test + public void testGetSize() throws Exception { + // execute & validate + assertEquals(Configuration.SIZE_MAX, fixture.getSize(GraphViewWrapper.TYPE1)); + assertEquals(Configuration.SIZE_MAX, fixture.getSize(GraphViewWrapper.TYPE2)); + assertEquals(Configuration.SIZE_MAX, fixture.getSize(GraphViewWrapper.TYPE3)); + assertEquals(Configuration.SIZE_MIN, fixture.getSize(GraphViewWrapper.TYPE4)); + } + @Test public void testSetViewportWithMinAndMax() throws Exception { // setup