android: clean-up and some refactoring in java code.
[maemo-rb.git] / android / src / org / rockbox / RockboxKeyboardInput.java
blob540ba12c22ec8d9eb555a304aa4499da87562b70
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2010 Jonathan Gordon
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
22 package org.rockbox;
25 import android.app.Activity;
26 import android.app.AlertDialog;
27 import android.app.Dialog;
28 import android.content.DialogInterface;
29 import android.text.Editable;
30 import android.view.LayoutInflater;
31 import android.view.View;
32 import android.widget.EditText;
34 public class RockboxKeyboardInput
36 public void kbd_input(final String text, final String ok, final String cancel)
38 final Activity c = RockboxService.getInstance().getActivity();
40 c.runOnUiThread(new Runnable() {
41 public void run()
43 LayoutInflater inflater = LayoutInflater.from(c);
44 View addView = inflater.inflate(R.layout.keyboardinput, null);
45 EditText input = (EditText) addView.findViewById(R.id.KbdInput);
46 input.setText(text);
47 new AlertDialog.Builder(c)
48 .setTitle(R.string.KbdInputTitle)
49 .setView(addView)
50 .setIcon(R.drawable.icon)
51 .setCancelable(false)
52 .setPositiveButton(ok, new DialogInterface.OnClickListener()
54 public void onClick(DialogInterface dialog, int whichButton) {
55 EditText input = (EditText)((Dialog)dialog)
56 .findViewById(R.id.KbdInput);
57 Editable s = input.getText();
58 put_result(true, s.toString());
61 .setNegativeButton(cancel, new DialogInterface.OnClickListener()
63 public void onClick(DialogInterface dialog, int whichButton)
65 put_result(false, "");
68 .show();
70 });
73 private native void put_result(boolean accepted, String new_string);
75 public boolean is_usable()
77 return RockboxService.getInstance().getActivity() != null;