Search in sources :

Example 16 with OnTouchListener

use of android.view.View.OnTouchListener in project Android-ParallaxHeaderViewPager by kmshack.

the class SampleListFragment method onActivityCreated.

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    mListView.setOnScrollListener(new OnScroll());
    mListView.setAdapter(new ArrayAdapter<String>(getActivity(), R.layout.list_item, android.R.id.text1, mListItems));
    if (MainActivity.NEEDS_PROXY) {
        //in my moto phone(android 2.1),setOnScrollListener do not work well
        mListView.setOnTouchListener(new OnTouchListener() {

            @Override
            public boolean onTouch(View v, MotionEvent event) {
                if (mScrollTabHolder != null)
                    mScrollTabHolder.onScroll(mListView, 0, 0, 0, mPosition);
                return false;
            }
        });
    }
}
Also used : OnTouchListener(android.view.View.OnTouchListener) View(android.view.View) AbsListView(android.widget.AbsListView) ListView(android.widget.ListView) MotionEvent(android.view.MotionEvent)

Example 17 with OnTouchListener

use of android.view.View.OnTouchListener in project glitch-hq-android by tinyspeck.

the class ProfileFragment method init.

private void init(View root) {
    boolean bUpdateData = m_actList == null;
    View profileSelf = root.findViewById(R.id.profile_user_self);
    View profileOther = root.findViewById(R.id.profile_others);
    ImageView vbg = (ImageView) root.findViewById(R.id.profilebg);
    int nType = Util.GetScreenSizeAttribute(getActivity());
    int[] resBackgrounds = { R.drawable.profile_background, R.drawable.profile_background_l, R.drawable.profile_background_xl };
    int[] resGroddleBg = { R.drawable.profile_other_background, R.drawable.profile_other_background, R.drawable.profile_other_background_xl };
    vbg.setImageResource(m_bOtherProfile ? resGroddleBg[nType] : resBackgrounds[nType]);
    if (nType == 0) {
        int nPaddingTop = 180;
        int nWidth = Util.GetScreenSize(getActivity()).widthPixels;
        if (nWidth > 320)
            nPaddingTop = 170;
        if (m_bOtherProfile)
            nPaddingTop -= 36;
        vbg.setPadding(0, nPaddingTop, 0, 0);
    } else if (nType == 2) {
        int nPaddingTop = 120;
        if (m_bOtherProfile)
            nPaddingTop = 0;
        vbg.setPadding(0, nPaddingTop, 0, 0);
    }
    ScrollView sv = (ScrollView) root.findViewById(R.id.scr_profile);
    sv.setOnTouchListener(new OnTouchListener() {

        public boolean onTouch(View arg0, MotionEvent arg1) {
            return true;
        }
    });
    profileSelf.setVisibility(m_bOtherProfile ? View.GONE : View.VISIBLE);
    profileOther.setVisibility(m_bOtherProfile ? View.VISIBLE : View.GONE);
    ((ImageView) root.findViewById(R.id.rookfossil_image)).setVisibility(m_bOtherProfile ? View.GONE : View.VISIBLE);
    ((ImageView) root.findViewById(R.id.treasure_image)).setVisibility(m_bOtherProfile ? View.VISIBLE : View.GONE);
    m_vProfile = m_bOtherProfile ? profileOther : profileSelf;
    nameTextView = (TextView) m_vProfile.findViewById(R.id.playername);
    nameTextView.setTypeface(m_application.m_vagFont);
    m_listView = (LinearListView) root.findViewById(R.id.homeListView);
    m_learningListView = (LinearListView) root.findViewById(R.id.learning_list);
    m_unlearningListView = (LinearListView) root.findViewById(R.id.unlearning_list);
    m_onlineIcon = (ImageView) m_vProfile.findViewById(R.id.player_online_status);
    m_avatar = (ImageView) m_vProfile.findViewById(R.id.avatar);
    if (!m_bOtherProfile) {
        m_tv_currants = (TextView) m_vProfile.findViewById(R.id.profile_currant_amount);
        m_tv_currants.setTypeface(m_application.m_vagLightFont);
        m_tv_imagination = (TextView) m_vProfile.findViewById(R.id.profile_imagination_amount);
        m_tv_imagination.setTypeface(m_application.m_vagLightFont);
    }
    m_tv_level = (TextView) m_vProfile.findViewById(R.id.tv_level);
    m_tv_level.setTypeface(m_application.m_vagLightFont);
    m_tv_achievements = (TextView) m_vProfile.findViewById(R.id.tv_achievements);
    m_tv_achievements.setTypeface(m_application.m_vagLightFont);
    m_tv_skills = (TextView) m_vProfile.findViewById(R.id.tv_skills);
    m_tv_skills.setTypeface(m_application.m_vagLightFont);
    m_tv_upgrades = (TextView) m_vProfile.findViewById(R.id.tv_upgrades);
    m_tv_upgrades.setTypeface(m_application.m_vagLightFont);
    if (bUpdateData)
        m_actList = new Vector<glitchActivity>();
    m_adapter = new ActivityListViewAdapter(this, m_actList);
    m_listView.setAdapter(m_adapter);
    if (bUpdateData) {
        m_learningList = new Vector<skillAvailable>();
        m_unlearningList = new Vector<skillAvailable>();
    }
    m_learningAdapter = new LearningListViewAdapter(getActivity(), m_learningList);
    m_learningListView.setAdapter(m_learningAdapter);
    m_unlearningAdapter = new UnlearningListViewAdapter(getActivity(), m_unlearningList);
    m_unlearningListView.setAdapter(m_unlearningAdapter);
    View clouds = root.findViewById(R.id.clouds);
    Util.startTranslateAnimation(clouds, 300000);
    m_learningListView.setOnClickListener(new OnClickListener() {

        public void onClick(View arg0) {
            skillAvailable skill = m_learningList.get(0);
            SkillDetailFragment fm = new SkillDetailFragment(m_this, skill);
            ((HomeScreen) getActivity()).setCurrentFragment(fm, true);
        }
    });
    m_unlearningListView.setOnClickListener(new OnClickListener() {

        public void onClick(View arg0) {
            skillAvailable skill = m_unlearningList.get(0);
            SkillDetailFragment fm = new SkillDetailFragment(m_this, skill);
            ((HomeScreen) getActivity()).setCurrentFragment(fm, true);
        }
    });
    //     initPushToRefresh();
    setupSettings();
    if (m_bOtherProfile) {
        m_learningListView.setVisibility(View.GONE);
        m_unlearningListView.setVisibility(View.GONE);
        if (bUpdateData)
            getProfileInfo(false);
    } else {
        m_learningListView.setVisibility(View.VISIBLE);
        m_unlearningListView.setVisibility(View.VISIBLE);
        if (bUpdateData) {
            GlitchRequest request = m_application.glitch.getRequest("players.info");
            request.execute(this);
        }
    }
    if (!bUpdateData)
        showProfilePage();
}
Also used : OnTouchListener(android.view.View.OnTouchListener) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) ScrollView(android.widget.ScrollView) MotionEvent(android.view.MotionEvent) GlitchRequest(com.tinyspeck.android.GlitchRequest) ScrollView(android.widget.ScrollView) BaseFragment.skillAvailable(com.tinyspeck.glitchhq.BaseFragment.skillAvailable) OnClickListener(android.view.View.OnClickListener) ImageView(android.widget.ImageView) Vector(java.util.Vector)

