com.nextgis.maplib.util.FileUtil Java Examples

The following examples show how to use com.nextgis.maplib.util.FileUtil. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: VectorLayer.java    From android_maplib with GNU Lesser General Public License v3.0 6 votes vote down vote up
public void toNGW(Long id, String account, int syncType, Pair<Integer, Integer> ver) {
    if (id != null && id != NOT_FOUND) {
        mLayerType = Constants.LAYERTYPE_NGW_VECTOR;
        try {
            JSONObject rootConfig = toJSON();
            if (ver != null) {
                rootConfig.put(NGWVectorLayer.JSON_NGW_VERSION_MAJOR_KEY, ver.first);
                rootConfig.put(NGWVectorLayer.JSON_NGW_VERSION_MINOR_KEY, ver.second);
            }

            rootConfig.put(NGWVectorLayer.JSON_ACCOUNT_KEY, account);
            rootConfig.put(Constants.JSON_ID_KEY, id);
            rootConfig.put(NGWVectorLayer.JSON_SYNC_TYPE_KEY, syncType);
            rootConfig.put(NGWVectorLayer.JSON_NGWLAYER_TYPE_KEY, Connection.NGWResourceTypeVectorLayer);
            FileUtil.writeToFile(getFileName(), rootConfig.toString());
            MapBase map = MapDrawable.getInstance();
            map.load();
            new Sync().execute();
        } catch (IOException | JSONException ignored) { }
    }
}
 
Example #2
Source File: LocalResourceListItem.java    From android_maplibui with GNU Lesser General Public License v3.0 6 votes vote down vote up
protected void init(
        File file,
        int type,
        boolean selectable,
        boolean forWritableFolder)
{
    mFile = file;
    mType = type;

    if (selectable) {
        if (!forWritableFolder) {
            mSelectable = true;
            mVisibleCheckBox = true;
        } else if (FILETYPE_FOLDER == mType) {
            mSelectable = FileUtil.isDirectoryWritable(file);
            mVisibleCheckBox = true;
        }
    } else {
        mSelectable = false;
        mVisibleCheckBox = false;
    }
}
 
Example #3
Source File: VectorLayer.java    From android_maplib with GNU Lesser General Public License v3.0 6 votes vote down vote up
public boolean insertAttachFile(
        long featureId,
        long attachId,
        InputStream inputStream)
{
    Uri uri = Uri.parse("content://" + mAuthority + "/" + mPath.getName() +
            "/" + featureId + "/" + Constants.URI_ATTACH + "/" + attachId);
    try {
        OutputStream attachOutStream = mContext.getContentResolver().openOutputStream(uri);
        if (attachOutStream != null) {
            FileUtil.copy(inputStream, attachOutStream);
            attachOutStream.close();
        }

    } catch (IOException e) {
        Log.d(TAG, "create attach file failed, " + e.getLocalizedMessage());
        return false;
    }

    return true;
}
 
Example #4
Source File: LayerFactoryUI.java    From android_maplibui with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public void createNewVectorLayer(
        final Context context,
        final LayerGroup groupLayer,
        final Uri uri)
{
    String layerName =
            FileUtil.getFileNameByUri(context, uri, context.getString(R.string.new_layer));
    final int lastPeriodPos = layerName.lastIndexOf('.');
    if (lastPeriodPos > 0) {
        layerName = layerName.substring(0, lastPeriodPos);
    }
    if (context instanceof NGActivity) {
        NGActivity fragmentActivity = (NGActivity) context;
        CreateLocalLayerDialog newFragment = new CreateLocalLayerDialog();
        newFragment.setLayerGroup(groupLayer)
                .setLayerType(LayerFillService.VECTOR_LAYER)
                .setUri(uri)
                .setLayerName(layerName)
                .setTitle(context.getString(R.string.create_vector_layer))
                .setTheme(fragmentActivity.getThemeId())
                .show(fragmentActivity.getSupportFragmentManager(), "create_vector_layer");
    }
}
 
