From: DeaDDooMER Date: Thu, 16 Dec 2021 15:47:19 +0000 (+0300) Subject: android: add simple launcher (port from k8vavoom) X-Git-Url: http://deadsoftware.ru/gitweb?a=commitdiff_plain;h=0d9765413a5600fb512aeb6c926a22a9a3768c82;p=d2df-sdl.git android: add simple launcher (port from k8vavoom) --- diff --git a/android/AndroidManifest.xml b/android/AndroidManifest.xml index b69d31f..a952434 100644 --- a/android/AndroidManifest.xml +++ b/android/AndroidManifest.xml @@ -5,16 +5,26 @@ android:versionName="0.667-git" android:installLocation="auto"> - - + + + + + + + + + + + + @@ -31,24 +41,26 @@ android:theme="@android:style/Theme.NoTitleBar.Fullscreen" android:hardwareAccelerated="true" android:debuggable="true" > - + + + + - - + + + + diff --git a/android/src/org/d2df/app/Doom2DF.java b/android/src/org/d2df/app/Doom2DF.java index 4f7b00d..47220cb 100644 --- a/android/src/org/d2df/app/Doom2DF.java +++ b/android/src/org/d2df/app/Doom2DF.java @@ -1,5 +1,6 @@ package org.d2df.app; +import android.content.Intent; import android.app.Activity; import android.os.Bundle; @@ -8,38 +9,46 @@ import org.libsdl.app.SDLActivity; public class Doom2DF extends SDLActivity { - @Override - protected String[] getLibraries() { - return new String[] { - "crystax", - "SDL2", - "mpg123", - "SDL2_mixer", - "enet", - "miniupnpc", - "Doom2DF" - }; - } - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - - CopyAssets.copyAssets(SDL.getContext(), ""); - CopyAssets.copyAssets(SDL.getContext(), "data"); - CopyAssets.copyAssets(SDL.getContext(), "data/models"); - CopyAssets.copyAssets(SDL.getContext(), "maps"); - CopyAssets.copyAssets(SDL.getContext(), "maps/megawads"); - CopyAssets.copyAssets(SDL.getContext(), "wads"); - CopyAssets.copyAssets(SDL.getContext(), "instruments"); - CopyAssets.copyAssets(SDL.getContext(), "timidity.cfg"); - } - - @Override - protected void onDestroy() { - super.onDestroy(); - - /* This will fix bug #31 and may be #32 */ - System.exit(0); - } + @Override + protected String[] getLibraries () { + return new String[] { + "crystax", + "SDL2", + "mpg123", + "SDL2_mixer", + "enet", + "miniupnpc", + "Doom2DF" + }; + } + + @Override + protected String[] getArguments () { + Intent intent = getIntent(); + String value = intent.getStringExtra(Launcher.prefArgs); + String[] args = value.split("\\s+"); + return args; + } + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + CopyAssets.copyAssets(SDL.getContext(), ""); + CopyAssets.copyAssets(SDL.getContext(), "data"); + CopyAssets.copyAssets(SDL.getContext(), "data/models"); + CopyAssets.copyAssets(SDL.getContext(), "maps"); + CopyAssets.copyAssets(SDL.getContext(), "maps/megawads"); + CopyAssets.copyAssets(SDL.getContext(), "wads"); + CopyAssets.copyAssets(SDL.getContext(), "instruments"); + CopyAssets.copyAssets(SDL.getContext(), "timidity.cfg"); + } + + @Override + protected void onDestroy() { + super.onDestroy(); + + /* This will fix bug #31 and may be #32 */ + System.exit(0); + } } diff --git a/android/src/org/d2df/app/Launcher.java b/android/src/org/d2df/app/Launcher.java new file mode 100644 index 0000000..86d93b9 --- /dev/null +++ b/android/src/org/d2df/app/Launcher.java @@ -0,0 +1,108 @@ +package org.d2df.app; + +import android.app.Activity; +import android.os.Bundle; +import android.util.Log; + +import android.content.*; + +import android.view.*; +import android.widget.*; +import android.text.*; + +import java.io.*; +import java.util.*; +import java.lang.*; + +public class Launcher extends Activity { + + static final String preferences = "org.d2df.app.PREF"; + static final String prefArgs = "CommandLine"; + + private EditText cmdline; + + private void saveCommandLine () { + String s = cmdline.getText().toString(); + SharedPreferences sh = getSharedPreferences(preferences, MODE_PRIVATE); + SharedPreferences.Editor ed = sh.edit(); + ed.putString(prefArgs, s); + ed.apply(); + } + + private String loadCommandLine () { + SharedPreferences sh = getSharedPreferences(preferences, MODE_PRIVATE); + return sh.getString(prefArgs, ""); + } + + private class CmdLineWatcher implements TextWatcher { + + @Override + public void beforeTextChanged (CharSequence s, int start, int count,int after) { + } + + @Override + public void onTextChanged (CharSequence s, int start, int before, int count) { + } + + @Override + public void afterTextChanged (Editable s) { + saveCommandLine(); + } + } + + private View.OnClickListener StartVavoomEvent = new View.OnClickListener () { + + public void onClick (View view) { + Intent intent = new Intent(Launcher.this, Doom2DF.class); + String s = Launcher.this.cmdline.getText().toString(); + intent.putExtra(prefArgs, s); + Launcher.this.startActivity(intent); + } + }; + + private void addImage (ViewGroup g, int id) { + ImageView v = new ImageView(this); + v.setImageResource(id); + g.addView(v); + } + + private void addText (ViewGroup g, String s) { + TextView v = new TextView(this); + v.setText(s); + // v.setTextSize(16); + g.addView(v); + } + + private EditText addTextField (ViewGroup g, String s, TextWatcher w) { + EditText v = new EditText(this); + v.setText(s); + v.addTextChangedListener(w); + g.addView(v); + return v; + } + + private void addButton (ViewGroup g, String s, View.OnClickListener c) { + Button v = new Button(this); + v.setText(s); + v.setOnClickListener(c); + g.addView(v); + } + + private void rebuild () { + LinearLayout layout = new LinearLayout(this); + layout.setOrientation(LinearLayout.VERTICAL); +// addImage(layout, R.drawable.doom2df_logo); + addText(layout, "Command line:"); + cmdline = addTextField(layout, loadCommandLine(), new CmdLineWatcher()); + addButton(layout, "Start", StartVavoomEvent); + setContentView(layout); + } + + @Override + public void onCreate (Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + requestWindowFeature(Window.FEATURE_NO_TITLE); + rebuild(); + } + +}