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:org.quantumbadger.redreader.views.SearchListingHeader.java

public SearchListingHeader(final Activity parentActivity, final SearchPostListURL url) {
    super(parentActivity);
    mUrl = url;//from   w w w. j av a  2 s.co  m

    LayoutInflater layoutInflater = (LayoutInflater) parentActivity
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    layoutInflater.inflate(R.layout.search_listing_header, this, true);

    mQuery = (EditText) findViewById(R.id.search_listing_header_query_editText);
    mQuery.setText(url.query);
    mQuery.setImeOptions(EditorInfo.IME_ACTION_NEXT);

    mSubreddit = (EditText) findViewById(R.id.search_listing_header_sub_editText);
    // null and "all" are isomorphic; but SearchPostListURL takes null
    if (url.subreddit == null) {
        mSubreddit.setText("all");
    } else {
        mSubreddit.setText(url.subreddit);
    }

    TextView.OnEditorActionListener onEnter = new TextView.OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            performSearch(parentActivity, mSubreddit, mQuery);
            return true;
        }
    };
    mSubreddit.setImeOptions(EditorInfo.IME_ACTION_SEARCH);
    mSubreddit.setOnEditorActionListener(onEnter);

    mSearchButton = (Button) findViewById(R.id.search_listing_header_search);
    mSearchButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            performSearch(parentActivity, mSubreddit, mQuery);
        }
    });
}

From source file:org.sufficientlysecure.keychain.ui.base.CryptoOperationFragment.java

public void hideKeyboard() {
    Activity activity = getActivity();
    if (activity == null) {
        return;//  w w  w. j a v  a2s.co  m
    }
    InputMethodManager inputManager = (InputMethodManager) activity
            .getSystemService(Context.INPUT_METHOD_SERVICE);

    // check if no view has focus
    View v = activity.getCurrentFocus();
    if (v == null)
        return;

    inputManager.hideSoftInputFromWindow(v.getWindowToken(), 0);
}

From source file:com.breadwallet.tools.manager.BRNotificationManager.java

public static void sendNotification(Activity ctx, int icon, String title, String message, int mId) {
    if (ctx == null)
        return;//from w  w w.  ja  v  a  2s . c  o  m
    android.support.v4.app.NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(ctx)
            .setSmallIcon(icon).setContentTitle(title).setContentText(message);
    // Creates an explicit intent for an Activity in your app
    Intent resultIntent = new Intent(ctx, MainActivity.class);

    // The stack builder object will contain an artificial back stack for the
    // started Activity.
    // This ensures that navigating backward from the Activity leads out of
    // your application to the Home screen.
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(ctx);
    // Adds the back stack for the Intent (but not the Intent itself)
    stackBuilder.addParentStack(MainActivity.class);
    // Adds the Intent that starts the Activity to the top of the stack
    stackBuilder.addNextIntent(resultIntent);
    PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
    mBuilder.setContentIntent(resultPendingIntent);
    NotificationManager mNotificationManager = (NotificationManager) ctx
            .getSystemService(Context.NOTIFICATION_SERVICE);
    // mId allows you to update the notification later on.
    mNotificationManager.notify(mId, mBuilder.build());
}

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

/**
 * Kopiert die Login-Informationen in die Zwischenablage.
 * //  ww  w .j  a  v  a2 s.  c o m
 * FIXME dkn Die callingActivity kann durch getActivity() ersetzt werden.
 */
private void copyLoginInfo(final Activity callingActivity) {
    ClipboardManager clipboard = (ClipboardManager) callingActivity.getSystemService(Context.CLIPBOARD_SERVICE);
    clipboard.setPrimaryClip(ClipData.newPlainText(null, currentServiceInfo.getLoginInfo()));
}

From source file:com.yanzhenjie.album.mvp.ActivitySource.java

@Override
void closeInputMethod() {
    Activity activity = getHost();
    View focusView = activity.getCurrentFocus();
    if (focusView != null) {
        InputMethodManager manager = (InputMethodManager) activity
                .getSystemService(Context.INPUT_METHOD_SERVICE);
        if (manager != null) {
            manager.hideSoftInputFromWindow(focusView.getWindowToken(), 0);
        }//w w  w.ja  va  2s.com
    }
}

