Aklımda Kalası Kelimeler

* давайте работать вместе
* Zarf ve Mazruf, Zerafet(xHoyratlık) ile aynı kökten(za-ra-fe) gelir
* Bedesten
* Suç subuta ermiştir - Suç sabit olmuştur
Android etiketine sahip kayıtlar gösteriliyor. Tüm kayıtları göster
Android etiketine sahip kayıtlar gösteriliyor. Tüm kayıtları göster

5 Ekim 2010 Salı

Android: Listener tanımlama

Ref: http://tseng-blog.nge-web.net/blog/2009/02/14/implementing-listeners-in-your-android-java-application/

3 Yolu var:
  1. Satır içi:

    public class LoginExample extends Activity
    {
    /** Called when the activity is first created. */

    @Override
    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    ...

    // Set Click Listener
    btnLogin.setOnClickListener(new OnClickListener() {
    @Override
    public void onClick(View v) {
    // Check Login
    }
    });
    }
    }
  2. "implements" kullanılarak:

    public class LoginExample extends Activity implements OnClickListener
    {
    @Override
    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    ...

    // Set Click Listener
    btnLogin.setOnClickListener(this);
    }

    @Override
    public void OnClickListener(View v) {

    if(v.getId() == R.id.id_btnLogin){

    // Check Login
    }

    // --- ya da

    if(v == findViewById(R.id.id_btnLogin)){

    // Check Login
    }

    // --- ya da birden fazla düğmenin onClick eventi buraya gelecek
    switch( v.getId() )
    {
    case R.id.id_btnLogin :
    //......
    break;

    case R.id.id_btnLogOut :
    //......
    break;

    ......
    }
    }
    }
  3. Değişken gibi kullanarak:

    public class LoginExample extends Activity
    {
    // Set Click Listener
    OnClickListener btnLoginClickListener = new OnClickListener(){

    @Override
    public void OnClickListener(View v) {

    // Check Login
    }
    };


    @Override
    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    ...
    btnLogin.setOnClickListener(btnLoginClickListener);
    }
    }

3 Ekim 2010 Pazar

Android: Application Resources

Ref: http://developer.android.com/guide/topics/resources/index.html

Externalizing your resources also allows you to provide alternative resources that support specific device configurations such as different languages or screen sizes, which becomes increasingly important as more Android-powered devices become available with different configurations. In order to provide compatibility with different configurations, you must organize resources in your project's res/ directory, using various sub-directories that group resources by type and configuration.

For example, while your default UI layout is saved in the res/layout/ directory, you might specify a different UI layout to be used when the screen is in landscape orientation, by saving it in the res/layout-land/ directory. Android automatically applies the appropriate resources by matching the device's current configuration to your resource directory names.

Anatomy of an Android Application

Ref: http://www.anddev.org/novice-tutorials-f8/anatomy-of-an-android-application-t21.html


There are four building blocks to an Android application:
  1. Activity

  2. Intent Receiver

  3. Service

  4. Content Provider

Not every application needs to have all four, but your application will be written with some combination of these.

Once you have decided what components you need for your application, you should list them in a file called AndroidManifest.xml. This is an XML file where you declare the components of your application and what their capabilities and requirements are. See the Android manifest file documentation for complete details.

Activity


Activities are the most common of the four Android building blocks. An activity is usually a single screen in your application. Each activity is implemented as a single class that extends the Activity base class.


