Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
ag2s20150909 committed May 14, 2024
1 parent a1626b7 commit a05e954
Show file tree
Hide file tree
Showing 27 changed files with 21,205 additions and 21,066 deletions.
21 changes: 11 additions & 10 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ static def releaseTime() {
}

android {
compileSdk 33
buildToolsVersion = '33.0.0'
compileSdk 34
buildToolsVersion = '34.0.0'
//签名设置
signingConfigs {
release {
Expand Down Expand Up @@ -92,7 +92,7 @@ android {

}

tasks.whenTaskAdded {task ->
tasks.configureEach { task ->
//新版的AGP7.1.0修改apk输出路径会导致文件找不到而出错(硬编码???),暂时禁用这个task
// if(task.name.contains("createReleaseApkListingFileRedirect")) {
// //task.enabled = false
Expand All @@ -103,7 +103,8 @@ tasks.whenTaskAdded {task ->
}


task syncMappingFile(type: Sync){
tasks.register('syncMappingFile', Sync) {
dependsOn('minifyReleaseWithR8')
from "$projectDir/build/outputs/mapping/release"
into "$rootDir/release/mapping"
exclude("configuration.txt")
Expand All @@ -113,14 +114,14 @@ task syncMappingFile(type: Sync){
}


task syncApkFile(type: Sync) {
tasks.register('syncApkFile', Sync) {
dependsOn syncMappingFile
from "$projectDir/build/outputs/apk/release"
into "$rootDir/release"
exclude("logs/**")
exclude("sdk-dependencies/**")
//保护下面的不会被删除
preserve{
preserve {
include("mapping/**")
}
}
Expand All @@ -129,11 +130,11 @@ task syncApkFile(type: Sync) {

dependencies {

compileOnly "com.android.tools.build:gradle:$agp_version"
//compileOnly "com.android.tools.build:gradle:$agp_version"

//coreLibraryDesugaring('com.android.tools:desugar_jdk_libs:1.1.5')

implementation "androidx.recyclerview:recyclerview:1.2.1"
implementation "androidx.recyclerview:recyclerview:1.3.2"
//implementation 'org.conscrypt:conscrypt-android:2.5.2'
//An HTTP & HTTP/2 client for Android and Java applications.
implementation "com.squareup.okhttp3:okhttp:$okhttp_version"
Expand All @@ -143,8 +144,8 @@ dependencies {

testImplementation 'junit:junit:4.13.2'

androidTestImplementation 'androidx.test.ext:junit:1.1.4'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.0'
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'

}

6 changes: 5 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,11 @@
<uses-permission
android:name="android.permission.WRITE_EXTERNAL_STORAGE"
tools:ignore="ScopedStorage" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission
android:name="android.permission.READ_EXTERNAL_STORAGE"
android:maxSdkVersion="32" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_MEDIA_PLAYBACK" />
<!-- 请求忽略电池优化 -->
<uses-permission android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
Expand Down Expand Up @@ -90,6 +93,7 @@
<service
android:name=".services.TTSService"
android:exported="true"
android:foregroundServiceType="mediaPlayback"
android:label="@string/app_name"
tools:ignore="ExportedService,UnusedAttribute">
<intent-filter android:priority="1000">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

import android.util.Log;

import androidx.annotation.Keep;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
Expand All @@ -27,6 +29,7 @@

import okhttp3.Cookie;

@Keep
public class SerializableCookie implements Serializable {
private static final String TAG = SerializableCookie.class.getSimpleName();

Expand Down
19 changes: 18 additions & 1 deletion app/src/main/java/me/ag2s/tts/APP.java
Original file line number Diff line number Diff line change
Expand Up @@ -231,11 +231,28 @@ private static Context initAndGetAppCtxWithReflection() {

}

private static void tryInstallGmsSsl(Context context) {
try {
Context gmsContext = context.createPackageContext("com.google.android.gms",
CONTEXT_INCLUDE_CODE | CONTEXT_IGNORE_SECURITY);
gmsContext.getClassLoader()
.loadClass("com.google.android.gms.common.security.ProviderInstallerImpl")
.getDeclaredMethod("insertProvider", Context.class)
.invoke(null, gmsContext);

} catch (Exception e) {
e.printStackTrace();

}
}


@Override
public void onCreate() {
super.onCreate();
//Security.insertProviderAt(Conscrypt.newProvider(), 1);
new Thread(() -> {
tryInstallGmsSsl(APP.this);
}).start();
mContext = this.getApplicationContext();
}

Expand Down
11 changes: 8 additions & 3 deletions app/src/main/java/me/ag2s/tts/GetSampleText.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,15 @@ protected void onCreate(Bundle savedInstanceState) {
Intent returnData = new Intent();

Intent i = getIntent();
String language = i.getExtras().getString("language");
String country = i.getExtras().getString("country");
String variant = i.getExtras().getString("variant");
Bundle bundle = i.getExtras();
if (bundle == null) return;

String language = bundle.getString("language");
String country = bundle.getString("country");
String variant = bundle.getString("variant");
Log.d(TAG, language + "_" + country + "_" + variant);

if (language == null || country == null) return;
Locale locale = new Locale(language, country);
returnData.putExtra(TextToSpeech.Engine.EXTRA_SAMPLE_TEXT, TtsVoiceSample.getByLocate(this, locale));
setResult(result, returnData);
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/me/ag2s/tts/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@

import me.ag2s.tts.adapters.TtsActorAdapter;
import me.ag2s.tts.adapters.TtsStyleAdapter;
import me.ag2s.tts.data.TtsActorManger;
import me.ag2s.tts.databinding.ActivityMainBinding;
import me.ag2s.tts.services.Constants;
import me.ag2s.tts.services.TtsActorManger;
import me.ag2s.tts.services.TtsDictManger;
import me.ag2s.tts.services.TtsFormatManger;
import me.ag2s.tts.services.TtsOutputFormat;
Expand Down Expand Up @@ -151,7 +151,7 @@ protected void onCreate(Bundle savedInstanceState) {
if (textToSpeech == null) {
connectToText2Speech();
}
Toast.makeText(MainActivity.this, "" + item.getShortName(), Toast.LENGTH_SHORT).show();
Toast.makeText(MainActivity.this, item.getShortName(), Toast.LENGTH_SHORT).show();
}

});
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/me/ag2s/tts/adapters/TtsActorAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import java.util.Locale;

import me.ag2s.tts.R;
import me.ag2s.tts.services.TtsActor;
import me.ag2s.tts.data.TtsActor;
import me.ag2s.tts.utils.CommonTool;

public class TtsActorAdapter extends RecyclerView.Adapter<TtsActorAdapter.ViewHolder> {
Expand Down Expand Up @@ -80,7 +80,7 @@ public void onBindViewHolder(@NotNull ViewHolder holder, int position) {
holder.itemView.setBackground(holder.itemView.getContext().getDrawable(R.drawable.unselect));
}
TtsActor data = mData.get(position);
holder.tv_title.setText(data.getName());
holder.tv_title.setText(data.getShortName());
Locale locale = data.getLocale();
//locale.getDisplayCountry(Locale.getDefault());
holder.tv_des.setText(String.format("%s%s\n%s", CommonTool.localeToEmoji(locale), locale.getDisplayLanguage(Locale.getDefault()), data.getNote()));
Expand Down
103 changes: 103 additions & 0 deletions app/src/main/java/me/ag2s/tts/data/TtsActor.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
package me.ag2s.tts.data;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import java.util.Locale;
import java.util.Objects;

public class TtsActor {
/**
* 标准名称
*/
@NonNull
private final String name;

/**
* 简写名称
*/
@NonNull
private final String shortName;
/**
* 性别,true 为女性,false为男性
*/
private final boolean gender;

/**
* 地区
*/
@NonNull
private final String locale;

/**
* 注释
*/
@Nullable
private final String note;

private Locale tempLocate;


public TtsActor(@NonNull String name, @NonNull String shortName, boolean gender, @NonNull String locale, @NonNull String note) {
this.name = name;
this.shortName = shortName;
this.gender = gender;
this.locale = locale;
this.note = note;
}


@NonNull
public String getName() {
return name;
}

@NonNull
public String getShortName() {
return shortName;
}

public boolean getGender() {
return gender;
}

@NonNull
public String getLocaleStr() {
return locale;
}

public Locale getLocale() {

if (tempLocate != null) {
return tempLocate;
}


String tag = "-";
if (locale.contains("-")) {
tag = "-";
} else if (locale.contains("_")) {
tag = "_";
}
String[] temp = locale.split(tag);
tempLocate = new Locale(temp[0], temp[1], gender ? "Female" : "Male");
return tempLocate;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
TtsActor ttsActor = (TtsActor) o;
return gender == ttsActor.gender && Objects.equals(name, ttsActor.name) && Objects.equals(shortName, ttsActor.shortName) && Objects.equals(locale, ttsActor.locale);
}

@Override
public int hashCode() {
return Objects.hash(name, shortName, gender, locale);
}

public Object getNote() {
return this.note;
}
}
71 changes: 71 additions & 0 deletions app/src/main/java/me/ag2s/tts/data/TtsActorComparator.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package me.ag2s.tts.data;

import java.util.Comparator;
import java.util.Locale;

public class TtsActorComparator implements Comparator<TtsActor> {

public static final TtsActorComparator INSTANCE = new TtsActorComparator();
private final Locale locale;

public TtsActorComparator() {
this.locale = Locale.getDefault();
}

public TtsActorComparator(Locale locale) {
this.locale = locale;
}

@Override
public int compare(TtsActor o1, TtsActor o2) {
Locale loc1 = o1.getLocale();
Locale loc2 = o2.getLocale();
boolean b11 = loc1.getISO3Language().equals(locale.getISO3Language());
boolean b12 = loc1.getISO3Country().equals(locale.getISO3Country());
boolean b13 = loc1.getDisplayVariant(Locale.US).equals(locale.getDisplayVariant(Locale.US));
boolean b21 = loc2.getISO3Language().equals(locale.getISO3Language());
boolean b22 = loc2.getISO3Country().equals(locale.getISO3Country());
boolean b23 = loc2.getDisplayVariant(Locale.US).equals(locale.getDisplayVariant(Locale.US));


if (b11 != b21) {
return b11 ? -1 : 1;
}
if (b12 != b22) {
return b12 ? -1 : 1;
}


// //语言都不同
// if ((!b11) && (!b21)) {
// return 0;
// }
// //两个都相同
// if (b11 && b12 && b13 == b21 && b22 && b23) {
// return 0;
// }
// if (b11 && b12 && b13) {
// return -1;
// }
// if (b21 && b22 && b23) {
// return 1;
// }
// if ((b11 && b12 == b21 && b22)) {
// if (b13 == b23) {
// return 0;
// }
// if (b13) {
// return -1;
// } else {
// return 1;
// }
// }
// if (b11 && b12) {
// return -1;
// }
// if (b21 && b22) {
// return 1;
// }
return 0;
}
}
Loading

0 comments on commit a05e954

Please sign in to comment.