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.android.calendar.event.CreateEventDialogFragment.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    final Activity activity = getActivity();
    final LayoutInflater layoutInflater = (LayoutInflater) activity
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View view = layoutInflater.inflate(R.layout.create_event_dialog, null);

    mColor = view.findViewById(R.id.color);
    mCalendarName = (TextView) view.findViewById(R.id.calendar_name);
    mAccountName = (TextView) view.findViewById(R.id.account_name);

    mEventTitle = (EditText) view.findViewById(R.id.event_title);
    mEventTitle.addTextChangedListener(this);

    mDate = (TextView) view.findViewById(R.id.event_day);
    if (mDateString != null) {
        mDate.setText(mDateString);//from  w ww.j a  va  2  s . com
    }

    mAlertDialog = new AlertDialog.Builder(activity).setTitle(R.string.new_event_dialog_label).setView(view)
            .setPositiveButton(R.string.create_event_dialog_save, new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    createAllDayEvent();
                    dismiss();
                }
            }).setNeutralButton(R.string.edit_label, new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    mController.sendEventRelatedEventWithExtraWithTitleWithCalendarId(this,
                            EventType.CREATE_EVENT, -1, mDateInMillis, mDateInMillis + DateUtils.DAY_IN_MILLIS,
                            0, 0, CalendarController.EXTRA_CREATE_ALL_DAY, -1, mEventTitle.getText().toString(),
                            mCalendarId);
                    dismiss();
                }
            }).setNegativeButton(android.R.string.cancel, null).create();

    return mAlertDialog;
}

From source file:com.kncwallet.wallet.ui.WalletAddressFragment.java

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

    this.activity = (FragmentActivity) activity;
    this.application = (WalletApplication) activity.getApplication();
    this.prefs = PreferenceManager.getDefaultSharedPreferences(activity);
    this.nfcManager = (NfcManager) activity.getSystemService(Context.NFC_SERVICE);
}

From source file:de.dknapps.pswgendroid.ServiceDetailFragment.java

/**
 * Generiert das Passwort und kopiert es in die Zwischenablage.
 * /* www  .j av  a2s  .co  m*/
 * FIXME dkn Die callingActivity kann durch getActivity() ersetzt werden.
 */
public void onClickButtonCopyPassword(final Activity callingActivity, final View buttonOpenUrl) {
    try {
        String password = getValidatedOrGeneratedPassword();
        ClipboardManager clipboard = (ClipboardManager) callingActivity
                .getSystemService(Context.CLIPBOARD_SERVICE);
        clipboard.setPrimaryClip(ClipData.newPlainText(null, password));
    } catch (Exception e) {
        PswGenAdapter.handleThrowable(callingActivity, e);
    }
}

From source file:com.ohso.util.ImageHandler.java

public ImageHandler(Activity activity) {
    MEMORY_CLASS = ((ActivityManager) activity.getSystemService(Context.ACTIVITY_SERVICE)).getMemoryClass();
    MEMORY_CACHE_SIZE = 1024 * 1024 * MEMORY_CLASS / 8; // Use 1/8 the available memory
    mMemoryCache = new LruCache<String, Bitmap>(MEMORY_CACHE_SIZE) {
        protected int sizeOf(String key, Bitmap bitmap) {
            return bitmap.getRowBytes() * bitmap.getHeight();
        }/*from  w ww .jav  a2s.c om*/
    };
    File cacheDir = new File(activity.getCacheDir(), "thumbnails");
    try {
        mDiskCache = DiskLruCache.open(cacheDir, 1, 1, DISK_CACHE_SIZE);
    } catch (IOException e) {
        e.printStackTrace();
    }
    mPixelSize = scaledDIP(IMAGE_DIMENSIONS);
    mPlaceholderParams = new RelativeLayout.LayoutParams((int) mPixelSize, (int) mPixelSize);
    mPlaceholderParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
    mPlaceholderParams.topMargin = 0;
}

From source file:it.uniroma3.android.gpstracklogger.adapters.AdapterTrack.java

public AdapterTrack(Activity activity, int textViewResourceId, List<Track> tracks) {
    super(activity, textViewResourceId, tracks);
    try {//from w  w w .j  a  v a  2  s  . com
        this.activity = activity;
        this.lTrack = tracks;
        inflater = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    } catch (Exception e) {

    }
}

From source file:com.example.android.screencapture.ScreenCaptureFragment.java

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    Activity activity = getActivity();
    DisplayMetrics metrics = new DisplayMetrics();
    activity.getWindowManager().getDefaultDisplay().getMetrics(metrics);
    mScreenDensity = metrics.densityDpi;
    mMediaProjectionManager = (MediaProjectionManager) activity
            .getSystemService(Context.MEDIA_PROJECTION_SERVICE);
}

From source file:ch.jeda.platform.android.SensorManager.java

@Override
public void onAttach(final Activity activity) {
    super.onAttach(activity);
    this.sensorMap.clear();
    this.sensorInfoMap.clear();
    this.sensorListenerMap.clear();
    this.imp = (android.hardware.SensorManager) activity.getSystemService(Activity.SENSOR_SERVICE);
    this.checkAdd(SensorType.ACCELERATION, 1f, 0f, this.imp.getDefaultSensor(Sensor.TYPE_ACCELEROMETER));
    this.checkAdd(SensorType.GRAVITY, 1f, 0f, this.imp.getDefaultSensor(Sensor.TYPE_GRAVITY));
    this.checkAdd(SensorType.LIGHT, 1f, 0f, this.imp.getDefaultSensor(Sensor.TYPE_LIGHT));
    this.checkAdd(SensorType.LINEAR_ACCELERATION, 1f, 0f,
            this.imp.getDefaultSensor(Sensor.TYPE_LINEAR_ACCELERATION));
    // Android returns values in micro Tesla
    this.checkAdd(SensorType.MAGNETIC_FIELD, 1e-6f, 0f, this.imp.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD));
    // Android returns value in hekto Pascal
    this.checkAdd(SensorType.PRESSURE, 100f, 0f, this.imp.getDefaultSensor(Sensor.TYPE_PRESSURE));
    // Android returns value in centimeter
    this.checkAdd(SensorType.PROXIMITY, 0.01f, 0f, this.imp.getDefaultSensor(Sensor.TYPE_PROXIMITY));
    // Android returns value in degrees Celcius
    this.checkAdd(SensorType.TEMPERATURE, 1f, -273.15f, this.imp.getDefaultSensor(Sensor.TYPE_TEMPERATURE));
}

From source file:com.feathercoin.wallet.feathercoin.ui.RequestCoinsFragment.java

@SuppressLint("InlinedApi")
@Override/*  www .  ja  va  2  s  .c  o  m*/
public void onAttach(final Activity activity) {
    super.onAttach(activity);
    this.activity = (AbstractWalletActivity) activity;
    application = (WalletApplication) activity.getApplication();

    nfcManager = activity.getSystemService(Context.NFC_SERVICE);
    clipboardManager = (android.text.ClipboardManager) activity.getSystemService(Context.CLIPBOARD_SERVICE);
}

From source file:de.vanita5.twittnuker.fragment.support.BaseSupportListFragment.java

public final Object getSystemService(final String name) {
    final Activity activity = getActivity();
    if (activity != null)
        return activity.getSystemService(name);
    return null;/*from  w ww  .  j  a  va  2  s.c om*/
}

From source file:com.physicaroid.pocketduino.cordova.PocketDuino.java

private void getDeviceName(CallbackContext callbackContext) {
    Activity activity = cordova.getActivity();
    UsbManager mUsbManager = (UsbManager) activity.getSystemService(Context.USB_SERVICE);
    HashMap<String, UsbDevice> map = mUsbManager.getDeviceList();
    Iterator<UsbDevice> it = map.values().iterator();
    while (it.hasNext()) {
        UsbDevice device = it.next();/*  ww w.ja  v  a2 s  .  c  o m*/
        // use device info
        Log.v(POCKETDUINO, "!!!--- USB Device Name ---!!!");
        Log.v(POCKETDUINO, device.getDeviceName());
        Log.v(POCKETDUINO, "!!!--- USB Device Product ID ---!!!");
        Log.v(POCKETDUINO, Integer.toString(device.getProductId()));
        Log.v(POCKETDUINO, "!!!--- USB Device Vendor ID ---!!!");
        Log.v(POCKETDUINO, Integer.toString(device.getVendorId()));
        Log.v(POCKETDUINO, "!!!--- USB Device Hash Code ---!!!");
        Log.v(POCKETDUINO, Integer.toString(device.hashCode()));
    }
}