Update to 0.5.2

This commit is contained in:
David-Development 2013-11-02 00:13:16 +01:00
parent 663d4ea60f
commit b809eb0d30
7 changed files with 168 additions and 93 deletions

View file

@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="de.luhmer.owncloudnewsreader"
android:versionCode="36"
android:versionName="0.5.1" >
android:versionCode="37"
android:versionName="0.5.2" >
<uses-sdk
android:minSdkVersion="7"

Binary file not shown.

View file

@ -49,24 +49,26 @@ How to compile the App
==================================
Requirements:
-----------------------
>1) Eclipse + ADT Plugin + Android SDK installed
>1) Eclipse + ADT Plugin + Android SDK installed or Android Studio
>2) Git installed (you can do the following stuff without git but I'm not going to show how).
Download and install:
-----------------------
>1) Open cmd/terminal
>1) Open cmd/terminal
>2) Navigate to your workspace
>3) Then type in:
>3) Then type in:
><pre>
git clone https://github.com/JakeWharton/ActionBarSherlock.git
git clone https://github.com/David-Development/Android-PullToRefresh.git
git clone https://github.com/owncloud/News-Android-App.git
git clone https://github.com/gabrielemariotti/changeloglib.git
git clone https://github.com/MichaelFlisar/MessageBar.git
></pre>
>Go to Eclipse and do the following:
>--> File --> Import --> Android Project from Exsisting Source --> [...]/ActionBarSherlock/actionbarsherlock
>--> File --> Import --> Android Project from Exsisting Source --> [...]/Android-PullToRefresh/library
>--> File --> Import --> Android Project from Exsisting Source --> [...]/News-Android-App
... for all other Dependencies the same ...
>Then make a right click on the News-Android-App Project and select "Properties". Select the tab "Android". In this Window you should see the Project Build Target at the top and Libarys at the buttom of the window. Two of them are maybe marked with a read cross. So remove them and add the ActionBarSherlock and the Android PullToRefresh Libary
@ -87,6 +89,7 @@ Updates
---------------------
- Improvement - Notification when background sync is enabled and new items are received
- Improvement - Fix high CPU-Load in Detail-View
- Improvement - Speed up image caching
0.5.0 (Google Play)
---------------------

View file

@ -53,11 +53,11 @@ public class GetImageAsyncTask extends AsyncTask<Void, Void, String>
{
//private static final String TAG = "GetImageAsyncTask";
private static int count = 0;
//private static int count = 0;
private URL WEB_URL_TO_FILE;
private ImageDownloadFinished imageDownloadFinished;
private int AsynkTaskId;
private int AsyncTaskId;
private String rootPath;
private Context cont;
@ -66,7 +66,7 @@ public class GetImageAsyncTask extends AsyncTask<Void, Void, String>
public String feedID = null;
public boolean scaleImage = false;
public int dstHeight; // height in pixels
public int dstWidth; // width in pixels
public int dstWidth; // width in pixels
//private ImageView imgView;
//private WeakReference<ImageView> imageViewReference;
@ -83,7 +83,7 @@ public class GetImageAsyncTask extends AsyncTask<Void, Void, String>
this.lruCache = lruCache;
this.cont = cont;
imageDownloadFinished = imgDownloadFinished;
this.AsynkTaskId = AsynkTaskId;
this.AsyncTaskId = AsynkTaskId;
this.rootPath = rootPath;
//this.imageViewReference = new WeakReference<ImageView>(imageView);
}
@ -91,7 +91,7 @@ public class GetImageAsyncTask extends AsyncTask<Void, Void, String>
@Override
protected void onPostExecute(String result) {
if(imageDownloadFinished != null)
imageDownloadFinished.DownloadFinished(AsynkTaskId, result, lruCache);
imageDownloadFinished.DownloadFinished(AsyncTaskId, result, lruCache);
//imgView.setImageDrawable(GetFavIconFromCache(WEB_URL_TO_FILE.toString(), context));
super.onPostExecute(result);
}
@ -102,12 +102,12 @@ public class GetImageAsyncTask extends AsyncTask<Void, Void, String>
protected String doInBackground(Void... params) {
try
{
File cacheFile = ImageHandler.getFullPathOfCacheFile(WEB_URL_TO_FILE.toString(), rootPath);
File cacheFile = ImageHandler.getFullPathOfCacheFile(WEB_URL_TO_FILE.toString(), rootPath);
if(!cacheFile.isFile())
{
File dir = new File(rootPath);
dir.mkdirs();
cacheFile = ImageHandler.getFullPathOfCacheFile(WEB_URL_TO_FILE.toString(), rootPath);
cacheFile = ImageHandler.getFullPathOfCacheFile(WEB_URL_TO_FILE.toString(), rootPath);
//cacheFile.createNewFile();
@ -161,6 +161,7 @@ public class GetImageAsyncTask extends AsyncTask<Void, Void, String>
fOut.close();
*/
/*
count++;
if(count >= 25)//Check every 25 images the cache size
{
@ -188,7 +189,7 @@ public class GetImageAsyncTask extends AsyncTask<Void, Void, String>
break;
}
}
}
} */
}
return cacheFile.getPath();
}
@ -200,33 +201,5 @@ public class GetImageAsyncTask extends AsyncTask<Void, Void, String>
}
@SuppressWarnings({ "rawtypes", "unchecked" })
public static LinkedHashMap sortHashMapByValuesD(HashMap passedMap) {
List mapKeys = new ArrayList(passedMap.keySet());
List mapValues = new ArrayList(passedMap.values());
Collections.sort(mapValues);
Collections.sort(mapKeys);
LinkedHashMap sortedMap = new LinkedHashMap();
Iterator valueIt = mapValues.iterator();
while (valueIt.hasNext()) {
Object val = valueIt.next();
Iterator keyIt = mapKeys.iterator();
while (keyIt.hasNext()) {
Object key = keyIt.next();
String comp1 = passedMap.get(key).toString();
String comp2 = val.toString();
if (comp1.equals(comp2)){
passedMap.remove(key);
mapKeys.remove(key);
sortedMap.put((String)key, (Double)val);
break;
}
}
}
return sortedMap;
}
}

