Example usage for android.widget ListView setSelection

List of usage examples for android.widget ListView setSelection

Introduction

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

Prototype

@Override
public void setSelection(int position) 

Source Link

Document

Sets the currently selected item.

Usage

From source file:com.sentaroh.android.Utilities.Dialog.SafFileSelectDialogFragment.java

private void updateTreeFileList(String p_dir, final String creat_dir, final String r_dir,
        final TreeFilelistAdapter tfa, final ListView lv) {
    Log.v("", "p_dir=" + p_dir + ", create_dir=" + creat_dir + ", r_dir=" + r_dir);
    SafFile lf = mSafFileMgr.getSafFileBySdcardPath(mDialogSafRoot, r_dir + p_dir + creat_dir, true);
    if (!p_dir.equals("/")) {//not root
        for (int i = tfa.getDataItemCount() - 1; i >= 0; i--) {
            TreeFilelistItem tfi = tfa.getDataItem(i);
            if (tfi.isDir()) {
                String fp = tfi.getPath() + tfi.getName();
                if (fp.equalsIgnoreCase(p_dir)) {
                    if (tfi.isSubDirLoaded())
                        tfa.removeChildItem(tfi, i);
                    int sdc = tfa.getDataItem(i).getSubDirItemCount();
                    sdc++;//from   w  ww .ja va2  s. c om
                    tfa.getDataItem(i).setSubDirItemCount(sdc);
                    processLocalDirTree(mDialogFileOnly, r_dir + p_dir, i, tfi, tfa);
                    lv.setSelection(i);
                }
            }
        }
    } else {//root
        Log.v("", "find=" + findDirEntry(tfa, "/", creat_dir));
        if (findDirEntry(tfa, "/", creat_dir) >= 0)
            return;
        for (int i = tfa.getDataItemCount() - 1; i >= 0; i--) {
            TreeFilelistItem tfi = tfa.getDataItem(i);
            if (tfi.isDir()) {
                String fp = tfi.getPath() + tfi.getName();
                if (fp.compareToIgnoreCase(p_dir + creat_dir) < 0) {
                    tfi = buildTreeFileListItem(lf, "/");
                    tfi.setSubDirItemCount(0);
                    if ((i + 1) > tfa.getDataItemCount()) {
                        tfa.addDataItem(tfi);
                    } else {
                        int ip = findNextDirEntry(tfa, i + 1);
                        if (ip >= 0)
                            tfa.insertDataItem(ip, tfi);
                        else {
                            ip = findLastDirEntry(tfa);
                            if (ip >= 0)
                                tfa.insertDataItem(ip + 1, tfi);
                            else
                                tfa.insertDataItem(0, tfi);
                        }
                    }
                    tfa.createShowList();
                    break;
                }
            }
        }
    }
}

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);
        }//  w  w  w.  j  av a2s.c  om
    }
}

From source file:com.sentaroh.android.Utilities.Dialog.FileSelectDialogFragment.java

private void updateTreeFileList(String p_dir, final String creat_dir, final String r_dir,
        final TreeFilelistAdapter tfa, final ListView lv) {
    //      Log.v("","p_dir="+p_dir+", create_dir="+creat_dir+", r_dir="+r_dir);
    File lf = new File(r_dir + p_dir + creat_dir);
    if (!p_dir.equals("/")) {//not root
        for (int i = tfa.getDataItemCount() - 1; i >= 0; i--) {
            TreeFilelistItem tfi = tfa.getDataItem(i);
            if (tfi.isDir()) {
                String fp = tfi.getPath() + tfi.getName();
                //                  Log.v("","fp="+fp);
                if (fp.equalsIgnoreCase(p_dir)) {
                    if (tfi.isSubDirLoaded())
                        tfa.removeChildItem(tfi, i);
                    int sdc = tfa.getDataItem(i).getSubDirItemCount();
                    sdc++;// ww w. j  av  a2 s. com
                    tfa.getDataItem(i).setSubDirItemCount(sdc);
                    processLocalDirTree(mDialogFileOnly, r_dir, i, tfi, tfa);
                    lv.setSelection(i);
                }
            }
        }
    } else {//root
        if (findDirEntry(tfa, "/", creat_dir) >= 0)
            return;
        boolean found = false;
        for (int i = tfa.getDataItemCount() - 1; i >= 0; i--) {
            TreeFilelistItem tfi = tfa.getDataItem(i);
            String fp = tfi.getPath() + tfi.getName();
            //              Log.v("","tfi name="+tfi.getPath()+", comp="+fp.compareToIgnoreCase(p_dir+creat_dir));
            if (tfi.isDir()) {
                if (fp.compareToIgnoreCase(p_dir + creat_dir) < 0) {
                    found = true;
                    tfi = buildTreeFileListItem(lf, "/");
                    tfi.setSubDirItemCount(0);
                    if ((i + 1) > tfa.getDataItemCount()) {
                        tfa.addDataItem(tfi);
                    } else {
                        int ip = findNextDirEntry(tfa, i + 1);
                        if (ip >= 0)
                            tfa.insertDataItem(ip, tfi);
                        else {
                            ip = findLastDirEntry(tfa);
                            if (ip >= 0)
                                tfa.insertDataItem(ip + 1, tfi);
                            else
                                tfa.insertDataItem(0, tfi);
                        }
                    }
                    tfa.createShowList();
                    break;
                }
            }
        }
        if (!found) {
            TreeFilelistItem tfi = buildTreeFileListItem(lf, "/");
            tfa.insertDataItem(0, tfi);
        }
    }
}

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

public void debug(final String text) {
    if (!DEBUG) {
        return;//from  w w  w .  j ava  2  s.com
    }
    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;
}

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

