Java Code Examples for android.widget.ListAdapter#getItem()

The following examples show how to use android.widget.ListAdapter#getItem() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestUtilities.java    From google-authenticator-android with Apache License 2.0 6 votes vote down vote up
/** Taps the specified preference displayed by the provided Activity. */
@FixWhenMinSdkVersion(11)
@SuppressWarnings("deprecation")
public static void tapPreference(PreferenceActivity activity, Preference preference) {
  // IMPLEMENTATION NOTE: There's no obvious way to find out which View corresponds to the
  // preference because the Preference list in the adapter is flattened, whereas the View
  // hierarchy in the ListView is not.
  // Thus, we go for the Reflection-based invocation of Preference.performClick() which is as
  // close to the invocation stack of a normal tap as it gets.

  // Only perform the click if the preference is in the adapter to catch cases where the
  // preference is not part of the PreferenceActivity for some reason.
  ListView listView = activity.getListView();
  ListAdapter listAdapter = listView.getAdapter();
  for (int i = 0, len = listAdapter.getCount(); i < len; i++) {
    if (listAdapter.getItem(i) == preference) {
      invokePreferencePerformClickOnMainThread(preference, activity.getPreferenceScreen());
      return;
    }
  }
  throw new IllegalArgumentException("Preference " + preference + " not in list");
}
 
Example 2
Source File: MainActivity.java    From listmyaps with Apache License 2.0 6 votes vote down vote up
@Override
public void onPause() {
	super.onPause();
	SharedPreferences.Editor editor = getSharedPreferences(PREFSFILE, 0).edit();
	editor.putBoolean(ALWAYS_GOOGLE_PLAY,
			((CheckBox) findViewById(R.id.always_gplay)).isChecked());
	if (template != null) {
		editor.putLong(TEMPLATEID, template.id);
	}
	ListAdapter adapter = getListAdapter();
	int count = adapter.getCount();
	for (int i = 0; i < count; i++) {
		SortablePackageInfo spi = (SortablePackageInfo) adapter.getItem(i);
		editor.putBoolean(SELECTED + "." + spi.packageName, spi.selected);
	}
	editor.commit();
}
 
Example 3
Source File: MainActivity.java    From listmyaps with Apache License 2.0 6 votes vote down vote up
/**
 * Share with the world.
 */
private void doStumble() {
	ListAdapter adapter = getListAdapter();
	int count = adapter.getCount();
	ArrayList<String> collect = new ArrayList<String>(); 
	for (int i = 0; i < count; i++) {
		SortablePackageInfo spi = (SortablePackageInfo) adapter.getItem(i);
		if (spi.selected) {
			collect.add(spi.packageName);
		}
	}
	
	Collections.shuffle(collect);
	StringBuilder sb = new StringBuilder();
	for (int i=0;i<collect.size();i++) {
		if (sb.length()>0) {
			sb.append(",");
		}
		sb.append(collect.get(i));
		if (sb.length()>200) {
			break; // prevent the url from growing overly large. 
		}
	}
	openUri(this,Uri.parse(getString(R.string.url_browse,sb.toString())));
}
 
Example 4
Source File: MainActivity.java    From listmyaps with Apache License 2.0 6 votes vote down vote up
/**
 * Check if at least one app is selected. Pop up a toast if none is selected.
 * 
 * @return true if no app is selected.
 */
public boolean isNothingSelected() {
	ListAdapter adapter = getListAdapter();
	if (adapter != null) {
		int count = adapter.getCount();
		for (int i = 0; i < count; i++) {
			SortablePackageInfo spi = (SortablePackageInfo) adapter.getItem(i);
			if (spi.selected) {
				return false;
			}
		}
	}
	Toast.makeText(this, R.string.msg_warn_nothing_selected, Toast.LENGTH_LONG)
			.show();
	return true;
}
 
Example 5
Source File: TagSelectionListener.java    From listmyaps with Apache License 2.0 6 votes vote down vote up
/**
 * 
 * @param adapter
 *          The listadapter (containing the list of apps) to control.
 */
public TagSelectionListener(ListAdapter adapter) {
	this.adapter = adapter;
	int count = adapter.getCount();
	Vector<String> collect = new Vector<String>();
	for (int i = 0; i < count; i++) {
		SortablePackageInfo spi = (SortablePackageInfo) adapter.getItem(i);
		String[] tags = MainActivity.noNull(spi.tags).split(",");
		for (String tag : tags) {
			String tmp = tag.trim();
			if (tmp.length() > 0 && !collect.contains(tmp)) {
				collect.add(tmp);
			}
		}
	}
	items = collect.toArray(new String[0]);
	states = new boolean[items.length];
	Arrays.sort(items);
}
 
Example 6
Source File: MergeAdapter.java    From Shield with MIT License 5 votes vote down vote up
/**
 * Get the data item associated with the specified position in the data set.
 *
 * @param position Position of the item whose data we want
 */
@Override
public Object getItem(int position) {
    for (ListAdapter piece : pieces) {
        int size = piece.getCount();

        if (position < size) {
            return (piece.getItem(position));
        }

        position -= size;
    }

    return (null);
}
 
Example 7
Source File: MergeAdapter.java    From BLE with Apache License 2.0 5 votes vote down vote up
public Object getItem(int position) {
    int size;
    for (Iterator i$ = this.getPieces().iterator(); i$.hasNext(); position -= size) {
        ListAdapter piece = (ListAdapter) i$.next();
        size = piece.getCount();
        if (position < size) {
            return piece.getItem(position);
        }
    }

    return null;
}
 
Example 8
Source File: MergeAdapter.java    From AndroidBleManager with Apache License 2.0 5 votes vote down vote up
/**
 * Get the data item associated with the specified
 * position in the data set.
 *
 * @param position
 *          Position of the item whose data we want
 */
@Override
public Object getItem(int position) {
    for (ListAdapter piece : getPieces()) {
        int size=piece.getCount();

        if (position < size) {
            return(piece.getItem(position));
        }

        position-=size;
    }

    return(null);
}
 
Example 9
Source File: MergeAdapter.java    From mimicry with Apache License 2.0 5 votes vote down vote up
/**
 * Get the data item associated with the specified position in the data set.
 * @param position Position of the item whose data we want
 */
public Object getItem(int position) {
	for (ListAdapter piece : pieces) {
		int size = piece.getCount();

		if (position < size) {
			return (piece.getItem(position));
		}

		position -= size;
	}

	return (null);
}
 
Example 10
Source File: PickServerFragment.java    From android-vlc-remote with GNU General Public License v3.0 5 votes vote down vote up
private Preference getPreferenceFromMenuInfo(ContextMenuInfo menuInfo) {
    if (menuInfo != null) {
        if (menuInfo instanceof AdapterContextMenuInfo) {
            AdapterContextMenuInfo adapterMenuInfo = (AdapterContextMenuInfo) menuInfo;
            PreferenceScreen screen = getPreferenceScreen();
            ListAdapter root = screen.getRootAdapter();
            Object item = root.getItem(adapterMenuInfo.position);
            return (Preference) item;
        }
    }
    return null;
}
 
Example 11
Source File: MergeAdapter.java    From SimpleExplorer with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Get the data item associated with the specified position in the data set.
 *
 * @param position Position of the item whose data we want
 */
public Object getItem(int position) {
    for (ListAdapter piece : pieces) {
        int size = piece.getCount();

        if (position < size) {
            return piece.getItem(position);
        }

        position -= size;
    }

    return null;
}
 
Example 12
Source File: HeroDetailActivity.java    From tup.dota2recipe with Apache License 2.0 5 votes vote down vote up
@Override
public void onItemClick(ListAdapter parent, View view, int position, long id) {
    // Utils.startHeroDetailActivity(this.getActivity(),
    // (HeroDetailItem) parent.getItemAtPosition(position));
    final Object cItem = parent.getItem(position);
    if (cItem instanceof ItemsItem) {
        Utils.startItemsDetailActivity(this.getActivity(),
                (ItemsItem) cItem);
    }
}
 
Example 13
Source File: AuthenticatorActivityTest.java    From google-authenticator-android with Apache License 2.0 4 votes vote down vote up
@Test
public void testReorderAccounts() {
  accountDb.add(
      "first", "7777777777777777", OtpType.HOTP, null, null, AccountDb.GOOGLE_ISSUER_NAME);
  accountDb.add("second", "6666666666666666", OtpType.TOTP, null, null, null);
  accountDb.add("third", "5555555555555555", OtpType.TOTP, null, null, "Yahoo");

  activityTestRule.launchActivity(null);

  EmptySpaceClickableDragSortListView userList =
      activityTestRule.getActivity().findViewById(R.id.user_list);
  View firstView = userList.getChildAt(0);
  View thirdView = userList.getChildAt(2);
  View firstDragHandle = firstView.findViewById(R.id.user_row_drag_handle);
  View thirdDragHandle = thirdView.findViewById(R.id.user_row_drag_handle);
  int dragHandleWidth = firstDragHandle.getWidth();
  int dragHandleHeight = firstDragHandle.getHeight();
  int[] firstDragHandleLocation = new int[2];
  int[] thirdDragHandleLocation = new int[2];
  firstDragHandle.getLocationOnScreen(firstDragHandleLocation);
  thirdDragHandle.getLocationOnScreen(thirdDragHandleLocation);
  float fromX = firstDragHandleLocation[0] + (dragHandleWidth / 2.0f);
  float fromY = firstDragHandleLocation[1] + (dragHandleHeight / 2.0f);
  float toX = thirdDragHandleLocation[0] + (dragHandleWidth / 2.0f);
  float toY = thirdDragHandleLocation[1] + (dragHandleHeight / 2.0f);

  onView(equalTo(firstView))
      .perform(longClick())
      .perform(
          new GeneralSwipeAction(
              Swipe.SLOW,
              (view) -> {
                return new float[] {fromX, fromY};
              },
              (view) -> {
                return new float[] {toX, toY};
              },
              Press.FINGER));

  ListAdapter listAdapter = userList.getAdapter();
  PinInfo firstPinInfo = (PinInfo) listAdapter.getItem(0);
  PinInfo secondPinInfo = (PinInfo) listAdapter.getItem(1);
  PinInfo thirdPinInfo = (PinInfo) listAdapter.getItem(2);
  assertThat(firstPinInfo.getIndex().getName()).isEqualTo("second");
  assertThat(secondPinInfo.getIndex().getName()).isEqualTo("third");
  assertThat(thirdPinInfo.getIndex().getName()).isEqualTo("first");
}
 
