Why are accessibility service not working to take user actions? - java

#Override
public void onAccessibilityEvent(final AccessibilityEvent event) {
Date date = new Date(event.getEventTime());
SimpleDateFormat format = new SimpleDateFormat("dd/MM/yyyy hh:mm");
String time = format.format(date);
String reqTime = "25/11/2018 04:39";
if (reqTime.equals(time)) {
Log.d("MyAccessibilityService", "onAccessibilityEvent");
if (getRootInActiveWindow() == null) {
return;
}
AccessibilityNodeInfoCompat rootInActiveWindow = AccessibilityNodeInfoCompat.wrap(getRootInActiveWindow());
//Inspect app elements if ready
//Search bar is covered with textview which need to be clicked
List<AccessibilityNodeInfoCompat> clickOnQuestionMark = rootInActiveWindow.findAccessibilityNodeInfosByViewId("com.whatsapp:id/menuitem_search");
if (clickOnQuestionMark.isEmpty() || clickOnQuestionMark == null) {
return;
}
AccessibilityNodeInfoCompat clickMark = clickOnQuestionMark.get(0);
clickMark.performAction(AccessibilityNodeInfoCompat.ACTION_CLICK);
I am using this code for simuating clicking whatsapp search button, but when I opened whatsapp window on 25-11-2018 at 4:39 nothing happened. The code was working fine when no time was alloted. But problem was that everytime whatsapp was opened the search button would get clicked. How to click on the search button only when whatsapp is opened at a specific time?

You can convert to LocalDate
LocalDate localDate = date.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
and use equals method to specific LocalDate
Compares this LocalDate with another ensuring that the date is the same.
Only objects of type LocalDate are compared, other types return false.

Related

How to delete the entire Exchange Calender activities using Java EWS api?

I have written the code as below where it deletes the Appointment having current date but is there a way where i can delete the entire Calendar Appointments in one shot. Thanks in Advance
epublic static HashSet<String> userEventEws(ExchangeService service) {
HashSet<String> listSubject = new HashSet<String>();
Calendar yesterday = Calendar.getInstance();
Calendar now = Calendar.getInstance();
yesterday.add(Calendar.DATE, -1);
now.add(Calendar.DATE, 1);
Date startDate = yesterday.getTime();
Date endDate = now.getTime();
try {
CalendarFolder calendarFolder = CalendarFolder.bind(service, WellKnownFolderName.Calendar, new PropertySet());
CalendarView cView = new CalendarView(startDate,endDate);
cView.setPropertySet(new PropertySet(AppointmentSchema.Subject, AppointmentSchema.Start, AppointmentSchema.End));// we can set other properties
// as well depending upon our need.
FindItemsResults appointments = calendarFolder.findAppointments(cView);
List <Appointment>appList = appointments.getItems();
for (Appointment appointment : appList) {
listSubject.add(appointment.getSubject().trim());
appointment.delete(DeleteMode.HardDelete);
}
} catch (Exception e) {
e.printStackTrace();
}
return listSubject;
}
Generally the two options you have is you can batch delete the Items that you return from FindItems (find appointments will expand the recurring appointments which if you want to delete all the Items you don't want to do just delete the Master and single instances instead see https://msdn.microsoft.com/en-us/library/office/dn626016(v=exchg.150).aspx#bk_deleteews )
The other option would be to use the Empty Folder operation which should work in 2013 and above https://msdn.microsoft.com/en-us/library/office/ff709484%28v=exchg.150%29.aspx

How to get BooleanBinding from comparing 2 DatePickers?

I have two DatePickers and one Button on the GUI. I need to disable the button whenever the first datePicker has a date that is NOT before the second datePicker's date. i.e. before is false in the following snippet:
LocalDate date1 = dpFromDate.getValue();
LocalDate date2 = dpToDate.getValue();
boolean before = date1.isBefore(date2);
button.setDisable(!before);
using Bindings APIs.
BooleanBinding bb = ???;
button.disableProperty().bind(bb);
Here is my working solution, but I believe there is a better API to handle such situation:
BooleanBinding bb = Bindings.selectInteger(dpFromDate.valueProperty(), "year")
.greaterThanOrEqualTo(Bindings.selectInteger(dpToDate.valueProperty(), "year"));
bb = bb.or(
Bindings.selectInteger(dpFromDate.valueProperty(), "year")
.isEqualTo(Bindings.selectInteger(dpToDate.valueProperty(), "year"))
.and(Bindings.selectInteger(dpFromDate.valueProperty(), "monthValue")
.greaterThanOrEqualTo(Bindings.selectInteger(dpToDate.valueProperty(), "monthValue")))
);
bb = bb.or(
Bindings.selectInteger(dpFromDate.valueProperty(), "year")
.isEqualTo(Bindings.selectInteger(dpToDate.valueProperty(), "year"))
.and(Bindings.selectInteger(dpFromDate.valueProperty(), "monthValue")
.isEqualTo(Bindings.selectInteger(dpToDate.valueProperty(), "monthValue")))
.and(Bindings.selectInteger(dpFromDate.valueProperty(), "dayOfMonth")
.greaterThanOrEqualTo(Bindings.selectInteger(dpToDate.valueProperty(), "dayOfMonth")))
);
Just create a BooleanBinding depending on the DatePicker values that compares both dates. This way you don't have to write the functionality yourself and even more important - you don't need to create such a complicated binding:
BooleanBinding bb = Bindings.createBooleanBinding(() -> {
LocalDate from = dpFromDate.getValue();
LocalDate to = dpToDate.getValue();
// disable, if one selection is missing or from is not smaller than to
return (from == null || to == null || (from.compareTo(to) >= 0));
}, dpFromDate.valueProperty(), dpToDate.valueProperty());
button.disableProperty().bind(bb);

validateDateTimeRange tag for Oracle MAF

I'm trying to implement FROM and TO Date validation in Oracle MAF form.
In ADF I have seen the tag some thing like <af:validateDateTimeRange minimum="" maximum=""/>. From this blog you can get more details, It can be implemented in ADF application.
But I could't find such tag in Oracle MAF. Can you please suggest me, if you got any link to support this requirement?
you would need to use a value change listener. There is no equivalent tag in MAF
Frank
As suggested by Frank, below is the workaround to achieve this.
AMX Page:
<amx:inputDate value="#{bindings.inspFromDate.inputValue}" label="From Date" showRequired="true" inputType="datetime" valueChangeListener="#{validationBean.dateValidation}"/>
<amx:inputDate value="#{bindings.inspToDate.inputValue}" label="To Date" showRequired="true" inputType="datetime" valueChangeListener="#{validationBean.dateValidation}"/>
ValidationBean.java
public void dateValidation(ValueChangeEvent valueChangeEvent) throws ParseException {
String fromDate = (String) AdfmfJavaUtilities.evaluateELExpression("#{bindings.inspFromDate.inputValue}");
String toDate = (String) AdfmfJavaUtilities.evaluateELExpression("#{bindings.inspToDate.inputValue}");
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXXX");
formatter.setTimeZone(TimeZone.getTimeZone("IST"));
if (fromDate != null && !fromDate.isEmpty() && toDate != null && !toDate.isEmpty()) {
java.util.Date inputFromDate = formatter.parse(fromDate);
java.sql.Timestamp formattedFromDate = new Timestamp(inputFromDate.getTime());
java.util.Date inputToDate = formatter.parse(toDate);
java.sql.Timestamp formattedToDate = new Timestamp(inputToDate.getTime());
if (formattedFromDate.compareTo(formattedToDate) > 0) {
System.out.println("fromDate is greater than toDate");
throw new AdfException("From Date should be less than To Date.!", AdfException.INFO);
} else if (formattedFromDate.compareTo(formattedToDate) < 0) {
System.out.println("fromDate is less than toDate");
} else if (formattedFromDate.compareTo(formattedToDate) == 0) {
System.out.println("fromDate is equal to toDate");
}
}
}
This method will get both from date and to date from the front screen and convert into timestamp format to validate which is greater.
If From Date is greater than To Date, then it will show you the alert by saying that "From Date should be less than To Date.!". Below is the screenshot, how it will render in the front screen.
Hope this helps some one.!

Android - Create Custom Calendar with Event

I have an App which shows special Days. I want to integrate them into the calendar.
The events are static, they don't change, so I don't have to update the calendar very often.
I first thought of creating a local calendar and add the events, but new android versions (since 2.3?) seem not to support that; to implement I would have to create a Calendar Provider.
I saw this project on github: https://github.com/dschuermann/birthday-adapter. It is very complicated; its main use is adding the birthdays of the contacts to a new calendar.
There is lots of code, much of which I don't think I need. Do I really need to register to android's account manager to integrate a Calendar Provider? I just need a new Calendar with my event...
Would it be easier to take the user's default Calendar and add all the Events there? I could add some identifiers to the description, to be able to remove the events if the user doesn't want them.
Any tips, tutorials, or further readings are appreciated.
Metin Kale
You can create events in your device calendar via Intent. I think it could be useful for you.
public long addEventToCalender(ContentResolver cr, String title, String addInfo, String place, int status,
long startDate, boolean isRemind,long endDate) {
String eventUriStr = "content://com.android.calendar/events";
ContentValues event = new ContentValues();
// id, We need to choose from our mobile for primary its 1
event.put("calendar_id", 1);
event.put("title", title);
event.put("description", addInfo);
event.put("eventLocation", place);
event.put("eventTimezone", "UTC/GMT +2:00");
// For next 1hr
event.put("dtstart", startDate);
event.put("dtend", endDate);
//If it is bithday alarm or such kind (which should remind me for whole day) 0 for false, 1 for true
// values.put("allDay", 1);
// event.put("eventStatus", status);
event.put("hasAlarm", 1);
Uri eventUri = cr.insert(Uri.parse(eventUriStr), event);
long eventID = Long.parseLong(eventUri.getLastPathSegment());
if (isRemind) {
String reminderUriString = "content://com.android.calendar/reminders";
ContentValues reminderValues = new ContentValues();
reminderValues.put("event_id", eventID);
// Default value of the system. Minutes is a integer
reminderValues.put("minutes", 5);
// Alert Methods: Default(0), Alert(1), Email(2), SMS(3)
reminderValues.put("method", 1);
cr.insert(Uri.parse(reminderUriString), reminderValues); //Uri reminderUri =
}
return eventID;
}
For more information visit http://developer.android.com/reference/java/util/Calendar.html
In this reply you how to get contacts and birthdays.
Android Applicaiton - How to get birthday of a contact
and this library will offer you a powerful and flexible schedule so you can use
Caldroid Library

IllegalArgumentException after form submission returns message

I have a UIPanel that contains form elements. On click of submit, the form validates all the fields and if they are all valid, proceeds to insert the field values into the DB. If the DB returns a duplicate key exception, I show a message telling the user to update the field (See http://goo.gl/jOzZGG).
The message shows up, and the form loads properly for the most part, but a problem occurs when the Calendar element throws
java.lang.IllegalArgumentException: Cannot format given Object as a Date
If I submit the form and the forms finds errors during validation (related or unrelated to this Calendar field) there are no problems, only after validation is completed, and I add this message does it throw this exception.
Code for how I am generating the Calendar is below, but I am not sure why it would only throw an error in this scenario and not any other.
Calendar input = new Calendar();
input.setPattern("MM/dd/yyy");
input.setId(inputId);
input.setStyleClass(inputId);
input.setShowOn("button");
input.setNavigator(true);
input.setValueBinding("value", vb);
if(defaultVal != null && !defaultVal.equals("")){
SimpleDateFormat dbFormat = new SimpleDateFormat("yyyy-MM-dd");
SimpleDateFormat displayFormat = new SimpleDateFormat("MM/dd/yyyy");
String defaultDate = displayFormat.format(dbFormat.parse(defaultVal));
Date date = new Date();
date = displayFormat.parse(defaultDate);
if(required != null && !required.equals("") && !required.equals(",") && mandatory.length > 1){
if(mandatory[1].equalsIgnoreCase("Y")){
input.setRequired(true);
input.setRequiredMessage("Please enter a "+inputLabel+".");
HtmlMessage message = new HtmlMessage();
message.setFor(inputId);
message.setStyleClass("errorMessage");
div.getChildren().add(input);
div.getChildren().add(message);
}else{
input.setRequired(false);
div.getChildren().add(input);
}
}else{
div.getChildren().add(input);
}
}

Categories