9 Ekim 2018 Salı

NfcAdapter Sınıfı

Giriş
Açıklaması şöyle.
Contactless smart cards
A second card type is the contactless smart card, in which the card communicates with and is powered by the reader through RF induction technology (at data rates of 106–848 kbit/s). These cards require only proximity to an antenna to communicate. Like smart cards with contacts, contactless cards do not have an internal power source. Instead, they use an inductor to capture some of the incident radio-frequency interrogation signal, rectify it, and use it to power the card's electronics.
constructor
Şöyle yaparız.
NfcManager manager = ...;
NfcAdapter adapter = manager.getDefaultAdapter();
getDefaultAdaptet metodu
Şöyle yaparız.
NfcAdapter adapter = NfcAdapter.getDefaultAdapter(MainActivity.this);
isEnabled metodu
Şöyle yaparız.
if (adapter != null && adapter.isEnabled()) {
    // adapter exists and is enabled.
}

27 Ağustos 2018 Pazartesi

MotionEvent Sınıfı

MotionEvent.ACTION_UP Alanı
Açıklaması şöyle.
A pressed gesture has finished, the motion contains the final release location as well as any intermediate points since the last down or move event.
getAction metodu
Şöyle yaparız.
ivProductImage.setOnTouchListener(new View.OnTouchListener() {

  @Override
  public boolean onTouch(View v, MotionEvent event) {


    switch (event.getAction()) {
      case MotionEvent.ACTION_DOWN: {

        //press event
        imageDialog.show();

        return true;
      }
      case MotionEvent.ACTION_UP: {

        //release event
        imageDialog.dismiss();


        return true;
      }
      default:
        return false;

      }
  }

});

17 Ağustos 2018 Cuma

ApplicationInfo Sınıfı

flags Alanı
Bir uygulamanın oyun olup olmadığını anlamak için şöyle yaparız.
PackageManager pm = mContext.getPackageManager();
ApplicationInfo ai = pm.getApplicationInfo(mPackageName,0);
if((ai.flags & ApplicationInfo.FLAG_IS_GAME) == ApplicationInfo.FLAG_IS_GAME)
    return true;
return false;

14 Ağustos 2018 Salı

TextUtils Sınıfı

Giriş
Şu satırı dahil ederiz.
import android.text.TextUtils;
concat metodu
Şöyle yaparız.
SpannableString str1 = ...;
SpannableString str2 = ...;
String str = TextUtils.concat(str1 , str2);
join metodu
Iterable nesneleri attraç kullanarak birleştirir ve string'e çevirir.
Örnek
Şöyle yaparız.
ArrayList<Integer> list = ...;
String str = TextUtils.join (",", list);
Örnek
Şöyle yaparız.
TextUtils.join(" and ", names);
isEmpty metodu
Şöyle yaparız.
String str = ...;
if (TextUtils.isEmpty(tag)) {...}


1 Ağustos 2018 Çarşamba

SystemClock Sınıfı

elapsedRealtime metodu
Açıklaması şöyle.
Returns milliseconds since boot, including time spent in sleep.
elapsedRealtimeNanos metoud
Açıklaması şöyle.
Returns nanoseconds since boot. It will continue to tic even in sleep.
Şöyle yaparız.
long timeInNanos = System.nanoTime();
upTimeMillis metodu
Açıklaması şöyle.
Returns milliseconds since boot, not counting time spent in deep sleep.


19 Temmuz 2018 Perşembe

TextView Sınıfı

getPaint metodu
Şöyle yaparız.
TextView textView = findViewById(R.id.my_text_view);

Float ascent = textView.getPaint().getFontMetrics().ascent;
setAutoLinkMask metodu
Şöyle yaparız.
TextView tv = ...;
tv.setAutoLinkMask(Linkify.WEB_URLS);
tv.setAutoLinkMask(Html.fromHtml("<a href=...">foo.jpg</a>"));
setCustomSelectionActionMode metodu
TextView'a basılı tutunca açılan menu'yü değiştirmek için kullanılır. Şöyle yaparız.
textView.setCustomSelectionActionModeCallback(new android.view.ActionMode.Callback() {
  @Override
  public boolean onCreateActionMode(android.view.ActionMode mode, Menu menu) {

    ...
    return true;
  }

  @Override
  public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
    ...
    return false;
  }

  @Override
  public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
    return false;
  }

  @Override
  public void onDestroyActionMode(ActionMode mode) {
    ...
  }
});
setMaxLines metodu
XML ile şöyle yaparız.
android:maxLines="1" 
setMovementMethod metodu
Şöyle yaparız.
tv.setMovementMethod(LinkMovementMethod.getInstance());
setOnClickListener metodu
Şöyle yaparız.
tv.setOnClickListener(new View.OnClickListener() {

  @Override
  public void onClick(View v) {
    ...
  }
});
setStyle metodu
Şöyle yaparız.
<TextView
  android:id="@+id/items_category"
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  android:text="Category"
  style="@style/Category" />
styles.xml şöyledir.
<style name="Category">
  <item name="android:textColor">@android:color/black</item>
  <item name="android:textSize">40sp</item>
  <item name="android:background">#000000</item>
</style>