28 Şubat 2016 Pazar

TextWatcher Sınıfı

Giriş
Bu sınıfı EditText ile kullanılır.

İskeleti
TextWatcher ile şöyle kullanılır.
edt.addTextChangedListener(new TextWatcher() {

  @Override
  public void onTextChanged(CharSequence s, int start, int before, int count) {
  }

  @Override
  public void beforeTextChanged(CharSequence s, int start, int count,int after) {
  }

  @Override
  public void afterTextChanged(Editable s) {
  }
});
TextWatcher hem kod içinde şöyle metin atanınca
edt.setText("this is a test");


hem de kullanıcı metin girince tetiklenir.

afterTextChanged metodu
Metin değiştikten sonra en son haline erişebiliriz. 

Karakter sayısını sınırlamak istersek şöyle yaparız.
public void afterTextChanged(Editable s) {
  editText.setText(s.toString().substring(5));
}
Metnin http ile başlamasını istersek şöyle yaparız.
@Override
public void afterTextChanged(Editable s) {
  if(!s.toString().contains("http://")){
    editText.setText("http://");    Selection.setSelection(edt.getText(), edt.getText().length());
  }
}



18 Şubat 2016 Perşembe

Kamerayı Kullanmak

Video Kayıt
Video kayıt şöyle başlatılır.
private static final int REQUEST_VIDEO_CAPTURE = 4;
Intent takeVideoIntent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
if (takeVideoIntent.resolveActivity(getPackageManager()) != null) {
     startActivityForResult(takeVideoIntent, REQUEST_VIDEO_CAPTURE);
}
Kayıt bitince dosya şöyle alınır.
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (resultCode == RESULT_OK){
        switch (requestCode){
           Uri videoUri = data.getData();
           //Do something with the video
        }



Vibrator Sınıfı

constructor
Şöyle yaparız.
Vibrator vib = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
vibrate metodu
Şöyle yaparız.
vib.vibrate(500);


17 Şubat 2016 Çarşamba

SQLiteStatement Sınıfı

constructor
Şöyle yaparız.
SQLiteDatabase db = ...;
String sql = "...";
SQLiteStatement stm = db.compileStatement(sql);
bindString metodu
Sql cümlesi içindeki ? karakteri ile biten yere bir değer atar. Şöyle yaparız.
insert.bindString(1, ...);
execute metodu
Constructor'da verilen insert, update gibi bir cümleyi çalıştırır. Şöyle yaparız.
insert.execute();