Example usage for android.net Uri getQueryParameter

List of usage examples for android.net Uri getQueryParameter

Introduction

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

Prototype

@Nullable
public String getQueryParameter(String key) 

Source Link

Document

Searches the query string for the first value with the given key.

Usage

From source file:com.yeldi.yeldibazaar.AppDetails.java

@Override
protected void onCreate(Bundle savedInstanceState) {

    if (PreferenceManager.getDefaultSharedPreferences(this).getBoolean("lightTheme", false))
        setTheme(R.style.AppThemeLight);

    super.onCreate(savedInstanceState);
    ActionBarCompat abCompat = ActionBarCompat.create(this);
    abCompat.setDisplayHomeAsUpEnabled(true);

    setContentView(R.layout.appdetails);

    Intent i = getIntent();//  ww w.j  av  a 2  s. c  o  m
    appid = "";
    Uri data = getIntent().getData();
    if (data != null) {
        if (data.isHierarchical()) {
            if (data.getHost().equals("details")) {
                // market://details?id=app.id
                appid = data.getQueryParameter("id");
            } else {
                // https://f-droid.org/app/app.id
                appid = data.getLastPathSegment();
            }
        } else {
            // fdroid.app:app.id (old scheme)
            appid = data.getEncodedSchemeSpecificPart();
        }
        Log.d("FDroid", "AppDetails launched from link, for '" + appid + "'");
    } else if (!i.hasExtra("appid")) {
        Log.d("FDroid", "No application ID in AppDetails!?");
    } else {
        appid = i.getStringExtra("appid");
    }

    // Set up the list...
    headerView = new LinearLayout(this);
    ListView lv = (ListView) findViewById(android.R.id.list);
    lv.addHeaderView(headerView);
    ApkListAdapter la = new ApkListAdapter(this, null);
    setListAdapter(la);

    mPm = getPackageManager();
    // Get the preferences we're going to use in this Activity...
    AppDetails old = (AppDetails) getLastNonConfigurationInstance();
    if (old != null) {
        copyState(old);
    } else {
        if (!reset()) {
            finish();
            return;
        }
        resetRequired = false;
    }
    startViews();

}

From source file:com.fa.mastodon.activity.LoginActivity.java

@Override
protected void onStart() {
    super.onStart();
    /* Check if we are resuming during authorization by seeing if the intent contains the
     * redirect that was given to the server. If so, its response is here! */
    Uri uri = getIntent().getData();
    String redirectUri = getOauthRedirectUri();

    preferences = getSharedPreferences(getString(R.string.preferences_file_key), Context.MODE_PRIVATE);

    if (preferences.getString("accessToken", null) != null && preferences.getString("domain", null) != null) {
        // We are already logged in, go to MainActivity
        Intent intent = new Intent(this, MainActivity.class);
        startActivity(intent);// w  w  w . ja  va 2 s  . co m
        finish();
        return;
    }

    if (uri != null && uri.toString().startsWith(redirectUri)) {
        // This should either have returned an authorization code or an error.
        String code = uri.getQueryParameter("code");
        String error = uri.getQueryParameter("error");

        if (code != null) {
            /* During the redirect roundtrip this Activity usually dies, which wipes out the
             * instance variables, so they have to be recovered from where they were saved in
             * SharedPreferences. */
            domain = preferences.getString("domain", null);
            clientId = preferences.getString("clientId", null);
            clientSecret = preferences.getString("clientSecret", null);

            setLoading(true);
            /* Since authorization has succeeded, the final step to log in is to exchange
             * the authorization code for an access token. */
            Callback<AccessToken> callback = new Callback<AccessToken>() {
                @Override
                public void onResponse(Call<AccessToken> call, Response<AccessToken> response) {
                    if (response.isSuccessful()) {
                        onLoginSuccess(response.body().accessToken);
                    } else {
                        setLoading(false);

                        editText.setError(getString(R.string.error_retrieving_oauth_token));
                        Log.e(TAG, String.format("%s %s", getString(R.string.error_retrieving_oauth_token),
                                response.message()));
                    }
                }

                @Override
                public void onFailure(Call<AccessToken> call, Throwable t) {
                    setLoading(false);
                    editText.setError(getString(R.string.error_retrieving_oauth_token));
                    Log.e(TAG, String.format("%s %s", getString(R.string.error_retrieving_oauth_token),
                            t.getMessage()));
                }
            };

            getApiFor(domain).fetchOAuthToken(clientId, clientSecret, redirectUri, code, "authorization_code")
                    .enqueue(callback);
        } else if (error != null) {
            /* Authorization failed. Put the error response where the user can read it and they
             * can try again. */
            setLoading(false);
            editText.setError(getString(R.string.error_authorization_denied));
            Log.e(TAG, getString(R.string.error_authorization_denied) + error);
        } else {
            setLoading(false);
            // This case means a junk response was received somehow.
            editText.setError(getString(R.string.error_authorization_unknown));
        }
    }
}

