Wednesday, March 28, 2012

Android :: Hide Virtual Keyboard on App Start ( 隱藏鍵盤)

最近在做一個睇星坐APP, 一開始有一個 edittext, 但一當 load activity 時就該edittext 就立即on focus 彈出 virtual keyboard
google 一下, 只要在Activity::OnCreate 中加入以下 code 即可 !!!


// hidden keyboard
this.getWindow().setSoftInputMode(
WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);

Tuesday, February 07, 2012

Set up DfpAdView/AdView of admob

教學有很多, 但大多十分多肺話, 所以我的十分精簡:

1) Reg On Admob site to get the Publisher ID -  a14exxxxxxxxxx

2) Mainfest.xml:
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
     <activity
            android:name="com.google.ads.AdActivity"            android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" />

3) Add a LinearLayout called ad_layout to the Activity "XML" file that u want to show the ad.

4a) Add the code to the correspondence Activity "JAVA Code" file
   
    ------- Field -------
     private DfpAdView mAdView;

      I----- onCreate ------
      final LinearLayout adRow = (LinearLayout) findViewById(R.id.ad_layout);
mAdView = new DfpAdView(this, AdSize.SMART_BANNER, "a14exxxxxxxxxx");
adRow.addView(mAdView);
mAdView.loadAd(new AdRequest());

4b) Change DfpAdView to AdView, if u want AdView

5) Override onDestory
     @Override
protected void onDestroy() {
if (mAdView != null) {
mAdView.removeAllViews();
mAdView.destroy();
}
super.onDestroy();
}

6) Run Test !!!!

PS: Add DfpInterstitialAd Later
 

Saturday, January 27, 2007

Hafnium Vally ?

Intel and IBM announces a research result tothe use of alloy of hafnium to replace the silicon dioxide can makes Morrow's Law to be valid in the future.

New York Time

Sunday, January 21, 2007

Wednesday, January 17, 2007

Proxy + 代理猎手

我现在是proxy switcher 跟 代理猎手一起用,proxy switcher 有个功能是自动下载代理服务器网站的代理列表,找到后在全部拿到代理猎手上verify,看哪个连到gindis的比较快。。。具体操作嘛。。。。

proxy switcher
Actions-->Download Proxy Lists,等待几分钟,程序如果开始testing 那些代理的话你把他给stop掉,这时你应该可以在左边
NEW里看到一些刚刚下载的代理,点那个new的文件夹,全选右边的代理,然后File-->export to text file-->命名


代理猎手
System-->Change Option 出来一个option,按中间那个Verification Data Option tab, 选择下面的Add
会出现一个窗口
Name:随便
URL:你要verify 的网址,http://www.gindis.com, 这个填完后按旁边的get, 新窗口弹出再按get一次,这时你会在那个新窗口收到一些数据,随便copy 一下army commander 之类的当你的key word,然后按ok,接着回到你之前的Verification Data Option tab, 选择刚刚你才加的verification,然后按下面的use。这是为了以后测试你那些代理服务器连到这个网址后能不能在找到这个keyword,找到 的速度越快代表你的代理越快(当然可能连接gindis快的,连接论坛就慢了,有时根本不能连)

接下来去代理猎手主窗口,点Results-->import-->之前找到的代理,加完后点中间那个Result tab,按右边的verify all,等几分钟,good就是可以用的代理,你点Timing 可以从最快到最慢排序

回到proxy switcher
选择左边的proxyswitcher 文件夹,把刚刚那些good的代理加进去,剩下的就一个个试,看哪个速度快

Monday, January 15, 2007

Next Generation of Fortan -- Fortress

Sun released Fortress as a replacement of well know scientific purpose language -- Fortran.
Fortress is target on JVM 1.5.

The most natural different between it and Java is that it assume that a process should be run in parallel instead of single-threaded. It also means to target to high-performance computing area.

Tuesday, January 09, 2007

iPhone come out from Jobs's packet

In today Macworld San Franciso 2007, Jobs took a new iPod from his packet !!!

Ohhhhhhh~~ wait that is not iPod !!!!


~~ iPhone ~~

The details released were:
  1. 3.5-inch widescreen display

  2. 2.0 Megapixel camer

  3. 8GB /4GB storage

  4. Bluetooth with EDR

  5. WiFi

  6. quadband GSM radio with EDGE.
7. It will be availiable in June for $499 for 4GB and $599 for 8GB
iPhone Offical Site


Sunday, December 03, 2006

Quake 3 's InvSqrt

