Port JavaFX application fo Android APK, with javafxports

javafxports provide tools to build a Java(FX) runtime for Android devices. You can follow the instructions to port JavaFX Application to Android APK.

Here show how to port JavaFX Hello World to Android APK, on Ubuntu.

JavaFXAndroid
- It's assumed Android SDK is install on your system, at /home/eric/Android in my case.

- Gradle is need to create Android project from JavaFX application. To install Gradle (currently 1.4) on Ubuntu, run the command:
$ sudo apt-get install gradle


- You need a JavaFX-Dalvik Runtime. You can either download it here (easy) or build this yourself (less trivial). Always download the latest version of the runtime: dalvik-sdk-latest. /home/eric/dalvik-sdk in my case.


- Create a JavaFX Hello World project compiled with Java 7. To specify compiled with Java 7 in Netbeans, click File (or right click the project), -> Project Properties, select Category of Sources, select Source/Binary Format of JDK 7.


- To run Gradle to generate Android project, and ant to generate APK, the following environment setting have to be set.

path to Android SDK:
$ export ANDROID_SDK=/home/eric/Android/sdk
$ export PATH=$ANDROID_SDK/tools:$ANDROID_SDK/platform-tools:$PATH

Android and Java Home:
$ export ANDROID_HOME=/home/eric/Android/sdk
$ export JAVA_HOME=/home/eric/jdk1.8.0_20

- Switch to /home/eric/dalvik-sdk/android-tools, run the command to generate Android Project:

gradle -PDEBUG -PDIR=/home/eric/JavaFXAndroid -PNAME=JavaFXAndroid -PPACKAGE=com.JavaFXAndroid -PJFX_SDK=/home/eric/dalvik-sdk -PJFX_APP=/home/eric/NetBeansProjects/com.JavaFXAndroid/dist -PJFX_MAIN=com.javafxandroid.ComJavaFXAndroid -PANDROID_SDK=/home/eric/Android/sdk createProject

Where:

DIR=/home/eric/JavaFXAndroid - the output directory.
NAME=JavaFXAndroid - Name of the target Android project.
PACKAGE=com.JavaFXAndroid - package name of Java application
JFX_SDK=/home/eric/dalvik-sdk - location of downloaded JavaFX-Dalvik Runtime.
JFX_APP=/home/eric/NetBeansProjects/com.JavaFXAndroid/dist - The location of the Netbeans JavaFX project.
JFX_MAIN=com.javafxandroid.ComJavaFXAndroid - fully name of the main class of your JavaFX Application
ANDROID_SDK=/home/eric/Android/sdk createProject - location of your Android SDK.

Once successfully finished, switch to the the directory of the generated Android Project,  /home/eric/JavaFXAndroid/JavaFXAndroid in my case.

Run the command to generate the APK in its bin directory.
$ ant debug

Then you can run the adb command in bin directory to install the APK to real Android devices.
$ adb install -r -debug.apk


Run the ported Android app on real device:


Run Systrace in Android-Eclipse


The Systrace tool helps analyze the performance of your application by capturing and displaying execution times of your applications processes and other Android system processes. The tool combines data from the Android kernel such as the CPU scheduler, disk activity, and application threads to generate an HTML report that shows an overall picture of an Android device’s system processes for a given period of time.

The Systrace tool is particularly useful in diagnosing display problems where an application is slow to draw or stutters while displaying motion or animation. For more information on how to use Systrace, see Analyzing Display and Performance.


Keyboard shortcuts that are available while viewing a Systrace trace HTML report.


How to enable emoji input on Android

Open Setting -> Language & input, scroll down to Keyboard & Input Method. If you see the option of iWnn IME (Emoji), that means your device built-in support Emoji input. Check to enable it.


When you enter text, press and hold SpaceBar, to switch to Emoji (iWnn IME).



Place groupIndicator of ExpandableListView on right side

