Example usage for android.text Editable toString

List of usage examples for android.text Editable toString

Introduction

In this page you can find the example usage for android.text Editable toString.

Prototype

public String toString();

Source Link

Document

Returns a string containing the characters in this sequence in the same order as this sequence.

Usage

From source file:com.newtifry.android.SourceList.java

/**
 * Helper function to show a dialog to ask for a source name.
 *///from   www  .ja va  2 s. c o m
private void askForSourceName() {
    final EditText input = new EditText(this);

    new AlertDialog.Builder(this).setTitle(getString(R.string.create_source))
            .setMessage(getString(R.string.create_source_message)).setView(input)
            .setPositiveButton(getString(R.string.create), new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {
                    Editable value = input.getText();
                    if (value.length() > 0) {
                        // Fire it off to the create source function.
                        createSource(value.toString());
                    }
                }
            }).setNegativeButton(getString(R.string.cancel), new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {
                    // No need to take any action.
                }
            }).show();
}

From source file:com.fatelon.partyphotobooth.setup.fragments.EventInfoSetupFragment.java

@Override
public void onPause() {
    Context appContext = getActivity().getApplicationContext();

    // Store title.
    String lineOneString = null;/*from ww  w. j  ava 2  s.  c  o m*/
    Editable lineOne = mLineOne.getText();
    if (lineOne != null && lineOne.length() > 0) {
        lineOneString = lineOne.toString();
    }
    mPreferencesHelper.storeEventLineOne(appContext, lineOneString);

    String lineTwoString = null;
    Editable lineTwo = mLineTwo.getText();
    if (lineTwo != null && lineTwo.length() > 0) {
        lineTwoString = lineTwo.toString();
    }
    mPreferencesHelper.storeEventLineTwo(appContext, lineTwoString);

    // Store logo uri.
    String logoUriString = null;
    CharSequence logoUri = mLogoUri.getText();
    if (logoUri != null && logoUri.length() > 0) {
        logoUriString = logoUri.toString();
    }
    mPreferencesHelper.storeEventLogoUri(appContext, logoUriString);

    // Store date.
    if (mDateHidden.isChecked()) {
        mPreferencesHelper.storeEventDate(appContext, PreferencesHelper.EVENT_DATE_HIDDEN);
    } else {
        Calendar calendar = new GregorianCalendar(mDate.getYear(), mDate.getMonth(), mDate.getDayOfMonth());
        mPreferencesHelper.storeEventDate(appContext, calendar.getTimeInMillis());
    }

    super.onPause();
}

From source file:com.dwdesign.tweetings.fragment.DMConversationFragment.java

private void send() {
    final Editable text = mEditText.getText();
    if (isNullOrEmpty(text))
        return;//from ww w . j  a va 2s  . c  o m
    final String message = text.toString();
    if (mValidator.isValidTweet(message)) {
        final long account_id = mArguments.getLong(INTENT_KEY_ACCOUNT_ID, -1);
        final long conversation_id = mArguments.getLong(INTENT_KEY_CONVERSATION_ID, -1);
        final String screen_name = mArguments.getString(INTENT_KEY_SCREEN_NAME);
        mService.sendDirectMessage(account_id, screen_name, conversation_id, message);
        text.clear();
    }
}

From source file:org.thaliproject.nativetest.app.fragments.SettingsFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_settings, container, false);

    mSettings = Settings.getInstance(view.getContext());
    mSettings.load();/*from  w  w w  . j av  a  2  s.  c  o m*/

    mConnectionTimeoutEditText = (EditText) view.findViewById(R.id.connectionTimeoutEditText);
    mConnectionTimeoutEditText.setText(String.valueOf(mSettings.getConnectionTimeout()));
    mConnectionTimeoutEditText.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
        }

        @Override
        public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
        }

        @Override
        public void afterTextChanged(Editable editable) {
            if (editable.length() > 0) {
                try {
                    mSettings.setConnectionTimeout(Long.parseLong(editable.toString()));
                } catch (NumberFormatException e) {
                    Log.e(TAG, e.getMessage(), e);
                    mConnectionTimeoutEditText.setText(String.valueOf(mSettings.getConnectionTimeout()));
                }
            }
        }
    });

    mPortNumberEditText = (EditText) view.findViewById(R.id.portNumberEditText);
    mPortNumberEditText.setText(String.valueOf(mSettings.getPortNumber()));
    mPortNumberEditText.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
        }

        @Override
        public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
        }

        @Override
        public void afterTextChanged(Editable editable) {
            if (editable.length() > 0 && !editable.toString().equals("-")) {
                try {
                    mSettings.setPortNumber(Integer.parseInt(editable.toString()));
                } catch (NumberFormatException e) {
                    Log.e(TAG, e.getMessage(), e);
                    mPortNumberEditText.setText(String.valueOf(mSettings.getPortNumber()));
                }
            }
        }
    });

    mListenForIncomingConnectionsCheckbox = (CheckBox) view
            .findViewById(R.id.listenForIncomingConnectionCheckbox);
    mListenForIncomingConnectionsCheckbox.setChecked(mSettings.getListenForIncomingConnections());
    mListenForIncomingConnectionsCheckbox
            .setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
                @Override
                public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
                    mSettings.setListenForIncomingConnections(b);
                }
            });

    mHandshakeRequiredCheckbox = (CheckBox) view.findViewById(R.id.handshakeRequiredCheckBox);
    mHandshakeRequiredCheckbox.setChecked(mSettings.getHandshakeRequired());
    mHandshakeRequiredCheckbox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
            mSettings.setHandshakeRequired(b);
        }
    });

    mEnableWifiCheckBox = (CheckBox) view.findViewById(R.id.enableWifiCheckBox);
    mEnableWifiCheckBox.setChecked(mSettings.getEnableWifiDiscovery());
    mEnableWifiCheckBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
            mSettings.setEnableWifiDiscovery(b);
        }
    });

    mEnableBleCheckBox = (CheckBox) view.findViewById(R.id.enableBleCheckBox);
    mEnableBleCheckBox.setChecked(mSettings.getEnableBleDiscovery());
    mEnableBleCheckBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
            mSettings.setEnableBleDiscovery(b);
        }
    });

    Spinner spinner = (Spinner) view.findViewById(R.id.advertiseModeSpinner);
    ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(view.getContext(),
            R.array.advertise_mode_string_array, android.R.layout.simple_spinner_item);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spinner.setAdapter(adapter);
    spinner.setSelection(mSettings.getAdvertiseMode());
    spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> adapterView, View view, int index, long l) {
            mSettings.setAdvertiseMode(index);
        }

        @Override
        public void onNothingSelected(AdapterView<?> adapterView) {
        }
    });

    spinner = (Spinner) view.findViewById(R.id.advertiseTxPowerLevelSpinner);
    adapter = ArrayAdapter.createFromResource(view.getContext(), R.array.advertise_tx_power_level_string_array,
            android.R.layout.simple_spinner_item);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spinner.setAdapter(adapter);
    spinner.setSelection(mSettings.getAdvertiseTxPowerLevel());
    spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> adapterView, View view, int index, long l) {
            mSettings.setAdvertiseTxPowerLevel(index);
        }

        @Override
        public void onNothingSelected(AdapterView<?> adapterView) {
        }
    });

    spinner = (Spinner) view.findViewById(R.id.scanModeSpinner);
    adapter = ArrayAdapter.createFromResource(view.getContext(), R.array.scan_mode_string_array,
            android.R.layout.simple_spinner_item);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spinner.setAdapter(adapter);
    spinner.setSelection(mSettings.getScanMode());
    spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> adapterView, View view, int index, long l) {
            mSettings.setScanMode(index);
        }

        @Override
        public void onNothingSelected(AdapterView<?> adapterView) {
        }
    });

    mBufferSizeEditText = (EditText) view.findViewById(R.id.bufferSizeEditText);
    mBufferSizeEditText.setText(String.valueOf(mSettings.getBufferSize()));
    mBufferSizeEditText.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
        }

        @Override
        public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
        }

        @Override
        public void afterTextChanged(Editable editable) {
            if (editable.length() > 0) {
                try {
                    mSettings.setBufferSize(Integer.parseInt(editable.toString()));
                } catch (NumberFormatException e) {
                    Log.e(TAG, e.getMessage(), e);
                    mBufferSizeEditText.setText(String.valueOf(mSettings.getBufferSize()));
                }
            }
        }
    });

    mDataAmountEditText = (EditText) view.findViewById(R.id.dataAmountEditText);
    mDataAmountEditText.setText(String.valueOf(mSettings.getDataAmount()));
    mDataAmountEditText.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
        }

        @Override
        public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
        }

        @Override
        public void afterTextChanged(Editable editable) {
            if (editable.length() > 0) {
                try {
                    mSettings.setDataAmount(Long.parseLong(editable.toString()));
                } catch (NumberFormatException e) {
                    Log.e(TAG, e.getMessage(), e);
                    mDataAmountEditText.setText(String.valueOf(mSettings.getDataAmount()));
                }
            }
        }
    });

    mEnableAutoConnectCheckBox = (CheckBox) view.findViewById(R.id.autoConnectCheckBox);
    mEnableAutoConnectCheckBox.setChecked(mSettings.getAutoConnect());
    mEnableAutoConnectCheckBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
            mSettings.setAutoConnect(b);
        }
    });

    mEnableAutoConnectEvenWhenIncomingConnectionEstablishedCheckBox = (CheckBox) view
            .findViewById(R.id.autoConnectEvenWhenIncomingCheckBox);
    mEnableAutoConnectEvenWhenIncomingConnectionEstablishedCheckBox
            .setChecked(mSettings.getAutoConnectEvenWhenIncomingConnectionEstablished());
    mEnableAutoConnectEvenWhenIncomingConnectionEstablishedCheckBox
            .setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
                @Override
                public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
                    mSettings.setAutoConnectEvenWhenIncomingConnectionEstablished(b);
                }
            });

    return view;
}

