Example usage for com.google.gwt.core.client JsArrayInteger get

List of usage examples for com.google.gwt.core.client JsArrayInteger get

Introduction

In this page you can find the example usage for com.google.gwt.core.client JsArrayInteger get.

Prototype

public final native int get(int index) ;

Source Link

Document

Gets the value at a given index.

Usage

From source file:com.haulmont.cuba.web.widgets.client.addons.aceeditor.AceEditorWidget.java

License:Apache License

public int[] getCursorCoords() {
    JsArrayInteger cc = editor.getCursorCoords();
    return new int[] { cc.get(0), cc.get(1) };
}

From source file:com.smartgwt.client.widgets.cube.CubeGrid.java

License:Open Source License

/**
 * Given a record in this grid, this method returns the coordinates of the cell in which the  record is displayed as a 2
 * element array./*from w  ww . j a v  a 2  s.com*/
 * @param cellRecord record to find coordinates for
 *
 * @return 2 element array containing <code>[rowNum,colNum]</code> for the cell, or                  <code>null</code> if the
 * record is not found.
 */
public int[] getCellCoordinates(CellRecord cellRecord) {
    com.google.gwt.core.client.JsArrayInteger cellCoodJS = doGetCellCoordinates(cellRecord.getJsObj());
    return new int[] { cellCoodJS.get(0), cellCoodJS.get(1) };
}

From source file:core.util.Base64.java

License:GNU General Public License

public static byte[] convert(JsArrayInteger a) {
    byte[] bytes = new byte[a.length()];
    for (int i = 0; i < a.length(); ++i)
        bytes[i] = (byte) a.get(i);

    return bytes;
}

From source file:core.util.StringsPlatform.java

License:GNU General Public License

public static byte[] toBytes(String s) {
    JsArrayInteger a = jsToBytes(s);
    byte[] bytes = new byte[a.length()];

    for (int i = 0; i < a.length(); ++i)
        bytes[i] = (byte) a.get(i);

    return bytes;
}

From source file:edu.caltech.ipac.firefly.visualize.WebPlotResultParser.java

private static void checkForIntAryResult(String key, WebPlotResult wpRes, PlotResultOverlay res) {
    JsArrayInteger jsAry = res.getIntArrayResult(key);
    if (jsAry != null) {
        int ary[] = new int[jsAry.length()];
        for (int i = 0; (i < ary.length); i++)
            ary[i] = jsAry.get(i);
        wpRes.putResult(key, new DataEntry.IntArray(ary));
    }/*from w w w  .  ja  v a2s .c om*/

}

From source file:gov.wa.wsdot.mobile.client.activities.home.HomeActivity.java

License:Open Source License

private void createFavoritesList() {

    getFavoriteLocations();//  w  w w  . ja  v  a 2s.  com

    dbService.getStarredCameras(new ListCallback<GenericRow>() {

        @Override
        public void onFailure(DataServiceException error) {

        }

        @Override
        public void onSuccess(List<GenericRow> result) {

            if (!result.isEmpty()) {
                cameraItems.clear();
                CameraItem c;

                for (GenericRow camera : result) {
                    c = new CameraItem();

                    c.setCameraId(camera.getInt(CamerasColumns.CAMERA_ID));
                    c.setTitle(camera.getString(CamerasColumns.CAMERA_TITLE));

                    cameraItems.add(c);
                }

                view.hideEmptyFavoritesMessage();
                view.showCamerasHeader();
                view.showCamerasList();
                view.renderCameras(cameraItems);
                view.refresh();
                accessibility.postScreenChangeNotification();

            } else {
                view.hideCamerasHeader();
                view.hideCamerasList();
            }

        }
    });

    dbService.getStarredFerriesSchedules(new ListCallback<GenericRow>() {

        @Override
        public void onFailure(DataServiceException error) {
        }

        @Override
        public void onSuccess(final List<GenericRow> starredFerriesSchedules) {
            if (!starredFerriesSchedules.isEmpty()) {
                /** 
                 * Check the cache table for the last time data was downloaded. If we are within
                 * the allowed time period, don't sync, otherwise get fresh data from the server.
                 */
                dbService.getCacheLastUpdated(Tables.FERRIES_SCHEDULES, new ListCallback<GenericRow>() {

                    @Override
                    public void onFailure(DataServiceException error) {
                    }

                    @Override
                    public void onSuccess(List<GenericRow> result) {
                        boolean shouldUpdate = true;

                        if (!result.isEmpty()) {
                            double now = System.currentTimeMillis();
                            double lastUpdated = result.get(0).getDouble(CachesColumns.CACHE_LAST_UPDATED);
                            shouldUpdate = (Math.abs(now - lastUpdated) > (30 * 60000)); // Refresh every 30 minutes.
                        }

                        //view.showProgressBar();

                        if (shouldUpdate) {
                            final List<Integer> starred = new ArrayList<Integer>();

                            for (GenericRow row : starredFerriesSchedules) {
                                starred.add(row.getInt(FerriesSchedulesColumns.FERRIES_SCHEDULE_ID));
                            }

                            JsonpRequestBuilder jsonp = new JsonpRequestBuilder();
                            // Set timeout for 30 seconds (30000 milliseconds)
                            jsonp.setTimeout(30000);
                            jsonp.requestObject(FERRIES_SCHEDULES_URL, new AsyncCallback<FerriesRouteFeed>() {

                                @Override
                                public void onFailure(Throwable caught) {
                                    //view.hideProgressBar();
                                    phoneGap.getNotification().alert("Can't load data. Check your connection.",
                                            new AlertCallback() {
                                                @Override
                                                public void onOkButtonClicked() {
                                                    // TODO Auto-generated method stub
                                                }
                                            }, "Connection Error");
                                }

                                @Override
                                public void onSuccess(FerriesRouteFeed result) {

                                    if (result.getRoutes() != null) {
                                        ferriesRouteItems.clear();
                                        FerriesRouteItem item;
                                        int numRoutes = result.getRoutes().length();

                                        for (int i = 0; i < numRoutes; i++) {
                                            item = new FerriesRouteItem();

                                            item.setRouteID(result.getRoutes().get(i).getRouteID());
                                            item.setDescription(result.getRoutes().get(i).getDescription());
                                            item.setCrossingTime(result.getRoutes().get(i).getCrossingTime());
                                            item.setScheduleDate(
                                                    new JSONArray(result.getRoutes().get(i).getDate())
                                                            .toString());
                                            item.setRouteAlert(
                                                    new JSONArray(result.getRoutes().get(i).getRouteAlert())
                                                            .toString());
                                            item.setCacheDate(dateFormat.format(new Date(Long.parseLong(result
                                                    .getRoutes().get(i).getCacheDate().substring(6, 19)))));

                                            if (starred.contains(result.getRoutes().get(i).getRouteID())) {
                                                item.setIsStarred(1);
                                            }

                                            ferriesRouteItems.add(item);
                                        }

                                        // Purge existing border wait times covered by incoming data
                                        dbService.deleteFerriesSchedules(new VoidCallback() {

                                            @Override
                                            public void onFailure(DataServiceException error) {
                                            }

                                            @Override
                                            public void onSuccess() {
                                                // Bulk insert all the new ferries schedules
                                                dbService.insertFerriesSchedules(ferriesRouteItems,
                                                        new RowIdListCallback() {

                                                            @Override
                                                            public void onFailure(DataServiceException error) {
                                                            }

                                                            @Override
                                                            public void onSuccess(List<Integer> rowIds) {
                                                                // Update the cache table with the time we did the update
                                                                List<CacheItem> cacheItems = new ArrayList<CacheItem>();
                                                                cacheItems.add(
                                                                        new CacheItem(Tables.FERRIES_SCHEDULES,
                                                                                System.currentTimeMillis()));
                                                                dbService.updateCachesTable(cacheItems,
                                                                        new VoidCallback() {

                                                                            @Override
                                                                            public void onFailure(
                                                                                    DataServiceException error) {
                                                                            }

                                                                            @Override
                                                                            public void onSuccess() {

                                                                                dbService
                                                                                        .getStarredFerriesSchedules(
                                                                                                new ListCallback<GenericRow>() {

                                                                                                    @Override
                                                                                                    public void onFailure(
                                                                                                            DataServiceException error) {
                                                                                                    }

                                                                                                    @Override
                                                                                                    public void onSuccess(
                                                                                                            final List<GenericRow> starredMountainPassRows) {
                                                                                                        getFerriesSchedules(
                                                                                                                starredFerriesSchedules);
                                                                                                    }
                                                                                                });
                                                                            }
                                                                        });
                                                            }
                                                        });
                                            }
                                        });
                                    }
                                }
                            });

                        } else {
                            getFerriesSchedules(starredFerriesSchedules);
                        }

                    }
                });

            } else {
                view.hideFerriesHeader();
                view.hideFerriesList();
            }
        }
    });

    dbService.getStarredMountainPasses(new ListCallback<GenericRow>() {

        @Override
        public void onFailure(DataServiceException error) {
        }

        @Override
        public void onSuccess(final List<GenericRow> starredMountainPassRows) {
            if (!starredMountainPassRows.isEmpty()) {
                /** 
                 * Check the cache table for the last time data was downloaded. If we are within
                 * the allowed time period, don't sync, otherwise get fresh data from the server.
                 */
                dbService.getCacheLastUpdated(Tables.MOUNTAIN_PASSES, new ListCallback<GenericRow>() {

                    @Override
                    public void onFailure(DataServiceException error) {
                    }

                    @Override
                    public void onSuccess(List<GenericRow> result) {
                        boolean shouldUpdate = true;

                        if (!result.isEmpty()) {
                            double now = System.currentTimeMillis();
                            double lastUpdated = result.get(0).getDouble(CachesColumns.CACHE_LAST_UPDATED);
                            shouldUpdate = (Math.abs(now - lastUpdated) > (15 * 60000)); // Refresh every 15 minutes.
                        }

                        //view.showProgressBar();

                        if (shouldUpdate) {
                            final List<Integer> starred = new ArrayList<Integer>();

                            for (GenericRow row : starredMountainPassRows) {
                                starred.add(row.getInt(MountainPassesColumns.MOUNTAIN_PASS_ID));
                            }

                            JsonpRequestBuilder jsonp = new JsonpRequestBuilder();
                            // Set timeout for 30 seconds (30000 milliseconds)
                            jsonp.setTimeout(30000);
                            jsonp.requestObject(MOUNTAIN_PASS_URL, new AsyncCallback<MountainPassConditions>() {

                                @Override
                                public void onFailure(Throwable caught) {
                                    //view.hideProgressBar();
                                    phoneGap.getNotification().alert("Can't load data. Check your connection.",
                                            new AlertCallback() {
                                                @Override
                                                public void onOkButtonClicked() {
                                                    // TODO Auto-generated method stub
                                                }
                                            }, "Connection Error");
                                }

                                @Override
                                public void onSuccess(MountainPassConditions result) {
                                    mountainPassItems.clear();

                                    if (result.getMountainPassConditionsResult() != null) {
                                        MountainPassItem item;

                                        String weatherCondition;
                                        String weatherImage;
                                        String forecast_weather_image;

                                        String mDateUpdated = "";

                                        int numConditions = result.getMountainPassConditionsResult()
                                                .getPassCondition().length();

                                        for (int i = 0; i < numConditions; i++) {
                                            item = new MountainPassItem();

                                            weatherCondition = result.getMountainPassConditionsResult()
                                                    .getPassCondition().get(i).getWeatherCondition();
                                            weatherImage = getWeatherImage(weatherPhrases, weatherCondition);

                                            JsArrayInteger dateUpdated = result
                                                    .getMountainPassConditionsResult().getPassCondition().get(i)
                                                    .getDateUpdated();

                                            try {
                                                StringBuilder sb = new StringBuilder();
                                                for (int j = 0; j < 5; j++) {
                                                    sb.append(dateUpdated.get(j));
                                                    sb.append(",");
                                                }
                                                String tempDate = sb.toString().trim();
                                                tempDate = tempDate.substring(0, tempDate.length() - 1);
                                                Date date = parseDateFormat.parse(tempDate);
                                                mDateUpdated = dateFormat.format(date);
                                            } catch (Exception e) {
                                                mDateUpdated = "N/A";
                                            }

                                            JsArray<Forecast> forecasts = result
                                                    .getMountainPassConditionsResult().getPassCondition().get(i)
                                                    .getForecast();
                                            int numForecasts = forecasts.length();

                                            for (int k = 0; k < numForecasts; k++) {
                                                Forecast forecast = forecasts.get(k);

                                                if (isNight(forecast.getDay())) {
                                                    forecast_weather_image = getWeatherImage(
                                                            weatherPhrasesNight, forecast.getForecastText());
                                                } else {
                                                    forecast_weather_image = getWeatherImage(weatherPhrases,
                                                            forecast.getForecastText());
                                                }

                                                forecast.setWeatherIcon(forecast_weather_image);

                                                if (k == 0) {
                                                    if (weatherCondition.equals("")) {
                                                        weatherCondition = forecast.getForecastText()
                                                                .split("\\.")[0] + ".";
                                                        weatherImage = forecast_weather_image;
                                                    }
                                                }

                                                forecasts.set(k, forecast);

                                            }

                                            item.setWeatherCondition(weatherCondition);
                                            item.setElevationInFeet(result.getMountainPassConditionsResult()
                                                    .getPassCondition().get(i).getElevationInFeet());
                                            item.setMountainPassId(result.getMountainPassConditionsResult()
                                                    .getPassCondition().get(i).getMountainPassId());
                                            item.setRoadCondition(result.getMountainPassConditionsResult()
                                                    .getPassCondition().get(i).getRoadCondition());
                                            item.setTemperatureInFahrenheit(
                                                    result.getMountainPassConditionsResult().getPassCondition()
                                                            .get(i).getTemperatureInFahrenheit());
                                            item.setDateUpdated(mDateUpdated);
                                            item.setMountainPassName(result.getMountainPassConditionsResult()
                                                    .getPassCondition().get(i).getMountainPassName());
                                            item.setWeatherIcon(weatherImage);
                                            item.setRestrictionOneText(
                                                    result.getMountainPassConditionsResult().getPassCondition()
                                                            .get(i).getRestrictionOne().getRestrictionText());
                                            item.setRestrictionOneTravelDirection(
                                                    result.getMountainPassConditionsResult().getPassCondition()
                                                            .get(i).getRestrictionOne().getTravelDirection());
                                            item.setRestrictionTwoText(
                                                    result.getMountainPassConditionsResult().getPassCondition()
                                                            .get(i).getRestrictionTwo().getRestrictionText());
                                            item.setRestrictionTwoTravelDirection(
                                                    result.getMountainPassConditionsResult().getPassCondition()
                                                            .get(i).getRestrictionTwo().getTravelDirection());
                                            item.setCamera(
                                                    new JSONArray(result.getMountainPassConditionsResult()
                                                            .getPassCondition().get(i).getCameras())
                                                                    .toString());
                                            item.setForecast(new JSONArray(forecasts).toString());

                                            if (starred.contains(result.getMountainPassConditionsResult()
                                                    .getPassCondition().get(i).getMountainPassId())) {
                                                item.setIsStarred(1);
                                            }

                                            mountainPassItems.add(item);
                                        }

                                        // Purge existing mountain passes covered by incoming data
                                        dbService.deleteMountainPasses(new VoidCallback() {

                                            @Override
                                            public void onFailure(DataServiceException error) {
                                            }

                                            @Override
                                            public void onSuccess() {
                                                // Bulk insert all the new mountain passes
                                                dbService.insertMountainPasses(mountainPassItems,
                                                        new RowIdListCallback() {

                                                            @Override
                                                            public void onFailure(DataServiceException error) {
                                                            }

                                                            @Override
                                                            public void onSuccess(List<Integer> rowIds) {
                                                                // Update the cache table with the time we did the update
                                                                ArrayList<CacheItem> cacheItems = new ArrayList<CacheItem>();
                                                                cacheItems.add(
                                                                        new CacheItem(Tables.MOUNTAIN_PASSES,
                                                                                System.currentTimeMillis()));

                                                                dbService.updateCachesTable(cacheItems,
                                                                        new VoidCallback() {

                                                                            @Override
                                                                            public void onFailure(
                                                                                    DataServiceException error) {
                                                                            }

                                                                            @Override
                                                                            public void onSuccess() {

                                                                                dbService
                                                                                        .getStarredMountainPasses(
                                                                                                new ListCallback<GenericRow>() {

                                                                                                    @Override
                                                                                                    public void onFailure(
                                                                                                            DataServiceException error) {
                                                                                                    }

                                                                                                    @Override
                                                                                                    public void onSuccess(
                                                                                                            final List<GenericRow> starredMountainPassRows) {
                                                                                                        getMountainPasses(
                                                                                                                starredMountainPassRows);
                                                                                                    }
                                                                                                });

                                                                            }
                                                                        });
                                                            }
                                                        });
                                            }
                                        });
                                    }
                                }
                            });

                        } else {
                            getMountainPasses(starredMountainPassRows);
                        }
                    }
                });

            } else {
                view.hideMountainPassesHeader();
                view.hideMountainPassesList();
            }

        }
    });

    dbService.getStarredTravelTimes(new ListCallback<GenericRow>() {

        @Override
        public void onFailure(DataServiceException error) {
        }

        @Override
        public void onSuccess(final List<GenericRow> starredTravelTimesRows) {
            if (!starredTravelTimesRows.isEmpty()) {
                /** 
                 * Check the cache table for the last time data was downloaded. If we are within
                 * the allowed time period, don't sync, otherwise get fresh data from the server.
                 */
                dbService.getCacheLastUpdated(Tables.TRAVEL_TIMES, new ListCallback<GenericRow>() {

                    @Override
                    public void onFailure(DataServiceException error) {
                    }

                    @Override
                    public void onSuccess(List<GenericRow> result) {
                        boolean shouldUpdate = true;

                        if (!result.isEmpty()) {
                            double now = System.currentTimeMillis();
                            double lastUpdated = result.get(0).getDouble(CachesColumns.CACHE_LAST_UPDATED);
                            shouldUpdate = (Math.abs(now - lastUpdated) > (5 * 60000)); // Refresh every 5 minutes.
                        }

                        //view.showProgressBar();

                        if (shouldUpdate) {
                            final List<Integer> starred = new ArrayList<Integer>();

                            for (GenericRow row : starredTravelTimesRows) {
                                starred.add(row.getInt(TravelTimesColumns.TRAVEL_TIMES_ID));
                            }

                            JsonpRequestBuilder jsonp = new JsonpRequestBuilder();
                            // Set timeout for 30 seconds (30000 milliseconds)
                            jsonp.setTimeout(30000);
                            jsonp.requestObject(TRAVEL_TIMES_URL, new AsyncCallback<TravelTimes>() {

                                @Override
                                public void onFailure(Throwable caught) {
                                    //view.hideProgressBar();
                                    phoneGap.getNotification().alert("Can't load data. Check your connection.",
                                            new AlertCallback() {
                                                @Override
                                                public void onOkButtonClicked() {
                                                    // TODO Auto-generated method stub
                                                }
                                            }, "Connection Error");
                                }

                                @Override
                                public void onSuccess(TravelTimes result) {

                                    if (result.getTravelTimes() != null) {
                                        travelTimesItems.clear();
                                        TravelTimesItem item;

                                        int numItems = result.getTravelTimes().getItems().length();

                                        for (int i = 0; i < numItems; i++) {
                                            item = new TravelTimesItem();

                                            item.setDistance(
                                                    result.getTravelTimes().getItems().get(i).getDistance());
                                            item.setUpdated(
                                                    result.getTravelTimes().getItems().get(i).getUpdated());
                                            item.setTitle(result.getTravelTimes().getItems().get(i).getTitle());
                                            item.setAverageTime(
                                                    result.getTravelTimes().getItems().get(i).getAverage());
                                            item.setRouteId(Integer.parseInt(
                                                    result.getTravelTimes().getItems().get(i).getRouteId(),
                                                    10));
                                            item.setCurrentTime(
                                                    result.getTravelTimes().getItems().get(i).getCurrent());

                                            if (starred.contains(Integer.parseInt(
                                                    result.getTravelTimes().getItems().get(i).getRouteId(),
                                                    10))) {
                                                item.setIsStarred(1);
                                            }

                                            travelTimesItems.add(item);
                                        }

                                        // Purge existing mountain passes covered by incoming data
                                        dbService.deleteTravelTimes(new VoidCallback() {

                                            @Override
                                            public void onFailure(DataServiceException error) {
                                            }

                                            @Override
                                            public void onSuccess() {
                                                // Bulk insert all the new travel times
                                                dbService.insertTravelTimes(travelTimesItems,
                                                        new RowIdListCallback() {

                                                            @Override
                                                            public void onFailure(DataServiceException error) {
                                                            }

                                                            @Override
                                                            public void onSuccess(List<Integer> rowIds) {
                                                                // Update the cache table with the time we did the update
                                                                ArrayList<CacheItem> cacheItems = new ArrayList<CacheItem>();
                                                                cacheItems
                                                                        .add(new CacheItem(Tables.TRAVEL_TIMES,
                                                                                System.currentTimeMillis()));

                                                                dbService.updateCachesTable(cacheItems,
                                                                        new VoidCallback() {

                                                                            @Override
                                                                            public void onFailure(
                                                                                    DataServiceException error) {
                                                                            }

                                                                            @Override
                                                                            public void onSuccess() {

                                                                                dbService.getStarredTravelTimes(
                                                                                        new ListCallback<GenericRow>() {

                                                                                            @Override
                                                                                            public void onFailure(
                                                                                                    DataServiceException error) {
                                                                                            }

                                                                                            @Override
                                                                                            public void onSuccess(
                                                                                                    final List<GenericRow> starredMountainPassRows) {
                                                                                                getTravelTimes(
                                                                                                        starredTravelTimesRows);
                                                                                            }
                                                                                        });
                                                                            }
                                                                        });
                                                            }
                                                        });
                                            }
                                        });
                                    }
                                }
                            });

                        } else {
                            getTravelTimes(starredTravelTimesRows);
                        }

                    }
                });

            } else {
                view.hideTravelTimesHeader();
                view.hideTravelTimesList();
            }
        }
    });

    view.showEmptyFavoritesMessage();
}

From source file:gov.wa.wsdot.mobile.client.activities.mountainpasses.MountainPassesActivity.java

License:Open Source License

private void createTopicsList(final boolean forceUpdate) {

    /** /* ww w .ja va 2  s  . co m*/
     * Check the cache table for the last time data was downloaded. If we are within
     * the allowed time period, don't sync, otherwise get fresh data from the server.
     */
    dbService.getCacheLastUpdated(Tables.MOUNTAIN_PASSES, new ListCallback<GenericRow>() {

        @Override
        public void onFailure(DataServiceException error) {
        }

        @Override
        public void onSuccess(List<GenericRow> result) {
            boolean shouldUpdate = true;

            if (!result.isEmpty()) {
                double now = System.currentTimeMillis();
                double lastUpdated = result.get(0).getDouble(CachesColumns.CACHE_LAST_UPDATED);
                shouldUpdate = (Math.abs(now - lastUpdated) > (15 * 60000)); // Refresh every 15 minutes.
            }

            view.showProgressIndicator();

            if (shouldUpdate || forceUpdate) {
                /**
                 * Check the mountain passes table for any starred entries. If we find some,
                 * save them to a list so we can re-star those after we flush the database.
                 */
                dbService.getStarredMountainPasses(new ListCallback<GenericRow>() {

                    @Override
                    public void onFailure(DataServiceException error) {
                    }

                    @Override
                    public void onSuccess(List<GenericRow> result) {
                        starred.clear();

                        if (!result.isEmpty()) {
                            for (GenericRow row : result) {
                                starred.add(row.getInt(MountainPassesColumns.MOUNTAIN_PASS_ID));
                            }
                        }

                        JsonpRequestBuilder jsonp = new JsonpRequestBuilder();
                        // Set timeout for 30 seconds (30000 milliseconds)
                        jsonp.setTimeout(30000);
                        jsonp.requestObject(MOUNTAIN_PASS_URL, new AsyncCallback<MountainPassConditions>() {

                            @Override
                            public void onFailure(Throwable caught) {
                                view.hideProgressIndicator();
                                if (!alertShowing) {
                                    alertShowing = true;
                                    phoneGap.getNotification().alert("Can't load data. Check your connection.",
                                            new AlertCallback() {
                                                @Override
                                                public void onOkButtonClicked() {
                                                    alertShowing = false;
                                                }
                                            }, "Connection Error");
                                }
                            }

                            @Override
                            public void onSuccess(MountainPassConditions result) {
                                mountainPassItems.clear();

                                if (result.getMountainPassConditionsResult() != null) {
                                    MountainPassItem item;

                                    String weatherCondition;
                                    String weatherImage;
                                    String forecast_weather_image;

                                    String mDateUpdated = "";

                                    int numConditions = result.getMountainPassConditionsResult()
                                            .getPassCondition().length();

                                    for (int i = 0; i < numConditions; i++) {
                                        item = new MountainPassItem();

                                        weatherCondition = result.getMountainPassConditionsResult()
                                                .getPassCondition().get(i).getWeatherCondition();
                                        weatherImage = getWeatherImage(weatherPhrases, weatherCondition);

                                        JsArrayInteger dateUpdated = result.getMountainPassConditionsResult()
                                                .getPassCondition().get(i).getDateUpdated();

                                        try {
                                            StringBuilder sb = new StringBuilder();
                                            for (int j = 0; j < 5; j++) {
                                                sb.append(dateUpdated.get(j));
                                                sb.append(",");
                                            }
                                            String tempDate = sb.toString().trim();
                                            tempDate = tempDate.substring(0, tempDate.length() - 1);
                                            Date date = parseDateFormat.parse(tempDate);
                                            mDateUpdated = displayDateFormat.format(date);
                                        } catch (Exception e) {
                                            mDateUpdated = "N/A";
                                        }

                                        JsArray<Forecast> forecasts = result.getMountainPassConditionsResult()
                                                .getPassCondition().get(i).getForecast();
                                        int numForecasts = forecasts.length();

                                        for (int k = 0; k < numForecasts; k++) {
                                            Forecast forecast = forecasts.get(k);

                                            if (isNight(forecast.getDay())) {
                                                forecast_weather_image = getWeatherImage(weatherPhrasesNight,
                                                        forecast.getForecastText());
                                            } else {
                                                forecast_weather_image = getWeatherImage(weatherPhrases,
                                                        forecast.getForecastText());
                                            }

                                            forecast.setWeatherIcon(forecast_weather_image);

                                            if (k == 0) {
                                                if (weatherCondition.equals("")) {
                                                    weatherCondition = forecast.getForecastText()
                                                            .split("\\.")[0] + ".";
                                                    weatherImage = forecast_weather_image;
                                                }
                                            }

                                            forecasts.set(k, forecast);

                                        }

                                        item.setWeatherCondition(weatherCondition);
                                        item.setElevationInFeet(result.getMountainPassConditionsResult()
                                                .getPassCondition().get(i).getElevationInFeet());
                                        item.setMountainPassId(result.getMountainPassConditionsResult()
                                                .getPassCondition().get(i).getMountainPassId());
                                        item.setRoadCondition(result.getMountainPassConditionsResult()
                                                .getPassCondition().get(i).getRoadCondition());
                                        item.setTemperatureInFahrenheit(result.getMountainPassConditionsResult()
                                                .getPassCondition().get(i).getTemperatureInFahrenheit());
                                        item.setDateUpdated(mDateUpdated);
                                        item.setMountainPassName(result.getMountainPassConditionsResult()
                                                .getPassCondition().get(i).getMountainPassName());
                                        item.setWeatherIcon(weatherImage);
                                        item.setRestrictionOneText(
                                                result.getMountainPassConditionsResult().getPassCondition()
                                                        .get(i).getRestrictionOne().getRestrictionText());
                                        item.setRestrictionOneTravelDirection(
                                                result.getMountainPassConditionsResult().getPassCondition()
                                                        .get(i).getRestrictionOne().getTravelDirection());
                                        item.setRestrictionTwoText(
                                                result.getMountainPassConditionsResult().getPassCondition()
                                                        .get(i).getRestrictionTwo().getRestrictionText());
                                        item.setRestrictionTwoTravelDirection(
                                                result.getMountainPassConditionsResult().getPassCondition()
                                                        .get(i).getRestrictionTwo().getTravelDirection());
                                        item.setCamera(new JSONArray(result.getMountainPassConditionsResult()
                                                .getPassCondition().get(i).getCameras()).toString());
                                        item.setForecast(new JSONArray(forecasts).toString());

                                        if (starred.contains(result.getMountainPassConditionsResult()
                                                .getPassCondition().get(i).getMountainPassId())) {
                                            item.setIsStarred(1);
                                        }

                                        mountainPassItems.add(item);
                                    }

                                    // Purge existing mountain passes covered by incoming data
                                    dbService.deleteMountainPasses(new VoidCallback() {

                                        @Override
                                        public void onFailure(DataServiceException error) {
                                        }

                                        @Override
                                        public void onSuccess() {
                                            // Bulk insert all the new mountain passes
                                            dbService.insertMountainPasses(mountainPassItems,
                                                    new RowIdListCallback() {

                                                        @Override
                                                        public void onFailure(DataServiceException error) {
                                                        }

                                                        @Override
                                                        public void onSuccess(List<Integer> rowIds) {
                                                            // Update the cache table with the time we did the update
                                                            ArrayList<CacheItem> cacheItems = new ArrayList<CacheItem>();
                                                            cacheItems.add(new CacheItem(Tables.MOUNTAIN_PASSES,
                                                                    System.currentTimeMillis()));

                                                            dbService.updateCachesTable(cacheItems,
                                                                    new VoidCallback() {

                                                                        @Override
                                                                        public void onFailure(
                                                                                DataServiceException error) {
                                                                        }

                                                                        @Override
                                                                        public void onSuccess() {
                                                                            dbService.getMountainPasses(
                                                                                    new ListCallback<GenericRow>() {

                                                                                        @Override
                                                                                        public void onFailure(
                                                                                                DataServiceException error) {
                                                                                        }

                                                                                        @Override
                                                                                        public void onSuccess(
                                                                                                List<GenericRow> result) {
                                                                                            getMountainPasses(
                                                                                                    result);
                                                                                        }

                                                                                    });
                                                                        }
                                                                    });
                                                        }
                                                    });
                                        }
                                    });
                                }
                            }
                        });
                    }
                });

            } else {
                dbService.getMountainPasses(new ListCallback<GenericRow>() {

                    @Override
                    public void onFailure(DataServiceException error) {
                    }

                    @Override
                    public void onSuccess(List<GenericRow> result) {
                        getMountainPasses(result);
                    }

                });
            }
        }
    });

}

