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:edu.mit.mobile.android.demomode.Preferences.java

private void updateDemoModeEnabled() {
    getPackageManager().setComponentEnabledSetting(new ComponentName(this, DemoMode.class),
            mPrefs.getBoolean(KEY_ENABLED, true) ? PackageManager.COMPONENT_ENABLED_STATE_DEFAULT
                    : PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
            PackageManager.DONT_KILL_APP);
}

From source file:com.irccloud.android.activity.QuickReplyActivity.java

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

    if (getIntent().hasExtra("cid") && getIntent().hasExtra("bid")) {
        onNewIntent(getIntent());// ww w.  ja va2  s .c  om
    } else {
        finish();
        return;
    }

    final ImageButton send = (ImageButton) findViewById(R.id.sendBtn);
    final EditText message = (EditText) findViewById(R.id.messageTxt);
    message.setOnEditorActionListener(new TextView.OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView textView, int actionId, KeyEvent keyEvent) {
            if (actionId == EditorInfo.IME_ACTION_SEND && message.getText() != null
                    && message.getText().length() > 0)
                send.performClick();
            return true;
        }
    });
    message.setOnKeyListener(new View.OnKeyListener() {
        @Override
        public boolean onKey(View view, int keyCode, KeyEvent event) {
            if (event.getAction() == KeyEvent.ACTION_DOWN && keyCode == KeyEvent.KEYCODE_ENTER
                    && message.getText() != null && message.getText().length() > 0)
                send.performClick();
            return false;
        }
    });
    send.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if (message.getText() != null && message.getText().length() > 0) {
                Intent i = new Intent(RemoteInputService.ACTION_REPLY);
                i.setComponent(new ComponentName(getPackageName(), RemoteInputService.class.getName()));
                i.putExtras(getIntent());
                i.putExtra("reply", message.getText().toString());
                startService(i);
                finish();
            }
        }
    });

    ListView listView = (ListView) findViewById(R.id.conversation);
    listView.setAdapter(adapter);
}

From source file:com.toppatch.mv.ui.activities.LoginActivity2.java

private void enableAdmin() {
    DevicePolicyManager mDPM = (DevicePolicyManager) getSystemService(Context.DEVICE_POLICY_SERVICE);
    ComponentName mDeviceAdmin = new ComponentName(this, TopPatchAdmin.class);
    if (mDPM != null) {
        try {/*from   w  ww . j  a  v a 2  s.c o m*/

            //Add filter to listen to the choice made by the user to accept the terms or not.
            IntentFilter filter = new IntentFilter();
            filter.addAction(EnterpriseLicenseManager.ACTION_LICENSE_STATUS);
            actionReceiver = new SamsungReceiver();
            registerReceiver(actionReceiver, filter);

            Intent intent = new Intent(DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN);
            intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, mDeviceAdmin);
            intent.putExtra(DevicePolicyManager.EXTRA_ADD_EXPLANATION,
                    "Please Activate The Admin To Let Us Steal All Your Data And Sell It To Obama!");
            startActivityForResult(intent, RESULT_ENABLE);
        } catch (Exception e) {
            Log.w(TAG, "Exception: " + e);
        }
    } else {
        Log.e(TAG, "mDPM is null");
        //TODO device doesn't support MDM...report this shit.
    }
}

From source file:de.hackerspacebremen.push.PushIntentService.java

private void updateAppWidget(Context context, SpaceData data) {
    SharedPreferences dataPersistence = getSharedPreferences(Constants.SPACE_DATA_PERSISTENCE,
            Context.MODE_PRIVATE);
    Editor editor = dataPersistence.edit();
    editor.putBoolean(Constants.SPACE_OPEN_DATA_KEY, data.isSpaceOpen());
    editor.commit();/* ww  w.  jav  a  2  s . c  o  m*/

    RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.appwidget);
    remoteViews.setViewVisibility(R.id.indicatorImage, View.VISIBLE);
    remoteViews.setViewVisibility(R.id.errorText, View.GONE);

    if (data.isSpaceOpen()) {
        remoteViews.setImageViewResource(R.id.indicatorImage, R.drawable.banner);
    } else {
        remoteViews.setImageViewResource(R.id.indicatorImage, R.drawable.banner_blur);
    }

    AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
    ComponentName componentName = new ComponentName(context, HackerspaceWidgetProvider.class);
    appWidgetManager.updateAppWidget(componentName, remoteViews);
}