To place groupIndicator of ExpandableListView on right side, we can call setIndicatorBounds() for Android devices before Jelly Bean, or call setIndicatorBoundsRelative() for devices of Jelly Bean or higher.

Run on Nexus 7 of Android 4.4.4:



On Nexus One running Android 2.3.6



Modify MainActivity.java of last example "Create groupIndicator for ExpandableListView example", override onWindowFocusChanged() method.

package com.example.androidexpandablelistview;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import android.support.v7.app.ActionBarActivity;
import android.annotation.TargetApi;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.os.Bundle;
import android.widget.ExpandableListView;
import android.widget.Toast;

public class MainActivity extends ActionBarActivity {

ExpandableListView expandableListView;
MyExpandableListAdapter myExpandableListAdapter;
List<String> groupList;
HashMap<String, List<String>> childMap;

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

init();
expandableListView = (ExpandableListView) findViewById(R.id.mylist);
myExpandableListAdapter = new MyExpandableListAdapter(this, groupList, childMap);
expandableListView.setAdapter(myExpandableListAdapter);

}

@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2)
@Override
public void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);

Drawable drawable_groupIndicator =
getResources().getDrawable(R.drawable.groupindicator);
int drawable_width = drawable_groupIndicator.getMinimumWidth();

if(android.os.Build.VERSION.SDK_INT <
android.os.Build.VERSION_CODES.JELLY_BEAN_MR2){
expandableListView.setIndicatorBounds(
expandableListView.getWidth()-drawable_width,
expandableListView.getWidth());
}else{
expandableListView.setIndicatorBoundsRelative(
expandableListView.getWidth()-drawable_width,
expandableListView.getWidth());
}

Toast.makeText(MainActivity.this,
"drawable_width: " + drawable_width +"\n" +
"expandableListView.getWidth()" + expandableListView.getWidth(),
Toast.LENGTH_LONG).show();
}

private void init() {
groupList = new ArrayList<String>();
childMap = new HashMap<String, List<String>>();

List<String> groupList0 = new ArrayList<String>();
groupList0.add("groupList0 - 1");
groupList0.add("groupList0 - 2");
groupList0.add("groupList0 - 3");

List<String> groupList1 = new ArrayList<String>();
groupList1.add("groupList1 - 1");
groupList1.add("groupList1 - 2");
groupList1.add("groupList1 - 3");

List<String> groupList2 = new ArrayList<String>();
groupList2.add("groupList2 - 1");
groupList2.add("groupList2 - 2");
groupList2.add("groupList2 - 3");

List<String> groupList3 = new ArrayList<String>();
groupList3.add("groupList3 - 1");
groupList3.add("groupList3 - 2");
groupList3.add("groupList3 - 3");

groupList.add("Group List 0");
groupList.add("Group List 1");
groupList.add("Group List 2");
groupList.add("Group List 3");

childMap.put(groupList.get(0), groupList0);
childMap.put(groupList.get(1), groupList1);
childMap.put(groupList.get(2), groupList2);
childMap.put(groupList.get(3), groupList3);
}

}


"The import android.support.v7 cannot be resolved" and "ActionBarActivity cannot be resolved to a type"

It's a common error "The import android.support.v7 cannot be resolved" on import android.support.v7.app.ActionBarActivity; and "ActionBarActivity cannot be resolved to a type" on extends ActionBarActivity. It may be various reason to cause it. One of the reason is the auto-generated project appcompat_v7 closed.

Please check the video:

Create groupIndicator for ExpandableListView example

Modify from last exercise "ExpandableListView example", to create groupIndicator.


Copy drawables to /res/drawable/ folder. In my exercise, btn_check_buttonless_on.png and btn_check_buttonless_off.png copied from Android SDK folder: /Android/sdk/platforms/android-20/data/res/drawable-mdpi/

Create /res/drawable/groupindicator.xml, to define our groupIndicator.
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/btn_check_buttonless_off"
android:state_expanded="true" />
<item android:drawable="@drawable/btn_check_buttonless_on"/>
</selector>

