package com.exmple.jinritoutiao;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
import com.exmple.apa.BaseApalistce;
import com.exmple.apa.MyFrgAdapter;
import com.exmple.frage.Fragment_1;
import com.exmple.frage.Fragment_2;
import com.exmple.help.MyHelp;
import com.exmple.jinritoutiao.R;
import com.exmple.listvo.ListVo;
import com.slidingmenu.lib.SlidingMenu;
import Night1.Night;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.view.ViewPager;
import android.support.v4.view.ViewPager.OnPageChangeListener;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.WindowManager;
import android.widget.HorizontalScrollView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.database.sqlite.SQLiteDatabase;
import android.graphics.Color;
public class FuctionActivity extends FragmentActivity implements
OnClickListener {
/** 自定义HorizontalScrollView */
private HorizontalScrollView scvi;
LinearLayout line;
LinearLayout ll_more_columns;
RelativeLayout rl_column;
private ViewPager mViewPager;
private ImageView button_more_columns;
/** 新闻分类列表 */
/** 当前选中的栏目 */
int wit;
private List<TextView> tv_list;
private List<Fragment> listf;
public static boolean blFlag = false;
// 侧滑左侧的图片
int[] imageview = new int[] { R.drawable.dynamicicon_leftdrawer,
R.drawable.topicicon_leftdrawer,
R.drawable.ic_action_favor_on_pressed,
R.drawable.activityicon_leftdrawer,
R.drawable.sellicon_leftdrawer,
R.drawable.feedbackicon_leftdrawer, };
// 侧滑左侧的图片
String[] name = new String[] { "好友动态", "我的话题", "收藏", "活动", "商城", "反馈" };
private String[] columnData1 = new String[] { "推荐", "视频", "社会", "娱乐", "科技",
"汽车", "体育", "军事", "美女", "趣图" };
public static String str;
public static ImageView image;
private SlidingMenu menu;
private ListView listview;
private List<ListVo> list2;
private TextView text;
public static WindowManager window;
private SharedPreferences sp;
private final static String DAY = "day";
private final static String NIGHT = "night";
private Night nig;
private Editor ed;
private SQLiteDatabase sql;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_fuction);
MyHelp myHelp = new MyHelp(FuctionActivity.this, "navs", null, 1);
sql = myHelp.getWritableDatabase();
// private int flage = 0;
window = (WindowManager) getSystemService(Context.WINDOW_SERVICE);
// 加载布局文件
initView();
// 得到屏幕的宽度
WindowManager wm = getWindowManager();
wit = wm.getDefaultDisplay().getWidth();
// 找到图片
image = (ImageView) findViewById(R.id.top_head);
// 侧滑的方法
getSlidemenu();
listview = (ListView) findViewById(R.id.listview);
getImage();
getfra();
// horscoiview的配置
tv_list = new ArrayList<TextView>();
for (int i = 0; i < columnData1.length; i++) {
TextView text = new TextView(FuctionActivity.this);
text.setPadding(20, 10, 20, 10);
text.setText(columnData1[i]);
line.addView(text);
tv_list.add(text);
text.setTag(i);
text.setOnClickListener(this);
sql.execSQL("insert into nav values (?,?)", new String[] { null,
columnData1[i] });
}
BaseApalistce ba = new BaseApalistce(FuctionActivity.this, list2);
listview.setAdapter(ba);
FragmentManager fm = getSupportFragmentManager();
mViewPager.setAdapter(new MyFrgAdapter(fm, listf));
mViewPager.setCurrentItem(0);
setQTextColor(0);
mViewPager.setOnPageChangeListener(new OnPageChangeListener() {
@Override
public void onPageSelected(int arg0) {
setQTextColor(arg0);
}
@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
}
});
}
private void getSlidemenu() {
menu = new SlidingMenu(FuctionActivity.this);
menu.setMode(SlidingMenu.LEFT);
/* menu.setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN); */
// menu.setTouchModeAbove(SlidingMenu.SLIDING_WINDOW);
menu.setTouchModeAbove(SlidingMenu.TOUCHMODE_MARGIN);
// 设置策划的宽度
menu.setShadowWidth(200);
menu.setBehindOffset(150);
// 绑定Activity
menu.attachToActivity(this, SlidingMenu.SLIDING_CONTENT);
menu.setFadeDegree(0.35f);
menu.setMenu(R.layout.cehua);
ImageView setting = (ImageView) findViewById(R.id.setting);
ImageView night = (ImageView) findViewById(R.id.night);
text = (TextView) findViewById(R.id.day);
// 白天,黑夜的切换
sp = this.getSharedPreferences("skinchange", Context.MODE_PRIVATE);
String mode = sp.getString("skin", "");
nig = new Night(window, FuctionActivity.this);
if (mode != null || !mode.equals("")) {
if (mode.equals(NIGHT)) {
nig.night();
} else {
nig.day();
}
}
// 创建商品对象
SharedPreferences sha1 = getSharedPreferences("num", MODE_APPEND);
ed = sha1.edit();
night.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
SharedPreferences sha2 = getSharedPreferences("num",
MODE_APPEND);
int flage = sha2.getInt("aa", 0);
if (flage % 2 == 0) {
nig.night();
text.setText("白天模式");
text.setTextColor(Color.WHITE);
flage++;
} else {
nig.day();
text.setText("夜间模式");
text.setTextColor(Color.BLACK);
flage++;
}
ed.putInt("aa", flage);
ed.commit();
}
});
ImageView qq = (ImageView) findViewById(R.id.qq);
ImageView webo = (ImageView) findViewById(R.id.webo);
TextView login = (TextView) findViewById(R.id.login);
ImageView down = (ImageView) findViewById(R.id.down);
down.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Intent ints = new Intent(FuctionActivity.this,
DownActivity.class);
startActivityForResult(ints, 11);
overridePendingTransition(R.anim.slide_right, R.anim.slide_left);
}
});
login.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Intent ints = new Intent(FuctionActivity.this,
LoginMoreActivity.class);
startActivityForResult(ints, 2);
overridePendingTransition(R.anim.slide_right, R.anim.slide_left);
}
});
webo.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
ThridLogin.getViBo(FuctionActivity.this);
}
});
qq.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
ThridLogin.getThrid(FuctionActivity.this);
}
});
setting.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Intent ints = new Intent(FuctionActivity.this,
SettingActivity.class);
startActivityForResult(ints, 1);
overridePendingTransition(R.anim.slide_right, R.anim.slide_left);
}
});
image.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
if (menu.isMenuShowing() == false) {
menu.showMenu(true);
} else {
menu.showMenu(false);
}
}
});
}
/*
* public void night4(View view) { SharedPreferences preferences =
* getSharedPreferences("default_night", MODE_PRIVATE); Editor editor =
* preferences.edit(); if (blFlag) {
* this.setTheme(R.style.BrowserThemeNight); blFlag = false;
* editor.putBoolean("default_night", false); } else {
* this.setTheme(R.style.BrowserThemeDefault); blFlag = true;
* editor.putBoolean("default_night", true);
*
* } // 提交修改 editor.commit();
* this.setContentView(R.layout.activity_fuction); }
*/
// 为侧滑左侧配置数据
private List<ListVo> getImage() {
list2 = new ArrayList<ListVo>();
for (int i = 0; i < imageview.length; i++) {
ListVo li = new ListVo();
li.setImageview(imageview[i]);
li.setText(name[i]);
list2.add(li);
}
return list2;
}
// 为fragemetn配置数据
private List<Fragment> getfra() {
listf = new ArrayList<Fragment>();
for (int i = 0; i < columnData1.length; i++) {
Fragment_2 f2 = new Fragment_2();
// bundle传值
Bundle bundle = new Bundle();
bundle.putString("text", columnData1[i]);
/* Fragment_1 f1 = new Fragment_1(url[i]); */
f2.setArguments(bundle);
listf.add(f2);
}
return listf;
}
private void setQTextColor(int p) {
TextView textView = tv_list.get(p);
for (int i = 0; i < tv_list.size(); i++) {
TextView text = tv_list.get(p);
int k = text.getMeasuredWidth();
int l = text.getLeft();
int s = k / 2 + l - wit / 2;
scvi.smoothScrollTo(s, 0);
TextView t = tv_list.get(i);
if (!t.equals(textView)) {
t.setTextColor(Color.BLACK);
} else {
t.setTextColor(Color.RED);
}
}
}
private void initView() {
// 找控件
scvi = (HorizontalScrollView) findViewById(R.id.mColumnHorizontalScrollView);
// HorizontalScrollView里的线性
line = (LinearLayout) findViewById(R.id.mRadioGroup_content);
ll_more_columns = (LinearLayout) findViewById(R.id.ll_more_columns);
rl_column = (RelativeLayout) findViewById(R.id.rl_column);
button_more_columns = (ImageView) findViewById(R.id.button_more_columns);
mViewPager = (ViewPager) findViewById(R.id.mViewPager);
button_more_columns.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(FuctionActivity.this, "我是添加频道的", 0).show();
}
});
}
@Override
public void onClick(View v) {
int i = (Integer) v.getTag();
/* System.out.println(columnData[i]); */
for (int j = 0; j < tv_list.size(); j++) {
/*
* Toast.makeText(FuctionActivity.this, (CharSequence)
* tv_list.get(j), 0).show();
*/
mViewPager.setCurrentItem(i);
}
}
}