Saturday, January 25, 2014
Tuesday, October 8, 2013
Eclipse, Ant, CVS with Windows 7
I got a new machine with Windows 7, and started to setup my build environment.
We have an ant script to update from CVS and tag and etc...
Simply adding following ant task I could do this.
<target name="cvs_update">
<cvs command="update -dP">
</cvs>
</target>
<target name="cvs_tag">
<cvs command="tag ABC_${build_time}">
</cvs>
</target>
But, we should install WinCVS/CVSNT to run this We have an ant script to update from CVS and tag and etc...
Simply adding following ant task I could do this.
<target name="cvs_update">
<cvs command="update -dP">
</cvs>
</target>
<target name="cvs_tag">
<cvs command="tag ABC_${build_time}">
</cvs>
</target>
In Windows 7 I got a first issue, ant couldn't find the cvs.exe even if the cvs.exe in PATH variable. And if you check the in command prompt by type cvs it will run. But in Eclipse when you run above ant task it will keep saying application cvs not found.
[cvs] Caught exception: Cannot run program "cvs": CreateProcess error=2, The system cannot find the file specified
Only solution I found is:
uninstall and install CVSNT into a folder, which name doesn't have any spaces (Example Program_Files_(x86))
The 2nd I faced in login
[cvs] cvs update: Empty password used - try 'cvs login' with a real password [cvs]
The only solution I found is:
Run CVSNT Password Agent.
Saturday, May 18, 2013
Eclipse, Java : Inserting Single line "if block"
If we run our program after completing coding, those will not as excepted mostly, or at-least in testing we will find places where we have missed some null check or etc. So we may have to add a if condition to check and to avoid those Exceptions. Mostly those will be a single line "if blocks".
I am talking about cases like below. Say you have following line:
myObject.myMethod();
Here we got a NullPointerException because myObject is null, I wanted added a null check before this:
if(myObject!=null)
myObject.myMethod();
This is correct, but I mostly don't like this, for future coding and because of the readability, I prefer to add a block as follows. Sometime reader will think that, all the statements which following the above statement also inside the if condition.
if(myObject!=null){
myObject.myMethod();
}
It was hard for me always, because I had to write if block and copy paste the statement inside. But i found a method to do in Eclipse without doing copy paste.
Just go infront of the statement and start typing your if condition and write up to { and press enter key, then you will get what you want.
if(myObject!=null){|myObject.myMethod(); <-- font="">Keep the curser at the | position and press enter.-->
Okey now you try and let me know your comments.
I am talking about cases like below. Say you have following line:
myObject.myMethod();
Here we got a NullPointerException because myObject is null, I wanted added a null check before this:
if(myObject!=null)
myObject.myMethod();
This is correct, but I mostly don't like this, for future coding and because of the readability, I prefer to add a block as follows. Sometime reader will think that, all the statements which following the above statement also inside the if condition.
if(myObject!=null){
myObject.myMethod();
}
It was hard for me always, because I had to write if block and copy paste the statement inside. But i found a method to do in Eclipse without doing copy paste.
Just go infront of the statement and start typing your if condition and write up to { and press enter key, then you will get what you want.
if(myObject!=null){|myObject.myMethod(); <-- font="">Keep the curser at the | position and press enter.-->
Okey now you try and let me know your comments.
Wednesday, January 30, 2013
Part 2:Useful Eclipse Templates for Android Development
Part 1:Useful Eclipse Templates for Android Development
Weak Reference for Views in Activity.
Inside onCreate of each Android Activity we used to setContentView with layout xml. Then to access each view from the activity we use:
View view = findViewById(R.id..........);
to avoid calling findViewById multiple time, call this only in onCreate and keep this view as member variable inside activity.
View mView
.....
mView = findViewById(R.id..........);
Then, question is why we need to overload the onCreate method, we call findViewById only when needed and keep as member variable. So introduce following get method.
View getView(){
if(mView==null){
mView = findViewById(R.id..........);
}
return mView;
}
But in some cases, to avoid memory leakage issues, we need to remove all view from content view and need to null all these references in activity. But rather find each reference and assign to null, if we make a weak reference then it should all clear as we remove view from activity. For Example:
private WeakReference mView;
public View getView() {
if(!(mView!=null && mView.get()!=null)){
mView = new WeakReference((View) findViewById(R.id.....));
}
return mFrameAddStyleView.get();
}
Now, Let see how to write a Eclipse template to auto generate this:
Eclipse - > Windows -> Preferences -> Java -> Editor -> Templates -> New ...
Name:- wfind
Pattern:-
private WeakReference<${type}> m${new_name};
public ${type} get${new_name}() {
if(!(m${new_name}!=null && m${new_name}.get()!=null)){
m${new_name} = new WeakReference<${type}>((${type}) findViewById(R.id.${cursor}));
}
return m${new_name}.get();}
Now go to your activity class and type wfind and press Ctrl+Space you will get what you want.
Weak Reference for Views in Activity.
Inside onCreate of each Android Activity we used to setContentView with layout xml. Then to access each view from the activity we use:
View view = findViewById(R.id..........);
to avoid calling findViewById multiple time, call this only in onCreate and keep this view as member variable inside activity.
View mView
.....
mView = findViewById(R.id..........);
Then, question is why we need to overload the onCreate method, we call findViewById only when needed and keep as member variable. So introduce following get method.
View getView(){
if(mView==null){
mView = findViewById(R.id..........);
}
return mView;
}
But in some cases, to avoid memory leakage issues, we need to remove all view from content view and need to null all these references in activity. But rather find each reference and assign to null, if we make a weak reference then it should all clear as we remove view from activity. For Example:
private WeakReference
public View getView() {
if(!(mView!=null && mView.get()!=null)){
mView = new WeakReference
}
return mFrameAddStyleView.get();
}
Now, Let see how to write a Eclipse template to auto generate this:
Eclipse - > Windows -> Preferences -> Java -> Editor -> Templates -> New ...
Name:- wfind
Pattern:-
private WeakReference<${type}> m${new_name};
public ${type} get${new_name}() {
if(!(m${new_name}!=null && m${new_name}.get()!=null)){
m${new_name} = new WeakReference<${type}>((${type}) findViewById(R.id.${cursor}));
}
return m${new_name}.get();}
Now go to your activity class and type wfind and press Ctrl+Space you will get what you want.
Thursday, November 15, 2012
Android: UI Automator Viewer (uiautomatorviewer) - issue in landscape screen
If you are ttrying to use UI Testing tools introduced in Android SDK Tools, Revision 21 you will see a port-tailed image in uiautomatorviewer capture for landscape activities.
Hover over selection and uix file will perform properly, but only issue will be the image will not be aligned properly.
I found a possible workaround, just close the file (note down the location) and got the folder, you will see a image, please rotate accordingly.
Then come back and reopen the uix, it will ask for the screen slot, just show the rotated screen.
Hover over selection and uix file will perform properly, but only issue will be the image will not be aligned properly.
I found a possible workaround, just close the file (note down the location) and got the folder, you will see a image, please rotate accordingly.
Then come back and reopen the uix, it will ask for the screen slot, just show the rotated screen.
Tuesday, October 2, 2012
Java: Random Unique Indexes
Say you have a list of items, you want to pick item from the list in random order, but need to avoid duplicate items until you get all items from the list.
assume below list of colors
0. Red
1. Blue
2. Yellow
3. Green
You may have to display as Blue, Red, Yellow and Green, here you see we have random items but not duplicated.
Here I write a Java Utilities for that purpose. Here we have to generate random numbers with in the limit but we have to ignore already generated values when try next time.
So, First create a list of indexes.
[0]->0
[1]->1
[2]->2
[3]->3
mIndexes = new int[size];
for(int i = 0 ; i < mIndexes.length;i++){
mIndexes[i] = i;
}
First you have to create a random number within the size so,
mNextMaxIndex = size;
Let see how to generate random index with no duplicate.
Generate a random index with the size limit.
int index = mRandom.nextInt(mNextMaxIndex);
Value from the index will be the result.
int result = mIndexes[index];
now swap this value to end of the effect list and reduce the limit by one.
mNextMaxIndex--;
mIndexes[index] = mIndexes[mNextMaxIndex];
mIndexes[mNextMaxIndex] = result;
Say you got 2 then result will be 2 and our new list will be
[0]->0
[1]->1
[2]->3
[3]->2
and mNextMaxIndex will be 3.
Now for the next index, generate a random number within 3 and do the same steps again.
But finally if we reach the start we have to reset back start from the end.
if(mNextMaxIndex<1 font="font">1>
mNextMaxIndex = mIndexes.length;
}
I have the source code here, it have a main method to test his also i see a
assume below list of colors
0. Red
1. Blue
2. Yellow
3. Green
You may have to display as Blue, Red, Yellow and Green, here you see we have random items but not duplicated.
Here I write a Java Utilities for that purpose. Here we have to generate random numbers with in the limit but we have to ignore already generated values when try next time.
So, First create a list of indexes.
[0]->0
[1]->1
[2]->2
[3]->3
mIndexes = new int[size];
for(int i = 0 ; i < mIndexes.length;i++){
mIndexes[i] = i;
}
First you have to create a random number within the size so,
mNextMaxIndex = size;
Let see how to generate random index with no duplicate.
Generate a random index with the size limit.
int index = mRandom.nextInt(mNextMaxIndex);
Value from the index will be the result.
int result = mIndexes[index];
now swap this value to end of the effect list and reduce the limit by one.
mNextMaxIndex--;
mIndexes[index] = mIndexes[mNextMaxIndex];
mIndexes[mNextMaxIndex] = result;
Say you got 2 then result will be 2 and our new list will be
[0]->0
[1]->1
[2]->3
[3]->2
and mNextMaxIndex will be 3.
Now for the next index, generate a random number within 3 and do the same steps again.
But finally if we reach the start we have to reset back start from the end.
if(mNextMaxIndex<1 font="font">1>
mNextMaxIndex = mIndexes.length;
}
I have the source code here, it have a main method to test his also i see a
Thursday, September 20, 2012
Android: Issue In loading MP3 files, which Saved by Same Application
We had to list down and play some bundled MP3 files from our android application. We added a zip file with proper folder structure inside assert. Application will extract that into /data/data/{package name}/files/ folder on loading and make use of this.
In this both Media Metadata Retriever or Media Player API didn't work if we use direct file-name or URI.
First I was thinking the issue in permission of the written file, I manage to write files with the permission -rw-rw-rw but that was not enough. Issue was with owner. Those written files owner and group as same as the application not root or etc.
I couldn't find a API to change the owner of a file.But lucky, Media Metadata Retriever and Media Player API could accept File Descriptor, So We had to use FileInputStream to get The File Descriptor and pass it to tose APIs.
In this both Media Metadata Retriever or Media Player API didn't work if we use direct file-name or URI.
First I was thinking the issue in permission of the written file, I manage to write files with the permission -rw-rw-rw but that was not enough. Issue was with owner. Those written files owner and group as same as the application not root or etc.
I couldn't find a API to change the owner of a file.But lucky, Media Metadata Retriever and Media Player API could accept File Descriptor, So We had to use FileInputStream to get The File Descriptor and pass it to tose APIs.
Subscribe to:
Posts (Atom)



