Example usage for android.widget ListAdapter ListAdapter

List of usage examples for android.widget ListAdapter ListAdapter

Introduction

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

Prototype

ListAdapter

Source Link

Usage

From source file:com.rareventure.gps2.reviewer.map.OsmMapGpsTrailerReviewerMapActivity.java

private void initSasPanel() {
    ListView sasPanelList = (ListView) findViewById(R.id.sas_grid);

    sasPanelList.setOnItemClickListener(new OnItemClickListener() {

        private static final int MIN_TR_TIMESPAN_SEC = Util.SECONDS_IN_DAY;
        private static final int TR_TIMESPAN_MULTIPLIER = 3;

        @Override//w  w w.ja  va  2s.c  om
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            //note that getTimeRange reuses the same tr instance, so we have to be careful
            // when we call it twice
            TimeRange tr = gpsTrailerOverlay.sas.getTimeRange(position - 1);

            int currStartSec = tr.startTimeSec;
            int currEndSec = tr.endTimeSec;

            //co: we just want the time inside the box
            //            int timeSpan;
            //            
            //            if(tr.fullRangeEndSec - tr.fullRangeStartSec < MIN_TR_TIMESPAN_SEC / TR_TIMESPAN_MULTIPLIER)
            //            {
            //               timeSpan = MIN_TR_TIMESPAN_SEC;
            //            }
            //            else
            //            {
            //               timeSpan = (tr.fullRangeEndSec - tr.fullRangeStartSec) * TR_TIMESPAN_MULTIPLIER;
            //            }
            //            
            //            int currStartSec = (int) Math.max(- timeSpan /2 + (tr.endTimeSec/2 + tr.startTimeSec/2), getStartTimeMs()/1000);
            //            int currEndSec = (int) Math.min(timeSpan /2 + (tr.endTimeSec/2 + tr.startTimeSec/2), getEndTimeMs()/1000);
            //            
            //            if(position > 0)
            //            {
            //               TimeRange prevTr = gpsTrailerOverlay.sas.getTimeRange(position-1);
            //               currStartSec = Math.max(prevTr.endTimeSec, currStartSec);
            //            }
            //            
            //            if(position < gpsTrailerOverlay.sas.getTimeRangeCount() - 1)
            //            {
            //               TimeRange nextTr = gpsTrailerOverlay.sas.getTimeRange(position+1);
            //               currEndSec = Math.min(nextTr.startTimeSec, currEndSec);
            //            }
            //            
            if (currEndSec - currStartSec < timeView.getMinSelectableTimeSec()) {
                currEndSec = currStartSec + timeView.getMinSelectableTimeSec();
            }

            setStartAndEndTimeSec(currStartSec, currEndSec);
            updateTimeViewTime();

        }
    });

    sasPanelList.setAdapter(new ListAdapter() {

        @Override
        public void unregisterDataSetObserver(DataSetObserver observer) {
            gpsTrailerOverlay.sas.unregisterDataSetObserver(observer);

        }

        @Override
        public void registerDataSetObserver(DataSetObserver observer) {
            gpsTrailerOverlay.sas.registerDataSetObserver(observer);
        }

        @Override
        public boolean isEmpty() {
            return gpsTrailerOverlay.sas.isEmpty();
        }

        @Override
        public boolean hasStableIds() {
            return false; //because we might merge timeviews
        }

        @Override
        public int getViewTypeCount() {
            return 2;
        }

        public View getView(int position, View convertView, ViewGroup parent) {
            if (convertView == null) {
                //               Log.d(GTG.TAG,"SASPanel: Creating new view");
                if (position == 0)
                    convertView = getLayoutInflater().inflate(R.layout.selected_area_info_top_row, null);
                else
                    convertView = getLayoutInflater().inflate(R.layout.selected_area_info_row, null);
            }
            //            else
            //               Log.d(GTG.TAG,"SASPanel: Reusing view");

            if (position == 0) {
                ((TextView) convertView.findViewById(R.id.totalTime))
                        .setText(Util.convertMsToText(gpsTrailerOverlay.sas.getTotalTimeSecs() * 1000l));
                ((TextView) convertView.findViewById(R.id.totalDist)).setText(MapScaleWidget
                        .calcLabelForLength(gpsTrailerOverlay.sas.getTotalDistM(), GTG.prefs.useMetric));
                ((TextView) convertView.findViewById(R.id.timesInArea))
                        .setText(String.valueOf(gpsTrailerOverlay.sas.getTimesInArea()));
                ((TextView) convertView.findViewById(R.id.timesInArea))
                        .setText(String.valueOf(gpsTrailerOverlay.sas.getTimesInArea()));

                TimeZone tz = gpsTrailerOverlay.sas.timeZone;

                if (tz == null || tz.hasSameRules(Util.getCurrTimeZone())) {
                    convertView.findViewById(R.id.timeZoneTableRow).setVisibility(View.GONE);
                } else {
                    convertView.findViewById(R.id.timeZoneTableRow).setVisibility(View.VISIBLE);
                    ((TextView) convertView.findViewById(R.id.timezone)).setText(tz.getDisplayName());
                }

                return convertView;
            }

            TimeRange tr = gpsTrailerOverlay.sas.getTimeRange(position - 1);

            timeAndDateSdf.setTimeZone(gpsTrailerOverlay.sas.timeZone);

            String startText = timeAndDateSdf.format(new Date(tr.startTimeSec * 1000l));
            String endText = timeAndDateSdf.format(new Date(tr.endTimeSec * 1000l));

            ((TextView) convertView.findViewById(R.id.startTime)).setText(startText);
            ((TextView) convertView.findViewById(R.id.endTime)).setText(endText);

            String distText;
            if (tr.dist == -1)
                distText = "--";
            else {
                distText = MapScaleWidget.calcLabelForLength(tr.dist, GTG.prefs.useMetric);
            }

            ((TextView) convertView.findViewById(R.id.distance)).setText(distText);

            //this fixes a bug where sometimes if the last row is deleted and readded, it isn't
            //layedout again, causing the date/times to be cut off
            convertView.requestLayout();

            //            ((TextView)convertView.findViewById(R.id.timeLength)).setText("a certain amount of time");

            return convertView;
        }

        @Override
        public int getItemViewType(int position) {
            if (position == 0)
                return 0;
            return 1;
        }

        @Override
        public long getItemId(int position) {
            if (position == 0)
                return Long.MIN_VALUE;

            TimeRange tr = gpsTrailerOverlay.sas.getTimeRange(position - 1);

            return tr.fullRangeStartSec;
        }

        @Override
        public Object getItem(int position) {
            if (position == 0)
                return null;
            return gpsTrailerOverlay.sas.getTimeRange(position - 1);
        }

        @Override
        public int getCount() {
            int count = gpsTrailerOverlay.sas.getTimeRangeCount();
            //            Log.d(GTG.TAG,"item count is "+count);

            if (count >= 1)
                return count + 1;
            return 0;
        }

        @Override
        public boolean isEnabled(int position) {
            if (position == 0)
                return false;
            return true;
        }

        @Override
        public boolean areAllItemsEnabled() {
            return false;
        }
    });
}

