List UsbDevice, UsbInterface and UsbEndpoint in USB Host mode

I have a simple example "List attached USB devices in USB Host mode" in old post. It's modified to get various UsbDevice, UsbInterface and UsbEndpoint here.

UsbDevice, UsbInterface and UsbEndpoint in USB Host mode
UsbDevice, UsbInterface and UsbEndpoint in USB Host mode
As mentioned in the old post, have to specify the app to be run as UDB Host, add uses-feature of "android.hardware.usb.host", and android:minSdkVersion="12" in AndroidManifest.xml.

MainActivity.java
package com.example.androidusbhost;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;

import android.hardware.usb.UsbConstants;
import android.hardware.usb.UsbDevice;
import android.hardware.usb.UsbEndpoint;
import android.hardware.usb.UsbInterface;
import android.hardware.usb.UsbManager;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.Spinner;
import android.widget.TextView;
import android.app.Activity;
import android.content.Context;

public class MainActivity extends Activity {

Button btnCheck;
TextView textInfo;
TextView textInfoInterface;
TextView textEndPoint;

Spinner spDeviceName;
ArrayList<String> listDeviceName;
ArrayList<UsbDevice> listUsbDevice;
ArrayAdapter<String> adapterDevice;

Spinner spInterface;
ArrayList<String> listInterface;
ArrayList<UsbInterface> listUsbInterface;
ArrayAdapter<String> adapterInterface;

Spinner spEndPoint;
ArrayList<String> listEndPoint;
ArrayList<UsbEndpoint> listUsbEndpoint;
ArrayAdapter<String> adapterEndpoint;

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

spDeviceName = (Spinner)findViewById(R.id.spinnerdevicename);
spInterface = (Spinner)findViewById(R.id.spinnerinterface);
spEndPoint = (Spinner)findViewById(R.id.spinnerendpoint);
textInfo = (TextView) findViewById(R.id.info);
textInfoInterface = (TextView)findViewById(R.id.infointerface);
textEndPoint = (TextView)findViewById(R.id.infoendpoint);

btnCheck = (Button) findViewById(R.id.check);
btnCheck.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View arg0) {
checkDeviceInfo();
}
});
}

private void checkDeviceInfo() {

listDeviceName = new ArrayList<String>();
listUsbDevice = new ArrayList<UsbDevice>();

UsbManager manager = (UsbManager) getSystemService(Context.USB_SERVICE);
HashMap<String, UsbDevice> deviceList = manager.getDeviceList();
Iterator<UsbDevice> deviceIterator = deviceList.values().iterator();

while (deviceIterator.hasNext()) {
UsbDevice device = deviceIterator.next();
listDeviceName.add(device.getDeviceName());
listUsbDevice.add(device);

}

textInfo.setText("");
textInfoInterface.setText("");
textEndPoint.setText("");

adapterDevice = new ArrayAdapter<String>(this,
android.R.layout.simple_spinner_item, listDeviceName);
adapterDevice.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spDeviceName.setAdapter(adapterDevice);
spDeviceName.setOnItemSelectedListener(deviceOnItemSelectedListener);
}

OnItemSelectedListener deviceOnItemSelectedListener =
new OnItemSelectedListener(){

@Override
public void onItemSelected(AdapterView<?> parent,
View view, int position, long id) {
UsbDevice device = listUsbDevice.get(position);

String i = device.toString() + "\n" +
"DeviceID: " + device.getDeviceId() + "\n" +
"DeviceName: " + device.getDeviceName() + "\n" +
"DeviceClass: " + device.getDeviceClass() + " - "
+ translateDeviceClass(device.getDeviceClass()) + "\n" +
"DeviceSubClass: " + device.getDeviceSubclass() + "\n" +
"VendorID: " + device.getVendorId() + "\n" +
"ProductID: " + device.getProductId() + "\n" +
"InterfaceCount: " + device.getInterfaceCount();
textInfo.setText(i);

checkUsbDevicve(device);
}

@Override
public void onNothingSelected(AdapterView<?> parent) {}

};

private void checkUsbDevicve(UsbDevice d) {
listInterface = new ArrayList<String>();
listUsbInterface = new ArrayList<UsbInterface>();

for(int i=0; i<d.getInterfaceCount(); i++){
UsbInterface usbif = d.getInterface(i);
listInterface.add(usbif.toString());
listUsbInterface.add(usbif);
}

adapterInterface = new ArrayAdapter<String>(this,
android.R.layout.simple_spinner_item, listInterface);
adapterDevice.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spInterface.setAdapter(adapterInterface);
spInterface.setOnItemSelectedListener(interfaceOnItemSelectedListener);
}

OnItemSelectedListener interfaceOnItemSelectedListener =
new OnItemSelectedListener(){

@Override
public void onItemSelected(AdapterView<?> parent,
View view, int position, long id) {

UsbInterface selectedUsbIf = listUsbInterface.get(position);

String sUsbIf = "\n" + selectedUsbIf.toString() + "\n"
+ "Id: " + selectedUsbIf.getId() + "\n"
+ "InterfaceClass: " + selectedUsbIf.getInterfaceClass() + "\n"
+ "InterfaceProtocol: " + selectedUsbIf.getInterfaceProtocol() + "\n"
+ "InterfaceSubclass: " + selectedUsbIf.getInterfaceSubclass() + "\n"
+ "EndpointCount: " + selectedUsbIf.getEndpointCount();

textInfoInterface.setText(sUsbIf);
checkUsbInterface(selectedUsbIf);
}

@Override
public void onNothingSelected(AdapterView<?> parent) {}

};

private void checkUsbInterface(UsbInterface uif) {
listEndPoint = new ArrayList<String>();
listUsbEndpoint = new ArrayList<UsbEndpoint>();

for(int i=0; i<uif.getEndpointCount(); i++){
UsbEndpoint usbEndpoint = uif.getEndpoint(i);
listEndPoint.add(usbEndpoint.toString());
listUsbEndpoint.add(usbEndpoint);
}

adapterEndpoint = new ArrayAdapter<String>(this,
android.R.layout.simple_spinner_item, listEndPoint);
adapterEndpoint.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spEndPoint.setAdapter(adapterEndpoint);
spEndPoint.setOnItemSelectedListener(endpointOnItemSelectedListener);
}

OnItemSelectedListener endpointOnItemSelectedListener =
new OnItemSelectedListener(){

@Override
public void onItemSelected(AdapterView<?> parent,
View view, int position, long id) {

UsbEndpoint selectedEndpoint = listUsbEndpoint.get(position);

String sEndpoint = "\n" + selectedEndpoint.toString() + "\n"
+ translateEndpointType(selectedEndpoint.getType());

textEndPoint.setText(sEndpoint);
}

@Override
public void onNothingSelected(AdapterView<?> parent) {}

};

