Skip to content

Commit

Permalink
Merge pull request #1409 from fossasia/development
Browse files Browse the repository at this point in the history
chore: merge dev into master
  • Loading branch information
CloudyPadmal authored Oct 5, 2018
2 parents 22557e6 + 62ff44b commit 5d99ff7
Show file tree
Hide file tree
Showing 21 changed files with 444 additions and 726 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# PSLab Android App

<a href="https://play.google.com/store/apps/details?id=io.pslab"><img alt="Get it on Google Play" height="80" src="https://play.google.com/intl/en_us/badges/images/generic/en_badge_web_generic.png"></a>
<a href="https://f-droid.org/app/io.pslab"><img alt="Get it on F-Droid" height="80" src="https://f-droid.org/badge/get-it-on.png"></a>

[![Build Status](https://travis-ci.org/fossasia/pslab-android.svg?branch=development)](https://travis-ci.org/fossasia/pslab-android)
[![Gitter](https://badges.gitter.im/fossasia/pslab.svg)](https://gitter.im/fossasia/pslab?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge)
Expand Down
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ android {
applicationId "io.pslab"
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 4
versionName "2.0.3"
versionCode 5
versionName "2.0.4"
multiDexEnabled true
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
Expand Down
76 changes: 32 additions & 44 deletions app/src/main/java/io/pslab/activity/LuxMeterActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,9 @@
import android.os.Bundle;
import android.os.Handler;
import android.support.annotation.NonNull;
import android.support.design.widget.BottomNavigationView;
import android.support.design.widget.BottomSheetBehavior;
import android.support.design.widget.CoordinatorLayout;
import android.support.v4.app.ActivityCompat;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AppCompatActivity;
Expand All @@ -33,9 +31,8 @@
import butterknife.BindView;
import butterknife.ButterKnife;
import io.pslab.R;
import io.pslab.fragment.LuxMeterFragmentConfig;
import io.pslab.fragment.LuxMeterFragmentData;
import io.pslab.fragment.SettingsFragment;
import io.pslab.fragment.LuxMeterSettingFragment;
import io.pslab.others.CSVLogger;
import io.pslab.others.CustomSnackBar;
import io.pslab.others.GPSLogger;
Expand All @@ -58,8 +55,6 @@ public class LuxMeterActivity extends AppCompatActivity {
BottomSheetBehavior bottomSheetBehavior;
GestureDetector gestureDetector;

@BindView(R.id.navigation_lux_meter)
BottomNavigationView bottomNavigationView;
@BindView(R.id.toolbar)
Toolbar toolbar;
@BindView(R.id.cl)
Expand Down Expand Up @@ -99,39 +94,11 @@ protected void onCreate(Bundle savedInstanceState) {
tvShadow.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(bottomSheetBehavior.getState()==BottomSheetBehavior.STATE_EXPANDED)
if (bottomSheetBehavior.getState() == BottomSheetBehavior.STATE_EXPANDED)
bottomSheetBehavior.setState(BottomSheetBehavior.STATE_HIDDEN);
tvShadow.setVisibility(View.GONE);
}
});

bottomNavigationView.setOnNavigationItemSelectedListener
(new BottomNavigationView.OnNavigationItemSelectedListener() {
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
Fragment selectedFragment = null;
Fragment fragment = getSupportFragmentManager().findFragmentById(R.id.frame_layout_lux_meter);

switch (item.getItemId()) {
case R.id.action_data:
if (!(fragment instanceof LuxMeterFragmentData))
selectedFragment = LuxMeterFragmentData.newInstance();
break;
case R.id.action_config:
if (!(fragment instanceof LuxMeterFragmentConfig))
selectedFragment = LuxMeterFragmentConfig.newInstance();
break;
default:
break;
}
if (selectedFragment != null) {
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
transaction.replace(R.id.frame_layout_lux_meter, selectedFragment, selectedFragment.getTag());
transaction.commit();
}
return true;
}
});
try {
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
selectedFragment = LuxMeterFragmentData.newInstance();
Expand Down Expand Up @@ -222,7 +189,7 @@ public boolean onCreateOptionsMenu(Menu menu) {
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
MenuItem item = menu.findItem(R.id.record_data);
item.setIcon(recordData? R.drawable.ic_record_stop_white: R.drawable.ic_record_white);
item.setIcon(recordData ? R.drawable.ic_record_stop_white : R.drawable.ic_record_white);
return super.onPrepareOptionsMenu(menu);
}

Expand All @@ -234,7 +201,7 @@ public boolean onOptionsItemSelected(MenuItem item) {
((LuxMeterFragmentData) selectedFragment).stopSensorFetching();
invalidateOptionsMenu();
Long uniqueRef = realmPreferences.getLong("uniqueCount", 0);
selectedFragment.saveDataInRealm(uniqueRef,locationPref,gpsLogger);
selectedFragment.saveDataInRealm(uniqueRef, locationPref, gpsLogger);
CustomSnackBar.showSnackBar(coordinatorLayout, getString(R.string.exp_data_saved), null, null);
SharedPreferences.Editor editor = realmPreferences.edit();
editor.putLong("uniqueCount", uniqueRef + 1);
Expand All @@ -246,7 +213,7 @@ public boolean onOptionsItemSelected(MenuItem item) {
if (gpsLogger.isGPSEnabled()) {
recordData = true;
((LuxMeterFragmentData) selectedFragment).startSensorFetching();
CustomSnackBar.showSnackBar(coordinatorLayout,getString(R.string.data_recording_start)+"\n"+getString(R.string.location_enabled) , null, null);
CustomSnackBar.showSnackBar(coordinatorLayout, getString(R.string.data_recording_start) + "\n" + getString(R.string.location_enabled), null, null);
invalidateOptionsMenu();
} else {
checkGpsOnResume = true;
Expand All @@ -255,7 +222,7 @@ public boolean onOptionsItemSelected(MenuItem item) {
} else {
recordData = true;
((LuxMeterFragmentData) selectedFragment).startSensorFetching();
CustomSnackBar.showSnackBar(coordinatorLayout,getString(R.string.data_recording_start)+"\n"+getString(R.string.location_disabled) , null, null);
CustomSnackBar.showSnackBar(coordinatorLayout, getString(R.string.data_recording_start) + "\n" + getString(R.string.location_disabled), null, null);
invalidateOptionsMenu();
}
}
Expand All @@ -272,13 +239,18 @@ public boolean onOptionsItemSelected(MenuItem item) {
startActivity(MAP);
break;
case R.id.settings:
startActivity(new Intent(this, SettingsActivity.class));
Intent settingIntent = new Intent(this, SettingsActivity.class);
settingIntent.putExtra("title", "Lux Meter Settings");
startActivity(settingIntent);
break;
case R.id.show_logged_data:
Intent intent = new Intent(this, DataLoggerActivity.class);
intent.putExtra(DataLoggerActivity.CALLER_ACTIVITY, "Lux Meter");
startActivity(intent);

break;
case R.id.show_guide:
bottomSheetBehavior.setState(bottomSheetBehavior.getState() == BottomSheetBehavior.STATE_HIDDEN ?
BottomSheetBehavior.STATE_EXPANDED : BottomSheetBehavior.STATE_HIDDEN);
break;
default:
break;
Expand All @@ -289,13 +261,15 @@ public boolean onOptionsItemSelected(MenuItem item) {
@Override
protected void onResume() {
super.onResume();
SharedPreferences sharedPref;
sharedPref = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
if (checkGpsOnResume) {
if (gpsLogger.isGPSEnabled()) {
recordData = true;
gpsLogger.startFetchingLocation();
((LuxMeterFragmentData) selectedFragment).startSensorFetching();
invalidateOptionsMenu();
CustomSnackBar.showSnackBar(coordinatorLayout,getString(R.string.data_recording_start)+"\n"+getString(R.string.location_enabled) , null, null);
CustomSnackBar.showSnackBar(coordinatorLayout, getString(R.string.data_recording_start) + "\n" + getString(R.string.location_enabled), null, null);
} else {
recordData = false;
Toast.makeText(getApplicationContext(), getString(R.string.gps_not_enabled),
Expand All @@ -304,10 +278,13 @@ protected void onResume() {
}
checkGpsOnResume = false;
}
locationPref = PreferenceManager.getDefaultSharedPreferences(getBaseContext()).getBoolean(SettingsFragment.KEY_INCLUDE_LOCATION, false);
if(!locationPref && gpsLogger!=null){
locationPref = sharedPref.getBoolean(LuxMeterSettingFragment.KEY_INCLUDE_LOCATION, false);
if (!locationPref && gpsLogger != null) {
gpsLogger = null;
}
String highLimit = sharedPref.getString(LuxMeterSettingFragment.KEY_HIGH_LIMIT, "2000");
String updatePeriod = sharedPref.getString(LuxMeterSettingFragment.KEY_UPDATE_PERIOD, "1000");
LuxMeterFragmentData.setParameters(getValueFromText(highLimit, 10, 10000), getValueFromText(updatePeriod, 100, 1000));
}

@Override
Expand All @@ -318,4 +295,15 @@ public void onRequestPermissionsResult(int requestCode, @NonNull String[] permis
startActivity(MAP);
}
}

public int getValueFromText(String strValue, int lowerBound, int upperBound) {

if ("".equals(strValue)) {
return lowerBound;
}
int value = Integer.parseInt(strValue);
if (value > upperBound) return upperBound;
else if (value < lowerBound) return lowerBound;
else return value;
}
}
13 changes: 7 additions & 6 deletions app/src/main/java/io/pslab/activity/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@
import android.widget.TextView;
import android.widget.Toast;

import java.io.IOException;

import butterknife.BindView;
import butterknife.ButterKnife;
import io.pslab.R;
import io.pslab.communication.CommunicationHandler;
import io.pslab.fragment.AboutUsFragment;
Expand All @@ -41,11 +45,6 @@
import io.pslab.others.ScienceLabCommon;
import io.pslab.receivers.USBDetachReceiver;

import java.io.IOException;

import butterknife.BindView;
import butterknife.ButterKnife;

import static io.pslab.others.ScienceLabCommon.scienceLab;

public class MainActivity extends AppCompatActivity {
Expand Down Expand Up @@ -251,7 +250,9 @@ public boolean onNavigationItemSelected(@NonNull MenuItem item) {
if (drawer != null) {
drawer.closeDrawers();
}
startActivity(new Intent(MainActivity.this, SettingsActivity.class));
Intent intent = new Intent(MainActivity.this, SettingsActivity.class);
intent.putExtra("title", "Settings");
startActivity(intent);
return true;
case R.id.nav_about_us:
navItemIndex = 3;
Expand Down
30 changes: 23 additions & 7 deletions app/src/main/java/io/pslab/activity/SettingsActivity.java
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
package io.pslab.activity;

import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.app.Fragment;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.preference.PreferenceManager;
import android.support.v7.widget.Toolbar;
import android.view.MenuItem;
import android.widget.FrameLayout;

import io.pslab.R;
import io.pslab.fragment.SettingsFragment;
import io.pslab.others.GPSLogger;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.Unbinder;
import io.pslab.R;
import io.pslab.fragment.LuxMeterSettingFragment;
import io.pslab.fragment.SettingsFragment;
import io.pslab.others.GPSLogger;

/**
* Created by Avjeet on 7/7/18.
Expand All @@ -37,15 +39,29 @@ protected void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.activity_settings);
unBinder = ButterKnife.bind(this);

Intent intent = getIntent();
String title = intent.getStringExtra("title");

setSupportActionBar(toolbar);
ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
actionBar.setHomeAsUpIndicator(R.drawable.ic_arrow_back_white_24dp);
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setTitle(R.string.nav_settings);
actionBar.setTitle(title);
}

Fragment fragment;
switch (title) {
case "Lux Meter Settings":
fragment = new LuxMeterSettingFragment();
break;
default:
fragment = new SettingsFragment();
break;
}

if (savedInstanceState == null) {
getSupportFragmentManager().beginTransaction().add(R.id.content, new SettingsFragment()).commit();
getSupportFragmentManager().beginTransaction().add(R.id.content, fragment).commit();
}
}

Expand All @@ -70,7 +86,7 @@ public void onRequestPermissionsResult(int requestCode, @NonNull String[] permis
if (grantResults.length <= 0
|| grantResults[0] != PackageManager.PERMISSION_GRANTED) {
SharedPreferences.Editor editor = PreferenceManager.getDefaultSharedPreferences(getBaseContext()).edit();
editor.putBoolean(SettingsFragment.KEY_INCLUDE_LOCATION, false);
editor.putBoolean(LuxMeterSettingFragment.KEY_INCLUDE_LOCATION, false);
editor.commit();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -877,13 +877,15 @@ public void onClick(DialogInterface dialogInterface, int i) {
@Override
public void onClick(View view) {
startActivity(new Intent(WaveGeneratorActivity.this, OscilloscopeActivity.class));
waveDialog.cancel();
}
});

dialogView.findViewById(R.id.la_btn).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
startActivity(new Intent(WaveGeneratorActivity.this, LogicalAnalyzerActivity.class));
waveDialog.cancel();
}
});

Expand Down
Loading

0 comments on commit 5d99ff7

Please sign in to comment.