Example usage for android.content Context BIND_AUTO_CREATE

List of usage examples for android.content Context BIND_AUTO_CREATE

Introduction

In this page you can find the example usage for android.content Context BIND_AUTO_CREATE.

Prototype

int BIND_AUTO_CREATE

To view the source code for android.content Context BIND_AUTO_CREATE.

Click Source Link

Document

Flag for #bindService : automatically create the service as long as the binding exists.

Usage

From source file:com.jiusg.mainscreenshow.ui.MSS.java

@Override
protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);

    //      boolean findMethod = findActionBarTabsShowAtBottom();
    //      if (!findMethod) { // ?ActionBar?TabHost
    //         getWindow().setUiOptions(0);
    //      }//  w  ww  .  j av a2 s .  c  o  m
    //
    //      if(C.ISMEIZU){
    //         getWindow().setUiOptions(ActivityInfo.UIOPTION_SPLIT_ACTION_BAR_WHEN_NARROW);
    //         setTheme(R.style.AppTheme_Meizu);
    //      }

    //      setContentView(R.layout.tab_content);

    setActionBarLayout(R.layout.actionbar_mss);
    setContentView(R.layout.activity_mss);
    sp_userinfo = getSharedPreferences("userinfo", 0);

    viewPager = (ViewPager) findViewById(R.id.mss_vp);
    setting = (ImageButton) findViewById(R.id.actionbar_setting);
    title = (TextView) findViewById(R.id.actionbar_title);
    event = (ImageButton) findViewById(R.id.actionbar_event);
    preview = (ImageButton) findViewById(R.id.actionbar_preview);

    setting.setOnClickListener(this);
    event.setOnClickListener(this);
    preview.setOnClickListener(this);

    list = new ArrayList<android.support.v4.app.Fragment>();
    mssEvent = new MSSEventFragment();
    mssPreview = new MssPreviewFragment();
    list.add(mssEvent);
    list.add(mssPreview);

    viewPager.setAdapter(new MSSFragmentAdapter(getSupportFragmentManager(), list));
    viewPager.setCurrentItem(0);
    viewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
        @Override
        public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

        }

        @Override
        public void onPageSelected(int position) {
            switch (position) {
            case 0:
                title.setText(R.string.app_name);
                event.setImageResource(R.drawable.ic_event_press);
                preview.setImageResource(R.drawable.ic_preview);
                break;
            case 1:
                title.setText(R.string.action_MSSPreview);
                event.setImageResource(R.drawable.ic_event);
                preview.setImageResource(R.drawable.ic_preview_press);
                break;
            default:
                break;
            }
        }

        @Override
        public void onPageScrollStateChanged(int state) {

        }
    });

    //      final TabHost tabHost = getTabHost();
    //      tabHost.addTab(tabHost
    //            .newTabSpec("event")
    //            .setIndicator(null,
    //                  getResources().getDrawable(R.drawable.ic_tab_event))
    //            .setContent(new Intent(this, MSSEvent.class)));
    //      tabHost.addTab(tabHost
    //            .newTabSpec("preview")
    //            .setIndicator(null,
    //                  getResources().getDrawable(R.drawable.ic_tab_preview))
    //            .setContent(new Intent(this, MSSPreview.class)));

    //      if (true) {
    //         getTabWidget().setVisibility(View.GONE);
    //
    //         final ActionBar bar = getActionBar();
    //         bar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
    //
    //         bar.addTab(bar.newTab().setIcon(R.drawable.ic_tab_event)
    //               .setTabListener(this));
    //         bar.addTab(bar.newTab().setIcon(R.drawable.ic_tab_preview)
    //               .setTabListener(this));
    //
    //         // View????
    //         // bar.addTab(bar.newTab().setTabListener(this).setCustomView(R.layout.tab_widget_indicator).setTabListener(this));
    //
    //         // ActionBar Tab?
    //         SmartBarUtils.setActionBarTabsShowAtBottom(bar, true);
    //      }
    //
    //      SmartBarUtils.setBackIcon(getActionBar(),
    //            getResources().getDrawable(R.drawable.ic_back));

    // ?
    if (C.ISFREE) {
        sp_userinfo.edit().putString("UserVersionInfo", C.VERSION_FREE).commit();
    }

    // ?
    // sp_userinfo.edit().putString("UserVersionInfo", "OfficialVersion")
    // .commit();

    // ????
    if (!sp_userinfo.getString("UserVersionInfo", "").equals(C.VERSION_FREE)) {

        // ???????
        if (!sp_userinfo.getString("UserVersionInfo", "").equals("OfficialVersion")) {
            // ? ????
            if (mLicensingService == null) {

                Intent intent = new Intent();
                intent.setAction(ILicensingService.class.getName());
                bindService(intent, mLicenseConnection, Context.BIND_AUTO_CREATE);

            }

            hd = new LicenseHandler();
            Message msg = hd.obtainMessage();
            msg.obj = "License";
            hd.sendMessageDelayed(msg, 3000);
        }
    }

    mSc = new ServiceConnection() {

        @Override
        public void onServiceDisconnected(ComponentName name) {

        }

        @Override
        public void onServiceConnected(ComponentName name, IBinder service) {

            mssservice = ((MSSService.MSSSBinder) service).getMSSService();

        }
    };
}

