Example usage for android.app Activity getSystemService

List of usage examples for android.app Activity getSystemService

Introduction

In this page you can find the example usage for android.app Activity getSystemService.

Prototype

@Override
    public Object getSystemService(@ServiceName @NonNull String name) 

Source Link

Usage

From source file:com.oginotihiro.datepicker.DatePickerDialog.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Activity activity = getActivity();
    activity.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);

    mVibrator = (Vibrator) activity.getSystemService(Context.VIBRATOR_SERVICE);

    if (savedInstanceState != null) {
        mCalendar.set(Calendar.YEAR, savedInstanceState.getInt(KEY_SELECTED_YEAR));
        mCalendar.set(Calendar.MONTH, savedInstanceState.getInt(KEY_SELECTED_MONTH));
        mCalendar.set(Calendar.DAY_OF_MONTH, savedInstanceState.getInt(KEY_SELECTED_DAY));

        mMinYear = savedInstanceState.getInt(KEY_YEAR_START);
        mMaxYear = savedInstanceState.getInt(KEY_YEAR_END);
        mWeekStart = savedInstanceState.getInt(KEY_WEEK_START);

        mVibrate = savedInstanceState.getBoolean(KEY_VIBRATE);
        mColor = savedInstanceState.getInt(KEY_COLOR);
        mDarkColor = savedInstanceState.getInt(KEY_DARK_COLOR);
    }// w  w  w. j  av a 2  s .  com
}

From source file:hide.com.android.datetimepicker.date.DatePickerDialog.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    final Activity activity = getActivity();
    activity.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);

    if (Utils.hasVibratePermission(activity)) {
        mVibrator = (Vibrator) activity.getSystemService(Context.VIBRATOR_SERVICE);
    }/*from  w w w . ja va2  s. co  m*/

    if (savedInstanceState != null) {
        mCalendar.set(Calendar.YEAR, savedInstanceState.getInt(KEY_SELECTED_YEAR));
        mCalendar.set(Calendar.MONTH, savedInstanceState.getInt(KEY_SELECTED_MONTH));
        mCalendar.set(Calendar.DAY_OF_MONTH, savedInstanceState.getInt(KEY_SELECTED_DAY));
    }
}

From source file:com.breadwallet.BreadWalletApp.java

public void promptForAuthentication(Activity context, int mode, PaymentRequestEntity requestEntity,
        String message, String title, PaymentRequestWrapper paymentRequest, boolean forcePasscode) {
    Log.e(TAG, "promptForAuthentication: " + mode);
    if (context == null)
        return;/*from w w w.j a v a2  s  .  com*/
    KeyguardManager keyguardManager = (KeyguardManager) context.getSystemService(Activity.KEYGUARD_SERVICE);

    boolean useFingerPrint = ActivityCompat.checkSelfPermission(this,
            Manifest.permission.USE_FINGERPRINT) == PackageManager.PERMISSION_GRANTED
            && mFingerprintManager.isHardwareDetected() && mFingerprintManager.hasEnrolledFingerprints();
    if (mode == BRConstants.AUTH_FOR_PAY) {
        long limit = KeyStoreManager.getSpendLimit(context);
        long totalSent = BRWalletManager.getInstance(context).getTotalSent();

        if (requestEntity != null)
            if (limit <= totalSent + requestEntity.amount) {
                useFingerPrint = false;
            }
    }

    if (mode == BRConstants.AUTH_FOR_LIMIT || mode == BRConstants.AUTH_FOR_PHRASE) {
        useFingerPrint = false;
    }

    if (KeyStoreManager.getFailCount(context) != 0) {
        useFingerPrint = false;
    }
    long passTime = KeyStoreManager.getLastPasscodeUsedTime(context);
    if (passTime + TimeUnit.MILLISECONDS.convert(2, TimeUnit.DAYS) <= System.currentTimeMillis()) {
        useFingerPrint = false;
    }
    if (forcePasscode)
        useFingerPrint = false;

    if (keyguardManager.isKeyguardSecure()) {
        if (useFingerPrint) {
            // This happens when no fingerprints are registered.
            FingerprintDialogFragment fingerprintDialogFragment = new FingerprintDialogFragment();
            fingerprintDialogFragment.setMode(mode);
            fingerprintDialogFragment.setPaymentRequestEntity(requestEntity, paymentRequest);
            fingerprintDialogFragment.setMessage(message);
            fingerprintDialogFragment.setTitle(message != null ? "" : title);
            if (!context.isDestroyed())
                fingerprintDialogFragment.show(context.getFragmentManager(),
                        FingerprintDialogFragment.class.getName());
        } else {
            PasswordDialogFragment passwordDialogFragment = new PasswordDialogFragment();
            passwordDialogFragment.setMode(mode);
            passwordDialogFragment.setPaymentRequestEntity(requestEntity, paymentRequest);
            passwordDialogFragment.setVerifyOnlyTrue();
            passwordDialogFragment.setMessage(message);
            if (!context.isDestroyed())
                passwordDialogFragment.show(context.getFragmentManager(),
                        PasswordDialogFragment.class.getName());
        }
    } else {
        showDeviceNotSecuredWarning(context);
    }

}

From source file:com.emobc.android.activities.generators.FormActivityGenerator.java

private EditText insertTextField(final Activity activity, FormDataItem dataItem) {
    EditText txt = new EditText(activity);
    txt.setTag(dataItem.getFieldName());
    txt.setOnFocusChangeListener(new View.OnFocusChangeListener() {
        @Override//from   ww  w . j  a va 2s . c  o m
        public void onFocusChange(View v, boolean hasFocus) {
            if (!hasFocus) {
                InputMethodManager imm = (InputMethodManager) activity
                        .getSystemService(Context.INPUT_METHOD_SERVICE);
                imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
            }
        }
    });
    return txt;
}