public void response(final ChatResponse response) {
    if (speechPlayer != null || tts != null) {
        try {// ww w  .  j  av a  2 s  .  com
            tts.stop();
            speechPlayer.pause();
        } catch (Exception ignore) {
            Log.e("RESPONSE", "Error: " + ignore.getMessage());
        }
    }
    //needs when calling "sleep" or the its not going to let the mic off
    //also to stop the mic until the bot finish the sentence
    try {
        stopListening();
        this.response = response;

        String status = "";
        if (response.emote != null && !response.emote.equals("NONE")) {
            status = status + response.emote.toLowerCase();
        }
        if (response.action != null) {
            if (!status.isEmpty()) {
                status = status + " ";
            }
            status = status + response.action;
        }
        if (response.pose != null) {
            if (!status.isEmpty()) {
                status = status + " ";
            }
            status = status + response.pose;
        }

        if (response.command != null) {
            JSONObject jsonObject = response.getCommand();
            Command command = new Command(this, jsonObject);
        }

        TextView statusView = (TextView) findViewById(R.id.statusText);
        statusView.setText(status);

        final String text = response.message;
        final ListView list = (ListView) findViewById(R.id.chatList);
        if (text == null) {
            list.post(new Runnable() {
                @Override
                public void run() {
                    ChatResponse ready = new ChatResponse();
                    ready.message = "ready";
                    messages.add(ready);
                    ((ChatListAdapter) list.getAdapter()).notifyDataSetChanged();
                    list.invalidateViews();
                    if (list.getCount() > 2) {
                        list.setSelection(list.getCount() - 2);
                    }
                    beginListening();
                }
            });
            return;
        }
        list.post(new Runnable() {
            @Override
            public void run() {
                messages.add(response);
                ((ChatListAdapter) list.getAdapter()).notifyDataSetChanged();
                list.invalidateViews();
                if (list.getCount() > 2) {
                    list.setSelection(list.getCount() - 2);
                }
            }
        });

        WebView responseView = (WebView) findViewById(R.id.responseText);
        String html = Utils.linkHTML(text);
        if (html.contains("<") && html.contains(">")) {
            html = linkPostbacks(html);
        }
        responseView.loadDataWithBaseURL(null, html, "text/html", "utf-8", null);

        boolean talk = (text.trim().length() > 0) && (MainActivity.deviceVoice
                || (this.response.speech != null && this.response.speech.length() > 0));
        if (MainActivity.sound && talk) {
            if (!MainActivity.disableVideo && !videoError && this.response.isVideo()
                    && this.response.isVideoTalk()) {

                videoView.setOnPreparedListener(new OnPreparedListener() {
                    @Override
                    public void onPrepared(MediaPlayer mp) {
                        try {
                            mp.setLooping(true);
                            if (!MainActivity.deviceVoice) {
                                // Voice audio
                                speechPlayer = playAudio(response.speech, false, false, false);
                                speechPlayer.setOnCompletionListener(new OnCompletionListener() {
                                    @Override
                                    public void onCompletion(MediaPlayer mp) {
                                        mp.release();
                                        videoView.post(new Runnable() {
                                            public void run() {
                                                cycleVideo(response);
                                            }
                                        });
                                        runOnUiThread(new Runnable() {
                                            public void run() {
                                                if (!music) {
                                                    beginListening();
                                                }
                                            }
                                        });
                                    }
                                });

                                speechPlayer.start();
                            } else {
                                HashMap<String, String> params = new HashMap<String, String>();
                                params.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID, "id");

                                tts.speak(Utils.stripTags(text), TextToSpeech.QUEUE_FLUSH, params);
                            }
                        } catch (Exception exception) {
                            Log.wtf(exception.getMessage(), exception);
                        }
                    }
                });
                playVideo(this.response.avatarTalk, false);
            } else if (talk) {
                if (!MainActivity.deviceVoice) {
                    // Voice audio
                    playAudio(this.response.speech, false, false, true);
                } else {
                    HashMap<String, String> params = new HashMap<String, String>();
                    params.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID, "id");

                    this.tts.speak(Utils.stripTags(text), TextToSpeech.QUEUE_FLUSH, params);
                }
            }
        } else if (talk && (!MainActivity.disableVideo && !videoError && this.response.isVideo()
                && this.response.avatarTalk != null)) {
            videoView.setOnPreparedListener(new OnPreparedListener() {
                @Override
                public void onPrepared(MediaPlayer mp) {
                    mp.setLooping(false);
                }
            });
            videoView.setOnCompletionListener(new OnCompletionListener() {
                @Override
                public void onCompletion(MediaPlayer mp) {
                    videoView.setOnCompletionListener(null);
                    cycleVideo(response);
                }
            });
            playVideo(this.response.avatarTalk, false);
            runOnUiThread(new Runnable() {
                public void run() {
                    beginListening();
                }
            });
        } else {
            runOnUiThread(new Runnable() {
                public void run() {
                    beginListening();
                }
            });
        }
    } catch (Exception exception) {
        Log.wtf(exception.getMessage(), exception);
    }
    if (micLastStat) {
        MainActivity.listenInBackground = true;
    }
}

From source file:net.olejon.mdapp.AtcCodesActivity.java

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

    // Intent//from   w w  w. ja  v  a  2s.  co  m
    final Intent intent = getIntent();

    final String atcCode = intent.getStringExtra("code");

    final String atcCodes = atcCode.substring(0, 5);

    // Layout
    setContentView(R.layout.activity_atc_codes);

    // Toolbar
    final Toolbar toolbar = (Toolbar) findViewById(R.id.atc_codes_toolbar);
    toolbar.setTitle(atcCodes);

    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    // List
    ListView listView = (ListView) findViewById(R.id.atc_codes_list);

    View listViewEmpty = findViewById(R.id.atc_codes_list_empty);
    listView.setEmptyView(listViewEmpty);

    // Get substances
    mSqLiteDatabase = new SlDataSQLiteHelper(mContext).getReadableDatabase();
    mCursor = mSqLiteDatabase.query(SlDataSQLiteHelper.TABLE_ATC_CODES, null,
            SlDataSQLiteHelper.ATC_CODES_COLUMN_CODE + " LIKE " + mTools.sqe(atcCodes + "%"), null, null, null,
            SlDataSQLiteHelper.ATC_CODES_COLUMN_CODE);

    String[] fromColumns = new String[] { SlDataSQLiteHelper.ATC_CODES_COLUMN_CODE,
            SlDataSQLiteHelper.ATC_CODES_COLUMN_NAME };
    int[] toViews = new int[] { R.id.atc_codes_list_item_code, R.id.atc_codes_list_item_name };

    AtcCodesSimpleCursorAdapter atcCodesSimpleCursorAdapter = new AtcCodesSimpleCursorAdapter(atcCode, mContext,
            mCursor, fromColumns, toViews);

    listView.setAdapter(atcCodesSimpleCursorAdapter);

    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
            if (mCursor.moveToPosition(i)) {
                String substanceName = mCursor
                        .getString(mCursor.getColumnIndexOrThrow(SlDataSQLiteHelper.ATC_CODES_COLUMN_NAME));

                if (substanceName.equals("") || substanceName.equals("Diverse")
                        || substanceName.equals("Kombinasjoner") || substanceName.startsWith("Andre ")
                        || substanceName.contains("kombinasjon")) {
                    mTools.showToast(getString(R.string.atc_codes_substance_not_a_substance), 1);
                } else if (substanceName.contains(" / ")) {
                    final String[] substancesNamesStringArray = substanceName.split(" / ");

                    new MaterialDialog.Builder(mContext).title(getString(R.string.atc_codes_dialog_title))
                            .items(substancesNamesStringArray).itemsCallback(new MaterialDialog.ListCallback() {
                                @Override
                                public void onSelection(MaterialDialog materialDialog, View view, int i,
                                        CharSequence charSequence) {
                                    getSubstance(substancesNamesStringArray[i]);
                                }
                            }).itemColorRes(R.color.dark_blue).show();
                } else {
                    getSubstance(substanceName);
                }
            }
        }
    });

    for (int i = 0; i < mCursor.getCount(); i++) {
        if (mCursor.moveToPosition(i)) {
            String atcCodeSelection = mCursor
                    .getString(mCursor.getColumnIndexOrThrow(SlDataSQLiteHelper.ATC_CODES_COLUMN_CODE));

            if (atcCodeSelection.equals(atcCode)) {
                listView.setSelection(i);
                break;
            }
        }
    }
}

From source file:org.egov.android.view.activity.AllComplaintActivity.java

/**
 * The onResponse method will be invoked after the all complaint API call. onResponse methods
 * will contain the response.If the response has a status as 'success' then we have checked
 * whether the access token is valid or not.If the access token is invalid, redirect to login
 * page. If the access token is valid, the response contains the JSON object.
 * createdDate,complainantName,detail,crn,status values are retrieved from the response object
 * and store it to the variable then these values are set to the all complaint layout. call the
 * _addDownloadJobs method to display the complaint photo from the complaint photos directory on
 * the storage device. displays the All complaints list with the corresponding complaint image.
 * we have checked the pagination value.This value is retrieved from the api response if the
 * value is true then load more option will be displayed below the complaint list view.
 *///from   ww w .  j  a  va  2  s  .c  o  m
