Advertisement
Guest User

deezerInterface

a guest
Sep 11th, 2013
1,501
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.13 KB | None | 0 0
  1. public class DeezerInterface extends Activity{
  2.  
  3. public static final String LOG_TAG = "ConnectActivity";
  4.  
  5.  
  6. private final static String APP_ID = "XXX";
  7. private final static String[] PERMISSIONS = new String[] {"basic_access","offline_access","email"};
  8. private DeezerConnect mConnect;
  9. private String userID = "";
  10. private String accessToken = "";
  11.  
  12. public RequestListener mRequestListener = new RequestListener() {
  13.  
  14. @Override
  15. public void onComplete(String response, Object requestId) {
  16. Log.d(LOG_TAG, "Request result : " + response);
  17. JSONObject json;
  18. try {
  19. json = new JSONObject(response);
  20. }
  21. catch (JSONException e) {
  22. e.printStackTrace();
  23. return;
  24. }
  25.  
  26. final String userName = json.optString("name");
  27. final String userId = json.optString("id");
  28. userID = userId;
  29. runOnUiThread(new Runnable() {
  30.  
  31. @Override
  32. public void run() {
  33. //((TextView) findViewById(android.R.id.message)).setText("Hello " + userName);
  34.  
  35.  
  36. }
  37. });
  38.  
  39. accessToken = mConnect.getAccessToken();
  40. Log.d(LOG_TAG, "terminating");
  41. removeDialog(RESULT_OK);
  42.  
  43. }
  44.  
  45. @Override
  46. public void onOAuthException(OAuthException e, Object requestId) {
  47. Log.d(LOG_TAG, "RequestListener#onOAuthException");
  48. }
  49.  
  50. @Override
  51. public void onMalformedURLException(MalformedURLException e, Object requestId) {
  52. Log.d(LOG_TAG, "RequestListener#onMalformedURLException");
  53. }
  54.  
  55. @Override
  56. public void onIOException(IOException e, Object requestId) {
  57. Log.d(LOG_TAG, "RequestListener#onIOException");
  58. }
  59.  
  60. @Override
  61. public void onDeezerError(DeezerError e, Object requestId) {
  62. Log.d(LOG_TAG, "RequestListener#onDeezerError");
  63. }
  64.  
  65. };
  66. private DialogListener mDialogListener = new DialogListener() {
  67.  
  68. @Override
  69. public void onComplete(Bundle values) {
  70. SessionStore store = new SessionStore();
  71. store.save(mConnect, getApplicationContext());
  72. //store.clear(getApplicationContext());
  73. /*DeezerRequest request = new DeezerRequest("user/me");
  74. AsyncDeezerTask task = new AsyncDeezerTask(mConnect, mRequestListener);
  75. task.execute(request);*/
  76. }
  77.  
  78. @Override
  79. public void onCancel() {
  80. Log.d(LOG_TAG, "DialogListener#onCancel");
  81. }
  82.  
  83. @Override
  84. public void onOAuthException(OAuthException e) {
  85. Log.d(LOG_TAG, "DialogListener#onOAuthException", e);
  86. }
  87.  
  88. @Override
  89. public void onError(DialogError e) {
  90. Log.d(LOG_TAG, "DialogListener#onError", e);
  91. }
  92.  
  93. @Override
  94. public void onDeezerError(DeezerError e) {
  95. Log.d(LOG_TAG, "DialogListener#onDeezerError", e);
  96. }
  97.  
  98.  
  99. };
  100.  
  101.  
  102. @Override
  103. protected void onCreate(Bundle savedInstanceState) {
  104. Log.d(LOG_TAG, "created the dialog");
  105. super.onCreate(savedInstanceState);
  106. setContentView(R.layout.browser_link_context_header);
  107. }
  108.  
  109. @Override
  110. protected void onResume() {
  111. super.onResume();
  112. Log.d(LOG_TAG, "authorizing");
  113. mConnect = new DeezerConnectImpl(this, APP_ID);
  114. mConnect.authorize(this, PERMISSIONS, mDialogListener);
  115.  
  116. }
  117. @Override
  118. protected void onPause() {
  119. super.onPause();
  120. Log.d(LOG_TAG, "#onPause");
  121. }
  122.  
  123. @Override
  124. protected void onStop() {
  125. super.onStop();
  126. Log.d(LOG_TAG, "#onStop");
  127. }
  128. public String getAccessToken(){
  129. return accessToken;
  130. }
  131. public String getUserId(){
  132. return userID;
  133. }
  134.  
  135. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement