Tuesday, September 8, 2015

How to change the background color of an NSView loaded from nib/xib in Swift

I have an NSWindow and in the UI designer I have set its top-level view to be a custom NSView type I created (class Canvas : NSView).




This worked for me in xcode 7/swift 2.0. In order to set its background color in code you need to override NSView's awakeFromNib() function as such:

import Cocoa

class Canvas : NSView {
    
    override func awakeFromNib() {
        self.layer?.backgroundColor = NSColor(calibratedRed: 1, green: 1, blue: 1, alpha: 1).CGColor //set background to white ( not sure if it should be called before parent func)
        super.awakeFromNib()
    }
}

@NSApplicationMain
class AppDelegate: NSObject, NSApplicationDelegate {
    
    @IBOutlet weak var canvas: Canvas!
    @IBOutlet weak var window: NSWindow!
    
    func applicationDidFinishLaunching(aNotification: NSNotification) {
    }
    
    func applicationWillTerminate(aNotification: NSNotification) {
        // Insert code here to tear down your application
    }
    
}


Monday, May 25, 2015

Remove the sim lock from the Samsung Galaxy S2 LTE SC-03D - Japan Docomo

When I did this I had stock 4.0.4 (SC03DOMMP5 / SC03DDCMMP5) flashed with ODIN from sammobile.com (you can do it with heimdall too I guess). *Very important* 

In order to sim unlock the SC-03D it is necessary to first flash a "special" radio. Flashing the radio is possible with a CWM based recovery. Get the latest version of CWM-recovery from this forum and flash it using ODIN/Heimdall:
http://android.slateblue.tk/viewtopic.php?f=20&t=73

Then get the radio to flash:
Official TMo ICS RADIO_NOTE.zip
(from this XDA thread:
http://forum.xda-developers.com/showpost.php?p=37564563)

This radio is from the Galaxy Note (SC-05D) so it made my phone very very slow. However, you need this radio because it has options to make the phone sim free. Options which the original SC-03D radio does not. As soon as you flash this new radio boot the phone, run the dialer application and dial:

*#9090#

it might be very slow but eventually you should get to the service menu.

To access more options press [menu] then [Input key]. Then into the text box type:

Q0   (Q Zero, not QOh)


It should bring you to another menu after a second or so. Select these options:


[1] DEBUG SCREEN
[8] PHONE CONTROL
[5] SIMULATION
[6] NETWORK LOCK
[3] PERSO SHA256 OFF
Wait for 30 seconds , press MENU then BACK.
Select:
[4] NW LOCK NV DATA INITIALLIZ


Wait 60 seconds. Reboot.

Congrats you're sim free. You should remain sim free no matter what radio/firmware/rom you flash.

partial credit to FAB
http://blogs.yahoo.co.jp/fab4_boys/26754215.html
And HomuHomu for the recovery.

Thursday, March 26, 2015

YMobile adventures

I have a contract from E-Mobile which is now known as Y!Mobile. Because my Nexus 5 got wet the other day and doesn't work anymore I needed to use their service in another phone. Since the Nexus 5 takes a micro sim whereas my 3G phone takes a mini sim, I asked them to simply change my sim card to a bigger size. They said that's not possible. That I must terminate my current contract and create a sim-only contract. Not possible? ok!

I took out the lab's 3D printer and printed a micro to mini sim adapter :)
























How to JailBreak the Samsung Galaxy S2 sc-02c Docomo Japan

I assume you have a stock SC-02C by docomo. If you don't, download the firmware from sammobile and flash with ODIN.

Then flash Siyah Kernel 5.0.1 for S2 with ODIN:
http://d-h.st/Bcf

Hold Home+Volume Up+Power to go into recovery mode. Wipe Data/System.
Reboot into your rooted SC-02c.

If you need to break the sim lock of the phone copy this apk to the phone and install it. It will remove the sim lock:

http://d-h.st/6EfJ

After you have ensured SU exists and have used some manager to remove the junk apps by docomo re-flash the original kernel by extracting the zImage from the samsung firmware tar file and flashing the kernel only (careful don't reflash the entire firmware because you'll end up doing everything from scratch).

Re-flashing the original kernel is important to get the GPS working, I couldn't get WjChen0's gps fix to work (by adding it under /etc/init.d)

Good luck.


Friday, June 20, 2014

Android ROTATION_VECTOR values different across devices

I recently changed from calculating the rotation matrix by myself on the host pc side, with accelerometer and magnetometer values, to Sensor type ROTATION_VECTOR and just converting that into a matrix on the host pc.

I've noticed something strange though. The sensor event array values are different between the LG Nexus 5 and the Samsung S2. So if the ROTATION_VECTOR values array on the Nexus is:


  • values[0] //x-axis
  • values[1] //y-axis
  • values[2] //z-axis


then on the S2 it's something like:


  • values[0] //x-axis
  • values[1] //z-axis
  • values[2] //y-axis


These are just random examples, I'm not exactly sure what the axes are, just saying that the order is not the same within the array across devices.


On the Samsung Galaxy S2 I have installed an omnirom with kitkat which isn't officially supported so I'm thinking that could be one of the causes.

Monday, September 2, 2013

PS Move with GLFW (tested only on Linux)

I recently discovered by accident that GLFW sees the ps move as a 28-axis joystick with 19 buttons. I don't think it would have worked unless I had first paired via usb cable the PS Move using Thomas Perl's psmoveapi. I will report more when I have more info. For now I've only tested it on Ubuntu 13.04 64-bit.

When I start my engine I query for which controller has 28 axes and I assign that GLFW_JOYSTICK_x to an int variable called moveController. Then I check using the following snippet:

void Engine::checkMove()
{
    float position[28];
    unsigned char buttons[19];
    std::fill_n(position,28,0.0f);

    if (glfwGetJoystickPos( moveController, position,28) == 28 ) {

        glfwGetJoystickButtons(moveController,buttons,19);

        // for loop limited to 16 because 16-17-18 seemed
        // to be always GLFW_PRESS for some reason
        for (int i=0;i < 16;++i) {                                      
            if (buttons[i] == GLFW_PRESS) {
                std::cout << "Button " << i <<  " pressed " <<std::endl;
            }
        }
    }

}

Thursday, May 9, 2013

Docomo sc-02c to Jelly Bean 4.2.2 (Cyanogenmod 10.1)

I recently updated my Docomo Samsung Galaxy S2 (sc-02c) to Android 4.2.2 Jelly Bean. Use the following information at your own risk!

From KBC developers:
https://github.com/kbc-developers/release/wiki/Sc02c

[Kernel] Android 4.2.x Jellybeans for AOSP ROM by sakuramilkI flashed it using Odin3 1.85 on Windows 7.

Following the kernel flash I booted with power+home+up to go into CWM recovery. After I backed up the existing rom I did a wipe-factory-reset.

Then I applied [ROM] CyanogenMod10.1 JP Remix for SC-02C (which I'd already put in the sdcard)
And finally 20121212 gapps from http://goo.im/

Any questions plz leave a comment.