19 Ağustos 2016 Cuma

DexFile Sınıfı

Giriş
Aynı bir jar dosyasını dolaşır gibi Anroid uygulaması içinde sınıfları dolaşbilmemizi sağlar.

constructor
Şöyle yaparız.
DexFile df = new DexFile(context.getPackageCodePath());
entries metodu
Şöyle yaparız.
for (Enumeration<String> iter = df.entries(); iter.hasMoreElements();) {
  String s = iter.nextElement();
}

10 Ağustos 2016 Çarşamba

Window Sınıfı

requestFeature metodu
Açıklaması şöyle
This must be called before setContentView().
Activity sınıfımda şöyle yaparız.
protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  
  requestWindowFeature(...);
  getWindow().setFlags(...);
  setContentView(R.layout.activity_main);

}
Eğer ekranda başlık olmasın istersek şöyle yaparız.
requestWindowFeature(Window.FEATURE_NO_TITLE);
Tam ekran olsun istersek şöyle yaparız.
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
        WindowManager.LayoutParams.FLAG_FULLSCREEN);

2 Ağustos 2016 Salı

Button Sınıfı

Giriş
Şu satırı dahil ederiz.
import android.widget.Button;
onTouchEvent metodu
Şöyle yaparız.
@Override
public boolean onTouchEvent(MotionEvent event) {
  int x = (int) event.getX();
  int y = (int) event.getY();

  // ignores touches on transparent background
  if (isPixelTransparent(x, y))
    return false;
  else
    return super.onTouchEvent(event);
}
setOnClickListener metodu
Şu satırı dahil ederiz.
import android.view.View.OnClickListener;
Şöyle yaparız.
Button button = ...;
button.setOnClickListener(new View.OnClickListener() {
  @Override
  public void onClick(View v) {
    ...
  }
});
View nesnesi tıklanan düğmedir. Birden fazla düğme olduğunu varsayalım ve hepsine aynı listener nesnesini bağlayalım.
button1.setOnClickListener(...);
button2.setOnClickListener(...);
button3.setOnClickListener(...);
button4.setOnClickListener(..);
Düğmeyi şöyle ayırt ederiz.
@Override
public void onClick(View view) {
  switch (view.getId()) {
    case R.id.button1:
      ...
      break;
    case R.id.button2:
      ...
      break;
    case R.id.button3:
      ...
      break;
    case R.id.button4:
      ...
      break;
  }
}
setEnabled metodu
Şöyle yaparız.
button.setEnabled(true);
setText metodu
Şöyle yaprız
String text = ...;
button.setText (text);
setVisibility metodu
Şöyle yaparız.
button.setVisibility(View.INVISIBLE);


RingtoneManager Sınıfı

getDefaultUri metodu
Şöyle yaparız.
Uri ntfy = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
Ringtone r = RingtoneManager.getRingtone(getApplicationContext(), ntf);
getRingtone metodu
Şöyle yaparız.
Uri myUri = ...;
Ringtone r = RingtoneManager.getRingtone(getApplicationContext(), myUri);

27 Temmuz 2016 Çarşamba

Geocoder Sınıfı

Giriş
Address nesnesi elde etmek için kullanılır.

Constructor - context
Context nesnesi ile kurulur.
Context cxt = ...;
Geocoder coder = new Geocoder(cxt);
Şöyle yaparız.
Geocoder geocoder = new Geocoder(getActivity());
Constructor - context + locale
Şöyle yaparız.
Geocoder geocoder = new Geocoder(getActivity(), Locale.getDefault());
Şöyle yaparız.
Geocoder geocoder= new Geocoder(this, Locale.ENGLISH);
getFromLocationName
Elimizde bir adres olsun.
String address = ...
List<Address> tipinde bir sonuç döner. Şöyle yaparız.
List<Address> list = geocoder.getFromLocationName(address, 1);
Sonucun dolu olduğunu kontrol etmek gerekir.
if (list.size() > 0) {...}
getFromLocation metodu
Enlem ve boylama göre sonuç döner. Sonuç listesini sınırlayabiliriz. Şöyle yaparız.
int maxAddress = ...;
double longitude = ...;
double latitude = ...;
List<Address> addressList = geocoder.getFromLocation(latitude, longitude,
  maxAddress);
1 tane sonuç dönmesini istiyoruz.
double latitude = ...; double longitude = ...;
List<Address> list = geocoder.getFromLocation(latitude, longitude, 1);
Sonucun dolu olduğunu kontrol etmek gerekir.
if (list != null && list.size() > 0) {...}



25 Temmuz 2016 Pazartesi

ExifInterface Sınıfı

constructor 
Şöyle yaparız.
String filePath = ...;
ExifInterface exif = new ExifInterface(filePath); //API Level 5
getAttribute metodu
Şöyle yaparız.
String orientation = exif.getAttribute (ExifInterface.TAG_ORIENTATION);
getAttributeInt metodu
Şöyle yaparız.
int orientation = exif.getAttributeInt(
            ExifInterface.TAG_ORIENTATION, 0);



BitmapShader Sınıfı

constructor
Şöyle yaparız.
Bitmap bitmap = ...;
BitmapShader shader = 
 new BitmapShader(bitmap, Shader.TileMode.REPEAT, Shader.TileMode.CLAMP);