List of usage examples for android.view GestureDetector GestureDetector
public GestureDetector(Context context, OnGestureListener listener)
From source file:org.osm.keypadmapper2.KeypadMapper2Activity.java
/** Called when the activity is first created. */ @Override/*ww w.ja va 2 s. c o m*/ public void onCreate(Bundle savedInstanceState) { Log.d(TAG, "create"); if (KeypadMapperApplication.getInstance().getSettings().isLayoutOptimizationEnabled()) { getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); requestWindowFeature(Window.FEATURE_NO_TITLE); uiOptimizationEnabled = true; } super.onCreate(savedInstanceState); if (KeypadMapperApplication.getInstance().getSettings().isCompassAvailable()) { sensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE); gsensor = sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER); msensor = sensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD); } updateLocale(); setContentView(R.layout.main); menu = new KeypadMapperMenu(findViewById(R.id.menu)); menu.setMenuListener(this); gestureDetector = new GestureDetector(this, new MyGestureDetector()); // check for external storage String extStorageState = Environment.getExternalStorageState(); if (Environment.MEDIA_MOUNTED.equals(extStorageState)) { // We can read and write the media } else if (Environment.MEDIA_MOUNTED_READ_ONLY.equals(extStorageState)) { // We can only read the media showDialogFatalError(localizer.getString("errorStorageRO")); } else { // Something else is wrong. It may be one of many other states, but // all we need to know is we can neither read nor write showDialogFatalError(localizer.getString("errorStorageUnavailable")); } File kpmFolder = KeypadMapperApplication.getInstance().getKeypadMapperDirectory(); if (!kpmFolder.exists()) { if (!kpmFolder.mkdir()) { showDialogFatalError(localizer.getString("FolderCreationFailed")); } } if (savedInstanceState == null) { savedInstanceState = getIntent().getExtras(); } duplicates = new StringBuffer(); allData = new StringBuffer(); if (savedInstanceState == null) { // first start state = State.keypad; // only on first run automatically start GPS recording if (KeypadMapperApplication.getInstance().getSettings().isFirstRun()) { KeypadMapperApplication.getInstance().getSettings().clearFirstRun(); KeypadMapperApplication.getInstance().startGpsRecording(); // always start when app starts } } else { // restart state = State.values()[savedInstanceState.getInt("state", State.keypad.ordinal())]; satteliteInfoVisible = savedInstanceState.getBoolean("sat_info"); extendedAddressActive = savedInstanceState.getBoolean("extended_address"); if (savedInstanceState.getBoolean("debug_dialog_on")) { duplicates.append(savedInstanceState.getString("duplicates")); allData.append(savedInstanceState.getString("allData")); showTestScreenDialog(); } } keypadFragment = (KeypadFragment) getSupportFragmentManager().findFragmentByTag("keypad"); Log.d("Keypad", "isTablet = " + getResources().getBoolean(R.bool.is_tablet)); if (!getResources().getBoolean(R.bool.is_tablet)) { extendedAddressFragment = (ExtendedAddressFragment) getSupportFragmentManager() .findFragmentByTag("extended_address"); } else { extendedAddressFragment = (ExtendedAddressFragment) getSupportFragmentManager() .findFragmentById(R.id.fragment_extended_address_tablet); } Log.d("Keypad", "extended address fragment = " + extendedAddressFragment); satelliteInfo = (SatelliteInfoFragment) getSupportFragmentManager().findFragmentByTag("satellite"); satInfoView = findViewById(R.id.satellite_view); extendedAddressView = findViewById(R.id.extended_address_view); keypadView = findViewById(R.id.keypad_view); if (keypadView == null && extendedAddressView == null) { state = State.both; } btnTestVersion = (Button) keypadView.findViewById(R.id.btnTestVersion); /* btnTestVersion.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Intent i = new Intent(); i.setClass(KeypadMapper2Activity.this, SettingsActivity.class); i.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION); startActivity(i); // show debug screen with all registered addresses and locations //showTestScreenDialog(); } });*/ if (satteliteInfoVisible) { showSatteliteInfo(); } else { showKeypad(); } locationProvider.refreshReferenceToGps(); }
From source file:com.ecom.consumer.customviews.HorizontalListView.java
public HorizontalListView(Context context, AttributeSet attrs) { super(context, attrs); initScroll();//ww w . j a v a 2s . c o m mEdgeGlowLeft = new EdgeEffectCompat(context); mEdgeGlowRight = new EdgeEffectCompat(context); mGestureDetector = new GestureDetector(context, mGestureListener); bindGestureDetector(); initView(); retrieveXmlConfiguration(context, attrs); setWillNotDraw(false); // If the OS version is high enough then set the friction on the fling // tracker */ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { HoneycombPlus.setFriction(mFlingTracker, FLING_FRICTION); autoScroll(); } }
From source file:vc908.stickerfactory.ui.advancedrecyclerview.draggable.RecyclerViewDragDropManager.java
/** * Attaches {@link RecyclerView} instance. * * Before calling this method, the target {@link RecyclerView} must set * the wrapped adapter instance which is returned by the * {@link #createWrappedAdapter(RecyclerView.Adapter)} method. * * @param rv The {@link RecyclerView} instance * @param scrollEventDistributor The distributor for {@link RecyclerView.OnScrollListener} event *//*ww w. j a v a2 s . com*/ public void attachRecyclerView(RecyclerView rv, RecyclerViewOnScrollEventDistributor scrollEventDistributor) { if (rv == null) { throw new IllegalArgumentException("RecyclerView cannot be null"); } if (isReleased()) { throw new IllegalStateException("Accessing released object"); } if (mRecyclerView != null) { throw new IllegalStateException("RecyclerView instance has already been set"); } if (mAdapter == null || getDraggableItemWrapperAdapter(rv) != mAdapter) { throw new IllegalStateException("adapter is not set properly"); } if (scrollEventDistributor != null) { final RecyclerView rv2 = scrollEventDistributor.getRecyclerView(); if (rv2 != null && rv2 != rv) { throw new IllegalArgumentException( "The scroll event distributor attached to different RecyclerView instance"); } } mRecyclerView = rv; if (scrollEventDistributor != null) { scrollEventDistributor.add(mInternalUseOnScrollListener); mScrollEventRegisteredToDistributor = true; } else { mRecyclerView.addOnScrollListener(mInternalUseOnScrollListener); mScrollEventRegisteredToDistributor = false; } mRecyclerView.addOnItemTouchListener(mInternalUseOnItemTouchListener); mDisplayDensity = mRecyclerView.getResources().getDisplayMetrics().density; mTouchSlop = ViewConfiguration.get(mRecyclerView.getContext()).getScaledTouchSlop(); mScrollTouchSlop = (int) (mTouchSlop * SCROLL_TOUCH_SLOP_MULTIPLY + 0.5f); mGestureDetector = new GestureDetector(mRecyclerView.getContext(), new GestureDetector.SimpleOnGestureListener() { @Override public void onLongPress(MotionEvent e) { handleOnLongPress(e); } @Override public boolean onSingleTapUp(MotionEvent e) { return true; } @Override public boolean onDown(MotionEvent e) { return true; } }); mGestureDetector.setIsLongpressEnabled(true); if (supportsEdgeEffect()) { // edge effect is available on ICS or later mEdgeEffectDecorator = new EdgeEffectDecorator(mRecyclerView); mEdgeEffectDecorator.start(); } }
From source file:net.toload.main.hd.candidate.CandidateView.java
public CandidateView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); mContext = context;/*from ww w . j av a 2 s . c o m*/ mCandidateView = this; embeddedComposing = null; // Jeremy '15,6,4 for embedded composing view in candidateView when floating candidateView (not fixed) mLIMEPref = new LIMEPreferenceManager(context); //Jeremy '16,7,24 get themed objects TypedArray a = context.getTheme().obtainStyledAttributes(attrs, R.styleable.LIMECandidateView, defStyle, R.style.LIMECandidateView); int n = a.getIndexCount(); for (int i = 0; i < n; i++) { int attr = a.getIndex(i); switch (attr) { case R.styleable.LIMECandidateView_suggestHighlight: mDrawableSuggestHighlight = a.getDrawable(attr); break; case R.styleable.LIMECandidateView_voiceInputIcon: mDrawableVoiceInput = a.getDrawable(attr); break; case R.styleable.LIMECandidateView_ExpandButtonIcon: mDrawableExpandButton = a.getDrawable(attr); break; case R.styleable.LIMECandidateView_closeButtonIcon: mDrawableCloseButton = a.getDrawable(attr); break; case R.styleable.LIMECandidateView_candidateBackground: mColorBackground = a.getColor(attr, ContextCompat.getColor(context, R.color.third_background_light)); break; case R.styleable.LIMECandidateView_composingTextColor: mColorComposingText = a.getColor(attr, ContextCompat.getColor(context, R.color.second_foreground_light)); break; case R.styleable.LIMECandidateView_composingBackgroundColor: mColorComposingBackground = a.getColor(attr, ContextCompat.getColor(context, R.color.composing_background_light)); break; case R.styleable.LIMECandidateView_candidateNormalTextColor: mColorNormalText = a.getColor(attr, ContextCompat.getColor(context, R.color.foreground_light)); break; case R.styleable.LIMECandidateView_candidateNormalTextHighlightColor: mColorNormalTextHighlight = a.getColor(attr, ContextCompat.getColor(context, R.color.foreground_light)); break; case R.styleable.LIMECandidateView_composingCodeColor: mColorComposingCode = a.getColor(attr, ContextCompat.getColor(context, R.color.color_common_green_hl)); break; case R.styleable.LIMECandidateView_composingCodeHighlightColor: mColorComposingCodeHighlight = a.getColor(attr, ContextCompat.getColor(context, R.color.third_background_light)); break; case R.styleable.LIMECandidateView_spacerColor: mColorSpacer = a.getColor(attr, ContextCompat.getColor(context, R.color.candidate_spacer)); break; case R.styleable.LIMECandidateView_selKeyColor: mColorSelKey = a.getColor(attr, ContextCompat.getColor(context, R.color.candidate_selection_keys)); break; case R.styleable.LIMECandidateView_selKeyShiftedColor: mColorSelKeyShifted = a.getColor(attr, ContextCompat.getColor(context, R.color.color_common_green_hl)); break; } } a.recycle(); final Resources r = context.getResources(); Display display = ((WindowManager) context.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay(); Point screenSize = new Point(); display.getSize(screenSize); mScreenWidth = screenSize.x; mScreenHeight = screenSize.y; mVerticalPadding = (int) (r.getDimensionPixelSize(R.dimen.candidate_vertical_padding) * mLIMEPref.getFontSize()); configHeight = (int) (r.getDimensionPixelSize(R.dimen.candidate_stripe_height) * mLIMEPref.getFontSize()); mHeight = configHeight + mVerticalPadding; mExpandButtonWidth = r.getDimensionPixelSize(R.dimen.candidate_expand_button_width);// *mLIMEPref.getFontSize()); mCandidatePaint = new Paint(); mCandidatePaint.setColor(mColorNormalText); mCandidatePaint.setAntiAlias(true); mCandidatePaint.setTextSize(r.getDimensionPixelSize(R.dimen.candidate_font_size) * mLIMEPref.getFontSize()); mCandidatePaint.setStrokeWidth(0); mSelKeyPaint = new Paint(); mSelKeyPaint.setColor(mColorSelKey); mSelKeyPaint.setAntiAlias(true); mSelKeyPaint .setTextSize(r.getDimensionPixelSize(R.dimen.candidate_number_font_size) * mLIMEPref.getFontSize()); mSelKeyPaint.setStyle(Paint.Style.FILL_AND_STROKE); //final SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context); //Jeremy '12,4,23 add mContext parameter. The constructor without context is deprecated mGestureDetector = new GestureDetector(mContext, new GestureDetector.SimpleOnGestureListener() { @Override public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) { if (DEBUG) Log.i(TAG, "onScroll(): distanceX = " + distanceX + "; distanceY = " + distanceY); //Jeremy '12,4,8 filter out small scroll which is actually candidate selection. if (Math.abs(distanceX) < mHeight / 5 && Math.abs(distanceY) < mHeight / 5) return true; mScrolled = true; // Update full candidate list before scroll checkHasMoreRecords(); int sx = getScrollX(); sx += distanceX; if (sx < 0) { sx = 0; } if (sx + getWidth() > mTotalWidth) { sx -= distanceX; } if (mLIMEPref.getParameterBoolean("candidate_switch", false)) { hasSlide = true; mTargetScrollX = sx; scrollTo(sx, getScrollY()); currentX = getScrollX(); //Jeremy '12,7,6 set currentX to the left edge of current scrollview after scrolled } else { hasSlide = false; if (distanceX < 0) { goLeft = true; goRight = false; } else if (distanceX > 0) { goLeft = false; goRight = true; } else { mTargetScrollX = sx; } } return true; } }); }
From source file:com.aqtx.app.common.ui.viewpager.PagerSlidingTabStrip.java
private void addTabDoubleTapListener(final int position, View tab) { final GestureDetector gd = new GestureDetector(getContext(), new GestureDetector.SimpleOnGestureListener() { @Override/*from w ww .j a v a 2 s .c o m*/ public boolean onDoubleTap(MotionEvent e) { if (onTabDoubleTapListener != null) onTabDoubleTapListener.onCurrentTabDoubleTap(position); return true; } }); tab.setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { return gd.onTouchEvent(event); } }); }
From source file:com.raja.knowme.FragmentProfile.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View mHolderView = inflater.inflate(R.layout.fragment_profile, null); shake = AnimationUtils.loadAnimation(getActivity(), R.anim.shake); functions = new AppCommonFunctions(getActivity()); pref = new AppPreferences(getActivity()); knowmeData = new KnowMeDataObject(getActivity()); mProgressDialog = new ProgressDialog(getActivity()); mProgressDialog.setCancelable(false); mProgressDialog.setMessage(getString(R.string.loading)); mHeaderSwitcher = (TextSwitcher) mHolderView.findViewById(R.id.profile_subheader_text); mBodySwitcher = (TextSwitcher) mHolderView.findViewById(R.id.profile_body_text); mScrollview = (ScrollView) mHolderView.findViewById(R.id.profile_scrollview); mInstructionBtn = (RelativeLayout) mHolderView.findViewById(R.id.instrunstions_layout); if (!pref.getProfileFirstRun()) { mInstructionBtn.setVisibility(RelativeLayout.GONE); }//from ww w.java 2s. c om mInstructionBtn.setOnClickListener(new OnClickListener() { public void onClick(View v) { pref.setProfileRunned(); mInstructionBtn.setVisibility(RelativeLayout.GONE); } }); /* Multiple Screen Size Condition */ // Small Size if ((getContext().getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_SMALL) { // Toast.makeText(getActivity(), "small", Toast.LENGTH_SHORT).show(); mHeaderSwitcher.setFactory(new ViewFactory() { public View makeView() { /** Set up the custom auto scrolling text view class for lengthy album names */ AppTextView textSwitcher_text = new AppTextView(getActivity()); textSwitcher_text.setTextColor(Color.argb(225, 245, 242, 11)); textSwitcher_text.setTextSize(24 * functions.getScreenDPI()); textSwitcher_text.setSingleLine(true); textSwitcher_text.setEllipsize(TruncateAt.MARQUEE); textSwitcher_text.setMarqueeRepeatLimit(-1); textSwitcher_text.setHorizontallyScrolling(true); return textSwitcher_text; } }); mBodySwitcher.setFactory(new ViewFactory() { public View makeView() { /** Set up the custom auto scrolling text view class for lengthy album names */ AppTextView textSwitcher_text = new AppTextView(getActivity()); textSwitcher_text.setTextColor(Color.argb(225, 225, 225, 225)); textSwitcher_text.setTextSize(6 * functions.getScreenDPI()); return textSwitcher_text; } }); } //Normal Size else if ((getContext().getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_NORMAL) { //Toast.makeText(getActivity(),"normal" , Toast.LENGTH_SHORT).show(); mHeaderSwitcher.setFactory(new ViewFactory() { public View makeView() { /** Set up the custom auto scrolling text view class for lengthy album names */ AppTextView textSwitcher_text = new AppTextView(getActivity()); textSwitcher_text.setTextColor(Color.argb(225, 245, 242, 11)); textSwitcher_text.setTextSize(14 * functions.getScreenDPI()); textSwitcher_text.setSingleLine(true); textSwitcher_text.setEllipsize(TruncateAt.MARQUEE); textSwitcher_text.setMarqueeRepeatLimit(-1); textSwitcher_text.setHorizontallyScrolling(true); return textSwitcher_text; } }); mBodySwitcher.setFactory(new ViewFactory() { public View makeView() { /** Set up the custom auto scrolling text view class for lengthy album names */ AppTextView textSwitcher_text = new AppTextView(getActivity()); textSwitcher_text.setTextColor(Color.argb(225, 225, 225, 225)); textSwitcher_text.setTextSize(9 * functions.getScreenDPI()); return textSwitcher_text; } }); } // Large Size else if ((getContext().getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_LARGE) { //Toast.makeText(getActivity(),"large" , Toast.LENGTH_SHORT).show(); mHeaderSwitcher.setFactory(new ViewFactory() { public View makeView() { /** Set up the custom auto scrolling text view class for lengthy album names */ AppTextView textSwitcher_text = new AppTextView(getActivity()); textSwitcher_text.setTextColor(Color.argb(225, 245, 242, 11)); textSwitcher_text.setTextSize(32 * functions.getScreenDPI()); textSwitcher_text.setSingleLine(true); textSwitcher_text.setEllipsize(TruncateAt.MARQUEE); textSwitcher_text.setMarqueeRepeatLimit(-1); textSwitcher_text.setHorizontallyScrolling(true); return textSwitcher_text; } }); mBodySwitcher.setFactory(new ViewFactory() { public View makeView() { /** Set up the custom auto scrolling text view class for lengthy album names */ AppTextView textSwitcher_text = new AppTextView(getActivity()); textSwitcher_text.setTextColor(Color.argb(225, 225, 225, 225)); textSwitcher_text.setTextSize(18 * functions.getScreenDPI()); return textSwitcher_text; } }); } //X-large Size else if ((getContext().getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_XLARGE) { // Toast.makeText(getActivity(),"xlarge" , Toast.LENGTH_SHORT).show(); mHeaderSwitcher.setFactory(new ViewFactory() { public View makeView() { /** Set up the custom auto scrolling text view class for lengthy album names */ AppTextView textSwitcher_text = new AppTextView(getActivity()); textSwitcher_text.setTextColor(Color.argb(225, 245, 242, 11)); textSwitcher_text.setTextSize(48 * functions.getScreenDPI()); textSwitcher_text.setSingleLine(true); textSwitcher_text.setEllipsize(TruncateAt.MARQUEE); textSwitcher_text.setMarqueeRepeatLimit(-1); textSwitcher_text.setHorizontallyScrolling(true); return textSwitcher_text; } }); mBodySwitcher.setFactory(new ViewFactory() { public View makeView() { /** Set up the custom auto scrolling text view class for lengthy album names */ AppTextView textSwitcher_text = new AppTextView(getActivity()); textSwitcher_text.setTextColor(Color.argb(225, 225, 225, 225)); textSwitcher_text.setTextSize(24 * functions.getScreenDPI()); return textSwitcher_text; } }); } //Undefined Size else { // Toast.makeText(getActivity(),"undefined" , Toast.LENGTH_SHORT).show(); mHeaderSwitcher.setFactory(new ViewFactory() { public View makeView() { /** Set up the custom auto scrolling text view class for lengthy album names */ AppTextView textSwitcher_text = new AppTextView(getActivity()); textSwitcher_text.setTextColor(Color.argb(225, 245, 242, 11)); textSwitcher_text.setTextSize(32 * functions.getScreenDPI()); textSwitcher_text.setSingleLine(true); textSwitcher_text.setEllipsize(TruncateAt.MARQUEE); textSwitcher_text.setMarqueeRepeatLimit(-1); textSwitcher_text.setHorizontallyScrolling(true); return textSwitcher_text; } }); mBodySwitcher.setFactory(new ViewFactory() { public View makeView() { /** Set up the custom auto scrolling text view class for lengthy album names */ AppTextView textSwitcher_text = new AppTextView(getActivity()); textSwitcher_text.setTextColor(Color.argb(225, 225, 225, 225)); textSwitcher_text.setTextSize(20 * functions.getScreenDPI()); return textSwitcher_text; } }); } mProgressDialog.show(); new LoadData().execute(); gestureDetector = new GestureDetector(getActivity(), new OnGestureListener() { public boolean onSingleTapUp(MotionEvent e) { return false; } public void onShowPress(MotionEvent e) { } public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) { return false; } public void onLongPress(MotionEvent e) { } public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { try { if (Math.abs(e1.getY() - e2.getY()) > AppGlobalVariables.SWIPE_MAX_OFF_PATH) return false; /** Left swipe */ if (e1.getX() - e2.getX() > AppGlobalVariables.SWIPE_MIN_DISTANCE && Math.abs(velocityX) > AppGlobalVariables.SWIPE_THRESHOLD_VELOCITY) { if (count < (MAX_COUNT - 1)) nextDetail(); else { mHeaderSwitcher.startAnimation(shake); mBodySwitcher.startAnimation(shake); } /** Right Swipe */ } else if (e2.getX() - e1.getX() > AppGlobalVariables.SWIPE_MIN_DISTANCE && Math.abs(velocityX) > AppGlobalVariables.SWIPE_THRESHOLD_VELOCITY) { if (count != 0) previousDetail(); else { mHeaderSwitcher.startAnimation(shake); mBodySwitcher.startAnimation(shake); } } } catch (Exception e) { } return false; } public boolean onDown(MotionEvent e) { return false; } }); gestureListener = new View.OnTouchListener() { public boolean onTouch(View v, MotionEvent event) { return gestureDetector.onTouchEvent(event); } }; mScrollview.setOnTouchListener(gestureListener); return mHolderView; }
From source file:com.raja.knowme.FragmentTestimonials.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View mHolderView = inflater.inflate(R.layout.fragment_testimonials, null); shake = AnimationUtils.loadAnimation(getActivity(), R.anim.shake); functions = new AppCommonFunctions(getActivity()); pref = new AppPreferences(getActivity()); knowmeData = new KnowMeDataObject(getActivity()); mProgressDialog = new ProgressDialog(getActivity()); mProgressDialog.setCancelable(false); mProgressDialog.setMessage(getString(R.string.loading)); mHeaderSwitcher = (TextSwitcher) mHolderView.findViewById(R.id.testimonials_subheader_text); mBodySwitcher = (TextSwitcher) mHolderView.findViewById(R.id.testimonials_body_text); mScrollview = (ScrollView) mHolderView.findViewById(R.id.testimonials_scrollview); mInstructionBtn = (RelativeLayout) mHolderView.findViewById(R.id.instrunstions_layout); if (!pref.getTestimonialsFirstRun()) { mInstructionBtn.setVisibility(RelativeLayout.GONE); }// ww w . java2 s. com mInstructionBtn.setOnClickListener(new OnClickListener() { public void onClick(View v) { pref.setTestimonialsRunned(); mInstructionBtn.setVisibility(RelativeLayout.GONE); } }); /* Multiple Screen Size Condition */ // Small Size if ((getContext().getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_SMALL) { // Toast.makeText(getActivity(), "small", Toast.LENGTH_SHORT).show(); mHeaderSwitcher.setFactory(new ViewFactory() { public View makeView() { /** Set up the custom auto scrolling text view class for lengthy album names */ AppTextView textSwitcher_text = new AppTextView(getActivity()); textSwitcher_text.setTextColor(Color.argb(225, 245, 242, 11)); textSwitcher_text.setTextSize(24 * functions.getScreenDPI()); textSwitcher_text.setSingleLine(true); textSwitcher_text.setEllipsize(TruncateAt.MARQUEE); textSwitcher_text.setMarqueeRepeatLimit(-1); textSwitcher_text.setHorizontallyScrolling(true); return textSwitcher_text; } }); mBodySwitcher.setFactory(new ViewFactory() { public View makeView() { /** Set up the custom auto scrolling text view class for lengthy album names */ AppTextView textSwitcher_text = new AppTextView(getActivity()); textSwitcher_text.setTextColor(Color.argb(225, 225, 225, 225)); textSwitcher_text.setTextSize(6 * functions.getScreenDPI()); return textSwitcher_text; } }); } //Normal Size else if ((getContext().getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_NORMAL) { // Toast.makeText(getActivity(), "normal", Toast.LENGTH_SHORT).show(); mHeaderSwitcher.setFactory(new ViewFactory() { public View makeView() { /** Set up the custom auto scrolling text view class for lengthy album names */ AppTextView textSwitcher_text = new AppTextView(getActivity()); textSwitcher_text.setTextColor(Color.argb(225, 245, 242, 11)); textSwitcher_text.setTextSize(14 * functions.getScreenDPI()); textSwitcher_text.setSingleLine(true); textSwitcher_text.setEllipsize(TruncateAt.MARQUEE); textSwitcher_text.setMarqueeRepeatLimit(-1); textSwitcher_text.setHorizontallyScrolling(true); return textSwitcher_text; } }); mBodySwitcher.setFactory(new ViewFactory() { public View makeView() { /** Set up the custom auto scrolling text view class for lengthy album names */ AppTextView textSwitcher_text = new AppTextView(getActivity()); textSwitcher_text.setTextColor(Color.argb(225, 225, 225, 225)); textSwitcher_text.setTextSize(9 * functions.getScreenDPI()); return textSwitcher_text; } }); } // Large Size else if ((getContext().getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_LARGE) { // Toast.makeText(getActivity(), "large", Toast.LENGTH_SHORT).show(); mHeaderSwitcher.setFactory(new ViewFactory() { public View makeView() { /** Set up the custom auto scrolling text view class for lengthy album names */ AppTextView textSwitcher_text = new AppTextView(getActivity()); textSwitcher_text.setTextColor(Color.argb(225, 245, 242, 11)); textSwitcher_text.setTextSize(32 * functions.getScreenDPI()); textSwitcher_text.setSingleLine(true); textSwitcher_text.setEllipsize(TruncateAt.MARQUEE); textSwitcher_text.setMarqueeRepeatLimit(-1); textSwitcher_text.setHorizontallyScrolling(true); return textSwitcher_text; } }); mBodySwitcher.setFactory(new ViewFactory() { public View makeView() { /** Set up the custom auto scrolling text view class for lengthy album names */ AppTextView textSwitcher_text = new AppTextView(getActivity()); textSwitcher_text.setTextColor(Color.argb(225, 225, 225, 225)); textSwitcher_text.setTextSize(18 * functions.getScreenDPI()); return textSwitcher_text; } }); } //X-large Size else if ((getContext().getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_XLARGE) { // Toast.makeText(getActivity(), "xlarge", Toast.LENGTH_SHORT).show(); mHeaderSwitcher.setFactory(new ViewFactory() { public View makeView() { /** Set up the custom auto scrolling text view class for lengthy album names */ AppTextView textSwitcher_text = new AppTextView(getActivity()); textSwitcher_text.setTextColor(Color.argb(225, 245, 242, 11)); textSwitcher_text.setTextSize(48 * functions.getScreenDPI()); textSwitcher_text.setSingleLine(true); textSwitcher_text.setEllipsize(TruncateAt.MARQUEE); textSwitcher_text.setMarqueeRepeatLimit(-1); textSwitcher_text.setHorizontallyScrolling(true); return textSwitcher_text; } }); mBodySwitcher.setFactory(new ViewFactory() { public View makeView() { /** Set up the custom auto scrolling text view class for lengthy album names */ AppTextView textSwitcher_text = new AppTextView(getActivity()); textSwitcher_text.setTextColor(Color.argb(225, 225, 225, 225)); textSwitcher_text.setTextSize(24 * functions.getScreenDPI()); return textSwitcher_text; } }); } //Undefined Size else { // Toast.makeText(getActivity(), "undefined", Toast.LENGTH_SHORT).show(); mHeaderSwitcher.setFactory(new ViewFactory() { public View makeView() { /** Set up the custom auto scrolling text view class for lengthy album names */ AppTextView textSwitcher_text = new AppTextView(getActivity()); textSwitcher_text.setTextColor(Color.argb(225, 245, 242, 11)); textSwitcher_text.setTextSize(20 * functions.getScreenDPI()); textSwitcher_text.setSingleLine(true); textSwitcher_text.setEllipsize(TruncateAt.MARQUEE); textSwitcher_text.setMarqueeRepeatLimit(-1); textSwitcher_text.setHorizontallyScrolling(true); return textSwitcher_text; } }); mBodySwitcher.setFactory(new ViewFactory() { public View makeView() { /** Set up the custom auto scrolling text view class for lengthy album names */ AppTextView textSwitcher_text = new AppTextView(getActivity()); textSwitcher_text.setTextColor(Color.argb(225, 225, 225, 225)); textSwitcher_text.setTextSize(12 * functions.getScreenDPI()); return textSwitcher_text; } }); } mProgressDialog.show(); new LoadData().execute(); gestureDetector = new GestureDetector(getActivity(), new OnGestureListener() { public boolean onSingleTapUp(MotionEvent e) { return false; } public void onShowPress(MotionEvent e) { } public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) { return false; } public void onLongPress(MotionEvent e) { } public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { try { if (Math.abs(e1.getY() - e2.getY()) > AppGlobalVariables.SWIPE_MAX_OFF_PATH) return false; /** Left swipe */ if (e1.getX() - e2.getX() > AppGlobalVariables.SWIPE_MIN_DISTANCE && Math.abs(velocityX) > AppGlobalVariables.SWIPE_THRESHOLD_VELOCITY) { if (count < (MAX_COUNT - 1)) nextDetail(); else { mHeaderSwitcher.startAnimation(shake); mBodySwitcher.startAnimation(shake); } /** Right Swipe */ } else if (e2.getX() - e1.getX() > AppGlobalVariables.SWIPE_MIN_DISTANCE && Math.abs(velocityX) > AppGlobalVariables.SWIPE_THRESHOLD_VELOCITY) { if (count != 0) previousDetail(); else { mHeaderSwitcher.startAnimation(shake); mBodySwitcher.startAnimation(shake); } } } catch (Exception e) { } return false; } public boolean onDown(MotionEvent e) { return false; } }); gestureListener = new View.OnTouchListener() { public boolean onTouch(View v, MotionEvent event) { return gestureDetector.onTouchEvent(event); } }; mScrollview.setOnTouchListener(gestureListener); return mHolderView; }
From source file:com.raja.knowme.FragmentReferences.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View mHolderView = inflater.inflate(R.layout.fragment_references, null); shake = AnimationUtils.loadAnimation(getActivity(), R.anim.shake); functions = new AppCommonFunctions(getActivity()); pref = new AppPreferences(getActivity()); knowmeData = new KnowMeDataObject(getActivity()); mProgressDialog = new ProgressDialog(getActivity()); mProgressDialog.setCancelable(false); mProgressDialog.setMessage(getString(R.string.loading)); mHeaderSwitcher = (TextSwitcher) mHolderView.findViewById(R.id.references_subheader_text); mBodySwitcher = (TextSwitcher) mHolderView.findViewById(R.id.references_body_text); mScrollview = (ScrollView) mHolderView.findViewById(R.id.references_scrollview); mInstructionBtn = (RelativeLayout) mHolderView.findViewById(R.id.instrunstions_layout); if (!pref.getReferencesFirstRun()) { mInstructionBtn.setVisibility(RelativeLayout.GONE); }/*from w ww .j av a 2 s . c om*/ mInstructionBtn.setOnClickListener(new OnClickListener() { public void onClick(View v) { pref.setReferencesRunned(); mInstructionBtn.setVisibility(RelativeLayout.GONE); } }); /* Multiple Screen Size Condition */ // Small Size if ((getContext().getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_SMALL) { // Toast.makeText(getActivity(), "small", Toast.LENGTH_SHORT).show(); mHeaderSwitcher.setFactory(new ViewSwitcher.ViewFactory() { public View makeView() { /** Set up the custom auto scrolling text view class for lengthy album names */ AppTextView textSwitcher_text = new AppTextView(getActivity()); textSwitcher_text.setTextColor(Color.argb(225, 245, 242, 11)); textSwitcher_text.setTextSize(24 * functions.getScreenDPI()); textSwitcher_text.setSingleLine(true); textSwitcher_text.setEllipsize(TextUtils.TruncateAt.MARQUEE); textSwitcher_text.setMarqueeRepeatLimit(-1); textSwitcher_text.setHorizontallyScrolling(true); return textSwitcher_text; } }); mBodySwitcher.setFactory(new ViewSwitcher.ViewFactory() { public View makeView() { /** Set up the custom auto scrolling text view class for lengthy album names */ AppTextView textSwitcher_text = new AppTextView(getActivity()); textSwitcher_text.setTextColor(Color.argb(225, 225, 225, 225)); textSwitcher_text.setTextSize(6 * functions.getScreenDPI()); return textSwitcher_text; } }); } //Normal Size else if ((getContext().getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_NORMAL) { // Toast.makeText(getActivity(), "normal", Toast.LENGTH_SHORT).show(); mHeaderSwitcher.setFactory(new ViewSwitcher.ViewFactory() { public View makeView() { /** Set up the custom auto scrolling text view class for lengthy album names */ AppTextView textSwitcher_text = new AppTextView(getActivity()); textSwitcher_text.setTextColor(Color.argb(225, 245, 242, 11)); textSwitcher_text.setTextSize(14 * functions.getScreenDPI()); textSwitcher_text.setSingleLine(true); textSwitcher_text.setEllipsize(TextUtils.TruncateAt.MARQUEE); textSwitcher_text.setMarqueeRepeatLimit(-1); textSwitcher_text.setHorizontallyScrolling(true); return textSwitcher_text; } }); mBodySwitcher.setFactory(new ViewSwitcher.ViewFactory() { public View makeView() { /** Set up the custom auto scrolling text view class for lengthy album names */ AppTextView textSwitcher_text = new AppTextView(getActivity()); textSwitcher_text.setTextColor(Color.argb(225, 225, 225, 225)); textSwitcher_text.setTextSize(9 * functions.getScreenDPI()); return textSwitcher_text; } }); } // Large Size else if ((getContext().getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_LARGE) { // Toast.makeText(getActivity(), "large", Toast.LENGTH_SHORT).show(); mHeaderSwitcher.setFactory(new ViewSwitcher.ViewFactory() { public View makeView() { /** Set up the custom auto scrolling text view class for lengthy album names */ AppTextView textSwitcher_text = new AppTextView(getActivity()); textSwitcher_text.setTextColor(Color.argb(225, 245, 242, 11)); textSwitcher_text.setTextSize(32 * functions.getScreenDPI()); textSwitcher_text.setSingleLine(true); textSwitcher_text.setEllipsize(TextUtils.TruncateAt.MARQUEE); textSwitcher_text.setMarqueeRepeatLimit(-1); textSwitcher_text.setHorizontallyScrolling(true); return textSwitcher_text; } }); mBodySwitcher.setFactory(new ViewSwitcher.ViewFactory() { public View makeView() { /** Set up the custom auto scrolling text view class for lengthy album names */ AppTextView textSwitcher_text = new AppTextView(getActivity()); textSwitcher_text.setTextColor(Color.argb(225, 225, 225, 225)); textSwitcher_text.setTextSize(18 * functions.getScreenDPI()); return textSwitcher_text; } }); } //X-large Size else if ((getContext().getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_XLARGE) { // Toast.makeText(getActivity(), "xlarge", Toast.LENGTH_SHORT).show(); mHeaderSwitcher.setFactory(new ViewSwitcher.ViewFactory() { public View makeView() { /** Set up the custom auto scrolling text view class for lengthy album names */ AppTextView textSwitcher_text = new AppTextView(getActivity()); textSwitcher_text.setTextColor(Color.argb(225, 245, 242, 11)); textSwitcher_text.setTextSize(48 * functions.getScreenDPI()); textSwitcher_text.setSingleLine(true); textSwitcher_text.setEllipsize(TextUtils.TruncateAt.MARQUEE); textSwitcher_text.setMarqueeRepeatLimit(-1); textSwitcher_text.setHorizontallyScrolling(true); return textSwitcher_text; } }); mBodySwitcher.setFactory(new ViewSwitcher.ViewFactory() { public View makeView() { /** Set up the custom auto scrolling text view class for lengthy album names */ AppTextView textSwitcher_text = new AppTextView(getActivity()); textSwitcher_text.setTextColor(Color.argb(225, 225, 225, 225)); textSwitcher_text.setTextSize(24 * functions.getScreenDPI()); return textSwitcher_text; } }); } //Undefined Size else { // Toast.makeText(getActivity(), "undefined", Toast.LENGTH_SHORT).show(); mHeaderSwitcher.setFactory(new ViewSwitcher.ViewFactory() { public View makeView() { /** Set up the custom auto scrolling text view class for lengthy album names */ AppTextView textSwitcher_text = new AppTextView(getActivity()); textSwitcher_text.setTextColor(Color.argb(225, 245, 242, 11)); textSwitcher_text.setTextSize(32 * functions.getScreenDPI()); textSwitcher_text.setSingleLine(true); textSwitcher_text.setEllipsize(TextUtils.TruncateAt.MARQUEE); textSwitcher_text.setMarqueeRepeatLimit(-1); textSwitcher_text.setHorizontallyScrolling(true); return textSwitcher_text; } }); mBodySwitcher.setFactory(new ViewSwitcher.ViewFactory() { public View makeView() { /** Set up the custom auto scrolling text view class for lengthy album names */ AppTextView textSwitcher_text = new AppTextView(getActivity()); textSwitcher_text.setTextColor(Color.argb(225, 225, 225, 225)); textSwitcher_text.setTextSize(20 * functions.getScreenDPI()); return textSwitcher_text; } }); } mProgressDialog.show(); new LoadData().execute(); gestureDetector = new GestureDetector(getActivity(), new OnGestureListener() { public boolean onSingleTapUp(MotionEvent e) { return false; } public void onShowPress(MotionEvent e) { } public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) { return false; } public void onLongPress(MotionEvent e) { } public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { try { if (Math.abs(e1.getY() - e2.getY()) > AppGlobalVariables.SWIPE_MAX_OFF_PATH) return false; /** Left swipe */ if (e1.getX() - e2.getX() > AppGlobalVariables.SWIPE_MIN_DISTANCE && Math.abs(velocityX) > AppGlobalVariables.SWIPE_THRESHOLD_VELOCITY) { if (count < (MAX_COUNT - 1)) nextDetail(); else { mHeaderSwitcher.startAnimation(shake); mBodySwitcher.startAnimation(shake); } /** Right Swipe */ } else if (e2.getX() - e1.getX() > AppGlobalVariables.SWIPE_MIN_DISTANCE && Math.abs(velocityX) > AppGlobalVariables.SWIPE_THRESHOLD_VELOCITY) { if (count != 0) previousDetail(); else { mHeaderSwitcher.startAnimation(shake); mBodySwitcher.startAnimation(shake); } } } catch (Exception e) { } return false; } public boolean onDown(MotionEvent e) { return false; } }); gestureListener = new View.OnTouchListener() { public boolean onTouch(View v, MotionEvent event) { return gestureDetector.onTouchEvent(event); } }; mScrollview.setOnTouchListener(gestureListener); return mHolderView; }
From source file:com.rnd.snapsplit.view.OcrCaptureFragment.java
/** * Initializes the UI and creates the detector pipeline. *//*from w ww .j a v a2 s . c om*/ // @Override // public void onActivityResult(int requestCode, int resultCode, Intent data) { // super.onActivityResult(requestCode, resultCode, data); // // if (requestCode == TAKE_PHOTO_CODE && resultCode == RESULT_OK) { // Toast.makeText(getContext(), "pic saved", Toast.LENGTH_LONG).show(); // Log.d("CameraDemo", "Pic saved"); // } // } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { final View view = inflater.inflate(R.layout.view_ocr_capture, container, false); final Activity activity = getActivity(); final Context context = getContext(); ((Toolbar) activity.findViewById(R.id.tool_bar_hamburger)) .setBackgroundColor(ContextCompat.getColor(context, android.R.color.transparent)); final String dir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES) + "/picFolder/"; File newdir = new File(dir); newdir.mkdirs(); mPreview = (CameraSourcePreview) view.findViewById(R.id.preview); mGraphicOverlay = (GraphicOverlay<OcrGraphic>) view.findViewById(R.id.graphicOverlay); StrictMode.VmPolicy.Builder builder = new StrictMode.VmPolicy.Builder(); StrictMode.setVmPolicy(builder.build()); // Set good defaults for capturing text. boolean autoFocus = true; boolean useFlash = false; // createNewThread(); // t.start(); final ImageView upArrow = (ImageView) view.findViewById(R.id.arrow_up); upArrow.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (rotationAngle == 0) { // arrow up //mCameraSource.takePicture(null, mPicture); //mGraphicOverlay.clear(); // mGraphicOverlay.clear(); // mGraphicOverlay.amountItem = null; onPause(); //shouldContinue = false; //mCamera.takePicture(null, null, mPicture); File pictureFile = getOutputMediaFile(); if (pictureFile == null) { return; } try { FileOutputStream fos = new FileOutputStream(pictureFile); Bitmap receiptBitmap = byteStreamToBitmap(mCameraSource.mostRecentBitmap); receiptBitmap.compress(Bitmap.CompressFormat.JPEG, 80, fos); picPath = pictureFile.getAbsolutePath(); //fos.write(mCameraSource.mostRecentBitmap); fos.close(); } catch (FileNotFoundException e) { } catch (IOException e) { } upArrow.animate().rotation(180).setDuration(500).start(); TextView amount = (TextView) view.findViewById(R.id.text_amount_value); if (mGraphicOverlay.amountItem == null) { amount.setText("0.00"); } else { amount.setText(String.format("%.2f", mGraphicOverlay.amountItemAfterFormat)); } TextView desc = (TextView) view.findViewById(R.id.text_name_value); desc.setText(mGraphicOverlay.description); RelativeLayout box = (RelativeLayout) view.findViewById(R.id.recognition_box); box.setVisibility(View.VISIBLE); Animation slide_up = AnimationUtils.loadAnimation(activity.getApplicationContext(), R.anim.slide_up); box.startAnimation(slide_up); rotationAngle = 180; } else { // t.interrupt(); // t = null; RelativeLayout box = (RelativeLayout) view.findViewById(R.id.recognition_box); Animation slide_down = AnimationUtils.loadAnimation(activity.getApplicationContext(), R.anim.slide_down); upArrow.animate().rotation(0).setDuration(500).start(); box.startAnimation(slide_down); box.setVisibility(View.INVISIBLE); //shouldContinue = true; mGraphicOverlay.amountItem = null; mGraphicOverlay.amountItemAfterFormat = 0f; mGraphicOverlay.description = ""; onResume(); // createNewThread(); // t.start(); rotationAngle = 0; } } }); ImageView addButton = (ImageView) view.findViewById(R.id.add_icon); addButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // takePicture(); EditText description = (EditText) view.findViewById(R.id.text_name_value); EditText amount = (EditText) view.findViewById(R.id.text_amount_value); float floatAmount = Float.parseFloat(amount.getText().toString()); Summary t = new Summary(description.getText().toString(), floatAmount); Bundle bundle = new Bundle(); bundle.putSerializable("splitTransaction", t); // ByteArrayOutputStream stream = new ByteArrayOutputStream(); // mCameraSource.mostRecentBitmap.compress(Bitmap.CompressFormat.PNG, 80, stream); // byte[] byteArray = stream.toByteArray(); //Bitmap receiptBitmap = byteStreamToBitmap(mCameraSource.mostRecentBitmap); //bundle.putParcelable("receiptPicture",receiptBitmap); bundle.putString("receiptPicture", picPath); FriendsSelectionFragment fragment = new FriendsSelectionFragment(); fragment.setArguments(bundle); ((Toolbar) activity.findViewById(R.id.tool_bar_hamburger)).setVisibility(View.INVISIBLE); getActivity().getSupportFragmentManager().beginTransaction() .add(R.id.fragment_holder, fragment, "FriendsSelectionFragment").addToBackStack(null) .commit(); } }); // Check for the camera permission before accessing the camera. If the // permission is not granted yet, request permission. int rc = ActivityCompat.checkSelfPermission(context, Manifest.permission.CAMERA); if (rc == PackageManager.PERMISSION_GRANTED) { createCameraSource(autoFocus, useFlash); } else { requestCameraPermission(); } gestureDetector = new GestureDetector(context, new CaptureGestureListener()); scaleGestureDetector = new ScaleGestureDetector(context, new ScaleListener()); // Snackbar.make(mGraphicOverlay, "Tap to Speak. Pinch/Stretch to zoom", // Snackbar.LENGTH_LONG) // .show(); // Set up the Text To Speech engine. TextToSpeech.OnInitListener listener = new TextToSpeech.OnInitListener() { @Override public void onInit(final int status) { if (status == TextToSpeech.SUCCESS) { Log.d("OnInitListener", "Text to speech engine started successfully."); tts.setLanguage(Locale.US); } else { Log.d("OnInitListener", "Error starting the text to speech engine."); } } }; tts = new TextToSpeech(activity.getApplicationContext(), listener); return view; }
From source file:com.eleybourn.bookcatalogue.BookEdit.java
/** * If we are passed a flatened book list, get it and validate it * /*from w w w.j a v a 2 s .c o m*/ * @param extras * @param savedInstanceState */ private void initBooklist(Bundle extras, Bundle savedInstanceState) { if (extras != null) { String list = extras.getString("FlattenedBooklist"); if (list != null && !list.equals("")) { mList = new FlattenedBooklist(mDbHelper.getDb(), list); // Check to see it really exists. The underlying table // disappeared once in testing // which is hard to explain; it theoretically should only happen // if the app closes // the database or if the activity pauses with 'isFinishing()' // returning true. if (mList.exists()) { int pos; if (savedInstanceState != null && savedInstanceState.containsKey("FlattenedBooklistPosition")) { pos = savedInstanceState.getInt("FlattenedBooklistPosition"); } else if (extras.containsKey("FlattenedBooklistPosition")) { pos = extras.getInt("FlattenedBooklistPosition"); } else { pos = 0; } mList.moveTo(pos); while (!mList.getBookId().equals(mRowId)) { if (!mList.moveNext()) break; } if (!mList.getBookId().equals(mRowId)) { mList.close(); mList = null; } else { // Add a gesture lister for 'swipe' gestures mGestureDetector = new GestureDetector(this, mGestureListener); } } else { mList.close(); mList = null; } } } }