我正在尝试使用API Picasso保存图像.为了做到这一点,我正在努力Target保存,但我不能做这项工作.
我怎么能这样做?
试
//save image
public static void imageDownload(Context ctx){
Picasso.with(ctx)
.load("http://blog.concretesolutions.com.br/wp-content/uploads/2015/04/Android1.png")
.into(getTarget("http://blog.concretesolutions.com.br/wp-content/uploads/2015/04/Android1.png"));
}
//target to save
private static Target getTarget(final String url){
Target target = new Target(){
@Override
public void onBitmapLoaded(final Bitmap bitmap, Picasso.LoadedFrom from) {
new Thread(new Runnable() {
@Override
public void run() {
//Log.i("PRODUTOS_FOLDER", CreateAppFolder.getProdutosFolder());
File file = new File(Environment.getExternalStorageDirectory() + url);
try {
file.createNewFile();
FileOutputStream ostream = new FileOutputStream(file);
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, ostream);
ostream.flush();
ostream.close();
}
catch (Exception e) {
e.printStackTrace();
}
}
}).start(); …Run Code Online (Sandbox Code Playgroud) 我正在寻找一种解决方案来定义在所有请求中使用的唯一标头.今天我用@Header每个请求都传似参数,但我想只定义在所有请求工作没有需要通像一个参数,例如固定在我的请求,这头头@GET和@POST
今天我用这个.请注意,@GET我需要的每个请求都将Header定义为参数.
//interface
@GET("/json.php")
void getUsuarioLogin(
@Header("Authorization") String token,
@QueryMap Map<String, String> params,
Callback<JsonElement> response
);
//interface
@GET("/json.php")
void addUsuario(
@Header("Authorization") String token,
@QueryMap Map<String, String> params,
Callback<JsonElement> response
);
//using
public void getUsuarioLogin(){
Map<String, String> params = new HashMap<String, String>();
params.put("email", "me@mydomain.com");
params.put("senha", ConvertStringToMD5.getMD5("mypassword"));
RestAdapter adapter = new RestAdapter.Builder()
.setLogLevel(RestAdapter.LogLevel.FULL)
.setEndpoint(WebServiceURL.getBaseWebServiceURL())
.build();
UsuarioListener listener = adapter.create(UsuarioListener.class);
listener.getUsuarioLogin(
//header
"Basic " + BasicAuthenticationRest.getBasicAuthentication(),
params,
new Callback<JsonElement>() {
@Override
public void success(JsonElement arg0, Response …Run Code Online (Sandbox Code Playgroud) 我需要发送一个json到我的webservice,json是:
{
"Sala": {
"usuario": "%@",
"adversario": "%@",
"atualizacao": "%@",
"device": "%@",
"device_tipo": "ios"
}
}
Run Code Online (Sandbox Code Playgroud)
.我正在尝试使用Retrofit API 1.8.当我尝试发送帖子时抛出一个异常.
例外:
com.google.gson.JsonSyntaxException: com.google.gson.stream.MalformedJsonException: Use JsonReader.setLenient(true) to accept malformed JSON at line 1 column 7 path $
Run Code Online (Sandbox Code Playgroud)
我正在尝试这个
public class ChatObject {
private String usuario;
private String adversario;
private String atualizacao;
private String email;
private String device;
private String device_tipo;
Run Code Online (Sandbox Code Playgroud)
改造界面
@POST("/WsChat/interacao.json")
public void onReceiveMessage(@Body ChatObject obj,
Callback<JsonElement> response);
Run Code Online (Sandbox Code Playgroud)
器物
public void receiveMessage(){
///{\"Sala\":{\"usuario\":\"%@\",\"adversario\":\"%@\",\"atualizacao\":\"%@\",\"device\":\"%@\",\"device_tipo\":\"ios\"}}
ChatObject chatObject = new ChatObject(BatalhaConfigs.USUARIO_EMAIL,
BatalhaConfigs.ADVERSARIO_EMAIL,
new Date().toString(), …Run Code Online (Sandbox Code Playgroud) 我正在尝试在CustomDrawerLayout中使用ActionBarDrawerToggle.当我尝试导入时,import android.support.v4.app.ActionBarDrawerToggle;它已被弃用.当我尝试导入时import android.support.v7.app.ActionBarDrawerToggle;,构造函数不接受五个参数,并且ActionBar中的图标未更改.我的问题是我应该使用v4弃用还是v7有四个参数?
这里.
V4
/**v4 works with 5 arguments in constructor and change icon ActionBar but it's deprecated*/
import android.support.v4.app.ActionBarDrawerToggle;
private ActionBarDrawerToggle tg;
//ActionBarDrawerToggle deprecated
tg = new ActionBarDrawerToggle(this, dl, R.drawable.ic_launcher, R.string.drawer_open, R.string.drawer_close){
public void onDrawerClosed(View view) {
ab.setTitle(tl);
supportInvalidateOptionsMenu();
}
public void onDrawerOpened(View view) {
ab.setTitle(tlf);
supportInvalidateOptionsMenu();
}
};
Run Code Online (Sandbox Code Playgroud)
V7
/**v7 works with 4 arguments in constructor and not change icon of ActionBar*/
import android.support.v7.app.ActionBarDrawerToggle;
private ActionBarDrawerToggle tg;
tg = new ActionBarDrawerToggle(this, dl, R.drawable.ic_launcher, …Run Code Online (Sandbox Code Playgroud) 我正在尝试将JSONArray反序列化为List.要做到这一点,我正在尝试使用Gson,但我无法理解为什么不起作用,JSON的所有值都为null.
我怎么能这样做?
JSON
{ "result" : [
{ "Noticia" : {
"created" : "2015-08-20 19:58:49",
"descricao" : "tttttt",
"id" : "19",
"image" : null,
"titulo" : "ddddd",
"usuario" : "FERNANDO PAIVA"
} },
{ "Noticia" : {
"created" : "2015-08-20 19:59:57",
"descricao" : "hhhhhhhh",
"id" : "20",
"image" : "logo.png",
"titulo" : "TITULO DA NOTICIA",
"usuario" : "FERNANDO PAIVA"
} }
] }
Run Code Online (Sandbox Code Playgroud)
反序列化
List<Noticia> lista = new ArrayList<Noticia>();
Gson gson = new Gson();
JSONArray array = obj.getJSONArray("result");
Type listType …Run Code Online (Sandbox Code Playgroud) 我正在尝试验证文件类型的HttpPostedFileBase属性以检查文件类型,但我不能这样做,因为验证正在通过.我怎么能这样做?
试
模型
public class EmpresaModel{
[Required(ErrorMessage="Choose a file .JPG, .JPEG or .PNG file")]
[ValidateFile(ErrorMessage = "Please select a .JPG, .JPEG or .PNG file")]
public HttpPostedFileBase imagem { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
HTML
<div class="form-group">
<label for="@Html.IdFor(model => model.imagem)" class="cols-sm-2 control-label">Escolha a imagem <img src="~/Imagens/required.png" height="6" width="6"></label>
@Html.TextBoxFor(model => Model.imagem, new { Class = "form-control", placeholder = "Informe a imagem", type = "file" })
@Html.ValidationMessageFor(model => Model.imagem)
</div>
Run Code Online (Sandbox Code Playgroud)
ValidateFileAttribute
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Drawing;
using …Run Code Online (Sandbox Code Playgroud) 我正在尝试Thread在我的项目中发送电子邮件.当我点击a时Button,a Thread启动并ProgressBar显示a.所有邮件一发送,ProgressBar就不会消失.
这是我的代码:
Button btnSendMail = new Button("Mail");
btnSendMail.addClickListener(this);
@Override
public void buttonClick(ClickEvent event) {
if(event.getButton() == btnSendMail){
sendMail();
}
}
}
private void sendMail(){
List<String> list = new ArrayList<String>();
list.add("mymail@domain.com");
list.add("metoyou@domain.com");
list.add("thisismymail@domain.com");
new Thread(){
public void run(){
while(!isInterrupt()){
progressbar.setVisible(true);
for(String send : list){
new SendMailClass(send); //javamail class
}
progressbar.setVisible(false);
interrupt();
}
}.start();
}
Run Code Online (Sandbox Code Playgroud)
如何控制ProgressBar分离的可见性Thread?
我正在尝试更改OptionGroup以显示Horizontal.在vaadin7书中有一个用CSS改变的例子,但不起作用.
我正在尝试这个.
//styles.scss
/** optiongroup */
/* Lay the options horizontally */
.v-select-optiongroup-horizontal .v-select-option {
display: inline-block;
}
/* Avoid wrapping if the layout is too tight */
.v-select-optiongroup-horizontal {
white-space: nowrap;
}
/* Some extra spacing is needed */
.v-select-optiongroup-horizontal .v-select-option.v-radiobutton {
padding-right: 10px;
}
Run Code Online (Sandbox Code Playgroud)
//Here the OptionGroup
OptionGroup optionGroup = new OptionGroup();
optionGroup.addItem("Usuário");
optionGroup.addItem("Representante");
Run Code Online (Sandbox Code Playgroud)
任何的想法?
我正在尝试在我的应用程序中使用BeanFieldGroup创建一个ComboBox组件,但仍然无法做到这一点.我尝试先创建一个组合框,然后在buildAndBind中添加这个组合框,但也不起作用.
我正在尝试这个:
/** person's bean */
@Entity
public class Person{
@Id
@GeneratedValue
private Integer id;
@NotNull
@NotEmpty
@Size(min=5, max=50, message="insert first name")
private String firstName;
@NotNull
@NotEmpty
@Email private String email;
//female or male
private String gender;
//get and set
}
/** app */
public class PersonView extends CustomComponent{
private final BeanFieldGroup<Person> binder = new BeanFieldGroup<Person>(Person.class);
private Person bean = new Person();
private ComboBox gender;
public PersonView(){
VerticalLayout vLayout = new VerticalLayout();
Field<?> field = null;
field = binder.buildAndBind("Gender", "gender", …Run Code Online (Sandbox Code Playgroud) 我有一个图像,我想使用 Volley 库将这个图像上传到我的网络服务,问题是我正在寻找如何去做但仍然没有找到。
我找到了这个,但对我不起作用:http : //develop-for-android.blogspot.com.br/2014/01/using-volley-in-your-application.html
我怎样才能做到这一点 ?
我正在尝试这个。
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == RESULT_LOAD_IMAGE && resultCode == RESULT_OK && null != data) {
Uri selectedImage = data.getData();
String[] filePathColumn = { MediaStore.Images.Media.DATA };
Cursor cursor = getContentResolver().query(selectedImage,
filePathColumn, null, null, null);
cursor.moveToFirst();
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
fotoPerfil = cursor.getString(columnIndex);
cursor.close();
ImageView imageView = (ImageView) findViewById(R.id.imgView);
imageView.setImageBitmap(BitmapFactory.decodeFile(picturePath));
}
}
UploadoImageToServer upload = new UploadoImageToServer();
ApplicationController app = new …Run Code Online (Sandbox Code Playgroud) android ×5
java ×5
json ×3
vaadin7 ×3
gson ×2
retrofit ×2
frameworks ×1
http-headers ×1
jakarta-mail ×1
picasso ×1
progress-bar ×1
rest ×1
vaadin ×1