List of usage examples for android.content ComponentName ComponentName
private ComponentName(String pkg, Parcel in)
From source file:com.example.android.supportv4.media.QueueFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment_list, container, false); mSkipPrevious = (ImageButton) rootView.findViewById(R.id.skip_previous); mSkipPrevious.setEnabled(false);/*from w w w . j av a 2 s.c om*/ mSkipPrevious.setOnClickListener(mButtonListener); mSkipNext = (ImageButton) rootView.findViewById(R.id.skip_next); mSkipNext.setEnabled(false); mSkipNext.setOnClickListener(mButtonListener); mPlayPause = (ImageButton) rootView.findViewById(R.id.play_pause); mPlayPause.setEnabled(true); mPlayPause.setOnClickListener(mButtonListener); mQueueAdapter = new QueueAdapter(getActivity()); ListView mListView = (ListView) rootView.findViewById(R.id.list_view); mListView.setAdapter(mQueueAdapter); mListView.setFocusable(true); mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { MediaSessionCompat.QueueItem item = mQueueAdapter.getItem(position); mTransportControls.skipToQueueItem(item.getQueueId()); } }); mMediaBrowser = new MediaBrowserCompat(getActivity(), new ComponentName(getActivity(), MediaBrowserServiceSupport.class), mConnectionCallback, null); return rootView; }
From source file:jieehd.villain.updater.VillainUpdater.java
private boolean haveNetworkConnection() { boolean haveConnectedWifi = false; boolean haveConnectedMobile = false; ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo[] netInfo = cm.getAllNetworkInfo(); for (NetworkInfo ni : netInfo) { if (ni.getTypeName().equalsIgnoreCase("WIFI")) if (ni.isConnected()) haveConnectedWifi = true; if (ni.getTypeName().equalsIgnoreCase("MOBILE")) if (ni.isConnected()) haveConnectedMobile = true; }//from w w w . j a v a 2s .c om if (haveConnectedWifi == false && haveConnectedMobile == false) { Log.d("Network State", "false"); AlertDialog.Builder alert = new AlertDialog.Builder(VillainUpdater.this); alert.setTitle("No Data Connection!"); alert.setMessage( "You have no data connection, click ok to turn on WiFi or Mobile Data in order to check for OTA updates."); alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { // TODO Auto-generated method stub final Intent intent = new Intent(Intent.ACTION_MAIN, null); intent.addCategory(Intent.CATEGORY_LAUNCHER); final ComponentName cn = new ComponentName("com.android.settings", "com.android.settings.wifi.WifiSettings"); intent.setComponent(cn); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(intent); } }); alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { // TODO Auto-generated method stub return; } }); alert.show(); } else { download(); } return haveConnectedWifi || haveConnectedMobile; }
From source file:com.example.haizhu.myvoiceassistant.ui.RobotChatActivity.java
private void iniData() { globalPref = GlobalPref.getInstance(); TruingDataHandler.setListener(this); chatAdapter = new RobotChatAdapter(getApplicationContext(), resultList); initListener();//from ww w . j a v a 2 s. c o m speechRecognizer = SpeechRecognizer.createSpeechRecognizer(getApplicationContext(), new ComponentName(this, VoiceRecognitionService.class)); speechRecognizer.setRecognitionListener(recognitionListener); speechSynthesizer = new SpeechSynthesizer(AssistantApplication.getInstance().getApplicationContext(), "holder", speechSynthesizerListener); // ?setApiKey???apiKeysecretKey speechSynthesizer.setApiKey("DnBhRg9PvmNSs0a6OD4BHLAk", "8492ef7b1b435bce2b98e41c1023e67b"); speechSynthesizer.setAudioStreamType(AudioManager.STREAM_MUSIC); listener = new DrawerLayout.DrawerListener() { @Override public void onDrawerSlide(View drawerView, float slideOffset) { } @Override public void onDrawerOpened(View drawerView) { } @Override public void onDrawerClosed(View drawerView) { } @Override public void onDrawerStateChanged(int newState) { } }; }
From source file:com.example.android.mediabrowserservice.QueueFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment_list, container, false); mSkipPrevious = (ImageButton) rootView.findViewById(R.id.skip_previous); mSkipPrevious.setEnabled(false);/*from w ww . j a v a2 s. c o m*/ mSkipPrevious.setOnClickListener(mButtonListener); mSkipNext = (ImageButton) rootView.findViewById(R.id.skip_next); mSkipNext.setEnabled(false); mSkipNext.setOnClickListener(mButtonListener); mPlayPause = (ImageButton) rootView.findViewById(R.id.play_pause); mPlayPause.setEnabled(true); mPlayPause.setOnClickListener(mButtonListener); mQueueAdapter = new QueueAdapter(getActivity()); ListView mListView = (ListView) rootView.findViewById(R.id.list_view); mListView.setAdapter(mQueueAdapter); mListView.setFocusable(true); mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { MediaSessionCompat.QueueItem item = mQueueAdapter.getItem(position); mTransportControls.skipToQueueItem(item.getQueueId()); } }); mMediaBrowser = new MediaBrowserCompat(getActivity(), new ComponentName(getActivity(), MusicService.class), mConnectionCallback, null); return rootView; }
From source file:com.andreadec.musicplayer.MusicService.java
/** * Called when the service is created.//from ww w. j av a2 s .c om */ @Override public void onCreate() { PowerManager powerManager = (PowerManager) getSystemService(Context.POWER_SERVICE); wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "MusicServiceWakelock"); // Initialize the telephony manager telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE); phoneStateListener = new MusicPhoneStateListener(); notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); // Initialize pending intents quitPendingIntent = PendingIntent.getBroadcast(this, 0, new Intent("com.andreadec.musicplayer.quit"), 0); previousPendingIntent = PendingIntent.getBroadcast(this, 0, new Intent("com.andreadec.musicplayer.previous"), 0); playpausePendingIntent = PendingIntent.getBroadcast(this, 0, new Intent("com.andreadec.musicplayer.playpause"), 0); nextPendingIntent = PendingIntent.getBroadcast(this, 0, new Intent("com.andreadec.musicplayer.next"), 0); pendingIntent = PendingIntent.getActivity(this, 0, new Intent(this, MainActivity.class).setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP), PendingIntent.FLAG_UPDATE_CURRENT); // Read saved user preferences preferences = PreferenceManager.getDefaultSharedPreferences(this); // Initialize the media player mediaPlayer = new MediaPlayer(); mediaPlayer.setOnCompletionListener(this); mediaPlayer.setWakeMode(this, PowerManager.PARTIAL_WAKE_LOCK); // Enable the wake lock to keep CPU running when the screen is switched off shuffle = preferences.getBoolean(Constants.PREFERENCE_SHUFFLE, Constants.DEFAULT_SHUFFLE); repeat = preferences.getBoolean(Constants.PREFERENCE_REPEAT, Constants.DEFAULT_REPEAT); repeatAll = preferences.getBoolean(Constants.PREFERENCE_REPEATALL, Constants.DEFAULT_REPEATALL); try { // This may fail if the device doesn't support bass boost bassBoost = new BassBoost(1, mediaPlayer.getAudioSessionId()); bassBoost.setEnabled( preferences.getBoolean(Constants.PREFERENCE_BASSBOOST, Constants.DEFAULT_BASSBOOST)); setBassBoostStrength(preferences.getInt(Constants.PREFERENCE_BASSBOOSTSTRENGTH, Constants.DEFAULT_BASSBOOSTSTRENGTH)); bassBoostAvailable = true; } catch (Exception e) { bassBoostAvailable = false; } try { // This may fail if the device doesn't support equalizer equalizer = new Equalizer(1, mediaPlayer.getAudioSessionId()); equalizer.setEnabled( preferences.getBoolean(Constants.PREFERENCE_EQUALIZER, Constants.DEFAULT_EQUALIZER)); setEqualizerPreset( preferences.getInt(Constants.PREFERENCE_EQUALIZERPRESET, Constants.DEFAULT_EQUALIZERPRESET)); equalizerAvailable = true; } catch (Exception e) { equalizerAvailable = false; } random = new Random(System.nanoTime()); // Necessary for song shuffle shakeListener = new ShakeListener(this); if (preferences.getBoolean(Constants.PREFERENCE_SHAKEENABLED, Constants.DEFAULT_SHAKEENABLED)) { shakeListener.enable(); } telephonyManager.listen(phoneStateListener, PhoneStateListener.LISTEN_CALL_STATE); // Start listen for telephony events // Inizialize the audio manager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE); mediaButtonReceiverComponent = new ComponentName(getPackageName(), MediaButtonReceiver.class.getName()); audioManager.registerMediaButtonEventReceiver(mediaButtonReceiverComponent); audioManager.requestAudioFocus(null, AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN); // Initialize remote control client if (Build.VERSION.SDK_INT >= 14) { icon = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher); Intent mediaButtonIntent = new Intent(Intent.ACTION_MEDIA_BUTTON); mediaButtonIntent.setComponent(mediaButtonReceiverComponent); PendingIntent mediaPendingIntent = PendingIntent.getBroadcast(getApplicationContext(), 0, mediaButtonIntent, 0); remoteControlClient = new RemoteControlClient(mediaPendingIntent); remoteControlClient.setTransportControlFlags(RemoteControlClient.FLAG_KEY_MEDIA_PLAY_PAUSE | RemoteControlClient.FLAG_KEY_MEDIA_PREVIOUS | RemoteControlClient.FLAG_KEY_MEDIA_NEXT); audioManager.registerRemoteControlClient(remoteControlClient); } updateNotificationMessage(); IntentFilter intentFilter = new IntentFilter(); intentFilter.addAction("com.andreadec.musicplayer.quit"); intentFilter.addAction("com.andreadec.musicplayer.previous"); intentFilter.addAction("com.andreadec.musicplayer.previousNoRestart"); intentFilter.addAction("com.andreadec.musicplayer.playpause"); intentFilter.addAction("com.andreadec.musicplayer.next"); intentFilter.addAction(AudioManager.ACTION_AUDIO_BECOMING_NOISY); broadcastReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { String action = intent.getAction(); if (action.equals("com.andreadec.musicplayer.quit")) { sendBroadcast(new Intent("com.andreadec.musicplayer.quitactivity")); stopSelf(); return; } else if (action.equals("com.andreadec.musicplayer.previous")) { previousItem(false); } else if (action.equals("com.andreadec.musicplayer.previousNoRestart")) { previousItem(true); } else if (action.equals("com.andreadec.musicplayer.playpause")) { playPause(); } else if (action.equals("com.andreadec.musicplayer.next")) { nextItem(); } else if (action.equals(AudioManager.ACTION_AUDIO_BECOMING_NOISY)) { if (preferences.getBoolean(Constants.PREFERENCE_STOPPLAYINGWHENHEADSETDISCONNECTED, Constants.DEFAULT_STOPPLAYINGWHENHEADSETDISCONNECTED)) { pause(); } } } }; registerReceiver(broadcastReceiver, intentFilter); if (!isPlaying()) { loadLastSong(); } startForeground(Constants.NOTIFICATION_MAIN, notification); }
From source file:com.buddi.client.dfu.FeaturesActivity.java
private void setupPluginsInDrawer(final ViewGroup container) { final LayoutInflater inflater = LayoutInflater.from(this); final PackageManager pm = getPackageManager(); // look for Master Control Panel final Intent mcpIntent = new Intent(Intent.ACTION_MAIN); mcpIntent.setClassName(MCP_PACKAGE, MCP_CLASS); final ResolveInfo mcpInfo = pm.resolveActivity(mcpIntent, 0); // configure link to Master Control Panel final TextView mcpItem = (TextView) container.findViewById(R.id.link_mcp); if (mcpInfo == null) { mcpItem.setTextColor(Color.GRAY); ColorMatrix grayscale = new ColorMatrix(); grayscale.setSaturation(0.0f);/*from w w w . ja va 2s.c om*/ mcpItem.getCompoundDrawables()[0].setColorFilter(new ColorMatrixColorFilter(grayscale)); } mcpItem.setOnClickListener(new View.OnClickListener() { @Override public void onClick(final View v) { Intent action = mcpIntent; if (mcpInfo == null) action = new Intent(Intent.ACTION_VIEW, Uri.parse(MCP_MARKET_URI)); action.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION); try { startActivity(action); } catch (final ActivityNotFoundException e) { Toast.makeText(FeaturesActivity.this, R.string.no_application_play, Toast.LENGTH_SHORT).show(); } mDrawerLayout.closeDrawers(); } }); // look for other plug-ins final Intent utilsIntent = new Intent(Intent.ACTION_MAIN); utilsIntent.addCategory(UTILS_CATEGORY); final List<ResolveInfo> appList = pm.queryIntentActivities(utilsIntent, 0); for (final ResolveInfo info : appList) { final View item = inflater.inflate(R.layout.drawer_plugin, container, false); final ImageView icon = (ImageView) item.findViewById(android.R.id.icon); final TextView label = (TextView) item.findViewById(android.R.id.text1); label.setText(info.loadLabel(pm)); icon.setImageDrawable(info.loadIcon(pm)); item.setOnClickListener(new View.OnClickListener() { @Override public void onClick(final View v) { final Intent intent = new Intent(); intent.setComponent(new ComponentName(info.activityInfo.packageName, info.activityInfo.name)); intent.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION); startActivity(intent); mDrawerLayout.closeDrawers(); } }); container.addView(item); } }
From source file:com.akhbulatov.wordkeeper.ui.fragment.WordListFragment.java
@Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { inflater.inflate(R.menu.fragment_word, menu); MenuItem searchItem = menu.findItem(R.id.menu_search_word); SearchView searchView = (SearchView) searchItem.getActionView(); SearchManager searchManager = (SearchManager) getActivity().getSystemService(Context.SEARCH_SERVICE); searchView.setSearchableInfo(/*from ww w. j a v a2 s .c o m*/ searchManager.getSearchableInfo(new ComponentName(getActivity(), MainActivity.class))); searchView.setImeOptions(EditorInfo.IME_ACTION_SEARCH); searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() { @Override public boolean onQueryTextSubmit(String query) { return false; } @Override public boolean onQueryTextChange(String newText) { final Cursor cursor = mWordDbAdapter.getAll(sSortMode); final int column = cursor.getColumnIndex(WordEntry.COLUMN_NAME); if (newText.length() > 0) { mWordAdapter.swapCursor(new FilterCursorWrapper(cursor, newText, column)); mTextEmptyWordList.setVisibility(View.GONE); if (mWordAdapter.getItemCount() == 0) { String escapedNewText = TextUtils.htmlEncode(newText); String formattedNoResults = String.format(getString(R.string.no_results_word), escapedNewText); CharSequence styledNoResults = Html.fromHtml(formattedNoResults); mTextNoResultsWord.setText(styledNoResults); mTextNoResultsWord.setVisibility(View.VISIBLE); } else { mTextNoResultsWord.setVisibility(View.GONE); } } else { mWordAdapter.swapCursor(cursor); mTextNoResultsWord.setVisibility(View.GONE); if (mWordAdapter.getItemCount() == 0) { mTextEmptyWordList.setVisibility(View.VISIBLE); } } return true; } }); }
From source file:com.akhbulatov.wordkeeper.ui.fragment.CategoryListFragment.java
@Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { inflater.inflate(R.menu.fragment_category, menu); MenuItem searchItem = menu.findItem(R.id.menu_search_category); SearchView searchView = (SearchView) searchItem.getActionView(); SearchManager searchManager = (SearchManager) getActivity().getSystemService(Context.SEARCH_SERVICE); searchView.setSearchableInfo(/*from w ww .ja v a 2 s . com*/ searchManager.getSearchableInfo(new ComponentName(getActivity(), MainActivity.class))); searchView.setImeOptions(EditorInfo.IME_ACTION_SEARCH); searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() { @Override public boolean onQueryTextChange(String newText) { final Cursor cursor = mCategoryDbAdapter.getAll(); final int column = cursor.getColumnIndex(CategoryEntry.COLUMN_NAME); if (newText.length() > 0) { mCategoryAdapter.swapCursor(new FilterCursorWrapper(cursor, newText, column)); if (mCategoryAdapter.getItemCount() == 0) { String escapedNewText = TextUtils.htmlEncode(newText); String formattedNoResults = String.format(getString(R.string.no_results_category), escapedNewText); CharSequence styledNoResults = Html.fromHtml(formattedNoResults); mTextNoResultsCategory.setText(styledNoResults); mTextNoResultsCategory.setVisibility(View.VISIBLE); } else { mTextNoResultsCategory.setVisibility(View.GONE); } } else { mCategoryAdapter.swapCursor(cursor); mTextNoResultsCategory.setVisibility(View.GONE); } return true; } @Override public boolean onQueryTextSubmit(String query) { return false; } }); }
From source file:com.akalizakeza.apps.ishusho.activity.NewPostActivity.java
@AfterPermissionGranted(RC_CAMERA_PERMISSIONS) private void showImagePicker() { // Check for camera permissions if (!EasyPermissions.hasPermissions(this, cameraPerms)) { EasyPermissions.requestPermissions(this, "This sample will upload a picture from your Camera", RC_CAMERA_PERMISSIONS, cameraPerms); return;// w ww.j ava 2 s . c o m } // Choose file storage location File file = new File(getExternalCacheDir(), UUID.randomUUID().toString()); mFileUri = Uri.fromFile(file); // Camera final List<Intent> cameraIntents = new ArrayList<Intent>(); final Intent captureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); final PackageManager packageManager = getPackageManager(); final List<ResolveInfo> listCam = packageManager.queryIntentActivities(captureIntent, 0); for (ResolveInfo res : listCam) { final String packageName = res.activityInfo.packageName; final Intent intent = new Intent(captureIntent); intent.setComponent(new ComponentName(packageName, res.activityInfo.name)); intent.setPackage(packageName); intent.putExtra(MediaStore.EXTRA_OUTPUT, mFileUri); cameraIntents.add(intent); } // Image Picker Intent pickerIntent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI); Intent chooserIntent = Intent.createChooser(pickerIntent, getString(R.string.picture_chooser_title)); chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, cameraIntents.toArray(new Parcelable[cameraIntents.size()])); startActivityForResult(chooserIntent, TC_PICK_IMAGE); }