100 Days of Google Dev
Starting now, Google are releasing 100 developer videos over 100 days, covering from Chrome to Android. Subscribe now: http://goo.gl/mQyv5L
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>