List of usage examples for android.content DialogInterface cancel
void cancel();
From source file:com.piusvelte.sonet.core.SonetComments.java
private void loadComments() { mComments.clear();// w w w .j a v a2s. c om setListAdapter(new SimpleAdapter(SonetComments.this, mComments, R.layout.comment, new String[] { Entities.FRIEND, Statuses.MESSAGE, Statuses.CREATEDTEXT, getString(R.string.like) }, new int[] { R.id.friend, R.id.message, R.id.created, R.id.like })); mMessage.setEnabled(false); mMessage.setText(R.string.loading); final ProgressDialog loadingDialog = new ProgressDialog(this); final AsyncTask<Void, String, String> asyncTask = new AsyncTask<Void, String, String>() { @Override protected String doInBackground(Void... none) { // load the status itself if (mData != null) { SonetCrypto sonetCrypto = SonetCrypto.getInstance(getApplicationContext()); UriMatcher um = new UriMatcher(UriMatcher.NO_MATCH); String authority = Sonet.getAuthority(SonetComments.this); um.addURI(authority, SonetProvider.VIEW_STATUSES_STYLES + "/*", SonetProvider.STATUSES_STYLES); um.addURI(authority, SonetProvider.TABLE_NOTIFICATIONS + "/*", SonetProvider.NOTIFICATIONS); Cursor status; switch (um.match(mData)) { case SonetProvider.STATUSES_STYLES: status = getContentResolver().query(Statuses_styles.getContentUri(SonetComments.this), new String[] { Statuses_styles.ACCOUNT, Statuses_styles.SID, Statuses_styles.ESID, Statuses_styles.WIDGET, Statuses_styles.SERVICE, Statuses_styles.FRIEND, Statuses_styles.MESSAGE, Statuses_styles.CREATED }, Statuses_styles._ID + "=?", new String[] { mData.getLastPathSegment() }, null); if (status.moveToFirst()) { mService = status.getInt(4); mServiceName = getResources().getStringArray(R.array.service_entries)[mService]; mAccount = status.getLong(0); mSid = sonetCrypto.Decrypt(status.getString(1)); mEsid = sonetCrypto.Decrypt(status.getString(2)); Cursor widget = getContentResolver().query( Widgets_settings.getContentUri(SonetComments.this), new String[] { Widgets.TIME24HR }, Widgets.WIDGET + "=? and " + Widgets.ACCOUNT + "=?", new String[] { Integer.toString(status.getInt(3)), Long.toString(mAccount) }, null); if (widget.moveToFirst()) { mTime24hr = widget.getInt(0) == 1; } else { Cursor b = getContentResolver().query( Widgets_settings.getContentUri(SonetComments.this), new String[] { Widgets.TIME24HR }, Widgets.WIDGET + "=? and " + Widgets.ACCOUNT + "=?", new String[] { Integer.toString(status.getInt(3)), Long.toString(Sonet.INVALID_ACCOUNT_ID) }, null); if (b.moveToFirst()) { mTime24hr = b.getInt(0) == 1; } else { Cursor c = getContentResolver() .query(Widgets_settings.getContentUri(SonetComments.this), new String[] { Widgets.TIME24HR }, Widgets.WIDGET + "=? and " + Widgets.ACCOUNT + "=?", new String[] { Integer.toString(AppWidgetManager.INVALID_APPWIDGET_ID), Long.toString(Sonet.INVALID_ACCOUNT_ID) }, null); if (c.moveToFirst()) { mTime24hr = c.getInt(0) == 1; } else { mTime24hr = false; } c.close(); } b.close(); } widget.close(); HashMap<String, String> commentMap = new HashMap<String, String>(); commentMap.put(Statuses.SID, mSid); commentMap.put(Entities.FRIEND, status.getString(5)); commentMap.put(Statuses.MESSAGE, status.getString(6)); commentMap.put(Statuses.CREATEDTEXT, Sonet.getCreatedText(status.getLong(7), mTime24hr)); commentMap.put(getString(R.string.like), mService == TWITTER ? getString(R.string.retweet) : mService == IDENTICA ? getString(R.string.repeat) : ""); mComments.add(commentMap); // load the session Cursor account = getContentResolver().query(Accounts.getContentUri(SonetComments.this), new String[] { Accounts.TOKEN, Accounts.SECRET, Accounts.SID }, Accounts._ID + "=?", new String[] { Long.toString(mAccount) }, null); if (account.moveToFirst()) { mToken = sonetCrypto.Decrypt(account.getString(0)); mSecret = sonetCrypto.Decrypt(account.getString(1)); mAccountSid = sonetCrypto.Decrypt(account.getString(2)); } account.close(); } status.close(); break; case SonetProvider.NOTIFICATIONS: Cursor notification = getContentResolver().query( Notifications.getContentUri(SonetComments.this), new String[] { Notifications.ACCOUNT, Notifications.SID, Notifications.ESID, Notifications.FRIEND, Notifications.MESSAGE, Notifications.CREATED }, Notifications._ID + "=?", new String[] { mData.getLastPathSegment() }, null); if (notification.moveToFirst()) { // clear notification ContentValues values = new ContentValues(); values.put(Notifications.CLEARED, 1); getContentResolver().update(Notifications.getContentUri(SonetComments.this), values, Notifications._ID + "=?", new String[] { mData.getLastPathSegment() }); mAccount = notification.getLong(0); mSid = sonetCrypto.Decrypt(notification.getString(1)); mEsid = sonetCrypto.Decrypt(notification.getString(2)); mTime24hr = false; // load the session Cursor account = getContentResolver().query(Accounts.getContentUri(SonetComments.this), new String[] { Accounts.TOKEN, Accounts.SECRET, Accounts.SID, Accounts.SERVICE }, Accounts._ID + "=?", new String[] { Long.toString(mAccount) }, null); if (account.moveToFirst()) { mToken = sonetCrypto.Decrypt(account.getString(0)); mSecret = sonetCrypto.Decrypt(account.getString(1)); mAccountSid = sonetCrypto.Decrypt(account.getString(2)); mService = account.getInt(3); } account.close(); HashMap<String, String> commentMap = new HashMap<String, String>(); commentMap.put(Statuses.SID, mSid); commentMap.put(Entities.FRIEND, notification.getString(3)); commentMap.put(Statuses.MESSAGE, notification.getString(4)); commentMap.put(Statuses.CREATEDTEXT, Sonet.getCreatedText(notification.getLong(5), mTime24hr)); commentMap.put(getString(R.string.like), mService == TWITTER ? getString(R.string.retweet) : getString(R.string.repeat)); mComments.add(commentMap); mServiceName = getResources().getStringArray(R.array.service_entries)[mService]; } notification.close(); break; default: mComments.clear(); HashMap<String, String> commentMap = new HashMap<String, String>(); commentMap.put(Statuses.SID, ""); commentMap.put(Entities.FRIEND, ""); commentMap.put(Statuses.MESSAGE, "error, status not found"); commentMap.put(Statuses.CREATEDTEXT, ""); commentMap.put(getString(R.string.like), ""); mComments.add(commentMap); } String response = null; HttpGet httpGet; SonetOAuth sonetOAuth; boolean liked = false; String screen_name = ""; switch (mService) { case TWITTER: sonetOAuth = new SonetOAuth(TWITTER_KEY, TWITTER_SECRET, mToken, mSecret); if ((response = SonetHttpClient.httpResponse(mHttpClient, sonetOAuth.getSignedRequest( new HttpGet(String.format(TWITTER_USER, TWITTER_BASE_URL, mEsid))))) != null) { try { JSONObject user = new JSONObject(response); screen_name = "@" + user.getString(Sscreen_name) + " "; } catch (JSONException e) { Log.e(TAG, e.toString()); } } publishProgress(screen_name); response = SonetHttpClient.httpResponse(mHttpClient, sonetOAuth.getSignedRequest(new HttpGet(String.format(TWITTER_MENTIONS, TWITTER_BASE_URL, String.format(TWITTER_SINCE_ID, mSid))))); break; case FACEBOOK: if ((response = SonetHttpClient.httpResponse(mHttpClient, new HttpGet(String.format(FACEBOOK_LIKES, FACEBOOK_BASE_URL, mSid, Saccess_token, mToken)))) != null) { try { JSONArray likes = new JSONObject(response).getJSONArray(Sdata); for (int i = 0, i2 = likes.length(); i < i2; i++) { JSONObject like = likes.getJSONObject(i); if (like.getString(Sid).equals(mAccountSid)) { liked = true; break; } } } catch (JSONException e) { Log.e(TAG, e.toString()); } } publishProgress(getString(liked ? R.string.unlike : R.string.like)); response = SonetHttpClient.httpResponse(mHttpClient, new HttpGet( String.format(FACEBOOK_COMMENTS, FACEBOOK_BASE_URL, mSid, Saccess_token, mToken))); break; case MYSPACE: sonetOAuth = new SonetOAuth(MYSPACE_KEY, MYSPACE_SECRET, mToken, mSecret); response = SonetHttpClient.httpResponse(mHttpClient, sonetOAuth.getSignedRequest(new HttpGet(String .format(MYSPACE_URL_STATUSMOODCOMMENTS, MYSPACE_BASE_URL, mEsid, mSid)))); break; case LINKEDIN: sonetOAuth = new SonetOAuth(LINKEDIN_KEY, LINKEDIN_SECRET, mToken, mSecret); httpGet = new HttpGet(String.format(LINKEDIN_UPDATE, LINKEDIN_BASE_URL, mSid)); for (String[] header : LINKEDIN_HEADERS) httpGet.setHeader(header[0], header[1]); if ((response = SonetHttpClient.httpResponse(mHttpClient, sonetOAuth.getSignedRequest(httpGet))) != null) { try { JSONObject data = new JSONObject(response); if (data.has("isCommentable") && !data.getBoolean("isCommentable")) { publishProgress(getString(R.string.uncommentable)); } if (data.has("isLikable")) { publishProgress(getString( data.has("isLiked") && data.getBoolean("isLiked") ? R.string.unlike : R.string.like)); } else { publishProgress(getString(R.string.unlikable)); } } catch (JSONException e) { Log.e(TAG, e.toString()); } } else { publishProgress(getString(R.string.unlikable)); } httpGet = new HttpGet(String.format(LINKEDIN_UPDATE_COMMENTS, LINKEDIN_BASE_URL, mSid)); for (String[] header : LINKEDIN_HEADERS) httpGet.setHeader(header[0], header[1]); response = SonetHttpClient.httpResponse(mHttpClient, sonetOAuth.getSignedRequest(httpGet)); break; case FOURSQUARE: response = SonetHttpClient.httpResponse(mHttpClient, new HttpGet( String.format(FOURSQUARE_GET_CHECKIN, FOURSQUARE_BASE_URL, mSid, mToken))); break; case IDENTICA: sonetOAuth = new SonetOAuth(IDENTICA_KEY, IDENTICA_SECRET, mToken, mSecret); if ((response = SonetHttpClient.httpResponse(mHttpClient, sonetOAuth.getSignedRequest( new HttpGet(String.format(IDENTICA_USER, IDENTICA_BASE_URL, mEsid))))) != null) { try { JSONObject user = new JSONObject(response); screen_name = "@" + user.getString(Sscreen_name) + " "; } catch (JSONException e) { Log.e(TAG, e.toString()); } } publishProgress(screen_name); response = SonetHttpClient.httpResponse(mHttpClient, sonetOAuth.getSignedRequest(new HttpGet(String.format(IDENTICA_MENTIONS, IDENTICA_BASE_URL, String.format(IDENTICA_SINCE_ID, mSid))))); break; case GOOGLEPLUS: //TODO: // get plussed status break; case CHATTER: // Chatter requires loading an instance if ((mChatterInstance == null) || (mChatterToken == null)) { if ((response = SonetHttpClient.httpResponse(mHttpClient, new HttpPost( String.format(CHATTER_URL_ACCESS, CHATTER_KEY, mToken)))) != null) { try { JSONObject jobj = new JSONObject(response); if (jobj.has("instance_url") && jobj.has(Saccess_token)) { mChatterInstance = jobj.getString("instance_url"); mChatterToken = jobj.getString(Saccess_token); } } catch (JSONException e) { Log.e(TAG, e.toString()); } } } if ((mChatterInstance != null) && (mChatterToken != null)) { httpGet = new HttpGet(String.format(CHATTER_URL_LIKES, mChatterInstance, mSid)); httpGet.setHeader("Authorization", "OAuth " + mChatterToken); if ((response = SonetHttpClient.httpResponse(mHttpClient, httpGet)) != null) { try { JSONObject jobj = new JSONObject(response); if (jobj.getInt(Stotal) > 0) { JSONArray likes = jobj.getJSONArray("likes"); for (int i = 0, i2 = likes.length(); i < i2; i++) { JSONObject like = likes.getJSONObject(i); if (like.getJSONObject(Suser).getString(Sid).equals(mAccountSid)) { mChatterLikeId = like.getString(Sid); liked = true; break; } } } } catch (JSONException e) { Log.e(TAG, e.toString()); } } publishProgress(getString(liked ? R.string.unlike : R.string.like)); httpGet = new HttpGet(String.format(CHATTER_URL_COMMENTS, mChatterInstance, mSid)); httpGet.setHeader("Authorization", "OAuth " + mChatterToken); response = SonetHttpClient.httpResponse(mHttpClient, httpGet); } else { response = null; } break; } return response; } return null; } @Override protected void onProgressUpdate(String... params) { mMessage.setText(""); if (params != null) { if ((mService == TWITTER) || (mService == IDENTICA)) { mMessage.append(params[0]); } else { if (mService == LINKEDIN) { if (params[0].equals(getString(R.string.uncommentable))) { mSend.setEnabled(false); mMessage.setEnabled(false); mMessage.setText(R.string.uncommentable); } else { setCommentStatus(0, params[0]); } } else { setCommentStatus(0, params[0]); } } } mMessage.setEnabled(true); } @Override protected void onPostExecute(String response) { if (response != null) { int i2; try { JSONArray comments; mSimpleDateFormat = null; switch (mService) { case TWITTER: comments = new JSONArray(response); if ((i2 = comments.length()) > 0) { for (int i = 0; i < i2; i++) { JSONObject comment = comments.getJSONObject(i); if (comment.getString(Sin_reply_to_status_id) == mSid) { HashMap<String, String> commentMap = new HashMap<String, String>(); commentMap.put(Statuses.SID, comment.getString(Sid)); commentMap.put(Entities.FRIEND, comment.getJSONObject(Suser).getString(Sname)); commentMap.put(Statuses.MESSAGE, comment.getString(Stext)); commentMap.put(Statuses.CREATEDTEXT, Sonet.getCreatedText( parseDate(comment.getString(Screated_at), TWITTER_DATE_FORMAT), mTime24hr)); commentMap.put(getString(R.string.like), getString(R.string.retweet)); mComments.add(commentMap); } } } else { noComments(); } break; case FACEBOOK: comments = new JSONObject(response).getJSONArray(Sdata); if ((i2 = comments.length()) > 0) { for (int i = 0; i < i2; i++) { JSONObject comment = comments.getJSONObject(i); HashMap<String, String> commentMap = new HashMap<String, String>(); commentMap.put(Statuses.SID, comment.getString(Sid)); commentMap.put(Entities.FRIEND, comment.getJSONObject(Sfrom).getString(Sname)); commentMap.put(Statuses.MESSAGE, comment.getString(Smessage)); commentMap.put(Statuses.CREATEDTEXT, Sonet.getCreatedText(comment.getLong(Screated_time) * 1000, mTime24hr)); commentMap.put(getString(R.string.like), getString(comment.has(Suser_likes) && comment.getBoolean(Suser_likes) ? R.string.unlike : R.string.like)); mComments.add(commentMap); } } else { noComments(); } break; case MYSPACE: comments = new JSONObject(response).getJSONArray(Sentry); if ((i2 = comments.length()) > 0) { for (int i = 0; i < i2; i++) { JSONObject entry = comments.getJSONObject(i); HashMap<String, String> commentMap = new HashMap<String, String>(); commentMap.put(Statuses.SID, entry.getString(ScommentId)); commentMap.put(Entities.FRIEND, entry.getJSONObject(Sauthor).getString(SdisplayName)); commentMap.put(Statuses.MESSAGE, entry.getString(Sbody)); commentMap.put(Statuses.CREATEDTEXT, Sonet.getCreatedText( parseDate(entry.getString(SpostedDate), MYSPACE_DATE_FORMAT), mTime24hr)); commentMap.put(getString(R.string.like), ""); mComments.add(commentMap); } } else { noComments(); } break; case LINKEDIN: JSONObject jsonResponse = new JSONObject(response); if (jsonResponse.has(S_total) && (jsonResponse.getInt(S_total) != 0)) { comments = jsonResponse.getJSONArray(Svalues); if ((i2 = comments.length()) > 0) { for (int i = 0; i < i2; i++) { JSONObject comment = comments.getJSONObject(i); JSONObject person = comment.getJSONObject(Sperson); HashMap<String, String> commentMap = new HashMap<String, String>(); commentMap.put(Statuses.SID, comment.getString(Sid)); commentMap.put(Entities.FRIEND, person.getString(SfirstName) + " " + person.getString(SlastName)); commentMap.put(Statuses.MESSAGE, comment.getString(Scomment)); commentMap.put(Statuses.CREATEDTEXT, Sonet.getCreatedText(comment.getLong(Stimestamp), mTime24hr)); commentMap.put(getString(R.string.like), ""); mComments.add(commentMap); } } else { noComments(); } } break; case FOURSQUARE: comments = new JSONObject(response).getJSONObject(Sresponse).getJSONObject(Scheckin) .getJSONObject(Scomments).getJSONArray(Sitems); if ((i2 = comments.length()) > 0) { for (int i = 0; i < i2; i++) { JSONObject comment = comments.getJSONObject(i); JSONObject user = comment.getJSONObject(Suser); HashMap<String, String> commentMap = new HashMap<String, String>(); commentMap.put(Statuses.SID, comment.getString(Sid)); commentMap.put(Entities.FRIEND, user.getString(SfirstName) + " " + user.getString(SlastName)); commentMap.put(Statuses.MESSAGE, comment.getString(Stext)); commentMap.put(Statuses.CREATEDTEXT, Sonet.getCreatedText(comment.getLong(ScreatedAt) * 1000, mTime24hr)); commentMap.put(getString(R.string.like), ""); mComments.add(commentMap); } } else { noComments(); } break; case IDENTICA: comments = new JSONArray(response); if ((i2 = comments.length()) > 0) { for (int i = 0; i < i2; i++) { JSONObject comment = comments.getJSONObject(i); if (comment.getString(Sin_reply_to_status_id) == mSid) { HashMap<String, String> commentMap = new HashMap<String, String>(); commentMap.put(Statuses.SID, comment.getString(Sid)); commentMap.put(Entities.FRIEND, comment.getJSONObject(Suser).getString(Sname)); commentMap.put(Statuses.MESSAGE, comment.getString(Stext)); commentMap.put(Statuses.CREATEDTEXT, Sonet.getCreatedText( parseDate(comment.getString(Screated_at), TWITTER_DATE_FORMAT), mTime24hr)); commentMap.put(getString(R.string.like), getString(R.string.repeat)); mComments.add(commentMap); } } } else { noComments(); } break; case GOOGLEPLUS: //TODO: load comments HttpPost httpPost = new HttpPost(GOOGLE_ACCESS); List<NameValuePair> httpParams = new ArrayList<NameValuePair>(); httpParams.add(new BasicNameValuePair("client_id", GOOGLE_CLIENTID)); httpParams.add(new BasicNameValuePair("client_secret", GOOGLE_CLIENTSECRET)); httpParams.add(new BasicNameValuePair("refresh_token", mToken)); httpParams.add(new BasicNameValuePair("grant_type", "refresh_token")); try { httpPost.setEntity(new UrlEncodedFormEntity(httpParams)); if ((response = SonetHttpClient.httpResponse(mHttpClient, httpPost)) != null) { JSONObject j = new JSONObject(response); if (j.has(Saccess_token)) { String access_token = j.getString(Saccess_token); if ((response = SonetHttpClient.httpResponse(mHttpClient, new HttpGet(String.format(GOOGLEPLUS_ACTIVITY, GOOGLEPLUS_BASE_URL, mSid, access_token)))) != null) { // check for a newer post, if it's the user's own, then set CLEARED=0 try { JSONObject item = new JSONObject(response); if (item.has(Sobject)) { JSONObject object = item.getJSONObject(Sobject); if (object.has(Sreplies)) { int commentCount = 0; JSONObject replies = object.getJSONObject(Sreplies); if (replies.has(StotalItems)) { //TODO: load comments commentCount = replies.getInt(StotalItems); } } } } catch (JSONException e) { Log.e(TAG, e.toString()); } } } } } catch (UnsupportedEncodingException e) { Log.e(TAG, e.toString()); } catch (JSONException e) { Log.e(TAG, e.toString()); } break; case CHATTER: JSONObject chats = new JSONObject(response); if (chats.getInt(Stotal) > 0) { comments = chats.getJSONArray(Scomments); if ((i2 = comments.length()) > 0) { for (int i = 0; i < i2; i++) { JSONObject comment = comments.getJSONObject(i); HashMap<String, String> commentMap = new HashMap<String, String>(); commentMap.put(Statuses.SID, comment.getString(Sid)); commentMap.put(Entities.FRIEND, comment.getJSONObject(Suser).getString(Sname)); commentMap.put(Statuses.MESSAGE, comment.getJSONObject(Sbody).getString(Stext)); commentMap.put(Statuses.CREATEDTEXT, Sonet.getCreatedText( parseDate(comment.getString(ScreatedDate), CHATTER_DATE_FORMAT), mTime24hr)); commentMap.put(getString(R.string.like), ""); mComments.add(commentMap); } } else { noComments(); } } else { noComments(); } break; } } catch (JSONException e) { Log.e(TAG, e.toString()); } } else { noComments(); } setListAdapter(new SimpleAdapter(SonetComments.this, mComments, R.layout.comment, new String[] { Entities.FRIEND, Statuses.MESSAGE, Statuses.CREATEDTEXT, getString(R.string.like) }, new int[] { R.id.friend, R.id.message, R.id.created, R.id.like })); if (loadingDialog.isShowing()) loadingDialog.dismiss(); } private void noComments() { HashMap<String, String> commentMap = new HashMap<String, String>(); commentMap.put(Statuses.SID, ""); commentMap.put(Entities.FRIEND, ""); commentMap.put(Statuses.MESSAGE, getString(R.string.no_comments)); commentMap.put(Statuses.CREATEDTEXT, ""); commentMap.put(getString(R.string.like), ""); mComments.add(commentMap); } private long parseDate(String date, String format) { if (date != null) { // hack for the literal 'Z' if (date.substring(date.length() - 1).equals("Z")) { date = date.substring(0, date.length() - 2) + "+0000"; } Date created = null; if (format != null) { if (mSimpleDateFormat == null) { mSimpleDateFormat = new SimpleDateFormat(format, Locale.ENGLISH); // all dates should be GMT/UTC mSimpleDateFormat.setTimeZone(sTimeZone); } try { created = mSimpleDateFormat.parse(date); return created.getTime(); } catch (ParseException e) { Log.e(TAG, e.toString()); } } else { // attempt to parse RSS date if (mSimpleDateFormat != null) { try { created = mSimpleDateFormat.parse(date); return created.getTime(); } catch (ParseException e) { Log.e(TAG, e.toString()); } } for (String rfc822 : sRFC822) { mSimpleDateFormat = new SimpleDateFormat(rfc822, Locale.ENGLISH); mSimpleDateFormat.setTimeZone(sTimeZone); try { if ((created = mSimpleDateFormat.parse(date)) != null) { return created.getTime(); } } catch (ParseException e) { Log.e(TAG, e.toString()); } } } } return System.currentTimeMillis(); } }; loadingDialog.setMessage(getString(R.string.loading)); loadingDialog.setCancelable(true); loadingDialog.setOnCancelListener(new DialogInterface.OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { if (!asyncTask.isCancelled()) asyncTask.cancel(true); } }); loadingDialog.setButton(ProgressDialog.BUTTON_NEGATIVE, getString(android.R.string.cancel), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.cancel(); } }); loadingDialog.show(); asyncTask.execute(); }
From source file:com.lifehackinnovations.siteaudit.FloorPlanActivity.java
public void getscaledialog() { ImageView googlemaps = new ImageView(this); googlemaps.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); googlemaps.setPadding(25, 25, 25, 25); googlemaps.setImageResource(R.drawable.google_maps256x256); googlemaps.setOnClickListener(new ImageView.OnClickListener() { public void onClick(View v) { startActivity(u.intent("Getscalefromgooglemaps")); getscaledialog.cancel();/*from w ww.j av a2 s .c o m*/ } }); ImageView twopoints = new ImageView(this); twopoints.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); twopoints.setPadding(25, 25, 25, 25); twopoints.setImageResource(R.drawable.pointsonmapicon); twopoints.setOnClickListener(new ImageView.OnClickListener() { public void onClick(View v) { ACTION = ACTION_GETSCALEFROMPOINTS; toptoolbar.setVisibility(View.INVISIBLE); righttoolbar.setVisibility(View.INVISIBLE); floorplantitle.setVisibility(View.VISIBLE); floorplantitle.setText("Please select first point"); GETSCALESTAGE = STAGE_GETFIRSTPOINT; getscaledialog.cancel(); } }); LinearLayout choosepicturelocationlayout; choosepicturelocationlayout = new LinearLayout(this); choosepicturelocationlayout .setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); choosepicturelocationlayout.setOrientation(LinearLayout.HORIZONTAL); choosepicturelocationlayout.addView(googlemaps); choosepicturelocationlayout.addView(twopoints); choosepicturelocationlayout.setGravity(Gravity.CENTER_HORIZONTAL); AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle("Choose Method for Getting Scale") .setMessage("Please choose Google Maps, or Two Points on Map").setView(choosepicturelocationlayout) .setCancelable(false).setIcon(R.drawable.ic_launcher) .setNegativeButton("CANCEL", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.cancel(); } }).setCancelable(true); getscaledialog = builder.create(); getscaledialog.show(); }
From source file:com.piusvelte.sonet.SonetComments.java
private void loadComments() { mComments.clear();/*from w ww. j a va 2 s . c o m*/ setListAdapter(new SimpleAdapter(SonetComments.this, mComments, R.layout.comment, new String[] { Entities.FRIEND, Statuses.MESSAGE, Statuses.CREATEDTEXT, getString(R.string.like) }, new int[] { R.id.friend, R.id.message, R.id.created, R.id.like })); mMessage.setEnabled(false); mMessage.setText(R.string.loading); final ProgressDialog loadingDialog = new ProgressDialog(this); final AsyncTask<Void, String, String> asyncTask = new AsyncTask<Void, String, String>() { @Override protected String doInBackground(Void... none) { // load the status itself if (mData != null) { SonetCrypto sonetCrypto = SonetCrypto.getInstance(getApplicationContext()); UriMatcher um = new UriMatcher(UriMatcher.NO_MATCH); String authority = Sonet.getAuthority(SonetComments.this); um.addURI(authority, SonetProvider.VIEW_STATUSES_STYLES + "/*", SonetProvider.STATUSES_STYLES); um.addURI(authority, SonetProvider.TABLE_NOTIFICATIONS + "/*", SonetProvider.NOTIFICATIONS); Cursor status; switch (um.match(mData)) { case SonetProvider.STATUSES_STYLES: status = getContentResolver().query(Statuses_styles.getContentUri(SonetComments.this), new String[] { Statuses_styles.ACCOUNT, Statuses_styles.SID, Statuses_styles.ESID, Statuses_styles.WIDGET, Statuses_styles.SERVICE, Statuses_styles.FRIEND, Statuses_styles.MESSAGE, Statuses_styles.CREATED }, Statuses_styles._ID + "=?", new String[] { mData.getLastPathSegment() }, null); if (status.moveToFirst()) { mService = status.getInt(4); mServiceName = getResources().getStringArray(R.array.service_entries)[mService]; mAccount = status.getLong(0); mSid = sonetCrypto.Decrypt(status.getString(1)); mEsid = sonetCrypto.Decrypt(status.getString(2)); Cursor widget = getContentResolver().query( Widgets_settings.getContentUri(SonetComments.this), new String[] { Widgets.TIME24HR }, Widgets.WIDGET + "=? and " + Widgets.ACCOUNT + "=?", new String[] { Integer.toString(status.getInt(3)), Long.toString(mAccount) }, null); if (widget.moveToFirst()) { mTime24hr = widget.getInt(0) == 1; } else { Cursor b = getContentResolver().query( Widgets_settings.getContentUri(SonetComments.this), new String[] { Widgets.TIME24HR }, Widgets.WIDGET + "=? and " + Widgets.ACCOUNT + "=?", new String[] { Integer.toString(status.getInt(3)), Long.toString(Sonet.INVALID_ACCOUNT_ID) }, null); if (b.moveToFirst()) { mTime24hr = b.getInt(0) == 1; } else { Cursor c = getContentResolver() .query(Widgets_settings.getContentUri(SonetComments.this), new String[] { Widgets.TIME24HR }, Widgets.WIDGET + "=? and " + Widgets.ACCOUNT + "=?", new String[] { Integer.toString(AppWidgetManager.INVALID_APPWIDGET_ID), Long.toString(Sonet.INVALID_ACCOUNT_ID) }, null); if (c.moveToFirst()) { mTime24hr = c.getInt(0) == 1; } else { mTime24hr = false; } c.close(); } b.close(); } widget.close(); HashMap<String, String> commentMap = new HashMap<String, String>(); commentMap.put(Statuses.SID, mSid); commentMap.put(Entities.FRIEND, status.getString(5)); commentMap.put(Statuses.MESSAGE, status.getString(6)); commentMap.put(Statuses.CREATEDTEXT, Sonet.getCreatedText(status.getLong(7), mTime24hr)); commentMap.put(getString(R.string.like), mService == TWITTER ? getString(R.string.retweet) : mService == IDENTICA ? getString(R.string.repeat) : ""); mComments.add(commentMap); // load the session Cursor account = getContentResolver().query(Accounts.getContentUri(SonetComments.this), new String[] { Accounts.TOKEN, Accounts.SECRET, Accounts.SID }, Accounts._ID + "=?", new String[] { Long.toString(mAccount) }, null); if (account.moveToFirst()) { mToken = sonetCrypto.Decrypt(account.getString(0)); mSecret = sonetCrypto.Decrypt(account.getString(1)); mAccountSid = sonetCrypto.Decrypt(account.getString(2)); } account.close(); } status.close(); break; case SonetProvider.NOTIFICATIONS: Cursor notification = getContentResolver().query( Notifications.getContentUri(SonetComments.this), new String[] { Notifications.ACCOUNT, Notifications.SID, Notifications.ESID, Notifications.FRIEND, Notifications.MESSAGE, Notifications.CREATED }, Notifications._ID + "=?", new String[] { mData.getLastPathSegment() }, null); if (notification.moveToFirst()) { // clear notification ContentValues values = new ContentValues(); values.put(Notifications.CLEARED, 1); getContentResolver().update(Notifications.getContentUri(SonetComments.this), values, Notifications._ID + "=?", new String[] { mData.getLastPathSegment() }); mAccount = notification.getLong(0); mSid = sonetCrypto.Decrypt(notification.getString(1)); mEsid = sonetCrypto.Decrypt(notification.getString(2)); mTime24hr = false; // load the session Cursor account = getContentResolver().query(Accounts.getContentUri(SonetComments.this), new String[] { Accounts.TOKEN, Accounts.SECRET, Accounts.SID, Accounts.SERVICE }, Accounts._ID + "=?", new String[] { Long.toString(mAccount) }, null); if (account.moveToFirst()) { mToken = sonetCrypto.Decrypt(account.getString(0)); mSecret = sonetCrypto.Decrypt(account.getString(1)); mAccountSid = sonetCrypto.Decrypt(account.getString(2)); mService = account.getInt(3); } account.close(); HashMap<String, String> commentMap = new HashMap<String, String>(); commentMap.put(Statuses.SID, mSid); commentMap.put(Entities.FRIEND, notification.getString(3)); commentMap.put(Statuses.MESSAGE, notification.getString(4)); commentMap.put(Statuses.CREATEDTEXT, Sonet.getCreatedText(notification.getLong(5), mTime24hr)); commentMap.put(getString(R.string.like), mService == TWITTER ? getString(R.string.retweet) : getString(R.string.repeat)); mComments.add(commentMap); mServiceName = getResources().getStringArray(R.array.service_entries)[mService]; } notification.close(); break; default: mComments.clear(); HashMap<String, String> commentMap = new HashMap<String, String>(); commentMap.put(Statuses.SID, ""); commentMap.put(Entities.FRIEND, ""); commentMap.put(Statuses.MESSAGE, "error, status not found"); commentMap.put(Statuses.CREATEDTEXT, ""); commentMap.put(getString(R.string.like), ""); mComments.add(commentMap); } String response = null; HttpGet httpGet; SonetOAuth sonetOAuth; boolean liked = false; String screen_name = ""; switch (mService) { case TWITTER: sonetOAuth = new SonetOAuth(BuildConfig.TWITTER_KEY, BuildConfig.TWITTER_SECRET, mToken, mSecret); if ((response = SonetHttpClient.httpResponse(mHttpClient, sonetOAuth.getSignedRequest( new HttpGet(String.format(TWITTER_USER, TWITTER_BASE_URL, mEsid))))) != null) { try { JSONObject user = new JSONObject(response); screen_name = "@" + user.getString(Sscreen_name) + " "; } catch (JSONException e) { Log.e(TAG, e.toString()); } } publishProgress(screen_name); response = SonetHttpClient.httpResponse(mHttpClient, sonetOAuth.getSignedRequest(new HttpGet(String.format(TWITTER_MENTIONS, TWITTER_BASE_URL, String.format(TWITTER_SINCE_ID, mSid))))); break; case FACEBOOK: if ((response = SonetHttpClient.httpResponse(mHttpClient, new HttpGet(String.format(FACEBOOK_LIKES, FACEBOOK_BASE_URL, mSid, Saccess_token, mToken)))) != null) { try { JSONArray likes = new JSONObject(response).getJSONArray(Sdata); for (int i = 0, i2 = likes.length(); i < i2; i++) { JSONObject like = likes.getJSONObject(i); if (like.getString(Sid).equals(mAccountSid)) { liked = true; break; } } } catch (JSONException e) { Log.e(TAG, e.toString()); } } publishProgress(getString(liked ? R.string.unlike : R.string.like)); response = SonetHttpClient.httpResponse(mHttpClient, new HttpGet( String.format(FACEBOOK_COMMENTS, FACEBOOK_BASE_URL, mSid, Saccess_token, mToken))); break; case MYSPACE: sonetOAuth = new SonetOAuth(BuildConfig.MYSPACE_KEY, BuildConfig.MYSPACE_SECRET, mToken, mSecret); response = SonetHttpClient.httpResponse(mHttpClient, sonetOAuth.getSignedRequest(new HttpGet(String .format(MYSPACE_URL_STATUSMOODCOMMENTS, MYSPACE_BASE_URL, mEsid, mSid)))); break; case LINKEDIN: sonetOAuth = new SonetOAuth(BuildConfig.LINKEDIN_KEY, BuildConfig.LINKEDIN_SECRET, mToken, mSecret); httpGet = new HttpGet(String.format(LINKEDIN_UPDATE, LINKEDIN_BASE_URL, mSid)); for (String[] header : LINKEDIN_HEADERS) httpGet.setHeader(header[0], header[1]); if ((response = SonetHttpClient.httpResponse(mHttpClient, sonetOAuth.getSignedRequest(httpGet))) != null) { try { JSONObject data = new JSONObject(response); if (data.has("isCommentable") && !data.getBoolean("isCommentable")) { publishProgress(getString(R.string.uncommentable)); } if (data.has("isLikable")) { publishProgress(getString( data.has("isLiked") && data.getBoolean("isLiked") ? R.string.unlike : R.string.like)); } else { publishProgress(getString(R.string.unlikable)); } } catch (JSONException e) { Log.e(TAG, e.toString()); } } else { publishProgress(getString(R.string.unlikable)); } httpGet = new HttpGet(String.format(LINKEDIN_UPDATE_COMMENTS, LINKEDIN_BASE_URL, mSid)); for (String[] header : LINKEDIN_HEADERS) httpGet.setHeader(header[0], header[1]); response = SonetHttpClient.httpResponse(mHttpClient, sonetOAuth.getSignedRequest(httpGet)); break; case FOURSQUARE: response = SonetHttpClient.httpResponse(mHttpClient, new HttpGet( String.format(FOURSQUARE_GET_CHECKIN, FOURSQUARE_BASE_URL, mSid, mToken))); break; case IDENTICA: sonetOAuth = new SonetOAuth(BuildConfig.IDENTICA_KEY, BuildConfig.IDENTICA_SECRET, mToken, mSecret); if ((response = SonetHttpClient.httpResponse(mHttpClient, sonetOAuth.getSignedRequest( new HttpGet(String.format(IDENTICA_USER, IDENTICA_BASE_URL, mEsid))))) != null) { try { JSONObject user = new JSONObject(response); screen_name = "@" + user.getString(Sscreen_name) + " "; } catch (JSONException e) { Log.e(TAG, e.toString()); } } publishProgress(screen_name); response = SonetHttpClient.httpResponse(mHttpClient, sonetOAuth.getSignedRequest(new HttpGet(String.format(IDENTICA_MENTIONS, IDENTICA_BASE_URL, String.format(IDENTICA_SINCE_ID, mSid))))); break; case GOOGLEPLUS: //TODO: // get plussed status break; case CHATTER: // Chatter requires loading an instance if ((mChatterInstance == null) || (mChatterToken == null)) { if ((response = SonetHttpClient.httpResponse(mHttpClient, new HttpPost( String.format(CHATTER_URL_ACCESS, BuildConfig.CHATTER_KEY, mToken)))) != null) { try { JSONObject jobj = new JSONObject(response); if (jobj.has("instance_url") && jobj.has(Saccess_token)) { mChatterInstance = jobj.getString("instance_url"); mChatterToken = jobj.getString(Saccess_token); } } catch (JSONException e) { Log.e(TAG, e.toString()); } } } if ((mChatterInstance != null) && (mChatterToken != null)) { httpGet = new HttpGet(String.format(CHATTER_URL_LIKES, mChatterInstance, mSid)); httpGet.setHeader("Authorization", "OAuth " + mChatterToken); if ((response = SonetHttpClient.httpResponse(mHttpClient, httpGet)) != null) { try { JSONObject jobj = new JSONObject(response); if (jobj.getInt(Stotal) > 0) { JSONArray likes = jobj.getJSONArray("likes"); for (int i = 0, i2 = likes.length(); i < i2; i++) { JSONObject like = likes.getJSONObject(i); if (like.getJSONObject(Suser).getString(Sid).equals(mAccountSid)) { mChatterLikeId = like.getString(Sid); liked = true; break; } } } } catch (JSONException e) { Log.e(TAG, e.toString()); } } publishProgress(getString(liked ? R.string.unlike : R.string.like)); httpGet = new HttpGet(String.format(CHATTER_URL_COMMENTS, mChatterInstance, mSid)); httpGet.setHeader("Authorization", "OAuth " + mChatterToken); response = SonetHttpClient.httpResponse(mHttpClient, httpGet); } else { response = null; } break; } return response; } return null; } @Override protected void onProgressUpdate(String... params) { mMessage.setText(""); if (params != null) { if ((mService == TWITTER) || (mService == IDENTICA)) { mMessage.append(params[0]); } else { if (mService == LINKEDIN) { if (params[0].equals(getString(R.string.uncommentable))) { mSend.setEnabled(false); mMessage.setEnabled(false); mMessage.setText(R.string.uncommentable); } else { setCommentStatus(0, params[0]); } } else { setCommentStatus(0, params[0]); } } } mMessage.setEnabled(true); } @Override protected void onPostExecute(String response) { if (response != null) { int i2; try { JSONArray comments; mSimpleDateFormat = null; switch (mService) { case TWITTER: comments = new JSONArray(response); if ((i2 = comments.length()) > 0) { for (int i = 0; i < i2; i++) { JSONObject comment = comments.getJSONObject(i); if (comment.getString(Sin_reply_to_status_id) == mSid) { HashMap<String, String> commentMap = new HashMap<String, String>(); commentMap.put(Statuses.SID, comment.getString(Sid)); commentMap.put(Entities.FRIEND, comment.getJSONObject(Suser).getString(Sname)); commentMap.put(Statuses.MESSAGE, comment.getString(Stext)); commentMap.put(Statuses.CREATEDTEXT, Sonet.getCreatedText( parseDate(comment.getString(Screated_at), TWITTER_DATE_FORMAT), mTime24hr)); commentMap.put(getString(R.string.like), getString(R.string.retweet)); mComments.add(commentMap); } } } else { noComments(); } break; case FACEBOOK: comments = new JSONObject(response).getJSONArray(Sdata); if ((i2 = comments.length()) > 0) { for (int i = 0; i < i2; i++) { JSONObject comment = comments.getJSONObject(i); HashMap<String, String> commentMap = new HashMap<String, String>(); commentMap.put(Statuses.SID, comment.getString(Sid)); commentMap.put(Entities.FRIEND, comment.getJSONObject(Sfrom).getString(Sname)); commentMap.put(Statuses.MESSAGE, comment.getString(Smessage)); commentMap.put(Statuses.CREATEDTEXT, Sonet.getCreatedText(comment.getLong(Screated_time) * 1000, mTime24hr)); commentMap.put(getString(R.string.like), getString(comment.has(Suser_likes) && comment.getBoolean(Suser_likes) ? R.string.unlike : R.string.like)); mComments.add(commentMap); } } else { noComments(); } break; case MYSPACE: comments = new JSONObject(response).getJSONArray(Sentry); if ((i2 = comments.length()) > 0) { for (int i = 0; i < i2; i++) { JSONObject entry = comments.getJSONObject(i); HashMap<String, String> commentMap = new HashMap<String, String>(); commentMap.put(Statuses.SID, entry.getString(ScommentId)); commentMap.put(Entities.FRIEND, entry.getJSONObject(Sauthor).getString(SdisplayName)); commentMap.put(Statuses.MESSAGE, entry.getString(Sbody)); commentMap.put(Statuses.CREATEDTEXT, Sonet.getCreatedText( parseDate(entry.getString(SpostedDate), MYSPACE_DATE_FORMAT), mTime24hr)); commentMap.put(getString(R.string.like), ""); mComments.add(commentMap); } } else { noComments(); } break; case LINKEDIN: JSONObject jsonResponse = new JSONObject(response); if (jsonResponse.has(S_total) && (jsonResponse.getInt(S_total) != 0)) { comments = jsonResponse.getJSONArray(Svalues); if ((i2 = comments.length()) > 0) { for (int i = 0; i < i2; i++) { JSONObject comment = comments.getJSONObject(i); JSONObject person = comment.getJSONObject(Sperson); HashMap<String, String> commentMap = new HashMap<String, String>(); commentMap.put(Statuses.SID, comment.getString(Sid)); commentMap.put(Entities.FRIEND, person.getString(SfirstName) + " " + person.getString(SlastName)); commentMap.put(Statuses.MESSAGE, comment.getString(Scomment)); commentMap.put(Statuses.CREATEDTEXT, Sonet.getCreatedText(comment.getLong(Stimestamp), mTime24hr)); commentMap.put(getString(R.string.like), ""); mComments.add(commentMap); } } else { noComments(); } } break; case FOURSQUARE: comments = new JSONObject(response).getJSONObject(Sresponse).getJSONObject(Scheckin) .getJSONObject(Scomments).getJSONArray(Sitems); if ((i2 = comments.length()) > 0) { for (int i = 0; i < i2; i++) { JSONObject comment = comments.getJSONObject(i); JSONObject user = comment.getJSONObject(Suser); HashMap<String, String> commentMap = new HashMap<String, String>(); commentMap.put(Statuses.SID, comment.getString(Sid)); commentMap.put(Entities.FRIEND, user.getString(SfirstName) + " " + user.getString(SlastName)); commentMap.put(Statuses.MESSAGE, comment.getString(Stext)); commentMap.put(Statuses.CREATEDTEXT, Sonet.getCreatedText(comment.getLong(ScreatedAt) * 1000, mTime24hr)); commentMap.put(getString(R.string.like), ""); mComments.add(commentMap); } } else { noComments(); } break; case IDENTICA: comments = new JSONArray(response); if ((i2 = comments.length()) > 0) { for (int i = 0; i < i2; i++) { JSONObject comment = comments.getJSONObject(i); if (comment.getString(Sin_reply_to_status_id) == mSid) { HashMap<String, String> commentMap = new HashMap<String, String>(); commentMap.put(Statuses.SID, comment.getString(Sid)); commentMap.put(Entities.FRIEND, comment.getJSONObject(Suser).getString(Sname)); commentMap.put(Statuses.MESSAGE, comment.getString(Stext)); commentMap.put(Statuses.CREATEDTEXT, Sonet.getCreatedText( parseDate(comment.getString(Screated_at), TWITTER_DATE_FORMAT), mTime24hr)); commentMap.put(getString(R.string.like), getString(R.string.repeat)); mComments.add(commentMap); } } } else { noComments(); } break; case GOOGLEPLUS: //TODO: load comments HttpPost httpPost = new HttpPost(GOOGLE_ACCESS); List<NameValuePair> httpParams = new ArrayList<NameValuePair>(); httpParams.add(new BasicNameValuePair("client_id", BuildConfig.GOOGLECLIENT_ID)); httpParams .add(new BasicNameValuePair("client_secret", BuildConfig.GOOGLECLIENT_SECRET)); httpParams.add(new BasicNameValuePair("refresh_token", mToken)); httpParams.add(new BasicNameValuePair("grant_type", "refresh_token")); try { httpPost.setEntity(new UrlEncodedFormEntity(httpParams)); if ((response = SonetHttpClient.httpResponse(mHttpClient, httpPost)) != null) { JSONObject j = new JSONObject(response); if (j.has(Saccess_token)) { String access_token = j.getString(Saccess_token); if ((response = SonetHttpClient.httpResponse(mHttpClient, new HttpGet(String.format(GOOGLEPLUS_ACTIVITY, GOOGLEPLUS_BASE_URL, mSid, access_token)))) != null) { // check for a newer post, if it's the user's own, then set CLEARED=0 try { JSONObject item = new JSONObject(response); if (item.has(Sobject)) { JSONObject object = item.getJSONObject(Sobject); if (object.has(Sreplies)) { int commentCount = 0; JSONObject replies = object.getJSONObject(Sreplies); if (replies.has(StotalItems)) { //TODO: load comments commentCount = replies.getInt(StotalItems); } } } } catch (JSONException e) { Log.e(TAG, e.toString()); } } } } } catch (UnsupportedEncodingException e) { Log.e(TAG, e.toString()); } catch (JSONException e) { Log.e(TAG, e.toString()); } break; case CHATTER: JSONObject chats = new JSONObject(response); if (chats.getInt(Stotal) > 0) { comments = chats.getJSONArray(Scomments); if ((i2 = comments.length()) > 0) { for (int i = 0; i < i2; i++) { JSONObject comment = comments.getJSONObject(i); HashMap<String, String> commentMap = new HashMap<String, String>(); commentMap.put(Statuses.SID, comment.getString(Sid)); commentMap.put(Entities.FRIEND, comment.getJSONObject(Suser).getString(Sname)); commentMap.put(Statuses.MESSAGE, comment.getJSONObject(Sbody).getString(Stext)); commentMap.put(Statuses.CREATEDTEXT, Sonet.getCreatedText( parseDate(comment.getString(ScreatedDate), CHATTER_DATE_FORMAT), mTime24hr)); commentMap.put(getString(R.string.like), ""); mComments.add(commentMap); } } else { noComments(); } } else { noComments(); } break; } } catch (JSONException e) { Log.e(TAG, e.toString()); } } else { noComments(); } setListAdapter(new SimpleAdapter(SonetComments.this, mComments, R.layout.comment, new String[] { Entities.FRIEND, Statuses.MESSAGE, Statuses.CREATEDTEXT, getString(R.string.like) }, new int[] { R.id.friend, R.id.message, R.id.created, R.id.like })); if (loadingDialog.isShowing()) loadingDialog.dismiss(); } private void noComments() { HashMap<String, String> commentMap = new HashMap<String, String>(); commentMap.put(Statuses.SID, ""); commentMap.put(Entities.FRIEND, ""); commentMap.put(Statuses.MESSAGE, getString(R.string.no_comments)); commentMap.put(Statuses.CREATEDTEXT, ""); commentMap.put(getString(R.string.like), ""); mComments.add(commentMap); } private long parseDate(String date, String format) { if (date != null) { // hack for the literal 'Z' if (date.substring(date.length() - 1).equals("Z")) { date = date.substring(0, date.length() - 2) + "+0000"; } Date created = null; if (format != null) { if (mSimpleDateFormat == null) { mSimpleDateFormat = new SimpleDateFormat(format, Locale.ENGLISH); // all dates should be GMT/UTC mSimpleDateFormat.setTimeZone(sTimeZone); } try { created = mSimpleDateFormat.parse(date); return created.getTime(); } catch (ParseException e) { Log.e(TAG, e.toString()); } } else { // attempt to parse RSS date if (mSimpleDateFormat != null) { try { created = mSimpleDateFormat.parse(date); return created.getTime(); } catch (ParseException e) { Log.e(TAG, e.toString()); } } for (String rfc822 : sRFC822) { mSimpleDateFormat = new SimpleDateFormat(rfc822, Locale.ENGLISH); mSimpleDateFormat.setTimeZone(sTimeZone); try { if ((created = mSimpleDateFormat.parse(date)) != null) { return created.getTime(); } } catch (ParseException e) { Log.e(TAG, e.toString()); } } } } return System.currentTimeMillis(); } }; loadingDialog.setMessage(getString(R.string.loading)); loadingDialog.setCancelable(true); loadingDialog.setOnCancelListener(new DialogInterface.OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { if (!asyncTask.isCancelled()) asyncTask.cancel(true); } }); loadingDialog.setButton(ProgressDialog.BUTTON_NEGATIVE, getString(android.R.string.cancel), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.cancel(); } }); loadingDialog.show(); asyncTask.execute(); }
From source file:com.afwsamples.testdpc.policy.PolicyManagementFragment.java
/** * Shows a prompt to ask for the certificate password. If the certificate password is correct, * import the private key and certificate. * * @param intent Intent that contains the certificate data uri. * @param attempts The number of times user entered incorrect password. *///w ww.j a va 2 s. c o m private void showPromptForCertificatePassword(final Intent intent, final int attempts) { if (getActivity() == null || getActivity().isFinishing()) { return; } View passwordInputView = getActivity().getLayoutInflater().inflate(R.layout.certificate_password_prompt, null); final EditText input = (EditText) passwordInputView.findViewById(R.id.password_input); if (attempts > 1) { passwordInputView.findViewById(R.id.incorrect_password).setVisibility(View.VISIBLE); } new AlertDialog.Builder(getActivity()).setTitle(getString(R.string.certificate_password_prompt_title)) .setView(passwordInputView) .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { String userPassword = input.getText().toString(); importKeyCertificateFromIntent(intent, userPassword, attempts); dialog.dismiss(); } }).setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.cancel(); } }).show(); }
From source file:com.cliff.comichelper.MainActivity.java
protected void showSelectVolumesDialog(final Comic comic) { AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle(R.string.title_select_volumes); ArrayList<String> list = new ArrayList<String>(); for (int i = 0; i < comic.volumes.length; i++) list.add(comic.volumes[i].volumeName); builder.setMultiChoiceItems(list.toArray(new CharSequence[list.size()]), null, new DialogInterface.OnMultiChoiceClickListener() { @Override/*from w ww .ja v a2 s. co m*/ public void onClick(DialogInterface dialog, int indexSelected, boolean isChecked) { } }) // Set the action buttons .setPositiveButton(R.string.button_ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int id) { allowCloseDialog(dialog, true); final AlertDialog alert = (AlertDialog) dialog; final ListView list = alert.getListView(); ArrayList<Integer> intList = new ArrayList<Integer>(); for (int i = 0; i < list.getAdapter().getCount(); i++) { if (list.isItemChecked(i)) intList.add(i); } int[] volumes = new int[intList.size()]; for (int i = 0; i < volumes.length; i++) volumes[i] = intList.get(i); Command command = new Command(Constants.COMMAND_DOWNLOAD); command.addParam(Constants.PARAM_COMIC, comic); command.addParam(Constants.PARAM_VOLUMES, volumes); command.addParam(Constants.PARAM_ROOTDIR, preferences .getString(SettingsActivity.KEY_DOWNLOAD_LOCATION, SettingsActivity.DIR_DOWNLOAD)); eventBus.post(command); startProgressDialog(R.string.title_download, R.string.message_starting, false); } }).setNegativeButton(R.string.button_cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int id) { allowCloseDialog(dialog, true); dialog.cancel(); } }).setNeutralButton(R.string.button_selectall, new DialogInterface.OnClickListener() { private boolean enabled = false; @Override public void onClick(DialogInterface dialog, int id) { allowCloseDialog(dialog, false); final AlertDialog alert = (AlertDialog) dialog; final ListView list = alert.getListView(); enabled = !enabled; for (int i = 0; i < list.getAdapter().getCount(); i++) { list.setItemChecked(i, enabled); } } }); AlertDialog dialog = builder.create(); dialog.show(); }
From source file:com.dirkgassen.wator.ui.view.RangeSlider.java
/** * Allows the user to click on the thumb. Clicking shows an alert that allows the user to enter a value. The * entered value is adjusted to the minimum/maximum (or to be one of the value set if one is active). * * @return {@code true} to indicate that the click was handled. *///from w w w. j a va 2s . c o m @Override public boolean performClick() { super.performClick(); final Context c = this.getContext(); final AlertDialog.Builder alert = new AlertDialog.Builder(c); final EditText input = new EditText(c); input.setInputType(InputType.TYPE_CLASS_NUMBER); input.setEms(getMaxDigits()); alert.setView(input).setTitle(getContext().getString(R.string.enter_new_value_title)) .setPositiveButton("Ok", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { try { int enteredValue = Integer.valueOf(input.getText().toString().trim()); int newValue; if (valueSet != null) { newValue = valueSet[valueSet.length - 1]; for (int searchValue : valueSet) { if (enteredValue <= searchValue) { newValue = searchValue; break; } } } else { newValue = enteredValue < minValue ? minValue : enteredValue > maxValue ? maxValue : enteredValue; } if (newValue != enteredValue) { Toast.makeText(c, c.getString(R.string.entered_value_adjusted, newValue), Toast.LENGTH_LONG).show(); } if (newValue != value) { updateValue(newValue, true /* from user */); } } catch (NumberFormatException e) { Toast.makeText(c, R.string.invalid_value, Toast.LENGTH_SHORT).show(); } } }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { dialog.cancel(); } }).show(); return true; }
From source file:com.linkedin.android.eventsapp.EventFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { final String eventNameArg = getArguments().getString(EXTRA_EVENT_NAME); final long eventDateArg = getArguments().getLong(EXTRA_EVENT_DATE); final String eventLocationArg = getArguments().getString(EXTRA_EVENT_LOCATION); int pictureIdArg = getArguments().getInt(EXTRA_PICTURE_ID); boolean isAttendingArg = getArguments().getBoolean(EXTRA_EVENT_ATTENDING); Person[] attendeesArg = (Person[]) getArguments().getParcelableArray(EXTRA_EVENT_ATTENDEES); SimpleDateFormat dateFormat = new SimpleDateFormat("E dd MMM yyyy 'at' hh:00 a"); final String dateString = dateFormat.format(new Date(eventDateArg)); View v = inflater.inflate(R.layout.layout_event_fragment, container, false); boolean accessTokenValid = LISessionManager.getInstance(getActivity()).getSession().isValid(); if (!accessTokenValid) { ViewStub linkedinLogin = (ViewStub) v.findViewById(R.id.connectWithLinkedInStub); linkedinLogin.inflate();//w ww .ja va 2s . c o m Button loginButton = (Button) v.findViewById(R.id.connectWithLinkedInButton); loginButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Log.i(TAG, "clicked login button"); LISessionManager.getInstance(getActivity()).init(getActivity(), Constants.scope, new AuthListener() { @Override public void onAuthSuccess() { Intent intent = new Intent(getActivity(), MainActivity.class); startActivity(intent); getActivity().finish(); } @Override public void onAuthError(LIAuthError error) { } }, false); } }); } TextView eventNameView = (TextView) v.findViewById(R.id.eventName); eventNameView.setText(eventNameArg); TextView eventLocationAndDateView = (TextView) v.findViewById(R.id.eventLocationAndDate); eventLocationAndDateView.setText(eventLocationArg + " " + dateString); TextView eventAttendeeCount = (TextView) v.findViewById(R.id.attendeeCount); eventAttendeeCount.setText("Other Attendees (" + attendeesArg.length + ")"); ImageView eventImageView = (ImageView) v.findViewById(R.id.eventImage); eventImageView.setImageResource(pictureIdArg); final Button attendButton = (Button) v.findViewById(R.id.attendButton); final Button declineButton = (Button) v.findViewById(R.id.declineButton); if (isAttendingArg) { attendButton.setText("Attending"); attendButton.setEnabled(false); declineButton.setText("Decline"); declineButton.setEnabled(true); } attendButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { ((Button) v).setText("Attending"); v.setEnabled(false); declineButton.setText("Decline"); declineButton.setEnabled(true); if (LISessionManager.getInstance(getActivity()).getSession().isValid()) { AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(getActivity()); alertDialogBuilder.setTitle("Share on LinkedIn?"); alertDialogBuilder.setCancelable(true) .setPositiveButton("Yes", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { JSONObject shareObject = new JSONObject(); try { JSONObject visibilityCode = new JSONObject(); visibilityCode.put("code", "anyone"); shareObject.put("visibility", visibilityCode); shareObject.put("comment", "I am attending " + eventNameArg + " in " + eventLocationArg + " on " + dateString); } catch (JSONException e) { } APIHelper.getInstance(getActivity()).postRequest(getActivity(), Constants.shareBaseUrl, shareObject, new ApiListener() { @Override public void onApiSuccess(ApiResponse apiResponse) { Toast.makeText(getActivity(), "Your share was successful!", Toast.LENGTH_LONG); } @Override public void onApiError(LIApiError apiError) { Log.e(TAG, apiError.toString()); Toast.makeText(getActivity(), "Your share was unsuccessful. Try again later!", Toast.LENGTH_LONG); } }); } }).setNegativeButton("No", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.cancel(); } }); AlertDialog alertDialog = alertDialogBuilder.create(); alertDialog.show(); } } }); declineButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { ((Button) v).setText("Declined"); v.setEnabled(false); attendButton.setText("Attend"); attendButton.setEnabled(true); } }); ListView attendeesListView = (ListView) v.findViewById(R.id.attendeesList); AttendeeAdapter adapter = new AttendeeAdapter(getActivity(), R.layout.attendee_list_item, attendeesArg, accessTokenValid); attendeesListView.setAdapter(adapter); attendeesListView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { ArrayAdapter adapter = (ArrayAdapter) parent.getAdapter(); Person person = (Person) adapter.getItem(position); Intent intent = new Intent(getActivity(), ProfileActivity.class); Bundle extras = new Bundle(); extras.putParcelable("person", person); intent.putExtras(extras); startActivity(intent); } }); return v; }
From source file:com.instiwork.RegistrationActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_registration); callbackManager = CallbackManager.Factory.create(); pDialogOut = new ProgressDialog(RegistrationActivity.this); pDialogOut.setMessage("Signing up..."); pDialogOut.setCancelable(false);//ww w.j ava2 s .com pDialogOut.setCanceledOnTouchOutside(false); appSharedPref = getSharedPreferences("INSTIWORD", Context.MODE_PRIVATE); Picasso.with(getApplicationContext()).load(R.drawable.registrationbg).fit().centerCrop() .into((ImageView) findViewById(R.id.regbg)); dateOfBirth = (TextView) findViewById(R.id.dateofbirth); license = (RobotoLight) findViewById(R.id.license); ll_license = (LinearLayout) findViewById(R.id.ll_license); selecteddata = (RecyclerView) findViewById(R.id.selecteddat); selecteddata.setVisibility(View.GONE); gender = (RadioGroup) findViewById(R.id.gender_group); fstName = (EditText) findViewById(R.id.first_name); lastname = (EditText) findViewById(R.id.last_name); email = (EditText) findViewById(R.id.email); email_confirm = (EditText) findViewById(R.id.email_confirm); password = (EditText) findViewById(R.id.password); conformPassword = (EditText) findViewById(R.id.con_password); mobile = (EditText) findViewById(R.id.mobile); ll_image_selection = (LinearLayout) findViewById(R.id.ll_image_selection); pro_img = (ImageView) findViewById(R.id.pro_img); countryPbar = (ProgressBar) findViewById(R.id.countryPbar); country_spinner = (Spinner) findViewById(R.id.country_spinner); countryPbar.setVisibility(View.VISIBLE); country_spinner.setVisibility(View.GONE); txt_terms_conditions = (RobotoBold) findViewById(R.id.txt_terms_conditions); country_spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { try { country_2_code = objectsCountry.get(position).getString("country_2_code"); country_id = objectsCountry.get(position).getString("country_id"); } catch (Exception e) { e.printStackTrace(); } } @Override public void onNothingSelected(AdapterView<?> parent) { } }); ll_image_selection.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Intent i = new Intent(RegistrationActivity.this, ImageTakerActivityCamera.class); startActivityForResult(i, 1); } }); txt_terms_conditions.setText(Html.fromHtml("<u>Terms and Condition</u>")); txt_terms_conditions.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { dialogTermsUse(); } }); findViewById(R.id.footer).setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { onBackPressed(); } }); findViewById(R.id.help_password).setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { android.app.AlertDialog.Builder alertDialogBuilder = new android.app.AlertDialog.Builder( RegistrationActivity.this); alertDialogBuilder.setTitle("Password Requirements"); alertDialogBuilder.setMessage( "Please Ensure that Password should have at least 6 characters (Maximum 20) long and it contains at least one lowercase letter, one uppercase letter, one number and one special character.") .setCancelable(false).setPositiveButton("ok", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.cancel(); } }); android.app.AlertDialog alertDialog = alertDialogBuilder.create(); alertDialog.show(); } }); findViewById(R.id.help_dob).setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { android.app.AlertDialog.Builder alertDialogBuilder = new android.app.AlertDialog.Builder( RegistrationActivity.this); alertDialogBuilder.setTitle("Date of Birth"); alertDialogBuilder .setMessage("We require date of birth to verify that no minors are bidding on the jobs.") .setCancelable(false).setPositiveButton("ok", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.cancel(); } }); android.app.AlertDialog alertDialog = alertDialogBuilder.create(); alertDialog.show(); } }); findViewById(R.id.help_license).setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { android.app.AlertDialog.Builder alertDialogBuilder = new android.app.AlertDialog.Builder( RegistrationActivity.this); alertDialogBuilder.setTitle("License"); alertDialogBuilder .setMessage("Please select if you have any work licenses like electrician, plumber, etc...") .setCancelable(false).setPositiveButton("ok", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.cancel(); } }); android.app.AlertDialog alertDialog = alertDialogBuilder.create(); alertDialog.show(); } }); gender.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override public void onCheckedChanged(RadioGroup group, int checkedId) { //Logger.showMessage("Geder : ", "" + checkedId); if (("" + checkedId).equalsIgnoreCase("2131558563")) {//female genderData = "" + 2; } else { genderData = "" + 1; } } }); ll_license.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Intent i = new Intent(RegistrationActivity.this, LicenseActivity.class); startActivityForResult(i, 420); } }); findViewById(R.id.loginBttn).setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { license_ = ""; if (fstName.getText().toString().trim().equalsIgnoreCase("")) { fstName.setError("Please enter name."); fstName.requestFocus(); } else { if (email.getText().toString().trim().equalsIgnoreCase("")) { email.setError("Please enter email."); email.requestFocus(); } else { if (android.util.Patterns.EMAIL_ADDRESS.matcher(email.getText().toString().trim()) .matches()) { if (email_confirm.getText().toString().trim().equalsIgnoreCase("")) { email_confirm.setError("Please enter email again."); email_confirm.requestFocus(); } else { if (android.util.Patterns.EMAIL_ADDRESS .matcher(email_confirm.getText().toString().trim()).matches()) { if (email.getText().toString().trim() .equalsIgnoreCase(email_confirm.getText().toString().trim())) { if (!android.util.Patterns.PHONE.matcher(mobile.getText().toString().trim()) .matches()) { mobile.setError("Please enter valid mobile number."); mobile.requestFocus(); } else { // if (password.getText().toString().trim().equalsIgnoreCase("")) { if (!isValidPassword(password.getText().toString().trim())) { password.setError( "Please Ensure that Password should have at least 6 characters (Maximum 20) long and it contains at least one lowercase letter, one uppercase letter, one number and one special character."); password.requestFocus(); } else { if (conformPassword.getText().toString().trim() .equalsIgnoreCase("")) { conformPassword.setError("Please enter password again."); conformPassword.requestFocus(); } else { if (conformPassword.getText().toString().trim() .equals(password.getText().toString().trim())) { if (dateOfBirth.getText().toString().trim() .equalsIgnoreCase("Birth date")) { Snackbar.make(findViewById(android.R.id.content), "Please select date of birth", Snackbar.LENGTH_LONG) .setActionTextColor(Color.RED).show(); } else { if (isValidDOB( dateOfBirth.getText().toString().trim())) { if (country_2_code.equalsIgnoreCase("0")) { Snackbar.make( findViewById(android.R.id.content), "Select Country From List", Snackbar.LENGTH_LONG) .setActionTextColor(Color.RED).show(); } else { if (InstiworkApplication.getInstance() .getSelectedLicenseArray() != null) { for (int i = 0; i < InstiworkApplication .getInstance() .getSelectedLicenseArray() .size(); i++) { try { if (i == 0) { license_ = license_ + InstiworkApplication .getInstance() .getSelectedLicenseArray() .get(i) .getString( "id"); } else { license_ = license_ + "," + InstiworkApplication .getInstance() .getSelectedLicenseArray() .get(i) .getString( "id"); } } catch (Exception e) { e.printStackTrace(); } } } if (((CheckBox) findViewById(R.id.trmscondi)) .isChecked()) { ll_image_selection.setEnabled(false); txt_terms_conditions.setEnabled(false); findViewById(R.id.footer).setEnabled(false); findViewById(R.id.help_password) .setEnabled(false); findViewById(R.id.help_dob) .setEnabled(false); findViewById(R.id.help_license) .setEnabled(false); ll_license.setEnabled(false); findViewById(R.id.loginBttn) .setEnabled(false); findViewById(R.id.fb_log).setEnabled(false); dateOfBirth.setEnabled(false); ll_image_selection.setClickable(false); txt_terms_conditions.setClickable(false); findViewById(R.id.footer) .setClickable(false); findViewById(R.id.help_password) .setClickable(false); findViewById(R.id.help_dob) .setClickable(false); findViewById(R.id.help_license) .setClickable(false); ll_license.setClickable(false); findViewById(R.id.loginBttn) .setClickable(false); findViewById(R.id.fb_log) .setClickable(false); dateOfBirth.setClickable(false); try { if (appSharedPref .getString("GCM_TOKEN", "") .equalsIgnoreCase("")) { String date[] = dateOfBirth .getText().toString().trim() .split("/"); final String URL = InstiworkConstants.URL_DOMAIN + "Signup_ios?name=" + URLEncoder.encode( fstName.getText() .toString() .trim(), "UTF-8") + "&contact=" + URLEncoder.encode( mobile.getText() .toString() .trim(), "UTF-8") + "&companyname=" + URLEncoder.encode( lastname.getText() .toString() .trim(), "UTF-8") + "&email=" + URLEncoder.encode( email.getText() .toString() .trim(), "UTF-8") + "&password=" + URLEncoder.encode( password.getText() .toString() .trim(), "UTF-8") + "&gender=" + genderData + "&year=" + date[2] + "&month=" + date[0] + "&date=" + date[1] + "&license=" + URLEncoder.encode( license_, "UTF-8") + "&device_type=2" + "&lat=" + LOCATION_LATITUDE + "&lng=" + LOCATION_LONGITUDE + "&country2_code=" + country_2_code + "&country_id=" + country_id + "&device_token="; (new RegistrationGCM(URL)) .executeOnExecutor( AsyncTask.THREAD_POOL_EXECUTOR); } else { gcmToken = appSharedPref .getString("GCM_TOKEN", ""); String date[] = dateOfBirth .getText().toString().trim() .split("/"); final String URL = InstiworkConstants.URL_DOMAIN + "Signup_ios?name=" + URLEncoder.encode( fstName.getText() .toString() .trim(), "UTF-8") + "&contact=" + URLEncoder.encode( mobile.getText() .toString() .trim(), "UTF-8") + "&companyname=" + URLEncoder.encode( lastname.getText() .toString() .trim(), "UTF-8") + "&email=" + URLEncoder.encode( email.getText() .toString() .trim(), "UTF-8") + "&password=" + URLEncoder.encode( password.getText() .toString() .trim(), "UTF-8") + "&gender=" + genderData + "&year=" + date[2] + "&month=" + date[0] + "&date=" + date[1] + "&license=" + license_ + "&device_type=2&device_token=" + URLEncoder.encode( gcmToken, "UTF-8") + "&lat=" + LOCATION_LATITUDE + "&lng=" + LOCATION_LONGITUDE + "&country2_code=" + country_2_code + "&country_id=" + country_id; // login_User(URL); } } catch (Exception e) { e.printStackTrace(); } } else { Snackbar.make( findViewById(android.R.id.content), "Please agree to Terms And Conditions.", Snackbar.LENGTH_LONG) .setActionTextColor(Color.RED) .show(); } } } else { Snackbar.make(findViewById(android.R.id.content), "You are under 14 years old.", Snackbar.LENGTH_LONG) .setActionTextColor(Color.RED).show(); //soutrik } } } else { conformPassword.setError( "Password amd confirm password should be same."); conformPassword.requestFocus(); } } } } } else { email_confirm.setError("Email amd confirm email should be same."); email_confirm.requestFocus(); } } else { email_confirm.setError("Please enter valid email."); email_confirm.requestFocus(); } } } else { email.setError("Please enter valid email."); email.requestFocus(); } } } } }); findViewById(R.id.fb_log).setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if (appSharedPref.getString("GCM_TOKEN", "").equalsIgnoreCase("")) { (new RegistrationGCMFB()).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); } else { gcmToken = appSharedPref.getString("GCM_TOKEN", ""); LoginManager.getInstance().logInWithReadPermissions(RegistrationActivity.this, Arrays.asList("public_profile", "email")); } } }); //---------Facebook LoginManager.getInstance().registerCallback(callbackManager, new FacebookCallback<LoginResult>() { @Override public void onSuccess(LoginResult loginResult) { // App code fbAccessToken = loginResult.getAccessToken().getToken(); GraphRequest request = GraphRequest.newMeRequest(loginResult.getAccessToken(), new GraphRequest.GraphJSONObjectCallback() { @Override public void onCompleted(JSONObject object, GraphResponse response) { // Log.i("FBRESULT", object.toString()); pDialogOut.setMessage("Authenticate Facebook User."); pDialogOut.show(); try { final String URL = InstiworkConstants.URL_DOMAIN + "Login_ios/checkfacebooksignup?facebook_id=" + object.getString("id") + "&device_token=" + URLEncoder.encode(gcmToken, "UTF-8") + "&device_type=2"; FB_ChkUser(URL, object); } catch (Exception e) { e.printStackTrace(); } } }); Bundle parameters = new Bundle(); parameters.putString("fields", "id,name,email,birthday,first_name,last_name,gender"); request.setParameters(parameters); request.executeAsync(); } @Override public void onCancel() { // App code pDialogOut.dismiss(); } @Override public void onError(FacebookException exception) { // App code pDialogOut.dismiss(); if (exception instanceof FacebookAuthorizationException) { if (AccessToken.getCurrentAccessToken() != null) { LoginManager.getInstance().logOut(); LoginManager.getInstance().logInWithReadPermissions(RegistrationActivity.this, Arrays.asList("public_profile", "email")); } else { // Toast.makeText(RegistrationActivity.this, "Facebook Exception : " + exception.toString(), Toast.LENGTH_SHORT).show(); } } else { // Toast.makeText(RegistrationActivity.this, "Facebook Exception : " + exception.toString(), Toast.LENGTH_SHORT).show(); } } }); dateOfBirth.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) {//soutrik Calendar today = Calendar.getInstance(); View dialoglayout = LayoutInflater.from(getApplicationContext()) .inflate(R.layout.dialog_date_picker, null); final DatePicker dPicker = (DatePicker) dialoglayout.findViewById(R.id.date_picker); dPicker.setMaxDate(today.getTimeInMillis()); // set DatePicker MAX Date today.set(dPicker.getYear(), dPicker.getMonth() + 1, dPicker.getDayOfMonth()); today.add(Calendar.YEAR, -14); dPicker.updateDate(today.get(Calendar.YEAR), today.get(Calendar.MONTH) - 1, today.get(Calendar.DATE)); AlertDialog.Builder builder = new AlertDialog.Builder(RegistrationActivity.this); builder.setPositiveButton("OK", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int id) { try { SimpleDateFormat changeFormat = new SimpleDateFormat("MM/dd/yyyy"); Calendar newDate = Calendar.getInstance(); newDate.set(dPicker.getYear(), dPicker.getMonth(), dPicker.getDayOfMonth()); dateOfBirth.setText(changeFormat.format(newDate.getTime())); Logger.showMessage("DOBBBBB : ", changeFormat.format(newDate.getTime())); } catch (Exception e) { e.printStackTrace(); } } }); builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int id) { dateOfBirth.setText("Birth date"); } }); builder.setView(dialoglayout); builder.show(); } }); // getCountryList(); buildGoogleApiClient(); if (gMapOption == null) { gMapOption = new GoogleMapOptions(); gMapOption.ambientEnabled(true); gMapOption.compassEnabled(true); } }
From source file:com.example.android.bluepayandroidsdk.MainActivity.java
public void submit(View v) { String resultMessage = null;// www . ja v a 2 s . c om Map<String, String> result = null; Map<String, String> paymentInfo = new HashMap<String, String>(); if (v.getId() == R.id.payButton) { if (LaunchPaymentSection.getName1().toString().equals("First Name".toString())) { LaunchPaymentSection.name1Text.setError("First Name is required"); return; } if (LaunchPaymentSection.getName2().toString().equals("Last Name".toString())) { LaunchPaymentSection.name2Text.setError("Last Name is required"); return; } if (LaunchPaymentSection.getAddr1().toString().equals("Addr 1".toString())) { LaunchPaymentSection.addr1Text.setError("Addr 1 is required"); return; } try { if (!validateCard(LaunchPaymentSection.getCardNumber())) { LaunchPaymentSection.cardNumberText.setError("Invalid Card #"); return; } } catch (Exception e) { LaunchPaymentSection.cardNumberText.setError("Invalid Card #"); return; } try { if (!LaunchPaymentSection.getCVV2().matches("\\d+") || LaunchPaymentSection.getCVV2().length() < 3 || LaunchPaymentSection.getCVV2().length() > 4) { LaunchPaymentSection.cvv2Text.setError("Invalid CVV2"); return; } } catch (Exception e) { LaunchPaymentSection.cvv2Text.setError("Invalid CVV2"); return; } try { if (!LaunchPaymentSection.getAmount().matches("^(?!\\.?$)\\d{0,6}(\\.\\d{0,2})?$")) { LaunchPaymentSection.amount.setError("Invalid Amount"); return; } } catch (Exception e) { LaunchPaymentSection.amount.setError("Invalid Amount"); return; } if (LaunchPaymentSection.getAddr2().toString().equals("Addr 2".toString())) { LaunchPaymentSection.addr2Text.setText(""); } if (LaunchPaymentSection.getCity().toString().equals("City".toString())) { LaunchPaymentSection.cityText.setText(""); } if (LaunchPaymentSection.getState().toString().equals("State".toString())) { LaunchPaymentSection.stateText.setText(""); } if (LaunchPaymentSection.getZip().toString().equals("Zip".toString())) { LaunchPaymentSection.zipText.setText(""); } // do POST here; make new BluePay class for processing paymentInfo.put("name1", LaunchPaymentSection.getName1()); paymentInfo.put("name2", LaunchPaymentSection.getName2()); paymentInfo.put("addr1", LaunchPaymentSection.getAddr1()); paymentInfo.put("addr2", LaunchPaymentSection.getAddr2()); paymentInfo.put("city", LaunchPaymentSection.getCity()); paymentInfo.put("state", LaunchPaymentSection.getState()); paymentInfo.put("zip", LaunchPaymentSection.getZip()); paymentInfo.put("cardNumber", LaunchPaymentSection.getCardNumber()); paymentInfo.put("expMonth", String.format("%02d", Integer.parseInt(LaunchPaymentSection.getExpMonth()))); paymentInfo.put("expYear", LaunchPaymentSection.getExpYear()); paymentInfo.put("cvv2", LaunchPaymentSection.getCVV2()); paymentInfo.put("amount", LaunchPaymentSection.getAmount()); } else if (v.getId() == R.id.tokenButton) { if (LaunchTokenSection.getName1().toString().equals("First Name".toString())) { LaunchTokenSection.name1Text.setError("First Name is required"); return; } if (LaunchTokenSection.getName2().toString().equals("Last Name".toString())) { LaunchTokenSection.name2Text.setError("Last Name is required"); return; } if (LaunchTokenSection.getAddr1().toString().equals("Addr 1".toString())) { LaunchTokenSection.addr1Text.setError("Addr 1 is required"); return; } try { if (!validateCard(LaunchTokenSection.getCardNumber())) { LaunchTokenSection.cardNumberText.setError("Invalid Card #"); return; } } catch (Exception e) { LaunchTokenSection.cardNumberText.setError("Invalid Card #"); return; } try { if (!LaunchTokenSection.getCVV2().matches("\\d+") || LaunchTokenSection.getCVV2().length() < 3 || LaunchTokenSection.getCVV2().length() > 4) { LaunchTokenSection.cvv2Text.setError("Invalid CVV2"); return; } } catch (Exception e) { LaunchTokenSection.cvv2Text.setError("Invalid CVV2"); return; } if (LaunchTokenSection.getAddr2().toString().equals("Addr 2".toString())) { LaunchTokenSection.addr2Text.setText(""); } if (LaunchTokenSection.getCity().toString().equals("City".toString())) { LaunchTokenSection.cityText.setText(""); } if (LaunchTokenSection.getState().toString().equals("State".toString())) { LaunchTokenSection.stateText.setText(""); } if (LaunchTokenSection.getZip().toString().equals("Zip".toString())) { LaunchTokenSection.zipText.setText(""); } paymentInfo.put("name1", LaunchTokenSection.getName1()); paymentInfo.put("name2", LaunchTokenSection.getName2()); paymentInfo.put("addr1", LaunchTokenSection.getAddr1()); paymentInfo.put("addr2", LaunchTokenSection.getAddr2()); paymentInfo.put("city", LaunchTokenSection.getCity()); paymentInfo.put("state", LaunchTokenSection.getState()); paymentInfo.put("zip", LaunchTokenSection.getZip()); paymentInfo.put("transType", "AUTH"); paymentInfo.put("cardNumber", LaunchTokenSection.getCardNumber()); paymentInfo.put("expMonth", String.format("%02d", Integer.parseInt(LaunchTokenSection.getExpMonth()))); paymentInfo.put("expYear", LaunchTokenSection.getExpYear()); paymentInfo.put("cvv2", LaunchTokenSection.getCVV2()); paymentInfo.put("amount", "0.00"); } else if (v.getId() == R.id.btn_swipeCard) { try { if (!LaunchSwipeSection.getAmount().matches("^(?!\\.?$)\\d{0,6}(\\.\\d{0,2})?$")) { LaunchSwipeSection.amount.setError("Invalid Amount"); return; } } catch (Exception e) { LaunchSwipeSection.amount.setError("Invalid Amount"); return; } if (LaunchSwipeSection.getAddr1().toString().equals("Addr 1".toString())) { LaunchSwipeSection.addr1Text.setText(""); } if (LaunchSwipeSection.getAddr2().toString().equals("Addr 2".toString())) { LaunchSwipeSection.addr2Text.setText(""); } if (LaunchSwipeSection.getCity().toString().equals("City".toString())) { LaunchSwipeSection.cityText.setText(""); } if (LaunchSwipeSection.getState().toString().equals("State".toString())) { LaunchSwipeSection.stateText.setText(""); } if (LaunchSwipeSection.getZip().toString().equals("Zip".toString())) { LaunchSwipeSection.zipText.setText(""); } paymentInfo.put("name1", cardHolderFirst); paymentInfo.put("name2", cardHolderLast); paymentInfo.put("ksn", KSN); paymentInfo.put("track1", encTrack1); paymentInfo.put("track1Length", String.valueOf(track1.length())); paymentInfo.put("amount", LaunchSwipeSection.getAmount()); paymentInfo.put("addr1", LaunchSwipeSection.getAddr1()); paymentInfo.put("addr2", LaunchSwipeSection.getAddr2()); paymentInfo.put("city", LaunchSwipeSection.getCity()); paymentInfo.put("state", LaunchSwipeSection.getState()); paymentInfo.put("zip", LaunchSwipeSection.getZip()); if (LaunchSwipeSection.getAddr1().toString().equals("".toString())) { LaunchSwipeSection.addr1Text.setText("Addr 1"); } if (LaunchSwipeSection.getAddr2().toString().equals("".toString())) { LaunchSwipeSection.addr2Text.setText("Addr 2"); } if (LaunchSwipeSection.getCity().toString().equals("".toString())) { LaunchSwipeSection.cityText.setText("City"); } if (LaunchSwipeSection.getState().toString().equals("".toString())) { LaunchSwipeSection.stateText.setText("State"); } if (LaunchSwipeSection.getZip().toString().equals("".toString())) { LaunchSwipeSection.zipText.setText("Zip"); } } else return; result = bluepay.doPost(paymentInfo); switch (result.get("STATUS")) { case "1": resultMessage = "The transaction has been approved. Transaction ID:" + result.get("TRANS_ID"); break; case "0": resultMessage = "The transaction has been declined"; break; case "E": resultMessage = "An error occurred with the payment. Reason: " + result.get("MESSAGE"); break; default: resultMessage = "General error."; break; } new AlertDialog.Builder(this).setTitle("Transaction Result").setMessage(resultMessage).setCancelable(false) .setPositiveButton("OK", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.cancel(); } }).create().show(); }
From source file:com.shafiq.myfeedle.core.MyfeedleComments.java
private void loadComments() { mComments.clear();//from w w w.ja v a 2 s . c o m setListAdapter(new SimpleAdapter(MyfeedleComments.this, mComments, R.layout.comment, new String[] { Entities.FRIEND, Statuses.MESSAGE, Statuses.CREATEDTEXT, getString(R.string.like) }, new int[] { R.id.friend, R.id.message, R.id.created, R.id.like })); mMessage.setEnabled(false); mMessage.setText(R.string.loading); final ProgressDialog loadingDialog = new ProgressDialog(this); final AsyncTask<Void, String, String> asyncTask = new AsyncTask<Void, String, String>() { @Override protected String doInBackground(Void... none) { // load the status itself if (mData != null) { MyfeedleCrypto myfeedleCrypto = MyfeedleCrypto.getInstance(getApplicationContext()); UriMatcher um = new UriMatcher(UriMatcher.NO_MATCH); String authority = Myfeedle.getAuthority(MyfeedleComments.this); um.addURI(authority, MyfeedleProvider.VIEW_STATUSES_STYLES + "/*", MyfeedleProvider.STATUSES_STYLES); um.addURI(authority, MyfeedleProvider.TABLE_NOTIFICATIONS + "/*", MyfeedleProvider.NOTIFICATIONS); Cursor status; switch (um.match(mData)) { case MyfeedleProvider.STATUSES_STYLES: status = getContentResolver().query(Statuses_styles.getContentUri(MyfeedleComments.this), new String[] { Statuses_styles.ACCOUNT, Statuses_styles.SID, Statuses_styles.ESID, Statuses_styles.WIDGET, Statuses_styles.SERVICE, Statuses_styles.FRIEND, Statuses_styles.MESSAGE, Statuses_styles.CREATED }, Statuses_styles._ID + "=?", new String[] { mData.getLastPathSegment() }, null); if (status.moveToFirst()) { mService = status.getInt(4); mServiceName = getResources().getStringArray(R.array.service_entries)[mService]; mAccount = status.getLong(0); mSid = myfeedleCrypto.Decrypt(status.getString(1)); mEsid = myfeedleCrypto.Decrypt(status.getString(2)); Cursor widget = getContentResolver().query( Widgets_settings.getContentUri(MyfeedleComments.this), new String[] { Widgets.TIME24HR }, Widgets.WIDGET + "=? and " + Widgets.ACCOUNT + "=?", new String[] { Integer.toString(status.getInt(3)), Long.toString(mAccount) }, null); if (widget.moveToFirst()) { mTime24hr = widget.getInt(0) == 1; } else { Cursor b = getContentResolver().query( Widgets_settings.getContentUri(MyfeedleComments.this), new String[] { Widgets.TIME24HR }, Widgets.WIDGET + "=? and " + Widgets.ACCOUNT + "=?", new String[] { Integer.toString(status.getInt(3)), Long.toString(Myfeedle.INVALID_ACCOUNT_ID) }, null); if (b.moveToFirst()) { mTime24hr = b.getInt(0) == 1; } else { Cursor c = getContentResolver() .query(Widgets_settings.getContentUri(MyfeedleComments.this), new String[] { Widgets.TIME24HR }, Widgets.WIDGET + "=? and " + Widgets.ACCOUNT + "=?", new String[] { Integer.toString(AppWidgetManager.INVALID_APPWIDGET_ID), Long.toString(Myfeedle.INVALID_ACCOUNT_ID) }, null); if (c.moveToFirst()) { mTime24hr = c.getInt(0) == 1; } else { mTime24hr = false; } c.close(); } b.close(); } widget.close(); HashMap<String, String> commentMap = new HashMap<String, String>(); commentMap.put(Statuses.SID, mSid); commentMap.put(Entities.FRIEND, status.getString(5)); commentMap.put(Statuses.MESSAGE, status.getString(6)); commentMap.put(Statuses.CREATEDTEXT, Myfeedle.getCreatedText(status.getLong(7), mTime24hr)); commentMap.put(getString(R.string.like), mService == TWITTER ? getString(R.string.retweet) : mService == IDENTICA ? getString(R.string.repeat) : ""); mComments.add(commentMap); // load the session Cursor account = getContentResolver().query( Accounts.getContentUri(MyfeedleComments.this), new String[] { Accounts.TOKEN, Accounts.SECRET, Accounts.SID }, Accounts._ID + "=?", new String[] { Long.toString(mAccount) }, null); if (account.moveToFirst()) { mToken = myfeedleCrypto.Decrypt(account.getString(0)); mSecret = myfeedleCrypto.Decrypt(account.getString(1)); mAccountSid = myfeedleCrypto.Decrypt(account.getString(2)); } account.close(); } status.close(); break; case MyfeedleProvider.NOTIFICATIONS: Cursor notification = getContentResolver().query( Notifications.getContentUri(MyfeedleComments.this), new String[] { Notifications.ACCOUNT, Notifications.SID, Notifications.ESID, Notifications.FRIEND, Notifications.MESSAGE, Notifications.CREATED }, Notifications._ID + "=?", new String[] { mData.getLastPathSegment() }, null); if (notification.moveToFirst()) { // clear notification ContentValues values = new ContentValues(); values.put(Notifications.CLEARED, 1); getContentResolver().update(Notifications.getContentUri(MyfeedleComments.this), values, Notifications._ID + "=?", new String[] { mData.getLastPathSegment() }); mAccount = notification.getLong(0); mSid = myfeedleCrypto.Decrypt(notification.getString(1)); mEsid = myfeedleCrypto.Decrypt(notification.getString(2)); mTime24hr = false; // load the session Cursor account = getContentResolver().query( Accounts.getContentUri(MyfeedleComments.this), new String[] { Accounts.TOKEN, Accounts.SECRET, Accounts.SID, Accounts.SERVICE }, Accounts._ID + "=?", new String[] { Long.toString(mAccount) }, null); if (account.moveToFirst()) { mToken = myfeedleCrypto.Decrypt(account.getString(0)); mSecret = myfeedleCrypto.Decrypt(account.getString(1)); mAccountSid = myfeedleCrypto.Decrypt(account.getString(2)); mService = account.getInt(3); } account.close(); HashMap<String, String> commentMap = new HashMap<String, String>(); commentMap.put(Statuses.SID, mSid); commentMap.put(Entities.FRIEND, notification.getString(3)); commentMap.put(Statuses.MESSAGE, notification.getString(4)); commentMap.put(Statuses.CREATEDTEXT, Myfeedle.getCreatedText(notification.getLong(5), mTime24hr)); commentMap.put(getString(R.string.like), mService == TWITTER ? getString(R.string.retweet) : getString(R.string.repeat)); mComments.add(commentMap); mServiceName = getResources().getStringArray(R.array.service_entries)[mService]; } notification.close(); break; default: mComments.clear(); HashMap<String, String> commentMap = new HashMap<String, String>(); commentMap.put(Statuses.SID, ""); commentMap.put(Entities.FRIEND, ""); commentMap.put(Statuses.MESSAGE, "error, status not found"); commentMap.put(Statuses.CREATEDTEXT, ""); commentMap.put(getString(R.string.like), ""); mComments.add(commentMap); } String response = null; HttpGet httpGet; MyfeedleOAuth myfeedleOAuth; boolean liked = false; String screen_name = ""; switch (mService) { case TWITTER: myfeedleOAuth = new MyfeedleOAuth(TWITTER_KEY, TWITTER_SECRET, mToken, mSecret); if ((response = MyfeedleHttpClient.httpResponse(mHttpClient, myfeedleOAuth.getSignedRequest( new HttpGet(String.format(TWITTER_USER, TWITTER_BASE_URL, mEsid))))) != null) { try { JSONObject user = new JSONObject(response); screen_name = "@" + user.getString(Sscreen_name) + " "; } catch (JSONException e) { Log.e(TAG, e.toString()); } } publishProgress(screen_name); response = MyfeedleHttpClient.httpResponse(mHttpClient, myfeedleOAuth.getSignedRequest(new HttpGet(String.format(TWITTER_MENTIONS, TWITTER_BASE_URL, String.format(TWITTER_SINCE_ID, mSid))))); break; case FACEBOOK: if ((response = MyfeedleHttpClient.httpResponse(mHttpClient, new HttpGet(String.format(FACEBOOK_LIKES, FACEBOOK_BASE_URL, mSid, Saccess_token, mToken)))) != null) { try { JSONArray likes = new JSONObject(response).getJSONArray(Sdata); for (int i = 0, i2 = likes.length(); i < i2; i++) { JSONObject like = likes.getJSONObject(i); if (like.getString(Sid).equals(mAccountSid)) { liked = true; break; } } } catch (JSONException e) { Log.e(TAG, e.toString()); } } publishProgress(getString(liked ? R.string.unlike : R.string.like)); response = MyfeedleHttpClient.httpResponse(mHttpClient, new HttpGet( String.format(FACEBOOK_COMMENTS, FACEBOOK_BASE_URL, mSid, Saccess_token, mToken))); break; case MYSPACE: myfeedleOAuth = new MyfeedleOAuth(MYSPACE_KEY, MYSPACE_SECRET, mToken, mSecret); response = MyfeedleHttpClient.httpResponse(mHttpClient, myfeedleOAuth.getSignedRequest(new HttpGet(String .format(MYSPACE_URL_STATUSMOODCOMMENTS, MYSPACE_BASE_URL, mEsid, mSid)))); break; case LINKEDIN: myfeedleOAuth = new MyfeedleOAuth(LINKEDIN_KEY, LINKEDIN_SECRET, mToken, mSecret); httpGet = new HttpGet(String.format(LINKEDIN_UPDATE, LINKEDIN_BASE_URL, mSid)); for (String[] header : LINKEDIN_HEADERS) httpGet.setHeader(header[0], header[1]); if ((response = MyfeedleHttpClient.httpResponse(mHttpClient, myfeedleOAuth.getSignedRequest(httpGet))) != null) { try { JSONObject data = new JSONObject(response); if (data.has("isCommentable") && !data.getBoolean("isCommentable")) { publishProgress(getString(R.string.uncommentable)); } if (data.has("isLikable")) { publishProgress(getString( data.has("isLiked") && data.getBoolean("isLiked") ? R.string.unlike : R.string.like)); } else { publishProgress(getString(R.string.unlikable)); } } catch (JSONException e) { Log.e(TAG, e.toString()); } } else { publishProgress(getString(R.string.unlikable)); } httpGet = new HttpGet(String.format(LINKEDIN_UPDATE_COMMENTS, LINKEDIN_BASE_URL, mSid)); for (String[] header : LINKEDIN_HEADERS) httpGet.setHeader(header[0], header[1]); response = MyfeedleHttpClient.httpResponse(mHttpClient, myfeedleOAuth.getSignedRequest(httpGet)); break; case FOURSQUARE: response = MyfeedleHttpClient.httpResponse(mHttpClient, new HttpGet( String.format(FOURSQUARE_GET_CHECKIN, FOURSQUARE_BASE_URL, mSid, mToken))); break; case IDENTICA: myfeedleOAuth = new MyfeedleOAuth(IDENTICA_KEY, IDENTICA_SECRET, mToken, mSecret); if ((response = MyfeedleHttpClient.httpResponse(mHttpClient, myfeedleOAuth.getSignedRequest( new HttpGet(String.format(IDENTICA_USER, IDENTICA_BASE_URL, mEsid))))) != null) { try { JSONObject user = new JSONObject(response); screen_name = "@" + user.getString(Sscreen_name) + " "; } catch (JSONException e) { Log.e(TAG, e.toString()); } } publishProgress(screen_name); response = MyfeedleHttpClient.httpResponse(mHttpClient, myfeedleOAuth.getSignedRequest(new HttpGet(String.format(IDENTICA_MENTIONS, IDENTICA_BASE_URL, String.format(IDENTICA_SINCE_ID, mSid))))); break; case GOOGLEPLUS: //TODO: // get plussed status break; case CHATTER: // Chatter requires loading an instance if ((mChatterInstance == null) || (mChatterToken == null)) { if ((response = MyfeedleHttpClient.httpResponse(mHttpClient, new HttpPost( String.format(CHATTER_URL_ACCESS, CHATTER_KEY, mToken)))) != null) { try { JSONObject jobj = new JSONObject(response); if (jobj.has("instance_url") && jobj.has(Saccess_token)) { mChatterInstance = jobj.getString("instance_url"); mChatterToken = jobj.getString(Saccess_token); } } catch (JSONException e) { Log.e(TAG, e.toString()); } } } if ((mChatterInstance != null) && (mChatterToken != null)) { httpGet = new HttpGet(String.format(CHATTER_URL_LIKES, mChatterInstance, mSid)); httpGet.setHeader("Authorization", "OAuth " + mChatterToken); if ((response = MyfeedleHttpClient.httpResponse(mHttpClient, httpGet)) != null) { try { JSONObject jobj = new JSONObject(response); if (jobj.getInt(Stotal) > 0) { JSONArray likes = jobj.getJSONArray("likes"); for (int i = 0, i2 = likes.length(); i < i2; i++) { JSONObject like = likes.getJSONObject(i); if (like.getJSONObject(Suser).getString(Sid).equals(mAccountSid)) { mChatterLikeId = like.getString(Sid); liked = true; break; } } } } catch (JSONException e) { Log.e(TAG, e.toString()); } } publishProgress(getString(liked ? R.string.unlike : R.string.like)); httpGet = new HttpGet(String.format(CHATTER_URL_COMMENTS, mChatterInstance, mSid)); httpGet.setHeader("Authorization", "OAuth " + mChatterToken); response = MyfeedleHttpClient.httpResponse(mHttpClient, httpGet); } else { response = null; } break; } return response; } return null; } @Override protected void onProgressUpdate(String... params) { mMessage.setText(""); if (params != null) { if ((mService == TWITTER) || (mService == IDENTICA)) { mMessage.append(params[0]); } else { if (mService == LINKEDIN) { if (params[0].equals(getString(R.string.uncommentable))) { mSend.setEnabled(false); mMessage.setEnabled(false); mMessage.setText(R.string.uncommentable); } else { setCommentStatus(0, params[0]); } } else { setCommentStatus(0, params[0]); } } } mMessage.setEnabled(true); } @Override protected void onPostExecute(String response) { if (response != null) { int i2; try { JSONArray comments; mSimpleDateFormat = null; switch (mService) { case TWITTER: comments = new JSONArray(response); if ((i2 = comments.length()) > 0) { for (int i = 0; i < i2; i++) { JSONObject comment = comments.getJSONObject(i); if (comment.getString(Sin_reply_to_status_id) == mSid) { HashMap<String, String> commentMap = new HashMap<String, String>(); commentMap.put(Statuses.SID, comment.getString(Sid)); commentMap.put(Entities.FRIEND, comment.getJSONObject(Suser).getString(Sname)); commentMap.put(Statuses.MESSAGE, comment.getString(Stext)); commentMap.put(Statuses.CREATEDTEXT, Myfeedle.getCreatedText( parseDate(comment.getString(Screated_at), TWITTER_DATE_FORMAT), mTime24hr)); commentMap.put(getString(R.string.like), getString(R.string.retweet)); mComments.add(commentMap); } } } else { noComments(); } break; case FACEBOOK: comments = new JSONObject(response).getJSONArray(Sdata); if ((i2 = comments.length()) > 0) { for (int i = 0; i < i2; i++) { JSONObject comment = comments.getJSONObject(i); HashMap<String, String> commentMap = new HashMap<String, String>(); commentMap.put(Statuses.SID, comment.getString(Sid)); commentMap.put(Entities.FRIEND, comment.getJSONObject(Sfrom).getString(Sname)); commentMap.put(Statuses.MESSAGE, comment.getString(Smessage)); commentMap.put(Statuses.CREATEDTEXT, Myfeedle .getCreatedText(comment.getLong(Screated_time) * 1000, mTime24hr)); commentMap.put(getString(R.string.like), getString(comment.has(Suser_likes) && comment.getBoolean(Suser_likes) ? R.string.unlike : R.string.like)); mComments.add(commentMap); } } else { noComments(); } break; case MYSPACE: comments = new JSONObject(response).getJSONArray(Sentry); if ((i2 = comments.length()) > 0) { for (int i = 0; i < i2; i++) { JSONObject entry = comments.getJSONObject(i); HashMap<String, String> commentMap = new HashMap<String, String>(); commentMap.put(Statuses.SID, entry.getString(ScommentId)); commentMap.put(Entities.FRIEND, entry.getJSONObject(Sauthor).getString(SdisplayName)); commentMap.put(Statuses.MESSAGE, entry.getString(Sbody)); commentMap.put(Statuses.CREATEDTEXT, Myfeedle.getCreatedText( parseDate(entry.getString(SpostedDate), MYSPACE_DATE_FORMAT), mTime24hr)); commentMap.put(getString(R.string.like), ""); mComments.add(commentMap); } } else { noComments(); } break; case LINKEDIN: JSONObject jsonResponse = new JSONObject(response); if (jsonResponse.has(S_total) && (jsonResponse.getInt(S_total) != 0)) { comments = jsonResponse.getJSONArray(Svalues); if ((i2 = comments.length()) > 0) { for (int i = 0; i < i2; i++) { JSONObject comment = comments.getJSONObject(i); JSONObject person = comment.getJSONObject(Sperson); HashMap<String, String> commentMap = new HashMap<String, String>(); commentMap.put(Statuses.SID, comment.getString(Sid)); commentMap.put(Entities.FRIEND, person.getString(SfirstName) + " " + person.getString(SlastName)); commentMap.put(Statuses.MESSAGE, comment.getString(Scomment)); commentMap.put(Statuses.CREATEDTEXT, Myfeedle.getCreatedText(comment.getLong(Stimestamp), mTime24hr)); commentMap.put(getString(R.string.like), ""); mComments.add(commentMap); } } else { noComments(); } } break; case FOURSQUARE: comments = new JSONObject(response).getJSONObject(Sresponse).getJSONObject(Scheckin) .getJSONObject(Scomments).getJSONArray(Sitems); if ((i2 = comments.length()) > 0) { for (int i = 0; i < i2; i++) { JSONObject comment = comments.getJSONObject(i); JSONObject user = comment.getJSONObject(Suser); HashMap<String, String> commentMap = new HashMap<String, String>(); commentMap.put(Statuses.SID, comment.getString(Sid)); commentMap.put(Entities.FRIEND, user.getString(SfirstName) + " " + user.getString(SlastName)); commentMap.put(Statuses.MESSAGE, comment.getString(Stext)); commentMap.put(Statuses.CREATEDTEXT, Myfeedle.getCreatedText(comment.getLong(ScreatedAt) * 1000, mTime24hr)); commentMap.put(getString(R.string.like), ""); mComments.add(commentMap); } } else { noComments(); } break; case IDENTICA: comments = new JSONArray(response); if ((i2 = comments.length()) > 0) { for (int i = 0; i < i2; i++) { JSONObject comment = comments.getJSONObject(i); if (comment.getString(Sin_reply_to_status_id) == mSid) { HashMap<String, String> commentMap = new HashMap<String, String>(); commentMap.put(Statuses.SID, comment.getString(Sid)); commentMap.put(Entities.FRIEND, comment.getJSONObject(Suser).getString(Sname)); commentMap.put(Statuses.MESSAGE, comment.getString(Stext)); commentMap.put(Statuses.CREATEDTEXT, Myfeedle.getCreatedText( parseDate(comment.getString(Screated_at), TWITTER_DATE_FORMAT), mTime24hr)); commentMap.put(getString(R.string.like), getString(R.string.repeat)); mComments.add(commentMap); } } } else { noComments(); } break; case GOOGLEPLUS: //TODO: load comments HttpPost httpPost = new HttpPost(GOOGLE_ACCESS); List<NameValuePair> httpParams = new ArrayList<NameValuePair>(); httpParams.add(new BasicNameValuePair("client_id", GOOGLE_CLIENTID)); httpParams.add(new BasicNameValuePair("client_secret", GOOGLE_CLIENTSECRET)); httpParams.add(new BasicNameValuePair("refresh_token", mToken)); httpParams.add(new BasicNameValuePair("grant_type", "refresh_token")); try { httpPost.setEntity(new UrlEncodedFormEntity(httpParams)); if ((response = MyfeedleHttpClient.httpResponse(mHttpClient, httpPost)) != null) { JSONObject j = new JSONObject(response); if (j.has(Saccess_token)) { String access_token = j.getString(Saccess_token); if ((response = MyfeedleHttpClient.httpResponse(mHttpClient, new HttpGet(String.format(GOOGLEPLUS_ACTIVITY, GOOGLEPLUS_BASE_URL, mSid, access_token)))) != null) { // check for a newer post, if it's the user's own, then set CLEARED=0 try { JSONObject item = new JSONObject(response); if (item.has(Sobject)) { JSONObject object = item.getJSONObject(Sobject); if (object.has(Sreplies)) { int commentCount = 0; JSONObject replies = object.getJSONObject(Sreplies); if (replies.has(StotalItems)) { //TODO: load comments commentCount = replies.getInt(StotalItems); } } } } catch (JSONException e) { Log.e(TAG, e.toString()); } } } } } catch (UnsupportedEncodingException e) { Log.e(TAG, e.toString()); } catch (JSONException e) { Log.e(TAG, e.toString()); } break; case CHATTER: JSONObject chats = new JSONObject(response); if (chats.getInt(Stotal) > 0) { comments = chats.getJSONArray(Scomments); if ((i2 = comments.length()) > 0) { for (int i = 0; i < i2; i++) { JSONObject comment = comments.getJSONObject(i); HashMap<String, String> commentMap = new HashMap<String, String>(); commentMap.put(Statuses.SID, comment.getString(Sid)); commentMap.put(Entities.FRIEND, comment.getJSONObject(Suser).getString(Sname)); commentMap.put(Statuses.MESSAGE, comment.getJSONObject(Sbody).getString(Stext)); commentMap.put(Statuses.CREATEDTEXT, Myfeedle.getCreatedText( parseDate(comment.getString(ScreatedDate), CHATTER_DATE_FORMAT), mTime24hr)); commentMap.put(getString(R.string.like), ""); mComments.add(commentMap); } } else { noComments(); } } else { noComments(); } break; } } catch (JSONException e) { Log.e(TAG, e.toString()); } } else { noComments(); } setListAdapter(new SimpleAdapter(MyfeedleComments.this, mComments, R.layout.comment, new String[] { Entities.FRIEND, Statuses.MESSAGE, Statuses.CREATEDTEXT, getString(R.string.like) }, new int[] { R.id.friend, R.id.message, R.id.created, R.id.like })); if (loadingDialog.isShowing()) loadingDialog.dismiss(); } private void noComments() { HashMap<String, String> commentMap = new HashMap<String, String>(); commentMap.put(Statuses.SID, ""); commentMap.put(Entities.FRIEND, ""); commentMap.put(Statuses.MESSAGE, getString(R.string.no_comments)); commentMap.put(Statuses.CREATEDTEXT, ""); commentMap.put(getString(R.string.like), ""); mComments.add(commentMap); } private long parseDate(String date, String format) { if (date != null) { // hack for the literal 'Z' if (date.substring(date.length() - 1).equals("Z")) { date = date.substring(0, date.length() - 2) + "+0000"; } Date created = null; if (format != null) { if (mSimpleDateFormat == null) { mSimpleDateFormat = new SimpleDateFormat(format, Locale.ENGLISH); // all dates should be GMT/UTC mSimpleDateFormat.setTimeZone(sTimeZone); } try { created = mSimpleDateFormat.parse(date); return created.getTime(); } catch (ParseException e) { Log.e(TAG, e.toString()); } } else { // attempt to parse RSS date if (mSimpleDateFormat != null) { try { created = mSimpleDateFormat.parse(date); return created.getTime(); } catch (ParseException e) { Log.e(TAG, e.toString()); } } for (String rfc822 : sRFC822) { mSimpleDateFormat = new SimpleDateFormat(rfc822, Locale.ENGLISH); mSimpleDateFormat.setTimeZone(sTimeZone); try { if ((created = mSimpleDateFormat.parse(date)) != null) { return created.getTime(); } } catch (ParseException e) { Log.e(TAG, e.toString()); } } } } return System.currentTimeMillis(); } }; loadingDialog.setMessage(getString(R.string.loading)); loadingDialog.setCancelable(true); loadingDialog.setOnCancelListener(new DialogInterface.OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { if (!asyncTask.isCancelled()) asyncTask.cancel(true); } }); loadingDialog.setButton(ProgressDialog.BUTTON_NEGATIVE, getString(android.R.string.cancel), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.cancel(); } }); loadingDialog.show(); asyncTask.execute(); }