金融信息化及交易管理系统(股票交易系统APP)

目 录
1 绪 论 1
1.1 选题背景及意义 1
1.2 研究现状 1
1.3 研究主要内容 4
2 需求分析与实施方案 5
2.1 虚拟金融信息化交易系统的功能 5
2.2 可行性分析 5
2.3 系统开发技术 5
2.4 系统开发工具及环境 6
2.5 系统开发方式 7
3 需求分析 8
3.1 系统结构 8
3.2 系统描述 9
3.2.1 总述 9
3.2.2 分述 9
3.3 总体功能模块 10
3.3.1 总体功能模块 11
3.3.2 用户登录流程 11
3.4 系统用例模型 11
3.4.1 活动者识别 11
3.4.2 用例识别 12
3.4.3 用例图 12
4 系统设计 13
4.1 功能模块细化 13
4.1.1 我的首页(系统首页)模块 13
4.1.2 金融信息化交易模块 13
4.1.3 个人信息修改模块 13
4.2 数据库设计 13
4.2.1 E-R图的设计 13
4.2.2 数据表 14
4.3 系统类设计 16
4.3.1 Util工具类的设计 16
4.3.2 业务逻辑层的类设计 19
4.3.3 视图层的设计 20
5 系统实现 21
5.1代码实现 21
5.1.1开发环境 21
5.1.2 数据表设计与实现 21
5.1.3 数据库连接字符串 23
5.2 功能实现 23
5.2.1 首页模块 23
5.2.2 交易模块 26
5.2.3 个人信息模块 28
6 系统测试 31
6.1 概述 31
6.2 系统测试用例 31
6.2.1 系统首页测试 33
6.2.2 交易测试 34
6.2.3 个人信息测试 35
6.3 测试总结 39
7 结 论 40
7.1 设计评价 40
7.2 改进要求及目标 40
参考文献 41
致 谢 42
3.2 系统分析
系统分析初步界定了系统的范围和功能。为了有一个更加清晰的开发思路,现用自然语言对整个虚拟金融信息化交易系统进行详细地描述。
1.总述
该虚拟金融信息化交易系统主要有我的首页、我的持仓、交易明细、账户信息、用户注册、用户登录、安全退出和金融搜索八大功能模块。用户在注册该系统之后,只需输入自己的用户名和密码,即可登录到该系统进行金融信息查询、金融买入、金融卖出、交易明细查询、个人信息修改等操作。除此之外,该系统还提供了丰富翔实的金融、财经链接,以方便用户(游客也可以)进行浏览和学习。
2.分述
接下来,本人将对上述功能模块进行详细的描述。
1、我的首页:亦即系统首页,任何游客或者是已经进行注册了的用户都可以浏览。在我的首页中囊括了丰富翔实、精彩纷呈的网页内容。其中有颇具人性化的网站欢迎标语,随着时间和用户的不同会发生细微的变化;优美精致的网站Logo,简洁大方的搜索栏,贴心实用的天气预报,当然肯定少不了丰富多彩的网站链接,包括站内的图文资讯和热门TAG,还有站外的新浪财经、金融之家和金融入门等等。
2、用户注册:浏览了如此精彩的首页,如果你想驻足,享受更多、更精彩的体验的话,你可以马上点击“用户注册”链接,进入用户注册页面进行注册。当然你必须遵循一定的规则才能顺利完成注册,比如为了确保账户安全、有效,页面上的六个输入框用户名、密码、重复密码、邮箱、手机号码和联系地址都必须正确地填写,否则你有可能无法完成注册。
3、用户登录:如果你已经顺利完成了注册,那么系统将会自动跳转到“用户登录”页面,你可以马上尝试登录。这里只需要正确地输入你的用户名和密码,就可以成功地查看到你的金融持仓、金融信息化交易明细和个人信息,这个时候,你将有权对这些模块进行相关操作。
4、我的持仓:用户在成功登录到该系统后,将可以对此模块进行操作。在此模块中,用户可以查看到自己金融持有信息、价格信息,还可以进行相应的金融信息化交易。
5、交易明细:用户在成功登录到该系统后,可以到交易明细模块查看自己的金融信息化交易即金融代码、金融名称、金融价格、金融数量、交易类型和交易时间的具体情况。
6、账户信息:用户在成功登录到该系统后,同样也可以进入账户信息模块,查看和修改自己的个人信息,其中包括用户姓名、登录密码、邮箱、手机号码、联系地址和注册日期,但注册日期是不允许修改的。用户修改后,点击表单下面的“确定”按钮,即可完成个人信息的修改,然后页面会跳转到登录页面,要求用户重新进行登录。
7、金融搜索:为了增加用户的体验,方便用户查询自己感兴趣的金融信息,在系统的每一个页面都设置了同样的搜索栏。无论用户正在浏览哪个页面,只要在搜索栏中输入你想要查询的金融代码,就可以轻松快捷地搜索到所需要的金融信息和相关的持仓信息。而且这项功能同样也对非用户的游客进行开放,但游客并不能得到相关的金融持仓信息。
8、安全退出:如果用户完成相关体验后,想要退出该系统,可以点击“安全退出”按钮,页面会自动跳转到登录界面。本文转载自http://www.biyezuopin.vip/onews.asp?id=14023在不重新登录的情况下,用户跟普通游客一样,不能浏览我的持仓、交易明细等页面。
3.3 总体功能模块
该虚拟金融信息化交易系统,主要是为了满足用户对金融信息化交易的体验,要求操作简单快捷、界面整洁大方,因此必须要设计一个好的程序架构和运作流程。从上述系统描述中可以大致了解到整个虚拟金融信息化交易系统的总体功能模块划分及流程图概况。如图3-2、3-3所示。
3.3.1 总体功能图
金融信息化及交易管理系统(股票交易系统APP)_第1张图片

图3-2 总体功能图
3.3.2 用户登录流程
金融信息化及交易管理系统(股票交易系统APP)_第2张图片

图3-2 用户登录流程

package com.chandler.red.mystock;

import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.WindowManager;
import android.widget.TextView;
import android.widget.Toast;

import com.android.volley.Request;
import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.StringRequest;
import com.android.volley.toolbox.Volley;
import com.chandler.red.mystock.adapter.MainStockListAdapter;
import com.chandler.red.mystock.db.MyDbManager;
import com.chandler.red.mystock.db.MySqlHelper;
import com.chandler.red.mystock.entity.Stock;
import com.chandler.red.mystock.entity.StockBean;
import com.chandler.red.mystock.manager.ThreadPoolManager;
import com.timehop.stickyheadersrecyclerview.StickyRecyclerHeadersDecoration;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.HashSet;
import java.util.List;
import java.util.Timer;
import java.util.TimerTask;


public class MainActivity extends AppCompatActivity implements View.OnClickListener{

    private static HashSet StockHeadIds_ = new HashSet();
    private static List StockIds_ = new ArrayList<>();
    private final static String ShIndex = "s_sh000001";
    private final static String SzIndex = "s_sz399001";
    private final static String ChuangIndex = "s_sz399006";
    private final static String Sh50Index = "s_sh000016";
    private final static String Sh300Index = "s_sh000300";
    private final static String ZXIndex = "s_sz399005";
    private final static String DqsIndex = "gb_$dji";
    private final static String NsdkIndex = "gb_ixic";
    private final static String HkIndex = "rt_hkHSI";
    private final static int MAX_SH = 604000;
    private final static int MAX_SZ = 3000;
    private final static int MAX_CH = 302000;
    private TextView tvDate;
    private Timer timer;
    RecyclerView recyclerView;
    MainStockListAdapter adapter;
    List stockList;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
        initClickEvent();
    }

    private void initView() {
        tvDate = findViewById(R.id.tv_date);
        recyclerView = findViewById(R.id.recycle_view);
        stockList = new ArrayList<>();
        recyclerView.setLayoutManager(new LinearLayoutManager(this));
        adapter = new MainStockListAdapter(this, stockList);
        recyclerView.setAdapter(adapter);
        // Add the sticky headers decoration
        final StickyRecyclerHeadersDecoration headersDecor = new StickyRecyclerHeadersDecoration(adapter);
        recyclerView.addItemDecoration(headersDecor);
        adapter.setOnItemClickLitener(new MainStockListAdapter.OnItemClickLitener() {
            @Override
            public void onItemClick(View view, int position) {
                String id = stockList.get(position).getId_();
                String url = StockImgApi.IMG_F + id.split("_")[1] + ".gif";
                Intent intent = new Intent(MainActivity.this, StockImgActivity.class);
                intent.putExtra("type",2);
                intent.putExtra("url", url);
                intent.putExtra("id", id);
                startActivity(intent);
            }

            @Override
            public void onItemLongClick(View view, int position) {
                showMyDialog(position);
            }
        });
    }

    private void initClickEvent(){
        findViewById(R.id.sh_layout).setOnClickListener(this);
        findViewById(R.id.sz_layout).setOnClickListener(this);
        findViewById(R.id.chuang_layout).setOnClickListener(this);
        findViewById(R.id.dqs_layout).setOnClickListener(this);
        findViewById(R.id.nsdq_layout).setOnClickListener(this);
        findViewById(R.id.hk_layout).setOnClickListener(this);
        findViewById(R.id.sh50_layout).setOnClickListener(this);
        findViewById(R.id.sh300_layout).setOnClickListener(this);
        findViewById(R.id.zx_layout).setOnClickListener(this);
    }

    private void refreshTime(){
        Calendar calendar = Calendar.getInstance();
        String now = calendar.get(Calendar.YEAR) + "年"
                + (calendar.get(Calendar.MONTH)+1) + "月"//从0计算
                + calendar.get(Calendar.DAY_OF_MONTH) + "日 "
                + "星期"+weekDayFormate(calendar.get(Calendar.DAY_OF_WEEK))
                + "  "+calendar.get(Calendar.HOUR_OF_DAY)+":"+calendar.get(Calendar.MINUTE)+":"+calendar.get(Calendar.SECOND);
        tvDate.setText(now);
    }

    private String weekDayFormate(int num){
        String week = "";
        if(num==1){
            week = "日";
        }else if(num==2){
            week = "一";
        }else if(num==3){
            week = "二";
        }else if(num==4){
            week = "三";
        }else if(num==5){
            week = "四";
        }else if(num==6){
            week = "五";
        }else if(num==7){
            week = "六";
        }
        return week;
    }

    @Override
    public void onDestroy() {
        super.onDestroy();  // Always call the superclass

//        saveStocksToPreferences();
        MyDbManager.getInstance(this).closeDb();

    }

    @Override
    protected void onPause() {
        super.onPause();
        timer.cancel();
        queue.stop();
    }

    @Override
    protected void onResume() {
        super.onResume();
        refreshTime();

        timer = new Timer("RefreshStocks");
        timer.schedule(new TimerTask() {
            @Override
            public void run() {
                handler.sendEmptyMessageAtTime(2,500);
            }
        }, 0, 9500); // 10 seconds
    }

    @Override
    public void onSaveInstanceState(Bundle savedInstanceState) {
//        saveStocksToPreferences();

        // Always call the superclass so it can save the view hierarchy state
        super.onSaveInstanceState(savedInstanceState);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_main, menu);
        return true;
    }

    String numberlist = "";
    int from = 1;
    int curNumber = 600001;
    int szNumber = 1;
    int chuangNumber = 300001;
    private void createShNumber(){
        numberlist = "000001";
        for(int i=0;i<50;i++){
            if(curNumber>=MAX_SH)break;
            if(curNumber>=602000 && curNumber<603000)curNumber=603000;
            numberlist = numberlist+","+curNumber;
            curNumber++;
        }
        createStockData(numberlist);
    }

    private void createSzNumber(){
        numberlist = "399001";
        for(int i=0;i<50;i++){
            if(szNumber>=MAX_SZ)break;
            if(szNumber<10){
                numberlist = numberlist+",00000"+szNumber;
            }else if(szNumber<100){
                numberlist = numberlist+",0000"+szNumber;
            }else if(szNumber<1000){
                numberlist = numberlist+",000"+szNumber;
            }else {
                numberlist = numberlist+",00"+szNumber;
            }
            szNumber++;
        }
        createStockData(numberlist);
    }

    private void createChuangNumber(){
        numberlist = "399006";
        for(int i=0;i<50;i++){
            if(chuangNumber>=MAX_CH)break;
            numberlist = numberlist+","+chuangNumber;
            chuangNumber++;
        }
        createStockData(numberlist);
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_create) {
            showProgressDialog("正在生成股票数据...");
            createShNumber();
            return true;
        }
        else if(id == R.id.action_search){
            searchStockData();
        }
        else if(id == R.id.action_refresh){
            refreshStocks();
        }

        return super.onOptionsItemSelected(item);
    }

    private void createStockData(String numbers){
        String[] nums = numbers.split(",");
        String list = "";
        for(String number:nums){
            if(number.length() != 6)
                continue;
            if (number.startsWith("6")) {
                number = "s_sh" + number;
            } else if (number.startsWith("0") || number.startsWith("3")) {
                number = "s_sz" + number;
            } else{
                continue;
            }
            list += number+",";
        }
        list = list.substring(0,list.length()-1);
        querySinaStock(list);
    }

    private Handler handler = new Handler(){
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            switch (msg.what){
                case 1:
                    if(curNumber=MAX_SH && szNumber>=MAX_SZ && chuangNumber>=MAX_CH){
                            runOnUiThread(new Runnable() {
                                @Override
                                public void run() {
                                    dimissProgressDialog();
                                    int count = MyDbManager.getInstance(MainActivity.this).getStockCount();
                                    Toast.makeText(MainActivity.this,"生成股票数据成功,共:"+count+"支股票",Toast.LENGTH_LONG).show();
                                    Log.i(MySqlHelper.TAG,"curNumber:"+curNumber+" szNumber:"+szNumber+" chuangNumber:"+chuangNumber);
                                }
                            });
                        }else {
                            runOnUiThread(new Runnable() {
                                @Override
                                public void run() {
                                    dimissProgressDialog();
                                    int count = MyDbManager.getInstance(MainActivity.this).getStockCount();
                                    Toast.makeText(MainActivity.this,"生成股票数据失败,共:"+count+"支股票",Toast.LENGTH_LONG).show();
                                    Log.i(MySqlHelper.TAG,"curNumber:"+curNumber+" szNumber:"+szNumber+" chuangNumber:"+chuangNumber);
                                }
                            });
                        }
                    }
                    break;
                case 2:
                    refreshStocks();
                    break;
                case 3:
                    refreshSelectedStock();
                    break;
                default:

                    break;
            }
        }
    };

    public void querySinaStock(String list){
        // Instantiate the RequestQueue.
        if(queue==null)
            queue = Volley.newRequestQueue(this);
        String url ="http://hq.sinajs.cn/list=" + list;
        //http://hq.sinajs.cn/list=sh600000,sh600536

        // Request a string response from the provided URL.
        StringRequest stringRequest = new StringRequest(Request.Method.GET, url,
                new Response.Listener() {
                    @Override
                    public void onResponse(final String response) {
                        ThreadPoolManager.getSinglePool().execute(new Runnable() {
                            @Override
                            public void run() {
                                MyDbManager.getInstance(MainActivity.this).replace(responseToStocks(response));
//                                handler.removeCallbacksAndMessages(null);
                                handler.sendEmptyMessage(1);
                                Log.i(MySqlHelper.TAG,"success curNumber:"+curNumber+" szNumber:"+szNumber+" chuangNumber:"+chuangNumber+" from:"+from);
                            }
                        });
                    }
                },
                new Response.ErrorListener() {
                    @Override
                    public void onErrorResponse(VolleyError error) {
                        if(from == 1){
                            from = 2;
                        }else if(from ==2){
                            from = 3;
                        }else if(from ==3){
                            from = 4;
                        }
                        Log.i(MySqlHelper.TAG,"error curNumber:"+curNumber+" szNumber:"+szNumber+" chuangNumber:"+chuangNumber+" from:"+from);
//                        handler.removeCallbacksAndMessages(null);
                        handler.sendEmptyMessage(1);
                    }
                });

        queue.add(stringRequest);
        queue.start();
    }

    public List responseToStocks(String response){
        response = response.replaceAll("\n", "");
        String[] stocks = response.split(";");

        List stockList = new ArrayList<>();
        for(String stock : stocks) {
            String[] leftRight = stock.split("=");
            if (leftRight.length < 2)
                continue;

            String right = leftRight[1].replaceAll("\"", "");
            if (right.isEmpty())
                continue;

            String left = leftRight[0];
            if (left.isEmpty())
                continue;
            String[] lefts = left.split("_");
            String number = lefts[2]+"_"+lefts[3];
            String name = "";
            String value = "";
            String[] values = right.split(",");
            try{
                if(number.equals(ShIndex) || number.equals(SzIndex) || number.equals(ChuangIndex)){
                    name = values[0];
                    value = values[1];
                }else if(number.equals(DqsIndex) || number.equals(NsdkIndex)){
                    name = values[0];
                    value = values[1];
                }else if(number.equals(HkIndex)){
                    name = values[0];
                    value = values[6];
                }else {
                    name = values[0];
                    value = values[1];
                }

            }catch (ArrayIndexOutOfBoundsException e){
                Log.e("MainActivity",e.toString());
            }
            StockBean stockNow = new StockBean(number,name,value);
            StockBean  stockBean= MyDbManager.getInstance(this).getStockByNumberOrName(number);
            if(stockBean!=null){
                stockNow.setSelected(stockBean.isSelected());
                stockNow.setTopTime(stockBean.getTopTime());
            }
            stockList.add(stockNow);
        }

        return stockList;
    }

    private void searchStockData(){
        startActivity(new Intent(MainActivity.this,SerachActivity.class));
    }

    @Override
    public void onClick(View view) {
        Intent intent = new Intent(MainActivity.this,StockImgActivity.class);
        intent.putExtra("type",1);
        switch (view.getId()){
            case R.id.sh_layout:
                intent.putExtra("url",StockImgApi.SHIMG);
                intent.putExtra("id",ShIndex);
                break;
            case R.id.sz_layout:
                intent.putExtra("url",StockImgApi.SZIMG);
                intent.putExtra("id",SzIndex);
                break;
            case R.id.chuang_layout:
                intent.putExtra("url",StockImgApi.CHUANGIMG);
                intent.putExtra("id",ChuangIndex);
                break;
            case R.id.dqs_layout:
                intent.putExtra("url",StockImgApi.DQS);
                intent.putExtra("id",DqsIndex);
                break;
            case R.id.nsdq_layout:
                intent.putExtra("url",StockImgApi.NSDQ);
                intent.putExtra("id",NsdkIndex);
                break;
            case R.id.hk_layout:
                intent.putExtra("url",StockImgApi.HK);
                intent.putExtra("id",HkIndex);
                break;
            case R.id.sh50_layout:
                intent.putExtra("url",StockImgApi.SH50);
                intent.putExtra("id",Sh50Index);
                break;
            case R.id.sh300_layout:
                intent.putExtra("url",StockImgApi.SH300);
                intent.putExtra("id",Sh300Index);
                break;
            case R.id.zx_layout:
                intent.putExtra("url",StockImgApi.ZX);
                intent.putExtra("id",ZXIndex);
                break;
        }
        startActivity(intent);
    }

    // 浦发银行,15.06,15.16,15.25,15.27,14.96,15.22,15.24,205749026,3113080980,
    // 51800,15.22,55979,15.21,1404740,15.20,1016176,15.19,187800,15.18,300,15.24,457700,15.25,548900,15.26,712266,15.27,1057960,15.28,2015-09-10,15:04:07,00

    public List sinaResponseToStocks(String response){
        response = response.replaceAll("\n", "");
        String[] stocks = response.split(";");

        List stockBeanList = new ArrayList<>();
        for(String stock : stocks) {
            String[] leftRight = stock.split("=");
            if (leftRight.length < 2)
                continue;

            String right = leftRight[1].replaceAll("\"", "");
            if (right.isEmpty())
                continue;

            String left = leftRight[0];
            if (left.isEmpty())
                continue;

            Stock stockNow = new Stock();
            String[] lefts = left.split("_");
            stockNow.id_ = lefts[2]+"_"+lefts[3];

            String[] values = right.split(",");
            try{
                if(stockNow.id_.equals(ShIndex) || stockNow.id_.equals(SzIndex) || stockNow.id_.equals(ChuangIndex)){
                    stockNow.name_ = values[0];
                    stockNow.now_ = values[1];
                    stockNow.increase = values[2];
                    stockNow.percent = values[3];
                }else if(stockNow.id_.equals(DqsIndex) || stockNow.id_.equals(NsdkIndex)){
                    stockNow.name_ = values[0];
                    stockNow.now_ = values[1];
                    stockNow.increase = values[4];
                    stockNow.percent = values[2];
                }else if(stockNow.id_.equals(HkIndex)){
                    stockNow.name_ = values[1];
                    stockNow.now_ = values[6];
                    stockNow.increase = values[7];
                    stockNow.percent = values[8];
                }else {
                    stockNow.name_ = values[0];
                    stockNow.now_ = values[1];
                    stockNow.increase = values[2];
                    stockNow.percent = values[3];
                }

            }catch (ArrayIndexOutOfBoundsException e){
                Log.e("MainActivity",e.toString());
            }

            stockBeanList.add(stockNow);
        }

        return stockBeanList;
    }

    RequestQueue queue;
    public void querySinaHeadStocks(String list){
        // Instantiate the RequestQueue.
        if(queue==null)
            queue = Volley.newRequestQueue(this);
        String url ="http://hq.sinajs.cn/list=" + list;
        //http://hq.sinajs.cn/list=sh600000,sh600536

        // Request a string response from the provided URL.
        StringRequest stringRequest = new StringRequest(Request.Method.GET, url,
                new Response.Listener() {
                    @Override
                    public void onResponse(String response) {
                        updateStockHeader(sinaResponseToStocks(response));
                    }
                },
                new Response.ErrorListener() {
                    @Override
                    public void onErrorResponse(VolleyError error) {
//                        Toast.makeText(MainActivity.this,"数据请求失败",Toast.LENGTH_LONG).show();
                        Log.e(MySqlHelper.TAG,"请求数据失败");
                    }
                });

        queue.add(stringRequest);
        queue.start();
    }

    public void querySinaStocks(String list){
        // Instantiate the RequestQueue.
        if(queue==null)
            queue = Volley.newRequestQueue(this);
        String url ="http://hq.sinajs.cn/list=" + list;
        //http://hq.sinajs.cn/list=sh600000,sh600536

        // Request a string response from the provided URL.
        StringRequest stringRequest = new StringRequest(Request.Method.GET, url,
                new Response.Listener() {
                    @Override
                    public void onResponse(String response) {
                        updateStockListView(sinaResponseToStocks(response));
                    }
                },
                new Response.ErrorListener() {
                    @Override
                    public void onErrorResponse(VolleyError error) {
                        Log.e(MySqlHelper.TAG,"请求数据失败");
                    }
                });

        queue.add(stringRequest);
        queue.start();
    }

    private void refreshStocks(){
        runOnUiThread(new Runnable() {
            @Override
            public void run() {
                refreshTime();
            }
        });
        refreshHeaderStock();
        refreshSelectedStock();
    }

    private void refreshHeaderStock(){
        String idsStr = ShIndex + "," + SzIndex + "," + ChuangIndex+","+Sh50Index+","+Sh300Index+","+ZXIndex
                +","+DqsIndex+","+NsdkIndex+"," +HkIndex;

        String[] ids = idsStr.split(",");
        StockHeadIds_.clear();
        for (String id : ids) {
            StockHeadIds_.add(id);
        }

        String headids = "";
        for (String id : StockHeadIds_){
            headids += id;
            headids += ",";
        }
        querySinaHeadStocks(headids);
    }

    private void refreshSelectedStock(){
        StockIds_.clear();
        List selectids = MyDbManager.getInstance(this).getSelectedStockIds();
        for(String id:selectids){
            StockIds_.add(id);
        }
        String ids = "";
        for (String id : StockIds_){
            ids += id;
            ids += ",";
        }

        querySinaStocks(ids);
    }

    private void updateStockHeader(List stocks) {
        for (Stock stock : stocks) {
            Double dIncrease = Double.parseDouble(stock.increase);
            Double dPercent = Double.parseDouble(stock.percent);
            String change = String.format("%.2f", dPercent) + "% " + String.format("%.2f", dIncrease);
            if (stock.id_.equals(ShIndex) || stock.id_.equals(SzIndex) || stock.id_.equals(ChuangIndex)
                    || stock.id_.equals(DqsIndex) || stock.id_.equals(NsdkIndex) || stock.id_.equals(HkIndex)
                    || stock.id_.equals(Sh50Index) || stock.id_.equals(Sh300Index) || stock.id_.equals(ZXIndex)) {
                int indexId;
                int changeId;
                int nameId;
                if (stock.id_.equals(ShIndex)) {
                    indexId = R.id.stock_sh_index;
                    changeId = R.id.stock_sh_change;
                    nameId = R.id.stock_sh_name;
                } else if (stock.id_.equals(SzIndex)) {
                    indexId = R.id.stock_sz_index;
                    changeId = R.id.stock_sz_change;
                    nameId = R.id.stock_sz_name;
                } else if (stock.id_.equals(ChuangIndex)) {
                    indexId = R.id.stock_chuang_index;
                    changeId = R.id.stock_chuang_change;
                    nameId = R.id.stock_chuang_name;
                } else if (stock.id_.equals(DqsIndex)) {
                    indexId = R.id.stock_dqs_index;
                    changeId = R.id.stock_dqs_change;
                    nameId = R.id.stock_dqs_name;
                } else if (stock.id_.equals(NsdkIndex)) {
                    indexId = R.id.stock_nsdk_index;
                    changeId = R.id.stock_nsdk_change;
                    nameId = R.id.stock_nsdk_name;
                } else if (stock.id_.equals(HkIndex)) {
                    indexId = R.id.stock_hk_index;
                    changeId = R.id.stock_hk_change;
                    nameId = R.id.stock_hk_name;
                } else if (stock.id_.equals(Sh50Index)) {
                    indexId = R.id.stock_sh50_index;
                    changeId = R.id.stock_sh50_change;
                    nameId = R.id.stock_sh50_name;
                } else if (stock.id_.equals(Sh300Index)) {
                    indexId = R.id.stock_sh300_index;
                    changeId = R.id.stock_sh300_change;
                    nameId = R.id.stock_sh300_name;
                } else {
                    indexId = R.id.stock_zx_index;
                    changeId = R.id.stock_zx_change;
                    nameId = R.id.stock_zx_name;
                }
                TextView indexText = findViewById(indexId);
                TextView changeText = findViewById(changeId);
                TextView nameText = findViewById(nameId);
                nameText.setText(stock.name_);
                indexText.setText(stock.now_);
                int color = getResources().getColor(R.color.main_text_color);
                if (dIncrease > 0) {
                    color = getResources().getColor(R.color.main_red_color);
                } else if (dIncrease < 0) {
                    color = getResources().getColor(R.color.main_green_color);
                }
                indexText.setTextColor(color);
                changeText.setTextColor(color);
                changeText.setText(change);

                continue;
            }
        }
    }

    public void updateStockListView(List stocks){
        List topIds = MyDbManager.getInstance(this).getTopStockIds();
        for(Stock stock:stocks){
            if(topIds.contains(stock.getId_())){
                stock.setTop(true);
            }else {
                stock.setTop(false);
            }
        }
        stockList = stocks;
        adapter.setData(stockList);
    }

    private void showMyDialog(final int position){
        final AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
        View view = LayoutInflater.from(this).inflate(R.layout.dialog_layout,null);
        TextView tvTop = view.findViewById(R.id.tv_top);
        TextView tvDel = view.findViewById(R.id.tv_delete);
        final String id = stockList.get(position).getId_();
        final boolean isTop = stockList.get(position).isTop();
        if(isTop){
            tvTop.setText("取消置顶");
        }else {
            tvTop.setText("置顶股票");
        }
        builder.setView(view);
        final AlertDialog alertDialog=builder.show();
        WindowManager.LayoutParams lp = alertDialog.getWindow().getAttributes();
        lp.width = getResources().getDimensionPixelSize(R.dimen.dialog_width);
        lp.height = getResources().getDimensionPixelSize(R.dimen.dialog_height);
        alertDialog.getWindow().setAttributes(lp);

        tvTop.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                alertDialog.dismiss();
                if(isTop){
                    MyDbManager.getInstance(MainActivity.this).updateStockTopTime(id,0);
                }else {
                    long time = System.currentTimeMillis();
                    MyDbManager.getInstance(MainActivity.this).updateStockTopTime(id,time);
                }
                handler.removeCallbacksAndMessages(null);
                handler.sendEmptyMessage(3);
            }
        });
        tvDel.findViewById(R.id.tv_delete).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                alertDialog.dismiss();
                MyDbManager.getInstance(MainActivity.this).clearSelected(id);
                stockList.remove(position);
                adapter.setData(stockList);
                Toast.makeText(MainActivity.this, "已删除", Toast.LENGTH_SHORT).show();
            }
        });
    }

    ProgressDialog mProgressDialog;
    protected void showProgressDialog(String msg){
        try{
            showProgressDialog(msg,true,true);
        }catch (Exception e){
        }
    }
    protected void showProgressDialog(String msg,boolean isCancelOutside){
        showProgressDialog(msg,true,isCancelOutside);
    }

    protected void showProgressDialog(String msg, boolean isCancelable,boolean isCancelOutside){
        if(mProgressDialog==null){
            mProgressDialog = new ProgressDialog(this);
        }
        if(mProgressDialog.isShowing()){
            return;
        }
        mProgressDialog.setMessage(msg);
        mProgressDialog.setCancelable(isCancelable);
        mProgressDialog.setCanceledOnTouchOutside(isCancelable);
        mProgressDialog.show();
    }

    protected void dimissProgressDialog(){
        if(mProgressDialog!=null && mProgressDialog.isShowing()){
            mProgressDialog.dismiss();
        }
    }
}

