use of com.simplecity.amp_library.ui.fragments.SettingsFragment in project Shuttle by timusus.
the class DialogUtils method showColorPickerDialog.
public static void showColorPickerDialog(SettingsFragment fragment, int selectedColor, int[] mainColors, int[][] subColors, ColorSelectionListener listener) {
View customView = LayoutInflater.from(fragment.getActivity()).inflate(R.layout.dialog_color_picker, null);
RecyclerView recyclerView = (RecyclerView) customView.findViewById(R.id.recyclerView);
GridLayoutManager gridLayoutManager = new GridLayoutManager(fragment.getActivity(), 5);
recyclerView.setLayoutManager(gridLayoutManager);
ThemeUtils.themeRecyclerView(recyclerView);
recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
ThemeUtils.themeRecyclerView(recyclerView);
super.onScrollStateChanged(recyclerView, newState);
}
});
ColorAdapter colorAdapter = new ColorAdapter();
List<AdaptableItem> colorViews = new ArrayList<>();
for (int i = 0, length = mainColors.length; i < length; i++) {
ColorView colorView = new ColorView(mainColors[i]);
boolean selected = false;
//If the sub colors array contains our selected color, then we set this colorView to selected.
for (int j = 0, jLength = subColors[i].length; j < jLength; j++) {
if (subColors[i][j] == selectedColor) {
selected = true;
}
}
colorView.selected = selected;
colorViews.add(colorView);
}
colorAdapter.setItems(colorViews);
recyclerView.setAdapter(colorAdapter);
colorAdapter.setColorListener((position, color, isSubColor) -> {
if (isSubColor) {
colorAdapter.setSelectedPosition(position);
} else {
List<AdaptableItem> subColorViews = new ArrayList<>();
for (int i = 0, length = subColors[position].length; i < length; i++) {
ColorView colorView = new ColorView(subColors[position][i]);
colorView.selected = colorView.color == selectedColor;
subColorViews.add(colorView);
colorAdapter.isSubColor = true;
}
colorAdapter.setItems(subColorViews);
}
});
int neutralTextResId;
TextView textView = (TextView) customView.findViewById(R.id.text1);
if (ShuttleUtils.isUpgraded()) {
textView.setVisibility(View.GONE);
neutralTextResId = R.string.dialog_custom;
} else {
textView.setVisibility(View.VISIBLE);
if (ShuttleUtils.isAmazonBuild()) {
neutralTextResId = R.string.get_pro_button_amazon;
} else {
neutralTextResId = R.string.btn_upgrade;
}
}
getBuilder(fragment.getActivity()).title(fragment.getActivity().getString(R.string.color_pick)).negativeText(R.string.cancel).onNegative((dialog, which) -> dialog.dismiss()).positiveText(R.string.button_done).onPositive((dialog, which) -> {
int color = selectedColor;
for (AdaptableItem item : colorAdapter.items) {
if (((ColorView) item).selected) {
color = ((ColorView) item).color;
break;
}
}
listener.colorSelected(color);
dialog.dismiss();
}).neutralText(neutralTextResId).autoDismiss(false).onNeutral((dialog, which) -> {
if (ShuttleUtils.isUpgraded()) {
showCustomColorPickerDialog(fragment.getActivity(), selectedColor, listener);
dialog.dismiss();
} else {
showUpgradeDialog(fragment.getActivity(), (upgradeDialog, which1) -> {
if (ShuttleUtils.isAmazonBuild()) {
ShuttleUtils.openShuttleLink(fragment.getActivity(), "com.simplecity.amp_pro");
} else {
AnalyticsManager.logUpgrade(AnalyticsManager.UpgradeType.COLORS);
((SettingsActivity) fragment.getActivity()).purchasePremiumUpgrade();
}
});
}
}).customView(customView, false).show();
}
use of com.simplecity.amp_library.ui.fragments.SettingsFragment in project Shuttle by timusus.
the class SettingsActivity method onCreate.
@SuppressLint("InlinedApi")
@Override
protected void onCreate(Bundle savedInstanceState) {
if (!ShuttleUtils.isUpgraded() && !ShuttleUtils.isAmazonBuild()) {
IabManager.getInstance();
}
ThemeUtils.setTheme(this);
mPrefs = PreferenceManager.getDefaultSharedPreferences(this);
if (!ShuttleUtils.hasLollipop() && ShuttleUtils.hasKitKat()) {
getWindow().setFlags(FLAG_TRANSLUCENT_STATUS, FLAG_TRANSLUCENT_STATUS);
mTintManager = new SystemBarTintManager(this);
}
if (!ShuttleUtils.hasKitKat()) {
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
}
if (SettingsManager.getInstance().canTintNavBar()) {
getWindow().setNavigationBarColor(ColorUtils.getPrimaryColorDark(this));
}
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_settings);
setSupportActionBar((Toolbar) findViewById(R.id.toolbar));
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
ThemeUtils.themeActionBar(this);
ThemeUtils.themeStatusBar(this, mTintManager);
if (savedInstanceState == null) {
if (!getIntent().getBooleanExtra(EXTRA_SUPPORT, false)) {
getSupportActionBar().setTitle(getString(R.string.settings));
getSupportFragmentManager().beginTransaction().replace(R.id.main_container, new SettingsFragment()).commit();
} else {
getSupportActionBar().setTitle(getString(R.string.pref_title_support));
getSupportFragmentManager().beginTransaction().replace(R.id.main_container, SettingsFragment.newInstance(R.xml.settings_support)).commit();
}
}
}
Aggregations