View file

@ -21,7 +21,12 @@
package de.luhmer.owncloudnewsreader.services;
import java.io.File;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Random;
@ -31,10 +36,13 @@ import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.database.Cursor;
import android.preference.PreferenceManager;
import android.support.v4.app.NotificationCompat;
import de.luhmer.owncloudnewsreader.NewsReaderListActivity;
import de.luhmer.owncloudnewsreader.R;
import de.luhmer.owncloudnewsreader.SettingsActivity;
import de.luhmer.owncloudnewsreader.async_tasks.GetImageAsyncTask;
import de.luhmer.owncloudnewsreader.database.DatabaseConnection;
import de.luhmer.owncloudnewsreader.helper.BitmapDrawableLruCache;
@ -51,10 +59,10 @@ public class DownloadImagesService extends IntentService {
private NotificationCompat.Builder NotificationDownloadImages;
private int count;
private int maxCount;
//private int total_size = 0;
public DownloadImagesService() {
super(null);
super(null);
initService();
}
@ -128,17 +136,83 @@ public class DownloadImagesService extends IntentService {
notify.flags |= Notification.FLAG_AUTO_CANCEL;
//notify.flags |= Notification.FLAG_NO_CLEAR;
if(maxCount > 0)
if(maxCount > 0)
notificationManager.notify(NOTIFICATION_ID, notify);
for(String link : links)
for(String link : links)
new GetImageAsyncTask(link, imgDownloadFinished, 999, ImageHandler.getPathImageCache(this), this, null).execute();
}
private void RemoveOldImages(Context context) {
HashMap<File, Long> files;
long size = ImageHandler.getFolderSize(new File(ImageHandler.getPath(context)));
size = (long) (size / 1024d / 1024d);
SharedPreferences mPrefs = PreferenceManager.getDefaultSharedPreferences(context);
int max_allowed_size = Integer.parseInt(mPrefs.getString(SettingsActivity.SP_MAX_CACHE_SIZE, "1000"));//Default is 1Gb --> 1000mb
if(size > max_allowed_size)
{
files = new HashMap<File, Long>();
for(File file : ImageHandler.getFilesFromDir(new File(ImageHandler.getPathImageCache(context))))
{
files.put(file, file.lastModified());
}
for(Object itemObj : sortHashMapByValuesD(files).entrySet())
{
File file = (File) itemObj;
file.delete();
size -= file.length();
if(size < max_allowed_size)
break;
}
}
}
@SuppressWarnings({ "rawtypes", "unchecked" })
public static LinkedHashMap sortHashMapByValuesD(HashMap passedMap) {
List mapKeys = new ArrayList(passedMap.keySet());
List mapValues = new ArrayList(passedMap.values());
Collections.sort(mapValues);
Collections.sort(mapKeys);
LinkedHashMap sortedMap = new LinkedHashMap();
Iterator valueIt = mapValues.iterator();
while (valueIt.hasNext()) {
Object val = valueIt.next();
Iterator keyIt = mapKeys.iterator();
while (keyIt.hasNext()) {
Object key = keyIt.next();
String comp1 = passedMap.get(key).toString();
String comp2 = val.toString();
if (comp1.equals(comp2)){
passedMap.remove(key);
mapKeys.remove(key);
sortedMap.put((String)key, (Double)val);
break;
}
}
}
return sortedMap;
}
ImageDownloadFinished imgDownloadFinished = new ImageDownloadFinished() {
@Override
public void DownloadFinished(int AsynkTaskId, String fileCachePath, BitmapDrawableLruCache lruCache) {
if(fileCachePath != null) {
File file = new File(fileCachePath);
long size = file.length();
//total_size += size;
if(size == 0)
file.delete();
}
count++;
// Sets the progress indicator to a max value, the
// current completion percentage, and "determinate"
@ -148,8 +222,11 @@ public class DownloadImagesService extends IntentService {
// Displays the progress bar for the first time.
notificationManager.notify(NOTIFICATION_ID, NotificationDownloadImages.build());
if(maxCount == count)
if(maxCount == count) {
notificationManager.cancel(NOTIFICATION_ID);
if(DownloadImagesService.this != null)
RemoveOldImages(DownloadImagesService.this);
}
}
};
}

View file

@ -26,6 +26,7 @@ import java.util.List;
import android.app.ActivityManager;
import android.app.Service;
import android.appwidget.AppWidgetManager;
import android.content.ComponentName;
import android.content.Intent;
import android.content.SharedPreferences;
@ -46,6 +47,7 @@ import de.luhmer.owncloudnewsreader.reader.OnAsyncTaskCompletedListener;
import de.luhmer.owncloudnewsreader.reader.owncloud.API;
import de.luhmer.owncloudnewsreader.reader.owncloud.OwnCloud_Reader;
import de.luhmer.owncloudnewsreader.services.IOwnCloudSyncService.Stub;
import de.luhmer.owncloudnewsreader.widget.WidgetProvider;
public class OwnCloudSyncService extends Service {
@ -188,19 +190,20 @@ public class OwnCloudSyncService extends Service {
ThrowException((Exception) task_result);
else
{
ActivityManager am = (ActivityManager) getSystemService(ACTIVITY_SERVICE);
List<ActivityManager.RunningTaskInfo> runningTaskInfo = am.getRunningTasks(1);
SharedPreferences mPrefs = PreferenceManager.getDefaultSharedPreferences(OwnCloudSyncService.this);
int newItemsCount = mPrefs.getInt(Constants.LAST_UPDATE_NEW_ITEMS_COUNT_STRING, 0);
if(newItemsCount > 0) {
ActivityManager am = (ActivityManager) getSystemService(ACTIVITY_SERVICE);
List<ActivityManager.RunningTaskInfo> runningTaskInfo = am.getRunningTasks(1);
ComponentName componentInfo = runningTaskInfo.get(0).topActivity;
if(!componentInfo.getPackageName().equals("de.luhmer.owncloudnewsreader")) {
SharedPreferences mPrefs = PreferenceManager.getDefaultSharedPreferences(OwnCloudSyncService.this);
int newItemsCount = mPrefs.getInt(Constants.LAST_UPDATE_NEW_ITEMS_COUNT_STRING, 0);
if(newItemsCount > 0) {
ComponentName componentInfo = runningTaskInfo.get(0).topActivity;
if(!componentInfo.getPackageName().equals("de.luhmer.owncloudnewsreader")) {
String tickerText = getString(R.string.notification_new_items_ticker).replace("X", String.valueOf(newItemsCount));
String contentText = getString(R.string.notification_new_items_text).replace("X", String.valueOf(newItemsCount));
String title = getString(R.string.app_name);
NotificationManagerNewsReader.getInstance(OwnCloudSyncService.this).ShowMessage(title, tickerText, contentText);
}
UpdateWidget();
}
}
@ -209,7 +212,20 @@ public class OwnCloudSyncService extends Service {
}
};
private void UpdateWidget()
{
Intent intent = new Intent(this, WidgetProvider.class);
intent.setAction("android.appwidget.action.APPWIDGET_UPDATE");
// Use an array and EXTRA_APPWIDGET_IDS instead of AppWidgetManager.EXTRA_APPWIDGET_ID,
// since it seems the onUpdate() is only fired on that:
int ids[] = AppWidgetManager.getInstance(getApplication()).getAppWidgetIds(new ComponentName(getApplication(), WidgetProvider.class));
intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS,ids);
intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID,ids);
sendBroadcast(intent);
}
private void ThrowException(Exception ex) {
List<IOwnCloudSyncServiceCallback> callbackList = getCallBackItemsAndBeginBroadcast();
for (IOwnCloudSyncServiceCallback icb : callbackList) {

View file

@ -51,47 +51,53 @@ public class WidgetProvider extends AppWidgetProvider {
@Override
public void onReceive(Context context, Intent intent) {
final int appWidgetId;
if(intent.hasExtra(AppWidgetManager.EXTRA_APPWIDGET_ID))
appWidgetId = intent.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID);
final int appWidgetId[];
if(intent.hasExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS))
appWidgetId = intent.getIntArrayExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS);
else if(intent.hasExtra(AppWidgetManager.EXTRA_APPWIDGET_ID))
appWidgetId = new int[] { intent.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID) };
else
appWidgetId = AppWidgetManager.INVALID_APPWIDGET_ID;
appWidgetId = new int[] { AppWidgetManager.INVALID_APPWIDGET_ID };
if(Constants.debugModeWidget)
Log.d(TAG, "onRecieve - WidgetID: " + appWidgetId);
String action = intent.getAction();
if (AppWidgetManager.ACTION_APPWIDGET_DELETED.equals(action)) {
if (appWidgetId != AppWidgetManager.INVALID_APPWIDGET_ID) {
this.onDeleted(context, new int[] { appWidgetId });
}
} else if (intent.getAction().equals(ACTION_WIDGET_RECEIVER)) {
Intent intentRefresh = new Intent(context, WidgetProvider.class);
intentRefresh.setAction("android.appwidget.action.APPWIDGET_UPDATE");
// Use an array and EXTRA_APPWIDGET_IDS instead of AppWidgetManager.EXTRA_APPWIDGET_ID,
// since it seems the onUpdate() is only fired on that:
intentRefresh.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS,new int[] { appWidgetId });
context.sendBroadcast(intentRefresh);
} else if (intent.getAction().equals(ACTION_LIST_CLICK)) {
try
{
String uid = intent.getExtras().getString(UID_TODO);
//Intent intentToDoListAct = new Intent(context, TodoListActivity.class);
Intent intentToDoListAct = new Intent(context, NewsReaderListActivity.class);
intentToDoListAct.putExtra(UID_TODO, uid);
intentToDoListAct.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intentToDoListAct);
if(Constants.debugModeWidget)
Log.d(TAG, "ListItem Clicked Starting Activity for Item: " + uid);
}
catch(Exception ex)
{
ex.printStackTrace();
}
}
String action = intent.getAction();
for(int i = 0; i < appWidgetId.length; i++) {
if (AppWidgetManager.ACTION_APPWIDGET_DELETED.equals(action)) {
if (appWidgetId[i] != AppWidgetManager.INVALID_APPWIDGET_ID) {
this.onDeleted(context, new int[] { appWidgetId[i] });
}
} /*else if (intent.getAction().equals(ACTION_WIDGET_RECEIVER)) {
Intent intentRefresh = new Intent(context, WidgetProvider.class);
intentRefresh.setAction("android.appwidget.action.APPWIDGET_UPDATE");
// Use an array and EXTRA_APPWIDGET_IDS instead of AppWidgetManager.EXTRA_APPWIDGET_ID,
// since it seems the onUpdate() is only fired on that:
intentRefresh.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, new int[] { appWidgetId[i] });
context.sendBroadcast(intentRefresh);
} */else if (action.equals(ACTION_LIST_CLICK)) {
try
{
String uid = intent.getExtras().getString(UID_TODO);
//Intent intentToDoListAct = new Intent(context, TodoListActivity.class);
Intent intentToDoListAct = new Intent(context, NewsReaderListActivity.class);
intentToDoListAct.putExtra(UID_TODO, uid);
intentToDoListAct.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intentToDoListAct);
if(Constants.debugModeWidget)
Log.d(TAG, "ListItem Clicked Starting Activity for Item: " + uid);
}
catch(Exception ex)
{
ex.printStackTrace();
}
} /*else if(action.equals("android.appwidget.action.APPWIDGET_UPDATE") || action.equals(ACTION_WIDGET_RECEIVER)) {
onUpdate(context, AppWidgetManager.getInstance(context), new int[] { appWidgetId[i] });
}*/
}
super.onReceive(context, intent);
}
@ -150,7 +156,7 @@ public class WidgetProvider extends AppWidgetProvider {
Intent intent = new Intent(context, WidgetService.class);
intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
rv.setRemoteAdapter(appWidgetId, R.id.list_view, intent);
rv.setRemoteAdapter(appWidgetId, R.id.list_view, intent);
Intent onListClickIntent = new Intent(context, WidgetProvider.class);