Example usage for android.content DialogInterface cancel

List of usage examples for android.content DialogInterface cancel

Introduction

In this page you can find the example usage for android.content DialogInterface cancel.

Prototype

void cancel();

Source Link

Document

Cancels the dialog, invoking the OnCancelListener .

Usage

From source file:com.lifehackinnovations.siteaudit.FloorPlanActivity.java

public void showchecksdialog() {
    Boolean passedchecks = false;
    String PositiveButtonString;//from  ww  w . jav a2 s  . c om
    String DisplayChecksOrPassedString;
    String ListChecksString = dochecks();
    String Title;

    if (ListChecksString.trim().length() == 0) {
        passedchecks = true;
    }
    if (passedchecks) {
        DisplayChecksOrPassedString = "Are you sure your finished editing floorplans?";
        Title = "Exit";
        PositiveButtonString = "OK";
    } else {
        DisplayChecksOrPassedString = "You have outstanding issues with this floorplan, please correct these issues before exiting.";
        Title = "Outstanding Issues!";
        PositiveButtonString = "IGNORE & EXIT";
    }

    TextView showfailedcheckstv;
    showfailedcheckstv = new TextView(this);
    showfailedcheckstv.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
    showfailedcheckstv.setText(ListChecksString);
    showfailedcheckstv.setPadding(5, 5, 5, 5);

    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setTitle(Title).setMessage(DisplayChecksOrPassedString).setView(showfailedcheckstv)
            .setCancelable(false).setIcon(R.drawable.ic_launcher)
            .setPositiveButton(PositiveButtonString, new DialogInterface.OnClickListener() {

                @Override

                public void onClick(DialogInterface dialog, int which) {
                    // TODO Auto-generated method stub

                    balmvalues();
                    new SaveTask(progressDialog).execute();
                    try {
                        sethourglassicons();
                    } catch (Throwable e) {

                    }
                    finish();
                    System.gc();
                    dialog.dismiss();
                    finish();
                }

            }).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.shafiq.myfeedle.core.MyfeedleNotifications.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    final ProgressDialog loadingDialog = new ProgressDialog(this);
    final AsyncTask<Integer, String, Boolean> asyncTask = new AsyncTask<Integer, String, Boolean>() {

        @Override/*from   w w w. j ava  2 s. c  o m*/
        protected Boolean doInBackground(Integer... arg0) {
            if (arg0[0] == R.id.menu_notifications_refresh) {
                // select all accounts with notifications set
                Cursor widgets = getContentResolver().query(
                        Widgets_settings.getDistinctContentUri(MyfeedleNotifications.this),
                        new String[] { Widgets.ACCOUNT }, Widgets.ACCOUNT + "!=-1 and (" + Widgets.LIGHTS
                                + "=1 or " + Widgets.VIBRATE + "=1 or " + Widgets.SOUND + "=1)",
                        null, null);
                if (widgets.moveToFirst()) {
                    mMyfeedleCrypto = MyfeedleCrypto.getInstance(getApplicationContext());
                    HttpClient httpClient = MyfeedleHttpClient.getThreadSafeClient(getApplicationContext());
                    while (!widgets.isAfterLast()) {
                        long accountId = widgets.getLong(0);
                        ArrayList<String> notificationSids = new ArrayList<String>();
                        Cursor account = getContentResolver().query(
                                Accounts.getContentUri(MyfeedleNotifications.this),
                                new String[] { Accounts.TOKEN, Accounts.SECRET, Accounts.SERVICE,
                                        Accounts.SID },
                                Accounts._ID + "=?", new String[] { Long.toString(accountId) }, null);
                        if (account.moveToFirst()) {
                            // for each account, for each notification, check for updates
                            // if there are no updates past 24hrs and cleared, delete
                            String token = mMyfeedleCrypto.Decrypt(account.getString(0));
                            String secret = mMyfeedleCrypto.Decrypt(account.getString(1));
                            int service = account.getInt(2);
                            String accountEsid = mMyfeedleCrypto.Decrypt(account.getString(3));
                            mSimpleDateFormat = null;
                            if (service == TWITTER) {
                                Cursor currentNotifications = getContentResolver().query(
                                        Notifications.getContentUri(MyfeedleNotifications.this),
                                        new String[] { Notifications.SID }, Notifications.ACCOUNT + "=?",
                                        new String[] { Long.toString(accountId) }, null);
                                // loop over notifications
                                if (currentNotifications.moveToFirst()) {
                                    // store sids, to avoid duplicates when requesting the latest feed
                                    String sid = mMyfeedleCrypto.Decrypt(currentNotifications.getString(0));
                                    if (!notificationSids.contains(sid)) {
                                        notificationSids.add(sid);
                                    }
                                }
                                currentNotifications.close();
                                // limit to newest status
                                MyfeedleOAuth myfeedleOAuth = new MyfeedleOAuth(TWITTER_KEY, TWITTER_SECRET,
                                        token, secret);
                                String last_sid = null;
                                Cursor last_status = getContentResolver().query(
                                        Statuses.getContentUri(MyfeedleNotifications.this),
                                        new String[] { Statuses.SID }, Statuses.ACCOUNT + "=?",
                                        new String[] { Long.toString(accountId) },
                                        Statuses.CREATED + " ASC LIMIT 1");
                                if (last_status.moveToFirst()) {
                                    last_sid = mMyfeedleCrypto.Decrypt(last_status.getString(0));
                                }
                                last_status.close();
                                // get all mentions since the oldest status for this account
                                String response = MyfeedleHttpClient.httpResponse(httpClient,
                                        myfeedleOAuth.getSignedRequest(
                                                new HttpGet(String.format(TWITTER_MENTIONS, TWITTER_BASE_URL,
                                                        last_sid != null
                                                                ? String.format(TWITTER_SINCE_ID, last_sid)
                                                                : ""))));
                                if (response != null) {
                                    try {
                                        JSONArray comments = new JSONArray(response);
                                        for (int i = 0, i2 = comments.length(); i < i2; i++) {
                                            JSONObject comment = comments.getJSONObject(i);
                                            JSONObject user = comment.getJSONObject(Suser);
                                            if (!user.getString(Sid).equals(accountEsid)
                                                    && !notificationSids.contains(comment.getString(Sid))) {
                                                String friend = user.getString(Sname);
                                                addNotification(comment.getString(Sid), user.getString(Sid),
                                                        friend, comment.getString("text"),
                                                        parseDate(comment.getString("created_at"),
                                                                TWITTER_DATE_FORMAT),
                                                        accountId, friend + " mentioned you on Twitter");
                                            }
                                        }
                                    } catch (JSONException e) {
                                        Log.e(TAG, service + ":" + e.toString());
                                    }
                                }
                            } else if (service == IDENTICA) {
                                Cursor currentNotifications = getContentResolver().query(
                                        Notifications.getContentUri(MyfeedleNotifications.this),
                                        new String[] { Notifications.SID }, Notifications.ACCOUNT + "=?",
                                        new String[] { Long.toString(accountId) }, null);
                                // loop over notifications
                                if (currentNotifications.moveToFirst()) {
                                    // store sids, to avoid duplicates when requesting the latest feed
                                    String sid = mMyfeedleCrypto.Decrypt(currentNotifications.getString(0));
                                    if (!notificationSids.contains(sid)) {
                                        notificationSids.add(sid);
                                    }
                                }
                                currentNotifications.close();
                                // limit to newest status
                                MyfeedleOAuth myfeedleOAuth = new MyfeedleOAuth(IDENTICA_KEY, IDENTICA_SECRET,
                                        token, secret);
                                String last_sid = null;
                                Cursor last_status = getContentResolver().query(
                                        Statuses.getContentUri(MyfeedleNotifications.this),
                                        new String[] { Statuses.SID }, Statuses.ACCOUNT + "=?",
                                        new String[] { Long.toString(accountId) },
                                        Statuses.CREATED + " ASC LIMIT 1");
                                if (last_status.moveToFirst()) {
                                    last_sid = mMyfeedleCrypto.Decrypt(last_status.getString(0));
                                }
                                last_status.close();
                                // get all mentions since the oldest status for this account
                                String response = MyfeedleHttpClient.httpResponse(httpClient,
                                        myfeedleOAuth.getSignedRequest(
                                                new HttpGet(String.format(IDENTICA_MENTIONS, IDENTICA_BASE_URL,
                                                        last_sid != null
                                                                ? String.format(IDENTICA_SINCE_ID, last_sid)
                                                                : ""))));
                                if (response != null) {
                                    try {
                                        JSONArray comments = new JSONArray(response);
                                        for (int i = 0, i2 = comments.length(); i < i2; i++) {
                                            JSONObject comment = comments.getJSONObject(i);
                                            JSONObject user = comment.getJSONObject(Suser);
                                            if (!user.getString(Sid).equals(accountEsid)
                                                    && !notificationSids.contains(comment.getString(Sid))) {
                                                String friend = user.getString(Sname);
                                                addNotification(comment.getString(Sid), user.getString(Sid),
                                                        friend, comment.getString("text"),
                                                        parseDate(comment.getString("created_at"),
                                                                TWITTER_DATE_FORMAT),
                                                        accountId, friend + " mentioned you on Identi.ca");
                                            }
                                        }
                                    } catch (JSONException e) {
                                        Log.e(TAG, service + ":" + e.toString());
                                    }
                                }
                            } else {
                                Cursor currentNotifications = getContentResolver().query(
                                        Notifications.getContentUri(MyfeedleNotifications.this),
                                        new String[] { Notifications._ID, Notifications.SID,
                                                Notifications.UPDATED, Notifications.CLEARED,
                                                Notifications.ESID },
                                        Notifications.ACCOUNT + "=?", new String[] { Long.toString(accountId) },
                                        null);
                                if (currentNotifications.moveToFirst()) {
                                    String response;
                                    MyfeedleOAuth myfeedleOAuth;
                                    switch (service) {
                                    case FACEBOOK:
                                        // loop over notifications
                                        while (!currentNotifications.isAfterLast()) {
                                            long notificationId = currentNotifications.getLong(0);
                                            String sid = mMyfeedleCrypto
                                                    .Decrypt(currentNotifications.getString(1));
                                            long updated = currentNotifications.getLong(2);
                                            boolean cleared = currentNotifications.getInt(3) == 1;
                                            // store sids, to avoid duplicates when requesting the latest feed
                                            if (!notificationSids.contains(sid)) {
                                                notificationSids.add(sid);
                                            }
                                            // get comments for current notifications
                                            if ((response = MyfeedleHttpClient.httpResponse(httpClient,
                                                    new HttpGet(
                                                            String.format(FACEBOOK_COMMENTS, FACEBOOK_BASE_URL,
                                                                    sid, Saccess_token, token)))) != null) {
                                                // check for a newer post, if it's the user's own, then set CLEARED=0
                                                try {
                                                    JSONArray comments = new JSONObject(response)
                                                            .getJSONArray(Sdata);
                                                    int i2 = comments.length();
                                                    if (i2 > 0) {
                                                        for (int i = 0; i < i2; i++) {
                                                            JSONObject comment = comments.getJSONObject(i);
                                                            long created_time = comment.getLong(Screated_time)
                                                                    * 1000;
                                                            if (created_time > updated) {
                                                                // new comment
                                                                ContentValues values = new ContentValues();
                                                                values.put(Notifications.UPDATED, created_time);
                                                                JSONObject from = comment.getJSONObject(Sfrom);
                                                                if (accountEsid.equals(from.getString(Sid))) {
                                                                    // user's own comment, clear the notification
                                                                    values.put(Notifications.CLEARED, 1);
                                                                } else if (cleared) {
                                                                    values.put(Notifications.NOTIFICATION,
                                                                            String.format(getString(
                                                                                    R.string.friendcommented),
                                                                                    from.getString(Sname)));
                                                                    values.put(Notifications.CLEARED, 0);
                                                                } else {
                                                                    values.put(Notifications.NOTIFICATION,
                                                                            String.format(getString(
                                                                                    R.string.friendcommented),
                                                                                    from.getString(Sname)
                                                                                            + " and others"));
                                                                }
                                                                getContentResolver().update(
                                                                        Notifications.getContentUri(
                                                                                MyfeedleNotifications.this),
                                                                        values, Notifications._ID + "=?",
                                                                        new String[] { Long
                                                                                .toString(notificationId) });
                                                            }
                                                        }
                                                    }
                                                } catch (JSONException e) {
                                                    Log.e(TAG, service + ":" + e.toString());
                                                }
                                            }
                                            currentNotifications.moveToNext();
                                        }
                                        // check the latest feed
                                        if ((response = MyfeedleHttpClient.httpResponse(httpClient,
                                                new HttpGet(String.format(FACEBOOK_HOME, FACEBOOK_BASE_URL,
                                                        Saccess_token, token)))) != null) {
                                            try {
                                                JSONArray jarr = new JSONObject(response).getJSONArray(Sdata);
                                                // if there are updates, clear the cache
                                                int d2 = jarr.length();
                                                if (d2 > 0) {
                                                    for (int d = 0; d < d2; d++) {
                                                        JSONObject o = jarr.getJSONObject(d);
                                                        String sid = o.getString(Sid);
                                                        // if already notified, ignore
                                                        if (!notificationSids.contains(sid)) {
                                                            // only parse status types, not photo, video or link
                                                            if (o.has(Stype) && o.has(Sfrom)) {
                                                                JSONObject f = o.getJSONObject(Sfrom);
                                                                if (f.has(Sname) && f.has(Sid)) {
                                                                    String notification = null;
                                                                    String esid = f.getString(Sid);
                                                                    String friend = f.getString(Sname);
                                                                    if (o.has(Sto)) {
                                                                        // handle wall messages from one friend to another
                                                                        JSONObject t = o.getJSONObject(Sto);
                                                                        if (t.has(Sdata)) {
                                                                            JSONObject n = t.getJSONArray(Sdata)
                                                                                    .getJSONObject(0);
                                                                            if (n.has(Sname)) {
                                                                                if (n.has(Sid) && (n
                                                                                        .getString(Sid)
                                                                                        .equals(accountEsid))) {
                                                                                    notification = String
                                                                                            .format(getString(
                                                                                                    R.string.friendcommented),
                                                                                                    friend);
                                                                                }
                                                                            }
                                                                        }
                                                                    }
                                                                    int commentCount = 0;
                                                                    if (o.has(Scomments)) {
                                                                        JSONObject jo = o
                                                                                .getJSONObject(Scomments);
                                                                        if (jo.has(Sdata)) {
                                                                            JSONArray comments = jo
                                                                                    .getJSONArray(Sdata);
                                                                            commentCount = comments.length();
                                                                            // notifications
                                                                            if ((sid != null)
                                                                                    && (commentCount > 0)) {
                                                                                // default hasCommented to whether or not these comments are for the own user's status
                                                                                boolean hasCommented = notification != null
                                                                                        || esid.equals(
                                                                                                accountEsid);
                                                                                for (int c2 = 0; c2 < commentCount; c2++) {
                                                                                    JSONObject c3 = comments
                                                                                            .getJSONObject(c2);
                                                                                    if (c3.has(Sfrom)) {
                                                                                        JSONObject c4 = c3
                                                                                                .getJSONObject(
                                                                                                        Sfrom);
                                                                                        if (c4.getString(Sid)
                                                                                                .equals(accountEsid)) {
                                                                                            if (!hasCommented) {
                                                                                                // the user has commented on this thread, notify any updates
                                                                                                hasCommented = true;
                                                                                            }
                                                                                            // clear any notifications, as the user is already aware
                                                                                            if (notification != null) {
                                                                                                notification = null;
                                                                                            }
                                                                                        } else if (hasCommented) {
                                                                                            // don't notify about user's own comments
                                                                                            // send the parent comment sid
                                                                                            notification = String
                                                                                                    .format(getString(
                                                                                                            R.string.friendcommented),
                                                                                                            c4.getString(
                                                                                                                    Sname));
                                                                                        }
                                                                                    }
                                                                                }
                                                                            }
                                                                        }
                                                                    }
                                                                    if (notification != null) {
                                                                        String message = o.has(Smessage)
                                                                                ? o.getString(Smessage)
                                                                                : null;
                                                                        if (!o.getString(Stype).equals(Sstatus)
                                                                                && o.has(Slink)) {
                                                                            message = message == null
                                                                                    ? "[" + o.getString(Stype)
                                                                                            + "]"
                                                                                    : "[" + o.getString(Stype)
                                                                                            + "]";
                                                                        }
                                                                        // new notification
                                                                        addNotification(sid, esid, friend,
                                                                                message,
                                                                                o.getLong(Screated_time) * 1000,
                                                                                accountId, notification);
                                                                    }
                                                                }
                                                            }
                                                        }
                                                    }
                                                }
                                            } catch (JSONException e) {
                                                Log.e(TAG, service + ":" + e.toString());
                                            }
                                        }
                                        break;
                                    case MYSPACE:
                                        myfeedleOAuth = new MyfeedleOAuth(MYSPACE_KEY, MYSPACE_SECRET, token,
                                                secret);
                                        // loop over notifications
                                        while (!currentNotifications.isAfterLast()) {
                                            long notificationId = currentNotifications.getLong(0);
                                            String sid = mMyfeedleCrypto
                                                    .Decrypt(currentNotifications.getString(1));
                                            long updated = currentNotifications.getLong(2);
                                            boolean cleared = currentNotifications.getInt(3) == 1;
                                            String esid = mMyfeedleCrypto
                                                    .Decrypt(currentNotifications.getString(4));
                                            // store sids, to avoid duplicates when requesting the latest feed
                                            if (!notificationSids.contains(sid)) {
                                                notificationSids.add(sid);
                                            }
                                            // get comments for current notifications
                                            if ((response = MyfeedleHttpClient.httpResponse(httpClient,
                                                    myfeedleOAuth.getSignedRequest(new HttpGet(
                                                            String.format(MYSPACE_URL_STATUSMOODCOMMENTS,
                                                                    MYSPACE_BASE_URL, esid, sid))))) != null) {
                                                // check for a newer post, if it's the user's own, then set CLEARED=0
                                                try {
                                                    JSONArray comments = new JSONObject(response)
                                                            .getJSONArray(Sentry);
                                                    int i2 = comments.length();
                                                    if (i2 > 0) {
                                                        for (int i = 0; i < i2; i++) {
                                                            JSONObject comment = comments.getJSONObject(i);
                                                            long created_time = parseDate(
                                                                    comment.getString(SpostedDate),
                                                                    MYSPACE_DATE_FORMAT);
                                                            if (created_time > updated) {
                                                                // new comment
                                                                ContentValues values = new ContentValues();
                                                                values.put(Notifications.UPDATED, created_time);
                                                                JSONObject author = comment
                                                                        .getJSONObject(Sauthor);
                                                                if (accountEsid.equals(author.getString(Sid))) {
                                                                    // user's own comment, clear the notification
                                                                    values.put(Notifications.CLEARED, 1);
                                                                } else if (cleared) {
                                                                    values.put(Notifications.NOTIFICATION,
                                                                            String.format(getString(
                                                                                    R.string.friendcommented),
                                                                                    comment.getString(
                                                                                            SdisplayName)));
                                                                    values.put(Notifications.CLEARED, 0);
                                                                } else {
                                                                    values.put(Notifications.NOTIFICATION,
                                                                            String.format(getString(
                                                                                    R.string.friendcommented),
                                                                                    comment.getString(
                                                                                            SdisplayName)
                                                                                            + " and others"));
                                                                }
                                                                getContentResolver().update(
                                                                        Notifications.getContentUri(
                                                                                MyfeedleNotifications.this),
                                                                        values, Notifications._ID + "=?",
                                                                        new String[] { Long
                                                                                .toString(notificationId) });
                                                            }
                                                        }
                                                    }
                                                } catch (JSONException e) {
                                                    Log.e(TAG, service + ":" + e.toString());
                                                }
                                            }
                                            currentNotifications.moveToNext();
                                        }
                                        // check the latest feed
                                        if ((response = MyfeedleHttpClient
                                                .httpResponse(httpClient,
                                                        myfeedleOAuth.getSignedRequest(
                                                                new HttpGet(String.format(MYSPACE_HISTORY,
                                                                        MYSPACE_BASE_URL))))) != null) {
                                            try {
                                                JSONArray jarr = new JSONObject(response).getJSONArray(Sentry);
                                                // if there are updates, clear the cache
                                                int d2 = jarr.length();
                                                if (d2 > 0) {
                                                    for (int d = 0; d < d2; d++) {
                                                        JSONObject o = jarr.getJSONObject(d);
                                                        String sid = o.getString(SstatusId);
                                                        // if already notified, ignore
                                                        if (!notificationSids.contains(sid)) {
                                                            if (o.has(Sauthor) && o.has(SrecentComments)) {
                                                                JSONObject f = o.getJSONObject(Sauthor);
                                                                if (f.has(SdisplayName) && f.has(Sid)) {
                                                                    String notification = null;
                                                                    String esid = f.getString(Sid);
                                                                    String friend = f.getString(SdisplayName);
                                                                    JSONArray comments = o
                                                                            .getJSONArray(SrecentComments);
                                                                    int commentCount = comments.length();
                                                                    // notifications
                                                                    if ((sid != null) && (commentCount > 0)) {
                                                                        // default hasCommented to whether or not these comments are for the own user's status
                                                                        boolean hasCommented = notification != null
                                                                                || esid.equals(accountEsid);
                                                                        for (int c2 = 0; c2 < commentCount; c2++) {
                                                                            JSONObject c3 = comments
                                                                                    .getJSONObject(c2);
                                                                            if (c3.has(Sauthor)) {
                                                                                JSONObject c4 = c3
                                                                                        .getJSONObject(Sauthor);
                                                                                if (c4.getString(Sid)
                                                                                        .equals(accountEsid)) {
                                                                                    if (!hasCommented) {
                                                                                        // the user has commented on this thread, notify any updates
                                                                                        hasCommented = true;
                                                                                    }
                                                                                    // clear any notifications, as the user is already aware
                                                                                    if (notification != null) {
                                                                                        notification = null;
                                                                                    }
                                                                                } else if (hasCommented) {
                                                                                    // don't notify about user's own comments
                                                                                    // send the parent comment sid
                                                                                    notification = String
                                                                                            .format(getString(
                                                                                                    R.string.friendcommented),
                                                                                                    c4.getString(
                                                                                                            SdisplayName));
                                                                                }
                                                                            }
                                                                        }
                                                                    }
                                                                    if (notification != null) {
                                                                        // new notification
                                                                        addNotification(sid, esid, friend,
                                                                                o.getString(Sstatus),
                                                                                parseDate(o.getString(
                                                                                        "moodStatusLastUpdated"),
                                                                                        MYSPACE_DATE_FORMAT),
                                                                                accountId, notification);
                                                                    }
                                                                }
                                                            }
                                                        }
                                                    }
                                                }
                                            } catch (JSONException e) {
                                                Log.e(TAG, service + ":" + e.toString());
                                            }
                                        }
                                        break;
                                    case FOURSQUARE:
                                        // loop over notifications
                                        while (!currentNotifications.isAfterLast()) {
                                            long notificationId = currentNotifications.getLong(0);
                                            String sid = mMyfeedleCrypto
                                                    .Decrypt(currentNotifications.getString(1));
                                            long updated = currentNotifications.getLong(2);
                                            boolean cleared = currentNotifications.getInt(3) == 1;
                                            // store sids, to avoid duplicates when requesting the latest feed
                                            if (!notificationSids.contains(sid)) {
                                                notificationSids.add(sid);
                                            }
                                            // get comments for current notifications
                                            if ((response = MyfeedleHttpClient.httpResponse(httpClient,
                                                    new HttpGet(String.format(FOURSQUARE_GET_CHECKIN,
                                                            FOURSQUARE_BASE_URL, sid, token)))) != null) {
                                                // check for a newer post, if it's the user's own, then set CLEARED=0
                                                try {
                                                    JSONArray comments = new JSONObject(response)
                                                            .getJSONObject(Sresponse).getJSONObject(Scheckin)
                                                            .getJSONObject(Scomments).getJSONArray(Sitems);
                                                    int i2 = comments.length();
                                                    if (i2 > 0) {
                                                        for (int i = 0; i < i2; i++) {
                                                            JSONObject comment = comments.getJSONObject(i);
                                                            long created_time = comment.getLong(ScreatedAt)
                                                                    * 1000;
                                                            if (created_time > updated) {
                                                                // new comment
                                                                ContentValues values = new ContentValues();
                                                                values.put(Notifications.UPDATED, created_time);
                                                                JSONObject user = comment.getJSONObject(Suser);
                                                                if (accountEsid.equals(user.getString(Sid))) {
                                                                    // user's own comment, clear the notification
                                                                    values.put(Notifications.CLEARED, 1);
                                                                } else if (cleared) {
                                                                    values.put(Notifications.NOTIFICATION,
                                                                            String.format(getString(
                                                                                    R.string.friendcommented),
                                                                                    user.getString(SfirstName)
                                                                                            + " "
                                                                                            + user.getString(
                                                                                                    SlastName)));
                                                                    values.put(Notifications.CLEARED, 0);
                                                                } else {
                                                                    values.put(Notifications.NOTIFICATION,
                                                                            String.format(getString(
                                                                                    R.string.friendcommented),
                                                                                    user.getString(SfirstName)
                                                                                            + " "
                                                                                            + user.getString(
                                                                                                    SlastName)
                                                                                            + " and others"));
                                                                }
                                                                getContentResolver().update(
                                                                        Notifications.getContentUri(
                                                                                MyfeedleNotifications.this),
                                                                        values, Notifications._ID + "=?",
                                                                        new String[] { Long
                                                                                .toString(notificationId) });
                                                            }
                                                        }
                                                    }
                                                } catch (JSONException e) {
                                                    Log.e(TAG, service + ":" + e.toString());
                                                }
                                            }
                                            currentNotifications.moveToNext();
                                        }
                                        // check the latest feed
                                        if ((response = MyfeedleHttpClient.httpResponse(httpClient,
                                                new HttpGet(String.format(FOURSQUARE_CHECKINS,
                                                        FOURSQUARE_BASE_URL, token)))) != null) {
                                            try {
                                                JSONArray jarr = new JSONObject(response)
                                                        .getJSONObject(Sresponse).getJSONArray(Srecent);
                                                // if there are updates, clear the cache
                                                int d2 = jarr.length();
                                                if (d2 > 0) {
                                                    for (int d = 0; d < d2; d++) {
                                                        JSONObject o = jarr.getJSONObject(d);
                                                        String sid = o.getString(Sid);
                                                        // if already notified, ignore
                                                        if (!notificationSids.contains(sid)) {
                                                            if (o.has(Suser) && o.has(Scomments)) {
                                                                JSONObject f = o.getJSONObject(Suser);
                                                                if (f.has(SfirstName) && f.has(SlastName)
                                                                        && f.has(Sid)) {
                                                                    String notification = null;
                                                                    String esid = f.getString(Sid);
                                                                    String friend = f.getString(SfirstName)
                                                                            + " " + f.getString(SlastName);
                                                                    JSONArray comments = o
                                                                            .getJSONArray(Scomments);
                                                                    int commentCount = comments.length();
                                                                    // notifications
                                                                    if (commentCount > 0) {
                                                                        // default hasCommented to whether or not these comments are for the own user's status
                                                                        boolean hasCommented = notification != null
                                                                                || esid.equals(accountEsid);
                                                                        for (int c2 = 0; c2 < commentCount; c2++) {
                                                                            JSONObject c3 = comments
                                                                                    .getJSONObject(c2);
                                                                            if (c3.has(Suser)) {
                                                                                JSONObject c4 = c3
                                                                                        .getJSONObject(Suser);
                                                                                if (c4.getString(Sid)
                                                                                        .equals(accountEsid)) {
                                                                                    if (!hasCommented) {
                                                                                        // the user has commented on this thread, notify any updates
                                                                                        hasCommented = true;
                                                                                    }
                                                                                    // clear any notifications, as the user is already aware
                                                                                    if (notification != null) {
                                                                                        notification = null;
                                                                                    }
                                                                                } else if (hasCommented) {
                                                                                    // don't notify about user's own comments
                                                                                    // send the parent comment sid
                                                                                    notification = String
                                                                                            .format(getString(
                                                                                                    R.string.friendcommented),
                                                                                                    c4.getString(
                                                                                                            SfirstName)
                                                                                                            + " "
                                                                                                            + c4.getString(
                                                                                                                    SlastName));
                                                                                }
                                                                            }
                                                                        }
                                                                    }
                                                                    if (notification != null) {
                                                                        String message = "";
                                                                        if (o.has(Sshout)) {
                                                                            message = o.getString(Sshout)
                                                                                    + "\n";
                                                                        }
                                                                        if (o.has(Svenue)) {
                                                                            JSONObject venue = o
                                                                                    .getJSONObject(Svenue);
                                                                            if (venue.has(Sname)) {
                                                                                message += "@" + venue
                                                                                        .getString(Sname);
                                                                            }
                                                                        }
                                                                        // new notification
                                                                        addNotification(sid, esid, friend,
                                                                                message,
                                                                                o.getLong(ScreatedAt) * 1000,
                                                                                accountId, notification);
                                                                    }
                                                                }
                                                            }
                                                        }
                                                    }
                                                }
                                            } catch (JSONException e) {
                                                Log.e(TAG, service + ":" + e.toString());
                                            }
                                        }
                                        break;
                                    case LINKEDIN:
                                        myfeedleOAuth = new MyfeedleOAuth(LINKEDIN_KEY, LINKEDIN_SECRET, token,
                                                secret);
                                        // loop over notifications
                                        while (!currentNotifications.isAfterLast()) {
                                            long notificationId = currentNotifications.getLong(0);
                                            String sid = mMyfeedleCrypto
                                                    .Decrypt(currentNotifications.getString(1));
                                            long updated = currentNotifications.getLong(2);
                                            boolean cleared = currentNotifications.getInt(3) == 1;
                                            // store sids, to avoid duplicates when requesting the latest feed
                                            if (!notificationSids.contains(sid)) {
                                                notificationSids.add(sid);
                                            }
                                            // get comments for current notifications
                                            HttpGet httpGet = new HttpGet(String
                                                    .format(LINKEDIN_UPDATE_COMMENTS, LINKEDIN_BASE_URL, sid));
                                            for (String[] header : LINKEDIN_HEADERS)
                                                httpGet.setHeader(header[0], header[1]);
                                            if ((response = MyfeedleHttpClient.httpResponse(httpClient,
                                                    myfeedleOAuth.getSignedRequest(httpGet))) != null) {
                                                // check for a newer post, if it's the user's own, then set CLEARED=0
                                                try {
                                                    JSONObject jsonResponse = new JSONObject(response);
                                                    if (jsonResponse.has(S_total)
                                                            && (jsonResponse.getInt(S_total) != 0)) {
                                                        JSONArray comments = jsonResponse.getJSONArray(Svalues);
                                                        int i2 = comments.length();
                                                        if (i2 > 0) {
                                                            for (int i = 0; i < i2; i++) {
                                                                JSONObject comment = comments.getJSONObject(i);
                                                                long created_time = comment.getLong(Stimestamp);
                                                                if (created_time > updated) {
                                                                    // new comment
                                                                    ContentValues values = new ContentValues();
                                                                    values.put(Notifications.UPDATED,
                                                                            created_time);
                                                                    JSONObject person = comment
                                                                            .getJSONObject(Sperson);
                                                                    if (accountEsid
                                                                            .equals(person.getString(Sid))) {
                                                                        // user's own comment, clear the notification
                                                                        values.put(Notifications.CLEARED, 1);
                                                                    } else if (cleared) {
                                                                        values.put(Notifications.NOTIFICATION,
                                                                                String.format(getString(
                                                                                        R.string.friendcommented),
                                                                                        person.getString(
                                                                                                SfirstName)
                                                                                                + " "
                                                                                                + person.getString(
                                                                                                        SlastName)));
                                                                        values.put(Notifications.CLEARED, 0);
                                                                    } else {
                                                                        values.put(Notifications.NOTIFICATION,
                                                                                String.format(getString(
                                                                                        R.string.friendcommented),
                                                                                        person.getString(
                                                                                                SfirstName)
                                                                                                + " "
                                                                                                + person.getString(
                                                                                                        SlastName)
                                                                                                + " and others"));
                                                                    }
                                                                    getContentResolver().update(
                                                                            Notifications.getContentUri(
                                                                                    MyfeedleNotifications.this),
                                                                            values, Notifications._ID + "=?",
                                                                            new String[] { Long.toString(
                                                                                    notificationId) });
                                                                }
                                                            }
                                                        }
                                                    }
                                                } catch (JSONException e) {
                                                    Log.e(TAG, service + ":" + e.toString());
                                                }
                                            }
                                            currentNotifications.moveToNext();
                                        }
                                        // check the latest feed
                                        HttpGet httpGet = new HttpGet(
                                                String.format(LINKEDIN_UPDATES, LINKEDIN_BASE_URL));
                                        for (String[] header : LINKEDIN_HEADERS) {
                                            httpGet.setHeader(header[0], header[1]);
                                        }
                                        if ((response = MyfeedleHttpClient.httpResponse(httpClient,
                                                myfeedleOAuth.getSignedRequest(httpGet))) != null) {
                                            try {
                                                JSONArray jarr = new JSONObject(response).getJSONArray(Svalues);
                                                // if there are updates, clear the cache
                                                int d2 = jarr.length();
                                                if (d2 > 0) {
                                                    for (int d = 0; d < d2; d++) {
                                                        JSONObject o = jarr.getJSONObject(d);
                                                        String sid = o.getString(SupdateKey);
                                                        // if already notified, ignore
                                                        if (!notificationSids.contains(sid)) {
                                                            String updateType = o.getString(SupdateType);
                                                            JSONObject updateContent = o
                                                                    .getJSONObject(SupdateContent);
                                                            if (LinkedIn_UpdateTypes.contains(updateType)
                                                                    && updateContent.has(Sperson)) {
                                                                JSONObject f = updateContent
                                                                        .getJSONObject(Sperson);
                                                                if (f.has(SfirstName) && f.has(SlastName)
                                                                        && f.has(Sid)
                                                                        && o.has(SupdateComments)) {
                                                                    JSONObject updateComments = o
                                                                            .getJSONObject(SupdateComments);
                                                                    if (updateComments.has(Svalues)) {
                                                                        String notification = null;
                                                                        String esid = f.getString(Sid);
                                                                        JSONArray comments = updateComments
                                                                                .getJSONArray(Svalues);
                                                                        int commentCount = comments.length();
                                                                        // notifications
                                                                        if (commentCount > 0) {
                                                                            // default hasCommented to whether or not these comments are for the own user's status
                                                                            boolean hasCommented = notification != null
                                                                                    || esid.equals(accountEsid);
                                                                            for (int c2 = 0; c2 < commentCount; c2++) {
                                                                                JSONObject c3 = comments
                                                                                        .getJSONObject(c2);
                                                                                if (c3.has(Sperson)) {
                                                                                    JSONObject c4 = c3
                                                                                            .getJSONObject(
                                                                                                    Sperson);
                                                                                    if (c4.getString(Sid)
                                                                                            .equals(accountEsid)) {
                                                                                        if (!hasCommented) {
                                                                                            // the user has commented on this thread, notify any updates
                                                                                            hasCommented = true;
                                                                                        }
                                                                                        // clear any notifications, as the user is already aware
                                                                                        if (notification != null) {
                                                                                            notification = null;
                                                                                        }
                                                                                    } else if (hasCommented) {
                                                                                        // don't notify about user's own comments
                                                                                        // send the parent comment sid
                                                                                        notification = String
                                                                                                .format(getString(
                                                                                                        R.string.friendcommented),
                                                                                                        c4.getString(
                                                                                                                SfirstName)
                                                                                                                + " "
                                                                                                                + c4.getString(
                                                                                                                        SlastName));
                                                                                    }
                                                                                }
                                                                            }
                                                                        }
                                                                        if (notification != null) {
                                                                            String update = LinkedIn_UpdateTypes
                                                                                    .getMessage(updateType);
                                                                            if (LinkedIn_UpdateTypes.APPS.name()
                                                                                    .equals(updateType)) {
                                                                                if (f.has(SpersonActivities)) {
                                                                                    JSONObject personActivities = f
                                                                                            .getJSONObject(
                                                                                                    SpersonActivities);
                                                                                    if (personActivities
                                                                                            .has(Svalues)) {
                                                                                        JSONArray updates = personActivities
                                                                                                .getJSONArray(
                                                                                                        Svalues);
                                                                                        for (int u = 0, u2 = updates
                                                                                                .length(); u < u2; u++) {
                                                                                            update += updates
                                                                                                    .getJSONObject(
                                                                                                            u)
                                                                                                    .getString(
                                                                                                            Sbody);
                                                                                            if (u < (updates
                                                                                                    .length()
                                                                                                    - 1))
                                                                                                update += ", ";
                                                                                        }
                                                                                    }
                                                                                }
                                                                            } else if (LinkedIn_UpdateTypes.CONN
                                                                                    .name()
                                                                                    .equals(updateType)) {
                                                                                if (f.has(Sconnections)) {
                                                                                    JSONObject connections = f
                                                                                            .getJSONObject(
                                                                                                    Sconnections);
                                                                                    if (connections
                                                                                            .has(Svalues)) {
                                                                                        JSONArray updates = connections
                                                                                                .getJSONArray(
                                                                                                        Svalues);
                                                                                        for (int u = 0, u2 = updates
                                                                                                .length(); u < u2; u++) {
                                                                                            update += updates
                                                                                                    .getJSONObject(
                                                                                                            u)
                                                                                                    .getString(
                                                                                                            SfirstName)
                                                                                                    + " "
                                                                                                    + updates
                                                                                                            .getJSONObject(
                                                                                                                    u)
                                                                                                            .getString(
                                                                                                                    SlastName);
                                                                                            if (u < (updates
                                                                                                    .length()
                                                                                                    - 1))
                                                                                                update += ", ";
                                                                                        }
                                                                                    }
                                                                                }
                                                                            } else if (LinkedIn_UpdateTypes.JOBP
                                                                                    .name()
                                                                                    .equals(updateType)) {
                                                                                if (updateContent.has(Sjob)
                                                                                        && updateContent
                                                                                                .getJSONObject(
                                                                                                        Sjob)
                                                                                                .has(Sposition)
                                                                                        && updateContent
                                                                                                .getJSONObject(
                                                                                                        Sjob)
                                                                                                .getJSONObject(
                                                                                                        Sposition)
                                                                                                .has(Stitle))
                                                                                    update += updateContent
                                                                                            .getJSONObject(Sjob)
                                                                                            .getJSONObject(
                                                                                                    Sposition)
                                                                                            .getString(Stitle);
                                                                            } else if (LinkedIn_UpdateTypes.JGRP
                                                                                    .name()
                                                                                    .equals(updateType)) {
                                                                                if (f.has(SmemberGroups)) {
                                                                                    JSONObject memberGroups = f
                                                                                            .getJSONObject(
                                                                                                    SmemberGroups);
                                                                                    if (memberGroups
                                                                                            .has(Svalues)) {
                                                                                        JSONArray updates = memberGroups
                                                                                                .getJSONArray(
                                                                                                        Svalues);
                                                                                        for (int u = 0, u2 = updates
                                                                                                .length(); u < u2; u++) {
                                                                                            update += updates
                                                                                                    .getJSONObject(
                                                                                                            u)
                                                                                                    .getString(
                                                                                                            Sname);
                                                                                            if (u < (updates
                                                                                                    .length()
                                                                                                    - 1))
                                                                                                update += ", ";
                                                                                        }
                                                                                    }
                                                                                }
                                                                            } else if (LinkedIn_UpdateTypes.PREC
                                                                                    .name()
                                                                                    .equals(updateType)) {
                                                                                if (f.has(
                                                                                        SrecommendationsGiven)) {
                                                                                    JSONObject recommendationsGiven = f
                                                                                            .getJSONObject(
                                                                                                    SrecommendationsGiven);
                                                                                    if (recommendationsGiven
                                                                                            .has(Svalues)) {
                                                                                        JSONArray updates = recommendationsGiven
                                                                                                .getJSONArray(
                                                                                                        Svalues);
                                                                                        for (int u = 0, u2 = updates
                                                                                                .length(); u < u2; u++) {
                                                                                            JSONObject recommendation = updates
                                                                                                    .getJSONObject(
                                                                                                            u);
                                                                                            JSONObject recommendee = recommendation
                                                                                                    .getJSONObject(
                                                                                                            Srecommendee);
                                                                                            if (recommendee.has(
                                                                                                    SfirstName))
                                                                                                update += recommendee
                                                                                                        .getString(
                                                                                                                SfirstName);
                                                                                            if (recommendee.has(
                                                                                                    SlastName))
                                                                                                update += recommendee
                                                                                                        .getString(
                                                                                                                SlastName);
                                                                                            if (recommendation
                                                                                                    .has(SrecommendationSnippet))
                                                                                                update += ":"
                                                                                                        + recommendation
                                                                                                                .getString(
                                                                                                                        SrecommendationSnippet);
                                                                                            if (u < (updates
                                                                                                    .length()
                                                                                                    - 1))
                                                                                                update += ", ";
                                                                                        }
                                                                                    }
                                                                                }
                                                                            } else if (LinkedIn_UpdateTypes.SHAR
                                                                                    .name().equals(updateType)
                                                                                    && f.has(ScurrentShare)) {
                                                                                JSONObject currentShare = f
                                                                                        .getJSONObject(
                                                                                                ScurrentShare);
                                                                                if (currentShare.has(Scomment))
                                                                                    update = currentShare
                                                                                            .getString(
                                                                                                    Scomment);
                                                                            }
                                                                            // new notification
                                                                            addNotification(sid, esid,
                                                                                    f.getString(SfirstName)
                                                                                            + " "
                                                                                            + f.getString(
                                                                                                    SlastName),
                                                                                    update,
                                                                                    o.getLong(Stimestamp),
                                                                                    accountId, notification);
                                                                        }
                                                                    }
                                                                }
                                                            }
                                                        }
                                                    }
                                                }
                                            } catch (JSONException e) {
                                                Log.e(TAG, service + ":" + e.toString());
                                            }
                                        }
                                        break;
                                    case GOOGLEPLUS:
                                        // get new access token, need different request here
                                        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", token));
                                        httpParams.add(new BasicNameValuePair("grant_type", "refresh_token"));
                                        try {
                                            httpPost.setEntity(new UrlEncodedFormEntity(httpParams));
                                            if ((response = MyfeedleHttpClient.httpResponse(httpClient,
                                                    httpPost)) != null) {
                                                JSONObject j = new JSONObject(response);
                                                if (j.has(Saccess_token)) {
                                                    String access_token = j.getString(Saccess_token);
                                                    while (!currentNotifications.isAfterLast()) {
                                                        long notificationId = currentNotifications.getLong(0);
                                                        String sid = mMyfeedleCrypto
                                                                .Decrypt(currentNotifications.getString(1));
                                                        long updated = currentNotifications.getLong(2);
                                                        boolean cleared = currentNotifications.getInt(3) == 1;
                                                        // store sids, to avoid duplicates when requesting the latest feed
                                                        if (!notificationSids.contains(sid)) {
                                                            notificationSids.add(sid);
                                                        }
                                                        // get comments for current notifications
                                                        if ((response = MyfeedleHttpClient.httpResponse(
                                                                httpClient,
                                                                new HttpGet(String.format(GOOGLEPLUS_ACTIVITY,
                                                                        GOOGLEPLUS_BASE_URL, sid,
                                                                        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: notifications
                                                                        }
                                                                    }
                                                                }
                                                            } catch (JSONException e) {
                                                                Log.e(TAG, service + ":" + e.toString());
                                                            }
                                                        }
                                                        currentNotifications.moveToNext();
                                                    }
                                                    // get new feed
                                                    if ((response = MyfeedleHttpClient.httpResponse(httpClient,
                                                            new HttpGet(String.format(GOOGLEPLUS_ACTIVITIES,
                                                                    GOOGLEPLUS_BASE_URL, "me", "public", 20,
                                                                    access_token)))) != null) {
                                                        JSONObject r = new JSONObject(response);
                                                        if (r.has(Sitems)) {
                                                            JSONArray items = r.getJSONArray(Sitems);
                                                            for (int i1 = 0, i2 = items
                                                                    .length(); i1 < i2; i1++) {
                                                                JSONObject item = items.getJSONObject(i1);
                                                                if (item.has(Sactor) && item.has(Sobject)) {
                                                                    JSONObject actor = item
                                                                            .getJSONObject(Sactor);
                                                                    JSONObject object = item
                                                                            .getJSONObject(Sobject);
                                                                    if (item.has(Sid) && actor.has(Sid)
                                                                            && actor.has(SdisplayName)
                                                                            && item.has(Spublished)
                                                                            && object.has(Sreplies)
                                                                            && object.has(SoriginalContent)) {
                                                                        String sid = item.getString(Sid);
                                                                        String esid = actor.getString(Sid);
                                                                        String friend = actor
                                                                                .getString(SdisplayName);
                                                                        String originalContent = object
                                                                                .getString(SoriginalContent);
                                                                        if ((originalContent == null)
                                                                                || (originalContent
                                                                                        .length() == 0)) {
                                                                            originalContent = object
                                                                                    .getString(Scontent);
                                                                        }
                                                                        String photo = null;
                                                                        if (actor.has(Simage)) {
                                                                            JSONObject image = actor
                                                                                    .getJSONObject(Simage);
                                                                            if (image.has(Surl)) {
                                                                                photo = image.getString(Surl);
                                                                            }
                                                                        }
                                                                        long date = parseDate(
                                                                                item.getString(Spublished),
                                                                                GOOGLEPLUS_DATE_FORMAT);
                                                                        int commentCount = 0;
                                                                        JSONObject replies = object
                                                                                .getJSONObject(Sreplies);
                                                                        String notification = null;
                                                                        if (replies.has(StotalItems)) {
                                                                            Log.d(TAG, Sreplies + ":"
                                                                                    + replies.toString());
                                                                            commentCount = replies
                                                                                    .getInt(StotalItems);
                                                                        }
                                                                        if (notification != null) {
                                                                            // new notification
                                                                            addNotification(sid, esid, friend,
                                                                                    originalContent, date,
                                                                                    accountId, notification);
                                                                        }
                                                                    }
                                                                }
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        } catch (UnsupportedEncodingException e) {
                                            Log.e(TAG, e.toString());
                                        } catch (JSONException e) {
                                            Log.e(TAG, e.toString());
                                        }
                                        break;
                                    }
                                }
                                currentNotifications.close();
                            }
                            // remove old notifications
                            getContentResolver().delete(Notifications.getContentUri(MyfeedleNotifications.this),
                                    Notifications.CLEARED + "=1 and " + Notifications.ACCOUNT + "=? and "
                                            + Notifications.CREATED + "<?",
                                    new String[] { Long.toString(accountId),
                                            Long.toString(System.currentTimeMillis() - 86400000) });
                        }
                        account.close();
                        widgets.moveToNext();
                    }
                } else {
                    publishProgress("No notifications have been set up on any accounts.");
                }
                widgets.close();
                return false;
            } else if (arg0[0] == R.id.menu_notifications_clear_all) {
                // clear all notifications
                ContentValues values = new ContentValues();
                values.put(Notifications.CLEARED, 1);
                MyfeedleNotifications.this.getContentResolver()
                        .update(Notifications.getContentUri(MyfeedleNotifications.this), values, null, null);
                return true;
            }
            return false;
        }

        @Override
        protected void onProgressUpdate(String... messages) {
            (Toast.makeText(MyfeedleNotifications.this, messages[0], Toast.LENGTH_LONG)).show();
        }

        @Override
        protected void onPostExecute(Boolean finish) {
            if (loadingDialog.isShowing()) {
                loadingDialog.dismiss();
            }
            if (finish) {
                MyfeedleNotifications.this.finish();
            }
        }

        private void addNotification(String sid, String esid, String friend, String message, long created,
                long accountId, String notification) {
            ContentValues values = new ContentValues();
            values.put(Notifications.SID, sid);
            values.put(Notifications.ESID, esid);
            values.put(Notifications.FRIEND, friend);
            values.put(Notifications.MESSAGE, message);
            values.put(Notifications.CREATED, created);
            values.put(Notifications.ACCOUNT, accountId);
            values.put(Notifications.NOTIFICATION, notification);
            values.put(Notifications.CLEARED, 0);
            values.put(Notifications.UPDATED, created);
            getContentResolver().insert(Notifications.getContentUri(MyfeedleNotifications.this), values);
        }

        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(item.getItemId());
    return true;
    //      return super.onOptionsItemSelected(item);
}

From source file:com.eveningoutpost.dexdrip.Home.java

private void promptTextInput_old() {

    if (recognitionRunning)
        return;/*from  w  ww. jav  a  2  s. c o m*/
    recognitionRunning = true;

    final AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setTitle("Type treatment\neg: units x.x");
    // Set up the input
    final EditText input = new EditText(this);
    input.setInputType(InputType.TYPE_CLASS_TEXT);
    builder.setView(input);
    // Set up the buttons
    builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            voiceRecognitionText.setText(input.getText().toString());
            voiceRecognitionText.setVisibility(View.VISIBLE);
            last_speech_time = JoH.ts();
            naturalLanguageRecognition(input.getText().toString());

        }
    });
    builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            dialog.cancel();
        }
    });

    final AlertDialog dialog = builder.create();
    input.setOnFocusChangeListener(new View.OnFocusChangeListener() {
        @Override
        public void onFocusChange(View v, boolean hasFocus) {
            if (hasFocus) {
                if (dialog != null)
                    dialog.getWindow()
                            .setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
            }
        }
    });
    dialog.show();
    recognitionRunning = false;
}

From source file:com.citrus.sample.WalletPaymentFragment.java

private void showSendMoneyPrompt() {
    final AlertDialog.Builder alert = new AlertDialog.Builder(getActivity());
    final String message = "Send Money to Friend In A Flash";
    String positiveButtonText = "Send";

    LinearLayout linearLayout = new LinearLayout(getActivity());
    linearLayout.setOrientation(LinearLayout.VERTICAL);
    final TextView labelAmount = new TextView(getActivity());
    final EditText editAmount = new EditText(getActivity());
    final TextView labelMobileNo = new TextView(getActivity());
    final EditText editMobileNo = new EditText(getActivity());
    final TextView labelMessage = new TextView(getActivity());
    final EditText editMessage = new EditText(getActivity());
    editAmount.setSingleLine(true);//from w w w.  jav  a2 s  . c  o m
    editMobileNo.setSingleLine(true);
    editMessage.setSingleLine(true);

    labelAmount.setText("Amount");
    labelMobileNo.setText("Enter Mobile No of Friend");
    labelMessage.setText("Enter Message (Optional)");

    LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(
            LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);

    labelAmount.setLayoutParams(layoutParams);
    labelMobileNo.setLayoutParams(layoutParams);
    labelMessage.setLayoutParams(layoutParams);
    editAmount.setLayoutParams(layoutParams);
    editMobileNo.setLayoutParams(layoutParams);
    editMessage.setLayoutParams(layoutParams);

    linearLayout.addView(labelAmount);
    linearLayout.addView(editAmount);
    linearLayout.addView(labelMobileNo);
    linearLayout.addView(editMobileNo);
    linearLayout.addView(labelMessage);
    linearLayout.addView(editMessage);

    int paddingPx = Utils.getSizeInPx(getActivity(), 32);
    linearLayout.setPadding(paddingPx, paddingPx, paddingPx, paddingPx);

    editAmount.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL);
    editMobileNo.setInputType(InputType.TYPE_CLASS_NUMBER);
    alert.setTitle("Send Money In A Flash");
    alert.setMessage(message);

    alert.setView(linearLayout);
    alert.setPositiveButton(positiveButtonText, new DialogInterface.OnClickListener() {

        public void onClick(DialogInterface dialog, int whichButton) {
            String amount = editAmount.getText().toString();
            String mobileNo = editMobileNo.getText().toString();
            String message = editMessage.getText().toString();

            mCitrusClient.sendMoneyToMoblieNo(new Amount(amount), mobileNo, message,
                    new Callback<PaymentResponse>() {
                        @Override
                        public void success(PaymentResponse paymentResponse) {
                            //                        Utils.showToast(getActivity(), paymentResponse.getStatus() == CitrusResponse.Status.SUCCESSFUL ? "Sent Money Successfully." : "Failed To Send the Money");
                            ((UIActivity) getActivity()).showSnackBar(
                                    paymentResponse.getStatus() == CitrusResponse.Status.SUCCESSFUL
                                            ? "Sent Money Successfully."
                                            : "Failed To Send the Money");
                        }

                        @Override
                        public void error(CitrusError error) {
                            //                        Utils.showToast(getActivity(), error.getMessage());
                            ((UIActivity) getActivity()).showSnackBar(error.getMessage());
                        }
                    });
            // Hide the keyboard.
            InputMethodManager imm = (InputMethodManager) getActivity()
                    .getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.hideSoftInputFromWindow(editAmount.getWindowToken(), 0);
        }
    });

    alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int whichButton) {
            dialog.cancel();
        }
    });

    editAmount.requestFocus();
    alert.show();
}

From source file:de.baumann.hhsmoodle.activities.Activity_todo.java

private void setupListViewListener() {
    lvItems.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
        @Override/*from ww w.  j a  v a2 s  .  c  o m*/
        public boolean onItemLongClick(AdapterView<?> adapter, View item, final int pos, long id) {

            final String text = (String) adapter.getItemAtPosition(pos);
            // Remove the item within array at position
            items.remove(pos);
            // Refresh the adapter
            itemsAdapter.notifyDataSetChanged();
            // Return true consumes the long click event (marks it handled)
            writeItems();

            Snackbar snackbar = Snackbar.make(lvItems, R.string.todo_removed, Snackbar.LENGTH_LONG)
                    .setAction(R.string.todo_removed_back, new View.OnClickListener() {
                        @Override
                        public void onClick(View view) {
                            items.add(pos, text);
                            // Refresh the adapter
                            itemsAdapter.notifyDataSetChanged();
                            // Return true consumes the long click event (marks it handled)
                            writeItems();
                        }
                    });
            snackbar.show();

            return true;
        }
    });

    lvItems.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        public void onItemClick(AdapterView<?> adapter, View item, final int pos, long id) {

            AlertDialog.Builder builder = new AlertDialog.Builder(Activity_todo.this);
            View dialogView = View.inflate(Activity_todo.this, R.layout.dialog_edit_text_singleline, null);

            final EditText edit_title = (EditText) dialogView.findViewById(R.id.pass_title);
            ImageButton ib_paste = (ImageButton) dialogView.findViewById(R.id.imageButtonPaste);

            ib_paste.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View arg0) {
                    final CharSequence[] options = { getString(R.string.paste_date),
                            getString(R.string.paste_time) };
                    new android.app.AlertDialog.Builder(Activity_todo.this)
                            .setPositiveButton(R.string.toast_cancel, new DialogInterface.OnClickListener() {

                                public void onClick(DialogInterface dialog, int whichButton) {
                                    dialog.dismiss();
                                }
                            }).setItems(options, new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialog, int item) {
                                    if (options[item].equals(getString(R.string.paste_date))) {
                                        Date date = new Date();
                                        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd",
                                                Locale.getDefault());
                                        String dateNow = format.format(date);
                                        edit_title.getText().insert(edit_title.getSelectionStart(), dateNow);
                                    }

                                    if (options[item].equals(getString(R.string.paste_time))) {
                                        Date date = new Date();
                                        SimpleDateFormat format = new SimpleDateFormat("HH:mm",
                                                Locale.getDefault());
                                        String timeNow = format.format(date);
                                        edit_title.getText().insert(edit_title.getSelectionStart(), timeNow);
                                    }
                                }
                            }).show();
                }
            });

            String text = (String) adapter.getItemAtPosition(pos);
            edit_title.setText(text);

            builder.setView(dialogView);
            builder.setTitle(R.string.number_edit_entry);
            builder.setPositiveButton(R.string.toast_yes, new DialogInterface.OnClickListener() {

                public void onClick(DialogInterface dialog, int whichButton) {

                    String inputTag = edit_title.getText().toString().trim();
                    // Remove the item within array at position
                    items.remove(pos);
                    items.add(pos, inputTag);
                    // Refresh the adapter
                    itemsAdapter.notifyDataSetChanged();
                    // Return true consumes the long click event (marks it handled)
                    writeItems();

                }
            });
            builder.setNegativeButton(R.string.toast_cancel, new DialogInterface.OnClickListener() {

                public void onClick(DialogInterface dialog, int whichButton) {
                    dialog.cancel();
                }
            });

            final AlertDialog dialog2 = builder.create();
            // Display the custom alert dialog on interface
            dialog2.show();
            helper_main.showKeyboard(Activity_todo.this, edit_title);
        }
    });
}

From source file:org.kde.necessitas.ministro.MinistroActivity.java

private void checkNetworkAndDownload(final boolean update) {
    if (isOnline(this))
        new CheckLibraries().execute(update);
    else {//from  w w  w  .j  a  v a 2 s .c  o  m
        AlertDialog.Builder builder = new AlertDialog.Builder(MinistroActivity.this);
        builder.setMessage(getResources().getString(R.string.ministro_network_access_msg));
        builder.setCancelable(true);
        builder.setNeutralButton(getResources().getString(R.string.settings_msg),
                new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {
                        final ProgressDialog m_dialog = ProgressDialog.show(MinistroActivity.this, null,
                                getResources().getString(R.string.wait_for_network_connection_msg), true, true,
                                new DialogInterface.OnCancelListener() {
                                    public void onCancel(DialogInterface dialog) {
                                        finishMe();
                                    }
                                });
                        getApplication().registerReceiver(new BroadcastReceiver() {
                            @Override
                            public void onReceive(Context context, Intent intent) {
                                if (isOnline(MinistroActivity.this)) {
                                    try {
                                        getApplication().unregisterReceiver(this);
                                    } catch (Exception e) {
                                        e.printStackTrace();
                                    }
                                    runOnUiThread(new Runnable() {
                                        public void run() {
                                            m_dialog.dismiss();
                                            new CheckLibraries().execute(update);
                                        }
                                    });
                                }
                            }
                        }, new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION));
                        try {
                            startActivity(new Intent(Settings.ACTION_WIRELESS_SETTINGS));
                        } catch (Exception e) {
                            e.printStackTrace();
                            try {
                                startActivity(new Intent(Settings.ACTION_WIFI_SETTINGS));
                            } catch (Exception e1) {

                                e1.printStackTrace();
                            }
                        }
                        dialog.dismiss();
                    }
                });
        builder.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int id) {
                dialog.cancel();
            }
        });
        builder.setOnCancelListener(new DialogInterface.OnCancelListener() {
            public void onCancel(DialogInterface dialog) {
                finishMe();
            }
        });
        AlertDialog alert = builder.create();
        alert.show();
    }
}