Modify /res/layout/activity_main.xml to specify android:groupIndicator of ExpandableListView.
<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.androidexpandablelistview.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" />

<ExpandableListView
android:id="@+id/mylist"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:groupIndicator="@drawable/groupindicator" />

</LinearLayout>



Next:
- Place groupIndicator of ExpandableListView on right side


Asus Flashtool Installer for Zenfone



http://d-h.st/LGq
AsusFlashTool 1.0.0.0


http://d-h.st/LGq
Asus Flash Tool 1.0.0.7

Download RAW Firmware Here


  1. Open the ASUS Flash Tool, AFT will automatically detect mobile devices (if not automatically detect, please re-plug the USB cable)


  2. Step 2:
  3. 1), automatically detect the serial number (for example: DCATCY141082), State representatives connection status bar turns blue. Not connected display. Detected inconsistent with the actual SN possible, but does not affect the refresh firmware.

    2), manually select the correct model, there is no drop-down menu, and on behalf of AFT is not supported; model forget if elected, you will be prompted
    3), select whether empty user data, Yes on behalf empty, No representative of any default No, please choose according to the actual situation.

    4), click on the box icon, select the path to the firmware raw file.

    5), click again, you need to update the machine, serial number, and blue State status bar.

    6), the start point Start icon to start the firmware update.
  4.  flash process, the phone will appear black, is a normal, over a period of time will automatically display
  5.  Success, Asus Flash Tool will show below, the system will automatically reboot into the phone.

    Note: Sometimes brushing, the phone is turned off black state, press the power button to boot to see whether the boot.

    entire process takes about 6.5 minutes

Download RootZenfone 1.4.5r APK


Credit to Shakahuang

RootZenFone APK / RootZenUI APK

Supported Models:
* ZenFone 5 (T00F / T00J)
* ZenFone 6 (T00G / Z002)
* PadFone S (T00N) 

* Fonepad Note 6 (K00G aka ME560CG) v11.2.1.22 
* ZenFone 5 LTE (T00P)
* MeMO Pad 7 (ME70C)

To be confirmed models:  
* PadFone Mini (T00E)
* MeMO Pad 8 (K011) should be ME181C
* Transformer Pad TF303CL (K014)
* Transformer Pad TF103C (K010) TF103CG (K018)
* Fonepad 7 FE375CG (K019)
* Fonepad 7 FE170CG (K012) 
-> not working


Instructions:
*Turn off mobile data & wifi /Airplane mode
*Open RootZenfone
*Click Root, after 5 seconds Turn off, and Turn on wait until complete.

http://d-h.st/hEn
 

ASUS first MTK 4G phone T45



The T45’s design is similar to the ZenFone’s. There are black, white, red, and yellow versions but only the black version is on sale right now.

Display size is the standard entry-level, using 4.5 inches 854 * 480 resolution TFT screen, built-in 512M RAM / 4G ROM memory, and 1750 mA battery, the system is not native kitkat customized ZenUI. Core processor is MediaTek 's MT6582 M, with the MT6290 can support mobile 4G / 3G and GSM networks. Due to different positioning, T45 and ZenFone series products can not be compared.

Price: 113.95 USD

source : gizmochina.com and mtksj.com

Asus ZenWatch image Gallery and Specifications



Specifications:

Display - AMOLED 320 x 320 (277ppi) 1.36 inches
Chipset - Qualcomm® Snapdragon™ 400
CPU - 1.2GHz
RAM - 512MB
Memory - 4GB
Sensors - 9 Axis Sensor, Heart Rate
Dimensions - 39.8 x 50.6 7.9mm
Weight - 75g
Battery - 369mAh
Water Resistance - IP55

Price at €199 (about $260)









image credit to http://www.mobile01.com/topicdetail.php?f=588&t=4064170&last=52015671

Display ASCII character on ListView

It's a simple example to display ASCII code and character on ListView.


package com.example.androidlistascii;

import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.ListView;

public class MainActivity extends ActionBarActivity {

ListView listAscii;
AsciiCode Asciis[];
ArrayAdapter<AsciiCode> asciiArrayAdapter;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
listAscii = (ListView) findViewById(R.id.asciilist);
initAsciis();

asciiArrayAdapter = new ArrayAdapter<AsciiCode>(this,
android.R.layout.simple_list_item_1, android.R.id.text1, Asciis);
listAscii.setAdapter(asciiArrayAdapter);
}

private void initAsciis() {
Asciis = new AsciiCode[128];
for (int i = 0; i < 128; i++) {
Asciis[i] = new AsciiCode(i);
}
}

class AsciiCode{
int id;
char charAscii;

AsciiCode(int id){
this.id = id;
charAscii = (char)id;
}

public String toString(){
return
String.format("%03d", id)
+ " /(hex) 0x" + String.format("%02x", id).toUpperCase()
+ " : " + charAscii;
}
}
}

<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.androidlistascii.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" />

<ListView
android:id="@+id/asciilist"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />

</LinearLayout>

[Zenfone] How to Enter Safe Mode


how to enter safe mode?

  1. turn off zenfone 
  2. push the power button
  3. when it starts booting press volume down until the safe mode appears. 

Android ADB on WiFi: unable to connect to

For any reason, adb (via Wifi) cannot connect to device with error:

unable to connect to <ip address>:<port>

Try to restarts the adbd (on device) daemon listening on TCP on the specified port, by running adb command tcpip, with USB connected to device.

$ ./adb tcpip 5555

then connect again.

$ ./adb connect 192.168.1.111


Related:
Setup Android adb for Wifi debug

Android ADB device offline

When I run the adb command to list devices, it show my connected device with "offline", and I cannot issue any command on it.

My solution is to run Task Manager (on Ubuntu) and kill the running adb, then re-run adb again, problem solved:)


Thanks for Vladislav Ivanov comment. You can also enter the command:

adb kill-server

and then
adb start-server



Related:
- Setup Android adb for Wifi debug

Make square shaped layout, equal width and height

To make a layout in square shape, with equal width and height, we can re-assign LayoutParams.width and height of our layout in OnGlobalLayoutListener.

like this:
  myGridLayout.getViewTreeObserver().addOnGlobalLayoutListener(
new OnGlobalLayoutListener(){

@Override
public void onGlobalLayout() {

int pLength;
int pWidth = myGridLayout.getWidth();
int pHeight = myGridLayout.getHeight();

//Set myGridLayout equal width and height
if(pWidth>=pHeight){
pLength = pHeight;
}else{
pLength = pWidth;
}
ViewGroup.LayoutParams pParams = myGridLayout.getLayoutParams();
pParams.width = pLength;
pParams.height = pLength;
myGridLayout.setLayoutParams(pParams);

//deprecated in API level 16
myGridLayout.getViewTreeObserver().removeGlobalOnLayoutListener(this);
//for API Level >= 16
//myGridLayout.getViewTreeObserver().removeOnGlobalLayoutListener(this);
}});


Update last exercise.

Modify activity_main.xml, to change 8x8 centered GridLayout
<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.androidtouchview.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" />

<GridLayout
android:id="@+id/mygrid"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:columnCount="8"
android:rowCount="8"
android:layout_gravity="center"
android:background="@android:color/background_light" >
</GridLayout>

</LinearLayout>

Modify MainActivity.java
package com.example.androidtouchview;

import com.example.androidtouchview.MyView.OnToggledListener;

import android.support.v7.app.ActionBarActivity;
import android.view.ViewGroup;
import android.view.ViewTreeObserver.OnGlobalLayoutListener;
import android.widget.GridLayout;
import android.widget.Toast;
import android.os.Bundle;

