Android Wheel Widget

by Alessandro Crugnola on January 28, 2012

in android

Tweet

spacer

This is a simple widget I created as part of the Aviary Editor SDK for Android. It creates a wheel-like widet which can be scrolled in both directions.
The idea was to replace the default slider widget and use a more “real world” component.
Moreover if you’ll add the VIBRATE permission into your AndroidManifest.xml file you’ll have also haptics feedback while the wheel is scrolling:

1
<uses-permission android:name="android.permission.VIBRATE" />

To include the wheel widget in the current layout, you should add in the layout xml this lines:

1
2
3
4
5
6
7
<it.sephiroth.android.wheel.view.Wheel
android:id="@+id/wheel"
xmlns:sephiroth="schemas.android.com/apk/res/it.sephiroth.android.wheel"
android:layout_"match_parent"
android:layout_"match_parent"
sephiroth:numRotations="6"
sephiroth:ticks="28" />

Where numRotations is the max number of rotations the wheel can perform and ticks is the total number of ticks the wheel will display.

Then in your activity you can add a OnScrollListener listener to the wheel widget, in this way:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
mWheel = (Wheel) findViewById( R.id.wheel );
mWheel.setOnScrollListener( new OnScrollListener() {

@Override
public void onScrollStarted( Wheel view, float value, int roundValue ) {
}

@Override
public void onScrollFinished( Wheel view, float value, int roundValue ) {
}

@Override
public void onScroll( Wheel view, float value, int roundValue ) {
}
} );

You can download the source at the gihub project page.

Tagged as: android, github, widget

{ 6 comments }

Android Workspace Widget

by Alessandro Crugnola on November 1, 2011

in android

Tweet

 

spacer I was looking for an android widget similar to the launcher workspace widget ( the one used in almost all launchers ), but a bit more customizable and with the possibility to use an Adapter as content provider. So at the end I mixed portion of code from the android launcher Workspace widget, the Gallery widget and the AbsListView widget.

Nothing particular tricky, just a combination of the 3 widgets in order to have the same sliding effect of the workspace ( using custom number of columns and rows ), but at the same time with an ArrayAdapter for creating views, and a little glow effect at start at the end of scrolling for creating the gingerbread style overscroll effect.

This is the source code: workspace

It’s just a first version, so it’s not really optimized…

The adapter used for creating this example looks like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
class WorkspaceAdapter extends ArrayAdapter<applicationinfo> {

   int screenId;
   PackageManager pm;
   private LayoutInflater mInflater;
   private int nCellsPerScreen = 4;

   public WorkspaceAdapter( Context context, int textViewResourceId, List</applicationinfo><applicationinfo> objects ) {
      super( context, textViewResourceId, objects );
      screenId = textViewResourceId;
      pm = context.getPackageManager();
      nCellsPerScreen = context.getResources().getInteger( R.integer.config_portraitCells ) * context.getResources().getInteger( R.integer.config_portraitRows );
      mInflater = (LayoutInflater) context.getSystemService( LAYOUT_INFLATER_SERVICE );
   }

   @Override
   public int getCount() {
      return (int) Math.ceil( (double) super.getCount() / nCellsPerScreen );
   }

   public int getRealCount() {
      return super.getCount();
   }

   @Override
   public View getView( int position, View convertView, ViewGroup parent ) {

      if ( convertView == null ) {
         convertView = mInflater.inflate( screenId, mWorkspace, false );
         ((CellLayout)convertView).setNumCols( nCellsPerScreen );
      }

      CellLayout cell = (CellLayout) convertView;

      int index = position * nCellsPerScreen;
      int realCount = getRealCount();

      for ( int i = 0; i < nCellsPerScreen; i++ ) {
         CellInfo cellInfo = cell.findVacantCell( 1, 1 );
         TextView text;

         if ( cellInfo == null ) {
            text = (TextView) cell.getChildAt( i );
         } else {
            text = (TextView) mInflater.inflate( R.layout.application_boxed, cell, false );
            CellLayout.LayoutParams lp = new CellLayout.LayoutParams( cellInfo.cellX, cellInfo.cellY, cellInfo.spanH,
                  cellInfo.spanV );
            cell.addView( text, i, lp );
         }

         if ( index + i < realCount ) {
            ApplicationInfo appInfo = getItem( index + i );
            CharSequence label = appInfo.loadLabel( pm );
            Drawable bm = appInfo.loadIcon( pm );

            text.setCompoundDrawablesWithIntrinsicBounds( null, bm, null, null ); // new
            text.setText( label );
            text.setClickable( true );
            text.setFocusable( true );
            text.setVisibility( View.VISIBLE );
         } else {
            text.setVisibility( View.INVISIBLE );
         }
      }
      return convertView;
   }
}

 

