Class SyzygyApplication

java.lang.Object
android.content.Context
android.content.ContextWrapper
android.app.Application
com.syzygy.events.SyzygyApplication
All Implemented Interfaces:
android.content.ComponentCallbacks, android.content.ComponentCallbacks2, Consumer<RuntimeException>

public class SyzygyApplication extends android.app.Application implements Consumer<RuntimeException>
The main application class This class handles the navigation between the different activities This class manages the database and keeps track of which user is logged in Also contains helper functions for activities
  • Nested Class Summary

    Nested classes/interfaces inherited from class android.app.Application

    android.app.Application.ActivityLifecycleCallbacks, android.app.Application.OnProvideAssistDataListener

    Nested classes/interfaces inherited from class android.content.Context

    android.content.Context.BindServiceFlags
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private static final String
     
    private static final CharSequence
     
    The current activity displayed to the user
    private Database
    The database instance for this appp
    private String
    The id of the device
    private final List<Consumer<android.net.Uri>>
    Set of listeners that are waiting on receiving a user selected image
    private com.google.android.gms.location.FusedLocationProviderClient
    The client to get the location
    static final int
    The request code to use when requesting permissions for location
    private final List<Consumer<android.location.Location>>
    Set of listeners that are waiting on receiving the device's location
    (package private) android.graphics.drawable.Drawable
    The icon to use for the create facility menu option
    (package private) android.graphics.drawable.Drawable
    The icon to use for admin menu option
    static boolean
     
    The listener for notifications
    static final String
    The id of the User account associated with the Syzygy system
    private User
    The user logged into the device

    Fields inherited from class android.content.Context

    ACCESSIBILITY_SERVICE, ACCOUNT_SERVICE, ACTIVITY_SERVICE, ALARM_SERVICE, APP_OPS_SERVICE, APP_SEARCH_SERVICE, APPWIDGET_SERVICE, AUDIO_SERVICE, BATTERY_SERVICE, BIND_ABOVE_CLIENT, BIND_ADJUST_WITH_ACTIVITY, BIND_ALLOW_ACTIVITY_STARTS, BIND_ALLOW_OOM_MANAGEMENT, BIND_AUTO_CREATE, BIND_DEBUG_UNBIND, BIND_EXTERNAL_SERVICE, BIND_EXTERNAL_SERVICE_LONG, BIND_IMPORTANT, BIND_INCLUDE_CAPABILITIES, BIND_NOT_FOREGROUND, BIND_NOT_PERCEPTIBLE, BIND_SHARED_ISOLATED_PROCESS, BIND_WAIVE_PRIORITY, BIOMETRIC_SERVICE, BLOB_STORE_SERVICE, BLUETOOTH_SERVICE, BUGREPORT_SERVICE, CAMERA_SERVICE, CAPTIONING_SERVICE, CARRIER_CONFIG_SERVICE, CLIPBOARD_SERVICE, COMPANION_DEVICE_SERVICE, CONNECTIVITY_DIAGNOSTICS_SERVICE, CONNECTIVITY_SERVICE, CONSUMER_IR_SERVICE, CONTEXT_IGNORE_SECURITY, CONTEXT_INCLUDE_CODE, CONTEXT_RESTRICTED, CREDENTIAL_SERVICE, CROSS_PROFILE_APPS_SERVICE, DEVICE_ID_DEFAULT, DEVICE_ID_INVALID, DEVICE_LOCK_SERVICE, DEVICE_POLICY_SERVICE, DISPLAY_HASH_SERVICE, DISPLAY_SERVICE, DOMAIN_VERIFICATION_SERVICE, DOWNLOAD_SERVICE, DROPBOX_SERVICE, EUICC_SERVICE, FILE_INTEGRITY_SERVICE, FINGERPRINT_SERVICE, GAME_SERVICE, GRAMMATICAL_INFLECTION_SERVICE, HARDWARE_PROPERTIES_SERVICE, HEALTHCONNECT_SERVICE, INPUT_METHOD_SERVICE, INPUT_SERVICE, IPSEC_SERVICE, JOB_SCHEDULER_SERVICE, KEYGUARD_SERVICE, LAUNCHER_APPS_SERVICE, LAYOUT_INFLATER_SERVICE, LOCALE_SERVICE, LOCATION_SERVICE, MEDIA_COMMUNICATION_SERVICE, MEDIA_METRICS_SERVICE, MEDIA_PROJECTION_SERVICE, MEDIA_ROUTER_SERVICE, MEDIA_SESSION_SERVICE, MIDI_SERVICE, MODE_APPEND, MODE_ENABLE_WRITE_AHEAD_LOGGING, MODE_MULTI_PROCESS, MODE_NO_LOCALIZED_COLLATORS, MODE_PRIVATE, MODE_WORLD_READABLE, MODE_WORLD_WRITEABLE, NETWORK_STATS_SERVICE, NFC_SERVICE, NOTIFICATION_SERVICE, NSD_SERVICE, OVERLAY_SERVICE, PEOPLE_SERVICE, PERFORMANCE_HINT_SERVICE, POWER_SERVICE, PRINT_SERVICE, RECEIVER_EXPORTED, RECEIVER_NOT_EXPORTED, RECEIVER_VISIBLE_TO_INSTANT_APPS, RESTRICTIONS_SERVICE, ROLE_SERVICE, SEARCH_SERVICE, SENSOR_SERVICE, SHORTCUT_SERVICE, STATUS_BAR_SERVICE, STORAGE_SERVICE, STORAGE_STATS_SERVICE, SYSTEM_HEALTH_SERVICE, TELECOM_SERVICE, TELEPHONY_IMS_SERVICE, TELEPHONY_SERVICE, TELEPHONY_SUBSCRIPTION_SERVICE, TEXT_CLASSIFICATION_SERVICE, TEXT_SERVICES_MANAGER_SERVICE, TV_INPUT_SERVICE, TV_INTERACTIVE_APP_SERVICE, UI_MODE_SERVICE, USAGE_STATS_SERVICE, USB_SERVICE, USER_SERVICE, VIBRATOR_MANAGER_SERVICE, VIBRATOR_SERVICE, VIRTUAL_DEVICE_SERVICE, VPN_MANAGEMENT_SERVICE, WALLPAPER_SERVICE, WIFI_AWARE_SERVICE, WIFI_P2P_SERVICE, WIFI_RTT_RANGING_SERVICE, WIFI_SERVICE, WINDOW_SERVICE

    Fields inherited from interface android.content.ComponentCallbacks2

    TRIM_MEMORY_BACKGROUND, TRIM_MEMORY_COMPLETE, TRIM_MEMORY_MODERATE, TRIM_MEMORY_RUNNING_CRITICAL, TRIM_MEMORY_RUNNING_LOW, TRIM_MEMORY_RUNNING_MODERATE, TRIM_MEMORY_UI_HIDDEN
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Called on errors in the database
    private boolean
     
    void
    Sets the user to null
    void
    Displays the associated image of the instance to the user as a popup
    formatTimestamp(com.google.firebase.Timestamp t)
    Formats a timestamp
    Gets the database
    void
    getImage(Consumer<android.net.Uri> imageListener)
    Gets an image from the user
    void
    getLocation(Consumer<android.location.Location> locationListener)
    Gets the location
     
    void
    loadMenuIcon(android.view.Menu menu)
    Loads the icon for the account menu
    void
    loadMenuItemIcons(android.view.Menu menu)
    Loads the icons for the account menu options
    void
     
    void
     
    (package private) void
    pingLocation(boolean granted)
    Called when users grants/declines location permission.
    (package private) void
    Called on create of activities to register that this activity is the current activity.
    private void
    Gets the current location and actions all location listeners.
    (package private) void
    sendImage(android.net.Uri image)
    Called when the user selects an image.
    void
    Sends a notification to the user
    private void
    Sets the user using this device and registers a notification listener
    signupUser(String name, String email, String phone, String bio, Boolean admin, Boolean org, android.net.Uri image, Consumer<Boolean> onComplete)
    To be called by the Signup activity upon submission
    void
    switchToActivity(Class<? extends android.app.Activity> to)
    Opens the new activity and closes the old activity

    Methods inherited from class android.app.Application

    getProcessName, onConfigurationChanged, onLowMemory, onTrimMemory, registerActivityLifecycleCallbacks, registerComponentCallbacks, registerOnProvideAssistDataListener, unregisterActivityLifecycleCallbacks, unregisterComponentCallbacks, unregisterOnProvideAssistDataListener

    Methods inherited from class android.content.ContextWrapper

    attachBaseContext, bindIsolatedService, bindService, bindService, bindService, bindService, bindServiceAsUser, bindServiceAsUser, checkCallingOrSelfPermission, checkCallingOrSelfUriPermission, checkCallingOrSelfUriPermissions, checkCallingPermission, checkCallingUriPermission, checkCallingUriPermissions, checkPermission, checkSelfPermission, checkUriPermission, checkUriPermission, checkUriPermissions, clearWallpaper, createAttributionContext, createConfigurationContext, createContext, createContextForSplit, createDeviceContext, createDeviceProtectedStorageContext, createDisplayContext, createPackageContext, createWindowContext, createWindowContext, databaseList, deleteDatabase, deleteFile, deleteSharedPreferences, enforceCallingOrSelfPermission, enforceCallingOrSelfUriPermission, enforceCallingPermission, enforceCallingUriPermission, enforcePermission, enforceUriPermission, enforceUriPermission, fileList, getApplicationContext, getApplicationInfo, getAssets, getAttributionSource, getAttributionTag, getBaseContext, getCacheDir, getClassLoader, getCodeCacheDir, getContentResolver, getDatabasePath, getDataDir, getDeviceId, getDir, getDisplay, getExternalCacheDir, getExternalCacheDirs, getExternalFilesDir, getExternalFilesDirs, getExternalMediaDirs, getFilesDir, getFileStreamPath, getMainExecutor, getMainLooper, getNoBackupFilesDir, getObbDir, getObbDirs, getOpPackageName, getPackageCodePath, getPackageManager, getPackageName, getPackageResourcePath, getParams, getResources, getSharedPreferences, getSystemService, getSystemServiceName, getTheme, getWallpaper, getWallpaperDesiredMinimumHeight, getWallpaperDesiredMinimumWidth, grantUriPermission, isDeviceProtectedStorage, isRestricted, isUiContext, moveDatabaseFrom, moveSharedPreferencesFrom, openFileInput, openFileOutput, openOrCreateDatabase, openOrCreateDatabase, peekWallpaper, registerDeviceIdChangeListener, registerReceiver, registerReceiver, registerReceiver, registerReceiver, removeStickyBroadcast, removeStickyBroadcastAsUser, revokeSelfPermissionsOnKill, revokeUriPermission, revokeUriPermission, sendBroadcast, sendBroadcast, sendBroadcast, sendBroadcastAsUser, sendBroadcastAsUser, sendOrderedBroadcast, sendOrderedBroadcast, sendOrderedBroadcast, sendOrderedBroadcast, sendOrderedBroadcast, sendOrderedBroadcast, sendOrderedBroadcastAsUser, sendStickyBroadcast, sendStickyBroadcast, sendStickyBroadcastAsUser, sendStickyOrderedBroadcast, sendStickyOrderedBroadcastAsUser, setTheme, setWallpaper, setWallpaper, startActivities, startActivities, startActivity, startActivity, startForegroundService, startInstrumentation, startIntentSender, startIntentSender, startService, stopService, unbindService, unregisterDeviceIdChangeListener, unregisterReceiver, updateServiceGroup

    Methods inherited from class android.content.Context

    bindIsolatedService, getColor, getColorStateList, getDrawable, getString, getString, getSystemService, getText, obtainStyledAttributes, obtainStyledAttributes, obtainStyledAttributes, obtainStyledAttributes, revokeSelfPermissionOnKill, sendBroadcastWithMultiplePermissions

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface java.util.function.Consumer

    andThen
  • Field Details

    • NO_DATABASE

      public static boolean NO_DATABASE
    • SYSTEM_ACCOUNT_ID

      public static final String SYSTEM_ACCOUNT_ID
      The id of the User account associated with the Syzygy system
      See Also:
    • LOCATION_REQUEST_CODE

      public static final int LOCATION_REQUEST_CODE
      The request code to use when requesting permissions for location
      See Also:
    • db

      private Database db
      The database instance for this appp
    • user

      private User user
      The user logged into the device
    • notificationListener

      private User.NotificationListener notificationListener
      The listener for notifications
    • deviceID

      private String deviceID
      The id of the device
    • currentActivity

      private SyzygyActivity currentActivity
      The current activity displayed to the user
    • location

      private com.google.android.gms.location.FusedLocationProviderClient location
      The client to get the location
    • locationListeners

      private final List<Consumer<android.location.Location>> locationListeners
      Set of listeners that are waiting on receiving the device's location
    • imageListeners

      private final List<Consumer<android.net.Uri>> imageListeners
      Set of listeners that are waiting on receiving a user selected image
    • CHANNEL_ID

      private static final String CHANNEL_ID
      See Also:
    • CHANNEL_NAME

      private static final CharSequence CHANNEL_NAME
  • Constructor Details

    • SyzygyApplication

      public SyzygyApplication()
  • Method Details

    • onCreate

      public void onCreate()
      Overrides:
      onCreate in class android.app.Application
    • setUser

      private void setUser(@Stirs User u)
      Sets the user using this device and registers a notification listener
    • loadMenuIcon

      public void loadMenuIcon(android.view.Menu menu)
      Loads the icon for the account menu
      Parameters:
      menu - The menu
    • loadMenuItemIcons

      public void loadMenuItemIcons(android.view.Menu menu)
      Loads the icons for the account menu options
      Parameters:
      menu - The menu
    • onTerminate

      public void onTerminate()
      Overrides:
      onTerminate in class android.app.Application
    • registerActivity

      void registerActivity(SyzygyActivity activity)
      Called on create of activities to register that this activity is the current activity. Switches the update listener over to the new activity
      Parameters:
      activity - The now current activity
    • getUser

      @Observes public User getUser()
      Returns:
      The user currently using this app
    • clearUser

      public void clearUser()
      Sets the user to null
    • getDatabase

      public Database getDatabase()
      Gets the database
      Returns:
      the database
    • canGetLocation

      private boolean canGetLocation()
      Returns:
      If permission has been granted to get location
    • retrieveLocation

      private void retrieveLocation()
      Gets the current location and actions all location listeners. Location listeners are passed null if permissions are not granted or the location fails. Clears the listeners list after actioning.
    • pingLocation

      void pingLocation(boolean granted)
      Called when users grants/declines location permission. Actions all waiting location listeners. Passes null if permissions are not granted or the location fails. Clears the listeners list after retrieval.
      Parameters:
      granted - If permission was granted
    • sendImage

      void sendImage(android.net.Uri image)
      Called when the user selects an image. Sends the image to all current listeners
      Parameters:
      image - The image
    • getLocation

      public void getLocation(Consumer<android.location.Location> locationListener)
      Gets the location

      Checks if location permissions are granted. If not, asks for permission. Then actions the listener with null if permissions are still not granted or an error occurs. Otherwise passes the location

      Parameters:
      locationListener - The listener. Called when the location has been retrieved
    • getImage

      public void getImage(Consumer<android.net.Uri> imageListener)
      Gets an image from the user

      Checks if file search permissions are granted. If not, asks for permission. Then actions the listener with null if permissions are still not granted or an error occurs. Otherwise passes the image

      Parameters:
      imageListener - The listener. Called when the image has been retrieved
    • displayImage

      public void displayImage(DatabaseInstance<?> instance)
      Displays the associated image of the instance to the user as a popup
      Parameters:
      instance - The instance whose image should be displayed
    • signupUser

      public Set<Integer> signupUser(String name, String email, String phone, String bio, Boolean admin, Boolean org, android.net.Uri image, Consumer<Boolean> onComplete)
      To be called by the Signup activity upon submission
      Returns:
      all invalid properties
    • switchToActivity

      public void switchToActivity(Class<? extends android.app.Activity> to)
      Opens the new activity and closes the old activity
      Parameters:
      to - The new activity
    • formatTimestamp

      public String formatTimestamp(com.google.firebase.Timestamp t)
      Formats a timestamp
      Parameters:
      t - the time
      Returns:
      The timestamp as "dd/MM/yyyy"
    • accept

      public void accept(RuntimeException e)
      Called on errors in the database
      Specified by:
      accept in interface Consumer<RuntimeException>
    • sendNotification

      public void sendNotification(Notification n)
      Sends a notification to the user
      Parameters:
      n - The notification