Posts

Showing posts from March, 2013

To Find the file extension using JAVA

To Find the file extension using JAVA String extension; int dotPos = filenameExtension.lastIndexOf("."); extension = filenameExtension.substring(dotPos);

Combining both view with xml layout

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, para

Disabling Context Menu for EditText in Android

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.... andorid:longClickable="false"

Sencha Touch 2

Why Sencha Touch 2 INTRODUCTION: 1. As a Android developer we need to implement UI in a generic way as much as possible ,even though project is targeting to particular device. Because android support multiple screen sizes. Eg: 7 inch, 10 inch tablets , phone devices with different sizes. 2. If we are working on Iphone, we need to develop UI for both Ipad and Iphone. Same case in other technologies also. Here the question is can we develop UI to work in all the devices irrespective of the size ??? Here one more question is can we develop UI to work in most of the popular devices irrespective of platform like Android/Iphone/BlackBerry/Windows ??? Answer to the above questions is "Sencha Touch 2" What is Sencha Touch 2 ??? -Framework that enables developers to build fast and impressive apps that works on iOS, Android, BlackBerry, Kindle Fire etc and produce a native-apps. -It's a high-performan

Template Method Pattern

Image
Template Method Motivation If we take a look at the dictionary definition of a template we can see that a template is a preset format, used as a starting point for a particular application so that the format does not have to be recreated each time it is used. On the same idea is the template method is based. A template method defines an algorithm in a base class using abstract operations that subclasses override to provide concrete behavior. Intent - Define the skeleton of an algorithm in an operation, deferring some steps to subclasses. - Template Method lets subclasses redefine certain steps of an algorithm without letting them to change the algorithm's structure. Implementation AbstractClass - defines abstract primitive operations that concrete subclasses define to implement steps of an algorithm. - implements a template method which defines the skeleton of an algorithm. The template method calls primitive operations as well as operations defined in Abstract

Observer Pattern

Image
Observer Pattern Motivation We can not talk about Object Oriented Programming without considering the state of the objects. After all object oriented programming is about objects and their interaction. The cases when certain objects need to be informed about the changes occured in other objects are frequent. To have a good design means to decouple as much as possible and to reduce the dependencies. The Observer Design Pattern can be used whenever a subject has to be observed by one or more observers. Let's assume we have a stock system which provides data for several types of client. We want to have a client implemented as a web based application but in near future we need to add clients for mobile devices, Palm or Pocket PC, or to have a system to notify the users with sms alerts. Now it's simple to see what we need from the observer pattern: we need to separate the subject(stocks server) from it's observers(client applications) in such a way that adding new observ

Command Pattern

Image
Command Pattern “An object that contains a symbol, name or key that represents a list of commands, actions or keystrokes”. This is the definition of a macro, one that should be familiar to any computer user. From this idea the Command design pattern was given birth. The Macro represents, at some extent, a command that is built from the reunion of a set of other commands, in a given order. Just as a macro, the Command design pattern encapsulates commands (method calls) in objects allowing us to issue requests without knowing the requested operation or the requesting object. Command design pattern provides the options to queue commands, undo/redo actions and other manipulations. Intent - encapsulate a request in an object - allows the parameterization of clients with different requests - allows saving the requests in a queue Implementation The idea and implementation of the Command design pattern is quite simple, as we will see in the diagram below, needing only few extra clas

Prototype Pattern

Image
Prototype Pattern Motivation Today’s programming is all about costs. Saving is a big issue when it comes to using computer resources, so programmers are doing their best to find ways of improving the performance When we talk about object creation we can find a better way to have new objects: cloning. To this idea one particular design pattern is related: rather than creation it uses cloning. If the cost of creating a new object is large and creation is resource intensive, we clone the object. The Prototype design pattern is the one in question. It allows an object to create customized objects without knowing their class or any details of how to create them. Up to this point it sounds a lot like the Factory Method pattern, the difference being the fact that for the Factory the palette of prototypical objects never contains more than one object. Intent specifying the kind of objects to create using a prototypical instance creating new objects by copying this prototype Imple

Chain of Responsibility pattern

Image
Chain of Responsibility Motivation In writing an application of any kind, it often happens that the event generated by one object needs to be handled by another one. And, to make our work even harder, we also happen to be denied access to the object which needs to handle the event. In this case there are two possibilities: there is the beginner/lazy approach of making everything public, creating reference to every object and continuing from there and then there is the expert approach of using the Chain of Responsibility. The Chain of Responsibility design pattern allows an object to send a command without knowing what object will receive and handle it. The request is sent from one object to another making them parts of a chain and each object in this chain can handle the command, pass it on or do both. The most usual example of a machine using the Chain of Responsibility is the vending machine coin slot: rather than having a slot for each type of coin, the machine has only one s

Prototype Pattern

Image
Prototype Pattern Motivation Today’s programming is all about costs. Saving is a big issue when it comes to using computer resources, so programmers are doing their best to find ways of improving the performance When we talk about object creation we can find a better way to have new objects: cloning. To this idea one particular design pattern is related: rather than creation it uses cloning. If the cost of creating a new object is large and creation is resource intensive, we clone the object. The Prototype design pattern is the one in question. It allows an object to create customized objects without knowing their class or any details of how to create them. Up to this point it sounds a lot like the Factory Method pattern, the difference being the fact that for the Factory the palette of prototypical objects never contains more than one object. Intent specifying the kind of objects to create using a prototypical instance creating new objects by copying this prototype Imple

Builder Pattern

Image
Builder Pattern Motivation The more complex an application is the complexity of classes and objects used increases. Complex objects are made of parts produced by other objects that need special care when being built. An application might need a mechanism for building complex objects that is independent from the ones that make up the object. If this is the problem you are being confronted with, you might want to try using the Builder (or Adaptive Builder) design pattern. This pattern allows a client object to construct a complex object by specifying only its type and content, being shielded from the details related to the object�s representation. This way the construction process can be used to create different representations. The logic of this process is isolated form the actual steps used in creating the complex object, so the process can be used again to create a different object form the same set of simple objects as the first one. Intent Defines an instance for creatin