Example usage for android.app Activity startActivity

List of usage examples for android.app Activity startActivity

Introduction

In this page you can find the example usage for android.app Activity startActivity.

Prototype

@Override
public void startActivity(Intent intent) 

Source Link

Document

Same as #startActivity(Intent,Bundle) with no options specified.

Usage

From source file:com.mimo.service.api.MimoOauth2Client.java

/**
 * Instantiate a webview and allows the user to login to the Api form within
 * the application/*from   www  .  ja  va 2 s . c  om*/
 * 
 * @param p_view
 *            : Calling view
 * 
 * @param p_activity
 *            : Calling Activity reference
 **/

@SuppressLint("SetJavaScriptEnabled")
public void login(View p_view, Activity p_activity) {

    final Activity m_activity;
    m_activity = p_activity;
    String m_url = this.m_api.getAuthUrl();
    WebView m_webview = new WebView(p_view.getContext());
    m_webview.getSettings().setJavaScriptEnabled(true);
    m_webview.setVisibility(View.VISIBLE);
    m_activity.setContentView(m_webview);

    m_webview.requestFocus(View.FOCUS_DOWN);
    /**
     * Open the softkeyboard of the device to input the text in form which
     * loads in webview.
     */
    m_webview.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View p_v, MotionEvent p_event) {
            switch (p_event.getAction()) {
            case MotionEvent.ACTION_DOWN:
            case MotionEvent.ACTION_UP:
                if (!p_v.hasFocus()) {
                    p_v.requestFocus();
                }
                break;
            }
            return false;
        }
    });

    /**
     * Show the progressbar in the title of the activity untill the page
     * loads the give url.
     */
    m_webview.setWebChromeClient(new WebChromeClient() {
        @Override
        public void onProgressChanged(WebView p_view, int p_newProgress) {
            ((Activity) m_context).setProgress(p_newProgress * 100);
            ((Activity) m_context).setTitle(MimoAPIConstants.DIALOG_TEXT_LOADING);

            if (p_newProgress == 100)
                ((Activity) m_context).setTitle(m_context.getString(R.string.app_name));
        }
    });

    m_webview.setWebViewClient(new WebViewClient() {
        @Override
        public void onPageStarted(WebView p_view, String p_url, Bitmap p_favicon) {
        }

        @Override
        public void onReceivedHttpAuthRequest(WebView p_view, HttpAuthHandler p_handler, String p_url,
                String p_realm) {
            p_handler.proceed(MimoAPIConstants.USERNAME, MimoAPIConstants.PASSWORD);
        }

        public void onPageFinished(WebView p_view, String p_url) {
            if (MimoAPIConstants.DEBUG) {
                Log.d(TAG, "Page Url = " + p_url);
            }
            if (p_url.contains("?code=")) {
                if (p_url.indexOf("code=") != -1) {
                    String[] m_urlSplit = p_url.split("=");

                    String m_tempString1 = m_urlSplit[1];
                    if (MimoAPIConstants.DEBUG) {
                        Log.d(TAG, "TempString1 = " + m_tempString1);
                    }
                    String[] m_urlSplit1 = m_tempString1.split("&");

                    String m_code = m_urlSplit1[0];
                    if (MimoAPIConstants.DEBUG) {
                        Log.d(TAG, "code = " + m_code);
                    }
                    MimoOauth2Client.this.m_code = m_code;
                    Thread m_thread = new Thread() {
                        public void run() {
                            String m_token = requesttoken(MimoOauth2Client.this.m_code);

                            Log.d(TAG, "Token = " + m_token);

                            Intent m_navigateIntent = new Intent(m_activity, MimoTransactions.class);

                            m_navigateIntent.putExtra(MimoAPIConstants.KEY_TOKEN, m_token);

                            m_activity.startActivity(m_navigateIntent);
                        }
                    };
                    m_thread.start();
                } else {
                    if (MimoAPIConstants.DEBUG) {
                        Log.d(TAG, "going in else");
                    }
                }
            } else if (p_url.contains(MimoAPIConstants.URL_KEY_TOKEN)) {
                if (p_url.indexOf(MimoAPIConstants.URL_KEY_TOKEN) != -1) {
                    String[] m_urlSplit = p_url.split("=");
                    final String m_token = m_urlSplit[1];

                    Thread m_thread = new Thread() {
                        public void run() {
                            Intent m_navigateIntent = new Intent(m_activity, MimoTransactions.class);
                            m_navigateIntent.putExtra(MimoAPIConstants.KEY_TOKEN, m_token);
                            m_activity.startActivity(m_navigateIntent);
                        }
                    };
                    m_thread.start();
                }
            }
        };
    });

    m_webview.loadUrl(m_url);
}

