[Q] Working with simple XML array - Android Q&A, Help & Troubleshooting

Not sure why it crash while looping the array:
Code:
final String tname[] = getResources().getStringArray(R.array.tname);
final int tid[] = getResources().getIntArray(R.array.tid);
final int tlv[] = getResources().getIntArray(R.array.tlv);
int tlength = tname.length;
String pname[] = new String[tlength];
int pid[] = new int[tlength];
for(int i = 0; i < tlength; i++) {
if(tlv[i] <= 0) {
pname[i] = tname[i];
pid[i] = tid[i];
}
}
setListAdapter(new ArrayAdapter<String>(this, R.layout.pMenu, pname));
Thanks in advance!

Related

[Q] :How to use list view for Map

Hi,
I am developing an android app in which i am using csv file and displaying column contents as listview its displaying as [a,b,c,d] in single row how to display them in individual row in listview.Please any one help me how to achive this.
This is my csv file reading code using hashcode.
Code:
public static Map<String,ArrayList<String>> parseCsv(InputStreamReader reader, String separator, boolean hasHeader) throws IOException {
Map<String,ArrayList<String> > values = new LinkedHashMap<String,ArrayList<String>>();
List<String> columnNames = new LinkedList<String>();
BufferedReader br = null;
br = new BufferedReader(reader);
String line;
int numLines = 0;
while ((line = br.readLine()) != null) {
//if (StringUtils.isNotBlank(line)) {
//if (!line.startsWith("#")) {
String[] tokens = line.split(separator);
if (tokens != null) {
for (int i = 0; i < tokens.length; ++i) {
if (numLines == 0) {
columnNames.add(hasHeader ? tokens[i] : ("row_"+i));
} else {
ArrayList<String> column = values.get(columnNames.get(i));
if (column == null) {
column = new ArrayList<String>();
}
column.add(tokens[i]);
values.put(columnNames.get(i), column);
}
}
}
++numLines;
}
// }//
// }//
return values;
listview code is:
Code:
oslist.add(values);
ListView list = (ListView) findViewById(R.id.studentnames);
String name="name";
// Add it listview
ListAdapter adapter = new SimpleAdapter(this,
oslist, R.layout.student_list, new String[] { name }, new int[] { R.id.name});
list.setAdapter(adapter);

[Q] Draw Objects on Screen

I'm starting to build an app that needs 2D drawing on Android Studio and even after some search I still have some troubles understanding some things. My intention is to draw Balls as objects, so that I can specify its radius and locations to draw. That ball should be a filled circle.
So here are my questions:
1. How to create the ball class in the most organized way? (Its constructors, methods, and stuff like that)​1. Where to call that class to create balls?(what should I do on the onCreate() method? My coding should go in my MainActivity class?)​1. How to draw them by a timer?(create a ball with a random radius and position and draw it on screen)​1. Where to draw them? (container)​
I saw a lot of things using canvas, the mysterious onDraw() method and I didn't get much of it.
I didn't understand how to control when to draw it.
I used this code for leaning and kinda control the drawing of objects , but It seems too messy and dont feel right.
Its a sensor controlled ball.
Bubbleview.java
Code:
public class BubbleView extends View
{
private int diametro;
private int x;
private int y;
private int Xt;
private int Yt;
private ShapeDrawable bubble;
private ShapeDrawable rect;
private boolean isTouch = false;
private int width;
private int height;
private WindowManager wm;
private Display display;
private Point size;
private Point centroBola;
private Point centroRet;
//private Color Retcor;
//private Color Bolacor;
public BubbleView(Context context)
{
super(context);
/*--Instancias--*/
bubble = new ShapeDrawable(new OvalShape());
rect = new ShapeDrawable(new RectShape());
size = new Point();
//Retcor = new Color();
//Bolacor = new Color();
createBubble();
}
private void createBubble()
{
wm = (WindowManager)getContext().getSystemService(Context.WINDOW_SERVICE);
display = wm.getDefaultDisplay();
display.getSize(size);
width = (size.x);
height = (size.y);
x = width/2;
y = height/2;
//centroBola.set(x+(diametro/2),y-(diametro/2));
diametro = 100;
bubble.setBounds(x-diametro,y-diametro, x + diametro, y + diametro);
rect.setBounds(0, 10, size.x-1,80);
bubble.getPaint().setColor(0xff74AC23);
//rect.getPaint().setColor(0xff74AC23);//0xffEE4400
}
protected void move(float f, float g)
{
if (isTouch)
{
x = Xt;
y = Yt;
}
else
{
if (bubble.getBounds().right > width)
{
x=width-diametro-1;
y = (int) (y + g);
}
if (bubble.getBounds().left < 0)
{
x = 0;
y = (int) (y + g);
}
if (bubble.getBounds().top < 0)
{
x = (int) (x - f);
y = 1;
}
if (bubble.getBounds().bottom > height) {
x = (int) (x - f);
y = height - diametro -1;
}
x = (int) (x - f);
y = (int) (y + g);
}
//rect.setBounds(x+40, y+40, x + diametro, y + diametro);
bubble.setBounds(x,y,x +diametro,y+diametro);
}
@Override
public boolean onTouchEvent(MotionEvent event)
{
Xt = (int) event.getX();
Yt = (int) event.getY();
int evento = event.getAction();
switch (evento)
{
case MotionEvent.ACTION_DOWN:
bubble.setBounds(0, 0, Xt + diametro,Yt+ diametro);
//rect.setBounds(Xt, Yt, Xt + diametro,Yt+ diametro);
//coords.setText("X: " + X + ", Y: " + Y);
isTouch = true;
break;
case MotionEvent.ACTION_MOVE:
//coords.setText("X: " + X + ", Y: " + Y);
break;
case MotionEvent.ACTION_UP:
//Toast.makeText(this, "Saiu da tela em: X: " + X + ", Y: " + Y, Toast.LENGTH_SHORT);
isTouch = false;
break;
}
return true;
}
protected void onDraw(Canvas canvas)
{
super.onDraw(canvas);
//rect.draw(canvas);
bubble.draw(canvas);
}
}
So I tried to build my app using this as a reference, but no success.
Wich way should the code becomes more intuitive?
thx in advance

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);

Trouble with string encode after decompile APK file

Hello,
I have a trouble with a string text encode after decompile an APK file.
I used APK Tool decompile.
The code was encoded here:
Code:
public class API
extends Activity
{
public static String a = "081b11458016006d513b0290cc7be0b39c28626ea506b9ed291b125114f2a38369a42e77a066a7789e5883ed47113fc3";
public static String b = "081b11458016006d513b0290cc7be0b36f01584bcfccde8bd9e2bd628ca804e7056b175ad6a1fa1bf3cf31d8a28b94e9";
public static String c = "081b11458016006d513b0290cc7be0b36f01584bcfccde8bd9e2bd628ca804e7056b175ad6a1fa1bf3cf31d8a28b94e9";
public static JSONObject d = new JSONObject();
public static String e = "";
private static int h = 0;
private boolean f = false;
private ProgressDialog g;
private JSONObject a(JSONObject paramJSONObject)
{
int i = 0;
Iterator localIterator = paramJSONObject.keys();
int[] arrayOfInt = new int[paramJSONObject.length()];
int j = 0;
JSONObject localJSONObject1;
int m;
if (!localIterator.hasNext())
{
Arrays.sort(arrayOfInt);
localJSONObject1 = new JSONObject();
m = arrayOfInt.length;
}
for (;;)
{
if (i >= m)
{
return localJSONObject1;
int k = j + 1;
arrayOfInt[j] = Integer.parseInt(((String)localIterator.next()).toString());
j = k;
break;
}
String str1 = Integer.toString(arrayOfInt[i]);
try
{
JSONObject localJSONObject2 = (JSONObject)paramJSONObject.get(str1);
if (((paramJSONObject.get(str1) instanceof JSONObject)) && (!a(localJSONObject2.get("package").toString())))
{
String str2 = localJSONObject2.get("package").toString();
if (!getApplicationContext().getSharedPreferences("listpacks", 0).getBoolean(str2, false)) {
if (localJSONObject2.get("type").toString().equals("1"))
{
if (!this.f)
{
this.f = true;
d = localJSONObject2;
}
}
else
{
e = e + localJSONObject2.get("package").toString() + "|";
localJSONObject1.put(str1, localJSONObject2);
}
}
}
}
catch (JSONException localJSONException)
{
localJSONException.printStackTrace();
}
i++;
}
}
I'm looking for many forum but I'm not find answer.
Anybody can help me decode 3 text string a,b,c please?
Updated: Dear, I have been decode text string by step by step replace char - because I'm not coder.
Result string a:
Code:
081b11458016006d513b0290cc7be0b39c28626ea506b9ed291b125114f2a38369a42e77a066a7789e5883ed47113fc3
is
Code:
http_abc.com/defgh_v2/api_in.php?app_name=9apps&api=19
Update new question, maybe easy: Anybody please tell me what is type encode? ( Again, I'm not a coder but I'm a Google Man hihi)

Android VideoView Resize Algorithm - Bilinear or Bicubic?

Hi, community,
I was trying to resize a video to be played on Google Pixel 5 to fit the screen. I am able to achieve the required but I need to dig a bit deeper to understand the functioning under the hood. I want to understand if the resizing is happening on hardware or software? Also, what is the algorithm used in the resizing operation whether it is bilinear or bicubic or Lanczos or anything else?
Java:
public void setVideo(String id)
{
System.out.println("Starting video");
System.out.println(id);
String videoPath = Environment.getExternalStorageDirectory().getPath()+"/"+ id;
videoView.setVideoPath(videoPath);
videoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mp) {
DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);
int screenWidth = metrics.widthPixels;
int screenHeight = metrics.heightPixels;
float screenProportion = (float) screenWidth / (float) screenHeight;
android.view.ViewGroup.LayoutParams lp = videoView.getLayoutParams();
int VideoWidth = mp.getVideoWidth();
int VideoHeight = mp.getVideoHeight();
float videoProportion = (float) VideoWidth / (float) VideoHeight;
if (videoProportion > screenProportion) {
lp.width = screenWidth;
lp.height = (int) ((float) screenWidth / videoProportion);
} else {
lp.width = (int) (videoProportion * (float) screenHeight);
lp.height = screenHeight;
}
videoView.setLayoutParams(lp);
}
});
videoView.start();

Categories

Resources