|
| 1 | +from java import cast, jclass |
| 2 | + |
| 3 | +def create_widgets(context): |
| 4 | + # Java Classes |
| 5 | + LinearLayout = jclass('android.widget.LinearLayout') |
| 6 | + Button = jclass('android.widget.Button') |
| 7 | + TextView = jclass('android.widget.TextView') |
| 8 | + EditText = jclass('android.widget.EditText') |
| 9 | + CheckBox = jclass('android.widget.CheckBox') |
| 10 | + RadioButton = jclass('android.widget.RadioButton') |
| 11 | + ImageView = jclass('android.widget.ImageView') |
| 12 | + ProgressBar = jclass('android.widget.ProgressBar') |
| 13 | + Switch = jclass('android.widget.Switch') |
| 14 | + ToggleButton = jclass('android.widget.ToggleButton') |
| 15 | + SeekBar = jclass('android.widget.SeekBar') |
| 16 | + |
| 17 | + # Create LinearLayout |
| 18 | + layout = LinearLayout(context) |
| 19 | + layout_params = LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, |
| 20 | + LinearLayout.LayoutParams.WRAP_CONTENT) |
| 21 | + layout.setLayoutParams(layout_params) |
| 22 | + layout.setOrientation(LinearLayout.VERTICAL) |
| 23 | + |
| 24 | + # Create Button |
| 25 | + button = Button(context) |
| 26 | + button.setText('Button created in Python') |
| 27 | + layout.addView(button) |
| 28 | + |
| 29 | + # Create TextView |
| 30 | + textView = TextView(context) |
| 31 | + textView.setText('TextView created in Python') |
| 32 | + layout.addView(textView) |
| 33 | + |
| 34 | + # Create EditText |
| 35 | + editText = EditText(context) |
| 36 | + editText.setHint('EditText created in Python') |
| 37 | + layout.addView(editText) |
| 38 | + |
| 39 | + # Create CheckBox |
| 40 | + checkBox = CheckBox(context) |
| 41 | + checkBox.setText('CheckBox created in Python') |
| 42 | + layout.addView(checkBox) |
| 43 | + |
| 44 | + # Create RadioButton |
| 45 | + radioButton = RadioButton(context) |
| 46 | + radioButton.setText('RadioButton created in Python') |
| 47 | + layout.addView(radioButton) |
| 48 | + |
| 49 | + # Create ImageView |
| 50 | + imageView = ImageView(context) |
| 51 | + layout.addView(imageView) |
| 52 | + |
| 53 | + # Create ProgressBar |
| 54 | + progressBar = ProgressBar(context) |
| 55 | + layout.addView(progressBar) |
| 56 | + |
| 57 | + # Create Switch |
| 58 | + switch = Switch(context) |
| 59 | + switch.setText('Switch created in Python') |
| 60 | + layout.addView(switch) |
| 61 | + |
| 62 | + # Create ToggleButton |
| 63 | + toggleButton = ToggleButton(context) |
| 64 | + toggleButton.setTextOn('On') |
| 65 | + toggleButton.setTextOff('Off') |
| 66 | + layout.addView(toggleButton) |
| 67 | + |
| 68 | + # Create SeekBar |
| 69 | + seekBar = SeekBar(context) |
| 70 | + layout.addView(seekBar) |
| 71 | + |
| 72 | + # Return layout |
| 73 | + return layout |
0 commit comments