Example #1
0
 public boolean logOffline(final IAbstractActivity fromActivity, final LogType logType) {
   String log = "";
   if (StringUtils.isNotBlank(Settings.getSignature()) && Settings.isAutoInsertSignature()) {
     log = LogTemplateProvider.applyTemplates(Settings.getSignature(), true);
   }
   logOffline(fromActivity, log, Calendar.getInstance(), logType);
   return true;
 }
  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
    final int id = item.getItemId();

    if (id == MENU_SIGNATURE) {
      insertIntoLog(LogTemplateProvider.applyTemplates(Settings.getSignature(), false), true);
      return true;
    } else if (id >= 10 && id <= 19) {
      rating = (id - 9) / 2.0;
      if (rating < 1) {
        rating = 0;
      }
      updatePostButtonText();
      return true;
    }
    final LogTemplate template = LogTemplateProvider.getTemplate(id);
    if (template != null) {
      final String newText = template.getValue(false);
      insertIntoLog(newText, true);
      return true;
    }
    return false;
  }
Example #3
0
 private void loadLogFromDatabase() {
   final LogEntry log = DataStore.loadLogOffline(geocode);
   if (log != null) {
     typeSelected = log.getType();
     date.setTime(new Date(log.date));
     text = log.log;
   } else if (StringUtils.isNotBlank(Settings.getSignature())
       && Settings.isAutoInsertSignature()
       && StringUtils.isBlank(currentLogText())) {
     insertIntoLog(
         LogTemplateProvider.applyTemplates(Settings.getSignature(), new LogContext(cache, null)),
         false);
   }
 }
  @Override
  public boolean onCreateOptionsMenu(final Menu menu) {
    getMenuInflater().inflate(R.menu.abstract_logging_activity, menu);

    final SubMenu menuLog = menu.findItem(R.id.menu_templates).getSubMenu();
    for (final LogTemplate template : LogTemplateProvider.getTemplatesWithSignature()) {
      menuLog.add(0, template.getItemId(), 0, template.getResourceId());
    }

    final SubMenu menuSmilies = menu.findItem(R.id.menu_smilies).getSubMenu();
    for (final Smiley smiley : GCSmiliesProvider.getSmilies()) {
      menuSmilies.add(0, smiley.getItemId(), 0, smiley.text);
    }

    return true;
  }
  @Override
  public boolean onOptionsItemSelected(final MenuItem item) {
    final int id = item.getItemId();
    if (id == R.id.menu_repeat_last) {
      replaceLog(getLastLog());
      return true;
    }

    final LogTemplate template = LogTemplateProvider.getTemplate(id);
    if (template != null) {
      insertIntoLog(template.getValue(getLogContext()), true);
      return true;
    }

    final Smiley smiley = GCSmiliesProvider.getSmiley(id);
    if (smiley != null) {
      insertIntoLog("[" + smiley.text + "]", true);
      return true;
    }

    return super.onOptionsItemSelected(item);
  }
  public void init() {
    if (geocode != null) {
      app.setAction(geocode);
    }
    postButton = (Button) findViewById(R.id.post);
    tweetBox = (LinearLayout) findViewById(R.id.tweet_box);
    tweetCheck = (CheckBox) findViewById(R.id.tweet);
    clearButton = (Button) findViewById(R.id.clear);
    saveButton = (Button) findViewById(R.id.save);

    possibleLogTypes = cache.getPossibleLogTypes();

    final cgLog log = app.loadLogOffline(geocode);
    if (log != null) {
      typeSelected = log.type;
      date.setTime(new Date(log.date));
      text = log.log;
      updatePostButtonText();
    } else if (StringUtils.isNotBlank(Settings.getSignature())
        && Settings.isAutoInsertSignature()
        && StringUtils.isBlank(((EditText) findViewById(R.id.log)).getText())) {
      insertIntoLog(LogTemplateProvider.applyTemplates(Settings.getSignature(), false), false);
    }

    if (!possibleLogTypes.contains(typeSelected)) {
      if (alreadyFound) {
        typeSelected = LogType.LOG_NOTE;
      } else {
        typeSelected = possibleLogTypes.get(0);
      }
      setType(typeSelected);
    }

    final Button typeButton = (Button) findViewById(R.id.type);
    registerForContextMenu(typeButton);
    typeButton.setText(typeSelected.getL10n());
    typeButton.setOnClickListener(
        new View.OnClickListener() {

          public void onClick(View view) {
            openContextMenu(view);
          }
        });

    final Button dateButton = (Button) findViewById(R.id.date);
    dateButton.setText(cgBase.formatShortDate(date.getTime().getTime()));
    dateButton.setOnClickListener(new DateListener());

    final EditText logView = (EditText) findViewById(R.id.log);
    if (StringUtils.isBlank(logView.getText()) && StringUtils.isNotBlank(text)) {
      logView.setText(text);
    }

    tweetCheck.setChecked(true);

    final ActivityState lastState = (ActivityState) getLastNonConfigurationInstance();
    if (lastState != null) {
      lastState.restore(this);
    }

    if (cgBase.isEmpty(viewstates)) {
      enablePostButton(false);
      new LoadDataThread().start();
    } else {
      enablePostButton(true);
    }

    saveButton.setOnClickListener(
        new View.OnClickListener() {

          @Override
          public void onClick(View v) {
            saveLog(true);
          }
        });

    clearButton.setOnClickListener(new ClearListener());
  }
  @Override
  public boolean onCreateOptionsMenu(Menu menu) {
    SubMenu menuLog = null;

    menuLog =
        menu.addSubMenu(0, 0, 0, res.getString(R.string.log_add))
            .setIcon(android.R.drawable.ic_menu_add);
    for (LogTemplate template : LogTemplateProvider.getTemplates()) {
      menuLog.add(0, template.getItemId(), 0, template.getResourceId());
    }
    menuLog.add(0, MENU_SIGNATURE, 0, res.getString(R.string.init_signature));

    final SubMenu menuStars =
        menu.addSubMenu(0, SUBMENU_VOTE, 0, res.getString(R.string.log_rating))
            .setIcon(android.R.drawable.ic_menu_sort_by_size);
    menuStars.add(0, 10, 0, res.getString(R.string.log_no_rating));
    menuStars.add(
        0,
        19,
        0,
        res.getString(R.string.log_stars_5)
            + " ("
            + res.getString(R.string.log_stars_5_description)
            + ")");
    menuStars.add(
        0,
        18,
        0,
        res.getString(R.string.log_stars_45)
            + " ("
            + res.getString(R.string.log_stars_45_description)
            + ")");
    menuStars.add(
        0,
        17,
        0,
        res.getString(R.string.log_stars_4)
            + " ("
            + res.getString(R.string.log_stars_4_description)
            + ")");
    menuStars.add(
        0,
        16,
        0,
        res.getString(R.string.log_stars_35)
            + " ("
            + res.getString(R.string.log_stars_35_description)
            + ")");
    menuStars.add(
        0,
        15,
        0,
        res.getString(R.string.log_stars_3)
            + " ("
            + res.getString(R.string.log_stars_3_description)
            + ")");
    menuStars.add(
        0,
        14,
        0,
        res.getString(R.string.log_stars_25)
            + " ("
            + res.getString(R.string.log_stars_25_description)
            + ")");
    menuStars.add(
        0,
        13,
        0,
        res.getString(R.string.log_stars_2)
            + " ("
            + res.getString(R.string.log_stars_2_description)
            + ")");
    menuStars.add(
        0,
        12,
        0,
        res.getString(R.string.log_stars_15)
            + " ("
            + res.getString(R.string.log_stars_15_description)
            + ")");
    menuStars.add(
        0,
        11,
        0,
        res.getString(R.string.log_stars_1)
            + " ("
            + res.getString(R.string.log_stars_1_description)
            + ")");

    return true;
  }
Example #8
0
  @Override
  public void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState, R.layout.logcache_activity);

    // Get parameters from intent and basic cache information from database
    final Bundle extras = getIntent().getExtras();
    if (extras != null) {
      cacheid = extras.getString(EXTRAS_ID);
      geocode = extras.getString(EXTRAS_GEOCODE);
    }

    if ((StringUtils.isBlank(cacheid)) && StringUtils.isNotBlank(geocode)) {
      cacheid = cgData.getCacheidForGeocode(geocode);
    }
    if (StringUtils.isBlank(geocode) && StringUtils.isNotBlank(cacheid)) {
      geocode = cgData.getGeocodeForGuid(cacheid);
    }

    cache = cgData.loadCache(geocode, LoadFlags.LOAD_CACHE_OR_DB);
    possibleLogTypes = cache.getPossibleLogTypes();

    if (StringUtils.isNotBlank(cache.getName())) {
      setTitle(res.getString(R.string.log_new_log) + ": " + cache.getName());
    } else {
      setTitle(res.getString(R.string.log_new_log) + ": " + cache.getGeocode());
    }

    // Get ids for later use
    postButton = (Button) findViewById(R.id.post);
    tweetBox = (LinearLayout) findViewById(R.id.tweet_box);
    tweetCheck = (CheckBox) findViewById(R.id.tweet);
    logPasswordBox = (LinearLayout) findViewById(R.id.log_password_box);

    // initialize with default values
    setDefaultValues();

    // Restore previous state
    if (savedInstanceState != null) {
      rating = savedInstanceState.getDouble(SAVED_STATE_RATING);
      typeSelected = LogType.getById(savedInstanceState.getInt(SAVED_STATE_TYPE));
      date.setTimeInMillis(savedInstanceState.getLong(SAVED_STATE_DATE));
      imageCaption = savedInstanceState.getString(SAVED_STATE_IMAGE_CAPTION);
      imageDescription = savedInstanceState.getString(SAVED_STATE_IMAGE_DESCRIPTION);
      imageUri = Uri.parse(savedInstanceState.getString(SAVED_STATE_IMAGE_URI));
    } else {
      // If log had been previously saved, load it now, otherwise initialize signature as needed
      final LogEntry log = cgData.loadLogOffline(geocode);
      if (log != null) {
        typeSelected = log.type;
        date.setTime(new Date(log.date));
        text = log.log;
      } else if (StringUtils.isNotBlank(Settings.getSignature())
          && Settings.isAutoInsertSignature()
          && StringUtils.isBlank(currentLogText())) {
        insertIntoLog(
            LogTemplateProvider.applyTemplates(Settings.getSignature(), new LogContext(cache)),
            false);
      }
    }
    updatePostButtonText();
    updateImageButton();
    enablePostButton(false);

    final Button typeButton = (Button) findViewById(R.id.type);
    typeButton.setText(typeSelected.getL10n());
    typeButton.setOnClickListener(
        new View.OnClickListener() {

          @Override
          public void onClick(View view) {
            selectLogType();
          }
        });

    final Button dateButton = (Button) findViewById(R.id.date);
    setDate(date);
    dateButton.setOnClickListener(new DateListener());

    final EditText logView = (EditText) findViewById(R.id.log);
    if (StringUtils.isBlank(currentLogText()) && StringUtils.isNotBlank(text)) {
      logView.setText(text);
    }

    tweetCheck.setChecked(true);
    updateTweetBox(typeSelected);
    updateLogPasswordBox(typeSelected);

    final Button imageButton = (Button) findViewById(R.id.image_btn);
    imageButton.setOnClickListener(
        new View.OnClickListener() {

          @Override
          public void onClick(View view) {
            selectImage();
          }
        });

    final Button saveButton = (Button) findViewById(R.id.save);
    saveButton.setOnClickListener(
        new View.OnClickListener() {

          @Override
          public void onClick(View v) {
            saveLog(true);
          }
        });

    final Button clearButton = (Button) findViewById(R.id.clear);
    clearButton.setOnClickListener(
        new View.OnClickListener() {

          @Override
          public void onClick(View v) {
            clearLog();
          }
        });

    loggingManager = cache.getLoggingManager(this);

    loggingManager.init();
  }