Example usage for android.net Uri getScheme

List of usage examples for android.net Uri getScheme

Introduction

In this page you can find the example usage for android.net Uri getScheme.

Prototype

@Nullable
public abstract String getScheme();

Source Link

Document

Gets the scheme of this URI.

Usage

From source file:org.apache.cordova.AndroidWebView.java

/**
 * Load the specified URL in the Cordova webview or a new browser instance.
 *
 * NOTE: If openExternal is false, only URLs listed in whitelist can be loaded.
 *
 * @param url           The url to load.
 * @param openExternal  Load url in browser instead of Cordova webview.
 * @param clearHistory  Clear the history stack, so new page becomes top of history
 * @param params        Parameters for new app
 *//*  w w w  . ja va  2 s .  c om*/
public void showWebPage(String url, boolean openExternal, boolean clearHistory,
        HashMap<String, Object> params) {
    LOG.d(TAG, "showWebPage(%s, %b, %b, HashMap", url, openExternal, clearHistory);

    // If clearing history
    if (clearHistory) {
        this.clearHistory();
    }

    // If loading into our webview
    if (!openExternal) {

        // Make sure url is in whitelist
        if (url.startsWith("file://") || Config.isUrlWhiteListed(url)) {
            // TODO: What about params?
            // Load new URL
            this.loadUrl(url);
            return;
        }
        // Load in default viewer if not
        LOG.w(TAG,
                "showWebPage: Cannot load URL into webview since it is not in white list.  Loading into browser instead. (URL="
                        + url + ")");
    }
    try {
        // Omitting the MIME type for file: URLs causes "No Activity found to handle Intent".
        // Adding the MIME type to http: URLs causes them to not be handled by the downloader.
        Intent intent = new Intent(Intent.ACTION_VIEW);
        Uri uri = Uri.parse(url);
        if ("file".equals(uri.getScheme())) {
            intent.setDataAndType(uri, resourceApi.getMimeType(uri));
        } else {
            intent.setData(uri);
        }
        cordova.getActivity().startActivity(intent);
    } catch (android.content.ActivityNotFoundException e) {
        LOG.e(TAG, "Error loading url " + url, e);
    }
}

From source file:com.baroq.pico.google.PlayServices.java

@Override
public void onPlayersLoaded(int statusCode, PlayerBuffer buffer) {
    JSONObject json = new JSONObject();
    try {/*from   w  w  w  .ja v a 2  s .  co  m*/
        json.put("type", PLAYER_LOADED);
        json.put("statusCode", statusCode);
        switch (statusCode) {
        case GamesClient.STATUS_OK:
            // if data was successfully loaded and is up-to-date.
            JSONArray players = new JSONArray();
            JSONObject player;
            for (int i = 0, l = buffer.getCount(); i < l; i++) {
                Player p = buffer.get(i);
                player = new JSONObject();
                player.put("displayName", p.getDisplayName());
                if (p.hasHiResImage()) {
                    Uri uri = p.getHiResImageUri();
                    player.put("hiResImageUri", uri.getScheme() + ':' + uri.getSchemeSpecificPart());
                }
                if (p.hasIconImage()) {
                    Uri uri = p.getIconImageUri();
                    player.put("iconImageUri", uri.getScheme() + ':' + uri.getSchemeSpecificPart());
                }
                player.put("playerId", p.getPlayerId());
                player.put("retrievedTimestamp", p.getRetrievedTimestamp());
                players.put(player);
            }
            json.put("list", players);
            break;
        case GamesClient.STATUS_INTERNAL_ERROR:
            // if an unexpected error occurred in the service 
            break;
        case GamesClient.STATUS_NETWORK_ERROR_STALE_DATA:
            // if the device was unable to communicate with the network. In this case, the operation is not retried automatically.
            break;
        case GamesClient.STATUS_CLIENT_RECONNECT_REQUIRED:
            // need to reconnect GamesClient
            mHelper.reconnectClients(clientTypes);
            break;
        case GamesClient.STATUS_LICENSE_CHECK_FAILED:
            // The game is not licensed to the user. Further calls will return the same code.
            break;
        default:
            // error
            break;
        }
    } catch (JSONException ex) {
        Log.e(TAG, "PLAYER_LOADED [" + statusCode + "] exception: " + ex.getMessage());
        return;
    }

    buffer.close();
    PluginResult pluginResult = new PluginResult(PluginResult.Status.OK, json);
    pluginResult.setKeepCallback(true);
    connectionCB.sendPluginResult(pluginResult);
}

