Example usage for android.content Context AUDIO_SERVICE

List of usage examples for android.content Context AUDIO_SERVICE

Introduction

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

Prototype

String AUDIO_SERVICE

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

Click Source Link

Document

Use with #getSystemService(String) to retrieve a android.media.AudioManager for handling management of volume, ringer modes and audio routing.

Usage

From source file:com.android.tv.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    if (DEBUG)/*from   w  ww.jav  a 2s.c  o m*/
        Log.d(TAG, "onCreate()");
    super.onCreate(savedInstanceState);
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M && !PermissionUtils.hasAccessAllEpg(this)) {
        Toast.makeText(this, R.string.msg_not_supported_device, Toast.LENGTH_LONG).show();
        finish();
        return;
    }
    boolean skipToShowOnboarding = getIntent().getAction() == Intent.ACTION_VIEW
            && TvContract.isChannelUriForPassthroughInput(getIntent().getData());
    if (Features.ONBOARDING_EXPERIENCE.isEnabled(this) && OnboardingUtils.needToShowOnboarding(this)
            && !skipToShowOnboarding && !TvCommonUtils.isRunningInTest()) {
        // TODO: The onboarding is turned off in test, because tests are broken by the
        // onboarding. We need to enable the feature for tests later.
        startActivity(OnboardingActivity.buildIntent(this, getIntent()));
        finish();
        return;
    }

    TvApplication tvApplication = (TvApplication) getApplication();
    tvApplication.getMainActivityWrapper().onMainActivityCreated(this);
    if (BuildConfig.ENG && SystemProperties.ALLOW_STRICT_MODE.getValue()) {
        Toast.makeText(this, "Using Strict Mode for eng builds", Toast.LENGTH_SHORT).show();
    }
    mTracker = tvApplication.getTracker();
    mTvInputManagerHelper = tvApplication.getTvInputManagerHelper();
    mTvInputManagerHelper.addCallback(mTvInputCallback);
    mUsbTunerInputId = UsbTunerTvInputService.getInputId(this);
    mChannelDataManager = tvApplication.getChannelDataManager();
    mProgramDataManager = tvApplication.getProgramDataManager();
    mProgramDataManager.addOnCurrentProgramUpdatedListener(Channel.INVALID_ID,
            mOnCurrentProgramUpdatedListener);
    mProgramDataManager.setPrefetchEnabled(true);
    mChannelTuner = new ChannelTuner(mChannelDataManager, mTvInputManagerHelper);
    mChannelTuner.addListener(mChannelTunerListener);
    mChannelTuner.start();
    mPipInputManager = new PipInputManager(this, mTvInputManagerHelper, mChannelTuner);
    mPipInputManager.start();
    mMemoryManageables.add(mProgramDataManager);
    mMemoryManageables.add(ImageCache.getInstance());
    mMemoryManageables.add(TvContentRatingCache.getInstance());
    if (CommonFeatures.DVR.isEnabled(this) && BuildCompat.isAtLeastN()) {
        mDvrManager = tvApplication.getDvrManager();
        mDvrDataManager = tvApplication.getDvrDataManager();
    }

    DisplayManager displayManager = (DisplayManager) getSystemService(Context.DISPLAY_SERVICE);
    Display display = displayManager.getDisplay(Display.DEFAULT_DISPLAY);
    Point size = new Point();
    display.getSize(size);
    int screenWidth = size.x;
    int screenHeight = size.y;
    mDefaultRefreshRate = display.getRefreshRate();

    mOverlayRootView = (OverlayRootView) getLayoutInflater().inflate(R.layout.overlay_root_view, null, false);
    setContentView(R.layout.activity_tv);
    mTvView = (TunableTvView) findViewById(R.id.main_tunable_tv_view);
    int shrunkenTvViewHeight = getResources().getDimensionPixelSize(R.dimen.shrunken_tvview_height);
    mTvView.initialize((AppLayerTvView) findViewById(R.id.main_tv_view), false, screenHeight,
            shrunkenTvViewHeight);
    mTvView.setOnUnhandledInputEventListener(new OnUnhandledInputEventListener() {
        @Override
        public boolean onUnhandledInputEvent(InputEvent event) {
            if (isKeyEventBlocked()) {
                return true;
            }
            if (event instanceof KeyEvent) {
                KeyEvent keyEvent = (KeyEvent) event;
                if (keyEvent.getAction() == KeyEvent.ACTION_DOWN && keyEvent.isLongPress()) {
                    if (onKeyLongPress(keyEvent.getKeyCode(), keyEvent)) {
                        return true;
                    }
                }
                if (keyEvent.getAction() == KeyEvent.ACTION_UP) {
                    return onKeyUp(keyEvent.getKeyCode(), keyEvent);
                } else if (keyEvent.getAction() == KeyEvent.ACTION_DOWN) {
                    return onKeyDown(keyEvent.getKeyCode(), keyEvent);
                }
            }
            return false;
        }
    });
    mTimeShiftManager = new TimeShiftManager(this, mTvView, mProgramDataManager, mTracker,
            new OnCurrentProgramUpdatedListener() {
                @Override
                public void onCurrentProgramUpdated(long channelId, Program program) {
                    updateMediaSession();
                    switch (mTimeShiftManager.getLastActionId()) {
                    case TimeShiftManager.TIME_SHIFT_ACTION_ID_REWIND:
                    case TimeShiftManager.TIME_SHIFT_ACTION_ID_FAST_FORWARD:
                    case TimeShiftManager.TIME_SHIFT_ACTION_ID_JUMP_TO_PREVIOUS:
                    case TimeShiftManager.TIME_SHIFT_ACTION_ID_JUMP_TO_NEXT:
                        updateChannelBannerAndShowIfNeeded(UPDATE_CHANNEL_BANNER_REASON_FORCE_SHOW);
                        break;
                    default:
                        updateChannelBannerAndShowIfNeeded(UPDATE_CHANNEL_BANNER_REASON_UPDATE_INFO);
                        break;
                    }
                }
            });

    mPipView = (TunableTvView) findViewById(R.id.pip_tunable_tv_view);
    mPipView.initialize((AppLayerTvView) findViewById(R.id.pip_tv_view), true, screenHeight,
            shrunkenTvViewHeight);

    if (!PermissionUtils.hasAccessWatchedHistory(this)) {
        WatchedHistoryManager watchedHistoryManager = new WatchedHistoryManager(getApplicationContext());
        watchedHistoryManager.start();
        mTvView.setWatchedHistoryManager(watchedHistoryManager);
    }
    mTvViewUiManager = new TvViewUiManager(this, mTvView, mPipView,
            (FrameLayout) findViewById(android.R.id.content), mTvOptionsManager);

    mPipView.setFixedSurfaceSize(screenWidth / 2, screenHeight / 2);
    mPipView.setBlockScreenType(TunableTvView.BLOCK_SCREEN_TYPE_SHRUNKEN_TV_VIEW);

    ViewGroup sceneContainer = (ViewGroup) findViewById(R.id.scene_container);
    mChannelBannerView = (ChannelBannerView) getLayoutInflater().inflate(R.layout.channel_banner,
            sceneContainer, false);
    mKeypadChannelSwitchView = (KeypadChannelSwitchView) getLayoutInflater()
            .inflate(R.layout.keypad_channel_switch, sceneContainer, false);
    InputBannerView inputBannerView = (InputBannerView) getLayoutInflater().inflate(R.layout.input_banner,
            sceneContainer, false);
    SelectInputView selectInputView = (SelectInputView) getLayoutInflater().inflate(R.layout.select_input,
            sceneContainer, false);
    selectInputView.setOnInputSelectedCallback(new OnInputSelectedCallback() {
        @Override
        public void onTunerInputSelected() {
            Channel currentChannel = mChannelTuner.getCurrentChannel();
            if (currentChannel != null && !currentChannel.isPassthrough()) {
                hideOverlays();
            } else {
                tuneToLastWatchedChannelForTunerInput();
            }
        }

        @Override
        public void onPassthroughInputSelected(TvInputInfo input) {
            Channel currentChannel = mChannelTuner.getCurrentChannel();
            String currentInputId = currentChannel == null ? null : currentChannel.getInputId();
            if (TextUtils.equals(input.getId(), currentInputId)) {
                hideOverlays();
            } else {
                tuneToChannel(Channel.createPassthroughChannel(input.getId()));
            }
        }

        private void hideOverlays() {
            getOverlayManager().hideOverlays(TvOverlayManager.FLAG_HIDE_OVERLAYS_KEEP_DIALOG
                    | TvOverlayManager.FLAG_HIDE_OVERLAYS_KEEP_SIDE_PANELS
                    | TvOverlayManager.FLAG_HIDE_OVERLAYS_KEEP_PROGRAM_GUIDE
                    | TvOverlayManager.FLAG_HIDE_OVERLAYS_KEEP_MENU
                    | TvOverlayManager.FLAG_HIDE_OVERLAYS_KEEP_FRAGMENT);
        }
    });
    mSearchFragment = new ProgramGuideSearchFragment();
    mOverlayManager = new TvOverlayManager(this, mChannelTuner, mKeypadChannelSwitchView, mChannelBannerView,
            inputBannerView, selectInputView, sceneContainer, mSearchFragment);

    mAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
    mAudioFocusStatus = AudioManager.AUDIOFOCUS_LOSS;

    mMediaSession = new MediaSession(this, MEDIA_SESSION_TAG);
    mMediaSession.setCallback(new MediaSession.Callback() {
        @Override
        public boolean onMediaButtonEvent(Intent mediaButtonIntent) {
            // Consume the media button event here. Should not send it to other apps.
            return true;
        }
    });
    mMediaSession
            .setFlags(MediaSession.FLAG_HANDLES_MEDIA_BUTTONS | MediaSession.FLAG_HANDLES_TRANSPORT_CONTROLS);
    mNowPlayingCardWidth = getResources().getDimensionPixelSize(R.dimen.notif_card_img_max_width);
    mNowPlayingCardHeight = getResources().getDimensionPixelSize(R.dimen.notif_card_img_height);

    mTvViewUiManager.restoreDisplayMode(false);
    if (!handleIntent(getIntent())) {
        finish();
        return;
    }

    mAudioCapabilitiesReceiver = new AudioCapabilitiesReceiver(this,
            new AudioCapabilitiesReceiver.OnAc3PassthroughCapabilityChangeListener() {
                @Override
                public void onAc3PassthroughCapabilityChange(boolean capability) {
                    mAc3PassthroughSupported = capability;
                }
            });
    mAudioCapabilitiesReceiver.register();

    mAccessibilityManager = (AccessibilityManager) getSystemService(Context.ACCESSIBILITY_SERVICE);
    mSendConfigInfoRecurringRunner = new RecurringRunner(this, TimeUnit.DAYS.toMillis(1),
            new SendConfigInfoRunnable(mTracker, mTvInputManagerHelper), null);
    mSendConfigInfoRecurringRunner.start();
    mChannelStatusRecurringRunner = SendChannelStatusRunnable.startChannelStatusRecurringRunner(this, mTracker,
            mChannelDataManager);

    // To avoid not updating Rating systems when changing language.
    mTvInputManagerHelper.getContentRatingsManager().update();

    initForTest();
}

