我试图让用户触摸图像,然后基本上一个圆形放大镜将显示将允许用户更好地选择图像上的某个区域.当用户释放触摸时,放大的部分将消失.这用于几个照片编辑应用程序,我正在尝试实现我自己的版本.我下面的代码确实放大了图像视图的圆形部分,但是一旦我松开手指就不会删除或清除缩放.我目前设置一个位图到画布使用canvas = new Canvas(bitMap);然后设置imageview takenPhoto.setImageBitmap(bitMap); 我不知道我是否正确的方式.onTouch代码如下:
zoomPos = new PointF(0,0);
takenPhoto.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
int action = event.getAction();
switch (action) {
case MotionEvent.ACTION_DOWN:
zoomPos.x = event.getX();
zoomPos.y = event.getY();
matrix.reset();
matrix.postScale(2f, 2f, zoomPos.x, zoomPos.y);
shader.setLocalMatrix(matrix);
canvas.drawCircle(zoomPos.x, zoomPos.y, 20, shaderPaint);
takenPhoto.invalidate();
break;
case MotionEvent.ACTION_MOVE:
zoomPos.x = event.getX();
zoomPos.y = event.getY();
matrix.reset();
matrix.postScale(2f, 2f, zoomPos.x, zoomPos.y);
canvas.drawCircle(zoomPos.x, zoomPos.y, 20, shaderPaint);
takenPhoto.invalidate();
break;
case MotionEvent.ACTION_UP:
//clear zoom here?
break;
case MotionEvent.ACTION_CANCEL:
break;
default:
break; …Run Code Online (Sandbox Code Playgroud) android image-zoom touch-event android-imageview android-canvas
我在.MP4格式的网站上有一个视频文件,我希望用户能够通过点击链接将视频下载到他们的SD卡.是否有捷径可寻.我目前有这个代码,但它不起作用......不确定我做错了什么.谢谢你的帮助!
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;
import org.apache.http.util.ByteArrayBuffer;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
public class VideoManager extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);}
private final String PATH = "/sdcard/download/"; //put the downloaded file here
public void DownloadFromUrl(String VideoURL, String fileName) { //this is the downloader method
try {
URL url = new URL("http://www.ericmoyer.com/episode1.mp4"); //you can write here any …Run Code Online (Sandbox Code Playgroud) 是否可以将活动作为服务实施?我的活动是语音识别活动.我希望在应用程序的后台运行活动,不断检查语音,当用户说出命令时,它会识别它,然后执行操作.我的问题是......是否可以这样做,如果是这样,后台服务如何通知当前活动或应用程序?之前有一篇帖子没有明确的答案......感谢您的任何意见或帮助.以下是来自另一个StackOverflow帖子的语音活动:
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.speech.RecognitionListener;
import android.speech.RecognizerIntent;
import android.speech.SpeechRecognizer;
import android.widget.Button;
import android.widget.TextView;
import java.util.ArrayList;
import android.util.Log;
public class voiceRecognitionTest extends Activity implements OnClickListener
{
private TextView mText;
private SpeechRecognizer sr;
private static final String TAG = "MyStt3Activity";
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button speakButton = (Button) findViewById(R.id.btn_speak);
mText = (TextView) findViewById(R.id.textView1);
speakButton.setOnClickListener(this);
sr = SpeechRecognizer.createSpeechRecognizer(this);
sr.setRecognitionListener(new listener());
}
class listener implements RecognitionListener
{
public void onReadyForSpeech(Bundle params)
{ …Run Code Online (Sandbox Code Playgroud) 我一直在搜索关于彼得森算法的信息,但是已经遇到过参考文献,说明它不满足饥饿但只是死锁.这是真的?若有,有人可以详细说明为什么不呢?
彼得森的算法:
flag[0] = 0;
flag[1] = 0;
turn;
P0: flag[0] = 1;
turn = 1;
while (flag[1] == 1 && turn == 1)
{
// busy wait
}
// critical section
...
// end of critical section
flag[0] = 0;
P1: flag[1] = 1;
turn = 0;
while (flag[0] == 1 && turn == 0)
{
// busy wait
}
// critical section
...
// end of critical section
flag[1] = 0;
Run Code Online (Sandbox Code Playgroud)
该算法使用两个变量,flag和turn.标志值为1表示进程想要进入临界区.变量turn保存转过程的ID.如果P1不想进入其临界区,或者如果P1通过将转到0设置为P0优先级,则允许进程P0进入临界区.
我使用GridLayoutManager使用Glide 3.6 + RecyclerView在我们的应用程序中看到了很长的图像加载时间.图像大约为20kb-40kb.似乎滑动将所有请求排队,导致图像在开始向下滚动列表后需要花费很长时间才能加载.我已经附加了GenericRequest类的日志.
V/GenericRequest? finished setup for calling load in 0.170291 this: 249721749
V/GenericRequest? finished onSizeReady in 0.36724999999999997 this: 249721749
V/GenericRequest? finished run method in 0.763083 this: 249721749
V/GenericRequest? Got onSizeReady in 0.041249999999999995 this: 991315424
V/GenericRequest? finished setup for calling load in 0.15479199999999999 this: 991315424
V/GenericRequest? finished onSizeReady in 0.30008399999999996 this: 991315424
V/GenericRequest? finished run method in 0.499959 this: 991315424
V/GenericRequest? Got onSizeReady in 0.060584 this: 1029510845
V/GenericRequest? finished setup for calling load in 0.200625 this: 1029510845
V/GenericRequest? finished …Run Code Online (Sandbox Code Playgroud) 假设用户已经在他/她的手机上安装了应用程序,我想知道是否可以通过向他们发送短信来打开某人手机上的Android应用程序.有点像我的Droid应用程序在哪里?我可以像发短信一样发送"OPEN",后台服务会认出这个并打开应用程序吗?这是可能的,如果是这样的例子吗?谢谢
我试图在另一个按钮上叠加一种按钮.原因是我想向用户解释某些按钮会做什么.
例如: 将有一个按钮.在右上角或该按钮中的任何一个都会有一个问号.当用户按下问号时,它将解释该按钮的作用.
我正在尝试解析MongoDB云服务器中的数据.我从服务器返回的JSON数据如下:
[
{
"_id": {
"$oid": "4e78eb48737d445c00c8826b"
},
"message": "cmon",
"type": 1,
"loc": {
"longitude": -75.65530921666667,
"latitude": 41.407904566666666
},
"title": "test"
},
{
"_id": {
"$oid": "4e7923cb737d445c00c88289"
},
"message": "yo",
"type": 4,
"loc": {
"longitude": -75.65541383333333,
"latitude": 41.407908883333334
},
"title": "wtf"
},
{
"_id": {
"$oid": "4e79474f737d445c00c882b2"
},
"message": "hxnxjx",
"type": 4,
"loc": {
"longitude": -75.65555572509766,
"latitude": 41.41263961791992
},
"title": "test cell"
}
Run Code Online (Sandbox Code Playgroud)
]
我遇到的问题是返回的数据结构不包含JSON对象数组的名称.返回的每个对象都是"帖子".但是如果没有JSON对象数组的名称,我如何使用GSON解析它.我想将这些"帖子"放入Post类型的ArrayList中.
在过去的几个月里,我一直在使用Dagger/Retrofit,并且已经看到了为api实现ApiModule类的常见模式.这些ApiModules通常看起来像这样:
@Provides @Singleton Client provideClient(OkHttpClient client) {
return new OkClient(client);
}
@Provides @Singleton Endpoint provideEndpoint() {
return "release".equalsIgnoreCase(BuildConfig.BUILD_TYPE)
? Endpoints.newFixedEndpoint(PRODUCTION_URL, "Foo Production Url")
: Endpoints.newFixedEndpoint(STAGING_URL, "Foo Staging Url");
}
@Provides @Singleton Converter provideConverter(Gson gson) {
return new GsonConverter(gson);
}
@Provides @Singleton RestAdapter provideRestAdapter(Endpoint endpoint, Client client,
Converter converter) {
return new RestAdapter.Builder()
.setClient(client)
.setEndpoint(endpoint)
.setConverter(converter)
.setLogLevel(BuildConfig.DEBUG
? RestAdapter.LogLevel.FULL
: RestAdapter.LogLevel.NONE)
.build();
}
@Provides @Singleton FooApi provideFooApi(RestAdapter restAdapter) {
return restAdapter.create(FooApi.class);
}
Run Code Online (Sandbox Code Playgroud)
但要清理这个,为什么不这样做:
@Provides @Singleton Client provideClient(OkHttpClient client) {
return new …Run Code Online (Sandbox Code Playgroud) 如何使用alarm()或sleep每1000毫秒执行一次函数?如果函数在1000毫秒内没有执行或完成,我希望程序执行其他操作.
编辑:添加了伪代码
while(true) {
alarm(1000);
execute function;
sleep(1000);
alarm(0);
}
Run Code Online (Sandbox Code Playgroud)
现在,如果警报(1000)信号SIGALRM是我可以调用其他功能的地方吗?我是这种东西的新手,所以甚至不确定我是否正确使用它.