List of usage examples for android.os Message getData
public Bundle getData()
From source file:com.google.ytd.SubmitActivity.java
public void upload(Uri videoUri) { this.dialog = new ProgressDialog(this); dialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); dialog.setMessage("uploading ..."); dialog.setCancelable(false);//from w w w .j a va 2s . com dialog.show(); Handler handler = new Handler() { @Override public void handleMessage(Message msg) { dialog.dismiss(); String videoId = msg.getData().getString("videoId"); if (!Util.isNullOrEmpty(videoId)) { currentFileSize = 0; totalBytesUploaded = 0; Intent result = new Intent(); result.putExtra("videoId", videoId); setResult(RESULT_OK, result); finish(); } else { String error = msg.getData().getString("error"); if (!Util.isNullOrEmpty(error)) { Toast.makeText(SubmitActivity.this, error, Toast.LENGTH_LONG).show(); } } } }; asyncUpload(videoUri, handler); }
From source file:info.guardianproject.mrapp.server.YouTubeSubmit.java
private String gdataUpload(File file, String uploadUrl, int start) throws IOException { //int chunk = end - start + 1; //int bufferSize = 1024; //byte[] buffer = new byte[bufferSize]; FileInputStream fileStream = new FileInputStream(file); URL url = new URL(uploadUrl); HttpPost hPut = getGDataHttpPost(url.getHost(), uploadUrl, null); hPut.setHeader("X-HTTP-Method-Override", "PUT"); // some mobile proxies do not support PUT, using X-HTTP-Method-Override to get around this problem if (isFirstRequest()) { Log.d(LOG_TAG,//from w w w .j ava 2s . c o m String.format("First time...Uploaded %d bytes so far.", (int) totalBytesUploaded, Locale.US)); } else { Log.d(LOG_TAG, String.format(Locale.US, "Retry: Uploaded %d bytes so far.", (int) totalBytesUploaded)); } String mimeType = "video/mp4"; hPut.setHeader("Content-Type", mimeType); long fileLength = file.length(); if (start != -1) { String cRange = String.format(Locale.US, "bytes %d-%d/%d", start, fileLength, fileLength); hPut.setHeader("Content-Range", cRange); Log.d(LOG_TAG, "upload content-range: " + cRange); } InputStreamEntityWithProgress fileEntity = new InputStreamEntityWithProgress(fileStream, start, fileLength, mimeType);//"binary/octet-stream"); hPut.setEntity(fileEntity); HttpResponse hResp = httpClient.execute(hPut); int responseCode = hResp.getStatusLine().getStatusCode(); Log.d(LOG_TAG, "responseCode=" + responseCode); Log.d(LOG_TAG, "responseMessage=" + hResp.getStatusLine().getReasonPhrase()); InputStream isResp = hResp.getEntity().getContent(); try { if (responseCode == 201) { String videoId = parseVideoId(isResp); /* String latLng = null; if (this.videoLocation != null) { latLng = String.format("lat=%f lng=%f", this.videoLocation.getLatitude(), this.videoLocation.getLongitude(), Locale.US); } */ Message msg = handler.obtainMessage(888); msg.getData().putInt("progress", 100); handler.sendMessage(msg); return videoId; } else if (responseCode == 200) { Header[] headers = hResp.getAllHeaders(); Log.d(LOG_TAG, String.format("Headers keys %s.", headers.length, Locale.US)); for (Header header : headers) { Log.d(LOG_TAG, String.format("Header key %s value %s.", header.getName(), header.getValue(), Locale.US)); } Log.w(LOG_TAG, "Received 200 response during resumable uploading"); throw new IOException( String.format(Locale.US, "Unexpected response code : responseCode=%d responseMessage=%s", responseCode, hResp.getStatusLine().getReasonPhrase())); } else { if ((responseCode + "").startsWith("5")) { String error = String.format(Locale.US, "responseCode=%d responseMessage=%s", responseCode, hResp.getStatusLine().getReasonPhrase()); Log.w(LOG_TAG, error); // TODO - this exception will trigger retry mechanism to kick in // TODO - even though it should not, consider introducing a new type so // TODO - resume does not kick in upon 5xx throw new IOException(error); } else if (responseCode == 308) { // these actually means "resume incomplete" // OK, the chunk completed succesfully Log.d(LOG_TAG, String.format("responseCode=%d responseMessage=%s", responseCode, hResp.getStatusLine().getReasonPhrase())); } else { // TODO - this case is not handled properly yet Log.w(LOG_TAG, String.format("Unexpected return code : %d %s while uploading :%s", responseCode, hResp.getStatusLine().getReasonPhrase(), uploadUrl, Locale.US)); } } } catch (ParserConfigurationException e) { e.printStackTrace(); } catch (SAXException e) { e.printStackTrace(); } return null; }
From source file:net.networksaremadeofstring.rhybudd.ViewZenossDevice.java
/** Called when the activity is first created. */ @Override/*from ww w.j a v a2s . c o m*/ public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); settings = PreferenceManager.getDefaultSharedPreferences(this); setContentView(R.layout.view_zenoss_device3); actionbar = getActionBar(); actionbar.setDisplayHomeAsUpEnabled(true); actionbar.setHomeButtonEnabled(true); list = (ListView) findViewById(R.id.ZenossEventsList); errorHandler = new Handler() { public void handleMessage(Message msg) { try { Toast.makeText(ViewZenossDevice.this, msg.getData().getString("exception"), Toast.LENGTH_LONG) .show(); } catch (Exception e) { ////BugSenseHandler.sendException("ViewZenossDevice-ErrorHandler", e); } } }; loadAverageHandler = new Handler() { public void handleMessage(Message msg) { try { ((ImageView) findViewById(R.id.loadAverageGraph)).setImageDrawable(loadAverageGraph); } catch (Exception e) { e.printStackTrace(); } } }; CPUGraphHandler = new Handler() { public void handleMessage(Message msg) { try { ((ImageView) findViewById(R.id.CPUGraph)).setImageDrawable(CPUGraph); } catch (Exception e) { e.printStackTrace(); } } }; MemoryGraphHandler = new Handler() { public void handleMessage(Message msg) { try { ((ImageView) findViewById(R.id.MemoryGraph)).setImageDrawable(MemoryGraph); } catch (Exception e) { e.printStackTrace(); } } }; eventsHandler = new Handler() { public void handleMessage(Message msg) { try { //((ProgressBar) findViewById(R.id.eventsProgressBar)).setVisibility(4); } catch (Exception e) { ////BugSenseHandler.sendException("ViewZenossDevice", e); } if (EventCount > 0 && msg.what == 1) { try { adapter = new ZenossEventsAdaptor(ViewZenossDevice.this, listOfZenossEvents, false); list.setAdapter(adapter); } catch (Exception e) { ////BugSenseHandler.sendException("ViewZenossDevice", e); } } else { list = null; } } }; firstLoadHandler = new Handler() { public void handleMessage(Message msg) { if (dialog != null) dialog.dismiss(); try { if (DeviceObject != null && msg.what == 1 && DeviceObject.getJSONObject("result").getBoolean("success") == true) { //Log.i("DeviceDetails",DeviceObject.toString()); DeviceDetails = DeviceObject.getJSONObject("result").getJSONObject("data"); try { String Name = DeviceDetails.getString("snmpSysName").toUpperCase(); if (Name.equals("")) { Name = DeviceDetails.getString("name").toUpperCase(); } ((TextView) findViewById(R.id.deviceID)).setText(Name); //actionbar.setTitle(DeviceDetails.getString("snmpSysName")); actionbar.setSubtitle(Name); } catch (Exception e) { ((TextView) findViewById(R.id.deviceID)).setText("--"); } try { ((TextView) findViewById(R.id.modelTime)) .setText(DeviceDetails.getString("lastCollected")); } catch (Exception e) { ((TextView) findViewById(R.id.modelTime)).setText("Unknown"); } try { ((TextView) findViewById(R.id.firstSeen)).setText(DeviceDetails.getString("firstSeen")); } catch (Exception e) { ((TextView) findViewById(R.id.firstSeen)).setText(""); } try { ((TextView) findViewById(R.id.location)) .setText(DeviceDetails.getString("snmpLocation")); } catch (Exception e) { ((TextView) findViewById(R.id.location)).setText("Unknown Location"); } try { ((TextView) findViewById(R.id.uptime)).setText(DeviceDetails.getString("uptime")); } catch (Exception e) { //Already got a placeholder } try { ((TextView) findViewById(R.id.productionState)) .setText(DeviceDetails.getString("productionState")); } catch (Exception e) { //Already got a placeholder } try { ((TextView) findViewById(R.id.memorySwap)) .setText(DeviceDetails.getJSONObject("memory").getString("ram") + " / " + DeviceDetails.getJSONObject("memory").getString("swap")); } catch (Exception e) { //Already got a placeholder } String Groups = ""; try { for (int i = 0; i < DeviceDetails.getJSONArray("groups").length(); i++) { if (i > 0) Groups += ", "; try { Groups += DeviceDetails.getJSONArray("groups").getJSONObject(i) .getString("name"); } catch (Exception e) { ////BugSenseHandler.sendException("ViewZenossDevice", e); } } ((TextView) findViewById(R.id.groups)).setText(Groups); } catch (Exception e) { ////BugSenseHandler.sendException("ViewZenossDevice", e); } String Systems = ""; try { for (int i = 0; i < DeviceDetails.getJSONArray("systems").length(); i++) { if (i > 0) Systems += ", "; Systems += DeviceDetails.getJSONArray("systems").getJSONObject(i).getString("name"); } ((TextView) findViewById(R.id.systems)).setText(Systems); } catch (Exception e) { //Already got a placeholder ////BugSenseHandler.sendException("ViewZenossDevice", e); } //etc } else { Toast.makeText(ViewZenossDevice.this, "There was an error loading the Device details", Toast.LENGTH_LONG).show(); //finish(); } } catch (Exception e) { //e.printStackTrace(); Toast.makeText(ViewZenossDevice.this, "An error was encountered parsing the JSON.", Toast.LENGTH_LONG).show(); ////BugSenseHandler.sendException("ViewZenossDevice", e); } } }; dialog = new ProgressDialog(this); dialog.setTitle("Contacting Zenoss"); dialog.setMessage("Please wait:\nLoading Device details...."); dialog.show(); dataPreload = new Thread() { public void run() { try { Message msg = new Message(); Bundle bundle = new Bundle(); if (API == null) { try { /*if(settings.getBoolean("httpBasicAuth", false)) { API = new ZenossAPIv2(settings.getString("userName", ""), settings.getString("passWord", ""), settings.getString("URL", ""),settings.getString("BAUser", ""), settings.getString("BAPassword", "")); } else { API = new ZenossAPIv2(settings.getString("userName", ""), settings.getString("passWord", ""), settings.getString("URL", "")); }*/ } /*catch(ConnectTimeoutException cte) { if(cte.getMessage() != null) { //Toast.makeText(ViewZenossDevice.this, "An error was encountered;\r\n" + cte.getMessage().toString(), Toast.LENGTH_LONG).show(); bundle.putString("exception","The connection timed out;\r\n" + cte.getMessage().toString()); msg.setData(bundle); msg.what = 0; errorHandler.sendMessage(msg); } else { bundle.putString("exception","A time out error was encountered but the exception thrown contains no further information."); msg.setData(bundle); msg.what = 0; errorHandler.sendMessage(msg); //Toast.makeText(ViewZenossDevice.this, "An error was encountered but the exception thrown contains no further information.", Toast.LENGTH_LONG).show(); } }*/ catch (Exception e) { if (e.getMessage() != null) { bundle.putString("exception", "An error was encountered;\r\n" + e.getMessage().toString()); msg.setData(bundle); msg.what = 0; errorHandler.sendMessage(msg); //Toast.makeText(ViewZenossDevice.this, "An error was encountered;\r\n" + e.getMessage().toString(), Toast.LENGTH_LONG).show(); } else { bundle.putString("exception", "An error was encountered but the exception thrown contains no further information."); msg.setData(bundle); msg.what = 0; errorHandler.sendMessage(msg); //Toast.makeText(ViewZenossDevice.this, "An error was encountered but the exception thrown contains no further information.", Toast.LENGTH_LONG).show(); } } DeviceObject = API.GetDevice(getIntent().getStringExtra("UID")); } } catch (Exception e) { //e.printStackTrace(); //BugSenseHandler.sendException("updateDevices-dataPreload",e); firstLoadHandler.sendEmptyMessage(0); } firstLoadHandler.sendEmptyMessage(1); } }; dataPreload.start(); loadAvgGraphLoad = new Thread() { public void run() { try { if (API == null) { Message msg = new Message(); Bundle bundle = new Bundle(); try { /*if(settings.getBoolean("httpBasicAuth", false)) { API = new ZenossAPIv2(settings.getString("userName", ""), settings.getString("passWord", ""), settings.getString("URL", ""),settings.getString("BAUser", ""), settings.getString("BAPassword", "")); } else { API = new ZenossAPIv2(settings.getString("userName", ""), settings.getString("passWord", ""), settings.getString("URL", "")); }*/ if (PreferenceManager.getDefaultSharedPreferences(ViewZenossDevice.this) .getBoolean(ZenossAPI.PREFERENCE_IS_ZAAS, false)) { API = new ZenossAPIZaas(); } else { API = new ZenossAPICore(); } ZenossCredentials credentials = new ZenossCredentials(ViewZenossDevice.this); API.Login(credentials); } catch (Exception e) { e.printStackTrace(); } } JSONObject graphURLs = API.GetDeviceGraphs(getIntent().getStringExtra("UID")); //Log.e("graphURLs",graphURLs.toString(3)); int urlCount = graphURLs.getJSONObject("result").getJSONArray("data").length(); for (int i = 0; i < urlCount; i++) { JSONObject currentGraph = null; try { currentGraph = graphURLs.getJSONObject("result").getJSONArray("data").getJSONObject(i); if (currentGraph.getString("title").equals("Load Average")) { loadAverageGraph = API.GetGraph(currentGraph.getString("url")); loadAverageHandler.sendEmptyMessage(1); } else if (currentGraph.getString("title").equals("CPU Utilization")) { CPUGraph = API.GetGraph(currentGraph.getString("url")); CPUGraphHandler.sendEmptyMessage(1); } else if (currentGraph.getString("title").equals("Memory Utilization")) { MemoryGraph = API.GetGraph(currentGraph.getString("url")); MemoryGraphHandler.sendEmptyMessage(1); } } catch (Exception e) { e.printStackTrace(); } } } catch (Exception e) { e.printStackTrace(); } } }; loadAvgGraphLoad.start(); eventsLoad = new Thread() { public void run() { try { if (API == null) { Message msg = new Message(); Bundle bundle = new Bundle(); try { /*if(settings.getBoolean("httpBasicAuth", false)) { API = new ZenossAPIv2(settings.getString("userName", ""), settings.getString("passWord", ""), settings.getString("URL", ""),settings.getString("BAUser", ""), settings.getString("BAPassword", "")); } else { API = new ZenossAPIv2(settings.getString("userName", ""), settings.getString("passWord", ""), settings.getString("URL", "")); }*/ if (PreferenceManager.getDefaultSharedPreferences(ViewZenossDevice.this) .getBoolean(ZenossAPI.PREFERENCE_IS_ZAAS, false)) { API = new ZenossAPIZaas(); } else { API = new ZenossAPICore(); } ZenossCredentials credentials = new ZenossCredentials(ViewZenossDevice.this); API.Login(credentials); } catch (ConnectTimeoutException cte) { if (cte.getMessage() != null) { //Toast.makeText(ViewZenossDevice.this, , Toast.LENGTH_LONG).show(); bundle.putString("exception", "An error was encountered;\r\n" + cte.getMessage().toString()); } else { //Toast.makeText(ViewZenossDevice.this, "An error was encountered but the exception thrown contains no further information.", Toast.LENGTH_LONG).show(); bundle.putString("exception", "An error was encountered but the exception thrown contains no further information."); } msg.setData(bundle); msg.what = 0; errorHandler.sendMessage(msg); } catch (Exception e) { if (e.getMessage() != null) { //Toast.makeText(ViewZenossDevice.this, "An error was encountered;\r\n" + e.getMessage().toString(), Toast.LENGTH_LONG).show(); bundle.putString("exception", "An error was encountered;\r\n" + e.getMessage().toString()); } else { //Toast.makeText(ViewZenossDevice.this, "An error was encountered but the exception thrown contains no further information.", Toast.LENGTH_LONG).show(); bundle.putString("exception", "An error was encountered but the exception thrown contains no further information."); } msg.setData(bundle); msg.what = 0; errorHandler.sendMessage(msg); } } /*try { EventsObject = API.GetDeviceEvents(getIntent().getStringExtra("UID"),false); } catch(Exception e) { e.printStackTrace(); }*/ /*try { if((EventsObject.has("type") && EventsObject.get("type").equals("exception")) || !EventsObject.getJSONObject("result").has("totalCount") ) { EventsObject = API.GetDeviceEvents(getIntent().getStringExtra("UID"),true); } } catch(Exception e) { e.printStackTrace(); }*/ if (null != EventsObject && EventsObject.has("result") && EventsObject.getJSONObject("result").getInt("totalCount") > 0) { Events = EventsObject.getJSONObject("result").getJSONArray("events"); try { if (EventsObject != null) { EventCount = EventsObject.getJSONObject("result").getInt("totalCount"); for (int i = 0; i < EventCount; i++) { //JSONObject CurrentEvent = null; try { //CurrentEvent = Events.getJSONObject(i); listOfZenossEvents.add(new ZenossEvent(Events.getJSONObject(i))); //Log.i("ForLoop",CurrentEvent.getString("summary")); } catch (JSONException e) { //Log.e("API - Stage 2 - Inner", e.getMessage()); } catch (Exception e) { //BugSenseHandler.sendException("ViewZenossDevice-EventsLoop", e); } } eventsHandler.sendEmptyMessage(1); } else { //Log.i("eventsLoad","Had a problem; EventsObject was null"); //eventsHandler.sendEmptyMessage(0); } } catch (JSONException e) { e.printStackTrace(); //BugSenseHandler.sendException("ViewZenossDevice-Events", e); eventsHandler.sendEmptyMessage(0); } } else { eventsHandler.sendEmptyMessage(0); } } catch (Exception e) { //Log.e("API - Stage 1", e.getMessage()); //BugSenseHandler.sendException("ViewZenossDevice-Events", e); eventsHandler.sendEmptyMessage(0); } } }; eventsLoad.start(); }
From source file:activities.Activity_Main.java
private void end_of_init() { // Finalize screen appearence if (Tracer == null) Tracer = Tracer.getInstance();//from w w w . ja v a 2 s . c o m Tracer.v(mytag, "end_of_init Main Screen.."); if (!reload) { //alertDialog not sync splash if (AD_notSyncAlert == null) createAlert(); } //splash if (!SP_params.getBoolean("SPLASH", false)) { Dialog_Splash dialog_splash = new Dialog_Splash(this); dialog_splash.show(); SP_prefEditor.clear(); SP_prefEditor.putBoolean("SPLASH", true); SP_prefEditor.commit(); return; } end_of_init_requested = false; if (history != null) history = null; //Free resource history = new Vector<String[]>(); historyPosition = 0; //load widgets if (widgetHandler == null) { Tracer.i(mytag, "Starting WidgetHandler thread !"); widgetHandler = new Handler() { @Override public void handleMessage(Message msg) { try { historyPosition++; loadWigets(msg.getData().getInt("id"), msg.getData().getString("type")); Tracer.v(mytag + ".widgetHandler", "add history " + msg.getData().getInt("id") + " " + msg.getData().getString("type")); history.add(historyPosition, new String[] { msg.getData().getInt("id") + "", msg.getData().getString("type") }); } catch (Exception e) { Tracer.e(mytag + ".widgetHandler", "handler error into loadWidgets"); e.printStackTrace(); } } }; } if (WM_Agent == null) { Tracer.v(mytag, "Starting wAgent !"); WM_Agent = new Widgets_Manager(Tracer, widgetHandler); WM_Agent.widgetupdate = WU_widgetUpdate; } if (T_starting != null) { T_starting.cancel(); T_starting.setText("Creating widgets...."); T_starting.setDuration(Toast.LENGTH_SHORT); T_starting.show(); } init_done = true; if ((SP_params.getBoolean("START_ON_MAP", false) && (!Tracer.force_Main))) { //Solve #2029 if (SP_params.getBoolean("SYNC", false)) { Tracer.e(mytag, "Direct start on Map requested..."); Tracer.Map_as_main = true; //Memorize that Map is now the main screen INTENT_map = new Intent(Activity_Main.this, Activity_Map.class); startActivity(INTENT_map); } else { if (AD_notSyncAlert == null) createAlert(); AD_notSyncAlert.show(); } } else { Tracer.force_Main = false; //Reset flag 'called from Map view' loadWigets(0, "root"); historyPosition = 0; history.add(historyPosition, new String[] { "0", "root" }); } init_done = true; dont_kill = false; //By default, the onDestroy activity will also kill engines }
From source file:org.uoyabause.android.YabauseHandler.java
public void handleMessage(Message msg) { yabause.showDialog(msg.what, msg.getData()); }
From source file:com.zxing.qrcode.decoding.CaptureActivityHandler.java
@Override public void handleMessage(Message message) { switch (message.what) { case R.id.auto_focus: // Log.d(TAG, "Got auto-focus message"); // When one auto focus pass finishes, start another. This is the // closest thing to // continuous AF. It does seem to hunt a bit, but I'm not sure what // else to do. if (state == State.PREVIEW) { CameraManager.get().requestAutoFocus(this, R.id.auto_focus); }// ww w .j a va 2 s . c om break; case R.id.restart_preview: Log.d(TAG, "Got restart preview message"); restartPreviewAndDecode(); break; case R.id.decode_succeeded: Log.d(TAG, "Got decode succeeded message"); state = State.SUCCESS; Bundle bundle = message.getData(); Bitmap barcode = bundle == null ? null : (Bitmap) bundle.getParcelable(DecodeThread.BARCODE_BITMAP); final String str_result = ((Result) message.obj).getText(); System.out.println("====str_result====" + str_result); String match = "^[0-9]{13}"; boolean b = str_result.matches(match); // Toast.makeText(activity, ""+b, 1).show(); // activity.handleDecode((Result) message.obj, barcode); if (b) { String url = RequestUrls.TIAOXING_CODE_URL.replace("[code]", str_result); FinalHttp fh = new FinalHttp(); fh.get(url, new AjaxCallBack<Object>() { @Override public void onSuccess(Object t) { // TODO Auto-generated method stub super.onSuccess(t); try { System.out.println("===TIAOXING_CODE_URL====" + new JSONObject(t.toString())); Intent tagIntent = new Intent(activity, TagdetialActivity.class); tagIntent.putExtra("jsonStr", t.toString()); tagIntent.putExtra("barcodes", str_result); tagIntent.putExtra("eid", eid); tagIntent.putExtra("tag_ids", tag_ids); activity.startActivity(tagIntent); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } } @Override public void onFailure(Throwable t, String strMsg) { // TODO Auto-generated method stub super.onFailure(t, strMsg); } }); } else { try { Intent intent = new Intent(Intent.ACTION_VIEW); // //// intent.setPackage("com.tencent.mm");// intent.putExtra(Intent.EXTRA_SUBJECT, "share"); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); // // // intent.setData(Uri.parse("http://weixin.qq.com/r/o3w_sRvEMSVOhwrSnyCH")); intent.setData(Uri.parse(str_result)); activity.startActivity(intent); } catch (Exception e) { Toast.makeText(activity, R.string.no_wechat_rem, Toast.LENGTH_SHORT).show(); } } break; case R.id.decode_failed: // We're decoding as fast as possible, so when one decode fails, // start another. state = State.PREVIEW; CameraManager.get().requestPreviewFrame(decodeThread.getHandler(), R.id.decode); break; case R.id.return_scan_result: Log.d(TAG, "Got return scan result message"); activity.setResult(Activity.RESULT_OK, (Intent) message.obj); activity.finish(); break; } }
From source file:org.zywx.wbpalmstar.engine.universalex.EUExWidget.java
@Override public void onHandleMessage(Message message) { if (message == null) { return;//from w w w . j ava 2 s . com } Bundle bundle = message.getData(); switch (message.what) { case MSG_IS_APP_INSTALLED: isAppInstalledMsg(bundle.getStringArray(BUNDLE_DATA)); break; case MSG_RELOAD_WIDGET_BY_APPID: reloadWidgetByAppIdMsg(bundle.getStringArray(BUNDLE_DATA)); break; default: super.onHandleMessage(message); } }
From source file:it.angrydroids.epub3reader.EpubReaderMain.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_epub_reader_main); // ----- get activity elements view1 = (WebView) findViewById(R.id.firstViewport); view2 = (WebView) findViewById(R.id.secondViewport); layout = (LinearLayout) findViewById(R.id.mainLayout); iconCloseView1 = (Button) findViewById(R.id.topRightFirstView); iconCloseView2 = (Button) findViewById(R.id.topRightSecondView); layoutView1 = (RelativeLayout) findViewById(R.id.firstViewportLayout); layoutView2 = (RelativeLayout) findViewById(R.id.secondViewportLayout); // -----/*from w ww .java 2s . c o m*/ // ----- get activity screen size DisplayMetrics metrics = this.getResources().getDisplayMetrics(); screenWidth = metrics.widthPixels; screenHeight = metrics.heightPixels; // ----- navigator = new EpubNavigator(getBaseContext()); // enable JavaScript for cool things to happen! view1.getSettings().setJavaScriptEnabled(true); view2.getSettings().setJavaScriptEnabled(true); // when the app starts, only one view is shown updateView1(ViewStateEnum.books); updateView2(ViewStateEnum.invisible); // ----- SWIPE PAGE view1.setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { if (stateView1 == ViewStateEnum.books) { swipePage(v, event, BookEnum.first); } if (syncScrollActivated == true && stateView2 != ViewStateEnum.invisible) { // syncScroll(v, view2, event); work in progress } WebView view = (WebView) v; return view.onTouchEvent(event); } }); view2.setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { if (stateView2 == ViewStateEnum.books) { swipePage(v, event, BookEnum.second); } WebView view = (WebView) v; return view.onTouchEvent(event); } }); // ----- // ----- VIEW CLOSING iconCloseView1.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { ViewStateEnum newState = navigator.closeView1(); ViewStateEnum oldState = stateView1; updateView1(newState); if (oldState == ViewStateEnum.books) { updateView2(ViewStateEnum.invisible); } } }); iconCloseView2.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { updateView2(navigator.closeView2()); } }); // ----- // ----- NOTE & LINK view1.setOnLongClickListener(new OnLongClickListener() { @Override public boolean onLongClick(View v) { if (stateView1 == ViewStateEnum.books || stateView1 == ViewStateEnum.notes) { Message msg = new Message(); msg.setTarget(new Handler() { @Override public void handleMessage(Message msg) { super.handleMessage(msg); String url = msg.getData().getString(getString(R.string.url)); if (url != null) if (stateView1 == ViewStateEnum.books || stateView1 == ViewStateEnum.notes) { updateView2(ViewStateEnum.notes); navigator.setView2(url); } else { navigator.setView1(url); } } }); view1.requestFocusNodeHref(msg); } return false; } }); view1.setWebViewClient(new WebViewClient() { public boolean shouldOverrideUrlLoading(WebView view, String url) { try { updateView1(navigator.setView1(url)); } catch (Exception e) { errorMessage(getString(R.string.error_LoadPage)); } return true; } }); view2.setOnLongClickListener(new OnLongClickListener() { @Override public boolean onLongClick(View v) { Message msg = new Message(); msg.setTarget(new Handler() { @Override public void handleMessage(Message msg) { super.handleMessage(msg); String url = msg.getData().getString(getString(R.string.url)); if (url != null) { try { if (stateView2 == ViewStateEnum.books || stateView2 == ViewStateEnum.notes) { updateView1(ViewStateEnum.notes); navigator.setView1(url); } else { navigator.setView2(url); } } catch (Exception e) { errorMessage(getString(R.string.error_LoadPage)); } } } }); view2.requestFocusNodeHref(msg); return false; } }); view2.setWebViewClient(new WebViewClient() { public boolean shouldOverrideUrlLoading(WebView view, String url) { try { updateView2(navigator.setView2(url)); } catch (Exception e) { errorMessage(getString(R.string.error_LoadPage)); } return true; } }); // ----- // ----- LOAD STATE SharedPreferences preferences = getPreferences(MODE_PRIVATE); if (preferences.getBoolean(getString(R.string.bookOpen), false)) { loadState(preferences); } else { bookSelector = BookEnum.first; Intent goToChooser = new Intent(this, FileChooser.class); startActivityForResult(goToChooser, 0); } // ----- }
From source file:org.mortbay.ijetty.IJetty.java
License:asdf
public IJetty() { super();/*from w w w . j a va 2s . c o m*/ handler = new Handler() { public void handleMessage(Message msg) { int total = msg.getData().getInt("prog"); progressDialog.setProgress(total); if (total >= 100) { dismissDialog(__SETUP_PROGRESS_DIALOG); } } }; }
From source file:org.mortbay.ijetty.IJetty.java
License:asdf
private void downloadMsg(android.os.Message msg) { final String downloadUrl = msg.getData().getString("downloadUrl"); final String savedName = msg.getData().getString("savedName"); DownloadManager.getInstance().startDownload(downloadUrl, savedName); }