public static void registerDeviceForPushNotifications(final Context ctx, String token) {
    SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(ctx);
    String uuid = settings.getString(WPCOM_PUSH_DEVICE_UUID, null);
    if (uuid == null) return;

    String deviceName = DeviceUtils.getInstance().getDeviceName(ctx);
    Map<String, String> contentStruct = new HashMap<String, String>();
    contentStruct.put("device_token", token);
    contentStruct.put("device_family", "android");
    contentStruct.put("app_secret_key", NotificationUtils.getAppPushNotificationsName());
    contentStruct.put("device_name", deviceName);
    contentStruct.put("device_model", Build.MANUFACTURER + " " + Build.MODEL);
    contentStruct.put("app_version", WordPress.versionName);
    contentStruct.put("os_version", android.os.Build.VERSION.RELEASE);
    contentStruct.put("device_uuid", uuid);
    com.wordpress.rest.RestRequest.Listener listener =
        new RestRequest.Listener() {
          @Override
          public void onResponse(JSONObject jsonObject) {
            AppLog.d(T.NOTIFS, "Register token action succeeded");
            try {
              String deviceID = jsonObject.getString("ID");
              if (deviceID == null) {
                AppLog.e(
                    T.NOTIFS,
                    "Server response is missing of the device_id. Registration skipped!!");
                return;
              }
              SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(ctx);
              SharedPreferences.Editor editor = settings.edit();
              editor.putString(WPCOM_PUSH_DEVICE_SERVER_ID, deviceID);
              JSONObject settingsJSON = jsonObject.getJSONObject("settings");
              editor.putString(WPCOM_PUSH_DEVICE_NOTIFICATION_SETTINGS, settingsJSON.toString());
              editor.commit();
              AppLog.d(T.NOTIFS, "Server response OK. The device_id : " + deviceID);
            } catch (JSONException e1) {
              AppLog.e(T.NOTIFS, "Server response is NOT ok. Registration skipped!!", e1);
            }
          }
        };
    RestRequest.ErrorListener errorListener =
        new RestRequest.ErrorListener() {
          @Override
          public void onErrorResponse(VolleyError volleyError) {
            AppLog.e(T.NOTIFS, "Register token action failed", volleyError);
          }
        };

    WordPress.getRestClientUtils()
        .post("/devices/new", contentStruct, null, listener, errorListener);
  }
Esempio n. 2
0
  /*
   * returns entire log as plain text
   */
  public static String toPlainText(Context context) {
    StringBuilder sb = new StringBuilder();

    // add version & device info
    sb.append("WordPress Android version: " + WordPress.getVersionName(context))
        .append("\n")
        .append("Android device name: " + DeviceUtils.getInstance().getDeviceName(context))
        .append("\n\n");

    Iterator<LogEntry> it = mLogEntries.iterator();
    int lineNum = 1;
    while (it.hasNext()) {
      sb.append(String.format("%02d - ", lineNum)).append(it.next().logText).append("\n");
      lineNum++;
    }
    return sb.toString();
  }
  @Override
  public void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    setContentView(R.layout.about);

    if (DeviceUtils.getInstance().isBlackBerry()) {
      TextView appTitle = (TextView) findViewById(R.id.about_first_line);
      appTitle.setText(getString(R.string.app_title_blackberry));
    }

    TextView version = (TextView) findViewById(R.id.about_version);
    version.setText(getString(R.string.version) + " " + WordPress.versionName);

    Button tos = (Button) findViewById(R.id.about_tos);
    tos.setOnClickListener(this);

    Button pp = (Button) findViewById(R.id.about_privacy);
    pp.setOnClickListener(this);
  }
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
          // Adjust position if only one blog is in the app
          if (mListView.getHeaderViewsCount() > 0 && position > 0) position--;

          if (!mIsDotComBlog) position++;

          if (position == mActivePosition) {
            // Same row selected
            mMenuDrawer.closeMenu();
            return;
          }

          int activityTag = (Integer) view.getTag();

          mActivePosition = position;
          mAdapter.notifyDataSetChanged();
          Intent intent = null;

          SharedPreferences settings =
              PreferenceManager.getDefaultSharedPreferences(WPActionBarActivity.this);
          SharedPreferences.Editor editor = settings.edit();

          switch (activityTag) {
            case READER_ACTIVITY:
              if (!(WPActionBarActivity.this instanceof ReaderActivity)) mShouldFinish = true;
              int readerBlogID = WordPress.wpDB.getWPCOMBlogID();
              if (WordPress.currentBlog.isDotcomFlag()) {
                intent = new Intent(WPActionBarActivity.this, ReaderActivity.class);
                intent.putExtra("id", readerBlogID);
                intent.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
                editor.putInt("wp_pref_last_activity", READER_ACTIVITY);
              }
              break;
            case POSTS_ACTIVITY:
              if (!(WPActionBarActivity.this instanceof PostsActivity)
                  || (WPActionBarActivity.this instanceof PagesActivity)) mShouldFinish = true;
              intent = new Intent(WPActionBarActivity.this, PostsActivity.class);
              intent.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
              editor.putInt("wp_pref_last_activity", POSTS_ACTIVITY);
              break;
            case PAGES_ACTIVITY:
              if (!(WPActionBarActivity.this instanceof PagesActivity)) mShouldFinish = true;
              intent = new Intent(WPActionBarActivity.this, PagesActivity.class);
              intent.putExtra("id", WordPress.currentBlog.getId());
              intent.putExtra("isNew", true);
              intent.putExtra("viewPages", true);
              intent.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
              editor.putInt("wp_pref_last_activity", PAGES_ACTIVITY);
              break;
            case COMMENTS_ACTIVITY:
              if (!(WPActionBarActivity.this instanceof CommentsActivity)) mShouldFinish = true;
              intent = new Intent(WPActionBarActivity.this, CommentsActivity.class);
              intent.putExtra("id", WordPress.currentBlog.getId());
              intent.putExtra("isNew", true);
              intent.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
              editor.putInt("wp_pref_last_activity", COMMENTS_ACTIVITY);
              break;
              //                case STATS_ACTIVITY:
              //                    if (!(WPActionBarActivity.this instanceof StatsActivity))
              //                        mShouldFinish = true;
              //                    intent = new Intent(WPActionBarActivity.this,
              // StatsActivity.class);
              //                    intent.putExtra("id", WordPress.currentBlog.getId());
              //                    intent.putExtra("isNew",
              //                            true);
              //                    intent.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
              //                    editor.putInt("wp_pref_last_activity", STATS_ACTIVITY);
              //                    break;
            case QUICK_PHOTO_ACTIVITY:
              mShouldFinish = false;
              intent = new Intent(WPActionBarActivity.this, EditPostActivity.class);
              intent.putExtra(
                  "quick-media",
                  DeviceUtils.getInstance().hasCamera(getApplicationContext())
                      ? Constants.QUICK_POST_PHOTO_CAMERA
                      : Constants.QUICK_POST_PHOTO_LIBRARY);
              intent.putExtra("isNew", true);
              break;
            case QUICK_VIDEO_ACTIVITY:
              mShouldFinish = false;
              intent = new Intent(WPActionBarActivity.this, EditPostActivity.class);
              intent.putExtra(
                  "quick-media",
                  DeviceUtils.getInstance().hasCamera(getApplicationContext())
                      ? Constants.QUICK_POST_VIDEO_CAMERA
                      : Constants.QUICK_POST_VIDEO_LIBRARY);
              intent.putExtra("isNew", true);
              break;
            case VIEW_SITE_ACTIVITY:
              if (!(WPActionBarActivity.this instanceof ViewSiteActivity)) mShouldFinish = true;
              intent = new Intent(WPActionBarActivity.this, ViewSiteActivity.class);
              intent.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
              editor.putInt("wp_pref_last_activity", VIEW_SITE_ACTIVITY);
              break;
            case DASHBOARD_ACTIVITY:
              if (!(WPActionBarActivity.this instanceof DashboardActivity)) mShouldFinish = true;
              intent = new Intent(WPActionBarActivity.this, DashboardActivity.class);
              intent.putExtra("loadAdmin", true);
              intent.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
              editor.putInt("wp_pref_last_activity", DASHBOARD_ACTIVITY);
              break;
            case SETTINGS_ACTIVITY:
              // Settings shouldn't be launched with a delay, or close the drawer
              mShouldFinish = false;
              Intent settingsIntent =
                  new Intent(WPActionBarActivity.this, PreferencesActivity.class);
              startActivityForResult(settingsIntent, SETTINGS_REQUEST);
              return;
          }

          editor.commit();
          if (intent != null) {
            mMenuDrawer.closeMenu();
            startActivityWithDelay(intent);
          }
        }