I am developing soft keyboard and I added a toggle button similar to the shift button to my keyboard with option isSticky=true on it. How can I control this sticky button from my code? Or actually is it even possible, since my toggle button loses state each time I change the orientation.
public class SoftKeyboard extends InputMethodService
implements KeyboardView.OnKeyboardActionListener {
And I have a function with onKey to specify the key pressed.
See Handling Orientation Change: http://developer.android.com/guide/topics/resources/runtime-changes.html
I've faced a similar issue. You can create a second drawable, and manually draw the sticky indicator on it. Then load this drawable in your xml or java code - depending on your orientation.
Related
I want to make a touch on a button in a layout and also that touch is done by program using injectinputevent method, so that button is clicked even without touching it.
You can use the performClick method on that button.
Call this view's OnClickListener, if it is defined. Performs all normal actions associated with clicking: reporting accessibility event, playing a sound, etc.
You can call if from another method:
your_button.performClick();
I am trying to make a like button with two states in my app but i am confused on what type of button that is used in android app's like instagram and facebook is it a normal button,image button or a toggle button, i've searched around for this but i haven't gotten any answers, please help
A sleek implementation would be to create a Custom ImageView, which has an object (boolean, int, etc) that maintains it's state. You maintain this state by it's onClickListener associated with the imageview, and set the drawable to be a new image corresponding to it's respective state when triggered.
For example, say you have a "like" button similar to Facebook's. Initially, it has a background drawable of a gray thumb and say our state is a boolean value which is false when gray. When a user clicks on the thumb, state would change to true and the image drawable becomes blue indicating it has been activated. We know to make the drawable the blue version because that state is now "true".
So each click event would swap states, and set the drawable to be a new image based on state. This implies have multiple types of images.
EDIT:
Additionally, this could actually be a button with Text in it and a drawable using drawableLeft , drawableRight , etc... which you change the text color and corresponding drawable on state change via method in your Custom Button implementation
You could make a custom checkbox. When the user presses the checkbox, it changes to the like state. If it's already checked, uncheck the box.
Here is the question I found: Defining custom-checkbox in android
I know this may not be an appropriate question, but I want to know how a touch enabled OS like
android detects a button in an app and calls the appropriate handler? When programming an app we just give the alignment information of a particular button. So, how android keeps the mapping between a button and screen position? I think this is kindof dynamic because if you change the screen orientation or use zoom or something like that the button positions are changed dynamically. So, android must look at the touch position and decide whether a button is there or not and call the appropriate handler. How this all things put together?
I appreciate any reply.
My overriding question is this: In Android PreferenceActivity, how can I write an OnClickListener which will have the same functionality as pressing the Android back button as I navigate through PreferenceScreen defined menus? That is to say, I would like users of my App to explicity see a menu choice "Back" which will bring them to the previous menu, or bring them out of the menu activity to their previous activity if they are at the root of this particular PreferenceActivity session.
The android developer documents tell us
Note that this XML resource contains a preference screen holding another fragment, the Prefs1FragmentInner implemented here. This allows the user to traverse down a hierarchy of preferences; pressing back will pop each fragment off the stack to return to the previous preferences.
And they are correct about that. I navigate happily through my menus by clicking on PreferenceScreen items to get to that screen, and using the Android back button to go Back up a level. But I'm not sure a casual user really understands the "Back" button, I know I didn't until I read about it in Developer docs. SO I would would like them to have an explicit Preference defined menu choice whos OnClickListener duplicates the function of the Android back button.
So I tried to put in a Preference in my menu that would go back. Having determined that a not Overriden onBackPressed in a my subclass of PreferenceActivity just referred back to Activity.onBackPressed() which merely calls finish(), I tried this OnClickListener:
private OnPreferenceClickListener clickFinishesSuccessfully = new OnPreferenceClickListener() {
#Override
public boolean onPreferenceClick(Preference preference) {
finish();
return true;
}
};
As it turns out, this did NOT do the same thing as pressing the back button! Pressing this button always took me out of the PreferenceActivity entirely, back to the Activity from which I had called my PreferenceActivity. Specifically, it did NOT navigate back through my menus no matter how deep I was when I clicked it.
I am guessing here: When I have gotten to a submenu by clicking an onscreen preference which is really a PreferenceScreen, I am no longer in my own PreferenceActivity. I must be in some other Activity?
So my functional question: what can I put in my OnClickListener of my "Back" Preference to get the same function as the Android Back button navigating through my menus?
I think the casual user should know about the back button. The button is used everywhere so it might be a problem getting used in the first day but after that it's natural. Without being used to the "back" button I can hardly imagine doing the everyday tasks.
The preference you want to add just duplicates functionality and doesn't provide a consistent way with the rest of the system. If Google was considering back being an uncommon thing for casual users would have added that option in phone's Settings which is also a PreferenceActivity.
How do you hide the keypad?
I'm currently using the following code to hide the keypad. Is there a better way to do this?
Window window = getWindow();
window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
You have the right idea for hiding the soft keyboard. You could probably use the SOFT_INPUT_STATE_HIDDEN flag instead of the ALWAYS_HIDDEN one, this would allow it so it will re-open when the user clicks in the EditText without the need to call setSoftInputMode() again.