mirror of
https://github.com/TrianguloY/UrlChecker.git
synced 2024-09-19 20:02:16 +02:00
CustomTabs toggleable button.
CustomTabs empty service so other apps 'think' this can open custom tabs.
This commit is contained in:
parent
02c5cdf0d5
commit
8987c4b777
@ -11,7 +11,7 @@
|
||||
android:supportsRtl="true"
|
||||
android:theme="@android:style/Theme.DeviceDefault"
|
||||
android:usesCleartextTraffic="true">
|
||||
<activity android:name=".activities.AboutActivity"></activity>
|
||||
<activity android:name=".activities.AboutActivity" />
|
||||
<activity android:name=".activities.ConfigActivity" />
|
||||
<activity
|
||||
android:name=".dialogs.MainDialog"
|
||||
@ -40,6 +40,14 @@
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
|
||||
<service
|
||||
android:name=".services.CustomTabs"
|
||||
android:exported="true">
|
||||
<intent-filter>
|
||||
<action android:name="android.support.customtabs.action.CustomTabsService" />
|
||||
</intent-filter>
|
||||
</service>
|
||||
</application>
|
||||
|
||||
</manifest>
|
@ -1,10 +1,13 @@
|
||||
package com.trianguloy.urlchecker.modules.list;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.content.ClipData;
|
||||
import android.content.ClipboardManager;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
@ -54,13 +57,17 @@ public class OpenModule extends AModuleData {
|
||||
|
||||
class OpenDialog extends AModuleDialog implements View.OnClickListener, PopupMenu.OnMenuItemClickListener, View.OnLongClickListener {
|
||||
|
||||
private static final String CTABS_EXTRA = "android.support.customtabs.extra.SESSION";
|
||||
|
||||
private LastOpened lastOpened;
|
||||
private boolean ctabs = false;
|
||||
|
||||
private List<String> packages;
|
||||
private Button btn_open;
|
||||
private ImageButton btn_openWith;
|
||||
private Menu menu;
|
||||
private PopupMenu popup;
|
||||
private ImageButton btn_ctabs;
|
||||
|
||||
public OpenDialog(MainDialog dialog) {
|
||||
super(dialog);
|
||||
@ -73,10 +80,22 @@ class OpenDialog extends AModuleDialog implements View.OnClickListener, PopupMen
|
||||
|
||||
@Override
|
||||
public void onInitialize(View views) {
|
||||
btn_ctabs = views.findViewById(R.id.ctabs);
|
||||
btn_ctabs.setOnClickListener(this);
|
||||
btn_ctabs.setOnLongClickListener(this);
|
||||
setCtabs(getActivity().getIntent().hasExtra(CTABS_EXTRA));
|
||||
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR2) {
|
||||
btn_ctabs.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
btn_open = views.findViewById(R.id.open);
|
||||
btn_open.setOnClickListener(this);
|
||||
btn_open.setOnLongClickListener(this);
|
||||
|
||||
btn_openWith = views.findViewById(R.id.open_with);
|
||||
btn_openWith.setOnClickListener(this);
|
||||
|
||||
View btn_share = views.findViewById(R.id.share);
|
||||
btn_share.setOnClickListener(this);
|
||||
btn_share.setOnLongClickListener(this);
|
||||
@ -99,6 +118,9 @@ class OpenDialog extends AModuleDialog implements View.OnClickListener, PopupMen
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
switch (v.getId()) {
|
||||
case R.id.ctabs:
|
||||
toggleCtabs();
|
||||
break;
|
||||
case R.id.open:
|
||||
openUrl(0);
|
||||
break;
|
||||
@ -114,6 +136,12 @@ class OpenDialog extends AModuleDialog implements View.OnClickListener, PopupMen
|
||||
@Override
|
||||
public boolean onLongClick(View v) {
|
||||
switch (v.getId()) {
|
||||
case R.id.ctabs:
|
||||
Toast.makeText(getActivity(), "Toggle Custom Tabs feature", Toast.LENGTH_SHORT).show();
|
||||
break;
|
||||
case R.id.open:
|
||||
intentDetails();
|
||||
break;
|
||||
case R.id.share:
|
||||
copyToClipboard();
|
||||
break;
|
||||
@ -183,10 +211,29 @@ class OpenDialog extends AModuleDialog implements View.OnClickListener, PopupMen
|
||||
intent.setData(Uri.parse(getUrl()));
|
||||
intent.setComponent(null);
|
||||
intent.setPackage(chosed);
|
||||
|
||||
|
||||
} else {
|
||||
// replace with new VIEW intent
|
||||
intent = UrlUtilities.getViewIntent(getUrl(), chosed);
|
||||
}
|
||||
|
||||
if (ctabs && !intent.hasExtra(CTABS_EXTRA)) {
|
||||
// enable Custom tabs
|
||||
|
||||
// https://developer.chrome.com/multidevice/android/customtabs
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
|
||||
Bundle extras = new Bundle();
|
||||
extras.putBinder(CTABS_EXTRA, null); // Set to null for no session
|
||||
intent.putExtras(extras);
|
||||
}
|
||||
}
|
||||
|
||||
if (!ctabs && intent.hasExtra(CTABS_EXTRA)) {
|
||||
// disable ctabs
|
||||
intent.removeExtra(CTABS_EXTRA);
|
||||
}
|
||||
|
||||
getActivity().startActivity(intent);
|
||||
}
|
||||
|
||||
@ -223,4 +270,28 @@ class OpenDialog extends AModuleDialog implements View.OnClickListener, PopupMen
|
||||
Toast.makeText(getActivity(), R.string.mOpen_clipboard, Toast.LENGTH_LONG).show();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Toggle the custom tabs state
|
||||
*/
|
||||
private void toggleCtabs() {
|
||||
setCtabs(!ctabs);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the custom tabs state
|
||||
*/
|
||||
private void setCtabs(boolean state) {
|
||||
btn_ctabs.setImageResource(state ? R.drawable.ctabs_on : R.drawable.ctabs_off);
|
||||
ctabs = state;
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows the uri of the current intent
|
||||
*/
|
||||
private void intentDetails() {
|
||||
new AlertDialog.Builder(getActivity())
|
||||
.setMessage(getActivity().getIntent().toUri(0))
|
||||
.show();
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,105 @@
|
||||
package com.trianguloy.urlchecker.services;
|
||||
|
||||
import android.app.Service;
|
||||
import android.content.Intent;
|
||||
import android.os.IBinder;
|
||||
import android.util.Log;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.trianguloy.urlchecker.BuildConfig;
|
||||
|
||||
/**
|
||||
* Empty service for fake custom tabs.
|
||||
* <p>
|
||||
* referrer: https://chromium.googlesource.com/chromium/src/+/b71e98cdf14f18cb967a73857826f6e8c568cea0/chrome/android/java/src/org/chromium/chrome/browser/customtabs/CustomTabsConnectionService.java
|
||||
*/
|
||||
public class CustomTabs extends Service {
|
||||
|
||||
|
||||
@Override
|
||||
public void onCreate() {
|
||||
log("onCreate");
|
||||
super.onCreate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int onStartCommand(Intent intent, int flags, int startId) {
|
||||
log("onStartCommand");
|
||||
return super.onStartCommand(intent, flags, startId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
log("onDestroy");
|
||||
super.onDestroy();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBinder onBind(Intent intent) {
|
||||
log("onBind");
|
||||
return null;
|
||||
// return new IBinder() {
|
||||
// @Override
|
||||
// public String getInterfaceDescriptor() throws RemoteException {
|
||||
// log("getInterfaceDescriptor");
|
||||
// return null;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public boolean pingBinder() {
|
||||
// log("pingBinder");
|
||||
// return false;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public boolean isBinderAlive() {
|
||||
// log("isBinderAlive");
|
||||
// return false;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public IInterface queryLocalInterface(String descriptor) {
|
||||
// log("queryLocalInterface");
|
||||
// return null;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void dump(FileDescriptor fd, String[] args) throws RemoteException {
|
||||
// log("dump");
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void dumpAsync(FileDescriptor fd, String[] args) throws RemoteException {
|
||||
// log("dumpAsync");
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public boolean transact(int code, Parcel data, Parcel reply, int flags) throws RemoteException {
|
||||
// log("transact");
|
||||
// return false;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void linkToDeath(DeathRecipient recipient, int flags) throws RemoteException {
|
||||
// log("linkToDeath");
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public boolean unlinkToDeath(DeathRecipient recipient, int flags) {
|
||||
// log("unlinkToDeath");
|
||||
// return false;
|
||||
// }
|
||||
// };
|
||||
}
|
||||
|
||||
// ------------------- logging -------------------
|
||||
|
||||
private static final String TAG = "CT-service";
|
||||
|
||||
private void log(String message) {
|
||||
if (BuildConfig.DEBUG) {
|
||||
Toast.makeText(this, TAG + ": " + message, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
Log.d(TAG, message);
|
||||
}
|
||||
}
|
20
app/src/main/res/drawable/ctabs_off.xml
Normal file
20
app/src/main/res/drawable/ctabs_off.xml
Normal file
@ -0,0 +1,20 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:autoMirrored="true"
|
||||
android:tint="#FFFFFF"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24">
|
||||
<path
|
||||
android:fillColor="@android:color/white"
|
||||
android:pathData="M7,4h10v15h-10z" />
|
||||
<path
|
||||
android:fillColor="@android:color/white"
|
||||
android:pathData="M3,6h2v11h-2z" />
|
||||
<path
|
||||
android:fillColor="@android:color/white"
|
||||
android:pathData="M19,6h2v11h-2z" />
|
||||
<path
|
||||
android:fillColor="@android:color/white"
|
||||
android:pathData="M2.5 5.27l16.22 16.23l1.28-1.27l-16.23-16.23z" />
|
||||
</vector>
|
16
app/src/main/res/drawable/ctabs_on.xml
Normal file
16
app/src/main/res/drawable/ctabs_on.xml
Normal file
@ -0,0 +1,16 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:tint="#FFFFFF"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24">
|
||||
<path
|
||||
android:fillColor="@android:color/white"
|
||||
android:pathData="M7,4h10v15h-10z" />
|
||||
<path
|
||||
android:fillColor="@android:color/white"
|
||||
android:pathData="M3,6h2v11h-2z" />
|
||||
<path
|
||||
android:fillColor="@android:color/white"
|
||||
android:pathData="M19,6h2v11h-2z" />
|
||||
</vector>
|
@ -3,6 +3,12 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<ImageButton
|
||||
android:id="@+id/ctabs"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:src="@drawable/ctabs_off" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/open"
|
||||
android:layout_width="wrap_content"
|
||||
|
Loading…
Reference in New Issue
Block a user