allow to pickup apps

This commit is contained in:
Thomas 2020-04-19 17:31:07 +02:00
parent 0f22ba8905
commit 4d668273f7
13 changed files with 449 additions and 47 deletions

View File

@ -54,11 +54,13 @@
<data android:mimeType="text/plain" />
</intent-filter>
</activity>
<activity
android:name="app.fedilab.nitterizeme.activities.InstanceActivity"
android:name=".activities.AppsPickerActivity"
android:noHistory="true"
android:theme="@style/Theme.AppCompat.Translucent"/>
<activity
android:name=".activities.InstanceActivity"
android:excludeFromRecents="true"
android:theme="@style/AppThemeDialog" />
<activity
@ -72,7 +74,7 @@
android:label="@string/app_name"
android:theme="@style/AppTheme" />
<activity
android:name="app.fedilab.nitterizeme.activities.WebviewPlayerActivity"
android:name=".activities.WebviewPlayerActivity"
android:configChanges="keyboardHidden|orientation|screenSize"
android:label="@string/app_name"
android:launchMode="singleTask"

View File

@ -0,0 +1,120 @@
package app.fedilab.nitterizeme.activities;
/* Copyright 2020 Thomas Schneider
*
* This file is a part of UntrackMe
*
* This program is free software; you can redistribute it and/or modify it under the terms of the
* GNU General Public License as published by the Free Software Foundation; either version 3 of the
* License, or (at your option) any later version.
*
* UntrackMe is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
* Public License for more details.
*
* You should have received a copy of the GNU General Public License along with UntrackMe; if not,
* see <http://www.gnu.org/licenses>. */
import android.app.Activity;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.widget.GridView;
import android.widget.RelativeLayout;
import java.util.ArrayList;
import java.util.List;
import app.fedilab.nitterizeme.R;
import app.fedilab.nitterizeme.adapters.AppPickerAdapter;
import app.fedilab.nitterizeme.entities.AppPicker;
import static app.fedilab.nitterizeme.helpers.Utils.KILL_ACTIVITY;
import static app.fedilab.nitterizeme.helpers.Utils.URL_APP_PICKER;
public class AppsPickerActivity extends Activity {
private GridView gridView;
private String url;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_pickup_app);
SharedPreferences sharedpreferences = getSharedPreferences(MainActivity.APP_PREFS, Context.MODE_PRIVATE);
if (getIntent() == null) {
finish();
}
Bundle b = getIntent().getExtras();
if (b == null) {
finish();
}
if (b != null) {
url = b.getString(URL_APP_PICKER, null);
}
if (url == null) {
finish();
}
//At this point we are sure that url is not null
Intent stopMainActivity = new Intent(KILL_ACTIVITY);
sendBroadcast(stopMainActivity);
Intent delegate = new Intent(Intent.ACTION_VIEW);
delegate.setDataAndType(Uri.parse(url), "text/html");
delegate.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
List<ResolveInfo> activities;
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) {
activities = getPackageManager().queryIntentActivities(delegate, PackageManager.MATCH_ALL);
} else {
activities = getPackageManager().queryIntentActivities(delegate, 0);
}
RelativeLayout blank = findViewById(R.id.blank);
blank.setOnClickListener(v -> finish());
String thisPackageName = getApplicationContext().getPackageName();
ArrayList<String> packages = new ArrayList<>();
List<AppPicker> appPickers = new ArrayList<>();
for (ResolveInfo currentInfo : activities) {
String packageName = currentInfo.activityInfo.packageName;
if (!thisPackageName.equals(packageName) && !packages.contains(packageName)) {
AppPicker appPicker = new AppPicker();
appPicker.setIcon(currentInfo.activityInfo.loadIcon(getPackageManager()));
appPicker.setName(String.valueOf(currentInfo.loadLabel(getPackageManager())));
appPicker.setPackageName(packageName);
appPickers.add(appPicker);
}
}
GridView gridView = findViewById(R.id.app_list);
AppPickerAdapter appPickerAdapter = new AppPickerAdapter(appPickers);
gridView.setAdapter(appPickerAdapter);
gridView.setNumColumns(3);
gridView.setOnItemClickListener((parent, view1, position, id) -> {
for(AppPicker ap: appPickers){
ap.setSelected(false);
}
appPickers.get(position).setSelected(true);
appPickerAdapter.notifyDataSetChanged();
});
}
@Override
protected void onDestroy() {
super.onDestroy();
}
}

View File

@ -15,18 +15,15 @@ package app.fedilab.nitterizeme.activities;
* see <http://www.gnu.org/licenses>. */
import android.app.Activity;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.os.Parcelable;
import android.util.Patterns;
import android.view.View;
import android.widget.Button;
@ -35,7 +32,6 @@ import android.widget.RelativeLayout;
import android.widget.TextView;
import androidx.appcompat.app.AlertDialog;
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
import java.io.UnsupportedEncodingException;
import java.net.MalformedURLException;
@ -43,7 +39,6 @@ import java.net.URL;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@ -59,10 +54,10 @@ import static app.fedilab.nitterizeme.activities.CheckAppActivity.shortener_doma
import static app.fedilab.nitterizeme.activities.CheckAppActivity.twitter_domains;
import static app.fedilab.nitterizeme.activities.CheckAppActivity.youtube_domains;
import static app.fedilab.nitterizeme.activities.MainActivity.SET_BIBLIOGRAM_ENABLED;
import static app.fedilab.nitterizeme.activities.MainActivity.SET_EMBEDDED_PLAYER;
import static app.fedilab.nitterizeme.activities.MainActivity.SET_INVIDIOUS_ENABLED;
import static app.fedilab.nitterizeme.activities.MainActivity.SET_NITTER_ENABLED;
import static app.fedilab.nitterizeme.helpers.Utils.KILL_ACTIVITY;
import static app.fedilab.nitterizeme.helpers.Utils.URL_APP_PICKER;
import static app.fedilab.nitterizeme.helpers.Utils.ampExtract;
import static app.fedilab.nitterizeme.helpers.Utils.bibliogramAccountPattern;
import static app.fedilab.nitterizeme.helpers.Utils.bibliogramPostPattern;
@ -332,7 +327,15 @@ public class TransformActivity extends Activity {
* @param i original intent
*/
private void forwardToBrowser(Intent i) {
Intent intent = new Intent();
Intent app_picker = new Intent(TransformActivity.this, AppsPickerActivity.class);
Bundle b = new Bundle();
b.putString(URL_APP_PICKER, i.getDataString());
app_picker.putExtras(b);
startActivity(app_picker);
finish();
/* Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
String type = i.getType();
if (type == null) {
@ -390,7 +393,7 @@ public class TransformActivity extends Activity {
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, targetIntents.toArray(new Parcelable[]{}));
startActivity(chooserIntent);
}
finish();
finish();*/
}
@ -607,7 +610,7 @@ public class TransformActivity extends Activity {
};
thread.start();
return;
}else {
} else {
newUrl = remove_tracking_param(url);
}
if (newUrl != null) {

View File

@ -0,0 +1,100 @@
package app.fedilab.nitterizeme.adapters;
/* Copyright 2020 Thomas Schneider
*
* This file is a part of UntrackMe
*
* This program is free software; you can redistribute it and/or modify it under the terms of the
* GNU General Public License as published by the Free Software Foundation; either version 3 of the
* License, or (at your option) any later version.
*
* UntrackMe is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
* Public License for more details.
*
* You should have received a copy of the GNU General Public License along with UntrackMe; if not,
* see <http://www.gnu.org/licenses>. */
import android.content.res.Resources;
import android.os.Build;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.constraintlayout.widget.ConstraintLayout;
import java.util.List;
import app.fedilab.nitterizeme.R;
import app.fedilab.nitterizeme.entities.AppPicker;
public class AppPickerAdapter extends BaseAdapter {
private List<AppPicker> appPickers;
public AppPickerAdapter(List<AppPicker> appPickers) {
this.appPickers = appPickers;
}
@Override
public int getCount() {
return appPickers.size();
}
@Override
public AppPicker getItem(int position) {
return appPickers.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
final ViewHolder holder;
AppPicker appPicker = appPickers.get(position);
if (convertView == null) {
LayoutInflater layoutInflater = LayoutInflater.from(parent.getContext());
convertView = layoutInflater.inflate(R.layout.drawer_app_picker, parent, false);
holder = new ViewHolder();
holder.app_icon = convertView.findViewById(R.id.app_icon);
holder.app_name = convertView.findViewById(R.id.app_name);
holder.app_container = convertView.findViewById(R.id.app_container);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
try {
holder.app_icon.setImageDrawable(appPicker.getIcon());
} catch (Resources.NotFoundException e) {
holder.app_icon.setImageResource(R.drawable.ic_android);
}
holder.app_name.setText(appPicker.getName());
if( appPicker.isSelected()) {
holder.app_container.setBackgroundResource(R.drawable.rounded_selector);
}else{
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
holder.app_container.setBackground(null);
}
}
return convertView;
}
private static class ViewHolder {
ImageView app_icon;
TextView app_name;
ConstraintLayout app_container;
}
}

View File

@ -0,0 +1,57 @@
package app.fedilab.nitterizeme.entities;
import android.graphics.drawable.Drawable;
/* Copyright 2020 Thomas Schneider
*
* This file is a part of UntrackMe
*
* This program is free software; you can redistribute it and/or modify it under the terms of the
* GNU General Public License as published by the Free Software Foundation; either version 3 of the
* License, or (at your option) any later version.
*
* UntrackMe is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
* Public License for more details.
*
* You should have received a copy of the GNU General Public License along with UntrackMe; if not,
* see <http://www.gnu.org/licenses>. */
public class AppPicker {
private Drawable icon;
private String name;
private String packageName;
private boolean selected;
public Drawable getIcon() {
return icon;
}
public void setIcon(Drawable icon) {
this.icon = icon;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPackageName() {
return packageName;
}
public void setPackageName(String packageName) {
this.packageName = packageName;
}
public boolean isSelected() {
return selected;
}
public void setSelected(boolean selected) {
this.selected = selected;
}
}

View File

@ -54,6 +54,7 @@ import static app.fedilab.nitterizeme.activities.MainActivity.SET_NITTER_ENABLED
public class Utils {
public static final String KILL_ACTIVITY = "kill_activity";
public static final String URL_APP_PICKER = "url_app_picker";
public static final Pattern youtubePattern = Pattern.compile("(www\\.|m\\.)?(youtube\\.com|youtu\\.be|youtube-nocookie\\.com)/(((?!([\"'<])).)*)");
public static final Pattern nitterPattern = Pattern.compile("(mobile\\.|www\\.)?twitter.com([\\w-/]+)");
public static final Pattern bibliogramPostPattern = Pattern.compile("(m\\.|www\\.)?instagram.com(/p/[\\w-/]+)");

View File

@ -1,34 +0,0 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:aapt="http://schemas.android.com/aapt"
android:width="108dp"
android:height="108dp"
android:viewportWidth="108"
android:viewportHeight="108">
<path
android:fillType="evenOdd"
android:pathData="M32,64C32,64 38.39,52.99 44.13,50.95C51.37,48.37 70.14,49.57 70.14,49.57L108.26,87.69L108,109.01L75.97,107.97L32,64Z"
android:strokeWidth="1"
android:strokeColor="#00000000">
<aapt:attr name="android:fillColor">
<gradient
android:endX="78.5885"
android:endY="90.9159"
android:startX="48.7653"
android:startY="61.0927"
android:type="linear">
<item
android:color="#44000000"
android:offset="0.0" />
<item
android:color="#00000000"
android:offset="1.0" />
</gradient>
</aapt:attr>
</path>
<path
android:fillColor="#FFFFFF"
android:fillType="nonZero"
android:pathData="M66.94,46.02L66.94,46.02C72.44,50.07 76,56.61 76,64L32,64C32,56.61 35.56,50.11 40.98,46.06L36.18,41.19C35.45,40.45 35.45,39.3 36.18,38.56C36.91,37.81 38.05,37.81 38.78,38.56L44.25,44.05C47.18,42.57 50.48,41.71 54,41.71C57.48,41.71 60.78,42.57 63.68,44.05L69.11,38.56C69.84,37.81 70.98,37.81 71.71,38.56C72.44,39.3 72.44,40.45 71.71,41.19L66.94,46.02ZM62.94,56.92C64.08,56.92 65,56.01 65,54.88C65,53.76 64.08,52.85 62.94,52.85C61.8,52.85 60.88,53.76 60.88,54.88C60.88,56.01 61.8,56.92 62.94,56.92ZM45.06,56.92C46.2,56.92 47.13,56.01 47.13,54.88C47.13,53.76 46.2,52.85 45.06,52.85C43.92,52.85 43,53.76 43,54.88C43,56.01 43.92,56.92 45.06,56.92Z"
android:strokeWidth="1"
android:strokeColor="#00000000" />
</vector>

View File

@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="48dp"
android:height="48dp"
android:viewportWidth="34.79452"
android:viewportHeight="34.79452">
<group
android:translateX="4.6972604"
android:translateY="4.6972604">
<path
android:fillColor="#c4302b"
android:pathData="m4.8102,7.35s5.9145,-2.289 7.9671,-3.4741c2.0527,1.1851 7.8124,3.4741 7.8124,3.4741 0,11.419 -7.8124,14.22 -7.8124,14.22s-7.9671,-2.8007 -7.9671,-14.22z"
android:strokeWidth="1.0583"
android:strokeColor="#1da1f2" />
<path
android:fillColor="#FF000000"
android:pathData="m13.468,11.36v-1.5362l2.6883,2.6883 -2.6883,2.6883v-1.5746c-1.9202,0 -3.2644,0.6145 -4.2245,1.9586 0.384,-1.9202 1.5362,-3.8404 4.2245,-4.2245z"
android:strokeWidth=".26458" />
</group>
</vector>

View File

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="@android:color/transparent"/>
<stroke android:width="1dp" android:color="@color/colorAccent" />
<corners android:radius="10dp"/>
<padding android:left="0dp" android:top="0dp" android:right="0dp" android:bottom="0dp" />
</shape>

View File

@ -0,0 +1,90 @@
<?xml version="1.0" encoding="utf-8"?><!--
/* Copyright 2020 Thomas Schneider
*
* This file is a part of UntrackMe
*
* This program is free software; you can redistribute it and/or modify it under the terms of the
* GNU General Public License as published by the Free Software Foundation; either version 3 of the
* License, or (at your option) any later version.
*
* UntrackMe is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
* Public License for more details.
*
* You should have received a copy of the GNU General Public License along with UntrackMe; if not,
* see <http://www.gnu.org/licenses>. */
-->
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/main_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".activities.AppsPickerActivity">
<RelativeLayout
android:id="@+id/blank"
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toTopOf="@+id/app_container"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
/>
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/app_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
android:background="@color/colorPrimary"
>
<TextView
android:layout_marginStart="10dp"
android:layout_marginLeft="10dp"
android:paddingTop="10dp"
android:id="@+id/indication"
android:text="@string/continue_with"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:drawablePadding="5dp"
android:gravity="center_vertical"
android:textSize="16sp"
android:drawableStart="@drawable/ic_app_logo"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:drawableLeft="@drawable/ic_app_logo" />
<GridView
android:paddingTop="10dp"
android:id="@+id/app_list"
android:layout_width="match_parent"
android:layout_height="200dp"
android:stretchMode="columnWidth"
android:gravity="center"
app:layout_constraintTop_toBottomOf="@+id/indication"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toTopOf="@+id/once"/>
<Button
android:id="@+id/once"
style="@style/Widget.AppCompat.Button.Borderless.Colored"
android:text="@string/just_once"
android:textColor="@color/colorAccent"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toStartOf="@+id/always"
app:layout_constraintBottom_toBottomOf="parent" />
<Button
android:id="@+id/always"
style="@style/Widget.AppCompat.Button.Borderless.Colored"
android:text="@string/always"
android:textColor="@color/colorAccent"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintTop_toBottomOf="@+id/app_list"
app:layout_constraintStart_toEndOf="@+id/once"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toBottomOf="parent"/>
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@ -0,0 +1,32 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/app_container"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:paddingTop="5dp"
android:id="@+id/app_icon"
android:layout_width="50dp"
android:layout_height="50dp"
android:contentDescription="@string/icon_of_the_app"
app:layout_constraintBottom_toTopOf="@+id/app_name"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:paddingBottom="5dp"
android:id="@+id/app_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ellipsize="end"
android:gravity="center"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/app_icon" />
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@ -57,4 +57,7 @@
<string name="share_with">Share with</string>
<string name="check_apps">Check apps</string>
<string name="select_instances">Select instances</string>
<string name="continue_with">Continue with...</string>
<string name="just_once">Just once</string>
<string name="always">Always</string>
</resources>

View File

@ -44,6 +44,7 @@
<style name="Theme.AppCompat.Translucent">
<item name="colorAccent">@color/colorAccent</item>
<item name="colorPrimaryDark">@android:color/transparent</item>
<item name="android:textColor">@color/textColor</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowBackground">@android:color/transparent</item>