Tagged as: android, gallery, widget, workspace

{ 1 comment }

Compile skia for android on Mac Lion

by Alessandro Crugnola on October 17, 2011

in android, general

Tweet

Some time ago I started to look at skia as possible solution for graphics 2D editing for a native android project I was developing.
Well, even if skia is part of the android system and it’s used everywhere by android itself, trying to include skia in my project was quite an hell..
Looking for resources I just found old examples and tips, and every try was just a failure.. but since android uses skia internally to do graphics operations I decided to look into the android project.

After downloading the skia module from the android git repository I just realized it couldn’t be compiled by itself because it has external dependencies. So next step was to download and compile the whole android source code. Easy task? not at all, at least if you’re on a mac running Lion!

At the end I managed to compile everything and build the skia module as static module, in this way now my project can link the skia library and include correctly the skia headers.

Ok, I don’t have the whole procedure step by step here, first of all because it depends on the android version you’re going to compiled, second and most important because I didn’t write down all the steps spacer So this is more a sort of list of notes about compiling android on Lion and a reminder for myself too. ( I was trying to compile android 2.2 using “generic-user” as lunch configuration )

Build Android: source.android.com/source/initializing.html

To get rid of clearsilver errors: code.google.com/p/android/issues/detail?id=993#c27

Java 1.5 version complaining: wiki.oneswarm.org/index.php/OS_X_10.6_Snow_Leopard

Well, the first time you’ll try to “make” everything probably you’ll get this error:

1
./external/elfutils/config-compat-darwin.h:42: error: static declaration of ‘strnlen’ follows non-static declaration

modify ./external/elfutils/config-compat-darwin.h.
replace:

1
2
3
4
5
6
7
static inline size_t strnlen (const char *__string, size_t __maxlen)
{
int len = 0;
while (__maxlen-- && *__string++)
len++;
return len;
}

with:

1
2
3
4
5
6
7
8
9
#if 0
static inline size_t strnlen (const char *__string, size_t __maxlen)
{
int len = 0;
while (__maxlen-- && *__string++)
len++;
return len;
}
#endif

Well, at the end of the process I just edited the Android.mk makefile into external/skia adding a new entry for BUILD_STATIC_LIBRARY and the next command was simply:

1
mmm external/skia

which produced the required libskia.a file to be linked in my project.

Tagged as: android, java, lion, skia

{ 0 comments }

Aviary is hiring!

16 September 2011

Are you a ASP.NET developer in NYC? If so you may be interested: bit.ly/oPZxzE  

Tagged as: aviary, jobs, nyc

Read the full article →

QuickActionView in Android

9 July 2011

While I was searching for an custom implementation of the QuickContactBadge for Android, I went into this interesting post ( Lorenz’s Blog ), which had a custom widget called QuickAction. While it’s a very nice widget, it didn’t fit my needs because I had the necessity of create different action layouts ( horizontal, vertical, grid.. [...]

Tagged as: quickaction, quickcontact badge

Read the full article →

FBTracer updated to Firefox 5

2 July 2011

FBTracer aka Flash Tracer has been just updated to version 0.1.3 ( also thanks to Daniel D. Vanzin ) which is now compatible with the new Firefox 5. If you already have the extension installed it’s just a matter of check updates from the addons firefox page, otherwise you can download the extension from this [...]

Tagged as: extensions, fbtracer, firefox

Read the full article →

ImageView Zoom and Scroll

4 April 2011

Update: the source code has moved to github, so it’s easier for anyone to fork it! As long as Android doesn’t have a built-in ImageView widget with zoom and scroll capabilities I tries to create one by myself starting from the google repository. The result is pretty nice so I’m posting here the source code, [...]

Tagged as: android, github, image, ImageView, scroll, zoom

Read the full article →

Widget: SlidingDrawer top to bottom

29 March 2011

My android experiments continue… In the last project I had to implement a SlidingDrawer which comes from top and left. The problem was that the default widget does not support all the directions, but only bottom to top and right to left. That’s why I grabbed the SlidingDrawer source code and modified it in order [...]

Tagged as: android, sliding drawer, widget

Read the full article →

← Previous Entries

gipoco.com is neither affiliated with the authors of this page nor responsible for its contents. This is a safe-cache copy of the original web site.