Example 18 with OnTouchListener

use of android.view.View.OnTouchListener in project coursera-android by aporter.

the class IndicateTouchLocationActivity method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    mFrame = (FrameLayout) findViewById(R.id.frame);
    // Initialize pool of View.
    initViews();
    // Create and set on touch listener
    mFrame.setOnTouchListener(new OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            switch(event.getActionMasked()) {
                case MotionEvent.ACTION_DOWN:
                case MotionEvent.ACTION_POINTER_DOWN:
                    {
                        int pointerIndex = event.getActionIndex();
                        int pointerID = event.getPointerId(pointerIndex);
                        MarkerView marker = mInactiveMarkers.remove();
                        if (null != marker) {
                            mActiveMarkers.put(pointerID, marker);
                            marker.setXLoc(event.getX(pointerIndex));
                            marker.setYLoc(event.getY(pointerIndex));
                            updateTouches(mActiveMarkers.size());
                            mFrame.addView(marker);
                        }
                        break;
                    }
                case MotionEvent.ACTION_UP:
                case MotionEvent.ACTION_POINTER_UP:
                    {
                        int pointerIndex = event.getActionIndex();
                        int pointerID = event.getPointerId(pointerIndex);
                        MarkerView marker = mActiveMarkers.remove(pointerID);
                        if (null != marker) {
                            mInactiveMarkers.add(marker);
                            updateTouches(mActiveMarkers.size());
                            mFrame.removeView(marker);
                        }
                        break;
                    }
                case MotionEvent.ACTION_MOVE:
                    {
                        for (int idx = 0; idx < event.getPointerCount(); idx++) {
                            int ID = event.getPointerId(idx);
                            MarkerView marker = mActiveMarkers.get(ID);
                            if (null != marker) {
                                // Redraw only if finger has travel ed a minimum distance   
                                if (Math.abs(marker.getXLoc() - event.getX(idx)) > MIN_DXDY || Math.abs(marker.getYLoc() - event.getY(idx)) > MIN_DXDY) {
                                    // Set new location
                                    marker.setXLoc(event.getX(idx));
                                    marker.setYLoc(event.getY(idx));
                                    // Request re-draw
                                    marker.invalidate();
                                }
                            }
                        }
                        break;
                    }
                default:
                    Log.i(TAG, "unhandled action");
            }
            return true;
        }

        // update number of touches on each active MarkerView
        private void updateTouches(int numActive) {
            for (MarkerView marker : mActiveMarkers.values()) {
                marker.setTouches(numActive);
            }
        }
    });
}
Also used : OnTouchListener(android.view.View.OnTouchListener) View(android.view.View) SuppressLint(android.annotation.SuppressLint) Paint(android.graphics.Paint) MotionEvent(android.view.MotionEvent)

