Skip to content

Commit

Permalink
Merge branch 'TrianguloY:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
mariachrisochoou authored Jun 5, 2024
2 parents 1a4f3c1 + fee2edd commit 13e9476
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.trianguloy.urlchecker.modules.companions;

import com.trianguloy.urlchecker.R;
import com.trianguloy.urlchecker.utilities.Enums;

/** A generic size enum */
public enum Size implements Enums.IdEnum, Enums.StringEnum {
NONE(0, R.string.none),
SMALL(1, R.string.small),
NORMAL(2, R.string.normal),
BIG(3, R.string.big),
;

private final int id;
private final int string;

Size(int id, int string) {
this.id = id;
this.string = string;
}

@Override
public int getId() {
return id;
}

@Override
public int getStringResource() {
return string;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import static java.util.Objects.requireNonNullElse;

import android.content.ComponentName;
import android.content.pm.PackageManager;
import android.os.Build;
import android.view.View;
Expand Down Expand Up @@ -91,12 +92,17 @@ private void showData() {
SEPARATOR,

"queryIntentActivities:",
getActivity().getPackageManager().queryIntentActivities(UrlUtils.getViewIntent(urlData.url, null), Build.VERSION.SDK_INT >= Build.VERSION_CODES.M ? PackageManager.MATCH_ALL : 0).toString(),
IntentApp.getOtherPackages(UrlUtils.getViewIntent(urlData.url, null), getActivity()).toString(),

SEPARATOR,

"queryIntentActivityOptions:",
IntentApp.getOtherPackages(UrlUtils.getViewIntent(urlData.url, null), getActivity()).toString(),
getActivity().getPackageManager().queryIntentActivityOptions(
new ComponentName(getActivity(), MainDialog.class.getName()),
null,
UrlUtils.getViewIntent(urlData.url, null),
Build.VERSION.SDK_INT >= Build.VERSION_CODES.M ? PackageManager.MATCH_ALL : 0
).toString(),

SEPARATOR,

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import com.trianguloy.urlchecker.modules.companions.Flags;
import com.trianguloy.urlchecker.modules.companions.Incognito;
import com.trianguloy.urlchecker.modules.companions.LastOpened;
import com.trianguloy.urlchecker.modules.companions.Size;
import com.trianguloy.urlchecker.url.UrlData;
import com.trianguloy.urlchecker.utilities.generics.GenericPref;
import com.trianguloy.urlchecker.utilities.methods.AndroidUtils;
Expand Down Expand Up @@ -60,6 +61,10 @@ public static GenericPref.Bool MERGECOPY_PREF(Context cntx) {
return new GenericPref.Bool("open_mergeCopy", false, cntx);
}

public static GenericPref.Enumeration<Size> ICONSIZE_PREF(Context cntx) {
return new GenericPref.Enumeration<>("open_iconsize", Size.NORMAL, Size.class, cntx);
}

@Override
public String getId() {
return "open";
Expand Down Expand Up @@ -89,6 +94,7 @@ class OpenDialog extends AModuleDialog {
private final GenericPref.Bool noReferrerPref;
private final GenericPref.Bool rejectedPref;
private final GenericPref.Bool mergeCopyPref;
private final GenericPref.Enumeration<Size> iconSizePref;

private final LastOpened lastOpened;
private final CTabs cTabs;
Expand All @@ -114,6 +120,7 @@ public OpenDialog(MainDialog dialog) {
noReferrerPref = OpenModule.NOREFERRER_PREF(dialog);
rejectedPref = OpenModule.REJECTED_PREF(dialog);
mergeCopyPref = OpenModule.MERGECOPY_PREF(dialog);
iconSizePref = OpenModule.ICONSIZE_PREF(dialog);
}

@Override
Expand Down Expand Up @@ -208,7 +215,7 @@ private void updateSpinner(String url) {
var label = intentApps.get(0).getLabel(getActivity());
// label = getActivity().getString(R.string.mOpen_with, label);
btn_open.setText(label);
btn_open.setCompoundDrawables(intentApps.get(0).getIcon(getActivity()), null, null, null);
btn_open.setCompoundDrawables(intentApps.get(0).getIcon(getActivity(), iconSizePref.get()), null, null, null);
AndroidUtils.setEnabled(openParent, true);
btn_open.setEnabled(true);
menu.clear();
Expand Down Expand Up @@ -335,6 +342,7 @@ public void onInitialize(View views) {
OpenModule.REJECTED_PREF(getActivity()).attachToSwitch(views.findViewById(R.id.rejected));
LastOpened.PERDOMAIN_PREF(getActivity()).attachToSwitch(views.findViewById(R.id.perDomain));
OpenModule.MERGECOPY_PREF(getActivity()).attachToSwitch(views.findViewById(R.id.mergeCopy_pref));
OpenModule.ICONSIZE_PREF(getActivity()).attachToSpinner(views.findViewById(R.id.iconsize_pref), null);
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import android.graphics.drawable.Drawable;
import android.os.Build;

import com.trianguloy.urlchecker.dialogs.MainDialog;
import com.trianguloy.urlchecker.modules.companions.Size;

import java.util.ArrayList;
import java.util.HashMap;
Expand All @@ -27,14 +27,17 @@ public class IntentApp {
*/
public static List<IntentApp> getOtherPackages(Intent baseIntent, Context cntx) {
// get all packages
var resolveInfos = cntx.getPackageManager().queryIntentActivityOptions(
new ComponentName(cntx, MainDialog.class.getName()),
null,
var resolveInfos = cntx.getPackageManager().queryIntentActivities(
baseIntent,
Build.VERSION.SDK_INT >= Build.VERSION_CODES.M ? PackageManager.MATCH_ALL : 0);

var intentApps = new ArrayList<IntentApp>();
for (var resolveInfo : resolveInfos) intentApps.add(new IntentApp(resolveInfo));
for (var resolveInfo : resolveInfos) {
// filter the current app
if (!resolveInfo.activityInfo.packageName.equals(cntx.getPackageName())) {
intentApps.add(new IntentApp(resolveInfo));
}
}
return intentApps;
}

Expand Down Expand Up @@ -66,11 +69,19 @@ public CharSequence getLabel(Context activity) {
}

/** Returns the drawable, cached */
public Drawable getIcon(Context activity) {
public Drawable getIcon(Context activity, Size size) {
var dim = switch (size) {
case NONE -> 0;
case SMALL -> 25;
case NORMAL -> 50;
case BIG -> 75;
};
if (dim == 0) return null;

var component = getComponent();
if (!iconsCache.containsKey(component)) {
var icon = resolveInfo.loadIcon(activity.getPackageManager());
icon.setBounds(0, 0, 50, 50);
icon.setBounds(0, 0, dim, dim);
iconsCache.put(component, icon);
}
return iconsCache.get(component);
Expand Down
20 changes: 20 additions & 0 deletions app/src/main/res/layout/config_open.xml
Original file line number Diff line number Diff line change
Expand Up @@ -99,4 +99,24 @@
android:layout_marginTop="@dimen/smallPadding"
android:text="@string/mOpen_rejected" />

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="@dimen/smallPadding"
android:orientation="horizontal">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:text="@string/mOpen_iconSize" />

<Spinner
android:id="@+id/iconsize_pref"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1" />

</LinearLayout>

</LinearLayout>
4 changes: 4 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,9 @@ Hope you find the app useful! And don't hesitate to suggest features, report bug
<string name="back">Back</string>
<string name="dismiss">Dismiss</string>
<string name="noLinks">No links detected</string>
<string name="small">Small</string>
<string name="normal">Normal</string>
<string name="big">Big</string>
<!--
json
-->
Expand Down Expand Up @@ -194,6 +197,7 @@ Note: if you edit the patterns, new built-in patterns from app updates will not
<string name="mOpen_noReferrer">Hide the source app (referrer)</string>
<string name="mOpen_rejected">Hide app if URL was rejected (an app immediately requests to open the same URL it was opened with). Doesn\'t affect sharing.</string>
<string name="mOpen_mergeCopy">Merge Copy and Share buttons (long press to copy)</string>
<string name="mOpen_iconSize">Icon size</string>
<string name="mOpen_with">Open with %s</string>
<string name="mOpen_open">Open</string>
<string name="mOpen_share">Share</string>
Expand Down

0 comments on commit 13e9476

Please sign in to comment.