From source file:com.free.searcher.MainFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup viewContainer, Bundle savedInstanceState) {

    super.onCreateView(inflater, viewContainer, savedInstanceState);
    this.activity = getActivity();
    actionBar = activity.getActionBar();

    View v = inflater.inflate(R.layout.main, viewContainer, false);
    v.setOnSystemUiVisibilityChangeListener(this);

    webView = (WebView) v.findViewById(R.id.webView1);
    statusView = (TextView) v.findViewById(R.id.statusView);

    if (webViewBundle != null) {
        webView.restoreState(webViewBundle);
        Log.d("onCreateView.webView.restoreState", webViewBundle + "");
    } else if (currentUrl.length() > 0) {
        Log.d("onCreateView.locX, locY", locX + ", " + locY + ", " + currentUrl);
        webView.loadUrl(currentUrl);//from   www . ja va2  s  . com
        webView.setScrollX(locX);
        webView.setScrollY(locY);
        Log.d("currentUrl 8", currentUrl);
    }
    statusView.setText(status);

    Log.d("onCreateView.savedInstanceState", savedInstanceState + "vvv");
    mNotificationManager = (NotificationManager) activity.getSystemService(activity.NOTIFICATION_SERVICE);

    webView.setFocusable(true);
    webView.setFocusableInTouchMode(true);
    webView.requestFocus();
    webView.requestFocusFromTouch();
    webView.getSettings().setAllowContentAccess(false);
    webView.getSettings().setPluginState(WebSettings.PluginState.OFF);
    // webView.setBackgroundColor(LIGHT_BLUE);
    webView.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
    webView.setBackgroundColor(getResources().getColor(R.color.lightyellow));

    webView.setOnLongClickListener(this);
    statusView.setOnLongClickListener(this);

    webView.setWebViewClient(new WebViewClient() {

        private void jumpTo(final int xLocation, final int yLocation) {
            webView.postDelayed(new Runnable() {
                @Override
                public void run() {
                    Log.d("jumpTo1.locX, locY", xLocation + ", " + yLocation + ", " + currentUrl);
                    try {
                        webView.scrollTo(xLocation, yLocation);
                        webView.setScrollX(xLocation);
                        webView.setScrollY(yLocation);
                        //                           locX = 0;
                        //                           locY = 0;
                    } catch (RuntimeException e) {
                        Log.e("error jumpTo2.locX, locY", locX + ", " + locY + ", " + currentUrl);
                    }
                }
            }, 100);
        }

        @Override
        public boolean shouldOverrideUrlLoading(WebView view, final String url) {
            if (currentZipFileName.length() > 0 && (extractFile == null || extractFile.isClosed())) {
                try {
                    extractFile = new ExtractFile(currentZipFileName,
                            MainFragment.PRIVATE_PATH + currentZipFileName);
                } catch (RarException e) {
                    e.printStackTrace();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            int ind = url.indexOf("?deleteFile=");
            if (ind >= 0) {
                if (dupTask == null) {
                    showToast("Please do duplicate finding again.");
                    return true;
                }

                String urlStatus = Util.getUrlStatus(url);
                final String selectedFile = urlStatus.substring(urlStatus.indexOf("?deleteFile=") + 12,
                        urlStatus.length());
                Log.d("deleteFile", "url=" + url + ", urlStatus=" + urlStatus);

                AlertDialog.Builder alert = new AlertDialog.Builder(activity);
                alert.setTitle("Delete File?");
                alert.setMessage("Do you really want to delete file \"" + selectedFile + "\"?");
                alert.setCancelable(true);
                alert.setNegativeButton("Yes", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        try {
                            locX = webView.getScrollX();
                            locY = webView.getScrollY();
                            webView.loadUrl(
                                    new File(dupTask.deleteFile(selectedFile)).toURI().toURL().toString());
                        } catch (IOException e) {
                            statusView.setText(e.getMessage());
                            Log.d("deleteFile", e.getMessage(), e);
                        }
                    }
                });
                alert.setPositiveButton("No", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.cancel();
                    }
                });
                AlertDialog alertDialog = alert.create();
                alertDialog.show();
                return true;
            }

            ind = url.indexOf("?deleteGroup=");
            if (ind >= 0) {
                if (dupTask == null) {
                    showToast("Please do duplicate finding again.");
                    return true;
                }

                String urlStatus = Util.getUrlStatus(url);
                final String groupFile = urlStatus.substring(urlStatus.indexOf("?deleteGroup=") + 13,
                        urlStatus.length());
                int indexOf = groupFile.indexOf(",");
                final int group = Integer.parseInt(groupFile.substring(0, indexOf));
                final String selectedFile = groupFile.substring(indexOf + 1);
                Log.d("groupFile", ",groupFile=" + groupFile + ", url=" + url + ", urlStatus=" + urlStatus);

                AlertDialog.Builder alert = new AlertDialog.Builder(activity);
                alert.setTitle("Delete Group of Files?");
                alert.setMessage(
                        "Do you really want to delete this group, except file \"" + selectedFile + "\"?");
                alert.setCancelable(true);
                alert.setNegativeButton("Yes", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        locX = webView.getScrollX();
                        locY = webView.getScrollY();
                        webView.postDelayed(new Runnable() {
                            @Override
                            public void run() {
                                try {
                                    webView.loadUrl(new File(dupTask.deleteGroup(group, selectedFile)).toURI()
                                            .toURL().toString());
                                } catch (Throwable e) {
                                    statusView.setText(e.getMessage());
                                    Log.e("Delete Group", e.getMessage(), e);
                                    Log.e("Delete Group", locX + ", " + locY + ", " + currentUrl);
                                }
                            }
                        }, 0);
                    }
                });
                alert.setPositiveButton("No", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.cancel();
                    }
                });
                AlertDialog alertDialog = alert.create();
                alertDialog.show();
                return true;
            }

            ind = url.indexOf("?deleteFolder=");
            if (ind >= 0) {
                if (dupTask == null) {
                    showToast("Please do duplicate finding again.");
                    return true;
                }

                String urlStatus = Util.getUrlStatus(url);
                final String selectedFile = urlStatus.substring(urlStatus.indexOf("?deleteFolder=") + 14,
                        urlStatus.length());
                Log.d("deleteFolder",
                        ",deleteFolder=" + selectedFile + ", url=" + url + ", urlStatus=" + urlStatus);
                AlertDialog.Builder alert = new AlertDialog.Builder(activity);
                alert.setTitle("Delete folder?");
                alert.setMessage("Do you really want to delete duplicate in folder \""
                        + selectedFile.substring(0, selectedFile.lastIndexOf("/")) + "\"?");
                alert.setCancelable(true);
                alert.setNegativeButton("Yes", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        locX = webView.getScrollX();
                        locY = webView.getScrollY();
                        webView.postDelayed(new Runnable() {
                            @Override
                            public void run() {
                                try {
                                    webView.loadUrl(new File(dupTask.deleteFolder(selectedFile)).toURI().toURL()
                                            .toString());
                                } catch (Throwable e) {
                                    statusView.setText(e.getMessage());
                                    Log.e("Delete folder", e.getMessage(), e);
                                    Log.e("Delete folder", locX + ", " + locY + ", " + currentUrl);
                                }
                            }
                        }, 0);
                    }
                });
                alert.setPositiveButton("No", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.cancel();
                    }
                });
                AlertDialog alertDialog = alert.create();
                alertDialog.show();
                return true;
            }

            ind = url.indexOf("?deleteSub=");
            if (ind >= 0) {
                if (dupTask == null) {
                    showToast("Please do duplicate finding again.");
                    return true;
                }

                String urlStatus = Util.getUrlStatus(url);

                final String selectedFile = urlStatus.substring(urlStatus.indexOf("?deleteSub=") + 11,
                        urlStatus.length());
                Log.d("deleteSub", ",deleteSub=" + selectedFile + ", url=" + url + ", urlStatus=" + urlStatus);
                AlertDialog.Builder alert = new AlertDialog.Builder(activity);
                alert.setTitle("Delete sub folder?");
                alert.setMessage("Do you really want to delete duplicate files in sub folder of \""
                        + selectedFile.substring(0, selectedFile.lastIndexOf("/")) + "\"?");
                alert.setCancelable(true);
                alert.setNegativeButton("Yes", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        locX = webView.getScrollX();
                        locY = webView.getScrollY();
                        webView.postDelayed(new Runnable() {
                            @Override
                            public void run() {
                                try {
                                    webView.loadUrl(new File(dupTask.deleteSubFolder(selectedFile)).toURI()
                                            .toURL().toString());
                                } catch (Throwable e) {
                                    statusView.setText(e.getMessage());
                                    Log.e("Delete sub folder", e.getMessage(), e);
                                    Log.e("Delete sub folder", locX + ", " + locY + ", " + currentUrl);
                                }
                            }
                        }, 0);
                    }
                });
                alert.setPositiveButton("No", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.cancel();
                    }
                });
                AlertDialog alertDialog = alert.create();
                alertDialog.show();
                return true;
            }

            ind = url.indexOf("?viewName");
            if (ind >= 0) {
                if (dupTask == null) {
                    showToast("Please do duplicate finding again.");
                    return true;
                }
                nameOrder = !nameOrder;
                locX = 0;
                locY = 0;
                Log.d("url=", url + ", viewName");
                try {
                    webView.loadUrl(new File(dupTask.genFile(dupTask.groupList, dupTask.NAME_VIEW)).toURI()
                            .toURL().toString());
                } catch (IOException e) {
                    Log.e("viewName", e.getMessage(), e);
                }
                return true;
            }

            ind = url.indexOf("?viewGroup");
            if (ind >= 0) {
                if (dupTask == null) {
                    showToast("Please do duplicate finding again.");
                    return true;
                }
                groupViewChanged = true;
                locX = 0;
                locY = 0;
                Log.d("url=", url + ", viewGroup");
                try {
                    webView.loadUrl(new File(dupTask.genFile(dupTask.groupList, dupTask.GROUP_VIEW)).toURI()
                            .toURL().toString());
                } catch (IOException e) {
                    Log.e("viewGroup", e.getMessage(), e);
                }
                return true;
            }
            if (zextr == null) {
                locX = 0;
                locY = 0;
            } else {
                zextr = null;
            }

            if (MainActivity.popup) {
                final MainFragment frag = ((MainActivity) activity).addFragmentToStack();
                frag.status = Util.getUrlStatus(url);
                frag.load = load;
                frag.currentSearching = currentSearching;
                frag.selectedFiles = selectedFiles;
                frag.files = files;
                frag.currentZipFileName = currentZipFileName;
                if (extractFile != null) {
                    try {
                        frag.extractFile = new ExtractFile();
                        extractFile.copyTo(frag.extractFile);
                    } catch (RarException e) {
                        e.printStackTrace();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }

                frag.home = home;
                //                  if (mSearchView != null && mSearchView.getQuery().length() > 0) {
                //                     frag.mSearchView.setQuery(mSearchView.getQuery(), false);
                //                  }
                view.getHandler().postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        frag.webTask = new WebTask(MainFragment.this);
                        frag.webTask.init(frag.webView, url);
                        frag.webTask.execute();
                        frag.statusView.setText(frag.status);
                    }
                }, 100);
            } else {
                currentUrl = url;
                Log.d("currentUrl 19", currentUrl);
                status = Util.getUrlStatus(url);
                statusView.setText("Opening " + url + "...");
                webTask = new WebTask(MainFragment.this, webView, url, status.toString());
                webTask.execute();
            }
            //               setNavVisibility(false);
            return true;
        }

        //         @Override
        //         public WebResourceResponse shouldInterceptRequest(WebView view, String url) {
        //         }

        @Override
        public void onPageFinished(WebView view, String url) {
            if (container != null) {
                if (showFind) {
                    container.setVisibility(View.VISIBLE);
                    webView.findAllAsync(findBox.getText().toString());
                } else {
                    container.setVisibility(View.INVISIBLE);
                }
            }
            Log.d("onPageFinished", locX + ", " + locY + ", currentUrl=" + currentUrl + ", url=" + url);
            setNavVisibility(false);
            if (!backForward) { //if (zextr != null) {
                // zextr = null;
                jumpTo(locX, locY);
            } else {
                backForward = false;
            }
            //               locX = 0;
            //               locY = 0;
            Log.d("onPageFinished", url);
            /* This call inject JavaScript into the page which just finished loading. */
            //              webView.loadUrl("javascript:window.HTMLOUT.processHTML(" +
            //                    "'<head>'+document.getElementsByTagName('html')[0].innerHTML+'</head>');");
        }
    });

    WebSettings settings = webView.getSettings();
    //      webView.setWebViewClient(new WebViewClient());
    //      webView.setWebChromeClient(new WebChromeClient());
    //      webView.addJavascriptInterface(new HtmlSourceViewJavaScriptInterface(), "HTMLOUT");
    settings.setMinimumFontSize(13);
    settings.setJavaScriptEnabled(true);
    settings.setDefaultTextEncodingName("UTF-8");
    settings.setBuiltInZoomControls(true);
    // settings.setSansSerifFontFamily("Tahoma");
    settings.setEnableSmoothTransition(true);

    return v;
}

