Example usage for android.os Bundle putInt

List of usage examples for android.os Bundle putInt

Introduction

In this page you can find the example usage for android.os Bundle putInt.

Prototype

public void putInt(@Nullable String key, int value) 

Source Link

Document

Inserts an int value into the mapping of this Bundle, replacing any existing value for the given key.

Usage

From source file:com.dwdesign.tweetings.util.Utils.java

public static Bundle parseArguments(final String string) {
    final Bundle bundle = new Bundle();
    if (string != null) {
        try {//  w  ww .jav  a  2s  .  co  m
            final JSONObject json = new JSONObject(string);
            final Iterator<?> it = json.keys();
            while (it.hasNext()) {
                final Object key_obj = it.next();
                if (key_obj == null) {
                    continue;
                }
                final String key = key_obj.toString();
                final Object value = json.get(key);
                if (value instanceof Boolean) {
                    bundle.putBoolean(key, json.getBoolean(key));
                } else if (value instanceof Integer) {
                    // Simple workaround for account_id
                    if (INTENT_KEY_ACCOUNT_ID.equals(key)) {
                        bundle.putLong(key, json.getLong(key));
                    } else {
                        bundle.putInt(key, json.getInt(key));
                    }
                } else if (value instanceof Long) {
                    bundle.putLong(key, json.getLong(key));
                } else if (value instanceof String) {
                    bundle.putString(key, json.getString(key));
                } else {
                    Log.w(LOGTAG,
                            "Unknown type " + value.getClass().getSimpleName() + " in arguments key " + key);
                }
            }
        } catch (final JSONException e) {
            e.printStackTrace();
        } catch (final ClassCastException e) {
            e.printStackTrace();
        }
    }
    return bundle;
}

From source file:au.com.wallaceit.reddinator.Rservice.java

@Override
public RemoteViews getViewAt(int position) {
    RemoteViews row;/* w  w w.j  a va 2 s.c o  m*/
    if (position > data.length()) {
        return null; //  prevent errornous views
    }
    // check if its the last view and return loading view instead of normal row
    if (position == data.length()) {
        // build load more item
        //System.out.println("load more getViewAt("+position+") firing");
        RemoteViews loadmorerow = new RemoteViews(mContext.getPackageName(), R.layout.listrowloadmore);
        if (endOfFeed) {
            loadmorerow.setTextViewText(R.id.loadmoretxt, "There's nothing more here");
        } else {
            loadmorerow.setTextViewText(R.id.loadmoretxt, "Load more...");
        }
        loadmorerow.setTextColor(R.id.loadmoretxt, themeColors[0]);
        Intent i = new Intent();
        Bundle extras = new Bundle();
        extras.putString(WidgetProvider.ITEM_ID, "0"); // zero will be an indicator in the onreceive function of widget provider if its not present it forces a reload
        i.putExtras(extras);
        loadmorerow.setOnClickFillInIntent(R.id.listrowloadmore, i);
        return loadmorerow;
    } else {
        // build normal item
        String title = "";
        String url = "";
        String permalink = "";
        String thumbnail = "";
        String domain = "";
        String id = "";
        int score = 0;
        int numcomments = 0;
        boolean nsfw = false;
        try {
            JSONObject tempobj = data.getJSONObject(position).getJSONObject("data");
            title = tempobj.getString("title");
            //userlikes = tempobj.getString("likes");
            domain = tempobj.getString("domain");
            id = tempobj.getString("name");
            url = tempobj.getString("url");
            permalink = tempobj.getString("permalink");
            thumbnail = (String) tempobj.get("thumbnail"); // we have to call get and cast cause its not in quotes
            score = tempobj.getInt("score");
            numcomments = tempobj.getInt("num_comments");
            nsfw = tempobj.getBoolean("over_18");
        } catch (JSONException e) {
            e.printStackTrace();
            // return null; // The view is invalid;
        }
        // create remote view from specified layout
        if (bigThumbs) {
            row = new RemoteViews(mContext.getPackageName(), R.layout.listrowbigthumb);
        } else {
            row = new RemoteViews(mContext.getPackageName(), R.layout.listrow);
        }
        // build view
        row.setTextViewText(R.id.listheading, Html.fromHtml(title).toString());
        row.setFloat(R.id.listheading, "setTextSize", Integer.valueOf(titleFontSize)); // use for compatibility setTextViewTextSize only introduced in API 16
        row.setTextColor(R.id.listheading, themeColors[0]);
        row.setTextViewText(R.id.sourcetxt, domain);
        row.setTextColor(R.id.sourcetxt, themeColors[3]);
        row.setTextColor(R.id.votestxt, themeColors[4]);
        row.setTextColor(R.id.commentstxt, themeColors[4]);
        row.setTextViewText(R.id.votestxt, String.valueOf(score));
        row.setTextViewText(R.id.commentstxt, String.valueOf(numcomments));
        row.setInt(R.id.listdivider, "setBackgroundColor", themeColors[2]);
        row.setViewVisibility(R.id.nsfwflag, nsfw ? TextView.VISIBLE : TextView.GONE);
        // add extras and set click intent
        Intent i = new Intent();
        Bundle extras = new Bundle();
        extras.putString(WidgetProvider.ITEM_ID, id);
        extras.putInt("itemposition", position);
        extras.putString(WidgetProvider.ITEM_URL, url);
        extras.putString(WidgetProvider.ITEM_PERMALINK, permalink);
        i.putExtras(extras);
        row.setOnClickFillInIntent(R.id.listrow, i);
        // load thumbnail if they are enabled for this widget
        if (loadThumbnails) {
            // load big image if preference is set
            if (!thumbnail.equals("")) { // check for thumbnail; self is used to display the thinking logo on the reddit site, we'll just show nothing for now
                if (thumbnail.equals("nsfw") || thumbnail.equals("self") || thumbnail.equals("default")) {
                    int resource = 0;
                    switch (thumbnail) {
                    case "nsfw":
                        resource = R.drawable.nsfw;
                        break;
                    case "default":
                    case "self":
                        resource = R.drawable.self_default;
                        break;
                    }
                    row.setImageViewResource(R.id.thumbnail, resource);
                    row.setViewVisibility(R.id.thumbnail, View.VISIBLE);
                    //System.out.println("Loading default image: "+thumbnail);
                } else {
                    Bitmap bitmap;
                    String fileurl = mContext.getCacheDir() + "/thumbcache-" + appWidgetId + "/" + id + ".png";
                    // check if the image is in cache
                    if (new File(fileurl).exists()) {
                        bitmap = BitmapFactory.decodeFile(fileurl);
                        saveImageToStorage(bitmap, id);
                    } else {
                        // download the image
                        bitmap = loadImage(thumbnail);
                    }
                    if (bitmap != null) {
                        row.setImageViewBitmap(R.id.thumbnail, bitmap);
                        row.setViewVisibility(R.id.thumbnail, View.VISIBLE);
                    } else {
                        // row.setImageViewResource(R.id.thumbnail, android.R.drawable.stat_notify_error); for later
                        row.setViewVisibility(R.id.thumbnail, View.GONE);
                    }
                }
            } else {
                row.setViewVisibility(R.id.thumbnail, View.GONE);
            }
        } else {
            row.setViewVisibility(R.id.thumbnail, View.GONE);
        }
        // hide info bar if options set
        if (hideInf) {
            row.setViewVisibility(R.id.infbox, View.GONE);
        } else {
            row.setViewVisibility(R.id.infbox, View.VISIBLE);
        }
    }
    //System.out.println("getViewAt("+position+");");
    return row;
}

From source file:com.lgallardo.qbittorrentclient.RefreshListener.java

@Override
public void onSaveInstanceState(Bundle outState) {
    super.onSaveInstanceState(outState);
    // TODO: Delete
    outState.putInt("itemPosition", itemPosition);
}

From source file:com.antew.redditinpictures.library.service.RESTService.java

