Skip to content
This repository has been archived by the owner on May 19, 2023. It is now read-only.

Add ability to change various API parameters, cleanup, targetSdk 33 #9

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
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
11 changes: 9 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
*.iml
.gradle
/local.properties
/.idea
.DS_Store


/build
/captures
.externalNativeBuild
.cxx
local.properties
2 changes: 2 additions & 0 deletions CorrectorSoftcatala/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/build
/release
30 changes: 22 additions & 8 deletions CorrectorSoftcatala/build.gradle
Original file line number Diff line number Diff line change
@@ -1,22 +1,34 @@
apply plugin: 'com.android.application'
plugins {
id 'com.android.application'
}

gradle.projectsEvaluated {
tasks.withType(JavaCompile) {
options.compilerArgs << "-Xlint:deprecation"
}
}

android {
compileSdkVersion 26
compileSdk 33

defaultConfig {
applicationId "org.softcatala.corrector"
minSdkVersion 19
targetSdkVersion 26
minSdk 19
targetSdk 33
versionCode 11
versionName "1.0.10"
}

buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}

signingConfigs {
buildTypes {
Expand All @@ -31,6 +43,8 @@ android {
}

dependencies {
implementation 'com.android.support:appcompat-v7:26.+'
implementation 'com.android.support.constraint:constraint-layout:+'
}
implementation 'androidx.appcompat:appcompat:1.5.1'
implementation 'androidx.preference:preference:1.1.1' // latest 1.2.0 gives 'Duplicate class androidx.lifecycle.ViewModelLazy found in modules lifecycle-viewmodel-2.5.1-runtime'
implementation 'com.google.android.material:material:1.6.1'
implementation("androidx.constraintlayout:constraintlayout:2.1.4")
}
21 changes: 21 additions & 0 deletions CorrectorSoftcatala/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
30 changes: 10 additions & 20 deletions CorrectorSoftcatala/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,33 +1,22 @@
<?xml version="1.0" encoding="utf-8"?><!--
/**
* Copyright (c) 2011, The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-->
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="org.softcatala.corrector">

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name">
android:label="@string/app_name"
android:theme="@style/Theme.AppCompat.Light"
tools:targetApi="33">

<service
android:name=".LTSpellCheckerService"
android:label="@string/app_name"
android:permission="android.permission.BIND_TEXT_SERVICE">
android:permission="android.permission.BIND_TEXT_SERVICE"
android:exported="true">
<intent-filter>
<action android:name="android.service.textservice.SpellCheckerService" />
</intent-filter>
Expand All @@ -42,7 +31,8 @@
android:label="@string/sample_settings">

</activity>
<activity android:name=".WelcomeActivity">
<activity android:name=".WelcomeActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,27 @@
package org.softcatala.corrector;

import android.content.SharedPreferences;
import android.os.Build;
import android.preference.PreferenceManager;

import androidx.preference.PreferenceManager;

import java.util.Date;
import java.util.HashSet;
import java.util.Set;

public class Configuration {
private static final String languagetoolServerDefault = "https://api.languagetool.org";
private static final String languageDefault = "system";
private static final String motherTongueDefault = "";
private static final Set<String> preferredVariantsDefault = new HashSet<>();

private static volatile Configuration instance = null;
private static String PREF_DIALECT = "corrector.softcatala.dialect";
private static final String PREF_SERVER = "corrector.softcatala.server";
private static final String PREF_LANGUAGE = "corrector.softcatala.language";
private static final String PREF_MOTHER_TONGUE = "corrector.softcatala.mother_tongue";
private static final String PREF_PREFERRED_VARIANTS = "corrector.softcatala.preferred_variants";
private static int HttpConnections = 0;
private static Date LastConnection = null;
//public static SpellCheckerSettingsActivity SettingsActivity;
public static SpellCheckerSettingsActivity SettingsActivity;

public static synchronized Configuration getInstance() {
if (instance == null) {
Expand All @@ -41,23 +50,25 @@ public static synchronized Configuration getInstance() {
return instance;
}

/*public Boolean getDialect()
public String getServer()
{
boolean previousTo50 = Build.VERSION.SDK_INT <= Build.VERSION_CODES.KITKAT;

if (previousTo50)
return false;

SharedPreferences spref = PreferenceManager.getDefaultSharedPreferences(SettingsActivity);
Boolean dialect = spref.getBoolean(PREF_DIALECT, false);
return dialect;
if (SettingsActivity == null) {
return languagetoolServerDefault;
}
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(SettingsActivity);
return sharedPreferences.getString(PREF_SERVER, languagetoolServerDefault);
}

public void setDialect(Boolean dialect)
public String setServer(String server)
{
SharedPreferences spref = PreferenceManager.getDefaultSharedPreferences(SettingsActivity);
spref.edit().putBoolean(PREF_DIALECT, dialect).commit();
}*/
if (server.isEmpty()) {
server = languagetoolServerDefault;
}

SharedPreferences sharedPreference = PreferenceManager.getDefaultSharedPreferences(SettingsActivity);
sharedPreference.edit().putString(PREF_SERVER, server).apply();
return server;
}

