Example usage for android.widget AdapterView getItemAtPosition

List of usage examples for android.widget AdapterView getItemAtPosition

Introduction

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

Prototype

public Object getItemAtPosition(int position) 

Source Link

Document

Gets the data associated with the specified position in the list.

Usage

From source file:de.enlightened.peris.CategoriesFragment.java

@SuppressWarnings("rawtypes")
private void parseCachedForums(final ResultObject result) {
    Log.d(TAG, "parseCachedForums()");
    if (this.categoryList == null || !this.isExtraScrolling) {
        this.categoryList = new ArrayList<>();
    }//from   w  w  w .j av  a 2s.  co  m
    int retainedPosition = getListView().getFirstVisiblePosition();

    if (!this.initialParseDone) {
        final SharedPreferences appPreferences = this.activity.getSharedPreferences("prefs", 0);
        final String savedForumPosition = appPreferences
                .getString(this.storagePrefix + "forumScrollPosition" + this.passedSubforum, "0");
        retainedPosition = Integer.parseInt(savedForumPosition);
    }
    //Announcement Topics
    if (result.announcementTopics != null) {
        //this.categoryList.add(result.announcementTopics);
        this.categoryList.addAll(result.announcementTopics.getTopics());
    }

    //Sticky Topics
    if (result.stickyTopics != null) {
        this.categoryList.addAll(result.stickyTopics.getTopics());
    }

    Log.d(TAG, "Starting category parse! " + this.subforumId);
    //Forums
    if (result.categories != null) {
        this.categoryList.addAll(result.categories.get(this.subforumId).getChildren());
    }
    /*
    if (result.categories != null) {
      ArrayList<CategoryOld> forumz = CategoryParser.parseCategories(result.categories, this.subforumId, this.background);
      Log.d(TAG, "Forums parsed!");
      String currentHash = this.subforumParts[0];
      Log.d(TAG, "Hash Size: " + this.subforumParts.length);
      if (this.subforumParts.length == 1) {
        for (CategoryOld c : forumz) {
          this.categoryList.add(c);
        }
      } else {
        for (int i = 1; i < this.subforumParts.length; i++) {
          currentHash = currentHash + "###" + this.subforumParts[i];
          Log.d(TAG, "Checking hash: " + currentHash + " (total hash is " + this.totalHash + ")");
          ArrayList<CategoryOld> tempForums = null;
          for (CategoryOld c : forumz) {
    if (c.children != null && c.id.contentEquals(currentHash)) {
      tempForums = c.children;
    }
          }
            
          if (tempForums != null) {
    forumz = tempForums;
            
    if (currentHash.contentEquals(this.totalHash)) {
      for (CategoryOld c : forumz) {
        this.categoryList.add(c);
      }
    }
          }
        }
      }
    }*/
    Log.d(TAG, "Finished category parse!");
    //Non-Sticky Topics
    if (result.defaultTopics == null) {
        this.canScrollMoreThreads = false;
    } else {
        this.categoryList.addAll(result.defaultTopics.getTopics());
    }

    if (result.favoriteTopics != null) {
        Log.i(TAG, "We have some favs!");
        this.categoryList.addAll(result.favoriteTopics);
    }

    setListAdapter(new CategoryAdapter(this.categoryList, this.activity, this.application));
    registerForContextMenu(getListView());
    getListView().setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        @SuppressWarnings("checkstyle:requirethis")
        public void onItemClick(final AdapterView<?> parent, final View view, final int position,
                final long id) {
            final TopicItem topicItem = (TopicItem) parent.getItemAtPosition(position);

            if (topicItem != null && categorySelected != null) {
                categorySelected.onTopicItemSelected(topicItem);
            }
        }
    });

    getListView().setSelection(retainedPosition);
    this.initialParseDone = true;
}

From source file:info.zamojski.soft.towercollector.MainActivity.java

