List of usage examples for android.view View.OnLongClickListener View.OnLongClickListener
View.OnLongClickListener
From source file:org.jitsi.android.gui.call.VideoCallActivity.java
/** * Initializes speakerphone button./*from w w w .j av a 2 s .c o m*/ */ private void initSpeakerphoneButton() { View speakerphoneButton = findViewById(R.id.speakerphoneButton); speakerphoneButton.setOnLongClickListener(new View.OnLongClickListener() { @Override public boolean onLongClick(View v) { onCallVolumeClicked(v); return true; } }); }
From source file:uk.ac.hutton.ics.buntata.adapter.DatasourceAdapter.java
@Override public void onBindViewHolder(final AbstractViewHolder h, final int section, final int relativePosition, final int absolutePosition) { final BuntataDatasource item; final boolean isExpanded = getAbsolutePosition(absolutePosition, section) == expandedPosition; switch (section) { case LOCAL://w w w . j a v a 2 s.com item = local.get(relativePosition); break; case REMOTE: default: item = remote.get(relativePosition); } final ItemViewHolder holder = (ItemViewHolder) h; holder.nameView.setText(item.getName()); holder.descriptionView.setText(item.getDescription()); holder.sizeView.setText(context.getString(R.string.datasource_size, (item.getSizeNoVideo() / 1024f / 1024f), (item.getSizeTotal() / 1024f / 1024f))); holder.contactView.setText(item.getContact()); holder.contactView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { ShareCompat.IntentBuilder.from(context).setType("message/rfc822").addEmailTo(item.getContact()) .setSubject(context.getString(R.string.contact_email_subject)) .setChooserTitle(R.string.contact_email_dialog_title).startChooser(); } }); holder.providerView.setText(item.getDataProvider()); holder.versionView.setText(Integer.toString(item.getVersionNumber())); final BuntataDatasourceAdvanced ds = get(section, relativePosition); holder.progressBar.setVisibility(ds.isDownloading() ? View.VISIBLE : View.GONE); setState(ds, holder); // holder.downloadStatus.setImageResource(resource); // holder.downloadStatus.setColorFilter(ContextCompat.getColor(context, R.color.colorPrimaryDark)); /* If there is an icon, set it */ String iconPath = DatasourceService.getIcon(context, item); if (!StringUtils.isEmpty(iconPath)) { holder.imageView.setScaleType(ImageView.ScaleType.CENTER_CROP); RequestCreator r; File f = new File(iconPath); if (f.exists()) r = Picasso.get().load(f); else r = Picasso.get().load(iconPath); r.noPlaceholder().into(holder.imageView); } /* Else set a default icon */ else { holder.imageView.setImageResource(R.drawable.drawer_data_source); holder.imageView.setScaleType(ImageView.ScaleType.CENTER_INSIDE); holder.imageView.setColorFilter(ContextCompat.getColor(context, R.color.colorPrimaryDark)); } holder.detailsView.setVisibility(isExpanded ? View.VISIBLE : View.GONE); holder.view.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { expandedPosition = isExpanded ? -1 : getAbsolutePosition(absolutePosition, section); /* Set a new transition */ ChangeBounds transition = new ChangeBounds(); /* For 150 ms */ transition.setDuration(150); /* And start it */ TransitionManager.beginDelayedTransition(parent, transition); /* Let the parent view know that something changed and that it needs to re-layout */ notifyDataSetChanged(); } }); /* Add a long click handler */ holder.view.setOnLongClickListener(new View.OnLongClickListener() { @Override public boolean onLongClick(View v) { /* If it's not installed or if it's currently downloading, do nothing */ if ((ds.getState() == BuntataDatasourceAdvanced.InstallState.NOT_INSTALLED) || ds.isDownloading()) return true; /* Show the option do delete the data source */ DialogUtils.showDialog(context, R.string.dialog_delete_datasource_title, R.string.dialog_delete_datasource_text, R.string.generic_yes, R.string.generic_no, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { /* Reset the currently selected data source, if this was the selected item */ int selected = PreferenceUtils.getPreferenceAsInt(context, PreferenceUtils.PREFS_SELECTED_DATASOURCE_ID, -1); if (selected == ds.getId()) PreferenceUtils.removePreference(context, PreferenceUtils.PREFS_SELECTED_DATASOURCE_ID); /* Remember that this isn't downloaded anymore */ ds.setState(BuntataDatasourceAdvanced.InstallState.NOT_INSTALLED); try { /* Delete associated files */ new DatasourceManager(context, ds.getId()).remove(); } catch (IOException e) { e.printStackTrace(); } int installedDatasources = new DatasourceManager(context, -1).getAll().size(); if (installedDatasources < 1) PreferenceUtils.removePreference(context, PreferenceUtils.PREFS_AT_LEAST_ONE_DATASOURCE); onDatasetChanged(); animate(holder); GoogleAnalyticsUtils.trackEvent(context, BaseActivity.getTracker(context, BaseActivity.TrackerName.APP_TRACKER), context.getString(R.string.ga_event_category_datasource_deleted), "Datasource: " + ds.getId()); } }, null); return true; } }); /* Add a click handler */ holder.downloadStatus.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (ds.isDownloading()) { DialogUtils.showDialog(context, R.string.dialog_download_cancel_title, R.string.dialog_download_cancel_text, R.string.generic_yes, R.string.generic_no, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { if (downloadTask != null) { downloadTask.cancel(true); holder.progressBar.setVisibility(View.GONE); ds.setDownloading(false); downloadTask = null; setState(ds, holder); } } }, null); return; } else { for (BuntataDatasourceAdvanced dss : dataset) { if (dss.isDownloading()) { SnackbarUtils.show(v, R.string.snackbar_only_one_download, ContextCompat.getColor(context, android.R.color.primary_text_dark), ContextCompat.getColor(context, R.color.colorPrimaryDark), Snackbar.LENGTH_LONG); return; } } } switch (ds.getState()) { case INSTALLED_NO_UPDATE: /* Just remember the selected id and close the activity to return to wherever we came from */ PreferenceUtils.setPreferenceAsInt(context, PreferenceUtils.PREFS_SELECTED_DATASOURCE_ID, ds.getId()); context.setResult(Activity.RESULT_OK); context.finish(); return; case INSTALLED_HAS_UPDATE: case NOT_INSTALLED: DialogUtils.showDialog(context, R.string.dialog_download_title, R.string.dialog_download_message, R.string.generic_yes, R.string.generic_no, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { initDownload(true, holder, ds); } }, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { initDownload(false, holder, ds); } }); break; } } }); }
From source file:org.sufficientlysecure.donations.DonationsFragment.java
@Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); /* Flattr *///w ww .j av a 2 s . com if (mFlattrEnabled) { // inflate flattr view into stub ViewStub flattrViewStub = (ViewStub) getActivity().findViewById(R.id.donations__flattr_stub); flattrViewStub.inflate(); buildFlattrView(); } /* Google */ if (mGoogleEnabled) { // inflate google view into stub ViewStub googleViewStub = (ViewStub) getActivity().findViewById(R.id.donations__google_stub); googleViewStub.inflate(); // choose donation amount mGoogleSpinner = (Spinner) getActivity().findViewById(R.id.donations__google_android_market_spinner); ArrayAdapter<CharSequence> adapter; if (mDebug) { adapter = new ArrayAdapter<CharSequence>(getActivity(), android.R.layout.simple_spinner_item, CATALOG_DEBUG); } else { adapter = new ArrayAdapter<CharSequence>(getActivity(), android.R.layout.simple_spinner_item, mGoogleCatalogValues); } adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); mGoogleSpinner.setAdapter(adapter); Button btGoogle = (Button) getActivity() .findViewById(R.id.donations__google_android_market_donate_button); btGoogle.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { donateGoogleOnClick(v); } }); // Create the helper, passing it our context and the public key to verify signatures with if (mDebug) Log.d(TAG, "Creating IAB helper."); mHelper = new IabHelper(getActivity(), mGooglePubkey); // enable debug logging (for a production application, you should set this to false). mHelper.enableDebugLogging(mDebug); // Start setup. This is asynchronous and the specified listener // will be called once setup completes. if (mDebug) Log.d(TAG, "Starting setup."); mHelper.startSetup(new IabHelper.OnIabSetupFinishedListener() { public void onIabSetupFinished(IabResult result) { if (mDebug) Log.d(TAG, "Setup finished."); if (!result.isSuccess()) { // Oh noes, there was a problem. openDialog(android.R.drawable.ic_dialog_alert, R.string.donations__google_android_market_not_supported_title, getString(R.string.donations__google_android_market_not_supported)); return; } // Have we been disposed of in the meantime? If so, quit. if (mHelper == null) return; } }); } /* PayPal */ if (mPaypalEnabled) { // inflate paypal view into stub ViewStub paypalViewStub = (ViewStub) getActivity().findViewById(R.id.donations__paypal_stub); paypalViewStub.inflate(); Button btPayPal = (Button) getActivity().findViewById(R.id.donations__paypal_donate_button); btPayPal.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { donatePayPalOnClick(v); } }); } /* Bitcoin */ if (mBitcoinEnabled) { // inflate bitcoin view into stub ViewStub bitcoinViewStub = (ViewStub) getActivity().findViewById(R.id.donations__bitcoin_stub); bitcoinViewStub.inflate(); Button btBitcoin = (Button) getActivity().findViewById(R.id.donations__bitcoin_button); btBitcoin.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { donateBitcoinOnClick(v); } }); btBitcoin.setOnLongClickListener(new View.OnLongClickListener() { @Override public boolean onLongClick(View v) { Toast.makeText(getActivity(), R.string.donations__bitcoin_toast_copy, Toast.LENGTH_SHORT) .show(); // http://stackoverflow.com/a/11012443/832776 if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.HONEYCOMB) { android.text.ClipboardManager clipboard = (android.text.ClipboardManager) getActivity() .getSystemService(getActivity().CLIPBOARD_SERVICE); clipboard.setText(mBitcoinAddress); } else { android.content.ClipboardManager clipboard = (android.content.ClipboardManager) getActivity() .getSystemService(getActivity().CLIPBOARD_SERVICE); android.content.ClipData clip = android.content.ClipData.newPlainText(mBitcoinAddress, mBitcoinAddress); clipboard.setPrimaryClip(clip); } return true; } }); } }
From source file:com.javielinux.tweettopics2.TweetTopicsActivity.java
public void refreshActionBarColumns() { int currentPosition = pager.getCurrentItem(); layoutBackgroundColumnsBar.removeAllViews(); int padding = (int) getResources().getDimension(R.dimen.default_padding); //int sizeButton = (int) getResources().getDimension(R.dimen.actionbar_columns_height); for (int i = 1; i < fragmentAdapter.getFragmentList().size(); i++) { ImageView view = new ImageView(this); view.setPadding(padding, padding, padding, padding); view.setImageBitmap(ColumnsUtils.getButtonWithTitle(this, fragmentAdapter.getFragmentList().get(i), true, currentPosition == i ? Color.GREEN : Color.BLACK)); view.setTag(i);/*from www . j ava 2 s . c o m*/ view.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { if (layoutMainOptionsColumns.getVisibility() != View.VISIBLE) { showActionBarIndicatorAndMovePager((Integer) view.getTag()); } } }); view.setOnLongClickListener(new View.OnLongClickListener() { @Override public boolean onLongClick(View view) { int pos = (Integer) view.getTag(); int[] loc = new int[2]; view.getLocationOnScreen(loc); showOptionsColumns(loc[0], pos, true); return false; } }); layoutBackgroundColumnsBar.addView(view); } }