//他同性恋,我有壁纸的应用,它工作正常但不在android 8
(oreo),当我点击按钮将位图设置为壁纸时,我发现她设置了缩放,我怎么样可以避免这种变焦?
public class ViewWallpaper extends AppCompatActivity {
ImageView imageView;
FloatingActionButton backbtn;
FloatingActionMenu mainFloating;
com.github.clans.fab.FloatingActionButton fbShare;
//Room Database
CompositeDisposable compositeDisposable;
RecentRepository recentRepository;
//checking permissions
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
switch (requestCode)
{
case Common.PERMISSION_REQUEST_CODE:
{
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED)
{
AlertDialog dialog = new SpotsDialog(ViewWallpaper.this);
dialog.show();
dialog.setMessage("Please waiting ....");
String filename = UUID.randomUUID().toString()+".png";
Picasso.with(getBaseContext())
.load(Common.select_background.getImageUrl())
.into(new SaveImageHelper(getBaseContext(),
dialog,
getApplicationContext().getContentResolver(),
filename,
"Unty Live wallpaper"));//probleme here
}
else
Toast.makeText(this,"You need to accept this permission to download images",Toast.LENGTH_SHORT).show();
}
}
}
//Method to set Bitmap as wallpaper
private Target target = new Target(){
@Override
public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
WallpaperManager wallpaperManager = WallpaperManager.getInstance(getApplicationContext());
try {
wallpaperManager.setBitmap(bitmap);
StyleableToast.makeText(ViewWallpaper.this,"Wallpaper Set Successfully",R.style.SetWallpaper).show();
} catch (IOException e) {
e.printStackTrace();
}
}
@Override
public void onBitmapFailed(Drawable errorDrawable) {
}
@Override
public void onPrepareLoad(Drawable placeHolderDrawable) {
}
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_view_wallpaper);
//Init RoomDatabase
compositeDisposable = new CompositeDisposable();
LocalDatabase database = LocalDatabase.getInstance(this);
recentRepository = RecentRepository.getInstance(RecentsDataSource.getInstance(database.recentsDAO()));
imageView =(ImageView)findViewById(R.id.imageThumb);
Picasso.with(this)
.load(Common.select_background.getImageUrl())
.into(imageView);
mainFloating =(FloatingActionMenu)findViewById(R.id.menu);
fbShare = (com.github.clans.fab.FloatingActionButton)findViewById(R.id.fb_share);
fbShare.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//Create callback
shareDialog.registerCallback(callbackManager, new FacebookCallback<Sharer.Result>() {
@Override
public void onSuccess(Sharer.Result result) {
Toast.makeText(ViewWallpaper.this, "Share successfull !", Toast.LENGTH_SHORT).show();
}
@Override
public void onCancel() {
Toast.makeText(ViewWallpaper.this, "Share Cancelled !", Toast.LENGTH_SHORT).show();
}
@Override
public void onError(FacebookException error) {
Toast.makeText(ViewWallpaper.this, ""+error.getMessage(), Toast.LENGTH_SHORT).show();
}
});
//We will fetch photo from link and convert to bitmap
Picasso.with(getBaseContext())
.load(Common.select_background.getImageUrl())
.into(facebookConvertBitmap);
}
});
floatingActionButton = (com.github.clans.fab.FloatingActionButton)findViewById(R.id.fabWallpaper);
floatingActionButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Picasso.with(getBaseContext())
.load(Common.select_background.getImageUrl())
.into(target);
}
});
//View count
increaseViewCount();
}
@Override
protected void onDestroy() {
Picasso.with(this).cancelRequest(target);
compositeDisposable.clear();
super.onDestroy();
}
@Override
public boolean onOptionsItemSelected(MenuItem item){
if(item.getItemId()== android.R.id.home)
finish(); // to close activity when click back btn
return super.onOptionsItemSelected(item);
}
}