Saturday, October 2, 2010

Disabling Context Menu for EditText in Android

Generally most of the applications use EditText in Every UI screen.
Android provides default keyboard for EditText. This Keyboard pops-up whenever we are keeping the cursor in EditText box.

Also Android provides default ContextMenu options for EditText. If you enter any text in EditText box and then long press on the entered text , then context menu options will pop-up. These options like cut,copy ,paste ...etc. These are like right click options for the MSWord.


But For some requirements these context menu options not required and also some situations we have to disable this context menu options also. To do this we have to add one tag in XML for that edit text box.

Eg.  Add the following tag to ur EditText properties....

                      android:longClickable="false"

Tuesday, September 28, 2010

To Find the file extension using JAVA

String extension;


int dotPos = filenameExtension.lastIndexOf(".");

extension = filenameExtension.substring(dotPos);

Wednesday, September 22, 2010

Combining both view with xml layout.

package com.android.murthy;

import android.app.Activity;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Rect;
import android.graphics.RectF;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup.LayoutParams;
import android.widget.Button;
import android.widget.EditText;

public class Dynamic extends Activity {
    /** Called when the activity is first created. */
    Inner inner;
    EditText preview_val;
    Button show_prev;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        inner = new Inner(this);
      //  setContentView(inner);
        LayoutParams params = new LayoutParams(150,105);
        addContentView(inner, params);
        preview_val = (EditText) findViewById(R.id.prev_value);
        show_prev = (Button) findViewById(R.id.previewBtn);
        show_prev.setOnClickListener(new OnClickListener() {
          
            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                String value = preview_val.getText().toString();
                Log.i("edit_txt value",value);
            }
        });
      
      
      
      
    }
    private class Inner extends View{

        public Inner(Context context) {
            super(context);
            // TODO Auto-generated constructor stub
        }
        @Override
        protected void onDraw(Canvas canvas) {
            // TODO Auto-generated method stub
            super.onDraw(canvas);
            Rect rect = new Rect(10, 40, 60, 80);
            Paint paint = new Paint();
            paint.setStyle(Paint.Style.FILL);
            paint.setColor(Color.RED);
           // canvas.drawColor(Color.GREEN);
            canvas.drawRect(rect, paint);
        }
    }
}
 main.xml

    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#FFFFFF"
   
    >


                android:layout_height="fill_parent" >

          android:layout_marginLeft="200dp"
          android:text="ZOOM (%)"
          android:id="@+id/zoom_txt"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:textColor="#000000"/>                 

          android:id="@+id/prev_value"
          android:layout_width="100dp"
          android:layout_height="wrap_content"
          android:layout_marginLeft="200dp"
          android:maxLines="1"/>
         


Monday, July 12, 2010

About Android SDK and It's contents

Android:

Android is a Stack for mobile devices, that includes an Operating system, middle ware, and key applications.

Android SDK:

The android SDK provides tools and libraries that are necessary to begin developing application that run on android devices..

SDK contains the following folders:

 1)add-ons:
    -Add-ons is an extension to the Android SDK development environment that  lets your to develop applications for devices .
  -Eg. we can develop an android application that uses google maps.This google maps API is available in this add-on folder.

2)docs:

- This folder contains full set of documentation in HTML format.
-This documentation includes development guide and API reference.
-This documentation is very useful for the developers, who is not having any net connection(broadband) .

3)platforms:

- This folder contains a set of Android platform versions. So that you can develop applications in different versions.

4)samples:

-This folder contains Sample code and applications that are specific to platform versions.

5)tools:
-This folder contains set of development and profiling tools available to us, such as emulator,android tool, adb, ddms etc.

6) SDK Readme.text:
-This file explains how to perform initial setup of android SDK.
-This also explains how to launch the Android SDK and AVD Manager tool on all platforms.

7)SDK setup.exe:
-This is shortcut that launches the Android SDK and AVD Manager tool.

8) usb_driver:

-This is folder is not in the android sdk if you are downloaded for Linux Operating System.
-We get this folder whenever we downloaded the SDK for Windows.
-This folder contains the driver files that we can install on our windows computer.So that we can run and debug our applications on actual device.

Screens:

Monday, July 5, 2010

Basic Flow of Lucene , Apache Solr. (Internal Flow /Process involved in Apache Lucene)

Read The following Article to Become Master in Lucene Scoring.
You can't get this information from anywhere.

Internal Flow in Apache Solr:

Whenver we enter something to search in Solr admin console,it will be received by QueryComponent.java. Means this is the starting point for the search process. QueryComponent.java is present in Solr.

Functionalities of QueryComponent.java


-Receives Query string.

-splits the query string based on some characters.

-collects the unique-id's from schema.xml.

-Find id's that are matched with query string.

-Send response to the user.

INTERNAL FLOW IN LUCENE:

The QueryParser is used to transform user submitted query strings into QueryObjects.

Lucene's Query API:


When a human-readable query is parsed by Lucene's QueryParser, it is converted to a single concrete subclass of the Query class. However, we need some understanding of the underlying concrete Query subclasses. The relevant subclasses, their purpose, and some example expressions for each are listed in the following table:



Query Implementation

Purpose

Sample expressions

TermQuery

Single term query, which effectively is a single word.

reynolds

PhraseQuery

A match of several terms in order, or in near vicinity to one another.

"light up ahead"

RangeQuery

Matches documents with terms between beginning and ending terms, including or excluding the end points.

[A TO Z]
{A TO Z}

WildcardQuery

Lightweight, regular-expression-like term-matching syntax.

j*v?
f??bar

PrefixQuery

Matches all terms that begin with a specified string.

cheese*

FuzzyQuery

Levenshtein algorithm for closeness matching.

