[Q] How to determine of time object is between two other time objects? - Android Q&A, Help & Troubleshooting

How can I determine if the current time is between two other time objects?
For example: current: 15:23, startTime: 22:00, endTime: 06:00. So the current time is not between this two other times, but this "23:47" is.
*I don't care about the date, only the time
I tried to do it like this:
Code:
Time startTime = getStartTime();
Time endTime = getEndTime();
Calendar c = Calendar.getInstance();
Time now = new Time(c.getTimeInMillis());
if (now.before(endTime) && now.after(startTime)) {
return true;
}
return false;
but it dosen't work well. their aren't any errors but it just dosen't work.
To be more precise the problem is that 15:35.after(22:00) return true... and I don't know why. I think that the problem is something with the dates but I don't know what

I found the solution:
Code:
Time startTime = getStartTime();
Time endTime = getEndTime();
Calendar startCalendarTime = Calendar.getInstance();
startCalendarTime.set(0, 0, 0, startTime.getHours(), startTime.getMinutes());
Calendar endCalendarTime = Calendar.getInstance();
endCalendarTime.set(0, 0, 0, endTime.getHours(), endTime.getMinutes());
Calendar nowCalendarTime = Calendar.getInstance();
int hours = nowCalendarTime.getTime().getHours();
int minutes = nowCalendarTime.getTime().getMinutes();
nowCalendarTime.set(0, 0, 0, hours, minutes);
if (nowCalendarTime.after(startCalendarTime) && nowCalendarTime.before(endCalendarTime)) {
return true;
}
return false;

Where to put this code ??

Related

customizing XDA's today screen

Is it possible to customize the XDA's today screen (i.e. by using XML) as you can do with the Orange's SPV ?
Download Microsoft's Theme Generator...
http://www.microsoft.com/mobile/pocketpc/downloads/powertoys.asp
There are some other goodies on that page aswell.
Good luck!
Powertoy is not what I am looking for: the idea is not only changing the background image but to organize all the datas on the screen as and where you wish (date, time, numbers of emails received, fonts, etc.) as you can do on smarphone 2002 changing the today screen's script in XML.
For examples what you can do with Smartphone 2002:
http://www.smartphony.org/stories.php?topic=32
It's a bit more complicated with PPC 2002. Unlike smartphone, it is an API to change the contents of 'Today'. Each line is loaded as a type of 'snap in' dll.
Do you I could find some examples of that kind of work ?
It is really a pain in the ass
But this works fine... 8)
#include "stdafx.h"
#include <todaycmn.h>
#define IDI_ICON1 101
HINSTANCE Instance;
BOOL Refresh;
HICON hIcon;
LRESULT CALLBACK WindowProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
{
PAINTSTRUCT ps;
RECT rect;
switch (msg) {
case WM_TODAYCUSTOM_CLEARCACHE:
break;
case WM_TODAYCUSTOM_QUERYREFRESHCACHE:
if (Refresh) {
Refresh = FALSE;
((TODAYLISTITEM *)(wparam))->cyp = 20;
return TRUE;
} else {
return FALSE;
}
case WM_ERASEBKGND:
{
TODAYDRAWWATERMARKINFO dwi;
dwi.hwnd = hwnd;
dwi.hdc = (HDC)wparam;
GetClientRect(hwnd, &(dwi.rc));
SendMessage(GetParent(hwnd), TODAYM_DRAWWATERMARK, 0, (LPARAM)&dwi);
return 1;
}
case WM_PAINT:
BeginPaint(hwnd, &ps);
GetWindowRect(hwnd, &rect);
SetBkMode(ps.hdc, TRANSPARENT);
hIcon = (HICON)LoadImage(Instance,MAKEINTRESOURCE(IDI_ICON1),IMAGE_ICON,16,16,LR_DEFAULTCOLOR );
DrawIcon(ps.hdc, 2, 0, hIcon);
DestroyIcon(hIcon);
LOGFONT lf;
HFONT hSysFont;
HFONT hFont, hFontOld;
hSysFont = (HFONT) GetStockObject(SYSTEM_FONT);
GetObject(hSysFont, sizeof(LOGFONT), &lf);
lf.lfWeight = FW_BOLD;
lf.lfHeight = (long) -((8.0 * (double)GetDeviceCaps(ps.hdc, LOGPIXELSY) / 72.0)+.5);
hFont = CreateFontIndirect(&lf);
hFontOld = (HFONT) SelectObject(ps.hdc, hFont);
SetTextColor(ps.hdc, SendMessage(GetParent(hwnd), TODAYM_GETCOLOR, (WPARAM)TODAYCOLOR_TEXT, NULL));
GetClientRect(hwnd, &rect);
DrawText(ps.hdc, TEXT("Text you want to enter"), -1, &rect, DT_LEFT | DT_TOP | DT_NOCLIP);
SelectObject(ps.hdc, hFontOld);
DeleteObject(hFont);
EndPaint(hwnd, &ps);
break;
case WM_LBUTTONUP:
// Whatever you want to occur when the button is pressed //
CreateProcess(TEXT("iexplore.exe"), NULL, NULL, NULL, FALSE, 0, NULL, NULL, NULL, NULL);
break;
default:
return DefWindowProc(hwnd, msg, wparam, lparam);
}
return 0;
}
HWND APIENTRY InitializeCustomItem(TODAYLISTITEM *tli, HWND parent)
{
if (!tli->fEnabled) {
return NULL;
}
Instance = tli->hinstDLL;
WNDCLASS wc;
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc = (WNDPROC)WindowProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = Instance;
wc.hIcon = 0;
wc.hCursor = 0;
wc.hbrBackground = (HBRUSH)COLOR_BACKGROUND + 1;
wc.lpszMenuName = NULL;
wc.lpszClassName = TEXT("RegisterClassName");
UnregisterClass(TEXT("RegisterClassName"), Instance);
RegisterClass(&wc);
Refresh = TRUE;
return CreateWindow(TEXT("RegisterClassName"), TEXT("RegisterClassName"), WS_VISIBLE | WS_CHILD, CW_DEFAULT, CW_DEFAULT, 0, 0, parent, NULL, Instance, NULL);
}
Thank's !
Is there somewhere a technical documentation about that ?

Kernel Sysfs Param Storage function - Get calling parameter

So, I hate to ask because I'm sure this is really simple...
I have this function that is storing a sysfs value. To save space, I have 4 different parameters sharing the function as it's basically the same function for each. I'd like to check which parameter is calling the function so that I can perform some checks depending on the parameter (ie, that each is in a logical order compared to it's neighboring values). How would I get the name of parameter that called it?
https://gist.github.com/yoinx/6a3ff00945f3ec1db230
embedded to avoid the link:
Code:
/* Frequency limit storage */
static int set_freq_limit(const char *val, const struct kernel_param *kp)
{
int ret = 0;
int i, cnt;
int valid = 0;
struct cpufreq_policy *policy;
static struct cpufreq_frequency_table *tbl = NULL;
ret = kstrtouint(val, 10, &i);
if (ret)
return -EINVAL;
policy = cpufreq_cpu_get(0);
tbl = cpufreq_frequency_get_table(0);
for (cnt = 0; (tbl[cnt].frequency != CPUFREQ_TABLE_END); cnt++) {
if (cnt > 0)
if (tbl[cnt].frequency == i)
valid = 1;
}
if (!valid)
return -EINVAL;
ret = param_set_int(val, kp);
return ret;
}
static struct kernel_param_ops freq_limit_ops = {
.set = set_freq_limit,
.get = param_get_int,
};
module_param_cb(freq_hell, &freq_limit_ops, &FREQ_HELL, 0644);
module_param_cb(freq_very_hot, &freq_limit_ops, &FREQ_VERY_HOT, 0644);
module_param_cb(freq_hot, &freq_limit_ops, &FREQ_HOT, 0644);
module_param_cb(freq_warm, &freq_limit_ops, &FREQ_WARM, 0644);
I could go even more sloppy and just duplicate this function repeatedly... But I'd rather not.
I thought kp would hold the kernel parameter... but it's a structure, not a variable... So I'm not positive what value in the structure would hold the name.
Thanks for the help.
Edit:
Would it be kp->name?
Ok, so not sure why it wouldn't work for me the other day... Which is what lead me to this post.
It was indeed kp->name, like I expected it to be. When I was trying to test it in a printk, it was causing a kernel panic though. Whatever, it worked now.
It prints out as module.param, just in case this helps anyone in the future.
*Edit*
Here's how I ended up doing this. Again, in case it helps anyone in the future.
Code:
/* Frequency limit storage */
static int set_freq_limit(const char *val, const struct kernel_param *kp)
{
int ret = 0;
int i, cnt;
int valid = 0;
struct cpufreq_policy *policy;
static struct cpufreq_frequency_table *tbl = NULL;
ret = kstrtouint(val, 10, &i);
if (ret)
return -EINVAL;
policy = cpufreq_cpu_get(0);
tbl = cpufreq_frequency_get_table(0);
for (cnt = 0; (tbl[cnt].frequency != CPUFREQ_TABLE_END); cnt++) {
if (cnt > 0)
if (tbl[cnt].frequency == i)
valid = 1;
}
if (!valid)
return -EINVAL;
/* Perform some sanity checks on the values that we're storing
* to make sure that they're scaling linearly */
if (strcmp( kp->name, "msm_thermal.freq_warm") == 0 && i <= FREQ_HOT)
return -EINVAL;
if ( strcmp( kp->name, "msm_thermal.freq_hot") == 0 && ( i >= FREQ_WARM || i <= FREQ_VERY_HOT ))
return -EINVAL;
if ( strcmp( kp->name, "msm_thermal.freq_very_hot") == 0 && ( i >= FREQ_HOT || i <= FREQ_HELL ))
return -EINVAL;
if ( strcmp( kp->name, "msm_thermal.freq_hell") == 0 && i >= FREQ_VERY_HOT )
return -EINVAL;
/* End Sanity Checks */
ret = param_set_int(val, kp);
return ret;
}
static struct kernel_param_ops freq_limit_ops = {
.set = set_freq_limit,
.get = param_get_int,
};
module_param_cb(freq_hell, &freq_limit_ops, &FREQ_HELL, 0644);
module_param_cb(freq_very_hot, &freq_limit_ops, &FREQ_VERY_HOT, 0644);
module_param_cb(freq_hot, &freq_limit_ops, &FREQ_HOT, 0644);
module_param_cb(freq_warm, &freq_limit_ops, &FREQ_WARM, 0644);

Android Volley request weird “1 second” delay between multiple fast clicks

Sorry for my bad english, but i have problem and can't figure it out..
I have custom listview in my fragment for getting products from JSON array. And I have 3 ImageButtons in every listview row;
Plus Button(+), Minus Button(-) and Remove Button(X)..
So when i click each button, its calling JSON request for update product's piece number, getting new datas from response and repopulate array list.
Everything ok but, when I click that buttons faster, it seems there is 1 sec delay between multiple requests even first volley request has already done before.
Here is my JSON method in TableAdapter.java
Code:
[SIZE="3"]public void JSON(final int position, final int process) {
if (inProgress==false) {
dialog = new ProgressDialog(myContext);
dialog.setMessage("Updating.....");
dialog.show();
inProgress = true;
System.out.println("**** Now request is beginning............");
final int rowID = tableModelList.get(position).getID();
final int treeID = tableModelList.get(position).getAna_dal();
final float price = tableModelList.get(position).getBFiyat();
final int quantity = tableModelList.get(position).getAdet();
final int print = tableModelList.get(position).getYazdimi();
final String insertUrl = "This is URL for getting json array";
Map<String, String> parameters = new HashMap<>();
parameters.put("tableID", "" + getTableId);
parameters.put("rowID", "" + rowID);
parameters.put("treeID", ""+treeID);
parameters.put("process",""+process);
parameters.put("quantity",""+quantity);
parameters.put("price",""+price);
parameters.put("print",""+print);
CustomRequest jsObjRequest = new CustomRequest(Request.Method.POST, insertUrl, parameters, new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
try {
JSONArray getOrders = response.getJSONArray("order");
Gson gson = new Gson();
tableModelList.clear();
for (int i = 0; i < getOrders.length(); i++) {
JSONObject order = getOrders.getJSONObject(i);
TableModel tableModel = gson.fromJson(order.toString(), TableModel.class);
tableModelList.add(tableModel);
}
mAdapter.notifyDataSetChanged();
System.out.println("**** onResponse: Request is done............");
System.out.println("**** JSON: "+response.toString());
dialog.cancel();
inProgress = false;
} catch (JSONException e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError response) {
Log.d("Response: ", response.toString());
inProgress = false;
}
});
requestQueue.add(jsObjRequest);
}
}[/SIZE]
Dialog is showing when request beginning and canceling when request is done. But as I said, when I click faster, there is a delay between multiple requests even first request has already done. I'm saying 1 sec, because 2nd request is beginning after 1 sec exactly, no matter how I clicking fast. I can't figure it out..
I tested fast clicks to showing toasts with random numbers and it's working fine. But when I testing with JSON method, there is a weird delay.
I have SwipeRefreshLayout and ScrollView in my fragment. I'm using Volley with singleton.
Here is video to showing what my problem is;
Here is Logcat output for every click
Every fast click has returning success json output, but nothing change instantly on the screen..
Thanks for your help.

