use of android.util.SparseBooleanArray in project android-topeka by googlesamples.
the class AnswerHelperAndroidTest method setCorrectAnswers.
@Before
public void setCorrectAnswers() {
mCorrectAnswer = new SparseBooleanArray();
mCorrectAnswer.put(0, true);
mCorrectAnswer.put(1, true);
mCorrectAnswer.put(2, true);
}
use of android.util.SparseBooleanArray in project facebook-android-sdk by facebook.
the class PermissionSelectActivity method onClick.
public void onClick(View v) {
SparseBooleanArray checked = listView.getCheckedItemPositions();
ArrayList<String> readPerms = new ArrayList<>();
String writePri = null;
ArrayList<String> publishPerms = new ArrayList<>();
for (int i = 0; i < checked.size(); i++) {
// Item position in adapter
int position = checked.keyAt(i);
// Add perm only if checked
if (checked.valueAt(i)) {
String checkedItem = adapter.getItem(position);
if (DefaultAudience.EVERYONE.toString().equals(checkedItem)) {
writePri = "EVERYONE";
} else if (DefaultAudience.FRIENDS.toString().equals(checkedItem)) {
writePri = "FRIENDS";
} else if (DefaultAudience.ONLY_ME.toString().equals(checkedItem)) {
writePri = "ONLY_ME";
} else if ((PUBLISH_PERMS_LIST).contains(checkedItem)) {
publishPerms.add(checkedItem);
} else
readPerms.add(checkedItem);
}
}
String[] readPermsArr = readPerms.toArray(new String[readPerms.size()]);
String[] publishPermsArr = publishPerms.toArray(new String[publishPerms.size()]);
Intent intent = new Intent();
intent.putExtra(EXTRA_SELECTED_READ_PARAMS, readPermsArr);
intent.putExtra(EXTRA_SELECTED_WRITE_PRIVACY, writePri);
intent.putExtra(EXTRA_SELECTED_PUBLISH_PARAMS, publishPermsArr);
setResult(RESULT_OK, intent);
finish();
}
use of android.util.SparseBooleanArray in project XobotOS by xamarin.
the class NetworkStats method getUniqueUids.
/**
* Return list of unique UIDs known by this data structure.
*/
public int[] getUniqueUids() {
final SparseBooleanArray uids = new SparseBooleanArray();
for (int uid : this.uid) {
uids.put(uid, true);
}
final int size = uids.size();
final int[] result = new int[size];
for (int i = 0; i < size; i++) {
result[i] = uids.keyAt(i);
}
return result;
}
use of android.util.SparseBooleanArray in project WordPress-Android by wordpress-mobile.
the class StatsSingleItemDetailsActivity method onCreate.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.stats_activity_single_post_details);
ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
actionBar.setDisplayHomeAsUpEnabled(true);
}
// pull to refresh setup
mSwipeToRefreshHelper = new SwipeToRefreshHelper(this, (CustomSwipeRefreshLayout) findViewById(R.id.ptr_layout), new SwipeToRefreshHelper.RefreshListener() {
@Override
public void onRefreshStarted() {
if (!NetworkUtils.checkConnection(getBaseContext())) {
mSwipeToRefreshHelper.setRefreshing(false);
return;
}
refreshStats();
}
});
TextView mStatsForLabel = (TextView) findViewById(R.id.stats_summary_title);
mGraphContainer = (LinearLayout) findViewById(R.id.stats_bar_chart_fragment_container);
mStatsViewsLabel = (TextView) findViewById(R.id.stats_views_label);
mStatsViewsTotals = (TextView) findViewById(R.id.stats_views_totals);
mMonthsAndYearsModule = (LinearLayout) findViewById(R.id.stats_months_years_module);
mMonthsAndYearsHeader = (RelativeLayout) findViewById(R.id.stats_months_years_header);
mMonthsAndYearsList = (LinearLayout) findViewById(R.id.stats_months_years_list_linearlayout);
mMonthsAndYearsEmptyPlaceholder = (LinearLayout) findViewById(R.id.stats_months_years_empty_module_placeholder);
mAveragesModule = (LinearLayout) findViewById(R.id.stats_averages_module);
mAveragesHeader = (RelativeLayout) findViewById(R.id.stats_averages_list_header);
mAveragesList = (LinearLayout) findViewById(R.id.stats_averages_list_linearlayout);
mAveragesEmptyPlaceholder = (LinearLayout) findViewById(R.id.stats_averages_empty_module_placeholder);
mRecentWeeksModule = (LinearLayout) findViewById(R.id.stats_recent_weeks_module);
mRecentWeeksHeader = (RelativeLayout) findViewById(R.id.stats_recent_weeks_list_header);
mRecentWeeksList = (LinearLayout) findViewById(R.id.stats_recent_weeks_list_linearlayout);
mRecentWeeksEmptyPlaceholder = (LinearLayout) findViewById(R.id.stats_recent_weeks_empty_module_placeholder);
mYearsIdToExpandedMap = new SparseBooleanArray();
mAveragesIdToExpandedMap = new SparseBooleanArray();
mRecentWeeksIdToExpandedMap = new SparseBooleanArray();
setTitle(R.string.stats);
mOuterScrollView = (ScrollViewExt) findViewById(R.id.scroll_view_stats);
if (savedInstanceState != null) {
mRemoteItemID = savedInstanceState.getString(ARG_REMOTE_ITEM_ID);
mRemoteBlogID = savedInstanceState.getLong(ARG_REMOTE_BLOG_ID, 0);
mRemoteItemType = savedInstanceState.getString(ARG_REMOTE_ITEM_TYPE);
mItemTitle = savedInstanceState.getString(ARG_ITEM_TITLE);
mItemURL = savedInstanceState.getString(ARG_ITEM_URL);
mRestResponseParsed = (PostViewsModel) savedInstanceState.getSerializable(ARG_REST_RESPONSE);
mSelectedBarGraphIndex = savedInstanceState.getInt(ARG_SELECTED_GRAPH_BAR, -1);
mPrevNumberOfBarsGraph = savedInstanceState.getInt(ARG_PREV_NUMBER_OF_BARS, -1);
final int yScrollPosition = savedInstanceState.getInt(SAVED_STATS_SCROLL_POSITION);
if (yScrollPosition != 0) {
mOuterScrollView.postDelayed(new Runnable() {
public void run() {
if (!isFinishing()) {
mOuterScrollView.scrollTo(0, yScrollPosition);
}
}
}, StatsConstants.STATS_SCROLL_TO_DELAY);
}
if (savedInstanceState.containsKey(ARG_AVERAGES_EXPANDED_ROWS)) {
mAveragesIdToExpandedMap = savedInstanceState.getParcelable(ARG_AVERAGES_EXPANDED_ROWS);
}
if (savedInstanceState.containsKey(ARG_RECENT_EXPANDED_ROWS)) {
mRecentWeeksIdToExpandedMap = savedInstanceState.getParcelable(ARG_RECENT_EXPANDED_ROWS);
}
if (savedInstanceState.containsKey(ARG_YEARS_EXPANDED_ROWS)) {
mYearsIdToExpandedMap = savedInstanceState.getParcelable(ARG_YEARS_EXPANDED_ROWS);
}
} else if (getIntent() != null && getIntent().getExtras() != null) {
Bundle extras = getIntent().getExtras();
mRemoteItemID = extras.getString(ARG_REMOTE_ITEM_ID);
mRemoteBlogID = extras.getLong(ARG_REMOTE_BLOG_ID, 0);
mRemoteItemType = extras.getString(ARG_REMOTE_ITEM_TYPE);
mItemTitle = extras.getString(ARG_ITEM_TITLE);
mItemURL = extras.getString(ARG_ITEM_URL);
mRestResponseParsed = (PostViewsModel) extras.getSerializable(ARG_REST_RESPONSE);
mSelectedBarGraphIndex = extras.getInt(ARG_SELECTED_GRAPH_BAR, -1);
}
if (mRemoteBlogID == 0 || mRemoteItemID == null) {
Toast.makeText(this, R.string.stats_generic_error, Toast.LENGTH_LONG).show();
finish();
return;
}
if (savedInstanceState == null) {
AnalyticsUtils.trackWithSiteId(AnalyticsTracker.Stat.STATS_SINGLE_POST_ACCESSED, mRemoteBlogID);
}
// Setup the main top label that opens the post in the Reader where possible
if (mItemTitle != null || mItemURL != null) {
mStatsForLabel.setVisibility(View.VISIBLE);
mStatsForLabel.setText(mItemTitle != null ? mItemTitle : mItemURL);
// make the label clickable if the URL is available
if (mItemURL != null) {
mStatsForLabel.setTextColor(getResources().getColor(R.color.stats_link_text_color));
mStatsForLabel.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final Context ctx = v.getContext();
StatsUtils.openPostInReaderOrInAppWebview(ctx, mRemoteBlogID, mRemoteItemID, mRemoteItemType, mItemURL);
}
});
} else {
mStatsForLabel.setTextColor(getResources().getColor(R.color.grey_darken_20));
}
} else {
mStatsForLabel.setVisibility(View.GONE);
}
}
use of android.util.SparseBooleanArray in project XobotOS by xamarin.
the class ListView method getCheckItemIds.
/**
* Returns the set of checked items ids. The result is only valid if the
* choice mode has not been set to {@link #CHOICE_MODE_NONE}.
*
* @return A new array which contains the id of each checked item in the
* list.
*
* @deprecated Use {@link #getCheckedItemIds()} instead.
*/
@Deprecated
public long[] getCheckItemIds() {
// Use new behavior that correctly handles stable ID mapping.
if (mAdapter != null && mAdapter.hasStableIds()) {
return getCheckedItemIds();
}
// Fall back to it to support legacy apps.
if (mChoiceMode != CHOICE_MODE_NONE && mCheckStates != null && mAdapter != null) {
final SparseBooleanArray states = mCheckStates;
final int count = states.size();
final long[] ids = new long[count];
final ListAdapter adapter = mAdapter;
int checkedCount = 0;
for (int i = 0; i < count; i++) {
if (states.valueAt(i)) {
ids[checkedCount++] = adapter.getItemId(states.keyAt(i));
}
}
// resulting in checkedCount being smaller than count.
if (checkedCount == count) {
return ids;
} else {
final long[] result = new long[checkedCount];
System.arraycopy(ids, 0, result, 0, checkedCount);
return result;
}
}
return new long[0];
}
Aggregations