Top Ad 728x90

Rabu, 11 September 2013

Create SimpleDateFormat for specified Locale

by
Example of creating SimpleDateFormat with specified Locale from previous exercise "Get default Locale and available Locales".

Create SimpleDateFormat with specified Locale


package com.example.androidlocale;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
import android.app.Activity;

public class MainActivity extends Activity {

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

TextView textViewDefaultLocale = (TextView)findViewById(R.id.defaultlocale);
TextView textViewNoOfLocale = (TextView)findViewById(R.id.numberoflocale);
ListView listViewAvailableLocale = (ListView)findViewById(R.id.listviewlocale);

Locale defaultLocale = Locale.getDefault();
textViewDefaultLocale.setText("Default Locale: " + defaultLocale.toString());

final Locale[] availableLocales = Locale.getAvailableLocales();
textViewNoOfLocale.setText("Number of available Locale: " + availableLocales.length);
String[] availableLocalesString = new String[availableLocales.length];

for (int i=0; i<availableLocales.length; i++){
availableLocalesString[i] = availableLocales[i].toString();
}

ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, availableLocalesString);
listViewAvailableLocale.setAdapter(adapter);

listViewAvailableLocale.setOnItemClickListener(
new OnItemClickListener(){

@Override
public void onItemClick(AdapterView<?> parent,
View view, int position, long id) {
Locale item = availableLocales[position];

String format = "yyyy-MM-dd'T'HH:mm:ss.SSSZ";
SimpleDateFormat simpleDateFormat = new SimpleDateFormat(format, item);
Date now = new Date();
Toast.makeText(getApplicationContext(),
"Locale: " + item.toString() + "\n"
+ simpleDateFormat.format(now),
Toast.LENGTH_LONG).show();

}});

}

}

Senin, 09 September 2013

Get details of Locale

by
Last exercise list available Locale of the system. It's modified to display details of the clicked Locale.

Get details of Locale


package com.example.androidlocale;

import java.util.Locale;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
import android.app.Activity;

public class MainActivity extends Activity {

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

TextView textViewDefaultLocale = (TextView)findViewById(R.id.defaultlocale);
TextView textViewNoOfLocale = (TextView)findViewById(R.id.numberoflocale);
ListView listViewAvailableLocale = (ListView)findViewById(R.id.listviewlocale);

Locale defaultLocale = Locale.getDefault();
textViewDefaultLocale.setText("Default Locale: " + defaultLocale.toString());

final Locale[] availableLocales = Locale.getAvailableLocales();
textViewNoOfLocale.setText("Number of available Locale: " + availableLocales.length);
String[] availableLocalesString = new String[availableLocales.length];

for (int i=0; i<availableLocales.length; i++){
availableLocalesString[i] = availableLocales[i].toString();
}

ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, availableLocalesString);
listViewAvailableLocale.setAdapter(adapter);

listViewAvailableLocale.setOnItemClickListener(
new OnItemClickListener(){

@Override
public void onItemClick(AdapterView<?> parent,
View view, int position, long id) {
Locale item = availableLocales[position];

Toast.makeText(getApplicationContext(),
"Language: " + item.getLanguage() + "\n"
+ "Country: " + item.getCountry() + "\n"
+ "DisplayName: " + item.getDisplayName() + "\n"
+ "DisplayLanguage: " + item.getDisplayLanguage() + "\n"
+ "DisplayCountry: " + item.getDisplayCountry(),
Toast.LENGTH_LONG).show();
}});

}

}


Keep using the layout in last exercise.

Next: Create SimpleDateFormat for specified Locale

Sabtu, 07 September 2013

Get default Locale and available Locales

by
Example to get default Locale and available Locales:

Get default Locale and available Locales


package com.example.androidlocale;

import java.util.Locale;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
import android.app.Activity;

public class MainActivity extends Activity {

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

TextView textViewDefaultLocale = (TextView)findViewById(R.id.defaultlocale);
TextView textViewNoOfLocale = (TextView)findViewById(R.id.numberoflocale);
ListView listViewAvailableLocale = (ListView)findViewById(R.id.listviewlocale);

Locale defaultLocale = Locale.getDefault();
textViewDefaultLocale.setText("Default Locale: " + defaultLocale.toString());

Locale[] availableLocales = Locale.getAvailableLocales();
textViewNoOfLocale.setText("Number of available Locale: " + availableLocales.length);
String[] availableLocalesString = new String[availableLocales.length];

for (int i=0; i<availableLocales.length; i++){
availableLocalesString[i] = availableLocales[i].toString();
}

ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, availableLocalesString);
listViewAvailableLocale.setAdapter(adapter);

}

}


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

<TextView
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" />
<TextView
android:id="@+id/defaultlocale"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<TextView
android:id="@+id/numberoflocale"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<ListView
android:id="@+id/listviewlocale"
android:layout_width="match_parent"
android:layout_height="match_parent"/>

</LinearLayout>

next: Get details of Locale

Combine bitmap, half/half

by
This example demonstrate how to combin two bitmap, half from a bitmap, another from the mirror bitmap of the same source.

Combine bitmap, half/half


package com.example.androiddrawbitmap;

import java.io.FileNotFoundException;

import android.net.Uri;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.Bitmap.Config;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Matrix;
import android.graphics.Rect;
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 {

Button btnLoadImage;
TextView textSource;
ImageView imageResult;

final int RQS_IMAGE1 = 1;

Uri source;
Bitmap bitmapMaster;
Canvas canvasMaster;

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

btnLoadImage = (Button) findViewById(R.id.loadimage);
textSource = (TextView) findViewById(R.id.sourceuri);
imageResult = (ImageView) findViewById(R.id.result);

btnLoadImage.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View arg0) {
Intent intent = new Intent(
Intent.ACTION_PICK,
android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(intent, RQS_IMAGE1);
}
});

}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);

Bitmap tempBitmap;

if (resultCode == RESULT_OK) {
switch (requestCode) {
case RQS_IMAGE1:
source = data.getData();

try {
tempBitmap = BitmapFactory
.decodeStream(getContentResolver().openInputStream(
source));

//create a mirror bitmap
Matrix matrixMirror = new Matrix();
matrixMirror.preScale(-1.0f, 1.0f);
Bitmap bitmapMirror = Bitmap.createBitmap(tempBitmap, 0, 0,
tempBitmap.getWidth(), tempBitmap.getHeight(),
matrixMirror, false);

//define half/half area
Rect rect1Half = new Rect(0, 0, tempBitmap.getWidth() / 2,
tempBitmap.getHeight());
Rect rect2Half = new Rect((tempBitmap.getWidth() / 2) + 1,
0, tempBitmap.getWidth(), tempBitmap.getHeight());

Config config = tempBitmap.getConfig();
if (config == null) {
config = Bitmap.Config.ARGB_8888;
}

//craete the master bitmap
bitmapMaster = Bitmap.createBitmap(
tempBitmap.getWidth(), tempBitmap.getHeight(), config);
canvasMaster = new Canvas(bitmapMaster);

//merge bitmap half/half
canvasMaster.drawBitmap(tempBitmap, rect1Half, rect1Half,
null);
canvasMaster.drawBitmap(bitmapMirror, rect2Half, rect2Half,
null);

imageResult.setImageBitmap(bitmapMaster);

} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

break;
}
}
}

}


<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:layout_gravity="center_horizontal"
android:autoLink="web"
android:text="http://android-er.blogspot.com/"
android:textStyle="bold" />

<Button
android:id="@+id/loadimage"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Load Image 1" />

<TextView
android:id="@+id/sourceuri"
android:layout_width="match_parent"
android:layout_height="wrap_content" />

<ImageView
android:id="@+id/result"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:background="@android:color/background_dark"
android:scaleType="centerInside" />

</LinearLayout>


download filesDownload the files.



more: Something about processing images in Android

Jumat, 06 September 2013

Sony releases Camera Remote API (beta)

by
With Sony Camera Remote API (beta), developers can create smartphone apps to control Sony cameras
  • Develop your own applications to control camera or get captured image and create Photo Uploader, Time Lapse Control Software, or other novel ideas for applications using the latest and greatest Sony cameras.
  • Start Today with the easy to learn and use, JSON based Application Programming Interface (API).
  • Since the API is platform agnostic, you can develop for your choice of operating systems like Android™, iOS™, Windows™ or others.


Visit: http://camera.developer.sony.com/

Press release: Sony to release API for using mobile devices as Wi-Fi remote controls for Sony cameras


Top Ad 728x90