Skip to content

Commit

Permalink
graph grid refactoring and improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
VREMSoftwareDevelopment committed Jan 14, 2017
1 parent c81c106 commit e1c04cf
Show file tree
Hide file tree
Showing 17 changed files with 166 additions and 79 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -8,3 +8,4 @@ build
coverage
libs
release
*IntegrationTest.java
6 changes: 3 additions & 3 deletions 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
15 changes: 10 additions & 5 deletions app/src/main/java/com/vrem/wifianalyzer/Configuration.java
Expand Up @@ -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<WiFiChannel, WiFiChannel> wiFiChannelPair;

public Configuration(boolean largeScreen, int size) {
public Configuration(boolean largeScreen) {
this.largeScreen = largeScreen;
this.size = size;
setSize(SIZE_MAX);
setWiFiChannelPair(WiFiChannels.UNKNOWN);
}

Expand All @@ -50,6 +51,10 @@ public void setWiFiChannelPair(@NonNull Pair<WiFiChannel, WiFiChannel> wiFiChann
}

public boolean isSizeAvailable() {
return size == FOUR_KB;
return size == SIZE_MAX;
}

public void setSize(int size) {
this.size = size;
}
}
16 changes: 1 addition & 15 deletions app/src/main/java/com/vrem/wifianalyzer/MainActivity.java
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/com/vrem/wifianalyzer/MainContext.java
Expand Up @@ -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);
Expand Down
14 changes: 13 additions & 1 deletion app/src/main/java/com/vrem/wifianalyzer/about/AboutActivity.java
Expand Up @@ -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
Expand Down Expand Up @@ -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);
}

Expand Down
Expand Up @@ -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<WiFiChannel, WiFiChannel> wiFiChannelPair;

Expand All @@ -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;
}
}
Expand Down
Expand Up @@ -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<NavigationItem> navigationItems = new ArrayList<>();
private final Configuration configuration;
private final Context context;
Expand Down
Expand Up @@ -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;
Expand All @@ -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<WiFiChannel, WiFiChannel> wiFiChannelPair;
private GraphViewWrapper graphViewWrapper;
Expand Down Expand Up @@ -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)
};
}

Expand All @@ -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) {
Expand All @@ -139,18 +137,19 @@ 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;
int maxX = minX + (graphViewWrapper.getViewportCntX() * WiFiChannels.FREQUENCY_SPREAD);
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<DataPoint> series = new TitleLineGraphSeries<>(dataPoints);
Expand Down
Expand Up @@ -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;
Expand All @@ -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;
}
}
Expand Down
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -92,7 +90,7 @@ public GraphView getGraphView() {
}

private int getNumX() {
return NUM_X;
return NUM_X_TIME;
}

void setGraphViewWrapper(@NonNull GraphViewWrapper graphViewWrapper) {
Expand All @@ -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<DataPoint> 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);
Expand Down
@@ -0,0 +1,39 @@
/*
* WiFi Analyzer
* Copyright (C) 2017 VREM Software Development <VREMSoftwareDevelopment@gmail.com>
*
* 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 <http://www.gnu.org/licenses/>
*/

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;
}
Expand Up @@ -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;
Expand Down

0 comments on commit e1c04cf

Please sign in to comment.