reformat code & optimize import & reorder entries
This commit is contained in:
@ -10,221 +10,219 @@ import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import butterknife.BindView;
|
||||
import com.gh.base.BaseFragmentActivity;
|
||||
import com.gh.common.util.DisplayUtils;
|
||||
import com.gh.download.DownloadManager;
|
||||
import com.gh.gamecenter.adapter.FragmentAdapter;
|
||||
import com.gh.gamecenter.download.FileSendFragment;
|
||||
import com.gh.gamecenter.download.GameDownLoadFragment;
|
||||
import com.gh.gamecenter.download.GameUpdateFragment;
|
||||
import com.gh.gamecenter.eventbus.EBDownloadChanged;
|
||||
import com.gh.gamecenter.eventbus.EBMiPush;
|
||||
import com.gh.gamecenter.eventbus.EBSkip;
|
||||
import com.gh.gamecenter.eventbus.EBUISwitch;
|
||||
import com.gh.gamecenter.download.*;
|
||||
import com.gh.gamecenter.eventbus.*;
|
||||
import com.gh.gamecenter.manager.PackageManager;
|
||||
import de.greenrobot.event.EventBus;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import butterknife.BindView;
|
||||
import de.greenrobot.event.EventBus;
|
||||
|
||||
/**
|
||||
* 下载更新管理页面
|
||||
*
|
||||
*
|
||||
* @author 黄壮华
|
||||
*
|
||||
*/
|
||||
public class DownloadManagerActivity extends BaseFragmentActivity implements
|
||||
OnClickListener, OnPageChangeListener {
|
||||
OnClickListener, OnPageChangeListener {
|
||||
|
||||
@BindView(R.id.downloadmanager_viewPager) ViewPager downloadmanager_viewPager;
|
||||
@BindView(R.id.downloadmanager_tv_download) TextView downloadmanager_tv_download;
|
||||
@BindView(R.id.downloadmanager_tv_update) TextView downloadmanager_tv_update;
|
||||
@BindView(R.id.downloadmanager_download_number) TextView downloadmanager_download_number;
|
||||
@BindView(R.id.downloadmanager_tv_send) TextView downloadmanager_tv_send;
|
||||
@BindView(R.id.downloadmanager_update_number) TextView downloadmanager_update_number;
|
||||
@BindView(R.id.downloadmanager_ll_download) LinearLayout downloadmanager_ll_download;
|
||||
@BindView(R.id.downloadmanager_ll_send) LinearLayout downloadmanager_ll_send;
|
||||
@BindView(R.id.downloadmanager_ll_update) LinearLayout downloadmanager_ll_update;
|
||||
@BindView(R.id.downloadmanager_slide_line) View downloadmanager_slide_line;
|
||||
@BindView(R.id.downloadmanager_viewPager)
|
||||
ViewPager downloadmanager_viewPager;
|
||||
@BindView(R.id.downloadmanager_tv_download)
|
||||
TextView downloadmanager_tv_download;
|
||||
@BindView(R.id.downloadmanager_tv_update)
|
||||
TextView downloadmanager_tv_update;
|
||||
@BindView(R.id.downloadmanager_download_number)
|
||||
TextView downloadmanager_download_number;
|
||||
@BindView(R.id.downloadmanager_tv_send)
|
||||
TextView downloadmanager_tv_send;
|
||||
@BindView(R.id.downloadmanager_update_number)
|
||||
TextView downloadmanager_update_number;
|
||||
@BindView(R.id.downloadmanager_ll_download)
|
||||
LinearLayout downloadmanager_ll_download;
|
||||
@BindView(R.id.downloadmanager_ll_send)
|
||||
LinearLayout downloadmanager_ll_send;
|
||||
@BindView(R.id.downloadmanager_ll_update)
|
||||
LinearLayout downloadmanager_ll_update;
|
||||
@BindView(R.id.downloadmanager_slide_line)
|
||||
View downloadmanager_slide_line;
|
||||
Runnable runnable = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
downloadmanager_ll_download.performClick();
|
||||
}
|
||||
};
|
||||
private LinearLayout.LayoutParams lparams;
|
||||
private int width;
|
||||
private Handler handler = new Handler();
|
||||
|
||||
private LinearLayout.LayoutParams lparams;
|
||||
@Override
|
||||
protected void onSaveInstanceState(Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
outState.putInt("CurrentItem", downloadmanager_viewPager.getCurrentItem());
|
||||
}
|
||||
|
||||
private int width;
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
private Handler handler = new Handler();
|
||||
View contentView = View.inflate(this, R.layout.activity_downloadmanager, null);
|
||||
init(contentView, "下载管理");
|
||||
|
||||
@Override
|
||||
protected void onSaveInstanceState(Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
outState.putInt("CurrentItem", downloadmanager_viewPager.getCurrentItem());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
downloadmanager_ll_download.setOnClickListener(this);
|
||||
downloadmanager_ll_update.setOnClickListener(this);
|
||||
downloadmanager_ll_send.setOnClickListener(this);
|
||||
|
||||
View contentView = View.inflate(this, R.layout.activity_downloadmanager, null);
|
||||
init(contentView, "下载管理");
|
||||
int updateSize = PackageManager.getUpdateList().size();
|
||||
if (updateSize != 0) {
|
||||
downloadmanager_update_number.setVisibility(View.VISIBLE);
|
||||
downloadmanager_update_number.setText(String.valueOf(updateSize));
|
||||
} else {
|
||||
downloadmanager_update_number.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
downloadmanager_ll_download.setOnClickListener(this);
|
||||
downloadmanager_ll_update.setOnClickListener(this);
|
||||
downloadmanager_ll_send.setOnClickListener(this);
|
||||
int downloadSize = DownloadManager.getInstance(getApplicationContext()).getAll().size();
|
||||
if (downloadSize != 0) {
|
||||
downloadmanager_download_number.setVisibility(View.VISIBLE);
|
||||
downloadmanager_download_number.setText(String.valueOf(downloadSize));
|
||||
} else {
|
||||
downloadmanager_download_number.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
int updateSize = PackageManager.getUpdateList().size();
|
||||
if (updateSize != 0) {
|
||||
downloadmanager_update_number.setVisibility(View.VISIBLE);
|
||||
downloadmanager_update_number.setText(String.valueOf(updateSize));
|
||||
} else {
|
||||
downloadmanager_update_number.setVisibility(View.GONE);
|
||||
}
|
||||
int currentItem;
|
||||
if (savedInstanceState != null) {
|
||||
currentItem = savedInstanceState.getInt("CurrentItem");
|
||||
} else {
|
||||
currentItem = getIntent().getIntExtra("currentItem", -1);
|
||||
if (getIntent().getBundleExtra("data") != null) {
|
||||
currentItem = getIntent().getBundleExtra("data").getInt("currentItem", -1);
|
||||
}
|
||||
}
|
||||
if (currentItem == -1) {
|
||||
currentItem = 1; //默认游戏下载页面
|
||||
}
|
||||
|
||||
int downloadSize = DownloadManager.getInstance(getApplicationContext()).getAll().size();
|
||||
if (downloadSize != 0) {
|
||||
downloadmanager_download_number.setVisibility(View.VISIBLE);
|
||||
downloadmanager_download_number.setText(String.valueOf(downloadSize));
|
||||
} else {
|
||||
downloadmanager_download_number.setVisibility(View.GONE);
|
||||
}
|
||||
DisplayMetrics outMetrics = new DisplayMetrics();
|
||||
getWindowManager().getDefaultDisplay().getMetrics(outMetrics);
|
||||
width = outMetrics.widthPixels / 3;
|
||||
lparams = new LinearLayout.LayoutParams((int) (width * 0.7),
|
||||
DisplayUtils.dip2px(getApplicationContext(), 2));
|
||||
lparams.leftMargin = (int) (width * (currentItem + 0.17f));
|
||||
downloadmanager_slide_line.setLayoutParams(lparams);
|
||||
|
||||
int currentItem;
|
||||
if (savedInstanceState != null) {
|
||||
currentItem = savedInstanceState.getInt("CurrentItem");
|
||||
} else {
|
||||
currentItem = getIntent().getIntExtra("currentItem", -1);
|
||||
if (getIntent().getBundleExtra("data") != null) {
|
||||
currentItem = getIntent().getBundleExtra("data").getInt("currentItem", -1);
|
||||
}
|
||||
}
|
||||
if (currentItem == -1) {
|
||||
currentItem = 1; //默认游戏下载页面
|
||||
}
|
||||
List<Fragment> list = new ArrayList<>();
|
||||
list.add(new FileSendFragment());
|
||||
list.add(new GameDownLoadFragment());
|
||||
list.add(new GameUpdateFragment());
|
||||
downloadmanager_viewPager.setAdapter(new FragmentAdapter(getSupportFragmentManager(), list));
|
||||
downloadmanager_viewPager.addOnPageChangeListener(this);
|
||||
downloadmanager_viewPager.setCurrentItem(currentItem);
|
||||
}
|
||||
|
||||
DisplayMetrics outMetrics = new DisplayMetrics();
|
||||
getWindowManager().getDefaultDisplay().getMetrics(outMetrics);
|
||||
width = outMetrics.widthPixels / 3;
|
||||
lparams = new LinearLayout.LayoutParams((int)(width * 0.7),
|
||||
DisplayUtils.dip2px(getApplicationContext(), 2));
|
||||
lparams.leftMargin = (int) (width * (currentItem + 0.17f));
|
||||
downloadmanager_slide_line.setLayoutParams(lparams);
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
handler.removeCallbacksAndMessages(null);
|
||||
}
|
||||
|
||||
List<Fragment> list = new ArrayList<>();
|
||||
list.add(new FileSendFragment());
|
||||
list.add(new GameDownLoadFragment());
|
||||
list.add(new GameUpdateFragment());
|
||||
downloadmanager_viewPager.setAdapter(new FragmentAdapter(getSupportFragmentManager(), list));
|
||||
downloadmanager_viewPager.addOnPageChangeListener(this);
|
||||
downloadmanager_viewPager.setCurrentItem(currentItem);
|
||||
}
|
||||
@Override
|
||||
public void onPageSelected(int position) {
|
||||
if (position == 1) {
|
||||
EventBus.getDefault().post(new EBUISwitch("DownloadManagerActivity", 1));
|
||||
downloadmanager_tv_download.setTextColor(getResources().getColor(R.color.theme));
|
||||
downloadmanager_tv_update.setTextColor(getResources().getColor(R.color.title));
|
||||
downloadmanager_tv_send.setTextColor(getResources().getColor(R.color.title));
|
||||
} else if (position == 2) {
|
||||
EventBus.getDefault().post(new EBUISwitch("DownloadManagerActivity", 2));
|
||||
downloadmanager_tv_download.setTextColor(getResources().getColor(R.color.title));
|
||||
downloadmanager_tv_update.setTextColor(getResources().getColor(R.color.theme));
|
||||
downloadmanager_tv_send.setTextColor(getResources().getColor(R.color.title));
|
||||
} else {
|
||||
downloadmanager_tv_download.setTextColor(getResources().getColor(R.color.title));
|
||||
downloadmanager_tv_update.setTextColor(getResources().getColor(R.color.title));
|
||||
downloadmanager_tv_send.setTextColor(getResources().getColor(R.color.theme));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
handler.removeCallbacksAndMessages(null);
|
||||
}
|
||||
@Override
|
||||
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
|
||||
if (positionOffset != 0) {
|
||||
lparams.leftMargin = (int) (width * (position + positionOffset + 0.17f));
|
||||
downloadmanager_slide_line.setLayoutParams(lparams);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPageSelected(int position) {
|
||||
if (position == 1) {
|
||||
EventBus.getDefault().post(new EBUISwitch("DownloadManagerActivity", 1));
|
||||
downloadmanager_tv_download.setTextColor(getResources().getColor(R.color.theme));
|
||||
downloadmanager_tv_update.setTextColor(getResources().getColor(R.color.title));
|
||||
downloadmanager_tv_send.setTextColor(getResources().getColor(R.color.title));
|
||||
} else if (position == 2){
|
||||
EventBus.getDefault().post(new EBUISwitch("DownloadManagerActivity", 2));
|
||||
downloadmanager_tv_download.setTextColor(getResources().getColor(R.color.title));
|
||||
downloadmanager_tv_update.setTextColor(getResources().getColor(R.color.theme));
|
||||
downloadmanager_tv_send.setTextColor(getResources().getColor(R.color.title));
|
||||
} else {
|
||||
downloadmanager_tv_download.setTextColor(getResources().getColor(R.color.title));
|
||||
downloadmanager_tv_update.setTextColor(getResources().getColor(R.color.title));
|
||||
downloadmanager_tv_send.setTextColor(getResources().getColor(R.color.theme));
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void onPageScrollStateChanged(int state) {
|
||||
|
||||
@Override
|
||||
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
|
||||
if (positionOffset != 0) {
|
||||
lparams.leftMargin = (int) (width * (position + positionOffset + 0.17f));
|
||||
downloadmanager_slide_line.setLayoutParams(lparams);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPageScrollStateChanged(int state) {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
final int id = view.getId();
|
||||
if (id == R.id.actionbar_rl_back) {
|
||||
finish();
|
||||
} else if (id == R.id.downloadmanager_ll_download) {
|
||||
downloadmanager_viewPager.setCurrentItem(1);
|
||||
} else if (id == R.id.downloadmanager_ll_update) {
|
||||
downloadmanager_viewPager.setCurrentItem(2);
|
||||
} else if (id == R.id.downloadmanager_ll_send) {
|
||||
downloadmanager_viewPager.setCurrentItem(0);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
public void onEventMainThread(EBMiPush mipush) {
|
||||
if ("plugin_install".equals(mipush.getFrom())) {
|
||||
downloadmanager_ll_download.performClick();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
final int id = view.getId();
|
||||
if (id == R.id.actionbar_rl_back) {
|
||||
finish();
|
||||
} else if (id == R.id.downloadmanager_ll_download) {
|
||||
downloadmanager_viewPager.setCurrentItem(1);
|
||||
} else if (id == R.id.downloadmanager_ll_update) {
|
||||
downloadmanager_viewPager.setCurrentItem(2);
|
||||
} else if (id == R.id.downloadmanager_ll_send) {
|
||||
downloadmanager_viewPager.setCurrentItem(0);
|
||||
}
|
||||
}
|
||||
public void onEventMainThread(EBDownloadChanged changed) {
|
||||
if ("download".equals(changed.getType())) {
|
||||
if (changed.getVisibility() == View.VISIBLE) {
|
||||
downloadmanager_download_number.setVisibility(View.VISIBLE);
|
||||
} else if (changed.getVisibility() == View.GONE) {
|
||||
downloadmanager_download_number.setVisibility(View.GONE);
|
||||
} else if (changed.getVisibility() == View.INVISIBLE) {
|
||||
downloadmanager_download_number.setVisibility(View.INVISIBLE);
|
||||
}
|
||||
downloadmanager_download_number.setText(String.valueOf(changed.getSize()));
|
||||
} else if ("update".equals(changed.getType())) {
|
||||
if (changed.getSize() == -1) {
|
||||
int number = Integer.valueOf(downloadmanager_update_number.getText().toString());
|
||||
if (number == 1) {
|
||||
downloadmanager_update_number.setVisibility(View.GONE);
|
||||
} else {
|
||||
downloadmanager_update_number.setText(String.valueOf(number - 1));
|
||||
}
|
||||
} else {
|
||||
if (changed.getSize() != 0) {
|
||||
if (changed.getVisibility() == View.VISIBLE) {
|
||||
downloadmanager_update_number.setVisibility(View.VISIBLE);
|
||||
} else if (changed.getVisibility() == View.GONE) {
|
||||
downloadmanager_update_number.setVisibility(View.GONE);
|
||||
} else if (changed.getVisibility() == View.INVISIBLE) {
|
||||
downloadmanager_update_number.setVisibility(View.INVISIBLE);
|
||||
}
|
||||
downloadmanager_update_number.setText(String.valueOf(changed.getSize()));
|
||||
} else {
|
||||
downloadmanager_update_number.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void onEventMainThread(EBMiPush mipush){
|
||||
if ("plugin_install".equals(mipush.getFrom())) {
|
||||
downloadmanager_ll_download.performClick();
|
||||
}
|
||||
}
|
||||
|
||||
public void onEventMainThread(EBDownloadChanged changed) {
|
||||
if ("download".equals(changed.getType())) {
|
||||
if (changed.getVisibility() == View.VISIBLE){
|
||||
downloadmanager_download_number.setVisibility(View.VISIBLE);
|
||||
} else if (changed.getVisibility() == View.GONE) {
|
||||
downloadmanager_download_number.setVisibility(View.GONE);
|
||||
} else if (changed.getVisibility() == View.INVISIBLE) {
|
||||
downloadmanager_download_number.setVisibility(View.INVISIBLE);
|
||||
}
|
||||
downloadmanager_download_number.setText(String.valueOf(changed.getSize()));
|
||||
} else if ("update".equals(changed.getType())) {
|
||||
if (changed.getSize() == -1) {
|
||||
int number = Integer.valueOf(downloadmanager_update_number.getText().toString());
|
||||
if (number == 1) {
|
||||
downloadmanager_update_number.setVisibility(View.GONE);
|
||||
} else {
|
||||
downloadmanager_update_number.setText(String.valueOf(number - 1));
|
||||
}
|
||||
} else {
|
||||
if (changed.getSize() != 0) {
|
||||
if (changed.getVisibility() == View.VISIBLE){
|
||||
downloadmanager_update_number.setVisibility(View.VISIBLE);
|
||||
} else if (changed.getVisibility() == View.GONE) {
|
||||
downloadmanager_update_number.setVisibility(View.GONE);
|
||||
} else if (changed.getVisibility() == View.INVISIBLE) {
|
||||
downloadmanager_update_number.setVisibility(View.INVISIBLE);
|
||||
}
|
||||
downloadmanager_update_number.setText(String.valueOf(changed.getSize()));
|
||||
} else {
|
||||
downloadmanager_update_number.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void onEventMainThread(EBSkip skip) {
|
||||
if ("DownloadManagerActivity".equals(skip.getType())) {
|
||||
if (skip.getCurrentItem() == 1) {
|
||||
handler.postDelayed(runnable, 300);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Runnable runnable = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
downloadmanager_ll_download.performClick();
|
||||
}
|
||||
};
|
||||
public void onEventMainThread(EBSkip skip) {
|
||||
if ("DownloadManagerActivity".equals(skip.getType())) {
|
||||
if (skip.getCurrentItem() == 1) {
|
||||
handler.postDelayed(runnable, 300);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user