Ejemplo n.º 1
0
  private void showNote(boolean xml) {

    if (xml) {
      content.setText(note.getXmlContent());
      title.setText((CharSequence) note.getTitle());
      this.setTitle(this.getTitle() + " - XML");
      return;
    }

    LinkInternalSpan[] links =
        noteContent.getSpans(0, noteContent.length(), LinkInternalSpan.class);
    MatchFilter noteLinkMatchFilter = LinkInternalSpan.getNoteLinkMatchFilter(noteContent, links);

    // show the note (spannable makes the TextView able to output styled text)
    content.setText(noteContent, TextView.BufferType.SPANNABLE);

    // add links to stuff that is understood by Android except phone numbers because it's too
    // aggressive
    // TODO this is SLOWWWW!!!!

    int linkFlags = 0;

    if (Preferences.getBoolean(Preferences.Key.LINK_EMAILS)) linkFlags |= Linkify.EMAIL_ADDRESSES;
    if (Preferences.getBoolean(Preferences.Key.LINK_URLS)) linkFlags |= Linkify.WEB_URLS;
    if (Preferences.getBoolean(Preferences.Key.LINK_ADDRESSES)) linkFlags |= Linkify.MAP_ADDRESSES;

    Linkify.addLinks(content, linkFlags);

    // Custom phone number linkifier (fixes lp:512204)
    if (Preferences.getBoolean(Preferences.Key.LINK_PHONES))
      Linkify.addLinks(
          content,
          LinkifyPhone.PHONE_PATTERN,
          "tel:",
          LinkifyPhone.sPhoneNumberMatchFilter,
          Linkify.sPhoneNumberTransformFilter);

    // This will create a link every time a note title is found in the text.
    // The pattern contains a very dumb (title1)|(title2) escaped correctly
    // Then we transform the url from the note name to the note id to avoid characters that mess up
    // with the URI (ex: ?)
    if (Preferences.getBoolean(Preferences.Key.LINK_TITLES)) {
      Pattern pattern = NoteManager.buildNoteLinkifyPattern(this, note.getTitle());

      if (pattern != null) {
        Linkify.addLinks(
            content,
            pattern,
            Tomdroid.CONTENT_URI + "/",
            noteLinkMatchFilter,
            noteTitleTransformFilter);

        // content.setMovementMethod(LinkMovementMethod.getInstance());
      }
    }
    title.setText((CharSequence) note.getTitle());
  }
Ejemplo n.º 2
0
  private void updateTextAttributes() {
    float baseSize = Float.parseFloat(Preferences.getString(Preferences.Key.BASE_TEXT_SIZE));
    content.setTextSize(baseSize);
    title.setTextSize(baseSize * 1.3f);

    title.setTextColor(Color.BLUE);
    title.setPaintFlags(title.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG);
    title.setBackgroundColor(0xffffffff);

    content.setBackgroundColor(0xffffffff);
    content.setTextColor(Color.DKGRAY);
  }
Ejemplo n.º 3
0
  @SuppressWarnings("deprecation")
  private void startSyncing(boolean push) {

    String serverUri = Preferences.getString(Preferences.Key.SYNC_SERVER);
    SyncService currentService = SyncManager.getInstance().getCurrentService();

    if (currentService.needsAuth()) {

      // service needs authentication
      TLog.i(TAG, "Creating dialog");

      showDialog(DIALOG_AUTH_PROGRESS);

      Handler handler =
          new Handler() {

            @Override
            public void handleMessage(Message msg) {

              Uri authorizationUri = (Uri) msg.obj;
              if (authorizationUri != null) {

                resetSyncValues();

                Intent i = new Intent(Intent.ACTION_VIEW, authorizationUri);
                startActivity(i);

              } else {
                // Auth failed, don't update the value
                showDialog(DIALOG_CONNECT_FAILED);
              }

              if (authProgressDialog != null) authProgressDialog.dismiss();
            }
          };

      ((ServiceAuth) currentService).getAuthUri(serverUri, handler);
    } else {
      syncProcessedNotes = 0;
      syncTotalNotes = 0;
      dialogString = getString(R.string.syncing_connect);
      showDialog(DIALOG_SYNC);
      SyncManager.getInstance().startSynchronization(push); // push by default
    }
  }
Ejemplo n.º 4
0
  /** Called when the activity is created. */
  @SuppressLint("NewApi")
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    Preferences.init(this, CLEAR_PREFERENCES);
    context = this;
    SyncManager.setActivity(this);
    SyncManager.setHandler(this.syncMessageHandler);

    main = View.inflate(this, R.layout.main, null);

    setContentView(main);

    // get the Path to the notes-folder from Preferences
    if (Preferences.getString(Preferences.Key.SD_LOCATION).startsWith("/")) {
      NOTES_PATH = Preferences.getString(Preferences.Key.SD_LOCATION);
    } else {
      NOTES_PATH =
          Environment.getExternalStorageDirectory()
              + "/"
              + Preferences.getString(Preferences.Key.SD_LOCATION)
              + "/";
    }

    // generate the http header we want to send on syncing
    getPackageManager();
    try {
      PackageInfo pi =
          getPackageManager().getPackageInfo(getPackageName(), PackageManager.GET_META_DATA);
      HTTP_HEADER =
          String.format(
              "%1$s v%2$s, build %3$s, Android v%4$s, %5$s/%6$s",
              pi.packageName,
              pi.versionName,
              pi.versionCode,
              Build.VERSION.RELEASE,
              Build.MANUFACTURER,
              Build.MODEL);
    } catch (NameNotFoundException e) {
      e.printStackTrace();
      HTTP_HEADER = "Tomdroid vunknown, build unknown, Android unknown, unknown/unknown";
    }
    TLog.v(TAG, "Generated http-header: {0}: {1}", "X-Tomboy-Client", Tomdroid.HTTP_HEADER);

    // did we already show the warning and got destroyed by android's activity killer?
    if (Preferences.getBoolean(Preferences.Key.FIRST_RUN)) {
      TLog.i(TAG, "Tomdroid is first run.");

      // add a first explanatory note
      NoteManager.putNote(this, FirstNote.createFirstNote(this));

      // Warn that this is a "will eat your babies" release
      showDialog(DIALOG_FIRST_RUN);
    }

    this.intent = getIntent();

    if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
      this.setTitle(getString(R.string.app_name) + " - " + getString(R.string.SearchResultTitle));
      query = intent.getStringExtra(SearchManager.QUERY);

      // adds query to search history suggestions
      SearchRecentSuggestions suggestions =
          new SearchRecentSuggestions(
              this, SearchSuggestionProvider.AUTHORITY, SearchSuggestionProvider.MODE);
      suggestions.saveRecentQuery(query, null);
    } else {
      // if main view -> disable the tomdroid icon home button
      setHomeButtonEnabled(false);
    }

    String defaultSortOrder = Preferences.getString(Preferences.Key.SORT_ORDER);
    NoteManager.setSortOrder(defaultSortOrder);

    // set list adapter
    updateNotesList(query, -1);

    // add note to pane for tablet
    rightPane = (LinearLayout) findViewById(R.id.right_pane);
    registerForContextMenu(findViewById(android.R.id.list));

    // check if receiving note
    if (getIntent().hasExtra("view_note")) {
      uri = getIntent().getData();
      getIntent().setData(null);
      Intent i = new Intent(Intent.ACTION_VIEW, uri, this, ViewNote.class);
      startActivity(i);
    }

    if (rightPane != null) {
      content = (TextView) findViewById(R.id.content);
      title = (TextView) findViewById(R.id.title);

      // this we will call on resume as well.
      updateTextAttributes();
      showNoteInPane(0);
    }

    // set the view shown when the list is empty
    updateEmptyList(query);

    // Syncing if SyncOnStart (pref) set AND onCreate_SyncOnStart set false for syncing only on
    // startup
    if (Preferences.getBoolean(Preferences.Key.SYNC_ON_START) && first_onCreate_run) {
      startSyncing(true);
      TLog.i(TAG, "SyncOnStart activated");
    }

    // we already run onCreate now!
    first_onCreate_run = false;
  }
Ejemplo n.º 5
0
 private void resetSyncValues() {
   Preferences.putLong(
       Preferences.Key.LATEST_SYNC_REVISION,
       (Long) Preferences.Key.LATEST_SYNC_REVISION.getDefault());
   Preferences.putString(Preferences.Key.LATEST_SYNC_DATE, new Time().formatTomboy());
 }