本页文章导读:
▪擒获来电事件 捕获来电事件
public class YourApplicationPhoneStateListener extends PhoneStateListener
{
@Override
public void onCallStateChanged (int state, String incomingNumber)
{
/* state can be any of the following:
Te.........
▪ linearlayout承袭扩展篇 linearlayout继承扩展篇
前面写了一个一个linearLayout,只不过那个只是继承了一个属性,在群聊的时候有人问 想在扩展的时候添加几个按钮,作为一个封装用,于是我就试了一下效果还不错:我.........
▪ 在sd卡顶用程序创建目录 在sd卡中用程序创建目录
如果要想在sd卡中的一个子目录下创造文件FileOutputStream fos = new FileOutputStream("/sdcard/Wallpaper/"+fileName); 这是错误的,需要
// create a File object for the parent directory
File wallpa.........
[1]擒获来电事件
来源: 互联网 发布时间: 2014-02-18
捕获来电事件
public class YourApplicationPhoneStateListener extends PhoneStateListener
{
@Override
public void onCallStateChanged (int state, String incomingNumber)
{
/* state can be any of the following:
TelephonyManager.CALL_STATE_IDLE
TelephonyManager.CALL_STATE_RINGING
TelephonyManager.CALL_STATE_OFFHOOK
*/
}
}
TelephonyManager.listen(new YourApplicationPhoneStateListener());
public class PhoneStateBroadcastReceiver extends BroadcastReceiver
{
@Override
public void onReceive(Context context, Intent intent) {
Bundle bundle = intent.getExtras();
int state = bundle.getInt(TelephonyManager.EXTRA_STATE);
if (state == TelephonyManager.CALL_STATE_RINGING) {
String phoneNumber =
bundle.getString(TelephonyManager.EXTRA_INCOMING_NUMBER );
}
}
}
<receiver android:name="package.to.PhoneStateBroadcastReceiver" android:enabled="true">
<intent-filter>
<action android:name="android.telephony.TelephonyManager.ACTION_PHONE_STATE_CHANGED" />
</intent-filter>
</receiver>
[2] linearlayout承袭扩展篇
来源: 互联网 发布时间: 2014-02-18
linearlayout继承扩展篇
前面写了一个一个linearLayout,只不过那个只是继承了一个属性,在群聊的时候有人问 想在扩展的时候添加几个按钮,作为一个封装用,于是我就试了一下效果还不错:我做了一个人工的进度条 可以加可以减
主函数很简单就一句话setContentView(R.layout.main);
相比大家都明白所有的东西 都在main.xml中
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res/co.android.widget" android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="wrap_content" android:paddingTop="5px" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Meter:" /> <com.commonsware.android.widget.Meter android:id="@+id/meter" android:layout_width="fill_parent" android:layout_height="wrap_content" app:max="100" app:incr="1" app:decr="5" /> </LinearLayout>。红色部分是我自己加的属性啊 ,一定注意包名co.android.widget
通过上面可以看到 没有prossbar,也没有加喝减的按钮啊,其实想想就知道了全在co.android.widget.Meter这里面。
那么就来看看Meter里面有啥:
public class Meter extends LinearLayout {
private int max=100;
private int incrAmount=1;
private int decrAmount=-1;
private ProgressBar bar=null;
private View.OnClickListener onIncr=null;
private View.OnClickListener onDecr=null;
public Meter(final Context ctxt, AttributeSet attrs) {
super(ctxt, attrs);
this.setOrientation(HORIZONTAL);
TypedArray a=ctxt.obtainStyledAttributes(attrs,R.styleable.Meter,0, 0);
max=a.getInt(R.styleable.Meter_max, 100);
incrAmount=a.getInt(R.styleable.Meter_incr, 1);
decrAmount=-1*a.getInt(R.styleable.Meter_decr, 1);
a.recycle();
}
/*
public void setOnIncrListener(View.OnClickListener onIncr) {
this.onIncr=onIncr;
}
public void setOnDecrListener(View.OnClickListener onDecr) {
this.onDecr=onDecr;
}
public void setProgress(int progress) {
bar.setProgress(progress);
}
public void setMax(int max) {
this.max=max;
bar.setMax(max);
}
*/
@Override
protected void onFinishInflate() {
super.onFinishInflate();
((Activity)getContext()).getLayoutInflater().inflate(R.layout.meter, this);
bar=(ProgressBar)findViewById(R.id.bar);
bar.setMax(max);
ImageButton btn=(ImageButton)findViewById(R.id.incr);
btn.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
bar.incrementProgressBy(incrAmount);
if (onIncr!=null) {
onIncr.onClick(Meter.this);
}
}
});
btn=(ImageButton)findViewById(R.id.decr);
btn.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
bar.incrementProgressBy(decrAmount);
if (onDecr!=null) {
onDecr.onClick(Meter.this);
}
}
});
}
}
我用不同颜色标注的部分 自己悟吧,就是怎么引用自定义属性。
你如果和上一篇比较就知道了 就多了一个onFinishInflate() 在这个方法中引用了另一个xml
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="wrap_content" > <ImageButton android:id="@+id/decr" android:layout_height="30px" android:layout_width="30px" android:src="/blog_article/@drawable/decr/index.html" /> <ProgressBar android:id="@+id/bar" android:layout_width="0px" android:layout_weight="1" android:layout_height="wrap_content" /> <ImageButton android:id="@+id/incr" android:layout_height="30px" android:layout_width="30px" android:src="/blog_article/@drawable/incr/index.html" /> </LinearLayout>
attr就很简单了
<resources> <declare-styleable name="Meter"> <attr name="max" format="integer" /> <attr name="incr" format="integer" /> <attr name="decr" format="integer" /> </declare-styleable> </resources>
[3] 在sd卡顶用程序创建目录
来源: 互联网 发布时间: 2014-02-18
在sd卡中用程序创建目录
如果要想在sd卡中的一个子目录下创造文件FileOutputStream fos = new FileOutputStream("/sdcard/Wallpaper/"+fileName); 这是错误的,需要
// create a File object for the parent directory
File wallpaperDirectory = new File("/sdcard/Wallpaper/");
// have the object build the directory structure, if needed.
wallpaperDirectory.mkdirs();
// create a File object for the output file
File outputFile = new File(wallpaperDirectory, filename);
// now attach the OutputStream to the file object, instead of a String representation
FileOutputStream fos = new FileOutputStream(outputFile);
当然别忘了检查sd卡存在不Environment.getExternalStorageDirectory()
最新技术文章: