DEADSOFTWARE

android: add simple launcher (port from k8vavoom)
[d2df-sdl.git] / android / src / org / d2df / app / Launcher.java
1 package org.d2df.app;
3 import android.app.Activity;
4 import android.os.Bundle;
5 import android.util.Log;
7 import android.content.*;
9 import android.view.*;
10 import android.widget.*;
11 import android.text.*;
13 import java.io.*;
14 import java.util.*;
15 import java.lang.*;
17 public class Launcher extends Activity {
19 static final String preferences = "org.d2df.app.PREF";
20 static final String prefArgs = "CommandLine";
22 private EditText cmdline;
24 private void saveCommandLine () {
25 String s = cmdline.getText().toString();
26 SharedPreferences sh = getSharedPreferences(preferences, MODE_PRIVATE);
27 SharedPreferences.Editor ed = sh.edit();
28 ed.putString(prefArgs, s);
29 ed.apply();
30 }
32 private String loadCommandLine () {
33 SharedPreferences sh = getSharedPreferences(preferences, MODE_PRIVATE);
34 return sh.getString(prefArgs, "");
35 }
37 private class CmdLineWatcher implements TextWatcher {
39 @Override
40 public void beforeTextChanged (CharSequence s, int start, int count,int after) {
41 }
43 @Override
44 public void onTextChanged (CharSequence s, int start, int before, int count) {
45 }
47 @Override
48 public void afterTextChanged (Editable s) {
49 saveCommandLine();
50 }
51 }
53 private View.OnClickListener StartVavoomEvent = new View.OnClickListener () {
55 public void onClick (View view) {
56 Intent intent = new Intent(Launcher.this, Doom2DF.class);
57 String s = Launcher.this.cmdline.getText().toString();
58 intent.putExtra(prefArgs, s);
59 Launcher.this.startActivity(intent);
60 }
61 };
63 private void addImage (ViewGroup g, int id) {
64 ImageView v = new ImageView(this);
65 v.setImageResource(id);
66 g.addView(v);
67 }
69 private void addText (ViewGroup g, String s) {
70 TextView v = new TextView(this);
71 v.setText(s);
72 // v.setTextSize(16);
73 g.addView(v);
74 }
76 private EditText addTextField (ViewGroup g, String s, TextWatcher w) {
77 EditText v = new EditText(this);
78 v.setText(s);
79 v.addTextChangedListener(w);
80 g.addView(v);
81 return v;
82 }
84 private void addButton (ViewGroup g, String s, View.OnClickListener c) {
85 Button v = new Button(this);
86 v.setText(s);
87 v.setOnClickListener(c);
88 g.addView(v);
89 }
91 private void rebuild () {
92 LinearLayout layout = new LinearLayout(this);
93 layout.setOrientation(LinearLayout.VERTICAL);
94 // addImage(layout, R.drawable.doom2df_logo);
95 addText(layout, "Command line:");
96 cmdline = addTextField(layout, loadCommandLine(), new CmdLineWatcher());
97 addButton(layout, "Start", StartVavoomEvent);
98 setContentView(layout);
99 }
101 @Override
102 public void onCreate (Bundle savedInstanceState) {
103 super.onCreate(savedInstanceState);
104 requestWindowFeature(Window.FEATURE_NO_TITLE);
105 rebuild();