Nov 24, 2014

Customize Toast to show longer duration

This example show how to customize Toast to show longer duration, by using CountDownTimer to call toast.show() repeatly. And also show how to make the toast counting.


package com.example.androidtoastduration;

import android.support.v7.app.ActionBarActivity;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;
import android.os.Bundle;
import android.os.CountDownTimer;


public class MainActivity extends ActionBarActivity {
 
 Button text1, text2, text3, text4;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        text1 = (Button)findViewById(R.id.text1);
        text2 = (Button)findViewById(R.id.text2);
        text3 = (Button)findViewById(R.id.text3);
        text4 = (Button)findViewById(R.id.text4);
        
        text1.setOnClickListener(new OnClickListener(){

   @Override
   public void onClick(View v) {
    Toast.makeText(
      MainActivity.this, 
      "LENGTH_SHORT", 
      Toast.LENGTH_SHORT).show();
   }});
        
        text2.setOnClickListener(new OnClickListener(){

   @Override
   public void onClick(View v) {
    Toast toast = Toast.makeText(
      MainActivity.this, 
      "10 second - Not Work!", 
      Toast.LENGTH_SHORT);
    toast.setDuration(10000); //set duration, not work
    toast.show();
   }});
        
        text3.setOnClickListener(new OnClickListener(){

   @Override
   public void onClick(View v) {
    final Toast toast = Toast.makeText(
      MainActivity.this, 
      "10 second", 
      Toast.LENGTH_SHORT);
    toast.show();
    
    new CountDownTimer(10000, 1000)
             {
                 public void onTick(long millisUntilFinished) {
                  toast.show(); 
                 }
                 
                 public void onFinish() {
                  toast.cancel();
                  
                 }
             }.start();
   }});
        
        text4.setOnClickListener(new OnClickListener(){

   @Override
   public void onClick(View v) {
    final Toast toast = Toast.makeText(
      MainActivity.this, 
      "10 second", 
      Toast.LENGTH_SHORT);
    toast.show();
    
    new CountDownTimer(10000, 1000)
             {
     int count = 10;
     
                 public void onTick(long millisUntilFinished) {
                  toast.show();
                  count--;
                  toast.setText(count + " sec");
                 }
                 
                 public void onFinish() {
                  toast.cancel();
                  
                 }
             }.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.androidtoastduration.MainActivity" >

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="android-coding.blogspot.com" />
    
    <Button
        android:id="@+id/text1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="40dp"
        android:textStyle="bold"
        android:text="LENGTH_SHORT" />
    
    <Button
        android:id="@+id/text2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="40dp"
        android:textStyle="bold"
        android:text="10 sec Toast - NOT Work!" />
    
    <Button
        android:id="@+id/text3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="40dp"
        android:textStyle="bold"
        android:text="10 sec Toast" />
    
    <Button
        android:id="@+id/text4"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="40dp"
        android:textStyle="bold"
        android:text="10 sec counting Toast" />

</LinearLayout>

Nov 20, 2014

Introduction to Android Auto


Timothy Jordan Introduces Android Auto. Android Auto brings the Android platform to the car in a way that's optimized for the driving experience. It's the same Google platform you already use for phones, tablets, televisions, watches, and more. In fact, all these experiences will often be in the same APK. But now, your app can also extend to the car in a way that's safer and more efficient for the driver. So drivers can stay connected with their hands on the wheel and their eyes on the road.

Using Android Auto is easy. Users go to the Google Play store and download apps that support Android Auto onto their phone.. When they connect their phone to the car, the phone goes into car mode and casts the Android Auto experience to the car's screen. This means that although all the apps and services are actually running on the phone, they're displayed in the car's dash. Users interact with them using the vehicle's controls such as a built-in touchscreen and microphone.

Oct 29, 2014

Android TV - Using the Leanback library

The LeanBack Support Library makes it easy and fast to build great looking Android TV apps. Ankur Kotwal covers the key components to get you started building apps for Android TV using this library.

DevBytes: Android TV - Using the Leanback library

Oct 9, 2014

Google Play services 6.1

Learn about Google Play services 6.1 in this DevByte from Magnus Hyttsten. Google Play services 6.1 adds Enhanced Ecommerce analytics support from Google Tag Manager and offers new improvements to the Google Drive Android API. With this release, we're also including a refresh of the Google Fit developer preview, so that you can test your fitness apps on any Android device.

Google Play services 6.1

Infolinks In Text Ads