今日头条(App和MainActivity类)

///***********************************/App类导xutils

package com.example.my;

import org.xutils.x;

/**
 * Created by dell on 2017/8/10.
 */

public class App extends com.andy.share.App {
    @Override
    public void onCreate() {
        super.onCreate();
        x.Ext.init(this);
        x.Ext.setDebug(BuildConfig.DEBUG);
    }
}

///******************************************************//MainActivity类

package com.example.my;

import android.content.Intent;
import android.content.SharedPreferences;
import android.support.design.widget.TabLayout;
import android.support.v4.view.ViewPager;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.andy.library.ChannelActivity;
import com.andy.library.ChannelBean;
import com.andy.share.QQOauthUtils;
import com.example.city_picker.CityListActivity;
import com.jeremyfeinstein.slidingmenu.lib.SlidingMenu;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;
import com.umeng.socialize.UMAuthListener;
import com.umeng.socialize.UMShareAPI;
import com.umeng.socialize.bean.SHARE_MEDIA;
import com.umeng.socialize.utils.Log;

import org.xutils.image.ImageOptions;
import org.xutils.x;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

public class MainActivity extends AppCompatActivity implements View.OnClickListener {

    private ImageView imagedenglu;
    private SlidingMenu slidingMenu;
    private SlidingMenu slidingMenu1;
    private QQOauthUtils qq;
    private ImageView qqdenglu;
    private ImageView yejian;
    private int theme = R.style.AppTheme;
    private ImageView sezhi;
    private TabLayout tablayout;
    private ViewPager viewpager;

    private List list = new ArrayList<>();
    private String jsonbeans;
    private SharedPreferences pre;
    private TextView buff;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (savedInstanceState != null) {
            theme = savedInstanceState.getInt("theme");
            setTheme(theme);
        }
        setContentView(R.layout.activity_main);
        buff = (TextView) findViewById(R.id.buff);
        qq = new QQOauthUtils();
        imagedenglu = (ImageView) findViewById(R.id.imagedenglu);
        sezhi = (ImageView) findViewById(R.id.sezhi);
        qqdenglu = (ImageView) findViewById(R.id.qqdenglu);
        yejian = (ImageView) findViewById(R.id.yejian);
        tablayout = (TabLayout) findViewById(R.id.tablayout);
        viewpager = (ViewPager) findViewById(R.id.viewpager);
        imagedenglu.setOnClickListener(this);
        slidingMenu = new SlidingMenu(this);
        slidingMenu.setMode(SlidingMenu.LEFT);
        slidingMenu.setTouchModeAbove(SlidingMenu.TOUCHMODE_NONE);
        slidingMenu.setBehindOffset(50);
        slidingMenu.setFadeDegree(0.5f);
        slidingMenu.attachToActivity(this, SlidingMenu.SLIDING_CONTENT);
        slidingMenu.setMenu(R.layout.slidingmeau);
        viewpager.setAdapter(new Myadapter(getSupportFragmentManager()));
        tablayout.setupWithViewPager(viewpager);
    }


    //buttononcilck相应
    public void button(View view) {
        //        1. appgradle里面
        //        compile 'com.github.andyoom:citypicker:v1.0.4'
        //
        //
        //        2.在项目的build.gradle中添加
        //        maven {url "https://jitpack.io"}
        CityListActivity.startCityActivityForResult(this);
    }


    public void getit(View v) {
        //先获取一个oncilk的控件,放在main        // 1. appgradle里面
        //compile 'com.github.andyoom:draggrid:v1.0.1'

        //    2.在项目的build.gradle中添加
        //        maven {url "https://jitpack.io"}放在  jcenter()下面


        pre = getSharedPreferences("channel", MODE_PRIVATE);
        jsonbeans = pre.getString("beans", null);
        if (jsonbeans == null) {
            lintList();
            ChannelActivity.startChannelActivity(this, list);
        } else {
            ChannelActivity.startChannelActivity(this, jsonbeans);
        }
    }

    private void lintList() {
        list.add(new ChannelBean("热点", true));
        list.add(new ChannelBean("视频", true));
        list.add(new ChannelBean("社会", false));
        list.add(new ChannelBean("娱乐", false));
        list.add(new ChannelBean("军事", false));
        list.add(new ChannelBean("图片", false));
        list.add(new ChannelBean("体育", false));
        list.add(new ChannelBean("汽车", false));
        list.add(new ChannelBean("国境", false));
    }


    @Override
    public void onBackPressed() {
        super.onBackPressed();
        SharedPreferences.Editor editor = pre.edit();
        editor.putString("beans", jsonbeans);
        editor.commit();
    }

    @Override
    protected void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
        outState.putInt("theme", theme);
    }

    @Override
    protected void onRestoreInstanceState(Bundle savedInstanceState) {
        super.onRestoreInstanceState(savedInstanceState);
        theme = savedInstanceState.getInt("theme");
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.imagedenglu:
                slidingMenu.toggle();
                break;
        }
    }

    public void yexiangying(View view) {
        theme = (theme == R.style.AppTheme) ? R.style.NightAppTheme : R.style.AppTheme;
        MainActivity.this.recreate();
    }


    public void QQing(View view) {
        qq.qqLogin(this);
        UMShareAPI umShareAPI = UMShareAPI.get(this);
        umShareAPI.getPlatformInfo(MainActivity.this, SHARE_MEDIA.QQ, new UMAuthListener() {
            @Override
            public void onStart(SHARE_MEDIA share_media) {
            }

            @Override
            public void onComplete(SHARE_MEDIA share_media, int i, Map map) {
                if (i == 0) {
                    Toast.makeText(MainActivity.this, "登陆成功", Toast.LENGTH_LONG).show();
                } else if (i == 2) {
                    String s = map.get("iconurl");
                    ImageOptions.Builder builder = new ImageOptions.Builder();
                    builder.setRadius(90);
                    ImageOptions imageOptions = builder.build();
                    x.image().bind(imagedenglu, s, imageOptions);
                    x.image().bind(qqdenglu, s, imageOptions);
                }
            }

            @Override
            public void onError(SHARE_MEDIA share_media, int i, Throwable throwable) {

            }

            @Override
            public void onCancel(SHARE_MEDIA share_media, int i) {

            }
        });

    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == CityListActivity.REQUEST_CODE && resultCode == CityListActivity.RESULT_CODE) {
            String city = data.getStringExtra(CityListActivity.RESULT_KEY);
            //buffid控件
            buff.setText(city);
            jsonbeans = data.getStringExtra(ChannelActivity.RESULT_JSON_KEY);
            Log.e("onActivityResult", "onActivityResult: " + jsonbeans);
        }
        qq.onActivityResult(requestCode, resultCode, data);
        UMShareAPI.get(this).onActivityResult(requestCode, resultCode, data);


    }

    public void imagesez(View view) {
        Intent intent = new Intent(MainActivity.this, Sezhi.class);
        startActivity(intent);
    }


}

你可能感兴趣的:(今日头条(App和MainActivity类))