fixed sign in activity actionbar

fixed open sensitive media in status screen
added tweets count
This commit is contained in:
Mariotaku Lee 2015-04-14 13:11:50 +08:00
parent 0148436e1b
commit b57e8fc51a
8 changed files with 123 additions and 42 deletions

View File

@ -34,11 +34,10 @@ public class SpiceService extends Service {
SpiceProfilingUtil.log(this, "onCreate");
mAlarmManager = (AlarmManager) getSystemService(Service.ALARM_SERVICE);
IntentFilter mScreenOnFilter = new IntentFilter("android.intent.action.SCREEN_ON");
SpiceService.this.registerReceiver(mScreenOReceiver, mScreenOnFilter);
IntentFilter mScreenOffFilter = new IntentFilter("android.intent.action.SCREEN_OFF");
SpiceService.this.registerReceiver(mScreenOReceiver, mScreenOffFilter);
IntentFilter screenFilter = new IntentFilter();
screenFilter.addAction(Intent.ACTION_SCREEN_ON);
screenFilter.addAction(Intent.ACTION_SCREEN_OFF);
registerReceiver(mScreenReceiver, screenFilter);
// Upload Service
final Intent uploadIntent = new Intent(SpiceUploadReceiver.ACTION_UPLOAD_PROFILE);
@ -49,19 +48,20 @@ public class SpiceService extends Service {
@Override
public void onDestroy() {
mAlarmManager.cancel(mUploadIntent);
unregisterReceiver(mScreenReceiver);
super.onDestroy();
}
private BroadcastReceiver mScreenOReceiver = new BroadcastReceiver() {
private BroadcastReceiver mScreenReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (action.equals("android.intent.action.SCREEN_ON")) {
SpiceProfilingUtil.profile(context,SpiceProfilingUtil.FILE_NAME_SCREEN, "SCREEN ON" + "," + NetworkStateUtil.getConnectedType(context));
SpiceProfilingUtil.log(context, "SCREEN ON" + "," + NetworkStateUtil.getConnectedType(context));
} else if (action.equals("android.intent.action.SCREEN_OFF")) {
SpiceProfilingUtil.profile(context,SpiceProfilingUtil.FILE_NAME_SCREEN, "SCREEN OFF" + "," + NetworkStateUtil.getConnectedType(context));
SpiceProfilingUtil.log(context, "SCREEN OFF" + "," + NetworkStateUtil.getConnectedType(context));
if (action.equals(Intent.ACTION_SCREEN_ON)) {
SpiceProfilingUtil.profile(context, SpiceProfilingUtil.FILE_NAME_SCREEN, "SCREEN ON" + "," + NetworkStateUtil.getConnectedType(context));
SpiceProfilingUtil.log(context, "SCREEN ON" + "," + NetworkStateUtil.getConnectedType(context));
} else if (action.equals(Intent.ACTION_SCREEN_OFF)) {
SpiceProfilingUtil.profile(context, SpiceProfilingUtil.FILE_NAME_SCREEN, "SCREEN OFF" + "," + NetworkStateUtil.getConnectedType(context));
SpiceProfilingUtil.log(context, "SCREEN OFF" + "," + NetworkStateUtil.getConnectedType(context));
}
}

View File

@ -23,6 +23,7 @@ import android.app.Fragment;
import android.app.FragmentTransaction;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.view.WindowCompat;
import android.support.v7.app.ActionBar;
import android.view.MenuItem;
import android.view.Window;
@ -48,6 +49,7 @@ public class BrowserActivity extends BaseActionBarActivity {
@Override
protected void onCreate(final Bundle savedInstanceState) {
supportRequestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
supportRequestWindowFeature(WindowCompat.FEATURE_ACTION_BAR);
super.onCreate(savedInstanceState);
final ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {

View File

@ -38,6 +38,7 @@ import android.support.v4.app.DialogFragment;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.support.v4.view.WindowCompat;
import android.support.v7.app.ActionBar;
import android.text.Editable;
import android.text.TextUtils;
@ -293,6 +294,7 @@ public class SignInActivity extends BaseActionBarActivity implements TwitterCons
@Override
protected void onCreate(final Bundle savedInstanceState) {
supportRequestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
supportRequestWindowFeature(WindowCompat.FEATURE_ACTION_BAR);
super.onCreate(savedInstanceState);
mPreferences = getSharedPreferences(SHARED_PREFERENCES_NAME, MODE_PRIVATE);
mResolver = getContentResolver();

View File

@ -72,11 +72,16 @@ public class SupportTabsAdapter extends SupportFixedFragmentStatePagerAdapter im
clear();
}
public void addTab(final Class<? extends Fragment> cls, final Bundle args, final String name, final Integer icon,
final int position, final String tag) {
public void addTab(final Class<? extends Fragment> cls, final Bundle args, final String name,
final Integer icon, final int position, final String tag) {
addTab(new SupportTabSpec(name, icon, cls, args, position, tag));
}
public void addTab(final Class<? extends Fragment> cls, final Bundle args, final String name,
final Integer icon, final String type, final int position, final String tag) {
addTab(new SupportTabSpec(name, icon, type, cls, args, position, tag));
}
public void addTab(final SupportTabSpec spec) {
mTabs.add(spec);
notifyDataSetChanged();

View File

@ -1229,11 +1229,12 @@ public class StatusFragment extends BaseSupportFragment implements LoaderCallbac
}
public boolean isDetailMediaExpanded() {
if (mDetailMediaExpanded) return true;
if (mDisplayMediaPreview) {
final ParcelableStatus status = mStatus;
return status != null && (mSensitiveContentEnabled || !status.is_possibly_sensitive);
}
return mDetailMediaExpanded;
return false;
}
public void setDetailMediaExpanded(boolean expanded) {

View File

@ -56,12 +56,11 @@ import android.support.v4.content.Loader;
import android.support.v4.content.res.ResourcesCompat;
import android.support.v4.view.ViewCompat;
import android.support.v4.view.ViewPager;
import android.support.v4.view.ViewPager.OnPageChangeListener;
import android.support.v7.app.ActionBar;
import android.support.v7.app.ActionBarActivity;
import android.support.v7.widget.Toolbar;
import android.text.Html;
import android.text.SpannableStringBuilder;
import android.text.Spanned;
import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater;
@ -103,9 +102,9 @@ import org.mariotaku.twidere.model.ParcelableMedia;
import org.mariotaku.twidere.model.ParcelableUser;
import org.mariotaku.twidere.model.ParcelableUserList;
import org.mariotaku.twidere.model.SingleResponse;
import org.mariotaku.twidere.model.SupportTabSpec;
import org.mariotaku.twidere.provider.TwidereDataStore.CachedUsers;
import org.mariotaku.twidere.provider.TwidereDataStore.Filters;
import org.mariotaku.twidere.text.TextAlphaSpan;
import org.mariotaku.twidere.util.AsyncTwitterWrapper;
import org.mariotaku.twidere.util.ColorUtils;
import org.mariotaku.twidere.util.ContentValuesCreator;
@ -172,7 +171,7 @@ import static org.mariotaku.twidere.util.Utils.showInfoMessage;
public class UserFragment extends BaseSupportFragment implements OnClickListener,
OnLinkClickListener, OnSizeChangedListener, OnSharedPreferenceChangeListener,
OnTouchListener, DrawerCallback, SupportFragmentCallback, SystemWindowsInsetsCallback,
RefreshScrollTopInterface {
RefreshScrollTopInterface, OnPageChangeListener {
private static final ArgbEvaluator sArgbEvaluator = new ArgbEvaluator();
@ -186,6 +185,9 @@ public class UserFragment extends BaseSupportFragment implements OnClickListener
private static final int TAB_POSITION_STATUSES = 0;
private static final int TAB_POSITION_MEDIA = 1;
private static final int TAB_POSITION_FAVORITES = 2;
private static final String TAB_TYPE_STATUSES = "statuses";
private static final String TAB_TYPE_MEDIA = "media";
private static final String TAB_TYPE_FAVORITES = "favorites";
private MediaLoaderWrapper mProfileImageLoader;
private ShapedImageView mProfileImageView;
@ -423,6 +425,53 @@ public class UserFragment extends BaseSupportFragment implements OnClickListener
&& y >= location[1] && y <= location[1] + v.getHeight();
}
@Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
}
@Override
public void onPageSelected(int position) {
updateSubtitle();
}
private void updateSubtitle() {
final ActionBarActivity activity = (ActionBarActivity) getActivity();
if (activity == null) return;
final ActionBar actionBar = activity.getSupportActionBar();
if (actionBar == null) return;
final ParcelableUser user = mUser;
if (user == null) {
actionBar.setSubtitle(null);
return;
}
final SupportTabSpec spec = mPagerAdapter.getTab(mViewPager.getCurrentItem());
switch (spec.type) {
case TAB_TYPE_STATUSES: {
actionBar.setSubtitle(getResources().getQuantityString(R.plurals.N_statuses, user.statuses_count, user.statuses_count));
break;
}
case TAB_TYPE_MEDIA: {
actionBar.setSubtitle(getResources().getQuantityString(R.plurals.N_media, user.media_count, user.media_count));
break;
}
case TAB_TYPE_FAVORITES: {
actionBar.setSubtitle(getResources().getQuantityString(R.plurals.N_favorites, user.favorites_count, user.favorites_count));
break;
}
default: {
actionBar.setSubtitle(null);
break;
}
}
updateTitleAlpha();
}
@Override
public void onPageScrollStateChanged(int state) {
}
@Override
public void scrollBy(float dy) {
final Fragment fragment = mCurrentVisibleFragment;
@ -516,8 +565,9 @@ public class UserFragment extends BaseSupportFragment implements OnClickListener
}
activity.setTitle(UserColorNameUtils.getDisplayName(activity, user, true));
updateTitleColor();
updateTitleAlpha();
invalidateOptionsMenu();
updateSubtitle();
}
@Override
@ -726,6 +776,7 @@ public class UserFragment extends BaseSupportFragment implements OnClickListener
mViewPager.setAdapter(mPagerAdapter);
mPagerIndicator.setViewPager(mViewPager);
mPagerIndicator.setTabDisplayOption(TabPagerIndicator.LABEL);
mPagerIndicator.setOnPageChangeListener(this);
mFollowButton.setOnClickListener(this);
mProfileImageView.setOnClickListener(this);
@ -1272,7 +1323,7 @@ public class UserFragment extends BaseSupportFragment implements OnClickListener
final ActionBar actionBar = linkHandler.getSupportActionBar();
if (actionBar == null) return;
final Drawable shadow = ResourcesCompat.getDrawable(activity.getResources(), R.drawable.shadow_user_banner_action_bar, null);
mActionBarBackground = new ActionBarDrawable(getResources(), shadow);
mActionBarBackground = new ActionBarDrawable(shadow);
mActionBarBackground.setAlpha(linkHandler.getCurrentThemeBackgroundAlpha());
mProfileBannerView.setAlpha(linkHandler.getCurrentThemeBackgroundAlpha() / 255f);
actionBar.setBackgroundDrawable(mActionBarBackground);
@ -1295,11 +1346,11 @@ public class UserFragment extends BaseSupportFragment implements OnClickListener
tabArgs.putLong(EXTRA_USER_ID, args.getLong(EXTRA_USER_ID, -1));
tabArgs.putString(EXTRA_SCREEN_NAME, args.getString(EXTRA_SCREEN_NAME));
}
mPagerAdapter.addTab(UserTimelineFragment.class, tabArgs, getString(R.string.statuses), R.drawable.ic_action_quote, TAB_POSITION_STATUSES, null);
mPagerAdapter.addTab(UserTimelineFragment.class, tabArgs, getString(R.string.statuses), R.drawable.ic_action_quote, TAB_TYPE_STATUSES, TAB_POSITION_STATUSES, null);
if (Utils.isOfficialKeyAccount(context, accountId)) {
mPagerAdapter.addTab(UserMediaTimelineFragment.class, tabArgs, getString(R.string.media), R.drawable.ic_action_gallery, TAB_POSITION_MEDIA, null);
mPagerAdapter.addTab(UserMediaTimelineFragment.class, tabArgs, getString(R.string.media), R.drawable.ic_action_gallery, TAB_TYPE_MEDIA, TAB_POSITION_MEDIA, null);
}
mPagerAdapter.addTab(UserFavoritesFragment.class, tabArgs, getString(R.string.favorites), R.drawable.ic_action_star, TAB_POSITION_FAVORITES, null);
mPagerAdapter.addTab(UserFavoritesFragment.class, tabArgs, getString(R.string.favorites), R.drawable.ic_action_star, TAB_TYPE_FAVORITES, TAB_POSITION_FAVORITES, null);
}
private boolean shouldUseNativeMenu() {
@ -1401,36 +1452,34 @@ public class UserFragment extends BaseSupportFragment implements OnClickListener
if (actionBarView instanceof Toolbar) {
final Toolbar toolbar = (Toolbar) actionBarView;
toolbar.setTitleTextColor(itemColor);
toolbar.setSubtitleTextColor(itemColor);
ThemeUtils.setActionBarOverflowColor(toolbar, itemColor);
ThemeUtils.wrapToolbarMenuIcon(toolbar, itemColor, itemColor);
}
mPagerIndicator.updateAppearance();
}
updateTitleColor();
updateTitleAlpha();
}
private void updateTitleColor() {
private void updateTitleAlpha() {
final int[] location = new int[2];
mNameView.getLocationInWindow(location);
final float nameShowingRatio = (mHeaderDrawerLayout.getPaddingTop() - location[1])
/ (float) mNameView.getHeight();
final int textAlpha = Math.round(0xFF * MathUtils.clamp(nameShowingRatio, 0, 1));
final float textAlpha = MathUtils.clamp(nameShowingRatio, 0, 1);
final FragmentActivity activity = getActivity();
final SpannableStringBuilder spannedTitle;
final CharSequence title = activity.getTitle();
if (title instanceof SpannableStringBuilder) {
spannedTitle = (SpannableStringBuilder) title;
} else {
spannedTitle = SpannableStringBuilder.valueOf(title);
final View actionBarView = activity.getWindow().findViewById(android.support.v7.appcompat.R.id.action_bar);
if (actionBarView instanceof Toolbar) {
final Toolbar toolbar = (Toolbar) actionBarView;
final TextView titleView = ViewUtils.findViewByText(toolbar, toolbar.getTitle());
if (titleView != null) {
titleView.setAlpha(textAlpha);
}
final TextView subtitleView = ViewUtils.findViewByText(toolbar, toolbar.getSubtitle());
if (subtitleView != null) {
subtitleView.setAlpha(textAlpha);
}
}
final TextAlphaSpan[] spans = spannedTitle.getSpans(0, spannedTitle.length(), TextAlphaSpan.class);
if (spans.length > 0) {
spans[0].setAlpha(textAlpha);
} else {
spannedTitle.setSpan(new TextAlphaSpan(textAlpha), 0, spannedTitle.length(),
Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
activity.setTitle(spannedTitle);
}
private static class ActionBarDrawable extends LayerDrawable {
@ -1443,7 +1492,7 @@ public class UserFragment extends BaseSupportFragment implements OnClickListener
private int mAlpha;
private float mOutlineAlphaFactor;
public ActionBarDrawable(Resources resources, Drawable shadow) {
public ActionBarDrawable(Drawable shadow) {
super(new Drawable[]{shadow, new ActionBarColorDrawable(true)});
mShadowDrawable = getDrawable(0);
mColorDrawable = (ColorDrawable) getDrawable(1);

View File

@ -52,4 +52,13 @@ public class CompareUtils {
return object1.equals(object2);
}
public static boolean textEquals(CharSequence text1, CharSequence text2) {
if (text1 == null || text2 == null) return text1 == text2;
if (text1 == text2) return true;
if (text1.length() != text2.length()) return false;
for (int i = 0, j = text1.length(); i < j; i++) {
if (text1.charAt(i) != text2.charAt(i)) return false;
}
return true;
}
}

View File

@ -31,6 +31,7 @@ import android.view.ViewGroup;
import android.view.ViewOutlineProvider;
import android.widget.CompoundButton;
import android.widget.ProgressBar;
import android.widget.TextView;
public final class ViewUtils {
@ -99,6 +100,18 @@ public final class ViewUtils {
return null;
}
public static TextView findViewByText(View view, CharSequence text) {
if (view instanceof TextView && CompareUtils.textEquals(text, ((TextView) view).getText()))
return (TextView) view;
if (view instanceof ViewGroup) {
for (int i = 0, j = ((ViewGroup) view).getChildCount(); i < j; i++) {
final TextView found = findViewByText(((ViewGroup) view).getChildAt(i), text);
if (found != null) return found;
}
}
return null;
}
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
static class ViewAccessorJB {
static void setBackground(final View view, final Drawable background) {