[Widget] Countdown

Put problem concerning Views, Layouts and other XML-Resources (like AndroidManifest) here.

[Widget] Countdown

Postby warwink » Thu Jan 14, 2010 5:03 pm

Well, i search a really long time but didn't find.

Like I wrote in the title, i want to add a countdown in my widget.

1) Is there another way to play with the display content in the Provider than this one :

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.appwidget_provider);
  2.  
  3. views.setTextViewText(R.id.TVWidgetName, data.characterName);
Parsed in 0.030 seconds, using GeSHi 1.0.8.4


If I could retrieve a TextView or a layout for exemple to use after a CountDownTimer.

2) I tried to use a Chronometer but can't find a way to use it as a countdown.

3) I rode that since 1.6, it's not possible to set android:updatePeriodMillis less than 30min, is true ?
Because, I tried to set to 1s or 10s, but onUpdate is never called.

Anyway, If you have some ideas or clues ? help !! :)

Here some part of my code.

res/xml/widget.xml
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. <appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
  2.  
  3.     android:minWidth="186dp"
  4.  
  5.     android:minHeight="45dp"
  6.  
  7.     android:updatePeriodMillis="120000"
  8.  
  9.     android:initialLayout="@layout/appwidget_provider"
  10.  
  11.     android:configure="com.eveinfo.widget.WidgetConfigure"
  12.  
  13.  />
Parsed in 0.031 seconds, using GeSHi 1.0.8.4


AndroidManifest.xml
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. <activity android:name=".widget.WidgetConfigure">
  2.  
  3.                         <intent-filter>
  4.  
  5.                                 <action android:name="android.appwidget.action.APPWIDGET_CONFIGURE" />
  6.  
  7.                         </intent-filter>
  8.  
  9.                 </activity>
  10.  
  11.  
  12.  
  13.                 <receiver android:name=".widget.WidgetProvider">
  14.  
  15.                         <intent-filter>
  16.  
  17.                                 <action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
  18.  
  19.                         </intent-filter>
  20.  
  21.                         <meta-data android:name="android.appwidget.provider"
  22.  
  23.                                 android:resource="@xml/widget" />
  24.  
  25.                 </receiver>
Parsed in 0.035 seconds, using GeSHi 1.0.8.4


WidgetProvider.java
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. public class WidgetProvider extends AppWidgetProvider {
  2.  
  3.         // log tag
  4.  
  5.         private static final String TAG = "WidgetProvider";
  6.  
  7.  
  8.  
  9.         private static CountDown countDown;
  10.  
  11.  
  12.  
  13.         @Override
  14.  
  15.         public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
  16.  
  17.                 System.out.println("onUpdate");
  18.  
  19.                 Log.d(TAG, "onUpdate");
  20.  
  21.                 final int N = appWidgetIds.length;
  22.  
  23.                 for (int i = 0; i < N; i++) {
  24.  
  25.                         int appWidgetId = appWidgetIds[i];
  26.  
  27.                         updateAppWidget(context, appWidgetManager, appWidgetId);
  28.  
  29.                 }
  30.  
  31.         }
  32.  
  33.  
  34.  
  35.         @Override
  36.  
  37.         public void onDeleted(Context context, int[] appWidgetIds) {
  38.  
  39.                 Log.d(TAG, "onDeleted");
  40.  
  41.                 final int N = appWidgetIds.length;
  42.  
  43.                 for (int i = 0; i < N; i++) {
  44.  
  45.                         WidgetConfigure.deleteTitlePref(context, appWidgetIds[i]);
  46.  
  47.                 }
  48.  
  49.         }
  50.  
  51.  
  52.  
  53.         @Override
  54.  
  55.         public void onEnabled(Context context) {
  56.  
  57.                 Log.d(TAG, "onEnabled");
  58.  
  59.         }
  60.  
  61.  
  62.  
  63.         @Override
  64.  
  65.         public void onDisabled(Context context) {
  66.  
  67.                 Log.d(TAG, "onDisabled");
  68.  
  69.         }
  70.  
  71.  
  72.  
  73.         static void updateAppWidget(Context context, AppWidgetManager appWidgetManager, int appWidgetId) {
  74.  
  75.                 Log.d(TAG, "updateAppWidget appWidgetId=" + appWidgetId);
  76.  
  77.                 WidgetData data = WidgetConfigure.loadTitlePref(context, appWidgetId);
  78.  
  79.  
  80.  
  81.                 RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.appwidget_provider);
  82.  
  83.                 .......
  84.  
  85.         appWidgetManager.updateAppWidget(appWidgetId, views);
  86.  
  87.         }
  88.  
  89.  
  90.  
  91.         static class CountDown extends CountDownTimer {
  92.  
  93.                
  94.  
  95.                 private Context context;
  96.  
  97.                 private long time;
  98.  
  99.                
  100.  
  101.                 public CountDown(Context context, long millisInFuture, long countDownInterval) {
  102.  
  103.                         super(millisInFuture, countDownInterval);
  104.  
  105.                         this.context = context;
  106.  
  107.                 }
  108.  
  109.  
  110.  
  111.                 @Override
  112.  
  113.                 public void onFinish() {
  114.  
  115.                 }
  116.  
  117.  
  118.  
  119.                 @Override
  120.  
  121.                 public void onTick(long millisUntilFinished) {
  122.  
  123.                         RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.appwidget_provider);
  124.  
  125.                         views.setTextViewText(R.id.TVWidgetTraining, "" + millisUntilFinished);
  126.  
  127.                         setTime(millisUntilFinished);
  128.  
  129.                 }
  130.  
  131.  
  132.  
  133.                 public void setTime(long time) {
  134.  
  135.                         this.time = time;
  136.  
  137.                 }
  138.  
  139.  
  140.  
  141.                 public long getTime() {
  142.  
  143.                         return time;
  144.  
  145.                 }
  146.  
  147.         }
