Example usage for android.content ComponentName ComponentName

List of usage examples for android.content ComponentName ComponentName

Introduction

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

Prototype

private ComponentName(String pkg, Parcel in) 

Source Link

Usage

From source file:com.dmplayer.manager.MusicPlayerService.java

@SuppressLint("NewApi")
@Override/*from   w  w  w  .j av a2 s.  c om*/
public int onStartCommand(Intent intent, int flags, int startId) {
    try {
        SongDetail messageObject = MediaController.getInstance().getPlayingSongDetail();
        if (messageObject == null) {
            DMPlayerUtility.runOnUIThread(new Runnable() {
                @Override
                public void run() {
                    stopSelf();
                }
            });
            return START_STICKY;
        }
        if (supportLockScreenControls) {
            ComponentName remoteComponentName = new ComponentName(getApplicationContext(),
                    MusicPlayerReceiver.class.getName());
            try {
                if (remoteControlClient == null) {
                    audioManager.registerMediaButtonEventReceiver(remoteComponentName);
                    Intent mediaButtonIntent = new Intent(Intent.ACTION_MEDIA_BUTTON);
                    mediaButtonIntent.setComponent(remoteComponentName);
                    PendingIntent mediaPendingIntent = PendingIntent.getBroadcast(this, 0, mediaButtonIntent,
                            0);
                    remoteControlClient = new RemoteControlClient(mediaPendingIntent);
                    audioManager.registerRemoteControlClient(remoteControlClient);
                }
                remoteControlClient.setTransportControlFlags(RemoteControlClient.FLAG_KEY_MEDIA_PLAY
                        | RemoteControlClient.FLAG_KEY_MEDIA_PAUSE
                        | RemoteControlClient.FLAG_KEY_MEDIA_PLAY_PAUSE
                        | RemoteControlClient.FLAG_KEY_MEDIA_STOP | RemoteControlClient.FLAG_KEY_MEDIA_PREVIOUS
                        | RemoteControlClient.FLAG_KEY_MEDIA_NEXT);
            } catch (Exception e) {
                Log.e("tmessages", e.toString());
            }
        }
        createNotification(messageObject);
    } catch (Exception e) {
        e.printStackTrace();
    }
    return START_STICKY;
}

From source file:com.dm.material.dashboard.candybar.adapters.IntentAdapter.java

@Override
public View getView(final int position, View view, ViewGroup viewGroup) {
    ViewHolder holder;/*www. j av  a  2  s  .co m*/
    if (view == null) {
        view = View.inflate(mContext, R.layout.fragment_intent_chooser_item_list, null);
        holder = new ViewHolder(view);
        view.setTag(holder);
    } else {
        holder = (ViewHolder) view.getTag();
        holder.divider.setVisibility(View.VISIBLE);
    }

    holder.icon.setImageDrawable(DrawableHelper.getAppIcon(mContext, mApps.get(position).getApp()));
    holder.name.setText(mApps.get(position).getApp().loadLabel(mContext.getPackageManager()).toString());

    if (position == mApps.size() - 1) {
        holder.divider.setVisibility(View.GONE);
    }

    if (mApps.get(position).getType() == IntentChooser.TYPE_SUPPORTED) {
        holder.type.setTextColor(ColorHelper.getAttributeColor(mContext, android.R.attr.textColorSecondary));
        holder.type.setText(mContext.getResources().getString(R.string.intent_email_supported));
    } else if (mApps.get(position).getType() == IntentChooser.TYPE_RECOMMENDED) {
        holder.type.setTextColor(ColorHelper.getAttributeColor(mContext, R.attr.colorAccent));
        holder.type.setText(mContext.getResources().getString(R.string.intent_email_recommended));
    } else {
        holder.type.setTextColor(Color.parseColor("#F44336"));
        holder.type.setText(mContext.getResources().getString(R.string.intent_email_not_supported));
    }

    holder.container.setOnClickListener(v -> {
        ActivityInfo app = mApps.get(position).getApp().activityInfo;
        if (mApps.get(position).getType() == IntentChooser.TYPE_RECOMMENDED
                || mApps.get(position).getType() == IntentChooser.TYPE_SUPPORTED) {
            ComponentName name = new ComponentName(app.applicationInfo.packageName, app.name);
            sendRequest(name);

            FragmentManager fm = ((AppCompatActivity) mContext).getSupportFragmentManager();
            if (fm != null) {
                DialogFragment dialog = (DialogFragment) fm.findFragmentByTag(IntentChooserFragment.TAG);
                if (dialog != null) {
                    dialog.dismiss();
                }
            }
            return;
        }

        Toast.makeText(mContext, R.string.intent_email_not_supported_message, Toast.LENGTH_LONG).show();
    });

    return view;
}

