Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OTC-508: Test insuree image upload from Android 7 #133

Merged
merged 1 commit into from
Feb 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,18 @@ android {
signingConfig signingConfigs.releaseConfig
}
buildConfigField "boolean", "LOG", "false"

// Refer to https://developer.android.com/reference/android/util/Log for the log level values
buildConfigField "int", "CONSOLE_LOG_LEVEL", '8' //Assert
buildConfigField "int", "FILE_LOG_LEVEL", '8' //Assert
}
debug {
debuggable = true
buildConfigField "boolean", "LOG", "true"

// Refer to https://developer.android.com/reference/android/util/Log for the log level values
buildConfigField "int", "CONSOLE_LOG_LEVEL", '2' //Verbose
buildConfigField "int", "FILE_LOG_LEVEL", '2' //Verbose
}
flavorDimensions 'std'
}
Expand Down
26 changes: 24 additions & 2 deletions app/src/main/assets/pages/Settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<input type="submit" id="btnSaveRarPassword" strName="SaveRarPassword" value="Save">
</div>

<br><br>
<br />

<ul class="ulEntry">
<li>
Expand All @@ -33,6 +33,28 @@
<div class="footer">
<input type="submit" id="btnBackToDefault" strName="BackToDefault" value="Save">
</div>

<br />

<ul class="ulEntry">
<li>
<span strName="ExportLogs">Export logs</span>
</li>
</ul>
<div class="footer">
<input type="submit" id="btnExportLogs" strName="ExportLogsButton" value="Save">
</div>

<br />

<ul class="ulEntry">
<li>
<span strName="ClearLogs">Clear logs</span>
</li>
</ul>
<div class="footer">
<input type="submit" id="btnClearLogs" strName="ClearLogsButton" value="Save">
</div>
</div>
</body>
</html>
</html>
8 changes: 8 additions & 0 deletions app/src/main/assets/pages/Settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,12 @@ $(document).ready(function () {
Android.ShowDialog(e.message);
}
});

$('#btnExportLogs').click(function () {
Android.exportLogs()
});

$('#btnClearLogs').click(function () {
Android.clearLogs()
});
});
64 changes: 35 additions & 29 deletions app/src/main/java/org/openimis/imispolicies/Acquire.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,14 @@
import android.location.LocationManager;
import android.net.Uri;
import android.os.Bundle;
import android.provider.MediaStore;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.FileProvider;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import org.openimis.imispolicies.tools.Log;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
Expand All @@ -65,10 +66,9 @@
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;

import static android.provider.MediaStore.EXTRA_OUTPUT;

