From 7709a717536bca49bf17c3031d265f530f512912 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Wed, 22 May 2013 13:14:02 +0400 Subject: fix dashclock widget class filename update icon, add svg icon source, minor dashclock-related tweaks --- src/org/fox/ttrss/DashClock.java | 126 +++++++++++++++++++++++++++++++++++++++ src/org/fox/ttrss/Dashclock.java | 126 --------------------------------------- 2 files changed, 126 insertions(+), 126 deletions(-) create mode 100644 src/org/fox/ttrss/DashClock.java delete mode 100644 src/org/fox/ttrss/Dashclock.java (limited to 'src') diff --git a/src/org/fox/ttrss/DashClock.java b/src/org/fox/ttrss/DashClock.java new file mode 100644 index 00000000..26c1ecbb --- /dev/null +++ b/src/org/fox/ttrss/DashClock.java @@ -0,0 +1,126 @@ +package org.fox.ttrss; + +import java.util.HashMap; + +import android.content.Context; +import android.content.Intent; +import android.content.SharedPreferences; +import android.preference.PreferenceManager; +import android.util.Log; + +import com.google.android.apps.dashclock.api.DashClockExtension; +import com.google.android.apps.dashclock.api.ExtensionData; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; + +public class DashClock extends DashClockExtension { + + private final String TAG = this.getClass().getSimpleName(); + + protected SharedPreferences m_prefs; + + @Override + protected void onInitialize(boolean isReconnect) { + super.onInitialize(isReconnect); + setUpdateWhenScreenOn(true); + + m_prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); + } + + @Override + protected void onUpdateData(int reason) { + + UnreadRequest req = new UnreadRequest(getApplicationContext()); + + @SuppressWarnings("serial") + HashMap map = new HashMap() { + { + put("op", "login"); + put("user", m_prefs.getString("login", "").trim()); + put("password", m_prefs.getString("password", "").trim()); + } + }; + + req.execute(map); + } + + protected class UnreadRequest extends ApiRequest { + private String m_sessionId; + + private int m_unreadCount; + + public UnreadRequest(Context context) { + super(context); + } + + @SuppressWarnings("unchecked") + protected void onPostExecute(JsonElement result) { + if (result != null) { + try { + JsonObject content = result.getAsJsonObject(); + if (content != null) { + m_sessionId = content.get("session_id").getAsString(); + + Log.d(TAG, "Authenticated!"); + + ApiRequest req = new ApiRequest(m_context) { + protected void onPostExecute(JsonElement result) { + m_unreadCount = 0; + + if (result != null) { + try { + JsonElement unreadCount = result.getAsJsonObject().get("unread"); + + if (unreadCount != null) { + m_unreadCount = unreadCount.getAsInt(); + } else { + m_unreadCount = -1; + } + + ExtensionData updatedData = null; // when null DashClock hides the widget + if (m_unreadCount > 0) { + updatedData = new ExtensionData(); + updatedData.visible(true); + + updatedData.icon(R.drawable.dashclock); + updatedData.status(String.valueOf(m_unreadCount)); + + updatedData.expandedTitle(m_unreadCount + " unread articles"); + //updatedData.expandedBody(getString(R.string.app_name)); + + updatedData.clickIntent(new Intent().setClassName("org.fox.ttrss", + "org.fox.ttrss.OnlineActivity")); + } + publishUpdate(updatedData); + + } catch (Exception e) { + e.printStackTrace(); + } + } + + //Log.d(TAG, "unread count is: " + m_unreadCount); + } + }; + + @SuppressWarnings("serial") + HashMap map = new HashMap() { + { + put("sid", m_sessionId); + put("op", "getUnread"); + } + }; + + req.execute(map); + + return; + } + + } catch (Exception e) { + e.printStackTrace(); + } + } + + m_sessionId = null; + } + } +} diff --git a/src/org/fox/ttrss/Dashclock.java b/src/org/fox/ttrss/Dashclock.java deleted file mode 100644 index 041a45bd..00000000 --- a/src/org/fox/ttrss/Dashclock.java +++ /dev/null @@ -1,126 +0,0 @@ -package org.fox.ttrss; - -import java.util.HashMap; - -import android.content.Context; -import android.content.Intent; -import android.content.SharedPreferences; -import android.preference.PreferenceManager; -import android.util.Log; - -import com.google.android.apps.dashclock.api.DashClockExtension; -import com.google.android.apps.dashclock.api.ExtensionData; -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; - -public class DashClock extends DashClockExtension { - - private static final String TAG = "TTRSS-DC"; - - protected SharedPreferences m_prefs; - - @Override - protected void onInitialize(boolean isReconnect) { - super.onInitialize(isReconnect); - setUpdateWhenScreenOn(true); - - m_prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); - } - - @Override - protected void onUpdateData(int reason) { - - UnreadRequest req = new UnreadRequest(getApplicationContext()); - - @SuppressWarnings("serial") - HashMap map = new HashMap() { - { - put("op", "login"); - put("user", m_prefs.getString("login", "").trim()); - put("password", m_prefs.getString("password", "").trim()); - } - }; - - req.execute(map); - } - - protected class UnreadRequest extends ApiRequest { - private String m_sessionId; - - private int m_unreadCount; - - public UnreadRequest(Context context) { - super(context); - } - - @SuppressWarnings("unchecked") - protected void onPostExecute(JsonElement result) { - if (result != null) { - try { - JsonObject content = result.getAsJsonObject(); - if (content != null) { - m_sessionId = content.get("session_id").getAsString(); - - Log.d(TAG, "Authenticated!"); - - ApiRequest req = new ApiRequest(m_context) { - protected void onPostExecute(JsonElement result) { - m_unreadCount = 0; - - if (result != null) { - try { - JsonElement unreadCount = result.getAsJsonObject().get("unread"); - - if (unreadCount != null) { - m_unreadCount = unreadCount.getAsInt(); - } else { - m_unreadCount = -1; - } - - ExtensionData updatedData = null; // when null DashClock hides the widget - if (m_unreadCount > 0) { - updatedData = new ExtensionData(); - updatedData.visible(true); - - updatedData.icon(R.drawable.dashclock); - updatedData.status(String.valueOf(m_unreadCount)); - - updatedData.expandedTitle(m_unreadCount + " unread articles"); - updatedData.expandedBody(getString(R.string.app_name)); - - updatedData.clickIntent(new Intent().setClassName("org.fox.ttrss", - "org.fox.ttrss.OnlineActivity")); - } - publishUpdate(updatedData); - - } catch (Exception e) { - e.printStackTrace(); - } - } - - Log.d(TAG, "unread count is: " + m_unreadCount); - } - }; - - @SuppressWarnings("serial") - HashMap map = new HashMap() { - { - put("sid", m_sessionId); - put("op", "getUnread"); - } - }; - - req.execute(map); - - return; - } - - } catch (Exception e) { - e.printStackTrace(); - } - } - - m_sessionId = null; - } - } -} -- cgit v1.2.3