Skip to content

Commit

Permalink
A13 Notifications update
Browse files Browse the repository at this point in the history
* added POST_NOTIFICATIONS permissions for Android 13+
  • Loading branch information
AwaisKing committed Jun 12, 2023
1 parent e2a2124 commit ff753a6
Show file tree
Hide file tree
Showing 10 changed files with 101 additions and 40 deletions.
10 changes: 10 additions & 0 deletions .idea/deploymentTargetDropDown.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ android {
minSdk 19
targetSdk 33

versionCode 126
versionName '12.6'
versionCode 127
versionName '12.7'

multiDexEnabled true

Expand Down
6 changes: 4 additions & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@
</queries>

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

<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />

Expand All @@ -24,6 +25,7 @@
<application
android:name=".LinkedApp"
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_descriptor"
android:hardwareAccelerated="true"
android:icon="@mipmap/ic_launcher"
Expand Down Expand Up @@ -89,8 +91,8 @@
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />

<action android:name="android.intent.action.WEB_SEARCH" />
<action android:name="android.intent.action.SEARCH" />
<action android:name="android.intent.action.WEB_SEARCH" />
<action android:name="com.google.android.gms.actions.SEARCH_ACTION" />
</intent-filter>

Expand Down
38 changes: 21 additions & 17 deletions app/src/main/java/awais/backworddictionary/Main.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package awais.backworddictionary;

import android.Manifest;
import android.app.Activity;
import android.content.Context;
import android.content.DialogInterface;
Expand Down Expand Up @@ -38,7 +39,6 @@
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;

import com.applovin.sdk.AppLovinSdk;
import com.google.android.material.appbar.AppBarLayout;
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
import com.google.android.material.tabs.TabLayout;
Expand Down Expand Up @@ -75,7 +75,6 @@ public final class Main extends AppCompatActivity implements FragmentLoader, Mai
static {
AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);
}

public static final int TTS_DATA_CHECK_CODE = 775;
static final TTSRefresher ttsRefresher = () -> onTTSInit(TextToSpeech.SUCCESS);
private static final int[] tabs = {R.string.reverse, R.string.sounds_like, R.string.spelled_like, R.string.synonyms, R.string.antonyms,
Expand Down Expand Up @@ -126,8 +125,7 @@ protected void onCreate(final Bundle savedInstanceState) {
final Context context = viewGroup.getContext();
final View view = new View(context, null, 0);
view.setBackgroundColor(ContextCompat.getColor(context, R.color.colorPrimary));
view.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
Utils.statusBarHeight));
view.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, Utils.statusBarHeight));
view.setFocusableInTouchMode(false);
view.setLongClickable(true);
view.setFocusable(false);
Expand Down Expand Up @@ -187,14 +185,16 @@ protected void onCreate(final Bundle savedInstanceState) {
}
mainBinding.fabOptions.toggle();
}).setMenuToggleListener(opened -> {
if (!opened) {
fabParams.height = ViewGroup.LayoutParams.WRAP_CONTENT;
fabParams.width = ViewGroup.LayoutParams.WRAP_CONTENT;
mainBinding.fabOptions.setLayoutParams(fabParams);
}
if (opened) return;
fabParams.height = ViewGroup.LayoutParams.WRAP_CONTENT;
fabParams.width = ViewGroup.LayoutParams.WRAP_CONTENT;
mainBinding.fabOptions.setLayoutParams(fabParams);
});
TooltipCompat.setTooltipText(mainBinding.fabOptions, getString(R.string.options));

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU)
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.POST_NOTIFICATIONS}, 696969);

loadFragments(true);
setSearchView();
handleData();
Expand Down Expand Up @@ -259,7 +259,7 @@ else if (prevItem.title != null && !prevItem.title.isEmpty()) {
}

@Override
public void onTabUnselected(final TabLayout.Tab tab) { prevTab = tab.getPosition(); }
public void onTabUnselected(final TabLayout.Tab tab) {prevTab = tab.getPosition();}

