diff --git a/twidere.component.common/src/main/java/org/mariotaku/twidere/constant/SharedPreferenceConstants.java b/twidere.component.common/src/main/java/org/mariotaku/twidere/constant/SharedPreferenceConstants.java index f8b6d8e64..69afaea18 100644 --- a/twidere.component.common/src/main/java/org/mariotaku/twidere/constant/SharedPreferenceConstants.java +++ b/twidere.component.common/src/main/java/org/mariotaku/twidere/constant/SharedPreferenceConstants.java @@ -141,8 +141,6 @@ public interface SharedPreferenceConstants { String KEY_THEME_BACKGROUND = "theme_background"; @Preference(type = INT, hasDefault = true, defaultInt = DEFAULT_THEME_BACKGROUND_ALPHA) String KEY_THEME_BACKGROUND_ALPHA = "theme_background_alpha"; - @Preference(type = BOOLEAN, hasDefault = true, defaultBoolean = true) - String KEY_THEME_DARK_ACTIONBAR = "theme_dark_actionbar"; @Preference(type = INT) String KEY_THEME_COLOR = "theme_color"; @Preference(type = STRING, hasDefault = true, defaultString = DEFAULT_THEME_FONT_FAMILY) diff --git a/twidere/build.gradle b/twidere/build.gradle index 75c337e69..dbad104d0 100644 --- a/twidere/build.gradle +++ b/twidere/build.gradle @@ -80,8 +80,7 @@ dependencies { compile 'com.rengwuxian.materialedittext:library:2.0.3' compile 'com.pnikosis:materialish-progress:1.5' compile 'com.squareup.okhttp:okhttp:2.3.0' - // Disabled temporarilly due to attribute clash with subsampling-scale-image-view -// compile 'pl.droidsonroids.gif:android-gif-drawable:1.1.3' + compile 'pl.droidsonroids.gif:android-gif-drawable:1.1.5' compile 'com.github.mariotaku:MessageBubbleView:1.0' compile 'com.github.mariotaku:DragSortListView:0.6.1' compile 'com.github.mariotaku:SlidingMenu:1.3' diff --git a/twidere/src/main/AndroidManifest.xml b/twidere/src/main/AndroidManifest.xml index ddce1a4d8..28f94130c 100644 --- a/twidere/src/main/AndroidManifest.xml +++ b/twidere/src/main/AndroidManifest.xml @@ -1,8 +1,9 @@ - + @@ -276,6 +277,7 @@ android:label="@string/set_color" android:theme="@style/Theme.Twidere.Light.NoDisplay"/> - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package org.mariotaku.twidere.activity; - -import android.annotation.SuppressLint; -import android.os.Bundle; - -import org.mariotaku.twidere.Constants; -import org.mariotaku.twidere.app.TwidereApplication; -import org.mariotaku.twidere.fragment.support.BasePullToRefreshListFragment; -import org.mariotaku.twidere.util.AsyncTwitterWrapper; -import org.mariotaku.twidere.util.MessagesManager; -import org.mariotaku.twidere.util.ThemeUtils; - -@SuppressLint("Registered") -public class BaseActivity extends BaseThemedActivity implements Constants { - - private boolean mInstanceStateSaved, mIsVisible, mIsOnTop; - - public MessagesManager getMessagesManager() { - return getTwidereApplication() != null ? getTwidereApplication().getMessagesManager() : null; - } - - @Override - public int getThemeColor() { - return ThemeUtils.getUserAccentColor(this); - } - - @Override - public int getThemeResourceId() { - return ThemeUtils.getThemeResource(this); - } - - public TwidereApplication getTwidereApplication() { - return (TwidereApplication) getApplication(); - } - - public AsyncTwitterWrapper getTwitterWrapper() { - return getTwidereApplication() != null ? getTwidereApplication().getTwitterWrapper() : null; - } - - public boolean isOnTop() { - return mIsOnTop; - } - - public boolean isVisible() { - return mIsVisible; - } - - protected BasePullToRefreshListFragment getCurrentPullToRefreshFragment() { - return null; - } - - protected boolean isStateSaved() { - return mInstanceStateSaved; - } - - @Override - protected void onPause() { - mIsOnTop = false; - super.onPause(); - } - - @Override - protected void onResume() { - super.onResume(); - mInstanceStateSaved = false; - mIsOnTop = true; - } - - @Override - protected void onSaveInstanceState(final Bundle outState) { - mInstanceStateSaved = true; - super.onSaveInstanceState(outState); - } - - @Override - protected void onStart() { - super.onStart(); - mIsVisible = true; - final MessagesManager croutons = getMessagesManager(); - if (croutons != null) { - croutons.addMessageCallback(this); - } - } - - @Override - protected void onStop() { - mIsVisible = false; - final MessagesManager croutons = getMessagesManager(); - if (croutons != null) { - croutons.removeMessageCallback(this); - } - super.onStop(); - } - -} diff --git a/twidere/src/main/java/org/mariotaku/twidere/activity/FiltersActivity.java b/twidere/src/main/java/org/mariotaku/twidere/activity/FiltersActivity.java index 51857df48..b51ea38fc 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/activity/FiltersActivity.java +++ b/twidere/src/main/java/org/mariotaku/twidere/activity/FiltersActivity.java @@ -38,6 +38,7 @@ import android.support.v4.app.FragmentActivity; import android.support.v4.app.FragmentTransaction; import android.support.v4.view.ViewPager; import android.support.v4.view.ViewPager.OnPageChangeListener; +import android.support.v4.view.WindowCompat; import android.support.v4.widget.SimpleCursorAdapter; import android.support.v7.app.ActionBar; import android.support.v7.app.ActionBar.Tab; @@ -131,6 +132,7 @@ public class FiltersActivity extends BaseActionBarActivity implements TabListene @Override public void onCreate(final Bundle savedInstanceState) { + supportRequestWindowFeature(WindowCompat.FEATURE_ACTION_BAR); super.onCreate(savedInstanceState); mPreferences = getSharedPreferences(SHARED_PREFERENCES_NAME, MODE_PRIVATE); setContentView(R.layout.activity_filters); diff --git a/twidere/src/main/java/org/mariotaku/twidere/activity/support/AccountsManagerActivity.java b/twidere/src/main/java/org/mariotaku/twidere/activity/support/AccountsManagerActivity.java index 41e75da5c..08dfa96af 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/activity/support/AccountsManagerActivity.java +++ b/twidere/src/main/java/org/mariotaku/twidere/activity/support/AccountsManagerActivity.java @@ -5,6 +5,7 @@ import android.os.Bundle; 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.view.MenuItem; @@ -40,6 +41,7 @@ public class AccountsManagerActivity extends BaseActionBarActivity { @Override protected void onCreate(Bundle savedInstanceState) { + supportRequestWindowFeature(WindowCompat.FEATURE_ACTION_BAR); super.onCreate(savedInstanceState); final ActionBar actionBar = getSupportActionBar(); if (actionBar != null) { diff --git a/twidere/src/main/java/org/mariotaku/twidere/activity/support/DraftsActivity.java b/twidere/src/main/java/org/mariotaku/twidere/activity/support/DraftsActivity.java index d80b95755..ec358a81e 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/activity/support/DraftsActivity.java +++ b/twidere/src/main/java/org/mariotaku/twidere/activity/support/DraftsActivity.java @@ -40,6 +40,7 @@ import android.support.v4.app.FragmentActivity; import android.support.v4.app.LoaderManager.LoaderCallbacks; import android.support.v4.content.CursorLoader; import android.support.v4.content.Loader; +import android.support.v4.view.WindowCompat; import android.support.v7.app.ActionBar; import android.util.Log; import android.util.SparseBooleanArray; @@ -193,6 +194,7 @@ public class DraftsActivity extends BaseActionBarActivity implements LoaderCallb @Override protected void onCreate(final Bundle savedInstanceState) { + supportRequestWindowFeature(WindowCompat.FEATURE_ACTION_BAR); super.onCreate(savedInstanceState); mResolver = getContentResolver(); mPreferences = getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE); diff --git a/twidere/src/main/java/org/mariotaku/twidere/activity/support/HomeActivity.java b/twidere/src/main/java/org/mariotaku/twidere/activity/support/HomeActivity.java index 72a579d93..39ec8a0e9 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/activity/support/HomeActivity.java +++ b/twidere/src/main/java/org/mariotaku/twidere/activity/support/HomeActivity.java @@ -102,7 +102,7 @@ import org.mariotaku.twidere.util.ThemeUtils; import org.mariotaku.twidere.util.Utils; import org.mariotaku.twidere.util.accessor.ActivityAccessor; import org.mariotaku.twidere.util.accessor.ActivityAccessor.TaskDescriptionCompat; -import org.mariotaku.twidere.util.accessor.ViewAccessor; +import org.mariotaku.twidere.util.ViewUtils; import org.mariotaku.twidere.util.message.TaskStateChangedEvent; import org.mariotaku.twidere.util.message.UnreadCountUpdatedEvent; import org.mariotaku.twidere.view.ExtendedViewPager; @@ -236,11 +236,6 @@ public class HomeActivity extends BaseActionBarActivity implements OnClickListen notifyControlBarOffsetChanged(); } - @Override - public int getThemeResourceId() { - return ThemeUtils.getNoActionBarThemeResource(this); - } - @Override public boolean onKeyUp(final int keyCode, @NonNull final KeyEvent event) { switch (keyCode) { @@ -789,7 +784,7 @@ public class HomeActivity extends BaseActionBarActivity implements OnClickListen final int actionBarAlpha = isTransparent ? ThemeUtils.getUserThemeBackgroundAlpha(this) : 0xFF; final IHomeActionButton homeActionButton = (IHomeActionButton) mActionsButton; mTabIndicator.setItemContext(ThemeUtils.getActionBarContext(this)); - ViewAccessor.setBackground(mActionBar, ThemeUtils.getActionBarBackground(this, themeResId, themeColor, true)); + ViewUtils.setBackground(mActionBar, ThemeUtils.getActionBarBackground(this, themeResId, themeColor, true)); if (ThemeUtils.isDarkTheme(themeResId)) { final int backgroundColor = ThemeUtils.getThemeBackgroundColor(mTabIndicator.getItemContext()); final int foregroundColor = ThemeUtils.getThemeForegroundColor(mTabIndicator.getItemContext()); @@ -817,7 +812,7 @@ public class HomeActivity extends BaseActionBarActivity implements OnClickListen } mTabIndicator.setAlpha(actionBarAlpha / 255f); mActionsButton.setAlpha(actionBarAlpha / 255f); - ViewAccessor.setBackground(mActionBarOverlay, ThemeUtils.getWindowContentOverlay(this)); + ViewUtils.setBackground(mActionBarOverlay, ThemeUtils.getWindowContentOverlay(this)); } private void setupHomeTabs() { @@ -859,7 +854,7 @@ public class HomeActivity extends BaseActionBarActivity implements OnClickListen mSlidingMenu.setBehindCanvasTransformer(new ListenerCanvasTransformer(this)); final Window window = getWindow(); final Drawable windowBackground = ThemeUtils.getWindowBackground(this, getCurrentThemeResourceId()); - ViewAccessor.setBackground(mSlidingMenu.getContent(), windowBackground); + ViewUtils.setBackground(mSlidingMenu.getContent(), windowBackground); window.setBackgroundDrawable(new EmptyDrawable(windowBackground)); } diff --git a/twidere/src/main/java/org/mariotaku/twidere/activity/support/LinkHandlerActivity.java b/twidere/src/main/java/org/mariotaku/twidere/activity/support/LinkHandlerActivity.java index 0ee9e353a..7a93ca155 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/activity/support/LinkHandlerActivity.java +++ b/twidere/src/main/java/org/mariotaku/twidere/activity/support/LinkHandlerActivity.java @@ -21,6 +21,7 @@ package org.mariotaku.twidere.activity.support; import android.annotation.SuppressLint; import android.content.Intent; +import android.graphics.Color; import android.graphics.Rect; import android.net.Uri; import android.os.Build; @@ -30,8 +31,11 @@ import android.support.v4.app.Fragment; import android.support.v4.app.FragmentTransaction; import android.support.v4.view.WindowCompat; import android.support.v7.app.ActionBar; +import android.support.v7.widget.Toolbar; import android.view.KeyEvent; +import android.view.Menu; import android.view.MenuItem; +import android.view.View; import android.view.Window; import android.view.WindowManager.LayoutParams; @@ -43,6 +47,7 @@ import org.mariotaku.twidere.fragment.iface.IBaseFragment.SystemWindowsInsetsCal import org.mariotaku.twidere.fragment.iface.IBasePullToRefreshFragment; import org.mariotaku.twidere.fragment.iface.SupportFragmentCallback; import org.mariotaku.twidere.fragment.support.SearchFragment; +import org.mariotaku.twidere.util.ColorUtils; import org.mariotaku.twidere.util.KeyboardShortcutsHandler; import org.mariotaku.twidere.util.KeyboardShortcutsHandler.ShortcutCallback; import org.mariotaku.twidere.util.MultiSelectEventHandler; @@ -66,12 +71,19 @@ public class LinkHandlerActivity extends BaseActionBarActivity implements System private TintedStatusFrameLayout mMainContent; private boolean mFinishOnly; + private int mActionBarItemsColor; @Override public Fragment getCurrentVisibleFragment() { return getSupportFragmentManager().findFragmentById(R.id.main_content); } + + @Override + public int getThemeResourceId() { + return R.style.Theme_Twidere_Light_DialogWhenLarge; + } + @Override public void onDetachFragment(Fragment fragment) { @@ -153,6 +165,19 @@ public class LinkHandlerActivity extends BaseActionBarActivity implements System return false; } + @Override + protected boolean onPrepareOptionsPanel(View view, Menu menu) { + final boolean result = super.onPrepareOptionsPanel(view, menu); + if (mActionBarItemsColor != 0) { + final View actionBarView = getWindow().findViewById(android.support.v7.appcompat.R.id.action_bar); + if (actionBarView instanceof Toolbar) { + ((Toolbar) actionBarView).setTitleTextColor(mActionBarItemsColor); + ThemeUtils.setActionBarOverflowColor((Toolbar) actionBarView, mActionBarItemsColor); + } + } + return result; + } + @Override protected void onCreate(final Bundle savedInstanceState) { mMultiSelectHandler = new MultiSelectEventHandler(this); @@ -166,7 +191,7 @@ public class LinkHandlerActivity extends BaseActionBarActivity implements System final ActionBar actionBar = getSupportActionBar(); if (actionBar != null) { actionBar.setDisplayHomeAsUpEnabled(true); - setActionBarBackground(actionBar, linkId, data); + setActionBarTheme(actionBar, linkId, data); } setContentView(R.layout.activity_content_fragment); mMainContent.setOnFitSystemWindowsListener(this); @@ -206,6 +231,7 @@ public class LinkHandlerActivity extends BaseActionBarActivity implements System if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { window.addFlags(LayoutParams.FLAG_TRANSLUCENT_STATUS); } + supportRequestWindowFeature(WindowCompat.FEATURE_ACTION_BAR); supportRequestWindowFeature(WindowCompat.FEATURE_ACTION_BAR_OVERLAY); supportRequestWindowFeature(WindowCompat.FEATURE_ACTION_MODE_OVERLAY); final int transitionRes; @@ -230,28 +256,34 @@ public class LinkHandlerActivity extends BaseActionBarActivity implements System } @SuppressLint("AppCompatMethod") - private void setActionBarBackground(ActionBar actionBar, int linkId, Uri data) { + private void setActionBarTheme(ActionBar actionBar, int linkId, Uri data) { + final int currentThemeColor = getCurrentThemeColor(); + int actionBarItemsColor = ColorUtils.getContrastYIQ(currentThemeColor, 192); switch (linkId) { case LINK_ID_USER: { + actionBarItemsColor = Color.WHITE; break; } case LINK_ID_SEARCH: case LINK_ID_USER_LISTS: { ThemeUtils.applyActionBarBackground(actionBar, this, getCurrentThemeResourceId(), - getCurrentThemeColor(), false); + currentThemeColor, false); ThemeUtils.applyActionBarBackground(getActionBar(), this, getCurrentThemeResourceId(), - getCurrentThemeColor(), true); + currentThemeColor, true); break; } default: { ThemeUtils.applyActionBarBackground(actionBar, this, getCurrentThemeResourceId(), - getCurrentThemeColor(), true); + currentThemeColor, true); ThemeUtils.applyActionBarBackground(getActionBar(), this, getCurrentThemeResourceId(), - getCurrentThemeColor(), true); + currentThemeColor, true); break; } } - + if (actionBarItemsColor != 0) { + ThemeUtils.setActionBarItemsColor(getWindow(), actionBar, actionBarItemsColor); + } + mActionBarItemsColor = actionBarItemsColor; } private void setStatusBarColor(int linkId, Uri uri) { diff --git a/twidere/src/main/java/org/mariotaku/twidere/activity/support/SignInActivity.java b/twidere/src/main/java/org/mariotaku/twidere/activity/support/SignInActivity.java index ccec06b92..65b676b46 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/activity/support/SignInActivity.java +++ b/twidere/src/main/java/org/mariotaku/twidere/activity/support/SignInActivity.java @@ -68,7 +68,7 @@ import org.mariotaku.twidere.util.ParseUtils; import org.mariotaku.twidere.util.ThemeUtils; import org.mariotaku.twidere.util.TwitterContentUtils; import org.mariotaku.twidere.util.Utils; -import org.mariotaku.twidere.util.accessor.ViewAccessor; +import org.mariotaku.twidere.util.ViewUtils; import org.mariotaku.twidere.util.net.OkHttpClientFactory; import org.mariotaku.twidere.util.net.TwidereHostResolverFactory; @@ -327,7 +327,7 @@ public class SignInActivity extends BaseActionBarActivity implements TwitterCons mEditPassword.addTextChangedListener(this); final Resources resources = getResources(); final ColorStateList color = ColorStateList.valueOf(resources.getColor(R.color.material_light_green)); - ViewAccessor.setBackgroundTintList(mSignInButton, color); + ViewUtils.setBackgroundTintList(mSignInButton, color); setSignInButton(); } diff --git a/twidere/src/main/java/org/mariotaku/twidere/activity/support/UserProfileEditorActivity.java b/twidere/src/main/java/org/mariotaku/twidere/activity/support/UserProfileEditorActivity.java index f9aa30573..549383f31 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/activity/support/UserProfileEditorActivity.java +++ b/twidere/src/main/java/org/mariotaku/twidere/activity/support/UserProfileEditorActivity.java @@ -53,7 +53,7 @@ import org.mariotaku.twidere.util.MediaLoaderWrapper; import org.mariotaku.twidere.util.ParseUtils; import org.mariotaku.twidere.util.ThemeUtils; import org.mariotaku.twidere.util.TwitterWrapper; -import org.mariotaku.twidere.util.accessor.ViewAccessor; +import org.mariotaku.twidere.util.ViewUtils; import org.mariotaku.twidere.view.ForegroundColorView; import org.mariotaku.twidere.view.iface.IExtendedView.OnSizeChangedListener; @@ -118,7 +118,7 @@ public class UserProfileEditorActivity extends BaseActionBarActivity implements @Override public int getThemeResourceId() { - return ThemeUtils.getNoActionBarThemeResource(this); + return ThemeUtils.getThemeResource(this); } @Override @@ -137,8 +137,8 @@ public class UserProfileEditorActivity extends BaseActionBarActivity implements setContentView(R.layout.activity_user_profile_editor); setSupportActionBar(mToolbar); - ViewAccessor.setBackground(mActionBarOverlay, ThemeUtils.getWindowContentOverlay(this)); - ViewAccessor.setBackground(mToolbar, ThemeUtils.getActionBarBackground(mToolbar.getContext(), + ViewUtils.setBackground(mActionBarOverlay, ThemeUtils.getWindowContentOverlay(this)); + ViewUtils.setBackground(mToolbar, ThemeUtils.getActionBarBackground(mToolbar.getContext(), getCurrentThemeResourceId())); // setOverrideExitAniamtion(false); mEditName.addTextChangedListener(this); diff --git a/twidere/src/main/java/org/mariotaku/twidere/adapter/decorator/DividerItemDecoration.java b/twidere/src/main/java/org/mariotaku/twidere/adapter/decorator/DividerItemDecoration.java index 8eb0c3b95..549fb1cf6 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/adapter/decorator/DividerItemDecoration.java +++ b/twidere/src/main/java/org/mariotaku/twidere/adapter/decorator/DividerItemDecoration.java @@ -88,6 +88,7 @@ public class DividerItemDecoration extends RecyclerView.ItemDecoration { } public void drawVertical(Canvas c, RecyclerView parent) { + if (mDivider == null) return; final int left = parent.getPaddingLeft(); final int right = parent.getWidth() - parent.getPaddingRight(); @@ -109,6 +110,7 @@ public class DividerItemDecoration extends RecyclerView.ItemDecoration { } public void drawHorizontal(Canvas c, RecyclerView parent) { + if (mDivider == null) return; final int top = parent.getPaddingTop(); final int bottom = parent.getHeight() - parent.getPaddingBottom(); @@ -131,6 +133,7 @@ public class DividerItemDecoration extends RecyclerView.ItemDecoration { @Override public void getItemOffsets(Rect outRect, View view, RecyclerView parent, State state) { + if (mDivider == null) return; final int childPos = parent.getChildAdapterPosition(view); final int start = getDecorationStart(), end = getDecorationEnd(parent); if (start >= 0 && childPos < start || end >= 0 && childPos > end) { diff --git a/twidere/src/main/java/org/mariotaku/twidere/app/TwidereApplication.java b/twidere/src/main/java/org/mariotaku/twidere/app/TwidereApplication.java index 2031b67ef..7ce52c4db 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/app/TwidereApplication.java +++ b/twidere/src/main/java/org/mariotaku/twidere/app/TwidereApplication.java @@ -81,6 +81,7 @@ public class TwidereApplication extends MultiDexApplication implements Constants private static final String KEY_UCD_DATA_PROFILING = "ucd_data_profiling"; private static final String KEY_SPICE_DATA_PROFILING = "spice_data_profiling"; + private static final String KEY_KEYBOARD_SHORTCUT_INITIALIZED = "keyboard_shortcut_initialized"; private Handler mHandler; private MediaLoaderWrapper mMediaLoaderWrapper; @@ -143,8 +144,11 @@ public class TwidereApplication extends MultiDexApplication implements Constants public KeyboardShortcutsHandler getKeyboardShortcutsHandler() { if (mKeyboardShortcutsHandler != null) return mKeyboardShortcutsHandler; mKeyboardShortcutsHandler = new KeyboardShortcutsHandler(this); - if (mKeyboardShortcutsHandler.isEmpty()) { + final SharedPreferences preferences = getSharedPreferences(); + if (mKeyboardShortcutsHandler.isEmpty() + && !preferences.getBoolean(KEY_KEYBOARD_SHORTCUT_INITIALIZED, false)) { mKeyboardShortcutsHandler.reset(); + preferences.edit().putBoolean(KEY_KEYBOARD_SHORTCUT_INITIALIZED, true); } return mKeyboardShortcutsHandler; } @@ -225,8 +229,6 @@ public class TwidereApplication extends MultiDexApplication implements Constants mDefaultUserAgent = UserAgentUtils.getDefaultUserAgentString(this); mHandler = new Handler(); mMessageBus = new Bus(); - mPreferences = getSharedPreferences(SHARED_PREFERENCES_NAME, MODE_PRIVATE); - mPreferences.registerOnSharedPreferenceChangeListener(this); initializeAsyncTask(); initAccountColor(this); initUserColor(this); @@ -258,12 +260,13 @@ public class TwidereApplication extends MultiDexApplication implements Constants } private void migrateUsageStatisticsPreferences() { - final boolean hasUsageStatistics = mPreferences.contains(KEY_USAGE_STATISTICS); + final SharedPreferences preferences = getSharedPreferences(); + final boolean hasUsageStatistics = preferences.contains(KEY_USAGE_STATISTICS); if (hasUsageStatistics) return; - if (mPreferences.contains(KEY_UCD_DATA_PROFILING) || mPreferences.contains(KEY_SPICE_DATA_PROFILING)) { - final boolean prevUsageEnabled = mPreferences.getBoolean(KEY_UCD_DATA_PROFILING, false) - || mPreferences.getBoolean(KEY_SPICE_DATA_PROFILING, false); - final Editor editor = mPreferences.edit(); + if (preferences.contains(KEY_UCD_DATA_PROFILING) || preferences.contains(KEY_SPICE_DATA_PROFILING)) { + final boolean prevUsageEnabled = preferences.getBoolean(KEY_UCD_DATA_PROFILING, false) + || preferences.getBoolean(KEY_SPICE_DATA_PROFILING, false); + final Editor editor = preferences.edit(); editor.putBoolean(KEY_USAGE_STATISTICS, prevUsageEnabled); editor.remove(KEY_UCD_DATA_PROFILING); editor.remove(KEY_SPICE_DATA_PROFILING); @@ -271,6 +274,13 @@ public class TwidereApplication extends MultiDexApplication implements Constants } } + private SharedPreferences getSharedPreferences() { + if (mPreferences != null) return mPreferences; + mPreferences = getSharedPreferences(SHARED_PREFERENCES_NAME, MODE_PRIVATE); + mPreferences.registerOnSharedPreferenceChangeListener(this); + return mPreferences; + } + @Override public void onLowMemory() { if (mMediaLoaderWrapper != null) { diff --git a/twidere/src/main/java/org/mariotaku/twidere/fragment/KeyboardShortcutsFragment.java b/twidere/src/main/java/org/mariotaku/twidere/fragment/KeyboardShortcutsFragment.java index 47d3d9660..178a53b6d 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/fragment/KeyboardShortcutsFragment.java +++ b/twidere/src/main/java/org/mariotaku/twidere/fragment/KeyboardShortcutsFragment.java @@ -23,8 +23,10 @@ import android.app.Activity; import android.app.AlertDialog; import android.app.AlertDialog.Builder; import android.app.Dialog; +import android.app.DialogFragment; import android.content.Context; import android.content.DialogInterface; +import android.content.DialogInterface.OnClickListener; import android.content.DialogInterface.OnKeyListener; import android.content.SharedPreferences; import android.content.SharedPreferences.OnSharedPreferenceChangeListener; @@ -38,6 +40,7 @@ import android.text.TextUtils; import android.view.KeyEvent; import android.view.Menu; import android.view.MenuInflater; +import android.view.MenuItem; import android.view.View; import android.widget.TextView; @@ -53,9 +56,22 @@ public class KeyboardShortcutsFragment extends BasePreferenceFragment { private KeyboardShortcutsHandler mKeyboardShortcutHandler; + @Override + public boolean onOptionsItemSelected(MenuItem item) { + switch (item.getItemId()) { + case MENU_RESET: { + final DialogFragment f = new ResetKeyboardShortcutConfirmDialogFragment(); + f.show(getFragmentManager().beginTransaction(), "reset_keyboard_shortcut_confirm"); + return true; + } + } + return super.onOptionsItemSelected(item); + } + @Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); + setHasOptionsMenu(true); final Activity activity = getActivity(); mKeyboardShortcutHandler = TwidereApplication.getInstance(activity).getKeyboardShortcutsHandler(); final PreferenceScreen defaultScreen = getPreferenceScreen(); @@ -213,4 +229,27 @@ public class KeyboardShortcutsFragment extends BasePreferenceFragment { setSummary(spec != null ? spec.toKeyString() : null); } } + + public static class ResetKeyboardShortcutConfirmDialogFragment extends DialogFragment implements OnClickListener { + @Override + public void onClick(DialogInterface dialog, int which) { + switch (which) { + case DialogInterface.BUTTON_POSITIVE: { + TwidereApplication app = TwidereApplication.getInstance(getActivity()); + app.getKeyboardShortcutsHandler().reset(); + break; + } + } + } + + @NonNull + @Override + public Dialog onCreateDialog(Bundle savedInstanceState) { + final AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); + builder.setMessage(R.string.reset_keyboard_shortcuts_confirm); + builder.setPositiveButton(android.R.string.ok, this); + builder.setNegativeButton(android.R.string.cancel, this); + return builder.create(); + } + } } diff --git a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/DataExportImportTypeSelectorDialogFragment.java b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/DataExportImportTypeSelectorDialogFragment.java index 4c206af5f..bb8fee869 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/DataExportImportTypeSelectorDialogFragment.java +++ b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/DataExportImportTypeSelectorDialogFragment.java @@ -27,6 +27,7 @@ import android.content.DialogInterface.OnClickListener; import android.content.DialogInterface.OnMultiChoiceClickListener; import android.content.DialogInterface.OnShowListener; import android.os.Bundle; +import android.support.annotation.NonNull; import android.support.v4.app.FragmentActivity; import android.util.SparseBooleanArray; import android.view.View; @@ -40,165 +41,168 @@ import android.widget.TextView; import org.mariotaku.twidere.R; import org.mariotaku.twidere.adapter.ArrayAdapter; import org.mariotaku.twidere.fragment.iface.ISupportDialogFragmentCallback; +import org.mariotaku.twidere.util.DataImportExportUtils; public final class DataExportImportTypeSelectorDialogFragment extends BaseSupportDialogFragment implements - OnMultiChoiceClickListener, OnClickListener, OnShowListener, OnItemClickListener { + OnMultiChoiceClickListener, OnClickListener, OnShowListener, OnItemClickListener { - private TypeAdapter mAdapter; - private ListView mListView; + private TypeAdapter mAdapter; + private ListView mListView; - @Override - public void onCancel(final DialogInterface dialog) { - super.onCancel(dialog); - final FragmentActivity a = getActivity(); - if (a instanceof Callback) { - ((Callback) a).onCancelled(this); - } - } + @Override + public void onCancel(final DialogInterface dialog) { + super.onCancel(dialog); + final FragmentActivity a = getActivity(); + if (a instanceof Callback) { + ((Callback) a).onCancelled(this); + } + } - @Override - public final void onClick(final DialogInterface dialog, final int which) { - switch (which) { - case DialogInterface.BUTTON_POSITIVE: { - final int flags = getCheckedFlags(); - onPositiveButtonClicked(flags); - break; - } - } - } + @Override + public final void onClick(final DialogInterface dialog, final int which) { + switch (which) { + case DialogInterface.BUTTON_POSITIVE: { + final int flags = getCheckedFlags(); + onPositiveButtonClicked(flags); + break; + } + } + } - @Override - public final void onClick(final DialogInterface dialog, final int which, final boolean isChecked) { - updatePositiveButton(dialog); - } + @Override + public final void onClick(final DialogInterface dialog, final int which, final boolean isChecked) { + updatePositiveButton(dialog); + } - @Override - public final Dialog onCreateDialog(final Bundle savedInstanceState) { - final Context context = getActivity(); - final int flags = getEnabledFlags(); - mAdapter = new TypeAdapter(context, flags); - mListView = new ListView(context); - mAdapter.add(new Type(R.string.settings, FLAG_PREFERENCES)); - mAdapter.add(new Type(R.string.nicknames, FLAG_NICKNAMES)); - mAdapter.add(new Type(R.string.user_colors, FLAG_USER_COLORS)); - mAdapter.add(new Type(R.string.custom_host_mapping, FLAG_HOST_MAPPING)); - mListView.setAdapter(mAdapter); - mListView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE); - mListView.setOnItemClickListener(this); - for (int i = 0, j = mAdapter.getCount(); i < j; i++) { - mListView.setItemChecked(i, mAdapter.isEnabled(i)); - } - final AlertDialog.Builder builder = new AlertDialog.Builder(context); - builder.setTitle(getTitle()); - builder.setView(mListView); - builder.setPositiveButton(android.R.string.ok, this); - builder.setNegativeButton(android.R.string.cancel, null); - final AlertDialog dialog = builder.create(); - dialog.setOnShowListener(this); - return dialog; - } + @NonNull + @Override + public final Dialog onCreateDialog(final Bundle savedInstanceState) { + final Context context = getActivity(); + final int flags = getEnabledFlags(); + mAdapter = new TypeAdapter(context, flags); + mListView = new ListView(context); + mAdapter.add(new Type(R.string.settings, DataImportExportUtils.FLAG_PREFERENCES)); + mAdapter.add(new Type(R.string.nicknames, DataImportExportUtils.FLAG_NICKNAMES)); + mAdapter.add(new Type(R.string.user_colors, DataImportExportUtils.FLAG_USER_COLORS)); + mAdapter.add(new Type(R.string.custom_host_mapping, DataImportExportUtils.FLAG_HOST_MAPPING)); + mAdapter.add(new Type(R.string.keyboard_shortcuts, DataImportExportUtils.FLAG_KEYBOARD_SHORTCUTS)); + mListView.setAdapter(mAdapter); + mListView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE); + mListView.setOnItemClickListener(this); + for (int i = 0, j = mAdapter.getCount(); i < j; i++) { + mListView.setItemChecked(i, mAdapter.isEnabled(i)); + } + final AlertDialog.Builder builder = new AlertDialog.Builder(context); + builder.setTitle(getTitle()); + builder.setView(mListView); + builder.setPositiveButton(android.R.string.ok, this); + builder.setNegativeButton(android.R.string.cancel, null); + final AlertDialog dialog = builder.create(); + dialog.setOnShowListener(this); + return dialog; + } - @Override - public void onDismiss(final DialogInterface dialog) { - super.onDismiss(dialog); - final FragmentActivity a = getActivity(); - if (a instanceof Callback) { - ((Callback) a).onDismissed(this); - } - } + @Override + public void onDismiss(final DialogInterface dialog) { + super.onDismiss(dialog); + final FragmentActivity a = getActivity(); + if (a instanceof Callback) { + ((Callback) a).onDismissed(this); + } + } - @Override - public void onItemClick(final AdapterView view, final View child, final int position, final long id) { - updatePositiveButton(getDialog()); - } + @Override + public void onItemClick(final AdapterView view, final View child, final int position, final long id) { + updatePositiveButton(getDialog()); + } - @Override - public final void onShow(final DialogInterface dialog) { - updatePositiveButton(dialog); - } + @Override + public final void onShow(final DialogInterface dialog) { + updatePositiveButton(dialog); + } - private int getCheckedFlags() { - final SparseBooleanArray checked = mListView.getCheckedItemPositions(); - int flags = 0; - for (int i = 0, j = checked.size(); i < j; i++) { - final Type type = (Type) mListView.getItemAtPosition(i); - if (checked.valueAt(i)) { - flags |= type.flag; - } - } - return flags; - } + private int getCheckedFlags() { + final SparseBooleanArray checked = mListView.getCheckedItemPositions(); + int flags = 0; + for (int i = 0, j = checked.size(); i < j; i++) { + final Type type = (Type) mListView.getItemAtPosition(i); + if (checked.valueAt(i)) { + flags |= type.flag; + } + } + return flags; + } - private int getEnabledFlags() { - final Bundle args = getArguments(); - if (args == null) return FLAG_ALL; - return args.getInt(EXTRA_FLAGS, FLAG_ALL); - } + private int getEnabledFlags() { + final Bundle args = getArguments(); + if (args == null) return DataImportExportUtils.FLAG_ALL; + return args.getInt(EXTRA_FLAGS, DataImportExportUtils.FLAG_ALL); + } - private CharSequence getTitle() { - final Bundle args = getArguments(); - if (args == null) return null; - return args.getCharSequence(EXTRA_TITLE); - } + private CharSequence getTitle() { + final Bundle args = getArguments(); + if (args == null) return null; + return args.getCharSequence(EXTRA_TITLE); + } - private void onPositiveButtonClicked(final int flags) { - final FragmentActivity a = getActivity(); - final Bundle args = getArguments(); - if (args == null) return; - final String path = args.getString(EXTRA_PATH); - if (a instanceof Callback) { - ((Callback) a).onPositiveButtonClicked(path, flags); - } - } + private void onPositiveButtonClicked(final int flags) { + final FragmentActivity a = getActivity(); + final Bundle args = getArguments(); + if (args == null) return; + final String path = args.getString(EXTRA_PATH); + if (a instanceof Callback) { + ((Callback) a).onPositiveButtonClicked(path, flags); + } + } - private void updatePositiveButton(final DialogInterface dialog) { - if (!(dialog instanceof AlertDialog)) return; - final AlertDialog alertDialog = (AlertDialog) dialog; - final Button positiveButton = alertDialog.getButton(DialogInterface.BUTTON_POSITIVE); - positiveButton.setEnabled(getCheckedFlags() != 0); - } + private void updatePositiveButton(final DialogInterface dialog) { + if (!(dialog instanceof AlertDialog)) return; + final AlertDialog alertDialog = (AlertDialog) dialog; + final Button positiveButton = alertDialog.getButton(DialogInterface.BUTTON_POSITIVE); + positiveButton.setEnabled(getCheckedFlags() != 0); + } - public static interface Callback extends ISupportDialogFragmentCallback { - void onPositiveButtonClicked(String path, int flags); - } + public static interface Callback extends ISupportDialogFragmentCallback { + void onPositiveButtonClicked(String path, int flags); + } - private static class Type { - private final int title, flag; + private static class Type { + private final int title, flag; - Type(final int title, final int flag) { - this.title = title; - this.flag = flag; - } - } + Type(final int title, final int flag) { + this.title = title; + this.flag = flag; + } + } - private static class TypeAdapter extends ArrayAdapter { + private static class TypeAdapter extends ArrayAdapter { - private final int mEnabledFlags; + private final int mEnabledFlags; - public TypeAdapter(final Context context, final int enabledFlags) { - super(context, android.R.layout.simple_list_item_multiple_choice); - mEnabledFlags = enabledFlags; - } + public TypeAdapter(final Context context, final int enabledFlags) { + super(context, android.R.layout.simple_list_item_multiple_choice); + mEnabledFlags = enabledFlags; + } - @Override - public boolean areAllItemsEnabled() { - return false; - } + @Override + public boolean areAllItemsEnabled() { + return false; + } - @Override - public View getView(final int position, final View convertView, final ViewGroup parent) { - final View view = super.getView(position, convertView, parent); - final TextView text1 = (TextView) view.findViewById(android.R.id.text1); - text1.setText(getItem(position).title); - view.setEnabled(isEnabled(position)); - return view; - } + @Override + public View getView(final int position, final View convertView, final ViewGroup parent) { + final View view = super.getView(position, convertView, parent); + final TextView text1 = (TextView) view.findViewById(android.R.id.text1); + text1.setText(getItem(position).title); + view.setEnabled(isEnabled(position)); + return view; + } - @Override - public boolean isEnabled(final int position) { - return (mEnabledFlags & getItem(position).flag) != 0; - } + @Override + public boolean isEnabled(final int position) { + return (mEnabledFlags & getItem(position).flag) != 0; + } - } + } } diff --git a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/QuickMenuFragment.java b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/QuickMenuFragment.java index 923632810..a01c59165 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/QuickMenuFragment.java +++ b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/QuickMenuFragment.java @@ -34,7 +34,7 @@ import org.mariotaku.twidere.fragment.support.TrendsSuggectionsFragment.TrendsAd import org.mariotaku.twidere.provider.TwidereDataStore.CachedTrends; import org.mariotaku.twidere.util.ThemeUtils; import org.mariotaku.twidere.util.Utils; -import org.mariotaku.twidere.util.accessor.ViewAccessor; +import org.mariotaku.twidere.util.ViewUtils; import org.mariotaku.twidere.view.ExtendedFrameLayout; import org.mariotaku.twidere.view.iface.IExtendedView.OnFitSystemWindowsListener; @@ -127,7 +127,7 @@ public class QuickMenuFragment extends BaseSupportFragment implements OnFitSyste mSlidingUpPanel = (SlidingUpPanelLayout) view.findViewById(R.id.activities_drawer); mActivitiesConfigButton = (ImageButton) view.findViewById(R.id.activities_config_button); final View activitiesContainer = view.findViewById(R.id.activities_container); - ViewAccessor.setBackground(activitiesContainer, ThemeUtils.getWindowBackground(getThemedContext())); + ViewUtils.setBackground(activitiesContainer, ThemeUtils.getWindowBackground(getThemedContext())); } @Override diff --git a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/UserFragment.java b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/UserFragment.java index e53d7f56f..aa170be34 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/UserFragment.java +++ b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/UserFragment.java @@ -57,6 +57,8 @@ import android.support.v4.content.res.ResourcesCompat; import android.support.v4.view.ViewCompat; import android.support.v4.view.ViewPager; 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; @@ -85,6 +87,7 @@ import org.mariotaku.twidere.activity.iface.IThemedActivity; import org.mariotaku.twidere.activity.support.AccountSelectorActivity; import org.mariotaku.twidere.activity.support.ColorPickerDialogActivity; import org.mariotaku.twidere.activity.support.LinkHandlerActivity; +import org.mariotaku.twidere.activity.support.ThemedActionBarActivity; import org.mariotaku.twidere.activity.support.UserListSelectorActivity; import org.mariotaku.twidere.activity.support.UserProfileEditorActivity; import org.mariotaku.twidere.adapter.support.SupportTabsAdapter; @@ -116,9 +119,9 @@ import org.mariotaku.twidere.util.TwidereLinkify; import org.mariotaku.twidere.util.TwidereLinkify.OnLinkClickListener; import org.mariotaku.twidere.util.UserColorNameUtils; import org.mariotaku.twidere.util.Utils; +import org.mariotaku.twidere.util.ViewUtils; import org.mariotaku.twidere.util.accessor.ActivityAccessor; import org.mariotaku.twidere.util.accessor.ActivityAccessor.TaskDescriptionCompat; -import org.mariotaku.twidere.util.accessor.ViewAccessor; import org.mariotaku.twidere.util.menu.TwidereMenuInfo; import org.mariotaku.twidere.util.message.FriendshipUpdatedEvent; import org.mariotaku.twidere.util.message.ProfileUpdatedEvent; @@ -218,9 +221,11 @@ public class UserFragment extends BaseSupportFragment implements OnClickListener private boolean mGetUserInfoLoaderInitialized, mGetFriendShipLoaderInitialized; private int mBannerWidth; private int mCardBackgroundColor; + private int mActionBarShadowColor; private int mUserUiColor; private ActionBarDrawable mActionBarBackground; + private Drawable mActionBarHomeAsUpIndicator; private Fragment mCurrentVisibleFragment; @@ -413,7 +418,7 @@ public class UserFragment extends BaseSupportFragment implements OnClickListener public boolean isScrollContent(float x, float y) { final ViewPager v = mViewPager; final int[] location = new int[2]; - v.getLocationOnScreen(location); + v.getLocationInWindow(location); return x >= location[0] && x <= location[0] + v.getWidth() && y >= location[1] && y <= location[1] + v.getHeight(); } @@ -652,6 +657,7 @@ public class UserFragment extends BaseSupportFragment implements OnClickListener .registerOnSharedPreferenceChangeListener(this); mLocale = getResources().getConfiguration().locale; mCardBackgroundColor = ThemeUtils.getCardBackgroundColor(activity); + mActionBarShadowColor = 0xA0000000; mProfileImageLoader = getApplication().getMediaLoaderWrapper(); final Bundle args = getArguments(); long accountId = -1, userId = -1; @@ -1233,7 +1239,7 @@ public class UserFragment extends BaseSupportFragment implements OnClickListener if (mActionBarBackground == null) { setupBaseActionBar(); } - final FragmentActivity activity = getActivity(); + final ActionBarActivity activity = (ActionBarActivity) getActivity(); final IThemedActivity themed = (IThemedActivity) activity; final int themeRes = themed.getCurrentThemeResourceId(); if (ThemeUtils.isDarkTheme(themeRes)) { @@ -1250,7 +1256,7 @@ public class UserFragment extends BaseSupportFragment implements OnClickListener mProfileBannerView.setBackgroundColor(color); mLocationView.setLinkTextColor(color); mURLView.setLinkTextColor(color); - ViewAccessor.setBackground(mPagerIndicator, ThemeUtils.getActionBarStackedBackground(activity, themeRes, color, true)); + ViewUtils.setBackground(mPagerIndicator, ThemeUtils.getActionBarStackedBackground(activity, themeRes, color, true)); final HeaderDrawerLayout drawer = mHeaderDrawerLayout; if (drawer != null) { @@ -1270,6 +1276,8 @@ public class UserFragment extends BaseSupportFragment implements OnClickListener mActionBarBackground.setAlpha(linkHandler.getCurrentThemeBackgroundAlpha()); mProfileBannerView.setAlpha(linkHandler.getCurrentThemeBackgroundAlpha() / 255f); actionBar.setBackgroundDrawable(mActionBarBackground); + mActionBarHomeAsUpIndicator = ThemeUtils.getActionBarHomeAsUpIndicator(actionBar); + actionBar.setHomeAsUpIndicator(mActionBarHomeAsUpIndicator); } private void setupUserPages() { @@ -1358,35 +1366,43 @@ public class UserFragment extends BaseSupportFragment implements OnClickListener } mActionBarBackground.setOutlineAlphaFactor(tabOutlineAlphaFactor); - final FragmentActivity activity = getActivity(); + final ThemedActionBarActivity activity = (ThemedActionBarActivity) getActivity(); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { setCompatToolbarOverlayAlpha(activity, factor * tabOutlineAlphaFactor); } - if (activity instanceof IThemedActivity) { - final Drawable drawable = mPagerIndicator.getBackground(); - final int stackedTabColor; - if (ThemeUtils.isDarkTheme(((IThemedActivity) activity).getCurrentThemeResourceId())) { - stackedTabColor = getResources().getColor(R.color.background_color_action_bar_dark); - final int contrastColor = ColorUtils.getContrastYIQ(stackedTabColor, 192); - mPagerIndicator.setIconColor(contrastColor); - mPagerIndicator.setLabelColor(contrastColor); - mPagerIndicator.setStripColor(mUserUiColor); - } else if (drawable instanceof ColorDrawable) { - stackedTabColor = mUserUiColor; - final int tabColor = (Integer) sArgbEvaluator.evaluate(tabOutlineAlphaFactor, stackedTabColor, mCardBackgroundColor); - ((ColorDrawable) drawable).setColor(tabColor); - final int contrastColor = ColorUtils.getContrastYIQ(tabColor, 192); - mPagerIndicator.setIconColor(contrastColor); - mPagerIndicator.setLabelColor(contrastColor); - mPagerIndicator.setStripColor(contrastColor); - } - } else { - final int contrastColor = ColorUtils.getContrastYIQ(mUserUiColor, 192); + final Drawable drawable = mPagerIndicator.getBackground(); + final int stackedTabColor; + if (ThemeUtils.isDarkTheme(activity.getCurrentThemeResourceId())) { + stackedTabColor = getResources().getColor(R.color.background_color_action_bar_dark); + final int contrastColor = ColorUtils.getContrastYIQ(stackedTabColor, 192); + mPagerIndicator.setIconColor(contrastColor); + mPagerIndicator.setLabelColor(contrastColor); + mPagerIndicator.setStripColor(mUserUiColor); + } else if (drawable instanceof ColorDrawable) { + stackedTabColor = mUserUiColor; + final int tabColor = (Integer) sArgbEvaluator.evaluate(tabOutlineAlphaFactor, stackedTabColor, mCardBackgroundColor); + ((ColorDrawable) drawable).setColor(tabColor); + final int contrastColor = ColorUtils.getContrastYIQ(tabColor, 192); mPagerIndicator.setIconColor(contrastColor); mPagerIndicator.setLabelColor(contrastColor); mPagerIndicator.setStripColor(contrastColor); + } else { + // This shouldn't happen, return + return; + } + final int barColor = (Integer) sArgbEvaluator.evaluate(factor, mActionBarShadowColor, stackedTabColor); + final int itemColor = ColorUtils.getContrastYIQ(barColor, 192); + if (mActionBarHomeAsUpIndicator != null) { + mActionBarHomeAsUpIndicator.setColorFilter(itemColor, Mode.SRC_ATOP); + } + final View actionBarView = activity.getWindow().findViewById(android.support.v7.appcompat.R.id.action_bar); + if (actionBarView instanceof Toolbar) { + final Toolbar toolbar = (Toolbar) actionBarView; + toolbar.setTitleTextColor(itemColor); + ThemeUtils.setActionBarOverflowColor(toolbar, itemColor); + ThemeUtils.wrapToolbarMenuIcon(toolbar, itemColor, itemColor); } mPagerIndicator.updateAppearance(); } @@ -1395,7 +1411,7 @@ public class UserFragment extends BaseSupportFragment implements OnClickListener private void updateTitleColor() { final int[] location = new int[2]; - mNameView.getLocationOnScreen(location); + mNameView.getLocationInWindow(location); final float nameShowingRatio = (mHeaderDrawerLayout.getPaddingTop() - location[1]) / (float) mNameView.getHeight(); final int textAlpha = Math.round(0xFF * MathUtils.clamp(nameShowingRatio, 0, 1)); diff --git a/twidere/src/main/java/org/mariotaku/twidere/graphic/ActionIconDrawable.java b/twidere/src/main/java/org/mariotaku/twidere/graphic/ActionIconDrawable.java index d6f198407..c5f7a5dd8 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/graphic/ActionIconDrawable.java +++ b/twidere/src/main/java/org/mariotaku/twidere/graphic/ActionIconDrawable.java @@ -30,7 +30,8 @@ import org.mariotaku.twidere.util.menu.TwidereMenuInfo; */ public class ActionIconDrawable extends DrawableWrapper { - private final int mDefaultColor; + private int mDefaultColor; + private int mHighlightColor; public ActionIconDrawable(Drawable drawable, int defaultColor) { super(drawable); @@ -38,6 +39,16 @@ public class ActionIconDrawable extends DrawableWrapper { setHighlightColor(0); } + public int getDefaultColor() { + return mDefaultColor; + } + + public void setDefaultColor(int defaultColor) { + mDefaultColor = defaultColor; + updateColorFilter(); + } + + public static void setMenuHighlight(MenuItem item, TwidereMenuInfo info) { final Drawable icon = item.getIcon(); if (icon instanceof ActionIconDrawable) { @@ -46,7 +57,12 @@ public class ActionIconDrawable extends DrawableWrapper { } private void setHighlightColor(int color) { - setColorFilter(color == 0 ? mDefaultColor : color, Mode.SRC_ATOP); + mHighlightColor = color; + updateColorFilter(); + } + + private void updateColorFilter() { + setColorFilter(mHighlightColor == 0 ? mDefaultColor : mHighlightColor, Mode.SRC_ATOP); } } diff --git a/twidere/src/main/java/org/mariotaku/twidere/preference/SwitchSettingsDetailsPreference.java b/twidere/src/main/java/org/mariotaku/twidere/preference/SwitchSettingsDetailsPreference.java index ca75952d1..3988f1d82 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/preference/SwitchSettingsDetailsPreference.java +++ b/twidere/src/main/java/org/mariotaku/twidere/preference/SwitchSettingsDetailsPreference.java @@ -31,6 +31,7 @@ import android.widget.Switch; import org.mariotaku.twidere.Constants; import org.mariotaku.twidere.fragment.SettingsDetailsFragment; +import org.mariotaku.twidere.util.ViewUtils; /** * Created by mariotaku on 15/4/7. @@ -63,7 +64,7 @@ public class SwitchSettingsDetailsPreference extends SwitchPreference implements if (view instanceof ViewGroup) { ((ViewGroup) view).setDescendantFocusability(ViewGroup.FOCUS_BLOCK_DESCENDANTS); } - final Switch switchView = (Switch) findViewByType(view, Switch.class); + final Switch switchView = (Switch) ViewUtils.findViewByType(view, Switch.class); if (switchView != null) { switchView.setClickable(true); switchView.setFocusable(true); @@ -76,17 +77,6 @@ public class SwitchSettingsDetailsPreference extends SwitchPreference implements return mView = super.onCreateView(parent); } - private static View findViewByType(View view, Class cls) { - if (cls.isAssignableFrom(view.getClass())) return view; - if (view instanceof ViewGroup) { - for (int i = 0, j = ((ViewGroup) view).getChildCount(); i < j; i++) { - final View found = findViewByType(((ViewGroup) view).getChildAt(i), cls); - if (found != null) return found; - } - } - return null; - } - @Override protected void onClick() { diff --git a/twidere/src/main/java/org/mariotaku/twidere/preference/ThemeBackgroundPreference.java b/twidere/src/main/java/org/mariotaku/twidere/preference/ThemeBackgroundPreference.java index 9e998d620..0186cc3f4 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/preference/ThemeBackgroundPreference.java +++ b/twidere/src/main/java/org/mariotaku/twidere/preference/ThemeBackgroundPreference.java @@ -24,7 +24,7 @@ import android.widget.SeekBar.OnSeekBarChangeListener; import org.mariotaku.twidere.Constants; import org.mariotaku.twidere.R; import org.mariotaku.twidere.graphic.AlphaPatternDrawable; -import org.mariotaku.twidere.util.accessor.ViewAccessor; +import org.mariotaku.twidere.util.ViewUtils; /** * Created by mariotaku on 14/11/8. @@ -173,7 +173,7 @@ public class ThemeBackgroundPreference extends DialogPreference implements Const mAlphaSlider.setOnSeekBarChangeListener(mAlphaSliderChangedListener); mAlphaSlider.setProgress(preferences.getInt(KEY_THEME_BACKGROUND_ALPHA, DEFAULT_THEME_BACKGROUND_ALPHA)); final int patternSize = res.getDimensionPixelSize(R.dimen.element_spacing_msmall); - ViewAccessor.setBackground(mAlphaPreview, new AlphaPatternDrawable(patternSize)); + ViewUtils.setBackground(mAlphaPreview, new AlphaPatternDrawable(patternSize)); updateAlphaVisibility(); updateAlphaPreview(); diff --git a/twidere/src/main/java/org/mariotaku/twidere/preference/ThemePreviewPreference.java b/twidere/src/main/java/org/mariotaku/twidere/preference/ThemePreviewPreference.java index e4509f89d..b88d88a6a 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/preference/ThemePreviewPreference.java +++ b/twidere/src/main/java/org/mariotaku/twidere/preference/ThemePreviewPreference.java @@ -42,7 +42,7 @@ import org.mariotaku.twidere.Constants; import org.mariotaku.twidere.R; import org.mariotaku.twidere.util.ColorUtils; import org.mariotaku.twidere.util.ThemeUtils; -import org.mariotaku.twidere.util.accessor.ViewAccessor; +import org.mariotaku.twidere.util.ViewUtils; import org.mariotaku.twidere.view.iface.IExtendedView; import org.mariotaku.twidere.view.iface.IExtendedView.TouchInterceptor; @@ -109,10 +109,10 @@ public class ThemePreviewPreference extends Preference implements Constants, OnS final int cardBackgroundColor = ThemeUtils.getCardBackgroundColor(context); final int accentColor = ThemeUtils.getUserAccentColor(context); - ViewAccessor.setBackground(windowBackgroundView, ThemeUtils.getWindowBackground(context)); + ViewUtils.setBackground(windowBackgroundView, ThemeUtils.getWindowBackground(context)); // ViewAccessor.setBackground(windowContentOverlayView, ThemeUtils.getWindowContentOverlay(context)); - ViewAccessor.setBackground(actionBarView, ThemeUtils.getActionBarBackground(context, themeRes, accentColor, true)); - ViewAccessor.setBackground(actionBarOverlay, ThemeUtils.getWindowContentOverlay(context)); + ViewUtils.setBackground(actionBarView, ThemeUtils.getActionBarBackground(context, themeRes, accentColor, true)); + ViewUtils.setBackground(actionBarOverlay, ThemeUtils.getWindowContentOverlay(context)); cardView.setCardBackgroundColor(cardBackgroundColor); actionBarView.setTitle(R.string.app_name); @@ -122,7 +122,7 @@ public class ThemePreviewPreference extends Preference implements Constants, OnS inflater.inflate(R.menu.menu_status, menuBar.getMenu()); ThemeUtils.wrapMenuIcon(menuBar, MENU_GROUP_STATUS_SHARE); if (statusContentView != null) { - ViewAccessor.setBackground(statusContentView, ThemeUtils.getWindowBackground(context)); + ViewUtils.setBackground(statusContentView, ThemeUtils.getWindowBackground(context)); final View profileView = statusContentView.findViewById(R.id.profile_container); final ImageView profileImageView = (ImageView) statusContentView.findViewById(R.id.profile_image); diff --git a/twidere/src/main/java/org/mariotaku/twidere/provider/TwidereDataProvider.java b/twidere/src/main/java/org/mariotaku/twidere/provider/TwidereDataProvider.java index 5299e98cc..3b6ae66d0 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/provider/TwidereDataProvider.java +++ b/twidere/src/main/java/org/mariotaku/twidere/provider/TwidereDataProvider.java @@ -540,11 +540,15 @@ public final class TwidereDataProvider extends ContentProvider implements Consta final String[] credentialsCols = {Accounts.BASIC_AUTH_PASSWORD, Accounts.OAUTH_TOKEN, Accounts.OAUTH_TOKEN_SECRET, Accounts.CONSUMER_KEY, Accounts.CONSUMER_SECRET}; if (projection == null || TwidereArrayUtils.contains(projection, credentialsCols) - && !checkPermission(PERMISSION_ACCOUNTS)) + && !checkPermission(PERMISSION_ACCOUNTS)) { + final String pkgName = mPermissionsManager.getPackageNameByUid(Binder.getCallingUid()); throw new SecurityException("Access column " + TwidereArrayUtils.toString(projection, ',', true) - + " in database accounts requires level PERMISSION_LEVEL_ACCOUNTS"); - if (!checkPermission(PERMISSION_READ)) - throw new SecurityException("Access database " + table + " requires level PERMISSION_LEVEL_READ"); + + " in database accounts requires level PERMISSION_LEVEL_ACCOUNTS, package: " + pkgName); + } + if (!checkPermission(PERMISSION_READ)) { + final String pkgName = mPermissionsManager.getPackageNameByUid(Binder.getCallingUid()); + throw new SecurityException("Access database " + table + " requires level PERMISSION_LEVEL_READ, package: " + pkgName); + } break; } case TABLE_ID_DIRECT_MESSAGES: @@ -734,9 +738,14 @@ public final class TwidereDataProvider extends ContentProvider implements Consta } private void notifyContentObserver(final Uri uri) { - final ContentResolver cr = getContentResolver(); - if (uri == null || cr == null) return; - cr.notifyChange(uri, null); + mHandler.post(new Runnable() { + @Override + public void run() { + final ContentResolver cr = getContentResolver(); + if (uri == null || cr == null) return; + cr.notifyChange(uri, null); + } + }); } diff --git a/twidere/src/main/java/org/mariotaku/twidere/util/DataImportExportUtils.java b/twidere/src/main/java/org/mariotaku/twidere/util/DataImportExportUtils.java index 612e51463..ffe09ce81 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/util/DataImportExportUtils.java +++ b/twidere/src/main/java/org/mariotaku/twidere/util/DataImportExportUtils.java @@ -21,6 +21,7 @@ package org.mariotaku.twidere.util; import android.content.Context; import android.content.SharedPreferences; +import android.util.Log; import org.json.JSONObject; import org.mariotaku.jsonserializer.JSONFileIO; @@ -47,136 +48,158 @@ import static org.mariotaku.twidere.annotation.Preference.Type.INVALID; public class DataImportExportUtils implements Constants { - public static void exportData(final Context context, final File dst, final int flags) throws IOException { - if (dst == null) throw new FileNotFoundException(); - dst.delete(); - final FileOutputStream fos = new FileOutputStream(dst); - final ZipOutputStream zos = new ZipOutputStream(new BufferedOutputStream(fos)); - if (hasFlag(flags, FLAG_PREFERENCES)) { - writeSharedPreferencesData(zos, context, SHARED_PREFERENCES_NAME, ENTRY_PREFERENCES); - } - if (hasFlag(flags, FLAG_NICKNAMES)) { - writeRawSharedPreferencesData(zos, context, USER_NICKNAME_PREFERENCES_NAME, ENTRY_NICKNAMES); - } - if (hasFlag(flags, FLAG_USER_COLORS)) { - writeRawSharedPreferencesData(zos, context, USER_COLOR_PREFERENCES_NAME, ENTRY_USER_COLORS); - } - if (hasFlag(flags, FLAG_HOST_MAPPING)) { - writeRawSharedPreferencesData(zos, context, HOST_MAPPING_PREFERENCES_NAME, ENTRY_HOST_MAPPING); - } - zos.finish(); - zos.flush(); - Utils.closeSilently(zos); - Utils.closeSilently(fos); - } + public static final String ENTRY_PREFERENCES = "preferences.json"; + public static final String ENTRY_NICKNAMES = "nicknames.json"; + public static final String ENTRY_USER_COLORS = "user_colors.json"; + public static final String ENTRY_HOST_MAPPING = "host_mapping.json"; + public static final String ENTRY_KEYBOARD_SHORTCUTS = "keyboard_shortcuts.json"; - public static int getImportedSettingsFlags(final File src) throws IOException { - if (src == null) return 0; - final ZipFile zipFile = new ZipFile(src); - int flags = 0; - if (zipFile.getEntry(ENTRY_PREFERENCES) != null) { - flags |= FLAG_PREFERENCES; - } - if (zipFile.getEntry(ENTRY_NICKNAMES) != null) { - flags |= FLAG_NICKNAMES; - } - if (zipFile.getEntry(ENTRY_USER_COLORS) != null) { - flags |= FLAG_USER_COLORS; - } - if (zipFile.getEntry(ENTRY_HOST_MAPPING) != null) { - flags |= FLAG_HOST_MAPPING; - } - zipFile.close(); - return flags; - } + public static final int FLAG_PREFERENCES = 0x1; + public static final int FLAG_NICKNAMES = 0x2; + public static final int FLAG_USER_COLORS = 0x4; + public static final int FLAG_HOST_MAPPING = 0x8; + public static final int FLAG_KEYBOARD_SHORTCUTS = 0x10; + public static final int FLAG_ALL = FLAG_PREFERENCES | FLAG_NICKNAMES | FLAG_USER_COLORS | FLAG_HOST_MAPPING | FLAG_KEYBOARD_SHORTCUTS; - public static HashMap getSupportedPreferencesMap() { - final Field[] fields = SharedPreferenceConstants.class.getDeclaredFields(); - final HashMap supportedPrefsMap = new HashMap(); - for (final Field field : fields) { - final Preference annotation = field.getAnnotation(Preference.class); - if (Modifier.isStatic(field.getModifiers()) && CompareUtils.classEquals(field.getType(), String.class) - && annotation != null && annotation.exportable() && annotation.type() != INVALID) { - try { - supportedPrefsMap.put((String) field.get(null), annotation); - } catch (final IllegalAccessException e) { - } catch (final IllegalArgumentException e) { - } - } - } - return supportedPrefsMap; - } + public static void exportData(final Context context, final File dst, final int flags) throws IOException { + if (dst == null) throw new FileNotFoundException(); + dst.delete(); + final FileOutputStream fos = new FileOutputStream(dst); + final ZipOutputStream zos = new ZipOutputStream(new BufferedOutputStream(fos)); + if (hasFlag(flags, FLAG_PREFERENCES)) { + writeSharedPreferencesData(zos, context, SHARED_PREFERENCES_NAME, ENTRY_PREFERENCES); + } + if (hasFlag(flags, FLAG_NICKNAMES)) { + writeRawSharedPreferencesData(zos, context, USER_NICKNAME_PREFERENCES_NAME, ENTRY_NICKNAMES); + } + if (hasFlag(flags, FLAG_USER_COLORS)) { + writeRawSharedPreferencesData(zos, context, USER_COLOR_PREFERENCES_NAME, ENTRY_USER_COLORS); + } + if (hasFlag(flags, FLAG_HOST_MAPPING)) { + writeRawSharedPreferencesData(zos, context, HOST_MAPPING_PREFERENCES_NAME, ENTRY_HOST_MAPPING); + } + if (hasFlag(flags, FLAG_KEYBOARD_SHORTCUTS)) { + writeRawSharedPreferencesData(zos, context, KEYBOARD_SHORTCUTS_PREFERENCES_NAME, ENTRY_KEYBOARD_SHORTCUTS); + } + zos.finish(); + zos.flush(); + Utils.closeSilently(zos); + Utils.closeSilently(fos); + } - public static void importData(final Context context, final File src, final int flags) throws IOException { - if (src == null) throw new FileNotFoundException(); - final ZipFile zipFile = new ZipFile(src); - if (hasFlag(flags, FLAG_PREFERENCES)) { - readSharedPreferencesData(zipFile, context, SHARED_PREFERENCES_NAME, ENTRY_PREFERENCES); - } - if (hasFlag(flags, FLAG_NICKNAMES)) { - readRawSharedPreferencesData(zipFile, context, USER_NICKNAME_PREFERENCES_NAME, ENTRY_NICKNAMES); - } - if (hasFlag(flags, FLAG_USER_COLORS)) { - readRawSharedPreferencesData(zipFile, context, USER_COLOR_PREFERENCES_NAME, ENTRY_USER_COLORS); - } - if (hasFlag(flags, FLAG_HOST_MAPPING)) { - readRawSharedPreferencesData(zipFile, context, HOST_MAPPING_PREFERENCES_NAME, ENTRY_HOST_MAPPING); - } - zipFile.close(); - } + public static int getImportedSettingsFlags(final File src) throws IOException { + if (src == null) return 0; + final ZipFile zipFile = new ZipFile(src); + int flags = 0; + if (zipFile.getEntry(ENTRY_PREFERENCES) != null) { + flags |= FLAG_PREFERENCES; + } + if (zipFile.getEntry(ENTRY_NICKNAMES) != null) { + flags |= FLAG_NICKNAMES; + } + if (zipFile.getEntry(ENTRY_USER_COLORS) != null) { + flags |= FLAG_USER_COLORS; + } + if (zipFile.getEntry(ENTRY_HOST_MAPPING) != null) { + flags |= FLAG_HOST_MAPPING; + } + if (zipFile.getEntry(ENTRY_KEYBOARD_SHORTCUTS) != null) { + flags |= FLAG_KEYBOARD_SHORTCUTS; + } + zipFile.close(); + return flags; + } - private static byte[] getSerializedRawSharedPreferencesData(final Context context, final String name) { - final SharedPreferences prefs = context.getSharedPreferences(name, Context.MODE_PRIVATE); - return JSONSerializer.getByteArray(new RawSharedPreferencesData(prefs)); - } + public static HashMap getSupportedPreferencesMap() { + final Field[] fields = SharedPreferenceConstants.class.getDeclaredFields(); + final HashMap supportedPrefsMap = new HashMap(); + for (final Field field : fields) { + final Preference annotation = field.getAnnotation(Preference.class); + if (Modifier.isStatic(field.getModifiers()) && CompareUtils.classEquals(field.getType(), String.class) + && annotation != null && annotation.exportable() && annotation.type() != INVALID) { + try { + supportedPrefsMap.put((String) field.get(null), annotation); + } catch (final IllegalAccessException | IllegalArgumentException e) { + Log.w(LOGTAG, e); + } + } + } + return supportedPrefsMap; + } - private static byte[] getSerializedSharedPreferencesData(final Context context, final String name) { - final SharedPreferences prefs = context.getSharedPreferences(name, Context.MODE_PRIVATE); - return JSONSerializer.getByteArray(new SharedPreferencesData(prefs)); - } + public static void importData(final Context context, final File src, final int flags) throws IOException { + if (src == null) throw new FileNotFoundException(); + final ZipFile zipFile = new ZipFile(src); + if (hasFlag(flags, FLAG_PREFERENCES)) { + readSharedPreferencesData(zipFile, context, SHARED_PREFERENCES_NAME, ENTRY_PREFERENCES); + } + if (hasFlag(flags, FLAG_NICKNAMES)) { + readRawSharedPreferencesData(zipFile, context, USER_NICKNAME_PREFERENCES_NAME, ENTRY_NICKNAMES); + } + if (hasFlag(flags, FLAG_USER_COLORS)) { + readRawSharedPreferencesData(zipFile, context, USER_COLOR_PREFERENCES_NAME, ENTRY_USER_COLORS); + } + if (hasFlag(flags, FLAG_HOST_MAPPING)) { + readRawSharedPreferencesData(zipFile, context, HOST_MAPPING_PREFERENCES_NAME, ENTRY_HOST_MAPPING); + } + if (hasFlag(flags, FLAG_KEYBOARD_SHORTCUTS)) { + readRawSharedPreferencesData(zipFile, context, KEYBOARD_SHORTCUTS_PREFERENCES_NAME, ENTRY_KEYBOARD_SHORTCUTS); + } + zipFile.close(); + } - private static boolean hasFlag(final int flags, final int flag) { - return (flags & flag) != 0; - } + private static byte[] getSerializedRawSharedPreferencesData(final Context context, final String name) { + final SharedPreferences prefs = context.getSharedPreferences(name, Context.MODE_PRIVATE); + return JSONSerializer.getByteArray(new RawSharedPreferencesData(prefs)); + } - private static void readRawSharedPreferencesData(final ZipFile zipFile, final Context context, - final String preferencesName, final String entryName) throws IOException { - final ZipEntry entry = zipFile.getEntry(entryName); - if (entry == null) return; - final JSONObject json = JSONFileIO.convertJSONObject(zipFile.getInputStream(entry)); - final RawSharedPreferencesData data = JSONSerializer.createObject(RawSharedPreferencesData.JSON_CREATOR, json); - if (data != null) { - data.writeToSharedPreferences(context.getSharedPreferences(preferencesName, Context.MODE_PRIVATE)); - } - } + private static byte[] getSerializedSharedPreferencesData(final Context context, final String name) { + final SharedPreferences prefs = context.getSharedPreferences(name, Context.MODE_PRIVATE); + return JSONSerializer.getByteArray(new SharedPreferencesData(prefs)); + } - private static void readSharedPreferencesData(final ZipFile zipFile, final Context context, - final String preferencesName, final String entryName) throws IOException { - final ZipEntry entry = zipFile.getEntry(entryName); - if (entry == null) return; - final JSONObject json = JSONFileIO.convertJSONObject(zipFile.getInputStream(entry)); - final SharedPreferencesData data = JSONSerializer.createObject(SharedPreferencesData.JSON_CREATOR, json); - if (data != null) { - data.writeToSharedPreferences(context.getSharedPreferences(preferencesName, Context.MODE_PRIVATE)); - } - } + private static boolean hasFlag(final int flags, final int flag) { + return (flags & flag) != 0; + } - private static void writeRawSharedPreferencesData(final ZipOutputStream zos, final Context context, - final String preferencesName, final String entryName) throws IOException { - final byte[] data = getSerializedRawSharedPreferencesData(context, preferencesName); - if (data == null) return; - zos.putNextEntry(new ZipEntry(entryName)); - zos.write(data); - zos.closeEntry(); - } + private static void readRawSharedPreferencesData(final ZipFile zipFile, final Context context, + final String preferencesName, final String entryName) throws IOException { + final ZipEntry entry = zipFile.getEntry(entryName); + if (entry == null) return; + final JSONObject json = JSONFileIO.convertJSONObject(zipFile.getInputStream(entry)); + final RawSharedPreferencesData data = JSONSerializer.createObject(RawSharedPreferencesData.JSON_CREATOR, json); + if (data != null) { + data.writeToSharedPreferences(context.getSharedPreferences(preferencesName, Context.MODE_PRIVATE)); + } + } - private static void writeSharedPreferencesData(final ZipOutputStream zos, final Context context, - final String preferencesName, final String entryName) throws IOException { - final byte[] data = getSerializedSharedPreferencesData(context, preferencesName); - if (data == null) return; - zos.putNextEntry(new ZipEntry(entryName)); - zos.write(data); - zos.closeEntry(); - } + private static void readSharedPreferencesData(final ZipFile zipFile, final Context context, + final String preferencesName, final String entryName) throws IOException { + final ZipEntry entry = zipFile.getEntry(entryName); + if (entry == null) return; + final JSONObject json = JSONFileIO.convertJSONObject(zipFile.getInputStream(entry)); + final SharedPreferencesData data = JSONSerializer.createObject(SharedPreferencesData.JSON_CREATOR, json); + if (data != null) { + data.writeToSharedPreferences(context.getSharedPreferences(preferencesName, Context.MODE_PRIVATE)); + } + } + + private static void writeRawSharedPreferencesData(final ZipOutputStream zos, final Context context, + final String preferencesName, final String entryName) throws IOException { + final byte[] data = getSerializedRawSharedPreferencesData(context, preferencesName); + if (data == null) return; + zos.putNextEntry(new ZipEntry(entryName)); + zos.write(data); + zos.closeEntry(); + } + + private static void writeSharedPreferencesData(final ZipOutputStream zos, final Context context, + final String preferencesName, final String entryName) throws IOException { + final byte[] data = getSerializedSharedPreferencesData(context, preferencesName); + if (data == null) return; + zos.putNextEntry(new ZipEntry(entryName)); + zos.write(data); + zos.closeEntry(); + } } diff --git a/twidere/src/main/java/org/mariotaku/twidere/util/PermissionsManager.java b/twidere/src/main/java/org/mariotaku/twidere/util/PermissionsManager.java index 6f301ba14..ccc292975 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/util/PermissionsManager.java +++ b/twidere/src/main/java/org/mariotaku/twidere/util/PermissionsManager.java @@ -76,8 +76,7 @@ public class PermissionsManager implements Constants { } public boolean checkSignature(final int uid) { - final String pname = getPackageNameByUid(uid); - return checkSignature(pname); + return checkSignature(getPackageNameByUid(uid)); } public boolean checkSignature(final String pname) { diff --git a/twidere/src/main/java/org/mariotaku/twidere/util/ThemeUtils.java b/twidere/src/main/java/org/mariotaku/twidere/util/ThemeUtils.java index de3141547..db1c7bbb1 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/util/ThemeUtils.java +++ b/twidere/src/main/java/org/mariotaku/twidere/util/ThemeUtils.java @@ -43,6 +43,7 @@ import android.support.v7.internal.view.SupportActionModeWrapperTrojan; import android.support.v7.internal.view.menu.ActionMenuItemView; import android.support.v7.internal.widget.ActionBarOverlayLayout; import android.support.v7.widget.ActionMenuView; +import android.support.v7.widget.Toolbar; import android.text.SpannableStringBuilder; import android.text.Spanned; import android.text.TextPaint; @@ -55,7 +56,9 @@ import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.view.View.OnLongClickListener; +import android.view.Window; import android.widget.CompoundButton; +import android.widget.ImageView; import android.widget.ProgressBar; import android.widget.TextView; @@ -66,7 +69,6 @@ import org.mariotaku.twidere.activity.iface.IThemedActivity; import org.mariotaku.twidere.graphic.ActionBarColorDrawable; import org.mariotaku.twidere.graphic.ActionIconDrawable; import org.mariotaku.twidere.text.ParagraphSpacingSpan; -import org.mariotaku.twidere.util.accessor.ViewAccessor; import org.mariotaku.twidere.util.menu.TwidereMenuInfo; import org.mariotaku.twidere.view.TabPagerIndicator; import org.mariotaku.twidere.view.iface.IThemedView; @@ -157,7 +159,7 @@ public class ThemeUtils implements Constants { contextViewField.setAccessible(true); final View view = (View) contextViewField.get(actionBar); if (view == null) return; - ViewAccessor.setBackground(view, getActionBarBackground(activity, themeRes, accentColor, outlineEnabled)); + ViewUtils.setBackground(view, getActionBarBackground(activity, themeRes, accentColor, outlineEnabled)); } catch (Exception e) { e.printStackTrace(); } @@ -183,7 +185,7 @@ public class ThemeUtils implements Constants { final int themeRes = ((IThemedActivity) activity).getCurrentThemeResourceId(); final int themeColor = ((IThemedActivity) activity).getCurrentThemeColor(); final int contrastColor = ColorUtils.getContrastYIQ(themeColor, 192); - ViewAccessor.setBackground(indicator, getActionBarStackedBackground(activity, themeRes, themeColor, true)); + ViewUtils.setBackground(indicator, getActionBarStackedBackground(activity, themeRes, themeColor, true)); if (isDarkTheme(themeRes)) { final int foregroundColor = getThemeForegroundColor(activity); indicator.setIconColor(foregroundColor); @@ -217,6 +219,26 @@ public class ThemeUtils implements Constants { } } + @SuppressLint("NewApi") + public static void setActionBarOverflowColor(Toolbar toolbar, int itemColor) { + if (toolbar == null) return; + final ActionMenuView actionMenuView = ViewUtils.findViewByType(toolbar, ActionMenuView.class); + if (actionMenuView == null) return; + View overflowView = null; + for (int i = 0, j = actionMenuView.getChildCount(); i < j; i++) { + final View child = actionMenuView.getChildAt(i); + final ActionMenuView.LayoutParams lp = (ActionMenuView.LayoutParams) child.getLayoutParams(); + if (lp.isOverflowButton) { + overflowView = child; + break; + } + } + if (!(overflowView instanceof ImageView)) return; + final Drawable drawable = ((ImageView) overflowView).getDrawable(); + if (drawable == null) return; + drawable.setColorFilter(itemColor, Mode.SRC_ATOP); + } + public static void setCompatToolbarOverlay(Activity activity, Drawable background) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) return; final View view = activity.getWindow().findViewById(android.support.v7.appcompat.R.id.decor_content_parent); @@ -243,6 +265,11 @@ public class ThemeUtils implements Constants { if (ArrayUtils.contains(excludeGroups, item.getGroupId())) return; final Drawable icon = item.getIcon(); if (icon == null) return; + if (icon instanceof ActionIconDrawable) { + ((ActionIconDrawable) icon).setDefaultColor(itemColor); + item.setIcon(icon); + return; + } icon.mutate(); final Drawable.Callback callback = icon.getCallback(); final ActionIconDrawable newIcon = new ActionIconDrawable(icon, itemColor); @@ -250,12 +277,17 @@ public class ThemeUtils implements Constants { item.setIcon(newIcon); } + public static void wrapMenuIcon(ActionMenuView view, int... excludeGroups) { - final int itemBackgroundColor = ThemeUtils.getThemeBackgroundColor(view.getContext()); - final int popupItemBackgroundColor = ThemeUtils.getThemeBackgroundColor(view.getContext(), view.getPopupTheme()); final Resources resources = view.getResources(); final int colorDark = resources.getColor(R.color.action_icon_dark); final int colorLight = resources.getColor(R.color.action_icon_light); + wrapMenuIcon(view, colorDark, colorLight, excludeGroups); + } + + public static void wrapMenuIcon(ActionMenuView view, int colorDark, int colorLight, int... excludeGroups) { + final int itemBackgroundColor = ThemeUtils.getThemeBackgroundColor(view.getContext()); + final int popupItemBackgroundColor = ThemeUtils.getThemeBackgroundColor(view.getContext(), view.getPopupTheme()); final int itemColor = ColorUtils.getContrastYIQ(itemBackgroundColor, colorDark, colorLight); final int popupItemColor = ColorUtils.getContrastYIQ(popupItemBackgroundColor, colorDark, colorLight); final Menu menu = view.getMenu(); @@ -272,6 +304,21 @@ public class ThemeUtils implements Constants { } } + public static void wrapToolbarMenuIcon(Toolbar view, int itemColor, int popupItemColor, int... excludeGroups) { + final Menu menu = view.getMenu(); + final int childCount = view.getChildCount(); + for (int i = 0, j = menu.size(), k = 0; i < j; i++) { + final MenuItem item = menu.getItem(i); + wrapMenuItemIcon(item, itemColor, excludeGroups); + if (item.hasSubMenu()) { + wrapMenuIcon(menu, popupItemColor, popupItemColor, excludeGroups); + } + if (item.isVisible()) { + k++; + } + } + } + public static void wrapMenuIcon(Context context, Menu menu, int... excludeGroups) { final int backgroundColor = ThemeUtils.getThemeBackgroundColor(context); @@ -416,13 +463,13 @@ public class ThemeUtils implements Constants { } else if (view instanceof ProgressBar) { final ColorStateList tintList = ColorStateList.valueOf(tintColor); final ProgressBar progressBar = (ProgressBar) view; - ViewAccessor.setProgressTintList(progressBar, tintList); - ViewAccessor.setProgressBackgroundTintList(progressBar, tintList); - ViewAccessor.setIndeterminateTintList(progressBar, tintList); + ViewUtils.setProgressTintList(progressBar, tintList); + ViewUtils.setProgressBackgroundTintList(progressBar, tintList); + ViewUtils.setIndeterminateTintList(progressBar, tintList); } else if (view instanceof CompoundButton) { final ColorStateList tintList = ColorStateList.valueOf(tintColor); final CompoundButton compoundButton = (CompoundButton) view; - ViewAccessor.setButtonTintList(compoundButton, tintList); + ViewUtils.setButtonTintList(compoundButton, tintList); } // TODO support TintableBackgroundView } @@ -521,23 +568,6 @@ public class ThemeUtils implements Constants { return applyActionBarDrawable(context, d, isTransparentBackground(themeRes)); } - public static int getActionIconColor(final int themeRes) { - switch (themeRes) { - case R.style.Theme_Twidere_Light: - case R.style.Theme_Twidere_Light_SolidBackground: - case R.style.Theme_Twidere_Light_Transparent: - case R.style.Theme_Twidere_Light_Compose: - case R.style.Theme_Twidere_Light_Dialog: - case R.style.Theme_Twidere_ActionBar_Colored_Light: - case R.style.Theme_Twidere_Settings_Light: - case R.style.Theme_Twidere_Drawer_Light: - case R.style.Theme_Twidere_Drawer_Light_Transparent: - case R.style.Theme_Twidere_Settings_Light_DarkActionBar_DarkIcon: - return 0x99333333; - } - return 0xCCFFFFFF; - } - public static int getColorBackgroundCacheHint(final Context context) { final TypedArray a = context.obtainStyledAttributes(new int[]{android.R.attr.colorBackgroundCacheHint}); final int color = a.getColor(0, Color.TRANSPARENT); @@ -554,20 +584,14 @@ public class ThemeUtils implements Constants { } public static int getComposeThemeResource(final Context context) { - return getComposeThemeResource(getThemeNameOption(context), getDarkActionBarOption(context)); + return getComposeThemeResource(getThemeNameOption(context)); } - public static int getComposeThemeResource(final String name, final boolean darkActionBar) { + public static int getComposeThemeResource(final String name) { if (VALUE_THEME_NAME_DARK.equals(name)) return R.style.Theme_Twidere_Dark_Compose; return R.style.Theme_Twidere_Light_Compose; } - public static boolean getDarkActionBarOption(final Context context) { - if (context == null) return true; - final SharedPreferencesWrapper pref = getSharedPreferencesWrapper(context); - return pref.getBoolean(KEY_THEME_DARK_ACTIONBAR, true); - } - public static Context getDialogThemedContext(final Context context) { return new ContextThemeWrapper(context, getDialogThemeResource(context)); } @@ -614,25 +638,6 @@ public class ThemeUtils implements Constants { return d; } - public static int getMenuIconColor(final Context context) { - return getMenuIconColor(getThemeResource(context)); - } - - public static int getMenuIconColor(final int themeRes) { - switch (themeRes) { - case R.style.Theme_Twidere_Light: - case R.style.Theme_Twidere_Light_SolidBackground: - case R.style.Theme_Twidere_Light_Transparent: - case R.style.Theme_Twidere_Light_Compose: - case R.style.Theme_Twidere_Light_Dialog: - case R.style.Theme_Twidere_ActionBar_Colored_Light: - case R.style.Theme_Twidere_Settings_Light: - case R.style.Theme_Twidere_Settings_Light_DarkActionBar_DarkIcon: - return 0x99333333; - } - return 0xCCFFFFFF; - } - public static int getNoDisplayThemeResource(final Context context) { if (context == null) return R.style.Theme_Twidere_Dark_NoDisplay; final SharedPreferencesWrapper pref = getSharedPreferencesWrapper(context); @@ -659,21 +664,16 @@ public class ThemeUtils implements Constants { } public static int getSettingsThemeResource(final Context context) { - return getSettingsThemeResource(getThemeNameOption(context), getDarkActionBarOption(context)); + return getSettingsThemeResource(getThemeNameOption(context)); } - public static int getSettingsThemeResource(final String name, final boolean darkActionBar) { + public static int getSettingsThemeResource(final String name) { if (VALUE_THEME_NAME_TWIDERE.equals(name) || VALUE_THEME_NAME_LIGHT.equals(name)) - return darkActionBar ? R.style.Theme_Twidere_Settings_Light_DarkActionBar - : R.style.Theme_Twidere_Settings_Light; + return R.style.Theme_Twidere_Settings_Light_DarkActionBar; else if (VALUE_THEME_NAME_DARK.equals(name)) return R.style.Theme_Twidere_Settings_Dark; return R.style.Theme_Twidere_Settings_Light_DarkActionBar; } - public static int getSettingsWizardThemeResource(final Context context) { - return R.style.Theme_Twidere_Settings_Light; - } - public static int getTextAppearanceLarge(final Context context) { // final Context wrapped = getThemedContext(context, // getResources(context)); @@ -798,33 +798,10 @@ public class ThemeUtils implements Constants { } public static int getThemeResource(final Context context) { - return getThemeResource(getThemeNameOption(context), getThemeBackgroundOption(context), - getDarkActionBarOption(context)); + return getThemeResource(getThemeNameOption(context), getThemeBackgroundOption(context)); } - public static int getNoActionBarThemeResource(final Context context) { - return getNoActionBarThemeResource(getThemeNameOption(context), getThemeBackgroundOption(context), - getDarkActionBarOption(context)); - } - - public static int getNoActionBarThemeResource(final String name, final String background, final boolean darkActionBar) { - if (VALUE_THEME_NAME_LIGHT.equals(name)) { - if (VALUE_THEME_BACKGROUND_SOLID.equals(background)) - return R.style.Theme_Twidere_Light_SolidBackground_NoActionBar; - else if (VALUE_THEME_BACKGROUND_TRANSPARENT.equals(background)) - return R.style.Theme_Twidere_Light_Transparent_NoActionBar; - return R.style.Theme_Twidere_Light_NoActionBar; - } else if (VALUE_THEME_NAME_DARK.equals(name)) { - if (VALUE_THEME_BACKGROUND_SOLID.equals(background)) - return R.style.Theme_Twidere_Dark_SolidBackground_NoActionBar; - else if (VALUE_THEME_BACKGROUND_TRANSPARENT.equals(background)) - return R.style.Theme_Twidere_Dark_Transparent_NoActionBar; - return R.style.Theme_Twidere_Dark_NoActionBar; - } - return R.style.Theme_Twidere_Light_NoActionBar; - } - - public static int getThemeResource(final String name, final String background, final boolean darkActionBar) { + public static int getThemeResource(final String name, final String background) { if (VALUE_THEME_NAME_LIGHT.equals(name)) { if (VALUE_THEME_BACKGROUND_SOLID.equals(background)) return R.style.Theme_Twidere_Light_SolidBackground; @@ -937,9 +914,6 @@ public class ThemeUtils implements Constants { case R.style.Theme_Twidere_Dark_Dialog: case R.style.Theme_Twidere_Dark_Compose: case R.style.Theme_Twidere_Dark_Transparent: - case R.style.Theme_Twidere_Dark_NoActionBar: - case R.style.Theme_Twidere_Dark_SolidBackground_NoActionBar: - case R.style.Theme_Twidere_Dark_Transparent_NoActionBar: return true; } return false; @@ -953,8 +927,6 @@ public class ThemeUtils implements Constants { switch (themeRes) { case R.style.Theme_Twidere_Dark_Transparent: case R.style.Theme_Twidere_Light_Transparent: - case R.style.Theme_Twidere_Dark_Transparent_NoActionBar: - case R.style.Theme_Twidere_Light_Transparent_NoActionBar: return true; } return false; @@ -1057,4 +1029,30 @@ public class ThemeUtils implements Constants { textView.setText(builder); } + public static void setActionBarItemsColor(Window window, android.support.v7.app.ActionBar actionBar, int itemColor) { + final Drawable drawable = getActionBarHomeAsUpIndicator(actionBar); + if (drawable != null) { + drawable.setColorFilter(itemColor, Mode.SRC_ATOP); + } + actionBar.setHomeAsUpIndicator(drawable); + setActionBarTitleTextColor(window, itemColor); + } + + public static void setActionBarTitleTextColor(Window window, int itemColor) { + final View actionBarView = window.findViewById(android.support.v7.appcompat.R.id.action_bar); + if (actionBarView instanceof Toolbar) { + ((Toolbar) actionBarView).setTitleTextColor(itemColor); + } + } + + public static Drawable getActionBarHomeAsUpIndicator(android.support.v7.app.ActionBar actionBar) { + final Context context = actionBar.getThemedContext(); + @SuppressWarnings("ConstantConditions") + final TypedArray a = context.obtainStyledAttributes(null, R.styleable.ActionBar, R.attr.actionBarStyle, 0); + try { + return a.getDrawable(R.styleable.ActionBar_homeAsUpIndicator); + } finally { + a.recycle(); + } + } } diff --git a/twidere/src/main/java/org/mariotaku/twidere/util/accessor/ViewAccessor.java b/twidere/src/main/java/org/mariotaku/twidere/util/ViewUtils.java similarity index 93% rename from twidere/src/main/java/org/mariotaku/twidere/util/accessor/ViewAccessor.java rename to twidere/src/main/java/org/mariotaku/twidere/util/ViewUtils.java index 8e04e9d0f..a560228c4 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/util/accessor/ViewAccessor.java +++ b/twidere/src/main/java/org/mariotaku/twidere/util/ViewUtils.java @@ -17,7 +17,7 @@ * along with this program. If not, see . */ -package org.mariotaku.twidere.util.accessor; +package org.mariotaku.twidere.util; import android.annotation.TargetApi; import android.content.res.ColorStateList; @@ -27,11 +27,12 @@ import android.graphics.Rect; import android.graphics.drawable.Drawable; import android.os.Build; import android.view.View; +import android.view.ViewGroup; import android.view.ViewOutlineProvider; import android.widget.CompoundButton; import android.widget.ProgressBar; -public final class ViewAccessor { +public final class ViewUtils { public static boolean isInLayout(View view) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR2) { @@ -86,6 +87,18 @@ public final class ViewAccessor { ViewAccessorL.setProgressTintList(view, list); } + @SuppressWarnings("unchecked") + public static T findViewByType(View view, Class cls) { + if (cls.isAssignableFrom(view.getClass())) return (T) view; + if (view instanceof ViewGroup) { + for (int i = 0, j = ((ViewGroup) view).getChildCount(); i < j; i++) { + final View found = findViewByType(((ViewGroup) view).getChildAt(i), cls); + if (found != null) return (T) found; + } + } + return null; + } + @TargetApi(Build.VERSION_CODES.JELLY_BEAN) static class ViewAccessorJB { static void setBackground(final View view, final Drawable background) { @@ -142,7 +155,7 @@ public final class ViewAccessor { /** - * Interface by which a View builds its {@link org.mariotaku.twidere.util.accessor.ViewAccessor.OutlineCompat}, used for shadow casting and clipping. + * Interface by which a View builds its {@link ViewUtils.OutlineCompat}, used for shadow casting and clipping. */ public static abstract class ViewOutlineProviderCompat { /** diff --git a/twidere/src/main/java/org/mariotaku/twidere/util/content/SupportFragmentReloadCursorObserver.java b/twidere/src/main/java/org/mariotaku/twidere/util/content/SupportFragmentReloadCursorObserver.java index cc23a3505..a59c44397 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/util/content/SupportFragmentReloadCursorObserver.java +++ b/twidere/src/main/java/org/mariotaku/twidere/util/content/SupportFragmentReloadCursorObserver.java @@ -23,6 +23,7 @@ import android.database.ContentObserver; import android.database.Cursor; import android.net.Uri; import android.os.Handler; +import android.os.Looper; import android.support.v4.app.Fragment; import android.support.v4.app.LoaderManager.LoaderCallbacks; @@ -55,7 +56,7 @@ public final class SupportFragmentReloadCursorObserver extends ContentObserver i } private static Handler createHandler() { - if (Thread.currentThread().getId() != 1) return null; + if (Thread.currentThread().getId() != 1) return new Handler(Looper.getMainLooper()); return new Handler(); } } diff --git a/twidere/src/main/java/org/mariotaku/twidere/view/HomeActionButton.java b/twidere/src/main/java/org/mariotaku/twidere/view/HomeActionButton.java index cb5aafe97..83d0547a2 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/view/HomeActionButton.java +++ b/twidere/src/main/java/org/mariotaku/twidere/view/HomeActionButton.java @@ -39,9 +39,9 @@ import android.widget.ProgressBar; import org.mariotaku.twidere.R; import org.mariotaku.twidere.util.ThemeUtils; -import org.mariotaku.twidere.util.accessor.ViewAccessor; -import org.mariotaku.twidere.util.accessor.ViewAccessor.OutlineCompat; -import org.mariotaku.twidere.util.accessor.ViewAccessor.ViewOutlineProviderCompat; +import org.mariotaku.twidere.util.ViewUtils; +import org.mariotaku.twidere.util.ViewUtils.OutlineCompat; +import org.mariotaku.twidere.util.ViewUtils.ViewOutlineProviderCompat; import org.mariotaku.twidere.view.iface.IHomeActionButton; import me.uucky.colorpicker.internal.EffectViewHelper; @@ -92,14 +92,14 @@ public class HomeActionButton extends FrameLayout implements IHomeActionButton { } mIconView = (ImageView) findViewById(android.R.id.icon); mProgressBar = (ProgressBar) findViewById(android.R.id.progress); - ViewAccessor.setOutlineProvider(this, new HomeActionButtonOutlineProvider()); + ViewUtils.setOutlineProvider(this, new HomeActionButtonOutlineProvider()); setClipToOutline(true); setButtonColor(Color.WHITE); } @Override public void setButtonColor(int color) { - ViewAccessor.setBackground(this, new ColorDrawable(color)); + ViewUtils.setBackground(this, new ColorDrawable(color)); } @Override diff --git a/twidere/src/main/java/org/mariotaku/twidere/view/HomeActionButtonCompat.java b/twidere/src/main/java/org/mariotaku/twidere/view/HomeActionButtonCompat.java index f1b495788..2e61b8fe8 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/view/HomeActionButtonCompat.java +++ b/twidere/src/main/java/org/mariotaku/twidere/view/HomeActionButtonCompat.java @@ -41,7 +41,7 @@ import android.widget.ProgressBar; import org.mariotaku.twidere.R; import org.mariotaku.twidere.util.ColorUtils; import org.mariotaku.twidere.util.ThemeUtils; -import org.mariotaku.twidere.util.accessor.ViewAccessor; +import org.mariotaku.twidere.util.ViewUtils; import org.mariotaku.twidere.view.iface.IHomeActionButton; public class HomeActionButtonCompat extends FrameLayout implements IHomeActionButton { @@ -66,7 +66,7 @@ public class HomeActionButtonCompat extends FrameLayout implements IHomeActionBu final Resources resources = getResources(); final int radius = resources.getDimensionPixelSize(R.dimen.element_spacing_small); mBackground = new FloatingActionDrawable(this, radius); - ViewAccessor.setBackground(this, mBackground); + ViewUtils.setBackground(this, mBackground); } @Override diff --git a/twidere/src/main/java/org/mariotaku/twidere/view/LeftDrawerFrameLayout.java b/twidere/src/main/java/org/mariotaku/twidere/view/LeftDrawerFrameLayout.java index e683178fd..c8ec2b8ee 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/view/LeftDrawerFrameLayout.java +++ b/twidere/src/main/java/org/mariotaku/twidere/view/LeftDrawerFrameLayout.java @@ -29,7 +29,7 @@ import android.util.AttributeSet; import android.widget.FrameLayout; import org.mariotaku.twidere.util.ThemeUtils; -import org.mariotaku.twidere.util.accessor.ViewAccessor; +import org.mariotaku.twidere.util.ViewUtils; public class LeftDrawerFrameLayout extends FrameLayout { @@ -48,7 +48,7 @@ public class LeftDrawerFrameLayout extends FrameLayout { public LeftDrawerFrameLayout(final Context context, final AttributeSet attrs, final int defStyle) { super(context, attrs, defStyle); final Drawable bg = ThemeUtils.getWindowBackground(context, ThemeUtils.getDrawerThemeResource(context)); - ViewAccessor.setBackground(this, bg); + ViewUtils.setBackground(this, bg); setWillNotDraw(false); mClipPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR)); } diff --git a/twidere/src/main/java/org/mariotaku/twidere/view/LinePageIndicator.java b/twidere/src/main/java/org/mariotaku/twidere/view/LinePageIndicator.java index 154f4d2c3..1957a1298 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/view/LinePageIndicator.java +++ b/twidere/src/main/java/org/mariotaku/twidere/view/LinePageIndicator.java @@ -32,7 +32,7 @@ import android.view.View; import android.view.ViewConfiguration; import org.mariotaku.twidere.R; -import org.mariotaku.twidere.util.accessor.ViewAccessor; +import org.mariotaku.twidere.util.ViewUtils; import org.mariotaku.twidere.view.iface.PagerIndicator; /** @@ -84,7 +84,7 @@ public class LinePageIndicator extends View implements PagerIndicator { final Drawable background = a.getDrawable(R.styleable.LinePageIndicator_android_background); if (background != null) { - ViewAccessor.setBackground(this, background); + ViewUtils.setBackground(this, background); } a.recycle(); diff --git a/twidere/src/main/java/org/mariotaku/twidere/view/RightDrawerFrameLayout.java b/twidere/src/main/java/org/mariotaku/twidere/view/RightDrawerFrameLayout.java index 0bc1a453e..eb5e68bee 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/view/RightDrawerFrameLayout.java +++ b/twidere/src/main/java/org/mariotaku/twidere/view/RightDrawerFrameLayout.java @@ -29,7 +29,7 @@ import android.util.AttributeSet; import android.widget.FrameLayout; import org.mariotaku.twidere.util.ThemeUtils; -import org.mariotaku.twidere.util.accessor.ViewAccessor; +import org.mariotaku.twidere.util.ViewUtils; public class RightDrawerFrameLayout extends FrameLayout { @@ -48,7 +48,7 @@ public class RightDrawerFrameLayout extends FrameLayout { public RightDrawerFrameLayout(final Context context, final AttributeSet attrs, final int defStyle) { super(context, attrs, defStyle); final Drawable bg = ThemeUtils.getWindowBackground(context, ThemeUtils.getDrawerThemeResource(context)); - ViewAccessor.setBackground(this, bg); + ViewUtils.setBackground(this, bg); setWillNotDraw(false); mClipPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR)); } diff --git a/twidere/src/main/java/org/mariotaku/twidere/view/ShapedImageView.java b/twidere/src/main/java/org/mariotaku/twidere/view/ShapedImageView.java index d837bcc28..2a1b26091 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/view/ShapedImageView.java +++ b/twidere/src/main/java/org/mariotaku/twidere/view/ShapedImageView.java @@ -49,9 +49,9 @@ import android.view.View; import android.widget.ImageView; import org.mariotaku.twidere.R; -import org.mariotaku.twidere.util.accessor.ViewAccessor; -import org.mariotaku.twidere.util.accessor.ViewAccessor.OutlineCompat; -import org.mariotaku.twidere.util.accessor.ViewAccessor.ViewOutlineProviderCompat; +import org.mariotaku.twidere.util.ViewUtils; +import org.mariotaku.twidere.util.ViewUtils.OutlineCompat; +import org.mariotaku.twidere.util.ViewUtils.ViewOutlineProviderCompat; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; @@ -426,8 +426,8 @@ public class ShapedImageView extends ImageView { } private void initOutlineProvider() { - ViewAccessor.setClipToOutline(this, true); - ViewAccessor.setOutlineProvider(this, new CircularOutlineProvider()); + ViewUtils.setClipToOutline(this, true); + ViewUtils.setOutlineProvider(this, new CircularOutlineProvider()); } private void setBorderColorsInternal(int alpha, int... colors) { diff --git a/twidere/src/main/java/org/mariotaku/twidere/view/TwitterCardContainer.java b/twidere/src/main/java/org/mariotaku/twidere/view/TwitterCardContainer.java index 694316454..019b208c5 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/view/TwitterCardContainer.java +++ b/twidere/src/main/java/org/mariotaku/twidere/view/TwitterCardContainer.java @@ -23,7 +23,7 @@ import android.content.Context; import android.util.AttributeSet; import android.widget.FrameLayout; -import org.mariotaku.twidere.util.accessor.ViewAccessor; +import org.mariotaku.twidere.util.ViewUtils; /** * Created by mariotaku on 15/1/1. @@ -47,7 +47,7 @@ public class TwitterCardContainer extends FrameLayout { public void setCardSize(int width, int height) { mCardWidth = width; mCardHeight = height; - if (!ViewAccessor.isInLayout(this)) { + if (!ViewUtils.isInLayout(this)) { requestLayout(); } } diff --git a/twidere/src/main/java/org/mariotaku/twidere/view/themed/ThemedAutoCompleteTextView.java b/twidere/src/main/java/org/mariotaku/twidere/view/themed/ThemedAutoCompleteTextView.java index ac90d82c5..1a7631414 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/view/themed/ThemedAutoCompleteTextView.java +++ b/twidere/src/main/java/org/mariotaku/twidere/view/themed/ThemedAutoCompleteTextView.java @@ -25,7 +25,7 @@ import android.util.AttributeSet; import android.widget.AutoCompleteTextView; import org.mariotaku.twidere.util.ThemeUtils; -import org.mariotaku.twidere.util.accessor.ViewAccessor; +import org.mariotaku.twidere.util.ViewUtils; import org.mariotaku.twidere.view.iface.IThemedView; public class ThemedAutoCompleteTextView extends AutoCompleteTextView implements IThemedView { @@ -45,6 +45,6 @@ public class ThemedAutoCompleteTextView extends AutoCompleteTextView implements @Override public void setThemeTintColor(ColorStateList color) { - ViewAccessor.setBackgroundTintList(this, color); + ViewUtils.setBackgroundTintList(this, color); } } diff --git a/twidere/src/main/java/org/mariotaku/twidere/view/themed/ThemedEditText.java b/twidere/src/main/java/org/mariotaku/twidere/view/themed/ThemedEditText.java index 1cda97363..d65903e96 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/view/themed/ThemedEditText.java +++ b/twidere/src/main/java/org/mariotaku/twidere/view/themed/ThemedEditText.java @@ -25,7 +25,7 @@ import android.util.AttributeSet; import android.widget.EditText; import org.mariotaku.twidere.util.ThemeUtils; -import org.mariotaku.twidere.util.accessor.ViewAccessor; +import org.mariotaku.twidere.util.ViewUtils; import org.mariotaku.twidere.view.iface.IThemedView; public class ThemedEditText extends EditText implements IThemedView { @@ -45,6 +45,6 @@ public class ThemedEditText extends EditText implements IThemedView { @Override public void setThemeTintColor(ColorStateList color) { - ViewAccessor.setBackgroundTintList(this, color); + ViewUtils.setBackgroundTintList(this, color); } } diff --git a/twidere/src/main/java/org/mariotaku/twidere/view/themed/ThemedMultiAutoCompleteTextView.java b/twidere/src/main/java/org/mariotaku/twidere/view/themed/ThemedMultiAutoCompleteTextView.java index 08942b85d..a0aff2556 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/view/themed/ThemedMultiAutoCompleteTextView.java +++ b/twidere/src/main/java/org/mariotaku/twidere/view/themed/ThemedMultiAutoCompleteTextView.java @@ -25,7 +25,7 @@ import android.util.AttributeSet; import android.widget.MultiAutoCompleteTextView; import org.mariotaku.twidere.util.ThemeUtils; -import org.mariotaku.twidere.util.accessor.ViewAccessor; +import org.mariotaku.twidere.util.ViewUtils; import org.mariotaku.twidere.view.iface.IThemedView; public class ThemedMultiAutoCompleteTextView extends MultiAutoCompleteTextView implements IThemedView { @@ -45,7 +45,7 @@ public class ThemedMultiAutoCompleteTextView extends MultiAutoCompleteTextView i @Override public void setThemeTintColor(ColorStateList color) { - ViewAccessor.setBackgroundTintList(this, color); + ViewUtils.setBackgroundTintList(this, color); setLinkTextColor(color); setHighlightColor(color.getDefaultColor()); } diff --git a/twidere/src/main/res-localized/menu/menu_keyboard_shortcuts.xml b/twidere/src/main/res-localized/menu/menu_keyboard_shortcuts.xml index ddff7a8aa..7855c1f48 100644 --- a/twidere/src/main/res-localized/menu/menu_keyboard_shortcuts.xml +++ b/twidere/src/main/res-localized/menu/menu_keyboard_shortcuts.xml @@ -21,9 +21,7 @@ \ No newline at end of file diff --git a/twidere/src/main/res/values/ids.xml b/twidere/src/main/res/values/ids.xml index 5a5c9e0d0..3e1a04004 100644 --- a/twidere/src/main/res/values/ids.xml +++ b/twidere/src/main/res/values/ids.xml @@ -76,4 +76,5 @@ + \ No newline at end of file diff --git a/twidere/src/main/res/values/strings.xml b/twidere/src/main/res/values/strings.xml index 21b1a5403..d09ff4688 100644 --- a/twidere/src/main/res/values/strings.xml +++ b/twidere/src/main/res/values/strings.xml @@ -743,5 +743,7 @@ Conflicts with %s Overwrite Navigation + Reset to default + Reset keyboard shortcuts to default? \ No newline at end of file diff --git a/twidere/src/main/res/values/themes.xml b/twidere/src/main/res/values/themes.xml index a40b48a33..5fccc0dc7 100644 --- a/twidere/src/main/res/values/themes.xml +++ b/twidere/src/main/res/values/themes.xml @@ -25,6 +25,7 @@ + + + + - - - - - - - - - - - - - - - - - - - - + + + +