From source file:com.anand.music.PlaylistFragment.java

@Override
public void onStart() {
    super.onStart();
    Activity containerActivity = getActivity();
    Intent playlistIntent = new Intent(containerActivity, MediaPlayerService.class);
    if (MediaPlayerService.mHasLaunched) {
        if (!mBound) {
            containerActivity.bindService(playlistIntent, mConnection, Context.BIND_AUTO_CREATE);
        }//w w  w . j  a va2 s .com
    } else {
        containerActivity.startService(playlistIntent);
        containerActivity.bindService(playlistIntent, mConnection, Context.BIND_AUTO_CREATE);
    }
}

From source file:com.android.msahakyan.fma.fragment.TrackDetailFragment.java

@Override
public void onStart() {
    super.onStart();
    if (mPlayIntent == null) {
        mPlayIntent = new Intent(activity, MusicService.class);
        activity.bindService(mPlayIntent, mServiceConnection, Context.BIND_AUTO_CREATE);
    }/*from  www.  ja v a2s.  co m*/
}

From source file:at.alladin.rmbt.android.test.RMBTTestFragment.java

@Override
public void onStart() {
    super.onStart();

    getActivity().getActionBar().hide();
    ((RMBTMainActivity) getActivity()).setLockNavigationDrawer(true);

    // Bind to RMBTService
    final Intent serviceIntent = new Intent(context, RMBTService.class);
    context.bindService(serviceIntent, this, Context.BIND_AUTO_CREATE);

    handler.post(updateTask);/* w ww  . j a v a2 s .  c o  m*/

    //getActivity().getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
    getActivity().getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
}

From source file:com.hyechon.etrackermv.FaceTrackerActivity.java

/**
 * Initializes the UI and initiates the creation of a face detector.
 *//*from   ww w  .  j a  v a 2  s  . c o m*/
