Advertisement
Guest User

Untitled

a guest
Mar 24th, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.87 KB | None | 0 0
  1. public class LoginActivity extends AppCompatActivity {
  2.  
  3. private static final String TAG = "Login";
  4. FragmentManager fragmentManager;
  5. FragmentTransaction fragmentTransaction;
  6. private FragmentLogin fragmentLogin;
  7. private FragmentAcount fragmentAcount;
  8.  
  9. @Override
  10. protected void onCreate(Bundle savedInstanceState) {
  11. super.onCreate(savedInstanceState);
  12. setContentView(R.layout.activity_main);
  13.  
  14. fragmentLogin = new FragmentLogin();
  15. fragmentAcount = new FragmentAcount();
  16.  
  17. fragmentManager = getSupportFragmentManager();
  18. fragmentTransaction = fragmentManager.beginTransaction();
  19.  
  20. fragmentTransaction.add(R.id.activity, fragmentLogin).commit();
  21. }
  22.  
  23. @Override
  24. protected void onActivityResult(int requestCode, int resultCode, Intent data) {
  25. VKCallback<VKAccessToken> callback = new VKCallback<VKAccessToken>() {
  26. @Override
  27. public void onResult(VKAccessToken res) {
  28. // User passed Authorization
  29. Log.i(TAG, "good");
  30. startTestActivity();
  31. }
  32.  
  33. @Override
  34. public void onError(VKError error) {
  35. Log.i(TAG, "error " + error.errorMessage);
  36. }
  37. };
  38.  
  39. if (!VKSdk.onActivityResult(requestCode, resultCode, data, callback)) {
  40. super.onActivityResult(requestCode, resultCode, data);
  41. }
  42. }
  43.  
  44. private void startTestActivity() {
  45. //startActivity(new Intent(this, WellcomeActivity.class));
  46. replaceFragment(fragmentAcount);
  47. }
  48.  
  49. private void replaceFragment(Fragment fragment) {
  50. fragmentTransaction = fragmentManager.beginTransaction();
  51. fragmentTransaction.replace(R.id.activity, fragment);
  52. fragmentTransaction.commit();
  53. }
  54. }
  55.  
  56. public class FragmentLogin extends Fragment {
  57.  
  58. private Button enter;
  59.  
  60. private static final String[] sMyScope = new String[]{
  61. VKScope.FRIENDS,
  62. VKScope.WALL,
  63. VKScope.PHOTOS,
  64. VKScope.NOHTTPS,
  65. VKScope.MESSAGES,
  66. VKScope.DOCS
  67. };
  68.  
  69. public void onCreate(Bundle savedInstanceState) {
  70. super.onCreate(savedInstanceState);
  71. }
  72.  
  73.  
  74. @Override
  75. public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
  76. View v = inflater.inflate(R.layout.fragment_login, container, false);
  77. findId(v);
  78. enter.setOnClickListener(new View.OnClickListener() {
  79. @Override
  80. public void onClick(View v) {
  81. enterVk();
  82. }
  83. });
  84.  
  85. return v;
  86. }
  87.  
  88. private void findId(View v) {
  89. enter = (Button)v.findViewById(R.id.enter);
  90. }
  91.  
  92. private void enterVk() {
  93. try {
  94. VKSdk.login(getActivity(), sMyScope);
  95. } catch(Exception e) {
  96. System.out.println(e.getMessage());
  97. }
  98. }
  99. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement