package com.example.administrator.project; import android.animation.ObjectAnimator; import android.animation.ValueAnimator; import android.app.Activity; import android.app.AlertDialog; import android.content.ContentValues; import android.content.DialogInterface; import android.content.Intent; import android.content.res.Resources; import android.content.res.TypedArray; import android.database.Cursor; import android.database.sqlite.SQLiteDatabase; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.net.Uri; import android.os.Bundle; import android.text.TextUtils; import android.view.View; import android.view.animation.Animation; import android.view.animation.LayoutAnimationController; import android.view.animation.LinearInterpolator; import android.view.animation.ScaleAnimation; import android.widget.AdapterView; import android.widget.ArrayAdapter; import android.widget.Button; import android.widget.ImageButton; import android.widget.ListView; import android.widget.SearchView; import android.widget.SimpleAdapter; import android.widget.Toast; import java.io.BufferedReader; import java.io.InputStream; import java.io.InputStreamReader; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; public class CharactorActivity extends Activity { public static SimpleAdapter adapter; public static SimpleAdapter adapter1; public static int ff; private ListView mListView; private ListView mListView1; private Animation animation; private LayoutAnimationController controller; public static List<Map<String,Object>> charactor = new ArrayList<>(); public static List<String> Lname = new ArrayList<>(); public static List<String> Linformation = new ArrayList<>(); public static int[] s = new int[20]; public static int[] txtids = new int[100]; public static SpellConvert spellConvert = SpellConvert.getInstance();; // public static boolean[] is_uri = new boolean[100]; // public static Uri[] alluri = new Uri[100]; private int[] imagesId={R.drawable.liubei,R.drawable.lvbu,R.drawable.simayi,R.drawable.sunquan,R.drawable.zhangfei,R.drawable.zhouyu,R.drawable.zhugeliang,R.drawable.diaochan_big,R.drawable.guanyu,R.drawable.caocao}; public int[] resIds = {R.mipmap.liubei1,R.mipmap.lvbu1,R.mipmap.simayi1,R.mipmap.sunquan1,R.mipmap.zhangfei1,R.mipmap.zhouyu1,R.mipmap.zhugeliang1,R.mipmap.diaochan1,R.mipmap.guanyu1,R.mipmap.caocao1}; public static String[] Name = new String[]{"刘备(Liu Bei)","吕布(Lv Bu)","司马懿(Si Ma Yi)","孙权(Sun Quan)","张飞(Zhang Fei)","周瑜(Zhou Yu)","诸葛亮(Zhu Ge Liang)","貂蝉(Diao Chan)","关羽(Guan Yu)","曹操(Cao Cao)"}; public static String[] Sex = new String[]{"男","男","男","男","男","男","男","女","男","男"}; public static String[] Bron = new String[]{"161 - 223","? - 198","179 - 251","182 - 252","? - 221","175 - 210","181 - 234","? - ?","? - 219","155 - 220"}; public static String[] Where = new String[]{"幽州涿郡(河北保定市涿州)","并州五原郡九原(内蒙古包头市九原区麻池镇西北古城遗址)","司隶河内郡温(河南焦作市温县西)","扬州吴郡富春(浙江杭州市富阳)","幽州涿郡(河北保定市涿州)","扬州庐江郡舒(安徽合肥市庐江县西南)","徐州琅邪国阳都(山东临沂市沂南县南)","?(虚构人物)","司隶河东郡解(山西运城市临猗县西南)","豫州沛国谯(安徽亳州市亳县)"}; public static String[] Country = new String[]{"蜀","群","魏","吴","蜀","吴","蜀","群","蜀","蜀"}; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.charactor_content); TypedArray ar = getResources().obtainTypedArray(R.array.actions); int len = ar.length(); for (int i = 0; i < len; i++) { txtids[i] = ar.getResourceId(i, 0); InputStream inputStream = getResources().openRawResource(txtids[i]); Linformation.add(getString(inputStream)); } ar.recycle(); charactor.clear(); for(int i=0;i<10;i++){ Map<String,Object> temp = new LinkedHashMap<>(); // temp.put("uri","zzz"); temp.put("imageid",imagesId[i]); temp.put("resid",resIds[i]); temp.put("name",Name[i]); temp.put("sex",Sex[i]); temp.put("bron",Bron[i]); temp.put("where",Where[i]); temp.put("country",Country[i]); temp.put("txtid",i); // is_uri[i] = false; charactor.add(temp); Lname.add(spellConvert.getSelling(Name[i])); } ff = 0; mListView = (ListView)findViewById(R.id.listView); mListView1 = (ListView)findViewById(R.id.listView1); SearchView searchView = (SearchView) findViewById(R.id.searchView); adapter = new SimpleAdapter(this,charactor,R.layout.list_item,new String[] {"imageid","name"},new int [] {R.id.imageView,R.id.textView}); mListView.setAdapter(adapter); mListView.setVisibility(View.VISIBLE); mListView1.setVisibility(View.INVISIBLE); mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> adapterView, View view, int position, long id) { Intent intent = new Intent(CharactorActivity.this,Charactor.class); Bundle bundle = new Bundle(); bundle.putString("name",charactor.get(position).get("name").toString()); bundle.putString("sex",charactor.get(position).get("sex").toString()); bundle.putString("bron",charactor.get(position).get("bron").toString()); bundle.putString("where",charactor.get(position).get("where").toString()); bundle.putString("country",charactor.get(position).get("country").toString()); bundle.putInt("imageid",Integer.valueOf(charactor.get(position).get("imageid").toString()).intValue()); bundle.putInt("resid",Integer.valueOf(charactor.get(position).get("resid").toString()).intValue()); bundle.putInt("txtid",Integer.valueOf(charactor.get(position).get("txtid").toString()).intValue()); bundle.putInt("id",position); intent.putExtras(bundle); startActivity(intent); overridePendingTransition(R.anim.lefttoright, R.anim.righttoleft); } }); mListView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() { @Override public boolean onItemLongClick(AdapterView<?> parent, View view, final int position, long id) { AlertDialog.Builder builder = new AlertDialog.Builder(CharactorActivity.this); builder.setTitle("删除人物信息"); builder.setMessage("从人物列表删除" + charactor.get(position).get("name") + "?"); builder.setPositiveButton("确定",new DialogInterface.OnClickListener(){ @Override public void onClick(DialogInterface dialog, int which) { charactor.remove(position); Lname.remove(position); adapter.notifyDataSetChanged(); // for(int i=position;i<20;i++){ // alluri[i] = alluri[i+1]; // } } }).setNegativeButton("取消",new DialogInterface.OnClickListener(){ @Override public void onClick(DialogInterface dialog, int which) { } }).create(); builder.show(); return true; } }); animation = new ScaleAnimation(0.1f, 1.0f, 0.1f, 1.0f); animation.setDuration(500); controller = new LayoutAnimationController(animation, 1f); controller.setOrder(LayoutAnimationController.ORDER_NORMAL); mListView.setLayoutAnimation(controller); mListView.setTextFilterEnabled(true); searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener(){ @Override public boolean onQueryTextChange(String newText) { if(!TextUtils.isEmpty(newText)){ searchItem(newText); } else{ mListView.setVisibility(View.VISIBLE); mListView1.setVisibility(View.INVISIBLE); } return true; } @Override public boolean onQueryTextSubmit(String query) { mListView1.setVisibility(View.VISIBLE); mListView.setVisibility(View.INVISIBLE); // TODO Auto-generated method stub return false; } }); searchView.setSubmitButtonEnabled(false); Button add_button = (Button) findViewById(R.id.add_button); add_button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent intent1 = new Intent(CharactorActivity.this,Charactor.class); Bundle bundle = new Bundle(); CharactorActivity.ff = 1; bundle.putString("name",null); bundle.putString("sex",null); bundle.putString("bron",null); bundle.putString("where",null); bundle.putString("country",null); bundle.putString("imageid",null); bundle.putString("resid",null); bundle.putInt("txtid",10); bundle.putString("id",null); bundle.putString("uri",null); intent1.putExtras(bundle); startActivity(intent1); overridePendingTransition(R.anim.lefttoright, R.anim.righttoleft); } }); } public void searchItem(String name) { final List<Map<String,Object>> searcharray = new ArrayList<>(); int z = 0; for (int i = 0; i < Lname.size(); i++) { int index = Lname.get(i).indexOf(name); // 存在匹配的数据 if (index != -1) { Map<String,Object> temp = new LinkedHashMap<>(); temp.put("imageid",Integer.valueOf(charactor.get(i).get("imageid").toString()).intValue()); temp.put("resid",Integer.valueOf(charactor.get(i).get("resid").toString()).intValue()); temp.put("name",charactor.get(i).get("name").toString()); temp.put("sex",charactor.get(i).get("sex").toString()); temp.put("bron",charactor.get(i).get("bron").toString()); temp.put("where",charactor.get(i).get("where").toString()); temp.put("country",charactor.get(i).get("country").toString()); temp.put("txtid",Integer.valueOf(charactor.get(i).get("txtid").toString()).intValue()); temp.put("uri",null); searcharray.add(temp); s[z] = i; z++; } } adapter1 = new SimpleAdapter(this,searcharray,R.layout.list_item,new String[] {"imageid","name"},new int [] {R.id.imageView,R.id.textView}); mListView1.setAdapter(adapter1); mListView1.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> adapterView, View view, int position, long id) { Intent intent = new Intent(CharactorActivity.this,Charactor.class); Bundle bundle = new Bundle(); bundle.putString("name",searcharray.get(position).get("name").toString()); bundle.putString("sex",searcharray.get(position).get("sex").toString()); bundle.putString("bron",searcharray.get(position).get("bron").toString()); bundle.putString("where",searcharray.get(position).get("where").toString()); bundle.putString("country",searcharray.get(position).get("country").toString()); bundle.putString("imageid",searcharray.get(position).get("imageid").toString()); bundle.putInt("resid",Integer.valueOf(searcharray.get(position).get("resid").toString()).intValue()); bundle.putInt("txtid",Integer.valueOf(searcharray.get(position).get("txtid").toString()).intValue()); bundle.putInt("id",s[position]);; intent.putExtras(bundle); startActivity(intent); overridePendingTransition(R.anim.lefttoright, R.anim.righttoleft); } }); mListView1.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() { @Override public boolean onItemLongClick(AdapterView<?> parent, View view, final int position, long id) { AlertDialog.Builder builder = new AlertDialog.Builder(CharactorActivity.this); builder.setTitle("删除人物信息"); builder.setMessage("从人物列表删除" + searcharray.get(position).get("name") + "?"); builder.setPositiveButton("确定",new DialogInterface.OnClickListener(){ @Override public void onClick(DialogInterface dialog, int which) { searcharray.remove(position); charactor.remove(s[position]); Lname.remove(s[position]); adapter.notifyDataSetChanged(); adapter1.notifyDataSetChanged(); for(int i=position;i<9;i++){ s[i] = s[i+1]; } // for(int i=s[position];i<20;i++){ // alluri[i] = alluri[i+1]; // } } }).setNegativeButton("取消",new DialogInterface.OnClickListener(){ @Override public void onClick(DialogInterface dialog, int which) { } }).create(); builder.show(); return true; } }); } public static String getString(InputStream inputStream) { InputStreamReader inputStreamReader = null; try { inputStreamReader = new InputStreamReader(inputStream, "GBK"); } catch (Exception e1) { e1.printStackTrace(); } BufferedReader reader = new BufferedReader(inputStreamReader); StringBuffer sb = new StringBuffer(""); String line; try { while ((line = reader.readLine()) != null) { sb.append(line); sb.append("\n"); } } catch (Exception e) { e.printStackTrace(); } return sb.toString(); } }
最近下载更多
阿九11111 LV4
5月21日
求学的熊猫 LV11
5月20日
121514713 LV2
2023年5月26日
dglin20001030 LV1
2023年5月18日
watsonChen LV1
2023年2月9日
1532593037 LV8
2023年1月7日
yzhszz LV3
2022年12月27日
SQ2930501923 LV14
2022年12月12日
Highlighz LV4
2022年6月29日
g010112g LV6
2022年5月22日
最近浏览更多
2636804923 LV6
6月20日
AIWU1234 LV2
6月9日
lilitu LV6
5月29日
今晚都别睡啦 LV9
5月29日
happySuperman LV2
5月29日
阿九11111 LV4
5月21日
Aban-beautiful
5月13日
暂无贡献等级
求学的熊猫 LV11
5月6日
wangxiaolaugh LV2
2023年12月25日
不止是六位数 LV7
2023年12月21日