Example 19 with OnTouchListener

use of android.view.View.OnTouchListener in project Etar-Calendar by Etar-Group.

the class EventInfoFragment method updateEvent.

private void updateEvent(View view) {
    if (mEventCursor == null || view == null) {
        return;
    }
    Context context = view.getContext();
    if (context == null) {
        return;
    }
    String eventName = mEventCursor.getString(EVENT_INDEX_TITLE);
    if (eventName == null || eventName.length() == 0) {
        eventName = getActivity().getString(R.string.no_title_label);
    }
    // Events.CONTENT_URI intent.  Update these with values read from the db.
    if (mStartMillis == 0 && mEndMillis == 0) {
        mStartMillis = mEventCursor.getLong(EVENT_INDEX_DTSTART);
        mEndMillis = mEventCursor.getLong(EVENT_INDEX_DTEND);
        if (mEndMillis == 0) {
            String duration = mEventCursor.getString(EVENT_INDEX_DURATION);
            if (!TextUtils.isEmpty(duration)) {
                try {
                    Duration d = new Duration();
                    d.parse(duration);
                    long endMillis = mStartMillis + d.getMillis();
                    if (endMillis >= mStartMillis) {
                        mEndMillis = endMillis;
                    } else {
                        Log.d(TAG, "Invalid duration string: " + duration);
                    }
                } catch (DateException e) {
                    Log.d(TAG, "Error parsing duration string " + duration, e);
                }
            }
            if (mEndMillis == 0) {
                mEndMillis = mStartMillis;
            }
        }
    }
    mAllDay = mEventCursor.getInt(EVENT_INDEX_ALL_DAY) != 0;
    String location = mEventCursor.getString(EVENT_INDEX_EVENT_LOCATION);
    String description = mEventCursor.getString(EVENT_INDEX_DESCRIPTION);
    String rRule = mEventCursor.getString(EVENT_INDEX_RRULE);
    String eventTimezone = mEventCursor.getString(EVENT_INDEX_EVENT_TIMEZONE);
    mHeadlines.setBackgroundColor(mCurrentColor);
    // What
    if (eventName != null) {
        setTextCommon(view, R.id.title, eventName);
    }
    // When
    // Set the date and repeats (if any)
    String localTimezone = Utils.getTimeZone(mActivity, mTZUpdater);
    Resources resources = context.getResources();
    String displayedDatetime = Utils.getDisplayedDatetime(mStartMillis, mEndMillis, System.currentTimeMillis(), localTimezone, mAllDay, context);
    String displayedTimezone = null;
    if (!mAllDay) {
        displayedTimezone = Utils.getDisplayedTimezone(mStartMillis, localTimezone, eventTimezone);
    }
    // Display the datetime.  Make the timezone (if any) transparent.
    if (displayedTimezone == null) {
        setTextCommon(view, R.id.when_datetime, displayedDatetime);
    } else {
        int timezoneIndex = displayedDatetime.length();
        displayedDatetime += "  " + displayedTimezone;
        SpannableStringBuilder sb = new SpannableStringBuilder(displayedDatetime);
        ForegroundColorSpan transparentColorSpan = new ForegroundColorSpan(resources.getColor(R.color.event_info_headline_transparent_color));
        sb.setSpan(transparentColorSpan, timezoneIndex, displayedDatetime.length(), Spannable.SPAN_INCLUSIVE_INCLUSIVE);
        setTextCommon(view, R.id.when_datetime, sb);
    }
    // Display the repeat string (if any)
    String repeatString = null;
    if (!TextUtils.isEmpty(rRule)) {
        EventRecurrence eventRecurrence = new EventRecurrence();
        eventRecurrence.parse(rRule);
        Time date = new Time(localTimezone);
        date.set(mStartMillis);
        if (mAllDay) {
            date.timezone = Time.TIMEZONE_UTC;
        }
        eventRecurrence.setStartDate(date);
        repeatString = EventRecurrenceFormatter.getRepeatString(mContext, resources, eventRecurrence, true);
    }
    if (repeatString == null) {
        view.findViewById(R.id.when_repeat).setVisibility(View.GONE);
    } else {
        setTextCommon(view, R.id.when_repeat, repeatString);
    }
    // Where
    if (location == null || location.trim().length() == 0) {
        setVisibilityCommon(view, R.id.where, View.GONE);
    } else {
        final TextView textView = mWhere;
        if (textView != null) {
            textView.setAutoLinkMask(0);
            textView.setText(location.trim());
            try {
                textView.setText(Utils.extendedLinkify(textView.getText().toString(), true));
                // Linkify.addLinks() sets the TextView movement method if it finds any links.
                // We must do the same here, in case linkify by itself did not find any.
                // (This is cloned from Linkify.addLinkMovementMethod().)
                MovementMethod mm = textView.getMovementMethod();
                if ((mm == null) || !(mm instanceof LinkMovementMethod)) {
                    if (textView.getLinksClickable()) {
                        textView.setMovementMethod(LinkMovementMethod.getInstance());
                    }
                }
            } catch (Exception ex) {
                // unexpected
                Log.e(TAG, "Linkification failed", ex);
            }
            textView.setOnTouchListener(new OnTouchListener() {

                @Override
                public boolean onTouch(View v, MotionEvent event) {
                    try {
                        return v.onTouchEvent(event);
                    } catch (ActivityNotFoundException e) {
                        // ignore
                        return true;
                    }
                }
            });
        }
    }
    // Description
    if (description != null && description.length() != 0) {
        mDesc.setText(description);
    }
    // Launch Custom App
    if (Utils.isJellybeanOrLater()) {
        updateCustomAppButton();
    }
}
Also used : Context(android.content.Context) OnTouchListener(android.view.View.OnTouchListener) ForegroundColorSpan(android.text.style.ForegroundColorSpan) LinkMovementMethod(android.text.method.LinkMovementMethod) Duration(com.android.calendarcommon2.Duration) Time(android.text.format.Time) ScrollView(android.widget.ScrollView) View(android.view.View) AdapterView(android.widget.AdapterView) AttendeesView(com.android.calendar.event.AttendeesView) TextView(android.widget.TextView) IOException(java.io.IOException) ActivityNotFoundException(android.content.ActivityNotFoundException) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) DateException(com.android.calendarcommon2.DateException) MotionEvent(android.view.MotionEvent) EventRecurrence(com.android.calendarcommon2.EventRecurrence) ActivityNotFoundException(android.content.ActivityNotFoundException) LinkMovementMethod(android.text.method.LinkMovementMethod) MovementMethod(android.text.method.MovementMethod) DateException(com.android.calendarcommon2.DateException) TextView(android.widget.TextView) Resources(android.content.res.Resources) SpannableStringBuilder(android.text.SpannableStringBuilder)

