Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

On touch refresh fixed

  • Loading branch information...
commit 87f22f3ef9b761a4268661b176db71817a28c212 1 parent 6b29d70
Carles Sentis authored
View
10 AndroidManifest.xml
@@ -1,7 +1,8 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.codeskraps.lolo"
- android:versionCode="8"
- android:versionName="1.7" >
+ android:versionCode="9"
+ android:versionName="1.8" >
+
<!-- Remember to update the info code version -->
<uses-sdk
@@ -39,6 +40,11 @@
android:name="android.appwidget.provider"
android:resource="@xml/loloinfo" />
</receiver>
+ <receiver android:name=".UpdateWidgetReceiver" >
+ <intent-filter>
+ <action android:name="com.codeskraps.lolo.BROADCAST_RECEIVER" />
+ </intent-filter>
+ </receiver>
<service android:name=".UpdateWidgetService" />
</application>
View
9 README.rdoc
@@ -4,7 +4,7 @@
* <b>Git:</b> https://github.com/091labs/lo-lo
* <b>Author:</b> 091 Labs members
* <b>License:</b> GNU GPL v3
-* <b>Latest Version:</b> 1.7
+* <b>Latest Version:</b> 1.8
* <b>Release Date:</b> 2012
== General Infromation
@@ -32,9 +32,12 @@ Install from Google Play
== ChangeLog
+<b>v1.8</b>
+* Added - Custom interval update
+
<b>v1.7</b>
-* Fix bug - Widget views not updating from pedingIntent
-* Fix bug - Connection time out view update
+* Bug fixed - Widget views not updating from pedingIntent
+* Bug fixed - Connection time out view update
<b>v1.6</b>
* Bug fixed - onSharedPreferenceChanged not fired
View
23 res/values/strings.xml
@@ -7,11 +7,14 @@
<!-- Preference Activity -->
<string name="prefsCat_General">General</string>
+
<string name="prefsSync_title">Show last sync time</string>
<string name="prefsSync_summarNot">Not yet synced!</string>
+
<string name="prefs24_title">Use 24-hour format</string>
<string name="prefs24_summaryOne">01:00 pm</string>
<string name="prefs24_summaryTwo">13:00</string>
+
<string name="prefsOnClick_title">On touch action</string>
<string name="prefsOnClick_dialogTitle">On touch action</string>
<string name="prefsOnClick_summary">Choose what should be done when you touch the widget -</string>
@@ -32,8 +35,26 @@
<string name="prefsURL_title">URL</string>
<string name="prefsURL_summary">Set a Custom URL -</string>
<string name="prefsURL_default">091labs.com</string>
+
+ <string name="prefsInterval_title">Interval update</string>
+ <string name="prefsInterval_dialogTitle">Interval update</string>
+
+ <string-array name="interval_entries">
+ <item>5 minutes</item>
+ <item>15 minutes</item>
+ <item>Half hour</item>
+ <item>An hour</item>
+ </string-array>
+ <string-array name="interval_values">
+ <item>0</item>
+ <item>1</item>
+ <item>2</item>
+ <item>3</item>
+ </string-array>
+
<string name="prefsCat_Info">Information</string>
- <string name="prefsInfo_Title">091 Labs lo-lo v1.7</string>
+
+ <string name="prefsInfo_Title">091 Labs lo-lo v1.8</string>
<string name="prefsInfo_summary">GNU GPL License v3 - 2012</string>
<!-- About -->
View
4 res/xml/loloinfo.xml
@@ -3,6 +3,8 @@
android:initialLayout="@layout/widget"
android:minHeight="72dip"
android:minWidth="72dip"
- android:updatePeriodMillis="180000"
android:configure="com.codeskraps.lolo.PrefsActivity"
android:previewImage="@drawable/open" />
+
+<!-- android:updatePeriodMillis="180000" -->
+
View
9 res/xml/preferences.xml
@@ -6,6 +6,7 @@
android:defaultValue="true"
android:key="chkSync"
android:title="@string/prefsSync_title" />
+
<CheckBoxPreference
android:defaultValue="true"
android:key="chk24"
@@ -23,6 +24,14 @@
android:defaultValue="@string/prefsURL_default"
android:key="eURL"
android:title="@string/prefsURL_title" />
+
+ <ListPreference
+ android:defaultValue="15"
+ android:dialogTitle="@string/prefsInterval_dialogTitle"
+ android:entries="@array/interval_entries"
+ android:entryValues="@array/interval_values"
+ android:key="lstInterval"
+ android:title="@string/prefsInterval_title" />
</PreferenceCategory>
<PreferenceCategory android:title="@string/prefsCat_Info" >
<Preference
View
17 src/com/codeskraps/lolo/Constants.java
@@ -0,0 +1,17 @@
+package com.codeskraps.lolo;
+
+public class Constants {
+
+ public static final String FORCE_WIDGET_UPDATE = "com.codeskraps.lolo.FORCE_WIDGET_UPDATE";
+ public static final String BROADCAST_RECEIVER = "com.codeskraps.lolo.BROADCAST_RECEIVER";
+ public static final String CONFIGURE_ACTION = "android.appwidget.action.APPWIDGET_CONFIGURE";
+
+ public static final String ONCLICK = "lstOnClick";
+ public static final String EURL = "eURL";
+ public static final String LAST_SYNC = "sync";
+ public static final String SHOW_SYNC = "chkSync";
+ public static final String HOUR24 = "chk24";
+ public static final String INTERVAL = "lstInterval";
+ public static final String ABOUT = "prefAbout";
+ public static final String FIRST_LAUNCH = "firstLaunch";
+}
View
87 src/com/codeskraps/lolo/LoloProvider.java
@@ -21,6 +21,7 @@
package com.codeskraps.lolo;
+import android.app.AlarmManager;
import android.app.PendingIntent;
import android.appwidget.AppWidgetManager;
import android.appwidget.AppWidgetProvider;
@@ -28,93 +29,73 @@
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
-import android.net.Uri;
import android.preference.PreferenceManager;
import android.util.Log;
import android.widget.RemoteViews;
public class LoloProvider extends AppWidgetProvider {
private static final String TAG = LoloProvider.class.getSimpleName();
- public static final String FORCE_WIDGET_UPDATE = "com.codeskraps.lolo.FORCE_WIDGET_UPDATE";
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
- if (BuildConfig.DEBUG == true)
- Log.d(TAG, "onUpdate");
+ if (BuildConfig.DEBUG) Log.d(TAG, "onUpdate");
updateWidget(context);
super.onUpdate(context, appWidgetManager, appWidgetIds);
}
@Override
public void onReceive(Context context, Intent intent) {
- if (BuildConfig.DEBUG == true)
- Log.d(TAG, "onReceive");
-
+ if (BuildConfig.DEBUG) Log.d(TAG, "onReceive");
final String action = intent.getAction();
- if (action.equals(FORCE_WIDGET_UPDATE))
- updateWidget(context);
-
+ Log.d(TAG, "Action: " + action);
+ if (action.equals(Constants.FORCE_WIDGET_UPDATE)) updateWidget(context);
super.onReceive(context, intent);
}
public void updateWidget(Context context) {
- if (BuildConfig.DEBUG == true)
- Log.d(TAG, "updateWidget");
+ if (BuildConfig.DEBUG) Log.d(TAG, "updateWidget");
ComponentName thisWidget = new ComponentName(context, LoloProvider.class);
AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
int[] appWidgetIds = appWidgetManager.getAppWidgetIds(thisWidget);
+
updateWidget(context, appWidgetManager, appWidgetIds);
}
private void updateWidget(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
- if (BuildConfig.DEBUG == true)
- Log.d(TAG, "updateWidget2");
-
- final int N = appWidgetIds.length;
+ if (BuildConfig.DEBUG) Log.d(TAG, "updateWidget2");
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
+ RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.widget);
- Intent serviceIntent = new Intent(context, UpdateWidgetService.class);
+ if (appWidgetIds.length > 0) {
+ for (int appWidgetId : appWidgetIds) {
- Intent intent = null;
- PendingIntent pendingIntent = null;
+ remoteViews.setOnClickPendingIntent(R.id.imgLolo, Utils.getOnTouchIntent(context));
+ appWidgetManager.updateAppWidget(appWidgetId, remoteViews);
+ }
+ }
- int onClick = Integer.parseInt(prefs.getString(PrefsActivity.ONCLICK, "0"));
- RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.widget);
+ Intent broadcastIntent = new Intent();
+ broadcastIntent.setAction(Constants.BROADCAST_RECEIVER);
+ PendingIntent pi = PendingIntent.getBroadcast(context, 0, broadcastIntent, 0);
- for (int i = 0; i < N; i++) {
- int appWidgetId = appWidgetIds[i];
-
- switch (onClick) {
- case 0:
- intent = new Intent("com.codeskraps.lol.DO_NOTHING");
- pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
- break;
-
- case 1:
- pendingIntent = PendingIntent.getService(context, 0, serviceIntent, 0);
- break;
-
- case 2:
- intent = new Intent(context, PrefsActivity.class);
- pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
- break;
-
- case 3:
- intent = new Intent(Intent.ACTION_VIEW);
- String url = prefs.getString(PrefsActivity.EURL,
- context.getString(R.string.prefsURL_default));
- if (!url.startsWith("http://"))
- url = "http://" + url;
- intent.setData(Uri.parse(url));
- pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
- break;
- }
- remoteViews.setOnClickPendingIntent(R.id.imgLolo, pendingIntent);
- appWidgetManager.updateAppWidget(appWidgetId, remoteViews);
+ String intervalString = prefs.getString(Constants.INTERVAL, "1");
+ int intervalEntry = Integer.parseInt(intervalString);
+
+// @formatter:off
+ int interval = 0;
+ switch(intervalEntry){
+ case 0: interval = 5; break;
+ case 1: interval = 15; break;
+ case 2: interval = 30; break;
+ case 3: interval = 60; break;
}
+// @formatter:on
+
+ AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
+ alarmManager.setInexactRepeating(AlarmManager.RTC, System.currentTimeMillis() + 1000 * 60
+ * interval, 1000 * 60 * interval, pi);
- // Update the widgets via the service
- context.startService(serviceIntent);
+ context.sendBroadcast(broadcastIntent);
}
}
View
126 src/com/codeskraps/lolo/PrefsActivity.java
@@ -36,29 +36,23 @@
import android.util.Log;
import android.view.KeyEvent;
-public class PrefsActivity extends PreferenceActivity implements OnSharedPreferenceChangeListener, OnPreferenceClickListener {
+public class PrefsActivity extends PreferenceActivity implements OnSharedPreferenceChangeListener,
+ OnPreferenceClickListener {
private static final String TAG = PrefsActivity.class.getSimpleName();
- private static String CONFIGURE_ACTION = "android.appwidget.action.APPWIDGET_CONFIGURE";
- public static final String FORCE_WIDGET_UPDATE = "com.codeskraps.lolo.FORCE_WIDGET_UPDATE";
- public static final String ONCLICK = "lstOnClick";
- public static final String EURL = "eURL";
- public static final String LAST_SYNC = "sync";
- public static final String SHOW_SYNC = "chkSync";
- public static final String HOUR24 = "chk24";
- public static final String ABOUT = "prefAbout";
- public static final String FIRST_LAUNCH = "firstLaunch";
private SharedPreferences prefs = null;
private ListPreference lstOnClick = null;
private EditTextPreference eURL = null;
private CheckBoxPreference chkSync = null;
private CheckBoxPreference chk24 = null;
+ private ListPreference lstInterval = null;
+
private String[] entries_OnClick = null;
+ private String[] entries_Interval = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
- if (BuildConfig.DEBUG == true)
- Log.d(TAG, "onCreate");
+ if (BuildConfig.DEBUG) Log.d(TAG, "onCreate");
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.preferences);
@@ -68,13 +62,15 @@ protected void onCreate(Bundle savedInstanceState) {
prefs.registerOnSharedPreferenceChangeListener(this);
entries_OnClick = getResources().getStringArray(R.array.OnClick_entries);
+ entries_Interval = getResources().getStringArray(R.array.interval_entries);
+
+ lstOnClick = (ListPreference) findPreference(Constants.ONCLICK);
+ eURL = (EditTextPreference) findPreference(Constants.EURL);
+ chkSync = (CheckBoxPreference) findPreference(Constants.SHOW_SYNC);
+ chk24 = (CheckBoxPreference) findPreference(Constants.HOUR24);
+ lstInterval = (ListPreference) findPreference(Constants.INTERVAL);
+ Preference prefAbout = (Preference) findPreference(Constants.ABOUT);
- lstOnClick = (ListPreference) findPreference(ONCLICK);
- eURL = (EditTextPreference) findPreference(EURL);
- chkSync = (CheckBoxPreference) findPreference(SHOW_SYNC);
- chk24 = (CheckBoxPreference) findPreference(HOUR24);
- Preference prefAbout = (Preference) findPreference(ABOUT);
-
prefAbout.setOnPreferenceClickListener(this);
}
@@ -83,78 +79,76 @@ protected void onResume() {
super.onResume();
prefs.registerOnSharedPreferenceChangeListener(this);
-
- String lstSync = prefs.getString(LAST_SYNC, null);
- if (lstSync == null)
- chkSync.setSummary(getString(R.string.prefsSync_summarNot));
- else
- chkSync.setSummary(lstSync);
-
- boolean hour24 = prefs.getBoolean(HOUR24, true);
- if (hour24)
- chk24.setSummary(getString(R.string.prefs24_summaryTwo));
- else
- chk24.setSummary(getString(R.string.prefs24_summaryOne));
-
- String onClick = prefs.getString(ONCLICK, entries_OnClick[0]);
+
+ String lstSync = prefs.getString(Constants.LAST_SYNC, null);
+ if (lstSync == null) chkSync.setSummary(getString(R.string.prefsSync_summarNot));
+ else chkSync.setSummary(lstSync);
+
+ boolean hour24 = prefs.getBoolean(Constants.HOUR24, true);
+ if (hour24) chk24.setSummary(getString(R.string.prefs24_summaryTwo));
+ else chk24.setSummary(getString(R.string.prefs24_summaryOne));
+
+ String onClick = prefs.getString(Constants.ONCLICK, "0");
int action = Integer.parseInt(onClick);
lstOnClick.setSummary(entries_OnClick[action]);
- String url = prefs.getString(EURL, getString(R.string.prefsURL_default));
+ String url = prefs.getString(Constants.EURL, getString(R.string.prefsURL_default));
String urlSummary = String.format("%s %s", getString(R.string.prefsURL_summary), url);
eURL.setSummary(urlSummary);
- if (action != 3)
- eURL.setEnabled(false);
-
- if (prefs.getBoolean(FIRST_LAUNCH, true)) {
+ String intervalString = prefs.getString(Constants.INTERVAL, "1");
+ int interval = Integer.parseInt(intervalString);
+ lstInterval.setSummary(entries_Interval[interval]);
+
+ if (action != 3) eURL.setEnabled(false);
+
+ if (prefs.getBoolean(Constants.FIRST_LAUNCH, true)) {
startActivity(new Intent(this, AboutActivity.class));
SharedPreferences.Editor editor = prefs.edit();
- editor.putBoolean(FIRST_LAUNCH, false);
+ editor.putBoolean(Constants.FIRST_LAUNCH, false);
editor.commit();
}
}
@Override
protected void onPause() {
- if (BuildConfig.DEBUG == true)
- Log.d(TAG, "onPause");
+ if (BuildConfig.DEBUG) Log.d(TAG, "onPause");
super.onPause();
prefs.unregisterOnSharedPreferenceChangeListener(this);
}
@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
- if (BuildConfig.DEBUG == true)
- Log.d(TAG, "onSharedPreferenceChanged");
-
- if (key.equals(HOUR24)) {
- boolean hour24 = prefs.getBoolean(HOUR24, true);
- if (hour24)
- chk24.setSummary(getString(R.string.prefs24_summaryTwo));
- else
- chk24.setSummary(getString(R.string.prefs24_summaryOne));
-
- } else if (key.equals(ONCLICK)) {
- String onClick = prefs.getString(ONCLICK, entries_OnClick[0]);
+ if (BuildConfig.DEBUG) Log.d(TAG, "onSharedPreferenceChanged");
+
+ if (key.equals(Constants.HOUR24)) {
+ boolean hour24 = prefs.getBoolean(Constants.HOUR24, true);
+ if (hour24) chk24.setSummary(getString(R.string.prefs24_summaryTwo));
+ else chk24.setSummary(getString(R.string.prefs24_summaryOne));
+
+ } else if (key.equals(Constants.ONCLICK)) {
+ String onClick = prefs.getString(Constants.ONCLICK, "0");
int action = Integer.parseInt(onClick);
lstOnClick.setSummary(entries_OnClick[action]);
- if (action != 3)
- eURL.setEnabled(false);
- else
- eURL.setEnabled(true);
- } else if (key.equals(EURL)) {
- String url = prefs.getString(EURL, getString(R.string.prefsURL_default));
+ if (action != 3) eURL.setEnabled(false);
+ else eURL.setEnabled(true);
+
+ } else if (key.equals(Constants.EURL)) {
+ String url = prefs.getString(Constants.EURL, getString(R.string.prefsURL_default));
String urlSummary = String.format("%s %s", getString(R.string.prefsURL_summary), url);
eURL.setSummary(urlSummary);
+
+ } else if (key.equals(Constants.INTERVAL)) {
+ String intervalString = prefs.getString(Constants.INTERVAL, "1");
+ int interval = Integer.parseInt(intervalString);
+ lstInterval.setSummary(entries_Interval[interval]);
}
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
- if (BuildConfig.DEBUG == true)
- Log.d(TAG, "onKeyDown");
+ if (BuildConfig.DEBUG) Log.d(TAG, "onKeyDown");
if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.ECLAIR
&& keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {
@@ -172,18 +166,16 @@ public void onBackPressed() {
// This will be called either automatically for you on 2.0
// or later, or by the code above on earlier versions of the
// platform.
- if (BuildConfig.DEBUG == true)
- Log.d(TAG, "onBackPressed");
+ if (BuildConfig.DEBUG) Log.d(TAG, "onBackPressed");
resultIntent();
finish();
return;
}
private void resultIntent() {
- if (BuildConfig.DEBUG == true)
- Log.d(TAG, "resultIntent");
+ if (BuildConfig.DEBUG) Log.d(TAG, "resultIntent");
- if (CONFIGURE_ACTION.equals(getIntent().getAction())) {
+ if (Constants.CONFIGURE_ACTION.equals(getIntent().getAction())) {
Intent intent = getIntent();
Bundle extras = intent.getExtras();
if (extras != null) {
@@ -195,12 +187,12 @@ private void resultIntent() {
setResult(RESULT_OK, result);
}
}
- sendBroadcast(new Intent(FORCE_WIDGET_UPDATE));
+ sendBroadcast(new Intent(Constants.FORCE_WIDGET_UPDATE));
}
@Override
public boolean onPreferenceClick(Preference pref) {
- if (pref.getKey().equals(ABOUT)) {
+ if (pref.getKey().equals(Constants.ABOUT)) {
startActivity(new Intent(this, AboutActivity.class));
}
return false;
View
176 src/com/codeskraps/lolo/UpdateWidgetReceiver.java
@@ -0,0 +1,176 @@
+package com.codeskraps.lolo;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.HttpURLConnection;
+import java.net.URL;
+import java.text.DateFormat;
+import java.util.Calendar;
+import java.util.List;
+
+import org.xmlpull.v1.XmlPullParserException;
+
+import android.appwidget.AppWidgetManager;
+import android.content.BroadcastReceiver;
+import android.content.ComponentName;
+import android.content.Context;
+import android.content.Intent;
+import android.content.SharedPreferences;
+import android.os.Handler;
+import android.preference.PreferenceManager;
+import android.util.Log;
+import android.view.View;
+import android.widget.RemoteViews;
+
+import com.codeskraps.lolo.RSSXmlParser.Entry;
+
+public class UpdateWidgetReceiver extends BroadcastReceiver {
+ private static final String TAG = UpdateWidgetReceiver.class.getSimpleName();
+
+ private static Context context = null;
+ private static Handler handler;
+ private static boolean lolo;
+ private Thread downloadThread;
+
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ if (BuildConfig.DEBUG) Log.d(TAG, "onStartCommand");
+
+ UpdateWidgetReceiver.context = context;
+
+ handler = new Handler();
+
+ if (Utils.isNetworkAvailable(context)) {
+ ComponentName provider = new ComponentName(context, LoloProvider.class);
+ AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
+ int[] appWidgets = appWidgetManager.getAppWidgetIds(provider);
+
+ if (appWidgets.length > 0) {
+ for (int widgetId : appWidgets) {
+ RemoteViews remoteViews = new RemoteViews(context.getPackageName(),
+ R.layout.widget);
+ remoteViews.setViewVisibility(R.id.prgBar, View.VISIBLE);
+ appWidgetManager.updateAppWidget(widgetId, remoteViews);
+ }
+ } else Log.d(TAG, "No widgets installed");
+
+ downloadThread = new MyThread();
+ downloadThread.start();
+
+ // new DownloadXmlTask().execute();
+ } else Log.d(TAG, "No network connection");
+ }
+
+ static private class MyThread extends Thread {
+ @Override
+ public void run() {
+ try {
+ lolo = Utils.getLolo();
+ } catch (IOException e) {
+ Log.e(TAG, e.getMessage());
+ } finally {
+ handler.post(new MyRunnable());
+ }
+ }
+ }
+
+ static private class MyRunnable implements Runnable {
+ public void run() {
+ SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
+ ComponentName provider = new ComponentName(context, LoloProvider.class);
+ AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
+ RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.widget);
+ int[] appWidgetIds = appWidgetManager.getAppWidgetIds(provider);
+
+ if (appWidgetIds.length > 0) {
+ for (int appWidgetId : appWidgetIds) {
+
+ if (lolo) {
+ remoteViews.setImageViewResource(R.id.imgLolo, R.drawable.open);
+ Log.d(TAG, "The labs is open");
+ } else {
+ remoteViews.setImageViewResource(R.id.imgLolo, R.drawable.closed);
+ Log.d(TAG, "The labs is close");
+ }
+
+ Calendar c = Calendar.getInstance();
+
+ SharedPreferences.Editor editor = prefs.edit();
+ editor.putString(Constants.LAST_SYNC,
+ DateFormat.getDateTimeInstance().format(c.getTime()));
+ editor.commit();
+
+ boolean showSync = prefs.getBoolean(Constants.SHOW_SYNC, true);
+ if (showSync) {
+ boolean hour24 = prefs.getBoolean(Constants.HOUR24, true);
+ String hours = new String();
+ if (hour24) {
+ hours = new String("");
+ if (c.get(Calendar.HOUR_OF_DAY) < 10) hours += "0";
+ hours += c.get(Calendar.HOUR_OF_DAY);
+ } else {
+ hours = new String("");
+ if (c.get(Calendar.HOUR) < 10) hours += "0";
+ hours += c.get(Calendar.HOUR);
+ }
+
+ String minutes = new String("");
+ if (c.get(Calendar.MINUTE) < 10) minutes += "0";
+ minutes += c.get(Calendar.MINUTE);
+
+ String lastSync = String.format("%s:%s\n", hours, minutes);
+ Log.d(TAG, "lastSnync:" + lastSync);
+ remoteViews.setTextViewText(R.id.txtSync, lastSync);
+ remoteViews.setViewVisibility(R.id.txtSync, View.VISIBLE);
+
+ } else remoteViews.setViewVisibility(R.id.txtSync, View.GONE);
+
+ remoteViews.setViewVisibility(R.id.prgBar, View.GONE);
+ remoteViews.setOnClickPendingIntent(R.id.imgLolo,
+ Utils.getOnTouchIntent(context));
+ appWidgetManager.updateAppWidget(appWidgetId, remoteViews);
+ }
+ } else Log.d(TAG, "No widgets installed");
+ }
+ }
+
+ // Uploads XML from stackoverflow.com, parses it, and combines it with
+ // HTML markup. Returns HTML string.
+ private String loadXmlFromNetwork(String urlString) throws XmlPullParserException, IOException {
+ InputStream stream = null;
+ RSSXmlParser rssXmlParser = new RSSXmlParser();
+ List<Entry> entries = null;
+
+ try {
+ stream = downloadUrl(urlString);
+ entries = rssXmlParser.parse(stream);
+ // Makes sure that the InputStream is closed after the app is
+ // finished using it.
+ } finally {
+ if (stream != null) stream.close();
+ }
+
+ // Each Entry object represents a single post in the XML feed.
+ // This section processes the entries list to combine each entry with
+ // HTML markup.
+ // Each entry is displayed in the UI as a link that optionally includes
+ // a text summary.
+ return entries.get(0).title;
+ }
+
+ // Given a string representation of a URL, sets up a connection and gets
+ // an input stream.
+ private InputStream downloadUrl(String urlString) throws IOException {
+ URL url = new URL(urlString);
+ HttpURLConnection conn = (HttpURLConnection) url.openConnection();
+ conn.setReadTimeout(10000 /* milliseconds */);
+ conn.setConnectTimeout(15000 /* milliseconds */);
+ conn.setRequestMethod("GET");
+ conn.setDoInput(true);
+ // Starts the query
+ conn.connect();
+ InputStream stream = conn.getInputStream();
+
+ return stream;
+ }
+}
View
68 src/com/codeskraps/lolo/Utils.java
@@ -23,26 +23,28 @@
import java.io.BufferedReader;
import java.io.IOException;
-import java.io.InputStream;
import java.io.InputStreamReader;
-import java.util.ArrayList;
-import java.util.List;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
+import org.apache.http.params.BasicHttpParams;
+import org.apache.http.params.HttpConnectionParams;
+import org.apache.http.params.HttpParams;
import org.json.JSONException;
import org.json.JSONObject;
import org.json.JSONTokener;
-import org.xmlpull.v1.XmlPullParser;
-import org.xmlpull.v1.XmlPullParserException;
+import android.app.PendingIntent;
import android.content.Context;
+import android.content.Intent;
+import android.content.SharedPreferences;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
+import android.net.Uri;
+import android.preference.PreferenceManager;
import android.util.Log;
-import android.util.Xml;
public class Utils {
private static final String TAG = Utils.class.getSimpleName();
@@ -52,9 +54,7 @@ public static boolean isNetworkAvailable(Context context) {
ConnectivityManager cm = (ConnectivityManager) context
.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo networkInfo = cm.getActiveNetworkInfo();
- if (networkInfo != null && networkInfo.isConnected()) {
- return true;
- }
+ if (networkInfo != null && networkInfo.isConnected()) { return true; }
return false;
}
@@ -63,7 +63,11 @@ public static boolean getLolo() throws IOException {
Log.d(TAG, "download begining");
Log.d(TAG, "download url:" + URL);
- HttpClient client = new DefaultHttpClient();
+ HttpParams httpParameters = new BasicHttpParams();
+ HttpConnectionParams.setConnectionTimeout(httpParameters, 5000);
+ HttpConnectionParams.setSoTimeout(httpParameters, 10000);
+
+ HttpClient client = new DefaultHttpClient(httpParameters);
HttpGet request = new HttpGet(URL);
HttpResponse response = client.execute(request);
@@ -71,14 +75,14 @@ public static boolean getLolo() throws IOException {
.getContent(), "UTF-8"));
String json = reader.readLine();
reader.close();
-
+
JSONTokener tokener = new JSONTokener(json);
boolean lolo = false;
try {
JSONObject finalResult = new JSONObject(tokener);
lolo = Boolean.getBoolean(finalResult.getString("open"));
- // Log.d(TAG, "lolo: " + lolo);
+ Log.d(TAG, "lolo: " + lolo);
} catch (JSONException e) {
Log.e(TAG, e.getMessage());
}
@@ -87,4 +91,44 @@ public static boolean getLolo() throws IOException {
+ " sec");
return lolo;
}
+
+ public static PendingIntent getOnTouchIntent(Context context) {
+ PendingIntent pendingIntent = null;
+ Intent intent = null;
+
+ SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
+ int onClick = Integer.parseInt(prefs.getString(Constants.ONCLICK, "0"));
+
+ switch (onClick) {
+ case 0:
+ intent = new Intent("com.codeskraps.lol.DO_NOTHING");
+ pendingIntent = PendingIntent.getActivity(context, 0, intent,
+ PendingIntent.FLAG_UPDATE_CURRENT);
+ break;
+
+ case 1:
+ intent = new Intent();
+ intent.setAction(Constants.BROADCAST_RECEIVER);
+ pendingIntent = PendingIntent.getBroadcast(context, 0, intent,
+ PendingIntent.FLAG_UPDATE_CURRENT);
+ break;
+
+ case 2:
+ intent = new Intent(context, PrefsActivity.class);
+ pendingIntent = PendingIntent.getActivity(context, 0, intent,
+ PendingIntent.FLAG_UPDATE_CURRENT);
+ break;
+
+ case 3:
+ intent = new Intent(Intent.ACTION_VIEW);
+ String url = prefs.getString(Constants.EURL,
+ context.getString(R.string.prefsURL_default));
+ if (!url.startsWith("http://")) url = "http://" + url;
+ intent.setData(Uri.parse(url));
+ pendingIntent = PendingIntent.getActivity(context, 0, intent,
+ PendingIntent.FLAG_UPDATE_CURRENT);
+ break;
+ }
+ return pendingIntent;
+ }
}
Please sign in to comment.
Something went wrong with that request. Please try again.