@Override protected void onPause() { // unregister listener super.onPause(); if (!dbManager.isDatabaseClosed()) dbManager.closeDatabase(); sensorManager.unregisterListener(this); }
@Override public void onDestroy() { super.onDestroy(); handler.removeCallbacks(Update); sensorManager.unregisterListener(this); if (dbManager != null) dbManager.closeDatabase(); }
@Override protected void onResume() { super.onResume(); // register this class as a listener for the orientation and // accelerometer sensors if (dbManager == null) { dbManager = DatabaseManager.INSTANCE; dbManager.init(getApplicationContext()); } else if (dbManager.isDatabaseClosed()) { dbManager.init(getApplicationContext()); } sensorManager.registerListener( this, sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER), SensorManager.SENSOR_DELAY_NORMAL); }
@Override public void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.fullimageslider); db = new DatabaseHandler(this); dbManager = DatabaseManager.INSTANCE; dbManager.init(getApplicationContext()); getSupportActionBar().setDisplayHomeAsUpEnabled(true); options = new DisplayImageOptions.Builder() .showImageForEmptyUri(R.drawable.ic_launcher) .showImageOnFail(R.drawable.ic_launcher) .resetViewBeforeLoading(true) .cacheOnDisc(true) .imageScaleType(ImageScaleType.EXACTLY) .bitmapConfig(Bitmap.Config.RGB_565) .considerExifParams(true) .displayer(new FadeInBitmapDisplayer(300)) .build(); setTitle(Constant.CATEGORY_TITLE); // Look up the AdView as a resource and load a request. mAdView = (AdView) findViewById(R.id.adView); mAdView.loadAd(new AdRequest.Builder().build()); Intent i = getIntent(); position = i.getIntExtra("POSITION_ID", 0); mAllImages = i.getStringArrayExtra("IMAGE_ARRAY"); mAllImageCatName = i.getStringArrayExtra("IMAGE_CATNAME"); TOTAL_IMAGE = mAllImages.length - 1; viewpager = (ViewPager) findViewById(R.id.image_slider); handler = new Handler(); PinchZoomPageAdapter adapter = new PinchZoomPageAdapter(this, mAllImages, mAllImageCatName); viewpager.setAdapter(adapter); viewpager.setCurrentItem(position); sensorManager = (SensorManager) getSystemService(SENSOR_SERVICE); lastUpdate = System.currentTimeMillis(); mCountPage = 0; mInterstitial = new InterstitialAd(this); mInterstitial.setAdUnitId(getResources().getString(R.string.admob_publisher_id)); request = new AdRequest.Builder().addTestDevice("7F0E780CC56F3BA7C1CA7488A61F46BE").build(); mInterstitial.loadAd(request); mInterstitial.setAdListener( new AdListener() { @Override public void onAdClosed() { mInterstitial.loadAd(request); } }); viewpager.setOnPageChangeListener( new OnPageChangeListener() { @Override public void onPageSelected(int position) { // TODO Auto-generated method stub mCountPage++; Log.d("haipn", "page count:" + mCountPage); if (mCountPage >= 20) { if (mInterstitial.isLoaded()) { mInterstitial.show(); mCountPage = 0; } } position = viewpager.getCurrentItem(); Image_Url = mAllImages[position]; List<Pojo> pojolist = db.getFavRow(Image_Url); if (pojolist.size() == 0) { menu.getItem(3).setIcon(getResources().getDrawable(R.drawable.fav)); } else { if (pojolist.get(0).getImageurl().equals(Image_Url)) { menu.getItem(3).setIcon(getResources().getDrawable(R.drawable.fav_hover)); } } } @Override public void onPageScrolled(int arg0, float arg1, int position) { // TODO Auto-generated method stub } @Override public void onPageScrollStateChanged(int position) { // TODO Auto-generated method stub } }); }