From source file:jake2.gwt.client.GwtWebGLRenderer.java

License:Open Source License

protected image_t GL_LoadNewImage(final String name, int type) {
    final image_t image = GL_Find_free_image_t(name, type);

    JsArrayInteger d = getImageSize(name);
    if (d == null) {
        gl.log("Size not found for " + name);
        image.width = 128;/*from w ww .ja v  a  2s  .c  om*/
        image.height = 128;
    } else {
        image.width = d.get(0);
        image.height = d.get(1);
    }

    if (type != jake2.qcommon.QuakeImage.it_pic) {
        gl.glTexImage2D(GLAdapter.GL_TEXTURE_2D, 0, 4, HOLODECK_TEXTURE_SIZE, HOLODECK_TEXTURE_SIZE, 0,
                GLAdapter.GL_RGBA, GLAdapter.GL_UNSIGNED_BYTE, holoDeckTexture);
        gl.glTexParameterf(GLAdapter.GL_TEXTURE_2D, GLAdapter.GL_TEXTURE_MIN_FILTER, GLAdapter.GL_LINEAR);
        gl.glTexParameterf(GLAdapter.GL_TEXTURE_2D, GLAdapter.GL_TEXTURE_MAG_FILTER, GLAdapter.GL_LINEAR);
    }

    imageQueue.add(image);
    if (imageQueue.size() == 1) {
        new ImageLoader().schedule();
    }

    return image;
}

From source file:jake2.gwt.client.GwtWireframeGLRenderer.java

License:Open Source License

protected image_t GL_LoadNewImage(final String name, int type) {
    final image_t image = GL_Find_free_image_t(name, type);

    JsArrayInteger d = getImageSize(name);
    if (d == null) {
        gl.log("Size not found for " + name);
        image.width = 128;//from  w  w  w  . j a  v a 2 s.  c om
        image.height = 128;
    } else {
        image.width = d.get(0);
        image.height = d.get(1);
    }

    return image;
}

From source file:nz.co.doltech.gwtjui.core.client.js.JsArrayUtil.java

License:Apache License

public static List<Integer> toList(JsArrayInteger array) {
    List<Integer> list = new ArrayList<>();
    if (array != null) {
        for (int i = 0; i < array.length(); i++) {
            list.add(array.get(i));
        }//ww  w  . ja  v a  2s.  c o  m
    }
    return list;
}