Fix toolbars

pull/145/head
Alinson S. Xavier 9 years ago
parent 9a6dafaa79
commit ca9d56e59e

@ -31,6 +31,7 @@ import android.support.v7.widget.Toolbar;
import android.view.*;
import android.widget.*;
import org.isoron.uhabits.*;
import org.isoron.uhabits.tasks.ProgressBar;
import org.isoron.uhabits.utils.*;
@ -60,6 +61,39 @@ public abstract class BaseScreen
this.activity = activity;
}
@Deprecated
public static void setupActionBarColor(AppCompatActivity activity,
int color)
{
Toolbar toolbar = (Toolbar) activity.findViewById(R.id.toolbar);
if (toolbar == null) return;
activity.setSupportActionBar(toolbar);
ActionBar actionBar = activity.getSupportActionBar();
if (actionBar == null) return;
actionBar.setDisplayHomeAsUpEnabled(true);
ColorDrawable drawable = new ColorDrawable(color);
actionBar.setBackgroundDrawable(drawable);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
{
int darkerColor = ColorUtils.mixColors(color, Color.BLACK, 0.75f);
activity.getWindow().setStatusBarColor(darkerColor);
toolbar.setElevation(InterfaceUtils.dpToPixels(activity, 2));
View view = activity.findViewById(R.id.toolbarShadow);
if (view != null) view.setVisibility(View.GONE);
view = activity.findViewById(R.id.headerShadow);
if (view != null) view.setVisibility(View.GONE);
}
}
/**
* Ends the current selection operation.
*/
@ -210,6 +244,7 @@ public abstract class BaseScreen
int color = rootView.getToolbarColor();
setActionBarColor(actionBar, color);
setStatusBarColor(color);
setupToolbarElevation(toolbar);
}
private void setActionBarColor(@NonNull ActionBar actionBar, int color)
@ -220,12 +255,23 @@ public abstract class BaseScreen
private void setStatusBarColor(int baseColor)
{
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
{
int darkerColor =
ColorUtils.mixColors(baseColor, Color.BLACK, 0.75f);
activity.getWindow().setStatusBarColor(darkerColor);
}
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) return;
int darkerColor = ColorUtils.mixColors(baseColor, Color.BLACK, 0.75f);
activity.getWindow().setStatusBarColor(darkerColor);
}
private void setupToolbarElevation(Toolbar toolbar)
{
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) return;
toolbar.setElevation(InterfaceUtils.dpToPixels(activity, 2));
View view = activity.findViewById(R.id.toolbarShadow);
if (view != null) view.setVisibility(View.GONE);
view = activity.findViewById(R.id.headerShadow);
if (view != null) view.setVisibility(View.GONE);
}
private class ActionModeWrapper implements ActionMode.Callback

@ -19,16 +19,15 @@
package org.isoron.uhabits.ui.about;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
import android.content.*;
import android.net.*;
import android.os.*;
import android.view.*;
import android.widget.*;
import org.isoron.uhabits.BuildConfig;
import org.isoron.uhabits.R;
import org.isoron.uhabits.ui.BaseActivity;
import org.isoron.uhabits.utils.InterfaceUtils;
import org.isoron.uhabits.*;
import org.isoron.uhabits.ui.*;
import org.isoron.uhabits.utils.*;
/**
* Activity that allows the user to see information about the app itself.
@ -76,11 +75,11 @@ public class AboutActivity extends BaseActivity implements View.OnClickListener
super.onCreate(savedInstanceState);
setContentView(R.layout.about);
// setupSupportActionBar(true);
int color =
InterfaceUtils.getStyledColor(this, R.attr.aboutScreenColor);
// setupActionBarColor(color);
BaseScreen.setupActionBarColor(this, color);
TextView tvVersion = (TextView) findViewById(R.id.tvVersion);
TextView tvRate = (TextView) findViewById(R.id.tvRate);

@ -19,21 +19,21 @@
package org.isoron.uhabits.ui.habits.show;
import android.content.ContentUris;
import android.net.Uri;
import android.os.Bundle;
import android.support.v7.app.ActionBar;
import android.content.*;
import android.net.*;
import android.os.*;
import android.support.v7.app.*;
import org.isoron.uhabits.HabitsApplication;
import org.isoron.uhabits.R;
import org.isoron.uhabits.models.Habit;
import org.isoron.uhabits.models.HabitList;
import org.isoron.uhabits.ui.BaseActivity;
import org.isoron.uhabits.*;
import org.isoron.uhabits.models.*;
import org.isoron.uhabits.ui.*;
import org.isoron.uhabits.utils.*;
import javax.inject.Inject;
import javax.inject.*;
/**
* Activity that allows the user to see more information about a single habit.
*
* Shows all the metadata for the habit, in addition to several charts.
*/
public class ShowHabitActivity extends BaseActivity
@ -53,7 +53,8 @@ public class ShowHabitActivity extends BaseActivity
habit = habitList.getById(ContentUris.parseId(data));
setContentView(R.layout.show_habit_activity);
// setupSupportActionBar(true);
BaseScreen.setupActionBarColor(this, ColorUtils.getColor(this, habit.getColor()));
setupHabitActionBar();
}
@ -65,7 +66,6 @@ public class ShowHabitActivity extends BaseActivity
if (actionBar == null) return;
actionBar.setTitle(habit.getName());
// setupActionBarColor(ColorUtils.getColor(this, habit.color));
}
public Habit getHabit()

@ -19,11 +19,11 @@
package org.isoron.uhabits.ui.settings;
import android.os.Bundle;
import android.os.*;
import org.isoron.uhabits.R;
import org.isoron.uhabits.ui.BaseActivity;
import org.isoron.uhabits.utils.InterfaceUtils;
import org.isoron.uhabits.*;
import org.isoron.uhabits.ui.*;
import org.isoron.uhabits.utils.*;
/**
* Activity that allows the user to view and modify the app settings.
@ -35,10 +35,9 @@ public class SettingsActivity extends BaseActivity
{
super.onCreate(savedInstanceState);
setContentView(R.layout.settings_activity);
// setupSupportActionBar(true);
int color =
InterfaceUtils.getStyledColor(this, R.attr.aboutScreenColor);
// setupActionBarColor(color);
BaseScreen.setupActionBarColor(this, color);
}
}

@ -75,17 +75,11 @@ public class SettingsFragment extends PreferenceFragmentCompat
private void setResultOnPreferenceClick(String key, final int result)
{
Preference pref = findPreference(key);
pref.setOnPreferenceClickListener(
new Preference.OnPreferenceClickListener()
{
@Override
public boolean onPreferenceClick(Preference preference)
{
getActivity().setResult(result);
getActivity().finish();
return true;
}
});
pref.setOnPreferenceClickListener(preference -> {
getActivity().setResult(result);
getActivity().finish();
return true;
});
}
@Override

Loading…
Cancel
Save