2012年4月30日 星期一

[iOS]取得 WebView Element 和 Save Password

當我們程式會存取WebView登入畫面時 可以透過下面的JavaScript語法賦與帳號和密碼 已達成Auto fill的功能
NSString *usernameJS = [NSString stringWithFormat:@"document.getElementById('account').value ='%@'", username];
NSString *passwordJS = [NSString stringWithFormat:@"document.getElementById('password').value ='%@'", password];
[self.logInWebView stringByEvaluatingJavaScriptFromString: usernameJS];
[self.logInWebView stringByEvaluatingJavaScriptFromString: passwordJS];

如果要取值的話只要執行@"document.getElementById('account').value" 就可以囉

另外密碼除存在本機端可透過 SFHFKeychainUtils 這程式去做密碼的控管與保護 
詳情細節請參考  
http://stackoverflow.com/questions/4772341/is-it-possible-for-a-uiwebview-to-save-and-autofill-previously-entered-form-valu

2012年4月10日 星期二

[Android]Fragment中 呼叫ImageView Animation

我們在使用TabActivity的時候 可能會有很多個Tab 每個會嵌入一個Activity 我們暫時稱第一個Tab包含的Activity為myActivity1 然後myActivity1包含很多個Fragment View 假若我們會assign 第一個Fragment1的view 當做myActivity1的view 這個Fragment1 的Layout 裡包含了一個 imageView的動畫想要播放 將會發現不管是放在onActivityCreate(),onStart(),onResume() 動畫都不會執行 後來網路找到了資料 要將動畫的開始 放在myActivity1的 onWindowFocusChanged(boolean hasFocus) 中動畫才能順利執行
public class myActivity1{

 @Override
 public void onWindowFocusChanged(boolean hasFocus) {
  // TODO Auto-generated method stub
  super.onWindowFocusChanged(hasFocus);
  Resources res =getResources(); 
  AnimationDrawable animDraw = (AnimationDrawable)res.getDrawable(R.drawable.nfc_animation_list);
  ImageView animImgView = (ImageView)findViewById(R.id.nfc_movie_imageview);
  animImgView.setImageDrawable(animDraw);
  animDraw.start();
 }
}