From source file:com.dwdesign.tweetings.activity.ImageViewerActivity.java

@Override
public void onClick(final View view) {
    final Uri uri = getIntent().getData();
    switch (view.getId()) {
    case R.id.close: {
        onBackPressed();//from w w w. ja va  2  s .c  o m
        break;
    }
    case R.id.refresh_stop_save: {
        if (!mImageLoaded && !mImageLoading) {
            loadImage();
        } else if (!mImageLoaded && mImageLoading) {
            stopLoading();
        } else if (mImageLoaded) {
            saveImage();
        }
        break;
    }
    case R.id.share: {
        if (uri == null) {
            break;
        }
        final Intent intent = new Intent(Intent.ACTION_SEND);
        final String scheme = uri.getScheme();
        if ("file".equals(scheme)) {
            intent.setType("image/*");
            intent.putExtra(Intent.EXTRA_STREAM, uri);
        } else {
            intent.setType("text/plain");
            intent.putExtra(Intent.EXTRA_TEXT, uri.toString());
        }
        startActivity(Intent.createChooser(intent, getString(R.string.share)));
        break;
    }
    case R.id.open_in_browser: {
        if (uri == null) {
            break;
        }
        final String scheme = uri.getScheme();
        if ("http".equals(scheme) || "https".equals(scheme)) {
            final Intent intent = new Intent(Intent.ACTION_VIEW, uri);
            intent.addCategory(Intent.CATEGORY_BROWSABLE);
            try {
                startActivity(intent);
            } catch (final ActivityNotFoundException e) {
                // Ignore.
            }
        }
        break;
    }
    }
}

From source file:com.synox.android.ui.activity.Uploader.java

public void uploadFiles() {
    try {/*w ww.j a v  a  2 s .  c  o m*/

        // ArrayList for files with path in external storage
        ArrayList<String> local = new ArrayList<>();
        ArrayList<String> remote = new ArrayList<>();

        // this checks the mimeType
        for (Parcelable mStream : mStreamsToUpload) {

            Uri uri = (Uri) mStream;
            String data = null;
            String filePath = "";

            if (uri != null) {
                if (uri.getScheme().equals("content")) {
                    String mimeType = getContentResolver().getType(uri);

                    if (mimeType.contains("image")) {
                        String[] CONTENT_PROJECTION = { Images.Media.DATA, Images.Media.DISPLAY_NAME,
                                Images.Media.MIME_TYPE, Images.Media.SIZE };
                        Cursor c = getContentResolver().query(uri, CONTENT_PROJECTION, null, null, null);
                        c.moveToFirst();
                        int index = c.getColumnIndex(Images.Media.DATA);
                        data = c.getString(index);
                        filePath = mUploadPath + c.getString(c.getColumnIndex(Images.Media.DISPLAY_NAME));

                    } else if (mimeType.contains("video")) {
                        String[] CONTENT_PROJECTION = { Video.Media.DATA, Video.Media.DISPLAY_NAME,
                                Video.Media.MIME_TYPE, Video.Media.SIZE, Video.Media.DATE_MODIFIED };
                        Cursor c = getContentResolver().query(uri, CONTENT_PROJECTION, null, null, null);
                        c.moveToFirst();
                        int index = c.getColumnIndex(Video.Media.DATA);
                        data = c.getString(index);
                        filePath = mUploadPath + c.getString(c.getColumnIndex(Video.Media.DISPLAY_NAME));

                    } else if (mimeType.contains("audio")) {
                        String[] CONTENT_PROJECTION = { Audio.Media.DATA, Audio.Media.DISPLAY_NAME,
                                Audio.Media.MIME_TYPE, Audio.Media.SIZE };
                        Cursor c = getContentResolver().query(uri, CONTENT_PROJECTION, null, null, null);
                        c.moveToFirst();
                        int index = c.getColumnIndex(Audio.Media.DATA);
                        data = c.getString(index);
                        filePath = mUploadPath + c.getString(c.getColumnIndex(Audio.Media.DISPLAY_NAME));

                    } else {
                        Cursor cursor = getContentResolver().query(uri,
                                new String[] { MediaStore.MediaColumns.DISPLAY_NAME }, null, null, null);
                        cursor.moveToFirst();
                        int nameIndex = cursor.getColumnIndex(cursor.getColumnNames()[0]);
                        if (nameIndex >= 0) {
                            filePath = mUploadPath + cursor.getString(nameIndex);
                        }
                    }

                } else if (uri.getScheme().equals("file")) {
                    filePath = Uri.decode(uri.toString()).replace(uri.getScheme() + "://", "");
                    if (filePath.contains("mnt")) {
                        String splitedFilePath[] = filePath.split("/mnt");
                        filePath = splitedFilePath[1];
                    }
                    final File file = new File(filePath);
                    data = file.getAbsolutePath();
                    filePath = mUploadPath + file.getName();
                } else {
                    throw new SecurityException();
                }
                if (data == null) {
                    mRemoteCacheData.add(filePath);
                    CopyTmpFileAsyncTask copyTask = new CopyTmpFileAsyncTask(this);
                    Object[] params = { uri, filePath, mRemoteCacheData.size() - 1, getAccount().name,
                            getContentResolver() };
                    mNumCacheFile++;
                    showWaitingCopyDialog();
                    copyTask.execute(params);
                } else {
                    remote.add(filePath);
                    local.add(data);
                }
            } else {
                throw new SecurityException();
            }

            Intent intent = new Intent(getApplicationContext(), FileUploader.class);
            intent.putExtra(FileUploader.KEY_UPLOAD_TYPE, FileUploader.UPLOAD_MULTIPLE_FILES);
            intent.putExtra(FileUploader.KEY_LOCAL_FILE, local.toArray(new String[local.size()]));
            intent.putExtra(FileUploader.KEY_REMOTE_FILE, remote.toArray(new String[remote.size()]));
            intent.putExtra(FileUploader.KEY_ACCOUNT, getAccount());
            startService(intent);

            //Save the path to shared preferences
            SharedPreferences.Editor appPrefs = PreferenceManager
                    .getDefaultSharedPreferences(getApplicationContext()).edit();
            appPrefs.putString("last_upload_path", mUploadPath);
            appPrefs.apply();

            finish();
        }

    } catch (SecurityException e) {
        String message = String.format(getString(R.string.uploader_error_forbidden_content),
                getString(R.string.app_name));
        Toast.makeText(this, message, Toast.LENGTH_LONG).show();
    } catch (NullPointerException npe) {
        Log_OC.e(this.getClass().getName(), "Unknown error occurred. Message: " + npe.getLocalizedMessage());
    }
}

From source file:devcoin.wallet.ui.SendCoinsFragment.java

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

    receivingAddressView = (AutoCompleteTextView) view.findViewById(R.id.send_coins_receiving_address);
    receivingAddressView.setAdapter(new AutoCompleteAddressAdapter(activity, null));
    receivingAddressView.setOnFocusChangeListener(receivingAddressListener);
    receivingAddressView.addTextChangedListener(receivingAddressListener);

    receivingStaticView = view.findViewById(R.id.send_coins_receiving_static);
    receivingStaticAddressView = (TextView) view.findViewById(R.id.send_coins_receiving_static_address);
    receivingStaticLabelView = (TextView) view.findViewById(R.id.send_coins_receiving_static_label);

    receivingStaticView.setOnFocusChangeListener(new OnFocusChangeListener() {
        private ActionMode actionMode;

        @Override/*from w  w  w .j a va2s  . c  om*/
        public void onFocusChange(final View v, final boolean hasFocus) {
            if (hasFocus)
                actionMode = activity.startActionMode(new ReceivingAddressActionMode());
            else
                actionMode.finish();
        }
    });

    final CurrencyAmountView btcAmountView = (CurrencyAmountView) view.findViewById(R.id.send_coins_amount_btc);
    btcAmountView.setCurrencySymbol(btcShift == 0 ? Constants.CURRENCY_CODE_BTC : Constants.CURRENCY_CODE_MBTC);
    btcAmountView.setInputPrecision(btcShift == 0 ? Constants.BTC_MAX_PRECISION : Constants.MBTC_MAX_PRECISION);
    btcAmountView.setHintPrecision(btcPrecision);
    btcAmountView.setShift(btcShift);

    final CurrencyAmountView localAmountView = (CurrencyAmountView) view
            .findViewById(R.id.send_coins_amount_local);
    localAmountView.setInputPrecision(Constants.LOCAL_PRECISION);
    localAmountView.setHintPrecision(Constants.LOCAL_PRECISION);
    amountCalculatorLink = new CurrencyCalculatorLink(btcAmountView, localAmountView);

    bluetoothEnableView = (CheckBox) view.findViewById(R.id.send_coins_bluetooth_enable);
    bluetoothEnableView.setChecked(bluetoothAdapter != null && bluetoothAdapter.isEnabled());
    bluetoothEnableView.setOnCheckedChangeListener(new OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(final CompoundButton buttonView, final boolean isChecked) {
            if (isChecked && !bluetoothAdapter.isEnabled()) {
                // try to enable bluetooth
                startActivityForResult(new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE),
                        REQUEST_CODE_ENABLE_BLUETOOTH);
            }
        }
    });

    bluetoothMessageView = (TextView) view.findViewById(R.id.send_coins_bluetooth_message);

    sentTransactionView = (ListView) view.findViewById(R.id.send_coins_sent_transaction);
    sentTransactionListAdapter = new TransactionsListAdapter(activity, wallet, application.maxConnectedPeers(),
            false);
    sentTransactionView.setAdapter(sentTransactionListAdapter);

    viewGo = (Button) view.findViewById(R.id.send_coins_go);
    viewGo.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(final View v) {
            validateReceivingAddress(true);
            validateAmounts(true);

            if (everythingValid())
                handleGo();
        }
    });

    viewCancel = (Button) view.findViewById(R.id.send_coins_cancel);
    viewCancel.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(final View v) {
            if (state == State.INPUT)
                activity.setResult(Activity.RESULT_CANCELED);

            activity.finish();
        }
    });

    popupMessageView = (TextView) inflater.inflate(R.layout.send_coins_popup_message, container);

    popupAvailableView = inflater.inflate(R.layout.send_coins_popup_available, container);

    if (savedInstanceState != null) {
        restoreInstanceState(savedInstanceState);
    } else {
        final Intent intent = activity.getIntent();
        final String action = intent.getAction();
        final Uri intentUri = intent.getData();
        final String scheme = intentUri != null ? intentUri.getScheme() : null;

        if ((Intent.ACTION_VIEW.equals(action) || NfcAdapter.ACTION_NDEF_DISCOVERED.equals(action))
                && intentUri != null && "devcoin".equals(scheme))
            initStateFromBitcoinUri(intentUri);
        else if (intent.hasExtra(SendCoinsActivity.INTENT_EXTRA_ADDRESS))
            initStateFromIntentExtras(intent.getExtras());
    }

    return view;
}

From source file:com.google.android.apps.muzei.provider.MuzeiProvider.java

private File getCacheFileForArtworkUri(Uri artworkUri) {
    Context context = getContext();
    if (context == null || artworkUri == null) {
        return null;
    }//from www .ja v  a 2 s .c  o m
    File directory = new File(context.getFilesDir(), "artwork");
    if (!directory.exists() && !directory.mkdirs()) {
        return null;
    }
    String[] projection = { BaseColumns._ID, MuzeiContract.Artwork.COLUMN_NAME_IMAGE_URI,
            MuzeiContract.Artwork.COLUMN_NAME_TOKEN };
    Cursor data = queryArtwork(artworkUri, projection, null, null, null);
    if (data == null) {
        return null;
    }
    if (!data.moveToFirst()) {
        Log.e(TAG, "Invalid artwork URI " + artworkUri);
        return null;
    }
    // While normally we'd use data.getLong(), we later need this as a String so the automatic conversion helps here
    String id = data.getString(0);
    String imageUri = data.getString(1);
    String token = data.getString(2);
    data.close();
    if (TextUtils.isEmpty(imageUri) && TextUtils.isEmpty(token)) {
        return new File(directory, id);
    }
    // Otherwise, create a unique filename based on the imageUri and token
    StringBuilder filename = new StringBuilder();
    if (!TextUtils.isEmpty(imageUri)) {
        Uri uri = Uri.parse(imageUri);
        filename.append(uri.getScheme()).append("_").append(uri.getHost()).append("_");
        String encodedPath = uri.getEncodedPath();
        if (!TextUtils.isEmpty(encodedPath)) {
            int length = encodedPath.length();
            if (length > 60) {
                encodedPath = encodedPath.substring(length - 60);
            }
            encodedPath = encodedPath.replace('/', '_');
            filename.append(encodedPath).append("_");
        }
    }
    // Use the imageUri if available, otherwise use the token
    String unique = !TextUtils.isEmpty(imageUri) ? imageUri : token;
    try {
        MessageDigest md = MessageDigest.getInstance("MD5");
        md.update(unique.getBytes("UTF-8"));
        byte[] digest = md.digest();
        for (byte b : digest) {
            if ((0xff & b) < 0x10) {
                filename.append("0").append(Integer.toHexString((0xFF & b)));
            } else {
                filename.append(Integer.toHexString(0xFF & b));
            }
        }
    } catch (NoSuchAlgorithmException | UnsupportedEncodingException e) {
        filename.append(unique.hashCode());
    }
    return new File(directory, filename.toString());
}

From source file:hashengineering.digitalcoin.wallet.ui.SendCoinsFragment.java

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

    receivingAddressView = (AutoCompleteTextView) view.findViewById(R.id.send_coins_receiving_address);
    receivingAddressView.setAdapter(new AutoCompleteAddressAdapter(activity, null));
    receivingAddressView.setOnFocusChangeListener(receivingAddressListener);
    receivingAddressView.addTextChangedListener(receivingAddressListener);

    receivingStaticView = view.findViewById(R.id.send_coins_receiving_static);
    receivingStaticAddressView = (TextView) view.findViewById(R.id.send_coins_receiving_static_address);
    receivingStaticLabelView = (TextView) view.findViewById(R.id.send_coins_receiving_static_label);

    receivingStaticView.setOnFocusChangeListener(new OnFocusChangeListener() {
        private ActionMode actionMode;

        @Override/*w  w w.  java 2s  .com*/
        public void onFocusChange(final View v, final boolean hasFocus) {
            if (hasFocus)
                actionMode = activity.startActionMode(new ReceivingAddressActionMode());
            else
                actionMode.finish();
        }
    });

    final CurrencyAmountView btcAmountView = (CurrencyAmountView) view.findViewById(R.id.send_coins_amount_btc);
    btcAmountView.setCurrencySymbol(Constants.CURRENCY_CODE_BITCOIN);
    btcAmountView.setHintPrecision(btcPrecision);

    final CurrencyAmountView localAmountView = (CurrencyAmountView) view
            .findViewById(R.id.send_coins_amount_local);
    localAmountView.setHintPrecision(Constants.LOCAL_PRECISION);
    amountCalculatorLink = new CurrencyCalculatorLink(btcAmountView, localAmountView);

    bluetoothEnableView = (CheckBox) view.findViewById(R.id.send_coins_bluetooth_enable);
    bluetoothEnableView.setChecked(bluetoothAdapter != null && bluetoothAdapter.isEnabled());
    bluetoothEnableView.setOnCheckedChangeListener(new OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(final CompoundButton buttonView, final boolean isChecked) {
            if (isChecked && !bluetoothAdapter.isEnabled()) {
                // try to enable bluetooth
                startActivityForResult(new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE),
                        REQUEST_CODE_ENABLE_BLUETOOTH);
            }
        }
    });

    bluetoothMessageView = (TextView) view.findViewById(R.id.send_coins_bluetooth_message);

    sentTransactionView = (ListView) view.findViewById(R.id.send_coins_sent_transaction);
    sentTransactionListAdapter = new TransactionsListAdapter(activity, wallet, application.maxConnectedPeers(),
            false);
    sentTransactionView.setAdapter(sentTransactionListAdapter);

    viewGo = (Button) view.findViewById(R.id.send_coins_go);
    viewGo.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(final View v) {
            validateReceivingAddress(true);
            validateAmounts(true);

            if (everythingValid())
                handleGo();
        }
    });

    viewCancel = (Button) view.findViewById(R.id.send_coins_cancel);
    viewCancel.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(final View v) {
            if (state == State.INPUT)
                activity.setResult(Activity.RESULT_CANCELED);

            activity.finish();
        }
    });

    popupMessageView = (TextView) inflater.inflate(R.layout.send_coins_popup_message, container);

    popupAvailableView = inflater.inflate(R.layout.send_coins_popup_available, container);

    if (savedInstanceState != null) {
        restoreInstanceState(savedInstanceState);
    } else {
        final Intent intent = activity.getIntent();
        final String action = intent.getAction();
        final Uri intentUri = intent.getData();
        final String scheme = intentUri != null ? intentUri.getScheme() : null;

        if ((Intent.ACTION_VIEW.equals(action) || NfcAdapter.ACTION_NDEF_DISCOVERED.equals(action))
                && intentUri != null && "bitcoin".equals(scheme))
            initStateFromBitcoinUri(intentUri);
        else if (intent.hasExtra(SendCoinsActivity.INTENT_EXTRA_ADDRESS))
            initStateFromIntentExtras(intent.getExtras());
    }

    return view;
}

From source file:org.apache.cordova.file.FileUtils.java

@Override
public Uri remapUri(Uri uri) {
    // Remap only cdvfile: URLs (not content:).
    if (!LocalFilesystemURL.FILESYSTEM_PROTOCOL.equals(uri.getScheme())) {
        return null;
    }/* w  w w .j  a  va 2s  .  c o m*/
    try {
        LocalFilesystemURL inputURL = LocalFilesystemURL.parse(uri);
        Filesystem fs = this.filesystemForURL(inputURL);
        if (fs == null) {
            return null;
        }
        String path = fs.filesystemPathForURL(inputURL);
        if (path != null) {
            return Uri.parse("file://" + fs.filesystemPathForURL(inputURL));
        }
        return null;
    } catch (IllegalArgumentException e) {
        return null;
    }
}

From source file:com.silverpop.engage.deeplinking.EngageDeepLinkManager.java

Uri trimDeeplink(Uri deeplink) {
    String host = deeplink.getHost();
    List<String> pathSegments = new LinkedList<String>(deeplink.getPathSegments());
    if (pathSegments.isEmpty()) {
        // trim off host
        if (!TextUtils.isEmpty(host)) {
            host = null;/*from  w w w.j  a v  a  2  s. co  m*/
        }
    }

    for (int i = pathSegments.size() - 1; i >= 0; i--) {
        // remove trailing slashes
        if (pathSegments.get(i).equals("/")) {
            pathSegments.remove(i);
        } else {
            pathSegments.remove(i);
            break;
        }
    }

    String pathString = "";
    for (int i = 0; i < pathSegments.size(); i++) {
        pathString += "/";
        pathString += pathSegments.get(i);
    }

    Uri.Builder builder = new Uri.Builder();
    builder.scheme(deeplink.getScheme());
    builder.path(pathString);
    builder.query(deeplink.getQuery());

    return builder.build();
}

