Search in sources :

Example 1 with DetachableResultReceiver

use of se.alexanderblom.delicious.util.DetachableResultReceiver in project android-delicious by lexs.

the class AddBookmarkActivity method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_add_bookmark);
    setTitle(R.string.activity_add_bookmark_title);
    // Enable up button
    getActionBar().setHomeButtonEnabled(true);
    errorDrawable = DeliciousApplication.getErrorDrawable();
    titleFetcher = new TitleFetcher(this);
    receiver = new DetachableResultReceiver(new Handler());
    urlView = (EditText) findViewById(R.id.url);
    titleView = (EditText) findViewById(R.id.title);
    notesView = (EditText) findViewById(R.id.notes);
    tagsView = (MultiAutoCompleteTextView) findViewById(R.id.tags);
    privateView = (CheckBox) findViewById(R.id.mark_private);
    // TODO: Implement tag suggestion
    /*ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
                android.R.layout.simple_spinner_dropdown_item, TAGS);
        tagsView.setAdapter(adapter);
        tagsView.setTokenizer(new MultiAutoCompleteTextView.CommaTokenizer());*/
    // Enable user to press enter when done
    tagsView.setOnEditorActionListener(new OnEditorActionListener() {

        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if (actionId == EditorInfo.IME_ACTION_DONE) {
                saveBookmark();
                return true;
            } else {
                return false;
            }
        }
    });
    Intent intent = getIntent();
    if (Intent.ACTION_SEND.equals(intent.getAction())) {
        String url = intent.getStringExtra(Intent.EXTRA_TEXT);
        String title = intent.getStringExtra(Intent.EXTRA_SUBJECT);
        urlView.setText(url);
        titleView.setText(title);
        // Check were focus should go
        if (TextUtils.isEmpty(url)) {
            urlView.requestFocus();
        } else if (TextUtils.isEmpty(title)) {
            titleView.requestFocus();
        } else {
            // Focus tags because it can't be prefilled
            tagsView.requestFocus();
        }
    }
    // Fetch title if necessary
    titleFetcher.maybeFetchTitle();
}
Also used : KeyEvent(android.view.KeyEvent) Handler(android.os.Handler) OnEditorActionListener(android.widget.TextView.OnEditorActionListener) MultiAutoCompleteTextView(android.widget.MultiAutoCompleteTextView) TextView(android.widget.TextView) Intent(android.content.Intent) DetachableResultReceiver(se.alexanderblom.delicious.util.DetachableResultReceiver) TitleFetcher(se.alexanderblom.delicious.helpers.TitleFetcher)

Aggregations

Intent (android.content.Intent)1 Handler (android.os.Handler)1 KeyEvent (android.view.KeyEvent)1 MultiAutoCompleteTextView (android.widget.MultiAutoCompleteTextView)1 TextView (android.widget.TextView)1 OnEditorActionListener (android.widget.TextView.OnEditorActionListener)1 TitleFetcher (se.alexanderblom.delicious.helpers.TitleFetcher)1 DetachableResultReceiver (se.alexanderblom.delicious.util.DetachableResultReceiver)1