From source file:co.edu.uniajc.vtf.content.NavigationActivity.java

@Override
protected void onResume() {
    super.onResume();
    ComponentName loComponent = new ComponentName(this, NetworkStatusReceiver.class);
    this.getPackageManager().setComponentEnabledSetting(loComponent,
            PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP);
    LatLng loDestiny = new LatLng(this.coDestiny.getLatitude(), this.coDestiny.getLongitude());

    if (this.coCurrentPosition != null) {
        coLatlngBounds = createLatLngBoundsObject(this.coCurrentPosition, loDestiny);
        coMap.moveCamera(CameraUpdateFactory.newLatLngBounds(coLatlngBounds, ciWidth, ciHeight, 150));
    }/*from   ww w .java 2s.  c o  m*/
}

From source file:com.dycody.android.idealnote.BaseActivity.java

/**
 * Notifies App Widgets about data changes so they can update theirselves
 *///from   w w w. j a va2  s .  c  o  m
public static void notifyAppWidgets(Context context) {
    // Home widgets
    AppWidgetManager mgr = AppWidgetManager.getInstance(context);
    int[] ids = mgr.getAppWidgetIds(new ComponentName(context, ListWidgetProvider.class));
    Log.d(Constants.TAG, "Notifies AppWidget data changed for widgets " + Arrays.toString(ids));
    mgr.notifyAppWidgetViewDataChanged(ids, R.id.widget_list);

    // Dashclock
    LocalBroadcastManager.getInstance(context).sendBroadcast(new Intent(Constants.INTENT_UPDATE_DASHCLOCK));
}

From source file:com.ppdl.microphone.MainActivity.java

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

    SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this);
    sp.edit().remove(Constant.EXTRA_INFILE).commit(); // infile?PCM?????

    Button recordButton = (Button) findViewById(R.id.buttonRecord);
    recordButton.setOnTouchListener(new View.OnTouchListener() {

        @Override//from www .j a v a 2 s . com
        public boolean onTouch(View v, MotionEvent event) {
            switch (event.getAction()) {
            case MotionEvent.ACTION_DOWN:
                startRecording();
                Toast.makeText(MainActivity.this, "Start Recording", Toast.LENGTH_SHORT).show();
                break;

            case MotionEvent.ACTION_UP:
                stopRecording();
                v.performClick();
                Toast.makeText(MainActivity.this, "Stop Recording", Toast.LENGTH_SHORT).show();
                break;

            default:
                break;
            }
            return false;
        }
    });

    Button playButton = (Button) findViewById(R.id.buttonPlay);
    playButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            startPlaying();
        }
    });

    Button stopButton = (Button) findViewById(R.id.buttonStop);
    stopButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            stopPlaying();
        }
    });

    Button recognizeButton = (Button) findViewById(R.id.buttonRecognize);
    recognizeButton.setOnTouchListener(new View.OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            switch (event.getAction()) {
            case MotionEvent.ACTION_DOWN:
                Toast.makeText(MainActivity.this, "Start Recognizing", Toast.LENGTH_SHORT).show();
                speechRecognizer.cancel();
                Intent intent = new Intent();
                bindParams(intent);
                intent.putExtra("vad", "touch");
                speechRecognizer.startListening(intent);
                break;

            case MotionEvent.ACTION_UP:
                v.performClick();
                Toast.makeText(MainActivity.this, "Stop Recognizing", Toast.LENGTH_SHORT).show();
                speechRecognizer.stopListening();
                break;

            default:
                break;
            }
            return false;
        }
    });

    speechRecognizer = SpeechRecognizer.createSpeechRecognizer(this,
            new ComponentName(this, VoiceRecognitionService.class));
    speechRecognizer.setRecognitionListener(mRecognitionListner);
}

From source file:com.abhijitvalluri.android.fitnotifications.widget.ServiceToggle.java

@Override
public void onReceive(Context context, Intent intent) {
    super.onReceive(context, intent);

    if (TOGGLE_CLICKED.equals(intent.getAction())) {
        AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
        RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.service_toggle_widget);
        if (NLService.isEnabled()) {
            NLService.setEnabled(false);
            views.setImageViewResource(R.id.widgetToggleButton, R.drawable.ic_speaker_notes_off_white_48dp);
            views.setInt(R.id.widgetToggleButton, "setBackgroundResource", R.drawable.round_rectangle_red);
            views.setTextViewText(R.id.widgetToggleText, context.getString(R.string.widget_off_text));
            views.setTextColor(R.id.widgetToggleText, ContextCompat.getColor(context, R.color.red));
        } else {//from  w  ww.ja  v  a2 s . c  om
            NLService.setEnabled(true);
            views.setImageViewResource(R.id.widgetToggleButton, R.drawable.ic_speaker_notes_white_48dp);
            views.setInt(R.id.widgetToggleButton, "setBackgroundResource", R.drawable.round_rectangle_green);
            views.setTextViewText(R.id.widgetToggleText, context.getString(R.string.widget_on_text));
            views.setTextColor(R.id.widgetToggleText, ContextCompat.getColor(context, R.color.green));
        }

        views.setOnClickPendingIntent(R.id.widgetToggleButton,
                getPendingSelfIntent(context, 0, TOGGLE_CLICKED));

        ComponentName componentName = new ComponentName(context, ServiceToggle.class);
        appWidgetManager.updateAppWidget(componentName, views);
    }
}

From source file:de.hero.vertretungsplan.HtmlWork.java

@SuppressLint("NewApi")
private void updateWidget(boolean before) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        RemoteViews widget = new RemoteViews(context.getPackageName(), R.layout.widget);
        AppWidgetManager appManager = AppWidgetManager.getInstance(context);
        ComponentName name = new ComponentName(context, WidgetProvider.class);
        if (before) {
            widget.setImageViewResource(R.id.aktButton, R.drawable.ic_action_aktualisieren_pressed);
        } else {//w ww  . j  ava2s  .co m
            widget.setImageViewResource(R.id.aktButton, R.drawable.aktualisieren_drawable);
            if (dataChanged) {
                appManager.notifyAppWidgetViewDataChanged(appManager.getAppWidgetIds(name), R.id.words);
            }
        }
        appManager.partiallyUpdateAppWidget(appManager.getAppWidgetIds(name), widget);
    }
}

From source file:com.echopf.ECHOFcmListenerService.java

/**
 * Sets notification layouts.//  w w w. j a v a  2  s  .  c  om
 * @param data 
 * @return NotificationCompat.Builder
 */
public NotificationCompat.Builder getNotificationBuilder(Bundle data) {
    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this).setAutoCancel(true);

    // get ApplicationInfo
    ApplicationInfo appInfo = null;
    String appName = null;
    try {
        appInfo = getPackageManager().getApplicationInfo(getPackageName(), PackageManager.GET_META_DATA);
        appName = getPackageManager()
                .getApplicationLabel(getPackageManager().getApplicationInfo(getPackageName(), 0)).toString();
    } catch (NameNotFoundException e) {
        throw new RuntimeException(e);
    }

    // set title
    String title = (data.getString("title") != null) ? data.getString("title") : appName;
    notificationBuilder.setContentTitle(title);

    // set message
    if (data.getString("message") != null)
        notificationBuilder.setContentText(data.getString("message"));

    // set icon
    int manifestIco = appInfo.metaData.getInt(NOTIFICATION_ICON_KEY);
    int icon = (manifestIco != 0) ? manifestIco : appInfo.icon;
    notificationBuilder.setSmallIcon(icon);

    // set sound
    Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    notificationBuilder.setSound(defaultSoundUri);

    // set content intent
    String activity = appInfo.metaData.getString(PUSH_OPEN_ACTIVITY_KEY);
    if (activity != null) {

        try {
            Intent intent = new Intent(this, Class.forName(activity)).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
                    .setComponent(new ComponentName(appInfo.packageName, activity)).putExtras(data);
            PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent,
                    PendingIntent.FLAG_CANCEL_CURRENT);
            notificationBuilder.setContentIntent(pendingIntent);
        } catch (ClassNotFoundException e) {
            throw new RuntimeException(e);
        }

    }

    return notificationBuilder;
}

From source file:com.cocosw.bottomsheet.ActionMenu.java

public int addIntentOptions(int groupId, int itemId, int order, ComponentName caller, Intent[] specifics,
        Intent intent, int flags, MenuItem[] outSpecificItems) {
    PackageManager pm = mContext.getPackageManager();
    final List<ResolveInfo> lri = pm.queryIntentActivityOptions(caller, specifics, intent, 0);
    final int N = lri != null ? lri.size() : 0;

    if ((flags & FLAG_APPEND_TO_GROUP) == 0) {
        removeGroup(groupId);//from  w  w  w. ja va 2s  . c  o m
    }

    for (int i = 0; i < N; i++) {
        final ResolveInfo ri = lri.get(i);
        Intent rintent = new Intent(ri.specificIndex < 0 ? intent : specifics[ri.specificIndex]);
        rintent.setComponent(
                new ComponentName(ri.activityInfo.applicationInfo.packageName, ri.activityInfo.name));
        final MenuItem item = add(groupId, itemId, order, ri.loadLabel(pm)).setIcon(ri.loadIcon(pm))
                .setIntent(rintent);
        if (outSpecificItems != null && ri.specificIndex >= 0) {
            outSpecificItems[ri.specificIndex] = item;
        }
    }

    return N;
}

From source file:co.codecrunch.musicplayerlite.manager.MusicPlayerService.java

@SuppressLint("NewApi")
@Override/*  ww  w. ja v  a 2 s .  com*/
public int onStartCommand(Intent intent, int flags, int startId) {
    try {
        SongDetail messageObject = MediaController.getInstance().getPlayingSongDetail();
        if (messageObject == null) {
            MusicPlayerUtility.runOnUIThread(new Runnable() {
                @Override
                public void run() {
                    stopSelf();
                }
            });
            return START_STICKY;
        }
        if (supportLockScreenControls) {
            ComponentName remoteComponentName = new ComponentName(getApplicationContext(),
                    MusicPlayerReceiver.class.getName());
            try {
                if (remoteControlClient == null) {
                    audioManager.registerMediaButtonEventReceiver(remoteComponentName);
                    Intent mediaButtonIntent = new Intent(Intent.ACTION_MEDIA_BUTTON);
                    mediaButtonIntent.setComponent(remoteComponentName);
                    PendingIntent mediaPendingIntent = PendingIntent.getBroadcast(this, 0, mediaButtonIntent,
                            0);
                    remoteControlClient = new RemoteControlClient(mediaPendingIntent);
                    audioManager.registerRemoteControlClient(remoteControlClient);
                }
                remoteControlClient.setTransportControlFlags(RemoteControlClient.FLAG_KEY_MEDIA_PLAY
                        | RemoteControlClient.FLAG_KEY_MEDIA_PAUSE
                        | RemoteControlClient.FLAG_KEY_MEDIA_PLAY_PAUSE
                        | RemoteControlClient.FLAG_KEY_MEDIA_STOP | RemoteControlClient.FLAG_KEY_MEDIA_PREVIOUS
                        | RemoteControlClient.FLAG_KEY_MEDIA_NEXT);
            } catch (Exception e) {
                Log.e("tmessages", e.toString());
            }
        }
        createNotification(messageObject);
    } catch (Exception e) {
        e.printStackTrace();
    }
    return START_STICKY;
}