What type of event is control-click in gwt - gwt

What is the event type for the control click in a table cell in a GWT application? I want to basically change the color of the background when the user does this action.
This part of my code basically just looks like:
public void onBrowserEvent(Event event) {
Element td = getEventTargetCell(event);
if (td == null) return;
Element tr = DOM.getParent(td);
System.out.println("Event " + Event.getCurrentEvent());
switch (DOM.eventGetType(event)) {
case Event.ONMOUSEDOWN: {
//DOM.setStyleAttribute(td, "backgroundColor", "#ffce00");
onRowClick(tr);
break;
}
case Event.ONMOUSEUP: {
//DOM.setStyleAttribute(td, "backgroundColor", "#ffffff");
break;
}
case Event.ONMOUSEOVER: {
//DOM.setStyleAttribute(td, "backgroundColor", "#ffce00");
onRowRollover(tr);
break;
}
case Event.ONMOUSEOUT: {
//DOM.setStyleAttribute(td, "backgroundColor","#ffffff");
break;
}
/*case Event.ONCLICK: {
DOM.setStyleAttribute(td, "backgroundColor", "#ffce00");
break;
}*/
case Event.ONDBLCLICK: {
//DOM.setStyleAttribute(td, "backgroundColor", "#ffffff");
break;
}
case Event.KEYEVENTS: {
//DOM.setStyleAttribute(td, "backgroundColor", "#ffce00");
break;
}
case Event.ONFOCUS: {
//DOM.setStyleAttribute(td, "backgroundColor", "#ffce00");
break;
}
/*case Event. {
DOM.setStyleAttribute(td, "backgroundColor", "#ffce00");
break;
}*/
}
}
What do I need to do to capture this event?

The http://google-web-toolkit.googlecode.com/svn/javadoc/2.0/com/google/gwt/user/client/Event.html object passed into onBrowserEvent has methods. Methods such as boolean getCtrlKey().
case Event.ONCLICK: {
if (event.getCtrlKey()) {
DOM.setStyleAttribute(td, "backgroundColor", "#ffce00");
}
break;
}
This will work for Windows, not sure about Mac and Linux. On OS X you might check getMetaKey() instead, since Command is normally used where Control is used on Windows.

How about wrapping the contents of the cell in a FocusPanel and adding the appropriate handler (most likely MouseDownHandler)? (tip: create the handler once and add it to all the related cells)
You can also add key handlers, etc. to FocusPanel so you won't need to dabble in native browser events (which could lead to some trouble, browser-specific code, etc.), let GWT do that for you :)

Related

How to disable haptic feedback in showTimePicker()?

In Flutter, if you show a time picker by calling showTimePicker(), it will heavily vibrate when picking the time (in dial mode).
Is there a way to disable the time picker dialogs haptic feedback?
Looking at the source code, you can see that everything related to vibration is private API
void _vibrate() {
switch (Theme.of(context).platform) {
case TargetPlatform.android:
case TargetPlatform.fuchsia:
case TargetPlatform.linux:
case TargetPlatform.windows:
_vibrateTimer?.cancel();
_vibrateTimer = Timer(_kVibrateCommitDelay, () {
HapticFeedback.vibrate();
_vibrateTimer = null;
});
break;
case TargetPlatform.iOS:
case TargetPlatform.macOS:
break;
}
}
void _handleTimeChanged(TimeOfDay value) {
_vibrate();
setState(() {
_selectedTime.value = value;
});
}
So unfortunately, the only clean way is to create your own TimePickerDialog and change that behavior.

SplitButton does not close the dropdownitems once clicked

I am using component SfSplitButton of Blazor Syncfusion version 19.2.48 in razor page as below:
<SfSplitButton Content="Downloads"
Disabled="IsDownloadReportButtonDisabled"
CssClass="mr-2">
<SplitButtonEvents ItemSelected="OnDownloadReportItemSelected"></SplitButtonEvents>
<DropDownMenuItems>
<DropDownMenuItem Id="DownloadTcaReportItem" Text="Download Report"></DropDownMenuItem>
<DropDownMenuItem Id="DownloadTcaConsentReportItem" Text="Download Consent"></DropDownMenuItem>
#if (_isAccountOccupationalHealth)
{
<DropDownMenuItem Id="DownloadTcaSummaryReportItem" Text="Download Summary Report"></DropDownMenuItem>
}
</DropDownMenuItems>
</SfSplitButton>
#code{
private async Task OnDownloadReportItemSelected(MenuEventArgs args)
{
switch (args.Item.Id)
{
case "DownloadTcaReportItem":
//Do some task
break;
case "DownloadTcaSummaryReportItem":
//Do some task
break;
case "DownloadTcaConsentReportItem":
//Do some task
break;
}
}
}
after click on dropdown items still showing in the other pages

Public List In MainActivity and MVVM

I need some help with MVVM architecture.
I have a RecyclerView that receives LiveData and display it perfectly, however, my recyclerView requires another source of Data to customize colors and backgrounds of TextViews. for now I'm using a public list declared in the Mainactivity, But I've read that it's not a good practice.
is it possible to perform a non-live request to database from inside RecyclerView, in order to replace the public list ? if not I would really like some suggestions.
here is my onBindViewHolder:
#Override
public void onBindViewHolder(#NonNull ResultRecyclerViewAdapter.ResultHolder holder, int position) {
Results currentResult = results.get(position);
holder.ston1.setText(currentResult.getSton1());
holder.ston2.setText(String.valueOf(currentResult.getSton2()));
holder.ston1.setBackgroundColor(0xFF12FF45);
holder.ston2.setBackgroundColor(0xFF12FF45);
holder.ston1.getBackground().setAlpha(100);
holder.ston2.getBackground().setAlpha(100);
for (Ston ston: MainActivity.Stons){
if (currentResult.getStonCode().equals(ston.getStonCode()) && currentResult.getStonType().equals(ston.getStonType())){
switch (ston.getStonSelected()) {
case "WADS":
holder.ston1.getBackground().setAlpha(255);
break;
case "WQAS":
holder.ston2.getBackground().setAlpha(255);
break;
}
break;
}
}
holder.ston1.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Boolean found = false;
for (Ston ston: MainActivity.Stons){
if (currentResult.getStonCode().equals(ston.getStonCode())){
found = true;
break;
}
}
if (!found) {
holder.ston1.getBackground().setAlpha(255);
MainActivity.Stons.add(new Stons(currentResult.getStonCode(),"WADS",
currentResult.getStonType()));
}
else {
for (Ston ston : MainActivity.Stons) {
if (currentResult.getStonCode().equals(ston.getStonCode()) && ston.getStonSelected().equals("WADS") &&
ston.getStonType().equals(currentResult.getStonType())){
MainActivity.Stons.remove(ston);
holder.ston1.getBackground().setAlpha(100);
break;
}
}
}
}
});
holder.ston2.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Boolean found = false;
for (Ston ston: MainActivity.Stons){
if (currentResult.getStonCode().equals(ston.getStonCode())){
found = true;
break;
}
}
if (!found) {
holder.ston2.getBackground().setAlpha(255);
MainActivity.Stons.add(new Stons(currentResult.getStonCode(),"WQAS",
currentResult.getStonType()));
}
else {
for (Ston ston : MainActivity.Stons) {
if (currentResult.getStonCode().equals(ston.getStonCode()) && ston.getStonSelected().equals("WQAS") &&
ston.getStonType().equals(currentResult.getStonType())){
MainActivity.Stons.remove(ston);
holder.ston2.getBackground().setAlpha(100);
break;
}
}
}
}
});
One option that I see is to create new type specifically for your recyclerview adapter that will hold both Results object and information that you use for background alpha. So in your activity (or fragment) when livedata observer is triggered you don't directly pass it to adapter, but first create collection of objects of your new type, and then pass it to adapter. And I strongly suggest you to use Kotlin if possible, there you can use collection mapping to map collection from the db to your new type's collection.

How to Handle the OnItemClick and OnItemLongClick event while the ListView has setOnTouchListener

A ListView that I have setting the onTouchListener to implementate the item swipe function, and I still need the onItemClick and the onItemLongClick event, but I can't do it.
while I do noting int the onTouch function, and return false, the onItemClick or the longClick will response.the code like this:
public boolean onTouch(View v, MotionEvent event) {
return false
}
But when I have done something and then at the Action_Up I return it false, the click event no response.somting like that:
public boolean onTouch(View v, MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
// Todo something
break;
case MotionEvent.ACTION_MOVE:
// Todo something
break;
case MotionEvent.ACTION_UP:
// Todo something
if (the Condition) {
return true;
} else {
return false;
}
break;
default:
break;
}
return true;
}
I don't know why. I have search this for few days, and until now I still don't know how to do it.Please help me.
I have found the way. By the way, there are many libs to do this.

GWT Tree widgets swallow arrow keyboard events which make TextBoxes contained in TreeItems not respond to arrow keys

Easily reproducible in GWT 1.6.4:
Tree tree = new Tree();
tree.addItem(new TextBox());
The problem lies with onBrowserEvent in Tree:
switch (eventType) {
case Event.ONKEYDOWN:
case Event.ONKEYUP: {
if (isArrowKey(DOM.eventGetKeyCode(event))) {
DOM.eventCancelBubble(event, true);
DOM.eventPreventDefault(event);
return;
}
}
Like a lot of GWT widgets, they don't subclass well. There has to be a simple trick I could swing for this?
Solved this with a bit of a hack.
m_tree = new Tree()
{
#Override
protected boolean isKeyboardNavigationEnabled(TreeItem inCurrentItem)
{
return false;
}
#Override
public void onBrowserEvent(Event event) {
int eventType = DOM.eventGetType(event);
switch (eventType)
{
case Event.ONKEYDOWN:
case Event.ONKEYPRESS:
case Event.ONKEYUP:
return;
default:
break;
}
super.onBrowserEvent(event);
}
};