0

I finally managed to create a SIMPLE widget (1x1 cell) with ONE button that does something. In my case (for now) a toast. This was actually quite hard to do. Widgets work different from normal app's.

My code so far of all important files:
http://paste2.org/p/2427468


QUESTION 1:

I have a normal BUTTON, with a background. I have a @drawable/...xml on that button which defines the different images for normal and pressed state. This works quit nicely. Since toggleButton isnt supported on WIDGETS i had to use 'Button', but i want the effect of the toggle button. So after a button click the pressed state must be fixed/freezed! after another click the normal state should me fixed/freezed. How do you do this?



QUESTION 2:

If question 1 works: i need different actions on normal and pressed state. I would like to lower/increase the brightness of the screen.

In an app i created this worked:

    WindowManager.LayoutParams lp = getWindow().getAttributes();
    Toast.makeText(getBaseContext(),"Low brightness",Toast.LENGTH_LONG).show();
    lp.screenBrightness = 0.004F;
    float BackLightValue = lp.screenBrightness;
    int SysBackLightValue = (int)(BackLightValue * 255);
    android.provider.Settings.System.putInt(getContentResolver(),android.provider.Settings.System.SCREEN_BRIGHTNESS,SysBackLightValue);             
    getWindow().setAttributes(lp);

How do implement this in a widget?

I believe I'm almost done with this widget, but need a hand on these two questions.

Thanks!

1 Answers1

2

Din't understand your first question but for the second question , you can create an activity that has no UI and write the above code to set the brightness.Use an intent to call this activity and share the data between them.

ankur_gaur
  • 21
  • 2
  • Ankur_gaur, thank you for your reply. ToggleButtons are not supported in widgets.. please read the docs about this. So to get the effect of a togglebutton, i want to use a button and freeze/hold the hover and normal states. So it will look like a toggle button. How do i do this? Not valid code, but to get the idea.. something like: http://paste2.org/p/2463312 – user1688558 Nov 11 '12 at 13:21
  • Does any know how to make this 'toggleButton'? – user1688558 Nov 16 '12 at 14:41