private void noticeNewBlog(Context context) {
    NotificationManager notiManager =
        (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    notiManager.cancel(Constants.NOTIFICATION_NEW_MICRO_BLOG); // 先清除上一次提醒;

    Intent intent = new Intent();
    // 粉丝
    if (entity.getContentType() == Skeleton.TYPE_MORE) {
      intent.setAction("com.shejiaomao.weibo.SOCIAL_GRAPH");
      intent.addCategory("android.intent.category.DEFAULT");
      intent.putExtra("SOCIAL_GRAPH_TYPE", SocialGraphTask.TYPE_FOLLOWERS);
      intent.putExtra("USER", account.getUser());
    } else {
      intent.setAction("com.shejiaomao.weibo.MAIN");
      intent.addCategory("android.intent.category.DEFAULT");
      intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    }
    intent.putExtra("CONTENT_TYPE", entity.getContentType());
    intent.putExtra("ACCOUNT", account);

    Notification notification = new Notification();
    notification.icon = R.drawable.icon_notification;
    notification.flags = Notification.FLAG_AUTO_CANCEL;
    notification.tickerText = entity.getTickerText();

    if (sheJiaoMao.isVibrateNotification()) {
      notification.defaults |= Notification.DEFAULT_VIBRATE;
    }
    if (sheJiaoMao.isRingtoneNotification()) {
      if (StringUtil.isNotEmpty(sheJiaoMao.getRingtoneUri())) {
        notification.sound = Uri.parse(sheJiaoMao.getRingtoneUri());
      } else {
        notification.defaults |= Notification.DEFAULT_SOUND;
      }
    }

    if (sheJiaoMao.isFlashingLEDNotification()) {
      notification.ledARGB = Color.GREEN;
      notification.ledOffMS = 1000;
      notification.ledOnMS = 1000;
      notification.flags |= Notification.FLAG_SHOW_LIGHTS;
    }

    int requestCode = account.getAccountId().intValue() * 100 + entity.getContentType();
    PendingIntent pendingIntent =
        PendingIntent.getActivity(context, requestCode, intent, PendingIntent.FLAG_UPDATE_CURRENT);

    notification.setLatestEventInfo(
        context, entity.getContentTitle(), entity.getContentText(), pendingIntent);

    notiManager.notify(requestCode, notification);
  }
  private void startMediaPlayer(
      int iAction,
      int iType,
      int iPosition,
      int iMaxProgress,
      int iCurProgress,
      String sAudioId,
      String sTitle,
      String sDescription) {
    if (iAudioPlayerState == 1) return;
    Intent intent = new Intent(NewPlayMusicActivity.this, PlayMusicService.class);
    if (iAction == 2) intent.setAction(PlayMusicService.ACTION_NEXT);
    else intent.setAction(PlayMusicService.ACTION_PLAY);
    Bundle bundle = new Bundle();

    bundle.putInt("type", iType);
    bundle.putInt("position", iPosition);
    Log.d(Const.APP_TAG, "startMediaPlayer() position:" + iPosition);
    bundle.putInt("maxprogress", iMaxProgress);
    bundle.putInt("curprogress", iCurProgress);
    bundle.putString("id", sAudioId);
    bundle.putString("title", sTitle);
    bundle.putString("description", sDescription);
    intent.putExtras(bundle);

    startService(intent);

    mBtnMediaPlayPause.setImageResource(android.R.drawable.ic_media_pause);
  }
Example #3
0
  /**
   * Set share intent
   *
   * @param selectedItems
   * @return shared intent
   */
  public static Intent createShareIntent(ArrayList<MediaObject> selectedItems) {
    final ArrayList<Uri> uris = new ArrayList<Uri>();
    final Intent intent = new Intent();
    int mediaType = 0;
    String mimeType = "image/*";

    for (int i = 0; selectedItems.size() > i; i++) {
      if (uris.size() >= 1000) break;
      mediaType = selectedItems.get(i).getType();
      mimeType = (mediaType == MediaItem.IMAGE) ? "image/*" : "video/*";

      MediaItem item = (MediaItem) selectedItems.get(i);
      Uri uri = ContentUris.withAppendedId(item.getUri(mediaType), item.getId());
      uris.add(uri);
    }

    final int size = uris.size();
    if (size > 0) {

      if (size > 1) {
        intent.setAction(Intent.ACTION_SEND_MULTIPLE).setType(mimeType);
        intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);
      } else {
        intent.setAction(Intent.ACTION_SEND).setType(mimeType);
        intent.putExtra(Intent.EXTRA_STREAM, uris.get(0));
      }
      intent.setType(mimeType);
    }

    return intent;
  }
Example #4
0
  @Override
  public void onReceive(Context context, Intent intent) {
    if (intent != null) {
      String action = intent.getAction();
      if (action == null) return;

      if (DefaultAmarinoServiceIntentConfig.ACTION_CONNECT.equals(action)) {
        Logger.d(TAG, "CONNECT request received");
        Intent i = new Intent(context, AmarinoService.class);
        i.setAction(DefaultAmarinoServiceIntentConfig.ACTION_CONNECT);
        i.replaceExtras(intent);
        context.startService(i);
      } else if (DefaultAmarinoServiceIntentConfig.ACTION_DISCONNECT.equals(action)) {
        Logger.d(TAG, "DISCONNECT request received");
        Intent i = new Intent(context, AmarinoService.class);
        i.setAction(DefaultAmarinoServiceIntentConfig.ACTION_DISCONNECT);
        i.replaceExtras(intent);
        context.startService(i);
      } else if (DefaultAmarinoServiceIntentConfig.ACTION_GET_CONNECTED_DEVICES.equals(action)) {
        Logger.d(TAG, "GET_CONNECTED_DEVICES request received");
        Intent i = new Intent(context, AmarinoService.class);
        i.setAction(DefaultAmarinoServiceIntentConfig.ACTION_GET_CONNECTED_DEVICES);
        context.startService(i);
      }
    }
  }
  @Override
  public void onClick(View v) {
    Context context = v.getContext();
    Intent intent = new Intent();
    intent.putExtras(mArgs);
    intent.putExtra("access_token", StateKeeper.accessToken.getAccessToken());

    switch (v.getId()) {
      case R.id.attitudes_count:
      case R.id.retweeted_attitudes_count:
        break;
      case R.id.reposts_count:
      case R.id.retweeted_reposts_count:
        intent.setClass(context, RepostActivity.class);
        intent.setAction(Status.REPOST_LIST);
        break;
      case R.id.comments_count:
      case R.id.retweeted_comments_count:
        intent.setClass(context, CommentActivity.class);
        intent.setAction(Comment.FOR_STATUS);
        break;
      case R.id.to_reply:
        intent.setClass(context, SendActivity.class);
        intent.setAction(Comment.REPLY);
        break;
    }

    context.startActivity(intent);
  }
Example #6
0
  @Override
  public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
    super.onUpdate(context, appWidgetManager, appWidgetIds);

    RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.menu_layout);

    Intent update = new Intent(context, MenuProvider.class);
    update.setAction(CLICK_UPDATE);
    PendingIntent pendingIntent = PendingIntent.getBroadcast(context, update_code, update, 0);
    remoteViews.setOnClickPendingIntent(R.id.update, pendingIntent);

    Intent nextDate = new Intent(context, MenuProvider.class);
    nextDate.setAction(CLICK_NEXT);
    pendingIntent = PendingIntent.getBroadcast(context, right_code, nextDate, 0);
    remoteViews.setOnClickPendingIntent(R.id.arrow_right, pendingIntent);

    Intent previousDate = new Intent(context, MenuProvider.class);
    previousDate.setAction(CLICK_PREVIOUS);
    pendingIntent = PendingIntent.getBroadcast(context, left_code, previousDate, 0);
    remoteViews.setOnClickPendingIntent(R.id.arrow_left, pendingIntent);

    remoteViews.setRemoteAdapter(R.id.dish_list, new Intent(context, DishListService.class));
    updateDate(remoteViews, R.id.date_text, PreferenceManager.getCalendar(context));
    appWidgetManager.updateAppWidget(appWidgetIds, remoteViews);
  }
