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.

Thursday, August 15, 2013

Difference between px, dp, dip and sp in Android?



px
  • Pixels - corresponds to actual pixels on the screen.

in
  • Inches - based on the physical size of the screen.

mm
  • Millimeters - based on the physical size of the screen.

pt
  • Points - 1/72 of an inch based on the physical size of the screen.

dp
  • Density-independent Pixels - an abstract unit that is based on the physical density of the screen. These units are relative to a 160 dpi screen, so one dp is one pixel on a 160 dpi screen. The ratio of dp-to-pixel will change with the screen density, but not necessarily in direct proportion. Note: The compiler accepts both "dip" and "dp", though "dp" is more consistent with "sp".

sp
  • Scale-independent Pixels - this is like the dp unit, but it is also scaled by the user's font size preference. It is recommend you use this unit when specifying font sizes, so they will be adjusted for both the screen density and user's preference.


Monday, May 13, 2013

ListExpandableView

ListExpandableView:

Implementation:

listview_row.xml:
  • In listview_row xml file we have two relative layout. 1.- rel_top_layout and 2. - rel_bottom_layout
  • ByDefault bottom layout visibility is gone and top layout is visible.

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 :