From source file:com.zhongsou.souyue.activity.SplashActivity.java

/**
 * ?/*  ww w  . jav a  2 s . co m*/
 */
private void initFromWX() {
    Intent intent = this.getIntent();
    if (null == intent)
        return;
    String str = intent.getDataString() == null ? "" : intent.getDataString();
    try {
        if (ConfigApi.isSouyue()) {
            str = URLDecoder.decode(str, "utf-8");
        }
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    }
    Log.i("", "splash : " + str);
    if ((ShareApi.WEIXIN_APP_ID.concat("://slot")).equals(str)) {
        jumpType = JUMP_TYPE_SLOT;
        Log.i("slot", "initFromWX");
        return;
    } else if ((ShareApi.WEIXIN_APP_ID.concat("://zero")).equals(str)) {
        jumpType = JUMP_TYPE_ZERO;
        return;
    } else if (str.startsWith(ShareApi.WEIXIN_APP_ID + "://" + JUMP_TYPE_INTERESTCARD)) {
        jumpType = JUMP_TYPE_INTERESTCARD;
        CircleResponseResultItem item = new CircleResponseResultItem();
        if (!ConfigApi.isSouyue()) {
            try {
                str = URLDecoder.decode(str, "utf-8");
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
            }
        }
        Uri uri = Uri.parse(str);
        if (uri != null) {
            String interest_id = uri.getQueryParameter("circleId");
            try {
                item.setInterest_id(Long.valueOf(interest_id));
            } catch (NumberFormatException e) {
                e.printStackTrace();
            }
            pushInfo.setInterestBlog(item);
        }
        return;
    } else if (str.startsWith(ShareApi.WEIXIN_APP_ID.concat("://lingpai"))) {
        jumpType = JUMP_TYPE_LINGPAI;
        url = str.substring(str.indexOf("http"), str.length());
        return;
    } else if (str.startsWith((ShareApi.WEIXIN_APP_ID.concat("://interest")))) {
        jumpType = JUMP_TYPE_INTEREST;
        if (!ConfigApi.isSouyue()) {
            try {
                str = URLDecoder.decode(str, "utf-8");
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
            }
        }
        wrapInterest(str);
        return;
    } else if (str.startsWith((ShareApi.WEIXIN_APP_ID.concat("://galleryNews")))) {//
        jumpType = JUMP_TYPE_GALLERYNEWS;
        String wxStr = ShareApi.WEIXIN_APP_ID.concat("://galleryNews");
        str = str.substring(0, wxStr.length()) + "?" + str.substring(wxStr.length() + 1);
        wrapGalleryNews(str);
        return;
    }

    String[] st = str.split("//");// wx360a9785675a8653://
    Log.i(LOG_TAG, str);
    if (st.length >= 2) {

        if (st.length == 3 && isMatchUrl(st[2], "opentype=(\\w{8})", "emptyWeb")
                && isMatchUrl(st[2], "source=(\\w{6})", "search")) {//??
            String[] resultStr = st[2].split("\\?");
            String[] param = resultStr[1].split("&");
            for (int i = 0; i < param.length; i++) {
                String[] s = param[i].split("=");
                if (s.length >= 2) {
                    if ("opentype".equals(s[0]) && "emptyWeb".equals(s[1])) {
                        keyword = s[1];//keyword
                    }
                    if ("source".equals(s[0]) && "search".equals(s[1])) {
                        srpId = s[1];//srpId??
                    }
                }
            }
            if (str.contains("url=")) {
                if (str.indexOf("url=") + 4 < str.length()) {
                    url = str.substring(str.indexOf("url=") + 4, str.length());
                }
                Log.i("", "url : " + url);
            }
            return;
        }
        if (!ConfigApi.isSouyue()) {
            try {
                st[1] = URLDecoder.decode(st[1], "utf-8");
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
            }
        }
        String[] dataStr = st[1].split("&");// keyword=ddd&srpId=sfsfsf&url=
        if (dataStr.length >= 3) {
            String[] s = dataStr[0].split("=");
            if (s.length >= 2)
                keyword = s[1];
            s = dataStr[1].split("=");
            if (s.length >= 2)
                srpId = s[1];
            if (!ConfigApi.isSouyue()) {
                try {
                    str = URLDecoder.decode(str, "utf-8");
                } catch (UnsupportedEncodingException e) {
                    e.printStackTrace();
                }
            }
            if (str.contains("&url=")) {
                if (str.indexOf("&url=") + 5 < str.length()) {
                    url = str.substring(str.indexOf("&url=") + 5, str.length());
                    if (!ConfigApi.isSouyue()) {
                        try {
                            url = URLDecoder.decode(url, "utf-8");
                        } catch (UnsupportedEncodingException e) {
                            e.printStackTrace();
                        }
                    }
                    // add by trade
                    if (url.contains("opentype=src")) {
                        g = "0";
                        if (url.contains("md5")) {
                            md5 = (url.split("md5=")[1]).split("&")[0];
                        }
                    }
                }
                Log.i("", "url : " + url);
            }
        } else if (dataStr.length >= 2) {
            String[] s = dataStr[0].split("=");
            if (s.length >= 2)
                keyword = s[1];
            s = dataStr[1].split("=");
            if (s.length >= 2)
                srpId = s[1];

        } else {
            String[] s = dataStr[0].split("=");
            if (s.length >= 2)
                keyword = s[1];
        }
    } else {
        pushInfo = null;
    }
}

