[android]Fix warnings

Signed-off-by: Jean-BaptisteC <jeanbaptiste.charron@outlook.fr>
This commit is contained in:
Jean-Baptiste 2024-02-22 19:59:45 +01:00 committed by Alexander Borsuk
parent 168faed742
commit 08b0d523ad
21 changed files with 83 additions and 210 deletions

View file

@ -12,8 +12,6 @@ import android.widget.Button;
import android.widget.CheckBox;
import android.widget.TextView;
import androidx.activity.result.ActivityResultLauncher;
import androidx.activity.result.contract.ActivityResultContracts;
import androidx.annotation.CallSuper;
import androidx.annotation.Keep;
import androidx.annotation.NonNull;
@ -24,7 +22,6 @@ import androidx.annotation.StyleRes;
import app.organicmaps.base.BaseMwmFragmentActivity;
import app.organicmaps.downloader.CountryItem;
import app.organicmaps.downloader.MapManager;
import app.organicmaps.intent.Factory;
import app.organicmaps.location.LocationHelper;
import app.organicmaps.location.LocationListener;
import app.organicmaps.util.Config;

View file

@ -31,7 +31,6 @@ import androidx.annotation.StyleRes;
import androidx.annotation.UiThread;
import androidx.appcompat.widget.Toolbar;
import androidx.core.app.ActivityCompat;
import androidx.core.content.IntentCompat;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;
import androidx.fragment.app.Fragment;

View file

@ -3,7 +3,6 @@ package app.organicmaps;
import static android.Manifest.permission.ACCESS_COARSE_LOCATION;
import static android.Manifest.permission.ACCESS_FINE_LOCATION;
import android.app.Activity;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
@ -16,10 +15,8 @@ import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.StringRes;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.content.IntentCompat;
import app.organicmaps.display.DisplayManager;
import app.organicmaps.intent.Factory;
import app.organicmaps.location.LocationHelper;
import app.organicmaps.util.Config;
import app.organicmaps.util.LocationUtils;

View file

@ -13,7 +13,6 @@ import androidx.annotation.Nullable;
import androidx.annotation.StyleRes;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import androidx.core.content.IntentCompat;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentFactory;
import androidx.fragment.app.FragmentManager;

View file

@ -15,7 +15,6 @@ import app.organicmaps.util.log.Logger;
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

View file

@ -55,19 +55,14 @@ public class ChooseBookmarkCategoryAdapter extends BaseBookmarkCategoryAdapter<C
final SingleChoiceHolder holder = new SingleChoiceHolder(view);
view.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
if (mListener == null)
return;
view.setOnClickListener(v -> {
if (mListener == null)
return;
if (holder.getItemViewType() == VIEW_TYPE_ADD_NEW)
mListener.onCategoryCreate();
else
mListener.onCategorySet(holder.getBindingAdapterPosition());
}
if (holder.getItemViewType() == VIEW_TYPE_ADD_NEW)
mListener.onCategoryCreate();
else
mListener.onCategorySet(holder.getBindingAdapterPosition());
});
return holder;

View file

@ -48,15 +48,10 @@ class BottomPanel
mFragment = fragment;
mFab = frame.findViewById(R.id.fab);
mFab.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
if (mFragment.getAdapter() != null )
mFragment.getAdapter().setAvailableMapsMode();
update();
}
mFab.setOnClickListener(v -> {
if (mFragment.getAdapter() != null )
mFragment.getAdapter().setAvailableMapsMode();
update();
});
mButton = frame.findViewById(R.id.action);

View file

@ -436,21 +436,7 @@ class DownloaderAdapter extends RecyclerView.Adapter<DownloaderAdapter.ViewHolde
super.updateIcon(country);
mIcon.setFocusable(country.isExpandable() && country.status != CountryItem.STATUS_DONE);
}
}.setOnIconClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
processClick(true);
}
}).setOnCancelClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
MapManager.nativeCancel(mItem.id);
}
});
}.setOnIconClickListener(v -> processClick(true)).setOnCancelClickListener(v -> MapManager.nativeCancel(mItem.id));
mName = frame.findViewById(R.id.name);
mSubtitle = frame.findViewById(R.id.subtitle);

View file

@ -205,29 +205,19 @@ public final class MapManager
public static boolean warn3gAndDownload(Activity activity, final String countryId, @Nullable final Runnable onAcceptListener)
{
return warnOn3g(activity, countryId, new Runnable()
{
@Override
public void run()
{
if (onAcceptListener != null)
onAcceptListener.run();
nativeDownload(countryId);
}
return warnOn3g(activity, countryId, () -> {
if (onAcceptListener != null)
onAcceptListener.run();
nativeDownload(countryId);
});
}
static boolean warn3gAndRetry(Activity activity, final String countryId, @Nullable final Runnable onAcceptListener)
{
return warnOn3g(activity, countryId, new Runnable()
{
@Override
public void run()
{
if (onAcceptListener != null)
onAcceptListener.run();
nativeRetry(countryId);
}
return warnOn3g(activity, countryId, () -> {
if (onAcceptListener != null)
onAcceptListener.run();
nativeRetry(countryId);
});
}

View file

@ -196,17 +196,12 @@ public class OnmapDownloader implements MwmActivity.LeftAnimationTrackListener
mProgress = controls.findViewById(R.id.wheel_downloader_progress);
mButton = controls.findViewById(R.id.downloader_button);
mProgress.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
if (mCurrentCountry == null)
return;
mProgress.setOnClickListener(v -> {
if (mCurrentCountry == null)
return;
MapManager.nativeCancel(mCurrentCountry.id);
setAutodownloadLocked(true);
}
MapManager.nativeCancel(mCurrentCountry.id);
setAutodownloadLocked(true);
});
mButton.setOnClickListener(v -> MapManager.warnOn3g(mActivity, mCurrentCountry == null ? null :
mCurrentCountry.id, () -> {

View file

@ -362,27 +362,22 @@ public class EditorFragment extends BaseMwmFragment implements View.OnClickListe
return;
}
showAdditionalNames(true);
UiUtils.waitLayout(mNamesView, new ViewTreeObserver.OnGlobalLayoutListener()
{
@Override
public void onGlobalLayout()
{
LinearLayoutManager lm = (LinearLayoutManager) mNamesView.getLayoutManager();
int position = args.getInt(LAST_INDEX_OF_NAMES_ARRAY);
UiUtils.waitLayout(mNamesView, () -> {
LinearLayoutManager lm = (LinearLayoutManager) mNamesView.getLayoutManager();
int position = args.getInt(LAST_INDEX_OF_NAMES_ARRAY);
View nameItem = lm.findViewByPosition(position);
View nameItem = lm.findViewByPosition(position);
int cvNameTop = mCardName.getTop();
int nameItemTop = nameItem.getTop();
int cvNameTop = mCardName.getTop();
int nameItemTop = nameItem.getTop();
view.scrollTo(0, cvNameTop + nameItemTop);
view.scrollTo(0, cvNameTop + nameItemTop);
// TODO(mgsergio): Uncomment if focus and keyboard are required.
// TODO(mgsergio): Keyboard doesn't want to hide. Only pressing back button works.
// View nameItemInput = nameItem.findViewById(R.id.input);
// nameItemInput.requestFocus();
// InputUtils.showKeyboard(nameItemInput);
}
// TODO(mgsergio): Uncomment if focus and keyboard are required.
// TODO(mgsergio): Keyboard doesn't want to hide. Only pressing back button works.
// View nameItemInput = nameItem.findViewById(R.id.input);
// nameItemInput.requestFocus();
// InputUtils.showKeyboard(nameItemInput);
});
}

View file

@ -38,18 +38,14 @@ public class LanguagesFragment extends BaseMwmRecyclerFragment<LanguagesAdapter>
languages.add(lang);
}
Collections.sort(languages, new Comparator<Language>()
{
@Override
public int compare(Language lhs, Language rhs) {
// Default name can be changed, but it should be last in list of names.
if (lhs.isDefaultLang() && !rhs.isDefaultLang())
return 1;
if (!lhs.isDefaultLang() && rhs.isDefaultLang())
return -1;
Collections.sort(languages, (lhs, rhs) -> {
// Default name can be changed, but it should be last in list of names.
if (lhs.isDefaultLang() && !rhs.isDefaultLang())
return 1;
if (!lhs.isDefaultLang() && rhs.isDefaultLang())
return -1;
return lhs.name.compareTo(rhs.name);
}
return lhs.name.compareTo(rhs.name);
});
return new LanguagesAdapter(this, languages.toArray(new Language[languages.size()]));

View file

@ -112,18 +112,13 @@ public class MultilanguageAdapter extends RecyclerView.Adapter<MultilanguageAdap
}
});
itemView.findViewById(R.id.delete).setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
// TODO(mgsergio): Implement item deletion.
// int position = getAdapterPosition();
// mHostFragment.removeLocalizedName(position + 1);
// mNames.remove(position);
// notifyItemRemoved(position);
}
});
itemView.findViewById(R.id.delete).setOnClickListener(v -> {
// TODO(mgsergio): Implement item deletion.
// int position = getAdapterPosition();
// mHostFragment.removeLocalizedName(position + 1);
// mNames.remove(position);
// notifyItemRemoved(position);
});
}
}
}

