Example usage for android.content Intent setClass

List of usage examples for android.content Intent setClass

Introduction

In this page you can find the example usage for android.content Intent setClass.

Prototype

public @NonNull Intent setClass(@NonNull Context packageContext, @NonNull Class<?> cls) 

Source Link

Document

Convenience for calling #setComponent(ComponentName) with the name returned by a Class object.

Usage

From source file:com.example.yuen.e_carei.ShowAppointmentList.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_list);

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    toolbar.setTitle("E-care");
    setSupportActionBar(toolbar);/*  w  w w  . j  a v a2  s .  co m*/

    db = new SQLiteHandler(getApplicationContext());
    session = new SessionManager(getApplicationContext());

    drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    NavigationView view = (NavigationView) findViewById(R.id.navigation_view);
    view.getMenu().getItem(1).setChecked(true);
    view.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
        @Override
        public boolean onNavigationItemSelected(MenuItem menuItem) {
            Toast.makeText(ShowAppointmentList.this, menuItem.getItemId() + " pressed", Toast.LENGTH_LONG)
                    .show();
            Intent intent = new Intent();
            Log.d(R.id.nav_1 + "", menuItem.getItemId() + " ");
            switch (menuItem.getItemId()) {
            case R.id.nav_1:
                intent.setClass(ShowAppointmentList.this, Case_history_review.class);
                startActivity(intent);
                break;
            case R.id.nav_2:
                intent.setClass(ShowAppointmentList.this, ShowAppointmentList.class);
                //intent .putExtra("name", "Hello B Activity");
                startActivity(intent);
                break;
            case R.id.nav_3:
                intent.setClass(ShowAppointmentList.this, Appointmentcreate.class);
                //intent .putExtra("name", "Hello B Activity");
                startActivity(intent);
                break;
            case R.id.nav_4:
                intent.setClass(ShowAppointmentList.this, AlarmActivity.class);
                //intent .putExtra("name", "Hello B Activity");
                startActivity(intent);
                break;
            case R.id.nav_5:
                intent.setClass(ShowAppointmentList.this, PatientReport.class);
                //intent .putExtra("name", "Hello B Activity");
                startActivity(intent);
                break;
            case R.id.nav_6:
                //logout
                AlertDialog.Builder builder = new AlertDialog.Builder(ShowAppointmentList.this);
                //Uncomment the below code to Set the message and title from the strings.xml file
                //builder.setMessage(R.string.dialog_message) .setTitle(R.string.dialog_title);

                //Setting message manually and performing action on button click
                builder.setMessage("Do you want to close this application ?").setCancelable(false)
                        .setPositiveButton("Yes", new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int id) {
                                session.setLogin(false);
                                db.deleteUsers();
                                final Intent intent_logout = new Intent(ShowAppointmentList.this,
                                        LoginActivity.class);
                                startActivity(intent_logout);
                                finish();
                            }
                        }).setNegativeButton("No", new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int id) {
                                //  Action for 'NO' Button
                                dialog.cancel();
                            }
                        });

                //Creating dialog box
                AlertDialog alert = builder.create();
                //Setting the title manually
                alert.setTitle("AlertDialogExample");
                alert.show();

                break;
            }
            menuItem.setChecked(true);
            drawerLayout.closeDrawers();
            return true;
        }
    });

    ActionBarDrawerToggle actionBarDrawerToggle = new ActionBarDrawerToggle(this, drawerLayout, toolbar,
            R.string.drawer_open, R.string.drawer_close) {
        @Override
        public void onDrawerClosed(View drawerView) {
            super.onDrawerClosed(drawerView);
        }

        @Override
        public void onDrawerOpened(View drawerView) {
            super.onDrawerOpened(drawerView);
        }
    };

    db = new SQLiteHandler(getApplicationContext());
    dbuser = db.getUserDetails();
    View header = view.getHeaderView(0);
    TextView headerName = (TextView) header.findViewById(R.id.drawer_name);
    username = dbuser.get("name");
    uid = dbuser.get("uid");
    headerName.setText(username);
    ImageLoader imageLoader = AppController.getInstance().getImageLoader();
    com.example.yuen.e_carei_doctor.customlistviewvolley.CirculaireNetworkImageView headerphoto = (com.example.yuen.e_carei_doctor.customlistviewvolley.CirculaireNetworkImageView) header
            .findViewById(R.id.drawer_thumbnail);
    headerphoto.setImageUrl("http://10.89.133.147/test/" + dbuser.get("image"), imageLoader);
    drawerLayout.setDrawerListener(actionBarDrawerToggle);
    actionBarDrawerToggle.syncState();

    mListView = (SwipeMenuListView) findViewById(R.id.listView);
    swipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.swipe_refresh_layout);

    swipeRefreshLayout.setOnRefreshListener(this);

    /**
     * Showing Swipe Refresh animation on activity create
     * As animation won't start on onCreate, post runnable is used
     */
    swipeRefreshLayout.post(new Runnable() {
        @Override
        public void run() {

            swipeRefreshLayout.setRefreshing(true);
            fetchPatients();
        }
    });

    PD = new ProgressDialog(this);
    //Showing progress dialog before making http request
    PD.setMessage("Loading...");
    PD.show();
    mAdapter = new AppointmentListAdapter(this, appointmentList);
    mListView.setAdapter(mAdapter);
    //fetchPatients();
    // step 1. create a MenuCreator
    SwipeMenuCreator creator = new SwipeMenuCreator() {

        @Override
        public void create(SwipeMenu menu) {

            // create "delete" item
            SwipeMenuItem deleteItem = new SwipeMenuItem(getApplicationContext());
            // set item background
            deleteItem.setBackground(new ColorDrawable(Color.rgb(0xF9, 0x3F, 0x25)));
            // set item width
            deleteItem.setWidth(dp2px(90));
            // set a icon
            deleteItem.setIcon(R.drawable.ic_delete);
            // add to menu
            menu.addMenuItem(deleteItem);
        }
    };
    // set creator
    mListView.setMenuCreator(creator);

    // step 2. listener item click event
    mListView.setOnMenuItemClickListener(new SwipeMenuListView.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(int position, SwipeMenu menu, int index) {
            AppointmentList item = appointmentList.get(position);
            switch (index) {
            case 0:
                // delete
                //delete(item);
                final String row_aid = aidlist.get(position).toString();
                AlertDialog.Builder builder = new AlertDialog.Builder(ShowAppointmentList.this);

                //Setting message manually and performing action on button click
                builder.setMessage("Do you want to delete this row ?").setCancelable(false)
                        .setPositiveButton("Yes", new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int id) {
                                delete(uid, row_aid);
                                fetchPatients();
                            }
                        }).setNegativeButton("No", new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int id) {
                                //  Action for 'NO' Button
                                dialog.cancel();
                            }
                        });

                //Creating dialog box
                AlertDialog alert = builder.create();
                //Setting the title manually
                alert.setTitle("AlertDialogExample");
                alert.show();
                break;
            }
            return false;
        }
    });

    // set SwipeListener
    mListView.setOnSwipeListener(new SwipeMenuListView.OnSwipeListener() {

        @Override
        public void onSwipeStart(int position) {
            // swipe start
        }

        @Override
        public void onSwipeEnd(int position) {
            // swipe end
        }
    });

    // set MenuStateChangeListener
    mListView.setOnMenuStateChangeListener(new SwipeMenuListView.OnMenuStateChangeListener() {
        @Override
        public void onMenuOpen(int position) {
        }

        @Override
        public void onMenuClose(int position) {
        }
    });

    // other setting
    //      listView.setCloseInterpolator(new BounceInterpolator());

    // test item long click
    mListView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {

        @Override
        public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
            Toast.makeText(getApplicationContext(), position + " long click", Toast.LENGTH_SHORT).show();
            return false;
        }
    });

}

