文件名称:csnd版android
文件大小:3.84MB
文件格式:ZIP
更新时间:2018-08-01 05:38:41
csdn
setContentView(R.layout.main); frameLayout = (FrameLayout) findViewById(R.id.dialogfram); (((ViewGroup) findViewById(android.R.id.content)).getChildAt(0)).setBackgroundColor(Color.parseColor("#ff121111")); // //hide the actionBar getActionBar().hide(); setupMenu(); cache = ACache.get(MainActivity.this); boolean isConn = NetUtil.checkNet(MainActivity.this); if (isConn) { // Log.i("ht","has conn========"); }else{ // Log.i("ht","no conn========"); FrameLayout frameLayout = (FrameLayout) findViewById(R.id.dialogfram); frameLayout.setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View arg0, MotionEvent arg1) { // TODO Auto-generated method stub return true; } }); frameLayout.setVisibility(View.VISIBLE); TextView textOk = (TextView) findViewById(R.id.dialogfram).findViewById(R.id.ok); TextView textCancel = (TextView) findViewById(R.id.dialogfram).findViewById(R.id.cancle); textOk.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { // Log.d("html","====textOk====="); Intent intent = new Intent(Settings.ACTION_SETTINGS); startActivity(intent); findViewById(R.id.dialogfram).setVisibility(View.GONE); } }); textCancel.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { // Log.d("html","====textCancel====="); findViewById(R.id.dialogfram).setVisibility(View.GONE); } }); } sensorManager = (SensorManager) getSystemService(SENSOR_SERVICE); vibrator = (Vibrator) getSystemService(Service.VIBRATOR_SERVICE); changeFragment(new CloudFragment()); // ImageView imageShare = (ImageView) findViewById(R.id.action_bar_id).findViewById(R.id.share_image); imageShare.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { } }); } private void setupMenu(){ mResideMenu = new ResideMenu(this); mResideMenu.setBackground(R.drawable.menu_background);//设置北京图片 mResideMenu.attachToActivity(this); mResideMenu.setMenuListener(mMenuListener); mResideMenu.setScaleValue(0.4f); mMenu_name = getResources().getStringArray(R.array.menu_array); this.mMenu_cloud = new ResideMenuItem(this, R.drawable.mojitip_17, mMenu_name[0]); this.mMenu_mobile = new ResideMenuItem(this, R.drawable.mojitip_13, mMenu_name[1]); this.mMenu_industry = new ResideMenuItem(this, R.drawable.mojitip_14, mMenu_name[2]); this.mMenu_magzine = new ResideMenuItem(this, R.drawable.mojitip_15, mMenu_name[3]); this.mMenu_blog = new ResideMenuItem(this,R.drawable.mojitip_16,mMenu_name[4]); this.mMenu_save = new ResideMenuItem(this,R.drawable.mojitip_24,mMenu_name[5]); this.mMenu_settings = new ResideMenuItem(this,R.drawable.mojitip_26,mMenu_name[6]); this.mMenu_exit = new ResideMenuItem(this,R.drawable.exit,mMenu_name[7]); this.mMenu_cloud.setOnClickListener(this); this.mMenu_industry.setOnClickListener(this); this.mMenu_magzine.setOnClickListener(this); this.mMenu_mobile.setOnClickListener(this); this.mMenu_blog.setOnClickListener(this); this.mMenu_settings.setOnClickListener(this); this.mMenu_save.setOnClickListener(this); this.mMenu_exit.setOnClickListener(this); mResideMenu.addMenuItem(mMenu_cloud, ResideMenu.DIRECTION_LEFT); mResideMenu.addMenuItem(mMenu_mobile, ResideMenu.DIRECTION_LEFT); mResideMenu.addMenuItem(mMenu_industry, ResideMenu.DIRECTION_LEFT); mResideMenu.addMenuItem(mMenu_magzine, ResideMenu.DIRECTION_LEFT); mResideMenu.addMenuItem(mMenu_blog, ResideMenu.DIRECTION_LEFT); mResideMenu.addMenuItem(mMenu_save,ResideMenu.DIRECTION_LEFT); mResideMenu.addMenuItem(mMenu_settings,ResideMenu.DIRECTION_LEFT); mResideMenu.addMenuItem(mMenu_exit,ResideMenu.DIRECTION_LEFT); ImageView toggleIv = (ImageView) findViewById(R.id.openMenuBtn); //open menu toggleIv.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { mResideMenu.openMenu(ResideMenu.DIRECTION_LEFT); } }); //set default title this.setActionBarTitle(mMenu_name[0]); } @Override public boolean dispatchTouchEvent(MotionEvent ev) { return mResideMenu.dispatchTouchEvent(ev); } private ResideMenu.OnMenuListener mMenuListener = new ResideMenu.OnMenuListener() { @Override public void openMenu() { // Toast.makeText(MainActivity.this, "Menu is opened!", Toast.LENGTH_SHORT).show(); } @Override public void closeMenu() { // Toast.makeText(MainActivity.this, "Menu is closed!", Toast.LENGTH_SHORT).show(); } }; private void changeFragment(Fragment targetFragment){ frameLayout.setVisibility(View.GONE); mResideMenu.clearIgnoredViewList(); getSupportFragmentManager() .beginTransaction() .replace(R.id.main_fragment, targetFragment, "fragment") .setTransitionStyle(FragmentTransaction.TRANSIT_FRAGMENT_FADE) .commit(); } /** * set title * @param title title name */ public void setActionBarTitle(String title){ TextView titleTv = (TextView) findViewById(R.id.title); titleTv.setText(title); System.out.println("title:"+titleTv.getText().toString()); } @Override public void onClick(View view) { if (view == mMenu_cloud){ setActionBarTitle(mMenu_name[0]); changeFragment(new CloudFragment()); }else if (view == mMenu_industry){ setActionBarTitle(mMenu_name[2]); changeFragment(new IndustryFragment()); }else if (view == mMenu_magzine){ setActionBarTitle(mMenu_name[3]); changeFragment(new Magzine()); }else if (view == mMenu_mobile){ setActionBarTitle(mMenu_name[1]); changeFragment(new Mobile()); }else if (view == mMenu_blog){ setActionBarTitle(mMenu_name[4]); changeFragment(new SoftDevFragment()); }else if (view == mMenu_settings){ setActionBarTitle(mMenu_name[6]); changeFragment(new SettingFragment()); }else if (view == mMenu_save) { setActionBarTitle(mMenu_name[5]); changeFragment(new MySaveFragment()); }else if (view == mMenu_exit) { TextView textTitle = (TextView) frameLayout.findViewById(R.id.title); TextView textSure = (TextView) frameLayout.findViewById(R.id.delete); TextView textOk = (TextView) frameLayout.findViewById(R.id.ok); TextView textCancel = (TextView) frameLayout.findViewById(R.id.cancle); textTitle.setText("确定退出"); textSure.setVisibility(View.GONE); frameLayout.setVisibility(View.VISIBLE); textOk.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { MainActivity.this.finish(); } }); textCancel.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { frameLayout.setVisibility(View.GONE); } }); }