Back to project page SimpleReader.
The source code is released under:
Apache License
If you think the Android project SimpleReader listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.dreamteam.app.ui; /*from w w w. ja va 2s .co m*/ import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; import java.util.List; import android.app.Activity; import android.database.sqlite.SQLiteDatabase; import android.os.Bundle; import android.support.v4.view.ViewPager; import android.support.v4.view.ViewPager.OnPageChangeListener; import android.view.LayoutInflater; import android.view.View; import android.widget.ImageView; import android.widget.LinearLayout; import com.dreamteam.app.adapter.GuideViewPagerAdapter; import com.dreamteam.app.commons.AppConfig; import com.dreamteam.app.commons.AppContext; import com.dreamteam.app.db.FeedDBManager; import com.dreateam.app.ui.R; /** * * @{# GuideActivity.java Create on 2013-5-2 ????10:59:08 * * class desc: ????????????????? * * <p> * Copyright: Copyright(c) 2013 * </p> * @Version 1.0 * @Author <a href="mailto:gaolei_xj@163.com">Leo</a> * * */ public class GuideActivity extends Activity implements OnPageChangeListener { private ViewPager vp; private GuideViewPagerAdapter vpAdapter; private List<View> views; // ??????? private ImageView[] dots; // ?????????? private int currentIndex; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.guide); // ???????? initViews(); // ????????? initDots(); writeDB(); //??????????? writeSaveDaysFile(); //?????????? AppContext.clearSdCache(); } private void writeSaveDaysFile() { String fileName = getFilesDir().getAbsolutePath() + File.separator + AppConfig.PREF_DEPRECATED; File file = new File(fileName); try { file.createNewFile(); } catch (IOException e) { e.printStackTrace(); } } private void writeDB() { InputStream inputStream = null; try { inputStream = getAssets().open("feed.db"); FeedDBManager helper = new FeedDBManager(this, FeedDBManager.DB_NAME, null, 1); SQLiteDatabase db = helper.getWritableDatabase(); File dbFile = new File(db.getPath()); if(dbFile.exists()) { dbFile.delete(); } FileOutputStream fos = null; try { fos = new FileOutputStream(dbFile); byte buffer[] = new byte[1024 * 4]; while((inputStream.read(buffer)) != -1) { fos.write(buffer); } } catch(FileNotFoundException e) { e.printStackTrace(); } catch(IOException e) { e.printStackTrace(); } finally { try { if(inputStream != null) { inputStream.close(); inputStream = null; } if(fos != null) { fos.close(); fos = null; } } catch (IOException e) { e.printStackTrace(); } db.close(); } } catch(IOException e) { e.printStackTrace(); } } private void initViews() { LayoutInflater inflater = LayoutInflater.from(this); views = new ArrayList<View>(); // ?????????? views.add(inflater.inflate(R.layout.what_new_one, null)); views.add(inflater.inflate(R.layout.what_new_two, null)); views.add(inflater.inflate(R.layout.what_new_three, null)); views.add(inflater.inflate(R.layout.what_new_four, null)); // ????Adapter vpAdapter = new GuideViewPagerAdapter(views, this); vp = (ViewPager) findViewById(R.id.viewpager); vp.setAdapter(vpAdapter); // ???? vp.setOnPageChangeListener(this); } private void initDots() { LinearLayout ll = (LinearLayout) findViewById(R.id.ll); dots = new ImageView[views.size()]; // ??????????? for (int i = 0; i < views.size(); i++) { dots[i] = (ImageView) ll.getChildAt(i); dots[i].setEnabled(true);// ??????? } currentIndex = 0; dots[currentIndex].setEnabled(false);// ?????????????? } private void setCurrentDot(int position) { if (position < 0 || position > views.size() - 1 || currentIndex == position) { return; } dots[position].setEnabled(false); dots[currentIndex].setEnabled(true); currentIndex = position; } // ????????????? @Override public void onPageScrollStateChanged(int arg0) { } // ?????????????? @Override public void onPageScrolled(int arg0, float arg1, int arg2) { } // ????????????? @Override public void onPageSelected(int arg0) { // ???????????? setCurrentDot(arg0); } }