Fix compatibility with Android 3.0

Incompatible APIs were used in the custom layouts and the extra keys
options.

Add @TargetApi annotations to help catch similar issues in the future
with the help of 'gradle lint'.
This commit is contained in:
Jules Aguillon 2024-02-10 17:33:42 +01:00
parent 332413ed3c
commit d5676d683f
5 changed files with 11 additions and 3 deletions

View File

@ -1,5 +1,6 @@
package juloo.keyboard2;
import android.annotation.TargetApi;
import android.content.Context;
import android.content.SharedPreferences;
import android.os.Build.VERSION;
@ -7,6 +8,7 @@ import android.preference.PreferenceManager;
import java.util.Map;
import java.util.Set;
@TargetApi(24)
public final class DirectBootAwarePreferences
{
/* On API >= 24, preferences are read from the device protected storage. This

View File

@ -1,5 +1,6 @@
package juloo.keyboard2;
import android.annotation.TargetApi;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
@ -118,6 +119,7 @@ public class Keyboard2 extends InputMethodService
return Arrays.asList();
}
@TargetApi(12)
private ExtraKeys extra_keys_of_subtype(InputMethodSubtype subtype)
{
String extra_keys = subtype.getExtraValueOf("extra_keys");
@ -127,6 +129,7 @@ public class Keyboard2 extends InputMethodService
return ExtraKeys.EMPTY;
}
@TargetApi(12)
private void refreshAccentsOption(InputMethodManager imm, InputMethodSubtype subtype)
{
List<InputMethodSubtype> enabled_subtypes = getEnabledSubtypes(imm);

View File

@ -1,5 +1,6 @@
package juloo.keyboard2;
import android.annotation.TargetApi;
import android.app.Activity;
import android.content.Intent;
import android.media.AudioManager;
@ -31,7 +32,7 @@ public class LauncherActivity extends Activity
_intro_video = (VideoView)findViewById(R.id.launcher_intro_video);
_tryhere_text = (TextView)findViewById(R.id.launcher_tryhere_text);
_tryhere_area = (EditText)findViewById(R.id.launcher_tryhere_area);
if (VERSION.SDK_INT > 28)
if (VERSION.SDK_INT >= 28)
_tryhere_area.addOnUnhandledKeyEventListener(
this.new Tryhere_OnUnhandledKeyEventListener());
setup_intro_video(_intro_video);
@ -76,6 +77,7 @@ public class LauncherActivity extends Activity
v.start();
}
@TargetApi(28)
final class Tryhere_OnUnhandledKeyEventListener implements View.OnUnhandledKeyEventListener
{
public boolean onUnhandledKeyEvent(View v, KeyEvent ev)

View File

@ -51,7 +51,7 @@ public class CustomExtraKeysPreference extends ListGroupPreference<String>
void select(final SelectionCallback<String> callback)
{
new AlertDialog.Builder(getContext())
.setView(R.layout.dialog_edit_text)
.setView(View.inflate(getContext(), R.layout.dialog_edit_text, null))
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener(){
public void onClick(DialogInterface dialog, int which)
{

View File

@ -7,6 +7,7 @@ import android.content.SharedPreferences;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.view.View;
import android.widget.ArrayAdapter;
import java.util.ArrayList;
import java.util.Arrays;
@ -149,7 +150,7 @@ public class LayoutsPreference extends ListGroupPreference<LayoutsPreference.Lay
{
ArrayAdapter layouts = new ArrayAdapter(getContext(), android.R.layout.simple_list_item_1, _layout_display_names);
new AlertDialog.Builder(getContext())
.setView(R.layout.dialog_edit_text)
.setView(View.inflate(getContext(), R.layout.dialog_edit_text, null))
.setAdapter(layouts, new DialogInterface.OnClickListener(){
public void onClick(DialogInterface _dialog, int which)
{