Wednesday, July 19, 2017

ExoPlayer: Flexible Media Playback for Android (Google I/O '17)


ExoPlayer is an open source media playback library for Android. Used by thousands of applications, it enables great media experiences and can be customized to suit individual needs. Recent additions to the library have ranged from a new high level API to advanced features such as multi-period DASH support and spatial audio. In this talk you’ll learn what’s new in ExoPlayer, as well as some of ExoPlayer’s key concepts, points of customization and inner workings.


Related Link:
> Android Developers > API Guides > Media and Camera > ExoPlayer


Tuesday, July 18, 2017

EditText with drawable icon


<?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:layout_margin="20dp"
    android:orientation="vertical"
    tools:context="com.blogspot.android_er.androidedittextchanged.MainActivity">

    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <ImageView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:src="@android:mipmap/sym_def_app_icon"/>
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical">
            <TextView
                android:id="@+id/title"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center_horizontal"
                android:layout_marginTop="10dp"
                android:layout_marginBottom="10dp"
                android:autoLink="web"
                android:text="http://android-er.blogspot.com/"
                android:textStyle="bold"/>
            <EditText
                android:id="@+id/edittext1"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:text="normal EditText"/>
            <EditText
                android:id="@+id/edittext2"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:text="EditText with drawableLeft"
                android:drawableLeft="@mipmap/ic_launcher"/>
            <EditText
                android:id="@+id/edittext3"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:text="EditText with drawableRight"
                android:drawableRight="@mipmap/ic_launcher_round"/>
            <EditText
                android:id="@+id/edittext4"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:text="EditText with drawableTop"
                android:drawableTop="@mipmap/ic_launcher"/>
            <EditText
                android:id="@+id/edittext5"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:text="EditText with drawableBottom"
                android:drawableBottom="@mipmap/ic_launcher_round"/>
            <EditText
                android:id="@+id/edittext6"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:text="EditText with background"
                android:background="@mipmap/ic_launcher"/>
        </LinearLayout>
    </FrameLayout>


</LinearLayout>


Monday, July 17, 2017

Set background and alpha of EditText

Examples of Setting background and alpha of EditText:


<?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:layout_margin="20dp"
    android:orientation="vertical"
    tools:context="com.blogspot.android_er.androidedittextchanged.MainActivity">

    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <ImageView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:src="@android:mipmap/sym_def_app_icon"/>
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical">
            <TextView
                android:id="@+id/title"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center_horizontal"
                android:layout_marginTop="10dp"
                android:layout_marginBottom="10dp"
                android:autoLink="web"
                android:text="http://android-er.blogspot.com/"
                android:textStyle="bold"/>
            <EditText
                android:id="@+id/edittext1"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:textSize="28dp"
                android:text="normal EditText"/>
            <EditText
                android:id="@+id/edittext2"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:text="EditText with background #50FFFFFF"
                android:textSize="28dp"
                android:background="#50FFFFFF"/>
            <EditText
                android:id="@+id/edittext3"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:text="EditText with background #FFFFFF"
                android:textSize="28dp"
                android:background="#FFFFFF"/>
            <EditText
                android:id="@+id/edittext4"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:text="EditText with background #FFFFFF and alpha=0.5"
                android:textSize="28dp"
                android:background="#FFFFFF"
                android:alpha="0.5"/>
        </LinearLayout>
    </FrameLayout>
</LinearLayout>

Sunday, July 16, 2017

EditText with custom shape (drawable)


To create EditText with our own shape, create a drawable XML to define our custom shape:

res/drawable/myshape.xml
<?xml version="1.0" encoding="utf-8"?>
<shape
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle"
    android:padding="10dp">
    <solid android:color="#505050"/>
    <corners
        android:bottomRightRadius="10dp"
        android:bottomLeftRadius="10dp"
        android:topLeftRadius="10dp"
        android:topRightRadius="10dp"/>
</shape>


Reference my shape in layout xml:
<?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:layout_margin="20dp"
    android:orientation="vertical"
    tools:context="com.blogspot.android_er.androidedittextchanged.MainActivity">

    <TextView
        android:id="@+id/title"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:autoLink="web"
        android:text="http://android-er.blogspot.com/"
        android:textStyle="bold"/>

    <EditText
        android:id="@+id/edittext1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:hint="normal EditText"/>
    <EditText
        android:id="@+id/edittext2"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:hint="EditText with custom shape"
        android:textColorHint="#B0B0B0"
        android:textColor="#F0F0F0"
        android:background="@drawable/myshape" />

</LinearLayout>


Saturday, July 15, 2017

Download your FREE copy of 'Android Security Cookbook'

Ensure your apps are as tight as can be from outside threats with this cookbook. With recipes you can take to newer versions when needed this 350 page download shows you how to catch the trickiest vulnerabilities before they become a problem and gives you, and your customers, the peace of mind you deserve.

Download your FREE copy of 'Android Security Cookbook'


Thursday, July 13, 2017

AutoCompleteTextView, subclass of EditText with Auto-complete function

AutoCompleteTextView is a subclass of EditText that shows completion suggestions automatically while the user is typing.


To implement AutoCompleteTextView in your app:

Add the AutoCompleteTextView to your layout:
<?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:layout_margin="20dp"
    android:orientation="vertical"
    tools:context="com.blogspot.android_er.androidedittextchanged.MainActivity">

    <TextView
        android:id="@+id/title"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:autoLink="web"
        android:text="http://android-er.blogspot.com/"
        android:textStyle="bold"/>

    <AutoCompleteTextView
        android:id="@+id/autocompletetextview"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" />

</LinearLayout>



Edit res/values/strings.xml to add array that contains all text suggestions.
<resources>
    <string name="app_name">AndroidEditTextChanged</string>
    <string-array name="suggestion">
        <item>January</item>
        <item>February</item>
        <item>March</item>
        <item>April</item>
        <item>May</item>
        <item>June</item>
        <item>July</item>
        <item>August</item>
        <item>September</item>
        <item>October</item>
        <item>November</item>
        <item>December</item>
    </string-array>
</resources>


Set adapter using the string array for the AutoCompleteTextView
package com.blogspot.android_er.androidedittextchanged;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;

public class MainActivity extends AppCompatActivity {

    AutoCompleteTextView autoCompleteTextView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        autoCompleteTextView =
                (AutoCompleteTextView)findViewById(R.id.autocompletetextview);

        String[] suggestion = getResources().getStringArray(R.array.suggestion);
        ArrayAdapter<String> adapter =
                new ArrayAdapter<String>(this,
                        android.R.layout.simple_list_item_1, suggestion);
        autoCompleteTextView.setAdapter(adapter);

    }

}



Tuesday, July 11, 2017

Another example of TextWatcher to monitor text changed in EditText

Last show Monitor user action on EditText, and do something in onTextChanged() method of TextWatcher. It's another example to do something in afterTextChanged() method, don't care what and where is the change, just do something on the changed text.


package com.blogspot.android_er.androidedittextchanged;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.text.Editable;
import android.text.TextWatcher;
import android.widget.EditText;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {

    EditText editText;
    TextView tvMsg;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        editText = (EditText)findViewById(R.id.edittext);
        tvMsg = (TextView)findViewById(R.id.msg);

        editText.addTextChangedListener(myTextWatcher);
    }

    TextWatcher myTextWatcher = new TextWatcher() {

        @Override
        public void beforeTextChanged(CharSequence charSequence,
                                      int i, int i1, int i2) {
        }

        @Override
        public void onTextChanged(CharSequence charSequence,
                                  int i, int i1, int i2) {
        }

        @Override
        public void afterTextChanged(Editable editable) {
            tvMsg.setText(editable.toString().toUpperCase());
        }
    };
}



<?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:layout_margin="20dp"
    android:orientation="vertical"
    tools:context="com.blogspot.android_er.androidedittextchanged.MainActivity">

    <TextView
        android:id="@+id/title"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:autoLink="web"
        android:text="http://android-er.blogspot.com/"
        android:textStyle="bold"/>

    <EditText
        android:id="@+id/edittext"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="Enter text"
        android:textSize="24dp"/>
    <TextView
        android:id="@+id/msg"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:textStyle="bold"
        android:textSize="24dp"/>


</LinearLayout>




Monday, July 10, 2017

Monitor user action on EditText

This example implement TextWatcher for EditText, such that we can detect user action on EditText, no extra "Enter" button is need.



package com.blogspot.android_er.androidedittextchanged;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.text.Editable;
import android.text.TextWatcher;
import android.widget.EditText;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {

    EditText editText;
    TextView tvMsg, tvInfo;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        editText = (EditText)findViewById(R.id.edittext);
        tvMsg = (TextView)findViewById(R.id.msg);
        tvInfo = (TextView)findViewById(R.id.info);

        editText.addTextChangedListener(myTextWatcher);
    }

    TextWatcher myTextWatcher = new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence charSequence, 
                                      int i, int i1, int i2) {
            tvInfo.setText("beforeTextChanged(): \n"
                    + charSequence + "\n"
                    + i + "\n"
                    + i1 + "\n"
                    + i2);
        }

        @Override
        public void onTextChanged(CharSequence charSequence, 
                                  int i, int i1, int i2) {
            tvInfo.setText("onTextChanged(): \n"
                    + charSequence + "\n"
                    + i + "\n"
                    + i1 + "\n"
                    + i2);
            tvMsg.setText(charSequence);
        }

        @Override
        public void afterTextChanged(Editable editable) {
            /*
            String s = editable.toString();
            tvInfo.setText("afterTextChanged(): \n"
                    + s);
                    */
        }
    };
}



<?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:layout_margin="20dp"
    android:orientation="vertical"
    tools:context="com.blogspot.android_er.androidedittextchanged.MainActivity">

    <TextView
        android:id="@+id/title"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:autoLink="web"
        android:text="http://android-er.blogspot.com/"
        android:textStyle="bold"/>

    <EditText
        android:id="@+id/edittext"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="Enter text"
        android:textSize="24dp"/>
    <TextView
        android:id="@+id/msg"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:textStyle="bold"
        android:textSize="24dp"/>
    <TextView
        android:id="@+id/info"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:textStyle="italic"
        android:textSize="20dp"/>

</LinearLayout>



Next:
Another example of TextWatcher to monitor text changed in EditText

Sunday, July 9, 2017

Android Vitals

MUST SEE:
Introducing Android vitals, a guide to better app and games performance that helps drive engagement and installs.

Friday, July 7, 2017

Android Things Projects

Android Things Projects

Key Features

  • Learn to build promising IoT projects with Android Things
  • Make the most out of hardware peripherals using standard Android APIs
  • Build enticing projects on IoT, home automation, and robotics by leveraging Raspberry Pi 3 and Intel Edison

Book Description
Android Things makes developing connected embedded devices easy by providing the same Android development tools, best-in-class Android framework, and Google APIs that make developers successful on mobile.

With this book, you will be able to take advantage of the new Android framework APIs to securely build projects using low-level components such as sensors, resistors, capacitors, and display controllers. This book will teach you all you need to know about working with Android Things through practical projects based on home automation, robotics, IoT, and so on. We'll teach you to make the most of the Android Things and build enticing projects such as a smart greenhouse that controls the climate and environment automatically. You'll also create an alarm system, integrate Android Things with IoT cloud platforms, and more.

By the end of this book, you will know everything about Android Things, and you'll have built some very cool projects using the latest technology that is driving the adoption of IoT. You will also have primed your mindset so that you can use your knowledge for profitable, practical projects.

What you will learn

  • Understand IoT ecosystem and the Android Things role
  • See the Android Things framework: installation, environment, SDK, and APIs
  • See how to effectively use sensors (GPIO and I2C Bus)
  • Integrate Android Things with IoT cloud platforms
  • Create practical IoT projects using Android Things
  • Integrate Android Things with other systems using standard IoT protocols
  • Use Android Things in IoT projects

About the Author
Francesco Azzola is an electronic engineer with over 15 years of experience in computer programming and JEE architecture. He is SCEA certified (Sun Certified Enterprise Architect), SCWCD, and SCJP. He is an Android and IoT enthusiast. He loves creating IoT projects using Arduino, Raspberry Pi, Android, and other platforms.

He is interested in the convergence between IoT and mobile applications. Previously, he worked in the mobile development field for several years. He has created a blog called survivingwithandroid,where he shares posts about coding in Android and IoT projects.

Table of Contents

  1. Getting Started with Android Things
  2. Create an alarm system using Android Things
  3. How to make an environmental monitoring system
  4. Integrate Android Things with IoT cloud platforms
  5. Create a smart system to control ambient light
  6. Remote Weather station
  7. Build a spying eye
  8. Android with Android Things


Reactive Android Programming

Make the most of asynchronous android programming

Reactive Android Programming

About This Book

  • Install and set up RxJava for Android development
  • Implement the Reactive paradigm for Android programming using RxJava
  • Create cutting edge real world Android apps with Reactive programming.

Who This Book Is For
Are you an android developer trying to figure out how to use reactive paradigm for your programming needs? If yes then this is the book for you. No previous knowledge of RxJava is required.

What You Will Learn

  • Set up an environment for asynchronous that is reactive Android programming
  • Write custom observables and higher level abstractions
  • Orchestrating multiple calls using Reactive programming principles
  • Fetch remote financial data using RxJava
  • Integrate and process Twitter streams gracefully
  • Utilize Reactive programming to develop interactive and responsive Android apps
  • Create your own application to follow financial stock updates in real-time based on selected companies' symbols
  • Integrate updates from the Twitter for those companies.

In Detail
Writing code on Android is hard. Writing a high quality code that involves concurrent and parallel tasks is even harder. Ensuring that this code will run without unforeseen race conditions is an the order of magnitude harder. RxJava is the tool that can help write code for such tasks.

In this book a novice developer will be introduced to a wide variety of tools that RxJava provides to enable them to produce robust and high-quality code for their asynchronous tasks by building a relatively simple(and high quality) application using advanced RxJava techniques to produce a high quality product.

Part 1 of the book will lead the developer through RxJava's initial setup in Android environment. In Part 2, the reader will learn RxJava 2.0 step-by-step by starting off with stock data processing and display.The developer will learn to choose appropriate Schedulers and to use Retrofit library for remote requests.In Part 3, the reader will also learn advanced topics such as adding integration to Twitter to process its streaming data by combining it with stock data.

Style and approach
This book is a step by step practical guide which will essentially teach you to set up, implement, and debug Reactive Android Code with ease.