dimanche 21 septembre 2014

Get ImageView bitmap


Bitmap bitmap = ((BitmapDrawable)image.getDrawable()).getBitmap();
Be carefull to check if your image.getDrawable() can actually be cast to BitmapDrawable (to avoid ClassCastExceptions). 
If, for instance, you use layers in your image then this snippet will be slightly different: Bitmap bitmap = ((BitmapDrawable)((LayerDrawable)image.getDrawable()).getDrawable(0)).getBitmap(‌​);
http://stackoverflow.com/questions/8306623/get-bitmap-attached-to-imageview

samedi 13 septembre 2014

Manage audio volume in my app

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 false;
    }
}

jeudi 28 août 2014

PS: Enregistrement d’une image comme motif prédéfini


  1. Utilisez l’outil Rectangle de sélection  sur une image ouverte pour sélectionner une zone à utiliser comme motif. La valeur du contour progressif doit être de 0 pixel. Notez que les grandes images peuvent devenir difficiles à manier.

  2. Choisissez Edition > Utiliser comme motif.

  3. Donnez un nom au motif dans la boîte de dialogue Nom du motif.
    Remarque :
    si vous utilisez un motif provenant d’une image et que vous l’appliquez à une autre, Photoshop convertit le mode colorimétrique.

lundi 11 août 2014

Java copy-constructors

/**
  * Regular constructor.
  */
  public Galaxy(double aMass, String aName) {
    fMass = aMass;
    fName = aName;
  }

  /**
  * Copy constructor.
  */
  public Galaxy(Galaxy aGalaxy) {
    this(aGalaxy.getMass(), aGalaxy.getName());
    //no defensive copies are created here, since 
    //there are no mutable object fields (String is immutable)
  }

  /**
  * Alternative style for a copy constructor, using a static newInstance
  * method.
  */
  public static Galaxy newInstance(Galaxy aGalaxy) {
    return new Galaxy(aGalaxy.getMass(), aGalaxy.getName());
  }

(from http://www.javapractices.com/topic/TopicAction.do?Id=12)

mercredi 16 juillet 2014

Google Play Services not running on Froyo 2.2 and below

Google Mobile Ads is now offered through Google Play Services 4.0 and this error occurs because the Google Play Services is not available. Most likely you will run into this on Froyo, where there is a special version that can be used.
Note: Google Play services 4.0.30 (released November 2013) and newer versions require Android 2.3 or higher. If your app supports Android 2.2, you can continue development with the Google Play services SDK, but must instead install Google Play services for Froyo from the SDK Manager.
http:// android-developers.blogspot.no/2013/10/google-play-services-40.html
With over 97% of devices now running Android 2.3 (Gingerbread) or newer platform versions, we’re dropping support for Froyo from this release of the Google Play services SDK in order to make it possible to offer more powerful APIs in the future. That means you will not be able to utilize these new APIs on devices running Android 2.2 (Froyo).
Important: Because it is hard to anticipate the state of each device, you must always check for a compatible Google Play services APK before you access Google Play services features. For many apps, the best time to check is during the onResume() method of the main activity.
Alernative 1 is to check if Google Play Services is available before using AdView.
int status = GooglePlayServicesUtil.isGooglePlayServicesAvailable(getApplicationContext();
if(status == ConnectionResult.SUCCESS) {
    //Success! Do what you want
}
Alernative 2 is to use GoogleAdMobAdsSdk-6.4.1.jar
There are at least two solutions to solve the problem:
  • Change the minSdkVersion in your app's manifest to 9.
  • Don't use the latest Google Play Services library, but use the Froyo version in stead.
or

There is a third solution: guard the code that requires new functionality in Google Play Services (such as Admob ads) with a if (android.os.Build.VERSION.SDK_INT > android.os.Build.VERSION_CODES.FROYO)

samedi 12 juillet 2014

Adding Google Play Services via IntelliJ

This was successfully tested with Google Play Services v18 & IntelliJ 13:

You need to have a copy (as opposed to using it directly from the SDK folder), because if Google updates it, things are going to break when you update your SDK, it's safer to keep a copy (albeit more tedious because you will have to manually update when a new version comes out). I found out that it's better to decide when to update than to be surprised with cryptic compilation errors.
With that in mind, copy the library alongside your project. The library is located in
"ANDROID-SDK"/extras/google/google_play_services/libproject/google-play-services_lib
ANDROID-SDK is wherever you stored the SDK when you downloaded it. Google changes this every now and then, so just find it, it will be there.
Copy that entire folder like this:
/mylibpath/google-play-services_lib/ <-- THIS IS THE NEW ONE
Good, now let's import it to IntelliJ-IDEA the right way:
1) Select your project/main module from project panel (⌘ 1) and hit ⌘ ↓ in order to open project structure window or just do File -> Project Structure.
2) Select Modules from left panel, then hit + button (or ⌘ N) then select "import module" and navigate to the google-play-services_lib that you just copied next to your project's module folder. (/mylibpath/).
The wizard will ask a series of questions, just hit next, defaults are fine, but read what's going on, understand what's happening, this is a core concept in Java, Android and Intellij. Experiment if you don't know what each dialog is saying (or why some may be empty).
After you're done, the google play Project will be added to Modules alongside with your project.
Don't close this window (or open it again if you did).
3) Still in the modules, select your project/module, then select "Dependencies" from right panel (it's atab) and finally Click + button at the bottom (or ⌘ N which will work if you have the focus in this tab), then from the popup chose "3 Module dependencies..." and select "google-play-services_lib", which you added in the previous step. It should be there. If it's not, you didn't add the module in step 2.
4) Finally, Click + button again (or ⌘ N) but this time select "1 jars or directories...", navigate to the "/libs" folder of the above path and select "google-play-services.jar".
5) Click ok and close project structure window.
If you did this, your main module should have a dependency that looks like this:
Dependencies
Also make sure that in the Project Structure window, FACETS Tab, the Google Play Services has the "Library Module" checked. It is a library module.
Note: Make sure you have not added "google-play-services_lib" project as library in "Libraries" (left panel under Modules). If you have, you can go to "Libraries and simply remove it. Google Play Library Should Not Appear In Libraries.
Credit: this text comes from this StackOverflow answer

jeudi 4 avril 2013

PS: Copy items from multiple layers at a time | creativebits™

Copy items from multiple layers at a time | creativebits™:
Copy items from multiple layers at a time
JimD (2623 pencils) | Tue, 2005-01-25 00:33 Photoshop

You can copy items from multiple layers at a time in Photoshop by simply adding the Shift key to Command+C or selecting Copy from the Edit menu. Now when you paste, it will give you results as if you had flattened all your layers before making the copy command.

vendredi 28 décembre 2012

./bbwp ~/Work/Temp/BB10_output/myapp.zip -g keyStorePass -p params.json --buildId 2 -o ~/Work/Projects/myapp/out/ -v params.json is the KEY to success ;) { "blackberry-signer": { "-cskpass": "cksPassword" } }

jeudi 13 décembre 2012

Problems signing a BB10 WebWorks Application - BlackBerry Support Community Forums

Problems signing a BB10 WebWorks Application - BlackBerry Support Community Forums:

The problem lies in the fact that my keystore and csk passwords are different and bbwp is expecting them to be the same (which it doesn't do for the playbook). If I created new keys I would use the same for both.

Anyhow I have found a solution and that is to use the -p parameter:

bbwp c:\myapp\myarchive.zip -g mykeystorepassword -p params.json -o c:\myapp\output

The csk password is specified in the params.json file thus:

{
    "blackberry-signer": {
        "-cskpass": "mycskpassword"
    }
}

Thanks everyone for your input.

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);
      }
}