Compatibility for api level 19

This commit is contained in:
MrLetsplay 2021-07-11 15:50:26 +02:00
parent 6433e841f3
commit 86cf510bca
12 changed files with 53 additions and 35 deletions

View File

@ -3,12 +3,12 @@ plugins {
} }
android { android {
compileSdkVersion 29 compileSdkVersion 30
defaultConfig { defaultConfig {
applicationId "de.jg_cody.Teraplex" applicationId "de.jg_cody.Teraplex"
minSdkVersion 16 minSdkVersion 19
targetSdkVersion 29 targetSdkVersion 30
versionCode 1 versionCode 1
versionName "1.0" versionName "1.0"
multiDexEnabled true multiDexEnabled true

View File

@ -24,6 +24,7 @@ import android.os.Vibrator;
import android.provider.MediaStore; import android.provider.MediaStore;
import android.text.SpannableString; import android.text.SpannableString;
import android.text.style.ForegroundColorSpan; import android.text.style.ForegroundColorSpan;
import android.util.Base64;
import android.util.TypedValue; import android.util.TypedValue;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.Menu; import android.view.Menu;
@ -57,7 +58,6 @@ import java.io.ByteArrayOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Base64;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
@ -85,14 +85,15 @@ public class MainActivity extends AppCompatActivity {
Map<String, MenuItem> tabitems = new HashMap<>(); Map<String, MenuItem> tabitems = new HashMap<>();
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); getWindow().clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
getWindow().setStatusBarColor(Color.TRANSPARENT); getWindow().setStatusBarColor(Color.TRANSPARENT);
getWindow().setNavigationBarColor(Color.BLUE); getWindow().setNavigationBarColor(Color.BLUE);
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
getWindow().setStatusBarContrastEnforced(false); getWindow().setStatusBarContrastEnforced(false);
} }
@ -477,7 +478,6 @@ public class MainActivity extends AppCompatActivity {
} }
@RequiresApi(api = Build.VERSION_CODES.O)
@Override @Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) { protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data); super.onActivityResult(requestCode, resultCode, data);
@ -505,7 +505,7 @@ public class MainActivity extends AppCompatActivity {
} }
Background.close(); Background.close();
SharedPreferences p = getSharedPreferences("appsettings", Context.MODE_PRIVATE); SharedPreferences p = getSharedPreferences("appsettings", Context.MODE_PRIVATE);
p.edit().putString("Background", Base64.getEncoder().encodeToString(bOut.toByteArray())).apply(); p.edit().putString("Background", Base64.encodeToString(bOut.toByteArray(), Base64.DEFAULT)).apply();
loadBackground(); loadBackground();
startActivity(getIntent()); startActivity(getIntent());
finish(); finish();
@ -517,12 +517,11 @@ public class MainActivity extends AppCompatActivity {
} }
@RequiresApi(api = Build.VERSION_CODES.O)
private void loadBackground() { private void loadBackground() {
SharedPreferences p = getSharedPreferences("appsettings", Activity.MODE_PRIVATE); SharedPreferences p = getSharedPreferences("appsettings", Activity.MODE_PRIVATE);
String Background = p.getString("Background", null); String Background = p.getString("Background", null);
ImageView I = findViewById(R.id.Background); ImageView I = findViewById(R.id.Background);
byte[] BA = Base64.getDecoder().decode(Background); byte[] BA = Base64.decode(Background, Base64.DEFAULT);
I.setImageBitmap(BitmapFactory.decodeByteArray(BA, 0, BA.length)); I.setImageBitmap(BitmapFactory.decodeByteArray(BA, 0, BA.length));
} }

View File

