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:com.neu.fragment.BancheTimeFragment.java

public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.banche_info, null);
    screenWidth = getActivity().getWindowManager().getDefaultDisplay().getWidth();
    screenHeight = getActivity().getWindowManager().getDefaultDisplay().getHeight();

    toast = new Toast(getActivity());

    // System.out.println(screenHeight+"px");
    // System.out.println("width:" + screenWidth);
    tableInfo = (TableLayout) view.findViewById(R.id.tableInfo);
    fromHunnan = (RelativeLayout) view.findViewById(R.id.hunnan_bt);
    fromNanhu = (RelativeLayout) view.findViewById(R.id.nanhu_bt);
    from_tx = (TextView) view.findViewById(R.id.from_tx);
    // spinner = (Spinner) view.findViewById(R.id.spinner_type);
    // ???// ww w .j a va  2 s .c o  m
    selected_image = (ImageView) view.findViewById(R.id.selected_image);
    selected_name = (TextView) view.findViewById(R.id.selected_name);
    searchName = selected_name.getText().toString();
    searchName_fore = searchName;

    stu_show = (LinearLayout) view.findViewById(R.id.stu_show);
    dialog = MyDialog.createLoadingDialog(getActivity(), "...");

    freshInfo = (TextView) view.findViewById(R.id.fresh_info);
    //??
    freshInfo.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {

            new Thread(new Runnable() {
                String result = "";

                @Override
                public void run() {
                    try {
                        // TODO Auto-generated method stub
                        //xml???
                        StoreBancheInfoUtils.storeInfoFromNet(getActivity());

                    } catch (UnkownNetWorkException e) {
                        System.out.println(e.getMessage());

                        Message msg = new Message();
                        msg.what = MSG_NETERROR;
                        handler.sendMessage(msg);

                    } catch (IOException e) {
                        // TODO: handle exception
                    }
                }
            }).start();
        }
    });
    // popMenu
    final PopMenu popMenu = new PopMenu(getActivity(), screenWidth);

    // ??
    RelativeLayout showType = (RelativeLayout) view.findViewById(R.id.select_type);
    showType.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View view) {
            // TODO Auto-generated method stub
            popMenu.showAsDropDown(view);

        }
    });
    // ? 
    popMenu.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            // TODO Auto-generated method stub
            searchName = ((Person) parent.getItemAtPosition(position)).getItem_name().toString();
            int drawable = ((Person) parent.getItemAtPosition(position)).getItem_image();
            selected_image.setBackgroundResource(drawable);
            selected_name.setText(searchName);
            if (searchName.equals("")) {
                if (!searchName_fore.equals(searchName)) {
                    stu_show.setVisibility(View.VISIBLE);
                    from_tx.setText("");
                    tableInfo.removeAllViews();
                }
            } else if (searchName.equals("?")) {
                if (!searchName_fore.equals(searchName)) {
                    stu_show.setVisibility(View.GONE);
                    from_tx.setText("");
                    tableInfo.removeAllViews();
                }
            }
            searchName_fore = searchName;

            popMenu.dismiss();
        }
    });

    fromHunnan.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {

            from = "?";
            task = new SearchAsyncTask();
            task.dialog = dialog;
            task.from = from;
            task.stu_show = stu_show;
            task.from_tx = from_tx;
            task.toast = toast;
            task.searchName = searchName;
            task.tableInfo = tableInfo;
            task.execute();
        }
    });
    fromNanhu.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {

            if (searchName.equals(""))
                from = "??";
            else
                from = "?";
            task = new SearchAsyncTask();
            task.dialog = dialog;
            task.from = from;
            task.toast = toast;
            task.stu_show = stu_show;
            task.from_tx = from_tx;
            task.searchName = searchName;
            task.tableInfo = tableInfo;
            task.execute();
        }
    });

    return view;
}

From source file:biz.incomsystems.fwknop2.ConfigDetailFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.fragment_config_detail, container, false);
    active_Nick = getArguments().getString("item_id");
    myJuice = new PluginContract();

    //Handlers for the input fields
    txt_NickName = (TextView) rootView.findViewById(R.id.NickName);
    txt_allowIP = (TextView) rootView.findViewById(R.id.iptoallow);
    lay_allowIP = (LinearLayout) rootView.findViewById(R.id.iptoallowsl);
    lay_natIP = (LinearLayout) rootView.findViewById(R.id.natipsl);
    lay_natport = (LinearLayout) rootView.findViewById(R.id.natportsl);
    lay_serverCMD = (LinearLayout) rootView.findViewById(R.id.servercmdsl);
    txt_ports = (TextView) rootView.findViewById(R.id.AccessPorts);
    txt_server_ip = (TextView) rootView.findViewById(R.id.destIP);
    txt_server_port = (TextView) rootView.findViewById(R.id.destPort);
    txt_server_time = (TextView) rootView.findViewById(R.id.fwTimeout);
    txt_server_cmd = (TextView) rootView.findViewById(R.id.servercmd);
    txt_nat_ip = (TextView) rootView.findViewById(R.id.natip);
    txt_nat_port = (TextView) rootView.findViewById(R.id.natport);
    lay_AccessPort = (LinearLayout) rootView.findViewById(R.id.AccessPortsl);
    lay_fwTimeout = (LinearLayout) rootView.findViewById(R.id.fwTimeoutl);
    lay_sshcmd = (LinearLayout) rootView.findViewById(R.id.sshcmdsl);
    txt_ssh_cmd = (TextView) rootView.findViewById(R.id.sshcmd);
    txt_KEY = (TextView) rootView.findViewById(R.id.passwd);
    txt_HMAC = (TextView) rootView.findViewById(R.id.hmac);
    chkb64hmac = (CheckBox) rootView.findViewById(R.id.chkb64hmac);
    chkb64key = (CheckBox) rootView.findViewById(R.id.chkb64key);

    spn_juice = (Spinner) rootView.findViewById(R.id.juice_spn);
    juice_adapt = new ConnectionSpinnerAdapter(getActivity());
    spn_juice.setAdapter(juice_adapt);/*from w  w w. j av  a 2  s .  co  m*/

    spn_allowip = (Spinner) rootView.findViewById(R.id.allowip);
    ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(getActivity(), R.array.spinner_options,
            android.R.layout.simple_spinner_item);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spn_allowip.setAdapter(adapter);
    spn_allowip.setOnItemSelectedListener(new OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {
            if (parent.getItemAtPosition(pos).toString().equalsIgnoreCase("Allow IP")) {
                lay_allowIP.setVisibility(View.VISIBLE);
            } else {
                lay_allowIP.setVisibility(View.GONE);
            }
        }

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

    spn_ssh = (Spinner) rootView.findViewById(R.id.ssh);
    ArrayAdapter<CharSequence> adapter_ssh = ArrayAdapter.createFromResource(getActivity(), R.array.ssh_options,
            android.R.layout.simple_spinner_item);
    adapter_ssh.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spn_ssh.setAdapter(adapter_ssh);
    spn_ssh.setOnItemSelectedListener(new OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {
            // An item was selected. You can retrieve the selected item using
            // parent.getItemAtPosition(pos)
            if (parent.getItemAtPosition(pos).toString().equalsIgnoreCase("None")) {
                lay_sshcmd.setVisibility(View.GONE);
                spn_juice.setVisibility(View.GONE);
                // blank the other options here
            } else if (parent.getItemAtPosition(pos).toString().equalsIgnoreCase("SSH Uri")) {
                // show the txt for the uri
                lay_sshcmd.setVisibility(View.VISIBLE);
                spn_juice.setVisibility(View.GONE);
            } else if (parent.getItemAtPosition(pos).toString().equalsIgnoreCase("Juicessh")) {
                lay_sshcmd.setVisibility(View.GONE);

                if (connectionListLoader == null) {
                    connectionListLoader = new ConnectionListLoader(getActivity(), juice_adapt);
                    connectionListLoader.setOnLoadedListener(new ConnectionListLoader.OnLoadedListener() {
                        @Override
                        public void onLoaded() { // This is so ugly...
                            spn_juice.setVisibility(View.VISIBLE);
                            if (config.SSH_CMD.contains("juice:") && spn_juice.getCount() > 0) {
                                for (int n = 0; n < spn_juice.getCount(); n++) {
                                    if (config.SSH_CMD.contains(juice_adapt.getConnectionName(n))) {
                                        spn_juice.setSelection(n);
                                    }
                                }
                            }
                        }
                    });
                    getActivity().getSupportLoaderManager().initLoader(0, null, connectionListLoader);
                } else {
                    getActivity().getSupportLoaderManager().restartLoader(0, null, connectionListLoader);
                }
            }
        }

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

    spn_configtype = (Spinner) rootView.findViewById(R.id.configtype);
    ArrayAdapter<CharSequence> adapter2 = ArrayAdapter.createFromResource(getActivity(),
            R.array.configtype_options, android.R.layout.simple_spinner_item);
    adapter2.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spn_configtype.setAdapter(adapter2);
    spn_configtype.setOnItemSelectedListener(new OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {
            if (parent.getItemAtPosition(pos).toString().equalsIgnoreCase("Open Port")) {
                configtype = "Open Port";
                lay_AccessPort.setVisibility(View.VISIBLE);
                lay_fwTimeout.setVisibility(View.VISIBLE);
                txt_nat_ip.setText("");
                txt_nat_port.setText("");
                txt_server_cmd.setText("");
            } else {
                lay_AccessPort.setVisibility(View.GONE);
                lay_fwTimeout.setVisibility(View.GONE);
            }
            if (parent.getItemAtPosition(pos).toString().equalsIgnoreCase("Nat Access")) {
                configtype = "Nat Access";
                txt_server_cmd.setText("");
                lay_AccessPort.setVisibility(View.VISIBLE);
                lay_fwTimeout.setVisibility(View.VISIBLE);
                lay_natIP.setVisibility(View.VISIBLE);
                lay_natport.setVisibility(View.VISIBLE);
            } else {
                lay_natIP.setVisibility(View.GONE);
                lay_natport.setVisibility(View.GONE);
            }
            if (parent.getItemAtPosition(pos).toString().equalsIgnoreCase("Server Command")) {
                configtype = "Server Command";
                lay_serverCMD.setVisibility(View.VISIBLE);
                txt_ports.setText("");
                txt_nat_ip.setText("");
                txt_nat_port.setText("");
                txt_server_time.setText("");
            } else {
                lay_serverCMD.setVisibility(View.GONE);
            }
        }

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

    //Below is the loading of a saved config
    if (active_Nick.equalsIgnoreCase("")) {
        txt_NickName.setText("");
        config.SSH_CMD = "";
        txt_HMAC.setInputType(InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD);
        txt_KEY.setInputType(InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD);
    } else {
        config = mydb.getConfig(active_Nick);
        txt_NickName.setText(active_Nick);
        if (config.ACCESS_IP.equalsIgnoreCase("Resolve IP")) {
            spn_allowip.setSelection(0);
        } else if (config.ACCESS_IP.equalsIgnoreCase("0.0.0.0")) {
            spn_allowip.setSelection(1);
        } else {
            spn_allowip.setSelection(2);
            txt_allowIP.setText(config.ACCESS_IP);
        }
        txt_ports.setText(config.PORTS);
        txt_server_ip.setText(config.SERVER_IP);
        txt_server_port.setText(config.SERVER_PORT);
        txt_server_time.setText(config.SERVER_TIMEOUT);
        txt_KEY.setText(config.KEY);
        if (config.KEY_BASE64) {
            chkb64key.setChecked(true);
        } else {
            chkb64key.setChecked(false);
        }
        txt_HMAC.setText(config.HMAC);
        if (config.HMAC_BASE64) {
            chkb64hmac.setChecked(true);
        } else {
            chkb64hmac.setChecked(false);
        }
        if (!config.SERVER_CMD.equalsIgnoreCase("")) {
            spn_configtype.setSelection(2);
            txt_server_cmd.setText(config.SERVER_CMD);
        } else if (!config.NAT_IP.equalsIgnoreCase("")) {
            spn_configtype.setSelection(1);
            txt_ports.setText(config.PORTS);
            txt_nat_ip.setText(config.NAT_IP);
            txt_nat_port.setText(config.NAT_PORT);
            txt_server_time.setText(config.SERVER_TIMEOUT);
        } else {
            spn_configtype.setSelection(0);
        }
        if (config.SSH_CMD.equalsIgnoreCase("")) {
            spn_ssh.setSelection(0);
        } else if (config.SSH_CMD.contains("juice:")) {
            spn_ssh.setSelection(2);
        } else {
            spn_ssh.setSelection(1);
            txt_ssh_cmd.setText(config.SSH_CMD);
        }
    }
    return rootView;
}

From source file:id.ridon.keude.views.ManageReposActivity.java

private void scanForRepos() {
    final RepoScanListAdapter adapter = new RepoScanListAdapter(this);
    final MDnsHelper mDnsHelper = new MDnsHelper(this, adapter);

    final View view = getLayoutInflater().inflate(R.layout.repodiscoverylist, null);
    final ListView repoScanList = (ListView) view.findViewById(R.id.reposcanlist);

    final AlertDialog alrt = new AlertDialog.Builder(this).setView(view)
            .setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
                @Override/*from  ww  w . j  a va  2 s . c  o  m*/
                public void onClick(DialogInterface dialog, int which) {
                    mDnsHelper.stopDiscovery();
                    dialog.dismiss();
                }
            }).create();

    alrt.setTitle(R.string.local_repos_title);
    alrt.setOnDismissListener(new DialogInterface.OnDismissListener() {
        @Override
        public void onDismiss(DialogInterface dialog) {
            mDnsHelper.stopDiscovery();
        }
    });

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

            final DiscoveredRepo discoveredService = (DiscoveredRepo) parent.getItemAtPosition(position);

            final ServiceInfo serviceInfo = discoveredService.getServiceInfo();
            String type = serviceInfo.getPropertyString("type");
            String protocol = type.contains("fdroidrepos") ? "https:/" : "http:/";
            String path = serviceInfo.getPropertyString("path");
            if (TextUtils.isEmpty(path))
                path = "/fdroid/repo";
            String serviceUrl = protocol + serviceInfo.getInetAddresses()[0] + ":" + serviceInfo.getPort()
                    + path;
            showAddRepo(serviceUrl, serviceInfo.getPropertyString("fingerprint"));
        }
    });

    alrt.show();
    mDnsHelper.discoverServices();
}

From source file:de.sindzinski.wetter.ForecastDailyFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    // The ForecastAdapter will take data from a source and
    // use it to populate the ListView it's attached to.
    mForecastAdapter = new ForecastAdapterDaily(getActivity(), null, 0);

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

    // Get a reference to the ListView, and attach this adapter to it.
    mListView = (ListView) rootView.findViewById(R.id.listview_forecast);
    mListView.setAdapter(mForecastAdapter);
    mListView.setNestedScrollingEnabled(true);
    View emptyView = rootView.findViewById(R.id.listview_forecast_empty);
    mListView.setEmptyView(emptyView);/*from ww  w.ja  v a  2 s .c o m*/
    // We'll call our MainActivity
    mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) {
            // CursorAdapter returns a cursor at the correct position for getItem(), or null
            // if it cannot seek to that position.
            Cursor cursor = (Cursor) adapterView.getItemAtPosition(position);
            if (cursor != null) {
                String locationSetting = Utility.getPreferredLocation(getActivity());
                mForecastAdapter.selectedItem(position);
                mForecastAdapter.notifyDataSetChanged();
                //                    ((CallbackDaily) getActivity())
                //                            .onItemSelectedDaily(WeatherContract.WeatherEntry.buildWeatherLocationWithDateDaily(
                //                                    locationSetting, cursor.getLong(COL_WEATHER_DATE)));
            }
            mPosition = position;

        }
    });

    /*
    * Sets up a SwipeRefreshLayout.OnRefreshListener that is invoked when the user
    * performs a swipe-to-refresh gesture.
    */
    mSwipeRefreshLayout = (SwipeRefreshLayout) rootView.findViewById(R.id.swiperefresh);
    mSwipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
        @Override
        public void onRefresh() {
            Log.i(LOG_TAG, "onRefresh called from SwipeRefreshLayout");

            // This method performs the actual data-refresh operation.
            // The method calls setRefreshing(false) when it's finished.
            // get the new data from you data source
            if (!WetterSyncAdapter.syncImmediately(getActivity())) {
                if (mSwipeRefreshLayout.isRefreshing()) {
                    mSwipeRefreshLayout.setRefreshing(false);
                }
            }
            ;

            /* our swipeRefreshLayout needs to be notified when the data is
            returned in order for it to stop the animation */
            //                        mHandler.post(refreshing);
        }
    });
    // sets the colors used in the refresh animation
    mSwipeRefreshLayout.setColorSchemeResources(R.color.primary, R.color.primary_dark, R.color.primary_light);

    // If there's instance state, mine it for useful information.
    // The end-goal here is that the user never knows that turning their device sideways
    // does crazy lifecycle related things.  It should feel like some stuff stretched out,
    // or magically appeared to take advantage of room, but data or place in the app was never
    // actually *lost*.
    if (savedInstanceState != null && savedInstanceState.containsKey(SELECTED_KEY)) {
        // The listview probably hasn't even been populated yet.  Actually perform the
        // swapout in onLoadFinished.
        mPosition = savedInstanceState.getInt(SELECTED_KEY);
    }

    mForecastAdapter.setUseTodayLayout(mUseTodayLayout);

    return rootView;
}