From source file:org.alfresco.mobile.android.application.fragments.create.DocumentPropertiesDialogFragment.java

public Dialog onCreateDialog(Bundle savedInstanceState) {
    AnalyticsHelper.reportScreen(getActivity(), AnalyticsManager.SCREEN_NODE_CREATE_FORM);

    final String fragmentTag = (String) getArguments().get(ARGUMENT_FRAGMENT_TAG);
    final AlfrescoAccount currentAccount = (AlfrescoAccount) getArguments().get(ARGUMENT_ACCOUNT);
    final DocumentTypeRecord documentType = (DocumentTypeRecord) getArguments().get(ARGUMENT_DOCUMENT_TYPE);
    final ResolveInfo editor = (ResolveInfo) getArguments().get(ARGUMENT_EDITOR);

    File f = null;/*from   w w w  . j  a  v a  2s  .c o  m*/
    if (FileExplorerFragment.TAG.equals(fragmentTag)) {
        // If creation inside the download area, we store it inside
        // download.
        f = AlfrescoStorageManager.getInstance(getActivity()).getDownloadFolder(currentAccount);
    } else {
        // If creation inside a repository folder, we store temporarly
        // inside the capture.
        f = AlfrescoStorageManager.getInstance(getActivity()).getCaptureFolder(currentAccount);
    }

    final File folderStorage = f;

    LayoutInflater inflater = LayoutInflater.from(getActivity());
    final View v = inflater.inflate(R.layout.app_create_document, (ViewGroup) this.getView());

    ((TextView) v.findViewById(R.id.document_extension)).setText(documentType.extension);

    final MaterialEditText textName = ((MaterialEditText) v.findViewById(R.id.document_name));
    // This Listener is responsible to enable or not the validate button and
    // error message.
    textName.addTextChangedListener(new TextWatcher() {
        public void afterTextChanged(Editable s) {
            if (s.length() > 0) {
                textName.setFloatingLabelText(getString(R.string.content_name));
                ((MaterialDialog) getDialog()).getActionButton(DialogAction.POSITIVE).setEnabled(true);
                if (UIUtils.hasInvalidName(s.toString().trim())) {
                    textName.setError(getString(R.string.filename_error_character));
                    ((MaterialDialog) getDialog()).getActionButton(DialogAction.POSITIVE).setEnabled(false);
                } else {
                    textName.setError(null);
                }
            } else {
                textName.setHint(R.string.create_document_name_hint);
                ((MaterialDialog) getDialog()).getActionButton(DialogAction.POSITIVE).setEnabled(false);
                textName.setError(null);
            }
        }

        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        public void onTextChanged(CharSequence s, int start, int before, int count) {
        }
    });

    MaterialDialog dialog = new MaterialDialog.Builder(getActivity()).iconRes(R.drawable.ic_application_logo)
            .title(R.string.create_document_title).customView(v, true).positiveText(R.string.create)
            .negativeText(R.string.cancel).callback(new MaterialDialog.ButtonCallback() {
                @Override
                public void onNegative(MaterialDialog dialog) {
                    dialog.dismiss();
                }

                @Override
                public void onPositive(MaterialDialog dialog) {
                    String fileName = textName.getText().toString().trim().concat(documentType.extension);

                    File newFile = new File(folderStorage, fileName);

                    if (newFile.exists() && FileExplorerFragment.TAG.equals(fragmentTag)) {
                        // If the file already exist, we prompt a warning
                        // message.
                        textName.setError(getString(R.string.create_document_filename_error));
                        return;
                    } else {
                        try {
                            // If there's a template we create the file
                            // based on
                            // this template.
                            if (documentType.templatePath != null) {
                                AssetManager assetManager = getActivity().getAssets();
                                IOUtils.copyFile(assetManager.open(documentType.templatePath), newFile);
                            } else {
                                newFile.createNewFile();
                            }
                        } catch (IOException e1) {
                            Log.e(TAG, Log.getStackTraceString(e1));
                        }
                    }

                    // We create the Intent based on informations we grab
                    // previously.
                    Intent intent = new Intent(Intent.ACTION_VIEW);
                    Uri data = Uri.fromFile(newFile);
                    intent.setDataAndType(data, documentType.mimetype);
                    intent.setComponent(new ComponentName(editor.activityInfo.applicationInfo.packageName,
                            editor.activityInfo.name));

                    try {
                        Fragment fr = getFragmentManager().findFragmentByTag(fragmentTag);
                        if (fr != null && fr.isVisible()) {
                            if (fr instanceof DocumentFolderBrowserFragment) {
                                // During Creation on a specific folder.
                                ((DocumentFolderBrowserFragment) fr).setCreateFile(newFile);
                            } else if (fr instanceof FileExplorerFragment) {
                                // During Creation inside the download
                                // folder.
                                ((FileExplorerFragment) fr).setCreateFile(newFile);
                            }
                            fr.startActivity(intent);
                        }
                    } catch (ActivityNotFoundException e) {
                        AlfrescoNotificationManager.getInstance(getActivity())
                                .showToast(R.string.error_unable_open_file);
                    }
                    dismiss();
                }
            }).build();

    dialog.getActionButton(DialogAction.POSITIVE).setEnabled(false);

    return dialog;
}