From source file:com.amazon.android.navigator.Navigator.java

/**
 * Start activity./*from  w  w w  .  j a v  a  2s.  c  o  m*/
 *
 * @param currentActivity Current activity reference.
 * @param screenName      Screen name.
 * @param providedBundle  Provided bundle.
 */
private void startActivity(Activity currentActivity, String screenName, Bundle providedBundle,
        ActivitySwitchListener activitySwitchListener) {

    Class newActivityClass = mScreenNameClassMap.get(screenName);

    if (mCurrentActivity == null) {
        Log.d(TAG, "mCurrentActivity is null, switching to:" + screenName);
        Intent intent = new Intent();

        intent.setComponent(new ComponentName(mContext, newActivityClass));
        if (activitySwitchListener != null) {
            activitySwitchListener.onPreActivitySwitch(intent);
        }
        mContext.startActivity(intent);
        return;
    }

    Intent intent = new Intent(currentActivity, newActivityClass);

    if (activitySwitchListener != null) {
        activitySwitchListener.onPreActivitySwitch(intent);
    }

    Bundle bundle = providedBundle;

    IActivityTransition activityTransition = null;
    if (currentActivity instanceof IActivityTransition) {
        activityTransition = (IActivityTransition) currentActivity;

        activityTransition.onBeforeActivityTransition();
    }

    Log.d(TAG, "Activity: " + getActivityName(currentActivity) + " is starting a new " + "activity" + intent);
    if (bundle != null) {
        currentActivity.startActivity(intent, bundle);
    } else {
        currentActivity.startActivity(intent);
    }

    if (activityTransition != null) {
        activityTransition.onPostStartActivity();
    }
}

From source file:com.darshancomputing.BatteryIndicatorPro.AlarmsFragment.java

private void bindView(View view) {
    final TextView summary_tv = (TextView) view.findViewById(R.id.alarm_summary);
    final View summary_box = view.findViewById(R.id.alarm_summary_box);
    final CompoundButton toggle = (CompoundButton) view.findViewById(R.id.toggle);

    final int id = mCursor.getInt(AlarmDatabase.INDEX_ID);
    String type = mCursor.getString(AlarmDatabase.INDEX_TYPE);
    String threshold = mCursor.getString(AlarmDatabase.INDEX_THRESHOLD);
    Boolean enabled = (mCursor.getInt(AlarmDatabase.INDEX_ENABLED) == 1);

    String s = pfrag.str.alarm_types_display[pfrag.str.indexOf(pfrag.str.alarm_type_values, type)];
    if (type.equals("temp_rises")) {
        s += " " + pfrag.str.formatTemp(Integer.valueOf(threshold), convertF, false);
    } else if (type.equals("charge_drops") || type.equals("charge_rises")) {
        s += " " + threshold + "%";
    }/*from   w  ww  .  j  a  v a 2 s  . co  m*/
    final String summary = s;

    summary_tv.setText(summary);

    toggle.setChecked(enabled);

    toggle.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            alarms.setEnabled(id, isChecked);
        }
    });

    summary_box.setOnCreateContextMenuListener(new OnCreateContextMenuListener() {
        public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
            curId = id;
            curIndex = mAlarmsList.indexOfChild((View) v.getParent().getParent());

            getActivity().getMenuInflater().inflate(R.menu.alarm_item_context, menu);
            menu.setHeaderTitle(summary);
        }
    });

    summary_box.setOnKeyListener(new OnKeyListener() {
        public boolean onKey(View v, int keyCode, android.view.KeyEvent event) {
            if (keyCode == event.KEYCODE_DPAD_CENTER && event.getAction() == event.ACTION_DOWN)
                v.setPressed(true);

            return false;
        }
    });

    summary_box.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            ComponentName comp = new ComponentName(getActivity().getPackageName(),
                    AlarmEditActivity.class.getName());
            startActivity(new Intent().setComponent(comp).putExtra(AlarmEditActivity.EXTRA_ALARM_ID, id));
        }
    });
}

