Minor code improvements

This commit is contained in:
MrLetsplay 2021-08-23 20:32:16 +02:00
parent d5463b335f
commit 8fc81dc00a
4 changed files with 22 additions and 87 deletions

View File

@ -99,12 +99,8 @@ public class AddButtonDialogSingle extends DialogFragment {
} }
} }
public interface AddButtonDialogListenerSingle { public interface AddButtonDialogListenerSingle {
void applyTextsSingle(String name, String command, String button); void applyTextsSingle(String name, String command, String button);
} }
} }

View File

@ -37,8 +37,6 @@ public class AddHeadlineDialog extends DialogFragment {
editText_name = view.findViewById(R.id.dialogheadline_editText_name); editText_name = view.findViewById(R.id.dialogheadline_editText_name);
builder.setView(view) builder.setView(view)
.setTitle(R.string.heading) .setTitle(R.string.heading)
.setNegativeButton(R.string.cancel, (dialogInterface, i) -> { .setNegativeButton(R.string.cancel, (dialogInterface, i) -> {
@ -89,12 +87,8 @@ public class AddHeadlineDialog extends DialogFragment {
} }
} }
public interface AddHeadlineDialogListener { public interface AddHeadlineDialogListener {
void applyTextsHeadline(String headline); void applyTextsHeadline(String headline);
} }
} }

View File

@ -19,7 +19,6 @@ public class IntroActivity extends AppCompatActivity {
show_logoanimation = p.getBoolean("Logoanimation", true); show_logoanimation = p.getBoolean("Logoanimation", true);
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
if (show_logoanimation) { if (show_logoanimation) {
setContentView(R.layout.activity_intro); setContentView(R.layout.activity_intro);
final Handler handler = new Handler(Looper.getMainLooper()); final Handler handler = new Handler(Looper.getMainLooper());
handler.postDelayed(new Runnable() { handler.postDelayed(new Runnable() {
@ -32,17 +31,10 @@ public class IntroActivity extends AppCompatActivity {
} }
}, 4000); }, 4000);
} else { } else {
final Handler handler = new Handler(Looper.getMainLooper());
handler.postDelayed(new Runnable() {
@Override
public void run() {
//Do something after 100ms
Intent m = new Intent(getApplicationContext(), MainActivity.class); Intent m = new Intent(getApplicationContext(), MainActivity.class);
m.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NO_ANIMATION); m.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NO_ANIMATION);
startActivity(m); startActivity(m);
} }
}, 0);
}
} }

View File