public class MainActivity extends ActionBarActivity
implements OnToggledListener{

int numberOfGlobalLayoutCalled = 0;

MyView[] myViews;

GridLayout myGridLayout;

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

myGridLayout = (GridLayout)findViewById(R.id.mygrid);

int numOfCol = myGridLayout.getColumnCount();
int numOfRow = myGridLayout.getRowCount();
myViews = new MyView[numOfCol*numOfRow];
for(int yPos=0; yPos<numOfRow; yPos++){
for(int xPos=0; xPos<numOfCol; xPos++){
MyView tView = new MyView(this, xPos, yPos);
tView.setOnToggledListener(this);
myViews[yPos*numOfCol + xPos] = tView;
myGridLayout.addView(tView);
}
}

myGridLayout.getViewTreeObserver().addOnGlobalLayoutListener(
new OnGlobalLayoutListener(){

@Override
public void onGlobalLayout() {

int pLength;
final int MARGIN = 5;

int pWidth = myGridLayout.getWidth();
int pHeight = myGridLayout.getHeight();
int numOfCol = myGridLayout.getColumnCount();
int numOfRow = myGridLayout.getRowCount();

//Set myGridLayout equal width and height
if(pWidth>=pHeight){
pLength = pHeight;
}else{
pLength = pWidth;
}
ViewGroup.LayoutParams pParams = myGridLayout.getLayoutParams();
pParams.width = pLength;
pParams.height = pLength;
myGridLayout.setLayoutParams(pParams);

int w = pLength/numOfCol; //pWidth/numOfCol;
int h = pLength/numOfRow; //pHeight/numOfRow;

for(int yPos=0; yPos<numOfRow; yPos++){
for(int xPos=0; xPos<numOfCol; xPos++){
GridLayout.LayoutParams params =
(GridLayout.LayoutParams)myViews[yPos*numOfCol + xPos].getLayoutParams();
params.width = w - 2*MARGIN;
params.height = h - 2*MARGIN;
params.setMargins(MARGIN, MARGIN, MARGIN, MARGIN);
myViews[yPos*numOfCol + xPos].setLayoutParams(params);
}
}

Toast.makeText(MainActivity.this,
"numberOfGlobalLayoutCalled = " + numberOfGlobalLayoutCalled,
Toast.LENGTH_SHORT).show();
numberOfGlobalLayoutCalled++;

//deprecated in API level 16
myGridLayout.getViewTreeObserver().removeGlobalOnLayoutListener(this);
//for API Level >= 16
//myGridLayout.getViewTreeObserver().removeOnGlobalLayoutListener(this);
}});
}

@Override
public void OnToggled(MyView v, boolean touchOn) {

//get the id string
String idString = v.getIdX() + ":" + v.getIdY();

Toast.makeText(MainActivity.this,
"Toogled:\n" +
idString + "\n" +
touchOn,
Toast.LENGTH_SHORT).show();
}

}

OnGlobalLayoutListener called repeatly, and remove it

In last post, we re-layout the views when the global layout state within the view tree changes, with OnGlobalLayoutListener. But once re-layout the views, it trigger another layout state change, and repeat and repeat again.


To prevent it, we can call removeGlobalOnLayoutListener() (deprecated in API level 16) or removeOnGlobalLayoutListener() (for API Level >= 16) after layout.

MainActivity.java
package com.example.androidtouchview;

import com.example.androidtouchview.MyView.OnToggledListener;

import android.support.v7.app.ActionBarActivity;
import android.view.ViewTreeObserver.OnGlobalLayoutListener;
import android.widget.GridLayout;
import android.widget.Toast;
import android.os.Bundle;

public class MainActivity extends ActionBarActivity
implements OnToggledListener{

int numberOfGlobalLayoutCalled = 0;

MyView[] myViews;

GridLayout myGridLayout;

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

myGridLayout = (GridLayout)findViewById(R.id.mygrid);

int numOfCol = myGridLayout.getColumnCount();
int numOfRow = myGridLayout.getRowCount();
myViews = new MyView[numOfCol*numOfRow];
for(int yPos=0; yPos<numOfRow; yPos++){
for(int xPos=0; xPos<numOfCol; xPos++){
MyView tView = new MyView(this, xPos, yPos);
tView.setOnToggledListener(this);
myViews[yPos*numOfCol + xPos] = tView;
myGridLayout.addView(tView);
}
}

myGridLayout.getViewTreeObserver().addOnGlobalLayoutListener(
new OnGlobalLayoutListener(){

@Override
public void onGlobalLayout() {

final int MARGIN = 5;

int pWidth = myGridLayout.getWidth();
int pHeight = myGridLayout.getHeight();
int numOfCol = myGridLayout.getColumnCount();
int numOfRow = myGridLayout.getRowCount();
int w = pWidth/numOfCol;
int h = pHeight/numOfRow;

for(int yPos=0; yPos<numOfRow; yPos++){
for(int xPos=0; xPos<numOfCol; xPos++){
GridLayout.LayoutParams params =
(GridLayout.LayoutParams)myViews[yPos*numOfCol + xPos].getLayoutParams();
params.width = w - 2*MARGIN;
params.height = h - 2*MARGIN;
params.setMargins(MARGIN, MARGIN, MARGIN, MARGIN);
myViews[yPos*numOfCol + xPos].setLayoutParams(params);
}
}

Toast.makeText(MainActivity.this,
"numberOfGlobalLayoutCalled = " + numberOfGlobalLayoutCalled,
Toast.LENGTH_SHORT).show();
numberOfGlobalLayoutCalled++;

//deprecated in API level 16
myGridLayout.getViewTreeObserver().removeGlobalOnLayoutListener(this);
//for API Level >= 16
//myGridLayout.getViewTreeObserver().removeOnGlobalLayoutListener(this);
}});
}

@Override
public void OnToggled(MyView v, boolean touchOn) {

//get the id string
String idString = v.getIdX() + ":" + v.getIdY();

Toast.makeText(MainActivity.this,
"Toogled:\n" +
idString + "\n" +
touchOn,
Toast.LENGTH_SHORT).show();
}

}

Implement callback function by implementing interface for custom view

Last post "Custom View, detect touch to toggle color" and also "warning: custom view overrides onTouchEvent but not performClick and #onTouchEvent should call #performClick when a click is detected", we have a self-running custom view to detect user touch and toggle color. But the MainActivity don't know what happen on it. To make MainActivity informed when color toggled, we can implement interface for our custom view.


MyView.java
package com.example.androidtouchview;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;

public class MyView extends View {

public interface OnToggledListener {
void OnToggled(MyView v, boolean touchOn);
}

boolean touchOn;
boolean mDownTouch = false;
private OnToggledListener toggledListener;

public MyView(Context context) {
super(context);
init();
}

public MyView(Context context, AttributeSet attrs) {
super(context, attrs);
init();
}

public MyView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
init();
}

private void init() {
touchOn = false;
}

@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
setMeasuredDimension(MeasureSpec.getSize(widthMeasureSpec),
MeasureSpec.getSize(heightMeasureSpec));
}

@Override
protected void onDraw(Canvas canvas) {
if (touchOn) {
canvas.drawColor(Color.RED);
} else {
canvas.drawColor(Color.GRAY);
}
}

@Override
public boolean onTouchEvent(MotionEvent event) {
super.onTouchEvent(event);

switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:

touchOn = !touchOn;
invalidate();

if(toggledListener != null){
toggledListener.OnToggled(this, touchOn);
}

mDownTouch = true;
return true;

case MotionEvent.ACTION_UP:
if (mDownTouch) {
mDownTouch = false;
performClick();
return true;
}
}
return false;
}

@Override
public boolean performClick() {
super.performClick();
return true;
}

public void setOnToggledListener(OnToggledListener listener){
toggledListener = listener;
}

}

MainActivity.java
package com.example.androidtouchview;

import com.example.androidtouchview.MyView.OnToggledListener;