From source file:eu.faircode.netguard.ServiceJob.java

private static void submit(Rule rule, PersistableBundle bundle, Context context) {
    PackageManager pm = context.getPackageManager();
    JobScheduler scheduler = (JobScheduler) context.getSystemService(Context.JOB_SCHEDULER_SERVICE);

    // Get english application label
    String label = null;/*from www  .j a  v a  2s.c  o m*/
    try {
        Configuration config = new Configuration();
        config.setLocale(new Locale("en"));
        Resources res = pm.getResourcesForApplication(rule.info.packageName);
        res.updateConfiguration(config, res.getDisplayMetrics());
        label = res.getString(rule.info.applicationInfo.labelRes);
    } catch (Throwable ex) {
        Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
        CharSequence cs = rule.info.applicationInfo.loadLabel(pm);
        if (cs != null)
            label = cs.toString();
    }

    // Add application data
    bundle.putInt("uid", rule.info.applicationInfo.uid);
    bundle.putString("package", rule.info.packageName);
    bundle.putInt("version_code", rule.info.versionCode);
    bundle.putString("version_name", rule.info.versionName);
    bundle.putString("label", label);
    bundle.putInt("system", rule.system ? 1 : 0);
    try {
        bundle.putString("installer", pm.getInstallerPackageName(rule.info.packageName));
    } catch (Throwable ex) {
        Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
        bundle.putString("installer", null);
    }

    // Cancel overlapping jobs
    for (JobInfo pending : scheduler.getAllPendingJobs()) {
        String type = pending.getExtras().getString("type");
        if (type != null && type.equals(bundle.getString("type"))) {
            if (type.equals("rule")) {
                int uid = pending.getExtras().getInt("uid");
                if (uid == bundle.getInt("uid")) {
                    Log.i(TAG, "Canceling id=" + pending.getId());
                    scheduler.cancel(pending.getId());
                }
            } else if (type.equals("host")) {
                int uid = pending.getExtras().getInt("uid");
                int version = pending.getExtras().getInt("version");
                int protocol = pending.getExtras().getInt("protocol");
                String daddr = pending.getExtras().getString("daddr");
                int dport = pending.getExtras().getInt("dport");
                if (uid == bundle.getInt("uid") && version == bundle.getInt("version")
                        && protocol == bundle.getInt("protocol") && daddr != null
                        && daddr.equals(bundle.getString("daddr")) && dport == bundle.getInt("dport")) {
                    Log.i(TAG, "Canceling id=" + pending.getId());
                    scheduler.cancel(pending.getId());
                }
            }
        }
    }

    // Schedule job
    ComponentName serviceName = new ComponentName(context, ServiceJob.class);
    JobInfo job = new JobInfo.Builder(++id, serviceName).setRequiredNetworkType(JobInfo.NETWORK_TYPE_UNMETERED)
            .setMinimumLatency(Util.isDebuggable(context) ? 10 * 1000 : 60 * 1000).setExtras(bundle)
            .setPersisted(true).build();
    if (scheduler.schedule(job) == JobScheduler.RESULT_SUCCESS)
        Log.i(TAG, "Scheduled job=" + job.getId() + " success");
    else
        Log.e(TAG, "Scheduled job=" + job.getId() + " failed");
}

From source file:com.cwp.cmoneycharge.activity.AddPayActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.add);// 
    SysApplication.getInstance().addActivity(this); // ?this
    super.onStart();// 
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        setTranslucentStatus(true);/*ww  w . j a  va2s . co  m*/
        findViewById(R.id.top).setVisibility(View.VISIBLE);
    }
    mTintManager = new SystemBarTintManager(this);
    mTintManager.setStatusBarTintEnabled(true);
    mTintManager.setStatusBarTintResource(R.color.statusbar_bg);

    txtMoney = (EditText) findViewById(R.id.txtMoney);// ??
    txtTime = (EditText) findViewById(R.id.txtTime);// ?
    txtAddress = (EditText) findViewById(R.id.txtAddress);// ?
    txtMark = (EditText) findViewById(R.id.txtMark);// ?
    spType = (Spinner) findViewById(R.id.spType);// ?
    btnSaveButton = (Button) findViewById(R.id.btnSave);// ??
    btnCancelButton = (Button) findViewById(R.id.btnCancel);// ??
    btnVoice = (Button) findViewById(R.id.btnVoice);// ?
    rb1 = (RadioButton) findViewById(R.id.payout_tab_rb);
    rb2 = (RadioButton) findViewById(R.id.income_tab_rb);
    left_back = (ImageView) findViewById(R.id.example_left3);
    btn_loacte = (ImageView) findViewById(R.id.btn_loacte);
    addphoto = (ImageView) findViewById(R.id.addphoto);
    bottom_empty = (FrameLayout) findViewById(R.id.bottom_empty);
    bottom_full = (LinearLayout) findViewById(R.id.bottom_full);

    //?
    //?
    mLocationClient = new LocationClient(getApplicationContext());
    mLocationClient.registerLocationListener(mLocationListener);
    //TODO
    speechRecognizer = SpeechRecognizer.createSpeechRecognizer(this,
            new ComponentName(this, VoiceRecognitionService.class));
    speechRecognizer.setRecognitionListener(this);

    dialogShowUtil = new DialogShowUtil(this, this, VoiceSave, type, // ?dialog
            VoiceDefault);
    btn_loacte.setOnClickListener(this); // ?

    // ????
    bottom_empty.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            keyBoard.hideKeyboard();
            bottom_empty.setVisibility(View.GONE);
            bottom_full.setVisibility(View.VISIBLE);
        }
    });

    // 
    addphoto.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            Intent intent = new Intent(AddPayActivity.this, PublishedActivity.class);
            intent.putExtra("cwp.id", userid);
            startActivityForResult(intent, 102);
        }
    });

    left_back.setOnClickListener(new OnClickListener() {

        public void onClick(View v) {
            Intent intent = null;
            type = "pay";
            typemode = "add";
            if (bundle.containsKey("cwp.frament3")) {
                intent = new Intent(AddPayActivity.this, MainActivity.class);
                intent.putExtra("cwp.Fragment", "3");// ?
            } else {
                intent = new Intent(AddPayActivity.this, MainActivity.class);
            }
            intent.putExtra("cwp.id", userid);
            startActivity(intent);
            finish();// 
        }
    });

    //        mRecognitionListener = new DialogRecognitionListener() { // ?
    //
    //            @Override
    //            public void onResults(Bundle results) {
    //                ArrayList<String> rs = results != null ? results
    //                        .getStringArrayList(RESULTS_RECOGNITION) : null;
    //                if (rs != null && rs.size() > 0) {
    //                    Recognition(rs.get(0)); // ?
    //                    // Toast.makeText(AddPayActivity.this, rs.get(0),
    //                    // Toast.LENGTH_SHORT).show();
    //                }
    //            }
    //        };

    corporation_fl = (FrameLayout) findViewById(R.id.corporation_fl);
    address_fl = (FrameLayout) findViewById(R.id.address_fl);

    //checkBox
    rb1.setOnCheckedChangeListener(new OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {

            if (rb1.isChecked()) { // 
                type = "pay";
            } else // 
            {
                type = "income";
            }
            updatetype();
        }
    });

    final Calendar c = Calendar.getInstance();// ??
    mYear = c.get(Calendar.YEAR);// ?
    mMonth = c.get(Calendar.MONTH);// ?
    mDay = c.get(Calendar.DAY_OF_MONTH);// ?

}

