Sony Smart Extras (Smartwatch) Keeping the screen on – controlling the screen state

May 18th, 2012

In the utils package there is a function that can be used to control the screen state.

    /**
     * Set the accessory screens state.
     *
     * @see Control.Intents#SCREEN_STATE_AUTO
     * @see Control.Intents#SCREEN_STATE_DIM
     * @see Control.Intents#SCREEN_STATE_OFF
     * @see Control.Intents#SCREEN_STATE_ON
     *
     * @param state The screen state.
     */
    protected void setScreenState(final int state) {
        if (Dbg.DEBUG) {
            Dbg.d("setScreenState: " + state);
        }
        Intent intent = new Intent(Control.Intents.CONTROL_SET_SCREEN_STATE_INTENT);
        intent.putExtra(Control.Intents.EXTRA_SCREEN_STATE, state);
        sendToHostApp(intent);
    }

So all we need to do in order to control the screen state is to call this with the correct screen state intent. The following example will keep the screen on

 setScreenState(Intents.SCREEN_STATE_ON);

Android: Rotate a bitmap

May 16th, 2012

Here is a small sample that will rotate a bitmap.

Bitmap animation = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.eye_rotate, mBitmapOptions);
 
Bitmap bitmap = Bitmap.createBitmap(animation.getWidth(), animation.getHeight(), BITMAP_CONFIG);
bitmap.setDensity(DisplayMetrics.DENSITY_DEFAULT);
 
Matrix matrix = new Matrix();
matrix.reset();
matrix.setTranslate(0, 0);
matrix.postRotate(updateAnimationRotateImage1Step, (animation.getWidth()/2), (animation.getHeight()/2));        	
 
Canvas canvas = new Canvas(bitmap);
Paint paint = new Paint();
int xPos = 0;
int yPos = 0;
Rect src = new Rect(xPos, yPos, xPos + animation.getWidth(), yPos + animation.getHeight());
Rect dst = new Rect(0, 0, animation.getWidth(), animation.getHeight());
 
canvas.drawBitmap(mBackground, src, dst, paint);
canvas.drawBitmap(animation, matrix, null);

Git, stop tracking a file, but keep it localy

May 14th, 2012

In order to stop tracking a file in git then rm is used – however this will delete the file from my local directory as well. The following will stop tracking the file, but keep it on my local computer.

git rm --cached path/filename

After this step, it is very likely that the file should be added to a .gitignore file;)

Kill all processes with a given name

April 27th, 2012

suppose we wish to kill all instances of rsync that is running
Simplest given that we know the process name

pkill rsync
ps aux|awk '/sleep/ {print "kill -9 " $1}'

Or a sligtly longer version that might(?) be more verbose as to what it does

kill -9 $(ps aux | grep '[r]sync' | awk '{print $2}')

un tar and ownership of the extracted files

April 25th, 2012

If the user extracting is a “ordinary” user, the files will be owned by that user (by default).
If the user extracting is a super user, then the files ownership will be preserved (by default).

Note: This is by default and can be overridden when needed:

From the manual page of tar:

--same-owner
       try extracting files with the same ownership as exists in the archive (default for superuser)
 
--no-same-owner
       extract files as yourself (default for ordinary users)

The 5 W’s of survival; W as in Worries that is

April 23rd, 2012

This is simply a list of things that you need to worry about when trying to survive.

  • Wood
  • Weather
  • Widdow makers
  • Wigglies (scorpions, spiders and all the creepy crawlies)
  • Water

Sony Smart Extras (Smartwatch) When using an .xml file to specify the layout of an accessory, remember the following

April 20th, 2012
  • All sizes should be expressed in px. This to avoid scaling based on the phone density.
  • If an ImageView is used to show an image, we recommend that you specify layout_width and layout_height in px to avoid scaling based on the phone density.

Note: This is since the phone density is based on the phone (or tablet) you have connected the smart extension to, not the smart extension itself.

Sony Smartwatch Accelerometer sensor when is a axis positive (witch side is up)?

April 18th, 2012

For the axis the values are:

  Positive value Negative value
x: The button is up The button is down
y: The Sony label is up The Sony label is down
z: The Screen is down The screen is up

Also a interesting thing to note, no matter how we all try to (when having the accelerometer using the SENSOR_STATUS_ACCURACY_HIGH) we can not get it to go past 78,15m/s^2.

Courage is facing the challenge with a healthy fear not being fearless!

April 16th, 2012

“The way to survival whether you’re the victim or the rescuer, is through the path of methodical caution a calming of the spirit, mind and careful planning of your every move. Courage is facing the challenge with a healthy fear not being fearless. More than anything else making it through a horrendous ordeal requires the will to live if you expect to survive.”
-Les Stroud. (Used as a voice over at the end of S3E1 Sierra Nevada when Les Stroud was “rescued”).

Converting a text to a curve

April 11th, 2012

If you intend to for instance laser cut a design that includes text make sure to convert it to curves before submitting it, to ensure the text looks as you designed it regardless of whether or not the cutter have the font.
The command is:
Ctrl + Q in CorelDRAW
Ctrl + Shift + C in Inkscape
Ctrl + Shift + O in Adobe Illustrator