From source file:com.granita.tasks.EditTaskFragment.java

@Override
public void onItemSelected(AdapterView<?> arg0, View arg1, int pos, long itemId) {
    Cursor c = (Cursor) arg0.getItemAtPosition(pos);

    String accountType = c.getString(TASK_LIST_PROJECTION_VALUES.account_type);
    mListColor = TaskFieldAdapters.LIST_COLOR.get(c);
    updateColor((float) mRootView.getScrollY() / mTaskListBar.getMeasuredHeight());

    if (mEditor != null) {
        mEditor.updateValues();//from   w w w.j  av a  2s .  com
    }

    if (!mAppForEdit) {
        long listId = c.getLong(TASK_LIST_PROJECTION_VALUES.id);
        mValues.put(Tasks.LIST_ID, listId);
        mSelectedList = itemId;
        mLastAccountType = c.getString(TASK_LIST_PROJECTION_VALUES.account_type);
    }

    if (mModel == null || !mModel.getAccountType().equals(accountType)) {
        // the model changed, load the new model
        Sources.loadModelAsync(mAppContext, accountType, this);
    } else {
        postUpdateView();
    }
}

From source file:org.alfresco.mobile.android.application.fragments.menu.MainMenuFragment.java

@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
    AlfrescoAccount acc = (AlfrescoAccount) parent.getItemAtPosition(position);
    int accountId = (int) acc.getId();

    switch (accountId) {
    case AccountsAdapter.PROFILES_ITEM:
        ProfilesConfigFragment.with(getActivity()).display();
        hideSlidingMenu(false);/*from   www  .  ja  va 2 s .c o m*/
        refresh();
        break;
    case AccountsAdapter.NETWORK_ITEM:
        NetworksFragment.with(getActivity()).display();
        hideSlidingMenu(false);
        refresh();
        break;
    case AccountsAdapter.MANAGE_ITEM:
        displayPreferences((BaseActivity) getActivity(), getAccount().getId());
        hideSlidingMenu(false);
        refresh();
        break;
    default:
        if (currentAccount != null && currentAccount.getId() != accountId) {
            if (getActivity() instanceof AlfrescoActivity) {
                ((TextView) accountsSpinnerButton.findViewById(R.id.accounts_spinner_title))
                        .setText(acc.getTitle());
                ((AlfrescoActivity) getActivity()).swapAccount(acc);
                if (SLIDING_TAG.equals(getTag())) {
                    ((MainMenuFragment) ((AlfrescoActivity) getActivity()).getFragment(TAG)).swapAccount();
                } else {
                    ((MainMenuFragment) ((AlfrescoActivity) getActivity()).getFragment(SLIDING_TAG))
                            .swapAccount();
                }
            }
        }
        break;
    }

    listPopupWindow.dismiss();
    listPopupWindow = null;
}

