@Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    addPreferencesFromResource(R.xml.settings_special_list);
    Bundle b = getArguments();
    if (b != null) {
      Log.d(TAG, "id= " + getArguments().getInt("id"));
      final SpecialList specialList = SpecialList.getSpecialList(getArguments().getInt("id") * -1);
      ((SpecialListsSettingsActivity) getActivity()).setSpecialList(specialList);

      ActionBar actionbar = getActivity().getActionBar();
      if (specialList == null) actionbar.setTitle("No list");
      else actionbar.setTitle(specialList.getName());
      if (!MirakelCommonPreferences.isTablet()) {
        ImageButton delList = new ImageButton(getActivity());
        delList.setBackgroundResource(android.R.drawable.ic_menu_delete);
        actionbar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM, ActionBar.DISPLAY_SHOW_CUSTOM);
        actionbar.setCustomView(
            delList,
            new ActionBar.LayoutParams(
                LayoutParams.WRAP_CONTENT,
                LayoutParams.WRAP_CONTENT,
                Gravity.CENTER_VERTICAL | DefinitionsHelper.GRAVITY_RIGHT));
        delList.setOnClickListener(((ListSettings) getActivity()).getDelOnClickListener());
      }
      try {
        new SpecialListSettings(this, specialList).setup();
      } catch (NoSuchListException e) {
        getActivity().finish();
      }
    } else {
      Log.d(TAG, "bundle null");
    }
  }
 @Override
 protected List<Pair<Integer, String>> getItems() {
   List<SpecialList> specialLists = SpecialList.allSpecial(true);
   List<Pair<Integer, String>> items = new ArrayList<Pair<Integer, String>>();
   for (SpecialList list : specialLists) {
     items.add(new Pair<Integer, String>(list.getId(), list.getName()));
   }
   return items;
 }
 @Override
 protected void setupSettings() {
   this.specialList =
       SpecialList.getSpecialList(
           getIntent().getIntExtra("id", SpecialList.firstSpecial().getId()) * -1);
   try {
     new SpecialListSettings(this, this.specialList).setup();
   } catch (NoSuchListException e) {
     finish();
   }
 }
示例#4
0
 public static SpecialList firstSpecialSafe(final Context ctx) {
   SpecialList s = SpecialList.firstSpecial();
   if (s == null) {
     s =
         SpecialList.newSpecialList(
             ctx.getString(R.string.list_all),
             new HashMap<String, SpecialListsBaseProperty>(),
             true,
             ctx);
     if (ListMirakel.count() == 0) {
       ListMirakel.safeFirst(ctx);
     }
     s.save(false);
   }
   return s;
 }
 private SpecialList newSpecialList() {
   return SpecialList.newSpecialList(
       getString(R.string.special_lists_new),
       new HashMap<String, SpecialListsBaseProperty>(),
       true,
       this);
 }
 @Override
 public boolean onOptionsItemSelected(MenuItem item) {
   switch (item.getItemId()) {
     case android.R.id.home:
       finish();
       return true;
     default:
       if (item.getTitle().equals(getString(R.string.delete))) {
         if (this.specialList != null) {
           this.specialList.destroy();
         }
         finish();
         return true;
       } else if (item.getTitle().equals(getString(R.string.add))) {
         SpecialList s = newSpecialList();
         Intent intent = new Intent(this, SpecialListsSettingsActivity.class);
         intent.putExtra("id", s.getId());
         startActivity(intent);
         return true;
       }
       break;
   }
   return super.onOptionsItemSelected(item);
 }
  public static ListMirakel getList(Context context, int widgetId) {

    int listId = getSettings(context).getInt(getKey(widgetId, "list_id"), 0);
    ListMirakel list = ListMirakel.getList(listId);
    if (list == null) {
      list = SpecialList.firstSpecial();
      if (list == null) {
        list = ListMirakel.first();
        if (list == null) {
          Toast.makeText(context, "You have no Lists!", Toast.LENGTH_SHORT).show();
          return null;
        }
      }
    }
    return list;
  }
 private SpecialList newSpecialList() {
   return SpecialList.newSpecialList(getString(R.string.special_lists_new), "", true, this);
 }