From source file:com.bayapps.android.robophish.ui.FullScreenPlayerActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_full_player);
    initializeToolbar();/* w  w w . j av a  2s  . co m*/
    if (getSupportActionBar() != null) {
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        getSupportActionBar().setTitle("");
    }

    mBackgroundImage = (ImageView) findViewById(R.id.background_image);
    mPauseDrawable = ContextCompat.getDrawable(this, R.drawable.uamp_ic_pause_white_48dp);
    mPlayDrawable = ContextCompat.getDrawable(this, R.drawable.uamp_ic_play_arrow_white_48dp);
    mPlayPause = (ImageView) findViewById(R.id.play_pause);
    mSkipNext = (ImageView) findViewById(R.id.next);
    mSkipPrev = (ImageView) findViewById(R.id.prev);
    mStart = (TextView) findViewById(R.id.startText);
    mEnd = (TextView) findViewById(R.id.endText);
    mSeekbar = (SeekBar) findViewById(R.id.seekBar1);
    mLine1 = (TextView) findViewById(R.id.line1);
    mLine2 = (TextView) findViewById(R.id.line2);
    mLine3 = (TextView) findViewById(R.id.line3);
    mLine4 = (TextView) findViewById(R.id.line4);
    mLine5 = (TextView) findViewById(R.id.line5);
    mLoading = (ProgressBar) findViewById(R.id.progressBar1);
    mControllers = findViewById(R.id.controllers);

    mSkipNext.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            MediaControllerCompat.TransportControls controls = getSupportMediaController()
                    .getTransportControls();
            controls.skipToNext();
        }
    });

    mSkipPrev.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            MediaControllerCompat.TransportControls controls = getSupportMediaController()
                    .getTransportControls();
            controls.skipToPrevious();
        }
    });

    mPlayPause.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            PlaybackStateCompat state = getSupportMediaController().getPlaybackState();
            if (state != null) {
                MediaControllerCompat.TransportControls controls = getSupportMediaController()
                        .getTransportControls();
                switch (state.getState()) {
                case PlaybackStateCompat.STATE_PLAYING: // fall through
                case PlaybackStateCompat.STATE_BUFFERING:
                    controls.pause();
                    stopSeekbarUpdate();
                    break;
                case PlaybackStateCompat.STATE_PAUSED:
                case PlaybackStateCompat.STATE_STOPPED:
                    controls.play();
                    scheduleSeekbarUpdate();
                    break;
                default:
                    LogHelper.d(TAG, "onClick with state ", state.getState());
                }
            }
        }
    });

    mSeekbar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
        @Override
        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
            mStart.setText(DateUtils.formatElapsedTime(progress / 1000));
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {
            stopSeekbarUpdate();
        }

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {
            getSupportMediaController().getTransportControls().seekTo(seekBar.getProgress());
            scheduleSeekbarUpdate();
        }
    });

    // Only update from the intent if we are not recreating from a config change:
    if (savedInstanceState == null) {
        //updateFromParams(getIntent());  //FIXME:  Why were they doing this???
    }

    mMediaBrowser = new MediaBrowserCompat(this, new ComponentName(this, MusicService.class),
            mConnectionCallback, null);
}

From source file:org.ametro.app.ApplicationEx.java

public void changeNetworkStateReceiverState(boolean enabled) {
    PackageManager manager = getPackageManager();
    ComponentName name = new ComponentName(this, NetworkStateReceiver.class);
    int state = enabled ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED
            : PackageManager.COMPONENT_ENABLED_STATE_DISABLED;
    manager.setComponentEnabledSetting(name, state, PackageManager.DONT_KILL_APP);
}