From source file:de.enlightened.peris.IntroScreen.java

@SuppressLint("NewApi")
public final void onCreate(final Bundle savedInstanceState) {
    this.dbHelper = new PerisDBHelper(this);
    final Bundle bundle = getIntent().getExtras();
    if (bundle != null) {
        if (bundle.containsKey("server_id")) {
            if (bundle.getString("server_id") != null) {

                this.incomingShortcut = true;
                this.shortcutServerId = bundle.getString("server_id");
            }/*from   ww  w  . j ava 2 s .  c om*/
        }
    }

    final PerisApp app = (PerisApp) getApplication();
    app.initSession();

    startService(new Intent(this, MailService.class));
    this.initDatabase();

    final SharedPreferences appPreferences = getSharedPreferences("prefs", 0);

    this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);

    final SharedPreferences.Editor editor = appPreferences.edit();
    editor.putString("server_address", getString(R.string.server_location));
    editor.commit();

    final String backgroundColor = app.getSession().getServer().serverColor;

    ThemeSetter.setTheme(this, backgroundColor);

    super.onCreate(savedInstanceState);

    ThemeSetter.setActionBar(this, backgroundColor);

    //Track app analytics
    this.ah = ((PerisApp) getApplication()).getAnalyticsHelper();
    this.ah.trackScreen(getString(R.string.app_name) + " v" + getString(R.string.app_version) + " for Android",
            true);

    setContentView(R.layout.intro_screen);

    this.serverInputter = (EditText) findViewById(R.id.intro_screen_add_server_box);

    final Button serverAdder = (Button) findViewById(R.id.intro_screen_submit_new_server);

    serverAdder.setOnClickListener(new View.OnClickListener() {

        @SuppressWarnings("checkstyle:requirethis")
        public void onClick(final View v) {

            if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB) {
                new ServerValidationTask().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR,
                        serverInputter.getText().toString().trim());
            } else {
                new ServerValidationTask().execute(serverInputter.getText().toString().trim());
            }

        }
    });

    this.lvServers = (ListView) findViewById(R.id.intro_screen_server_list);
    this.gvServers = (GridView) findViewById(R.id.intro_screen_server_grid);

    if (this.lvServers == null) {
        registerForContextMenu(this.gvServers);
        this.gvServers.setOnItemClickListener(new OnItemClickListener() {
            @SuppressWarnings("checkstyle:requirethis")
            public void onItemClick(final AdapterView<?> parent, final View view, final int position,
                    final long id) {
                final Server server = serverList.get(position);
                connectToServer(server);
            }
        });
    } else {
        this.lvServers.setDivider(null);
        registerForContextMenu(this.lvServers);

        this.lvServers.setOnItemClickListener(new OnItemClickListener() {
            @SuppressWarnings("checkstyle:requirethis")
            public void onItemClick(final AdapterView<?> parent, final View view, final int position,
                    final long id) {
                final Server server = serverList.get(position);
                connectToServer(server);
            }
        });
    }

    final TextView tvTapaShoutout = (TextView) findViewById(R.id.intro_screen_app_title);
    tvTapaShoutout.setOnClickListener(new View.OnClickListener() {

        public void onClick(final View v) {
            final Intent browserIntent = new Intent(Intent.ACTION_VIEW,
                    Uri.parse("https://github.com/McNetic/peris"));
            startActivity(browserIntent);
        }
    });

    //Check for incoming link from tapatalk :-)
    String host = "";

    final Uri data = getIntent().getData();

    if (data != null) {
        host = data.getHost();
        this.stealingType = data.getQueryParameter("location");

        if (this.stealingType == null) {
            this.stealingType = "0";
        } else {
            if (this.stealingType.contentEquals("forum")) {
                final String forumId = data.getQueryParameter("fid");

                if (forumId == null) {
                    this.stealingLocation = "0";
                } else {
                    this.stealingLocation = forumId;
                }
            }

            if (this.stealingType.contentEquals("topic")) {
                final String topicId = data.getQueryParameter("tid");

                if (topicId == null) {
                    this.stealingLocation = "0";
                } else {
                    this.stealingLocation = topicId;
                }
            }
        }

    }

    if (host.length() > 0) {
        this.linkToSteal = host;
        this.stealingLink = true;
        return;
    }

}

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