From source file:com.thejoshwa.ultrasonic.androidapp.util.Util.java

public static void registerMediaButtonEventReceiver(Context context) {
    if (getMediaButtonsPreference(context)) {
        AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
        audioManager.registerMediaButtonEventReceiver(
                new ComponentName(context.getPackageName(), MediaButtonIntentReceiver.class.getName()));

    }//from   www .  j  av  a2s  .  c om
}

From source file:com.nest5.businessClient.Initialactivity.java

/**
 * Begins the activity./*ww  w.  ja v  a  2  s. c  o  m*/
 */
@Override
public void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    this.savedInstanceState = savedInstanceState;
    getWindow().setFormat(PixelFormat.RGBA_8888);
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_DITHER);
    BugSenseHandler.initAndStartSession(Initialactivity.this, "1a5a6af1");
    setContentView(R.layout.swipe_view);
    checkLogin();
    // add necessary intent values to be matched.

    intentFilter.addAction(WifiP2pManager.WIFI_P2P_STATE_CHANGED_ACTION);
    intentFilter.addAction(WifiP2pManager.WIFI_P2P_PEERS_CHANGED_ACTION);
    intentFilter.addAction(WifiP2pManager.WIFI_P2P_CONNECTION_CHANGED_ACTION);
    intentFilter.addAction(WifiP2pManager.WIFI_P2P_THIS_DEVICE_CHANGED_ACTION);

    manager = (WifiP2pManager) getSystemService(Context.WIFI_P2P_SERVICE);
    channel = manager.initialize(this, getMainLooper(), null);
    mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
    dbHelper = new MySQLiteHelper(this);
    ingredientCategoryDatasource = new IngredientCategoryDataSource(dbHelper);
    db = ingredientCategoryDatasource.open();
    ingredientCategories = ingredientCategoryDatasource.getAllIngredientCategory();
    // ingredientCategoryDatasource.close();
    productCategoryDatasource = new ProductCategoryDataSource(dbHelper);
    productCategoryDatasource.open(db);
    productsCategories = productCategoryDatasource.getAllProductCategory();
    taxDataSource = new TaxDataSource(dbHelper);
    taxDataSource.open(db);
    taxes = taxDataSource.getAllTax();
    unitDataSource = new UnitDataSource(dbHelper);
    unitDataSource.open(db);
    units = unitDataSource.getAllUnits();
    ingredientDatasource = new IngredientDataSource(dbHelper);
    ingredientDatasource.open(db);
    ingredientes = ingredientDatasource.getAllIngredient();
    productDatasource = new ProductDataSource(dbHelper);
    productDatasource.open(db);
    productos = productDatasource.getAllProduct();
    comboDatasource = new ComboDataSource(dbHelper);
    comboDatasource.open(db);
    combos = comboDatasource.getAllCombos();
    saleDataSource = new SaleDataSource(dbHelper);
    saleDataSource.open(db);
    saleList = saleDataSource.getAllSales();
    syncRowDataSource = new SyncRowDataSource(dbHelper);
    syncRowDataSource.open(db);

    Calendar today = Calendar.getInstance();
    Calendar tomorrow = Calendar.getInstance();
    today.set(Calendar.HOUR, 0);
    today.set(Calendar.HOUR_OF_DAY, 0);
    today.set(Calendar.MINUTE, 0);
    today.set(Calendar.SECOND, 0);
    today.set(Calendar.MILLISECOND, 0);
    tomorrow.roll(Calendar.DATE, 1);
    tomorrow.set(Calendar.HOUR, 0);
    tomorrow.set(Calendar.HOUR_OF_DAY, 0);
    tomorrow.set(Calendar.MINUTE, 0);
    tomorrow.set(Calendar.SECOND, 0);
    tomorrow.set(Calendar.MILLISECOND, 0);

    init = today.getTimeInMillis();
    end = tomorrow.getTimeInMillis();
    //Log.d(TAG, today.toString());
    //Log.d(TAG, tomorrow.toString());
    Calendar now = Calendar.getInstance();
    now.setTimeInMillis(System.currentTimeMillis());
    //Log.d(TAG, now.toString());

    //Log.d(TAG, "Diferencia entre tiempos: " + String.valueOf(end - init));
    salesFromToday = saleDataSource.getAllSalesWithin(init, end);
    updateRegistrables();
    // ingredientDatasource.close();
    mDemoCollectionPagerAdapter = new DemoCollectionPagerAdapter(getSupportFragmentManager());
    mViewPager = (ViewPager) findViewById(R.id.pager);
    mViewPager.setAdapter(mDemoCollectionPagerAdapter);

    mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
        @Override
        public void onPageSelected(int position) {
            // When swiping between pages, select the
            // corresponding tab.
            getActionBar().setSelectedNavigationItem(position);

        }
    });

    final ActionBar actionBar = getActionBar();
    // Specify that tabs should be displayed in the action bar.
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

    // Create a tab listener that is called when the user changes tabs.
    ActionBar.TabListener tabListener = new ActionBar.TabListener() {

        @Override
        public void onTabReselected(Tab tab, FragmentTransaction ft) {
            // TODO Auto-generated method stub

        }

        @Override
        public void onTabSelected(Tab tab, FragmentTransaction ft) {
            mViewPager.setCurrentItem(tab.getPosition());

        }

        @Override
        public void onTabUnselected(Tab tab, FragmentTransaction ft) {
            // TODO Auto-generated method stub

        }

    };

    Tab homeTab = actionBar.newTab().setText("Inicio").setTabListener(tabListener);
    Tab ordersTab = actionBar.newTab().setText("rdenes").setTabListener(tabListener);
    /*Tab dailyTab = actionBar.newTab().setText("Registros")
    .setTabListener(tabListener);
    Tab inventoryTab = actionBar.newTab().setText("Inventarios")
    .setTabListener(tabListener);*/
    Tab nest5ReadTab = actionBar.newTab().setText("Nest5").setTabListener(tabListener);
    actionBar.addTab(homeTab, true);
    actionBar.addTab(ordersTab, false);
    //actionBar.addTab(dailyTab, false);
    //actionBar.addTab(inventoryTab, false);
    actionBar.addTab(nest5ReadTab, false);

    currentOrder = new LinkedHashMap<Registrable, Integer>();
    inTableRegistrable = new ArrayList<Registrable>();
    savedOrders = new LinkedHashMap<String, LinkedHashMap<Registrable, Integer>>();
    cookingOrders = new LinkedList<LinkedHashMap<Registrable, Integer>>();
    //cookingOrdersMethods = new LinkedHashMap<LinkedHashMap<Registrable, Integer>, String>();
    cookingOrdersDelivery = new LinkedHashMap<LinkedHashMap<Registrable, Integer>, Integer>();
    cookingOrdersTogo = new LinkedHashMap<LinkedHashMap<Registrable, Integer>, Integer>();
    //cookingOrdersTip = new LinkedHashMap<LinkedHashMap<Registrable, Integer>, Integer>();
    //cookingOrdersDiscount = new LinkedHashMap<LinkedHashMap<Registrable, Integer>, Double>();
    cookingOrdersTimes = new LinkedHashMap<LinkedHashMap<Registrable, Integer>, Long>();
    cookingOrdersTable = new LinkedHashMap<LinkedHashMap<Registrable, Integer>, CurrentTable<Table, Integer>>();
    openTables = new LinkedList<CurrentTable<Table, Integer>>();
    //cookingOrdersReceived = new LinkedHashMap<LinkedHashMap<Registrable, Integer>, Double>();
    frases = getResources().getStringArray(R.array.phrases);
    timer = new Timer();
    deviceID = DeviceID.getDeviceId(mContext);
    //////Log.i("AACCCAAAID",deviceID);
    BebasFont = Typeface.createFromAsset(getAssets(), "fonts/BebasNeue.otf");
    VarelaFont = Typeface.createFromAsset(getAssets(), "fonts/Varela-Regular.otf");
    // Lector de tarjetas magnticas
    mAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
    //mReader = new ACR31Reader(mAudioManager);
    /* Initialize the reset progress dialog */

    mResetProgressDialog = new ProgressDialog(mContext);

    // ACR31 RESET CALLBACK
    /*mReader.setOnResetCompleteListener(new ACR31Reader.OnResetCompleteListener() {
            
               
       //hola como estas
       @Override
       public void onResetComplete(ACR31Reader reader) {
            
    if (mSettingSleepTimeout) {
            
            
       mGettingStatus = true;
            
            
       mReader.setSleepTimeout(mSleepTimeout);
       mSettingSleepTimeout = false;
    }
            
    runOnUiThread(new Runnable() {
            
       @Override
       public void run() {
          mResetProgressDialog.dismiss();
       };
    });
       }
    });*/
    /* Set the raw data callback. */
    /*mReader.setOnRawDataAvailableListener(new ACR31Reader.OnRawDataAvailableListener() {
            
       @Override
       public void onRawDataAvailable(ACR31Reader reader, byte[] rawData) {
    ////Log.i("MISPRUEBAS", "setOnRawDataAvailableListener");
            
    final String hexString = toHexString(rawData)
          + (reader.verifyData(rawData) ? " (Checksum OK)"
                : " (Checksum Error)");
            
    ////Log.i("MISPRUEBAS", hexString);
    if (reader.verifyData(rawData)) {
       runOnUiThread(new Runnable() {
            
          @Override
          public void run() {
            
             mResetProgressDialog
                   .setMessage("Solicitando Informacin al Servidor...");
             mResetProgressDialog.setCancelable(false);
             mResetProgressDialog.setIndeterminate(true);
             mResetProgressDialog.show();
            
          }
       });
       SharedPreferences prefs = Util
             .getSharedPreferences(mContext);
            
       restService = new RestService(recievePromoandUserHandler,
             mContext, Setup.PROD_URL
                   + "/company/initMagneticStamp");
       restService.addParam("company",
             prefs.getString(Setup.COMPANY_ID, "0"));
       restService.addParam("magnetic5", hexString);
       restService.setCredentials("apiadmin", Setup.apiKey);
       try {
          restService.execute(RestService.POST);
       } catch (Exception e) {
          e.printStackTrace();
          ////Log.i("MISPRUEBAS", "Error empezando request");
       }
    }
            
       }
    });*/

}

From source file:com.thejoshwa.ultrasonic.androidapp.util.Util.java

public static void unregisterMediaButtonEventReceiver(Context context) {
    AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
    audioManager.unregisterMediaButtonEventReceiver(
            new ComponentName(context.getPackageName(), MediaButtonIntentReceiver.class.getName()));
}

From source file:com.wso2.mobile.mdm.services.PolicyTester.java

private boolean isMuted() {
    AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
    if (audioManager.getStreamVolume(AudioManager.STREAM_RING) != 0) {
        return false;
    } else {//  w w  w .  ja v  a  2s  .  c  o  m
        return true;
    }
}

From source file:com.speedtong.example.ui.chatting.ChattingActivity.java

private void initToneGenerator() {
    AudioManager mAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
    if (mToneGenerator == null) {
        try {/*from  w w w .  ja v  a2  s. c o  m*/
            int streamVolume = mAudioManager.getStreamVolume(AudioManager.STREAM_MUSIC);
            int streamMaxVolume = mAudioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
            int volume = (int) (TONE_RELATIVE_VOLUME * (streamVolume / streamMaxVolume));
            mToneGenerator = new ToneGenerator(AudioManager.STREAM_MUSIC, volume);

        } catch (RuntimeException e) {
            LogUtil.d("Exception caught while creating local tone generator: " + e);
            mToneGenerator = null;
        }
    }
}

From source file:com.sentaroh.android.TaskAutomation.TaskExecutor.java

final static private void executeBuiltinActionPrimitive(TaskManagerParms taskMgrParms,
        EnvironmentParms envParms, CommonUtilities util, TaskResponse taskResponse, ActionResponse ar,
        String bia, String dlg_id, String en, String tn) {
    if (bia.equals(BUILTIN_ACTION_WIFI_ON)) {
        taskResponse.active_thread_ctrl.setThreadMessage(BUILTIN_ACTION_WIFI_ON);
        setWifiOn(taskMgrParms, envParms, util, taskResponse, ar);
    } else if (bia.equals(BUILTIN_ACTION_WIFI_OFF)) {
        taskResponse.active_thread_ctrl.setThreadMessage(BUILTIN_ACTION_WIFI_OFF);
        setWifiOff(taskMgrParms, envParms, util, taskResponse, ar);
    } else if (bia.equals(BUILTIN_ACTION_WIFI_DISABLE_CONNECTED_SSID)) {
        taskResponse.active_thread_ctrl.setThreadMessage(BUILTIN_ACTION_WIFI_DISABLE_CONNECTED_SSID);
        setWifiDisableSsid(taskMgrParms, envParms, util, taskResponse, ar);
    } else if (bia.equals(BUILTIN_ACTION_WIFI_REMOVE_CONNECTED_SSID)) {
        taskResponse.active_thread_ctrl.setThreadMessage(BUILTIN_ACTION_WIFI_REMOVE_CONNECTED_SSID);
        setWifiRemoveSsid(taskMgrParms, envParms, util, taskResponse, ar);
    } else if (bia.equals(BUILTIN_ACTION_BLUETOOTH_ON)) {
        taskResponse.active_thread_ctrl.setThreadMessage(BUILTIN_ACTION_BLUETOOTH_ON);
        setBluetoothOn(taskMgrParms, envParms, util, taskResponse, ar);
    } else if (bia.equals(BUILTIN_ACTION_BLUETOOTH_OFF)) {
        taskResponse.active_thread_ctrl.setThreadMessage(BUILTIN_ACTION_BLUETOOTH_OFF);
        setBluetoothOff(taskMgrParms, envParms, util, taskResponse, ar);
    } else if (bia.equals(BUILTIN_ACTION_WAIT_1_SEC)) {
        waitTimeTc(taskResponse, 1 * 1000);
        if (!taskResponse.active_thread_ctrl.isEnable()) {
            ar.action_resp = ActionResponse.ACTION_CANCELLED;
            ar.resp_msg_text = "Action was cancelled";
        }/*  ww  w  .j  av  a 2s. c  o  m*/
    } else if (bia.equals(BUILTIN_ACTION_WAIT_5_SEC)) {
        waitTimeTc(taskResponse, 5 * 1000);
        if (!taskResponse.active_thread_ctrl.isEnable()) {
            ar.action_resp = ActionResponse.ACTION_CANCELLED;
            ar.resp_msg_text = "Action was cancelled";
        }
    } else if (bia.equals(BUILTIN_ACTION_WAIT_1_MIN)) {
        waitTimeTc(taskResponse, 1 * 60 * 1000);
        if (!taskResponse.active_thread_ctrl.isEnable()) {
            ar.action_resp = ActionResponse.ACTION_CANCELLED;
            ar.resp_msg_text = "Action was cancelled";
        }
    } else if (bia.equals(BUILTIN_ACTION_WAIT_5_MIN)) {
        waitTimeTc(taskResponse, 5 * 60 * 1000);
        if (!taskResponse.active_thread_ctrl.isEnable()) {
            ar.action_resp = ActionResponse.ACTION_CANCELLED;
            ar.resp_msg_text = "Action was cancelled";
        }
    } else if (bia.equals(BUILTIN_ACTION_SWITCH_TO_HOME)) {
        setScreenSwitchToHome(taskMgrParms, envParms, util, taskResponse, ar);
    } else if (bia.equals(BUILTIN_ACTION_SCREEN_LOCK)) {
        setScreenLocked(taskMgrParms, util, taskResponse, ar);
    } else if (bia.equals(BUILTIN_ACTION_SCREEN_ON)) {
        screenOnSync(taskMgrParms, taskResponse, ar);
    } else if (bia.equals(BUILTIN_ACTION_SCREEN_ON_ASYNC)) {
        screenOnAsync(taskMgrParms, taskResponse, ar);
    } else if (bia.equals(BUILTIN_ACTION_PLAYBACK_DEFAULT_ALARM)) {
        playBackDefaultAlarm(taskMgrParms, envParms, util, taskResponse, ar);
    } else if (bia.equals(BUILTIN_ACTION_PLAYBACK_DEFAULT_NOTIFICATION)) {
        playBackDefaultNotification(taskMgrParms, envParms, util, taskResponse, ar);
    } else if (bia.equals(BUILTIN_ACTION_PLAYBACK_DEFAULT_RINGTONE)) {
        playBackDefaultRingtone(taskMgrParms, envParms, util, taskResponse, ar);
    } else if (bia.equals(BUILTIN_ACTION_VIBRATE)) {
        vibrateDefaultPattern(taskMgrParms.context, ar);
    } else if (bia.equals(BUILTIN_ACTION_RESTART_SCHEDULER)) {
        sendCmdToService(taskResponse, BUILTIN_ACTION_RESTART_SCHEDULER, dlg_id,
                CMD_THREAD_TO_SVC_RESTART_SCHEDULER, BUILTIN_ACTION_RESTART_SCHEDULER);
    } else if (bia.equals(BUILTIN_ACTION_RINGER_NORMAL)) {
        AudioManager am = (AudioManager) taskMgrParms.context.getSystemService(Context.AUDIO_SERVICE);
        am.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
        //         am.setStreamMute(AudioManager.STREAM_MUSIC, false);
        //         am.setStreamMute(AudioManager.STREAM_RING, false);
        //         am.setStreamMute(AudioManager.STREAM_NOTIFICATION, false);
        //           am.setStreamMute(AudioManager.STREAM_SYSTEM, false);
        //           am.setStreamMute(AudioManager.STREAM_ALARM, false);
    } else if (bia.equals(BUILTIN_ACTION_RINGER_SILENT)) {
        AudioManager am = (AudioManager) taskMgrParms.context.getSystemService(Context.AUDIO_SERVICE);
        am.setRingerMode(AudioManager.RINGER_MODE_SILENT);
        //         am.setStreamMute(AudioManager.STREAM_MUSIC, true);
        //         am.setStreamMute(AudioManager.STREAM_RING, true);
        //         am.setStreamMute(AudioManager.STREAM_NOTIFICATION, true);
        //           am.setStreamMute(AudioManager.STREAM_SYSTEM, true);
        //           am.setStreamMute(AudioManager.STREAM_ALARM, true);
    } else if (bia.equals(BUILTIN_ACTION_RINGER_VIBRATE)) {
        AudioManager am = (AudioManager) taskMgrParms.context.getSystemService(Context.AUDIO_SERVICE);
        am.setRingerMode(AudioManager.RINGER_MODE_VIBRATE);
        //         am.setStreamMute(AudioManager.STREAM_MUSIC, true);
        //         am.setStreamMute(AudioManager.STREAM_RING, true);
        //         am.setStreamMute(AudioManager.STREAM_NOTIFICATION, true);
        //           am.setStreamMute(AudioManager.STREAM_SYSTEM, true);
        //           am.setStreamMute(AudioManager.STREAM_ALARM, true);
    } else if (bia.equals(BUILTIN_ACTION_AUTO_SYNC_ENABLED)) {
        setAutoSyncEnabled(taskMgrParms, envParms, util, taskResponse, ar);
    } else if (bia.equals(BUILTIN_ACTION_AUTO_SYNC_DISABLED)) {
        setAutoSyncDisabled(taskMgrParms, envParms, util, taskResponse, ar);
    } else if (bia.equals(BUILTIN_ACTION_ABORT)) {
        ar.action_resp = ActionResponse.ACTION_ABORT;
        ar.resp_msg_text = "Task was aborted";
    } else {
        ar.action_resp = ActionResponse.ACTION_ERROR;
        ar.resp_msg_text = String.format(taskMgrParms.teMsgs.msgs_thread_task_unknoww_action, bia);
    }
}

From source file:org.botlibre.sdk.activity.ChatActivity.java

public void submitChat() {

    ChatConfig config = new ChatConfig();
    config.instance = this.instance.id;
    config.conversation = MainActivity.conversation;
    config.speak = !MainActivity.deviceVoice;
    config.avatar = this.avatarId;
    if (MainActivity.translate && MainActivity.voice != null) {
        config.language = MainActivity.voice.language;
    }/*from  www .  j  a  v a 2  s . co m*/
    if (MainActivity.disableVideo) {
        config.avatarFormat = "image";
    } else {
        config.avatarFormat = MainActivity.webm ? "webm" : "mp4";
    }
    config.avatarHD = MainActivity.hd;

    EditText v = (EditText) findViewById(R.id.messageText);
    config.message = v.getText().toString().trim();
    if (config.message.equals("")) {
        return;
    }
    this.messages.add(config);
    runOnUiThread(new Runnable() {
        @Override
        public void run() {
            ListView list = (ListView) findViewById(R.id.chatList);
            ((ChatListAdapter) list.getAdapter()).notifyDataSetChanged();
            list.invalidateViews();
        }

    });

    Spinner emoteSpin = (Spinner) findViewById(R.id.emoteSpin);
    config.emote = emoteSpin.getSelectedItem().toString();

    HttpChatAction action = new HttpChatAction(ChatActivity.this, config);
    action.execute();

    v.setText("");
    emoteSpin.setSelection(0);
    resetToolbar();

    WebView responseView = (WebView) findViewById(R.id.responseText);
    responseView.loadDataWithBaseURL(null, "thinking...", "text/html", "utf-8", null);

    //Check the volume
    AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
    int volume = audioManager.getStreamVolume(AudioManager.STREAM_MUSIC);
    if (volume <= 3 && volumeChecked) {
        Toast.makeText(this, "Please check 'Media' volume", Toast.LENGTH_LONG).show();
        volumeChecked = false;
    }

    //stop letting the mic on.
    stopListening();
    //its Important for "sleep" "scream" ...etc commands.
    //this will turn off the mic
    MainActivity.listenInBackground = false;
}

From source file:com.lybeat.lilyplayer.widget.media.IjkVideoView.java

public void release(boolean cleartargetstate) {
    if (mMediaPlayer != null) {
        mMediaPlayer.reset();/* w ww . j  a v  a2  s  . c  o m*/
        mMediaPlayer.release();
        mMediaPlayer = null;
        // REMOVED: mPendingSubtitleTracks.clear();
        mCurrentState = STATE_IDLE;
        if (cleartargetstate) {
            mTargetState = STATE_IDLE;
        }
        AudioManager am = (AudioManager) mAppContext.getSystemService(Context.AUDIO_SERVICE);
        am.abandonAudioFocus(null);
    }
}

From source file:org.runbuddy.tomahawk.services.PlaybackService.java

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

    EventBus.getDefault().register(this);

    PipeLine.get();/*from w  w  w .ja v a  2  s.c  o m*/

    mMediaBrowserHelper = new MediaBrowserHelper(this);

    mMediaPlayers.put(AndroidMediaPlayer.class, new AndroidMediaPlayer());
    mMediaPlayers.put(VLCMediaPlayer.class, new VLCMediaPlayer());
    mMediaPlayers.put(DeezerMediaPlayer.class, new DeezerMediaPlayer());
    mMediaPlayers.put(SpotifyMediaPlayer.class, new SpotifyMediaPlayer());

    startService(new Intent(this, MicroService.class));

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        mRemoteControllerConnection = new RemoteControllerConnection();
        bindService(new Intent(this, RemoteControllerService.class), mRemoteControllerConnection,
                Context.BIND_AUTO_CREATE);
    }

    // Initialize WakeLock
    PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
    mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, TAG);

    mAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);

    mPlaybackManager = PlaybackManager.get(IdGenerator.getSessionUniqueStringId());
    mPlaybackManager.setCallback(mPlaybackManagerCallback);

    initMediaSession();

    try {
        mNotification = new MediaNotification(this);
    } catch (RemoteException e) {
        Log.e(TAG, "Could not connect to media controller: ", e);
    }

    Log.d(TAG, "PlaybackService has been created");
}