功能分类:影音
支持平台:Android
运行环境:Android
开发语言:Java
开发工具:Eclipse
源码大小:8.54MB
源码下载地址:http://down.51cto.com/data/1976551
源码简介
适合新手学习的多合一播放器。
源码运行截图
运行截图
运行截图
运行截图
运行截图
运行截图
运行截图
源码片段
- public class Main extends Activity implements OnClickListener{
- private Button btn1,btn2,btn3;
- private boolean isExit;
- private SharedPreferences sp;
- private Editor et;
- private FrameLayout fldetails;
- private Set<string> ePathSet;
- private Set<string> vPathSet;
- private Set<string> mPathSet;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- requestWindowFeature(Window.FEATURE_NO_TITLE);
- setContentView(R.layout.main);
- sp = getSharedPreferences(Tool.SP_MYSHAREDPREFERENCES, MODE_PRIVATE);
- et = sp.edit();
- ePathSet = new HashSet<string>();
- vPathSet = new HashSet<string>();
- mPathSet = new HashSet<string>();
- init();
- Tool.logd("★★★★★"+sp.getBoolean(Tool.SP_ISINITPATH, false));
- fldetails = (FrameLayout) findViewById(R.id.flDetails);
- btn1 = (Button) findViewById(R.id.btn1);
- btn2 = (Button) findViewById(R.id.btn2);
- btn3 = (Button) findViewById(R.id.btn3);
- btn1.setOnClickListener(this);
- btn2.setOnClickListener(this);
- btn3.setOnClickListener(this);
- FragmentTransaction ft = getFragmentManager().beginTransaction();
- EbookFragment ebook = new EbookFragment();
- ft.replace(R.id.flDetails, ebook);
- ft.commit();
- fldetails.setBackgroundResource(R.drawable.ebook_bg);
- }
- private void init() {
- // TODO Auto-generated method stub
- boolean isInitPath = sp.getBoolean(Tool.SP_ISINITPATH, false);
- if(!isInitPath){
- String[] e_paths = Tool.getPathByXml(this, Tool.EBOOK);
- String[] v_paths = Tool.getPathByXml(this, Tool.VIDEO);
- String[] m_paths = Tool.getPathByXml(this, Tool.MUSIC);
- for(String path : e_paths){
- ePathSet.add(path);
- }
- for(String path : v_paths){
- vPathSet.add(path);
- }
- for(String path : m_paths){
- mPathSet.add(path);
- }
- et.putStringSet("ebook_path", ePathSet);
- et.putStringSet("video_path", vPathSet);
- et.putStringSet("music_path", mPathSet);
- et.putBoolean("isInitPath", true);
- et.commit();
- }
- }
- @Override
- public boolean onCreateOptionsMenu(Menu menu) {
- // Inflate the menu; this adds items to the action bar if it is present.
- setIconEnable(menu, true);
- getMenuInflater().inflate(R.menu.main, menu);
- return true;
- }
- private void setIconEnable(Menu menu, boolean b) {
- // TODO Auto-generated method stub
- try {
- Class<!--?--> clazz = Class.forName("com.android.internal.view.menu.MenuBuilder");
- Method m = clazz.getDeclaredMethod("setOptionalIconsVisible", boolean.class);
- m.setAccessible(true);
- m.invoke(menu, b);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- @Override
- public boolean onOptionsItemSelected(MenuItem item) {
- // TODO Auto-generated method stub
- super.onOptionsItemSelected(item);
- switch(item.getItemId()){
- case R.id.add_ebook:
- et.putInt(Tool.SP_TYPE, Tool.EBOOK);
- et.commit();
- Intent intent = new Intent(Main.this,AddingPath.class);
- startActivity(intent);
- overridePendingTransition(android.R.anim.slide_in_left, android.R.anim.slide_out_right);
- break;
- case R.id.add_video:
- et.putInt(Tool.SP_TYPE, Tool.VIDEO);
- et.commit();
- Intent intent1 = new Intent(Main.this,AddingPath.class);
- startActivity(intent1);
- overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out);
- break;
- case R.id.add_music:
- et.putInt(Tool.SP_TYPE, Tool.MUSIC);
- Intent intent2 = new Intent(Main.this,AddingPath.class);
- startActivity(intent2);
- et.commit();
- break;
- case R.id.setting:
- Intent intent3 = new Intent(Main.this,PreferenceSetting.class);
- startActivity(intent3);
- break;
- case R.id.baidu:
- Uri uri = Uri.parse("http://www.baidu.com");
- Intent intent4 = new Intent(Intent.ACTION_VIEW,uri);
- startActivity(intent4);
- break;
- case R.id.about:
- showAuthorDetail();
- break;
- case R.id.exit:
- System.exit(0);
- break;
- }
- return true;
- }
- private void showAuthorDetail() {
- // TODO Auto-generated method stub
- Builder bd = new Builder(this);
- bd.setTitle("关于我们");
- bd.setMessage("版本: 1.0 \n开发者:袁野 \n开发时间:2014-05-16");
- bd.show();
- }
- @Override
- public void onClick(View v) {
- FragmentTransaction ft = getFragmentManager().beginTransaction();
- switch(v.getId()){
- case R.id.btn1:
- EbookFragment ebook = new EbookFragment();
- ft.replace(R.id.flDetails, ebook);
- ft.commit();
- fldetails.setBackgroundResource(R.drawable.ebook_bg);
- break;
- case R.id.btn2:
- VideoFragment video = new VideoFragment();
- ft.replace(R.id.flDetails,video);
- ft.commit();
- fldetails.setBackgroundResource(R.drawable.movie_bg);
- break;
- case R.id.btn3:
- MusicFragment music = new MusicFragment();
- ft.replace(R.id.flDetails, music);
- ft.commit();
- fldetails.setBackgroundResource(R.drawable.music_bg1);
- break;
- }
- }
- @Override
- public boolean onKeyDown(int keyCode, KeyEvent event) {
- if(keyCode == KeyEvent.KEYCODE_BACK)
- {
- exitBy2Click(); //调用双击退出函数
- }
- return false;
- }
- private void exitBy2Click() {
- Timer tExit = null;
- if (isExit == false) {
- isExit = true; // 准备退出
- Toast.makeText(this, "再按一次退出程序", Toast.LENGTH_SHORT).show();
- tExit = new Timer();
- tExit.schedule(new TimerTask() {
- @Override
- public void run() {
- isExit = false; // 取消退出
- }
- }, 2000); // 如果2秒钟内没有按下返回键,则启动定时器取消掉刚才执行的任务
- } else {
- finish();
- }
- }
- }</string></string></string></string></string></string>