Example usage for android.view View setOnLongClickListener

List of usage examples for android.view View setOnLongClickListener

Introduction

In this page you can find the example usage for android.view View setOnLongClickListener.

Prototype

public void setOnLongClickListener(@Nullable OnLongClickListener l) 

Source Link

Document

Register a callback to be invoked when this view is clicked and held.

Usage

From source file:de.ub0r.android.websms.WebSMS.java

/**
 * {@inheritDoc}//w w w  .j  av a2  s  .  c o  m
 */
@SuppressWarnings({ "unchecked", "deprecation" })
@Override
public final void onCreate(final Bundle savedInstanceState) {
    this.requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
    this.setTheme(PreferencesActivity.getTheme(this));
    super.onCreate(savedInstanceState);
    Log.d(TAG, "onCreate(" + savedInstanceState + ")");
    this.threadHandler = new Handler();

    // Restore preferences
    de.ub0r.android.lib.Utils.setLocale(this);

    this.cbmgr = (ClipboardManager) this.getSystemService(CLIPBOARD_SERVICE);

    // save ref to me.
    me = this;
    final SharedPreferences p = PreferenceManager.getDefaultSharedPreferences(this);

    // inflate XML
    this.setContentView(R.layout.main);
    this.getSupportActionBar().setHomeButtonEnabled(true);

    // indeterminate progress bar is spinning by default so stop it,
    // updateProgressBar will start it again if necessary
    this.setSupportProgressBarIndeterminateVisibility(false);

    this.etTo = (MultiAutoCompleteTextView) this.findViewById(R.id.to);
    this.etText = (EditText) this.findViewById(R.id.text);
    this.etTextLabel = (TextView) this.findViewById(R.id.text_);
    this.tvPaste = (TextView) this.findViewById(R.id.text_paste);
    this.tvClear = (TextView) this.findViewById(R.id.text_clear);

    this.vCustomSender = (ToggleButton) this.findViewById(R.id.custom_sender);
    this.vFlashSMS = (ToggleButton) this.findViewById(R.id.flashsms);
    this.vSendLater = (ToggleButton) this.findViewById(R.id.send_later);

    if (isNewVersion()) {
        Log.i(TAG, "detected version update");
        SharedPreferences.Editor editor = p.edit();
        editor.remove(PREFS_CONNECTORS); // remove cache
        editor.apply();
        rules.upgrade();
    }

    // get cached Connectors
    String s = p.getString(PREFS_CONNECTORS, null);
    if (TextUtils.isEmpty(s)) {
        this.updateConnectors();

    } else if (CONNECTORS.size() == 0) {
        // skip static remaining connectors
        try {
            ArrayList<ConnectorSpec> cache;
            cache = (ArrayList<ConnectorSpec>) (new ObjectInputStream(new BufferedInputStream(
                    new ByteArrayInputStream(Base64.decode(s, Base64.DEFAULT)), BUFSIZE))).readObject();
            CONNECTORS.addAll(cache);
            if (p.getBoolean(PREFS_AUTOUPDATE, true)) {
                updateFreecount();
            }
        } catch (Exception e) {
            Log.d(TAG, "error loading connectors", e);
        }
    }
    Log.d(TAG, "loaded connectors: " + CONNECTORS.size());

    if (PSEUDO_CONNECTORS.size() == 0) {
        PSEUDO_CONNECTORS.add(rules.getSpec(this));
    }

    if (savedInstanceState == null) {
        this.revertPrefsToStdConnector();
        // note: do not revert to std connector on orientation change
    }

    this.reloadPrefs();

    if (savedInstanceState != null) {
        this.lastTo = savedInstanceState.getString(EXTRA_TO);
        this.lastMsg = savedInstanceState.getString(EXTRA_TEXT);
    }

    // register Listener
    this.vCustomSender.setOnClickListener(this);
    this.vSendLater.setOnClickListener(this);
    this.findViewById(R.id.select).setOnClickListener(this);
    View v = this.findViewById(R.id.clear);
    v.setOnClickListener(this);
    v.setOnLongClickListener(this);
    this.findViewById(R.id.emo).setOnClickListener(this);
    this.tvPaste.setOnClickListener(this);
    this.tvClear.setOnClickListener(this);
    this.etText.addTextChangedListener(this.twCount);
    this.etText.addTextChangedListener(this.twButtons);
    this.etTo.addTextChangedListener(this.twButtons);
    this.etTo.setAdapter(new MobilePhoneAdapter(this));
    this.etTo.setTokenizer(new MultiAutoCompleteTextView.CommaTokenizer());
    this.etTo.requestFocus();

    this.parseIntent(this.getIntent());

    boolean checkPrefix = true;
    boolean showIntro = false;
    if (TextUtils.isEmpty(p.getString(PREFS_SENDER, null))
            && TextUtils.isEmpty(p.getString(PREFS_DEFPREFIX, null)) && CONNECTORS.size() == 0) {
        checkPrefix = false;
        showIntro = true;
    }

    requestPermission(Manifest.permission.READ_CONTACTS, PERMISSIONS_REQUEST_READ_CONTACTS,
            R.string.permissions_read_contacts, null);
    if (TextUtils.isEmpty(p.getString(PREFS_SENDER, null))
            || TextUtils.isEmpty(p.getString(PREFS_DEFPREFIX, null))) {
        fetchSenderAndPrefixFromPhoneNumber();
    }

    // check default prefix
    if (checkPrefix && !p.getString(PREFS_DEFPREFIX, "").startsWith("+")) {
        this.log(R.string.log_wrong_defprefix);
    }

    if (showIntro) {
        // skip help intro for at least 2min
        if (System.currentTimeMillis() > p.getLong(PREFS_LASTHELP, 0L)
                + de.ub0r.android.lib.Utils.MINUTES_IN_MILLIS * 2) {
            p.edit().putLong(PREFS_LASTHELP, System.currentTimeMillis()).apply();
            this.startActivity(new Intent(this, HelpIntroActivity.class));
        }
    }

}

