Null safety cleanups.

parent 8ecec8bc
......@@ -70,6 +70,7 @@ import static android.support.v4.app.NotificationCompat.PRIORITY_LOW;
import static android.support.v4.app.NotificationCompat.PRIORITY_MIN;
import static android.support.v4.app.NotificationCompat.VISIBILITY_SECRET;
import static android.support.v4.content.ContextCompat.getColor;
import static java.util.Objects.requireNonNull;
import static org.briarproject.bramble.util.StringUtils.isNullOrEmpty;
import static org.briarproject.bramble.util.StringUtils.toHexString;
import static org.briarproject.briar.android.activity.BriarActivity.GROUP_ID;
......@@ -119,8 +120,8 @@ class AndroidNotificationManagerImpl implements AndroidNotificationManager,
this.androidExecutor = androidExecutor;
this.clock = clock;
appContext = app.getApplicationContext();
notificationManager = (NotificationManager)
appContext.getSystemService(NOTIFICATION_SERVICE);
notificationManager = (NotificationManager) requireNonNull(
appContext.getSystemService(NOTIFICATION_SERVICE));
}
@Override
......
......@@ -30,6 +30,7 @@ import static android.content.Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS;
import static android.content.Intent.FLAG_ACTIVITY_NEW_TASK;
import static android.content.Intent.FLAG_ACTIVITY_NO_ANIMATION;
import static android.os.Build.VERSION.SDK_INT;
import static java.util.Objects.requireNonNull;
import static java.util.logging.Logger.getLogger;
import static org.briarproject.briar.android.activity.RequestCodes.REQUEST_DOZE_WHITELISTING;
import static org.briarproject.briar.android.activity.RequestCodes.REQUEST_PASSWORD;
......@@ -177,8 +178,8 @@ public abstract class BriarActivity extends BaseActivity {
b.setNegativeButton(R.string.cancel,
(dialog, which) -> dialog.dismiss());
b.setOnDismissListener(dialog -> {
CheckBox checkBox =
((AlertDialog) dialog).findViewById(R.id.checkbox);
CheckBox checkBox = requireNonNull(
((AlertDialog) dialog).findViewById(R.id.checkbox));
if (checkBox.isChecked())
briarController.doNotAskAgainForDozeWhiteListing();
});
......
......@@ -221,7 +221,6 @@ abstract class BaseControllerImpl extends DbControllerImpl
text = HtmlUtils.clean(blogManager.getPostText(m), ARTICLE);
textCache.put(m, text);
}
//noinspection ConstantConditions
return text;
}
......
......@@ -92,13 +92,11 @@ public class BlogFragment extends BaseFragment
@Nullable ViewGroup container,
@Nullable Bundle savedInstanceState) {
Bundle args = requireNonNull(getArguments());
byte[] b = args.getByteArray(GROUP_ID);
if (b == null) throw new IllegalStateException("No group ID in args");
groupId = new GroupId(b);
groupId = new GroupId(requireNonNull(args.getByteArray(GROUP_ID)));
View v = inflater.inflate(R.layout.fragment_blog, container, false);
adapter = new BlogPostAdapter(requireNonNull(getActivity()), this,
adapter = new BlogPostAdapter(requireActivity(), this,
getFragmentManager());
list = v.findViewById(R.id.postList);
list.setLayoutManager(new LinearLayoutManager(getActivity()));
......@@ -269,7 +267,7 @@ public class BlogFragment extends BaseFragment
}
private void setToolbarTitle(Author a) {
getActivity().setTitle(a.getName());
requireActivity().setTitle(a.getName());
}
private void loadSharedContacts() {
......@@ -311,7 +309,7 @@ public class BlogFragment extends BaseFragment
private void setToolbarSubTitle(int total, int online) {
ActionBar actionBar =
((BriarActivity) getActivity()).getSupportActionBar();
((BriarActivity) requireActivity()).getSupportActionBar();
if (actionBar != null) {
actionBar.setSubtitle(
getString(R.string.shared_with, total, online));
......@@ -336,9 +334,8 @@ public class BlogFragment extends BaseFragment
snackbar.getView().setBackgroundResource(R.color.briar_primary);
if (scroll) {
View.OnClickListener onClick = v -> list.smoothScrollToPosition(0);
snackbar.setActionTextColor(ContextCompat
.getColor(getContext(),
R.color.briar_button_text_positive));
snackbar.setActionTextColor(ContextCompat.getColor(requireContext(),
R.color.briar_button_text_positive));
snackbar.setAction(R.string.blogs_blog_post_scroll_to, onClick);
}
snackbar.show();
......@@ -347,7 +344,7 @@ public class BlogFragment extends BaseFragment
private void showDeleteDialog() {
DialogInterface.OnClickListener okListener =
(dialog, which) -> deleteBlog();
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity(),
AlertDialog.Builder builder = new AlertDialog.Builder(requireActivity(),
R.style.BriarDialogTheme);
builder.setTitle(getString(R.string.blogs_remove_blog));
builder.setMessage(
......@@ -362,7 +359,7 @@ public class BlogFragment extends BaseFragment
new UiResultExceptionHandler<Void, DbException>(this) {
@Override
public void onResultUi(Void result) {
Toast.makeText(getActivity(),
Toast.makeText(requireActivity(),
R.string.blogs_blog_removed, LENGTH_SHORT)
.show();
finish();
......
......@@ -35,7 +35,6 @@ import javax.inject.Inject;
import static android.app.Activity.RESULT_OK;
import static android.content.Intent.FLAG_ACTIVITY_CLEAR_TOP;
import static android.support.design.widget.Snackbar.LENGTH_LONG;
import static java.util.Objects.requireNonNull;
import static java.util.logging.Logger.getLogger;
import static org.briarproject.briar.android.activity.BriarActivity.GROUP_ID;
import static org.briarproject.briar.android.activity.RequestCodes.REQUEST_WRITE_BLOG_POST;
......@@ -78,14 +77,14 @@ public class FeedFragment extends BaseFragment implements
public View onCreateView(LayoutInflater inflater,
@Nullable ViewGroup container,
@Nullable Bundle savedInstanceState) {
requireNonNull(getActivity()).setTitle(R.string.blogs_button);
requireActivity().setTitle(R.string.blogs_button);
View v = inflater.inflate(R.layout.fragment_blog, container, false);
adapter =
new BlogPostAdapter(getActivity(), this, getFragmentManager());
adapter = new BlogPostAdapter(requireActivity(), this,
getFragmentManager());
layoutManager = new LinearLayoutManager(getActivity());
layoutManager = new LinearLayoutManager(requireActivity());
list = v.findViewById(R.id.postList);
list.setLayoutManager(layoutManager);
list.setAdapter(adapter);
......@@ -176,19 +175,19 @@ public class FeedFragment extends BaseFragment implements
if (personalBlog == null) return false;
switch (item.getItemId()) {
case R.id.action_write_blog_post:
Intent i1 =
new Intent(getActivity(), WriteBlogPostActivity.class);
Intent i1 = new Intent(requireActivity(),
WriteBlogPostActivity.class);
i1.putExtra(GROUP_ID, personalBlog.getId().getBytes());
startActivityForResult(i1, REQUEST_WRITE_BLOG_POST);
return true;
case R.id.action_rss_feeds_import:
Intent i2 =
new Intent(getActivity(), RssFeedImportActivity.class);
Intent i2 = new Intent(requireActivity(),
RssFeedImportActivity.class);
startActivity(i2);
return true;
case R.id.action_rss_feeds_manage:
Intent i3 =
new Intent(getActivity(), RssFeedManageActivity.class);
Intent i3 = new Intent(requireActivity(),
RssFeedManageActivity.class);
i3.putExtra(GROUP_ID, personalBlog.getId().getBytes());
startActivity(i3);
return true;
......@@ -230,10 +229,11 @@ public class FeedFragment extends BaseFragment implements
@Override
public void onAuthorClick(BlogPostItem post) {
if (getContext() == null) return;
Intent i = new Intent(getContext(), BlogActivity.class);
i.putExtra(GROUP_ID, post.getGroupId().getBytes());
i.setFlags(FLAG_ACTIVITY_CLEAR_TOP);
getContext().startActivity(i);
requireContext().startActivity(i);
}
@Override
......@@ -252,9 +252,8 @@ public class FeedFragment extends BaseFragment implements
s.getView().setBackgroundResource(R.color.briar_primary);
if (scroll) {
OnClickListener onClick = v -> list.smoothScrollToPosition(0);
s.setActionTextColor(ContextCompat
.getColor(getContext(),
R.color.briar_button_text_positive));
s.setActionTextColor(ContextCompat.getColor(requireContext(),
R.color.briar_button_text_positive));
s.setAction(R.string.blogs_blog_post_scroll_to, onClick);
}
s.show();
......
......@@ -2,8 +2,11 @@ package org.briarproject.briar.android.blog;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.MenuItem;
import org.briarproject.bramble.api.nullsafety.MethodsNotNullByDefault;
import org.briarproject.bramble.api.nullsafety.ParametersNotNullByDefault;
import org.briarproject.bramble.api.sync.GroupId;
import org.briarproject.bramble.api.sync.MessageId;
import org.briarproject.briar.R;
......@@ -13,11 +16,13 @@ import org.briarproject.briar.android.fragment.BaseFragment.BaseFragmentListener
import static org.briarproject.briar.android.blog.BasePostFragment.POST_ID;
@MethodsNotNullByDefault
@ParametersNotNullByDefault
public class ReblogActivity extends BriarActivity implements
BaseFragmentListener {
@Override
public void onCreate(Bundle savedInstanceState) {
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent intent = getIntent();
......
......@@ -51,7 +51,6 @@ import javax.inject.Inject;
import static android.os.Build.VERSION.SDK_INT;
import static android.support.v4.app.ActivityOptionsCompat.makeSceneTransitionAnimation;
import static android.support.v4.view.ViewCompat.getTransitionName;
import static java.util.Objects.requireNonNull;
import static java.util.logging.Level.WARNING;
import static java.util.logging.Logger.getLogger;
import static org.briarproject.bramble.util.LogUtils.logDuration;
......@@ -106,13 +105,13 @@ public class ContactListFragment extends BaseFragment implements EventListener {
public View onCreateView(LayoutInflater inflater,
@Nullable ViewGroup container,
@Nullable Bundle savedInstanceState) {
requireNonNull(getActivity()).setTitle(R.string.contact_list_button);
requireActivity().setTitle(R.string.contact_list_button);
View contentView = inflater.inflate(R.layout.list, container, false);
OnContactClickListener<ContactListItem> onContactClickListener =
(view, item) -> {
Intent i = new Intent(getActivity(),
Intent i = new Intent(requireActivity(),
ConversationActivity.class);
ContactId contactId = item.getContact().getId();
i.putExtra(CONTACT_ID, contactId.getInt());
......@@ -130,16 +129,17 @@ public class ContactListFragment extends BaseFragment implements EventListener {
Pair.create(holder.bulb,
getTransitionName(holder.bulb));
ActivityOptionsCompat options =
makeSceneTransitionAnimation(getActivity(),
makeSceneTransitionAnimation(requireActivity(),
avatar, bulb);
ActivityCompat.startActivity(getActivity(), i,
ActivityCompat.startActivity(requireActivity(), i,
options.toBundle());
} else {
// work-around for android bug #224270
startActivity(i);
}
};
adapter = new ContactListAdapter(getContext(), onContactClickListener);
adapter = new ContactListAdapter(requireContext(),
onContactClickListener);
list = contentView.findViewById(R.id.list);
list.setLayoutManager(new LinearLayoutManager(getContext()));
list.setAdapter(adapter);
......@@ -161,8 +161,8 @@ public class ContactListFragment extends BaseFragment implements EventListener {
// Handle presses on the action bar items
switch (item.getItemId()) {
case R.id.action_add_contact:
Intent intent =
new Intent(getContext(), ContactExchangeActivity.class);
Intent intent = new Intent(requireContext(),
ContactExchangeActivity.class);
startActivity(intent);
return true;
default:
......
......@@ -69,11 +69,11 @@ public abstract class BaseContactSelectorFragment<I extends SelectableContactIte
View contentView = inflater.inflate(R.layout.list, container, false);
list = contentView.findViewById(R.id.list);
list.setLayoutManager(new LinearLayoutManager(getActivity()));
list.setLayoutManager(new LinearLayoutManager(requireActivity()));
list.setEmptyImage(R.drawable.ic_empty_state_contact_list);
list.setEmptyText(getString(R.string.no_contacts_selector));
list.setEmptyAction(getString(R.string.no_contacts_selector_action));
adapter = getAdapter(requireNonNull(getContext()), this);
adapter = getAdapter(requireContext(), this);
list.setAdapter(adapter);
// restore selected contacts if available
......
......@@ -39,9 +39,8 @@ public class AliasDialogFragment extends AppCompatDialogFragment {
setStyle(STYLE_NO_TITLE, R.style.BriarDialogTheme);
BriarActivity a = (BriarActivity) requireNonNull(getActivity());
a.getActivityComponent().inject(this);
viewModel = ViewModelProviders.of(getActivity(), viewModelFactory)
((BriarActivity) requireActivity()).getActivityComponent().inject(this);
viewModel = ViewModelProviders.of(requireActivity(), viewModelFactory)
.get(ConversationViewModel.class);
}
......
......@@ -502,7 +502,6 @@ public class ConversationActivity extends BriarActivity
* <p>
* Attention: Call this only after contactName has been initialized.
*/
@SuppressWarnings("ConstantConditions")
private List<ConversationItem> createItems(
Collection<ConversationMessageHeader> headers) {
List<ConversationItem> items = new ArrayList<>(headers.size());
......
......@@ -57,8 +57,7 @@ public class ImageFragment extends Fragment {
@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
BaseActivity a = (BaseActivity) requireNonNull(getActivity());
a.getActivityComponent().inject(this);
((BaseActivity) requireActivity()).getActivityComponent().inject(this);
}
@Override
......@@ -78,8 +77,8 @@ public class ImageFragment extends Fragment {
View v = inflater.inflate(R.layout.fragment_image, container,
false);
viewModel = ViewModelProviders.of(requireNonNull(getActivity()),
viewModelFactory).get(ImageViewModel.class);
viewModel = ViewModelProviders.of(requireActivity(), viewModelFactory)
.get(ImageViewModel.class);
photoView = v.findViewById(R.id.photoView);
photoView.setScaleLevels(1, 2, 4);
......
......@@ -44,7 +44,6 @@ import javax.annotation.Nullable;
import javax.inject.Inject;
import static android.support.design.widget.Snackbar.LENGTH_INDEFINITE;
import static java.util.Objects.requireNonNull;
import static java.util.logging.Level.WARNING;
import static java.util.logging.Logger.getLogger;
import static org.briarproject.bramble.util.LogUtils.logDuration;
......@@ -93,24 +92,23 @@ public class ForumListFragment extends BaseEventFragment implements
public View onCreateView(LayoutInflater inflater,
@Nullable ViewGroup container,
@Nullable Bundle savedInstanceState) {
requireNonNull(getActivity()).setTitle(R.string.forums_button);
requireActivity().setTitle(R.string.forums_button);
View contentView =
inflater.inflate(R.layout.fragment_forum_list, container,
false);
adapter = new ForumListAdapter(getActivity());
adapter = new ForumListAdapter(requireActivity());
list = contentView.findViewById(R.id.forumList);
list.setLayoutManager(new LinearLayoutManager(getActivity()));
list.setLayoutManager(new LinearLayoutManager(requireActivity()));
list.setAdapter(adapter);
snackbar = Snackbar.make(list, "", LENGTH_INDEFINITE);
snackbar.getView().setBackgroundResource(R.color.briar_primary);
snackbar.setAction(R.string.show, this);
snackbar.setActionTextColor(ContextCompat
.getColor(getActivity(), R.color.briar_button_text_positive));
snackbar.setActionTextColor(ContextCompat.getColor(requireContext(),
R.color.briar_button_text_positive));
return contentView;
}
......@@ -148,8 +146,8 @@ public class ForumListFragment extends BaseEventFragment implements
// Handle presses on the action bar items
switch (item.getItemId()) {
case R.id.action_create_forum:
Intent intent =
new Intent(getContext(), CreateForumActivity.class);
Intent intent = new Intent(requireContext(),
CreateForumActivity.class);
startActivity(intent);
return true;
default:
......@@ -270,7 +268,7 @@ public class ForumListFragment extends BaseEventFragment implements
@Override
public void onClick(View view) {
// snackbar click
Intent i = new Intent(getContext(), ForumInvitationActivity.class);
Intent i = new Intent(requireContext(), ForumInvitationActivity.class);
startActivity(i);
}
}
package org.briarproject.briar.android.fragment;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.Dialog;
import android.content.DialogInterface;
import android.os.Bundle;
......@@ -26,6 +25,8 @@ import java.util.Collection;
import javax.annotation.Nullable;
import javax.inject.Inject;
import static java.util.Objects.requireNonNull;
@MethodsNotNullByDefault
@ParametersNotNullByDefault
public class ScreenFilterDialogFragment extends DialogFragment {
......@@ -58,26 +59,20 @@ public class ScreenFilterDialogFragment extends DialogFragment {
@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
Activity activity = getActivity();
if (activity == null) throw new IllegalStateException();
((BaseActivity) activity).getActivityComponent().inject(this);
((BaseActivity) requireActivity()).getActivityComponent().inject(this);
}
@Override
public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
Activity activity = getActivity();
if (activity == null) throw new IllegalStateException();
AlertDialog.Builder builder = new AlertDialog.Builder(activity,
AlertDialog.Builder builder = new AlertDialog.Builder(requireActivity(),
R.style.BriarDialogThemeNoFilter);
builder.setTitle(R.string.screen_filter_title);
Bundle args = getArguments();
if (args == null) throw new IllegalStateException();
ArrayList<String> appNames = args.getStringArrayList("appNames");
Bundle args = requireNonNull(getArguments());
ArrayList<String> appNames =
requireNonNull(args.getStringArrayList("appNames"));
ArrayList<String> packageNames =
args.getStringArrayList("packageNames");
if (appNames == null || packageNames == null)
throw new IllegalStateException();
LayoutInflater inflater = activity.getLayoutInflater();
requireNonNull(args.getStringArrayList("packageNames"));
LayoutInflater inflater = requireActivity().getLayoutInflater();
// See https://stackoverflow.com/a/24720976/6314875
@SuppressLint("InflateParams")
View dialogView = inflater.inflate(R.layout.dialog_screen_filter, null);
......
......@@ -76,7 +76,6 @@ public class ContactChooserFragment extends BaseFragment {
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
@Nullable Bundle savedInstanceState) {
View contentView = inflater.inflate(R.layout.list, container, false);
OnContactClickListener<ContactListItem> onContactClickListener =
......@@ -85,11 +84,11 @@ public class ContactChooserFragment extends BaseFragment {
Contact c2 = item.getContact();
showMessageScreen(c1, c2);
};
adapter = new ContactListAdapter(requireNonNull(getActivity()),
adapter = new ContactListAdapter(requireActivity(),
onContactClickListener);
list = contentView.findViewById(R.id.list);
list.setLayoutManager(new LinearLayoutManager(getActivity()));
list.setLayoutManager(new LinearLayoutManager(requireActivity()));
list.setAdapter(adapter);
list.setEmptyText(R.string.no_contacts);
......
......@@ -36,6 +36,7 @@ import static android.hardware.Camera.Parameters.FOCUS_MODE_MACRO;
import static android.hardware.Camera.Parameters.SCENE_MODE_AUTO;
import static android.hardware.Camera.Parameters.SCENE_MODE_BARCODE;
import static android.os.Build.VERSION.SDK_INT;
import static java.util.Objects.requireNonNull;
import static java.util.logging.Level.INFO;
import static java.util.logging.Level.WARNING;
import static java.util.logging.Logger.getLogger;
......@@ -127,7 +128,7 @@ public class CameraView extends SurfaceView implements SurfaceHolder.Callback,
}
setDisplayOrientation(getScreenRotationDegrees());
// Use barcode scene mode if it's available
Parameters params = camera.getParameters();
Parameters params = requireNonNull(camera).getParameters();
params = setSceneMode(camera, params);
if (SCENE_MODE_BARCODE.equals(params.getSceneMode())) {
// If the scene mode enabled the flash, try to disable it
......@@ -164,8 +165,9 @@ public class CameraView extends SurfaceView implements SurfaceHolder.Callback,
* See {@link Camera#setDisplayOrientation(int)}.
*/
private int getScreenRotationDegrees() {
WindowManager wm =
(WindowManager) getContext().getSystemService(WINDOW_SERVICE);
WindowManager wm = (WindowManager)
getContext().getSystemService(WINDOW_SERVICE);
if (wm == null) return 0;
Display d = wm.getDefaultDisplay();
switch (d.getRotation()) {
case Surface.ROTATION_0:
......
......@@ -71,9 +71,7 @@ public class ContactExchangeErrorFragment extends BaseFragment {
// buttons
Button tryAgain = v.findViewById(R.id.tryAgainButton);
tryAgain.setOnClickListener(view -> {
if (getActivity() != null) getActivity().onBackPressed();
});
tryAgain.setOnClickListener(view -> requireActivity().onBackPressed());
Button cancel = v.findViewById(R.id.cancelButton);
cancel.setOnClickListener(view -> finish());
return v;
......
......@@ -42,6 +42,7 @@ import static android.bluetooth.BluetoothAdapter.SCAN_MODE_CONNECTABLE;
import static android.bluetooth.BluetoothAdapter.SCAN_MODE_CONNECTABLE_DISCOVERABLE;
import static android.bluetooth.BluetoothAdapter.STATE_ON;
import static android.content.pm.PackageManager.PERMISSION_GRANTED;
import static java.util.Objects.requireNonNull;
import static java.util.logging.Logger.getLogger;
import static org.briarproject.briar.android.activity.RequestCodes.REQUEST_BLUETOOTH_DISCOVERABLE;
import static org.briarproject.briar.android.activity.RequestCodes.REQUEST_PERMISSION_CAMERA_LOCATION;
......@@ -96,14 +97,13 @@ public abstract class KeyAgreementActivity extends BriarActivity implements
component.inject(this);
}
@SuppressWarnings("ConstantConditions")
@Override
public void onCreate(@Nullable Bundle state) {
super.onCreate(state);
setContentView(R.layout.activity_fragment_container_toolbar);
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
requireNonNull(getSupportActionBar()).setDisplayHomeAsUpEnabled(true);
if (state == null) {
showInitialFragment(IntroFragment.newInstance());
}
......@@ -202,7 +202,8 @@ public abstract class KeyAgreementActivity extends BriarActivity implements
}
@Override
public void onActivityResult(int request, int result, Intent data) {
public void onActivityResult(int request, int result,
@Nullable Intent data) {
if (request == REQUEST_BLUETOOTH_DISCOVERABLE) {
if (result == RESULT_CANCELED) {
setBluetoothState(BluetoothState.REFUSED);
......
......@@ -53,7 +53,6 @@ import static android.view.View.VISIBLE;
import static android.view.ViewGroup.LayoutParams.MATCH_PARENT;
import static android.widget.LinearLayout.HORIZONTAL;
import static android.widget.Toast.LENGTH_LONG;
import static java.util.Objects.requireNonNull;
import static java.util.logging.Level.INFO;
import static java.util.logging.Level.WARNING;
import static java.util.logging.Logger.getLogger;
......@@ -139,8 +138,7 @@ public class KeyAgreementFragment extends BaseEventFragment
@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
requireNonNull(getActivity())
.setRequestedOrientation(SCREEN_ORIENTATION_NOSENSOR);
requireActivity().setRequestedOrientation(SCREEN_ORIENTATION_NOSENSOR);
cameraView.setPreviewConsumer(new QrCodeDecoder(this));
}
......@@ -191,7 +189,7 @@ public class KeyAgreementFragment extends BaseEventFragment
@UiThread
private void logCameraExceptionAndFinish(CameraException e) {
logException(LOG, WARNING, e);
Toast.makeText(getActivity(), R.string.camera_error,
Toast.makeText(requireActivity(), R.string.camera_error,
LENGTH_LONG).show();
finish();
}
......@@ -262,7 +260,7 @@ public class KeyAgreementFragment extends BaseEventFragment
} catch (IOException | IllegalArgumentException e) {
LOG.log(WARNING, "QR Code Invalid", e);
reset();
Toast.makeText(getActivity(), R.string.qr_code_invalid,
Toast.makeText(requireActivity(), R.string.qr_code_invalid,
LENGTH_LONG).show();
}
}
......@@ -353,7 +351,7 @@ public class KeyAgreementFragment extends BaseEventFragment
@Override
protected void finish() {
getActivity().getSupportFragmentManager().popBackStack();
requireActivity().getSupportFragmentManager().popBackStack();
}
@NotNullByDefault
......
......@@ -17,7 +17,6 @@ import javax.annotation.Nullable;
import static android.view.inputmethod.EditorInfo.IME_ACTION_NEXT;
import static android.view.inputmethod.EditorInfo.IME_ACTION_NONE;
import static java.util.Objects.requireNonNull;
import static org.briarproject.bramble.api.identity.AuthorConstants.MAX_AUTHOR_NAME_LENGTH;
import static org.briarproject.bramble.util.StringUtils.toUtf8;
import static org.briarproject.briar.android.util.UiUtils.setError;
......@@ -45,7 +44,7 @@ public class AuthorNameFragment extends SetupFragment {
public View onCreateView(LayoutInflater inflater,
@Nullable ViewGroup container,
@Nullable Bundle savedInstanceState) {
requireNonNull(getActivity()).setTitle(getString(R.string.setup_title));
requireActivity().setTitle(getString(R.string.setup_title));
View v = inflater.inflate(R.layout.fragment_setup_author_name,
container, false);
authorNameWrapper = v.findViewById(R.id.nickname_entry_wrapper);
......
......@@ -18,7 +18,6 @@ import org.briarproject.briar.android.login.PowerView.OnCheckedChangedListener;
import static android.view.View.INVISIBLE;
import static android.view.View.VISIBLE;
import static java.util.Objects.requireNonNull;
import static org.briarproject.briar.android.activity.RequestCodes.REQUEST_DOZE_WHITELISTING;
import static org.briarproject.briar.android.util.UiUtils.getDozeWhitelistingIntent;
import static org.briarproject.briar.android.util.UiUtils.showOnboardingDialog;
......@@ -49,7 +48,7 @@ public class DozeFragment extends SetupFragment
public View onCreateView(LayoutInflater inflater,
@Nullable ViewGroup container,
@Nullable Bundle savedInstanceState) {
requireNonNull(getActivity()).setTitle(getString(R.string.setup_doze_title));
requireActivity().setTitle(getString(R.string.setup_doze_title));
setHasOptionsMenu(false);
View v = inflater.inflate(R.layout.fragment_setup_doze, container,
false);
......@@ -100,8 +99,7 @@ public class DozeFragment extends SetupFragment
@SuppressLint("BatteryLife")
private void askForDozeWhitelisting() {
if (getContext() == null) return;
Intent i = getDozeWhitelistingIntent(getContext());
Intent i = getDozeWhitelistingIntent(requireContext());
startActivityForResult(i, REQUEST_DOZE_WHITELISTING);
}
......
......@@ -22,7 +22,6 @@ import static android.content.Context.INPUT_METHOD_SERVICE;
import static android.view.View.INVISIBLE;
import static android.view.View.VISIBLE;
import static android.view.inputmethod.EditorInfo.IME_ACTION_DONE;
import static java.util.Objects.requireNonNull;
import static org.briarproject.bramble.api.crypto.PasswordStrengthEstimator.QUITE_WEAK;
import static org.briarproject.briar.android.util.UiUtils.setError;
......@@ -53,7 +52,7 @@ public class PasswordFragment extends SetupFragment {
public View onCreateView(LayoutInflater inflater,
@Nullable ViewGroup container,
@Nullable Bundle savedInstanceState) {
requireNonNull(getActivity()).setTitle(getString(R.string.setup_password_intro));
requireActivity().setTitle(getString(R.string.setup_password_intro));
View v = inflater.inflate(R.layout.fragment_setup_password, container,
false);
......@@ -115,8 +114,9 @@ public class PasswordFragment extends SetupFragment {
@Override
public void onClick(View view) {