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:de.baumann.hhsmoodle.helper.helper_main.java

public static void showKeyboard(final Activity activity, final EditText editText) {
    new Handler().postDelayed(new Runnable() {
        public void run() {
            InputMethodManager imm = (InputMethodManager) activity
                    .getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.showSoftInput(editText, InputMethodManager.SHOW_IMPLICIT);
            editText.setSelection(editText.length());
        }/* w ww .  ja v  a2  s  .  c o  m*/
    }, 200);
}

From source file:com.xabber.android.ui.activity.ChatActivity.java

public static void hideKeyboard(Activity activity) {
    // Check if no view has focus:
    View view = activity.getCurrentFocus();
    if (view != null) {
        InputMethodManager inputManager = (InputMethodManager) activity
                .getSystemService(Context.INPUT_METHOD_SERVICE);
        inputManager.hideSoftInputFromWindow(view.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
    }//  ww w. j  ava2  s. co  m
}

From source file:com.vinexs.tool.Utility.java

public static void hideKeyBroad(Activity activity) {
    try {//www .  j  av  a  2s .c  o  m
        View currentView = activity.getCurrentFocus();
        if (currentView == null) {
            throw new Exception("Cannot get current focus");
        }
        InputMethodManager inputMethodManager = (InputMethodManager) activity
                .getSystemService(Context.INPUT_METHOD_SERVICE);
        inputMethodManager.hideSoftInputFromWindow(currentView.getWindowToken(),
                InputMethodManager.HIDE_NOT_ALWAYS);
    } catch (Exception ignored) {
    }
}

From source file:com.coinblesk.client.utils.UIUtils.java

private static void disableBluetooth(Activity activity) {
    BluetoothManager bm = (BluetoothManager) activity.getSystemService(Context.BLUETOOTH_SERVICE);
    BluetoothAdapter mBluetoothAdapter = bm.getAdapter();
    if (mBluetoothAdapter != null && mBluetoothAdapter.isEnabled()) {
        mBluetoothAdapter.disable();/*w w  w.j av  a2  s.c o  m*/
        Intent exchangeRateChanged = new Intent(Constants.EXCHANGE_RATE_CHANGED_ACTION);
        LocalBroadcastManager.getInstance(activity).sendBroadcast(exchangeRateChanged);
    }
}

From source file:com.tlongdev.bktf.util.Utility.java

public static void hideKeyboard(Activity activity) {
    if (activity == null) {
        return;//from w  ww  .j a  v a2s . c om
    }

    //overkill?
    View view = activity.getCurrentFocus();
    if (view != null) {
        InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
    }

    activity.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
}

From source file:com.andrewshu.android.reddit.common.Common.java

public static boolean shouldLoadThumbnails(Activity activity, RedditSettings settings) {
    //check for wifi connection and wifi thumbnail setting
    boolean thumbOkay = true;
    if (settings.isLoadThumbnailsOnlyWifi()) {
        thumbOkay = false;//  w w  w . j a va2 s .c o  m
        ConnectivityManager connMan = (ConnectivityManager) activity
                .getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo netInfo = connMan.getActiveNetworkInfo();
        if (netInfo != null && netInfo.getType() == ConnectivityManager.TYPE_WIFI && netInfo.isConnected()) {
            thumbOkay = true;
        }
    }
    return settings.isLoadThumbnails() && thumbOkay;
}

From source file:com.mezcaldev.hotlikeme.ChatActivity.java

public static void hideSoftKeyboard(Activity activity) {
    InputMethodManager inputMethodManager = (InputMethodManager) activity
            .getSystemService(Activity.INPUT_METHOD_SERVICE);

    if (activity.getCurrentFocus() != null) {
        inputMethodManager.hideSoftInputFromWindow(activity.getCurrentFocus().getWindowToken(), 0);
    }//w w  w  .j  ava 2  s  .  c  o  m

}

From source file:com.stockita.popularmovie.utility.Utilities.java

/**
 * Hide the keyboard/*from w ww.j  a  v  a2 s.  c  om*/
 */
public static void hideKeyboard(Activity activity) {
    View view = activity.getCurrentFocus();
    if (view != null) {
        InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
    }
}

From source file:de.azapps.mirakel.helper.TaskDialogHelpers.java

public static void playbackFile(final Activity context, final FileMirakel file, final boolean loud) {
    final MediaPlayer mPlayer = new MediaPlayer();
    final AudioManager am = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
    if (!loud) {//from   w  ww .  j a  va2  s . c om
        am.setSpeakerphoneOn(false);
        am.setMode(AudioManager.MODE_IN_CALL);
        context.setVolumeControlStream(AudioManager.STREAM_VOICE_CALL);
    }
    try {
        mPlayer.reset();
        if (!loud) {
            mPlayer.setAudioStreamType(AudioManager.STREAM_VOICE_CALL);
        }
        mPlayer.setDataSource(file.getFileStream(context).getFD());
        mPlayer.prepare();
        mPlayer.start();
        mPlayer.setOnCompletionListener(new OnCompletionListener() {
            @Override
            public void onCompletion(final MediaPlayer mp) {
                audio_playback_dialog.dismiss();
            }
        });
        am.setMode(AudioManager.MODE_NORMAL);
        audio_playback_playing = true;
    } catch (final IOException e) {
        Log.e(TAG, "prepare() failed");
    }
    audio_playback_dialog = new AlertDialog.Builder(context).setTitle(R.string.audio_playback_title)
            .setPositiveButton(R.string.audio_playback_pause, null)
            .setNegativeButton(R.string.audio_playback_stop, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(final DialogInterface dialog, final int which) {
                    mPlayer.release();
                }
            }).setOnCancelListener(new OnCancelListener() {
                @Override
                public void onCancel(final DialogInterface dialog) {
                    mPlayer.release();
                    dialog.cancel();
                }
            }).create();
    audio_playback_dialog.setOnShowListener(new OnShowListener() {
        @Override
        public void onShow(final DialogInterface dialog) {
            final Button button = ((AlertDialog) dialog).getButton(DialogInterface.BUTTON_POSITIVE);
            button.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(final View v) {
                    if (audio_playback_playing) {
                        button.setText(R.string.audio_playback_play);
                        mPlayer.pause();
                        audio_playback_playing = false;
                    } else {
                        button.setText(R.string.audio_playback_pause);
                        mPlayer.start();
                        audio_playback_playing = true;
                    }
                }
            });
        }
    });
    audio_playback_dialog.show();
}

From source file:com.apptentive.android.sdk.util.Util.java

public static void showSoftKeyboard(Activity activity, View target) {
    if (activity != null && activity.getCurrentFocus() != null) {
        InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.showSoftInput(target, 0);// w  w  w  .j a  va2 s  .  c o  m
    }
}