Skip to content
This repository has been archived by the owner on Mar 27, 2020. It is now read-only.

Commit

Permalink
Merge pull request #190 from PanicInitiative/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
niccs committed Jan 31, 2016
2 parents f6b9da7 + e8aa7cc commit de6fc46
Show file tree
Hide file tree
Showing 10 changed files with 328 additions and 162 deletions.
19 changes: 18 additions & 1 deletion app/src/main/assets/mobile_en.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"mobile": {
"version": "9",
"version": "10",
"data": [
{
"id": "setup-warning",
Expand Down Expand Up @@ -844,6 +844,23 @@
}
],
"content": "<p>Congratulations the new vibration patterns are tested !</p>"
},
{
"id": "setup-training_1.5",
"lang": "en",
"type": "simple",
"title": "Setup Alert",
"action": [
{
"title": "Learn",
"link": "setup-alarm-test-hardware"
},
{
"title": "Skip",
"link": "home-ready"
}
],
"content": "<p>Panic Button has been updated and now uses a new default trigger mechanism. </p><p>Even better, you can now choose your own trigger mechanism to help prevent false triggers. Let's get started and get you up to speed with these new features. </p>"
}
]
}
Expand Down
27 changes: 16 additions & 11 deletions app/src/main/java/org/iilab/pb/CalculatorActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,19 @@
import android.view.ViewConfiguration;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

import org.iilab.pb.calculator.CalculatorImpl;
import org.iilab.pb.common.AppConstants;
import org.iilab.pb.common.AppUtil;
import org.iilab.pb.common.ApplicationSettings;
import org.iilab.pb.trigger.MultiClickEvent;

import static org.iilab.pb.common.AppConstants.DISGUISE_UNLOCK_LONGPRESS_TIME;
import static org.iilab.pb.common.AppConstants.WIZARD_FLAG_HOME_READY;
import static org.iilab.pb.common.AppUtil.behaveAsHomeButton;
import static org.iilab.pb.common.AppUtil.playTrainingForRelease1_5;
import static org.iilab.pb.common.AppUtil.unbindDrawables;
import static org.iilab.pb.common.AppUtil.vibrateForHapticFeedback;
import static org.iilab.pb.common.ApplicationSettings.setWizardState;

public class CalculatorActivity extends PanicButtonActivity {

private static final int[] buttons = {R.id.one, R.id.two, R.id.three,
Expand All @@ -33,11 +39,10 @@ public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.calculator_layout);
registerButtonEvents();
// startService(new Intent(this, HardwareTriggerService.class));

calculator = new CalculatorImpl();

ApplicationSettings.setWizardState(this, AppConstants.WIZARD_FLAG_HOME_READY);
setWizardState(this, WIZARD_FLAG_HOME_READY);
if(playTrainingForRelease1_5(getApplicationContext()) )
Toast.makeText(this, "Calculate! has been updated. Go to the settings to find out more!", Toast.LENGTH_LONG).show();
}