From source file:com.onebus.view.MainActivity.java

public void onResults(Bundle results) {
    long end2finish = System.currentTimeMillis() - speechEndTime;
    status = STATUS_None;//from w  w  w  .j a  v a2 s.  c o m
    ArrayList<String> nbest = results.getStringArrayList(SpeechRecognizer.RESULTS_RECOGNITION);
    /*
     * print("?" + Arrays.toString(nbest.toArray(new
     * String[nbest.size()])));
     */

    Intent intent = new Intent();
    intent.setClass(getApplicationContext(), SearchActivity.class);
    intent.putExtra("tag", 1);
    intent.putExtra("strMessage", nbest.get(0).toString());
    startActivity(intent);

    String json_res = results.getString("origin_result");

    String strEnd2Finish = "";
    if (end2finish < 60 * 1000) {
        strEnd2Finish = "(waited " + end2finish + "ms)";
    }

    cancel();
}

From source file:com.feytuo.chat.activity.MainActivity.java

public void onTabpublishClicked(View view) {
    if (App.isLogin()) {
        Intent intentpublish = new Intent();
        intentpublish.setClass(MainActivity.this, PublishActivity.class);
        startActivity(intentpublish);/* w ww. j a  v  a 2  s. c o  m*/
    }
}

From source file:org.openremote.android.console.AppSettingsActivity.java

