Calendar trigger
This commit is contained in:
parent
5f278a6ba0
commit
67238bd2f0
@ -143,6 +143,8 @@ public class ActivityManageRule extends Activity
|
|||||||
final static int requestCodeActionCopyTextToClipboardEdit = 830;
|
final static int requestCodeActionCopyTextToClipboardEdit = 830;
|
||||||
final static int requestCodeActionSetLocationServiceAdd = 831;
|
final static int requestCodeActionSetLocationServiceAdd = 831;
|
||||||
final static int requestCodeActionSetLocationServiceEdit = 832;
|
final static int requestCodeActionSetLocationServiceEdit = 832;
|
||||||
|
final static int requestCodeTriggerCalendarEventAdd = 833;
|
||||||
|
final static int requestCodeTriggerCalendarEventEdit = 834;
|
||||||
|
|
||||||
public static ActivityManageRule getInstance()
|
public static ActivityManageRule getInstance()
|
||||||
{
|
{
|
||||||
@ -347,6 +349,12 @@ public class ActivityManageRule extends Activity
|
|||||||
variableStateEditor.putExtra(intentNameTriggerParameter2, selectedTrigger.getTriggerParameter2());
|
variableStateEditor.putExtra(intentNameTriggerParameter2, selectedTrigger.getTriggerParameter2());
|
||||||
startActivityForResult(variableStateEditor, requestCodeTriggerCheckVariableEdit);
|
startActivityForResult(variableStateEditor, requestCodeTriggerCheckVariableEdit);
|
||||||
break;
|
break;
|
||||||
|
case calendarEvent:
|
||||||
|
Intent calendarStateEditor = new Intent(ActivityManageRule.this, ActivityManageTriggerCalendar.class);
|
||||||
|
calendarStateEditor.putExtra(intentNameTriggerParameter1, selectedTrigger.getTriggerParameter());
|
||||||
|
calendarStateEditor.putExtra(intentNameTriggerParameter2, selectedTrigger.getTriggerParameter2());
|
||||||
|
startActivityForResult(calendarStateEditor, requestCodeTriggerCalendarEventEdit);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -636,6 +644,8 @@ public class ActivityManageRule extends Activity
|
|||||||
items.add(new Item(typesLong[i].toString(), R.drawable.router));
|
items.add(new Item(typesLong[i].toString(), R.drawable.router));
|
||||||
else if(types[i].toString().equals(Trigger_Enum.subSystemState.toString()))
|
else if(types[i].toString().equals(Trigger_Enum.subSystemState.toString()))
|
||||||
items.add(new Item(typesLong[i].toString(), R.drawable.subsystemstate));
|
items.add(new Item(typesLong[i].toString(), R.drawable.subsystemstate));
|
||||||
|
else if(types[i].toString().equals(Trigger_Enum.calendarEvent.toString()))
|
||||||
|
items.add(new Item(typesLong[i].toString(), R.drawable.calendar));
|
||||||
else
|
else
|
||||||
items.add(new Item(typesLong[i].toString(), R.drawable.placeholder));
|
items.add(new Item(typesLong[i].toString(), R.drawable.placeholder));
|
||||||
}
|
}
|
||||||
@ -644,15 +654,15 @@ public class ActivityManageRule extends Activity
|
|||||||
{
|
{
|
||||||
public View getView(int position, View convertView, ViewGroup parent)
|
public View getView(int position, View convertView, ViewGroup parent)
|
||||||
{
|
{
|
||||||
//User super class to create the View
|
// User super class to create the View
|
||||||
View v = super.getView(position, convertView, parent);
|
View v = super.getView(position, convertView, parent);
|
||||||
|
|
||||||
TextView tv = (TextView)v.findViewById(android.R.id.text1);
|
TextView tv = (TextView)v.findViewById(android.R.id.text1);
|
||||||
|
|
||||||
//Put the image on the TextView
|
// Put the image on the TextView
|
||||||
tv.setCompoundDrawablesWithIntrinsicBounds(items.get(position).icon, 0, 0, 0);
|
tv.setCompoundDrawablesWithIntrinsicBounds(items.get(position).icon, 0, 0, 0);
|
||||||
|
|
||||||
//Add margin between image and text (support various screen densities)
|
// Add margin between image and text (support various screen densities)
|
||||||
int dp5 = (int) (5 * getResources().getDisplayMetrics().density + 0.5f);
|
int dp5 = (int) (5 * getResources().getDisplayMetrics().density + 0.5f);
|
||||||
tv.setCompoundDrawablePadding(dp5);
|
tv.setCompoundDrawablePadding(dp5);
|
||||||
|
|
||||||
@ -861,6 +871,13 @@ public class ActivityManageRule extends Activity
|
|||||||
startActivityForResult(variableTriggerEditor, requestCodeTriggerCheckVariableAdd);
|
startActivityForResult(variableTriggerEditor, requestCodeTriggerCheckVariableAdd);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
else if(triggerType == Trigger_Enum.calendarEvent)
|
||||||
|
{
|
||||||
|
newTrigger.setTriggerType(Trigger_Enum.calendarEvent);
|
||||||
|
Intent calendarTriggerEditor = new Intent(myContext, ActivityManageTriggerCalendar.class);
|
||||||
|
startActivityForResult(calendarTriggerEditor, requestCodeTriggerCalendarEventAdd);
|
||||||
|
return;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
getTriggerParameterDialog(context, booleanChoices).show();
|
getTriggerParameterDialog(context, booleanChoices).show();
|
||||||
|
|
||||||
@ -1994,6 +2011,17 @@ public class ActivityManageRule extends Activity
|
|||||||
this.refreshTriggerList();
|
this.refreshTriggerList();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if(requestCode == requestCodeTriggerCalendarEventAdd)
|
||||||
|
{
|
||||||
|
if(resultCode == RESULT_OK)
|
||||||
|
{
|
||||||
|
newTrigger.setTriggerParameter(data.getBooleanExtra(intentNameTriggerParameter1, true));
|
||||||
|
newTrigger.setTriggerParameter2(data.getStringExtra(intentNameTriggerParameter2));
|
||||||
|
newTrigger.setParentRule(ruleToEdit);
|
||||||
|
ruleToEdit.getTriggerSet().add(newTrigger);
|
||||||
|
this.refreshTriggerList();
|
||||||
|
}
|
||||||
|
}
|
||||||
else if(requestCode == requestCodeTriggerTetheringEdit)
|
else if(requestCode == requestCodeTriggerTetheringEdit)
|
||||||
{
|
{
|
||||||
if(resultCode == RESULT_OK)
|
if(resultCode == RESULT_OK)
|
||||||
@ -2033,6 +2061,19 @@ public class ActivityManageRule extends Activity
|
|||||||
this.refreshTriggerList();
|
this.refreshTriggerList();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if(requestCode == requestCodeTriggerCalendarEventEdit)
|
||||||
|
{
|
||||||
|
if(resultCode == RESULT_OK)
|
||||||
|
{
|
||||||
|
Trigger editedTrigger = new Trigger();
|
||||||
|
editedTrigger.setTriggerType(Trigger_Enum.calendarEvent);
|
||||||
|
editedTrigger.setTriggerParameter(data.getBooleanExtra(intentNameTriggerParameter1, true));
|
||||||
|
editedTrigger.setTriggerParameter2(data.getStringExtra(intentNameTriggerParameter2));
|
||||||
|
editedTrigger.setParentRule(ruleToEdit);
|
||||||
|
ruleToEdit.getTriggerSet().set(editIndex, editedTrigger);
|
||||||
|
this.refreshTriggerList();
|
||||||
|
}
|
||||||
|
}
|
||||||
else if(requestCode == requestCodeActionCopyTextToClipboardAdd)
|
else if(requestCode == requestCodeActionCopyTextToClipboardAdd)
|
||||||
{
|
{
|
||||||
if(resultCode == RESULT_OK)
|
if(resultCode == RESULT_OK)
|
||||||
|
@ -1,15 +1,30 @@
|
|||||||
package com.jens.automation2;
|
package com.jens.automation2;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
|
import android.content.Intent;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.view.View;
|
||||||
|
import android.widget.ArrayAdapter;
|
||||||
|
import android.widget.Button;
|
||||||
import android.widget.CheckBox;
|
import android.widget.CheckBox;
|
||||||
import android.widget.CompoundButton;
|
import android.widget.CompoundButton;
|
||||||
|
import android.widget.EditText;
|
||||||
|
import android.widget.Spinner;
|
||||||
|
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
|
|
||||||
public class ActivityManageTriggerCalendar extends Activity
|
public class ActivityManageTriggerCalendar extends Activity
|
||||||
{
|
{
|
||||||
CheckBox chkCalendarEventDirection;
|
CheckBox chkCalendarEventDirection;
|
||||||
|
Spinner spinnerCalendarTitleDirection, spinnerCalendarLocationDirection, spinnerCalendarDescriptionDirection, spinnerCalendarAvailabilityDirection, spinnerCalendarAvailability;
|
||||||
|
EditText etCalendarTitle, etCalendarLocation, etCalendarDescription;
|
||||||
|
Button bSaveTriggerCalendar;
|
||||||
|
|
||||||
|
private static String[] directions;
|
||||||
|
ArrayAdapter<String> directionSpinnerAdapter;
|
||||||
|
|
||||||
|
private static String[] availabilities;
|
||||||
|
ArrayAdapter<String> availabilitySpinnerAdapter;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(@Nullable Bundle savedInstanceState)
|
protected void onCreate(@Nullable Bundle savedInstanceState)
|
||||||
@ -19,6 +34,51 @@ public class ActivityManageTriggerCalendar extends Activity
|
|||||||
setContentView(R.layout.activity_manage_trigger_calendar);
|
setContentView(R.layout.activity_manage_trigger_calendar);
|
||||||
|
|
||||||
chkCalendarEventDirection = (CheckBox) findViewById(R.id.chkCalendarEventDirection);
|
chkCalendarEventDirection = (CheckBox) findViewById(R.id.chkCalendarEventDirection);
|
||||||
|
spinnerCalendarTitleDirection = (Spinner)findViewById(R.id.spinnerCalendarTitleDirection);
|
||||||
|
spinnerCalendarLocationDirection = (Spinner)findViewById(R.id.spinnerCalendarLocationDirection);
|
||||||
|
spinnerCalendarDescriptionDirection = (Spinner)findViewById(R.id.spinnerCalendarDescriptionDirection);
|
||||||
|
spinnerCalendarAvailabilityDirection = (Spinner)findViewById(R.id.spinnerCalendarAvailabilityDirection);
|
||||||
|
spinnerCalendarAvailability = (Spinner)findViewById(R.id.spinnerCalendarAvailability);
|
||||||
|
|
||||||
|
etCalendarTitle = (EditText)findViewById(R.id.etCalendarTitle);
|
||||||
|
etCalendarLocation = (EditText)findViewById(R.id.etCalendarLocation);
|
||||||
|
etCalendarDescription = (EditText)findViewById(R.id.etCalendarDescription);
|
||||||
|
|
||||||
|
bSaveTriggerCalendar = (Button)findViewById(R.id.bSaveTriggerCalendar);
|
||||||
|
|
||||||
|
directions = new String[] {
|
||||||
|
getResources().getString(R.string.directionStringEquals),
|
||||||
|
getResources().getString(R.string.directionStringContains),
|
||||||
|
getResources().getString(R.string.directionStringDoesNotContain),
|
||||||
|
getResources().getString(R.string.directionStringStartsWith),
|
||||||
|
getResources().getString(R.string.directionStringEndsWith),
|
||||||
|
getResources().getString(R.string.directionStringNotEquals)
|
||||||
|
};
|
||||||
|
directionSpinnerAdapter = new ArrayAdapter<String>(this, R.layout.text_view_for_poi_listview_mediumtextsize, ActivityManageTriggerCalendar.directions);
|
||||||
|
spinnerCalendarTitleDirection.setAdapter(directionSpinnerAdapter);
|
||||||
|
spinnerCalendarLocationDirection.setAdapter(directionSpinnerAdapter);
|
||||||
|
spinnerCalendarDescriptionDirection.setAdapter(directionSpinnerAdapter);
|
||||||
|
spinnerCalendarAvailabilityDirection.setAdapter(directionSpinnerAdapter);
|
||||||
|
directionSpinnerAdapter.notifyDataSetChanged();
|
||||||
|
|
||||||
|
/*
|
||||||
|
AVAILABILITY_BUSY = 0
|
||||||
|
AVAILABILITY_FREE = 1;
|
||||||
|
AVAILABILITY_TENTATIVE = 2;
|
||||||
|
============================ Own Types:
|
||||||
|
EXCHANGE OOF = 3
|
||||||
|
EXCHANGE WORKING ELSEWHERE = 4
|
||||||
|
*/
|
||||||
|
availabilities = new String[] {
|
||||||
|
getResources().getString(R.string.calendarStringBusy),
|
||||||
|
getResources().getString(R.string.calendarStringFree),
|
||||||
|
getResources().getString(R.string.calendarStringTentative),
|
||||||
|
getResources().getString(R.string.calendarStringOutOfOffice),
|
||||||
|
getResources().getString(R.string.calendarStringWorkingElsewhere),
|
||||||
|
};
|
||||||
|
availabilitySpinnerAdapter = new ArrayAdapter<String>(this, R.layout.text_view_for_poi_listview_mediumtextsize, ActivityManageTriggerCalendar.availabilities);
|
||||||
|
spinnerCalendarAvailability.setAdapter(availabilitySpinnerAdapter);
|
||||||
|
availabilitySpinnerAdapter.notifyDataSetChanged();
|
||||||
|
|
||||||
chkCalendarEventDirection.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener()
|
chkCalendarEventDirection.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener()
|
||||||
{
|
{
|
||||||
@ -31,5 +91,82 @@ public class ActivityManageTriggerCalendar extends Activity
|
|||||||
chkCalendarEventDirection.setText(R.string.eventIsCurrentlyNotHappening);
|
chkCalendarEventDirection.setText(R.string.eventIsCurrentlyNotHappening);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
bSaveTriggerCalendar.setOnClickListener(new View.OnClickListener()
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public void onClick(View view)
|
||||||
|
{
|
||||||
|
String titleDir = Trigger.getMatchCode(spinnerCalendarTitleDirection.getSelectedItem().toString());
|
||||||
|
String title = etCalendarTitle.getText().toString();
|
||||||
|
String descriptionDir = Trigger.getMatchCode(spinnerCalendarDescriptionDirection.getSelectedItem().toString());
|
||||||
|
String description = etCalendarDescription.getText().toString();
|
||||||
|
String locationDir = Trigger.getMatchCode(spinnerCalendarLocationDirection.getSelectedItem().toString());
|
||||||
|
String location = etCalendarLocation.getText().toString();
|
||||||
|
String availabilityDir = Trigger.getMatchCode(spinnerCalendarAvailabilityDirection.getSelectedItem().toString());
|
||||||
|
int availability = spinnerCalendarAvailability.getSelectedItemPosition();
|
||||||
|
|
||||||
|
String returnString =
|
||||||
|
titleDir + Trigger.triggerParameter2Split + title + Trigger.triggerParameter2Split +
|
||||||
|
descriptionDir + Trigger.triggerParameter2Split + description + Trigger.triggerParameter2Split +
|
||||||
|
locationDir + Trigger.triggerParameter2Split + location + Trigger.triggerParameter2Split +
|
||||||
|
availabilityDir + Trigger.triggerParameter2Split + String.valueOf(availability);
|
||||||
|
|
||||||
|
Intent data = new Intent();
|
||||||
|
data.putExtra(ActivityManageRule.intentNameTriggerParameter1, chkCalendarEventDirection.isChecked());
|
||||||
|
data.putExtra(ActivityManageRule.intentNameTriggerParameter2, returnString);
|
||||||
|
ActivityManageTriggerCalendar.this.setResult(RESULT_OK, data);
|
||||||
|
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
Intent inputIntent = getIntent();
|
||||||
|
if(inputIntent.hasExtra(ActivityManageRule.intentNameTriggerParameter1))
|
||||||
|
loadValuesIntoGui(inputIntent);
|
||||||
|
}
|
||||||
|
|
||||||
|
void loadValuesIntoGui(Intent data)
|
||||||
|
{
|
||||||
|
//TODO:try-catch
|
||||||
|
|
||||||
|
if(data.hasExtra(ActivityManageRule.intentNameTriggerParameter1))
|
||||||
|
chkCalendarEventDirection.setChecked(data.getBooleanExtra(ActivityManageRule.intentNameTriggerParameter1, true));
|
||||||
|
|
||||||
|
if(data.hasExtra(ActivityManageRule.intentNameTriggerParameter2))
|
||||||
|
{
|
||||||
|
String input[] = data.getStringExtra(ActivityManageRule.intentNameTriggerParameter2).split(Trigger.triggerParameter2Split);
|
||||||
|
/*
|
||||||
|
0 = titleDir
|
||||||
|
1 = title
|
||||||
|
2 = descriptionDir
|
||||||
|
3 = description
|
||||||
|
4 = locationDir
|
||||||
|
5 = location
|
||||||
|
6 = availabilityDir
|
||||||
|
7 = availability
|
||||||
|
*/
|
||||||
|
|
||||||
|
for(int i = 0; i < directions.length; i++)
|
||||||
|
{
|
||||||
|
if(Trigger.getMatchCode(directions[i]).equalsIgnoreCase(input[0]))
|
||||||
|
spinnerCalendarTitleDirection.setSelection(i);
|
||||||
|
|
||||||
|
if(Trigger.getMatchCode(directions[i]).equalsIgnoreCase(input[2]))
|
||||||
|
spinnerCalendarDescriptionDirection.setSelection(i);
|
||||||
|
|
||||||
|
if(Trigger.getMatchCode(directions[i]).equalsIgnoreCase(input[4]))
|
||||||
|
spinnerCalendarLocationDirection.setSelection(i);
|
||||||
|
|
||||||
|
if(Trigger.getMatchCode(directions[i]).equalsIgnoreCase(input[6]))
|
||||||
|
spinnerCalendarAvailabilityDirection.setSelection(i);
|
||||||
|
}
|
||||||
|
|
||||||
|
spinnerCalendarAvailability.setSelection(Integer.parseInt(input[7]));
|
||||||
|
|
||||||
|
etCalendarTitle.setText(input[1]);
|
||||||
|
etCalendarDescription.setText(input[3]);
|
||||||
|
etCalendarLocation.setText(input[5]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -580,6 +580,9 @@ public class ActivityPermissions extends Activity
|
|||||||
case notification:
|
case notification:
|
||||||
addToArrayListUnique(Manifest.permission.BIND_NOTIFICATION_LISTENER_SERVICE, requiredPermissions);
|
addToArrayListUnique(Manifest.permission.BIND_NOTIFICATION_LISTENER_SERVICE, requiredPermissions);
|
||||||
break;
|
break;
|
||||||
|
case calendarEvent:
|
||||||
|
addToArrayListUnique(Manifest.permission.READ_CALENDAR, requiredPermissions);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -1023,6 +1026,10 @@ public class ActivityPermissions extends Activity
|
|||||||
for(String ruleName : getRulesUsing(Action.Action_Enum.setLocationService))
|
for(String ruleName : getRulesUsing(Action.Action_Enum.setLocationService))
|
||||||
usingElements.add(String.format(getResources().getString(R.string.ruleXrequiresThis), ruleName));
|
usingElements.add(String.format(getResources().getString(R.string.ruleXrequiresThis), ruleName));
|
||||||
break;
|
break;
|
||||||
|
case Manifest.permission.READ_CALENDAR:
|
||||||
|
for(String ruleName : getRulesUsing(Trigger.Trigger_Enum.calendarEvent))
|
||||||
|
usingElements.add(String.format(getResources().getString(R.string.ruleXrequiresThis), ruleName));
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return usingElements;
|
return usingElements;
|
||||||
|
@ -6,6 +6,7 @@ import android.util.Log;
|
|||||||
import com.jens.automation2.location.CellLocationChangedReceiver;
|
import com.jens.automation2.location.CellLocationChangedReceiver;
|
||||||
import com.jens.automation2.location.WifiBroadcastReceiver;
|
import com.jens.automation2.location.WifiBroadcastReceiver;
|
||||||
import com.jens.automation2.receivers.BroadcastListener;
|
import com.jens.automation2.receivers.BroadcastListener;
|
||||||
|
import com.jens.automation2.receivers.CalendarReceiver;
|
||||||
import com.jens.automation2.receivers.DateTimeListener;
|
import com.jens.automation2.receivers.DateTimeListener;
|
||||||
import com.jens.automation2.receivers.AutomationListenerInterface;
|
import com.jens.automation2.receivers.AutomationListenerInterface;
|
||||||
import com.jens.automation2.receivers.BatteryReceiver;
|
import com.jens.automation2.receivers.BatteryReceiver;
|
||||||
@ -210,6 +211,9 @@ public class ReceiverCoordinator
|
|||||||
|
|
||||||
if(Rule.isAnyRuleUsing(Trigger.Trigger_Enum.screenState))
|
if(Rule.isAnyRuleUsing(Trigger.Trigger_Enum.screenState))
|
||||||
ScreenStateReceiver.startScreenStateReceiver(AutomationService.getInstance());
|
ScreenStateReceiver.startScreenStateReceiver(AutomationService.getInstance());
|
||||||
|
|
||||||
|
if(Rule.isAnyRuleUsing(Trigger.Trigger_Enum.calendarEvent))
|
||||||
|
CalendarReceiver.startCalendarReceiver(AutomationService.getInstance());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void stopAllReceivers()
|
public static void stopAllReceivers()
|
||||||
@ -243,6 +247,7 @@ public class ReceiverCoordinator
|
|||||||
BluetoothReceiver.stopBluetoothReceiver();
|
BluetoothReceiver.stopBluetoothReceiver();
|
||||||
HeadphoneJackListener.getInstance().stopListener(AutomationService.getInstance());
|
HeadphoneJackListener.getInstance().stopListener(AutomationService.getInstance());
|
||||||
DeviceOrientationListener.getInstance().stopListener(AutomationService.getInstance());
|
DeviceOrientationListener.getInstance().stopListener(AutomationService.getInstance());
|
||||||
|
CalendarReceiver.getInstance().stopListener(AutomationService.getInstance());
|
||||||
}
|
}
|
||||||
catch(Exception e)
|
catch(Exception e)
|
||||||
{
|
{
|
||||||
|
@ -127,7 +127,7 @@ public class Trigger
|
|||||||
case checkVariable:
|
case checkVariable:
|
||||||
return context.getResources().getString(R.string.checkVariable);
|
return context.getResources().getString(R.string.checkVariable);
|
||||||
case calendarEvent:
|
case calendarEvent:
|
||||||
return context.getResources().getString(R.string.calendarEvent);
|
return context.getResources().getString(R.string.calendarEventCapital);
|
||||||
default:
|
default:
|
||||||
return "Unknown";
|
return "Unknown";
|
||||||
}
|
}
|
||||||
@ -1880,6 +1880,12 @@ public class Trigger
|
|||||||
else
|
else
|
||||||
returnString.append(String.format(Miscellaneous.getAnyContext().getResources().getString(R.string.variableCheckStringDeleted), triggerParameter2));
|
returnString.append(String.format(Miscellaneous.getAnyContext().getResources().getString(R.string.variableCheckStringDeleted), triggerParameter2));
|
||||||
break;
|
break;
|
||||||
|
case calendarEvent:
|
||||||
|
if(triggerParameter)
|
||||||
|
returnString.append(Miscellaneous.getAnyContext().getResources().getString(R.string.eventIsCurrentlyHappening));
|
||||||
|
else
|
||||||
|
returnString.append(Miscellaneous.getAnyContext().getResources().getString(R.string.eventIsCurrentlyNotHappening));
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
returnString.append("error");
|
returnString.append("error");
|
||||||
break;
|
break;
|
||||||
|
@ -18,9 +18,20 @@ import java.util.List;
|
|||||||
|
|
||||||
public class CalendarReceiver extends BroadcastReceiver implements AutomationListenerInterface
|
public class CalendarReceiver extends BroadcastReceiver implements AutomationListenerInterface
|
||||||
{
|
{
|
||||||
static BroadcastReceiver calendarReceiverInstance = null;
|
static CalendarReceiver calendarReceiverInstance = null;
|
||||||
static boolean calendarReceiverActive = false;
|
static boolean calendarReceiverActive = false;
|
||||||
static IntentFilter calendarIntentFilter = null;
|
static IntentFilter calendarIntentFilter = null;
|
||||||
|
private static AutomationService automationServiceRef;
|
||||||
|
private static Intent calendarIntent = null;
|
||||||
|
|
||||||
|
public static CalendarReceiver getInstance()
|
||||||
|
{
|
||||||
|
if(calendarReceiverInstance == null)
|
||||||
|
calendarReceiverInstance = new CalendarReceiver();
|
||||||
|
|
||||||
|
return calendarReceiverInstance;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onReceive(Context context, Intent intent)
|
public void onReceive(Context context, Intent intent)
|
||||||
{
|
{
|
||||||
@ -41,7 +52,7 @@ public class CalendarReceiver extends BroadcastReceiver implements AutomationLis
|
|||||||
if(!calendarReceiverActive)
|
if(!calendarReceiverActive)
|
||||||
{
|
{
|
||||||
if(calendarReceiverInstance == null)
|
if(calendarReceiverInstance == null)
|
||||||
calendarReceiverInstance = new BatteryReceiver();
|
calendarReceiverInstance = new CalendarReceiver();
|
||||||
|
|
||||||
if(calendarIntentFilter == null)
|
if(calendarIntentFilter == null)
|
||||||
{
|
{
|
||||||
@ -99,7 +110,7 @@ public class CalendarReceiver extends BroadcastReceiver implements AutomationLis
|
|||||||
Cursor cursor = context.getContentResolver()
|
Cursor cursor = context.getContentResolver()
|
||||||
.query(
|
.query(
|
||||||
Uri.parse("content://com.android.calendar/events"),
|
Uri.parse("content://com.android.calendar/events"),
|
||||||
new String[] { "calendar_id", "title", "description", "dtstart", "dtend", "eventLocation", "AVAILABILITY" },
|
new String[] { "calendar_id", "title", "description", "dtstart", "dtend", "eventLocation", "availability" },
|
||||||
null, null, null);
|
null, null, null);
|
||||||
|
|
||||||
cursor.moveToFirst();
|
cursor.moveToFirst();
|
||||||
@ -109,6 +120,8 @@ public class CalendarReceiver extends BroadcastReceiver implements AutomationLis
|
|||||||
List<CalendarEvent> eventlist = new ArrayList<>();
|
List<CalendarEvent> eventlist = new ArrayList<>();
|
||||||
|
|
||||||
for (int i = 0; i < CNames.length; i++)
|
for (int i = 0; i < CNames.length; i++)
|
||||||
|
{
|
||||||
|
try
|
||||||
{
|
{
|
||||||
CalendarEvent event = new CalendarEvent();
|
CalendarEvent event = new CalendarEvent();
|
||||||
event.id = cursor.getString(1);
|
event.id = cursor.getString(1);
|
||||||
@ -117,12 +130,49 @@ public class CalendarReceiver extends BroadcastReceiver implements AutomationLis
|
|||||||
event.start = Miscellaneous.calendarFromLong(Long.parseLong(cursor.getString(4)));
|
event.start = Miscellaneous.calendarFromLong(Long.parseLong(cursor.getString(4)));
|
||||||
event.end = Miscellaneous.calendarFromLong(Long.parseLong(cursor.getString(5)));
|
event.end = Miscellaneous.calendarFromLong(Long.parseLong(cursor.getString(5)));
|
||||||
event.location = cursor.getString(6);
|
event.location = cursor.getString(6);
|
||||||
event.availability = cursor.getString(7)
|
event.availability = cursor.getString(7);
|
||||||
eventlist.add(event);
|
eventlist.add(event);
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{}
|
||||||
cursor.moveToNext();
|
cursor.moveToNext();
|
||||||
}
|
}
|
||||||
|
|
||||||
return eventlist;
|
return eventlist;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void startCalendarReceiver(final AutomationService automationServiceRef)
|
||||||
|
{
|
||||||
|
if (!calendarReceiverActive)
|
||||||
|
{
|
||||||
|
CalendarReceiver.automationServiceRef = automationServiceRef;
|
||||||
|
|
||||||
|
if (calendarReceiverInstance == null)
|
||||||
|
calendarReceiverInstance = new CalendarReceiver();
|
||||||
|
|
||||||
|
if (calendarIntentFilter == null)
|
||||||
|
{
|
||||||
|
calendarIntentFilter = new IntentFilter();
|
||||||
|
calendarIntentFilter.addAction(Intent.ACTION_PROVIDER_CHANGED);
|
||||||
|
}
|
||||||
|
|
||||||
|
calendarIntent = automationServiceRef.registerReceiver(calendarReceiverInstance, calendarIntentFilter);
|
||||||
|
|
||||||
|
calendarReceiverActive = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void stopScreenStateReceiver()
|
||||||
|
{
|
||||||
|
if (calendarReceiverActive)
|
||||||
|
{
|
||||||
|
if (calendarReceiverInstance != null)
|
||||||
|
{
|
||||||
|
automationServiceRef.unregisterReceiver(calendarReceiverInstance);
|
||||||
|
calendarReceiverInstance = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
calendarReceiverActive = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
@ -77,12 +77,12 @@
|
|||||||
android:layout_height="wrap_content">
|
android:layout_height="wrap_content">
|
||||||
|
|
||||||
<Spinner
|
<Spinner
|
||||||
android:id="@+id/spinnerTitleDirection"
|
android:id="@+id/spinnerCalendarTitleDirection"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content" />
|
android:layout_height="wrap_content" />
|
||||||
|
|
||||||
<EditText
|
<EditText
|
||||||
android:id="@+id/etNotificationTitle"
|
android:id="@+id/etCalendarTitle"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:ems="10" />
|
android:ems="10" />
|
||||||
@ -113,12 +113,12 @@
|
|||||||
android:layout_height="wrap_content">
|
android:layout_height="wrap_content">
|
||||||
|
|
||||||
<Spinner
|
<Spinner
|
||||||
android:id="@+id/spinnerTextDirection"
|
android:id="@+id/spinnerCalendarLocationDirection"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content" />
|
android:layout_height="wrap_content" />
|
||||||
|
|
||||||
<EditText
|
<EditText
|
||||||
android:id="@+id/etNotificationText"
|
android:id="@+id/etCalendarLocation"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:ems="10" />
|
android:ems="10" />
|
||||||
@ -149,12 +149,12 @@
|
|||||||
android:layout_height="wrap_content">
|
android:layout_height="wrap_content">
|
||||||
|
|
||||||
<Spinner
|
<Spinner
|
||||||
android:id="@+id/spinnerMarkedAsDirection"
|
android:id="@+id/spinnerCalendarDescriptionDirection"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content" />
|
android:layout_height="wrap_content" />
|
||||||
|
|
||||||
<Spinner
|
<EditText
|
||||||
android:id="@+id/spinnerMarkedAsOptions"
|
android:id="@+id/etCalendarDescription"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:ems="10" />
|
android:ems="10" />
|
||||||
@ -177,7 +177,7 @@
|
|||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_gravity="center_vertical"
|
android:layout_gravity="center_vertical"
|
||||||
android:text="@string/markedAs" />
|
android:text="@string/availability" />
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:orientation="vertical"
|
android:orientation="vertical"
|
||||||
@ -185,12 +185,12 @@
|
|||||||
android:layout_height="wrap_content">
|
android:layout_height="wrap_content">
|
||||||
|
|
||||||
<Spinner
|
<Spinner
|
||||||
android:id="@+id/spinnerTextDirection"
|
android:id="@+id/spinnerCalendarAvailabilityDirection"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content" />
|
android:layout_height="wrap_content" />
|
||||||
|
|
||||||
<EditText
|
<Spinner
|
||||||
android:id="@+id/etNotificationText"
|
android:id="@+id/spinnerCalendarAvailability"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:ems="10" />
|
android:ems="10" />
|
||||||
@ -202,7 +202,7 @@
|
|||||||
</TableLayout>
|
</TableLayout>
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
android:id="@+id/bSaveActionCloseNotification"
|
android:id="@+id/bSaveTriggerCalendar"
|
||||||
android:layout_marginTop="@dimen/default_margin"
|
android:layout_marginTop="@dimen/default_margin"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
@ -910,6 +910,11 @@
|
|||||||
<string name="calendarEventCapital">Calendar event</string>
|
<string name="calendarEventCapital">Calendar event</string>
|
||||||
<string name="location">Location</string>
|
<string name="location">Location</string>
|
||||||
<string name="calendarDescription">Description/notes</string>
|
<string name="calendarDescription">Description/notes</string>
|
||||||
<string name="markedAs">Marked as</string>
|
<string name="availability">Availability</string>
|
||||||
<string name="eventIsCurrentlyNotHappening">Event is currently not happening/has ended</string>
|
<string name="eventIsCurrentlyNotHappening">Event is currently not happening/has ended</string>
|
||||||
|
<string name="calendarStringBusy">busy</string>
|
||||||
|
<string name="calendarStringFree">free</string>
|
||||||
|
<string name="calendarStringTentative">tentative</string>
|
||||||
|
<string name="calendarStringOutOfOffice">out of office</string>
|
||||||
|
<string name="calendarStringWorkingElsewhere">working elsewhere</string>
|
||||||
</resources>
|
</resources>
|
Loading…
Reference in New Issue
Block a user