From source file:com.notifry.android.SourceList.java

/**
 * Helper function to show a dialog to ask for a source name.
 *//*from w  w  w .  ja  va2s. c  o  m*/
private void askForSourceName() {
    final EditText input = new EditText(this);

    new AlertDialog.Builder(this).setTitle(getString(R.string.create_source))
            .setMessage(getString(R.string.create_source_message)).setView(input)
            .setPositiveButton(getString(R.string.create), new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int whichButton) {
                    Editable value = input.getText();
                    if (value.length() > 0) {
                        // Fire it off to the create source
                        // function.
                        createSource(value.toString());
                    }
                }
            }).setNegativeButton(getString(R.string.cancel), new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int whichButton) {
                    // No need to take any action.
                }
            }).show();
}

From source file:com.downrighttech.dmxdip.MainActivity.java

@Override
public void afterTextChanged(Editable s) {
    Log.v(TAG, "afterTextChanged" + s.toString());
    int start = mFirstAddress;
    int span = 1;

    // Check Start has a length
    if (editText_Start.length() != 0) {
        int currentStart = Integer.parseInt(editText_Start.getText().toString());
        //if greater then last then make it that.
        if (currentStart > mLastAddress) {
            editText_Start.setText(Integer.toString(mLastAddress));
            editText_Start.selectAll();//  ww w .j a va  2 s. c  om
        }
        if (currentStart < mFirstAddress)
            editText_Start.setText(Integer.toString(mFirstAddress));
        start = Integer.parseInt(editText_Start.getText().toString());
    }

    // Check Span has a length
    if (editText_Span.length() != 0) {
        int currentSpan = Integer.parseInt(editText_Span.getText().toString());
        if (currentSpan > mLastAddress) {
            editText_Span.setText(Integer.toString(mLastAddress));
            editText_Span.selectAll();
        }
        if (Integer.parseInt(editText_Span.getText().toString()) <= 0) {
            editText_Span.setText("1");
            editText_Span.selectAll();
        }
        span = Integer.parseInt(editText_Span.getText().toString());
    }

    if (mSkipProcess)
        return;
    Log.v(TAG, "input: " + start + "." + span);

    SharedPreferences.Editor editor = mSharedPreferences.edit();
    editor.putInt("pref_start", start);
    editor.putInt("pref_span", span);
    editor.commit();

    updateArray(start, span);
    updateButtons();
    buildChart();
    buildIntent();
}

