Java Code Examples for java.util.ArrayList.get()

The following are Jave code examples for showing how to use get() of the java.util.ArrayList class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: FlickLauncher   File: DragController.java   View Source Code Vote up 6 votes
private DropTarget findDropTarget(int x, int y, int[] dropCoordinates) {
    final Rect r = mRectTemp;

    final ArrayList<DropTarget> dropTargets = mDropTargets;
    final int count = dropTargets.size();
    for (int i=count-1; i>=0; i--) {
        DropTarget target = dropTargets.get(i);
        if (!target.isDropEnabled())
            continue;

        target.getHitRectRelativeToDragLayer(r);

        mDragObject.x = x;
        mDragObject.y = y;
        if (r.contains(x, y)) {

            dropCoordinates[0] = x;
            dropCoordinates[1] = y;
            mLauncher.getDragLayer().mapCoordInSelfToDescendent((View) target, dropCoordinates);

            return target;
        }
    }
    return null;
}
 
Example 2
Project: rskj   File: RLPTest.java   View Source Code Vote up 6 votes
@Test
public void encodeDecodeShortListWithTwoByteArraysWithElementsLength56() {
    byte[] value1 = new byte[26];
    byte[] value2 = new byte[28];
    byte[] element1 = RLP.encodeElement(value1);
    byte[] element2 = RLP.encodeElement(value2);
    byte[] encoded = RLP.encodeList(element1, element2);

    Assert.assertNotNull(encoded);
    Assert.assertEquals(1 + 1 + 1 + 26 + 1 + 28, encoded.length);
    Assert.assertEquals((byte)(247 + 1), encoded[0]);
    Assert.assertEquals((byte)(56), encoded[1]);

    ArrayList<RLPElement> list = RLP.decode2(encoded);

    Assert.assertNotNull(list);
    Assert.assertEquals(1, list.size());

    RLPList list2 = (RLPList) list.get(0);

    Assert.assertNotNull(list2);
    Assert.assertEquals(2, list2.size());
    Assert.assertArrayEquals(value1, list2.get(0).getRLPData());
    Assert.assertArrayEquals(value2, list2.get(1).getRLPData());
}
 
