Example usage for android.widget SimpleAdapter SimpleAdapter

List of usage examples for android.widget SimpleAdapter SimpleAdapter

Introduction

In this page you can find the example usage for android.widget SimpleAdapter SimpleAdapter.

Prototype

public SimpleAdapter(Context context, List<? extends Map<String, ?>> data, @LayoutRes int resource,
        String[] from, @IdRes int[] to) 

Source Link

Document

Constructor

Usage

From source file:com.piusvelte.sonet.core.SelectFriends.java

protected void loadFriends() {
    mFriends.clear();// w w  w  .  j a  va2 s  . c  om
    //      SimpleAdapter sa = new SimpleAdapter(SelectFriends.this, mFriends, R.layout.friend, new String[]{Entities.PROFILE, Entities.FRIEND, Entities.ESID}, new int[]{R.id.profile, R.id.name, R.id.selected});
    SimpleAdapter sa = new SimpleAdapter(SelectFriends.this, mFriends, R.layout.friend,
            new String[] { Entities.FRIEND, Entities.ESID }, new int[] { R.id.name, R.id.selected });
    setListAdapter(sa);
    final ProgressDialog loadingDialog = new ProgressDialog(this);
    final AsyncTask<Long, String, Boolean> asyncTask = new AsyncTask<Long, String, Boolean>() {
        @Override
        protected Boolean doInBackground(Long... params) {
            boolean loadList = false;
            SonetCrypto sonetCrypto = SonetCrypto.getInstance(getApplicationContext());
            // load the session
            Cursor account = getContentResolver().query(Accounts.getContentUri(SelectFriends.this),
                    new String[] { Accounts.TOKEN, Accounts.SECRET, Accounts.SERVICE }, Accounts._ID + "=?",
                    new String[] { Long.toString(params[0]) }, null);
            if (account.moveToFirst()) {
                mToken = sonetCrypto.Decrypt(account.getString(0));
                mSecret = sonetCrypto.Decrypt(account.getString(1));
                mService = account.getInt(2);
            }
            account.close();
            String response;
            switch (mService) {
            case TWITTER:
                break;
            case FACEBOOK:
                if ((response = SonetHttpClient.httpResponse(mHttpClient, new HttpGet(
                        String.format(FACEBOOK_FRIENDS, FACEBOOK_BASE_URL, Saccess_token, mToken)))) != null) {
                    try {
                        JSONArray friends = new JSONObject(response).getJSONArray(Sdata);
                        for (int i = 0, l = friends.length(); i < l; i++) {
                            JSONObject f = friends.getJSONObject(i);
                            HashMap<String, String> newFriend = new HashMap<String, String>();
                            newFriend.put(Entities.ESID, f.getString(Sid));
                            newFriend.put(Entities.PROFILE, String.format(FACEBOOK_PICTURE, f.getString(Sid)));
                            newFriend.put(Entities.FRIEND, f.getString(Sname));
                            // need to alphabetize
                            if (mFriends.isEmpty())
                                mFriends.add(newFriend);
                            else {
                                String fullName = f.getString(Sname);
                                int spaceIdx = fullName.lastIndexOf(" ");
                                String newFirstName = null;
                                String newLastName = null;
                                if (spaceIdx == -1)
                                    newFirstName = fullName;
                                else {
                                    newFirstName = fullName.substring(0, spaceIdx++);
                                    newLastName = fullName.substring(spaceIdx);
                                }
                                List<HashMap<String, String>> newFriends = new ArrayList<HashMap<String, String>>();
                                for (int i2 = 0, l2 = mFriends.size(); i2 < l2; i2++) {
                                    HashMap<String, String> oldFriend = mFriends.get(i2);
                                    if (newFriend == null) {
                                        newFriends.add(oldFriend);
                                    } else {
                                        fullName = oldFriend.get(Entities.FRIEND);
                                        spaceIdx = fullName.lastIndexOf(" ");
                                        String oldFirstName = null;
                                        String oldLastName = null;
                                        if (spaceIdx == -1)
                                            oldFirstName = fullName;
                                        else {
                                            oldFirstName = fullName.substring(0, spaceIdx++);
                                            oldLastName = fullName.substring(spaceIdx);
                                        }
                                        if (newFirstName == null) {
                                            newFriends.add(newFriend);
                                            newFriend = null;
                                        } else {
                                            int comparison = oldFirstName.compareToIgnoreCase(newFirstName);
                                            if (comparison == 0) {
                                                // compare firstnames
                                                if (newLastName == null) {
                                                    newFriends.add(newFriend);
                                                    newFriend = null;
                                                } else if (oldLastName != null) {
                                                    comparison = oldLastName.compareToIgnoreCase(newLastName);
                                                    if (comparison == 0) {
                                                        newFriends.add(newFriend);
                                                        newFriend = null;
                                                    } else if (comparison > 0) {
                                                        newFriends.add(newFriend);
                                                        newFriend = null;
                                                    }
                                                }
                                            } else if (comparison > 0) {
                                                newFriends.add(newFriend);
                                                newFriend = null;
                                            }
                                        }
                                        newFriends.add(oldFriend);
                                    }
                                }
                                if (newFriend != null)
                                    newFriends.add(newFriend);
                                mFriends = newFriends;
                            }
                        }
                        loadList = true;
                    } catch (JSONException e) {
                        Log.e(TAG, e.toString());
                    }
                }
                break;
            case MYSPACE:
                break;
            case LINKEDIN:
                break;
            case FOURSQUARE:
                break;
            case IDENTICA:
                break;
            case GOOGLEPLUS:
                break;
            case CHATTER:
                break;
            }
            return loadList;
        }

        @Override
        protected void onPostExecute(Boolean loadList) {
            if (loadList) {
                //               SimpleAdapter sa = new SimpleAdapter(SelectFriends.this, mFriends, R.layout.friend, new String[]{Entities.PROFILE, Entities.FRIEND}, new int[]{R.id.profile, R.id.name});
                SimpleAdapter sa = new SimpleAdapter(SelectFriends.this, mFriends, R.layout.friend,
                        new String[] { Entities.FRIEND, Entities.ESID },
                        new int[] { R.id.name, R.id.selected });
                sa.setViewBinder(mViewBinder);
                setListAdapter(sa);
            }
            if (loadingDialog.isShowing())
                loadingDialog.dismiss();
        }
    };
    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(mAccountId);
}

From source file:at.alladin.rmbt.android.fragments.result.RMBTTestResultDetailFragment.java

@Override
public void taskEnded(final JSONArray testResultDetail) {
    if (!isVisible())
        return;/*from   w  ww. j a va  2 s.  co m*/

    if (testResultDetail != null && testResultDetail.length() > 0 && !testResultDetailTask.hasError()) {

        try {

            HashMap<String, String> viewItem;

            if (testType == ResultDetailType.SPEEDTEST) {
                for (int i = 0; i < testResultDetail.length(); i++) {

                    final JSONObject singleItem = testResultDetail.getJSONObject(i);

                    viewItem = new HashMap<String, String>();
                    viewItem.put("name", singleItem.optString("title", ""));

                    if (singleItem.has("time")) {
                        final String timeString = Helperfunctions.formatTimestampWithTimezone(
                                singleItem.optLong("time", 0), singleItem.optString("timezone", null),
                                true /* seconds */);
                        viewItem.put("value", timeString == null ? "-" : timeString);
                    } else
                        viewItem.put("value", singleItem.optString("value", ""));
                    itemList.add(viewItem);
                }
            } else if (testType == ResultDetailType.QOS_TEST) {
                if (InformationCollector.qoSResult != null) {
                    int c = 0;
                    for (QoSTestResult nnResult : InformationCollector.qoSResult.getResults()) {
                        viewItem = new HashMap<String, String>();
                        viewItem.put("name", "TEST " + (c++) + "");
                        viewItem.put("value", nnResult.getTestType().name());
                        itemList.add(viewItem);

                        for (Entry<String, Object> item : nnResult.getResultMap().entrySet()) {
                            viewItem = new HashMap<String, String>();
                            viewItem.put("name", item.getKey());
                            viewItem.put("value", String.valueOf(item.getValue()));
                            itemList.add(viewItem);
                        }
                    }
                }

            }

        } catch (final JSONException e) {
            e.printStackTrace();
        }

        valueList = new SimpleAdapter(getActivity(), itemList, R.layout.test_result_detail_item,
                new String[] { "name", "value" }, new int[] { R.id.name, R.id.value });

        listView.setAdapter(valueList);

        listView.invalidate();

        progessBar.setVisibility(View.GONE);
        emptyView.setVisibility(View.GONE);
        listView.setVisibility(View.VISIBLE);

    } else {
        Log.i(DEBUG_TAG, "LEERE LISTE");
        progessBar.setVisibility(View.GONE);
        emptyView.setVisibility(View.VISIBLE);
        emptyView.setText(getString(R.string.error_no_data));
        emptyView.invalidate();
    }

}

From source file:org.opendatakit.tables.activities.TableManager.java

private void makeNoTableNotice() {
    List<HashMap<String, String>> fillMaps = new ArrayList<HashMap<String, String>>();
    HashMap<String, String> temp = new HashMap<String, String>();
    temp.put(TABLE_MANAGER_ROW_MAP_KEY_LABEL, getString(R.string.no_table_message));
    fillMaps.add(temp);// ww  w .j av  a2  s  .c  om
    arrayAdapter = new SimpleAdapter(this, fillMaps, R.layout.plain_list_row, from, to);
    this.mListFragment.setListAdapter(arrayAdapter);
}

From source file:com.pgmacdesign.lacunacompanion.fragments.MailFragment.java

public void refreshMail() {

    JSONObject hashOptions = new JSONObject();
    if (pageNum != 1)
        JsonParser.put(hashOptions, "page_number", pageNum);
    if (filterTag != "")
        JsonParser.put(hashOptions, "tags", filterTag);

    ClientSide.setContext(getActivity());
    JSONObject result = ClientSide.send(new Object[] { hashOptions }, "/inbox", "view_inbox");

    if (result != null) {
        JSONArray messages = JsonParser.getJA(result, "messages");
        List<Map<String, String>> mailList = new ArrayList<Map<String, String>>();
        ArrayList<String> mailIds = new ArrayList<String>(24); // Max numbers on each page is 25.

        boolean hasMail = false; // By default, so that there's no way to screw up.
        if (messages.length() > 0) {
            for (int i = 0; i < messages.length(); i++) {
                JSONObject message = JsonParser.getJO(messages, i);

                Map<String, String> datum = new HashMap<String, String>(2);
                datum.put("from", JsonParser.getS(message, "from"));
                datum.put("subject", JsonParser.getS(message, "subject"));
                mailList.add(datum);//ww w .ja va 2 s .  c  o m

                mailIds.add(JsonParser.getS(message, "id"));

                hasMail = true;
            }
        } else {
            Map<String, String> datum = new HashMap<String, String>(2);
            datum.put("from", "No new Mail available.");
            datum.put("subject", "Sorry. :(");
            mailList.add(datum);

            hasMail = false;
        }

        // Let the UI refresh when there's no mails.
        ListView mails = (ListView) getActivity().findViewById(R.id.mails);
        SimpleAdapter adapter = new SimpleAdapter(getActivity(), mailList, android.R.layout.simple_list_item_2,
                new String[] { "from", "subject" }, new int[] { android.R.id.text1, android.R.id.text2 });
        mails.setAdapter(adapter);

        if (hasMail == true) {
            final Object[] MAIL_IDS = mailIds.toArray();

            //spinnerReset = System.currentTimeMillis();
            mails.setOnItemClickListener(new OnItemClickListener() {
                public void onItemClick(AdapterView<?> a, View v, int pos, long id) {
                    //if (System.currentTimeMillis() - spinnerReset < 1000) {
                    //Nothing!
                    //}
                    //else if (System.currentTimeMillis() - spinnerReset > 1000) {
                    String mailId = MAIL_IDS[pos].toString();

                    Intent intent = new Intent(getActivity(),
                            com.pgmacdesign.lacunacompanion.module.inbox.ViewMail.class);
                    intent.putExtra("mailId", mailId);

                    getActivity().startActivity(intent);
                    //}
                }
            });

            // Populate the pages Spinner.
            ArrayAdapter<String> pagesSpinnerAdapter = new ArrayAdapter<String>(getActivity(),
                    android.R.layout.simple_spinner_item);
            adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
            Spinner mailPages = (Spinner) getActivity().findViewById(R.id.mailPage);
            double pages = (double) Math.ceil(JsonParser.getL(result, "message_count") / 25);

            for (int i = 1; i < pages; i++) {
                pagesSpinnerAdapter.add("" + i);
            }

            mailPages.setAdapter(pagesSpinnerAdapter);
            mailPages.recomputeViewAttributes(mailPages);
            mailPages.setSelection(pageNum - 1);
        }
    }
}

From source file:com.shafiq.myfeedle.core.SelectFriends.java

protected void loadFriends() {
    mFriends.clear();//ww w. j a  v a  2 s  . co m
    //      SimpleAdapter sa = new SimpleAdapter(SelectFriends.this, mFriends, R.layout.friend, new String[]{Entities.PROFILE, Entities.FRIEND, Entities.ESID}, new int[]{R.id.profile, R.id.name, R.id.selected});
    SimpleAdapter sa = new SimpleAdapter(SelectFriends.this, mFriends, R.layout.friend,
            new String[] { Entities.FRIEND, Entities.ESID }, new int[] { R.id.name, R.id.selected });
    setListAdapter(sa);
    final ProgressDialog loadingDialog = new ProgressDialog(this);
    final AsyncTask<Long, String, Boolean> asyncTask = new AsyncTask<Long, String, Boolean>() {
        @Override
        protected Boolean doInBackground(Long... params) {
            boolean loadList = false;
            MyfeedleCrypto myfeedleCrypto = MyfeedleCrypto.getInstance(getApplicationContext());
            // load the session
            Cursor account = getContentResolver().query(Accounts.getContentUri(SelectFriends.this),
                    new String[] { Accounts.TOKEN, Accounts.SECRET, Accounts.SERVICE }, Accounts._ID + "=?",
                    new String[] { Long.toString(params[0]) }, null);
            if (account.moveToFirst()) {
                mToken = myfeedleCrypto.Decrypt(account.getString(0));
                mSecret = myfeedleCrypto.Decrypt(account.getString(1));
                mService = account.getInt(2);
            }
            account.close();
            String response;
            switch (mService) {
            case TWITTER:
                break;
            case FACEBOOK:
                if ((response = MyfeedleHttpClient.httpResponse(mHttpClient, new HttpGet(
                        String.format(FACEBOOK_FRIENDS, FACEBOOK_BASE_URL, Saccess_token, mToken)))) != null) {
                    try {
                        JSONArray friends = new JSONObject(response).getJSONArray(Sdata);
                        for (int i = 0, l = friends.length(); i < l; i++) {
                            JSONObject f = friends.getJSONObject(i);
                            HashMap<String, String> newFriend = new HashMap<String, String>();
                            newFriend.put(Entities.ESID, f.getString(Sid));
                            newFriend.put(Entities.PROFILE, String.format(FACEBOOK_PICTURE, f.getString(Sid)));
                            newFriend.put(Entities.FRIEND, f.getString(Sname));
                            // need to alphabetize
                            if (mFriends.isEmpty())
                                mFriends.add(newFriend);
                            else {
                                String fullName = f.getString(Sname);
                                int spaceIdx = fullName.lastIndexOf(" ");
                                String newFirstName = null;
                                String newLastName = null;
                                if (spaceIdx == -1)
                                    newFirstName = fullName;
                                else {
                                    newFirstName = fullName.substring(0, spaceIdx++);
                                    newLastName = fullName.substring(spaceIdx);
                                }
                                List<HashMap<String, String>> newFriends = new ArrayList<HashMap<String, String>>();
                                for (int i2 = 0, l2 = mFriends.size(); i2 < l2; i2++) {
                                    HashMap<String, String> oldFriend = mFriends.get(i2);
                                    if (newFriend == null) {
                                        newFriends.add(oldFriend);
                                    } else {
                                        fullName = oldFriend.get(Entities.FRIEND);
                                        spaceIdx = fullName.lastIndexOf(" ");
                                        String oldFirstName = null;
                                        String oldLastName = null;
                                        if (spaceIdx == -1)
                                            oldFirstName = fullName;
                                        else {
                                            oldFirstName = fullName.substring(0, spaceIdx++);
                                            oldLastName = fullName.substring(spaceIdx);
                                        }
                                        if (newFirstName == null) {
                                            newFriends.add(newFriend);
                                            newFriend = null;
                                        } else {
                                            int comparison = oldFirstName.compareToIgnoreCase(newFirstName);
                                            if (comparison == 0) {
                                                // compare firstnames
                                                if (newLastName == null) {
                                                    newFriends.add(newFriend);
                                                    newFriend = null;
                                                } else if (oldLastName != null) {
                                                    comparison = oldLastName.compareToIgnoreCase(newLastName);
                                                    if (comparison == 0) {
                                                        newFriends.add(newFriend);
                                                        newFriend = null;
                                                    } else if (comparison > 0) {
                                                        newFriends.add(newFriend);
                                                        newFriend = null;
                                                    }
                                                }
                                            } else if (comparison > 0) {
                                                newFriends.add(newFriend);
                                                newFriend = null;
                                            }
                                        }
                                        newFriends.add(oldFriend);
                                    }
                                }
                                if (newFriend != null)
                                    newFriends.add(newFriend);
                                mFriends = newFriends;
                            }
                        }
                        loadList = true;
                    } catch (JSONException e) {
                        Log.e(TAG, e.toString());
                    }
                }
                break;
            case MYSPACE:
                break;
            case LINKEDIN:
                break;
            case FOURSQUARE:
                break;
            case IDENTICA:
                break;
            case GOOGLEPLUS:
                break;
            case CHATTER:
                break;
            }
            return loadList;
        }

        @Override
        protected void onPostExecute(Boolean loadList) {
            if (loadList) {
                //               SimpleAdapter sa = new SimpleAdapter(SelectFriends.this, mFriends, R.layout.friend, new String[]{Entities.PROFILE, Entities.FRIEND}, new int[]{R.id.profile, R.id.name});
                SimpleAdapter sa = new SimpleAdapter(SelectFriends.this, mFriends, R.layout.friend,
                        new String[] { Entities.FRIEND, Entities.ESID },
                        new int[] { R.id.name, R.id.selected });
                sa.setViewBinder(mViewBinder);
                setListAdapter(sa);
            }
            if (loadingDialog.isShowing())
                loadingDialog.dismiss();
        }
    };
    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(mAccountId);
}

From source file:be.evias.cloudLogin.FragmentNavigationDrawer.java

public void initializeNavigationAdapter() {
    List<HashMap<String, String>> navigation_items = new ArrayList<HashMap<String, String>>();
    navigation_items.add(new HashMap<String, String>() {
        {/*from   w  ww . jav  a  2  s.  co m*/
            put("icon", Integer.toString(R.drawable.icn_profile));
            put("text", mCurrentUser.getName());
            put("desc", mCurrentUser.getEmail());
        }
    });
    navigation_items.add(new HashMap<String, String>() {
        {
            put("icon", Integer.toString(R.drawable.icn_checkout));
            put("text", getString(R.string.title_logout));
            put("desc", getString(R.string.desc_logout));
        }
    });

    String[] keys = { "icon", "text", "desc" };
    int[] ids = { R.id.item_icon, R.id.item_text, R.id.item_description };

    SimpleAdapter adapter = new SimpleAdapter(getActionBar().getThemedContext(), navigation_items,
            R.layout.navigation_drawer_item, keys, ids);

    mDrawerListView.setAdapter(adapter);
    mDrawerListView.setItemChecked(mCurrentSelectedPosition, true);
}

From source file:com.saulcintero.moveon.fragments.Summary2.java

private void splitData(int nextDistance) {
    dataByUnits.clear();/* w  w w .  j av a2  s  .c  o m*/
    oldTime = 0;
    sumDistance = nextDistance;

    DBManager = new DataManager(mContext);
    DBManager.Open();
    cursor = DBManager.getRowsFromTable(String.valueOf(id), "locations");
    cursor.moveToFirst();
    if (cursor.getCount() > 0) {
        while (!cursor.isAfterLast()) {
            distance = cursor.getFloat(cursor.getColumnIndex("distance"));
            time = cursor.getInt(cursor.getColumnIndex("time"));

            if ((distance * 1000) >= (nextDistance + 10)) { // not shown 3
                // decimals, 10
                // units are
                // added to
                // filling the
                // hundred
                DataByUnits d = new DataByUnits();
                d.time = time - oldTime;
                oldTime = time;
                d.distance = sumDistance;

                dataByUnits.add(d);

                nextDistance += sumDistance;
            }
            cursor.moveToNext();
        }

        if ((distance > 0) && ((distance - dataByUnits.size()) > 0)) {
            DataByUnits d = new DataByUnits();
            d.time = time - oldTime;
            d.distance = (distance
                    + ((((distance * sumDistance) - (dataByUnits.size() * sumDistance)) / sumDistance)
                            / sumDistance));

            dataByUnits.add(d);

            writeValues();
        }
    }
    closeCursorAndDB();

    List<HashMap<String, String>> mList = new ArrayList<HashMap<String, String>>();
    for (int i = 0; i <= (dataByUnits.size() - 1); i++) {
        HashMap<String, String> hm = new HashMap<String, String>();
        hm.put("summary2_long_unit", options[i]);
        hm.put("summary2_time", options2[i]);
        hm.put("summary2_ritm", options3[i]);
        hm.put("summary2_icon", Integer.toString(icons[i]));
        mList.add(hm);
    }

    String[] from = { "summary2_icon", "summary2_long_unit", "summary2_time", "summary2_ritm" };
    int[] to = { R.id.summary2_icon, R.id.summary2_long_unit, R.id.summary2_time, R.id.summary2_ritm };

    SimpleAdapter adapter = new SimpleAdapter(mContext, mList, R.layout.summary2_list_row, from, to);
    summary2ListView.setAdapter(adapter);
}

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

private void redraw() {
    server_lst = db.getServers();/* w  w w. j a va  2 s.c  o  m*/

    List<Map<String, Object>> result = new ArrayList<Map<String, Object>>();
    Map<String, Object> server_line;

    for (ServerNode node : server_lst) {
        server_line = new HashMap<String, Object>();
        server_line.put("uri", node.uri);
        if (node.inuse) {
            server_line.put("inuse", R.drawable.btn_check_on);
        } else {
            server_line.put("inuse", R.drawable.btn_check_off);
        }
        server_line.put("napk", "Applications: " + node.napk);
        result.add(server_line);
    }
    SimpleAdapter show_out = new SimpleAdapter(this, result, R.layout.repolisticons,
            new String[] { "uri", "inuse", "napk" }, new int[] { R.id.uri, R.id.img, R.id.numberapks });

    setListAdapter(show_out);
}

From source file:ca.spencerelliott.mercury.Changesets.java

@Override
public void onCreate(Bundle bundle) {
    super.onCreate(bundle);

    this.requestWindowFeature(Window.FEATURE_PROGRESS);
    this.requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);

    setContentView(R.layout.changesets);

    //Cancel any notifications previously setup
    NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    nm.cancel(1);/*from  w  w  w.  j  a  v a 2  s. c  om*/

    //Create a new array list for the changesets
    changesets_list = new ArrayList<Map<String, ?>>();
    changesets_data = new ArrayList<Beans.ChangesetBean>();

    //Get the list view to store the changesets
    changesets_listview = (ListView) findViewById(R.id.changesets_list);

    TextView empty_text = (TextView) findViewById(R.id.changesets_empty_text);

    //Set the empty view
    changesets_listview.setEmptyView(empty_text);

    //Use a simple adapter to display the changesets based on the array list made earlier
    changesets_listview.setAdapter(new SimpleAdapter(this, changesets_list, R.layout.changeset_item,
            new String[] { COMMIT, FORMATTED_INFO },
            new int[] { R.id.changesets_commit, R.id.changesets_info }));

    //Set the on click listener
    changesets_listview.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> adapterview, View view, int position, long id) {
            Intent intent = new Intent(Changesets.this, ChangesetViewer.class);

            //Pass the changeset information to the changeset viewer
            Bundle params = new Bundle();
            params.putString("changeset_commit_text", changesets_data.get(position).getTitle());
            params.putString("changeset_changes", changesets_data.get(position).getContent());
            params.putLong("changeset_updated", changesets_data.get(position).getUpdated());
            params.putString("changeset_authors", changesets_data.get(position).getAuthor());
            params.putString("changeset_link", changesets_data.get(position).getLink());
            //params.putBoolean("is_https", is_https);

            intent.putExtras(params);

            startActivity(intent);
        }

    });

    //Register the list view for opening the context menu
    registerForContextMenu(changesets_listview);

    //Get the intent passed by the program
    if (getIntent() != null) {
        //Check to see if this is a search window
        if (Intent.ACTION_SEARCH.equals(getIntent().getAction())) {
            //Change the title of the activity and the empty text of the list so it looks like a search window
            this.setTitle(R.string.search_results_label);
            empty_text.setText(R.string.search_results_empty);

            //Retrieve the query the user entered
            String query = getIntent().getStringExtra(SearchManager.QUERY);

            //Convert the query to lower case
            query = query.toLowerCase();

            //Retrieve the bundle data
            Bundle retrieved_data = getIntent().getBundleExtra(SearchManager.APP_DATA);

            //If the bundle was passed, grab the changeset data
            if (retrieved_data != null) {
                changesets_data = retrieved_data
                        .getParcelableArrayList("ca.spencerelliott.mercury.SEARCH_DATA");
            }

            //If we're missing changeset data, stop here
            if (changesets_data == null)
                return;

            //Create a new array list to store the changesets that were a match
            ArrayList<Beans.ChangesetBean> search_beans = new ArrayList<Beans.ChangesetBean>();

            //Loop through each changeset
            for (Beans.ChangesetBean b : changesets_data) {
                //Check to see if any changesets match
                if (b.getTitle().toLowerCase().contains(query)) {
                    //Get the title and date of the commit
                    String commit_text = b.getTitle();
                    Date commit_date = new Date(b.getUpdated());

                    //Add a new changeset to display in the list view
                    changesets_list.add(createChangeset(
                            (commit_text.length() > 30 ? commit_text.substring(0, 30) + "..." : commit_text),
                            b.getRevisionID() + " - " + commit_date.toLocaleString()));

                    //Add this bean to the list of found search beans
                    search_beans.add(b);
                }
            }

            //Switch the changeset data over to the changeset data that was a match
            changesets_data = search_beans;

            //Update the list in the activity
            list_handler.sendEmptyMessage(SUCCESSFUL);

            //Notify the activity that it is a search window
            is_search_window = true;

            //Stop loading here
            return;
        }

        //Get the data from the intent
        Uri data = getIntent().getData();

        if (data != null) {
            //Extract the path in the intent
            String path_string = data.getEncodedPath();

            //Split it by the forward slashes
            String[] split_path = path_string.split("/");

            //Make sure a valid path was passed
            if (split_path.length == 3) {
                //Get the repository id from the intent
                repo_id = Long.parseLong(split_path[2].toString());
            } else {
                //Notify the user if there was a problem
                Toast.makeText(this, R.string.invalid_intent, 1000).show();
            }
        }
    }

    //Retrieve the changesets
    refreshChangesets();
}

From source file:com.google.cloud.solutions.flexenv.PlayActivity.java

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

    setContentView(R.layout.activity_play);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);//  w  ww .  j  av  a  2  s  .c om

    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawer, toolbar,
            R.string.navigation_drawer_open, R.string.navigation_drawer_close);
    drawer.setDrawerListener(toggle);
    toggle.syncState();

    NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
    channelMenu = navigationView.getMenu();
    navigationView.setNavigationItemSelectedListener(this);
    initChannels(getResources().getString(R.string.channels));

    GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
            .requestIdToken(getString(R.string.default_web_client_id)).requestEmail().build();
    mGoogleApiClient = new GoogleApiClient.Builder(this).enableAutoManage(this, this)
            .addApi(Auth.GOOGLE_SIGN_IN_API, gso).build();
    auth = FirebaseAuth.getInstance();
    authListener = new FirebaseAuth.AuthStateListener() {
        @Override
        public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
            FirebaseUser user = firebaseAuth.getCurrentUser();
            if (user != null) {
                inbox = "client-" + Integer.toString(Math.abs(user.getUid().hashCode()));
                Log.d(TAG, "onAuthStateChanged:signed_in:" + inbox);
                status.setText("Signin as " + user.getDisplayName());
                updateUI(true);
            } else {
                Log.d(TAG, "onAuthStateChanged:signed_out");
                updateUI(false);
            }
        }
    };
    SignInButton signInButton = (SignInButton) findViewById(R.id.sign_in_button);
    signInButton.setSize(SignInButton.SIZE_STANDARD);
    signInButton.setScopes(gso.getScopeArray());
    signInButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Intent signInIntent = Auth.GoogleSignInApi.getSignInIntent(mGoogleApiClient);
            // Start authenticating with Google ID first.
            startActivityForResult(signInIntent, RC_SIGN_IN);
        }
    });
    channelLabel = (TextView) findViewById(R.id.channelLabel);
    Button signOutButton = (Button) findViewById(R.id.sign_out_button);
    signOutButton.setOnClickListener(this);

    messages = new ArrayList<Map<String, String>>();
    messageAdapter = new SimpleAdapter(this, messages, android.R.layout.simple_list_item_2,
            new String[] { "message", "meta" }, new int[] { android.R.id.text1, android.R.id.text2 });
    messageHistory = (ListView) findViewById(R.id.messageHistory);
    messageHistory.setAdapter(messageAdapter);
    messageText = (EditText) findViewById(R.id.messageText);
    messageText.setOnKeyListener(this);
    fmt = new SimpleDateFormat("yy.MM.dd HH:mm z");

    status = (TextView) findViewById(R.id.status);

}