private String translateEndpointType(int type){
switch(type){
case UsbConstants.USB_ENDPOINT_XFER_CONTROL:
return "USB_ENDPOINT_XFER_CONTROL (endpoint zero)";
case UsbConstants.USB_ENDPOINT_XFER_ISOC:
return "USB_ENDPOINT_XFER_ISOC (isochronous endpoint)";
case UsbConstants.USB_ENDPOINT_XFER_BULK :
return "USB_ENDPOINT_XFER_BULK (bulk endpoint)";
case UsbConstants.USB_ENDPOINT_XFER_INT:
return "USB_ENDPOINT_XFER_INT (interrupt endpoint)";
default:
return "unknown";
}
}

private String translateDeviceClass(int deviceClass){
switch(deviceClass){
case UsbConstants.USB_CLASS_APP_SPEC:
return "Application specific USB class";
case UsbConstants.USB_CLASS_AUDIO:
return "USB class for audio devices";
case UsbConstants.USB_CLASS_CDC_DATA:
return "USB class for CDC devices (communications device class)";
case UsbConstants.USB_CLASS_COMM:
return "USB class for communication devices";
case UsbConstants.USB_CLASS_CONTENT_SEC:
return "USB class for content security devices";
case UsbConstants.USB_CLASS_CSCID:
return "USB class for content smart card devices";
case UsbConstants.USB_CLASS_HID:
return "USB class for human interface devices (for example, mice and keyboards)";
case UsbConstants.USB_CLASS_HUB:
return "USB class for USB hubs";
case UsbConstants.USB_CLASS_MASS_STORAGE:
return "USB class for mass storage devices";
case UsbConstants.USB_CLASS_MISC:
return "USB class for wireless miscellaneous devices";
case UsbConstants.USB_CLASS_PER_INTERFACE:
return "USB class indicating that the class is determined on a per-interface basis";
case UsbConstants.USB_CLASS_PHYSICA:
return "USB class for physical devices";
case UsbConstants.USB_CLASS_PRINTER:
return "USB class for printers";
case UsbConstants.USB_CLASS_STILL_IMAGE:
return "USB class for still image devices (digital cameras)";
case UsbConstants.USB_CLASS_VENDOR_SPEC:
return "Vendor specific USB class";
case UsbConstants.USB_CLASS_VIDEO:
return "USB class for video devices";
case UsbConstants.USB_CLASS_WIRELESS_CONTROLLER:
return "USB class for wireless controller devices";
default: return "Unknown USB class!";

}
}

}

Layout, 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: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://arteluzevida.blogspot.com/"
android:textStyle="bold" />

<Button
android:id="@+id/check"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Check USB devices" />

<Spinner
android:id="@+id/spinnerdevicename"
android:layout_width="match_parent"
android:layout_height="wrap_content" />

<Spinner
android:id="@+id/spinnerinterface"
android:layout_width="match_parent"
android:layout_height="wrap_content" />

<Spinner
android:id="@+id/spinnerendpoint"
android:layout_width="match_parent"
android:layout_height="wrap_content" />

<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent" >

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

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

<TextView
android:id="@+id/infointerface"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textStyle="italic" />

<TextView
android:id="@+id/infoendpoint"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textStyle="bold" />

</LinearLayout>
</ScrollView>

</LinearLayout>

In the demo video, the Android device is connected to PC in beginning; it show one UsbDevice only. Then connect with a Arduino Esplora board with USB OTG cable; it show two UsbDevice connected.


download filesDownload the files.

Next:
Read iManufacturer and iProduct of USB Device from raw Device Descriptors



Step-by-step: Android USB Host Mode programming

Process Stats: Understanding How Your App Uses RAM

Posted by Dianne Hackborn, Android framework team


Android 4.4 KitKat introduced a new system service called procstats that helps you better understand how your app is using the RAM resources on a device. Procstats makes it possible to see how your app is behaving over time — including how long it runs in the background and how much memory it uses during that time. It helps you quickly find inefficiencies and misbehaviors in your app that can affect how it performs, especially when running on low-RAM devices.



You can access procstats data using an adb shell command, but for convenience there is also a new Process Stats developer tool that provides a graphical front-end to that same data. You can find Process Stats in Settings > Developer options > Process Stats.



In this post we’ll first take a look at the Process Stats graphical tool, then dig into the details of the memory data behind it, how it's collected, and why it's so useful to you as you analyze your app.





Process Stats overview of memory used by background processes over time.




Looking at systemwide memory use and background processes



When you open Process Stats, you see a summary of systemwide memory conditions and details on how processes are using memory over time. The image at right gives you an example of what you might see on a typical device.



At the top of the screen we can see that:



  • We are looking at that data collected over the last ~3.5 hours.

  • Currently the device’s RAM is in good shape ("Device memory is currently normal").

  • During that entire time the memory state has been good — this is shown by the green bar. If device memory was getting low, you would see yellow and red regions on the left of the bar representing the amount of total time with low memory.



Below the green bar, we can see an overview of the processes running in the background and the memory load they've put on the system:



  • The percentage numbers on the right indicate the amount of time each process has spent running during the total duration.

  • The blue bars indicate the relative computed memory load of each process. (The memory load is runtime*avg_pss, which we will go into more detail on later.)

  • Some apps may be listed multiple times, since what is being shown is processes (for example, Google Play services runs in two processes). The memory load of these apps is the sum of the load of their individual processes.

  • There are a few processes at the top that have all been running for 100% of the time, but with different weights because of their relative memory use.



Analyzing memory for specific processes



The example shows some interesting data: we have a Clock app with a higher memory weight than Google Keyboard, even though it ran for less than half the time. We can dig into the details of these processes just by tapping on them:







Process Stats memory details for Clock and Keyboard processes over the past 3.5 hours.





The details for these two processes reveal that:




  • The reason that Clock has been running at all is because it is being used as the current screen saver when the device is idle.

  • Even though the Clock process ran for less than half the time of the Keyboard, its ram use was significantly larger (almost 3x), which is why its overall weight is larger.



Essentially, procstats provides a “memory use” gauge that's much like the storage use or data use gauges, showing how much RAM the apps running in the background are using. Unlike with storage or data, though, memory use is much harder to quantify and measure, and procstats uses some tricks to do so. To illustrate the complexity of measuring memory use, consider a related topic: task managers.



Understanding task managers and their memory info



We’ve had a long history of task managers on Android. Android has always deeply supported multitasking, which means the geeky of us will tend to want to have some kind of UI for seeing and controlling this multitasking like the traditional UI we are used to from the desktop. However, multitasking on Android is actually quite a bit more complicated and fundamentally different than on a traditional desktop operating system, as I previously covered in Multitasking the Android Way. This deeply impacts how we can show it to the user.



Multitasking and continuous process management


To get a feel for just how different process management is on Android, you can take a look at the output of an important system service, the activity manager, with adb shell dumpsys activity. The example below shows a snapshot of current application processes on Android 4.4, listing them from most important to least:



ACTIVITY MANAGER RUNNING PROCESSES (dumpsys activity processes)
Process LRU list (sorted by oom_adj, 22 total, non-act at 2, non-svc at 2):
PERS #21: sys F/ /P trm: 0 23064:system/1000 (fixed)
PERS #20: pers F/ /P trm: 0 23163:com.android.systemui/u0a12 (fixed)
PERS #19: pers F/ /P trm: 0 23344:com.nuance.xt9.input/u0a77 (fixed)
PERS #18: pers F/ /P trm: 0 23357:com.android.phone/1001 (fixed)
PERS #17: pers F/ /P trm: 0 23371:com.android.nfc/1027 (fixed)
Proc # 3: fore F/ /IB trm: 0 13892:com.google.android.apps.magazines/u0a59 (service)
com.google.android.apps.magazines/com.google.apps.dots.android.app.service.SyncService<=Proc{23064:system/1000}
Proc # 2: fore F/ /IB trm: 0 23513:com.google.process.gapps/u0a8 (provider)
com.google.android.gsf/.gservices.GservicesProvider<=Proc{13892:com.google.android.apps.magazines/u0a59}
Proc # 0: fore F/A/T trm: 0 24811:com.android.settings/1000 (top-activity)
Proc # 4: vis F/ /IF trm: 0 23472:com.google.process.location/u0a8 (service)
com.google.android.backup/.BackupTransportService<=Proc{23064:system/1000}
Proc #14: prcp F/ /IF trm: 0 23298:com.google.android.inputmethod.latin/u0a57 (service)
com.google.android.inputmethod.latin/com.android.inputmethod.latin.LatinIME<=Proc{23064:system/1000}
Proc # 1: home B/ /HO trm: 0 23395:com.android.launcher/u0a13 (home)
Proc #16: cch B/ /CA trm: 0 23966:com.google.android.deskclock/u0a36 (cch-act)
Proc # 6: cch B/ /CE trm: 0 7716:com.google.android.music:main/u0a62 (cch-empty)
Proc # 5: cch B/ /CE trm: 0 8644:com.google.android.apps.docs/u0a39 (cch-empty)
Proc # 8: cch+2 B/ /CE trm: 0 5131:com.google.android.youtube/u0a78 (cch-empty)
Proc # 7: cch+2 B/ /CE trm: 0 23338:com.google.android.gms/u0a8 (cch-empty)
Proc #10: cch+4 B/ /CE trm: 0 8937:com.google.android.apps.walletnfcrel/u0a24 (cch-empty)
Proc # 9: cch+4 B/ /CE trm: 0 24689:com.google.android.apps.plus/u0a70 (cch-empty)
Proc #15: cch+6 B/ /S trm: 0 23767:com.google.android.apps.currents/u0a35 (cch-started-services)
Proc #13: cch+6 B/ /CE trm: 0 9115:com.google.android.gm/u0a44 (cch-empty)
Proc #12: cch+6 B/ /S trm: 0 7738:android.process.media/u0a6 (cch-started-services)
Proc #11: cch+6 B/ /CE trm: 0 8922:com.google.android.setupwizard/u0a19 (cch-empty)



Example output of dumpsys activity command, showing all processes currently running.



There are a few major groups of processes here — persistent system processes, the foreground processes, background processes, and finally cached processes — and the category of a process is extremely important for understanding its impact on the system.



At the same time, processes on this list change all of the time. For example, in the snapshot above we can see that “com.google.android.gm” is currently an important process, but that is because it is doing a background sync, something the user would not generally be aware of or want to manage.



Snapshotting per-process RAM use



The traditional use of a task manager is closely tied to RAM use, and Android provides a tool called meminfo for looking at a snapshot of current per-process RAM use. You can access it with the command adb shell dumpsys meminfo. Here's an example of the output.



Total PSS by OOM adjustment:
31841 kB: Native
13173 kB: zygote (pid 23001)
4372 kB: surfaceflinger (pid 23000)
3721 kB: mediaserver (pid 126)
3317 kB: glgps (pid 22993)
1656 kB: drmserver (pid 125)
995 kB: wpa_supplicant (pid 23148)
786 kB: netd (pid 121)
518 kB: sdcard (pid 132)
475 kB: vold (pid 119)
458 kB: keystore (pid 128)
448 kB: /init (pid 1)
412 kB: adbd (pid 134)
254 kB: ueventd (pid 108)
238 kB: dhcpcd (pid 10617)
229 kB: tf_daemon (pid 130)
200 kB: installd (pid 127)
185 kB: dumpsys (pid 14207)
144 kB: healthd (pid 117)
139 kB: debuggerd (pid 122)
121 kB: servicemanager (pid 118)
48217 kB: System
48217 kB: system (pid 23064)
49095 kB: Persistent
34012 kB: com.android.systemui (pid 23163 / activities)
7719 kB: com.android.phone (pid 23357)
4676 kB: com.android.nfc (pid 23371)
2688 kB: com.nuance.xt9.input (pid 23344)
24945 kB: Foreground
24945 kB: com.android.settings (pid 24811 / activities)
17136 kB: Visible
14026 kB: com.google.process.location (pid 23472)
3110 kB: com.android.defcontainer (pid 13976)
6911 kB: Perceptible
6911 kB: com.google.android.inputmethod.latin (pid 23298)
14277 kB: A Services
14277 kB: com.google.process.gapps (pid 23513)
26422 kB: Home
26422 kB: com.android.launcher (pid 23395 / activities)
21798 kB: B Services
16242 kB: com.google.android.apps.currents (pid 23767)
5556 kB: android.process.media (pid 7738)
145869 kB: Cached
41588 kB: com.google.android.apps.plus (pid 24689)
21417 kB: com.google.android.deskclock (pid 23966 / activities)
14463 kB: com.google.android.apps.docs (pid 8644)
14303 kB: com.google.android.gm (pid 9115)
11014 kB: com.google.android.music:main (pid 7716)
10688 kB: com.google.android.apps.magazines (pid 13892)
10240 kB: com.google.android.gms (pid 23338)
9882 kB: com.google.android.youtube (pid 5131)
8807 kB: com.google.android.apps.walletnfcrel (pid 8937)
3467 kB: com.google.android.setupwizard (pid 8922)

Total RAM: 998096 kB
Free RAM: 574945 kB (145869 cached pss + 393200 cached + 35876 free)
Used RAM: 392334 kB (240642 used pss + 107196 buffers + 3856 shmem + 40640 slab)
Lost RAM: 30817 kB
Tuning: 64 (large 384), oom 122880 kB, restore limit 40960 kB (high-end-gfx)


Example output of dumpsys meminfo command, showing memory currently used by running processes.



We are now looking at the same processes as above, again organized by importance, but now with on their impact on RAM use.



Usually when we measure RAM use in Android, we do this with Linux’s PSS (Proportional Set Size) metric. This is the amount of RAM actually mapped into the process, but weighted by the amount it is shared across processes. So if there is a 4K page of RAM mapped in to two processes, its PSS amount for each process would be 2K.




The nice thing about using PSS is that you can add up this value across all processes to determine the actual total RAM use. This characteristic is used at the end of the meminfo report to compute how much RAM is in use (which comes in part from all non-cached processes), versus how much is "free" (which includes cached processes).





Task-manager style memory info, showing a snapshot of memory used by running apps.



Task manager UI based on PSS snapshot



Given the information we have so far, we can imagine various ways to present this in a somewhat traditional task manager UI. In fact, the UI you see in Settings > Apps > Running is derived from this information. It shows all processes running services (“svc” adjustment in the LRU list) and on behalf of the system (the processes with a “<=Proc{489:system/1000}” dependency), computing the PSS RAM for each of these and any other processes they have dependencies on.



The problem with visualizing memory use in this way is that it gives you the instantaneous state of the apps, without context over time. On Android, users don’t directly control the creation and removal of application processes — they may be kept for future use, removed when the system decides, or run in the background without the user explicitly launching them. So looking only at the instantaneous state of memory use only, you would be missing important information about what is actually going on over time.



For example, in our first look at the process state we see the com.google.android.apps.magazines process running for a sync, but when we collected the RAM use right after that it was no longer running in the background but just being kept around as an old cached process.



To address this problem, the new procstats tool continually monitors the state of all application processes over time, aggregating that information and collecting PSS samples from those processes while doing so. You can view the raw data being collected by procstats with the command adb shell dumpsys procstats.




Seeing memory use over time with procstats



Let’s now go back to procstats and take a look at the context it provides by showing memory use over time. We can use the command adb shell dumpsys procstats --hours 3 to output memory information collected over the last 3 hours. This is the same data as represented graphically in the first Process Stats example.



The output shows all of the processes that have run in the last 3 hours, sorted with the ones running the most first. (Processes in a cached state don’t count for the total time in this sort.) Like the initial graphical representation, we now clearly see a big group of processes that run all of the time, and then some that run occasionally — this includes the Magazines process, which we can now see ran for 3.6% of the time over the last 3 hours.



  * com.google.android.inputmethod.latin / u0a57:
TOTAL: 100% (6.4MB-6.7MB-6.8MB/5.4MB-5.4MB-5.4MB over 21)
Imp Fg: 100% (6.4MB-6.7MB-6.8MB/5.4MB-5.4MB-5.4MB over 21)
* com.google.process.gapps / u0a8:
TOTAL: 100% (12MB-13MB-14MB/10MB-11MB-12MB over 211)
Imp Fg: 0.11%
Imp Bg: 0.83% (13MB-13MB-13MB/11MB-11MB-11MB over 1)
Service: 99% (12MB-13MB-14MB/10MB-11MB-12MB over 210)
* com.android.systemui / u0a12:
TOTAL: 100% (29MB-32MB-34MB/26MB-29MB-30MB over 21)
Persistent: 100% (29MB-32MB-34MB/26MB-29MB-30MB over 21)
* com.android.phone / 1001:
TOTAL: 100% (6.5MB-7.1MB-7.6MB/5.4MB-5.9MB-6.4MB over 21)
Persistent: 100% (6.5MB-7.1MB-7.6MB/5.4MB-5.9MB-6.4MB over 21)
* com.nuance.xt9.input / u0a77:
TOTAL: 100% (2.3MB-2.5MB-2.7MB/1.5MB-1.5MB-1.5MB over 21)
Persistent: 100% (2.3MB-2.5MB-2.7MB/1.5MB-1.5MB-1.5MB over 21)
* com.android.nfc / 1027:
TOTAL: 100% (4.2MB-4.5MB-4.6MB/3.2MB-3.2MB-3.3MB over 21)
Persistent: 100% (4.2MB-4.5MB-4.6MB/3.2MB-3.2MB-3.3MB over 21)
* com.google.process.location / u0a8:
TOTAL: 100% (13MB-13MB-14MB/10MB-11MB-11MB over 21)
Imp Fg: 100% (13MB-13MB-14MB/10MB-11MB-11MB over 21)
* system / 1000:
TOTAL: 100% (42MB-46MB-56MB/39MB-42MB-48MB over 21)
Persistent: 100% (42MB-46MB-56MB/39MB-42MB-48MB over 21)
* com.google.android.apps.currents / u0a35:
TOTAL: 100% (16MB-16MB-16MB/14MB-14MB-14MB over 17)
Service: 100% (16MB-16MB-16MB/14MB-14MB-14MB over 17)
* com.android.launcher / u0a13:
TOTAL: 77% (25MB-26MB-27MB/22MB-23MB-24MB over 73)
Top: 77% (25MB-26MB-27MB/22MB-23MB-24MB over 73)
(Home): 23% (25MB-26MB-26MB/23MB-23MB-24MB over 12)
* android.process.media / u0a6:
TOTAL: 48% (5.0MB-5.3MB-5.5MB/4.0MB-4.2MB-4.2MB over 11)
Imp Fg: 0.00%
Imp Bg: 0.00%
Service: 48% (5.0MB-5.3MB-5.5MB/4.0MB-4.2MB-4.2MB over 11)
Receiver: 0.00%
(Cached): 22% (4.1MB-4.5MB-4.8MB/3.0MB-3.5MB-3.8MB over 8)
* com.google.android.deskclock / u0a36:
TOTAL: 42% (20MB-21MB-21MB/18MB-19MB-19MB over 8)
Imp Fg: 42% (20MB-21MB-21MB/18MB-19MB-19MB over 8)
Service: 0.00%
Receiver: 0.01%
(Cached): 58% (17MB-20MB-21MB/16MB-18MB-19MB over 14)
* com.android.settings / 1000:
TOTAL: 23% (19MB-22MB-28MB/15MB-19MB-24MB over 31)
Top: 23% (19MB-22MB-28MB/15MB-19MB-24MB over 31)
(Last Act): 77% (9.7MB-14MB-20MB/7.5MB-11MB-18MB over 8)
(Cached): 0.02%
* com.google.android.apps.magazines / u0a59:
TOTAL: 3.6% (10MB-10MB-10MB/8.7MB-9.0MB-9.0MB over 6)
Imp Bg: 0.03%
Service: 3.6% (10MB-10MB-10MB/8.7MB-9.0MB-9.0MB over 6)
(Cached): 17% (9.9MB-10MB-10MB/8.7MB-8.9MB-9.0MB over 5)
* com.android.defcontainer / u0a5:
TOTAL: 1.4% (2.7MB-3.0MB-3.0MB/1.9MB-1.9MB-1.9MB over 7)
Top: 1.2% (3.0MB-3.0MB-3.0MB/1.9MB-1.9MB-1.9MB over 6)
Imp Fg: 0.19% (2.7MB-2.7MB-2.7MB/1.9MB-1.9MB-1.9MB over 1)
Service: 0.00%
(Cached): 15% (2.6MB-2.6MB-2.6MB/1.8MB-1.8MB-1.8MB over 1)
* com.google.android.youtube / u0a78:
TOTAL: 1.3% (9.0MB-9.0MB-9.0MB/7.8MB-7.8MB-7.8MB over 1)
Imp Bg: 1.0% (9.0MB-9.0MB-9.0MB/7.8MB-7.8MB-7.8MB over 1)
Service: 0.27%
Service Rs: 0.01%
Receiver: 0.00%
(Cached): 99% (9.1MB-9.4MB-9.7MB/7.7MB-7.9MB-8.1MB over 24)
* com.google.android.gms / u0a8:
TOTAL: 0.91% (9.2MB-9.2MB-9.2MB/7.6MB-7.6MB-7.6MB over 1)
Imp Bg: 0.79% (9.2MB-9.2MB-9.2MB/7.6MB-7.6MB-7.6MB over 1)
Service: 0.11%
Receiver: 0.00%
(Cached): 99% (8.2MB-9.4MB-10MB/6.5MB-7.6MB-8.1MB over 25)
* com.google.android.gm / u0a44:
TOTAL: 0.56%
Imp Bg: 0.55%
Service: 0.01%
Receiver: 0.00%
(Cached): 99% (11MB-13MB-14MB/10MB-12MB-13MB over 24)
* com.google.android.apps.plus / u0a70:
TOTAL: 0.22%
Imp Bg: 0.22%
Service: 0.00%
Receiver: 0.00%
(Cached): 100% (38MB-40MB-41MB/36MB-38MB-39MB over 17)
* com.google.android.apps.docs / u0a39:
TOTAL: 0.15%
Imp Bg: 0.09%
Service: 0.06%
(Cached): 54% (13MB-14MB-14MB/12MB-12MB-13MB over 17)
* com.google.android.music:main / u0a62:
TOTAL: 0.11%
Imp Bg: 0.04%
Service: 0.06%
Receiver: 0.01%
(Cached): 70% (7.7MB-10MB-11MB/6.4MB-9.0MB-9.3MB over 20)
* com.google.android.apps.walletnfcrel / u0a24:
TOTAL: 0.01%
Receiver: 0.01%
(Cached): 69% (8.1MB-8.4MB-8.6MB/7.0MB-7.1MB-7.1MB over 13)
* com.google.android.setupwizard / u0a19:
TOTAL: 0.00%
Receiver: 0.00%
(Cached): 69% (2.7MB-3.2MB-3.4MB/1.8MB-2.0MB-2.2MB over 13)

Run time Stats:
SOff/Norm: +1h43m29s710ms
SOn /Norm: +1h37m14s290ms
TOTAL: +3h20m44s0ms

Start time: 2013-11-06 07:24:27
Total elapsed time: +3h42m23s56ms (partial) libdvm.so chromeview


Example output of dumpsys procstats --hours 3 command, showing memory details for processes running in the background over the past ~3 hours.



The percentages tell you how much of the overall time each process has spent in various key states. The memory numbers tell you about memory samples in those states, as minPss-avgPss-maxPss / minUss-avgUss-maxUss. The procstats tool also has a number of command line options to control its output — use adb shell dumpsys procstats -h to see a list of the available options.



Comparing this raw data from procstats with the visualization of its data we previously saw, we can see that it is showing only process run data from a subset of states: Imp Fg, Imp Bg, Service, Service Rs, and Receiver. These are the situations where the process is actively running in the background, for as long as it needs to complete the work it is doing. In terms of device memory use, these are the process states that tend to cause the most trouble: apps running in the background taking RAM from other things.



Getting started with procstats



We have already found the new procstats tool to be invaluable in better understanding the overall memory behavior of Android systems, and it has been a key part of the Project Svelte effort in Android 4.4.



As you develop your own applications, be sure to use procstats and the other tools mentioned here to help understand how your own app is behaving, especially how much it runs in the background and how much RAM it uses during that time.




More information about how to analyze and debug RAM use on Android is available on the developer page Investigating Your RAM Usage.


A fast Android Emulator, Genymotion

Genymotion is the next generation of the AndroVM open source project, already trusted by 450,000 developers.

It’s even easier to use and has lots more functionalities. To know more: http://www.genymotion.com/

Lenovo to acquire Motorola Mobility

Just announced at Google Official Blog:

We’ve just signed an agreement to sell Motorola to Lenovo for $2.91 billion. As this is an important move for Android users everywhere, I wanted to explain why in detail. ~ read more: http://googleblog.blogspot.hk/2014/01/lenovo-to-acquire-motorola-mobility.html


Android Community Group@ARM Connected Commuity

Android Community Group
Android is a robust software stack that includes an operating system, middleware and select applications. If you are developing Android apps or devices for mobile phones, tablets, etc., here (http://community.arm.com/groups/android-community) is where you'll find the latest ARM technology including Android porting guides, reference platform information and Linux kernel information including partnership with Linaro. You'll also find useful information on Mali, graphics IP and some of ARM Android porting service partners.

Build native mobile applications using HTML, CSS and JavaScript

Google introduce early developer preview of a toolchain to build native mobile apps using HTML, CSS and JavaScript. The toolchain based on Apache Cordova, an open-source mobile development framework.



The toolchain wraps your Chrome App with a native application shell and enables you to distribute your app via Google Play and the Apple App Store. We provide a simple developer workflow for packaging a Chrome App natively for mobile platforms. You can run your Chrome App on a device or emulator using the command-line or an IDE. Alternatively, you can use the Chrome Apps Developer Tool to run your app on an Android device without the need to install an IDE or the mobile platform’s SDK.

Soure: Chromium Blog: Run Chrome Apps on mobile using Apache Cordova




Programming Google Glass

Google Glass is the new wearable computer everyone's talking about. It offers a head-mounted optical display and touch interface, and it's programmable. Kick-start your Glassware development by exploring how users can interface with Glass, developing a Glass application fast by using the Mirror API to manipulate Timeline cards and menus, tracking a Glass's geolocation, creating rich interactions by responding to user inputs, and capturing or serving user images and videos. This is the book to read for a shortcut to this brave new world.

Google Glass is the next big thing in portable technology---a wearable computer with an optical head-mounted display. Programming Google Glass is your all-inclusive guidebook for crafting your own Glassware using the Mirror API.

You'll start by setting up a production-ready service using Google App Engine, then provide Glass users an authorization to your Glassware. You'll learn how to handle the provided credentials, and from there you'll dive into the parts that make up the Glass interface, managing the timeline and creating cards and menu items. Next you'll create services where the user can interact with your server, such as geolocation tracking, change notifications, and custom menu options. You'll use this information to create a sophisticated application that suggests local restaurants. You'll see how to attach or detach assets, images, and video, and learn the basics of the emerging field of optical-display design. You'll see how to properly design new Glassware and update existing applications to become Glassware.

Now is the best time to be an early adopter of a technology that will only become more advanced, nuanced, and ubiquitous.

What You Need:

You will need a Google Glass device and Java 1.6 or greater. An Android device, like a smart phone or tablet, is also helpful, but not necessary.

Application Development with Qt Creator

Application Development with Qt Creator

A fast-paced guide for building cross-platform applications using Qt and Qt Quick
Overview
  • Introduces the basic concepts of programming using Qt and the Qt Quick framework, with tips and tricks to help you make the most of Qt Creator
  • Shows you how to write cross-platform mobile applications with Qt Creator
  • Full of illustrations and diagrams, with clear step-by-step instructions and practical examples that will help you build cross-platform applications using Qt and Qt Quick
In Detail
Qt Creator is the leading open-source, cross-platform integrated development environment (IDE) for building GUI applications that run on Windows, Mac OS X, Linux, Android, and many embedded systems. It greatly simplifies cross-platform application development, targeting desktop computers, embedded platforms, and mobile systems. If you want to build and debug applications with Qt Creator in no time, then this book is for you.
This book provides a thorough introduction to using Qt Creator to make cross-platform applications that you can read in just a few hours. It covers everything you need to know to build applications with Qt Creator. This book also discusses the facets of Qt Creator that make it a valued software development environment for students and professionals alike.
The book starts by showing you how to get, install, and use Qt Creator, beginning with the basics of how to edit, compile, debug, and run applications. Along the way, you will learn to use Qt to write cross-platform GUI applications for Mac OS X, Windows, Linux, and Android in C++ and Qt Quick.
This book covers how to craft GUIs with Qt Designer, localize applications using Qt Linguist, and profile application performance with Qt Creator's tools and valgrind. You will gain valuable insight in constructing applications using Qt in C++ and Qt Quick, Qt's declarative GUI authoring platform and learn everything you need to know to use Qt Creator effectively as a software developer.
What you will learn from this book
  • Use Qt Creator's editor to edit your application source and resource files
  • Localize applications using Qt Linguist and Qt
  • Design GUI applications using both Qt and Qt Quick
  • Write mobile applications for Android using Qt Creator and Qt Quick
  • Integrate version control with Qt Creator
  • Gain valuable tips known only to professional developers
Approach
Written in a concise and easy-to-follow approach, this book will guide you to develop your first application with Qt with illustrated examples and screenshots
Who this book is written for
If you are a developer who is new to Qt and Qt Creator and is interested in harnessing the power of Qt for cross-platform development, this book is great for you. If you have basic experience programming in C++, you have what it takes to create great cross-platform applications using Qt and Qt Creator!

Developing Android on Android: Automate Your Device with Scripts and Tasks

Developing Android on Android: Automate Your Device with Scripts and Tasks

Take advantage of the open, tinker-friendly Android platform and make your device work the way you want it to. Quickly create Android tasks, scripts, and programs entirely on your Android device--no PC required. Learn how to build your own innovative Android programs and workflows with tools you can run on Android itself, and tailor the Android default user interface to match your mobile lifestyle needs. Apply your favorite scripting language to rapidly develop programs that speak the time and battery level, alert you to important events or locations, read your new email to you, and much more.

Take charge of your Android phone or tablet by creating your own programs and scripts to make your device work for you. Developing Android on Android will teach you how to use the latest cutting-edge technologies to tailor your Android experience to your mobile lifestyle.

Write scripts that listen to your voice and post spoken tweets on Twitter. Track your phone's status and have it report its location every ten minutes via an instant message. Query and listen to weather forecasts with the click of a headset button. Have system notifications and new SMS messages automatically read to you. Design your own application launcher with a look and behavior that can be dynamically modified depending on the scripts and applications you execute.

With step-by-step instructions throughout, you'll master how to develop your own custom applications. And because you'll be using programming tools on your Android, you can change and improve your programs at any time. You'll build new Android programs and task-driven on-board workflows faster than any traditional Android development environment could hope to match!

What You Need

An Android smartphone or tablet running Android 4.0 or higher.


Interactive resizable PopupWindow

This example show how to implement OnTouchListener for PopupWindow to make it resizable inactively.

Interactive resizable PopupWindow
Interactive resizable PopupWindow

package com.example.androidpopupwindow;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.view.ViewGroup.LayoutParams;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.PopupWindow;
import android.widget.Spinner;
import android.app.Activity;

public class MainActivity extends Activity {

String[] DayOfWeek = {"Sunday", "Monday", "Tuesday",
"Wednesday", "Thursday", "Friday", "Saturday"};

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

final Button btnOpenPopup = (Button) findViewById(R.id.openpopup);
btnOpenPopup.setOnClickListener(new Button.OnClickListener() {

@Override
public void onClick(View arg0) {
LayoutInflater layoutInflater =
(LayoutInflater)getBaseContext()
.getSystemService(LAYOUT_INFLATER_SERVICE);
View popupView = layoutInflater.inflate(R.layout.popup, null);
final PopupWindow popupWindow = new PopupWindow(
popupView, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);

Button btnDismiss = (Button)popupView.findViewById(R.id.dismiss);

Spinner popupSpinner = (Spinner)popupView.findViewById(R.id.popupspinner);

ArrayAdapter<String> adapter =
new ArrayAdapter<String>(MainActivity.this,
android.R.layout.simple_spinner_item, DayOfWeek);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
popupSpinner.setAdapter(adapter);

btnDismiss.setOnClickListener(new Button.OnClickListener(){

@Override
public void onClick(View v) {
popupWindow.dismiss();
}});

popupWindow.showAsDropDown(btnOpenPopup, 50, -30);

popupView.setOnTouchListener(new OnTouchListener() {
int orgX, orgY;
int offsetX, offsetY;

int orgWidth, orgHeight;

@Override
public boolean onTouch(View v, MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
orgX = (int) event.getRawX();
orgY = (int) event.getRawY();

orgWidth = v.getMeasuredWidth();
orgHeight = v.getMeasuredHeight();

break;
case MotionEvent.ACTION_MOVE:
offsetX = (int)event.getRawX() - orgX;
offsetY = (int)event.getRawY() - orgY;

//resize PopWindow
popupWindow.update(
orgWidth + offsetX,
orgHeight + offsetY);
break;
}
return true;
}});
}

});
}

}

For other files, such as layout, customborder.xml...etc, refer to last exercise "PopupWindow with transparent background" and "Create background of Popup Window with custom shape".

download filesDownload the files.


Related: Implement drag-and-drop movable PopupWindow

Implement drag-and-drop movable PopupWindow

This example implement OnTouchListener() for PopupWindow to detect user action of drag-and-drop, to move PopupWindow.

movable PopupWindow
Movable PopupWindow

package com.example.androidpopupwindow;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.view.ViewGroup.LayoutParams;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.PopupWindow;
import android.widget.Spinner;
import android.app.Activity;

