List of usage examples for android.app Activity getSystemService
@Override
public Object getSystemService(@ServiceName @NonNull String name)
From source file:org.dmfs.android.microfragments.HostFragment.java
private void executeTransition(@NonNull Activity activity, @NonNull FragmentTransition fragmentTransition) { if (!fragmentTransition.timestamp().isAfter(mLastTransactionTimestamp)) { // ignore outdated transition return;//from ww w.j a v a 2s . c om } mLastTransactionTimestamp = fragmentTransition.timestamp(); MicroFragment microFragment = new FragmentEnvironment<>( mFragmentManager.findFragmentById(R.id.microfragments_host)).microFragment(); MicroFragmentHost host = new BasicMicroFragmentHost(mOperationDoveCote.cage()); fragmentTransition.prepare(activity, mFragmentManager, host, microFragment); FragmentTransaction fragmentTransaction = fragmentTransition.updateTransaction(activity, mFragmentManager.beginTransaction(), mFragmentManager, host, microFragment); if (!fragmentTransaction.isEmpty()) { fragmentTransaction.commit(); } mFragmentManager.executePendingTransactions(); fragmentTransition.cleanup(activity, mFragmentManager, host, microFragment); // post an update, in case the backstack has not been changed by the transition we still have to notify the listener postUpdate(new FragmentEnvironment<>(currentFragment()).microFragment()); // close keyboard if necessary if (activity.getCurrentFocus() == null) { // no view is focused, close the keyboard InputMethodManager inputManager = (InputMethodManager) activity .getSystemService(Context.INPUT_METHOD_SERVICE); inputManager.hideSoftInputFromWindow(activity.findViewById(android.R.id.content).getWindowToken(), 0); } }
From source file:org.cryptsecure.Utility.java
/** * Sets the content view with custom title. This is necessary for a holo * layout where a custom title bar is normally not permitted. * //from w ww. ja v a 2 s.c o m * @param activity * the activity * @param resIdMainLayout * the res id main layout * @param resIdTitle * the res id title * @return the linear layout */ public static LinearLayout setContentViewWithCustomTitle(Activity activity, int resIdMainLayout, int resIdTitle) { Context context = activity.getApplicationContext(); // Inflate the given layouts LayoutInflater inflaterInfo = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE); View titleView = (View) inflaterInfo.inflate(resIdTitle, null); View mainView = (View) inflaterInfo.inflate(resIdMainLayout, null); // Own custom title bar // // ATTENTION: // ADD THIS TO THEME <item name="android:windowNoTitle">true</item> activity.requestWindowFeature(Window.FEATURE_NO_TITLE); // We can ONLY disable the original title bar because you cannot combine // HOLO theme with a CUSTOM title bar :( // So we make our own title bar instead! // ALSO REMOVE TITLEBAR FROM APPLICATION AT STARTUP: // ADD TO MANIFEST // android:theme="@android:style/Theme.NoTitleBar" // THE FOLLOWING IS NOT WORKING WITH HOLO // requestWindowFeature(Window.FEATURE_CUSTOM_TITLE); // setContentView(R.layout.activity_main); // getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, // R.layout.title_main); // Create title layout LinearLayout.LayoutParams lpTitle = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); LinearLayout titleLayout = new LinearLayout(context); titleLayout.setOrientation(LinearLayout.VERTICAL); titleLayout.addView(titleView); titleLayout.setLayoutParams(lpTitle); // Create main layout LinearLayout.LayoutParams lpMain = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT); LinearLayout mainLayout = new LinearLayout(context); mainLayout.setOrientation(LinearLayout.VERTICAL); mainLayout.addView(mainView); mainLayout.setLayoutParams(lpMain); // Create root outer layout LinearLayout outerLayout = new LinearLayout(context); outerLayout.setOrientation(LinearLayout.VERTICAL); outerLayout.addView(titleLayout); outerLayout.addView(mainLayout); // outerLayout.setBackgroundColor(Color.rgb(255, 0, 0)); // mainLayout.setBackgroundColor(Color.rgb(0, 255, 0)); // titleLayout.setBackgroundColor(Color.rgb(0, 0, 255)); // lpSectionInnerLeft.setMargins(20, 5, 0, 15); // LinearLayout.LayoutParams lpSectionInnerRight = new // LinearLayout.LayoutParams( // 90, LinearLayout.LayoutParams.WRAP_CONTENT, 0f); // lpSectionInnerRight.setMargins(0, 5, 15, 15); // After setting NO TITLE .. apply the layout activity.setContentView(outerLayout); return mainLayout; }
From source file:me.acristoffers.tracker.fragments.PackageDetailsFragment.java
private void setupUI() { final Activity activity = getActivity(); final View view = getView(); if (activity == null || view == null) { return;//from w ww . j a v a 2 s .com } String code = null; final Bundle arguments = getArguments(); if (arguments != null) { code = arguments.getString(PackageDetailsActivity.PACKAGE_CODE); } if (code == null || code.isEmpty()) { final Intent intent = activity.getIntent(); if (intent != null) { code = intent.getStringExtra(PackageDetailsActivity.PACKAGE_CODE); } } if (code == null || code.isEmpty()) { return; } final RecyclerView recyclerView = (RecyclerView) view.findViewById(R.id.steps); final RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(activity); recyclerView.setLayoutManager(layoutManager); pkg = new Package(code, getActivity(), null); final StepListAdapter stepListAdapter = new StepListAdapter(pkg, activity); recyclerView.setAdapter(stepListAdapter); TextView textView = (TextView) view.findViewById(R.id.name); textView.setText(pkg.getName()); textView = (TextView) view.findViewById(R.id.code); textView.setText(pkg.getCod()); textView.setOnLongClickListener(new View.OnLongClickListener() { @Override public boolean onLongClick(View view) { final ClipboardManager clipboardManager = (ClipboardManager) activity .getSystemService(Context.CLIPBOARD_SERVICE); if (clipboardManager != null) { final String code = pkg.getCod(); final ClipData clipData = ClipData.newPlainText(code, code); clipboardManager.setPrimaryClip(clipData); final Toast toast = Toast.makeText(activity, R.string.code_copied, Toast.LENGTH_SHORT); toast.show(); return true; } return false; } }); if (!pkg.getSteps().isEmpty()) { textView = (TextView) view.findViewById(R.id.emptyStepView); textView.setVisibility(View.INVISIBLE); } final NotificationManager nm = (NotificationManager) activity .getSystemService(Context.NOTIFICATION_SERVICE); nm.cancel(pkg.getId()); }
From source file:jackpal.androidterm.Term.java
private void doShowSoftKeyboard() { if (getCurrentEmulatorView() == null) return;//from ww w . j a va 2s. c om Activity activity = this; InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE); imm.showSoftInput(getCurrentEmulatorView(), InputMethodManager.SHOW_FORCED); }
From source file:com.quectel.camera2test.Camera2RawFragment.java
/** * Opens the camera specified by {@link #mCameraId}. *//*from w w w . j a v a2 s. c o m*/ @SuppressWarnings("MissingPermission") private void openCamera() { if (!setUpCameraOutputs()) { return; } if (!hasAllPermissionsGranted()) { requestCameraPermissions(); return; } Activity activity = getActivity(); CameraManager manager = (CameraManager) activity.getSystemService(Context.CAMERA_SERVICE); try { // Wait for any previously running session to finish. if (!mCameraOpenCloseLock.tryAcquire(2500, TimeUnit.MILLISECONDS)) { throw new RuntimeException("Time out waiting to lock camera opening."); } String cameraId; Handler backgroundHandler; synchronized (mCameraStateLock) { cameraId = mCameraId; backgroundHandler = mBackgroundHandler; } // Attempt to open the camera. mStateCallback will be called on the background handler's // thread when this succeeds or fails. manager.openCamera(cameraId, mStateCallback, backgroundHandler); } catch (CameraAccessException e) { e.printStackTrace(); } catch (InterruptedException e) { throw new RuntimeException("Interrupted while trying to lock camera opening.", e); } }
From source file:com.ape.camera2raw.Camera2RawFragment.java
/** * Opens the camera specified by {@link #mCameraId}. *//*from ww w. j ava 2s . c o m*/ private void openCamera() { if (!setUpCameraOutputs()) { return; } if (!hasAllPermissionsGranted()) { requestCameraPermissions(); return; } Activity activity = getActivity(); CameraManager manager = (CameraManager) activity.getSystemService(Context.CAMERA_SERVICE); try { // Wait for any previously running session to finish. if (!mCameraOpenCloseLock.tryAcquire(2500, TimeUnit.MILLISECONDS)) { throw new RuntimeException("Time out waiting to lock camera opening."); } String cameraId; Handler backgroundHandler; synchronized (mCameraStateLock) { cameraId = mCameraId; backgroundHandler = mBackgroundHandler; } // Attempt to open the camera. mStateCallback will be called on the background handler's // thread when this succeeds or fails. manager.openCamera(cameraId, mStateCallback, 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.android.camera2raw.Camera2RawFragment.java
/** * Sets up state related to camera that is needed before opening a {@link CameraDevice}. */// w ww . j a v a 2 s. c o m private boolean setUpCameraOutputs() { Activity activity = getActivity(); CameraManager manager = (CameraManager) activity.getSystemService(Context.CAMERA_SERVICE); if (manager == null) { ErrorDialog.buildErrorDialog("This device doesn't support Camera2 API.").show(getFragmentManager(), "dialog"); return false; } try { // Find a CameraDevice that supports RAW captures, and configure state. for (String cameraId : manager.getCameraIdList()) { CameraCharacteristics characteristics = manager.getCameraCharacteristics(cameraId); // We only use a camera that supports RAW in this sample. if (!contains(characteristics.get(CameraCharacteristics.REQUEST_AVAILABLE_CAPABILITIES), CameraCharacteristics.REQUEST_AVAILABLE_CAPABILITIES_RAW)) { continue; } StreamConfigurationMap map = characteristics .get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP); // For still image captures, we use the largest available size. Size largestJpeg = Collections.max(Arrays.asList(map.getOutputSizes(ImageFormat.JPEG)), new CompareSizesByArea()); Size largestRaw = Collections.max(Arrays.asList(map.getOutputSizes(ImageFormat.RAW_SENSOR)), new CompareSizesByArea()); synchronized (mCameraStateLock) { // Set up ImageReaders for JPEG and RAW outputs. Place these in a reference // counted wrapper to ensure they are only closed when all background tasks // using them are finished. if (mJpegImageReader == null || mJpegImageReader.getAndRetain() == null) { mJpegImageReader = new RefCountedAutoCloseable<>(ImageReader.newInstance( largestJpeg.getWidth(), largestJpeg.getHeight(), ImageFormat.JPEG, /*maxImages*/5)); } mJpegImageReader.get().setOnImageAvailableListener(mOnJpegImageAvailableListener, mBackgroundHandler); if (mRawImageReader == null || mRawImageReader.getAndRetain() == null) { mRawImageReader = new RefCountedAutoCloseable<>( ImageReader.newInstance(largestRaw.getWidth(), largestRaw.getHeight(), ImageFormat.RAW_SENSOR, /*maxImages*/ 5)); } mRawImageReader.get().setOnImageAvailableListener(mOnRawImageAvailableListener, mBackgroundHandler); mCharacteristics = characteristics; mCameraId = cameraId; } return true; } } catch (CameraAccessException e) { e.printStackTrace(); } // If we found no suitable cameras for capturing RAW, warn the user. ErrorDialog.buildErrorDialog("This device doesn't support capturing RAW photos").show(getFragmentManager(), "dialog"); return false; }
From source file:com.krayzk9s.imgurholo.ui.ImagesFragment.java
@Override public boolean onOptionsItemSelected(MenuItem item) { // handle item selection final Activity activity = getActivity(); switch (item.getItemId()) { case R.id.action_download: Toast.makeText(activity,//from w w w . j a v a 2 s .c o m String.format(getActivity().getResources().getString(R.string.toast_downloading), urls.size()), Toast.LENGTH_SHORT).show(); Intent serviceIntent = new Intent(activity, DownloadService.class); serviceIntent.putParcelableArrayListExtra("ids", ids); if (albumId != null) serviceIntent.putExtra("albumName", albumId); else serviceIntent.putExtra("albumName", imageCall); activity.startService(serviceIntent); return true; case R.id.action_refresh: urls = new ArrayList<String>(); ids = new ArrayList<JSONParcelable>(); page = 0; makeGallery(); return true; case R.id.action_copy: ClipboardManager clipboard = (ClipboardManager) activity.getSystemService(Context.CLIPBOARD_SERVICE); ClipData clip = ClipData.newPlainText("imgur Link", "http://imgur.com/a/" + albumId); clipboard.setPrimaryClip(clip); Toast.makeText(activity, R.string.toast_copied, Toast.LENGTH_SHORT).show(); return true; case R.id.action_share: Intent intent = new Intent(android.content.Intent.ACTION_SEND); intent.setType("text/plain"); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET); intent.putExtra(Intent.EXTRA_TEXT, "http://imgur.com/a/" + albumId); startActivity(intent); return true; case R.id.action_new: Intent i = new Intent(this.getActivity().getApplicationContext(), ImageSelectActivity.class); startActivityForResult(i, 1); //select image return true; case R.id.action_comments: if (galleryAlbumData != null) { CommentsAsync commentsAsync = new CommentsAsync(((ImgurHoloActivity) getActivity()), galleryAlbumData); commentsAsync.execute(); return true; } else return super.onOptionsItemSelected(item); default: return super.onOptionsItemSelected(item); } }
From source file:com.quectel.camera2test.Camera2RawFragment.java
/** * Sets up state related to camera that is needed before opening a {@link CameraDevice}. *///from w w w . j a v a 2 s . c o m private boolean setUpCameraOutputs() { Activity activity = getActivity(); CameraManager manager = (CameraManager) activity.getSystemService(Context.CAMERA_SERVICE); if (manager == null) { ErrorDialog.buildErrorDialog("This device doesn't support Camera2 API.").show(getFragmentManager(), "dialog"); return false; } try { // Find a CameraDevice that supports RAW captures, and configure state. for (String cameraId : manager.getCameraIdList()) { CameraCharacteristics characteristics = manager.getCameraCharacteristics(cameraId); Log.d(TAG, "---characteristics = " + characteristics); // We only use a camera that supports RAW in this sample. if (!contains(characteristics.get(CameraCharacteristics.REQUEST_AVAILABLE_CAPABILITIES), CameraCharacteristics.REQUEST_AVAILABLE_CAPABILITIES_RAW)) { Log.d(TAG, "-1--characteristics continue"); continue; } Log.d(TAG, "-1--characteristics = " + characteristics); StreamConfigurationMap map = characteristics .get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP); // For still image captures, we use the largest available size. Size largestJpeg = Collections.max(Arrays.asList(map.getOutputSizes(ImageFormat.JPEG)), new CompareSizesByArea()); Size largestRaw = Collections.max(Arrays.asList(map.getOutputSizes(ImageFormat.RAW_SENSOR)), new CompareSizesByArea()); synchronized (mCameraStateLock) { // Set up ImageReaders for JPEG and RAW outputs. Place these in a reference // counted wrapper to ensure they are only closed when all background tasks // using them are finished. if (mJpegImageReader == null || mJpegImageReader.getAndRetain() == null) { mJpegImageReader = new RefCountedAutoCloseable<>(ImageReader.newInstance( largestJpeg.getWidth(), largestJpeg.getHeight(), ImageFormat.JPEG, /*maxImages*/5)); } mJpegImageReader.get().setOnImageAvailableListener(mOnJpegImageAvailableListener, mBackgroundHandler); if (mRawImageReader == null || mRawImageReader.getAndRetain() == null) { mRawImageReader = new RefCountedAutoCloseable<>( ImageReader.newInstance(largestRaw.getWidth(), largestRaw.getHeight(), ImageFormat.RAW_SENSOR, /*maxImages*/ 5)); } mRawImageReader.get().setOnImageAvailableListener(mOnRawImageAvailableListener, mBackgroundHandler); mCharacteristics = characteristics; mCameraId = cameraId; } return true; } } catch (CameraAccessException e) { e.printStackTrace(); } // If we found no suitable cameras for capturing RAW, warn the user. ErrorDialog.buildErrorDialog("This device doesn't support capturing RAW photos").show(getFragmentManager(), "dialog"); return false; }
From source file:com.ape.camera2raw.Camera2RawFragment.java
/** * Sets up state related to camera that is needed before opening a {@link CameraDevice}. */// w ww. j a v a 2 s.c o m private boolean setUpCameraOutputs() { Activity activity = getActivity(); CameraManager manager = (CameraManager) activity.getSystemService(Context.CAMERA_SERVICE); if (manager == null) { ErrorDialog.buildErrorDialog("This device doesn't support Camera2 API.").show(getFragmentManager(), "dialog"); return false; } try { // Find a CameraDevice that supports RAW captures, and configure state. for (String cameraId : manager.getCameraIdList()) { CameraCharacteristics characteristics = manager.getCameraCharacteristics(cameraId); // We only use a camera that supports RAW in this sample. if (!contains(characteristics.get(CameraCharacteristics.REQUEST_AVAILABLE_CAPABILITIES), CameraCharacteristics.REQUEST_AVAILABLE_CAPABILITIES_RAW)) { continue; } StreamConfigurationMap map = characteristics .get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP); // For still image captures, we use the largest available size. Size largestJpeg = Collections.max(Arrays.asList(map.getOutputSizes(ImageFormat.JPEG)), new CompareSizesByArea()); Size largestRaw = Collections.max(Arrays.asList(map.getOutputSizes(ImageFormat.RAW_SENSOR)), new CompareSizesByArea()); Log.d("WAY", "largestRaw = " + largestRaw); //largestRaw = new Size(4208, 3120);//9051 synchronized (mCameraStateLock) { // Set up ImageReaders for JPEG and RAW outputs. Place these in a reference // counted wrapper to ensure they are only closed when all background tasks // using them are finished. if (mJpegImageReader == null || mJpegImageReader.getAndRetain() == null) { mJpegImageReader = new RefCountedAutoCloseable<>(ImageReader.newInstance( largestJpeg.getWidth(), largestJpeg.getHeight(), ImageFormat.JPEG, /*maxImages*/5)); } mJpegImageReader.get().setOnImageAvailableListener(mOnJpegImageAvailableListener, mBackgroundHandler); if (mRawImageReader == null || mRawImageReader.getAndRetain() == null) { mRawImageReader = new RefCountedAutoCloseable<>( ImageReader.newInstance(largestRaw.getWidth(), largestRaw.getHeight(), ImageFormat.RAW_SENSOR, /*maxImages*/ 5)); } mRawImageReader.get().setOnImageAvailableListener(mOnRawImageAvailableListener, mBackgroundHandler); mCharacteristics = characteristics; mCameraId = cameraId; } return true; } } catch (CameraAccessException e) { e.printStackTrace(); } // If we found no suitable cameras for capturing RAW, warn the user. ErrorDialog.buildErrorDialog("This device doesn't support capturing RAW photos").show(getFragmentManager(), "dialog"); return false; }