io.appium.settings 4.1.0 → 4.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Binary file
package/app/build.gradle CHANGED
@@ -6,8 +6,8 @@ android {
6
6
  defaultConfig {
7
7
  minSdkVersion 18
8
8
  targetSdkVersion 30
9
- versionCode 44
10
- versionName "4.1.0"
9
+ versionCode 47
10
+ versionName "4.2.0"
11
11
  applicationId "io.appium.settings"
12
12
  }
13
13
 
@@ -206,7 +206,7 @@ public class Settings extends Activity {
206
206
  private void finishActivity() {
207
207
  Log.d(TAG, "Closing the app");
208
208
  Handler handler = new Handler();
209
- handler.postDelayed(Settings.this::finish, 1000);
209
+ handler.postDelayed(Settings.this::finish, 0);
210
210
  }
211
211
 
212
212
  @Override
@@ -26,6 +26,8 @@ import android.util.Log;
26
26
 
27
27
  import org.apache.commons.lang3.LocaleUtils;
28
28
 
29
+ import java.util.ArrayList;
30
+ import java.util.List;
29
31
  import java.util.Locale;
30
32
 
31
33
  import io.appium.settings.handlers.LocaleSettingHandler;
@@ -54,7 +56,7 @@ public class LocaleSettingReceiver extends BroadcastReceiver implements HasActio
54
56
  // Expect https://developer.android.com/reference/java/util/Locale.html#Locale(java.lang.String,%20java.lang.String) format.
55
57
  Locale locale = new Locale(language, country);
56
58
  String script = intent.getStringExtra(SCRIPT);
57
- if (!isBlank(script)) {
59
+ if (script != null) {
58
60
  if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
59
61
  locale = new Locale.Builder().setLocale(locale).setScript(script).build();
60
62
  } else {
@@ -63,13 +65,32 @@ public class LocaleSettingReceiver extends BroadcastReceiver implements HasActio
63
65
  }
64
66
  }
65
67
  if (!LocaleUtils.isAvailableLocale(locale)) {
66
- Log.e(TAG, String.format(
67
- "The locale %s is not known. Only the following locales are available: %s",
68
- locale, LocaleUtils.availableLocaleList())
69
- );
70
- setResultCode(Activity.RESULT_CANCELED);
71
- setResultData(String.format("The locale %s is not known", locale));
72
- return;
68
+ List<Locale> approximateMatchesLc = matchLocales(language, country);
69
+ if (!approximateMatchesLc.isEmpty() && isBlank(script)) {
70
+ Log.i(TAG, String.format(
71
+ "The locale %s is not known. Selecting the closest known one %s instead",
72
+ locale, approximateMatchesLc.get(0))
73
+ );
74
+ locale = approximateMatchesLc.get(0);
75
+ } else {
76
+ List<Locale> approximateMatchesL = matchLocales(language);
77
+ if (approximateMatchesL.isEmpty()) {
78
+ Log.e(TAG, String.format(
79
+ "The locale %s is not known. Only the following locales are available: %s",
80
+ locale, LocaleUtils.availableLocaleList())
81
+ );
82
+ } else {
83
+ Log.e(TAG, String.format(
84
+ "The locale %s is not known. " +
85
+ "The following locales are available for the %s language: %s" +
86
+ "The following locales are available altogether: %s",
87
+ locale, language, approximateMatchesL, LocaleUtils.availableLocaleList())
88
+ );
89
+ }
90
+ setResultCode(Activity.RESULT_CANCELED);
91
+ setResultData(String.format("The locale %s is not known", locale));
92
+ return;
93
+ }
73
94
  }
74
95
 
75
96
  new LocaleSettingHandler(context).setLocale(locale);
@@ -82,4 +103,25 @@ public class LocaleSettingReceiver extends BroadcastReceiver implements HasActio
82
103
  public String getAction() {
83
104
  return ACTION;
84
105
  }
106
+
107
+ private static List<Locale> matchLocales(String language) {
108
+ List<Locale> matches = new ArrayList<>();
109
+ for (Locale locale: LocaleUtils.availableLocaleList()) {
110
+ if (locale.getLanguage().equalsIgnoreCase(language)) {
111
+ matches.add(locale);
112
+ }
113
+ }
114
+ return matches;
115
+ }
116
+
117
+ private static List<Locale> matchLocales(String language, String country) {
118
+ List<Locale> matches = new ArrayList<>();
119
+ for (Locale locale: LocaleUtils.availableLocaleList()) {
120
+ if (locale.getLanguage().equalsIgnoreCase(language)
121
+ && locale.getCountry().equalsIgnoreCase(country)) {
122
+ matches.add(locale);
123
+ }
124
+ }
125
+ return matches;
126
+ }
85
127
  }
package/index.js CHANGED
@@ -1,5 +1,3 @@
1
- "use strict";
2
-
3
1
  const path = require('path');
4
2
 
5
3
  module.exports = {
package/package.json CHANGED
@@ -1,11 +1,13 @@
1
1
  {
2
2
  "name": "io.appium.settings",
3
- "version": "4.1.0",
3
+ "version": "4.2.0",
4
4
  "description": "App for dealing with Android settings",
5
5
  "main": "index.js",
6
6
  "scripts": {
7
- "bump-gradle-version": "gulp gradle-version-update --package-version=${npm_package_version} && git add app/build.gradle",
7
+ "bump-gradle-version": "node scripts/gradle-version-update.js --package-version=${npm_package_version} && git add app/build.gradle",
8
8
  "lint": "./gradlew lint",
9
+ "js:lint": "eslint .",
10
+ "js:lint:fix": "npm run lint -- --fix",
9
11
  "move-apks": "rm -rf apks && mkdir -p apks && cp app/build/outputs/apk/debug/settings_apk-debug.apk apks",
10
12
  "build": "./gradlew clean assembleDebug && npm run move-apks",
11
13
  "prepare": "npm run build",
@@ -16,6 +18,10 @@
16
18
  "type": "git",
17
19
  "url": "https://github.com/appium/io.appium.settings.git"
18
20
  },
21
+ "engines": {
22
+ "node": ">=14",
23
+ "npm": ">=8"
24
+ },
19
25
  "keywords": [
20
26
  "appium",
21
27
  "android",
@@ -33,16 +39,18 @@
33
39
  "!.DS_Store",
34
40
  "NOTICE.txt"
35
41
  ],
36
- "author": "https://github.com/appium",
42
+ "author": "Appium Contributors",
37
43
  "license": "Apache-2.0",
38
44
  "bugs": {
39
45
  "url": "https://github.com/appium/io.appium.settings/issues"
40
46
  },
41
47
  "homepage": "https://github.com/appium/io.appium.settings",
42
48
  "devDependencies": {
43
- "@appium/gulp-plugins": "^7.0.0",
49
+ "@appium/eslint-config-appium": "^6.0.0",
50
+ "eslint": "^7.32.0",
51
+ "fancy-log": "^2.0.0",
44
52
  "@semantic-release/git": "^10.0.1",
45
- "gulp": "^4.0.0",
46
- "semantic-release": "^19.0.2"
53
+ "semantic-release": "^19.0.2",
54
+ "semver": "^7.3.7"
47
55
  }
48
56
  }