floating View displaying on hover in android - android

I am trying to implement some hints when a user is hovering a button or another view, I see that android have support for onHoverListener but I don't understand how it really works. However I did try to find a solution how to make a floating editText on a button hover but I didn't find any ideas.
I am thinking that hover in android is the same think with long click because you can't hover with finger without clicking the view.

OnHoverListener is only implemented in 2 specific situations: a) when a Bluetooth or USB mouse is plugged into the device, or b) on Galaxy Note devices, when the S-Pen (stylus) is hovering over the object.
In specific setups/situations this can be a very neat feature, but unfortunately, most users will never even know it exists. For your situation, you may want to implement an OnLongClickListener for showing hints/tips as that is pretty standard in Android.
This example will show a TextView or ImageView hint for 5 seconds when a long-click is initiated:
btn.setOnLongClickListener(new View.OnLongClickListener() {
#Override
public boolean onLongClick(View view) {
findViewById(R.id.hint).setVisibility(View.VISIBLE);
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
public void run() {
findViewById(R.id.hint).setVisibility(View.GONE);
}
}, 5000);
return true;
}
});
Hope this helps,

I want to add up on Aaron's answer.
Some devices with sensitive screens - Samsung S5 comes to mind - don't even need an s-pen.
Just need to hold your finger 1/2 inch over the screen and it would trigger it.

Related

How to know a user as moved to a new Card in a Google Glass app?

Is there a way for the CardScrollView or CardScrollAdapter to let me know when the user moves from one card to another?
Initially I was using the GestureDetector to detect swipes to the left or right, but in Glass applications users can use, e.g., two-finger swipes to quickly pan and move to a distant card (or even voice controls).
There must be a better way to know exactly when a new card is displayed than to track all these directional events.
I know CardScrollView.getSelectedItemPosition() gives me the current card in view, but not exactly when a new card is displayed.
I also thought that CardScrollAdapter.getView() would run every time a new card is displayed, but in Glass applications it runs once in the beginning of the activity execution.
Any help would be great.
My Glass is somewhere in my storage so I can't test this now but you can try onDetachedToWindow and onAttachedToWindow. Probably something like this:
private View buildView() {
CardBuilder card = new CardBuilder(this, CardBuilder.Layout.TEXT);
card.setText(R.string.whatever);
View view = card.getView();
view.addOnAttachStateChangeListener(new View.OnAttachStateChangeListener() {
#Override
public void onViewAttachedToWindow(View v) {
}
#Override
public void onViewDetachedFromWindow(View v) {
}
});
return view;
}
Also Card lifecycle might give you some idea.
The solution is actually in the documentation as suggested by #EntryLevelDev
CardScrollView notifies you with the following listener interfaces that are inherited from AdapterView:
AdapterView.OnItemSelectedListener - An item is selected after the user finishes scrolling through the list and settles on an item.
from: https://developers.google.com/glass/develop/gdk/reference/com/google/android/glass/widget/CardScrollView#onAttachedToWindow()

Android Swipe Images Intro Screen on First Run

I've been looking around a lot lately but haven't really found much on this.
I'm making my third Android app and I'm looking to implement an intro screen on first run of the app where a series of images are shown explaining the apps functionality and the idea behind it; you can swipe the images left or right and at the last image you get to the app by swiping.
I really like the sort of thing they have done with the CamScanner app but despite my searching I have no idea how to implement it other knowing a little bit about some people referring to Fragments. Any help would be appreciated greatly and since we need better UI on Android, a good answer would help a lot of developers take the cue! :)
create a method to show popup window. show images in a scroll view in that popup. at last image set touch listener to dismiss that popup.
and call that method from onResume method of your Activity like this
protected void onResume(){
super.onResume();
SharedPreferences pref = getSharedPreferences(MyPrefs, MODE_PRIVATE);
boolean b = pref.getBoolean("FirstTime",true);
if(b)
{ new Handler().postDelayed(new Runnable() {
public void run() {
showIntroPopup();
}
}, 100);
}
}
in that popup set "FirstTime" boolean to false in SharedPreferences.

Run multiple performClick() with UI update

