jeudi 1 mai 2014

not running on android 2.3.1 gingerbread


Vote count:

0




Hi i have developed an app that combines drawables by creating bitmap and laying on top of it. It is working in other devices but when i tested it on a specific device. an android 2.3.1 600x1024 device Here's a link of the device. it crashes 100% of the time.



package com.wayfinder.wayfinder;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.StringReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import org.xml.sax.InputSource;
import org.xml.sax.XMLReader;
import android.os.Bundle;
import android.os.Environment;
import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Typeface;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Adapter;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

public class ImageMap extends Activity {
Bitmap img1,img2,img3;
ImageView home;
ProgressDialog dialog;
ListAdapter adapter = null;
private ListView listView1;
final ArrayList<String> list = new ArrayList<String>();
String[] arrlist = {"ASAP",
"GREEN LITE",
"SPIN MANILA",
"MEGA MOBILE",
"MBC",
"ABS CBN",
"MOBEXT",
"FILIPINO STAR NGAYON",
"ADOBO",
"NONE",
"NONE",
"NONE",
"NONE",
"NONE",
"NONE",
"PERFUMO",
"MEGAWORLD",
"ALVEO LAND",
"SM LIFESTYLE",
"NONE",
"WI FUN",
"VITAL STRATS",
"CCI",
"BIG PIX",
"OMAG",
"SMX",
"URLED ENTERPRISE",
"NONE",
"MANILA BULLETIN",
"I ACADEMY",
"PLDT",
"NET PLAY INC",
"NONE",
"NONE",
"ALC",
"NONE",
"UPMG",
"BROTHER",
"V CARGO",
"CPE METROBANK",
"NONE",
"PINOY XTREME",
"MANILA NATURES",
"SMART/TV 5",
"PUREFOODS",
"NONE",
"NONE",
"AIR21",
"BOMBORADYO"};
final ArrayList<Integer> listx = new ArrayList<Integer>();
final ArrayList<Integer> listy = new ArrayList<Integer>();
final ArrayList<Integer> listdrawable = new ArrayList<Integer>();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_image_create);
img1 = BitmapFactory.decodeResource(this.getResources(),
R.drawable.mapimagenew2);

home = (ImageView) findViewById(R.id.home);
home.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Intent intent = new Intent(ImageMap.this,Home.class);
startActivity(intent);
}
});

listView1 = (ListView) findViewById(R.id.listbooth);
listView1.setDivider(null);
listView1.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
/* companies */




/* x axis */
int initx = 87;
for(int ax = 0;ax<8;ax++)
{
listx.add(initx);
initx+=32;
}
listx.add(initx);

initx = 85;
for(int bx = 0;bx<3;bx++)
{
listx.add(initx);
}
initx += 45;
for(int cx = 0;cx<3;cx++)
{
listx.add(initx);
}
initx += 22;
for(int dx = 0;dx<3;dx++)
{
listx.add(initx);
}
initx += 46;
listx.add(initx);
initx += 22;
for(int ex = 0;ex<2;ex++)
{
listx.add(initx);
}
initx += 56;
for(int fx = 0;fx<2;fx++)
{
listx.add(initx);
}
initx += 32;
listx.add(initx);
initx = 188;
for(int gx=0;gx<2;gx++)
{
listx.add(initx);
initx+=34;
}
initx-=62;
for(int hx=0;hx<2;hx++)
{
listx.add(initx);
initx+=32;
}
initx-=62;
for(int ix=0;ix<2;ix++)
{
listx.add(initx);
initx+=32;
}
initx+=20;
listx.add(initx);

initx = 84;
for(int jx = 0;jx<3;jx++)
{
listx.add(initx);
}
initx += 45;
listx.add(initx);
for(int kx = 0;kx<4;kx++)
{
listx.add(initx);
if(kx%2==1)
initx-=22;
else
initx+=22;
}
initx+=68;
for(int lx = 0;lx<4;lx++)
{
listx.add(initx);
if(lx==2)
initx+=22;
}
initx+=55;
listx.add(initx);
initx = 84;
for(int mx = 0;mx<5;mx++)
{
listx.add(initx);
initx+=62;
}

