コード例 #1
0
ファイル: ActivityMain.java プロジェクト: JCulver/NotePad-2
 /**
  * Returns a list id from an intent if it contains one, either as part of its URI or as an extra
  *
  * <p>Returns -1 if no id was contained, this includes insert actions
  */
 long getListId(final Intent intent) {
   long retval = -1;
   if (intent != null
       && intent.getData() != null
       && (Intent.ACTION_EDIT.equals(intent.getAction())
           || Intent.ACTION_VIEW.equals(intent.getAction())
           || Intent.ACTION_INSERT.equals(intent.getAction()))) {
     if ((intent.getData().getPath().startsWith(NotePad.Lists.PATH_VISIBLE_LISTS)
         || intent.getData().getPath().startsWith(NotePad.Lists.PATH_LISTS)
         || intent.getData().getPath().startsWith(TaskList.URI.getPath()))) {
       try {
         retval = Long.parseLong(intent.getData().getLastPathSegment());
       } catch (NumberFormatException e) {
         retval = -1;
       }
     } else if (-1 != intent.getLongExtra(LegacyDBHelper.NotePad.Notes.COLUMN_NAME_LIST, -1)) {
       retval = intent.getLongExtra(LegacyDBHelper.NotePad.Notes.COLUMN_NAME_LIST, -1);
     } else if (-1 != intent.getLongExtra(TaskDetailFragment.ARG_ITEM_LIST_ID, -1)) {
       retval = intent.getLongExtra(TaskDetailFragment.ARG_ITEM_LIST_ID, -1);
     } else if (-1 != intent.getLongExtra(Task.Columns.DBLIST, -1)) {
       retval = intent.getLongExtra(Task.Columns.DBLIST, -1);
     }
   }
   return retval;
 }
コード例 #2
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    final Intent intent = getIntent();

    // Do some setup based on the action being performed.
    final String action = intent.getAction();
    if (Intent.ACTION_EDIT.equals(action)) {
      mState = STATE_EDIT;
      // mUri = intent.getData();
    } else if (Intent.ACTION_INSERT.equals(action)) {
      mState = STATE_INSERT;

    } else {
      // Whoops, unknown action! Bail.
      Log.e(TAG, "Unknown action, exiting");
      finish();
      return;
    }

    // Set the layout for this activity. You can find it in
    // res/layout/note_editor.xml
    setContentView(R.layout.note_editor);

    // The text view for our note, identified by its ID in the XML file.
    mText = (EditText) findViewById(R.id.note);

    // If an instance of this activity had previously stopped, we can
    // get the original text it started with.
    if (savedInstanceState != null) {
      mOriginalContent = savedInstanceState.getString(ORIGINAL_CONTENT);
    }
  }
コード例 #3
0
ファイル: NoteEdit.java プロジェクト: patenst/banderlabs
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    if (savedInstanceState != null) {
      final Object note = savedInstanceState.get(ORIGINAL_NOTE);
      if (note != null) mOriginalNote = (Note) note;
    }

    final Intent intent = getIntent();
    final String action = intent.getAction();
    if (Intent.ACTION_VIEW.equals(action) || Intent.ACTION_EDIT.equals(action)) {
      mState = STATE_EDIT;
      mUri = intent.getData();
    } else if (Intent.ACTION_INSERT.equals(action)) {
      mState = STATE_INSERT;
      if (mOriginalNote == null) {
        mUri = getContentResolver().insert(intent.getData(), null);
      } else {
        mUri = mOriginalNote.getUri();
      }

      setResult(RESULT_OK, (new Intent()).setAction(mUri.toString()));
    }

    if (mUri == null) {
      finish();
      return;
    }

    setContentView(R.layout.edit);

    mBodyText = (EditText) findViewById(R.id.body);

    Button confirmButton = (Button) findViewById(R.id.confirm);
    confirmButton.setOnClickListener(
        new View.OnClickListener() {
          public void onClick(View view) {
            finish();
          }
        });
    Button cancelButton = (Button) findViewById(R.id.cancel);
    cancelButton.setOnClickListener(
        new View.OnClickListener() {
          public void onClick(View view) {
            cancelNote();
          }
        });
  }
コード例 #4
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.contact_edit);
    initUI();

    Intent intent = getIntent();
    bundle = intent.getExtras();
    //		uri = intent.getData();
    String action = intent.getAction();
    if (Intent.ACTION_EDIT.equals(action)) {
      mState = STATE_EDIT;
    } else if (Intent.ACTION_INSERT.equals(action)) {
      mState = STATE_INSERT;
    }
  }
  @Override
  public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    if (savedInstanceState != null) {
      // Just restore from the saved state.  No loading.
      onRestoreInstanceState(savedInstanceState);
      if (mStatus == Status.SELECTING_ACCOUNT) {
        // Account select dialog is showing.  Don't setup the editor yet.
      } else if (mStatus == Status.LOADING) {
        startGroupMetaDataLoader();
      } else {
        setupEditorForAccount();
      }
    } else if (Intent.ACTION_EDIT.equals(mAction)) {
      startGroupMetaDataLoader();
    } else if (Intent.ACTION_INSERT.equals(mAction)) {
      final Account account =
          mIntentExtras == null
              ? null
              : (Account) mIntentExtras.getParcelable(Intents.Insert.EXTRA_ACCOUNT);
      final String dataSet =
          mIntentExtras == null ? null : mIntentExtras.getString(Intents.Insert.EXTRA_DATA_SET);

      if (account != null) {
        // Account specified in Intent - no data set can be specified in this manner.
        mAccountName = account.name;
        mAccountType = account.type;
        mDataSet = dataSet;
        setupEditorForAccount();
      } else {
        // No Account specified. Let the user choose from a disambiguation dialog.
        selectAccountAndCreateGroup();
      }
    } else {
      throw new IllegalArgumentException(
          "Unknown Action String "
              + mAction
              + ". Only support "
              + Intent.ACTION_EDIT
              + " or "
              + Intent.ACTION_INSERT);
    }
  }
コード例 #6
0
  @Override
  public int onStartCommand(Intent intent, int flags, int startId) {
    if (intent != null
        && (Intent.ACTION_DELETE.equals(intent.getAction())
            || Intent.ACTION_INSERT.equals(intent.getAction()) && intentProcessed)) {
      Log.d(LOG, "Service got shutdown intent");
      Ntf.show(this, false);
      stopSelf();
      intentProcessed = true;
      return START_NOT_STICKY;
    }

    Ntf.show(this, true);
    intentProcessed = true;
    if (intent != null) {
      Cfg.Pattern = intent.getIntExtra(TaskerActivity.BUNDLE_PATTERN, Cfg.Pattern);
      updatePattern();
      view.invalidate();
    }
    return START_STICKY;
  }
コード例 #7
0
ファイル: ActivityMain.java プロジェクト: JCulver/NotePad-2
  /** Returns true the intent URI targets a note. Either an edit/view or insert. */
  boolean isNoteIntent(final Intent intent) {
    if (intent == null) {
      return false;
    }
    if (Intent.ACTION_SEND.equals(intent.getAction())
        || "com.google.android.gm.action.AUTO_SEND".equals(intent.getAction())) {
      return true;
    }

    if (intent.getData() != null
        && (Intent.ACTION_EDIT.equals(intent.getAction())
            || Intent.ACTION_VIEW.equals(intent.getAction())
            || Intent.ACTION_INSERT.equals(intent.getAction()))
        && (intent.getData().getPath().startsWith(LegacyDBHelper.NotePad.Notes.PATH_VISIBLE_NOTES)
            || intent.getData().getPath().startsWith(LegacyDBHelper.NotePad.Notes.PATH_NOTES)
            || intent.getData().getPath().startsWith(Task.URI.getPath()))
        && !intent.getData().getPath().startsWith(TaskList.URI.getPath())) {
      return true;
    }

    return false;
  }
  /**
   * Saves or creates the group based on the mode, and if successful finishes the activity. This
   * actually only handles saving the group name.
   *
   * @return true when successful
   */
  public boolean save() {
    if (!hasValidGroupName() || mStatus != Status.EDITING) {
      mStatus = Status.CLOSING;
      if (mListener != null) {
        mListener.onReverted();
      }
      return false;
    }

    // If we are about to close the editor - there is no need to refresh the data
    getLoaderManager().destroyLoader(LOADER_EXISTING_MEMBERS);

    // If there are no changes, then go straight to onSaveCompleted()
    if (!hasNameChange() && !hasMembershipChange()) {
      onSaveCompleted(false, mGroupUri);
      return true;
    }

    mStatus = Status.SAVING;

    Activity activity = getActivity();
    // If the activity is not there anymore, then we can't continue with the save process.
    if (activity == null) {
      return false;
    }
    Intent saveIntent = null;
    if (Intent.ACTION_INSERT.equals(mAction)) {
      // Create array of raw contact IDs for contacts to add to the group
      long[] membersToAddArray = convertToArray(mListMembersToAdd);

      // Create the save intent to create the group and add members at the same time
      saveIntent =
          ContactSaveService.createNewGroupIntent(
              activity,
              new AccountWithDataSet(mAccountName, mAccountType, mDataSet),
              mGroupNameView.getText().toString(),
              membersToAddArray,
              activity.getClass(),
              GroupEditorActivity.ACTION_SAVE_COMPLETED);
    } else if (Intent.ACTION_EDIT.equals(mAction)) {
      // Create array of raw contact IDs for contacts to add to the group
      long[] membersToAddArray = convertToArray(mListMembersToAdd);

      // Create array of raw contact IDs for contacts to add to the group
      long[] membersToRemoveArray = convertToArray(mListMembersToRemove);

      // Create the update intent (which includes the updated group name if necessary)
      saveIntent =
          ContactSaveService.createGroupUpdateIntent(
              activity,
              mGroupId,
              getUpdatedName(),
              membersToAddArray,
              membersToRemoveArray,
              activity.getClass(),
              GroupEditorActivity.ACTION_SAVE_COMPLETED);
    } else {
      throw new IllegalStateException("Invalid intent action type " + mAction);
    }
    activity.startService(saveIntent);
    return true;
  }
