import com.example.zhoukaoyimini.R;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.AlphaAnimation;
import android.view.animation.AnimationSet;
import android.view.animation.ScaleAnimation;
import android.view.animation.TranslateAnimation;
import android.widget.ImageView;
public class FragmentThree extends Fragment{
private ImageView iv3;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view=View.inflate(getActivity(), R.layout.fragmentthree, null);
iv3 = (ImageView) view.findViewById(R.id.iv3);
AnimationSet as=new AnimationSet(true);
AlphaAnimation aa=new AlphaAnimation(0f,1f);
aa.setDuration(2000);
TranslateAnimation ta=new TranslateAnimation(0,100,0,200);
ta.setDuration(2000);
ScaleAnimation sa=new ScaleAnimation(0.1f,1.0f,0.1f,1.0f,0.5f,0.5f);
sa.setDuration(2000);
as.addAnimation(aa);
as.addAnimation(ta);
as.addAnimation(sa);
as.setDuration(6000);
iv3.startAnimation(as);
return view;
}
}
========================================
package com.example.zhoukaoyimini;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;
import android.app.Application;
public class App extends Application{
@Override
public void onCreate() {
super.onCreate();
ImageLoaderConfiguration configuration=ImageLoaderConfiguration.createDefault(this);
ImageLoader.getInstance().init(configuration);
}
}
=======================================
package com.example.zhoukaoyimini;
import java.util.ArrayList;
import java.util.List;
import com.example.zhoukaoyiminiFragment.FragmentThree;
import com.example.zhoukaoyiminiFragment.FragmentTwo;
import com.example.zhoukaoyiminiFragment.Fragmentone;
import android.os.Bundle;
import android.os.Handler;
import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v4.view.ViewPager.OnPageChangeListener;
import android.text.format.Time;
import android.view.Menu;
public class MainActivity extends FragmentActivity {
private ViewPager vp;
private List<Fragment> list;
private SharedPreferences spf;
SharedPreferences.Editor editor;
Handler handler=new Handler();
int time=4;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
vp = (ViewPager) findViewById(R.id.vp);
list = new ArrayList<Fragment>();
list.add(new Fragmentone());
list.add(new FragmentTwo());
list.add(new FragmentThree());
MyvpAdapter adapter=new MyvpAdapter(getSupportFragmentManager());
vp.setAdapter(adapter);
spf = getSharedPreferences("jizhu", MODE_PRIVATE);
editor=spf.edit();
boolean flag=spf.getBoolean("flag", false);
if (flag) {
Intent intent = new Intent(MainActivity.this,OtherActivity.class);
startActivity(intent);
}
vp.setOnPageChangeListener(new OnPageChangeListener() {
@Override
public void onPageSelected(int arg0) {
// TODO Auto-generated method stub
switch (arg0) {
case 0:
break;
case 1:
break;
case 2:
editor.putBoolean("flag", true);
editor.commit();
handler.postDelayed(new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
time--;
if (time==-1) {
Intent intent = new Intent(MainActivity.this,OtherActivity.class);
startActivity(intent);
finish();
}
handler.postDelayed(this,1000);
}
}, 1000);
break;
default:
break;
}
}
@Override
public void onPageScrolled(int arg0, float arg1, int arg2) {
// TODO Auto-generated method stub
}
@Override
public void onPageScrollStateChanged(int arg0) {
// TODO Auto-generated method stub
}
});
}
class MyvpAdapter extends FragmentPagerAdapter{
public MyvpAdapter(FragmentManager fm) {
super(fm);
// TODO Auto-generated constructor stub
}
@Override
public Fragment getItem(int arg0) {
// TODO Auto-generated method stub
return list.get(arg0);
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return list.size();
}}
}
=====================================
package com.example.zhoukaoyimini;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import android.app.Activity;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
import com.example.zhoukaoyiminiBean.GetData;
import com.google.gson.Gson;
import com.nostra13.universalimageloader.core.ImageLoader;
public class OtherActivity extends Activity {
private ListView lv;
private MylistAdapter listadapter;
GetData data;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.otheractivity);
lv = (ListView) findViewById(R.id.lv);
initData();
listadapter = new MylistAdapter();
lv.setAdapter(listadapter);
}
class MylistAdapter extends BaseAdapter{
@Override
public int getCount() {
// TODO Auto-generated method stub
if (data!=null) {
return data.toString().length();
}
return 0;
}
@Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return null;
}
@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return 0;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
ViewHolder holder;
if(convertView==null){
convertView=View.inflate(OtherActivity.this,R.layout.list_item,null);
holder=new ViewHolder();
holder.til=(TextView) convertView.findViewById(R.id.til);
holder.name=(TextView) convertView.findViewById(R.id.name);
holder.ima=(ImageView) convertView.findViewById(R.id.ima);
convertView.setTag(holder);
}else
{
holder= (ViewHolder) convertView.getTag();
}
holder.til.setText(data.getData().get(position).getNews_title());
holder.name.setText(data.getData().get(position).getNews_summary());
ImageLoader.getInstance().displayImage(data.getData().get(position).getPic_url(),holder.ima);
return convertView;
}
}
static class ViewHolder{
TextView til;
TextView name;
ImageView ima;
}
private void initData() {
// TODO Auto-generated method stub
new AsyncTask<String,String,String>(){
@Override
protected String doInBackground(String... strings) {
String result = getdata();
return result;
}
@Override
protected void onPostExecute(String result) {
Gson gson=new Gson();
data = gson.fromJson(result, GetData.class);
listadapter.notifyDataSetChanged();
super.onPostExecute(result);
}
}.execute();
}
private String getdata() {
String result="";
try {
URL url=new URL("http://api.expoon.com/AppNews/getNewsList/type/1/p/1");
HttpURLConnection con= (HttpURLConnection) url.openConnection();
con.setRequestMethod("GET");
con.setConnectTimeout(5000);
con.setReadTimeout(5000);
int code=con.getResponseCode();
if(code==200)
{
InputStream is=con.getInputStream();
ByteArrayOutputStream bos=new ByteArrayOutputStream();
byte[] buff=new byte[1024];
int len=-1;
while((len=is.read(buff))!=-1){
bos.write(buff,0,len);
}
result=new String(bos.toByteArray());
}
} catch (Exception e) {
e.printStackTrace();
}
return result;
}
}