public int getHttpConnections() {
return HttpConnections;
Expand All @@ -74,4 +85,49 @@ public Date getLastConnection() {
public void setLastConnection(Date date) {
LastConnection = date;
}

public String getLanguage()
{
if (SettingsActivity == null) {
return languageDefault;
}

SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(SettingsActivity);
return sharedPreferences.getString(PREF_LANGUAGE, languageDefault);
}

public String getMotherTongue()
{
if (SettingsActivity == null) {
return motherTongueDefault;
}

SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(SettingsActivity);
return sharedPreferences.getString(PREF_MOTHER_TONGUE, motherTongueDefault);
}

public Set<String> getPreferredVariants()
{
if (SettingsActivity == null) {
return preferredVariantsDefault;
}

SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(SettingsActivity);
return sharedPreferences.getStringSet(PREF_PREFERRED_VARIANTS, preferredVariantsDefault);
}

public void setLanguage(String language) {
SharedPreferences sharedPreference = PreferenceManager.getDefaultSharedPreferences(SettingsActivity);
sharedPreference.edit().putString(PREF_LANGUAGE, language).apply();
}

public void setMotherTongue(String motherTongue) {
SharedPreferences sharedPreference = PreferenceManager.getDefaultSharedPreferences(SettingsActivity);
sharedPreference.edit().putString(PREF_MOTHER_TONGUE, motherTongue).apply();
}

public void setPreferredVariants(Set<String> preferredVariants) {
SharedPreferences sharedPreference = PreferenceManager.getDefaultSharedPreferences(SettingsActivity);
sharedPreference.edit().putStringSet(PREF_PREFERRED_VARIANTS, preferredVariants).apply();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

package org.softcatala.corrector;

import android.os.Build;
import android.service.textservice.SpellCheckerService;
import android.util.Log;
import android.view.textservice.SentenceSuggestionsInfo;
Expand Down Expand Up @@ -56,23 +55,18 @@ public static int[] convertIntegers(ArrayList<Integer> integers) {
int[] ret = new int[integers.size()];
Iterator<Integer> iterator = integers.iterator();
for (int i = 0; i < ret.length; i++) {
ret[i] = iterator.next().intValue();
ret[i] = iterator.next();
}
return ret;
}

private boolean isSentenceSpellCheckApiSupported() {
// Note that the sentence level spell check APIs work on Jelly Bean or later.
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN;
}

@Override
public void onCreate() {
if (DBG) {
Log.d(TAG, "onCreate");
}
mLocale = getLocale();
mReportedErrors = new HashSet<String>();
mReportedErrors = new HashSet<>();
}

@Override
Expand Down Expand Up @@ -117,21 +111,15 @@ public SentenceSuggestionsInfo[] onGetSentenceSuggestionsMultiple(
TextInfo[] textInfos, int suggestionsLimit) {

try {
if (!isSentenceSpellCheckApiSupported()) {
Log.e(TAG, "Sentence spell check is not supported on this platform");
return null;
}

final ArrayList<SentenceSuggestionsInfo> retval = new ArrayList<SentenceSuggestionsInfo>();
for (int i = 0; i < textInfos.length; ++i) {
final TextInfo ti = textInfos[i];
final ArrayList<SentenceSuggestionsInfo> retval = new ArrayList<>();
for (final TextInfo ti : textInfos) {
if (DBG) {
Log.d(TAG, "onGetSentenceSuggestionsMultiple: " + ti.getText());
}

ArrayList<SuggestionsInfo> sis = new ArrayList<SuggestionsInfo>();
ArrayList<Integer> offsets = new ArrayList<Integer>();
ArrayList<Integer> lengths = new ArrayList<Integer>();
ArrayList<SuggestionsInfo> sis = new ArrayList<>();
ArrayList<Integer> offsets = new ArrayList<>();
ArrayList<Integer> lengths = new ArrayList<>();

removePreviouslyMarkedErrors(ti, sis, offsets, lengths);
getSuggestionsFromLT(ti, sis, offsets, lengths);
Expand Down Expand Up @@ -165,17 +153,17 @@ private void getSuggestionsFromLT(TextInfo ti, ArrayList<SuggestionsInfo> sis,
Suggestion[] suggestions = languageToolRequest
.GetSuggestions(input);

for (int s = 0; s < suggestions.length; s++) {
for (Suggestion suggestion : suggestions) {
SuggestionsInfo si = new SuggestionsInfo(
SuggestionsInfo.RESULT_ATTR_LOOKS_LIKE_TYPO,
suggestions[s].Text);
suggestion.Text);

si.setCookieAndSequence(ti.getCookie(), ti.getSequence());
sis.add(si);
offsets.add(suggestions[s].Position);
lengths.add(suggestions[s].Length);
String incorrectText = input.substring(suggestions[s].Position,
suggestions[s].Position + suggestions[s].Length);
offsets.add(suggestion.Position);
lengths.add(suggestion.Length);
String incorrectText = input.substring(suggestion.Position,
suggestion.Position + suggestion.Length);

if (mReportedErrors.size() < MAX_REPORTED_ERRORS_STORED) {
mReportedErrors.add(incorrectText);
Expand Down Expand Up @@ -213,7 +201,7 @@ private void removePreviouslyMarkedErrors(TextInfo ti, ArrayList<SuggestionsInfo
while (idx != -1) {

SuggestionsInfo siNone = new SuggestionsInfo(REMOVE_SPAN,
new String[]{new String()});
new String[]{""});
siNone.setCookieAndSequence(ti.getCookie(), ti.getSequence());
sis.add(siNone);
int len = txt.length();
Expand Down
Loading