Example #5
Source File: LayerFactoryUI.java    From android_maplibui with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public void createNewVectorLayerWithForm(
        final Context context,
        final LayerGroup groupLayer,
        final Uri uri)
{
    String layerName =
            FileUtil.getFileNameByUri(context, uri, context.getString(R.string.new_layer));
    final int lastPeriodPos = layerName.lastIndexOf('.');
    if (lastPeriodPos > 0) {
        layerName = layerName.substring(0, lastPeriodPos);
    }
    if (context instanceof NGActivity) {
        NGActivity fragmentActivity = (NGActivity) context;
        CreateLocalLayerDialog newFragment = new CreateLocalLayerDialog();
        newFragment.setLayerGroup(groupLayer)
                .setLayerType(LayerFillService.VECTOR_LAYER_WITH_FORM)
                .setUri(uri)
                .setLayerName(layerName)
                .setTitle(context.getString(R.string.create_vector_layer))
                .setTheme(fragmentActivity.getThemeId())
                .show(fragmentActivity.getSupportFragmentManager(), "create_vector_with_form_layer");
    }
}
 
Example #6
Source File: VectorLayer.java    From android_maplib with GNU Lesser General Public License v3.0 6 votes vote down vote up
protected Map<String, AttachItem> loadAttach(String featureId)
{
    File attachFolder = new File(mPath, featureId);
    File meta = new File(attachFolder, META);
    try {
        String metaContent = FileUtil.readFromFile(meta);
        JSONArray jsonArray = new JSONArray(metaContent);
        Map<String, AttachItem> attach = new HashMap<>();
        for (int i = 0; i < jsonArray.length(); i++) {
            JSONObject jsonValue = jsonArray.getJSONObject(i);
            AttachItem attachItem = new AttachItem();
            attachItem.fromJSON(jsonValue);
            attach.put(attachItem.getAttachId(), attachItem);
        }
        return attach;

    } catch (IOException | JSONException e) {
        // e.printStackTrace();
    }

    return null;
}
 
Example #7
Source File: FormBuilderModifyAttributesActivity.java    From android_maplibui with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
        case RESELECT_ROW:
            if (mMeta != null && mMeta.exists()) {
                try {
                    String metaString = FileUtil.readFromFile(mMeta);
                    JSONObject metaJson = new JSONObject(metaString);
                    metaJson.remove(JSON_KEY_LIST_SAVED_KEY);
                    FileUtil.writeToFile(mMeta, metaJson.toString());
                    refreshActivityView();
                } catch (JSONException | IOException ignored) {}
            }
            return true;
        default:
            return super.onOptionsItemSelected(item);
    }
}
 
Example #8
Source File: ClearCacheTask.java    From android_maplibui with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
protected Void doInBackground(File... path) {
    if (path.length > 0) {
        if (path[0].exists() && path[0].isDirectory()) {
            File[] data = path[0].listFiles();
            int c = 0;
            for (File file : data) {
                publishProgress(++c, data.length);
                if (file.isDirectory() && MapUtil.isParsable(file.getName()))
                    FileUtil.deleteRecursive(file);
            }
        }
    }

    return null;
}
 
Example #9
Source File: LayerUtil.java    From android_maplibui with GNU Lesser General Public License v3.0 6 votes vote down vote up
public static ArrayList<String> fillLookupTableIds(File path) throws IOException, JSONException {
    String formText = FileUtil.readFromFile(path);
    JSONArray formJson = new JSONArray(formText);
    ArrayList<String> lookupTableIds = new ArrayList<>();

    for (int i = 0; i < formJson.length(); i++) {
        JSONObject element = formJson.getJSONObject(i);
        if (ConstantsUI.JSON_COMBOBOX_VALUE.equals(element.optString(Constants.JSON_TYPE_KEY))) {
            element = element.getJSONObject(ConstantsUI.JSON_ATTRIBUTES_KEY);
            if (element.has(ConstantsUI.JSON_NGW_ID_KEY))
                if (element.getLong(ConstantsUI.JSON_NGW_ID_KEY) != -1)
                    lookupTableIds.add(element.getLong(ConstantsUI.JSON_NGW_ID_KEY) + "");
        }
    }

    return lookupTableIds;
}
 
Example #10
Source File: LayerFillService.java    From android_maplibui with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public boolean execute(IProgressor progressor) {
    try {
        VectorLayer vectorLayer = (VectorLayer) mLayer;
        if (null == vectorLayer)
            return false;
        File meta = new File(mPath.getParentFile(), NGFP_META);

        if (meta.exists()) {
            String jsonText = FileUtil.readFromFile(meta);
            JSONObject metaJson = new JSONObject(jsonText);
            //read fields
            List<Field> fields = NGWUtil.getFieldsFromJson(metaJson.getJSONArray(NGWUtil.NGWKEY_FIELDS));
            //read geometry type
            String geomTypeString = metaJson.getString("geometry_type");
            int geomType = GeoGeometryFactory.typeFromString(geomTypeString);
            vectorLayer.create(geomType, fields);

            if (GeoJSONUtil.isGeoJsonHasFeatures(mPath)) {
                //read SRS -- not need as we will be fill layer with 3857
                JSONObject srs = metaJson.getJSONObject(NGWUtil.NGWKEY_SRS);
                int nSRS = srs.getInt(NGWUtil.NGWKEY_ID);
                vectorLayer.fillFromGeoJson(mPath, nSRS, progressor);
            }
        } else
            vectorLayer.createFromGeoJson(mPath, progressor); // should never get there
    } catch (IOException | JSONException | SQLiteException | NGException | ClassCastException e) {
        e.printStackTrace();
        setError(e, progressor);
        notifyError(mProgressMessage);
        return false;
    }

    if (mDeletePath)
        FileUtil.deleteRecursive(mPath);

    return true;
}
 
Example #11
Source File: VectorLayer.java    From android_maplib with GNU Lesser General Public License v3.0 5 votes vote down vote up
protected IStyleRule getStyleRule()
{
    try {
        JSONObject jsonObject = new JSONObject(FileUtil.readFromFile(getFileName()));
        jsonObject = jsonObject.getJSONObject(JSON_RENDERERPROPS_KEY);
        jsonObject = jsonObject.getJSONObject(JSON_STYLE_RULE_KEY);
        FieldStyleRule rule = new FieldStyleRule(this);
        rule.fromJSON(jsonObject);
        return rule;
    } catch (JSONException | IOException e) {
        e.printStackTrace();
    }

    return null;
}
 
Example #12
Source File: MapBase.java    From android_maplib with GNU Lesser General Public License v3.0 5 votes vote down vote up
public void moveTo(File newPath)
{

    if (mPath.equals(newPath)) {
        return;
    }

    clearLayers();

    if (FileUtil.move(mPath, newPath)) {
        //change path
        mPath = newPath;
    }
    load();
}
 
Example #13
Source File: MapBase.java    From android_maplib with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public boolean delete()
{
    for (ILayer layer : mLayers) {
        layer.setParent(null);
        layer.delete();
    }

    mLayers.clear();

    return FileUtil.deleteRecursive(getFileName());
}
 
Example #14
Source File: Table.java    From android_maplib with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public boolean load()
{
    try {
        JSONObject jsonObject = new JSONObject(FileUtil.readFromFile(getFileName()));
        fromJSON(jsonObject);
    } catch (JSONException | IOException | SQLiteException e) {
        e.printStackTrace();
        return false;
    }
    return true;
}
 
Example #15
Source File: Table.java    From android_maplib with GNU Lesser General Public License v3.0 5 votes vote down vote up
protected File getFileName()
{
    // do we need this?
    try {
        FileUtil.createDir(getPath());
    } catch (RuntimeException e) {
        e.printStackTrace();
    }

    return new File(getPath(), CONFIG);
}
 
Example #16
Source File: Table.java    From android_maplib with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public boolean delete()
{
    FileUtil.deleteRecursive(mPath);
    if (mParent != null && mParent instanceof LayerGroup) {
        LayerGroup group = (LayerGroup) mParent;
        group.onLayerDeleted(mId);
    }
    return true;
}
 