public class MainActivity extends Activity {

String[] DayOfWeek = {"Sunday", "Monday", "Tuesday",
"Wednesday", "Thursday", "Friday", "Saturday"};

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

final Button btnOpenPopup = (Button) findViewById(R.id.openpopup);
btnOpenPopup.setOnClickListener(new Button.OnClickListener() {

@Override
public void onClick(View arg0) {
LayoutInflater layoutInflater =
(LayoutInflater)getBaseContext()
.getSystemService(LAYOUT_INFLATER_SERVICE);
View popupView = layoutInflater.inflate(R.layout.popup, null);
final PopupWindow popupWindow = new PopupWindow(
popupView, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);

Button btnDismiss = (Button)popupView.findViewById(R.id.dismiss);

Spinner popupSpinner = (Spinner)popupView.findViewById(R.id.popupspinner);

ArrayAdapter<String> adapter =
new ArrayAdapter<String>(MainActivity.this,
android.R.layout.simple_spinner_item, DayOfWeek);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
popupSpinner.setAdapter(adapter);

btnDismiss.setOnClickListener(new Button.OnClickListener(){

@Override
public void onClick(View v) {
popupWindow.dismiss();
}});

popupWindow.showAsDropDown(btnOpenPopup, 50, -30);

popupView.setOnTouchListener(new OnTouchListener() {
int orgX, orgY;
int offsetX, offsetY;

@Override
public boolean onTouch(View v, MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
orgX = (int) event.getX();
orgY = (int) event.getY();
break;
case MotionEvent.ACTION_MOVE:
offsetX = (int)event.getRawX() - orgX;
offsetY = (int)event.getRawY() - orgY;
popupWindow.update(offsetX, offsetY, -1, -1, true);
break;
}
return true;
}});
}

});
}

}

For other files, such as layout, customborder.xml...etc, refer to last exercise "PopupWindow with transparent background" and "Create background of Popup Window with custom shape".

download filesDownload the files.



Related: Interactive resizable PopupWindow

Create background of Popup Window with custom shape

Last example display "PopupWindow with transparent background". I want to have transparent background with visible border. This example create background with custom shape, have rounded border, semi-transparent background.

Popup Window with background of custom shape
Popup Window with background of custom shape
Create /res/drawable/customborder.xml to define custom shape.
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners
android:topLeftRadius="0dp"
android:topRightRadius="30dp"
android:bottomRightRadius="30dp"
android:bottomLeftRadius="30dp" />
<stroke
android:width="3dp"
android:color="@android:color/background_dark" />
<solid
android:color="#800000c0"/>
</shape>

Modify /res/layout/popup.xml to define android:background="@drawable/customborder".
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/customborder"
android:orientation="vertical" >

<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="1dp"
android:orientation="vertical" >

<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="20dp"
android:orientation="vertical" >

<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="It's a PopupWindow" />

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

<Spinner
android:id="@+id/popupspinner"
android:spinnerMode="dialog"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />

<Button
android:id="@+id/dismiss"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Dismiss" />
</LinearLayout>
</LinearLayout>

</LinearLayout>

download filesDownload the files.

Next: Implement drag-and-drop movable PopupWindow

PopupWindow with transparent background

PopupWindow with transparent background
PopupWindow with transparent background
A simple way to make background of PopupWindow transparent, you can define android:background="@android:color/transparent" in layout XML of the PopupWindow.

popup.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@android:color/transparent"
android:orientation="vertical" >

<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="1dp"
android:orientation="vertical" >

<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="20dp"
android:orientation="vertical" >

<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="It's a PopupWindow" />

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

<Spinner
android:id="@+id/popupspinner"
android:spinnerMode="dialog"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />

<Button
android:id="@+id/dismiss"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Dismiss" />
</LinearLayout>
</LinearLayout>

</LinearLayout>

MainActivity.java
package com.example.androidpopupwindow;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup.LayoutParams;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.PopupWindow;
import android.widget.Spinner;
import android.app.Activity;

public class MainActivity extends Activity {

String[] DayOfWeek = {"Sunday", "Monday", "Tuesday",
"Wednesday", "Thursday", "Friday", "Saturday"};

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

final Button btnOpenPopup = (Button) findViewById(R.id.openpopup);
btnOpenPopup.setOnClickListener(new Button.OnClickListener() {

@Override
public void onClick(View arg0) {
LayoutInflater layoutInflater =
(LayoutInflater)getBaseContext()
.getSystemService(LAYOUT_INFLATER_SERVICE);
View popupView = layoutInflater.inflate(R.layout.popup, null);
final PopupWindow popupWindow = new PopupWindow(
popupView, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);

Button btnDismiss = (Button)popupView.findViewById(R.id.dismiss);

Spinner popupSpinner = (Spinner)popupView.findViewById(R.id.popupspinner);

ArrayAdapter<String> adapter =
new ArrayAdapter<String>(MainActivity.this,
android.R.layout.simple_spinner_item, DayOfWeek);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
popupSpinner.setAdapter(adapter);

btnDismiss.setOnClickListener(new Button.OnClickListener(){

@Override
public void onClick(View v) {
popupWindow.dismiss();
}});

popupWindow.showAsDropDown(btnOpenPopup, 50, -30);
}

});
}

}

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

<Button
android:id="@+id/openpopup"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Open Popup Window" />

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

</LinearLayout>

download filesDownload the files.

Next: Creat background of Popup Window with custom shape

javafxports , a JavaFX on Android Porting Community

javafxports host a JavaFX Android community project. It contains instructions on how to run JavaFX applications on Android. The code is available at https://bitbucket.org/javafxports/android-graphics-rt.


Creating JavaFX Applications that also run on Android devices is not that hard. This project contains everything that is required to build a Java(FX) runtime for Android devices, along with instructions on how to create an Android project based on an existing Java Project. You can choose to either build the runtime yourself, or download one in the Downloads section of this project. The brave ones can build their own runtime. -- follow the instructions to build the runtime on Linux and MacOS.



Android Application Security Essentials

Android Application Security Essentials
Write secure Android applications using the most up-to-date techniques and concepts
Overview
  • Understand Android security from kernel to the application layer
  • Protect components using permissions
  • Safeguard user and corporate data from prying eyes
  • Understand the security implications of mobile payments, NFC, and more
In Detail
In today’s techno-savvy world, more and more parts of our lives are going digital, and all this information is accessible anytime and anywhere using mobile devices. It is of the utmost importance that you understand and implement security in your apps that will reduce the likelihood of hazards that will wreck your users' experience.
"Android Application Security Essentials" takes a deep look into Android security from kernel to the application level, with practical hands-on examples, illustrations, and everyday use cases. This book will show you how to overcome the challenge of getting the security of your applications right.
"Android Application Security Essentials" will show you how to secure your Android applications and data. It will equip you with tricks and tips that will come in handy as you develop your applications.
We will start by learning the overall security architecture of the Android stack. Securing components with permissions, defining security in a manifest file, cryptographic algorithms and protocols on the Android stack, secure storage, security focused testing, and protecting enterprise data on your device is then also discussed in detail. You will also learn how to be security-aware when integrating newer technologies like NFC and mobile payments into your Android applications.
At the end of this book, you will understand Android security at the system level all the way to the nitty-gritty details of application security for securing your Android applications.
What you will learn from this book
  • Get familiar with Android security architecture
  • Secure Android components using permissions
  • Implement cryptography algorithms and protocols to secure your data
  • Protect user information both at rest and in transit
  • Test apps for security
  • Understand security considerations for upcoming use cases like NFC and mobile payments
  • Guard the corporate data of enterprises apps
Approach
"Android Application Security Essentials" is packed with examples, screenshots, illustrations, and real world use cases to secure your apps the right way.
Who this book is written for
If you are looking for guidance and detailed instructions on how to secure app data, then this book is for you. Developers, architects, managers, and technologists who wish to enhance their knowledge of Android security will find this book interesting. Some prior knowledge of development on the Android stack is desirable but not required.

Learning Android: Develop Mobile Apps using Java and Eclipse

Learning Android: Develop Mobile Apps using Java and Eclipse

Want to build apps for Android devices? This book is the perfect way to master the fundamentals. Written by experts who have taught this mobile platform to hundreds of developers in large organizations and startups alike, this gentle introduction shows experienced object-oriented programmers how to use Android’s basic building blocks to create user interfaces, store data, connect to the network, and more.
Throughout the book, you’ll build a Twitter-like application, adding new features with each chapter. You’ll also create your own toolbox of code patterns to help you program any type of Android application with ease.
  • Become familiar with the Android platform and how it fits into the mobile ecosystem
  • Dive into the Android stack, including its application framework and the APK application package
  • Learn Android’s building blocks: Activities, Intents, Services, Content Providers, and Broadcast Receivers
  • Create basic Android user interfaces and organize UI elements in Views and Layouts
  • Build a service that uses a background process to update data in your application
January 31, 2014  1449319238  978-1449319236 Second Edition

HTC One X and One X+ will not get KitKat update...!!!

It's posted in HTC UK’s twitter account that "the One X+ will not receive further Android updates & will remain on the current version of Android". That means both HTC One X and One X+ will not get KitKat update...!!!

ByeByeHTC
#ByeByeHTC


Example of ListFragment inside DrawerLayout

This exercise implement android.app.ListFragment inside DrawerLayout. The ListFragment part refer to my another old post. If you are looking for ListView inside DrawLayout, read last post.

ListFragment inside DrawerLayout
ListFragment inside DrawerLayout

In order to use android.app.ListFragment in your app, AndroidManifest.xml have to be modified to define android:minSdkVersion="11".

Create /res/layout/listfragment1.xml to define the layout of our ListFragment.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingLeft="8dp"
android:paddingRight="8dp" >

<ListView
android:id="@id/android:list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:drawSelectorOnTop="false" />

<TextView
android:id="@id/android:empty"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="No data" />

</LinearLayout>

Create MyListFragment1.java extends ListFragment.
package com.example.androiddrawerlayout;

import android.app.ListFragment;
import android.os.Bundle;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.Toast;

public class MyListFragment1 extends ListFragment {

String[] month = { "January", "February", "March", "April", "May", "June",
"July", "August", "September", "October", "November", "December" };

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ListAdapter myListAdapter = new ArrayAdapter<String>(getActivity(),
android.R.layout.simple_list_item_1, month);
setListAdapter(myListAdapter);
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
return inflater.inflate(R.layout.listfragment1, container, false);
}

@Override
public void onListItemClick(ListView l, View v, int position, long id) {
// TODO Auto-generated method stub
Toast.makeText(getActivity(),
getListView().getItemAtPosition(position).toString(),
Toast.LENGTH_LONG).show();
}
}

Modify /res/layout/activity_main.xml to include <fragment> of "com.example.androiddrawerlayout.MyListFragment1" inside drawer.
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent" >

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/background_light"
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="Main layout" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:autoLink="web"
android:text="http://arteluzevida.blogspot.com/"
android:textStyle="bold" />

<Button
android:id="@+id/opendrawer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Open Drawer" />

<TextView
android:id="@+id/prompt"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="right" />

<TextView
android:id="@+id/prompt2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="right" />

<TextView
android:id="@+id/selection"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="right" />
</LinearLayout>

<LinearLayout
android:id="@+id/drawer"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="@android:color/background_light"
android:orientation="vertical"
android:padding="5dp" >

<fragment
android:id="@+id/fragment1"
android:name="com.example.androiddrawerlayout.MyListFragment1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1" />
</LinearLayout>

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

MainActivity.java
package com.example.androiddrawerlayout;

import android.os.Bundle;
import android.app.Activity;
import android.support.v4.widget.DrawerLayout;
import android.support.v4.widget.DrawerLayout.DrawerListener;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

public class MainActivity extends Activity {

DrawerLayout drawerLayout;
View drawerView;
TextView textPrompt, textPrompt2;
TextView textSelection;

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

textPrompt = (TextView)findViewById(R.id.prompt);
textPrompt2 = (TextView)findViewById(R.id.prompt2);

drawerLayout = (DrawerLayout)findViewById(R.id.drawer_layout);
drawerView = (View)findViewById(R.id.drawer);

Button buttonOpenDrawer = (Button)findViewById(R.id.opendrawer);
buttonOpenDrawer.setOnClickListener(new OnClickListener(){

@Override
public void onClick(View arg0) {
drawerLayout.openDrawer(drawerView);
}});

drawerLayout.setDrawerListener(myDrawerListener);

/*
* In my trial experiment:
* Without dummy OnTouchListener for the drawView to
* consume the onTouch event, touching/clicking on
* un-handled view on drawView will pass to the view
* under it!
* - Touching on the Android icon will
* trigger the TextView("http://arteluzevida.blogspot.com/")
* to open the web.
*/
/*
drawerView.setOnTouchListener(new OnTouchListener() {

@Override
public boolean onTouch(View v, MotionEvent event) {
// TODO Auto-generated method stub
return true;
}
});
*/

textSelection = (TextView)findViewById(R.id.selection);
}

DrawerListener myDrawerListener = new DrawerListener(){

@Override
public void onDrawerClosed(View drawerView) {
textPrompt.setText("onDrawerClosed");
}

@Override
public void onDrawerOpened(View drawerView) {
textPrompt.setText("onDrawerOpened");
}

@Override
public void onDrawerSlide(View drawerView, float slideOffset) {
textPrompt.setText("onDrawerSlide: " + String.format("%.2f", slideOffset));
}

@Override
public void onDrawerStateChanged(int newState) {
String state;
switch(newState){
case DrawerLayout.STATE_IDLE:
state = "STATE_IDLE";
break;
case DrawerLayout.STATE_DRAGGING:
state = "STATE_DRAGGING";
break;
case DrawerLayout.STATE_SETTLING:
state = "STATE_SETTLING";
break;
default:
state = "unknown!";
}

textPrompt2.setText(state);
}};

}



download filesDownload the files.