Example usage for android.net Uri getPort

List of usage examples for android.net Uri getPort

Introduction

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

Prototype

public abstract int getPort();

Source Link

Document

Gets the port from the authority for this URI.

Usage

From source file:org.path.episample.android.activities.MainMenuActivity.java

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

    // android.os.Debug.waitForDebugger();

    mPropertyManager = new PropertyManager(this);
    mWifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);

    // must be at the beginning of any activity that can be called from an
    // external intent
    setAppName("survey");
    Uri uri = getIntent().getData();
    Uri formUri = null;/*from   w w w  .  j  a v  a  2  s  .  co m*/

    if (uri != null) {
        // initialize to the URI, then we will customize further based upon the
        // savedInstanceState...
        final Uri uriFormsProvider = FormsProviderAPI.CONTENT_URI;
        final Uri uriWebView = UrlUtils.getWebViewContentUri(this);
        if (uri.getScheme().equalsIgnoreCase(uriFormsProvider.getScheme())
                && uri.getAuthority().equalsIgnoreCase(uriFormsProvider.getAuthority())) {
            List<String> segments = uri.getPathSegments();
            if (segments != null && segments.size() == 1) {
                String appName = segments.get(0);
                setAppName(appName);
            } else if (segments != null && segments.size() >= 2) {
                String appName = segments.get(0);
                setAppName(appName);
                formUri = Uri.withAppendedPath(Uri.withAppendedPath(uriFormsProvider, appName),
                        segments.get(1));
            } else {
                assignContentView();
                createErrorDialog(getString(R.string.invalid_uri_expecting_n_segments, uri.toString(), 2),
                        EXIT);
                return;
            }
        } else if (uri.getScheme().equals(uriWebView.getScheme())
                && uri.getAuthority().equals(uriWebView.getAuthority())
                && uri.getPort() == uriWebView.getPort()) {
            List<String> segments = uri.getPathSegments();
            if (segments != null && segments.size() == 1) {
                String appName = segments.get(0);
                setAppName(appName);
            } else {
                assignContentView();
                createErrorDialog(getString(R.string.invalid_uri_expecting_one_segment, uri.toString()), EXIT);
                return;
            }

        } else {
            assignContentView();
            createErrorDialog(getString(R.string.unrecognized_uri, uri.toString(), uriWebView.toString(),
                    uriFormsProvider.toString()), EXIT);
            return;
        }
    }

    if (savedInstanceState != null) {
        // if appName is explicitly set, use it...
        setAppName(savedInstanceState.containsKey(APP_NAME) ? savedInstanceState.getString(APP_NAME)
                : getAppName());

        if (savedInstanceState.containsKey(CONFLICT_TABLES)) {
            mConflictTables = savedInstanceState.getBundle(CONFLICT_TABLES);
        }
    }

    WebLogger.getLogger(getAppName()).i(t, "Starting up, creating directories");
    try {
        String appName = getAppName();
        if (appName != null && appName.length() != 0) {
            ODKFileUtils.verifyExternalStorageAvailability();
            ODKFileUtils.assertDirectoryStructure(appName);
        }
    } catch (RuntimeException e) {
        assignContentView();
        createErrorDialog(e.getMessage(), EXIT);
        return;
    }

    if (savedInstanceState != null) {
        // if we are restoring, assume that initialization has already occurred.

        pageWaitingForData = savedInstanceState.containsKey(PAGE_WAITING_FOR_DATA)
                ? savedInstanceState.getString(PAGE_WAITING_FOR_DATA)
                : null;
        pathWaitingForData = savedInstanceState.containsKey(PATH_WAITING_FOR_DATA)
                ? savedInstanceState.getString(PATH_WAITING_FOR_DATA)
                : null;
        actionWaitingForData = savedInstanceState.containsKey(ACTION_WAITING_FOR_DATA)
                ? savedInstanceState.getString(ACTION_WAITING_FOR_DATA)
                : null;

        currentFragment = ScreenList.valueOf(savedInstanceState.containsKey(CURRENT_FRAGMENT)
                ? savedInstanceState.getString(CURRENT_FRAGMENT)
                : currentFragment.name());

        if (savedInstanceState.containsKey(FORM_URI)) {
            FormIdStruct newForm = FormIdStruct.retrieveFormIdStruct(getContentResolver(),
                    Uri.parse(savedInstanceState.getString(FORM_URI)));
            if (newForm != null) {
                setAppName(newForm.appName);
                setCurrentForm(newForm);
            }
        }
        setInstanceId(savedInstanceState.containsKey(INSTANCE_ID) ? savedInstanceState.getString(INSTANCE_ID)
                : getInstanceId());
        setUploadTableId(
                savedInstanceState.containsKey(UPLOAD_TABLE_ID) ? savedInstanceState.getString(UPLOAD_TABLE_ID)
                        : getUploadTableId());

        String tmpScreenPath = savedInstanceState.containsKey(SCREEN_PATH)
                ? savedInstanceState.getString(SCREEN_PATH)
                : getScreenPath();
        String tmpControllerState = savedInstanceState.containsKey(CONTROLLER_STATE)
                ? savedInstanceState.getString(CONTROLLER_STATE)
                : getControllerState();
        setSectionScreenState(tmpScreenPath, tmpControllerState);

        setAuxillaryHash(
                savedInstanceState.containsKey(AUXILLARY_HASH) ? savedInstanceState.getString(AUXILLARY_HASH)
                        : getAuxillaryHash());

        if (savedInstanceState.containsKey(SESSION_VARIABLES)) {
            sessionVariables = savedInstanceState.getBundle(SESSION_VARIABLES);
        }

        if (savedInstanceState.containsKey(SECTION_STATE_SCREEN_HISTORY)) {
            sectionStateScreenHistory = savedInstanceState.getParcelableArrayList(SECTION_STATE_SCREEN_HISTORY);
        }
    } else if (formUri != null) {
        // request specifies a specific formUri -- try to open that
        FormIdStruct newForm = FormIdStruct.retrieveFormIdStruct(getContentResolver(), formUri);
        if (newForm == null) {
            // can't find it -- launch the initialization dialog to hopefully
            // discover it.
            WebLogger.getLogger(getAppName()).i(t, "onCreate -- calling setRunInitializationTask");
            Survey.getInstance().setRunInitializationTask(getAppName());
            currentFragment = ScreenList.WEBKIT;
        } else {
            transitionToFormHelper(uri, newForm);
        }
    }

    assignContentView();
}

