コード例 #1
0
        public void handleMessage(Message message) {
          String TAG = className + ".handleMessage";
          PBLogger.entry(TAG);
          String json = (String) message.obj;
          if (message.arg1 == RESULT_OK && json != null) {
            try {
              cats = CategoriesListHelper.parseCategoriesFromJson(resources, json);
              CategoryListActivity.this.loadCatsIntoPreferences(cats);
              // OK...only now should we proceed to list the categories.

              CategoryListActivity.this.showCategories(cats);
            } catch (PBException e) {
              Toast.makeText(
                      CategoryListActivity.this,
                      resources.getString(R.string.errorTryingToParseCategories),
                      Toast.LENGTH_LONG)
                  .show();
              PBLogger.e(TAG, resources.getString(R.string.errorTryingToParseCategories), e);
            }
          } else {
            Toast.makeText(
                    CategoryListActivity.this,
                    resources.getString(R.string.errorTryingToGetCategoriesFromService),
                    Toast.LENGTH_LONG)
                .show();
            PBLogger.e(TAG, resources.getString(R.string.errorTryingToGetCategoriesFromService));
          }
          PBLogger.exit(TAG);
        }
コード例 #2
0
  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
    String TAG = className + "onOptionsItemSelected";
    PBLogger.entry(TAG);
    Intent preferencesIntent = null;
    switch (item.getItemId()) {
      case R.id.menu_contact_preferences:
        preferencesIntent = new Intent(getBaseContext(), ContactPreferencesActivity.class);
        break;

      case R.id.menu_subscription_preferences:
        preferencesIntent = new Intent(getBaseContext(), SubscriptionPreferencesActivity.class);
      default:
        PBLogger.w(TAG, "No preferences matching itemId = " + item.getItemId());
        break;
    }
    PBLogger.i(TAG, "Setting Preferences Activity -  = " + preferencesIntent);

    if (preferencesIntent != null) {
      startActivity(preferencesIntent);
    }
    PBLogger.exit(TAG);

    return true;
  }
コード例 #3
0
  public static ArrayList<OpportunityCategory> parseCategories(String jsonResponse)
      throws PBException {
    ArrayList<OpportunityCategory> cats = null;
    String TAG = className + ".parseCategories";
    PBLogger.entry(TAG);
    try {
      JSONArray jsonArray = new JSONArray(jsonResponse);
      cats = new ArrayList<OpportunityCategory>(jsonArray.length());
      jsonArray = new JSONArray(jsonResponse);
      for (int i = 0; i < jsonArray.length(); i++) {
        JSONObject jsonObj = jsonArray.getJSONObject(i);
        OpportunityCategory cat = new OpportunityCategory();
        cat.setId(jsonObj.getInt(Constants.CATEGORY_ID));
        cat.setName(jsonObj.getString(Constants.CATEGORY_NAME));
        cats.add(cat);
      }
    } catch (JSONException e) {

      throw new PBException(resources.getString(R.string.errorTryingToParseCategories), e);
    }

    PBLogger.d(TAG, "returning cats = " + cats);
    PBLogger.exit(TAG);
    return cats;
  }
コード例 #4
0
  private void showCategories(ArrayList<OpportunityCategory> cats) {
    String TAG = className + ".showCategories";
    PBLogger.entry(TAG);
    setContentView(R.layout.activity_category_list);

    // Grab resources - they will come in handy later.
    if (resources == null) resources = this.getResources();

    // Put all the categories into the list.
    ListView itemlist = (ListView) findViewById(R.id.listCategory);

    // attach list click adapter.
    ArrayAdapter<OpportunityCategory> adapter =
        new ArrayAdapter<OpportunityCategory>(
            CategoryListActivity.this, android.R.layout.simple_list_item_1, cats);

    if (itemlist == null || adapter == null) {
      PBLogger.e(TAG, "null itemlist or adapter...itemlist = " + itemlist + " adapter " + adapter);
    } else {
      itemlist.setAdapter(adapter);
      itemlist.setSelection(0);
      itemlist.setOnItemClickListener((OnItemClickListener) CategoryListActivity.this);
    }

    // Show overlay - first time only
    SharedPreferences prefs =
        PreferenceManager.getDefaultSharedPreferences(CategoryListActivity.this);
    showOverlay = prefs.getBoolean("showOverlay", true);
    PBLogger.i(TAG, "onCreate showOverlay =" + showOverlay);
    if (showOverlay == true) {
      showCategoriesOverlay();
    }

    PBLogger.exit(TAG);
  }
コード例 #5
0
  @Override
  protected void onResume() {
    String TAG = className + ".onResume";
    PBLogger.entry(TAG);
    super.onResume();

    PBLogger.exit(TAG);
  }
コード例 #6
0
  @Override
  public void onCreate(Bundle savedInstanceState) {
    String TAG = className + ".onCreate";
    PBLogger.entry(TAG);
    super.onCreate(savedInstanceState);

    // fetch Categories, call service. It comes back to handler.
    Intent categoryListServiceIntent = new Intent(this, CategoryListService.class);
    // Create a new Messenger for the communication back
    Messenger messenger = new Messenger(categoriesHandler);
    categoryListServiceIntent.putExtra(Constants.MESSENGER, messenger);
    startService(categoryListServiceIntent);

    PBLogger.exit(TAG);
  }