public static void testApplyTemplates() { final String noTemplates = " no templates "; assertEquals( noTemplates, LogTemplateProvider.applyTemplates(noTemplates, new LogContext(null, null, true))); // This test can occasionally fail if the current year changes right after the next line. final String currentYear = Integer.toString(Calendar.YEAR); assertTrue( LogTemplateProvider.applyTemplates("[DATE]", new LogContext(null, null, true)) .contains(currentYear)); }
@Override public boolean onOptionsItemSelected(MenuItem item) { int id = item.getItemId(); if (id == MENU_SIGNATURE) { EditText log = (EditText) findViewById(R.id.log); String content = log.getText().toString(); if (content.length() > 0) { insertIntoLog("\n"); } insertIntoLog(LogTemplateProvider.applyTemplates(settings.getSignature(), base)); return true; } else if (id >= 10 && id <= 19) { rating = (id - 9) / 2.0; if (post == null) { post = (Button) findViewById(R.id.post); } if (rating == 0.0) { post.setText(res.getString(R.string.log_post_no_rate)); } else { post.setText(res.getString(R.string.log_post_rate) + " " + ratingTextValue(rating) + "*"); } return true; } LogTemplate template = LogTemplateProvider.getTemplate(id); if (template != null) { String newText = template.getValue(base); insertIntoLog(newText); return true; } return false; }
public void init() { if (geocode != null) { app.setAction(geocode); } types.clear(); if (cache.type.equals("event") || cache.type.equals("mega") || cache.type.equals("cito") || cache.type.equals("lostfound")) { types.add(cgBase.LOG_WILL_ATTEND); types.add(cgBase.LOG_NOTE); types.add(cgBase.LOG_ATTENDED); types.add(cgBase.LOG_NEEDS_ARCHIVE); } else if (cache.type.equals("earth")) { types.add(cgBase.LOG_FOUND_IT); types.add(cgBase.LOG_DIDNT_FIND_IT); types.add(cgBase.LOG_NOTE); types.add(cgBase.LOG_NEEDS_MAINTENANCE); types.add(cgBase.LOG_NEEDS_ARCHIVE); } else if (cache.type.equals("webcam")) { types.add(cgBase.LOG_WEBCAM_PHOTO_TAKEN); types.add(cgBase.LOG_DIDNT_FIND_IT); types.add(cgBase.LOG_NOTE); types.add(cgBase.LOG_NEEDS_ARCHIVE); types.add(cgBase.LOG_NEEDS_MAINTENANCE); } else { types.add(cgBase.LOG_FOUND_IT); types.add(cgBase.LOG_DIDNT_FIND_IT); types.add(cgBase.LOG_NOTE); types.add(cgBase.LOG_NEEDS_ARCHIVE); types.add(cgBase.LOG_NEEDS_MAINTENANCE); } if (cache.owner.equalsIgnoreCase(settings.getUsername())) { types.add(cgBase.LOG_OWNER_MAINTENANCE); types.add(cgBase.LOG_TEMP_DISABLE_LISTING); types.add(cgBase.LOG_ENABLE_LISTING); types.add(cgBase.LOG_ARCHIVE); types.remove(Integer.valueOf(cgBase.LOG_UPDATE_COORDINATES)); if (cache.type.equals("event") || cache.type.equals("mega") || cache.type.equals("cito") || cache.type.equals("lostfound")) { types.add(cgBase.LOG_ANNOUNCEMENT); } } final cgLog log = app.loadLogOffline(geocode); if (log != null) { typeSelected = log.type; date.setTime(new Date(log.date)); text = log.log; if (typeSelected == cgBase.LOG_FOUND_IT && settings.isGCvoteLogin()) { if (post == null) { post = (Button) findViewById(R.id.post); } post.setText(res.getString(R.string.log_post_no_rate)); } } else if (settings.getSignature() != null && settings.signatureAutoinsert && settings.getSignature().length() > 0 && 0 == ((EditText) findViewById(R.id.log)).getText().length()) { insertIntoLog(LogTemplateProvider.applyTemplates(settings.getSignature(), base)); } if (types.contains(typeSelected) == false) { if (alreadyFound) { typeSelected = cgBase.LOG_NOTE; } else { typeSelected = types.get(0); } setType(typeSelected); } Button typeButton = (Button) findViewById(R.id.type); registerForContextMenu(typeButton); typeButton.setText(cgBase.logTypes2.get(typeSelected)); typeButton.setOnClickListener( new View.OnClickListener() { public void onClick(View view) { openContextMenu(view); } }); Button dateButton = (Button) findViewById(R.id.date); dateButton.setText(base.formatShortDate(date.getTime().getTime())); dateButton.setOnClickListener(new cgeovisitDateListener()); EditText logView = (EditText) findViewById(R.id.log); if (logView.getText().length() == 0 && text != null && text.length() > 0) { logView.setText(text); } if (tweetBox == null) { tweetBox = (LinearLayout) findViewById(R.id.tweet_box); } if (tweetCheck == null) { tweetCheck = (CheckBox) findViewById(R.id.tweet); } tweetCheck.setChecked(true); if (post == null) { post = (Button) findViewById(R.id.post); } if (viewstate == null || viewstate.length() == 0) { post.setEnabled(false); post.setOnTouchListener(null); post.setOnClickListener(null); loadData thread; thread = new loadData(cacheid); thread.start(); } else { post.setEnabled(true); post.setOnClickListener(new postListener()); } if (save == null) { save = (Button) findViewById(R.id.save); } save.setOnClickListener(new saveListener()); if (clear == null) { clear = (Button) findViewById(R.id.clear); } clear.setOnClickListener(new clearListener()); }