当前位置: 首页>>代码示例>>Java>>正文


Java VKResponse类代码示例

本文整理汇总了Java中com.vk.sdk.api.VKResponse的典型用法代码示例。如果您正苦于以下问题:Java VKResponse类的具体用法?Java VKResponse怎么用?Java VKResponse使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


VKResponse类属于com.vk.sdk.api包,在下文中一共展示了VKResponse类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: onClick

import com.vk.sdk.api.VKResponse; //导入依赖的package包/类
@Override
public void onClick(View view) {
    setIsLoading(true);
    if (mAttachmentImages != null && VKSdk.getAccessToken() != null) {
        final Long userId = Long.parseLong(VKSdk.getAccessToken().userId);
        VKUploadWallPhotoRequest photoRequest = new VKUploadWallPhotoRequest(mAttachmentImages, userId, 0);
        photoRequest.executeWithListener(new VKRequest.VKRequestListener() {
            @Override
            public void onComplete(VKResponse response) {
                VKPhotoArray photos = (VKPhotoArray) response.parsedModel;
                VKAttachments attachments = new VKAttachments(photos);
                makePostWithAttachments(attachments);
            }

            @Override
            public void onError(VKError error) {
                setIsLoading(false);
                if (mListener != null) {
                    mListener.onVkShareError(error);
                }
            }
        });
    } else {
        makePostWithAttachments(null);
    }
}
 
开发者ID:DESTROYED,项目名称:The_busy_calendar,代码行数:27,代码来源:VKShareDialogDelegate.java

示例2: onPlaylistClicked

import com.vk.sdk.api.VKResponse; //导入依赖的package包/类
@Override
public void onPlaylistClicked(VkApiAlbum playlist, int position) {
    if(binding.loadingIndicator.getVisibility() == View.VISIBLE){
        return; // Don't accept click events when loading
    }

    binding.loadingIndicator.setVisibility(View.VISIBLE);

    VKApi.audio().add(VKParameters.from("audio_id", audioToAdd.id, "owner_id", audioToAdd.owner_id, VKApiConst.ALBUM_ID, playlist.getId())).executeWithListener(new VKRequest.VKRequestListener() {
        @Override
        public void onComplete(VKResponse response) {
            if(listener != null){
                listener.onAudioAddedToPlaylist(audioToAdd, playlist);
            }
            dismissAllowingStateLoss();
        }
    });
}
 
开发者ID:Mavamaarten,项目名称:vk_music_android,代码行数:19,代码来源:AddTrackToPlaylistDialogFragment.java

示例3: removeAudio

import com.vk.sdk.api.VKResponse; //导入依赖的package包/类
private void removeAudio(VKApiAudio audio, int position) {
    VKApi.audio().delete(VKParameters.from("audio_id", audio.id, "owner_id", audio.owner_id)).executeWithListener(new VKRequest.VKRequestListener() {
        @Override
        public void onComplete(VKResponse response) {
            try {
                int responseCode = response.json.getInt("response");
                if (responseCode == 1) {
                    audioArray.remove(position);
                    adapter.notifyItemRemoved(position);
                    Snackbar.make(binding.getRoot(), R.string.track_removed, Snackbar.LENGTH_SHORT).show();
                }
            } catch (JSONException e) {
                onError(null);
            }
        }

        @Override
        public void onError(VKError error) {
            Snackbar.make(binding.getRoot(), R.string.error_deleting_track, Snackbar.LENGTH_LONG).show();
        }
    });
}
 
开发者ID:Mavamaarten,项目名称:vk_music_android,代码行数:23,代码来源:AudioListFragment.java

示例4: onAddPlaylistClicked

import com.vk.sdk.api.VKResponse; //导入依赖的package包/类
private void onAddPlaylistClicked() {
    View alertView = LayoutInflater.from(this).inflate(R.layout.layout_dialog_createplaylist, null, false);
    EditText playlistTitle = (EditText) alertView.findViewById(R.id.playlist_title);

    new AlertDialog.Builder(this)
            .setTitle(R.string.create_playlist)
            .setView(alertView)
            .setNegativeButton(android.R.string.cancel, null)
            .setPositiveButton(android.R.string.ok, (dialog, which) -> {
                VKApi.audio().addAlbum(VKParameters.from("title", playlistTitle.getText())).executeWithListener(new VKRequest.VKRequestListener() {
                    @Override
                    public void onComplete(VKResponse response) {
                        loadPlaylists();
                    }
                });
            })
            .show();
}
 
开发者ID:Mavamaarten,项目名称:vk_music_android,代码行数:19,代码来源:MainActivity.java

示例5: onPlaylistItemLongClicked

import com.vk.sdk.api.VKResponse; //导入依赖的package包/类
private void onPlaylistItemLongClicked(VkApiAlbum playlist) {
    new AlertDialog.Builder(this)
            .setMessage("Are you sure you want to delete " + playlist.getTitle() + "?")
            .setNegativeButton(android.R.string.cancel, null)
            .setPositiveButton(android.R.string.ok, (dialog, which) -> {
                VKApi.audio().deleteAlbum(VKParameters.from(VKApiConst.ALBUM_ID, playlist.getId())).executeWithListener(new VKRequest.VKRequestListener() {
                    @Override
                    public void onComplete(VKResponse response) {
                        drawer.removeItem(playlist.getId());
                        loadPlaylists();
                        Snackbar.make(binding.slidinglayout, R.string.deleted_playlist, Snackbar.LENGTH_SHORT).show();
                    }
                });
            })
            .show();
}
 
开发者ID:Mavamaarten,项目名称:vk_music_android,代码行数:17,代码来源:MainActivity.java

示例6: onComplete

import com.vk.sdk.api.VKResponse; //导入依赖的package包/类
@Override
public void onComplete(VKResponse response) {
    super.onComplete(response);

    JSONObject responseObj = null;

    try {
        responseObj = response.json.getJSONObject("response");
    } catch (Exception e) {
        e.printStackTrace();
    }

    if (responseObj == null) {
        Log.i(LOG_TAG, "response is null");
        return;
    }

    String text = responseObj.optString("text");
    int lyricsId = responseObj.optInt("lyrics_id");
    onLyrics(lyricsId, text);
}
 
开发者ID:DmitriyG1,项目名称:vk-music-player-android,代码行数:22,代码来源:VkAudioHelper.java

示例7: onReceiveNewToken

import com.vk.sdk.api.VKResponse; //导入依赖的package包/类
@Override
public void onReceiveNewToken(VKAccessToken newToken) {
    super.onReceiveNewToken(newToken);
    newToken.saveTokenToSharedPreferences(getActivity(), "VK_ACCESS_TOKEN");

    VKRequest request = VKApi.users().get(VKParameters.from(VKApiConst.FIELDS, "photo_200"));
    request.executeWithListener(new VKRequest.VKRequestListener() {
        @Override
        public void onComplete(VKResponse response) {
            super.onComplete(response);

            VKList<VKApiUserFull> vkList = (VKList<VKApiUserFull>) response.parsedModel;
            VKApiUserFull user = vkList.get(0);
            saveUserData(
                    user.first_name + " " + user.last_name,
                    user.photo_200
            );
            ((BaseSocialActivity) getActivity()).setLoginStatus(true, Const.SocialNetworks.VK_ID);
            moveToProfile();
        }
    });
    Log.d(LOG_TAG, "New User Token received");
}
 
开发者ID:CheDream-Android,项目名称:CheDream,代码行数:24,代码来源:LoginFragment.java

示例8: makePost

import com.vk.sdk.api.VKResponse; //导入依赖的package包/类
private void makePost(VKAttachments attachments, String message) {
    VKRequest post = VKApi.wall().post(VKParameters.from(VKApiConst.OWNER_ID, "-" + TARGET_GROUP, VKApiConst.ATTACHMENTS, attachments, VKApiConst.MESSAGE, message));
    post.setModelClass(VKWallPostResult.class);
    post.executeWithListener(new VKRequestListener() {
        @Override
        public void onComplete(VKResponse response) {
            if (isAdded()) {
                VKWallPostResult result = (VKWallPostResult) response.parsedModel;
                Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(String.format("https://vk.com/wall-%d_%s", TARGET_GROUP, result.post_id)));
                startActivity(i);
            }
        }

        @Override
        public void onError(VKError error) {
            showError(error.apiError != null ? error.apiError : error);
        }
    });
}
 
开发者ID:VKCOM,项目名称:vk-android-sdk,代码行数:20,代码来源:TestActivity.java

示例9: setPhoto