public class Acquire extends AppCompatActivity {
private static final String LOG_TAG = "ACQUIRE";
private static final int SCAN_QR_REQUEST_CODE = 0;
Expand Down Expand Up @@ -97,7 +97,7 @@ public class Acquire extends AppCompatActivity {

private Picasso picasso;

private Target imageTarget = new Target() {
private final Target imageTarget = new Target() {
@Override
public void onBitmapLoaded(final Bitmap bitmap, Picasso.LoadedFrom from) {
theImage = bitmap;
Expand All @@ -120,9 +120,10 @@ public void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.acquire_main);

final ActionBar actionBar = getSupportActionBar();
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setTitle(getResources().getString(R.string.Acquire));

if (actionBar != null) {
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setTitle(getResources().getString(R.string.Acquire));
}

global = (Global) getApplicationContext();
ca = new ClientAndroidInterface(this);
Expand All @@ -136,14 +137,18 @@ public void onCreate(Bundle savedInstanceState) {
tempPhotoFile = new File(Path, "temp.jpg");
try {
if (tempPhotoFile.delete()) {
Log.i(LOG_TAG, "Leftover temp image deleted");
Log.v(LOG_TAG, "Leftover temp image deleted");
}

if (!tempPhotoFile.createNewFile()) {
Log.w(LOG_TAG, "Temp photo file already exists");
}
tempPhotoUri = FileProvider.getUriForFile(this,
String.format("%s.fileprovider", BuildConfig.APPLICATION_ID),
tempPhotoFile);
if (tempPhotoUri == null) {
Log.w(LOG_TAG, "Failed to create temp photo URI");
}
} catch (IOException e) {
Log.e(LOG_TAG, "Temp photo file creation failed", e);
}
Expand Down Expand Up @@ -188,7 +193,7 @@ public void afterTextChanged(Editable InsNo) {
Criteria c = new Criteria();
towers = lm.getBestProvider(c, false);
if (towers != null) {
Location loc = null;
Location loc;
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
// TODO: Consider calling
// ActivityCompat#requestPermissions
Expand All @@ -207,16 +212,18 @@ public void afterTextChanged(Editable InsNo) {
}

} else {
Toast.makeText(Acquire.this, "No providers found", Toast.LENGTH_LONG).show();
Log.w(LOG_TAG, "No location providers found");
Toast.makeText(Acquire.this, "No location providers found", Toast.LENGTH_LONG).show();
}

iv.setOnClickListener(v -> {
});

btnTakePhoto.setOnClickListener(v -> {
try {
Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra(EXTRA_OUTPUT, tempPhotoUri);
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra(MediaStore.EXTRA_OUTPUT, tempPhotoUri);
global.grantUriPermissions(this, tempPhotoUri, intent, Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
startActivityForResult(intent, TAKE_PHOTO_REQUEST_CODE);
} catch (ActivityNotFoundException e) {
Log.e(LOG_TAG, "Image capture activity not found", e);
Expand Down Expand Up @@ -324,32 +331,31 @@ protected boolean isValidate() {
}

private int SubmitData() throws IOException, UserException {
int Uploaded = 0;
File myDir = new File(Path);

//Get current date and format it in yyyyMMdd format
SimpleDateFormat format = new SimpleDateFormat("yyyyMMddHHmmss", Locale.US);
Calendar cal = Calendar.getInstance();
String d = format.format(cal.getTime());

String fName = etCHFID.getText() + "_" + global.getOfficerCode() + "_" + d + "_" + Latitude + "_" + Longitude + ".jpg";
//Create file and delete if exists
File file = new File(myDir, fName);
if (file.exists()) file.delete();
Uploaded = 1;
String date = AppInformation.DateTimeInfo.getDefaultFileDatetimeFormatter().format(new Date());
String fName = etCHFID.getText() + "_" + global.getOfficerCode() + "_" + date + "_" + Latitude + "_" + Longitude + ".jpg";

File file = new File(global.getSubdirectory("Images"), fName);
if (file.exists()) {
Log.w(LOG_TAG, String.format("File already exists: %s", file.getAbsolutePath()));
}

FileOutputStream out = new FileOutputStream(file);
theImage.compress(Bitmap.CompressFormat.JPEG, global.getIntKey("image_jpeg_quality", 40), out);

out.flush();
out.close();

if (file.length() == 0L) {
Log.w(LOG_TAG, "Compressing photo failed, the resulting file has no content");
}

ContentValues contentValues = new ContentValues();
contentValues.put("PhotoPath", file.getAbsolutePath());
String[] whereArgs = {etCHFID.getText().toString()};

sqlHandler.updateData("tblInsuree", contentValues, "CHFID = ?", whereArgs);
if(sqlHandler.updateData("tblInsuree", contentValues, "CHFID = ?", whereArgs, false) == 0) {
Log.w(LOG_TAG, String.format("Cannot update photo path. No insuree for CHFID: %s", etCHFID.getText().toString()));
}

return Uploaded;
return 1;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import android.support.v7.app.ActionBar;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import org.openimis.imispolicies.tools.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import org.openimis.imispolicies.tools.Log;
import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.View;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,14 @@
import android.app.Activity;
import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.ContentResolver;
import android.content.ContentValues;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.content.res.Resources;
import android.database.Cursor;
import android.database.SQLException;
Expand All @@ -52,11 +55,14 @@
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.util.Base64;
import android.util.Log;

import org.openimis.imispolicies.tools.Log;

import android.util.Xml;
import android.view.LayoutInflater;
import android.view.View;
import android.webkit.JavascriptInterface;
import android.webkit.MimeTypeMap;
import android.widget.TextView;
import android.widget.Toast;

Expand Down Expand Up @@ -106,7 +112,8 @@
import java.util.Set;
import java.util.regex.Pattern;

import org.openimis.imispolicies.Util.AndroidUtil;
import org.openimis.imispolicies.tools.Util;
import org.openimis.imispolicies.tools.Util.AndroidUtil;
import org.xmlpull.v1.XmlSerializer;

import javax.crypto.Cipher;
Expand All @@ -115,11 +122,12 @@

import static android.database.sqlite.SQLiteDatabase.openOrCreateDatabase;
import static android.provider.MediaStore.EXTRA_OUTPUT;
import static org.openimis.imispolicies.Util.JsonUtil.isStringEmpty;
import static org.openimis.imispolicies.Util.StringUtil.isEmpty;
import static org.openimis.imispolicies.tools.Util.JsonUtil.isStringEmpty;
import static org.openimis.imispolicies.tools.Util.StringUtil.isEmpty;

public class ClientAndroidInterface {
private static final String LOG_TAG_RENEWAL = "RENEWAL";
private static final String LOG_TAG_SETTINGS = "SETTINGS";

private Context mContext;

Expand Down Expand Up @@ -814,7 +822,7 @@ public int SaveFamily(String FamilyData, String InsureeData) {
Online = 2;
values.put("isOffline", 2);
}
sqlHandler.updateData("tblFamilies", values, "FamilyId = ? AND (isOffline = ? OR isOffline = ?) ", new String[]{String.valueOf(FamilyId), String.valueOf(isOffline), String.valueOf(Online)});
sqlHandler.updateData("tblFamilies", values, "FamilyId = ? AND (isOffline = ? OR isOffline = ?) ", new String[]{String.valueOf(FamilyId), String.valueOf(isOffline), String.valueOf(Online)}, false);
//Automatic sync
/*
if (isOffline == 0 && global.getUserId() > 0) {
Expand Down Expand Up @@ -4670,14 +4678,7 @@ public boolean accept(File dir, String filename) {

private File[] GetListOfImages(String DirectoryPath, final String FileName) {
File Directory = new File(DirectoryPath);
FilenameFilter filter = new FilenameFilter() {

@Override
public boolean accept(File dir, String filename) {
return filename.equalsIgnoreCase(FileName);
}
};
return Directory.listFiles(filter);
return Directory.listFiles((dir, filename) -> filename.equalsIgnoreCase(FileName));
}

@JavascriptInterface
Expand Down Expand Up @@ -6423,4 +6424,32 @@ private int getMaxIdFromTable(String idFieldName, String tableName) {
" for table " + tableName);
}
}

@JavascriptInterface
public void clearLogs() {
Util.AndroidUtil.showConfirmDialog(
mContext,
R.string.ConfirmClearLogs,
(d, i) -> {
Log.deleteLogFiles();
}
);
}

@JavascriptInterface
public void exportLogs() {
Util.AndroidUtil.showConfirmDialog(
mContext,
R.string.ConfirmExportLogs,
(d, i) -> new Thread(() -> {
File targetFile = Log.zipLogFiles();

Uri logExportUri = FileProvider.getUriForFile(mContext,
String.format("%s.fileprovider", BuildConfig.APPLICATION_ID),
targetFile);

global.sendFile(mContext, logExportUri, "application/zip");
}).start()
);
}
}
10 changes: 0 additions & 10 deletions app/src/main/java/org/openimis/imispolicies/Compressor.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,7 @@ public static void zip(ArrayList<File> targetPath, String destinationFilePath, S
}

ZipFile zipFile = new ZipFile(destinationFilePath);

/* File targetFile = new File(targetPath);
if (targetFile.isFile()) {
zipFile.addFile(targetFile, parameters);
} else if (targetFile.isDirectory()) {
zipFile.addFolder(targetFile, parameters);
}*/
zipFile.addFiles(targetPath, parameters);


} catch (Exception e) {
e.printStackTrace();
}
Expand All @@ -58,7 +49,6 @@ public static void zip(String targetPath, String destinationFilePath, String pas
} else if (targetFile.isDirectory()) {
zipFile.addFolder(targetFile, parameters);
}

} catch (Exception e) {
e.printStackTrace();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import android.content.ContentValues;
import android.content.Intent;
import android.content.Context;
import android.util.Log;
import org.openimis.imispolicies.tools.Log;

import org.apache.commons.lang3.StringUtils;
import org.apache.http.HttpEntity;
Expand All @@ -13,6 +13,7 @@
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.openimis.imispolicies.tools.Util;

import java.io.IOException;
import java.net.HttpURLConnection;
Expand Down
Loading