View file

@ -337,14 +337,7 @@ class SimpleTimetableAdapter extends RecyclerView.Adapter<SimpleTimetableAdapter
// Save index of the day to get it back when checkbox will be toggled.
checkBox.setTag(dayIndex);
days.put(dayIndex, checkBox);
day.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
checkBox.toggle();
}
});
day.setOnClickListener(v -> checkBox.toggle());
((TextView) day.findViewById(R.id.tv__day)).setText(TimeFormatUtils.formatShortWeekday(dayIndex));
}
@ -374,14 +367,7 @@ class SimpleTimetableAdapter extends RecyclerView.Adapter<SimpleTimetableAdapter
{
super(itemView);
mAdd = itemView.findViewById(R.id.btn__add_time);
mAdd.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
addTimetable();
}
});
mAdd.setOnClickListener(v -> addTimetable());
}
@Override

View file

@ -97,14 +97,9 @@ public class StreetAdapter extends RecyclerView.Adapter<StreetAdapter.BaseViewHo
streetLoc = itemView.findViewById(R.id.street_localized);
selected = itemView.findViewById(R.id.selected);
itemView.setOnClickListener(this);
selected.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
selected.toggle();
StreetViewHolder.this.onClick(selected);
}
selected.setOnClickListener(v -> {
selected.toggle();
StreetViewHolder.this.onClick(selected);
});
}

View file

