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:net.zionsoft.obadiah.ui.fragments.TextFragment.java

@Override
public void onVersesSelectionChanged(boolean hasSelected) {
    if (hasSelected) {
        if (mActionMode != null)
            return;
        mActionMode = ((ActionBarActivity) getActivity()).startSupportActionMode(new ActionMode.Callback() {
            @Override/*from w w w . jav a  2 s.  c o m*/
            public boolean onCreateActionMode(ActionMode actionMode, Menu menu) {
                actionMode.getMenuInflater().inflate(R.menu.menu_text_selection_context, menu);
                return true;
            }

            @Override
            public boolean onPrepareActionMode(ActionMode actionMode, Menu menu) {
                return false;
            }

            @Override
            public boolean onActionItemClicked(ActionMode actionMode, MenuItem menuItem) {
                switch (menuItem.getItemId()) {
                case R.id.action_copy:
                    Analytics.trackUIEvent("copy");

                    final Activity activity = getActivity();
                    if (mClipboardManager == null) {
                        // noinspection deprecation
                        mClipboardManager = (ClipboardManager) activity
                                .getSystemService(Context.CLIPBOARD_SERVICE);
                    }
                    mClipboardManager.setText(
                            buildText(mVersePagerAdapter.getSelectedVerses(mVerseViewPager.getCurrentItem())));
                    Toast.makeText(activity, R.string.toast_verses_copied, Toast.LENGTH_SHORT).show();
                    actionMode.finish();
                    return true;
                case R.id.action_share:
                    Analytics.trackUIEvent("share");

                    startActivity(Intent.createChooser(
                            new Intent().setAction(Intent.ACTION_SEND).setType("text/plain").putExtra(
                                    Intent.EXTRA_TEXT,
                                    buildText(mVersePagerAdapter
                                            .getSelectedVerses(mVerseViewPager.getCurrentItem()))),
                            getResources().getText(R.string.text_share_with)));
                    actionMode.finish();
                    return true;
                default:
                    return false;
                }
            }

            @Override
            public void onDestroyActionMode(ActionMode actionMode) {
                if (actionMode != mActionMode)
                    return;
                mVersePagerAdapter.deselectVerses();
                mActionMode = null;
            }
        });
    } else {
        if (mActionMode != null)
            mActionMode.finish();
    }
}

From source file:com.irccloud.android.IRCCloudApplicationBase.java

public void onPause(final Activity context) {
    final ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    if (notifierSockerTimerTask != null)
        notifierSockerTimerTask.cancel();
    notifierSockerTimerTask = new TimerTask() {
        @Override/*from   ww  w  .j  a  v a2  s.  c  o  m*/
        public void run() {
            notifierSockerTimerTask = null;
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
                ActivityManager am = (ActivityManager) getSystemService(ACTIVITY_SERVICE);
                for (ActivityManager.RunningAppProcessInfo info : am.getRunningAppProcesses()) {
                    if (info.processName.equals(context.getPackageName())
                            && info.importance == ActivityManager.RunningAppProcessInfo.IMPORTANCE_FOREGROUND)
                        return;
                }
            }
            if (!conn.notifier && conn.getState() == NetworkConnection.STATE_CONNECTED) {
                conn.disconnect();
                if (ServersList.getInstance().count() < 1) {
                    Crashlytics.log(Log.DEBUG, "IRCCloud",
                            "No servers configured, not connecting notifier socket");
                    return;
                }
                if (!(Build.VERSION.SDK_INT >= Build.VERSION_CODES.N && cm.isActiveNetworkMetered() && cm
                        .getRestrictBackgroundStatus() == ConnectivityManager.RESTRICT_BACKGROUND_STATUS_ENABLED)) {
                    try {
                        Thread.sleep(1000);
                        conn.notifier = true;
                        conn.connect();
                    } catch (Exception e) {
                    }
                }
            }
        }
    };

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N && cm.isActiveNetworkMetered()
            && cm.getRestrictBackgroundStatus() == ConnectivityManager.RESTRICT_BACKGROUND_STATUS_ENABLED) {
        notifierTimer.schedule(notifierSockerTimerTask, 5000);
    } else {
        notifierTimer.schedule(notifierSockerTimerTask, 300000);
    }
}

From source file:de.schildbach.wallet.ui.RequestCoinsFragment.java

@Override
public void onAttach(final Activity activity) {
    super.onAttach(activity);

    this.activity = (AbstractWalletActivity) activity;
    this.application = (WalletApplication) activity.getApplication();
    this.nfcManager = (NfcManager) activity.getSystemService(Context.NFC_SERVICE);
    this.clipboardManager = (ClipboardManager) activity.getSystemService(Context.CLIPBOARD_SERVICE);
}

From source file:com.example.android.apprestrictionenforcer.StatusFragment.java