private boolean setFragment(final Uri uri) {
    final Bundle extras = getIntent().getExtras();
    Fragment fragment = null;//www  .  ja v  a  2 s . c  om
    if (uri != null) {
        final Bundle bundle = new Bundle();
        if (extras != null) {
            bundle.putAll(extras);
        }
        switch (matchLinkId(uri)) {
        case LINK_ID_STATUS: {
            setTitle(R.string.view_status);
            fragment = new StatusFragment();
            final String param_status_id = uri.getQueryParameter(QUERY_PARAM_STATUS_ID);
            bundle.putLong(INTENT_KEY_STATUS_ID, parseLong(param_status_id));
            break;
        }
        case LINK_ID_USER: {
            setTitle(R.string.view_user_profile);
            fragment = new UserProfileFragment();
            final String param_screen_name = uri.getQueryParameter(QUERY_PARAM_SCREEN_NAME);
            final String param_user_id = uri.getQueryParameter(QUERY_PARAM_USER_ID);
            if (!isNullOrEmpty(param_screen_name)) {
                bundle.putString(INTENT_KEY_SCREEN_NAME, param_screen_name);
            }
            if (!isNullOrEmpty(param_user_id)) {
                bundle.putLong(INTENT_KEY_USER_ID, parseLong(param_user_id));
            }
            break;
        }
        case LINK_ID_USER_TIMELINE: {
            setTitle(R.string.tweets);
            fragment = new UserTimelineFragment();
            final String param_screen_name = uri.getQueryParameter(QUERY_PARAM_SCREEN_NAME);
            final String param_user_id = uri.getQueryParameter(QUERY_PARAM_USER_ID);
            if (!isNullOrEmpty(param_screen_name)) {
                bundle.putString(INTENT_KEY_SCREEN_NAME, param_screen_name);
            }
            if (!isNullOrEmpty(param_user_id)) {
                bundle.putLong(INTENT_KEY_USER_ID, parseLong(param_user_id));
            }
            break;
        }
        case LINK_ID_USER_FAVORITES: {
            setTitle(R.string.favorites);
            fragment = new UserFavoritesFragment();
            final String param_screen_name = uri.getQueryParameter(QUERY_PARAM_SCREEN_NAME);
            final String param_user_id = uri.getQueryParameter(QUERY_PARAM_USER_ID);
            if (!isNullOrEmpty(param_screen_name)) {
                bundle.putString(INTENT_KEY_SCREEN_NAME, param_screen_name);
            }
            if (!isNullOrEmpty(param_user_id)) {
                bundle.putLong(INTENT_KEY_USER_ID, parseLong(param_user_id));
            }
            break;
        }
        case LINK_ID_USER_FOLLOWERS: {
            setTitle(R.string.followers);
            fragment = new UserFollowersFragment();
            final String param_screen_name = uri.getQueryParameter(QUERY_PARAM_SCREEN_NAME);
            final String param_user_id = uri.getQueryParameter(QUERY_PARAM_USER_ID);
            if (!isNullOrEmpty(param_screen_name)) {
                bundle.putString(INTENT_KEY_SCREEN_NAME, param_screen_name);
            }
            if (!isNullOrEmpty(param_user_id)) {
                bundle.putLong(INTENT_KEY_USER_ID, parseLong(param_user_id));
            }
            break;
        }
        case LINK_ID_USER_FRIENDS: {
            setTitle(R.string.following);
            fragment = new UserFriendsFragment();
            final String param_screen_name = uri.getQueryParameter(QUERY_PARAM_SCREEN_NAME);
            final String param_user_id = uri.getQueryParameter(QUERY_PARAM_USER_ID);
            if (!isNullOrEmpty(param_screen_name)) {
                bundle.putString(INTENT_KEY_SCREEN_NAME, param_screen_name);
            }
            if (!isNullOrEmpty(param_user_id)) {
                bundle.putLong(INTENT_KEY_USER_ID, parseLong(param_user_id));
            }
            break;
        }
        case LINK_ID_USER_BLOCKS: {
            setTitle(R.string.blocked_users);
            fragment = new UserBlocksListFragment();
            break;
        }
        case LINK_ID_CONVERSATION: {
            setTitle(R.string.view_conversation);
            fragment = new ConversationFragment();
            final String param_status_id = uri.getQueryParameter(QUERY_PARAM_STATUS_ID);
            bundle.putLong(INTENT_KEY_STATUS_ID, parseLong(param_status_id));
            break;
        }
        case LINK_ID_DIRECT_MESSAGES_CONVERSATION: {
            setTitle(R.string.direct_messages);
            fragment = new DMConversationFragment();
            final String param_conversation_id = uri.getQueryParameter(QUERY_PARAM_CONVERSATION_ID);
            final String param_screen_name = uri.getQueryParameter(QUERY_PARAM_SCREEN_NAME);
            final long conversation_id = parseLong(param_conversation_id);
            if (conversation_id > 0) {
                bundle.putLong(INTENT_KEY_CONVERSATION_ID, conversation_id);
            } else if (param_screen_name != null) {
                bundle.putString(INTENT_KEY_SCREEN_NAME, param_screen_name);
            }
            break;
        }
        case LINK_ID_LIST_DETAILS: {
            setTitle(R.string.user_list);
            fragment = new UserListDetailsFragment();
            final String param_screen_name = uri.getQueryParameter(QUERY_PARAM_SCREEN_NAME);
            final String param_user_id = uri.getQueryParameter(QUERY_PARAM_USER_ID);
            final String param_list_id = uri.getQueryParameter(QUERY_PARAM_LIST_ID);
            final String param_list_name = uri.getQueryParameter(QUERY_PARAM_LIST_NAME);
            if (isNullOrEmpty(param_list_id) && (isNullOrEmpty(param_list_name)
                    || isNullOrEmpty(param_screen_name) && isNullOrEmpty(param_user_id))) {
                finish();
                return false;
            }
            bundle.putInt(INTENT_KEY_LIST_ID, parseInt(param_list_id));
            bundle.putLong(INTENT_KEY_USER_ID, parseLong(param_user_id));
            bundle.putString(INTENT_KEY_SCREEN_NAME, param_screen_name);
            bundle.putString(INTENT_KEY_LIST_NAME, param_list_name);
            break;
        }
        case LINK_ID_LIST_TYPES: {
            setTitle(R.string.user_list);
            fragment = new UserListTypesFragment();
            final String param_screen_name = uri.getQueryParameter(QUERY_PARAM_SCREEN_NAME);
            final String param_user_id = uri.getQueryParameter(QUERY_PARAM_USER_ID);
            if (isNullOrEmpty(param_screen_name) && isNullOrEmpty(param_user_id)) {
                finish();
                return false;
            }
            bundle.putLong(INTENT_KEY_USER_ID, parseLong(param_user_id));
            bundle.putString(INTENT_KEY_SCREEN_NAME, param_screen_name);
            break;
        }
        case LINK_ID_LIST_TIMELINE: {
            setTitle(R.string.list_timeline);
            fragment = new UserListTimelineFragment();
            final String param_screen_name = uri.getQueryParameter(QUERY_PARAM_SCREEN_NAME);
            final String param_user_id = uri.getQueryParameter(QUERY_PARAM_USER_ID);
            final String param_list_id = uri.getQueryParameter(QUERY_PARAM_LIST_ID);
            final String param_list_name = uri.getQueryParameter(QUERY_PARAM_LIST_NAME);
            if (isNullOrEmpty(param_list_id) && (isNullOrEmpty(param_list_name)
                    || isNullOrEmpty(param_screen_name) && isNullOrEmpty(param_user_id))) {
                finish();
                return false;
            }
            bundle.putInt(INTENT_KEY_LIST_ID, parseInt(param_list_id));
            bundle.putLong(INTENT_KEY_USER_ID, parseLong(param_user_id));
            bundle.putString(INTENT_KEY_SCREEN_NAME, param_screen_name);
            bundle.putString(INTENT_KEY_LIST_NAME, param_list_name);
            break;
        }
        case LINK_ID_LIST_MEMBERS: {
            setTitle(R.string.list_members);
            fragment = new UserListMembersFragment();
            final String param_screen_name = uri.getQueryParameter(QUERY_PARAM_SCREEN_NAME);
            final String param_user_id = uri.getQueryParameter(QUERY_PARAM_USER_ID);
            final String param_list_id = uri.getQueryParameter(QUERY_PARAM_LIST_ID);
            final String param_list_name = uri.getQueryParameter(QUERY_PARAM_LIST_NAME);
            if (isNullOrEmpty(param_list_id) && (isNullOrEmpty(param_list_name)
                    || isNullOrEmpty(param_screen_name) && isNullOrEmpty(param_user_id))) {
                finish();
                return false;
            }
            bundle.putInt(INTENT_KEY_LIST_ID, parseInt(param_list_id));
            bundle.putLong(INTENT_KEY_USER_ID, parseLong(param_user_id));
            bundle.putString(INTENT_KEY_SCREEN_NAME, param_screen_name);
            bundle.putString(INTENT_KEY_LIST_NAME, param_list_name);
            break;
        }
        case LINK_ID_LIST_SUBSCRIBERS: {
            setTitle(R.string.list_subscribers);
            fragment = new UserListSubscribersFragment();
            final String param_screen_name = uri.getQueryParameter(QUERY_PARAM_SCREEN_NAME);
            final String param_user_id = uri.getQueryParameter(QUERY_PARAM_USER_ID);
            final String param_list_id = uri.getQueryParameter(QUERY_PARAM_LIST_ID);
            final String param_list_name = uri.getQueryParameter(QUERY_PARAM_LIST_NAME);
            if (isNullOrEmpty(param_list_id) && (isNullOrEmpty(param_list_name)
                    || isNullOrEmpty(param_screen_name) && isNullOrEmpty(param_user_id))) {
                finish();
                return false;
            }
            bundle.putInt(INTENT_KEY_LIST_ID, parseInt(param_list_id));
            bundle.putLong(INTENT_KEY_USER_ID, parseLong(param_user_id));
            bundle.putString(INTENT_KEY_SCREEN_NAME, param_screen_name);
            bundle.putString(INTENT_KEY_LIST_NAME, param_list_name);
            break;
        }
        case LINK_ID_LIST_CREATED: {
            setTitle(R.string.list_created_by_user);
            fragment = new UserListCreatedFragment();
            final String param_screen_name = uri.getQueryParameter(QUERY_PARAM_SCREEN_NAME);
            final String param_user_id = uri.getQueryParameter(QUERY_PARAM_USER_ID);
            if (isNullOrEmpty(param_screen_name) && isNullOrEmpty(param_user_id)) {
                finish();
                return false;
            }
            bundle.putLong(INTENT_KEY_USER_ID, parseLong(param_user_id));
            bundle.putString(INTENT_KEY_SCREEN_NAME, param_screen_name);
            break;
        }
        case LINK_ID_LIST_SUBSCRIPTIONS: {
            setTitle(R.string.list_user_followed);
            fragment = new UserListSubscriptionsFragment();
            final String param_screen_name = uri.getQueryParameter(QUERY_PARAM_SCREEN_NAME);
            final String param_user_id = uri.getQueryParameter(QUERY_PARAM_USER_ID);
            if (isNullOrEmpty(param_screen_name) && isNullOrEmpty(param_user_id)) {
                finish();
                return false;
            }
            bundle.putLong(INTENT_KEY_USER_ID, parseLong(param_user_id));
            bundle.putString(INTENT_KEY_SCREEN_NAME, param_screen_name);
            break;
        }
        case LINK_ID_LIST_MEMBERSHIPS: {
            setTitle(R.string.list_following_user);
            fragment = new UserListMembershipsFragment();
            final String param_screen_name = uri.getQueryParameter(QUERY_PARAM_SCREEN_NAME);
            final String param_user_id = uri.getQueryParameter(QUERY_PARAM_USER_ID);
            if (isNullOrEmpty(param_screen_name) && isNullOrEmpty(param_user_id)) {
                finish();
                return false;
            }
            bundle.putLong(INTENT_KEY_USER_ID, parseLong(param_user_id));
            bundle.putString(INTENT_KEY_SCREEN_NAME, param_screen_name);
            break;
        }
        case LINK_ID_USERS_RETWEETED_STATUS: {
            setTitle(R.string.users_retweeted_this);
            fragment = new UserRetweetedStatusFragment();
            final String param_status_id = uri.getQueryParameter(QUERY_PARAM_STATUS_ID);
            bundle.putLong(INTENT_KEY_STATUS_ID, parseLong(param_status_id));
            break;
        }
        case LINK_ID_SAVED_SEARCHES: {
            setTitle(R.string.saved_searches);
            fragment = new SavedSearchesListFragment();
            break;
        }
        case LINK_ID_RETWEETED_TO_ME: {
            setTitle(R.string.retweets_of_me);
            fragment = new RetweetedToMeFragment();
            break;
        }
        case LINK_ID_NEARBY: {
            setTitle(R.string.nearby_tweets);
            fragment = new NativeNearbyMapFragment();
            break;
        }
        case LINK_ID_TRENDS: {
            setTitle(R.string.trends);
            fragment = new TrendsFragment();
            break;
        }
        case LINK_ID_USER_MENTIONS: {
            setTitle(R.string.user_mentions);
            fragment = new UserMentionsFragment();
            final String param_screen_name = uri.getQueryParameter(QUERY_PARAM_SCREEN_NAME);
            if (!isNullOrEmpty(param_screen_name)) {
                bundle.putString(INTENT_KEY_SCREEN_NAME, param_screen_name);
            } else {
                finish();
                return false;
            }
            break;
        }
        case LINK_ID_MENTIONS: {
            setTitle(R.string.mentions);
            fragment = new MentionsFragment();
            break;
        }
        case LINK_ID_INCOMING_FRIENDSHIPS: {
            setTitle(R.string.incoming_friendships);
            fragment = new IncomingFriendshipsFragment();
            break;
        }
        case LINK_ID_BUFFERAPP: {
            final String param_code = uri.getQueryParameter(QUERY_PARAM_CODE);
            setTitle(R.string.accounts);
            fragment = new AccountsFragment();
            bundle.putString(INTENT_KEY_BUFFERAPP_CODE, param_code);
            break;
        }
        default: {
            break;
        }
        }
        final String param_account_id = uri.getQueryParameter(QUERY_PARAM_ACCOUNT_ID);
        if (param_account_id != null) {
            bundle.putLong(INTENT_KEY_ACCOUNT_ID, parseLong(param_account_id));
        } else {
            final String param_account_name = uri.getQueryParameter(QUERY_PARAM_ACCOUNT_NAME);
            if (param_account_name != null) {
                bundle.putLong(INTENT_KEY_ACCOUNT_ID, getAccountId(this, param_account_name));
            } else {
                final long account_id = getDefaultAccountId(this);
                if (isMyAccount(this, account_id)) {
                    bundle.putLong(INTENT_KEY_ACCOUNT_ID, account_id);
                } else {
                    finish();
                    return false;
                }
            }
        }
        if (fragment != null) {
            fragment.setArguments(bundle);
        }
    }
    mFragment = fragment;
    return true;
}

From source file:gc.david.dfm.ui.activity.MainActivity.java

private void handleMapsHostIntent(final Uri uri) {
    final String queryParameter = uri.getQueryParameter("q");
    if (queryParameter != null) {
        final Matcher matcher = getMatcherForUri(queryParameter);
        if (matcher.find()) {
            setDestinationPosition(matcher);
        } else {/* w w  w .j  a v  a2s .  c om*/
            final NoSuchFieldException noSuchFieldException = new NoSuchFieldException(
                    "Error al obtener las coordenadas. Matcher = " + matcher.toString());
            DFMLogger.logException(noSuchFieldException);
            toastIt("Unable to parse address", this);
        }
    } else {
        final NoSuchFieldException noSuchFieldException = new NoSuchFieldException("Query sin parmetro q.");
        DFMLogger.logException(noSuchFieldException);
        toastIt("Unable to parse address", this);
    }
}

From source file:org.kontalk.provider.UsersProvider.java

/** Reverse-lookup a userId hash to insert a new record to users table.
 * FIXME this method could take a very long time to complete.
private void newRecord(SQLiteDatabase db, String matchHash) {
// lookup all phone numbers until our hash matches
Context context = getContext();//from  w ww  . j  a v  a  2  s. c  o m
final Cursor phones = context.getContentResolver().query(Phone.CONTENT_URI,
    new String[] { Phone.NUMBER, Phone.DISPLAY_NAME, Phone.LOOKUP_KEY, Phone.CONTACT_ID },
    null, null, null);
        
try {
    while (phones.moveToNext()) {
        String number = phones.getString(0);
        
        // a phone number with less than 4 digits???
        if (number.length() < 4)
            continue;
        
        // fix number
        try {
            number = NumberValidator.fixNumber(context, number,
                    Authenticator.getDefaultAccountName(context), null);
        }
        catch (Exception e) {
            Log.e(TAG, "unable to normalize number: " + number + " - skipping", e);
            // skip number
            continue;
        }
        
        try {
            String hash = MessageUtils.sha1(number);
            if (hash.equalsIgnoreCase(matchHash)) {
                ContentValues values = new ContentValues();
                values.put(Users.HASH, matchHash);
                values.put(Users.NUMBER, number);
                values.put(Users.DISPLAY_NAME, phones.getString(1));
                values.put(Users.LOOKUP_KEY, phones.getString(2));
                values.put(Users.CONTACT_ID, phones.getLong(3));
                db.insert(TABLE_USERS, null, values);
                break;
            }
        }
        catch (NoSuchAlgorithmException e) {
            Log.e(TAG, "unable to generate SHA-1 hash for " + number + " - skipping", e);
        }
        catch (SQLiteConstraintException sqe) {
            // skip duplicate number
            break;
        }
    }
}
finally {
    phones.close();
}
        
}
*/