import com.vk.sdk.api.VKResponse; //导入依赖的package包/类
public void setPhoto(final ImageView imageView, final Button button){
    VKParameters params = new VKParameters();
    params.put(VKApiConst.FIELDS, "photo_max_orig");

    VKRequest request = new VKRequest("users.get",params);
    request.executeWithListener(new VKRequest.VKRequestListener() {

        @Override
        public void onComplete(VKResponse response) {
            super.onComplete(response);
            JSONArray resp = null;
            try {
                resp = response.json.getJSONArray("response");
                JSONObject user = resp.getJSONObject(0);
                String photo_max_orig_url = user.getString("photo_max_orig");
                imageView.setVisibility(View.VISIBLE);
                button.setVisibility(View.GONE);
                Glide.with(context).load(photo_max_orig_url).into(imageView);
            } catch (JSONException e) {
                Log.d("VkSdkHelper", String.valueOf(e));
            }
            }

        @Override
        public void onError(VKError error) {
            super.onError(error);
        }
    });
}
 
开发者ID:DESTROYED,项目名称:The_busy_calendar,代码行数:30,代码来源:VkSdkHelper.java

示例10: wakeUpSession

import com.vk.sdk.api.VKResponse; //导入依赖的package包/类
/**
 * Checks if an access token exist and performs a try to use it again
 *
 * @param context            An application context for store an access token
 * @param loginStateCallback if callback specified, {@link VKCallback#onResult(Object)} method will be called after login state changed
 * @return true, if an access token exists and not expired
 */
public static boolean wakeUpSession(@NonNull final Context context, final VKCallback<LoginState> loginStateCallback) {
    final Context appContext = context.getApplicationContext();
    VKUIHelper.setApplicationContext(appContext);

    VKAccessToken token = VKAccessToken.currentToken();

    if (token != null && token.accessToken != null && !token.isExpired()) {
        forceLoginState(LoginState.Pending, loginStateCallback);
        trackVisitor(new VKRequest.VKRequestListener() {
            @Override
            public void onComplete(VKResponse response) {
                updateLoginState(context, loginStateCallback);
            }

            @Override
            public void onError(VKError error) {
                //Possible double call of access token invalid
                if (error != null && error.apiError != null && error.apiError.errorCode == 5) {
                    onAccessTokenIsInvalid(appContext);
                }
                updateLoginState(context, loginStateCallback);
            }
        });
        return true;
    }
    updateLoginState(context, loginStateCallback);
    return false;
}
 
开发者ID:DESTROYED,项目名称:The_busy_calendar,代码行数:36,代码来源:VKSdk.java

示例11: onComplete

import com.vk.sdk.api.VKResponse; //导入依赖的package包/类
@Override
public void onComplete(VKResponse response) {
    synchronized (this.syncObj) {
        try {
            listener.onComplete(response);
        } catch (Exception e) {
            // nothing
        }
        isFinish = true;
        syncObj.notifyAll();
    }
}
 
开发者ID:DESTROYED,项目名称:The_busy_calendar,代码行数:13,代码来源:VKSyncRequestUtil.java

示例12: run

import com.vk.sdk.api.VKResponse; //导入依赖的package包/类
@Override
public void run() {
    if (mCheckUserInstallAnswer == CHECK_USER_INSTALL_ANSWER_VK
            || mCheckUserInstallAnswer == CHECK_USER_INSTALL_ANSWER_VK_FORCE) {
        for (final String receipt : purchases) {

            final String platform = "android";
            final int appId = getIntResByName(mAppCtx, VKSdk.SDK_APP_ID);
            final String deviceId = getDeviceId(mAppCtx);

            VKRequest request = new VKRequest(METHOD_NAME_SAVE_TRANSACTION);
            request.addExtraParameter(PLATFORM, platform);
            request.addExtraParameter(APP_ID, appId);
            if (!TextUtils.isEmpty(deviceId)) {
                request.addExtraParameter(DEVICE_ID, deviceId);
            }
            request.addExtraParameter(RECEIPT, receipt);

            request.executeSyncWithListener(new VKRequest.VKRequestListener() {
                @Override
                public void onComplete(VKResponse response) {
                    VKPaymentsDatabase.getInstance(mAppCtx).deletePurchase(receipt);
                    log("apps.saveTransaction successful response=" + response.json);
                }

                @Override
                public void onError(VKError error) {
                    log("apps.saveTransaction error=" + (error.apiError == null ? error.errorMessage : error.apiError.errorMessage));
                }
            });
        }
    }
}
 
开发者ID:marpies,项目名称:vk-ane,代码行数:34,代码来源:VKPaymentsServerSender.java

示例13: onResume