float InvSqrt (float x){
float xhalf = 0.5f*x;
int i = *(int*)&x;
i = 0x5f3759df - (i >> 1);
x = *(float*)&i;
x = x*(1.5f - xhalf*x*x);
return x;
}

Math explanation here (PDF)

Thursday, November 23, 2006

Send File !?!? 沒有困難 ~~~

Ha, I find the simple input is just a PDF file, so to check the programe is correct or not, just remain the output to .bin file..

Source Code Later !!

Sunday, November 12, 2006

Download from You Tube

"View Page Source” and do a text search for

player2.swf?video_id=

For example the internal prolonged video identification code may be:

b4Knsa7kBPE&l=48&t=OEgsToPDskI3D6CVWsTxEa4BzcTHKXc7
&s=E04B5F8107785BA4:8A51374783A7BCE6

Keep in mind that the code between “&t=” and “&s=” may be session-sensitive and changed every time the video is accessed.

To save the video, the URL path format is

http://www.youtube.com/get_video?video_id=prolonged_video_identification_code

Set the range of SQL result

SQL LIMIT

如果在某項查詢結果中,我們想要的僅是其中一部份時,可以使用 LIMIT 來限制資料被讀取的筆數。
例如,找出座號最前面的五位學生姓名:

SELECT realname FROM student ORDER BY num LIMIT 0, 5

在此例中,LIMIT 後方的 0 代表「從第 0 筆資料開始」,5 表示「取出 5 筆資料」。

Monday, October 30, 2006

Here's some code for blurring an image:

float[] kernelData = new float[9];
for (int i = 0; i < kernelData.length; i++)
{
kernelData[i] = 0.15f;
}
ConvolveOp blur = new ConvolveOp(new Kernel(3, 3, kernelData));
BufferedImage blurryImage = new BufferedImage(w, h, w, h,
BufferedImage.TYPE_INT_ARGB);
blurryImage.createGraphics().drawImage(imageToBlur, blur, 0, 2);

Add time stamp to picture using Java

public static void addDate(File inputFile) throws Exception {
String inputFilename = inputFile.getPath();
System.out.println("Starting with '" + inputFilename + "'");
BufferedImage input = ImageIO.read(inputFile);
Graphics2D graphics = (Graphics2D) input.createGraphics();
Date lastModified = new Date(inputFile.lastModified());
SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
String dateStamp = sdf.format(lastModified);
int fontSize = (int) (0.4 * input.getHeight() / 10.0);
Font font = new Font("Arial", Font.BOLD, fontSize);
graphics.setFont(font);
int height = graphics.getFontMetrics().getHeight();
int width = graphics.getFontMetrics().stringWidth(dateStamp);

BufferedImage dateImage = new BufferedImage(2 * fontSize + width, 2
* fontSize + height, BufferedImage.TYPE_INT_ARGB);
Graphics2D dateGraphics = (Graphics2D) dateImage.getGraphics().create();
dateGraphics.setColor(new Color(0, 0, 0, 0));
dateGraphics.setComposite(AlphaComposite.Src);
dateGraphics.fillRect(0, 0, width, height);

dateGraphics.setComposite(AlphaComposite.SrcOver);
dateGraphics.setFont(font);
dateGraphics.setColor(Color.black);
dateGraphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
GlyphVector gv = font.createGlyphVector(dateGraphics
.getFontRenderContext(), dateStamp);
// dateGraphics.drawString(dateStamp, fontSize, fontSize);
dateGraphics.translate(fontSize, 2 * fontSize);
for (int i = 0; i < gv.getNumGlyphs(); i++) {
Shape glyph = gv.getGlyphOutline(i);
dateGraphics.setStroke(new BasicStroke(fontSize / 10));
dateGraphics.draw(glyph);
}
float[] kernel = new float[25];
for (int i = 0; i < kernel.length; i++)
kernel[i] = 1.0f / kernel.length;
ConvolveOp cOp = new ConvolveOp(new Kernel(5, 5, kernel));
BufferedImage blurred = cOp.filter(dateImage, null);
dateGraphics.dispose();

int iWidth = input.getWidth();
int iHeight = input.getHeight();
int cHeight = iWidth * 2 / 3;
int dHeight = (iHeight - cHeight) / 2;

int y = (iHeight - dHeight) - blurred.getHeight();
int x = iWidth - blurred.getWidth();

graphics.drawImage(blurred, x - fontSize, y - 2 * fontSize, null);
graphics.setFont(font);
graphics.setColor(Color.white);
graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
graphics.drawString(dateStamp, x, y);
graphics.dispose();

int lastDotIndex = inputFilename.lastIndexOf('.');
String outputFilename = inputFilename.substring(0, lastDotIndex)
+ ".new" + inputFilename.substring(lastDotIndex);
FileOutputStream out = new FileOutputStream(outputFilename);
/* encodes image as a JPEG data stream */
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
JPEGEncodeParam param = encoder.getDefaultJPEGEncodeParam(input);
param.setQuality(0.9f, true);
encoder.setJPEGEncodeParam(param);
encoder.encode(input);
System.out.println("Ending with '" + inputFilename + "'");
}

Of course, it's not a pinnacle of Java2D programming, nor was it intended to. Since i don't have any imaging-related java.net project, i'm not intending to polish it to perfection. It even uses classes in the com.sun.image.codec.jpeg package. Hereby it is released to the public domain - feel free to use, reuse and abuse it in any way - but don't come back if your nuclear reactor stops functioning because of this :)

The result is quite OK:

Tuesday, October 24, 2006

Add new Features to Java

Fun :) Very funny :)

A much fair comparsion should be Rudy vs Groovy vs Python vs Perl.

Java should and it should be much complex than Ruby becuz of its strong typing system.

However, some of the Ease of Development(EoD) of Ruby can be absorded by Java, to richer Java's expression prower without damaging the strong typing system.

For example:
'yield return' can save your works from creating a new array to store the results in list.

Direct "regular expression' support like what Javascript does can save works from createing/managing Pattern, Matcher Objects.

Lambda provide better DSL support in Java.

...... etc.

You may(are going to) say: 'Hey !!! we the community don't need them all. Seriously, I dun need them.'

Okay, who asked for GC, Object-Oriented programming support, RTTI, Bytecode and Cross platform support ???

Back to just 3 years back now, I think sun is the one person who support GC. If you read the javalobby and even the Sun's Java REF DB. NOBODY think GC is good, everybody just try to reinforce the 'delete' key into the language.

Now, I think 99% of us agreed that GC is a must.
(hey, u disagree !!! Why?? I'm Sorry, I forget that C programmers do read javalobby :)

We're lucky that we get some smart folks to do the R&D for us. Sometime even all of us think that something go wrong, maybe its bucz (we're)||(the things) is wrong.

I'm not telling you that the community is making the wrong decisions to any change in java language( I agree that the current generic implementation sucks). Spring, iBat, Tomcat...etc from the java community are the masterpiece. But sometime people object to the new language changes just bcuz:

I dun understand it
I dun like it BUCZ I dun learned it b4
I dun use it I dunno the advantage of it
I just simple dislike changes
I have a good reason blah blah...

I know many people (of course just surrounding me, U is not the one) hate something just bcuz they dun understand it. This is a psychology topic I learned in uni:
If someone put a unopenable, sealed, opaque large box in your house with no good reason and order you to not open it. At the beginning u should be curious about it. But later on experts found out two very funny results:

1) treat it as normal, the box is here just like it should be.

2) lock/hidden/throw/remove/return the box. Someone even called the police. Why? bcuz people afraid the stuffs inside the box. if the box is similar to a human size 50% people think a dead body inside. if the size is similar to the 21" TV 30% of people afraid that it is dirty $$ ....so on.

Now, the reaction of the java community is similar. Why add closure????? it is damager??? why ??? I dunno why.....

Well, dun start a flame war that Java shouldn't add XXXXX. This is not related to this topic.

What I want to say is the main purpose of comparing Java and Rudy is to show that java is bad or show that xxx features from ruby should be added to java bucz java is weak in this use case.

I PERDICT:

I THINK ALL RUBY FEATURES WILL BE ADDED TO JAVA SOON OR LATER.

u: omg/suck/shit, I want clear and simple java only, dun change java into ruby.

Hey, hold one. U misunderstand me. I means JRuby == power of ruby + power of java

What !?!? It doesn't look like Java.

Then look for Groovy == ruby power + Java syntax

What ?!?!?! You just want part of the ruby in java.
Please move to other post that talk about adding new features like closure .... etc.

It is meaningless to compare the color and size of an apple and orange.
Go and make something like Rudy vs Perl --- Why Perl sucks? Or C# vs Java why people always think C# is easier? Or Java vs VB.Net why Java can’t replace VB for the past 10 ten is much educational and meaningful that Java vs Ruby – Why Strong typed language always look sucks in front of dynamic typed language.