@Override
public int update(@NonNull Uri uri, ContentValues values, String selection, String[] selectionArgs) {
    try {
        boolean isResync = Boolean.parseBoolean(uri.getQueryParameter(Users.RESYNC));
        boolean bootstrap = Boolean.parseBoolean(uri.getQueryParameter(Users.BOOTSTRAP));
        boolean commit = Boolean.parseBoolean(uri.getQueryParameter(Users.COMMIT));

        if (isResync) {
            // we keep this synchronized to allow for the initial resync by the
            // registration activity
            synchronized (this) {
                long diff = System.currentTimeMillis() - mLastResync;
                if (diff > 1000 && (!bootstrap || dbHelper.isNew())) {
                    if (commit) {
                        commit();
                        return 0;
                    } else {
                        return resync();
                    }
                }

                mLastResync = System.currentTimeMillis();
                return 0;
            }
        }

        // simple update
        int match = sUriMatcher.match(uri);
        switch (match) {
        case USERS:
        case USERS_JID:
            return updateUser(values, Boolean.parseBoolean(uri.getQueryParameter(Users.OFFLINE)), selection,
                    selectionArgs);

        case KEYS:
        case KEYS_JID:
        case KEYS_JID_FINGERPRINT:
            throw new IllegalArgumentException("use insert for keys");

        default:
            throw new IllegalArgumentException("Unknown URI " + uri);
        }
    } finally {
        invalidateFastScrollingIndexCache();
    }
}

