예제 #1
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_vklogin);

    VKUIHelper.onCreate(this);
    VKSdk.initialize(sdkListener, appID, VKAccessToken.tokenFromSharedPreferences(this, sTokenKey));
    VKSdk.authorize(sMyScope, true, true);
  }
예제 #2
0
  public boolean logout() {
    VKSdk.logout();
    if (!VKSdk.isLoggedIn()) {
      dao.reset();
      bus.post(new VkLogoutEvent());

      return true;
    } else {
      return false;
    }
  }
예제 #3
0
 @Override
 protected void onResume() {
   super.onResume();
   VKUIHelper.onResume(this);
   if (VKSdk.wakeUpSession()) {
     MyIntentService.startActionNewsfeedGetVKRequest(
         context,
         myApp.getPreferences().getVkToken(),
         myApp.getPreferences().getVKFeedStartFrom());
   } else {
     VKSdk.authorize(sMyScope, true, true);
   }
 }
  public VKParameters getPreparedParameters() {
    if (mPreparedParameters == null) {
      mPreparedParameters = new VKParameters(mMethodParameters);

      // Set current access token from SDK object
      VKAccessToken token = VKSdk.getAccessToken();
      if (token != null) mPreparedParameters.put(VKApiConst.ACCESS_TOKEN, token.accessToken);
      if (!this.secure)
        if (token != null && (token.secret != null || token.httpsRequired)) {
          this.secure = true;
        }
      // Set actual version of API
      mPreparedParameters.put(VKApiConst.VERSION, VKSdkVersion.API_VERSION);
      // 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;
  }
예제 #5
0
  @Override
  protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (!VKSdk.onActivityResult(
        requestCode,
        resultCode,
        data,
        new VKCallback<VKAccessToken>() {
          @Override
          public void onResult(VKAccessToken res) {
            Log.d(LOG_T, "Successfully logged in");
            Intent intent = new Intent();
            intent.putExtra("result", "LoggedIN");
            setResult(RESULT_OK, intent);
            finish();
          }

          @Override
          public void onError(VKError error) {
            Log.d(LOG_T, "Error");
            Intent intent = new Intent();
            intent.putExtra("result", "ERROR");
            setResult(RESULT_CANCELED, intent);
            finish();
          }
        })) {
      super.onActivityResult(requestCode, resultCode, data);
    }
  }
 @Override
 public void onClick(View v) {
   switch (v.getId()) {
     case R.id.btn_login:
       VKSdk.login(this, "friends", "photos");
       break;
   }
 }
예제 #7
0
 @Override
 protected void onCreate(Bundle savedInstanceState) {
   super.onCreate(savedInstanceState);
   setContentView(R.layout.activity_login);
   Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
   setSupportActionBar(toolbar);
   VKSdk.login(this, sMyScope);
 }
예제 #8
0
  @Override
  public void onCreate() {
    super.onCreate();

    context = getApplicationContext();

    vkAccessTokenTracker.startTracking();
    VKSdk.initialize(this);
  }
  @Override
  public void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (!VKSdk.onActivityResult(
        requestCode,
        resultCode,
        data,
        new VKCallback<VKAccessToken>() {
          @Override
          public void onResult(VKAccessToken res) {
            // Пользователь успешно авторизовался
            userID = res.userId;

            Log.d(LOG_TAG, " onResult");

            final Bitmap photo = mBitmap;

            VKRequest request2 =
                VKApi.uploadWallPhotoRequest(
                    new VKUploadImage(photo, VKImageParameters.jpgImage(0.9f)), 0, 0);

            request2.executeWithListener(
                new VKRequest.VKRequestListener() {
                  @Override
                  public void onComplete(VKResponse response) {
                    photo.recycle();
                    VKApiPhoto photoModel = ((VKPhotoArray) response.parsedModel).get(0);
                    // Make post with photo

                    Log.d(LOG_TAG, " photoModel.getId() = " + photoModel.getId());

                    makePost(
                        new VKAttachments(photoModel),
                        mCharacter.getName() + "\n" + mCharacter.getDescription());
                    Log.d(LOG_TAG, " onComplete");
                  }

                  @Override
                  public void onError(VKError error) {
                    Log.d(LOG_TAG, " onError");
                  }
                });
          }

          @Override
          public void onError(VKError error) {
            // Произошла ошибка авторизации (например, пользователь запретил авторизацию)
            Log.d(LOG_TAG, " VKError onError");
          }
        })) {
      super.onActivityResult(requestCode, resultCode, data);
    }
  }
예제 #10
0
  private boolean processCommonError(VKError error) {
    if (error.errorCode == VKError.VK_API_ERROR) {
      if (error.apiError.errorCode == 14) {
        error.apiError.request = this;
        this.mLoadingOperation = null;
        VKSdk.instance().sdkListener().onCaptchaError(error.apiError);
        return true;
      } else if (error.apiError.errorCode == 16) {
        VKAccessToken token = VKSdk.getAccessToken();
        token.httpsRequired = true;
        repeat();
        return true;
      } else if (error.apiError.errorCode == 17) {
        Intent i = new Intent(VKUIHelper.getTopActivity(), VKOpenAuthActivity.class);
        i.putExtra(VKOpenAuthActivity.VK_EXTRA_VALIDATION_URL, error.apiError.redirectUri);
        i.putExtra(VKOpenAuthActivity.VK_EXTRA_VALIDATION_REQUEST, this.registerObject());
        VKUIHelper.getTopActivity().startActivityForResult(i, VKSdk.VK_SDK_REQUEST_CODE);
        return true;
      }
    }

    return false;
  }
예제 #11
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    VKUIHelper.onCreate(this);
    myApp = (MyApp) getApplicationContext();
    context = getApplicationContext();
    setContentView(R.layout.activity_main);

    // создаем адаптер

    boxAdapter = new VKNewsfeedAdapter(this, products);
    fillData();

    // настраиваем список
    ListView lvMain = (ListView) findViewById(R.id.messages_table);
    lvMain.setAdapter(boxAdapter);

    // The filter's action is BROADCAST_ACTION
    IntentFilter statusIntentFilter = new IntentFilter(Const.BROADCAST_ACTION);

    // Sets the filter's category to DEFAULT
    statusIntentFilter.addCategory(Intent.CATEGORY_DEFAULT);
    // Instantiates a new ResponseStateReceiver
    ResponseStateReceiver mDownloadStateReceiver = new ResponseStateReceiver();

    // Registers the ResponseStateReceiver and its intent filters
    LocalBroadcastManager.getInstance(this)
        .registerReceiver(mDownloadStateReceiver, statusIntentFilter);

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
    fab.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View view) {
            Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
                .setAction("Action", null)
                .show();
          }
        });

    VKSdk.initialize(sdkListener, appID, VKAccessToken.tokenFromSharedPreferences(this, sTokenKey));
  }
  @Override
  public void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == VKServiceActivity.VKServiceType.Authorization.getOuterCode()
        || requestCode == VKServiceActivity.VKServiceType.Validation.getOuterCode()
            && resultCode == Activity.RESULT_OK) {
      ((MainActivity) getActivity()).replaceFragment(new MainFragment(), false);
      return;
    }
    if (data == null) {
      super.onActivityResult(requestCode, resultCode, null);
      return;
    }
    if (!VKSdk.onActivityResult(
        requestCode,
        resultCode,
        data,
        new VKCallback<VKAccessToken>() {
          @Override
          public void onResult(VKAccessToken res) {
            //				Toast.makeText(getActivity(), "Login success", Toast.LENGTH_SHORT).show();
            //				btnLogin.setVisibility(View.GONE); // TODO: 11/5/15 need to catch login result and
            // hide login button
          }

          @Override
          public void onError(VKError error) {
            Toast.makeText(
                    getActivity(),
                    String.format("Login error: %s", error.errorMessage),
                    Toast.LENGTH_LONG)
                .show();
          }
        })) {
      super.onActivityResult(requestCode, resultCode, data);
    }
  }
 public void getVkToken(Fragment fragment) {
   VKSdk.login(fragment);
 }
예제 #14
0
 @Override
 public void onTokenExpired(VKAccessToken expiredToken) {
   VKSdk.authorize(sMyScope);
 }
예제 #15
0
 @Override
 protected void onActivityResult(int requestCode, int resultCode, Intent data) {
   VKSdk.processActivityResult(VKSdk.VK_SDK_REQUEST_CODE, resultCode, data);
 }
  private void shareVK() {
    String[] sMyScope =
        new String[] {VKScope.MESSAGES, VKScope.WALL, VKScope.NOHTTPS, VKScope.PHOTOS};

    VKSdk.login(this, sMyScope);
  }