From source file:com.example.lowviscam.GalleryActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    isLight = getIntent().getExtras().getBoolean("isLight");
    if (isLight == false) {
        this.setTheme(R.style.AppBaseThemeDark);
    } else {//from   w  w w. j  a  va  2s  . co  m
        this.setTheme(R.style.AppBaseTheme);
    }
    setContentView(R.layout.activity_gallery);

    // Retrieve APHont font and apply it
    mFace = Typeface.createFromAsset(getAssets(), "fonts/APHont-Regular_q15c.otf");
    SpannableString s = new SpannableString("Image Gallery");
    s.setSpan(new TypefaceSpan(this, "APHont-Bold_q15c.otf"), 0, s.length(),
            Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

    // Update the action bar title with the TypefaceSpan instance
    ActionBar actionBar = getActionBar();
    actionBar.setTitle(s);

    actionBar.setDisplayHomeAsUpEnabled(true);

    // Fetch the {@link LayoutInflater} service so that new views can be created
    LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);

    // Find the {@link GridView} that was already defined in the XML layout
    GridView gridView = (GridView) findViewById(R.id.grid);

    // Initialize the adapter with all the coupons. Set the adapter on the {@link GridView}.
    try {
        gridView.setAdapter(new CouponAdapter(inflater, createAllCoupons()));
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    // Set a click listener for each picture in the grid
    gridView.setOnItemClickListener(this);
    gridView.setOnTouchListener(new OnSwipeTouchListener() {

        public void onSwipeTop() {
            //Toast.makeText(GalleryActivity.this, "top", Toast.LENGTH_SHORT).show();
        }

        public void onSwipeRight() {
            //Toast.makeText(GalleryActivity.this, "right", Toast.LENGTH_SHORT).show();
        }

        public void onSwipeLeft() {
            //Toast.makeText(GalleryActivity.this, "left", Toast.LENGTH_SHORT).show();
        }

        public void onSwipeBottom() {
            //Toast.makeText(GalleryActivity.this, "bottom", Toast.LENGTH_SHORT).show();
        }

    });
    gridView.setOnItemLongClickListener(new OnItemLongClickListener() {

        public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
            // Find coupon that was clicked based off of position in adapter
            Coupon coupon = (Coupon) parent.getItemAtPosition(position);
            //Get absolutepath of image for adding.
            File list[] = mediaStorageDir.listFiles();
            File tmpFile = list[list.length - position - 1];
            String photoUri = coupon.mImageUri.toString();
            try {
                photoUri = MediaStore.Images.Media.insertImage(getContentResolver(), tmpFile.getAbsolutePath(),
                        null, null);
            } catch (FileNotFoundException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            // Create share intent
            Intent shareIntent = ShareCompat.IntentBuilder.from(GalleryActivity.this).setText(coupon.mTitle)
                    .setType("image/jpeg").setStream(Uri.parse(photoUri))
                    .setChooserTitle(getString(R.string.share_using)).createChooserIntent();
            startActivity(shareIntent);

            return true;
        }
    });

}