/* y axis */
int inity = 49;
for(int ay=0;ay<8;ay++)
{
listy.add(inity);
}
listy.add(inity);

inity += 52;
for(int by = 0;by<3;by++)
{
listy.add(inity);
inity+=22;
}
inity-=66;
for(int cy = 0;cy<3;cy++)
{
listy.add(inity);
inity+=22;
}
inity-=66;
for(int dy = 0;dy<3;dy++)
{
listy.add(inity);
inity+=22;
}
inity-=66;
listy.add(inity);
for(int ey = 0;ey<2;ey++)
{
listy.add(inity);
inity+=32;
}
inity-=66;
for(int fy = 0;fy<2;fy++)
{
listy.add(inity);
inity+=32;
}
inity-=61;
listy.add(inity);
inity+=90;
for(int gy = 0;gy<2;gy++)
{
listy.add(inity);
}
inity+=61;
for(int hy = 0;hy<2;hy++)
{
listy.add(inity);
}
inity+=32;
for(int iy = 0;iy<2;iy++)
{
listy.add(inity);
}
inity-=95;
listy.add(inity);
inity+=95;
inity += 58;
for(int jy = 0;jy<3;jy++)
{
listy.add(inity);
inity+=22;
}
inity-=66;
listy.add(inity);
inity+=22;
for(int ky = 0;ky<4;ky++)
{
listy.add(inity);
if(ky%2==1 && ky> 0)
inity+=22;
}
inity-=66;
for(int ly = 0;ly<4;ly++)
{
listy.add(inity);
if(ly<2)
inity+=22;
else if(ly==2)
inity-=44;
}
listy.add(inity);
inity+=84;
for(int my = 0;my<5;my++)
{
listy.add(inity);
}


/* drawables */

for(int ad = 0;ad<8;ad++)
{
listdrawable.add(R.drawable.ncube);
}
listdrawable.add(R.drawable.lcube);
for(int bd = 0;bd<3;bd++)
{
listdrawable.add(R.drawable.scube);
}
for(int cd = 0;cd<3;cd++)
{
listdrawable.add(R.drawable.scube);
}
for(int dd = 0;dd<3;dd++)
{
listdrawable.add(R.drawable.scube);
}
listdrawable.add(R.drawable.icube);
for(int ed = 0;ed<2;ed++)
{
listdrawable.add(R.drawable.ncube);
}
for(int fd = 0;fd<2;fd++)
{
listdrawable.add(R.drawable.ncube);
}
listdrawable.add(R.drawable.icube2);
for(int gd = 0;gd<2;gd++)
{
listdrawable.add(R.drawable.icube2);
}
for(int hd = 0;hd<4;hd++)
{
listdrawable.add(R.drawable.ncube);
}
listdrawable.add(R.drawable.hcube);

for(int jd = 0;jd<3;jd++)
{
listdrawable.add(R.drawable.scube);
}
for(int kd = 0;kd<5;kd++)
{
if(kd==0)
listdrawable.add(R.drawable.icubeh);
else
listdrawable.add(R.drawable.scube);
}

for(int ld = 0;ld<4;ld++)
{
if(ld==3)
listdrawable.add(R.drawable.icube2);
else
listdrawable.add(R.drawable.scube);

}
listdrawable.add(R.drawable.hmcube);
for(int md = 0;md<5;md++)
{
listdrawable.add(R.drawable.icube2h);
}


/* end lists */

for(int lli = 0;lli < listdrawable.size();lli++)
{
list.add(arrlist[lli]);

}

adapter = new ArrayAdapter<String>(this, R.layout.blacktext_list,R.id.list_content, list);
listView1.setAdapter(adapter);


final Typeface fonttype=Typeface.createFromAsset(getAssets(),"fonts/Novecentowide-DemiBold 2.ttf");



listView1.setOnItemClickListener(new AdapterView.OnItemClickListener() {


@SuppressWarnings("deprecation")
@Override
public void onItemClick(AdapterView<?> parent, final View view,
int position, long id) {
int x = listx.get(position);
int y = listy.get(position);
img2 = BitmapFactory.decodeResource(getApplicationContext().getResources(),
listdrawable.get(position));
Drawable d = new BitmapDrawable(getResources(),combineImages(img1,img2,x,y));
ImageView img1 = (ImageView)findViewById(R.id.img1);
img1.setBackgroundDrawable(d);
for(int a = 0; a < parent.getChildCount(); a++)
{
parent.getChildAt(a).setBackgroundColor(Color.TRANSPARENT);

}
Toast.makeText(getApplicationContext(), listy.get(position).toString(), Toast.LENGTH_LONG).show();
TextView mytextView = (TextView) view.findViewById(R.id.list_content);
mytextView.setTypeface(fonttype);
listView1.setItemChecked(position, true);
}

});





}
public Bitmap combineImages(Bitmap c, Bitmap s, int x,int y) { // can add a 3rd parameter 'String loc' if you want to save the new image - left some code to do that at the bottom
Bitmap cs = null;

int width, height = 0;

if(c.getWidth() > s.getWidth()) {
width = c.getWidth();
height = c.getHeight() + s.getHeight();
} else {
width = s.getWidth();
height = c.getHeight() + s.getHeight();
}

cs = Bitmap.createBitmap(width, c.getHeight(), Bitmap.Config.ARGB_8888);

Canvas comboImage = new Canvas(cs);

comboImage.drawBitmap(c, 0f, 0f, null);
comboImage.drawBitmap(s, x, y, null);

// this is an extra bit I added, just incase you want to save the new image somewhere and then return the location
/*String tmpImg = String.valueOf(System.currentTimeMillis()) + ".png";

OutputStream os = null;
try {
os = new FileOutputStream(loc + tmpImg);
cs.compress(CompressFormat.PNG, 100, os);
} catch(IOException e) {
Log.e("combineImages", "problem combining images", e);
}*/

return cs;
}



private class StableArrayAdapter extends ArrayAdapter<String> {

HashMap<String, Integer> mIdMap = new HashMap<String, Integer>();

public StableArrayAdapter(Context context, int textViewResourceId,
List<String> objects) {
super(context, textViewResourceId, objects);
for (int i = 0; i < objects.size(); ++i) {
mIdMap.put(objects.get(i), i);
}
}

@Override
public long getItemId(int position) {
String item = getItem(position);
return mIdMap.get(item);
}

@Override
public boolean hasStableIds() {
return true;
}

}


}


This is the xml layout i am using



<LinearLayout xmlns:android="http://ift.tt/nIICcg"
xmlns:tools="http://ift.tt/LrGmb4"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".ImageMap" >
<ImageView
android:id="@+id/home"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/homebutton"
/>
<ImageView
android:id="@+id/img1"
android:layout_width="wrap_content"
android:layout_height="200dp"
android:background="@drawable/mapimagenew2"
android:contentDescription="mapimage"
/>

<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/container"
android:padding="25dp"
>
<ListView
android:id="@+id/listbooth"
android:cacheColorHint="#0000"
android:padding="5dp"
android:layout_marginLeft="15dp"
android:clickable="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>


and this is my manifest



<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://ift.tt/nIICcg"
package="com.wayfinder.wayfinder"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="18" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>

<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >
<activity
android:name="com.wayfinder.wayfinder.Home"
android:label="@string/app_name"
android:screenOrientation="portrait" >


</activity>
<activity
android:name="com.wayfinder.wayfinder.Sched"
android:label="@string/title_activity_sched"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="com.wayfinder.wayfinder.ImageMap"
android:label="@string/title_activity_image_map"
android:screenOrientation="portrait" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>

</activity>
<activity
android:name="com.wayfinder.wayfinder.ViewBoothList"
android:label="@string/title_activity_image_map"
android:screenOrientation="portrait" >

</activity>
<activity
android:name="com.wayfinder.wayfinder.SchedThurs"
android:label="@string/title_activity_sched_thurs"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="com.wayfinder.wayfinder.SchedFri"
android:label="@string/title_activity_sched_fri"
android:screenOrientation="portrait" >
</activity>
</application>

</manifest>


asked 29 secs ago






Aucun commentaire:

Enregistrer un commentaire