public class MainActivity
extends android.support.v7.app.AppCompatActivity
This class is the launcher activity of the app which handles
various permissions of the app. One of the main function of this activity is to manage the
lifecycle of two important fragments:
SettingsPreferenceFragment
,
VideosListFragment
,
RecorderService
Modifier and Type | Class and Description |
---|---|
static interface |
MainActivity.AnalyticsSettingsListerner |
(package private) class |
MainActivity.ViewPagerAdapter
ViewPagerAdapter class to handle fragment tabs
|
Modifier and Type | Field and Description |
---|---|
private MainActivity.AnalyticsSettingsListerner |
analyticsSettingsListerner
Interface to listen to settings changes pertaining to analytics.
|
private android.support.design.widget.FloatingActionButton |
fab
FloatingActionButton view which handles the record start/stop action |
private android.media.projection.MediaProjection |
mMediaProjection
MediaProjection token to hold screen capture permission grant
|
private PermissionResultListener |
mPermissionResultListener
Permission listener interface to listen to permission results obtained from
SettingsPreferenceFragment
|
private android.media.projection.MediaProjectionManager |
mProjectionManager
Instance of
MediaProjectionManager system service |
private android.content.SharedPreferences |
prefs
Object of
SharedPreferences to read the app's settings. |
private android.support.v4.view.ViewPager |
viewPager
ViewPager to handle swiping (left/right) of SettingsPreferenceFragment
and VideosListFragment fragments |
DEFAULT_KEYS_DIALER, DEFAULT_KEYS_DISABLE, DEFAULT_KEYS_SEARCH_GLOBAL, DEFAULT_KEYS_SEARCH_LOCAL, DEFAULT_KEYS_SHORTCUT, FOCUSED_STATE_SET, RESULT_CANCELED, RESULT_FIRST_USER, RESULT_OK
ACCESSIBILITY_SERVICE, ACCOUNT_SERVICE, ACTIVITY_SERVICE, ALARM_SERVICE, APP_OPS_SERVICE, APPWIDGET_SERVICE, AUDIO_SERVICE, BATTERY_SERVICE, BIND_ABOVE_CLIENT, BIND_ADJUST_WITH_ACTIVITY, BIND_ALLOW_OOM_MANAGEMENT, BIND_AUTO_CREATE, BIND_DEBUG_UNBIND, BIND_EXTERNAL_SERVICE, BIND_IMPORTANT, BIND_NOT_FOREGROUND, BIND_WAIVE_PRIORITY, BLUETOOTH_SERVICE, CAMERA_SERVICE, CAPTIONING_SERVICE, CARRIER_CONFIG_SERVICE, CLIPBOARD_SERVICE, COMPANION_DEVICE_SERVICE, CONNECTIVITY_SERVICE, CONSUMER_IR_SERVICE, CONTEXT_IGNORE_SECURITY, CONTEXT_INCLUDE_CODE, CONTEXT_RESTRICTED, DEVICE_POLICY_SERVICE, DISPLAY_SERVICE, DOWNLOAD_SERVICE, DROPBOX_SERVICE, FINGERPRINT_SERVICE, HARDWARE_PROPERTIES_SERVICE, INPUT_METHOD_SERVICE, INPUT_SERVICE, JOB_SCHEDULER_SERVICE, KEYGUARD_SERVICE, LAUNCHER_APPS_SERVICE, LAYOUT_INFLATER_SERVICE, LOCATION_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, POWER_SERVICE, PRINT_SERVICE, RECEIVER_VISIBLE_TO_INSTANT_APPS, RESTRICTIONS_SERVICE, SEARCH_SERVICE, SENSOR_SERVICE, SHORTCUT_SERVICE, STORAGE_SERVICE, STORAGE_STATS_SERVICE, SYSTEM_HEALTH_SERVICE, TELECOM_SERVICE, TELEPHONY_SERVICE, TELEPHONY_SUBSCRIPTION_SERVICE, TEXT_CLASSIFICATION_SERVICE, TEXT_SERVICES_MANAGER_SERVICE, TV_INPUT_SERVICE, UI_MODE_SERVICE, USAGE_STATS_SERVICE, USB_SERVICE, USER_SERVICE, VIBRATOR_SERVICE, WALLPAPER_SERVICE, WIFI_AWARE_SERVICE, WIFI_P2P_SERVICE, WIFI_SERVICE, WINDOW_SERVICE
Constructor and Description |
---|
MainActivity() |
Modifier and Type | Method and Description |
---|---|
static void |
createDir()
Static method to create the app's default directory in the external storage
|
private boolean |
isServiceRunning(java.lang.Class<?> serviceClass)
Method to check if the
RecorderService is running |
protected void |
onActivityResult(int requestCode,
int resultCode,
android.content.Intent data)
onActivityResult method to handle the activity results for floating controls
and screen recording permission
|
protected void |
onCreate(android.os.Bundle savedInstanceState)
This method handles themes, populates the UI views and click listeners.
|
boolean |
onCreateOptionsMenu(android.view.Menu menu) |
void |
onDirectoryChanged()
Method to remove and recreate the
VideosListFragment when the save location changes |
boolean |
onOptionsItemSelected(android.view.MenuItem item) |
void |
onRequestPermissionsResult(int requestCode,
java.lang.String[] permissions,
int[] grantResults)
Overrided onRequestPermissionsResult from
PermissionResultListener |
protected void |
onStart() |
protected void |
onStop() |
private void |
requestAnalyticsPermission()
Method to create a dialog to request for analytics permission.
|
void |
requestPermissionAudio()
Method to request audio permission
|
boolean |
requestPermissionStorage()
Method to request permission for writing to external storage
|
void |
requestSystemWindowsPermission()
Method to request system windows permission.
|
void |
setAnalyticsSettingsListerner(MainActivity.AnalyticsSettingsListerner analyticsSettingsListerner)
Method to set
MainActivity.AnalyticsSettingsListerner |
void |
setPermissionResultListener(PermissionResultListener mPermissionResultListener)
Method to set
PermissionResultListener |
private void |
setSystemWindowsPermissionResult()
Sets system overlay permission if permission granted.
|
void |
setupAnalytics()
Method to initialize the countly analytics sdk.
The sdk is initialized either to only report app crashes or to report usage analytics based on the settings chosen by the user which is saved to the shared preference |
private void |
setupViewPager(android.support.v4.view.ViewPager viewPager)
Method to add the fragments:
SettingsPreferenceFragment and VideosListFragment
to the viewpager and add ViewPager.addOnPageChangeListener(ViewPager.OnPageChangeListener)
to hide fab on VideosListFragment |
addContentView, closeOptionsMenu, dispatchKeyEvent, findViewById, getDelegate, getDrawerToggleDelegate, getMenuInflater, getResources, getSupportActionBar, getSupportParentActivityIntent, invalidateOptionsMenu, onConfigurationChanged, onContentChanged, onCreateSupportNavigateUpTaskStack, onDestroy, onKeyDown, onMenuItemSelected, onMenuOpened, onPanelClosed, onPostCreate, onPostResume, onPrepareSupportNavigateUpTaskStack, onSaveInstanceState, onSupportActionModeFinished, onSupportActionModeStarted, onSupportContentChanged, onSupportNavigateUp, onTitleChanged, onWindowStartingSupportActionMode, openOptionsMenu, setContentView, setContentView, setContentView, setSupportActionBar, setSupportProgress, setSupportProgressBarIndeterminate, setSupportProgressBarIndeterminateVisibility, setSupportProgressBarVisibility, setTheme, startSupportActionMode, supportInvalidateOptionsMenu, supportNavigateUpTo, supportRequestWindowFeature, supportShouldUpRecreateTask
dump, getLastCustomNonConfigurationInstance, getLifecycle, getSupportFragmentManager, getSupportLoaderManager, onAttachFragment, onBackPressed, onCreatePanelMenu, onLowMemory, onMultiWindowModeChanged, onNewIntent, onPause, onPictureInPictureModeChanged, onPrepareOptionsPanel, onPreparePanel, onResume, onResumeFragments, onRetainCustomNonConfigurationInstance, onRetainNonConfigurationInstance, onStateNotSaved, setEnterSharedElementCallback, setExitSharedElementCallback, startActivityForResult, startActivityFromFragment, startActivityFromFragment, startIntentSenderFromFragment, supportFinishAfterTransition, supportPostponeEnterTransition, supportStartPostponedEnterTransition, validateRequestPermissionsRequestCode
attachBaseContext, closeContextMenu, createPendingResult, dismissDialog, dismissKeyboardShortcutsHelper, dispatchGenericMotionEvent, dispatchKeyShortcutEvent, dispatchPopulateAccessibilityEvent, dispatchTouchEvent, dispatchTrackballEvent, enterPictureInPictureMode, enterPictureInPictureMode, finish, finishActivity, finishActivityFromChild, finishAffinity, finishAfterTransition, finishAndRemoveTask, finishFromChild, getActionBar, getApplication, getCallingActivity, getCallingPackage, getChangingConfigurations, getComponentName, getContentScene, getContentTransitionManager, getCurrentFocus, getFragmentManager, getIntent, getLastNonConfigurationInstance, getLayoutInflater, getLoaderManager, getLocalClassName, getMaxNumPictureInPictureActions, getMediaController, getParent, getParentActivityIntent, getPreferences, getReferrer, getRequestedOrientation, getSearchEvent, getSystemService, getTaskId, getTitle, getTitleColor, getVoiceInteractor, getVolumeControlStream, getWindow, getWindowManager, hasWindowFocus, isActivityTransitionRunning, isChangingConfigurations, isChild, isDestroyed, isFinishing, isImmersive, isInMultiWindowMode, isInPictureInPictureMode, isLocalVoiceInteractionSupported, isTaskRoot, isVoiceInteraction, isVoiceInteractionRoot, managedQuery, moveTaskToBack, navigateUpTo, navigateUpToFromChild, onActionModeFinished, onActionModeStarted, onActivityReenter, onApplyThemeResource, onAttachedToWindow, onAttachFragment, onChildTitleChanged, onContextItemSelected, onContextMenuClosed, onCreate, onCreateContextMenu, onCreateDescription, onCreateDialog, onCreateDialog, onCreateNavigateUpTaskStack, onCreatePanelView, onCreateThumbnail, onDetachedFromWindow, onEnterAnimationComplete, onGenericMotionEvent, onKeyLongPress, onKeyMultiple, onKeyShortcut, onKeyUp, onLocalVoiceInteractionStarted, onLocalVoiceInteractionStopped, onMultiWindowModeChanged, onNavigateUp, onNavigateUpFromChild, onOptionsMenuClosed, onPictureInPictureModeChanged, onPostCreate, onPrepareDialog, onPrepareDialog, onPrepareNavigateUpTaskStack, onPrepareOptionsMenu, onProvideAssistContent, onProvideAssistData, onProvideKeyboardShortcuts, onProvideReferrer, onRestart, onRestoreInstanceState, onRestoreInstanceState, onSaveInstanceState, onSearchRequested, onSearchRequested, onTouchEvent, onTrackballEvent, onTrimMemory, onUserInteraction, onUserLeaveHint, onVisibleBehindCanceled, onWindowAttributesChanged, onWindowFocusChanged, onWindowStartingActionMode, onWindowStartingActionMode, openContextMenu, overridePendingTransition, postponeEnterTransition, recreate, registerForContextMenu, releaseInstance, removeDialog, reportFullyDrawn, requestDragAndDropPermissions, requestPermissions, requestShowKeyboardShortcuts, requestVisibleBehind, requestWindowFeature, runOnUiThread, setActionBar, setContentTransitionManager, setDefaultKeyMode, setEnterSharedElementCallback, setExitSharedElementCallback, setFeatureDrawable, setFeatureDrawableAlpha, setFeatureDrawableResource, setFeatureDrawableUri, setFinishOnTouchOutside, setImmersive, setIntent, setMediaController, setPictureInPictureParams, setProgress, setProgressBarIndeterminate, setProgressBarIndeterminateVisibility, setProgressBarVisibility, setRequestedOrientation, setResult, setResult, setSecondaryProgress, setShowWhenLocked, setTaskDescription, setTitle, setTitle, setTitleColor, setTurnScreenOn, setVisible, setVolumeControlStream, setVrModeEnabled, shouldShowRequestPermissionRationale, shouldUpRecreateTask, showAssist, showDialog, showDialog, showLockTaskEscapeMessage, startActionMode, startActionMode, startActivities, startActivities, startActivity, startActivity, startActivityFromChild, startActivityFromChild, startActivityFromFragment, startActivityFromFragment, startActivityIfNeeded, startActivityIfNeeded, startIntentSender, startIntentSender, startIntentSenderFromChild, startIntentSenderFromChild, startLocalVoiceInteraction, startLockTask, startManagingCursor, startNextMatchingActivity, startNextMatchingActivity, startPostponedEnterTransition, startSearch, stopLocalVoiceInteraction, stopLockTask, stopManagingCursor, takeKeyEvents, triggerSearch, unregisterForContextMenu
applyOverrideConfiguration, getAssets, getTheme
bindService, checkCallingOrSelfPermission, checkCallingOrSelfUriPermission, checkCallingPermission, checkCallingUriPermission, checkPermission, checkSelfPermission, checkUriPermission, checkUriPermission, clearWallpaper, createConfigurationContext, createContextForSplit, createDeviceProtectedStorageContext, createDisplayContext, createPackageContext, databaseList, deleteDatabase, deleteFile, deleteSharedPreferences, enforceCallingOrSelfPermission, enforceCallingOrSelfUriPermission, enforceCallingPermission, enforceCallingUriPermission, enforcePermission, enforceUriPermission, enforceUriPermission, fileList, getApplicationContext, getApplicationInfo, getBaseContext, getCacheDir, getClassLoader, getCodeCacheDir, getContentResolver, getDatabasePath, getDataDir, getDir, getExternalCacheDir, getExternalCacheDirs, getExternalFilesDir, getExternalFilesDirs, getExternalMediaDirs, getFilesDir, getFileStreamPath, getMainLooper, getNoBackupFilesDir, getObbDir, getObbDirs, getPackageCodePath, getPackageManager, getPackageName, getPackageResourcePath, getSharedPreferences, getSystemServiceName, getWallpaper, getWallpaperDesiredMinimumHeight, getWallpaperDesiredMinimumWidth, grantUriPermission, isDeviceProtectedStorage, isRestricted, moveDatabaseFrom, moveSharedPreferencesFrom, openFileInput, openFileOutput, openOrCreateDatabase, openOrCreateDatabase, peekWallpaper, registerReceiver, registerReceiver, registerReceiver, registerReceiver, removeStickyBroadcast, removeStickyBroadcastAsUser, revokeUriPermission, revokeUriPermission, sendBroadcast, sendBroadcast, sendBroadcastAsUser, sendBroadcastAsUser, sendOrderedBroadcast, sendOrderedBroadcast, sendOrderedBroadcastAsUser, sendStickyBroadcast, sendStickyBroadcastAsUser, sendStickyOrderedBroadcast, sendStickyOrderedBroadcastAsUser, setWallpaper, setWallpaper, startForegroundService, startInstrumentation, startService, stopService, unbindService, unregisterReceiver
getColor, getColorStateList, getDrawable, getString, getString, getSystemService, getText, obtainStyledAttributes, obtainStyledAttributes, obtainStyledAttributes, obtainStyledAttributes, registerComponentCallbacks, unregisterComponentCallbacks
private PermissionResultListener mPermissionResultListener
PermissionResultListener
private MainActivity.AnalyticsSettingsListerner analyticsSettingsListerner
MainActivity.AnalyticsSettingsListerner
private android.media.projection.MediaProjection mMediaProjection
private android.media.projection.MediaProjectionManager mProjectionManager
MediaProjectionManager
system serviceprivate android.support.design.widget.FloatingActionButton fab
FloatingActionButton
view which handles the record start/stop actionprivate android.support.v4.view.ViewPager viewPager
ViewPager
to handle swiping (left/right) of SettingsPreferenceFragment
and VideosListFragment
fragmentsprivate android.content.SharedPreferences prefs
SharedPreferences
to read the app's settings.SettingsPreferenceFragment
public static void createDir()
protected void onCreate(android.os.Bundle savedInstanceState)
onCreate
in class android.support.v7.app.AppCompatActivity
savedInstanceState
- default savedInstance bundle sent by Android runtimepublic void setupAnalytics()
private void setupViewPager(android.support.v4.view.ViewPager viewPager)
SettingsPreferenceFragment
and VideosListFragment
to the viewpager and add ViewPager.addOnPageChangeListener(ViewPager.OnPageChangeListener)
to hide fab
on VideosListFragment
viewPager
- viewpager instance from the layoutprivate boolean isServiceRunning(java.lang.Class<?> serviceClass)
RecorderService
is runningserviceClass
- Collection containing the RecorderService
classRecorderService
is runningjava.lang.NullPointerException
- May throw NullPointerExceptionprotected void onActivityResult(int requestCode, int resultCode, android.content.Intent data)
onActivityResult
in class android.support.v4.app.FragmentActivity
requestCode
- Unique request code for different startActivityForResult callsresultCode
- result code representing the user's choicedata
- Extra intent data passed from calling intentpublic void onDirectoryChanged()
VideosListFragment
when the save location changespublic boolean requestPermissionStorage()
public void requestSystemWindowsPermission()
private void setSystemWindowsPermissionResult()
public void requestPermissionAudio()
public void onRequestPermissionsResult(int requestCode, @NonNull java.lang.String[] permissions, @NonNull int[] grantResults)
PermissionResultListener
onRequestPermissionsResult
in interface android.support.v4.app.ActivityCompat.OnRequestPermissionsResultCallback
onRequestPermissionsResult
in class android.support.v4.app.FragmentActivity
requestCode
- permissions
- grantResults
- PermissionResultListener
private void requestAnalyticsPermission()
public void setPermissionResultListener(PermissionResultListener mPermissionResultListener)
PermissionResultListener
mPermissionResultListener
- PermissionResultListener
objectpublic void setAnalyticsSettingsListerner(MainActivity.AnalyticsSettingsListerner analyticsSettingsListerner)
MainActivity.AnalyticsSettingsListerner
analyticsSettingsListerner
- MainActivity.AnalyticsSettingsListerner
objectprotected void onStart()
onStart
in class android.support.v7.app.AppCompatActivity
protected void onStop()
onStop
in class android.support.v7.app.AppCompatActivity
public boolean onCreateOptionsMenu(android.view.Menu menu)
onCreateOptionsMenu
in class android.app.Activity
public boolean onOptionsItemSelected(android.view.MenuItem item)
onOptionsItemSelected
in class android.app.Activity