From source file:com.paramonod.kikos.MainActivity.java

public void makingFullStackIcon(int id, GeoPoint geoPoint) {
    OverlayItem oi = new OverlayItem(geoPoint, main.getResources().getDrawable(id));
    final BalloonItem bi = new BalloonItem(main, oi.getGeoPoint());
    if (id != R.drawable.orpgshop) {
        bi.setOnBalloonListener(new OnBalloonListener() {
            @Override/*from  w  w  w .  j a  v a2  s.  co  m*/
            public void onBalloonViewClick(BalloonItem balloonItem, View view) {
            }

            @Override
            public void onBalloonShow(BalloonItem balloonItem) {
                Intent intent = new Intent(main, DetailActivity.class);
                int m = 0;
                for (int i = 0; i < shopInterfaces.size(); i++) {
                    GeoPoint g = new GeoPoint(shopInterfaces.get(i).getCoordX(),
                            shopInterfaces.get(i).getCoordY());
                    if (g.equals(balloonItem.getGeoPoint())) {
                        m = i;
                        //  Log.e("Search", "got here" + Integer.toString(m));
                    }
                }
                intent.putExtra(DetailActivity.EXTRA_POSITION, m);
                startActivity(intent);
            }

            @Override
            public void onBalloonHide(BalloonItem balloonItem) {

            }

            @Override
            public void onBalloonAnimationStart(BalloonItem balloonItem) {

            }

            @Override
            public void onBalloonAnimationEnd(BalloonItem balloonItem) {

            }
        });
    } else {
        bi.setOnBalloonListener(new OnBalloonListener() {
            @Override
            public void onBalloonViewClick(BalloonItem balloonItem, View view) {
            }

            @Override
            public void onBalloonShow(BalloonItem balloonItem) {
                final AlertDialog.Builder b = new AlertDialog.Builder(main);
                b.setTitle(" ?");
                b.setMessage(
                        "?   ? ?  ? ? ? ?,  ");
                b.setPositiveButton("", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        AlertDialog.Builder builder = new AlertDialog.Builder(main);
                        final EditText et = new EditText(main);
                        builder.setMessage(
                                "   ?,  ? ? ? ?  ??: "
                                        + searchView.getQuery());
                        builder.setTitle(" ");
                        builder.setView(et);
                        builder.setPositiveButton("", new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                String s = et.getText().toString();
                                if (s.equals(""))
                                    s = searchView.getQuery().toString();
                                GeoPoint biGeo = bi.getGeoPoint();
                                Pair p = new Pair();
                                p.first = s;
                                p.second = biGeo;
                                places.add(p);
                                SharedPreferences.Editor editor = getPreferences(MODE_PRIVATE).edit();
                                String connectionsJSONString1 = new Gson().toJson(p);
                                editor.putString("places" + placesIDX, connectionsJSONString1);
                                editor.commit();
                                placesIDX++;
                            }
                        });
                        builder.show();
                    }
                });
                b.setNegativeButton("", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.cancel();
                    }
                });
                b.show();
                /* mc.getDownloader().getGeoCode(new GeoCodeListener() {
                     @Override
                     public boolean onFinishGeoCode(final GeoCode geoCode) {
                         if (geoCode != null) {
                             Log.e("Not so fucking", "title" + geoCode.getTitle() + "\nsubtitle" + geoCode.getSubtitle() + "\ndisplayname" + geoCode.getDisplayName() + "\nkind" + geoCode.getKind());
                             main.name = geoCode.getTitle();
                         } else {
                         }
                         AsyncTask asyncTask = new AsyncTask() {
                             @Override
                             protected Object doInBackground(Object[] params) {
                                 String namme = "";
                                 try {
                                     URL url = new URL("https://search-maps.yandex.ru/v1/?text=" + params[0] + "&type=biz&lang=ru_RU&apikey=245e2b86-5cfb-40c3-a064-516c37dba6b2");
                        
                                     System.out.println(url);
                                     HttpURLConnection con = (HttpURLConnection) url.openConnection();
                                     con.connect();
                                     // optional default is GET
                                     con.setRequestMethod("GET");
                                     //int responseCode = con.getResponseCode(); if smth crashes
                                     BufferedReader in = new BufferedReader(
                                             new InputStreamReader(con.getInputStream()));
                                     String inputLine;
                                     String response = "";
                        
                                     while ((inputLine = in.readLine()) != null) {
                                         response += inputLine;
                                     }
                                     in.close();
                                     con.disconnect();
                                     MapActivity.jsonObject = new JSONObject(response);
                                     JSONArray ja1 = MapActivity.jsonObject.getJSONArray("features");
                                     for (int i = 0; i < ja1.length(); i++) {
                                         JSONObject j0 = ja1.getJSONObject(i);
                                         JSONObject j11 = j0.getJSONObject("properties");
                                         main.namme += " " + j11.getString("name");
                                     }
                                 } catch (Exception e) {
                                     e.printStackTrace();
                                 }
                                 return null;
                             }
                        
                             @Override
                             protected void onPostExecute(Object o) {
                                 super.onPostExecute(o);
                                 main.selectName();
                        
                        
                        
                             }
                         }.execute(main.name);
                         return true;
                     }
                 }, balloonItem.getGeoPoint());
                 intent = new Intent(main, DetailYandexActivity.class);
                */
            }

            @Override
            public void onBalloonHide(BalloonItem balloonItem) {

            }

            @Override
            public void onBalloonAnimationStart(BalloonItem balloonItem) {

            }

            @Override
            public void onBalloonAnimationEnd(BalloonItem balloonItem) {

            }
        });
    }
    bi.setDrawable(getResources().getDrawable(R.drawable.itkerk));
    oi.setBalloonItem(bi);
    o.addOverlayItem(oi);

}

