I'm making a game using AndEngine which uses the soft keyboard of the device.
I'm NOT using EditText, but rather my own. I'm trying to detect presses on the soft keyboard,
I've already succeeded in showing and hiding the keyboard over the AndEngine scene.
My activity implements the OnKeyboardActionListener, which I read is used as a soft-keyboard listener, but I'm not sure how to register the keyboard with this class (the activity).
Obviously, at the moment, the code inside onPress() is useless..
I couldn't find any examples, most of them refers to EditText, which I'm not using..
Is it possible?
Maybe a service or something?
Thanks in advance.
EDIT:
I'm trying to create my own keyboard using KeyboardView and a custom Keyboard,
This way I could do
KeyboardView kbView = new KeyboardView(this,null);
kbView.setKeyboard(new Keyboard(this, R.xml.keyboard);
kbView.setOnKeyboardActionListener(new OnKeyboardActionListener() {
....
}
Has anyone done this? works, doesn't?
Thanks.
I ended up creating my own Keyboard and KeyboardView`, then I used this code
CustomKeyboardView kbView = (CustomKeyboardView) findViewById(R.id.keyboard_view);
kbView.setKeyboard(new Keyboard(this, R.xml.myCustomKeyboard);
kbView.setOnKeyboardActionListener(new OnKeyboardActionListener() {
#Override
public void onPress(int primaryCode) {
// A Key was pressed
}
....
}
And created a KeyboardView in the xml layout
<pathToCustomKeyboardView.CustomKeyboardView
android:id="#+id/keyboard_view"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:visibility="gone"
android:layout_alignParentBottom="true" />
CustomKeyboardView only extends KeyboardView, dunno why, but it works with the custom and not with the original
EDIT:
Also, The activity extends SimpleLayoutGameActivity, And then I selected the layout which contains the CustomKeyboardView
Related
android:inputType is not working on EdidtTextPreference from support library. Is changing the input type even possible with this preference? I want a preference with a numeric keyboard. More specifically I will want to set a custom Keyboard, but I can't seem to even open the default one with this preference. If it is not possible with EditTextPreference, can someone give me an idea how I would go about doing what I desire?
<android.support.v7.preference.EditTextPreference
android:key="key"
android:title="title"
android:maxLines="1"
android:dialogMessage="title"
android:inputType="number" />
Actually, the solution is quite easy. Since android:inputType="number" didn't seem to work, I went with this:
PreferenceFragment.java
#Override
public void onResume() {
EditTextPreference preference = (EditTextPreference) findPreference("key");
EditText et = preference.getEditText();
if (et != null) {
et.setInputType(InputType.TYPE_CLASS_NUMBER);
//in fact, you can do whatever you can normally with an EditText here
}
}
Although I'm not sure if this is how it works with the latest androidx Preference.
I'm using sliding panels with my android app, but i need to get an event when the panel is up, is there a way listen to when it happens?
im using a sothree Sliding panel library
Looks like you are talking about umano/AndroidSlidingUpPanel. After briefly looking at the documentation/code you should be able to set a PanelSlideListener to your SlidingUpPanelLayout. They also provide a SimplePanelSlideListener which inserts no-ops for any functions you choose not to implement, which is probably what you will want to use.
For example inside of your Activity's onCreate you could do something like:
SlidingUpPanelLayout slidingPanel = (SlidingUpPanelLayout)findViewById(R.id.your_sliding_layout);
slidingPanel.setPanelSlideListener(new SimplePanelSlideListener() {
#Override
public void onPanelExpanded(View panel) {
// Insert your code here
}
});
I am trying to use this library for card view
https://github.com/DenisMondon/material-design-library
<com.blunderer.materialdesignlibrary.views.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:mdl_title="CardView"
app:mdl_description="A Left Image CardView"
app:mdl_normalButton="Normal"
app:mdl_highlightButton="Highlight"
app:mdl_imagePosition="left"
app:mdl_image="#drawable/image" />
I can not figure out how to add a onClickListener for the labels normalButton and highlightButto.
Can someone please give me a hand. thank you
Also how to set an Image programmatically into this cardView?
It has following two listeners
private OnClickListener mOnNormalButtonClickListener;
private OnClickListener mOnHighlightButtonClickListener;
You need to implement CardView.mOnNormalButtonClickListener, CardView.mOnHighlightButtonClickListener in your activity and override their methods to implement the click listeners for these buttons and set them using these functions.
setOnNormalButtonClickListener(OnClickListener onNormalButtonClickListener)
setOnHighlightButtonClickListener(OnClickListener onHighlightButtonClickListener)
#Joolah
With the latest version of the library, you can have a cardview url image.
Just write this:
myCardView.setImageUrl("http://your_image_url");
I have developed a custom component consist of a layout and two labels within it. This layout is draggable. The code is similar to this :
DragAndDropWrapper boxWrap= new DragAndDropWrapper(layout);
mainLayout.addComponent(boxWrap);
After that I have a RichTextArea that allows the layout to be dropped in it. With this code.
RichTextArea richText= new RichTextArea;
DragAndDropWrapper dndWrapper = new DragAndDropWrapper(richText);
dndWrapper.setDropHandler(new DropHandler() {
public void drop(DragAndDropEvent event) {
//Do whatever you want when something is dropped
}
//Criterio de aceptacion
public AcceptCriterion getAcceptCriterion() {
return AcceptAll.get();
}
});
The code works fine. But when I drop the layout within the RichTextArea y want to get the Text written in this area and add some text but the method richText.getValue() is not updated unless I change the focus to another component or tab out. I guess there is not being communication with the server side so the value is not updated. Is there any way to force a a focus change when mousedown on the layout? I tried with JavaScript but i dont know how to add a onmousedown="function()" attribute to the layout component. I also tried extending RichTextArea and implementing the MouseListener or something or a TextChangeListener, but nothing works.
Any clue? Thank you.
PS: The component cannot be different from a RichTextArea.
Have you set richText.setImmediate(true); ?
I am attempting to use a swipe gesture to finish a fragment, and if the fragment is displaying the keyboard, the keyboard will be hidden. The following is a sample:
public void finishFragment() {
View focus = getCurrentFocus();
InputMethodManager imm = null;
if (focus != null) {
imm = (InputMethodManager) focus.getContext().
getSystemService(Context.INPUT_METHOD_SERVICE);
if (imm.isActive()) {
imm.hideSoftInputFromWindow(focus.getWindowToken(), 0);
}
}
if (getFragmentManager().getBackStackEntryCount() > 1) {
getFragmentManager().popBackStack();
}
}
Unfortunately, since I am calling a service along side the fragment stack, the service is hanging up the UI display, thus giving it a laggy appearance. Does anyone know how I can hide the keyboard without calling a service or should I call an Async process? Even better, does anyone know how onBackPressed() removes the keyboard?
There are only 2 ways to control the keyboard on Android:
Programmatically with the InputMethodManager like you are doing (which will as far as I know always requires you to call .getSystemService() to use)
Using android:windowSoftInputMode="X" to specify the behavior of the keyboard in the context of the given activity tag in the AndroidManifest
So to answer your questions of: "Does anyone know how I can hide the keyboard without calling a service"? You could do the following in the AndroidManifest, where ActivityX is the activity you want to have this type of behavior.
AndroidManifest.xml:
<activity
android:name="com.namespace.of.ActivityXYZ"
android:windowSoftInputMode="stateHidden" />
This will serve to hide the keyboard initially for ActivityX, but I am not sure if this will give you the desired behavior/lack of laggyness when swiping to finish the fragment. Also try changing "stateHidden" to "stateAlwaysHidden" or "stateUnchanged". Checkout what these do here if you do not know.
Another approach would be: instead of checking the focus and getting the keyboard programmatically like you are doing, why not just finish() the activity managing the fragment you wish to end? This will also hide the keyboard if it was open.
Hope this helps!