Skip to content

Commit

Permalink
Merge pull request #2362 from marunjar/fix_lint_warnings
Browse files Browse the repository at this point in the history
fix lint warning
  • Loading branch information
marunjar authored Jan 2, 2025
2 parents 10b8838 + e740e73 commit 37712b8
Show file tree
Hide file tree
Showing 17 changed files with 180 additions and 240 deletions.
2 changes: 1 addition & 1 deletion app/lint.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<!-- reduce warnings related to translations -->
<issue id="Typos" severity="informational" />
<issue id="TypographyQuotes" severity="ignore" />
<issue id="DuplicateStrings" severity="informational" />
<issue id="DuplicateStrings" severity="ignore" />

<!-- ignore until kotlin is in use -->
<issue id="UnknownNullness" severity="ignore" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,9 @@ public void setUp() {
PreferenceManager.setDefaultValues(mActivityRule.getActivity(), R.xml.preferences, true);

// Remove lock screen
Runnable wakeUpDevice = new Runnable() {
public void run() {
mActivityRule.getActivity().getWindow().addFlags(WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON |
WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED |
WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
}
};
Runnable wakeUpDevice = () -> mActivityRule.getActivity().getWindow().addFlags(WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON |
WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED |
WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
mActivityRule.getActivity().runOnUiThread(wakeUpDevice);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,7 @@ public class FavoritesTest extends AbstractMainActivityTest {
private void enableInternalBar() {
mActivityRule.getActivity().prefs.edit().putBoolean("enable-favorites-bar", false).apply();
try {
mActivityRule.runOnUiThread(new Runnable() {
@Override
public void run() {
mActivityRule.getActivity().recreate();
}
});
mActivityRule.runOnUiThread(() -> mActivityRule.getActivity().recreate());
} catch (Throwable throwable) {
throwable.printStackTrace();
}
Expand Down
11 changes: 4 additions & 7 deletions app/src/main/java/fr/neamar/kiss/DataHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public DataHandler(Context context) {
start = System.currentTimeMillis();

IntentFilter intentFilter = new IntentFilter(MainActivity.LOAD_OVER);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
this.context.getApplicationContext().registerReceiver(this, intentFilter, Context.RECEIVER_EXPORTED);
}
else {
Expand Down Expand Up @@ -240,12 +240,9 @@ public void onReceive(final Context context, Intent intent) {
// starting the service needs to be slightly delayed because the Intent is fired *before* the app is considered in the foreground.
// Each new release of Android manages to make the developer life harder.
// Can't wait for the next one.
handler.postDelayed(new Runnable() {
@Override
public void run() {
Log.i(TAG, "Screen turned on or unlocked, retrying to start background services");
connectToProvider(name, counter + 1);
}
handler.postDelayed(() -> {
Log.i(TAG, "Screen turned on or unlocked, retrying to start background services");
connectToProvider(name, counter + 1);
}, 10);
}
}
Expand Down
63 changes: 22 additions & 41 deletions app/src/main/java/fr/neamar/kiss/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ public void onReceive(Context context, Intent intent) {
}
};

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
// Since Android 33, we need to specify is the receiver is available from other applications
// For some reasons, in our case, using RECEIVER_NOT_EXPORTED means we do not get the updates from our own services?!
// So we export the receiver.
Expand Down Expand Up @@ -263,12 +263,7 @@ public void onReceive(Context context, Intent intent) {
findViewById(android.R.id.content).setOnTouchListener(this);

// Add layout change listener for soft keyboard detection
findViewById(android.R.id.content).getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
forwarderManager.onGlobalLayout();
}
});
findViewById(android.R.id.content).getViewTreeObserver().addOnGlobalLayoutListener(() -> forwarderManager.onGlobalLayout());

// add history popup touch listener to empty view (prevents it from not working there)
this.emptyListView.setOnTouchListener(this);
Expand Down Expand Up @@ -360,40 +355,31 @@ public void onTextChanged(CharSequence s, int start, int before, int count) {
// Fixes bug when dropping onto a textEdit widget which can cause a NPE
// This fix should be on ALL TextEdit Widgets !!!
// See : https://stackoverflow.com/a/23483957
searchEditText.setOnDragListener(new View.OnDragListener() {
@Override
public boolean onDrag(View v, DragEvent event) {
return true;
}
});

searchEditText.setOnDragListener((v, event) -> true);

// On validate, launch first record
searchEditText.setOnEditorActionListener(new OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (actionId == android.R.id.closeButton) {
systemUiVisibilityHelper.onKeyboardVisibilityChanged(false);
if (mPopup != null) {
mPopup.dismiss();
return true;
}
systemUiVisibilityHelper.onKeyboardVisibilityChanged(false);
hider.fixScroll();
return false;
searchEditText.setOnEditorActionListener((v, actionId, event) -> {
if (actionId == android.R.id.closeButton) {
systemUiVisibilityHelper.onKeyboardVisibilityChanged(false);
if (mPopup != null) {
mPopup.dismiss();
return true;
}
systemUiVisibilityHelper.onKeyboardVisibilityChanged(false);
hider.fixScroll();
return false;
}

if (prefs.getBoolean("always-default-web-search-on-enter", false)) {
SearchPojo pojo = SearchProvider.getDefaultSearch(v.getText().toString(), MainActivity.this, prefs);
if (pojo != null) {
Result.fromPojo(MainActivity.this, pojo).fastLaunch(MainActivity.this, null);
}
} else {
adapter.onClick(adapter.getCount() - 1, v);
if (prefs.getBoolean("always-default-web-search-on-enter", false)) {
SearchPojo pojo = SearchProvider.getDefaultSearch(v.getText().toString(), MainActivity.this, prefs);
if (pojo != null) {
Result.fromPojo(MainActivity.this, pojo).fastLaunch(MainActivity.this, null);
}

return true;
} else {
adapter.onClick(adapter.getCount() - 1, v);
}

return true;
});

registerForContextMenu(menuButton);
Expand Down Expand Up @@ -907,12 +893,7 @@ public void registerPopup(ListPopup popup) {
dismissPopup();
mPopup = popup;
popup.setVisibilityHelper(systemUiVisibilityHelper);
popup.setOnDismissListener(new PopupWindow.OnDismissListener() {
@Override
public void onDismiss() {
MainActivity.this.mPopup = null;
}
});
popup.setOnDismissListener(() -> MainActivity.this.mPopup = null);
hider.fixScroll();
}

Expand Down
57 changes: 18 additions & 39 deletions app/src/main/java/fr/neamar/kiss/SettingsActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -397,12 +397,9 @@ private void addExcludedAppSettings() {

PreferenceScreen excludedAppsScreen = ExcludePreferenceScreen.getInstance(
this,
new ExcludePreferenceScreen.IsExcludedCallback() {
@Override
public boolean isExcluded(@NonNull AppPojo app) {
return app.isExcluded();
}
},
R.string.ui_excluded_apps,
R.string.ui_excluded_apps_dialog_title,
AppPojo::isExcluded,
new ExcludePreferenceScreen.OnExcludedListener() {
@Override
public void onExcluded(final @NonNull AppPojo app) {
Expand All @@ -413,9 +410,7 @@ public void onExcluded(final @NonNull AppPojo app) {
public void onIncluded(final @NonNull AppPojo app) {
dataHandler.removeFromExcluded(app);
}
},
R.string.ui_excluded_apps,
R.string.ui_excluded_apps_dialog_title
}
);

PreferenceGroup category = (PreferenceGroup) findPreference("exclude_apps_category");
Expand All @@ -427,12 +422,9 @@ private void addExcludedFromHistoryAppSettings() {

PreferenceScreen excludedAppsScreen = ExcludePreferenceScreen.getInstance(
this,
new ExcludePreferenceScreen.IsExcludedCallback() {
@Override
public boolean isExcluded(@NonNull AppPojo app) {
return app.isExcludedFromHistory();
}
},
R.string.ui_excluded_from_history_apps,
R.string.ui_excluded_apps_dialog_title,
AppPojo::isExcludedFromHistory,
new ExcludePreferenceScreen.OnExcludedListener() {
@Override
public void onExcluded(final @NonNull AppPojo app) {
Expand All @@ -443,9 +435,7 @@ public void onExcluded(final @NonNull AppPojo app) {
public void onIncluded(final @NonNull AppPojo app) {
dataHandler.removeFromExcludedFromHistory(app);
}
},
R.string.ui_excluded_from_history_apps,
R.string.ui_excluded_apps_dialog_title
}
);

PreferenceGroup category = (PreferenceGroup) findPreference("exclude_apps_category");
Expand All @@ -461,12 +451,9 @@ private void addExcludedShortcutAppSettings() {

PreferenceScreen excludedAppsScreen = ExcludePreferenceScreen.getInstance(
this,
new ExcludePreferenceScreen.IsExcludedCallback() {
@Override
public boolean isExcluded(@NonNull AppPojo app) {
return app.isExcludedShortcuts();
}
},
R.string.ui_excluded_from_shortcuts_apps,
R.string.ui_excluded_apps_dialog_title,
AppPojo::isExcludedShortcuts,
new ExcludePreferenceScreen.OnExcludedListener() {
@Override
public void onExcluded(final @NonNull AppPojo app) {
Expand All @@ -477,9 +464,7 @@ public void onExcluded(final @NonNull AppPojo app) {
public void onIncluded(final @NonNull AppPojo app) {
dataHandler.removeFromExcludedShortcutApps(app);
}
},
R.string.ui_excluded_from_shortcuts_apps,
R.string.ui_excluded_apps_dialog_title
}
);

PreferenceGroup category = (PreferenceGroup) findPreference("exclude_apps_category");
Expand Down Expand Up @@ -532,9 +517,6 @@ private void addCustomSearchProvidersDelete(final SharedPreferences prefs) {
Set<String> availableSearchProviders = SearchProvider.getAvailableSearchProviders(this, prefs);
Set<String> updatedProviders = SearchProvider.getAvailableSearchProviders(this, prefs);

if (availableSearchProviders == null)
return false;

for (String searchProvider : availableSearchProviders) {
for (String providerToDelete : searchProvidersToDelete) {
if (searchProvider.startsWith(providerToDelete + "|")) {
Expand Down Expand Up @@ -723,15 +705,12 @@ private void fixSummaries() {
if (historyLength < 300) {
getPreferenceScreen().removePreference(rateApp);
} else {
rateApp.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse("market://details?id=" + getApplicationContext().getPackageName()));
startActivity(intent);

return true;
}
rateApp.setOnPreferenceClickListener(preference -> {
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse("market://details?id=" + getApplicationContext().getPackageName()));
startActivity(intent);

return true;
});
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,16 @@ public class ContactsProvider extends Provider<ContactsPojo> {

@Override
public void onChange(boolean selfChange) {
Log.v(TAG, "Contact changed, reloading provider.");
onChange(selfChange, null);
}

@Override
public void onChange(boolean selfChange, @Nullable Uri uri) {
Log.v(TAG, "Contact changed, reloading provider: " + uri);
onChange(selfChange, uri, 0);
}

@Override
public void onChange(boolean selfChange, @Nullable Uri uri, int flags) {
Log.v(TAG, "Contact changed, reloading provider: " + uri + ", flags: " + flags);
onChange(selfChange, Collections.singletonList(uri), flags);
}

Expand Down
64 changes: 30 additions & 34 deletions app/src/main/java/fr/neamar/kiss/forwarder/TagsMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ListAdapter;
import android.widget.TextView;
import android.widget.Toast;

Expand Down Expand Up @@ -220,57 +219,54 @@ public ListPopup showMenu(final View anchor) {
if (popupMenu == null) {
Context context = anchor.getContext();
popupMenu = new ListPopup(context);
TagsMenu.MenuAdapter adapter = new TagsMenu.MenuAdapter();
TagsMenu.MenuAdapter menuAdapter = new TagsMenu.MenuAdapter();

SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);

//build menu
adapter.add(new TagsMenu.MenuItemTitle(context, R.string.popup_tags_title));
menuAdapter.add(new TagsMenu.MenuItemTitle(context, R.string.popup_tags_title));
for (String tag : tagList) {
adapter.add(new TagsMenu.MenuItemTag(tag));
menuAdapter.add(new TagsMenu.MenuItemTag(tag));
}

// remember where the title should go
int actionsTitlePosition = adapter.getCount();
int actionsTitlePosition = menuAdapter.getCount();
if (!prefs.getBoolean("history-onclick", false))
adapter.add(new TagsMenu.MenuItemBtn(context, R.string.show_history));
menuAdapter.add(new TagsMenu.MenuItemBtn(context, R.string.show_history));
if (prefs.getBoolean("pref-show-untagged", false))
adapter.add(new TagsMenu.MenuItemBtn(context, R.string.show_untagged));
menuAdapter.add(new TagsMenu.MenuItemBtn(context, R.string.show_untagged));
// insert title only if at least an action was added
if (actionsTitlePosition != adapter.getCount())
adapter.add(actionsTitlePosition, new TagsMenu.MenuItemTitle(context, R.string.popup_tags_actions));
if (actionsTitlePosition != menuAdapter.getCount())
menuAdapter.add(actionsTitlePosition, new TagsMenu.MenuItemTitle(context, R.string.popup_tags_actions));

adapter.add(new TagsMenu.MenuItemDivider());
adapter.add(new TagsMenu.MenuItemBtn(context, R.string.ctx_menu));
menuAdapter.add(new TagsMenu.MenuItemDivider());
menuAdapter.add(new TagsMenu.MenuItemBtn(context, R.string.ctx_menu));

// set popup interaction rules
popupMenu.setAdapter(adapter);
popupMenu.setAdapter(menuAdapter);
popupMenu.setDismissOnItemClick(isAutoDismiss());
popupMenu.setOnItemClickListener(new ListPopup.OnItemClickListener() {
@Override
public void onItemClick(ListAdapter adapter, View view, int position) {
Object adapterItem = adapter.getItem(position);
if (adapterItem instanceof TagsMenu.MenuItemTag) {
TagsMenu.MenuItemTag item = (TagsMenu.MenuItemTag) adapterItem;
// show only apps that match this tag
mainActivity.showMatchingTags(item.tag);
} else if (adapterItem instanceof TagsMenu.MenuItemBtn) {
int nameRes = ((TagsMenu.MenuItemBtn) adapterItem).nameRes;
if (nameRes == R.string.ctx_menu) {
if (popupMenu != null)
popupMenu.dismiss();
popupMenu = null;
anchor.showContextMenu();
} else if (nameRes == R.string.show_history) {
mainActivity.showHistory();
} else if (nameRes == R.string.show_untagged) {
mainActivity.showUntagged();
}
popupMenu.setOnItemClickListener((adapter, view, position) -> {
Object adapterItem = adapter.getItem(position);
if (adapterItem instanceof MenuItemTag) {
MenuItemTag item = (MenuItemTag) adapterItem;
// show only apps that match this tag
mainActivity.showMatchingTags(item.tag);
} else if (adapterItem instanceof MenuItemBtn) {
int nameRes = ((MenuItemBtn) adapterItem).nameRes;
if (nameRes == R.string.ctx_menu) {
if (popupMenu != null)
popupMenu.dismiss();
popupMenu = null;
anchor.showContextMenu();
} else if (nameRes == R.string.show_history) {
mainActivity.showHistory();
} else if (nameRes == R.string.show_untagged) {
mainActivity.showUntagged();
}
}
});
popupMenu.setOnItemLongClickListener((adapter1, view, position) -> {
Object adapterItem = adapter1.getItem(position);
popupMenu.setOnItemLongClickListener((adapter, view, position) -> {
Object adapterItem = adapter.getItem(position);
if (adapterItem instanceof MenuItemTag) {
MenuItemTag item = (MenuItemTag) adapterItem;
String msg = mainActivity.getResources().getString(R.string.toast_favorites_added);
Expand Down
Loading

0 comments on commit 37712b8

Please sign in to comment.