Example usage for android.view Window FEATURE_RIGHT_ICON

List of usage examples for android.view Window FEATURE_RIGHT_ICON

Introduction

In this page you can find the example usage for android.view Window FEATURE_RIGHT_ICON.

Prototype

int FEATURE_RIGHT_ICON

To view the source code for android.view Window FEATURE_RIGHT_ICON.

Click Source Link

Document

Flag for having an icon on the right side of the title bar

Usage

From source file:com.nanosheep.bikeroute.Feedback.java

@Override
public final void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    app = ((BikeRouteApp) getApplication());
    requestWindowFeature(Window.FEATURE_RIGHT_ICON);
    setContentView(R.layout.feedback);//from w  w w  . j a  v a2s  .  co  m
    setFeatureDrawableResource(Window.FEATURE_RIGHT_ICON, R.drawable.ic_bar_bikeroute);

    nameField = (TextView) findViewById(R.id.name_input);
    emailField = (TextView) findViewById(R.id.email_input);
    commentField = (TextView) findViewById(R.id.comment_input);
    submit = (Button) findViewById(R.id.submit_button);

    //Handle rotations
    final Object[] data = (Object[]) getLastNonConfigurationInstance();
    if (data != null) {
        nameField.setText((CharSequence) data[0]);
        emailField.setText((CharSequence) data[1]);
        commentField.setText((CharSequence) data[2]);
    }
    //Input validation
    final Validate watcher = new Validate();
    nameField.addTextChangedListener(watcher);
    emailField.addTextChangedListener(watcher);
    commentField.addTextChangedListener(watcher);

    //Form submit handler
    submitHandler = new SubmitHandler();
    submit.setOnClickListener(submitHandler);
}

From source file:org.appcelerator.titanium.TiBaseActivity.java

protected void setNavBarHidden(boolean hidden) {
    if (!hidden) {
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
            // Do not enable these features on Honeycomb or later since it will break the action bar.
            this.requestWindowFeature(Window.FEATURE_LEFT_ICON);
            this.requestWindowFeature(Window.FEATURE_RIGHT_ICON);
        }/*w  ww.  j  a  v a  2  s .c o m*/

        this.requestWindowFeature(Window.FEATURE_PROGRESS);
        this.requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);

    } else {
        this.requestWindowFeature(Window.FEATURE_NO_TITLE);
    }
}

From source file:org.openintents.notepad.NoteEditor.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    if (DEBUG) {// w  w  w. j a  v a2s .co m
        Log.d(TAG, "onCreate()");
    }

    if (getIntent().getAction().equals(Intent.ACTION_CREATE_SHORTCUT)) {
        createShortcut();
        return;
    }

    if (savedInstanceState == null) {
        // sDecryptedText has no use for brand new activities
        sDecryptedText = null;
    }

    // Usually, sDecryptedText == null.
    mDecryptedText = sDecryptedText;
    if (sDecryptedText != null) {
        // we use the text right now,
        // so don't encrypt the text anymore.
        EncryptActivity.cancelEncrypt();

        if (EncryptActivity.getPendingEncryptActivities() == 0) {
            if (DEBUG) {
                Log.d(TAG, "sDecryptedText = null");
            }
            // no more encrypt activies will be called
            sDecryptedText = null;
        }
    }

    mSelectionStart = 0;
    mSelectionStop = 0;

    // If an instance of this activity had previously stopped, we can
    // get the original text it started with.
    if (savedInstanceState != null) {
        mOriginalContent = savedInstanceState.getString(BUNDLE_ORIGINAL_CONTENT);
        mUndoRevert = savedInstanceState.getString(BUNDLE_UNDO_REVERT);
        mState = savedInstanceState.getInt(BUNDLE_STATE);
        String uriString = savedInstanceState.getString(BUNDLE_URI);
        if (uriString != null) {
            mUri = Uri.parse(uriString);
        }

        mSelectionStart = savedInstanceState.getInt(BUNDLE_SELECTION_START);
        mSelectionStop = savedInstanceState.getInt(BUNDLE_SELECTION_STOP);
        mFileContent = savedInstanceState.getString(BUNDLE_FILE_CONTENT);
        if (mApplyText == null && mApplyTextBefore == null && mApplyTextAfter == null) {
            // Only read values if they had not been set by
            // onActivityResult() yet:
            mApplyText = savedInstanceState.getString(BUNDLE_APPLY_TEXT);
            mApplyTextBefore = savedInstanceState.getString(BUNDLE_APPLY_TEXT_BEFORE);
            mApplyTextAfter = savedInstanceState.getString(BUNDLE_APPLY_TEXT_AFTER);
        }
    } else {
        // Do some setup based on the action being performed.
        final Intent intent = getIntent();
        final String action = intent.getAction();

        if (Intent.ACTION_EDIT.equals(action) || Intent.ACTION_VIEW.equals(action)) {
            // Requested to edit: set that state, and the data being edited.
            mState = STATE_EDIT;
            mUri = intent.getData();

            if (mUri != null && mUri.getScheme().equals("file")) {
                mState = STATE_EDIT_NOTE_FROM_SDCARD;
                // Load the file into a new note.

                if (ContextCompat.checkSelfPermission(this,
                        Manifest.permission.READ_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) {
                    mFileContent = readFile(FileUriUtils.getFile(mUri));
                } else {
                    if (ActivityCompat.shouldShowRequestPermissionRationale(this,
                            Manifest.permission.READ_EXTERNAL_STORAGE)) {

                    } else {
                        ActivityCompat.requestPermissions(this,
                                new String[] { Manifest.permission.READ_EXTERNAL_STORAGE },
                                REQUEST_CODE_PERMISSION_READ_EXTERNAL_STORAGE);
                        mFileContent = getString(R.string.request_permissions);
                    }
                }
            } else if (mUri != null && !mUri.getAuthority().equals(NotePad.AUTHORITY)) {
                // Note a notepad note. Treat slightly differently.
                // (E.g. a note from OI Shopping List)
                mState = STATE_EDIT_EXTERNAL_NOTE;
            }

        } else if (Intent.ACTION_INSERT.equals(action) || Intent.ACTION_SEND.equals(action)) {

            // Use theme of most recently modified note:
            ContentValues values = new ContentValues(1);
            String theme = getMostRecentlyUsedTheme();
            values.put(Notes.THEME, theme);

            String tags = intent.getStringExtra(NotepadInternalIntents.EXTRA_TAGS);
            values.put(Notes.TAGS, tags);

            if (mText != null) {
                values.put(Notes.SELECTION_START, mText.getSelectionStart());
                values.put(Notes.SELECTION_END, mText.getSelectionEnd());
            }

            // Requested to insert: set that state, and create a new entry
            // in the container.
            mState = STATE_INSERT;
            /*
             * intent.setAction(Intent.ACTION_EDIT); intent.setData(mUri);
            * setIntent(intent);
            */

            if (Intent.ACTION_SEND.equals(action)) {
                values.put(Notes.NOTE, getIntent().getStringExtra(Intent.EXTRA_TEXT));
                mUri = getContentResolver().insert(Notes.CONTENT_URI, values);
            } else {
                mUri = getContentResolver().insert(intent.getData(), values);
            }

            // If we were unable to create a new note, then just finish
            // this activity. A RESULT_CANCELED will be sent back to the
            // original activity if they requested a result.
            if (mUri == null) {
                Log.e(TAG, "Failed to insert new note into " + getIntent().getData());
                finish();
                return;
            }

            // The new entry was created, so assume all will end well and
            // set the result to be returned.
            // setResult(RESULT_OK, (new
            // Intent()).setAction(mUri.toString()));
            setResult(RESULT_OK, intent);

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

    // setup actionbar
    if (mActionBarAvailable) {
        requestWindowFeature(Window.FEATURE_ACTION_BAR);
        WrapActionBar bar = new WrapActionBar(this);
        bar.setDisplayHomeAsUpEnabled(true);
        // force to show the actionbar on version 14+
        if (Integer.valueOf(android.os.Build.VERSION.SDK) >= 14) {
            bar.setHomeButtonEnabled(true);
        }
    } else {
        requestWindowFeature(Window.FEATURE_RIGHT_ICON);
    }

    // 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 (mState == STATE_EDIT_NOTE_FROM_SDCARD) {
        // We add a text watcher, so that the title can be updated
        // to indicate a small "*" if modified.
        mText.addTextChangedListener(mTextWatcherSdCard);
    }

    if (mState != STATE_EDIT_NOTE_FROM_SDCARD) {

        // Check if we load a note from notepad or from some external module
        if (mState == STATE_EDIT_EXTERNAL_NOTE) {
            // Get all the columns as we don't know which columns are
            // supported.
            mCursor = managedQuery(mUri, null, null, null, null);

            // Now check which columns are available
            List<String> columnNames = Arrays.asList(mCursor.getColumnNames());

            if (!columnNames.contains(Notes.NOTE)) {
                hasNoteColumn = false;
            }
            if (!columnNames.contains(Notes.TAGS)) {
                hasTagsColumn = false;
            }
            if (!columnNames.contains(Notes.ENCRYPTED)) {
                hasEncryptionColumn = false;
            }
            if (!columnNames.contains(Notes.THEME)) {
                hasThemeColumn = false;
            }
            if (!columnNames.contains(Notes.SELECTION_START)) {
                hasSelection_startColumn = false;
            }
            if (!columnNames.contains(Notes.SELECTION_END)) {
                hasSelection_endColumn = false;
            }
        } else {
            // Get the note!
            mCursor = managedQuery(mUri, PROJECTION, null, null, null);

            // It's not an external note, so all the columns are available
            // in the database
        }
    } else {
        mCursor = null;
    }

    mText.addTextChangedListener(mTextWatcherCharCount);

    initSearchPanel();
}

From source file:org.openintents.notepad.NoteEditor.java

private void getNoteFromContentProvider() {
    // If we didn't have any trouble retrieving the data, it is now
    // time to get at the stuff.
    if (mCursor != null && mCursor.requery() && mCursor.moveToFirst()) {

        // Modify our overall title depending on the mode we are running in.
        if (mState == STATE_EDIT || mState == STATE_EDIT_EXTERNAL_NOTE) {
            setTitle(getText(R.string.title_edit));
        } else if (mState == STATE_INSERT) {
            setTitle(getText(R.string.title_create));
        }/*from  w  w  w.  j  av a  2  s.com*/

        // This always has to be available
        long id = mCursor.getLong(mCursor.getColumnIndex(Notes._ID));
        String note;

        if (mState == STATE_EDIT_EXTERNAL_NOTE) {
            // Check if the other columns are available

            // Note
            if (hasNoteColumn) {
                note = mCursor.getString(mCursor.getColumnIndex(Notes.NOTE));
            } else {
                note = "";
            }

            // Encrypted
            mEncrypted = isNoteUnencrypted() ? 0 : 1;

            // Theme
            if (hasThemeColumn) {
                mTheme = mCursor.getString(mCursor.getColumnIndex(Notes.THEME));
            } else {
                note = "";
            }

            // Selection start
            if (hasSelection_startColumn) {
                mSelectionStart = mCursor.getInt(mCursor.getColumnIndex(Notes.SELECTION_START));
            } else {
                mSelectionStart = 0;
            }

            // Selection end
            if (hasSelection_endColumn) {
                mSelectionStop = mCursor.getInt(mCursor.getColumnIndex(Notes.SELECTION_END));
            } else {
                mSelectionStop = 0;
            }
        } else {
            // We know for sure all the columns are available
            note = mCursor.getString(COLUMN_INDEX_NOTE);
            mEncrypted = mCursor.getLong(COLUMN_INDEX_ENCRYPTED);
            mTheme = mCursor.getString(COLUMN_INDEX_THEME);
            mSelectionStart = mCursor.getInt(COLUMN_INDEX_SELECTION_START);
            mSelectionStop = mCursor.getInt(COLUMN_INDEX_SELECTION_END);
        }

        if (mEncrypted == 0) {
            // Not encrypted

            // This is a little tricky: we may be resumed after previously
            // being
            // paused/stopped. We want to put the new text in the text view,
            // but leave the user where they were (retain the cursor
            // position
            // etc). This version of setText does that for us.
            if (!note.equals(mText.getText().toString())) {
                mText.setTextKeepState(note);
                // keep state does not work, so we have to do it manually:
                mText.setSelection(mSelectionStart, mSelectionStop);
            }
        } else {
            if (mDecryptedText != null) {
                // Text had already been decrypted, use that:
                if (DEBUG) {
                    Log.d(TAG, "set decrypted text as mText: " + mDecryptedText);
                }
                mText.setTextKeepState(mDecryptedText);
                // keep state does not work, so we have to do it manually:
                mText.setSelection(mSelectionStart, mSelectionStop);

                if (!mActionBarAvailable) {
                    setFeatureDrawableResource(Window.FEATURE_RIGHT_ICON, android.R.drawable.ic_lock_idle_lock);
                }
            } else {
                // Decrypt note
                if (DEBUG) {
                    Log.d(TAG, "Decrypt note: " + note);
                }

                // Overwrite mText because it may contain unencrypted note
                // from savedInstanceState.
                // mText.setText(R.string.encrypted);

                Intent i = new Intent();
                i.setAction(CryptoIntents.ACTION_DECRYPT);
                i.putExtra(CryptoIntents.EXTRA_TEXT, note);
                i.putExtra(PrivateNotePadIntents.EXTRA_ID, id);

                try {
                    if (checkCallingOrSelfPermission(
                            CryptoIntents.PERMISSION_SAFE_ACCESS_INTENTS) == PackageManager.PERMISSION_GRANTED) {
                        startActivityForResult(i, REQUEST_CODE_DECRYPT);
                    } else {
                        Toast.makeText(this, R.string.decryption_failed_due_to_permissions, Toast.LENGTH_SHORT)
                                .show();
                    }
                } catch (ActivityNotFoundException e) {
                    Toast.makeText(this, R.string.decryption_failed, Toast.LENGTH_SHORT).show();
                    Log.e(TAG, "failed to invoke decrypt");
                }
            }
        }

        // If we hadn't previously retrieved the original text, do so
        // now. This allows the user to revert their changes.
        if (mOriginalContent == null) {
            mOriginalContent = note;
        }

    } else {
        setTitle(getText(R.string.error_title));
        mText.setText(getText(R.string.error_message));
    }
}

From source file:org.openintents.notepad.NoteEditor.java

/**
 * Unencrypt the current note./*w w  w.  j  a va 2  s .  com*/
 */
private void unencryptNote() {
    String text = mText.getText().toString();
    String title = ExtractTitle.extractTitle(text);
    String tags = getTags();
    // Log.i(TAG, "unencrypt tags: " + tags);

    ContentValues values = new ContentValues();
    values.put(Notes.MODIFIED_DATE, System.currentTimeMillis());
    values.put(Notes.TITLE, title);
    values.put(Notes.NOTE, text);
    values.put(Notes.ENCRYPTED, 0);

    getContentResolver().update(mUri, values, null, null);
    mCursor.requery();

    if (!mActionBarAvailable) {
        setFeatureDrawable(Window.FEATURE_RIGHT_ICON, null);
    }

    // Small trick: Tags have not been converted properly yet. Let's do it
    // now:
    Intent i = new Intent(this, EncryptActivity.class);
    i.putExtra(PrivateNotePadIntents.EXTRA_ACTION, CryptoIntents.ACTION_DECRYPT);
    i.putExtra(CryptoIntents.EXTRA_TEXT_ARRAY, EncryptActivity.getCryptoStringArray(null, null, tags));
    i.putExtra(PrivateNotePadIntents.EXTRA_URI, mUri.toString());
    startActivity(i);
}