button.performClick();
For software demonstration purposes, I want to show the user interface updating after each button performClick(). For example, if the Activity was a calculator I can currently simulate the pressing of buttons [1], [2] and [3] using
btn1.performClick();
btn2.performClick();
btn3.performClick();
However, these updates to the EditText too quickly with no visible pause, i.e. it appears "123" are written to the screen simultaneously. What I want is:-
btn1.performClick() updates UI so people can physically see only button press updated to the EditText before the next button does. Similarly with btn2.performClick() and then btn3.performClick().
You may want to use a library like Robotium, and use Solo.waitForText Method to do what you want.
The problem is that we can not determine in advance the time that it will take to display the text, as it depends on the content of your onClick method.
It's why Robotium may be useful for what you want.
You can either use
Thread.sleep(delay);
or use
handler.postDelayed(Runnable,delay);
Use handler for btn2.performClick() and btn3.performClick() like...
final Handler handler = new Handler();
handler.postDelayed(new Runnable() {
#Override
public void run() {
// do something after 100ms
btn2.performClick();
}
}, 100);

Facebook android scrumptious tutorial ListView not clickable on Google TV

I have just recently built an android tablet app (looking to port it to Google TV now) which is in close analogy to the Facebook Android Scrumptious App tutorial. In particular the issue is in the section of "Show Friends" of that tutorial: http://developers.facebook.com/docs/tutorials/androidsdk/3.0/scrumptious/show-friends/
On the tablet when I touch the Select a Friend part of the ListView, it responds to the onClick. But on the Google TV using Dpad remote, this doesn't work. In particular, (after doing some Log) the onClick never gets called. I have written the part of the code from the tutorial where the onClick doesn't get called.
Just to summarize: This onClick DOES GET CALLED on android tablet and mobile. BUT DOES NOT GET CALLED when on Google TV and clicking using the Enter button on the remote control.
Any help on getting this onClick to get called on the Google TV platform would be most helpful.
private class PeopleListElement extends BaseListElement {
public PeopleListElement(int requestCode) {
super(getActivity().getResources().getDrawable(R.drawable.action_people),
getActivity().getResources().getString(R.string.action_people),
getActivity().getResources().getString(R.string.action_people_default),
requestCode);
}
#Override
protected View.OnClickListener getOnClickListener() {
return new View.OnClickListener() {
#Override
public void onClick(View view) {
// Supposed to do something here BUT ON GOOGLE TV DOES NOT GET CALLED
}
};
}
what happens when you use the touchpad pointer to click the item? I suspect that it may be related to the layout hierarchy and that something higher up is grabbing the dpad event. Conversely it could be that dpad focus is not on the element you think it is.
There are some bugs amongst the various Google TV devices not sending the right key codes for things like OK/Enter or the D-pad center. You might want to add a key listener to see what codes are getting sent to your view.

Android OnLongClickListener strange / unreliable behaviour

I'm currently fighting against the OnLongClickListener on Android Api Lvl 8.
Take this code:
this.webView.setOnLongClickListener(new OnLongClickListener() {
#Override
public boolean onLongClick(View v) {
System.out.println("long click");
return true;
}
});
It works perfectly. I can press anywhere on the WebView and the event triggers every time.
Now take a look at this one:
this.webView.setOnLongClickListener(new OnLongClickListener() {
#Override
public boolean onLongClick(View v) {
final EditText editText = getUrlTextField();
switch (editText.getVisibility()) {
case View.VISIBLE:
editText.setVisibility(View.GONE);
return true;
case View.GONE:
editText.setVisibility(View.VISIBLE);
return true;
default:
return false;
}
}
});
Assuming the URL EditText components is currently visible, it gets gone from the display and should be shown again when another long click event is triggered.
But if you run this, the event just works once (!) when one performs a long click on any position on the WebView. To make things complicated, the long click works again when it is performed on a link on the website...
Can anyone explain if it is a bug in the sdk and/or if there is a mistake in my thinking how the OnLongClickListener is working?!? :/
EDIT:
I've run now several different scenarios on a Nexus One and come to following conclussion: Changing the layout on runtime more or less kills the OnLongClickListener... I haven't found a way to get it work reliably at all...
I would really appreciate if anyone could give me a hint... I'm at my wits end :(
Personnally, I ended up by re-setting the listener after each relayout.
I've run into this issue as well. It seems that if the view layout changes in a way that child view bounds need to be modified (i.e. TextView is wrap_content width and you set its text to something longer/shorter than it was before), views in the hierarchy will have their onStartTemporaryDetach method called (most likely due to a layout pass, although I haven't dug deep enough to find out for sure). If you look at the source for View that onStartTemporaryDetach ultimately unsets the pressed state of the view.
Changing the views in your layout that will be updated periodically to have bounds that will not change regardless of the value you set, will fix the issue. Although, that is still not awesome.

Categories

Resources