use of androidx.annotation.NonNull in project Douya by DreaminginCodeZH.
the class TabViewPagerAdapter method instantiateItem.
@NonNull
@Override
public Object instantiateItem(@NonNull ViewGroup container, int position) {
View view = mViews[position];
container.addView(view);
return view;
}
use of androidx.annotation.NonNull in project AntennaPod by AntennaPod.
the class ShareDialog method onCreateDialog.
@NonNull
@Override
public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
if (getArguments() != null) {
ctx = getActivity();
item = (FeedItem) getArguments().getSerializable(ARGUMENT_FEED_ITEM);
prefs = getActivity().getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE);
}
View content = View.inflate(ctx, R.layout.share_episode_dialog, null);
AlertDialog.Builder builder = new AlertDialog.Builder(ctx);
builder.setTitle(R.string.share_label);
builder.setView(content);
RadioGroup radioGroup = content.findViewById(R.id.share_dialog_radio_group);
radioGroup.setOnCheckedChangeListener((group, checkedId) -> checkBoxStartAt.setEnabled(checkedId != R.id.share_media_file_radio));
radioLinkToEpisode = content.findViewById(R.id.share_link_to_episode_radio);
radioMediaFile = content.findViewById(R.id.share_media_file_radio);
checkBoxStartAt = content.findViewById(R.id.share_start_at_timer_dialog);
setupOptions();
builder.setPositiveButton(R.string.share_label, (dialog, id) -> {
boolean includePlaybackPosition = checkBoxStartAt.isChecked();
if (radioLinkToEpisode.isChecked()) {
ShareUtils.shareFeedItemLinkWithDownloadLink(ctx, item, includePlaybackPosition);
} else if (radioMediaFile.isChecked()) {
ShareUtils.shareFeedItemFile(ctx, item.getMedia());
} else {
throw new IllegalStateException("Unknown share method");
}
prefs.edit().putBoolean(PREF_SHARE_EPISODE_START_AT, includePlaybackPosition).apply();
}).setNegativeButton(R.string.cancel_label, (dialog, id) -> dialog.dismiss());
return builder.create();
}
use of androidx.annotation.NonNull in project AntennaPod by AntennaPod.
the class SleepTimerDialog method onCreateDialog.
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
View content = View.inflate(getContext(), R.layout.time_dialog, null);
AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
builder.setTitle(R.string.sleep_timer_label);
builder.setView(content);
builder.setPositiveButton(R.string.close_label, null);
etxtTime = content.findViewById(R.id.etxtTime);
spTimeUnit = content.findViewById(R.id.spTimeUnit);
timeSetup = content.findViewById(R.id.timeSetup);
timeDisplay = content.findViewById(R.id.timeDisplay);
timeDisplay.setVisibility(View.GONE);
time = content.findViewById(R.id.time);
Button extendSleepFiveMinutesButton = content.findViewById(R.id.extendSleepFiveMinutesButton);
extendSleepFiveMinutesButton.setText(getString(R.string.extend_sleep_timer_label, 5));
Button extendSleepTenMinutesButton = content.findViewById(R.id.extendSleepTenMinutesButton);
extendSleepTenMinutesButton.setText(getString(R.string.extend_sleep_timer_label, 10));
Button extendSleepTwentyMinutesButton = content.findViewById(R.id.extendSleepTwentyMinutesButton);
extendSleepTwentyMinutesButton.setText(getString(R.string.extend_sleep_timer_label, 20));
extendSleepFiveMinutesButton.setOnClickListener(v -> {
if (controller != null) {
controller.extendSleepTimer(5 * 1000 * 60);
}
});
extendSleepTenMinutesButton.setOnClickListener(v -> {
if (controller != null) {
controller.extendSleepTimer(10 * 1000 * 60);
}
});
extendSleepTwentyMinutesButton.setOnClickListener(v -> {
if (controller != null) {
controller.extendSleepTimer(20 * 1000 * 60);
}
});
etxtTime.setText(SleepTimerPreferences.lastTimerValue());
etxtTime.postDelayed(() -> {
InputMethodManager imm = (InputMethodManager) getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(etxtTime, InputMethodManager.SHOW_IMPLICIT);
}, 100);
String[] spinnerContent = new String[] { getString(R.string.time_seconds), getString(R.string.time_minutes), getString(R.string.time_hours) };
ArrayAdapter<String> spinnerAdapter = new ArrayAdapter<>(getContext(), android.R.layout.simple_spinner_item, spinnerContent);
spinnerAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spTimeUnit.setAdapter(spinnerAdapter);
spTimeUnit.setSelection(SleepTimerPreferences.lastTimerTimeUnit());
CheckBox cbShakeToReset = content.findViewById(R.id.cbShakeToReset);
CheckBox cbVibrate = content.findViewById(R.id.cbVibrate);
CheckBox chAutoEnable = content.findViewById(R.id.chAutoEnable);
cbShakeToReset.setChecked(SleepTimerPreferences.shakeToReset());
cbVibrate.setChecked(SleepTimerPreferences.vibrate());
chAutoEnable.setChecked(SleepTimerPreferences.autoEnable());
cbShakeToReset.setOnCheckedChangeListener((buttonView, isChecked) -> SleepTimerPreferences.setShakeToReset(isChecked));
cbVibrate.setOnCheckedChangeListener((buttonView, isChecked) -> SleepTimerPreferences.setVibrate(isChecked));
chAutoEnable.setOnCheckedChangeListener((compoundButton, isChecked) -> SleepTimerPreferences.setAutoEnable(isChecked));
Button disableButton = content.findViewById(R.id.disableSleeptimerButton);
disableButton.setOnClickListener(v -> {
if (controller != null) {
controller.disableSleepTimer();
}
});
Button setButton = content.findViewById(R.id.setSleeptimerButton);
setButton.setOnClickListener(v -> {
if (!PlaybackService.isRunning) {
Snackbar.make(content, R.string.no_media_playing_label, Snackbar.LENGTH_LONG).show();
return;
}
try {
long time = Long.parseLong(etxtTime.getText().toString());
if (time == 0) {
throw new NumberFormatException("Timer must not be zero");
}
SleepTimerPreferences.setLastTimer(etxtTime.getText().toString(), spTimeUnit.getSelectedItemPosition());
if (controller != null) {
controller.setSleepTimer(SleepTimerPreferences.timerMillis());
}
closeKeyboard(content);
} catch (NumberFormatException e) {
e.printStackTrace();
Snackbar.make(content, R.string.time_dialog_invalid_input, Snackbar.LENGTH_LONG).show();
}
});
return builder.create();
}
use of androidx.annotation.NonNull in project AntennaPod by AntennaPod.
the class TagSettingsDialog method onCreateDialog.
@NonNull
@Override
public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
ArrayList<FeedPreferences> feedPreferencesList = (ArrayList<FeedPreferences>) getArguments().getSerializable(ARG_FEED_PREFERENCES);
Set<String> commonTags = new HashSet<>(feedPreferencesList.get(0).getTags());
for (FeedPreferences preference : feedPreferencesList) {
commonTags.retainAll(preference.getTags());
}
displayedTags = new ArrayList<>(commonTags);
displayedTags.remove(FeedPreferences.TAG_ROOT);
viewBinding = EditTagsDialogBinding.inflate(getLayoutInflater());
viewBinding.tagsRecycler.setLayoutManager(new GridLayoutManager(getContext(), 2));
viewBinding.tagsRecycler.addItemDecoration(new ItemOffsetDecoration(getContext(), 4));
adapter = new TagSelectionAdapter();
adapter.setHasStableIds(true);
viewBinding.tagsRecycler.setAdapter(adapter);
viewBinding.rootFolderCheckbox.setChecked(commonTags.contains(FeedPreferences.TAG_ROOT));
viewBinding.newTagButton.setOnClickListener(v -> addTag(viewBinding.newTagEditText.getText().toString().trim()));
loadTags();
viewBinding.newTagEditText.setThreshold(1);
viewBinding.newTagEditText.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
viewBinding.newTagEditText.showDropDown();
viewBinding.newTagEditText.requestFocus();
return false;
}
});
if (feedPreferencesList.size() > 1) {
viewBinding.commonTagsInfo.setVisibility(View.VISIBLE);
}
AlertDialog.Builder dialog = new AlertDialog.Builder(getContext());
dialog.setView(viewBinding.getRoot());
dialog.setTitle(R.string.feed_tags_label);
dialog.setPositiveButton(android.R.string.ok, (d, input) -> {
addTag(viewBinding.newTagEditText.getText().toString().trim());
updatePreferencesTags(feedPreferencesList, commonTags);
});
dialog.setNegativeButton(R.string.cancel_label, null);
return dialog.create();
}
use of androidx.annotation.NonNull in project AntennaPod by AntennaPod.
the class EpisodesFragment method onCreateView.
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
super.onCreateView(inflater, container, savedInstanceState);
View rootView = inflater.inflate(R.layout.pager_fragment, container, false);
Toolbar toolbar = rootView.findViewById(R.id.toolbar);
toolbar.setTitle(R.string.episodes_label);
toolbar.inflateMenu(R.menu.episodes);
displayUpArrow = getParentFragmentManager().getBackStackEntryCount() != 0;
if (savedInstanceState != null) {
displayUpArrow = savedInstanceState.getBoolean(KEY_UP_ARROW);
}
((MainActivity) getActivity()).setupToolbarToggle(toolbar, displayUpArrow);
ViewPager2 viewPager = rootView.findViewById(R.id.viewpager);
viewPager.setAdapter(new EpisodesPagerAdapter(this));
viewPager.setOffscreenPageLimit(2);
super.setupPagedToolbar(toolbar, viewPager);
// Give the TabLayout the ViewPager
tabLayout = rootView.findViewById(R.id.sliding_tabs);
new TabLayoutMediator(tabLayout, viewPager, (tab, position) -> {
switch(position) {
case POS_NEW_EPISODES:
tab.setText(R.string.new_episodes_label);
break;
case POS_ALL_EPISODES:
tab.setText(R.string.all_episodes_short_label);
break;
case POS_FAV_EPISODES:
tab.setText(R.string.favorite_episodes_label);
break;
default:
break;
}
}).attach();
// restore our last position
SharedPreferences prefs = getActivity().getSharedPreferences(TAG, Context.MODE_PRIVATE);
int lastPosition = prefs.getInt(PREF_LAST_TAB_POSITION, 0);
viewPager.setCurrentItem(lastPosition, false);
return rootView;
}
Aggregations