@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.main); /*read settings*/ settings = getSharedPreferences(PREFS_NAME, 0); boolean hide = settings.getBoolean(PREFS_HIDDEN, false); int color = settings.getInt(PREFS_COLOR, -1); flmg = new FileManager(); flmg.setShowHiddenFiles(hide); handler = new EventHandler(Main.this, flmg); handler.setTextColor(color); table = handler.new TableRow(); /*sets the ListAdapter for our ListActivity and *gives our EventHandler class the same adapter */ handler.setListAdapter(table); setListAdapter(table); /* register context menu for our list view */ registerForContextMenu(getListView()); path_label = (TextView) findViewById(R.id.path_label); detail_label = (TextView) findViewById(R.id.detail_label); path_label.setText("path: /sdcard"); handler.setUpdateLabel(path_label, detail_label); ImageButton help_b = (ImageButton) findViewById(R.id.help_button); help_b.setOnClickListener(handler); ImageButton home_b = (ImageButton) findViewById(R.id.home_button); home_b.setOnClickListener(handler); ImageButton back_b = (ImageButton) findViewById(R.id.back_button); back_b.setOnClickListener(handler); ImageButton info_b = (ImageButton) findViewById(R.id.info_button); info_b.setOnClickListener(handler); ImageButton manage_b = (ImageButton) findViewById(R.id.manage_button); manage_b.setOnClickListener(handler); ImageButton multi_b = (ImageButton) findViewById(R.id.multiselect_button); multi_b.setOnClickListener(handler); ImageButton operation_b = (ImageButton) findViewById(R.id.multioperation_button); operation_b.setOnClickListener(handler); }
@Override public void onCreate(Bundle savedInstanceState) { ThemeUtils.onActivityCreateSetTheme(this); super.onCreate(savedInstanceState); setContentView(R.layout.import_zip_main); mContext = this; /* read settings */ mSettings = getSharedPreferences(PREFS_NAME, 0); int sort = mSettings.getInt(PREFS_SORT, 2); mFileMag = new FileManager(); mFileMag.setSortType(sort); if (savedInstanceState != null) mHandler = new EventHandler( FileImportActivity.this, mFileMag, savedInstanceState.getString("location")); else mHandler = new EventHandler(FileImportActivity.this, mFileMag); mTable = mHandler.new TableRow(); /* * sets the ListAdapter for our ListActivity andgives our EventHandler * class the same adapter */ mHandler.setListAdapter(mTable); setListAdapter(mTable); /* register context menu for our list view */ registerForContextMenu(getListView()); mPathLabel = (TextView) findViewById(R.id.path_label); mPathLabel.setText("path: /sdcard"); setTitle(R.string.import_title); getSupportActionBar() .setDisplayOptions( ActionBar.DISPLAY_HOME_AS_UP | ActionBar.DISPLAY_SHOW_TITLE | ActionBar.DISPLAY_SHOW_HOME); }
/** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); /* 清除共享区内的信息 */ SharedPreferences pf = getSharedPreferences("partition", 0); SharedPreferences.Editor editor = pf.edit(); editor.clear(); mMedia = new MediaProvider(this); mDevices = new DeviceManager(this); mHandler = new EventHandler(this, this, mMedia, mDevices); mTable = mHandler.new TableRow(); mMenuListener = mHandler.new MenuItemListener(); /* 设置信息预览栏内容 */ mThumb = (LinearLayout) findViewById(R.id.thumb); mVideo = (SurfaceView) findViewById(R.id.thumb_movie); mImage = (ImageView) findViewById(R.id.thumbnail); Drawable bp = getResources().getDrawable(R.drawable.thumbnail_equipment); Bitmap m = ((BitmapDrawable) bp).getBitmap(); mPreview = (TextView) findViewById(R.id.preview); mPath = (TextView) findViewById(R.id.path); mIndex = (TextView) findViewById(R.id.index); mHandler.setViewResource(mVideo, mImage, mPreview, mPath, mIndex); /* 把ListView 与 TableRow 绑定,并监听items的被选中事件 */ list = getListView(); mHandler.setListAdapter(mTable, list); list.setAdapter(mTable); list.setOnItemSelectedListener(mHandler); list.setOnItemClickListener(mHandler); list.setOnItemLongClickListener(mHandler); /* 设置监听导航栏的菜单item */ Button devices = (Button) findViewById(R.id.device_button); Button video = (Button) findViewById(R.id.video_button); Button picture = (Button) findViewById(R.id.picture_button); Button music = (Button) findViewById(R.id.music_button); Button file = (Button) findViewById(R.id.file_button); devices.setOnClickListener(mHandler); video.setOnClickListener(mHandler); picture.setOnClickListener(mHandler); music.setOnClickListener(mHandler); file.setOnClickListener(mHandler); /* 读取传进来的参数决定过滤类型 */ Bundle b = getIntent().getExtras(); if (b != null) { String action = b.getString("media_type"); if (action != null) { if (action.equals("MEDIA_TYPE_MUSIC")) { mHandler.setFilterType(mMedia.MUSIC_FILTER); music.performClick(); } else if (action.equals("MEDIA_TYPE_PICTURE")) { mHandler.setFilterType(mMedia.PICTURE_FILTER); picture.performClick(); } else if (action.equals("MEDIA_TYPE_VIDEO")) { mHandler.setFilterType(mMedia.MOVIE_FILTER); video.performClick(); } else if (action.equals("MEDIA_TYPE_ALL")) { mHandler.setFilterType(mMedia.ALLTYPE_FILTER); file.performClick(); } else { devices.performClick(); } } else { Log.d(TAG, "started by other parames"); devices.performClick(); } } else { devices.performClick(); } /* 设置option菜单栏信息 */ createMenu(); /* 增加热插拔功能 */ mReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { String tmpstring = intent.getData().getPath(); Log.d(TAG, "devices path:" + tmpstring); if (intent.getAction().equals(intent.ACTION_MEDIA_REMOVED) || intent.getAction().equals(intent.ACTION_MEDIA_BAD_REMOVAL)) { /* 等待1秒钟再刷新界面,这是因为底层发出卸载信号时,有时实际上还没卸载掉设备 */ try { Thread.currentThread().sleep(500); } catch (Exception e) { } ; if (mHandler.currentDir.startsWith(tmpstring) || mHandler.isDeviceList()) { showDeviceList(); } if (mDevices.isInterStoragePath(tmpstring)) { // DisplayToast(getResources().getString(R.string.flash_out)); } else if (mDevices.isSdStoragePath(tmpstring)) { DisplayToast(getResources().getString(R.string.sdcard_out)); } else if (mDevices.isUsbStoragePath(tmpstring)) { DisplayToast(getResources().getString(R.string.usb_out)); } } else if (intent.getAction().equals(intent.ACTION_MEDIA_MOUNTED)) { if (mHandler.isDeviceList()) { showDeviceList(); } if (mDevices.isInterStoragePath(tmpstring)) { // DisplayToast(getResources().getString(R.string.flash_in)); } else if (mDevices.isSdStoragePath(tmpstring)) { DisplayToast(getResources().getString(R.string.sdcard_in)); } else if (mDevices.isUsbStoragePath(tmpstring)) { DisplayToast(getResources().getString(R.string.usb_in)); } } } }; IntentFilter filter = new IntentFilter(); filter.addAction(Intent.ACTION_MEDIA_MOUNTED); filter.addAction(Intent.ACTION_MEDIA_REMOVED); filter.addAction(Intent.ACTION_MEDIA_BAD_REMOVAL); filter.addDataScheme("file"); registerReceiver(mReceiver, filter); if (getIntent().getAction() != null) { if (getIntent().getAction().equals("com.softwinner.action.GET_FILE")) { returnFile = true; } } }