Tuesday, March 29, 2011

Michael Galpin: Working with XML on Android

Itt van.

+

startActivityForResult-nal a requestCode nem lehet negativ

Pontosabban lehet, de: "Using negative requestCode is the same as calling startActivity(Intent) (the activity is not launched as a sub-activity)." Azaz nem fog meghivodni az onActivityResult(..)

Thursday, March 24, 2011

Android: masik Activity megnyitasa

Intent myIntent = new Intent();
myIntent.setClassName(packageName, className);
startActivity(myIntent);

Ha pedig parametereket akarunk atadni, akkor meg a startActivity elott:
myIntent.putExtra("name", "John Doe");

amit a masik oldalon (mondjuk az onCreate-ben) igy kapunk meg:
Bundle extras = getIntent().getExtras();
if (null != extras) {
String name = extras.getString("name");
}

Sokmindent at lehet adni extrakban, de object-et nem. Ezt ki kell parsolni mondjuk egy stringtombbe vagy egy json-ba (GSON).

Itt viszont azt irjak, hogy legjobb, ha Parcelable az object-unk, mert azt at lehet adni extra-kent es sokkal gyorsabb mint a parsolgatas.

Ha pedig vissza is akarunk adni valamit akkor:
- startActivityForResult(Intent, int) a sima startActivity(Intent) helyett
- a masik Activity-ben setResult(int)

ListView onListitemClick() nem hivodik meg, ha van focusable View a ListView-ban

Egyik megoldas, hogy az Adapter getView-jaban beallitjuk ennek az View-n, hogy ne legyen Focusable:

myButton.setFocusable(false);

Itt azt is irjak masik megoldasnak, hogy az xml-ben beallitjuk a android:focusable="false" es android:focusableInTouchMode="false" property-ket, de nekem ez nem mukodott.

Create new Activity in Eclipse

Vagy new Class.. vagy pedig:

  1. Double click on AndroidManifest.xml in the package explorer.
  2. Click on the "Application" tab of the manifest editor
  3. Click on "Add.." under the "Application Nodes" heading (bottom left of the screen)
  4. Choose Activity from the list in the dialog that pops up (if you have the option, you want to create a new top-level element)
  5. Click on the "Name*" link under the "Attributes for" header (bottom right of the window) to create a class for the new activity.

Android: Opening a New Screen

Itt van.

Tuesday, March 22, 2011

Android Adapterek

Itt van.

JSON parsing on Android

innen

  1. That comes with platform (org.json) – optimized since 2.2
  2. Jackson
  3. GSON
...
  1. org.json – Not very convenient to use. Doesn’t support stream parsing out of the box.
  2. jackson – very convenient to use, excellent mapping features, custom stream deserializers… but don’t use it on Android. Like Facebook and Twitter did… This will put you into the grave:) Everything is excellent before you will take a look into the ddms log.
  3. gson – GSON stream is very nice and small. It doesn’t produce so much garbage as Jackson. But it is not so convenient to use. Good news that GSON stream parser is included in API 11.

Android ListView examples

Krysztof Grajek: Custom ListView items and adapters

AppFulcrum:

2 dologra erdemes odafigyelni a sajat ArrayAdapterunkben. Egyreszt amikor a ListView egy sora lekerul a kijelzorol ezt a view-t megkapja az adapater es a getView(..) method convertView-jaban ujra megapjuk es fel tudjuk hasznalni. Masreszt a getView-ban hivott findViewByID() eleg koltseges ezert erdemes egy ViewHolder class-ban tarolni a findeViewByID() alltal talalt view-kat es ezt a convertView tag-jeben tarolni. Ezzel Lars Vogel szerint kb 175%-os performacianovekedeset erhetunk el. Valahogy igy:
// ViewHolder will buffer the assess to the individual fields of the row layout
static class ViewHolder {
public ImageView imageView;
public TextView textView;
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
if (null == convertView) {
LayoutInflater inflater = context.getLayoutInflater();
rowView = inflater.inflate(R.layout.rowlayout, null, true);
holder = new ViewHolder();
holder.textView = (TextView) rowView.findViewById(R.id.label);
holder.imageView = (ImageView) rowView.findViewById(R.id.icon);
rowView.setTag(holder);
} else {
holder = (ViewHolder) rowView.getTag();
}
holder.textView.setText("whatever text");
holder.imageView.setImageResource(R.drawable.testicon);
return convertView;
}

Monday, March 21, 2011

Android es Eclipse tutorialok

Android

dp to pixel (Android)

private int dpToPixel(float dp) {
int result;
final float scale = getResources().getDisplayMetrics().density;
result = (int) (dp * scale + 0.5f);
return result;
}

Thursday, March 17, 2011

Emulator-ban fut-e az Android code

Csak ezt talaltam:
if ("sdk".equals(Build.PRODUCT)) {...}

Android Location

LocationManager lm = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
Location loc = lm.getLastKnownLocation(LocationManager.GPS_PROVIDER);
if (null != loc) {
Double longitude = loc.getLongitude();
Double latitude = loc.getLatitude();
}

A manifiest-be pedig:
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION" />

Ez az utolso csak akkor kell, ha LocationManager.GPS_PROVIDER helyett valami mock location provider-t akarunk hasznalni. Ezt meg valahogy igy tehejuk meg:

String MOCK_LOC_PROVIDER_NAME = "mockLocationProvider";
...
lm.addTestProvider(MOCK_LOC_PROVIDER_NAME, false, false, false, false, false, false, false, 0, 5);
Location location = new Location(MOCK_LOC_PROVIDER_NAME);
location.setLatitude(32.23434);
location.setLongitude(-16.32525);
location.setTime(new Date().getTime());
lm.setTestProviderLocation(MOCK_LOC_PROVIDER_NAME, location);
lm.setTestProviderEnabled(MOCK_LOC_PROVIDER_NAME, true);

Es igy nezhetjuk meg, hogy mar hozzaadtuk-e a sajat location provider-unket (2-szer ugyanazt nem lehet hozzaadni mert akkor hiba lesz):
List providers = lm.getAllProviders();
if (providers.contains(MOCK_LOC_PROVIDER_NAME)) {...}

Wednesday, March 16, 2011

Friday, March 11, 2011

AndEngine

This is the official WiKi for AndEngine -- the free 2D OpenGL Game Engine for the Android platform.

Readonly sdcard AVD-hez

Letrehoztam Eclipse-ben egy AVD-t (Android Virtual Device), de az sdcard-ja readonly volt. Probalkoztam mindenfelevel, de vegul az segitett, ha csinaltam egy uj AVD-t. Nem tudom mit rontottam el elsore, de ez a masodik mar nem volt read only. Itt viszont eloszor tul kicsi-t csinaltam (128 MB) amire nem tudtam felmasolni egy 7 MB-os mp4-et. Amikor csinaltam egy masik AVD-t 1024 MB-os sdcard-dal, akkor arra mar felment ez a file. (Viszont maga az AVD sokkal lassabban keszult el, mert sokaig tartott letrehozni az sdcard.img-t. Raadasul az AVD indulasanal is lassabban tolti be az sdcard-ot, ezert egy ideig itt is readonly-nak tunik.)

Monday, March 07, 2011

Friday, March 04, 2011