From source file:org.codeforafrica.citizenreporter.eNCA.widgets.SlidingTabLayout.java

private void populateTabStrip() {
    final PagerAdapter adapter = mViewPager.getAdapter();
    final View.OnClickListener tabClickListener = new TabClickListener();
    boolean showIcons = (mIcons != null && mIcons.length == adapter.getCount() && mTabViewIconViewId != 0);

    for (int i = 0; i < adapter.getCount(); i++) {
        View tabView = null;
        //if (showIcons) {
        tabView = LayoutInflater.from(getContext()).inflate(mTabViewLayoutId, mTabStrip, false);
        ImageView imgIcon = (ImageView) tabView.findViewById(mTabViewIconViewId);
        imgIcon.setImageDrawable(getContext().getResources().getDrawable(mIcons[i]));
        TextView tabTitleView = (TextView) tabView.findViewById(mTabViewTextViewId);
        tabTitleView.setText(getContext().getResources().getString(mTitles[i]));

        // tag the badge for this tab so it can be found by setBadge()
        //if (mTabBadgeViewId != 0) {
        //    View badgeView = tabView.findViewById(mTabBadgeViewId);
        //    if (badgeView != null) {
        //        badgeView.setTag(makeBadgeTag(i));
        //    }//ww  w  .  j  ava  2  s .c  o  m
        // }
        //}
        /*else {
        TextView tabTitleView = null;
                
        if (mTabViewLayoutId != 0) {
            tabView = LayoutInflater.from(getContext()).inflate(mTabViewLayoutId, mTabStrip, false);
            tabTitleView = (TextView) tabView.findViewById(mTabViewTextViewId);
        } else {
            tabView = createDefaultTabView(getContext());
            tabTitleView = (TextView) tabView;
        }
                
        if (tabTitleView != null) {
            if(mTitles!=null) {
                tabTitleView.setText(getContext().getResources().getString(mTitles[i]));
            }
        }
        }*/

        if (mDistributeEvenly) {
            LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) tabView.getLayoutParams();
            lp.width = 0;
            lp.weight = 1;
        }

        tabView.setOnClickListener(tabClickListener);
        final String desc = mContentDescriptions.get(i, null);
        if (desc != null) {
            tabView.setContentDescription(desc);
            // show toast with content description on long click
            tabView.setOnLongClickListener(new OnLongClickListener() {
                @Override
                public boolean onLongClick(View v) {
                    int offsetX = v.getLeft();
                    int offsetY = v.getTop() + v.getHeight() + (v.getHeight() / 2);
                    Toast toast = Toast.makeText(v.getContext(), desc, Toast.LENGTH_SHORT);
                    toast.setGravity(Gravity.LEFT | Gravity.TOP, offsetX, offsetY);
                    toast.show();
                    return true;
                }
            });
        }

        mTabStrip.addView(tabView);
        if (i == mViewPager.getCurrentItem()) {
            tabView.setSelected(true);
        }
    }
}

From source file:cgeo.geocaching.CacheDetailActivity.java

