how to change background of a widget

by james pruett » Sat, 18 Dec 2010 01:09:59 GMT


Sponsored Links
 I want to change the background of a widget.
This is from the wiki word of the day widget example code:
Thanks for any leads!
-cellurl

I have tried:

   /**
    * Build a widget update to show the current Wiktionary
    * "Word of the day." Will block until the online API returns.
    */
   public RemoteViews buildUpdate(Context context) {

     RemoteViews updateViews = null;
     updateViews = new RemoteViews(context.getPackageName(),
R.layout.widget_word);
     updateViews.setTextViewText(R.id.definition, "off");

         Intent i=new Intent(this, WidgetService.class);
            PendingIntent pi=PendingIntent.getService(this, 0, i, 0);
            updateViews.setOnClickPendingIntent(R.id.widget, pi);

->none of these work
            //updateViews.setImageViewBitmap(R.id.widget,
R.drawable.widget_bg_normal_ticket);
            //updateViews.setImageViewResource(R.id.widget,
R.drawable.widget_bg_normal_ticket);
            //updateViews.setImageViewResource(Global.myAppWidgetId,
R.drawable.widget_bg_normal_ticket);

     return updateViews;
   }

-- 



Re: how to change background of a widget

by cellurl » Sat, 18 Dec 2010 04:03:56 GMT


 More info. It says RemoteView doesnt have setImageResource().
Q: Does that mean I am out of luck??
-cellurl

---code-----

   This Line unHappy->
        views.setImageViewResource(R.id.widget,
R.drawable.widget_bg_normal_speedlimit);

        int appWidgetId= Global.myAppWidgetId;
        if(appWidgetId != 0) {
 
org.wikispeedia.SpeedLimitc.WordWidget.myAppWidgetManager.updateAppWidget(appWidgetId,
views);
        } else {
                Log.d("TAGG","You forgot to re-add the widget OR we are using
an old-installed one...");
        }

---error------
WARN/ResourceType(615):
Skipping entry 0x7f090002 in package table 0 because it is not
complex!
WARN/AppWidgetHostView(615):
updateAppWidget couldn't find any view, using error view
at android.widget.RemoteViews$ActionException: view:
android.widget.RelativeLayout doesn't have method:
setImageResource(int)
at android.widget.RemoteViews$ReflectionAction.apply(RemoteViews.java:
438)
at android.widget.RemoteViews.performApply(RemoteViews.java:855)
at android.widget.RemoteViews.apply(RemoteViews.java:832)
at
android.appwidget.AppWidgetHostView.updateAppWidget(AppWidgetHostView.java:
167)
at
android.appwidget.AppWidgetHost.updateAppWidgetView(AppWidgetHost.java:
243)
at android.appwidget.AppWidgetHost
$UpdateHandler.handleMessage(AppWidgetHost.java:73)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:3948)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:521)
at com.android.internal.os.ZygoteInit
$MethodAndArgsCaller.run(ZygoteInit.java:782)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:540)
at dalvik.system.NativeStart.main(Native Method)
INFO/ActivityManager(572):
Stopping service: org.wikispeedia.SpeedLimitc/
apt.tutorial.WidgetService

-- 


Sponsored Links


Re: Re: how to change background of a widget

by Mark Murphy » Sat, 18 Dec 2010 04:07:51 GMT


 


One option is to use a layout file that has your desired background.

-- 
Mark Murphy (a Commons Guy)
 http://commonsware.com  |  http://github.com/commonsguy 
 http://commonsware.com/blog  |  http://twitter.com/commonsguy 

_The Busy Coder's Guide to *Advanced* Android Development_ Version 1.9
Available!

-- 



Re: Re: how to change background of a widget

by Kostya Vasilyev » Sat, 18 Dec 2010 17:45:38 GMT


 17.12.2010 23:03, cellurl :
More info. It says RemoteView doesnt have setImageResource(). Q: Does that mean I am out of luck?? -cellurl
RemoteViewshas setImageViewResource. http://developer.android.com/reference/android/widget/RemoteViews.html #setImageViewResource(int, int) Put an ImageView into your RelativeLayout, size it to fit the entire layout, and it's as good as having a background image. Might want to also set background="@android:color/transparent" for the relative layout, as an optimization. -- Kostya Vasilyev -- WiFi Manager + pretty widget -- http://kmansoft.wordpress.com --



Re: how to change background of a widget

by cellurl » Fri, 28 Jan 2011 21:39:55 GMT


 That worked so easily, I didn't believe it at first!
Only the experts know "the workarounds". Thanks Kostya!
-cellurl




-- 



Re: Re: how to change background of a widget

by Kostya Vasilyev » Fri, 28 Jan 2011 21:46:29 GMT


 Cool!

28.01.2011 16:39, cellurl :
That worked so easily, I didn't believe it at first! Only the experts know "the workarounds". Thanks Kostya! -cellurl
17.12.2010 23:03, cellurl :
More info. It says RemoteView doesnt have setImageResource(). Q: Does that mean I am out of luck?? -cellurl
RemoteViewshas setImageViewResource. http://developer.android.com/reference/android/widget/RemoteViews.htm... , int) Put an ImageView into your RelativeLayout, size it to fit the entire layout, and it's as good as having abackgroundimage. Might want to also setbackground="@android:color/transparent" for the relative layout, as an optimization. -- Kostya Vasilyev -- WiFi Manager + prettywidget-- http://kmansoft.wordpress.com
-- Kostya Vasilyev -- WiFi Manager + pretty widget -- http://kmansoft.wordpress.com --



Other Threads

1. OSCL libraries programming guide

Any guys know where  I can find some simple example codes and guides
to help to develop  oscl-based program for OpenCore,  Docs in opencore/
docs/* are library reference

Thanks in advance!
--~--~---------~--~----~------------~-------~--~----~
unsubscribe: android-porting+unsubscr...@googlegroups.com
website: 

2. SSL and Non-Trusted Certificates using DefaultHttpClient

Hello all. I'm trying to create an SSL connection to a server that
uses a Self-Signed Certificate, and I'm trying to do it with a
DefaultHttpConnection. So far I have been able to turn off the
hostname checking for this connection (i.e. the gmail.com !=
mail.google.com error) but I cannot get past the Non-Trusted
Certificate error...

However, I have been able to make such a connection using the
java.net.ssl classes using the code below and download the site's
certificate. I believe that my next move should be to load the cert
into the default keystore, but I'm very fuzzy on how to do this, and I
haven't been able to find anything in the group that actually uses the
DefaultHttpClient instead of just creating an InputStream and
OutputStream to the server using the java.net.ssl.SSLSocket class.

My working code that uses the java.net.ssl libraries is below. Can
anybody help me turn this connection into a DefaultHttpConnection or
tell me what to do with the cert? Thanks in advance, G

P.S. MyHostNameVerifier and MyTrustManager are simple classes that
implement javax.net.ssl.HostnameVerifier and import
javax.net.ssl.X509TrustManager, respectively. MyHostnameVerifier
returns true in the verify() method, and MyTrustManager returns an
empty array in the getAcceptedIssuers() method.  These two classes
were necessary to make the initial connection go through, but don't
seem to help when it comes to the DefaultHttpConnection (or maybe I'm
just not using it right... please help)

                        HttpsURLConnection.setDefaultHostnameVerifier(new 
MyHostNameVerifier
());

                        MyTrustManager[] mtm = {new MyTrustManager()};
                        SSLContext sc = SSLContext.getInstance("TLS");
                        sc.init(null, mtm, new SecureRandom());

                        
HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory
());

                        SSLSocketFactory factory =
HttpsURLConnection.getDefaultSSLSocketFactory();
                        SSLSocket socket = 
(SSLSocket)factory.createSocket(server, port);

                // Connect to the server
                socket.startHandshake();

                // Retrieve the server's certificate chain
                Certificate[] serverCerts = socket.getSession
().getPeerCertificates();
                //socket.getSession().getPeerCertificateChain()

                // Close the socket
                socket.close();
--~--~---------~--~----~------------~-------~--~----~

3. Hi Dear all

4. getting the system wallpapers, is it possible?

5. Creating multiple layouts

6. full screen without status bar

7. Grrrr "error: device not found"