学习中1(来源于sdk大全)

 

package com.receiver.test2;

 

import android.app.Activity;

import android.app.Dialog;

import android.content.BroadcastReceiver;

import android.content.Context;

import android.content.Intent;

import android.content.IntentFilter;

import android.os.Bundle;

import android.view.View;

import android.view.Window;

import android.view.WindowManager;

import android.widget.Button;

import android.widget.TextView;

 

public class ReceiverTest extends Activity {

private int intLevel;

private int intScale;

private Button mButton01;

 

 

    private BroadcastReceiver mBatInfoReceiver = new BroadcastReceiver() {

 

@Override

public void onReceive(Context context, Intent intent) {

// TODO Auto-generated method stub

String action = intent.getAction();

if(Intent.ACTION_BATTERY_CHANGED.equals(action)) {

intLevel = intent.getIntExtra("level", 0);

intScale = intent.getIntExtra("scale", 100);

onBatteryInfoReceiver(intLevel,intScale);

}

}

    

    };

    /** Called when the activity is first created. */

    @Override

    public void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        setContentView(R.layout.main);

        mButton01 = (Button)findViewById(R.id.myButton1);

 

        mButton01.setOnClickListener(new Button.OnClickListener(){

 

@Override

public void onClick(View arg0) {

// TODO Auto-generated method stub

registerReceiver(mBatInfoReceiver, new IntentFilter(Intent.ACTION_BATTERY_CHANGED));

}

        

        });

    }

 

    public void onBatteryInfoReceiver(int intLevel, int intScale) {

     final Dialog d = new Dialog(ReceiverTest.this);

     d.setContentView(R.layout.mydialog);

    

     Window window = d.getWindow();

     window.setFlags(WindowManager.LayoutParams.FLAG_BLUR_BEHIND, WindowManager.LayoutParams.FLAG_BLUR_BEHIND);

    

     TextView mTextView02 = (TextView)d.findViewById(R.id.myTextView02);

     mTextView02.setText(getResources().getText(R.string.str_dialog_body)+String.valueOf(intLevel * 100/intScale) + "%");

    

     Button mButton02 = (Button)d.findViewById(R.id.myButton2);

     mButton02.setOnClickListener(new Button.OnClickListener() {

 

@Override

public void onClick(View v) {

// TODO Auto-generated method stub

unregisterReceiver(mBatInfoReceiver);

d.dismiss();

}

    

     });

     d.show();

    }

}

 

 

main.xml

 

 

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

    android:orientation="vertical"

    android:layout_width="fill_parent"

    android:layout_height="fill_parent"

    >

<TextView  

    android:layout_width="wrap_content" 

    android:layout_height="wrap_content" 

    android:text="@string/how_to_get_battery"

    />

    <Button

     android:id="@+id/myButton1"

     android:layout_width="wrap_content"

     android:layout_height="wrap_content" 

     android:text="@string/press_me"

    />

</LinearLayout>

 

 

 

mydialog.xml

 

 

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

    android:orientation="vertical"

    android:layout_width="fill_parent"

    android:layout_height="fill_parent"

    >

<TextView  

android:id="@+id/myTextView02"

    android:layout_width="wrap_content" 

    android:layout_height="wrap_content" 

    android:text="@string/hello"

    />

    <Button

     android:id="@+id/myButton2"

     android:layout_width="wrap_content"

     android:layout_height="wrap_content" 

     android:text="@string/return_back"

    />

</LinearLayout>

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string name="hello">Hello World, ReceiverTest!</string>
    <string name="app_name">ReceiverTest2</string>
    <string name="str_dialog_body">电量计算:</string>
    <string name="how_to_get_battery">如何获取电池电量?</string>
    <string name="press_me">点击我获得电量</string>
    <string name="return_back">返回</string>
    
</resources>

 

manifest.xmlbu

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
OpenStack SDK是用于编写OpenStack API客户端的软件开发工具包,它提供了一组Python库和工具,用于编写和管理OpenStack云基础架构服务。学习OpenStack SDK可以帮助您更好地了解如何使用OpenStack API进行云资源管理。 以下是学习OpenStack SDK的建议步骤: 1. 熟悉OpenStack基础知识:在开始学习OpenStack SDK之前,您需要了解OpenStack的基础知识,例如OpenStack组件和架构、OpenStack API等。 2. 安装OpenStack SDK:在学习OpenStack SDK之前,您需要安装OpenStack SDK。您可以使用pip或者从源代码安装。 3. 熟悉OpenStack SDK文档:OpenStack SDK提供了详细的文档,包括API参考、示例和教程等。熟悉这些文档可以帮助您更好地了解OpenStack SDK的使用。 4. 编写OpenStack SDK应用程序:使用OpenStack SDK,您可以编写Python应用程序,用于创建、更新和删除OpenStack云资源。为了使学习更加容易,可以从一些简单的应用程序开始,例如创建虚拟机或者存储卷。 5. 学习OpenStack SDK的高级特性:OpenStack SDK还提供了一些高级特性,例如任务管理、错误处理和异步操作等。学习这些特性可以让您更好地管理和监视OpenStack云资源。 6. 参与OpenStack社区:OpenStack社区提供了许多资源和工具,帮助您更好地了解和使用OpenStack。参加OpenStack社区活动,例如邮件列表、IRC和会议,可以帮助您更好地了解OpenStack SDK和其他OpenStack技术。 总的来说,学习OpenStack SDK需要一定的时间和精力,但是它可以帮助您更好地管理和监视OpenStack云资源。通过熟悉OpenStack SDK的基础知识、阅读文档、编写应用程序以及参与OpenStack社区活动,您可以成为一名优秀的OpenStack开发者。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值