@Override
public void addContextMenu(final View view) {
    view.setOnLongClickListener(new OnLongClickListener() {

        @Override/*from  www .  j a  v  a 2  s .c  o m*/
        public boolean onLongClick(final View v) {
            if (view.getId() == R.id.description || view.getId() == R.id.hint) {
                selectedTextView = (IndexOutOfBoundsAvoidingTextView) view;
                mSelectionModeActive = true;
                return false;
            }
            currentActionMode = startSupportActionMode(new ActionMode.Callback() {

                @Override
                public boolean onPrepareActionMode(final ActionMode actionMode, final Menu menu) {
                    return prepareClipboardActionMode(view, actionMode, menu);
                }

                private boolean prepareClipboardActionMode(final View view, final ActionMode actionMode,
                        final Menu menu) {
                    switch (view.getId()) {
                    case R.id.value: // coordinates, gc-code, name
                        clickedItemText = ((TextView) view).getText();
                        final CharSequence itemTitle = ((TextView) ((View) view.getParent())
                                .findViewById(R.id.name)).getText();
                        if (itemTitle.equals(res.getText(R.string.cache_coordinates))) {
                            clickedItemText = GeopointFormatter.reformatForClipboard(clickedItemText);
                        }
                        buildDetailsContextMenu(actionMode, menu, itemTitle, true);
                        return true;
                    case R.id.description:
                        // combine short and long description
                        final String shortDesc = cache.getShortDescription();
                        if (StringUtils.isBlank(shortDesc)) {
                            clickedItemText = cache.getDescription();
                        } else {
                            clickedItemText = shortDesc + "\n\n" + cache.getDescription();
                        }
                        buildDetailsContextMenu(actionMode, menu, res.getString(R.string.cache_description),
                                false);
                        return true;
                    case R.id.personalnote:
                        clickedItemText = cache.getPersonalNote();
                        buildDetailsContextMenu(actionMode, menu, res.getString(R.string.cache_personal_note),
                                true);
                        return true;
                    case R.id.hint:
                        clickedItemText = cache.getHint();
                        buildDetailsContextMenu(actionMode, menu, res.getString(R.string.cache_hint), false);
                        return true;
                    case R.id.log:
                        clickedItemText = ((TextView) view).getText();
                        buildDetailsContextMenu(actionMode, menu, res.getString(R.string.cache_logs), false);
                        return true;
                    case R.id.date: // event date
                        clickedItemText = Formatter.formatHiddenDate(cache);
                        buildDetailsContextMenu(actionMode, menu, res.getString(R.string.cache_event), true);
                        menu.findItem(R.id.menu_calendar).setVisible(cache.canBeAddedToCalendar());
                        return true;
                    }
                    return false;
                }

                @Override
                public void onDestroyActionMode(final ActionMode actionMode) {
                    currentActionMode = null;
                }

                @Override
                public boolean onCreateActionMode(final ActionMode actionMode, final Menu menu) {
                    actionMode.getMenuInflater().inflate(R.menu.details_context, menu);
                    prepareClipboardActionMode(view, actionMode, menu);
                    // Return true so that the action mode is shown
                    return true;
                }

                @Override
                public boolean onActionItemClicked(final ActionMode actionMode, final MenuItem menuItem) {
                    switch (menuItem.getItemId()) {
                    // detail fields
                    case R.id.menu_calendar:
                        CalendarAdder.addToCalendar(CacheDetailActivity.this, cache);
                        actionMode.finish();
                        return true;
                    // handle clipboard actions in base
                    default:
                        return onClipboardItemSelected(actionMode, menuItem, clickedItemText, cache);
                    }
                }
            });
            return true;
        }
    });
}

From source file:com.launcher.silverfish.launcher.homescreen.HomeScreenFragment.java