From source file:org.getlantern.firetweet.util.Utils.java

public static void openUsers(final Activity activity, final List<ParcelableUser> users) {
    if (activity == null || users == null)
        return;//w  ww  .j a v  a2s  .c om
    final Bundle extras = new Bundle();
    extras.putParcelableArrayList(EXTRA_USERS, new ArrayList<>(users));
    final Uri.Builder builder = new Uri.Builder();
    builder.scheme(SCHEME_FIRETWEET);
    builder.authority(AUTHORITY_USERS);
    final Intent intent = new Intent(Intent.ACTION_VIEW, builder.build());
    intent.putExtras(extras);
    activity.startActivity(intent);
}

From source file:org.getlantern.firetweet.util.Utils.java

public static void openStatuses(final Activity activity, final List<ParcelableStatus> statuses) {
    if (activity == null || statuses == null)
        return;//w  w  w  .j a v  a 2 s  .c o m
    final Bundle extras = new Bundle();
    extras.putParcelableArrayList(EXTRA_STATUSES, new ArrayList<>(statuses));
    final Uri.Builder builder = new Uri.Builder();
    builder.scheme(SCHEME_FIRETWEET);
    builder.authority(AUTHORITY_STATUSES);
    final Intent intent = new Intent(Intent.ACTION_VIEW, builder.build());
    intent.putExtras(extras);
    activity.startActivity(intent);
}

From source file:org.getlantern.firetweet.util.Utils.java

public static void openStatusFavoriters(final Activity activity, final long accountId, final long statusId) {
    if (activity == null)
        return;/* w  w w .  j  a va2 s . c  o  m*/
    final Uri.Builder builder = new Uri.Builder();
    builder.scheme(SCHEME_FIRETWEET);
    builder.authority(AUTHORITY_STATUS_FAVORITERS);
    builder.appendQueryParameter(QUERY_PARAM_ACCOUNT_ID, String.valueOf(accountId));
    builder.appendQueryParameter(QUERY_PARAM_STATUS_ID, String.valueOf(statusId));
    final Intent intent = new Intent(Intent.ACTION_VIEW, builder.build());
    activity.startActivity(intent);
}

From source file:com.android.mms.ui.MessageUtils.java

public static void addNumberOrEmailtoContact(final String numberOrEmail, final int REQUEST_CODE,
        final Activity activity) {
    if (!TextUtils.isEmpty(numberOrEmail)) {
        String message = activity.getResources().getString(R.string.add_contact_dialog_message, numberOrEmail);
        AlertDialog.Builder builder = new AlertDialog.Builder(activity).setTitle(numberOrEmail)
                .setMessage(message);/*from  w w w.  j  a v a2 s  .  co  m*/
        AlertDialog dialog = builder.create();
        dialog.setButton(AlertDialog.BUTTON_POSITIVE,
                activity.getResources().getString(R.string.add_contact_dialog_existing),
                new DialogInterface.OnClickListener() {

                    public void onClick(DialogInterface dialog, int which) {
                        // TODO Auto-generated method stub
                        Intent intent = new Intent(Intent.ACTION_INSERT_OR_EDIT);
                        intent.setType(Contacts.CONTENT_ITEM_TYPE);
                        if (Mms.isEmailAddress(numberOrEmail)) {
                            intent.putExtra(ContactsContract.Intents.Insert.EMAIL, numberOrEmail);
                        } else {
                            intent.putExtra(ContactsContract.Intents.Insert.PHONE, numberOrEmail);
                        }
                        if (REQUEST_CODE > 0) {
                            activity.startActivityForResult(intent, REQUEST_CODE);
                        } else {
                            activity.startActivity(intent);
                        }
                    }
                });

        dialog.setButton(AlertDialog.BUTTON_NEGATIVE,
                activity.getResources().getString(R.string.add_contact_dialog_new),
                new DialogInterface.OnClickListener() {

                    public void onClick(DialogInterface dialog, int which) {
                        // TODO Auto-generated method stub
                        final Intent intent = new Intent(Intent.ACTION_INSERT, Contacts.CONTENT_URI);
                        if (Mms.isEmailAddress(numberOrEmail)) {
                            intent.putExtra(ContactsContract.Intents.Insert.EMAIL, numberOrEmail);
                        } else {
                            intent.putExtra(ContactsContract.Intents.Insert.PHONE, numberOrEmail);
                        }
                        if (REQUEST_CODE > 0) {
                            activity.startActivityForResult(intent, REQUEST_CODE);
                        } else {
                            activity.startActivity(intent);
                        }
                    }
                });
        dialog.show();
    }
}

From source file:com.dwdesign.tweetings.util.Utils.java

public static void openStatus(final Activity activity, final ParcelableStatus status) {
    if (activity == null || status == null)
        return;/*from   w  ww . j  a  va 2s. c  o m*/
    final long account_id = status.account_id, status_id = status.status_id;
    final Bundle bundle = new Bundle();
    bundle.putParcelable(INTENT_KEY_STATUS, status);
    if (activity instanceof DualPaneActivity && ((DualPaneActivity) activity).isDualPaneMode()) {
        final DualPaneActivity dual_pane_activity = (DualPaneActivity) activity;
        final Fragment details_fragment = dual_pane_activity.getDetailsFragment();
        if (details_fragment instanceof StatusFragment && details_fragment.isAdded()) {
            ((StatusFragment) details_fragment).displayStatus(status);
            dual_pane_activity.bringRightPaneToFront();
        } else {
            final Fragment fragment = new StatusFragment();
            final Bundle args = new Bundle(bundle);
            args.putLong(INTENT_KEY_ACCOUNT_ID, account_id);
            args.putLong(INTENT_KEY_STATUS_ID, status_id);
            fragment.setArguments(args);
            dual_pane_activity.showAtPane(DualPaneActivity.PANE_RIGHT, fragment, true);
        }
    } else {
        final Uri.Builder builder = new Uri.Builder();
        builder.scheme(SCHEME_TWEETINGS);
        builder.authority(AUTHORITY_STATUS);
        builder.appendQueryParameter(QUERY_PARAM_ACCOUNT_ID, String.valueOf(account_id));
        builder.appendQueryParameter(QUERY_PARAM_STATUS_ID, String.valueOf(status_id));
        final Intent intent = new Intent(Intent.ACTION_VIEW, builder.build());

        intent.putExtras(bundle);
        activity.startActivity(intent);
    }
}

From source file:org.getlantern.firetweet.util.Utils.java

public static void openUserMentions(final Activity activity, final long account_id, final String screen_name) {
    if (activity == null)
        return;/*from  w ww .j  a  v  a  2 s  .c  om*/
    final Uri.Builder builder = new Uri.Builder();
    builder.scheme(SCHEME_FIRETWEET);
    builder.authority(AUTHORITY_USER_MENTIONS);
    builder.appendQueryParameter(QUERY_PARAM_ACCOUNT_ID, String.valueOf(account_id));
    if (screen_name != null) {
        builder.appendQueryParameter(QUERY_PARAM_SCREEN_NAME, screen_name);
    }
    final Intent intent = new Intent(Intent.ACTION_VIEW, builder.build());
    activity.startActivity(intent);
}

From source file:com.dwdesign.tweetings.util.Utils.java

public static void openUserListDetails(final Activity activity, final long account_id, final int list_id,
        final long user_id, final String screen_name, final String list_name) {
    if (activity == null)
        return;/*from   www . j ava 2  s .  c o m*/
    if (activity instanceof DualPaneActivity && ((DualPaneActivity) activity).isDualPaneMode()) {
        final DualPaneActivity dual_pane_activity = (DualPaneActivity) activity;
        final Fragment fragment = new UserListDetailsFragment();
        final Bundle args = new Bundle();
        args.putLong(INTENT_KEY_ACCOUNT_ID, account_id);
        args.putInt(INTENT_KEY_LIST_ID, list_id);
        args.putLong(INTENT_KEY_USER_ID, user_id);
        args.putString(INTENT_KEY_SCREEN_NAME, screen_name);
        args.putString(INTENT_KEY_LIST_NAME, list_name);
        fragment.setArguments(args);
        dual_pane_activity.showFragment(fragment, true);
    } else {
        final Uri.Builder builder = new Uri.Builder();
        builder.scheme(SCHEME_TWEETINGS);
        builder.authority(AUTHORITY_LIST_DETAILS);
        builder.appendQueryParameter(QUERY_PARAM_ACCOUNT_ID, String.valueOf(account_id));
        if (list_id > 0) {
            builder.appendQueryParameter(QUERY_PARAM_LIST_ID, String.valueOf(list_id));
        }
        if (user_id > 0) {
            builder.appendQueryParameter(QUERY_PARAM_USER_ID, String.valueOf(user_id));
        }
        if (screen_name != null) {
            builder.appendQueryParameter(QUERY_PARAM_SCREEN_NAME, screen_name);
        }
        if (list_name != null) {
            builder.appendQueryParameter(QUERY_PARAM_LIST_NAME, list_name);
        }
        activity.startActivity(new Intent(Intent.ACTION_VIEW, builder.build()));
    }
}

