use of android.support.annotation.RequiresApi in project PainlessMusicPlayer by Doctoror.
the class PlaybackNotificationFactoryImpl method createChannel.
@RequiresApi(Build.VERSION_CODES.O)
private static NotificationChannel createChannel(@NonNull final Context context) {
final NotificationChannel channel = new NotificationChannel(CHANNEL_ID, context.getString(R.string.Now_Playing), NotificationManager.IMPORTANCE_DEFAULT);
channel.setLockscreenVisibility(Notification.VISIBILITY_PUBLIC);
channel.setShowBadge(true);
channel.enableVibration(false);
channel.setSound(null, null);
return channel;
}
use of android.support.annotation.RequiresApi in project xDrip-plus by jamorham.
the class BackgroundScanReceiver method onReceive.
@RequiresApi(api = Build.VERSION_CODES.O)
@Override
public void onReceive(Context context, Intent intent) {
final String action = intent.getAction();
android.util.Log.d("BackgroundScanReceiver", "GOT SCAN INTENT!! " + action);
if (action != null && action.equals(ACTION_NAME)) {
String caller = intent.getStringExtra(CALLING_CLASS);
if (caller == null)
caller = this.getClass().getSimpleName();
// TODO by class name?
final BackgroundScanner backgroundScanner = RxBleProvider.getSingleton().getBackgroundScanner();
try {
final List<ScanResult> scanResults = backgroundScanner.onScanResultReceived(intent);
final String matchedMac = scanResults.get(0).getBleDevice().getMacAddress();
final String matchedName = scanResults.get(0).getBleDevice().getName();
final boolean calledBack = processCallbacks(caller, matchedMac, matchedName, SCAN_FOUND_CALLBACK);
UserError.Log.d(caller, "Scan results received: " + matchedMac + " " + scanResults);
if (!calledBack) {
try {
// bit of an ugly fix to system wide persistent nature of background scans and lack of proper support for one hit over various android devices
backgroundScanner.stopBackgroundBleScan(// must match original
PendingIntent.getBroadcast(// must match original
xdrip.getAppContext(), // must match original
142, intent, PendingIntent.FLAG_UPDATE_CURRENT));
} catch (Exception e) {
//
}
}
} catch (NullPointerException | BleScanException exception) {
UserError.Log.e(caller, "Failed to scan devices" + exception);
}
}
// ignore invalid actions
}
use of android.support.annotation.RequiresApi in project yoo_home_Android by culturer.
the class LoginActivity method initEvent.
@RequiresApi(api = Build.VERSION_CODES.HONEYCOMB)
private void initEvent() {
mEtMobile.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
@Override
public void afterTextChanged(Editable s) {
if (!TextUtils.isEmpty(s) && mIvCleanPhone.getVisibility() == View.GONE) {
mIvCleanPhone.setVisibility(View.VISIBLE);
} else if (TextUtils.isEmpty(s)) {
mIvCleanPhone.setVisibility(View.GONE);
}
}
});
mEtPassword.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
@Override
public void afterTextChanged(Editable s) {
if (!TextUtils.isEmpty(s) && mCleanPassword.getVisibility() == View.GONE) {
mCleanPassword.setVisibility(View.VISIBLE);
} else if (TextUtils.isEmpty(s)) {
mCleanPassword.setVisibility(View.GONE);
}
if (s.toString().isEmpty())
return;
if (!s.toString().matches("[A-Za-z0-9]+")) {
String temp = s.toString();
Toast.makeText(LoginActivity.this, "请输入数字或字母", Toast.LENGTH_SHORT).show();
s.delete(temp.length() - 1, temp.length());
mEtPassword.setSelection(s.length());
}
}
});
/**
* 禁止键盘弹起的时候可以滚动
*/
mScrollView.setOnTouchListener((v, event) -> true);
mScrollView.addOnLayoutChangeListener((v, left, top, right, bottom, oldLeft, oldTop, oldRight, oldBottom) -> {
/* old是改变前的左上右下坐标点值,没有old的是改变后的左上右下坐标点值
现在认为只要控件将Activity向上推的高度超过了1/3屏幕高,就认为软键盘弹起*/
if (oldBottom != 0 && bottom != 0 && (oldBottom - bottom > keyHeight)) {
Log.e("wenzhihao", "up------>" + (oldBottom - bottom));
int dist = mContent.getBottom() - bottom;
if (dist > 0) {
ObjectAnimator mAnimatorTranslateY = ObjectAnimator.ofFloat(mContent, "translationY", 0.0f, -dist);
mAnimatorTranslateY.setDuration(300);
mAnimatorTranslateY.setInterpolator(new LinearInterpolator());
mAnimatorTranslateY.start();
RxAnimationTool.zoomIn(mLogo, 0.6f, dist);
}
mService.setVisibility(View.INVISIBLE);
} else if (oldBottom != 0 && bottom != 0 && (bottom - oldBottom > keyHeight)) {
Log.e("wenzhihao", "down------>" + (bottom - oldBottom));
if ((mContent.getBottom() - oldBottom) > 0) {
ObjectAnimator mAnimatorTranslateY = ObjectAnimator.ofFloat(mContent, "translationY", mContent.getTranslationY(), 0);
mAnimatorTranslateY.setDuration(300);
mAnimatorTranslateY.setInterpolator(new LinearInterpolator());
mAnimatorTranslateY.start();
// 键盘收回后,logo恢复原来大小,位置同样回到初始位置
RxAnimationTool.zoomOut(mLogo, 0.6f);
}
mService.setVisibility(View.VISIBLE);
}
});
mBtnLogin.setOnClickListener(v -> {
RxKeyboardTool.hideSoftInput(LoginActivity.this);
tel = mEtMobile.getText().toString();
password = MD5Util.encrypt(mEtPassword.getText().toString().trim());
presenter.login(tel, password);
});
}
use of android.support.annotation.RequiresApi in project OpenCamera by ageback.
the class HDRProcessor method adjustHistogram.
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
private void adjustHistogram(Allocation allocation_in, Allocation allocation_out, int width, int height, float hdr_alpha, int n_tiles, long time_s) {
if (MyDebug.LOG)
Log.d(TAG, "adjustHistogram");
final boolean adjust_histogram = false;
if (adjust_histogram) {
// create histogram
int[] histogram = new int[256];
if (MyDebug.LOG)
Log.d(TAG, "time before creating histogram: " + (System.currentTimeMillis() - time_s));
Allocation histogramAllocation = computeHistogramAllocation(allocation_in, false, false, time_s);
if (MyDebug.LOG)
Log.d(TAG, "time after creating histogram: " + (System.currentTimeMillis() - time_s));
histogramAllocation.copyTo(histogram);
/*if( MyDebug.LOG ) {
// compare/adjust
allocations[0].copyTo(bm);
int [] debug_histogram = new int[256];
for(int i=0;i<256;i++) {
debug_histogram[i] = 0;
}
int [] debug_buffer = new int[width];
for(int y=0;y<height;y++) {
bm.getPixels(debug_buffer, 0, width, 0, y, width, 1);
for(int x=0;x<width;x++) {
int color = debug_buffer[x];
float r = (float)((color & 0xFF0000) >> 16);
float g = (float)((color & 0xFF00) >> 8);
float b = (float)(color & 0xFF);
//float value = 0.299f*r + 0.587f*g + 0.114f*b; // matches ScriptIntrinsicHistogram default behaviour
float value = Math.max(r, g);
value = Math.max(value, b);
int i_value = (int)value;
i_value = Math.min(255, i_value); // just in case
debug_histogram[i_value]++;
}
}
for(int x=0;x<256;x++) {
Log.d(TAG, "histogram[" + x + "] = " + histogram[x] + " debug_histogram: " + debug_histogram[x]);
//histogram[x] = debug_histogram[x];
}
}*/
int[] c_histogram = new int[256];
c_histogram[0] = histogram[0];
for (int x = 1; x < 256; x++) {
c_histogram[x] = c_histogram[x - 1] + histogram[x];
}
/*if( MyDebug.LOG ) {
for(int x=0;x<256;x++) {
Log.d(TAG, "histogram[" + x + "] = " + histogram[x] + " cumulative: " + c_histogram[x]);
}
}*/
histogramAllocation.copyFrom(c_histogram);
ScriptC_histogram_adjust histogramAdjustScript = new ScriptC_histogram_adjust(rs);
histogramAdjustScript.set_c_histogram(histogramAllocation);
histogramAdjustScript.set_hdr_alpha(hdr_alpha);
if (MyDebug.LOG)
Log.d(TAG, "call histogramAdjustScript");
histogramAdjustScript.forEach_histogram_adjust(allocation_in, allocation_out);
if (MyDebug.LOG)
Log.d(TAG, "time after histogramAdjustScript: " + (System.currentTimeMillis() - time_s));
}
// final boolean adjust_histogram_local = false;
final boolean adjust_histogram_local = true;
if (adjust_histogram_local) {
// Contrast Limited Adaptive Histogram Equalisation
// Note we don't fully equalise the histogram, rather the resultant image is the mid-point of the non-equalised and fully-equalised images
// See https://en.wikipedia.org/wiki/Adaptive_histogram_equalization#Contrast_Limited_AHE
// Also see "Adaptive Histogram Equalization and its Variations" ( http://www.cs.unc.edu/Research/MIDAG/pubs/papers/Adaptive%20Histogram%20Equalization%20and%20Its%20Variations.pdf ),
// Pizer, Amburn, Austin, Cromartie, Geselowitz, Greer, ter Haar Romeny, Zimmerman, Zuiderveld (1987).
// create histograms
Allocation histogramAllocation = Allocation.createSized(rs, Element.I32(rs), 256);
if (MyDebug.LOG)
Log.d(TAG, "create histogramScript");
ScriptC_histogram_compute histogramScript = new ScriptC_histogram_compute(rs);
if (MyDebug.LOG)
Log.d(TAG, "bind histogram allocation");
histogramScript.bind_histogram(histogramAllocation);
// final int n_tiles_c = 8;
// final int n_tiles_c = 4;
// final int n_tiles_c = 1;
int[] c_histogram = new int[n_tiles * n_tiles * 256];
for (int i = 0; i < n_tiles; i++) {
double a0 = ((double) i) / (double) n_tiles;
double a1 = ((double) i + 1.0) / (double) n_tiles;
int start_x = (int) (a0 * width);
int stop_x = (int) (a1 * width);
if (stop_x == start_x)
continue;
for (int j = 0; j < n_tiles; j++) {
double b0 = ((double) j) / (double) n_tiles;
double b1 = ((double) j + 1.0) / (double) n_tiles;
int start_y = (int) (b0 * height);
int stop_y = (int) (b1 * height);
if (stop_y == start_y)
continue;
/*if( MyDebug.LOG )
Log.d(TAG, i + " , " + j + " : " + start_x + " , " + start_y + " to " + stop_x + " , " + stop_y);*/
Script.LaunchOptions launch_options = new Script.LaunchOptions();
launch_options.setX(start_x, stop_x);
launch_options.setY(start_y, stop_y);
/*if( MyDebug.LOG )
Log.d(TAG, "call histogramScript");*/
histogramScript.invoke_init_histogram();
histogramScript.forEach_histogram_compute(allocation_in, launch_options);
int[] histogram = new int[256];
histogramAllocation.copyTo(histogram);
/*if( MyDebug.LOG ) {
// compare/adjust
allocations[0].copyTo(bm);
int [] debug_histogram = new int[256];
for(int k=0;k<256;k++) {
debug_histogram[k] = 0;
}
int [] debug_buffer = new int[width];
for(int y=start_y;y<stop_y;y++) {
bm.getPixels(debug_buffer, 0, width, 0, y, width, 1);
for(int x=start_x;x<stop_x;x++) {
int color = debug_buffer[x];
float r = (float)((color & 0xFF0000) >> 16);
float g = (float)((color & 0xFF00) >> 8);
float b = (float)(color & 0xFF);
//float value = 0.299f*r + 0.587f*g + 0.114f*b; // matches ScriptIntrinsicHistogram default behaviour
float value = Math.max(r, g);
value = Math.max(value, b);
int i_value = (int)value;
i_value = Math.min(255, i_value); // just in case
debug_histogram[i_value]++;
}
}
for(int x=0;x<256;x++) {
Log.d(TAG, "histogram[" + x + "] = " + histogram[x] + " debug_histogram: " + debug_histogram[x]);
//histogram[x] = debug_histogram[x];
}
}*/
// clip histogram, for Contrast Limited AHE algorithm
int n_pixels = (stop_x - start_x) * (stop_y - start_y);
int clip_limit = (5 * n_pixels) / 256;
/*if( MyDebug.LOG )
Log.d(TAG, "clip_limit: " + clip_limit);*/
{
// find real clip limit
int bottom = 0, top = clip_limit;
while (top - bottom > 1) {
int middle = (top + bottom) / 2;
int sum = 0;
for (int x = 0; x < 256; x++) {
if (histogram[x] > middle) {
sum += (histogram[x] - clip_limit);
}
}
if (sum > (clip_limit - middle) * 256)
top = middle;
else
bottom = middle;
}
clip_limit = (top + bottom) / 2;
/*if( MyDebug.LOG )
Log.d(TAG, "updated clip_limit: " + clip_limit);*/
}
int n_clipped = 0;
for (int x = 0; x < 256; x++) {
if (histogram[x] > clip_limit) {
n_clipped += (histogram[x] - clip_limit);
histogram[x] = clip_limit;
}
}
int n_clipped_per_bucket = n_clipped / 256;
/*if( MyDebug.LOG ) {
Log.d(TAG, "n_clipped: " + n_clipped);
Log.d(TAG, "n_clipped_per_bucket: " + n_clipped_per_bucket);
}*/
for (int x = 0; x < 256; x++) {
histogram[x] += n_clipped_per_bucket;
}
int histogram_offset = 256 * (i * n_tiles + j);
c_histogram[histogram_offset] = histogram[0];
for (int x = 1; x < 256; x++) {
c_histogram[histogram_offset + x] = c_histogram[histogram_offset + x - 1] + histogram[x];
}
/*if( MyDebug.LOG ) {
for(int x=0;x<256;x++) {
Log.d(TAG, "histogram[" + x + "] = " + histogram[x] + " cumulative: " + c_histogram[histogram_offset+x]);
}
}*/
}
}
if (MyDebug.LOG)
Log.d(TAG, "time after creating histograms: " + (System.currentTimeMillis() - time_s));
Allocation c_histogramAllocation = Allocation.createSized(rs, Element.I32(rs), n_tiles * n_tiles * 256);
c_histogramAllocation.copyFrom(c_histogram);
ScriptC_histogram_adjust histogramAdjustScript = new ScriptC_histogram_adjust(rs);
histogramAdjustScript.set_c_histogram(c_histogramAllocation);
histogramAdjustScript.set_hdr_alpha(hdr_alpha);
histogramAdjustScript.set_n_tiles(n_tiles);
histogramAdjustScript.set_width(width);
histogramAdjustScript.set_height(height);
if (MyDebug.LOG)
Log.d(TAG, "call histogramAdjustScript");
histogramAdjustScript.forEach_histogram_adjust(allocation_in, allocation_out);
if (MyDebug.LOG)
Log.d(TAG, "time after histogramAdjustScript: " + (System.currentTimeMillis() - time_s));
}
}
use of android.support.annotation.RequiresApi in project OpenCamera by ageback.
the class HDRProcessor method processAvgMulti.
/**
* Combines multiple images by averaging them.
* @param bitmaps Input bitmaps. The resultant bitmap will be stored as the first bitmap on exit,
* the other input bitmaps will be recycled.
*/
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
public void processAvgMulti(List<Bitmap> bitmaps, float hdr_alpha, int n_tiles) throws HDRProcessorException {
if (MyDebug.LOG) {
Log.d(TAG, "processAvgMulti");
Log.d(TAG, "hdr_alpha: " + hdr_alpha);
}
int n_bitmaps = bitmaps.size();
if (n_bitmaps != 8) {
if (MyDebug.LOG)
Log.e(TAG, "n_bitmaps should be 8, not " + n_bitmaps);
throw new HDRProcessorException(HDRProcessorException.INVALID_N_IMAGES);
}
for (int i = 1; i < n_bitmaps; i++) {
if (bitmaps.get(i).getWidth() != bitmaps.get(0).getWidth() || bitmaps.get(i).getHeight() != bitmaps.get(0).getHeight()) {
if (MyDebug.LOG) {
Log.e(TAG, "bitmaps not of same resolution");
for (int j = 0; j < n_bitmaps; j++) {
Log.e(TAG, "bitmaps " + j + " : " + bitmaps.get(j).getWidth() + " x " + bitmaps.get(j).getHeight());
}
}
throw new HDRProcessorException(HDRProcessorException.UNEQUAL_SIZES);
}
}
long time_s = System.currentTimeMillis();
int width = bitmaps.get(0).getWidth();
int height = bitmaps.get(0).getHeight();
initRenderscript();
if (MyDebug.LOG)
Log.d(TAG, "### time after creating renderscript: " + (System.currentTimeMillis() - time_s));
// create allocations
Allocation allocation0 = Allocation.createFromBitmap(rs, bitmaps.get(0));
Allocation allocation1 = Allocation.createFromBitmap(rs, bitmaps.get(1));
Allocation allocation2 = Allocation.createFromBitmap(rs, bitmaps.get(2));
Allocation allocation3 = Allocation.createFromBitmap(rs, bitmaps.get(3));
Allocation allocation4 = Allocation.createFromBitmap(rs, bitmaps.get(4));
Allocation allocation5 = Allocation.createFromBitmap(rs, bitmaps.get(5));
Allocation allocation6 = Allocation.createFromBitmap(rs, bitmaps.get(6));
Allocation allocation7 = Allocation.createFromBitmap(rs, bitmaps.get(7));
if (MyDebug.LOG)
Log.d(TAG, "### time after creating allocations from bitmaps: " + (System.currentTimeMillis() - time_s));
// perform auto-alignment
/*for(int i=1;i<bitmaps.size();i++) {
{
List<Bitmap> bitmaps2 = new ArrayList<>();
bitmaps2.add(bitmaps.get(0));
bitmaps2.add(bitmap.get(i));
Allocation [] allocations = new Allocation[2];
allocations[0] = allocation_avg;
allocations[1] = allocation_new;
BrightnessDetails brightnessDetails = autoAlignment(offsets_x, offsets_y, allocations, width, height, bitmaps, 0, true, null, true, time_s);
int median_brightness = brightnessDetails.median_brightness;
if( MyDebug.LOG ) {
Log.d(TAG, "### time after autoAlignment: " + (System.currentTimeMillis() - time_s));
Log.d(TAG, "median_brightness: " + median_brightness);
}
}*/
// write new avg image
// create RenderScript
ScriptC_process_avg processAvgScript = new ScriptC_process_avg(rs);
// set allocations
processAvgScript.set_bitmap1(allocation1);
processAvgScript.set_bitmap2(allocation2);
processAvgScript.set_bitmap3(allocation3);
processAvgScript.set_bitmap4(allocation4);
processAvgScript.set_bitmap5(allocation5);
processAvgScript.set_bitmap6(allocation6);
processAvgScript.set_bitmap7(allocation7);
if (MyDebug.LOG)
Log.d(TAG, "call processAvgScript");
if (MyDebug.LOG)
Log.d(TAG, "### time before processAvgScript: " + (System.currentTimeMillis() - time_s));
processAvgScript.forEach_avg_multi(allocation0, allocation0);
if (MyDebug.LOG)
Log.d(TAG, "### time after processAvgScript: " + (System.currentTimeMillis() - time_s));
{
if (MyDebug.LOG)
Log.d(TAG, "release bitmaps");
for (int i = 1; i < bitmaps.size(); i++) {
bitmaps.get(i).recycle();
}
}
if (hdr_alpha != 0.0f) {
adjustHistogram(allocation0, allocation0, width, height, hdr_alpha, n_tiles, time_s);
if (MyDebug.LOG)
Log.d(TAG, "### time after adjustHistogram: " + (System.currentTimeMillis() - time_s));
}
allocation0.copyTo(bitmaps.get(0));
if (MyDebug.LOG)
Log.d(TAG, "### time for processAvgMulti: " + (System.currentTimeMillis() - time_s));
}
Aggregations