Commit 45351148 authored by kastner's avatar kastner

Reformated and linted all code.

parent 658e7704
......@@ -9,13 +9,13 @@ import android.view.ViewGroup;
/**
* Created by zpw1998 on 6/17/15.
*/
public class ActivityBarFragment extends Fragment{
public class ActivityBarFragment extends Fragment {
@Override
public android.view.View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
Bundle savedInstanceState) {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.activity_bottom, container, false);
}
}
......@@ -34,7 +34,6 @@ import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.LinearLayout;
......@@ -51,7 +50,6 @@ import com.google.android.gms.maps.GoogleMap.OnCameraChangeListener;
import com.google.android.gms.maps.GoogleMap.OnInfoWindowClickListener;
import com.google.android.gms.maps.GoogleMap.OnMarkerClickListener;
import com.google.android.gms.maps.MapFragment;
import com.google.android.gms.maps.UiSettings;
import com.google.android.gms.maps.model.BitmapDescriptor;
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
import com.google.android.gms.maps.model.CameraPosition;
......@@ -129,11 +127,9 @@ import static edu.umd.umiacs.newsstand.NewsStandConstants.MAP_LON_RIGHT;
import static edu.umd.umiacs.newsstand.NewsStandConstants.MAX_CACHE_SECONDS;
import static edu.umd.umiacs.newsstand.NewsStandConstants.ONE_HAND_MODE_KEY;
import static edu.umd.umiacs.newsstand.NewsStandConstants.QUERY_RECORDS_FILENAME;
import static edu.umd.umiacs.newsstand.NewsStandConstants.SAMPLE_SESSION_FILENAME;
import static edu.umd.umiacs.newsstand.NewsStandConstants.SEARCH_KEY;
import static edu.umd.umiacs.newsstand.NewsStandConstants.TEXT_MARKER_SIZE;
import static edu.umd.umiacs.newsstand.NewsStandConstants.TITLE;
import static edu.umd.umiacs.newsstand.NewsStandConstants.TRAINING_SESSION_FILENAME;
import static edu.umd.umiacs.newsstand.NewsStandConstants.TWITTERSTAND;
public class MainActivity extends Activity implements OnCameraChangeListener, OnClickListener,
......@@ -239,7 +235,7 @@ public class MainActivity extends Activity implements OnCameraChangeListener, On
//Accelerometer
private SensorManager mSensorManager;
private Sensor mAccelerometer;
boolean mSensorInitialized;
private boolean mSensorInitialized;
//Grid
private DeviceGrid portraitGrid;
......@@ -250,7 +246,7 @@ public class MainActivity extends Activity implements OnCameraChangeListener, On
@Override
public boolean onCreateOptionsMenu(Menu menu) {
//Inflate options menu from XML
//Inflate options menu from XML
getMenuInflater().inflate(R.menu.activity_main, menu);
mMenu = menu;
......@@ -265,15 +261,13 @@ public class MainActivity extends Activity implements OnCameraChangeListener, On
/**
* This method check mobile is connected to network.
*
* @param context
* @return true if connected otherwise false.
*/
public static boolean isNetworkAvailable(Context context) {
private static boolean isNetworkAvailable(Context context) {
ConnectivityManager conMan = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
if(conMan.getActiveNetworkInfo() != null && conMan.getActiveNetworkInfo().isConnected())
return true;
else
return false;
return conMan.getActiveNetworkInfo() != null && conMan.getActiveNetworkInfo().isConnected();
}
// ================================================================================
......@@ -306,8 +300,8 @@ public class MainActivity extends Activity implements OnCameraChangeListener, On
setupTopBarItems();
setupKeen();
if(!isNetworkAvailable(this)) {
Toast.makeText(this,"No Internet connection",Toast.LENGTH_LONG).show();
if (!isNetworkAvailable(this)) {
Toast.makeText(this, "No Internet connection", Toast.LENGTH_LONG).show();
finish(); //Calling this method to close this activity when internet is not available.
}
}
......@@ -324,7 +318,7 @@ public class MainActivity extends Activity implements OnCameraChangeListener, On
super.onPause();
}
public void saveGlobalsToFiles() {
private void saveGlobalsToFiles() {
NewsStandApplication applicationState = ((NewsStandApplication) getApplicationContext());
FileOutputStream fosAll = null, fosLang = null, fosFeed = null, fosCountry = null;
ObjectOutputStream oosAll = null, oosLang = null, oosFeed = null, oosCountry = null;
......@@ -520,7 +514,7 @@ public class MainActivity extends Activity implements OnCameraChangeListener, On
switch (clickedView.getId()) {
//case R.id.nbutton:
// nButtonClicked();
// nButtonClicked();
case R.id.homeLinearLayout:
//Log.i(TAG, "Home Item Clicked");
homeItemClicked();
......@@ -577,20 +571,18 @@ public class MainActivity extends Activity implements OnCameraChangeListener, On
return;
case R.id.layoutInfo:
//Log.i(TAG, "HIT");
if(mHandMode == 3 || mHandMode == 2|| mHandMode == 0) {
if (mHandMode == 3 || mHandMode == 2 || mHandMode == 0) {
aboutItemClicked();
}
else{
} else {
topStoriesItemClicked();
}
return;
case R.id.layoutTopStories:
//Log.i(TAG, "HIT");
if(mHandMode == 3 || mHandMode == 2 || mHandMode == 0) {
if (mHandMode == 3 || mHandMode == 2 || mHandMode == 0) {
topStoriesItemClicked();
setUpMapIfNeeded();
}
else{
} else {
aboutItemClicked();
}
return;
......@@ -791,7 +783,7 @@ public class MainActivity extends Activity implements OnCameraChangeListener, On
alert.show();
}
public void modeItemClicked() {
private void modeItemClicked() {
FragmentManager manager = getFragmentManager();
ModeAlertDialogFragment modeAlert = new ModeAlertDialogFragment();
......@@ -1008,22 +1000,20 @@ public class MainActivity extends Activity implements OnCameraChangeListener, On
mZoomOutButton = (ImageButton) findViewById(R.id.zoomOutButton);
//mnButton = (Button)findViewById(R.id.nbutton);
mRefreshButton = (ImageButton) findViewById(R.id.refreshButton);
// mModeButton = (ImageButton) findViewById(R.id.modeInvis);
// mModeButton = (ImageButton) findViewById(R.id.modeInvis);
//mSourcesButton = (ImageButton) findViewById(R.id.sourcesInvis);
// mInfoButton = (ImageButton) findViewById(R.id.infoInvis);
// mInfoButton = (ImageButton) findViewById(R.id.infoInvis);
//mTopStoriesButton = (ImageButton) findViewById(R.id.topStoriesInvis);
// mSettingsButton = (ImageButton) findViewById(R.id.settingsInvis);
// mSettingsButton = (ImageButton) findViewById(R.id.settingsInvis);
//mSearchButton = (ImageButton) findViewById(R.id.searchInvis);
// mModeButton.setOnClickListener(this);
// mModeButton.setOnClickListener(this);
//mSourcesButton.setOnClickListener(this);
//mInfoButton.setOnClickListener(this);
//mTopStoriesButton.setOnClickListener(this);
//mSettingsButton.setOnClickListener(this);
// mSearchButton.setOnClickListener(this);
// mSearchButton.setOnClickListener(this);
mZoomInButton.setOnClickListener(this);
mZoomOutButton.setOnClickListener(this);
mRefreshButton.setOnClickListener(this);
......@@ -1196,8 +1186,6 @@ public class MainActivity extends Activity implements OnCameraChangeListener, On
android.widget.TextView rightText = (android.widget.TextView) findViewById(R.id.BottomTopStories);
if (mHandMode == 3) { // Neutral
leftPic.setImageResource(R.drawable.info);
rightPic.setImageResource(R.drawable.rss);
......@@ -1363,7 +1351,6 @@ public class MainActivity extends Activity implements OnCameraChangeListener, On
}
private void sourceCancelButtonClicked() {
NewsStandApplication applicationState = ((NewsStandApplication) getApplicationContext());
if (mSelectedSourceType == SourceType.FEED_SOURCE) {
......@@ -1778,7 +1765,7 @@ public class MainActivity extends Activity implements OnCameraChangeListener, On
return topicBitmapDescriptor;
}
public void gridMarkersDidComplete(DeviceGridCellMarker deviceGridCellMarker) {
private void gridMarkersDidComplete(DeviceGridCellMarker deviceGridCellMarker) {
if (retrievedCurrentWindow)
return;
......@@ -1930,7 +1917,7 @@ public class MainActivity extends Activity implements OnCameraChangeListener, On
Paint paint = new Paint();
Rect markerBoundingRegion = getRectForMarker(markerName,
new LatLng(currentMapMarker.getLatitude(),currentMapMarker.getLongitude()), paint);
new LatLng(currentMapMarker.getLatitude(), currentMapMarker.getLongitude()), paint);
float measuredText = paint.measureText(markerName);
Rect textRect = new Rect();
......@@ -2088,9 +2075,9 @@ public class MainActivity extends Activity implements OnCameraChangeListener, On
}
}
private Map<String, Object> topicRatio (ArrayList<MapMarker> markers) {
private Map<String, Object> topicRatio(ArrayList<MapMarker> markers) {
Map<String, Object> ratiosMap = new HashMap<String, Object>();
double numGeneral=0, numBusiness=0, numEntertainment=0, numHealth=0, numSciTech=0, numSports = 0, numInvalid=0;
double numGeneral = 0, numBusiness = 0, numEntertainment = 0, numHealth = 0, numSciTech = 0, numSports = 0, numInvalid = 0;
double numElms = markers.size();
for (MapMarker mapMarker : markers) {
......@@ -2112,13 +2099,13 @@ public class MainActivity extends Activity implements OnCameraChangeListener, On
numInvalid++;
}
ratiosMap.put("%general", numGeneral/numElms);
ratiosMap.put("%business", numBusiness/numElms);
ratiosMap.put("%entertainment", numEntertainment/numElms);
ratiosMap.put("%health", numHealth/numElms);
ratiosMap.put("%scitech", numSciTech/numElms);
ratiosMap.put("%sports", numSports/numElms);
ratiosMap.put("%invalid", numInvalid/numElms);
ratiosMap.put("%general", numGeneral / numElms);
ratiosMap.put("%business", numBusiness / numElms);
ratiosMap.put("%entertainment", numEntertainment / numElms);
ratiosMap.put("%health", numHealth / numElms);
ratiosMap.put("%scitech", numSciTech / numElms);
ratiosMap.put("%sports", numSports / numElms);
ratiosMap.put("%invalid", numInvalid / numElms);
return ratiosMap;
}
......@@ -2381,10 +2368,10 @@ public class MainActivity extends Activity implements OnCameraChangeListener, On
ArrayList<Source> mCountrySources = new ArrayList<Source>();
ArrayList<String> holdCountryNames = new ArrayList<String>();
for(Iterator<Source> sourceIterator = feedSources.iterator(); sourceIterator.hasNext();){
for (Iterator<Source> sourceIterator = feedSources.iterator(); sourceIterator.hasNext(); ) {
Source source = sourceIterator.next();
String item = source.getCountryCode();
if(!holdCountryNames.contains(item)){
if (!holdCountryNames.contains(item)) {
holdCountryNames.add(item);
mCountrySources.add(source);
}
......@@ -2445,7 +2432,7 @@ public class MainActivity extends Activity implements OnCameraChangeListener, On
refreshMap();
updateSearchKeyword();
updateSourceText();
} else {
} else {
/* mSearchKeyTextView.setAlpha(0.0f);
mSourceTextView.setAlpha(0.0f);
Timer timer = new Timer();
......@@ -2653,11 +2640,10 @@ public class MainActivity extends Activity implements OnCameraChangeListener, On
Fragment mapCheck = getFragmentManager().findFragmentById(R.id.miniMap);
//if(mapCheck. )
lat_low = y2lat(lowerLeftY - 180.0 );//- 180.0
lat_high = y2lat(upperRightY - 180.0 );//- 180.0
lon_low = lowerLeftX - 180.0 ;//- 180.0
lon_high = upperRightX - 180.0;//- 180.0
lat_low = y2lat(lowerLeftY - 180.0);//- 180.0
lat_high = y2lat(upperRightY - 180.0);//- 180.0
lon_low = lowerLeftX - 180.0;//- 180.0
lon_high = upperRightX - 180.0;//- 180.0
String markersURL = "";
......
......@@ -13,21 +13,23 @@ public enum MapLayers {
BRANDS("Brands");
public static final List<String> LAYER_NAMES;
static {
List<String> names = new ArrayList<>(MapLayers.values().length);
for(MapLayers s : MapLayers.values()){
for (MapLayers s : MapLayers.values()) {
names.add(s.toString());
}
LAYER_NAMES = Collections.unmodifiableList(names);
}
private String name;
MapLayers(String name){
this.name=name;
MapLayers(String name) {
this.name = name;
}
@Override
public String toString(){
public String toString() {
return this.name;
}
}
\ No newline at end of file
......@@ -73,7 +73,7 @@ public class NewsStandApplication extends Application {
this.mLanguageSources = languageSources;
}
public static Context getContext(){
public static Context getContext() {
return mContext;
}
......
package edu.umd.umiacs.newsstand;
public class NewsStandConstants {
private NewsStandConstants(){}
private NewsStandConstants() {
}
public static final String GENERAL_PREFS = "GeneralPrefsFile";
public static final String ALL_SOURCES_FILENAME = "all_sources_file";
......@@ -43,12 +44,12 @@ public class NewsStandConstants {
public static final int TIMEOUT_MILLISECONDS = 4000;
// public static String[] LAYER_STRINGS = new String[]{
// "Icon",
// "Disease",
// "Keyword",
// "Location",
// "People",
// "Brands"
// };
// public static String[] LAYER_STRINGS = new String[]{
// "Icon",
// "Disease",
// "Keyword",
// "Location",
// "People",
// "Brands"
// };
}
\ No newline at end of file
package edu.umd.umiacs.newsstand;
import android.content.res.Resources;
import android.util.Log;
import java.util.ArrayList;
......@@ -13,16 +12,18 @@ public enum StandMode {
PHOTOSTAND(NewsStandApplication.getContext().getString(R.string.photostand_mode));
public static final List<String> MODE_NAMES;
static {
Log.i(StandMode.class.toString(), "Called static init");
List<String> names = new ArrayList<>(StandMode.values().length);
for(StandMode s : StandMode.values()){
for (StandMode s : StandMode.values()) {
names.add(s.toString());
}
MODE_NAMES = Collections.unmodifiableList(names);
}
private final String name;
StandMode(String name) {
this.name = name;
}
......
......@@ -22,7 +22,7 @@ import static edu.umd.umiacs.newsstand.NewsStandConstants.TITLE;
*/
public class AboutDialogFragment extends DialogFragment {
DialogInterface.OnClickListener moreInfoListener = new DialogInterface.OnClickListener() {
private DialogInterface.OnClickListener moreInfoListener = new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Intent intent = new Intent(getActivity(), WebViewActivity.class);
......@@ -45,7 +45,7 @@ public class AboutDialogFragment extends DialogFragment {
try {
PackageInfo pInfo = getActivity().getPackageManager().getPackageInfo(getActivity().getPackageName(), 0);
version = "Version " + pInfo.versionName;
} catch (PackageManager.NameNotFoundException e) {
} catch (PackageManager.NameNotFoundException ignored) {
}
......@@ -60,9 +60,8 @@ public class AboutDialogFragment extends DialogFragment {
builder.setNegativeButton("More Info", moreInfoListener);
/** Creating the alert dialog window using the builder class */
AlertDialog dialog = builder.create();
/** Return the alert dialog window */
return dialog;
return builder.create();
}
}
......@@ -18,8 +18,6 @@ public class DeviceGrid {
static final float[] gridDivision = {0.005f, 0.01f, 0.05f, 0.75f, 0.1f, 0.25f, 0.5f, 1.0f, 2.0f, 4.0f, 8.0f, 10.0f,
12.0f, 15.0f, 18.0f, 20.0f, 24.0f, 30.0f, 36.0f, 40.0f, 45.0f, 60.0f, 72.0f, 90.0f, 120.0f,
180.0f, 360.0f};
private float xDiv;
private float yDiv;
public DeviceGrid(PointF bounds) {
mBounds = bounds;
......@@ -27,15 +25,15 @@ public class DeviceGrid {
}
private void createGrid() {
for (int i = 0; i < gridDivision.length; i++)
if (mBounds.x <= gridDivision[i]) {
xDiv = gridDivision[i];
for (float aGridDivision : gridDivision)
if (mBounds.x <= aGridDivision) {
float xDiv = aGridDivision;
break;
}
for (int i = 0; i < gridDivision.length; i++) {
if (mBounds.y <= gridDivision[i]) {
yDiv = gridDivision[i];
for (float aGridDivision : gridDivision) {
if (mBounds.y <= aGridDivision) {
float yDiv = aGridDivision;
break;
}
}
......@@ -43,27 +41,27 @@ public class DeviceGrid {
public ArrayList<DeviceGridCell> getGridCellsForWindowAndZoom(PointF lowerLeftCorner, PointF upperRightCorner,
PointF windowBounds) {
ArrayList<DeviceGridCell> gridCells = new ArrayList<DeviceGridCell>();
ArrayList<DeviceGridCell> gridCells = new ArrayList<>();
float currentXDiv = 360.0f;
float currentYDiv = 360.0f;
for (int i = 0; i < gridDivision.length; i++)
if (windowBounds.x <= gridDivision[i]) {
currentXDiv = gridDivision[i];
for (float aGridDivision1 : gridDivision)
if (windowBounds.x <= aGridDivision1) {
currentXDiv = aGridDivision1;
break;
}
for (int i = 0; i < gridDivision.length; i++)
if (windowBounds.y <= gridDivision[i]) {
currentYDiv = gridDivision[i];
for (float aGridDivision : gridDivision)
if (windowBounds.y <= aGridDivision) {
currentYDiv = aGridDivision;
break;
}
//Log.i(TAG, "Xdiv: " + xDiv + " ydiv: " + yDiv);
int numColumns = (int) Math.round((360000.0f / (currentXDiv * 1000.0f)));
int numRows = (int) Math.round((360000.0f / (currentYDiv * 1000.0f)));
int numColumns = Math.round((360000.0f / (currentXDiv * 1000.0f)));
int numRows = Math.round((360000.0f / (currentYDiv * 1000.0f)));
// Calculate lowerLeftCorner Grid cell
DeviceGridCell lowerLeftCornerGridCell = null;
......@@ -129,27 +127,27 @@ public class DeviceGrid {
}
public ArrayList<PolylineOptions> getGridPolylines(PointF windowBounds) {
ArrayList<PolylineOptions> polylines = new ArrayList<PolylineOptions>();
ArrayList<PolylineOptions> polylines = new ArrayList<>();
float currentXDiv = 360.0f;
float currentYDiv = 360.0f;
for (int i = 0; i < gridDivision.length; i++)
if (windowBounds.x <= gridDivision[i]) {
currentXDiv = gridDivision[i];
for (float aGridDivision1 : gridDivision)
if (windowBounds.x <= aGridDivision1) {
currentXDiv = aGridDivision1;
break;
}
for (int i = 0; i < gridDivision.length; i++)
if (windowBounds.y <= gridDivision[i]) {
currentYDiv = gridDivision[i];
for (float aGridDivision : gridDivision)
if (windowBounds.y <= aGridDivision) {
currentYDiv = aGridDivision;
break;
}
//Log.i(TAG, "windowbounds " + windowBounds.x + " windowbounds y " + windowBounds.y + "xdiv: " + currentXDiv + " ydiv: " + currentYDiv);
int numColumns = (int) Math.round((360000.0f / (currentXDiv * 1000.0f)));
int numRows = (int) Math.round((360000.0f / (currentYDiv * 1000.0f)));
int numColumns = Math.round((360000.0f / (currentXDiv * 1000.0f)));
int numRows = Math.round((360000.0f / (currentYDiv * 1000.0f)));
for (int i = 0; i < numColumns; i++) {
float currentColVal = i * currentXDiv;
......
......@@ -9,7 +9,7 @@ public class DeviceGridCell {
protected double upperRightX;
protected double upperRightY;
public boolean showOnScreen = true;
private boolean showOnScreen = true;
public static double EPSILON = 5.96e-08;
......@@ -77,19 +77,16 @@ public class DeviceGridCell {
if (obj == this)
return true;
//if (!(obj instanceof DeviceGridCell) || !(obj instanceof DeviceGridCellMarker))
// return false;
// return false;
DeviceGridCell otherGridCell = (DeviceGridCell) obj;
// Modify numbers so 0 can not be in denominator (or numerator)
if (Math.abs((lowerLeftX + 1.0) / (otherGridCell.getLowerLeftX() + 1.0) - 1) < EPSILON &&
return Math.abs((lowerLeftX + 1.0) / (otherGridCell.getLowerLeftX() + 1.0) - 1) < EPSILON &&
Math.abs((lowerLeftY + 1.0) / (otherGridCell.getLowerLeftY() + 1.0) - 1) < EPSILON &&
Math.abs((upperRightX + 1.0) / (otherGridCell.getUpperRightX() + 1.0) - 1) < EPSILON &&
Math.abs((upperRightY + 1.0) / (otherGridCell.getUpperRightY() + 1.0) - 1) < EPSILON) {
return true;
}
Math.abs((upperRightY + 1.0) / (otherGridCell.getUpperRightY() + 1.0) - 1) < EPSILON;
return false;
}
@Override
......@@ -98,24 +95,13 @@ public class DeviceGridCell {
}
public boolean isSameRow(DeviceGridCell otherGridCell) {
if (otherGridCell == null)
return false;
if (Math.abs((upperRightY + 1.0) / (otherGridCell.getUpperRightY() + 1.0) - 1) < EPSILON)
return true;
return otherGridCell != null && Math.abs((upperRightY + 1.0) / (otherGridCell.getUpperRightY() + 1.0) - 1) < EPSILON;
return false;
}
public boolean isSameColumn(DeviceGridCell otherGridCell) {
if (otherGridCell == null) {
return false;