2015年2月8日 星期日

Android internal storage file

//save

public static boolean storeInsideImage(Context context, Bitmap image, String filepath, String filename) {


 File infilepath = new File(context.getFilesDir().getAbsoluteFile(), filepath);
 if (!infilepath.exists()) {
  infilepath.mkdirs();
 }

 try {

  File imgfile = new File(infilepath, filename);
  if (!imgfile.exists()){
   imgfile.createNewFile();
  }
  FileOutputStream fileOutputStream = new FileOutputStream(imgfile);
  BufferedOutputStream bos = new BufferedOutputStream(fileOutputStream);
  // choose another format if PNG doesn't suit you
  image.compress(CompressFormat.JPEG, 100, fileOutputStream);
//   fileOutputStream.flush();
//   fileOutputStream.close();
  bos.flush();
  bos.close();
  return true;
 } catch (FileNotFoundException e) {
  Log.w("TAG", "Error saving image file: " + e.getMessage());
  return false;
 } catch (IOException e) {
  Log.w("TAG", "Error saving image file: " + e.getMessage());
  return false;
 }
 }


//load & delete

private void loadImageFromStorage(String path)
{

   try {
    //先刪除上一張
    //File dir = getFilesDir();
    File file = new File("/data/data/com.udn.nm.food/files/GoodFood/data/Files", "login.jpg");
    boolean deleted = file.delete();
    Log.d("ddddddd", "ddddddd deleted"+deleted);
   
       File f=new File(path, "login.jpg");

       Bitmap b = BitmapFactory.decodeStream(new FileInputStream(f));
       if(b !=null){
        imageView1.setImageBitmap(b);
       }
       else{
        imageView1.setBackgroundResource(R.drawable.login_bg);
       }
     
         //  ImageView img=(ImageView)findViewById(R.id.imgPicker);
      // img.setImageBitmap(b);
   }
   catch (FileNotFoundException e)
   {
    imageView1.setBackgroundResource(R.drawable.login_bg);
       e.printStackTrace();
   }

}

}


2015年1月27日 星期二

Android Activity has leaked IntentReceiver that was originally registered here. Are you missing a call to unregisterReceiver()?

參考網址:http://stackoverflow.com/questions/14357566/activity-has-leaked-intentreceiver-that-was-originally-registered-here-are-you

@Override
protected void onPause() {
    super.onPause();

    unregisterReceiver(yourReceiver);
}

2015年1月22日 星期四

Android不讓弹出鍵盤擋住View

在AndroidManifest.xml 加adjustPan
 <activity
....
....
.
 android:windowSoftInputMode="adjustPan"

</activity>

2015年1月21日 星期三

OpenLDAP for windows(連接mysql)

openldap 版本:openldap-2.4.38-x86

下載網址http://sourceforge.net/projects/openldapwindows/

安裝步驟 一直下一步就好(安裝路徑我是設在C:\OpenLDAP)

安裝完後打開 C:\OpenLDAP\etc\openldap\slapd.conf

找到BDB database definitions部分
可以修改下面3行(我是用默認的,做測試用的而已)         
suffix "dc=my-domain,dc=com"
rootdn "cn=Manager,dc=my-domain,dc=com"
rootpw test


過來就是連接mysql部分
找到# MySQL Database  修改資料庫資料
backend              sql
database             sql
suffix               "dc=example,dc=com"
rootdn               "cn=root,dc=example,dc=com"
rootpw               test
dbname               openldap    #資料庫表名稱
dbuser               root         #資料庫帳號
dbpasswd           ******     #資料庫密碼
insentry_stmt       "INSERT INTO ldap_entries (dn,oc_map_id,parent,keyval) VALUES (?,?,?,?)"
subtree_cond         "ldap_entries.dn LIKE CONCAT('%',?)"
upper_func           "upper"
concat_pattern       "?+?"
has_ldapinfo_dn_ru   no
check_schema         yes
database        monitor


修改完到C:\OpenLDAP\etc 打開odbc.ini

找到MySQLTestServer 改成

[openldap]  #資料庫表名稱
Driver=MySQL
Description=Test MySQL Database 2013
Server=localhost
Port=3306
Database=openldap #資料庫表名稱
# UID=openldap
Password=*****  #資料庫密碼


改完後到C:\OpenLDAP\etc\back-sql\mysql  

把01_backsql_create.sql,
   02_testdb_create.sql
   03_testdb_data.sql
   04_testdb_metadata.sql
都匯到資料庫


設定完後到C:\OpenLDAP\libexec  按StartLDAP.cmd  啟動

啟動完就可以連了

JavaScript‎ 列印

 <script type="text/JavaScript">
        function printpage()
        {
            window.print()
        }
    </script>

2015年1月14日 星期三

Android update ViewPager View


@Override
public Object instantiateItem(ViewGroup container, int position) {
    View view = null;
    view = mInflater.inflate(R.layout.record_list_layout, null);          
    TextView test= (TextView) view.findViewById(R.id.test);
    String key = "test" + position;

    test.setTag(key);
  ((ViewPager) arg0).addView(view );
    return view;
}

//0為第一筆
TextView test= myViewPager.findViewWithTag("test0");
// 更新內容
if (test!= null ) {
    test.setText("update");
}

2015年1月12日 星期一

JAVA 亂數排序 Collections.shuffle

        ArrayList<String> list=new ArrayList<String>();
        list.add("a");
        list.add("b");
        list.add("c");
        list.add("d");
        Collections.shuffle(list);
         
        for(String result:list)
        {
         System.out.println(result);
        }