Example #17
Source File: TMSLayer.java    From android_maplib with GNU Lesser General Public License v3.0 5 votes vote down vote up
protected void fillFromZipInt(Uri uri, IProgressor progressor) throws IOException, NGException, RuntimeException {
    InputStream inputStream;
    String url = uri.toString();
    if (NetworkUtil.isValidUri(url))
        inputStream = new URL(url).openStream();
    else
        inputStream = mContext.getContentResolver().openInputStream(uri);

    if (inputStream == null)
        throw new NGException(mContext.getString(R.string.error_download_data));

    int streamSize = inputStream.available();
    if (null != progressor)
        progressor.setMax(streamSize);

    int increment = 0;
    byte[] buffer = new byte[Constants.IO_BUFFER_SIZE];

    ZipInputStream zis = new ZipInputStream(inputStream);
    ZipEntry ze;
    while ((ze = zis.getNextEntry()) != null) {
        FileUtil.unzipEntry(zis, ze, buffer, mPath);
        increment += ze.getCompressedSize();
        zis.closeEntry();
        if (null != progressor) {
            if(progressor.isCanceled())
                return;
            progressor.setValue(increment);
            progressor.setMessage(getContext().getString(R.string.processed) + " " + increment + " " + getContext().getString(R.string.of) + " " + streamSize);
        }
    }
}
 
Example #18
Source File: RemoteTMSLayer.java    From android_maplib with GNU Lesser General Public License v3.0 5 votes vote down vote up
protected void getTileFromStream(
        String url,
        File tilePath)
        throws IOException
{
    FileUtil.createDir(tilePath.getParentFile());
    OutputStream output = new FileOutputStream(tilePath.getAbsolutePath());
    NetworkUtil.getStream(url, getLogin(), getPassword(), output);
}
 
Example #19
Source File: GeometryRTree.java    From android_maplib with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public synchronized void save(File path) {

    boolean isSameFile = null != mPath && mPath.equals(path);

    if(isSameFile && !mHasEdits)
        return;

    try {
        FileUtil.createDir(path.getParentFile());
        FileOutputStream fileOutputStream = new FileOutputStream(path);
        DataOutputStream dataOutputStream = new DataOutputStream(fileOutputStream);

        dataOutputStream.writeInt(maxEntries);
        dataOutputStream.writeInt(minEntries);
        dataOutputStream.writeInt(size);

        root.write(dataOutputStream);

        dataOutputStream.flush();
        dataOutputStream.close();
        fileOutputStream.close();

        mHasEdits = false;
    } catch (RuntimeException | IOException e) {
        e.printStackTrace();
    }
}
 
Example #20
Source File: LayerFactory.java    From android_maplib with GNU Lesser General Public License v3.0 4 votes vote down vote up
public ILayer createLayer(
        Context context,
        File path)
{
    File config_file = new File(path, CONFIG);
    ILayer layer = null;

    try {
        String sData = FileUtil.readFromFile(config_file);
        JSONObject rootObject = new JSONObject(sData);
        int nType = rootObject.getInt(JSON_TYPE_KEY);

        switch (nType) {
            case LAYERTYPE_REMOTE_TMS:
                layer = new RemoteTMSLayer(context, path);
                break;
            case LAYERTYPE_NGW_RASTER:
                layer = new NGWRasterLayer(context, path);
                break;
            case LAYERTYPE_NGW_VECTOR:
                layer = new NGWVectorLayer(context, path);
                break;
            case LAYERTYPE_NGW_WEBMAP:
                layer = new NGWWebMapLayer(context, path);
                break;
            case LAYERTYPE_LOCAL_VECTOR:
                layer = new VectorLayer(context, path);
                break;
            case LAYERTYPE_LOCAL_TMS:
                layer = new LocalTMSLayer(context, path);
                break;
            case LAYERTYPE_GROUP:
                layer = new LayerGroup(context, path, this);
                break;
            case LAYERTYPE_TRACKS:
                layer = new TrackLayer(context, path);
                break;
            case LAYERTYPE_LOOKUPTABLE:
                layer = new NGWLookupTable(context, path);
                break;
        }
    } catch (IOException | JSONException e) {
        Log.d(TAG, e.getLocalizedMessage());
    }

    return layer;
}
 
Example #21
Source File: TileItem.java    From android_maplib with GNU Lesser General Public License v3.0 4 votes vote down vote up
public final String toString(){
    return "" + getZoomLevel() + FileUtil.getPathSeparator() + getX() + FileUtil.getPathSeparator() + getY();
}
 
Example #22
Source File: ExportGPXTask.java    From android_maplibui with GNU Lesser General Public License v3.0 4 votes vote down vote up
private void appendTrack(File temp, String name, StringBuilder sb, Formatter f, Cursor trackpoints) throws IOException {
    GeoPoint point = new GeoPoint();
    int latId = trackpoints.getColumnIndex(TrackLayer.FIELD_LAT);
    int lonId = trackpoints.getColumnIndex(TrackLayer.FIELD_LON);
    int timeId = trackpoints.getColumnIndex(TrackLayer.FIELD_TIMESTAMP);
    int eleId = trackpoints.getColumnIndex(TrackLayer.FIELD_ELE);
    int satId = trackpoints.getColumnIndex(TrackLayer.FIELD_SAT);
    int fixId = trackpoints.getColumnIndex(TrackLayer.FIELD_FIX);

    DecimalFormat df = new DecimalFormat("0", new DecimalFormatSymbols(Locale.ENGLISH));
    df.setMaximumFractionDigits(340); //340 = DecimalFormat.DOUBLE_FRACTION_DIGITS

    sb.setLength(0);
    sb.append(GPX_TAG_TRACK);

    if (name != null) {
        sb.append(GPX_TAG_NAME);
        sb.append(name);
        sb.append(GPX_TAG_NAME_CLOSE);
    }

    sb.append(GPX_TAG_TRACK_SEGMENT);
    FileUtil.writeToFile(temp, sb.toString(), true);

    do {
        sb.setLength(0);
        point.setCoordinates(trackpoints.getDouble(lonId), trackpoints.getDouble(latId));
        point.setCRS(CRS_WEB_MERCATOR);
        point.project(CRS_WGS84);
        String sLon = df.format(point.getX());
        String sLat = df.format(point.getY());
        f.format(GPX_TAG_TRACK_SEGMENT_POINT, sLat, sLon);
        f.format(GPX_TAG_TRACK_SEGMENT_POINT_TIME, getTimeStampAsString(trackpoints.getLong(timeId)));
        f.format(GPX_TAG_TRACK_SEGMENT_POINT_ELE, df.format(trackpoints.getDouble(eleId)));
        f.format(GPX_TAG_TRACK_SEGMENT_POINT_SAT, trackpoints.getString(satId));
        f.format(GPX_TAG_TRACK_SEGMENT_POINT_FIX, trackpoints.getString(fixId));
        sb.append(GPX_TAG_TRACK_SEGMENT_POINT_CLOSE);
        FileUtil.writeToFile(temp, sb.toString(), true);
    } while (trackpoints.moveToNext());

    sb.setLength(0);
    sb.append(GPX_TAG_TRACK_SEGMENT_CLOSE);
    sb.append(GPX_TAG_TRACK_CLOSE);
    FileUtil.writeToFile(temp, sb.toString(), true);
}
 
Example #23
Source File: LayerFactoryUI.java    From android_maplibui with GNU Lesser General Public License v3.0 4 votes vote down vote up
public ILayer createLayer(
        Context context,
        File path)
{
    File config_file = new File(path, CONFIG);
    ILayer layer = null;

    try {
        String sData = FileUtil.readFromFile(config_file);
        JSONObject rootObject = new JSONObject(sData);
        int nType = rootObject.getInt(JSON_TYPE_KEY);

        switch (nType) {
            case LAYERTYPE_REMOTE_TMS:
                layer = new RemoteTMSLayerUI(context, path);
                break;
            case LAYERTYPE_NGW_RASTER:
                layer = new NGWRasterLayerUI(context, path);
                break;
            case LAYERTYPE_NGW_VECTOR:
                layer = new NGWVectorLayerUI(context, path);
                break;
            case LAYERTYPE_NGW_WEBMAP:
                layer = new NGWWebMapLayerUI(context, path);
                break;
            case LAYERTYPE_LOCAL_VECTOR:
                layer = new VectorLayerUI(context, path);
                break;
            case LAYERTYPE_LOCAL_TMS:
                layer = new LocalTMSLayerUI(context, path);
                break;
            case LAYERTYPE_GROUP:
                layer = new LayerGroupUI(context, path, this);
                break;
            case LAYERTYPE_TRACKS:
                layer = new TrackLayerUI(context, path);
                break;
            case LAYERTYPE_LOOKUPTABLE:
                layer = new NGWLookupTable(context, path); // TODO: 26.07.15 Do we need UI for this?
                break;
        }
    } catch (IOException | JSONException e) {
        Log.d(TAG, e.getLocalizedMessage());
    }

    return layer;
}
 
Example #24
Source File: VectorLayer.java    From android_maplib with GNU Lesser General Public License v3.0 4 votes vote down vote up
protected void deleteAttaches(String featureId)
{
    File attachFolder = new File(mPath, featureId);
    FileUtil.renameAndDelete(attachFolder);
}
 
Example #25
Source File: LayerFactoryUI.java    From android_maplibui with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public void createNewLocalTMSLayer(
        final Context context,
        final LayerGroup groupLayer,
        final Uri uri)
{
    String ext = "zip";
    String layerName =
            FileUtil.getFileNameByUri(context, uri, context.getString(R.string.new_layer));
    final int lastPeriodPos = layerName.lastIndexOf('.');
    if (lastPeriodPos > 0) {
        ext = layerName.substring(lastPeriodPos).toLowerCase();
        layerName = layerName.substring(0, lastPeriodPos);
    }
    if (context instanceof NGActivity) {
        NGActivity fragmentActivity = (NGActivity) context;

        if (ext.equals(".ngrc")) {
            Intent intent = new Intent(context, LayerFillService.class);
            intent.setAction(LayerFillService.ACTION_ADD_TASK);
            intent.putExtra(LayerFillService.KEY_URI, uri);
            intent.putExtra(LayerFillService.KEY_INPUT_TYPE, LayerFillService.TMS_LAYER);
            intent.putExtra(LayerFillService.KEY_LAYER_GROUP_ID, groupLayer.getId());

            LayerFillProgressDialogFragment.startFill(intent);
            return;
        }

        AtomicReference<Uri> temp = new AtomicReference<>(uri);
        if (MapUtil.isZippedGeoJSON(context, temp)) {
            createNewVectorLayer(context, groupLayer, temp.get());
            return;
        }

        CreateLocalLayerDialog newFragment = new CreateLocalLayerDialog();
        newFragment.setLayerGroup(groupLayer)
                .setLayerType(LayerFillService.TMS_LAYER)
                .setUri(uri)
                .setLayerName(layerName)
                .setTitle(context.getString(R.string.create_tms_layer))
                .setTheme(fragmentActivity.getThemeId())
                .show(fragmentActivity.getSupportFragmentManager(), "create_tms_layer");
    }
}
 
Example #26
Source File: LayerFillService.java    From android_maplibui with GNU Lesser General Public License v3.0 4 votes vote down vote up
public void cancel() {
    if (mLayer != null)
        mLayer.delete();
    else if (mLayerPath != null)
        FileUtil.deleteRecursive(mLayerPath);
}
 
Example #27
Source File: MapFragment.java    From android_gisapp with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void onResume()
{
    super.onResume();

    boolean showControls = mPreferences.getBoolean(KEY_PREF_SHOW_ZOOM_CONTROLS, false);
    showMapButtons(showControls, mMapRelativeLayout);

    if(Constants.DEBUG_MODE)
        Log.d(Constants.TAG, "KEY_PREF_SHOW_ZOOM_CONTROLS: " + (showControls ? "ON" : "OFF"));

    showControls = mPreferences.getBoolean(KEY_PREF_SHOW_SCALE_RULER, true);
    if (showControls)
        mScaleRulerLayout.setVisibility(View.VISIBLE);
    else
        mScaleRulerLayout.setVisibility(View.GONE);

    showControls = mPreferences.getBoolean(KEY_PREF_SHOW_ZOOM, false);
    if (showControls)
        mZoomLevel.setVisibility(View.VISIBLE);
    else
        mZoomLevel.setVisibility(View.GONE);

    showControls = mPreferences.getBoolean(KEY_PREF_SHOW_MEASURING, false);
    if (showControls)
        mRuler.setVisibility(View.VISIBLE);
    else
        mRuler.setVisibility(View.GONE);

    if (null != mMap) {
        mMap.getMap().setBackground(mApp.getMapBackground());
        mMap.addListener(this);
    }

    String coordinatesFormat = mPreferences.getString(SettingsConstantsUI.KEY_PREF_COORD_FORMAT, Location.FORMAT_DEGREES + "");
    if (FileUtil.isIntegerParseInt(coordinatesFormat))
        mCoordinatesFormat = Integer.parseInt(coordinatesFormat);
    else
        mCoordinatesFormat = Location.FORMAT_DEGREES;
    mCoordinatesFraction = mPreferences.getInt(SettingsConstantsUI.KEY_PREF_COORD_FRACTION, DEFAULT_COORDINATES_FRACTION_DIGITS);

    if (null != mCurrentLocationOverlay) {
        mCurrentLocationOverlay.updateMode(mPreferences.getString(SettingsConstantsUI.KEY_PREF_SHOW_CURRENT_LOC, "3"));
        mCurrentLocationOverlay.startShowingCurrentLocation();
    }
    if (null != mGpsEventSource) {
        mGpsEventSource.addListener(this);
        if (mGPSDialog == null || !mGPSDialog.isShowing())
            mGPSDialog = NotificationHelper.showLocationInfo(getActivity());
    }

    if (null != mEditLayerOverlay) {
        mEditLayerOverlay.addListener(this);
        mEditLayerOverlay.onResume();
    }

    try {
        String statusPanelModeStr = mPreferences.getString(SettingsConstantsUI.KEY_PREF_SHOW_STATUS_PANEL, "1");
        if (FileUtil.isIntegerParseInt(statusPanelModeStr))
            mStatusPanelMode = Integer.parseInt(statusPanelModeStr);
        else
            mStatusPanelMode = 0;
    } catch (ClassCastException e){
        mStatusPanelMode = 0;
        if(Constants.DEBUG_MODE)
            Log.d(Constants.TAG, "Previous version of KEY_PREF_SHOW_STATUS_PANEL of bool type. Let set it to 0");
    }

    if (null != mStatusPanel) {
        if (mStatusPanelMode != 0) {
            mStatusPanel.setVisibility(View.VISIBLE);
            fillStatusPanel(null);

            if (mMode != MODE_NORMAL && mStatusPanelMode != 3)
                mStatusPanel.setVisibility(View.INVISIBLE);
        } else {
            mStatusPanel.removeAllViews();
        }

        setMarginsToPanel();
    }

    boolean showCompass = mPreferences.getBoolean(KEY_PREF_SHOW_COMPASS, true);
    checkCompass(showCompass);

    mCurrentCenter = null;
}
 
Example #28
Source File: MainActivity.java    From android_gisapp with GNU General Public License v3.0 4 votes vote down vote up
@Override
protected void onActivityResult(
        int requestCode,
        int resultCode,
        Intent data)
{
    //http://stackoverflow.com/questions/10114324/show-dialogfragment-from-onactivityresult
    //http://stackoverflow.com/questions/16265733/failure-delivering-result-onactivityforresult/18345899
    super.onActivityResult(requestCode, resultCode, data);

    switch (requestCode) {
        case FILE_SELECT_CODE:
            if (resultCode == RESULT_OK) {
                // Get the Uri of the selected file
                Uri uri = data.getData();
                if(Constants.DEBUG_MODE)
                    Log.d(TAG, "File Uri: " + (uri != null ? uri.toString() : ""));
                //check the file type from extension
                String fileName = FileUtil.getFileNameByUri(this, uri, "");
                if (fileName.toLowerCase().endsWith("ngrc") ||
                        fileName.toLowerCase().endsWith("zip")) { //create local tile layer
                    if (null != mMapFragment) {
                        mMapFragment.addLocalTMSLayer(uri);
                    }
                } else if (fileName.toLowerCase().endsWith("geojson")) { //create local vector layer
                    if (null != mMapFragment) {
                        mMapFragment.addLocalVectorLayer(uri);
                    }
                } else if (fileName.toLowerCase().endsWith("ngfp")) { //create local vector layer with form
                    if (null != mMapFragment) {
                        mMapFragment.addLocalVectorLayerWithForm(uri);
                    }
                } else {
                    Toast.makeText(
                            this, getString(R.string.error_file_unsupported),
                            Toast.LENGTH_SHORT).show();
                }
            }
            break;
        case IVectorLayerUI.MODIFY_REQUEST:
            mMapFragment.onActivityResult(requestCode, resultCode, data);
            break;
    }
}