mirror of
https://github.com/TrianguloY/UrlChecker.git
synced 2024-09-19 11:52:14 +02:00
Implemented preset flags feature #37
Strings, spanish strings, icons, config layout, dialog layout Added advanced options to make room for the preset flags button
This commit is contained in:
parent
83a75fe466
commit
188d79de5e
@ -4,6 +4,7 @@ import android.content.ClipData;
|
||||
import android.content.ClipboardManager;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.graphics.Path;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
@ -12,6 +13,7 @@ import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.ImageButton;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.PopupMenu;
|
||||
import android.widget.Toast;
|
||||
|
||||
@ -58,10 +60,49 @@ public class OpenModule extends AModuleData {
|
||||
}
|
||||
}
|
||||
|
||||
enum PresetFlagsValues {
|
||||
AUTO(Key.AUTO),
|
||||
EXCLUDE_RECENTS(Key.EXCLUDE_RECENTS),
|
||||
INSIDE(Key.INSIDE);
|
||||
|
||||
public final int key;
|
||||
static private PresetFlagsValues[] values = null;
|
||||
|
||||
PresetFlagsValues(int key) {
|
||||
this.key = key;
|
||||
}
|
||||
|
||||
// Combinations of flags are always unique, this way is easier to read and keep track of
|
||||
private static class Key {
|
||||
public static final int AUTO = 0xFFFFFFFF; // Will never match
|
||||
public static final int EXCLUDE_RECENTS = Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS;
|
||||
public static final int INSIDE = Intent.FLAG_ACTIVITY_NEW_TASK |
|
||||
Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS |
|
||||
Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT;
|
||||
}
|
||||
|
||||
// To get enum out of key
|
||||
public static PresetFlagsValues getFlag(int key){
|
||||
if (values == null){ // init if necessary
|
||||
values = PresetFlagsValues.values();
|
||||
}
|
||||
for (PresetFlagsValues e: values) {
|
||||
if (e.key == key){
|
||||
return e;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static GenericPref.Int CTABS_PREF() {
|
||||
return new GenericPref.Int("open_ctabs", CtabsValues.AUTO.key);
|
||||
}
|
||||
|
||||
public static GenericPref.Int PRESETFLAGS_PREF() {
|
||||
return new GenericPref.Int("open_presetflags", PresetFlagsValues.AUTO.key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getId() {
|
||||
return "open";
|
||||
@ -97,16 +138,26 @@ class OpenDialog extends AModuleDialog implements View.OnClickListener, PopupMen
|
||||
private final GenericPref.Int ctabsPref = OpenModule.CTABS_PREF();
|
||||
private boolean ctabs = false;
|
||||
|
||||
private final GenericPref.Int presetFlagsPref = OpenModule.PRESETFLAGS_PREF();
|
||||
private OpenModule.PresetFlagsValues presetState;
|
||||
private OpenModule.PresetFlagsValues presetMatch;
|
||||
private final OpenModule.PresetFlagsValues[] presetValues = OpenModule.PresetFlagsValues.values();
|
||||
|
||||
private List<String> packages;
|
||||
private Button btn_open;
|
||||
private ImageButton btn_openWith;
|
||||
private Menu menu;
|
||||
private PopupMenu popup;
|
||||
private ImageButton btn_ctabs;
|
||||
private ImageButton btn_presetflags;
|
||||
private ImageButton expand;
|
||||
private LinearLayout box;
|
||||
|
||||
|
||||
public OpenDialog(MainDialog dialog) {
|
||||
super(dialog);
|
||||
ctabsPref.init(dialog);
|
||||
presetFlagsPref.init(dialog);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -130,10 +181,28 @@ class OpenDialog extends AModuleDialog implements View.OnClickListener, PopupMen
|
||||
btn_ctabs.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
btn_presetflags = views.findViewById(R.id.presetflags);
|
||||
btn_presetflags.setOnClickListener(this);
|
||||
btn_presetflags.setOnLongClickListener(this);
|
||||
// Checks if intent flags match any of the presets
|
||||
final int flags = intent.getFlags();
|
||||
presetMatch = OpenModule.PresetFlagsValues.getFlag(flags);
|
||||
OpenModule.PresetFlagsValues preference = OpenModule.PresetFlagsValues.getFlag(presetFlagsPref.get());
|
||||
|
||||
setPresetState(presetFlagsPref.get() != OpenModule.PresetFlagsValues.AUTO.key ? // if preference is not auto
|
||||
(preference != null ? preference : OpenModule.PresetFlagsValues.AUTO) : // set state as preference if not null
|
||||
(presetMatch != null ? presetMatch : OpenModule.PresetFlagsValues.AUTO));
|
||||
|
||||
btn_open = views.findViewById(R.id.open);
|
||||
btn_open.setOnClickListener(this);
|
||||
btn_open.setOnLongClickListener(this);
|
||||
|
||||
box = views.findViewById(R.id.advanced);
|
||||
expand = views.findViewById(R.id.expand);
|
||||
expand.setOnClickListener(this);
|
||||
box.setVisibility(View.VISIBLE);
|
||||
toggleAdvancedOpts();
|
||||
|
||||
btn_openWith = views.findViewById(R.id.open_with);
|
||||
btn_openWith.setOnClickListener(this);
|
||||
|
||||
@ -162,6 +231,12 @@ class OpenDialog extends AModuleDialog implements View.OnClickListener, PopupMen
|
||||
case R.id.ctabs:
|
||||
toggleCtabs();
|
||||
break;
|
||||
case R.id.presetflags:
|
||||
rotatePresetFlags();
|
||||
break;
|
||||
case R.id.expand:
|
||||
toggleAdvancedOpts();
|
||||
break;
|
||||
case R.id.open:
|
||||
openUrl(0);
|
||||
break;
|
||||
@ -180,6 +255,9 @@ class OpenDialog extends AModuleDialog implements View.OnClickListener, PopupMen
|
||||
case R.id.ctabs:
|
||||
Toast.makeText(getActivity(), R.string.mOpen_tabsDesc, Toast.LENGTH_SHORT).show();
|
||||
break;
|
||||
case R.id.presetflags:
|
||||
Toast.makeText(getActivity(), R.string.mOpen_rotatePresetFlags, Toast.LENGTH_SHORT).show();
|
||||
break;
|
||||
case R.id.share:
|
||||
copyToClipboard();
|
||||
break;
|
||||
@ -275,6 +353,10 @@ class OpenDialog extends AModuleDialog implements View.OnClickListener, PopupMen
|
||||
intent.removeExtra(CTABS_EXTRA);
|
||||
}
|
||||
|
||||
if (presetState != OpenModule.PresetFlagsValues.AUTO) {
|
||||
intent.setFlags(presetState.key);
|
||||
}
|
||||
|
||||
PackageUtilities.startActivity(intent, R.string.toast_noApp, getActivity());
|
||||
}
|
||||
|
||||
@ -330,16 +412,61 @@ class OpenDialog extends AModuleDialog implements View.OnClickListener, PopupMen
|
||||
ctabs = state;
|
||||
}
|
||||
|
||||
/**
|
||||
* Rotates the preset flags state
|
||||
*/
|
||||
private void rotatePresetFlags() {
|
||||
int index = presetState.ordinal() + 1; // next state
|
||||
index = presetValues.length <= index ? 0 : index; // OOB check
|
||||
// If a match was found there is no need to iterate through the auto state
|
||||
index = presetMatch == null ? index :
|
||||
presetValues[index] == OpenModule.PresetFlagsValues.AUTO ? index + 1 : index;
|
||||
index = presetValues.length <= index ? 0 : index; // OOB check
|
||||
setPresetState(presetValues[index]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the preset flags state
|
||||
* @param state
|
||||
*/
|
||||
private void setPresetState(OpenModule.PresetFlagsValues state) {
|
||||
int image;
|
||||
switch (state){
|
||||
case INSIDE:
|
||||
image = R.drawable.mopen_inside;
|
||||
break;
|
||||
case EXCLUDE_RECENTS:
|
||||
image = R.drawable.mopen_exclude_recents;
|
||||
break;
|
||||
case AUTO:
|
||||
default:
|
||||
image = R.drawable.mopen_inside;
|
||||
}
|
||||
btn_presetflags.setImageResource(image);
|
||||
presetState = state;
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows/hides the advanced options
|
||||
*/
|
||||
private void toggleAdvancedOpts(){
|
||||
box.setVisibility(box.getVisibility() == View.GONE ? View.VISIBLE : View.GONE);
|
||||
expand.setImageResource(box.getVisibility() == View.VISIBLE ?
|
||||
R.drawable.arrow_down :
|
||||
R.drawable.arrow_right);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class OpenConfig extends AModuleConfig {
|
||||
|
||||
private final GenericPref.Int ctabsPref = OpenModule.CTABS_PREF();
|
||||
private final GenericPref.Int presetFlagsPref = OpenModule.PRESETFLAGS_PREF();
|
||||
|
||||
public OpenConfig(ConfigActivity activity) {
|
||||
super(activity);
|
||||
ctabsPref.init(activity);
|
||||
presetFlagsPref.init(activity);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -365,5 +492,15 @@ class OpenConfig extends AModuleConfig {
|
||||
cntx.getString(R.string.disabled)));
|
||||
ctabsPref.attachToSpinner(views.findViewById(R.id.ctabs_pref),
|
||||
ctabsElements);
|
||||
|
||||
List<GenericPref.Int.AdapterPair> presetFlagsElements = new LinkedList<>();
|
||||
presetFlagsElements.add(new GenericPref.Int.AdapterPair(OpenModule.PresetFlagsValues.AUTO.key,
|
||||
cntx.getString(R.string.auto)));
|
||||
presetFlagsElements.add(new GenericPref.Int.AdapterPair(OpenModule.PresetFlagsValues.INSIDE.key,
|
||||
cntx.getString(R.string.mOpen_optionInside)));
|
||||
presetFlagsElements.add(new GenericPref.Int.AdapterPair(OpenModule.PresetFlagsValues.EXCLUDE_RECENTS.key,
|
||||
cntx.getString(R.string.mOpen_optionExcludeRecents)));
|
||||
presetFlagsPref.attachToSpinner(views.findViewById(R.id.presetflags_pref),
|
||||
presetFlagsElements);
|
||||
}
|
||||
}
|
10
app/src/main/res/drawable/mopen_auto.xml
Normal file
10
app/src/main/res/drawable/mopen_auto.xml
Normal file
@ -0,0 +1,10 @@
|
||||
<vector android:autoMirrored="true"
|
||||
android:height="24dp"
|
||||
android:viewportHeight="24"
|
||||
android:viewportWidth="24"
|
||||
android:width="24dp"
|
||||
xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<path
|
||||
android:fillColor="@color/app"
|
||||
android:pathData="M9.4,16.6L4.8,12l4.6,-4.6L8,6l-6,6 6,6 1.4,-1.4zM14.6,16.6l4.6,-4.6 -4.6,-4.6L16,6l6,6 -6,6 -1.4,-1.4z" />
|
||||
</vector>
|
13
app/src/main/res/drawable/mopen_exclude_recents.xml
Normal file
13
app/src/main/res/drawable/mopen_exclude_recents.xml
Normal file
@ -0,0 +1,13 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24">
|
||||
<path
|
||||
android:fillColor="@color/app"
|
||||
android:pathData="M3,4h8v15h-8z" />
|
||||
<path
|
||||
android:fillColor="@color/app"
|
||||
android:pathData="M13,4h8v15h-8z" />
|
||||
|
||||
</vector>
|
9
app/src/main/res/drawable/mopen_inside.xml
Normal file
9
app/src/main/res/drawable/mopen_inside.xml
Normal file
@ -0,0 +1,9 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24">
|
||||
<path
|
||||
android:fillColor="@color/app"
|
||||
android:pathData="M7,4h10v15h-10z" />
|
||||
</vector>
|
@ -21,4 +21,15 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textView3"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/mOpen_presetFlagsSetting" />
|
||||
|
||||
<Spinner
|
||||
android:id="@+id/presetflags_pref"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
</LinearLayout>
|
@ -1,51 +1,85 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center_vertical">
|
||||
|
||||
<ImageButton
|
||||
android:id="@+id/ctabs"
|
||||
style="?android:attr/buttonBarButtonStyle"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:src="@drawable/ctabs_off" />
|
||||
android:gravity="center_vertical"
|
||||
android:orientation="vertical">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="0dp"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:background="@drawable/open_both"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<Button
|
||||
android:id="@+id/open"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:background="@drawable/open_left"
|
||||
android:minHeight="60dp"
|
||||
android:padding="5dp"
|
||||
android:text="@string/mOpen_open"
|
||||
android:textColor="?android:attr/colorBackground"
|
||||
android:textStyle="bold" />
|
||||
|
||||
<ImageButton
|
||||
android:id="@+id/open_with"
|
||||
android:id="@+id/expand"
|
||||
style="?android:attr/buttonBarButtonStyle"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:background="@drawable/open_right"
|
||||
android:paddingRight="1dp"
|
||||
android:src="@drawable/arrow_down"
|
||||
android:src="@drawable/arrow_right"
|
||||
android:tint="?attr/colorAccent" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:background="@drawable/open_both"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<Button
|
||||
android:id="@+id/open"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:background="@drawable/open_left"
|
||||
android:minHeight="60dp"
|
||||
android:paddingLeft="5dp"
|
||||
android:paddingRight="5dp"
|
||||
android:text="@string/mOpen_open"
|
||||
android:textColor="?android:attr/colorBackground"
|
||||
android:textStyle="bold" />
|
||||
|
||||
<ImageButton
|
||||
android:id="@+id/open_with"
|
||||
style="?android:attr/buttonBarButtonStyle"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:background="@drawable/open_right"
|
||||
android:paddingRight="1dp"
|
||||
android:src="@drawable/arrow_down"
|
||||
android:tint="?attr/colorAccent" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<Button
|
||||
android:id="@+id/share"
|
||||
style="?android:attr/buttonBarButtonStyle"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:text="@string/mOpen_share" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<Button
|
||||
android:id="@+id/share"
|
||||
style="?android:attr/buttonBarButtonStyle"
|
||||
android:layout_width="wrap_content"
|
||||
<LinearLayout
|
||||
android:id="@+id/advanced"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:text="@string/mOpen_share" />
|
||||
android:layout_weight="1"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<ImageButton
|
||||
android:id="@+id/ctabs"
|
||||
style="?android:attr/buttonBarButtonStyle"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:src="@drawable/ctabs_off" />
|
||||
|
||||
<ImageButton
|
||||
android:id="@+id/presetflags"
|
||||
style="?android:attr/buttonBarButtonStyle"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:src="@drawable/mopen_auto" />
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
@ -58,17 +58,26 @@ Nota: si editas los patrones, nuevos patrones incorporados en futuras actualizac
|
||||
|
||||
<string name="mOpen_name"><![CDATA[Abrir y compartir]]></string>
|
||||
<string name="mOpen_desc">"Contiene los siguientes botones (de izquierda a derecha):
|
||||
- Botón de 'custom tabs': activa/desactiva la característica de 'custom tabs'. Cuando se activa el navegador se debería abrir en un modo reducido 'lite'.
|
||||
- Boton de abrir: pulsa el nombre de la aplicación para abrir el enlace en ella. Si un enlace puede ser abierto por varias se mostrará una flecha para poder elegir.
|
||||
- Botón de compartir: Púlsalo para compartir el enlace. Mantenlo pulsado para copiarlo diréctamente en el navegador.
|
||||
Botones de las opciones avanzadas (de izquierda a derecha):
|
||||
- Botón de 'custom tabs': activa/desactiva la característica de 'custom tabs'. Cuando se activa el navegador se debería abrir en un modo reducido 'lite'.
|
||||
- Botón de plantilla al abrir: rota entre los diferentes modos para abrir la url:
|
||||
- Temporal: Después de abrir la url, cuando salga de la app esta se cerrará automáticamente.
|
||||
- Nueva ventana: Abre la app de forma independiente.
|
||||
Este módulo no puede ser deshabilitado."</string>
|
||||
<string name="mOpen_ctabsSetting">"Estado por defecto de 'Custom tabs':"</string>
|
||||
<string name="mOpen_presetFlagsSetting">Plantilla por defecto:</string>
|
||||
<string name="mOpen_optionExcludeRecents">Nueva ventana</string>
|
||||
<string name="mOpen_optionInside">Temporal</string>
|
||||
<string name="mOpen_with">Abrir con %s</string>
|
||||
<string name="mOpen_open">Abrir</string>
|
||||
<string name="mOpen_share">Compartir</string>
|
||||
<string name="mOpen_clipboard">Url copiada al portapapeles</string>
|
||||
<string name="mOpen_noapps">Sin aplicaciones</string>
|
||||
<string name="mOpen_tabsDesc">"Activa/desactiva 'custom tabs'"</string>
|
||||
<string name="mOpen_rotatePresetFlags">Rota las plantillas</string>
|
||||
|
||||
|
||||
<string name="mStatus_name">Código de estado</string>
|
||||
<string name="mStatus_desc">"Al pulsar el botón de comprobar, se realizará una peticion para obtener y mostrar el código de estado de la url.
|
||||
|
@ -59,17 +59,25 @@ Note: if you edit the patterns, new built-in patterns from app updates will not
|
||||
|
||||
<string name="mOpen_name"><![CDATA[Open & Share]]></string>
|
||||
<string name="mOpen_desc">"Contains the following buttons (left to right):
|
||||
- Custom Tabs button: toggle to enable/disable the custom tab feature. When enabled the browser should be opened in a 'lite' mode.
|
||||
- Open button: Press the app name to open the link on that app. If a link can be opened with multiple apps, an arrow will be shown to let you choose.
|
||||
- Share button: Press the button to share the link. Long press to quickly copy to clipboard.
|
||||
Advanced options buttons (left to right):
|
||||
- Custom Tabs button: toggle to enable/disable the custom tab feature. When enabled the browser should be opened in a 'lite' mode.
|
||||
- Open preset button: rotates between different modes to open the url:
|
||||
- Temporal: After opening the url, when you exit the app it will close.
|
||||
- New window: Opens the app independently.
|
||||
This module can't be disabled."</string>
|
||||
<string name="mOpen_ctabsSetting">Custom tabs default state:</string>
|
||||
<string name="mOpen_presetFlagsSetting">Open presets default state:</string>
|
||||
<string name="mOpen_optionExcludeRecents">New window</string>
|
||||
<string name="mOpen_optionInside">Temporal</string>
|
||||
<string name="mOpen_with">Open with %s</string>
|
||||
<string name="mOpen_open">Open</string>
|
||||
<string name="mOpen_share">Share</string>
|
||||
<string name="mOpen_clipboard">Url copied to clipboard</string>
|
||||
<string name="mOpen_noapps">No apps</string>
|
||||
<string name="mOpen_tabsDesc">Toggle Custom Tabs feature</string>
|
||||
<string name="mOpen_rotatePresetFlags">Rotate open presets</string>
|
||||
|
||||
<string name="mStatus_name">Status code</string>
|
||||
<string name="mStatus_desc">"By pressing the check button, a petition will be made to retrieve and display the site status code.
|
||||
|
Loading…
Reference in New Issue
Block a user