Search in sources :

Example 1 with LibSlides

use of cn.eoe.android.libraries.entity.LibSlides in project Libraries-for-Android-Developers by eoecn.

the class HttpTest method TestSlide.

/**
	 * 测试 获取插件列表 获取与解析
	 */
public static void TestSlide() {
    final Gson gson = new Gson();
    String urlString = "http://www.1sters.com/api/v1/libraries/slides";
    HttpUtil.get(urlString, new BaseJsonHttpResponseHandler<LibSlides>() {

        @Override
        public void onSuccess(int statusCode, Header[] headers, String rawJsonResponse, LibSlides response) {
            System.out.println("suc");
            System.err.println(response.getData().get(0).getItems().get(0).getLabel());
        }

        @Override
        public void onFailure(int statusCode, Header[] headers, Throwable throwable, String rawJsonData, LibSlides errorResponse) {
            System.out.println("fail");
        }

        @Override
        protected LibSlides parseResponse(String rawJsonData, boolean isFailure) throws Throwable {
            // TODO Auto-generated method stub
            return gson.fromJson(rawJsonData, LibSlides.class);
        }

        ;
    });
}
Also used : LibSlides(cn.eoe.android.libraries.entity.LibSlides) Header(org.apache.http.Header) Gson(com.google.gson.Gson)

Example 2 with LibSlides

use of cn.eoe.android.libraries.entity.LibSlides in project Libraries-for-Android-Developers by eoecn.

the class MainActivity method onCreate.

@SuppressLint("NewApi")
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    getSupportActionBar().setBackgroundDrawable(getResources().getDrawable(R.drawable.common_title_bg));
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setHomeButtonEnabled(true);
    mTitle = mDrawerTitle = getTitle();
    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    mDrawerLeft = (LinearLayout) findViewById(R.id.left_drawer);
    mContentLayout = (FrameLayout) findViewById(R.id.content_frame);
    mDrawerList = (ListView) findViewById(R.id.left_drawer_list_view);
    //        List<Object> items = new ArrayList<Object>();
    //        items.add(new Category(""));
    //        items.add(new Item("最新的", R.drawable.star));
    //        items.add(new Item("热门的", R.drawable.like_me));
    //        items.add(new Item("收藏的", R.drawable.star));
    //获取侧栏目数据 每次都更新不使用缓存
    SlideFactory.getInstance(this).getSlide(false, new SlideRevHandler() {

        @Override
        public void onSuccess(int statusCode, LibSlides slides) {
            //异步获取的,如果有缓存数据就直接返回
            System.err.println(statusCode + " " + slides.getData().get(0).getItems().get(0).getTitle());
        }

        @Override
        public void onFailure(int statusCode, Throwable throwable) {
            throwable.printStackTrace();
        }
    });
    mDrawerList.setOnItemClickListener(new DrawerItemClickListener());
    // set a custom shadow that overlays the main content when the drawer opens
    mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START);
    // ActionBarDrawerToggle ties together the the proper interactions
    // between the sliding drawer and the action bar app icon
    mDrawerToggle = new ActionBarDrawerToggle(this, /* host Activity */
    mDrawerLayout, /* DrawerLayout object */
    R.drawable.ic_drawer, /* nav drawer image to replace 'Up' caret */
    R.string.app_name, /* "open drawer" description for accessibility */
    R.string.app_name) {

        /* "close drawer" description for accessibility */
        public void onDrawerClosed(View view) {
            getSupportActionBar().setTitle(mTitle);
            // creates call to onPrepareOptionsMenu()
            invalidateOptionsMenu();
        }

        public void onDrawerOpened(View drawerView) {
            getSupportActionBar().setTitle(mDrawerTitle);
            // creates call to onPrepareOptionsMenu()
            invalidateOptionsMenu();
        }
    };
    mDrawerLayout.setDrawerListener(mDrawerToggle);
    if (savedInstanceState == null) {
        selectItem(0);
    }
}
Also used : LibSlides(cn.eoe.android.libraries.entity.LibSlides) ActionBarDrawerToggle(android.support.v4.app.ActionBarDrawerToggle) SlideRevHandler(cn.eoe.android.libraries.entity.SlideFactory.SlideRevHandler) View(android.view.View) WebView(android.webkit.WebView) SuppressLint(android.annotation.SuppressLint) SuppressLint(android.annotation.SuppressLint)

Aggregations

LibSlides (cn.eoe.android.libraries.entity.LibSlides)2 SuppressLint (android.annotation.SuppressLint)1 ActionBarDrawerToggle (android.support.v4.app.ActionBarDrawerToggle)1 View (android.view.View)1 WebView (android.webkit.WebView)1 SlideRevHandler (cn.eoe.android.libraries.entity.SlideFactory.SlideRevHandler)1 Gson (com.google.gson.Gson)1 Header (org.apache.http.Header)1