Parsed in 0.044 seconds, using GeSHi 1.0.8.4



Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. package com.eveinfo.widget;
  2.  
  3.  
  4.  
  5. public class WidgetConfigure extends Activity {
  6.  
  7.         static final String TAG = "AppWidgetConfigure";
  8.  
  9.  
  10.  
  11.         private static final String PREFS_NAME = "com.eveinfo.widget.WidgetProvider";
  12.  
  13.         private static final String PREF_PREFIX_KEY = "widget_";
  14.  
  15.         private static final String PREF_SUFIX_CHARNAME_KEY = "_charName";
  16.  
  17.         private static final String PREF_SUFIX_USERID_KEY = "_userID";
  18.  
  19.         private static final String PREF_SUFIX_CHARID_KEY = "_charID";
  20.  
  21.         private static final String PREF_SUFIX_APIID_KEY = "_apiKey";
  22.  
  23.  
  24.  
  25.         private Spinner spinner;
  26.  
  27.         private ArrayList<Pilot> pilots;
  28.  
  29.         private String[] list;
  30.  
  31.  
  32.  
  33.         int mAppWidgetId = AppWidgetManager.INVALID_APPWIDGET_ID;
  34.  
  35.  
  36.  
  37.         public WidgetConfigure() {
  38.  
  39.                 super();
  40.  
  41.         }
  42.  
  43.  
  44.  
  45.         @Override
  46.  
  47.         public void onCreate(Bundle icicle) {
  48.  
  49.                 super.onCreate(icicle);
  50.  
  51.                 setResult(RESULT_CANCELED);
  52.  
  53.                 setContentView(R.layout.appwidget_configure);
  54.  
  55.  
  56.  
  57.                 .........
  58.  
  59.  
  60.  
  61.                 spinner = (Spinner) findViewById(R.id.SWidget);
  62.  
  63.                 ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, list);
  64.  
  65.                 adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
  66.  
  67.                 spinner.setAdapter(adapter);
  68.  
  69.  
  70.  
  71.                 findViewById(R.id.BWidgetSave).setOnClickListener(mOnClickListener);
  72.  
  73.  
  74.  
  75.                 Intent intent = getIntent();
  76.  
  77.                 Bundle extras = intent.getExtras();
  78.  
  79.                 if (extras != null) {
  80.  
  81.                         mAppWidgetId = extras.getInt(AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID);
  82.  
  83.                 }
  84.  
  85.  
  86.  
  87.                 if (mAppWidgetId == AppWidgetManager.INVALID_APPWIDGET_ID) {
  88.  
  89.                         finish();
  90.  
  91.                 }
  92.  
  93.         }
  94.  
  95.  
  96.  
  97.         View.OnClickListener mOnClickListener = new View.OnClickListener() {
  98.  
  99.                 public void onClick(View v) {
  100.  
  101.                         final Context context = WidgetConfigure.this;
  102.  
  103.  
  104.  
  105.                         Pilot pilot = pilots.get(spinner.getSelectedItemPosition());
  106.  
  107.  
  108.  
  109.                         saveTitlePref(context, mAppWidgetId, pilot.getName(), pilot.getUserId(), pilot.getCharacterId(), pilot
  110.  
  111.                                         .getApiKey());
  112.  
  113.  
  114.  
  115.                         // Push widget update to surface with newly set prefix
  116.  
  117.                         AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
  118.  
  119.                         WidgetProvider.updateAppWidget(context, appWidgetManager, mAppWidgetId);
  120.  
  121.  
  122.  
  123.                         // Make sure we pass back the original appWidgetId
  124.  
  125.                         Intent resultValue = new Intent();
  126.  
  127.                         resultValue.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, mAppWidgetId);
  128.  
  129.                         setResult(RESULT_OK, resultValue);
  130.  
  131.                         finish();
  132.  
  133.                 }
  134.  
  135.         };
  136.  
  137.  
  138.  
  139.         static void saveTitlePref(Context context, int appWidgetId, String charName, int userID, long charID, String apiKey) {
  140.  
  141.                 .........
  142.  
  143.         }
  144.  
  145.  
  146.  
  147.         static WidgetData loadTitlePref(Context context, int appWidgetId) {
  148.  
  149.                 .........
  150.  
  151.         }
  152.  
  153.  
  154.  
  155.         static void deleteTitlePref(Context context, int appWidgetId) {
  156.  
  157.         }
  158.  
  159.  
  160.  
  161.         static void loadAllTitlePrefs(Context context, ArrayList<Integer> appWidgetIds, ArrayList<String> texts) {
  162.  
  163.         }
  164.  
  165.  
  166.  
  167.         public static class WidgetData {
  168.  
  169.                 String characterName;
  170.  
  171.                 int userID;
  172.  
  173.                 long characterID;
  174.  
  175.                 String apiKey;
  176.  
  177.         }
  178.  
  179. }
Parsed in 0.048 seconds, using GeSHi 1.0.8.4


Thx,
Warwink,
warwink
Freshman
Freshman
 
Posts: 3
Joined: Thu Jan 14, 2010 4:49 pm

Top

Postby warwink » Mon Jan 18, 2010 11:59 pm

No chance to do that ?
warwink
Freshman
Freshman
 
Posts: 3
Joined: Thu Jan 14, 2010 4:49 pm

Postby qlimax » Tue Jan 19, 2010 12:34 am

for the 3) you can watch how i implemented a cpu meter widget
http://egsolutions.ch/
¯`·.¸¸.><((((º>¯`·.¸¸. ><((((º>
User avatar
qlimax
Master Developer
Master Developer
 
Posts: 271
Joined: Mon Aug 31, 2009 10:54 am
Location: Swiss

Postby warwink » Tue Jan 19, 2010 5:10 pm

Thank you very much.

I made one at the moment with yours solution.

Just a question, does the alarm wake up the phone every time ?
warwink
Freshman
Freshman
 
Posts: 3
Joined: Thu Jan 14, 2010 4:49 pm

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: No registered users and 3 guests