Example 20 with OnTouchListener

use of android.view.View.OnTouchListener in project android_frameworks_base by DirtyUnicorns.

the class VolumeDialog method initRow.

@SuppressLint("InflateParams")
private void initRow(final VolumeRow row, final int stream, int iconRes, int iconMuteRes, boolean important) {
    row.stream = stream;
    row.iconRes = iconRes;
    row.iconMuteRes = iconMuteRes;
    row.important = important;
    row.view = mDialog.getLayoutInflater().inflate(R.layout.volume_dialog_row, null);
    row.view.setId(row.stream);
    row.view.setTag(row);
    row.header = (TextView) row.view.findViewById(R.id.volume_row_header);
    row.header.setId(20 * row.stream);
    mSpTexts.add(row.header);
    row.slider = (SeekBar) row.view.findViewById(R.id.volume_row_slider);
    row.slider.setOnSeekBarChangeListener(new VolumeSeekBarChangeListener(row));
    row.anim = null;
    row.cachedShowHeaders = VolumePrefs.DEFAULT_SHOW_HEADERS;
    // forward events above the slider into the slider
    row.view.setOnTouchListener(new OnTouchListener() {

        private final Rect mSliderHitRect = new Rect();

        private boolean mDragging;

        @SuppressLint("ClickableViewAccessibility")
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            row.slider.getHitRect(mSliderHitRect);
            if (!mDragging && event.getActionMasked() == MotionEvent.ACTION_DOWN && event.getY() < mSliderHitRect.top) {
                mDragging = true;
            }
            if (mDragging) {
                event.offsetLocation(-mSliderHitRect.left, -mSliderHitRect.top);
                row.slider.dispatchTouchEvent(event);
                if (event.getActionMasked() == MotionEvent.ACTION_UP || event.getActionMasked() == MotionEvent.ACTION_CANCEL) {
                    mDragging = false;
                }
                return true;
            }
            return false;
        }
    });
    row.icon = (ImageButton) row.view.findViewById(R.id.volume_row_icon);
    row.icon.setImageResource(iconRes);
    row.icon.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            Events.writeEvent(mContext, Events.EVENT_ICON_CLICK, row.stream, row.iconState);
            mController.setActiveStream(row.stream);
            if (row.stream == AudioManager.STREAM_RING) {
                final boolean hasVibrator = mController.hasVibrator();
                if (mState.ringerModeInternal == AudioManager.RINGER_MODE_NORMAL) {
                    if (hasVibrator) {
                        mController.setRingerMode(AudioManager.RINGER_MODE_VIBRATE, false);
                    } else {
                        final boolean wasZero = row.ss.level == 0;
                        mController.setStreamVolume(stream, wasZero ? row.lastAudibleLevel : 0);
                    }
                } else {
                    mController.setRingerMode(AudioManager.RINGER_MODE_NORMAL, false);
                    if (row.ss.level == 0) {
                        mController.setStreamVolume(stream, 1);
                    }
                }
            } else if (row.stream == AudioManager.STREAM_NOTIFICATION) {
                // only ringer icon can change silent or vibrate mode
                if (mState.ringerModeInternal == AudioManager.RINGER_MODE_NORMAL) {
                    final boolean vmute = row.ss.level == 0;
                    mController.setStreamVolume(stream, vmute ? row.lastAudibleLevel : 0);
                }
            } else {
                final boolean vmute = row.ss.level == row.ss.levelMin;
                mController.setStreamVolume(stream, vmute ? row.lastAudibleLevel : row.ss.levelMin);
            }
            // reset the grace period, slider should update immediately
            row.userAttempt = 0;
        }
    });
}
Also used : Rect(android.graphics.Rect) OnTouchListener(android.view.View.OnTouchListener) SuppressLint(android.annotation.SuppressLint) OnClickListener(android.view.View.OnClickListener) View(android.view.View) TextView(android.widget.TextView) MotionEvent(android.view.MotionEvent) SuppressLint(android.annotation.SuppressLint)

Aggregations

MotionEvent (android.view.MotionEvent)44 View (android.view.View)44 OnTouchListener (android.view.View.OnTouchListener)44 TextView (android.widget.TextView)28 ImageView (android.widget.ImageView)15 OnClickListener (android.view.View.OnClickListener)14 ListView (android.widget.ListView)8 SuppressLint (android.annotation.SuppressLint)7 AdapterView (android.widget.AdapterView)7 Intent (android.content.Intent)5 Rect (android.graphics.Rect)5 OnGenericMotionListener (android.view.View.OnGenericMotionListener)5 AbsListView (android.widget.AbsListView)5 DialogInterface (android.content.DialogInterface)4 KeyEvent (android.view.KeyEvent)4 RelativeLayout (android.widget.RelativeLayout)4 ScrollView (android.widget.ScrollView)4 Builder (android.app.AlertDialog.Builder)3 WindowManager (android.view.WindowManager)3 OnItemClickListener (android.widget.AdapterView.OnItemClickListener)3