aboutsummaryrefslogtreecommitdiff
path: root/src/org/fox/ttrss/util
diff options
context:
space:
mode:
Diffstat (limited to 'src/org/fox/ttrss/util')
-rw-r--r--src/org/fox/ttrss/util/AppRater.java105
-rw-r--r--src/org/fox/ttrss/util/DatabaseHelper.java89
-rw-r--r--src/org/fox/ttrss/util/EnlargingImageView.java252
-rw-r--r--src/org/fox/ttrss/util/FontSizeDialogPreference.java224
-rw-r--r--src/org/fox/ttrss/util/HeadlinesRequest.java101
-rw-r--r--src/org/fox/ttrss/util/ImageCacheService.java212
-rw-r--r--src/org/fox/ttrss/util/LessBrokenWebView.java37
-rw-r--r--src/org/fox/ttrss/util/NoChildFocusScrollView.java34
-rw-r--r--src/org/fox/ttrss/util/PrefsBackupAgent.java19
-rw-r--r--src/org/fox/ttrss/util/SimpleLoginManager.java105
-rw-r--r--src/org/fox/ttrss/util/TitleWebView.java91
-rw-r--r--src/org/fox/ttrss/util/TypefaceCache.java29
12 files changed, 0 insertions, 1298 deletions
diff --git a/src/org/fox/ttrss/util/AppRater.java b/src/org/fox/ttrss/util/AppRater.java
deleted file mode 100644
index 21dccdff..00000000
--- a/src/org/fox/ttrss/util/AppRater.java
+++ /dev/null
@@ -1,105 +0,0 @@
-package org.fox.ttrss.util;
-
-// From http://androidsnippets.com/prompt-engaged-users-to-rate-your-app-in-the-android-market-appirater
-
-import android.app.Dialog;
-import android.content.ActivityNotFoundException;
-import android.content.Context;
-import android.content.Intent;
-import android.content.SharedPreferences;
-import android.net.Uri;
-import android.view.View;
-import android.view.View.OnClickListener;
-import android.widget.Button;
-import android.widget.LinearLayout;
-import android.widget.TextView;
-
-public class AppRater {
- private final static String APP_TITLE = "Tiny Tiny RSS";
- private final static String APP_PNAME = "org.fox.ttrss";
-
- private final static int DAYS_UNTIL_PROMPT = 3;
- private final static int LAUNCHES_UNTIL_PROMPT = 7;
-
- public static void appLaunched(Context mContext) {
- SharedPreferences prefs = mContext.getSharedPreferences("apprater", 0);
-
- if (prefs.getBoolean("dontshowagain", false)) { return ; }
-
- SharedPreferences.Editor editor = prefs.edit();
-
- // Increment launch counter
- long launch_count = prefs.getLong("launch_count", 0) + 1;
- editor.putLong("launch_count", launch_count);
-
- // Get date of first launch
- Long date_firstLaunch = prefs.getLong("date_firstlaunch", 0);
- if (date_firstLaunch == 0) {
- date_firstLaunch = System.currentTimeMillis();
- editor.putLong("date_firstlaunch", date_firstLaunch);
- }
-
- // Wait at least n days before opening
- if (launch_count >= LAUNCHES_UNTIL_PROMPT &&
- !prefs.getBoolean("dontshowagain", false) &&
- System.currentTimeMillis() >= date_firstLaunch + (DAYS_UNTIL_PROMPT * 24 * 60 * 60 * 1000)) {
-
- showRateDialog(mContext, editor);
- }
-
- editor.commit();
- }
-
- public static void showRateDialog(final Context mContext, final SharedPreferences.Editor editor) {
- final Dialog dialog = new Dialog(mContext);
- dialog.setTitle("Rate " + APP_TITLE);
-
- LinearLayout ll = new LinearLayout(mContext);
- ll.setOrientation(LinearLayout.VERTICAL);
-
- TextView tv = new TextView(mContext);
- tv.setText("If you enjoy using " + APP_TITLE + ", please take a moment to rate it. Thanks for your support!");
- tv.setWidth(240);
- tv.setPadding(4, 0, 4, 10);
- ll.addView(tv);
-
- Button b1 = new Button(mContext);
- b1.setText("Rate " + APP_TITLE);
- b1.setOnClickListener(new OnClickListener() {
- public void onClick(View v) {
- try {
- mContext.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + APP_PNAME)));
- } catch (ActivityNotFoundException e) {
- mContext.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=" + APP_PNAME)));
- }
- dialog.dismiss();
- }
- });
- ll.addView(b1);
-
- Button b2 = new Button(mContext);
- b2.setText("Remind me later");
- b2.setOnClickListener(new OnClickListener() {
- public void onClick(View v) {
- dialog.dismiss();
- }
- });
- ll.addView(b2);
-
- Button b3 = new Button(mContext);
- b3.setText("No, thanks");
- b3.setOnClickListener(new OnClickListener() {
- public void onClick(View v) {
- if (editor != null) {
- editor.putBoolean("dontshowagain", true);
- editor.commit();
- }
- dialog.dismiss();
- }
- });
- ll.addView(b3);
-
- dialog.setContentView(ll);
- dialog.show();
- }
-} \ No newline at end of file
diff --git a/src/org/fox/ttrss/util/DatabaseHelper.java b/src/org/fox/ttrss/util/DatabaseHelper.java
deleted file mode 100644
index 572ff62e..00000000
--- a/src/org/fox/ttrss/util/DatabaseHelper.java
+++ /dev/null
@@ -1,89 +0,0 @@
-package org.fox.ttrss.util;
-import android.content.Context;
-import android.database.sqlite.SQLiteDatabase;
-import android.database.sqlite.SQLiteOpenHelper;
-import android.provider.BaseColumns;
-
-
-public class DatabaseHelper extends SQLiteOpenHelper {
-
- @SuppressWarnings("unused")
- private final String TAG = this.getClass().getSimpleName();
- public static final String DATABASE_NAME = "OfflineStorage.db";
- public static final int DATABASE_VERSION = 4;
-
- public DatabaseHelper(Context context) {
- super(context, DATABASE_NAME, null, DATABASE_VERSION);
- }
-
- @Override
- public void onCreate(SQLiteDatabase db) {
- db.execSQL("DROP VIEW IF EXISTS cats_unread;");
- db.execSQL("DROP VIEW IF EXISTS feeds_unread;");
- db.execSQL("DROP TRIGGER IF EXISTS articles_set_modified;");
- db.execSQL("DROP TABLE IF EXISTS categories;");
- db.execSQL("DROP TABLE IF EXISTS feeds;");
- db.execSQL("DROP TABLE IF EXISTS articles;");
-
- db.execSQL("CREATE TABLE IF NOT EXISTS feeds (" +
- BaseColumns._ID + " INTEGER PRIMARY KEY AUTOINCREMENT," +
- "feed_url TEXT, " +
- "title TEXT, " +
- "has_icon BOOLEAN, " +
- "cat_id INTEGER" +
- ");");
-
- db.execSQL("CREATE TABLE IF NOT EXISTS categories (" +
- BaseColumns._ID + " INTEGER PRIMARY KEY AUTOINCREMENT," +
- "title TEXT" +
- ");");
-
- db.execSQL("CREATE TABLE IF NOT EXISTS articles (" +
- BaseColumns._ID + " INTEGER PRIMARY KEY AUTOINCREMENT," +
- "unread BOOLEAN, " +
- "marked BOOLEAN, " +
- "published BOOLEAN, " +
- "score INTEGER, " +
- "updated INTEGER, " +
- "is_updated BOOLEAN, " +
- "title TEXT, " +
- "link TEXT, " +
- "feed_id INTEGER, " +
- "tags TEXT, " +
- "content TEXT, " +
- "author TEXT, " +
- "selected BOOLEAN, " +
- "modified BOOLEAN" +
- ");");
-
- db.execSQL("CREATE TRIGGER articles_set_modified UPDATE OF marked, published, unread ON articles " +
- "BEGIN " +
- " UPDATE articles SET modified = 1 WHERE " + BaseColumns._ID + " = " + "OLD." + BaseColumns._ID + "; " +
- "END;");
-
- db.execSQL("CREATE VIEW feeds_unread AS SELECT feeds."+BaseColumns._ID+" AS "+BaseColumns._ID+", " +
- "feeds.title AS title, " +
- "cat_id, " +
- "SUM(articles.unread) AS unread FROM feeds " +
- "LEFT JOIN articles ON (articles.feed_id = feeds."+BaseColumns._ID+") " +
- "GROUP BY feeds."+BaseColumns._ID+", feeds.title;");
-
- //sqlite> select categories._id,categories.title,sum(articles.unread) from categories left j
- //oin feeds on (feeds.cat_id = categories._id) left join articles on (articles.feed_id = fee
- //ds._id) group by categories._id;
-
- db.execSQL("CREATE VIEW cats_unread AS SELECT categories."+BaseColumns._ID+" AS "+BaseColumns._ID+", " +
- "categories.title AS title, " +
- "SUM(articles.unread) AS unread FROM categories " +
- "LEFT JOIN feeds ON (feeds.cat_id = categories."+BaseColumns._ID+") "+
- "LEFT JOIN articles ON (articles.feed_id = feeds."+BaseColumns._ID+") " +
- "GROUP BY categories."+BaseColumns._ID+", categories.title;");
-
- }
-
- @Override
- public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
- onCreate(db);
- }
-
-}
diff --git a/src/org/fox/ttrss/util/EnlargingImageView.java b/src/org/fox/ttrss/util/EnlargingImageView.java
deleted file mode 100644
index b6f9bce9..00000000
--- a/src/org/fox/ttrss/util/EnlargingImageView.java
+++ /dev/null
@@ -1,252 +0,0 @@
-package org.fox.ttrss.util;
-
-/*
- * Copyright (C) 2013 Tomáš Procházka
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-import java.lang.reflect.Field;
-
-import android.content.Context;
-import android.util.AttributeSet;
-import android.view.View;
-
-/**
- * Special version of ImageView which allow enlarge width of image if android:adjustViewBounds is true.
- *
- * <p>It simulate HTML behaviour &lt;img src="" widh="100" /&gt;</p>
- * <p><a href="http://stackoverflow.com/questions/6202000/imageview-one-dimension-to-fit-free-space-and-second-evaluate-to-keep-aspect-rati">Stackoverflow question link</a></p>
- *
- * <p>It also allow set related view which will be used as reference for size measure.</p>
- *
- * @author Tomáš Procházka &lt;<a href="mailto:tomas.prochazka@inmite.eu">tomas.prochazka@gmail.com</a>&gt;
- * @version $Revision: 0$ ($Date: 6.6.2011 18:16:52$)
- */
-public class EnlargingImageView extends android.widget.ImageView {
-
- private int mDrawableWidth;
- private int mDrawableHeight;
- private boolean mAdjustViewBoundsL;
- private int mMaxWidthL = Integer.MAX_VALUE;
- private int mMaxHeightL = Integer.MAX_VALUE;
- private View relatedView;
-
- public EnlargingImageView(Context context, AttributeSet attrs, int defStyle) {
- super(context, attrs, defStyle);
-
- // hack for acces some private field of parent :-(
- Field f;
- try {
- f = android.widget.ImageView.class.getDeclaredField("mAdjustViewBounds");
- f.setAccessible(true);
- setAdjustViewBounds((Boolean) f.get(this));
-
- f = android.widget.ImageView.class.getDeclaredField("mMaxWidth");
- f.setAccessible(true);
- setMaxWidth((Integer) f.get(this));
-
- f = android.widget.ImageView.class.getDeclaredField("mMaxHeight");
- f.setAccessible(true);
- setMaxHeight((Integer) f.get(this));
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
-
- public EnlargingImageView(Context context, AttributeSet attrs) {
- this(context, attrs, 0);
- }
-
- public EnlargingImageView(Context context) {
- super(context);
- }
-
- public void setAdjustViewBounds(boolean adjustViewBounds) {
- super.setAdjustViewBounds(adjustViewBounds);
- mAdjustViewBoundsL = adjustViewBounds;
- }
-
- public void setMaxWidth(int maxWidth) {
- super.setMaxWidth(maxWidth);
- mMaxWidthL = maxWidth;
- }
-
- public void setMaxHeight(int maxHeight) {
- super.setMaxHeight(maxHeight);
- mMaxHeightL = maxHeight;
- }
-
- @Override
- protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
- super.onMeasure(widthMeasureSpec, heightMeasureSpec);
-
- if (getDrawable() == null) {
- setMeasuredDimension(0, 0);
- return;
- }
-
- mDrawableWidth = getDrawable().getIntrinsicWidth();
- mDrawableHeight = getDrawable().getIntrinsicHeight();
-
- int w = 0;
- int h = 0;
-
- // Desired aspect ratio of the view's contents (not including padding)
- float desiredAspect = 0.0f;
-
- // We are allowed to change the view's width
- boolean resizeWidth = false;
-
- // We are allowed to change the view's height
- boolean resizeHeight = false;
-
- if (mDrawableWidth > 0) {
- w = mDrawableWidth;
- h = mDrawableHeight;
- if (w <= 0) w = 1;
- if (h <= 0) h = 1;
-
- // We are supposed to adjust view bounds to match the aspect
- // ratio of our drawable. See if that is possible.
- if (mAdjustViewBoundsL) {
-
- int widthSpecMode = MeasureSpec.getMode(widthMeasureSpec);
- int heightSpecMode = MeasureSpec.getMode(heightMeasureSpec);
-
- resizeWidth = widthSpecMode != MeasureSpec.EXACTLY;
- resizeHeight = heightSpecMode != MeasureSpec.EXACTLY;
-
- desiredAspect = (float) w / (float) h;
- }
- }
-
- int pleft = getPaddingLeft();
- int pright = getPaddingRight();
- int ptop = getPaddingTop();
- int pbottom = getPaddingBottom();
-
- int widthSize;
- int heightSize;
-
- if (resizeWidth || resizeHeight) {
- /* If we get here, it means we want to resize to match the
- drawables aspect ratio, and we have the freedom to change at
- least one dimension.
- */
-
- // Get the max possible width given our constraints
- widthSize = resolveAdjustedSize(w + pleft + pright,
- mMaxWidthL, widthMeasureSpec);
-
- // Get the max possible height given our constraints
- heightSize = resolveAdjustedSize(h + ptop + pbottom,
- mMaxHeightL, heightMeasureSpec);
-
- if (desiredAspect != 0.0f) {
- // See what our actual aspect ratio is
- float actualAspect = (float) (widthSize - pleft - pright) /
- (heightSize - ptop - pbottom);
-
- if (Math.abs(actualAspect - desiredAspect) > 0.0000001) {
-
- // Try adjusting width to be proportional to height
- if (resizeWidth) {
- int newWidth = (int) (desiredAspect * (heightSize - ptop - pbottom)) + pleft + pright;
- if (/*newWidth <= widthSize &&*/newWidth > 0) {
- widthSize = Math.min(newWidth, mMaxWidthL);
- heightSize = (int) ((widthSize - pleft - pright) / desiredAspect) + ptop + pbottom;
- }
- }
-
- // Try adjusting height to be proportional to width
- if (resizeHeight) {
- int newHeight = (int) ((widthSize - pleft - pright) / desiredAspect) + ptop + pbottom;
- if (/*newHeight <= heightSize && */newHeight > 0) {
- heightSize = Math.min(newHeight, mMaxHeightL);
- widthSize = (int) (desiredAspect * (heightSize - ptop - pbottom)) + pleft + pright;
- }
- }
- }
- }
- } else {
- /* We are either don't want to preserve the drawables aspect ratio,
- or we are not allowed to change view dimensions. Just measure in
- the normal way.
- */
- w += pleft + pright;
- h += ptop + pbottom;
-
- w = Math.max(w, getSuggestedMinimumWidth());
- h = Math.max(h, getSuggestedMinimumHeight());
-
- widthSize = resolveSize(w, widthMeasureSpec);
- heightSize = resolveSize(h, heightMeasureSpec);
- }
-
- //Log.d(Constants.LOGTAG, mDrawableWidth + ":" + mDrawableHeight + " to " + widthSize + ":" + heightSize);
-
- setMeasuredDimension(widthSize, heightSize);
-
- if (relatedView != null) {
- //Log.i(Constants.LOGTAG, getTag() + " onMeasure:" + widthSize + ", " + heightSize + " update size of related view!");
- relatedView.getLayoutParams().width = widthSize;
- relatedView.getLayoutParams().height = heightSize;
- }
-
- }
-
- @Override
- protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
- super.onLayout(changed, left, top, right, bottom);
- //Log.d(Constants.LOGTAG, getTag() + " onLayout:" + left + ", " + top + ", " + right + ", " + bottom);
- }
-
- /**
- * Experimental. This view will be set to the same size as this image.
- */
- public void setRelatedView(View view) {
- relatedView = view;
- }
-
- @Override
- protected void onSizeChanged(int w, int h, int oldw, int oldh) {
- super.onSizeChanged(w, h, oldw, oldh);
- //Log.d(Constants.LOGTAG, getTag() + " onSizeChanged:" + w + ", " + h + ", " + oldw + ", " + oldh);
- }
-
- private int resolveAdjustedSize(int desiredSize, int maxSize, int measureSpec) {
- int result = desiredSize;
- int specMode = MeasureSpec.getMode(measureSpec);
- int specSize = MeasureSpec.getSize(measureSpec);
- switch (specMode) {
- case MeasureSpec.UNSPECIFIED:
- /* Parent says we can be as big as we want. Just don't be larger
- than max size imposed on ourselves.
- */
- result = Math.min(desiredSize, maxSize);
- break;
- case MeasureSpec.AT_MOST:
- // Parent says we can be as big as we want, up to specSize.
- // Don't be larger than specSize, and don't be larger than
- // the max size imposed on ourselves.
- result = Math.min(Math.min(desiredSize, specSize), maxSize);
- break;
- case MeasureSpec.EXACTLY:
- // No choice. Do what we are told.
- result = specSize;
- break;
- }
- return result;
- }
-} \ No newline at end of file
diff --git a/src/org/fox/ttrss/util/FontSizeDialogPreference.java b/src/org/fox/ttrss/util/FontSizeDialogPreference.java
deleted file mode 100644
index a4220fd1..00000000
--- a/src/org/fox/ttrss/util/FontSizeDialogPreference.java
+++ /dev/null
@@ -1,224 +0,0 @@
-package org.fox.ttrss.util;
-
-// http://www.lukehorvat.com/blog/android-seekbardialogpreference/
-
-import org.fox.ttrss.R;
-
-import android.content.Context;
-import android.content.res.TypedArray;
-import android.os.Parcel;
-import android.os.Parcelable;
-import android.preference.DialogPreference;
-import android.util.AttributeSet;
-import android.util.TypedValue;
-import android.view.View;
-import android.widget.SeekBar;
-import android.widget.SeekBar.OnSeekBarChangeListener;
-import android.widget.TextView;
-
-/**
- * A {@link DialogPreference} that provides a user with the means to select an
- * integer from a {@link SeekBar}, and persist it.
- *
- * @author lukehorvat
- *
- */
-public class FontSizeDialogPreference extends DialogPreference {
- private static final int DEFAULT_MIN_PROGRESS = 9;
- private static final int DEFAULT_MAX_PROGRESS = 24;
- private static final String DEFAULT_PROGRESS = "0";
-
- private int mMinProgress = DEFAULT_MIN_PROGRESS;
- private int mMaxProgress = DEFAULT_MAX_PROGRESS;
- private int mProgress;
- private CharSequence mProgressTextSuffix;
- private TextView mProgressText;
- private SeekBar mSeekBar;
-
- public FontSizeDialogPreference(Context context) {
- this(context, null);
- }
-
- public FontSizeDialogPreference(Context context, AttributeSet attrs) {
- super(context, attrs);
-
- setProgressTextSuffix(" " + context.getString(R.string.font_size_dialog_suffix));
-
- // set layout
- setDialogLayoutResource(R.layout.select_font_size_dialog);
- setPositiveButtonText(android.R.string.ok);
- setNegativeButtonText(android.R.string.cancel);
- setDialogIcon(null);
- }
-
- @Override
- protected void onSetInitialValue(boolean restore, Object defaultValue) {
- setProgress(restore ? Integer.valueOf(getPersistedString(DEFAULT_PROGRESS))
- : Integer.valueOf((String)defaultValue));
- }
-
- @Override
- protected Object onGetDefaultValue(TypedArray a, int index) {
- return a.getString(index);
- }
-
- @Override
- protected void onBindDialogView(View view) {
- super.onBindDialogView(view);
-
- mProgressText = (TextView) view.findViewById(R.id.text_progress);
-
- mSeekBar = (SeekBar) view.findViewById(R.id.seek_bar);
- mSeekBar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
- @Override
- public void onStopTrackingTouch(SeekBar seekBar) {
- }
-
- @Override
- public void onStartTrackingTouch(SeekBar seekBar) {
- }
-
- @Override
- public void onProgressChanged(SeekBar seekBar, int progress,
- boolean fromUser) {
- // update text that displays the current SeekBar progress value
- // note: this does not persist the progress value. that is only
- // ever done in setProgress()
- String progressStr = String.valueOf(progress + mMinProgress);
- mProgressText.setText(mProgressTextSuffix == null ? progressStr
- : progressStr.concat(mProgressTextSuffix.toString()));
- mProgressText.setTextSize(TypedValue.COMPLEX_UNIT_SP, progress + mMinProgress);
- }
- });
-
- mSeekBar.setMax(mMaxProgress - mMinProgress);
- mSeekBar.setProgress(mProgress - mMinProgress);
- }
-
- public int getMinProgress() {
- return mMinProgress;
- }
-
- public void setMinProgress(int minProgress) {
- mMinProgress = minProgress;
- setProgress(Math.max(mProgress, mMinProgress));
- }
-
- public int getMaxProgress() {
- return mMaxProgress;
- }
-
- public void setMaxProgress(int maxProgress) {
- mMaxProgress = maxProgress;
- setProgress(Math.min(mProgress, mMaxProgress));
- }
-
- public int getProgress() {
- return mProgress;
- }
-
- public void setProgress(int progress) {
- progress = Math.max(Math.min(progress, mMaxProgress), mMinProgress);
-
- if (progress != mProgress) {
- mProgress = progress;
- persistString(String.valueOf(progress));
- notifyChanged();
- }
- }
-
- public CharSequence getProgressTextSuffix() {
- return mProgressTextSuffix;
- }
-
- public void setProgressTextSuffix(CharSequence progressTextSuffix) {
- mProgressTextSuffix = progressTextSuffix;
- }
-
- @Override
- protected void onDialogClosed(boolean positiveResult) {
- super.onDialogClosed(positiveResult);
-
- // when the user selects "OK", persist the new value
- if (positiveResult) {
- int seekBarProgress = mSeekBar.getProgress() + mMinProgress;
- if (callChangeListener(seekBarProgress)) {
- setProgress(seekBarProgress);
- }
- }
- }
-
- @Override
- protected Parcelable onSaveInstanceState() {
- // save the instance state so that it will survive screen orientation
- // changes and other events that may temporarily destroy it
- final Parcelable superState = super.onSaveInstanceState();
-
- // set the state's value with the class member that holds current
- // setting value
- final SavedState myState = new SavedState(superState);
- myState.minProgress = getMinProgress();
- myState.maxProgress = getMaxProgress();
- myState.progress = getProgress();
-
- return myState;
- }
-
- @Override
- protected void onRestoreInstanceState(Parcelable state) {
- // check whether we saved the state in onSaveInstanceState()
- if (state == null || !state.getClass().equals(SavedState.class)) {
- // didn't save the state, so call superclass
- super.onRestoreInstanceState(state);
- return;
- }
-
- // restore the state
- SavedState myState = (SavedState) state;
- setMinProgress(myState.minProgress);
- setMaxProgress(myState.maxProgress);
- setProgress(myState.progress);
-
- super.onRestoreInstanceState(myState.getSuperState());
- }
-
- private static class SavedState extends BaseSavedState {
- int minProgress;
- int maxProgress;
- int progress;
-
- public SavedState(Parcelable superState) {
- super(superState);
- }
-
- public SavedState(Parcel source) {
- super(source);
-
- minProgress = source.readInt();
- maxProgress = source.readInt();
- progress = source.readInt();
- }
-
- @Override
- public void writeToParcel(Parcel dest, int flags) {
- super.writeToParcel(dest, flags);
-
- dest.writeInt(minProgress);
- dest.writeInt(maxProgress);
- dest.writeInt(progress);
- }
-
- @SuppressWarnings("unused")
- public static final Parcelable.Creator<SavedState> CREATOR = new Parcelable.Creator<SavedState>() {
- @Override
- public SavedState createFromParcel(Parcel in) {
- return new SavedState(in);
- }
-
- @Override
- public SavedState[] newArray(int size) {
- return new SavedState[size];
- }
- };
- }
-} \ No newline at end of file
diff --git a/src/org/fox/ttrss/util/HeadlinesRequest.java b/src/org/fox/ttrss/util/HeadlinesRequest.java
deleted file mode 100644
index 551c0add..00000000
--- a/src/org/fox/ttrss/util/HeadlinesRequest.java
+++ /dev/null
@@ -1,101 +0,0 @@
-package org.fox.ttrss.util;
-
-import java.lang.reflect.Type;
-import java.util.List;
-
-import org.fox.ttrss.ApiRequest;
-import org.fox.ttrss.GlobalState;
-import org.fox.ttrss.OnlineActivity;
-import org.fox.ttrss.R;
-import org.fox.ttrss.types.Article;
-import org.fox.ttrss.types.ArticleList;
-import org.fox.ttrss.types.Feed;
-
-import android.content.Context;
-import android.util.Log;
-
-import com.google.gson.Gson;
-import com.google.gson.JsonArray;
-import com.google.gson.JsonElement;
-import com.google.gson.reflect.TypeToken;
-
-public class HeadlinesRequest extends ApiRequest {
- public static final int HEADLINES_REQUEST_SIZE = 30;
- public static final int HEADLINES_BUFFER_MAX = 1500;
-
- private final String TAG = this.getClass().getSimpleName();
-
- private int m_offset = 0;
- private OnlineActivity m_activity;
- private ArticleList m_articles = GlobalState.getInstance().m_loadedArticles;
- private Feed m_feed;
-
- public HeadlinesRequest(Context context, OnlineActivity activity, final Feed feed) {
- super(context);
-
- m_activity = activity;
- m_feed = feed;
- }
-
- protected void onPostExecute(JsonElement result) {
- if (result != null) {
- try {
-
- // check if we are returning results for correct feed
- if (GlobalState.getInstance().m_activeFeed != null && !m_feed.equals(GlobalState.getInstance().m_activeFeed)) {
- Log.d(TAG, "received results for wrong feed, bailing out.");
- return;
- }
-
- JsonArray content = result.getAsJsonArray();
- if (content != null) {
- Type listType = new TypeToken<List<Article>>() {}.getType();
- final List<Article> articles = new Gson().fromJson(content, listType);
-
- if (m_offset == 0) {
- m_articles.clear();
- } else {
- while (m_articles.size() > HEADLINES_BUFFER_MAX) {
- m_articles.remove(0);
- }
-
- if (m_articles.get(m_articles.size()-1).id == -1) {
- m_articles.remove(m_articles.size()-1); // remove previous placeholder
- }
-
- }
-
- for (Article f : articles)
- if (!m_articles.containsId(f.id))
- m_articles.add(f);
-
- if (articles.size() == HEADLINES_REQUEST_SIZE) {
- Article placeholder = new Article(-1);
- m_articles.add(placeholder);
- }
-
- /* if (m_articles.size() == 0)
- m_activity.setLoadingStatus(R.string.no_headlines_to_display, false);
- else */
-
- m_activity.setLoadingStatus(R.string.blank, false);
-
- return;
- }
-
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
-
- if (m_lastError == ApiError.LOGIN_FAILED) {
- m_activity.login();
- } else {
- m_activity.setLoadingStatus(getErrorMessage(), false);
- }
- }
-
- public void setOffset(int skip) {
- m_offset = skip;
- }
-}
diff --git a/src/org/fox/ttrss/util/ImageCacheService.java b/src/org/fox/ttrss/util/ImageCacheService.java
deleted file mode 100644
index 5b029fc6..00000000
--- a/src/org/fox/ttrss/util/ImageCacheService.java
+++ /dev/null
@@ -1,212 +0,0 @@
-package org.fox.ttrss.util;
-
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.URL;
-import java.net.URLConnection;
-import java.security.MessageDigest;
-import java.security.NoSuchAlgorithmException;
-import java.util.Date;
-
-import org.fox.ttrss.OnlineActivity;
-import org.fox.ttrss.R;
-import org.fox.ttrss.offline.OfflineDownloadService;
-
-import android.app.ActivityManager;
-import android.app.ActivityManager.RunningServiceInfo;
-import android.app.IntentService;
-import android.app.Notification;
-import android.app.NotificationManager;
-import android.app.PendingIntent;
-import android.content.Context;
-import android.content.Intent;
-import android.os.Environment;
-
-public class ImageCacheService extends IntentService {
-
- @SuppressWarnings("unused")
- private final String TAG = this.getClass().getSimpleName();
-
- public static final int NOTIFY_DOWNLOADING = 1;
-
- private static final String CACHE_PATH = "/image-cache/";
-
- private int m_imagesDownloaded = 0;
-
- private NotificationManager m_nmgr;
-
- public ImageCacheService() {
- super("ImageCacheService");
- }
-
- private boolean isDownloadServiceRunning() {
- ActivityManager manager = (ActivityManager) getSystemService(ACTIVITY_SERVICE);
- for (RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
- if ("org.fox.ttrss.OfflineDownloadService".equals(service.service.getClassName())) {
- return true;
- }
- }
- return false;
- }
-
-
- @Override
- public void onCreate() {
- super.onCreate();
- m_nmgr = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
- }
-
- public static boolean isUrlCached(Context context, String url) {
- String hashedUrl = md5(url);
-
- File storage = context.getExternalCacheDir();
-
- File file = new File(storage.getAbsolutePath() + CACHE_PATH + "/" + hashedUrl + ".png");
-
- return file.exists();
- }
-
- public static String getCacheFileName(Context context, String url) {
- String hashedUrl = md5(url);
-
- File storage = context.getExternalCacheDir();
-
- File file = new File(storage.getAbsolutePath() + CACHE_PATH + "/" + hashedUrl + ".png");
-
- return file.getAbsolutePath();
- }
-
- public static void cleanupCache(Context context, boolean deleteAll) {
- if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())) {
- File storage = context.getExternalCacheDir();
- File cachePath = new File(storage.getAbsolutePath() + CACHE_PATH);
-
- long now = new Date().getTime();
-
- if (cachePath.isDirectory()) {
- for (File file : cachePath.listFiles()) {
- if (deleteAll || now - file.lastModified() > 1000*60*60*24*7) {
- file.delete();
- }
- }
- }
- }
- }
-
- protected static String md5(String s) {
- try {
- MessageDigest digest = java.security.MessageDigest.getInstance("MD5");
- digest.update(s.getBytes());
- byte messageDigest[] = digest.digest();
-
- StringBuffer hexString = new StringBuffer();
- for (int i=0; i<messageDigest.length; i++)
- hexString.append(Integer.toHexString(0xFF & messageDigest[i]));
-
- return hexString.toString();
-
- } catch (NoSuchAlgorithmException e) {
- e.printStackTrace();
- }
-
- return null;
- }
-
- private InputStream getStream(String urlString) {
- try {
- URL url = new URL(urlString);
- URLConnection urlConnection = url.openConnection();
- urlConnection.setConnectTimeout(250);
- urlConnection.setReadTimeout(5*1000);
- return urlConnection.getInputStream();
- } catch (Exception ex) {
- return null;
- }
- }
-
- @SuppressWarnings("deprecation")
- private void updateNotification(String msg) {
- Notification notification = new Notification(R.drawable.icon,
- getString(R.string.notify_downloading_title), System.currentTimeMillis());
-
- PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
- new Intent(this, OnlineActivity.class), 0);
-
- notification.flags |= Notification.FLAG_ONGOING_EVENT;
- notification.flags |= Notification.FLAG_ONLY_ALERT_ONCE;
-
- notification.setLatestEventInfo(this, getString(R.string.notify_downloading_title), msg, contentIntent);
-
- m_nmgr.notify(NOTIFY_DOWNLOADING, notification);
- }
-
- /* private void updateNotification(int msgResId) {
- updateNotification(getString(msgResId));
- } */
-
- @Override
- protected void onHandleIntent(Intent intent) {
- String url = intent.getStringExtra("url");
-
- //Log.d(TAG, "got request to download URL=" + url);
-
- if (!Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState()))
- return;
-
- String hashedUrl = md5(url);
-
- File storage = getExternalCacheDir();
- File cachePath = new File(storage.getAbsolutePath() + CACHE_PATH);
- if (!cachePath.exists()) cachePath.mkdirs();
-
- if (cachePath.isDirectory() && hashedUrl != null) {
- File outputFile = new File(cachePath.getAbsolutePath() + "/" + hashedUrl + ".png");
-
- if (!outputFile.exists()) {
-
- //Log.d(TAG, "downloading to " + outputFile.getAbsolutePath());
-
- InputStream is = getStream(url);
-
- if (is != null) {
- try {
- FileOutputStream fos = new FileOutputStream(outputFile);
-
- byte[] buffer = new byte[1024];
- int len = 0;
- while ((len = is.read(buffer)) != -1) {
- fos.write(buffer, 0, len);
- }
-
- fos.close();
- is.close();
-
- m_imagesDownloaded++;
-
- updateNotification(getString(R.string.notify_downloading_images, m_imagesDownloaded));
-
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- }
- }
- }
-
- @Override
- public void onDestroy() {
- super.onDestroy();
-
- if (!isDownloadServiceRunning()) {
- m_nmgr.cancel(NOTIFY_DOWNLOADING);
-
- Intent success = new Intent();
- success.setAction(OfflineDownloadService.INTENT_ACTION_SUCCESS);
- success.addCategory(Intent.CATEGORY_DEFAULT);
- sendBroadcast(success);
- }
- }
-
-}
diff --git a/src/org/fox/ttrss/util/LessBrokenWebView.java b/src/org/fox/ttrss/util/LessBrokenWebView.java
deleted file mode 100644
index c6cab513..00000000
--- a/src/org/fox/ttrss/util/LessBrokenWebView.java
+++ /dev/null
@@ -1,37 +0,0 @@
-package org.fox.ttrss.util;
-
-import android.content.Context;
-import android.util.AttributeSet;
-import android.view.MotionEvent;
-import android.webkit.WebView;
-
-public class LessBrokenWebView extends WebView {
-
- public LessBrokenWebView(Context context) {
- super(context);
- // TODO Auto-generated constructor stub
- }
-
- public LessBrokenWebView(Context context, AttributeSet attrs) {
- super(context, attrs);
- // TODO Auto-generated constructor stub
- }
-
- public LessBrokenWebView(Context context, AttributeSet attrs, int defStyle) {
- super(context, attrs, defStyle);
- // TODO Auto-generated constructor stub
- }
-
- @Override
- public boolean onTouchEvent(MotionEvent event) {
-
- if (event.getAction() == MotionEvent.ACTION_DOWN) {
- int temp_ScrollY = getScrollY();
- scrollTo(getScrollX(), getScrollY() + 1);
- scrollTo(getScrollX(), temp_ScrollY);
- }
-
- return super.onTouchEvent(event);
- }
-
-}
diff --git a/src/org/fox/ttrss/util/NoChildFocusScrollView.java b/src/org/fox/ttrss/util/NoChildFocusScrollView.java
deleted file mode 100644
index 3dea82a4..00000000
--- a/src/org/fox/ttrss/util/NoChildFocusScrollView.java
+++ /dev/null
@@ -1,34 +0,0 @@
-package org.fox.ttrss.util;
-
-import android.content.Context;
-import android.util.AttributeSet;
-import android.view.View;
-import android.webkit.WebView;
-import android.widget.ScrollView;
-
-public class NoChildFocusScrollView extends ScrollView {
-
- public NoChildFocusScrollView(Context context) {
- super(context);
- // TODO Auto-generated constructor stub
- }
-
-
- public NoChildFocusScrollView(Context context, AttributeSet attrs) {
- super(context, attrs);
- // TODO Auto-generated constructor stub
- }
-
- public NoChildFocusScrollView(Context context, AttributeSet attrs,
- int defStyle) {
- super(context, attrs, defStyle);
- // TODO Auto-generated constructor stub
- }
-
- @Override
- public void requestChildFocus(View child, View focused) {
- if (focused instanceof WebView )
- return;
- super.requestChildFocus(child, focused);
- }
-}
diff --git a/src/org/fox/ttrss/util/PrefsBackupAgent.java b/src/org/fox/ttrss/util/PrefsBackupAgent.java
deleted file mode 100644
index 2b33615f..00000000
--- a/src/org/fox/ttrss/util/PrefsBackupAgent.java
+++ /dev/null
@@ -1,19 +0,0 @@
-package org.fox.ttrss.util;
-
-import android.app.backup.BackupAgentHelper;
-import android.app.backup.SharedPreferencesBackupHelper;
-
-public class PrefsBackupAgent extends BackupAgentHelper {
- // The name of the SharedPreferences file
- static final String PREFS = "org.fox.ttrss_preferences";
-
- // A key to uniquely identify the set of backup data
- static final String PREFS_BACKUP_KEY = "prefs";
-
- // Allocate a helper and add it to the backup agent
- @Override
- public void onCreate() {
- SharedPreferencesBackupHelper helper = new SharedPreferencesBackupHelper(this, PREFS);
- addHelper(PREFS_BACKUP_KEY, helper);
- }
-}
diff --git a/src/org/fox/ttrss/util/SimpleLoginManager.java b/src/org/fox/ttrss/util/SimpleLoginManager.java
deleted file mode 100644
index 072c0062..00000000
--- a/src/org/fox/ttrss/util/SimpleLoginManager.java
+++ /dev/null
@@ -1,105 +0,0 @@
-package org.fox.ttrss.util;
-
-import java.util.HashMap;
-
-import org.fox.ttrss.ApiRequest;
-
-import android.content.Context;
-import android.util.Log;
-
-import com.google.gson.JsonElement;
-import com.google.gson.JsonObject;
-
-public abstract class SimpleLoginManager {
- private final String TAG = this.getClass().getSimpleName();
-
- protected class LoginRequest extends ApiRequest {
- private int m_requestId;
- protected String m_sessionId;
- protected int m_apiLevel;
- protected Context m_context;
-
- public LoginRequest(Context context, int requestId) {
- super(context);
- m_context = context;
- m_requestId = requestId;
- }
-
- protected void onPostExecute(JsonElement result) {
- Log.d(TAG, "onPostExecute");
-
- if (result != null) {
- try {
- JsonObject content = result.getAsJsonObject();
- if (content != null) {
- m_sessionId = content.get("session_id").getAsString();
-
- Log.d(TAG, "[SLM] Authenticated!");
-
- ApiRequest req = new ApiRequest(m_context) {
- protected void onPostExecute(JsonElement result) {
- m_apiLevel = 0;
-
- if (result != null) {
- try {
- m_apiLevel = result.getAsJsonObject()
- .get("level").getAsInt();
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
-
- Log.d(TAG, "[SLM] Received API level: " + m_apiLevel);
-
- onLoginSuccess(m_requestId, m_sessionId, m_apiLevel);
- }
- };
-
- @SuppressWarnings("serial")
- HashMap<String, String> map = new HashMap<String, String>() {
- {
- put("sid", m_sessionId);
- put("op", "getApiLevel");
- }
- };
-
- req.execute(map);
-
- return;
- }
-
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
-
- m_sessionId = null;
-
- onLoginFailed(m_requestId, this);
- }
-
- }
-
- public void logIn(Context context, int requestId, final String login, final String password) {
- LoginRequest ar = new LoginRequest(context, requestId);
-
- HashMap<String, String> map = new HashMap<String, String>() {
- {
- put("op", "login");
- put("user", login.trim());
- put("password", password.trim());
- }
- };
-
- onLoggingIn(requestId);
-
- ar.execute(map);
- }
-
- protected abstract void onLoggingIn(int requestId);
-
- protected abstract void onLoginSuccess(int requestId, String sessionId, int apiLevel);
-
- protected abstract void onLoginFailed(int requestId, ApiRequest ar);
-
-}
diff --git a/src/org/fox/ttrss/util/TitleWebView.java b/src/org/fox/ttrss/util/TitleWebView.java
deleted file mode 100644
index 4d97918e..00000000
--- a/src/org/fox/ttrss/util/TitleWebView.java
+++ /dev/null
@@ -1,91 +0,0 @@
-package org.fox.ttrss.util;
-
-// http://www.techques.com/question/1-9718245/Webview-in-Scrollview
-
-import android.content.Context;
-import android.graphics.Canvas;
-import android.util.AttributeSet;
-import android.view.MotionEvent;
-import android.view.View;
-import android.webkit.WebView;
-
-public class TitleWebView extends WebView{
-
- public TitleWebView(Context context, AttributeSet attrs){
- super(context, attrs);
- }
-
- private int titleHeight;
-
- @Override
- protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec){
- super.onMeasure(widthMeasureSpec, heightMeasureSpec);
- // determine height of title bar
- View title = getChildAt(0);
- titleHeight = title==null ? 0 : title.getMeasuredHeight();
- }
-
- @Override
- public boolean onInterceptTouchEvent(MotionEvent ev){
- return true; // don't pass our touch events to children (title bar), we send these in dispatchTouchEvent
- }
-
- private boolean touchInTitleBar;
- @Override
- public boolean dispatchTouchEvent(MotionEvent me){
-
- boolean wasInTitle = false;
- switch(me.getActionMasked()){
- case MotionEvent.ACTION_DOWN:
- touchInTitleBar = (me.getY() <= visibleTitleHeight());
- break;
-
- case MotionEvent.ACTION_UP:
- case MotionEvent.ACTION_CANCEL:
- wasInTitle = touchInTitleBar;
- touchInTitleBar = false;
- break;
- }
- if(touchInTitleBar || wasInTitle) {
- View title = getChildAt(0);
- if(title!=null) {
- // this touch belongs to title bar, dispatch it here
- me.offsetLocation(0, getScrollY());
- return title.dispatchTouchEvent(me);
- }
- }
- // this is our touch, offset and process
- me.offsetLocation(0, -titleHeight);
- return super.dispatchTouchEvent(me);
- }
-
- /**
- * @return visible height of title (may return negative values)
- */
- private int visibleTitleHeight(){
- return titleHeight-getScrollY();
- }
-
- @Override
- protected void onScrollChanged(int l, int t, int oldl, int oldt){
- super.onScrollChanged(l, t, oldl, oldt);
- View title = getChildAt(0);
- if(title!=null) // undo horizontal scroll, so that title scrolls only vertically
- title.offsetLeftAndRight(l - title.getLeft());
- }
-
- @Override
- protected void onDraw(Canvas c){
-
- c.save();
- int tH = visibleTitleHeight();
- if(tH>0) {
- // clip so that it doesn't clear background under title bar
- int sx = getScrollX(), sy = getScrollY();
- c.clipRect(sx, sy+tH, sx+getWidth(), sy+getHeight());
- }
- c.translate(0, titleHeight);
- super.onDraw(c);
- c.restore();
- }
- }
diff --git a/src/org/fox/ttrss/util/TypefaceCache.java b/src/org/fox/ttrss/util/TypefaceCache.java
deleted file mode 100644
index 150d3d83..00000000
--- a/src/org/fox/ttrss/util/TypefaceCache.java
+++ /dev/null
@@ -1,29 +0,0 @@
-package org.fox.ttrss.util;
-
-import java.util.Hashtable;
-
-import android.content.Context;
-import android.graphics.Typeface;
-import android.util.Log;
-
-public class TypefaceCache {
- private static final String TAG = "TypefaceCache";
- private static final Hashtable<String, Typeface> cache = new Hashtable<String, Typeface>();
-
- public static Typeface get(Context c, String typefaceName, int style) {
- synchronized (cache) {
- String key = typefaceName + ":" + style;
-
- if (!cache.containsKey(key)) {
- try {
- Typeface t = Typeface.create(typefaceName, style);
- cache.put(key, t);
- } catch (Exception e) {
- Log.e(TAG, "Could not get typeface '" + typefaceName + "' because " + e.getMessage());
- return null;
- }
- }
- return cache.get(key);
- }
- }
-} \ No newline at end of file