android.os. Builder
常用的Dialog总结

Andoid Dialog1、AlertDialog,具有0-3个按钮,可以放选项、复选框单选框等,以建议的方式域用户交互可以。
2、ProgressDialog,显示一个进度的圆环或者进度条。
3、DataPickerDialog,选择日期的dialog。
4、TimePickerDialog,选择时间的dialog。
用户可以继承Dialog类或者它的子类并且创建一个新的leyout。
Showing a DialogDialog总是作为一个Activity的一部分来创建和显示的。
正常可以使用Activity的onCreateDialog(int)回调函数来创建Dialog。
使用这个回调函数的时候,系统会自动管理每个dialog的状态,并把它们关联到这个Activity,有效的使它成为dialog的所有者。
这样每个第啊咯个都从父Activity继承一些属性。
For example, when a dialog is open, the Menu key reveals the options menu defined for the Activity and the volume keys modify the audio stream used by the Activity.注意:如果你在onCreate()之外创建dialog,他不会附属于任何的Activity,可以使用dialog的setOwnerActivity(Activity)来设置。
当想显示一个dialog的时候,调用showDialog(int),并传递一个整数来唯一标识想要显示的dialog即可。
当第一次使用一个dialog的时候,Android会调用onCreateDialog(int),应该在这里创建dialog。
这个回调方法的参数是你传递给showDialog(int)的id。
创建Dialog结束后,返回这个dialog对象。
android build子系统解析

Android Building System 分析设定档Android building system 包括几种重要的设定档,* Android.mk* AndroidProducts.mk* target_<os>-<arch>.mk, host_<os>-<arch>.mk and <os>-<arch>.mk* BoardConfig.mk* buildspec.mkAndroid.mk 是module 和package 的设定档,每个module/package 的目录下都会有一个Android.mk。
所谓的module 是指系统的native code ,相对于用Java 写成的Android application 称为package。
AndroidProducts.mk 则设定product 配置。
product 即特定系统版本,透过编译不同product ,产生不同软件配置内容,安装不同的application。
Product 可视为特定项目,产生特定规格系统。
BoardConfig.mk 是为product 主板做设定,像是driver 选择、设定。
*<os>-<arch>.mk 则是针对选择的操作系统和CPU 架构,进行相关设定。
buildspec.mk 是位于source 根目录下,为进行编译者所做之额外设定。
例如,可在此选择要产生的product 、平台、额外的module/package 等。
参数build/envsetup.sh 实作一个mm 指令,以编译单一module,不需编译整个source tree。
ONE_SHOT_MAKEFILE 这个makefile 变量/参数就是用以实作这个功能。
使用方法是在执行make 时,将该变量指定为module 的Android.mk。
AndroidBuild类如何获取手机硬件信息

Android Build类如何获取手机硬件信息Android Build类是怎么到获取手机硬件信息的呢?别着急,接下来就让店铺来教下大家吧,快来看看吧,希望能让大家有所收获!了解获取手机硬件信息的Android Build的相关类1. Build.BOARD // 主板2. Build.BRAND // android系统定制商3. Build.CPU_ABI // cpu指令集4. Build.DEVICE // 设备参数5. Build.DISPLAY // 显示屏参数6. Build.FINGERPRINT // 硬件名称7. Build.HOST8. Build.ID // 修订版本列表9. Build.MANUFACTURER // 硬件制造商10. Build.MODEL // 版本11. Build.PRODUCT // 手机制造商12. Build.TAGS // 描述build的标签 13. Build.TIME14. Build.TYPE // builder类型15. ER通过Android Build类代码获取手机硬件信息import java.io.BufferedReader;import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException;import java.io.ObjectInputStream.GetField;import android.Manifest; import android.app.Activity;import android.app.ActivityManager;import android.app.ActivityManager.MemoryInfo; import android.content.Context;import android.content.pm.PackageManager; import.ConnectivityManager; import workInfo; import android.os.Build;import android.telephony.TelephonyManager; import android.util.Log;public class PhoneInfo {private static final String TAG = PhoneInfo.class.getSimpleName(); private static final String FILE_MEMORY = "/proc/meminfo"; private static final String FILE_CPU = "/proc/cpuinfo"; public String mIMEI; public int mPhoneType; public int mSysVersion;public String mNetWorkCountryIso; public String mNetWorkOperator; public String mNetWorkOperatorName; public int mNetWorkType; public boolean mIsOnLine;public String mConnectTypeName; public long mFreeMem; public long mT otalMem; public String mCupInfo; public String mProductName; public String mModelName;public String mManufacturerName;private PhoneInfo() {}public static String getIMEI(Context context) {TelephonyManager manager = (T elephonyManager) context .getSystemService(Activity.TELEPHONY_SERVICE); // check if has the permissionif (PackageManager.PERMISSION_GRANTED == context.getPackageManager().checkPermission(Manifest.permission.READ_PHONE_STATE, context.getPackageName())) { return manager.getDeviceId(); } else {return null; } }public static int getPhoneType(Context context) {TelephonyManager manager = (T elephonyManager) context .getSystemService(Activity.TELEPHONY_SERVICE); return manager.getPhoneType(); }public static int getSysVersion() { return Build.VERSION.SDK_INT; }public static String getNetWorkCountryIso(Context context) { TelephonyManager manager = (T elephonyManager) context .getSystemService(Activity.TELEPHONY_SERVICE); return manager.getNetworkCountryIso(); }public static String getNetWorkOperator(Context context) { TelephonyManager manager = (T elephonyManager) context .getSystemService(Activity.TELEPHONY_SERVICE); return manager.getNetworkOperator(); }public static String getNetWorkOperatorName(Context context) { TelephonyManager manager = (TelephonyManager) context.getSystemService(Activity.TELEPHONY_SERVICE); return manager.getNetworkOperatorName(); }public static int getNetworkType(Context context) {TelephonyManager manager = (T elephonyManager) context .getSystemService(Activity.TELEPHONY_SERVICE); return manager.getNetworkType(); }public static boolean isOnline(Context context) {ConnectivityManager manager = (ConnectivityManager) context .getSystemService(Activity.CONNECTIVITY_SERVICE);NetworkInfo info = manager.getActiveNetworkInfo(); if (info != null && info.isConnected()) { return true; }return false; }public static String getConnectTypeName(Context context) { if (!isOnline(context)) {return "OFFLINE"; }ConnectivityManager manager = (ConnectivityManager) context .getSystemService(Activity.CONNECTIVITY_SERVICE);NetworkInfo info = manager.getActiveNetworkInfo(); if (info != null) {return info.getTypeName(); } else {return "OFFLINE"; } }public static long getFreeMem(Context context) {ActivityManager manager = (ActivityManager) context.getSystemService(Activity.ACTIVITY_SERVICE); MemoryInfo info = new MemoryInfo(); manager.getMemoryInfo(info);long free = info.availMem / 1024 / 1024; return free; }public static long getTotalMem(Context context) { try {FileReader fr = new FileReader(FILE_MEMORY); BufferedReader br = new BufferedReader(fr); String text = br.readLine();String[] array = text.split("\\s+"); Log.w(TAG, text);return Long.valueOf(array[1]) / 1024; } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); }return -1; }public static String getCpuInfo() { try {FileReader fr = new FileReader(FILE_CPU); BufferedReader br = new BufferedReader(fr);String text = br.readLine();String[] array = text.split(":\\s+", 2); for (int i = 0; i < array.length; i++) { Log.w(TAG, " ..... " + array[i]); }Log.w(TAG, text); return array[1];} catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); }return null; }public static String getProductName() { return Build.PRODUCT; }public static String getModelName() { return Build.MODEL; } public static String getManufacturerName() { return Build.MANUFACTURER; }public static PhoneInfo getPhoneInfo(Context context) { PhoneInfo result = new PhoneInfo(); result.mIMEI = getIMEI(context);result.mPhoneType = getPhoneType(context); result.mSysVersion = getSysVersion();result.mNetWorkCountryIso = getNetWorkCountryIso(context); result.mNetWorkOperator = getNetWorkOperator(context);result.mNetWorkOperatorName = getNetWorkOperatorName(context); result.mNetWorkType = getNetworkType(context); result.mIsOnLine = isOnline(context);result.mConnectTypeName = getConnectTypeName(context); result.mFreeMem = getFreeMem(context); result.mT otalMem = getTotalMem(context); result.mCupInfo = getCpuInfo();result.mProductName = getProductName(); result.mModelName = getModelName();result.mManufacturerName = getManufacturerName(); return result; }@Overridepublic String toString() {StringBuilder builder = new StringBuilder(); builder.append("IMEI : "+mIMEI+"\n");builder.append("mPhoneType : "+mPhoneType+"\n");builder.append("mSysVersion : "+mSysVersion+"\n"); builder.append("mNetWorkCountryIso : "+mNetWorkCountryIso+"\n");builder.append("mNetWorkOperator : "+mNetWorkOperator+"\n");builder.append("mNetWorkOperatorName : "+mNetWorkOperatorName+"\n");builder.append("mNetWorkType : "+mNetWorkType+"\n"); builder.append("mIsOnLine : "+mIsOnLine+"\n");builder.append("mConnectTypeName : "+mConnectTypeName+"\n"); builder.append("mFreeMem : "+mFreeMem+"M\n"); builder.append("mTotalMem : "+mT otalMem+"M\n"); builder.append("mCupInfo : "+mCupInfo+"\n");builder.append("mProductName : "+mProductName+"\n");builder.append("mModelName : "+mModelName+"\n");builder.append("mManufacturerName : "+mManufacturerName+"\n");return builder.toString(); } }通过Android Build类获取手机硬件信息所需要的权限代码<uses-permissionandroid:name="android.permission.READ_PHONE_STATE"/> <uses-permissionandroid:name="android.permission.ACCESS_NETWORK_STATE"/>。
app开发快速理解——推送通知小红点角标

app开发快速理解——推送通知⼩红点⾓标package com.example.chapter11;import android.app.Notification;import android.app.NotificationManager;import android.app.PendingIntent;import android.content.Context;import android.content.Intent;import android.graphics.BitmapFactory;import android.os.Build;import android.os.Bundle;import android.text.TextUtils;import android.view.View;import android.widget.EditText;import android.widget.Toast;import androidx.appcompat.app.AppCompatActivity;import com.example.chapter11.util.ViewUtil;public class NotifySimpleActivity extends AppCompatActivity implements View.OnClickListener {private EditText et_title;private EditText et_message;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(yout.activity_notify_simple);et_title = findViewById(R.id.et_title);et_message = findViewById(R.id.et_message);findViewById(R.id.btn_send_simple).setOnClickListener(this);}@Overridepublic void onClick(View v) {if (v.getId() == R.id.btn_send_simple) {ViewUtil.hideOneInputMethod(this, et_message); // 隐藏输⼊法软键盘if (TextUtils.isEmpty(et_title.getText())) {Toast.makeText(this, "请填写消息标题", Toast.LENGTH_SHORT).show();return;}if (TextUtils.isEmpty(et_message.getText())) {Toast.makeText(this, "请填写消息内容", Toast.LENGTH_SHORT).show();return;}String title = et_title.getText().toString();String message = et_message.getText().toString();sendSimpleNotify(title, message); // 发送简单的通知消息}}// 发送简单的通知消息(包括消息标题和消息内容)private void sendSimpleNotify(String title, String message) {// 发送消息之前要先创建通知渠道,创建代码见MainApplication.java// 创建⼀个跳转到活动页⾯的意图Intent clickIntent = new Intent(this, MainActivity.class);// 创建⼀个⽤于页⾯跳转的延迟意图PendingIntent contentIntent = PendingIntent.getActivity(this,R.string.app_name, clickIntent, PendingIntent.FLAG_UPDATE_CURRENT);// 创建⼀个通知消息的建造器Notification.Builder builder = new Notification.Builder(this);if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {// Android 8.0开始必须给每个通知分配对应的渠道builder = new Notification.Builder(this, getString(R.string.app_name));}builder.setContentIntent(contentIntent) // 设置内容的点击意图.setAutoCancel(true) // 点击通知栏后是否⾃动清除该通知.setSmallIcon(R.mipmap.ic_launcher) // 设置应⽤名称左边的⼩图标.setSubText("这⾥是副本") // 设置通知栏⾥⾯的附加说明⽂本// 设置通知栏右边的⼤图标.setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.ic_app)).setContentTitle(title) // 设置通知栏⾥⾯的标题⽂本.setContentText(message); // 设置通知栏⾥⾯的内容⽂本Notification notify = builder.build(); // 根据通知建造器构建⼀个通知对象// 从系统服务中获取通知管理器NotificationManager notifyMgr = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);// 使⽤通知管理器推送通知,然后在⼿机的通知栏就会看到该消息notifyMgr.notify(R.string.app_name, notify);}}package com.example.chapter11;import android.app.Notification;import android.app.NotificationManager;import android.app.PendingIntent;import android.content.Context;import android.content.Intent;import android.graphics.BitmapFactory;import android.os.Build;import android.os.Bundle;import android.text.TextUtils;import android.view.View;import android.widget.EditText;import android.widget.Toast;import androidx.appcompat.app.AppCompatActivity;import com.example.chapter11.util.ViewUtil;public class NotifyCounterActivity extends AppCompatActivity implements View.OnClickListener { private EditText et_title;private EditText et_message;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(yout.activity_notify_counter);et_title = findViewById(R.id.et_title);et_message = findViewById(R.id.et_message);findViewById(R.id.btn_send_counter).setOnClickListener(this);}@Overridepublic void onClick(View v) {if (v.getId() == R.id.btn_send_counter) {ViewUtil.hideOneInputMethod(this, et_message); // 隐藏输⼊法软键盘if (TextUtils.isEmpty(et_title.getText())) {Toast.makeText(this, "请填写消息标题", Toast.LENGTH_SHORT).show();return;}if (TextUtils.isEmpty(et_message.getText())) {Toast.makeText(this, "请填写消息内容", Toast.LENGTH_SHORT).show();return;}String title = et_title.getText().toString();String message = et_message.getText().toString();sendCounterNotify(title, message); // 发送计时的通知消息}}// 发送计时的通知消息private void sendCounterNotify(String title, String message) {// 发送消息之前要先创建通知渠道,创建代码见MainApplication.java// 创建⼀个跳转到活动页⾯的意图Intent cancelIntent = new Intent(this, MainActivity.class);// 创建⼀个⽤于页⾯跳转的延迟意图PendingIntent deleteIntent = PendingIntent.getActivity(this,R.string.app_name, cancelIntent, PendingIntent.FLAG_UPDATE_CURRENT);// 创建⼀个通知消息的建造器Notification.Builder builder = new Notification.Builder(this);if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {// Android 8.0开始必须给每个通知分配对应的渠道builder = new Notification.Builder(this, getString(R.string.app_name));}builder.setDeleteIntent(deleteIntent) // 设置内容的清除意图.setSmallIcon(R.mipmap.ic_launcher) // 设置应⽤名称左边的⼩图标// 设置通知栏右边的⼤图标.setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.ic_app)).setProgress(100, 60, false) // 设置进度条及其具体进度.setUsesChronometer(true) // 设置是否显⽰计时器.setContentTitle(title) // 设置通知栏⾥⾯的标题⽂本.setContentText(message); // 设置通知栏⾥⾯的内容⽂本Notification notify = builder.build(); // 根据通知建造器构建⼀个通知对象// 从系统服务中获取通知管理器NotificationManager notifyMgr = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);// 使⽤通知管理器推送通知,然后在⼿机的通知栏就会看到该消息notifyMgr.notify(R.string.app_name, notify);}}package com.example.chapter11.util;import android.annotation.TargetApi;import android.app.Notification;import android.app.NotificationChannel;import android.app.NotificationManager;import android.content.Context;import .Uri;import android.os.Build;import android.os.Bundle;import android.util.Log;import com.example.chapter11.BuildConfig;import ng.reflect.Field;import ng.reflect.Method;public class NotifyUtil {private final static String TAG = "NotifyUtil";@TargetApi(Build.VERSION_CODES.O)// 创建通知渠道。
android自定义对话框

接下来我们来看看如何在对话框中嵌套一个ListView。
首先,需要一个布局文件,布局文件里只创建一个ListView,如下代码<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent"android:layout_height="fill_parent" android:scrollbars="vertical"> <ListViewandroid:id="@+id/listCity"android:layout_width="fill_parent"android:layout_height="fill_parent"android:scrollbars="vertical"/></LinearLayout>Java代码如下private void ShowLoginDialog(){Builder builder = new AlertDialog.Builder(Tab1Activity.this);builder.setTitle("选择城市");LayoutInflater factory = LayoutInflater.from(Tab1Activity.this); View dialogView = factory.inflate(yout.dialogcity, null); listCity =(ListView)dialogView.findViewById(R.id.listCity);GetCity();builder.setView(dialogView);builder.show();}private void GetCity(){System.out.println("asd");ArrayList<HashMap<String, String>> listData = new ArrayList<HashMap<String,String>>();HashMap<String, String> hmItem = new HashMap<String, String>();hmItem.put("city", "北京");listData.add(hmItem);hmItem = new HashMap<String, String>();hmItem.put("city", "上海");listData.add(hmItem);hmItem = new HashMap<String, String>();hmItem.put("city", "深圳");listData.add(hmItem);hmItem = new HashMap<String, String>();hmItem.put("city", "天津");listData.add(hmItem);hmItem = new HashMap<String, String>();hmItem.put("city", "南京");listData.add(hmItem);hmItem = new HashMap<String, String>();hmItem.put("city", "武汉");listData.add(hmItem);hmItem = new HashMap<String, String>();hmItem.put("city", "江苏");listData.add(hmItem);hmItem = new HashMap<String, String>();listData.add(hmItem);SimpleAdapter sim = new SimpleAdapter(this, listData, yout.simple_list_item_1, new String[]{"city"}, new int[]{android.R.id.text1});listCity.setAdapter(sim);}直接调用ShowLoginDialog方法即可。
android显示单选列表对话框builder.setSingleChoiceItems

android显⽰单选列表对话框builder.setSingleChoiceItems通过AlertDialog.Builder类的setSingleChoiceItems⽅法可以创建带单按钮的列表:⽅法如下:1、从资源⽂件中装载数据:public Builder setSingleChoiceItems(int itemsId, int checkedItem, finalOnClickListener listener)2、从数据集中装载数据public Builder setSingleChoiceItems(Cursorcursor, int checkedItem, String labelColumn, final OnClickListener listener)3、从字符串数组中装载数据public Builder setSingleChoiceItems(CharSequence[] items, int checkedItem, finalOnClickListener listener)4、从ListAdapter对象中装载数据public BuildersetSingleChoiceItems(ListAdapter adpater, int checkedItem, final OnClickListener listener)package com.js.sinlgechoiceitemstest;import android.app.Activity;import android.app.AlertDialog;import android.content.DialogInterface;import android.os.Bundle;import android.os.Handler;import android.view.View;import android.view.View.OnClickListener;import android.widget.Button;import android.widget.Toast;public class SingleChoiceItemsTest extends Activity implements OnClickListener{private String[] province = new String[] { "上海", "北京", "湖南", "湖北", "海南" };private Button btnSingleChoiceList;// 单击事件对象的实例private ButtonOnClick buttonOnClick = new ButtonOnClick(1);/** Called when the activity is first created. */@Overridepublic void onCreate(Bundle savedInstanceState){super.onCreate(savedInstanceState);setContentView(yout.main);btnSingleChoiceList = (Button) findViewById(R.id.btnSingleChoice);btnSingleChoiceList.setOnClickListener(this);}@Overridepublic void onClick(View v){showSingleChoiceButton();}// 在单选选项中显⽰确定和取消按钮//buttonOnClickg变量的数据类型是ButtonOnClick,⼀个单击事件类private void showSingleChoiceButton(){AlertDialog.Builder builder = new AlertDialog.Builder(this);builder.setTitle("请选择省份");builder.setSingleChoiceItems(province, 0, buttonOnClick);builder.setPositiveButton("确定", buttonOnClick);builder.setNegativeButton("取消", buttonOnClick);builder.show();}private class ButtonOnClick implements DialogInterface.OnClickListener{private int index; // 表⽰选项的索引public ButtonOnClick(int index){this.index = index;}@Overridepublic void onClick(DialogInterface dialog, int which){// which表⽰单击的按钮索引,所有的选项索引都是⼤于0,按钮索引都是⼩于0的。
OSBuilder

1.1 OSBuilder的模板文件夹结构:模板文件夹结构如下:.\Configurations --> 放置默认的配置文件(_Default.xml),当“保存为默认配置”时由程序自动生成;.\OEM --> 您可以将除 SYS 和 XIP 以外的所有的 OEM 组件全部放置于此;.\EXT --> 可有可无。
有的话,您可以将 OEM 目录下的类似于官方 ROM 中以OEM 组件放置于此。
当然,具体放什么,取决于您的喜好。
.\ROM\XIP --> 放置 MSXIPKernel、MSXIPKernelLTK、OEMXIPKernel 等。
由程序产生。
方法:附加工具->创建模板->选择官方的 .nb0/.payload 文件-> OK。
包括以下文件和目录:Map.txtparthdr.binromhdr.binboot.rgu(必须)\LangDB\MSXIPKernel\MSXIPKernelLTK\OEMXIPKERNEL\WinCENLS_Lang_0804ROM.tpl-->该名称可自己命名,为模板文件,创建方法如下:附加工具->创建模板->选择官方的 .nb0/.payload 文件-> OK,保存即可。
OS.nb0-->创建模板文件必须的文件,也就是I900的os.nb。
XIP.bin-->I900的原始的XIP.bin文件,可有可无。
\LZX36-->LZX压缩方式必须的cecompr.dll文件\LZX16--> LZX压缩方式必须的cecompr.dll文件.\SYS --> 不用多说了.\Donor-->用来存放你要移植的新核心xip文件,可以是一个xip.bin文件,也可以是MSXIPKernel文件夹形式,用于移植xip。
其他的就自己随意建来用啦,比如说我自己建立一个tools文件夹用于存放其它一些工具,建立一个Flash文件夹存放生成的rom等等。
android浏览器源代码

/bbs/home.php?mod=invite&id=62&c=apzrou /bbs/home.php?mod=invite&id=61&c=akkahk /bbs/home.php?mod=invite&id=60&c=zhhsor /bbs/home.php?mod=invite&id=59&c=4ukha8 /bbs/home.php?mod=invite&id=58&c=lgg60m /bbs/home.php?mod=invite&id=57&c=ymgm3m /bbs/home.php?mod=invite&id=56&c=n5zhht /bbs/home.php?mod=invite&id=55&c=huukbh /bbs/home.php?mod=invite&id=54&c=8yrc1c /bbs/home.php?mod=invite&id=53&c=stf115package com.explorer;import static com.mime.MIME.MIME_MapTable;import java.io.BufferedInputStream;import java.io.BufferedOutputStream;import java.io.DataInputStream;import java.io.DataOutputStream;import java.io.File;import java.io.FileInputStream;import java.io.FileOutputStream; import java.util.ArrayList;import java.util.Arrays;import parator;import java.util.HashMap;import java.util.List;import java.util.Map;import android.app.Activity;import android.app.AlertDialog;import android.app.Dialog;import android.app.ProgressDialog; import android.content.DialogInterface; import android.content.Intent;import .Uri;import android.os.Bundle;import android.os.Environment; import android.os.Handler;import android.os.Looper;import android.os.Message;import youtInflater; import android.view.Menu;import android.view.MenuInflater;import android.view.MenuItem;import android.view.View;import android.view.View.OnClickListener;import android.widget.AdapterView;import android.widget.AdapterView.OnItemClickListener;import android.widget.AdapterView.OnItemLongClickListener;import android.widget.Button;import android.widget.EditText;import android.widget.ListAdapter;import android.widget.ListView;import android.widget.SimpleAdapter;import android.widget.TextView;import android.widget.Toast;import com.file.R;public class MainActivity extends Activity implements OnClickListener, OnItemClickListener, OnItemLongClickListener { private TextView currentDir;private Button btnC;private Button btnE;private ListView listView;private File rootDir;private File copyPath;private String flag;private String startFilePath;private String desFilePath;private List<File> fileList = new ArrayList<File>();private ProgressDialog progressDialog;private int currentLen = 0;private long totaLength = 0;private Handler messageHandler;/** Called when the activity is first created. */@Overridepublic void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState);setContentView(yout.main);currentDir = (TextView) findViewById(R.id.currentDir);// fileName = (TextView) findViewById();btnC = (Button) findViewById(R.id.btnC);btnE = (Button) findViewById(R.id.btnE);btnC.setOnClickListener(this);btnE.setOnClickListener(this);listView = (ListView) findViewById(R.id.listView);listView.setOnItemClickListener(this);listView.setOnItemLongClickListener(this);//得到当前线程的Looper实例,由于当前线程是UI线程也可以通过Looper.getMainLooper()得到messageHandler = new MessageHandler(Looper.myLooper());if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) { rootDir = Environment.getExternalStorageDirectory();} else {rootDir = Environment.getRootDirectory();}loadFiles(rootDir);}//自定义Handlerclass MessageHandler extends Handler {public MessageHandler(Looper looper) {super(looper);}@Overridepublic void handleMessage(Message msg) {loadFiles(new File(currentDir.getText().toString()));}}@Overridepublic boolean onCreateOptionsMenu(Menu menu) {MenuInflater inflater = getMenuInflater();inflater.inflate(R.menu.menu, menu);return true;}@Overridepublic boolean onOptionsItemSelected(MenuItem item) {if (item.getItemId() == R.id.newFile) {LayoutInflater factory = LayoutInflater.from(MainActivity.this);final View view = factory.inflate(yout.rename, null);AlertDialog d = new AlertDialog.Builder(MainActivity.this).setCancelable(true).setMessage("文件夹名") .setView(view).setPositiveButton("确定", new DialogInterface.OnClickListener() {@Overridepublic void onClick(DialogInterface dialog, int which) {String dirName = ((EditText) view.findViewById(R.id.rename)).getText().toString();String newFile = currentDir.getText().toString() + "/" + dirName;if (new File(newFile).exists()) {Toast.makeText(MainActivity.this, "文件夹已存在", Toast.LENGTH_LONG).show();return;}File f = new File(currentDir.getText().toString(), dirName);f.mkdir();}}).create();d.show();} else if (item.getItemId() == R.id.about) {Dialog d = new AlertDialog.Builder(MainActivity.this).setTitle("文件浏览器1.0beta").setMessage("本程序由劲松Alex制作") .setPositiveButton("确定", null).create();d.show();} else if (item.getItemId() == R.id.exit) {MainActivity.this.finish();}return true;}/*** 加载当前文件夹列表* */public void loadFiles(File dir) {List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();if (dir != null) {// 处理上级目录if (!dir.getAbsolutePath().equals(rootDir.getAbsolutePath())) {Map<String, Object> map = new HashMap<String, Object>();map.put("file", dir.getParentFile());map.put("name", "上一级目录");map.put("img", R.drawable.folder);list.add(map);}currentDir.setText(dir.getAbsolutePath());File[] files = dir.listFiles();sortFiles(files);if (files != null) {for (File f : files) {Map<String, Object> map = new HashMap<String, Object>();map.put("file", f);map.put("name", f.getName());map.put("img", f.isDirectory() ? R.drawable.folder: (f.getName().toLowerCase().endsWith(".zip") ? R.drawable.zip : R.drawable.text));list.add(map);}}} else {Toast.makeText(this, "目录不正确,请输入正确的目录!", Toast.LENGTH_LONG).show();}ListAdapter adapter = new SimpleAdapter(this, list, yout.item, new String[] { "name", "img" }, new int[] {, R.id.icon });// listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);listView.setAdapter(adapter);}/*** 排序文件列表* */private void sortFiles(File[] files) {Arrays.sort(files, new Comparator<File>() {public int compare(File file1, File file2) {if (file1.isDirectory() && file2.isDirectory())return 1;if (file2.isDirectory())return 1;return -1;}});}/*** 打开文件** @param file*/private void openFile(File file) {Intent intent = new Intent();intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);// 设置intent的Action属性intent.setAction(Intent.ACTION_VIEW);// 获取文件file的MIME类型String type = getMIMEType(file);// 设置intent的data和Type属性。
androidlistbuilder用法

androidlistbuilder用法Android ListBuilder 是一个用于快速创建列表视图的强大工具,它可以帮助我们以简单的方式创建并定制各种类型的列表视图。
无论是简单的文本列表,还是复杂的带有图像和附件的列表视图,ListBuilder 都可以很好地满足我们的需求。
使用 ListBuilder 的一般步骤如下:1. 创建 ListBuilder 实例要使用 ListBuilder,我们首先需要创建一个 ListBuilder 的实例。
可以通过 ListBuilder 的构造函数来创建实例,构造函数接收一个Context 对象作为参数。
例如:```javaListBuilder listBuilder = new ListBuilder(context);```2.设置列表布局在创建了 ListBuilder 实例后,我们需要设置列表的样式和布局。
可以使用方法 `setLayoutManager(`来设置列表的布局管理器,例如使用`LinearLayoutManager` 或者 `GridLayoutManager`。
例如:```javalistBuilder.setLayoutManager(newLinearLayoutManager(context));```3.创建数据源接下来,我们需要准备用于填充列表的数据源。
数据源可以是任何实现了 `ListBuilder.Item` 接口的对象。
`ListBuilder.Item` 接口定义了用于显示在列表项中的数据的方法。
例如,我们可以创建一个普通的文本列表项:```javapublic class TextItem implements ListBuilder.Itemprivate String text;public TextItem(String text)this.text = text;}public int getTypreturn 0;}public int getLayoutRereturn yout.item_text;}public void bindView(ListBuilder.ViewHolder viewHolder)TextView textView =viewHolder.itemView.findViewById(R.id.text_view);textView.setText(text);}```在上面的示例中,`Type(` 方法返回列表项的类型(用于多类型列表);`getLayoutRes(` 返回列表项的布局资源 ID;`bindView(` 方法用于将数据绑定到列表项的视图上。
史上最全的Androidbuild.gradle配置教程

史上最全的Androidbuild.gradle配置教程前⾔Android Studio是采⽤gradle来构建项⽬的,gradle是基于groovy语⾔的,如果只是⽤它构建普通Android项⽬的话,是可以不去学groovy的。
当我们创建⼀个Android项⽬时会包含两个Android build.gradle配置详解⽂件,如下图:⼀、Project的build.gradle⽂件:对应的build.gradle代码如下:// Top-level build file where you can add configuration options common to all sub-projects/modules.buildscript {//这⾥是gradle脚本执⾏所需依赖,分别是对应的maven库和插件repositories {google()//从Android Studio3.0后新增了google()配置,可以引⽤google上的开源项⽬jcenter()//是⼀个类似于github的代码托管仓库,声明了jcenter()配置,可以轻松引⽤ jcenter上的开源项⽬}dependencies {classpath 'com.android.tools.build:gradle:3.0.0'////此处是android的插件gradle,gradle是⼀个强⼤的项⽬构建⼯具// NOTE: Do not place your application dependencies here; they belong// in the individual module build.gradle files}}allprojects {//这⾥是项⽬本⾝需要的依赖,⽐如项⽬所需的maven库repositories {google()jcenter()}}// 运⾏gradle clean时,执⾏此处定义的task任务。
实验3 Android应用界面开发(2)

实验3 Android应用界面开发(2)一、实验目的1、掌握常用的界面设计组件的功能❑TextView和EditText的功能和用法❑Button和ImageButton的功能和用法❑RadioButton和CheckBox的功能和用法❑ToggleButton的功能和用法❑时钟的功能和用法❑ImageView的功能和用法❑AutoCompleteTextView的功能和用法❑Spinner的功能和用法❑日期和时间选择器的功能和用法2、掌握常用的XML属性3、使用XML属性来开发漂亮的用户界面二、实验步骤1、补充并调试程序,运行效果如下图所示。
以下是程序中要用到的bg_border.xml文件的内容,请注意文件所放的位置:<?xml version="1.0"encoding="utf-8"?><shape xmlns:android="/apk/res/android"> <solid android:color="#000000"/><stroke android:width="2dip"android:color="#0000ee"/></shape>以下是程序中要用到的strings.xml文件的内容:<?xml version="1.0"encoding="utf-8"?><resources><string name="hello">Hello World,EditText!</string><string name="app_name">注册页面</string></resources>以下是main.xml文件的内容,请根据运行结果图,补充程序中所缺的XML属性值<?xml version="1.0"encoding="utf-8"?><TableLayout xmlns:android="/apk/res/android"android:orientation="vertical"android:layout_width="fill_parent"android:layout_height="fill_parent"><TableRow><TextViewandroid:layout_width="fill_parent"android:layout_height="wrap_content"android:text="用户名:"android:textSize="10pt"android:background="@drawable/bg_border"/><EditTextandroid:layout_width="fill_parent"android:layout_height="wrap_content"android:hint="请填写登录帐号"android:selectAllOnFocus="true"/></TableRow><TableRow><TextViewandroid:layout_width="fill_parent"android:layout_height="wrap_content"android:text="密码:"android:textSize="10pt"android:background="@drawable/bg_border"/><EditTextandroid:layout_width="fill_parent"android:layout_height="wrap_content"android:password=/></TableRow><TableRow><TextViewandroid:layout_width="fill_parent"android:layout_height="wrap_content"android:text="电话号码:"android:textSize="10pt"android:background="@drawable/bg_border"/><EditTextandroid:layout_width="fill_parent"android:layout_height="wrap_content"android:hint="请填写您的电话号码"android:selectAllOnFocus="true"android:phoneNumber=android:maxLength="11"/></TableRow><TableRow><TextViewandroid:layout_width="fill_parent"android:layout_height="wrap_content"android:text="邮箱:"android:textSize="10pt"android:background="@drawable/bg_border"/><EditTextandroid:layout_width="fill_parent"android:layout_height="wrap_content"android:hint=/></TableRow><Buttonandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:text="注册"/></TableLayout>2、编写程序实现如下图所示的效果。
Android 触摸屏单击测试

我们今天要学习的就是android游戏开发必须对手机的各个设备非常了解。
其中最重要的设备之一就是触摸屏。
所以我们这里重点研究触摸屏的单击。
我们直接看代码吧。
这里是触摸屏单击的测试代码:java代码:package eoe.gamedev;import android.app.Activity;import android.os.Bundle;import android.util.Log;import android.view.MotionEvent;import android.view.View;import android.view.View.OnTouchListener;import android.widget.TextView;public class SingleTouchTest extends Activity implements OnTouchListener{StringBuilder builder = new StringBuilder();TextView textView;public void onCreate(Bundle state){super.onCreate(state);textView = new TextView(this);textView.setText("Touch and Drag one finger");textView.setOnTouchListener(this);setContentView(textView);}public boolean onTouch(View arg0, MotionEvent arg1) {builder.setLength(0);switch(arg1.getAction()){case MotionEvent.ACTION_DOWN: builder.append("down, ");break;case MotionEvent.ACTION_MOVE:builder.append("move, ");break;case MotionEvent.ACTION_UP:builder.append("up ,");break;case MotionEvent.ACTION_CANCEL:builder.append("cancel, ");break;}builder.append(arg1.getX());builder.append(", ");builder.append(arg1.getY());Log.d("TouchTest",builder.toString());textView.setText(builder.toString());return true;}}单击屏幕要实现OnTouchListener,实现public boolean onTouch(View arg0, MotionEvent arg1)方法。
View方面的知识点

MainActivity.xmlpackage com.example.uidemo1;import android.os.Bundle;import android.app.Activity;import android.app.AlertDialog;import android.app.AlertDialog.Builder;import youtInflater;import android.view.Menu;import android.view.MenuItem;import android.view.View;import android.view.View.OnClickListener;import android.widget.Button;import android.widget.EditT ext;import android.widget.LinearLayout;import android.widget.Toast;import android.support.v4.app.NavUtils;import android.text.AndroidCharacter;public class MainActivity extends Activity {// 获得activity_main中的这个buttonButton button1;EditText editText1;EditText editText2;public static final int BID = 1;OnClickListener onClickListener = new OnClickListener() {@Overridepublic void onClick(View v) {switch (v.getId()) {case R.id.button1: //在这里中有两个button1的,为了区别开来,使用tag 标记。
Android SDK 2.2 开发环境安装

5. 回到 Available Software 界面,你应该看到 "Developer Tools" 。选取 checkbox 。点击 Next,接受 license agreement, 然后点击 Finish。
6. 重起 Eclipse.
[配置 ADT]
配置 Eclipse 里的 ADT,使其指向 Android SDK 。
Create Activity: HelloAndroid
点击 Finish.
2). 编写代码:打印 Hello Android
package com.android.helloandroid;
import android.app.Activity;
import android.os.Bundle;
1. 选取 Eclipse Window > Preferences...
2. 选择 Android
3. 点击 Browse... 定位 Android SDK 目录。
4. 点击 Apply, 然后 OK.
(本节内容参考:/sdk/eclipse-adt.html)
super.onCreate(savedInstanceState);
TextView tv = new TextView(this);
tv.setText("Hello, Android");
setContentView(tv);
}
}
3)运行
ADT 使运行非常简单:
Android SDK 1.5 Revision 3 (Jul 2009) API Level: 3 Requires SDK Tools r6 or higher. Cupcake
Android开发闹钟(详细开发步骤)

一、MainActivity中的代码:package .daming;import java.util.Calendar;import android.app.Activity;import android.app.AlarmManager;import android.app.AlertDialog;import android.app.PendingIntent;import android.app.TimePickerDialog;import android.content.DialogInterface; import android.content.Intent;import android.content.SharedPreferences; import android.os.Bundle;import android.view.KeyEvent;import youtInflater;import android.view.MotionEvent;import android.view.View;import android.widget.Button;import android.widget.EditText;import android.widget.TextView;import android.widget.TimePicker;import android.widget.Toast;public class MainActivity extends Activity { TextView setTime1;TextView setTime2;TextView setTime3;Button mButton1;Button mButton2;Button mButton3;Button mButton4;Button mButton5;Button mButton6;String time1String = null;String time2String = null;String time3String = null;String defalutString = "目前无设置";AlertDialog builder = null;Calendar c=Calendar.getInstance();@Overridepublic void onCreate(Bundle savedInstanceState){super.onCreate(savedInstanceState);setContentView(yout.main);//取得活动的Preferences对象SharedPreferences settings =getPreferences(Activity.MODE_PRIVATE);time1String = settings.getString("TIME1", defalutString); time2String = settings.getString("TIME2", defalutString); time3String = settings.getString("TIME3", defalutString);InitButton1();InitButton2();InitButton3();InitButton4();InitButton5();InitButton6();setTime1.setText(time1String);setTime3.setText(time2String);setTime2.setText(time3String);}public void InitButton1(){setTime1=(TextView) findViewById(R.id.setTime1);mButton1=(Button)findViewById(R.id.mButton1);mButton1.setOnClickListener(new View.OnClickListener(){public void onClick(View v){c.setTimeInMillis(System.currentTimeMillis());int mHour=c.get(Calendar.HOUR_OF_DAY);int mMinute=c.get(Calendar.MINUTE);new TimePickerDialog(MainActivity.this,new TimePickerDialog.OnTimeSetListener(){public void onTimeSet(TimePicker view,int hourOfDay, int minute){c.setTimeInMillis(System.currentTimeMillis());c.set(Calendar.HOUR_OF_DAY,hourOfDay);c.set(Calendar.MINUTE,minute);c.set(Calendar.SECOND,0);c.set(LISECOND,0);Intent intent = new Intent(MainActivity.this, CallAlarm.class);PendingIntent sender=PendingIntent.getBroadcast(MainActivity.this,0, intent, 0);AlarmManager am;am = (AlarmManager)getSystemService(ALARM_SERVICE); am.set(AlarmManager.RTC_WAKEUP,c.getTimeInMillis(),sender);String tmpS=format(hourOfDay)+":"+format(minute); setTime1.setText(tmpS);//SharedPreferences保存数据,并提交SharedPreferences time1Share = getPreferences(0);SharedPreferences.Editor editor = time1Share.edit(); editor.putString("TIME1", tmpS);mit();Toast.makeText(MainActivity.this,"设置大明闹钟时间为"+tmpS,Toast.LENGTH_SHORT).show();}},mHour,mMinute,true).show();}});}public void InitButton2(){mButton2=(Button) findViewById(R.id.mButton2);mButton2.setOnClickListener(new View.OnClickListener(){public void onClick(View v){Intent intent = new Intent(MainActivity.this,CallAlarm.class);PendingIntent sender=PendingIntent.getBroadcast(MainActivity.this,0, intent, 0);AlarmManager am;am =(AlarmManager)getSystemService(ALARM_SERVICE);am.cancel(sender);Toast.makeText(MainActivity.this,"大明闹钟时间删除",Toast.LENGTH_SHORT).show();setTime1.setText("目前无设置");SharedPreferences time1Share = getPreferences(0);SharedPreferences.Editor editor = time1Share.edit(); editor.putString("TIME1", "目前无设置");mit();}});}public void InitButton3(){setTime3=(TextView) findViewById(R.id.setTime5);mButton3=(Button)findViewById(R.id.mButton5);mButton3.setOnClickListener(new View.OnClickListener(){public void onClick(View v){c.setTimeInMillis(System.currentTimeMillis());int mHour=c.get(Calendar.HOUR_OF_DAY);int mMinute=c.get(Calendar.MINUTE);new TimePickerDialog(MainActivity.this,new TimePickerDialog.OnTimeSetListener(){public void onTimeSet(TimePicker view,int hourOfDay, int minute){c.setTimeInMillis(System.currentTimeMillis());c.set(Calendar.HOUR_OF_DAY,hourOfDay);c.set(Calendar.MINUTE,minute);c.set(Calendar.SECOND,0);c.set(LISECOND,0);Intent intent = new Intent(MainActivity.this, CallAlarm.class);PendingIntent sender=PendingIntent.getBroadcast(MainActivity.this,1, intent, 0);AlarmManager am;am = (AlarmManager)getSystemService(ALARM_SERVICE); am.set(AlarmManager.RTC_WAKEUP,c.getTimeInMillis(),sender);String tmpS=format(hourOfDay)+":"+format(minute); setTime3.setText(tmpS);//SharedPreferences保存数据,并提交SharedPreferences time2Share = getPreferences(1);SharedPreferences.Editor editor = time2Share.edit(); editor.putString("TIME2", tmpS);mit();Toast.makeText(MainActivity.this,"设置大明闹钟时间为"+tmpS,Toast.LENGTH_SHORT).show();}},mHour,mMinute,true).show();}});}public void InitButton4(){mButton4=(Button) findViewById(R.id.mButton6);mButton4.setOnClickListener(new View.OnClickListener(){public void onClick(View v){Intent intent = new Intent(MainActivity.this,CallAlarm.class);PendingIntent sender=PendingIntent.getBroadcast(MainActivity.this,0, intent, 0);AlarmManager am;am =(AlarmManager)getSystemService(ALARM_SERVICE);am.cancel(sender);Toast.makeText(MainActivity.this,"大明闹钟时间删除",Toast.LENGTH_SHORT).show();setTime3.setText("目前无设置");//SharedPreferences保存数据,并提交SharedPreferences time2Share = getPreferences(1);SharedPreferences.Editor editor = time2Share.edit();editor.putString("TIME2", "目前无设置");mit();}});}public void InitButton5(){setTime2=(TextView) findViewById(R.id.setTime2);LayoutInflater factory = LayoutInflater.from(this);final View setView = factory.inflate(yout.timeset,null); final TimePicker tPicker=(TimePicker)setView.findViewById(R.id.tPicker);tPicker.setIs24HourView(true);final AlertDialog di=new AlertDialog.Builder(MainActivity.this) .setIcon(R.drawable.clock).setTitle("设置").setView(setView).setPositiveButton("确定",new DialogInterface.OnClickListener(){public void onClick(DialogInterface dialog, int which) {EditTexted=(EditText)setView.findViewById(R.id.mEdit);int times=Integer.parseInt(ed.getText().toString()) *1000;c.setTimeInMillis(System.currentTimeMillis());c.set(Calendar.HOUR_OF_DAY,tPicker.getCurrentHour());c.set(Calendar.MINUTE,tPicker.getCurrentMinute());c.set(Calendar.SECOND,0);c.set(LISECOND,0);Intent intent = new Intent(MainActivity.this,CallAlarm.class);PendingIntent sender = PendingIntent.getBroadcast( MainActivity.this,1, intent, 0);AlarmManager am;am = (AlarmManager)getSystemService(ALARM_SERVICE); am.setRepeating(AlarmManager.RTC_WAKEUP,c.getTimeInMillis(),times,sender);String tmpS=format(tPicker.getCurrentHour())+":"+ format(tPicker.getCurrentMinute());String subStr = "设置大明闹钟时间为"+tmpS+"开始,重复间隔为"+times/1000+"秒";setTime2.setText("设置大明闹钟时间为"+tmpS+"开始,重复间隔为"+times/1000+"秒");//SharedPreferences保存数据,并提交SharedPreferences time3Share = getPreferences(2); SharedPreferences.Editor editor = time3Share.edit();editor.putString("TIME3", subStr);mit();Toast.makeText(MainActivity.this,"设置大明闹钟为"+tmpS+"开始,重复间隔为"+times/1000+"秒", Toast.LENGTH_SHORT).show();}}).setNegativeButton("取消",new DialogInterface.OnClickListener(){public void onClick(DialogInterface dialog, int which) {}}).create();mButton5=(Button) findViewById(R.id.mButton3);mButton5.setOnClickListener(new View.OnClickListener(){public void onClick(View v){c.setTimeInMillis(System.currentTimeMillis());tPicker.setCurrentHour(c.get(Calendar.HOUR_OF_DAY));tPicker.setCurrentMinute(c.get(Calendar.MINUTE));di.show();}});}public void InitButton6(){mButton6=(Button) findViewById(R.id.mButton4);mButton6.setOnClickListener(new View.OnClickListener(){public void onClick(View v){Intent intent = new Intent(MainActivity.this, CallAlarm.class);PendingIntent sender = PendingIntent.getBroadcast( MainActivity.this,1, intent, 0);AlarmManager am;am = (AlarmManager)getSystemService(ALARM_SERVICE); am.cancel(sender);Toast.makeText(MainActivity.this,"闹钟时间删除",Toast.LENGTH_SHORT).show();setTime2.setText("目前无设置");//SharedPreferences保存数据,并提交SharedPreferences time3Share = getPreferences(2); SharedPreferences.Editor editor = time3Share.edit(); editor.putString("TIME3", "目前无设置");mit();}});}@Overridepublic boolean onKeyUp(int keyCode, KeyEvent event) {if(keyCode == KeyEvent.KEYCODE_BACK){builder = new AlertDialog.Builder(MainActivity.this).setIcon(R.drawable.clock).setTitle("温馨提示:").setMessage("您是否要退出大明闹钟程序").setPositiveButton("确定",new DialogInterface.OnClickListener() {public void onClick(DialogInterface dialog,int whichButton) {MainActivity.this.finish();}}).setNegativeButton("取消",new DialogInterface.OnClickListener() {public void onClick(DialogInterface dialog, int whichButton) {builder.dismiss();}}).show();}return true;}private String format(int x){String s=""+x;if(s.length()==1) s="0"+s;return s;}}二、CallAlarm中的代码:package .daming;import android.content.Context;import android.content.Intent;import android.content.BroadcastReceiver;import android.os.Bundle;public class CallAlarm extends BroadcastReceiver {@Overridepublic void onReceive(Context context, Intent intent) {Intent i = new Intent(context, AlarmAlert.class);Bundle bundleRet = new Bundle();bundleRet.putString("STR_CALLER", "");i.putExtras(bundleRet);i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);context.startActivity(i);}}三、AlarmAlert中的代码:package .daming;import android.app.Activity;import android.app.AlertDialog;import android.content.DialogInterface;import android.os.Bundle;public class AlarmAlert extends Activity{@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);new AlertDialog.Builder(AlarmAlert.this).setIcon(R.drawable.clock).setTitle("大明闹钟响了!!").setMessage("快完成你制定的计划吧").setPositiveButton("关掉它",new DialogInterface.OnClickListener(){public void onClick(DialogInterface dialog, int whichButton) {AlarmAlert.this.finish();}}).show();}}四、main.xml布局文件的代码:<?xml version="1.0" encoding="utf-8"?><AbsoluteLayoutxmlns:android="/apk/res/android"android:id="@+id/layout1"android:layout_width="fill_parent"android:layout_height="fill_parent"android:background="@drawable/other"><DigitalClockandroid:id="@+id/dClock"android:layout_width="wrap_content"android:layout_height="wrap_content"android:textSize="40sp"android:textColor="@drawable/blue"android:layout_x="70px"android:layout_y="32px"></DigitalClock><TextViewandroid:id="@+id/text1"android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/str_title3"android:textSize="20sp"android:textColor="@drawable/black" android:layout_x="10px"android:layout_y="104px"></TextView><Buttonandroid:id="@+id/mButton1"android:layout_width="wrap_content" android:layout_height="40px"android:text="@string/str_button1"android:textColor="@drawable/black" android:textSize="18sp"android:layout_x="190px"android:layout_y="102px"></Button><TextViewandroid:id="@+id/setTime1"android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/str_default" android:textColor="@drawable/red"android:textSize="16sp"android:layout_x="10px"android:layout_y="149px"></TextView><Buttonandroid:id="@+id/mButton2"android:layout_width="wrap_content" android:layout_height="40px"android:text="@string/str_button2" android:textColor="@drawable/black" android:textSize="18sp"android:layout_x="190px"android:layout_y="142px"></Button><TextViewandroid:id="@+id/text5"android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/str_title4"android:textSize="20sp"android:textColor="@drawable/black" android:layout_x="10px"android:layout_y="216px"></TextView><Buttonandroid:id="@+id/mButton5"android:layout_width="wrap_content" android:layout_height="40px"android:text="@string/str_button1" android:textColor="@drawable/black" android:textSize="18sp"android:layout_x="190px"android:layout_y="212px"></Button><TextViewandroid:id="@+id/setTime5"android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/str_default" android:textColor="@drawable/red"android:textSize="16sp"android:layout_x="10px"android:layout_y="259px"></TextView><Buttonandroid:id="@+id/mButton6"android:layout_width="wrap_content" android:layout_height="40px"android:text="@string/str_button2" android:textColor="@drawable/black" android:textSize="18sp"android:layout_x="190px"android:layout_y="252px"></Button><TextViewandroid:id="@+id/text2"android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/str_title2"android:textSize="20sp"android:textColor="@drawable/black" android:layout_x="10px"android:layout_y="326px"></TextView><Buttonandroid:id="@+id/mButton3"android:layout_width="wrap_content" android:layout_height="40px"android:text="@string/str_button1" android:textColor="@drawable/black" android:textSize="18sp"android:layout_x="190px"android:layout_y="322px"></Button><TextViewandroid:id="@+id/setTime2"android:layout_width="170px"android:layout_height="wrap_content" android:text="@string/str_default" android:textColor="@drawable/red"android:textSize="16sp"android:layout_x="10px"android:layout_y="369px"></TextView><Buttonandroid:id="@+id/mButton4"android:layout_width="wrap_content" android:layout_height="40px"android:text="@string/str_button2" android:textColor="@drawable/black" android:textSize="18sp"android:layout_x="190px"android:layout_y="362px"></Button></AbsoluteLayout>五、timeset.xml布局文件中的代码:<?xml version="1.0" encoding="utf-8"?><AbsoluteLayoutandroid:id="@+id/layout2"android:layout_width="fill_parent"android:layout_height="fill_parent"xmlns:android="/apk/res/android" ><TextViewandroid:id="@+id/text1"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="@string/str_text1"android:textColor="@drawable/white"android:textSize="16sp"android:layout_x="10px"android:layout_y="32px"></TextView><TextViewandroid:id="@+id/text2"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="@string/str_text2"android:textColor="@drawable/white"android:textSize="16sp"android:layout_x="10px"android:layout_y="172px"></TextView><TimePickerandroid:id="@+id/tPicker"android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_x="100px"android:layout_y="12px"></TimePicker><EditTextandroid:id="@+id/mEdit"android:layout_width="52px"android:layout_height="40px"android:text="15"android:textSize="16sp"android:layout_x="120px"android:layout_y="162px"></EditText><TextViewandroid:id="@+id/text3"android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/str_text3"android:textColor="@drawable/white" android:textSize="16sp"android:layout_x="180px"android:layout_y="172px"></TextView></AbsoluteLayout>六、string.xml中的代码:<?xml version="1.0" encoding="utf-8"?><resources><string name="hello">Hello World, EX06_10</string> <string name="app_name">大明原创闹钟</string><string name="str_button1">设置闹钟</string><string name="str_button2">删除闹钟</string><string name="str_title2">重复响起的闹钟</string> <string name="str_title3">大明闹钟一</string><string name="str_title4">大明闹钟二</string><string name="str_default">目前无设置</string><string name="str_text1">开始时间</string><string name="str_text2">重复响起的闹钟</string> <string name="str_text3">秒</string></resources>七:color.xml中的代码:<?xml version="1.0" encoding="utf-8"?><resources><drawable name="white">#FFFFFFFF</drawable><drawable name="other">#FF00FFF0</drawable><drawable name="black">#000000</drawable><drawable name="blue">#0000FF</drawable><drawable name="red">#FF0000</drawable></resources>八、AndroidManifest.xml中的代码<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="/apk/res/android" package=".daming"android:versionCode="1"android:versionName="1.0"><uses-sdk android:minSdkVersion="8" /><application android:icon="@drawable/icon"android:label="@string/app_name"><!-- 註冊receiver CallAlarm --><receiver android:name=".CallAlarm" android:process=":remote" /><activity android:name=".MainActivity"android:label="@string/app_name"><intent-filter><action android:name="android.intent.action.MAIN" /> <categoryandroid:name="UNCHER" /></intent-filter></activity><activity android:name=".AlarmAlert"android:label="@string/app_name"></activity></application></manifest>。
手机安全卫士部分源代码

package cn.yhsh.mobilesalf;import java.io.File;import java.io.IOException;import java.io.InputStream;import .HttpURLConnection;import .MalformedURLException;import .URL;import org.json.JSONException;import org.json.JSONObject;import com.lidroid.xutils.HttpUtils;import com.lidroid.xutils.exception.HttpException;import com.lidroid.xutils.http.ResponseInfo;import com.lidroid.xutils.http.callback.RequestCallBack;import cn.yhsh.mobilesalf.utils.StreamUtils;import android.app.Activity;import android.app.AlertDialog;import android.app.AlertDialog.Builder;import android.content.DialogInterface;import android.content.Intent;import android.content.SharedPreferences;import android.content.pm.PackageInfo;import android.content.pm.PackageManager;import NotFoundException; import .Uri;import android.os.Bundle;import android.os.Environment;import android.os.Handler;import android.os.Message;import android.os.SystemClock;import android.view.View;import android.widget.TextView;import android.widget.Toast;public class SplashMainActivity extends Activity {protected static final int MSG_UPDATE_DIALOG = 1;protected static final int MSG_UPDATE_ENTERHOME = 2;protected static final int MSG_SERVER_ERROR = 3;protected static final int MSG_URL_ERROR = 4;protected static final int MSG_IO_ERROR = 5;protected static final int MSG_JSON_ERROR = 6;private String code;private String des;private String apkurl;private Handler handler = new Handler() {public void handleMessage(Message msg) {switch (msg.what) {case MSG_UPDATE_DIALOG:// 2.1弹出对话框showdialog();break;case MSG_UPDATE_ENTERHOME://跳转到主界面enterHome();break;case MSG_SERVER_ERROR:Toast.makeText(getApplicationContext(), "您的网络连接服务器异常,请查看是否已连接网络!!", Toast.LENGTH_LONG).show();//跳转到主界面enterHome();break;case MSG_URL_ERROR:Toast.makeText(getApplicationContext(), "错误号:"+MSG_URL_ERROR, Toast.LENGTH_LONG).show();//跳转到主界面enterHome();break;case MSG_IO_ERROR:Toast.makeText(getApplicationContext(), "您的网络可能有问题,读取网络资源错误,请查看是网络是否正常!!", Toast.LENGTH_LONG).show();//跳转到主界面enterHome();break;case MSG_JSON_ERROR:Toast.makeText(getApplicationContext(), "错误号:"+MSG_JSON_ERROR, Toast.LENGTH_LONG).show();//跳转到主界面enterHome();break;}};};private TextView tv_splash_plan;private String str;private SharedPreferences sp;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(yout.activity_splash_main);//获取configsp = getSharedPreferences("config", MODE_PRIVA TE);TextView tv_splash_versionname = (TextView) findViewById(_splash_versionname);tv_splash_plan = (TextView) findViewById(_splash_plan);tv_splash_versionname.setText("版本号:"+getversionname());//判断如果打开自动更新,就调用自动更新方法if(sp.getBoolean("update", true)){update();}else{//如果关闭自动更新,直接进入主界面//SystemClock.sleep(2000);//不能再主线程中睡,会阻塞线程new Thread(){public void run(){//先睡2秒,在进入主页面SystemClock.sleep(2000);enterHome();};}.start();}}private void showdialog() {//创建对话框对象,对话框只能用thisAlertDialog.Builder builder = new Builder(this);//设置标题builder.setTitle("升级提醒!!");//设置图标builder.setIcon(R.drawable.ic_launcher);//设置描述信息builder.setMessage(des);//1.对话框点击空白处消失//设置对话框不能消失builder.setCancelable(false);//设置升级按钮builder.setPositiveButton("升级", new DialogInterface.OnClickListener() {@Overridepublic void onClick(DialogInterface dialog, int which) {download();}});//2.点击取消按钮,跳转到主界面,在界面中点击返回键返回到splash界面的问题//设置取消按钮builder.setNegativeButton("取消", new DialogInterface.OnClickListener() {@Overridepublic void onClick(DialogInterface dialog, int which) {//隐藏对话框dialog.dismiss();enterHome();}});builder.show();};/*** 下载最新版本*/protected void download() {HttpUtils httpUtils = new HttpUtils();//判断SD卡是否挂载if(Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)){ //获取SD卡根目录下载的安装包路径File file = new File(Environment.getExternalStorageDirectory().getPath(),"heima.apk");str = file.toString();httpUtils.download(apkurl, str, new RequestCallBack<File>() {@Overridepublic void onSuccess(ResponseInfo<File> arg0) {System.out.println("下载成功!!!");//下载成功后,安装最新版软件即可install();}@Overridepublic void onFailure(HttpException arg0, String arg1) {System.out.println("下载失败!!");}@Overridepublic void onLoading(long total, long current,boolean isUploading) {super.onLoading(total, current, isUploading);// 显示当前下载进度// total : 总进度// current : 当前进度// isUploading : 是否支持断点下载//设置控件可见tv_splash_plan.setVisibility(View.VISIBLE);tv_splash_plan.setText(current+"/"+total);if(current==total){Toast.makeText(getApplicationContext(), "安装包已下载到SD卡根目录!", Toast.LENGTH_LONG).show();}}});}}/*** 安装最新版软件*/protected void install() {/*** <intent-filter><action android:name="android.intent.action.VIEW" /><category android:name="android.intent.category.DEFAULT" /><data android:scheme="content" /> content从内容提供者中获取数据<data android:scheme="file" /> file:从文件中获取数据<data android:mimeType="application/vnd.android.package-archive" /> </intent-filter>*///创建意图对象Intent intent = new Intent();//设置actionintent.setAction("android.intent.action.VIEW");//设置categoryintent.addCategory("android.intent.category.DEFAULT");//设置type,由于两者互斥,所以不可以,换另外一种方法// intent.setType("application/vnd.android.package-archive");// intent.setData(Uri.fromFile(new File(str)));intent.setDataAndType(Uri.fromFile(new File(str)),"application/vnd.android.package-archive");//启动意图startActivityForResult(intent, 0);}@Overrideprotected void onActivityResult(int requestCode, int resultCode, Intent data) {super.onActivityResult(requestCode, resultCode, data);//安装完成后。
Android6.07.08.0一个简单的app内更新版本-okgoapp版本更新

Android6.07.08.0⼀个简单的app内更新版本-okgoapp版本更新登陆时splash初始页调⽤接⼝检查app版本。
如有更新,使⽤okGo的⽂件下载,保存到指定位置,调⽤Android安装apk。
<!-- Android 8.0 (Android O)为了针对⼀些流氓软件引导⽤户安装其他⽆关应⽤。
在应⽤权限设置的“特殊访问权限”中,加⼊了“安装其他应⽤”的设置 --><uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES"/>package com.test.activity.sys;import android.Manifest;import android.app.Activity;import android.content.Context;import android.content.DialogInterface;import android.content.Intent;import android.content.pm.PackageInfo;import android.content.pm.PackageManager;import .Uri;import android.os.Build;import android.os.Environment;import android.os.Handler;import android.os.Looper;import android.provider.Settings;import android.support.annotation.NonNull;import android.support.annotation.Nullable;import android.os.Bundle;import android.support.v4.app.ActivityCompat;import android.support.v4.content.FileProvider;import android.support.v7.app.AlertDialog;import android.text.format.Formatter;import android.util.Log;import android.view.View;import android.view.Window;import android.widget.TextView;import android.widget.Toast;import com.lzy.okgo.OkGo;import com.lzy.okgo.callback.FileCallback;import com.lzy.okgo.callback.StringCallback;import com.lzy.okgo.convert.FileConvert;import com.lzy.okgo.model.Progress;import com.lzy.okgo.model.Response;import com.test.BuildConfig;import com.test.Constant;import com.test.R;import com.test.activity.MainActivity;import com.test.activity.sys.LoginActivity;import com.test.util.DataUtils;import com.test.view.NumberProgressBar;import org.json.JSONException;import org.json.JSONObject;import java.io.File;import java.text.NumberFormat;/*** @author cralor* @date 2018/8/8* 启动页 Activity*/public class SplashActivity extends Activity{public static final int INSTALL_APK_REQUESTCODE = 3;public static final int GET_UNKNOWN_APP_SOURCES = 7;private File apkFile;/*** 可以额外指定⽂件的下载⽬录和下载完成后的⽂件名*/private String destFileDir = Environment.getExternalStorageDirectory() + FileConvert.DM_TARGET_FOLDER + "myAppDownload" + File.separator;private String destFileName = "myApp.apk";private Handler handler;private Context content;private TextView tvDownloadSize;private TextView tvProgress;private TextView tvNetSpeed;private NumberProgressBar pbProgress;private NumberFormat numberFormat;@Overrideprotected void onCreate(@Nullable Bundle savedInstanceState) {//去掉标题栏requestWindowFeature(Window.FEATURE_NO_TITLE);// getWindow().setFlags(youtParams. FLAG_FULLSCREEN ,youtParams. FLAG_FULLSCREEN);super.onCreate(savedInstanceState);setContentView(yout.activity_splash);content = this;handler = new Handler(Looper.getMainLooper());numberFormat = NumberFormat.getPercentInstance();numberFormat.setMinimumFractionDigits(2);initView();}/*** 打开程序时判断是否已经登陆过,且token有效*/private void initView() {// ...handler.postDelayed(new Runnable() {@Overridepublic void run() {OkGo.<String>post(Constant.GET_VERSION).tag(1).execute(new StringCallback() {@Overridepublic void onSuccess(Response<String> response) {String data = response.body();String code = "";String sysVersion = "";try {JSONObject jsonObject = new JSONObject(data);code = jsonObject.get("code").toString();sysVersion = jsonObject.get("data").toString();} catch (JSONException e) {e.printStackTrace();}Log.v("data",""+code);if(Constant.SUCCESS_CODE.equals(code)){// Android studio 中 build.gradle 中的版本号// 获取PackageManager的实例PackageManager packageManager = getPackageManager();// getPackageName()是你当前类的包名,0代表是获取版本信息PackageInfo packInfo = null;String appVersion = "";try {packInfo = packageManager.getPackageInfo(getPackageName(), 0);} catch (NotFoundException e) {e.printStackTrace();}if (packInfo != null) {appVersion = packInfo.versionName;}if(appVersion.equals(sysVersion)){Intent intent = new Intent(SplashActivity.this, MainActivity.class);startActivity(intent);finish();}else{Log.e("SplashActivity","需要更新版本到---"+sysVersion);Toast.makeText(content, "有新版本需要更新", Toast.LENGTH_SHORT).show(); getVersion();}}}@Overridepublic void onError(Response<String> response) {Toast.makeText(content, "请求失败", Toast.LENGTH_SHORT).show();Intent intent = new Intent(SplashActivity.this, LoginActivity.class);startActivity(intent);overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out);finish();}});}}, 3);}/*** 更新弹出框*/public void getVersion(){//退出的确认弹出框new AlertDialog.Builder(content).setTitle("提⽰").setMessage("请更新最新版本").setCancelable(false).setPositiveButton("确定", new DialogInterface.OnClickListener() {@Overridepublic void onClick(DialogInterface dialog, int whichButton) {Toast.makeText(content, "dianjixiazai ", Toast.LENGTH_SHORT).show();fileDownload();View view1 = getLayoutInflater().inflate(yout.update_app_progress, null);tvDownloadSize = view1.findViewById(R.id.downloadSize);tvProgress = view1.findViewById(Progress);tvNetSpeed = view1.findViewById(Speed);pbProgress = view1.findViewById(R.id.pbProgress);AlertDialog.Builder builder = new AlertDialog.Builder(content);builder.setTitle("正在下载");builder.setView(view1);builder.setCancelable(false);builder.setNegativeButton("取消", new DialogInterface.OnClickListener(){@Overridepublic void onClick(DialogInterface dialog, int which) {finish();}});builder.create().show();}).setNegativeButton("取消", new DialogInterface.OnClickListener() {@Overridepublic void onClick(DialogInterface dialog, int whichButton) {finish();}}).show();}/*** 获取服务器apk*/public void fileDownload() {//检查是否获得写⼊权限,未获得则向⽤户请求。
Android实验报告组件布局

Android 开发(实验五)实验题目:Android组件布局试验指导老师:班级:计算机科学与技术系班姓名:一、实验目的1、掌握Android组件布局的使用方法2、学会组件布局的重要属性与应用3、能够根据需求,通过布局构建各类实际的页面。
二、实验内容组件布局有:LinearLayout、TableLayout、FrameLayout、RelativeLayout三、实验步骤1、用表格布局完成登录界面<TableLayoutxmlns:android="/apk/res/android"android:layout_width="fill_parent"android:layout_height="fill_parent"android:background="#FFFFCC"android:stretchColumns="0,3" ><ImageView android:layout_width="fill_parent"android:layout_height="5dp"/><TableRow><ImageViewandroid:layout_width="wrap_content"android:layout_height="100dp"android:src="@drawable/img"android:gravity="center"android:layout_span="4"/></TableRow><TableRow ><TextView/><TextViewandroid:layout_width="fill_parent"android:layout_height="wrap_content"android:gravity="right"android:text="@string/username"android:textStyle="bold"android:textColor="#000000"/><EditTextandroid:layout_width="fill_parent"android:layout_height="wrap_content" android:gravity="left"android:minWidth="200px"android:id="@+id/ETname"/></TableRow><TableRow ><TextView/><TextViewandroid:layout_width="fill_parent"android:layout_height="wrap_content" android:gravity="right"android:text="@string/password"android:textStyle="bold"android:textColor="#000000"/><EditTextandroid:layout_width="fill_parent"android:layout_height="wrap_content" android:gravity="left"android:minWidth="200px"android:inputType="textPassword"android:id="@+id/ETpwd"/></TableRow><TableRow><TextView /><Buttonandroid:id="@+id/Btok"android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="right"android:text="@string/button"android:textStyle="bold"/><Buttonandroid:id="@+id/Btcancel"android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="left"android:text="@string/cancel"android:textStyle="bold"/></TableRow></TableLayout>2、使用线性布局完成系统主界面<LinearLayoutxmlns:android="/apk/res/android" android:layout_width="match_parent"android:layout_height="match_parent"android:orientation="vertical"android:background="#FFFFCC"><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:text="欢迎登陆此系统!"android:layout_gravity="center"android:textSize="30sp"android:textColor="#000000"/><Buttonandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:text="退出"android:textSize="30sp"android:textColor="#000000"android:id="@+id/Btquit"/></LinearLayout>3、使用线性布局和相对布局嵌套完成注册页面<LinearLayoutxmlns:android="/apk/res/android" android:layout_width="match_parent"android:layout_height="match_parent"android:orientation="vertical"android:background="#FFFFCC"><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:text="注册"android:layout_gravity="center"android:textSize="30sp"android:textColor="#000000"/><RelativeLayoutxmlns:android="/apk/res/android" android:layout_width="match_parent"android:layout_height="match_parent"><TextViewandroid:id="@+id/lname"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="用户名 "android:layout_gravity="center"android:textSize="20sp"android:textColor="#000000"/><EditTextandroid:id="@+id/ename"android:layout_width="200px"android:layout_height="wrap_content" android:layout_toRightOf="@id/lname"/> <TextViewandroid:id="@+id/lpwd"android:layout_width="wrap_content"android:layout_height="wrap_content" android:text="密码 "android:layout_below="@id/lname"android:layout_marginTop="20px"android:textSize="20sp"android:textColor="#000000"/><EditTextandroid:id="@+id/epwd"android:layout_width="200px"android:layout_height="wrap_content" android:inputType="textPassword"android:layout_toRightOf="@id/lpwd"android:layout_alignTop="@id/lpwd"/> <TextViewandroid:id="@+id/lapwd"android:layout_width="wrap_content"android:layout_height="wrap_content" android:text="确认密码 "android:layout_below="@id/lpwd"android:layout_marginTop="20px"android:textSize="20sp"android:textColor="#000000"/><EditTextandroid:id="@+id/eapwd"android:layout_width="200px"android:layout_height="wrap_content" android:inputType="textPassword"android:layout_toRightOf="@id/lapwd" android:layout_alignTop="@id/lapwd"/> <Buttonandroid:id="@+id/Btok"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="提交"android:layout_below="@id/lapwd"android:layout_marginTop="20px"android:layout_marginRight="20px"android:textSize="20sp"android:textColor="#000000"/><Buttonandroid:id="@+id/Btqx"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="取消"android:layout_below="@id/lapwd"android:layout_toRightOf="@id/Btok"android:layout_alignTop="@id/Btok"android:textSize="20sp"android:textColor="#000000"/></RelativeLayout></LinearLayout>4、事件代码如下:LayoutTestActivity.javapackage youttest;import android.app.Activity;import android.content.Intent;import android.os.Bundle;import android.view.View;import android.view.View.OnClickListener;import android.widget.Button;import android.widget.EditText;public class LayoutTestActivity extends Activity {/** Called when the activity is first created. */ private Button Btok;private Button Btcancel;// private EditText ETname;// private EditText ETpwd;@Overridepublic void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(yout.main);Btok = (Button)findViewById(R.id.Btok);Btcancel = (Button)findViewById(R.id.Btcancel); Btok.setOnClickListener(new myOnClickListener());Btcancel.setOnClickListener(new myOnClickListener());}public class myOnClickListener implements OnClickListener{@Overridepublic void onClick(View v) {// TODO Auto-generated method stubIntent intent = new Intent();switch(v.getId()){case R.id.Btok:intent.setClass(LayoutTestActivity.this, LoginActivity.class);startActivity(intent);break;case R.id.Btcancel:intent.setClass(LayoutTestActivity.this, ZhuCe.class);startActivity(intent);break;}}};}LoginActivity.javapackage youttest;import android.app.Activity;import android.app.AlertDialog;import android.content.DialogInterface;import android.content.Intent;import android.os.Bundle;import android.view.View;import android.view.View.OnClickListener;import android.widget.Button;public class LoginActivity extends Activity {private Button Btquit;@Overridepublic void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(yout.login);Btquit = (Button)findViewById(R.id.Btquit);Btquit.setOnClickListener(new OnClickListener(){@Overridepublic void onClick(View v) {// TODO Auto-generated method stubnew AlertDialog.Builder(LoginActivity.this).setTitle("确认窗口").setMessage("确定要退出应用程序?").setPositiveButton("确定",new DialogInterface.OnClickListener() {@Overridepublic void onClick(DialogInterface dialog, int i) {// TODO Auto-generated method stubfinish();}}).setNegativeButton("取消",new DialogInterface.OnClickListener(){@Overridepublic void onClick(DialogInterface dialog, int which) {// TODO Auto-generated method stub}}).show();}});}}ZhuCe.javapackage youttest;import android.app.Activity;import android.os.Bundle;public class ZhuCe extends Activity {@Overridepublic void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState);setContentView(yout.zhuce);}}四、实验结果五、实验总结1、通过本次实验,掌握了Android组件布局的使用方法2、也学会了组件布局的重要属性与应用能够根据需求,通过布局构建各类实际的页面3、实验中遇到的问题,通过自己的努力最后得以解决。
material design dialog的用法

material design dialog的用法Material Design 是Google 推出的一种设计规范,广泛应用于Android、iOS 以及Web 平台。
其中的Material Design Dialog 是一种现代化的对话框组件,具有良好的用户体验和高度的定制性。
接下来,我们将详细介绍Material Design Dialog 的用法,包括组件、创建自定义对话框、布局与样式、交互与动效等方面,并通过实践案例加深理解。
1.Material Design Dialog 简介Material Design Dialog 继承自Android 的AlertDialog,但它更具现代化气息。
它包含几种预设的样式,如单行、多行、列表等,同时支持自定义布局。
Material Design Dialog 使用了卡片式设计,边缘有圆角,并支持动态阴影效果。
2.Material Design Dialog 组件Material Design Dialog 主要包括以下组件:- Content:对话框的主要内容区域。
- Action Button:对话框底部的一个按钮,用于执行确定操作。
- Header:对话框顶部的标题栏。
- Footer:对话框底部的按钮区域。
3.创建自定义对话框要创建自定义对话框,我们需要使用Android 工作室或Java 编写代码。
以下是一个简单的示例:```javaAlertDialog.Builder builder = new AlertDialog.Builder(this);builder.setTitle("提示");builder.setMessage("您确定要删除此文件吗?");builder.setPositiveButton("确定", newDialogInterface.OnClickListener() {@Overridepublic void onClick(DialogInterface dialog, int which) {// 执行确定操作}});builder.setNegativeButton("取消", newDialogInterface.OnClickListener() {@Overridepublic void onClick(DialogInterface dialog, int which) {// 执行取消操作}});AlertDialog dialog = builder.create();dialog.show();```4.对话框布局与样式在自定义对话框时,我们可以通过布局文件和样式文件来调整对话框的布局和样式。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
根据Android的安全机制,在使用TelephonyManager时,必须在AndroidManifest.xml 中添加<uses-permission android:name="READ_PHONE_STATE" /> 否则无法获得系统的许可。
手机型号Build.MODEL
String MODEL The end-user-visible name for the end product.
sdk版本 Build.VERSION.SDK
String SD
K
This constant is deprecated. Use SDK_INT to easily get this as an integer.
及frimware版本号(系统版本号)Build.VERSION.RELEASE
String RELEASE The user-visible version string.
private void loadPhoneStatus() { TelephonyManager
phoneMgr=(TelephonyManager)this.getSystemService(Context.TELEPHONY_SERVICE); txtPhoneModel.setText(Build.MODEL); //手机型号
txtPhoneNumber.setT ext(phoneMgr.getLine1Number());//本机电话号码
txtSdkVersion.setText(Build.VERSION.SDK);//SDK版本号
txtOsVersion.setText(Build.VERSION.RELEASE);//Firmware/OS 版本号}
事实上,Build能向我们提供包括硬件厂商,硬件编号,序列号等很多信息调用方法也都同上,很简单。
Strin
g
BOARD The name of the underlying board, like "goldfish".
Strin
g
BOOTLOADER The system bootloader version number.
Strin
g
BRAND The brand (e.g., carrier) the software is customized for, if any.
Strin
g
CPU_ABI The name of the instruction set (CPU type + ABI convention) of native code.
Strin
g CPU_ABI2The name of the second instruction set (CPU type + ABI convention) of native code.
Strin DEVICE The name of the industrial design.
g
Strin
g
DISPLAY A build ID string meant for displaying to the user
Strin
g
FINGERPRINT A string that uniquely identifies this build.
Strin
g
HARDWARE The name of the hardware (from the kernel command line or /proc).
Strin
g
HOST
Strin
g
ID Either a changelist number, or a label like "M4-rc20".
Strin
g MANUFACTURE
R
The manufacturer of the product/hardware.
Strin
g
MODEL The end-user-visible name for the end product.
Strin
g
PRODUCT The name of the overall product.
Strin
g
RADIO The radio firmware version number.
Strin
g
SERIAL A hardware serial number, if available.
Strin
g
TAGS Comma-separated tags describing the build, like "unsigned,debug".
long TIME
Strin
g
TYPE The type of build, like "user" or "eng".
Strin
g
UNKNOWN Value used for when a build property is unknown.
Strin
g
USER
android.os.Build
Java代码
1Build.BOARD // 主板
2Build.BRAND // android系统定制商
3Build.CPU_ABI // cpu指令集
4Build.DEVICE // 设备参数
5Build.DISPLAY // 显示屏参数
6Build.FINGERPRINT // 硬件名称
7Build.HOST
8Build.ID // 修订版本列表
9Build.MANUFACTURER // 硬件制造商
10Build.MODEL // 版本
11Build.PRODUCT // 手机制造商
12Build.TAGS // 描述build的标签
13Build.TIME
14Build.TYPE // builder类型
ER
16
17// 运行结果
18/*
19board: unknown
20brand: generic
21cpu abi: armeabi
22device: generic
23display: google_sdk-eng 2.1 ERD79 22607 test-keys
24finger print: generic/google_sdk/generic/:2.1/ERD79/22607:eng/test-keys 25host:
26id: ERD79
27manufacturer: unknown
28model: google_sdk
29product: google_sdk
30tags: test-keys
31time: 1261185425000
32type: eng
33user: android-build
34*/
Build.VERSION
Java代码
35// 当前开发代号
36Build.VERSION.CODENAME
37// 源码控制版本号
38Build.VERSION.INCREMENTAL
39// 版本字符串
40Build.VERSION.RELEASE
41// 版本号
42Build.VERSION.SDK
43// 版本号
44Build.VERSION.SDK_INT
45
46// 结果
47/*
48REL
4922607
50 2.1
517
527
53*/
54
55// Build.VERSION.SDK_INT可与switch搭配用
56switch (Build.VERSION.SDK_INT) {
57case Build.VERSION_CODES.BASE: // 1.0
58break;
59
60case Build.VERSION_CODES.BASE_1_1: // 1.1
61break;
62
63case Build.VERSION_CODES.CUPCAKE: // 1.5
64break;
65
66case Build.VERSION_CODES.CUR_DEVELOPMENT: // current dev version 67break;
68
69case Build.VERSION_CODES.DONUT: // 1.6
70break;
71
72case Build.VERSION_CODES.ECLAIR: // 2.0
73break;
74
75case Build.VERSION_CODES.ECLAIR_0_1: // 2.0.1
76break;
77
78case Build.VERSION_CODES.ECLAIR_MR1: // 2.1
79break;。