Java tutorial
/* * Copyright (C) 2013 Andreas Stuetz <andreas.stuetz@gmail.com> * * 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.dashihui.afford.ui.activity; import android.content.Intent; import android.graphics.Color; import android.net.Uri; import android.os.Bundle; import android.support.v4.app.Fragment; import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentPagerAdapter; import android.support.v4.view.ViewPager; import android.util.TypedValue; import android.view.View; import android.view.View.OnClickListener; import android.widget.ImageButton; import android.widget.TextView; import com.dashihui.afford.AffordApp; import com.dashihui.afford.R; import com.dashihui.afford.business.entity.EtySendToUI; import com.dashihui.afford.common.base.BaseActivity; import com.dashihui.afford.common.base.BaseAtyFragment; import com.dashihui.afford.common.constants.CommConstans; import com.dashihui.afford.ui.activity.fragment.FragmentServerDetail; import com.dashihui.afford.ui.activity.fragment.FragmentServerState; import com.dashihui.afford.ui.widget.WdtPagerSlidingTabStrip; import com.lidroid.xutils.util.LogUtils; public class AtyFragmentServerDetail extends BaseAtyFragment implements OnClickListener { private WdtPagerSlidingTabStrip tabs; private ViewPager pager; private MyPagerAdapter adapter; private int currentColor = 0xFF666666; private TextView mTopTitle_txt; private ImageButton mIbtnBack; private ImageButton mRightPhone;//?? private int mSearchClassifyType;// ???????? public final static String TABCODE = "tabCode";// // public final static String SER_HOUSE_TAG = "ser_house_tag";//? // public final static String DAT_DEEP_TAG = "dat_deep_tag";///?? public static String mOrderCode = ""; public static boolean ORDSTATETAG = false; public static String mAtyHouseTpye = "";//?? // public static String mDayOrDeepType="";//??/?? @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.aty_frag_server_detail); //???? mAtyHouseTpye = getIntent().getStringExtra(AtySettlementOrder.ORDER_PAY_TYPE); //?? mOrderCode = getIntent().getStringExtra(AtySettlementOrder.ORDER_CODE); mTopTitle_txt = (TextView) findViewById(R.id.title); mTopTitle_txt.setText(""); mRightPhone = (ImageButton) findViewById(R.id.top_btn_right); mRightPhone.setVisibility(View.VISIBLE); mRightPhone.setImageResource(R.drawable.icon_phone); mRightPhone.setOnClickListener(this); mIbtnBack = (ImageButton) findViewById(R.id.ibtnBack); mIbtnBack.setOnClickListener(this); tabs = (WdtPagerSlidingTabStrip) findViewById(R.id.apps_fragment_tabs); pager = (ViewPager) findViewById(R.id.apps_fragment_viewpager); Intent intent = getIntent(); //??1 2 ?? ???searchClassifyType mSearchClassifyType = intent.getIntExtra("searchClassifyType", -1); adapter = new MyPagerAdapter(getSupportFragmentManager()); // ???N?? pager.setOffscreenPageLimit(adapter.getCount()); pager.setAdapter(adapter); final int pageMargin = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 2, getResources().getDisplayMetrics()); pager.setPageMargin(pageMargin); pager.setCurrentItem(intent.getIntExtra(TABCODE, 0)); tabs.setViewPager(pager); changeColor(currentColor); } @Override protected void onResume() { adapter.notifyDataSetChanged(); super.onResume(); } private void changeColor(int newColor) { tabs.setIndicatorColor(newColor); } public void onColorClicked(View v) { int color = Color.parseColor(v.getTag().toString()); changeColor(color); } @Override protected void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); outState.putInt("currentColor", currentColor); } @Override protected void onRestoreInstanceState(Bundle savedInstanceState) { super.onRestoreInstanceState(savedInstanceState); currentColor = savedInstanceState.getInt("currentColor"); changeColor(currentColor); } @Override public void onSuccess(EtySendToUI beanSendUI) { } @Override public void onFailure(EtySendToUI beanSendUI) { } public class MyPagerAdapter extends FragmentPagerAdapter { public MyPagerAdapter(FragmentManager supportFragmentManager) { super(supportFragmentManager); } @Override public CharSequence getPageTitle(int position) { return CommConstans.COMMONARRAY.TABS_ORDERDETAIL[position]; } @Override public int getCount() { return CommConstans.COMMONARRAY.TABS_ORDERDETAIL.length; } @Override public Fragment getItem(int position) { Fragment fragment = null; switch (position) { case 0: fragment = FragmentServerState.newInstance(AtyFragmentServerDetail.this, position); break; case 1: fragment = FragmentServerDetail.newInstance(AtyFragmentServerDetail.this, position); break; default: break; } return fragment; } } @Override public void onClick(View v) { // TODO Auto-generated method stub switch (v.getId()) { case R.id.ibtnBack: onBackPressed(); break; case R.id.top_btn_right: String phone = AffordApp.getInstance().getEntityLocation().getSTORE().getTEL(); LogUtils.e("onClick===========phone==========>" + phone); Intent intent = new Intent(new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + phone))); startActivity(intent); break; default: break; } } }