金融信息化及交易管理系统(股票交易系统APP)_第3张图片
金融信息化及交易管理系统(股票交易系统APP)_第4张图片
金融信息化及交易管理系统(股票交易系统APP)_第5张图片
金融信息化及交易管理系统(股票交易系统APP)_第6张图片
金融信息化及交易管理系统(股票交易系统APP)_第7张图片
金融信息化及交易管理系统(股票交易系统APP)_第8张图片
金融信息化及交易管理系统(股票交易系统APP)_第9张图片
金融信息化及交易管理系统(股票交易系统APP)_第10张图片
金融信息化及交易管理系统(股票交易系统APP)_第11张图片
金融信息化及交易管理系统(股票交易系统APP)_第12张图片
金融信息化及交易管理系统(股票交易系统APP)_第13张图片
金融信息化及交易管理系统(股票交易系统APP)_第14张图片
金融信息化及交易管理系统(股票交易系统APP)_第15张图片
金融信息化及交易管理系统(股票交易系统APP)_第16张图片
金融信息化及交易管理系统(股票交易系统APP)_第17张图片
金融信息化及交易管理系统(股票交易系统APP)_第18张图片
金融信息化及交易管理系统(股票交易系统APP)_第19张图片
金融信息化及交易管理系统(股票交易系统APP)_第20张图片
金融信息化及交易管理系统(股票交易系统APP)_第21张图片
金融信息化及交易管理系统(股票交易系统APP)_第22张图片

你可能感兴趣的:(股票交易系统,金融交易系统,股票APP,Java,毕业设计)