Mar 25, 2014

Google Play Services 4.3

This video introduce all new things you can do with the new released Google Play services 4.3. This release includes two new APIs (Address and Analytics) and updates to the Play Games services, and Drive APIs.

Mar 18, 2014

Android Wear SDK

Android Wear SDK Developer Preview announced, to extend Android platform to a new generation of wearable devices. Visit: http://developer.android.com/wear/

This video, introduce how to make app ready for the wrist with Android Wear.

Mar 12, 2014

Introduction To OpenGL ES on Android

The tutorial video was posted by Samsung Developers at 2011, to provide introduction to OpenGL ES concepts and programming for Android. Intended for people familiar with Android but new to 3D graphics programming and OpenGL. Contains an overview of important concepts, and discusses key APIs.

)


Mar 10, 2014

Implement sliding page using ViewPager

android.support.v4.view.ViewPager is a layout manager that allows the user to flip left and right through pages of data.

Example:
ViewPager example
ViewPager example

/res/layout/slide_page.xml, layout of individual page.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/content"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="android-coding.blogspot.com" />

    <TextView
        android:id="@+id/pagenumber"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:textSize="38sp"
        android:textStyle="bold" />

    <EditText
        android:id="@+id/edit"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

</LinearLayout>

SlidePageSupportFragment.java, Fragment share for 0~3th pages.
package com.example.android_viewpager;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import android.widget.Toast;

public class SlidePageSupportFragment extends Fragment {
 //Share by SlidePageSupportFragment 0~3, 
 //and set pageNumber by calling setPageNumber()
 //...NOT always valid
 
 int pageNumber = 0;  //default
 
 public void setPageNumber(int num){
  pageNumber = num;
 }

 @Override
 public View onCreateView(LayoutInflater inflater, ViewGroup container,
   Bundle savedInstanceState) {

  ViewGroup rootView = (ViewGroup) inflater.inflate(
                R.layout.slide_page, container, false);
  TextView textPageNumber = (TextView)rootView.findViewById(R.id.pagenumber);
  textPageNumber.setText("Page " + pageNumber);
  
  Toast.makeText(getActivity(), 
    "onCreateView() - Page " + pageNumber, 
    Toast.LENGTH_SHORT).show();
  
        return rootView;
 }

 @Override
 public void onDestroyView() {
  super.onDestroyView();
  
  Toast.makeText(getActivity(), 
    "onDestroyView() - Page " + pageNumber, 
    Toast.LENGTH_SHORT).show();
 }

}

SlidePageSupportFragment4.java, dedicate for 4th page.
package com.example.android_viewpager;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import android.widget.Toast;

public class SlidePageSupportFragment4 extends Fragment {
 //specified for SlidePageSupportFragment4
 //with fixed pageNumber = 4
 
 int pageNumber = 4;

 @Override
 public View onCreateView(LayoutInflater inflater, ViewGroup container,
   Bundle savedInstanceState) {

  ViewGroup rootView = (ViewGroup) inflater.inflate(
                R.layout.slide_page, container, false);
  TextView textPageNumber = (TextView)rootView.findViewById(R.id.pagenumber);
  textPageNumber.setText("Page " + pageNumber);
  
  Toast.makeText(getActivity(), 
    "onCreateView() - Page " + pageNumber, 
    Toast.LENGTH_SHORT).show();
  
        return rootView;
 }

 @Override
 public void onDestroyView() {
  super.onDestroyView();
  
  Toast.makeText(getActivity(), 
    "onDestroyView() - Page " + pageNumber, 
    Toast.LENGTH_SHORT).show();
 }

}

/res/layout/activity_main.xml, layout of main activity, with <android.support.v4.view.ViewPager>.
<android.support.v4.view.ViewPager
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/pager"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />

MainActivity.java
package com.example.android_viewpager;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;

public class MainActivity extends FragmentActivity {

    private static final int NUM_PAGES = 5;

    private ViewPager mPager;
    private PagerAdapter mPagerAdapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        mPager = (ViewPager) findViewById(R.id.pager);
        mPagerAdapter = new MyFragmentStatePagerAdapter(getSupportFragmentManager());
        mPager.setAdapter(mPagerAdapter);
    }

    @Override
    public void onBackPressed() {
        if (mPager.getCurrentItem() == 0) {
            super.onBackPressed();
        } else {
            mPager.setCurrentItem(mPager.getCurrentItem() - 1);
        }
    }

    private class MyFragmentStatePagerAdapter extends FragmentStatePagerAdapter {
        public MyFragmentStatePagerAdapter(FragmentManager fm) {
            super(fm);
        }

        @Override
        public Fragment getItem(int position) {
         Fragment tmpFragment;
         if(position==4){
          tmpFragment = new SlidePageSupportFragment4();
         }else{
          tmpFragment = new SlidePageSupportFragment();
             ((SlidePageSupportFragment)tmpFragment).setPageNumber(position);
         }
            return tmpFragment;
        }

        @Override
        public int getCount() {
            return NUM_PAGES;
        }
    }
}


Reference: Using ViewPager for Screen Slides


Mar 9, 2014

SlidingPaneLayout example

android.support.v4.widget.SlidingPaneLayout provides a horizontal, multi-pane layout for use at the top level of a UI. A left (or first) pane is treated as a content list or browser, subordinate to a primary detail view for displaying content.


SlidingPaneLayout example
SlidingPaneLayout example


<android.support.v4.widget.SlidingPaneLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical" >

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Pane A"
            android:textStyle="bold" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="android-coding.blogspot.com" />

        <ImageView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:src="@drawable/ic_launcher" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="#101010"
        android:orientation="vertical" >

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Pane B"
            android:textColor="#C0C0C0"
            android:textStyle="italic|bold" />

        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/ic_launcher" />
    </LinearLayout>

</android.support.v4.widget.SlidingPaneLayout>

Mar 5, 2014

Change TextSize of EditText programmically

To set TextSize of EditText, call its setTextSize() method.


package com.example.androidedittext;

import android.os.Bundle;
import android.app.Activity;
import android.widget.EditText;
import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener;
import android.widget.TextView;

public class MainActivity extends Activity {

 @Override
 protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_main);
  
  final EditText input = (EditText)findViewById(R.id.input);
  input.setTextSize(28);
  
  SeekBar seekbarScale = (SeekBar)findViewById(R.id.sbsize);
  final TextView textScale = (TextView)findViewById(R.id.textsize);
  
  seekbarScale.setOnSeekBarChangeListener(new OnSeekBarChangeListener(){

   @Override
   public void onProgressChanged(SeekBar seekBar, int progress,
     boolean fromUser) {
    int size = progress+1;
    input.setTextSize(size);
    textScale.setText(String.valueOf(size));
   }

   @Override
   public void onStartTrackingTouch(SeekBar seekBar) {
    // TODO Auto-generated method stub
    
   }

   @Override
   public void onStopTrackingTouch(SeekBar seekBar) {
    // TODO Auto-generated method stub
    
   }});

 }

}

<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=".MainActivity" >

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="android-coding.blogspot.com" />
    
    <SeekBar 
        android:id="@+id/sbsize"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:max="50"
        android:progress="28"/>
    
    <TextView
        android:id="@+id/textsize"
     android:layout_width="match_parent"
        android:layout_height="wrap_content" />

    <EditText
        android:id="@+id/input"
     android:layout_width="match_parent"
        android:layout_height="wrap_content" />
 
</LinearLayout>

Infolinks In Text Ads