Skip to content

Commit

Permalink
Merge pull request #1 from batumi/usingFielddb
Browse files Browse the repository at this point in the history
Using fielddb
  • Loading branch information
cesine authored Sep 5, 2017
2 parents 7026aaa + 9cc2836 commit 93a0ebb
Show file tree
Hide file tree
Showing 17 changed files with 1,273 additions and 1,732 deletions.
4 changes: 3 additions & 1 deletion AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="19" />
android:targetSdkVersion="23" />

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.STORAGE" />
Expand Down Expand Up @@ -110,6 +110,8 @@
</service>
<service android:name="com.github.fielddb.service.DownloadDatumsService" >
</service>
<service android:name="com.github.fielddb.service.DownloadFilesService" >
</service>
<service android:name="com.github.fielddb.service.RegisterUserService" >
</service>
<service android:name="com.github.fielddb.service.UploadAudioVideoService" >
Expand Down
File renamed without changes
File renamed without changes
File renamed without changes
Binary file modified ic_launcher-kindle.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified ic_launcher-web.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion project.properties
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@
#proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt

# Project target.
target=android-20
target=Google Inc.:Google APIs:23
android.library.reference.1=../../fielddbhome/AndroidFieldDB
206 changes: 3 additions & 203 deletions src/com/github/fielddb/KartuliSpeechRecognitionApplication.java
Original file line number Diff line number Diff line change
@@ -1,215 +1,15 @@
package com.github.fielddb;

/* https://github.com/ACRA/acralyzer/wiki/setup */
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.security.KeyStore;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
import java.security.cert.CertificateException;
import java.util.Locale;

import org.acra.ACRA;
import org.acra.ACRAConfiguration;
import org.acra.annotation.ReportsCrashes;

import com.github.fielddb.database.DatumContentProvider;
import com.github.fielddb.database.FieldDBUserContentProvider;
import com.github.fielddb.database.User;
import com.github.fielddb.database.DatumContentProvider.DatumTable;
import com.github.fielddb.database.UserContentProvider.UserTable;
import com.github.fielddb.lessons.Config;
import com.github.fielddb.service.DownloadDatumsService;
import com.github.fielddb.service.KartuliSMSCorpusService;
import com.github.fielddb.service.RegisterUserService;
import com.github.opensourcefieldlinguistics.fielddb.speech.kartuli.BuildConfig;
import com.github.opensourcefieldlinguistics.fielddb.speech.kartuli.R;

import android.app.Application;
import android.content.Context;
import android.content.CursorLoader;
import android.content.Intent;
import android.content.res.Configuration;
import android.database.Cursor;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.Uri;
import android.util.Log;

