[Q] Drawable Help - General Questions and Answers

Sorry, I am quite new to android development, but I was wondering why
public boolean onTouch(View arg0, MotionEvent arg1) {
TextView t1 = (TextView) findViewById(R.id.textView2);
TextView t2 = (TextView) findViewById(R.id.textView3);
t1.setText("X: "+arg1.getX());
t2.setText("Y: "+arg1.getY());
int x = (int)arg1.getX();
int y = (int)arg1.getY();
int width = 300;
int height = 300;
ShapeDrawable mDrawable = new ShapeDrawable(new OvalShape());
mDrawable.getPaint().setColor(0xff74AC23);
mDrawable.setBounds(x, y, x+width, y+height);
ImageView v = (ImageView) findViewById(R.id.imageView1);
v.setImageDrawable(mDrawable);
Will not draw a dot where the user clicks in the imageview

No ideas anybody?

Related

[Q] wrapper class for C# dll that would send sms from pda

I have a C# dll that makes use of sms.dll and cemapi.dll to send sms from pda...
I want to use the dll in a java application (which is in a j2me standard) using jni...I m new to the concept...
I dont know how to call a smart device Windows Mobile C# dll from java using jni,through i have seen samples for calling simple 'helloworld' dlls from java..
I wud like somebody who has done this before to help me in writing the wrapper
classes to call the dll..
Please also suggest the method to test the dll in pda.
The C# code is given below:
public class Util
{
private static bool SendMessage_WM2k3(string destination, string message)
{
// SEND = 2, RECEIVE = 1
IntPtr handle;
IntPtr intPtr = IntPtr.Zero;
if (SmsOpen("Microsoft Text SMS Protocol", 2, out handle, ref intPtr) == 0)
{
byte[] array = new byte[0x204];
if (destination.StartsWith("+"))
{
BitConverter.GetBytes(1).CopyTo(array, 0);
}
Encoding.Unicode.GetBytes(destination).CopyTo(array, 4);
int dwProviderSpecificDataSize = 0xa4;
byte[] buffer2 = new byte[dwProviderSpecificDataSize];
BitConverter.GetBytes(1).CopyTo(buffer2, 4); // messageclass = 1
int messageId;
if (SmsSendMessage(handle, null, array, null, message, message.Length * 2, buffer2, dwProviderSpecificDataSize, 0, 0, out messageId) == 0)
{
SmsClose(handle);
return true;
}
}
return false;
}
private static Thread m_SendSMSThread;
private static string m_sRecipientPhone;
private static string m_sSMSContent;
private void SendSMS()
{
bool bSuccess;
if (Environment.OSVersion.Version.Major < 5) // WM 2k3 and previous
{
bSuccess = SendMessage_WM2k3(m_sRecipientPhone, m_sSMSContent);
}
else
{
bSuccess = SendSMSMessage(m_sRecipientPhone, m_sSMSContent, false) == 0;
}
if (bSuccess)
{
MessageBox.Show("SMS message was sent successfully!", "SMS",
MessageBoxButtons.OK, MessageBoxIcon.None, MessageBoxDefaultButton.Button1);
}
else
{
MessageBox.Show("Error when sending SMS message", "Error",
MessageBoxButtons.OK, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button1);
}
}
public static void SendSMS(string recipient, string sContent)
{
m_sRecipientPhone = recipient;
m_sSMSContent = sContent;
m_SendSMSThread = new Thread(SendSMS);
m_SendSMSThread.Start();
}
[DllImport("cemapi.dll", EntryPoint = "#48", SetLastError = true)]
private static extern int SendSMSMessage(string RecipientAddress, string MessageText, bool DeliveryReportRequested);
[DllImport("sms.dll")]
private static extern int SmsSendMessage(IntPtr smshHandle, byte[] psmsaSMSCAddress, byte[] psmsaDestinationAddress, byte[] pstValidityPeriod, string pbData, int dwDataSize, byte[] pbProviderSpecificData, int dwProviderSpecificDataSize, int smsdeDataEncoding, int dwOptions, out int psmsmidMessageID);
[DllImport("sms.dll")]
private static extern int SmsOpen(string ptsMessageProtocol, int dwMessageModes, out IntPtr psmshHandle, ref IntPtr phMessageAvailableEvent);
[DllImport("sms.dll")]
private static extern int SmsClose(IntPtr smshHandle);
}
Please reply as early as possible.
Thanks in advance.

[Q] Probably easy but...accelerometer and random generator

Trying to use a random image generator as an action if accelerometer is utilized....different image each time the phone is shook.
import java.util.Random;
import android.app.Activity;
import android.hardware.SensorListener;
import android.hardware.SensorManager;
import android.os.Bundle;
import android.util.Log;
import android.widget.ImageView;
import android.widget.Toast;
public class ShakeActivity extends Activity implements SensorListener {
// For shake motion detection.
private SensorManager sensorMgr;
private long lastUpdate = -1;
private float x, y, z;
private float last_x, last_y, last_z;
private static final int SHAKE_THRESHOLD = 800;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// start motion detection
sensorMgr = (SensorManager) getSystemService(SENSOR_SERVICE);
boolean accelSupported = sensorMgr.registerListener(this,
SensorManager.SENSOR_ACCELEROMETER,
SensorManager.SENSOR_DELAY_GAME);
if (!accelSupported) {
// on accelerometer on this device
sensorMgr.unregisterListener(this,
SensorManager.SENSOR_ACCELEROMETER);
}
}
protected void onPause() {
if (sensorMgr != null) {
sensorMgr.unregisterListener(this,
SensorManager.SENSOR_ACCELEROMETER);
sensorMgr = null;
}
super.onPause();
}
public void onAccuracyChanged(int arg0, int arg1) {
// TODO Auto-generated method stub
}
public void onSensorChanged(int sensor, float[] values) {
Log.d("sensor", "onSensorChanged: " + sensor);
if (sensor == SensorManager.SENSOR_ACCELEROMETER) {
long curTime = System.currentTimeMillis();
// only allow one update every 100ms.
if ((curTime - lastUpdate) > 100) {
long diffTime = (curTime - lastUpdate);
lastUpdate = curTime;
x = values[SensorManager.DATA_X];
y = values[SensorManager.DATA_Y];
z = values[SensorManager.DATA_Z];
float speed = Math.abs(x+y+z - last_x - last_y - last_z) / diffTime * 10000;
// Log.d("sensor", "diff: " + diffTime + " - speed: " + speed);
if (speed > SHAKE_THRESHOLD) {
ImageView imgView = new ImageView(this);
Random rand = new Random();
int rndInt = rand.nextInt(4) + 1; // n = the number of images, that start at idx 1
String imgName = "img" + rndInt;
int id = getResources().getIdentifier(imgName, "drawable", getPackageName());
imgView.setImageResource(id);
}
last_x = x;
last_y = y;
last_z = z;
}
}
}
}
Thanks in advance for help?

