on Sunday, August 31, 2014


How does Media.release() work. Looking at the docs it feels that you have to use it like this:



MediaService.loadMedia('sounds/connection-error.wav').then(function(media){
media.play();
media.release();
});


But I googled enough to know that is wrong. We have to explicitly release the core instances on Android.


But how to do that? If I have 8 views in my app and if I play a sound file on each of those views does that count as 8 core instances being used? And can I go back to say view number 1 and again play the sound associated with that view? If so, would that count as a 9th instances ?


Straight away calling media.release() just like above does not play any sound at all.




I have a problem changing the background color randomly: first I try to use parseColor In the Colorclass:


public class Colors {



public String[] colors = {
"#39add1", // light blue
"#3079ab", // dark blue
"#c25975" // mauve
};

public int getcolor() {
Random randomGenerator = new Random();
String color = "";

int randomNumber = randomGenerator.nextInt(3);

color = colors[randomNumber];
int colorAsInt = Color.parseColor(color);
return colorAsInt;
}


}


And in the Activity class:



View.OnClickListener listener = new View.OnClickListener() {
@Override
public void onClick(View view) {
int color = mColors.getcolor();
relativeLayout.setBackgroundColor(color);





}
};


It works perfectly: but when I try to use String for return type of getcolor and use parse int in the activity class , when i run the app it gives me an error :Unfortunately app has stopped.


the color class:



public String getcolor() {
Random randomGenerator = new Random();
String color = "";

int randomNumber = randomGenerator.nextInt(3);

color = colors[randomNumber];
return color;
}


And the activity class:



View.OnClickListener listener = new View.OnClickListener() {
@Override
public void onClick(View view) {
String color = mColors.getcolor();
relativeLayout.setBackgroundColor(Integer.parseInt(color));





}
};


why this problem happens?




I'm getting a NoClassDefFoundError for a class that exists in my Android App. I'm building with maven and the class that can't be found is LruBitmapCache.java, an implementation of the Volley ImageCache which I have written inside my android project:



public class LruBitmapCache extends LruCache<String, Bitmap> implements ImageCache
{
public static int getDefaultLruCacheSize()
{
final int maxMemory = (int) (Runtime.getRuntime().maxMemory() / 1024);
final int cacheSize = maxMemory / 8;

return cacheSize;
}

public LruBitmapCache()
{
this(getDefaultLruCacheSize());
}

public LruBitmapCache(int sizeInKiloBytes)
{
super(sizeInKiloBytes);
}

@Override
protected int sizeOf(String key, Bitmap value)
{
return value.getRowBytes() * value.getHeight() / 1024;
}

@Override
public Bitmap getBitmap(String url)
{
return get(url);
}

@Override
public void putBitmap(String url, Bitmap bitmap)
{
put(url, bitmap);
}
}


My pom.xml is as follows



<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<groupId>com.x.y</groupId>
<artifactId>parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../../parent</relativePath>
</parent>

<modelVersion>4.0.0</modelVersion>
<artifactId>android-project</artifactId>
<packaging>apk</packaging>

<build>
<plugins>
<plugin>
<groupId>com.jayway.maven.plugins.android.generation2</groupId>
<artifactId>android-maven-plugin</artifactId>
<version>3.8.2</version>
<configuration>
<sdk>
<platform>19</platform>
</sdk>
<deleteConflictingFiles>true</deleteConflictingFiles>
<undeployBeforeDeploy>false</undeployBeforeDeploy>
<device>usb</device>
</configuration>
<extensions>true</extensions>
</plugin>

<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
</build>

<dependencies>
<dependency>
<groupId>android</groupId>
<artifactId>android</artifactId>
<version>4.4.2_r3</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>com.google.android</groupId>
<artifactId>support-v4</artifactId>
<version>r7</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.1</version>
</dependency>

<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-mapper-asl</artifactId>
<version>1.9.12</version>
</dependency>

<dependency>
<groupId>com.googlecode.androidannotations</groupId>
<artifactId>androidannotations</artifactId>
<version>2.7.1</version>
</dependency>

<dependency>
<groupId>com.mcxiaoke.volley</groupId>
<artifactId>library</artifactId>
<version>1.0.6</version>
</dependency>

<dependency>
<groupId>fr.avianey</groupId>
<artifactId>facebook-android-api</artifactId>
<version>3.17.1</version>
</dependency>

<dependency>
<groupId>org.twitter4j</groupId>
<artifactId>twitter4j-core</artifactId>
<version>4.0.2</version>
</dependency>

</dependencies>
</project>


I'm building and deploying the app with "mvn install android:deploy", which successfully deploys the app to the device, but when I try and open the application I get the NoClassDefFoundError (since some application code attempts to initialize the LruBitmapCache). I had assumed it might have been because the Volley dependency wasn't being included in the classes, but I'm not 100% sure how the dex classes work. Does anyone have any idea why this could be happening or has anyone had this before? Faulty classes? Dependency conflict? Any help is appreciated.




I have a slide menu in my app and its work very good but i have a list view in slide menu only work in MainActivity and it is not work in other Activities but i copy all of codes about slide menu from MainActivity and it is same with other activities but OnItemClickListener Only work in MainActivity. Here is codes:



slidelist.setOnItemClickListener(new OnItemClickListener(){

@Override
public void onItemClick(AdapterView<?> parent, View view, int position,
long id) {
switch(position){
case 0:
DL.closeDrawers();
break;
case 1:
startActivity(new Intent(MainActivity.this, Settings.class));
finish();
break;
case 2:
startActivity(new Intent(MainActivity.this, Email.class));
break;
case 3:
Intent goToMarket = new Intent(Intent.ACTION_VIEW)
.setData(Uri.parse("http://cafebazaar.ir/app/com.seyedmehdi.scarystories/?l=fa"));
startActivity(goToMarket);
break;
case 4:
startActivity(new Intent(MainActivity.this, Manba.class));
break;
default:
break;
}

}
});


Please help. Sorry from my bad English.




When I try this:



map.put("password1", Base64.encode("111111".getBytes(),Base64.DEFAULT));
map.put("password2", Base64.encode("111111".getBytes(),Base64.DEFAULT));
map.put("password3", Base64.encode("111111".getBytes(),Base64.DEFAULT));


I got different value of password1,password2 and password3:


password1:[B@5368aecc


password2:[B@536e9ea0


password3:[B@536c0dec


Is it should be the same value? Thanks in advance.


on Saturday, August 30, 2014


I have to do a very laborious task on a regular basis and am looking for a way to automate the process. I have to Clone 2 git repos, open in eclipse, add one repo as a dependency of the other,c hange package names, refactor, replace the res folder with another and build. I want to write a script or something that will automate the whole process. Is this possible? If so where do I start?





restartLoader(0, data, this);


while using restartLoader like above I got an error:



The method restartLoader(int, Bundle, LoaderManager.LoaderCallbacks) in the type LoaderManager is not applicable for the arguments (int, Bundle, MainActivity).



Here is my code:



private void doSearch(String query){
Bundle data = new Bundle();
data.putString("query", query);
getSupportLoaderManager().restartLoader(0, data, this);
}

private void getPlace(String query){
Bundle data = new Bundle();
data.putString("query", query);
getSupportLoaderManager().restartLoader(1, data, this);
}