本文整理汇总了Java中com.nextgis.maplib.util.NetworkUtil类的典型用法代码示例。如果您正苦于以下问题:Java NetworkUtil类的具体用法?Java NetworkUtil怎么用?Java NetworkUtil使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
NetworkUtil类属于com.nextgis.maplib.util包,在下文中一共展示了NetworkUtil类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onPostExecute
import com.nextgis.maplib.util.NetworkUtil; //导入依赖的package包/类
@Override
protected void onPostExecute(HttpResponse response)
{
super.onPostExecute(response);
if (response.isOk()) {
try {
new JSONObject(response.getResponseBody());
createLayer(response.getResponseBody());
} catch (JSONException ignored) {
Toast.makeText(mContext, R.string.qms_unavailable, Toast.LENGTH_SHORT).show();
}
} else {
Toast.makeText(
mContext, NetworkUtil.getError(mContext, response.getResponseCode()),
Toast.LENGTH_SHORT).show();
}
mChecked.remove(mLayerId);
if (mChecked.size() == 0)
mGroupLayer.save();
}
示例2: doInBackground
import com.nextgis.maplib.util.NetworkUtil; //导入依赖的package包/类
@Override
protected HttpResponse doInBackground(String... args) {
String url = args[0];
String method = args[1];
String token = args[2];
if (TextUtils.isEmpty(token)) {
try {
token = getToken(args);
userCheck(token);
} catch (IOError e) {
return new HttpResponse(NetworkUtil.ERROR_CONNECT_FAILED);
}
}
HttpResponse response = getResponse(url, method, token);
if (!response.isOk()) {
response = userCheck(token);
if (!response.isOk())
return new HttpResponse(NetworkUtil.ERROR_CONNECT_FAILED);
else
response = getResponse(url, method, token);
}
return response;
}
示例3: fillExtent
import com.nextgis.maplib.util.NetworkUtil; //导入依赖的package包/类
public void fillExtent() {
try {
mExtent = new GeoEnvelope();
String url = NGWUtil.getExtent(mConnection.getURL(), mRemoteId);
HttpResponse response =
NetworkUtil.get(url, mConnection.getLogin(), mConnection.getPassword(), false);
if (!response.isOk())
return;
JSONObject extent =
new JSONObject(response.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));
mExtent.setMax(x, y);
x = Geo.wgs84ToMercatorSphereX(extent.getDouble(JSON_MIN_LON_KEY));
y = Geo.wgs84ToMercatorSphereY(extent.getDouble(JSON_MIN_LAT_KEY));
mExtent.setMin(x, y);
} catch (IOException | JSONException ignored) { }
}
示例4: fillFromNGW
import com.nextgis.maplib.util.NetworkUtil; //导入依赖的package包/类
protected void fillFromNGW(Map<String, String> dataMap, IProgressor progressor) throws IOException, NGException, JSONException {
if (!mNet.isNetworkAvailable()) { //return tile from cache
throw new NGException(getContext().getString(R.string.error_network_unavailable));
}
if(null != progressor){
progressor.setMessage(getContext().getString(R.string.message_loading));
}
Log.d(Constants.TAG, "download layer " + getName());
HttpResponse response =
NetworkUtil.get(NGWUtil.getResourceMetaUrl(mCacheUrl, mRemoteId), mCacheLogin,
mCachePassword, false);
if (!response.isOk()) {
throw new NGException(NetworkUtil.getError(mContext, response.getResponseCode()));
}
JSONObject geoJSONObject = new JSONObject(response.getResponseBody());
JSONObject lookupTable = geoJSONObject.getJSONObject("lookup_table");
JSONObject itemsObject = lookupTable.getJSONObject("items");
for (Iterator<String> iter = itemsObject.keys(); iter.hasNext(); ) {
String key = iter.next();
String value = itemsObject.getString(key);
dataMap.put(key, value);
}
}
示例5: sendFeatureAttachOnServer
import com.nextgis.maplib.util.NetworkUtil; //导入依赖的package包/类
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);
}
示例6: doInBackground
import com.nextgis.maplib.util.NetworkUtil; //导入依赖的package包/类
@Override
protected HttpResponse doInBackground(Integer... params) {
if (!mNet.isNetworkAvailable())
return new HttpResponse(NetworkUtil.ERROR_NETWORK_UNAVAILABLE);
try {
mLayerId = params[0];
return NetworkUtil.get(QMS_GEOSERVICE_URL + mLayerId + QMS_DETAIL_APPENDIX, null, null, false);
} catch (IOException e) {
e.printStackTrace();
}
return new HttpResponse(NetworkUtil.ERROR_DOWNLOAD_DATA);
}
示例7: onClick
import com.nextgis.maplib.util.NetworkUtil; //导入依赖的package包/类
@Override
public void onClick(View v) {
if (v.getId() == R.id.signin) {
boolean loginPasswordFilled = checkEditText(mLogin) && checkEditText(mPassword);
if (!loginPasswordFilled) {
Toast.makeText(getActivity(), R.string.field_not_filled, Toast.LENGTH_SHORT).show();
return;
}
IGISApplication application = (IGISApplication) getActivity().getApplication();
application.sendEvent(ConstantsUI.GA_NGID, ConstantsUI.GA_CONNECT, ConstantsUI.GA_USER);
mSignInButton.setEnabled(false);
final Activity activity = getActivity();
String login = mLogin.getText().toString();
String password = mPassword.getText().toString();
NGIDUtils.getToken(activity, login, password, new NGIDUtils.OnFinish() {
@Override
public void onFinish(HttpResponse response) {
mSignInButton.setEnabled(true);
if (response.isOk()) {
activity.finish();
} else {
Toast.makeText(
activity,
NetworkUtil.getError(activity, response.getResponseCode()),
Toast.LENGTH_SHORT).show();
}
}
});
} else if (v.getId() == R.id.signup) {
Intent browser = new Intent(Intent.ACTION_VIEW, Uri.parse(NGIDUtils.NGID_MY));
startActivity(browser);
}
}
示例8: onPostExecute
import com.nextgis.maplib.util.NetworkUtil; //导入依赖的package包/类
@Override
protected void onPostExecute(HttpResponse result)
{
super.onPostExecute(result);
String message;
if (result.isOk()) {
try {
JSONObject obj = new JSONObject(result.getResponseBody());
Long id = obj.getLong(Constants.JSON_ID_KEY);
if (mLayer != null)
mLayer.toNGW(id, mConnection.getName(), Constants.SYNC_ALL, mVer);
result.setResponseCode(-999);
} catch (JSONException e) {
result.setResponseCode(500);
e.printStackTrace();
}
}
switch (result.getResponseCode()) {
case -999:
message = mContext.getString(mLayer == null
? R.string.message_group_created
: R.string.message_layer_created);
break;
default:
message = NetworkUtil.getError(mContext, result.getResponseCode());
break;
}
Toast.makeText(mContext, message, Toast.LENGTH_LONG).show();
}
示例9: getResponse
import com.nextgis.maplib.util.NetworkUtil; //导入依赖的package包/类
private static HttpResponse getResponse(String target, String method, String token) {
try {
URL url = new URL(target);
HttpsURLConnection conn = (HttpsURLConnection) url.openConnection();
if (!TextUtils.isEmpty(token))
conn.setRequestProperty("Authorization", token);
conn.setRequestMethod(method);
conn.connect();
BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
String line, data = "";
while ((line = in.readLine()) != null)
data += line;
in.close();
HttpResponse response = new HttpResponse(200);
response.setResponseBody(data);
response.setOk(true);
return response;
} catch (IOException ignored) {
ignored.printStackTrace();
}
return new HttpResponse(NetworkUtil.ERROR_CONNECT_FAILED);
}
示例10: fillCapabilities
import com.nextgis.maplib.util.NetworkUtil; //导入依赖的package包/类
protected void fillCapabilities()
{
mSupportedTypes.clear();
try {
String sURL = mURL + "/resource/schema";
HttpResponse response = NetworkUtil.get(sURL, getLogin(), getPassword(), false);
if (!response.isOk())
return;
JSONObject schema = new JSONObject(response.getResponseBody());
JSONObject resources = schema.getJSONObject("resources");
if (null != resources) {
Iterator<String> keys = resources.keys();
while (keys.hasNext()) {
int type = getType(keys.next());
if (type != NGWResourceTypeNone) {
if (mSupportedTypes.isEmpty()) {
mSupportedTypes.add(type);
} else if (!isTypeSupported(type)) {
mSupportedTypes.add(type);
}
}
}
}
} catch (IOException | JSONException e) {
e.printStackTrace();
}
}
示例11: fillStyles
import com.nextgis.maplib.util.NetworkUtil; //导入依赖的package包/类
public void fillStyles()
{
mStyles = new ArrayList<>();
try {
String sURL = mConnection.getURL() + "/resource/" + mRemoteId + "/child/";
HttpResponse response =
NetworkUtil.get(sURL, mConnection.getLogin(), mConnection.getPassword(), false);
if (!response.isOk())
return;
JSONArray children = new JSONArray(response.getResponseBody());
for (int i = 0; i < children.length(); i++) {
//Only store style id
//To get more style properties need to create style class extended from Resource
//Style extends Resource
//mStyles.add(new Style(styleObject, mConnection);
JSONObject styleObject = children.getJSONObject(i);
JSONObject JSONResource = styleObject.getJSONObject("resource");
JSONArray interfaces = JSONResource.getJSONArray("interfaces");
for (int j = 0; j < interfaces.length(); j++) {
if (interfaces.getString(j).equals("IRenderableStyle")) {
long remoteId = JSONResource.getLong("id");
mStyles.add(remoteId);
break;
}
}
}
} catch (IOException | JSONException e) {
e.printStackTrace();
}
}
示例12: fillPermissions
import com.nextgis.maplib.util.NetworkUtil; //导入依赖的package包/类
public void fillPermissions()
{
try {
String sURL = mConnection.getURL() + "/api/resource/" + mRemoteId + "/permission";
HttpResponse response =
NetworkUtil.get(sURL, mConnection.getLogin(), mConnection.getPassword(), false);
if (!response.isOk())
return;
mPermissions = new JSONObject(response.getResponseBody());
if (!mPermissions.has(Constants.JSON_RESOURCE_KEY))
mPermissions = null;
} catch (IOException | JSONException e) {
e.printStackTrace();
}
}
示例13: NGWLookupTable
import com.nextgis.maplib.util.NetworkUtil; //导入依赖的package包/类
public NGWLookupTable(Context context, File path) {
super(context, path);
mNet = new NetworkUtil(context);
mSyncType = Constants.SYNC_NONE;
mLayerType = Constants.LAYERTYPE_LOOKUPTABLE;
}
示例14: RemoteTMSLayer
import com.nextgis.maplib.util.NetworkUtil; //导入依赖的package包/类
public RemoteTMSLayer(
Context context,
File path)
{
super(context, path);
mNet = new NetworkUtil(context);
mSubdomains = new ArrayList<>();
mCurrentSubdomain = 0;
mLayerType = LAYERTYPE_REMOTE_TMS;
mTileMaxAge = DEFAULT_TILE_MAX_AGE;
setViewSize(100, 100);
}
示例15: getTileFromStream
import com.nextgis.maplib.util.NetworkUtil; //导入依赖的package包/类
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);
}