Android Open Source - ponyville-live-android Network Delay Adapter

From Project

Back to project page ponyville-live-android.


The source code is released under:

Apache License

If you think the Android project ponyville-live-android listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

/*from  w w w  . j  a  v a 2s. com*/
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import static butterknife.ButterKnife.findById;

class NetworkDelayAdapter extends BindableAdapter<Long> {
  private static final long[] VALUES = {
      250, 500, 1000, 2000, 3000

  public static int getPositionForValue(long value) {
    for (int i = 0; i < VALUES.length; i++) {
      if (VALUES[i] == value) {
        return i;
    return 3; // Default to 2000 if something changes.

  NetworkDelayAdapter(Context context) {

  public int getCount() {
    return VALUES.length;

  public Long getItem(int position) {
    return VALUES[position];

  public long getItemId(int position) {
    return position;

  public View newView(LayoutInflater inflater, int position, ViewGroup container) {
    return inflater.inflate(android.R.layout.simple_spinner_item, container, false);

  public void bindView(Long item, int position, View view) {
    TextView tv = findById(view,;
    tv.setText(item + "ms");

  public View newDropDownView(LayoutInflater inflater, int position, ViewGroup container) {
    return inflater.inflate(android.R.layout.simple_spinner_dropdown_item, container, false);

Java Source Code List