@Override
protected void onHandleIntent(Intent intent) {
    Uri action = intent.getData();/*from   w ww  .  j av  a 2s.c o  m*/
    Bundle extras = intent.getExtras();

    if (extras == null || action == null) {
        Ln.e("You did not pass extras or data with the Intent.");
        return;
    }

    // We default to GET if no verb was specified.
    int verb = extras.getInt(EXTRA_HTTP_VERB, GET);
    RequestCode requestCode = (RequestCode) extras.getSerializable(EXTRA_REQUEST_CODE);
    Bundle params = extras.getParcelable(EXTRA_PARAMS);
    String cookie = extras.getString(EXTRA_COOKIE);
    String userAgent = extras.getString(EXTRA_USER_AGENT);

    // Items in this bundle are simply passed on in onRequestComplete
    Bundle passThrough = extras.getBundle(EXTRA_PASS_THROUGH);

    HttpEntity responseEntity = null;
    Intent result = new Intent(Constants.Broadcast.BROADCAST_HTTP_FINISHED);
    result.putExtra(EXTRA_PASS_THROUGH, passThrough);
    Bundle resultData = new Bundle();

    try {
        // Here we define our base request object which we will
        // send to our REST service via HttpClient.
        HttpRequestBase request = null;

        // Let's build our request based on the HTTP verb we were
        // given.
        switch (verb) {
        case GET: {
            request = new HttpGet();
            attachUriWithQuery(request, action, params);
        }
            break;

        case DELETE: {
            request = new HttpDelete();
            attachUriWithQuery(request, action, params);
        }
            break;

        case POST: {
            request = new HttpPost();
            request.setURI(new URI(action.toString()));

            // Attach form entity if necessary. Note: some REST APIs
            // require you to POST JSON. This is easy to do, simply use
            // postRequest.setHeader('Content-Type', 'application/json')
            // and StringEntity instead. Same thing for the PUT case
            // below.
            HttpPost postRequest = (HttpPost) request;

            if (params != null) {
                UrlEncodedFormEntity formEntity = new UrlEncodedFormEntity(paramsToList(params));
                postRequest.setEntity(formEntity);
            }
        }
            break;

        case PUT: {
            request = new HttpPut();
            request.setURI(new URI(action.toString()));

            // Attach form entity if necessary.
            HttpPut putRequest = (HttpPut) request;

            if (params != null) {
                UrlEncodedFormEntity formEntity = new UrlEncodedFormEntity(paramsToList(params));
                putRequest.setEntity(formEntity);
            }
        }
            break;
        }

        if (request != null) {
            DefaultHttpClient client = new DefaultHttpClient();

            // GZip requests
            // antew on 3/12/2014 - Disabling GZIP for now, need to figure this CloseGuard error:
            // 03-12 21:02:09.248    9674-9683/com.antew.redditinpictures.pro E/StrictMode A resource was acquired at attached stack trace but never released. See java.io.Closeable for information on avoiding resource leaks.
            //         java.lang.Throwable: Explicit termination method 'end' not called
            // at dalvik.system.CloseGuard.open(CloseGuard.java:184)
            // at java.util.zip.Inflater.<init>(Inflater.java:82)
            // at java.util.zip.GZIPInputStream.<init>(GZIPInputStream.java:96)
            // at java.util.zip.GZIPInputStream.<init>(GZIPInputStream.java:81)
            // at com.antew.redditinpictures.library.service.RESTService$GzipDecompressingEntity.getContent(RESTService.java:346)
            client.addRequestInterceptor(getGzipRequestInterceptor());
            client.addResponseInterceptor(getGzipResponseInterceptor());

            if (cookie != null) {
                request.addHeader("Cookie", cookie);
            }

            if (userAgent != null) {
                request.addHeader("User-Agent", Constants.Reddit.USER_AGENT);
            }

            // Let's send some useful debug information so we can monitor things
            // in LogCat.
            Ln.d("Executing request: %s %s ", verbToString(verb), action.toString());

            // Finally, we send our request using HTTP. This is the synchronous
            // long operation that we need to run on this thread.
            HttpResponse response = client.execute(request);

            responseEntity = response.getEntity();
            StatusLine responseStatus = response.getStatusLine();
            int statusCode = responseStatus != null ? responseStatus.getStatusCode() : 0;

            if (responseEntity != null) {
                resultData.putString(REST_RESULT, EntityUtils.toString(responseEntity));
                resultData.putSerializable(EXTRA_REQUEST_CODE, requestCode);
                resultData.putInt(EXTRA_STATUS_CODE, statusCode);
                result.putExtra(EXTRA_BUNDLE, resultData);

                onRequestComplete(result);
            } else {
                onRequestFailed(result, statusCode);
            }
        }
    } catch (URISyntaxException e) {
        Ln.e(e, "URI syntax was incorrect. %s %s ", verbToString(verb), action.toString());
        onRequestFailed(result, 0);
    } catch (UnsupportedEncodingException e) {
        Ln.e(e, "A UrlEncodedFormEntity was created with an unsupported encoding.");
        onRequestFailed(result, 0);
    } catch (ClientProtocolException e) {
        Ln.e(e, "There was a problem when sending the request.");
        onRequestFailed(result, 0);
    } catch (IOException e) {
        Ln.e(e, "There was a problem when sending the request.");
        onRequestFailed(result, 0);
    } finally {
        if (responseEntity != null) {
            try {
                responseEntity.consumeContent();
            } catch (IOException ignored) {
            }
        }
    }
}

From source file:com.irccloud.android.activity.MainActivity.java

@Override
public void onMessageViewReady() {
    if (shouldFadeIn) {
        Crashlytics.log(Log.DEBUG, "IRCCloud", "Fade In");
        MessageViewFragment mvf = (MessageViewFragment) getSupportFragmentManager()
                .findFragmentById(R.id.messageViewFragment);
        UsersListFragment ulf = (UsersListFragment) getSupportFragmentManager()
                .findFragmentById(R.id.usersListFragment);

        if (Build.VERSION.SDK_INT < 16) {
            AlphaAnimation anim = new AlphaAnimation(0, 1);
            anim.setDuration(150);/*from   w  w w.  j a v  a2 s  .c o  m*/
            anim.setFillAfter(true);
            if (mvf != null && mvf.getListView() != null)
                mvf.getListView().startAnimation(anim);
            if (ulf != null && ulf.getListView() != null)
                ulf.getListView().startAnimation(anim);
        } else {
            if (mvf != null && mvf.getListView() != null)
                mvf.getListView().animate().alpha(1);
            if (ulf != null && ulf.getListView() != null)
                ulf.getListView().animate().alpha(1);
        }
        if (mvf != null && mvf.getListView() != null) {
            if (mvf.buffer != buffer && buffer != null
                    && BuffersDataSource.getInstance().getBuffer(buffer.bid) != null) {
                Bundle b = new Bundle();
                b.putInt("cid", buffer.cid);
                b.putInt("bid", buffer.bid);
                b.putBoolean("fade", false);
                mvf.setArguments(b);
            }
            mvf.showSpinner(false);
        }
        shouldFadeIn = false;
    }
}

From source file:com.irccloud.android.activity.MainActivity.java

@Override
public void onSaveInstanceState(Bundle state) {
    super.onSaveInstanceState(state);
    if (server != null)
        state.putInt("cid", server.cid);
    if (buffer != null) {
        state.putInt("bid", buffer.bid);
        if (messageTxt != null && messageTxt.getText() != null)
            buffer.draft = messageTxt.getText().toString();
        else//from   ww w  . ja  v a 2s.  co m
            buffer.draft = null;
    }
    state.putSerializable("backStack", backStack);
    if (imageCaptureURI != null)
        state.putString("imagecaptureuri", imageCaptureURI.toString());
}

From source file:com.irccloud.android.activity.MainActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    AlertDialog.Builder builder;/*from   www . j a va  2s.  c  o m*/
    AlertDialog dialog;

    switch (item.getItemId()) {
    case android.R.id.home:
        if (drawerLayout != null && findViewById(R.id.usersListFragment2) == null) {
            if (drawerLayout.isDrawerOpen(Gravity.LEFT))
                drawerLayout.closeDrawer(Gravity.LEFT);
            else if (drawerLayout.getDrawerLockMode(Gravity.LEFT) == DrawerLayout.LOCK_MODE_UNLOCKED)
                drawerLayout.openDrawer(Gravity.LEFT);
            drawerLayout.closeDrawer(Gravity.RIGHT);
        }
        break;
    case R.id.menu_whois:
        NetworkConnection.getInstance().whois(buffer.cid, buffer.name, null);
        break;
    case R.id.menu_identify:
        NickservFragment nsFragment = new NickservFragment();
        nsFragment.setCid(buffer.cid);
        nsFragment.show(getSupportFragmentManager(), "nickserv");
        break;
    case R.id.menu_add_network:
        addNetwork();
        break;
    case R.id.menu_channel_options:
        ChannelOptionsFragment newFragment = new ChannelOptionsFragment(buffer.cid, buffer.bid);
        newFragment.show(getSupportFragmentManager(), "channeloptions");
        break;
    case R.id.menu_buffer_options:
        BufferOptionsFragment bufferFragment = new BufferOptionsFragment(buffer.cid, buffer.bid, buffer.type);
        bufferFragment.show(getSupportFragmentManager(), "bufferoptions");
        break;
    case R.id.menu_userlist:
        if (drawerLayout != null) {
            if (drawerLayout.isDrawerOpen(Gravity.RIGHT)) {
                drawerLayout.closeDrawers();
            } else {
                if (findViewById(R.id.usersListFragment2) == null)
                    drawerLayout.closeDrawer(Gravity.LEFT);
                drawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED, Gravity.RIGHT);
                drawerLayout.openDrawer(Gravity.RIGHT);
            }
            if (!getSharedPreferences("prefs", 0).getBoolean("userSwipeTip", false)) {
                Toast.makeText(this, "Drag from the edge of the screen to quickly open and close the user list",
                        Toast.LENGTH_LONG).show();
                SharedPreferences.Editor editor = getSharedPreferences("prefs", 0).edit();
                editor.putBoolean("userSwipeTip", true);
                editor.commit();
            }
        }
        return true;
    case R.id.menu_ignore_list:
        Bundle args = new Bundle();
        args.putInt("cid", buffer.cid);
        IgnoreListFragment ignoreList = new IgnoreListFragment();
        ignoreList.setArguments(args);
        ignoreList.show(getSupportFragmentManager(), "ignorelist");
        return true;
    case R.id.menu_ban_list:
        NetworkConnection.getInstance().mode(buffer.cid, buffer.name, "b");
        return true;
    case R.id.menu_leave:
        if (ChannelsDataSource.getInstance().getChannelForBuffer(buffer.bid) == null)
            NetworkConnection.getInstance().join(buffer.cid, buffer.name, null);
        else
            NetworkConnection.getInstance().part(buffer.cid, buffer.name, null);
        return true;
    case R.id.menu_archive:
        if (buffer.archived == 0)
            NetworkConnection.getInstance().archiveBuffer(buffer.cid, buffer.bid);
        else
            NetworkConnection.getInstance().unarchiveBuffer(buffer.cid, buffer.bid);
        return true;
    case R.id.menu_delete:
        builder = new AlertDialog.Builder(MainActivity.this);
        builder.setInverseBackgroundForced(Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB);

        if (buffer.type.equals("console"))
            builder.setTitle("Delete Connection");
        else
            builder.setTitle("Delete History");

        if (buffer.type.equalsIgnoreCase("console"))
            builder.setMessage("Are you sure you want to remove this connection?");
        else if (buffer.type.equalsIgnoreCase("channel"))
            builder.setMessage("Are you sure you want to clear your history in " + buffer.name + "?");
        else
            builder.setMessage("Are you sure you want to clear your history with " + buffer.name + "?");

        builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
            }
        });
        builder.setPositiveButton("Delete", new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                if (buffer.type.equals("console")) {
                    NetworkConnection.getInstance().deleteServer(buffer.cid);
                } else {
                    NetworkConnection.getInstance().deleteBuffer(buffer.cid, buffer.bid);
                }
                dialog.dismiss();
            }
        });
        dialog = builder.create();
        dialog.setOwnerActivity(MainActivity.this);
        dialog.show();
        return true;
    case R.id.menu_editconnection:
        if (!getResources().getBoolean(R.bool.isTablet)) {
            Intent i = new Intent(this, EditConnectionActivity.class);
            i.putExtra("cid", buffer.cid);
            startActivity(i);
        } else {
            EditConnectionFragment editFragment = new EditConnectionFragment();
            editFragment.setCid(buffer.cid);
            editFragment.show(getSupportFragmentManager(), "editconnection");
        }
        return true;
    case R.id.menu_disconnect:
        if (server != null && server.status != null && (server.status.equalsIgnoreCase("waiting_to_retry"))
                || (server.status.contains("connected") && !server.status.startsWith("dis"))) {
            NetworkConnection.getInstance().disconnect(buffer.cid, null);
        } else {
            NetworkConnection.getInstance().reconnect(buffer.cid);
        }
        return true;
    }
    return super.onOptionsItemSelected(item);
}

From source file:com.irccloud.android.activity.MainActivity.java

@Override
public void onBufferSelected(int bid) {
    launchBid = -1;/*from   w  w  w .j av  a  2 s. co  m*/
    launchURI = null;
    cidToOpen = -1;
    bufferToOpen = null;
    setIntent(new Intent(this, MainActivity.class));

    if (suggestionsTimerTask != null)
        suggestionsTimerTask.cancel();
    sortedChannels = null;
    sortedUsers = null;

    if (drawerLayout != null) {
        drawerLayout.closeDrawers();
    }
    if (bid != -1 && conn != null && conn.getUserInfo() != null) {
        conn.getUserInfo().last_selected_bid = bid;
    }
    for (int i = 0; i < backStack.size(); i++) {
        if (buffer != null && backStack.get(i) == buffer.bid)
            backStack.remove(i);
    }
    if (buffer != null && buffer.bid >= 0 && bid != buffer.bid) {
        backStack.add(0, buffer.bid);
        buffer.draft = messageTxt.getText().toString();
    }
    if (buffer == null || buffer.bid == -1 || buffer.cid == -1 || buffer.bid == bid)
        shouldFadeIn = false;
    else
        shouldFadeIn = true;
    buffer = BuffersDataSource.getInstance().getBuffer(bid);
    if (buffer != null) {
        Crashlytics.log(Log.DEBUG, "IRCCloud",
                "Buffer selected: cid" + buffer.cid + " bid" + bid + " shouldFadeIn: " + shouldFadeIn);
        server = ServersDataSource.getInstance().getServer(buffer.cid);

        try {
            TreeMap<Long, EventsDataSource.Event> events = EventsDataSource.getInstance()
                    .getEventsForBuffer(buffer.bid);
            if (events != null) {
                events = (TreeMap<Long, EventsDataSource.Event>) events.clone();
                for (EventsDataSource.Event e : events.values()) {
                    if (e != null && e.highlight && e.from != null) {
                        UsersDataSource.User u = UsersDataSource.getInstance().getUser(buffer.bid, e.from);
                        if (u != null && u.last_mention < e.eid)
                            u.last_mention = e.eid;
                    }
                }
            }
        } catch (Exception e) {
            Crashlytics.logException(e);
        }

        try {
            if (Build.VERSION.SDK_INT >= 16 && buffer != null && server != null) {
                NfcAdapter nfc = NfcAdapter.getDefaultAdapter(this);
                if (nfc != null) {
                    String uri = "irc";
                    if (server.ssl > 0)
                        uri += "s";
                    uri += "://" + server.hostname + ":" + server.port;
                    if (buffer.type.equals("channel")) {
                        uri += "/" + URLEncoder.encode(buffer.name, "UTF-8");
                        ChannelsDataSource.Channel c = ChannelsDataSource.getInstance()
                                .getChannelForBuffer(buffer.bid);
                        if (c != null && c.hasMode("k"))
                            uri += "," + c.paramForMode("k");
                    }
                    nfc.setNdefPushMessage(new NdefMessage(NdefRecord.createUri(uri)), this);
                }
            }
        } catch (Exception e) {
        }
    } else {
        Crashlytics.log(Log.DEBUG, "IRCCloud",
                "Buffer selected but not found: bid" + bid + " shouldFadeIn: " + shouldFadeIn);
        server = null;
    }
    update_subtitle();
    final Bundle b = new Bundle();
    if (buffer != null)
        b.putInt("cid", buffer.cid);
    b.putInt("bid", bid);
    b.putBoolean("fade", shouldFadeIn);
    BuffersListFragment blf = (BuffersListFragment) getSupportFragmentManager()
            .findFragmentById(R.id.BuffersList);
    final MessageViewFragment mvf = (MessageViewFragment) getSupportFragmentManager()
            .findFragmentById(R.id.messageViewFragment);
    UsersListFragment ulf = (UsersListFragment) getSupportFragmentManager()
            .findFragmentById(R.id.usersListFragment);
    UsersListFragment ulf2 = (UsersListFragment) getSupportFragmentManager()
            .findFragmentById(R.id.usersListFragment2);
    if (mvf != null)
        mvf.ready = false;
    if (blf != null)
        blf.setSelectedBid(bid);
    if (ulf != null)
        ulf.setArguments(b);
    if (ulf2 != null)
        ulf2.setArguments(b);

    if (shouldFadeIn) {
        Crashlytics.log(Log.DEBUG, "IRCCloud", "Fade Out");
        if (Build.VERSION.SDK_INT < 16) {
            AlphaAnimation anim = new AlphaAnimation(1, 0);
            anim.setDuration(150);
            anim.setFillAfter(true);
            anim.setAnimationListener(new Animation.AnimationListener() {
                @Override
                public void onAnimationStart(Animation animation) {

                }

                @Override
                public void onAnimationEnd(Animation animation) {
                    if (mvf != null)
                        mvf.setArguments(b);
                    messageTxt.setText("");
                    if (buffer != null && buffer.draft != null)
                        messageTxt.append(buffer.draft);
                }

                @Override
                public void onAnimationRepeat(Animation animation) {

                }
            });
            try {
                mvf.getListView().startAnimation(anim);
                ulf.getListView().startAnimation(anim);
            } catch (Exception e) {

            }
        } else {
            mvf.getListView().animate().alpha(0).withEndAction(new Runnable() {
                @Override
                public void run() {
                    if (mvf != null)
                        mvf.setArguments(b);
                    messageTxt.setText("");
                    if (buffer != null && buffer.draft != null)
                        messageTxt.append(buffer.draft);
                }
            });
            ulf.getListView().animate().alpha(0);
        }
        mvf.showSpinner(true);
    } else {
        if (mvf != null)
            mvf.setArguments(b);
        messageTxt.setText("");
        if (buffer != null && buffer.draft != null)
            messageTxt.append(buffer.draft);
    }

    updateUsersListFragmentVisibility();
    supportInvalidateOptionsMenu();
    if (excludeBIDTask != null)
        excludeBIDTask.cancel(true);
    excludeBIDTask = new ExcludeBIDTask();
    excludeBIDTask.execute(bid);
    if (drawerLayout != null)
        new RefreshUpIndicatorTask().execute((Void) null);
    if (buffer != null && buffer.cid != -1) {
        if (drawerLayout != null) {
            drawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED, Gravity.LEFT);
            getSupportActionBar().setHomeButtonEnabled(true);
        }
    }
    update_suggestions(false);
}