コード例 #9
0
ファイル: FragmentLayout.java プロジェクト: avary/NotePad
  @Override
  protected void onNewIntent(Intent intent) {
    if (UI_DEBUG_PRINTS) Log.d("FragmentLayout", "On New Intent");

    // Search
    if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
      String query = intent.getStringExtra(SearchManager.QUERY);
      // list.onQueryTextChange(query);
      if (list != null && list.mSearchView != null) {
        list.mSearchView.setQuery(query, false);
      } else if (list != null) {
        list.onQueryTextSubmit(query);
      }
      // Edit or View a list or a note.
    } else if (Intent.ACTION_EDIT.equals(intent.getAction())
        || Intent.ACTION_VIEW.equals(intent.getAction())) {
      if (UI_DEBUG_PRINTS) Log.d("FragmentLayout", "On New Intent EDIT");
      // First, if we should display a list
      if (intent.getData() != null
          && intent.getData().getPath().startsWith(NotePad.Lists.PATH_VISIBLE_LIST_ID)) {
        // Get id to display
        String newId = intent.getData().getPathSegments().get(NotePad.Lists.ID_PATH_POSITION);
        long listId = Long.parseLong(newId);
        // Handle it differently depending on if the app has already
        // loaded or not.
        openListFromIntent(listId);
      } else if (intent.getData() != null
          && intent.getData().getPath().startsWith(NotePad.Notes.PATH_VISIBLE_NOTE_ID)) {
        if (list != null) {
          long listId = ALL_NOTES_ID;
          if (intent.getExtras() != null) {
            listId = intent.getExtras().getLong(NotePad.Notes.COLUMN_NAME_LIST, ALL_NOTES_ID);
          }
          // Open the containing list if we have to. No need to change
          // lists
          // if we are already displaying all notes.
          if (listId != -1 && currentListId != ALL_NOTES_ID && currentListId != listId) {
            openListFromIntent(listId);
          }
          if (listId != -1) {
            list.handleNoteIntent(intent);
          }
        }
      }
    } else if (Intent.ACTION_INSERT.equals(intent.getAction())) {
      if (UI_DEBUG_PRINTS) Log.d("FragmentLayout", "On New Intent INSERT");
      if (intent.getType() != null && intent.getType().equals(NotePad.Lists.CONTENT_TYPE)
          || intent.getData() != null
              && intent.getData().equals(NotePad.Lists.CONTENT_VISIBLE_URI)) {
        // get Title
        if (intent.getExtras() != null) {
          String title = intent.getExtras().getString(NotePad.Lists.COLUMN_NAME_TITLE, "");
          createList(title);
        }
      } else if (intent.getType() != null && intent.getType().equals(NotePad.Notes.CONTENT_TYPE)
          || intent.getData() != null
              && intent.getData().equals(NotePad.Notes.CONTENT_VISIBLE_URI)) {
        Log.d("FragmentLayout", "INSERT NOTE");
        if (list != null) {
          long listId = ALL_NOTES_ID;
          if (intent.getExtras() != null) {
            listId = intent.getExtras().getLong(NotePad.Notes.COLUMN_NAME_LIST, ALL_NOTES_ID);
          }

          // Open the containing list if we have to. No need to change
          // lists
          // if we are already displaying all notes.
          if (listId != -1 && currentListId != ALL_NOTES_ID && currentListId != listId) {
            openListFromIntent(listId);
          }
          if (listId != -1) {
            list.handleNoteIntent(intent);
          }
        }
      }
    }
  }