@ReportsCrashes(formKey = "", formUri = "", reportType = org.acra.sender.HttpSender.Type.JSON, httpMethod = org.acra.sender.HttpSender.Method.PUT, formUriBasicAuthLogin = "see_private_constants", formUriBasicAuthPassword = "see_private_constants")
public class KartuliSpeechRecognitionApplication extends Application {
User mUser;
public class KartuliSpeechRecognitionApplication extends FieldDBApplication {

@Override
public final void onCreate() {
DatumContentProvider.setAppType(Config.APP_TYPE);
DatumContentProvider.setDataIsAboutLanguageName(Config.DATA_IS_ABOUT_LANGUAGE_NAME_ASCII);
public void onCreate() {
mUpdateSampleData = new Intent(getApplicationContext(), KartuliSMSCorpusService.class);
super.onCreate();
String language = forceLocale(Config.DATA_IS_ABOUT_LANGUAGE_ISO);
Log.d(Config.TAG, "Forced the locale to " + language);

// (new File(Config.DEFAULT_OUTPUT_DIRECTORY)).mkdirs();

ACRAConfiguration config = ACRA.getNewDefaultConfig(this);
config.setFormUri(Config.ACRA_SERVER_URL);
config.setFormUriBasicAuthLogin(Config.ACRA_USER);
config.setFormUriBasicAuthPassword(Config.ACRA_PASS);

/* https://github.com/OpenSourceFieldlinguistics/FieldDB/issues/1435 */
boolean doesAcraSupportKeystoresWorkaroundForSNIMissingVirtualhosts = false;
if (doesAcraSupportKeystoresWorkaroundForSNIMissingVirtualhosts) {

// Get an instance of the Bouncy Castle KeyStore format
KeyStore trusted;
try {
trusted = KeyStore.getInstance("BKS");
// Get the raw resource, which contains the keystore with
// your trusted certificates (root and any intermediate certs)
InputStream in = getApplicationContext().getResources().openRawResource(R.raw.sslkeystore);
try {
// Initialize the keystore with the provided trusted
// certificates
// Also provide the password of the keystore
trusted.load(in, Config.KEYSTORE_PASS.toCharArray());
// TODO waiting for https://github.com/ACRA/acra/pull/132
// config.setKeyStore(trusted);
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
} catch (CertificateException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
in.close();
} catch (IOException e) {
e.printStackTrace();
}
}
} catch (KeyStoreException e1) {
e1.printStackTrace();
}

} else {
// TODO waiting for https://github.com/ACRA/acra/pull/132
config.setDisableSSLCertValidation(true);
}

ACRA.setConfig(config);

if (!BuildConfig.DEBUG)
ACRA.init(this);

// Get the user from the db
String[] userProjection = { UserTable.COLUMN_ID, UserTable.COLUMN_REV, UserTable.COLUMN_USERNAME, UserTable.COLUMN_FIRSTNAME,
UserTable.COLUMN_LASTNAME, UserTable.COLUMN_EMAIL, UserTable.COLUMN_GRAVATAR, UserTable.COLUMN_AFFILIATION,
UserTable.COLUMN_RESEARCH_INTEREST, UserTable.COLUMN_DESCRIPTION, UserTable.COLUMN_SUBTITLE };
CursorLoader cursorLoader = new CursorLoader(getApplicationContext(), FieldDBUserContentProvider.CONTENT_URI, userProjection, null,
null, null);
Cursor cursor = cursorLoader.loadInBackground();
if (cursor == null) {
Log.e(Config.TAG, "there was no user");
return;
}
cursor.moveToFirst();
String _id = "";
String username = "default";
if (cursor.getCount() > 0) {
_id = cursor.getString(cursor.getColumnIndexOrThrow(UserTable.COLUMN_ID));
String _rev = cursor.getString(cursor.getColumnIndexOrThrow(UserTable.COLUMN_REV));
username = cursor.getString(cursor.getColumnIndexOrThrow(UserTable.COLUMN_USERNAME));
String firstname = cursor.getString(cursor.getColumnIndexOrThrow(UserTable.COLUMN_FIRSTNAME));
String lastname = cursor.getString(cursor.getColumnIndexOrThrow(UserTable.COLUMN_LASTNAME));
String email = cursor.getString(cursor.getColumnIndexOrThrow(UserTable.COLUMN_EMAIL));
String gravatar = cursor.getString(cursor.getColumnIndexOrThrow(UserTable.COLUMN_GRAVATAR));
String affiliation = cursor.getString(cursor.getColumnIndexOrThrow(UserTable.COLUMN_AFFILIATION));
String researchInterest = cursor.getString(cursor.getColumnIndexOrThrow(UserTable.COLUMN_RESEARCH_INTEREST));
String description = cursor.getString(cursor.getColumnIndexOrThrow(UserTable.COLUMN_DESCRIPTION));
String subtitle = cursor.getString(cursor.getColumnIndexOrThrow(UserTable.COLUMN_SUBTITLE));
String actualJSON = "";
mUser = new User(_id, _rev, username, firstname, lastname, email, gravatar, affiliation, researchInterest, description, subtitle,
null, actualJSON);
if (!BuildConfig.DEBUG)
ACRA.getErrorReporter().putCustomData("username", username);
Config.CURRENT_USERNAME = username;
} else {
Log.e(Config.TAG, "There is no user... this is a problme the app wont work.");
if (!BuildConfig.DEBUG)
ACRA.getErrorReporter().putCustomData("username", "unknown");
}
/* Make the default corpus point to the user's own corpus */
Config.DEFAULT_CORPUS = Config.DEFAULT_CORPUS.replace("username", username);
Config.CURRENT_USERNAME = username;
Config.DEFAULT_OUTPUT_DIRECTORY = "/sdcard/" + Config.DATA_IS_ABOUT_LANGUAGE_NAME_ASCII + "-" + Config.APP_TYPE + "/"
+ Config.DEFAULT_CORPUS;
(new File(Config.DEFAULT_OUTPUT_DIRECTORY)).mkdirs();

if (!BuildConfig.DEBUG) {
ACRA.getErrorReporter().putCustomData("dbname", Config.DEFAULT_CORPUS);
}

Log.d(Config.TAG, cursor.getString(cursor.getColumnIndexOrThrow(UserTable.COLUMN_USERNAME)));
cursor.close();

/*
* If we are in debug mode, or the user is connected to wifi, download
* updates for samples and also register the user if they weren't registered
* before
*/
ConnectivityManager connManager = (ConnectivityManager) getApplicationContext().getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo wifi = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
if (Config.APP_TYPE.equals("speechrecognition")) {
Log.d(Config.TAG, "Not downloading samples, they are included in the training app");

String[] datumProjection = { UserTable.COLUMN_ID };
CursorLoader loader = new CursorLoader(getApplicationContext(), DatumContentProvider.CONTENT_URI, datumProjection, null, null, null);
Cursor datumCursor = loader.loadInBackground();
if (datumCursor.getCount() == 0) {
getContentResolver().insert(DatumContentProvider.CONTENT_URI, DatumTable.sampleData());
Intent updateSMSSamples = new Intent(getApplicationContext(), KartuliSMSCorpusService.class);
getApplicationContext().startService(updateSMSSamples);
}
datumCursor.close();
} else {
if (wifi.isConnected() || Config.D) {
Intent updateSamples = new Intent(getApplicationContext(), DownloadDatumsService.class);
getApplicationContext().startService(updateSamples);
}
}
if (mUser.get_rev() == null || "".equals(mUser.get_rev())) {
Intent registerUser = new Intent(getApplicationContext(), RegisterUserService.class);
registerUser.setData(Uri.parse(FieldDBUserContentProvider.CONTENT_URI + "/" + _id));
getApplicationContext().startService(registerUser);
}

}

/**
* Forces the locale for the duration of the app to the language needed for
* that version of the Experiment. It accepts a variable in the form en or
* en-US containing just the language code, or the language code followed by a
* - and the co
*
* @param lang
* @return
*/
public String forceLocale(String lang) {
if (lang.equals(Locale.getDefault().getLanguage())) {
return Locale.getDefault().getDisplayLanguage();
}
Configuration config = this.getBaseContext().getResources().getConfiguration();
Locale locale;
if (lang.contains("-")) {
String[] langCountrycode = lang.split("-");
locale = new Locale(langCountrycode[0], langCountrycode[1]);
} else {
locale = new Locale(lang);
}
Locale.setDefault(locale);
config.locale = locale;
this.getBaseContext().getResources().updateConfiguration(config, this.getBaseContext().getResources().getDisplayMetrics());

return Locale.getDefault().getDisplayLanguage();
}
}
33 changes: 0 additions & 33 deletions src/com/github/fielddb/lessons/Config.java

This file was deleted.

35 changes: 0 additions & 35 deletions src/com/github/fielddb/lessons/PrivateConstantsSample.java

This file was deleted.

Loading

0 comments on commit 93a0ebb

Please sign in to comment.