Example usage for android.content Intent getCharSequenceExtra

List of usage examples for android.content Intent getCharSequenceExtra

Introduction

In this page you can find the example usage for android.content Intent getCharSequenceExtra.

Prototype

public CharSequence getCharSequenceExtra(String name) 

Source Link

Document

Retrieve extended data from the intent.

Usage

From source file:com.ushahidi.android.app.ui.phone.AddReportActivity.java

/**
 * Get shared text from other Android applications
 *//*  w  ww. j av  a  2 s  .  co m*/
public void getSharedText() {
    Intent intent = getIntent();
    String action = intent.getAction();
    if (action != null) {
        if (action.equals(Intent.ACTION_SEND) || action.equals(Intent.ACTION_CHOOSER)) {
            CharSequence text = intent.getCharSequenceExtra(Intent.EXTRA_TEXT);
            if (text != null) {
                view.mIncidentDesc.setText(text);
            }
        }
    }
}

From source file:com.doctoror.fuckoffmusicplayer.presentation.playback.PlaybackAndroidService.java

@Override
public int onStartCommand(final Intent intent, final int flags, final int startId) {
    if (ContextCompat.checkSelfPermission(this,
            Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
        stopSelf();/* ww w.jav a 2 s  .  c o  m*/
        return START_NOT_STICKY;
    }

    if (intent == null) {
        stopSelf(startId);
        return START_NOT_STICKY;
    }

    final String action = intent.getAction();
    if (action == null) {
        stopSelf(startId);
        return START_NOT_STICKY;
    }

    switch (intent.getAction()) {
    case ACTION_PLAY_PAUSE:
        onActionPlayPause();
        break;

    case ACTION_PLAY:
        onActionPlay(intent);
        break;

    case ACTION_PLAY_ANYTHING:
        onActionPlayAnything();
        break;

    case ACTION_PAUSE:
        onActionPause();
        break;

    case ACTION_STOP:
        onActionStop();
        break;

    case ACTION_STOP_WITH_ERROR:
        onActionStopWithError(intent.getCharSequenceExtra(EXTRA_ERROR_MESSAGE));
        break;

    case ACTION_PREV:
        onActionPrev();
        break;

    case ACTION_NEXT:
        onActionNext();
        break;

    case ACTION_SEEK:
        onActionSeek(intent);
        break;

    case Intent.ACTION_MEDIA_BUTTON:
        onActionMediaButton(intent);
        break;

    default:
        stopSelf(startId);
        return START_NOT_STICKY;
    }
    return START_STICKY;
}

From source file:com.folioreader.ui.folio.activity.FolioActivity.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {

    if (requestCode == RequestCode.SEARCH.value) {
        Log.v(LOG_TAG, "-> onActivityResult -> " + RequestCode.SEARCH);

        if (resultCode == RESULT_CANCELED)
            return;

        searchAdapterDataBundle = data.getBundleExtra(SearchAdapter.DATA_BUNDLE);
        searchQuery = data.getCharSequenceExtra(SearchActivity.BUNDLE_SAVE_SEARCH_QUERY);

        if (resultCode == SearchActivity.ResultCode.ITEM_SELECTED.getValue()) {

            searchItem = data.getParcelableExtra(EXTRA_SEARCH_ITEM);
            // In case if SearchActivity is recreated due to screen rotation then FolioActivity
            // will also be recreated, so mFolioPageViewPager might be null.
            if (mFolioPageViewPager == null)
                return;
            currentChapterIndex = getChapterIndex(Constants.HREF, searchItem.getHref());
            mFolioPageViewPager.setCurrentItem(currentChapterIndex);
            FolioPageFragment folioPageFragment = getCurrentFragment();
            if (folioPageFragment == null)
                return;
            folioPageFragment.highlightSearchItem(searchItem);
            searchItem = null;// w  w w. j  av  a2  s. com
        }

    } else if (requestCode == RequestCode.CONTENT_HIGHLIGHT.value && resultCode == RESULT_OK
            && data.hasExtra(TYPE)) {

        String type = data.getStringExtra(TYPE);

        if (type.equals(CHAPTER_SELECTED)) {
            goToChapter(data.getStringExtra(SELECTED_CHAPTER_POSITION));

        } else if (type.equals(HIGHLIGHT_SELECTED)) {
            HighlightImpl highlightImpl = data.getParcelableExtra(HIGHLIGHT_ITEM);
            currentChapterIndex = highlightImpl.getPageNumber();
            mFolioPageViewPager.setCurrentItem(currentChapterIndex);
            FolioPageFragment folioPageFragment = getCurrentFragment();
            if (folioPageFragment == null)
                return;
            folioPageFragment.scrollToHighlightId(highlightImpl.getRangy());
        }
    }
}

From source file:de.vanita5.twittnuker.activity.support.ComposeActivity.java

private boolean handleDefaultIntent(final Intent intent) {
    if (intent == null)
        return false;
    final String action = intent.getAction();
    mShouldSaveAccounts = !Intent.ACTION_SEND.equals(action) && !Intent.ACTION_SEND_MULTIPLE.equals(action);
    final Uri data = intent.getData();
    final CharSequence extraSubject = intent.getCharSequenceExtra(Intent.EXTRA_SUBJECT);
    final CharSequence extraText = intent.getCharSequenceExtra(Intent.EXTRA_TEXT);
    final Uri extraStream = intent.getParcelableExtra(Intent.EXTRA_STREAM);
    if (extraStream != null) {
        new AddMediaTask(this, extraStream, createTempImageUri(), ParcelableMedia.TYPE_IMAGE, false).execute();
    } else if (data != null) {
        new AddMediaTask(this, data, createTempImageUri(), ParcelableMedia.TYPE_IMAGE, false).execute();
    } else if (intent.hasExtra(EXTRA_SHARE_SCREENSHOT)) {
        final Bitmap bitmap = intent.getParcelableExtra(EXTRA_SHARE_SCREENSHOT);
        if (bitmap != null) {
            try {
                new AddBitmapTask(this, bitmap, createTempImageUri(), ParcelableMedia.TYPE_IMAGE).execute();
            } catch (IOException e) {
                // ignore
                bitmap.recycle();//from  w  w  w  .j av a 2  s. c  o  m
            }
        }
    }
    mEditText.setText(getShareStatus(this, extraSubject, extraText));
    final int selection_end = mEditText.length();
    mEditText.setSelection(selection_end);
    return true;
}

From source file:nl.mpcjanssen.simpletask.AddTask.java

@Override
public void onCreate(Bundle savedInstanceState) {
    Log.v(TAG, "onCreate()");

    m_app = (TodoApplication) getApplication();
    m_app.setActionBarStyle(getWindow());
    requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
    super.onCreate(savedInstanceState);
    IntentFilter intentFilter = new IntentFilter();
    intentFilter.addAction(Constants.BROADCAST_UPDATE_UI);
    intentFilter.addAction(Constants.BROADCAST_SYNC_START);
    intentFilter.addAction(Constants.BROADCAST_SYNC_DONE);

    localBroadcastManager = m_app.getLocalBroadCastManager();

    m_broadcastReceiver = new BroadcastReceiver() {
        @Override/*  w w w. j  av  a  2s  . c  o  m*/
        public void onReceive(Context context, @NotNull Intent intent) {
            if (intent.getAction().equals(Constants.BROADCAST_SYNC_START)) {
                setProgressBarIndeterminateVisibility(true);
            } else if (intent.getAction().equals(Constants.BROADCAST_SYNC_DONE)) {
                setProgressBarIndeterminateVisibility(false);
            }
        }
    };
    localBroadcastManager.registerReceiver(m_broadcastReceiver, intentFilter);

    ActionBar actionBar = getActionBar();
    if (actionBar != null) {
        actionBar.setDisplayHomeAsUpEnabled(true);
    }
    final Intent intent = getIntent();
    ActiveFilter mFilter = new ActiveFilter();
    mFilter.initFromIntent(intent);
    final String action = intent.getAction();
    // create shortcut and exit
    if (Intent.ACTION_CREATE_SHORTCUT.equals(action)) {
        Log.d(TAG, "Setting up shortcut icon");
        setupShortcut();
        finish();
        return;
    } else if (Intent.ACTION_SEND.equals(action)) {
        Log.d(TAG, "Share");
        if (intent.hasExtra(Intent.EXTRA_TEXT)) {
            share_text = intent.getCharSequenceExtra(Intent.EXTRA_TEXT).toString();
        } else {
            share_text = "";
        }
        if (!m_app.hasShareTaskShowsEdit()) {
            if (!share_text.equals("")) {
                addBackgroundTask(share_text);
            }
            finish();
            return;
        }
    } else if ("com.google.android.gm.action.AUTO_SEND".equals(action)) {
        // Called as note to self from google search/now
        noteToSelf(intent);
        finish();
        return;
    } else if (Constants.INTENT_BACKGROUND_TASK.equals(action)) {
        Log.v(TAG, "Adding background task");
        if (intent.hasExtra(Constants.EXTRA_BACKGROUND_TASK)) {
            addBackgroundTask(intent.getStringExtra(Constants.EXTRA_BACKGROUND_TASK));
        } else {
            Log.w(TAG, "Task was not in extras");
        }
        finish();
        return;
    }

    getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);

    setContentView(R.layout.add_task);

    // text
    textInputField = (EditText) findViewById(R.id.taskText);
    m_app.setEditTextHint(textInputField, R.string.tasktexthint);

    if (share_text != null) {
        textInputField.setText(share_text);
    }

    Task iniTask = null;
    setTitle(R.string.addtask);

    m_backup = m_app.getTaskCache(this).getTasksToUpdate();
    if (m_backup != null && m_backup.size() > 0) {
        ArrayList<String> prefill = new ArrayList<String>();
        for (Task t : m_backup) {
            prefill.add(t.inFileFormat());
        }
        String sPrefill = Util.join(prefill, "\n");
        textInputField.setText(sPrefill);
        setTitle(R.string.updatetask);
    } else {
        if (textInputField.getText().length() == 0) {
            iniTask = new Task(1, "");
            iniTask.initWithFilter(mFilter);
        }

        if (iniTask != null && iniTask.getTags().size() == 1) {
            List<String> ps = iniTask.getTags();
            String project = ps.get(0);
            if (!project.equals("-")) {
                textInputField.append(" +" + project);
            }
        }

        if (iniTask != null && iniTask.getLists().size() == 1) {
            List<String> cs = iniTask.getLists();
            String context = cs.get(0);
            if (!context.equals("-")) {
                textInputField.append(" @" + context);
            }
        }
    }
    // Listen to enter events, use IME_ACTION_NEXT for soft keyboards
    // like Swype where ENTER keyCode is not generated.

    int inputFlags = InputType.TYPE_CLASS_TEXT;

    if (m_app.hasCapitalizeTasks()) {
        inputFlags |= InputType.TYPE_TEXT_FLAG_CAP_SENTENCES;
    }
    textInputField.setRawInputType(inputFlags);
    textInputField.setImeOptions(EditorInfo.IME_ACTION_NEXT);
    textInputField.setOnEditorActionListener(new TextView.OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView textView, int actionId, @Nullable KeyEvent keyEvent) {

            boolean hardwareEnterUp = keyEvent != null && keyEvent.getAction() == KeyEvent.ACTION_UP
                    && keyEvent.getKeyCode() == KeyEvent.KEYCODE_ENTER;
            boolean hardwareEnterDown = keyEvent != null && keyEvent.getAction() == KeyEvent.ACTION_DOWN
                    && keyEvent.getKeyCode() == KeyEvent.KEYCODE_ENTER;
            boolean imeActionNext = (actionId == EditorInfo.IME_ACTION_NEXT);

            if (imeActionNext || hardwareEnterUp) {
                // Move cursor to end of line
                int position = textInputField.getSelectionStart();
                String remainingText = textInputField.getText().toString().substring(position);
                int endOfLineDistance = remainingText.indexOf('\n');
                int endOfLine;
                if (endOfLineDistance == -1) {
                    endOfLine = textInputField.length();
                } else {
                    endOfLine = position + endOfLineDistance;
                }
                textInputField.setSelection(endOfLine);
                replaceTextAtSelection("\n", false);

                if (hasCloneTags()) {
                    String precedingText = textInputField.getText().toString().substring(0, endOfLine);
                    int lineStart = precedingText.lastIndexOf('\n');
                    String line;
                    if (lineStart != -1) {
                        line = precedingText.substring(lineStart, endOfLine);
                    } else {
                        line = precedingText;
                    }
                    Task t = new Task(0, line);
                    LinkedHashSet<String> tags = new LinkedHashSet<String>();
                    for (String ctx : t.getLists()) {
                        tags.add("@" + ctx);
                    }
                    for (String prj : t.getTags()) {
                        tags.add("+" + prj);
                    }
                    replaceTextAtSelection(Util.join(tags, " "), true);
                }
                endOfLine++;
                textInputField.setSelection(endOfLine);
            }
            return (imeActionNext || hardwareEnterDown || hardwareEnterUp);
        }
    });

    setCloneTags(m_app.isAddTagsCloneTags());
    setWordWrap(m_app.isWordWrap());

    findViewById(R.id.cb_wrap).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            setWordWrap(hasWordWrap());
        }
    });

    int textIndex = 0;
    textInputField.setSelection(textIndex);

    // Set button callbacks
    findViewById(R.id.btnContext).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            showContextMenu();
        }
    });
    findViewById(R.id.btnProject).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            showTagMenu();
        }
    });
    findViewById(R.id.btnPrio).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            showPrioMenu();
        }
    });

    findViewById(R.id.btnDue).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            insertDate(Task.DUE_DATE);
        }
    });
    findViewById(R.id.btnThreshold).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            insertDate(Task.THRESHOLD_DATE);
        }
    });

    if (m_backup != null && m_backup.size() > 0) {
        textInputField.setSelection(textInputField.getText().length());
    }
}