コード例 #10
0
  public void onClickOk(View v) {
    // Gets the action that triggered the intent filter for this Activity

    // TODO async

    final String action = getIntent().getAction();

    // For an edit action:
    if (Intent.ACTION_EDIT.equals(action)) {

      // Sets the Activity state to EDIT, and gets the URI for the data to
      // be edited.
      mState = STATE_EDIT;

      // For an insert or paste action:
    } else if (Intent.ACTION_INSERT.equals(action)) {
      // Sets the Activity state to INSERT, gets the general note URI, and
      // inserts an
      // empty record in the provider
      mState = STATE_INSERT;
      // mUri = getContentResolver().insert(intent.getData(), null);

      UserDataDbAdapter mUserDataDbAdapter = UserDataDbAdapter.getInstance(this);
      mUserDataDbAdapter.open();

      KanjiList list = null;
      list = mUserDataDbAdapter.createKanjiList(mText.getText().toString());
      // TODO check name not in use

      /*
       * If the attempt to insert the new note fails, shuts down this
       * Activity. The originating Activity receives back RESULT_CANCELED
       * if it requested a result. Logs that the insert failed.
       */
      if (list == null) {

        // Writes the log identifier, a message, and the URI that
        // failed.
        Log.e(Constants.DEBUG, "Failed to insert new list into " + getIntent().getData());

        // Closes the activity.
        finish();
        return;
      }

      // Since the new entry was created, this sets the result to be
      // returned
      // set the result to be returned.
      setResult(RESULT_OK, (new Intent()).putExtra(Constants.RESULT_ID, list.getId()));

      // If the action was other than EDIT or INSERT:
    } else {

      // Logs an error that the action was not understood, finishes the
      // Activity, and
      // returns RESULT_CANCELED to an originating Activity.
      Log.e(Constants.DEBUG, "Unknown action, exiting");
      finish();
      return;
    }
    finish();
  }
コード例 #11
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // go fullscreen for devices with QVGA screen (only way I found
    // how to fit UI on the screen)
    Display display = getWindowManager().getDefaultDisplay();
    if ((display.getWidth() == 240 || display.getWidth() == 320)
        && (display.getHeight() == 240 || display.getHeight() == 320)) {
      requestWindowFeature(Window.FEATURE_NO_TITLE);
      getWindow()
          .setFlags(
              WindowManager.LayoutParams.FLAG_FULLSCREEN,
              WindowManager.LayoutParams.FLAG_FULLSCREEN);
      mFullScreen = true;
    }

    // theme must be set before setContentView
    AndroidUtils.setThemeFromPreferences(this);

    setContentView(R.layout.sudoku_edit);
    mRootLayout = (ViewGroup) findViewById(R.id.root_layout);
    mBoard = (SudokuBoardView) findViewById(R.id.sudoku_board);

    mDatabase = new SudokuDatabase(getApplicationContext());

    mGuiHandler = new Handler();

    Intent intent = getIntent();
    String action = intent.getAction();
    if (Intent.ACTION_EDIT.equals(action)) {
      // Requested to edit: set that state, and the data being edited.
      mState = STATE_EDIT;
      if (intent.hasExtra(EXTRA_SUDOKU_ID)) {
        mSudokuID = intent.getLongExtra(EXTRA_SUDOKU_ID, 0);
      } else {
        throw new IllegalArgumentException(
            String.format("Extra with key '%s' is required.", EXTRA_SUDOKU_ID));
      }
    } else if (Intent.ACTION_INSERT.equals(action)) {
      mState = STATE_INSERT;
      mSudokuID = 0;

      if (intent.hasExtra(EXTRA_FOLDER_ID)) {
        mFolderID = intent.getLongExtra(EXTRA_FOLDER_ID, 0);
      } else {
        throw new IllegalArgumentException(
            String.format("Extra with key '%s' is required.", EXTRA_FOLDER_ID));
      }

    } else {
      // Whoops, unknown action!  Bail.
      Log.e(TAG, "Unknown action, exiting.");
      finish();
      return;
    }

    if (savedInstanceState != null) {
      mGame = new SudokuGame();
      mGame.restoreState(savedInstanceState);
    } else {
      if (mSudokuID != 0) {
        // existing sudoku, read it from database
        mGame = mDatabase.getSudoku(mSudokuID);
        mGame.getCells().markAllCellsAsEditable();
      } else {
        mGame = SudokuGame.createEmptyGame();
      }
    }
    mBoard.setGame(mGame);

    mInputMethods = (IMControlPanel) findViewById(R.id.input_methods);
    mInputMethods.initialize(mBoard, mGame, null);

    // only numpad input method will be enabled
    for (InputMethod im : mInputMethods.getInputMethods()) {
      im.setEnabled(false);
    }
    mInputMethods.getInputMethod().setEnabled(true);
    mInputMethods.activateInputMethod();
  }