private void requestChangeBatteryOptimizations () { if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { Intent intent = new Intent(); String packageName = getActivity().getPackageName(); PowerManager pm = (PowerManager) getActivity().getSystemService(Context.POWER_SERVICE); if (pm.isIgnoringBatteryOptimizations(packageName)) intent.setAction(Settings.ACTION_IGNORE_BATTERY_OPTIMIZATION_SETTINGS); else { intent.setAction(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS); intent.setData(Uri.parse("package:" + packageName)); } getActivity().startActivity(intent); } }
@Override public void onPreExecute() { ((AnkiActivity) getActivity()).showProgressBar(); final InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(getView().getWindowToken(), 0); }
LayoutInflater inflater = (LayoutInflater) getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE); row = inflater.inflate(R.layout.wifi_scanner_list_item, parent, false);
@SuppressLint("NewApi") @Override public View getView(int position, View convertView, ViewGroup parent) { View row = convertView; ActionHolder holder; if (row == null) { LayoutInflater inflater = (LayoutInflater) getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE); row = inflater.inflate(R.layout.actions_list_item, parent, false); if (getActivity().getSharedPreferences("THEME", 0).getBoolean("isDark", false)) row.setBackgroundResource(R.drawable.card_background_dark); holder = new ActionHolder(); holder.icon = (ImageView) (row != null ? row.findViewById(R.id.actionIcon) : null); holder.name = (TextView) (row != null ? row.findViewById(R.id.actionName) : null); holder.description = (TextView) (row != null ? row.findViewById(R.id.actionDescription) : null); if (row != null) row.setTag(holder); } else holder = (ActionHolder) row.getTag(); Plugin action = mAvailable.get(position); holder.icon.setImageResource(action.getIconResourceId()); holder.name.setText(getString(action.getName())); holder.description.setText(getString(action.getDescription())); return row; }
.getSystemService(Context.LAYOUT_INFLATER_SERVICE); row = inflater.inflate(R.layout.target_list_item, parent, false);
v.setBackgroundColor(ContextCompat.getColor(getActivity(), R.color.background_window)); mWifiManager = (WifiManager) getActivity().getSystemService(Context.WIFI_SERVICE); mClipboard = (ClipboardManager) getActivity().getSystemService(Context.CLIPBOARD_SERVICE); mWifiMatcher = new WirelessMatcher(getResources().openRawResource(R.raw.alice)); mScanReceiver = new ScanReceiver();
@Override public void onFocusChange(View v, boolean hasFocus) { if (hasFocus) { InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE); imm.showSoftInput(hexEditText, InputMethodManager.SHOW_IMPLICIT); } } });
private void toggleSoftKeyboard(boolean visible) { InputMethodManager imm = (InputMethodManager) getActivity().getSystemService( Context.INPUT_METHOD_SERVICE); if (visible) { imm.showSoftInput(mEditText, InputMethodManager.SHOW_IMPLICIT); } else { imm.hideSoftInputFromWindow(mEditText.getWindowToken(), 0); } } }
public void hideKeyboard() { InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(mFolderNameEditText.getWindowToken(), 0); }
private void performCopyCommand(String label, String command) { // Check we still in a valid context if (getActivity() == null) { return; } // Copy to clipboard ClipboardManager clipboard = (ClipboardManager) getActivity().getSystemService( Context.CLIPBOARD_SERVICE); ClipData clip = ClipData.newPlainText(label, command); clipboard.setPrimaryClip(clip); // Show a confirmation message final String msg = getString(R.string.download_commands_dialog_copy_message, label); Toast.makeText(getContext(), msg, Toast.LENGTH_SHORT).show(); } }
@SuppressWarnings("ConstantConditions") private Observable<Request> doRequestDownload(Integer requestCode) { return SafeObservable.fromNullCallable(() -> { if (getActivity() != null) { Request request = new Request(); request.mRequestCode = requestCode; ConnectivityManager cm = (ConnectivityManager) getActivity() .getSystemService(Activity.CONNECTIVITY_SERVICE); NetworkInfo ni = cm.getActiveNetworkInfo(); if (ni == null) { request.mStatus = 1; return request; } if (ConnectivityManagerCompat.isActiveNetworkMetered(cm) || AndroidHelper.isRoaming(cm)) { request.mStatus = 2; return request; } return request; } throw new IllegalStateException(); }) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()); }
@Override public boolean onTouch(View v, MotionEvent event) { if (v != hexEditText && hexEditText.hasFocus()) { hexEditText.clearFocus(); InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(hexEditText.getWindowToken(), 0); hexEditText.clearFocus(); return true; } return false; } };
@Override public void onColorChanged(int newColor) { color = newColor; if (newColorPanel != null) { newColorPanel.setColor(newColor); } if (!fromEditText && hexEditText != null) { setHex(newColor); if (hexEditText.hasFocus()) { InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(hexEditText.getWindowToken(), 0); hexEditText.clearFocus(); } } fromEditText = false; }
private void clearData() { TcaDb.resetDb(mContext); SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(mContext); sharedPrefs.edit().clear().apply(); // Remove all notifications that are currently shown NotificationManager notificationManager = (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE); if (notificationManager != null) { notificationManager.cancelAll(); } int readCalendar = ContextCompat.checkSelfPermission( requireActivity(), Manifest.permission.READ_CALENDAR); int writeCalendar = ContextCompat.checkSelfPermission( requireActivity(), Manifest.permission.WRITE_CALENDAR); // Delete local calendar Utils.setSetting(mContext, Const.SYNC_CALENDAR, false); if (readCalendar == PackageManager.PERMISSION_GRANTED && writeCalendar == PackageManager.PERMISSION_GRANTED) { CalendarController.deleteLocalCalendar(mContext); } }
private void vibrationInit(List<RecyclerViewItem> items) { final Vibrator vibrator = (Vibrator) Objects.requireNonNull(getActivity()) .getSystemService(Context.VIBRATOR_SERVICE); final int min = mVibration.getMin(); int max = mVibration.getMax(); final float offset = (max - min) / 100f; SeekBarView vibration = new SeekBarView(); vibration.setTitle(getString(R.string.vibration_strength)); vibration.setUnit("%"); vibration.setProgress(Math.round((mVibration.get() - min) / offset)); vibration.setOnSeekBarListener(new SeekBarView.OnSeekBarListener() { @Override public void onStop(SeekBarView seekBarView, int position, String value) { mVibration.setVibration(Math.round(position * offset + min), getActivity()); getHandler().postDelayed(() -> { if (vibrator != null) { vibrator.vibrate(300); } }, 250); } @Override public void onMove(SeekBarView seekBarView, int position, String value) { } }); items.add(vibration); }