Android Views

AndroidViews is a regularly updated database, gathering different open source Custom Android UI Views, interaction patterns, libraries and tools.

Android Asset Studio

Android Asset Studio is a collection of tools for android icon generation, Actionbar style generator, Holo colors generator,etc.

Friday, August 31, 2012

HTML5 eBook Friar Framework For Android


About Friar:
  • Friar is an HTML5 eBook framework to publish interactive books on Android devices using simply open web standards.
  • The Friar Framework is a tool for generating Android ebook apps. It is based on and inspired by the Baker Framework for iOS (www.bakerframework.com) and the name is sort of a play on words.

Friday, August 24, 2012

The wheel widget for Android:


Introduction:
  • You can use wheel widget for country,state,date,time selection.you can use this wheel control in your project. You have to include WheelLibrary as a library for run this project.

Usage:
  • In this project there are six main class.
1) CitiesActivity : * This class is use for city selection on the base of selected country. We use one wheelview for country and set CountryAdapter in this view.
final WheelView country = (WheelView) findViewById(R.id.country);
country.setVisibleItems(3);
country.setViewAdapter(new CountryAdapter(this));
  • Here we use another wheelview for city.When we change and scroll country wheel than updateCities(city, cities, newValue) function will be called in which cities will be list out on the base of selected country.
country.addChangingListener(new OnWheelChangedListener() {
public void onChanged(WheelView wheel, int oldValue, int newValue) {
if (!scrolling) {
updateCities(city, cities, newValue);
}
}
});
country.addScrollingListener( new OnWheelScrollListener() {
public void onScrollingStarted(WheelView wheel) {
scrolling = true;
}
public void onScrollingFinished(WheelView wheel) {
scrolling = false;
updateCities(city, cities, country.getCurrentItem());
}
});
Updates the city wheel
private void updateCities(WheelView city, String cities[][], int index) {
ArrayWheelAdapter<String> adapter =
new ArrayWheelAdapter<String>(this, cities[index]);
adapter.setTextSize(18);
city.setViewAdapter(adapter);
city.setCurrentItem(cities[index].length / 2);
}

2) DateActivity :

  • In this activity we use three wheelview for day,year and month.

final WheelView month = (WheelView) findViewById(R.id.month);
final WheelView year = (WheelView) findViewById(R.id.year);
final WheelView day = (WheelView) findViewById(R.id.day);
  • we use DateArrayAdapter for month and DateNumericAdapter for year and day.When we change and scroll wheelview than OnWheelChangedListener() will be called in which we specify updateDays(year, month, day) .this function set max days according to selected month and year.

void updateDays(WheelView year, WheelView month, WheelView day) {
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.YEAR, calendar.get(Calendar.YEAR) + year.getCurrentItem());
calendar.set(Calendar.MONTH, month.getCurrentItem());
int maxDays = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
day.setViewAdapter(new DateNumericAdapter(this, 1, maxDays, calendar.get(Calendar.DAY_OF_MONTH) - 1));
int curDay = Math.min(maxDays, day.getCurrentItem() + 1);
day.setCurrentItem(curDay - 1, true);
}
3) PasswActivity:
  • When we change and scroll wheelview than OnWheelChangedListener() will be called in which we specify updateStatus().this function check whichever number selected is true or not.

private void updateStatus() {
TextView text = (TextView) findViewById(R.id.pwd_status);
if (testPin(2, 4, 6, 1)) {
text.setText("Congratulation!");
} else {
text.setText("Invalid PIN");
}
}
private boolean testPin(int v1, int v2, int v3, int v4) {
return testWheelValue(R.id.passw_1, v1) && testWheelValue(R.id.passw_2, v2) &&
testWheelValue(R.id.passw_3, v3) && testWheelValue(R.id.passw_4, v4);
}
4) SlotMachineActivity:
  • This activity do same functionality like PasswActivity done.
5) Time2Activity:
  • This activity do same functionality like DateActivity done.Additional code is for time selection.
6) TimeActivity:
  • This activity do same functionality like Time2Activity but here we just select time.we can not select date.
Reference Link:
http://code.google.com/p/android-wheel/










Pedometer For Android:


Introduction:


  • Pedometer is an application, that counts your steps.

Features:

  • It has an option to notify you by voice in given intervals about any value. You can set a desired pace/speed and get notified when you have to go faster or slower.
  • There are more options available under menu. Steps Pedometer lets you set modes for either walking or running.
  • You can customize your body weight, Stride length; you can set the step sensitivity settings to match your walking or run style.
  • Step pedometer also gives you a detailed display of the miles you have walked or ran and most of all shows you the calories you have burned.

Limitations & tips:

  • If not accurate,* try adjusting the sensitivity setting*. Works best when attached firmly to your body.
  • On some phones it can't count the steps when the Screen is off,Stry tweaking the "Operational level" setting if this happens.
  • Not suitable for all day use, as it consumes power constantly.
  • You can download project from here

 


Check internet connection in android:


Introduction:

  • If you want to check internet connection in device than follow below steps.

Steps:

  • You have to simply put isNetworkAvailable() function in to your class file.
/**
* Checking whether net connection is available or not.
* @param nContext
* @return true if net connection is avaible otherwise false
*/
public static boolean isNetworkAvailable(Context nContext) {
boolean isNetAvailable = false;
if (nContext != null) {
ConnectivityManager mConnectivityManager = (ConnectivityManager) nContext
.getSystemService(Context.CONNECTIVITY_SERVICE);

if (mConnectivityManager != null) {
boolean mobileNetwork = false;
boolean wifiNetwork = false;

boolean mobileNetworkConnecetd = false;
boolean wifiNetworkConnecetd = false;

NetworkInfo mobileInfo = mConnectivityManager
.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
NetworkInfo wifiInfo = mConnectivityManager
.getNetworkInfo(ConnectivityManager.TYPE_WIFI);

if (mobileInfo != null)
mobileNetwork = mobileInfo.isAvailable();

if (wifiInfo != null)
wifiNetwork = wifiInfo.isAvailable();

if (wifiNetwork == true || mobileNetwork == true) {
mobileNetworkConnecetd = mobileInfo
.isConnectedOrConnecting();
wifiNetworkConnecetd = wifiInfo.isConnectedOrConnecting();
}

isNetAvailable = (mobileNetworkConnecetd || wifiNetworkConnecetd);
}
}
return isNetAvailable;
}

  • Please provide internet permission in your AndroidManifest file.

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

For Open Internet Setting Screen:

  • Now if there is no internet connection available and you want to navigate on intenet setting screen of your device than use below code.
Intent intent = new Intent(Settings.ACTION_WIRELESS_SETTINGS);
startActivityForResult(intent, 11);



Thursday, August 23, 2012

GestureImageView For Android:


Introduction:
  • > This is a simple Android View class which provides basic pinch and zoom capability for images.
  • > Can be used as a replacement for a standard ImageView when you want to include pinch and zoom.
Features:
  • > Pinch zoom in place (i.e. zoom occurs from point of touch)
  • > Panning with fling gesture
  • > Double tap zoom
  • > Configurable zoom boundaries (min/max)
Limitations:
  • > Does not support Rotation
  • > Does not support Pan and Zoom together
  • > Not all methods of ImageView class are supported (will throw UnsupportedOperationException if strict is true)
Usage:
  • You have to include GestureImageviewLibrary as a library for run this project.
  • Configured as View in layout.xml :
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:gesture-image="http://schemas.polites.com/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<com.polites.android.GestureImageView
android:id="@+id/image"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:src="@drawable/image"
gesture-image:min-scale="0.1"
gesture-image:max-scale="10.0"
gesture-image:strict="false"/>
</LinearLayout>
  • Configured Programmatically:
import com.polites.android.GestureImageView;
import android.app.Activity;
import android.os.Bundle;
import android.view.ViewGroup;
import android.widget.LinearLayout.LayoutParams; public class SampleActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
LayoutParams params = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
GestureImageView view = new GestureImageView(this);
view.setImageResource(R.drawable.image);
view.setLayoutParams(params);
ViewGroup layout = (ViewGroup) findViewById(R.id.layout);
layout.addView(view);
}
}
Reference Link:
You can download SourceCode from below links :

Swipe To Dismiss ListView For Android:

Introduction:

Here I am sharing a code to perform delete operation on listview  by just swiping it to right or left.

 
















  • Keep in mind this thing will only work in 4.0 or above. First Download the Demo from here.
  • After extracting the zip you will find three class file in src project.

1) Main Activity

  • The Class which displays the view to user and also has listener implementation on button and listview.

2) SwipeDismissTouchListener

  • This class is responsible to listen swipe over the button’s object.
dismissableButton.setOnTouchListener(new SwipeDismissTouchListener(
 dismissableButton,
 null,
 new SwipeDismissTouchListener.OnDismissCallback() {
 @Override
 public void onDismiss(View view, Object token) {
 dismissableContainer.removeView(dismissableButton);
 }
 }));

3) SwipeDismissListViewTouchListener

  • This class is responsible to listen swipe over the listview’s item object. In below code snippet just check that we are passing listview object while constructing an object of this class.
SwipeDismissListViewTouchListener touchListener =
new SwipeDismissListViewTouchListener(
listView,
new SwipeDismissListViewTouchListener.OnDismissCallback() {
@Override
public void onDismiss(ListView listView, int[] reverseSortedPositions) {
for (int position : reverseSortedPositions) {
myAdapter.remove(myAdapter.getItem(position));
}
myAdapter.notifyDataSetChanged();
}
});

  • Both SwipeDismissTouchListener and SwipeDismissListViewTouchListener implements OnTouchListener which listens every touch on particular views.
  • You can also download source code from here.

Pin Progress For Android:


Introduction:
  • Custom indicator that could show all of the information in a tiny footprint.




  • The color indicates whether it's downloaded (blue) or not (gray). The appearance of the pin indicates whether the download is permanent (white, upright) or temporary (gray, diagonal). And when state is in the process of changing, progress is indicated by a moving pie chart.
  • We can use this pie chart to show our progress instead of progress bar, it takes minimum space to show & flexibility to appear on top of the downloading content.


Reference Link:


Wednesday, August 22, 2012

ColorMixer For Android:


Introduction:

Sometimes, you want your users to pick a color. A simple approach is to give the user a fixed roster of a handful of colors -- easy, but limited. A fancy approach is to use some form of color wheel, but these can be difficult to use on a touchscreen and perhaps impossible without a touchscreen.
ColorMixer is a widget that provides a simple set of SeekBars to let the user mix red, green, and blue to pick an arbitrary color. It is not very big, so it is easy to fit on a form, and it is still fairly finger-friendly.
It is also packaged as a dialog (ColorMixerDialog), a dialog-themed activity (ColorMixerActivity), and a preference (ColorPreference).

Usage:

  • ColorMixer:
ColorMixer is a simple widget. Given that you have the parcel installed in your project, or have manually merged the source and resources into your project, you can add the widget to a layout like any other:
<com.commonsware.cwac.colormixer.ColorMixer
android:id="@+id/mixer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
You can call getColor() and setColor() to manipulate the color at runtime. You can also call setOnColorChangedListener() to register a ColorMixer.OnColorChangedListener object, which will be called with onColorChanged() when the color is altered by the user.
  • ColorMixerDialog:
ColorMixerDialog is an AlertDialog subclass. Hence, to create and show the dialog, all you need to do is create an instance and show() it:
new ColorMixerDialog(this, someColor, onDialogSet).show();
In the above code snippet, this is a Context (e.g., an Activity), someColor is the color you want to start with, and onDialogSet is a ColorMixer.OnColorChangedListener that will be notified if the user clicks the "Set" button on the dialog and has changed the color from the initial value.
  • ColorMixerActivity:
ColorMixerActivity is a dialog-themed Activity. This is useful for situations where you want a dialog but do not want to deal with a dialog.
To use it, add it as an activity to your project. You will need to use the full package in your <activity> element, marking it as using Theme.Dialog. Here is one implementation, from the demo/ project:
<activity android:name="com.commonsware.cwac.colormixer.ColorMixerActivity"
android:label="@string/app_name"
android:theme="@android:style/Theme.Dialog">
</activity>
In the Intent you use to start the activity, you can supply the starting color via a ColorMixerActivity.COLOR integer extra, and the dialog title via a ColorMixerActivity.TITLE string extra. For example:
Intent i=new Intent(this, ColorMixerActivity.class);
i.putExtra(ColorMixerActivity.TITLE, "Pick a Color");
i.putExtra(ColorMixerActivity.COLOR, mixer.getColor());
startActivityForResult(i, COLOR_REQUEST);
  • ColorPreference:
ColorPreference is a Preference class, to be referenced in preference XML and loaded into a PreferenceActivity. It has no attributes beyond the standard ones.
<PreferenceScreen
xmlns:android="http://schemas.android.com/apk/res/android">
<com.commonsware.cwac.colormixer.ColorPreference
android:key="favoriteColor"
android:defaultValue="0xFFA4C639"
android:title="Your Favorite Color"
</PreferenceScreen>
The preference is stored as an integer under the key you specify in the XML.
  • Dependencies:
This depends upon the cwac-parcel library for accessing project-level resources Which is already included in ColorMixer Library. Include ColorMixerLibrary.

  • Reference Link:
     https://github.com/commonsguy/cwac-colormixer/downloads


Tuesday, August 21, 2012

Audalyzer For Android:



Introduction :
It displays sound readings from the microphone as a waveform display, as a frequency spectrum, and as a dB meter. dB levels are relative to the maximum input level of your device.

Since microphone sensitivity varies between individual devices, let alone models, it's impossible to generate accurate sound level readings with this app; so all data should be taken with a pinch of salt. Still, it may be interesting when used to compare sound readings at different locations.

Decibel (dB) scales are logarithmic, which means that each unit on the scale is a multiple of the underlying unit. So, 0dB represents some "base" level; 10dB is 10 times this level; 20dB is 100 times; etc. If the base level is a zero input signal, then 10dB is 10 times this, which is also zero; 20dB would be 100 times zero, also zero; etc. In other words, an actual zero input can't be represented. So the base level has to be some other value. There is no minimum input signal; but there is a maximum, where the input is fully saturated. So we choose this as the base -- 0dB -- and other values are derived from this. Hence -10dB means 1/10th of the maximum, -20dB is 1/100th, etc.

You need to include two libraries for run this project : 1) HermitAndroid 2) HermitLibrary

Features :
Displays waveform, frequency spectrum, and dB meter.
Meter shows instantaneous, average, and peak values.



Reference link :
http://code.google.com/p/moonblink/wiki/Audalyzer