Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

v1.2

  • Loading branch information...
commit 5f32d88ae54000716ac089ab8e77223fb09fd806 1 parent b7135d2
Carles Sentis authored
11 AndroidManifest.xml
View
@@ -1,7 +1,8 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.codeskraps.lolo"
- android:versionCode="2"
- android:versionName="1.1" >
+ android:versionCode="3"
+ android:versionName="1.2" >
+ <!-- Remember to update the info code version -->
<uses-sdk
android:minSdkVersion="7"
@@ -14,10 +15,14 @@
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
- <activity android:name=".PrefsActivity"
+ <activity
+ android:name=".PrefsActivity"
android:theme="@android:style/Theme.Light.NoTitleBar" >
<intent-filter>
+ <action android:name="android.intent.action.MAIN" />
<action android:name="android.appwidget.action.APPWIDGET_CONFIGURE" />
+
+ <category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
16 res/layout/header.xml
View
@@ -1,13 +1,9 @@
-<?xml version="1.0" encoding="utf-8"?>
-<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:orientation="vertical" >
+<merge xmlns:android="http://schemas.android.com/apk/res/android" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
- android:background="#222222"
+ android:background="#333333"
android:orientation="horizontal" >
<ImageView
@@ -22,15 +18,15 @@
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:text="@string/app_name"
- android:textColor="#B39000"
+ android:textColor="#AAAAAA"
android:textSize="25dp"
android:typeface="normal" />
</LinearLayout>
<LinearLayout
- android:layout_width="fill_parent"
+ android:layout_width="match_parent"
android:layout_height="1dp"
- android:background="#666666"
+ android:background="#FF0000"
android:orientation="horizontal" />
-</LinearLayout>
+</merge>
17 res/layout/prefs.xml
View
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:orientation="vertical" >
+
+ <include
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ layout="@layout/header" />
+
+ <ListView
+ android:id="@android:id/list"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent" />
+
+</LinearLayout>
12 res/layout/test.xml
View
@@ -1,12 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:orientation="vertical" >
-
-
- <Button
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:text="ok"/>
-</LinearLayout>
25 res/layout/widget.xml
View
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
-<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
@@ -11,7 +11,24 @@
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal|center"
android:contentDescription="@string/contentDescription"
- android:src="@drawable/closed"
- android:padding="15dip" />
+ android:padding="15dip"
+ android:src="@drawable/closed" />
-</LinearLayout>
+ <TextView
+ android:id="@+id/txtSync"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:layout_alignBottom="@id/imgLolo"
+ android:gravity="center_horizontal"
+ android:typeface="monospace"
+ android:shadowColor="#000000"
+ android:shadowDx="1"
+ android:shadowDy="1"
+ android:shadowRadius="1"
+ android:textColor="#FFFFFF" />
+
+<!-- <ProgressBar -->
+<!-- android:id="@+id/prgBar" -->
+<!-- /> -->
+
+</RelativeLayout>
17 res/values/strings.xml
View
@@ -7,14 +7,15 @@
<!-- Preference Activity -->
<string name="prefsCat_General">General</string>
- <string name="prefsOnClick_title">OnClick event</string>
- <string name="prefsOnClick_dialogTitle">Select One</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>
<string-array name="OnClick_entries">
- <item>Nothing</item>
+ <item>Do nothing</item>
<item>Update lo-lo status</item>
- <item>Open preference screen</item>
- <item>Open 091 Labs web page</item>
+ <item>Open widget settings</item>
+ <item>Open URL</item>
</string-array>
<string-array name="OnClick_values">
<item>0</item>
@@ -22,9 +23,13 @@
<item>2</item>
<item>3</item>
</string-array>
+
+ <string name="prefsURL_title">URL</string>
+ <string name="prefsURL_summary">Set a Custom URL -</string>
+ <string name="prefsURL_default">091labs.com</string>
<string name="prefsCat_Info">Information</string>
- <string name="prefsInfo_Title">091 Labs lo-lo v1.1</string>
+ <string name="prefsInfo_Title">091 Labs lo-lo v1.2</string>
<string name="prefsInfo_summary">GNU GPL License v3 - 2012</string>
</resources>
13 res/xml/preferences.xml
View
@@ -3,12 +3,17 @@
<PreferenceCategory android:title="@string/prefsCat_General" >
<ListPreference
- android:key="lstOnClick"
- android:title="@string/prefsOnClick_title"
+ android:defaultValue="0"
+ android:dialogTitle="@string/prefsOnClick_dialogTitle"
android:entries="@array/OnClick_entries"
android:entryValues="@array/OnClick_values"
- android:defaultValue="0"
- android:dialogTitle="@string/prefsOnClick_dialogTitle" />
+ android:key="lstOnClick"
+ android:title="@string/prefsOnClick_title" />
+
+ <EditTextPreference
+ android:key="eURL"
+ android:title="@string/prefsURL_title"
+ android:defaultValue="@string/prefsURL_default" />
</PreferenceCategory>
<PreferenceCategory android:title="@string/prefsCat_Info" >
<Preference
24 src/com/codeskraps/lolo/LoloProvider.java
View
@@ -15,16 +15,17 @@
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";
- private static final String URL = "http://091labs.com";
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
+ Log.d(TAG, "onUpdate");
updateWidget(context);
super.onUpdate(context, appWidgetManager, appWidgetIds);
}
@Override
public void onReceive(Context context, Intent intent) {
+ Log.d(TAG, "onReceive");
final String action = intent.getAction();
if (action.equals(FORCE_WIDGET_UPDATE))
@@ -32,15 +33,17 @@ public void onReceive(Context context, Intent intent) {
super.onReceive(context, intent);
}
-
+
public void updateWidget(Context context) {
- ComponentName thisWidget = new ComponentName(context, LoloProvider.class);
- AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
- int[] appWidgetIds = appWidgetManager.getAppWidgetIds(thisWidget);
- updateWidget(context, appWidgetManager, appWidgetIds);
- }
+ 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) {
+ Log.d(TAG, "updateWidget2");
final int N = appWidgetIds.length;
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
@@ -59,6 +62,7 @@ private void updateWidget(Context context, AppWidgetManager appWidgetManager, in
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);
@@ -69,7 +73,11 @@ private void updateWidget(Context context, AppWidgetManager appWidgetManager, in
break;
case 3:
intent = new Intent(Intent.ACTION_VIEW);
- intent.setData(Uri.parse(URL));
+ 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;
}
97 src/com/codeskraps/lolo/PrefsActivity.java
View
@@ -5,29 +5,36 @@
import android.content.SharedPreferences;
import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
import android.os.Bundle;
+import android.preference.EditTextPreference;
import android.preference.ListPreference;
import android.preference.PreferenceActivity;
import android.preference.PreferenceManager;
import android.util.Log;
import android.view.KeyEvent;
+import android.widget.ImageView;
+import android.widget.LinearLayout;
+import android.widget.RelativeLayout;
+import android.widget.RelativeLayout.LayoutParams;
public class PrefsActivity extends PreferenceActivity implements OnSharedPreferenceChangeListener {
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";
private SharedPreferences prefs = null;
private ListPreference lstOnClick = null;
+ private EditTextPreference eURL = null;
private String[] entries_OnClick = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
Log.d(TAG, "onCreate");
super.onCreate(savedInstanceState);
-
- // setContentView(R.layout.header);
+
addPreferencesFromResource(R.xml.preferences);
+ setContentView(R.layout.prefs);
prefs = PreferenceManager.getDefaultSharedPreferences(this);
prefs.registerOnSharedPreferenceChangeListener(this);
@@ -35,53 +42,79 @@ protected void onCreate(Bundle savedInstanceState) {
entries_OnClick = getResources().getStringArray(R.array.OnClick_entries);
lstOnClick = (ListPreference) findPreference(ONCLICK);
+ eURL = (EditTextPreference) findPreference(EURL);
+ }
+
+ @Override
+ protected void onResume() {
+ super.onResume();
- String onClick = prefs.getString(ONCLICK, "Nothing");
- lstOnClick.setSummary(entries_OnClick[Integer.parseInt(onClick)]);
+ String onClick = prefs.getString(ONCLICK, entries_OnClick[0]);
+ int action = Integer.parseInt(onClick);
+ lstOnClick.setSummary(entries_OnClick[action]);
+
+ String url = prefs.getString(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);
}
@Override
protected void onPause() {
+ Log.d(TAG, "onPause");
super.onPause();
prefs.unregisterOnSharedPreferenceChangeListener(this);
}
@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
+ Log.d(TAG, "onSharedPreferenceChanged");
if (key.equals(ONCLICK)) {
- String onClick = prefs.getString(ONCLICK, "Nothing");
- lstOnClick.setSummary(entries_OnClick[Integer.parseInt(onClick)]);
+ String onClick = prefs.getString(ONCLICK, entries_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));
+ String urlSummary = String.format("%s %s", getString(R.string.prefsURL_summary), url);
+ eURL.setSummary(urlSummary);
}
}
-
+
@Override
- public boolean onKeyDown(int keyCode, KeyEvent event) {
- if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.ECLAIR
- && keyCode == KeyEvent.KEYCODE_BACK
- && event.getRepeatCount() == 0) {
- // Take care of calling this method on earlier versions of
- // the platform where it doesn't exist.
- //Log.d(TAG, "SDK < Eclair");
- onBackPressed();
- }
-
- return super.onKeyDown(keyCode, event);
- }
-
- @Override
- 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.
- //Log.d(TAG, "onBackPressed");
- resultIntent();
- finish();
- return;
- }
+ public boolean onKeyDown(int keyCode, KeyEvent event) {
+ Log.d(TAG, "onKeyDown");
+ if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.ECLAIR
+ && keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {
+ // Take care of calling this method on earlier versions of
+ // the platform where it doesn't exist.
+ Log.d(TAG, "SDK < Eclair");
+ onBackPressed();
+ }
+
+ return super.onKeyDown(keyCode, event);
+ }
+
+ @Override
+ 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.
+ Log.d(TAG, "onBackPressed");
+ resultIntent();
+ finish();
+ return;
+ }
private void resultIntent() {
Log.d(TAG, "resultIntent");
-
+
if (CONFIGURE_ACTION.equals(getIntent().getAction())) {
Intent intent = getIntent();
Bundle extras = intent.getExtras();
@@ -96,4 +129,4 @@ private void resultIntent() {
}
sendBroadcast(new Intent(FORCE_WIDGET_UPDATE));
}
-}
+}
20 src/com/codeskraps/lolo/UpdateWidgetService.java
View
@@ -1,6 +1,8 @@
package com.codeskraps.lolo;
import java.io.IOException;
+import java.util.Calendar;
+import java.util.Date;
import android.app.Service;
import android.appwidget.AppWidgetManager;
@@ -10,6 +12,7 @@
import android.os.IBinder;
import android.util.Log;
import android.widget.RemoteViews;
+import android.widget.Toast;
public class UpdateWidgetService extends Service {
private static final String TAG = UpdateWidgetService.class.getSimpleName();
@@ -77,6 +80,23 @@ public void run() {
remoteViews.setImageViewResource(R.id.imgLolo, R.drawable.closed);
Log.d(TAG, "The labs is close");
}
+
+ Calendar c = Calendar.getInstance();
+
+ String hours = new String("");
+ if (c.get(Calendar.HOUR_OF_DAY) < 10)
+ hours += "0";
+ hours += c.get(Calendar.HOUR_OF_DAY);
+
+ 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);
+
appWidgetManager.updateAppWidget(widgetId, remoteViews);
}
} else {
4 src/com/codeskraps/lolo/Utils.java
View
@@ -43,7 +43,7 @@ public static boolean getLolo() throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(response.getEntity()
.getContent(), "UTF-8"));
String json = reader.readLine();
- Log.d(TAG, "json: " + json);
+// Log.d(TAG, "json: " + json);
JSONTokener tokener = new JSONTokener(json);
String lolo = null;
@@ -55,7 +55,7 @@ public static boolean getLolo() throws IOException {
Log.e(TAG, e.getMessage());
}
- Log.d(TAG, "download ready in"
+ Log.d(TAG, "download ready in "
+ ((System.currentTimeMillis() - startTime) / 1000) + " sec");
if (lolo.equals("true")) {
Please sign in to comment.
Something went wrong with that request. Please try again.