mercredi 26 septembre 2012

android - Changing locale: Force activity to reload resources? - Stack Overflow

android - Changing locale: Force activity to reload resources? - Stack Overflow: In your AndroidManifest.xml, add this attribute to your Activity
android:configChanges="locale"
In your activity override onConfigurationChanged()
@Override
public void onConfigurationChanged(Configuration newConfig) {
   // refresh your views here
   super.onConfigurationChanged(newConfig);
}

mardi 25 septembre 2012

android - getSize() giving me errors - Stack Overflow

android - getSize() giving me errors - Stack Overflow: This supports both older and newer devices:
private static Point getDisplaySize(final Display display) {
   final Point point = new Point();
     try {
           display.getSize(point);
     } catch (java.lang.NoSuchMethodError ignore) { // Older device
          point.x = display.getWidth();
          point.y = display.getHeight();
     }
     return point;
}

layout - Android: How to get screen dimensions - Stack Overflow

layout - Android: How to get screen dimensions - Stack Overflow: If you want the the display dimensions in pixels you can use getSize:
Display display = getWindowManager().getDefaultDisplay();
Point size = new Point();
display.getSize(size);
int width = size.x;
int height = size.y;
If you're not in an Activity you can get the default Display via WINDOW_SERVICE:
WindowManager wm = (WindowManager) ctx.getSystemService(Context.WINDOW_SERVICE);
Display display = wm.getDefaultDisplay();
Before getSize was introduced (in API level 13), you could use the getWidth and getHeight methods that are now deprecated:
Display display = getWindowManager().getDefaultDisplay(); 
int width = display.getWidth();  // deprecated
int height = display.getHeight(); // deprecated

jeudi 20 septembre 2012

CraftyFella's Blog: Syntax Highlighting with Blogger Engine

CraftyFella's Blog: Syntax Highlighting with Blogger Engine:
// Comment
public class Testing {
����public Testing() {
����}
�
����public void Method() {
��������/* Another Comment
�����������on multiple lines */
��������int x = 9;
����}
}

CraftyFella's Blog: Syntax Highlighting with Blogger Engine

CraftyFella's Blog: Syntax Highlighting with Blogger Engine:


<link href='http://alexgorbatchev.com/pub/sh/current/styles/shCore.css' rel='stylesheet' type='text/css'/> 
<link href='http://alexgorbatchev.com/pub/sh/current/styles/shThemeDefault.css' rel='stylesheet' type='text/css'/> 
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shCore.js' type='text/javascript'></script> 
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushCpp.js' type='text/javascript'></script> 
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushCSharp.js' type='text/javascript'></script> 
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushCss.js' type='text/javascript'></script> 
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushJava.js' type='text/javascript'></script> 
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushJScript.js' type='text/javascript'></script> 
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushPhp.js' type='text/javascript'></script> 
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushPython.js' type='text/javascript'></script> 
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushRuby.js' type='text/javascript'></script> 
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushSql.js' type='text/javascript'></script> 
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushVb.js' type='text/javascript'></script> 
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushXml.js' type='text/javascript'></script> 
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushPerl.js' type='text/javascript'></script> 
<script language='javascript'> 
SyntaxHighlighter.config.bloggerMode = true;
SyntaxHighlighter.config.clipboardSwf = 'http://alexgorbatchev.com/pub/sh/current/scripts/clipboard.swf';
SyntaxHighlighter.all();
</script>

android - What is the default audio stream of TTS? - Stack Overflow

android - What is the default audio stream of TTS? - Stack Overflow:

params.put(TextToSpeech.Engine.KEY_PARAM_STREAM, String.valueOf(AudioManager.STREAM_ALARM));

jeudi 13 septembre 2012

java - System.currentTimeMillis vs System.nanoTime - Stack Overflow

java - System.currentTimeMillis vs System.nanoTime - Stack Overflow:

For example, to measure how long some code takes to execute:

long startTime = System.nanoTime();
// ... the code being measured ...
long estimatedTime = System.nanoTime() - startTime;

vendredi 7 septembre 2012

audio - Change Media volume in Android? - Stack Overflow

audio - Change Media volume in Android? - Stack Overflow:

private AudioManager audio;

Inside onCreate:

audio = (AudioManager) getSystemService(Context.AUDIO_SERVICE);

Override onKeyDown:

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
     switch (keyCode) {
          case KeyEvent.KEYCODE_VOLUME_UP:
                audio.adjustStreamVolume(AudioManager.STREAM_MUSIC,
                                   AudioManager.ADJUST_RAISE, AudioManager.FLAG_SHOW_UI);
                return true;
          case KeyEvent.KEYCODE_VOLUME_DOWN:
                audio.adjustStreamVolume(AudioManager.STREAM_MUSIC,
                                   AudioManager.ADJUST_LOWER, AudioManager.FLAG_SHOW_UI);
                return true;
          default:
                return super.onKeyDown(keyCode, event);
      }
}