コード例 #1
1
 /**
  * 删除程序的快捷方式
  *
  * @param activity Activity
  */
 public static void delShortcut(Activity activity) {
   Intent shortcut = new Intent("com.android.launcher.action.UNINSTALL_SHORTCUT");
   // 快捷方式的名称
   shortcut.putExtra(Intent.EXTRA_SHORTCUT_NAME, activity.getString(R.string.app_name));
   String appClass = activity.getPackageName() + "." + activity.getLocalClassName();
   ComponentName comp = new ComponentName(activity.getPackageName(), appClass);
   shortcut.putExtra(
       Intent.EXTRA_SHORTCUT_INTENT, new Intent(Intent.ACTION_MAIN).setComponent(comp));
   activity.sendBroadcast(shortcut);
 }
コード例 #2
0
  /**
   * @param activity
   * @param enableGPS
   * @param showSettingsIfAutoSwitchImpossible
   * @return true if GPS could be switched to the desired value without user interaction, else the
   *     settings will be started and false is returned
   */
  public static boolean switchGPS(
      Activity activity, boolean enableGPS, boolean showSettingsIfAutoSwitchImpossible) {

    String provider =
        Settings.Secure.getString(
            activity.getContentResolver(), Settings.Secure.LOCATION_PROVIDERS_ALLOWED);
    boolean currentlyEnabled = provider.contains("gps");

    if (canTurnOnGPSAutomatically(activity)) {
      //			String provider = Settings.Secure.getString(
      //					activity.getContentResolver(),
      //					Settings.Secure.LOCATION_PROVIDERS_ALLOWED);
      //			boolean currentlyEnabled = provider.contains("gps");
      if (!currentlyEnabled && enableGPS) {

        if (android.os.Build.VERSION.SDK_INT > 14) {
          // to make it work in android 4.0 and higher - enable access to my location setting
          Intent intent = new Intent("android.location.GPS_ENABLED_CHANGE");
          intent.putExtra("enabled", true);
          activity.sendBroadcast(intent);
        }

        pokeGPSButton(activity);

      } else if (
      /*currentlyEnabled &&*/ !enableGPS) { // always send disable intent for higher OS versions and
                                            // only poke if enabled, regardless of the version

        if (android.os.Build.VERSION.SDK_INT > 14) {
          // to make it work in android 4.0 and higher - disable access to my location setting
          Intent intent = new Intent("android.location.GPS_ENABLED_CHANGE");
          intent.putExtra("enabled", false);
          activity.sendBroadcast(intent);
        }

        if (currentlyEnabled) pokeGPSButton(activity);
      }
      return true;
    } else if (showSettingsIfAutoSwitchImpossible) {

      if (currentlyEnabled) return true;

      Log.d(
          LOG_TAG, "Can't enable GPS automatically, will start " + "settings for manual enabling!");
      openLocationSettingsPage(activity);
    }
    return false;
  }
コード例 #3
0
  @Override
  public boolean requestModelUpdate(UserActionEnum action, @Nullable Bundle args) {
    // If the action is a VIDEO_VIEWED we save the information that the video has been viewed by
    // the user in AppData.
    if (action.equals(VideoLibraryUserActionEnum.VIDEO_PLAYED)) {
      if (args != null && args.containsKey(KEY_VIDEO_ID)) {
        String playedVideoId = args.getString(KEY_VIDEO_ID);

        LOGD(TAG, "setVideoViewed id=" + playedVideoId);
        Uri myPlayedVideoUri =
            ScheduleContract.MyViewedVideos.buildMyViewedVideosUri(
                AccountUtils.getActiveAccountName(mActivity));

        AsyncQueryHandler handler = new AsyncQueryHandler(mActivity.getContentResolver()) {};
        final ContentValues values = new ContentValues();
        values.put(ScheduleContract.MyViewedVideos.VIDEO_ID, playedVideoId);
        handler.startInsert(-1, null, myPlayedVideoUri, values);

        // Because change listener is set to null during initialization, these
        // won't fire on pageview.
        mActivity.sendBroadcast(ScheduleWidgetProvider.getRefreshBroadcastIntent(mActivity, false));

        // Request an immediate user data sync to reflect the viewed video in the cloud.
        SyncHelper.requestManualSync(AccountUtils.getActiveAccount(mActivity), true);
      } else {
        LOGE(
            TAG,
            "The VideoLibraryUserActionEnum.VIDEO_VIEWED action was called without a "
                + "proper Bundle.");
        return false;
      }
    }
    return true;
  }
コード例 #4
0
 private static void pokeGPSButton(Activity activity) {
   final Intent poke = new Intent();
   poke.setClassName(
       "com.android.settings", "com.android.settings.widget.SettingsAppWidgetProvider");
   poke.addCategory(Intent.CATEGORY_ALTERNATIVE);
   poke.setData(Uri.parse("3"));
   activity.sendBroadcast(poke);
 }
コード例 #5
0
  /* (non-Javadoc)
   * @see android.widget.CompoundButton.OnCheckedChangeListener#onCheckedChanged(android.widget.CompoundButton, boolean)
   */
  public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {

    configuration.setEnabled(isChecked);

    final Intent intent = new Intent(NewsConstants.CONFIGURATION_UPDATE);

    intent.putExtra(Configuration.class.getName(), configuration);

    parentActivity.sendBroadcast(intent);
  }
コード例 #6
0
 /**
  * 删除
  *
  * @param activity
  * @param shortCutName
  */
 public void deleteShortCut(Activity activity, String shortCutName) {
   Intent shortCut = new Intent("com.android.launcher.permission.UNINSTALL_SHORTCUT");
   // 快捷方式的名称
   shortCut.putExtra(Intent.EXTRA_SHORTCUT_NAME, shortCutName);
   Intent intent = new Intent(activity, activity.getClass());
   intent.setAction("android.intent.action.MAIN");
   intent.addCategory("android.intent.category.LAUNCHER");
   shortCut.putExtra(Intent.EXTRA_SHORTCUT_INTENT, intent);
   activity.sendBroadcast(shortCut);
 }
コード例 #7
0
ファイル: UIHelper.java プロジェクト: yuzhangiot/smartaudio
  private String[] buildSongList() {
    mActivity.sendBroadcast(
        new Intent(
            Intent.ACTION_MEDIA_MOUNTED,
            Uri.parse("file://" + Environment.getExternalStorageDirectory())));

    String[] fields = {
      MediaStore.Audio.Media._ID,
      MediaStore.Audio.Media.DATA,
      MediaStore.Audio.Media.TITLE,
      MediaStore.Audio.Artists.ARTIST,
      MediaStore.Audio.Albums.ALBUM,
      MediaStore.Audio.Albums.ALBUM_ID,
      MediaStore.Audio.Media.DISPLAY_NAME
    };

    Cursor cursor =
        mActivity.managedQuery(
            MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, fields, null, null, null);

    List<String> songList = new ArrayList<String>();
    // Clear the file list to replace its contents with current file list.
    mSongFileList.clear();

    while (cursor != null && cursor.moveToNext() && songList != null) {
      if (!cursor.getString(1).endsWith(".wav")) {
        // the media streamer will only work for wav files skip any other file type
        continue;
      }
      songList.add(cursor.getString(2) + "\nby " + cursor.getString(3));
      mSongFileList.add(cursor.getString(1));
    }

    if (songList.size() == 0) {
      AlertDialog.Builder alertBuilder = new AlertDialog.Builder(mActivity);
      alertBuilder.setMessage(
          "Please install wave files on device and then relaunch the application.");
      alertBuilder.setNegativeButton(
          "Quit",
          new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface arg0, int arg1) {
              mActivity.finish();
              android.os.Process.killProcess(android.os.Process.myPid());
            }
          });
      alertBuilder.setCancelable(false);
      alertBuilder.create().show();
    }

    return songList.toArray(new String[songList.size()]);
  }
コード例 #8
0
ファイル: TalkHelperFragment.java プロジェクト: norain2050/zc
 @Override
 public void onItemClick(AdapterView<?> arg0, View view, int pos, long arg3) {
   // TODO Auto-generated method stub
   try {
     Intent intent = new Intent();
     intent.setAction("jimome.action.sendtext");
     intent.putExtra("text", baseJson.getTexts()[pos]);
     context.sendBroadcast(intent);
     context.finish();
   } catch (Exception e) {
     // TODO: handle exception
   }
 }
コード例 #9
0
  /**
   * 为程序创建桌面快捷方式
   *
   * @param activity Activity
   */
  public static void addShortcut(Activity activity) {
    Intent shortcut = new Intent("com.android.launcher.action.INSTALL_SHORTCUT");
    // 快捷方式的名称
    shortcut.putExtra(Intent.EXTRA_SHORTCUT_NAME, activity.getString(R.string.app_name));
    shortcut.putExtra("duplicate", false); // 不允许重复创建
    Intent shortcutIntent = new Intent(Intent.ACTION_MAIN);
    shortcutIntent.setClassName(activity, activity.getClass().getName());
    shortcut.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
    // 快捷方式的图标
    ShortcutIconResource iconRes =
        ShortcutIconResource.fromContext(activity, R.drawable.ic_launcher);
    shortcut.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, iconRes);

    activity.sendBroadcast(shortcut);
  }
コード例 #10
0
 /** Handles time zone preference changes */
 @Override
 public boolean onPreferenceChange(Preference preference, Object newValue) {
   String tz;
   final Activity activity = getActivity();
   if (preference == mUseHomeTZ) {
     if ((Boolean) newValue) {
       tz = mTimeZoneId;
     } else {
       tz = CalendarCache.TIMEZONE_TYPE_AUTO;
     }
     Utils.setTimeZone(activity, tz);
     return true;
   } else if (preference == mHideDeclined) {
     mHideDeclined.setChecked((Boolean) newValue);
     Intent intent = new Intent(Utils.getWidgetScheduledUpdateAction(activity));
     intent.setDataAndType(CalendarContract.CONTENT_URI, Utils.APPWIDGET_DATA_TYPE);
     activity.sendBroadcast(intent);
     return true;
   } else if (preference == mWeekStart) {
     mWeekStart.setValue((String) newValue);
     mWeekStart.setSummary(mWeekStart.getEntry());
   } else if (preference == mDefaultReminder) {
     mDefaultReminder.setValue((String) newValue);
     mDefaultReminder.setSummary(mDefaultReminder.getEntry());
   } else if (preference == mSnoozeDelay) {
     mSnoozeDelay.setValue((String) newValue);
     mSnoozeDelay.setSummary(mSnoozeDelay.getEntry());
   } else if (preference == mRingtone) {
     if (newValue instanceof String) {
       Utils.setRingTonePreference(activity, (String) newValue);
       String ringtone = getRingtoneTitleFromUri(activity, (String) newValue);
       mRingtone.setSummary(ringtone == null ? "" : ringtone);
     }
     return true;
   } else if (preference == mVibrate) {
     mVibrate.setChecked((Boolean) newValue);
     return true;
   } else if (preference == mDefaultStart) {
     int i = mDefaultStart.findIndexOfValue((String) newValue);
     mDefaultStart.setSummary(mDefaultStart.getEntries()[i]);
     return true;
   } else {
     return true;
   }
   return false;
 }
コード例 #11
0
 public void creatShortCut(Activity activity, String shortCutName, int resourceId) {
   Intent intent = new Intent(activity, activity.getClass());
   /** 卸载应用并删除图标 */
   intent.setAction("android.intent.action.MAIN");
   intent.addCategory("android.intent.category.LAUNCHER");
   Intent shortcutintent = new Intent("com.android.launcher.action.INSTALL_SHORTCUT");
   // 不允许重复
   shortcutintent.putExtra("duplicate", false);
   // 设置标题
   shortcutintent.putExtra(Intent.EXTRA_SHORTCUT_NAME, shortCutName);
   // 设置图标
   Parcelable icon =
       Intent.ShortcutIconResource.fromContext(activity.getApplicationContext(), resourceId);
   shortcutintent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, icon);
   // 点击快捷方式,运行入口
   shortcutintent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, intent);
   activity.sendBroadcast(shortcutintent);
 }
コード例 #12
0
ファイル: Camera.java プロジェクト: Phong6698/MemoryBook
  public void createCamera(Activity activity) {
    Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);

    this.timestamp = new Timestamp(Calendar.getInstance().getTimeInMillis());
    String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(this.timestamp);

    // folder stuff
    File imagesFolder = new File(Environment.getExternalStorageDirectory(), "MyImages");
    imagesFolder.mkdirs();

    File image = new File(imagesFolder, "QR_" + timeStamp + ".jpg");
    uriSavedImage = Uri.fromFile(image);

    Intent mediaScanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
    mediaScanIntent.setData(uriSavedImage);
    activity.sendBroadcast(mediaScanIntent);

    cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, uriSavedImage);
    activity.startActivityForResult(cameraIntent, TAKE_PICTURE);
  }
コード例 #13
0
 @Override
 public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
   Activity a = getActivity();
   if (key.equals(KEY_ALERTS)) {
     updateChildPreferences();
     if (a != null) {
       Intent intent = new Intent();
       intent.setClass(a, AlertReceiver.class);
       if (mAlert.isChecked()) {
         intent.setAction(AlertReceiver.ACTION_DISMISS_OLD_REMINDERS);
       } else {
         intent.setAction(AlertReceiver.EVENT_REMINDER_APP_ACTION);
       }
       a.sendBroadcast(intent);
     }
   }
   if (a != null) {
     BackupManager.dataChanged(a.getPackageName());
   }
 }
コード例 #14
0
  private void doReferrerTest(
      String ref,
      final TestableDistribution distribution,
      final Distribution.ReadyCallback distributionReady)
      throws InterruptedException {
    final Intent intent = new Intent(ACTION_INSTALL_REFERRER);
    intent.setClassName(AppConstants.ANDROID_PACKAGE_NAME, CLASS_REFERRER_RECEIVER);
    intent.putExtra("referrer", ref);

    final BroadcastReceiver receiver =
        new BroadcastReceiver() {
          @Override
          public void onReceive(Context context, Intent intent) {
            Log.i(LOGTAG, "Test received " + intent.getAction());

            ThreadUtils.postToBackgroundThread(
                new Runnable() {
                  @Override
                  public void run() {
                    distribution.addOnDistributionReadyCallback(distributionReady);
                    distribution.go();
                  }
                });
          }
        };

    IntentFilter intentFilter = new IntentFilter(ReferrerReceiver.ACTION_REFERRER_RECEIVED);
    final LocalBroadcastManager localBroadcastManager =
        LocalBroadcastManager.getInstance(mActivity);
    localBroadcastManager.registerReceiver(receiver, intentFilter);

    Log.i(LOGTAG, "Broadcasting referrer intent.");
    try {
      mActivity.sendBroadcast(intent, null);
      synchronized (distribution) {
        distribution.wait(WAIT_TIMEOUT_MSEC);
      }
    } finally {
      localBroadcastManager.unregisterReceiver(receiver);
    }
  }
コード例 #15
0
  public boolean execute(String action, JSONArray data, final CallbackContext callbackContext) {
    Boolean result = false;

    if (ACTION_START.equalsIgnoreCase(action)) {
      if (geotrigger.isEnabled()) {
        callbackContext.error("Service has already been started");
      } else if (!geotrigger.isConfigured()) {
        callbackContext.error("Call configure before calling start");
      } else {

        this.geotrigger.start();
        result = true;
        callbackContext.success("start succeed");
      }
    } else if (ACTION_STOP.equalsIgnoreCase(action)) {
      if (!geotrigger.isEnabled()) {
        callbackContext.error("The service hasn't started yet");
      } else {
        this.geotrigger.stop();
        result = true;
        callbackContext.success("stop succeed");
      }
    } else if (ACTION_CONFIGURE.equalsIgnoreCase(action)) {
      if (geotrigger.isEnabled()) {
        Log.v(Config.TAG, "has enabled, then disable all the previous geofences");
        geotrigger.stop();
      }

      TripPlan tripPlanToConfigure = null;
      try {
        TripPlanParser parser = new TripPlanParser(data.toString());
        tripPlanToConfigure = parser.getTripplan();

      } catch (Exception e) {
        e.printStackTrace();
        callbackContext.error("Errors occur when parsing tripplan data");
      }

      if (tripPlanToConfigure != null) {
        this.geotrigger.configure(tripPlanToConfigure);
        result = true;
        callbackContext.success("configure succeed");
      }
    } else if (ACTION_RECONFIGURE.equalsIgnoreCase(action)) {

      TripPlan tripPlanToConfigure = null;
      try {
        TripPlanParser parser = new TripPlanParser(data.toString());
        tripPlanToConfigure = parser.getTripplan();

      } catch (Exception e) {
        e.printStackTrace();
        callbackContext.error("Errors occur when parsing tripplan data");
      }

      if (tripPlanToConfigure != null) {
        this.geotrigger.reconfigure(tripPlanToConfigure);
        result = true;
        callbackContext.success("configure succeed");
      }
    } else if (ACTION_ADDPLACE.equalsIgnoreCase(action)) {
      if (!this.geotrigger.isConfigured()) {
        callbackContext.error("The service is not configured yet");
      } else {
        Place place = null;
        try {
          PlaceParser parser = new PlaceParser(data.toString());
          place = parser.getPlace();
        } catch (Exception e) {
          e.printStackTrace();
        }

        if (place == null) {
          callbackContext.error("Errors occur when parsing tripplan data");
        } else {
          boolean isAdded = this.geotrigger.addPlace(place);
          if (isAdded) {
            result = true;
            callbackContext.success("adding place succeed");
          } else {
            callbackContext.error("failed to add place");
          }
        }
      }

    } else if (ACTION_DELETEPLACE.equalsIgnoreCase(action)) {
      if (!this.geotrigger.isConfigured()) {
        callbackContext.error("The service is not configured yet");
      } else {
        String placeUuid = null;
        try {
          PlaceUuidParser parser = new PlaceUuidParser(data.toString());
          placeUuid = parser.getPlaceUuid();
        } catch (Exception e) {
          e.printStackTrace();
        }

        if (placeUuid == null) {
          callbackContext.error("Errors occur when parsing place uuid");
        } else {
          boolean isDeleted = this.geotrigger.deletePlace(placeUuid);
          if (isDeleted) {
            result = true;
            callbackContext.success("deleting place succeed");
          } else {
            callbackContext.error("failed to delete place");
          }
        }
      }
    } else if (ACTION_ENABLEPLACE.equalsIgnoreCase(action)) {
      if (!this.geotrigger.isConfigured()) {
        callbackContext.error("The service is not configured yet");
      } else {
        String placeUuid = null;
        try {
          PlaceUuidParser parser = new PlaceUuidParser(data.toString());
          placeUuid = parser.getPlaceUuid();
        } catch (Exception e) {
          e.printStackTrace();
        }

        if (placeUuid == null) {
          callbackContext.error("Errors occur when parsing place uuid");
        } else {
          boolean isEnabled = this.geotrigger.enablePlace(placeUuid);
          if (isEnabled) {
            result = true;
            callbackContext.success("enable place succeed");
          } else {
            callbackContext.error("failed to enable place");
          }
        }
      }
    } else if (ACTION_DISABLEPLACE.equalsIgnoreCase(action)) {
      if (!this.geotrigger.isConfigured()) {
        callbackContext.error("The service is not configured yet");
      } else {
        String placeUuid = null;
        try {
          PlaceUuidParser parser = new PlaceUuidParser(data.toString());
          placeUuid = parser.getPlaceUuid();
        } catch (Exception e) {
          e.printStackTrace();
        }

        if (placeUuid == null) {
          callbackContext.error("Errors occur when parsing place uuid");
        } else {
          boolean isEnabled = this.geotrigger.disablePlace(placeUuid);
          if (isEnabled) {
            result = true;
            callbackContext.success("disable place succeed");
          } else {
            callbackContext.error("failed to disable place");
          }
        }
      }
    } else if (ACTION_GETCURRENTLOCATION.equalsIgnoreCase(action)) {
      final LocationManager locationManager =
          (LocationManager) this.cordova.getActivity().getSystemService(Context.LOCATION_SERVICE);
      Criteria criteria = new Criteria();
      criteria.setAltitudeRequired(false);
      criteria.setBearingRequired(false);
      criteria.setSpeedRequired(true);
      criteria.setCostAllowed(true);
      criteria.setAccuracy(Criteria.ACCURACY_FINE);
      criteria.setHorizontalAccuracy(Criteria.ACCURACY_HIGH);
      criteria.setPowerRequirement(Criteria.POWER_HIGH);

      String bestProvider = locationManager.getBestProvider(criteria, true);
      if (bestProvider != LocationManager.PASSIVE_PROVIDER) {
        locationManager.requestLocationUpdates(
            bestProvider,
            0,
            0,
            new LocationListener() {

              @Override
              public void onLocationChanged(Location location) {
                JSONObject object = new JSONObject();
                try {
                  object.put("lat", location.getLatitude());
                  object.put("lng", location.getLongitude());
                } catch (JSONException e) {
                  e.printStackTrace();
                }
                callbackContext.success(object);
                locationManager.removeUpdates(this);
              }

              @Override
              public void onProviderDisabled(String arg0) {}

              @Override
              public void onProviderEnabled(String arg0) {}

              @Override
              public void onStatusChanged(String arg0, int arg1, Bundle arg2) {}
            });
      }
    } else if (ACTION_SETONNOTIFICATIONCLICKEDCALLBACK.equalsIgnoreCase(action)) {
      String callbackId = callbackContext.getCallbackId();
      this.callbackIds.put(ACTION_SETONNOTIFICATIONCLICKEDCALLBACK, callbackId);
      Log.d(Config.TAG, "notificaton callback is set");
      return true;
    } else if (ACTION_MOCK_START.equalsIgnoreCase(action)) {
      if (this.geoFaker != null && this.geoFaker.isStarted()) {
        callbackContext.error("geofaker has started");
      } else {
        this.geoFaker = new Geofaker(this.cordova.getActivity());
        this.geoFaker.start();
        result = true;
        callbackContext.success("mocking started");
      }
    } else if (ACTION_MOCK_STOP.equalsIgnoreCase(action)) {
      if (this.geoFaker != null && this.geoFaker.isStarted()) {
        this.geoFaker.stop();
        result = true;
        callbackContext.success("mocking stopped");
      } else {
        callbackContext.error("geofaker has already stopped");
      }
    } else if (ACTION_MOCK.equalsIgnoreCase(action)) {
      Intent intent = new Intent();
      intent.setAction(Geofaker.INTENT_MOCK_GPS_PROVIDER);
      intent.putExtra(Geofaker.MOCKED_JSON_COORDINATES, data.toString());
      activity.sendBroadcast(intent);
      result = true;
      callbackContext.success("mocked position: " + data.toString());
    }

    return result;
  }
コード例 #16
0
  @Override
  public boolean onOptionsItemSelected(MenuItem item) {

    switch (item.getItemId()) {
      case android.R.id.home:
        sharedPrefs.edit().putBoolean("should_refresh", false).commit();
        onBackPressed();
        return true;

      case R.id.menu_settings:
        Intent settings = new Intent(context, SettingsActivity.class);
        startActivityForResult(settings, SETTINGS_RESULT);
        return true;

      case R.id.menu_save_search:
        Toast.makeText(context, getString(R.string.saving_search), Toast.LENGTH_SHORT).show();
        new Thread(
                new Runnable() {
                  @Override
                  public void run() {
                    try {
                      Twitter twitter = Utils.getTwitter(context, AppSettings.getInstance(context));
                      twitter.createSavedSearch(
                          searchQuery.replace(" -RT", "").replace(" TOP", ""));

                      ((Activity) context)
                          .runOnUiThread(
                              new Runnable() {
                                @Override
                                public void run() {
                                  Toast.makeText(
                                          context, getString(R.string.success), Toast.LENGTH_SHORT)
                                      .show();
                                }
                              });
                    } catch (TwitterException e) {
                      // something went wrong
                    }
                  }
                })
            .start();
        return super.onOptionsItemSelected(item);

      case R.id.menu_compose_with_search:
        Intent compose = new Intent(context, ComposeActivity.class);
        compose.putExtra("user", searchQuery);
        startActivity(compose);
        return super.onOptionsItemSelected(item);

      case R.id.menu_search:
        // overridePendingTransition(0,0);
        // finish();
        // overridePendingTransition(0,0);
        // return super.onOptionsItemSelected(item);

      case R.id.menu_pic_filter:
        if (!item.isChecked()) {
          searchQuery += " filter:links twitter.com";
          item.setChecked(true);
        } else {
          searchQuery = searchQuery.replace("filter:links", "").replace("twitter.com", "");
          item.setChecked(false);
        }

        Intent broadcast = new Intent("com.klinker.android.twitter.NEW_SEARCH");
        broadcast.putExtra("query", searchQuery);
        context.sendBroadcast(broadcast);

        return super.onOptionsItemSelected(item);

      case R.id.menu_remove_rt:
        if (!item.isChecked()) {
          searchQuery += " -RT";
          item.setChecked(true);
        } else {
          searchQuery = searchQuery.replace(" -RT", "");
          item.setChecked(false);
        }

        broadcast = new Intent("com.klinker.android.twitter.NEW_SEARCH");
        broadcast.putExtra("query", searchQuery);
        context.sendBroadcast(broadcast);

        return super.onOptionsItemSelected(item);

      case R.id.menu_show_top_tweets:
        if (!item.isChecked()) {
          searchQuery += " TOP";
          item.setChecked(true);
        } else {
          searchQuery = searchQuery.replace(" TOP", "");
          item.setChecked(false);
        }

        broadcast = new Intent("com.klinker.android.twitter.NEW_SEARCH");
        broadcast.putExtra("query", searchQuery);
        context.sendBroadcast(broadcast);

        return super.onOptionsItemSelected(item);

      default:
        return super.onOptionsItemSelected(item);
    }
  }
 // *****************************************************************************
 // Helper Methods
 // *****************************************************************************
 protected void SendMessage(String message) {
   intent.putExtra(OUT_MESSAGE_KEY, message);
   intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
   parentActivity.sendBroadcast(intent);
 }
コード例 #18
0
 /** Broadcasts the given intent to all interested BroadcastReceivers. */
 public void sendBroadcast(Intent intent) {
   mActivity.sendBroadcast(intent);
 }