Skip to content

Commit

Permalink
Merge pull request #3618 from deltachat/adb/code-cleanup-26/2/25
Browse files Browse the repository at this point in the history
fix some linter warnings
  • Loading branch information
adbenitez authored Feb 26, 2025
2 parents 9b9a546 + 7193b4d commit f8dc6bb
Show file tree
Hide file tree
Showing 43 changed files with 173 additions and 207 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Bundle;
import android.view.Menu;
Expand All @@ -23,7 +24,7 @@
import com.b44t.messenger.DcContact;
import com.b44t.messenger.DcContext;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.request.target.SimpleTarget;
import com.bumptech.glide.request.target.CustomTarget;
import com.bumptech.glide.request.transition.Transition;

import org.thoughtcrime.securesms.components.AvatarSelector;
Expand Down Expand Up @@ -74,7 +75,7 @@ protected void onCreate(Bundle state, boolean ready) {
setContentView(R.layout.group_create_activity);
verified = false;
broadcast = getIntent().getBooleanExtra(CREATE_BROADCAST, false);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
Objects.requireNonNull(getSupportActionBar()).setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeAsUpIndicator(R.drawable.ic_close_white_24dp);

groupChatId = getIntent().getIntExtra(EDIT_GROUP_CHAT_ID, 0);
Expand Down Expand Up @@ -354,11 +355,14 @@ private void setAvatarView(Uri output) {
.diskCacheStrategy(DiskCacheStrategy.NONE)
.centerCrop()
.override(AVATAR_SIZE, AVATAR_SIZE)
.into(new SimpleTarget<Bitmap>() {
.into(new CustomTarget<Bitmap>() {
@Override
public void onResourceReady(@NonNull Bitmap resource, Transition<? super Bitmap> transition) {
setAvatar(output, resource);
}

@Override
public void onLoadCleared(@Nullable Drawable placeholder) {}
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,17 @@

import android.animation.Animator;

import androidx.annotation.NonNull;

public abstract class AnimationCompleteListener implements Animator.AnimatorListener {
@Override
public final void onAnimationStart(Animator animation) {}
public final void onAnimationStart(@NonNull Animator animation) {}

@Override
public abstract void onAnimationEnd(Animator animation);
public abstract void onAnimationEnd(@NonNull Animator animation);

@Override
public final void onAnimationCancel(Animator animation) {}
public final void onAnimationCancel(@NonNull Animator animation) {}
@Override
public final void onAnimationRepeat(Animator animation) {}
public final void onAnimationRepeat(@NonNull Animator animation) {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public Uri getThumbnailUri() {

@Override
public boolean equals(Object other) {
return other != null && other instanceof UriAttachment && ((UriAttachment) other).dataUri.equals(this.dataUri);
return other instanceof UriAttachment && ((UriAttachment) other).dataUri.equals(this.dataUri);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public void startRecording() {
throw new AssertionError("We can only record once at a time.");
}

ParcelFileDescriptor fds[] = ParcelFileDescriptor.createPipe();
ParcelFileDescriptor[] fds = ParcelFileDescriptor.createPipe();

captureUri = blobProvider.create(context, new ParcelFileDescriptor.AutoCloseInputStream(fds[0]),
MediaUtil.AUDIO_AAC, "voice.aac", null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ private ProgressEventHandler(@NonNull AudioSlidePlayer player) {
}

@Override
public void handleMessage(Message msg) {
public void handleMessage(@NonNull Message msg) {
AudioSlidePlayer player = playerReference.get();

if (player == null || player.mediaPlayer == null || !isPlayerActive(player.mediaPlayer)) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
package org.thoughtcrime.securesms.components;

import android.animation.Animator;
import android.annotation.TargetApi;
import android.app.Activity;
import android.content.Context;
import android.graphics.drawable.BitmapDrawable;
import android.net.Uri;
import android.os.Build;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.loader.app.LoaderManager;
Expand Down Expand Up @@ -186,13 +185,6 @@ private void animateWindowInCircular(@Nullable View anchor, @NonNull View conten
animator.start();
}

private void animateWindowInTranslate(@NonNull View contentView) {
Animation animation = new TranslateAnimation(0, 0, contentView.getHeight(), 0);
animation.setDuration(ANIMATION_DURATION);

getContentView().startAnimation(animation);
}

private void animateWindowOutCircular(@Nullable View anchor, @NonNull View contentView) {
Pair<Integer, Integer> coordinates = getClickOrigin(anchor, contentView);
Animator animator = ViewAnimationUtils.createCircularReveal(getContentView(),
Expand All @@ -204,20 +196,20 @@ private void animateWindowOutCircular(@Nullable View anchor, @NonNull View conte
animator.setDuration(ANIMATION_DURATION);
animator.addListener(new Animator.AnimatorListener() {
@Override
public void onAnimationStart(Animator animation) {
public void onAnimationStart(@NonNull Animator animation) {
}

@Override
public void onAnimationEnd(Animator animation) {
public void onAnimationEnd(@NonNull Animator animation) {
AttachmentTypeSelector.super.dismiss();
}

@Override
public void onAnimationCancel(Animator animation) {
public void onAnimationCancel(@NonNull Animator animation) {
}

@Override
public void onAnimationRepeat(Animator animation) {
public void onAnimationRepeat(@NonNull Animator animation) {
}
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.thoughtcrime.securesms.components;

import android.annotation.TargetApi;
import android.content.Context;
import android.content.res.ColorStateList;
import android.graphics.PorterDuff;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import android.app.Activity;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.net.Uri;
import android.view.Gravity;
Expand Down Expand Up @@ -32,10 +33,6 @@ public class AvatarSelector extends PopupWindow {

private final @NonNull LoaderManager loaderManager;
private final @NonNull RecentPhotoViewRail recentRail;
private final @NonNull ImageView imageButton;
private final @NonNull ImageView cameraButton;
private final @NonNull ImageView removeButton;
private final @NonNull ImageView closeButton;

private @Nullable AttachmentClickedListener listener;

Expand All @@ -48,25 +45,25 @@ public AvatarSelector(@NonNull Context context, @NonNull LoaderManager loaderMan
this.listener = listener;
this.loaderManager = loaderManager;
this.recentRail = ViewUtil.findById(layout, R.id.recent_photos);
this.imageButton = ViewUtil.findById(layout, R.id.gallery_button);
this.cameraButton = ViewUtil.findById(layout, R.id.camera_button);
this.closeButton = ViewUtil.findById(layout, R.id.close_button);
this.removeButton = ViewUtil.findById(layout, R.id.remove_button);

this.imageButton.setOnClickListener(new PropagatingClickListener(ADD_GALLERY));
this.cameraButton.setOnClickListener(new PropagatingClickListener(TAKE_PHOTO));
this.closeButton.setOnClickListener(new CloseClickListener());
this.removeButton.setOnClickListener(new PropagatingClickListener(REMOVE_PHOTO));
ImageView imageButton = ViewUtil.findById(layout, R.id.gallery_button);
ImageView cameraButton = ViewUtil.findById(layout, R.id.camera_button);
ImageView closeButton = ViewUtil.findById(layout, R.id.close_button);
ImageView removeButton = ViewUtil.findById(layout, R.id.remove_button);

imageButton.setOnClickListener(new PropagatingClickListener(ADD_GALLERY));
cameraButton.setOnClickListener(new PropagatingClickListener(TAKE_PHOTO));
closeButton.setOnClickListener(new CloseClickListener());
removeButton.setOnClickListener(new PropagatingClickListener(REMOVE_PHOTO));
this.recentRail.setListener(new RecentPhotoSelectedListener());
if (!includeClear) {
this.removeButton.setVisibility(View.GONE);
removeButton.setVisibility(View.GONE);
ViewUtil.findById(layout, R.id.remove_button_label).setVisibility(View.GONE);
}

setContentView(layout);
setWidth(LinearLayout.LayoutParams.MATCH_PARENT);
setHeight(LinearLayout.LayoutParams.WRAP_CONTENT);
setBackgroundDrawable(new BitmapDrawable());
setBackgroundDrawable(new BitmapDrawable(context.getResources(), (Bitmap) null));
setAnimationStyle(0);
setInputMethodMode(PopupWindow.INPUT_METHOD_NOT_NEEDED);
setFocusable(true);
Expand All @@ -88,7 +85,7 @@ public void show(@NonNull Activity activity, final @NonNull View anchor) {
getContentView().getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
getContentView().getViewTreeObserver().removeGlobalOnLayoutListener(this);
getContentView().getViewTreeObserver().removeOnGlobalLayoutListener(this);

animateWindowInTranslate(getContentView());
}
Expand Down Expand Up @@ -167,8 +164,8 @@ public void onClick(View v) {
}

public interface AttachmentClickedListener {
public void onClick(int type);
public void onQuickAttachment(Uri uri);
void onClick(int type);
void onQuickAttachment(Uri uri);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,6 @@ public void setAvatarClickListener(OnClickListener listener) {
avatarImage.setOnClickListener(listener);
}

public void setAvatarLongClickListener(OnLongClickListener listener) {
avatarImage.setOnLongClickListener(listener);
}

public void setSeenRecently(boolean enabled) {
seenRecentlyIndicator.setVisibility(enabled? View.VISIBLE : View.GONE);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ public CircleColorImageView(Context context, AttributeSet attrs, int defStyleAtt
int circleColor = Color.WHITE;

if (attrs != null) {
TypedArray typedArray = context.getTheme().obtainStyledAttributes(attrs, R.styleable.CircleColorImageView, 0, 0);
circleColor = typedArray.getColor(R.styleable.CircleColorImageView_circleColor, Color.WHITE);
typedArray.recycle();
try (TypedArray typedArray = context.getTheme().obtainStyledAttributes(attrs, R.styleable.CircleColorImageView, 0, 0)) {
circleColor = typedArray.getColor(R.styleable.CircleColorImageView_circleColor, Color.WHITE);
}
}

Drawable circle = context.getResources().getDrawable(R.drawable.circle_tintable);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public void setTransport(TransportOption transport) {
}

@Override
public InputConnection onCreateInputConnection(EditorInfo editorInfo) {
public InputConnection onCreateInputConnection(@NonNull EditorInfo editorInfo) {
InputConnection inputConnection = super.onCreateInputConnection(editorInfo);

if(Prefs.isEnterSendsEnabled(getContext())) {
Expand Down Expand Up @@ -143,7 +143,6 @@ private void initialize() {
}
}

@RequiresApi(api = Build.VERSION_CODES.HONEYCOMB_MR2)
private static class CommitContentListener implements InputConnectionCompat.OnCommitContentListener {

private static final String TAG = CommitContentListener.class.getName();
Expand All @@ -155,7 +154,7 @@ private CommitContentListener(@NonNull InputPanel.MediaListener mediaListener) {
}

@Override
public boolean onCommitContent(InputContentInfoCompat inputContentInfo, int flags, Bundle opts) {
public boolean onCommitContent(@NonNull InputContentInfoCompat inputContentInfo, int flags, Bundle opts) {
if (BuildCompat.isAtLeastNMR1() && (flags & InputConnectionCompat.INPUT_CONTENT_GRANT_READ_URI_PERMISSION) != 0) {
try {
inputContentInfo.requestPermission();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,9 @@ public ContactFilterToolbar(Context context, AttributeSet attrs, int defStyleAtt

searchText.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS);

this.clearToggle.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
searchText.setText("");
displayTogglingView(null);
}
this.clearToggle.setOnClickListener(v -> {
searchText.setText("");
displayTogglingView(null);
});

this.searchText.addTextChangedListener(new TextWatcher() {
Expand Down Expand Up @@ -115,19 +112,16 @@ private void displayTogglingView(View view) {
private void expandTapArea(final View container, final View child) {
final int padding = getResources().getDimensionPixelSize(R.dimen.contact_selection_actions_tap_area);

container.post(new Runnable() {
@Override
public void run() {
Rect rect = new Rect();
child.getHitRect(rect);
container.post(() -> {
Rect rect = new Rect();
child.getHitRect(rect);

rect.top -= padding;
rect.left -= padding;
rect.right += padding;
rect.bottom += padding;
rect.top -= padding;
rect.left -= padding;
rect.right += padding;
rect.bottom += padding;

container.setTouchDelegate(new TouchDelegate(rect, child));
}
container.setTouchDelegate(new TouchDelegate(rect, child));
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ private void init(@Nullable AttributeSet attrs) {
deliveryStatusView = new DeliveryStatusView(findViewById(R.id.delivery_indicator));

if (attrs != null) {
TypedArray typedArray = getContext().getTheme().obtainStyledAttributes(attrs, R.styleable.ConversationItemFooter, 0, 0);
textColor = typedArray.getInt(R.styleable.ConversationItemFooter_footer_text_color, getResources().getColor(R.color.core_white));
setTextColor(textColor);
typedArray.recycle();
try (TypedArray typedArray = getContext().getTheme().obtainStyledAttributes(attrs, R.styleable.ConversationItemFooter, 0, 0)) {
textColor = typedArray.getInt(R.styleable.ConversationItemFooter_footer_text_color, getResources().getColor(R.color.core_white));
setTextColor(textColor);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@

public class ConversationItemThumbnail extends FrameLayout {

private static final String TAG = ConversationItemThumbnail.class.getSimpleName();

private static final Paint LIGHT_THEME_OUTLINE_PAINT = new Paint();
private static final Paint DARK_THEME_OUTLINE_PAINT = new Paint();
public static final double IMAGE_ASPECT_RATIO = 1.0;
Expand Down Expand Up @@ -62,20 +60,20 @@ public class ConversationItemThumbnail extends FrameLayout {

public ConversationItemThumbnail(Context context) {
super(context);
init(null);
init();
}

public ConversationItemThumbnail(Context context, AttributeSet attrs) {
super(context, attrs);
init(attrs);
init();
}

public ConversationItemThumbnail(final Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
init(attrs);
init();
}

private void init(@Nullable AttributeSet attrs) {
private void init() {
inflate(getContext(), R.layout.conversation_item_thumbnail, this);

this.thumbnail = findViewById(R.id.conversation_thumbnail_image);
Expand Down Expand Up @@ -119,7 +117,7 @@ protected void onMeasure(int originalWidthMeasureSpec, int originalHeightMeasure

@SuppressWarnings("SuspiciousNameCombination")
@Override
protected void dispatchDraw(Canvas canvas) {
protected void dispatchDraw(@NonNull Canvas canvas) {

super.dispatchDraw(canvas);

Expand Down
Loading

0 comments on commit f8dc6bb

Please sign in to comment.