From source file:org.getlantern.firetweet.activity.support.ComposeActivity.java

private boolean handleDefaultIntent(final Intent intent) {
    if (intent == null)
        return false;
    final String action = intent.getAction();
    final boolean hasAccountIds;
    if (intent.hasExtra(EXTRA_ACCOUNT_IDS)) {
        mAccountsAdapter.setSelectedAccountIds(intent.getLongArrayExtra(EXTRA_ACCOUNT_IDS));
        hasAccountIds = true;/*from  w  w  w  . ja  v a  2  s.c  o m*/
    } else if (intent.hasExtra(EXTRA_ACCOUNT_ID)) {
        mAccountsAdapter.setSelectedAccountIds(intent.getLongExtra(EXTRA_ACCOUNT_ID, -1));
        hasAccountIds = true;
    } else {
        hasAccountIds = false;
    }
    mShouldSaveAccounts = !Intent.ACTION_SEND.equals(action) && !Intent.ACTION_SEND_MULTIPLE.equals(action)
            && !hasAccountIds;
    final Uri data = intent.getData();
    final CharSequence extraSubject = intent.getCharSequenceExtra(Intent.EXTRA_SUBJECT);
    final CharSequence extraText = intent.getCharSequenceExtra(Intent.EXTRA_TEXT);
    final Uri extraStream = intent.getParcelableExtra(Intent.EXTRA_STREAM);
    //TODO handle share_screenshot extra (Bitmap)
    if (extraStream != null) {
        AsyncTaskUtils.executeTask(
                new AddMediaTask(this, extraStream, createTempImageUri(), ParcelableMedia.TYPE_IMAGE, false));
    } else if (data != null) {
        AsyncTaskUtils.executeTask(
                new AddMediaTask(this, data, createTempImageUri(), ParcelableMedia.TYPE_IMAGE, false));
    } else if (intent.hasExtra(EXTRA_SHARE_SCREENSHOT) && Utils.useShareScreenshot()) {
        final Bitmap bitmap = intent.getParcelableExtra(EXTRA_SHARE_SCREENSHOT);
        if (bitmap != null) {
            try {
                AsyncTaskUtils.executeTask(
                        new AddBitmapTask(this, bitmap, createTempImageUri(), ParcelableMedia.TYPE_IMAGE));
            } catch (IOException e) {
                // ignore
                bitmap.recycle();
            }
        }
    }
    mEditText.setText(getShareStatus(this, extraSubject, extraText));
    final int selection_end = mEditText.length();
    mEditText.setSelection(selection_end);
    return true;
}

