public static Drawable getProgressBarDrawable() { if (BaseActivity.getRunningActivity() != null) { Activity context = BaseActivity.getRunningActivity(); return new CircularProgressDrawable.Builder(context) .color(Utils.resolveColor(context, R.attr.theme_color, Color.BLUE)) .build(); } return null; }
@Override protected void onSuccess(TokenInfo tokenInfo) { super.onSuccess(tokenInfo); // 同一登录账户 if (tokenInfo != null && AppContext.isLoggedIn() && AppContext.getAccount().getUid().equals(tokenInfo.getUid())) { if (BaseActivity.getRunningActivity() != null && BaseActivity.getRunningActivity() instanceof MainActivity) { if (getParams()[0].getAccessToken().isExpired()) requestLogin(BaseActivity.getRunningActivity(), getParams()[0]); } } }
@Override protected void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); outState.putInt("index", index); outState.putSerializable("bean", mBean); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.ui_picture_pager); if (getSupportActionBar() != null) { getSupportActionBar().setDisplayShowHomeEnabled(false); getSupportActionBar().setDisplayHomeAsUpEnabled(true); } mBean = savedInstanceState == null ? PhotosFragment.photos : (PhotosBean) savedInstanceState.getSerializable("bean"); index = savedInstanceState == null ? getIntent().getIntExtra("index", 0) : savedInstanceState.getInt("index", 0); myViewPagerAdapter = new MyViewPagerAdapter(getFragmentManager()); viewPager.setAdapter(myViewPagerAdapter); viewPager.setCurrentItem(index); viewPager.setOnPageChangeListener(this); if (size() > 1 && getSupportActionBar() != null) getSupportActionBar().setTitle(String.format("%d/%d", index + 1, size())); layStatus.setVisibility(View.VISIBLE); viewStatus.setVisibility(View.VISIBLE); txtStatus.setText(getStatus(index).getText()); if (Build.VERSION.SDK_INT >= 19) { layToolbar.setPadding( 0, layToolbar.getPaddingTop() + SystemUtils.getStatusBarHeight(this), 0, 0); if (SystemUtils.hasNavigationBar(this)) { layStatus.setPadding(0, 0, 0, SystemUtils.getNavigationBarHeight(this)); } } getToolbar().setBackgroundColor(Color.TRANSPARENT); }
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.ui_main); CacheClearFragment.clearCompress(); BizFragment bizFragment = BizFragment.createBizFragment(this); bizFragment.createFabAnimator(fabBtn); fabBtn.setOnLongClickListener( new View.OnLongClickListener() { @Override public boolean onLongClick(View v) { // 触发一次刷新 ((AsToolbar) getToolbar()).performDoublcClick(); appBarLayout.setExpanded(true); return true; } }); bizFragment.getFabAnimator().setDuration(200); getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setDisplayShowHomeEnabled(false); setupDrawer(savedInstanceState); setupMenu(savedInstanceState); setupFab(savedInstanceState); setupAppBarLayout(savedInstanceState); if (savedInstanceState != null) { toolbarTitle = savedInstanceState.getString("toolbarTitle"); if (!TextUtils.isEmpty(toolbarTitle)) getSupportActionBar().setTitle(toolbarTitle); } mInstance = this; OtherItemFragment.checkPhotoPermission(this, true); }
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (requestCode == REQUEST_CODE_AUTH) { if (resultCode == Activity.RESULT_OK) { AccountBean accountBean = (AccountBean) data.getSerializableExtra("account"); AppContext.getAccount().setAccessToken(accountBean.getAccessToken()); if (accountBean.getUser() != null) { AppContext.getAccount().setUser(accountBean.getUser()); } if (accountBean.getGroups() != null) { AppContext.getAccount().setGroups(accountBean.getGroups()); } AccountUtils.newAccount(AppContext.getAccount()); AccountUtils.setLogedinAccount(AppContext.getAccount()); login(); } } }
@Override protected void onResume() { super.onResume(); // 修复偶尔Fab按钮不见了 if (menuFragment != null && menuFragment.getSelectedId() == 1) { if (fabBtn.getVisibility() != View.VISIBLE) { fabBtn.setVisibility(View.VISIBLE); } } if (!AppContext.isLoggedIn()) { finish(); return; } if (AppContext.getAccount().getAccessToken().isExpired()) { requestLogin(this, AppContext.getAccount()); } invalidateOptionsMenu(); }
@Override protected void onNewIntent(Intent intent) { super.onNewIntent(intent); if (intent == null) return; String action = intent.getAction(); // 切换账号 if (ACTION_LOGIN.equals(action)) { setupFab(null); menuFragment.changeAccount(); } else { if (ACTION_NOTIFICATION.equals(action) && MenuFragment.MENU_FRIENDSHIP == Integer.parseInt(intent.getStringExtra("type"))) { FriendshipPagerFragment.launch(this, AppContext.getAccount().getUser(), 1); } else { int menuId = getActionType(intent, action); menuFragment.triggerMenuClick(menuId); } } }
@Override protected void layoutInit(LayoutInflater inflater, Bundle savedInstanceSate) { super.layoutInit(inflater, savedInstanceSate); BaseActivity activity = (BaseActivity) getActivity(); activity.getSupportActionBar().setDisplayHomeAsUpEnabled(true); activity.getSupportActionBar().setTitle(R.string.title_login); setHasOptionsMenu(true); progressBar.setIndeterminate(true); editAccount = textinputAccount.getEditText(); editAccount.addTextChangedListener(new MTextWatcher(textinputAccount)); editPassword = textinputPassword.getEditText(); editPassword.addTextChangedListener(new MTextWatcher(textinputPassword)); if (getArguments() != null) { editAccount.setText(getArguments().getString("account")); editPassword.setText(getArguments().getString("password")); } WebSettings setting = webView.getSettings(); setting.setJavaScriptEnabled(true); setting.setDomStorageEnabled(true); setting.setAppCacheEnabled(true); setting.setDefaultTextEncodingName("utf-8"); webView.addJavascriptInterface(new LoginJavaScriptInterface(), "loginjs"); webView.setWebViewClient( new WebViewClient() { @Override public boolean shouldOverrideUrlLoading(WebView view, final String url) { if (url.startsWith(SettingUtility.getStringSetting("callback_url"))) webView.loadUrl("javascript:getAccount()"); view.loadUrl(url); Logger.d(TAG, "load url = " + url); // 是否授权成功 if (accountTask == null && url != null && url.startsWith(SettingUtility.getStringSetting("callback_url"))) { Params params = ParamsUtil.deCodeUrl(url); String code = params.getParameter("code"); Logger.d(TAG, "授权成功, code = " + code); if (getActivity() == null) return true; accountTask = new AccountTask(); accountTask.execute(code); } return true; } }); webView.setWebChromeClient( new WebChromeClient() { @Override public void onProgressChanged(WebView view, int newProgress) { if (newProgress < 100) { progressBar.setVisibility(View.VISIBLE); } else if (newProgress == 100) { progressBar.setVisibility(View.GONE); } if (newProgress < 100) { } else if (newProgress == 100) { Logger.d(TAG, String.format("progress = 100 , url = %s", view.getUrl())); if (!accountFilled && !TextUtils.isEmpty(view.getUrl()) && view.getUrl().equalsIgnoreCase("about:blank")) { webView.loadUrl("javascript:fillAccount()"); accountFilled = true; } // 是否授权成功 if (accountTask == null && webView.getUrl() != null && webView.getUrl().startsWith(SettingUtility.getStringSetting("callback_url"))) { Params params = ParamsUtil.deCodeUrl(webView.getUrl()); String code = params.getParameter("code"); Logger.d(TAG, "授权成功, code = " + code); if (getActivity() == null) return; accountTask = new AccountTask(); accountTask.execute(code); } } if (webView.getUrl() != null && webView.getUrl().startsWith(SettingUtility.getStringSetting("callback_url"))) { webView.setVisibility(View.GONE); } super.onProgressChanged(view, newProgress); } }); if (!TextUtils.isEmpty(editAccount.getText().toString()) && !TextUtils.isEmpty(editPassword.getText().toString())) { new Handler() .postDelayed( new Runnable() { @Override public void run() { doLogin(); } }, 500); } }
@Override public void onPause() { super.onPause(); UMengUtil.onPageEnd(this, "相册预览页"); }
@Override public void onResume() { super.onResume(); UMengUtil.onPageStart(this, "相册预览页"); }
@Override protected void onPostCreate(Bundle savedInstanceState) { super.onPostCreate(savedInstanceState); if (drawerToggle != null) drawerToggle.syncState(); }
@Override protected void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); if (!TextUtils.isEmpty(toolbarTitle)) outState.putString("toolbarTitle", toolbarTitle); }
@Override public void onDestroy() { super.onDestroy(); mInstance = null; }