Wednesday, May 23, 2012

android copy folders from assets to internal device app data folder

I created two folders inside assets ("images" and "files") both containing some files. I need to copy it when first launch to data/data/com.relatedPackage.myApp keeping same name and same file contents. I am an iOS programmer and that os does not allow to copy whole folders so, in android, which is the proper method to do it?



Possible to copy whole folder "images" (including its files) from assets to data/...? That would be great.
If not, should I create first empty folders using same names at data/... and then copy files from assets to current? In this case would be necessary to list all files inside folders in order to copy to data/...? Thank you.





Make text height 100% of div?

I'm trying to make the text 100% height of a div but it doesn't work. It just becomes 100% of the body { font-size:?; }. Is there any way to make it follow the div height?
The div height is 4% of the whole page and I wan't the text to follow it when you rezise/change resolution.



best regards,
Daniel





Serving different XML content on the same web

I don't know if this is the suitable place to ask this question, so I am sorry if I am doing it wrong. I think this is not a duplicate question. If it is, I am sorry too.



Currently, I have a web app which takes its content from a unique XML document. The URL is "http://webapp.com/"



The problem is that now I have to create a second version of the web which uses a new different XML document, so I have to put them different URLs, something like the following:



http://webapp.com/activities

http://webapp.com/stages



How can I have all my sources on just one directory on server-side (I suppose it's better to maintain, the resources are cached better, etc...) but with these 2 URLs pointing to the folder and making the PHP loades the XML depending on the URL?



I suppose I have to change the .htaccess file to redirect to that folder, but how can I tell what XML I must load? And the user must see on the search bar the URL he used, for example "http://webapp.com/activities"



Can anybody help me please?
Thanks for all





How to press back button in android programatically?

I my app i have a logout functionality. If user clicks logout it goes to home screen.Now i am exiting my app by pressing back button. But what i want is i need to exit automatically(i.e Programatically) as same like as back button functionality. I know by calling finish() will do the functionality. But the thing is it goes to the previous activity.



Thanks for your help guys





Spring @Transactional does not work in JUnit test?

I am using Spring 3.2 and JUnit 4.



My Dao class is as follows:



@Transactional public class SomeDaoImpl implements SomeDao {



The update operations on this work if executed directly from web application. However, I am seeing that junit integration tests that exercise the update methods do not actually persist the changes. Is something rolling the transactions back when junit methods are executed?





Best practices for API backwards compatibility

I'm working on an iPhone/iPad/Android app which communicates with a JSON API.



The first release of the version of the app is complete, and now additional phases of development are taking place. In the additional phases, the app needs to integrate with a new version of the API and allow the user access to additional features such as new screens or modified behaviour within existing screens. The app does however need to be backwards with previous versions of the API.



What is the best practice for tackling such a requirement?
I could of could do checks throughout the code:



if (APIVersion == 1) {

} else if (APIVersion == 2) {

} else if (APIVersion == ....) {

}...


But I'm concerned about the scalability of this approach.
The factory method comes to mind but I'm not sure how far this would get me.



Thanks,
Mark





array variable in awk

A=(aaa bbb ccc)    
cat abc.txt | awk '{ print $1, ${A[$1]} }'


I want to index an array element based on the $1, but the code above is not correct in awk syntax. Could someone help? Thanks!





Extension method in where clause in linq to Entities

In linq to Entities we needed a method that works like "sql like". We have implemented our own extension method to IQueryable, because contains method not work for us because doesn't accept patterns like '%a%b%'



The created code is:



private const char WildcardCharacter = '%';

public static IQueryable<TSource> WhereLike<TSource>(this IQueryable<TSource> _source, Expression<Func<TSource, string>> _valueSelector, string _textSearch)
{
if (_valueSelector == null)
{
throw new ArgumentNullException("valueSelector");
}

return _source.Where(BuildLikeExpressionWithWildcards(_valueSelector, _textSearch));
}

private static Expression<Func<TSource, bool>> BuildLikeExpressionWithWildcards<TSource>(Expression<Func<TSource, string>> _valueSelector, string _textToSearch)
{
var method = GetPatIndexMethod();

var body = Expression.Call(method, Expression.Constant(WildcardCharacter + _textToSearch + WildcardCharacter), _valueSelector.Body);

var parameter = _valueSelector.Parameters.Single();
UnaryExpression expressionConvert = Expression.Convert(Expression.Constant(0), typeof(int?));
return Expression.Lambda<Func<TSource, bool>> (Expression.GreaterThan(body, expressionConvert), parameter);
}

private static MethodInfo GetPatIndexMethod()
{
var methodName = "PatIndex";

Type stringType = typeof(SqlFunctions);
return stringType.GetMethod(methodName);
}


This works correctly and the code is executed entirely in SqlServer, but now we would use this extension method inside where clause as:



myDBContext.MyObject.Where(o => o.Description.Like(patternToSearch) || o.Title.Like(patterToSerch));


The problem is that the methods used in the where clause have to return a bool result if is it used with operators like '||' , and I don't know how to make that the code I have created returns a bool and keep the code executed in sqlserver. I suppose that I have to convert the returned Expression by BuildLinqExpression method to bool, but I don't know how to do it



To sum up! First of all it's possible to create our own extensiond methods in Linq to Entities that execute the code in SqlServer? if this is possible how I have to do it?



Thanks for your help.





Post JSON to Python CGI

I am looking to post JSON sent by any standard library such as 'JQUERY' using the standard.



$.ajax() post routine with my JSON.



can you tell me if on the page I post to ("saveList.py") this code is correct that will get the resultant json and then return the response as successful.



cheers, I've only ever worked with Django and now raw cgi so im slightly confused.



#!/usr/bin/env python
# -*- coding: UTF-8 -*-

import sys
import json

def get():
result = {'success':'true','message':'The Command Completed Successfully'}
data = sys.stdin.read()
myjson = json.loads(data)

self.response.out.write(str(result))




show 1 insted of 01 with PHP pack for Persian numbers

there is a function for converting English standard nums to Persian (Farsi) or Arabic nums:




function farsinum($str){ if (strlen($str) == 1){
$str = "0".$str; $out = ""; for ($i = 0; $i < strlen($str); ++$i) {
$c = substr($str, $i, 1);
$out .= pack("C*", 0xDB, 0xB0 + $c); } } return $out; }




but this function produce 01 02 03 ... insted of 1 2 3 ...
i think something must be change here:




$out .= pack("C*", 0xDB, 0xB0 + $c);




any help appreciated.





Confusion in int conversion of a string in PHP

I am unable to get the exact value of $data, which I converted into integer from this,



<?php

$data = '9999999999';
echo $datan = (int) $data;

?>


How can I get the exact value of $data from $datan?





Unable to use ActionBarSherlock library

I have Created a new android project from existing source(ActionBarSherlock library) with API 15. I added this library to my project(Project properties -> android -> library-> add ->com_actionbarsherlock ->apply ->ok).But When I again see (Project properties -> android -> library->) com_actionbarsherlock is showing red color cross.So, I am unable to import the library classes.I am really struggling with this.
Any help would be appreciate.Screen Shot When I add library
Screen Shot After library is added





Python script - How to set the right server, when I perform request/open of application

Python 3.2.2, I want to check HTTP status code (eg. 200 or 404) on some www application.



There are five servers and each server have a copy of this www application



(The user is automatically redirected to the application on the server with low traffic/sometimes on random server).



Suppose that the name of servers is: 0,1,2,3,4



I tried various options i have tried, three of them I pasted below (they works -always return 200, but choose not this server what I want):



1



import urllib.request,urllib.parse, http.cookiejar
values2= {"server":"2"}
data2 = urllib.parse.urlencode(values2)
data2 = data2.encode("utf-8")
request2 = urllib.request.Request(url,data2)
cj2 = http.cookiejar.CookieJar()
cj2.add_cookie_header(request2)
urlOpener2 = urllib.request.build_opener(urllib.request.HTTPCookieProcessor(cj2))
url2 = urlOpener2.open(request2)
x2 = url2.getcode()


2



import urllib.request
headers1 = {"Set-Cookie":"server=2"}
req1 = urllib.request.Request(url, None, headers1)
t1 = urllib.request.urlopen(req1)
coderesp1 = t1.getcode()


3



import urllib.request
urlOpener3 = urllib.request.build_opener()
urlOpener3.addheaders.append(("Set-Cookie", "server=2"))
url3 = urlOpener3.open(url)
x3 = url3.getcode()


If you have some questions about my problem, please write, I will immediately reply to what you want to know.





Android bitmap out of memory error

I get the famous out of memory error. But i have tried many of the suggested solutions on this problem without any luck. I understand that to prevent a bitmap to exceed the memory, you make a static variable of the drawable (Android docs). But that isn't working in my app because i have so many markers as you can see..



Does anyone have a suggestion to a solution?



for(Poi p : poiarray){

WeakReference<Bitmap> bitmap = new WeakReference<Bitmap>(p.get_poiIcon());
if(bitmap!=null){

Drawable marker = new BitmapDrawable(Bitmap.createScaledBitmap(bitmap.get(), 60, 60, true));
annotationOverLays.add(new CustomAnnotation(marker,p,this,mapView));
//mapView.getOverlays().add(new CustomAnnotation(marker,p,this,mapView));
}
}
mapView.getOverlays().addAll(annotationOverLays);


ERROR:



05-23 13:08:31.436: E/dalvikvm-heap(22310): 20736-byte external allocation too large for this process.
05-23 13:08:31.436: E/dalvikvm(22310): Out of memory: Heap Size=23111KB, Allocated=22474KB, Bitmap Size=1505KB
05-23 13:08:31.436: E/GraphicsJNI(22310): VM won't let us allocate 20736 bytes




Sending JSON through GET Method in Objective-C

I have a seemingly easy question. I'm trying to send data from my iPad device to a server using JSON. The thing is, all tutorials I see about sending JSON to the server uses the POST method. My question is, is it possible to send JSON using the GET method? It will be really helpful if you can give me some pointers on how to do it. Thanks.





Defining JQuery Function

The two below functions work as scripted except for when i add the Function next () {;} and function prev () {'} around it to define the custom function.



What am I doing wrong here?



function next() {

$('#up').click(function() {
$("#two").prev().animate({height:'80%'}, 500);
});
;}


function prev() {
$('#down').click(function() {
$("#two").next().animate({height:'80%'}, 500);
});
;}




Regarding Map pin points that should display dynamically in iphone

hi everyone i have a mapview where i have to drop pins on the map based on latitude and longitude where i used to get that from a webservice can any one help me out how to get and plot it on the map





move the focus from textbox to ajax combobox on enter key

I want to move the focus from the textbox to an ajax combobox on enter key



 <script type="text/javascript">
$(document).ready(function () {
$("#txtGroupSname").keydown(checkForEnter);
function checkForEnter(event) {

if (event.keyCode == 13) {
document.getElementById("cmbUnder").focus();
return false;
//$("#cmbUnder").focus();
}
}
});




txtGroupSname is my textbox and cmbUnder is the ajax combobox.



Any ideas or suggestions please.
Thanks,





Is it possible to generate XML file in gef

Is it possible to generate XML file from Shape example in GEF,Same as its getting generated in GMF?
Like in GMF if we select GMF Design page and open it with XML file,it provides all external information about model figures,same like i want to generate with GEF.





How to change the comment link text "Login or register to post comment" to be shorter eg " comment" in drupal


  1. I have created a Q&A type using
    Create Content in drupal.


  2. I have created a new content name
    Ask and Answer.


  3. Until this i don't have any issues.
    Now problem is i have enabled
    comments in content type.


  4. In this case i need to change the
    "Add new comment" or similar links
    related to comments as "Answer"
    without changing the core comment
    module.


  5. How can i do this?




Thanks in advance.