Example usage for android.widget ListView getAdapter

List of usage examples for android.widget ListView getAdapter

Introduction

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

Prototype

@Override
public ListAdapter getAdapter() 

Source Link

Document

Returns the adapter currently in use in this ListView.

Usage

From source file:ua.mkh.settings.full.MainActivity.java

public static void setListViewHeightBasedOnChildren(ListView lv) {
    ListAdapter listAdapter = lv.getAdapter();
    if (listAdapter == null)
        return;/* w w  w  .j ava 2s . com*/

    int desiredWidth = MeasureSpec.makeMeasureSpec(lv.getWidth(), MeasureSpec.UNSPECIFIED);
    int totalHeight = 0;
    View view = null;
    for (int i = 0; i < listAdapter.getCount(); i++) {
        view = listAdapter.getView(i, view, lv);
        if (i == 0)
            view.setLayoutParams(new ViewGroup.LayoutParams(desiredWidth, LayoutParams.WRAP_CONTENT));

        view.measure(desiredWidth, MeasureSpec.UNSPECIFIED);
        totalHeight += view.getMeasuredHeight();
    }
    ViewGroup.LayoutParams params = lv.getLayoutParams();
    params.height = totalHeight + (lv.getDividerHeight() * (listAdapter.getCount() - 1));
    lv.setLayoutParams(params);
    lv.requestLayout();
}

From source file:org.botlibre.sdk.activity.ChatActivity.java

public void resetChat(View view) {
    ChatConfig config = new ChatConfig();
    config.instance = instance.id;//from   ww w. j a  v a2  s  .  c o  m
    config.avatar = this.avatarId;
    if (MainActivity.translate && MainActivity.voice != null) {
        config.language = MainActivity.voice.language;
    }
    if (MainActivity.disableVideo) {
        config.avatarFormat = "image";
    } else {
        config.avatarFormat = MainActivity.webm ? "webm" : "mp4";
    }
    config.avatarHD = MainActivity.hd;
    config.speak = !MainActivity.deviceVoice;
    HttpAction action = new HttpChatAction(ChatActivity.this, config);
    action.execute();

    EditText v = (EditText) findViewById(R.id.messageText);
    v.setText("");
    this.messages.clear();
    runOnUiThread(new Runnable() {
        @Override
        public void run() {
            ListView list = (ListView) findViewById(R.id.chatList);
            ((ChatListAdapter) list.getAdapter()).notifyDataSetChanged();
            list.invalidateViews();
        }

    });

    WebView responseView = (WebView) findViewById(R.id.responseText);
    responseView.loadDataWithBaseURL(null, "", "text/html", "utf-8", null);
}

From source file:com.hybris.mobile.app.commerce.activity.MainActivity.java

/**
 * Create the main menu drawer/*from   w ww  .  j a  va  2  s .c  o  m*/
 */
private void createMainMenuDrawer() {
    // Drawer
    mDrawerLayout = (DrawerLayout) findViewById(R.id.main_menu_drawer);
    final ListView drawerListView = (ListView) findViewById(R.id.main_menu_list_elements);

    // Drawer items
    List<MainMenuAdapter.MenuItem<? extends Activity>> drawerItemsList = new ArrayList<>();
    drawerItemsList.add(new MainMenuAdapter.MenuItem<>(R.string.main_menu_item_dashboard,
            R.drawable.b2b_icon_dashboard, DashboardActivity.class));
    drawerItemsList.add(new MainMenuAdapter.MenuItem<>(R.string.main_menu_item_orders,
            R.drawable.b2b_icon_orders, OrderHistoryActivity.class));
    drawerItemsList.add(new MainMenuAdapter.MenuItem<>(R.string.main_menu_item_catalog,
            R.drawable.b2b_icon_catalog, CatalogActivity.class));
    drawerItemsList.add(new MainMenuAdapter.MenuItem<>(R.string.main_menu_item_account,
            R.drawable.b2b_icon_account, AccountActivity.class));
    drawerItemsList.add(new MainMenuAdapter.MenuItem<>(R.string.main_menu_item_store_locator,
            R.drawable.b2b_icon_stores, StoreLocatorActivity.class));

    // Set the adapter for the drawer
    drawerListView.setAdapter(new MainMenuAdapter(this, drawerItemsList));

    // Item click
    drawerListView.setOnItemClickListener(new OnItemClickListener() {
        @SuppressWarnings("unchecked")
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            MainMenuAdapter.MenuItem<? extends Activity> drawerItem = (MainMenuAdapter.MenuItem<? extends Activity>) drawerListView
                    .getAdapter().getItem(position);

            startActivity(new Intent(MainActivity.this, drawerItem.getActivityClassName()));
        }
    });

    // Drawer toggle associated with action bar elements
    mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, R.drawable.ic_drawer,
            R.string.main_menu_open, R.string.main_menu_close) {
        public void onDrawerClosed(View view) {
            invalidateOptionsMenu();
        }

        public void onDrawerOpened(View drawerView) {
            invalidateOptionsMenu();
        }
    };

    mDrawerLayout.setDrawerListener(mDrawerToggle);

    // Swipe disabled
    if (!mIsMainMenuSwipeEnabled) {
        // Open with click on the menu only
        mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
    }

    // Drawer shadow
    mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START);
}

From source file:org.botlibre.sdk.activity.ChatActivity.java

public void submitChat() {

    ChatConfig config = new ChatConfig();
    config.instance = this.instance.id;
    config.conversation = MainActivity.conversation;
    config.speak = !MainActivity.deviceVoice;
    config.avatar = this.avatarId;
    if (MainActivity.translate && MainActivity.voice != null) {
        config.language = MainActivity.voice.language;
    }// w w  w. j  a va 2 s .  co m
    if (MainActivity.disableVideo) {
        config.avatarFormat = "image";
    } else {
        config.avatarFormat = MainActivity.webm ? "webm" : "mp4";
    }
    config.avatarHD = MainActivity.hd;

    EditText v = (EditText) findViewById(R.id.messageText);
    config.message = v.getText().toString().trim();
    if (config.message.equals("")) {
        return;
    }
    this.messages.add(config);
    runOnUiThread(new Runnable() {
        @Override
        public void run() {
            ListView list = (ListView) findViewById(R.id.chatList);
            ((ChatListAdapter) list.getAdapter()).notifyDataSetChanged();
            list.invalidateViews();
        }

    });

    Spinner emoteSpin = (Spinner) findViewById(R.id.emoteSpin);
    config.emote = emoteSpin.getSelectedItem().toString();

    HttpChatAction action = new HttpChatAction(ChatActivity.this, config);
    action.execute();

    v.setText("");
    emoteSpin.setSelection(0);
    resetToolbar();

    WebView responseView = (WebView) findViewById(R.id.responseText);
    responseView.loadDataWithBaseURL(null, "thinking...", "text/html", "utf-8", null);

    //Check the volume
    AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
    int volume = audioManager.getStreamVolume(AudioManager.STREAM_MUSIC);
    if (volume <= 3 && volumeChecked) {
        Toast.makeText(this, "Please check 'Media' volume", Toast.LENGTH_LONG).show();
        volumeChecked = false;
    }

    //stop letting the mic on.
    stopListening();
    //its Important for "sleep" "scream" ...etc commands.
    //this will turn off the mic
    MainActivity.listenInBackground = false;
}

From source file:org.botlibre.sdk.activity.ChatActivity.java

public void submitCorrection() {
    final EditText text = new EditText(this);
    MainActivity.prompt("Enter correction to the bot's response (what it should have said)", this, text,
            new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {
                    if (instance == null) {
                        return;
                    }/*from  w w w .j a  v  a 2  s .c o  m*/

                    ChatConfig config = new ChatConfig();
                    config.instance = instance.id;
                    config.conversation = MainActivity.conversation;
                    config.speak = !MainActivity.deviceVoice;
                    config.avatar = avatarId;
                    if (MainActivity.disableVideo) {
                        config.avatarFormat = "image";
                    } else {
                        config.avatarFormat = MainActivity.webm ? "webm" : "mp4";
                    }
                    config.avatarHD = MainActivity.hd;

                    config.message = text.getText().toString().trim();
                    if (config.message.equals("")) {
                        return;
                    }
                    messages.add(config);
                    runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            ListView list = (ListView) findViewById(R.id.chatList);
                            ((ChatListAdapter) list.getAdapter()).notifyDataSetChanged();
                            list.invalidateViews();
                        }

                    });

                    config.correction = true;

                    Spinner emoteSpin = (Spinner) findViewById(R.id.emoteSpin);
                    config.emote = emoteSpin.getSelectedItem().toString();

                    HttpChatAction action = new HttpChatAction(ChatActivity.this, config);
                    action.execute();

                    EditText v = (EditText) findViewById(R.id.messageText);
                    v.setText("");
                    emoteSpin.setSelection(0);
                    resetToolbar();

                    WebView responseView = (WebView) findViewById(R.id.responseText);
                    responseView.loadDataWithBaseURL(null, "thinking...", "text/html", "utf-8", null);

                }
            });
}

From source file:org.botlibre.sdk.activity.ChatActivity.java

public void flagResponse() {
    if (MainActivity.user == null) {
        MainActivity.showMessage("You must sign in to flag a response", this);
        return;//from w w w . j  ava  2 s  . c o  m
    }
    final EditText text = new EditText(this);
    MainActivity.prompt("Enter reason for flagging response as offensive", this, text,
            new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {
                    if (instance == null) {
                        return;
                    }
                    ChatConfig config = new ChatConfig();
                    config.instance = instance.id;
                    config.conversation = MainActivity.conversation;
                    config.speak = !MainActivity.deviceVoice;
                    config.avatar = avatarId;
                    if (MainActivity.translate && MainActivity.voice != null) {
                        config.language = MainActivity.voice.language;
                    }
                    if (MainActivity.disableVideo) {
                        config.avatarFormat = "image";
                    } else {
                        config.avatarFormat = MainActivity.webm ? "webm" : "mp4";
                    }
                    config.avatarHD = MainActivity.hd;

                    config.message = text.getText().toString().trim();
                    if (config.message.equals("")) {
                        return;
                    }
                    messages.add(config);
                    runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            ListView list = (ListView) findViewById(R.id.chatList);
                            ((ChatListAdapter) list.getAdapter()).notifyDataSetChanged();
                            list.invalidateViews();
                        }

                    });

                    config.offensive = true;

                    Spinner emoteSpin = (Spinner) findViewById(R.id.emoteSpin);
                    config.emote = emoteSpin.getSelectedItem().toString();

                    HttpChatAction action = new HttpChatAction(ChatActivity.this, config);
                    action.execute();

                    EditText v = (EditText) findViewById(R.id.messageText);
                    v.setText("");
                    emoteSpin.setSelection(0);
                    resetToolbar();

                    WebView responseView = (WebView) findViewById(R.id.responseText);
                    responseView.loadDataWithBaseURL(null, "thinking...", "text/html", "utf-8", null);
                }
            });
}

From source file:org.akvo.caddisfly.ui.activity.MainActivity.java

@Override
public void onLoadCalibration(final Handler.Callback callback) {
    final Context context = this;
    final MainApp mainApp = (MainApp) this.getApplicationContext();

    try {//  www .  j ava2 s  . c om
        AlertDialog.Builder builderSingle = new AlertDialog.Builder(context);
        builderSingle.setIcon(R.drawable.ic_launcher);
        builderSingle.setTitle(R.string.loadCalibration);

        final ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(context,
                android.R.layout.select_dialog_singlechoice);

        File external = Environment.getExternalStorageDirectory();
        final String folderName = Config.CALIBRATE_FOLDER_NAME;
        String path = external.getPath() + folderName;
        File folder = new File(path);
        if (folder.exists()) {
            final File[] listFiles = folder.listFiles();
            for (File listFile : listFiles) {
                arrayAdapter.add(listFile.getName());
            }

            builderSingle.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                }
            });

            builderSingle.setAdapter(arrayAdapter, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    String fileName = listFiles[which].getName();
                    final ArrayList<Integer> swatchList = new ArrayList<Integer>();

                    final ArrayList<String> rgbList = FileUtils.loadFromFile(fileName);
                    if (rgbList != null) {

                        for (String rgb : rgbList) {
                            swatchList.add(ColorUtils.getColorFromRgb(rgb));
                        }
                        (new AsyncTask<Void, Void, Void>() {
                            @Override
                            protected Void doInBackground(Void... params) {
                                mainApp.saveCalibratedSwatches(mainApp.currentTestInfo.getCode(), swatchList);

                                mainApp.setSwatches(mainApp.currentTestInfo.getCode());

                                SharedPreferences sharedPreferences = PreferenceManager
                                        .getDefaultSharedPreferences(context);
                                SharedPreferences.Editor editor = sharedPreferences.edit();

                                for (int i = 0; i < mainApp.rangeIntervals.size(); i++) {
                                    int index = i * mainApp.rangeIncrementStep;

                                    ColorUtils.autoGenerateColors(index, mainApp.currentTestInfo.getCode(),
                                            mainApp.colorList, mainApp.rangeIncrementStep, editor, 0);
                                }
                                editor.apply();
                                return null;
                            }

                            @Override
                            protected void onPostExecute(Void result) {
                                super.onPostExecute(result);
                                callback.handleMessage(null);
                            }
                        }).execute();

                    }
                }
            });

            final AlertDialog alert = builderSingle.create();
            alert.setOnShowListener(new DialogInterface.OnShowListener() {
                @Override
                public void onShow(DialogInterface dialogInterface) {
                    final ListView listView = alert.getListView();
                    listView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
                        @Override
                        public boolean onItemLongClick(AdapterView<?> adapterView, View view, int i, long l) {
                            final int position = i;

                            AlertUtils.askQuestion(context, R.string.delete, R.string.selectedWillBeDeleted,
                                    new DialogInterface.OnClickListener() {
                                        @SuppressWarnings("unchecked")
                                        @Override
                                        public void onClick(DialogInterface dialogInterface, int i) {
                                            String fileName = listFiles[position].getName();
                                            FileUtils.deleteFile(folderName, fileName);
                                            ArrayAdapter listAdapter = (ArrayAdapter) listView.getAdapter();
                                            listAdapter.remove(listAdapter.getItem(position));
                                        }
                                    });
                            return true;
                        }
                    });

                }
            });
            alert.show();
        } else {
            AlertUtils.showMessage(context, R.string.notFound, R.string.noSavedCalibrations);
        }
    } catch (ActivityNotFoundException e) {
        AlertUtils.showMessage(context, R.string.error, R.string.updateRequired);
    }

    callback.handleMessage(null);
}

From source file:com.tweetlanes.android.core.view.TweetFeedFragment.java

@Override
public void onJumpToTop() {
    if (mTweetFeedListView != null) {
        ListView listView = mTweetFeedListView.getRefreshableView();
        if (listView != null && listView.getAdapter() != null && !listView.getAdapter().isEmpty()) {
            listView.setSelection(0);/*from  ww  w .  j  a  v  a  2  s  . c om*/
        }
    }
}

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

private void init(final boolean moveToTop) {
    if (implicitlyCreated)
        return;/* w  ww  .  j av a2 s.c  o m*/

    parent.imagePreviewHelper = listAdapter.imagePreviewHelper = new ImagePreviewHelper(
            (ViewGroup) getView().findViewById(R.id.imagepreview_container), parent);

    final MessageListBackingData savedMainList = JuickAdvancedApplication.instance.getSavedList(getActivity());
    final ListView lv = getListView();
    boolean canUseMainList = getActivity() instanceof MainActivity; //
    if (savedMainList != null && canUseMainList) {
        messagesSource = savedMainList.messagesSource;
        initListWithMessages(savedMainList.messages);
        int selectItem = 0;
        ListAdapter wrappedAdapter = lv.getAdapter();
        for (int i = 0; i < wrappedAdapter.getCount(); i++) {
            Object ai = wrappedAdapter.getItem(i);
            if (ai != null && ai instanceof JuickMessage) {
                if (((JuickMessage) ai).getMID().equals(savedMainList.topMessageId)) {
                    selectItem = i;
                }
            }
        }
        lv.setSelectionFromTop(selectItem, savedMainList.topMessageScrollPos);
        JuickAdvancedApplication.instance.setSavedList(null, false);
    } else {
        final MessagesLoadNotification messagesLoadNotification = new MessagesLoadNotification(getActivity(),
                handler);
        Thread thr = new Thread("Download messages (init)") {

            public void run() {
                final MessagesLoadNotification notification = messagesLoadNotification;
                final Utils.Function<Void, RetainedData> then = new Utils.Function<Void, RetainedData>() {
                    @Override
                    public Void apply(final RetainedData mespos) {
                        handler.post(new Runnable() {
                            @Override
                            public void run() {
                                notification.statusText.setText("Filter and format..");
                            }
                        });
                        Log.w("com.juick.advanced", "getFirst: before filter");
                        final ArrayList<JuickMessage> messages = filterMessages(mespos.messages);
                        Log.w("com.juick.advanced", "getFirst: after filter");
                        Boolean ownView = null;
                        if (!JuickMessagesAdapter.dontKeepParsed(parent)) {
                            for (JuickMessage juickMessage : messages) {
                                if (ownView == null) {
                                    MicroBlog blog = MainActivity.microBlogs
                                            .get(juickMessage.getMID().getMicroBlogCode());
                                    ownView = blog instanceof OwnRenderItems;
                                }
                                if (!ownView) {
                                    juickMessage.parsedText = JuickMessagesAdapter.formatMessageText(parent,
                                            juickMessage, false);
                                }
                            }
                        }
                        final Parcelable listPosition = mespos.viewState;
                        if (isAdded()) {
                            if (messages.size() == 0) {
                                handler.post(new Runnable() {
                                    @Override
                                    public void run() {
                                        if (notification.lastError == null) {
                                            notification.statusText
                                                    .setText(parent.getString(R.string.EmptyList));
                                        } else {
                                            notification.statusText.setText(
                                                    "Error obtaining messages: " + notification.lastError);

                                        }
                                        notification.progressBar.setVisibility(View.GONE);
                                    }
                                });
                            }
                            final Activity activity = getActivity();
                            if (activity != null) {
                                final Parcelable finalListPosition = listPosition;
                                activity.runOnUiThread(new Runnable() {

                                    public void run() {
                                        try {
                                            if (isAdded()) {
                                                lastPrepareMessages(messages, new Runnable() {
                                                    @Override
                                                    public void run() {
                                                        if (!hasListView()) {
                                                            handler.postDelayed(this, 300);
                                                            return;
                                                        }
                                                        initListWithMessages(messages);
                                                        if (moveToTop) {
                                                            lv.setSelection(0);
                                                        } else {
                                                            if (finalListPosition != null) {
                                                                lv.onRestoreInstanceState(finalListPosition);
                                                            } else {
                                                                //setSelection(messagesSource.supportsBackwardRefresh() ? 1 : 0);
                                                                setSelection(0);
                                                            }
                                                        }
                                                        Log.w("com.juick.advanced", "getFirst: end.");
                                                        handler.postDelayed(new Runnable() {
                                                            @Override
                                                            public void run() {
                                                                onListLoaded();
                                                            }
                                                        }, 10);
                                                    }
                                                });
                                            }
                                        } catch (IllegalStateException e) {
                                            Toast.makeText(activity, e.toString(), Toast.LENGTH_LONG).show();
                                        }
                                    }
                                });
                            }
                        } else {
                            Log.w("com.juick.advanced", "getFirst: not added!");
                        }
                        return null;
                    }
                };
                if (getActivity() != null)
                    messagesSource.setContext(getActivity());
                if (restoreData == null) {
                    messagesSource.getFirst(notification, new Utils.Function<Void, ArrayList<JuickMessage>>() {
                        @Override
                        public Void apply(ArrayList<JuickMessage> juickMessages) {
                            return then.apply(new RetainedData(juickMessages, null));
                        }
                    });
                } else {
                    then.apply((RetainedData) restoreData);
                    restoreData = null;
                }
            }
        };
        thr.setPriority(Thread.MIN_PRIORITY);
        thr.start();
    }
}

From source file:org.botlibre.sdk.activity.ChatActivity.java

public void debug(final String text) {
    if (!DEBUG) {
        return;/*from  w  ww  .  j  a v  a  2 s .c o  m*/
    }
    final ListView list = (ListView) findViewById(R.id.chatList);
    list.post(new Runnable() {
        @Override
        public void run() {
            ChatResponse ready = new ChatResponse();
            ready.message = text;
            messages.add(ready);
            ((ChatListAdapter) list.getAdapter()).notifyDataSetChanged();
            list.invalidateViews();
            if (list.getCount() > 2) {
                list.setSelection(list.getCount() - 2);
            }
        }
    });
    return;
}