[android-developers] Re: did someone implement a ScrollView with horizontal scroll support?

2009-03-12 Thread kolbysoft

Here is one Google made earlier, except they forgot to flip x/y. Took
about an hour to convert. :)
Oh, and it might not work with the 1.1 SDK, because of the attribute
set changes. It works fine with the 1.0 SDK.


Michael

/*
 * Copyright (C) 2006 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *  http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package your.package.here;

import java.lang.reflect.Field;
import java.util.List;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Rect;
import android.util.AttributeSet;
import android.util.Log;
import android.view.FocusFinder;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.VelocityTracker;
import android.view.View;
import android.view.ViewConfiguration;
import android.view.ViewGroup;
import android.view.ViewParent;
import android.view.animation.AnimationUtils;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.Scroller;
import android.widget.TextView;

/**
 * Layout container for a view hierarchy that can be scrolled by the
user,
 * allowing it to be larger than the physical display. A ScrollView is
a
 * {...@link FrameLayout}, meaning you should place one child in it
containing the
 * entire contents to scroll; this child may itself be a layout
manager with a
 * complex hierarchy of objects. A child that is often used is a
 * {...@link LinearLayout} in a vertical orientation, presenting a
vertical array
 * of top-level items that the user can scroll through.
 *
 * 
 * You should never use a ScrollView with a {...@link ListView}, since
ListView
 * takes care of its own scrolling. Most importantly, doing this
defeats all of
 * the important optimizations in ListView for dealing with large
lists, since
 * it effectively forces the ListView to display its entire list of
items to
 * fill up the infinite container supplied by ScrollView.
 *
 * 
 * The {...@link TextView} class also takes care of its own scrolling, so
does not
 * require a ScrollView, but using the two together is possible to
achieve the
 * effect of a text view within a larger container.
 *
 * 
 * ScrollView only supports vertical scrolling.
 */
