码迷,mamicode.com
首页 > 系统相关 > 详细

Linux环境编程之同步(二):条件变量

时间:2014-06-08 17:45:15      阅读:337      评论:0      收藏:0      [点我收藏+]

标签:android   c   style   class   blog   code   

MainActivity如下:

package cn.testprogressdialog;
import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnCancelListener;
import android.os.Bundle;
import android.view.Window;
/**
 * Demo描述:
 * 自定义ProgressDialog
 * 
 * 备注说明:
 * 在此处progressDialog.setOnCancelListener(){}
 * 并没有起到按下back键盘使风火轮消失的作用.
 * 因为在initDialog(Context context)中设置了
 * dialog.setCancelable(false);
 * 若需要此功能,注释掉该句代码即可.
 */
public class MainActivity extends Activity {
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);
		Dialog progressDialog=initDialog(MainActivity.this);
		progressDialog.setOnCancelListener(new OnCancelListener() {
			@Override
			public void onCancel(DialogInterface dialog) {
				dialog.dismiss();
				//其余业务逻辑
			}
		});
		progressDialog.show();
	}

	public Dialog initDialog(Context context) {
		Dialog dialog = new DialogSubClass(MainActivity.this, R.style.dialog);
		dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
		dialog.setCanceledOnTouchOutside(false);
		dialog.setCancelable(false);
		return dialog;
	}

}

DialogSubClass如下:

package cn.testprogressdialog;
import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
public class DialogSubClass extends Dialog {
	public DialogSubClass(Context context, int theme) {
		super(context, theme);
	}

	protected DialogSubClass(Context context, boolean cancelable,OnCancelListener cancelListener) {
		super(context, cancelable, cancelListener);
	}

	public DialogSubClass(Context context) {
		super(context);
	}
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		View view = LayoutInflater.from(getContext()).inflate(R.layout.dialoglayout, null);
		setContentView(view);
	}
	
	@Override
	public void show() {
		super.show();
	}
	
	@Override
	public void dismiss() {
		super.dismiss();
	}
	
	public void setMsg(String txt) {
		
	}

}

dialoglayout.xml如下:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" >

    <ProgressBar
        android:id="@+id/progressBar"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="loading"
        android:textSize="20sp"
        android:layout_below="@id/progressBar"
        android:layout_marginTop="-5dip"
        android:layout_centerHorizontal="true"
        android:textColor="@android:color/black" 
        />

</RelativeLayout>

styles.xml如下:

<resources>

    <style name="AppBaseTheme" parent="android:Theme.Light"></style>

    <style name="AppTheme" parent="AppBaseTheme"></style>
    
    <style name="dialog" parent="@android:style/Theme.Dialog">
        <item name="android:windowFrame">@null</item>
        <item name="android:windowIsFloating">true</item>
        <item name="android:windowIsTranslucent">true</item>
        <item name="android:windowNoTitle">true</item>
        <item name="android:windowBackground">@android:color/transparent</item>
        <item name="android:backgroundDimEnabled">true</item>
        <item name="android:windowContentOverlay">@null</item>
    </style>

</resources>

main.xml如下:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    >

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="测试自定义ProgressDialog"
        android:layout_centerHorizontal="true"
        android:textSize="24sp"
    />

</RelativeLayout>


Linux环境编程之同步(二):条件变量,布布扣,bubuko.com

Linux环境编程之同步(二):条件变量

标签:android   c   style   class   blog   code   

原文地址:http://blog.csdn.net/to_be_it_1/article/details/28880831

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!