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

Commit

Permalink
#203 modified the parent classes as per new support library, so as to…
Browse files Browse the repository at this point in the history
… tak benefit of permisiion request callbacks
  • Loading branch information
niccs committed Feb 23, 2016
1 parent 35db07a commit 28d108d
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 194 deletions.
4 changes: 2 additions & 2 deletions app/src/main/java/org/iilab/pb/BaseFragmentActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;

public class BaseFragmentActivity extends FragmentActivity {
public class BaseFragmentActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Expand Down
186 changes: 7 additions & 179 deletions app/src/main/java/org/iilab/pb/HomeActivity.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package org.iilab.pb;

import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.text.TextUtils;
import android.util.Log;

Expand Down Expand Up @@ -61,7 +61,7 @@
import static org.iilab.pb.common.ApplicationSettings.setSelectedLanguage;


public class HomeActivity extends Activity {
public class HomeActivity extends AppCompatActivity {

ProgressDialog pDialog;

Expand All @@ -78,6 +78,7 @@ public void onCreate(Bundle savedInstanceState) {
Fabric.with(this, new Crashlytics());
setContentView(R.layout.welcome_screen);
//deleteShortCut();
Log.d(TAG,"onCreate of Home Activity");
int wizardState = getWizardState(this);
if (SKIP_WIZARD) {
pageId = PAGE_HOME_READY;
Expand Down Expand Up @@ -186,19 +187,20 @@ private void startNextActivity() {
if ((supportedLangs == null) || !(supportedLangs.contains(selectedLang))) {
setSelectedLanguage(this, DEFAULT_LANGUAGE_ENG);
}

//For testing
wizardState=WIZARD_FLAG_HOME_READY;
if (wizardState != WIZARD_FLAG_HOME_READY) {
Log.d(TAG, "First run TRUE, running WizardActivity with pageId = " + pageId);
Intent i = new Intent(HomeActivity.this, WizardActivity.class);
i.putExtra(PAGE_ID, pageId);
startActivity(i);
} else {
Log.d(TAG, "First run FALSE, running CalculatorActivity");
Intent i = new Intent(HomeActivity.this, CalculatorActivity.class);
// Make sure the HardwareTriggerService is started
if(isHardwareTriggerServiceEnabled(this)) {
if (isHardwareTriggerServiceEnabled(this)) {
startService(new Intent(this, HardwareTriggerService.class));
}
Intent i = new Intent(HomeActivity.this, CalculatorActivity.class);
startActivity(i);
}
}
Expand Down Expand Up @@ -256,183 +258,9 @@ protected void onPostExecute(Boolean response) {
e.printStackTrace();
}

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

startNextActivity();
}
}

// private class GetLatestVersion extends AsyncTask<Void, Void, Boolean> {
//
// @Override
// protected void onPreExecute() {
// super.onPreExecute();
// pDialog = ProgressDialog.show(HomeActivity.this, "Application", "Starting...", true, false);
// }
//
// @Override
// protected Boolean doInBackground(Void... params) {
//
// String url = AppConstants.BASE_URL + AppConstants.VERSION_CHECK_URL;
// JsonParser jsonParser = new JsonParser();
// ServerResponse response = jsonParser.retrieveServerData(AppConstants.HTTP_REQUEST_TYPE_GET, url, null, null, null);
// if (response.getStatus() == 200) {
// try {
// JSONObject responseObj = response.getjObj();
// latestVersion = responseObj.getInt("version");
// Log.e("??????", "latest version = " + latestVersion + " last updated version = " + lastUpdatedVersion);
// return true;
// } catch (JSONException e) {
// e.printStackTrace();
// }
// }
// return false;
// }
//
// @Override
// protected void onPostExecute(Boolean response) {
// super.onPostExecute(response);
//
// if (latestVersion > lastUpdatedVersion) {
// new GetMobileDataUpdate().execute();
// } else {
// setLastRunTimeInMillis(HomeActivity.this, System.currentTimeMillis());
// if (pDialog.isShowing())
// try {
// pDialog.dismiss();
// } catch (Exception e) {
// e.printStackTrace();
// }
// startNextActivity();
// }
// }
// }


// private class GetMobileDataUpdate extends AsyncTask<Void, Void, Boolean> {
//
// @Override
// protected void onPreExecute() {
// super.onPreExecute();
// try {
// pDialog = ProgressDialog.show(HomeActivity.this, "Application", "Downloading updates...", true, false);
// } catch (Exception e) {
// e.printStackTrace();
// }
// }
//
// @Override
// protected Boolean doInBackground(Void... params) {
//
// int version = 0;
// for(version = lastUpdatedVersion + 1; version <= latestVersion; version ++){
// if (selectedLang.equals("en")) {
// mobileDataUrl = AppConstants.BASE_URL + "/api/mobile." + version + ".json";
// } else {
// mobileDataUrl = AppConstants.BASE_URL + "/api/" + selectedLang + "/" + "mobile." + version + ".json";
// }
//
// JsonParser jsonParser = new JsonParser();
// ServerResponse response = jsonParser.retrieveServerData(AppConstants.HTTP_REQUEST_TYPE_GET, mobileDataUrl, null, null, null);
// if (response.getStatus() == 200) {
// Log.d(">>>><<<<", "success in retrieving server-response for url = " + mobileDataUrl);
// try {
// JSONObject responseObj = response.getjObj();
// JSONObject mobObj = responseObj.getJSONObject(JSON_OBJECT_MOBILE);
// JSONArray dataArray = mobObj.getJSONArray(JSON_ARRAY_DATA);
// insertMobileDataToLocalDB(dataArray);
// } catch (JSONException e) {
// e.printStackTrace();
// return false;
// }
// }
// }
//
// if(version > latestVersion){
// return true;
// } else{
// return false;
// }
// }
//
// @Override
// protected void onPostExecute(Boolean response) {
// super.onPostExecute(response);
//
// if(response){
// new GetHelpDataUpdate().execute();
// }
// else{
// if (pDialog.isShowing())
// pDialog.dismiss();
//
// startNextActivity();
// }
// }
// }


// private class GetHelpDataUpdate extends AsyncTask<Void, Void, Boolean> {
//
// @Override
// protected void onPreExecute() {
// super.onPreExecute();
// try {
// pDialog = ProgressDialog.show(HomeActivity.this, "Application", "Downloading help pages...", true, false);
// } catch (Exception e) {
// e.printStackTrace();
// }
// }
//
// @Override
// protected Boolean doInBackground(Void... params) {
//
// JsonParser jsonParser = new JsonParser();
// 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);
// 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);
// setLastUpdatedVersion(HomeActivity.this, latestVersion);
// return true;
// } catch (JSONException e) {
// e.printStackTrace();
// }
// }
// return false;
// }
//
// @Override
// protected void onPostExecute(Boolean response) {
// super.onPostExecute(response);
// if (pDialog.isShowing())
// try {
// pDialog.dismiss();
// } catch (Exception e) {
// e.printStackTrace();
// }
//
// startNextActivity();
// }
// }


// private void insertHelpDataToLocalDB(JSONArray dataArray) {
// List<HelpPage> pageList = HelpPage.parseHelpPages(dataArray);
//
// PBDatabase dbInstance = new PBDatabase(HomeActivity.this);
// dbInstance.open();
//
// for (int i = 0; i < pageList.size(); i++) {
// dbInstance.insertOrUpdateHelpPage(pageList.get(i));
// }
// dbInstance.close();
// }


}
2 changes: 0 additions & 2 deletions app/src/main/java/org/iilab/pb/LoginActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ private void actionOnKeyPress(){
if (isAlertActive(LoginActivity.this)) {
i.putExtra(PAGE_ID, PAGE_HOME_ALERTING);
} else {
//check permissions
i.putExtra(PAGE_ID, PAGE_HOME_READY);
}
}
Expand All @@ -85,5 +84,4 @@ private void actionOnKeyPress(){
setError(LoginActivity.this, passwordEditText, ((tryCount < 2) ? R.string.incorrect_pin : R.string.incorrect_pin_3_times));
tryCount++;
}

}
10 changes: 5 additions & 5 deletions app/src/main/java/org/iilab/pb/PanicButtonActivity.java
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
package org.iilab.pb;

import org.iilab.pb.alert.PanicAlert;
import org.iilab.pb.common.ApplicationSettings;

import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import org.iilab.pb.alert.PanicAlert;
import org.iilab.pb.common.ApplicationSettings;


public abstract class PanicButtonActivity extends Activity {
public abstract class PanicButtonActivity extends AppCompatActivity {
public static final int ADD_TO_TOP = 0;

@Override
Expand Down
6 changes: 3 additions & 3 deletions app/src/main/java/org/iilab/pb/WizardActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public void onCreate(Bundle savedInstanceState) {
return;
} else if (currentPage.getId().equals(PAGE_HOME_READY)) {
setWizardState(WizardActivity.this, WIZARD_FLAG_HOME_READY);
changeAppIcontoCalculator();
changeAppIconToCalculator();
if (isHardwareTriggerServiceEnabled(this)) {
startService(new Intent(this, HardwareTriggerService.class));
}
Expand Down Expand Up @@ -217,8 +217,8 @@ else if (currentPage.getComponent().equals(PAGE_COMPONENT_ALARM_TEST_HARDWARE))
}
}

private void changeAppIcontoCalculator() {
Log.i(TAG, "changeAppIcontoCalculator");
private void changeAppIconToCalculator() {
Log.i(TAG, "changeAppIconToCalculator");

getPackageManager().setComponentEnabledSetting(
new ComponentName("org.iilab.pb", "org.iilab.pb.HomeActivity-calculator"),
Expand Down
6 changes: 3 additions & 3 deletions app/src/main/java/org/iilab/pb/common/AppUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import android.os.Vibrator;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AppCompatActivity;
import android.text.Html;
import android.text.Spanned;
import android.util.DisplayMetrics;
Expand All @@ -19,7 +20,6 @@
import android.widget.EditText;
import android.widget.TextView;

import org.iilab.pb.BaseFragmentActivity;
import org.iilab.pb.R;
import org.iilab.pb.data.PBDatabase;
import org.iilab.pb.model.Page;
Expand Down Expand Up @@ -392,7 +392,7 @@ public static boolean playTrainingForRelease1_5(Context context) {
return false;
}

public static boolean checkAndRequestPermissions(BaseFragmentActivity activity) {
public static boolean checkAndRequestPermissions(AppCompatActivity activity) {
int permissionSendMessage = ContextCompat.checkSelfPermission(activity,
Manifest.permission.SEND_SMS);
int locationPermission = ContextCompat.checkSelfPermission(activity,Manifest.permission.ACCESS_FINE_LOCATION);
Expand All @@ -404,7 +404,7 @@ public static boolean checkAndRequestPermissions(BaseFragmentActivity activity)
listPermissionsNeeded.add(Manifest.permission.SEND_SMS);
}

Log.d(TAG, "permission sms value is " + permissionSendMessage + " " + PackageManager.PERMISSION_DENIED + " " + PackageManager.PERMISSION_GRANTED);
Log.d(TAG, "permissions status for sms is " + permissionSendMessage + " and location services is " + locationPermission);
if (!listPermissionsNeeded.isEmpty()) {
ActivityCompat.requestPermissions(activity, listPermissionsNeeded.toArray(new String[listPermissionsNeeded.size()]),
REQUEST_ID_MULTIPLE_PERMISSIONS);
Expand Down

0 comments on commit 28d108d

Please sign in to comment.