From source file:com.gimranov.zandy.app.data.Item.java

/**
 * Makes ArrayList<Bundle> from the present item. This was moved from
 * ItemDataActivity, but it's most likely to be used by such display
 * activities//from ww w . j a  v a 2 s . c o m
 */
public ArrayList<Bundle> toBundleArray(Database db) {
    JSONObject itemContent = this.content;
    /*
     * Here we walk through the data and make Bundles to send to the
     * ArrayAdapter. There should be no real risk of JSON exceptions, since
     * the JSON was checked when initialized in the Item object.
     * 
     * Each Bundle has two keys: "label" and "content"
     */
    JSONArray fields = itemContent.names();
    ArrayList<Bundle> rows = new ArrayList<Bundle>();
    Bundle b;

    try {
        JSONArray values = itemContent.toJSONArray(fields);
        for (int i = 0; i < itemContent.length(); i++) {
            b = new Bundle();

            /* Special handling for some types */
            if (fields.getString(i).equals("tags")) {
                // We display the tags semicolon-delimited
                StringBuilder sb = new StringBuilder();
                try {
                    JSONArray tagArray = values.getJSONArray(i);
                    for (int j = 0; j < tagArray.length(); j++) {
                        sb.append(tagArray.getJSONObject(j).getString("tag"));
                        if (j < tagArray.length() - 1)
                            sb.append("; ");
                    }

                    b.putString("content", sb.toString());
                } catch (JSONException e) {
                    // Fall back to empty
                    Log.e(TAG, "Exception parsing tags, with input: " + values.getString(i), e);
                    b.putString("content", "");
                }
            } else if (fields.getString(i).equals("notes")) {
                // TODO handle notes
                continue;
            } else if (fields.getString(i).equals("creators")) {
                /*
                 * Creators should be labeled with role and listed nicely
                 * This logic isn't as good as it could be.
                 */
                JSONArray creatorArray = values.getJSONArray(i);
                JSONObject creator;
                StringBuilder sb = new StringBuilder();
                for (int j = 0; j < creatorArray.length(); j++) {
                    creator = creatorArray.getJSONObject(j);
                    if (creator.getString("creatorType").equals("author")) {
                        if (creator.has("name"))
                            sb.append(creator.getString("name"));
                        else
                            sb.append(creator.getString("firstName") + " " + creator.getString("lastName"));
                    } else {
                        if (creator.has("name"))
                            sb.append(creator.getString("name"));
                        else
                            sb.append(creator.getString("firstName") + " " + creator.getString("lastName")
                                    + " (" + Item.localizedStringForString(creator.getString("creatorType"))
                                    + ")");
                    }
                    if (j < creatorArray.length() - 1)
                        sb.append(", ");
                }
                b.putString("content", sb.toString());
            } else if (fields.getString(i).equals("itemType")) {
                // We want to show the localized or human-readable type
                b.putString("content", Item.localizedStringForString(values.getString(i)));
            } else {
                // All other data is treated as just text
                b.putString("content", values.getString(i));
            }
            b.putString("label", fields.getString(i));
            b.putString("itemKey", getKey());
            rows.add(b);
        }
        b = new Bundle();
        int notes = 0;
        int atts = 0;
        ArrayList<Attachment> attachments = Attachment.forItem(this, db);
        for (Attachment a : attachments) {
            if ("note".equals(a.getType()))
                notes++;
            else
                atts++;
        }

        b.putInt("noteCount", notes);
        b.putInt("attachmentCount", atts);
        b.putString("content", "not-empty-so-sorting-works");
        b.putString("label", "children");
        b.putString("itemKey", getKey());
        rows.add(b);

        b = new Bundle();
        int collectionCount = ItemCollection.getCollectionCount(this, db);

        b.putInt("collectionCount", collectionCount);
        b.putString("content", "not-empty-so-sorting-works");
        b.putString("label", "collections");
        b.putString("itemKey", getKey());
        rows.add(b);
    } catch (JSONException e) {
        /*
         * We could die here, but I'd rather not, since this shouldn't be
         * possible.
         */
        Log.e(TAG, "JSON parse exception making bundles!", e);
    }

    /* We'd like to put these in a certain order, so let's try! */
    Collections.sort(rows, new Comparator<Bundle>() {
        @Override
        public int compare(Bundle b1, Bundle b2) {
            boolean mt1 = (b1.containsKey("content") && b1.getString("content").equals(""));
            boolean mt2 = (b2.containsKey("content") && b2.getString("content").equals(""));
            /* Put the empty fields at the bottom, same order */

            return (Item.sortValueForLabel(b1.getString("label"))
                    - Item.sortValueForLabel(b2.getString("label")) - (mt2 ? 300 : 0) + (mt1 ? 300 : 0));
        }
    });
    return rows;
}