List of usage examples for android.app Activity getSystemService
@Override
public Object getSystemService(@ServiceName @NonNull String name)
From source file:com.androiddevbook.onyourbike.chapter10.helpers.Notify.java
public Notify(Activity activity) { CLASS_NAME = getClass().getName();//from w w w . j a va 2 s . co m manager = (NotificationManager) activity.getSystemService(Context.NOTIFICATION_SERVICE); context = activity; }
From source file:com.dwdesign.tweetings.fragment.BaseDialogFragment.java
public Object getSystemService(final String name) { final Activity activity = getActivity(); if (activity != null) return activity.getSystemService(name); return null;//www .ja va 2s .c om }
From source file:org.badreader.client.fragments.BaseFragment.java
protected void showKeyboard(final Activity _context, final EditText _edit) { final InputMethodManager imm = (InputMethodManager) _context.getSystemService(Context.INPUT_METHOD_SERVICE); if (android.os.Build.VERSION.SDK_INT < 11) { imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0); }/*from w w w.ja v a 2s .c o m*/ _edit.postDelayed(new Runnable() { public void run() { _edit.requestFocus(); imm.showSoftInput(_edit, 0); } }, 100); }
From source file:com.pyxistech.android.rabbitreminder.adaptaters.AlertListAdapter.java
public AlertListAdapter(Activity context, AlertList list) { inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); this.list = list; this.context = context; }
From source file:com.example.android.apprestrictionenforcer.StatusFragment.java
/** * Unhides the AppRestrictionSchema sample in case it is hidden in this profile. * * @param activity The activity//www. j a v a 2 s. c o m */ private void unhideApp(Activity activity) { DevicePolicyManager devicePolicyManager = (DevicePolicyManager) activity .getSystemService(Activity.DEVICE_POLICY_SERVICE); devicePolicyManager.setApplicationHidden(EnforcerDeviceAdminReceiver.getComponentName(activity), Constants.PACKAGE_NAME_APP_RESTRICTION_SCHEMA, false); Toast.makeText(activity, "Enabled the app", Toast.LENGTH_SHORT).show(); mListener.onStatusUpdated(); }
From source file:org.onebusaway.android.util.UIUtils.java
/** * Sets up the search view in the action bar *///from w w w.j a va 2 s .c o m public static void setupSearch(Activity activity, Menu menu) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { SearchManager searchManager = (SearchManager) activity.getSystemService(Context.SEARCH_SERVICE); final MenuItem searchMenu = menu.findItem(R.id.action_search); SearchView searchView = (SearchView) MenuItemCompat.getActionView(searchMenu); searchView.setSearchableInfo(searchManager.getSearchableInfo(activity.getComponentName())); // Close the keyboard and SearchView at same time when the back button is pressed searchView.setOnQueryTextFocusChangeListener(new View.OnFocusChangeListener() { @Override public void onFocusChange(View view, boolean queryTextFocused) { if (!queryTextFocused) { MenuItemCompat.collapseActionView(searchMenu); } } }); } }
From source file:org.pixmob.feedme.ui.SelectAccountDialog.java
@Override public Dialog onCreateDialog(Bundle savedInstanceState) { final Activity activity = getActivity(); final AccountManager accountManager = (AccountManager) activity.getSystemService(Context.ACCOUNT_SERVICE); // Get Google accounts which are registered on this device. final Account[] accounts = accountManager.getAccountsByType(GOOGLE_ACCOUNT); if (accounts.length == 0) { // Found no Google account: an error dialog is displayed. return new AlertDialog.Builder(activity).setIcon(android.R.drawable.ic_dialog_alert) .setTitle(R.string.error).setMessage(R.string.no_google_account_found) .setPositiveButton(android.R.string.ok, null).create(); }/*from ww w.ja va 2 s . c o m*/ // Sort accounts by name. final String[] accountNames = new String[accounts.length]; for (int i = 0; i < accountNames.length; ++i) { accountNames[i] = accounts[i].name; } Arrays.sort(accountNames); // The current account is selected by default. int checkedIndex = -1; if (previousAccount != null) { for (int i = 0; checkedIndex == -1 && i < accountNames.length; ++i) { if (accountNames[i].equals(previousAccount)) { checkedIndex = i; } } } return new AlertDialog.Builder(activity).setTitle(R.string.select_google_account) .setSingleChoiceItems(accountNames, checkedIndex, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { final OnAccountSelectedListener l = listener != null ? listener.get() : null; if (l != null) { l.onAccountSelected(accountNames[which]); } dismiss(); } }).create(); }
From source file:com.achep.acdisplay.ui.fragments.PocketFragment.java
@Override public void onAttach(Activity activity) { super.onAttach(activity); mSensorManager = (SensorManager) activity.getSystemService(Context.SENSOR_SERVICE); mProximitySensor = mSensorManager.getDefaultSensor(Sensor.TYPE_PROXIMITY); mProximityAvailable = mProximitySensor != null; if (mProximityAvailable) { mMaximumRange = mProximitySensor.getMaximumRange(); }/*w ww . j a v a 2 s . c o m*/ }
From source file:net.eledge.android.europeana.gui.fragment.RecordDetailsFragment.java
@TargetApi(Build.VERSION_CODES.HONEYCOMB) private void setupClipboardAction(ListView mListView) { mListView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() { @Override/*from ww w. j a va 2s. c o m*/ public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) { RecordView record = mRecordViewAdapter.getItem(position); Activity activity = RecordDetailsFragment.this.getActivity(); ClipboardManager clipboard = (ClipboardManager) activity .getSystemService(Context.CLIPBOARD_SERVICE); clipboard .setPrimaryClip( ClipData.newPlainText(GuiUtils.getString(getActivity(), record.getLabel()), StringUtils.join( record.getValues(recordController.record, (EuropeanaApplication) getActivity().getApplication()), ";"))); GuiUtils.toast(activity, R.string.msg_copied2clipboard); return true; } }); }
From source file:org.paulrogers.android.retrofittest.MainActivity.java
/** * This method is used to hide a keyboard after a user has * finished typing the url.// w ww . j a v a 2 s. c o m */ public void hideKeyboard(Activity activity, IBinder windowToken) { InputMethodManager mgr = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE); mgr.hideSoftInputFromWindow(windowToken, 0); }