From source file:com.kunze.androidlocaltodo.TaskListActivity.java

@Override
public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
    Cursor cursor = (Cursor) parent.getItemAtPosition(position);
    final Task task = mDB.LoadTask(cursor);
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setTitle("Done?");
    builder.setMessage("Mark task \"" + task.mName + "\" as done?");
    builder.setNegativeButton("No", null);
    builder.setPositiveButton("Yes", new OnClickListener() {
        @Override/* w  w w .j  a  v a2 s  .c o  m*/
        public void onClick(DialogInterface dialog, int which) {
            if (task.mRepeatUnit == Task.RepeatUnit.NONE) {
                task.mCompletedDate = Calendar.getInstance();
            } else {
                Calendar repeatBase = Calendar.getInstance();
                if (!task.mRepeatFromComplete) {
                    repeatBase = task.mDueDate;
                }
                int calUnit;
                int calNumber = 1;
                switch (task.mRepeatUnit) {
                case DAYS:
                    calUnit = Calendar.DATE;
                    break;
                case WEEKS:
                    calUnit = Calendar.DATE;
                    calNumber = 7;
                    break;
                case MONTHS:
                    calUnit = Calendar.MONTH;
                    break;
                case YEARS:
                    calUnit = Calendar.YEAR;
                    break;
                default:
                    calUnit = Calendar.DATE;
                    calNumber = 0;
                    break;
                }
                calNumber *= task.mRepeatTime;
                task.mDueDate = repeatBase;
                task.mDueDate.add(calUnit, calNumber);
            }
            mDB.SaveTask(task);
            RefreshView();
        }
    });
    builder.show();
    return true;
}