private void registerButtonEvents() {
Expand Down Expand Up @@ -120,7 +125,7 @@ public void onClick(View view) {
return;
}
if(multiClickEvent.canStartVibration()){
AppUtil.vibrateForHapticFeedback(CalculatorActivity.this);
vibrateForHapticFeedback(CalculatorActivity.this);
CharSequence text = ((Button) view).getText();
//Toast.makeText(getApplicationContext(), "Press the button '" + text + "' once the vibration ends to trigger alerts", Toast.LENGTH_LONG).show();
}
Expand Down Expand Up @@ -161,7 +166,7 @@ public void run() {


mHasPerformedLongPress = false;
v.postDelayed(mPendingCheckForLongPress, AppConstants.DISGUISE_UNLOCK_LONGPRESS_TIME);
v.postDelayed(mPendingCheckForLongPress, DISGUISE_UNLOCK_LONGPRESS_TIME);

break;
case MotionEvent.ACTION_MOVE:
Expand Down Expand Up @@ -211,7 +216,7 @@ private void handleButtonPress(CalculatorImpl.Button button) {
@Override
protected void onDestroy() {
super.onDestroy();
AppUtil.unbindDrawables(getWindow().getDecorView().findViewById(android.R.id.content));
unbindDrawables(getWindow().getDecorView().findViewById(android.R.id.content));
System.gc();
}

Expand All @@ -220,6 +225,6 @@ public void onBackPressed() {
// super.onBackPressed();
// finish();
Log.d(TAG, "onBackPressed Called");
startActivity(AppUtil.behaveAsHomeButton());
startActivity(behaveAsHomeButton());
}
}
103 changes: 60 additions & 43 deletions app/src/main/java/org/iilab/pb/HomeActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
import android.text.TextUtils;
import android.util.Log;

import org.iilab.pb.common.AppUtil;
import org.iilab.pb.common.ApplicationSettings;
import com.crashlytics.android.Crashlytics;

import org.iilab.pb.data.PBDatabase;
import org.iilab.pb.model.Page;
import org.iilab.pb.model.PageAction;
Expand All @@ -22,9 +22,11 @@
import java.util.List;
import java.util.Locale;

import static org.iilab.pb.common.AppConstants.DATABASE_VERSION;
import io.fabric.sdk.android.Fabric;

import static org.iilab.pb.common.AppConstants.DEFAULT_LANGUAGE_ENG;
import static org.iilab.pb.common.AppConstants.DELIMITER_COMMA;
import static org.iilab.pb.common.AppConstants.FRESH_INSTALL_APP_RELEASE_NO;
import static org.iilab.pb.common.AppConstants.JSON_ARRAY_DATA;
import static org.iilab.pb.common.AppConstants.JSON_EXTENSION;
import static org.iilab.pb.common.AppConstants.JSON_OBJECT_HELP;
Expand All @@ -43,8 +45,20 @@
import static org.iilab.pb.common.AppConstants.WIZARD_FLAG_HOME_NOT_CONFIGURED_ALARM;
import static org.iilab.pb.common.AppConstants.WIZARD_FLAG_HOME_NOT_CONFIGURED_DISGUISE;
import static org.iilab.pb.common.AppConstants.WIZARD_FLAG_HOME_READY;
import com.crashlytics.android.Crashlytics;
import io.fabric.sdk.android.Fabric;
import static org.iilab.pb.common.AppUtil.insertMobileDataToLocalDB;
import static org.iilab.pb.common.AppUtil.isLanguageDataExists;
import static org.iilab.pb.common.AppUtil.loadJSONFromAsset;
import static org.iilab.pb.common.ApplicationSettings.addDBLoadedLanguage;
import static org.iilab.pb.common.ApplicationSettings.getLastUpdatedVersion;
import static org.iilab.pb.common.ApplicationSettings.getSelectedLanguage;
import static org.iilab.pb.common.ApplicationSettings.getSupportedLanguages;
import static org.iilab.pb.common.ApplicationSettings.getWizardState;
import static org.iilab.pb.common.ApplicationSettings.isHardwareTriggerServiceEnabled;
import static org.iilab.pb.common.ApplicationSettings.setAppUpdated;
import static org.iilab.pb.common.ApplicationSettings.setFirstRun;
import static org.iilab.pb.common.ApplicationSettings.setLastUpdatedVersion;
import static org.iilab.pb.common.ApplicationSettings.setPBSupportedLanguages;
import static org.iilab.pb.common.ApplicationSettings.setSelectedLanguage;


public class HomeActivity extends Activity {
Expand All @@ -54,8 +68,7 @@ public class HomeActivity extends Activity {
String pageId;
String selectedLang;
int currentLocalContentVersion;
int lastLocalContentVersion;
int lastLocalDBVersion;
int newLocalContentVersion;

private static final String TAG = HomeActivity.class.getName();
String supportedLangs;
Expand All @@ -65,7 +78,7 @@ public void onCreate(Bundle savedInstanceState) {
Fabric.with(this, new Crashlytics());
setContentView(R.layout.welcome_screen);
//deleteShortCut();
int wizardState = ApplicationSettings.getWizardState(this);
int wizardState = getWizardState(this);
if (SKIP_WIZARD) {
pageId = PAGE_HOME_READY;
} else if (wizardState == WIZARD_FLAG_HOME_NOT_CONFIGURED) {
Expand All @@ -78,40 +91,44 @@ public void onCreate(Bundle savedInstanceState) {
} else if (wizardState == WIZARD_FLAG_HOME_READY) {
pageId = PAGE_HOME_READY;
}
ApplicationSettings.setSelectedLanguage(this, getDefaultOSLanguage());
selectedLang = ApplicationSettings.getSelectedLanguage(this);
setSelectedLanguage(this, getDefaultOSLanguage());
selectedLang = getSelectedLanguage(this);
/*
lastLocalDBVersion is used for local db version update. If local db version is changed, then all local data will be deleted,
tables will be reformed & database is blank. So at that point we will force local-data update from assets, then a retrieval-try
from the remote database even if the data was retrieved within last 24-hours period.
*/
lastLocalDBVersion = ApplicationSettings.getLastUpdatedDBVersion(this);
Log.d(TAG, "lastLocalDBVersion " + lastLocalDBVersion);
if (lastLocalDBVersion < DATABASE_VERSION) {
Log.d(TAG, "local db version changed. needs a force update");
ApplicationSettings.setLocalDataInsertion(this, false);
}

currentLocalContentVersion = ApplicationSettings.getLastUpdatedVersion(HomeActivity.this);
// this is the version number from installed mobile_en.json
currentLocalContentVersion = getLastUpdatedVersion(HomeActivity.this);

try {
JSONObject jsonObj = new JSONObject(AppUtil.loadJSONFromAsset("mobile_en.json", getApplicationContext()));
JSONObject jsonObj = new JSONObject(loadJSONFromAsset("mobile_en.json", getApplicationContext()));
JSONObject mobileObj = jsonObj.getJSONObject(JSON_OBJECT_MOBILE);

lastLocalContentVersion = Integer.parseInt(mobileObj.getString(VERSION));
//this is from new assets folder
newLocalContentVersion = Integer.parseInt(mobileObj.getString(VERSION));
} catch (JSONException | NumberFormatException exception) {
Log.e(TAG, "Exception in reading mobile_en.json from asset" + exception.getMessage());
exception.printStackTrace();
}

/* We update the device language content if the english mobile_en.json version has increased or
* if the language of the device OS was perviously not installed*/

if ((lastLocalContentVersion > currentLocalContentVersion) || (!AppUtil.isLanguageDataExists(getApplicationContext(), selectedLang))) {
Log.d(TAG, "Update local data");
* if the language of the device OS was previously not installed*/

if ((newLocalContentVersion > currentLocalContentVersion) || (!isLanguageDataExists(getApplicationContext(), selectedLang))) {
Log.d(TAG, "Update local data as the english mobile_en.json version has increased");
// to check if the app is installed first time, -1 is the default value
if(currentLocalContentVersion== FRESH_INSTALL_APP_RELEASE_NO){
setFirstRun(getApplicationContext(),true);
setAppUpdated(getApplicationContext(), false);
}else {
setAppUpdated(getApplicationContext(), true);
}
new InitializeLocalData().execute();
ApplicationSettings.addDBLoadedLanguage(getApplicationContext(), selectedLang);
} else {
addDBLoadedLanguage(getApplicationContext(), selectedLang);

}
else {
Log.d(TAG, "no update of local data needed");
startNextActivity();
}
Expand Down Expand Up @@ -143,30 +160,30 @@ private void deleteShortCut() {
sendBroadcast(removeIntent);
}

private void setsupportedlanguages(Page languagesPage) {
private void setSupportedLanguages(Page languagesPage) {
List<String> allowedLanguages = new ArrayList<>();
List<PageAction> actionLanguages = languagesPage.getAction();
for (PageAction actionLanguage : actionLanguages) {
allowedLanguages.add(actionLanguage.getLanguage());
}
supportedLangs = TextUtils.join(DELIMITER_COMMA, allowedLanguages);
ApplicationSettings.setSupportedLanguages(this, supportedLangs);
setPBSupportedLanguages(this, supportedLangs);
}

private void startNextActivity() {
Log.d(TAG, "starting next activity");
int wizardState = ApplicationSettings.getWizardState(this);
supportedLangs = ApplicationSettings.getSupportedLanguages(this);
int wizardState = getWizardState(this);
supportedLangs = getSupportedLanguages(this);
Log.d(TAG, "Checking supported languages " + supportedLangs);
if (null == supportedLangs) {
PBDatabase dbInstance = new PBDatabase(this);
dbInstance.open();
Page languagesPage = dbInstance.retrievePage(PAGE_SETUP_LANGUAGE, DEFAULT_LANGUAGE_ENG);
setsupportedlanguages(languagesPage);
setSupportedLanguages(languagesPage);
dbInstance.close();
}
if ((supportedLangs == null) || !(supportedLangs.contains(selectedLang))) {
ApplicationSettings.setSelectedLanguage(this, DEFAULT_LANGUAGE_ENG);
setSelectedLanguage(this, DEFAULT_LANGUAGE_ENG);
}
if (wizardState != WIZARD_FLAG_HOME_READY) {
Log.d(TAG, "First run TRUE, running WizardActivity with pageId = " + pageId);
Expand All @@ -177,7 +194,7 @@ private void startNextActivity() {
Log.d(TAG, "First run FALSE, running CalculatorActivity");
Intent i = new Intent(HomeActivity.this, CalculatorActivity.class);
// Make sure the HardwareTriggerService is started
if(ApplicationSettings.isHardwareTriggerServiceEnabled(this)) {
if(isHardwareTriggerServiceEnabled(this)) {
startService(new Intent(this, HardwareTriggerService.class));
}
startActivity(i);
Expand All @@ -199,25 +216,25 @@ protected Boolean doInBackground(Void... params) {
String dataFileName = PREFIX_MOBILE_DATA + selectedLang + JSON_EXTENSION;
String helpFileName = PREFIX_HELP_DATA + selectedLang + JSON_EXTENSION;
try {
JSONObject jsonObj = new JSONObject(AppUtil.loadJSONFromAsset(dataFileName, getApplicationContext()));
JSONObject jsonObj = new JSONObject(loadJSONFromAsset(dataFileName, getApplicationContext()));
JSONObject mobileObj = jsonObj.getJSONObject(JSON_OBJECT_MOBILE);

lastUpdatedVersion = mobileObj.getInt(VERSION);
ApplicationSettings.setLastUpdatedVersion(HomeActivity.this, lastUpdatedVersion);
setLastUpdatedVersion(HomeActivity.this, lastUpdatedVersion);

JSONArray dataArray = mobileObj.getJSONArray(JSON_ARRAY_DATA);
AppUtil.insertMobileDataToLocalDB(dataArray, getApplicationContext());
insertMobileDataToLocalDB(dataArray, getApplicationContext());
} catch (JSONException jsonException) {
Log.e(TAG, "Exception in reading mobile_en.json from asset" + jsonException.getMessage());
jsonException.printStackTrace();
}

try {
JSONObject jsonObj = new JSONObject(AppUtil.loadJSONFromAsset(helpFileName, getApplicationContext()));
JSONObject jsonObj = new JSONObject(loadJSONFromAsset(helpFileName, getApplicationContext()));
JSONObject mobileObj = jsonObj.getJSONObject(JSON_OBJECT_HELP);

JSONArray dataArray = mobileObj.getJSONArray(JSON_ARRAY_DATA);
AppUtil.insertMobileDataToLocalDB(dataArray, getApplicationContext());
insertMobileDataToLocalDB(dataArray, getApplicationContext());
} catch (JSONException jsonException) {
Log.e(TAG, "Exception in reading help_en.json from asset" + jsonException.getMessage());
jsonException.printStackTrace();
Expand All @@ -237,8 +254,8 @@ protected void onPostExecute(Boolean response) {
e.printStackTrace();
}

ApplicationSettings.setLocalDataInsertion(HomeActivity.this, true);
ApplicationSettings.setLastUpdatedDBVersion(HomeActivity.this, DATABASE_VERSION);
// setLocalDataInsertion(HomeActivity.this, true);
// setLastUpdatedDBVersion(HomeActivity.this, DATABASE_VERSION);

startNextActivity();
}
Expand Down Expand Up @@ -278,7 +295,7 @@ protected void onPostExecute(Boolean response) {
// if (latestVersion > lastUpdatedVersion) {
// new GetMobileDataUpdate().execute();
// } else {
// ApplicationSettings.setLastRunTimeInMillis(HomeActivity.this, System.currentTimeMillis());
// setLastRunTimeInMillis(HomeActivity.this, System.currentTimeMillis());
// if (pDialog.isShowing())
// try {
// pDialog.dismiss();
Expand Down Expand Up @@ -373,13 +390,13 @@ protected void onPostExecute(Boolean response) {
// ServerResponse response = jsonParser.retrieveServerData(AppConstants.HTTP_REQUEST_TYPE_GET, helpDataUrl, null, null, null);
// if (response.getStatus() == 200) {
// Log.d(">>>><<<<", "success in retrieving server-response for url = " + helpDataUrl);
// ApplicationSettings.setLastRunTimeInMillis(HomeActivity.this, System.currentTimeMillis()); // if we can retrieve a single data, we change it up-to-date
// setLastRunTimeInMillis(HomeActivity.this, System.currentTimeMillis()); // if we can retrieve a single data, we change it up-to-date
// try {
// JSONObject responseObj = response.getjObj();
// JSONObject mobObj = responseObj.getJSONObject(JSON_OBJECT_HELP);
// JSONArray dataArray = mobObj.getJSONArray(JSON_ARRAY_DATA);
// insertHelpDataToLocalDB(dataArray);
// ApplicationSettings.setLastUpdatedVersion(HomeActivity.this, latestVersion);
// setLastUpdatedVersion(HomeActivity.this, latestVersion);
// return true;
// } catch (JSONException e) {
// e.printStackTrace();
Expand Down
Loading

0 comments on commit de6fc46

Please sign in to comment.