use of com.foobnix.pdf.search.activity.msg.MessegeBrightness in project LibreraReader by foobnix.
the class BrightnessHelper method showBlueLigthDialogAndBrightness.
public static void showBlueLigthDialogAndBrightness(final Activity a, View inflate, final Runnable onRefresh) {
final CheckBox isEnableBlueFilter = (CheckBox) inflate.findViewById(R.id.isEnableBlueFilter);
isEnableBlueFilter.setVisibility(Dips.isEInk(a) ? View.GONE : View.VISIBLE);
isEnableBlueFilter.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
AppState.get().isEnableBlueFilter = isChecked;
if (onRefresh != null) {
onRefresh.run();
}
}
});
final TextView onBlueFilter = (TextView) inflate.findViewById(R.id.onBlueFilter);
onBlueFilter.setVisibility(Dips.isEInk(a) ? View.GONE : View.VISIBLE);
TxtUtils.underlineTextView(onBlueFilter);
onBlueFilter.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
final AlertDialog.Builder builder = new AlertDialog.Builder(v.getContext());
builder.setTitle(R.string.bluelight_filter);
final View inflate = LayoutInflater.from(a).inflate(R.layout.dialog_bluelight, null, false);
final CustomColorView blueLightColor = (CustomColorView) inflate.findViewById(R.id.blueLightColor);
TxtUtils.bold(blueLightColor.getText1());
blueLightColor.withDefaultColors(AppState.BLUE_FILTER_DEFAULT_COLOR, Color.parseColor("#FFDD00"), Color.RED, Color.GREEN);
blueLightColor.init(AppState.get().blueLightColor);
blueLightColor.setOnColorChanged(new StringResponse() {
@Override
public boolean onResultRecive(String string) {
AppState.get().isEnableBlueFilter = true;
AppState.get().blueLightColor = Color.parseColor(string);
if (onRefresh != null) {
onRefresh.run();
}
// Keyboards.hideNavigation(a);
return false;
}
});
final CustomSeek blueLightAlpha = (CustomSeek) inflate.findViewById(R.id.blueLightAlpha);
blueLightAlpha.init(0, 99, AppState.get().blueLightAlpha);
blueLightAlpha.setOnSeekChanged(new IntegerResponse() {
@Override
public boolean onResultRecive(int result) {
AppState.get().isEnableBlueFilter = true;
AppState.get().blueLightAlpha = result;
blueLightAlpha.setValueText("" + AppState.get().blueLightAlpha + "%");
if (onRefresh != null) {
onRefresh.run();
}
return false;
}
});
blueLightAlpha.setValueText("" + AppState.get().blueLightAlpha + "%");
builder.setView(inflate);
builder.setNegativeButton(R.string.close, new DialogInterface.OnClickListener() {
@Override
public void onClick(final DialogInterface dialog, final int id) {
isEnableBlueFilter.setChecked(AppState.get().isEnableBlueFilter);
if (dialog != null) {
dialog.dismiss();
}
}
});
AlertDialog dialog = builder.create();
dialog.setOnDismissListener(new OnDismissListener() {
@Override
public void onDismiss(DialogInterface dialog) {
Keyboards.hideNavigation(a);
}
});
dialog.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
dialog.show();
}
});
// brightness
final CheckBox autoSettings = (CheckBox) inflate.findViewById(R.id.autoSettings);
final int systemBrigtnessInt = getSystemBrigtnessInt(a);
final CustomSeek customBrightness = (CustomSeek) inflate.findViewById(R.id.customBrightness);
int value = 0;
if (AppState.get().appBrightness == AppState.AUTO_BRIGTNESS) {
value = systemBrigtnessInt;
} else {
value = AppState.get().isEnableBlueFilter ? AppState.get().blueLightAlpha * -1 : AppState.get().appBrightness;
}
customBrightness.init(-100, 100, value);
customBrightness.setOnSeekChanged(new IntegerResponse() {
@Override
public boolean onResultRecive(int result) {
customBrightness.setValueText("" + result);
EventBus.getDefault().post(new MessegeBrightness(result));
isEnableBlueFilter.setChecked(AppState.get().isEnableBlueFilter);
return false;
}
});
autoSettings.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(final CompoundButton buttonView, final boolean isChecked) {
if (!buttonView.isPressed()) {
return;
}
if (isChecked) {
// auto
customBrightness.setEnabled(false);
customBrightness.reset(systemBrigtnessInt);
EventBus.getDefault().post(new MessegeBrightness(AppState.AUTO_BRIGTNESS));
} else {
customBrightness.setEnabled(true);
EventBus.getDefault().post(new MessegeBrightness(systemBrigtnessInt));
}
isEnableBlueFilter.setChecked(AppState.get().isEnableBlueFilter);
}
});
isEnableBlueFilter.setChecked(AppState.get().isEnableBlueFilter);
autoSettings.setChecked(AppState.get().appBrightness == AppState.AUTO_BRIGTNESS);
customBrightness.setEnabled(AppState.get().appBrightness != AppState.AUTO_BRIGTNESS);
}
use of com.foobnix.pdf.search.activity.msg.MessegeBrightness in project LibreraReader by foobnix.
the class BrightnessHelper method onActionMove.
public boolean onActionMove(final MotionEvent event) {
if (!AppState.get().isBrighrnessEnable) {
return false;
}
float yDiff = y - event.getY();
float dy = Math.abs(yDiff);
float dx = Math.abs(x - event.getX());
if ((isMovementStart || dy > Dips.DP_25) && event.getPointerCount() == 1 && x < BRIGHTNESS_WIDTH && dy > dx) {
isMovementStart = true;
lastPercent = (int) (yDiff * 100 / MAX);
float plus = getMinMaxValue(lastPercent + currentPercent);
EventBus.getDefault().post(new MessegeBrightness((int) plus));
}
return isMovementStart;
}
use of com.foobnix.pdf.search.activity.msg.MessegeBrightness in project LibreraReader by foobnix.
the class BrightnessHelper method onMessegeBrightness.
public static void onMessegeBrightness(MessegeBrightness msg, final TextView textView, final View overlay) {
int value = msg.getValue();
textView.setVisibility(View.VISIBLE);
textView.getHandler().removeCallbacksAndMessages(null);
textView.getHandler().postDelayed(new Runnable() {
@Override
public void run() {
textView.setVisibility(View.GONE);
}
}, 1000);
textView.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
onMessegeBrightness(new MessegeBrightness(AppState.AUTO_BRIGTNESS), textView, overlay);
Activity inflate = (Activity) textView.getContext();
CheckBox isEnableBlueFilter = inflate.findViewById(R.id.autoSettings);
if (isEnableBlueFilter != null) {
isEnableBlueFilter.setChecked(true);
}
View customBrightness = inflate.findViewById(R.id.customBrightness);
if (customBrightness != null) {
customBrightness.setEnabled(false);
}
}
});
if (value == AppState.AUTO_BRIGTNESS) {
AppState.get().isEnableBlueFilter = false;
// AppState.get().blueLightAlpha = 0;
AppState.get().appBrightness = AppState.AUTO_BRIGTNESS;
textView.setText(textView.getContext().getString(R.string.automatic));
} else if (value < 0) {
AppState.get().isEnableBlueFilter = true;
AppState.get().blueLightAlpha = Math.abs(value);
AppState.get().appBrightness = 0;
textView.setText(textView.getContext().getString(R.string.brightness) + " " + value + "%");
} else {
AppState.get().isEnableBlueFilter = false;
// AppState.get().blueLightAlpha = 0;
AppState.get().appBrightness = value;
textView.setText(textView.getContext().getString(R.string.brightness) + " " + value + "%");
}
BrightnessHelper.applyBrigtness((Activity) textView.getContext());
updateOverlay(overlay);
}
Aggregations