Android – Setting screen brightness from code behind

I ran into a problem today with trying to override the screen brightness for the current activity. I found there are 2 methods of changing your screen brightness, 1 which changed the whole system brightness or the other which is to change your current activity’s brightness.

I went for the latter however I came up against some problems when I tried to use the code I found here;

http://stackoverflow.com/a/5090578/276220

 I realised my eclipse was complaining because I had the project set as an android 2.1 project rather than the 2.3.3 handset which I was debugging on.
It would seem that you used to be able to just set it with;
public void SetBright(float value) 
{
    Window mywindow = getWindow();
    WindowManager.LayoutParams lp = mywindow.getAttributes();
    lp.screenBrightness = value;
    mywindow.setAttributes(lp);
}
However when google updated android with the option to set automatic brightness that method no longer worked. Therefore you had to check if the auto brightness had been set so that you could tell android that you were going to manually override the brightness
public void setBrightness(float brightness){ 
    try{
	int brightnessMode = android.provider.Settings.System.getInt(getContentResolver(), android.provider.Settings.System.SCREEN_BRIGHTNESS_MODE);
 
        if (brightnessMode == android.provider.Settings.System.SCREEN_BRIGHTNESS_MODE_AUTOMATIC) {
		android.provider.Settings.System.putInt(getContentResolver(), android.provider.Settings.System.SCREEN_BRIGHTNESS_MODE, android.provider.Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL);
	}
 
	WindowManager.LayoutParams layoutParams = getWindow().getAttributes();
	layoutParams.screenBrightness = brightness;
	getWindow().setAttributes(layoutParams);
    } catch (Exception e){
        // do something useful
    }
}
I also found this which is a nice slider attached to the brightness, however their post looks pretty awful to read so I’d suggest check the stackoverflow post first before you try and understand this one 😀
http://android-er.blogspot.com/2011/02/change-system-screen-brightness-using.html

SocialEngine Tutorial – Adding dynamic href links from code behind

One thing you might want to do when you’re coding your own modules/widgets is to have a link to another page you might have created within your socialengine site.

You could use the following to add a link inside your index.tpl view file

<a href='http://yoursite.com/yourmodule/yourfunctionname'>Click me</a>

However if you use direct paths such as this you might run into troubles later on if you decide to move your site or share your modules/widgets with other people.

The best way you can generate html links is through using the helper class which is available inside socialengine which is loaded with your view and available from the $this object. The syntax for using this helper class is as follows;

<?php echo $this->htmlLink('your-module-name/the-action-you-want-to-execute','Click me!'); ?>

SocialEngine Tutorial – Creating your own custom theme and styles with css

Carrying on from the initial post about customisation I thought I’d add a quick overview of how on earth you go about customising your SocialEngine site with your own custom css.

One thing i would suggest about editing the SocialEngine platform is that if you can, do it through the admin interface as much as possible. The reason I say this is because as the engine is designed, quite rightly, to function in a multitude of different styles and formations it is intrinsically linked to a database backend which keeps a note of themes available and modules/widget positions etc.

So first off head to the theme editor;
Log into your network as an admin > Admin > Layout > Theme Editor

I would suggest that you hit ‘Clone’ and clone an existing theme which will bring you to the next screen;

Now you’ll be taken back to the theme editor, MAKE SURE YOU ACTIVATE YOUR THEME! Otherwise you’ll be editing the original theme. To activate just hit ‘Activate Theme’ which will then allow you to edit your theme.

Now themes are made up of two items; constant.css and theme.css.

Constants deals with all the constants which are generic for the site for example, site width will be specified in there and body background etc. This is where you’re most likely to edit items which will effect most of the site.

Inside the theme.css you’ll be able to edit other stuff like menu bars and headings etc but you will also be able to specify your own styles for your own modules or widgets that you create.

After you’ve finished editing your theme hit the save button and you’re ready to rock and roll to see what you’ve destroyed on the site 🙂

The easiest way to know what styles to edit is to use some browser debugging such as firebug (for firefox) or chrome developer tools (google chrome). Enjoy!

 

SocialEngine Tutorial – Creating your own custom homepage

One of the first things you might want to do with SocialEngine is to start customising the hell out of it. What better place to start then with your homepage? I did a bit of googling for the answer to this and in the end I came up with a relatively neat-ish hack for it which requires minimal set up.

First off you’ll need to head into the layout editor –
Log into your network > Admin > Layout > Layout Editor

This page allows you to add widgets from the menu on the right (you can add stuff like login boxes and member counters etc). However it doesn’t really allow you to scrap the whole thing and start with your own layout completely.

If you want to do this then hit ‘edit columns’ and select the option with only a header, content and footer;

Now drag the ‘HTML Block’ from the available blocks (on the right) into your main content area. You can then click ‘edit’ on the html block and paste in your HTML. I’d suggest just creating your markup in another file and once you’re happy with it just paste it in.

If you want to be able to add a login area then drag that in too and then head to the main page in your browser and copy and paste the html of the login area block. This will allow you then to add your own styles to the login form as well as completely customise your own front page.