Camera real time image processing

I need to do some image processing in real time on mobile. I am using camera2 library. I managed to put camera preview directly on surfaceView but when i redirect it to ImageReader to do something with frames before i preview them it goes really slow, and there is not even processing just taking Y value from YUV_420_888 and converting it to gray picture in ARGB_8888 format. Code is below. For that one for loop i need about 600ms. And for image processing i will need to go trough that image at least one more time. In Bits array i form ARGB_8888 format out of Y array which is Y value of YUV_420_888 format. I test it on phone with Quad Core 1ghz processor and 1gb ram. Is there any way to speed this code up so i can go lets say 2-3 times trough picture and have at least 7-10 fps? If i delete for loop and just measure fps its 8-12fps. Why is it so slow compering to 25fps when i put it directly on surfaceView?
Code:
private final CameraDevice.StateCallback mStateCallback = new CameraDevice.StateCallback() {
@Override
public void onOpened(@NonNull CameraDevice cameraDevice) {
// This method is called when the camera is opened. We start camera preview here.
mCameraOpenCloseLock.release();
mCameraDevice = cameraDevice;
createCameraPreviewSession();
mImageReader.setOnImageAvailableListener(new ImageReader.OnImageAvailableListener() {
@Override
public void onImageAvailable(ImageReader reader) {
Image image = reader.acquireLatestImage();
if(image != null) {
ByteBuffer buffer0 = image.getPlanes()[0].getBuffer();
byte[] Y = new byte[buffer0.remaining()];
buffer0.get(Y);
byte[] Bits = new byte[Y.length*4]; //That's where the RGBA array goes.
int Ylength = Y.length;
for (int i = 0; i < Ylength; i++) {
int i1 = i*4;
Bits[i1] =Y[i];
Bits[i1 + 1] =Y[i];
Bits[i1 + 2] = Y[i];
Bits[i1 + 3] = -1;//0xff, that's the alpha.
}
Bitmap bm = Bitmap.createBitmap(image.getWidth(), image.getHeight(), Bitmap.Config.ARGB_8888);
bm.copyPixelsFromBuffer(ByteBuffer.wrap(Bits));
Bitmap scaled = Bitmap.createScaledBitmap(bm, surfaceView.getWidth(), surfaceView.getHeight(), true);
Canvas c;
c = surfaceHolder.lockCanvas();
c.drawBitmap(scaled, 0, 0, null);
surfaceHolder.unlockCanvasAndPost(c);
image.close();
time2 = System.nanoTime();
Log.d("Vreme",Double.toString(1000000000/(time2-time1))+"fps");
time1 = System.nanoTime();
}
}
},mBackgroundHandler);
}
@Override
public void onDisconnected(@NonNull CameraDevice cameraDevice) {
mCameraOpenCloseLock.release();
cameraDevice.close();
mCameraDevice = null;
}
@Override
public void onError(@NonNull CameraDevice cameraDevice, int error) {
mCameraOpenCloseLock.release();
cameraDevice.close();
mCameraDevice = null;
}
};

Video Encryption Decryption takes too much time

This is code for encryption of video
FileInputStream fis = new FileInputStream(extStore+"/digilearn/try.mp4");
FileOutputStream fos = new FileOutputStream(extStore+"/digilearn/enctry.mp4");
SecretKeySpec sks = new SecretKeySpec("MyDifficultPassw".getBytes(),
"AES");
Cipher cipher = Cipher.getInstance("AES");
cipher.init(Cipher.ENCRYPT_MODE, sks);
CipherOutputStream cos = new CipherOutputStream(fos, cipher);
int b;
byte[] d = new byte[8192];
while ((b = fis.read(d)) != -1) {
cos.write(d, 0, b);
}
// Flush and close streams.
cos.flush();
cos.close();
fis.close();
This is the code for decryption of video
File extStore = Environment.getExternalStorageDirectory();
FileInputStream fis = new FileInputStream(extStore+"/digilearn/enctry.mp4");
FileOutputStream fos = new FileOutputStream(extStore+"/digilearn/dectry.mp4");
SecretKeySpec sks = new SecretKeySpec("MyDifficultPassw".getBytes(),
"AES");
Cipher cipher = Cipher.getInstance("AES");
cipher.init(Cipher.DECRYPT_MODE, sks);
CipherInputStream cis = new CipherInputStream(fis, cipher);
int b;
byte[] d = new byte[2*8192];
while ((b = cis.read(d)) != -1) {
fos.write(d, 0, b);
}
fos.flush();
fos.close();
cis.close();
with above code encryption and decryption both works but it take too much time when encrypted video file from sd card with video size is 1 GB.

Categories

Resources