From source file:com.htc.dotdesign.ToolBoxService.java

private void initMenu() {
    if (mMenu != null) {
        ListView menuListView = (ListView) mMenu.findViewById(R.id.menu);
        menuListView.setAdapter(new ListAdapter() {

            @Override/*from   www . j av a 2  s. co m*/
            public void unregisterDataSetObserver(DataSetObserver observer) {
            }

            @Override
            public void registerDataSetObserver(DataSetObserver observer) {
            }

            @Override
            public boolean isEmpty() {
                return false;
            }

            @Override
            public boolean hasStableIds() {
                return true;
            }

            @Override
            public int getViewTypeCount() {
                return 1;
            }

            @Override
            public View getView(int position, View convertView, ViewGroup parent) {
                View listItem = convertView;
                if (listItem == null) {
                    LayoutInflater inflater = (LayoutInflater) getSystemService(
                            Context.LAYOUT_INFLATER_SERVICE);
                    listItem = inflater.inflate(R.layout.menu_listitem, null);
                }
                TextView text = (TextView) listItem.findViewById(R.id.item_text);

                switch (position) {
                case MENU_ITEM_CLEAR_ALL:
                    text.setText(R.string.menu_clean_all);
                    break;
                case MENU_ITEM_INSERT_IMAGES:
                    text.setText(R.string.menu_insert);
                    break;
                case MENU_ITEM_SET_THEME:
                    text.setText(R.string.menu_set_theme);
                    break;
                case MENU_ITEM_SHARE:
                    text.setText(R.string.menu_share);
                    break;
                case MENU_ITEM_EXIT:
                    text.setText(R.string.menu_exit);
                    break;
                default:
                    break;
                }
                return listItem;
            }

            @Override
            public int getItemViewType(int position) {
                return 0;
            }

            @Override
            public long getItemId(int position) {
                return position;
            }

            @Override
            public Object getItem(int position) {
                return position;
            }

            @Override
            public int getCount() {
                return 5;
            }

            @Override
            public boolean isEnabled(int position) {
                return true;
            }

            @Override
            public boolean areAllItemsEnabled() {
                return true;
            }
        });

        menuListView.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                Log.d(DotDesignConstants.LOG_TAG,
                        LOG_PREFIX + "onItemClick, position: " + position + ", id: " + id);
                Intent intent = new Intent(TOOL_BAR_ACTION_STATUS);
                intent.putExtra(EXTRA_CURR_FUNC, FunType.Fun_Menu);
                switch (position) {
                case MENU_ITEM_CLEAR_ALL:
                    intent.putExtra(EXTRA_MENNU_ITEM, MENU_ITEM_CLEAR_ALL_STR);
                    break;
                case MENU_ITEM_INSERT_IMAGES:
                    intent.putExtra(EXTRA_MENNU_ITEM, MENU_ITEM_INSERT_IMAGES_STR);
                    break;
                case MENU_ITEM_SET_THEME:
                    intent.putExtra(EXTRA_MENNU_ITEM, MENU_ITEM_SET_THEME_STR);
                    break;
                case MENU_ITEM_SHARE:
                    intent.putExtra(EXTRA_MENNU_ITEM, MENU_ITEM_SHARE_STR);
                    break;
                case MENU_ITEM_EXIT:
                    intent.putExtra(EXTRA_MENNU_ITEM, MENU_ITEM_EXIT_STR);
                    showHideToolbar(false);
                    break;
                default:
                    break;
                }
                mLocalBroadcastManager.sendBroadcast(intent);
                setToolPanelVisibility(false);
            }
        });
    }
}

From source file:com.juick.android.MessageMenu.java

protected void runActions() {
    if (!isDialogMode()) {
        AlertDialog.Builder builder = new AlertDialog.Builder(activity);
        final CharSequence[] items = new CharSequence[menuActions.size()];
        for (int j = 0; j < items.length; j++) {
            items[j] = menuActions.get(j).title;
        }/*  w  w  w  .j  a v a 2 s.  co m*/
        builder.setItems(items, this);
        final AlertDialog alertDialog = builder.create();
        alertDialog.setOnShowListener(new DialogInterface.OnShowListener() {
            @Override
            public void onShow(DialogInterface dialog) {
                ColorsTheme.ColorTheme colorTheme = JuickMessagesAdapter.getColorTheme(activity);
                ColorDrawable divider = new ColorDrawable(
                        colorTheme.getColor(ColorsTheme.ColorKey.COMMON_BACKGROUND, 0xFFFFFFFF));
                alertDialog.getListView().setDivider(divider);
                alertDialog.getListView().setDividerHeight(1);
            }
        });
        alertDialog.show();

        final ListAdapter adapter = alertDialog.getListView().getAdapter();
        SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(activity);
        float menuFontScale = 1;
        try {
            menuFontScale = Float.parseFloat(sp.getString("menuFontScale", "1.0"));
        } catch (Exception e) {
            e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
        }
        final boolean compressedMenu = sp.getBoolean("compressedMenu", false);
        final boolean singleLineMenu = sp.getBoolean("singleLineMenu", false);
        final float finalMenuFontScale = menuFontScale;
        final int screenHeight = activity.getWindow().getWindowManager().getDefaultDisplay().getHeight();
        alertDialog.getListView().setAdapter(new ListAdapter() {
            @Override
            public boolean areAllItemsEnabled() {
                return adapter.areAllItemsEnabled();
            }

            @Override
            public boolean isEnabled(int position) {
                return adapter.isEnabled(position);
            }

            @Override
            public void registerDataSetObserver(DataSetObserver observer) {
                adapter.registerDataSetObserver(observer);
            }

            @Override
            public void unregisterDataSetObserver(DataSetObserver observer) {
                adapter.unregisterDataSetObserver(observer);
            }

            @Override
            public int getCount() {
                return items.length;
            }

            @Override
            public Object getItem(int position) {
                return adapter.getItem(position);
            }

            @Override
            public long getItemId(int position) {
                return adapter.getItemId(position);
            }

            @Override
            public boolean hasStableIds() {
                return adapter.hasStableIds();
            }

            @Override
            public View getView(int position, View convertView, ViewGroup parent) {
                View retval = adapter.getView(position, null, parent);
                if (retval instanceof TextView) {
                    TextView tv = (TextView) retval;
                    if (compressedMenu) {
                        int minHeight = (int) ((screenHeight * 0.7) / getCount());
                        tv.setMinHeight(minHeight);
                        tv.setMinimumHeight(minHeight);
                    }
                    if (singleLineMenu) {
                        tv.setSingleLine(true);
                        tv.setEllipsize(TextUtils.TruncateAt.MIDDLE);
                    }
                    tv.setTextSize(22 * finalMenuFontScale);
                }
                return retval;
            }

            @Override
            public int getItemViewType(int position) {
                return adapter.getItemViewType(position);
            }

            @Override
            public int getViewTypeCount() {
                return adapter.getViewTypeCount();
            }

            @Override
            public boolean isEmpty() {
                return adapter.isEmpty();
            }
        });
    } else {
        AlertDialog.Builder builder = new AlertDialog.Builder(
                new ContextThemeWrapper(activity, R.style.Theme_Sherlock));
        View dialogView = activity.getLayoutInflater().inflate(R.layout.message_menu2, null);
        builder.setView(dialogView);
        builder.setCancelable(true);
        int width = activity.getWindowManager().getDefaultDisplay().getWidth();
        View scrollView = dialogView.findViewById(R.id.scrollView);
        scrollView.getLayoutParams().width = (int) (width * 0.90);
        final AlertDialog alertDialog = builder.create();
        alertDialog.setOnShowListener(new DialogInterface.OnShowListener() {
            @Override
            public void onShow(DialogInterface dialog) {
                //MainActivity.restyleChildrenOrWidget(alertDialog.getWindow().getDecorView());
            }
        });
        TextView messageNo = (TextView) dialogView.findViewById(R.id.message_no);
        messageNo.setText(listSelectedItem.getDisplayMessageNo());
        Spinner openUrl = (Spinner) dialogView.findViewById(R.id.open_url);
        Button singleURL = (Button) dialogView.findViewById(R.id.single_url);
        if (urls != null && urls.size() == 1) {
            singleURL.setVisibility(View.VISIBLE);
            openUrl.setVisibility(View.GONE);
            SpannableStringBuilder sb = new SpannableStringBuilder();
            sb.append(urls.get(0));
            sb.setSpan(new UnderlineSpan(), 0, sb.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
            singleURL.setText(sb);
            singleURL.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    alertDialog.dismiss();
                    launchURL(listSelectedItem.getMID(), urls.get(0));
                }
            });
        } else if (urls != null && urls.size() > 0) {
            singleURL.setVisibility(View.GONE);
            openUrl.setVisibility(View.VISIBLE);
            openUrl.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
                @Override
                public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                    if (position != 0) {
                        alertDialog.dismiss();
                        launchURL(listSelectedItem.getMID(), urls.get(position));
                    }
                }

                @Override
                public void onNothingSelected(AdapterView<?> parent) {
                    //To change body of implemented methods use File | Settings | File Templates.
                }
            });
            urls.add(0, activity.getString(R.string.ClickToSelectURL));
            openUrl.setAdapter(new BaseAdapter() {
                @Override
                public int getCount() {
                    return urls.size();
                }

                @Override
                public Object getItem(int position) {
                    return position;
                }

                @Override
                public long getItemId(int position) {
                    return position;
                }

                @Override
                public View getView(int position, View convertView, ViewGroup parent) {
                    View rowView = activity.getLayoutInflater().inflate(android.R.layout.simple_list_item_1,
                            null);
                    TextView textView = (TextView) rowView.findViewById(android.R.id.text1);
                    textView.setSingleLine(false);
                    textView.setMaxLines(5);
                    SpannableStringBuilder sb = new SpannableStringBuilder();
                    sb.append(urls.get(position));
                    if (position == 0) {
                        textView.setTextColor(0xFF808080);
                    } else {
                        sb.setSpan(new UnderlineSpan(), 0, sb.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
                    }
                    textView.setText(sb);
                    return rowView;
                }
            });
        } else {
            openUrl.setVisibility(View.GONE);
            singleURL.setVisibility(View.GONE);
        }
        final String UName = listSelectedItem.User.UName;
        View recommendMessage = dialogView.findViewById(R.id.recommend_message);
        View deleteMessage = dialogView.findViewById(R.id.delete_message);
        View saveMessage = dialogView.findViewById(R.id.save_message);
        View unsaveMessage = dialogView.findViewById(R.id.unsave_message);
        //View subscribeUser = dialogView.findViewById(R.id.subscribe_user);
        View subscribeMessage = dialogView.findViewById(R.id.subscribe_message);
        //View unsubscribeUser = dialogView.findViewById(R.id.unsubscribe_user);
        View unsubscribeMessage = dialogView.findViewById(R.id.unsubscribe_message);
        View translateMessage = dialogView.findViewById(R.id.translate_message);
        View shareMessage = dialogView.findViewById(R.id.share_message);
        //View blacklistUser = dialogView.findViewById(R.id.blacklist_user);
        //View filterUser = dialogView.findViewById(R.id.filter_user);
        //View userBlog = dialogView.findViewById(R.id.user_blog);
        //View userStats = dialogView.findViewById(R.id.user_stats);
        View openMessageInBrowser = dialogView.findViewById(R.id.open_message_in_browser);
        Button userCenter = (Button) dialogView.findViewById(R.id.user_center);
        if (null == dialogView.findViewById(R.id.column_3)) {
            // only for portrait
            userCenter.setText("@" + listSelectedItem.User.UName + " " + userCenter.getText());
        }

        unsubscribeMessage.setEnabled(listSelectedItem.getRID() == 0);
        subscribeMessage.setEnabled(listSelectedItem.getRID() == 0);
        unsaveMessage.setEnabled(listSelectedItem.getRID() == 0);
        recommendMessage.setEnabled(listSelectedItem.getRID() == 0);

        if (UName.equalsIgnoreCase(JuickAPIAuthorizer.getJuickAccountName(activity.getApplicationContext()))) {
            recommendMessage.setVisibility(View.GONE);
        } else {
            deleteMessage.setVisibility(View.GONE);
        }
        if (messagesSource instanceof SavedMessagesSource) {
            saveMessage.setVisibility(View.GONE);
        } else {
            unsaveMessage.setVisibility(View.GONE);
        }
        recommendMessage.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                alertDialog.dismiss();
                actionRecommendMessage();
            }
        });
        deleteMessage.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                alertDialog.dismiss();
                actionDeleteMessage();
            }
        });
        saveMessage.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                alertDialog.dismiss();
                actionSaveMessage();
            }
        });
        unsaveMessage.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                alertDialog.dismiss();
                actionUnsaveMessage();
            }
        });
        //            subscribeUser.setOnClickListener(new View.OnClickListener() {
        //                @Override
        //                public void onClick(View v) {
        //                    alertDialog.dismiss();
        //                    actionSubscribeUser();
        //                }
        //            });
        subscribeMessage.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                alertDialog.dismiss();
                actionSubscribeMessage();
            }
        });
        //            unsubscribeUser.setOnClickListener(new View.OnClickListener() {
        //                @Override
        //                public void onClick(View v) {
        //                    alertDialog.dismiss();
        //                    actionUnsubscribeUser();
        //                }
        //            });
        unsubscribeMessage.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                alertDialog.dismiss();
                actionUnsubscribeMessage();
            }
        });
        translateMessage.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                alertDialog.dismiss();
                actionTranslateMessage();
            }
        });
        shareMessage.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                alertDialog.dismiss();
                actionShareMessage();
            }
        });
        //            blacklistUser.setOnClickListener(new View.OnClickListener() {
        //                @Override
        //                public void onClick(View v) {
        //                    alertDialog.dismiss();
        //                    actionBlacklistUser();
        //                }
        //            });
        //            filterUser.setOnClickListener(new View.OnClickListener() {
        //                @Override
        //                public void onClick(View v) {
        //                    alertDialog.dismiss();
        //                    actionFilterUser(UName);
        //                }
        //            });
        //            userBlog.setOnClickListener(new View.OnClickListener() {
        //                @Override
        //                public void onClick(View v) {
        //                    alertDialog.dismiss();
        //                    actionUserBlog();
        //                }
        //            });
        //            userStats.setOnClickListener(new View.OnClickListener() {
        //                @Override
        //                public void onClick(View v) {
        //                    alertDialog.dismiss();
        //                    actionUserStats();
        //                }
        //            });
        openMessageInBrowser.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                alertDialog.dismiss();
                actionOpenMessageInBrowser();
            }
        });
        userCenter.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                alertDialog.dismiss();
                actionUserCenter();
            }
        });
        completeInitDialogMode(alertDialog, dialogView);
        alertDialog.show();
    }
}