24 Ağustos 2016 Çarşamba

ImageView Sınıfı

Giriş
Şu satırı dahil ederiz.
import android.widget.ImageView;
Constructor
İmzası şöyle
public ImageView(Context context);
veya
public ImageView(Context context, AttributeSet attrs);
veya
public ImageView(Context context, AttributeSet attrs, int defStyleAttr);
getMeasuredHeight metodu
Şöyle yaparız.
imageview.getMeasuredHeight();
getMeasuredWidth metodu
Şöyle yaparız.
imageview.getMeasuredWidth();
getHeight metodu
Şöyle yaparız.
int height = imageView.getHeight();
getWidth metodu
Şöyle yaparız.
int width = imageView.getWidth();
invalidate metodu
Şöyle yaparız.
imageview.invalidate();
setBackgroundDrawable metodu
Şöyle yaparız.
BitmapDrawable bitmapDrawable = ...;
imageview.setBackgroundDrawable(bitmapDrawable);
setScaleType metodu
scaleType alanını açıklaması şöyle
1. ImageView.ScaleType      CENTER
Center the image in the view, but perform no scaling. 

2. ImageView.ScaleType      CENTER_CROP
Scale the image uniformly (maintain the image's aspect ratio) so that both
dimensions (width and height) of the image will be equal to or larger than the 
corresponding dimension of the view (minus padding). 

3. ImageView.ScaleType      CENTER_INSIDE
Scale the image uniformly (maintain the image's aspect ratio) so that both
dimensions (width and height) of the image will be equal to or less than the 
corresponding dimension of the view (minus padding). 

4. ImageView.ScaleType      FIT_CENTER
Scale the image using CENTER. 

5. ImageView.ScaleType      FIT_END
Scale the image using END. 

6. ImageView.ScaleType      FIT_START
Scale the image using START. 

7. ImageView.ScaleType      FIT_XY
Scale the image using FILL. 

8.ImageView.ScaleType   MATRIX
Scale using the image matrix when drawing.  
Xml'de şöyle yaparız.
<ImageView
  ...
  android:scaleType="fitCenter"
  ...
/>
setImageBitmap metodu 
Şöyle yaparız.
Bitmap image = ...;
imageview.setImageBitmap(image);
setImageResource metodu 
Şöyle yaparız.
imageview.setImageResource(R.drawable.sidious);
setOnClickListener metodu
Şöyle yaparız.
imageview.setOnClickListener(new View.OnClickListener() {

  @Override
  public void onClick(View arg0) {
    ...
  }
});
setSrc metodu
Xml'de şöyle yaparız.
<ImageView
  ...
  android:src="@drawable/exchange1" />
setVisibility metodu
XML ile şöyle yaparız.
<ImageView
  ...
  android:visibility="gone"
/>
Şöyle yaparız.
imageview.setVisibility(View.VISIBLE);


23 Ağustos 2016 Salı

Google-Maps PolylineOptions Sınıfı

Giriş
Şu satırı dahil ederiz.
import com.google.android.gms.maps.model.PolylineOptions;
PolylineOptions bir Builder sınıfıdır. Zorunlu olmayan parametreler için varsayılan değerler sağlar. Bu sınıf şöyle kullanılır.
PolylineOptions opt = new PolylineOptions()
...
Polyline polyLine = googleMap.addPolyline(opt);
constructor
Şöyle yaparız
PolylineOptions opt = new PolylineOptions();
add metodu
Bir enlem/boylam dizisi alır. Şöyle yaparız.
opt.add(new LatLng(...,...),new LatLng(...,...),new LatLng(..., ...),
        new LatLng(...,...),new LatLng(...,...),new LatLng(...,...),
       );
color metodu
Rengi belirler. Şöyle yaparız.
opt.color(Color.RED);
width metodu
Kalınlığı belirler. Şöyle yaparız.
opt.width(8);

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);