@SuppressWarnings("deprecation")
private void updateShortcuts() {
    int count = appsList.size();
    int size = (int) Math.ceil(Math.sqrt(count));
    shortcutLayout.removeAllViews();/*  w  w  w .java 2s.co m*/

    if (size == 0) {
        size = 1;
    }

    // Redraw the layout
    shortcutLayout.setSize(size);
    shortcutLayout.requestLayout();
    shortcutLayout.invalidate();

    for (int i = 0; i < appsList.size(); i++) {
        final AppDetail app = appsList.get(i);
        View convertView = getActivity().getLayoutInflater().inflate(R.layout.shortcut_item, null);

        // load the app icon in an async task
        ImageView im = (ImageView) convertView.findViewById(R.id.item_app_icon);
        Utils.loadAppIconAsync(mPacMan, app.packageName.toString(), im);

        TextView tv = (TextView) convertView.findViewById(R.id.item_app_label);
        tv.setText(app.label);
        shortcutLayout.addView(convertView);

        convertView.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View view, MotionEvent event) {
                switch (MotionEventCompat.getActionMasked(event)) {
                case MotionEvent.ACTION_DOWN:
                    updateTouchDown(event);
                    break;

                case MotionEvent.ACTION_MOVE:
                    tryConsumeSwipe(event);
                    break;

                case MotionEvent.ACTION_UP:
                    // We only want to launch the activity if the touch was not consumed yet!
                    if (!touchConsumed) {
                        Intent i = mPacMan.getLaunchIntentForPackage(app.packageName.toString());
                        if (i != null) {
                            // Sanity check (application may have been uninstalled)
                            // TODO Remove it from the database
                            startActivity(i);
                        } else {
                            Toast.makeText(getContext(), R.string.application_not_installed, Toast.LENGTH_SHORT)
                                    .show();
                        }
                    }
                    break;
                }

                return touchConsumed;
            }
        });

        // start a drag when an app has been long clicked
        final long appId = app.id;
        final int appIndex = i;
        convertView.setOnLongClickListener(new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View view) {
                String[] mime_types = { ClipDescription.MIMETYPE_TEXT_PLAIN };
                ClipData data = new ClipData(Constants.DRAG_SHORTCUT_REMOVAL, mime_types,
                        new ClipData.Item(Long.toString(appId)));

                data.addItem(new ClipData.Item(Integer.toString(appIndex)));

                View.DragShadowBuilder shadowBuilder = new View.DragShadowBuilder(
                        view.findViewById(R.id.item_app_icon));

                // "This method was deprecated in API level 24. Use startDragAndDrop()
                // for newer platform versions."
                if (Build.VERSION.SDK_INT < 24) {
                    view.startDrag(data, shadowBuilder, view, 0);
                } else {
                    view.startDragAndDrop(data, shadowBuilder, view, 0);
                }

                // Show removal indicator
                FrameLayout rem_ind = (FrameLayout) rootView.findViewById(R.id.remove_indicator);
                rem_ind.setVisibility(View.VISIBLE);
                AlphaAnimation animation = new AlphaAnimation(0.0f, 1.0f);
                animation.setDuration(500);
                rem_ind.startAnimation(animation);
                return true;

            }
        });
    }
}

From source file:im.neon.adapters.VectorMessagesAdapter.java

/**
 * Manage the select mode i.e highlight an item when the user tap on it
 * @param contentView the cell view.//from ww  w  .j av a 2s. c  o  m
 * @param event the linked event
 */
private void manageSelectionMode(final View contentView, final Event event) {
    final String eventId = event.eventId;

    boolean isInSelectionMode = (null != mHighlightedEventId);
    boolean isHighlighted = TextUtils.equals(eventId, mHighlightedEventId);

    // display the action icon when selected
    contentView.findViewById(R.id.messagesAdapter_action_image)
            .setVisibility(isHighlighted ? View.VISIBLE : View.GONE);

    float alpha = (!isInSelectionMode || isHighlighted) ? 1.0f : 0.2f;

    // the message body is dimmed when not selected
    contentView.findViewById(R.id.messagesAdapter_body_view).setAlpha(alpha);
    contentView.findViewById(R.id.messagesAdapter_avatars_list).setAlpha(alpha);

    TextView tsTextView = (TextView) contentView
            .findViewById(org.matrix.androidsdk.R.id.messagesAdapter_timestamp);
    if (isInSelectionMode && isHighlighted) {
        tsTextView.setVisibility(View.VISIBLE);
    }

    contentView.findViewById(org.matrix.androidsdk.R.id.message_timestamp_layout_right)
            .setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (TextUtils.equals(eventId, mHighlightedEventId)) {
                        onMessageClick(event, getEventText(contentView),
                                contentView.findViewById(R.id.messagesAdapter_action_anchor));
                    } else {
                        onEventTap(eventId);
                    }
                }
            });

    contentView.setOnLongClickListener(new View.OnLongClickListener() {
        @Override
        public boolean onLongClick(View v) {
            if (!mIsSearchMode) {
                onMessageClick(event, getEventText(contentView),
                        contentView.findViewById(R.id.messagesAdapter_action_anchor));
                mHighlightedEventId = eventId;
                notifyDataSetChanged();
                return true;
            }

            return false;
        }
    });
}

From source file:com.example.ray.firstapp.bottombar.BottomBar.java