/**
 * Start {@link Main} activity//from  w  ww .j  a v a  2s. c  om
 */
private void startMain() {
    Intent intent = new Intent();
    intent.setClass(AppSettingsActivity.this, Main.class);
    startActivity(intent);
    finish();
}

From source file:com.jefftharris.passwdsafe.sync.MainActivity.java

/** Button onClick handler to select Dropbox files */
@SuppressWarnings({ "UnusedParameters", "unused" })
public void onDropboxChooseFiles(View view) {
    Intent intent = new Intent();
    intent.putExtra(DropboxFilesActivity.INTENT_PROVIDER_URI, itsDropboxUri);
    intent.setClass(this, DropboxFilesActivity.class);
    startActivity(intent);// w w  w  .  j a  v a2  s.c  om
}

From source file:com.jefftharris.passwdsafe.sync.MainActivity.java

/** Button onClick handler to select OneDrive files */
@SuppressWarnings("UnusedParameters")
public void onOnedriveChooseFiles(View view) {
    Intent intent = new Intent();
    intent.putExtra(OnedriveFilesActivity.INTENT_PROVIDER_URI, itsOnedriveUri);
    intent.setClass(this, OnedriveFilesActivity.class);
    startActivity(intent);//  www.  j a v  a2s.  co m
}

From source file:com.jefftharris.passwdsafe.sync.MainActivity.java

/** Button onClick handler to select ownCloud files */
@SuppressWarnings({ "UnusedParameters", "unused" })
public void onOwncloudChooseFiles(View view) {
    Intent intent = new Intent();
    intent.putExtra(OwncloudFilesActivity.INTENT_PROVIDER_URI, itsOwncloudUri);
    intent.setClass(this, OwncloudFilesActivity.class);
    startActivity(intent);/*  www  . ja  va2s. c o m*/
}

From source file:com.mifos.mifosxdroid.online.DashboardActivity.java

@Override
public boolean onNavigationItemSelected(MenuItem item) {

    // ignore the current selected item
    /*if (item.isChecked()) {
    mDrawerLayout.closeDrawer(Gravity.LEFT);
    return false;/* w  ww .jav a 2s  .c o m*/
    }*/

    // select which activity to open
    clearFragmentBackStack();
    final Intent intent = new Intent();
    switch (item.getItemId()) {
    case R.id.item_dashboard:
        replaceFragment(new SearchFragment(), false, R.id.container);
        break;
    case R.id.item_clients:
        replaceFragment(ClientListFragment.newInstance(), false, R.id.container);
        break;
    case R.id.item_groups:
        replaceFragment(GroupsListFragment.newInstance(), false, R.id.container);
        break;
    case R.id.item_centers:
        replaceFragment(CenterListFragment.newInstance(), false, R.id.container);
        break;
    case R.id.item_path_tracker:
        intent.setClass(getApplicationContext(), PathTrackingActivity.class);
        startNavigationClickActivity(intent);
        break;
    case R.id.item_offline:
        replaceFragment(OfflineDashboardFragment.newInstance(), false, R.id.container);
        break;

    }

    // close the drawer
    mDrawerLayout.closeDrawer(Gravity.LEFT);
    mNavigationView.setCheckedItem(R.id.item_dashboard);
    return true;
}

From source file:com.ibm.mobilefirstplatform.clientsdk.android.push.api.MFPPushIntentService.java

