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!