private void updateItems(final BottomBarItemBase[] bottomBarItems) {
    if (mItemContainer == null) {
        initializeViews();//from w  w w. java 2 s.  com
    }

    int index = 0;
    int biggestWidth = 0;

    mIsShiftingMode = MAX_FIXED_TAB_COUNT < bottomBarItems.length;

    if (!mIsDarkTheme && !mIgnoreNightMode && MiscUtils.isNightMode(mContext)) {
        mIsDarkTheme = true;
    }

    if (!mIsTabletMode && mIsShiftingMode) {
        mDefaultBackgroundColor = mCurrentBackgroundColor = mPrimaryColor;
        mBackgroundView.setBackgroundColor(mDefaultBackgroundColor);

        if (mContext instanceof Activity) {
            navBarMagic((Activity) mContext, this);
        }
    } else if (mIsDarkTheme) {
        darkThemeMagic();
    }

    View[] viewsToAdd = new View[bottomBarItems.length];

    for (BottomBarItemBase bottomBarItemBase : bottomBarItems) {
        int layoutResource;

        if (mIsShiftingMode && !mIsTabletMode) {
            layoutResource = R.layout.bb_bottom_bar_item_shifting;
        } else {
            layoutResource = mIsTabletMode ? R.layout.bb_bottom_bar_item_fixed_tablet
                    : R.layout.bb_bottom_bar_item_fixed;
        }

        View bottomBarTab = View.inflate(mContext, layoutResource, null);
        ImageView icon = (ImageView) bottomBarTab.findViewById(R.id.bb_bottom_bar_icon);

        icon.setImageDrawable(bottomBarItemBase.getIcon(mContext));

        if (!mIsTabletMode) {
            TextView title = (TextView) bottomBarTab.findViewById(R.id.bb_bottom_bar_title);
            title.setText(bottomBarItemBase.getTitle(mContext));

            if (mPendingTextAppearance != -1) {
                MiscUtils.setTextAppearance(title, mPendingTextAppearance);
            }

            if (mPendingTypeface != null) {
                title.setTypeface(mPendingTypeface);
            }
        }

        if (mIsDarkTheme || (!mIsTabletMode && mIsShiftingMode)) {
            icon.setColorFilter(mWhiteColor);
        }

        if (bottomBarItemBase instanceof BottomBarTab) {
            bottomBarTab.setId(((BottomBarTab) bottomBarItemBase).id);
        }

        if (index == mCurrentTabPosition) {
            selectTab(bottomBarTab, false);
        } else {
            unselectTab(bottomBarTab, false);
        }

        if (!mIsTabletMode) {
            if (bottomBarTab.getWidth() > biggestWidth) {
                biggestWidth = bottomBarTab.getWidth();
            }

            viewsToAdd[index] = bottomBarTab;
        } else {
            mItemContainer.addView(bottomBarTab);
        }

        bottomBarTab.setOnClickListener(this);
        bottomBarTab.setOnLongClickListener(this);
        index++;
    }

    if (!mIsTabletMode) {
        int proposedItemWidth = Math.min(MiscUtils.dpToPixel(mContext, mScreenWidth / bottomBarItems.length),
                mMaxFixedItemWidth);

        LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(proposedItemWidth,
                LinearLayout.LayoutParams.WRAP_CONTENT);

        for (View bottomBarView : viewsToAdd) {
            bottomBarView.setLayoutParams(params);
            mItemContainer.addView(bottomBarView);
        }
    }

    if (mPendingTextAppearance != -1) {
        mPendingTextAppearance = -1;
    }

    if (mPendingTypeface != null) {
        mPendingTypeface = null;
    }
}

From source file:com.harlan.jxust.ui.view.bottombar.BottomBar.java

