List of usage examples for android.view KeyEvent KEYCODE_ENTER
int KEYCODE_ENTER
To view the source code for android.view KeyEvent KEYCODE_ENTER.
Click Source Link
From source file:com.velli.passwordmanager.FragmentLockScreen.java
@Override public boolean onKey(View v, int keyCode, KeyEvent event) { if (event.getAction() == KeyEvent.ACTION_UP && keyCode == KeyEvent.KEYCODE_ENTER) { onClick(mButtonOk);// w w w .java2 s .c o m } return false; }
From source file:com.googlecode.eyesfree.brailleback.IMENavigationModeTest.java
/** * Tests the behaviour of the "text only" mode. * Used when there's an input connection, but input is not started. *///from w w w . jav a 2s .c o m public void testTextOnlyMode() { mIMENavMode.onActivate(); mIMENavMode.onCreateIME(); verify(mNext).onActivate(); mIMENavMode.onBindInput(); assertEquals(mBrailleTranslator, mIMENavMode.getBrailleTranslator()); assertNull(mIMENavMode.getDisplayManager()); assertEquals(mFeedbackManager, mIMENavMode.getFeedbackManager()); AccessibilityEvent accessibilityEvent = AccessibilityEvent.obtain(); try { mIMENavMode.onObserveAccessibilityEvent(accessibilityEvent); verify(mNext).onObserveAccessibilityEvent(accessibilityEvent); } finally { accessibilityEvent.recycle(); } accessibilityEvent = AccessibilityEvent.obtain(); try { mIMENavMode.onAccessibilityEvent(accessibilityEvent); verify(mNext).onAccessibilityEvent(accessibilityEvent); } finally { accessibilityEvent.recycle(); } AccessibilityNodeInfoCompat node = AccessibilityNodeInfoCompat.obtain(); try { mIMENavMode.onInvalidateAccessibilityNode(node); verify(mNext).onInvalidateAccessibilityNode(node); } finally { node.recycle(); } DisplayManager.Content content = new DisplayManager.Content(""); mIMENavMode.onPanLeftOverflow(content); verify(mNext).onPanLeftOverflow(content); mIMENavMode.onPanRightOverflow(content); verify(mNext).onPanRightOverflow(content); BrailleInputEvent inputEvent = new BrailleInputEvent(BrailleInputEvent.CMD_KEY_ENTER, 0, 0); mIMENavMode.onMappedInputEvent(inputEvent, content); verify(mNext, never()).onMappedInputEvent(inputEvent, content); verify(mIME).sendAndroidKey(KeyEvent.KEYCODE_ENTER); inputEvent = new BrailleInputEvent(BrailleInputEvent.CMD_KEY_DEL, 0, 0); mIMENavMode.onMappedInputEvent(inputEvent, content); verify(mNext, never()).onMappedInputEvent(inputEvent, content); verify(mIME).sendAndroidKey(KeyEvent.KEYCODE_DEL); inputEvent = new BrailleInputEvent(BrailleInputEvent.CMD_BRAILLE_KEY, 0x1b, 0); mIMENavMode.onMappedInputEvent(inputEvent, content); verify(mNext, never()).onMappedInputEvent(inputEvent, content); verify(mIME).handleBrailleKey(0x1b); inputEvent = new BrailleInputEvent(BrailleInputEvent.CMD_NAV_ITEM_NEXT, 0, 0); mIMENavMode.onMappedInputEvent(inputEvent, content); verify(mNext).onMappedInputEvent(inputEvent, content); verify(mIME, never()).moveCursor(anyInt(), anyInt()); inputEvent = new BrailleInputEvent(BrailleInputEvent.CMD_ACTIVATE_CURRENT, 0, 0); mIMENavMode.onMappedInputEvent(inputEvent, content); verify(mNext).onMappedInputEvent(inputEvent, content); verify(mIME, never()).sendDefaultAction(); inputEvent = new BrailleInputEvent(BrailleInputEvent.CMD_ROUTE, 0, 0); mIMENavMode.onMappedInputEvent(inputEvent, content); verify(mNext).onMappedInputEvent(inputEvent, content); verify(mIME, never()).route(anyInt(), any(DisplayManager.Content.class)); mIMENavMode.onUnbindInput(); mIMENavMode.onDestroyIME(); verify(mSelfBrailleManager, atLeastOnce()).setImeOpen(false); verify(mSelfBrailleManager, never()).setImeOpen(true); // Deactivate, but make sure it didn't happen too early. verify(mNext, never()).onDeactivate(); mIMENavMode.onDeactivate(); verify(mNext).onDeactivate(); }
From source file:com.nttec.everychan.ui.BoardsListFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { if (isFailInstance) { Toast.makeText(activity, R.string.error_unknown, Toast.LENGTH_LONG).show(); return new View(activity); }//w w w . j a v a2 s .c o m startItem = tabModel.startItemNumber; startItemTop = tabModel.startItemTop; rootView = inflater.inflate(R.layout.boardslist_fragment, container, false); loadingView = rootView.findViewById(R.id.boardslist_loading); errorView = rootView.findViewById(R.id.boardslist_error); errorTextView = (TextView) errorView.findViewById(R.id.frame_error_text); listView = (ListView) rootView.findViewById(android.R.id.list); listView.setOnItemClickListener(this); registerForContextMenu(listView); boardField = (EditText) rootView.findViewById(R.id.boardslist_board_field); boardField.setOnKeyListener(new View.OnKeyListener() { @Override public boolean onKey(View v, int keyCode, KeyEvent event) { if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) { onClick(v); return true; } return false; } }); buttonGo = (Button) rootView.findViewById(R.id.boardslist_btn_go); buttonGo.setOnClickListener(this); activity.setTitle(chan.getDisplayingName()); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) CompatibilityImpl.setActionBarCustomFavicon(activity, chan.getChanFavicon()); update(false); return rootView; }
From source file:com.flipzu.flipzu.Recorder.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); debug.logV(TAG, "onCreate()"); /* set content view from recorder.xml */ setContentView(R.layout.recorder);/*from w w w .ja v a2s .c o m*/ /* actionbar */ getSupportActionBar().setDisplayShowTitleEnabled(false); getSupportActionBar().setBackgroundDrawable(getResources().getDrawable(R.drawable.ab_background)); /* init Google tracker */ initGATracker(); /* init recording intent if needed */ if (intent == null) { intent = new Intent(this, FlipzuRecorderService.class); } /* vumeter */ if (vumeter == null) { vumeter = new VUMeter(this); } /* button listeners */ final Button rec_but = (Button) findViewById(R.id.rec_but); rec_but.setOnClickListener(new OnClickListener() { public void onClick(View v) { // if we're playing, stop if (mState == recorderState.STOPPED) { startRec(); return; } // otherwise, start recording and broadcast tasks if (mState == recorderState.RECORDING) { stopRec(); return; } } }); final EditText bcast_title_et = (EditText) findViewById(R.id.bcast_title); bcast_title_et.setOnKeyListener(new OnKeyListener() { public boolean onKey(View v, int keyCode, KeyEvent event) { // If the event is a key-down event on the "enter" button if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) { // Perform action on key press startRec(); return true; } return false; } }); }
From source file:jp.ksksue.app.terminal.AndroidUSBSerialMonitorLite.java
/** Called when the activity is first created. */ @Override/*w ww . j a v a 2s .c o m*/ public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); /* FIXME : How to check that there is a title bar menu or not. // Should not set a Window.FEATURE_NO_TITLE on Honeycomb because a user cannot see menu button. if(isICSorHigher) { if(!getWindow().hasFeature(Window.FEATURE_ACTION_BAR)) { requestWindowFeature(Window.FEATURE_NO_TITLE); } } */ setContentView(R.layout.main); mSvText = (ScrollView) findViewById(R.id.svText); mTvSerial = (TextView) findViewById(R.id.tvSerial); btWrite = (Button) findViewById(R.id.btWrite); btWrite.setEnabled(false); etWrite = (EditText) findViewById(R.id.etWrite); etWrite.setEnabled(false); etWrite.setHint("CR : \\r, LF : \\n, bin : \\u0000"); if (SHOW_DEBUG) { Log.d(TAG, "New FTDriver"); } // get service mSerial = new Physicaloid(this); if (SHOW_DEBUG) { Log.d(TAG, "New instance : " + mSerial); } // listen for new devices IntentFilter filter = new IntentFilter(); filter.addAction(UsbManager.ACTION_USB_DEVICE_ATTACHED); filter.addAction(UsbManager.ACTION_USB_DEVICE_DETACHED); registerReceiver(mUsbReceiver, filter); if (SHOW_DEBUG) { Log.d(TAG, "FTDriver beginning"); } openUsbSerial(); etWrite.setOnKeyListener(new OnKeyListener() { @Override public boolean onKey(View v, int keyCode, KeyEvent event) { if (event.getAction() == KeyEvent.ACTION_UP && keyCode == KeyEvent.KEYCODE_ENTER) { writeDataToSerial(); return true; } return false; } }); // --------------------------------------------------------------------------------------- // Write Button // --------------------------------------------------------------------------------------- if (!USE_WRITE_BUTTON_FOR_DEBUG) { btWrite.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { writeDataToSerial(); } }); } else { // Write test button for debug btWrite.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { String strWrite = ""; for (int i = 0; i < 3000; ++i) { strWrite = strWrite + " " + Integer.toString(i); } if (SHOW_DEBUG) { Log.d(TAG, "FTDriver Write(" + strWrite.length() + ") : " + strWrite); } mSerial.write(strWrite.getBytes(), strWrite.length()); } }); } // end of if(SHOW_WRITE_TEST_BUTTON) btnLoad = (Button) findViewById(R.id.btnLoad); btnLoad.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { SimpleFileDialog simpleFileDialog = new SimpleFileDialog(AndroidUSBSerialMonitorLite.this, "FileOpen", new SimpleFileDialog.SimpleFileDialogListener() { @Override public void onChosenDir(String chosenDir) { File file = null; FileInputStream fileInputStream = null; byte[] data; try { file = new File(chosenDir); if (file.isDirectory()) { throw new IOException("not file"); } fileInputStream = new FileInputStream(file); data = new byte[(int) file.length()]; fileInputStream.read(data); String dataText = new String(data, "UTF-8"); parseJSON(dataText); } catch (IOException e) { Toast.makeText(AndroidUSBSerialMonitorLite.this, e.getMessage(), Toast.LENGTH_SHORT).show(); } finally { if (fileInputStream != null) { try { fileInputStream.close(); } catch (IOException e) { e.printStackTrace(); } } } } }); simpleFileDialog.chooseFile_or_Dir(); } }); btnPlay = (Button) findViewById(R.id.btnPlay); btnPlay.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { startIrBeaconPulse(); } }); btnStop = (Button) findViewById(R.id.btnStop); btnStop.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { stopIrBeaconPulse(); } }); btnPlay.setEnabled(false); btnStop.setEnabled(false); }
From source file:com.italankin.dictionary.ui.main.MainActivity.java
private void setupInputLayout() { mInputLayout.setOnClickListener(new View.OnClickListener() { @Override// w w w .j a v a 2 s . co m public void onClick(View v) { mInput.requestFocus(); mInputManager.showSoftInput(mInput, 0); } }); ViewTreeObserver vto = mInputLayout.getViewTreeObserver(); vto.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { @Override public void onGlobalLayout() { if (Build.VERSION.SDK_INT >= 16) { ViewTreeObserver vto = mInputLayout.getViewTreeObserver(); vto.removeOnGlobalLayoutListener(this); } updateInputLayoutPosition(); } }); mInput.setOnKeyListener(new View.OnKeyListener() { @Override public boolean onKey(View v, int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_ENTER && event.getAction() == KeyEvent.ACTION_DOWN) { lookupNext(mInput.getText().toString()); return true; } return false; } }); }
From source file:de.azapps.mirakel.new_ui.fragments.TaskFragment.java
private void initTaskNameEdit() { taskNameEdit.setText(task.getName()); // Show Keyboard if stub if (task.isStub()) { taskNameViewSwitcher.showNext(); taskNameEdit.selectAll();//from w ww . ja va 2 s.co m taskNameEdit.requestFocus(); toggleKeyboard(); } taskNameEdit.setOnFocusChangeListener(new View.OnFocusChangeListener() { @Override public void onFocusChange(final View v, final boolean hasFocus) { if (hasFocus) { toggleKeyboard(); } } }); taskNameEdit.setOnEditorActionListener(new TextView.OnEditorActionListener() { @Override public boolean onEditorAction(final TextView v, final int actionId, final KeyEvent event) { switch (actionId) { case EditorInfo.IME_ACTION_DONE: case EditorInfo.IME_ACTION_SEND: updateName(); return true; } return false; } }); taskNameEdit.setOnKeyListener(new View.OnKeyListener() { @Override public boolean onKey(final View v, final int keyCode, final KeyEvent event) { // If the event is a key-down event on the "enter" button if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) { updateName(); return true; } return false; } }); }
From source file:com.fvd.nimbus.BrowseActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //overridePendingTransition( R.anim.slide_in_up, R.anim.slide_out_up ); //overridePendingTransition(R.anim.carbon_slide_in,R.anim.carbon_slide_out); //overridePendingTransition(R.anim.activity_open_scale,R.anim.activity_close_translate); getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); try {/*w w w . j a v a 2s.c o m*/ requestWindowFeature(Window.FEATURE_NO_TITLE); } catch (Exception e) { e.printStackTrace(); } clipData = new DataExchange(); isInitNow = true; setContentView(R.layout.screen_browser); serverHelper.getInstance().setCallback(this, this); prefs = PreferenceManager.getDefaultSharedPreferences(this); lastUrl = prefs.getString("LAST_URL", ""); saveCSS = prefs.getString("clipStyle", "1").equals("1"); ctx = this; //adapter = new TextAdapter(this); /*Uri data = getIntent().getData(); if(data!=null){ lastUrl=data.toString(); }*/ Intent intent = getIntent(); String action = intent.getAction(); String type = intent.getType(); if (Intent.ACTION_VIEW.equals(action) /*&& type != null*/) { Uri data = intent.getData(); if (data != null) { lastUrl = data.toString(); appSettings.appendLog("browse:onCreate " + lastUrl); } } else if (Intent.ACTION_SEND.equals(action) /*&& type != null*/) { if ("text/plain".equals(type)) { String surl = intent.getStringExtra(Intent.EXTRA_TEXT); if (surl.contains(" ")) { String[] arr = surl.replace("\t", " ").split(" "); for (String s : arr) { if (s.contains("://")) { lastUrl = s.trim(); break; } } } else if (surl.contains("://")) lastUrl = surl.trim(); appSettings.appendLog("browse:onCreate " + lastUrl); } } drawer = (DrawerLayout) findViewById(R.id.root); View v = findViewById(R.id.wv); wv = (fvdWebView) findViewById(R.id.wv); wv.setEventsHandler(this); //registerForContextMenu(wv); urlField = (AutoCompleteTextView) findViewById(R.id.etAddess); urlField.setSelectAllOnFocus(true); urlField.setOnEditorActionListener(new EditText.OnEditorActionListener() { @Override public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { if (actionId == EditorInfo.IME_ACTION_DONE) { /*InputMethodManager imm = (InputMethodManager)v.getContext().getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(v.getWindowToken(), 0);*/ onNavButtonClicked(); return true; } else if (event != null && event.getKeyCode() == KeyEvent.KEYCODE_ENTER) { onNavButtonClicked(); return true; } return false; } }); onViewCreated(); handler = new Handler() { @Override public void handleMessage(Message msg) { switch (msg.what) { case 0: findViewById(R.id.bZoomStack).setVisibility(View.VISIBLE); findViewById(R.id.bToggleMenu).setVisibility(View.GONE); break; default: break; } } }; navButton = (ImageButton) findViewById(R.id.ibReloadWebPage); navButton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { //Toast.makeText(getApplicationContext(), "You made a mess", Toast.LENGTH_LONG).show(); onNavButtonClicked(); } }); findViewById(R.id.bSavePageFragment).setOnClickListener(new View.OnClickListener() { public void onClick(View v) { //toggleTools(); floatMenu.collapse(); if (!wv.getInjected()) Toast.makeText(ctx, getString(R.string.wait_load), Toast.LENGTH_LONG).show(); clipMode = 2; if (wv.getInjected()/* && !v.isSelected()*/) { wv.setCanClip(true); v.setSelected(true); Toast.makeText(ctx, ctx.getString(R.string.use_longtap), Toast.LENGTH_LONG).show(); } } }); (findViewById(R.id.bSaveFullPage)).setOnClickListener(new View.OnClickListener() { public void onClick(View v) { floatMenu.collapse(); if (wv.getInjected()) { wv.setCanClip(false); wv.saveArticle(); clipMode = 1; progressDialog = ProgressDialog.show(v.getContext(), "Nimbus Clipper", getString(R.string.please_wait), true, false); } else { Toast.makeText(ctx, getString(R.string.wait_load), Toast.LENGTH_LONG).show(); } } }); findViewById(R.id.bTakeScreenshot).setOnClickListener(new View.OnClickListener() { public void onClick(View v) { //toggleTools(); floatMenu.collapse(); findViewById(R.id.bSaveFullPage).setVisibility(View.GONE); findViewById(R.id.bSavePageFragment).setVisibility(View.GONE); findViewById(R.id.bTakeScreenshot).setVisibility(View.GONE); if (wv.getInjected()) { wv.setCanClip(false); } findViewById(R.id.bToggleMenu).setVisibility(View.GONE); /*screenCapture(); findViewById(R.id.bToggleMenu).setVisibility(View.VISIBLE);*/ findViewById(R.id.bTakeScreenshot).postDelayed(new Runnable() { @Override public void run() { // TODO Auto-generated method stub screenCapture(); findViewById(R.id.bToggleMenu).setVisibility(View.VISIBLE); finish(); } }, 10); //showDialog(DIALOG_CAPTURE); } }); (findViewById(R.id.bDone)).setOnClickListener(new View.OnClickListener() { public void onClick(View v) { { try { wv.setCanClip(false); wv.endSelectionMode(); //findViewById(R.id.bSavePageFragment).setSelected(false); clipMode = 2; wv.endSelectionMode(); String selHtml = clipData.getContent(); if (selHtml.length() > 0) { String ss = selHtml.substring(0, selHtml.indexOf(">") + 1).toLowerCase(); int j = ss.indexOf("<div"); if (j == 0) { j = ss.indexOf("style"); if (j > 0) { int k = ss.indexOf("\"", j + 11); if (k > 0) selHtml = selHtml.replace(selHtml.substring(j, k + 1), ""); } //selHtml="<DIV>"+selHtml.substring(ss.length()); } clipData.setContent(selHtml); clipData.setTitle(wv.getTitle()); /*if (true){ if(sessionId.length() == 0 || userPass.length()==0) showSettings(); else { if(prefs.getBoolean("check_fast", false)){ sendNote(wv.getTitle(), clipData.getContent(), parent, tag); clipData.setContent(""); } else { //serverHelper.getInstance().setCallback(this,this); if(appSettings.sessionId.length()>0) { serverHelper.getInstance().sendRequest("notes:getFolders", "",""); } } } wv.endSelectionMode(); } */ Intent i = new Intent(getApplicationContext(), previewActivity.class); i.putExtra("content", clipData); startActivityForResult(i, 5); //overridePendingTransition( R.anim.slide_in_up, R.anim.slide_out_up ); overridePendingTransition(R.anim.carbon_slide_in, R.anim.carbon_slide_out); } //clipData.setContent(""); } catch (Exception e) { BugReporter.Send("onEndSelection", e.getMessage()); } } //showDialog(DIALOG_CAPTURE); } }); findViewById(R.id.bZoomIn).setOnClickListener(new View.OnClickListener() { public void onClick(View v) { wv.ZoomInSelection(); } }); findViewById(R.id.bZoomOut).setOnClickListener(new View.OnClickListener() { public void onClick(View v) { wv.ZoomOutSelection(); } }); setNavButtonState(NavButtonState.NBS_GO); progressBar = (ProgressBar) findViewById(R.id.progressbar); //CookieSyncManager.createInstance(this); //webSettings.setLoadsImagesAutomatically(imgOn); userMail = prefs.getString("userMail", ""); userPass = prefs.getString("userPass", ""); sessionId = prefs.getString("sessionId", ""); appSettings.sessionId = sessionId; appSettings.userMail = userMail; appSettings.userPass = userPass; if ("1".equals(prefs.getString("userAgent", "1"))) { wv.setUserAgent(null); } else wv.setUserAgent(deskAgent); final Activity activity = this; //lastUrl="file:///android_asset/android.html"; if (lastUrl.length() > 0) { //wv.navigate(lastUrl); //if(!urlField.getText().toString().equals(wv.getUrl())) urlField.setText(lastUrl); openURL(); } isInitNow = false; urlField.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View v, int position, long id) { // TODO Auto-generated method stub /*String item = (String)parent.getItemAtPosition(position); Toast.makeText( getApplicationContext(), " " + item, Toast.LENGTH_SHORT).show();*/ openURL(); } }); urlField.addTextChangedListener(this); parent = prefs.getString("remFolderId", "default"); /*ListView listView = (ListView) findViewById(R.id.left_drawer); listView.setAdapter(new DrawerMenuAdapter(this,getResources().getStringArray(R.array.lmenu_browser))); listView.setOnItemClickListener(this);*/ }
From source file:org.tigase.mobile.muc.MucRoomFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { this.view = inflater.inflate(R.layout.muc_conversation, container, false); this.stateImage = (ImageView) view.findViewById(R.id.user_presence); this.progressBar = (ProgressBar) view.findViewById(R.id.progressBar1); this.ed = (EditText) view.findViewById(R.id.chat_message_entry); this.ed.setOnKeyListener(new OnKeyListener() { @Override/*from www . ja v a 2 s .c o m*/ public boolean onKey(View v, int keyCode, KeyEvent event) { boolean ets = prefs.getBoolean(Preferences.ENTER_TO_SEND_KEY, true); if (ets && keyCode == KeyEvent.KEYCODE_ENTER) { sendMessage(); return true; } return false; } }); this.ed.setOnFocusChangeListener(new OnFocusChangeListener() { @Override public void onFocusChange(View v, boolean hasFocus) { if (!hasFocus) cancelEdit(); } }); this.sendButton = (Button) view.findViewById(R.id.chat_send_button); sendButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if (DEBUG) Log.i(TAG, "Klikniete"); sendMessage(); } }); this.lv = (ListView) view.findViewById(R.id.chat_conversation_history); lv.post(new Runnable() { @Override public void run() { lv.setSelection(Integer.MAX_VALUE); } }); return view; }
From source file:dev.memento.MementoBrowser.java
/** Called when the activity is first created. */ @Override/*w w w .j ava 2 s . co m*/ public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.main); mUserAgent = getApplicationContext().getText(R.string.user_agent).toString(); // Set the date and time format SimpleDateTime.mDateFormat = android.text.format.DateFormat.getDateFormat(getApplicationContext()); SimpleDateTime.mTimeFormat = android.text.format.DateFormat.getTimeFormat(getApplicationContext()); mDateChosenButton = (Button) findViewById(R.id.dateChosen); mDateDisplayedView = (TextView) findViewById(R.id.dateDisplayed); // Launch the DatePicker dialog box mDateChosenButton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { showDialog(DIALOG_DATE); } }); // Set the current date mToday = new SimpleDateTime(); // Handle change in orientation gracefully if (savedInstanceState == null) { mCurrentUrl = getApplicationContext().getText(R.string.homepage).toString(); mOriginalUrl = mCurrentUrl; setChosenDate(mToday); setDisplayedDate(mToday); mMementos = new MementoList(); } else { mCurrentUrl = savedInstanceState.getString("mCurrentUrl"); mDateChosen = (SimpleDateTime) savedInstanceState.getSerializable("mDateChosen"); mDateDisplayed = (SimpleDateTime) savedInstanceState.getSerializable("mDateDisplayed"); setChosenDate(mDateChosen); setDisplayedDate(mDateDisplayed); } mTimegateUris = getResources().getStringArray(R.array.listTimegates); // Add some favicons of web archives used by proxy server mFavicons = new HashMap<String, Bitmap>(); mFavicons.put("ia", BitmapFactory.decodeResource(getResources(), R.drawable.ia_favicon)); mFavicons.put("webcite", BitmapFactory.decodeResource(getResources(), R.drawable.webcite_favicon)); mFavicons.put("national-archives", BitmapFactory.decodeResource(getResources(), R.drawable.national_archives_favicon)); mProgressBar = (ProgressBar) findViewById(R.id.progressBar); mProgressBar.setVisibility(View.GONE); mLocation = (TextView) findViewById(R.id.locationEditText); mLocation.setSelectAllOnFocus(true); mLocation.setOnFocusChangeListener(new OnFocusChangeListener() { @Override public void onFocusChange(View v, boolean hasFocus) { // Replace title with URL when focus is lost if (hasFocus) mLocation.setText(mCurrentUrl); else if (mPageTitle.length() > 0) mLocation.setText(mPageTitle); } }); mLocation.setOnKeyListener(new OnKeyListener() { @Override public boolean onKey(View v, int keyCode, KeyEvent event) { //Log.d(LOG_TAG, "keyCode = " + keyCode + " event = " + event.getAction()); // Go to URL if user presses Go button if (event.getAction() == KeyEvent.ACTION_DOWN && keyCode == KeyEvent.KEYCODE_ENTER) { mOriginalUrl = fixUrl(mLocation.getText().toString()); // Access live version if date is today or in the future if (mToday.compareTo(mDateChosen) <= 0) { Log.d(LOG_TAG, "Browsing to " + mOriginalUrl); mWebview.loadUrl(mOriginalUrl); // Clear since we are visiting a different page in the present mMementos.clear(); } else makeMementoRequests(); // Hide the virtual keyboard ((InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE)) .hideSoftInputFromWindow(mLocation.getWindowToken(), 0); return true; } return false; } }); // TEST /* Context context = getBaseContext(); Drawable image = getImage(context, "http://web.archive.org/favicon.ico"); if (image == null) { System.out.println("image is null !!"); } else { //image.setBounds(5, 5, 5, 5); //ImageView imgView = new ImageView(context); //ImageView imgView = (ImageView)findViewById(R.id.imagetest); //imgView.setImageDrawable(image); mLocation.setCompoundDrawablesWithIntrinsicBounds(image, null, null, null); } */ mNextButton = (Button) findViewById(R.id.next); mNextButton.setEnabled(false); mNextButton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { // Advance to next Memento // This could happen if the index has not been set yet if (mMementos.getCurrentIndex() < 0) { int index = mMementos.getIndex(mDateDisplayed); if (index < 0) { Log.d(LOG_TAG, "Could not find next Memento after date " + mDateDisplayed); return; } else mMementos.setCurrentIndex(index); } // Locate the next Memento in the list Memento nextMemento = mMementos.getNext(); if (nextMemento == null) { Log.d(LOG_TAG, "Still could not find next Memento!"); Log.d(LOG_TAG, "Current index is " + mMementos.getCurrentIndex()); } else { SimpleDateTime date = nextMemento.getDateTime(); setChosenDate(nextMemento.getDateTime()); showToast("Time travelling to next Memento on " + mDateChosen.dateFormatted()); mDateDisplayed = date; String redirectUrl = nextMemento.getUrl(); Log.d(LOG_TAG, "Sending browser to " + redirectUrl); mWebview.loadUrl(redirectUrl); // Just in case it wasn't already enabled mPreviousButton.setEnabled(true); // If this is the last memento, disable button if (mMementos.isLast(date)) mNextButton.setEnabled(false); } } }); mPreviousButton = (Button) findViewById(R.id.previous); mPreviousButton.setEnabled(false); mPreviousButton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { // Advance to previous Memento // This could happen if the index has not been set yet if (mMementos.getCurrentIndex() < 0) { int index = mMementos.getIndex(mDateDisplayed); if (index < 0) { Log.d(LOG_TAG, "Could not find previous Memento before date " + mDateDisplayed); return; } else mMementos.setCurrentIndex(index); } // Locate the prev Memento in the list Memento prevMemento = mMementos.getPrevious(); if (prevMemento == null) { Log.d(LOG_TAG, "Still could not find previous Memento!"); Log.d(LOG_TAG, "Current index is " + mMementos.getCurrentIndex()); } else { SimpleDateTime date = prevMemento.getDateTime(); setChosenDate(date); showToast("Time travelling to previous Memento on " + mDateChosen.dateFormatted()); mDateDisplayed = date; String redirectUrl = prevMemento.getUrl(); Log.d(LOG_TAG, "Sending browser to " + redirectUrl); mWebview.loadUrl(redirectUrl); // Just in case it wasn't already enabled mNextButton.setEnabled(true); // If this is the first memento, disable button if (mMementos.isFirst(date)) mPreviousButton.setEnabled(false); } } }); mWebview = (WebView) findViewById(R.id.webview); mWebview.setWebViewClient(new MementoWebViewClient()); mWebview.setWebChromeClient(new MementoWebChromClient()); mWebview.getSettings().setJavaScriptEnabled(true); mWebview.loadUrl(mCurrentUrl); mWebview.setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { // Set focus here so focus is removed from the location text field // which will change the URL into the page's title. // There really should be a better way to do this, but it's a general // problem that other developers have ran into as well: // http://groups.google.com/group/android-developers/browse_thread/thread/9d1681a01f05e782?pli=1 if (mLocation.hasFocus()) { mWebview.requestFocus(); return true; } // Hide the virtual keyboard ((InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE)) .hideSoftInputFromWindow(mLocation.getWindowToken(), 0); return false; } }); //testMementos(); }