Example 3
Project: FlickLauncher   File: LauncherModel.java   View Source Code Vote up 6 votes
static void updateItemsInDatabaseHelper(Context context, final ArrayList<ContentValues> valuesList,
        final ArrayList<ItemInfo> items, final String callingFunction) {
    final ContentResolver cr = context.getContentResolver();

    final StackTraceElement[] stackTrace = new Throwable().getStackTrace();
    Runnable r = new Runnable() {
        public void run() {
            ArrayList<ContentProviderOperation> ops =
                    new ArrayList<ContentProviderOperation>();
            int count = items.size();
            for (int i = 0; i < count; i++) {
                ItemInfo item = items.get(i);
                final long itemId = item.id;
                final Uri uri = LauncherSettings.Favorites.getContentUri(itemId);
                ContentValues values = valuesList.get(i);

                ops.add(ContentProviderOperation.newUpdate(uri).withValues(values).build());
                updateItemArrays(item, itemId, stackTrace);

            }
            try {
                cr.applyBatch(LauncherProvider.AUTHORITY, ops);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    };
    runOnWorkerThread(r);
}
 
Example 4
Project: PengueeBot   File: FragMono.java   View Source Code Vote up 6 votes
private void prepareMonoPixelMap() {
	int[] row_cache = null;
	final int line = rgbData.length;
	final int column = rgbData[0].length;
	ArrayList<Point> al = new ArrayList<Point>();

	// Point first = null;

	for (int y = 0; y < line; y++) {
		row_cache = rgbData[y];
		for (int x = 0; x < column; x++)
			if (row_cache[x] == monoColor)
				al.add(new Point(x, y));
	}

	monoXY_Map = new int[2][al.size()];
	for (int i = 0; i < al.size(); i++) {
		Point p = (Point) al.get(i);
		monoXY_Map[0][i] = (int) p.getX();
		monoXY_Map[1][i] = (int) p.getY();
	}
	rgbData = null;
}
 
Example 5
Project: boohee_v5.6   File: PLA_ListView.java   View Source Code Vote up 6 votes
public boolean isFixedView(View v) {
    int i;
    ArrayList<FixedViewInfo> where = this.mHeaderViewInfos;
    int len = where.size();
    for (i = 0; i < len; i++) {
        if (((FixedViewInfo) where.get(i)).view == v) {
            return true;
        }
    }
    where = this.mFooterViewInfos;
    len = where.size();
    for (i = 0; i < len; i++) {
        if (((FixedViewInfo) where.get(i)).view == v) {
            return true;
        }
    }
    return false;
}
 
Example 6
Project: P-BrainAndroid   File: MainActivity.java   View Source Code Vote up 6 votes
private boolean requestPermissions() throws PackageManager.NameNotFoundException {
    PackageInfo info = getPackageManager().getPackageInfo(getPackageName(), PackageManager.GET_PERMISSIONS);
    ArrayList<String> toRequest = new ArrayList<>();
    if (info.requestedPermissions != null) {
        for (String p : info.requestedPermissions) {
            if (ContextCompat.checkSelfPermission(this, p) != PackageManager.PERMISSION_GRANTED) {
                toRequest.add(p);
            }
        }
    }

    if (toRequest.size() > 0) {
        String[] tra = new String[toRequest.size()];
        for (int i = 0; i < tra.length; i++) {
            tra[i] = toRequest.get(i);
        }
        ActivityCompat.requestPermissions(this, tra, PERMISSION_RESULT);
    }
    return toRequest.size() == 0;
}
 
Example 7
Project: LaunchEnr   File: ModelWriter.java   View Source Code Vote up 6 votes
/**
 * Move items in the DB to a new <container, screen, cellX, cellY>. We assume that the
 * cellX, cellY have already been updated on the ItemInfos.
 */
public void moveItemsInDatabase(final ArrayList<ItemInfo> items, long container, int screen) {
    ArrayList<ContentValues> contentValues = new ArrayList<>();
    int count = items.size();

    for (int i = 0; i < count; i++) {
        ItemInfo item = items.get(i);
        updateItemInfoProps(item, container, screen, item.cellX, item.cellY);

        final ContentValues values = new ContentValues();
        values.put(Favorites.CONTAINER, item.container);
        values.put(Favorites.CELLX, item.cellX);
        values.put(Favorites.CELLY, item.cellY);
        values.put(Favorites.RANK, item.rank);
        values.put(Favorites.SCREEN, item.screenId);

        contentValues.add(values);
    }
    mWorkerExecutor.execute(new UpdateItemsRunnable(items, contentValues));
}
 
Example 8
Project: GitHub   File: CheckTreeSelectionModel.java   View Source Code Vote up 6 votes
private TreeNode[] getPathToRoot(TreeNode aNode) {
    TreeNode[] retNodes;
    ArrayList<TreeNode> temp = new ArrayList<TreeNode>();

    /* Check for null, in case someone passed in a null node, or
    they passed in an element that isn't rooted at root. */
    while (aNode != null) {
        temp.add(aNode);
        aNode = aNode.getParent();
    }

    int num = temp.size();
    retNodes = new TreeNode[num];
    for (int i = num - 1; i >= 0; i--) {
        retNodes[num - 1 - i] = temp.get(i);
    }

    return retNodes;
}
 
Example 9
Project: NICON   File: GenericPDFs.java   View Source Code Vote up 6 votes
private static void calTotalValores(ArrayList<Object[]> list) {
    Double valor;
    valoresTotal = new String[list.get(0).length];
    for (Object[] value : list) {
        for (int j = 0; j < value.length; j++) {
            for (int k = 0; k < arrValoresTotal.length; k++) {
                if (j == arrValoresTotal[k]) {
                    System.err.println(value[j]);
                    valor = ((valoresTotal[j] == null) ? 0.0 : Moeda.unFormat(valoresTotal[j].replaceAll(" ", "").replaceAll(",", ".").replaceAll("STD", "")));
                    valor += Moeda.unFormat(toString(value[j]).replaceAll(" ", "").replaceAll(",", ".").replaceAll("STD", ""));
                    valoresTotal[j] = Moeda.format(valor);
                }
            }
        }
    }

    if (!Arrays.toString(arrValoresTotal).contains("0")) {
        valoresTotal[0] = "TOTAL";
    }

    list.add(valoresTotal);
}
 
Example 10
Project: OpenHub   File: FragmentPagerModel.java   View Source Code Vote up 5 votes
private static BaseFragment getFragment(ArrayList<Fragment> fragments
            , int position, FragmentCreator fragmentCreator){
        Fragment fragment  = fragments.get(position);
        if(fragment == null){
            fragment = fragmentCreator.createFragment();
//            Logger.d("create fragment " + fragment + (Math.random() * 1000 * 1000));
        }else{
//            Logger.d("reuse fragment" + fragment + (Math.random() * 1000 * 1000));
        }
        return (BaseFragment) fragment;
    }
 
Example 11
Project: browser   File: AppMenuActivity.java   View Source Code Vote up 5 votes
void initOverflowItems() {

		ArrayList<String> menus = getMenuList();
		if (mItems == null) {
			int siz = menus.size();
			if (siz == 0) {
				return;
			}
			mItems = new OverflowAdapter.OverflowItem[siz];
		}
		for (int i = 0; i < mItems.length; i++) {
			mItems[i] = new OverflowAdapter.OverflowItem(menus.get(i));
		}

	}
 
Example 12
Project: Lernkartei_2017   File: Rangliste.java   View Source Code Vote up 5 votes
private static void fillNamesAndPoints(ArrayList<String> Stack, ArrayList<Double> Points)
{
	for (int i = 0; i < Stack.size(); i++)
	{
		String p = (Points.get(i)).toString();
		String s = (Stack.get(i));
		String together = s + "     " + p;
		NamesAndPoints.add(together);
	}
}
 
Example 13
Project: email-newsletter-generator   File: EmailTemplateMakerProgram.java   View Source Code Vote up 5 votes
private void _readAndApplyThemeFromHtmlLine(ArrayList<String> htmlLines) {
    for (int i = 0; i < htmlLines.size(); i++) {
        String htmlLine = htmlLines.get(i);
        htmlLine = this._getHtmlLineAfterReadingProperties(htmlLine);
        htmlLines.set(i, htmlLine);
    }
}
 
Example 14
Project: GitJourney   File: FetchAddressIntentService.java   View Source Code Vote up 5 votes
@Override
protected void onHandleIntent(@Nullable Intent intent) {
    Log.v(TAG, "onHandleIntent");
    Geocoder geocoder = new Geocoder(this, Locale.getDefault());
    String errorMessage = "";
    // Get the location passed to this service through an extra.
    ArrayList<GitHubUserLocationDataEntry> locationsList = intent.getParcelableArrayListExtra(
            LocationConstants.LOCATION_DATA_EXTRA);
    ResultReceiver mReceiver = intent.getParcelableExtra(
            LocationConstants.RECEIVER);
    try {
        for (int i = 0; i < locationsList.size(); i++) {
            GitHubUserLocationDataEntry entry = locationsList.get(i);
            List<Address> addressList = geocoder.getFromLocationName(entry.getLocation(), 1);
            if (!addressList.isEmpty()) {
                Address address = addressList.get(0);
                entry.setLatitude(address.getLatitude());
                entry.setLongitude(address.getLongitude());
            }
        }
    } catch (IOException ioException) {
        // Catch network or other I/O problems.
        errorMessage = getString(R.string.service_not_available);
        Log.e(TAG, errorMessage, ioException);
    } catch (IllegalArgumentException illegalArgumentException) {
        // Catch invalid latitude or longitude values.
        errorMessage = getString(R.string.invalid_lat_long_used);
        Log.e(TAG, errorMessage, illegalArgumentException);
    }
    Bundle bundle = new Bundle();
    bundle.putParcelableArrayList(LocationConstants.LOCATION_DATA_EXTRA, locationsList);
    mReceiver.send(0, bundle);
}
 
Example 15
Project: youkes_browser   File: ImageUtil.java   View Source Code Vote up 5 votes
public static ArrayList<String> processImageDisplayUrl(
		ArrayList<String> imgs) {
		ArrayList<String> ret=new ArrayList<String>();
		
	for(int i=0;i<imgs.size();i++){
		String img=imgs.get(i);
		if(img.indexOf("http")==0){
			ret.add(img);
		}else{
			ret.add("file://"+img);
		}
	}
	return ret;
}
 
Example 16
Project: echo   File: Interpolation.java   View Source Code Vote up 4 votes
protected Map doTaskLogic(Map map) 
{	
	String sensorId = (String) map.get("SENSORID");
	Set<Map.Entry<String, String>> entrySet = map.entrySet();
	String currentVal ;
	Float sum = 0.0f; 
	
	//Window size zero indicates no interpolation needed
	if(interpolCountWindowSize == 0 || sensorId == null || entrySet.size() == 0 )
	{
		return map;
	}
	for (Entry<String, String> entry : entrySet) 
	{
		String obsType = entry.getKey();
		
		//We need to operate only on fields specified in useMsgField 
		if(useMsgField.contains(obsType))
		{
			currentVal = (String)map.get(obsType);
			String key = sensorId + obsType;
			
			//If map contains past values 
			if(valuesMap.containsKey(key))
			{
				ArrayList<Float> values = valuesMap.get(key);
				
				//Interpolation needs to be done only if current value is null
				if(currentVal.equals("null"))
				{
					for(int i =0 ; i < values.size() ; i++)
					{
						sum = sum +values.get(i);
					}
					currentVal= (sum/ values.size())+"";
					map.put(key, currentVal);
				}
				//Since the current value is not null , just add the values limiting array to the window size
				else 
				{
				  if (values.size() == interpolCountWindowSize)
					  values.remove(0);
				  
				  values.add(Float.parseFloat(currentVal));
				  valuesMap.put(key, values);
				  map.put(key, currentVal);
				}
			}
			//No past values Adding sensorId + obsType as key for first time 
			else if(!currentVal.equals("null"))
			{
				ArrayList<Float> list = new ArrayList<Float>();
				list.add(Float.parseFloat(currentVal));
				valuesMap.put(key, list);
				map.put(key, currentVal);
			}
		}
	}
	
	return map ;
}
 
Example 17
Project: arez   File: ObserverErrorHandlerSupportTest.java   View Source Code Vote up 4 votes
@Test
public void onObserverError_whereOneHandlerGeneratesError()
{
  final ObserverErrorHandlerSupport support = new ObserverErrorHandlerSupport();

  final ArezContext context = new ArezContext();
  final Observer observer = newReadOnlyObserver( context );
  final ObserverError error = ObserverError.ON_ACTIVATE_ERROR;
  final Throwable throwable = null;

  final AtomicInteger callCount1 = new AtomicInteger();
  final AtomicInteger callCount3 = new AtomicInteger();

  final RuntimeException exception = new RuntimeException( "X" );

  final ObserverErrorHandler handler1 = ( observerArg, errorArg, throwableArg ) -> callCount1.incrementAndGet();
  final ObserverErrorHandler handler2 = ( observerArg, errorArg, throwableArg ) -> {
    throw exception;
  };
  final ObserverErrorHandler handler3 = ( observerArg, errorArg, throwableArg ) -> callCount3.incrementAndGet();
  support.addObserverErrorHandler( handler1 );
  support.addObserverErrorHandler( handler2 );
  support.addObserverErrorHandler( handler3 );

  support.onObserverError( observer, error, throwable );

  assertEquals( callCount1.get(), 1 );
  assertEquals( callCount3.get(), 1 );

  final ArrayList<TestLogger.LogEntry> entries = getTestLogger().getEntries();
  assertEquals( entries.size(), 1 );
  final TestLogger.LogEntry entry1 = entries.get( 0 );
  assertEquals( entry1.getMessage(),
                "Exception when notifying error handler '" + handler2 + "' of 'ON_ACTIVATE_ERROR' error " +
                "in observer named '" + observer.getName() + "'." );
  assertEquals( entry1.getThrowable(), exception );

  support.onObserverError( observer, error, throwable );

  assertEquals( callCount1.get(), 2 );
  assertEquals( callCount3.get(), 2 );

  assertEquals( getTestLogger().getEntries().size(), 2 );
}
 
Example 18
Project: Kaeon-FUSION   File: Append.java   View Source Code Vote up 4 votes
@SuppressWarnings("rawtypes")
public Object process(Element element, ArrayList<Object> processed) {
	
	if(processed.get(0) instanceof ArrayList) {

		@SuppressWarnings("unchecked")
		ArrayList<Object> list = (ArrayList) processed.get(0);
		
		for(int i = 1; i < processed.size(); i++)
			list.add(processed.get(i));
	}
	
	if(processed.get(0) instanceof String) {
		
		Object stringObject = processed.get(0);
		
		for(int i = 1; i < processed.size(); i++)
			stringObject = ((String) stringObject) + processed.get(i);
	}
	
	return null;
}
 
Example 19
Project: BingoChess   File: BingoChessChallenge.java   View Source Code Vote up 4 votes
private ChessPlayer getChessPlayer(String handle) {
	ArrayList<ChessPlayer> playlist = getPlayerlist(handle);
	if (!playlist.isEmpty()) return playlist.get(0); //TODO: multiple games?
	else return null;
}
 
Example 20
Project: Kaeon-FUSION   File: AlterDatabase.java   View Source Code Vote up 3 votes
public Object onProcess(Element element, ArrayList<Object> processed) {
	
	String query = "ALTER DATABASE ";
	
	for(int i = 0; i < processed.size(); i++)
		query += processed.get(i) + " ";
	
	return query;
}