From source file:org.mariotaku.twidere.activity.support.ComposeActivity.java

private boolean handleDefaultIntent(final Intent intent) {
    if (intent == null)
        return false;
    final String action = intent.getAction();
    final boolean hasAccountIds;
    if (intent.hasExtra(EXTRA_ACCOUNT_IDS)) {
        mAccountsAdapter.setSelectedAccountIds(intent.getLongArrayExtra(EXTRA_ACCOUNT_IDS));
        hasAccountIds = true;// w w  w . j a  va  2  s .co m
    } else if (intent.hasExtra(EXTRA_ACCOUNT_ID)) {
        mAccountsAdapter.setSelectedAccountIds(intent.getLongExtra(EXTRA_ACCOUNT_ID, -1));
        hasAccountIds = true;
    } else {
        hasAccountIds = false;
    }
    mShouldSaveAccounts = !Intent.ACTION_SEND.equals(action) && !Intent.ACTION_SEND_MULTIPLE.equals(action)
            && !hasAccountIds;
    final Uri data = intent.getData();
    final CharSequence extraSubject = intent.getCharSequenceExtra(Intent.EXTRA_SUBJECT);
    final CharSequence extraText = intent.getCharSequenceExtra(Intent.EXTRA_TEXT);
    final Uri extraStream = intent.getParcelableExtra(Intent.EXTRA_STREAM);
    //TODO handle share_screenshot extra (Bitmap)
    if (extraStream != null) {
        AsyncTaskUtils.executeTask(
                new AddMediaTask(this, extraStream, createTempImageUri(), ParcelableMedia.TYPE_IMAGE, false));
    } else if (data != null) {
        AsyncTaskUtils.executeTask(
                new AddMediaTask(this, data, createTempImageUri(), ParcelableMedia.TYPE_IMAGE, false));
    } else if (intent.hasExtra(EXTRA_SHARE_SCREENSHOT) && Utils.useShareScreenshot()) {
        final Bitmap bitmap = intent.getParcelableExtra(EXTRA_SHARE_SCREENSHOT);
        if (bitmap != null) {
            try {
                AsyncTaskUtils.executeTask(
                        new AddBitmapTask(this, bitmap, createTempImageUri(), ParcelableMedia.TYPE_IMAGE));
            } catch (IOException e) {
                // ignore
                bitmap.recycle();
            }
        }
    }
    mEditText.setText(Utils.getShareStatus(this, extraSubject, extraText));
    final int selectionEnd = mEditText.length();
    mEditText.setSelection(selectionEnd);
    return true;
}

From source file:de.mrapp.android.preference.activity.PreferenceActivity.java

/**
 * Returns the char sequence, which is specified by a specific intent extra. The char sequence
 * can either be specified as a string or as a resource id.
 *
 * @param intent/*from   ww w  . j a v  a 2 s .  c  om*/
 *         The intent, which specifies the char sequence, as an instance of the class {@link
 *         Intent}. The intent may not be null
 * @param name
 *         The name of the intent extra, which specifies the char sequence, as a {@link String}.
 *         The name may not be null
 * @return The char sequence, which is specified by the given intent, as an instance of the
 * class {@link CharSequence} or null, if the intent does not specify a char sequence with the
 * given name
 */
private CharSequence getCharSequenceFromIntent(@NonNull final Intent intent, @NonNull final String name) {
    CharSequence charSequence = intent.getCharSequenceExtra(name);

    if (charSequence == null) {
        int resourceId = intent.getIntExtra(name, 0);

        if (resourceId != 0) {
            charSequence = getText(resourceId);
        }
    }

    return charSequence;
}

From source file:org.rm3l.maoni.ui.MaoniActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);

    final Intent intent = getIntent();

    setTheme(intent.getIntExtra(THEME, R.style.Maoni_AppTheme_Light));

    setContentView(R.layout.maoni_activity_feedback);

    mRootView = findViewById(R.id.maoni_container);
    if (mRootView == null) {
        throw new IllegalStateException(
                "Layout must contain a root view with the following id: maoni_container");
    }// w w  w .j  a va 2  s  .co  m

    mHighlightColor = ContextCompat.getColor(this, R.color.maoni_highlight_transparent_semi);
    mBlackoutColor = ContextCompat.getColor(this, R.color.maoni_black);

    if (intent.hasExtra(WORKING_DIR)) {
        mWorkingDir = new File(intent.getStringExtra(WORKING_DIR));
    } else {
        mWorkingDir = getCacheDir();
    }

    if (intent.hasExtra(SHARED_PREFERENCES)) {
        //noinspection unchecked
        mSharedPreferences = (HashMap<String, Object>) intent.getSerializableExtra(SHARED_PREFERENCES);
    }

    final ImageView headerImageView = (ImageView) findViewById(R.id.maoni_toolbar_header_image);
    if (headerImageView != null && intent.hasExtra(HEADER)) {
        final int headerLayoutId = intent.getIntExtra(HEADER, -1);
        if (headerLayoutId != -1) {
            headerImageView.setImageResource(headerLayoutId);
        }
    }

    if (intent.hasExtra(EXTRA_LAYOUT)) {
        final View extraContentView = findViewById(R.id.maoni_content_extra);
        if (extraContentView instanceof LinearLayout) {
            final int extraLayout = intent.getIntExtra(EXTRA_LAYOUT, -1);
            if (extraLayout != -1) {
                final LinearLayout extraContent = (LinearLayout) extraContentView;
                extraContent.setVisibility(View.VISIBLE);
                extraContent.addView(getLayoutInflater().inflate(extraLayout, extraContent, false));
            }
        }
    }

    final CallbacksConfiguration maoniConfiguration = CallbacksConfiguration.getInstance(this);
    mListener = maoniConfiguration.getListener();
    mValidator = maoniConfiguration.getValidator();

    final Toolbar toolbar = (Toolbar) findViewById(R.id.maoni_toolbar);
    if (toolbar != null) {
        toolbar.setTitle(intent.hasExtra(WINDOW_TITLE) ? intent.getCharSequenceExtra(WINDOW_TITLE)
                : getString(R.string.maoni_send_feedback));
        if (intent.hasExtra(WINDOW_SUBTITLE)) {
            toolbar.setSubtitle(intent.getCharSequenceExtra(WINDOW_SUBTITLE));
        }
        if (intent.hasExtra(TOOLBAR_TITLE_TEXT_COLOR)) {
            toolbar.setTitleTextColor(intent.getIntExtra(TOOLBAR_TITLE_TEXT_COLOR, R.color.maoni_white));
        }
        if (intent.hasExtra(TOOLBAR_SUBTITLE_TEXT_COLOR)) {
            toolbar.setSubtitleTextColor(intent.getIntExtra(TOOLBAR_SUBTITLE_TEXT_COLOR, R.color.maoni_white));
        }
        setSupportActionBar(toolbar);
    }

    final ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {
        actionBar.setDisplayHomeAsUpEnabled(true);
        actionBar.setHomeButtonEnabled(true);
        actionBar.setHomeButtonEnabled(true);
    }

    if (intent.hasExtra(MESSAGE)) {
        final CharSequence message = intent.getCharSequenceExtra(MESSAGE);
        final TextView activityMessageTv = (TextView) findViewById(R.id.maoni_feedback_message);
        if (activityMessageTv != null) {
            activityMessageTv.setText(message);
        }
    }

    if (intent.hasExtra(SCREENSHOT_HINT)) {
        final CharSequence screenshotInformationalHint = intent.getCharSequenceExtra(SCREENSHOT_HINT);
        final TextView screenshotInformationalHintTv = (TextView) findViewById(
                R.id.maoni_screenshot_informational_text);
        if (screenshotInformationalHintTv != null) {
            screenshotInformationalHintTv.setText(screenshotInformationalHint);
        }
    }

    mContentInputLayout = (TextInputLayout) findViewById(R.id.maoni_content_input_layout);
    mContent = (EditText) findViewById(R.id.maoni_content);

    if (intent.hasExtra(CONTENT_HINT)) {
        final CharSequence contentHint = intent.getCharSequenceExtra(CONTENT_HINT);
        if (mContentInputLayout != null) {
            mContentInputLayout.setHint(contentHint);
        }
    }

    if (intent.hasExtra(CONTENT_ERROR_TEXT)) {
        mContentErrorText = intent.getCharSequenceExtra(CONTENT_ERROR_TEXT);
    } else {
        mContentErrorText = getString(R.string.maoni_validate_must_not_be_blank);
    }

    mIncludeLogs = (CheckBox) findViewById(R.id.maoni_include_logs);
    if (mIncludeLogs != null && intent.hasExtra(INCLUDE_LOGS_TEXT)) {
        mIncludeLogs.setText(intent.getCharSequenceExtra(INCLUDE_LOGS_TEXT));
    }

    mIncludeScreenshot = (CheckBox) findViewById(R.id.maoni_include_screenshot);
    if (mIncludeScreenshot != null && intent.hasExtra(INCLUDE_SCREENSHOT_TEXT)) {
        mIncludeScreenshot.setText(intent.getCharSequenceExtra(INCLUDE_SCREENSHOT_TEXT));
    }

    mScreenshotFilePath = intent.getCharSequenceExtra(SCREENSHOT_FILE);

    mShowKeyboardOnStart = intent.getBooleanExtra(SHOW_KEYBOARD_ON_START, false);

    mScreenCapturingFeatureEnabled = intent.getBooleanExtra(SCREEN_CAPTURING_FEATURE_ENABLED, true);
    final Integer[] screenCapturingRelatedFields = new Integer[] { R.id.maoni_include_screenshot,
            R.id.maoni_include_screenshot_content };
    if (mScreenCapturingFeatureEnabled) {
        initScreenCaptureView(intent);
    }
    final int visibilityForScreenCapturingRelatedFields = (mScreenCapturingFeatureEnabled ? View.VISIBLE
            : View.GONE);
    for (final Integer screenCapturingRelatedField : screenCapturingRelatedFields) {
        final View view = findViewById(screenCapturingRelatedField);
        if (view == null) {
            continue;
        }
        view.setVisibility(visibilityForScreenCapturingRelatedFields);
    }

    mLogsCapturingFeatureEnabled = intent.getBooleanExtra(LOGS_CAPTURING_FEATURE_ENABLED, true);
    final Integer[] logsCapturingRelatedFields = new Integer[] { R.id.maoni_include_logs };
    final int visibilityForLogsCapturingRelatedFields = (mLogsCapturingFeatureEnabled ? View.VISIBLE
            : View.GONE);
    for (final Integer logsCapturingRelatedField : logsCapturingRelatedFields) {
        final View view = findViewById(logsCapturingRelatedField);
        if (view == null) {
            continue;
        }
        view.setVisibility(visibilityForLogsCapturingRelatedFields);
    }

    mFeedbackUniqueId = UUID.randomUUID().toString();

    final View fab = findViewById(R.id.maoni_fab);
    if (fab != null) {
        fab.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                validateAndSubmitForm();
            }
        });
    }

    setAppRelatedInfo();

    final UiListener uiListener = maoniConfiguration.getUiListener();
    if (uiListener != null) {
        uiListener.onCreate(mRootView, savedInstanceState);
    }
}

