我在想如何在不使用if语句的情况下获取整数的绝对值abs().起初我使用左移位(<<),试图将负号移出范围,然后将位移回原位,但不幸的是它对我不起作用.请让我知道它为什么不起作用以及其他替代方法.
我试图制作一个浮动视图,用户可以在屏幕上拖动.
我们的想法是启动一项服务,然后在屏幕上膨胀视图.
但是有一个问题,而不是将事件属于自己,它需要所有用户输入事件.
这是我的代码:manifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.floatandroidpractice"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.floatandroidpractice.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service android:name="com.example.floatandroidpractice.WalkingIconService" />
</application>
</manifest>
Run Code Online (Sandbox Code Playgroud)
浮动视图可以拖动:
package com.example.floatandroidpractice;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.view.MotionEvent;
import android.view.View;
public class littleIconView extends View {
private float viewX;
private float viewY;
private Paint mPaint;
private Bitmap …Run Code Online (Sandbox Code Playgroud) 从这篇文章中,我知道Android Debug Bridge由三个组件组成:
亚行客户
ADB服务器
设备或模拟器上的守护进程
我想从各自的源代码中更深入地了解这些组件.现在,我发现:
ADB客户:./ system/core/add/adb_client
ADB服务器:./ system/core/add/adb
设备或模拟器上的守护进程:不知道它在框架项目中的位置......
当我尝试使用以下代码运行由echo服务器和android客户端组成的测试时,我总是得到异常msg"socket is closed".这段代码可以简单地将msg发送到服务器,并从服务器接收消息,但如果你想同时做两件事,它就行不通了......我很好奇为什么它会导致这类问题,如果我希望它能够首先将msg发送到echo服务器,我应该如何解决它
然后从echo服务器接收消息?
// Server IP address
InetAddress serverIp;
// try to connect Server
try {
// set up server IP address
serverIp = InetAddress.getByName("192.168.17.1");
// set up port
int serverPort=12345;
// initiate socket connection
Socket clientSocket=new Socket(serverIp,serverPort);
BufferedOutputStream out = new BufferedOutputStream(clientSocket.getOutputStream());
out.write("Send From Android1111, stitch ".getBytes());
out.flush();
//wait to receive Server's msg
BufferedReader br =new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
total.toString();*/
// Display received msg with Toast
Toast.makeText(getApplicationContext(), br.readLine(), Toast.LENGTH_SHORT ).show();
//close connection
clientSocket.close();
// out.close();
// out = null; …Run Code Online (Sandbox Code Playgroud) 实际上,为了自学目的,我正在尝试在“Think in Java”中完成此练习-
练习 6:(2)在它自己的包中创建一个具有至少一种方法的接口。在单独的包中创建一个类。添加一个实现接口的受保护的内部类。在第三个包中,从您的类继承,并在方法内部返回受保护内部类的对象,并在返回期间向上转换到接口。
所以我在目录“a”下创建了一个名为 IgetResult.java 的类,它有一个 IIGetResult 接口。
interface IIGetResult {
String getResult();
}
public class IgetResult {
}
Run Code Online (Sandbox Code Playgroud)
然后我在另一个目录中创建另一个类——目录 b
import a.IgetResult.IIGetResult;
public class PracticeClass {
protected class inner implements IIGetResult {
@Override
String getResult(){ return "result";}
}
public static void main(String[] args) {
System.out.println("practice start");
}
}
Run Code Online (Sandbox Code Playgroud)
在最后一步,我使用命令编译两个 java 类:
# javac a/ .java b/ .java
并得到以下错误:
./a/IgetResult.java:1: duplicate class: IIGetResult
interface IIGetResult {
^
./a/IgetResult.java:4: duplicate class: IgetResult
public class IgetResult {
^
b/PracticeClass.java:1: cannot …Run Code Online (Sandbox Code Playgroud) 首先,我将绿色设置为View mIcon的背景,
View mIcon = findViewById(R.id.xxx);
GradientDrawable gdraw = (GradientDrawable) mContext.getResources().getDrawable(R.drawable.roundbtn_white_normal);
gdraw.setColor(Color.GREEN);
mIcon.setBackgroundDrawable(gdraw);
Run Code Online (Sandbox Code Playgroud)
然后,我不知道如何从这个View的背景中获取颜色......没有getColor()函数......
public static Country getCountryFromLocation(Context cxt, List<Country> countryList, Location location, int maxAddress) {
if (location == null || countryList == null || countryList.isEmpty()) {
Log.d("ooo", "location == null || countryList == null || countryList.isEmpty()");
return null;
}
double longitude = location.getLongitude();
double latitude = location.getLatitude();
Geocoder coder = new Geocoder(cxt);
try {
List<Address> addressList = coder.getFromLocation(latitude, longitude, maxAddress);
for (Address address : addressList) {
String curCountryCode = address.getCountryCode();
Log.d("ooo", "address " + address.toString());
if (TextUtils.isEmpty(curCountryCode)) {
continue;
}
for (Country country …Run Code Online (Sandbox Code Playgroud) android google-maps country-codes geolocation mobile-country-code
我正在学习linux系统编程,O'reilly.它说:"一个常见的错误是将缓冲区声明为在流关闭之前结束的范围内的自动变量.特别是,注意不要在main()本地提供缓冲区,然后无法显式关闭流. "
然后它显示了一个错误的代码示例:
#include <stdio.h>
int main()
{
char buf[BUFSIZ];
/*set stdin to block-buffered with a BUFSIZ buffer*/
setvbuf(stdout,buf,_IOFBF,BUFSIZ);
printf("Arr!\n");
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我编译并执行代码..并没有真正理解这种代码会导致什么...请帮助我理解这个概念,谢谢大家.