From source file:cl.gisred.android.CatastroActivity.java

private void alertNoGps() {
    final AlertDialog alertGps;
    final AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setMessage("El sistema GPS esta desactivado, Desea activarlo?").setCancelable(false)
            .setPositiveButton("Si", new DialogInterface.OnClickListener() {
                public void onClick(@SuppressWarnings("unused") final DialogInterface dialog,
                        @SuppressWarnings("unused") final int id) {
                    startActivity(new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS));
                }/*w w w.j a v a  2 s.  c o  m*/
            }).setNegativeButton("No", new DialogInterface.OnClickListener() {
                public void onClick(final DialogInterface dialog, @SuppressWarnings("unused") final int id) {
                    dialog.cancel();
                }
            });
    alertGps = builder.create();
    alertGps.show();
}

From source file:cm.aptoide.pt.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    AptoideThemePicker.setAptoideTheme(this);
    super.onCreate(savedInstanceState);

    serviceDownloadManagerIntent = new Intent(this, ServiceDownloadManager.class);
    startService(serviceDownloadManagerIntent);
    mContext = this;

    File sdcard_file = new File(SDCARD);
    if (!sdcard_file.exists() || !sdcard_file.canWrite()) {
        View simpleView = LayoutInflater.from(mContext).inflate(R.layout.dialog_simple_layout, null);
        Builder dialogBuilder = new AlertDialog.Builder(mContext).setView(simpleView);
        final AlertDialog noSDDialog = dialogBuilder.create();
        noSDDialog.setTitle(getText(R.string.remote_in_noSD_title));
        noSDDialog.setIcon(android.R.drawable.ic_dialog_alert);
        TextView message = (TextView) simpleView.findViewById(R.id.dialog_message);
        message.setText(getText(R.string.remote_in_noSD));
        noSDDialog.setCancelable(false);
        noSDDialog.setButton(Dialog.BUTTON_NEUTRAL, getString(android.R.string.ok),
                new Dialog.OnClickListener() {
                    @Override//from www.  j a  va 2  s.  c o  m
                    public void onClick(DialogInterface arg0, int arg1) {
                        finish();
                    }
                });
        noSDDialog.show();
    } else {
        StatFs stat = new StatFs(sdcard_file.getPath());
        long blockSize = stat.getBlockSize();
        long totalBlocks = stat.getBlockCount();
        long availableBlocks = stat.getAvailableBlocks();

        long total = (blockSize * totalBlocks) / 1024 / 1024;
        long avail = (blockSize * availableBlocks) / 1024 / 1024;
        Log.d("Aptoide", "* * * * * * * * * *");
        Log.d("Aptoide", "Total: " + total + " Mb");
        Log.d("Aptoide", "Available: " + avail + " Mb");

        if (avail < 10) {
            Log.d("Aptoide", "No space left on SDCARD...");
            Log.d("Aptoide", "* * * * * * * * * *");
            View simpleView = LayoutInflater.from(this).inflate(R.layout.dialog_simple_layout, null);
            Builder dialogBuilder = new AlertDialog.Builder(this).setView(simpleView);
            final AlertDialog noSpaceDialog = dialogBuilder.create();
            noSpaceDialog.setIcon(android.R.drawable.ic_dialog_alert);
            TextView message = (TextView) simpleView.findViewById(R.id.dialog_message);
            message.setText(getText(R.string.remote_in_noSDspace));
            noSpaceDialog.setButton(Dialog.BUTTON_NEUTRAL, getText(android.R.string.ok),
                    new Dialog.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface arg0, int arg1) {
                            finish();
                        }
                    });
            noSpaceDialog.show();
        } else {

            SharedPreferences sPref = PreferenceManager.getDefaultSharedPreferences(mContext);
            editor = PreferenceManager.getDefaultSharedPreferences(mContext).edit();

            if (!sPref.contains("matureChkBox")) {

                editor.putBoolean("matureChkBox", ApplicationAptoide.MATURECONTENTSWITCHVALUE);
                SharedPreferences sPrefOld = getSharedPreferences("aptoide_prefs", MODE_PRIVATE);
                if (sPrefOld.getString("app_rating", "none").equals("Mature")) {
                    editor.putBoolean("matureChkBox", false);
                }

            }

            if (!sPref.contains("version")) {

                ApplicationAptoide.setRestartLauncher(true);
                try {
                    editor.putInt("version",
                            getPackageManager().getPackageInfo(getPackageName(), 0).versionCode);
                } catch (NameNotFoundException e) {
                    e.printStackTrace();
                }

            }

            if (sPref.getString("myId", null) == null) {
                String rand_id = UUID.randomUUID().toString();
                editor.putString("myId", rand_id);
            }

            if (sPref.getInt("scW", 0) == 0 || sPref.getInt("scH", 0) == 0) {
                DisplayMetrics dm = new DisplayMetrics();
                getWindowManager().getDefaultDisplay().getMetrics(dm);
                editor.putInt("scW", dm.widthPixels);
                editor.putInt("scH", dm.heightPixels);
            }
            editor.commit();
            File file = new File(LOCAL_PATH + "/apks");
            if (!file.exists()) {
                file.mkdirs();
            }

            new Thread(new Runnable() {

                @Override
                public void run() {

                    // Note the L that tells the compiler to interpret the
                    // number as a Long
                    final long MAXFILEAGE = 2678400000L; // 1 month in
                    // milliseconds

                    // Get file handle to the directory. In this case the
                    // application files dir
                    File dir = new File(LOCAL_PATH + "/apks");

                    // Optain list of files in the directory.
                    // listFiles() returns a list of File objects to each
                    // file found.
                    File[] files = dir.listFiles();

                    // Loop through all files
                    for (File f : files) {

                        // Get the last modified date. Miliseconds since
                        // 1970
                        long lastmodified = f.lastModified();

                        // Do stuff here to deal with the file..
                        // For instance delete files older than 1 month
                        if (lastmodified + MAXFILEAGE < System.currentTimeMillis()) {
                            f.delete();
                        }
                    }
                }
            }).start();
            db = Database.getInstance();

            Intent i = new Intent(mContext, MainService.class);
            startService(i);
            bindService(i, conn, Context.BIND_AUTO_CREATE);
            order = Order.values()[PreferenceManager.getDefaultSharedPreferences(mContext).getInt("order_list",
                    0)];

            registerReceiver(updatesReceiver, new IntentFilter("update"));
            registerReceiver(statusReceiver, new IntentFilter("status"));
            registerReceiver(loginReceiver, new IntentFilter("login"));
            registerReceiver(storePasswordReceiver, new IntentFilter("401"));
            registerReceiver(redrawInstalledReceiver, new IntentFilter("pt.caixamagica.aptoide.REDRAW"));
            if (!ApplicationAptoide.MULTIPLESTORES) {
                registerReceiver(parseFailedReceiver, new IntentFilter("PARSE_FAILED"));
            }

            registerReceiver(newRepoReceiver, new IntentFilter("pt.caixamagica.aptoide.NEWREPO"));
            registered = true;

            categoriesStrings = new HashMap<String, Integer>();

            //            categoriesStrings.put("Applications", R.string.applications);

            boolean serversFileIsEmpty = true;

            if (sPref.getBoolean("firstrun", true)) {
                // Intent shortcutIntent = new Intent(Intent.ACTION_MAIN);
                // shortcutIntent.setClassName("cm.aptoide.pt",
                // "cm.aptoide.pt.Start");
                // final Intent intent = new Intent();
                // intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT,
                // shortcutIntent);
                //
                // intent.putExtra(Intent.EXTRA_SHORTCUT_NAME,
                // getString(R.string.app_name));
                // Parcelable iconResource =
                // Intent.ShortcutIconResource.fromContext(this,
                // R.drawable.ic_launcher);
                //
                // intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
                // iconResource);
                // intent.putExtra("duplicate", false);
                // intent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
                // sendBroadcast(intent);

                if (new File(LOCAL_PATH + "/servers.xml").exists()
                        && ApplicationAptoide.DEFAULTSTORENAME == null) {
                    try {

                        SAXParserFactory spf = SAXParserFactory.newInstance();
                        SAXParser sp = spf.newSAXParser();

                        MyappHandler handler = new MyappHandler();

                        sp.parse(new File(LOCAL_PATH + "/servers.xml"), handler);
                        ArrayList<String> server = handler.getServers();
                        if (server.isEmpty()) {
                            serversFileIsEmpty = true;
                        } else {
                            getIntent().putExtra("newrepo", server);
                        }

                    } catch (Exception e) {
                        e.printStackTrace();
                    }

                }
                editor.putBoolean("firstrun", false);
                editor.putBoolean("orderByCategory", true);
                editor.commit();
            }

            if (getIntent().hasExtra("newrepo")) {
                ArrayList<String> repos = (ArrayList<String>) getIntent().getSerializableExtra("newrepo");
                for (final String uri2 : repos) {
                    View simpleView = LayoutInflater.from(mContext).inflate(R.layout.dialog_simple_layout,
                            null);
                    Builder dialogBuilder = new AlertDialog.Builder(mContext).setView(simpleView);
                    final AlertDialog addNewRepoDialog = dialogBuilder.create();
                    addNewRepoDialog.setTitle(getString(R.string.add_store));
                    addNewRepoDialog.setIcon(android.R.drawable.ic_menu_add);

                    TextView message = (TextView) simpleView.findViewById(R.id.dialog_message);
                    message.setText((getString(R.string.newrepo_alrt) + uri2 + " ?"));

                    addNewRepoDialog.setCancelable(false);
                    addNewRepoDialog.setButton(Dialog.BUTTON_POSITIVE, getString(android.R.string.yes),
                            new Dialog.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface arg0, int arg1) {
                                    dialogAddStore(uri2, null, null);
                                }
                            });
                    addNewRepoDialog.setButton(Dialog.BUTTON_NEGATIVE, getString(android.R.string.no),
                            new Dialog.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialog, int arg1) {
                                    dialog.cancel();
                                }
                            });
                    addNewRepoDialog.show();
                }
            } else if (db.getStores(false).getCount() == 0 && ApplicationAptoide.DEFAULTSTORENAME == null
                    && serversFileIsEmpty) {
                View simpleView = LayoutInflater.from(mContext).inflate(R.layout.dialog_simple_layout, null);
                Builder dialogBuilder = new AlertDialog.Builder(mContext).setView(simpleView);
                final AlertDialog addAppsRepoDialog = dialogBuilder.create();
                addAppsRepoDialog.setTitle(getString(R.string.add_store));
                addAppsRepoDialog.setIcon(android.R.drawable.ic_menu_add);
                TextView message = (TextView) simpleView.findViewById(R.id.dialog_message);
                message.setText(getString(R.string.myrepo_alrt) + "\n" + "http://apps.store.aptoide.com/");
                addAppsRepoDialog.setCancelable(false);
                addAppsRepoDialog.setButton(Dialog.BUTTON_POSITIVE, getString(android.R.string.yes),
                        new Dialog.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface arg0, int arg1) {
                                dialogAddStore("http://apps.store.aptoide.com", null, null);
                            }
                        });
                addAppsRepoDialog.setButton(Dialog.BUTTON_NEGATIVE, getString(android.R.string.no),
                        new Dialog.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int arg1) {
                                dialog.cancel();
                            }
                        });
                addAppsRepoDialog.show();
            }

            new Thread(new Runnable() {

                @Override
                public void run() {
                    try {
                        getUpdateParameters();
                        if (getPackageManager().getPackageInfo(getPackageName(), 0).versionCode < Integer
                                .parseInt(updateParams.get("versionCode"))) {
                            runOnUiThread(new Runnable() {
                                @Override
                                public void run() {
                                    requestUpdateSelf();
                                }
                            });
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            }).start();

        }

        featuredView = LayoutInflater.from(mContext).inflate(R.layout.page_featured, null);
        availableView = LayoutInflater.from(mContext).inflate(R.layout.page_available, null);
        updateView = LayoutInflater.from(mContext).inflate(R.layout.page_updates, null);
        banner = (LinearLayout) availableView.findViewById(R.id.banner);
        breadcrumbs = (LinearLayout) LayoutInflater.from(mContext).inflate(R.layout.breadcrumb_container, null);
        installedView = new ListView(mContext);
        updatesListView = (ListView) updateView.findViewById(R.id.updates_list);

        availableListView = (ListView) availableView.findViewById(R.id.available_list);
        joinStores = (CheckBox) availableView.findViewById(R.id.join_stores);

        availableAdapter = new AvailableListAdapter(mContext, null,
                CursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER);
        installedAdapter = new InstalledAdapter(mContext, null, CursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER,
                db);
        updatesAdapter = new UpdatesAdapter(mContext, null, CursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER);

        pb = (TextView) availableView.findViewById(R.id.loading_pb);
        addStoreButton = availableView.findViewById(R.id.add_store);

        bannerStoreAvatar = (ImageView) banner.findViewById(R.id.banner_store_avatar);
        bannerStoreName = (TextView) banner.findViewById(R.id.banner_store_name);
        bannerStoreDescription = (AutoScaleTextView) banner.findViewById(R.id.banner_store_description);
    }
}