private void updateItems(final BottomBarItemBase[] bottomBarItems) {
    if (mItemContainer == null) {
        initializeViews();// ww w  .ja  v a2s  .c  om
    }

    int index = 0;
    int biggestWidth = 0;

    mIsShiftingMode = MAX_FIXED_TAB_COUNT < bottomBarItems.length;

    if (!mIsDarkTheme && !mIgnoreNightMode && MiscUtils.isNightMode(mContext)) {
        mIsDarkTheme = true;
    }

    if (mIsDarkTheme) {
        darkThemeMagic();
    } else if (!mIsTabletMode && mIsShiftingMode) {
        mDefaultBackgroundColor = mCurrentBackgroundColor = mPrimaryColor;
        mBackgroundView.setBackgroundColor(mDefaultBackgroundColor);

        if (mContext instanceof Activity) {
            navBarMagic((Activity) mContext, this);
        }
    }

    View[] viewsToAdd = new View[bottomBarItems.length];

    for (BottomBarItemBase bottomBarItemBase : bottomBarItems) {
        int layoutResource;

        if (mIsShiftingMode && !mIsTabletMode) {
            layoutResource = R.layout.bb_bottom_bar_item_shifting;
        } else {
            layoutResource = mIsTabletMode ? R.layout.bb_bottom_bar_item_fixed_tablet
                    : R.layout.bb_bottom_bar_item_fixed;
        }

        View bottomBarTab = View.inflate(mContext, layoutResource, null);
        ImageView icon = (ImageView) bottomBarTab.findViewById(R.id.bb_bottom_bar_icon);

        icon.setImageDrawable(bottomBarItemBase.getIcon(mContext));

        if (!mIsTabletMode) {
            TextView title = (TextView) bottomBarTab.findViewById(R.id.bb_bottom_bar_title);
            title.setText(bottomBarItemBase.getTitle(mContext));

            if (mPendingTextAppearance != -1) {
                MiscUtils.setTextAppearance(title, mPendingTextAppearance);
            }

            if (mPendingTypeface != null) {
                title.setTypeface(mPendingTypeface);
            }
        }

        if (mIsDarkTheme || (!mIsTabletMode && mIsShiftingMode)) {
            icon.setColorFilter(mWhiteColor);
        }

        if (bottomBarItemBase instanceof BottomBarTab) {
            bottomBarTab.setId(((BottomBarTab) bottomBarItemBase).id);
        }

        if (index == mCurrentTabPosition) {
            selectTab(bottomBarTab, false);
        } else {
            unselectTab(bottomBarTab, false);
        }

        if (!mIsTabletMode) {
            if (bottomBarTab.getWidth() > biggestWidth) {
                biggestWidth = bottomBarTab.getWidth();
            }

            viewsToAdd[index] = bottomBarTab;
        } else {
            mItemContainer.addView(bottomBarTab);
        }

        bottomBarTab.setOnClickListener(this);
        bottomBarTab.setOnLongClickListener(this);
        index++;
    }

    if (!mIsTabletMode) {
        int proposedItemWidth = Math.min(MiscUtils.dpToPixel(mContext, mScreenWidth / bottomBarItems.length),
                mMaxFixedItemWidth);

        mInActiveShiftingItemWidth = (int) (proposedItemWidth * 0.9);
        mActiveShiftingItemWidth = (int) (proposedItemWidth
                + (proposedItemWidth * (bottomBarItems.length * 0.1)));

        for (View bottomBarView : viewsToAdd) {
            LinearLayout.LayoutParams params;

            if (mIsShiftingMode && !mIgnoreShiftingResize) {
                if (TAG_BOTTOM_BAR_VIEW_ACTIVE.equals(bottomBarView.getTag())) {
                    params = new LinearLayout.LayoutParams(mActiveShiftingItemWidth,
                            LinearLayout.LayoutParams.WRAP_CONTENT);
                } else {
                    params = new LinearLayout.LayoutParams(mInActiveShiftingItemWidth,
                            LinearLayout.LayoutParams.WRAP_CONTENT);
                }
            } else {
                params = new LinearLayout.LayoutParams(proposedItemWidth,
                        LinearLayout.LayoutParams.WRAP_CONTENT);
            }

            bottomBarView.setLayoutParams(params);
            mItemContainer.addView(bottomBarView);
        }
    }

    if (mPendingTextAppearance != -1) {
        mPendingTextAppearance = -1;
    }

    if (mPendingTypeface != null) {
        mPendingTypeface = null;
    }
}

From source file:au.com.glassechidna.velocityviewpager.VelocityViewPager.java

private void updateViewOnLongClickListeners() {
    final int childCount = getChildCount();
    for (int i = 0; i < childCount; i++) {
        final View child = getChildAt(i);
        final LayoutParams layoutParams = (LayoutParams) child.getLayoutParams();
        if (!layoutParams.isDecor) {
            if (mOnItemLongClickListener != null) {
                child.setOnLongClickListener(this);
            }/* www  .  j  a  v a  2s  .  c  om*/
        }
    }
}

From source file:com.asksven.betterbatterystats.adapters.StatsAdapter.java

