⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 options.java

📁 goText is a program for mobile phones that allows you to send text messages over GPRS/EDGE/UMTS. It
💻 JAVA
字号:
/**
 * Class : short description
 * @author Michele 'Miccar' Cardinale miccar@gmail.com
 * @author Natale Vinto ebballon@interfree.it
 * @version 1.0
 */

 /*
  *  goText : text messaging over GPRS
  *  Copyright (C) 2006  Natale Vinto <ebballon@interfree.it>
  *  OpenJLab Group www.openjlab.org
  *  Copyright (C) 2006  Michele Cardinale 'Miccar' <miccar@gmail.com>
  *  www.miccar.org
  *
  *  This program is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
  *  the Free Software Foundation; either version 2 of the License, or
  *  (at your option) any later version.
  *
  *  This program is distributed in the hope that it will be useful,
  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  *      GNU General Public License for more details.
  *
  *  You should have received a copy of the GNU General Public License
  *  along with this program; if not, write to the Free Software
  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  */

import javax.microedition.rms.*;
import java.util.*;

public class Options {
    private int lang;
    private long timestamp;
    private int counter;
    private int charscounter;
    private int connectionmethod;
    private static final int ID_TIMESTAMP=1;
    private static final int ID_LANG=2;
    private static final int ID_COUNTER=3;
    private static final int ID_CHARSCOUNTER=4;
    private static final int ID_CONNECTIONMETHOD=5;
    private static final String RN="_options";
    
    public Options() {
        read(RN);
    }
    
    public int getLang(){
        return this.lang;
    }
    
    public long getTimestamp(){
        return this.timestamp;
    }
    
    public int getCounter(){
        return this.counter;
    }
    
    public int getCharsCounter(){
        return this.charscounter;
    }
    
    public int getConnectionMethod(){
        return this.connectionmethod;
    }
    
    /**
     *
     * @param lang
     * @return
     */
    public int setLang(int lang){
        RecordStore rs=null;
        int old_lang=this.lang;
        byte[] data=(lang+"").getBytes();
        try{
            rs = RecordStore.openRecordStore(RN, false );
        }catch (Exception e){}
        try{
            rs.setRecord(ID_LANG, data, 0, data.length);
            this.lang=lang;
        }catch (Exception e){
            this.lang=old_lang;
            return -1;
        }
        return 1;
    }
    
    public int setTimestamp(long timestamp){
        RecordStore rs=null;
        long old_timestamp=this.timestamp;
        byte[] data=(timestamp+"").getBytes();
        try{
            rs = RecordStore.openRecordStore(RN, false );
        }catch (Exception e){}
        try{
            rs.setRecord(ID_TIMESTAMP, data, 0, data.length);
            this.timestamp=timestamp;
        }catch (Exception e){
            this.timestamp=old_timestamp;
            return -1;
        }
        return 1;
    }
    
    private int setCounter(int counter){
        RecordStore rs=null;
        int old_counter=this.counter;
        byte[] data=(counter+"").getBytes();
        try{
            rs = RecordStore.openRecordStore(RN, false );
        }catch (Exception e){}
        try{
            rs.setRecord(ID_COUNTER, data, 0, data.length);
            this.counter=counter;
        }catch (Exception e){
            this.counter=old_counter;
            return -1;
        }
        return 1;
    }
    
    public int setCharsCounter(int charscounter){
        RecordStore rs=null;
        int old_charscounter=this.charscounter;
        byte[] data=(charscounter+"").getBytes();
        try{
            rs = RecordStore.openRecordStore(RN, false );
        }catch (Exception e){}
        try{
            rs.setRecord(ID_CHARSCOUNTER, data, 0, data.length);
            this.charscounter=charscounter;
        }catch (Exception e){
            this.charscounter=old_charscounter;
            return -1;
        }
        return 1;
    }
    
    public int setConnectionMethod(int connectionmethod){
        RecordStore rs=null;
        int old_connectionmethod=this.connectionmethod;
        byte[] data=(connectionmethod+"").getBytes();
        try{
            rs = RecordStore.openRecordStore(RN, false );
        }catch (Exception e){}
        try{
            rs.setRecord(ID_CONNECTIONMETHOD, data, 0, data.length);
            this.connectionmethod=connectionmethod;
        }catch (Exception e){
            this.connectionmethod=old_connectionmethod;
            return -1;
        }
        return 1;
    }
    
    public int increaseCounter(int incr){
        return setCounter(getCounter()+incr);
    }
    
    public int resetCounter(){
        return setCounter(0);
    }
    
    private void read(String RN){
        RecordStore rs=null;
        try{
            rs = RecordStore.openRecordStore(RN, true );
            String data=null;
            try{
                data=new String(rs.getRecord(ID_TIMESTAMP));
            }catch(Exception e){
                data=(new Date().getTime())+"";
                try{
                    rs.addRecord(data.getBytes(), 0, data.getBytes().length); //timestamp
                }catch (Exception ee){}
            }finally{
                this.timestamp=Long.parseLong(data);
            }
            try{
                data=new String(rs.getRecord(ID_LANG));
            }catch(Exception e){
                data="0";
                try{
                    rs.addRecord(data.getBytes(), 0, data.getBytes().length); //lang
                }catch (Exception ee){}
            }finally{
                this.lang=Integer.parseInt(data);
            }
            try{
                data=new String(rs.getRecord(ID_COUNTER));
            }catch(Exception e){
                data="0";
                try{
                    rs.addRecord(data.getBytes(), 0, data.getBytes().length); //counter
                }catch (Exception ee){}
            }finally{
                this.counter=Integer.parseInt(data);
            }
            try{
                data=new String(rs.getRecord(ID_CHARSCOUNTER));
            }catch(Exception e){
                data="0";
                try{
                    rs.addRecord(data.getBytes(), 0, data.getBytes().length); //charscounter
                }catch (Exception ee){}
            }finally{
                this.charscounter=Integer.parseInt(data);
            }
            try{
                data=new String(rs.getRecord(ID_CONNECTIONMETHOD));
            }catch(Exception e){
                data="0";
                try{
                    rs.addRecord(data.getBytes(), 0, data.getBytes().length); //charscounter
                }catch (Exception ee){}
            }finally{
                this.connectionmethod=Integer.parseInt(data);
            }
            rs.closeRecordStore();
        }catch (Exception e){}
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -