17 Ocak 2018 Çarşamba

PhoneStateListener Arayüzü

CALL_STATE Alanı
Örnek
Önce şöyle yaparız.
TelephonyManager tm=
  (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
Sonra şöyle yaparız.
MyPhoneStateListener phoneListener = new MyPhoneStateListener();

// Register listener for LISTEN_CALL_STATE
tm.listen(phoneListener, PhoneStateListener.LISTEN_CALL_STATE);
Listener şöyledir.
private class MyPhoneStateListener extends PhoneStateListener {

  @Override
  public void onCallStateChanged(int state, String incomingNumber) {
    switch (state){
      case TelephonyManager.CALL_STATE_OFFHOOK:
      // This state denotes that the mobile is busy in some call

      break;

      case TelephonyManager.CALL_STATE_RINGING:
      // This state denotes that the phone is ringing

      break;

      case TelephonyManager.CALL_STATE_IDLE:
      // This state denoted that the phone is idle

      
      break;
    }
    super.onCallStateChanged(state, incomingNumber);
  }
}
SIGNAL_STRENGTHS Alanı
GSM sinyal gücünü dinlemek için şöyle yaparız.
telephonyManager.listen(myListener, PhoneStateListener.LISTEN_SIGNAL_STRENGTHS);

12 Ocak 2018 Cuma

AlertDialog Sınıfı

constructor
Şöyle yaparız.
AlertDialog alertDialog = new AlertDialog.Builder(this).create();
constructor - protected
Protected olduğı için dışarıdan çağrılamaz. Metodun içi şöyle
protected AlertDialog(Context context) {
  this(context, 0);
}
constructor - protected
Protected olduğı için dışarıdan çağrılamaz. Metodun içi şöyle
protected AlertDialog(Context context, @StyleRes int themeResId) {
  this(context, themeResId, true);
}
findViewById metodu
Düğmelerin yerine değiştirmek için şöyle yaparız.
Button posBtn = (Button) alertDialog.findViewById(android.R.id.button1);
Button negBtn = (Button) alertDialog.findViewById(android.R.id.button2);
Button neuBtn = (Button) alertDialog.findViewById(android.R.id.button3);

//get parent ViewGroup
 ViewGroup parentLayout = (ViewGroup) posBtn.getParent();

//get child indexes
int posIndex = parentLayout.indexOfChild(posBtn);
int negindex = parentLayout.indexOfChild(negBtn);
int neuIndex = parentLayout.indexOfChild(neuBtn);

 parentLayout.removeAllViews();
 parentLayout.addView(neuIndex,posBtn); //< --- swapping neutral and positive
 parentLayout.addView(posIndex,neuBtn);
 parentLayout.addView(negIndex,negBtn); 
setButton metodu
Şöyle yaparız.
// Setting OK Button
alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
  public void onClick(DialogInterface dialog, int which) {

  }
});
setMessage metodu
Şöyle yaparız.
// Setting Dialog Message
alertDialog.setMessage(msg);
setTitle metodu
Şöyle yaparız.
// Setting Dialog Title
alertDialog.setTitle("ERROR");
show metodu
Şöyle yaparız.
// Showing Alert Message
alertDialog.show();


AlertDialog.Builder Sınıfı

constructor
Activity nesnesinin context alanını alır. Bir düğmenin click olayı içinde kodlamak istersek şöyle yaparız.
AlertDialog.Builder builder = new AlertDialog.Builder (MyActivity.this);
Şöyle yaparız.
builder = AlertDialog.Builder(context, R.style.MyAlertDialogTheme);
create metodu
Şöyle yaparız.
AlertDialog alert = builder.create();
setCancellable metodu
Şöyle yaparız.
builder.setCancelable(false)
setItems metodu
Şöyle yaparız
builder.setItems(R.array.preference_grid_entries, gridDialogListener);
setMessage metodu
Şöyle yaparız.
builder.setMessage("GPS is not active. Do you want to open?");
setNegativeButton metodu
Şöyle yaparız.
builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
  public void onClick(DialogInterface dialog, int which) {
    dialog.cancel();
  }
});
setOnDismissListener metodu
Şöyle yaparız.
builder.setOnDismissListener(new DialogInterface.OnDismissListener() {

  public void onDismiss(DialogInterface dialog) {
  ...
   }
});
setPositiveButton metodu
Şöyle yaparız.
builder.setPositiveButton(android.R.string.ok, null);
Şöyle yaparız.
builder.setPositiveButton("Settings", new DialogInterface.OnClickListener() {
  public void onClick(DialogInterface dialog,int which) {
    ...
  }
});
setTitle metodu
Şöyle yaparız.
builder.setTitle("GPS Settings");
setView metodu
Şöyle yaparız.
View promptView = ...;
builder.setView(promptView);
show metodu
Şöyle yaparız.
// Showing Alert Message
builder.show();