List of usage examples for android.app Activity getApplicationContext
@Override
public Context getApplicationContext()
From source file:sysnetlab.android.sdc.ui.fragments.ExperimentSensorListFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.fragment_experiment_sensor_list, container, false); ListView listView = (ListView) view.findViewById(R.id.listview_experiment_view_sensor_list); TextView textView = (TextView) view.findViewById(R.id.textview_experiment_view_no_sensors); Activity activity = getActivity(); List<AbstractSensor> lstSensors = null; List<AbstractSensor> selectedSensors = new ArrayList<AbstractSensor>(); if (activity instanceof ViewExperimentActivity) { lstSensors = (ArrayList<AbstractSensor>) ExperimentManagerSingleton.getInstance().getActiveExperiment() .getSensors();/*w ww .j a va 2 s .co m*/ Log.d("SensorDataCollector", "ViewExperimentActivity::ExperimentSensorListFragment::onCreateView() sensors: " + lstSensors.size()); } else if (activity instanceof CreateExperimentActivity) { if (!SensorDiscoverer.isInitialized()) SensorDiscoverer.initialize(activity.getApplicationContext()); lstSensors = SensorDiscoverer.discoverSensorList(); ((CreateExperimentActivity) activity).selectSensors(lstSensors); for (Iterator<AbstractSensor> it = lstSensors.iterator(); it.hasNext();) { AbstractSensor sensor = it.next(); if (sensor.isSelected()) { selectedSensors.add(sensor); } } Log.d("SensorDataCollector", "CreateExperimentActivity::ExperimentSensorListFragment::onCreateView() sensors: " + selectedSensors.size()); } else { Log.d("SensorDataCollector", "ExperimentSensorListFragment::onCreateView(): " + "not a CreateExperimentActivity."); } if (selectedSensors == null || selectedSensors.size() == 0) { Log.d("SensorDataCollector", "CreateExperimentActivity::ExperimentSensorListFragment::onCreateView() nothing to show"); textView.setVisibility(View.GONE); listView.setVisibility(View.GONE); } else { Log.d("SensorDataCollector", "CreateExperimentActivity::ExperimentSensorListFragment::onCreateView() show sensors"); textView.setVisibility(View.GONE); SensorListAdapter sensorListAdaptor = new SensorListAdapter(activity, selectedSensors, View.GONE); listView.setAdapter(sensorListAdaptor); listView.setVisibility(View.VISIBLE); } mListView = listView; return view; }
From source file:org.artoolkit.ar.samples.nftBook.CameraSurface.java
@SuppressWarnings("deprecation") public CameraSurface(Context context) { super(context); Log.i(TAG, "CameraSurface(): ctor called"); Activity activityRef = (Activity) context; try {/*from www . j a v a 2 s . c o m*/ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { if (PackageManager.PERMISSION_GRANTED != ContextCompat.checkSelfPermission(activityRef, Manifest.permission.CAMERA)) { mustAskPermissionFirst = true; if (activityRef.shouldShowRequestPermissionRationale(Manifest.permission.CAMERA)) { // Will drop in here if user denied permissions access camera before. // Or no uses-permission CAMERA element is in the // manifest file. Must explain to the end user why the app wants // permissions to the camera devices. Toast.makeText(activityRef.getApplicationContext(), "App requires access to camera to be granted", Toast.LENGTH_SHORT).show(); } // Request permission from the user to access the camera. Log.i(TAG, "CameraSurface(): must ask user for camera access permission"); activityRef.requestPermissions(new String[] { Manifest.permission.CAMERA }, nftBookActivity.REQUEST_CAMERA_PERMISSION_RESULT); return; } } } catch (Exception ex) { Log.e(TAG, "CameraSurface(): exception caught, " + ex.getMessage()); return; } SurfaceHolder holder = getHolder(); holder.addCallback(this); holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); // Deprecated in API level 11. Still required for API levels <= 10. }
From source file:org.artoolkit.ar.samples.ARNativeES1.CameraSurface.java
@SuppressWarnings("deprecation") public CameraSurface(Context context) { super(context); Log.i(TAG, "CameraSurface(): ctor called"); Activity activityRef = (Activity) context; try {//from www. j ava 2 s.c o m if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { if (PackageManager.PERMISSION_GRANTED != ContextCompat.checkSelfPermission(activityRef, Manifest.permission.CAMERA)) { mustAskPermissionFirst = true; if (activityRef.shouldShowRequestPermissionRationale(Manifest.permission.CAMERA)) { // Will drop in here if user denied permissions access camera before. // Or no uses-permission CAMERA element is in the // manifest file. Must explain to the end user why the app wants // permissions to the camera devices. Toast.makeText(activityRef.getApplicationContext(), "App requires access to camera to be granted", Toast.LENGTH_SHORT).show(); } // Request permission from the user to access the camera. Log.i(TAG, "CameraSurface(): must ask user for camera access permission"); activityRef.requestPermissions(new String[] { Manifest.permission.CAMERA }, ARNativeES1Activity.REQUEST_CAMERA_PERMISSION_RESULT); return; } } } catch (Exception ex) { Log.e(TAG, "CameraSurface(): exception caught, " + ex.getMessage()); return; } SurfaceHolder holder = getHolder(); holder.addCallback(this); holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); // Deprecated in API level 11. Still required for API levels <= 10. }
From source file:org.artoolkit.ar.samples.ARNativeOSG.CameraSurface.java
@SuppressWarnings("deprecation") public CameraSurface(Context context) { super(context); Log.i(TAG, "CameraSurface(): ctor called"); Activity activityRef = (Activity) context; try {/*from ww w . j a va 2s . com*/ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { if (PackageManager.PERMISSION_GRANTED != ContextCompat.checkSelfPermission(activityRef, Manifest.permission.CAMERA)) { mustAskPermissionFirst = true; if (activityRef.shouldShowRequestPermissionRationale(Manifest.permission.CAMERA)) { // Will drop in here if user denied permissions access camera before. // Or no uses-permission CAMERA element is in the // manifest file. Must explain to the end user why the app wants // permissions to the camera devices. Toast.makeText(activityRef.getApplicationContext(), "App requires access to camera to be granted", Toast.LENGTH_SHORT).show(); } // Request permission from the user to access the camera. Log.i(TAG, "CameraSurface(): must ask user for camera access permission"); activityRef.requestPermissions(new String[] { Manifest.permission.CAMERA }, ARNativeOSGActivity.REQUEST_CAMERA_PERMISSION_RESULT); return; } } } catch (Exception ex) { Log.e(TAG, "CameraSurface(): exception caught, " + ex.getMessage()); return; } SurfaceHolder holder = getHolder(); holder.addCallback(this); holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); // Deprecated in API level 11. Still required for API levels <= 10. }
From source file:org.artoolkit.ar.samples.ARNative.CameraSurface.java
@SuppressWarnings("deprecation") public CameraSurface(Context context) { super(context); Log.i(TAG, "CameraSurface(): ctor called"); Activity activityRef = (Activity) context; try {//from ww w . j av a 2 s .c om if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { if (PackageManager.PERMISSION_GRANTED != ContextCompat.checkSelfPermission(activityRef, Manifest.permission.CAMERA)) { mustAskPermissionFirst = true; if (activityRef.shouldShowRequestPermissionRationale(Manifest.permission.CAMERA)) { // Will drop in here if user denied permissions access camera before. // Or no uses-permission CAMERA element is in the // manifest file. Must explain to the end user why the app wants // permissions to the camera devices. Toast.makeText(activityRef.getApplicationContext(), "App requires access to camera to be granted", Toast.LENGTH_SHORT).show(); } // Request permission from the user to access the camera. Log.i(TAG, "CameraSurface(): must ask user for camera access permission"); activityRef.requestPermissions(new String[] { Manifest.permission.CAMERA }, ARNativeActivity.REQUEST_CAMERA_PERMISSION_RESULT); return; } } } catch (Exception ex) { Log.e(TAG, "CameraSurface(): exception caught, " + ex.getMessage()); return; } SurfaceHolder holder = getHolder(); holder.addCallback(this); holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); // Deprecated in API level 11. Still required for API levels <= 10. }
From source file:com.mobiuso.argo.ARModule.CameraSurface.java
@SuppressWarnings("deprecation") public CameraSurface(Context context) { super(context); Log.i(TAG, "CameraSurface(): ctor called"); Activity activityRef = (Activity) context; try {//w w w. j a va 2 s .co m if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { if (PackageManager.PERMISSION_GRANTED != ContextCompat.checkSelfPermission(activityRef, Manifest.permission.CAMERA)) { mustAskPermissionFirst = true; if (activityRef.shouldShowRequestPermissionRationale(Manifest.permission.CAMERA)) { // Will drop in here if user denied permissions access camera before. // Or no uses-permission CAMERA element is in the // manifest file. Must explain to the end user why the app wants // permissions to the camera devices. Toast.makeText(activityRef.getApplicationContext(), "App requires access to camera to be granted", Toast.LENGTH_SHORT).show(); } // Request permission from the user to access the camera. Log.i(TAG, "CameraSurface(): must ask user for camera access permission"); activityRef.requestPermissions(new String[] { Manifest.permission.CAMERA }, ARMovieActivity.REQUEST_CAMERA_PERMISSION_RESULT); return; } } } catch (Exception ex) { Log.e(TAG, "CameraSurface(): exception caught, " + ex.getMessage()); return; } SurfaceHolder holder = getHolder(); holder.addCallback(this); holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); // Deprecated in API level 11. Still required for API levels <= 10. }
From source file:com.android.dialer.voicemail.VoicemailPlaybackPresenter.java
/** * Initialize variables which are activity-independent and state-independent. *///from w ww. j a va 2 s . c o m protected VoicemailPlaybackPresenter(Activity activity) { Context context = activity.getApplicationContext(); mAsyncTaskExecutor = AsyncTaskExecutors.createAsyncTaskExecutor(); mVoicemailAudioManager = new VoicemailAudioManager(context, this); mVoicemailAsyncTaskUtil = new VoicemailAsyncTaskUtil(context.getContentResolver()); PowerManager powerManager = (PowerManager) context.getSystemService(Context.POWER_SERVICE); if (powerManager.isWakeLockLevelSupported(PowerManager.PROXIMITY_SCREEN_OFF_WAKE_LOCK)) { mProximityWakeLock = powerManager.newWakeLock(PowerManager.PROXIMITY_SCREEN_OFF_WAKE_LOCK, TAG); } }
From source file:jp.co.rediscovery.arflight.ManagerFragment.java
/** * ARSDK????/* ww w.j a v a2s . c om*/ * #stopDiscovery??? */ private void unbindServices() { if (ardiscoveryServiceBound) { ardiscoveryServiceBound = false; final Activity activity = getActivity(); if (activity == null) return; final Context app_context = activity.getApplicationContext(); queueEvent(new Runnable() { @Override public void run() { try { ardiscoveryService.stop(); app_context.unbindService(ardiscoveryServiceConnection); discoveryServiceBinder = null; ardiscoveryService = null; } catch (final Exception e) { Log.w(TAG, e); } } }); } }
From source file:org.artoolkit.ar.samples.nftSimple.CameraSurface.java
@SuppressWarnings("deprecation") public CameraSurface(Context context) { super(context); Log.i(TAG, "CameraSurface(): ctor called"); Activity activityRef = (Activity) context; try {//from w ww . j a v a 2s. c o m if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { if (PackageManager.PERMISSION_GRANTED != ContextCompat.checkSelfPermission(activityRef, Manifest.permission.CAMERA)) { mustAskPermissionFirst = true; if (activityRef.shouldShowRequestPermissionRationale(Manifest.permission.CAMERA)) { // Will drop in here if user denied permissions access camera before. // Or no uses-permission CAMERA element is in the // manifest file. Must explain to the end user why the app wants // permissions to the camera devices. Toast.makeText(activityRef.getApplicationContext(), "App requires access to camera to be granted", Toast.LENGTH_SHORT).show(); } // Request permission from the user to access the camera. Log.i(TAG, "CameraSurface(): must ask user for camera access permission"); activityRef.requestPermissions(new String[] { Manifest.permission.CAMERA }, nftSimpleActivity.REQUEST_CAMERA_PERMISSION_RESULT); return; } } } catch (Exception ex) { Log.e(TAG, "CameraSurface(): exception caught, " + ex.getMessage()); return; } SurfaceHolder holder = getHolder(); holder.addCallback(this); holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); // Deprecated in API level 11. Still required for API levels <= 10. }
From source file:org.artoolkit.ar.utils.calib_optical.CameraSurface.java
@SuppressWarnings("deprecation") public CameraSurface(Context context) { super(context); Log.i(TAG, "CameraSurface(): ctor called"); Activity activityRef = (Activity) context; try {/*from w ww. j a v a 2s . c o m*/ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { if (PackageManager.PERMISSION_GRANTED != ContextCompat.checkSelfPermission(activityRef, Manifest.permission.CAMERA)) { mustAskPermissionFirst = true; if (activityRef.shouldShowRequestPermissionRationale(Manifest.permission.CAMERA)) { // Will drop in here if user denied permissions access camera before. // Or no uses-permission CAMERA element is in the // manifest file. Must explain to the end user why the app wants // permissions to the camera devices. Toast.makeText(activityRef.getApplicationContext(), "App requires access to camera to be granted", Toast.LENGTH_SHORT).show(); } // Request permission from the user to access the camera. Log.i(TAG, "CameraSurface(): must ask user for camera access permission"); activityRef.requestPermissions(new String[] { Manifest.permission.CAMERA }, calib_optical_Activity.REQUEST_CAMERA_PERMISSION_RESULT); return; } } } catch (Exception ex) { Log.e(TAG, "CameraSurface(): exception caught, " + ex.getMessage()); return; } SurfaceHolder holder = getHolder(); holder.addCallback(this); holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); // Deprecated in API level 11. Still required for API levels <= 10. }