package com.example.administrator.project; import android.animation.ObjectAnimator; import android.animation.ValueAnimator; import android.app.Activity; import android.app.AlertDialog; import android.content.ContentResolver; import android.content.Context; import android.content.DialogInterface; import android.content.Intent; import android.content.res.Resources; import android.database.Cursor; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.drawable.Drawable; import android.net.Uri; import android.os.Bundle; import android.provider.MediaStore; import android.view.View; import android.view.animation.LinearInterpolator; import android.widget.Button; import android.widget.EditText; import android.widget.ImageButton; import android.widget.ImageView; import android.widget.Toast; import java.io.BufferedReader; import java.io.File; import java.io.FileReader; import java.io.InputStream; import java.io.InputStreamReader; import java.io.OutputStream; import java.util.LinkedHashMap; import java.util.Map; /** * Created by Administrator on 2017/11/24. */ public class Charactor extends Activity{ public static int flag; public static int f = 1; public int id; public String name; public String sex; public String where; public String bron; public String information; public String country; public int txtid; public int imageid; public int resid; public int defaulresid; public int defaultimageid; public ImageButton imageButton; public ImageView imageView; public Button button1; private AlertDialog.Builder builder; public Button button2; public Button button3; // public Uri adduri; private ObjectAnimator discAnimation; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.charactor); final EditText ename = (EditText) findViewById(R.id.ename); final EditText ebron = (EditText) findViewById(R.id.ebron); final EditText esex = (EditText) findViewById(R.id.esex); final EditText ewhere = (EditText) findViewById(R.id.ewhere); final EditText ecountry = (EditText) findViewById(R.id.ecountry); final EditText einformation = (EditText) findViewById(R.id.einformation); imageView = (ImageView) findViewById(R.id.imageView3); button2 = (Button) findViewById(R.id.button2); button1 = (Button) findViewById(R.id.button1); button3 = (Button) findViewById(R.id.button3); flag = 0; defaulresid = R.mipmap.timg4; defaultimageid = R.drawable.timg4; final Intent intent = getIntent(); Bundle bundle = intent.getExtras(); id = bundle.getInt("id"); if(CharactorActivity.ff == 1){ name = bundle.getString("name"); ename.setText(name); ename.setFocusable(true); bron = bundle.getString("bron"); ebron.setText(bron); ebron.setFocusable(true); sex = bundle.getString("sex"); esex.setText(sex); esex.setFocusable(true); where = bundle.getString("where"); ewhere.setText(where); ewhere.setFocusable(true); country = bundle.getString("country"); ecountry.setText(country); ecountry.setFocusable(true); einformation.setFocusable(true); resid = bundle.getInt("resid"); imageView.setImageResource(defaulresid); txtid = bundle.getInt("txtid"); imageid = bundle.getInt("imageid"); information = CharactorActivity.Linformation.get(txtid); einformation.setText(information); button2.setVisibility(View.INVISIBLE); button1.setVisibility(View.INVISIBLE); button3.setVisibility(View.VISIBLE); imageView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent intent1 = new Intent(Intent.ACTION_PICK,android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI); startActivityForResult(intent1,1); } }); button3.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { builder = new AlertDialog.Builder(Charactor.this); builder.setTitle("添加信息"); builder.setMessage("确定添加?"); builder.setPositiveButton("确定", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int pos) { CharactorActivity.ff = 0; String name1 = ename.getText().toString(); String bron1 = ebron.getText().toString(); String sex1 = esex.getText().toString(); String where1 = ewhere.getText().toString(); String country1 = ecountry.getText().toString(); String information1 = einformation.getText().toString(); CharactorActivity.Linformation.add(CharactorActivity.Linformation.size(),information1); CharactorActivity.Lname.add(CharactorActivity.Lname.size(),CharactorActivity.spellConvert.getSelling(name1)); flag = 0; Map<String,Object> temp = new LinkedHashMap<>(); temp.put("imageid",defaultimageid); temp.put("resid",defaulresid); temp.put("name",name1); temp.put("sex",sex1); temp.put("bron",bron1); temp.put("where",where1); temp.put("country",country1); temp.put("txtid",txtid); CharactorActivity.charactor.add(CharactorActivity.charactor.size(),temp); // CharactorActivity.is_uri[CharactorActivity.charactor.size()-1] = true; // CharactorActivity.alluri[CharactorActivity.charactor.size()-1] = adduri; CharactorActivity.adapter.notifyDataSetChanged(); ename.setFocusable(false); ebron.setFocusable(false); ecountry.setFocusable(false); esex.setFocusable(false); ewhere.setFocusable(false); einformation.setFocusable(false); Toast.makeText(Charactor.this,"人物添加成功",Toast.LENGTH_SHORT).show(); finish(); } }).setNegativeButton("取消", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int pos) { ename.setText(name); ebron.setText(bron); ewhere.setText(where); esex.setText(sex); ecountry.setText(country); einformation.setText(information); } }); builder.show(); } }); } else { name = bundle.getString("name"); ename.setText(name); ename.setFocusable(false); bron = bundle.getString("bron"); ebron.setText(bron); ebron.setFocusable(false); sex = bundle.getString("sex"); esex.setText(sex); esex.setFocusable(false); where = bundle.getString("where"); ewhere.setText(where); ewhere.setFocusable(false); country = bundle.getString("country"); ecountry.setText(country); ecountry.setFocusable(false); einformation.setFocusable(false); resid = bundle.getInt("resid"); txtid = bundle.getInt("txtid"); imageid = bundle.getInt("imageid"); // if(CharactorActivity.is_uri[id]){ // try { // // 读取uri所在的图片 // Toast.makeText(Charactor.this,CharactorActivity.alluri[id].toString(),Toast.LENGTH_SHORT).show(); // imageView.setImageURI(CharactorActivity.alluri[id]); // } catch (Exception e) { // } // } // else{ imageView.setImageResource(resid); // } information = CharactorActivity.Linformation.get(txtid); einformation.setText(information); button3.setVisibility(View.INVISIBLE); } button1.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { ename.setFocusable(true); ebron.setFocusable(true); ecountry.setFocusable(true); esex.setFocusable(true); ewhere.setFocusable(true); einformation.setFocusable(true); flag = 1; button2.setVisibility(View.VISIBLE); button1.setVisibility(View.INVISIBLE); } }); if(flag==0){ button1.setVisibility(View.VISIBLE); button2.setVisibility(View.INVISIBLE); } else{ button2.setVisibility(View.VISIBLE); button1.setVisibility(View.INVISIBLE); } id = bundle.getInt("id"); button2.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { builder = new AlertDialog.Builder(Charactor.this); builder.setTitle("保存信息"); builder.setMessage("确定保存?"); builder.setPositiveButton("确定", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int pos) { String name1 = ename.getText().toString(); String bron1 = ebron.getText().toString(); String sex1 = esex.getText().toString(); String where1 = ewhere.getText().toString(); String country1 = ecountry.getText().toString(); String information1 = einformation.getText().toString(); CharactorActivity.Linformation.remove(txtid); CharactorActivity.Linformation.add(txtid,information1); CharactorActivity.Lname.remove(id); CharactorActivity.Lname.add(id,CharactorActivity.spellConvert.getSelling(name1)); flag = 0; button1.setVisibility(View.VISIBLE); button2.setVisibility(View.INVISIBLE); Map<String,Object> temp = new LinkedHashMap<>(); temp.put("imageid",imageid); temp.put("resid",resid); temp.put("name",name1); temp.put("sex",sex1); temp.put("bron",bron1); temp.put("where",where1); temp.put("country",country1); temp.put("txtid",txtid); CharactorActivity.charactor.remove(id); CharactorActivity.charactor.add(id,temp); CharactorActivity.adapter.notifyDataSetChanged(); ename.setFocusable(false); ebron.setFocusable(false); ecountry.setFocusable(false); esex.setFocusable(false); ewhere.setFocusable(false); einformation.setFocusable(false); } }).setNegativeButton("取消", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int pos) { flag = 0; button1.setVisibility(View.VISIBLE); button2.setVisibility(View.INVISIBLE); ename.setText(name); ebron.setText(bron); ewhere.setText(where); esex.setText(sex); ecountry.setText(country); einformation.setText(information); ename.setFocusable(false); ebron.setFocusable(false); ecountry.setFocusable(false); esex.setFocusable(false); ewhere.setFocusable(false); einformation.setFocusable(false); } }); builder.show(); } }); imageButton = (ImageButton)findViewById(R.id.musicbutton); Intent intent2 = new Intent(Charactor.this,MusicService.class); setAnimations(); startService(intent2); discAnimation.start(); imageButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(Charactor.this,MusicService.class); if(f==1){ discAnimation.end(); stopService(intent); f = 0; } else if(f==0){ discAnimation.start(); startService(intent); f = 1; } } }); } @Override protected void onStop() { // TODO Auto-generated method stub Intent intent = new Intent (Charactor.this,MusicService.class); stopService(intent); super.onStop(); } private void setAnimations() { discAnimation = ObjectAnimator.ofFloat(imageButton, "rotation", 0, 360); discAnimation.setDuration(10000); discAnimation.setInterpolator(new LinearInterpolator()); discAnimation.setRepeatCount(ValueAnimator.INFINITE); } @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { Charactor.super.onActivityResult(requestCode,resultCode,data); if(resultCode==RESULT_OK){ Uri uri = data.getData(); // adduri = uri; String picture = uri.toString(); imageView.setImageURI(Uri.parse(picture)); } } // public static String getRealFilePath( final Context context, final Uri uri ) { // if ( null == uri ) return null; // final String scheme = uri.getScheme(); // String data = null; // if ( scheme == null ) // data = uri.getPath(); // else if ( ContentResolver.SCHEME_FILE.equals( scheme ) ) { // data = uri.getPath(); // } else if ( ContentResolver.SCHEME_CONTENT.equals( scheme ) ) { // Cursor cursor = context.getContentResolver().query( uri, new String[] { MediaStore.Images.ImageColumns.DATA }, null, null, null ); // if ( null != cursor ) { // if ( cursor.moveToFirst() ) { // int index = cursor.getColumnIndex( MediaStore.Images.ImageColumns.DATA ); // if ( index > -1 ) { // data = cursor.getString( index ); // } // } // cursor.close(); // } // } // return data; // } }

_nrxsh LV12
6月16日
阿九11111 LV4
2024年5月21日
求学的熊猫 LV11
2024年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日

_nrxsh LV12
6月16日
5460545
2024年12月24日
暂无贡献等级
chenranr LV10
2024年12月20日
2636804923 LV6
2024年6月20日
AIWU1234 LV2
2024年6月9日
lilitu LV6
2024年5月29日
今晚都别睡啦 LV9
2024年5月29日
happySuperman LV2
2024年5月29日
阿九11111 LV4
2024年5月21日
Aban-beautiful
2024年5月13日
暂无贡献等级