private void displayNewVersionDownloadOptions(Bundle extras) {
    UpdateInfo updateInfo = (UpdateInfo) extras.getSerializable(UpdateCheckAsyncTask.INTENT_KEY_UPDATE_INFO);
    // display dialog
    AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this);
    LayoutInflater inflater = LayoutInflater.from(this);
    View dialogLayout = inflater.inflate(R.layout.new_version, null);
    dialogBuilder.setView(dialogLayout);
    final AlertDialog alertDialog = dialogBuilder.create();
    alertDialog.setCanceledOnTouchOutside(true);
    alertDialog.setCancelable(true);/*  w w  w .  j a v a 2  s .com*/
    alertDialog.setTitle(R.string.updater_dialog_new_version_available);
    // load data
    ArrayAdapter<UpdateInfo.DownloadLink> adapter = new UpdateDialogArrayAdapter(alertDialog.getContext(),
            inflater, updateInfo.getDownloadLinks());
    ListView listView = (ListView) dialogLayout.findViewById(R.id.download_options_list);
    listView.setAdapter(adapter);
    // bind events
    final CheckBox disableAutoUpdateCheckCheckbox = (CheckBox) dialogLayout
            .findViewById(R.id.download_options_disable_auto_update_check_checkbox);
    listView.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            DownloadLink downloadLink = (DownloadLink) parent.getItemAtPosition(position);
            Log.d("displayNewVersionDownloadOptions(): Selected position: %s", downloadLink.getLabel());
            boolean disableAutoUpdateCheckCheckboxChecked = disableAutoUpdateCheckCheckbox.isChecked();
            Log.d("displayNewVersionDownloadOptions(): Disable update check checkbox checked = %s",
                    disableAutoUpdateCheckCheckboxChecked);
            if (disableAutoUpdateCheckCheckboxChecked) {
                MyApplication.getPreferencesProvider().setUpdateCheckEnabled(false);
            }
            MyApplication.getAnalytics().sendUpdateAction(downloadLink.getLabel());
            String link = downloadLink.getLink();
            try {
                startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(link)));
            } catch (ActivityNotFoundException ex) {
                Toast.makeText(getApplication(), R.string.web_browser_missing, Toast.LENGTH_LONG).show();
            }
            alertDialog.dismiss();
        }
    });
    alertDialog.setButton(DialogInterface.BUTTON_POSITIVE, getString(R.string.dialog_cancel),
            new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    boolean disableAutoUpdateCheckCheckboxChecked = disableAutoUpdateCheckCheckbox.isChecked();
                    Log.d("displayNewVersionDownloadOptions(): Disable update check checkbox checked = %s",
                            disableAutoUpdateCheckCheckboxChecked);
                    if (disableAutoUpdateCheckCheckboxChecked) {
                        MyApplication.getPreferencesProvider().setUpdateCheckEnabled(false);
                    }
                }
            });
    alertDialog.show();
}

From source file:it.ciopper90.gojack2.MessageListActivity.java

/**
 * {@inheritDoc}//from   ww w . j  a  v  a 2  s .c om
 */
