Example usage for android.widget ListView setAdapter

List of usage examples for android.widget ListView setAdapter

Introduction

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

Prototype

@Override
public void setAdapter(ListAdapter adapter) 

Source Link

Document

Sets the data behind this ListView.

Usage

From source file:com.esprit.droidcon.corruption.MusicNewsActivity.java

@Override
protected void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.maillist_layout);
    imageLoader = ImageLoader.getInstance();
    imageLoader.init(ImageLoaderConfiguration.createDefault(this));
    retry = (Button) findViewById(R.id.retry);
    ButterKnife.bind(this);
    mBackground = mImageView;/*from   w w  w .ja  va2s .  c  o m*/
    moveBackground();
    initToolbar();

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    connexionlay = (RelativeLayout) findViewById(R.id.connexionlay);

    mang = new ArrayList<>();

    final ListView listView = (ListView) findViewById(R.id.list_view);

    final ConnectivityManager conMgr = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
    final NetworkInfo activeNetwork = conMgr.getActiveNetworkInfo();
    if (activeNetwork != null && activeNetwork.isConnected()) {

        connexionlay.setVisibility(View.GONE);
        // notify user you are online
        final ParseQuery<ParseObject> query = ParseQuery.getQuery("Corruption");
        query.whereEqualTo("Type", "Bureau d ordre");
        query.findInBackground(new FindCallback<ParseObject>() {
            public void done(List<ParseObject> conThus, ParseException e) {
                if (e == null) {
                    //Log.d("score", "Retrieved " + scoreList.size() + " scores");
                    for (int i = conThus.size() - 1; i > 0; i--) {
                        ParseObject dong = conThus.get(i);
                        //System.out.println(dong.getParseFile("ImageFile").toString());
                        if (dong.getParseFile("AudioFile") != null) {
                            mang.add(new Corruption(dong.getString("Title"), dong.getString("Description"),
                                    dong.getString("Date"), dong.getString("Adress"),
                                    dong.getParseFile("Photo1").getUrl(), dong.getParseFile("Photo2").getUrl(),
                                    dong.getParseFile("Photo3").getUrl(),
                                    dong.getParseFile("AudioFile").getUrl(), dong.getDouble("Long"),
                                    dong.getDouble("Lat"), dong.getString("Heure"), dong.getString("Ville"),
                                    dong.getString("UserNom"), dong.getString("UserAdress"),
                                    dong.getString("UserTel"), dong.getString("UserMail"),
                                    dong.getString("Type"), dong.getString("VideoCode"), dong.getString("Etat")

                            ));

                            mGoogleCardsAdapter = new GoogleCardsTravelAdapter(getApplicationContext(), mang);
                            SwingBottomInAnimationAdapter swingBottomInAnimationAdapter = new SwingBottomInAnimationAdapter(
                                    mGoogleCardsAdapter);
                            swingBottomInAnimationAdapter.setAbsListView(listView);

                            assert swingBottomInAnimationAdapter.getViewAnimator() != null;
                            swingBottomInAnimationAdapter.getViewAnimator()
                                    .setInitialDelayMillis(INITIAL_DELAY_MILLIS);

                            listView.setClipToPadding(false);
                            listView.setDivider(null);
                            Resources r = getResources();
                            int px = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8,
                                    r.getDisplayMetrics());
                            listView.setDividerHeight(px);
                            listView.setFadingEdgeLength(0);
                            listView.setFitsSystemWindows(true);
                            px = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 12,
                                    r.getDisplayMetrics());
                            listView.setPadding(px, px, px, px);
                            listView.setScrollBarStyle(ListView.SCROLLBARS_OUTSIDE_OVERLAY);
                            listView.setAdapter(swingBottomInAnimationAdapter);

                            /*   SwingBottomInAnimationAdapter swingBottomInAnimationAdapter = new SwingBottomInAnimationAdapter(
                                     new SwipeDismissAdapter(mGoogleCardsAdapter, this));
                               swingBottomInAnimationAdapter.setAbsListView(listView);*/
                        } else

                        {
                            mang.add(new Corruption(dong.getString("Title"), dong.getString("Description"),
                                    dong.getString("Date"), dong.getString("Adress"),
                                    dong.getParseFile("Photo1").getUrl(), dong.getParseFile("Photo2").getUrl(),
                                    dong.getParseFile("Photo3").getUrl(), dong.getDouble("Long"),
                                    dong.getDouble("Lat"), dong.getString("Heure"), dong.getString("Ville"),
                                    dong.getString("UserNom"), dong.getString("UserAdress"),
                                    dong.getString("UserTel"), dong.getString("UserMail"),
                                    dong.getString("Type"), dong.getString("VideoCode"), dong.getString("Etat")

                            ));

                            mGoogleCardsAdapter = new GoogleCardsTravelAdapter(getApplicationContext(), mang);
                            SwingBottomInAnimationAdapter swingBottomInAnimationAdapter = new SwingBottomInAnimationAdapter(
                                    mGoogleCardsAdapter);
                            swingBottomInAnimationAdapter.setAbsListView(listView);

                            assert swingBottomInAnimationAdapter.getViewAnimator() != null;
                            swingBottomInAnimationAdapter.getViewAnimator()
                                    .setInitialDelayMillis(INITIAL_DELAY_MILLIS);

                            listView.setClipToPadding(false);
                            listView.setDivider(null);
                            Resources r = getResources();
                            int px = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8,
                                    r.getDisplayMetrics());
                            listView.setDividerHeight(px);
                            listView.setFadingEdgeLength(0);
                            listView.setFitsSystemWindows(true);
                            px = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 12,
                                    r.getDisplayMetrics());
                            listView.setPadding(px, px, px, px);
                            listView.setScrollBarStyle(ListView.SCROLLBARS_OUTSIDE_OVERLAY);
                            listView.setAdapter(swingBottomInAnimationAdapter);

                        }
                    }

                } else {
                    Log.d("score", "Error: " + e.getMessage());
                    Toast.makeText(getApplicationContext(), "Error: " + e.getMessage(), Toast.LENGTH_LONG)
                            .show();
                }
            }
        });

        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

                Corruption corp = (Corruption) parent.getItemAtPosition(position);
                SwipeImageAdapter.img1 = corp.getImage1();
                SwipeImageAdapter.img2 = corp.getImage2();
                SwipeImageAdapter.img3 = corp.getImage3();
                SwipeImageAdapter.title = corp.getTitle();
                SwipeImageAdapter.desc = corp.getDesc();
                //prodimg = prod.getProductImage();
                Intent i = new Intent(MusicNewsActivity.this, SingleCorruptionActivity.class);
                i.putExtra("audiourl", corp.getAudiofile());
                i.putExtra("longi", corp.getLongi());
                i.putExtra("title", corp.getTitle());
                i.putExtra("desc", corp.getDesc());
                i.putExtra("photourl", corp.getImage1());
                i.putExtra("lat", corp.getLat());
                i.putExtra("date", corp.getDate());
                i.putExtra("heure", corp.getHeure());
                i.putExtra("ville", corp.getVille());
                i.putExtra("usernom", corp.getUserNom());
                i.putExtra("useradress", corp.getUserAdress());
                i.putExtra("usertel", corp.getUserTel());
                i.putExtra("usermail", corp.getUserMail());
                i.putExtra("type", corp.getType());
                i.putExtra("videocode", corp.getVideo());
                i.putExtra("etat", corp.getEtat());

                startActivity(i);
                finish();

            }
        });

    } else {
        // notify user you are not online
        connexionlay.setVisibility(View.VISIBLE);
        retry.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                // fabProgressCircle.show();
                //  startYourAsynchronousJob();
                Intent refresh = new Intent(MusicNewsActivity.this, MusicNewsActivity.class);
                startActivity(refresh);
                finish();

            }
        });

    }

}

From source file:com.nttec.everychan.ui.presentation.BoardFragment.java

private void openReferencesList(final String from) {
    final List<Integer> positions = new ArrayList<>();
    int position = -1;
    for (int i = 0; i < presentationModel.presentationList.size(); ++i) {
        if (presentationModel.presentationList.get(i).sourceModel.number.equals(from)) {
            position = i;//  w  ww .j a v  a  2 s  .  com
            break;
        }
    }
    if (position != -1) {
        Spanned referencesString = presentationModel.presentationList.get(position).referencesString;
        if (referencesString == null) {
            Logger.e(TAG, "null referencesString");
            return;
        }
        ClickableURLSpan[] spans = referencesString.getSpans(0, referencesString.length(),
                ClickableURLSpan.class);
        for (ClickableURLSpan span : spans) {
            String url = span.getURL();
            try {
                //url    , .. ???  PresentationItemModel ( )
                UrlPageModel model = UrlHandler.getPageModel(url);
                for (; position < presentationModel.presentationList.size(); ++position) {
                    if (presentationModel.presentationList.get(position).sourceModel.number
                            .equals(model.postNumber)) {
                        break;
                    }
                }
                if (position < presentationModel.presentationList.size())
                    positions.add(position);
            } catch (Exception e) {
                Logger.e(TAG, e);
            }
        }
    }

    if (positions.size() == 0) {
        Logger.e(TAG, "no references");
        return;
    }

    final int bgShadowResource = ThemeUtils.getThemeResId(activity.getTheme(), R.attr.dialogBackgroundShadow);
    final int bgColor = ThemeUtils.getThemeColor(activity.getTheme(), R.attr.activityRootBackground,
            Color.BLACK);
    final View tmpV = new View(activity);
    final Dialog tmpDlg = new Dialog(activity);
    tmpDlg.getWindow().setBackgroundDrawableResource(bgShadowResource);
    tmpDlg.requestWindowFeature(Window.FEATURE_NO_TITLE);
    tmpDlg.setCanceledOnTouchOutside(true);
    tmpDlg.setContentView(tmpV);
    tmpDlg.show();
    Runnable next = new Runnable() {
        @Override
        public void run() {
            final int dlgWidth = tmpV.getWidth();
            tmpDlg.hide();
            tmpDlg.cancel();

            ListView dlgList = new ListView(activity);
            dlgList.setAdapter(new ArrayAdapter<Integer>(activity, 0, positions) {
                @Override
                public View getView(int position, View convertView, ViewGroup parent) {
                    try {
                        int adapterPositon = getItem(position);
                        View view = adapter.getView(adapterPositon, convertView, parent, dlgWidth,
                                adapter.getItem(adapterPositon), from);
                        view.setBackgroundColor(bgColor);
                        return view;
                    } catch (Exception e) {
                        Logger.e(TAG, e);
                        Toast.makeText(activity, R.string.error_unknown, Toast.LENGTH_LONG).show();
                        return new View(activity);
                    }
                }
            });

            Dialog dialog = new Dialog(activity);
            dialog.getWindow().setBackgroundDrawableResource(bgShadowResource);
            dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
            dialog.setCanceledOnTouchOutside(true);
            dialog.setContentView(dlgList);
            dialog.show();
            dialogs.add(dialog);
        }
    };
    if (tmpV.getWidth() != 0) {
        next.run();
    } else {
        AppearanceUtils.callWhenLoaded(tmpDlg.getWindow().getDecorView(), next);
    }
}

From source file:com.nttec.everychan.ui.presentation.BoardFragment.java

private void showThreadPreviewDialog(final int position) {
    final List<PresentationItemModel> items = new ArrayList<>();
    final int bgShadowResource = ThemeUtils.getThemeResId(activity.getTheme(), R.attr.dialogBackgroundShadow);
    final int bgColor = ThemeUtils.getThemeColor(activity.getTheme(), R.attr.activityRootBackground,
            Color.BLACK);//from  w w w .jav a  2  s.c  o m
    final View tmpV = new View(activity);
    final Dialog tmpDlg = new Dialog(activity);
    tmpDlg.getWindow().setBackgroundDrawableResource(bgShadowResource);
    tmpDlg.requestWindowFeature(Window.FEATURE_NO_TITLE);
    tmpDlg.setCanceledOnTouchOutside(true);
    tmpDlg.setContentView(tmpV);
    tmpDlg.show();
    Runnable next = new Runnable() {
        @Override
        public void run() {
            final int dlgWidth = tmpV.getWidth();
            tmpDlg.hide();
            tmpDlg.cancel();
            final Dialog dialog = new Dialog(activity);

            if (presentationModel.source != null && presentationModel.source.threads != null
                    && presentationModel.source.threads.length > position
                    && presentationModel.source.threads[position].posts != null
                    && presentationModel.source.threads[position].posts.length > 0) {

                final String threadNumber = presentationModel.source.threads[position].posts[0].number;

                ClickableURLSpan.URLSpanClickListener spanClickListener = new ClickableURLSpan.URLSpanClickListener() {
                    @Override
                    public void onClick(View v, ClickableURLSpan span, String url, String referer) {
                        if (url.startsWith("#")) {
                            try {
                                UrlPageModel threadPageModel = new UrlPageModel();
                                threadPageModel.chanName = chan.getChanName();
                                threadPageModel.type = UrlPageModel.TYPE_THREADPAGE;
                                threadPageModel.boardName = tabModel.pageModel.boardName;
                                threadPageModel.threadNumber = threadNumber;
                                url = chan.buildUrl(threadPageModel) + url;
                                dialog.dismiss();
                                UrlHandler.open(chan.fixRelativeUrl(url), activity);
                            } catch (Exception e) {
                                Logger.e(TAG, e);
                            }
                        } else {
                            dialog.dismiss();
                            UrlHandler.open(chan.fixRelativeUrl(url), activity);
                        }
                    }
                };

                AndroidDateFormat.initPattern();
                String datePattern = AndroidDateFormat.getPattern();
                DateFormat dateFormat = datePattern == null
                        ? DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT)
                        : new SimpleDateFormat(datePattern, Locale.US);
                dateFormat.setTimeZone(settings.isLocalTime() ? TimeZone.getDefault()
                        : TimeZone.getTimeZone(presentationModel.source.boardModel.timeZoneId));

                int postsCount = presentationModel.source.threads[position].postsCount;
                boolean showIndex = presentationModel.source.threads[position].posts.length <= postsCount;
                int curPostIndex = postsCount - presentationModel.source.threads[position].posts.length + 1;

                boolean openSpoilers = settings.openSpoilers();

                for (int i = 0; i < presentationModel.source.threads[position].posts.length; ++i) {
                    PresentationItemModel model = new PresentationItemModel(
                            presentationModel.source.threads[position].posts[i], chan.getChanName(),
                            presentationModel.source.pageModel.boardName,
                            presentationModel.source.pageModel.threadNumber, dateFormat, spanClickListener,
                            imageGetter, ThemeUtils.ThemeColors.getInstance(activity.getTheme()), openSpoilers,
                            floatingModels, null);
                    model.buildSpannedHeader(showIndex ? (i == 0 ? 1 : ++curPostIndex) : -1,
                            presentationModel.source.boardModel.bumpLimit,
                            presentationModel.source.boardModel.defaultUserName, null, false);
                    items.add(model);
                }
            } else {
                items.add(presentationModel.presentationList.get(position));
            }
            ListView dlgList = new ListView(activity);
            dlgList.setAdapter(new ArrayAdapter<PresentationItemModel>(activity, 0, items) {
                @Override
                public View getView(int position, View convertView, ViewGroup parent) {
                    View view = adapter.getView(position, convertView, parent, dlgWidth, getItem(position));
                    view.setBackgroundColor(bgColor);
                    return view;
                }
            });
            dialog.getWindow().setBackgroundDrawableResource(bgShadowResource);
            dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
            dialog.setCanceledOnTouchOutside(true);
            dialog.setContentView(dlgList);
            dialog.show();
            dialogs.add(dialog);
        }
    };
    if (tmpV.getWidth() != 0) {
        next.run();
    } else {
        AppearanceUtils.callWhenLoaded(tmpDlg.getWindow().getDecorView(), next);
    }
}

From source file:ch.blinkenlights.android.vanilla.LibraryPagerAdapter.java

@Override
public Object instantiateItem(ViewGroup container, int position) {
    int type = mTabOrder[position];
    ListView view = mLists[type];

    if (view == null) {
        LibraryActivity activity = mActivity;
        LayoutInflater inflater = activity.getLayoutInflater();
        LibraryAdapter adapter;//  ww  w .  ja v  a2s.c  o m
        DraggableRow header = null;

        switch (type) {
        case MediaUtils.TYPE_ARTIST:
            adapter = mArtistAdapter = new MediaAdapter(activity, MediaUtils.TYPE_ARTIST, mPendingArtistLimiter,
                    activity);
            mArtistAdapter.setExpandable(getMediaTypePosition(MediaUtils.TYPE_SONG) != -1
                    || getMediaTypePosition(MediaUtils.TYPE_ALBUM) != -1);
            header = (DraggableRow) inflater.inflate(R.layout.draggable_row, null);
            break;
        case MediaUtils.TYPE_ALBARTIST:
            adapter = mAlbArtAdapter = new MediaAdapter(activity, MediaUtils.TYPE_ALBARTIST,
                    mPendingAlbArtLimiter, activity);
            mAlbArtAdapter.setExpandable(getMediaTypePosition(MediaUtils.TYPE_SONG) != -1
                    || getMediaTypePosition(MediaUtils.TYPE_ALBUM) != -1);
            header = (DraggableRow) inflater.inflate(R.layout.draggable_row, null);
            break;
        case MediaUtils.TYPE_COMPOSER:
            adapter = mComposerAdapter = new MediaAdapter(activity, MediaUtils.TYPE_COMPOSER,
                    mPendingComposerLimiter, activity);
            mComposerAdapter.setExpandable(getMediaTypePosition(MediaUtils.TYPE_SONG) != -1
                    || getMediaTypePosition(MediaUtils.TYPE_ALBUM) != -1);
            header = (DraggableRow) inflater.inflate(R.layout.draggable_row, null);
            break;
        case MediaUtils.TYPE_ALBUM:
            adapter = mAlbumAdapter = new MediaAdapter(activity, MediaUtils.TYPE_ALBUM, mPendingAlbumLimiter,
                    activity);
            mAlbumAdapter.setExpandable(getMediaTypePosition(MediaUtils.TYPE_SONG) != -1);
            mPendingAlbumLimiter = null;
            header = (DraggableRow) inflater.inflate(R.layout.draggable_row, null);
            break;
        case MediaUtils.TYPE_SONG:
            adapter = mSongAdapter = new MediaAdapter(activity, MediaUtils.TYPE_SONG, mPendingSongLimiter,
                    activity);
            mPendingSongLimiter = null;
            header = (DraggableRow) inflater.inflate(R.layout.draggable_row, null);
            break;
        case MediaUtils.TYPE_PLAYLIST:
            adapter = mPlaylistAdapter = new MediaAdapter(activity, MediaUtils.TYPE_PLAYLIST, null, activity);
            break;
        case MediaUtils.TYPE_GENRE:
            adapter = mGenreAdapter = new MediaAdapter(activity, MediaUtils.TYPE_GENRE, null, activity);
            mGenreAdapter.setExpandable(getMediaTypePosition(MediaUtils.TYPE_SONG) != -1);
            break;
        case MediaUtils.TYPE_FILE:
            adapter = mFilesAdapter = new FileSystemAdapter(activity, mPendingFileLimiter);
            mPendingFileLimiter = null;
            header = (DraggableRow) inflater.inflate(R.layout.draggable_row, null);
            break;
        default:
            throw new IllegalArgumentException("Invalid media type: " + type);
        }

        view = (ListView) inflater.inflate(R.layout.listview, null);
        view.setOnCreateContextMenuListener(this);
        view.setOnItemClickListener(this);

        view.setTag(type);
        if (header != null) {
            header.setText(mHeaderText);
            header.setTag(new ViewHolder()); // behave like a normal library row
            view.addHeaderView(header);
            mHeaderViews.add(header);
        }
        view.setAdapter(adapter);

        loadSortOrder((SortableAdapter) adapter);

        adapter.setFilter(mFilter);

        mAdapters[type] = adapter;
        mLists[type] = view;
        mRequeryNeeded[type] = true;
    }

    requeryIfNeeded(type);
    container.addView(view);
    return view;
}

From source file:com.dragon4.owo.ar_trace.ARCore.MixView.java

public void initSearchbar() {
    final ListView searchListView = (ListView) mainArView.findViewById(R.id.ar_mixview_search_list);

    searchbar = (LinearLayout) mainArView.findViewById(R.id.ar_mixview_searchbar);
    hideSearchbar = (Button) mainArView.findViewById(R.id.ar_mixview_hide_searchbar);
    searchBtn = (Button) mainArView.findViewById(R.id.ar_mixview_search);
    searchBtn.setOnClickListener(new View.OnClickListener() {
        @Override//from w  w  w.j  a  v  a  2s.c  o  m
        public void onClick(View view) {
            parentButtonView.setVisibility(View.GONE);
            searchbar.setVisibility(View.VISIBLE);
        }
    });
    hideSearchbar.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            searchbar.setVisibility(View.GONE);
            parentButtonView.setVisibility(View.VISIBLE);
        }
    });

    searchText = (EditText) mainArView.findViewById(R.id.ar_mixview_search_text);
    searchText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView v, int actionId, android.view.KeyEvent event) {
            switch (actionId) {
            case EditorInfo.IME_ACTION_SEARCH:
                String queryString = searchText.getText().toString();
                Intent intent = new Intent(context, SearchKeywordListActivity.class);
                intent.putExtra("searchName", queryString);
                InputMethodManager imm = (InputMethodManager) context
                        .getSystemService(Context.INPUT_METHOD_SERVICE);
                imm.hideSoftInputFromWindow(mainArView.getWindowToken(), 0);
                mainArView.setVisibility(View.GONE);
                ((Activity) context).startActivityForResult(intent, SEARCH_LIST);
                break;
            default:
                Toast.makeText(context, "", Toast.LENGTH_LONG).show();
                return false;
            }
            return true;
        }
    });

    TextWatcher watcher = new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {

        }

        @Override
        public void onTextChanged(final CharSequence charSequence, int i, int i1, int i2) {
            new Thread(new Runnable() {
                @Override
                public void run() {
                    String queryString = searchText.getText().toString();
                    try {
                        List<ARMarker> searchList = null;
                        String encodedQueryString = URLEncoder.encode(queryString, "UTF-8");

                        String tempCallbackUrl = "http://ac.map.naver.com/ac?q=" + encodedQueryString
                                + "&st=10&r_lt=10&r_format=json";
                        String rawData = new NaverHttpHandler().execute(tempCallbackUrl).get();
                        Log.i("rawData", rawData);

                        JSONObject root = new JSONObject(rawData);
                        JSONArray dataArray = root.getJSONArray("items");
                        JSONArray locationData = dataArray.getJSONArray(0);

                        Log.i("dataArray", locationData.toString());

                        final ArrayList<String> list = new ArrayList<>();
                        for (int index = 0; index < locationData.length(); index++)
                            list.add(locationData.getString(index).substring(2,
                                    locationData.getString(index).length() - 2));

                        ((Activity) context).runOnUiThread(new Runnable() {
                            @Override
                            public void run() {
                                SearchViewAdapter adapter = new SearchViewAdapter(inflater);
                                adapter.setDataList(list);
                                adapter.setCurrentText(charSequence.toString());
                                searchListView.setAdapter(adapter);
                                searchListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                                    @Override
                                    public void onItemClick(AdapterView<?> adapterView, View view, int i,
                                            long l) {
                                        String queryString = list.get(i);
                                        searchText.setText(queryString);
                                    }
                                });
                            }
                        });
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    } catch (ExecutionException e) {
                        e.printStackTrace();
                    } catch (UnsupportedEncodingException e) {
                        e.printStackTrace();
                    } catch (JSONException e) {
                        e.printStackTrace();
                    }
                }
            }).start();
        }

        @Override
        public void afterTextChanged(Editable editable) {

        }
    };
    searchText.addTextChangedListener(watcher);
}

From source file:com.bayapps.android.robophish.ui.MediaBrowserFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    LogHelper.d(TAG, "fragment.onCreateView");

    View rootView;//  ww  w .  j  a va  2 s.  c o m

    String mediaId = getMediaId();
    ListView listView;

    if (mediaId != null && MediaIDHelper.isShow(mediaId)) {

        setHasOptionsMenu(true); //show option to download

        rootView = inflater.inflate(R.layout.fragment_list_show, container, false);

        ViewPager viewPager = (ViewPager) rootView.findViewById(R.id.viewpager);
        viewPager.setAdapter(new ShowPagerAdapter(inflater, rootView));
        viewPager.setOffscreenPageLimit(3);

        TabLayout tabLayout = (TabLayout) rootView.findViewById(R.id.sliding_tabs);
        tabLayout.setupWithViewPager(viewPager);

        final WebView setlist = (WebView) rootView.findViewById(R.id.setlist_webview);
        setlist.getSettings().setJavaScriptEnabled(true);

        AsyncHttpClient setlistClient = new AsyncHttpClient();
        RequestParams setlistParams = new RequestParams();
        setlistParams.put("api", "2.0");
        setlistParams.put("method", "pnet.shows.setlists.get");
        setlistParams.put("showdate", getSubTitle());
        setlistParams.put("apikey", "C01AEE2002E80723E9E7");
        setlistParams.put("format", "json");
        setlistClient.get("http://api.phish.net/api.js", setlistParams, new JsonHttpResponseHandler() {

            @Override
            public void onSuccess(int statusCode, Header[] headers, JSONArray response) {
                super.onSuccess(statusCode, headers, response);
                try {
                    JSONObject result = response.getJSONObject(0);
                    String city = result.getString("city");
                    String state = result.getString("state");
                    String country = result.getString("country");
                    String venue = result.getString("venue");

                    String header = "<h1>" + venue + "</h1>" + "<h2>" + city + ", " + state + "<br/>" + country
                            + "</h2>";

                    String setlistdata = result.getString("setlistdata");
                    String setlistnotes = result.getString("setlistnotes");
                    setlist.loadData(header + setlistdata + setlistnotes, "text/html", null);
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }

            @Override
            public void onFailure(int statusCode, Header[] headers, Throwable throwable,
                    JSONObject errorResponse) {
                super.onFailure(statusCode, headers, throwable, errorResponse);
            }
        });

        final WebView reviews = (WebView) rootView.findViewById(R.id.reviews_webview);
        reviews.getSettings().setJavaScriptEnabled(true);

        AsyncHttpClient reviewsClient = new AsyncHttpClient();
        RequestParams reviewsParams = new RequestParams();
        reviewsParams.put("api", "2.0");
        reviewsParams.put("method", "pnet.reviews.query");
        reviewsParams.put("showdate", getSubTitle());
        reviewsParams.put("apikey", "C01AEE2002E80723E9E7");
        reviewsParams.put("format", "json");
        reviewsClient.get("http://api.phish.net/api.js", reviewsParams, new JsonHttpResponseHandler() {

            @Override
            public void onSuccess(int statusCode, Header[] headers, JSONArray response) {
                super.onSuccess(statusCode, headers, response);
                try {
                    String display = "";

                    int len = response.length();
                    for (int i = 0; i < len; i++) {
                        JSONObject entry = response.getJSONObject(i);
                        String author = entry.getString("author");
                        String review = entry.getString("review");
                        String tstamp = entry.getString("tstamp");

                        Date reviewTime = new Date(Long.parseLong(tstamp) * 1000);
                        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                        String reviewDate = dateFormat.format(reviewTime);

                        String reviewSubs = review.replaceAll("\n", "<br/>");

                        display += "<h2>" + author + "</h2>" + "<h4>" + reviewDate + "</h4>";
                        display += reviewSubs + "<br/>";
                    }

                    reviews.loadData(display, "text/html", null);
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }

            @Override
            public void onFailure(int statusCode, Header[] headers, Throwable throwable,
                    JSONObject errorResponse) {
                super.onFailure(statusCode, headers, throwable, errorResponse);
            }
        });

        final WebView tapernotesWebview = (WebView) rootView.findViewById(R.id.tapernotes_webview);
        tapernotesWebview.getSettings().setJavaScriptEnabled(true);

        String showId = extractShowFromMediaID(mediaId);
        final AsyncHttpClient tapernotesClient = new AsyncHttpClient();
        tapernotesClient.get("http://phish.in/api/v1/shows/" + showId + ".json", null,
                new JsonHttpResponseHandler() {

                    @Override
                    public void onSuccess(int statusCode, Header[] headers, JSONObject response) {
                        super.onSuccess(statusCode, headers, response);
                        try {
                            mShowData = response;
                            JSONObject data = response.getJSONObject("data");
                            String tapernotes = data.getString("taper_notes");
                            if (tapernotes.equals("null"))
                                tapernotes = "Not available";
                            String notesSubs = tapernotes.replaceAll("\n", "<br/>");

                            tapernotesWebview.loadData(notesSubs, "text/html", null);
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                    }

                    @Override
                    public void onFailure(int statusCode, Header[] headers, Throwable throwable,
                            JSONObject errorResponse) {
                        super.onFailure(statusCode, headers, throwable, errorResponse);
                    }
                });

    } else {
        rootView = inflater.inflate(R.layout.fragment_list, container, false);
    }

    mErrorView = rootView.findViewById(R.id.playback_error);
    mErrorMessage = (TextView) mErrorView.findViewById(R.id.error_message);

    mBrowserAdapter = new BrowseAdapter(getActivity());

    listView = (ListView) rootView.findViewById(R.id.list_view);
    listView.setAdapter(mBrowserAdapter);
    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            checkForUserVisibleErrors(false);
            MediaBrowserCompat.MediaItem item = mBrowserAdapter.getItem(position);
            mMediaFragmentListener.onMediaItemSelected(item);
        }
    });

    return rootView;
}

From source file:com.rfo.basic.Run.java

private void doDebugSwapDialog() {

    ArrayList<String> msg = new ArrayList<String>();
    msg.addAll(Arrays.asList("Program", "Scalars", "Array", "List", "Stack", "Bundle", "Watch"));
    final String[] names = { "View Program", "View Scalars", "View Array", "View List", "View Stack",
            "View Bundle", "View Watch", "View Console" };

    LayoutInflater inflater = getLayoutInflater();
    View dialogLayout = inflater.inflate(R.layout.debug_list_s_layout, null);

    ListView debugView = (ListView) dialogLayout.findViewById(R.id.debug_list_s);
    debugView.setAdapter(new ArrayAdapter<String>(Run.this, R.layout.simple_list_layout_1, msg));
    debugView.setVerticalScrollBarEnabled(true);
    debugView.setClickable(true);//  ww  w . j  av  a2  s . c  om

    debugView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            DialogSelector(position);
            boolean dosel = (dbDialogArray && WatchedArray == null) || (dbDialogList && WatchedList == -1)
                    || (dbDialogStack && WatchedStack == -1) || (dbDialogBundle && WatchedBundle == -1);
            if (dosel) {
                // if the element has not been defined ask if user wishes to do so.
                // or at least this is where it will go.
                // for now, default to view program.
                DialogSelector(0);
                position = 0;
            }
            String name = (position < names.length) ? names[position] : "";
            Toaster(name).show();
        }
    });

    AlertDialog.Builder builder = new AlertDialog.Builder(Run.this).setCancelable(true).setTitle("Select View:")
            .setView(dialogLayout);

    builder.setOnCancelListener(new DialogInterface.OnCancelListener() {
        public void onCancel(DialogInterface arg0) {
            WaitForSwap = false;
        }
    });

    builder.setPositiveButton("Confirm", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            WaitForSwap = false;
            dbSwap = false;
        }
    });

    /*  // leave out until the element selector is done.
          builder.setNeutralButton("Choose Element",
             new DialogInterface.OnClickListener() {
    public void onClick(DialogInterface dialog,int which) {
       WaitForSelect = true;
    }
             });
    */
    dbSwapDialog = builder.show();
    dbSwapDialog.getWindow().setLayout(WindowManager.LayoutParams.MATCH_PARENT,
            WindowManager.LayoutParams.MATCH_PARENT);
}

From source file:com.rfo.basic.Run.java

private void doDebugDialog() {

    int lineIndex = 0;
    String text = "";
    if (mInterpreter != null) {
        lineIndex = mInterpreter.ExecutingLineIndex;
        text = mInterpreter.ExecutingLineBuffer.text();
    }//from   w  w  w.  j ava 2s .  co m

    ArrayList<String> msg = new ArrayList<String>();

    if (!dbDialogProgram) {
        msg = mInterpreter.dbDoFunc();
        msg.add("Executable Line #:    " + Integer.toString(lineIndex + 1) + '\n' + chomp(text));
    }

    if (dbDialogScalars)
        msg.addAll(mInterpreter.dbDoScalars("  "));
    if (dbDialogArray)
        msg.addAll(mInterpreter.dbDoArray("  "));
    if (dbDialogList)
        msg.addAll(mInterpreter.dbDoList("  "));
    if (dbDialogStack)
        msg.addAll(mInterpreter.dbDoStack("  "));
    if (dbDialogBundle)
        msg.addAll(mInterpreter.dbDoBundle("  "));
    if (dbDialogWatch)
        msg.addAll(mInterpreter.dbDoWatch("  "));

    if (dbDialogProgram) {
        for (int i = 0; i < Basic.lines.size(); ++i) {
            msg.add(((i == lineIndex) ? " >>" : "   ") // mark current line
                    + (i + 1) + ": " // one-based line index
                    + chomp(Basic.lines.get(i).text())); // remove newline
        }
    }

    LayoutInflater inflater = getLayoutInflater();
    View dialogLayout = inflater.inflate(R.layout.debug_dialog_layout, null);

    ListView debugView = (ListView) dialogLayout.findViewById(R.id.debug_list);
    debugView.setAdapter(new ArrayAdapter<String>(Run.this, R.layout.debug_list_layout, msg));
    debugView.setVerticalScrollBarEnabled(true);
    if (dbDialogProgram) {
        debugView.setSelection(lineIndex);
    }

    AlertDialog.Builder builder = new AlertDialog.Builder(Run.this).setCancelable(true)
            .setTitle(R.string.debug_name).setView(dialogLayout);

    builder.setOnCancelListener(new DialogInterface.OnCancelListener() {
        public void onCancel(DialogInterface arg0) {
            DebuggerHalt = true;
            WaitForDebugResume = false;
            releaseDebugLOCK();
        }
    });

    builder.setPositiveButton("Resume", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            WaitForDebugResume = false;
            releaseDebugLOCK();
        }
    });

    builder.setNeutralButton("Step", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            DebuggerStep = true;
            WaitForDebugResume = true;
            releaseDebugLOCK();
        }
    });

    builder.setNegativeButton("View Swap", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            dbSwap = true;
            releaseDebugLOCK();
        }
    });

    dbDialog = builder.show();
    dbDialog.getWindow().setLayout(WindowManager.LayoutParams.MATCH_PARENT,
            WindowManager.LayoutParams.MATCH_PARENT);
}

From source file:com.android.vending.billing.InAppBillingService.LACK.listAppsFragment.java

public void getDir(String paramString, ListView paramListView, boolean paramBoolean) {
      System.out.println("dir get");
      this.myPath.setText("Location: " + paramString);
      ArrayList localArrayList = new ArrayList();
      File localFile = new File(paramString);
      File[] arrayOfFile = localFile.listFiles();
      if (arrayOfFile == null) {
          System.out.println("null files for start dir list");
      }/*from   w w  w  .  j a  v a 2s .c om*/
      if (!paramString.equals(this.root)) {
          localArrayList.add(new ItemFile(this.root));
          localArrayList.add(new ItemFile("../", localFile.getParent()));
      }
      for (;;) {
          int j = arrayOfFile.length;
          int i = 0;
          while (i < j) {
              paramString = arrayOfFile[i];
              if ((paramString.canRead())
                      && ((paramString.isDirectory()) || (paramString.toString().toLowerCase().endsWith(".apk"))
                              || (paramString.toString().toLowerCase().endsWith(".odex"))
                              || (paramString.toString().toLowerCase().endsWith(".jar"))
                              || (paramString.toString().toLowerCase().endsWith(".oat")))) {
                  localArrayList.add(new ItemFile(paramString.toString()));
              }
              i += 1;
          }
          System.out.println("root " + this.root);
          if ((!this.root.equals(basepath)) && (paramBoolean)) {
              localArrayList.add(new ItemFile(basepath));
          }
      }
      paramString = new ArrayAdapter(getContext(), 2130968615, localArrayList) {
          public View getView(int paramAnonymousInt, View paramAnonymousView, ViewGroup paramAnonymousViewGroup) {
              listAppsFragment.ItemFile localItemFile = (listAppsFragment.ItemFile) getItem(paramAnonymousInt);
              View localView = paramAnonymousView;
              paramAnonymousView = localView;
              if (localView == null) {
                  paramAnonymousView = ((LayoutInflater) listAppsFragment.getInstance()
                          .getSystemService("layout_inflater")).inflate(2130968615, paramAnonymousViewGroup,
                                  false);
              }
              paramAnonymousViewGroup = (TextView) paramAnonymousView.findViewById(2131558562);
              paramAnonymousViewGroup.setTextAppearance(getContext(), listAppsFragment.getSizeText());
              paramAnonymousViewGroup.setText(localItemFile.file);
              paramAnonymousViewGroup = (ImageView) paramAnonymousView.findViewById(2131558561);
              if ((paramAnonymousInt == 0) || (paramAnonymousInt == 1)) {
              }
              try {
                  if ((getCount() > 1) && (((listAppsFragment.ItemFile) getItem(1)).file.equals("../"))) {
                      paramAnonymousViewGroup.setImageDrawable(listAppsFragment.getRes().getDrawable(2130837545));
                      return paramAnonymousView;
                  }
                  if (new File(localItemFile.full).isDirectory()) {
                      paramAnonymousViewGroup.setImageDrawable(listAppsFragment.getRes().getDrawable(2130837546));
                      return paramAnonymousView;
                  }
              } catch (Exception paramAnonymousViewGroup) {
                  paramAnonymousViewGroup.printStackTrace();
                  return paramAnonymousView;
                  paramAnonymousViewGroup.setImageDrawable(listAppsFragment.getRes().getDrawable(2130837547));
                  return paramAnonymousView;
              } catch (OutOfMemoryError paramAnonymousViewGroup) {
                  paramAnonymousViewGroup.printStackTrace();
                  System.gc();
              }
              return paramAnonymousView;
          }
      };
      paramString.sort(new byNameFile());
      paramListView.setAdapter(paramString);
      paramString.notifyDataSetChanged();
  }