public View getView(int position, View convertView, ViewGroup viewGroup) {
    StatElement entry = m_listData.get(position);

    SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(this.m_context);
    boolean bShowBars = sharedPrefs.getBoolean("show_gauge", false);

    if (LogSettings.DEBUG) {
        Log.i(TAG, "Values: " + entry.getVals());
    }//w  w  w .java 2s.  c  o m

    if (convertView == null) {
        LayoutInflater inflater = (LayoutInflater) m_context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

        // depending on settings show new pie gauge or old bar gauge
        if (!bShowBars) {
            convertView = inflater.inflate(R.layout.stat_row, null);
        } else {
            convertView = inflater.inflate(R.layout.stat_row_gauge, null);
        }
    }

    final float scale = this.m_context.getResources().getDisplayMetrics().density;

    TextView tvName = (TextView) convertView.findViewById(R.id.TextViewName);

    /////////////////////////////////////////
    // we do some stuff here to handle settings about font size and thumbnail size
    String fontSize = sharedPrefs.getString("medium_font_size", "16");
    int mediumFontSize = Integer.parseInt(fontSize);

    //we need to change "since" fontsize
    tvName.setTextSize(TypedValue.COMPLEX_UNIT_SP, mediumFontSize);

    // We need to handle an exception here: Sensors do not have a name so we use the fqn instead
    if (entry instanceof SensorUsage) {
        tvName.setText(entry.getFqn(UidNameResolver.getInstance(m_context)));

    } else {
        tvName.setText(entry.getName());
    }

    boolean bShowKb = sharedPrefs.getBoolean("enable_kb", true);
    ImageView iconKb = (ImageView) convertView.findViewById(R.id.imageKB);

    iconKb.setVisibility(View.INVISIBLE);

    TextView tvFqn = (TextView) convertView.findViewById(R.id.TextViewFqn);
    tvFqn.setText(entry.getFqn(UidNameResolver.getInstance(m_context)));

    TextView tvData = (TextView) convertView.findViewById(R.id.TextViewData);

    // for alarms the values is wakeups per hour so we need to take the time as reference for the text
    if (entry instanceof Alarm) {
        tvData.setText(entry.getData((long) m_timeSince));
    } else {
        tvData.setText(entry.getData((long) m_maxValue));
    }

    //LinearLayout myLayout = (LinearLayout) convertView.findViewById(R.id.LinearLayoutBar);
    LinearLayout myFqnLayout = (LinearLayout) convertView.findViewById(R.id.LinearLayoutFqn);
    LinearLayout myRow = (LinearLayout) convertView.findViewById(R.id.LinearLayoutEntry);

    // long press for "copy to clipboard"
    convertView.setOnLongClickListener(new OnItemLongClickListener(position));

    if (!bShowBars) {
        GraphablePie gauge = (GraphablePie) convertView.findViewById(R.id.Gauge);

        /////////////////////////////////////////
        // we do some stuff here to handle settings about font size and thumbnail size
        String iconDim = sharedPrefs.getString("thumbnail_size", "56");
        int iconSize = Integer.parseInt(iconDim);
        int pixels = (int) (iconSize * scale + 0.5f);
        //we need to change "since" fontsize
        gauge.getLayoutParams().height = pixels;
        gauge.getLayoutParams().width = pixels;
        gauge.requestLayout();

        ////////////////////////////////////////////////////////////////////////////////////
        if (entry instanceof NetworkUsage) {
            gauge.setValue(entry.getValues()[0], ((NetworkUsage) entry).getTotal());

        } else {
            double max = m_maxValue;
            // avoid rounding errors leading to values > 100 %
            if (entry.getValues()[0] > max) {
                max = entry.getValues()[0];
                Log.i(TAG, "Upping gauge max to " + max);
            }
            gauge.setValue(entry.getValues()[0], max);
        }
    } else {
        GraphableBars buttonBar = (GraphableBars) convertView.findViewById(R.id.ButtonBar);
        int iHeight = 10;
        try {
            iHeight = Integer.valueOf(sharedPrefs.getString("graph_bar_height", "10"));
        } catch (Exception e) {
            iHeight = 10;
        }
        if (iHeight == 0) {
            iHeight = 10;
        }

        buttonBar.setMinimumHeight(iHeight);
        buttonBar.setName(entry.getName());
        buttonBar.setValues(entry.getValues(), m_maxValue);
    }
    ImageView iconView = (ImageView) convertView.findViewById(R.id.icon);
    LinearLayout iconLayout = (LinearLayout) convertView.findViewById(R.id.LayoutIcon);
    /////////////////////////////////////////
    // we do some stuff here to handle settings about font size and thumbnail size
    String iconDim = sharedPrefs.getString("thumbnail_size", "56");
    int iconSize = Integer.parseInt(iconDim);
    int pixels = (int) (iconSize * scale + 0.5f);
    //we need to change "since" fontsize
    iconView.getLayoutParams().width = pixels;
    iconView.getLayoutParams().height = pixels;
    iconView.requestLayout();
    //n 20;setLay.setTextSize(TypedValue.COMPLEX_UNIT_DIP, iconSize);

    ////////////////////////////////////////////////////////////////////////////////////

    // add on click listener for the icon only if KB is enabled
    //        if (bShowKb)
    //        {
    //           // set a click listener for the list
    //           iconKb.setOnClickListener(new OnIconClickListener(position));
    //        }

    // show / hide fqn text
    if ((entry instanceof Process) || (entry instanceof State) || (entry instanceof Misc)
            || (entry instanceof NativeKernelWakelock) || (entry instanceof Alarm)
            || (entry instanceof SensorUsage)) {
        myFqnLayout.setVisibility(View.GONE);
    } else {
        myFqnLayout.setVisibility(View.VISIBLE);
    }

    // show / hide package icons (we show / hide the whole layout as it contains a margin that must be hidded as well
    if ((entry instanceof NativeKernelWakelock) || (entry instanceof State) || (entry instanceof Misc)) {

        iconView.setVisibility(View.GONE);

    } else {
        iconView.setVisibility(View.VISIBLE);
        iconView.setImageDrawable(entry.getIcon(UidNameResolver.getInstance(m_context)));
        // set a click listener for the list
        iconView.setOnClickListener(new OnPackageClickListener(position));

    }

    // add on click listener for the list entry if details are availble
    if ((entry instanceof Alarm) || (entry instanceof NativeKernelWakelock) || (entry instanceof SensorUsage)) {
        convertView.setOnClickListener(new OnItemClickListener(position));
    }

    //        // show / hide set dividers
    //        ListView myList = (ListView) convertView.getListView(); //findViewById(R.id.id.list);
    //        myList.setDivider(new ColorDrawable(0x99F10529));
    //        myList.setDividerHeight(1);
    return convertView;
}