private void onUnhandled(Context context, Intent intent) {
    String action = intent.getAction();
    if ((MFPPushUtils.getIntentPrefix(context) + GCM_MESSAGE).equals(action)) {
        MFPInternalPushMessage message = intent.getParcelableExtra(GCM_EXTRA_MESSAGE);

        int notificationId = randomObj.nextInt();
        message.setNotificationId(notificationId);
        saveInSharedPreferences(message);

        intent = new Intent(MFPPushUtils.getIntentPrefix(context) + IBM_PUSH_NOTIFICATION);

        intent.setClass(context, MFPPushNotificationHandler.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP);

        intent.putExtra(NOTIFICATIONID, message.getNotificationId());

        generateNotification(context, message.getAlert(), getNotificationTitle(context), message.getAlert(),
                getCustomNotificationIcon(context, message.getIcon()), intent, getNotificationSound(message),
                notificationId, message);
    }/*from   w ww  .  j a v  a2 s.  c  o m*/
}

From source file:com.orange.oidc.secproxy_service.HttpOpenidConnect.java

public boolean getTokens(Context ctx, String id, String login) {

    if (mOcp == null)
        return false;

    try {//  w  w w. ja  va2  s.  c  o  m

        String requestObject = null;
        String authorization_endpoint = null;
        try {

            // retrieve openid config
            JSONObject json = getHttpJSON(mOcp.m_server_url + openIdConfigurationUrl);
            if (json == null) {
                Logd(TAG, "could not get openid-configuration on server : " + mOcp.m_server_url);
                return false;
            }

            // get authorization end_point
            authorization_endpoint = json.optString("authorization_endpoint");

            Logd(TAG, "authorization_endpoint : " + authorization_endpoint);

            // TAZTAG : no use to define request object if key jwt is not used ?
            if (mUsePrivateKeyJWT) {
                // get jwks_uri of the server
                String jwks_uri = json.optString("jwks_uri");
                if (jwks_uri == null || jwks_uri.length() < 1) {
                    Logd(TAG, "could not get jwks_uri from openid-configuration on server : "
                            + mOcp.m_server_url);
                    return false;
                }
                Logd(TAG, "jwks_uri : " + jwks_uri);

                // get jwks
                String jwks = getHttpString(jwks_uri);
                if (jwks == null || jwks.length() < 1) {
                    Logd(TAG, "could not get jwks_uri content from : " + jwks_uri);
                    return false;
                }
                Logd(TAG, "jwks : " + jwks);

                // extract public key
                PublicKey serverPubKey = KryptoUtils.pubKeyFromJwk(jwks);
                if (serverPubKey == null) {
                    Logd(TAG, "could not extract public key from jwk : " + jwks);
                    return false;
                }

                // get oidc request object
                requestObject = secureProxy.getOidcRequestObject(mOcp.m_server_url, mOcp.m_client_id,
                        mOcp.m_scope, serverPubKey);
                Logd(TAG, "secureStorage requestObject : " + requestObject);
            }

        } catch (Exception ee) {
            // error generating request object
            ee.printStackTrace();
            return false;
        }

        // build post parameters
        List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(7);
        nameValuePairs.add(new BasicNameValuePair("redirect_uri", mOcp.m_redirect_uri));
        nameValuePairs.add(new BasicNameValuePair("response_type", "code"));
        nameValuePairs.add(new BasicNameValuePair("scope", mOcp.m_scope));

        nameValuePairs.add(new BasicNameValuePair("client_id", secureProxy.getClientId()));

        //         nameValuePairs.add(new BasicNameValuePair("nonce",         mOcp.m_nonce));
        nameValuePairs.add(new BasicNameValuePair("nonce", "1234567890"));
        if (!isEmpty(requestObject)) {
            nameValuePairs.add(new BasicNameValuePair("request", requestObject));
        }
        nameValuePairs.add(new BasicNameValuePair("prompt", "consent"));

        // get URL encoded string from list of key value pairs
        String postParams = getQuery(nameValuePairs);

        Log.d(TAG, "get URL encoded string from list of key value pairs : " + postParams);

        // launch webview

        // init intent
        Intent intent = new Intent(Intent.ACTION_VIEW);
        intent.setClass(ctx, WebViewActivity.class);

        // prepare request parameters
        intent.putExtra("id", id);

        intent.putExtra("server_url", authorization_endpoint);
        intent.putExtra("redirect_uri", mOcp.m_redirect_uri);
        intent.putExtra("client_id", mOcp.m_client_id);
        if (login != null)
            intent.putExtra("login", login);

        intent.putExtra("postParams", postParams);

        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP
                | Intent.FLAG_ACTIVITY_NO_ANIMATION);

        // display webview
        ctx.startActivity(intent);

    } catch (Exception e) {
        e.printStackTrace();
        return false;
    }
    return true;
}