public static Bitmap downloadImage(String url) {
    // 0xAARRGGBB; 32bit 4byte :안드로이드에서 표현할수있는 1pixel 의 최대 크기
    // RGB8888 32bit, RGB565 16bit
    // pixel..
    // 화면 하나를 RGB8888 Bitmap으로 표현하는데 1메가 정도 계산해보면 그런데 이걸 RGB565를 쓰면 반으로 줄어요
    // 메모리사용량이
    // 고려해보는것도 좋습니다.
    // url에 접근하는것은 웹서버에 접근하는것이므로 httpClient를 쓰는게 맞는데
    // 일반적인 자바의 방식으로 해보겠다고 강사님이 그러심.
    // 자바에 원래 URL이라는 클래스가 있다고 하심 java.net.URL

    try {
      URL u = new URL(url);
      URLConnection con = u.openConnection();
      InputStream is = con.getInputStream();
      // 안드로이드 왜 decode라는것이 들어갈까? 화면은 보통 그림을 압축해서 저장하고 jpg,png 이런것이
      // Bitmap을 한번 압축해서
      // 용량을 줄입니다. jpg나 그런것을 Bitmap으로 디코딩하는 메소드입니다. 반대로 인코딩도 존재합니다.
      Bitmap bmp = BitmapFactory.decodeStream(is);
      is.close();
      return bmp;
    } catch (MalformedURLException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
      HelpF.Log.e("Twitter", "URL  Exception");
    } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
      HelpF.Log.e("Twitter", "Decode IO Exception");
    }
    return null;
  }
  protected String getListRequestURL(ArrayList<NameValuePair> params)
      throws URISyntaxException, IOException {
    URI u =
        URIUtils.createURI(
            "http",
            "ep.knou.ac.kr",
            -1,
            "portal/epo/service/retrieveIntgAnncList.data",
            URLEncodedUtils.format(params, "UTF-8"),
            null);
    HelpF.Log.d(this, "u.toURL():" + u.toURL());
    // HttpPost post = new HttpPost(u);
    HttpGet get = new HttpGet(u);
    // HttpPost post = new
    // HttpPost("http://api.twitter.com/1/direct_messages/new.xml");
    // 한글처리
    // post.setEntity(new UrlEncodedFormEntity(params, HTTP.UTF_8));
    HttpResponse response = mHttpClient.execute(get);
    int code = response.getStatusLine().getStatusCode();
    HttpEntity entity = response.getEntity();
    InputStream is = entity.getContent();

    StringBuilder sb = new StringBuilder();
    java.io.InputStreamReader isr = null;

    BufferedReader br = null;
    try {
      isr = new java.io.InputStreamReader(is, "UTF-8");
      br = new BufferedReader(isr);
      String tmp = null;
      while ((tmp = br.readLine()) != null) {
        sb.append(tmp);
      }

    } catch (Exception ex) {
    } finally {
      try {
        br.close();
      } catch (IOException ex) {
      }
      try {
        isr.close();
      } catch (IOException ex) {
      }
    }
    String content = sb.toString();
    HelpF.Log.d("HAN", "content1:" + content);
    return content;
  }
 @Override
 public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
   HelpF.Log.w(
       TAG,
       "Upgrading database from version "
           + oldVersion
           + " to "
           + newVersion
           + ", which will destroy all old data");
   onCreate(db);
 }
Ejemplo n.º 4
0
    protected void onPostExecute(Long result) {
      dismissDialog(DIALOG1_KEY);

      mTvDepartment.setText(
          Html.fromHtml("<font color='#008652'>[부서]</font>" + mKnouNoticeInfo.regDpNm));
      mTvDate.setText(
          Html.fromHtml(
              "<font color='#008652'>[작성일]</font>" + mKnouNoticeInfo.regDttm.substring(0, 10)));
      mTvHit.setText(Html.fromHtml("<font color='#008652'>[조회]</font>" + mKnouNoticeInfo.inqT));
      mTvSubject.setText(
          Html.fromHtml("<font color='#008" + "652'>[제목]</font>" + mKnouNoticeInfo.tit));
      if (mWvContent != null) {
        FrameLayout mContentView =
            (FrameLayout) getWindow().getDecorView().findViewById(android.R.id.content);
        HelpF.Log.d("HAN", "mKnouNoticeInfo.content:" + mKnouNoticeInfo.content);
        System.out.println("mKnouNoticeInfo.content:" + mKnouNoticeInfo.content);
        mWvContent.loadDataWithBaseURL(
            null, mKnouNoticeInfo.content.toString(), mimeType, encoding, null);
      }
      mCustomerArrayAdapter =
          new CustomerArrayAdapter(
              NoticeRead.this, 0, new ArrayList<KnouNoticeFileInfo>(mKnouNoticeInfo.AttacheFiles));
      if (0 < mKnouNoticeInfo.AttacheFiles.size()) {
        mBtnFileView.setVisibility(View.VISIBLE);
      }

      if (mIread == 1) {
        mTgbtnCollection.setChecked(false);
      } else if (mIread == 2) {
        mTgbtnCollection.setChecked(true);
      }

      if (mMemo != null) {
        if (!mMemo.trim().equals("")) {
          mBtnMemo.setText("메모(O)");
        } else {
          mBtnMemo.setText("메모(X)");
        }
      } else {
        mBtnMemo.setText("메모(X)");
      }
      findViewById(R.id.notice_read).setVisibility(View.VISIBLE);
    }
  protected String getInfoRequestURL(ArrayList<NameValuePair> params) {
    // 학과 선택
    URI u = null;
    try {
      u =
          URIUtils.createURI(
              "http",
              "ep.knou.ac.kr",
              -1,
              "/portal/epo/service/retrieveIntgAnncDtl.do",
              URLEncodedUtils.format(params, "UTF-8"),
              null);
    } catch (URISyntaxException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
    try {
      HelpF.Log.d("HAN", "u.toURL():" + u.toURL());
    } catch (MalformedURLException e1) {
      // TODO Auto-generated catch block
      e1.printStackTrace();
    }
    /*
    HttpPost post = new HttpPost(u);
    // 한글처리
    try {
    	post.setEntity(new UrlEncodedFormEntity(params, HTTP.UTF_8));
    } catch (UnsupportedEncodingException e2) {
    	// TODO Auto-generated catch block
    	e2.printStackTrace();
    }
    */

    HttpGet get = new HttpGet(u);
    HttpResponse response = null;
    try {
      response = mHttpClient.execute(get);
    } catch (ClientProtocolException e1) {
      // TODO Auto-generated catch block
      e1.printStackTrace();
    } catch (IOException e1) {
      // TODO Auto-generated catch block
      e1.printStackTrace();
    }
    int code = response.getStatusLine().getStatusCode();
    HttpEntity entity = response.getEntity();
    InputStream is = null;
    try {
      is = entity.getContent();
    } catch (IllegalStateException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }

    StringBuilder sb = new StringBuilder();
    java.io.InputStreamReader isr = null;

    BufferedReader br = null;
    try {
      isr = new java.io.InputStreamReader(is, "UTF-8");
      br = new BufferedReader(isr);
      String tmp = null;
      while ((tmp = br.readLine()) != null) {
        sb.append(tmp);
      }

    } catch (Exception ex) {
    } finally {
      try {
        br.close();
      } catch (IOException ex) {
      }
      try {
        isr.close();
      } catch (IOException ex) {
      }
    }
    String content = sb.toString();
    // Log.d("HAN","content1:"+content);
    content = content.substring(content.indexOf("<!-- view -->")); // <!--   입력 내용  -->
    content = content.substring(0, content.lastIndexOf("<!-- // view -->"));
    HelpF.Log.d("HAN", "content1:" + content);
    return content;
  }
 public void finalize() {
   HelpF.Log.d("HAN", "DiaryProvider finalize");
 }
  @Override
  public Cursor query(
      Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
    SQLiteQueryBuilder qb = new SQLiteQueryBuilder();
    String orderBy = null;
    String logSql = null;
    String sql = null;
    // Log.d("HAN", "uri:" + uri.toString());
    switch (sUriMatcher.match(uri)) {
      case KNOU_NOTICES:
        qb.setTables(KNOU_NOTICE.TABLE_NAME);
        qb.setProjectionMap(sKnouNoticeProjectionMap);
        orderBy = KNOU_NOTICE.ORDER_ID_DESC;
        break;

      case KNOU_NOTICE_ID:
        qb.setTables(KNOU_NOTICE.TABLE_NAME);
        qb.setProjectionMap(sKnouNoticeProjectionMap);
        qb.appendWhere(KNOU_NOTICE._ID + "=" + uri.getPathSegments().get(1));
        orderBy = KNOU_NOTICE.ORDER_ID_DESC;
        break;

      case KNOU_NOTICE_FILES:
        qb.setTables(KNOU_NOTICE_FILE.TABLE_NAME);
        qb.setProjectionMap(sKnouNoticeFileProjectionMap);
        orderBy = KNOU_NOTICE_FILE.ORDER_ID_DESC;
        break;

      case KNOU_NOTICE_FILE_ID:
        qb.setTables(KNOU_NOTICE_FILE.TABLE_NAME);
        qb.setProjectionMap(sKnouNoticeFileProjectionMap);
        qb.appendWhere(KNOU_NOTICE_FILE._ID + "=" + uri.getPathSegments().get(1));
        orderBy = KNOU_NOTICE_FILE.ORDER_ID_DESC;
        break;

      default:
        throw new IllegalArgumentException("Unknown URI " + uri);
    }

    SQLiteDatabase db = mOpenHelper.getReadableDatabase();
    Cursor c = null;
    // If no sort order is specified use the default
    if (!TextUtils.isEmpty(sortOrder)) {
      orderBy = sortOrder;
    }
    // Get the database and run the query
    sql = qb.buildQuery(projection, selection, selectionArgs, null, null, orderBy, null);
    if (debug) {
      logSql = sql;
      if (selectionArgs != null) {
        for (int i = 0; i < selectionArgs.length; i++) {
          logSql = logSql.replace("?", selectionArgs[i]);
          // Log.d("HAN", "1111selectionArgs["+i+"]:"+selectionArgs[i]);
        }
      }
      HelpF.Log.d("HAN", "sql[" + uri + "]:" + logSql);
    }
    c = db.rawQuery(sql, selectionArgs);

    // Tell the cursor what uri to watch, so it knows when its source data
    // changes
    c.setNotificationUri(getContext().getContentResolver(), uri);
    return c;
  }