@ -6,6 +6,7 @@ import android.graphics.BitmapFactory;
import android.graphics.drawable.BitmapDrawable; import android.graphics.drawable.BitmapDrawable;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.util.Base64;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
@ -16,8 +17,6 @@ import androidx.annotation.RequiresApi;
import androidx.fragment.app.Fragment; import androidx.fragment.app.Fragment;
import androidx.lifecycle.ViewModelProvider; import androidx.lifecycle.ViewModelProvider;
import java.util.Base64;
import de.jg_cody.Teraplex.MainActivity; import de.jg_cody.Teraplex.MainActivity;
import de.jg_cody.Teraplex.R; import de.jg_cody.Teraplex.R;
@ -25,7 +24,6 @@ public class CreditsFragment extends Fragment {
private CreditsViewModel creditsViewModel; private CreditsViewModel creditsViewModel;
@RequiresApi(api = Build.VERSION_CODES.O)
public View onCreateView(@NonNull LayoutInflater inflater, public View onCreateView(@NonNull LayoutInflater inflater,
ViewGroup container, Bundle savedInstanceState) { ViewGroup container, Bundle savedInstanceState) {
creditsViewModel = creditsViewModel =
@ -35,7 +33,7 @@ public class CreditsFragment extends Fragment {
String Background = p.getString("Background", null); String Background = p.getString("Background", null);
if (Background != null) { if (Background != null) {
ImageView I = root.findViewById(R.id.Background); ImageView I = root.findViewById(R.id.Background);
byte[] BA = Base64.getDecoder().decode(Background); byte[] BA = Base64.decode(Background, Base64.DEFAULT);
I.setImageDrawable(new BitmapDrawable(getResources(), MainActivity.scaleCenterCrop(BitmapFactory.decodeByteArray(BA, 0, BA.length), MainActivity.getScreenHeight(), MainActivity.getScreenWidth()))); I.setImageDrawable(new BitmapDrawable(getResources(), MainActivity.scaleCenterCrop(BitmapFactory.decodeByteArray(BA, 0, BA.length), MainActivity.getScreenHeight(), MainActivity.getScreenWidth())));
I.setScaleType(ImageView.ScaleType.CENTER_CROP); I.setScaleType(ImageView.ScaleType.CENTER_CROP);
} }

View File

@ -13,6 +13,7 @@ import android.media.MediaPlayer;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.os.Vibrator; import android.os.Vibrator;
import android.util.Base64;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
@ -24,7 +25,6 @@ import androidx.annotation.RequiresApi;
import androidx.fragment.app.Fragment; import androidx.fragment.app.Fragment;
import androidx.lifecycle.ViewModelProvider; import androidx.lifecycle.ViewModelProvider;
import java.util.Base64;
import java.util.Locale; import java.util.Locale;
import java.util.Objects; import java.util.Objects;
@ -37,7 +37,6 @@ public class EinstellungenFragment extends Fragment {
private EinstellungenViewModel einstellungenViewModel; private EinstellungenViewModel einstellungenViewModel;
@RequiresApi(api = Build.VERSION_CODES.O)
public View onCreateView(@NonNull LayoutInflater inflater, public View onCreateView(@NonNull LayoutInflater inflater,
ViewGroup container, Bundle savedInstanceState) { ViewGroup container, Bundle savedInstanceState) {
einstellungenViewModel = einstellungenViewModel =
@ -47,7 +46,7 @@ public class EinstellungenFragment extends Fragment {
String Background = p.getString("Background", null); String Background = p.getString("Background", null);
if (Background != null) { if (Background != null) {
ImageView I = root.findViewById(R.id.Background); ImageView I = root.findViewById(R.id.Background);
byte[] BA = Base64.getDecoder().decode(Background); byte[] BA = Base64.decode(Background, Base64.DEFAULT);
I.setImageDrawable(new BitmapDrawable(getResources(), MainActivity.scaleCenterCrop(BitmapFactory.decodeByteArray(BA, 0, BA.length), MainActivity.getScreenHeight(), MainActivity.getScreenWidth()))); I.setImageDrawable(new BitmapDrawable(getResources(), MainActivity.scaleCenterCrop(BitmapFactory.decodeByteArray(BA, 0, BA.length), MainActivity.getScreenHeight(), MainActivity.getScreenWidth())));
I.setScaleType(ImageView.ScaleType.CENTER_CROP); I.setScaleType(ImageView.ScaleType.CENTER_CROP);
} }

View File

@ -11,6 +11,7 @@ import android.media.MediaPlayer;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.os.Vibrator; import android.os.Vibrator;
import android.util.Base64;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
@ -24,7 +25,6 @@ import androidx.annotation.RequiresApi;
import androidx.fragment.app.Fragment; import androidx.fragment.app.Fragment;
import androidx.lifecycle.ViewModelProvider; import androidx.lifecycle.ViewModelProvider;
import java.util.Base64;
import java.util.Objects; import java.util.Objects;
import de.jg_cody.Teraplex.MainActivity; import de.jg_cody.Teraplex.MainActivity;
@ -46,7 +46,6 @@ public class KonsoleFragment extends Fragment {
private KonsoleViewModel konsoleViewModel; private KonsoleViewModel konsoleViewModel;
@RequiresApi(api = Build.VERSION_CODES.O)
public View onCreateView(@NonNull LayoutInflater inflater, public View onCreateView(@NonNull LayoutInflater inflater,
ViewGroup container, Bundle savedInstanceState) { ViewGroup container, Bundle savedInstanceState) {
konsoleViewModel = konsoleViewModel =
@ -56,7 +55,7 @@ public class KonsoleFragment extends Fragment {
String Background = p.getString("Background", null); String Background = p.getString("Background", null);
if (Background != null) { if (Background != null) {
ImageView I = root.findViewById(R.id.Background); ImageView I = root.findViewById(R.id.Background);
byte[] BA = Base64.getDecoder().decode(Background); byte[] BA = Base64.decode(Background, Base64.DEFAULT);
I.setImageDrawable(new BitmapDrawable(getResources(), MainActivity.scaleCenterCrop(BitmapFactory.decodeByteArray(BA, 0, BA.length), MainActivity.getScreenHeight(), MainActivity.getScreenWidth()))); I.setImageDrawable(new BitmapDrawable(getResources(), MainActivity.scaleCenterCrop(BitmapFactory.decodeByteArray(BA, 0, BA.length), MainActivity.getScreenHeight(), MainActivity.getScreenWidth())));
I.setScaleType(ImageView.ScaleType.CENTER_CROP); I.setScaleType(ImageView.ScaleType.CENTER_CROP);
} }

View File

@ -8,6 +8,7 @@ import android.graphics.BitmapFactory;
import android.graphics.drawable.BitmapDrawable; import android.graphics.drawable.BitmapDrawable;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.util.Base64;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
@ -29,7 +30,6 @@ import org.json.JSONException;
import org.json.JSONObject; import org.json.JSONObject;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Base64;
import java.util.Objects; import java.util.Objects;
import de.jg_cody.Teraplex.AddButtonDialogSingle; import de.jg_cody.Teraplex.AddButtonDialogSingle;
@ -69,7 +69,6 @@ public class TabsFragment extends Fragment implements AddButtonDialogSingle.AddB
this.tabname = tabname; this.tabname = tabname;
} }
@RequiresApi(api = Build.VERSION_CODES.O)
public View onCreateView(@NonNull LayoutInflater inflater, public View onCreateView(@NonNull LayoutInflater inflater,
ViewGroup container, Bundle savedInstanceState) { ViewGroup container, Bundle savedInstanceState) {
tabsViewModel = tabsViewModel =
@ -79,7 +78,7 @@ public class TabsFragment extends Fragment implements AddButtonDialogSingle.AddB
String Background = p.getString("Background", null); String Background = p.getString("Background", null);
if (Background != null) { if (Background != null) {
ImageView I = root.findViewById(R.id.Background); ImageView I = root.findViewById(R.id.Background);
byte[] BA = Base64.getDecoder().decode(Background); byte[] BA = Base64.decode(Background, Base64.DEFAULT);
I.setImageDrawable(new BitmapDrawable(getResources(), MainActivity.scaleCenterCrop(BitmapFactory.decodeByteArray(BA, 0, BA.length), MainActivity.getScreenHeight(), MainActivity.getScreenWidth()))); I.setImageDrawable(new BitmapDrawable(getResources(), MainActivity.scaleCenterCrop(BitmapFactory.decodeByteArray(BA, 0, BA.length), MainActivity.getScreenHeight(), MainActivity.getScreenWidth())));
I.setScaleType(ImageView.ScaleType.CENTER_CROP); I.setScaleType(ImageView.ScaleType.CENTER_CROP);
} }
@ -264,7 +263,6 @@ public class TabsFragment extends Fragment implements AddButtonDialogSingle.AddB
; ;
} }
@RequiresApi(api = Build.VERSION_CODES.KITKAT)
public void save() throws JSONException { public void save() throws JSONException {
JSONArray listItems2 = new JSONArray(); JSONArray listItems2 = new JSONArray();
for (ListItem Item : listAdapter.getObjects()) { for (ListItem Item : listAdapter.getObjects()) {

View File

@ -10,6 +10,7 @@ import android.media.MediaPlayer;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.os.Vibrator; import android.os.Vibrator;
import android.util.Base64;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
@ -24,7 +25,6 @@ import androidx.annotation.RequiresApi;
import androidx.fragment.app.Fragment; import androidx.fragment.app.Fragment;
import androidx.lifecycle.ViewModelProvider; import androidx.lifecycle.ViewModelProvider;
import java.util.Base64;
import java.util.Objects; import java.util.Objects;
import de.jg_cody.Teraplex.MainActivity; import de.jg_cody.Teraplex.MainActivity;
@ -48,7 +48,6 @@ public class HomeFragment extends Fragment {
private HomeViewModel homeViewModel; private HomeViewModel homeViewModel;
@RequiresApi(api = Build.VERSION_CODES.O)
public View onCreateView(@NonNull LayoutInflater inflater, public View onCreateView(@NonNull LayoutInflater inflater,
ViewGroup container, Bundle savedInstanceState) { ViewGroup container, Bundle savedInstanceState) {
SharedPreferences prefs = requireContext().getSharedPreferences("appsettings", Context.MODE_PRIVATE); SharedPreferences prefs = requireContext().getSharedPreferences("appsettings", Context.MODE_PRIVATE);
@ -63,7 +62,7 @@ public class HomeFragment extends Fragment {
String Background = p.getString("Background", null); String Background = p.getString("Background", null);
if (Background != null) { if (Background != null) {
ImageView I = root.findViewById(R.id.Background); ImageView I = root.findViewById(R.id.Background);
byte[] BA = Base64.getDecoder().decode(Background); byte[] BA = Base64.decode(Background, Base64.DEFAULT);
I.setImageDrawable(new BitmapDrawable(getResources(), MainActivity.scaleCenterCrop(BitmapFactory.decodeByteArray(BA, 0, BA.length), MainActivity.getScreenHeight(), MainActivity.getScreenWidth()))); I.setImageDrawable(new BitmapDrawable(getResources(), MainActivity.scaleCenterCrop(BitmapFactory.decodeByteArray(BA, 0, BA.length), MainActivity.getScreenHeight(), MainActivity.getScreenWidth())));
I.setScaleType(ImageView.ScaleType.CENTER_CROP); I.setScaleType(ImageView.ScaleType.CENTER_CROP);
} }

View File

@ -15,11 +15,14 @@ public abstract class ListItem {
this.type = type; this.type = type;
} }
@RequiresApi(api = Build.VERSION_CODES.KITKAT)
public JSONObject toJson() throws JSONException { public JSONObject toJson() throws JSONException {
JSONObject toJson = new JSONObject(); JSONObject toJson = new JSONObject();
toJson.put("type", type); toJson.put("type", type);
toJson.put("strings", new JSONArray(getStrings())); JSONArray a = new JSONArray();
for(String s : getStrings()) {
a.put(s);
}
toJson.put("strings", a);
return toJson; return toJson;
} }

View File

@ -6,6 +6,7 @@ import android.graphics.BitmapFactory;
import android.graphics.drawable.BitmapDrawable; import android.graphics.drawable.BitmapDrawable;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.util.Base64;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
@ -17,7 +18,6 @@ import androidx.annotation.RequiresApi;
import androidx.fragment.app.Fragment; import androidx.fragment.app.Fragment;
import androidx.lifecycle.ViewModelProvider; import androidx.lifecycle.ViewModelProvider;
import java.util.Base64;
import java.util.Objects; import java.util.Objects;
import de.jg_cody.Teraplex.MainActivity; import de.jg_cody.Teraplex.MainActivity;
@ -28,7 +28,6 @@ public class ZeitsteuerungFragment extends Fragment {
private ZeitsteuerungViewModel zeitsteuerungViewModel; private ZeitsteuerungViewModel zeitsteuerungViewModel;
TimePicker timePicker; TimePicker timePicker;
@RequiresApi(api = Build.VERSION_CODES.O)
public View onCreateView(@NonNull LayoutInflater inflater, public View onCreateView(@NonNull LayoutInflater inflater,
ViewGroup container, Bundle savedInstanceState) { ViewGroup container, Bundle savedInstanceState) {
zeitsteuerungViewModel = zeitsteuerungViewModel =
@ -38,7 +37,7 @@ public class ZeitsteuerungFragment extends Fragment {
String Background = p.getString("Background", null); String Background = p.getString("Background", null);
if (Background != null) { if (Background != null) {
ImageView I = root.findViewById(R.id.Background); ImageView I = root.findViewById(R.id.Background);
byte[] BA = Base64.getDecoder().decode(Background); byte[] BA = Base64.decode(Background, Base64.DEFAULT);
I.setImageDrawable(new BitmapDrawable(getResources(), MainActivity.scaleCenterCrop(BitmapFactory.decodeByteArray(BA, 0, BA.length), MainActivity.getScreenHeight(), MainActivity.getScreenWidth()))); I.setImageDrawable(new BitmapDrawable(getResources(), MainActivity.scaleCenterCrop(BitmapFactory.decodeByteArray(BA, 0, BA.length), MainActivity.getScreenHeight(), MainActivity.getScreenWidth())));
I.setScaleType(ImageView.ScaleType.CENTER_CROP); I.setScaleType(ImageView.ScaleType.CENTER_CROP);
} }

View File

@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="purple_200">#EE0000</color>
<color name="purple_500">#EE0000</color>
<color name="red_dark">#B30000</color>
<color name="red">#DA0303</color>
<color name="blue">#FF0088FF</color>
<color name="yellow">#FFE500</color>
<color name="turquoise">#00FFF7</color>
<color name="orange">#FF7700</color>
<color name="pink">#D900FF</color>
<color name="green">#00FF0A</color>
<color name="teal_700">#870101</color>
<color name="colorOnBackgroundNight">#000000</color>
<color name="colorOnBackgroundDay">#FFFFFF</color>
<color name="black">#000000</color>
<color name="white">#FFFFFF</color>
<color name="green_200">#00EE00</color>
<color name="green_500">#00EE00</color>
<color name="green_700">#00B300</color>
<color name="green_100">#03DA03</color>
<color name="green_600">#018701</color>
</resources>

View File

@ -22,5 +22,4 @@
<color name="green_700">#00B300</color> <color name="green_700">#00B300</color>
<color name="green_100">#03DA03</color> <color name="green_100">#03DA03</color>
<color name="green_600">#018701</color> <color name="green_600">#018701</color>
</resources> </resources>

View File

@ -6,7 +6,7 @@ buildscript {
maven { url 'https://maven.google.com/' } maven { url 'https://maven.google.com/' }
} }
dependencies { dependencies {
classpath 'com.android.tools.build:gradle:4.2.1' classpath 'com.android.tools.build:gradle:4.2.2'
// NOTE: Do not place your application dependencies here; they belong // NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files // in the individual module build.gradle files