пʼятниця, 10 грудня 2010 р.

Control over default music player from your application

If you need to control default music player from your application(in my case app which replace default lock screen) just make your activity implements MediaPlayerControl and impelement all of its methods.



public class MyActivity extends Activity implements MediaController.MediaPlayerControl
{

@Override
protected void onCreate(Bundle savedInstanceState){}


// implement all methods

@Override
public void start() { }

@Override
public void pause() { }
}

Custom Android Button Style

If you need to draw non standard button in android, you could do like described here:
http://blog.androgames.net/40/custom-button-style-and-theme/ . Very nice.
Or you could just do in your code, like that
   Button yourButton = (Button) findViewById(R.id.idForYourButton);
    yourButton.getBackground().setColorFilter(0xff00ffff, PorterDuff.Mode.MULTIPLY);
you could define color 0xff00ffff in your color.xml, and get it by R.color.your_color.

четвер, 2 грудня 2010 р.

Configure wsgi for Django on Apache

I was need to run old and new version of my site.
So how to configure 2 version of your project on one apache server?
I've used 2 ports: 80(default) and 8080.
Edit your /etc/apache2/ports.conf and add this lines
NameVirtualHost *:80
Listen 80
NameVirtualHost *:8080
Listen 8080

Then go to /etc/apache2/sites-enabled/ , edit @000-default(default) and add those lines:

<VirtualHost *:80>
ServerAdmin webmaster@{{your_domain}}
DocumentRoot /var/www/

WSGIScriptAlias / /{__path_to_dir_where_your_project_is__}/django.wsgi
WSGIDaemonProcess {name_of_process} user={user_name} group={group_name} processes=5 threads=1
WSGIProcessGroup {name_of_process}

<Directory "{__path_to_dir_where_your_project_is__}">
Order allow,deny
Allow from all
</Directory>

<Location "site_media">
SetHandler None
</Location>

Alias /site_media/ /{__path_to_dir_where_your_project_is__}/{__path_to_media_folder__}/
<Directory "{__path_to_dir_where_your_project_is__}/{__path_to_media_folder__}">
Options FollowSymLinks
AllowOverride None
Order allow,deny
allow from all

ExpiresActive On
ExpiresDefault "access plus 5 days"
</Directory>

ErrorLog /var/log/apache2/error.log

# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn

CustomLog /var/log/apache2/access.log combined

</VirtualHost>

<VirtualHost *:8080>
ServerAdmin webmaster@{{your_domain}}
DocumentRoot /var/www/
ServerName {{your_domain}}
WSGIScriptAlias / /{__path_to_dir_where_project_is(another_version)__}/django.wsgi
WSGIDaemonProcess {name_of_process} user={user_name} group={group_name} processes=5 threads=1
WSGIProcessGroup {name_of_process}

<Directory "{__path_to_dir_where_your_project_is(another_version)__}">
Order allow,deny
Allow from all
</Directory>

<Location "site_media">
SetHandler None
</Location>

Alias /site_media/ /{__path_to_dir_where_your_project_is(another_version)__}/{__path_to_media_folder__}/
<Directory "{__path_to_dir_where_your_project_is(another_version)__}/{__path_to_media_folder__}">
Options FollowSymLinks
AllowOverride None
Order allow,deny
allow from all

ExpiresActive On
ExpiresDefault "access plus 5 days"
</Directory>

ErrorLog /var/log/apache2/error.log

# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn

CustomLog /var/log/apache2/access.log combined
<VirtualHost>

and finaly create file django.wsgi in {__path_to_dir_where_your_project_is__} and {__path_to_dir_where_your_project_is(another_version)__}
Here it is:
#!/usr/bin/python
import os
import sys

os.environ['DJANGO_SETTINGS_MODULE'] = '{settings_file_of_your_project}'
sys.path.append('{__path_to_your_project__}')
sys.path.append('{__path_to_dir_where_your_project_is__}')

import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()

Now you can start(restart) you apache.
Thats all folks!
p.s. it's work on my machine)