private void updateUi(Activity activity) {
    PackageManager packageManager = activity.getPackageManager();
    try {/*from w  w w.j  a v  a  2 s. com*/
        ApplicationInfo info = packageManager.getApplicationInfo(Constants.PACKAGE_NAME_APP_RESTRICTION_SCHEMA,
                PackageManager.GET_UNINSTALLED_PACKAGES);
        DevicePolicyManager devicePolicyManager = (DevicePolicyManager) activity
                .getSystemService(Activity.DEVICE_POLICY_SERVICE);
        if ((info.flags & ApplicationInfo.FLAG_INSTALLED) != 0) {
            if (!devicePolicyManager.isApplicationHidden(EnforcerDeviceAdminReceiver.getComponentName(activity),
                    Constants.PACKAGE_NAME_APP_RESTRICTION_SCHEMA)) {
                // The app is ready to enforce restrictions
                // This is unlikely to happen in this sample as unhideApp() handles it.
                mListener.onStatusUpdated();
            } else {
                // The app is installed but hidden in this profile
                mTextStatus.setText(R.string.status_not_activated);
                mButtonUnhide.setVisibility(View.VISIBLE);
            }
        } else {
            // Need to reinstall the sample app
            mTextStatus.setText(R.string.status_need_reinstall);
            mButtonUnhide.setVisibility(View.GONE);
        }
    } catch (PackageManager.NameNotFoundException e) {
        // Need to reinstall the sample app
        mTextStatus.setText(R.string.status_need_reinstall);
        mButtonUnhide.setVisibility(View.GONE);
    }
}

From source file:cc.mintcoin.wallet.ui.SendingAddressesFragment.java

@Override
public void onAttach(final Activity activity) {
    super.onAttach(activity);

    this.activity = (AbstractWalletActivity) activity;
    this.clipboardManager = (ClipboardManager) activity.getSystemService(Context.CLIPBOARD_SERVICE);
    this.loaderManager = getLoaderManager();
}

From source file:io.flutter.plugins.localauth.AuthenticationHelper.java

AuthenticationHelper(Activity activity, MethodCall call, AuthCompletionHandler completionHandler) {
    this.activity = activity;
    this.completionHandler = completionHandler;
    this.call = call;
    this.keyguardManager = (KeyguardManager) activity.getSystemService(Context.KEYGUARD_SERVICE);
    this.fingerprintManager = FingerprintManagerCompat.from(activity);
}

From source file:mintcoin.wallet.ui.WalletAddressFragment.java

@Override
public void onAttach(final Activity activity) {
    super.onAttach(activity);

    this.activity = activity;
    this.application = (WalletApplication) activity.getApplication();
    this.loaderManager = getLoaderManager();
    final NfcManager nfcManager = (NfcManager) activity.getSystemService(Context.NFC_SERVICE);
    this.nfcAdapter = nfcManager.getDefaultAdapter();
}

From source file:com.bonsai.btcreceive.ReceiveFragment.java

public void maybeShowKeyboard() {
    // Called by our parent when it would be good for us to
    // bring up the keyboard.

    mLogger.info("maybeShowKeyboard starting");

    // Does this ever happen?
    if (mFiatAmountEditText == null || mBTCAmountEditText == null)
        return;/*from  ww w .j  av  a  2  s.c  om*/

    // If the user has the value set already we don't want the
    // keyboard.
    if (mValueSet)
        return;

    mFiatAmountEditText.setFocusable(true);
    mFiatAmountEditText.setFocusableInTouchMode(true);
    mBTCAmountEditText.setFocusable(true);
    mBTCAmountEditText.setFocusableInTouchMode(true);

    Activity activity = getActivity();
    InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);

    if (mUserSetAmountFiat) {
        mLogger.info("maybeShowKeyboard fiat");
        imm.showSoftInput(mFiatAmountEditText, InputMethodManager.SHOW_IMPLICIT);
        mFiatAmountEditText.requestFocus();
    } else {
        mLogger.info("maybeShowKeyboard btc");
        imm.showSoftInput(mBTCAmountEditText, InputMethodManager.SHOW_IMPLICIT);
        mBTCAmountEditText.requestFocus();
    }
}

From source file:com.matthewmitchell.peercoin_android_wallet.ui.WalletAddressFragment.java

@Override
public void onAttach(final Activity activity) {
    super.onAttach(activity);

    this.activity = (WalletActivity) activity;
    this.application = (WalletApplication) activity.getApplication();
    this.loaderManager = getLoaderManager();
    final NfcManager nfcManager = (NfcManager) activity.getSystemService(Context.NFC_SERVICE);
    this.nfcAdapter = nfcManager.getDefaultAdapter();
}

From source file:org.mapsforge.applications.android.samples.location.MyLocationOverlay.java

/**
 * Constructs a new {@code MyLocationOverlay} with the given circle paints.
 * /* w  w  w  .  j av a2s  .com*/
 * @param activity
 *            a reference to the activity.
 * @param mapViewPosition
 *            the {@code MapViewPosition} whose location will be updated.
 * @param bitmap
 *            a bitmap to display at the current location (might be null).
 * @param circleFill
 *            the {@code Paint} used to fill the circle that represents the accuracy of the current location (might be null).
 * @param circleStroke
 *            the {@code Paint} used to stroke the circle that represents the accuracy of the current location (might be null).
 */
public MyLocationOverlay(Activity activity, MapViewPosition mapViewPosition, Bitmap bitmap, Paint circleFill,
        Paint circleStroke) {
    super();
    this.activity = activity;
    this.mapViewPosition = mapViewPosition;
    this.locationManager = (LocationManager) activity.getSystemService(Context.LOCATION_SERVICE);
    this.marker = new Marker(null, bitmap, 0, 0);
    this.circle = new Circle(null, 0, circleFill, circleStroke);
}