22 Şubat 2018 Perşembe

BluetoothGatt Sınıfı

Giriş
GATT için açıklama şöyle.
GATT is an acronym for the Generic Attribute Profile, and it defines the way that two Bluetooth Low Energy devices transfer data back and forth using concepts called Services and Characteristics. It makes use of a generic data protocol called the Attribute Protocol (ATT), which is used to store Services, Characteristics and related data in a simple lookup table using 16-bit IDs for each entry in the table.
readCharacteristics metodu
Açıklaması şöyle.
Calling readCharacteristic in sequence (without delay) will not work.

You have to wait for onCharacteristicRead for the first call before initiating the second one.

When you connect to the BLE device using connectGatt, you have to provide a BluetoothGattCallback. Implement onCharacteristicRead in that BluetoothGattCallback object, it will be called after each readCharacteristic actually finish. Inside that function you should read the next characteristic in queue until there is none.
Şöyle yaparız.
mGatt.readCharacteristic(...);

20 Şubat 2018 Salı

Volley JsonObjectRequest Sınıfı

constructor - delete
Şöyle yaparız.
JsonObjectRequest delReq = new JsonObjectRequest(Request.Method.DELETE, url,
  new Response.Listener<JSONObject>() {...},
  new Response.ErrorListener()        {...}
);
constructor - get
Şöyle yaparız.
JsonObjectRequest getReq = new JsonObjectRequest(Request.Method.GET, url, null  
  new Response.Listener<JSONObject>() {...},
  new Response.ErrorListener()        {...}
);
constructor - post
Şöyle yaparız.
String url ="http://...";

JsonObjectRequest postReq = new JsonObjectRequest (Request.Method.POST,
  url, obj, 
  new Response.Listener<JSONObject>() {...}
  new Response.ErrorListener()        {...}
);
getHeaders metodu
Http header'ındaki alanlara değer atamak için kullanılır.
Örnek
Get isteği için şöyle yaparız.
@Override
public Map<String, String> getHeaders() throws AuthFailureError
{
  HashMap<String, String> headers = new HashMap <String, String>();
  headers.put("Content-Type", "application/json; charset=utf-8");
  headers.put("WWW-Authenticate", "xBasic realm=".concat(""));
  headers.put("MyToken",sharedPreferences.getString("MyTokenAPI"));
  return headers;
}
Örnek
Post isteği için şöyle yaparız.
@Override
public Map<String, String> getHeaders() throws AuthFailureError {
  HashMap<String, String> headers = new HashMap<>();
  headers.put("token", "$2y$10$2V.Ux6CRmHoPCs2UziaVx.e6poDbFkZE2rrGrrLO1YbGcuUnkGFSS");
  return headers;
}
getParams metodu
Gönderilecek json verisini hazırlar. Şöyle yaparız.
@Override
protected Map<String, String> getParams() {
  Map<String, String> params = new HashMap<>();
  params.put("email", "t@t.ru");
  params.put("name", "Abyl");
  params.put("phone", "7777777777");
  params.put("fio", "fioasiodfaisfoiaosf");
  params.put("zarplata_ot", "450000");
  params.put("zarplata_do", "800000");
  params.put("opit_raboty", "2");
  params.put("city_id", "1");
  params.put("img",imagePath);
  params.put("user_id", "73");
  params.put("description", "asdasdasdasdasdasdasdasd");
  return params;
}
Diğer
Kullanmak için şöyle yaparız.
JSONObjectRequest rq = ...;
VolleyController.getInstance(getActivity()).addToRequestQueue(rq);

19 Şubat 2018 Pazartesi

PagerAdapter Sınıfı

Giriş
Soyut bir sınıftır. İskeleti şöyledir
public class FooPagerAdapter extends PagerAdapter {
  ...
}
destroyItem metodu
Şöyle yaparız.
@Override
public void destroyItem(ViewGroup parent, int position, Object view) {
  parent.removeView((View) view);
}
getCount metodu
Kaç sayfa olduğunu döner Şöyle yaparız.
@Override
public int getCount() {
  if(list != null) {
    return (int) Math.ceil((double) list.size() / perPage);
  } else {
    return 0;
  }
}
instantiateItem metodu
Şöyle yaparız.
@Override
public Object instantiateItem(ViewGroup parent, int position) {
  ViewGroup layout = (ViewGroup) inflater.inflate(R.layout.apps_grid, parent, false);
  ...
  return layout;
}
isViewFromObject metodu
Şöyle yaparız.
@Override
public boolean isViewFromObject(View view, Object object) {
  return view == object;
}