我需要咨询这个项目 [英] I need advice for this project

查看:127
本文介绍了我需要咨询这个项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  1. 为S JPEG图像。
  2. 显示一个按钮上,其允许用户将图像设置到它们的壁纸的图像。
  3. 自动调整图像大小,以用户特定的Andr​​oid手机的显示尺寸。
  4. 如果删除该应用程序卸载墙纸。

我可以做的步骤1和2 pretty的方便我只是坚持与其他两个步骤,任何人都可以点我在正确的方向。 这里是code到目前为止

 公共类MainActivity扩展活动实现OnClickListener {

    ImageView的IV;
    按钮B;
    我的意图;
    BMP位图;
    @覆盖
    保护无效的onCreate(包savedInstanceState){
        super.onCreate(savedInstanceState);
        的setContentView(R.layout.activity_main);
        初始化();
        InputStream的是= getResources()openRawResource(R.drawable.image)。
        BMP = BitmapFactory.de codeStream(是);
    }
    私人无效初始化(){
        IV =(ImageView的)findViewById(R.id.ivReturnedPic);
        B =(按钮)findViewById(R.id.bSetWallpaper);
        b.setOnClickListener(本);
    }
    @覆盖
    公共布尔onCreateOptionsMenu(功能菜单){
        //充气菜单;这增加了项目操作栏,如果它是present。
        。getMenuInflater()膨胀(R.menu.main,菜单);
        返回true;
    }

    @覆盖
    公共无效的onClick(视图v){
        // TODO自动生成方法存根
        开关(v.getId()){
        案例R.id.bSetWallpaper:
            尝试 {
                getApplicationContext()setWallpaper(BMP)。
            }赶上(IOException异常E){

                e.printStackTrace();
            }
            打破;
        }
    }

}
 

解决方案

设置壁纸所需的屏幕尺寸

  WallpaperManager myWallpaperManager = WallpaperManager.getInstance(getApplication());
INT高= myWallpaperManager.getDesiredMinimumHeight();
INT宽度= myWallpaperManager.getDesiredMinimumWidth();

尝试 {
    myWallpaperManager.setBitmap(Bitmap.createScaledBitmap(setAs,宽度,高度,真));
}赶上(最终IOException异常E){
    Toast.makeText(getApplication(),错误设置壁纸,Toast.LENGTH_SHORT).show();
}
 

和第四个问题,请参阅这个

  1. Shows s JPEG image.
  2. Display a button over the image that allows the user to set the image to their wallpaper.
  3. Auto resizes the image to the users specific Android phone display size.
  4. Removes the wallpaper if the app is uninstalled.

I can do step 1 and 2 pretty easy i'm just stuck with the other two steps can anyone point me in the right direction. here is the code so far

public class MainActivity extends Activity implements OnClickListener {

    ImageView iv;
    Button b;
    Intent i;
    Bitmap bmp;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initialize();
        InputStream is = getResources().openRawResource(R.drawable.image);
        bmp = BitmapFactory.decodeStream(is);
    }
    private void initialize(){
        iv = (ImageView) findViewById(R.id.ivReturnedPic);
        b = (Button) findViewById(R.id.bSetWallpaper);
        b.setOnClickListener(this);
    }
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

    @Override
    public void onClick(View v) {
        // TODO Auto-generated method stub
        switch(v.getId()){
        case R.id.bSetWallpaper:
            try {
                getApplicationContext().setWallpaper(bmp);
            } catch (IOException e) {

                e.printStackTrace();
            }
            break;
        }
    }

}

解决方案

to set the wallpaper on the desired screen size

WallpaperManager myWallpaperManager = WallpaperManager.getInstance(getApplication());
int height = myWallpaperManager.getDesiredMinimumHeight();
int width = myWallpaperManager.getDesiredMinimumWidth();

try {
    myWallpaperManager.setBitmap(Bitmap.createScaledBitmap(setAs, width , height , true));   
} catch (final IOException e) {
    Toast.makeText(getApplication(), "Error setting wallpaper", Toast.LENGTH_SHORT).show();
}

and for the fourth question please refer to this

这篇关于我需要咨询这个项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