From source file:com.example.testcamera.Camera2BasicFragmentEasy.java

/**
 * Opens the camera specified by {@link Camera2BasicFragmentEasy#mCameraId}.
 *///from   ww  w .  ja  v  a 2s . co m
private void openCamera(int width, int height) {
    if (ContextCompat.checkSelfPermission(getActivity(),
            Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) {
        FragmentCompat.requestPermissions(this, new String[] { Manifest.permission.CAMERA }, 1);
        return;
    }

    mCameraId = setUpCameraOutputs(width, height);

    //        configureTransform(width, height);

    //        ?CameraId???CameraIdCamera?CameraDevice
    Activity activity = getActivity();
    CameraManager manager = (CameraManager) activity.getSystemService(Context.CAMERA_SERVICE);
    try {
        if (!mSemaphore.tryAcquire(2500, TimeUnit.MILLISECONDS)) {
            throw new RuntimeException("Time out waiting to lock camera opening.");
        }
        //            ??CameraId
        //            ?CameraDeviceStateCallback??CameraDevice
        //            ?Handler?null?
        manager.openCamera(mCameraId, mStateCallback, mBackgroundHandler);
    } catch (CameraAccessException e) {
        e.printStackTrace();
    } catch (InterruptedException e) {
        throw new RuntimeException("Interrupted while trying to lock camera opening.", e);
    }
}

From source file:com.murrayc.galaxyzoo.app.SubjectFragment.java

private void doDownloadImage() {
    //We download the image from the remote server again,
    //even though we already have it in the ContentProvider,
    //available via the mUriImageStandard content: URI,
    //just to get it into the DownloadManager UI.
    //Unfortunately the DownloadManager rejects content: URIs.
    if (TextUtils.isEmpty(mUriStandardRemote)) {
        Log.error("doDownloadImage(): mUriStandardRemote was null.");
        return;/*from w w w. ja  va 2  s  .  c o  m*/
    }

    final Uri uri = Uri.parse(mUriStandardRemote);
    if (uri == null) {
        Log.error("doDownloadImage(): uri was null.");
        return;
    }

    final DownloadManager.Request request = new DownloadManager.Request(uri);
    request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);

    final Activity activity = getActivity();
    if (activity == null) {
        Log.error("doDownloadImage(): activity was null.");
        return;
    }

    final Object systemService = activity.getSystemService(Context.DOWNLOAD_SERVICE);
    if (systemService == null || !(systemService instanceof DownloadManager)) {
        Log.error("doDownloadImage(): Could not get DOWNLOAD_SERVICE.");
        return;
    }

    final DownloadManager downloadManager = (DownloadManager) systemService;
    downloadManager.enqueue(request);
}

From source file:com.flyingcrop.ScreenCaptureFragment.java

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    Activity activity = getActivity();
    mMediaProjectionManager = (MediaProjectionManager) activity
            .getSystemService(Context.MEDIA_PROJECTION_SERVICE);
    startScreenCapture();/*from  w  w w  .  ja v a2  s  . co m*/
}

From source file:com.example.camera2apidemo.Camera2Fragment.java

/**
 * Opens the camera specified by {@link Camera2Fragment#mCameraId}.
 *///from   w  w w  . ja  v  a 2  s.  c o m
private void openCamera(int width, int height) {
    if (ContextCompat.checkSelfPermission(getActivity(),
            Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) {
        FragmentCompat.requestPermissions(this, new String[] { Manifest.permission.CAMERA }, 1);
        return;
    }

    mCameraId = setUpCameraOutputs(width, height);

    //        ?CameraId???CameraIdCamera?CameraDevice
    Activity activity = getActivity();
    CameraManager manager = (CameraManager) activity.getSystemService(Context.CAMERA_SERVICE);
    try {
        if (!mSemaphore.tryAcquire(2500, TimeUnit.MILLISECONDS)) {
            throw new RuntimeException("Time out waiting to lock camera opening.");
        }
        //            ??CameraId
        //            ?CameraDeviceStateCallback??CameraDevice
        //            ?Handler?null?
        manager.openCamera(mCameraId, mStateCallback, mBackgroundHandler);
    } catch (CameraAccessException e) {
        e.printStackTrace();
    } catch (InterruptedException e) {
        throw new RuntimeException("Interrupted while trying to lock camera opening.", e);
    }
}

From source file:com.tzutalin.dlibtest.CameraConnectionFragment.java

/**
 * Opens the camera specified by {@link CameraConnectionFragment#cameraId}.
 *///w ww  .j  av a  2 s  .c o m
@SuppressLint("LongLogTag")
@DebugLog
private void openCamera(final int width, final int height) {
    Log.d(TAG, "width " + width + "height " + height);
    setUpCameraOutputs(width, height);
    configureTransform(width, height);
    final Activity activity = getActivity();
    final 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.");
        }
        if (ActivityCompat.checkSelfPermission(this.getActivity(),
                Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) {
            Timber.tag(TAG).w("checkSelfPermission CAMERA");
        }
        manager.openCamera("1", stateCallback, backgroundHandler);
        Timber.tag(TAG).d("open Camera");
    } catch (final CameraAccessException e) {
        Timber.tag(TAG).e("Exception!", e);
    } catch (final InterruptedException e) {
        throw new RuntimeException("Interrupted while trying to lock camera opening.", e);
    }
}

From source file:com.example.android.tflitecamerademo.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;//from  w  ww. ja va 2s. c o m
    } 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) {
        Log.e(TAG, "Failed to open Camera", e);
    } catch (InterruptedException e) {
        throw new RuntimeException("Interrupted while trying to lock camera opening.", e);
    }
}