From source file:edu.cmu.cylab.starslinger.view.HomeActivity.java

private boolean handleSendToAction() {
    Intent intent = getIntent();
    String action = intent.getAction();
    long filesize = 0;

    if (action != null) {
        if (action.equals(Intent.ACTION_SEND_MULTIPLE)) {

            showErrorExit(R.string.error_MultipleSendNotSupported);
            return false;

        } else if (action.equals(Intent.ACTION_SEND)) {
            DraftData d = DraftData.INSTANCE;

            d.setMsgHash(null);/*from  ww w.  j a  v  a2  s  .  c o m*/

            String type = intent.getType();
            Uri stream = (Uri) intent.getParcelableExtra(Intent.EXTRA_STREAM);
            CharSequence extra_text = intent.getCharSequenceExtra(Intent.EXTRA_TEXT);

            // if this is from a share menu
            try {
                // Get resource path from intent caller
                if (Intent.ACTION_SEND.equals(action)) {
                    if (stream != null) {
                        filesize = getOutStreamSizeAndData(stream, type);
                    } else if (!TextUtils.isEmpty(extra_text)) {
                        filesize = extra_text.length();
                        if (filesize <= SafeSlingerConfig.MAX_TEXTMESSAGE) {
                            d.removeFile();
                            d.setText(extra_text.toString());
                        } else {
                            d.setFileType("text/plain");
                            final byte[] textBytes = extra_text.toString().getBytes();
                            d.setFileData(textBytes);
                            d.setFileSize(textBytes.length);
                            SimpleDateFormat sdf = new SimpleDateFormat(SafeSlingerConfig.DATETIME_FILENAME,
                                    Locale.US);
                            d.setFileName(sdf.format(new Date()) + ".txt");
                            d.removeText();
                        }
                    }
                }

                if (filesize <= 0) {
                    showErrorExit(R.string.error_CannotSendEmptyFile);
                    return false;
                }
                if (filesize > SafeSlingerConfig.MAX_FILEBYTES) {
                    showErrorExit(String.format(getString(R.string.error_CannotSendFilesOver),
                            SafeSlingerConfig.MAX_FILEBYTES));
                    return false;
                }
            } catch (IOException e) {
                showErrorExit(e);
                return false;
            } catch (OutOfMemoryError e) {
                showErrorExit(R.string.error_OutOfMemoryError);
                return false;
            }
        }
    }
    return true;
}