public class aktiviteAdi extends Activity {



Your class will display a user interface composed of Views and respond to events. Most applications consist of multiple screens. For example, a text messaging application might have one screen that shows a list of contacts to send messages to, a second screen to write the message to the chosen contact, and other screens to review old messages or change settings. Each of these screens would be implemented as an activity. Moving to another screen is accomplished by a starting a new activity. In some cases an activity may return a value to the previous activity -- for example an activity that lets the user pick a photo would return the chosen photo to the caller.

When a new screen opens, the previous screen is paused and put onto a history stack. The user can navigate backward through previously opened screens in the history. Screens can also choose to be removed from the history stack when it would be inappropriate for them to remain. Android retains history stacks for each application launched from the home screen.

Intent and Intent Filters


Android uses a special class called an Intent to move from screen to screen. An intent describes what an application wants done. The two most important parts of the intent data structure are the action and the data to act upon. Typical values for action are MAIN (the front door of the activity), VIEW, PICK, EDIT, etc. The data is expressed as a URI. For example, to view contact information for a person, you would create an intent with the VIEW action and the data set to a URI representing that person.

There is a related class called an IntentFilter. While an intent is effectively a request to do something, an intent filter is a description of what intents an activity (or intent receiver, see below) is capable of handling. An activity that is able to display contact information for a person would publish an IntentFilter that said that it knows how to handle the action VIEW when applied to data representing a person. Activities publish their IntentFilters in the AndroidManifest.xml file.

Navigating from screen to screen is accomplished by resolving intents. To navigate forward, an activity calls startActivity(myIntent). The system then looks at the intent filters for all installed applications and picks the activity whose intent filters best matches myIntent. The new activity is informed of the intent, which causes it to be launched. The process of resolving intents happens at run time when startActivity is called, which offers two key benefits:

* Activities can reuse functionality from other components simply by making a request in the form of an Intent
* Activities can be replaced at any time by a new Activity with an equivalent IntentFilter


Intent Receiver


You can use an IntentReceiver when you want code in your application to execute in reaction to an external event, for example, when the phone rings, or when the data network is available, or when it's midnight. Intent receivers do not display a UI, although they may use the NotificationManager to alert the user if something interesting has happened. Intent receivers are registered in AndroidManifest.xml, but you can also register them from code using Context.registerReceiver(). Your application does not have to be running for its intent receivers to be called; the system will start your application, if necessary, when an intent receiver is triggered. Applications can also send their own intent broadcasts to others with Context.broadcastIntent().
Service

A Service is code that is long-lived and runs without a UI. A good example of this is a media player playing songs from a play list. In a media player application, there would probably be one or more activities that allow the user to choose songs and start playing them. However, the music playback itself should not be handled by an activity because the user will expect the music to keep playing even after navigating to a new screen. In this case, the media player activity could start a service using Context.startService() to to run in the background to keep the music going. The system will then keep the music playback service running until it has finished. (You can learn more about the priority given to services in the system by reading Lifecycle of an Android Application.) Note that you can connect to a service (and start it if it's not already running) with the Context.bindService() method. When connected to a service, you can communicate with it through an interface exposed by the service. For the music service, this might allow you to pause, rewind, etc.

Content Provider


Applications can store their data in files, an SQLite database, or any other mechanism that makes sense. A content provider, however, is useful if you want your application's data to be shared with other applications. A content provider is a class that implements a standard set of methods to let other applications store and retrieve the type of data that is handled by that content provider.

To get more details on content providers, see Accessing Content Providers.


Android Life Cycle


En Temel Generic Adapter


Burada bir list aktivite kullanarak setAdapter metodu çağırıyoruz. ListView bileşeneni ayrı bir şekilde herhangi bir layout içinde kullandığınızda ve findViewById ile nesneyi yakaladığınızda da göreceksinizki onunda içinde setAdapter metodu var :) (Hiçbir şey büyülü değildir)

Sıfırdan bir adapter yapıyorsanız bunu türetmeniz gerektiğini bilmeniz lazım. Peki bu adapter ne iş yapıyor ?
Listeleyici adapterden kayıtları değil, listenin içinde görünecek satırların view halini ister. Satırları oluşturmak için veriyide türettiğiniz adapter sınıfı içine koymak işinizi kolaylar ama dışarıda da tutabilirsiniz. Sonuç olarak bilmelisiniz ki getView, getItemId, getCount metotları adapter tarafından ilk yükleme ve dokunma halinde çağırılan metotlardır.

Programın başlangıç noktası olan ListActivity:

package com.yeni.listAdapter;

import android.app.ListActivity;
import android.os.Bundle;

public class baslangicAktivitesi extends ListActivity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

setListAdapter(new yeniAdapter(this));
}
}


Kendi Adapter sınıfımız BaseAdapter sınıfından türeyecek:
package com.yeni.listAdapter;

import android.content.Context;
import android.database.DataSetObserver;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

public class NewAdapter extends BaseAdapter {
private Context ctx;

public NewAdapter(Context _ctx) {
super();
ctx = _ctx;
}

@Override
public int getCount() {
return 3;
}

@Override
public Object getItem(int position) {
return null;
}

@Override
public long getItemId(int position) {
return 0;
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
TextView tv = new TextView(ctx);
tv.setText("This text will be shown");
LinearLayout lila = new LinearLayout(ctx);
lila.addView(tv, new LinearLayout.LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));

return lila;
}
}


Sonuç olarak, NewAdapter sınıfının içindeki getCount metodunun sonucu kadar getView metodu çağırılıyor ve oluşan View gösteriliyor.

BaseAdapter sınıfındaki getItem metodunu ezmezsek aşağıdaki sonuç olacak:


Çünkü:


Daha sonra bir incelememi daha yazıya döktüm: BaseAdapter içinde işlenen sıralı metotlar

Android: ImageView, LinearLayout


2 Ekim 2010 Cumartesi

Android: Drawable




android.graphics.drawable.Drawable



A Drawable that can rotate another Drawable based on the current level value. ScaleDrawable A Drawable that changes the size of another Drawable based on its current level value. ShapeDrawable A Drawable object that draws primitive shapes.

Known Indirect Subclasses
AnimationDrawable, LevelListDrawable, PaintDrawable, StateListDrawable, TransitionDrawable
AnimationDrawable An object used to create frame-by-frame animations, defined by a series of Drawable objects, which can be used as a View object's background.
LevelListDrawable A resource that manages a number of alternate Drawables, each assigned a maximum numerical value.
PaintDrawable Drawable that draws its bounds in the given paint, with optional rounded corners.
StateListDrawable Lets you assign a number of graphic images to a single Drawable and swap out the visible item by a string ID value.
TransitionDrawable An extension of LayerDrawables that is intended to cross-fade between the first and second layer.


Class Overview
A Drawable is a general abstraction for "something that can be drawn." Most often you will deal with Drawable as the type of resource retrieved for drawing things to the screen; the Drawable class provides a generic API for dealing with an underlying visual resource that may take a variety of forms. Unlike a View, a Drawable does not have any facility to receive events or otherwise interact with the user.

In addition to simple drawing, Drawable provides a number of generic mechanisms for its client to interact with what is being drawn:

The setBounds(Rect) method must be called to tell the Drawable where it is drawn and how large it should be. All Drawables should respect the requested size, often simply by scaling their imagery. A client can find the preferred size for some Drawables with the getIntrinsicHeight() and getIntrinsicWidth() methods.
The getPadding(Rect) method can return from some Drawables information about how to frame content that is placed inside of them. For example, a Drawable that is intended to be the frame for a button widget would need to return padding that correctly places the label inside of itself.
The setState(int[]) method allows the client to tell the Drawable in which state it is to be drawn, such as "focused", "selected", etc. Some drawables may modify their imagery based on the selected state.
The setLevel(int) method allows the client to supply a single continuous controller that can modify the Drawable is displayed, such as a battery level or progress level. Some drawables may modify their imagery based on the current level.
A Drawable can perform animations by calling back to its client through the Drawable.Callback interface. All clients should support this interface (via setCallback(Drawable.Callback)) so that animations will work. A simple way to do this is through the system facilities such as setBackgroundDrawable(Drawable) and ImageView.
Though usually not visible to the application, Drawables may take a variety of forms:
Bitmap: the simplest Drawable, a PNG or JPEG image.
Nine Patch: an extension to the PNG format allows it to specify information about how to stretch it and place things inside of it.
Shape: contains simple drawing commands instead of a raw bitmap, allowing it to resize better in some cases.
Layers: a compound drawable, which draws multiple underlying drawables on top of each other.
States: a compound drawable that selects one of a set of drawables based on its state.
Levels: a compound drawable that selects one of a set of drawables based on its level.
Scale: a compound drawable with a single child drawable, whose overall size is modified based on the current level.
For information and examples of creating drawable resources (XML or bitmap files that can be loaded in code), see Resources and Internationalization.

Summary

Android: ListView hakkında



void com.packageAdi.aktiviteAdi.onListItemClick(ListView parent, View v, int position, long id)


@Override


Overrides: onListItemClick(...) in ListActivity
protected void onListItemClick (ListView l, View v, int position, long id)
Since: API Level 1
This method will be called when an item in the list is selected. Subclasses should override. Subclasses can call getListView().getItemAtPosition(position) if they need to access the data associated with the selected item.

Parameters
l The ListView where the click happened
v The view that was clicked within the ListView
position The position of the view in the list
id The row id of the item that was clicked

AndroidManifest.xml






<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.packageAdi"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".aktivitiAdi"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

</application>
<uses-sdk android:minSdkVersion="8" />

</manifest>




  • manifest en üstte herşeyi içeren etiket olarak bulunur (application, uses-sdk, uses-permission gib).

  • application etiketi, kullanacağımız activity, service, provider (aktivite, servis ve içerik sağlayıcıları) içerir.
    • android:icon="drawable resource" → Program yüklendiğinde android üstünde görüntülenecek demektir
    • android:name="string" → Uygulamımızın adı
    • android:theme="resource or theme" → Uygulama içinde genel bir cilt hazırlayıp kullanabiliriz.



  • İzinler(permissions):manifest etiketi içinde users-permission etiketi içine cihazda kullanmak istediğimiz bazı kaynaklar için izin istemeliyiz (SMS almak, resim çekmek, çağrı yapmak, internete erişmek v.s.).
  • Versiyonlar: Yüklediğimiz uygulama hangi SDK ile çalışacaksa bu bilgiyi manifest altında uses-sdk etiketi içine yazmalıyız. Uygulamayı çalıştıran cihaz üstünde olmayan bir sdk ile programı çalıştıramayacağını bize söylesin.