import com.vk.sdk.api.VKResponse; //导入依赖的package包/类
@Override
public void onResume() {
    super.onResume();

    binding.loadingIndicator.setVisibility(View.VISIBLE);
    VKApi.audio().getAlbums(VKParameters.from(VKApiConst.OWNER_ID, user.getId())).executeWithListener(new VKRequest.VKRequestListener() {
        @Override
        public void onComplete(VKResponse response) {
            VkApiAlbumArrayResponse albumsResponse = gson.fromJson(response.responseString, VkApiAlbumArrayResponse.class);
            playlists.clear();
            playlists.addAll(albumsResponse.getResponse().getItems());

            for (VkApiAlbum album : playlists) {
                String fixedTitle;
                if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N) {
                    fixedTitle = Html.fromHtml(album.getTitle(), Html.FROM_HTML_MODE_LEGACY).toString();
                } else {
                    fixedTitle = Html.fromHtml(album.getTitle()).toString();
                }
                album.setTitle(fixedTitle);
            }

            adapter.notifyDataSetChanged();
            binding.loadingIndicator.setVisibility(View.GONE);
        }

        @Override
        public void onError(VKError error) {
            binding.loadingIndicator.setVisibility(View.VISIBLE);
            Snackbar.make(binding.rcvPlaylists, "Error loading playlists", Snackbar.LENGTH_LONG).show();
        }
    });
}
 
开发者ID:Mavamaarten,项目名称:vk_music_android,代码行数:34,代码来源:AddTrackToPlaylistDialogFragment.java

示例14: loadRadio

import com.vk.sdk.api.VKResponse; //导入依赖的package包/类
public void loadRadio(@Nullable VKApiAudio radioTrack, @Nullable Action0 onCompletedCallback) {
    binding.loadingIndicator.setVisibility(View.VISIBLE);

    VKParameters parameters;
    if (radioTrack == null) {
        parameters = VKParameters.from(VKApiConst.COUNT, 100, "shuffle", 1);
    } else {
        parameters = VKParameters.from("target_audio", radioTrack.owner_id + "_" + radioTrack.id, VKApiConst.COUNT, 100, "shuffle", 1);
    }

    VKApi.audio().getRecommendations(parameters).executeWithListener(new VKRequest.VKRequestListener() {
        @Override
        public void onComplete(VKResponse response) {
            audioArray.clear();
            audioArray.addAll((VkAudioArray) response.parsedModel);
            adapter.notifyDataSetChanged();
            binding.loadingIndicator.setVisibility(View.GONE);

            if (audioArray.size() == 0) {
                Snackbar.make(binding.getRoot(), R.string.no_similar_tracks, Snackbar.LENGTH_LONG).show();
                binding.noData.getRoot().setVisibility(View.VISIBLE);
            } else {
                binding.noData.getRoot().setVisibility(View.GONE);
            }

            if (onCompletedCallback != null) onCompletedCallback.call();
        }

        @Override
        public void onError(VKError error) {
            Snackbar.make(binding.rcvAudio, R.string.error_loading_radio, Snackbar.LENGTH_LONG);
            binding.loadingIndicator.setVisibility(View.GONE);
        }
    });
}
 
开发者ID:Mavamaarten,项目名称:vk_music_android,代码行数:36,代码来源:RadioFragment.java

示例15: getVKRequestListener

import com.vk.sdk.api.VKResponse; //导入依赖的package包/类
private VKRequest.VKRequestListener getVKRequestListener(){
    if(mVKRequestListener != null){
        return mVKRequestListener;
    }

    mVKRequestListener = new VKRequest.VKRequestListener() {
        @Override
        public void onComplete(VKResponse response) {
            super.onComplete(response);
            Log.i(LOG_TAG, "onComplete, parameters: " +  mRequest.getMethodParameters());

            onRequestComplete(processResponse(response));
        }

        @Override
        public void attemptFailed(VKRequest request, int attemptNumber, int totalAttempts) {
            super.attemptFailed(request, attemptNumber, totalAttempts);
            Log.i(LOG_TAG, "attemptFailed attemptNumber: " + attemptNumber +
                    ", totalAttempts: " + totalAttempts);
        }

        @Override
        public void onError(VKError error) {
            super.onError(error);
            Log.i(LOG_TAG, "error: " + error);
        }
    };

    return mVKRequestListener;
}
 
开发者ID:DmitriyG1,项目名称:vk-music-player-android,代码行数:31,代码来源:VkAudioInfoLoader.java


注:本文中的com.vk.sdk.api.VKResponse类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。