Android Open Source - saostar Tabs






From Project

Back to project page saostar.

License

The source code is released under:

Apache License

If you think the Android project saostar listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package net.azyobuzi.azyotter.saostar.configuration;
/* w ww .  j ava2  s  .  c o  m*/
import java.util.ArrayList;

import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;

import net.azyobuzi.azyotter.saostar.ContextAccess;
import net.azyobuzi.azyotter.saostar.linq.Enumerable;
import net.azyobuzi.azyotter.saostar.system.Action1;
import net.azyobuzi.azyotter.saostar.system.Action2;
import net.azyobuzi.azyotter.saostar.system.Action3;

import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;

import android.content.Context;

public class Tabs {
  private static final String fileName = "tabs.xml";

  private static ArrayList<Tab> list = null;

  private static void loadTabs() {
    list = new ArrayList<Tab>();

    try {
      Element root = DocumentBuilderFactory.newInstance()
        .newDocumentBuilder()
        .parse(ContextAccess.openFileInput(fileName))
        .getDocumentElement();

      NodeList tabs = root.getElementsByTagName("tab");
      for (int i = 0; i < tabs.getLength(); i++) {
        Element elm = (Element)tabs.item(i);
        Tab re = new Tab(
          elm.getElementsByTagName("name").item(0).getTextContent(),
          elm.getElementsByTagName("filter").item(0).getTextContent()
        );
        list.add(re);
      }
    } catch (Exception ex) {
      ex.printStackTrace();

      //????
      Tab homeTab = new Tab();
      homeTab.setName("Home");
      try {
        homeTab.setFilter("prop:isHomeTweet");
      } catch (Exception e) {
        e.printStackTrace();
      }
      add(homeTab);
    }
  }

  public static Enumerable<Tab> getAllTabs() {
    if (list == null) loadTabs();
    return Enumerable.from(list.toArray()).cast();
  }

  public static int getTabsCount() {
    if (list == null) loadTabs();
    return list.size();
  }

  public static Tab get(int index) {
    if (list == null) loadTabs();
    return list.get(index);
  }

  public static int indexOf(Tab tab) {
    if (list == null) loadTabs();
    return list.indexOf(tab);
  }

  public static void add(Tab tab) {
    if (list == null) loadTabs();
    list.add(tab);

    for (Action1<Tab> handler : addedHandler) {
      handler.invoke(tab);
    }

    save();
  }

  public static final ArrayList<Action1<Tab>> addedHandler = new ArrayList<Action1<Tab>>();

  public static void remove(Tab tab) {
    if (list == null) loadTabs();
    list.remove(tab);

    for (Action1<Tab> handler : removedHandler) {
      handler.invoke(tab);
    }

    save();
  }

  public static final ArrayList<Action1<Tab>> removedHandler = new ArrayList<Action1<Tab>>();

  public static void move(int from, int to) {
    if (list == null) loadTabs();
    Tab tab = list.remove(from);
    list.add(to, tab);

    for (Action3<Tab, Integer, Integer> handler : movedHandler) {
      handler.invoke(tab, from, to);
    }

    save();
  }

  public static final ArrayList<Action3<Tab, Integer, Integer>> movedHandler = new ArrayList<Action3<Tab, Integer, Integer>>();

  public static void save() {
    if (list == null) return;
    
    try {
      final Document doc = DocumentBuilderFactory.newInstance()
          .newDocumentBuilder()
          .newDocument();

      final Element root = doc.createElement("tabs");

      getAllTabs().forEach(new Action2<Tab, Integer>() {
        @Override
        public void invoke(Tab arg0, Integer arg1) {
          Element elm = doc.createElement("tab");

          Element child = doc.createElement("name");
          child.appendChild(doc.createTextNode(arg0.getName()));
          elm.appendChild(child);

          child = doc.createElement("filter");
          child.appendChild(doc.createTextNode(arg0.getFilter()));
          elm.appendChild(child);

          root.appendChild(elm);
        }
      });

      doc.appendChild(root);

      TransformerFactory.newInstance()
        .newTransformer()
        .transform(new DOMSource(doc), new StreamResult(ContextAccess.openFileOutput(fileName, Context.MODE_PRIVATE)));
    } catch (Exception ex) {
      ex.printStackTrace(); //??????????????????????
    }
  }
}




Java Source Code List

jp.ne.hatena.d.shogo0809.widget.SortableListView.java
net.azyobuzi.azyotter.saostar.ActivityUtil.java
net.azyobuzi.azyotter.saostar.ContextAccess.java
net.azyobuzi.azyotter.saostar.NotificationCenter.java
net.azyobuzi.azyotter.saostar.SaostarApplication.java
net.azyobuzi.azyotter.saostar.StringUtil.java
net.azyobuzi.azyotter.saostar.Twitter4JFactories.java
net.azyobuzi.azyotter.saostar.TwitterUriGenerator.java
net.azyobuzi.azyotter.saostar.activities.AccountPreferenceActivity.java
net.azyobuzi.azyotter.saostar.activities.AccountPreferenceFragment.java
net.azyobuzi.azyotter.saostar.activities.AccountsActivity.java
net.azyobuzi.azyotter.saostar.activities.AccountsFragment.java
net.azyobuzi.azyotter.saostar.activities.ExpandLinkActivity.java
net.azyobuzi.azyotter.saostar.activities.LoginActivity.java
net.azyobuzi.azyotter.saostar.activities.MainActivity.java
net.azyobuzi.azyotter.saostar.activities.RetryActivity.java
net.azyobuzi.azyotter.saostar.activities.SettingActivity.java
net.azyobuzi.azyotter.saostar.activities.SettingFragment.java
net.azyobuzi.azyotter.saostar.activities.TabFilterSettingFragment.java
net.azyobuzi.azyotter.saostar.activities.TabGeneralSettingFragment.java
net.azyobuzi.azyotter.saostar.activities.TabPreferenceActivity.java
net.azyobuzi.azyotter.saostar.activities.TabsActivity.java
net.azyobuzi.azyotter.saostar.activities.TabsFragment.java
net.azyobuzi.azyotter.saostar.activities.TimelineTabFragment.java
net.azyobuzi.azyotter.saostar.activities.TweetDetailActivity.java
net.azyobuzi.azyotter.saostar.activities.TwitterUriHookActivity.java
net.azyobuzi.azyotter.saostar.activities.UpdateStatusActivity.java
net.azyobuzi.azyotter.saostar.configuration.Account.java
net.azyobuzi.azyotter.saostar.configuration.Accounts.java
net.azyobuzi.azyotter.saostar.configuration.Command.java
net.azyobuzi.azyotter.saostar.configuration.Setting.java
net.azyobuzi.azyotter.saostar.configuration.Tab.java
net.azyobuzi.azyotter.saostar.configuration.Tabs.java
net.azyobuzi.azyotter.saostar.d_aqa.Constant.java
net.azyobuzi.azyotter.saostar.d_aqa.FunctionFactory.java
net.azyobuzi.azyotter.saostar.d_aqa.Function.java
net.azyobuzi.azyotter.saostar.d_aqa.Invokable.java
net.azyobuzi.azyotter.saostar.d_aqa.OperatorFactory.java
net.azyobuzi.azyotter.saostar.d_aqa.Operator.java
net.azyobuzi.azyotter.saostar.d_aqa.PropertyFactory.java
net.azyobuzi.azyotter.saostar.d_aqa.Property.java
net.azyobuzi.azyotter.saostar.d_aqa.Reader.java
net.azyobuzi.azyotter.saostar.d_aqa.operators.EqualityOperator.java
net.azyobuzi.azyotter.saostar.d_aqa.operators.GreaterThanOperator.java
net.azyobuzi.azyotter.saostar.d_aqa.operators.GreaterThanOrEqualOperator.java
net.azyobuzi.azyotter.saostar.d_aqa.operators.InequalityOperator.java
net.azyobuzi.azyotter.saostar.d_aqa.operators.LessThanOperator.java
net.azyobuzi.azyotter.saostar.d_aqa.operators.LessThanOrEqualOperator.java
net.azyobuzi.azyotter.saostar.d_aqa.properties.CreatedAtProperty.java
net.azyobuzi.azyotter.saostar.d_aqa.properties.FromCreatedAtProperty.java
net.azyobuzi.azyotter.saostar.d_aqa.properties.FromIdProperty.java
net.azyobuzi.azyotter.saostar.d_aqa.properties.FromNameProperty.java
net.azyobuzi.azyotter.saostar.d_aqa.properties.FromProtectedProperty.java
net.azyobuzi.azyotter.saostar.d_aqa.properties.FromScreenNameProperty.java
net.azyobuzi.azyotter.saostar.d_aqa.properties.FromVerifiedProperty.java
net.azyobuzi.azyotter.saostar.d_aqa.properties.IdProperty.java
net.azyobuzi.azyotter.saostar.d_aqa.properties.InReplyToProperty.java
net.azyobuzi.azyotter.saostar.d_aqa.properties.IsHomeTweetProperty.java
net.azyobuzi.azyotter.saostar.d_aqa.properties.OriginalTextProperty.java
net.azyobuzi.azyotter.saostar.d_aqa.properties.RetweetedCreatedAtProperty.java
net.azyobuzi.azyotter.saostar.d_aqa.properties.RetweetedIdProperty.java
net.azyobuzi.azyotter.saostar.d_aqa.properties.RetweetedProperty.java
net.azyobuzi.azyotter.saostar.d_aqa.properties.RetweetedSourceProperty.java
net.azyobuzi.azyotter.saostar.d_aqa.properties.RetweetedUserCreatedAtProperty.java
net.azyobuzi.azyotter.saostar.d_aqa.properties.RetweetedUserIdProperty.java
net.azyobuzi.azyotter.saostar.d_aqa.properties.RetweetedUserNameProperty.java
net.azyobuzi.azyotter.saostar.d_aqa.properties.RetweetedUserScreenNameProperty.java
net.azyobuzi.azyotter.saostar.d_aqa.properties.RetweetedUserVerifiedProperty.java
net.azyobuzi.azyotter.saostar.d_aqa.properties.SourceProperty.java
net.azyobuzi.azyotter.saostar.d_aqa.properties.TextProperty.java
net.azyobuzi.azyotter.saostar.linq.Enumerable.java
net.azyobuzi.azyotter.saostar.linq.Enumerator.java
net.azyobuzi.azyotter.saostar.services.FavoriteService.java
net.azyobuzi.azyotter.saostar.services.RetweetService.java
net.azyobuzi.azyotter.saostar.services.TimelineReceiveService.java
net.azyobuzi.azyotter.saostar.services.UpdateStatusService.java
net.azyobuzi.azyotter.saostar.system.Action1.java
net.azyobuzi.azyotter.saostar.system.Action2.java
net.azyobuzi.azyotter.saostar.system.Action3.java
net.azyobuzi.azyotter.saostar.system.Action.java
net.azyobuzi.azyotter.saostar.system.Func1.java
net.azyobuzi.azyotter.saostar.system.Func2.java
net.azyobuzi.azyotter.saostar.system.Func.java
net.azyobuzi.azyotter.saostar.timeline_data.TimelineItemCollection.java
net.azyobuzi.azyotter.saostar.timeline_data.TimelineItemId.java
net.azyobuzi.azyotter.saostar.timeline_data.TimelineItem.java
net.azyobuzi.azyotter.saostar.timeline_data.TweetEntities.java
net.azyobuzi.azyotter.saostar.timeline_data.UserCollection.java
net.azyobuzi.azyotter.saostar.timeline_data.UserInfo.java
net.azyobuzi.azyotter.saostar.widget.AccountSelector.java
net.azyobuzi.azyotter.saostar.widget.CustomizedUrlImageView.java