From source file:com.hybris.mobile.app.commerce.adapter.ProductListAdapterBase.java

protected OnItemSelectedListener getProductDetailVariantSpinnerListener() {
    return new OnItemSelectedListener() {
        @Override/*from   www  . j a  v  a2 s . c om*/
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {

            if (parent.getItemAtPosition(position) != null && mTriggerSpinnerOnChange) {

                Spinner spinnerToUpdate = null;

                switch (parent.getId()) {
                case R.id.product_item_variant_spinner_1:
                    spinnerToUpdate = mCurrentSelectedViewHolder.productItemVariantSpinner2;
                    break;

                case R.id.product_item_variant_spinner_2:
                    spinnerToUpdate = mCurrentSelectedViewHolder.productItemVariantSpinner3;
                    break;

                default:
                    break;
                }

                onItemSpinnerSelected(spinnerToUpdate, parent.getItemAtPosition(position));
            }

            // Workaround to activate the onchange listener only after having instantiated the latest spinner
            mNbVariantLevelsInstantiated++;
            if (mNbVariantLevelsInstantiated == mNbVariantLevels) {
                mTriggerSpinnerOnChange = true;
            }

        }

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

From source file:eu.vranckaert.worktime.activities.timeregistrations.TimeRegistrationListActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_registrations);

    setTitle(R.string.lbl_registrations_title);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setHomeButtonEnabled(true);

    // Setup slide-in menu
    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    mDrawerList = (ListView) findViewById(R.id.left_drawer);
    mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, R.drawable.ic_navigation_drawer,
            R.string.drawer_open, R.string.drawer_close) {

        /** Called when a drawer has settled in a completely closed state. */
        public void onDrawerClosed(View view) {
            getActionBar().setTitle(R.string.lbl_registrations_title);
            invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
        }/*w  w  w. j  a va  2s  .c o m*/

        /** Called when a drawer has settled in a completely open state. */
        public void onDrawerOpened(View drawerView) {
            getActionBar().setTitle(R.string.app_name);
            invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
        }
    };

    // Set the drawer toggle as the DrawerListener
    mDrawerLayout.setDrawerListener(mDrawerToggle);

    // Construct list of slide-in menu
    List<SlideInMenuAdapter.SlideInMenuItem> menuItems = new ArrayList<SlideInMenuAdapter.SlideInMenuItem>();
    menuItems.add(new SlideInMenuAdapter.SlideInMenuItem(getApplicationContext(), ManageProjectsActivity.class,
            R.string.home_btn_projects, R.drawable.ic_collections_collection_dark, R.id.menuItemProjects));
    menuItems.add(new SlideInMenuAdapter.SlideInMenuItem(getApplicationContext(), AccountLoginActivity.class,
            R.string.home_ab_menu_account, R.drawable.ic_social_person_dark, R.id.menuItemAccount));
    menuItems.add(new SlideInMenuAdapter.SlideInMenuItem(getApplicationContext(),
            ReportingCriteriaActivity.class, R.string.home_btn_reporting,
            R.drawable.ic_collections_view_as_list_dark, R.id.menuItemReporting));
    menuItems.add(new SlideInMenuAdapter.SlideInMenuItem(getApplicationContext(), TriggersActivity.class,
            R.string.home_btn_triggers, R.drawable.ic_device_access_network_wifi, R.id.menuItemTriggers));
    menuItems.add(new SlideInMenuAdapter.SlideInMenuItem(getApplicationContext(), PreferencesActivity.class,
            R.string.home_btn_preferences, R.drawable.ic_action_settings_dark, R.id.menuItemPreferences));
    menuItems.add(new SlideInMenuAdapter.SlideInMenuItem(getApplicationContext(), AboutActivity.class,
            R.string.home_ab_menu_about, R.drawable.ic_action_about_dark, R.id.menuItemAbout));
    SlideInMenuAdapter menuAdapter = new SlideInMenuAdapter(TimeRegistrationListActivity.this, menuItems);
    mDrawerList.setAdapter(menuAdapter);
    mDrawerList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            SlideInMenuAdapter.SlideInMenuItem menuItem = (SlideInMenuAdapter.SlideInMenuItem) parent
                    .getItemAtPosition(position);
            if (menuItem.getRequestCode() == -1) {
                startActivity(menuItem.getIntent());
            } else {
                startActivityForResult(menuItem.getIntent(), menuItem.getRequestCode());
            }
            mDrawerLayout.closeDrawer(mDrawerList);
        }
    });

    tracker = AnalyticsTracker.getInstance(getApplicationContext());
    tracker.trackPageView(TrackerConstants.PageView.TIME_REGISTRATIONS_ACTIVITY);

    loadExtraTimeRegistration = new TimeRegistration();
    loadExtraTimeRegistration.setId(-1);

    loadTimeRegistrations(true, true);

    getListView().setOnItemClickListener(new ListView.OnItemClickListener() {
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            Log.d(getApplicationContext(), LOG_TAG, "Clicked on TR-item " + position);
            TimeRegistration selectedRegistration = timeRegistrations.get(position);

            if (selectedRegistration.getId() == loadExtraTimeRegistration.getId()) {
                loadExtraTimeRegistrations(view.findViewById(R.id.progress_timeregistration_load_more));
                return;
            }

            TimeRegistration previousTimeRegistration = null;
            if (getTimeRegistrationsSize() > position + 1) {
                previousTimeRegistration = timeRegistrations.get(position + 1);
            }

            TimeRegistration nextTimeRegistration = null;
            if (position > 0) {
                nextTimeRegistration = timeRegistrations.get(position - 1);
            }

            Intent intent = new Intent(TimeRegistrationListActivity.this, TimeRegistrationDetailActivity.class);
            intent.putExtra(Constants.Extras.TIME_REGISTRATION, selectedRegistration);
            intent.putExtra(Constants.Extras.TIME_REGISTRATION_PREVIOUS, previousTimeRegistration);
            intent.putExtra(Constants.Extras.TIME_REGISTRATION_NEXT, nextTimeRegistration);
            startActivityForResult(intent, Constants.IntentRequestCodes.REGISTRATION_DETAILS);
        }
    });

    registerForContextMenu(getListView());

    showShowcase();
}