Android Studio 1.5 is now available to download from the stable release channel.
Find out more from Android Developers Blog: http://goo.gl/oIbJHO
package com.example.androidflipview;
import android.animation.ObjectAnimator;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
public class MainActivity extends AppCompatActivity {
Button buttonFlipX, buttonFlipY;
ImageView imageView;
boolean dirX = true;
boolean dirY = true;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
imageView = (ImageView)findViewById(R.id.image);
buttonFlipX = (Button)findViewById(R.id.buttonflipX);
buttonFlipY = (Button)findViewById(R.id.buttonflipY);
buttonFlipX.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v) {
if(dirX){
dirX = false;
buttonFlipX.setText("Flip X Backward");
ObjectAnimator flip = ObjectAnimator.ofFloat(imageView, "rotationX", 0f, 180f);
flip.setDuration(500);
flip.start();
}else{
dirX = true;
buttonFlipX.setText("Flip X Forward");
ObjectAnimator flip = ObjectAnimator.ofFloat(imageView, "rotationX", 180f, 0f);
flip.setDuration(1000);
flip.start();
}
}
});
buttonFlipY.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v) {
if(dirY){
dirY = false;
buttonFlipY.setText("Flip Y Backward");
ObjectAnimator flip = ObjectAnimator.ofFloat(imageView, "rotationY", 0f, 180f);
flip.setDuration(2000);
flip.start();
}else{
dirY = true;
buttonFlipY.setText("Flip Y Forward");
ObjectAnimator flip = ObjectAnimator.ofFloat(imageView, "rotationY", 180f, 0f);
flip.setDuration(3000);
flip.start();
}
}
});
}
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">
a
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="android-coding.blogspot.com"
android:textSize="28dp"
android:textStyle="bold" />
<Button
android:id="@+id/buttonflipX"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Flip X Forward" />
<Button
android:id="@+id/buttonflipY"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Flip Y Forward" />
<ImageView
android:id="@+id/image"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@mipmap/ic_launcher" />
</LinearLayout>
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<!--
Base application theme, dependent on API level. This theme is replaced
by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
-->
<style name="AppBaseTheme" parent="Theme.AppCompat.Light">
<!--
Theme customizations available in newer API levels can go in
res/values-vXX/styles.xml, while customizations related to
backward-compatibility can go here.
-->
</style>
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
</style>
<style name="LargeRedText" parent="@android:style/TextAppearance.Large">
<item name="android:textColor">#FF0000</item>
</style>
<style name="InverseMediumBlueText" parent="@android:style/TextAppearance.Medium.Inverse">
<item name="android:background">#0000FF</item>
</style>
<style name="GreenText" parent="@android:style/TextAppearance">
<item name="android:textColor">#00FF00</item>
</style>
<style name="ItalicGrayText" parent="@android:style/TextAppearance">
<item name="android:textColor">#A0A0A0</item>
<item name="android:textStyle">italic</item>
</style>
<style name="Bold50BlackText">
<item name="android:textColor">#000000</item>
<item name="android:textStyle">bold</item>
<item name="android:textSize">50dp</item>
</style>
</resources>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.example.androidtextappearance.MainActivity" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="android-coding.blogspot.com"
android:textSize="24dp"
android:textStyle="bold" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="textAppearance"
android:textAppearance="?android:textAppearance" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="textAppearanceLarge"
android:textAppearance="?android:textAppearanceLarge" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="textAppearanceMedium"
android:textAppearance="?android:textAppearanceMedium" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="textAppearanceSmall"
android:textAppearance="?android:textAppearanceSmall" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="custom style LargeRedText"
style="@style/LargeRedText" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="custom style InverseMediumBlueText"
style="@style/InverseMediumBlueText" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="custom style GreenText"
style="@style/GreenText" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="custom style ItalicGrayText"
style="@style/ItalicGrayText" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="custom style Bold50BlackText"
style="@style/Bold50BlackText" />
</LinearLayout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.example.androidtextappearance.MainActivity" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="android-coding.blogspot.com"
android:textSize="24dp"
android:textStyle="bold" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="textAppearance"
android:textAppearance="?android:textAppearance" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="textAppearanceLarge"
android:textAppearance="?android:textAppearanceLarge" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="textAppearanceMedium"
android:textAppearance="?android:textAppearanceMedium" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="textAppearanceSmall"
android:textAppearance="?android:textAppearanceSmall" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="textAppearanceInverse"
android:textAppearance="?android:textAppearanceInverse" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="textAppearanceLargeInverse"
android:textAppearance="?android:textAppearanceLargeInverse" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="textAppearanceMediumInverse"
android:textAppearance="?android:textAppearanceMediumInverse" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="textAppearanceSmallInverse"
android:textAppearance="?android:textAppearanceSmallInverse" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/darker_gray"
android:text="textAppearanceInverse"
android:textAppearance="?android:textAppearanceInverse" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/darker_gray"
android:text="textAppearanceLargeInverse"
android:textAppearance="?android:textAppearanceLargeInverse" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/darker_gray"
android:text="textAppearanceMediumInverse"
android:textAppearance="?android:textAppearanceMediumInverse" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/darker_gray"
android:text="textAppearanceSmallInverse"
android:textAppearance="?android:textAppearanceSmallInverse" />
</LinearLayout>
package com.example.androidvideoview;
import java.io.File;
import android.support.v7.app.ActionBarActivity;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.MediaController;
import android.widget.Toast;
import android.widget.ToggleButton;
import android.widget.VideoView;
import android.os.Bundle;
import android.os.Environment;
public class MainActivity extends ActionBarActivity {
ToggleButton enableMediaController;
VideoView myVideoView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
enableMediaController = (ToggleButton)findViewById(R.id.enableMediaController);
myVideoView = (VideoView)findViewById(R.id.myvideoview);
myVideoView.setVideoPath(getViewSrc());
myVideoView.requestFocus();
myVideoView.start();
setMediaController();
enableMediaController.setOnCheckedChangeListener(new OnCheckedChangeListener(){
@Override
public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked) {
setMediaController();
}});
}
private void setMediaController(){
if(enableMediaController.isChecked()){
myVideoView.setMediaController(new MediaController(this));
}else{
myVideoView.setMediaController(null);
}
}
private String getViewSrc(){
File extStorageDirectory = Environment.getExternalStorageDirectory();
String s = extStorageDirectory.getAbsolutePath() + "/test.mp4";
Toast.makeText(MainActivity.this, s, Toast.LENGTH_SHORT).show();
return s;
}
}
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.androidvideoview.MainActivity" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="android-coding.blogspot.com"
android:textSize="24dp"
android:textStyle="bold" />
<ToggleButton
android:id="@+id/enableMediaController"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textOn="Disable MediaController"
android:textOff="Enable MediaController"
android:checked="true"/>
<VideoView
android:id="@+id/myvideoview"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</LinearLayout>
package com.example.androidfront;
import android.support.v7.app.ActionBarActivity;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.EditText;
import android.widget.Spinner;
import android.graphics.Typeface;
import android.os.Bundle;
public class MainActivity extends ActionBarActivity {
String typeFaceName[] = {
"sans-serif",
"sans-serif-light",
"sans-serif-condensed",
"sans-serif-thin",
"sans-serif-medium"};
CheckBox checkBold, checkItalic;
Spinner selTypeFace;
EditText editArea;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
editArea = (EditText)findViewById(R.id.editarea);
checkBold = (CheckBox)findViewById(R.id.boldsel);
checkBold.setOnCheckedChangeListener(new OnCheckedChangeListener(){
@Override
public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked) {
updateFonts();
}});
checkItalic = (CheckBox)findViewById(R.id.italicsel);
checkItalic.setOnCheckedChangeListener(new OnCheckedChangeListener(){
@Override
public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked) {
updateFonts();
}});
selTypeFace = (Spinner)findViewById(R.id.typefacesel);
ArrayAdapter<String> adapter =
new ArrayAdapter<String>(this,
android.R.layout.simple_spinner_item, typeFaceName);
adapter.setDropDownViewResource(
android.R.layout.simple_spinner_dropdown_item);
selTypeFace.setAdapter(adapter);
selTypeFace.setOnItemSelectedListener(new OnItemSelectedListener(){
@Override
public void onItemSelected(AdapterView<?> parent, View view,
int position, long id) {
updateFonts();
}
@Override
public void onNothingSelected(AdapterView<?> parent) {}});
}
private void updateFonts(){
int tfSel = selTypeFace.getSelectedItemPosition();
String selTypeFaceName = typeFaceName[tfSel];
int style;
if(!checkBold.isChecked() && !checkItalic.isChecked()){
style = Typeface.NORMAL;
}else if(checkBold.isChecked() && !checkItalic.isChecked()){
style = Typeface.BOLD;
}else if(!checkBold.isChecked() && checkItalic.isChecked()){
style = Typeface.ITALIC;
}else{
style = Typeface.BOLD_ITALIC;
}
Typeface tf = Typeface.create(selTypeFaceName, style);
editArea.setTypeface(tf);
}
}
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.androidfront.MainActivity"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="android-coding.blogspot.com"
android:textSize="24dp"
android:textStyle="bold" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical" >
<TextView
android:fontFamily="sans-serif"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/test"/>
<TextView
android:fontFamily="sans-serif-light"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/test"/>
<TextView
android:fontFamily="sans-serif-condensed"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/test"/>
<TextView
android:fontFamily="sans-serif-thin"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/test"/>
<TextView
android:fontFamily="sans-serif-medium"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/test"/>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical" >
<Spinner
android:id="@+id/typefacesel"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<CheckBox
android:id="@+id/boldsel"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="BOLD"/>
<CheckBox
android:id="@+id/italicsel"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="ITALIC"/>
<EditText
android:id="@+id/editarea"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:singleLine="false"
android:gravity="top"
android:background="#E0E0E0"/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
package com.example.androidfront;
import android.support.v7.app.ActionBarActivity;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.EditText;
import android.widget.Spinner;
import android.graphics.Typeface;
import android.os.Bundle;
public class MainActivity extends ActionBarActivity {
String typeFaceName[] = {
"DEFAULT",
"DEFAULT_BOLD",
"MONOSPACE",
"SANS_SERIF",
"SERIF"};
Typeface typeFace[] = {
Typeface.DEFAULT,
Typeface.DEFAULT_BOLD,
Typeface.MONOSPACE,
Typeface.SANS_SERIF,
Typeface.SERIF};
CheckBox checkBold, checkItalic;
Spinner selTypeFace;
EditText editArea;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
editArea = (EditText)findViewById(R.id.editarea);
checkBold = (CheckBox)findViewById(R.id.boldsel);
checkBold.setOnCheckedChangeListener(new OnCheckedChangeListener(){
@Override
public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked) {
updateFonts();
}});
checkItalic = (CheckBox)findViewById(R.id.italicsel);
checkItalic.setOnCheckedChangeListener(new OnCheckedChangeListener(){
@Override
public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked) {
updateFonts();
}});
selTypeFace = (Spinner)findViewById(R.id.typefacesel);
ArrayAdapter<String> adapter =
new ArrayAdapter<String>(this,
android.R.layout.simple_spinner_item, typeFaceName);
adapter.setDropDownViewResource(
android.R.layout.simple_spinner_dropdown_item);
selTypeFace.setAdapter(adapter);
selTypeFace.setOnItemSelectedListener(new OnItemSelectedListener(){
@Override
public void onItemSelected(AdapterView<?> parent, View view,
int position, long id) {
updateFonts();
}
@Override
public void onNothingSelected(AdapterView<?> parent) {}});
}
private void updateFonts(){
int tfSel = selTypeFace.getSelectedItemPosition();
Typeface tf = typeFace[tfSel];
editArea.setTypeface(tf);
int style;
if(!checkBold.isChecked() && !checkItalic.isChecked()){
style = Typeface.NORMAL;
}else if(checkBold.isChecked() && !checkItalic.isChecked()){
style = Typeface.BOLD;
}else if(!checkBold.isChecked() && checkItalic.isChecked()){
style = Typeface.ITALIC;
}else{
style = Typeface.BOLD_ITALIC;
}
editArea.setTypeface(tf, style);
}
}
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.androidfront.MainActivity"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="android-coding.blogspot.com"
android:textSize="24dp"
android:textStyle="bold" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical" >
<TextView
android:typeface="normal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/test"/>
<TextView
android:typeface="monospace"
android:textStyle="bold"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/test"/>
<TextView
android:typeface="sans"
android:textStyle="italic"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/test"/>
<TextView
android:typeface="serif"
android:textStyle="bold|italic"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/test"/>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical" >
<Spinner
android:id="@+id/typefacesel"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<CheckBox
android:id="@+id/boldsel"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="BOLD"/>
<CheckBox
android:id="@+id/italicsel"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="ITALIC"/>
<EditText
android:id="@+id/editarea"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:singleLine="false"
android:gravity="top"
android:background="#E0E0E0"/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">AndroidFront</string>
<string name="hello_world">Hello world!</string>
<string name="action_settings">Settings</string>
<string name="test">ABCDEfghijKLMNOpqrstUVWXYz1234567890</string>
</resources>
package com.example.androidcpuinfo;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.widget.TextView;
public class MainActivity extends ActionBarActivity {
TextView cores, cpuinfo;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
cores = (TextView)findViewById(R.id.cores);
cpuinfo = (TextView)findViewById(R.id.cpuinfo);
Runtime runtime = Runtime.getRuntime();
int availableProcessors = runtime.availableProcessors();
cores.setText("You have " + availableProcessors + " availableProcessors");
//Read text file "/proc/cpuinfo"
String file_cpuinfo = "/proc/cpuinfo";
String info = "";
try {
FileReader fileReader = new FileReader(file_cpuinfo);
BufferedReader bufferReader = new BufferedReader(fileReader);
String line;
try {
while((line = bufferReader.readLine()) != null)
{
info += line + "\n";
}
cpuinfo.setText(info);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.androidcpuinfo.MainActivity" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="android-coding.blogspot.com"
android:textSize="24dp"
android:textStyle="bold" />
<TextView
android:id="@+id/cores"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20dp"
android:textStyle="italic" />
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:id="@+id/cpuinfo"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</ScrollView>
</LinearLayout>
package com.example.androidmirrorimage;
import android.support.v7.app.ActionBarActivity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Matrix;
import android.os.Bundle;
import android.widget.ImageView;
public class MainActivity extends ActionBarActivity {
ImageView image1, image2;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
image1 = (ImageView) findViewById(R.id.image1);
image2 = (ImageView) findViewById(R.id.image2);
Bitmap bm = BitmapFactory.decodeResource(getResources(),
R.drawable.ic_launcher);
image1.setImageBitmap(bm);
image2.setImageBitmap(getMirrorBitmap(bm));
}
private Bitmap getMirrorBitmap(Bitmap src) {
Matrix matrix = new Matrix();
matrix.preScale(1, -1);
Bitmap result = Bitmap.createBitmap(
src, 0, 0, src.getWidth(), src.getHeight(), matrix, false);
return result;
}
}
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.androidmirrorimage.MainActivity" >
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="android-coding.blogspot.com"
android:textSize="28dp"
android:textStyle="bold" />
<ImageView
android:id="@+id/image1"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" />
<ImageView
android:id="@+id/image2"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" />
</LinearLayout>
package com.example.androidtouchimageview;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapShader;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Shader;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.widget.ImageView;
public class TouchImageView extends ImageView {
private float radius = 0;
private Paint paint = null;
private float x;
private float y;
private boolean touched = false;
public TouchImageView(Context context) {
super(context);
// TODO Auto-generated constructor stub
}
public TouchImageView(Context context, AttributeSet attrs) {
super(context, attrs);
// TODO Auto-generated constructor stub
}
public TouchImageView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
// TODO Auto-generated constructor stub
}
@Override
public boolean onTouchEvent(MotionEvent event) {
int action = event.getAction();
touched = (action == MotionEvent.ACTION_DOWN
|| action == MotionEvent.ACTION_MOVE);
x = event.getX();
y = event.getY();
int w = getWidth();
int h = getHeight();
if(w>=h){
radius = h * event.getSize();
}else{
radius = w * event.getSize();
}
invalidate();
return true;
}
@Override
protected void onDraw(Canvas canvas) {
if (paint == null) {
Bitmap bm = Bitmap.createBitmap(
getWidth(),
getHeight(),
Bitmap.Config.ARGB_8888);
Canvas originalCanvas = new Canvas(bm);
super.onDraw(originalCanvas);
Shader shader = new BitmapShader(bm,
Shader.TileMode.CLAMP,
Shader.TileMode.CLAMP);
paint = new Paint();
paint.setShader(shader);
}
canvas.drawColor(getSolidColor());
if (touched) {
canvas.drawCircle(x, y, radius, paint);
}
}
}
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:orientation="vertical"
tools:context="com.example.androidtouchimageview.MainActivity" >
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="android-coding.blogspot.com"
android:textSize="28dp"
android:textStyle="bold" />
<com.example.androidtouchimageview.TouchImageView
android:id="@+id/image1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_launcher" />
<com.example.androidtouchimageview.TouchImageView
android:id="@+id/image2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@drawable/ic_launcher" />
</LinearLayout>
package com.example.valueanimatorofcolor;
import com.example.objectanimatorofargb.R;
import android.animation.ArgbEvaluator;
import android.animation.ObjectAnimator;
import android.animation.ValueAnimator;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
public class MainActivity extends Activity {
TextView title;
Button btnStart;
ImageView image;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
title = (TextView) findViewById(R.id.title);
image = (ImageView) findViewById(R.id.image);
btnStart = (Button) findViewById(R.id.start);
btnStart.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View v) {
startColorAnimation(image);
}});
}
private void startColorAnimation(View view){
//int colorStart = 0xFFffffff;
int colorStart = view.getSolidColor();
int colorEnd = 0xFF000000;
ValueAnimator colorAnim = ObjectAnimator.ofInt(
view, "backgroundColor", colorStart, colorEnd);
colorAnim.setDuration(2000);
colorAnim.setEvaluator(new ArgbEvaluator());
colorAnim.setRepeatCount(1);
colorAnim.setRepeatMode(ValueAnimator.REVERSE);
colorAnim.start();
}
}
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.valueanimatorofcolor.MainActivity" >
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="android-coding.blogspot.com"
android:textSize="28dp"
android:textStyle="bold" />
<Button
android:id="@+id/start"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Start Animation" />
<ImageView
android:id="@+id/image"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@drawable/ic_launcher" />
</LinearLayout>
package com.example.androidrevealeffect;
import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.ViewAnimationUtils;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.ToggleButton;
public class MainActivity extends Activity {
TextView title;
ImageView image;
ToggleButton btnHideShow;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
title = (TextView)findViewById(R.id.title);
image = (ImageView) findViewById(R.id.image);
btnHideShow = (ToggleButton) findViewById(R.id.hideshow);
btnHideShow.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked) {
if(isChecked){
hide(title);
hide(image);
}else{
show(title);
show(image);
}
}
});
}
// To reveal a previously invisible view using this effect:
private void show(final View view) {
// get the center for the clipping circle
int cx = (view.getLeft() + view.getRight()) / 2;
int cy = (view.getTop() + view.getBottom()) / 2;
// get the final radius for the clipping circle
int finalRadius = Math.max(view.getWidth(), view.getHeight());
// create the animator for this view (the start radius is zero)
Animator anim = ViewAnimationUtils.createCircularReveal(view, cx, cy,
0, finalRadius);
anim.setDuration(1000);
// make the view visible and start the animation
view.setVisibility(View.VISIBLE);
anim.start();
}
// To hide a previously visible view using this effect:
private void hide(final View view) {
// get the center for the clipping circle
int cx = (view.getLeft() + view.getRight()) / 2;
int cy = (view.getTop() + view.getBottom()) / 2;
// get the initial radius for the clipping circle
int initialRadius = view.getWidth();
// create the animation (the final radius is zero)
Animator anim = ViewAnimationUtils.createCircularReveal(view, cx, cy,
initialRadius, 0);
anim.setDuration(1000);
// make the view invisible when the animation is done
anim.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
super.onAnimationEnd(animation);
view.setVisibility(View.INVISIBLE);
}
});
// start the animation
anim.start();
}
}
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:orientation="vertical"
tools:context="com.example.androidrevealeffect.MainActivity" >
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="android-coding.blogspot.com"
android:textSize="28dp"
android:textStyle="bold" />
<ToggleButton
android:id="@+id/hideshow"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textOn="Show"
android:textOff="Hide" />
<ImageView
android:id="@+id/image"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@drawable/ic_launcher"
android:background="@android:color/darker_gray" />
</LinearLayout>
package com.example.androidobjectanimator;
import android.animation.ObjectAnimator;
import android.app.Activity;
import android.graphics.Path;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
public class MainActivity extends Activity {
LinearLayout mainLayout;
TextView textTitle;
Button buttonMove;
ImageView image;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mainLayout = (LinearLayout) findViewById(R.id.mainlayout);
mainLayout.setOnClickListener(MyOnClickListener);
textTitle = (TextView) findViewById(R.id.title);
textTitle.setOnClickListener(MyOnClickListener);
buttonMove = (Button) findViewById(R.id.buttonflip);
buttonMove.setOnClickListener(MyOnClickListener);
image = (ImageView) findViewById(R.id.image);
image.setOnClickListener(MyOnClickListener);
}
OnClickListener MyOnClickListener =
new OnClickListener() {
@Override
public void onClick(View v) {
moveit(v);
}
};
private void moveit(final View view) {
float x = view.getX();
float y = view.getY();
Path path = new Path();
path.moveTo(x + 0, y + 0);
path.lineTo(x + 100, y + 150);
path.lineTo(x + 400, y + 150);
path.lineTo(x + 0, y + 0);
ObjectAnimator objectAnimator =
ObjectAnimator.ofFloat(view, View.X,
View.Y, path);
objectAnimator.setDuration(3000);
objectAnimator.start();
}
}
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/mainlayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:orientation="vertical"
tools:context="com.example.androidflipview.MainActivity" >
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="android-coding.blogspot.com"
android:textSize="28dp"
android:textStyle="bold" />
<Button
android:id="@+id/buttonflip"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Move" />
<ImageView
android:id="@+id/image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_launcher" />
</LinearLayout>
package com.example.androidflipview;
import android.support.v7.app.ActionBarActivity;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.animation.ObjectAnimator;
import android.os.Bundle;
public class MainActivity extends ActionBarActivity {
LinearLayout mainLayout;
TextView textTitle;
Button buttonFlip;
ImageView image;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mainLayout = (LinearLayout)findViewById(R.id.mainlayout);
mainLayout.setOnClickListener(MyOnClickListener);
textTitle = (TextView)findViewById(R.id.title);
textTitle.setOnClickListener(MyOnClickListener);
buttonFlip = (Button)findViewById(R.id.buttonflip);
buttonFlip.setOnClickListener(MyOnClickListener);
image = (ImageView)findViewById(R.id.image);
image.setOnClickListener(MyOnClickListener);
}
OnClickListener MyOnClickListener = new OnClickListener(){
@Override
public void onClick(View v) {
rotateit(v);
}
};
private void rotateit(final View viewToFlip) {
ObjectAnimator rot = ObjectAnimator.ofFloat(viewToFlip, "rotation", 0f, 360f);
rot.setDuration(3000);
rot.start();
}
}
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/mainlayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:orientation="vertical"
tools:context="com.example.androidflipview.MainActivity" >
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="android-coding.blogspot.com"
android:textSize="28dp"
android:textStyle="bold" />
<Button
android:id="@+id/buttonflip"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Rotate" />
<ImageView
android:id="@+id/image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_launcher" />
</LinearLayout>
package com.example.androidflipview;
import android.support.v7.app.ActionBarActivity;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.animation.ObjectAnimator;
import android.os.Bundle;
public class MainActivity extends ActionBarActivity {
LinearLayout mainLayout;
TextView textTitle;
Button buttonFlip;
ImageView image;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mainLayout = (LinearLayout)findViewById(R.id.mainlayout);
mainLayout.setOnClickListener(MyOnClickListener);
textTitle = (TextView)findViewById(R.id.title);
textTitle.setOnClickListener(MyOnClickListener);
buttonFlip = (Button)findViewById(R.id.buttonflip);
buttonFlip.setOnClickListener(MyOnClickListener);
image = (ImageView)findViewById(R.id.image);
image.setOnClickListener(MyOnClickListener);
}
OnClickListener MyOnClickListener = new OnClickListener(){
@Override
public void onClick(View v) {
flipit(v);
}
};
private void flipit(final View viewToFlip) {
ObjectAnimator flip = ObjectAnimator.ofFloat(viewToFlip, "rotationX", 0f, 360f);
flip.setDuration(3000);
flip.start();
}
}
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/mainlayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:orientation="vertical"
tools:context="com.example.androidflipview.MainActivity" >
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="android-coding.blogspot.com"
android:textSize="28dp"
android:textStyle="bold" />
<Button
android:id="@+id/buttonflip"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Flip" />
<ImageView
android:id="@+id/image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_launcher" />
</LinearLayout>
package com.example.androidflipview;
import android.support.v7.app.ActionBarActivity;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import android.animation.ObjectAnimator;
import android.os.Bundle;
public class MainActivity extends ActionBarActivity {
TextView textTitle;
Button buttonFlip;
ImageView image;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
textTitle = (TextView)findViewById(R.id.title);
textTitle.setOnClickListener(MyOnClickListener);
buttonFlip = (Button)findViewById(R.id.buttonflip);
buttonFlip.setOnClickListener(MyOnClickListener);
image = (ImageView)findViewById(R.id.image);
image.setOnClickListener(MyOnClickListener);
}
OnClickListener MyOnClickListener = new OnClickListener(){
@Override
public void onClick(View v) {
flipit(v);
}
};
private void flipit(final View viewToFlip) {
ObjectAnimator flip = ObjectAnimator.ofFloat(viewToFlip, "rotationY", 0f, 360f);
flip.setDuration(3000);
flip.start();
}
}
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:orientation="vertical"
tools:context="com.example.androidflipview.MainActivity" >
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="android-coding.blogspot.com"
android:textSize="28dp"
android:textStyle="bold" />
<Button
android:id="@+id/buttonflip"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Flip" />
<ImageView
android:id="@+id/image"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@drawable/ic_launcher" />
</LinearLayout>
package com.example.androidemoji;
import java.io.UnsupportedEncodingException;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.widget.TextView;
public class MainActivity extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TextView emojiText = (TextView)findViewById(R.id.emojitext);
//byte[] bytes = {(byte) 0xF0, (byte) 0x9F, (byte) 0x98, (byte) 0x81};
//byte[] bytes = {(byte) 0xF0, (byte) 0x9F, (byte) 0x98, (byte) 0x84};
byte[] bytes = {(byte) 0xF0, (byte) 0x9F, (byte) 0x98, (byte) 0x89};
try {
emojiText.setText(new String(bytes, "UTF-8"));
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//Direct type in the emoji
//emojiText.setText("😁"); //maybe cannot displayed on browser
}
}
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.androidemoji.MainActivity" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="android-coding.blogspot.com"
android:textSize="28dp"
android:textStyle="bold" />
<TextView
android:id="@+id/emojitext"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:textSize="100dp"
android:textStyle="bold" />
</LinearLayout>
package com.example.androidlistviewscrolling;
import android.support.v7.app.ActionBarActivity;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;
import android.os.Bundle;
public class MainActivity extends ActionBarActivity {
String[] months = { "January", "February", "March", "April", "May", "June",
"July", "August", "September", "October", "November", "December" };
ListView listView;
int toPosition = months.length;
Button btnScrollTop, btnScrollBottom, btnScrollTo;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
listView = (ListView) findViewById(R.id.listview);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, months);
listView.setAdapter(adapter);
listView.setOnItemClickListener(new OnItemClickListener(){
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
toPosition = position;
btnScrollTo.setText("Scroll to position " + toPosition);
}});
btnScrollTop = (Button)findViewById(R.id.scrolltop);
btnScrollTop.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View v) {
listView.smoothScrollToPosition(0);
}});
btnScrollBottom = (Button)findViewById(R.id.scrollbottom);
btnScrollBottom.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View v) {
listView.smoothScrollToPosition(listView.getCount()-1);
}});
btnScrollTo = (Button)findViewById(R.id.scrollto);
btnScrollTo.setText("Scroll to position " + toPosition);
btnScrollTo.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View v) {
listView.smoothScrollToPosition(toPosition);
}});
}
}
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.androidlistviewscrolling.MainActivity" >
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical" >
<ListView
android:id="@+id/listview"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textStyle="bold"
android:textSize="28dp"
android:text="android-coding.blogspot.com" />
<Button
android:id="@+id/scrolltop"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Scroll to Top" />
<Button
android:id="@+id/scrollbottom"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Scroll to Bottom" />
<Button
android:id="@+id/scrollto"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>
package com.example.androidgetrunning;
import java.util.List;
import android.support.v7.app.ActionBarActivity;
import android.text.method.ScrollingMovementMethod;
import android.app.ActivityManager;
import android.os.Bundle;
import android.widget.TextView;
public class MainActivity extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//setContentView(R.layout.activity_main);
ActivityManager activityManager = (ActivityManager)getSystemService(ACTIVITY_SERVICE);
/*
* maxNum: the maximum number of entries to return in the list.
* The actual number returned may be smaller,
* depending on how many services are running.
*/
int maxNum = 100;
List<ActivityManager.RunningServiceInfo> list = activityManager.getRunningServices(maxNum);
StringBuilder info = new StringBuilder();
info.append("android-coding.blogspot.com" + "\n\n");
info.append("no. of running service: " + list.size() + "\n\n");
for(int i=0; i<list.size(); i++){
info.append(list.get(i).service + "\n\n");
}
TextView texView = new TextView(this);
texView.setMovementMethod(new ScrollingMovementMethod());
texView.setText(info);
setContentView(texView);
}
}
package com.example.androidgetrunning;
import java.util.List;
import android.support.v7.app.ActionBarActivity;
import android.text.method.ScrollingMovementMethod;
import android.app.ActivityManager;
import android.os.Bundle;
import android.widget.TextView;
public class MainActivity extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ActivityManager activityManager = (ActivityManager)getSystemService(ACTIVITY_SERVICE);
List<ActivityManager.RunningAppProcessInfo> list = activityManager.getRunningAppProcesses();
StringBuilder info = new StringBuilder();
info.append("android-coding.blogspot.com" + list.size() + "\n\n");
info.append("no. of running application processes: " + list.size() + "\n");
for(int i=0; i<list.size(); i++){
info.append(list.get(i).processName + "\n");
}
TextView texView = new TextView(this);
texView.setMovementMethod(new ScrollingMovementMethod());
texView.setText(info);
setContentView(texView);
}
}