com.vk.sdk.VKSdk Java Examples
The following examples show how to use
com.vk.sdk.VKSdk.
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: LoginMaster.java From uPods-android with Apache License 2.0 | 6 votes |
public void initUserProfile(final IOperationFinishWithDataCallback profileFetched, boolean isForceUpdate) { if (userProfile != null && !isForceUpdate) { profileFetched.operationFinished(userProfile); } else if (!isLogedIn()) { userProfile = new UserProfile(); profileFetched.operationFinished(userProfile); } else { if (AccessToken.getCurrentAccessToken() != null) { fetchFacebookUserData(profileFetched); } else if (Twitter.getSessionManager().getActiveSession() != null) { fetchTwitterUserData(profileFetched); } else if (VKSdk.isLoggedIn()) { fetchVkUserData(profileFetched); } } }
Example #2
Source File: VKModelOperation.java From cordova-social-vk with Apache License 2.0 | 6 votes |
@Override protected boolean postExecution() { if (!super.postExecution()) return false; if (mParser != null) { try { JSONObject response = getResponseJson(); parsedModel = mParser.createModel(response); return true; } catch (Exception e) { if (VKSdk.DEBUG) { e.printStackTrace(); } } } return false; }
Example #3
Source File: NavigationDrawerFragment.java From IdealMedia with Apache License 2.0 | 6 votes |
private void shareVK() { if (VKSdk.isLoggedIn() || VKSdk.wakeUpSession()) { new VKShareDialog() .setText(getString(R.string.like_text)) .setAttachmentLink(getString(R.string.like_url_title), getString(R.string.like_url)) .setShareDialogListener(new VKShareDialog.VKShareDialogListener() { @Override public void onVkShareComplete(int i) { showThankYouToast(); ((NavigationActivity)getActivity()).getTracker(NavigationActivity.TrackerName.APP_TRACKER) .send(new HitBuilders.EventBuilder().setCategory("Sharing").setAction("VK").setLabel("OK").build()); } @Override public void onVkShareCancel() { ((NavigationActivity)getActivity()).getTracker(NavigationActivity.TrackerName.APP_TRACKER) .send(new HitBuilders.EventBuilder().setCategory("Sharing").setAction("VK").setLabel("Cancel").build()); } }) .show(getFragmentManager(), "SHARE"); } else VKSdk.authorize(NavigationActivity.vkScope, true, false); }
Example #4
Source File: LoginActivity.java From vk_music_android with GNU General Public License v3.0 | 6 votes |
@Override protected void onActivityResult(final int requestCode, int resultCode, Intent data) { if (!VKSdk.onActivityResult(requestCode, resultCode, data, new VKCallback<VKAccessToken>() { @Override public void onResult(final VKAccessToken accessToken) { createUserComponentAndLaunchMainActivity(); } @Override public void onError(VKError error) { new AlertDialog.Builder(LoginActivity.this) .setMessage("Login failed: " + error.errorReason) .setPositiveButton(android.R.string.ok, null) .show(); } })) { super.onActivityResult(requestCode, resultCode, data); } }
Example #5
Source File: VKList.java From cordova-social-vk with Apache License 2.0 | 6 votes |
/** * Fills list according with data in {@code from}. * @param from an array of items in the list. You can use null. * @param creator interface implementation to parse objects. */ public void fill(JSONArray from, Parser<? extends T> creator) { if(from != null) { for(int i = 0; i < from.length(); i++) { try { T object = creator.parseObject(from.getJSONObject(i)); if(object != null) { items.add(object); } } catch (Exception e) { if (VKSdk.DEBUG) e.printStackTrace(); } } } }
Example #6
Source File: LoginMaster.java From uPods-android with Apache License 2.0 | 6 votes |
public void logout() { if (AccessToken.getCurrentAccessToken() != null) { LoginManager.getInstance().logOut(); Logger.printInfo(LOG_TAG, "Loged out from facebook"); } if (Twitter.getSessionManager().getActiveSession() != null) { Twitter.getSessionManager().clearActiveSession(); Twitter.logOut(); Logger.printInfo(LOG_TAG, "Loged out from twitter"); } if (VKSdk.isLoggedIn()) { VKSdk.logout(); Logger.printInfo(LOG_TAG, "Loged out from vk"); } Prefs.remove(SyncMaster.GLOBAL_TOKEN); userProfile = new UserProfile(); }
Example #7
Source File: VKUploadImage.java From cordova-social-vk with Apache License 2.0 | 6 votes |
public File getTmpFile() { Context ctx = VKUIHelper.getApplicationContext(); File outputDir = null; if (ctx != null) { outputDir = ctx.getExternalCacheDir(); if (outputDir == null || !outputDir.canWrite()) outputDir = ctx.getCacheDir(); } File tmpFile = null; try { tmpFile = File.createTempFile("tmpImg", String.format(".%s", mParameters.fileExtension()), outputDir); FileOutputStream fos = new FileOutputStream(tmpFile); if (mParameters.mImageType == VKImageParameters.VKImageType.Png) mImageData.compress(Bitmap.CompressFormat.PNG, 100, fos); else mImageData.compress(Bitmap.CompressFormat.JPEG, (int) (mParameters.mJpegQuality * 100), fos); fos.close(); } catch (IOException ignored) { if (VKSdk.DEBUG) ignored.printStackTrace(); } return tmpFile; }
Example #8
Source File: FragmentProfile.java From uPods-android with Apache License 2.0 | 6 votes |
@Override public void onActivityResult(int requestCode, int resultCode, Intent data) { mTwitterAuthClient.onActivityResult(requestCode, resultCode, data); if (!VKSdk.onActivityResult(requestCode, resultCode, data, new VKCallback<VKAccessToken>() { @Override public void onResult(VKAccessToken token) { initUIAfterLogin(); } @Override public void onError(VKError error) { } })) { super.onActivityResult(requestCode, resultCode, data); } else { super.onActivityResult(requestCode, resultCode, data); } }
Example #9
Source File: VKShareDialogDelegate.java From cordova-social-vk with Apache License 2.0 | 6 votes |
@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); } }
Example #10
Source File: VKUtil.java From cordova-social-vk with Apache License 2.0 | 6 votes |
/** * Returns md5 hash of string * * @param s string to hash * @return md5 hash */ public static String md5(final String s) { try { // Create MD5 Hash MessageDigest digest = MessageDigest.getInstance("MD5"); digest.update(s.getBytes()); byte messageDigest[] = digest.digest(); // Create Hex String StringBuilder hexString = new StringBuilder(); for (byte aMessageDigest : messageDigest) { String h = Integer.toHexString(0xFF & aMessageDigest); while (h.length() < 2) h = "0" + h; hexString.append(h); } return hexString.toString(); } catch (NoSuchAlgorithmException e) { if (VKSdk.DEBUG) e.printStackTrace(); } return ""; }
Example #11
Source File: VKUtil.java From cordova-social-vk with Apache License 2.0 | 6 votes |
/** * Builds map from list of strings * * @param args key-value pairs for build a map. Must be a multiple of 2 * @return Result map. If args not multiple of 2, last argument will be ignored */ public static Map<String, Object> mapFrom(Object... args) { if (args.length % 2 != 0) { if (VKSdk.DEBUG) Log.w("VKUtil", "Params must be paired. Last one is ignored"); } LinkedHashMap<String, Object> result = new LinkedHashMap<>(args.length / 2); for (int i = 0; i + 1 < args.length; i += 2) { if (args[i] == null || args[i + 1] == null || !(args[i] instanceof String)) { if (VKSdk.DEBUG) Log.e("VK SDK", "Error while using mapFrom", new InvalidParameterSpecException("Key and value must be specified. Key must be string")); continue; } result.put((String) args[i], args[i + 1]); } return result; }
Example #12
Source File: VKShareDialogDelegate.java From cordova-social-vk with Apache License 2.0 | 5 votes |
private void makePostWithAttachments(VKAttachments attachments) { if (attachments == null) { attachments = new VKAttachments(); } if (mExistingPhotos != null) { attachments.addAll(mExistingPhotos); } if (mAttachmentLink != null) { attachments.add(new VKApiLink(mAttachmentLink.linkUrl)); } String message = mShareTextField.getText().toString(); final Long userId = Long.parseLong(VKSdk.getAccessToken().userId); VKRequest wallPost = VKApi.wall().post(VKParameters.from(VKApiConst.OWNER_ID, userId, VKApiConst.MESSAGE, message, VKApiConst.ATTACHMENTS, attachments.toAttachmentsString())); wallPost.executeWithListener(new VKRequest.VKRequestListener() { @Override public void onError(VKError error) { setIsLoading(false); if (mListener != null) { mListener.onVkShareError(error); } } @Override public void onComplete(VKResponse response) { setIsLoading(false); VKWallPostResult res = (VKWallPostResult) response.parsedModel; if (mListener != null) { mListener.onVkShareComplete(res.post_id); } dialogFragmentI.dismissAllowingStateLoss(); } }); }
Example #13
Source File: SocialVk.java From cordova-social-vk with Apache License 2.0 | 5 votes |
private boolean init(String appId) { this.cordova.setActivityResultCallback(this); Log.i(TAG, "VK initialize"); VKSdk.initialize(getApplicationContext()); if(_callbackContext != null) { _callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK)); _callbackContext.success(); } return true; }
Example #14
Source File: VKRequest.java From cordova-social-vk with Apache License 2.0 | 5 votes |
private boolean processCommonError(final VKError error) { //TODO: lock thread, if ui required, release then if (error.errorCode == VKError.VK_API_ERROR) { final VKError apiError = error.apiError; VKSdk.notifySdkAboutApiError(apiError); if (apiError.errorCode == 16) { VKAccessToken token = VKAccessToken.currentToken(); if (token != null) { token.httpsRequired = true; token.save(); } repeat(); return true; } else if (shouldInterruptUI) { apiError.request = this; if (error.apiError.errorCode == 14) { this.mLoadingOperation = null; VKServiceActivity.interruptWithError(context, apiError, VKServiceActivity.VKServiceType.Captcha); return true; } else if (apiError.errorCode == 17) { VKServiceActivity.interruptWithError(context, apiError, VKServiceActivity.VKServiceType.Validation); return true; } } } return false; }
Example #15
Source File: VKRequest.java From cordova-social-vk with Apache License 2.0 | 5 votes |
public VKParameters getPreparedParameters() { if (mPreparedParameters == null) { mPreparedParameters = new VKParameters(mMethodParameters); //Set current access token from SDK object VKAccessToken token = VKAccessToken.currentToken(); if (token != null) { mPreparedParameters.put(VKApiConst.ACCESS_TOKEN, token.accessToken); if (token.httpsRequired) { this.secure = true; } } //Set actual version of API mPreparedParameters.put(VKApiConst.VERSION, VKSdk.getApiVersion()); //Set preferred language for request mPreparedParameters.put(VKApiConst.LANG, getLang()); if (this.secure) { //If request is secure, we need all urls as https mPreparedParameters.put(VKApiConst.HTTPS, "1"); } if (token != null && token.secret != null) { //If it not, generate signature of request String sig = generateSig(token); mPreparedParameters.put(VKApiConst.SIG, sig); } //From that moment you cannot modify parameters. //Specially for http loading } return mPreparedParameters; }
Example #16
Source File: VKDefaultParser.java From cordova-social-vk with Apache License 2.0 | 5 votes |
@Override public Object createModel(JSONObject object) { try { VKApiModel model = mModelClass.newInstance(); model.parse(object); return model; } catch (Exception e) { if (VKSdk.DEBUG) e.printStackTrace(); } return null; }
Example #17
Source File: VKHttpClient.java From cordova-social-vk with Apache License 2.0 | 5 votes |
public VKHTTPRequest(@Nullable String url) { if (url != null) { try { this.methodUrl = new URL(url); } catch (MalformedURLException e) { if (VKSdk.DEBUG) { e.printStackTrace(); } } } }
Example #18
Source File: SocialVk.java From cordova-social-vk with Apache License 2.0 | 5 votes |
private boolean shareOrLogin(final String url, final String comment, final String imageUrl) { this.cordova.setActivityResultCallback(this); final String[] scope = new String[]{VKScope.WALL, VKScope.PHOTOS}; if(!VKSdk.isLoggedIn()) { savedUrl = url; savedComment = comment; savedImageUrl = imageUrl; VKSdk.login(getActivity(), scope); } else { share(url, comment, imageUrl); } return true; }
Example #19
Source File: LoginActivity.java From vk_music_android with GNU General Public License v3.0 | 5 votes |
@Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (VKSdk.isLoggedIn()) { createUserComponentAndLaunchMainActivity(); return; } setTitle(R.string.log_in); ActivityLoginBinding binding = DataBindingUtil.setContentView(this, R.layout.activity_login); binding.login.setOnClickListener(v -> VKSdk.login(LoginActivity.this, "audio", "offline")); }
Example #20
Source File: MainActivity.java From vk_music_android with GNU General Public License v3.0 | 5 votes |
public void onLogoutClicked(View sender) { VKSdk.logout(); ((VkApplication) getApplication()).releaseUserComponent(); Intent intent = new Intent(this, LoginActivity.class); startActivity(intent); finish(); }
Example #21
Source File: VkApplication.java From vk_music_android with GNU General Public License v3.0 | 5 votes |
@Override public void onCreate() { super.onCreate(); if (!BuildConfig.DEBUG) { Fabric.with(this, new Crashlytics()); } appComponent = DaggerAppComponent.builder() .appModule(new AppModule(this)) .build(); vkAccessTokenTracker.startTracking(); VKSdk.initialize(this); Paper.init(this); Dexter.initialize(this); DrawerImageLoader.init(new AbstractDrawerImageLoader() { @Override public void set(ImageView imageView, Uri uri, Drawable placeholder, String tag) { Glide.with(imageView.getContext()) .load(uri) .into(imageView); } }); }
Example #22
Source File: LoginMaster.java From uPods-android with Apache License 2.0 | 5 votes |
public void init() { //First init VKSdk because it is used by vkAuthenticationProvider VKSdk.initialize(UpodsApplication.getContext()); initFacebook(); initTwitter(); initVkontakte(); }
Example #23
Source File: FragmentProfile.java From uPods-android with Apache License 2.0 | 5 votes |
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { mTwitterAuthClient = new TwitterAuthClient(); ((IToolbarHolder) getActivity()).getToolbar().setVisibility(View.GONE); rootView = inflater.inflate(R.layout.fragment_profile, container, false); loginManager = (ILoginManager) getActivity(); lnLoggedInState = (LinearLayout) rootView.findViewById(R.id.lnLoggedInState); lnLoggedOutState = (LinearLayout) rootView.findViewById(R.id.lnLoggedOutState); progressBar = (ProgressBar) rootView.findViewById(R.id.pbLoading); progressBar.setVisibility(View.GONE); rootView.findViewById(R.id.btnVklogin).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { VKSdk.login(FragmentProfile.this, VK_SCOPE); } }); if (LoginMaster.getInstance().isLogedIn()) { lnLoggedOutState.setVisibility(View.GONE); lnLoggedInState.setVisibility(View.VISIBLE); initUserProfileUI(); } else { initLoginUI(rootView); } return rootView; }
Example #24
Source File: NavigationActivity.java From IdealMedia with Apache License 2.0 | 5 votes |
@Override public void onVkLogout() { VKSdk.logout(); Toast.makeText(this, android.R.string.ok, Toast.LENGTH_SHORT).show(); putPlayerFragment(); getTracker(NavigationActivity.TrackerName.APP_TRACKER) .send(new HitBuilders.EventBuilder().setCategory("UX").setAction("settings").setLabel("vk logout").build()); }
Example #25
Source File: VKAudioFragment.java From IdealMedia with Apache License 2.0 | 5 votes |
@Override public void onResume() { super.onResume(); if (VKSdk.isLoggedIn() || VKSdk.wakeUpSession()) update(isNeedUpdate()); else VKSdk.authorize(NavigationActivity.vkScope, true, false); }
Example #26
Source File: SocialVk.java From cordova-social-vk with Apache License 2.0 | 4 votes |
private boolean login(String[] permissions) { VKSdk.login(getActivity(), permissions); return true; }
Example #27
Source File: LoginMaster.java From uPods-android with Apache License 2.0 | 4 votes |
public boolean isLogedIn() { return AccessToken.getCurrentAccessToken() != null || Twitter.getSessionManager().getActiveSession() != null || VKSdk.isLoggedIn(); }