Example #7
0
 public void servicioGuardarPosicion() {
   if (recuperarPreferenciaBoolean("servicio1")
       && (!recuperarPreferenciaBoolean("servicioActivo") || sp == null)) {
     Log.d("TabsActivity", "Activar servicio");
     SharedPreferences sp =
         this.getSharedPreferences("es.nervion.maps.activity_preferences", Context.MODE_PRIVATE);
     SharedPreferences.Editor spe = sp.edit();
     spe.putBoolean("pref_servicioActivo", true);
     spe.commit();
     Intent msgIntent = new Intent(this, SubirPosicionIntentService.class);
     msgIntent.setAction(SubirPosicionIntentService.BROADCAST_ACTION);
     msgIntent.putExtra("vivo", true);
     msgIntent.putExtra("refresco", 30000);
     msgIntent.putExtra("nombre", recuperarPreferenciaString("nombre"));
     msgIntent.putExtra("estado", recuperarPreferenciaString("estado"));
     msgIntent.putExtra("radio", recuperarPreferenciaInteger("radio"));
     startService(msgIntent);
   } else if (!recuperarPreferenciaBoolean("servicio1")
       && recuperarPreferenciaBoolean("servicioActivo")) {
     Log.d("TabsActivity", "Desactivar servicio");
     Intent intentPararServicio = new Intent(this, SubirPosicionIntentService.class);
     intentPararServicio.setAction(SubirPosicionIntentService.BROADCAST_MUERE);
     stopService(intentPararServicio);
     SharedPreferences sp =
         this.getSharedPreferences("es.nervion.maps.activity_preferences", Context.MODE_PRIVATE);
     SharedPreferences.Editor spe = sp.edit();
     spe.putBoolean("pref_servicioActivo", false);
     spe.commit();
   }
 }
Example #8
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    final TabHost tabHost = getTabHost();

    Intent intent = getIntent();

    String sUrlSrc = intent.getStringExtra("urlsrc");
    String sUrlDst = intent.getStringExtra("urldst");
    String sLangSrc = intent.getStringExtra("langsrc");
    String sLangDst = intent.getStringExtra("langdst");

    Intent inSrc = new Intent(this, MyBrowser.class);
    Intent inDst = new Intent(this, MyBrowser.class);
    inSrc.setAction(sUrlSrc);
    inDst.setAction(sUrlDst);

    tabHost.addTab(
        tabHost
            .newTabSpec("tab1")
            .setIndicator("", getResources().getDrawable(GetDrawableLangFromText(sLangSrc)))
            .setContent(inSrc));
    tabHost.addTab(
        tabHost
            .newTabSpec("tab2")
            .setIndicator("", getResources().getDrawable(GetDrawableLangFromText(sLangDst)))
            .setContent(inDst));
  }
Example #9
0
  private void clickMasterIntent(Integer request) {
    EditText inputText = (EditText) findViewById(R.id.input_entry);
    String inputStr = inputText.getText().toString();

    Intent i = new Intent();
    i.putExtra(CryptoIntents.EXTRA_TEXT, inputStr);

    if (request == ENCRYPT_REQUEST) {
      i.setAction(CryptoIntents.ACTION_ENCRYPT);
    } else if (request == DECRYPT_REQUEST) {
      i.setAction(CryptoIntents.ACTION_DECRYPT);
    } else if (request == GET_PASSWORD_REQUEST) {
      i.putExtra(CryptoIntents.EXTRA_UNIQUE_NAME, inputStr);
      i.setAction(CryptoIntents.ACTION_GET_PASSWORD);
    } else if (request == SET_PASSWORD_REQUEST) {
      String uniqueNameStr = ((EditText) findViewById(R.id.unique_name_entry)).getText().toString();
      String passwordStr = ((EditText) findViewById(R.id.password_entry)).getText().toString();
      String usernameStr = ((EditText) findViewById(R.id.username_entry)).getText().toString();

      i.putExtra(CryptoIntents.EXTRA_UNIQUE_NAME, uniqueNameStr);
      i.putExtra(CryptoIntents.EXTRA_PASSWORD, passwordStr);
      i.putExtra(CryptoIntents.EXTRA_USERNAME, usernameStr);

      i.setAction(CryptoIntents.ACTION_SET_PASSWORD);
    }
    try {
      startActivityForResult(i, request);
    } catch (ActivityNotFoundException e) {
      Log.e(TAG, "failed to invoke intent: " + e.toString());
    }
  }
  @Override
  public void onStart(Intent intent, int startId) {
    super.onStart(intent, startId);
    Log.v(TAG, "onStart");

    // RemoteViews is used with widget. This can be displayed in another process.
    RemoteViews remoteViews = new RemoteViews(getPackageName(), R.layout.main);
    // Prepare Intent which is sent when button is clicked
    Intent buttonIntent = new Intent();

    // If this Intent is issued when button is clicked
    if (BUTTON_CLICK_ACTION.equals(intent.getAction())) {
      buttonIntent.setAction(BUTTON_CLICK_ACTION2);
      remoteViews.setTextViewText(R.id.text, "Push Button");
    } else {
      buttonIntent.setAction(BUTTON_CLICK_ACTION);
      remoteViews.setTextViewText(R.id.text, "WidgetSample");
    }

    // Handle this Intent as PendingIntent
    PendingIntent pendingIntent = PendingIntent.getService(this, 0, buttonIntent, 0);
    remoteViews.setOnClickPendingIntent(R.id.button, pendingIntent);
    Log.v(TAG, "set PendingIntent here");
    Toast.makeText(this, "set PendingIntent", Toast.LENGTH_SHORT).show();

    // Update AppWidget display
    ComponentName thisWidget = new ComponentName(this, WidgetSample.class);
    AppWidgetManager manager = AppWidgetManager.getInstance(this);
    manager.updateAppWidget(thisWidget, remoteViews);
  }
  @Override
  public void onReceive(Context context, Intent intent) {
    /** Place to start service,activity or notification or any other action */
    System.out.println(TAG + " @OnReceive :" + intent.getAction());
    if (intent.hasExtra(Extras.URL)) {
      String url = intent.getStringExtra(Extras.URL);
      Intent intent1 = new Intent(context, BroadCastActivity.class);
      intent1.setAction(Intent.ACTION_MAIN);
      intent1.setAction(Intent.CATEGORY_LAUNCHER);
      intent1.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
      PendingIntent pendingIntent =
          PendingIntent.getActivity(context, 1, intent1, PendingIntent.FLAG_UPDATE_CURRENT);

      Notification notification =
          new NotificationCompat.Builder(context)
              .setContentTitle("Downloaded json")
              .setContentText(url)
              .setContentIntent(pendingIntent)
              .setSmallIcon(R.drawable.ic_stat_av_play_circle_outline)
              .setWhen(System.currentTimeMillis())
              .build();
      NotificationManager notificationManager =
          (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
      notificationManager.notify((int) (Math.random() * 100), notification);
    }
  }
  /**
   * Share the provided photo through other android apps
   *
   * <p>Will share the image as a image/jpg content type and include title and description as extra
   *
   * @param slideshowPhoto
   */
  public void actionSharePhoto(SlideshowPhoto slideshowPhoto) {
    Log.i(LOG_PREFIX, "Attempting to share photo " + slideshowPhoto);
    // TODO: Refactor this code.. rather ugly due to some GoogleTV related hacks

    if (slideshowPhoto != null) {
      Intent shareIntent = new Intent();
      shareIntent.setAction(Intent.ACTION_SEND);
      // we assume the type is image/jpg
      shareIntent.setType("image/jpg");

      String sharedText =
          slideshowPhoto.getTitle()
              + ": "
              + slideshowPhoto.getDescription()
              + "\n\n"
              + getResources().getString(R.string.share_footer);

      // if we have a cached file, add the stream and the sharedText
      // if not, add the url and the sharedText
      if (slideshowPhoto.isCacheExisting(rootFileDirectory)) {
        String path =
            "file://" + rootFileDirectory.getAbsolutePath() + "/" + slideshowPhoto.getFileName();
        Log.i(LOG_PREFIX, "Attempting to pass stream url " + path);
        shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse(path));
        shareIntent.putExtra(Intent.EXTRA_TEXT, sharedText);
      } else {
        shareIntent.putExtra(
            Intent.EXTRA_TEXT, slideshowPhoto.getLargePhoto() + "\n\n" + sharedText);
      }

      shareIntent.putExtra(Intent.EXTRA_SUBJECT, slideshowPhoto.getTitle());

      // Start the actual sharing activity
      try {
        List<ResolveInfo> relevantActivities =
            getPackageManager().queryIntentActivities(shareIntent, 0);
        if (AndroidUtils.isGoogleTV(getApplicationContext())
            || relevantActivities == null
            || relevantActivities.size() == 0) {
          Log.i(
              LOG_PREFIX,
              "No activity found that can handle image/jpg. Performing simple text share");
          Intent backupShareIntent = new Intent();
          backupShareIntent.setAction(Intent.ACTION_SEND);
          backupShareIntent.setType("text/plain");
          String backupSharedText = slideshowPhoto.getLargePhoto() + "\n\n" + sharedText;
          backupShareIntent.putExtra(Intent.EXTRA_TEXT, backupSharedText);
          startActivity(backupShareIntent);
        } else {
          startActivity(shareIntent);
        }

      } catch (ActivityNotFoundException e) {
        notifyUser("Unable to share current photo");
      }

    } else {
      notifyUser("Unable to share current photo");
    }
  }
 @Override
 public void onClick(View v) {
   Intent intent = null;
   int id = v.getId();
   if (id == R.id.resource_take) {
     intent = new Intent();
     SimpleDateFormat sdf = new SimpleDateFormat(SystemMethodUtil.LongDateTimeSdf);
     temFile =
         new File(
             filePathFolder
                 + "/"
                 + sdf.format(Calendar.getInstance(Locale.CHINA).getTime())
                 + ".jpg");
     intent.setAction(MediaStore.ACTION_IMAGE_CAPTURE);
     intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(temFile));
     ((Activity) context).startActivityForResult(intent, R.id.resource_take);
   } else if (id == R.id.resource_pick) {
     intent = new Intent();
     intent.setAction(Intent.ACTION_GET_CONTENT);
     intent.addCategory(Intent.CATEGORY_OPENABLE);
     intent.setType("image/");
     ((Activity) context).startActivityForResult(intent, R.id.resource_pick);
   } else if (id == R.id.resource_cancel) {
     IsImgShow = false;
   }
   dismiss();
 }
Example #14
0
 @Override
 protected void startDetailsIntent(int index) {
   Intent intent = new Intent(getActivity(), DetailsActivity.class);
   switch (index) {
     case SHOW:
       return;
     case UPDATE:
       intent.setAction(Tweet.ACTION_TWEET_UPDATE);
       break;
     case DESTROY:
       intent.setAction(Tweet.ACTION_TWEET_DESTROY);
       break;
     case RETWEET:
       intent.setAction(Tweet.ACTION_TWEET_RETWEET);
       break;
     case GET_RETWEETS:
       intent.setAction(Tweet.ACTION_TWEET_GET_RETWEETS);
       break;
     case GET_RETWEETED_BY:
       break;
     case GET_RETWEETED_BY_IDS:
       break;
     case FAVORITES:
       intent.setAction(Tweet.ACTION_TWEET_FAVORITES);
       break;
     case CREATE_FAVORITE:
       break;
     default:
       return;
   }
   startActivity(intent);
 }
  @Override
  public void onReceive(Context context, Intent intent) {
    ExtensionManager extensionManager = ExtensionManager.getInstance(context);
    if (extensionManager.cleanupExtensions()) {
      LOGD(TAG, "Extension cleanup performed and action taken.");

      Intent widgetUpdateIntent = new Intent(context, DashClockService.class);
      widgetUpdateIntent.setAction(DashClockService.ACTION_UPDATE_WIDGETS);
      context.startService(widgetUpdateIntent);
    }

    // If this is a replacement or change in the package, update all active extensions from
    // this package.
    String action = intent.getAction();
    if (Intent.ACTION_PACKAGE_CHANGED.equals(action)
        || Intent.ACTION_PACKAGE_REPLACED.equals(action)) {
      String packageName = intent.getData().getSchemeSpecificPart();
      if (TextUtils.isEmpty(packageName)) {
        return;
      }

      List<ComponentName> activeExtensions = extensionManager.getActiveExtensionNames();
      for (ComponentName cn : activeExtensions) {
        if (packageName.equals(cn.getPackageName())) {
          Intent extensionUpdateIntent = new Intent(context, DashClockService.class);
          extensionUpdateIntent.setAction(DashClockService.ACTION_UPDATE_EXTENSIONS);
          extensionUpdateIntent.putExtra(
              DashClockService.EXTRA_COMPONENT_NAME, cn.flattenToShortString());
          context.startService(extensionUpdateIntent);
        }
      }
    }
  }
  private final void saveNote() {
    String text = mText.getText().toString();
    int length = text.length();

    if (mState == STATE_INSERT) {
      if (length == 0) {
        Toast.makeText(this, R.string.nothing_to_save, Toast.LENGTH_SHORT).show();
        return;
      }

      String title = text.substring(0, Math.min(30, length));
      if (length > 30) {
        int lastSpace = title.lastIndexOf(' ');
        if (lastSpace > 0) {
          title = title.substring(0, lastSpace);
        }
      }
      Intent intent = new Intent();
      intent.setAction(Intent.ACTION_INSERT);
      intent.putExtra("title", title);
      intent.putExtra("body", text);
      setResult(RESULT_OK, intent);
    } else if (mState == STATE_EDIT) {
      Intent intent = new Intent();
      intent.setAction(Intent.ACTION_EDIT);
      intent.putExtra("body", text);
      setResult(RESULT_OK, intent);
    }
  }
Example #17
0
  // setShortcut(): Sets up the intent for Google Maps and creates the shortcuts on the user's
  // homescreen.
  private void setShortcut(int mode) {

    // Sets the reference to the address input.
    EditText address_1 = (EditText) findViewById(R.id.address_input_1);
    String location = new String();

    // Retrieves the address from the user's input.
    try {
      location = address_1.getText().toString();
      location = location.replace(" ", "+");
    }

    // NullPointerException handler.
    catch (NullPointerException e) {

      // A Toast message appears, notifying the user about the error.
      toastyPopUp("ERROR: NULLPOINTEREXCEPTION ENCOUNTERED WHILE RETRIEVING ADDRESS INPUT.");
    }

    // Launches Google Map in navigation mode and begins navigation immediately.
    Intent shortcutIntent =
        new Intent(
            android.content.Intent.ACTION_VIEW, Uri.parse("google.navigation:q=" + location));
    shortcutIntent.setAction(Intent.ACTION_VIEW);

    // Adds the address in the customized intent for Google Maps.
    Intent addIntent = new Intent();
    addIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
    addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, address_1.getText().toString());

    int iconResource = R.drawable.home_icon; // Used for setting the shortcut icon resource.

    // Sets the icon based on the selected mode.
    switch (mode) {

        // HOME:
      case 0:
        iconResource = R.drawable.home_icon;
        break;

        // WORK:
      case 1:
        iconResource = R.drawable.work_icon;
        break;

        // PLACE:
      case 2:
        iconResource = R.drawable.place_icon;
        break;
    }

    // Sets the icon resource for the shortcut.
    addIntent.putExtra(
        Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
        Intent.ShortcutIconResource.fromContext(getApplicationContext(), iconResource));

    // Installs the shortcut on the homescreen.
    addIntent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
    getApplicationContext().sendBroadcast(addIntent);
  }
 private void encrypt(Uri dataUri, boolean text) {
   // If there is no encryption key, don't bother.
   if (!mHasEncrypt) {
     Notify.showNotify(getActivity(), R.string.error_no_encrypt_subkey, Notify.Style.ERROR);
     return;
   }
   try {
     long keyId =
         new ProviderHelper(getActivity())
             .getCachedPublicKeyRing(dataUri)
             .extractOrGetMasterKeyId();
     long[] encryptionKeyIds = new long[] {keyId};
     Intent intent;
     if (text) {
       intent = new Intent(getActivity(), EncryptTextActivity.class);
       intent.setAction(EncryptTextActivity.ACTION_ENCRYPT_TEXT);
       intent.putExtra(EncryptTextActivity.EXTRA_ENCRYPTION_KEY_IDS, encryptionKeyIds);
     } else {
       intent = new Intent(getActivity(), EncryptFileActivity.class);
       intent.setAction(EncryptFileActivity.ACTION_ENCRYPT_DATA);
       intent.putExtra(EncryptFileActivity.EXTRA_ENCRYPTION_KEY_IDS, encryptionKeyIds);
     }
     // used instead of startActivity set actionbar based on callingPackage
     startActivityForResult(intent, 0);
   } catch (PgpGeneralException e) {
     Log.e(Constants.TAG, "key not found!", e);
   }
 }
Example #19
0
 // common utility - return intent to launch reader by reader name and full file name. Null if not
 // found
 public Intent launchReader(String name, String file) {
   String re[] = name.split(":");
   if (re.length == 2 && re[0].equals("Intent")) {
     Intent i = new Intent();
     i.setAction(Intent.ACTION_VIEW);
     i.setDataAndType(Uri.parse("file://" + file), re[1]);
     addToList("lastOpened", file, false);
     if (!history.containsKey(file) || history.get(file) == FINISHED) history.put(file, READING);
     return i;
   } else {
     Intent i = getIntentByLabel(name);
     if (i == null)
       // Toast.makeText(this, "Activity \"" + name + "\" not found!", Toast.LENGTH_SHORT).show();
       Toast.makeText(
               this,
               getResources().getString(R.string.jv_rla_activity)
                   + " \""
                   + name
                   + "\" "
                   + getResources().getString(R.string.jv_rla_not_found),
               Toast.LENGTH_SHORT)
           .show();
     else {
       i.setAction(Intent.ACTION_VIEW);
       i.setData(Uri.parse("file://" + file));
       addToList("lastOpened", file, false);
       if (!history.containsKey(file) || history.get(file) == FINISHED) history.put(file, READING);
       return i;
     }
   }
   return null;
 }
    @Override
    public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
      Intent intent = new Intent();

      if (PREF_KEY_LOCKSCREEN_SHORTCUT.contains(key)) {
        intent.setAction(ACTION_PREF_LOCKSCREEN_SHORTCUT_SETTING_CHANGED);
        intent.putExtra(EXTRA_LS_SHORTCUT_SLOT, PREF_KEY_LOCKSCREEN_SHORTCUT.indexOf(key));
        intent.putExtra(EXTRA_LS_SHORTCUT_VALUE, mPrefs.getString(key, null));
      } else if (key.equals(PREF_SIZE_ICON)) {
        intent.setAction(ACTION_PREF_LOCKSCREEN_SHORTCUT_SETTING_CHANGED);
        intent.putExtra(PREF_SIZE_ICON, sharedPreferences.getInt(key, 40));
      } else if (key.equals(PREF_KEY_LOCKSCREEN_SHORTCUT_SAFE_LAUNCH)) {
        intent.setAction(ACTION_PREF_LOCKSCREEN_SHORTCUT_SETTING_CHANGED);
        intent.putExtra(EXTRA_LS_SAFE_LAUNCH, mPrefs.getBoolean(key, false));
      } else if (key.equals(PREF_HIDE_ICON)) {
        int mode =
            sharedPreferences.getBoolean(key, false)
                ? PackageManager.COMPONENT_ENABLED_STATE_DISABLED
                : PackageManager.COMPONENT_ENABLED_STATE_ENABLED;
        getActivity()
            .getPackageManager()
            .setComponentEnabledSetting(
                new ComponentName(getActivity(), mainClass), mode, PackageManager.DONT_KILL_APP);
      }
      if (intent.getAction() != null) {
        mPrefs.edit().apply();
        getActivity().sendBroadcast(intent);
      }
    }
Example #21
0
  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
    int id = item.getItemId();
    if (id == R.id.action_pt_br) {
      Locale locale = new Locale("pt", "BR");
      tts.setLanguage(locale);
      return true;
    } else if (id == R.id.action_en_us) {
      Locale locale = Locale.ENGLISH;
      tts.setLanguage(locale);
      return true;
    } else if (id == R.id.action_check_data) {
      // Verifica se o pacote de dados do TTS está instalado
      Intent checkIntent = new Intent();
      checkIntent.setAction(TextToSpeech.Engine.ACTION_CHECK_TTS_DATA);
      startActivityForResult(checkIntent, ACTION_CHECK_DATA_CODE);
      return true;
    } else if (id == R.id.action_install_data) {
      // Instala o pacote de dados
      Intent installIntent = new Intent();
      installIntent.setAction(TextToSpeech.Engine.ACTION_INSTALL_TTS_DATA);
      startActivity(installIntent);
      return true;
    }

    return super.onOptionsItemSelected(item);
  }
Example #22
0
 private void rightButtonAction() {
   long time = Utils.getTimeNow();
   Context context = getActivity().getApplicationContext();
   Intent intent = new Intent(context, StopwatchService.class);
   intent.putExtra(Stopwatches.MESSAGE_TIME, time);
   intent.putExtra(Stopwatches.SHOW_NOTIF, false);
   switch (mState) {
     case Stopwatches.STOPWATCH_RUNNING:
       // do stop
       long curTime = Utils.getTimeNow();
       mAccumulatedTime += (curTime - mStartTime);
       doStop();
       intent.setAction(Stopwatches.STOP_STOPWATCH);
       context.startService(intent);
       releaseWakeLock();
       break;
     case Stopwatches.STOPWATCH_RESET:
     case Stopwatches.STOPWATCH_STOPPED:
       // do start
       doStart(time);
       intent.setAction(Stopwatches.START_STOPWATCH);
       context.startService(intent);
       acquireWakeLock();
       break;
     default:
       Log.w(LOG_TAG, "Illegal state " + mState + " while pressing the right stopwatch button");
       break;
   }
 }
Example #23
0
 public static void previous(final Context context, final boolean force) {
   final Intent previous = new Intent(context, MusicService.class);
   if (force) {
     previous.setAction(MusicService.PREVIOUS_FORCE_ACTION);
   } else {
     previous.setAction(MusicService.PREVIOUS_ACTION);
   }
   context.startService(previous);
 }
  public boolean onTouch(View v, MotionEvent e) {
    switch (e.getAction()) {
      case MotionEvent.ACTION_DOWN:
        if (v.getId() == R.id.l1) {
          l1.setBackgroundColor(Color.GRAY);
        }
        if (v.getId() == R.id.l2) {
          l2.setBackgroundColor(Color.GRAY);
        }
        if (v.getId() == R.id.l3) {
          l3.setBackgroundColor(Color.GRAY);
        }
        break;
      case MotionEvent.ACTION_UP:
        if (v.getId() == R.id.l1) {
          l1.setBackgroundColor(Color.WHITE);

          Intent intent = new Intent();
          intent.putExtra("select", "1");
          intent.setAction("shijian");
          context.sendBroadcast(intent);
          this.dismiss();
          //                      Toast.makeText(context, "ok", Toast.LENGTH_LONG).show();
        }
        if (v.getId() == R.id.l2) {
          l2.setBackgroundColor(Color.WHITE);
          Intent intent = new Intent();
          intent.putExtra("select", "2");
          intent.setAction("shijian");
          context.sendBroadcast(intent);

          this.dismiss();
        }
        if (v.getId() == R.id.l3) {
          l3.setBackgroundColor(Color.WHITE);
          Intent intent = new Intent();
          intent.putExtra("select", "3");
          intent.setAction("shijian");
          context.sendBroadcast(intent);
          //  Toast.makeText(context,"ok",Toast.LENGTH_LONG).show();
          this.dismiss();
        }
        break;
      case MotionEvent.ACTION_CANCEL:
        if (v.getId() == R.id.l1) {
          l1.setBackgroundColor(Color.WHITE);
        }
        if (v.getId() == R.id.l2) {
          l1.setBackgroundColor(Color.WHITE);
        }
        if (v.getId() == R.id.l3) {
          l1.setBackgroundColor(Color.WHITE);
        }
        break;
    }
    return true;
  }
	/**
	 * 卸载程序
	 */
	private void uninstallAppliation() {
		// TODO Auto-generated method stub
		Intent intent = new Intent();
		intent.setAction("android.intent.action.VIEW");
		intent.setAction("android.intent.action.DELETE");
		intent.addCategory("android.intent.category.DEFAULT");
		intent.setData(Uri.parse("package:" + appInfo.getPackname()));
		startActivityForResult(intent, 0);
		
	}
 @Override
 public void userAccepted(boolean userAccepted) {
   Intent heartRateConsentReceived = new Intent(this, STARAppService.class);
   if (userAccepted) {
     heartRateConsentReceived.setAction(STARAppService.HEART_RATE_CONSENT_YES);
   } else {
     heartRateConsentReceived.setAction(STARAppService.HEART_RATE_CONSENT_NO);
   }
   startService(heartRateConsentReceived);
   finish();
 }
    private void broadcastMeasurementStart() {
      Intent intent = new Intent();
      intent.setAction(UpdateIntent.MEASUREMENT_PROGRESS_UPDATE_ACTION);
      intent.putExtra(UpdateIntent.TASK_PRIORITY_PAYLOAD, MeasurementTask.USER_PRIORITY);
      MeasurementScheduler.this.sendBroadcast(intent);

      intent.setAction(UpdateIntent.SYSTEM_STATUS_UPDATE_ACTION);
      intent.putExtra(UpdateIntent.STATUS_MSG_PAYLOAD, realTask.getDescriptor() + " is running. ");

      MeasurementScheduler.this.sendBroadcast(intent);
    }
 @Override
 public void onReceive(Context context, Intent intent) {
   Intent mIntentForService = new Intent(context, XmppConnectionService.class);
   if (intent.getAction() != null) {
     mIntentForService.setAction(intent.getAction());
   } else {
     mIntentForService.setAction("other");
   }
   if (intent.getAction().equals("ui")
       || DatabaseBackend.getInstance(context).hasEnabledAccounts()) {
     context.startService(mIntentForService);
   }
 }
 /**
  * @param context
  * @brief methods for creating app shortcut icon on home screen
  */
 public static void createShortcut(Context context) {
   Intent shortcutIntent = new Intent(context, context.getClass());
   shortcutIntent.setAction(Intent.ACTION_MAIN);
   Intent addIntent = new Intent();
   addIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
   addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, context.getString(R.string.app_name));
   addIntent.putExtra(
       Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
       Intent.ShortcutIconResource.fromContext(context, R.mipmap.ic_launcher));
   addIntent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
   context.sendBroadcast(addIntent);
   savePreference(context, "SHORTCUT_CREATED", 1);
 }
 @Override
 protected void onPostExecute(Boolean result) {
   super.onPostExecute(result);
   if (result) { // ture为需要更新,false不需要更新
     Intent intent = new Intent(); // Itent就是我们要发送的内容
     intent.setAction(
         MessageConstants.REFRESH_HELPER); // 设置你这个广播的action,只有和这个action一样的接受者才能接受者才能接收广播
     intent.setAction(
         MessageConstants.REFRESH_GROUP); // 设置你这个广播的action,只有和这个action一样的接受者才能接受者才能接收广播
     // 发送广播
     context.sendBroadcast(intent);
   }
 }