From source file:com.dwdesign.tweetings.util.Utils.java

public static void openDirectMessagesConversation(final Activity activity, final long account_id,
        final long conversation_id) {
    if (activity == null)
        return;/* www  . ja v  a  2  s . c  o m*/
    if (activity instanceof DualPaneActivity && ((DualPaneActivity) activity).isDualPaneMode()) {
        final DualPaneActivity dual_pane_activity = (DualPaneActivity) activity;
        final Fragment details_fragment = dual_pane_activity.getDetailsFragment();
        if (details_fragment instanceof DMConversationFragment && details_fragment.isAdded()) {
            ((DMConversationFragment) details_fragment).showConversation(account_id, conversation_id);
        } else {
            final Fragment fragment = new DMConversationFragment();
            final Bundle args = new Bundle();
            if (account_id > 0 && conversation_id > 0) {
                args.putLong(INTENT_KEY_ACCOUNT_ID, account_id);
                if (conversation_id > 0) {
                    args.putLong(INTENT_KEY_CONVERSATION_ID, conversation_id);
                }
            }
            fragment.setArguments(args);
            dual_pane_activity.showAtPane(PANE_RIGHT, fragment, true);
        }
    } else {
        final Uri.Builder builder = new Uri.Builder();
        builder.scheme(SCHEME_TWEETINGS);
        builder.authority(AUTHORITY_DIRECT_MESSAGES_CONVERSATION);
        if (account_id > 0 && conversation_id > 0) {
            builder.appendQueryParameter(QUERY_PARAM_ACCOUNT_ID, String.valueOf(account_id));
            if (conversation_id > 0) {
                builder.appendQueryParameter(QUERY_PARAM_CONVERSATION_ID, String.valueOf(conversation_id));
            }
        }
        activity.startActivity(new Intent(Intent.ACTION_VIEW, builder.build()));
    }
}

From source file:com.dwdesign.tweetings.util.Utils.java

public static void openUserListMembers(final Activity activity, final long account_id, final int list_id,
        final long user_id, final String screen_name, final String list_name) {
    if (activity == null)
        return;//www .java 2s .co  m
    if (activity instanceof DualPaneActivity && ((DualPaneActivity) activity).isDualPaneMode()) {
        final DualPaneActivity dual_pane_activity = (DualPaneActivity) activity;
        final Fragment fragment = new UserListMembersFragment();
        final Bundle args = new Bundle();
        args.putLong(INTENT_KEY_ACCOUNT_ID, account_id);
        args.putInt(INTENT_KEY_LIST_ID, list_id);
        args.putLong(INTENT_KEY_USER_ID, user_id);
        args.putString(INTENT_KEY_SCREEN_NAME, screen_name);
        args.putString(INTENT_KEY_LIST_NAME, list_name);
        fragment.setArguments(args);
        dual_pane_activity.showAtPane(DualPaneActivity.PANE_LEFT, fragment, true);
    } else {
        final Uri.Builder builder = new Uri.Builder();
        builder.scheme(SCHEME_TWEETINGS);
        builder.authority(AUTHORITY_LIST_MEMBERS);
        builder.appendQueryParameter(QUERY_PARAM_ACCOUNT_ID, String.valueOf(account_id));
        if (list_id > 0) {
            builder.appendQueryParameter(QUERY_PARAM_LIST_ID, String.valueOf(list_id));
        }
        if (user_id > 0) {
            builder.appendQueryParameter(QUERY_PARAM_USER_ID, String.valueOf(user_id));
        }
        if (screen_name != null) {
            builder.appendQueryParameter(QUERY_PARAM_SCREEN_NAME, screen_name);
        }
        if (list_name != null) {
            builder.appendQueryParameter(QUERY_PARAM_LIST_NAME, list_name);
        }
        activity.startActivity(new Intent(Intent.ACTION_VIEW, builder.build()));
    }
}