From source file:edu.vuum.mocca.ui.tags.CreateTagsFragment.java

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    // Get the EditTexts
    loginIdET = (EditText) getView().findViewById(R.id.tags_create_value_login_id);
    storyIdET = (EditText) getView().findViewById(R.id.tags_create_value_story_id);
    tagET = (EditText) getView().findViewById(R.id.tags_create_value_tag);

    buttonClear = (Button) getView().findViewById(R.id.tags_create_button_reset);
    buttonCancel = (Button) getView().findViewById(R.id.tags_create_button_cancel);
    buttonCreate = (Button) getView().findViewById(R.id.tags_create_button_save);

    buttonClear.setOnClickListener(new OnClickListener() {
        @Override/*from  w w w  . j  a  v a  2s .  c  o m*/
        public void onClick(View v) {
            loginIdET.setText("" + 0);
            storyIdET.setText("" + 0);
            tagET.setText("" + "");
        }
    });

    buttonCancel.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            if (getResources().getBoolean(R.bool.isTablet) == true) {
                // put
                mOpener.openViewTagsFragment(0);
            } else {
                getActivity().finish(); // same as hitting 'back' button
            }
        }
    });

    buttonCreate.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // local Editables
            Editable loginIdCreateable = loginIdET.getText();
            Editable storyIdCreateable = storyIdET.getText();
            Editable tagCreateable = tagET.getText();

            long loginId = 0;
            long storyId = 0;
            String tag = "";

            // pull values from Editables
            loginId = Long.valueOf(loginIdCreateable.toString());
            storyId = Long.valueOf(storyIdCreateable.toString());
            tag = String.valueOf(tagCreateable.toString());

            // new TagsData object with above info
            TagsData newData = new TagsData(-1,
                    // -1 row index, because there is no way to know which row it
                    // will go into
                    loginId, storyId, tag);

            // insert it through Resolver to be put into ContentProvider
            try {
                resolver.insert(newData);
            } catch (RemoteException e) {
                Log.e(LOG_TAG, "Caught RemoteException => " + e.getMessage());
                e.printStackTrace();
            }
            // return back to proper state
            if (getResources().getBoolean(R.bool.isTablet) == true) {
                // put
                mOpener.openViewTagsFragment(0);
            } else {
                getActivity().finish(); // same as hitting 'back' button
            }
        }
    });

}

From source file:nl.sogeti.android.gpstracker.actions.NameTrack.java

@Override
public void afterTextChanged(Editable editable) {

    if (mStartStationAutoCompleteTextView.enoughToFilter()) {
        String newFilter = editable.toString();

        if (!newFilter.equalsIgnoreCase(mCurStartStationNameFilter)) {
            mCurStartStationNameFilter = newFilter;
            getSupportLoaderManager().restartLoader(STARTSTATIONCURSOR_LOADER, null, this);
        }/* w  w w  .  ja v  a 2 s  . c  om*/
    }

    if (mEndStationAutoCompleteTextView.enoughToFilter()) {
        String newFilter = editable.toString();
        if (!newFilter.equalsIgnoreCase(mCurEndStationNameFilter)) {
            mCurEndStationNameFilter = newFilter;
            getSupportLoaderManager().restartLoader(ENDSTATIONCURSOR_LOADER, null, this);
        }
    }
}

From source file:nl.jalava.appostle.AppListFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.app_list, container, false);
    appList = (ListView) view.findViewById(R.id.listView1);
    progress = (ProgressBar) view.findViewById(R.id.progressBar);
    progress_loading = (TextView) view.findViewById(R.id.progress_loading);

    progress.bringToFront();/*  w w w  .j  a  v a 2s .co  m*/
    progress_loading.bringToFront();

    mContext = view.getContext();

    // Make list clickable and fast scrollable.
    appList.setClickable(true);
    appList.setFastScrollEnabled(true);

    // OnClick
    appList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            AppInfo o = (AppInfo) appList.getItemAtPosition(position);
            listener.onAppSelected(o);
        }
    });

    // Swipe to refresh.
    mSwipeRefreshLayout = (SwipeRefreshLayout) view.findViewById(R.id.swipe_refresh_apps);
    mSwipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
        @Override
        public void onRefresh() {
            new UpdateAppList().execute();
        }
    });

    mSearchEdit = (RelativeLayout) view.findViewById(R.id.search_layout);

    // Restore the last visibility state of the text edit.
    if (mSearchEditOpen)
        mSearchEdit.setVisibility(View.VISIBLE);
    else
        mSearchEdit.setVisibility(View.GONE);

    mSearchText = (EditText) view.findViewById(R.id.search_app_edit);

    // Restore text and cursor position.
    mSearchText.setText(mSearchEditText);
    mSearchText.setSelection(mSearchEditTextPosition);

    mSearchText.addTextChangedListener(new TextWatcher() {
        @Override
        public void afterTextChanged(Editable s) {
            if (mAppInfoAdapter != null)
                mAppInfoAdapter.getFilter().filter(s);
            mSearchEditText = s.toString();
        }

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
        }
    });

    // Activate keyboard if search text edit is opened.
    // Close if no focus.
    mSearchText.setOnFocusChangeListener(new View.OnFocusChangeListener() {
        @Override
        public void onFocusChange(View v, boolean hasFocus) {
            if (hasFocus) {
                // Open keyboard
                ((InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE))
                        .showSoftInput(v, InputMethodManager.SHOW_FORCED);
            } else {
                // Close keyboard.
                ((InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE))
                        .hideSoftInputFromWindow(v.getWindowToken(), 0);
            }
        }
    });

    // Clear text button.
    Button clear = (Button) view.findViewById(R.id.search_clear_button);
    clear.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            mSearchText.setText("");
        }
    });

    // Close search.
    Button close = (Button) view.findViewById(R.id.search_close_button);
    close.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            mSearchEdit.setVisibility(View.GONE);
            mSearchEditOpen = false;
        }
    });

    // Prevent always refreshing when pulling listview down.
    appList.setOnScrollListener(new AbsListView.OnScrollListener() {
        @Override
        public void onScrollStateChanged(AbsListView view, int scrollState) {
        }

        @Override
        public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
            if (firstVisibleItem == 0) {
                mSwipeRefreshLayout.setEnabled(true);
            } else
                mSwipeRefreshLayout.setEnabled(false);
        }
    });

    pm = mContext.getPackageManager();
    doUpdate(-1);

    return view;
}