Android Open Source - Naming Char Review2






From Project

Back to project page Naming.

License

The source code is released under:

Apache License

If you think the Android project Naming 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.miemie.naming;
/*www .  ja  v a2s . co m*/
import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TableRow;
import android.widget.TextView;

import java.util.HashSet;

public class CharReview2 extends Activity implements OnClickListener {
    private final int COLUMNS = 3;

    final int[] mIds = {
            R.id.row1,
            R.id.row2,
            R.id.row3,
            R.id.row4,
            R.id.row5,
            R.id.row6,
            R.id.row7,
            R.id.row8,
            R.id.row9,
            R.id.row10,
    };

    private final int COUNT = mIds.length * COLUMNS;
    TextView[] mTVs = new TextView[COUNT];

    private int mID = 1;
    private SharedPreferences mPref;
    HashSet<String> mResult;
    String[] mSource;
    int mIndex = 0;
    ProgressDialog mDialog;

    SQLiteDatabase mDB;

    private Handler mHandler = new Handler() {

        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            if (msg.what == 1) {
                Intent it = new Intent();
                it.putExtra("id", mID);
                setResult(RESULT_OK, it);
                CharReview2.this.finish();
            }
        }

    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_review2);

        mDB = Utils.openNameDatabase(this);

        Intent it = getIntent();
        if (it != null) {
            mID = it.getIntExtra("id", 1);
        }

        mPref = getSharedPreferences(Constant.PREF_NAME, Context.MODE_PRIVATE);
        String temp = Utils.getStringPrefValue(mPref, Constant.PREF_CHARS, mID);
//        mResult = Utils.combineSToSet(temp, "@");
        mResult = new HashSet<String>();
        mSource = temp.split("@");

        for (int i = 0; i < mIds.length; i++) {
            TableRow row = (TableRow) findViewById(mIds[i]);
            mTVs[i * COLUMNS + 0] = (TextView) row.findViewById(R.id.tv_1);
            mTVs[i * COLUMNS + 0].setOnClickListener(this);
            mTVs[i * COLUMNS + 0].setTag(Boolean.FALSE);
            mTVs[i * COLUMNS + 1] = (TextView) row.findViewById(R.id.tv_2);
            mTVs[i * COLUMNS + 2] = (TextView) row.findViewById(R.id.tv_3);
        }

        Button next = (Button) findViewById(R.id.yes);
        next.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View arg0) {
                getNext();
                updateView();
            }
        });

    }

    @Override
    protected void onResume() {
        super.onResume();
        updateView();
    }

    @Override
    public void onClick(View v) {
        Boolean state = (Boolean) v.getTag();

        TextView tv = (TextView) v;
        String str = tv.getText().toString();
        String[] temp = str.split("\n");
        str = temp[0];
        
        if (state) {
            v.setBackgroundResource(android.R.color.background_light);
            if (mResult.contains(str)) {
                mResult.remove(str);
            }
        } else {
            v.setBackgroundResource(android.R.color.holo_blue_dark);
            if (!mResult.contains(str)) {
                mResult.add(str);
            }
        }
        v.setTag(!state);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        if (mDialog != null) {
            mDialog.dismiss();
            mDialog = null;
        }
        if (mDB != null) {
            mDB.close();
            mDB = null;
        }
    }

    @Override
    public void onBackPressed() {
        mDialog = new ProgressDialog(CharReview2.this);
        mDialog.setCancelable(false);
        mDialog.show();

        new Thread() {
            public void run() {
                int total = mSource.length;
                int index = mIndex * mTVs.length;
                if (total > index) {
                    String[] left = new String[total - index];
                    System.arraycopy(mSource, index, left, 0, left.length);
                    String result = Utils.allInOne(left, "@");
                    Utils.saveStringPrefValue(mPref, Constant.PREF_CHARS, result, mID);
                } else {
                    if (mResult.size() > 0) {
                        String result = Utils.allInOne(mResult.toArray(new String[mResult.size()]),
                                "@");
                        Utils.saveStringPrefValue(mPref, Constant.PREF_CHARS, result, mID);
                    }
                }
                

                if (mResult.size() > 0) {
                    Utils.saveToFile("charlist-" + mID +".txt", mResult, true);
                }

                mHandler.sendEmptyMessage(1);
            };
        }.start();
    }

    private void updateView() {
        SQLiteDatabase db = mDB;
        for (int i = 0; i < mIds.length; i++) {
            int index = mIndex * mIds.length + i;
            if (index < mSource.length) {
                String str = mSource[index];
                Cursor c = db.rawQuery(
                        "select strokes,spell,explain from signalName where signalNM=?",
                        new String[] {
                            str
                        });
                if (c == null) {
                    continue;
                }
                c.moveToFirst();
                mTVs[i * COLUMNS].setText(str);
                StringBuilder sb = new StringBuilder("(");
                sb.append(c.getString(1));
                sb.append(",");
                sb.append(c.getInt(0));
                sb.append(")");
                mTVs[i * COLUMNS + 1].setText(sb.toString());
                mTVs[i * COLUMNS + 2].setText(c.getString(2));
                c.close();
            } else {
                mTVs[i].setText("");
            }
        }
    }

    private boolean getNext() {

        for (int i = 0; i < mTVs.length; i++) {
            mTVs[i].setTag(Boolean.FALSE);
            mTVs[i].setBackgroundResource(android.R.color.background_light);
        }

        mIndex++;
        return true;
    }
}




Java Source Code List

com.miemie.naming.AbandonChars.java
com.miemie.naming.CharFilter.java
com.miemie.naming.CharReview2.java
com.miemie.naming.CharReview.java
com.miemie.naming.Constant.java
com.miemie.naming.MainActivity.java
com.miemie.naming.NamingProvider.java
com.miemie.naming.Naming.java
com.miemie.naming.PinyinActivity.java
com.miemie.naming.ResultActivity2.java
com.miemie.naming.ResultActivity.java
com.miemie.naming.Utils.java