Categories
discuss

Android VM crashes on Launch Mac

I have a problem. I’ve been working with Android in Eclipse for the past 4-5 weeks now and never had a problem with the VM (they were slow, yes. But never crashed).

Now, I believe since 4.2 when I started working on a new project for uni (deadline next week) my 4.2 VM suddently starts crashing on launch, because of “Kernel Panic” (resport at the end).

I wanted to ask if there is anything I could do, maybe download a hotfix or anything. Both the API and Eclipse are pretty much up to date or might there be something wrong with my computer? (Somehow even my old VMs (2.3.3, 3.1 and 4.1) crash on launch 99% of the time)

Any advice would be highly appreciated. Here the beginning of the Crash-Log:

Process: emulator64-arm [1334] Path:
/Users/USER/*/emulator64-arm Identifier: emulator64-arm Version: ??? Code Type: X86-64 (Native) Parent Process: eclipse [1156] User ID: 501

Date/Time: 2012-12-01 00:25:27.469 +0100 OS Version: Mac OS X 10.8.2 (12C2034) Report Version: 10

Interval Since Last Report: 130686 sec Crashes Since Last Report: 96 Per-App Crashes Since Last Report: 32 Anonymous UUID: ABE51F99-F7A9-2595-016E-C47FFD1F6C50

Crashed Thread: 0 Dispatch queue: com.apple.main-thread

Exception Type: EXC_BAD_ACCESS (SIGSEGV) Exception Codes: KERN_INVALID_ADDRESS at 0x0000000000000000

VM Regions Near 0: –> __TEXT 0000000100000000-0000000100247000 [ 2332K] r-x/rwx SM=COW /Users/USER/*

Thread 0 Crashed:: Dispatch queue: com.apple.main-thread

Answer

Do you have two screens? if yes, did you launch avd/vm on secondary screen last time? If yes, then check config vm file at:

cd ~/.android/avd/  
ls -la   => here you see all avds
cd [your_vm.avd]
joe emulator-user.ini => edit this config file and see value 

window.x = 2054 – this is stupid value, cause says where to display emulator window. Value is set cause emulator window was displayed at second screen on x position 2054 but as I say it’s bug at avd. Simply change it to better value to display window at your main screen so like my case:

window.x = 954
window.y = 199
uuid = 1342941165631

Save config file, start eclipse, start your avd/vm and all must run well.

Categories
discuss

Difference between ‘this’ , ‘activityname.this’ and getAplicationContext()

I dont know difference between them, I sometimes use this, sometimes activityame.this, sometimes getAplicationContext() when android needs context passed.

Answer

  • this points to the current object. In this case, an Activity Object
  • ActivityName.this also points to the current Activity Object, use it when you are working with an dynamic inner class, such as instantiating a new onClickListener() {}.
  • getApplicationContext() gets the Context reference for the whole application. Activity is a Context subclass, but certain things may vary between the appliation Context and the Activity. For the most part though, using the Activity as the Context works fine, I haven’t coded anything that needs getApplicationContext() yet.
Categories
discuss

Spring application showing server time instead of client time

Here is my code:

@RequestMapping(value="/test", method=RequestMethod.GET)
public @ResponseBody String test(HttpServletRequest request) {
    Calendar calendar = new GregorianCalendar(request.getLocale());
    String currentTime = calendar.getTime().toString();
    return"Current Time: " + currentTime;
}

This is showing me this time:

Current Time: Fri Nov 30 22:45:42 UTC 2012

I am in the central time zone, so it should be showing me this:

Current Time: Fri Nov 30 14:45:42 CST 2012

Why am I getting the server time instead of the client time?

Answer

Your code executes on server irrespective where your client is. On server you will setup timezone for that machine, which will be used to calculate time. when you call calendar.getTime() this timezone will be used.

If you want client time zone, you need to send it and use something SimpleDateFormat to convert server time to client timezone.

Categories
discuss

PorterDuffXfermode DST_IN not working as expected

So I’m trying to speed up some drawing we’re doing (drawing a portion of an arc with alpha transparency) and was attempting to cache the entire arc into a separate bitmap, and show it selectively with an alpha mask.

From the research I’ve done (the Xfermodes API demo for Android, this example, and this tool), if I have for example the following two graphics:

enter image description here

enter image description here

and draw using the following:

Xfermode DST_IN = new PorterDuffXfermode(PorterDuff.Mode.DST_IN);
Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);

canvas.drawBitmap(circle, 0, 0, paint);
paint.setXfermode(DST_IN);
canvas.drawBitmap(arc, 0, 0, paint);
paint.setXfermode(null);

I should get this result:

enter image description here

Where the destination image (the circle) is clipped to the area where the source image (the arc) is drawn. Instead, I get the full circle. If I just draw the arc, it appears in the correct location, and if I use DST_OUT instead, I get the inverse of the expected result (the other three quadrants of the circle).

I’ve also made sure to disable hardware rendering for this view, in case there was an issue with this Xfermode, but it doesn’t make a difference.

I broke it out into a separate project at the simplest level trying to get it to work, and using the following code, I still have the same problem:

public class ClippedView extends View {
    private Xfermode DST_IN, DST_OUT;
    private Paint paint;

    public ClippedView(Context context) {
        super(context);
        init();
    }

    private void init() {
        setLayoutParams(new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
        this.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
        paint = new Paint(Paint.ANTI_ALIAS_FLAG);
        DST_IN = new PorterDuffXfermode(PorterDuff.Mode.DST_IN);
        DST_OUT = new PorterDuffXfermode(PorterDuff.Mode.DST_OUT);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        paint.setColor(Color.GREEN);
        canvas.drawRect(0, 0, getWidth() / 2, getHeight() / 2, paint);
        paint.setColor(Color.BLACK);
        paint.setXfermode(DST_IN);
        canvas.drawCircle(getWidth() / 2, getHeight() / 2, getWidth() / 2, paint);
        paint.setXfermode(null);
    }
}

Am I using it wrong? Am I just missing something? Have I found a bug? 🙂

Answer

There’s a much cheaper and easier way to achieve this: use clipping. Canvas.clipRect() is enough. Your solution is burning a lot of fillrate. You can get the effect you want by using SRC_IN instead of DST_IN. Be careful though: it will work only in a transparent Bitmap or in layer. When you draw directly on screen, the destination is already filled by the window background.

Categories
discuss

How to delete an item using REST for Sharepoint 2013

I’m creating a Sharepoint App and i am restricted to using Javascript (jQuery included) and REST endpoints. I would like to delete an item from the host using the web app, but i’m getting an error (403: FORBIDDEN). This is the code i have so far:

executor = new SP.RequestExecutor(appweburl);
executor.executeAsync({
    url: appweburl + "/_api/SP.AppContextSite(@target)/web/lists/getbytitle('" + currentListTitle + "')/items(" + result.Id + ")/?@target='" + hostweburl + "'",
    method: "POST",
    headers: {
               "accept": "application/json",
               "X-RequestDigest": ?????
               "IF-MATCH": "*",
               "X-HTTP-Method": "DELETE"
             },
    success: onDeleteItemSuccess,
    error: onDeleteItemFail
});

Now I found out this X-RequestDigest is mandatory and i found some call to get this from REST:

$.ajax({
    url: appweburl + "/_api/SP.AppContextSite(@target)/contextinfo/?@target='" + hostweburl + "'",
    type: "POST",
    contentType: "application/x-www-url-encoded",
    dataType: "json",
    success: function (data) {
        if (data.d)
        {
            digestValue = data.d.GetContextWebInformation.FormDigestValue;
            alert(digestValue);
        }
    },
    error: function (xhr) {
        alert(xhr.status + ': ' + xhr.statusText);
    }
});

But it isn’t working at all (this might be because this code was for Sharepoint 2010) and it will keep giving me a 403: FORBIDDEN message.

Does anyone know how to delete a list item from one of the lists using REST (I can’t use/edit any code outside of the javascript!)?

Any help is appriciated and if you need any information please don’t hesitate to ask.

Answer

The code can’t be for SharePoint 2010, as _api is new to SP 2013.

[Update] Maybe you mean that your code was working in SP 2013 preview? In SP2013 RTM you need to use:

"Accept": "application/json; odata=verbose"
Source: stackoverflow
Text is available under the Creative Commons Attribution-ShareAlike License; additional terms may apply. By using this site, you agree to the Privacy Policy, and Copyright Policy. Content is available under CC BY-SA 3.0 unless otherwise noted. The answers/resolutions are collected from stackoverflow, are licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0 © No Copyrights, All Questions are retrived from public domain..