@ -83,9 +83,6 @@ public class MainActivity extends AppCompatActivity {
public static boolean editmode = false; public static boolean editmode = false;
public static boolean button_vibration = false; public static boolean button_vibration = false;
EditText editText_name;
int lastID = 6969; int lastID = 6969;
Map<String, MenuItem> tabitems = new HashMap<>(); Map<String, MenuItem> tabitems = new HashMap<>();
@ -95,21 +92,13 @@ public class MainActivity extends AppCompatActivity {
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);
} }
//getWindow().setBackgroundDrawableResource(R.drawable.toolbartop); //getWindow().setBackgroundDrawableResource(R.drawable.toolbartop);
getWindow().setBackgroundDrawable(new ColorDrawable(Color.BLACK)); getWindow().setBackgroundDrawable(new ColorDrawable(Color.BLACK));
if (savedInstanceState == null) {
/*getSupportFragmentManager().beginTransaction()
.replace(android.R.id.content, new DemoPreferenceFragment())
.commit();
NonDeveloperMessage.maybeShow(this);*/
}
SharedPreferences p = getSharedPreferences("appsettings", Activity.MODE_PRIVATE); SharedPreferences p = getSharedPreferences("appsettings", Activity.MODE_PRIVATE);
String Language = p.getString("Language", ""); String Language = p.getString("Language", "");
Locale locale = new Locale(Language); Locale locale = new Locale(Language);
@ -196,7 +185,7 @@ public class MainActivity extends AppCompatActivity {
LayoutInflater inflater = getLayoutInflater(); LayoutInflater inflater = getLayoutInflater();
View view = inflater.inflate(R.layout.addtabdialog, null); View view = inflater.inflate(R.layout.addtabdialog, null);
editText_name = view.findViewById(R.id.dialogtab_editText_name); EditText editText_name = view.findViewById(R.id.dialogtab_editText_name);
mBuilder.setView(view) mBuilder.setView(view)
@ -396,7 +385,7 @@ public class MainActivity extends AppCompatActivity {
} }
}); });
String tabsString = p.getString("tabs", null); String tabsString = p.getString("tabs", null);
List<String> tabs = new ArrayList<String>(); List<String> tabs = new ArrayList<>();
if (tabsString != null) { if (tabsString != null) {
try { try {
JSONArray tabsArray = new JSONArray(tabsString); JSONArray tabsArray = new JSONArray(tabsString);
@ -434,20 +423,6 @@ public class MainActivity extends AppCompatActivity {
} }
/*static public class DemoPreferenceFragment extends PreferenceFragmentCompat {
@Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
addPreferencesFromResource(R.xml.preferences);
}
@Override
public void onDisplayPreferenceDialog(Preference preference) {
if (preference instanceof ColorPreference) {
((ColorPreference) preference).showDialog(this, 0);
} else super.onDisplayPreferenceDialog(preference);
}
}*/
@Override @Override
public boolean onCreateOptionsMenu(Menu menu) { public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present. // Inflate the menu; this adds items to the action bar if it is present.
@ -558,12 +533,8 @@ public class MainActivity extends AppCompatActivity {
assert vr != null; assert vr != null;
vr.vibrate(100); vr.vibrate(100);
} }
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
finishAffinity();
} else {
finishAndRemoveTask(); finishAndRemoveTask();
} }
}
@Override @Override
@ -602,8 +573,6 @@ public class MainActivity extends AppCompatActivity {
e.printStackTrace(); e.printStackTrace();
} }
} else if (requestCode == CREATE_FILE && resultCode == RESULT_OK && null != data) { } else if (requestCode == CREATE_FILE && resultCode == RESULT_OK && null != data) {
data.getData();
try { try {
ParcelFileDescriptor pfd = getContentResolver(). ParcelFileDescriptor pfd = getContentResolver().
openFileDescriptor(data.getData(), "w"); openFileDescriptor(data.getData(), "w");
@ -625,19 +594,12 @@ public class MainActivity extends AppCompatActivity {
// Let the document provider know you're done by closing the stream. // Let the document provider know you're done by closing the stream.
fileOutputStream.close(); fileOutputStream.close();
pfd.close(); pfd.close();
} catch (FileNotFoundException e) { } catch (IOException | JSONException e) {
e.printStackTrace(); e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (JSONException e) {
} }
} else if (requestCode == PICK_PDF_FILE && resultCode == RESULT_OK && null != data) { } else if (requestCode == PICK_PDF_FILE && resultCode == RESULT_OK && null != data) {
try { try {
ParcelFileDescriptor pfd = getContentResolver(). ParcelFileDescriptor pfd = getContentResolver().
openFileDescriptor(data.getData(), "r"); openFileDescriptor(data.getData(), "r");
FileInputStream fileInputStream = FileInputStream fileInputStream =
@ -660,17 +622,9 @@ public class MainActivity extends AppCompatActivity {
sharedEditor.apply(); sharedEditor.apply();
startActivity(getIntent()); startActivity(getIntent());
finish(); finish();
} catch (IOException | JSONException e) {
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (JSONException e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
} }
@ -680,7 +634,6 @@ public class MainActivity extends AppCompatActivity {
ImageView I = findViewById(R.id.Background); ImageView I = findViewById(R.id.Background);
byte[] BA = Base64.decode(Background, Base64.DEFAULT); byte[] BA = Base64.decode(Background, Base64.DEFAULT);
I.setImageBitmap(BitmapFactory.decodeByteArray(BA, 0, BA.length)); I.setImageBitmap(BitmapFactory.decodeByteArray(BA, 0, BA.length));
} }
public static int getScreenWidth() { public static int getScreenWidth() {