@ -71,14 +71,9 @@ abstract class BaseRoutingErrorDialogFragment extends BaseMwmDialogFragment
super.onStart();
AlertDialog dlg = (AlertDialog) getDialog();
dlg.getButton(DialogInterface.BUTTON_NEGATIVE).setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
mCancelled = true;
dismiss();
}
dlg.getButton(DialogInterface.BUTTON_NEGATIVE).setOnClickListener(v -> {
mCancelled = true;
dismiss();
});
}
@ -133,16 +128,11 @@ abstract class BaseRoutingErrorDialogFragment extends BaseMwmDialogFragment
listView.setAdapter(buildAdapter());
listView.setChildDivider(new ColorDrawable(getResources().getColor(android.R.color.transparent)));
UiUtils.waitLayout(listView, new ViewTreeObserver.OnGlobalLayoutListener()
{
@Override
public void onGlobalLayout()
{
final int width = listView.getWidth();
final int indicatorWidth = UiUtils.dimen(requireContext(), R.dimen.margin_quadruple);
listView.setIndicatorBounds(width - indicatorWidth, width);
listView.setIndicatorBoundsRelative(width - indicatorWidth, width);
}
UiUtils.waitLayout(listView, () -> {
final int width = listView.getWidth();
final int indicatorWidth = UiUtils.dimen(requireContext(), R.dimen.margin_quadruple);
listView.setIndicatorBounds(width - indicatorWidth, width);
listView.setIndicatorBoundsRelative(width - indicatorWidth, width);
});
return countriesView;

View file

@ -37,14 +37,9 @@ public class RoutingPlanInplaceController extends RoutingPlanController
if (show)
UiUtils.show(getFrame());
mAnimator = animateFrame(show, new Runnable()
{
@Override
public void run()
{
if (!show)
UiUtils.hide(getFrame());
}
mAnimator = animateFrame(show, () -> {
if (!show)
UiUtils.hide(getFrame());
});
}
@ -71,14 +66,7 @@ public class RoutingPlanInplaceController extends RoutingPlanController
ValueAnimator animator =
ValueAnimator.ofFloat(show ? -getFrame().getHeight() : 0, show ? 0 : -getFrame().getHeight());
animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener()
{
@Override
public void onAnimationUpdate(ValueAnimator animation)
{
getFrame().setTranslationY((Float) animation.getAnimatedValue());
}
});
animator.addUpdateListener(animation -> getFrame().setTranslationY((Float) animation.getAnimatedValue()));
animator.addListener(new UiUtils.SimpleAnimatorListener()
{
@Override

View file

@ -57,27 +57,17 @@ class SearchHistoryAdapter extends RecyclerView.Adapter<SearchHistoryAdapter.Vie
case TYPE_CLEAR:
res = new ViewHolder(LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.item_search_clear_history, viewGroup, false));
res.mText.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
SearchRecents.clear();
notifyDataSetChanged();
}
res.mText.setOnClickListener(v -> {
SearchRecents.clear();
notifyDataSetChanged();
});
break;
case TYPE_MY_POSITION:
res = new ViewHolder(LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.item_search_my_position, viewGroup, false));
res.mText.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
RoutingController.get().onPoiSelected(LocationHelper.from(viewGroup.getContext()).getMyPosition());
mSearchToolbarController.onUpClick();
}
res.mText.setOnClickListener(v -> {
RoutingController.get().onPoiSelected(LocationHelper.from(viewGroup.getContext()).getMyPosition());
mSearchToolbarController.onUpClick();
});
break;

View file

@ -113,15 +113,10 @@ public final class HttpClient
if (p.data != null)
{
connection.setFixedLengthStreamingMode(p.data.length);
final OutputStream os = connection.getOutputStream();
try
try (OutputStream os = connection.getOutputStream())
{
os.write(p.data);
}
finally
{
os.close();
}
Logger.d(TAG, "Sent " + p.httpMethod + " with content of size " + p.data.length);
}
else

View file

@ -62,15 +62,10 @@ public class BookmarkColorDialogFragment extends BaseMwmDialogFragment
@SuppressLint("InflateParams")
final GridView gView = (GridView) LayoutInflater.from(requireActivity()).inflate(R.layout.fragment_color_grid, null);
gView.setAdapter(adapter);
gView.setOnItemClickListener(new AdapterView.OnItemClickListener()
{
@Override
public void onItemClick(AdapterView<?> arg0, View who, int pos, long id)
{
if (mColorSetListener != null)
mColorSetListener.onBookmarkColorSet(pos);
dismiss();
}
gView.setOnItemClickListener((arg0, who, pos, id) -> {
if (mColorSetListener != null)
mColorSetListener.onBookmarkColorSet(pos);
dismiss();
});
return gView;

View file

@ -71,14 +71,10 @@ public class DirectionFragment extends BaseMwmDialogFragment
mTvSubtitle = root.findViewById(R.id.tv__subtitle);
mTvDistance = root.findViewById(R.id.tv__straight_distance);
UiUtils.waitLayout(mTvTitle, new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout()
{
final int height = mTvTitle.getHeight();
final int lineHeight = mTvTitle.getLineHeight();
mTvTitle.setMaxLines(height / lineHeight);
}
UiUtils.waitLayout(mTvTitle, () -> {
final int height = mTvTitle.getHeight();
final int lineHeight = mTvTitle.getLineHeight();
mTvTitle.setMaxLines(height / lineHeight);
});
}