Saturday, August 8, 2020

Android 11 is almost ready

Android 11 is almost ready and we have got beta release from google now.

Google calling it as release candidate for final release. 

 https://developer.android.com/android11

Monday, April 11, 2016

SQL Performance enhancement for count function

SQL count aggregate function with case is helpful to reduce time to process sql db.
If you want count for any column bases on the value we can use the count function with case to reduce the processing time.

e..g. select count(case column1 when 'value1' then 1 else null end) as count1, count(case column1 when 'value2' then 1 else null end) as count2 from table1

Wednesday, February 24, 2016

Gradle

The Gradle build system


Since the Gradle build system (http://www.gradle.org) gets more and more attention I decided to have a look at how it works. This article should give you a brief overview of some of the features so that you get the taste of Gradle. It is not meant to be a tutorial to get you started and it’s recommended that you know about another build system.

What is it?

Gradle is a build system that combines and extends the best features of Ant and Maven. It supports task based build processes like Ant and follows convention over configuration like Maven. On top of that, Gradle build scripts are written in the Groovy language allowing to define more complex behaviour in cases where it is necessary. But you don’t need to be a Groovy expert because Gradle comes with a domain specific language (DSL) to define the builds.
Dependencies can be managed using Ivy and Maven repositories or by yourself if that is required. Most of the behaviour is defined in Gradle plug-ins that ship with its distribution. They can be used out of the box and adapted to your needs.

A simple example

A simple example of a build.gradle script for a Java project looks like this:
1
apply plugin: 'java'
It expects the default layout from Maven which consists of src/main/java, src/main/resource, src/test/java and src/test/resource. And it expects the source to be compatible with the current JVM it is running on. To change these properties of the ‘java’ plug-in you can use Gradle’s DSL:
1
2
sourceSets.main.java.srcDirs = ['src/java', 'src/generated']
sourceCompatibility = 1.6

Dependency management

Repositories

Gradle can access Maven and Ivy repositories. Here are some samples how to configure the repositories:
1
2
3
4
5
6
7
8
9
10
11
12
13
repositories {
  mavenLocal()
  maven {
  }
  mavenCentral()
}
repositories {
  ivy {
  }
}
The look-ups will be done in the order given within the repositories section. So in the above Maven example it will first look in the local repository of the user, then on the company’s server and finally on Maven Central.

Dependencies

To depend on an internal module, i.e. a module from the same project, you just write:
1
2
3
dependencies {
  compile project(':shared')
}
You can also add dependencies to external modules from Maven or Ivy repositories if you have defined them as described above.
1
2
3
4
dependencies {
  runtime group: 'org.hibernate', name: 'hibernate', version: '3.0.5'
  testRuntime 'org.mockito:mockito-core:1.8.4'
}
The above sample contains the long and the short version of a module identifier. If you have a dependency on a local file then you can specify it with:
1
2
3
4
dependencies {
  compile files('libs/a.jar', 'libs/b.jar')
  testCompile fileTree(dir: 'testlibs', include: '*.jar')
}
More sophisticated features can be found in the documentation and include stuff like:
  • overwriting transitive dependencies
  • use Ivy specific dependency features
  • etc.

Tasks

Tasks are the central building blocks of the build process. They consist of two lists of actions. One list is to configure the task and the other to execute it. Here is a sample:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
// Just define an empty task
task myTaskA
// Add a configuration action
myTaskA {
  println "config A"
}
// Add an execution action
myTaskA << {
  println "action A"
}
// Another task depending on myTaskA with configuration and action
task myTaskB (dependsOn: myTaskA) {
  println "config B"
  doLast {
    println "action B"
  }
}
Now you can start it:
1
$ gradle myTaskB
The configuration steps will be executed first. And since myTaskB depends on myTaskA the output will be:
1
2
3
4
5
6
7
8
config A
config B
:myTaskA
action A
:myTaskB
action B
BUILD SUCCESSFUL
Tasks can also be of a predefined type. The follwoing example uses the JavaExec type to start some Java code:
1
2
3
4
5
6
7
8
9
10
apply plugin: 'java'
// dependencies, repositories etc.
task startMain(type: JavaExec, dependsOn: classes) {
  main = 'mypackage.Main'
  args = "-x -y -z".split().toList()
  classpath sourceSets.main.classesDir
  classpath configurations.compile
}
The command gradle startMain prepares the classes and then starts the program using the classes and also the external dependencies as classpath.

Maven sample comparison

Just to be clear: this is not an A is better than B comparison. The purpose is only to show you the two different versions of a Maven and a Gradle build script that achieve the same thing.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
   <modelVersion>4.0.0</modelVersion>
   <groupId>ch.bbv.mavendemo</groupId>
   <artifactId>simpleMavenDemo</artifactId>
   <version>0.0.1-SNAPSHOT</version>
   <properties>
       <java.source.version>1.7</java.source.version>
       <junit.version>4.8.2</junit.version>
   </properties>
   <dependencies>
       <dependency>
           <groupId>junit</groupId>
           <artifactId>junit</artifactId>
           <version>${junit.version}</version>
           <scope>test</scope>
       </dependency>
   </dependencies>
   <build>
       <plugins>
           <plugin>
               <artifactId>maven-compiler-plugin</artifactId>
               <version>2.3.1</version>
               <configuration>
                   <source>${java.source.version}</source>
                   <target>${java.source.version}</target>
               </configuration>
           </plugin>
       </plugins>
   </build>
</project>
In Gradle this would be:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
apply plugin: 'java'
apply plugin: 'maven'
group = 'ch.bbv.gradledemo'
version = '0.0.1-SNAPSHOT'
//the default artifact id is the project name, which is per default the directory name of the project
project.ext.junitVersion='4.8.2'
sourceCompatibility = 1.7
targetCompatibility = 1.7
repositories {
   mavenCentral()
}
dependencies {
   testCompile 'junit:junit:'+junitVersion
}
The ‘maven’ plug-in allows you to install the artifact in your local Maven repository. Gradle’s DSL makes the build script much easier to read. Of course one could use polyglot Maven but that didn’t take off yet.

IDE integration

The first thing I tried was the Gradle plug-in called ‘eclipse’ (it’s a bit unlucky that everything is now called plug-in). This plug-in can generate eclipse configuration files with settings, project and classpath. This works quite well but you have to update and refresh the project yourself after changing the build.gradle file.
The opposite way around there are also plug-ins for eclipse. The first one is Groovy support so you can edit Groovy code in eclipse. The second one is the Gradle plug-in itself which manages the dependencies of your project, allows you to start Gradle tasks and more.
There is support for other IDEs as well. The current state of tooling can be found here: http://www.gradle.org/tooling

Documentation

Gradle comes with a comprehensive set of documentation including a user guide, reference material and even a book titled “Building and Testing with Gradle”. You can read the book online if you register on Gradleware’s web site. It’s a good read and covers all the stuff you need to get started with Gradle.
The user guide documents all the parts of Gradle and will be continuously extended as Gradle grows. The reference material is generated Java/Groovy doc for Gradle’s API and DSL.

Conclusion

I see three scenarios where Gradle can be a good candidate for your build system.
  1. If you are currently using Ant and the build.xmls get too complicated to handle. With the task based build and the support for existing Ant tasks, Gradle support the migration from Ant.
  2. You have trouble to get Maven to do what you want and maybe already started to write your own Maven plug-ins. Gradle supports the convention over configuration paradigm similar to Maven but can also be scripted with Groovy to do more powerful stuff.
  3. You start a new project.
Gradle as a build system makes a very good impression to me. Hopefully there will be more plug-ins developed when more and more projects use it. I’ve seen that a Jacoco plug-in is under development for example. Gradle itself will continuously be extended and there is also a short- and long-term road-map available. It is licensed under the Apache License, Version 2.0 and is used by open source projects like Spring and Hibernate and also by commercial entities.
Even though it has a bit of a steep learning curve it is worth a closer look.

This entry was posted in ALM, Java and tagged , , . Bookmark the permalink.

Tuesday, May 28, 2013

Firefox OS

FireFox OS

Firefox OS is a new mobile operating system developed by Mozilla. It uses a Linux kernel and boots into a Gecko-based runtime engine, which lets users run applications developed entirely using HTMLJavaScript, and other open web application APIs.
Firefox OS is currently under heavy development; we are constantly working on ways to make it easier for you to use and hack on Gaia (the default set of apps) and create your own. However, you need knowledge about systems in order to do things like build the entire Firefox OS stack, or flash a phone with a build of Firefox OS. Linked below are guides meant for Web developers interested in running and making changes to Gaia or developing apps to run on Firefox OS devices.
Here are the steps to install firefox os on your phone

http://support.mozilla.org/en-US/kb/download-and-install-applications-firefox-os

receive screen OnOff or Headset plug broadcast


There are some broadcast in android which you can't detect just declaring receiver with intent-filters in Android-Manifest.xml to detect them you need one active component service or activity which will register Custom broadcast receiver at run time as follows 


MyReceiver br = new MyReceiver();
IntentFilter theFilter1 = new IntentFilter(Intent.ACTION_HEADSET_PLUG);
IntentFilter theFilter2 = new IntentFilter(Intent.ACTION_SCREEN_ON);
registerReceiver(br, theFilter1);
registerReceiver(br, theFilter2);

Monday, February 18, 2013

Android Emulator soft/hard key shortcuts

Android Emulator soft/hard key shortcuts

Home            Home Button
F2                  Left Softkey / Menu / Settings button (or Page up)
Shift+f2         Right Softkey / Star button (or Page down)
Esc                Back Button
F3                 Call/ dial Button
F4                 Hang up / end call button
F5                 Search Button
Ctrl+F5         Volume up (or + on numeric keyboard with Num Lock off)
Ctrl+F6         Volume down (or + on numeric keyboard with Num Lock off)
F7                 Power Button
Ctrl+F3        Camera Button
Ctrl+F11      Switch layout orientation portrait/landscape backwards
Ctrl+F12      Switch layout orientation portrait/landscape forwards
F8                Toggle cell network
F9               Toggle code profiling
Alt+Enter   Toggle fullscreen mode
F6               Toggle trackball mode

Monday, January 21, 2013

Micromax A116 Canvas HD goes official with 5" screen, quad CPU

Micromax has announced the latest Canvas series smartphone today and it is called A116 Canvas HD unlike the rumours of Canvas 3. Packing a MediaTek 6589 quad-core processor, it will go on sale starting the first week of next month (i.e. February). Company has revealed that it wants to price A116 Canvas HD under INR 15K, which will surely make it an instant hit.
We thought it was time that we compared Micromax A116 with previous iteration of Canvas smartphones from Micromax.


Micromax A116 is significant improvement over the previous versions, considering that it packs a 720p display, quad-core processor and 1GB RAM. Canvas 1 and Canvas only have 512MB RAM, single and dual core processors respectively and WVGA resolution displays.

Tuesday, October 9, 2012

opengl with android part I

OpenGL 

OpenGL (originally called Open Graphics Library) is a 2D and 3D graphics API that was
developed by Silicon Graphics, Inc. (SGI) for its Unix workstations. Although SGI’s
version of OpenGL has been around for a long time, the first standardized spec of
OpenGL emerged in 1992. Now widely adopted on all operating systems, the OpenGL
standard forms the basis of much of the gaming, computer-aided design (CAD), and
even virtual reality (VR) industries.
The OpenGL standard is currently being managed by an industry consortium called The
Khronos Group (http://www.khronos.org), founded in 2000 by companies such as
NVIDIA, Sun Microsystems, ATI Technologies, and SGI. You can learn more about the
OpenGL spec at the consortium’s web site:
http://www.khronos.org/opengl/

The official documentation page for OpenGL is available here:
http://www.opengl.org/documentation/

OpenGL ES

The Khronos Group is also responsible for two additional standards that are tied to
OpenGL: OpenGL ES, and the EGL Native Platform Graphics Interface (known simply as
EGL). As we mentioned, OpenGL ES is a smaller version of OpenGL intended for
embedded systems.
The EGL standard is essentially an enabling interface between the underlying operating
system and the rendering APIs offered by OpenGL ES. Because OpenGL and OpenGL
ES are general-purpose interfaces for drawing, each operating system needs to provide
a standard hosting environment for OpenGL and OpenGL ES to interact with. Android
SDK, starting with its 1.5 release, hides these platform specifics quite well. We will learn
about this in the second section titled “Interfacing OpenGL ES with Android.”

Fundamentals of OpenGL
This section will help you understand the concepts behind OpenGL and the OpenGL ES
API. We’ll explain all the key APIs. To supplement the information from this chapter, you
might want to refer to the “Resources” section towards the end of this chapter. The
indicated resources there include the Red book, JSR 239 documentation, and the
Khronps Group API reference.

here is list of some of this api

glVertexPointer
glDrawElements
 glColor
 glClear
 gluLookAt
glFrustum
 glViewport

cheapest dual core android india stellar horizon

cheapest dual core android india  stellar horizon



General Information
Brand Spice
Model Mi-500 Stellar Horizon
Weight 0 G
Form Factor Touch Bar
Dimensions 0x0x0 MM
Operating Frequency GSM 900 / 1800 / UMTS 2100 MHz | GSM 900 / 1800 / UMTS 2100 MHz
Dual Sim Yes, Dual SIM, Dual Standby
Touch Screen Yes, Capacitive Touchscreen

Display Details
Display Color 5.0 inches Capacitive Touchscreen
Display Size Spice Mi-500 Stellar Horizon has a display size of 480 x 800 px

Camera
Camera Yes, Rear Camera : 5.0 MP Camera (2592x1944 Pixels) with Auto Focus and LED Flash, Front Camera : 0.3 MP, VGA Camera (640x480 Pixels)
Camera Res. 2592 x 1944 Pixels 
Zoom Yes, Digital Zoom
Video Yes
Video Recording Yes
Video Player Yes, MP4 Player

Software
Games Yes
Java Yes
Browser Yes
Operating System Android OS, v2.3 (Gingerbread), upgrade to v4.0

Call Records
Phone Book Practically Unlimited
Missed Calls Practically unlimited
Received Calls Practically unlimited
Dialed Calls Practically unlimited

Battery
Stand By Time N/A
Talk Time N/A
Li-ion 2150 mAH
Memory
Internal Memory Yes, Internal Memory : 4 GB ROM + 512 MB RAM
External Memory Yes, Up to 32 GB
Memory Slot Yes, Micro SD/T-Flash Card

Message
SMS Yes
MMS Yes
Email Yes
Instant Messaging Yes
Social Networking Services Yes

Music
Ring Tone Vibration, Polyphonic, MP3
FM Yes, FM Radio
Music Yes, Music Formats : MP3, AAC, AAC+, WAV with Loud Speaker, 3.5mm Audio Jack
Speaker Yes
Headset Yes

Data
GPRS Yes
Bluetooth Yes
Wirless Protocol Yes, Wi-Fi 802.11 b/g, Wi-Fi Tethering
Port Yes, USB Port
Edge Yes
Infra Red No
3G Yes
GPS Yes
CPU Yes, Dual core 1GHz processor
Salespack Handset, Battery, Charger, Earphone, USB Cable, User Manual, Warranty Card

Others
Applications :
Secured by NQ Mobile Security Apps

Colours
Black




Spice MI-500

Wednesday, August 8, 2012

create nice looking ListView filter on Android

First, you need to create an XML layout that has both an EditText, and a ListView.
<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <!-- Pretty hint text, and maxLines -->
    <EditText android:id="@+building_list/search_box" 
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:hint="type to filter"
        android:inputType="text"
        android:maxLines="1"/>

    <!-- Set height to 0, and let the weight param expand it -->
    <!-- Note the use of the default ID! This lets us use a 
         ListActivity still! -->
    <ListView android:id="@android:id/list"
        android:layout_width="fill_parent"
        android:layout_height="0dip"
        android:layout_weight="1" 
         /> 
</LinearLayout>
This will lay everything out properly, with a nice EditText above the ListView. Next, create a ListActivity as you would normally, but add a setContentView() call in the onCreate() method so we use our recently declared layout. Remember that we ID'ed the ListView specially, with android:id="@android:id/list". This allows the ListActivity to know which ListView we want to use in our declared layout.
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.filterable_listview);

        setListAdapter(new ArrayAdapter<String>(this,
                       android.R.layout.simple_list_item_1, 
                       getStringArrayList());
    }
Running the app now should show your previous ListView, with a nice box above. In order to make that box do something, we need to take the input from it, and make that input filter the list. While a lot of people have tried to do this manually, most ListView Adapter classes come with a Filter object that can be used to perform the filtering automagically. We just need to pipe the input from the EditText into the Filter. Turns out that is pretty easy. To run a quick test, add this line to your onCreate() call
adapter.getFilter().filter(s);
Notice that you will need to save your ListAdapter to a variable to make this work - I have saved my ArrayAdapter<String> from earlier into a variable called 'adapter'.
Next step is to get the input from the EditText. This actually takes a bit of thought. You could add an OnKeyListener() to your EditText. However, this listener only receives some key events. For example, if a user enters 'wyw', the predictive text will likely recommend 'eye'. Until the user chooses either 'wyw' or 'eye', your OnKeyListener will not receive a key event. Some may prefer this solution, but I found it frustrating. I wanted every key event, so I had the choice of filtering or not filtering. The solution is a TextWatcher. Simply create and add a TextWatcher to the EditText, and pass the ListAdapter Filter a filter request every time the text changes. Remember to remove the TextWatcher in OnDestroy()! Here is the final solution:
private EditText filterText = null;
ArrayAdapter<String> adapter = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.filterable_listview);

    filterText = (EditText) findViewById(R.id.search_box);
    filterText.addTextChangedListener(filterTextWatcher);

    setListAdapter(new ArrayAdapter<String>(this,
                   android.R.layout.simple_list_item_1, 
                   getStringArrayList());
}
private TextWatcher filterTextWatcher = new TextWatcher() {

    public void afterTextChanged(Editable s) {
    }

    public void beforeTextChanged(CharSequence s, int start, int count,
            int after) {
    }

    public void onTextChanged(CharSequence s, int start, int before,
            int count) {
        adapter.getFilter().filter(s);
    }
};
@Override
protected void onDestroy() {
    super.onDestroy();
    filterText.removeTextChangedListener(filterTextWatcher);
}

convert Drawable to Bitmap

This piece of code helps.
 
Bitmap icon = BitmapFactory.decodeResource(context.getResources(),
                                           R.drawable.icon_resource);
Edit: Here a version where the image gets downloaded.
String name = c.getString(str_url);
URL url_value = new URL(name);
ImageView profile = (ImageView)v.findViewById(R.id.vdo_icon);
if (profile != null) {
    Bitmap mIcon1 =
        BitmapFactory.decodeStream(url_value.openConnection().getInputStream());
    profile.setImageBitmap(mIcon1);
}
 
This converts a BitmapDrawable to a Bitmap.
Drawable d = ImagesArrayList.get(0);  Bitmap bitmap = ((BitmapDrawable)d).getBitmap();
 

transparent activity android

Add the following style In your res/values/styles.xml file (if you don’t have one, create it.) Here’s a complete file:
<?xml version="1.0" encoding="utf-8"?>
<resources>
  <style name="Theme.Transparent" parent="android:Theme">
    <item name="android:windowIsTranslucent">true</item>
    <item name="android:windowBackground">@android:color/transparent</item>
    <item name="android:windowContentOverlay">@null</item>
    <item name="android:windowNoTitle">true</item>
    <item name="android:windowIsFloating">true</item>
    <item name="android:backgroundDimEnabled">false</item>
  </style>
</resources>
(the value @color/transparent is the color value #00000000 which I put in res/values/color.xml file. You can also use @android:color/transparent in later Android versions)
Then apply the style to your activity, for example:
<activity android:name=".SampleActivity" android:theme="@style/Theme.Transparent">
...</activity>

pick a image from gallery (SD Card) for my app in android

Here's some sample code on how to do that:
protected void onActivityResult(int requestCode, int resultCode, Intent imageReturnedIntent) { 
    super.onActivityResult(requestCode, resultCode, imageReturnedIntent); 

    switch(requestCode) { 
    case REQ_CODE_PICK_IMAGE:
        if(resultCode == RESULT_OK){  
            Uri selectedImage = imageReturnedIntent.getData();
            String[] filePathColumn = {MediaStore.Images.Media.DATA};

            Cursor cursor = getContentResolver().query(selectedImage, filePathColumn, null, null, null);
            cursor.moveToFirst();

            int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
            String filePath = cursor.getString(columnIndex);
            cursor.close();


            Bitmap yourSelectedImage = BitmapFactory.decodeFile(filePath);
        }
    }
}

set HttpResponse timeout for Android in Java

HttpGet httpGet = new HttpGet(url);
HttpParams httpParameters = new BasicHttpParams();
// Set the timeout in milliseconds until a connection is established.
// The default value is zero, that means the timeout is not used. 
int timeoutConnection = 3000;
HttpConnectionParams.setConnectionTimeout(httpParameters, timeoutConnection);
// Set the default socket timeout (SO_TIMEOUT) 
// in milliseconds which is the timeout for waiting for data.
int timeoutSocket = 5000;
HttpConnectionParams.setSoTimeout(httpParameters, timeoutSocket);
DefaultHttpClient httpClient = new DefaultHttpClient(httpParameters);
HttpResponse response = httpClient.execute(httpGet);

If you want to set the Parameters of any existing HTTPClient (e.g. DefaultHttpClient or AndroidHttpClient) you can use the function setParams().
httpClient.setParams(httpParameters);

check internet access on android

here is the code which will help to check internet available

public boolean isOnline() {
    ConnectivityManager cm =
        (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo netInfo = cm.getActiveNetworkInfo();
    if (netInfo != null && netInfo.isConnectedOrConnecting()) {
        return true;
    }
    return false;
}

Tutorials and libraries for OpenGL-ES games on Android

Android tutorials:
Other Android OpenGL-ES information:
iPhone OpenGL-ES tutorials (where the OpenGl-ES information is probably useful):
As for libraries which a beginner might use to get a simpler hands-on experience with OpenGL-ES, I have only found Rokon, which is recently started, thus has many holes and bugs. And it's gnuGPL licensed (at the moment) which means it cannot be used, if we wish to sell our games.

1.  INsanityDesign
2.  nehe

Monday, August 6, 2012

Difference between Corona, Phonegap, Titanium



  1. PhoneGap is not just a native wrapper of a web app. Through the PhoneGap javascript APIs, the "web app" has access to the mobile phone functions such as Geolocation, Accelerometer Camera, Contacts, Database, File system, etc. Basically any function that the mobile phone SDK provides can be "bridged" to the javascript world. On the other hand, a normal web app that runs on the mobile web browser does not have access to most of these functions (security being the primary reason). Therefore, a PhoneGap app is more of a mobile app than a web app. You can certainly use PhoneGap to wrap a web app that does not use any PhoneGap APIs at all, but that is not what PhoneGap was created for.
  2. Titanium does NOT compile your html, css or javascript code into "native bits". They are packaged as resources to the executable bundle, much like an embedded image file. When the application runs, these resources are loaded into a UIWebView control and run there (as javascript, not native bits, of course). There is no such thing as a javascript-to-native-code (or to-objective-c) compiler. This is done the same way in PhoneGap as well. From architectural standpoint, these two frameworks are very similar.

     3. Corona SDK is a software development kit created by Walter Luh, co-founder of Corona Labs (formerly known as Ansca Mobile). It allows software programmers to build mobile applications for the iPhone, iPad, and Android devices.
    Corona lets developers use integrated Lua, layered on top of C++/OpenGL, to build graphically rich applications that are also lightweight in size and quick in development time. The SDK does not charge per-app royalty or impose any branding requirement, and has a subscription-based purchase model that allows new features to be rolled out immediately to users.