Java tutorial
/* * Copyright 2010 Sony Ericsson Mobile Communications AB * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.sonyericsson.demo; import android.app.Activity; import android.content.pm.ActivityInfo; import android.os.Bundle; import android.support.v4.view.ViewPager; import android.support.v4.view.ViewPager.OnPageChangeListener; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.view.View.OnLongClickListener; import android.view.Window; import android.view.WindowManager; import android.widget.TextView; import android.widget.Toast; /** * Activity for zoom tutorial 1 */ public class Demo extends Activity implements OnLongClickListener, OnPageChangeListener { private ViewPager vp; private ViewPagerAdapter vpAdapter; // pagination navigator current position private TextView m_tv; private int m_imageIdx; // image sources private static final int[] m_pics = { R.drawable.ballon, R.drawable.tintin1, R.drawable.tintin2 }; /** Constant used as menu item id for resetting zoom state */ @Override public void onCreate(Bundle savedInstanceState) { requestWindowFeature(Window.FEATURE_NO_TITLE); getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); super.onCreate(savedInstanceState); setContentView(R.layout.main); // get page indicator textview m_tv = (TextView) findViewById(R.id.full_image_indicator); vp = (ViewPager) findViewById(R.id.viewpager); vpAdapter = new ViewPagerAdapter(m_pics, this); vp.setAdapter(vpAdapter); vp.setOnPageChangeListener(this); vp.setCurrentItem(m_imageIdx); setCurIndicator(m_imageIdx); setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR); } /** * set current page indicator "N/M" */ private void setCurIndicator(int position) { m_imageIdx = position; String pos = String.format("%s/%s", position + 1, m_pics.length); m_tv.setText(pos); } @Override public void onPause() { super.onPause(); // Kill when pressing home key. this.finish(); } @Override protected void onDestroy() { super.onDestroy(); } @Override public boolean onCreateOptionsMenu(Menu menu) { return super.onCreateOptionsMenu(menu); } @Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { default: break; } return super.onOptionsItemSelected(item); } @Override public boolean onLongClick(View v) { // TODO Auto-generated method stub Toast.makeText(getApplicationContext(), "On Long Click", Toast.LENGTH_SHORT).show(); return true; } @Override public void onPageScrollStateChanged(int arg0) { // TODO Auto-generated method stub } @Override public void onPageScrolled(int arg0, float arg1, int arg2) { // TODO Auto-generated method stub } @Override public void onPageSelected(int arg0) { setCurIndicator(arg0); } }