public final boolean onItemLongClick(final AdapterView<?> parent, final View view, final int position,
        final long id) {
    final Context context = this;
    final Message m = Message.getMessage(this, (Cursor) parent.getItemAtPosition(position));
    final Uri target = m.getUri();
    final int read = m.getRead();
    final int type = m.getType();
    Builder builder = new Builder(context);
    builder.setTitle(R.string.message_options_);

    final Contact contact = this.conv.getContact();
    final String a = contact.getNumber();
    Log.d(TAG, "p: " + a);
    final String n = contact.getName();

    String[] items = this.longItemClickDialog;
    if (TextUtils.isEmpty(n)) {
        items[WHICH_VIEW_CONTACT] = this.getString(R.string.add_contact_);
    } else {
        items[WHICH_VIEW_CONTACT] = this.getString(R.string.view_contact_);
    }
    items[WHICH_CALL] = this.getString(R.string.call) + " " + contact.getDisplayName();
    if (read == 0) {
        items = items.clone();
        items[WHICH_MARK_UNREAD] = context.getString(R.string.mark_read_);
    }
    if (type == Message.SMS_DRAFT) {
        items = items.clone();
        items[WHICH_FORWARD] = context.getString(R.string.send_draft_);
    }
    builder.setItems(items, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(final DialogInterface dialog, final int which) {
            Intent i = null;
            switch (which) {
            case WHICH_VIEW_CONTACT:
                if (n == null) {
                    i = ContactsWrapper.getInstance().getInsertPickIntent(a);
                    Conversation.flushCache();
                } else {
                    final Uri u = MessageListActivity.this.conv.getContact().getUri();
                    i = new Intent(Intent.ACTION_VIEW, u);
                }
                try {
                    MessageListActivity.this.startActivity(i);
                } catch (ActivityNotFoundException e) {
                    Log.e(TAG, "activity not found: " + i.getAction(), e);
                    Toast.makeText(MessageListActivity.this, "activity not found", Toast.LENGTH_LONG).show();
                }
                break;
            case WHICH_CALL:
                MessageListActivity.this.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("tel:" + a)));
                break;
            case WHICH_MARK_UNREAD:
                ConversationListActivity.markRead(context, target, 1 - read);
                MessageListActivity.this.markedUnread = true;
                break;
            case WHICH_REPLY:
                // MessageListActivity.this.startActivity(ConversationListActivity
                // .getComposeIntent(MessageListActivity.this, a));
                break;
            case WHICH_FORWARD:
                int resId;
                if (type == Message.SMS_DRAFT) {
                    resId = R.string.send_draft_;
                    // i =
                    // ConversationListActivity.getComposeIntent(MessageListActivity.this,
                    // MessageListActivity.this.conv.getContact().getNumber());
                } else {
                    resId = R.string.forward_;
                    i = new Intent(Intent.ACTION_SEND);
                    i.setType("text/plain");
                    i.putExtra("forwarded_message", true);
                }
                CharSequence text = null;
                if (PreferencesActivity.decodeDecimalNCR(context)) {
                    text = Converter.convertDecNCR2Char(m.getBody());
                } else {
                    text = m.getBody();
                }
                i.putExtra(Intent.EXTRA_TEXT, text);
                i.putExtra("sms_body", text);
                context.startActivity(Intent.createChooser(i, context.getString(resId)));
                break;
            case WHICH_COPY_TEXT:
                final ClipboardManager cm = (ClipboardManager) context
                        .getSystemService(Context.CLIPBOARD_SERVICE);
                if (PreferencesActivity.decodeDecimalNCR(context)) {
                    cm.setText(Converter.convertDecNCR2Char(m.getBody()));
                } else {
                    cm.setText(m.getBody());
                }
                break;
            case WHICH_VIEW_DETAILS:
                final int t = m.getType();
                Builder b = new Builder(context);
                b.setTitle(R.string.view_details_);
                b.setCancelable(true);
                StringBuilder sb = new StringBuilder();
                final String a = m.getAddress(context);
                final long d = m.getDate();
                final String ds = DateFormat.format(context.getString(R.string.DATEFORMAT_details), d)
                        .toString();
                String sentReceived;
                String fromTo;
                if (t == Calls.INCOMING_TYPE) {
                    sentReceived = context.getString(R.string.received_);
                    fromTo = context.getString(R.string.from_);
                } else if (t == Calls.OUTGOING_TYPE) {
                    sentReceived = context.getString(R.string.sent_);
                    fromTo = context.getString(R.string.to_);
                } else {
                    sentReceived = "ukwn:";
                    fromTo = "ukwn:";
                }
                sb.append(sentReceived + " ");
                sb.append(ds);
                sb.append("\n");
                sb.append(fromTo + " ");
                sb.append(a);
                sb.append("\n");
                sb.append(context.getString(R.string.type_));
                if (m.isMMS()) {
                    sb.append(" MMS");
                } else {
                    sb.append(" SMS");
                }
                b.setMessage(sb.toString());
                b.setPositiveButton(android.R.string.ok, null);
                b.show();
                break;
            case WHICH_DELETE:
                ConversationListActivity.deleteMessages(context, target, R.string.delete_message_,
                        R.string.delete_message_question, null);
                break;
            default:
                break;
            }
        }
    });
    builder.show();
    return true;
}

From source file:sysnetlab.android.sdc.ui.CreateExperimentActivity.java

@Override
public void onTagClicked_ExperimentRunTaggingFragment(AdapterView<?> gridview, View view, int position) {
    if (mPreviousTagPosition != position) { // pressed different tags or
                                            // first press
        Log.d("SensorDataCollector", "Tagging: first tag or different tag pressed.");
        Log.d("SensorDataCollector", "previous tag position = " + mPreviousTagPosition + "\t"
                + "current tag position = " + position);

        StateTag stateTag = (StateTag) gridview.getItemAtPosition(position);

        if (mPreviousTagPosition >= 0) { // pressed different tags

            switch (mStateTagPrevious.getState()) {
            case TAG_ON:
                // turn off previous tag
                mStateTagPrevious.setState(TaggingState.TAG_OFF);
                UserInterfaceUtils.setViewBackgroundCompatible(gridview.getChildAt(mPreviousTagPosition),
                        mDrawableBackground);
                /*/*  w  ww  . ja  v  a  2  s. com*/
                 * gridview.getChildAt(mPreviousTagPosition).
                 * setBackgroundColor(
                 * getResources().getColor(android.R.
                 * color.background_light));
                 */
                mExperiment.setLastTagging(new TaggingAction(mStateTagPrevious.getTag(), new ExperimentTime(),
                        TaggingState.TAG_OFF));
                break;
            case TAG_OFF:
            case TAG_CONTEXT:
            }
        } else {
            mDrawableBackground = view.getBackground();
        }

        // turn on current tag
        stateTag.setState(TaggingState.TAG_ON);
        mExperiment.setLastTagging(
                new TaggingAction(stateTag.getTag(), new ExperimentTime(), TaggingState.TAG_ON));
        view.setBackgroundColor(getResources().getColor(android.R.color.darker_gray));

        mPreviousTagPosition = position;
        mStateTagPrevious = stateTag;
    } else { // pressed the same button

        Log.d("SensorDataCollector", "Tagging: first tag or different tag pressed.");
        Log.d("SensorDataCollector", "previous tag position = " + mPreviousTagPosition + "\t"
                + "current tag position = " + position);

        StateTag stateTag = (StateTag) gridview.getItemAtPosition(position);

        switch (stateTag.getState()) {
        case TAG_ON:
            // turn it off
            stateTag.setState(TaggingState.TAG_OFF);
            UserInterfaceUtils.setViewBackgroundCompatible(view, mDrawableBackground);
            /*
             * view.setBackgroundColor(getResources().getColor(
             * android.R.color.background_light));
             */
            mExperiment.setLastTagging(
                    new TaggingAction(mStateTagPrevious.getTag(), new ExperimentTime(), TaggingState.TAG_OFF));
            break;
        case TAG_OFF:
            // turn it on
            stateTag.setState(TaggingState.TAG_ON);
            view.setBackgroundColor(getResources().getColor(android.R.color.darker_gray));
            mExperiment.setLastTagging(
                    new TaggingAction(stateTag.getTag(), new ExperimentTime(), TaggingState.TAG_ON));
            break;
        case TAG_CONTEXT:
        }

        mPreviousTagPosition = position;
        mStateTagPrevious = stateTag;
    }
}

From source file:org.cirdles.chroni.FilePickerActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setTheme(android.R.style.Theme_Holo);

    // Set the view to be shown if the list is empty
    LayoutInflater inflator = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View emptyView = inflator.inflate(R.layout.file_picker_empty_view, null);
    ((ViewGroup) getListView().getParent()).addView(emptyView);
    getListView().setEmptyView(emptyView);

    // adds a RelativeLayout to wrap the listView so that a button can be placed at the bottom
    RelativeLayout outerLayout = (RelativeLayout) inflator.inflate(R.layout.file_picker_regular_view, null);
    ((ViewGroup) getListView().getParent()).addView(outerLayout);

    // sets the margin for the listView so that the bottom item isn't covered
    FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT,
            FrameLayout.LayoutParams.WRAP_CONTENT);
    params.setMargins(0, 0, 0, 100);// w  w w .ja  va  2  s. c  om
    getListView().setLayoutParams(params);

    // defines the action for the bottom button
    Button previousFolderButton = (Button) findViewById(R.id.filePickerPreviousButton);
    previousFolderButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            // moves to the previous directory (if it exists) and refreshes the list of files
            if (mainDirectory.getParentFile() != null) {
                mainDirectory = mainDirectory.getParentFile();
                refreshFilesList();

                // goes through and remo any stubborn delete imageViews
                ViewGroup list = getListView();
                int number = list.getChildCount();

                // gets rid of all the delete images
                for (int i = 0; i < number; i++) {
                    View child = list.getChildAt(i);
                    View checkbox = child.findViewById(R.id.checkBoxFilePicker);
                    checkbox.setVisibility(View.GONE);
                }

                // sets the action bar at the top so that it tells the user what the current directory is
                actionBar = getActionBar();
                if (actionBar != null)
                    actionBar.setTitle("/" + mainDirectory.getName());
            }

            // if in delete mode or move mode, resets back to normal mode
            if (inDeleteMode)
                toggleDelete();
            if (inMovePickMode)
                toggleMove(false); // pass false, not actually executing the move

        }
    });

    // defines what happens to a list item on a long press
    getListView().setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
        @Override
        public boolean onItemLongClick(AdapterView<?> parent, final View view, int position, long id) {
            // stores the address of the file/folder that has been chosen
            final File chosenFile = (File) parent.getItemAtPosition(position);

            if (!choosingDirectory) {
                // only gives options if the chosen file is NOT a directory
                if (!chosenFile.isDirectory()) {
                    // brings up a Dialog box and asks the user if they want to copy or delete the file
                    CharSequence[] options = { "Copy", "Move", "Delete" }; // the user's options
                    new AlertDialog.Builder(FilePickerActivity.this)
                            .setItems(options, new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialog, int which) {
                                    if (which == 0) { // copy has been chosen
                                        // resets cutFiles if it contains files
                                        if (cutFiles != null)
                                            cutFiles = null;

                                        copiedFile = chosenFile;
                                        Toast.makeText(FilePickerActivity.this, "File Copied!",
                                                Toast.LENGTH_SHORT).show();

                                        // sets the pasteButton's visibility to visible once the file has been copied
                                        Button pasteButton = (Button) findViewById(R.id.filePickerPasteButton);
                                        pasteButton.setVisibility(View.VISIBLE);

                                        dialog.dismiss();

                                    } else if (which == 1) { // move has been chosen
                                        // resets copiedFile if it has a file in it
                                        if (copiedFile != null)
                                            copiedFile = null;

                                        cutFiles = new ArrayList<>();
                                        cutFiles.add(chosenFile);
                                        Toast.makeText(FilePickerActivity.this, "File Copied!",
                                                Toast.LENGTH_SHORT).show();

                                        // sets the pasteButton's visibility to visible once the file has been copied
                                        Button pasteButton = (Button) findViewById(R.id.filePickerPasteButton);
                                        pasteButton.setVisibility(View.VISIBLE);

                                        dialog.dismiss();

                                    } else if (which == 2) { // delete has been chosen
                                        // shows a new dialog asking if the user would like to delete the file or not
                                        new AlertDialog.Builder(FilePickerActivity.this)
                                                .setMessage("Are you sure you want to delete this file?")
                                                .setPositiveButton("Yes",
                                                        new DialogInterface.OnClickListener() {
                                                            @Override
                                                            public void onClick(DialogInterface dialog,
                                                                    int which) {
                                                                // if deleting the currently copied file, un-copy it
                                                                if (copiedFile != null
                                                                        && chosenFile.equals(copiedFile)) {
                                                                    copiedFile = null;
                                                                    Button pasteButton = (Button) findViewById(
                                                                            R.id.filePickerPasteButton);
                                                                    pasteButton.setVisibility(View.GONE);
                                                                }

                                                                // deletes the file and updates the adapter
                                                                chosenFile.delete();
                                                                mAdapter.remove(chosenFile);
                                                                dialog.dismiss();
                                                            }
                                                        })
                                                .setNegativeButton("No", new DialogInterface.OnClickListener() {
                                                    @Override
                                                    public void onClick(DialogInterface dialog, int which) {
                                                        dialog.dismiss();
                                                    }
                                                }).show();
                                        dialog.dismiss();
                                    }
                                }
                            }).show();

                } else if (chosenFile.list().length == 0) { // can only delete directory if it's empty

                    // brings up a Dialog box and asks the user if they want to copy or delete the file
                    CharSequence[] options = { "Delete" }; // the user's options
                    new AlertDialog.Builder(FilePickerActivity.this)
                            .setItems(options, new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialog, int which) {
                                    // shows a new dialog asking if the user would like to delete the file or not
                                    new AlertDialog.Builder(FilePickerActivity.this)
                                            .setMessage("Are you sure you want to delete this file?")
                                            .setPositiveButton("Yes", new DialogInterface.OnClickListener() {
                                                @Override
                                                public void onClick(DialogInterface dialog, int which) {
                                                    // if deleting a currently copied or cut file, un-copy it
                                                    if ((copiedFile != null && chosenFile.equals(copiedFile))
                                                            || (cutFiles != null
                                                                    && cutFiles.contains(chosenFile))) {

                                                        // resets the copied/cut file(s)
                                                        if (copiedFile != null)
                                                            copiedFile = null;
                                                        if (cutFiles != null)
                                                            cutFiles = null;

                                                        // and gets rid of the paste button on the bottom
                                                        Button pasteButton = (Button) findViewById(
                                                                R.id.filePickerPasteButton);
                                                        pasteButton.setVisibility(View.GONE);
                                                    }

                                                    // deletes the file and updates the adapter
                                                    chosenFile.delete();
                                                    mAdapter.remove(chosenFile);
                                                    Toast.makeText(FilePickerActivity.this, "File Deleted!",
                                                            Toast.LENGTH_SHORT).show();

                                                    dialog.dismiss();
                                                }
                                            }).setNegativeButton("No", new DialogInterface.OnClickListener() {
                                                @Override
                                                public void onClick(DialogInterface dialog, int which) {
                                                    dialog.dismiss();
                                                }
                                            }).show();
                                }
                            }).show();
                }
            }

            return true;
        }
    });

    // Obtain content from the current intent for later use
    intentContent = getIntent().getStringExtra("Default_Directory");

    // Set initial directory if it hasn't been already defined
    if (mainDirectory == null) {
        mainDirectory = Environment.getExternalStorageDirectory(); // Takes user to root directory folder

        // Sets the initial directory based on what file the user is looking for (Aliquot or Report Settings)
        if (intentContent.contentEquals("Aliquot_Directory")
                || intentContent.contentEquals("From_Aliquot_Directory"))
            mainDirectory = new File(mainDirectory + "/CHRONI/Aliquot"); // Takes user to the Aliquot folder

        // Report Settings Menu if coming from a Dropdown Menu or the Report Settings Menu
        else if (intentContent.contentEquals("Report_Settings_Directory")
                || intentContent.contentEquals("From_Report_Directory"))
            mainDirectory = new File(mainDirectory + "/CHRONI/Report Settings");

        else if (intentContent.contentEquals("Parent_Directory"))
            choosingDirectory = true; // choosing a directory rather than a file

        // if none of these are true, the directory will be CHRONI's parent directory (externalStorageDirectory)
    }

    // sets the action bar at the top so that it tells the user what the current directory is
    actionBar = getActionBar();
    if (actionBar != null)
        actionBar.setTitle("/" + mainDirectory.getName());

    // Initialize the ArrayList
    mFiles = new ArrayList<>();

    // Set the ListAdapter
    mAdapter = new FilePickerListAdapter(this, mFiles);
    setListAdapter(mAdapter);

    // Initialize the extensions array to allow any file extensions
    acceptedFileExtensions = new String[] {};

    // Get intent extras
    if (getIntent().hasExtra(EXTRA_SHOW_HIDDEN_FILES)) {
        mShowHiddenFiles = getIntent().getBooleanExtra(EXTRA_SHOW_HIDDEN_FILES, false);
    }
    if (getIntent().hasExtra(EXTRA_ACCEPTED_FILE_EXTENSIONS)) {
        ArrayList<String> collection = getIntent().getStringArrayListExtra(EXTRA_ACCEPTED_FILE_EXTENSIONS);
        acceptedFileExtensions = collection.toArray(new String[collection.size()]);
    }

    // if no file permissions, asks for them
    if (ContextCompat.checkSelfPermission(this,
            android.Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
        ActivityCompat.requestPermissions(this,
                new String[] { android.Manifest.permission.WRITE_EXTERNAL_STORAGE }, 1);
    }
}

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

/**
 * Event triggered when clicking on any location from the list.
 *///from  www .  j a  va2 s  . c  o  m
@Override
public void onItemClick(AdapterView<?> parent, View arg1, int position, long arg3) {
    try {
        latitude = 0.0;
        longitute = 0.0;
        String selected = (String) parent.getItemAtPosition(position);
        int pos = autosug_item_text.indexOf(selected);
        Log.d(TAG, "json ->" + json_autosug_list.get(pos).toString());
        locationId = json_autosug_list.get(pos).getInt("id");
    } catch (JSONException e) {
        e.printStackTrace();
    }
}

From source file:tv.acfun.a63.CommentsActivity.java

@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
    int count = mAdapter.getCount();
    if (position > count) {
        if (isreload) {
            mFootview.findViewById(R.id.list_footview_progress).setVisibility(View.VISIBLE);
            TextView textview = (TextView) mFootview.findViewById(R.id.list_footview_text);
            textview.setText(R.string.loading);
            requestData(pageIndex, false);
        }/*  www. jav a2s .  c o  m*/
        return;
    }
    showBar(); // show input bar when selected comment
    Object o = parent.getItemAtPosition(position);
    if (o == null || !(o instanceof Comment))
        return;
    Comment c = (Comment) o;
    int quoteCount = getQuoteCount();
    removeQuote(mCommentText.getText());
    if (quoteCount == c.count)
        return; // ?
    String pre = ":#" + c.count;
    mQuoteSpan = new Quote(c.count);
    /**
     * @see http 
     *      ://www.kpbird.com/2013/02/android-chips-edittext-token-edittext
     *      .html
     */
    SpannableStringBuilder sb = SpannableStringBuilder.valueOf(mCommentText.getText());
    TextView tv = TextViewUtils.createBubbleTextView(this, pre);
    BitmapDrawable bd = (BitmapDrawable) TextViewUtils.convertViewToDrawable(tv);
    bd.setBounds(0, 0, bd.getIntrinsicWidth(), bd.getIntrinsicHeight());
    sb.insert(0, pre);
    mQuoteImage = new ImageSpan(bd);
    sb.setSpan(mQuoteImage, 0, pre.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    sb.setSpan(mQuoteSpan, 0, pre.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    sb.append("");
    mCommentText.setText(sb);
    mCommentText.setSelection(mCommentText.getText().length());
}

From source file:net.inbox.InboxMessage.java

/**
 * Dialog picking the folder for the attachment download.
 **///from   www.j  av  a 2  s  . c  o m
private void dialog_folder_picker() {
    chosen_folder = null;
    refresh_folders(1);

    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setTitle(getString(R.string.folder_title));
    builder.setPositiveButton(getString(R.string.btn_up_one_level), null);

    // Populating folders
    ListView lv_folders = new ListView(this);
    lv_folders.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
            // Obtain the index of the chosen folder
            String str = (String) parent.getItemAtPosition(position);
            for (File f : f_folders) {
                if (f.getName().equals(str)) {
                    current_path = f;
                    break;
                }
            }
            refresh_folders(2);
            lv_adapter.notifyDataSetChanged();
        }
    });

    // Continuing download
    lv_folders.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {

        @Override
        public boolean onItemLongClick(AdapterView<?> parent, View v, int position, long id) {
            // Obtain the index of the chosen folder
            String str = (String) parent.getItemAtPosition(position);
            for (File f : f_folders) {
                if (f.getName().equals(str)) {
                    chosen_folder = f;
                    break;
                }
            }
            dialog_folder_picker.dismiss();
            if (chosen_att == null) {
                full_message_tests();
            } else {
                attachment_tests();
            }
            return true;
        }
    });

    lv_adapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, s_folders);
    lv_folders.setAdapter(lv_adapter);

    builder.setView(lv_folders);
    dialog_folder_picker = builder.show();

    // Reassigning button to prevent early dialog ending
    dialog_folder_picker.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if (current_path.getParent() != null) {
                refresh_folders(3);
                lv_adapter.notifyDataSetChanged();
            }
        }
    });
}

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

public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
    if (doOnClick != null) {
        if (System.currentTimeMillis() < doOnClickActualTime + 1000) {
            doOnClick.run();/*from w  w w  . ja v  a  2  s  .  co  m*/
        }
        doOnClick = null;
        return;
    }
    JuickMessage jmsg = (JuickMessage) parent.getItemAtPosition(position);
    parentActivity.onReplySelected(jmsg);
}

From source file:com.procleus.brime.ui.LabelsFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    // Inflate the layout for this fragment
    ((MainActivity) getActivity()).setActionBarTitle("Labels");
    ((MainActivity) getActivity()).showFloatingActionButton(true);
    final View v = inflater.inflate(R.layout.labels_gragment, container, false);
    final NotesDbHelperOld tn = new NotesDbHelperOld(getActivity());

    labelsRetrieved = new ArrayList<String>();
    labelsRetrieved = tn.retrieveLabel();

    listView = (ListView) v.findViewById(R.id.listLabel);
    final ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(getContext(),
            android.R.layout.simple_list_item_1, labelsRetrieved);
    listView.setAdapter(arrayAdapter);//from w  w w . j av a  2  s  .co m
    ImageButton addLabelBtn = (ImageButton) v.findViewById(R.id.addLabelBtn);

    addLabelBtn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            addLabelFunc(v, tn);
        }
    });

    /*/WORK OF LONG ITEM CLICK LISTENER*/

    listView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
        @Override
        public boolean onItemLongClick(final AdapterView<?> parent, View view, final int position, long id) {

            final Dialog dialog = new Dialog(getContext());
            dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
            dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
            dialog.setCancelable(false);
            dialog.setContentView(R.layout.dialog_label);
            dialog.show();

            final Button negative = (Button) dialog.findViewById(R.id.btn_no_label);
            final Button positive = (Button) dialog.findViewById(R.id.btn_yes_label);

            negative.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {

                    dialog.dismiss();

                }
            });

            positive.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {

                    Log.i("brinjal", "Yes");

                    tn.deleteTextNote(String.valueOf(parent.getItemAtPosition(position)));
                    final ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(getContext(),
                            android.R.layout.simple_list_item_1, labelsRetrieved);
                    listView.setAdapter(arrayAdapter);
                    dialog.dismiss();

                }

            });

            return true;

        }
    });

    return v;
}