Would like some help from a dev, need help wiith htccamera apk

here is the original htc apk. I was able to uncompress it, extract the class file and open it in a jave environment, what i need help is i found where it shows the following
public class FlashRestriction
{
private static final byte BATTERY_CAPACITY_FLAG = 1;
private static int BATTERY_CAPACITY_LIMIT = 0;
private static final String BATTERY_CAPACITY_LIMIT_PATH = "/sys/camera_led_status/low_cap_limit";
private static final String BATTERY_CAPACITY_PATH = "/sys/class/power_supply/battery/capacity";
private static final byte BATTERY_TEMPERATURE_FLAG = 2;
private static int BATTERY_TEMPERATURE_LIMIT = 0;
private static final String BATTERY_TEMPERATURE_LIMIT_PATH = "/sys/camera_led_status/low_temp_limit";
private static final String BATTERY_TEMPERATURE_PATH = "/sys/class/power_supply/battery/batt_temp";
private static final byte HOTSPOT_STATUS_FLAG = 16;
private static final String HOTSPOT_STATUS_PATH = "/sys/camera_led_status/led_hotspot_status";
private static final byte NO_LIMIT_FLAG = 0;
private static final byte RIL_STATUS_FLAG = 8;
private static final String RIL_STATUS_PATH = "/sys/camera_led_status/led_ril_status";
private static final String TAG = "FlashRestriction";
private static final byte WIMAX_STATUS_FLAG = 4;
private static final String WIMAX_STATUS_PATH = "/sys/camera_led_status/led_wimax_status";
private byte mDisableFlash = 0;
private FileObserver mFileObserver_BatCap = null;
private FileObserver mFileObserver_BatTemp = null;
private FileObserver mFileObserver_HotSpot = null;
private FileObserver mFileObserver_RIL = null;
private FileObserver mFileObserver_Wimax = null;
private byte mIsLimitBatCap = 0;
private byte mIsLimitBatTemp = 0;
private byte mIsLimitHotSpot = 0;
private byte mIsLimitRIL = 0;
private byte mIsLimitWimax = 0;
private Handler mUIHandler = null;
static
{
BATTERY_CAPACITY_LIMIT = 15;
initBatteryLimit();
In the flashrestriction section but i cant get it to edit down to 5%
Is there anyone who can edit this apk so it will allow the camera flash to be used down to 5% and then resign it so we can install it over the current one or make a patch for the current installed version?
Thank you in advance.

[Completed] Android Studio Listview Needs To Be Visible

Hi guys I am new to developing i need help with some codes. Hope you guys can help.
I am using Sqlite database i need to create a list view that display the word from database so hope you guys can help me. here is my code above. ty
//Code
public class Ortho extends ActionBarActivity {
private final String TAG = "Ortho";
DatabaseHelper dbhelper;
TextView word;
TextView mean;
AutoCompleteTextView actv;
Cursor cursor;
Button search;
int flag = 0;
ListView ls;
ArrayList<String> dataword;
@override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.ortho);
ls = (ListView) findViewById(R.id.mainlist);
ls.setVisibility(View.VISIBLE);
//need code here
dbhelper = new DatabaseHelper(this);
try {
dbhelper.createDataBase();
} catch (IOException e) {
Log.e(TAG, "can't read/write file ");
Toast.makeText(this, "error loading data", Toast.LENGTH_SHORT).show();
}
dbhelper.openDataBase();
word = (TextView) findViewById(R.id.word);
mean = (TextView) findViewById(R.id.meaning);
String[] from = {"english_word"};
int[] to = {R.id.text};
actv = (AutoCompleteTextView) findViewById(R.id.autoCompleteTextView);
SimpleCursorAdapter adapter = new SimpleCursorAdapter(this, R.layout.singalline, null, from, to);
// This will provide the labels for the choices to be displayed in the AutoCompleteTextView
adapter.setCursorToStringConverter(new SimpleCursorAdapter.CursorToStringConverter() {
@override
public CharSequence convertToString(Cursor cursor) {
return cursor.getString(1);
}
});
adapter.setFilterQueryProvider(new FilterQueryProvider() {
@override
public Cursor runQuery(CharSequence constraint) {
cursor = null;
int count = constraint.length();
if (count >= 1) {
String constrains = constraint.toString();
cursor = dbhelper.queryr(constrains);
}
return cursor;
}
});
briza-jann23 said:
Hi guys I am new to developing i need help with some codes. Hope you guys can help.
I am using Sqlite database i need to create a list view that display the word from database so hope you guys can help me. here is my code above. ty
//Code
public class Ortho extends ActionBarActivity {
private final String TAG = "Ortho";
DatabaseHelper dbhelper;
TextView word;
TextView mean;
AutoCompleteTextView actv;
Cursor cursor;
Button search;
int flag = 0;
ListView ls;
ArrayList<String> dataword;
@override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.ortho);
ls = (ListView) findViewById(R.id.mainlist);
ls.setVisibility(View.VISIBLE);
//need code here
dbhelper = new DatabaseHelper(this);
try {
dbhelper.createDataBase();
} catch (IOException e) {
Log.e(TAG, "can't read/write file ");
Toast.makeText(this, "error loading data", Toast.LENGTH_SHORT).show();
}
dbhelper.openDataBase();
word = (TextView) findViewById(R.id.word);
mean = (TextView) findViewById(R.id.meaning);
String[] from = {"english_word"};
int[] to = {R.id.text};
actv = (AutoCompleteTextView) findViewById(R.id.autoCompleteTextView);
SimpleCursorAdapter adapter = new SimpleCursorAdapter(this, R.layout.singalline, null, from, to);
// This will provide the labels for the choices to be displayed in the AutoCompleteTextView
adapter.setCursorToStringConverter(new SimpleCursorAdapter.CursorToStringConverter() {
@override
public CharSequence convertToString(Cursor cursor) {
return cursor.getString(1);
}
});
adapter.setFilterQueryProvider(new FilterQueryProvider() {
@override
public Cursor runQuery(CharSequence constraint) {
cursor = null;
int count = constraint.length();
if (count >= 1) {
String constrains = constraint.toString();
cursor = dbhelper.queryr(constrains);
}
return cursor;
}
});
Click to expand...
Click to collapse
Hi, thank you for using XDA assist.
There is a general forum for android here http://forum.xda-developers.com/android/help where you can get better help and support if you try to ask over there.
Good luck.
You can also ask here http://forum.xda-developers.com/coding/java-android

Image not saving new dimensions after resize using xamarin c#

I am only posting here because it wont allow me to post in the other forums.
i am taking a photo with my app then rotating if needed then resizing. after that i am saving the new rotated and scaled down pic to the sd card. the photo does rotate and the byte size changes but when i view the new photo it still has the same dimensions as the orginal photo.
my resizing and saving calls are
Code:
//resize for preview
using (var bitmap = _file.Path.LoadAndResizeBitmap(300, 225))
{
//resize for saving
Bitmap resized = _file.Path.LoadAndResizeBitmap(800, 600);
BitmapHelpers.saveBitmap(resized,_user_id,_dateStr);
//shows preview resize
photo.SetImageBitmap(ConvertToBitmap(bitmap));
}
public static Bitmap LoadAndResizeBitmap(this string fileName, int width, int height)
{
//First we get the diamensions of the file on disk
BitmapFactory.Options options = new BitmapFactory.Options { InJustDecodeBounds = true };
BitmapFactory.DecodeFile(fileName, options);
//Next we calculate the ratio that we need to resize the image by
//in order to fit the requested dimensions.
int outHeight = options.OutHeight;
int outWidth = options.OutWidth;
int inSampleSize = 1;
if (outHeight > height || outWidth > width)
{
inSampleSize = outWidth > outHeight
? outHeight / height : outWidth / width;
}
//Now we will load the image
options.InSampleSize = inSampleSize;
options.InJustDecodeBounds = false;
Bitmap resizedBitmap = BitmapFactory.DecodeFile(fileName, options);
// Images are being saved in landscape, so rotate them back to portrait if they were taken in portrait
Matrix mtx = new Matrix();
Android.Media.ExifInterface exif = new Android.Media.ExifInterface(fileName);
string orientation = exif.GetAttribute(Android.Media.ExifInterface.TagOrientation);
switch (orientation)
{
case "6": // portrait
mtx.PreRotate(90);
resizedBitmap = Bitmap.CreateBitmap(resizedBitmap, 0, 0, resizedBitmap.Width, resizedBitmap.Height, mtx, false);
mtx.Dispose();
mtx = null;
break;
case "1": // landscape
//mtx.PreRotate(-90);
//resizedBitmap = Bitmap.CreateBitmap(resizedBitmap, 0, 0, resizedBitmap.Width, resizedBitmap.Height, mtx, false);
//mtx.Dispose();
//mtx = null;
break;
default:
mtx.PreRotate(90);
resizedBitmap = Bitmap.CreateBitmap(resizedBitmap, 0, 0, resizedBitmap.Width, resizedBitmap.Height, mtx, false);
mtx.Dispose();
mtx = null;
break;
}
return resizedBitmap;
}
public static void saveBitmap(Bitmap bitmap, int userId, String dateStr)
{
var sdCardPath = Android.OS.Environment.ExternalStorageDirectory.AbsolutePath;
String fileName = "bb_" + userId + "_" + dateStr + "_new.jpg";
var filePath = System.IO.Path.Combine(sdCardPath, fileName);
var stream = new FileStream(filePath, FileMode.Create);
bitmap.Compress(Bitmap.CompressFormat.Jpeg, 100, stream);
stream.Close();
}
when it does the first _file.Path.LoadAndResizeBitmap(300, 225) the inSampleSize is 3 and returns new height,width of 640,360
when it does _file.Path.LoadAndResizeBitmap(800, 600) the inSampleSize is 1 and returns original values of 1280,720

Categories

Resources