From source file:net.abcdroid.devfest12.ui.SessionLivestreamActivity.java

/**
 * Updates views that rely on session data from explicit strings.
 */// w w w  .  ja  va2s .co m
private void updateSessionViews(final String youtubeUrl, final String title, final String sessionAbstract,
        final String hashTag, final String trackName) {

    if (youtubeUrl == null) {
        // Get out, nothing to do here
        navigateUpOrFinish();
        return;
    }

    mTrackName = trackName;
    String youtubeVideoId = youtubeUrl;
    if (youtubeUrl.startsWith("http")) {
        final Uri youTubeUri = Uri.parse(youtubeUrl);
        youtubeVideoId = youTubeUri.getQueryParameter("v");
    }

    playVideo(youtubeVideoId);

    if (mTrackPlay) {
        EasyTracker.getTracker().trackView("Live Streaming: " + title);
        LOGD("Tracker", "Live Streaming: " + title);
    }

    final String newYoutubeUrl = Config.YOUTUBE_SHARE_URL_PREFIX + youtubeVideoId;
    mSessionShareData = new SessionShareData(title, hashTag, newYoutubeUrl);
    mShareMenuDeferredSetup = new Runnable() {
        @Override
        public void run() {
            new SessionsHelper(SessionLivestreamActivity.this).tryConfigureShareMenuItem(mShareMenuItem,
                    R.string.share_livestream_template, title, hashTag, newYoutubeUrl);
        }
    };

    if (mShareMenuItem != null) {
        mShareMenuDeferredSetup.run();
        mShareMenuDeferredSetup = null;
    }

    mSessionSummaryDeferredSetup = new Runnable() {
        @Override
        public void run() {
            updateSessionSummaryFragment(title, sessionAbstract);
            updateSessionLiveCaptionsFragment(trackName);
        }
    };

    if (!mLoadFromExtras) {
        mSessionSummaryDeferredSetup.run();
        mSessionSummaryDeferredSetup = null;
    }
}

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

