1
0
mirror of https://github.com/foobnix/LibreraReader.git synced 2025-10-05 15:52:56 +02:00

refactoring

This commit is contained in:
Ivan Ivanenko
2025-08-06 11:59:00 +03:00
parent 91beb21037
commit ea7cfff09e
26 changed files with 86 additions and 302 deletions

0
Configure Normal file
View File

View File

@@ -49,8 +49,7 @@
android:theme="@style/StyledIndicatorsWhite"
android:usesCleartextTraffic="true"
android:vmSafeMode="${appSafeMode}"
tools:overrideLibrary="androidx.car.app"
tools:replace="label, icon, roundIcon">
tools:overrideLibrary="androidx.car.app">
<meta-data
android:name="android.webkit.WebView.MetricsOptOut"

View File

@@ -15,6 +15,7 @@ import android.os.AsyncTask;
import android.os.Build;
import android.os.Environment;
import android.os.Handler;
import android.os.Looper;
import android.provider.DocumentsContract;
import android.text.format.DateFormat;
import android.text.format.Formatter;
@@ -1147,10 +1148,10 @@ public class ExtUtils {
}
public static void sharePage(final DocumentController dc, int page) {
sharePage(dc.getActivity(), dc.getCurrentBook(), page, dc.getPageUrl(page).toString());
}
private static void sharePage(final Activity a, final File file, int page, String pageUrl) {
@@ -1421,7 +1422,7 @@ public class ExtUtils {
View view = LayoutInflater.from(a).inflate(R.layout.dialog_loading_book, null, false);
final TextView text = (TextView) view.findViewById(R.id.text1);
handler = new Handler() {
handler = new Handler(Looper.getMainLooper()) {
@Override
public void handleMessage(android.os.Message msg) {
text.setText(a.getString(R.string.please_wait) + " " + msg.what + "%");

View File

@@ -2,23 +2,20 @@ package com.foobnix.pdf.info;
import android.app.Activity;
import android.os.Handler;
import android.os.Looper;
import androidx.annotation.NonNull;
import com.foobnix.LibreraApp;
import com.foobnix.android.utils.Apps;
import com.foobnix.android.utils.LOG;
import com.foobnix.ui2.MainTabs2;
import com.google.android.gms.ads.AdView;
import com.google.android.gms.ads.LoadAdError;
import com.google.android.gms.ads.MobileAds;
import com.google.android.gms.ads.interstitial.InterstitialAd;
import com.google.android.gms.ads.interstitial.InterstitialAdLoadCallback;
import com.foobnix.LibreraApp;
import com.google.android.ump.ConsentInformation;
import com.google.android.ump.UserMessagingPlatform;
import java.util.Random;
import java.util.concurrent.TimeUnit;
@@ -32,7 +29,7 @@ public class MyADSProvider {
private Activity a;
public void createHandler() {
handler = new Handler();
handler = new Handler(Looper.getMainLooper());
try {
Class.forName("android.os.AsyncTask");
} catch (Throwable ignore) {
@@ -51,7 +48,7 @@ public class MyADSProvider {
// LOG.d("ADS, can not Request Ads");
// return;
// }
LOG.d("ADS, can Request Ads");
LOG.d("ADS, can Request Ads");
if (withInterstitial) {

View File

@@ -8,6 +8,7 @@ import android.content.DialogInterface.OnDismissListener;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.os.Handler;
import android.os.Looper;
import android.text.InputType;
import android.text.TextUtils;
import android.view.Gravity;
@@ -48,7 +49,6 @@ import com.foobnix.android.utils.Views;
import com.foobnix.android.utils.WebViewUtils;
import com.foobnix.dao2.FileMeta;
import com.foobnix.drive.GFile;
import com.foobnix.ext.Fb2Extractor;
import com.foobnix.hypen.HypenUtils;
import com.foobnix.model.AppProfile;
import com.foobnix.model.AppSP;
@@ -937,7 +937,7 @@ public class Dialogs {
l.setPadding(Dips.dpToPx(5), Dips.dpToPx(5), Dips.dpToPx(5), Dips.dpToPx(5));
l.setOrientation(LinearLayout.VERTICAL);
final Handler handler = new Handler();
final Handler handler = new Handler(Looper.getMainLooper());
final Runnable actionWrapper = new Runnable() {

View File

@@ -28,6 +28,7 @@ import android.net.Uri;
import android.os.AsyncTask;
import android.os.Build;
import android.os.Handler;
import android.os.Looper;
import android.speech.tts.TextToSpeech.OnInitListener;
import android.text.Html;
import android.text.format.DateFormat;
@@ -1521,7 +1522,7 @@ public class DragingDialogs {
final String searchingString = anchor.getContext().getString(R.string.searching_please_wait_);
final int count = controller.getPageCount();
final Handler hMessage = new Handler() {
final Handler hMessage = new Handler(Looper.getMainLooper()) {
@Override
public void handleMessage(android.os.Message msg) {
int pageNumber = msg.what;
@@ -1587,7 +1588,7 @@ public class DragingDialogs {
searchString = matcher.group(1);
firstPage = Integer.parseInt(matcher.group(2));
lastPage = Integer.parseInt(matcher.group(3));
}else{
} else {
Toast.makeText(controller.getActivity(), R.string.msg_unexpected_error, Toast.LENGTH_SHORT).show();
return;
}
@@ -1626,7 +1627,7 @@ public class DragingDialogs {
hMessage.sendEmptyMessage(pageNumber);
return false;
}
}, firstPage-1, lastPage);
}, firstPage - 1, lastPage);
}
});

View File

@@ -7,6 +7,7 @@ import android.net.Uri;
import android.os.AsyncTask;
import android.os.Environment;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.view.KeyEvent;
import android.view.LayoutInflater;
@@ -161,7 +162,7 @@ public class MultyDocSearchDialog {
});
editPath.setText(Model.get().path);
final Handler updater2 = new Handler() {
final Handler updater2 = new Handler(Looper.getMainLooper()) {
@Override
public void handleMessage(Message msg) {
adapter.notifyDataSetChanged();
@@ -169,7 +170,7 @@ public class MultyDocSearchDialog {
};
final Handler updater1 = new Handler() {
final Handler updater1 = new Handler(Looper.getMainLooper()) {
@Override
public void handleMessage(Message msg) {
infoView1.setText((Model.get().currentPage + 1) + "/" + Model.get().currentPagesCount + " " + Model.get().currentDoc);
@@ -302,7 +303,7 @@ public class MultyDocSearchDialog {
if (!Model.get().isSearcingRun) {
return -1;
}
Model.get().currentDoc = String.format("[%s/%s]", num, books) +new File(filePath).getName();
Model.get().currentDoc = String.format("[%s/%s]", num, books) + new File(filePath).getName();
final int page = searchInThePDF(filePath, Model.get().text, updater1);
if (page != -1) {

View File

@@ -6,6 +6,7 @@ import android.content.DialogInterface;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.os.Handler;
import android.os.Looper;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
@@ -62,7 +63,7 @@ public class ColorsDialog {
super();
final View view = LayoutInflater.from(c).inflate(R.layout.dialog_colors, null, false);
handler = new Handler();
handler = new Handler(Looper.getMainLooper());
int colorText = magicBlackColor(colorTextDef);
int colorBg = magicBlackColor(colorBgDef);

View File

@@ -8,11 +8,11 @@ import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.res.ColorStateList;
import android.graphics.Color;
import android.graphics.PorterDuff;
import android.os.Build;
import android.os.Handler;
import android.os.Looper;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.MenuItem;
@@ -94,8 +94,8 @@ import java.util.concurrent.TimeUnit;
public class DocumentWrapperUI {
final DocumentController dc;
final Handler handler = new Handler();
final Handler handlerTimer = new Handler();
final Handler handler = new Handler(Looper.getMainLooper());
final Handler handlerTimer = new Handler(Looper.getMainLooper());
public View.OnClickListener onLockUnlock = new View.OnClickListener() {
@@ -1426,8 +1426,8 @@ public class DocumentWrapperUI {
//line1.getBackground().
TintUtil.setStrokeColorWithDash(line1,tintColor);
TintUtil.setStrokeColorWithDash(line2,tintColor);
TintUtil.setStrokeColorWithDash(line1, tintColor);
TintUtil.setStrokeColorWithDash(line2, tintColor);
} catch (Exception e) {
@@ -1717,7 +1717,7 @@ public class DocumentWrapperUI {
menuLayout.setVisibility(View.GONE);
bottomBar.setVisibility(View.GONE);
//adFrame.setVisibility(View.GONE);
// adFrame.setClickable(false);
// adFrame.setClickable(false);
imageMenuArrow.setImageResource(android.R.drawable.arrow_down_float);
// speedSeekBar.setVisibility(View.GONE);
@@ -1749,8 +1749,8 @@ public class DocumentWrapperUI {
bottomBar.setVisibility(View.VISIBLE);
//adFrame.setVisibility(View.VISIBLE);
// adFrame.setClickable(true);
// adFrame.setTag(null);
// adFrame.setClickable(true);
// adFrame.setTag(null);
imageMenuArrow.setImageResource(android.R.drawable.arrow_up_float);
@@ -1801,8 +1801,8 @@ public class DocumentWrapperUI {
}
public void hideAds() {
// adFrame.setTag("");
// adFrame.setVisibility(View.GONE);
// adFrame.setTag("");
// adFrame.setVisibility(View.GONE);
}
public void nextChose(boolean animate) {

View File

@@ -6,6 +6,7 @@ import android.graphics.drawable.Drawable;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@@ -22,7 +23,6 @@ import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.request.target.CustomTarget;
import com.bumptech.glide.request.transition.Transition;
import com.foobnix.android.utils.LOG;
import com.foobnix.android.utils.TxtUtils;
import com.foobnix.pdf.info.IMG;
import com.foobnix.pdf.info.R;
import com.foobnix.pdf.info.wrapper.MagicHelper;
@@ -81,7 +81,7 @@ public class ImagePageFragment extends Fragment {
text.setTextColor(MagicHelper.getTextColor());
//TxtUtils.setLinkTextColor(text);
handler = new Handler();
handler = new Handler(Looper.getMainLooper());
handler.postDelayed(new Runnable() {
@Override

View File

@@ -10,6 +10,7 @@ import android.graphics.Paint.Style;
import android.graphics.RectF;
import android.graphics.drawable.BitmapDrawable;
import android.os.Handler;
import android.os.Looper;
import android.util.AttributeSet;
import android.util.Pair;
import android.view.GestureDetector;
@@ -19,6 +20,7 @@ import android.view.animation.AccelerateDecelerateInterpolator;
import android.widget.Scroller;
import android.widget.Toast;
import com.foobnix.LibreraApp;
import com.foobnix.android.utils.Apps;
import com.foobnix.android.utils.Dips;
import com.foobnix.android.utils.LOG;
@@ -26,7 +28,6 @@ import com.foobnix.android.utils.TxtUtils;
import com.foobnix.android.utils.Vibro;
import com.foobnix.model.AppSP;
import com.foobnix.model.AppState;
import com.foobnix.pdf.info.ExtUtils;
import com.foobnix.pdf.info.R;
import com.foobnix.pdf.info.model.BookCSS;
import com.foobnix.pdf.info.view.BrightnessHelper;
@@ -42,8 +43,6 @@ import com.foobnix.pdf.search.activity.msg.TextWordsMessage;
import com.foobnix.sys.ClickUtils;
import com.foobnix.sys.TempHolder;
import com.foobnix.LibreraApp;
import org.ebookdroid.core.codec.Annotation;
import org.ebookdroid.core.codec.PageLink;
import org.ebookdroid.droids.mupdf.codec.TextWord;
@@ -112,7 +111,7 @@ public class PageImaveView extends View {
public PageImaveView(final Context context, final AttributeSet attrs) {
super(context, attrs);
handler = new Handler();
handler = new Handler(Looper.getMainLooper());
scroller = new Scroller(getContext(), new AccelerateDecelerateInterpolator());
imageGestureListener = new ImageSimpleGestureListener();
gestureDetector = new GestureDetector(context, imageGestureListener);

View File

@@ -8,6 +8,7 @@ import android.content.DialogInterface.OnClickListener;
import android.graphics.PointF;
import android.graphics.RectF;
import android.os.Handler;
import android.os.Looper;
import android.text.InputType;
import android.util.Pair;
import android.view.KeyEvent;
@@ -76,7 +77,7 @@ public class VerticalModeController extends DocumentController {
super(activity);
this.ctr = ctr;
CoreSettings.getInstance().fullScreen = AppState.get().fullScreenMode == AppState.FULL_SCREEN_FULLSCREEN;
handler = new Handler();
handler = new Handler(Looper.getMainLooper());
TempHolder.get().loadingCancelled = false;
}
@@ -649,7 +650,7 @@ public class VerticalModeController extends DocumentController {
}
public void commit() {
new Handler().postDelayed(new Runnable() {
new Handler(Looper.getMainLooper()).postDelayed(new Runnable() {
@Override
public void run() {
@@ -688,7 +689,7 @@ public class VerticalModeController extends DocumentController {
@Override
public void onCloseActivityFinal(Runnable run) {
TempHolder.get().loadingCancelled = true;
TempHolder.get().loadingCancelled = true;
stopTimer();
ctr.closeActivityFinal(run);
}

View File

@@ -8,6 +8,7 @@ import android.content.Intent;
import android.graphics.Color;
import android.os.Build;
import android.os.Handler;
import android.os.Looper;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.MenuItem;
@@ -22,7 +23,6 @@ import android.widget.TextView;
import com.foobnix.android.utils.Apps;
import com.foobnix.android.utils.LOG;
import com.foobnix.android.utils.TxtUtils;
import com.foobnix.model.AppState;
import com.foobnix.pdf.info.R;
import com.foobnix.pdf.info.TintUtil;
import com.foobnix.pdf.info.Urls;
@@ -180,7 +180,7 @@ public class TTSControlsView extends FrameLayout {
}
});
handler = new Handler();
handler = new Handler(Looper.getMainLooper());
seekMp3 = (SeekBar) view.findViewById(R.id.seekMp3);
seekCurrent = (TextView) view.findViewById(R.id.seekCurrent);
seekMax = (TextView) view.findViewById(R.id.seekMax);

View File

@@ -12,6 +12,7 @@ import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Build;
import android.os.Handler;
import android.os.Looper;
import android.view.View;
import android.widget.RemoteViews;
@@ -25,7 +26,6 @@ import com.bumptech.glide.request.transition.Transition;
import com.foobnix.LibreraApp;
import com.foobnix.android.utils.Apps;
import com.foobnix.android.utils.LOG;
import com.foobnix.android.utils.ResultResponse;
import com.foobnix.android.utils.TxtUtils;
import com.foobnix.dao2.FileMeta;
import com.foobnix.model.AppSP;
@@ -34,7 +34,6 @@ import com.foobnix.pdf.info.ExtUtils;
import com.foobnix.pdf.info.IMG;
import com.foobnix.pdf.info.R;
import com.foobnix.pdf.info.model.BookCSS;
import com.foobnix.pdf.info.widget.RecentBooksWidget;
import com.foobnix.pdf.info.widget.TTSWidget;
import com.foobnix.pdf.search.activity.HorizontalViewActivity;
import com.foobnix.sys.ImageExtractor;
@@ -76,7 +75,7 @@ public class TTSNotification {
@TargetApi(26)
public static void initChannels(Context context) {
TTSNotification.context = context;
handler = new Handler();
handler = new Handler(Looper.getMainLooper());
if (Build.VERSION.SDK_INT < 26) {
return;

View File

@@ -5,6 +5,7 @@ import android.content.res.Configuration;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import androidx.fragment.app.FragmentActivity;
@@ -14,7 +15,6 @@ import com.foobnix.model.AppState;
import com.foobnix.pdf.info.IMG;
import com.foobnix.pdf.info.MyADSProvider;
import com.foobnix.pdf.info.R;
import com.foobnix.pdf.search.view.CloseAppDialog;
import com.foobnix.tts.TTSEngine;
import com.foobnix.tts.TTSNotification;
@@ -49,7 +49,7 @@ public abstract class AdsFragmentActivity extends FragmentActivity {
super.onCreate(arg0);
myAds.intetrstialTimeout = intetrstialTimeoutSec;
myAds.createHandler();
handler = new Handler();
handler = new Handler(Looper.getMainLooper());
}
@Override

View File

@@ -8,6 +8,7 @@ import android.content.Intent;
import android.graphics.RectF;
import android.os.Build;
import android.os.Handler;
import android.os.Looper;
import androidx.core.app.NotificationCompat;
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
@@ -99,7 +100,7 @@ public class BooksService extends IntentService {
public BooksService() {
super("BooksService");
handler = new Handler();
handler = new Handler(Looper.getMainLooper());
LOG.d("BooksService", "Create");
}

View File

@@ -13,6 +13,7 @@ import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
@@ -321,7 +322,7 @@ public class MainTabs2 extends AdsFragmentActivity {
return;
}
handler = new Handler();
handler = new Handler(Looper.getMainLooper());
isEink = Dips.isEInk();
TintUtil.setStatusBarColor(this);

View File

@@ -12,6 +12,7 @@ import android.graphics.Color;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.text.Html;
import android.text.format.DateUtils;
import android.view.LayoutInflater;
@@ -335,7 +336,7 @@ public class PrefFragment2 extends UIFragment {
final LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
layoutParams.setMargins(Dips.dpToPx(2), Dips.dpToPx(2), Dips.dpToPx(2), Dips.dpToPx(2));
final Handler handler = new Handler();
final Handler handler = new Handler(Looper.getMainLooper());
final Runnable ask2 = new Runnable() {
@Override

View File

@@ -11,6 +11,7 @@ import android.graphics.Color;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.os.Looper;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.LayoutInflater;
@@ -353,7 +354,7 @@ public class SearchFragment2 extends UIFragment<FileMeta> {
NO_SERIES = " (" + getString(R.string.without_series) + ")";
handler = new Handler();
handler = new Handler(Looper.getMainLooper());
secondTopPanel = view.findViewById(R.id.secondTopPanel);
countBooks = (TextView) view.findViewById(R.id.countBooks);
@@ -448,7 +449,7 @@ public class SearchFragment2 extends UIFragment<FileMeta> {
@Override
public void run() {
Prefs.get().remove(SearchAllBooksWorker.SEARCH_ERRORS,0);
Prefs.get().remove(SearchAllBooksWorker.SEARCH_ERRORS, 0);
recyclerView.scrollToPosition(0);
seachAll();
}

View File

@@ -8,6 +8,7 @@ import android.content.res.Configuration;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.view.View;
import android.widget.ImageView;
@@ -21,6 +22,7 @@ import androidx.recyclerview.widget.RecyclerView;
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
import com.bumptech.glide.Glide;
import com.foobnix.LibreraApp;
import com.foobnix.android.utils.Apps;
import com.foobnix.android.utils.Dips;
import com.foobnix.android.utils.LOG;
@@ -43,7 +45,6 @@ import com.foobnix.ui2.adapter.FileMetaAdapter;
import com.foobnix.ui2.fast.FastScrollRecyclerView;
import com.foobnix.ui2.fast.FastScrollStateChangeListener;
import com.foobnix.LibreraApp;
import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;
@@ -79,7 +80,7 @@ public abstract class UIFragment<T> extends Fragment {
@Override
public void onAttach(Context context) {
super.onAttach(context);
handler = new Handler();
handler = new Handler(Looper.getMainLooper());
}
@Override
@@ -137,7 +138,7 @@ public abstract class UIFragment<T> extends Fragment {
public abstract void resetFragment();
public void onDoubleClick(){
public void onDoubleClick() {
}

View File

@@ -10,6 +10,7 @@ import android.content.res.Configuration;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.util.DisplayMetrics;
import android.view.KeyEvent;
import android.view.MotionEvent;
@@ -20,7 +21,6 @@ import com.foobnix.android.utils.Dips;
import com.foobnix.android.utils.Intents;
import com.foobnix.android.utils.Keyboards;
import com.foobnix.android.utils.LOG;
import com.foobnix.android.utils.TxtUtils;
import com.foobnix.drive.GFile;
import com.foobnix.model.AppBook;
import com.foobnix.model.AppProfile;
@@ -159,7 +159,7 @@ public class VerticalViewActivity extends AbstractActionActivity<VerticalViewAct
// ADS.activate(this, adView);
handler = new Handler();
handler = new Handler(Looper.getMainLooper());
getController().onBookLoaded(new Runnable() {
@@ -178,8 +178,6 @@ public class VerticalViewActivity extends AbstractActionActivity<VerticalViewAct
});
}

View File

@@ -1,225 +0,0 @@
package org.emdev.ui.actions;
import android.app.Activity;
import org.emdev.utils.LengthUtils;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
public class EventDispatcher {
private final Activity m_base;
private final InvokationType m_type;
/**
* Supported interfaces.
*/
private final Class<?>[] m_interfaces;
/**
* Real listeners.
*/
private final Map<Class<?>, List<Object>> m_listeners = new HashMap<Class<?>, List<Object>>();
private final Object m_proxy;
private final InvocationHandler m_handler;
/**
* Constructor
*
* @param type
* invocation type
* @param target
* target object
* @param listeners
* a list of listener interfaces
*/
public EventDispatcher(final Activity base, final InvokationType type, final Class<?>... listeners) {
if (LengthUtils.isEmpty(listeners)) {
throw new IllegalArgumentException("Listeners list cannot be empty");
}
for (final Class<?> listener : listeners) {
if (listener == null) {
throw new IllegalArgumentException("Listener class cannot be null");
}
if (!listener.isInterface()) {
throw new IllegalArgumentException("Listener class should be an interface");
}
}
m_base = base;
m_type = type;
m_handler = new Handler();
m_interfaces = listeners;
m_proxy = Proxy.newProxyInstance(this.getClass().getClassLoader(), listeners, m_handler);
}
/**
* Adds the target listener.
*
* @param listener
* the listener to add
*/
public void addListener(final Object listener) {
if (listener != null) {
for (final Class<?> listenerClass : m_interfaces) {
if (listenerClass.isInstance(listener)) {
List<Object> list = m_listeners.get(listenerClass);
if (list == null) {
list = new LinkedList<Object>();
m_listeners.put(listenerClass, list);
}
if (!list.contains(listener)) {
list.add(listener);
}
}
}
}
}
/**
* Removes the target listener.
*
* @param listener
* the listener to remove
*/
public void removeListener(final Object listener) {
if (listener != null) {
for (final Class<?> listenerClass : m_interfaces) {
if (listenerClass.isInstance(listener)) {
final List<Object> list = m_listeners.get(listenerClass);
if (list != null) {
list.remove(listener);
}
}
}
}
}
/**
* Gets a listener of the given type.
*
* @param <Listener>
* listener type
* @return listener proxy object casted to the given type
*/
@SuppressWarnings("unchecked")
public <Listener> Listener getListener() {
return (Listener) m_proxy;
}
/**
* This class implements invocation handler for event listeners.
*/
private class Handler implements InvocationHandler {
/**
* Processes a method invocation on a proxy instance and returns the
* result.
*
* @param proxy
* the proxy instance that the method was invoked on
* @param method
* the <code>Method</code> instance corresponding to
* the interface method invoked on the proxy instance.
* @param args
* an array of objects containing the values of the
* arguments passed in the method invocation on the proxy
* instance.
* @return the value to return from the method invocation on the
* proxy instance.
* @throws Throwable
* the exception to throw from the method
* invocation on the proxy instance.
* @see InvocationHandler#invoke(Object, Method, Object[])
*/
@Override
public Object invoke(final Object proxy, final Method method, final Object[] args) throws Throwable {
final Class<?> listenerClass = method.getDeclaringClass();
final List<Object> targets = m_listeners.get(listenerClass);
if (LengthUtils.isNotEmpty(targets)) {
final Task task = new Task(targets, method, args);
switch (m_type) {
case AsyncUI:
m_base.runOnUiThread(task);
break;
case SeparatedThread:
new Thread(task,"@T event invoke").start();
break;
case Direct:
default:
task.run();
break;
}
}
return null;
}
}
/**
* This class implements thread task for listener invocation.
*/
private class Task implements Runnable {
private final List<Object> m_targets;
private final Method m_method;
private final Object[] m_args;
/**
* Constructor
*
* @param method
* called method
* @param args
* method parameters
*/
public Task(final List<Object> targets, final Method method, final Object[] args) {
m_targets = targets;
m_method = method;
m_args = args;
}
/**
*
* @see java.lang.Runnable#run()
*/
@Override
public synchronized void run() {
directInvoke();
}
/**
* Direct invoke of the action.
*
* @param method
* called method
* @param args
* method parameters
*/
protected void directInvoke() {
for (final Object target : m_targets) {
try {
m_method.invoke(target, m_args);
} catch (final Throwable ex) {
ex.printStackTrace();
}
}
}
}
}

View File

@@ -9,6 +9,7 @@ import android.graphics.Paint;
import android.os.Bundle;
import android.os.Handler;
import android.os.HandlerThread;
import android.os.Looper;
import android.os.Message;
import android.view.MotionEvent;
import android.view.ScaleGestureDetector;
@@ -29,7 +30,8 @@ public class TestActivity extends Activity implements View.OnTouchListener,
static int dx = 0;
static int dy = 0;
ScaleGestureDetector scaleGestureDetector;
static float zoom =1;
static float zoom = 1;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@@ -40,7 +42,7 @@ public class TestActivity extends Activity implements View.OnTouchListener,
setContentView(mSurface);
Handler h = new Handler();
Handler h = new Handler(Looper.getMainLooper());
h.postDelayed(new Runnable() {
@Override
public void run() {
@@ -49,10 +51,10 @@ public class TestActivity extends Activity implements View.OnTouchListener,
}
}, 200);
scaleGestureDetector = new ScaleGestureDetector(this, new ScaleGestureDetector.OnScaleGestureListener() {
scaleGestureDetector = new ScaleGestureDetector(this, new ScaleGestureDetector.OnScaleGestureListener() {
@Override
public boolean onScale(ScaleGestureDetector detector) {
zoom =zoom* detector.getScaleFactor();
zoom = zoom * detector.getScaleFactor();
LOG.d("ScaleGestureDetector onScale", detector.getScaleFactor(), detector.getCurrentSpan(), detector.getPreviousSpan());
return true;
@@ -79,7 +81,6 @@ public class TestActivity extends Activity implements View.OnTouchListener,
int initX, initY;
public boolean onTouch(View v, MotionEvent event) {
boolean res = scaleGestureDetector.onTouchEvent(event);
if (event.getAction() == MotionEvent.ACTION_DOWN) {
@@ -89,8 +90,8 @@ public class TestActivity extends Activity implements View.OnTouchListener,
}
if (event.getAction() == MotionEvent.ACTION_MOVE) {
// mThread.addItem((int) event.getX(), (int) event.getY());
dx = (int) event.getX()-initX;
dy = (int)event.getY()-initY;
dx = (int) event.getX() - initX;
dy = (int) event.getY() - initY;
}
return res;
}
@@ -200,12 +201,12 @@ public class TestActivity extends Activity implements View.OnTouchListener,
// Clear Canvas first
c.drawColor(Color.BLACK);
c.translate(dx*3,dy*3);
c.scale(zoom,zoom);
c.translate(dx * 3, dy * 3);
c.scale(zoom, zoom);
//c.getMatrix().postTranslate(dx,dy);
//c.getMatrix().preScale(2,2);
c.drawRect(1,1,mDrawingWidth-1, mDrawingHeight-1,bPaint);
c.drawRect(1, 1, mDrawingWidth - 1, mDrawingHeight - 1, bPaint);
// Draw each item
for (DrawingItem item : mLocations) {
@@ -230,7 +231,6 @@ public class TestActivity extends Activity implements View.OnTouchListener,
c.restore();
// Release to be rendered to the screen
mDrawingSurface.unlockCanvasAndPost(c);
break;

View File

@@ -12,12 +12,12 @@ plugins {
android {
namespace = "mobi.librera.appcompose"
compileSdk = 36
compileSdk = rootProject.extra["compileSdk"] as Int
defaultConfig {
applicationId = "mobi.librera.appcompose"
minSdk = 30
targetSdk = 36
minSdk = rootProject.extra["minSdk"] as Int
targetSdk = rootProject.extra["targetSdk"] as Int
versionCode = 1
versionName = "1.0"

View File

@@ -1,6 +1,6 @@
plugins {
id("com.android.application") version "8.11.1" apply false
id("com.android.library") version "8.11.1" apply false
id("com.android.application") version "8.12.0" apply false
id("com.android.library") version "8.12.0" apply false
id("org.jetbrains.kotlin.android") version "2.2.0" apply false
id("org.jetbrains.kotlin.plugin.compose") version "2.2.0" apply false
id("androidx.room") version "2.7.2" apply false

View File

@@ -7,11 +7,18 @@ plugins {
android {
namespace = "com.foobnix.googledrive"
compileSdk = 36
compileSdk = rootProject.extra["compileSdk"] as Int
defaultConfig {
minSdk = 24
targetSdk = 36
minSdk = rootProject.extra["minSdk"] as Int
}
lint {
targetSdk = rootProject.extra["targetSdk"] as Int
}
testOptions {
targetSdk = rootProject.extra["targetSdk"] as Int
}
compileOptions {