From source file:com.jetheis.android.makeitrain.fragment.ReportDialogFragment.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    final Activity activity = getActivity();
    final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(activity);

    AlertDialog.Builder reportBuilder;//from   w w  w .  j ava  2  s . co  m

    LayoutInflater reportInflater = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View reportLayout = reportInflater.inflate(R.layout.report_dialog_fragment, null);

    int spent = preferences.getInt(activity.getString(R.string.pref_total_spent), 0);

    NumberFormat nf = NumberFormat.getCurrencyInstance();
    String spentDisplay = nf.format(spent);

    TextView reportText = (TextView) reportLayout.findViewById(R.id.report_dialog_fragment_text_view);
    reportText.setText(activity.getString(R.string.total_spent, spentDisplay));

    reportBuilder = new AlertDialog.Builder(activity);
    reportBuilder.setView(reportLayout);
    reportBuilder.setTitle(R.string.your_spending_report);
    reportBuilder.setPositiveButton(R.string.im_so_cool, null);
    reportBuilder.setNegativeButton(R.string.reset, new DialogInterface.OnClickListener() {

        public void onClick(DialogInterface dialog, int item) {
            dialog.dismiss();
            Editor editor = preferences.edit();
            editor.putInt(activity.getString(R.string.pref_total_spent), 0);
            editor.commit();
        }

    });

    return reportBuilder.create();
}

From source file:in.rab.ordboken.Ordboken.java

public SearchView initSearchView(Activity activity, Menu menu, String query, Boolean focus) {
    SearchManager searchManager = (SearchManager) activity.getSystemService(Context.SEARCH_SERVICE);
    SearchView searchView = (SearchView) activity.findViewById(R.id.mySearchView);

    searchView.setSearchableInfo(/* ww w.j av  a 2s  .c o m*/
            searchManager.getSearchableInfo(new ComponentName(activity, MainActivity.class)));

    // Hack to get the magnifying glass icon inside the EditText
    searchView.setIconifiedByDefault(true);
    searchView.setIconified(false);

    // Hack to get rid of the collapse button
    searchView.onActionViewExpanded();

    if (!focus) {
        searchView.clearFocus();
    }

    // searchView.setSubmitButtonEnabled(true);
    searchView.setQueryRefinementEnabled(true);

    if (query != null) {
        searchView.setQuery(query, false);
    }

    return searchView;
}

From source file:com.google.android.apps.mytracks.util.Api11Adapter.java

@Override
public void configureSearchWidget(Activity activity, final MenuItem menuItem) {
    SearchManager searchManager = (SearchManager) activity.getSystemService(Context.SEARCH_SERVICE);
    SearchView searchView = (SearchView) menuItem.getActionView();
    searchView.setSearchableInfo(searchManager.getSearchableInfo(activity.getComponentName()));
    searchView.setQueryRefinementEnabled(true);
}

From source file:org.sufficientlysecure.keychain.ui.adapter.SubkeysAddedAdapter.java

public SubkeysAddedAdapter(Activity activity, List<SaveKeyringParcel.SubkeyAdd> data, boolean newKeyring) {
    super(activity, -1, data);
    mActivity = activity;//from w ww.  j a  v a 2  s .  c om
    mInflater = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    mNewKeyring = newKeyring;
}

From source file:com.airg.android.permission.sample.DangerousFragment.java

@SuppressWarnings("ResourceType")
private void onLocationPermissionGranted() {
    latitude.setText(R.string.loading);//from w  w  w .  j ava2 s.c om
    longitude.setText(R.string.loading);

    final Activity activity = getActivity();
    gps = (LocationManager) activity.getSystemService(Context.LOCATION_SERVICE);
    updateLocation(gps.getLastKnownLocation(LocationManager.NETWORK_PROVIDER));
    gps.requestSingleUpdate(LocationManager.GPS_PROVIDER, this, null);
}