@Override
public void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    setContentView(R.layout.main);

    final Button btn_start = (Button) findViewById(R.id.start_button);
    final Button btn_google = (Button) findViewById(R.id.google_button);
    final Button btn_setting = (Button) findViewById(R.id.reset_button);
    mPreview = (CameraSourcePreview) findViewById(R.id.preview);
    mGraphicOverlay = (GraphicOverlay) findViewById(R.id.faceOverlay);

    setLayout();

    // ? ??
    mWebView.getSettings().setJavaScriptEnabled(true);
    // ? 
    mWebView.loadUrl("http://www.google.com");
    // WebViewClient 
    mWebView.setWebViewClient(new WebViewClientClass());

    btn_start.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            String start;

            if (start_flag == false) {
                btn_start.setText(" ");
                start_flag = true;
                if (device_flag == false) {
                    count_flag = true;
                } else {
                    count_flag_watch = true;
                    mConsumerService.sendData("1min,10"); //start flag
                }
                count_smartphone_blink = 0;
                count_eye_blink2 = 0;
                count_eye_blink_watch = 0;
                start = "start blink detection";
            } else {
                btn_start.setText(" ");
                if (count_flag_watch == true) {
                    mConsumerService.sendData("end");
                }
                start_flag = false;
                count_flag = false;
                count_flag_watch = false;
                count_eye_blink2 = 0;
                count_eye_blink = 0;
                start = "stop blink detection";
            }

            Toast.makeText(FaceTrackerActivity.this, start, Toast.LENGTH_SHORT).show();

            if (mIsBound == true && mConsumerService != null) {
                mConsumerService.findPeers();
            }

        }
    });

    btn_google.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            // Set the google url
            mWebView.loadUrl("http://www.google.com");

        }
    });

    btn_setting.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            count_put_get_FTAtoSA = count_set_SA;
            count_eye_blink2 = 0;
            count_eye_blink_watch = 0;

            if (mIsBound == true && mConsumerService != null) {
                if (mConsumerService.closeConnection() == false) {
                    /** tizen disconnected massage  **/
                    /* updateTextView("Disconnected");
                    Toast.makeText(getApplicationContext(), R.string.ConnectionAlreadyDisconnected, Toast.LENGTH_LONG).show();
                    mMessageAdapter.clear(); */
                }
            }
            Intent intent = new Intent(FaceTrackerActivity.this, SettingActivity.class);
            startActivity(intent);
        }
    });

    // Check for the camera permission before accessing the camera.  If the
    // permission is not granted yet, request permission.
    int rc = ActivityCompat.checkSelfPermission(this, Manifest.permission.CAMERA);
    if (rc == PackageManager.PERMISSION_GRANTED) {
        createCameraSource();
    } else {
        requestCameraPermission();
    }

    mThread = new BackThread(mHandler);
    mThread.setDaemon(true);
    mThread.start();

    /** Tizen **/
    mTextView = (TextView) findViewById(R.id.tvStatus);
    mMessageAdapter = new MessageAdapter();

    /** Bind service **/
    mIsBound = bindService(new Intent(FaceTrackerActivity.this, ConsumerService.class), mConnection,
            Context.BIND_AUTO_CREATE);
}

From source file:com.rks.musicx.ui.activities.MainActivity.java

@Override
protected void onStart() {
    super.onStart();
    Intent intent = new Intent(this, MusicXService.class);
    bindService(intent, mServiceConnection, Context.BIND_AUTO_CREATE);
    IntentFilter filter = new IntentFilter();
    filter.addAction(META_CHANGED);//from  w w  w . java2  s . co m
    filter.addAction(PLAYSTATE_CHANGED);
    filter.addAction(POSITION_CHANGED);
    filter.addAction(ITEM_ADDED);
    filter.addAction(ORDER_CHANGED);
    registerReceiver(broadcastReceiver, filter);
}

From source file:com.drinviewer.droiddrinviewer.ServerListFragment.java

/**
 * onResume Fragment method/*from   w ww.  j a va  2 s.  co  m*/
 */
@Override
public void onResume() {
    super.onResume();
    mustUpdateUI = true;

    try {
        if (discoverServerApi != null) {
            /**
             *  if the service is doing a discovery, just set the
             *  discoverServerProgress visibility to visible. 
             *  The service will call the listener when it has finished
             */
            if (discoverServerApi.isRunning()) {
                if (mActivity != null) {
                    mActivity.getMessageHandler().sendEmptyMessage(DroidDrinViewerConstants.MSG_DISCOVER_START);
                }
            } else {
                /**
                 * If the service is not doing a discovery,
                 * ask him for the most up-to-date host collection
                 * set it in the adapter and display it
                 */
                final DrinHostCollection newCollection = discoverServerApi.getMostUpToDateCollection();
                if (mActivity != null) {
                    mActivity.runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            if (newCollection != null) {
                                getAdapter().setHostCollection(newCollection);
                            } else {
                                getAdapter().initHostCollection();
                            }
                            getAdapter().notifyDataSetChanged();
                        }
                    });
                    /**
                     * either the hostcollection has been set or voided,
                     * turn off the discoverServerProgress
                     */
                    mActivity.getMessageHandler().sendEmptyMessage(DroidDrinViewerConstants.MSG_DISCOVER_DONE);
                }
            }
        } else {
            /**
             * Bind the DiscoverServerService if it is not, note that the onServiceConnected
             * method will send a startdiscovery message to the DrinViewerBroadcastReceiver
             * as soon as the service gets connected at startup
             */
            if (!isBound) {
                Intent intent = new Intent(mActivity.getApplication(), DiscoverServerService.class);
                intent.setAction(DiscoverServerService.class.getName());
                isBound = mActivity.getApplication().bindService(intent, this,
                        Context.BIND_AUTO_CREATE | Context.BIND_NOT_FOREGROUND);
            }
        }
    } catch (RemoteException e) {
        // ignore
        e.printStackTrace();
    }
}

From source file:it.baywaylabs.jumpersumo.MainActivity.java

private void initServices() {
    if (discoveryServiceBinder == null) {
        Intent i = new Intent(getApplicationContext(), ARDiscoveryService.class);
        getApplicationContext().bindService(i, ardiscoveryServiceConnection, Context.BIND_AUTO_CREATE);
    } else {/*from w  ww.j a v  a2 s  . c om*/
        ardiscoveryService = ((ARDiscoveryService.LocalBinder) discoveryServiceBinder).getService();
        ardiscoveryServiceBound = true;

        ardiscoveryService.start();
    }
}

From source file:co.realtime.ortc.OrtcModule.java

@Kroll.method
public void connect(String appKey, @Kroll.argument(optional = true) String authToken) {
    TiApplication appContext = TiApplication.getInstance();
    client.setApplicationContext(appContext.getApplicationContext());
    aKey = appKey;/*w  w w.j av a2  s .co m*/
    if (authToken == "" || authToken == null)
        authToken = "PM.Anonymous";
    aToken = authToken;

    Intent intent = new Intent(appContext, BackgroundService.class);
    appContext.bindService(intent, serviceConnection, Context.BIND_AUTO_CREATE);
    appContext.startService(intent);

    client.connect(appKey, aToken);
}

From source file:my.madet.uniteninfo.OpenVPN.java

/****** start of oncreate **/

@Override/*from w w  w .j  ava  2 s.com*/
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    rootView = inflater.inflate(R.layout.fragment_openvpn, container, false);
    // init progress dialog
    progressDialog = new ProgressDialog(rootView.getContext());
    // init sharedpref
    sharedPref = getActivity().getPreferences(Context.MODE_PRIVATE);

    dbHandler = new DatabaseHandler(rootView.getContext());
    studentEmail = dbHandler.getBiodata().get(DatabaseHandler.BIODATA_KEY_EMAIL);

    // show linked button
    linkAccountTextView = (TextView) rootView.findViewById(R.id.txtLabel2);
    linkAccountUserNameEditText = (EditText) rootView.findViewById(R.id.edittextUserName);
    linkAccountPasswordEditText = (EditText) rootView.findViewById(R.id.edittextPassword);
    linkAccountConnectButton = (Button) rootView.findViewById(R.id.buttonConnectToMyVpn);

    // subscribe and manage subcription button
    manageSubscriptionButton = (Button) rootView.findViewById(R.id.buttonManageSubs);
    subscribeButton = (Button) rootView.findViewById(R.id.buttonSubscribe);

    // generate developerPayload identifier
    if (sharedPref.getString("devPayloadId", "").equals("")) {
        // set the payload
        String data = studentEmail;
        SharedPreferences.Editor editor = sharedPref.edit();
        editor.putString("devPayloadId", data);
        editor.commit();
    }

    Intent serviceIntent = new Intent("com.android.vending.billing.InAppBillingService.BIND");
    serviceIntent.setPackage("com.android.vending");
    rootView.getContext().bindService(serviceIntent, mServiceConn, Context.BIND_AUTO_CREATE);

    subscribeButton.setOnClickListener(new SubscribeButtonClicked(rootView.getContext()));
    manageSubscriptionButton.setOnClickListener(new ManageSubscriptionButtonClicked(rootView.getContext()));

    return rootView;
}