com.nextgis.maplib.util.AccountUtil Java Examples

The following examples show how to use com.nextgis.maplib.util.AccountUtil. 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: NGWVectorLayer.java    From android_maplib with GNU Lesser General Public License v3.0 6 votes vote down vote up
protected HttpResponse sendFeatureAttachOnServer(JSONObject result, long featureId, AttachItem attach) throws JSONException, IOException {
    // add attachment to row
    JSONObject postJsonData = new JSONObject();
    JSONArray uploadMetaArray = result.getJSONArray("upload_meta");
    postJsonData.put("file_upload", uploadMetaArray.get(0));
    postJsonData.put("description", attach.getDescription());
    String postload = postJsonData.toString();
    if (Constants.DEBUG_MODE) {
        Log.d(Constants.TAG, "postload: " + postload);
    }

    // get account data
    AccountUtil.AccountData accountData = AccountUtil.getAccountData(mContext, mAccountName);

    // upload file
    String url = NGWUtil.getFeatureAttachmentUrl(accountData.url, mRemoteId, featureId);

    // update record in NGW
    return NetworkUtil.post(url, postload, accountData.login, accountData.password, false);
}
 
Example #2
Source File: LayersFragment.java    From android_gisapp with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean onMenuItemClick(MenuItem menuItem) {
    IGISApplication application = (IGISApplication) getActivity().getApplication();
    switch (menuItem.getItemId()) {
        case R.id.menu_new:
            application.sendEvent(GA_LAYER, GA_CREATE, GA_LOCAL);
            Intent intentNewLayer = new Intent(getActivity(), CreateVectorLayerActivity.class);
            startActivity(intentNewLayer);
            return true;
        case R.id.menu_add_local:
            application.sendEvent(GA_LAYER, GA_CREATE, GA_IMPORT);
            ((MainActivity) getActivity()).addLocalLayer();
            return true;
        case R.id.menu_add_remote:
            application.sendEvent(GA_LAYER, GA_CREATE, GA_GEOSERVICE);
            ((MainActivity) getActivity()).addRemoteLayer();
            return true;
        case R.id.menu_add_ngw:
            if (!AccountUtil.isProUser(getActivity())) {
                ControlHelper.showProDialog(getActivity());
            } else {
                application.sendEvent(GA_LAYER, GA_CREATE, GA_NGW);
                ((MainActivity) getActivity()).addNGWLayer();
            }
            return true;
        default:
            return super.onContextItemSelected(menuItem);
    }
}
 
Example #3
Source File: SplitCombobox.java    From android_maplibui with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void addToLayout(ViewGroup layout)
{
    LinearLayout container = new LinearLayout(getContext());
    container.setOrientation(VERTICAL);
    container.addView(mTitles);
    container.addView(mSpinners);
    addView(container);

    if (!AccountUtil.isProUser(getContext())) {
        FrameLayout splash = new FrameLayout(getContext());
        splash.setClickable(true);
        splash.setBackgroundColor(Color.argb(128, 128, 128, 128));
        ImageView sign = new ImageView(getContext());
        sign.setImageResource(R.drawable.ic_lock_black_24dp);
        sign.setScaleType(ImageView.ScaleType.FIT_CENTER);
        sign.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View view) {
                ControlHelper.showProDialog(getContext());
            }
        });

        splash.addView(sign);
        addView(splash);
    }

    layout.addView(this);
}
 
Example #4
Source File: LayersFragment.java    From android_gisapp with GNU General Public License v3.0 5 votes vote down vote up
@Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.sync:
                for (Account account : mAccounts) {
                    Bundle settingsBundle = new Bundle();
                    settingsBundle.putBoolean(
                            ContentResolver.SYNC_EXTRAS_MANUAL, true);
                    settingsBundle.putBoolean(
                            ContentResolver.SYNC_EXTRAS_EXPEDITED, true);

                    ContentResolver.requestSync(account, AUTHORITY, settingsBundle);
                }

                updateInfo();
                break;
            case R.id.new_layer:
                if (getActivity() != null) {
//                    View view = getActivity().getWindow().getDecorView().findViewById(android.R.id.content);
                    View view = getActivity().findViewById(R.id.new_layer);
                    PopupMenu popup = new PopupMenu(getActivity(), view);
                    UiUtil.setForceShowIcon(popup);
                    popup.getMenuInflater().inflate(R.menu.add_layer, popup.getMenu());
                    popup.setOnMenuItemClickListener(this);
                    if (!AccountUtil.isProUser(getActivity())) {
                        popup.getMenu().findItem(R.id.menu_add_ngw).setIcon(R.drawable.ic_lock_black_24dp);
                    }
                    popup.show();
                }

                break;
        }
    }
 