From source file:es.usc.citius.servando.calendula.fragments.MedicinesListFragment.java

private View createMedicineListItem(LayoutInflater inflater, final Medicine medicine) {

    View item = inflater.inflate(R.layout.medicines_list_item, null);

    ((TextView) item.findViewById(R.id.medicines_list_item_name)).setText(medicine.name());

    ImageView icon = (ImageView) item.findViewById(R.id.imageButton);
    icon.setImageDrawable(new IconicsDrawable(getContext()).icon(medicine.presentation().icon())
            //.color(Color.WHITE)
            .colorRes(R.color.agenda_item_title).paddingDp(8).sizeDp(40));

    View overlay = item.findViewById(R.id.medicines_list_item_container);
    overlay.setTag(medicine);/*from   www. ja v a2 s .  c  om*/

    String nextPickup = medicine.nextPickup();
    if (nextPickup != null) {
        TextView stockInfo = (TextView) item.findViewById(R.id.stock_info);
        stockInfo.setText("Prxima e-Receta: " + nextPickup);
    }

    String cn = medicine.cn();
    final Prescription p = cn != null ? Prescription.findByCn(medicine.cn()) : null;
    boolean boundToPrescription = p != null;
    boolean hasProspect = (p != null && p.hasProspect);

    if (!boundToPrescription) {
        item.findViewById(R.id.imageView).setVisibility(View.GONE);
    } else {
        IconicsDrawable ic = new IconicsDrawable(getContext()).icon(CommunityMaterial.Icon.cmd_file_document)
                .colorRes(R.color.agenda_item_title).paddingDp(10).sizeDp(40);
        ((ImageView) item.findViewById(R.id.imageView)).setImageDrawable(ic);

        if (hasProspect) {
            item.findViewById(R.id.imageView).setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    onClickProspect(medicine, p);
                }
            });
        } else {
            item.findViewById(R.id.imageView).setAlpha(0.2f);
            item.findViewById(R.id.imageView).setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Snack.show(R.string.download_prospect_not_available_message, getActivity());
                }
            });
        }
    }

    if (p != null && p.affectsDriving) {
        Drawable icDriv = new IconicsDrawable(getContext()).icon(CommunityMaterial.Icon.cmd_comment_alert)
                .color(Color.parseColor("#f39c12")).paddingDp(10).sizeDp(40);
        ((ImageView) item.findViewById(R.id.drive_icon)).setImageDrawable(icDriv);
        item.findViewById(R.id.drive_icon).setVisibility(View.VISIBLE);
        item.findViewById(R.id.drive_icon).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                showDrivingAdvice(p);
            }
        });
    } else {
        item.findViewById(R.id.drive_icon).setVisibility(View.GONE);
    }

    View.OnClickListener clickListener = new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Medicine m = (Medicine) view.getTag();
            if (mMedicineSelectedCallback != null && m != null) {
                Log.d(getTag(), "Click at " + m.name());
                mMedicineSelectedCallback.onMedicineSelected(m);
            } else {
                Log.d(getTag(), "No callback set");
            }
        }
    };

    overlay.setOnClickListener(clickListener);
    overlay.setOnLongClickListener(new View.OnLongClickListener() {
        @Override
        public boolean onLongClick(View view) {
            if (view.getTag() != null)
                showDeleteConfirmationDialog((Medicine) view.getTag());
            return true;
        }
    });
    return item;
}