mirror of
https://github.com/gsantner/dandelion
synced 2025-12-15 08:41:10 +01:00
Merged proper-themes
This commit is contained in:
commit
26751ff931
31 changed files with 1446 additions and 112 deletions
|
|
@ -31,9 +31,10 @@ import android.support.v4.app.Fragment;
|
|||
import android.support.v4.app.FragmentManager;
|
||||
import android.support.v4.app.FragmentPagerAdapter;
|
||||
import android.support.v4.view.ViewPager;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.LinearLayout;
|
||||
|
|
@ -43,10 +44,14 @@ import android.widget.Toast;
|
|||
import com.github.dfa.diaspora_android.App;
|
||||
import com.github.dfa.diaspora_android.R;
|
||||
import com.github.dfa.diaspora_android.data.AppSettings;
|
||||
import com.github.dfa.diaspora_android.fragment.ThemedFragment;
|
||||
import com.github.dfa.diaspora_android.ui.HtmlTextView;
|
||||
import com.github.dfa.diaspora_android.ui.IntellihideToolbarActivityListener;
|
||||
import com.github.dfa.diaspora_android.util.AppLog;
|
||||
import com.github.dfa.diaspora_android.util.DiasporaUrlHelper;
|
||||
import com.github.dfa.diaspora_android.util.Helpers;
|
||||
import com.github.dfa.diaspora_android.util.Log;
|
||||
import com.github.dfa.diaspora_android.util.theming.ThemeHelper;
|
||||
|
||||
import java.util.Observable;
|
||||
import java.util.Observer;
|
||||
|
|
@ -57,17 +62,24 @@ import butterknife.ButterKnife;
|
|||
/**
|
||||
* Activity that holds some fragments that show information about the app in a tab layout
|
||||
*/
|
||||
public class AboutActivity extends AppCompatActivity {
|
||||
public class AboutActivity extends ThemedActivity
|
||||
implements IntellihideToolbarActivityListener {
|
||||
|
||||
private SectionsPagerAdapter mSectionsPagerAdapter;
|
||||
private ViewPager mViewPager;
|
||||
|
||||
@BindView(R.id.about__appbar)
|
||||
AppBarLayout appBarLayout;
|
||||
|
||||
@BindView(R.id.main__topbar)
|
||||
protected Toolbar toolbar;
|
||||
|
||||
@BindView(R.id.appbar_linear_layout)
|
||||
protected LinearLayout linearLayout;
|
||||
|
||||
@BindView(R.id.tabs)
|
||||
protected TabLayout tabLayout;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
|
@ -87,23 +99,58 @@ public class AboutActivity extends AppCompatActivity {
|
|||
mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());
|
||||
|
||||
// Set up the ViewPager with the sections adapter.
|
||||
mViewPager = (ViewPager) findViewById(R.id.container);
|
||||
mViewPager = ButterKnife.findById(this, R.id.container);
|
||||
mViewPager.setAdapter(mSectionsPagerAdapter);
|
||||
|
||||
TabLayout tabLayout = (TabLayout) findViewById(R.id.tabs);
|
||||
tabLayout.setupWithViewPager(mViewPager);
|
||||
}
|
||||
|
||||
//Apply intellihide
|
||||
if (!((App) getApplication()).getSettings().isIntellihideToolbars()) {
|
||||
AppBarLayout.LayoutParams params = (AppBarLayout.LayoutParams) linearLayout.getLayoutParams();
|
||||
params.setScrollFlags(0);
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
if(getAppSettings().isIntellihideToolbars()) {
|
||||
this.enableToolbarHiding();
|
||||
} else {
|
||||
this.disableToolbarHiding();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void applyColorToViews() {
|
||||
ThemeHelper.updateToolbarColor(toolbar);
|
||||
ThemeHelper.updateTabLayoutColor(tabLayout);
|
||||
ThemeHelper.setPrimaryColorAsBackground(linearLayout);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void enableToolbarHiding() {
|
||||
AppLog.d(this, "Enable Intellihide");
|
||||
AppBarLayout.LayoutParams params = (AppBarLayout.LayoutParams) linearLayout.getLayoutParams();
|
||||
//scroll|enterAlways|snap
|
||||
params.setScrollFlags(toolbarDefaultScrollFlags);
|
||||
appBarLayout.setExpanded(true, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disableToolbarHiding() {
|
||||
AppLog.d(this, "Disable Intellihide");
|
||||
AppBarLayout.LayoutParams params = (AppBarLayout.LayoutParams) linearLayout.getLayoutParams();
|
||||
params.setScrollFlags(0); // clear all scroll flags
|
||||
appBarLayout.setExpanded(true, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fragment that shows general information about the app
|
||||
*/
|
||||
public static class AboutFragment extends Fragment {
|
||||
public static class AboutFragment extends ThemedFragment {
|
||||
|
||||
public static final String TAG = "com.github.dfa.diaspora_android.AboutActivity.AboutFragment";
|
||||
|
||||
@BindView(R.id.fragment_about__about_text)
|
||||
TextView aboutText;
|
||||
|
||||
@BindView(R.id.fragment_about__app_version)
|
||||
TextView appVersion;
|
||||
|
||||
public AboutFragment() {
|
||||
}
|
||||
|
|
@ -112,8 +159,7 @@ public class AboutActivity extends AppCompatActivity {
|
|||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
View rootView = inflater.inflate(R.layout.about__fragment_about, container, false);
|
||||
TextView appVersion = (TextView) rootView.findViewById(R.id.fragment_about__app_version);
|
||||
|
||||
ButterKnife.bind(this, rootView);
|
||||
if (isAdded()) {
|
||||
try {
|
||||
PackageInfo pInfo = getActivity().getPackageManager().getPackageInfo(getActivity().getPackageName(), 0);
|
||||
|
|
@ -125,18 +171,42 @@ public class AboutActivity extends AppCompatActivity {
|
|||
}
|
||||
return rootView;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void applyColorToViews() {
|
||||
ThemeHelper.updateTextViewColor(aboutText);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getFragmentTag() {
|
||||
return TAG;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreateBottomOptionsMenu(Menu menu, MenuInflater inflater) {
|
||||
/* Nothing to do */
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onBackPressed() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fragment that shows information about the license of the app and used 3rd party libraries
|
||||
*/
|
||||
public static class LicenseFragment extends Fragment {
|
||||
public static class LicenseFragment extends ThemedFragment {
|
||||
public static final String TAG = "com.github.dfa.diaspora_android.AboutActivity.LicenseFragment";
|
||||
|
||||
@BindView(R.id.fragment_license__licensetext)
|
||||
HtmlTextView textLicenseBox;
|
||||
|
||||
@BindView(R.id.fragment_license__3rdparty)
|
||||
HtmlTextView textLicense3partyBox;
|
||||
|
||||
private String accentColor;
|
||||
|
||||
|
||||
public LicenseFragment() {
|
||||
}
|
||||
|
|
@ -146,7 +216,7 @@ public class AboutActivity extends AppCompatActivity {
|
|||
View rootView = inflater.inflate(R.layout.about__fragment_license, container, false);
|
||||
ButterKnife.bind(this, rootView);
|
||||
final Context context = rootView.getContext();
|
||||
accentColor = Helpers.hexColorFromRessourceColor(context, R.color.colorAccent);
|
||||
accentColor = Helpers.colorToHex(ThemeHelper.getAccentColor());
|
||||
|
||||
textLicenseBox.setTextFormatted(getString(R.string.fragment_license__license_content,
|
||||
getMaintainersHtml(context),
|
||||
|
|
@ -160,8 +230,6 @@ public class AboutActivity extends AppCompatActivity {
|
|||
return rootView;
|
||||
}
|
||||
|
||||
private String accentColor;
|
||||
|
||||
public String getContributorsHtml(Context context) {
|
||||
String text = Helpers.readTextfileFromRawRessource(context, R.raw.contributors,
|
||||
"<font color='" + accentColor + "'><b>*</b></font> ", "<br>");
|
||||
|
|
@ -187,13 +255,52 @@ public class AboutActivity extends AppCompatActivity {
|
|||
text = text.replace("NEWENTRY", "<font color='" + accentColor + "'><b>*</b></font> ");
|
||||
return text;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void applyColorToViews() {
|
||||
ThemeHelper.updateTextViewColor(textLicense3partyBox);
|
||||
ThemeHelper.updateTextViewColor(textLicenseBox);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getFragmentTag() {
|
||||
return TAG;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreateBottomOptionsMenu(Menu menu, MenuInflater inflater) {
|
||||
/* Nothing to do */
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onBackPressed() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fragment that shows debug information like app version, pod version...
|
||||
*/
|
||||
public static class DebugFragment extends Fragment implements Observer {
|
||||
private TextView logBox;
|
||||
public static final String TAG = "com.github.dfa.diaspora_android.AboutActivity.DebugFragment";
|
||||
|
||||
@BindView(R.id.fragment_debug__package_name)
|
||||
TextView packageName;
|
||||
|
||||
@BindView(R.id.fragment_debug__app_version)
|
||||
TextView appVersion;
|
||||
|
||||
@BindView(R.id.fragment_debug__android_version)
|
||||
TextView osVersion;
|
||||
|
||||
@BindView(R.id.fragment_debug__device_name)
|
||||
TextView deviceName;
|
||||
|
||||
@BindView(R.id.fragment_debug__pod_domain)
|
||||
TextView podDomain;
|
||||
|
||||
@BindView(R.id.fragment_debug__log_box)
|
||||
TextView logBox;
|
||||
|
||||
public DebugFragment() {
|
||||
}
|
||||
|
|
@ -202,16 +309,10 @@ public class AboutActivity extends AppCompatActivity {
|
|||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
View rootView = inflater.inflate(R.layout.about__fragment_debug, container, false);
|
||||
TextView packageName = (TextView) rootView.findViewById(R.id.fragment_debug__package_name);
|
||||
TextView appVersion = (TextView) rootView.findViewById(R.id.fragment_debug__app_version);
|
||||
TextView osVersion = (TextView) rootView.findViewById(R.id.fragment_debug__android_version);
|
||||
TextView deviceName = (TextView) rootView.findViewById(R.id.fragment_debug__device_name);
|
||||
TextView podDomain = (TextView) rootView.findViewById(R.id.fragment_debug__pod_domain);
|
||||
logBox = (TextView) rootView.findViewById(R.id.fragment_debug__log_box);
|
||||
ButterKnife.bind(this, rootView);
|
||||
logBox.setOnLongClickListener(new View.OnLongClickListener() {
|
||||
@Override
|
||||
public boolean onLongClick(View view) {
|
||||
AppLog.d(this, "Long click registered");
|
||||
if (isAdded()) {
|
||||
ClipboardManager clipboard = (ClipboardManager) getActivity().getSystemService(CLIPBOARD_SERVICE);
|
||||
ClipData clip = ClipData.newPlainText("DEBUG_LOG", Log.getLogBuffer());
|
||||
|
|
@ -229,14 +330,14 @@ public class AboutActivity extends AppCompatActivity {
|
|||
if (isAdded()) {
|
||||
try {
|
||||
PackageInfo pInfo = getActivity().getPackageManager().getPackageInfo(getActivity().getPackageName(), 0);
|
||||
AppSettings settings = ((App) getActivity().getApplication()).getSettings();
|
||||
|
||||
AppSettings appSettings = ((App) getActivity().getApplication()).getSettings();
|
||||
DiasporaUrlHelper urls = new DiasporaUrlHelper(appSettings);
|
||||
packageName.setText(pInfo.packageName);
|
||||
appVersion.setText(getString(R.string.fragment_debug__app_version, pInfo.versionName + " (" + pInfo.versionCode + ")"));
|
||||
|
||||
osVersion.setText(getString(R.string.fragment_debug__android_version, Build.VERSION.RELEASE));
|
||||
deviceName.setText(getString(R.string.fragment_debug__device_name, Build.MANUFACTURER + " " + Build.MODEL));
|
||||
podDomain.setText(getString(R.string.fragment_debug__pod_domain, settings.getPodDomain()));
|
||||
podDomain.setText(getString(R.string.fragment_debug__pod_domain, urls.getPodUrl()));
|
||||
|
||||
} catch (PackageManager.NameNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
|
|
|
|||
|
|
@ -40,7 +40,6 @@ import android.support.v4.content.LocalBroadcastManager;
|
|||
import android.support.v4.view.GravityCompat;
|
||||
import android.support.v4.widget.DrawerLayout;
|
||||
import android.support.v7.app.ActionBarDrawerToggle;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.support.v7.widget.ActionMenuView;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import android.view.KeyEvent;
|
||||
|
|
@ -54,6 +53,7 @@ import android.widget.EditText;
|
|||
import android.widget.FrameLayout;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.RelativeLayout;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
|
|
@ -71,16 +71,21 @@ import com.github.dfa.diaspora_android.receiver.OpenExternalLinkReceiver;
|
|||
import com.github.dfa.diaspora_android.util.ProxyHandler;
|
||||
import com.github.dfa.diaspora_android.receiver.UpdateTitleReceiver;
|
||||
import com.github.dfa.diaspora_android.ui.BadgeDrawable;
|
||||
import com.github.dfa.diaspora_android.ui.IntellihideToolbarActivityListener;
|
||||
import com.github.dfa.diaspora_android.util.AppLog;
|
||||
import com.github.dfa.diaspora_android.util.CustomTabHelpers.CustomTabActivityHelper;
|
||||
import com.github.dfa.diaspora_android.util.DiasporaUrlHelper;
|
||||
import com.github.dfa.diaspora_android.util.theming.ThemeHelper;
|
||||
import com.github.dfa.diaspora_android.util.WebHelper;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
|
||||
public class MainActivity extends AppCompatActivity
|
||||
implements NavigationView.OnNavigationItemSelectedListener, WebUserProfileChangedListener, CustomTabActivityHelper.ConnectionCallback {
|
||||
public class MainActivity extends ThemedActivity
|
||||
implements NavigationView.OnNavigationItemSelectedListener,
|
||||
WebUserProfileChangedListener,
|
||||
CustomTabActivityHelper.ConnectionCallback,
|
||||
IntellihideToolbarActivityListener {
|
||||
|
||||
|
||||
public static final int REQUEST_CODE_ASK_PERMISSIONS = 123;
|
||||
|
|
@ -93,7 +98,6 @@ public class MainActivity extends AppCompatActivity
|
|||
public static final String ACTION_CHANGE_ACCOUNT = "com.github.dfa.diaspora_android.MainActivity.change_account";
|
||||
public static final String ACTION_CLEAR_CACHE = "com.github.dfa.diaspora_android.MainActivity.clear_cache";
|
||||
public static final String ACTION_UPDATE_TITLE_FROM_URL = "com.github.dfa.diaspora_android.MainActivity.set_title";
|
||||
public static final String ACTION_RELOAD_ACTIVITY = "com.github.dfa.diaspora_android.MainActivity.reload_activity";
|
||||
public static final String URL_MESSAGE = "URL_MESSAGE";
|
||||
public static final String EXTRA_URL = "com.github.dfa.diaspora_android.extra_url";
|
||||
public static final String CONTENT_HASHTAG = "content://com.github.dfa.diaspora_android.mainactivity/";
|
||||
|
|
@ -114,6 +118,9 @@ public class MainActivity extends AppCompatActivity
|
|||
/**
|
||||
* UI Bindings
|
||||
*/
|
||||
@BindView(R.id.main__appbar)
|
||||
AppBarLayout appBarLayout;
|
||||
|
||||
@BindView(R.id.main__topbar)
|
||||
Toolbar toolbarTop;
|
||||
|
||||
|
|
@ -129,6 +136,9 @@ public class MainActivity extends AppCompatActivity
|
|||
@BindView(R.id.main__navdrawer)
|
||||
DrawerLayout navDrawer;
|
||||
|
||||
RelativeLayout navDrawerLayout;
|
||||
LinearLayout navProfilePictureArea;
|
||||
|
||||
|
||||
// NavHeader cannot be bound by Butterknife
|
||||
private TextView navheaderTitle;
|
||||
|
|
@ -185,7 +195,7 @@ public class MainActivity extends AppCompatActivity
|
|||
}
|
||||
});
|
||||
|
||||
if(!appSettings.hasPodDomain()) {
|
||||
if (!appSettings.hasPodDomain()) {
|
||||
AppLog.d(this, "We have no pod. Show PodSelectionFragment");
|
||||
showFragment(getFragment(PodSelectionFragment.TAG));
|
||||
} else {
|
||||
|
|
@ -231,13 +241,6 @@ public class MainActivity extends AppCompatActivity
|
|||
|
||||
// Load app settings
|
||||
setupNavigationSlider();
|
||||
|
||||
if (!appSettings.isIntellihideToolbars()) {
|
||||
AppLog.v(this, "Disable intelligent hiding of toolbars");
|
||||
AppBarLayout.LayoutParams params = (AppBarLayout.LayoutParams) toolbarTop.getLayoutParams();
|
||||
params.setScrollFlags(0); // clear all scroll flags
|
||||
}
|
||||
|
||||
AppLog.v(this, "UI successfully set up");
|
||||
}
|
||||
|
||||
|
|
@ -261,7 +264,7 @@ public class MainActivity extends AppCompatActivity
|
|||
*/
|
||||
protected CustomFragment getFragment(String fragmentTag) {
|
||||
CustomFragment fragment = (CustomFragment) fm.findFragmentByTag(fragmentTag);
|
||||
if(fragment != null) {
|
||||
if (fragment != null) {
|
||||
return fragment;
|
||||
} else {
|
||||
switch (fragmentTag) {
|
||||
|
|
@ -282,8 +285,8 @@ public class MainActivity extends AppCompatActivity
|
|||
fm.beginTransaction().add(psf, fragmentTag).commit();
|
||||
return psf;
|
||||
default:
|
||||
AppLog.e(this,"Invalid Fragment Tag: "+fragmentTag
|
||||
+"\nAdd Fragments Tag to getFragment()'s switch case.");
|
||||
AppLog.e(this, "Invalid Fragment Tag: " + fragmentTag
|
||||
+ "\nAdd Fragments Tag to getFragment()'s switch case.");
|
||||
return getTopFragment();
|
||||
}
|
||||
}
|
||||
|
|
@ -296,7 +299,7 @@ public class MainActivity extends AppCompatActivity
|
|||
protected void showFragment(CustomFragment fragment) {
|
||||
AppLog.v(this, "showFragment()");
|
||||
CustomFragment currentTop = (CustomFragment) fm.findFragmentById(R.id.fragment_container);
|
||||
if(currentTop == null || !currentTop.getFragmentTag().equals(fragment.getFragmentTag())) {
|
||||
if (currentTop == null || !currentTop.getFragmentTag().equals(fragment.getFragmentTag())) {
|
||||
AppLog.v(this, "Fragment was not visible. Replace it.");
|
||||
fm.beginTransaction().addToBackStack(null).replace(R.id.fragment_container, fragment, fragment.getFragmentTag()).commit();
|
||||
invalidateOptionsMenu();
|
||||
|
|
@ -318,9 +321,10 @@ public class MainActivity extends AppCompatActivity
|
|||
navView.setNavigationItemSelectedListener(this);
|
||||
|
||||
View navHeader = navView.getHeaderView(0);
|
||||
LinearLayout navheaderProfileSection = ButterKnife.findById(navHeader, R.id.nav_profile_picture);
|
||||
navProfilePictureArea = ButterKnife.findById(navHeader, R.id.nav_profile_picture);
|
||||
navDrawerLayout = ButterKnife.findById(navHeader, R.id.nav_drawer);
|
||||
//Handle clicks on profile picture
|
||||
navheaderProfileSection.setOnClickListener(new View.OnClickListener() {
|
||||
navProfilePictureArea.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
navDrawer.closeDrawer(GravityCompat.START);
|
||||
|
|
@ -357,8 +361,10 @@ public class MainActivity extends AppCompatActivity
|
|||
}
|
||||
}
|
||||
}
|
||||
updateNavigationViewEntryVisibilities();
|
||||
}
|
||||
|
||||
// Set visibility
|
||||
protected void updateNavigationViewEntryVisibilities() {
|
||||
Menu navMenu = navView.getMenu();
|
||||
navMenu.findItem(R.id.nav_exit).setVisible(appSettings.isVisibleInNavExit());
|
||||
navMenu.findItem(R.id.nav_activities).setVisible(appSettings.isVisibleInNavActivities());
|
||||
|
|
@ -371,7 +377,7 @@ public class MainActivity extends AppCompatActivity
|
|||
navMenu.findItem(R.id.nav_profile).setVisible(appSettings.isVisibleInNavProfile());
|
||||
navMenu.findItem(R.id.nav_public).setVisible(appSettings.isVisibleInNavPublic_activities());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Forward incoming intents to handleIntent()
|
||||
* @param intent incoming
|
||||
|
|
@ -408,7 +414,7 @@ public class MainActivity extends AppCompatActivity
|
|||
return;
|
||||
} else {
|
||||
loadUrl = intent.getDataString();
|
||||
AppLog.v(this, "Intent has a delicious URL for us: "+loadUrl);
|
||||
AppLog.v(this, "Intent has a delicious URL for us: " + loadUrl);
|
||||
}
|
||||
} else if (ACTION_CHANGE_ACCOUNT.equals(action)) {
|
||||
AppLog.v(this, "Reset pod data and show PodSelectionFragment");
|
||||
|
|
@ -417,10 +423,6 @@ public class MainActivity extends AppCompatActivity
|
|||
} else if (ACTION_CLEAR_CACHE.equals(action)) {
|
||||
AppLog.v(this, "Clear WebView cache");
|
||||
((DiasporaStreamFragment) getFragment(DiasporaStreamFragment.TAG)).getWebView().clearCache(true);
|
||||
} else if (ACTION_RELOAD_ACTIVITY.equals(action)) {
|
||||
AppLog.v(this, "Recreate activity");
|
||||
recreate();
|
||||
return;
|
||||
} else if (Intent.ACTION_SEND.equals(action) && type != null) {
|
||||
switch (type) {
|
||||
case "text/plain":
|
||||
|
|
@ -447,13 +449,14 @@ public class MainActivity extends AppCompatActivity
|
|||
|
||||
/**
|
||||
* Handle activity results
|
||||
*
|
||||
* @param requestCode reqCode
|
||||
* @param resultCode resCode
|
||||
* @param data data
|
||||
* @param resultCode resCode
|
||||
* @param data data
|
||||
*/
|
||||
@Override
|
||||
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
AppLog.v(this, "onActivityResult(): "+requestCode);
|
||||
AppLog.v(this, "onActivityResult(): " + requestCode);
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
}
|
||||
|
||||
|
|
@ -463,7 +466,7 @@ public class MainActivity extends AppCompatActivity
|
|||
*/
|
||||
private CustomFragment getTopFragment() {
|
||||
Fragment top = fm.findFragmentById(R.id.fragment_container);
|
||||
if(top != null) {
|
||||
if (top != null) {
|
||||
return (CustomFragment) top;
|
||||
}
|
||||
return null;
|
||||
|
|
@ -480,12 +483,12 @@ public class MainActivity extends AppCompatActivity
|
|||
return;
|
||||
}
|
||||
CustomFragment top = getTopFragment();
|
||||
if(top != null) {
|
||||
if (top != null) {
|
||||
AppLog.v(this, "Top Fragment is not null");
|
||||
if(!top.onBackPressed()) {
|
||||
if (!top.onBackPressed()) {
|
||||
AppLog.v(this, "Top Fragment.onBackPressed was false");
|
||||
AppLog.v(this, "BackStackEntryCount: "+fm.getBackStackEntryCount());
|
||||
if(fm.getBackStackEntryCount()>0) {
|
||||
AppLog.v(this, "BackStackEntryCount: " + fm.getBackStackEntryCount());
|
||||
if (fm.getBackStackEntryCount() > 0) {
|
||||
fm.popBackStack();
|
||||
} else {
|
||||
snackbarExitApp.show();
|
||||
|
|
@ -530,6 +533,13 @@ public class MainActivity extends AppCompatActivity
|
|||
AppLog.v(this, "Register BroadcastReceivers");
|
||||
LocalBroadcastManager.getInstance(this).registerReceiver(brSetTitle, new IntentFilter(ACTION_UPDATE_TITLE_FROM_URL));
|
||||
LocalBroadcastManager.getInstance(this).registerReceiver(brOpenExternalLink, new IntentFilter(ACTION_OPEN_EXTERNAL_URL));
|
||||
this.appSettings = getAppSettings();
|
||||
if (appSettings.isIntellihideToolbars()) {
|
||||
this.enableToolbarHiding();
|
||||
} else {
|
||||
this.disableToolbarHiding();
|
||||
}
|
||||
updateNavigationViewEntryVisibilities();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -547,9 +557,9 @@ public class MainActivity extends AppCompatActivity
|
|||
toolbarBottom.setVisibility(View.VISIBLE);
|
||||
|
||||
CustomFragment top = getTopFragment();
|
||||
if(top != null) {
|
||||
if (top != null) {
|
||||
//Are we displaying a Fragment other than PodSelectionFragment?
|
||||
if(!top.getFragmentTag().equals(PodSelectionFragment.TAG)) {
|
||||
if (!top.getFragmentTag().equals(PodSelectionFragment.TAG)) {
|
||||
getMenuInflater().inflate(R.menu.main__menu_top, menu);
|
||||
getMenuInflater().inflate(R.menu.main__menu_bottom, toolbarBottom.getMenu());
|
||||
top.onCreateBottomOptionsMenu(toolbarBottom.getMenu(), getMenuInflater());
|
||||
|
|
@ -814,8 +824,8 @@ public class MainActivity extends AppCompatActivity
|
|||
|
||||
@Override
|
||||
public void onCustomTabsConnected() {
|
||||
if(customTabsSession == null) {
|
||||
AppLog.i(this, "CustomTabs warmup: "+customTabActivityHelper.warmup(0));
|
||||
if (customTabsSession == null) {
|
||||
AppLog.i(this, "CustomTabs warmup: " + customTabActivityHelper.warmup(0));
|
||||
customTabsSession = customTabActivityHelper.getSession();
|
||||
}
|
||||
}
|
||||
|
|
@ -973,4 +983,29 @@ public class MainActivity extends AppCompatActivity
|
|||
public void setTextToBeShared(String textToBeShared) {
|
||||
this.textToBeShared = textToBeShared;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void applyColorToViews() {
|
||||
ThemeHelper.updateToolbarColor(toolbarTop);
|
||||
ThemeHelper.updateActionMenuViewColor(toolbarBottom);
|
||||
navDrawerLayout.setBackgroundColor(appSettings.getPrimaryColor());
|
||||
navProfilePictureArea.setBackgroundColor(appSettings.getPrimaryColor());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void enableToolbarHiding() {
|
||||
AppLog.d(this, "Enable Intellihide");
|
||||
AppBarLayout.LayoutParams params = (AppBarLayout.LayoutParams) toolbarTop.getLayoutParams();
|
||||
//scroll|enterAlways|snap
|
||||
params.setScrollFlags(toolbarDefaultScrollFlags);
|
||||
appBarLayout.setExpanded(true, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disableToolbarHiding() {
|
||||
AppLog.d(this, "Disable Intellihide");
|
||||
AppBarLayout.LayoutParams params = (AppBarLayout.LayoutParams) toolbarTop.getLayoutParams();
|
||||
params.setScrollFlags(0); // clear all scroll flags
|
||||
appBarLayout.setExpanded(true, true);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,19 +1,15 @@
|
|||
/*
|
||||
This file is part of the Diaspora for Android.
|
||||
|
||||
Diaspora for Android 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.
|
||||
|
||||
Diaspora for Android 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 the Diaspora for Android.
|
||||
|
||||
If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.github.dfa.diaspora_android.activity;
|
||||
|
|
@ -25,37 +21,63 @@ import android.content.Context;
|
|||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.preference.EditTextPreference;
|
||||
import android.preference.ListPreference;
|
||||
import android.preference.Preference;
|
||||
import android.preference.PreferenceFragment;
|
||||
import android.preference.PreferenceScreen;
|
||||
import android.support.v7.app.ActionBar;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.support.design.widget.AppBarLayout;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.Window;
|
||||
import android.widget.FrameLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.github.dfa.diaspora_android.App;
|
||||
import com.github.dfa.diaspora_android.R;
|
||||
import com.github.dfa.diaspora_android.data.AppSettings;
|
||||
import com.github.dfa.diaspora_android.ui.IntellihideToolbarActivityListener;
|
||||
import com.github.dfa.diaspora_android.util.theming.ColorPalette;
|
||||
import com.github.dfa.diaspora_android.util.ProxyHandler;
|
||||
import com.github.dfa.diaspora_android.util.AppLog;
|
||||
import com.github.dfa.diaspora_android.util.theming.ThemeHelper;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
import uz.shift.colorpicker.LineColorPicker;
|
||||
import uz.shift.colorpicker.OnColorChangedListener;
|
||||
|
||||
/**
|
||||
* @author vanitas
|
||||
*/
|
||||
public class SettingsActivity extends AppCompatActivity {
|
||||
public class SettingsActivity extends ThemedActivity implements IntellihideToolbarActivityListener {
|
||||
@BindView(R.id.settings__appbar)
|
||||
protected AppBarLayout appBarLayout;
|
||||
|
||||
@BindView(R.id.settings__toolbar)
|
||||
protected Toolbar toolbar;
|
||||
|
||||
private ProxyHandler.ProxySettings oldProxySettings;
|
||||
private AppSettings appSettings;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
ActionBar toolbar = getSupportActionBar();
|
||||
if (toolbar != null)
|
||||
toolbar.setDisplayHomeAsUpEnabled(true);
|
||||
this.appSettings = new AppSettings(this);
|
||||
oldProxySettings = appSettings.getProxySettings();
|
||||
getFragmentManager().beginTransaction().replace(android.R.id.content, new SettingsFragment()).commit();
|
||||
setContentView(R.layout.settings__activity);
|
||||
ButterKnife.bind(this);
|
||||
setSupportActionBar(toolbar);
|
||||
toolbar.setNavigationIcon(getResources().getDrawable(R.drawable.ic_arrow_back_white_24px));
|
||||
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
SettingsActivity.this.onBackPressed();
|
||||
}
|
||||
});
|
||||
oldProxySettings = getAppSettings().getProxySettings();
|
||||
getFragmentManager().beginTransaction().replace(R.id.settings__fragment_container, new SettingsFragment()).commit();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -69,6 +91,28 @@ public class SettingsActivity extends AppCompatActivity {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void applyColorToViews() {
|
||||
ThemeHelper.updateToolbarColor(toolbar);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void enableToolbarHiding() {
|
||||
AppLog.d(this, "Enable Intellihide");
|
||||
AppBarLayout.LayoutParams params = (AppBarLayout.LayoutParams) toolbar.getLayoutParams();
|
||||
//scroll|enterAlways|snap
|
||||
params.setScrollFlags(toolbarDefaultScrollFlags);
|
||||
appBarLayout.setExpanded(true, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disableToolbarHiding() {
|
||||
AppLog.d(this, "Disable Intellihide");
|
||||
AppBarLayout.LayoutParams params = (AppBarLayout.LayoutParams) toolbar.getLayoutParams();
|
||||
params.setScrollFlags(0); // clear all scroll flags
|
||||
appBarLayout.setExpanded(true, true);
|
||||
}
|
||||
|
||||
public static class SettingsFragment extends PreferenceFragment implements SharedPreferences.OnSharedPreferenceChangeListener {
|
||||
private SharedPreferences sharedPreferences;
|
||||
|
||||
|
|
@ -96,6 +140,13 @@ public class SettingsActivity extends AppCompatActivity {
|
|||
@Override
|
||||
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
|
||||
updatePreference(findPreference(key));
|
||||
if(key.equals(getString(R.string.pref_key__intellihide_toolbars))) {
|
||||
if(sharedPreferences.getBoolean(getString(R.string.pref_key__intellihide_toolbars), false)) {
|
||||
((SettingsActivity)getActivity()).enableToolbarHiding();
|
||||
} else {
|
||||
((SettingsActivity)getActivity()).disableToolbarHiding();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void updatePreference(Preference preference) {
|
||||
|
|
@ -117,10 +168,29 @@ public class SettingsActivity extends AppCompatActivity {
|
|||
public boolean onPreferenceTreeClick(PreferenceScreen screen, Preference preference) {
|
||||
App app = ((App) getActivity().getApplication());
|
||||
AppSettings appSettings = app.getSettings();
|
||||
if(Build.VERSION.SDK_INT >= 21) {
|
||||
if (preference instanceof PreferenceScreen && ((PreferenceScreen) preference).getDialog() != null) {
|
||||
Window window = ((PreferenceScreen) preference).getDialog().getWindow();
|
||||
if (window != null) {
|
||||
window.setStatusBarColor(ThemeHelper.getPrimaryDarkColor());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Intent intent = new Intent(getActivity(), MainActivity.class);
|
||||
String podDomain = appSettings.getPodDomain();
|
||||
|
||||
switch (preference.getTitleRes()) {
|
||||
case R.string.pref_title__primary_color: {
|
||||
showColorPickerDialog(1);
|
||||
intent = null;
|
||||
break;
|
||||
}
|
||||
case R.string.pref_title__accent_color: {
|
||||
showColorPickerDialog(2);
|
||||
intent = null;
|
||||
break;
|
||||
}
|
||||
case R.string.pref_title__personal_settings: {
|
||||
intent.setAction(MainActivity.ACTION_OPEN_URL);
|
||||
intent.putExtra(MainActivity.URL_MESSAGE, "https://" + podDomain + "/user/edit");
|
||||
|
|
@ -177,6 +247,71 @@ public class SettingsActivity extends AppCompatActivity {
|
|||
}
|
||||
return super.onPreferenceTreeClick(screen, preference);
|
||||
}
|
||||
|
||||
/**
|
||||
* Show a colorPicker Dialog
|
||||
* @param type 1 -> Primary Color, 2 -> Accent Color
|
||||
*/
|
||||
public void showColorPickerDialog(final int type) {
|
||||
final AppSettings appSettings = ((App)getActivity().getApplication()).getSettings();
|
||||
final Context context = getActivity();
|
||||
|
||||
//Inflate dialog layout
|
||||
LayoutInflater inflater = getActivity().getLayoutInflater();
|
||||
View dialogLayout = inflater.inflate(R.layout.color_picker__dialog, null);
|
||||
final android.support.v7.app.AlertDialog.Builder builder = new android.support.v7.app.AlertDialog.Builder(context);
|
||||
builder.setView(dialogLayout);
|
||||
|
||||
final FrameLayout titleBackground = (FrameLayout) dialogLayout.findViewById(R.id.color_picker_dialog__title_background);
|
||||
final TextView title = (TextView) dialogLayout.findViewById(R.id.color_picker_dialog__title);
|
||||
final LineColorPicker base = (LineColorPicker) dialogLayout.findViewById(R.id.color_picker_dialog__base_picker);
|
||||
final LineColorPicker shade = (LineColorPicker) dialogLayout.findViewById(R.id.color_picker_dialog__shade_picker);
|
||||
|
||||
title.setText(type == 1 ? R.string.pref_title__primary_color : R.string.pref_title__accent_color);
|
||||
title.setTextColor(getResources().getColor(R.color.white));
|
||||
final int[] current = (type == 1 ? appSettings.getPrimaryColorSettings() : appSettings.getAccentColorSettings());
|
||||
base.setColors((type == 1 ? ColorPalette.getBaseColors(context) : ColorPalette.getAccentColors(context)));
|
||||
base.setSelectedColor(current[0]);
|
||||
shade.setColors(ColorPalette.getColors(context, current[0]));
|
||||
shade.setSelectedColor(current[1]);
|
||||
titleBackground.setBackgroundColor(shade.getColor());
|
||||
base.setOnColorChangedListener(new OnColorChangedListener() {
|
||||
@Override
|
||||
public void onColorChanged(int i) {
|
||||
AppLog.d(this, "Selected Base color changed: "+i);
|
||||
shade.setColors(ColorPalette.getColors(context, i));
|
||||
titleBackground.setBackgroundColor(i);
|
||||
if(i == current[0]) {
|
||||
shade.setSelectedColor(current[1]);
|
||||
titleBackground.setBackgroundColor(shade.getColor());
|
||||
}
|
||||
}
|
||||
});
|
||||
shade.setOnColorChangedListener(new OnColorChangedListener() {
|
||||
@Override
|
||||
public void onColorChanged(int i) {
|
||||
titleBackground.setBackgroundColor(i);
|
||||
}
|
||||
});
|
||||
|
||||
//Build dialog
|
||||
builder
|
||||
.setNegativeButton(android.R.string.cancel, null)
|
||||
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialogInterface, int i) {
|
||||
if(type == 1) {
|
||||
appSettings.setPrimaryColorSettings(base.getColor(), shade.getColor());
|
||||
if(Build.VERSION.SDK_INT >= 21) {
|
||||
getActivity().getWindow().setStatusBarColor(ThemeHelper.getPrimaryDarkColor());
|
||||
}
|
||||
((ThemedActivity)getActivity()).applyColorToViews();
|
||||
} else {
|
||||
appSettings.setAccentColorSettings(base.getColor(), shade.getColor());
|
||||
}
|
||||
}
|
||||
}).show();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -191,7 +326,7 @@ public class SettingsActivity extends AppCompatActivity {
|
|||
|
||||
@Override
|
||||
protected void onStop() {
|
||||
ProxyHandler.ProxySettings newProxySettings = appSettings.getProxySettings();
|
||||
ProxyHandler.ProxySettings newProxySettings = getAppSettings().getProxySettings();
|
||||
if(!oldProxySettings.equals(newProxySettings)) {
|
||||
AppLog.d(this, "ProxySettings changed.");
|
||||
//Proxy on-off? => Restart app
|
||||
|
|
|
|||
|
|
@ -0,0 +1,78 @@
|
|||
/*
|
||||
This file is part of the Diaspora for Android.
|
||||
|
||||
Diaspora for Android 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.
|
||||
|
||||
Diaspora for Android 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 the Diaspora for Android.
|
||||
|
||||
If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.github.dfa.diaspora_android.activity;
|
||||
|
||||
import android.annotation.TargetApi;
|
||||
import android.app.ActivityManager;
|
||||
import android.graphics.drawable.BitmapDrawable;
|
||||
import android.os.Build;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
|
||||
import com.github.dfa.diaspora_android.App;
|
||||
import com.github.dfa.diaspora_android.R;
|
||||
import com.github.dfa.diaspora_android.data.AppSettings;
|
||||
import com.github.dfa.diaspora_android.util.theming.ThemeHelper;
|
||||
|
||||
/**
|
||||
* Activity that supports color schemes
|
||||
* Created by vanitas on 06.10.16.
|
||||
*/
|
||||
|
||||
public abstract class ThemedActivity extends AppCompatActivity {
|
||||
|
||||
protected AppSettings getAppSettings() {
|
||||
return ((App)getApplication()).getSettings();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
ThemeHelper.getInstance(getAppSettings());
|
||||
updateStatusBarColor();
|
||||
updateRecentAppColor();
|
||||
applyColorToViews();
|
||||
}
|
||||
protected abstract void applyColorToViews();
|
||||
|
||||
/**
|
||||
* Update color of the status bar
|
||||
*/
|
||||
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
|
||||
private void updateStatusBarColor() {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||
getWindow().setStatusBarColor(ThemeHelper.getPrimaryDarkColor());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update primary color in recent apps overview
|
||||
*/
|
||||
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
|
||||
private void updateRecentAppColor(){
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||
BitmapDrawable drawable = ((BitmapDrawable) getDrawable(R.drawable.ic_launcher));
|
||||
if(drawable != null) {
|
||||
setTaskDescription(new ActivityManager.TaskDescription(
|
||||
getResources().getString(R.string.app_name),
|
||||
drawable.getBitmap(),
|
||||
getAppSettings().getPrimaryColor()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,19 +1,15 @@
|
|||
/*
|
||||
This file is part of the Diaspora for Android.
|
||||
|
||||
Diaspora for Android 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.
|
||||
|
||||
Diaspora for Android 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 the Diaspora for Android.
|
||||
|
||||
If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.github.dfa.diaspora_android.data;
|
||||
|
|
@ -319,4 +315,36 @@ public class AppSettings {
|
|||
public boolean isVisibleInNavProfile() {
|
||||
return getBoolean(prefApp, R.string.pref_key__visibility_nav__profile, false);
|
||||
}
|
||||
}
|
||||
|
||||
public void setPrimaryColorSettings(int base, int shade) {
|
||||
setInt(prefApp, R.string.pref_key__primary_color_base, base);
|
||||
setInt(prefApp, R.string.pref_key__primary_color_shade, shade);
|
||||
}
|
||||
|
||||
public int[] getPrimaryColorSettings() {
|
||||
return new int[]{
|
||||
getInt(prefApp, R.string.pref_key__primary_color_base, context.getResources().getColor(R.color.md_blue_500)),
|
||||
getInt(prefApp, R.string.pref_key__primary_color_shade, context.getResources().getColor(R.color.primary))
|
||||
};
|
||||
}
|
||||
|
||||
public int getPrimaryColor() {
|
||||
return getInt(prefApp, R.string.pref_key__primary_color_shade, context.getResources().getColor(R.color.primary));
|
||||
}
|
||||
|
||||
public void setAccentColorSettings(int base, int shade) {
|
||||
setInt(prefApp, R.string.pref_key__accent_color_base, base);
|
||||
setInt(prefApp, R.string.pref_key__accent_color_shade, shade);
|
||||
}
|
||||
|
||||
public int[] getAccentColorSettings() {
|
||||
return new int[]{
|
||||
getInt(prefApp, R.string.pref_key__accent_color_base, context.getResources().getColor(R.color.md_deep_orange_500)),
|
||||
getInt(prefApp, R.string.pref_key__accent_color_shade, context.getResources().getColor(R.color.accent))
|
||||
};
|
||||
}
|
||||
|
||||
public int getAccentColor() {
|
||||
return getInt(prefApp, R.string.pref_key__accent_color_shade, context.getResources().getColor(R.color.accent));
|
||||
}
|
||||
}
|
||||
|
|
@ -43,6 +43,7 @@ import com.github.dfa.diaspora_android.activity.MainActivity;
|
|||
import com.github.dfa.diaspora_android.data.AppSettings;
|
||||
import com.github.dfa.diaspora_android.util.ProxyHandler;
|
||||
import com.github.dfa.diaspora_android.ui.ContextMenuWebView;
|
||||
import com.github.dfa.diaspora_android.util.theming.ThemeHelper;
|
||||
import com.github.dfa.diaspora_android.util.AppLog;
|
||||
import com.github.dfa.diaspora_android.webview.CustomWebViewClient;
|
||||
import com.github.dfa.diaspora_android.webview.ProgressBarWebChromeClient;
|
||||
|
|
@ -62,7 +63,7 @@ import java.util.Locale;
|
|||
* Created by vanitas on 26.09.16.
|
||||
*/
|
||||
|
||||
public class BrowserFragment extends CustomFragment {
|
||||
public class BrowserFragment extends ThemedFragment {
|
||||
public static final String TAG = "com.github.dfa.diaspora_android.BrowserFragment";
|
||||
|
||||
protected View rootLayout;
|
||||
|
|
@ -145,6 +146,15 @@ public class BrowserFragment extends CustomFragment {
|
|||
webView.setWebChromeClient(new ProgressBarWebChromeClient(webView, progressBar));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
if(webView != null) {
|
||||
webSettings.setMinimumFontSize(appSettings.getMinimumFontSize());
|
||||
webSettings.setLoadsImagesAutomatically(appSettings.isLoadImages());
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("ResultOfMethodCallIgnored")
|
||||
protected boolean makeScreenshotOfWebView(boolean hasToShareScreenshot) {
|
||||
AppLog.i(this, "StreamFragment.makeScreenshotOfWebView()");
|
||||
|
|
@ -273,4 +283,9 @@ public class BrowserFragment extends CustomFragment {
|
|||
public ContextMenuWebView getWebView() {
|
||||
return this.webView;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void applyColorToViews() {
|
||||
ThemeHelper.updateProgressBarColor(progressBar);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,43 @@
|
|||
/*
|
||||
This file is part of the Diaspora for Android.
|
||||
|
||||
Diaspora for Android 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.
|
||||
|
||||
Diaspora for Android 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 the Diaspora for Android.
|
||||
|
||||
If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.github.dfa.diaspora_android.fragment;
|
||||
|
||||
import com.github.dfa.diaspora_android.App;
|
||||
import com.github.dfa.diaspora_android.data.AppSettings;
|
||||
import com.github.dfa.diaspora_android.util.theming.ThemeHelper;
|
||||
|
||||
/**
|
||||
* Fragment that supports color schemes
|
||||
* Created by vanitas on 06.10.16.
|
||||
*/
|
||||
|
||||
public abstract class ThemedFragment extends CustomFragment {
|
||||
protected AppSettings getAppSettings() {
|
||||
return ((App)getActivity().getApplication()).getSettings();
|
||||
}
|
||||
|
||||
protected abstract void applyColorToViews();
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
ThemeHelper.getInstance(getAppSettings());
|
||||
applyColorToViews();
|
||||
}
|
||||
}
|
||||
|
|
@ -33,7 +33,7 @@ import com.github.dfa.diaspora_android.data.AppSettings;
|
|||
import com.github.dfa.diaspora_android.util.AppLog;
|
||||
import com.github.dfa.diaspora_android.util.CustomTabHelpers.BrowserFallback;
|
||||
import com.github.dfa.diaspora_android.util.CustomTabHelpers.CustomTabActivityHelper;
|
||||
import com.github.dfa.diaspora_android.util.Helpers;
|
||||
import com.github.dfa.diaspora_android.util.theming.ThemeHelper;
|
||||
|
||||
/**
|
||||
* BroadcastReceiver that opens links in a Chrome CustomTab
|
||||
|
|
@ -48,9 +48,10 @@ public class OpenExternalLinkReceiver extends BroadcastReceiver {
|
|||
|
||||
@Override
|
||||
public void onReceive(Context c, Intent receiveIntent) {
|
||||
AppSettings settings = new AppSettings(c);
|
||||
AppSettings appSettings = new AppSettings(c);
|
||||
ThemeHelper.getInstance(appSettings);
|
||||
|
||||
AppLog.v(this, "OpenExternalLinkReceiver.onReceive(): url");
|
||||
AppLog.v(this, "OpenExternalLinkReceiver.onReceive(): url");
|
||||
|
||||
Uri url = null;
|
||||
try {
|
||||
|
|
@ -61,10 +62,10 @@ public class OpenExternalLinkReceiver extends BroadcastReceiver {
|
|||
return;
|
||||
}
|
||||
|
||||
if (settings.isChromeCustomTabsEnabled()) {
|
||||
if (appSettings.isChromeCustomTabsEnabled()) {
|
||||
// Setup Chrome Custom Tab
|
||||
CustomTabsIntent.Builder customTab = new CustomTabsIntent.Builder();
|
||||
customTab.setToolbarColor(Helpers.getColorFromRessource(c, R.color.colorPrimary));
|
||||
customTab.setToolbarColor(ThemeHelper.getPrimaryColor());
|
||||
customTab.addDefaultShareMenuItem();
|
||||
|
||||
Bitmap backButtonIcon = BitmapFactory.decodeResource(c.getResources(), R.drawable.chrome_custom_tab__back);
|
||||
|
|
|
|||
|
|
@ -48,7 +48,7 @@ public class BadgeDrawable extends Drawable {
|
|||
float textSize = context.getResources().getDimension(R.dimen.textsize_badge_count);
|
||||
|
||||
badgeBackground = new Paint();
|
||||
badgeBackground.setColor(ContextCompat.getColor(context.getApplicationContext(), R.color.accent));
|
||||
badgeBackground.setColor(ContextCompat.getColor(context.getApplicationContext(), R.color.md_deep_orange_650));
|
||||
badgeBackground.setAntiAlias(true);
|
||||
badgeBackground.setStyle(Paint.Style.FILL);
|
||||
badgeStroke = new Paint();
|
||||
|
|
|
|||
|
|
@ -0,0 +1,14 @@
|
|||
package com.github.dfa.diaspora_android.ui;
|
||||
|
||||
import android.support.design.widget.AppBarLayout;
|
||||
|
||||
/**
|
||||
* interface that adds options to control intellihide of toolbars to the Activity
|
||||
* Created by vanitas on 08.10.16.
|
||||
*/
|
||||
|
||||
public interface IntellihideToolbarActivityListener {
|
||||
int toolbarDefaultScrollFlags = AppBarLayout.LayoutParams.SCROLL_FLAG_SCROLL | AppBarLayout.LayoutParams.SCROLL_FLAG_ENTER_ALWAYS | AppBarLayout.LayoutParams.SCROLL_FLAG_SNAP;
|
||||
void enableToolbarHiding();
|
||||
void disableToolbarHiding();
|
||||
}
|
||||
|
|
@ -113,6 +113,10 @@ public class Helpers {
|
|||
return "#" + Integer.toHexString(context.getResources().getColor(idColor) & 0x00ffffff);
|
||||
}
|
||||
|
||||
public static String colorToHex(int color) {
|
||||
return "#" + Integer.toHexString(color & 0x00ffffff);
|
||||
}
|
||||
|
||||
public static void printBundle(Bundle savedInstanceState, String k) {
|
||||
if (savedInstanceState != null) {
|
||||
for (String key : savedInstanceState.keySet()) {
|
||||
|
|
|
|||
|
|
@ -0,0 +1,288 @@
|
|||
package com.github.dfa.diaspora_android.util.theming;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Color;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.support.v4.graphics.ColorUtils;
|
||||
|
||||
import com.github.dfa.diaspora_android.R;
|
||||
|
||||
/**
|
||||
* Created by dnld on 24/02/16.
|
||||
*/
|
||||
public class ColorPalette {
|
||||
|
||||
public static int[] getAccentColors(Context context){
|
||||
return new int[]{
|
||||
ContextCompat.getColor(context, R.color.md_red_500),
|
||||
ContextCompat.getColor(context, R.color.md_purple_500),
|
||||
ContextCompat.getColor(context, R.color.md_deep_purple_500),
|
||||
ContextCompat.getColor(context, R.color.md_blue_500),
|
||||
ContextCompat.getColor(context, R.color.md_light_blue_500),
|
||||
ContextCompat.getColor(context, R.color.md_cyan_500),
|
||||
ContextCompat.getColor(context, R.color.md_teal_500),
|
||||
ContextCompat.getColor(context, R.color.md_green_500),
|
||||
ContextCompat.getColor(context, R.color.md_yellow_500),
|
||||
ContextCompat.getColor(context, R.color.md_orange_500),
|
||||
ContextCompat.getColor(context, R.color.md_deep_orange_500),
|
||||
ContextCompat.getColor(context, R.color.md_brown_500),
|
||||
ContextCompat.getColor(context, R.color.md_blue_grey_500),
|
||||
};
|
||||
}
|
||||
|
||||
public static int getObscuredColor(int c){
|
||||
float[] hsv = new float[3];
|
||||
int color = c;
|
||||
Color.colorToHSV(color, hsv);
|
||||
hsv[2] *= 0.85f; // value component
|
||||
color = Color.HSVToColor(hsv);
|
||||
return color;
|
||||
}
|
||||
|
||||
public static int getTransparentColor(int color, int alpha){
|
||||
return ColorUtils.setAlphaComponent(color, alpha);
|
||||
}
|
||||
|
||||
public static int[] getTransparencyShadows(int color) {
|
||||
int[] shadows = new int[10];
|
||||
for (int i=0; i<10;i++)
|
||||
shadows[i]= (ColorPalette.getTransparentColor(color, ((100-(i*10))*255) /100));
|
||||
return shadows;
|
||||
}
|
||||
|
||||
public static int[] getBaseColors(Context context) {
|
||||
return new int[]{
|
||||
ContextCompat.getColor(context, R.color.md_red_500),
|
||||
ContextCompat.getColor(context, R.color.md_pink_500),
|
||||
ContextCompat.getColor(context, R.color.md_purple_500),
|
||||
ContextCompat.getColor(context, R.color.md_deep_purple_500),
|
||||
ContextCompat.getColor(context, R.color.md_indigo_500),
|
||||
ContextCompat.getColor(context, R.color.md_blue_500),
|
||||
ContextCompat.getColor(context, R.color.md_light_blue_500),
|
||||
ContextCompat.getColor(context, R.color.md_cyan_500),
|
||||
ContextCompat.getColor(context, R.color.md_teal_500),
|
||||
ContextCompat.getColor(context, R.color.md_green_500),
|
||||
ContextCompat.getColor(context, R.color.md_light_green_500),
|
||||
ContextCompat.getColor(context, R.color.md_lime_500),
|
||||
ContextCompat.getColor(context, R.color.md_yellow_500),
|
||||
ContextCompat.getColor(context, R.color.md_amber_500),
|
||||
ContextCompat.getColor(context, R.color.md_orange_500),
|
||||
ContextCompat.getColor(context, R.color.md_deep_orange_500),
|
||||
ContextCompat.getColor(context, R.color.md_brown_500),
|
||||
ContextCompat.getColor(context, R.color.md_blue_grey_500),
|
||||
ContextCompat.getColor(context, R.color.md_grey_500)
|
||||
};
|
||||
}
|
||||
|
||||
public static int[] getColors(Context context, int c) {
|
||||
if (c == ContextCompat.getColor(context, R.color.md_red_500)) {
|
||||
return new int[]{
|
||||
ContextCompat.getColor(context, R.color.md_red_200),
|
||||
ContextCompat.getColor(context, R.color.md_red_300),
|
||||
ContextCompat.getColor(context, R.color.md_red_400),
|
||||
ContextCompat.getColor(context, R.color.md_red_500),
|
||||
ContextCompat.getColor(context, R.color.md_red_600),
|
||||
ContextCompat.getColor(context, R.color.md_red_700),
|
||||
ContextCompat.getColor(context, R.color.md_red_800),
|
||||
ContextCompat.getColor(context, R.color.md_red_900)
|
||||
};
|
||||
} else if (c == ContextCompat.getColor(context, R.color.md_pink_500)) {
|
||||
return new int[]{
|
||||
ContextCompat.getColor(context, R.color.md_pink_200),
|
||||
ContextCompat.getColor(context, R.color.md_pink_300),
|
||||
ContextCompat.getColor(context, R.color.md_pink_400),
|
||||
ContextCompat.getColor(context, R.color.md_pink_500),
|
||||
ContextCompat.getColor(context, R.color.md_pink_600),
|
||||
ContextCompat.getColor(context, R.color.md_pink_700),
|
||||
ContextCompat.getColor(context, R.color.md_pink_800),
|
||||
ContextCompat.getColor(context, R.color.md_pink_900)
|
||||
};
|
||||
} else if (c == ContextCompat.getColor(context, R.color.md_purple_500)) {
|
||||
return new int[]{
|
||||
ContextCompat.getColor(context, R.color.md_purple_200),
|
||||
ContextCompat.getColor(context, R.color.md_purple_300),
|
||||
ContextCompat.getColor(context, R.color.md_purple_400),
|
||||
ContextCompat.getColor(context, R.color.md_purple_500),
|
||||
ContextCompat.getColor(context, R.color.md_purple_600),
|
||||
ContextCompat.getColor(context, R.color.md_purple_700),
|
||||
ContextCompat.getColor(context, R.color.md_purple_800),
|
||||
ContextCompat.getColor(context, R.color.md_purple_900)
|
||||
};
|
||||
} else if (c == ContextCompat.getColor(context, R.color.md_deep_purple_500)) {
|
||||
return new int[]{
|
||||
ContextCompat.getColor(context, R.color.md_deep_purple_200),
|
||||
ContextCompat.getColor(context, R.color.md_deep_purple_300),
|
||||
ContextCompat.getColor(context, R.color.md_deep_purple_400),
|
||||
ContextCompat.getColor(context, R.color.md_deep_purple_500),
|
||||
ContextCompat.getColor(context, R.color.md_deep_purple_600),
|
||||
ContextCompat.getColor(context, R.color.md_deep_purple_700),
|
||||
ContextCompat.getColor(context, R.color.md_deep_purple_800),
|
||||
ContextCompat.getColor(context, R.color.md_deep_purple_900)
|
||||
};
|
||||
} else if (c == ContextCompat.getColor(context, R.color.md_indigo_500)) {
|
||||
return new int[]{
|
||||
ContextCompat.getColor(context, R.color.md_indigo_200),
|
||||
ContextCompat.getColor(context, R.color.md_indigo_300),
|
||||
ContextCompat.getColor(context, R.color.md_indigo_400),
|
||||
ContextCompat.getColor(context, R.color.md_indigo_500),
|
||||
ContextCompat.getColor(context, R.color.md_indigo_600),
|
||||
ContextCompat.getColor(context, R.color.md_indigo_700),
|
||||
ContextCompat.getColor(context, R.color.md_indigo_800),
|
||||
ContextCompat.getColor(context, R.color.md_indigo_900)
|
||||
};
|
||||
} else if (c == ContextCompat.getColor(context, R.color.md_blue_500)) {
|
||||
return new int[]{
|
||||
ContextCompat.getColor(context, R.color.md_blue_200),
|
||||
ContextCompat.getColor(context, R.color.md_blue_300),
|
||||
ContextCompat.getColor(context, R.color.md_blue_400),
|
||||
ContextCompat.getColor(context, R.color.md_blue_500),
|
||||
ContextCompat.getColor(context, R.color.md_blue_600),
|
||||
ContextCompat.getColor(context, R.color.md_blue_650),
|
||||
ContextCompat.getColor(context, R.color.md_blue_700),
|
||||
ContextCompat.getColor(context, R.color.md_blue_750),
|
||||
ContextCompat.getColor(context, R.color.md_blue_800),
|
||||
ContextCompat.getColor(context, R.color.md_blue_900)
|
||||
};
|
||||
} else if (c == ContextCompat.getColor(context, R.color.md_light_blue_500)) {
|
||||
return new int[]{
|
||||
ContextCompat.getColor(context, R.color.md_light_blue_200),
|
||||
ContextCompat.getColor(context, R.color.md_light_blue_300),
|
||||
ContextCompat.getColor(context, R.color.md_light_blue_400),
|
||||
ContextCompat.getColor(context, R.color.md_light_blue_500),
|
||||
ContextCompat.getColor(context, R.color.md_light_blue_600),
|
||||
ContextCompat.getColor(context, R.color.md_light_blue_700),
|
||||
ContextCompat.getColor(context, R.color.md_light_blue_800),
|
||||
ContextCompat.getColor(context, R.color.md_light_blue_900)
|
||||
};
|
||||
} else if (c == ContextCompat.getColor(context, R.color.md_cyan_500)) {
|
||||
return new int[]{
|
||||
ContextCompat.getColor(context, R.color.md_cyan_200),
|
||||
ContextCompat.getColor(context, R.color.md_cyan_300),
|
||||
ContextCompat.getColor(context, R.color.md_cyan_400),
|
||||
ContextCompat.getColor(context, R.color.md_cyan_500),
|
||||
ContextCompat.getColor(context, R.color.md_cyan_600),
|
||||
ContextCompat.getColor(context, R.color.md_cyan_700),
|
||||
ContextCompat.getColor(context, R.color.md_cyan_800),
|
||||
ContextCompat.getColor(context, R.color.md_cyan_900)
|
||||
};
|
||||
} else if (c == ContextCompat.getColor(context, R.color.md_teal_500)) {
|
||||
return new int[]{
|
||||
ContextCompat.getColor(context, R.color.md_teal_200),
|
||||
ContextCompat.getColor(context, R.color.md_teal_300),
|
||||
ContextCompat.getColor(context, R.color.md_teal_400),
|
||||
ContextCompat.getColor(context, R.color.md_teal_500),
|
||||
ContextCompat.getColor(context, R.color.md_teal_600),
|
||||
ContextCompat.getColor(context, R.color.md_teal_700),
|
||||
ContextCompat.getColor(context, R.color.md_teal_800),
|
||||
ContextCompat.getColor(context, R.color.md_teal_900)
|
||||
};
|
||||
} else if (c == ContextCompat.getColor(context, R.color.md_green_500)) {
|
||||
return new int[]{
|
||||
ContextCompat.getColor(context, R.color.md_green_200),
|
||||
ContextCompat.getColor(context, R.color.md_green_300),
|
||||
ContextCompat.getColor(context, R.color.md_green_400),
|
||||
ContextCompat.getColor(context, R.color.md_green_500),
|
||||
ContextCompat.getColor(context, R.color.md_green_600),
|
||||
ContextCompat.getColor(context, R.color.md_green_700),
|
||||
ContextCompat.getColor(context, R.color.md_green_800),
|
||||
ContextCompat.getColor(context, R.color.md_green_900)
|
||||
};
|
||||
} else if (c == ContextCompat.getColor(context, R.color.md_light_green_500)) {
|
||||
return new int[]{
|
||||
ContextCompat.getColor(context, R.color.md_light_green_200),
|
||||
ContextCompat.getColor(context, R.color.md_light_green_300),
|
||||
ContextCompat.getColor(context, R.color.md_light_green_400),
|
||||
ContextCompat.getColor(context, R.color.md_light_green_500),
|
||||
ContextCompat.getColor(context, R.color.md_light_green_600),
|
||||
ContextCompat.getColor(context, R.color.md_light_green_700),
|
||||
ContextCompat.getColor(context, R.color.md_light_green_800),
|
||||
ContextCompat.getColor(context, R.color.md_light_green_900)
|
||||
};
|
||||
} else if (c == ContextCompat.getColor(context, R.color.md_lime_500)) {
|
||||
return new int[]{
|
||||
ContextCompat.getColor(context, R.color.md_lime_200),
|
||||
ContextCompat.getColor(context, R.color.md_lime_300),
|
||||
ContextCompat.getColor(context, R.color.md_lime_400),
|
||||
ContextCompat.getColor(context, R.color.md_lime_500),
|
||||
ContextCompat.getColor(context, R.color.md_lime_600),
|
||||
ContextCompat.getColor(context, R.color.md_lime_700),
|
||||
ContextCompat.getColor(context, R.color.md_lime_800),
|
||||
ContextCompat.getColor(context, R.color.md_lime_900)
|
||||
};
|
||||
} else if (c == ContextCompat.getColor(context, R.color.md_yellow_500)) {
|
||||
return new int[]{
|
||||
ContextCompat.getColor(context, R.color.md_yellow_400),
|
||||
ContextCompat.getColor(context, R.color.md_yellow_500),
|
||||
ContextCompat.getColor(context, R.color.md_yellow_600),
|
||||
ContextCompat.getColor(context, R.color.md_yellow_700),
|
||||
ContextCompat.getColor(context, R.color.md_yellow_800),
|
||||
ContextCompat.getColor(context, R.color.md_yellow_900)
|
||||
};
|
||||
} else if (c == ContextCompat.getColor(context, R.color.md_amber_500)) {
|
||||
return new int[]{
|
||||
ContextCompat.getColor(context, R.color.md_amber_200),
|
||||
ContextCompat.getColor(context, R.color.md_amber_300),
|
||||
ContextCompat.getColor(context, R.color.md_amber_400),
|
||||
ContextCompat.getColor(context, R.color.md_amber_500),
|
||||
ContextCompat.getColor(context, R.color.md_amber_600),
|
||||
ContextCompat.getColor(context, R.color.md_amber_700),
|
||||
ContextCompat.getColor(context, R.color.md_amber_800),
|
||||
ContextCompat.getColor(context, R.color.md_amber_900)
|
||||
};
|
||||
} else if (c == ContextCompat.getColor(context, R.color.md_orange_500)) {
|
||||
return new int[]{
|
||||
ContextCompat.getColor(context, R.color.md_orange_200),
|
||||
ContextCompat.getColor(context, R.color.md_orange_300),
|
||||
ContextCompat.getColor(context, R.color.md_orange_400),
|
||||
ContextCompat.getColor(context, R.color.md_orange_500),
|
||||
ContextCompat.getColor(context, R.color.md_orange_600),
|
||||
ContextCompat.getColor(context, R.color.md_orange_700),
|
||||
ContextCompat.getColor(context, R.color.md_orange_800),
|
||||
ContextCompat.getColor(context, R.color.md_orange_900)
|
||||
};
|
||||
} else if (c == ContextCompat.getColor(context, R.color.md_deep_orange_500)) {
|
||||
return new int[]{
|
||||
ContextCompat.getColor(context, R.color.md_deep_orange_200),
|
||||
ContextCompat.getColor(context, R.color.md_deep_orange_300),
|
||||
ContextCompat.getColor(context, R.color.md_deep_orange_400),
|
||||
ContextCompat.getColor(context, R.color.md_deep_orange_500),
|
||||
ContextCompat.getColor(context, R.color.md_deep_orange_600),
|
||||
ContextCompat.getColor(context, R.color.md_deep_orange_650),
|
||||
ContextCompat.getColor(context, R.color.md_deep_orange_700),
|
||||
ContextCompat.getColor(context, R.color.md_deep_orange_800),
|
||||
ContextCompat.getColor(context, R.color.md_deep_orange_900)
|
||||
};
|
||||
} else if (c == ContextCompat.getColor(context, R.color.md_brown_500)) {
|
||||
return new int[]{
|
||||
ContextCompat.getColor(context, R.color.md_brown_200),
|
||||
ContextCompat.getColor(context, R.color.md_brown_300),
|
||||
ContextCompat.getColor(context, R.color.md_brown_400),
|
||||
ContextCompat.getColor(context, R.color.md_brown_500),
|
||||
ContextCompat.getColor(context, R.color.md_brown_600),
|
||||
ContextCompat.getColor(context, R.color.md_brown_700),
|
||||
ContextCompat.getColor(context, R.color.md_brown_800),
|
||||
ContextCompat.getColor(context, R.color.md_brown_900)
|
||||
};
|
||||
} else if (c == ContextCompat.getColor(context, R.color.md_grey_500)) {
|
||||
return new int[]{
|
||||
ContextCompat.getColor(context, R.color.md_grey_400),
|
||||
ContextCompat.getColor(context, R.color.md_grey_500),
|
||||
ContextCompat.getColor(context, R.color.md_grey_600),
|
||||
ContextCompat.getColor(context, R.color.md_grey_700),
|
||||
ContextCompat.getColor(context, R.color.md_grey_800),
|
||||
ContextCompat.getColor(context, R.color.md_grey_900),
|
||||
Color.parseColor("#000000")
|
||||
};
|
||||
} else {
|
||||
return new int[]{
|
||||
ContextCompat.getColor(context, R.color.md_blue_grey_300),
|
||||
ContextCompat.getColor(context, R.color.md_blue_grey_400),
|
||||
ContextCompat.getColor(context, R.color.md_blue_grey_500),
|
||||
ContextCompat.getColor(context, R.color.md_blue_grey_600),
|
||||
ContextCompat.getColor(context, R.color.md_blue_grey_700),
|
||||
ContextCompat.getColor(context, R.color.md_blue_grey_800),
|
||||
ContextCompat.getColor(context, R.color.md_blue_grey_900)
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,128 @@
|
|||
/*
|
||||
This file is part of the Diaspora for Android.
|
||||
|
||||
Diaspora for Android 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.
|
||||
|
||||
Diaspora for Android 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 the Diaspora for Android.
|
||||
|
||||
If not, see <http://www.gnu.org/licenses/>.
|
||||
This class is inspired by org.horasapps.LeafPic
|
||||
*/
|
||||
package com.github.dfa.diaspora_android.util.theming;
|
||||
|
||||
import android.graphics.PorterDuff;
|
||||
import android.graphics.drawable.ColorDrawable;
|
||||
import android.support.design.widget.TabLayout;
|
||||
import android.support.v7.app.ActionBar;
|
||||
import android.support.v7.widget.ActionMenuView;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import android.view.View;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.EditText;
|
||||
import android.widget.ProgressBar;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.github.dfa.diaspora_android.data.AppSettings;
|
||||
|
||||
/**
|
||||
* Singleton that can be used to color views
|
||||
* Created by vanitas on 06.10.16.
|
||||
*/
|
||||
|
||||
public class ThemeHelper {
|
||||
private AppSettings appSettings;
|
||||
private static ThemeHelper instance;
|
||||
|
||||
private ThemeHelper(AppSettings appSettings) {
|
||||
this.appSettings = appSettings;
|
||||
}
|
||||
|
||||
public static ThemeHelper getInstance(AppSettings appSettings) {
|
||||
if(instance == null) {
|
||||
instance = new ThemeHelper(appSettings);
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
public static ThemeHelper getInstance() {
|
||||
if(instance == null) throw new IllegalStateException("ThemeHelper must be initialized using getInstance(AppSettings) before it can be used!");
|
||||
return instance;
|
||||
}
|
||||
|
||||
public static void updateEditTextColor(EditText editText) {
|
||||
if(editText != null) {
|
||||
editText.setHighlightColor(getInstance().appSettings.getAccentColor());
|
||||
}
|
||||
}
|
||||
|
||||
public static void updateCheckBoxColor(CheckBox checkBox) {
|
||||
if(checkBox != null) {
|
||||
checkBox.setHighlightColor(getInstance().appSettings.getAccentColor());
|
||||
}
|
||||
}
|
||||
|
||||
public static void updateTabLayoutColor(TabLayout tabLayout) {
|
||||
if(tabLayout != null) {
|
||||
tabLayout.setBackgroundColor(getInstance().appSettings.getPrimaryColor());
|
||||
tabLayout.setSelectedTabIndicatorColor(getInstance().appSettings.getAccentColor());
|
||||
}
|
||||
}
|
||||
|
||||
public static void updateTextViewColor(TextView textView) {
|
||||
if(textView != null) {
|
||||
textView.setHighlightColor(getInstance().appSettings.getAccentColor());
|
||||
textView.setLinkTextColor(getInstance().appSettings.getAccentColor());
|
||||
}
|
||||
}
|
||||
|
||||
public static void updateToolbarColor(Toolbar toolbar) {
|
||||
if(toolbar != null) {
|
||||
toolbar.setBackgroundColor(getInstance().appSettings.getPrimaryColor());
|
||||
}
|
||||
}
|
||||
|
||||
public static void updateActionMenuViewColor(ActionMenuView actionMenuView) {
|
||||
if(actionMenuView != null) {
|
||||
actionMenuView.setBackgroundColor(getInstance().appSettings.getPrimaryColor());
|
||||
}
|
||||
}
|
||||
|
||||
public static int getPrimaryColor() {
|
||||
return getInstance().appSettings.getPrimaryColor();
|
||||
}
|
||||
|
||||
public static int getAccentColor() {
|
||||
return getInstance().appSettings.getAccentColor();
|
||||
}
|
||||
|
||||
public static void setPrimaryColorAsBackground(View view) {
|
||||
if(view != null) {
|
||||
view.setBackgroundColor(getPrimaryColor());
|
||||
}
|
||||
}
|
||||
|
||||
public static int getPrimaryDarkColor() {
|
||||
return ColorPalette.getObscuredColor(getPrimaryColor());
|
||||
}
|
||||
|
||||
public static void updateActionBarColor(ActionBar actionBar) {
|
||||
if(actionBar != null) {
|
||||
actionBar.setBackgroundDrawable(new ColorDrawable(getInstance().appSettings.getPrimaryColor()));
|
||||
}
|
||||
}
|
||||
|
||||
public static void updateProgressBarColor(ProgressBar progressBar) {
|
||||
if(progressBar != null && progressBar.getProgressDrawable() != null) {
|
||||
progressBar.getProgressDrawable().setColorFilter(getAccentColor(), PorterDuff.Mode.SRC_IN);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue