디시인사이드 갤러리

갤러리 이슈박스, 최근방문 갤러리

갤러리 본문 영역

안드로이드 vnc 소스 이게 전부맞음?

ㅇㅇ(122.35) 2014.03.25 23:43:59
조회 1200 추천 0 댓글 0

/* 
 * This is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 * 
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this software; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,
 * USA.
 */

//
// androidVNC is the Activity for setting VNC server IP and port.
//

package android.androidVNC;

import android.app.Activity;
import android.app.Dialog;
import android.app.ActivityManager.MemoryInfo;
import android.content.DialogInterface;
import android.content.Intent;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.RadioGroup;
import android.widget.Spinner;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.Collections;

public class androidVNC extends Activity {
 private EditText ipText;
 private EditText portText;
 private EditText passwordText;
 private Button goButton;
 private TextView repeaterText;
 private RadioGroup groupForceFullScreen;
 private Spinner colorSpinner;
 private Spinner spinnerConnection;
 private VncDatabase database;
 private ConnectionBean selected;
 private EditText textNickname;
 private EditText textUsername;
 private CheckBox checkboxKeepPassword;
 private CheckBox checkboxLocalCursor;
 private boolean repeaterTextSet;

 @Override
 public void onCreate(Bundle icicle) {

  super.onCreate(icicle);
  setContentView(R.layout.main);

  ipText = (EditText) findViewById(R.id.textIP);
  portText = (EditText) findViewById(R.id.textPORT);
  passwordText = (EditText) findViewById(R.id.textPASSWORD);
  textNickname = (EditText) findViewById(R.id.textNickname);
  textUsername = (EditText) findViewById(R.id.textUsername);   goButt findViewById(R.id.buttonGO);
  ((Button) findViewById(R.id.buttonRepeater)).setOnClickListener(new View.OnClickListener() {
   
   @Override
   public void onClick(View v) {
    showDialog(R.layout.repeater_dialog);
   }
  });
  ((Button)findViewById(R.id.buttonImportExport)).setOnClickListener(new View.OnClickListener() {
   @Override
   public void onClick(View v) {
    showDialog(R.layout.importexport);
   }
  });
  colorSpinner = (Spinner)findViewById(R.id.colorformat);
  COLORMODEL[] models=COLORMODEL.values();
  ArrayAdapter<COLORMODEL> colorSpinnerAdapter = new ArrayAdapter<COLORMODEL>(this, android.R.layout.simple_spinner_item, models);
  groupForceFullScreen = (RadioGroup)findViewById(R.id.groupForceFullScreen);
  checkboxKeepPassword = (CheckBox)findViewById(R.id.checkboxKeepPassword);
  checkboxLocalCursor = (CheckBox)findViewById(R.id.checkboxUseLocalCursor);
  colorSpinner.setAdapter(colorSpinnerAdapter);
  colorSpinner.setSelection(0);   spinnerC
  spinnerConnection.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
   @Override
   public void onItemSelected(AdapterView<?> ad, View view, int itemIndex, long id) {
    selected = (ConnectionBean)ad.getSelectedItem();
    updateViewFromSelected();
   }
   @Override
   public void onNothingSelected(AdapterView<?> ad) {
    selected = null;
   }
  });
  spinnerConnection.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {

   /* (non-Javadoc)
    * @see android.widget.AdapterView.OnItemLongClickListener#onItemLongClick(android.widget.AdapterView, android.view.View, int, long)
    */
   @Override
   public boolean onItemLongClick(AdapterView<?> arg0, View arg1,
     int arg2, long arg3) {
    spinnerConnection.setSelection(arg2);
    selected = (ConnectionBean)spinnerConnection.getItemAtPosition(arg2);
    canvasStart();
    return true;
   }
   
  });
  repeaterText = (TextView)findViewById(R.id.textRepeaterId);
  goButton.setOnClickListener(new View.OnClickListener() {
   @Override
   public void onClick(View view) {
    canvasStart();
   }
  });
  
  database = new VncDatabase(this);
 }
 
 protected void onDestroy() {
  database.close();
  super.onDestroy();
 }
 
 /* (non-Javadoc)
  * @see android.app.Activity#onCreateDialog(int)
  */
 @Override
 protected Dialog onCreateDialog(int id) {
  if (id == R.layout.importexport)
   return new ImportExportDialog(this);
  else
   return new RepeaterDialog(this);
 }

 /* (non-Javadoc)
  * @see android.app.Activity#onCreateOptionsMenu(android.view.Menu)
  */
 @Override
 public boolean onCreateOptionsMenu(Menu menu) {
  getMenuInflater().inflate(R.menu.androidvncmenu,menu);
  return true;
 }

 /* (non-Javadoc)
  * @see android.app.Activity#onMenuOpened(int, android.view.Menu)
  */
 @Override
 public boolean onMenuOpened(int featureId, Menu menu) {
  menu.findItem(R.id.itemDeleteConnection).setEnabled(selected!=null && ! selected.isNew());
  menu.findItem(R.id.itemSaveAsCopy).setEnabled(selected!=null && ! selected.isNew());
  return true;
 }

 /* (non-Javadoc)
  * @see android.app.Activity#onOptionsItemSelected(android.view.MenuItem)
  */
 @Override
 public boolean onOptionsItemSelected(MenuItem item) {
  switch (item.getItemId())
  {
  case R.id.itemSaveAsCopy :
   if (selected.getNickname().equals(textNickname.getText().toString()))
    textNickname.setText("Copy of "+selected.getNickname());
   updateSelectedFromView();
   selected.set_Id(0);
   saveAndWriteRecent();
   arriveOnPage();
   break;
  case R.id.itemDeleteConnection :
   Utils.showYesNoPrompt(this, "Delete?", "Delete " + selected.getNickname() + "?",
     new DialogInterface.OnClickListener() {
    @Override
    public void onClick(DialogInterface dialog, int i)
    {
     selected.Gen_delete(database.getWritableDatabase());
     arriveOnPage();
    }
   }, null);
   break;
  case R.id.itemOpenDoc :
   Utils.showDocumentation(this);
   break;
  }
  return true;
 }

 private void updateViewFromSelected() {
  if (selected==null)
   return;
  ipText.setText(selected.getAddress());
  portText.setText(Integer.toString(selected.getPort()));
  if (selected.getKeepPassword() || selected.getPassword().length()>0) {
   passwordText.setText(selected.getPassword());
  }
  groupForceFullScreen.check(selected.getForceFull()==BitmapImplHint.AUTO ? R.id.radioForceFullScreenAuto : (selected.getForceFull() == BitmapImplHint.FULL ? R.id.radioForceFullScreenOn : R.id.radioForceFullScreenOff));
  checkboxKeepPassword.setChecked(selected.getKeepPassword());
  checkboxLocalCursor.setChecked(selected.getUseLocalCursor());
  textNickname.setText(selected.getNickname());
  textUsername.setText(selected.getUserName());
  COLORMODEL cm = COLORMODEL.valueOf(selected.getColorModel());
  COLORMODEL[] colors=COLORMODEL.values();
  for (int i=0; i<colors.length; ++i)
  {
   if (colors[i] == cm) {
    colorSpinner.setSelection(i);
    break;
   }
  }
  updateRepeaterInfo(selected.getUseRepeater(), selected.getRepeaterId());
 }
 
 /**
  * Called when changing view to match selected connection or from
  * Repeater dialog to update the repeater information shown.
  * @param repeaterId If null or empty, show text for not using repeater
  */
 void updateRepeaterInfo(boolean useRepeater, String repeaterId)
 {
  if (useRepeater)
  {
   repeaterText.setText(repeaterId);
   repeaterTextSet = true;
  }
  else
  {
   repeaterText.setText(getText(R.string.repeater_empty_text));
   repeaterTextSet = false;
  }
 }
 
 private void updateSelectedFromView() {
  if (selected==null) {
   return;
  }
  selected.setAddress(ipText.getText().toString());
  try
  {
   selected.setPort(Integer.parseInt(portText.getText().toString()));
  }
  catch (NumberFormatException nfe)
  {
   
  }
  selected.setNickname(textNickname.getText().toString());
  selected.setUserName(textUsername.getText().toString());
  selected.setForceFull(groupForceFullScreen.getCheckedRadioButtonId()==R.id.radioForceFullScreenAuto ? BitmapImplHint.AUTO : (groupForceFullScreen.getCheckedRadioButtonId()==R.id.radioForceFullScreenOn ? BitmapImplHint.FULL : BitmapImplHint.TILE));
  selected.setPassword(passwordText.getText().toString());
  selected.setKeepPassword(checkboxKeepPassword.isChecked());
  selected.setUseLocalCursor(checkboxLocalCursor.isChecked());
  selected.setColorModel(((COLORMODEL)colorSpinner.getSelectedItem()).nameString());
  if (repeaterTextSet)
  {
   selected.setRepeaterId(repeaterText.getText().toString());
   selected.setUseRepeater(true);
  }
  else
  {
   selected.setUseRepeater(false);
  }
 }
 
 protected void onStart() {
  super.onStart();
  arriveOnPage();
 }
 
 /**
  * Return the object representing the app global state in the database, or null
  * if the object hasn't been set up yet
  * @param db App's database -- only needs to be readable
  * @return Object representing the single persistent instance of MostRecentBean, which
  * is the app's global state
  */
 static MostRecentBean getMostRecent(SQLiteDatabase db)
 {
  ArrayList<MostRecentBean> recents = new ArrayList<MostRecentBean>(1);
  MostRecentBean.getAll(db, MostRecentBean.GEN_TABLE_NAME, recents, MostRecentBean.GEN_NEW);
  if (recents.size() == 0)
   return null;
  return recents.get(0);
 }
 
 void arriveOnPage() {   ArrayList<ConnectionBean> c ArrayList<ConnectionBean>();
  ConnectionBean.getAll(database.getReadableDatabase(), ConnectionBean.GEN_TABLE_NAME, connections, ConnectionBean.newInstance);
  Collections.sort(connections);
  connections.add(0, new ConnectionBean());   int c
  if ( connections.size()>1)
  {
   MostRecentBean mostRecent = getMostRecent(database.getReadableDatabase());
   if (mostRecent != null)
   {
    for ( int i=1; i<connections.size(); ++i)
    {
     if (connections.get(i).get_Id() == mostRecent.getConnectionId())
     {       c
      break;
     }
    }
   }
  }
  spinnerConnection.setAdapter(new ArrayAdapter<ConnectionBean>(this,android.R.layout.simple_spinner_item,
    connections.toArray(new ConnectionBean[connections.size()])));
  spinnerConnection.setSelection(connectionIndex,false);
  selected=connections.get(connectionIndex);
  updateViewFromSelected();
  IntroTextDialog.showIntroTextIfNecessary(this, database);
 }
 
 protected void onStop() {
  super.onStop();
  if ( selected == null ) {
   return;
  }
  updateSelectedFromView();
  selected.save(database.getWritableDatabase());
 }
 
 VncDatabase getDatabaseHelper()
 {
  return database;
 }
 
 private void canvasStart() {
  if (selected == null) return;
  MemoryInfo info = Utils.getMemoryInfo(this);
  if (info.lowMemory) {
   // Low Memory situation.  Prompt.
   Utils.showYesNoPrompt(this, "Continue?", "Android reports low system memory.\nContinue with VNC connection?", new DialogInterface.OnClickListener() {
    @Override
    public void onClick(DialogInterface dialog, int which) {
     vnc();
    }
   }, null);
  } else
   vnc();
 }
 
 private void saveAndWriteRecent()
 {
  SQLiteDatabase db = database.getWritableDatabase();
  db.beginTransaction();
  try
  {
   selected.save(db);
   MostRecentBean mostRecent = getMostRecent(db);
   if (mostRecent == null)
   {
    mostRecent = new MostRecentBean();
    mostRecent.setConnectionId(selected.get_Id());
    mostRecent.Gen_insert(db);
   }
   else
   {
    mostRecent.setConnectionId(selected.get_Id());
    mostRecent.Gen_update(db);
   }
   db.setTransactionSuccessful();
  }
  finally
  {
   db.endTransaction();
  }
 }
 
 private void vnc() {
  updateSelectedFromView();
  saveAndWriteRecent();
  Intent intent = new Intent(this, VncCanvasActivity.class);
  intent.putExtra(VncConstants.CONNECTION,selected.Gen_getValues());
  startActivity(intent);
 }
}
 
 
가능하면 누가 해석좀;;

추천 비추천

0

고정닉 0

0

댓글 영역

전체 댓글 0
본문 보기

하단 갤러리 리스트 영역

왼쪽 컨텐츠 영역

갤러리 리스트 영역

갤러리 리스트
번호 제목 글쓴이 작성일 조회 추천
설문 반응이 재밌어서 자꾸만 놀리고 싶은 리액션 좋은 스타는? 운영자 25/07/28 - -
AD 휴대폰 액세서리 세일 중임! 운영자 25/07/28 - -
416028 횽들 개발노트북 씨피유 비교점 (223.62) 14.04.03 92 0
416027 php씹 극혐 ㅆㅂ [4] (223.33) 14.04.03 227 0
416026 C언어 질문 있습니다. item(203.226) 14.04.03 102 0
416023 힛자점 풀개미&#039;ㅅ&#.갤로그로 이동합니다. 14.04.03 76 0
416018 코드게이트 2014 (CODEGATE 2014 ) 후기 - 2 [13] why(222.120) 14.04.03 5315 18
416017 등가가속도 이웃집힘법사갤로그로 이동합니다. 14.04.03 84 0
416015 난 애니볼 때도 근성이 없었나보다. 이웃집힘법사갤로그로 이동합니다. 14.04.03 95 0
416014 국회 이웃집힘법사갤로그로 이동합니다. 14.04.03 60 0
416013 랩뷰 피스파이스 말고 뭐없나? [2] 딩기(114.111) 14.04.03 167 0
416012 사람은 언제 죽을까? 이웃집힘법사갤로그로 이동합니다. 14.04.03 96 0
416011 코드게이트 2014 (CODEGATE 2014 ) 후기 - 1 [3] why(222.120) 14.04.03 3337 10
416010 가지 못 한다 [1] 이웃집힘법사갤로그로 이동합니다. 14.04.03 90 0
416008 의미있는 내용 [4] 이웃집힘법사갤로그로 이동합니다. 14.04.03 100 0
416007 si하기 싫으면 니트족해라. [2] 덕후(124.49) 14.04.03 172 0
416005 c++ 창시자 이름 넘 어렵당 [4] ct(223.33) 14.04.03 277 0
416001 프갤러 테스트(2) 풀어봐. [13] 이웃집힘법사갤로그로 이동합니다. 14.04.03 385 0
415999 간단한 자바 문제 도움 ! [4] 자바(219.241) 14.04.03 230 0
415998 신입생인데 과제질문좀할께요 [7] 신입생(125.134) 14.04.03 146 0
415995 과제 질문 좀 할게요 형들 .. [4] 퍽킹(175.208) 14.04.03 120 0
415993 이거좀 해주세요 [4] ㅇㅅㅇ(58.121) 14.04.02 137 0
415992 프갤러들은 정보올림피아드 문제보면 후딱풀음? [1] ㅇㄴㅁㅇㄴㅁ(39.121) 14.04.02 143 0
415991 calculus(미적분학)의 원뜻 이웃집힘법사갤로그로 이동합니다. 14.04.02 188 0
415989 솔직히 자신없다.. [1] 변산댁갤로그로 이동합니다. 14.04.02 71 0
415988 니들 그거아냐? 변산댁갤로그로 이동합니다. 14.04.02 43 0
415987 아 개발자 때려치고싶다 [2] 111(211.36) 14.04.02 872 0
415986 서류전형 붙어서 필기 면접가는데 뭐 보면 될까?? [2] 123(220.84) 14.04.02 180 0
415985 이 븅신드라!! [1] 변산댁갤로그로 이동합니다. 14.04.02 60 0
415984 프갤 죽돌이치고 변산댁갤로그로 이동합니다. 14.04.02 440 0
415983 제발 도와줘 뇌터짐 [1] c초보(117.111) 14.04.02 609 0
415982 엑셀로 그림 그리기 [1] (117.55) 14.04.02 134 0
415981 c언어 인터넷에서 잘 정리된거 없어? [1] ㅇㅇ(112.185) 14.04.02 143 0
415980 프로그래머들은 만성피로 느낀다며? ㅇㅇ(112.185) 14.04.02 122 0
415979 si 에 희망 주상욱 ㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋ [1] ㅇㅇ(222.112) 14.04.02 130 0
415977 컴퓨터 두대로 병행해서 개발하는 방법? [2] ㅁㄴㅇ(110.45) 14.04.02 104 0
415976 딱 이 말만 하고 나는 간다. 변산댁갤로그로 이동합니다. 14.04.02 124 0
415974 아 ㅅㅂ 책 안보고 인터넷 강좌만 들어도 되겠네 ㅇㅇ(112.185) 14.04.02 113 0
415973 프갤에서 하는 말은 언제나 똑같네 변산댁갤로그로 이동합니다. 14.04.02 50 0
415972 야시발 정보올림피아드라며 [2] ㅁㄴㅇ(39.121) 14.04.02 174 0
415971 컴공 나오면 고급인력이죠? [2] 12(175.116) 14.04.02 327 0
415969 간단한 c 코드좀 알려주셈 [5] wkqkfldks(220.93) 14.04.02 291 0
415968 어떤 사람이 나한테 와서 우주가 어떻게 생성된거냐고 묻는다. 변산댁갤로그로 이동합니다. 14.04.02 53 0
415965 Python vs Ruby vs Javascript [1] ct(175.206) 14.04.02 194 0
415964 2008 vs 2010 vs 2012 [1] 갤로그로 이동합니다. 14.04.02 116 0
415963 원서 계속 읽어야되나 고수분들 답변 좀요... [6] 수크라제갤로그로 이동합니다. 14.04.02 119 0
415962 컴공과 3학년인데 c언어도 모르는데 [14] 얌마(124.5) 14.04.02 511 0
415961 소프트웨어 관련 부전공 하려고해 [4] ㅋㄹ(182.213) 14.04.02 206 0
415959 초보자 scanf 질문 [5] 이보게징징이(218.239) 14.04.02 128 0
415958 힛자점 [1] 풀개미&#039;ㅅ&#.갤로그로 이동합니다. 14.04.02 50 0
415957 해더파일 클래서 말이야 갤로그로 이동합니다. 14.04.02 78 0
415955 Directx11 입문서는없는거냐?? +^+(223.62) 14.04.02 81 0
뉴스 '금쪽같은 내 스타' 엄정화X송승헌 & 장다아X이민재, 25년 세월 순삭? 비포애프터 로맨스 포스터 공개! 디시트렌드 07.30
갤러리 내부 검색
제목+내용게시물 정렬 옵션

오른쪽 컨텐츠 영역

실시간 베스트

1/8

뉴스

디시미디어

디시이슈

1/2