Ali Olcay Sahin, Bilgisayar, Yazılım, Internet, Software, Information Technologies
Monday, 19 December 2011
Audio Record Support for Android Emulator
Sample rate: 44100Mhz
Channel Type: CHANNEL_IN_MONO
Encoding: ENCODING_PCM_16BIT
But unfortunately this is not correct. Because neither emulator nor my Samsung Galaxy S2 supports this configuration. I have just discovered that the correct initialization for the android emulator is
Sample rate: 8000Mhz
Channel Type: CHANNEL_IN_MONO
Encoding: ENCODING_PCM_16BIT
this works for minimum buffer size calculation with getMinBufferSize(,,)
Cheers!
Sunday, 21 August 2011
Why do we need non-static inner class in java
Non static inner classes can reach to its enclosing class elements because they are dynamic elements of their enclosing classes. You can do that.
class A {
public void method(){}
public class B {
method(); // cannot do this if you define B as 'public static class B'
}
}
And in this case (non-static inner class). If you d like to create an instance of you inner class (B) in some other class, you should instantiate it like below.
class C {
public C(){
A.B b = new A().new B(); // B has the same characteristic like other non-static class elements
}
}
On the other hand if you aren't going to reach to the enclosing class elements from the inner class, you can define your inner class as static class. In this case you don't need to create an instance of enclosing class to create an instance of the inner class.
class C {
public C(){
A.B b = new A.B(); // this is a valid instantiation of a B's instance.
}
}
Wednesday, 3 August 2011
textview cannot be resolved to a type
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/text1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:gravity="center_vertical"
android:paddingLeft="6dip"
android:minHeight="?android:attr/listPreferredItemHeight"
></TextView>
and ArrayAdapter(view:View,textviewId:Int,items:String[]) wants a textview into 2nd parameter I was passing R.id.text1 as parameter but I needed to pass the layout (R.layout.list_item) instead of that textview. So why do you retrun 'textview cannot be resolved to a type' error to me? An example to confusing exceptions.
Saturday, 28 May 2011
Add custom repository to maven and add a library (dependency) from this repository
Scenario: there is that myLib-200.jar with a groupId which is 'aliolcicode' under the http://repo.aliolci.com
1. You have to add that custom repository to your maven settings to inform maven that 'I use my custom repositories next to maven repositories'. To do this. open your maven settings file (click here to see how) and add these lines below, between 'mirrors' tags
in XML above the important part is the url part the others are definition of your custom repository.
<mirror>
<id>aliolci</id>
<name>aliolci code repository</name>
<url>http://repo.aliolci.com</url>
<mirrorof>*</mirrorof>
</mirror>
2. Add your dependency to your project. There is nothing special about this. Just add your dependency as usual into your projects pom.xml.<dependencies>
<dependency>
<groupid>aliolcicode</groupid>
<artifactid>myLib</artifactid>
<version>200</version>
</dependency>
</dependencies>
That's it. Enjoy!
Saturday, 21 May 2011
Intellij IDEA is freezing during Maven project (pom.xml file) reimporting
Thursday, 5 May 2011
Maven settings.xml location at Ubuntu and Windows Systems
{Maven Installed Location}\conf\settings.xml
such as: C:\Program Files (x86)\Apache Software Foundation\apache-maven-3.0.3\conf
At Ubuntu systems it can be found under
/etc/maven2/settings.xml
Sunday, 1 May 2011
Ubuntu 11.04 set a new environment variable (persistently)
sudo gedit /etc/environment
If you open this file you will see the PATH variable's value. If you would like to set a new one just move to new line and set your variable in {variable_name}="{variable_value}" format. Such as JAVA_HOME="/usr/lib/jvm/java-6-sun/bin"
DONT FORGET TO OPEN FILE AS SUPER USER and restart your computer after you saved the changes.
To see the list of environment variables:
bash$ export
Wednesday, 16 February 2011
Android Activity life cycle
Tuesday, 1 February 2011
Custom Translate Animation for Android is almost ready
The original translate animation of android does not give information of the animated object's current location therefore I started to my project and it is almost finished. You can find the source code and algorithms of this functionality at my previous posts. I found some bugs in these code lines and I have already fixed but I still test them. I will share the trustworthy ones in next days. This project delayed for a long time because I moved to London and I am busy with the job search recently. But I will pay much more attention on the project in next days. You can watch the video of the animation. Attention!! the real animation works way smoother then the video. My PC is not strong enough to record and to emulate at the same time. See you..
Wednesday, 5 January 2011
Defining the route path between two points in 2D coordination system and Java implementation
I currently develop a 2D ball game for Android OS therefore this computing is important for the game to define the ball’s route in the game. In Android OS, there is a TranslateAnimation class to fulfil the Translate operation (changing the X, Y coordinates of an instance of a View class) but TranslateAnimation class does not supply the information of the animated object’s current x, y coordinate state. In my game, the ball’s place in time is important to take action according to its location. Therefore, I developed my own Extended TranslateAnimation class.
***The Algorithm***
I divide the animation operation in to two parts. First part is path resolving between the destination and the source points and the second part is animating the instance of a View class (animated object) and displaying it on the screen graphically. This article explains the path resolving operation which’s algorithm is below.
The figure below shows the representation of the destination(X1, Y1) and the source (X0, Y0) points. Red line (hypotenuse) shows the full path between points, green line shows the base and blue line shows the leg of the right triangle. The aim is, from the point 0 to point 1 if the animated object moves long as “d” on the redline (hypotenuse), what will be the new location on 2D plane( the “x, y” value of the very top and left had side of the plane is “0, 0” and it increases to the bottom right hand side). If it was calculated this new location’s coordinates, it would be set to the animated object’s location and the object would move to there.
The step by step algorithm is defined below for “d” distance.
1. Get little hypotenuse length (hypo=d)
2. Calculate the length of Hypotenuse (RealHypo)
3. Find Tan α = Blue Line/ Green Line
4. Find the α angle (use ArcTan)
5. Calculate the Cos α and Sin α values
Until here, we know the Cos α and Sin α values so we can calculate the base and leg length of the small right triangle which’s hypotenuse is “d” and top point is X0, Y0. So we just need to find the coordinate of the other tip of “d” (X’, Y’).
6. Find the difference between X0 – X’ = d*Cos α
7. Find the difference between Y0 – Y’ = d*Sin α
8. Subtract/Add these differences to X0 and Y0 According to the equations in step 5-6.
9. hypo=hypo+d
X’ = X0 - d*Cos α
Y’ = Y0 - d*Sin α
That’s all. One important note is Subtract/Add option changes according to the movement of the animated object therefore the direction calculation should be computed in step 7 as well.
Code
Full Java Code (VectoralPathResolver) is added below.
1: package aliolci.CrazyBall;
2: /*
3: * By Ali Olcay SAHIN
4: * www.aliolci.com
5: * aliolci@gmail.com
6: * Thank you for using it.
7: * */
8: import java.util.ArrayList;
9: import java.util.List;
10:
11: import android.graphics.PointF;
12:
13: public class VectoralPathResolver {
14: private float FromXDelta, ToXDelta, FromYDelta, ToYDelta;
15: private float d =(float) 0.1;//sensitivity
16: private float realHypo;
17: private float hypo;
18: private double TanAngle;
19: private double cosValue;
20: private double sinValue;
21: private byte signX;
22: private byte signY;
23: public VectoralPathResolver(float fromXDelta, float toXDelta,
24: float fromYDelta, float toYDelta) {
25: FromXDelta = fromXDelta;
26: ToXDelta = toXDelta;
27: FromYDelta = fromYDelta;
28: ToYDelta = toYDelta;
29:
30: realHypo = (float) Math.sqrt(Math.pow(FromXDelta-ToXDelta, 2)+Math.pow(FromYDelta-ToYDelta, 2));
31: hypo =0;
32: TanAngle = Math.atan((ToYDelta-FromYDelta)/(ToXDelta-FromXDelta));
33: cosValue =Math.cos(TanAngle);
34: sinValue =Math.sin(TanAngle);
35: signX = (byte) (Integer.signum((int) (ToXDelta-FromXDelta))<0?-1:1);
36: signY = (byte) (Integer.signum((int) (ToYDelta-FromYDelta))<0?-1:1);
37: }
38: public List<PointF> ResolveReturnFullPath()
39: {
40: List<PointF> path= new ArrayList<PointF>();
41: PointF f;
42: do
43: {
44: f=this.Next();
45: if(f!=null)
46: path.add(f);
47: }
48: while(f!=null);
49:
50: return path;
51: }
52: public void setSensitivity(float sensitivity)
53: {
54: d=sensitivity;
55: }
56: public PointF Next()
57: {
58: if(realHypo>hypo)
59: {
60: hypo+=d;
61: float Xnew = (float)(cosValue*hypo*signX)+FromXDelta;
62: float Ynew =(float)(sinValue*hypo*signY)+FromYDelta;
63: return new PointF(Xnew,Ynew);
64: }
65: else
66: return null;
67: }
68: public PointF Next(int HowMuchEachTime)
69: {
70: if(realHypo>hypo)
71: {
72: hypo+=d*HowMuchEachTime;
73: float Xnew = (float)(cosValue*hypo*signX)+FromXDelta;
74: float Ynew =(float)(sinValue*hypo*signY)+FromYDelta;
75: return new PointF(Xnew,Ynew);
76: }
77: else
78: return null;
79: }
80: public void reset()
81: {
82: hypo=0;
83: }
84: public int getTotalSteps()
85: {
86: return (int)(realHypo/d);
87: }
88: }