From b8564025bd7c722084c665f7a0a54beda8ef8209 Mon Sep 17 00:00:00 2001 From: Niki Roo Date: Sat, 18 May 2019 15:08:55 +0200 Subject: [PATCH] remove all android sources (another project is taking over that) --- .../fanfix/reader/android/AndroidReader.java | 62 ------ .../reader/android/AndroidReaderActivity.java | 191 ------------------ .../reader/android/AndroidReaderBook.java | 122 ----------- .../reader/android/AndroidReaderGroup.java | 101 --------- 4 files changed, 476 deletions(-) delete mode 100644 src/be/nikiroo/fanfix/reader/android/AndroidReader.java delete mode 100644 src/be/nikiroo/fanfix/reader/android/AndroidReaderActivity.java delete mode 100644 src/be/nikiroo/fanfix/reader/android/AndroidReaderBook.java delete mode 100644 src/be/nikiroo/fanfix/reader/android/AndroidReaderGroup.java diff --git a/src/be/nikiroo/fanfix/reader/android/AndroidReader.java b/src/be/nikiroo/fanfix/reader/android/AndroidReader.java deleted file mode 100644 index 7dcdd04..0000000 --- a/src/be/nikiroo/fanfix/reader/android/AndroidReader.java +++ /dev/null @@ -1,62 +0,0 @@ -package be.nikiroo.fanfix.reader.android; - -import android.app.Activity; -import android.content.Intent; -import android.net.Uri; - -import java.io.File; -import java.io.IOException; - -import be.nikiroo.fanfix.reader.BasicReader; - -public class AndroidReader extends BasicReader { - private Activity app; - - /** - * Do not use. - */ - private AndroidReader() { - // Required for reflection - } - - public AndroidReader(Activity app) { - this.app = app; - } - - @Override - public void read(boolean sync) throws IOException { - } - - @Override - public void browse(String source) { - } - - @Override - protected void start(File target, String program, boolean sync) throws IOException { - if (program == null) { - try { - Intent[] intents = new Intent[] { // - new Intent(Intent.ACTION_VIEW), // - new Intent(Intent.ACTION_OPEN_DOCUMENT) // - }; - - for (Intent intent : intents) { - intent.setDataAndType(Uri.parse(target.toURI().toString()), - "application/x-cbz"); - } - - Intent chooserIntent = Intent.createChooser(intents[0], - "Open CBZ in..."); - - // chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, - // intents); - - app.startActivity(chooserIntent); - } catch (UnsupportedOperationException e) { - super.start(target, program, sync); - } - } else { - super.start(target, program, sync); - } - } -} diff --git a/src/be/nikiroo/fanfix/reader/android/AndroidReaderActivity.java b/src/be/nikiroo/fanfix/reader/android/AndroidReaderActivity.java deleted file mode 100644 index 290b5ba..0000000 --- a/src/be/nikiroo/fanfix/reader/android/AndroidReaderActivity.java +++ /dev/null @@ -1,191 +0,0 @@ -package be.nikiroo.fanfix.reader.android; - -import android.app.Activity; -import android.app.AlertDialog; -import android.app.FragmentTransaction; -import android.content.Context; -import android.content.DialogInterface; -import android.os.Bundle; -import android.os.Environment; -import android.text.InputType; -import android.view.View; -import android.widget.EditText; - -import java.io.File; -import java.io.IOException; -import java.net.URL; - -import be.nikiroo.fanfix.Instance; -import be.nikiroo.fanfix.data.MetaData; -import be.nikiroo.fanfix.reader.BasicReader; -import be.nikiroo.fanfix.reader.Reader; -import be.nikiroo.utils.TraceHandler; - -public class AndroidReaderActivity extends Activity implements - AndroidReaderBook.OnFragmentInteractionListener { - private static Reader reader = null; - - @Override - protected void onCreate(Bundle savedInstanceState) { - reader = config(); - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_main); - } - - @Override - protected void onStart() { - super.onStart(); - refresh(); - } - - private void refresh() { - AndroidReaderGroup group = new AndroidReaderGroup(); - - FragmentTransaction trans = getFragmentManager().beginTransaction(); - trans.replace(R.id.Main_pnlStories, group); - trans.commit(); - getFragmentManager().executePendingTransactions(); - - group.fill(reader.getLibrary().getList(), reader); - } - - public void onAdd(View view) { - final View root = findViewById(R.id.Main); - - ask(this, - "Import new story", - "Enter the story URL (the program will then download it -- the interface will not be usable until it is downloaded", - "Download", new AnswerListener() { - @Override - public void onAnswer(final String answer) { - root.setEnabled(false); - new Thread(new Runnable() { - @Override - public void run() { - try { - URL url = new URL(answer); - reader.getLibrary().imprt(url, null); - } catch (Throwable e) { - // TODO: show error message correctly - String mess = ""; - for (String tab = ""; e != null - && e != e.getCause(); e = e - .getCause()) { - mess += tab + "[" - + e.getClass().getSimpleName() - + "] " + e.getMessage() + "\n"; - tab += "\t"; - } - - final String messf = mess; - AndroidReaderActivity.this - .runOnUiThread(new Runnable() { - @Override - public void run() { - ask(AndroidReaderActivity.this, - "Error", - "Cannot import URL: \n" - + messf, - "OK", null); - } - }); - - } - - AndroidReaderActivity.this - .runOnUiThread(new Runnable() { - @Override - public void run() { - refresh(); - root.setEnabled(true); - } - }); - } - }).start(); - } - }); - - /* - * Intent intent = new Intent(AndroidReaderActivity.this, SayIt.class); - * intent.putExtra(SayIt.MESSAGE, message); startActivity(intent); - */ - } - - @Override - public void onFragmentInteraction(MetaData meta) { - AndroidReader reader = new AndroidReader(this); - try { - reader.openExternal(Instance.getLibrary(), meta.getLuid()); - } catch (IOException e) { - e.printStackTrace(); - } - } - - private Reader config() { - if (reader != null) { - return reader; - } - - String internal = getExternalFilesDir(null).toString(); - File user = Environment - .getExternalStoragePublicDirectory(Environment.DIRECTORY_DOCUMENTS); - - try { - File parent = user.getParentFile(); - if (parent.exists() || parent.mkdirs()) { - File test = new File(parent, "test"); - if (test.exists() || (test.createNewFile() && test.delete())) { - user = parent; - } - } - } catch (Exception e) { - // Fall back to Documents/Books - } - - System.setProperty("DEBUG", "1"); - System.setProperty("fanfix.home", internal); - System.setProperty("fanfix.libdir", new File(user, "Books").toString()); - - Instance.resetConfig(false); - Instance.setTraceHandler(new TraceHandler(true, true, 2)); - - BasicReader.setDefaultReaderType(Reader.ReaderType.ANDROID); - return BasicReader.getReader(); - } - - public static void ask(Context context, String title, String message, - String okMessage, final AnswerListener listener) { - final EditText input = new EditText(context); - input.setFocusable(true); - input.setInputType(InputType.TYPE_CLASS_TEXT); - - AlertDialog.Builder alert = new AlertDialog.Builder(context); - alert.setTitle(title); - alert.setMessage(message); - alert.setCancelable(true); - alert.setView(input); - - if (listener != null) { - alert.setPositiveButton(okMessage, - new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - listener.onAnswer(input.getText().toString()); - } - }); - - alert.setOnCancelListener(new DialogInterface.OnCancelListener() { - @Override - public void onCancel(DialogInterface dialog) { - listener.onAnswer(null); - } - }); - } - - alert.show(); - } - - private interface AnswerListener { - public void onAnswer(String answer); - } -} \ No newline at end of file diff --git a/src/be/nikiroo/fanfix/reader/android/AndroidReaderBook.java b/src/be/nikiroo/fanfix/reader/android/AndroidReaderBook.java deleted file mode 100644 index 700a566..0000000 --- a/src/be/nikiroo/fanfix/reader/android/AndroidReaderBook.java +++ /dev/null @@ -1,122 +0,0 @@ -package be.nikiroo.fanfix.reader.android; - -import android.app.Activity; -import android.app.Fragment; -import android.graphics.Bitmap; -import android.os.AsyncTask; -import android.os.Bundle; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.FrameLayout; -import android.widget.ImageView; -import android.widget.TextView; - -import java.io.IOException; - -import be.nikiroo.fanfix.data.MetaData; -import be.nikiroo.fanfix.reader.Reader; -import be.nikiroo.utils.Image; -import be.nikiroo.utils.android.ImageUtilsAndroid; - -public class AndroidReaderBook extends Fragment { - private OnFragmentInteractionListener listener; - - /** - * This interface must be implemented by activities that contain this - * fragment to allow an interaction in this fragment to be communicated to - * the activity and potentially other fragments contained in that activity. - *

- * See the Android Training lesson Communicating with Other Fragments for more information. - */ - public interface OnFragmentInteractionListener { - void onFragmentInteraction(MetaData meta); - } - - public AndroidReaderBook() { - // Required empty public constructor - } - - @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, - Bundle savedInstanceState) { - return inflater.inflate(R.layout.fragment_android_reader_book, - container, false); - } - - @Override - public void onAttach(Activity context) { - super.onAttach(context); - if (context instanceof OnFragmentInteractionListener) { - listener = (OnFragmentInteractionListener) context; - } - } - - @Override - public void onDetach() { - super.onDetach(); - listener = null; - } - - public void fill(final MetaData meta, final Reader reader) { - ViewHolder viewHolder = new ViewHolder(getView()); - - viewHolder.title.setText(meta.getTitle()); - viewHolder.author.setText(meta.getAuthor()); - viewHolder.frame.setClickable(true); - viewHolder.frame.setFocusable(true); - viewHolder.frame.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - OnFragmentInteractionListener llistener = listener; - if (llistener != null) { - llistener.onFragmentInteraction(meta); - } - } - }); - - new AsyncTask() { - @Override - protected Image doInBackground(MetaData[] metas) { - if (metas[0].getCover() != null) { - return metas[0].getCover(); - } - - return reader.getLibrary().getCover(metas[0].getLuid()); - } - - @Override - protected void onPostExecute(Image coverImage) { - ViewHolder viewHolder = new ViewHolder(getView()); - - try { - if (coverImage != null) { - Bitmap coverBitmap = ImageUtilsAndroid - .fromImage(coverImage); - coverBitmap = Bitmap.createScaledBitmap(coverBitmap, - 128, 128, true); - viewHolder.cover.setImageBitmap(coverBitmap); - } - } catch (IOException e) { - e.printStackTrace(); - } - } - }.execute(meta); - } - - private class ViewHolder { - public FrameLayout frame; - public TextView title; - public TextView author; - public ImageView cover; - - public ViewHolder(View book) { - frame = book.findViewById(R.id.Book); - title = book.findViewById(R.id.Book_lblTitle); - author = book.findViewById(R.id.Book_lblAuthor); - cover = book.findViewById(R.id.Book_imgCover); - } - } -} diff --git a/src/be/nikiroo/fanfix/reader/android/AndroidReaderGroup.java b/src/be/nikiroo/fanfix/reader/android/AndroidReaderGroup.java deleted file mode 100644 index 2d48199..0000000 --- a/src/be/nikiroo/fanfix/reader/android/AndroidReaderGroup.java +++ /dev/null @@ -1,101 +0,0 @@ -package be.nikiroo.fanfix.reader.android; - -import android.app.Fragment; -import android.app.FragmentTransaction; -import android.content.Context; -import android.os.Bundle; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.BaseAdapter; -import android.widget.ListView; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import be.nikiroo.fanfix.data.MetaData; -import be.nikiroo.fanfix.reader.Reader; - -/** - * A simple {@link Fragment} subclass. Activities that contain this fragment - * must implement the {@link AndroidReaderGroup.OnFragmentInteractionListener} - * interface to handle interaction events. - */ -public class AndroidReaderGroup extends Fragment { - private OnFragmentInteractionListener listener; - private Map books = new HashMap(); - - public interface OnFragmentInteractionListener { - void onFragmentInteraction(MetaData meta); - } - - public AndroidReaderGroup() { - // Required empty public constructor - } - - @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, - Bundle savedInstanceState) { - return inflater.inflate(R.layout.fragment_android_reader_group, - container, false); - } - - @Override - public void onAttach(Context context) { - super.onAttach(context); - if (context instanceof OnFragmentInteractionListener) { - listener = (OnFragmentInteractionListener) context; - } - } - - @Override - public void onDetach() { - super.onDetach(); - listener = null; - } - - public void fill(final List metas, final Reader reader) { - final List datas = new ArrayList(metas); - - ListView list = getView().findViewById(R.id.Group_root); - list.setAdapter(new BaseAdapter() { - @Override - public int getCount() { - return datas.size(); - } - - @Override - public long getItemId(int position) { - return -1; // TODO: what is a "row id" in this context? - } - - @Override - public Object getItem(int position) { - return datas.get(position); - } - - @Override - public View getView(int position, View convertView, ViewGroup parent) { - AndroidReaderBook book = books.get(convertView); - if (book == null) { - book = new AndroidReaderBook(); - - FragmentTransaction trans = getFragmentManager() - .beginTransaction(); - trans.add(book, null); - trans.commit(); - getFragmentManager().executePendingTransactions(); - - books.put(book.getView(), book); - } - - MetaData meta = (MetaData) getItem(position); - book.fill(meta, reader); - - return book.getView(); - } - }); - } -} -- 2.27.0