private int handleIntent(final Intent intent, final boolean firstCreate) {
    // use packge's class loader to prevent BadParcelException
    intent.setExtrasClassLoader(getClassLoader());
    // reset intent
    setIntent(new Intent(this, HomeActivity.class));
    final String action = intent.getAction();
    if (Intent.ACTION_SEARCH.equals(action)) {
        final String query = intent.getStringExtra(SearchManager.QUERY);
        final Bundle appSearchData = intent.getBundleExtra(SearchManager.APP_DATA);
        final long accountId;
        if (appSearchData != null && appSearchData.containsKey(EXTRA_ACCOUNT_ID)) {
            accountId = appSearchData.getLong(EXTRA_ACCOUNT_ID, -1);
        } else {/*from w  w w. j  a  va 2 s . c  om*/
            accountId = getDefaultAccountId(this);
        }
        openSearch(this, accountId, query);
        return -1;
    }
    final boolean refreshOnStart = mPreferences.getBoolean(KEY_REFRESH_ON_START, false);
    final long[] refreshedIds = intent.getLongArrayExtra(EXTRA_REFRESH_IDS);
    if (refreshedIds != null) {
        mTwitterWrapper.refreshAll(refreshedIds);
    } else if (firstCreate && refreshOnStart) {
        mTwitterWrapper.refreshAll();
    }

    final Uri uri = intent.getData();
    final String tabType = uri != null ? Utils.matchTabType(uri) : null;
    int initialTab = -1;
    if (tabType != null) {
        final long accountId = ParseUtils.parseLong(uri.getQueryParameter(QUERY_PARAM_ACCOUNT_ID));
        for (int i = mPagerAdapter.getCount() - 1; i > -1; i--) {
            final SupportTabSpec tab = mPagerAdapter.getTab(i);
            if (tabType.equals(tab.type)) {
                initialTab = i;
                if (hasAccountId(tab.args, accountId)) {
                    break;
                }
            }
        }
    }
    if (initialTab != -1 && mViewPager != null) {
        // clearNotification(initial_tab);
    }
    final Intent extraIntent = intent.getParcelableExtra(EXTRA_EXTRA_INTENT);
    if (extraIntent != null && firstCreate) {
        extraIntent.setExtrasClassLoader(getClassLoader());
        startActivity(extraIntent);
    }
    return initialTab;
}