From source file:com.irccloud.android.activity.MainActivity.java

private boolean open_uri(Uri uri) {
    if (uri != null && conn != null && conn.ready) {
        launchURI = null;/*from  w w w . j a v a  2s.co  m*/
        ServersDataSource.Server s = null;
        try {
            if (uri.getHost().equals("cid")) {
                s = ServersDataSource.getInstance().getServer(Integer.parseInt(uri.getPathSegments().get(0)));
            }
        } catch (NumberFormatException e) {

        }
        if (s == null) {
            if (uri.getPort() > 0)
                s = ServersDataSource.getInstance().getServer(uri.getHost(), uri.getPort());
            else if (uri.getScheme() != null && uri.getScheme().equalsIgnoreCase("ircs"))
                s = ServersDataSource.getInstance().getServer(uri.getHost(), true);
            else
                s = ServersDataSource.getInstance().getServer(uri.getHost());
        }

        if (s != null) {
            if (uri.getPath() != null && uri.getPath().length() > 1) {
                String key = null;
                String channel = uri.getLastPathSegment();
                if (channel.contains(",")) {
                    key = channel.substring(channel.indexOf(",") + 1);
                    channel = channel.substring(0, channel.indexOf(","));
                }
                BuffersDataSource.Buffer b = BuffersDataSource.getInstance().getBufferByName(s.cid, channel);
                if (b != null) {
                    server = null;
                    return open_bid(b.bid);
                } else {
                    onBufferSelected(-1);
                    title.setText(channel);
                    getSupportActionBar().setTitle(channel);
                    bufferToOpen = channel;
                    conn.join(s.cid, channel, key);
                }
                return true;
            } else {
                BuffersDataSource.Buffer b = BuffersDataSource.getInstance().getBufferByName(s.cid, "*");
                if (b != null)
                    return open_bid(b.bid);
            }
        } else {
            if (!getResources().getBoolean(R.bool.isTablet)) {
                Intent i = new Intent(this, EditConnectionActivity.class);
                i.putExtra("hostname", uri.getHost());
                if (uri.getPort() > 0)
                    i.putExtra("port", uri.getPort());
                else if (uri.getScheme().equalsIgnoreCase("ircs"))
                    i.putExtra("port", 6697);
                if (uri.getPath() != null && uri.getPath().length() > 1)
                    i.putExtra("channels", uri.getPath().substring(1).replace(",", " "));
                startActivity(i);
            } else {
                EditConnectionFragment connFragment = new EditConnectionFragment();
                connFragment.default_hostname = uri.getHost();
                if (uri.getPort() > 0)
                    connFragment.default_port = uri.getPort();
                else if (uri.getScheme().equalsIgnoreCase("ircs"))
                    connFragment.default_port = 6697;
                if (uri.getPath() != null && uri.getPath().length() > 1)
                    connFragment.default_channels = uri.getPath().substring(1).replace(",", " ");
                connFragment.show(getSupportFragmentManager(), "addnetwork");
            }
            return true;
        }
    }
    return false;
}