28 Ağustos 2016 Pazar

SensorManager Sınıfı

Giriş
Şu satırları dahil ederiz.
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
constructor
Şöyle yaparız.
SensorManager sManager = (SensorManager) context.
                         getSystemService(Context.SENSOR_SERVICE);
getDefaultSensor metodu
Şöyle yaparız.
SensorManager sManager = ...
Sensor sensor = sManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
Şöyle yaparız.
Sensor sensor = sensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD);
Adım sayar şöyle yaparız.
Sensor sensor = sensorManager.getDefaultSensor(Sensor.TYPE_STEP_COUNTER);
Adım için şöyle yaparız.
Sensor sensor = sensorManager.getDefaultSensor(Sensor.TYPE_STEP_DETECTOR);

registerListener metodu
Şöyle yaparız.
Sensor sensor = ...;
sManager.registerListener(new MyListener(), sensor, 
                          SensorManager.SENSOR_DELAY_NORMAL);
Şöyle yaparız.
Sensor sensor = ...;
sManager.registerListener(new MyListener(), sensor, 
                          SensorManager.SENSOR_DELAY_FASTEST);
Activity içinde şöyle yaparız.
@Override
protected void onResume() {
  sensorManager.registerListener(this, sensor, SensorManager.SENSOR_DELAY_UI);
  super.onResume();
}
unregisterListener metodu
Şöyle yaparız
sensorManager.unregisterListener(this,sensor);
Activity içinde şöyle yaparız.
@Override
protected void onPause() {
  sensorManager.unregisterListener(this, magnetometer);
  super.onPause();
}



SmsManager Sınıfı

Giriş
Şu izinin olması gerekir.
<uses-permission android:name="android.permission.SEND_SMS" />
construtor
Şöyle yaparız.
SmsManager sms = SmsManager.getDefault();
divideMessage metodu
Şöyle yaparız.
SmsManager sm = ...;
ArrayList<String> parts = sm.divideMessage("LONG TEXT...");
sendMultiPartTextMessage metodu
Şöyle yaparız. Parçalar için de gönderme ve teslimat için Intent verilebilir.
ArrayList<String> parts = ...;
sm.sendMultiPartTextMessage(phoneNumber,null, parts, null, null);
sendTextMessage metodu
İmzası şöyle
void sendTextMessage(String recipient,String scAdress,String msg, 
PendingIntent sendIntent, PendingIntent deliveryIntent);
1. parametre alıcını numarası.
2. parametre gönderenin numarası
Bu parametrenin telefona ait numaralardan farklı bir numara ile çağrılması işe yaramıyor. scAddress spoof edilemiyor.
3. parametre metin mesajı
4. parametre gönderilme ihbarı
5. parametre okunma ihbarı

En kolay kullanım şekli şöyle. Sadece 160 karakter gönderir.
sms.sendTextMessage(recepientPhoneNumber, null, message, null, null);
İstersek gönderme ve teslimat için Intent verebiliriz. Şöyle yaparız.
String phoneNumber = ...; String message = ...;

PendingIntent sentPI = ...;
PendingIntent deliveredPI = ...;
SmsManager sms = SmsManager.getDefault();
sms.sendTextMessage(phoneNumber, null, message, sentPI, deliveredPI);

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