From source file:net.usecredits.wallet.ui.SendCoinsFragment.java

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

    receivingAddressView = (AutoCompleteTextView) view.findViewById(R.id.send_coins_receiving_address);
    receivingAddressView.setAdapter(new AutoCompleteAddressAdapter(activity, null));
    receivingAddressView.setOnFocusChangeListener(receivingAddressListener);
    receivingAddressView.addTextChangedListener(receivingAddressListener);

    receivingStaticView = view.findViewById(R.id.send_coins_receiving_static);
    receivingStaticAddressView = (TextView) view.findViewById(R.id.send_coins_receiving_static_address);
    receivingStaticLabelView = (TextView) view.findViewById(R.id.send_coins_receiving_static_label);

    receivingStaticView.setOnFocusChangeListener(new OnFocusChangeListener() {
        private ActionMode actionMode;

        @Override/* w ww  . j  av  a  2  s .c  o m*/
        public void onFocusChange(final View v, final boolean hasFocus) {
            if (hasFocus)
                actionMode = activity.startActionMode(new ReceivingAddressActionMode());
            else
                actionMode.finish();
        }
    });

    final CurrencyAmountView btcAmountView = (CurrencyAmountView) view.findViewById(R.id.send_coins_amount_btc);
    btcAmountView.setCurrencySymbol(btcShift == 0 ? Constants.CURRENCY_CODE_BTC : Constants.CURRENCY_CODE_MBTC);
    btcAmountView.setInputPrecision(btcShift == 0 ? Constants.BTC_MAX_PRECISION : Constants.MBTC_MAX_PRECISION);
    btcAmountView.setHintPrecision(btcPrecision);
    btcAmountView.setShift(btcShift);

    final CurrencyAmountView localAmountView = (CurrencyAmountView) view
            .findViewById(R.id.send_coins_amount_local);
    localAmountView.setInputPrecision(Constants.LOCAL_PRECISION);
    localAmountView.setHintPrecision(Constants.LOCAL_PRECISION);
    amountCalculatorLink = new CurrencyCalculatorLink(btcAmountView, localAmountView);

    bluetoothEnableView = (CheckBox) view.findViewById(R.id.send_coins_bluetooth_enable);
    bluetoothEnableView.setChecked(bluetoothAdapter != null && bluetoothAdapter.isEnabled());
    bluetoothEnableView.setOnCheckedChangeListener(new OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(final CompoundButton buttonView, final boolean isChecked) {
            if (isChecked && !bluetoothAdapter.isEnabled()) {
                // try to enable bluetooth
                startActivityForResult(new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE),
                        REQUEST_CODE_ENABLE_BLUETOOTH);
            }
        }
    });

    bluetoothMessageView = (TextView) view.findViewById(R.id.send_coins_bluetooth_message);

    sentTransactionView = (ListView) view.findViewById(R.id.send_coins_sent_transaction);
    sentTransactionListAdapter = new TransactionsListAdapter(activity, wallet, application.maxConnectedPeers(),
            false);
    sentTransactionView.setAdapter(sentTransactionListAdapter);

    viewGo = (Button) view.findViewById(R.id.send_coins_go);
    viewGo.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(final View v) {
            validateReceivingAddress(true);
            validateAmounts(true);

            if (everythingValid())
                handleGo();
        }
    });

    viewCancel = (Button) view.findViewById(R.id.send_coins_cancel);
    viewCancel.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(final View v) {
            if (state == State.INPUT)
                activity.setResult(Activity.RESULT_CANCELED);

            activity.finish();
        }
    });

    popupMessageView = (TextView) inflater.inflate(R.layout.send_coins_popup_message, container);

    popupAvailableView = inflater.inflate(R.layout.send_coins_popup_available, container);

    if (savedInstanceState != null) {
        restoreInstanceState(savedInstanceState);
    } else {
        final Intent intent = activity.getIntent();
        final String action = intent.getAction();
        final Uri intentUri = intent.getData();
        final String scheme = intentUri != null ? intentUri.getScheme() : null;

        if ((Intent.ACTION_VIEW.equals(action) || NfcAdapter.ACTION_NDEF_DISCOVERED.equals(action))
                && intentUri != null && "bitcoin".equals(scheme))
            initStateFromBitcoinUri(intentUri);
        else if (intent.hasExtra(SendCoinsActivity.INTENT_EXTRA_ADDRESS))
            initStateFromIntentExtras(intent.getExtras());
    }

    return view;
}