public class HorizontalScrollView extends FrameLayout {

static final String TAG = "HScroll";

private static final int ANIMATED_SCROLL_GAP = 250;

/**
 * When arrow scrolling, ListView will never scroll more than this
factor
 * times the height of the list.
 */
private static final float MAX_SCROLL_FACTOR = 0.5f;

private long mLastScroll;

private final Rect mTempRect = new Rect();
private Scroller mScroller;

/**
 * Flag to indicate that we are moving focus ourselves. This is so
the code
 * that watches for focus changes initiated outside this ScrollView
knows that
 * it does not have to do anything.
 */
private boolean mScrollViewMovedFocus;

/**
 * Position of the last motion event.
 */
private float mLastMotionX;

/**
 * True when the layout has changed but the traversal has not come
through
 * yet. Ideally the view hierarchy would keep track of this for us.
 */
private boolean mIsLayoutDirty = true;

/**
 * The child to give focus to in the event that a child has requested
focus
 * while the layout is dirty. This prevents the scroll from being
wrong if the
 * child has not been laid out before requesting focus.
 */
private View mChildToScrollTo = null;

/**
 * True if the user is currently dragging this ScrollView around.
This is not
 * the same as 'is being flinged', which can be checked by
 * mScroller.isFinished() (flinging begins when the user lifts his
finger).
 */
private boolean mIsBeingDragged = false;

/**
 * Determines speed during touch scrolling
 */
private VelocityTracker mVelocityTracker;

/**
 * When set to true, the scroll view measure its child to make it
fill the
 * currently visible area.
 */
private boolean mFillViewport;

/**
 * Whether arrow scrolling is animated.
 */
private boolean mSmoothScrollingEnabled = true;

public HorizontalScrollView(Context context) {
super(cont

[android-developers] Re: did someone implement a ScrollView with horizontal scroll support?

2009-03-12 Thread kolbysoft

The code in setScrollXY is not called anywhere in the class, and was
old test code to get around the fact that some fields/methods are not
available in sub-classes in different packages.

It can be and should have been removed, but then again, who has time
for that?

Michael

On Mar 12, 1:44 pm, Romain Guy  wrote:
> Do NOT use this implementation. The setScrollXY() method changes field
> by reflection. Not only is it likely to break it's also VERY VERY
> inefficient. Especially given the lookup is done *every* single time.
> View already has methods to change the scroll X/Y values.
>

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers-unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~--~~~~--~~--~--~---



[android-developers] Re: startActivity Problem

2009-07-30 Thread kolbysoft

Thanks Yusuf,

that worked.
Still curious though, when did the startActivity behavior change? It
worked in an older project that was also 1.5.

Michael

On Jul 30, 11:52 am, "Yusuf T. Mobile" 
wrote:
> Try using startService() to start your service instead of startActivity
> ().
>
> Yusuf Saib
> Android
> ·T· · ·Mobile· stick together
> The views, opinions and statements in this email are those of the
> author solely in their individual capacity, and do not necessarily
> represent those of T-Mobile USA, Inc.
>
> On Jul 30, 8:06 am, kolby  wrote:
>
>
>
> > Hi all,
> > I'm trying to call a service directly, and I'm getting an
> > ActivityNotFoundException thrown.
>
> > My main class looks like this:
> > --- 
> > 
> >     @Override
> >     public void onCreate(Bundle savedInstanceState) {
> >         super.onCreate(savedInstanceState);
> >         PackageManager pm = getPackageManager();
> >         try {
> >           Log.i(TAG,"retrieving services:");
> >           PackageInfo pinfo = pm.getPackageInfo("test.another",
> > PackageManager.GET_ACTIVITIES | PackageManager.GET_SERVICES);
> >           for (ServiceInfo serv : pinfo.services) {
> >             Log.i(TAG,"declared service: "+serv.name);
> >             Log.i(TAG,"  package name: "+serv.packageName);
> >             Log.i(TAG,"  enabled: "+serv.enabled);
> >             Log.i(TAG,"  exported: "+serv.exported);
> >           }
> >         } catch (NameNotFoundException e) {
> >           // TODO Auto-generated catch block
> >           e.printStackTrace();
> >         }
>
> >         Intent i = new Intent();
> >         i.setClassName("test.another", "test.another.MyService");
> >         startActivity(i);
> >         setContentView(R.layout.main);
> >     }
> > --- 
> > --
>
> > My service is empty, minus some log messages:
>
> > --- 
> > -
> >   public void onCreate() {
> >     Log.i(T,"created");
> >   }
>
> >   public void onStart(Intent i, int code) {
> >     Log.i(T,"started");
> >   }
>
> >   @Override
> >   public IBinder onBind(Intent intent) {
> >     // TODO Auto-generated method stub
> >     return null;
> >   }
> > --- 
> > -
>
> > And the service is declared in the manifest file:
> > --- 
> > 
> > 
> > http://schemas.android.com/apk/res/android";
> >       package="test.another"
> >       android:versionCode="1"
> >       android:versionName="1.0">
> >     
> >          >                   android:label="@string/app_name">
> >             
> >                 
> >                  > android:name="android.intent.category.LAUNCHER" />
> >             
> >         
> >     
> > 
> >     
> > 
>
> > --- 
> > -
>
> > When I run it in either the emulator or on my phone, I get this log:
>
> > --- 
> > -
> > 07-30 10:56:52.676: INFO/main(1686): retrieving services:
> > 07-30 10:56:52.686: INFO/main(1686): declared service:
> > test.another.MyService
> > 07-30 10:56:52.686: INFO/main(1686):   package name: test.another
> > 07-30 10:56:52.696: INFO/main(1686):   enabled: true
> > 07-30 10:56:52.696: INFO/main(1686):   exported: false
> > 07-30 10:56:52.696: INFO/ActivityManager(56): Starting activity:
> > Intent { comp={test.another/test.another.MyService} }
> > 07-30 10:56:52.716: DEBUG/AndroidRuntime(1686): Shutting down VM
> > 07-30 10:56:52.716: WARN/dalvikvm(1686): threadid=3: thread exiting
> > with uncaught exception (group=0x4000fe70)
> > 07-30 10:56:52.716: ERROR/AndroidRuntime(1686): Uncaught handler:
> > thread main exiting due to uncaught exception
> > 07-30 10:56:52.746: DEBUG/dalvikvm(1622): GC freed 5960 objects /
> > 376680 bytes in 423ms
> > 07-30 10:56:52.746: ERROR/AndroidRuntime(1686):
> > java.lang.RuntimeException: Unable to start activity ComponentInfo
> > {test.another/test.another.Main}:
> > android.content.ActivityNotFoundException: Unable to find explicit
> > activity class {test.another/test.another.MyService}; have you
> > declared this activity in your AndroidManifest.xml?
> > 07-30 10:56:52.746: ERROR/AndroidRuntime(1686):     at
> > android.app.ActivityThread.performLaunchActivity(ActivityThread.java:
> > 2268)
> > 07-30 10:56:52.746: ERROR/AndroidRuntime(1686):     at
> > android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:
> > 2284)
> > 07-30