Example 14
Source File: MainActivity.java    From checkey with GNU General Public License v3.0 4 votes vote down vote up
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    ListAdapter adapter = appListFragment.getListAdapter();
    AppEntry appEntry = (AppEntry) adapter.getItem(selectedItem);
    if (appEntry == null) {
        Toast.makeText(this, R.string.error_no_app_entry, Toast.LENGTH_SHORT).show();
        return true;
    }
    Intent intent = new Intent(this, WebViewActivity.class);
    intent.putExtra(Intent.EXTRA_TEXT, appEntry.getLabel());
    switch (item.getItemId()) {
        case android.R.id.home:
            setResult(RESULT_CANCELED);
            finish();
            return true;
        case R.id.details:
            showDetailView(appEntry, intent);
            return true;
        case R.id.generate_pin:
            generatePin(appEntry, intent);
            return true;
        case R.id.save:
            saveCertificate(appEntry, intent);
            return true;
        case R.id.virustotal:
            virustotal(appEntry, intent);
            return true;
        case R.id.by_apk_hash:
            byApkHash(appEntry, intent);
            return true;
        case R.id.by_package_name:
            byPackageName(appEntry, intent);
            return true;
        case R.id.by_signing_certificate:
            bySigningCertificate(appEntry, intent);
            return true;
        case R.id.action_settings:
            return true;
    }
    return super.onOptionsItemSelected(item);
}
 
Example 15
Source File: MainActivity.java    From listmyaps with Apache License 2.0 4 votes vote down vote up
/**
 * Construct what is to be shared/copied to the clipboard
 * 
 * @return the output for sharing.
 */
private CharSequence buildOutput() {
	if (template == null) {
		return getString(R.string.msg_error_no_templates);
	}

	StringBuilder ret = new StringBuilder();
	DateFormat df = DateFormat.getDateTimeInstance();
	boolean alwaysGP = ((CheckBox) findViewById(R.id.always_gplay)).isChecked();
	ListAdapter adapter = getListAdapter();
	int count = adapter.getCount();

	String now = java.text.DateFormat.getDateTimeInstance().format(
			Calendar.getInstance().getTime());
	int selected = 0;

	for (int i = 0; i < count; i++) {
		SortablePackageInfo spi = (SortablePackageInfo) adapter.getItem(i);
		if (spi.selected) {
			selected++;
			String tmp = spi.installer;
			if (alwaysGP) {
				tmp = "com.google.vending";
			}
			String firstInstalled = df.format(new Date(spi.firstInstalled));
			String lastUpdated = df.format(new Date(spi.lastUpdated));
			String sourceLink = createSourceLink(tmp, spi.packageName);
			String tmpl = template.item.replace("${comment}", noNull(spi.comment))
					.replace("${tags}",noNull(spi.tags))
					.replace("${packagename}", noNull(spi.packageName))
					.replace("${displayname}", noNull(spi.displayName))
					.replace("${source}", noNull(sourceLink))
					.replace("${versioncode}", "" + spi.versionCode)
					.replace("${targetsdk}", "" + spi.targetsdk)
					.replace("${version}", noNull(spi.version))
					.replace("${rating}", "" + spi.rating)
					.replace("${uid}", "" + spi.uid)
					.replace("${firstinstalled}", firstInstalled)
					.replace("${lastupdated}", lastUpdated)
					.replace("${datadir}", noNull(spi.dataDir))
					.replace("${marketid}", noNull(spi.installer));
			ret.append(tmpl);
		}
	}
	ret.insert(
			0,
			template.header.replace("${now}", now).replace("${count}",
					"" + selected));
	ret.append(template.footer.replace("${now}", now).replace("${count}",
			"" + selected));
	return ret;
}