import android.support.v7.app.ActionBarActivity;
import android.widget.Toast;
import android.os.Bundle;

public class MainActivity extends ActionBarActivity
implements OnToggledListener{

MyView myView00, myView01;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
myView00 = (MyView)findViewById(R.id.myview00);
myView01 = (MyView)findViewById(R.id.myview01);

myView00.setOnToggledListener(this);
myView01.setOnToggledListener(this);
}

@Override
public void OnToggled(MyView v, boolean touchOn) {

//get the id string
String idString = getResources().getResourceName(v.getId());

Toast.makeText(MainActivity.this,
"Toogled:\n" +
idString + "\n" +
touchOn,
Toast.LENGTH_SHORT).show();
}

}

activity_main.xml
<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.androidtouchview.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" />

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

<com.example.androidtouchview.MyView
android:id="@+id/myview00"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:layout_margin="10dp"/>
<com.example.androidtouchview.MyView
android:id="@+id/myview01"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="2"
android:layout_margin="10dp"/>

</LinearLayout>

</LinearLayout>


How to Keep ROOT after OTA update


Today there is OTA update for Zenfone 5 i'll show you how to update without missing root privilege.

  1. Open RootZenfone
  2.  Check root survival mode on/off (Click Activate)
  3. Result
  4. Install Update
  5. Successfully Update
  6. CPU-Z

ASUS ZenWatch Announced at IFA 2014


Asus ZenWatch Price: 199 Euro


Berlin, Germany (3rd September, 2014)
— ASUS Corporate Vice President Eric Chen, accompanied by ASUS Design Center Vice President Mitch Yang and ASUS Senior Product Director Derek Yu, today went on stage at a pre-IFA 2014 event held at the Classic Remise to announce the company’s latest lineup of innovations, including ASUS ZenWatch, the company’s first wearable device produced in partnership with Google.

ASUS ZenWatch, the perfect smart companion


ASUS ZenWatch is the first wearable device from ASUS, powered by Android Wear and featuring a version of the ASUS ZenUI user interface developed specifically for ZenWatch. This exquisitely-crafted and slim device pairs seamlessly with a smartphone running Android™ 4.3 or higher to provide relevant and useful information when it is needed most, and also to serve as a personal wellness manager in conjunction with the ASUS ZenUI Wellness app.

Explaining the design philosophy of the ZenWatch concept, Mitch Yang said “Our design philosophy is Start with People. We want to deliver a seamless digital experience for everyone to enjoy. With our ZenWatch, you will always be connected to everything that matters in your life.”

ZenWatch brings the luxury tradition of fine watchmaking to Android Wear, with an elegant, detail-focused design and use of high-quality materials. It is designed for supreme comfort, with a soft genuine stitched-leather strap and quick-release clasp. The 2.5D curved glass increases usability with a smooth and responsive touch experience. ZenWatch comes with a selection of instantly-changeable software watch faces, allowing users to customize ZenWatch easily to match their style.

ZenWatch is much more than a sophisticated timepiece. With a range of practical smart features, including Watch Unlock, Tap Tap, Remote Camera, Cover to Mute, Find My Phone and Presentation Control, ZenWatch is the perfect smart companion. Its seamless integration with ASUS ZenUI adds even more functionality for owners of ASUS smartphones, letting users enjoy enhanced versions of exclusive ASUS ZenUI apps such as What’s Next and Do It Later.

Thanks to its integrated 9-axis sensor, ZenWatch is also a fully-featured wellness manager. The companion ASUS ZenUI Wellness app lets users monitor and track a range of wellness statistics including steps taken, calories burned, activity duration, heart rate, exercise intensity and relaxation level. Users can set and monitor personal fitness goals with ease, and see their progress at a glance.

ZenWatch raises the bar on what users should expect from wearable devices, showcasing the power of the ASUS ‘design thinking’ philosophy and ushering in a new era of true luxury and sophistication. 

Zenwatch: