Android Open Source - markj Jw Group






From Project

Back to project page markj.

License

The source code is released under:

GNU Lesser General Public License

If you think the Android project markj 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 com.markjmind.mobile.api.android.ui;
//w ww. jav a 2 s  . co m
import java.util.Stack;

import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnTouchListener;

import com.markjmind.mobile.api.hub.Store;

public class JwGroup {
  public Stack<HistoryInfo> history;
  
  public String currView = null;
//  public Object currParam = null;
  
  protected Store<Store<Object>> group = new Store<Store<Object>>();
  protected int maxBackCount = 10;
  protected JwOnGroupSelect onGroupSelect;
  private boolean isHistory = false; 
  private boolean isReselected = false;
  
  public static enum Motion{
    CLICK,
    TOUCH_DOWN
  }
  
  public JwGroup(){
    currView=null;
    history = new Stack<HistoryInfo>();
  }
  
  public JwGroup(JwOnGroupSelect onGroupSelect){
    currView=null;
    this.onGroupSelect = onGroupSelect;
    history = new Stack<HistoryInfo>();
  }
  
  public void setOnGroupSelect(JwOnGroupSelect onGroupSelect){
    this.onGroupSelect = onGroupSelect;
  }
  
  public void add(String name, View click_view){
    add(name, click_view,null);
  }
  
  public void add(String name, View click_view, Object param){
    Store<Object> temp = new Store<Object>();
    temp.add("name", name);
    temp.add("view", click_view);
    temp.add("param", param);
    group.add(name, temp);
    click_view.setOnClickListener(new GroupOnClickListener(name));
  }
  
  public void clear(){
    group.clear();
    history.clear();
  }
  
  public View getView(String name){
    if(name==null){
      return null;
    }
    Store<Object> temp = getViewStore(name);
    if(temp!=null){
      return (View)temp.get("view");
    }else{
      return null;
    }
  }
  public String getName(int index){
    Store<Object> temp = getViewStore(index);
    if(temp!=null){
      return (String)temp.get("name");
    }else{
      return null;
    }
  }
  
  public View getView(int index){
    Store<Object> temp = getViewStore(index);
    if(temp!=null){
      return (View)temp.get("view");
    }else{
      return null;
    }
  }
  
  public Store<Object> getViewStore(int index){
    Store<Object> temp = group.getValue(index);
    return temp;
  }
  
  public Store<Object> getViewStore(String name){
    Store<Object> temp = (Store<Object>)group.get(name);
    return temp;
  }
  
  public void setParam(int index, Object param){
    Store<Object> temp = getViewStore(index);
    temp.add("param", param);
  }
  
  public void setParam(String name, Object param){
    Store<Object> temp = getViewStore(name);
    temp.add("param", param);
  }
  
  
  public Object getParam(int index){
    Store<Object> temp = getViewStore(index);
    if(temp!=null){
      return temp.get("param");
    }else{
      return null;
    }
  }
  public Object getParam(String name){
    Store<Object> temp = getViewStore(name);
    if(temp!=null){
      return temp.get("param");
    }else{
      return null;
    }
  }
    
  public View getCurrentView(){
    return getView(getCurrentName());
  }
  
  public void setListenerMotion(Motion motion){
    String[] keys = group.getKeys();
    switch (motion) {
    case CLICK:
      for(int i=0;i<keys.length;i++){
        Store<Object> temp = (Store<Object>)group.get(keys[i]);
        View click_view = (View)temp.get("view");
        click_view.setOnClickListener(new GroupOnClickListener(keys[i]));
        click_view.setOnTouchListener(null);
      }
      break;
    case TOUCH_DOWN:
      for(int i=0;i<keys.length;i++){
        Store temp = (Store)group.get(keys[i]);
        View click_view = (View)temp.get("view");
        click_view.setOnClickListener(null);
        click_view.setOnTouchListener(new GroupOnTouchListener(keys[i]));
      }
      break;
    }
  }
  

