List of usage examples for android.app Activity getSystemService
@Override
public Object getSystemService(@ServiceName @NonNull String name)
From source file:fr.xebia.magritte.classifier.lite.Camera2BasicFragment.java
/** Opens the camera specified by {@link Camera2BasicFragment#cameraId}. */ private void openCamera(int width, int height) { if (!checkedPermissions && !allPermissionsGranted()) { FragmentCompat.requestPermissions(this, getRequiredPermissions(), PERMISSIONS_REQUEST_CODE); return;/*ww w . j a v a 2 s . c om*/ } else { checkedPermissions = true; } setUpCameraOutputs(width, height); configureTransform(width, height); Activity activity = getActivity(); CameraManager manager = (CameraManager) activity.getSystemService(Context.CAMERA_SERVICE); try { if (!cameraOpenCloseLock.tryAcquire(2500, TimeUnit.MILLISECONDS)) { throw new RuntimeException("Time out waiting to lock camera opening."); } manager.openCamera(cameraId, stateCallback, backgroundHandler); } catch (CameraAccessException e) { e.printStackTrace(); } catch (InterruptedException e) { throw new RuntimeException("Interrupted while trying to lock camera opening.", e); } }
From source file:com.example.camera2apidemo.Camera2Fragment.java
private String setUpCameraOutputs(int width, int height) { Activity activity = getActivity(); CameraManager manager = (CameraManager) activity.getSystemService(Context.CAMERA_SERVICE); try {//from w w w. j a v a 2 s.c o m for (String cameraId : manager.getCameraIdList()) { CameraCharacteristics characteristics = manager.getCameraCharacteristics(cameraId); // ??? We don't use a front facing camera in this sample. Integer facing = characteristics.get(CameraCharacteristics.LENS_FACING); if (facing != null && facing == CameraCharacteristics.LENS_FACING_FRONT) { continue; } // ?? ?? StreamConfigurationMap map = characteristics .get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP); if (map == null) { continue; } // For still image captures, we use the largest available size. Size largest = Collections.max(Arrays.asList(map.getOutputSizes(ImageFormat.JPEG)), new CompareSizesByArea()); mImageReader = ImageReader.newInstance(largest.getWidth(), largest.getHeight(), ImageFormat.JPEG, /*maxImages*/2); mImageReader.setOnImageAvailableListener(mOnImageAvailableListener, mBackgroundHandler); // Check if the flash is supported. Boolean available = characteristics.get(CameraCharacteristics.FLASH_INFO_AVAILABLE); mFlashSupported = available == null ? false : available; return cameraId; } } catch (CameraAccessException e) { e.printStackTrace(); } catch (NullPointerException e) { // Currently an NPE is thrown when the Camera2API is used but not supported on the // device this code runs. // ErrorDialog.newInstance(getString(R.string.camera_error)) // .show(getChildFragmentManager(), FRAGMENT_DIALOG); } return null; }
From source file:com.cyanogenmod.messaging.quickmessage.QuickMessagePopup.java
/** * display the sim select dialog for multi sim phones *///w w w .j av a2 s . c om private void showSimSelector(Activity activity, final ComposeMessageView.OnSimSelectedCallback cb) { final TelecomManager telecomMgr = (TelecomManager) activity.getSystemService(Context.TELECOM_SERVICE); final List<PhoneAccountHandle> handles = telecomMgr.getCallCapablePhoneAccounts(); final List<PhoneAccountHandle> filteredHandles = new ArrayList<>(); //trim out SIP accounts for (PhoneAccountHandle handle : handles) { PhoneAccount phoneAccount = PhoneUtils.getAccountOrNull(activity, handle); if (phoneAccount != null) { Uri address = phoneAccount.getAddress(); if (address != null && !TextUtils.equals(address.getScheme(), PhoneAccount.SCHEME_SIP)) { filteredHandles.add(handle); } } } final SelectPhoneAccountDialogFragment.SelectPhoneAccountListener listener = new SelectPhoneAccountDialogFragment.SelectPhoneAccountListener() { @Override public void onPhoneAccountSelected(PhoneAccountHandle selectedAccountHandle, boolean setDefault) { // we need the subId and we only have a PhoneAccountHandle TelephonyManager telephonyManager = (TelephonyManager) mContext .getSystemService(Context.TELEPHONY_SERVICE); Iterator<PhoneAccountHandle> phoneAccounts = telecomMgr.getCallCapablePhoneAccounts() .listIterator(); int subId = 0; // defaulting to 0, just in case while (phoneAccounts.hasNext()) { PhoneAccountHandle p = phoneAccounts.next(); if (p.getId().equals(selectedAccountHandle.getId())) { PhoneAccount phoneAccount = telecomMgr.getPhoneAccount(p); subId = telephonyManager.getSubIdForPhoneAccount(phoneAccount); } } cb.onSimSelected(subId); } @Override public void onDialogDismissed() { } }; DialogFragment dialogFragment = SelectPhoneAccountDialogFragment.newInstance( R.string.select_phone_account_title, false /* canSetDefault */, filteredHandles, listener); dialogFragment.show(activity.getFragmentManager(), "SELECT_PHONE_ACCOUNT_DIALOG_FRAGMENT"); }
From source file:cc.mintcoin.wallet.ui.TransactionsListFragment.java
@Override public void onAttach(final Activity activity) { super.onAttach(activity); this.activity = (AbstractWalletActivity) activity; this.application = (WalletApplication) activity.getApplication(); this.config = application.getConfiguration(); this.wallet = application.getWallet(); this.nfcManager = (NfcManager) activity.getSystemService(Context.NFC_SERVICE); this.resolver = activity.getContentResolver(); this.loaderManager = getLoaderManager(); }
From source file:com.supremainc.biostar2.base.BaseListCursorAdapter.java
public BaseListCursorAdapter(Activity context, ListView listView, Popup popup) { this(context, NotificationDBProvider.getInstance(context).getPushAlarmCursor()); mDBProvider = NotificationDBProvider.getInstance(context); mContext = context;//from w w w .j a va 2 s . c om mListView = listView; mListView.setOnItemClickListener(this); mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); mToastPopup = new ToastPopup(context); mPopup = popup; }
From source file:org.jitsi.android.gui.contactlist.ContactListFragment.java
/** * Invoked when the options menu is created. Creates our own options menu * from the corresponding xml./* w w w.jav a 2 s . c o m*/ * * @param menu the options menu */ @TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH) @Override public void onCreateOptionsMenu(Menu menu, MenuInflater menuInflater) { super.onCreateOptionsMenu(menu, menuInflater); Activity activity = getActivity(); // Get the SearchView and set the searchable configuration SearchManager searchManager = (SearchManager) activity.getSystemService(Context.SEARCH_SERVICE); this.searchItem = menu.findItem(R.id.search); // OnActionExpandListener not supported prior API 14 if (AndroidUtils.hasAPI(14)) { searchItem.setOnActionExpandListener(new MenuItem.OnActionExpandListener() { @Override public boolean onMenuItemActionCollapse(MenuItem item) { filterContactList(""); return true; // Return true to collapse action view } public boolean onMenuItemActionExpand(MenuItem item) { return true; // Return true to expand action view } }); } if (AndroidUtils.hasAPI(11)) { SearchView searchView = (SearchView) searchItem.getActionView(); searchView.setSearchableInfo(searchManager.getSearchableInfo(activity.getComponentName())); int id = searchView.getContext().getResources().getIdentifier("android:id/search_src_text", null, null); TextView textView = (TextView) searchView.findViewById(id); textView.setTextColor(getResources().getColor(R.color.white)); textView.setHintTextColor(getResources().getColor(R.color.white)); bindSearchListener(); } }
From source file:com.granita.tasks.ViewTaskFragment.java
/** * Update the detail view with the current ContentSet. This removes any previous detail view and creates a new one if {@link #mContentSet} is not * <code>null</code>./*from ww w. j a v a 2 s . c o m*/ */ private void updateView() { Activity activity = getActivity(); if (mContent != null && activity != null) { final LayoutInflater inflater = (LayoutInflater) activity .getSystemService(Context.LAYOUT_INFLATER_SERVICE); if (mDetailView != null) { // remove values, to ensure all listeners get released mDetailView.setValues(null); } mContent.removeAllViews(); if (mContentSet != null) { mDetailView = (TaskView) inflater.inflate(R.layout.task_view, mContent, false); mDetailView.setModel(mModel); mDetailView.setValues(mContentSet); mContent.addView(mDetailView); } mActionButton = mDetailView.findViewById(R.id.action_button); if (mActionButton != null) { mActionButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { switch (mActionButtonAction) { case ACTION_COMPLETE: { completeTask(); break; } case ACTION_EDIT: { mCallback.onEditTask(mTaskUri, mContentSet); break; } } } }); } if (mContentSet != null && TaskFieldAdapters.IS_CLOSED.get(mContentSet)) { ((ImageView) mActionButton.findViewById(android.R.id.icon)) .setImageResource(R.drawable.content_edit); mActionButtonAction = ACTION_EDIT; } else { mActionButtonAction = ACTION_COMPLETE; } if (mColorBar != null) { updateColor((float) mRootView.getScrollY() / mColorBar.getMeasuredHeight()); } } }
From source file:com.tzutalin.dlibtest.CameraConnectionFragment.java
/** * Sets up member variables related to camera. * * @param width The width of available size for camera preview * @param height The height of available size for camera preview *//*from www. j a v a 2s.co m*/ @DebugLog @SuppressLint("LongLogTag") private void setUpCameraOutputs(final int width, final int height) { final Activity activity = getActivity(); final CameraManager manager = (CameraManager) activity.getSystemService(Context.CAMERA_SERVICE); try { SparseArray<Integer> cameraFaceTypeMap = new SparseArray<>(); // Check the facing types of camera devices for (final String cameraId : manager.getCameraIdList()) { final CameraCharacteristics characteristics = manager.getCameraCharacteristics(cameraId); final Integer facing = characteristics.get(CameraCharacteristics.LENS_FACING); if (facing != null && facing == CameraCharacteristics.LENS_FACING_FRONT) { if (cameraFaceTypeMap.get(CameraCharacteristics.LENS_FACING_FRONT) != null) { cameraFaceTypeMap.append(CameraCharacteristics.LENS_FACING_FRONT, cameraFaceTypeMap.get(CameraCharacteristics.LENS_FACING_FRONT) + 1); } else { cameraFaceTypeMap.append(CameraCharacteristics.LENS_FACING_FRONT, 1); } } if (facing != null && facing == CameraCharacteristics.LENS_FACING_BACK) { if (cameraFaceTypeMap.get(CameraCharacteristics.LENS_FACING_FRONT) != null) { cameraFaceTypeMap.append(CameraCharacteristics.LENS_FACING_BACK, cameraFaceTypeMap.get(CameraCharacteristics.LENS_FACING_BACK) + 1); } else { cameraFaceTypeMap.append(CameraCharacteristics.LENS_FACING_BACK, 1); } } } Integer num_facing_back_camera = cameraFaceTypeMap.get(CameraCharacteristics.LENS_FACING_BACK); for (final String cameraId : manager.getCameraIdList()) { final CameraCharacteristics characteristics = manager.getCameraCharacteristics(cameraId); final Integer facing = characteristics.get(CameraCharacteristics.LENS_FACING); // If facing back camera or facing external camera exist, we won't use facing front camera if (num_facing_back_camera != null && num_facing_back_camera > 0) { // We don't use a front facing camera in this sample if there are other camera device facing types if (facing != null && facing == CameraCharacteristics.LENS_FACING_FRONT) { continue; } } final StreamConfigurationMap map = characteristics .get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP); if (map == null) { continue; } // For still image captures, we use the largest available size. final Size largest = Collections.max(Arrays.asList(map.getOutputSizes(ImageFormat.YUV_420_888)), new CompareSizesByArea()); // Danger, W.R.! Attempting to use too large a preview size could exceed the camera // bus' bandwidth limitation, resulting in gorgeous previews but the storage of // garbage capture data. previewSize = chooseOptimalSize(map.getOutputSizes(SurfaceTexture.class), width, height, largest); // We fit the aspect ratio of TextureView to the size of preview we picked. final int orientation = getResources().getConfiguration().orientation; if (orientation == Configuration.ORIENTATION_LANDSCAPE) { textureView.setAspectRatio(previewSize.getWidth(), previewSize.getHeight()); } else { textureView.setAspectRatio(previewSize.getHeight(), previewSize.getWidth()); } CameraConnectionFragment.this.cameraId = cameraId; return; } } catch (final CameraAccessException e) { Timber.tag(TAG).e("Exception!", e); } catch (final NullPointerException e) { // Currently an NPE is thrown when the Camera2API is used but not supported on the // device this code runs. ErrorDialog.newInstance(getString(R.string.camera_error)).show(getChildFragmentManager(), FRAGMENT_DIALOG); } }
From source file:kr.wdream.storyshop.AndroidUtilities.java
public static void lockOrientation(Activity activity) { if (activity == null || prevOrientation != -10) { return;/* www . j a v a 2s . c om*/ } try { prevOrientation = activity.getRequestedOrientation(); WindowManager manager = (WindowManager) activity.getSystemService(Activity.WINDOW_SERVICE); if (manager != null && manager.getDefaultDisplay() != null) { int rotation = manager.getDefaultDisplay().getRotation(); int orientation = activity.getResources().getConfiguration().orientation; if (rotation == Surface.ROTATION_270) { if (orientation == Configuration.ORIENTATION_PORTRAIT) { activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); } else { activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE); } } else if (rotation == Surface.ROTATION_90) { if (orientation == Configuration.ORIENTATION_PORTRAIT) { activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT); } else { activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); } } else if (rotation == Surface.ROTATION_0) { if (orientation == Configuration.ORIENTATION_LANDSCAPE) { activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); } else { activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); } } else { if (orientation == Configuration.ORIENTATION_LANDSCAPE) { activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE); } else { activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT); } } } } catch (Exception e) { FileLog.e("tmessages", e); } }
From source file:de.schildbach.litecoinwallet.ui.RequestCoinsFragment.java
@Override public void onAttach(final Activity activity) { super.onAttach(activity); this.activity = (AbstractBindServiceActivity) activity; this.application = (WalletApplication) activity.getApplication(); this.wallet = application.getWallet(); this.prefs = PreferenceManager.getDefaultSharedPreferences(activity); this.loaderManager = getLoaderManager(); this.nfcManager = (NfcManager) activity.getSystemService(Context.NFC_SERVICE); this.clipboardManager = (ClipboardManager) activity.getSystemService(Context.CLIPBOARD_SERVICE); this.bluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); }