@Override
public void onTabReselected(final TabLayout.Tab tab) {}
Expand Down Expand Up @@ -334,8 +334,12 @@ public void onActivityResult(final int requestCode, final int resultCode, final
ttsErrorDialog = new MaterialAlertDialogBuilder(this, R.style.MaterialAlertDialogTheme).create();
ttsErrorDialog.setTitle(R.string.tts_not_initialized);
ttsErrorDialog.setMessage(getString(R.string.tts_data_not_found));
ttsErrorDialog.setButton(DialogInterface.BUTTON_NEGATIVE, getString(R.string.no),
(DialogInterface.OnClickListener) null);
ttsErrorDialog.setButton(DialogInterface.BUTTON_NEGATIVE, getString(R.string.no), (DialogInterface.OnClickListener) null);
ttsErrorDialog.setButton(DialogInterface.BUTTON_NEUTRAL, getString(R.string.dont_show_again), (d, w) -> {
SettingsHelper.setTTSErrorDialogHidden();
ttsErrorDialog.cancel();
ttsErrorDialog = null;
});
ttsErrorDialog.setButton(DialogInterface.BUTTON_POSITIVE, getString(R.string.ok), (d, w) -> {
ttsErrorDialog = null;
startActivity(new Intent(TextToSpeech.Engine.ACTION_INSTALL_TTS_DATA));
Expand All @@ -358,7 +362,7 @@ public void onActivityResult(final int requestCode, final int resultCode, final
}

@Override
public boolean onCreateOptionsMenu(final Menu menu) {
public boolean onCreateOptionsMenu(@NonNull final Menu menu) {
getMenuInflater().inflate(R.menu.menu, menu);
return true;
}
Expand Down Expand Up @@ -612,7 +616,7 @@ public static synchronized void onTTSInit(final int initStatus) {
isTTSAsyncRunning = true;

final String defaultEngine = tts.getDefaultEngine();
final Locale defaultLanguage = Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2 ? tts.getDefaultLanguage() : null;
final Locale defaultLanguage = tts.getDefaultLanguage();
Voice defaultVoice;
try {
defaultVoice = Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP ? tts.getDefaultVoice() : null;
Expand Down Expand Up @@ -645,7 +649,7 @@ public static synchronized void onTTSInit(final int initStatus) {

if (setEngine) engine = ttsEngine;

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2 && setLanguage) {
if (setLanguage) {
final List<Locale> languages = new ArrayList<>(0);
final List<Locale> locales = Arrays.asList(Locale.getAvailableLocales());
Collection<Locale> localeCollection;
Expand Down Expand Up @@ -674,9 +678,9 @@ public static synchronized void onTTSInit(final int initStatus) {
}
}

//noinspection deprecation
// noinspection deprecation
tts.setEngineByPackageName(engine);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) tts.setLanguage(language);
tts.setLanguage(language);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && voice != null) tts.setVoice(voice);

isTTSAsyncRunning = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public final class SettingsHelper {
private static final String KEY_SHOW_FLOATING_DIALOG = "showFloatingDialog";
private static final String KEY_SHOW_DEFS_POPUP = "showDefsPopup";
////////////////////////////////////////////////
private static final String KEY_TTS_ERROR_DLG_HIDDEN = "ttsErrorDialogHidden";
private static final String KEY_TTS_DLG_SEEN = "ttsDialogShown";
private static final String KEY_TTS_PITCH = "ttsPitch";
private static final String KEY_TTS_RATE = "ttsRate";
Expand All @@ -39,14 +40,11 @@ public final class SettingsHelper {
private static SharedPreferences preferences;

public static void setPreferences(@NonNull final Context context) {
if (preferences == null)
preferences = context.getSharedPreferences("settings", Context.MODE_PRIVATE);
if (preferences == null) preferences = context.getSharedPreferences("settings", Context.MODE_PRIVATE);

final ContentResolver contentResolver = context.getContentResolver();
defaultPitch = Settings.Secure.getInt(contentResolver, Settings.Secure.TTS_DEFAULT_PITCH,
FALLBACK_TTS_DEFAULT_PITCH);
defaultRate = Settings.Secure.getInt(contentResolver, Settings.Secure.TTS_DEFAULT_RATE,
FALLBACK_TTS_DEFAULT_RATE);
defaultPitch = Settings.Secure.getInt(contentResolver, Settings.Secure.TTS_DEFAULT_PITCH, FALLBACK_TTS_DEFAULT_PITCH);
defaultRate = Settings.Secure.getInt(contentResolver, Settings.Secure.TTS_DEFAULT_RATE, FALLBACK_TTS_DEFAULT_RATE);
}

public static int getNightMode() {
Expand Down Expand Up @@ -93,6 +91,10 @@ public static boolean isTTSHelpDialogSeen() {
return preferences != null && preferences.getBoolean(KEY_TTS_DLG_SEEN, false);
}

public static boolean isTTSErrorDialogHidden() {
return preferences != null && preferences.getBoolean(KEY_TTS_ERROR_DLG_HIDDEN, false);
}

public static int getTTSPitch() {
return preferences != null ? preferences.getInt(KEY_TTS_PITCH, defaultPitch) : defaultPitch;
}
Expand Down Expand Up @@ -191,8 +193,11 @@ public static void setTTSEngine(final String ttsEngine) {
}

public static void setTTSHelpDialogSeen() {
if (preferences != null)
preferences.edit().putBoolean(KEY_TTS_DLG_SEEN, true).apply();
if (preferences != null) preferences.edit().putBoolean(KEY_TTS_DLG_SEEN, true).apply();
}

public static void setTTSErrorDialogHidden() {
if (preferences != null) preferences.edit().putBoolean(KEY_TTS_ERROR_DLG_HIDDEN, true).apply();
}

public static void resetTTS() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@
public final class TextProcessHelper extends Activity {
private static BubbleHelper bubbleHelper;
private boolean isFound = false, dataHandled = false;
private AwaisomeDialog awaisomeDialog = null;
private AwaisomeDialog awaisomeDialog;
private NotificationChannel channel;
private Intent intent;
private Context context;
private Intent intent;

public FloatingDialogView floatingDialogView = null;

Expand Down Expand Up @@ -218,7 +218,7 @@ else if (o instanceof ClipData && (clipData = (ClipData) o).getItemCount() > 0
final boolean showFloatingDialog = SettingsHelper.showFloatingDialog();
final boolean showFloating = SettingsHelper.showFloating();

//Log.d("AWAISKING_APP", "isBubbles:" + isBubbles
// Log.d("AWAISKING_APP", "isBubbles:" + isBubbles
// + " -- showFloating:" + showFloating
// + " -- bubblesApiEnabled:" + bubblesApiEnabled
// + " -- canBubble: " + (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q && channel != null && channel.canBubble())
Expand All @@ -238,7 +238,7 @@ else if (o instanceof ClipData && (clipData = (ClipData) o).getItemCount() > 0
isBubbles |= bubblesApiEnabledIntrl && Intent.ACTION_SEND.equals(action) || isProcessText;
handleFallback = bubbleHelper == null || channel == null || !channel.canBubble() || !isBubbles && !bubblesApiEnabledIntrl;

//Log.d("AWAISKING_APP", "isBubbles: " + isBubbles
// Log.d("AWAISKING_APP", "isBubbles: " + isBubbles
// + " -- bubblesApiEnabledIntrl: " + bubblesApiEnabledIntrl
// + " -- fallback: " + handleFallback);
}
Expand Down
5 changes: 3 additions & 2 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@
<string name="about">About Me</string>

<string name="ok">OK</string>
<string name="cancel">Cancel</string>
<string name="yes">Yes</string>
<string name="no">No</string>
<string name="yes">Yes</string>
<string name="cancel">Cancel</string>
<string name="close">Close</string>
<string name="dont_show_again">Don\'t show again</string>

<string name="filter_settings">Filter Settings</string>
<string name="max_words">Max Words</string>
Expand Down
16 changes: 12 additions & 4 deletions app/src/main/res/xml/backup_descriptor.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<full-backup-content>
<include domain="sharedpref" path="settings.xml" />
<include domain="sharedpref" path="settings" />
<include domain="database" path="search_history_database.db" />
<include domain="database" path="search_history_database" />
<include
domain="sharedpref"
path="settings" />
<include
domain="sharedpref"
path="settings.xml" />
<include
domain="database"
path="search_history_database" />
<include
domain="database"
path="search_history_database.db" />
</full-backup-content>
31 changes: 31 additions & 0 deletions app/src/main/res/xml/data_extraction_rules.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?xml version="1.0" encoding="utf-8"?>
<data-extraction-rules>
<local-backup>
<include
domain="sharedpref"
path="settings" />
<include
domain="sharedpref"
path="settings.xml" />
<include
domain="database"
path="search_history_database" />
<include
domain="database"
path="search_history_database.db" />
</local-backup>
<cloud-backup>
<include
domain="sharedpref"
path="settings" />
<include
domain="sharedpref"
path="settings.xml" />
<include
domain="database"
path="search_history_database" />
<include
domain="database"
path="search_history_database.db" />
</cloud-backup>
</data-extraction-rules>

0 comments on commit ff753a6

Please sign in to comment.