tree~

BooleanQuery

Aggregates other Query instances into complex expressions allowing AND, OR, and NOT logic.

reynolds AND "light up ahead"
cheese* -cheesewhiz

QueryParser expression syntax:


The following items in this section describe the syntax QueryParser supports to create the various query types.


Single-term query:


A query string of only a single word is converted to an underlying TermQuery.


Phrase query:


To search for a group of words together in a field, surround the words with double-quotes. The query "hello world" corresponds to an exact phrase match, requiring "hello" and "world" to be successive terms for a match.

Lucene also supports sloppy phrase queries, where the terms between quotes do not necessarily have to be in the exact order. The slop factor measures against how many moves it takes to rearrange the terms into the exact order. If the number of moves is less than a specified slop factor, it is a match. QueryParser parses the expression "hello world"~2 as a PhraseQuery with a slop factor of 2, allowing matches on the phrases "world hello", "hello world", "hello * world", and "hello * * world", where the asterisks represent irrelevant words in the index. Note that "world * hello" does not match with a slop factor of 2. Why? Because the number of moves to get that back to "hello world" is 3. Hopping the word "world" to the asterisk position is one, to the "hello" position is two, and the third hop makes the exact match.


Range query:


Text or date range queries use bracketed syntax, with TO between the beginning term and ending term. The type of bracket determines whether the range is inclusive (square brackets) or exclusive (curly brackets).

NOTES: Non-date range queries use the start and end terms as the user entered them without modification. In the case of {Aardvark TO Zebra}, the terms are not lowercased. Start and end terms must not contain whitespace, or parsing fails; only single words are allowed. The analyzer is not run on the start and end terms.


Date range handling:


When a range query (such as [1/1/03 TO 12/31/03]) is encountered, the parser code first attempts to convert the start and end terms to dates. If the terms are valid dates, according to DateFormat.SHORT and lenient parsing, then the dates are converted to their internal textual representation (however, date field indexing is beyond the scope of this article). If either of the two terms fails to parse as a valid date, they both are used as is for a textual range.


Wildcard and prefix queries:


If a term contains an asterisk or question mark, it is considered a WildcardQuery, except when the term only contains a trailing asterisk and QueryParser optimizes it to a PrefixQuery instead. While the WildcardQuery API itself supports a leading wildcard character, the QueryParser does not allow it. An example wildcard query is w*ldc?rd, whereas the query prefix* is optimized as a PrefixQuery.


Fuzzy query:


Lucene's FuzzyQuery matches terms close to a specified term. The Levenshtein distance algorithm determines how close terms in the index are to a specified target term. "Edit distance" is another term for "Levenshtein distance," and is a measure of similarity between two strings, where distance is measured as the number of character deletions, insertions, or substitutions required to transform one string to the other string. For example, the edit distance between "three" and "tree" is one, as only one character deletion is needed. The number of moves is used in a threshold calculation, which is ratio of distance to string length.

QueryParser supports fuzzy-term queries using a trailing tilde on a term. For example, searching for wuzza~ will find documents that contain "fuzzy" and "wuzzy". Edit distance affects scoring, such that lower edit distances score higher.


Boolean query:


Constructing Boolean queries textually is done using the operators AND, OR, and NOT. Terms listed without an operator specified use an implicit operator, which by default is OR. A query of abc xyz will be interpreted as abc OR xyz. Placing a NOT in front of a term excludes documents containing the following term. Negating a term must be combined with at least one non-negated term to return documents. Each of the uppercase word operators has shortcut syntax shown in the following table.

Verbose syntax

Shortcut syntax

a AND b

+a +b

a OR b

a b

a AND NOT b

+a -b


Implementing Scoring:

The Scorer abstract class provides common scoring functionality for all Scorer implementations and is the heart of the Lucene scoring process. The Scorer defines the abstract methods which must be implemented in child classes.

The following methods are very important while we are implementing Score.


  1. DocIdSetIterator#nextDoc() — Advances to the next document that matches this Query, returning true if and only if there is another document that matches.

  2. DocIdSetIterator#docID() — Returns the id of the Document that contains the match. It is not valid until next() has been called at least once.


3.Scorer#score(Collector) — Scores and collects all matching documents using the given Collector.


4.Scorer#score() —Abstract method ,the child classes must implement.

--Returns the score of the current document matching the query.This value can be determined in any appropriate way for an application.

For instance, the TermScorer returns the tf * Weight.getValue() * fieldNorm.

NOTE:

Initially invalid, until DocIdSetIterator.next() or DocIdSetIterator.skipTo(int) is called the first time, or when called from within Collector.collect(int).

5. DocIdSetIterator#advance(int) — Skip ahead in the document matches to the document whose id is greater than or equal to the passed in value. In many instances, advance can be implemented more efficiently than simply looping through all the matching documents until the target document is identified.


CODING:

If anyone having interest to know more details about scoring implementaion just send a mail to the following mail-id:

murthy.mca53@gmail.com


Thanks&Regards

v.s.n murthy




Tuesday, May 4, 2010

Most Frquently Asked Questions in JAVA

Basic Questions from J2SE:

1) What is the difference between an interface and abstract?

2) What is the purpose of abstract class?

3) What is the use of volatile modifier?

4) Can we declare a class as private ? Explain ?

5) Tell me about native modifier ?

6) Explain public static void main(String args[])

7) What is the use of inheritance ?

8) Does java Supports Cyclic Inheritance ?

9) What is the size of char datatype in Java ?

10) What is the size of int data type in Java ?

11) How many keywords are there in Java?

12) Tell me about Access specifiers in Java?

JAVA JOBS FOR FRESHERS

Best Web site for Java Freshers