Example #5
Source File: SettingsHeaderFragment.java    From android_gisapp with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void createPreferences(PreferenceScreen screen)
{
    addPreferencesFromResource(R.xml.preference_headers);
    if (getActivity() != null && !AccountUtil.isProUser(getActivity()))
        screen.findPreference(SettingsConstantsUI.ACTION_PREFS_NGW).setIcon(R.drawable.ic_lock_black_24dp);
}
 
Example #6
Source File: NGWVectorLayer.java    From android_maplib with GNU Lesser General Public License v3.0 5 votes vote down vote up
protected HttpResponse changeFeatureOnServer(long featureId, String payload) throws IOException {
    AccountUtil.AccountData accountData = AccountUtil.getAccountData(mContext, mAccountName);

    // change on server
    String url = NGWUtil.getFeatureUrl(accountData.url, mRemoteId, featureId);
    return NetworkUtil.put(url, payload, accountData.login, accountData.password, false);
}
 
Example #7
Source File: NGWVectorLayer.java    From android_maplib with GNU Lesser General Public License v3.0 5 votes vote down vote up
protected HttpURLConnection getHttpConnection(AccountUtil.AccountData accountData) throws IOException {
    URL url = new URL(getFeaturesUrl(accountData));
    HttpURLConnection connection = (HttpURLConnection) url.openConnection();

    final String basicAuth = NetworkUtil.getHTTPBaseAuth(accountData.login, accountData.password);
    if (null != basicAuth) {
        connection.setRequestProperty("Authorization", basicAuth);
    }

    return connection;
}
 
Example #8
Source File: NGWVectorLayer.java    From android_maplib with GNU Lesser General Public License v3.0 5 votes vote down vote up
protected HttpResponse sendAttachOnServer(long featureId, AttachItem attach) throws IOException {
    // fill attach info
    String fileName = attach.getDisplayName();
    File filePath = new File(mPath, featureId + File.separator + attach.getAttachId());
    String fileMime = attach.getMimetype();

    // get account data
    AccountUtil.AccountData accountData = AccountUtil.getAccountData(mContext, mAccountName);

    // upload file
    String url = NGWUtil.getFileUploadUrl(accountData.url);
    return NetworkUtil.postFile(url, fileName, filePath, fileMime, accountData.login, accountData.password, false);
}
 
Example #9
Source File: NGWVectorLayer.java    From android_maplib with GNU Lesser General Public License v3.0 5 votes vote down vote up
protected String getFeaturesUrl(AccountUtil.AccountData accountData)
{
    if (mTracked)
        return NGWUtil.getTrackedFeaturesUrl(accountData.url, mRemoteId, getPreferences().getLong(SettingsConstants.KEY_PREF_LAST_SYNC_TIMESTAMP, 0));
    else
        return NGWUtil.getFeaturesUrl(accountData.url, mRemoteId, mServerWhere);
}
 
Example #10
Source File: NGWVectorLayer.java    From android_maplib with GNU Lesser General Public License v3.0 5 votes vote down vote up
public String getRemoteUrl()
{
    try {
        AccountUtil.AccountData accountData = AccountUtil.getAccountData(mContext, mAccountName);
        return NGWUtil.getResourceUrl(accountData.url, mRemoteId);
    } catch (IllegalStateException e) {
        return null;
    }
}
 
Example #11
Source File: NGWRasterLayer.java    From android_maplib with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public Bitmap getBitmap(TileItem tile) {
    if (!mExtentReceived) {
        HttpResponse result = null;
        try {
            AccountUtil.AccountData accountData = AccountUtil.getAccountData(mContext, getAccountName());
            result = NetworkUtil.get(NGWUtil.getExtent(accountData.url, mRemoteId), getLogin(), getPassword(), false);
            if (!result.isOk()) {
                throw new IllegalStateException("");
            }
            JSONObject extent = new JSONObject(result.getResponseBody()).getJSONObject(JSON_EXTENT_KEY);
            double x = Geo.wgs84ToMercatorSphereX(extent.getDouble(JSON_MAX_LON_KEY));
            double y = Geo.wgs84ToMercatorSphereY(extent.getDouble(JSON_MAX_LAT_KEY));
            mExtents.setMax(x, y);
            x = Geo.wgs84ToMercatorSphereX(extent.getDouble(JSON_MIN_LON_KEY));
            y = Geo.wgs84ToMercatorSphereY(extent.getDouble(JSON_MIN_LAT_KEY));
            mExtents.setMin(x, y);
            mExtentReceived = true;
        } catch (IOException | JSONException | IllegalStateException ignored) {
            if (result != null && result.getResponseCode() == 404)
                mExtentReceived = true;
        }
    }

    if (mExtents.intersects(tile.getEnvelope()))
        return super.getBitmap(tile);

    return null;
}
 
Example #12
Source File: NGWVectorLayer.java    From android_maplib with GNU Lesser General Public License v3.0 4 votes vote down vote up
protected HttpResponse deleteAttachOnServer(long featureId, long attachId) throws IOException {
    AccountUtil.AccountData accountData = AccountUtil.getAccountData(mContext, mAccountName);

    return NetworkUtil.delete(NGWUtil.getFeatureAttachmentUrl(accountData.url, mRemoteId, featureId)
                    + attachId, accountData.login, accountData.password, false);
}
 
Example #13
Source File: NGWVectorLayer.java    From android_maplib with GNU Lesser General Public License v3.0 4 votes vote down vote up
protected HttpResponse changeAttachOnServer(long featureId, long attachId, String putData) throws IOException {
    AccountUtil.AccountData accountData = AccountUtil.getAccountData(mContext, mAccountName);
    String url = NGWUtil.getFeatureAttachmentUrl(accountData.url, mRemoteId, featureId) + attachId;
    return NetworkUtil.put(url, putData, accountData.login,
                                            accountData.password, false);
}
 
Example #14
Source File: NGWVectorLayer.java    From android_maplib with GNU Lesser General Public License v3.0 4 votes vote down vote up
protected String getResourceMetaUrl(AccountUtil.AccountData accountData)
{
    return NGWUtil.getResourceUrl(accountData.url, mRemoteId);
}
 
Example #15
Source File: NGWVectorLayer.java    From android_maplib with GNU Lesser General Public License v3.0 4 votes vote down vote up
protected HttpResponse addFeatureOnServer(String payload) throws IOException {
    AccountUtil.AccountData accountData = AccountUtil.getAccountData(mContext, mAccountName);

    return NetworkUtil.post(NGWUtil.getFeaturesUrl(accountData.url, mRemoteId),
                     payload, accountData.login, accountData.password, false);
}
 
Example #16
Source File: NGWVectorLayer.java    From android_maplib with GNU Lesser General Public License v3.0 4 votes vote down vote up
protected HttpResponse deleteFeatureOnServer(long featureId) throws IOException {
    AccountUtil.AccountData accountData = AccountUtil.getAccountData(mContext, mAccountName);

    return NetworkUtil.delete(NGWUtil.getFeatureUrl(accountData.url, mRemoteId, featureId),
                               accountData.login, accountData.password, false);
}
 
Example #17
Source File: NGActivity.java    From android_maplibui with GNU Lesser General Public License v3.0 4 votes vote down vote up
public String getAppName() {
    String appName = "NextGIS Mobile";
    if (AccountUtil.isProUser(this))
        appName += " Pro";
    return appName;
}