List of usage examples for android.util SparseIntArray SparseIntArray
public SparseIntArray(int initialCapacity)
From source file:org.totschnig.myexpenses.ui.CursorFragmentPagerAdapter.java
public void setItemPositions() { mItemPositions = null;/*from w w w. j av a2 s . c om*/ if (mDataValid) { int count = mCursor.getCount(); mItemPositions = new SparseIntArray(count); mCursor.moveToPosition(-1); while (mCursor.moveToNext()) { int rowId = mCursor.getInt(mRowIDColumn); int cursorPos = mCursor.getPosition(); mItemPositions.append(rowId, cursorPos); } } }
From source file:com.artioml.practice.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar);/*from w w w . jav a 2 s . c o m*/ ImageButton settingsButton = (ImageButton) findViewById(R.id.settingsButton); settingsButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { MainSettingsDialog mainSettingsDialog = new MainSettingsDialog(MainActivity.this); mainSettingsDialog.show(); } }); fillSettingsPanel(); AudioAttributes.Builder attrBuilder = new AudioAttributes.Builder(); attrBuilder.setUsage(AudioAttributes.USAGE_GAME); SoundPool.Builder builder = new SoundPool.Builder(); builder.setMaxStreams(1); builder.setAudioAttributes(attrBuilder.build()); soundPool = builder.build(); soundMap = new SparseIntArray(1); soundMap.put(0, soundPool.load(getBaseContext(), R.raw.fire, 1)); punchButton = (Button) findViewById(R.id.punchButton); punchButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { punchButton.setEnabled(false); (new Handler()).postDelayed(new Runnable() { @Override public void run() { soundPool.play(soundMap.get(0), 1, 1, 1, 0, 1f); reaction = 0.00f; maxAcceleration = 0; count = 0; data = new ArrayList<>(); SensorManager sensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE); sensorManager.registerListener(sensorEventListener, sensorManager.getDefaultSensor(Sensor.TYPE_LINEAR_ACCELERATION), 1000); } }, 2000); } }); Button historyButton = (Button) findViewById(R.id.historyButton); historyButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Intent historyIntent = new Intent(MainActivity.this, HistoryActivity.class); startActivity(historyIntent); } }); }
From source file:com.example.maxuan.photoutils.ViewPagerActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_select_viewpager); mViewPager = (HackyViewPager) findViewById(R.id.view_pager); recyclerView = (RecyclerView) findViewById(R.id.recyclerView); cancelBtn = (ImageView) findViewById(R.id.selectCancel); cancelBtn.setOnClickListener(this); selectCheckBox = (CheckBox) findViewById(R.id.checkbox); selectCheckBox.setOnClickListener(this); completeBtn = (Button) findViewById(R.id.completeBtn); completeBtn.setOnClickListener(this); photos = new ArrayList<>(); posArray = new SparseIntArray(10); adapter = new PhotoPagerAdapter(this, photos); mViewPager.setAdapter(adapter);/*from w w w . j ava 2 s . c o m*/ mViewPager.addOnPageChangeListener(this); Intent intent = getIntent(); if (intent != null) { Bundle bundle = intent.getBundleExtra("data"); if (bundle == null) return; selectedPhotoArray = bundle.getSparseParcelableArray("selectedPhotos"); completeBtn.setText(String.format(format, selectedPhotoArray.size())); List<Photo> list = bundle.getParcelableArrayList("photos"); if (list != null) photos.addAll(list); for (int i = 0; i < photos.size(); ++i) { posArray.put(photos.get(i).id, i); } position = bundle.getInt("position", 0); maxCount = bundle.getInt("maxCount", 9); adapter.notifyDataSetChanged(); mViewPager.setCurrentItem(position); selectCheckBox.setChecked(selectedPhotoArray.indexOfKey(photos.get(position).id) >= 0); } selectedPhotoAdapter = new SelectedPhotoAdapter(this); LinearLayoutManager layoutManager = new LinearLayoutManager(this); layoutManager.setOrientation(LinearLayoutManager.HORIZONTAL); layoutManager.setReverseLayout(true); recyclerView.setLayoutManager(layoutManager); recyclerView.setAdapter(selectedPhotoAdapter); recyclerView.setVisibility(selectedPhotoArray.size() > 0 ? View.VISIBLE : View.GONE); if (savedInstanceState != null) { boolean isLocked = savedInstanceState.getBoolean(ISLOCKED_ARG, false); ((HackyViewPager) mViewPager).setLocked(isLocked); } if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) return; getWindow().getDecorView() .setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_FULLSCREEN | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY); }
From source file:it.evilsocket.dsploit.core.System.java
public static void init(Context context) throws Exception { mContext = context;/*from www. jav a 2 s . c o m*/ try { mStoragePath = getSettings().getString("PREF_SAVE_PATH", Environment.getExternalStorageDirectory().toString()); mSessionName = "dsploit-session-" + java.lang.System.currentTimeMillis(); mUpdateManager = new UpdateManager(mContext); mPlugins = new ArrayList<Plugin>(); mTargets = new Vector<Target>(); mOpenPorts = new SparseIntArray(3); // if we are here, network initialization didn't throw any error, lock wifi WifiManager wifiManager = (WifiManager) mContext.getSystemService(Context.WIFI_SERVICE); if (mWifiLock == null) mWifiLock = wifiManager.createWifiLock(WifiManager.WIFI_MODE_FULL, "wifiLock"); if (mWifiLock.isHeld() == false) mWifiLock.acquire(); // wake lock if enabled if (getSettings().getBoolean("PREF_WAKE_LOCK", true) == true) { PowerManager powerManager = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE); if (mWakeLock == null) mWakeLock = powerManager.newWakeLock(PowerManager.FULL_WAKE_LOCK, "wakeLock"); if (mWakeLock.isHeld() == false) mWakeLock.acquire(); } // set ports try { HTTP_PROXY_PORT = Integer.parseInt(getSettings().getString("PREF_HTTP_PROXY_PORT", "8080")); HTTP_SERVER_PORT = Integer.parseInt(getSettings().getString("PREF_HTTP_SERVER_PORT", "8081")); HTTPS_REDIR_PORT = Integer.parseInt(getSettings().getString("PREF_HTTPS_REDIRECTOR_PORT", "8082")); } catch (NumberFormatException e) { HTTP_PROXY_PORT = 8080; HTTP_SERVER_PORT = 8081; HTTPS_REDIR_PORT = 8082; } mNmap = new NMap(mContext); mArpSpoof = new ArpSpoof(mContext); mEttercap = new Ettercap(mContext); mIptables = new IPTables(); mHydra = new Hydra(mContext); mTcpdump = new TcpDump(mContext); // initialize network data at the end mNetwork = new Network(mContext); Target network = new Target(mNetwork), gateway = new Target(mNetwork.getGatewayAddress(), mNetwork.getGatewayHardware()), device = new Target(mNetwork.getLocalAddress(), mNetwork.getLocalHardware()); gateway.setAlias(mNetwork.getSSID()); device.setAlias(android.os.Build.MODEL); mTargets.add(network); mTargets.add(gateway); mTargets.add(device); mInitialized = true; } catch (Exception e) { errorLogging(TAG, e); throw e; } }
From source file:org.csploit.android.core.System.java
public static void init(Context context) throws Exception { mContext = context;/*from w w w.j a va 2 s . c om*/ try { Logger.debug("initializing System..."); mStoragePath = getSettings().getString("PREF_SAVE_PATH", Environment.getExternalStorageDirectory().toString()); mSessionName = "csploit-session-" + java.lang.System.currentTimeMillis(); mKnownIssues = new KnownIssues(); mPlugins = new ArrayList<>(); mOpenPorts = new SparseIntArray(3); mServices = new HashMap<>(); mPorts = new HashMap<>(); // if we are here, network initialization didn't throw any error, lock wifi WifiManager wifiManager = (WifiManager) mContext.getSystemService(Context.WIFI_SERVICE); if (mWifiLock == null) mWifiLock = wifiManager.createWifiLock(WifiManager.WIFI_MODE_FULL, "wifiLock"); if (!mWifiLock.isHeld()) mWifiLock.acquire(); // wake lock if enabled if (getSettings().getBoolean("PREF_WAKE_LOCK", true)) { PowerManager powerManager = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE); if (mWakeLock == null) mWakeLock = powerManager.newWakeLock(PowerManager.FULL_WAKE_LOCK, "wakeLock"); if (!mWakeLock.isHeld()) mWakeLock.acquire(); } // set ports try { HTTP_PROXY_PORT = Integer.parseInt(getSettings().getString("PREF_HTTP_PROXY_PORT", "8080")); HTTP_SERVER_PORT = Integer.parseInt(getSettings().getString("PREF_HTTP_SERVER_PORT", "8081")); HTTPS_REDIR_PORT = Integer.parseInt(getSettings().getString("PREF_HTTPS_REDIRECTOR_PORT", "8082")); MSF_RPC_PORT = Integer.parseInt(getSettings().getString("MSF_RPC_PORT", "55553")); } catch (NumberFormatException e) { HTTP_PROXY_PORT = 8080; HTTP_SERVER_PORT = 8081; HTTPS_REDIR_PORT = 8082; MSF_RPC_PORT = 55553; } uncaughtReloadNetworkMapping(); ThreadHelper.getSharedExecutor().execute(new Runnable() { @Override public void run() { preloadServices(); preloadVendors(); } }); } catch (Exception e) { if (!(e instanceof NoRouteToHostException)) errorLogging(e); throw e; } }
From source file:com.tct.fw.ex.photo.adapters.BaseCursorPagerAdapter.java
/** * Sets the {@link #mItemPosition} instance variable with the current mapping of * row id to cursor position.//from w w w . ja v a2 s . co m */ private void setItemPosition() { if (mCursor == null || mCursor.isClosed()) { mItemPosition = null; return; } SparseIntArray itemPosition = new SparseIntArray(mCursor.getCount()); mCursor.moveToPosition(-1); while (mCursor.moveToNext()) { final int rowId = mCursor.getString(mRowIDColumn).hashCode(); final int position = mCursor.getPosition(); itemPosition.append(rowId, position); } mItemPosition = itemPosition; }
From source file:com.cxsplay.wallyskim.widget.flexbox.FlexboxLayout.java
private int[] sortOrdersIntoReorderedIndices(int childCount, List<Order> orders) { Collections.sort(orders);// ww w. java 2 s . c o m if (mOrderCache == null) { mOrderCache = new SparseIntArray(childCount); } mOrderCache.clear(); int[] reorderedIndices = new int[childCount]; int i = 0; for (Order order : orders) { reorderedIndices[i] = order.index; mOrderCache.append(i, order.order); i++; } return reorderedIndices; }
From source file:com.cxsplay.wallyskim.widget.flexbox.FlexboxLayout.java
/** * Returns if any of the children's {@link LayoutParams#order} attributes are changed * from the last measurement./* www . j a va 2 s. c o m*/ * * @return {@code true} if changed from the last measurement, {@code false} otherwise. */ private boolean isOrderChangedFromLastMeasurement() { int childCount = getChildCount(); if (mOrderCache == null) { mOrderCache = new SparseIntArray(childCount); } if (mOrderCache.size() != childCount) { return true; } for (int i = 0; i < childCount; i++) { View view = getChildAt(i); if (view == null) { continue; } LayoutParams lp = (LayoutParams) view.getLayoutParams(); if (lp.order != mOrderCache.get(i)) { return true; } } return false; }
From source file:com.anysoftkeyboard.keyboards.views.AnyKeyboardBaseView.java
public AnyKeyboardBaseView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); //creating the KeyDrawableStateProvider, as it suppose to be backward compatible int keyTypeFunctionAttrId = R.attr.key_type_function; int keyActionAttrId = R.attr.key_type_action; int keyActionTypeDoneAttrId = R.attr.action_done; int keyActionTypeSearchAttrId = R.attr.action_search; int keyActionTypeGoAttrId = R.attr.action_go; LayoutInflater inflate = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); // int previewLayout = 0; mPreviewKeyTextSize = -1;//from w w w . jav a 2s .c o m mPreviewLabelTextSize = -1; mPreviewKeyBackground = null; mPreviewKeyTextColor = 0xFFF; final int[] padding = new int[] { 0, 0, 0, 0 }; KeyboardTheme theme = KeyboardThemeFactory.getCurrentKeyboardTheme(context.getApplicationContext()); final int keyboardThemeStyleResId = getKeyboardStyleResId(theme); Log.d(TAG, "Will use keyboard theme " + theme.getName() + " id " + theme.getId() + " res " + keyboardThemeStyleResId); //creating a mapping from the remote Attribute IDs to my local attribute ID. //this is required in order to backward support any build-system (which may cause the attribute IDs to change) final SparseIntArray attributeIdMap = new SparseIntArray(R.styleable.AnyKeyboardViewTheme.length + R.styleable.AnyKeyboardViewIconsTheme.length + ACTION_KEY_TYPES.length + KEY_TYPES.length); final int[] remoteKeyboardThemeStyleable = KeyboardSupport.createBackwardCompatibleStyleable( R.styleable.AnyKeyboardViewTheme, context, theme.getPackageContext(), attributeIdMap); final int[] remoteKeyboardIconsThemeStyleable = KeyboardSupport.createBackwardCompatibleStyleable( R.styleable.AnyKeyboardViewIconsTheme, context, theme.getPackageContext(), attributeIdMap); HashSet<Integer> doneLocalAttributeIds = new HashSet<Integer>(); TypedArray a = theme.getPackageContext().obtainStyledAttributes(keyboardThemeStyleResId, remoteKeyboardThemeStyleable); final int n = a.getIndexCount(); for (int i = 0; i < n; i++) { final int remoteIndex = a.getIndex(i); final int localAttrId = attributeIdMap.get(remoteKeyboardThemeStyleable[remoteIndex]); if (setValueFromTheme(a, padding, localAttrId, remoteIndex)) { doneLocalAttributeIds.add(localAttrId); if (localAttrId == R.attr.keyBackground) { //keyTypeFunctionAttrId and keyActionAttrId are remote final int[] keyStateAttributes = KeyboardSupport.createBackwardCompatibleStyleable(KEY_TYPES, context, theme.getPackageContext(), attributeIdMap); keyTypeFunctionAttrId = keyStateAttributes[0]; keyActionAttrId = keyStateAttributes[1]; } } } a.recycle(); // taking icons int iconSetStyleRes = theme.getIconsThemeResId(); Log.d(TAG, "Will use keyboard icons theme " + theme.getName() + " id " + theme.getId() + " res " + iconSetStyleRes); if (iconSetStyleRes != 0) { a = theme.getPackageContext().obtainStyledAttributes(iconSetStyleRes, remoteKeyboardIconsThemeStyleable); final int iconsCount = a.getIndexCount(); for (int i = 0; i < iconsCount; i++) { final int remoteIndex = a.getIndex(i); final int localAttrId = attributeIdMap.get(remoteKeyboardIconsThemeStyleable[remoteIndex]); if (setKeyIconValueFromTheme(theme, a, localAttrId, remoteIndex)) { doneLocalAttributeIds.add(localAttrId); if (localAttrId == R.attr.iconKeyAction) { //keyActionTypeDoneAttrId and keyActionTypeSearchAttrId and keyActionTypeGoAttrId are remote final int[] keyStateAttributes = KeyboardSupport.createBackwardCompatibleStyleable( ACTION_KEY_TYPES, context, theme.getPackageContext(), attributeIdMap); keyActionTypeDoneAttrId = keyStateAttributes[0]; keyActionTypeSearchAttrId = keyStateAttributes[1]; keyActionTypeGoAttrId = keyStateAttributes[2]; } } } a.recycle(); } // filling what's missing KeyboardTheme fallbackTheme = KeyboardThemeFactory.getFallbackTheme(context.getApplicationContext()); final int keyboardFallbackThemeStyleResId = getKeyboardStyleResId(fallbackTheme); Log.d(TAG, "Will use keyboard fallback theme " + fallbackTheme.getName() + " id " + fallbackTheme.getId() + " res " + keyboardFallbackThemeStyleResId); a = fallbackTheme.getPackageContext().obtainStyledAttributes(keyboardFallbackThemeStyleResId, R.styleable.AnyKeyboardViewTheme); final int fallbackCount = a.getIndexCount(); for (int i = 0; i < fallbackCount; i++) { final int index = a.getIndex(i); final int attrId = R.styleable.AnyKeyboardViewTheme[index]; if (doneLocalAttributeIds.contains(attrId)) continue; Log.d(TAG, "Falling back theme res ID " + index); setValueFromTheme(a, padding, attrId, index); } a.recycle(); // taking missing icons int fallbackIconSetStyleId = fallbackTheme.getIconsThemeResId(); Log.d(TAG, "Will use keyboard fallback icons theme " + fallbackTheme.getName() + " id " + fallbackTheme.getId() + " res " + fallbackIconSetStyleId); a = fallbackTheme.getPackageContext().obtainStyledAttributes(fallbackIconSetStyleId, R.styleable.AnyKeyboardViewIconsTheme); final int fallbackIconsCount = a.getIndexCount(); for (int i = 0; i < fallbackIconsCount; i++) { final int index = a.getIndex(i); final int attrId = R.styleable.AnyKeyboardViewIconsTheme[index]; if (doneLocalAttributeIds.contains(attrId)) continue; Log.d(TAG, "Falling back icon res ID " + index); setKeyIconValueFromTheme(fallbackTheme, a, attrId, index); } a.recycle(); //creating the key-drawable state provider, as we suppose to have the entire data now mDrawableStatesProvider = new KeyDrawableStateProvider(keyTypeFunctionAttrId, keyActionAttrId, keyActionTypeDoneAttrId, keyActionTypeSearchAttrId, keyActionTypeGoAttrId); // settings. // don't forget that there are TWO paddings, the theme's and the // background image's padding! Drawable keyboardBabground = super.getBackground(); if (keyboardBabground != null) { Rect backgroundPadding = new Rect(); keyboardBabground.getPadding(backgroundPadding); padding[0] += backgroundPadding.left; padding[1] += backgroundPadding.top; padding[2] += backgroundPadding.right; padding[3] += backgroundPadding.bottom; } super.setPadding(padding[0], padding[1], padding[2], padding[3]); final Resources res = getResources(); mKeyboardDimens.setKeyboardMaxWidth(res.getDisplayMetrics().widthPixels - padding[0] - padding[2]); mPreviewPopup = new PopupWindow(context); if (mPreviewKeyTextSize > 0) { if (mPreviewLabelTextSize <= 0) mPreviewLabelTextSize = mPreviewKeyTextSize; mPreviewLayut = inflatePreviewWindowLayout(inflate); mPreviewText = (TextView) mPreviewLayut.findViewById(R.id.key_preview_text); mPreviewText.setTextColor(mPreviewKeyTextColor); mPreviewText.setTypeface(mKeyTextStyle); mPreviewIcon = (ImageView) mPreviewLayut.findViewById(R.id.key_preview_icon); mPreviewPopup.setBackgroundDrawable(mPreviewKeyBackground); mPreviewPopup.setContentView(mPreviewLayut); mShowPreview = mPreviewLayut != null; } else { mPreviewLayut = null; mPreviewText = null; mShowPreview = false; } mPreviewPopup.setTouchable(false); mPreviewPopup .setAnimationStyle((mAnimationLevel == AnimationsLevel.None) ? 0 : R.style.KeyPreviewAnimation); mDelayBeforePreview = 0; mDelayAfterPreview = 10; mMiniKeyboardParent = this; mMiniKeyboardPopup = new PopupWindow(context.getApplicationContext()); mMiniKeyboardPopup.setBackgroundDrawable(null); mMiniKeyboardPopup .setAnimationStyle((mAnimationLevel == AnimationsLevel.None) ? 0 : R.style.MiniKeyboardAnimation); mPaint = new Paint(); mPaint.setAntiAlias(true); mPaint.setTextSize(mKeyTextSize); mPaint.setTextAlign(Align.CENTER); mPaint.setAlpha(255); mKeyBackgroundPadding = new Rect(0, 0, 0, 0); mKeyBackground.getPadding(mKeyBackgroundPadding); reloadSwipeThresholdsSettings(res); mMiniKeyboardSlideAllowance = res.getDimension(R.dimen.mini_keyboard_slide_allowance); AskOnGestureListener listener = new AskGestureEventsListener(this); mGestureDetector = AnyApplication.getDeviceSpecific().createGestureDetector(getContext(), listener); mGestureDetector.setIsLongpressEnabled(false); MultiTouchSupportLevel multiTouchSupportLevel = AnyApplication.getDeviceSpecific() .getMultiTouchSupportLevel(getContext()); mHasDistinctMultitouch = multiTouchSupportLevel == MultiTouchSupportLevel.Distinct; mKeyRepeatInterval = 50; AnyApplication.getConfig().addChangedListener(this); }