Ejemplo n.º 1
0
 @Override
 public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedState) {
   HorizontalPager pager = new HorizontalPager(getActivity());
   pager.setRotation(180);
   initializePager(pager);
   return pager;
 }
        @Override
        public void onCheckedChanged(final RadioGroup group, final int checkedId) {
          // Reset the animations if screen changed
          int previousScreen = mPager.getCurrentScreen();

          // Slide to the appropriate screen when the user checks a button.
          switch (checkedId) {
            case R.id.radio_btn_0:
              if (previousScreen != 0) stopAnimation();
              mPager.setCurrentScreen(0, true);
              rb0.setText(Html.fromHtml("<b><u><font color='#00FF00'> Favorites </font></u><b>"));
              rb1.setText(Html.fromHtml("<b><u><font color='#FFFFFF'> Holidays </font></u><b>"));
              break;
            case R.id.radio_btn_1:
              if (previousScreen != 1) stopAnimation();
              mPager.setCurrentScreen(1, true);
              rb0.setText(Html.fromHtml("<b><u><font color='#FFFFFF'> Favorites </font></u><b>"));
              rb1.setText(Html.fromHtml("<b><u><font color='#00FF00'> Holidays </font></u><b>"));
              break;
            default:
              break;
          }
        }
        @Override
        public void onScreenSwitched(final int screen) {
          // Reset the animations if screen changed
          int previousScreen = mPager.getCurrentScreen();

          // Check the appropriate button when the user swipes screens.
          switch (screen) {
            case 0:
              mRadioGroup.check(R.id.radio_btn_0);
              break;
            case 1:
              mRadioGroup.check(R.id.radio_btn_1);
              break;
            default:
              break;
          }
        }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.favorite);

    mPager = (HorizontalPager) findViewById(R.id.horizontal_pager);
    mRadioGroup = (RadioGroup) findViewById(R.id.tabs);
    mPager.setOnScreenSwitchListener(onScreenSwitchListener);
    mRadioGroup.setOnCheckedChangeListener(onCheckedChangedListener);
    rb0 = (RadioButton) findViewById(R.id.radio_btn_0);
    rb1 = (RadioButton) findViewById(R.id.radio_btn_1);
    rb0.setText(Html.fromHtml("<b><u><font color='#00FF00'> Favorites </font></u><b>"));
    rb1.setText(Html.fromHtml("<b><u><font color='#FFFFFF'> Holidays </font></u><b>"));

    TableLayout tv = (TableLayout) findViewById(R.id.fav_content);
    Bundle b = getIntent().getExtras();

    String value = b.getString("key");
    String[] entries = value.split("###");
    String mText = "";

    SimpleDateFormat formatter = new SimpleDateFormat("dd-MM-yyyy");
    Map<Date, String> map = new TreeMap<Date, String>();
    for (String entry : entries) {
      String[] s1 = entry.split(":::");
      if (s1.length == 2) {
        try {
          Date x = formatter.parse(s1[0]);
          map.put(x, s1[1]);
        } catch (ParseException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
        }
        // mText = mText + "<b><font color='white'>" + (s1[0])
        // + ": </font></b> &nbsp;" + s1[1].replace("^!", "")+"<br />";
      }
    }
    int xx = 0;
    for (Entry<Date, String> e : map.entrySet()) {
      TableRow row1 = new TableRow(this);
      TableRow row2 = new TableRow(this);

      TextView t1 = new TextView(this);
      TextView t2 = new TextView(this);

      String val = e.getValue();
      Calendar cal = Calendar.getInstance();
      cal.setTime(e.getKey());
      int year = cal.get(Calendar.YEAR);
      String month = Constants.getMonthName(cal.get(Calendar.MONTH) + 1);
      int day = cal.get(Calendar.DAY_OF_MONTH);
      t1.setText(
          Html.fromHtml("<font color='#00FF00'>" + day + " " + month + " " + year + "</font>"));
      t2.setText(
          Html.fromHtml(
              "<font color='#FFFFFF'>" + val.replace("^!", "").replace("#", "<br />") + "</font>"));
      t2.setPadding(10, 0, 0, 0);
      row1.addView(t1);
      row2.addView(t2);
      tv.addView(
          row1, new TableLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.FILL_PARENT));
      tv.addView(
          row2, new TableLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.FILL_PARENT));
      xx++;
    }

    /** List of holidays */
    StringBuilder allHolidays = new StringBuilder();
    for (Entry<String, String> entry : CalendarView.activity.holidayMap2015.entrySet()) {
      String[] s = entry.getKey().split(" ");
      allHolidays =
          allHolidays
              .append(s[1])
              .append("-")
              .append(Constants.getMonthInt(s[0]))
              .append("-2015:::")
              .append(entry.getValue())
              .append("###");
    }
    for (Entry<String, String> entry : CalendarView.activity.holidayMap.entrySet()) {
      String[] s = entry.getKey().split(" ");
      allHolidays =
          allHolidays
              .append(s[1])
              .append("-")
              .append(Constants.getMonthInt(s[0]))
              .append("-2016:::")
              .append(entry.getValue())
              .append("###");
    }

    String[] listOfHolidays = allHolidays.toString().split("###");
    ListView holidayContent = (ListView) findViewById(R.id.holiday_content);
    List<String> planetList = new ArrayList<String>();
    final SwipeViewDetector swipeDetector = new SwipeViewDetector();
    holidayContent.setOnTouchListener(swipeDetector);
    final ArrayAdapter<String> listAdapter =
        new ArrayAdapter<String>(this, R.layout.simplerow, planetList) {
          @Override
          public View getView(int position, View convertView, ViewGroup parent) {
            View view = super.getView(position, convertView, parent);
            TextView subTitleView = (TextView) view.findViewById(R.id.rowTextView);
            String txt = subTitleView.getText().toString();
            String day = txt.split("<:>")[0];
            String val = txt.split("<:>")[1];
            String str =
                "<font color='#00FF00'>"
                    + day
                    + "<br/></font><font color='#FFFFFF'>"
                    + val
                    + "</font>";
            subTitleView.setText(Html.fromHtml(str));

            return view;
          }
        };
    holidayContent.setOnItemClickListener(
        new OnItemClickListener() {

          @Override
          public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            if (swipeDetector.swipeDetected()) {
              String holi = ((TextView) view).getText().toString();
              deleteHolidayFromList(listAdapter, position, holi);
            }
          }
        });

    holidayContent.setOnItemLongClickListener(
        new OnItemLongClickListener() {

          @Override
          public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
            // final Context inst = CalendarView.activity;

            if (swipeDetector.swipeDetected()) {
              String holi = ((TextView) view).getText().toString();
              deleteHolidayFromList(listAdapter, position, holi);
            }
            return true;
          }
        });

    Map<Date, String> holiday_map = new TreeMap<Date, String>();
    for (String entry : listOfHolidays) {
      String[] s1 = entry.split(":::");
      if (s1.length == 2) {
        try {
          Date x = formatter.parse(s1[0]);
          map.put(x, s1[1]);
        } catch (ParseException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
        }
      }
    }

    for (Entry<Date, String> e : map.entrySet()) {
      try {
        String val = e.getValue().replace("^!", "");
        Calendar cal = Calendar.getInstance();
        cal.setTime(e.getKey());
        int year = cal.get(Calendar.YEAR);
        String month = Constants.getMonthName(cal.get(Calendar.MONTH) + 1);
        int day = cal.get(Calendar.DAY_OF_MONTH);
        for (String newVal : val.split("#")) {
          if (newVal.length() > 0) listAdapter.add(day + " " + month + " " + year + "<:>" + newVal);
        }
      } catch (Exception e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
      }
    }
    holidayContent.setAdapter(listAdapter);
  }