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];
}
use of android.util.SparseBooleanArray in project platform_frameworks_base by android.
the class ActionMenuPresenter method flagActionItems.
public boolean flagActionItems() {
final ArrayList<MenuItemImpl> visibleItems;
final int itemsSize;
if (mMenu != null) {
visibleItems = mMenu.getVisibleItems();
itemsSize = visibleItems.size();
} else {
visibleItems = null;
itemsSize = 0;
}
int maxActions = mMaxItems;
int widthLimit = mActionItemWidthLimit;
final int querySpec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED);
final ViewGroup parent = (ViewGroup) mMenuView;
int requiredItems = 0;
int requestedItems = 0;
int firstActionWidth = 0;
boolean hasOverflow = false;
for (int i = 0; i < itemsSize; i++) {
MenuItemImpl item = visibleItems.get(i);
if (item.requiresActionButton()) {
requiredItems++;
} else if (item.requestsActionButton()) {
requestedItems++;
} else {
hasOverflow = true;
}
if (mExpandedActionViewsExclusive && item.isActionViewExpanded()) {
// Overflow everything if we have an expanded action view and we're
// space constrained.
maxActions = 0;
}
}
// Reserve a spot for the overflow item if needed.
if (mReserveOverflow && (hasOverflow || requiredItems + requestedItems > maxActions)) {
maxActions--;
}
maxActions -= requiredItems;
final SparseBooleanArray seenGroups = mActionButtonGroups;
seenGroups.clear();
int cellSize = 0;
int cellsRemaining = 0;
if (mStrictWidthLimit) {
cellsRemaining = widthLimit / mMinCellSize;
final int cellSizeRemaining = widthLimit % mMinCellSize;
cellSize = mMinCellSize + cellSizeRemaining / cellsRemaining;
}
// Flag as many more requested items as will fit.
for (int i = 0; i < itemsSize; i++) {
MenuItemImpl item = visibleItems.get(i);
if (item.requiresActionButton()) {
View v = getItemView(item, null, parent);
if (mStrictWidthLimit) {
cellsRemaining -= ActionMenuView.measureChildForCells(v, cellSize, cellsRemaining, querySpec, 0);
} else {
v.measure(querySpec, querySpec);
}
final int measuredWidth = v.getMeasuredWidth();
widthLimit -= measuredWidth;
if (firstActionWidth == 0) {
firstActionWidth = measuredWidth;
}
final int groupId = item.getGroupId();
if (groupId != 0) {
seenGroups.put(groupId, true);
}
item.setIsActionButton(true);
} else if (item.requestsActionButton()) {
// Items in a group with other items that already have an action slot
// can break the max actions rule, but not the width limit.
final int groupId = item.getGroupId();
final boolean inGroup = seenGroups.get(groupId);
boolean isAction = (maxActions > 0 || inGroup) && widthLimit > 0 && (!mStrictWidthLimit || cellsRemaining > 0);
if (isAction) {
View v = getItemView(item, null, parent);
if (mStrictWidthLimit) {
final int cells = ActionMenuView.measureChildForCells(v, cellSize, cellsRemaining, querySpec, 0);
cellsRemaining -= cells;
if (cells == 0) {
isAction = false;
}
} else {
v.measure(querySpec, querySpec);
}
final int measuredWidth = v.getMeasuredWidth();
widthLimit -= measuredWidth;
if (firstActionWidth == 0) {
firstActionWidth = measuredWidth;
}
if (mStrictWidthLimit) {
isAction &= widthLimit >= 0;
} else {
// Did this push the entire first item past the limit?
isAction &= widthLimit + firstActionWidth > 0;
}
}
if (isAction && groupId != 0) {
seenGroups.put(groupId, true);
} else if (inGroup) {
// We broke the width limit. Demote the whole group, they all overflow now.
seenGroups.put(groupId, false);
for (int j = 0; j < i; j++) {
MenuItemImpl areYouMyGroupie = visibleItems.get(j);
if (areYouMyGroupie.getGroupId() == groupId) {
// Give back the action slot
if (areYouMyGroupie.isActionButton())
maxActions++;
areYouMyGroupie.setIsActionButton(false);
}
}
}
if (isAction)
maxActions--;
item.setIsActionButton(isAction);
} else {
// Neither requires nor requests an action button.
item.setIsActionButton(false);
}
}
return true;
}
use of android.util.SparseBooleanArray in project platform_frameworks_base by android.
the class AbsListView method setChoiceMode.
/**
* Defines the choice behavior for the List. By default, Lists do not have any choice behavior
* ({@link #CHOICE_MODE_NONE}). By setting the choiceMode to {@link #CHOICE_MODE_SINGLE}, the
* List allows up to one item to be in a chosen state. By setting the choiceMode to
* {@link #CHOICE_MODE_MULTIPLE}, the list allows any number of items to be chosen.
*
* @param choiceMode One of {@link #CHOICE_MODE_NONE}, {@link #CHOICE_MODE_SINGLE}, or
* {@link #CHOICE_MODE_MULTIPLE}
*/
public void setChoiceMode(int choiceMode) {
mChoiceMode = choiceMode;
if (mChoiceActionMode != null) {
mChoiceActionMode.finish();
mChoiceActionMode = null;
}
if (mChoiceMode != CHOICE_MODE_NONE) {
if (mCheckStates == null) {
mCheckStates = new SparseBooleanArray(0);
}
if (mCheckedIdStates == null && mAdapter != null && mAdapter.hasStableIds()) {
mCheckedIdStates = new LongSparseArray<Integer>(0);
}
// Modal multi-choice mode only has choices when the mode is active. Clear them.
if (mChoiceMode == CHOICE_MODE_MULTIPLE_MODAL) {
clearChoices();
setLongClickable(true);
}
}
}
Aggregations