  public void select(String name, Object param, boolean pushHistory){
    if(name.equals(currView) && !isReselected){
      return;
    }
    if(currView!=null && !name.equals(currView)){
      if(pushHistory){
        if(maxBackCount <= history.size()){
          history.remove(0);
        }
        history.push(new HistoryInfo(currView, param));
      }
    }
    currView = name;
    for(int i=0;i<group.size();i++){
      Store<Object> temp = (Store<Object>)group.getValue(i);
      String tempName =(String)temp.get("name");
      View view =(View)temp.get("view");
      Object vparam = temp.get("param");
      if(onGroupSelect!=null){
        if(name.equals(tempName)){
          if(param==null)
            param = vparam;
          onGroupSelect.selected(view, name, i, param);
        }else{
          onGroupSelect.deselected(view, name, i, param);
        }
      }
    }
  }
  
  public void select(String name, Object param){
    select(name, param, isHistory);
  }
  public void select(String name){
    select(name,null, isHistory);
  }
  
  public void select(int index){
    select(index, null);
  }
  
  public void select(int index, Object param){
    Store<Object> temp = (Store<Object>)group.getValue(index);
    select(temp.getString("name"),param);
  }
  
  public void select(int index, Object param, boolean pushHistory){
    Store<Object> temp = (Store<Object>)group.getValue(index);
    select(temp.getString("name"), param, pushHistory);
  }
  
  public void nextSelect(){
    int index = this.nextIndex();
    select(index);
  }
  
  public void backSelect(){
    int index = this.backIndex();
    select(index);
  }
  
  public void setReselected(boolean isReselected){
    this.isReselected = isReselected;
  }
  
  public int size(){
    return group.size();
  }

  
  public int getCurrentIndex(){
    String[] keys = group.getKeys();
    int index = -1;
    for(int i=0;i<keys.length;i++){
      if(keys[i].equals(currView)){
        index = i;
        break;
      }
    }
    return index;
  }
  
  public int nextIndex(){
    int nextIndex = getCurrentIndex()+1;
    if(nextIndex<size()){
      return nextIndex;
    }else{
      return 0;
    }
  }
  
  public int backIndex(){
    int backIndex = getCurrentIndex()-1;
    if(backIndex>=0){
      return backIndex;
    }else{
      return size()-1;
    }
  }
  
  
    
  public String getCurrentName(){
    return currView;
  }
  
  private class GroupOnClickListener implements OnClickListener{
    String name;
    
    public GroupOnClickListener(String name){
      this.name = name;
    }
    @Override
    public void onClick(View v) {
      select(name);
    }
  }
  private class GroupOnTouchListener implements OnTouchListener{
    String name;
    
    public GroupOnTouchListener(String name){
      this.name = name;
    }
    public void onClick(View v) {
      select(name);
    }
    @Override
    public boolean onTouch(View v, MotionEvent event) {
       switch (event.getAction()){
            case MotionEvent.ACTION_DOWN:
              select(name);
            break;
            }
            return false;

    }
  }
  
  public void setDefalutHistory(boolean isHistory){
    this.isHistory = isHistory;
  }
  
  class HistoryInfo{
    public String viewName;
    public Object param;
    public HistoryInfo(String viewName, Object param){
      this.viewName = viewName;
      this.param = param;
    }
  }
  public void setHistorySize(int size){
    this.maxBackCount=size;
  }
  public boolean back(){
    if(history.size()>0){
      HistoryInfo hInfo =history.pop();
      select(hInfo.viewName,hInfo.param, false);
      return true;
    }
    return false;
  }
  
}




Java Source Code List

com.markjmind.mobile.api.android.controller.JwAsyncTask.java
com.markjmind.mobile.api.android.controller.JwMapperException.java
com.markjmind.mobile.api.android.controller.JwMemberMapper.java
com.markjmind.mobile.api.android.controller.JwStringID.java
com.markjmind.mobile.api.android.controller.JwViewController.java
com.markjmind.mobile.api.android.controller.JwViewerCache.java
com.markjmind.mobile.api.android.controller.JwViewer.java
com.markjmind.mobile.api.android.controller.Jwc.java
com.markjmind.mobile.api.android.controller.OnClickListenerReceiver.java
com.markjmind.mobile.api.android.controller.ViewerXmlMapper.java
com.markjmind.mobile.api.android.exception.JwErrorCode.java
com.markjmind.mobile.api.android.exception.JwException.java
com.markjmind.mobile.api.android.json.JSONMsgString.java
com.markjmind.mobile.api.android.json.JwJOSNTreeArray.java
com.markjmind.mobile.api.android.json.JwJSONReader.java
com.markjmind.mobile.api.android.ui.JwAnimation.java
com.markjmind.mobile.api.android.ui.JwGroup.java
com.markjmind.mobile.api.android.ui.JwMenu.java
com.markjmind.mobile.api.android.ui.JwOnGroupSelect.java
com.markjmind.mobile.api.android.ui.JwTabGroup.java
com.markjmind.mobile.api.android.ui.JwTouchGroupListener.java
com.markjmind.mobile.api.android.ui.JwTouchGroup.java
com.markjmind.mobile.api.android.ui.JwTouchMotionGroupLisener.java
com.markjmind.mobile.api.android.ui.JwTouchMotionGroup.java
com.markjmind.mobile.api.android.ui.drawgraph.GraphBoard.java
com.markjmind.mobile.api.android.ui.drawgraph.GraphSkin.java
com.markjmind.mobile.api.android.ui.drawgraph.HBackLineSkin.java
com.markjmind.mobile.api.android.ui.drawgraph.LineGraphSkin.java
com.markjmind.mobile.api.android.ui.drawgraph.PieGraph.java
com.markjmind.mobile.api.android.ui.drawgraph.RectGraphSkin.java
com.markjmind.mobile.api.android.ui.drawgraph.SimpleStyle.java
com.markjmind.mobile.api.android.ui.drawgraph.TextArraySkin.java
com.markjmind.mobile.api.android.ui.drawgraph.VBackLineSkin.java
com.markjmind.mobile.api.android.ui.graph.Arc.java
com.markjmind.mobile.api.android.ui.graph.BarElement.java
com.markjmind.mobile.api.android.ui.graph.BarLayout.java
com.markjmind.mobile.api.android.ui.graph.Bar.java
com.markjmind.mobile.api.android.ui.graph.IPieSkin.java
com.markjmind.mobile.api.android.ui.graph.LineLayout.java
com.markjmind.mobile.api.android.ui.graph.MeasureLayout.java
com.markjmind.mobile.api.android.ui.graph.PieArcRoundSkin.java
com.markjmind.mobile.api.android.ui.graph.PieLayout.java
com.markjmind.mobile.api.android.ui.graph.PiePercentSkin.java
com.markjmind.mobile.api.android.ui.view.JwBaseDropDown.java
com.markjmind.mobile.api.android.ui.view.JwDropDown.java
com.markjmind.mobile.api.android.ui.view.JwSlidingLayout.java
com.markjmind.mobile.api.android.ui.view.JwWheelView.java
com.markjmind.mobile.api.android.ui.view.StickerListener.java
com.markjmind.mobile.api.android.ui.view.StickerView.java
com.markjmind.mobile.api.android.ui.view.textview.JwTextViewAutoScale.java
com.markjmind.mobile.api.android.ui.view.textview.JwTextViewFonts.java
com.markjmind.mobile.api.android.ui.view.textview.JwTextViewWrapScale.java
com.markjmind.mobile.api.android.ui.wrapper.JwAlertDialog.java
com.markjmind.mobile.api.android.ui.wrapper.JwToast.java
com.markjmind.mobile.api.android.util.JwFile.java
com.markjmind.mobile.api.android.util.JwPreferenceList.java
com.markjmind.mobile.api.android.util.JwPreference.java
com.markjmind.mobile.api.android.util.JwSound.java
com.markjmind.mobile.api.android.util.JwTextUtils.java
com.markjmind.mobile.api.android.util.PhoneInfo.java
com.markjmind.mobile.api.android.util.WebConnection.java
com.markjmind.mobile.api.android.xml.JwDomHandler.java
com.markjmind.mobile.api.android.xml.JwDomLoader.java
com.markjmind.mobile.api.android.xml.JwEditElementHandler.java
com.markjmind.mobile.api.android.xml.JwXmlLoader.java
com.markjmind.mobile.api.android.xml.JwXmlResoure.java
com.markjmind.mobile.api.hub.ArrayJDhub.java
com.markjmind.mobile.api.hub.DBhub.java
com.markjmind.mobile.api.hub.JDhub.java
com.markjmind.mobile.api.hub.Loader.java
com.markjmind.mobile.api.hub.StoreList.java
com.markjmind.mobile.api.hub.Store.java