@Override
public void onResponse(Event<ApiResponse> event) {
    String status = event.getData().getApiStatus().getStatus();
    String pagination = event.getData().getApiStatus().isPagination();
    String msg = event.getData().getApiStatus().getMessage();
    final ListView listView = (ListView) getActivity().findViewById(R.id.all_complaint_list);
    if (!toAppend) {
        listItem = new ArrayList<Complaint>();
    }
    if (status.equalsIgnoreCase("success")) {
        try {
            if (listItem.size() > 5) {
                listItem.remove(listItem.size() - 1);
            }
            JSONArray ja = new JSONArray(event.getData().getResponse().toString());
            Complaint item = null;
            isApiLoaded = true;
            if (ja.length() > 0) {
                ((TextView) getActivity().findViewById(R.id.all_errMsg)).setVisibility(View.GONE);
                for (int i = 0; i < ja.length(); i++) {
                    JSONObject jo = ja.getJSONObject(i);
                    item = new Complaint();
                    String userName = _getValue(jo, "complainantName");
                    item.setCreatedDate(_getValue(jo, "createdDate"));
                    item.setCreatedBy((userName.equals("")) ? _getValue(jo, "lastModifiedBy") : userName);
                    item.setDetails(_getValue(jo, "detail"));
                    item.setComplaintId(jo.getString("crn"));
                    item.setStatus(jo.getString("status"));
                    StorageManager sm = new StorageManager();
                    Object[] obj = sm.getStorageInfo(AllComplaintActivity.this.getActivity());
                    String complaintFolderName = obj[0].toString() + "/complaints/" + jo.getString("crn");

                    File complaintFolder = new File(complaintFolderName);
                    if (!complaintFolder.exists()) {
                        if (jo.getInt("supportDocsSize") == 0) {
                            item.setImagePath(
                                    complaintFolderName + File.separator + "photo_complaint_type.jpg");
                        } else {
                            item.setImagePath(complaintFolderName + File.separator + "photo_"
                                    + jo.getInt("supportDocsSize") + ".jpg");
                        }
                        sm.mkdirs(complaintFolderName);
                        _addDownloadJobs(complaintFolderName, jo);
                    } else {
                        item.setImagePath(complaintFolderName + File.separator + "photo_"
                                + complaintFolder.listFiles().length + ".jpg");
                    }
                    listItem.add(item);
                }

                if (listItem.size() > 5) {
                    listView.postDelayed(new Runnable() {
                        public void run() {
                            listView.setStackFromBottom(true);
                            listView.setSelection(listItem.size() - 8);
                        }
                    }, 0);
                }

                if (pagination.equals("true")) {
                    item = new Complaint();
                    listItem.add(item);
                }
                ServiceController.getInstance().startJobs();
                _displayListView(pagination.equals("true"));
            } else if (listItem.size() == 0) {
                ((TextView) getActivity().findViewById(R.id.all_errMsg)).setVisibility(View.VISIBLE);
                _displayListView(false);
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }
    } else {
        if (msg.matches(".*Invalid access token.*")) {
            _showMsg("Session expired");
            AndroidLibrary.getInstance().getSession().edit().putString("access_token", "").commit();
            Intent intent = new Intent(getActivity(), LoginActivity.class);
            intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
            getActivity().startActivity(intent);
            getActivity().finish();
        } else {
            page = (page > 1) ? page - 1 : 1;
            _showMsg(msg);
        }
    }
}

From source file:com.sentaroh.android.TaskAutomation.Config.ProfileMaintenanceTaskProfile.java

final static private void setEditTaskActionListener(final GlobalParameters mGlblParms, final Dialog dialog,
        final AdapterProfileList pfla, ListView pflv, final String curr_grp,
        final ArrayList<TaskActionEditListItem> adapter_act_list) {
    final Spinner spinnerActionProfile = (Spinner) dialog.findViewById(R.id.edit_profile_task_user_actionlist);
    CustomSpinnerAdapter adapterActionProfile = new CustomSpinnerAdapter(mGlblParms.context,
            R.layout.custom_simple_spinner_item);
    adapterActionProfile.setTextColor(Color.BLACK);
    ProfileMaintenance.setSpinnerActionProfile(mGlblParms, dialog, pfla, pflv, spinnerActionProfile,
            adapterActionProfile);/*from ww  w  .j ava  2 s  .  c o  m*/
    if (adapterActionProfile.getCount() == 0)
        spinnerActionProfile.setEnabled(false);

    final Spinner spinnerBuiltinPrimitiveAction = (Spinner) dialog
            .findViewById(R.id.edit_profile_task_builtin_primitive_actionlist);
    CustomSpinnerAdapter adapterBuiltinPrimitiveAction = new CustomSpinnerAdapter(mGlblParms.context,
            R.layout.custom_simple_spinner_item);
    adapterBuiltinPrimitiveAction.setTextColor(Color.BLACK);
    ProfileMaintenance.setSpinnerBuiltinPrimitiveAction(mGlblParms, dialog, spinnerBuiltinPrimitiveAction,
            adapterBuiltinPrimitiveAction);
    if (adapterBuiltinPrimitiveAction.getCount() == 0)
        spinnerBuiltinPrimitiveAction.setEnabled(false);

    final Spinner spinnerBuiltinConditionalAction = (Spinner) dialog
            .findViewById(R.id.edit_profile_task_builtin_conditional_actionlist);
    CustomSpinnerAdapter adapterBuiltinConditionalAction = new CustomSpinnerAdapter(mGlblParms.context,
            R.layout.custom_simple_spinner_item);
    adapterBuiltinConditionalAction.setTextColor(Color.BLACK);
    ProfileMaintenance.setSpinnerBuiltinConditionalAction(mGlblParms, dialog, spinnerBuiltinConditionalAction,
            adapterBuiltinConditionalAction);
    if (adapterBuiltinConditionalAction.getCount() == 0)
        spinnerBuiltinConditionalAction.setEnabled(false);

    final Spinner spinnerBuiltinCancelAction = (Spinner) dialog
            .findViewById(R.id.edit_profile_task_builtin_cancel_actionlist);
    CustomSpinnerAdapter adapterBuiltinCancelAction = new CustomSpinnerAdapter(mGlblParms.context,
            R.layout.custom_simple_spinner_item);
    adapterBuiltinCancelAction.setTextColor(Color.BLACK);
    ProfileMaintenance.setSpinnerBuiltinCancelAction(mGlblParms, dialog, spinnerBuiltinCancelAction,
            adapterBuiltinCancelAction);
    if (adapterBuiltinCancelAction.getCount() == 0)
        spinnerBuiltinCancelAction.setEnabled(false);

    final Spinner spinnerBuiltinBlockAction = (Spinner) dialog
            .findViewById(R.id.edit_profile_task_builtin_block_actionlist);
    CustomSpinnerAdapter adapterBuiltinBlockAction = new CustomSpinnerAdapter(mGlblParms.context,
            R.layout.custom_simple_spinner_item);
    adapterBuiltinBlockAction.setTextColor(Color.BLACK);
    ProfileMaintenance.setSpinnerBuiltinBlockAction(mGlblParms, dialog, spinnerBuiltinBlockAction,
            adapterBuiltinBlockAction);
    if (adapterBuiltinBlockAction.getCount() == 0)
        spinnerBuiltinBlockAction.setEnabled(false);

    final ListView lv_act_list = (ListView) dialog.findViewById(android.R.id.list);
    mGlblParms.taskActionListAdapter = new AdapterTaskActionEditList(mGlblParms.context,
            R.layout.task_action_list_item, adapter_act_list);
    lv_act_list.setAdapter(mGlblParms.taskActionListAdapter);
    lv_act_list.setEnabled(true);
    lv_act_list.setSelected(true);

    lv_act_list.setOnItemClickListener(new OnItemClickListener() {
        @Override
        final public void onItemClick(AdapterView<?> parent, View view, final int position, long id) {
            if (!mGlblParms.taskActionListAdapter.getItem(position).action.startsWith(BUILTIN_PREFIX)
                    && !curr_grp.equals(QUICK_TASK_GROUP_NAME)) {
                for (int i = 0; i < pfla.getDataListCount(); i++) {
                    if (pfla.getDataListItem(i).getProfileType().equals(PROFILE_TYPE_ACTION)
                            && pfla.getDataListItem(i).getProfileGroup().equals(curr_grp)
                            && pfla.getDataListItem(i).getProfileName()
                                    .equals(mGlblParms.taskActionListAdapter.getItem(position).action)) {
                        NotifyEvent ntfy = new NotifyEvent(mGlblParms.context);
                        ntfy.setListener(new NotifyEventListener() {
                            @Override
                            public void positiveResponse(Context c, Object[] o) {
                                updateTaskActionEditListDescription(mGlblParms, dialog, pfla, curr_grp,
                                        adapter_act_list);
                                mGlblParms.taskActionListAdapter.notifyDataSetChanged();
                            }

                            @Override
                            public void negativeResponse(Context c, Object[] o) {
                            }
                        });
                        ProfileMaintenanceActionProfile pmap = ProfileMaintenanceActionProfile.newInstance();
                        pmap.showDialog(mGlblParms.frgamentMgr, pmap, "EDIT", curr_grp,
                                pfla.getDataListItem(i));
                        pmap.setNotifyEvent(ntfy);
                        break;
                    }
                }
            }
        }
    });

    lv_act_list.setOnItemLongClickListener(new OnItemLongClickListener() {
        @Override
        final public boolean onItemLongClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
            createTaskActionListContextMenu(mGlblParms, dialog, curr_grp, arg2, pfla);
            return false;
        }
    });

    // Add user action?
    spinnerActionProfile.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        final public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
            if (arg2 != 0) {
                TaskActionEditListItem taeli = new TaskActionEditListItem();
                taeli.action = (String) spinnerActionProfile.getSelectedItem();
                mGlblParms.taskActionListAdapter.add(taeli);
                updateTaskActionEditListDescription(mGlblParms, dialog, pfla, curr_grp, adapter_act_list);
                mGlblParms.taskActionListAdapter.notifyDataSetChanged();
                lv_act_list.setSelection(mGlblParms.taskActionListAdapter.getCount() - 1);
                arg0.setSelection(0);
            }
        }

        @Override
        final public void onNothingSelected(AdapterView<?> arg0) {
        }
    });

    // Add builtin action primitive?
    spinnerBuiltinPrimitiveAction.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        final public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
            if (arg2 != 0) {
                TaskActionEditListItem taeli = new TaskActionEditListItem();
                taeli.action = (String) spinnerBuiltinPrimitiveAction.getSelectedItem();
                mGlblParms.taskActionListAdapter.add(taeli);
                mGlblParms.taskActionListAdapter.notifyDataSetChanged();
                lv_act_list.setSelection(mGlblParms.taskActionListAdapter.getCount() - 1);
                arg0.setSelection(0);
            }
        }

        @Override
        final public void onNothingSelected(AdapterView<?> arg0) {
        }

    });

    // Add builtin action conditional?
    spinnerBuiltinConditionalAction.setOnItemSelectedListener(new OnItemSelectedListener() {
        @Override
        final public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
            if (arg2 != 0) {
                TaskActionEditListItem taeli = new TaskActionEditListItem();
                taeli.action = (String) spinnerBuiltinConditionalAction.getSelectedItem();
                mGlblParms.taskActionListAdapter.add(taeli);
                mGlblParms.taskActionListAdapter.notifyDataSetChanged();
                lv_act_list.setSelection(mGlblParms.taskActionListAdapter.getCount() - 1);
                arg0.setSelection(0);
            }
        }

        @Override
        final public void onNothingSelected(AdapterView<?> arg0) {
        }
    });

    // Add builtin action cancel?
    spinnerBuiltinCancelAction.setOnItemSelectedListener(new OnItemSelectedListener() {
        @Override
        final public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
            if (arg2 != 0) {
                TaskActionEditListItem taeli = new TaskActionEditListItem();
                taeli.action = (String) spinnerBuiltinCancelAction.getSelectedItem();
                mGlblParms.taskActionListAdapter.add(taeli);
                mGlblParms.taskActionListAdapter.notifyDataSetChanged();
                lv_act_list.setSelection(mGlblParms.taskActionListAdapter.getCount() - 1);
                arg0.setSelection(0);
            }
        }

        @Override
        final public void onNothingSelected(AdapterView<?> arg0) {
        }
    });

    // Add builtin action block?
    spinnerBuiltinBlockAction.setOnItemSelectedListener(new OnItemSelectedListener() {
        @Override
        final public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
            if (arg2 != 0) {
                TaskActionEditListItem taeli = new TaskActionEditListItem();
                taeli.action = (String) spinnerBuiltinBlockAction.getSelectedItem();
                mGlblParms.taskActionListAdapter.add(taeli);
                mGlblParms.taskActionListAdapter.notifyDataSetChanged();
                lv_act_list.setSelection(mGlblParms.taskActionListAdapter.getCount() - 1);
                arg0.setSelection(0);
            }
        }

        @Override
        final public void onNothingSelected(AdapterView<?> arg0) {
        }
    });

    final Spinner spinnerSelectAction = (Spinner) dialog.findViewById(R.id.edit_profile_task_select_action);
    CustomSpinnerAdapter adapterSelectAction = new CustomSpinnerAdapter(mGlblParms.context,
            R.layout.custom_simple_spinner_item);
    adapterSelectAction.setTextColor(Color.BLACK);
    ProfileMaintenance.setSpinnerSelectAction(mGlblParms, dialog, spinnerSelectAction, adapterSelectAction);
    spinnerSelectAction.setOnItemSelectedListener(new OnItemSelectedListener() {
        @Override
        final public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
            spinnerActionProfile.setVisibility(Spinner.GONE);
            spinnerBuiltinPrimitiveAction.setVisibility(Spinner.GONE);
            spinnerBuiltinConditionalAction.setVisibility(Spinner.GONE);
            spinnerBuiltinCancelAction.setVisibility(Spinner.GONE);
            spinnerBuiltinBlockAction.setVisibility(Spinner.GONE);
            String act = (String) spinnerSelectAction.getSelectedItem();
            if (act.equals(mGlblParms.context.getString(R.string.msgs_edit_profile_action_select_user))) {
                spinnerActionProfile.setVisibility(Spinner.VISIBLE);
            } else if (act
                    .equals(mGlblParms.context.getString(R.string.msgs_edit_profile_action_select_primitive))) {
                spinnerBuiltinPrimitiveAction.setVisibility(Spinner.VISIBLE);
            } else if (act.equals(
                    mGlblParms.context.getString(R.string.msgs_edit_profile_action_select_conditional))) {
                spinnerBuiltinConditionalAction.setVisibility(Spinner.VISIBLE);
            } else if (act
                    .equals(mGlblParms.context.getString(R.string.msgs_edit_profile_action_select_cancel))) {
                spinnerBuiltinCancelAction.setVisibility(Spinner.VISIBLE);
            } else if (act
                    .equals(mGlblParms.context.getString(R.string.msgs_edit_profile_action_select_block))) {
                spinnerBuiltinBlockAction.setVisibility(Spinner.VISIBLE);
            }
        }

        @Override
        final public void onNothingSelected(AdapterView<?> arg0) {
        }
    });

}

From source file:com.sentaroh.android.SMBSync2.SyncTaskUtility.java

public void setRemoteDir(final String remurl, final String curdir, final String p_dir,
        final NotifyEvent p_ntfy) {
    final ArrayList<TreeFilelistItem> rows = new ArrayList<TreeFilelistItem>();

    NotifyEvent ntfy = new NotifyEvent(mContext);
    // set thread response 
    ntfy.setListener(new NotifyEventListener() {
        @Override//from   w  w  w.j a  v a 2  s.c  om
        public void positiveResponse(Context c, Object[] o) {
            @SuppressWarnings("unchecked")
            ArrayList<TreeFilelistItem> rfl = (ArrayList<TreeFilelistItem>) o[0];
            for (int i = 0; i < rfl.size(); i++) {
                if (rfl.get(i).isDir() && rfl.get(i).canRead())
                    rows.add(rfl.get(i));
            }
            Collections.sort(rows);
            if (rows.size() < 1)
                rows.add(new TreeFilelistItem(mContext.getString(R.string.msgs_dir_empty)));
            //??
            final Dialog dialog = new Dialog(mContext);
            dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
            dialog.setCanceledOnTouchOutside(false);
            dialog.setContentView(R.layout.item_select_list_dlg);

            LinearLayout ll_dlg_view = (LinearLayout) dialog.findViewById(R.id.item_select_list_dlg_view);
            ll_dlg_view.setBackgroundColor(mGp.themeColorList.dialog_msg_background_color);

            final LinearLayout title_view = (LinearLayout) dialog
                    .findViewById(R.id.item_select_list_dlg_title_view);
            final TextView title = (TextView) dialog.findViewById(R.id.item_select_list_dlg_title);
            final TextView subtitle = (TextView) dialog.findViewById(R.id.item_select_list_dlg_subtitle);
            title_view.setBackgroundColor(mGp.themeColorList.dialog_title_background_color);
            title.setTextColor(mGp.themeColorList.text_color_dialog_title);
            subtitle.setTextColor(mGp.themeColorList.text_color_dialog_title);

            title.setText(mContext.getString(R.string.msgs_select_remote_dir));
            subtitle.setText(mContext.getString(R.string.msgs_current_dir) + "/" + remurl);
            //             if (rows.size()<1) {
            //                TextView dlg_msg=(TextView)dialog.findViewById(R.id.item_select_list_dlg_msg);
            //                dlg_msg.setText(msgs_dir_empty);
            //                dlg_msg.setVisibility(TextView.VISIBLE);
            //             }
            final Button btn_ok = (Button) dialog.findViewById(R.id.item_select_list_dlg_ok_btn);
            //              if (rows.size()<=2) 
            //                 ((TextView)dialog.findViewById(R.id.item_select_list_dlg_spacer))
            //                 .setVisibility(TextView.VISIBLE);

            CommonDialog.setDlgBoxSizeLimit(dialog, true);

            final ListView lv = (ListView) dialog.findViewById(android.R.id.list);
            final TreeFilelistAdapter tfa = new TreeFilelistAdapter(mContext, true, false);
            //            tfa.setNotifyOnChange(true);
            tfa.setDataList(rows);
            lv.setAdapter(tfa);
            lv.setScrollingCacheEnabled(false);
            lv.setScrollbarFadingEnabled(false);
            lv.setFastScrollEnabled(true);

            if (p_dir.length() != 0)
                for (int i = 0; i < tfa.getDataItemCount(); i++) {
                    if (tfa.getDataItem(i).getName().equals(p_dir))
                        lv.setSelection(i);
                }

            lv.setOnItemClickListener(new OnItemClickListener() {
                public void onItemClick(AdapterView<?> items, View view, int idx, long id) {
                    // ????????
                    final int pos = tfa.getItem(idx);
                    final TreeFilelistItem tfi = tfa.getDataItem(pos);
                    if (tfi.getName().startsWith("---"))
                        return;
                    expandHideRemoteDirTree(remurl, pos, tfi, tfa);
                }
            });
            lv.setOnItemLongClickListener(new OnItemLongClickListener() {
                @Override
                public boolean onItemLongClick(AdapterView<?> arg0, View arg1, final int position, long arg3) {
                    final int t_pos = tfa.getItem(position);
                    if (tfa.getDataItem(t_pos).isChecked()) {
                        ccMenu.addMenuItem(mContext.getString(R.string.msgs_file_select_unselect_this_entry)
                                + " " + tfa.getDataItem(t_pos).getPath() + tfa.getDataItem(t_pos).getName())
                                .setOnClickListener(new CustomContextMenuOnClickListener() {
                                    @Override
                                    public void onClick(CharSequence menuTitle) {
                                        final TreeFilelistItem tfi = tfa.getDataItem(t_pos);
                                        if (tfi.getName().startsWith("---"))
                                            return;
                                        tfa.setDataItemIsUnselected(t_pos);
                                        btn_ok.setEnabled(false);
                                    }
                                });
                    } else {
                        ccMenu.addMenuItem(mContext.getString(R.string.msgs_file_select_select_this_entry) + " "
                                + tfa.getDataItem(t_pos).getPath() + tfa.getDataItem(t_pos).getName())
                                .setOnClickListener(new CustomContextMenuOnClickListener() {
                                    @Override
                                    public void onClick(CharSequence menuTitle) {
                                        final TreeFilelistItem tfi = tfa.getDataItem(t_pos);
                                        if (tfi.getName().startsWith("---"))
                                            return;
                                        tfa.setDataItemIsSelected(t_pos);
                                        btn_ok.setEnabled(true);
                                    }
                                });
                    }
                    ccMenu.createMenu();
                    return false;
                }
            });
            NotifyEvent ctv_ntfy = new NotifyEvent(mContext);
            // set file list thread response listener 
            ctv_ntfy.setListener(new NotifyEventListener() {
                @Override
                public void positiveResponse(Context c, Object[] o) {
                    if (o != null) {
                        int pos = (Integer) o[0];
                        if (tfa.getDataItem(pos).isChecked())
                            btn_ok.setEnabled(true);
                    }
                }

                @Override
                public void negativeResponse(Context c, Object[] o) {
                    btn_ok.setEnabled(false);
                    for (int i = 0; i < tfa.getDataItemCount(); i++) {
                        if (tfa.getDataItem(i).isChecked()) {
                            btn_ok.setEnabled(true);
                            break;
                        }
                    }
                }
            });
            tfa.setCbCheckListener(ctv_ntfy);

            //OK?
            btn_ok.setEnabled(false);
            btn_ok.setVisibility(Button.VISIBLE);
            btn_ok.setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {
                    String sel = "";
                    for (int i = 0; i < tfa.getCount(); i++) {
                        if (tfa.getDataItem(i).isChecked() && !tfa.getDataItem(i).getName()
                                .equals(mContext.getString(R.string.msgs_dir_empty))) {
                            if (tfa.getDataItem(i).getPath().length() == 1)
                                sel = tfa.getDataItem(i).getName();
                            else
                                sel = tfa.getDataItem(i).getPath().substring(1,
                                        tfa.getDataItem(i).getPath().length()) + tfa.getDataItem(i).getName();
                            break;
                        }
                    }
                    dialog.dismiss();
                    p_ntfy.notifyToListener(true, new Object[] { sel });
                }
            });
            //CANCEL?
            final Button btn_cancel = (Button) dialog.findViewById(R.id.item_select_list_dlg_cancel_btn);
            btn_cancel.setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {
                    dialog.dismiss();
                    p_ntfy.notifyToListener(false, null);
                }
            });
            // Cancel?
            dialog.setOnCancelListener(new Dialog.OnCancelListener() {
                @Override
                public void onCancel(DialogInterface arg0) {
                    btn_cancel.performClick();
                }
            });

            //             dialog.setOnKeyListener(new DialogOnKeyListener(context));
            //             dialog.setCancelable(false);
            dialog.show();
        }

        @Override
        public void negativeResponse(Context c, Object[] o) {
            p_ntfy.notifyToListener(false, o);
        }
    });
    createRemoteFileList(remurl, curdir, ntfy, true);
    return;
}

From source file:com.sentaroh.android.SMBSync2.SyncTaskUtility.java

public void selectLocalDirDlg(final String url, final String dir, String p_dir, final NotifyEvent p_ntfy) {

    //??/*from www  .  ja  v a2  s.c o m*/
    final Dialog dialog = new Dialog(mContext);
    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    dialog.setCanceledOnTouchOutside(false);
    dialog.setContentView(R.layout.item_select_list_dlg);

    LinearLayout ll_dlg_view = (LinearLayout) dialog.findViewById(R.id.item_select_list_dlg_view);
    ll_dlg_view.setBackgroundColor(mGp.themeColorList.dialog_msg_background_color);

    final LinearLayout title_view = (LinearLayout) dialog.findViewById(R.id.item_select_list_dlg_title_view);
    final TextView title = (TextView) dialog.findViewById(R.id.item_select_list_dlg_title);
    final TextView subtitle = (TextView) dialog.findViewById(R.id.item_select_list_dlg_subtitle);
    title_view.setBackgroundColor(mGp.themeColorList.dialog_title_background_color);
    title.setTextColor(mGp.themeColorList.text_color_dialog_title);
    subtitle.setTextColor(mGp.themeColorList.text_color_dialog_title);

    title.setText(mContext.getString(R.string.msgs_select_local_dir));
    subtitle.setText(mContext.getString(R.string.msgs_current_dir) + url + dir);

    final Button btn_ok = (Button) dialog.findViewById(R.id.item_select_list_dlg_ok_btn);

    //        if (rows.size()<=2) 
    //           ((TextView)dialog.findViewById(R.id.item_select_list_dlg_spacer))
    //           .setVisibility(TextView.VISIBLE);

    CommonDialog.setDlgBoxSizeLimit(dialog, true);

    ListView lv = (ListView) dialog.findViewById(android.R.id.list);
    final TreeFilelistAdapter tfa = new TreeFilelistAdapter(mContext, true, false);
    lv.setAdapter(tfa);
    ArrayList<TreeFilelistItem> tfl = createLocalFilelist(true, url, dir);
    if (tfl.size() < 1)
        tfl.add(new TreeFilelistItem(mContext.getString(R.string.msgs_dir_empty)));
    tfa.setDataList(tfl);
    lv.setScrollingCacheEnabled(false);
    lv.setScrollbarFadingEnabled(false);
    lv.setFastScrollEnabled(true);

    if (p_dir.length() != 0)
        for (int i = 0; i < tfa.getDataItemCount(); i++) {
            if (tfa.getDataItem(i).getName().equals(p_dir))
                lv.setSelection(i);
        }
    lv.setOnItemClickListener(new OnItemClickListener() {
        public void onItemClick(AdapterView<?> items, View view, int idx, long id) {
            final int pos = tfa.getItem(idx);
            final TreeFilelistItem tfi = tfa.getDataItem(pos);
            if (tfi.getName().startsWith("---"))
                return;
            expandHideLocalDirTree(true, url, pos, tfi, tfa);
        }
    });
    lv.setOnItemLongClickListener(new OnItemLongClickListener() {
        @Override
        public boolean onItemLongClick(AdapterView<?> arg0, View arg1, final int position, long arg3) {
            final int t_pos = tfa.getItem(position);
            if (tfa.getDataItem(t_pos).isChecked()) {
                ccMenu.addMenuItem(mContext.getString(R.string.msgs_file_select_select_this_entry) + " "
                        + tfa.getDataItem(t_pos).getPath() + tfa.getDataItem(t_pos).getName())
                        .setOnClickListener(new CustomContextMenuOnClickListener() {
                            @Override
                            public void onClick(CharSequence menuTitle) {
                                final TreeFilelistItem tfi = tfa.getDataItem(t_pos);
                                if (tfi.getName().startsWith("---"))
                                    return;
                                tfa.setDataItemIsUnselected(t_pos);
                                if (tfa.isDataItemIsSelected())
                                    btn_ok.setEnabled(true);
                                else
                                    btn_ok.setEnabled(false);
                            }
                        });
            } else {
                ccMenu.addMenuItem(mContext.getString(R.string.msgs_file_select_select_this_entry) + " "
                        + tfa.getDataItem(t_pos).getPath() + tfa.getDataItem(t_pos).getName())
                        .setOnClickListener(new CustomContextMenuOnClickListener() {
                            @Override
                            public void onClick(CharSequence menuTitle) {
                                final TreeFilelistItem tfi = tfa.getDataItem(t_pos);
                                if (tfi.getName().startsWith("---"))
                                    return;
                                tfa.setDataItemIsSelected(t_pos);
                                btn_ok.setEnabled(true);
                            }
                        });
            }
            ccMenu.createMenu();
            return false;
        }
    });
    NotifyEvent ctv_ntfy = new NotifyEvent(mContext);
    ctv_ntfy.setListener(new NotifyEventListener() {
        @Override
        public void positiveResponse(Context c, Object[] o) {
            if (o != null) {
                int pos = (Integer) o[0];
                if (tfa.getDataItem(pos).isChecked())
                    btn_ok.setEnabled(true);
            }
        }

        @Override
        public void negativeResponse(Context c, Object[] o) {
            btn_ok.setEnabled(false);
            for (int i = 0; i < tfa.getDataItemCount(); i++) {
                if (tfa.getDataItem(i).isChecked()) {
                    btn_ok.setEnabled(true);
                    break;
                }
            }
        }
    });
    tfa.setCbCheckListener(ctv_ntfy);

    //OK?
    btn_ok.setEnabled(false);
    btn_ok.setVisibility(Button.VISIBLE);
    btn_ok.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            String sel = "";
            for (int i = 0; i < tfa.getCount(); i++) {
                if (tfa.getDataItem(i).isChecked()
                        && !tfa.getDataItem(i).getName().equals(mContext.getString(R.string.msgs_dir_empty))) {
                    if (tfa.getDataItem(i).getPath().length() == 1)
                        sel = tfa.getDataItem(i).getName();
                    else
                        sel = tfa.getDataItem(i).getPath().substring(1, tfa.getDataItem(i).getPath().length())
                                + tfa.getDataItem(i).getName();
                    break;
                }
            }
            if (sel.equals("")) {

            }
            dialog.dismiss();
            p_ntfy.notifyToListener(true, new Object[] { sel });
        }
    });

    //CANCEL?
    final Button btn_cancel = (Button) dialog.findViewById(R.id.item_select_list_dlg_cancel_btn);
    btn_cancel.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            dialog.dismiss();
            p_ntfy.notifyToListener(false, null);
        }
    });
    // Cancel?
    dialog.setOnCancelListener(new Dialog.OnCancelListener() {
        @Override
        public void onCancel(DialogInterface arg0) {
            btn_cancel.performClick();
        }
    });
    //        dialog.setOnKeyListener(new DialogOnKeyListener(context));
    //        dialog.setCancelable(false);
    dialog.show();

    return;
}