Hi All,
I have recently been trying to port an augmented reality research project to the Galaxy Camera (EK-GC100) and have hit a few stumbling blocks. The main one of these is that whilst I can control the camera using software UI controls and the Android camera API, I would like to use the hardware zoom and shutter controls. My understanding based on trawling this forum is that it hasn't been done, but can anyone confirm whether or not this is the case? And if it is possible, how should I go about it? Any help would be greatly appreciated.
Thanks
Answered my own question!
It's ok, I've figured out the answer to this! I suspected Samsung may have been using the standard key event constants so wrote a very simple app to read out the key code value for any key down or up events. This app confirmed my thoughts. The constants used are:
Zoom in button pressed: KEYCODE_ZOOM_IN (value 168)
Zoom out button pressed: KEYCODE_ZOOM_OUT (value 169)
Shutter button pressed halfway: KEYCODE_FOCUS (value 80)
Shutter button pressed fully: KEYCODE_CAMERA (value 27)
When I pressed and held any of these buttons, the keycodes were sent repeatedly at a fairly high frequency. To make button handling a bit smoother, I have added some simple checks. If the user holds down a button, the first keycode is registered. The following 5 are ignored, then the 6th would be registered and the 5 event counter resets. If the user lets go of a button, this counter is also reset. The result is that the camera handles the zoom and shutter commands better than if I were just acting on every received keycode. Some example code is below:
Code:
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
switch (keyCode) {
case KeyEvent.KEYCODE_ZOOM_IN:
if(hwBtnHeldCounter==0)
{
zoomIn();
hwBtnHeldCounter++;
}
else if(hwBtnHeldCounter==5)
{
// reset counter
hwBtnHeldCounter = 0;
}
else
{
// increment counter
hwBtnHeldCounter++;
}
return true;
default:
return super.onKeyDown(keyCode, event);
}
}
@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
switch (keyCode) {
case KeyEvent.KEYCODE_ZOOM_IN:
// reset counter
hwBtnHeldCounter=0;
return true;
default:
return super.onKeyUp(keyCode, event);
}
}
Hope this helps some other aspiring Galaxy Camera developers out!
Related
Hello,
How could I, even if I need to code it, add "Vibrate" option to phone menu.
Alias the "Reboot" option.
Thank you,
Anthon.
Best bet is to use a lock screen replacement like lockbot pro with the eclair lockscreen (swipe left to toggle silent/vibe, swipe right to unlock). I'm not sure if Stericsons lockscreen can do it cause I haven't used his in a while.
Finally I had some time to wonder through the source code.
Heres what I found:
File: (...)/frameworks/policies/base/phone/com/android/internal/policy/impl/GlobalActions.java
Code:
mItems = Lists.newArrayList(
// silent mode
mSilentModeToggle,
// next: airplane mode
mAirplaneModeOn,
// next: reboot
new SinglePressAction(com.android.internal.R.drawable.ic_lock_power_off, R.string.global_action_reboot) {
public void onPress() {
ShutdownThread.reboot(mContext, true);
}
public boolean showDuringKeyguard() {
return true;
}
public boolean showBeforeProvisioning() {
return true;
}
},
// last: power off
new SinglePressAction(
com.android.internal.R.drawable.ic_lock_power_off,
R.string.global_action_power_off) {
public void onPress() {
// shutdown by making sure radio and power are handled accordingly.
ShutdownThread.shutdown(mContext, true);
}
public boolean showDuringKeyguard() {
Strings and Layout is here:
(...)/frameworks/base/core/res/res/values/strings.xml
(...)/frameworks/base/core/res/res/layout/power_dialog.xml
Gonna add a "Vibrate", or modify the "Silent" option, to the Phone Options.
I know this is not a major discovery. Only the answer to my question.
Thanks,
Anthon.
Why dont you just use the buttom on the left side on the phone? If you press "-" on the home, you can lower the ringtone volumen and set it to "Vibrate"...
MotionEvent http://android-developers.blogspot.com/?hl=en
The Android framework’s primary point of access for touch data is the android.view.MotionEvent class. Passed to your views through the onTouchEvent and onInterceptTouchEvent methods, MotionEvent contains data about “pointers,” or active touch points on the device’s screen. Through a MotionEvent you can obtain X/Y coordinates as well as size and pressure for each pointer. MotionEvent.getAction() returns a value describing what kind of motion event occurred.
One of the more common uses of touch input is letting the user drag an object around the screen. We can accomplish this in our View class from above by implementing onTouchEvent as follows:
@Override
public boolean onTouchEvent(MotionEvent ev) {
final int action = ev.getAction();
switch (action) {
case MotionEvent.ACTION_DOWN: {
final float x = ev.getX();
final float y = ev.getY();
// Remember where we started
mLastTouchX = x;
mLastTouchY = y;
break;
}
case MotionEvent.ACTION_MOVE: {
final float x = ev.getX();
final float y = ev.getY();
// Calculate the distance moved
final float dx = x - mLastTouchX;
final float dy = y - mLastTouchY;
// Move the object
mPosX += dx;
mPosY += dy;
// Remember this touch position for the next move event
mLastTouchX = x;
mLastTouchY = y;
// Invalidate to request a redraw
invalidate();
break;
}
}
return true;
}
The code above has a bug on devices that support multiple pointers. While dragging the image around the screen, place a second finger on the touchscreen then lift the first finger. The image jumps! What’s happening? We’re calculating the distance to move the object based on the last known position of the default pointer. When the first finger is lifted, the second finger becomes the default pointer and we have a large delta between pointer positions which our code dutifully applies to the object’s location.
If all you want is info about a single pointer’s location, the methods MotionEvent.getX() and MotionEvent.getY() are all you need. MotionEvent was extended in Android 2.0 (Eclair) to report data about multiple pointers and new actions were added to describe multitouch events. MotionEvent.getPointerCount() returns the number of active pointers. getX and getY now accept an index to specify which pointer’s data to retrieve.
anyone know?
You don't have much code up there but...
"mLastTouchX = x;
mLastTouchY = y;"
I assume those are globals... and the fact is that both action down and action move use those at the same time if you use two fingers...
EX:
-finger down create mlasttouchx&y at lets says 0,0 and you move to 1,1 enabling action move to correct it...
-keep finger still and add second finger...
-second finger changes the SAME variables of the previous item
-lift first finger so on action up theres no update (since you have no action up)
I'm not sure HOW to fix this issue (I've never tried multitouch) but your code doesn't support it.
How about adding some toggle variables and add an action up so on release it updates the points OR try using pointers (up to 3 as far as i can see probably for multitouch)
http://developer.android.com/reference/android/view/MotionEvent.html
Hello,
I'm very new to Android development and to this site, so I'm sorry if I'm posting a common issue or in the wrong place.
I am using a tutorial to just develop a simple app to get my feet wet.
I'm at the point where I create an Action Bar, and this is what I have in MainActivity.java :
@override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu.
// Adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
// Access the Share Item defined in menu XML
MenuItem shareItem = menu.findItem(R.id.menu_item_share);
// Access the object responsible for
// putting together the sharing submenu
if (shareItem != null) {
mShareActionProvider = (ShareActionProvider) MenuItemCompat.getActionProvider();
}
// Create an Intent to share your content
setShareIntent();
return true;
}
For the bold and highlighted part of the code, Android Studio is saying that cannot be applied. This is not allowing me to run the app.
Thanks for any help/advice!
Hi,
First off, I just entered the android programming world so my knowledge is very limited. Please bear with me.
I'm creating an XPosed module that simply takes a screenshot when I press the volume up or down buttons.
I've managed to hook the buttons globally, but since I don't have control of the topmost view, I don't know how I would be able to take a screenshot.
Originally, one would do it this way :
Code:
public Bitmap screenShot(View view) {
Bitmap bitmap = Bitmap.createBitmap(view.getWidth(),
view.getHeight(), Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
view.draw(canvas);
return bitmap;
}
screenShot((ViewGroup) view.getParent());
However, I would need the view of the current activity in the foreground, and I'm kind of lost on how to retrieve it from within the XPosed module.
I looked through XPosedHelper.class and found a bunch if "find" functions that can get methods, resources, and classes but there are no helper functions for views except this comment on the very end.
Code:
// TODO helpers for view traversing
My current code looks like this :
Code:
public class Main {
static void init() {
try {
Class<?> classPhoneWindowManager = findClass("com.android.internal.policy.impl.PhoneWindowManager", null);
findAndHookMethod(classPhoneWindowManager, "interceptKeyBeforeQueueing",
KeyEvent.class, int.class, boolean.class, handleInterceptKeyBeforeQueueing);
} catch (Exception e) { XposedBridge.log(e); }
}
private static XC_MethodHook handleInterceptKeyBeforeQueueing = new XC_MethodHook(XCallback.PRIORITY_HIGHEST) {
@Override
protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
final boolean isScreenOn = (Boolean) param.args[2];
if (isScreenOn) {
final KeyEvent event = (KeyEvent) param.args[0];
final int keyCode = event.getKeyCode();
if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN || keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
if (event.getAction() == KeyEvent.ACTION_DOWN) {
doSomething(param.thisObject, keyCode);
param.setResult(0);
return;
}
}
}
}
};
private static void doSomething(Object phoneWindowManager, int keycode) {
View content = findViewById(R.id.layoutroot);
content.setDrawingCacheEnabled(true);
}
}
I have to put some code in the "doSomething" function, but I'm kind of lost apprently. :crying:
How could I go about getting the screenshot of the current screen?
I've tried accessing the framebuffer, but realized that the framebuffer has been removed and only an empty fb0 exist on recent devices.
I also tried to use "/system/bin/screencap, screenshot, screenrecord" but for some reason, the application I'm targeting doesn't seem to work with those binaries.
Do you have any other suggestions? Any help would be appreciated.
Thanks.
You can use the APP called aiogestures,,Then you can change holding the menu button to screenshot button,or you can use the gravitybox to change the button………………
My English Is not very good……………
wish you can solve it???
仰天坏笑 said:
You can use the APP called aiogestures,,Then you can change holding the menu button to screenshot button,or you can use the gravitybox to change the button………………
My English Is not very good……………
wish you can solve it
Click to expand...
Click to collapse
Okay, I'll try those. Thanks!
However, it would be nice if I could implement my own code to directly get screenshots, instead of using an existing device's screenshot functionality. The reason being is, the application I'm targeting prohibits the user to take a screenshot, and therefore blocks all sorts of canonical methods to take a screenshot. I would like to have some more versatility and implement custom code to test different things, so I could bypass the screenshot restriction.
My android programming skills are quite poor... so any kind of help would be appreciated.
Thanks!
The great thing about open source is that you can use the work of others as a reference, so everyone benefits from everyone.
Luckily quite some Xposed developers do publish their sources.
A safe bet is to use GravityBox by the great @C3C076 as it implements a screenshot function..
Going to GravityBox at Github and searching (press T at github) for screenshot e.g. brings up the ScrreenshotTile.java
Here is a reference to the ModHwKeys.java - and there you'll find a takeScreenshot() function.
Cheers :fingers-crossed:
tonyp said:
The great thing about open source is that you can use the work of others as a reference, so everyone benefits from everyone.
Luckily quite some Xposed developers do publish their sources.
A safe bet is to use GravityBox by the great @C3C076 as it implements a screenshot function..
Going to GravityBox at Github and searching (press T at github) for screenshot e.g. brings up the ScrreenshotTile.java
Here is a reference to the ModHwKeys.java - and there you'll find a takeScreenshot() function.
Cheers :fingers-crossed:
Click to expand...
Click to collapse
Thanks!
However, it uses a service provided in "com.android.systemui.screenshot.TakeScreenshotService", which is blocked by the application. I'm trying to use various codes of taking screenshots, but all most of them require the current foreground view that is on the screen. I'm trying to figure out how I can get the foreground view class reference from within the XPosed module.
Any other suggestions?
android.view.SurfaceControl has some static methods for capturing screenshots silently. You can even control which layers should be excluded. E.g. you can do screenshot without system decors (navbar / status bar). Refer to https://android.googlesource.com/pl...r1/core/java/android/view/SurfaceControl.java (link is for lollipop but the same class exists in lower versions, too)
Here's an example how I use it on KitKat
https://github.com/GravityBox/Gravi...m/ceco/kitkat/gravitybox/ModDisplay.java#L446
binhexcraft said:
Thanks!
... which is blocked by the application....
Click to expand...
Click to collapse
Out of curiosity. Which app are you targeting?
C3C076 said:
android.view.SurfaceControl has some static methods for capturing screenshots silently. You can even control which layers should be excluded. E.g. you can do screenshot without system decors (navbar / status bar). Refer to https://android.googlesource.com/pl...r1/core/java/android/view/SurfaceControl.java (link is for lollipop but the same class exists in lower versions, too)
Here's an example how I use it on KitKat
https://github.com/GravityBox/Gravi...m/ceco/kitkat/gravitybox/ModDisplay.java#L446
Click to expand...
Click to collapse
Just tried it out and it works perfectly!!!
..............when the app is not running. When the app is running, then it gets blocked at :
Code:
final Bitmap bmp = (Bitmap) XposedHelpers.callStaticMethod(
XposedHelpers.findClass("android.view.SurfaceControl", null), "screenshot",
naturalW, naturalH, 0, 22000);
and when I look at the debug log, it says
"FB is protected: PERMISSION_DENIED"
This happens to be because the app is configured to use a "secure window".
Do you know if there is any workaround for this restriction?
My current thinking is to hook "captureScreenImplLocked" from here :
https://android.googlesource.com/pl...74/services/surfaceflinger/SurfaceFlinger.cpp
and make it bypass this part of the code.
Code:
if (hw->getSecureLayerVisible()) {
ALOGW("FB is protected: PERMISSION_DENIED");
return PERMISSION_DENIED;
}
or maybe just hook "getSecureLayerVisible" to always return false...
Would this be the right way to go?
...but before that, is it even possible? Cause I saw a post from someone saying that hooking SurfaceFlinger is not feasible or very disruptive...
http://forum.xda-developers.com/showpost.php?p=46388379&postcount=186
Or is there maybe a better, simpler way?
Thanks!
AA1973 said:
Out of curiosity. Which app are you targeting?
Click to expand...
Click to collapse
Sent you PM.
Answer to my own question.
I found a really simple workaround.
http://repo.xposed.info/module/fi.veetipaananen.android.disableflagsecure
Thanks for all the advice guys!!
I have finally fulfilled my objective.
1) Can anyone bring me back code of the press (BACK) devices such as the Galaxy LG etc., that kind of goes back button all the time back
2) Is it possible to make any changes in SPINNER another color? That is when I open the SPINNER any changes / Line will be a different color I choose?
3) just an example I built an app that chooses an image from the media Phone, after it came to ImageView this over and across, it's some of the images
How do I IMAGEVIEW rotation? I realized it is called rotation How do I use it?
1)
Code:
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
// do something
yourView.notifyBackPressed();
return false;
}
return super.onKeyDown(keyCode, event);
}
And in your View have to implement method, for example notifyBackPressed();
2) Good question i need to know that!
3)
Code:
private void rotate(float degree) {
final RotateAnimation rotateAnim = new RotateAnimation(0.0f, degree,
RotateAnimation.RELATIVE_TO_SELF, 0.5f,
RotateAnimation.RELATIVE_TO_SELF, 0.5f);
rotateAnim.setDuration(0);
rotateAnim.setFillAfter(true);
imgview.startAnimation(rotateAnim);
}
Bye
cristaccio85 said:
1)
Code:
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
// do something
yourView.notifyBackPressed();
return false;
}
return super.onKeyDown(keyCode, event);
}
And in your View have to implement method, for example notifyBackPressed();
2) Good question i need to know that!
3)
Code:
private void rotate(float degree) {
final RotateAnimation rotateAnim = new RotateAnimation(0.0f, degree,
RotateAnimation.RELATIVE_TO_SELF, 0.5f,
RotateAnimation.RELATIVE_TO_SELF, 0.5f);
rotateAnim.setDuration(0);
rotateAnim.setFillAfter(true);
imgview.startAnimation(rotateAnim);
}
Bye
Click to expand...
Click to collapse
The best, thanks 7